move all xml theme parsing into RenderThemeHandler
This commit is contained in:
parent
ca687b2c4f
commit
970c0b6f0b
@ -27,6 +27,10 @@ import javax.xml.parsers.SAXParserFactory;
|
|||||||
import org.oscim.backend.BitmapUtils;
|
import org.oscim.backend.BitmapUtils;
|
||||||
import org.oscim.backend.Log;
|
import org.oscim.backend.Log;
|
||||||
import org.oscim.backend.canvas.Bitmap;
|
import org.oscim.backend.canvas.Bitmap;
|
||||||
|
import org.oscim.backend.canvas.Color;
|
||||||
|
import org.oscim.backend.canvas.Paint.Cap;
|
||||||
|
import org.oscim.backend.canvas.Paint.FontFamily;
|
||||||
|
import org.oscim.backend.canvas.Paint.FontStyle;
|
||||||
import org.oscim.renderer.atlas.TextureAtlas;
|
import org.oscim.renderer.atlas.TextureAtlas;
|
||||||
import org.oscim.renderer.atlas.TextureAtlas.Rect;
|
import org.oscim.renderer.atlas.TextureAtlas.Rect;
|
||||||
import org.oscim.theme.renderinstruction.Area;
|
import org.oscim.theme.renderinstruction.Area;
|
||||||
@ -45,7 +49,6 @@ import org.xml.sax.SAXParseException;
|
|||||||
import org.xml.sax.XMLReader;
|
import org.xml.sax.XMLReader;
|
||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SAX2 handler to parse XML render theme files.
|
* SAX2 handler to parse XML render theme files.
|
||||||
*/
|
*/
|
||||||
@ -139,7 +142,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mRenderTheme.complete(mRulesList, mLevel);
|
mRenderTheme.complete(mRulesList, mLevel);
|
||||||
//mRenderTheme.mTextureAtlas = mTextureAtlas;
|
// mRenderTheme.mTextureAtlas = mTextureAtlas;
|
||||||
|
|
||||||
mTextureAtlas = null;
|
mTextureAtlas = null;
|
||||||
mRulesList.clear();
|
mRulesList.clear();
|
||||||
@ -188,13 +191,13 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
|
|
||||||
else if (ELEMENT_NAME_STYLE_TEXT.equals(localName)) {
|
else if (ELEMENT_NAME_STYLE_TEXT.equals(localName)) {
|
||||||
checkState(localName, Element.STYLE);
|
checkState(localName, Element.STYLE);
|
||||||
Text text = Text.create(localName, attributes, false);
|
Text text = createText(localName, attributes, false);
|
||||||
tmpStyleHash.put("t" + text.style, text);
|
tmpStyleHash.put("t" + text.style, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (ELEMENT_NAME_STYLE_AREA.equals(localName)) {
|
else if (ELEMENT_NAME_STYLE_AREA.equals(localName)) {
|
||||||
checkState(localName, Element.STYLE);
|
checkState(localName, Element.STYLE);
|
||||||
Area area = Area.create(localName, attributes, 0);
|
Area area = createArea(localName, attributes, 0);
|
||||||
tmpStyleHash.put("a" + area.style, area);
|
tmpStyleHash.put("a" + area.style, area);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +207,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
if ((style = attributes.getValue("from")) != null) {
|
if ((style = attributes.getValue("from")) != null) {
|
||||||
RenderInstruction ri = tmpStyleHash.get("l" + style);
|
RenderInstruction ri = tmpStyleHash.get("l" + style);
|
||||||
if (ri instanceof Line) {
|
if (ri instanceof Line) {
|
||||||
Line line = Line.create((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);
|
||||||
}
|
}
|
||||||
@ -212,28 +215,28 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
Log.d(TAG, "not a style: " + style);
|
Log.d(TAG, "not a style: " + style);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Line line = Line.create(null, localName, attributes, 0, false);
|
Line line = createLine(null, localName, attributes, 0, false);
|
||||||
tmpStyleHash.put("l" + line.style, line);
|
tmpStyleHash.put("l" + line.style, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (ELEMENT_NAME_STYLE_OUTLINE.equals(localName)) {
|
else if (ELEMENT_NAME_STYLE_OUTLINE.equals(localName)) {
|
||||||
checkState(localName, Element.RENDERING_INSTRUCTION);
|
checkState(localName, Element.RENDERING_INSTRUCTION);
|
||||||
Line line = Line.create(null, localName, attributes, mLevel++, true);
|
Line line = createLine(null, localName, attributes, mLevel++, true);
|
||||||
tmpStyleHash.put("o" + line.style, line);
|
tmpStyleHash.put("o" + line.style, line);
|
||||||
// outlineLayers.add(line);
|
// outlineLayers.add(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ("area".equals(localName)) {
|
else if ("area".equals(localName)) {
|
||||||
checkState(localName, Element.RENDERING_INSTRUCTION);
|
checkState(localName, Element.RENDERING_INSTRUCTION);
|
||||||
Area area = Area.create(localName, attributes, mLevel++);
|
Area area = createArea(localName, attributes, mLevel++);
|
||||||
// mRuleStack.peek().addRenderingInstruction(area);
|
// mRuleStack.peek().addRenderingInstruction(area);
|
||||||
mCurrentRule.addRenderingInstruction(area);
|
mCurrentRule.addRenderingInstruction(area);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ("caption".equals(localName)) {
|
else if ("caption".equals(localName)) {
|
||||||
checkState(localName, Element.RENDERING_INSTRUCTION);
|
checkState(localName, Element.RENDERING_INSTRUCTION);
|
||||||
Text text = Text.create(localName, attributes, true);
|
Text text = createText(localName, attributes, true);
|
||||||
mCurrentRule.addRenderingInstruction(text);
|
mCurrentRule.addRenderingInstruction(text);
|
||||||
|
|
||||||
if (text.symbol != null) {
|
if (text.symbol != null) {
|
||||||
@ -246,31 +249,31 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
|
|
||||||
else if ("circle".equals(localName)) {
|
else if ("circle".equals(localName)) {
|
||||||
checkState(localName, Element.RENDERING_INSTRUCTION);
|
checkState(localName, Element.RENDERING_INSTRUCTION);
|
||||||
Circle circle = Circle.create(localName, attributes, mLevel++);
|
Circle circle = createCircle(localName, attributes, mLevel++);
|
||||||
mCurrentRule.addRenderingInstruction(circle);
|
mCurrentRule.addRenderingInstruction(circle);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ("line".equals(localName)) {
|
else if ("line".equals(localName)) {
|
||||||
checkState(localName, Element.RENDERING_INSTRUCTION);
|
checkState(localName, Element.RENDERING_INSTRUCTION);
|
||||||
Line line = Line.create(null, localName, attributes, mLevel++, false);
|
Line line = createLine(null, localName, attributes, mLevel++, false);
|
||||||
mCurrentRule.addRenderingInstruction(line);
|
mCurrentRule.addRenderingInstruction(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ("lineSymbol".equals(localName)) {
|
else if ("lineSymbol".equals(localName)) {
|
||||||
checkState(localName, Element.RENDERING_INSTRUCTION);
|
checkState(localName, Element.RENDERING_INSTRUCTION);
|
||||||
LineSymbol lineSymbol = LineSymbol.create(localName, attributes);
|
LineSymbol lineSymbol = createLineSymbol(localName, attributes);
|
||||||
mCurrentRule.addRenderingInstruction(lineSymbol);
|
mCurrentRule.addRenderingInstruction(lineSymbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ("text".equals(localName)) {
|
else if ("text".equals(localName)) {
|
||||||
checkState(localName, Element.RENDERING_INSTRUCTION);
|
checkState(localName, Element.RENDERING_INSTRUCTION);
|
||||||
Text text = Text.create(localName, attributes, false);
|
Text text = createText(localName, attributes, false);
|
||||||
mCurrentRule.addRenderingInstruction(text);
|
mCurrentRule.addRenderingInstruction(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ("symbol".equals(localName)) {
|
else if ("symbol".equals(localName)) {
|
||||||
checkState(localName, Element.RENDERING_INSTRUCTION);
|
checkState(localName, Element.RENDERING_INSTRUCTION);
|
||||||
Symbol symbol = Symbol.create(localName, attributes);
|
Symbol symbol = createSymbol(localName, attributes);
|
||||||
mCurrentRule.addRenderingInstruction(symbol);
|
mCurrentRule.addRenderingInstruction(symbol);
|
||||||
|
|
||||||
if ((symbol.texture = mTextureAtlas.getTextureRegion(symbol.src)) == null)
|
if ((symbol.texture = mTextureAtlas.getTextureRegion(symbol.src)) == null)
|
||||||
@ -286,7 +289,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
if (style != null) {
|
if (style != null) {
|
||||||
Line line = (Line) tmpStyleHash.get("l" + style);
|
Line line = (Line) tmpStyleHash.get("l" + style);
|
||||||
if (line != null) {
|
if (line != null) {
|
||||||
Line newLine = Line.create(line, localName, attributes,
|
Line newLine = createLine(line, localName, attributes,
|
||||||
mLevel++, false);
|
mLevel++, false);
|
||||||
|
|
||||||
mCurrentRule.addRenderingInstruction(newLine);
|
mCurrentRule.addRenderingInstruction(newLine);
|
||||||
@ -351,7 +354,7 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
if ("img".equals(name)) {
|
if ("img".equals(name)) {
|
||||||
img = value;
|
img = value;
|
||||||
} else if ("name".equals(name)) {
|
} else if ("name".equals(name)) {
|
||||||
//img = value;
|
// img = value;
|
||||||
} else {
|
} else {
|
||||||
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
|
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
|
||||||
}
|
}
|
||||||
@ -446,4 +449,364 @@ public class RenderThemeHandler extends DefaultHandler {
|
|||||||
checkElement(elementName, element);
|
checkElement(elementName, element);
|
||||||
mElementStack.push(element);
|
mElementStack.push(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param elementName
|
||||||
|
* the name of the XML element.
|
||||||
|
* @param attributes
|
||||||
|
* the attributes of the XML element.
|
||||||
|
* @param caption
|
||||||
|
* ...
|
||||||
|
* @return a new Text with the given rendering attributes.
|
||||||
|
*/
|
||||||
|
public static Text createText(String elementName, Attributes attributes, boolean caption) {
|
||||||
|
String textKey = null;
|
||||||
|
FontFamily fontFamily = FontFamily.DEFAULT;
|
||||||
|
FontStyle fontStyle = FontStyle.NORMAL;
|
||||||
|
float fontSize = 0;
|
||||||
|
int fill = Color.BLACK;
|
||||||
|
int stroke = Color.BLACK;
|
||||||
|
float strokeWidth = 0;
|
||||||
|
String style = null;
|
||||||
|
float dy = 0;
|
||||||
|
int priority = Integer.MAX_VALUE;
|
||||||
|
String symbol = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < attributes.getLength(); ++i) {
|
||||||
|
String name = attributes.getLocalName(i);
|
||||||
|
String value = attributes.getValue(i);
|
||||||
|
if ("name".equals(name))
|
||||||
|
style = value;
|
||||||
|
else if ("k".equals(name)) {
|
||||||
|
textKey = value.intern();
|
||||||
|
} else if ("font-family".equals(name)) {
|
||||||
|
fontFamily = FontFamily.valueOf(value.toUpperCase());
|
||||||
|
} else if ("font-style".equals(name)) {
|
||||||
|
fontStyle = FontStyle.valueOf(value.toUpperCase());
|
||||||
|
} else if ("font-size".equals(name)) {
|
||||||
|
fontSize = Float.parseFloat(value);
|
||||||
|
} else if ("fill".equals(name)) {
|
||||||
|
fill = Color.parseColor(value);
|
||||||
|
} else if ("stroke".equals(name)) {
|
||||||
|
stroke = Color.parseColor(value);
|
||||||
|
} else if ("stroke-width".equals(name)) {
|
||||||
|
strokeWidth = Float.parseFloat(value);
|
||||||
|
} else if ("caption".equals(name)) {
|
||||||
|
caption = Boolean.parseBoolean(value);
|
||||||
|
} else if ("priority".equals(name)) {
|
||||||
|
priority = Integer.parseInt(value);
|
||||||
|
} else if ("dy".equals(name)) {
|
||||||
|
dy = Float.parseFloat(value);
|
||||||
|
} else if ("symbol".equals(name)) {
|
||||||
|
symbol = value;
|
||||||
|
} else {
|
||||||
|
logUnknownAttribute(elementName, name, value, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
validateText(elementName, textKey, fontSize, strokeWidth);
|
||||||
|
|
||||||
|
return new Text(style, textKey, fontFamily, fontStyle, fontSize, fill, stroke, strokeWidth,
|
||||||
|
dy, caption, symbol, priority);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void validateText(String elementName, String textKey, float fontSize,
|
||||||
|
float strokeWidth) {
|
||||||
|
if (textKey == null) {
|
||||||
|
throw new IllegalArgumentException("missing attribute k for element: "
|
||||||
|
+ elementName);
|
||||||
|
} else if (fontSize < 0) {
|
||||||
|
throw new IllegalArgumentException("font-size must not be negative: "
|
||||||
|
+ fontSize);
|
||||||
|
} else if (strokeWidth < 0) {
|
||||||
|
throw new IllegalArgumentException("stroke-width must not be negative: "
|
||||||
|
+ strokeWidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// private static final Pattern SPLIT_PATTERN = Pattern.compile(",");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param line
|
||||||
|
* ...
|
||||||
|
* @param elementName
|
||||||
|
* the name of the XML element.
|
||||||
|
* @param attributes
|
||||||
|
* the attributes of the XML element.
|
||||||
|
* @param level
|
||||||
|
* the drawing level of this instruction.
|
||||||
|
* @param isOutline
|
||||||
|
* ...
|
||||||
|
* @return a new Line with the given rendering attributes.
|
||||||
|
*/
|
||||||
|
public static Line createLine(Line line, String elementName, Attributes attributes,
|
||||||
|
int level, boolean isOutline) {
|
||||||
|
|
||||||
|
// Style name
|
||||||
|
String style = null;
|
||||||
|
// Bitmap
|
||||||
|
// String src = null;
|
||||||
|
|
||||||
|
float width = 0;
|
||||||
|
Cap cap = Cap.ROUND;
|
||||||
|
|
||||||
|
// Extras
|
||||||
|
int fade = -1;
|
||||||
|
boolean fixed = false;
|
||||||
|
float blur = 0;
|
||||||
|
float min = 0;
|
||||||
|
|
||||||
|
// Stipple
|
||||||
|
int stipple = 0;
|
||||||
|
float stippleWidth = 0;
|
||||||
|
|
||||||
|
int color = Color.RED;
|
||||||
|
|
||||||
|
int stippleColor = Color.BLACK;
|
||||||
|
|
||||||
|
if (line != null) {
|
||||||
|
color = line.color;
|
||||||
|
fixed = line.fixed;
|
||||||
|
fade = line.fade;
|
||||||
|
cap = line.cap;
|
||||||
|
blur = line.blur;
|
||||||
|
min = line.min;
|
||||||
|
stipple = line.stipple;
|
||||||
|
stippleColor = line.stippleColor;
|
||||||
|
stippleWidth = line.stippleWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < attributes.getLength(); ++i) {
|
||||||
|
String name = attributes.getLocalName(i);
|
||||||
|
String value = attributes.getValue(i);
|
||||||
|
|
||||||
|
if ("name".equals(name))
|
||||||
|
style = value;
|
||||||
|
else if ("src".equals(name)) {
|
||||||
|
// src = value;
|
||||||
|
} else if ("stroke".equals(name)) {
|
||||||
|
color = Color.parseColor(value);
|
||||||
|
} else if ("width".equals(name)) {
|
||||||
|
width = Float.parseFloat(value);
|
||||||
|
} else if ("cap".equals(name)) {
|
||||||
|
cap = Cap.valueOf(value.toUpperCase());
|
||||||
|
} else if ("fix".equals(name)) {
|
||||||
|
fixed = Boolean.parseBoolean(value);
|
||||||
|
} else if ("stipple".equals(name)) {
|
||||||
|
stipple = Integer.parseInt(value);
|
||||||
|
} else if ("stipple-stroke".equals(name)) {
|
||||||
|
stippleColor = Color.parseColor(value);
|
||||||
|
} else if ("stipple-width".equals(name)) {
|
||||||
|
stippleWidth = Float.parseFloat(value);
|
||||||
|
} else if ("fade".equals(name)) {
|
||||||
|
fade = Integer.parseInt(value);
|
||||||
|
} else if ("min".equals(name)) {
|
||||||
|
min = Float.parseFloat(value);
|
||||||
|
} else if ("blur".equals(name)) {
|
||||||
|
blur = Float.parseFloat(value);
|
||||||
|
} else if ("from".equals(name)) {
|
||||||
|
// ignore
|
||||||
|
} else {
|
||||||
|
logUnknownAttribute(elementName, name, value, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// inherit properties from 'line'
|
||||||
|
if (line != null) {
|
||||||
|
// use stroke width relative to 'line'
|
||||||
|
width = line.width + width;
|
||||||
|
if (width <= 0)
|
||||||
|
width = 1;
|
||||||
|
|
||||||
|
} else if (!isOutline) {
|
||||||
|
validateLine(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Line(level, style, color, width, cap, fixed,
|
||||||
|
stipple, stippleColor, stippleWidth,
|
||||||
|
fade, blur, isOutline, min);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void validateLine(float strokeWidth) {
|
||||||
|
if (strokeWidth < 0) {
|
||||||
|
throw new IllegalArgumentException("width must not be negative: "
|
||||||
|
+ strokeWidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param elementName
|
||||||
|
* the name of the XML element.
|
||||||
|
* @param attributes
|
||||||
|
* the attributes of the XML element.
|
||||||
|
* @param level
|
||||||
|
* the drawing level of this instruction.
|
||||||
|
* @return a new Area with the given rendering attributes.
|
||||||
|
*/
|
||||||
|
public static Area createArea(String elementName, Attributes attributes, int level) {
|
||||||
|
String src = null;
|
||||||
|
int fill = Color.BLACK;
|
||||||
|
int stroke = Color.TRANSPARENT;
|
||||||
|
float strokeWidth = 0;
|
||||||
|
int fade = -1;
|
||||||
|
int blend = -1;
|
||||||
|
int blendFill = Color.BLACK;
|
||||||
|
String style = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < attributes.getLength(); ++i) {
|
||||||
|
String name = attributes.getLocalName(i);
|
||||||
|
String value = attributes.getValue(i);
|
||||||
|
if ("name".equals(name))
|
||||||
|
style = value;
|
||||||
|
else if ("src".equals(name)) {
|
||||||
|
src = value;
|
||||||
|
} else if ("fill".equals(name)) {
|
||||||
|
fill = Color.parseColor(value);
|
||||||
|
} else if ("stroke".equals(name)) {
|
||||||
|
stroke = Color.parseColor(value);
|
||||||
|
} else if ("stroke-width".equals(name)) {
|
||||||
|
strokeWidth = Float.parseFloat(value);
|
||||||
|
} else if ("fade".equals(name)) {
|
||||||
|
fade = Integer.parseInt(value);
|
||||||
|
} else if ("blend".equals(name)) {
|
||||||
|
blend = Integer.parseInt(value);
|
||||||
|
} else if ("blend-fill".equals(name)) {
|
||||||
|
blendFill = Color.parseColor(value);
|
||||||
|
} else {
|
||||||
|
logUnknownAttribute(elementName, name, value, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
validateArea(strokeWidth);
|
||||||
|
return new Area(style, src, fill, stroke, strokeWidth, fade, level, blend,
|
||||||
|
blendFill);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void validateArea(float strokeWidth) {
|
||||||
|
if (strokeWidth < 0) {
|
||||||
|
throw new IllegalArgumentException("stroke-width must not be negative: "
|
||||||
|
+ strokeWidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param elementName
|
||||||
|
* the name of the XML element.
|
||||||
|
* @param attributes
|
||||||
|
* the attributes of the XML element.
|
||||||
|
* @param level
|
||||||
|
* the drawing level of this instruction.
|
||||||
|
* @return a new Circle with the given rendering attributes.
|
||||||
|
*/
|
||||||
|
public static Circle createCircle(String elementName, Attributes attributes, int level) {
|
||||||
|
Float radius = null;
|
||||||
|
boolean scaleRadius = false;
|
||||||
|
int fill = Color.TRANSPARENT;
|
||||||
|
int stroke = Color.TRANSPARENT;
|
||||||
|
float strokeWidth = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < attributes.getLength(); ++i) {
|
||||||
|
String name = attributes.getLocalName(i);
|
||||||
|
String value = attributes.getValue(i);
|
||||||
|
|
||||||
|
if ("r".equals(name)) {
|
||||||
|
radius = Float.valueOf(Float.parseFloat(value));
|
||||||
|
} else if ("scale-radius".equals(name)) {
|
||||||
|
scaleRadius = Boolean.parseBoolean(value);
|
||||||
|
} else if ("fill".equals(name)) {
|
||||||
|
fill = Color.parseColor(value);
|
||||||
|
} else if ("stroke".equals(name)) {
|
||||||
|
stroke = Color.parseColor(value);
|
||||||
|
} else if ("stroke-width".equals(name)) {
|
||||||
|
strokeWidth = Float.parseFloat(value);
|
||||||
|
} else {
|
||||||
|
logUnknownAttribute(elementName, name, value, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
validateCircle(elementName, radius, strokeWidth);
|
||||||
|
return new Circle(radius, scaleRadius, fill, stroke, strokeWidth, level);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void validateCircle(String elementName, Float radius, float strokeWidth) {
|
||||||
|
if (radius == null) {
|
||||||
|
throw new IllegalArgumentException("missing attribute r for element: "
|
||||||
|
+ elementName);
|
||||||
|
} else if (radius.floatValue() < 0) {
|
||||||
|
throw new IllegalArgumentException("radius must not be negative: " + radius);
|
||||||
|
} else if (strokeWidth < 0) {
|
||||||
|
throw new IllegalArgumentException("stroke-width must not be negative: "
|
||||||
|
+ strokeWidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param elementName
|
||||||
|
* the name of the XML element.
|
||||||
|
* @param attributes
|
||||||
|
* the attributes of the XML element.
|
||||||
|
* @return a new LineSymbol with the given rendering attributes.
|
||||||
|
*/
|
||||||
|
public static LineSymbol createLineSymbol(String elementName, Attributes attributes) {
|
||||||
|
String src = null;
|
||||||
|
boolean alignCenter = false;
|
||||||
|
boolean repeat = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < attributes.getLength(); ++i) {
|
||||||
|
String name = attributes.getLocalName(i);
|
||||||
|
String value = attributes.getValue(i);
|
||||||
|
|
||||||
|
if ("src".equals(name)) {
|
||||||
|
src = value;
|
||||||
|
} else if ("align-center".equals(name)) {
|
||||||
|
alignCenter = Boolean.parseBoolean(value);
|
||||||
|
} else if ("repeat".equals(name)) {
|
||||||
|
repeat = Boolean.parseBoolean(value);
|
||||||
|
} else {
|
||||||
|
logUnknownAttribute(elementName, name, value, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
validateLineSymbol(elementName, src);
|
||||||
|
return new LineSymbol(src, alignCenter, repeat);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void validateLineSymbol(String elementName, String src) {
|
||||||
|
if (src == null) {
|
||||||
|
throw new IllegalArgumentException("missing attribute src for element: "
|
||||||
|
+ elementName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param elementName
|
||||||
|
* the name of the XML element.
|
||||||
|
* @param attributes
|
||||||
|
* the attributes of the XML element.
|
||||||
|
* @return a new Symbol with the given rendering attributes.
|
||||||
|
*/
|
||||||
|
public static Symbol createSymbol(String elementName, Attributes attributes) {
|
||||||
|
String src = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < attributes.getLength(); ++i) {
|
||||||
|
String name = attributes.getLocalName(i);
|
||||||
|
String value = attributes.getValue(i);
|
||||||
|
|
||||||
|
if ("src".equals(name)) {
|
||||||
|
src = value;
|
||||||
|
} else {
|
||||||
|
logUnknownAttribute(elementName, name, value, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
validateSymbol(elementName, src);
|
||||||
|
return new Symbol(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void validateSymbol(String elementName, String src) {
|
||||||
|
if (src == null) {
|
||||||
|
throw new IllegalArgumentException("missing attribute src for element: "
|
||||||
|
+ elementName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,60 +25,7 @@ import org.xml.sax.Attributes;
|
|||||||
* Represents a closed polygon on the map.
|
* Represents a closed polygon on the map.
|
||||||
*/
|
*/
|
||||||
public final class Area extends RenderInstruction {
|
public final class Area extends RenderInstruction {
|
||||||
/**
|
|
||||||
* @param elementName
|
|
||||||
* the name of the XML element.
|
|
||||||
* @param attributes
|
|
||||||
* the attributes of the XML element.
|
|
||||||
* @param level
|
|
||||||
* the drawing level of this instruction.
|
|
||||||
* @return a new Area with the given rendering attributes.
|
|
||||||
*/
|
|
||||||
public static Area create(String elementName, Attributes attributes, int level) {
|
|
||||||
String src = null;
|
|
||||||
int fill = Color.BLACK;
|
|
||||||
int stroke = Color.TRANSPARENT;
|
|
||||||
float strokeWidth = 0;
|
|
||||||
int fade = -1;
|
|
||||||
int blend = -1;
|
|
||||||
int blendFill = Color.BLACK;
|
|
||||||
String style = null;
|
|
||||||
|
|
||||||
for (int i = 0; i < attributes.getLength(); ++i) {
|
|
||||||
String name = attributes.getLocalName(i);
|
|
||||||
String value = attributes.getValue(i);
|
|
||||||
if ("name".equals(name))
|
|
||||||
style = value;
|
|
||||||
else if ("src".equals(name)) {
|
|
||||||
src = value;
|
|
||||||
} else if ("fill".equals(name)) {
|
|
||||||
fill = Color.parseColor(value);
|
|
||||||
} else if ("stroke".equals(name)) {
|
|
||||||
stroke = Color.parseColor(value);
|
|
||||||
} else if ("stroke-width".equals(name)) {
|
|
||||||
strokeWidth = Float.parseFloat(value);
|
|
||||||
} else if ("fade".equals(name)) {
|
|
||||||
fade = Integer.parseInt(value);
|
|
||||||
} else if ("blend".equals(name)) {
|
|
||||||
blend = Integer.parseInt(value);
|
|
||||||
} else if ("blend-fill".equals(name)) {
|
|
||||||
blendFill = Color.parseColor(value);
|
|
||||||
} else {
|
|
||||||
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
validate(strokeWidth);
|
|
||||||
return new Area(style, src, fill, stroke, strokeWidth, fade, level, blend,
|
|
||||||
blendFill);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void validate(float strokeWidth) {
|
|
||||||
if (strokeWidth < 0) {
|
|
||||||
throw new IllegalArgumentException("stroke-width must not be negative: "
|
|
||||||
+ strokeWidth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Area(int fill) {
|
public Area(int fill) {
|
||||||
this.level = 0;
|
this.level = 0;
|
||||||
@ -91,29 +38,10 @@ public final class Area extends RenderInstruction {
|
|||||||
color = fill;
|
color = fill;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param style
|
public Area(String style, String src, int fill, int stroke, float strokeWidth,
|
||||||
* ...
|
|
||||||
* @param src
|
|
||||||
* ...
|
|
||||||
* @param fill
|
|
||||||
* ...
|
|
||||||
* @param stroke
|
|
||||||
* ...
|
|
||||||
* @param strokeWidth
|
|
||||||
* ...
|
|
||||||
* @param fade
|
|
||||||
* ...
|
|
||||||
* @param level
|
|
||||||
* ...
|
|
||||||
* @param blend
|
|
||||||
* ...
|
|
||||||
* @param blendFill
|
|
||||||
* ...
|
|
||||||
*/
|
|
||||||
private Area(String style, String src, int fill, int stroke, float strokeWidth,
|
|
||||||
int fade, int level, int blend, int blendFill) {
|
int fade, int level, int blend, int blendFill) {
|
||||||
super();
|
|
||||||
this.style = style;
|
this.style = style;
|
||||||
|
|
||||||
// if (fill == Color.TRANSPARENT) {
|
// if (fill == Color.TRANSPARENT) {
|
||||||
@ -125,8 +53,8 @@ public final class Area extends RenderInstruction {
|
|||||||
// paintFill.setShader(shader);
|
// paintFill.setShader(shader);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
color = fill; //GlUtils.colorToFloatP(fill);
|
this.color = fill; //GlUtils.colorToFloatP(fill);
|
||||||
blendColor = blendFill; //GlUtils.colorToFloatP(blendFill);
|
this.blendColor = blendFill; //GlUtils.colorToFloatP(blendFill);
|
||||||
|
|
||||||
this.blend = blend;
|
this.blend = blend;
|
||||||
this.strokeWidth = strokeWidth;
|
this.strokeWidth = strokeWidth;
|
||||||
@ -139,8 +67,8 @@ public final class Area extends RenderInstruction {
|
|||||||
renderCallback.renderArea(this, this.level);
|
renderCallback.renderArea(this, this.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String style;
|
|
||||||
private final int level;
|
private final int level;
|
||||||
|
public String style;
|
||||||
public final float strokeWidth;
|
public final float strokeWidth;
|
||||||
public final int color;
|
public final int color;
|
||||||
public final int fade;
|
public final int fade;
|
||||||
|
|||||||
@ -14,66 +14,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.theme.renderinstruction;
|
package org.oscim.theme.renderinstruction;
|
||||||
|
|
||||||
import org.oscim.backend.canvas.Color;
|
|
||||||
import org.oscim.theme.IRenderCallback;
|
import org.oscim.theme.IRenderCallback;
|
||||||
import org.oscim.theme.RenderThemeHandler;
|
|
||||||
import org.xml.sax.Attributes;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a round area on the map.
|
* Represents a round area on the map.
|
||||||
*/
|
*/
|
||||||
public final class Circle extends RenderInstruction {
|
public final class Circle extends RenderInstruction {
|
||||||
/**
|
|
||||||
* @param elementName
|
|
||||||
* the name of the XML element.
|
|
||||||
* @param attributes
|
|
||||||
* the attributes of the XML element.
|
|
||||||
* @param level
|
|
||||||
* the drawing level of this instruction.
|
|
||||||
* @return a new Circle with the given rendering attributes.
|
|
||||||
*/
|
|
||||||
public static Circle create(String elementName, Attributes attributes, int level) {
|
|
||||||
Float radius = null;
|
|
||||||
boolean scaleRadius = false;
|
|
||||||
int fill = Color.TRANSPARENT;
|
|
||||||
int stroke = Color.TRANSPARENT;
|
|
||||||
float strokeWidth = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < attributes.getLength(); ++i) {
|
|
||||||
String name = attributes.getLocalName(i);
|
|
||||||
String value = attributes.getValue(i);
|
|
||||||
|
|
||||||
if ("r".equals(name)) {
|
|
||||||
radius = Float.valueOf(Float.parseFloat(value));
|
|
||||||
} else if ("scale-radius".equals(name)) {
|
|
||||||
scaleRadius = Boolean.parseBoolean(value);
|
|
||||||
} else if ("fill".equals(name)) {
|
|
||||||
fill = Color.parseColor(value);
|
|
||||||
} else if ("stroke".equals(name)) {
|
|
||||||
stroke = Color.parseColor(value);
|
|
||||||
} else if ("stroke-width".equals(name)) {
|
|
||||||
strokeWidth = Float.parseFloat(value);
|
|
||||||
} else {
|
|
||||||
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
validate(elementName, radius, strokeWidth);
|
|
||||||
return new Circle(radius, scaleRadius, fill, stroke, strokeWidth, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void validate(String elementName, Float radius, float strokeWidth) {
|
|
||||||
if (radius == null) {
|
|
||||||
throw new IllegalArgumentException("missing attribute r for element: "
|
|
||||||
+ elementName);
|
|
||||||
} else if (radius.floatValue() < 0) {
|
|
||||||
throw new IllegalArgumentException("radius must not be negative: " + radius);
|
|
||||||
} else if (strokeWidth < 0) {
|
|
||||||
throw new IllegalArgumentException("stroke-width must not be negative: "
|
|
||||||
+ strokeWidth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final int level;
|
public final int level;
|
||||||
|
|
||||||
@ -84,7 +32,7 @@ public final class Circle extends RenderInstruction {
|
|||||||
public final boolean scaleRadius;
|
public final boolean scaleRadius;
|
||||||
public final float strokeWidth;
|
public final float strokeWidth;
|
||||||
|
|
||||||
private Circle(Float radius, boolean scaleRadius, int fill, int stroke,
|
public Circle(Float radius, boolean scaleRadius, int fill, int stroke,
|
||||||
float strokeWidth, int level) {
|
float strokeWidth, int level) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
|||||||
@ -24,114 +24,6 @@ import org.xml.sax.Attributes;
|
|||||||
* Represents a polyline on the map.
|
* Represents a polyline on the map.
|
||||||
*/
|
*/
|
||||||
public final class Line extends RenderInstruction {
|
public final class Line extends RenderInstruction {
|
||||||
//private static final Pattern SPLIT_PATTERN = Pattern.compile(",");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param line
|
|
||||||
* ...
|
|
||||||
* @param elementName
|
|
||||||
* the name of the XML element.
|
|
||||||
* @param attributes
|
|
||||||
* the attributes of the XML element.
|
|
||||||
* @param level
|
|
||||||
* the drawing level of this instruction.
|
|
||||||
* @param isOutline
|
|
||||||
* ...
|
|
||||||
* @return a new Line with the given rendering attributes.
|
|
||||||
*/
|
|
||||||
public static Line create(Line line, String elementName, Attributes attributes,
|
|
||||||
int level, boolean isOutline) {
|
|
||||||
|
|
||||||
// Style name
|
|
||||||
String style = null;
|
|
||||||
// Bitmap
|
|
||||||
//String src = null;
|
|
||||||
|
|
||||||
float width = 0;
|
|
||||||
Cap cap = Cap.ROUND;
|
|
||||||
|
|
||||||
// Extras
|
|
||||||
int fade = -1;
|
|
||||||
boolean fixed = false;
|
|
||||||
float blur = 0;
|
|
||||||
float min = 0;
|
|
||||||
|
|
||||||
// Stipple
|
|
||||||
int stipple = 0;
|
|
||||||
float stippleWidth = 0;
|
|
||||||
|
|
||||||
int color = Color.RED;
|
|
||||||
|
|
||||||
int stippleColor = Color.BLACK;
|
|
||||||
|
|
||||||
if (line != null) {
|
|
||||||
color = line.color;
|
|
||||||
fixed = line.fixed;
|
|
||||||
fade = line.fade;
|
|
||||||
cap = line.cap;
|
|
||||||
blur = line.blur;
|
|
||||||
min = line.min;
|
|
||||||
stipple = line.stipple;
|
|
||||||
stippleColor = line.stippleColor;
|
|
||||||
stippleWidth = line.stippleWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < attributes.getLength(); ++i) {
|
|
||||||
String name = attributes.getLocalName(i);
|
|
||||||
String value = attributes.getValue(i);
|
|
||||||
|
|
||||||
if ("name".equals(name))
|
|
||||||
style = value;
|
|
||||||
else if ("src".equals(name)) {
|
|
||||||
//src = value;
|
|
||||||
} else if ("stroke".equals(name)) {
|
|
||||||
color = Color.parseColor(value);
|
|
||||||
} else if ("width".equals(name)) {
|
|
||||||
width = Float.parseFloat(value);
|
|
||||||
} else if ("cap".equals(name)) {
|
|
||||||
cap = Cap.valueOf(value.toUpperCase());
|
|
||||||
} else if ("fix".equals(name)) {
|
|
||||||
fixed = Boolean.parseBoolean(value);
|
|
||||||
} else if ("stipple".equals(name)) {
|
|
||||||
stipple = Integer.parseInt(value);
|
|
||||||
} else if ("stipple-stroke".equals(name)) {
|
|
||||||
stippleColor = Color.parseColor(value);
|
|
||||||
} else if ("stipple-width".equals(name)) {
|
|
||||||
stippleWidth = Float.parseFloat(value);
|
|
||||||
} else if ("fade".equals(name)) {
|
|
||||||
fade = Integer.parseInt(value);
|
|
||||||
} else if ("min".equals(name)) {
|
|
||||||
min = Float.parseFloat(value);
|
|
||||||
} else if ("blur".equals(name)) {
|
|
||||||
blur = Float.parseFloat(value);
|
|
||||||
} else if ("from".equals(name)) {
|
|
||||||
} else {
|
|
||||||
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// inherit properties from 'line'
|
|
||||||
if (line != null) {
|
|
||||||
// use stroke width relative to 'line'
|
|
||||||
width = line.width + width;
|
|
||||||
if (width <= 0)
|
|
||||||
width = 1;
|
|
||||||
|
|
||||||
} else if (!isOutline) {
|
|
||||||
validate(width);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Line(level, style, color, width, cap, fixed,
|
|
||||||
stipple, stippleColor, stippleWidth,
|
|
||||||
fade, blur, isOutline, min);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void validate(float strokeWidth) {
|
|
||||||
if (strokeWidth < 0) {
|
|
||||||
throw new IllegalArgumentException("width must not be negative: "
|
|
||||||
+ strokeWidth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// static float[] parseFloatArray(String dashString) {
|
// static float[] parseFloatArray(String dashString) {
|
||||||
// String[] dashEntries = SPLIT_PATTERN.split(dashString);
|
// String[] dashEntries = SPLIT_PATTERN.split(dashString);
|
||||||
@ -160,7 +52,7 @@ public final class Line extends RenderInstruction {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Line(int level, String style, int color, float width,
|
public Line(int level, String style, int color, float width,
|
||||||
Cap cap, boolean fixed,
|
Cap cap, boolean fixed,
|
||||||
int stipple, int stippleColor, float stippleWidth,
|
int stipple, int stippleColor, float stippleWidth,
|
||||||
int fade, float blur, boolean isOutline, float min) {
|
int fade, float blur, boolean isOutline, float min) {
|
||||||
|
|||||||
@ -15,62 +15,22 @@
|
|||||||
package org.oscim.theme.renderinstruction;
|
package org.oscim.theme.renderinstruction;
|
||||||
|
|
||||||
import org.oscim.theme.IRenderCallback;
|
import org.oscim.theme.IRenderCallback;
|
||||||
import org.oscim.theme.RenderThemeHandler;
|
|
||||||
import org.xml.sax.Attributes;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an icon along a polyline on the map.
|
* Represents an icon along a polyline on the map.
|
||||||
*/
|
*/
|
||||||
public final class LineSymbol extends RenderInstruction {
|
public final class LineSymbol extends RenderInstruction {
|
||||||
/**
|
|
||||||
* @param elementName
|
|
||||||
* the name of the XML element.
|
|
||||||
* @param attributes
|
|
||||||
* the attributes of the XML element.
|
|
||||||
* @return a new LineSymbol with the given rendering attributes.
|
|
||||||
*/
|
|
||||||
public static LineSymbol create(String elementName, Attributes attributes) {
|
|
||||||
String src = null;
|
|
||||||
boolean alignCenter = false;
|
|
||||||
boolean repeat = false;
|
|
||||||
|
|
||||||
for (int i = 0; i < attributes.getLength(); ++i) {
|
|
||||||
String name = attributes.getLocalName(i);
|
|
||||||
String value = attributes.getValue(i);
|
|
||||||
|
|
||||||
if ("src".equals(name)) {
|
|
||||||
src = value;
|
|
||||||
} else if ("align-center".equals(name)) {
|
|
||||||
alignCenter = Boolean.parseBoolean(value);
|
|
||||||
} else if ("repeat".equals(name)) {
|
|
||||||
repeat = Boolean.parseBoolean(value);
|
|
||||||
} else {
|
|
||||||
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
validate(elementName, src);
|
|
||||||
return new LineSymbol(src, alignCenter, repeat);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void validate(String elementName, String src) {
|
|
||||||
if (src == null) {
|
|
||||||
throw new IllegalArgumentException("missing attribute src for element: "
|
|
||||||
+ elementName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean alignCenter;
|
public final boolean alignCenter;
|
||||||
//public final Bitmap bitmap;
|
// public final Bitmap bitmap;
|
||||||
public final boolean repeat;
|
public final boolean repeat;
|
||||||
public final String bitmap;
|
public final String bitmap;
|
||||||
|
|
||||||
private LineSymbol(String src, boolean alignCenter, boolean repeat) {
|
public LineSymbol(String src, boolean alignCenter, boolean repeat) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.bitmap = src;
|
this.bitmap = src;
|
||||||
//this.bitmap = BitmapUtils.createBitmap(src);
|
// this.bitmap = BitmapUtils.createBitmap(src);
|
||||||
this.alignCenter = alignCenter;
|
this.alignCenter = alignCenter;
|
||||||
this.repeat = repeat;
|
this.repeat = repeat;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,44 +16,11 @@ package org.oscim.theme.renderinstruction;
|
|||||||
|
|
||||||
import org.oscim.renderer.atlas.TextureRegion;
|
import org.oscim.renderer.atlas.TextureRegion;
|
||||||
import org.oscim.theme.IRenderCallback;
|
import org.oscim.theme.IRenderCallback;
|
||||||
import org.oscim.theme.RenderThemeHandler;
|
|
||||||
import org.xml.sax.Attributes;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an icon on the map.
|
* Represents an icon on the map.
|
||||||
*/
|
*/
|
||||||
public final class Symbol extends RenderInstruction {
|
public final class Symbol extends RenderInstruction {
|
||||||
/**
|
|
||||||
* @param elementName
|
|
||||||
* the name of the XML element.
|
|
||||||
* @param attributes
|
|
||||||
* the attributes of the XML element.
|
|
||||||
* @return a new Symbol with the given rendering attributes.
|
|
||||||
*/
|
|
||||||
public static Symbol create(String elementName, Attributes attributes) {
|
|
||||||
String src = null;
|
|
||||||
|
|
||||||
for (int i = 0; i < attributes.getLength(); ++i) {
|
|
||||||
String name = attributes.getLocalName(i);
|
|
||||||
String value = attributes.getValue(i);
|
|
||||||
|
|
||||||
if ("src".equals(name)) {
|
|
||||||
src = value;
|
|
||||||
} else {
|
|
||||||
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
validate(elementName, src);
|
|
||||||
return new Symbol(src);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void validate(String elementName, String src) {
|
|
||||||
if (src == null) {
|
|
||||||
throw new IllegalArgumentException("missing attribute src for element: "
|
|
||||||
+ elementName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final String src;
|
public final String src;
|
||||||
public TextureRegion texture;
|
public TextureRegion texture;
|
||||||
|
|||||||
@ -14,10 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.theme.renderinstruction;
|
package org.oscim.theme.renderinstruction;
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import org.oscim.backend.CanvasAdapter;
|
import org.oscim.backend.CanvasAdapter;
|
||||||
import org.oscim.backend.canvas.Color;
|
|
||||||
import org.oscim.backend.canvas.Paint;
|
import org.oscim.backend.canvas.Paint;
|
||||||
import org.oscim.backend.canvas.Paint.Align;
|
import org.oscim.backend.canvas.Paint.Align;
|
||||||
import org.oscim.backend.canvas.Paint.FontFamily;
|
import org.oscim.backend.canvas.Paint.FontFamily;
|
||||||
@ -25,87 +22,12 @@ import org.oscim.backend.canvas.Paint.FontStyle;
|
|||||||
import org.oscim.backend.canvas.Paint.Style;
|
import org.oscim.backend.canvas.Paint.Style;
|
||||||
import org.oscim.renderer.atlas.TextureRegion;
|
import org.oscim.renderer.atlas.TextureRegion;
|
||||||
import org.oscim.theme.IRenderCallback;
|
import org.oscim.theme.IRenderCallback;
|
||||||
import org.oscim.theme.RenderThemeHandler;
|
|
||||||
import org.xml.sax.Attributes;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a text along a polyline on the map.
|
* Represents a text along a polyline on the map.
|
||||||
*/
|
*/
|
||||||
public final class Text extends RenderInstruction {
|
public final class Text extends RenderInstruction {
|
||||||
|
|
||||||
/**
|
|
||||||
* @param elementName
|
|
||||||
* the name of the XML element.
|
|
||||||
* @param attributes
|
|
||||||
* the attributes of the XML element.
|
|
||||||
* @param caption
|
|
||||||
* ...
|
|
||||||
* @return a new Text with the given rendering attributes.
|
|
||||||
*/
|
|
||||||
public static Text create(String elementName, Attributes attributes, boolean caption) {
|
|
||||||
String textKey = null;
|
|
||||||
FontFamily fontFamily = FontFamily.DEFAULT;
|
|
||||||
FontStyle fontStyle = FontStyle.NORMAL;
|
|
||||||
float fontSize = 0;
|
|
||||||
int fill = Color.BLACK;
|
|
||||||
int stroke = Color.BLACK;
|
|
||||||
float strokeWidth = 0;
|
|
||||||
String style = null;
|
|
||||||
float dy = 0;
|
|
||||||
int priority = Integer.MAX_VALUE;
|
|
||||||
String symbol = null;
|
|
||||||
|
|
||||||
for (int i = 0; i < attributes.getLength(); ++i) {
|
|
||||||
String name = attributes.getLocalName(i);
|
|
||||||
String value = attributes.getValue(i);
|
|
||||||
if ("name".equals(name))
|
|
||||||
style = value;
|
|
||||||
else if ("k".equals(name)) {
|
|
||||||
textKey = value.intern();
|
|
||||||
} else if ("font-family".equals(name)) {
|
|
||||||
fontFamily = FontFamily.valueOf(value.toUpperCase());
|
|
||||||
} else if ("font-style".equals(name)) {
|
|
||||||
fontStyle = FontStyle.valueOf(value.toUpperCase());
|
|
||||||
} else if ("font-size".equals(name)) {
|
|
||||||
fontSize = Float.parseFloat(value);
|
|
||||||
} else if ("fill".equals(name)) {
|
|
||||||
fill = Color.parseColor(value);
|
|
||||||
} else if ("stroke".equals(name)) {
|
|
||||||
stroke = Color.parseColor(value);
|
|
||||||
} else if ("stroke-width".equals(name)) {
|
|
||||||
strokeWidth = Float.parseFloat(value);
|
|
||||||
} else if ("caption".equals(name)) {
|
|
||||||
caption = Boolean.parseBoolean(value);
|
|
||||||
} else if ("priority".equals(name)) {
|
|
||||||
priority = Integer.parseInt(value);
|
|
||||||
} else if ("dy".equals(name)) {
|
|
||||||
dy = Float.parseFloat(value);
|
|
||||||
} else if ("symbol".equals(name)) {
|
|
||||||
symbol = value;
|
|
||||||
} else {
|
|
||||||
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
validate(elementName, textKey, fontSize, strokeWidth);
|
|
||||||
|
|
||||||
return new Text(style, textKey, fontFamily, fontStyle, fontSize, fill, stroke, strokeWidth,
|
|
||||||
dy, caption, symbol, priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void validate(String elementName, String textKey, float fontSize,
|
|
||||||
float strokeWidth) {
|
|
||||||
if (textKey == null) {
|
|
||||||
throw new IllegalArgumentException("missing attribute k for element: "
|
|
||||||
+ elementName);
|
|
||||||
} else if (fontSize < 0) {
|
|
||||||
throw new IllegalArgumentException("font-size must not be negative: "
|
|
||||||
+ fontSize);
|
|
||||||
} else if (strokeWidth < 0) {
|
|
||||||
throw new IllegalArgumentException("stroke-width must not be negative: "
|
|
||||||
+ strokeWidth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final String style;
|
public final String style;
|
||||||
|
|
||||||
@ -137,7 +59,7 @@ public final class Text extends RenderInstruction {
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Text(String style, String textKey, FontFamily fontFamily, FontStyle fontStyle,
|
public Text(String style, String textKey, FontFamily fontFamily, FontStyle fontStyle,
|
||||||
float fontSize, int fill, int outline, float strokeWidth, float dy, boolean caption,
|
float fontSize, int fill, int outline, float strokeWidth, float dy, boolean caption,
|
||||||
String symbol, int priority) {
|
String symbol, int priority) {
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user