use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.
the class CommonSection method commonKey.
/**
* Deal with all the keys that are common to the different element types.
* Most tags are in fact the same for every element.
*
* @return True if this routine has processed the tag.
*/
protected boolean commonKey(TokenScanner scanner, TypElement current, String name, String value) {
if (name.equalsIgnoreCase("Type")) {
try {
int ival = Integer.decode(value);
if (ival >= 0x100) {
current.setType(ival >>> 8);
current.setSubType(ival & 0xff);
} else {
current.setType(ival & 0xff);
}
} catch (NumberFormatException e) {
throw new SyntaxException(scanner, "Bad number " + value);
}
} else if (name.equalsIgnoreCase("SubType")) {
try {
int ival = Integer.decode(value);
current.setSubType(ival);
} catch (NumberFormatException e) {
throw new SyntaxException(scanner, "Bad number for sub type " + value);
}
} else if (name.toLowerCase().startsWith("string")) {
try {
current.addLabel(value);
} catch (NumberFormatException e) {
throw new SyntaxException(scanner, "Bad number in " + value);
}
} else if (name.equalsIgnoreCase("Xpm")) {
Xpm xpm = readXpm(scanner, value, current.simpleBitmap());
current.setXpm(xpm);
} else if (name.equalsIgnoreCase("FontStyle")) {
int font = decodeFontStyle(value);
current.setFontStyle(font);
} else if (name.equalsIgnoreCase("CustomColor") || name.equals("ExtendedLabels")) {
// These are just noise, the appropriate flag is set if any feature is used.
} else if (name.equalsIgnoreCase("DaycustomColor")) {
current.setDayFontColor(value);
} else if (name.equalsIgnoreCase("NightcustomColor")) {
current.setNightCustomColor(value);
} else if (name.equalsIgnoreCase("Comment")) {
// a comment that is ignored.
} else {
return false;
}
return true;
}
use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.
the class CommonSection method readImage.
/**
* Read the bitmap part of a XPM image.
*
* In the TYP file, XPM is used when there is not really an image, so this is not
* always called.
*
* Almost all of this routine is checking that the strings are valid. They have the
* correct length, there are quotes at the beginning and end at that each pixel tag
* is listed in the colours section.
*/
protected BitmapImage readImage(TokenScanner scanner, ColourInfo colourInfo) {
StringBuffer sb = new StringBuffer();
int width = colourInfo.getWidth();
int height = colourInfo.getHeight();
int cpp = colourInfo.getCharsPerPixel();
for (int i = 0; i < height; i++) {
String line = scanner.readLine();
if (line.isEmpty())
throw new SyntaxException(scanner, "Invalid blank line in bitmap.");
if (line.charAt(0) != '"')
throw new SyntaxException(scanner, "xpm bitmap line must start with a quote: " + line);
if (line.length() < 1 + width * cpp)
throw new SyntaxException(scanner, "short image line: " + line);
line = line.substring(1, 1 + width * cpp);
sb.append(line);
// Do the syntax check, to avoid an error later when we don't have the line number any more
for (int cidx = 0; cidx < width * cpp; cidx += cpp) {
String tag = line.substring(cidx, cidx + cpp);
try {
colourInfo.getIndex(tag);
} catch (Exception e) {
throw new SyntaxException(scanner, String.format("Tag '%s' is not one of the defined colour pixels", tag));
}
}
}
if (sb.length() != width * height * cpp) {
throw new SyntaxException(scanner, "Got " + sb.length() + " of image data, " + "expected " + width * height * cpp);
}
return new BitmapImage(colourInfo, sb.toString());
}
use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.
the class DrawOrderSection method processLine.
/**
* There is only one tag in this section.
*/
public void processLine(TokenScanner scanner, String name, String value) {
if (!name.equalsIgnoreCase("Type"))
throw new SyntaxException(scanner, "Unrecognised keyword in draw order section: " + name);
String[] typeDrawOrder = value.split(",", -1);
if (typeDrawOrder.length != 2)
throw new SyntaxException(scanner, "Unrecognised drawOrder type " + value);
int fulltype;
try {
fulltype = Integer.decode(typeDrawOrder[0]);
} catch (NumberFormatException e) {
throw new SyntaxException(scanner, "Bad number " + typeDrawOrder[0]);
}
int type;
int subtype = 0;
if (fulltype >= 0x100) {
type = (fulltype >>> 8) & 0x3fff;
subtype = fulltype & 0xff;
} else {
type = fulltype & 0xff;
}
try {
int level = Integer.parseInt(typeDrawOrder[1]);
data.addPolygonStackOrder(level, type, subtype);
} catch (NumberFormatException e) {
throw new SyntaxException(scanner, "Bad number '" + typeDrawOrder[1] + "'");
}
}
use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.
the class TypTextReader method read.
public void read(String filename, Reader r) {
TokenScanner scanner = new TokenScanner(filename, r);
// the '#' comment character is not appropriate for this file
scanner.setCommentChar(null);
ProcessSection currentSection = null;
while (!scanner.isEndOfFile()) {
Token tok = scanner.nextToken();
if (tok.getType() == TokType.EOF)
break;
// We deal with whole line comments here
if (tok.isValue(";")) {
scanner.skipLine();
continue;
}
if (tok.getType() == TokType.SYMBOL) {
switch(tok.getValue().charAt(0)) {
case ';':
scanner.skipLine();
break;
case '[':
ProcessSection newSection = readSectionType(scanner);
if (currentSection != null)
currentSection.finish(scanner);
currentSection = newSection;
break;
case '"':
scanner.skipLine();
break;
}
} else {
if (currentSection == null)
throw new SyntaxException(scanner, "Missing section start");
// Line inside a section
String name = tok.getValue();
String sep = scanner.nextValue();
if (!sep.equals("=") && !sep.equals(":"))
throw new SyntaxException(scanner, "Expecting '=' or ':' instead of " + sep);
String value = scanner.readLine();
currentSection.processLine(scanner, name, value);
}
scanner.skipSpace();
}
}
use of uk.me.parabola.mkgmap.scan.SyntaxException in project mkgmap by openstreetmap.
the class RulesTest method runArrangeTest.
private boolean runArrangeTest(String rule, int id) {
TokenScanner scanner = new TokenScanner("test.file", new StringReader(rule));
ExpressionReader er = new ExpressionReader(scanner, FeatureKind.POLYLINE);
Op op = er.readConditions();
boolean[] orig = evalWays(op);
Op result = arranger.arrange(op);
if (!isSolved(result))
throw new SyntaxException("Could not solve rule expression: best attempt was " + fmtExpr(result));
boolean[] after = evalWays(result);
boolean ok = Arrays.equals(after, orig);
if (ok) {
if (!onlyErrors)
System.out.println("OK: " + rule);
} else {
System.out.println("ERROR: FAILED test: " + rule);
System.out.println(" new expr: " + op);
for (int i = 0; i < orig.length; i++) {
if (orig[i] != after[i]) {
System.out.println(" way " + testWays.get(i) + ", orig=" + orig[i] + ", arranged=" + after[i]);
}
}
checkStopOnFail();
}
return ok;
}
Aggregations