- start to extract android graphics dependency

- make IRenderThemeCallback more consistent
This commit is contained in:
Hannes Janetzek 2013-04-11 17:38:38 +02:00
parent 18a8b292d2
commit eb6778a907
19 changed files with 265 additions and 296 deletions

View File

@ -36,14 +36,15 @@ import org.oscim.renderer.layer.TextItem;
import org.oscim.theme.IRenderCallback; import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderTheme; import org.oscim.theme.RenderTheme;
import org.oscim.theme.renderinstruction.Area; import org.oscim.theme.renderinstruction.Area;
import org.oscim.theme.renderinstruction.Circle;
import org.oscim.theme.renderinstruction.Line; import org.oscim.theme.renderinstruction.Line;
import org.oscim.theme.renderinstruction.LineSymbol;
import org.oscim.theme.renderinstruction.RenderInstruction; import org.oscim.theme.renderinstruction.RenderInstruction;
import org.oscim.theme.renderinstruction.Symbol;
import org.oscim.theme.renderinstruction.Text; import org.oscim.theme.renderinstruction.Text;
import org.oscim.utils.LineClipper; import org.oscim.utils.LineClipper;
import org.oscim.view.DebugSettings; import org.oscim.view.DebugSettings;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.util.Log; import android.util.Log;
/** /**
@ -181,13 +182,13 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
mGeom = mDebugPoint; mGeom = mDebugPoint;
RenderInstruction[] ri; RenderInstruction[] ri;
ri = renderTheme.matchNode(debugTagWay, (byte) 0); ri = renderTheme.matchNode(debugTagWay, (byte) 0);
renderNode(ri, debugTagWay); renderNode(ri);
// draw tile box // draw tile box
mWay = mDebugWay; mWay = mDebugWay;
mDrawingLayer = 100 * renderLevels; mDrawingLayer = 100 * renderLevels;
ri = renderTheme.matchWay(mDebugWay.tags, (byte) 0, false); ri = renderTheme.matchWay(mDebugWay.tags, (byte) 0, false);
renderWay(ri, mDebugWay.tags); renderWay(ri);
} }
mTile = null; mTile = null;
@ -278,7 +279,7 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
return; return;
mGeom = geom; mGeom = geom;
renderNode(ri, tags); renderNode(ri);
} }
@Override @Override
@ -297,7 +298,7 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
RenderInstruction[] ri = renderTheme.matchWay(way.tags, RenderInstruction[] ri = renderTheme.matchWay(way.tags,
(byte) (mTile.zoomLevel + 0), way.closed); (byte) (mTile.zoomLevel + 0), way.closed);
renderWay(ri, way.tags); renderWay(ri);
if (debug.debugTheme && ri == null) if (debug.debugTheme && ri == null)
debugUnmatched(way.closed, way.tags); debugUnmatched(way.closed, way.tags);
@ -317,23 +318,23 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
ri = renderTheme.matchWay(closed ? debugTagArea : debugTagWay, ri = renderTheme.matchWay(closed ? debugTagArea : debugTagWay,
(byte) 0, true); (byte) 0, true);
renderWay(ri, tags); renderWay(ri);
} }
private void renderWay(RenderInstruction[] ri, Tag[] tags) { private void renderWay(RenderInstruction[] ri) {
if (ri == null) if (ri == null)
return; return;
for (int i = 0, n = ri.length; i < n; i++) 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) if (ri == null)
return; return;
for (int i = 0, n = ri.length; i < n; i++) for (int i = 0, n = ri.length; i < n; i++)
ri[i].renderNode(this, tags); ri[i].renderNode(this);
} }
private void clearState() { private void clearState() {
@ -494,11 +495,11 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
} }
@Override @Override
public void renderPointOfInterestCircle(float radius, Paint fill, int level) { public void renderPointOfInterestCircle(Circle circle, int level) {
} }
@Override @Override
public void renderPointOfInterestSymbol(Bitmap bitmap) { public void renderPointOfInterestSymbol(Symbol symbol) {
// Log.d(TAG, "add symbol"); // Log.d(TAG, "add symbol");
// if (mLayers.textureLayers == null) // if (mLayers.textureLayers == null)
@ -516,11 +517,11 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
} }
@Override @Override
public void renderAreaSymbol(Bitmap symbol) { public void renderAreaSymbol(Symbol symbol) {
} }
@Override @Override
public void renderWaySymbol(Bitmap symbol, boolean alignCenter, boolean repeat) { public void renderWaySymbol(LineSymbol symbol) {
} }
} }

View File

@ -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");
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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();
}

View File

@ -24,17 +24,16 @@ import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection; import org.oscim.core.MercatorProjection;
import org.oscim.core.PointD; import org.oscim.core.PointD;
import org.oscim.core.Tile; import org.oscim.core.Tile;
import org.oscim.graphics.Paint.Cap;
import org.oscim.renderer.GLRenderer.Matrices; import org.oscim.renderer.GLRenderer.Matrices;
import org.oscim.renderer.layer.Layer; import org.oscim.renderer.layer.Layer;
import org.oscim.renderer.layer.LineLayer; import org.oscim.renderer.layer.LineLayer;
import org.oscim.renderer.overlays.BasicOverlay; import org.oscim.renderer.overlays.BasicOverlay;
import org.oscim.theme.renderinstruction.Line; import org.oscim.theme.renderinstruction.Line;
import org.oscim.utils.FastMath; import org.oscim.utils.FastMath;
import org.oscim.utils.LineClipper;
import org.oscim.view.MapView; 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. */ /** This class draws a path line in given color. */
public class PathOverlay extends Overlay { public class PathOverlay extends Overlay {
@ -43,8 +42,8 @@ public class PathOverlay extends Overlay {
/* package */protected final ArrayList<GeoPoint> mPoints; /* package */protected final ArrayList<GeoPoint> mPoints;
/* package */boolean mUpdatePoints; /* package */boolean mUpdatePoints;
/** Paint settings. */ /** Line style */
protected Paint mPaint = new Paint(); /* package */ Line mLineStyle;
class RenderPath extends BasicOverlay { class RenderPath extends BasicOverlay {
@ -60,15 +59,14 @@ public class PathOverlay extends Overlay {
private float[] mPPoints; private float[] mPPoints;
private final short[] mIndex; private final short[] mIndex;
private int mSize; private int mSize;
private final LineClipper mClipper;
private final Line mLine;
// limit coords // limit coords
private final int max = 2048; private final int max = 2048;
public RenderPath(MapView mapView) { public RenderPath(MapView mapView) {
super(mapView); super(mapView);
mLine = new Line(Color.BLUE, 3.0f, Cap.BUTT); mClipper = new LineClipper(-max, -max, max, max);
mIndex = new short[1]; mIndex = new short[1];
mPPoints = new float[1]; mPPoints = new float[1];
mMapPoint = new PointD(); mMapPoint = new PointD();
@ -113,12 +111,12 @@ public class PathOverlay extends Overlay {
int size = mSize; int size = mSize;
// layers.clear();
LineLayer ll = (LineLayer) layers.getLayer(1, Layer.LINE); 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.verticesCnt = 0;
ll.line = mLine;
ll.width = 2.5f;
int x, y, px = 0, py = 0; int x, y, px = 0, py = 0;
int i = 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); super(mapView);
this.mPaint.setColor(color);
this.mPaint.setStrokeWidth(2.0f); mLineStyle = new Line(lineColor, lineWidth, Cap.BUTT);
this.mPaint.setStyle(Paint.Style.STROKE);
this.mPoints = new ArrayList<GeoPoint>(); this.mPoints = new ArrayList<GeoPoint>();
mLayer = new RenderPath(mapView); mLayer = new RenderPath(mapView);
} }
public void setColor(final int color) { public PathOverlay(MapView mapView, int lineColor) {
this.mPaint.setColor(color); 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. * Draw a great circle. Calculate a point for every 100km along the path.
* *
@ -205,7 +186,7 @@ public class PathOverlay extends Overlay {
* @param endPoint * @param endPoint
* end point of the great circle * end point of the great circle
*/ */
public void addGreatCircle(final GeoPoint startPoint, final GeoPoint endPoint) { public void addGreatCircle(GeoPoint startPoint, GeoPoint endPoint) {
synchronized (mPoints) { synchronized (mPoints) {
// get the great circle path length in meters // get the great circle path length in meters
@ -228,7 +209,7 @@ public class PathOverlay extends Overlay {
* @param numberOfPoints * @param numberOfPoints
* number of points to calculate along the path * 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) { final int numberOfPoints) {
// adapted from page // adapted from page
// http://compastic.blogspot.co.uk/2011/07/how-to-draw-great-circle-on-map-in.html // 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<GeoPoint> pts) {
synchronized (mPoints) {
mPoints.clear();
mPoints.addAll(pts);
mUpdatePoints = true;
}
}
public void addPoint(GeoPoint pt) {
synchronized (mPoints) { synchronized (mPoints) {
mPoints.add(pt); mPoints.add(pt);
mUpdatePoints = true; mUpdatePoints = true;
} }
} }
public void addPoint(final int latitudeE6, final int longitudeE6) { public void addPoint(int latitudeE6, int longitudeE6) {
synchronized (mPoints) { synchronized (mPoints) {
mPoints.add(new GeoPoint(latitudeE6, longitudeE6)); mPoints.add(new GeoPoint(latitudeE6, longitudeE6));
mUpdatePoints = true; mUpdatePoints = true;

View File

@ -17,15 +17,14 @@ package org.oscim.renderer.layer;
import java.nio.ShortBuffer; import java.nio.ShortBuffer;
import org.oscim.core.Tile; import org.oscim.core.Tile;
import org.oscim.graphics.Paint.Cap;
import org.oscim.renderer.GLRenderer; import org.oscim.renderer.GLRenderer;
import org.oscim.theme.renderinstruction.Line; import org.oscim.theme.renderinstruction.Line;
import org.oscim.utils.FastMath; import org.oscim.utils.FastMath;
import org.oscim.view.MapView; import org.oscim.view.MapView;
import android.graphics.Paint.Cap;
/** /**
* @author Hannes Janetzek
*/ */
public final class LineLayer extends Layer { public final class LineLayer extends Layer {
private static final float COORD_SCALE = GLRenderer.COORD_SCALE; private static final float COORD_SCALE = GLRenderer.COORD_SCALE;

View File

@ -14,10 +14,10 @@
*/ */
package org.oscim.renderer.layer; package org.oscim.renderer.layer;
import org.oscim.graphics.Canvas;
import org.oscim.graphics.Graphics;
import org.oscim.renderer.TextureRenderer; import org.oscim.renderer.TextureRenderer;
import android.graphics.Canvas;
public final class TextLayer extends TextureLayer { public final class TextLayer extends TextureLayer {
//private static String TAG = TextureLayer.class.getName(); //private static String TAG = TextureLayer.class.getName();
@ -39,7 +39,7 @@ public final class TextLayer extends TextureLayer {
public TextLayer() { public TextLayer() {
type = Layer.SYMBOL; type = Layer.SYMBOL;
mCanvas = new Canvas(); mCanvas = Graphics.res.getCanvas();
fixed = true; fixed = true;
} }
@ -139,13 +139,15 @@ public final class TextLayer extends TextureLayer {
float hw = width / 2.0f; float hw = width / 2.0f;
float hh = height / 2.0f; float hh = height / 2.0f;
float hh2 = 0; float hh2 = hh;
if (!it.text.caption) { //if (!it.text.caption) {
// displace by baseline // // displace by baseline
float desc = it.text.fontDescent / 2; // float desc = 0; //(hh - (height - it.text.fontDescent) / 2);
hh2 = hh + desc; //
hh = hh - desc; // //float desc = it.text.fontDescent / 2;
} // hh2 = hh + desc;
// hh = hh - desc;
//}
// texture coordinates // texture coordinates
short u1 = (short) (SCALE * x); short u1 = (short) (SCALE * x);
@ -240,7 +242,6 @@ public final class TextLayer extends TextureLayer {
buf[pos++] = u2; buf[pos++] = u2;
buf[pos++] = v1; buf[pos++] = v1;
// six indices to draw the four vertices // six indices to draw the four vertices
numIndices += TextureRenderer.INDICES_PER_SPRITE; numIndices += TextureRenderer.INDICES_PER_SPRITE;
verticesCnt += 4; verticesCnt += 4;

View File

@ -16,6 +16,8 @@ package org.oscim.renderer.overlays;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.core.Tile; 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.GLRenderer.Matrices;
import org.oscim.renderer.layer.Layer; import org.oscim.renderer.layer.Layer;
import org.oscim.renderer.layer.LineLayer; 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.theme.renderinstruction.Text;
import org.oscim.view.MapView; import org.oscim.view.MapView;
import android.graphics.Color;
import android.graphics.Paint.Cap;
public class GridOverlay extends BasicOverlay { public class GridOverlay extends BasicOverlay {

View File

@ -33,6 +33,8 @@ import java.util.HashMap;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.core.Tile; import org.oscim.core.Tile;
import org.oscim.generator.JobTile; 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.BufferObject;
import org.oscim.renderer.GLRenderer; import org.oscim.renderer.GLRenderer;
import org.oscim.renderer.GLRenderer.Matrices; 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.MapView;
import org.oscim.view.MapViewPosition; import org.oscim.view.MapViewPosition;
import android.graphics.Color;
import android.graphics.Paint.Cap;
import android.opengl.GLES20; import android.opengl.GLES20;
import android.os.SystemClock; import android.os.SystemClock;

View File

@ -15,12 +15,12 @@
package org.oscim.theme; package org.oscim.theme;
import org.oscim.theme.renderinstruction.Area; import org.oscim.theme.renderinstruction.Area;
import org.oscim.theme.renderinstruction.Circle;
import org.oscim.theme.renderinstruction.Line; 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 org.oscim.theme.renderinstruction.Text;
import android.graphics.Bitmap;
import android.graphics.Paint;
/** /**
* Callback methods for rendering areas, ways and points of interest (POIs). * Callback methods for rendering areas, ways and points of interest (POIs).
*/ */
@ -41,19 +41,17 @@ public interface IRenderCallback {
* @param symbol * @param symbol
* the symbol to be rendered. * the symbol to be rendered.
*/ */
void renderAreaSymbol(Bitmap symbol); void renderAreaSymbol(Symbol symbol);
/** /**
* Renders a point of interest circle with the given parameters. * Renders a point of interest circle with the given parameters.
* *
* @param radius * @param circle
* the radius of the circle. * the circle.
* @param fill
* the paint to be used for rendering the circle.
* @param level * @param level
* the drawing level on which the circle should be rendered. * 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. * Renders a point of interest symbol with the given bitmap.
@ -61,7 +59,7 @@ public interface IRenderCallback {
* @param symbol * @param symbol
* the symbol to be rendered. * the symbol to be rendered.
*/ */
void renderPointOfInterestSymbol(Bitmap symbol); void renderPointOfInterestSymbol(Symbol symbol);
/** /**
* Renders a way with the given parameters. * Renders a way with the given parameters.
@ -78,12 +76,8 @@ public interface IRenderCallback {
* *
* @param symbol * @param symbol
* the symbol to be rendered. * 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. * Renders a way with the given text along the way path.

View File

@ -14,12 +14,12 @@
*/ */
package org.oscim.theme.renderinstruction; package org.oscim.theme.renderinstruction;
import org.oscim.core.Tag; import org.oscim.graphics.Color;
import org.oscim.theme.IRenderCallback; import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler; import org.oscim.theme.RenderThemeHandler;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import android.graphics.Color;
/** /**
* Represents a closed polygon on the map. * Represents a closed polygon on the map.
@ -135,7 +135,7 @@ public final class Area extends RenderInstruction {
} }
@Override @Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) { public void renderWay(IRenderCallback renderCallback) {
renderCallback.renderArea(this, this.level); renderCallback.renderArea(this, this.level);
} }

View File

@ -14,7 +14,6 @@
*/ */
package org.oscim.theme.renderinstruction; package org.oscim.theme.renderinstruction;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback; import org.oscim.theme.IRenderCallback;
public class AreaLevel extends RenderInstruction { public class AreaLevel extends RenderInstruction {
@ -27,7 +26,7 @@ public class AreaLevel extends RenderInstruction {
} }
@Override @Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) { public void renderWay(IRenderCallback renderCallback) {
renderCallback.renderArea(this.area, level); renderCallback.renderArea(this.area, level);
} }
} }

View File

@ -14,14 +14,11 @@
*/ */
package org.oscim.theme.renderinstruction; package org.oscim.theme.renderinstruction;
import org.oscim.core.Tag; import org.oscim.graphics.Color;
import org.oscim.theme.IRenderCallback; import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler; import org.oscim.theme.RenderThemeHandler;
import org.xml.sax.Attributes; 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. * Represents a round area on the map.
@ -78,65 +75,38 @@ public final class Circle extends RenderInstruction {
} }
} }
private final Paint mFill; public final int level;
private final int mLevel;
private final Paint mOutline; public final int fill;
private final float mRadius; public final int outline;
private float mRenderRadius; public final float radius;
private final boolean mScaleRadius; public float renderRadius;
private final float mStrokeWidth; public final boolean scaleRadius;
public final float strokeWidth;
private Circle(Float radius, boolean scaleRadius, int fill, int stroke, private Circle(Float radius, boolean scaleRadius, int fill, int stroke,
float strokeWidth, int level) { float strokeWidth, int level) {
super(); super();
mRadius = radius.floatValue(); this.radius = radius.floatValue();
mScaleRadius = scaleRadius; this.scaleRadius = scaleRadius;
if (fill == Color.TRANSPARENT) { this.fill = fill;
mFill = null; this.outline = stroke;
} else {
mFill = new Paint(Paint.ANTI_ALIAS_FLAG);
mFill.setStyle(Style.FILL);
mFill.setColor(fill);
}
if (stroke == Color.TRANSPARENT) { this.strokeWidth = strokeWidth;
mOutline = null; this.level = level;
} else {
mOutline = new Paint(Paint.ANTI_ALIAS_FLAG);
mOutline.setStyle(Style.STROKE);
mOutline.setColor(stroke);
}
mStrokeWidth = strokeWidth; //if (!mScaleRadius) {
mLevel = level; // mRenderRadius = mRadius;
// if (mOutline != null) {
if (!mScaleRadius) { // mOutline.setStrokeWidth(mStrokeWidth);
mRenderRadius = mRadius; // }
if (mOutline != null) { //}
mOutline.setStrokeWidth(mStrokeWidth);
}
}
} }
@Override @Override
public void renderNode(IRenderCallback renderCallback, Tag[] tags) { public void renderNode(IRenderCallback renderCallback) {
if (mOutline != null) { renderCallback.renderPointOfInterestCircle(this, this.level);
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);
}
}
} }
} }

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -17,14 +17,12 @@ package org.oscim.theme.renderinstruction;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Pattern; 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.IRenderCallback;
import org.oscim.theme.RenderThemeHandler; import org.oscim.theme.RenderThemeHandler;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import android.graphics.Color;
import android.graphics.Paint.Cap;
/** /**
* Represents a polyline on the map. * Represents a polyline on the map.
*/ */
@ -236,7 +234,7 @@ public final class Line extends RenderInstruction {
} }
@Override @Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) { public void renderWay(IRenderCallback renderCallback) {
renderCallback.renderWay(this, level); renderCallback.renderWay(this, level);
} }

View File

@ -16,7 +16,6 @@ package org.oscim.theme.renderinstruction;
import java.io.IOException; import java.io.IOException;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback; import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler; import org.oscim.theme.RenderThemeHandler;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
@ -68,26 +67,26 @@ public final class LineSymbol extends RenderInstruction {
} }
} }
private final boolean mAlignCenter; public final boolean alignCenter;
private final Bitmap mBitmap; public final Bitmap bitmap;
private final boolean mRepeat; public final boolean repeat;
private LineSymbol(String src, boolean alignCenter, boolean repeat) private LineSymbol(String src, boolean alignCenter, boolean repeat)
throws IOException { throws IOException {
super(); super();
mBitmap = BitmapUtils.createBitmap(src); this.bitmap = BitmapUtils.createBitmap(src);
mAlignCenter = alignCenter; this.alignCenter = alignCenter;
mRepeat = repeat; this.repeat = repeat;
} }
@Override @Override
public void destroy() { public void destroy() {
mBitmap.recycle(); bitmap.recycle();
} }
@Override @Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) { public void renderWay(IRenderCallback renderCallback) {
renderCallback.renderWaySymbol(mBitmap, mAlignCenter, mRepeat); renderCallback.renderWaySymbol(this);
} }
} }

View File

@ -14,7 +14,6 @@
*/ */
package org.oscim.theme.renderinstruction; package org.oscim.theme.renderinstruction;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback; import org.oscim.theme.IRenderCallback;
/** /**
@ -30,19 +29,15 @@ public abstract class RenderInstruction {
/** /**
* @param renderCallback * @param renderCallback
* a reference to the receiver of all render callbacks. * 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 * @param renderCallback
* a reference to the receiver of all render callbacks. * 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) {
} }
/** /**

View File

@ -16,7 +16,6 @@ package org.oscim.theme.renderinstruction;
import java.io.IOException; import java.io.IOException;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback; import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler; import org.oscim.theme.RenderThemeHandler;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
@ -76,12 +75,12 @@ public final class Symbol extends RenderInstruction {
} }
@Override @Override
public void renderNode(IRenderCallback renderCallback, Tag[] tags) { public void renderNode(IRenderCallback renderCallback) {
renderCallback.renderPointOfInterestSymbol(bitmap); renderCallback.renderPointOfInterestSymbol(this);
} }
@Override @Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) { public void renderWay(IRenderCallback renderCallback) {
renderCallback.renderAreaSymbol(bitmap); renderCallback.renderAreaSymbol(this);
} }
} }

View File

@ -16,18 +16,17 @@ package org.oscim.theme.renderinstruction;
import java.util.Locale; 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.IRenderCallback;
import org.oscim.theme.RenderThemeHandler; import org.oscim.theme.RenderThemeHandler;
import org.xml.sax.Attributes; 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. * Represents a text along a polyline on the map.
*/ */
@ -85,26 +84,10 @@ public final class Text extends RenderInstruction {
validate(elementName, textKey, fontSize, strokeWidth); validate(elementName, textKey, fontSize, strokeWidth);
Typeface typeface = null; return new Text(style, textKey, fontFamily, fontStyle, fontSize, fill, stroke, strokeWidth,
if (fontFamily == FontFamily.DEFAULT) { dy, caption, priority);
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);
}
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, private static void validate(String elementName, String textKey, float fontSize,
float strokeWidth) { float strokeWidth) {
if (textKey == null) { if (textKey == null) {
@ -131,13 +114,16 @@ public final class Text extends RenderInstruction {
public float fontHeight; public float fontHeight;
public float fontDescent; public float fontDescent;
public static Text createText(float fontSize, float strokeWidth, int fill, int outline, public static Text createText(float fontSize, float strokeWidth, int fill, int outline,
boolean billboard) { 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) { int fill, int outline, float strokeWidth, float dy, boolean caption, int priority) {
this.style = style; this.style = style;
@ -146,17 +132,17 @@ public final class Text extends RenderInstruction {
this.dy = dy; this.dy = dy;
this.priority = priority; this.priority = priority;
paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint = Graphics.res.getPaint();
paint.setTextAlign(Align.CENTER); paint.setTextAlign(Align.CENTER);
paint.setTypeface(typeface); paint.setTypeface(fontFamily, fontStyle);
paint.setColor(fill); paint.setColor(fill);
paint.setTextSize(fontSize); paint.setTextSize(fontSize);
if (strokeWidth > 0) { if (strokeWidth > 0) {
stroke = new Paint(Paint.ANTI_ALIAS_FLAG); stroke = Graphics.res.getPaint();
stroke.setStyle(Style.STROKE); stroke.setStyle(Style.STROKE);
stroke.setTextAlign(Align.CENTER); stroke.setTextAlign(Align.CENTER);
stroke.setTypeface(typeface); stroke.setTypeface(fontFamily, fontStyle);
stroke.setColor(outline); stroke.setColor(outline);
stroke.setStrokeWidth(strokeWidth); stroke.setStrokeWidth(strokeWidth);
stroke.setTextSize(fontSize); stroke.setTextSize(fontSize);
@ -164,21 +150,16 @@ public final class Text extends RenderInstruction {
stroke = null; stroke = null;
this.fontSize = fontSize; 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 @Override
public void renderNode(IRenderCallback renderCallback, Tag[] tags) { public void renderNode(IRenderCallback renderCallback) {
if (caption) if (caption)
renderCallback.renderPointOfInterestCaption(this); renderCallback.renderPointOfInterestCaption(this);
} }
@Override @Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) { public void renderWay(IRenderCallback renderCallback) {
if (caption) if (caption)
renderCallback.renderAreaCaption(this); renderCallback.renderAreaCaption(this);
else else
@ -191,8 +172,11 @@ public final class Text extends RenderInstruction {
if (stroke != null) if (stroke != null)
stroke.setTextSize(fontSize * scaleFactor); stroke.setTextSize(fontSize * scaleFactor);
FontMetrics fm = paint.getFontMetrics(); // FontMetrics fm = paint.getFontMetrics();
fontHeight = (float) Math.ceil(Math.abs(fm.bottom) + Math.abs(fm.top)); // fontHeight = (float) Math.ceil(Math.abs(fm.bottom) + Math.abs(fm.top));
fontDescent = (float) Math.ceil(Math.abs(fm.descent)); // fontDescent = (float) Math.ceil(Math.abs(fm.descent));
fontHeight = paint.getFontHeight();
fontDescent = paint.getFontDescent();
} }
} }