use of uk.me.parabola.imgfmt.app.labelenc.EncodedText in project mkgmap by openstreetmap.
the class LBLFile method newLabel.
/**
* Add a new label with the given text. Labels are shared, so that identical
* text is always represented by the same label.
*
* @param text The text of the label, it will be in uppercase.
* @return A reference to the created label.
*/
public Label newLabel(String text) {
EncodedText encodedText = textEncoder.encodeText(text);
Label l = labelCache.get(encodedText);
if (l == null) {
l = new Label(encodedText.getChars());
labelCache.put(encodedText, l);
l.setOffset(getNextLabelOffset());
if (encodedText.getLength() > 0)
getWriter().put(encodedText.getCtext(), 0, encodedText.getLength());
alignForNext();
if (l.getOffset() > 0x3fffff)
throw new MapFailedException("Overflow of LBL section");
}
return l;
}
use of uk.me.parabola.imgfmt.app.labelenc.EncodedText 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);
}
use of uk.me.parabola.imgfmt.app.labelenc.EncodedText in project mkgmap by openstreetmap.
the class StructuredOutputStream method writeString.
/**
* Writes a string including a terminating null byte.
*
* For each character in the string the low-order byte is written.
*
* @param s The string to write.
* @throws IOException If the write fails.
*/
public void writeString(String s) throws IOException {
if (encoder == null)
throw new ExitException("tdbfile: character encoding is null");
EncodedText encodedText = encoder.encodeText(s);
if (encodedText == NO_TEXT)
return;
out.write(encodedText.getCtext(), 0, encodedText.getLength());
}
Aggregations