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();
}
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]);
}
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());
}
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());
}
}
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();
}
Aggregations