RenderTheme: ignore missing symbol atlas for now. formatting
This commit is contained in:
parent
d05c4ad0d1
commit
7c0e1540cb
@ -87,7 +87,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
* if an I/O error occurs while reading from the input stream.
|
* if an I/O error occurs while reading from the input stream.
|
||||||
*/
|
*/
|
||||||
public static IRenderTheme getRenderTheme(InputStream inputStream)
|
public static IRenderTheme getRenderTheme(InputStream inputStream)
|
||||||
throws SAXException, IOException {
|
throws SAXException, IOException {
|
||||||
|
|
||||||
RenderThemeHandler renderThemeHandler = new RenderThemeHandler();
|
RenderThemeHandler renderThemeHandler = new RenderThemeHandler();
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
* the XML attribute index position.
|
* the XML attribute index position.
|
||||||
*/
|
*/
|
||||||
public static void logUnknownAttribute(String element, String name,
|
public static void logUnknownAttribute(String element, String name,
|
||||||
String value, int attributeIndex) {
|
String value, int attributeIndex) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("unknown attribute in element ");
|
sb.append("unknown attribute in element ");
|
||||||
sb.append(element);
|
sb.append(element);
|
||||||
@ -128,7 +128,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
private final Stack<Element> mElementStack = new Stack<Element>();
|
private final Stack<Element> mElementStack = new Stack<Element>();
|
||||||
private final Stack<Rule> mRuleStack = new Stack<Rule>();
|
private final Stack<Rule> mRuleStack = new Stack<Rule>();
|
||||||
private final HashMap<String, RenderInstruction> tmpStyleHash =
|
private final HashMap<String, RenderInstruction> tmpStyleHash =
|
||||||
new HashMap<String, RenderInstruction>(10);
|
new HashMap<String, RenderInstruction>(10);
|
||||||
private TextureAtlas mTextureAtlas;
|
private TextureAtlas mTextureAtlas;
|
||||||
private int mLevel;
|
private int mLevel;
|
||||||
private RenderTheme mRenderTheme;
|
private RenderTheme mRenderTheme;
|
||||||
@ -174,7 +174,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName,
|
public void startElement(String uri, String localName, String qName,
|
||||||
Attributes attributes) throws SAXException {
|
Attributes attributes) throws SAXException {
|
||||||
try {
|
try {
|
||||||
if (ELEMENT_NAME_RENDER_THEME.equals(localName)) {
|
if (ELEMENT_NAME_RENDER_THEME.equals(localName)) {
|
||||||
checkState(localName, Element.RENDER_THEME);
|
checkState(localName, Element.RENDER_THEME);
|
||||||
@ -210,7 +210,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
RenderInstruction ri = tmpStyleHash.get("l" + style);
|
RenderInstruction ri = tmpStyleHash.get("l" + style);
|
||||||
if (ri instanceof Line) {
|
if (ri instanceof Line) {
|
||||||
Line line = createLine((Line) ri, localName, attributes, 0,
|
Line line = createLine((Line) ri, localName, attributes, 0,
|
||||||
false);
|
false);
|
||||||
tmpStyleHash.put("l" + line.style, line);
|
tmpStyleHash.put("l" + line.style, line);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -277,11 +277,12 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
checkState(localName, Element.RENDERING_INSTRUCTION);
|
checkState(localName, Element.RENDERING_INSTRUCTION);
|
||||||
Symbol symbol = createSymbol(localName, attributes);
|
Symbol symbol = createSymbol(localName, attributes);
|
||||||
mCurrentRule.addRenderingInstruction(symbol);
|
mCurrentRule.addRenderingInstruction(symbol);
|
||||||
|
if (mTextureAtlas != null) {
|
||||||
if ((symbol.texture = mTextureAtlas.getTextureRegion(symbol.src)) == null)
|
if ((symbol.texture = mTextureAtlas.getTextureRegion(symbol.src)) == null)
|
||||||
Log.d(TAG, "missing texture atlas item '" + symbol.src + "'");
|
Log.d(TAG, "missing texture atlas item '" + symbol.src + "'");
|
||||||
//else
|
//else
|
||||||
// Log.d(TAG, "using atlas item '" + symbol.src + "'");
|
// Log.d(TAG, "using atlas item '" + symbol.src + "'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (ELEMENT_NAME_USE_STYLE_LINE.equals(localName)) {
|
else if (ELEMENT_NAME_USE_STYLE_LINE.equals(localName)) {
|
||||||
@ -291,7 +292,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
Line line = (Line) tmpStyleHash.get("l" + style);
|
Line line = (Line) tmpStyleHash.get("l" + style);
|
||||||
if (line != null) {
|
if (line != null) {
|
||||||
Line newLine = createLine(line, localName, attributes,
|
Line newLine = createLine(line, localName, attributes,
|
||||||
mLevel++, false);
|
mLevel++, false);
|
||||||
|
|
||||||
mCurrentRule.addRenderingInstruction(newLine);
|
mCurrentRule.addRenderingInstruction(newLine);
|
||||||
}
|
}
|
||||||
@ -315,7 +316,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
Area area = (Area) tmpStyleHash.get("a" + style);
|
Area area = (Area) tmpStyleHash.get("a" + style);
|
||||||
if (area != null)
|
if (area != null)
|
||||||
mCurrentRule.addRenderingInstruction(new AreaLevel(area,
|
mCurrentRule.addRenderingInstruction(new AreaLevel(area,
|
||||||
mLevel++));
|
mLevel++));
|
||||||
else
|
else
|
||||||
Log.d(TAG, "BUG not an area style: " + style);
|
Log.d(TAG, "BUG not an area style: " + style);
|
||||||
}
|
}
|
||||||
@ -336,6 +337,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
checkState(localName, Element.ATLAS);
|
checkState(localName, Element.ATLAS);
|
||||||
createTextureRegion(localName, attributes);
|
createTextureRegion(localName, attributes);
|
||||||
} else {
|
} else {
|
||||||
|
//Log.d(TAG, "unknown element: " + localName);
|
||||||
throw new SAXException("unknown element: " + localName);
|
throw new SAXException("unknown element: " + localName);
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@ -362,8 +364,8 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
if (img == null)
|
if (img == null)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"missing attribute 'img' for element: "
|
"missing attribute 'img' for element: "
|
||||||
+ elementName);
|
+ elementName);
|
||||||
|
|
||||||
Bitmap bitmap = CanvasAdapter.g.loadBitmapAsset(IMG_PATH + img);
|
Bitmap bitmap = CanvasAdapter.g.loadBitmapAsset(IMG_PATH + img);
|
||||||
mTextureAtlas = new TextureAtlas(bitmap);
|
mTextureAtlas = new TextureAtlas(bitmap);
|
||||||
@ -383,9 +385,9 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
String[] pos = value.split(" ");
|
String[] pos = value.split(" ");
|
||||||
if (pos.length == 4) {
|
if (pos.length == 4) {
|
||||||
r = new Rect(Integer.parseInt(pos[0]),
|
r = new Rect(Integer.parseInt(pos[0]),
|
||||||
Integer.parseInt(pos[1]),
|
Integer.parseInt(pos[1]),
|
||||||
Integer.parseInt(pos[2]),
|
Integer.parseInt(pos[2]),
|
||||||
Integer.parseInt(pos[3]));
|
Integer.parseInt(pos[3]));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
|
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
|
||||||
@ -393,50 +395,49 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
if (regionName == null || r == null)
|
if (regionName == null || r == null)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"missing attribute 'name' or 'rect' for element: "
|
"missing attribute 'name' or 'rect' for element: "
|
||||||
+ elementName);
|
+ elementName);
|
||||||
|
|
||||||
mTextureAtlas.addTextureRegion(regionName.intern(), r);
|
mTextureAtlas.addTextureRegion(regionName.intern(), r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void checkElement(String elementName, Element element) throws SAXException {
|
private void checkElement(String elementName, Element element) throws SAXException {
|
||||||
Element parentElement;
|
Element parentElement;
|
||||||
switch (element) {
|
switch (element) {
|
||||||
case RENDER_THEME:
|
case RENDER_THEME:
|
||||||
if (!mElementStack.empty()) {
|
if (!mElementStack.empty()) {
|
||||||
throw new SAXException(UNEXPECTED_ELEMENT + elementName);
|
throw new SAXException(UNEXPECTED_ELEMENT + elementName);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case RULE:
|
case RULE:
|
||||||
parentElement = mElementStack.peek();
|
parentElement = mElementStack.peek();
|
||||||
if (parentElement != Element.RENDER_THEME
|
if (parentElement != Element.RENDER_THEME
|
||||||
&& parentElement != Element.RULE) {
|
&& parentElement != Element.RULE) {
|
||||||
throw new SAXException(UNEXPECTED_ELEMENT + elementName);
|
throw new SAXException(UNEXPECTED_ELEMENT + elementName);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case STYLE:
|
case STYLE:
|
||||||
parentElement = mElementStack.peek();
|
parentElement = mElementStack.peek();
|
||||||
if (parentElement != Element.RENDER_THEME) {
|
if (parentElement != Element.RENDER_THEME) {
|
||||||
throw new SAXException(UNEXPECTED_ELEMENT + elementName);
|
throw new SAXException(UNEXPECTED_ELEMENT + elementName);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case RENDERING_INSTRUCTION:
|
case RENDERING_INSTRUCTION:
|
||||||
if (mElementStack.peek() != Element.RULE) {
|
if (mElementStack.peek() != Element.RULE) {
|
||||||
throw new SAXException(UNEXPECTED_ELEMENT + elementName);
|
throw new SAXException(UNEXPECTED_ELEMENT + elementName);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case ATLAS:
|
case ATLAS:
|
||||||
parentElement = mElementStack.peek();
|
parentElement = mElementStack.peek();
|
||||||
// FIXME
|
// FIXME
|
||||||
if (parentElement != Element.RENDER_THEME
|
if (parentElement != Element.RENDER_THEME
|
||||||
&& parentElement != Element.ATLAS) {
|
&& parentElement != Element.ATLAS) {
|
||||||
throw new SAXException(UNEXPECTED_ELEMENT + elementName);
|
throw new SAXException(UNEXPECTED_ELEMENT + elementName);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new SAXException("unknown enum value: " + element);
|
throw new SAXException("unknown enum value: " + element);
|
||||||
@ -447,7 +448,6 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
mElementStack.push(element);
|
mElementStack.push(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static RenderTheme createRenderTheme(String elementName, Attributes attributes) {
|
static RenderTheme createRenderTheme(String elementName, Attributes attributes) {
|
||||||
Integer version = null;
|
Integer version = null;
|
||||||
int mapBackground = Color.WHITE;
|
int mapBackground = Color.WHITE;
|
||||||
@ -475,15 +475,15 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
|
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
throw new IllegalArgumentException("missing attribute version for element:"
|
throw new IllegalArgumentException("missing attribute version for element:"
|
||||||
+ elementName);
|
+ elementName);
|
||||||
} else if (version.intValue() != RENDER_THEME_VERSION) {
|
} else if (version.intValue() != RENDER_THEME_VERSION) {
|
||||||
throw new IllegalArgumentException("invalid render theme version:" + version);
|
throw new IllegalArgumentException("invalid render theme version:" + version);
|
||||||
} else if (baseStrokeWidth < 0) {
|
} else if (baseStrokeWidth < 0) {
|
||||||
throw new IllegalArgumentException("base-stroke-width must not be negative: "
|
throw new IllegalArgumentException("base-stroke-width must not be negative: "
|
||||||
+ baseStrokeWidth);
|
+ baseStrokeWidth);
|
||||||
} else if (baseTextSize < 0) {
|
} else if (baseTextSize < 0) {
|
||||||
throw new IllegalArgumentException("base-text-size must not be negative: "
|
throw new IllegalArgumentException("base-text-size must not be negative: "
|
||||||
+ baseTextSize);
|
+ baseTextSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RenderTheme(mapBackground, baseStrokeWidth, baseTextSize);
|
return new RenderTheme(mapBackground, baseStrokeWidth, baseTextSize);
|
||||||
@ -546,20 +546,20 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
validateText(elementName, textKey, fontSize, strokeWidth);
|
validateText(elementName, textKey, fontSize, strokeWidth);
|
||||||
|
|
||||||
return new Text(style, textKey, fontFamily, fontStyle, fontSize, fill, stroke, strokeWidth,
|
return new Text(style, textKey, fontFamily, fontStyle, fontSize, fill, stroke, strokeWidth,
|
||||||
dy, caption, symbol, priority);
|
dy, caption, symbol, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateText(String elementName, String textKey, float fontSize,
|
private static void validateText(String elementName, String textKey, float fontSize,
|
||||||
float strokeWidth) {
|
float strokeWidth) {
|
||||||
if (textKey == null) {
|
if (textKey == null) {
|
||||||
throw new IllegalArgumentException("missing attribute k for element: "
|
throw new IllegalArgumentException("missing attribute k for element: "
|
||||||
+ elementName);
|
+ elementName);
|
||||||
} else if (fontSize < 0) {
|
} else if (fontSize < 0) {
|
||||||
throw new IllegalArgumentException("font-size must not be negative: "
|
throw new IllegalArgumentException("font-size must not be negative: "
|
||||||
+ fontSize);
|
+ fontSize);
|
||||||
} else if (strokeWidth < 0) {
|
} else if (strokeWidth < 0) {
|
||||||
throw new IllegalArgumentException("stroke-width must not be negative: "
|
throw new IllegalArgumentException("stroke-width must not be negative: "
|
||||||
+ strokeWidth);
|
+ strokeWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,7 +579,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
* @return a new Line with the given rendering attributes.
|
* @return a new Line with the given rendering attributes.
|
||||||
*/
|
*/
|
||||||
private static Line createLine(Line line, String elementName, Attributes attributes,
|
private static Line createLine(Line line, String elementName, Attributes attributes,
|
||||||
int level, boolean isOutline) {
|
int level, boolean isOutline) {
|
||||||
|
|
||||||
// Style name
|
// Style name
|
||||||
String style = null;
|
String style = null;
|
||||||
@ -645,6 +645,8 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
blur = Float.parseFloat(value);
|
blur = Float.parseFloat(value);
|
||||||
} else if ("from".equals(name)) {
|
} else if ("from".equals(name)) {
|
||||||
// ignore
|
// ignore
|
||||||
|
} else if ("dasharray".equals(name)) {
|
||||||
|
// ignore
|
||||||
} else {
|
} else {
|
||||||
logUnknownAttribute(elementName, name, value, i);
|
logUnknownAttribute(elementName, name, value, i);
|
||||||
}
|
}
|
||||||
@ -662,14 +664,14 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new Line(level, style, color, width, cap, fixed,
|
return new Line(level, style, color, width, cap, fixed,
|
||||||
stipple, stippleColor, stippleWidth,
|
stipple, stippleColor, stippleWidth,
|
||||||
fade, blur, isOutline, min);
|
fade, blur, isOutline, min);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateLine(float strokeWidth) {
|
private static void validateLine(float strokeWidth) {
|
||||||
if (strokeWidth < 0) {
|
if (strokeWidth < 0) {
|
||||||
throw new IllegalArgumentException("width must not be negative: "
|
throw new IllegalArgumentException("width must not be negative: "
|
||||||
+ strokeWidth);
|
+ strokeWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -718,23 +720,28 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
validateArea(strokeWidth);
|
validateArea(strokeWidth);
|
||||||
|
|
||||||
if (src != null){
|
if (src != null) {
|
||||||
Bitmap b = CanvasAdapter.g.loadBitmapAsset(src);
|
try {
|
||||||
if (b != null)
|
Bitmap b = CanvasAdapter.g.loadBitmapAsset(src);
|
||||||
texture = new TextureItem(b, true);
|
if (b != null)
|
||||||
|
|
||||||
|
texture = new TextureItem(b, true);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.d(TAG, e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return new Area(style, fill, stroke, strokeWidth, fade, level, blend,
|
return new Area(style, fill, stroke, strokeWidth, fade, level, blend,
|
||||||
blendFill, texture);
|
blendFill, texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateArea(float strokeWidth) {
|
private static void validateArea(float strokeWidth) {
|
||||||
if (strokeWidth < 0) {
|
if (strokeWidth < 0) {
|
||||||
throw new IllegalArgumentException("stroke-width must not be negative: "
|
throw new IllegalArgumentException("stroke-width must not be negative: "
|
||||||
+ strokeWidth);
|
+ strokeWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -758,7 +765,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
String name = attributes.getLocalName(i);
|
String name = attributes.getLocalName(i);
|
||||||
String value = attributes.getValue(i);
|
String value = attributes.getValue(i);
|
||||||
|
|
||||||
if ("r".equals(name)) {
|
if ("r".equals(name) || "radius".equals(name)) {
|
||||||
radius = Float.valueOf(Float.parseFloat(value));
|
radius = Float.valueOf(Float.parseFloat(value));
|
||||||
} else if ("scale-radius".equals(name)) {
|
} else if ("scale-radius".equals(name)) {
|
||||||
scaleRadius = Boolean.parseBoolean(value);
|
scaleRadius = Boolean.parseBoolean(value);
|
||||||
@ -780,12 +787,12 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
private static void validateCircle(String elementName, Float radius, float strokeWidth) {
|
private static void validateCircle(String elementName, Float radius, float strokeWidth) {
|
||||||
if (radius == null) {
|
if (radius == null) {
|
||||||
throw new IllegalArgumentException("missing attribute r for element: "
|
throw new IllegalArgumentException("missing attribute r for element: "
|
||||||
+ elementName);
|
+ elementName);
|
||||||
} else if (radius.floatValue() < 0) {
|
} else if (radius.floatValue() < 0) {
|
||||||
throw new IllegalArgumentException("radius must not be negative: " + radius);
|
throw new IllegalArgumentException("radius must not be negative: " + radius);
|
||||||
} else if (strokeWidth < 0) {
|
} else if (strokeWidth < 0) {
|
||||||
throw new IllegalArgumentException("stroke-width must not be negative: "
|
throw new IllegalArgumentException("stroke-width must not be negative: "
|
||||||
+ strokeWidth);
|
+ strokeWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -823,7 +830,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
private static void validateLineSymbol(String elementName, String src) {
|
private static void validateLineSymbol(String elementName, String src) {
|
||||||
if (src == null) {
|
if (src == null) {
|
||||||
throw new IllegalArgumentException("missing attribute src for element: "
|
throw new IllegalArgumentException("missing attribute src for element: "
|
||||||
+ elementName);
|
+ elementName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -855,7 +862,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
private static void validateSymbol(String elementName, String src) {
|
private static void validateSymbol(String elementName, String src) {
|
||||||
if (src == null) {
|
if (src == null) {
|
||||||
throw new IllegalArgumentException("missing attribute src for element: "
|
throw new IllegalArgumentException("missing attribute src for element: "
|
||||||
+ elementName);
|
+ elementName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user