use of uk.me.parabola.imgfmt.app.labelenc.CharacterEncoder 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