- started overlays

- started symbol layer
- move renderer and generator out of view package
  - hopefully the last big refactoring for a while...
- improve perspective, plane should be more far away to decrease foreshortening
This commit is contained in:
Hannes Janetzek
2012-10-09 13:23:15 +02:00
parent 2713f3bc6f
commit 33d8865d7b
128 changed files with 2360 additions and 1417 deletions

View File

@@ -80,6 +80,41 @@ public final class Area extends RenderInstruction {
}
}
public Area(int fill) {
this.level = 0;
this.style = "";
this.fade = -1;
blendColor = null;
blend = -1;
strokeWidth = 0;
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];
}
/**
* @param style
* ...
* @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) {
super();

View File

@@ -25,16 +25,18 @@ import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Shader.TileMode;
final class BitmapUtils {
public 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);
String name = "/org/oscim/theme/osmarender/" + src.substring(PREFIX_JAR.length());
InputStream inputStream = BitmapUtils.class
.getResourceAsStream(name);
if (inputStream == null) {
throw new FileNotFoundException("resource not found: " + src);
throw new FileNotFoundException("resource not found: " + src + " " + name);
}
return inputStream;
} else if (src.startsWith(PREFIX_FILE)) {
@@ -51,7 +53,7 @@ final class BitmapUtils {
throw new IllegalArgumentException("invalid bitmap source: " + src);
}
static Bitmap createBitmap(String src) throws IOException {
public static Bitmap createBitmap(String src) throws IOException {
if (src == null || src.length() == 0) {
// no image source defined
return null;

View File

@@ -1,148 +0,0 @@
/*
* 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);
}
}

View File

@@ -49,7 +49,7 @@ public final class Line extends RenderInstruction {
String src = null;
int stroke = Color.BLACK;
float strokeWidth = 0;
float[] strokeDasharray = null;
int stipple = 0;
Cap strokeLinecap = Cap.ROUND;
int fade = -1;
boolean fixed = false;
@@ -75,8 +75,8 @@ public final class Line extends RenderInstruction {
stroke = Color.parseColor(value);
} else if ("width".equals(name)) {
strokeWidth = Float.parseFloat(value);
} else if ("stroke-dasharray".equals(name)) {
strokeDasharray = parseFloatArray(value);
} else if ("stipple".equals(name)) {
stipple = Integer.parseInt(value);
} else if ("cap".equals(name)) {
strokeLinecap = Cap.valueOf(value.toUpperCase(Locale.ENGLISH));
} else if ("fade".equals(name)) {
@@ -91,23 +91,43 @@ public final class Line extends RenderInstruction {
}
}
if (stipple != 0)
strokeLinecap = Cap.BUTT;
if (line != null) {
strokeWidth = line.width + strokeWidth;
if (strokeWidth <= 0)
strokeWidth = 1;
return new Line(line, style, src, stroke, strokeWidth, strokeDasharray,
return new Line(line, style, src, stroke, strokeWidth, stipple,
strokeLinecap, level, fixed, fade, blur, isOutline);
}
if (!isOutline)
validate(strokeWidth);
return new Line(style, src, stroke, strokeWidth, strokeDasharray, strokeLinecap,
return new Line(style, src, stroke, strokeWidth, stipple, strokeLinecap,
level, fixed, fade, blur, isOutline);
}
public Line(int stroke, float width, Cap cap) {
this.level = 0;
this.blur = 0;
this.cap = cap;
this.outline = false;
this.style = "";
this.width = width;
this.fixed = true;
this.fade = -1;
this.stipple = 2;
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];
}
private static void validate(float strokeWidth) {
if (strokeWidth < 0) {
throw new IllegalArgumentException("width must not be negative: "
@@ -124,34 +144,16 @@ public final class Line extends RenderInstruction {
return dashIntervals;
}
/**
*
*/
private final int level;
/**
*
*/
// public final Paint paint;
/**
*
*/
public final float width;
/**
*
*/
public final boolean round;
/**
*
*/
// public final boolean round;
public final float color[];
/**
*
*/
public final boolean outline;
/**
*
*/
public final boolean fixed;
public final int fade;
@@ -162,8 +164,34 @@ public final class Line extends RenderInstruction {
public final float blur;
public final int stipple;
/**
* @param style
* ...
* @param src
* ...
* @param stroke
* ...
* @param strokeWidth
* ...
* @param stipple
* ...
* @param strokeLinecap
* ...
* @param level
* ...
* @param fixed
* ...
* @param fade
* ...
* @param blur
* ...
* @param isOutline
* ...
*/
private Line(String style, String src, int stroke, float strokeWidth,
float[] strokeDasharray, Cap strokeLinecap, int level, boolean fixed,
int stipple, Cap strokeLinecap, int level, boolean fixed,
int fade, float blur, boolean isOutline) {
super();
@@ -183,7 +211,7 @@ public final class Line extends RenderInstruction {
// }
// paint.setStrokeCap(strokeLinecap);
round = (strokeLinecap == Cap.ROUND);
// round = (strokeLinecap == Cap.ROUND);
this.cap = strokeLinecap;
@@ -199,16 +227,43 @@ public final class Line extends RenderInstruction {
this.fixed = fixed;
this.blur = blur;
this.fade = fade;
this.stipple = stipple;
}
/**
* @param line
* ...
* @param style
* ...
* @param src
* ...
* @param stroke
* ...
* @param strokeWidth
* ...
* @param stipple
* ...
* @param strokeLinecap
* ...
* @param level
* ...
* @param fixed
* ...
* @param fade
* ...
* @param blur
* ...
* @param isOutline
* ...
*/
private Line(Line line, String style, String src, int stroke, float strokeWidth,
float[] strokeDasharray, Cap strokeLinecap, int level, boolean fixed,
int stipple, Cap strokeLinecap, int level, boolean fixed,
int fade, float blur, boolean isOutline) {
super();
this.style = style;
round = (strokeLinecap == Cap.ROUND);
// round = (strokeLinecap == Cap.ROUND);
color = line.color;
@@ -219,11 +274,13 @@ public final class Line extends RenderInstruction {
this.fade = fade;
this.cap = strokeLinecap;
this.blur = blur;
this.stipple = stipple;
}
@Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
// renderCallback.renderWay(mPaint, mLevel, mColor, mStrokeWidth, mRound, mOutline);
// renderCallback.renderWay(mPaint, mLevel, mColor, mStrokeWidth,
// mRound, mOutline);
renderCallback.renderWay(this, level);
}

View File

@@ -62,26 +62,26 @@ public final class Symbol extends RenderInstruction {
}
}
private final Bitmap mBitmap;
public final Bitmap bitmap;
private Symbol(String src) throws IOException {
public Symbol(String src) throws IOException {
super();
mBitmap = BitmapUtils.createBitmap(src);
bitmap = BitmapUtils.createBitmap(src);
}
@Override
public void destroy() {
mBitmap.recycle();
bitmap.recycle();
}
@Override
public void renderNode(IRenderCallback renderCallback, Tag[] tags) {
renderCallback.renderPointOfInterestSymbol(mBitmap);
renderCallback.renderPointOfInterestSymbol(bitmap);
}
@Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
renderCallback.renderAreaSymbol(mBitmap);
renderCallback.renderAreaSymbol(bitmap);
}
}

View File

@@ -32,15 +32,17 @@ import android.util.FloatMath;
/**
* Represents a text along a polyline on the map.
*/
public final class PathText extends RenderInstruction {
public final class Text 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.
* @param caption
* ...
* @return a new Text with the given rendering attributes.
*/
public static PathText create(String elementName, Attributes attributes) {
public static Text create(String elementName, Attributes attributes, boolean caption) {
String textKey = null;
FontFamily fontFamily = FontFamily.DEFAULT;
FontStyle fontStyle = FontStyle.NORMAL;
@@ -49,7 +51,8 @@ public final class PathText extends RenderInstruction {
int stroke = Color.BLACK;
float strokeWidth = 0;
String style = null;
// boolean caption = false;
float dy = 0;
for (int i = 0; i < attributes.getLength(); ++i) {
String name = attributes.getLocalName(i);
String value = attributes.getValue(i);
@@ -69,6 +72,10 @@ public final class PathText extends RenderInstruction {
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 ("dy".equals(name)) {
dy = Float.parseFloat(value);
} else {
RenderThemeHandler.logUnknownAttribute(elementName, name, value, i);
}
@@ -76,7 +83,7 @@ public final class PathText extends RenderInstruction {
validate(elementName, textKey, fontSize, strokeWidth);
Typeface typeface = Typeface.create(fontFamily.toTypeface(), fontStyle.toInt());
return new PathText(style, textKey, typeface, fontSize, fill, stroke, strokeWidth);
return new Text(style, textKey, typeface, fontSize, fill, stroke, strokeWidth, dy, caption);
}
private static void validate(String elementName, String textKey, float fontSize,
@@ -100,14 +107,17 @@ public final class PathText extends RenderInstruction {
public final float fontHeight;
public final float fontDescent;
public String style;
public final boolean caption;
public final float dy;
private PathText(String style, String textKey, Typeface typeface, float fontSize,
int fill, int outline, float strokeWidth) {
private Text(String style, String textKey, Typeface typeface, float fontSize,
int fill, int outline, float strokeWidth, float dy, boolean caption) {
super();
this.style = style;
this.textKey = textKey;
this.caption = caption;
this.dy = dy;
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTextAlign(Align.CENTER);
@@ -131,9 +141,18 @@ public final class PathText extends RenderInstruction {
fontDescent = FloatMath.ceil(Math.abs(fm.descent));
}
@Override
public void renderNode(IRenderCallback renderCallback, Tag[] tags) {
if (caption)
renderCallback.renderPointOfInterestCaption(this);
}
@Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
renderCallback.renderWayText(this);
if (caption)
renderCallback.renderAreaCaption(this);
else
renderCallback.renderWayText(this);
}
@Override