Search in sources :

Example 1 with TypData

use of uk.me.parabola.imgfmt.app.typ.TypData in project mkgmap by openstreetmap.

the class TypCompiler method makeMap.

/**
 * The integration with mkgmap.
 *
 * @param args The options that are in force.
 * @param filename The input filename.
 * @return Returns the name of the file that was written. It depends on the family id.
 */
public String makeMap(CommandArgs args, String filename) {
    assert filename.toLowerCase().endsWith(".txt");
    CharsetProbe probe = new CharsetProbe();
    String readCharset = probe.probeCharset(filename);
    TypData data;
    try {
        data = compile(filename, readCharset, args.getSort());
    } catch (SyntaxException e) {
        throw new MapFailedException("Compiling TYP txt file: " + e.getMessage());
    } catch (FileNotFoundException e) {
        throw new MapFailedException("Could not open TYP file " + filename + " to read");
    }
    TypParam param = data.getParam();
    int family = args.get("family-id", -1);
    int product = args.get("product-id", -1);
    int cp = args.get("code-page", -1);
    if (family != -1)
        param.setFamilyId(family);
    if (product != -1)
        param.setProductId(product);
    if (cp != -1)
        param.setCodePage(cp);
    File outFile = new File(filename);
    String outName = outFile.getName();
    int last;
    if (outName.length() > 4 && (last = outName.lastIndexOf('.')) > 0)
        outName = outName.substring(0, last);
    outName += ".typ";
    outFile = new File(args.getOutputDir(), outName);
    try {
        writeTyp(data, outFile);
    } catch (TypLabelException e) {
        throw new MapFailedException("TYP file cannot be written in code page " + data.getSort().getCodepage());
    } catch (IOException e) {
        throw new MapFailedException("Error while writing typ file", e);
    }
    return outFile.getPath();
}
Also used : TypLabelException(uk.me.parabola.imgfmt.app.typ.TypLabelException) TypData(uk.me.parabola.imgfmt.app.typ.TypData) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) FileNotFoundException(java.io.FileNotFoundException) TypParam(uk.me.parabola.imgfmt.app.typ.TypParam) IOException(java.io.IOException) TYPFile(uk.me.parabola.imgfmt.app.typ.TYPFile) File(java.io.File)

Example 2 with TypData

use of uk.me.parabola.imgfmt.app.typ.TypData in project mkgmap by openstreetmap.

the class TypTextReaderTest method testZeroColourBug.

@Test
public void testZeroColourBug() {
    String s = "[_point]\n" + "Type=0x01e\n" + "SubType=0x00\n" + "String1=0x04,island\n" + "DayXpm=\"5 5 1 1\"   Colormode=32\n" + "\"!      c #000000\"  canalalpha=15\n" + "\"!!!!!\"\n" + "\"!!!!!\"\n" + "\"!!!!!\"\n" + "\"!!!!!\"\n" + "\"!!!!!\"\n" + "[end]";
    tr = makeTyp(s);
    TypData data = tr.getData();
    TypPoint point = data.getPoints().get(0);
    ArrayImgWriter w = new ArrayImgWriter();
    point.write(w, data.getEncoder());
    byte[] out = w.getBytes();
    assertEquals("width", 5, out[1]);
    assertEquals("height", 5, out[2]);
    assertEquals("number of colours", 1, out[3]);
}
Also used : TypData(uk.me.parabola.imgfmt.app.typ.TypData) TypPoint(uk.me.parabola.imgfmt.app.typ.TypPoint) ArrayImgWriter(func.lib.ArrayImgWriter) Test(org.junit.Test)

Example 3 with TypData

use of uk.me.parabola.imgfmt.app.typ.TypData in project mkgmap by openstreetmap.

the class TypTextReaderTest method testIgnoreUnknownSections.

/**
 * Check that unknown sections don't throw an exception and are ignored without
 * affecting anything else.
 */
@Test
public void testIgnoreUnknownSections() {
    tr = makeTyp("[_unknown_section_name]\n" + "Type=0x2\n" + "String1=0x04,Parking\n" + "String2=0x03,Parkeergarage\n" + "OtherStuff=Unknown\n" + "[End]\n" + "[_id]\n" + "FID=4455\n" + "ProductCode=2\n" + "CodePage=1251\n" + "[End]");
    TypData data = tr.getData();
    System.out.println(data);
    assertEquals(4455, data.getParam().getFamilyId());
}
Also used : TypData(uk.me.parabola.imgfmt.app.typ.TypData) Test(org.junit.Test)

Example 4 with TypData

use of uk.me.parabola.imgfmt.app.typ.TypData in project mkgmap by openstreetmap.

the class TypCompiler method standAloneRun.

private void standAloneRun(String in, String out) {
    CharsetProbe probe = new CharsetProbe();
    String readCharset = probe.probeCharset(in);
    TypData data;
    try {
        data = compile(in, readCharset, null);
    } catch (SyntaxException e) {
        System.out.println(e.getMessage());
        return;
    } catch (FileNotFoundException e) {
        throw new MapFailedException("Could not open TYP file " + in + " to read");
    }
    try {
        writeTyp(data, new File(out));
    } catch (IOException e) {
        System.out.println("Error writing file: " + e.getMessage());
    }
}
Also used : TypData(uk.me.parabola.imgfmt.app.typ.TypData) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) TYPFile(uk.me.parabola.imgfmt.app.typ.TYPFile) File(java.io.File)

Example 5 with TypData

use of uk.me.parabola.imgfmt.app.typ.TypData in project mkgmap by openstreetmap.

the class TypCompiler method compile.

/**
 * Read and compile a TYP file, returning the compiled form.
 *
 * @param filename The input filename.
 * @param charset The character set to use to read this file. We should have already determined
 * that this character set is valid and can be used to read the file.
 * @param sort The sort information from command line options, used for the output code page
 * only. If null, then the code page set by CodePage in the typ.txt file will be used.
 *
 * @return The compiled form as a data structure.
 * @throws FileNotFoundException If the file doesn't exist.
 * @throws SyntaxException All user correctable problems in the input file.
 */
private TypData compile(String filename, String charset, Sort sort) throws FileNotFoundException, SyntaxException {
    TypTextReader tr = new TypTextReader();
    TypData data = tr.getData();
    data.setSort(sort);
    try {
        Reader r = new BufferedReader(new InputStreamReader(new FileInputStream(filename), charset));
        try {
            tr.read(filename, r);
        } finally {
            Utils.closeFile(r);
        }
    } catch (UnsupportedEncodingException e) {
        // Not likely to happen as we should have already used this character set!
        throw new MapFailedException("Unsupported character set", e);
    }
    return tr.getData();
}
Also used : InputStreamReader(java.io.InputStreamReader) TypData(uk.me.parabola.imgfmt.app.typ.TypData) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) BufferedReader(java.io.BufferedReader) TypTextReader(uk.me.parabola.mkgmap.typ.TypTextReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TypTextReader(uk.me.parabola.mkgmap.typ.TypTextReader) FileInputStream(java.io.FileInputStream)

Aggregations

TypData (uk.me.parabola.imgfmt.app.typ.TypData)9 Test (org.junit.Test)6 ArrayImgWriter (func.lib.ArrayImgWriter)4 IOException (java.io.IOException)3 MapFailedException (uk.me.parabola.imgfmt.MapFailedException)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 TYPFile (uk.me.parabola.imgfmt.app.typ.TYPFile)2 TypPoint (uk.me.parabola.imgfmt.app.typ.TypPoint)2 TypPolygon (uk.me.parabola.imgfmt.app.typ.TypPolygon)2 SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 Reader (java.io.Reader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ImgFileWriter (uk.me.parabola.imgfmt.app.ImgFileWriter)1 TypLabelException (uk.me.parabola.imgfmt.app.typ.TypLabelException)1