Search in sources :

Example 1 with CodeFunctions

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));
}
Also used : CodeFunctions(uk.me.parabola.imgfmt.app.labelenc.CodeFunctions)

Example 2 with CodeFunctions

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()]);
}
Also used : CharacterDecoder(uk.me.parabola.imgfmt.app.labelenc.CharacterDecoder) DecodedText(uk.me.parabola.imgfmt.app.labelenc.DecodedText) ArrayList(java.util.ArrayList) ImgFileReader(uk.me.parabola.imgfmt.app.ImgFileReader) BufferedImgFileReader(uk.me.parabola.imgfmt.app.BufferedImgFileReader) CodeFunctions(uk.me.parabola.imgfmt.app.labelenc.CodeFunctions)

Example 3 with CodeFunctions

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();
}
Also used : CodeFunctions(uk.me.parabola.imgfmt.app.labelenc.CodeFunctions)

Example 4 with CodeFunctions

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);
    }
}
Also used : BaseEncoder(uk.me.parabola.imgfmt.app.labelenc.BaseEncoder) CodeFunctions(uk.me.parabola.imgfmt.app.labelenc.CodeFunctions)

Example 5 with CodeFunctions

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);
}
Also used : EncodedText(uk.me.parabola.imgfmt.app.labelenc.EncodedText) CharacterEncoder(uk.me.parabola.imgfmt.app.labelenc.CharacterEncoder) CodeFunctions(uk.me.parabola.imgfmt.app.labelenc.CodeFunctions)

Aggregations

CodeFunctions (uk.me.parabola.imgfmt.app.labelenc.CodeFunctions)5 ArrayList (java.util.ArrayList)1 BufferedImgFileReader (uk.me.parabola.imgfmt.app.BufferedImgFileReader)1 ImgFileReader (uk.me.parabola.imgfmt.app.ImgFileReader)1 BaseEncoder (uk.me.parabola.imgfmt.app.labelenc.BaseEncoder)1 CharacterDecoder (uk.me.parabola.imgfmt.app.labelenc.CharacterDecoder)1 CharacterEncoder (uk.me.parabola.imgfmt.app.labelenc.CharacterEncoder)1 DecodedText (uk.me.parabola.imgfmt.app.labelenc.DecodedText)1 EncodedText (uk.me.parabola.imgfmt.app.labelenc.EncodedText)1