switch package org.mapsforge -> org.oscim
This commit is contained in:
179
src/org/oscim/theme/renderinstruction/Area.java
Normal file
179
src/org/oscim/theme/renderinstruction/Area.java
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.theme.IRenderCallback;
|
||||
import org.oscim.theme.RenderThemeHandler;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
/**
|
||||
* Represents a closed polygon on the map.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private Area(String style, String src, int fill, int stroke, float strokeWidth,
|
||||
int fade, int level, int blend, int blendFill) {
|
||||
super();
|
||||
this.style = style;
|
||||
|
||||
// if (fill == Color.TRANSPARENT) {
|
||||
// paintFill = null;
|
||||
// } else {
|
||||
// paintFill = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
// if (src != null) {
|
||||
// Shader shader = BitmapUtils.createBitmapShader(src);
|
||||
// paintFill.setShader(shader);
|
||||
// }
|
||||
// paintFill.setStyle(Style.FILL);
|
||||
// paintFill.setColor(fill);
|
||||
// paintFill.setStrokeCap(Cap.ROUND);
|
||||
// }
|
||||
//
|
||||
// if (stroke == Color.TRANSPARENT) {
|
||||
// paintOutline = null;
|
||||
// } else {
|
||||
// paintOutline = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
// paintOutline.setStyle(Style.STROKE);
|
||||
// paintOutline.setColor(stroke);
|
||||
// paintOutline.setStrokeCap(Cap.ROUND);
|
||||
// }
|
||||
|
||||
// if (stroke == Color.TRANSPARENT) {
|
||||
// stroke = null;
|
||||
// } else{
|
||||
// stroke = new Line()
|
||||
// }
|
||||
|
||||
color = new float[4];
|
||||
color[3] = (fill >> 24 & 0xff) / 255.0f;
|
||||
color[0] = (fill >> 16 & 0xff) / 255.0f * color[3];
|
||||
color[1] = (fill >> 8 & 0xff) / 255.0f * color[3];
|
||||
color[2] = (fill >> 0 & 0xff) / 255.0f * color[3];
|
||||
|
||||
if (blend > 0) {
|
||||
blendColor = new float[4];
|
||||
blendColor[3] = (blendFill >> 24 & 0xff) / 255.0f;
|
||||
blendColor[0] = (blendFill >> 16 & 0xff) / 255.0f * blendColor[3];
|
||||
blendColor[1] = (blendFill >> 8 & 0xff) / 255.0f * blendColor[3];
|
||||
blendColor[2] = (blendFill >> 0 & 0xff) / 255.0f * blendColor[3];
|
||||
} else {
|
||||
blendColor = null;
|
||||
}
|
||||
|
||||
this.blend = blend;
|
||||
this.strokeWidth = strokeWidth;
|
||||
this.fade = fade;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
|
||||
renderCallback.renderArea(this, this.level);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void scaleStrokeWidth(float scaleFactor) {
|
||||
// // if (paintOutline != null) {
|
||||
// // paintOutline.setStrokeWidth(strokeWidth * scaleFactor);
|
||||
// // }
|
||||
// }
|
||||
|
||||
public String style;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private final int level;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
// public final Paint paintFill;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
// public final Paint paintOutline;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final float strokeWidth;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final float color[];
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final int fade;
|
||||
|
||||
public final float blendColor[];
|
||||
|
||||
public final int blend;
|
||||
}
|
||||
33
src/org/oscim/theme/renderinstruction/AreaLevel.java
Normal file
33
src/org/oscim/theme/renderinstruction/AreaLevel.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.theme.IRenderCallback;
|
||||
|
||||
public class AreaLevel extends RenderInstruction {
|
||||
private final Area area;
|
||||
private final int level;
|
||||
|
||||
public AreaLevel(Area area, int level) {
|
||||
this.area = area;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
|
||||
renderCallback.renderArea(this.area, level);
|
||||
}
|
||||
}
|
||||
78
src/org/oscim/theme/renderinstruction/BitmapUtils.java
Normal file
78
src/org/oscim/theme/renderinstruction/BitmapUtils.java
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Shader.TileMode;
|
||||
|
||||
final class BitmapUtils {
|
||||
private static final String PREFIX_FILE = "file:";
|
||||
private static final String PREFIX_JAR = "jar:";
|
||||
|
||||
private static InputStream createInputStream(String src) throws FileNotFoundException {
|
||||
if (src.startsWith(PREFIX_JAR)) {
|
||||
String name = src.substring(PREFIX_JAR.length());
|
||||
InputStream inputStream = Thread.currentThread().getClass().getResourceAsStream(name);
|
||||
if (inputStream == null) {
|
||||
throw new FileNotFoundException("resource not found: " + src);
|
||||
}
|
||||
return inputStream;
|
||||
} else if (src.startsWith(PREFIX_FILE)) {
|
||||
File file = new File(src.substring(PREFIX_FILE.length()));
|
||||
if (!file.exists()) {
|
||||
throw new IllegalArgumentException("file does not exist: " + src);
|
||||
} else if (!file.isFile()) {
|
||||
throw new IllegalArgumentException("not a file: " + src);
|
||||
} else if (!file.canRead()) {
|
||||
throw new IllegalArgumentException("cannot read file: " + src);
|
||||
}
|
||||
return new FileInputStream(file);
|
||||
}
|
||||
throw new IllegalArgumentException("invalid bitmap source: " + src);
|
||||
}
|
||||
|
||||
static Bitmap createBitmap(String src) throws IOException {
|
||||
if (src == null || src.length() == 0) {
|
||||
// no image source defined
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStream inputStream = createInputStream(src);
|
||||
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
|
||||
inputStream.close();
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
static BitmapShader createBitmapShader(String src) throws IOException {
|
||||
Bitmap bitmap = BitmapUtils.createBitmap(src);
|
||||
if (bitmap == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BitmapShader(bitmap, TileMode.REPEAT, TileMode.REPEAT);
|
||||
}
|
||||
|
||||
private BitmapUtils() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
148
src/org/oscim/theme/renderinstruction/Caption.java
Normal file
148
src/org/oscim/theme/renderinstruction/Caption.java
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.theme.IRenderCallback;
|
||||
import org.oscim.theme.RenderThemeHandler;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.graphics.Paint.FontMetrics;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.FloatMath;
|
||||
|
||||
/**
|
||||
* Represents a text label on the map.
|
||||
*/
|
||||
public final class Caption extends RenderInstruction {
|
||||
/**
|
||||
* @param elementName
|
||||
* the name of the XML element.
|
||||
* @param attributes
|
||||
* the attributes of the XML element.
|
||||
* @return a new Caption with the given rendering attributes.
|
||||
*/
|
||||
public static Caption create(String elementName, Attributes attributes) {
|
||||
String textKey = null;
|
||||
float dy = 0;
|
||||
FontFamily fontFamily = FontFamily.DEFAULT;
|
||||
FontStyle fontStyle = FontStyle.NORMAL;
|
||||
float fontSize = 0;
|
||||
int fill = Color.BLACK;
|
||||
int stroke = Color.BLACK;
|
||||
float strokeWidth = 0;
|
||||
|
||||
for (int i = 0; i < attributes.getLength(); ++i) {
|
||||
String name = attributes.getLocalName(i);
|
||||
String value = attributes.getValue(i);
|
||||
|
||||
if ("k".equals(name)) {
|
||||
textKey = TextKey.getInstance(value);
|
||||
} else if ("dy".equals(name)) {
|
||||
dy = Float.parseFloat(value);
|
||||
} else if ("font-family".equals(name)) {
|
||||
fontFamily = FontFamily.valueOf(value.toUpperCase(Locale.ENGLISH));
|
||||
} else if ("font-style".equals(name)) {
|
||||
fontStyle = FontStyle.valueOf(value.toUpperCase(Locale.ENGLISH));
|
||||
} 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 {
|
||||
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
|
||||
}
|
||||
}
|
||||
|
||||
validate(elementName, textKey, fontSize, strokeWidth);
|
||||
Typeface typeface = Typeface.create(fontFamily.toTypeface(), fontStyle.toInt());
|
||||
return new Caption(textKey, dy, typeface, fontSize, fill, stroke, strokeWidth);
|
||||
}
|
||||
|
||||
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 float dy;
|
||||
public float fontSize;
|
||||
public final Paint paint;
|
||||
public final Paint stroke;
|
||||
public final String textKey;
|
||||
public final float fontHeight;
|
||||
public final float fontDescent;
|
||||
|
||||
private Caption(String textKey, float dy, Typeface typeface, float fontSize,
|
||||
int fillColor, int strokeColor, float strokeWidth) {
|
||||
super();
|
||||
|
||||
this.textKey = textKey.intern();
|
||||
this.dy = dy;
|
||||
this.fontSize = fontSize;
|
||||
|
||||
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
paint.setTextAlign(Align.CENTER);
|
||||
paint.setTypeface(typeface);
|
||||
paint.setColor(fillColor);
|
||||
|
||||
stroke = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
stroke.setStyle(Style.STROKE);
|
||||
stroke.setTextAlign(Align.CENTER);
|
||||
stroke.setTypeface(typeface);
|
||||
stroke.setColor(strokeColor);
|
||||
stroke.setStrokeWidth(strokeWidth);
|
||||
|
||||
paint.setTextSize(fontSize);
|
||||
stroke.setTextSize(fontSize);
|
||||
|
||||
FontMetrics fm = paint.getFontMetrics();
|
||||
fontHeight = FloatMath.ceil(Math.abs(fm.bottom) + Math.abs(fm.top));
|
||||
fontDescent = FloatMath.ceil(Math.abs(fm.descent));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderNode(IRenderCallback renderCallback, Tag[] tags) {
|
||||
renderCallback.renderPointOfInterestCaption(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
|
||||
renderCallback.renderAreaCaption(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scaleTextSize(float scaleFactor) {
|
||||
paint.setTextSize(fontSize * scaleFactor);
|
||||
stroke.setTextSize(fontSize * scaleFactor);
|
||||
}
|
||||
}
|
||||
142
src/org/oscim/theme/renderinstruction/Circle.java
Normal file
142
src/org/oscim/theme/renderinstruction/Circle.java
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.theme.IRenderCallback;
|
||||
import org.oscim.theme.RenderThemeHandler;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Style;
|
||||
|
||||
/**
|
||||
* Represents a round area on the map.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private final Paint mFill;
|
||||
private final int mLevel;
|
||||
private final Paint mOutline;
|
||||
private final float mRadius;
|
||||
private float mRenderRadius;
|
||||
private final boolean mScaleRadius;
|
||||
private final float mStrokeWidth;
|
||||
|
||||
private Circle(Float radius, boolean scaleRadius, int fill, int stroke,
|
||||
float strokeWidth, int level) {
|
||||
super();
|
||||
|
||||
mRadius = radius.floatValue();
|
||||
mScaleRadius = scaleRadius;
|
||||
|
||||
if (fill == Color.TRANSPARENT) {
|
||||
mFill = null;
|
||||
} else {
|
||||
mFill = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mFill.setStyle(Style.FILL);
|
||||
mFill.setColor(fill);
|
||||
}
|
||||
|
||||
if (stroke == Color.TRANSPARENT) {
|
||||
mOutline = null;
|
||||
} else {
|
||||
mOutline = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mOutline.setStyle(Style.STROKE);
|
||||
mOutline.setColor(stroke);
|
||||
}
|
||||
|
||||
mStrokeWidth = strokeWidth;
|
||||
mLevel = level;
|
||||
|
||||
if (!mScaleRadius) {
|
||||
mRenderRadius = mRadius;
|
||||
if (mOutline != null) {
|
||||
mOutline.setStrokeWidth(mStrokeWidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderNode(IRenderCallback renderCallback, Tag[] tags) {
|
||||
if (mOutline != null) {
|
||||
renderCallback.renderPointOfInterestCircle(mRenderRadius, mOutline, mLevel);
|
||||
}
|
||||
if (mFill != null) {
|
||||
renderCallback.renderPointOfInterestCircle(mRenderRadius, mFill, mLevel);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scaleStrokeWidth(float scaleFactor) {
|
||||
if (mScaleRadius) {
|
||||
mRenderRadius = mRadius * scaleFactor;
|
||||
if (mOutline != null) {
|
||||
mOutline.setStrokeWidth(mStrokeWidth * scaleFactor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
42
src/org/oscim/theme/renderinstruction/FontFamily.java
Normal file
42
src/org/oscim/theme/renderinstruction/FontFamily.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
|
||||
enum FontFamily {
|
||||
DEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, SERIF;
|
||||
|
||||
/**
|
||||
* @return the typeface object of this FontFamily.
|
||||
* @see <a href="http://developer.android.com/reference/android/graphics/Typeface.html">Typeface</a>
|
||||
*/
|
||||
Typeface toTypeface() {
|
||||
switch (this) {
|
||||
case DEFAULT:
|
||||
return Typeface.DEFAULT;
|
||||
case DEFAULT_BOLD:
|
||||
return Typeface.DEFAULT_BOLD;
|
||||
case MONOSPACE:
|
||||
return Typeface.MONOSPACE;
|
||||
case SANS_SERIF:
|
||||
return Typeface.SANS_SERIF;
|
||||
case SERIF:
|
||||
return Typeface.SERIF;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("unknown enum value: " + this);
|
||||
}
|
||||
}
|
||||
38
src/org/oscim/theme/renderinstruction/FontStyle.java
Normal file
38
src/org/oscim/theme/renderinstruction/FontStyle.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
enum FontStyle {
|
||||
BOLD, BOLD_ITALIC, ITALIC, NORMAL;
|
||||
|
||||
/**
|
||||
* @return the constant int value of this FontStyle.
|
||||
* @see <a href="http://developer.android.com/reference/android/graphics/Typeface.html">Typeface</a>
|
||||
*/
|
||||
int toInt() {
|
||||
switch (this) {
|
||||
case BOLD:
|
||||
return 1;
|
||||
case BOLD_ITALIC:
|
||||
return 3;
|
||||
case ITALIC:
|
||||
return 2;
|
||||
case NORMAL:
|
||||
return 0;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("unknown enum value: " + this);
|
||||
}
|
||||
}
|
||||
238
src/org/oscim/theme/renderinstruction/Line.java
Normal file
238
src/org/oscim/theme/renderinstruction/Line.java
Normal file
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.theme.IRenderCallback;
|
||||
import org.oscim.theme.RenderThemeHandler;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint.Cap;
|
||||
|
||||
/**
|
||||
* Represents a polyline on the map.
|
||||
*/
|
||||
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) {
|
||||
String src = null;
|
||||
int stroke = Color.BLACK;
|
||||
float strokeWidth = 0;
|
||||
float[] strokeDasharray = null;
|
||||
Cap strokeLinecap = Cap.ROUND;
|
||||
int fade = -1;
|
||||
boolean fixed = false;
|
||||
String style = null;
|
||||
float blur = 0;
|
||||
|
||||
if (line != null) {
|
||||
fixed = line.fixed;
|
||||
fade = line.fade;
|
||||
strokeLinecap = line.cap;
|
||||
blur = line.blur;
|
||||
}
|
||||
|
||||
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)) {
|
||||
stroke = Color.parseColor(value);
|
||||
} else if ("width".equals(name)) {
|
||||
strokeWidth = Float.parseFloat(value);
|
||||
} else if ("stroke-dasharray".equals(name)) {
|
||||
strokeDasharray = parseFloatArray(value);
|
||||
} else if ("cap".equals(name)) {
|
||||
strokeLinecap = Cap.valueOf(value.toUpperCase(Locale.ENGLISH));
|
||||
} else if ("fade".equals(name)) {
|
||||
fade = Integer.parseInt(value);
|
||||
} else if ("fixed".equals(name)) {
|
||||
fixed = Boolean.parseBoolean(value);
|
||||
} else if ("blur".equals(name)) {
|
||||
blur = Float.parseFloat(value);
|
||||
} else if ("from".equals(name)) {
|
||||
} else {
|
||||
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
|
||||
}
|
||||
}
|
||||
|
||||
if (line != null) {
|
||||
|
||||
strokeWidth = line.width + strokeWidth;
|
||||
if (strokeWidth <= 0)
|
||||
strokeWidth = 1;
|
||||
|
||||
return new Line(line, style, src, stroke, strokeWidth, strokeDasharray,
|
||||
strokeLinecap, level, fixed, fade, blur, isOutline);
|
||||
}
|
||||
|
||||
if (!isOutline)
|
||||
validate(strokeWidth);
|
||||
|
||||
return new Line(style, src, stroke, strokeWidth, strokeDasharray, strokeLinecap,
|
||||
level, fixed, fade, blur, isOutline);
|
||||
}
|
||||
|
||||
private static void validate(float strokeWidth) {
|
||||
if (strokeWidth < 0) {
|
||||
throw new IllegalArgumentException("width must not be negative: "
|
||||
+ strokeWidth);
|
||||
}
|
||||
}
|
||||
|
||||
static float[] parseFloatArray(String dashString) {
|
||||
String[] dashEntries = SPLIT_PATTERN.split(dashString);
|
||||
float[] dashIntervals = new float[dashEntries.length];
|
||||
for (int i = 0; i < dashEntries.length; ++i) {
|
||||
dashIntervals[i] = Float.parseFloat(dashEntries[i]);
|
||||
}
|
||||
return dashIntervals;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private final int level;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
// public final Paint paint;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final float width;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final boolean round;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final float color[];
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final boolean outline;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final boolean fixed;
|
||||
|
||||
public final int fade;
|
||||
|
||||
public final String style;
|
||||
|
||||
public final Cap cap;
|
||||
|
||||
public final float blur;
|
||||
|
||||
private Line(String style, String src, int stroke, float strokeWidth,
|
||||
float[] strokeDasharray, Cap strokeLinecap, int level, boolean fixed,
|
||||
int fade, float blur, boolean isOutline) {
|
||||
super();
|
||||
|
||||
this.style = style;
|
||||
|
||||
// paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
//
|
||||
// if (src != null) {
|
||||
// Shader shader = BitmapUtils.createBitmapShader(src);
|
||||
// paint.setShader(shader);
|
||||
// }
|
||||
//
|
||||
// paint.setStyle(Style.STROKE);
|
||||
// paint.setColor(stroke);
|
||||
// if (strokeDasharray != null) {
|
||||
// paint.setPathEffect(new DashPathEffect(strokeDasharray, 0));
|
||||
// }
|
||||
// paint.setStrokeCap(strokeLinecap);
|
||||
|
||||
round = (strokeLinecap == Cap.ROUND);
|
||||
|
||||
this.cap = strokeLinecap;
|
||||
|
||||
color = new float[4];
|
||||
color[3] = (stroke >> 24 & 0xff) / 255.0f;
|
||||
color[0] = (stroke >> 16 & 0xff) / 255.0f * color[3];
|
||||
color[1] = (stroke >> 8 & 0xff) / 255.0f * color[3];
|
||||
color[2] = (stroke >> 0 & 0xff) / 255.0f * color[3];
|
||||
|
||||
this.width = strokeWidth;
|
||||
this.level = level;
|
||||
this.outline = isOutline;
|
||||
this.fixed = fixed;
|
||||
this.blur = blur;
|
||||
this.fade = fade;
|
||||
}
|
||||
|
||||
private Line(Line line, String style, String src, int stroke, float strokeWidth,
|
||||
float[] strokeDasharray, Cap strokeLinecap, int level, boolean fixed,
|
||||
int fade, float blur, boolean isOutline) {
|
||||
super();
|
||||
|
||||
this.style = style;
|
||||
|
||||
round = (strokeLinecap == Cap.ROUND);
|
||||
|
||||
color = line.color;
|
||||
|
||||
this.width = strokeWidth;
|
||||
this.level = level;
|
||||
this.outline = isOutline;
|
||||
this.fixed = fixed;
|
||||
this.fade = fade;
|
||||
this.cap = strokeLinecap;
|
||||
this.blur = blur;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
|
||||
// renderCallback.renderWay(mPaint, mLevel, mColor, mStrokeWidth, mRound, mOutline);
|
||||
renderCallback.renderWay(this, level);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void scaleStrokeWidth(float scaleFactor) {
|
||||
// paint.setStrokeWidth(strokeWidth * scaleFactor);
|
||||
// }
|
||||
|
||||
public int getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
}
|
||||
93
src/org/oscim/theme/renderinstruction/LineSymbol.java
Normal file
93
src/org/oscim/theme/renderinstruction/LineSymbol.java
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.theme.IRenderCallback;
|
||||
import org.oscim.theme.RenderThemeHandler;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
/**
|
||||
* Represents an icon along a polyline on the map.
|
||||
*/
|
||||
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.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs while reading a resource.
|
||||
*/
|
||||
public static LineSymbol create(String elementName, Attributes attributes)
|
||||
throws IOException {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private final boolean mAlignCenter;
|
||||
private final Bitmap mBitmap;
|
||||
private final boolean mRepeat;
|
||||
|
||||
private LineSymbol(String src, boolean alignCenter, boolean repeat)
|
||||
throws IOException {
|
||||
super();
|
||||
|
||||
mBitmap = BitmapUtils.createBitmap(src);
|
||||
mAlignCenter = alignCenter;
|
||||
mRepeat = repeat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
mBitmap.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
|
||||
renderCallback.renderWaySymbol(mBitmap, mAlignCenter, mRepeat);
|
||||
}
|
||||
}
|
||||
144
src/org/oscim/theme/renderinstruction/PathText.java
Normal file
144
src/org/oscim/theme/renderinstruction/PathText.java
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.theme.IRenderCallback;
|
||||
import org.oscim.theme.RenderThemeHandler;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.graphics.Paint.FontMetrics;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.FloatMath;
|
||||
|
||||
/**
|
||||
* Represents a text along a polyline on the map.
|
||||
*/
|
||||
public final class PathText extends RenderInstruction {
|
||||
/**
|
||||
* @param elementName
|
||||
* the name of the XML element.
|
||||
* @param attributes
|
||||
* the attributes of the XML element.
|
||||
* @return a new PathText with the given rendering attributes.
|
||||
*/
|
||||
public static PathText create(String elementName, Attributes attributes) {
|
||||
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;
|
||||
|
||||
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 = TextKey.getInstance(value);
|
||||
} else if ("font-family".equals(name)) {
|
||||
fontFamily = FontFamily.valueOf(value.toUpperCase(Locale.ENGLISH));
|
||||
} else if ("font-style".equals(name)) {
|
||||
fontStyle = FontStyle.valueOf(value.toUpperCase(Locale.ENGLISH));
|
||||
} 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 {
|
||||
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
|
||||
}
|
||||
}
|
||||
|
||||
validate(elementName, textKey, fontSize, strokeWidth);
|
||||
Typeface typeface = Typeface.create(fontFamily.toTypeface(), fontStyle.toInt());
|
||||
return new PathText(style, textKey, typeface, fontSize, fill, stroke, strokeWidth);
|
||||
}
|
||||
|
||||
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 float fontSize;
|
||||
public final Paint paint;
|
||||
public Paint stroke;
|
||||
public String textKey;
|
||||
public final float fontHeight;
|
||||
public final float fontDescent;
|
||||
public String style;
|
||||
|
||||
private PathText(String style, String textKey, Typeface typeface, float fontSize,
|
||||
int fill, int outline, float strokeWidth) {
|
||||
super();
|
||||
|
||||
this.style = style;
|
||||
|
||||
this.textKey = textKey;
|
||||
|
||||
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
paint.setTextAlign(Align.CENTER);
|
||||
paint.setTypeface(typeface);
|
||||
paint.setColor(fill);
|
||||
|
||||
stroke = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
stroke.setStyle(Style.STROKE);
|
||||
stroke.setTextAlign(Align.CENTER);
|
||||
stroke.setTypeface(typeface);
|
||||
stroke.setColor(outline);
|
||||
stroke.setStrokeWidth(strokeWidth);
|
||||
|
||||
this.fontSize = fontSize;
|
||||
|
||||
paint.setTextSize(fontSize);
|
||||
stroke.setTextSize(fontSize);
|
||||
|
||||
FontMetrics fm = paint.getFontMetrics();
|
||||
fontHeight = FloatMath.ceil(Math.abs(fm.bottom) + Math.abs(fm.top));
|
||||
fontDescent = FloatMath.ceil(Math.abs(fm.descent));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
|
||||
renderCallback.renderWayText(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scaleTextSize(float scaleFactor) {
|
||||
paint.setTextSize(fontSize * scaleFactor);
|
||||
stroke.setTextSize(fontSize * scaleFactor);
|
||||
}
|
||||
}
|
||||
65
src/org/oscim/theme/renderinstruction/RenderInstruction.java
Normal file
65
src/org/oscim/theme/renderinstruction/RenderInstruction.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.theme.IRenderCallback;
|
||||
|
||||
/**
|
||||
* A RenderInstruction is a basic graphical primitive to draw a map.
|
||||
*/
|
||||
public abstract class RenderInstruction {
|
||||
/**
|
||||
* Destroys this RenderInstruction and cleans up all its internal resources.
|
||||
*/
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param renderCallback
|
||||
* a reference to the receiver of all render callbacks.
|
||||
* @param tags
|
||||
* the tags of the node.
|
||||
*/
|
||||
public void renderNode(IRenderCallback renderCallback, Tag[] tags) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param renderCallback
|
||||
* a reference to the receiver of all render callbacks.
|
||||
* @param tags
|
||||
* the tags of the way.
|
||||
*/
|
||||
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales the stroke width of this RenderInstruction by the given factor.
|
||||
*
|
||||
* @param scaleFactor
|
||||
* the factor by which the stroke width should be scaled.
|
||||
*/
|
||||
public void scaleStrokeWidth(float scaleFactor) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales the text size of this RenderInstruction by the given factor.
|
||||
*
|
||||
* @param scaleFactor
|
||||
* the factor by which the text size should be scaled.
|
||||
*/
|
||||
public void scaleTextSize(float scaleFactor) {
|
||||
}
|
||||
}
|
||||
87
src/org/oscim/theme/renderinstruction/Symbol.java
Normal file
87
src/org/oscim/theme/renderinstruction/Symbol.java
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.theme.IRenderCallback;
|
||||
import org.oscim.theme.RenderThemeHandler;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
/**
|
||||
* Represents an icon on the map.
|
||||
*/
|
||||
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.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs while reading a resource.
|
||||
*/
|
||||
public static Symbol create(String elementName, Attributes attributes)
|
||||
throws IOException {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private final Bitmap mBitmap;
|
||||
|
||||
private Symbol(String src) throws IOException {
|
||||
super();
|
||||
|
||||
mBitmap = BitmapUtils.createBitmap(src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
mBitmap.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderNode(IRenderCallback renderCallback, Tag[] tags) {
|
||||
renderCallback.renderPointOfInterestSymbol(mBitmap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
|
||||
renderCallback.renderAreaSymbol(mBitmap);
|
||||
}
|
||||
}
|
||||
33
src/org/oscim/theme/renderinstruction/TextKey.java
Normal file
33
src/org/oscim/theme/renderinstruction/TextKey.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
|
||||
final class TextKey {
|
||||
static String getInstance(String key) {
|
||||
if (Tag.TAG_KEY_ELE.equals(key)) {
|
||||
return Tag.TAG_KEY_ELE;
|
||||
} else if (Tag.TAG_KEY_HOUSE_NUMBER.equals(key)) {
|
||||
return Tag.TAG_KEY_HOUSE_NUMBER;
|
||||
} else if (Tag.TAG_KEY_NAME.equals(key)) {
|
||||
return Tag.TAG_KEY_NAME;
|
||||
} else if (Tag.TAG_KEY_REF.equals(key)) {
|
||||
return Tag.TAG_KEY_REF;
|
||||
} else {
|
||||
throw new IllegalArgumentException("invalid key: " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user