From eb6778a9076c74166b07baf4c7ffe4f7bd01de8c Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Thu, 11 Apr 2013 17:38:38 +0200 Subject: [PATCH] - start to extract android graphics dependency - make IRenderThemeCallback more consistent --- src/org/oscim/generator/TileGenerator.java | 31 ++++---- src/org/oscim/graphics/Color.java | 56 ++++++++++++++ src/org/oscim/graphics/Paint.java | 68 +++++++++++++++++ src/org/oscim/overlay/PathOverlay.java | 68 +++++++---------- src/org/oscim/renderer/layer/LineLayer.java | 3 +- src/org/oscim/renderer/layer/TextLayer.java | 23 +++--- .../oscim/renderer/overlays/GridOverlay.java | 4 +- .../oscim/renderer/overlays/TextOverlay.java | 4 +- src/org/oscim/theme/IRenderCallback.java | 24 +++--- .../oscim/theme/renderinstruction/Area.java | 6 +- .../theme/renderinstruction/AreaLevel.java | 3 +- .../oscim/theme/renderinstruction/Circle.java | 76 ++++++------------- .../theme/renderinstruction/FontFamily.java | 43 ----------- .../theme/renderinstruction/FontStyle.java | 39 ---------- .../oscim/theme/renderinstruction/Line.java | 8 +- .../theme/renderinstruction/LineSymbol.java | 19 +++-- .../renderinstruction/RenderInstruction.java | 9 +-- .../oscim/theme/renderinstruction/Symbol.java | 9 +-- .../oscim/theme/renderinstruction/Text.java | 68 +++++++---------- 19 files changed, 265 insertions(+), 296 deletions(-) create mode 100644 src/org/oscim/graphics/Color.java create mode 100644 src/org/oscim/graphics/Paint.java delete mode 100644 src/org/oscim/theme/renderinstruction/FontFamily.java delete mode 100644 src/org/oscim/theme/renderinstruction/FontStyle.java diff --git a/src/org/oscim/generator/TileGenerator.java b/src/org/oscim/generator/TileGenerator.java index 47628463..b59636a1 100644 --- a/src/org/oscim/generator/TileGenerator.java +++ b/src/org/oscim/generator/TileGenerator.java @@ -36,14 +36,15 @@ import org.oscim.renderer.layer.TextItem; import org.oscim.theme.IRenderCallback; import org.oscim.theme.RenderTheme; import org.oscim.theme.renderinstruction.Area; +import org.oscim.theme.renderinstruction.Circle; import org.oscim.theme.renderinstruction.Line; +import org.oscim.theme.renderinstruction.LineSymbol; import org.oscim.theme.renderinstruction.RenderInstruction; +import org.oscim.theme.renderinstruction.Symbol; import org.oscim.theme.renderinstruction.Text; import org.oscim.utils.LineClipper; import org.oscim.view.DebugSettings; -import android.graphics.Bitmap; -import android.graphics.Paint; import android.util.Log; /** @@ -181,13 +182,13 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback { mGeom = mDebugPoint; RenderInstruction[] ri; ri = renderTheme.matchNode(debugTagWay, (byte) 0); - renderNode(ri, debugTagWay); + renderNode(ri); // draw tile box mWay = mDebugWay; mDrawingLayer = 100 * renderLevels; ri = renderTheme.matchWay(mDebugWay.tags, (byte) 0, false); - renderWay(ri, mDebugWay.tags); + renderWay(ri); } mTile = null; @@ -278,7 +279,7 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback { return; mGeom = geom; - renderNode(ri, tags); + renderNode(ri); } @Override @@ -297,7 +298,7 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback { RenderInstruction[] ri = renderTheme.matchWay(way.tags, (byte) (mTile.zoomLevel + 0), way.closed); - renderWay(ri, way.tags); + renderWay(ri); if (debug.debugTheme && ri == null) debugUnmatched(way.closed, way.tags); @@ -317,23 +318,23 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback { ri = renderTheme.matchWay(closed ? debugTagArea : debugTagWay, (byte) 0, true); - renderWay(ri, tags); + renderWay(ri); } - private void renderWay(RenderInstruction[] ri, Tag[] tags) { + private void renderWay(RenderInstruction[] ri) { if (ri == null) return; for (int i = 0, n = ri.length; i < n; i++) - ri[i].renderWay(this, tags); + ri[i].renderWay(this); } - private void renderNode(RenderInstruction[] ri, Tag[] tags) { + private void renderNode(RenderInstruction[] ri) { if (ri == null) return; for (int i = 0, n = ri.length; i < n; i++) - ri[i].renderNode(this, tags); + ri[i].renderNode(this); } private void clearState() { @@ -494,11 +495,11 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback { } @Override - public void renderPointOfInterestCircle(float radius, Paint fill, int level) { + public void renderPointOfInterestCircle(Circle circle, int level) { } @Override - public void renderPointOfInterestSymbol(Bitmap bitmap) { + public void renderPointOfInterestSymbol(Symbol symbol) { // Log.d(TAG, "add symbol"); // if (mLayers.textureLayers == null) @@ -516,11 +517,11 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback { } @Override - public void renderAreaSymbol(Bitmap symbol) { + public void renderAreaSymbol(Symbol symbol) { } @Override - public void renderWaySymbol(Bitmap symbol, boolean alignCenter, boolean repeat) { + public void renderWaySymbol(LineSymbol symbol) { } } diff --git a/src/org/oscim/graphics/Color.java b/src/org/oscim/graphics/Color.java new file mode 100644 index 00000000..7e2bf41f --- /dev/null +++ b/src/org/oscim/graphics/Color.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.oscim.graphics; + +public class Color { + public static final int BLACK = 0xFF000000; + public static final int DKGRAY = 0xFF444444; + public static final int GRAY = 0xFF888888; + public static final int LTGRAY = 0xFFCCCCCC; + public static final int WHITE = 0xFFFFFFFF; + public static final int RED = 0xFFFF0000; + public static final int GREEN = 0xFF00FF00; + public static final int BLUE = 0xFF0000FF; + public static final int YELLOW = 0xFFFFFF00; + public static final int CYAN = 0xFF00FFFF; + public static final int MAGENTA = 0xFFFF00FF; + public static final int TRANSPARENT = 0; + + + /** + * Parse the color string, and return the corresponding color-int. + * If the string cannot be parsed, throws an IllegalArgumentException + * exception. Supported formats are: + * #RRGGBB + * #AARRGGBB + * 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', + * 'yellow', 'lightgray', 'darkgray' + */ + public static int parseColor(String colorString) { + if (colorString.charAt(0) == '#') { + // Use a long to avoid rollovers on #ffXXXXXX + long color = Long.parseLong(colorString.substring(1), 16); + if (colorString.length() == 7) { + // Set the alpha value + color |= 0x00000000ff000000; + } else if (colorString.length() != 9) { + throw new IllegalArgumentException("Unknown color"); + } + return (int)color; + } + throw new IllegalArgumentException("Unknown color"); + } +} diff --git a/src/org/oscim/graphics/Paint.java b/src/org/oscim/graphics/Paint.java new file mode 100644 index 00000000..91b866b1 --- /dev/null +++ b/src/org/oscim/graphics/Paint.java @@ -0,0 +1,68 @@ +/* + * 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 . + */ +package org.oscim.graphics; + +public interface Paint { + + public static enum Align { + CENTER, LEFT, RIGHT; + } + + public enum Cap { + BUTT, ROUND, SQUARE; + } + + public enum Style { + FILL, STROKE + } + + public enum FontFamily { + DEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, SERIF; + } + + public enum FontStyle { + BOLD, BOLD_ITALIC, ITALIC, NORMAL; + } + + int getColor(); + + int getTextHeight(String text); + + int getTextWidth(String text); + + void setBitmapShader(Bitmap bitmap); + + void setColor(int color); + + void setDashPathEffect(float[] strokeDasharray); + + void setStrokeCap(Cap cap); + + void setStrokeWidth(float width); + + void setStyle(Style style); + + void setTextAlign(Align align); + + void setTextSize(float textSize); + + void setTypeface(FontFamily fontFamily, FontStyle fontStyle); + + float measureText(String text); + + float getFontHeight(); + + float getFontDescent(); +} diff --git a/src/org/oscim/overlay/PathOverlay.java b/src/org/oscim/overlay/PathOverlay.java index a83f5149..3b8b870f 100644 --- a/src/org/oscim/overlay/PathOverlay.java +++ b/src/org/oscim/overlay/PathOverlay.java @@ -24,17 +24,16 @@ import org.oscim.core.MapPosition; import org.oscim.core.MercatorProjection; import org.oscim.core.PointD; import org.oscim.core.Tile; +import org.oscim.graphics.Paint.Cap; import org.oscim.renderer.GLRenderer.Matrices; import org.oscim.renderer.layer.Layer; import org.oscim.renderer.layer.LineLayer; import org.oscim.renderer.overlays.BasicOverlay; import org.oscim.theme.renderinstruction.Line; import org.oscim.utils.FastMath; +import org.oscim.utils.LineClipper; import org.oscim.view.MapView; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.Paint.Cap; /** This class draws a path line in given color. */ public class PathOverlay extends Overlay { @@ -43,8 +42,8 @@ public class PathOverlay extends Overlay { /* package */protected final ArrayList mPoints; /* package */boolean mUpdatePoints; - /** Paint settings. */ - protected Paint mPaint = new Paint(); + /** Line style */ + /* package */ Line mLineStyle; class RenderPath extends BasicOverlay { @@ -60,15 +59,14 @@ public class PathOverlay extends Overlay { private float[] mPPoints; private final short[] mIndex; private int mSize; - - private final Line mLine; + private final LineClipper mClipper; // limit coords private final int max = 2048; public RenderPath(MapView mapView) { super(mapView); - mLine = new Line(Color.BLUE, 3.0f, Cap.BUTT); + mClipper = new LineClipper(-max, -max, max, max); mIndex = new short[1]; mPPoints = new float[1]; mMapPoint = new PointD(); @@ -113,12 +111,12 @@ public class PathOverlay extends Overlay { int size = mSize; - // layers.clear(); LineLayer ll = (LineLayer) layers.getLayer(1, Layer.LINE); - // reset verticesCnt to reuse layer + ll.line = mLineStyle; + ll.width = ll.line.width; + + // Hack: reset verticesCnt to reuse layer ll.verticesCnt = 0; - ll.line = mLine; - ll.width = 2.5f; int x, y, px = 0, py = 0; int i = 0; @@ -167,36 +165,19 @@ public class PathOverlay extends Overlay { } } - public PathOverlay(MapView mapView, final int color) { + public PathOverlay(MapView mapView, int lineColor, float lineWidth) { super(mapView); - this.mPaint.setColor(color); - this.mPaint.setStrokeWidth(2.0f); - this.mPaint.setStyle(Paint.Style.STROKE); + + mLineStyle = new Line(lineColor, lineWidth, Cap.BUTT); this.mPoints = new ArrayList(); mLayer = new RenderPath(mapView); } - public void setColor(final int color) { - this.mPaint.setColor(color); + public PathOverlay(MapView mapView, int lineColor) { + this(mapView, lineColor, 2); } - - public void setAlpha(final int a) { - this.mPaint.setAlpha(a); - } - - public Paint getPaint() { - return mPaint; - } - - public void setPaint(final Paint pPaint) { - if (pPaint == null) { - throw new IllegalArgumentException("pPaint argument cannot be null"); - } - mPaint = pPaint; - } - /** * Draw a great circle. Calculate a point for every 100km along the path. * @@ -205,7 +186,7 @@ public class PathOverlay extends Overlay { * @param endPoint * end point of the great circle */ - public void addGreatCircle(final GeoPoint startPoint, final GeoPoint endPoint) { + public void addGreatCircle(GeoPoint startPoint, GeoPoint endPoint) { synchronized (mPoints) { // get the great circle path length in meters @@ -228,7 +209,7 @@ public class PathOverlay extends Overlay { * @param numberOfPoints * number of points to calculate along the path */ - public void addGreatCircle(final GeoPoint startPoint, final GeoPoint endPoint, + public void addGreatCircle(GeoPoint startPoint, GeoPoint endPoint, final int numberOfPoints) { // adapted from page // http://compastic.blogspot.co.uk/2011/07/how-to-draw-great-circle-on-map-in.html @@ -276,15 +257,22 @@ public class PathOverlay extends Overlay { } } - public void addPoint(final GeoPoint pt) { + public void setPoints(List pts) { synchronized (mPoints) { - mPoints.add(pt); + mPoints.clear(); + mPoints.addAll(pts); mUpdatePoints = true; - } } - public void addPoint(final int latitudeE6, final int longitudeE6) { + public void addPoint(GeoPoint pt) { + synchronized (mPoints) { + mPoints.add(pt); + mUpdatePoints = true; + } + } + + public void addPoint(int latitudeE6, int longitudeE6) { synchronized (mPoints) { mPoints.add(new GeoPoint(latitudeE6, longitudeE6)); mUpdatePoints = true; diff --git a/src/org/oscim/renderer/layer/LineLayer.java b/src/org/oscim/renderer/layer/LineLayer.java index 3fce5df4..a3645f4a 100644 --- a/src/org/oscim/renderer/layer/LineLayer.java +++ b/src/org/oscim/renderer/layer/LineLayer.java @@ -17,15 +17,14 @@ package org.oscim.renderer.layer; import java.nio.ShortBuffer; import org.oscim.core.Tile; +import org.oscim.graphics.Paint.Cap; import org.oscim.renderer.GLRenderer; import org.oscim.theme.renderinstruction.Line; import org.oscim.utils.FastMath; import org.oscim.view.MapView; -import android.graphics.Paint.Cap; /** - * @author Hannes Janetzek */ public final class LineLayer extends Layer { private static final float COORD_SCALE = GLRenderer.COORD_SCALE; diff --git a/src/org/oscim/renderer/layer/TextLayer.java b/src/org/oscim/renderer/layer/TextLayer.java index f838b5a9..b3c851e9 100644 --- a/src/org/oscim/renderer/layer/TextLayer.java +++ b/src/org/oscim/renderer/layer/TextLayer.java @@ -14,10 +14,10 @@ */ package org.oscim.renderer.layer; +import org.oscim.graphics.Canvas; +import org.oscim.graphics.Graphics; import org.oscim.renderer.TextureRenderer; -import android.graphics.Canvas; - public final class TextLayer extends TextureLayer { //private static String TAG = TextureLayer.class.getName(); @@ -39,7 +39,7 @@ public final class TextLayer extends TextureLayer { public TextLayer() { type = Layer.SYMBOL; - mCanvas = new Canvas(); + mCanvas = Graphics.res.getCanvas(); fixed = true; } @@ -139,13 +139,15 @@ public final class TextLayer extends TextureLayer { float hw = width / 2.0f; float hh = height / 2.0f; - float hh2 = 0; - if (!it.text.caption) { - // displace by baseline - float desc = it.text.fontDescent / 2; - hh2 = hh + desc; - hh = hh - desc; - } + float hh2 = hh; + //if (!it.text.caption) { + // // displace by baseline + // float desc = 0; //(hh - (height - it.text.fontDescent) / 2); + // + // //float desc = it.text.fontDescent / 2; + // hh2 = hh + desc; + // hh = hh - desc; + //} // texture coordinates short u1 = (short) (SCALE * x); @@ -240,7 +242,6 @@ public final class TextLayer extends TextureLayer { buf[pos++] = u2; buf[pos++] = v1; - // six indices to draw the four vertices numIndices += TextureRenderer.INDICES_PER_SPRITE; verticesCnt += 4; diff --git a/src/org/oscim/renderer/overlays/GridOverlay.java b/src/org/oscim/renderer/overlays/GridOverlay.java index 71653708..56bed9c4 100644 --- a/src/org/oscim/renderer/overlays/GridOverlay.java +++ b/src/org/oscim/renderer/overlays/GridOverlay.java @@ -16,6 +16,8 @@ package org.oscim.renderer.overlays; import org.oscim.core.MapPosition; import org.oscim.core.Tile; +import org.oscim.graphics.Color; +import org.oscim.graphics.Paint.Cap; import org.oscim.renderer.GLRenderer.Matrices; import org.oscim.renderer.layer.Layer; import org.oscim.renderer.layer.LineLayer; @@ -25,8 +27,6 @@ import org.oscim.theme.renderinstruction.Line; import org.oscim.theme.renderinstruction.Text; import org.oscim.view.MapView; -import android.graphics.Color; -import android.graphics.Paint.Cap; public class GridOverlay extends BasicOverlay { diff --git a/src/org/oscim/renderer/overlays/TextOverlay.java b/src/org/oscim/renderer/overlays/TextOverlay.java index 3c5334f4..7d9abca2 100644 --- a/src/org/oscim/renderer/overlays/TextOverlay.java +++ b/src/org/oscim/renderer/overlays/TextOverlay.java @@ -33,6 +33,8 @@ import java.util.HashMap; import org.oscim.core.MapPosition; import org.oscim.core.Tile; import org.oscim.generator.JobTile; +import org.oscim.graphics.Color; +import org.oscim.graphics.Paint.Cap; import org.oscim.renderer.BufferObject; import org.oscim.renderer.GLRenderer; import org.oscim.renderer.GLRenderer.Matrices; @@ -56,8 +58,6 @@ import org.oscim.utils.pool.Pool; import org.oscim.view.MapView; import org.oscim.view.MapViewPosition; -import android.graphics.Color; -import android.graphics.Paint.Cap; import android.opengl.GLES20; import android.os.SystemClock; diff --git a/src/org/oscim/theme/IRenderCallback.java b/src/org/oscim/theme/IRenderCallback.java index cb85c2d4..cdb83406 100644 --- a/src/org/oscim/theme/IRenderCallback.java +++ b/src/org/oscim/theme/IRenderCallback.java @@ -15,12 +15,12 @@ package org.oscim.theme; import org.oscim.theme.renderinstruction.Area; +import org.oscim.theme.renderinstruction.Circle; import org.oscim.theme.renderinstruction.Line; +import org.oscim.theme.renderinstruction.LineSymbol; +import org.oscim.theme.renderinstruction.Symbol; import org.oscim.theme.renderinstruction.Text; -import android.graphics.Bitmap; -import android.graphics.Paint; - /** * Callback methods for rendering areas, ways and points of interest (POIs). */ @@ -41,19 +41,17 @@ public interface IRenderCallback { * @param symbol * the symbol to be rendered. */ - void renderAreaSymbol(Bitmap symbol); + void renderAreaSymbol(Symbol symbol); /** * Renders a point of interest circle with the given parameters. * - * @param radius - * the radius of the circle. - * @param fill - * the paint to be used for rendering the circle. + * @param circle + * the circle. * @param level * the drawing level on which the circle should be rendered. */ - void renderPointOfInterestCircle(float radius, Paint fill, int level); + void renderPointOfInterestCircle(Circle circle, int level); /** * Renders a point of interest symbol with the given bitmap. @@ -61,7 +59,7 @@ public interface IRenderCallback { * @param symbol * the symbol to be rendered. */ - void renderPointOfInterestSymbol(Bitmap symbol); + void renderPointOfInterestSymbol(Symbol symbol); /** * Renders a way with the given parameters. @@ -78,12 +76,8 @@ public interface IRenderCallback { * * @param symbol * the symbol to be rendered. - * @param alignCenter - * true if the symbol should be centered, false otherwise. - * @param repeat - * true if the symbol should be repeated, false otherwise. */ - void renderWaySymbol(Bitmap symbol, boolean alignCenter, boolean repeat); + void renderWaySymbol(LineSymbol symbol); /** * Renders a way with the given text along the way path. diff --git a/src/org/oscim/theme/renderinstruction/Area.java b/src/org/oscim/theme/renderinstruction/Area.java index 9c9f2609..eeda73a6 100644 --- a/src/org/oscim/theme/renderinstruction/Area.java +++ b/src/org/oscim/theme/renderinstruction/Area.java @@ -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); } diff --git a/src/org/oscim/theme/renderinstruction/AreaLevel.java b/src/org/oscim/theme/renderinstruction/AreaLevel.java index 3803f338..0873252d 100644 --- a/src/org/oscim/theme/renderinstruction/AreaLevel.java +++ b/src/org/oscim/theme/renderinstruction/AreaLevel.java @@ -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); } } diff --git a/src/org/oscim/theme/renderinstruction/Circle.java b/src/org/oscim/theme/renderinstruction/Circle.java index 74e6be2f..5a711944 100644 --- a/src/org/oscim/theme/renderinstruction/Circle.java +++ b/src/org/oscim/theme/renderinstruction/Circle.java @@ -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); } } diff --git a/src/org/oscim/theme/renderinstruction/FontFamily.java b/src/org/oscim/theme/renderinstruction/FontFamily.java deleted file mode 100644 index 4a6f0781..00000000 --- a/src/org/oscim/theme/renderinstruction/FontFamily.java +++ /dev/null @@ -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 . - */ -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 Typeface - */ - 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); - } -} diff --git a/src/org/oscim/theme/renderinstruction/FontStyle.java b/src/org/oscim/theme/renderinstruction/FontStyle.java deleted file mode 100644 index 524a8b1c..00000000 --- a/src/org/oscim/theme/renderinstruction/FontStyle.java +++ /dev/null @@ -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 . - */ -package org.oscim.theme.renderinstruction; - -enum FontStyle { - BOLD, BOLD_ITALIC, ITALIC, NORMAL; - - /** - * @return the constant int value of this FontStyle. - * @see Typeface - */ - 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); - } -} diff --git a/src/org/oscim/theme/renderinstruction/Line.java b/src/org/oscim/theme/renderinstruction/Line.java index 6165aff9..fa5936e0 100644 --- a/src/org/oscim/theme/renderinstruction/Line.java +++ b/src/org/oscim/theme/renderinstruction/Line.java @@ -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); } diff --git a/src/org/oscim/theme/renderinstruction/LineSymbol.java b/src/org/oscim/theme/renderinstruction/LineSymbol.java index b49c588c..a667e390 100644 --- a/src/org/oscim/theme/renderinstruction/LineSymbol.java +++ b/src/org/oscim/theme/renderinstruction/LineSymbol.java @@ -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); } } diff --git a/src/org/oscim/theme/renderinstruction/RenderInstruction.java b/src/org/oscim/theme/renderinstruction/RenderInstruction.java index ba000d21..5b301adb 100644 --- a/src/org/oscim/theme/renderinstruction/RenderInstruction.java +++ b/src/org/oscim/theme/renderinstruction/RenderInstruction.java @@ -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) { } /** diff --git a/src/org/oscim/theme/renderinstruction/Symbol.java b/src/org/oscim/theme/renderinstruction/Symbol.java index dc9b0390..41c9d772 100644 --- a/src/org/oscim/theme/renderinstruction/Symbol.java +++ b/src/org/oscim/theme/renderinstruction/Symbol.java @@ -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); } } diff --git a/src/org/oscim/theme/renderinstruction/Text.java b/src/org/oscim/theme/renderinstruction/Text.java index 36e04e4d..953ed0ca 100644 --- a/src/org/oscim/theme/renderinstruction/Text.java +++ b/src/org/oscim/theme/renderinstruction/Text.java @@ -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(); } }