- start to extract android graphics dependency
- make IRenderThemeCallback more consistent
This commit is contained in:
@@ -14,12 +14,12 @@
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.graphics.Color;
|
||||
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.
|
||||
@@ -135,7 +135,7 @@ public final class Area extends RenderInstruction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
|
||||
public void renderWay(IRenderCallback renderCallback) {
|
||||
renderCallback.renderArea(this, this.level);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.theme.IRenderCallback;
|
||||
|
||||
public class AreaLevel extends RenderInstruction {
|
||||
@@ -27,7 +26,7 @@ public class AreaLevel extends RenderInstruction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
|
||||
public void renderWay(IRenderCallback renderCallback) {
|
||||
renderCallback.renderArea(this.area, level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,11 @@
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.graphics.Color;
|
||||
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.
|
||||
@@ -78,65 +75,38 @@ public final class Circle extends RenderInstruction {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
public final int level;
|
||||
|
||||
public final int fill;
|
||||
public final int outline;
|
||||
public final float radius;
|
||||
public float renderRadius;
|
||||
public final boolean scaleRadius;
|
||||
public final float strokeWidth;
|
||||
|
||||
private Circle(Float radius, boolean scaleRadius, int fill, int stroke,
|
||||
float strokeWidth, int level) {
|
||||
super();
|
||||
|
||||
mRadius = radius.floatValue();
|
||||
mScaleRadius = scaleRadius;
|
||||
this.radius = radius.floatValue();
|
||||
this.scaleRadius = scaleRadius;
|
||||
|
||||
if (fill == Color.TRANSPARENT) {
|
||||
mFill = null;
|
||||
} else {
|
||||
mFill = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mFill.setStyle(Style.FILL);
|
||||
mFill.setColor(fill);
|
||||
}
|
||||
this.fill = fill;
|
||||
this.outline = stroke;
|
||||
|
||||
if (stroke == Color.TRANSPARENT) {
|
||||
mOutline = null;
|
||||
} else {
|
||||
mOutline = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mOutline.setStyle(Style.STROKE);
|
||||
mOutline.setColor(stroke);
|
||||
}
|
||||
this.strokeWidth = strokeWidth;
|
||||
this.level = level;
|
||||
|
||||
mStrokeWidth = strokeWidth;
|
||||
mLevel = level;
|
||||
|
||||
if (!mScaleRadius) {
|
||||
mRenderRadius = mRadius;
|
||||
if (mOutline != null) {
|
||||
mOutline.setStrokeWidth(mStrokeWidth);
|
||||
}
|
||||
}
|
||||
//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);
|
||||
}
|
||||
}
|
||||
public void renderNode(IRenderCallback renderCallback) {
|
||||
renderCallback.renderPointOfInterestCircle(this, this.level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +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 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);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -17,14 +17,12 @@ package org.oscim.theme.renderinstruction;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.graphics.Color;
|
||||
import org.oscim.graphics.Paint.Cap;
|
||||
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.
|
||||
*/
|
||||
@@ -236,7 +234,7 @@ public final class Line extends RenderInstruction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
|
||||
public void renderWay(IRenderCallback renderCallback) {
|
||||
renderCallback.renderWay(this, level);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ 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;
|
||||
@@ -68,26 +67,26 @@ public final class LineSymbol extends RenderInstruction {
|
||||
}
|
||||
}
|
||||
|
||||
private final boolean mAlignCenter;
|
||||
private final Bitmap mBitmap;
|
||||
private final boolean mRepeat;
|
||||
public final boolean alignCenter;
|
||||
public final Bitmap bitmap;
|
||||
public final boolean repeat;
|
||||
|
||||
private LineSymbol(String src, boolean alignCenter, boolean repeat)
|
||||
throws IOException {
|
||||
super();
|
||||
|
||||
mBitmap = BitmapUtils.createBitmap(src);
|
||||
mAlignCenter = alignCenter;
|
||||
mRepeat = repeat;
|
||||
this.bitmap = BitmapUtils.createBitmap(src);
|
||||
this.alignCenter = alignCenter;
|
||||
this.repeat = repeat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
mBitmap.recycle();
|
||||
bitmap.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
|
||||
renderCallback.renderWaySymbol(mBitmap, mAlignCenter, mRepeat);
|
||||
public void renderWay(IRenderCallback renderCallback) {
|
||||
renderCallback.renderWaySymbol(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
*/
|
||||
package org.oscim.theme.renderinstruction;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.theme.IRenderCallback;
|
||||
|
||||
/**
|
||||
@@ -30,19 +29,15 @@ public abstract class RenderInstruction {
|
||||
/**
|
||||
* @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) {
|
||||
public void renderNode(IRenderCallback renderCallback) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
public void renderWay(IRenderCallback renderCallback) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,6 @@ 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;
|
||||
@@ -76,12 +75,12 @@ public final class Symbol extends RenderInstruction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderNode(IRenderCallback renderCallback, Tag[] tags) {
|
||||
renderCallback.renderPointOfInterestSymbol(bitmap);
|
||||
public void renderNode(IRenderCallback renderCallback) {
|
||||
renderCallback.renderPointOfInterestSymbol(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
|
||||
renderCallback.renderAreaSymbol(bitmap);
|
||||
public void renderWay(IRenderCallback renderCallback) {
|
||||
renderCallback.renderAreaSymbol(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,18 +16,17 @@ package org.oscim.theme.renderinstruction;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.graphics.Color;
|
||||
import org.oscim.graphics.Graphics;
|
||||
import org.oscim.graphics.Paint;
|
||||
import org.oscim.graphics.Paint.Align;
|
||||
import org.oscim.graphics.Paint.FontFamily;
|
||||
import org.oscim.graphics.Paint.FontStyle;
|
||||
import org.oscim.graphics.Paint.Style;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Represents a text along a polyline on the map.
|
||||
*/
|
||||
@@ -85,26 +84,10 @@ public final class Text extends RenderInstruction {
|
||||
|
||||
validate(elementName, textKey, fontSize, strokeWidth);
|
||||
|
||||
Typeface typeface = null;
|
||||
if (fontFamily == FontFamily.DEFAULT) {
|
||||
if (fontStyle == FontStyle.NORMAL)
|
||||
typeface = typefaceNormal;
|
||||
else if (fontStyle == FontStyle.BOLD)
|
||||
typeface = typefaceBold;
|
||||
}
|
||||
|
||||
if (typeface == null)
|
||||
typeface = Typeface.create(fontFamily.toTypeface(), fontStyle.toInt());
|
||||
|
||||
return new Text(style, textKey, typeface, fontSize, fill, stroke, strokeWidth, dy, caption, priority);
|
||||
return new Text(style, textKey, fontFamily, fontStyle, fontSize, fill, stroke, strokeWidth,
|
||||
dy, caption, priority);
|
||||
}
|
||||
|
||||
private static Typeface typefaceNormal = Typeface.create(FontFamily.DEFAULT.toTypeface(),
|
||||
FontStyle.NORMAL.toInt());
|
||||
|
||||
private static Typeface typefaceBold = Typeface.create(FontFamily.DEFAULT.toTypeface(),
|
||||
FontStyle.BOLD.toInt());
|
||||
|
||||
private static void validate(String elementName, String textKey, float fontSize,
|
||||
float strokeWidth) {
|
||||
if (textKey == null) {
|
||||
@@ -131,13 +114,16 @@ public final class Text extends RenderInstruction {
|
||||
|
||||
public float fontHeight;
|
||||
public float fontDescent;
|
||||
|
||||
public static Text createText(float fontSize, float strokeWidth, int fill, int outline,
|
||||
boolean billboard) {
|
||||
|
||||
return new Text("", "", typefaceNormal, fontSize, fill, outline, strokeWidth, 0, billboard, Integer.MAX_VALUE);
|
||||
return new Text("", "", FontFamily.DEFAULT, FontStyle.NORMAL,
|
||||
fontSize, fill, outline, strokeWidth, 0, billboard, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
private Text(String style, String textKey, Typeface typeface, float fontSize,
|
||||
private Text(String style, String textKey, FontFamily fontFamily, FontStyle fontStyle,
|
||||
float fontSize,
|
||||
int fill, int outline, float strokeWidth, float dy, boolean caption, int priority) {
|
||||
|
||||
this.style = style;
|
||||
@@ -146,17 +132,17 @@ public final class Text extends RenderInstruction {
|
||||
this.dy = dy;
|
||||
this.priority = priority;
|
||||
|
||||
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
paint = Graphics.res.getPaint();
|
||||
paint.setTextAlign(Align.CENTER);
|
||||
paint.setTypeface(typeface);
|
||||
paint.setTypeface(fontFamily, fontStyle);
|
||||
paint.setColor(fill);
|
||||
paint.setTextSize(fontSize);
|
||||
|
||||
if (strokeWidth > 0) {
|
||||
stroke = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
stroke = Graphics.res.getPaint();
|
||||
stroke.setStyle(Style.STROKE);
|
||||
stroke.setTextAlign(Align.CENTER);
|
||||
stroke.setTypeface(typeface);
|
||||
stroke.setTypeface(fontFamily, fontStyle);
|
||||
stroke.setColor(outline);
|
||||
stroke.setStrokeWidth(strokeWidth);
|
||||
stroke.setTextSize(fontSize);
|
||||
@@ -164,21 +150,16 @@ public final class Text extends RenderInstruction {
|
||||
stroke = null;
|
||||
|
||||
this.fontSize = fontSize;
|
||||
|
||||
FontMetrics fm = paint.getFontMetrics();
|
||||
fontHeight = (float) Math.ceil(Math.abs(fm.bottom) + Math.abs(fm.top));
|
||||
//fontDescent = (float) Math.ceil(Math.abs(fm.descent));
|
||||
fontDescent = Math.abs(fm.bottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderNode(IRenderCallback renderCallback, Tag[] tags) {
|
||||
public void renderNode(IRenderCallback renderCallback) {
|
||||
if (caption)
|
||||
renderCallback.renderPointOfInterestCaption(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
|
||||
public void renderWay(IRenderCallback renderCallback) {
|
||||
if (caption)
|
||||
renderCallback.renderAreaCaption(this);
|
||||
else
|
||||
@@ -191,8 +172,11 @@ public final class Text extends RenderInstruction {
|
||||
if (stroke != null)
|
||||
stroke.setTextSize(fontSize * scaleFactor);
|
||||
|
||||
FontMetrics fm = paint.getFontMetrics();
|
||||
fontHeight = (float) Math.ceil(Math.abs(fm.bottom) + Math.abs(fm.top));
|
||||
fontDescent = (float) Math.ceil(Math.abs(fm.descent));
|
||||
// FontMetrics fm = paint.getFontMetrics();
|
||||
// fontHeight = (float) Math.ceil(Math.abs(fm.bottom) + Math.abs(fm.top));
|
||||
// fontDescent = (float) Math.ceil(Math.abs(fm.descent));
|
||||
|
||||
fontHeight = paint.getFontHeight();
|
||||
fontDescent = paint.getFontDescent();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user