add TextBuilder for Text styles
This commit is contained in:
parent
a4cd4ad767
commit
a4555631b1
@ -18,6 +18,7 @@ import org.oscim.renderer.elements.TextLayer;
|
||||
import org.oscim.theme.styles.Area;
|
||||
import org.oscim.theme.styles.Line;
|
||||
import org.oscim.theme.styles.Text;
|
||||
import org.oscim.theme.styles.Text.TextBuilder;
|
||||
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
@ -26,7 +27,10 @@ import com.vividsolutions.jts.geom.LineString;
|
||||
public class OSMIndoorLayer extends JeoVectorLayer {
|
||||
|
||||
protected TextLayer mTextLayer;
|
||||
protected Text mText = Text.createText(16, 2.2f, Color.BLACK, Color.WHITE, true);
|
||||
protected Text mText = new TextBuilder()
|
||||
.setFontSize(16).setColor(Color.BLACK)
|
||||
.setStrokeWidth(2.2f).setStroke(Color.WHITE)
|
||||
.build();
|
||||
|
||||
public OSMIndoorLayer(Map map, VectorDataset data, Style style) {
|
||||
super(map, data, style);
|
||||
|
@ -25,6 +25,7 @@ import org.oscim.renderer.elements.TextItem;
|
||||
import org.oscim.renderer.elements.TextLayer;
|
||||
import org.oscim.theme.styles.Line;
|
||||
import org.oscim.theme.styles.Text;
|
||||
import org.oscim.theme.styles.Text.TextBuilder;
|
||||
|
||||
public class GridRenderer extends ElementRenderer {
|
||||
private final TextLayer mTextLayer;
|
||||
@ -37,7 +38,7 @@ public class GridRenderer extends ElementRenderer {
|
||||
|
||||
public GridRenderer() {
|
||||
this(1, new Line(Color.LTGRAY, 1.2f, Cap.BUTT),
|
||||
Text.createText(22, 0, Color.RED, 0, false));
|
||||
new TextBuilder().setFontSize(22).setColor(Color.RED).build());
|
||||
}
|
||||
|
||||
public GridRenderer(int numLines, Line lineStyle, Text textStyle) {
|
||||
|
@ -30,6 +30,7 @@ import org.oscim.renderer.elements.TextItem;
|
||||
import org.oscim.renderer.elements.TextLayer;
|
||||
import org.oscim.theme.styles.Line;
|
||||
import org.oscim.theme.styles.Text;
|
||||
import org.oscim.theme.styles.Text.TextBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -54,7 +55,7 @@ public class AtlasRenderLayer extends ElementRenderer {
|
||||
ll3.scale = 1f;
|
||||
|
||||
TextLayer tl = new TextLayer();
|
||||
Text t = Text.createText(20, 0, Color.BLACK, 0, false);
|
||||
Text t = new TextBuilder().setFontSize(20).setColor(Color.BLACK).build();
|
||||
layers.setTextureLayers(tl);
|
||||
|
||||
float[] points = new float[10];
|
||||
|
@ -1,5 +1,4 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
@ -18,6 +17,7 @@
|
||||
package org.oscim.theme.styles;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.backend.canvas.Paint;
|
||||
import org.oscim.backend.canvas.Paint.Align;
|
||||
import org.oscim.backend.canvas.Paint.FontFamily;
|
||||
@ -25,11 +25,146 @@ import org.oscim.backend.canvas.Paint.FontStyle;
|
||||
import org.oscim.renderer.atlas.TextureRegion;
|
||||
import org.oscim.theme.IRenderTheme.Callback;
|
||||
|
||||
/**
|
||||
* Represents a text along a polyline on the map.
|
||||
*/
|
||||
public final class Text extends RenderStyle {
|
||||
|
||||
public static class TextBuilder {
|
||||
|
||||
public String style;
|
||||
public float fontSize;
|
||||
|
||||
public String textKey;
|
||||
public boolean caption;
|
||||
public float dy;
|
||||
public int priority;
|
||||
public TextureRegion texture;
|
||||
public FontFamily fontFamily;
|
||||
public FontStyle fontStyle;
|
||||
|
||||
public int color;
|
||||
public int stroke;
|
||||
public float strokeWidth;
|
||||
|
||||
public TextBuilder reset() {
|
||||
fontFamily = FontFamily.DEFAULT;
|
||||
fontStyle = FontStyle.NORMAL;
|
||||
style = null;
|
||||
textKey = null;
|
||||
fontSize = 0;
|
||||
caption = false;
|
||||
priority = Integer.MAX_VALUE;
|
||||
texture = null;
|
||||
color = Color.BLACK;
|
||||
stroke = Color.BLACK;
|
||||
strokeWidth = 0;
|
||||
dy = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder() {
|
||||
reset();
|
||||
}
|
||||
|
||||
public Text build() {
|
||||
Text t = new Text(this);
|
||||
t.fontHeight = t.paint.getFontHeight();
|
||||
t.fontDescent = t.paint.getFontDescent();
|
||||
return t;
|
||||
}
|
||||
|
||||
public Text buildInternal() {
|
||||
return new Text(this);
|
||||
}
|
||||
|
||||
public TextBuilder setStyle(String style) {
|
||||
this.style = style;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder setFontSize(float fontSize) {
|
||||
this.fontSize = fontSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder setTextKey(String textKey) {
|
||||
this.textKey = textKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder setCaption(boolean caption) {
|
||||
this.caption = caption;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder setOffsetY(float dy) {
|
||||
this.dy = dy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder setPriority(int priority) {
|
||||
this.priority = priority;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder setTexture(TextureRegion texture) {
|
||||
this.texture = texture;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder setFontFamily(FontFamily fontFamily) {
|
||||
this.fontFamily = fontFamily;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder setFontStyle(FontStyle fontStyle) {
|
||||
this.fontStyle = fontStyle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder setColor(int color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder setStroke(int stroke) {
|
||||
this.stroke = stroke;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder setStrokeWidth(float strokeWidth) {
|
||||
this.strokeWidth = strokeWidth;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Text(TextBuilder tb) {
|
||||
this.style = tb.style;
|
||||
this.textKey = tb.textKey;
|
||||
this.caption = tb.caption;
|
||||
this.dy = tb.dy;
|
||||
this.priority = tb.priority;
|
||||
this.texture = tb.texture;
|
||||
|
||||
paint = CanvasAdapter.g.getPaint();
|
||||
paint.setTextAlign(Align.CENTER);
|
||||
paint.setTypeface(tb.fontFamily, tb.fontStyle);
|
||||
|
||||
paint.setColor(tb.color);
|
||||
paint.setTextSize(tb.fontSize);
|
||||
|
||||
if (tb.strokeWidth > 0) {
|
||||
stroke = CanvasAdapter.g.getPaint();
|
||||
stroke.setStyle(Paint.Style.STROKE);
|
||||
stroke.setTextAlign(Align.CENTER);
|
||||
stroke.setTypeface(tb.fontFamily, tb.fontStyle);
|
||||
stroke.setColor(tb.stroke);
|
||||
stroke.setStrokeWidth(tb.strokeWidth);
|
||||
stroke.setTextSize(tb.fontSize);
|
||||
} else
|
||||
stroke = null;
|
||||
|
||||
this.fontSize = tb.fontSize;
|
||||
}
|
||||
|
||||
public final String style;
|
||||
|
||||
public final float fontSize;
|
||||
@ -46,70 +181,6 @@ public final class Text extends RenderStyle {
|
||||
|
||||
public final TextureRegion texture;
|
||||
|
||||
public static Text createText(float fontSize, float strokeWidth, int fill, int outline,
|
||||
boolean billboard) {
|
||||
|
||||
return createText("", fontSize, strokeWidth, fill, outline, billboard);
|
||||
}
|
||||
|
||||
public static Text createText(String textKey, float fontSize, float strokeWidth, int fill,
|
||||
int outline,
|
||||
boolean billboard) {
|
||||
|
||||
Text t = new Text("",
|
||||
textKey,
|
||||
FontFamily.DEFAULT,
|
||||
FontStyle.NORMAL,
|
||||
fontSize,
|
||||
fill,
|
||||
outline,
|
||||
strokeWidth,
|
||||
0,
|
||||
billboard,
|
||||
null,
|
||||
Integer.MAX_VALUE);
|
||||
|
||||
t.fontHeight = t.paint.getFontHeight();
|
||||
t.fontDescent = t.paint.getFontDescent();
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
public Text(String style, String textKey, FontFamily fontFamily, FontStyle fontStyle,
|
||||
float fontSize, int fill, int outline, float strokeWidth, float dy, boolean caption,
|
||||
TextureRegion symbol, int priority) {
|
||||
|
||||
this.style = style;
|
||||
this.textKey = textKey;
|
||||
this.caption = caption;
|
||||
this.dy = -dy;
|
||||
this.priority = priority;
|
||||
this.texture = symbol;
|
||||
|
||||
paint = CanvasAdapter.g.getPaint();
|
||||
paint.setTextAlign(Align.CENTER);
|
||||
paint.setTypeface(fontFamily, fontStyle);
|
||||
|
||||
paint.setColor(fill);
|
||||
paint.setTextSize(fontSize);
|
||||
|
||||
if (strokeWidth > 0) {
|
||||
stroke = CanvasAdapter.g.getPaint();
|
||||
stroke.setStyle(Paint.Style.STROKE);
|
||||
stroke.setTextAlign(Align.CENTER);
|
||||
stroke.setTypeface(fontFamily, fontStyle);
|
||||
stroke.setColor(outline);
|
||||
stroke.setStrokeWidth(strokeWidth);
|
||||
stroke.setTextSize(fontSize);
|
||||
} else
|
||||
stroke = null;
|
||||
|
||||
this.fontSize = fontSize;
|
||||
|
||||
//fontHeight = paint.getFontHeight();
|
||||
//fontDescent = paint.getFontDescent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderNode(Callback renderCallback) {
|
||||
if (caption)
|
||||
|
Loading…
x
Reference in New Issue
Block a user