use of uk.me.parabola.imgfmt.app.labelenc.CodeFunctions in project mkgmap by openstreetmap.
the class Map method addInfo.
/**
* There is an area after the TRE header and before its data
* starts that is used to save licence info.
*
* It seems that this must follow the code page of the LBL file. The format6 encoding is not allowed
* however.
*
* @param msg Any string.
*/
public void addInfo(String msg) {
int codePage = lblFile.getCodePage();
CodeFunctions functions = CodeFunctions.createEncoderForLBL(0, codePage);
treFile.addInfo(functions.getEncoder().encodeText(msg));
}
use of uk.me.parabola.imgfmt.app.labelenc.CodeFunctions in project mkgmap by openstreetmap.
the class TREFileReader method getMapInfo.
public String[] getMapInfo(int codePage) {
CodeFunctions funcs = CodeFunctions.createEncoderForLBL(0, codePage);
CharacterDecoder decoder = funcs.getDecoder();
// First do the ones in the TRE header gap
ImgFileReader reader = getReader();
reader.position(header.getHeaderLength());
List<String> msgs = new ArrayList<>();
while (reader.position() < header.getHeaderLength() + header.getMapInfoSize()) {
byte[] m = reader.getZString();
decoder.reset();
for (byte b : m) decoder.addByte(b);
DecodedText text = decoder.getText();
String text1 = text.getText();
msgs.add(text1);
}
return msgs.toArray(new String[msgs.size()]);
}
use of uk.me.parabola.imgfmt.app.labelenc.CodeFunctions in project mkgmap by openstreetmap.
the class LBLFile method setEncoder.
public void setEncoder(int encodingType, int codepage) {
CodeFunctions cfuncs = CodeFunctions.createEncoderForLBL(encodingType, codepage);
lblHeader.setEncodingType(cfuncs.getEncodingType());
textEncoder = cfuncs.getEncoder();
}
use of uk.me.parabola.imgfmt.app.labelenc.CodeFunctions in project mkgmap by openstreetmap.
the class LBLFile method setCharacterType.
public void setCharacterType(String cs, boolean forceUpper) {
log.info("encoding type " + cs);
CodeFunctions cfuncs = CodeFunctions.createEncoderForLBL(cs);
lblHeader.setEncodingType(cfuncs.getEncodingType());
textEncoder = cfuncs.getEncoder();
if (forceUpper && textEncoder instanceof BaseEncoder) {
BaseEncoder baseEncoder = (BaseEncoder) textEncoder;
baseEncoder.setUpperCase(true);
}
}
use of uk.me.parabola.imgfmt.app.labelenc.CodeFunctions in project mkgmap by openstreetmap.
the class ImgHeader method setDescription.
/**
* Set the description. It is spread across two areas in the header.
*
* It appears that the description has to be in ascii.
*
* @param desc The description.
*/
protected void setDescription(String desc) {
// Force the description to be in ascii.
CodeFunctions funcs = CodeFunctions.createEncoderForLBL(0, 0);
CharacterEncoder encoder = funcs.getEncoder();
EncodedText enc = encoder.encodeText(desc);
byte[] ctext = enc.getCtext();
int len = enc.getLength() - 1;
if (len > 50)
throw new IllegalArgumentException("Description is too long (max 50)");
byte[] part1 = new byte[LEN_MAP_DESCRIPTION];
Arrays.fill(part1, (byte) ' ');
byte[] part2 = new byte[LEN_MAP_NAME_CONT];
Arrays.fill(part2, (byte) ' ');
if (ctext != null) {
if (len > LEN_MAP_DESCRIPTION) {
System.arraycopy(ctext, 0, part1, 0, LEN_MAP_DESCRIPTION);
System.arraycopy(ctext, LEN_MAP_DESCRIPTION, part2, 0, len - LEN_MAP_DESCRIPTION);
} else {
System.arraycopy(ctext, 0, part1, 0, len);
}
}
header.position(OFF_MAP_DESCRIPTION);
header.put(part1);
header.position(OFF_MAP_NAME_CONT);
header.put(part2);
// really?
header.put((byte) 0);
}
Aggregations