Render themes: line symbol, fix #124
This commit is contained in:
@@ -87,9 +87,6 @@ public class XmlMapsforgeThemeBuilder extends DefaultHandler {
|
||||
private static final String OUTLINE_STYLE = "O";
|
||||
private static final String AREA_STYLE = "A";
|
||||
|
||||
private static final float REPEAT_GAP_DEFAULT = 200f;
|
||||
private static final float REPEAT_START_DEFAULT = 30f;
|
||||
|
||||
/**
|
||||
* @param theme an input theme containing valid render theme XML data.
|
||||
* @return a new RenderTheme which is created by parsing the XML data from the input theme.
|
||||
@@ -571,6 +568,12 @@ public class XmlMapsforgeThemeBuilder extends DefaultHandler {
|
||||
else if ("symbol-scaling".equals(name))
|
||||
; // no-op
|
||||
|
||||
else if ("repeat-start".equals(name))
|
||||
b.repeatStart = Float.parseFloat(value) * mScale;
|
||||
|
||||
else if ("repeat-gap".equals(name))
|
||||
b.repeatGap = Float.parseFloat(value) * mScale;
|
||||
|
||||
else
|
||||
logUnknownAttribute(elementName, name, value, i);
|
||||
}
|
||||
@@ -611,30 +614,23 @@ public class XmlMapsforgeThemeBuilder extends DefaultHandler {
|
||||
b.texture = Utils.loadTexture(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
|
||||
|
||||
if (hasSymbol) {
|
||||
// We have no way to set a repeat gap for the renderer,
|
||||
// so we create a texture that already contains this repeat gap.
|
||||
float repeatGap = REPEAT_GAP_DEFAULT * mScale;
|
||||
float repeatStart = REPEAT_START_DEFAULT * mScale;
|
||||
int width = (int) (b.texture.width + repeatGap);
|
||||
// Line symbol
|
||||
int width = (int) (b.texture.width + b.repeatGap);
|
||||
int height = b.texture.height;
|
||||
Bitmap bmp = CanvasAdapter.newBitmap(width, height, 0);
|
||||
Bitmap bitmap = CanvasAdapter.newBitmap(width, height, 0);
|
||||
Canvas canvas = CanvasAdapter.newCanvas();
|
||||
canvas.setBitmap(bmp);
|
||||
canvas.drawBitmap(b.texture.bitmap, repeatStart, 0);
|
||||
b.texture = new TextureItem(bmp);
|
||||
|
||||
// We must set stipple values
|
||||
// The multipliers are determined empirically to
|
||||
// correspond to the representation at Mapsforge.
|
||||
b.stipple = b.texture.width * 3;
|
||||
b.strokeWidth *= 2 * mScale;
|
||||
|
||||
// Use texture color
|
||||
canvas.setBitmap(bitmap);
|
||||
canvas.drawBitmap(b.texture.bitmap, b.repeatStart, 0);
|
||||
b.texture = new TextureItem(bitmap);
|
||||
b.texture.mipmap = true;
|
||||
b.fixed = true;
|
||||
b.randomOffset = false;
|
||||
b.stipple = width;
|
||||
b.stippleWidth = 1;
|
||||
b.strokeWidth = height * 0.5f;
|
||||
b.stippleColor = Color.WHITE;
|
||||
b.fillColor = Color.TRANSPARENT;
|
||||
b.strokeColor = Color.TRANSPARENT;
|
||||
|
||||
b.fixed = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,9 +87,6 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
private static final String OUTLINE_STYLE = "O";
|
||||
private static final String AREA_STYLE = "A";
|
||||
|
||||
private static final float REPEAT_GAP_DEFAULT = 200f;
|
||||
private static final float REPEAT_START_DEFAULT = 30f;
|
||||
|
||||
/**
|
||||
* @param theme an input theme containing valid render theme XML data.
|
||||
* @return a new RenderTheme which is created by parsing the XML data from the input theme.
|
||||
@@ -569,6 +566,12 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
else if ("symbol-scaling".equals(name))
|
||||
; // no-op
|
||||
|
||||
else if ("repeat-start".equals(name))
|
||||
b.repeatStart = Float.parseFloat(value) * mScale;
|
||||
|
||||
else if ("repeat-gap".equals(name))
|
||||
b.repeatGap = Float.parseFloat(value) * mScale;
|
||||
|
||||
else
|
||||
logUnknownAttribute(elementName, name, value, i);
|
||||
}
|
||||
@@ -609,30 +612,23 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
b.texture = Utils.loadTexture(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
|
||||
|
||||
if (hasSymbol) {
|
||||
// We have no way to set a repeat gap for the renderer,
|
||||
// so we create a texture that already contains this repeat gap.
|
||||
float repeatGap = REPEAT_GAP_DEFAULT * mScale;
|
||||
float repeatStart = REPEAT_START_DEFAULT * mScale;
|
||||
int width = (int) (b.texture.width + repeatGap);
|
||||
// Line symbol
|
||||
int width = (int) (b.texture.width + b.repeatGap);
|
||||
int height = b.texture.height;
|
||||
Bitmap bmp = CanvasAdapter.newBitmap(width, height, 0);
|
||||
Bitmap bitmap = CanvasAdapter.newBitmap(width, height, 0);
|
||||
Canvas canvas = CanvasAdapter.newCanvas();
|
||||
canvas.setBitmap(bmp);
|
||||
canvas.drawBitmap(b.texture.bitmap, repeatStart, 0);
|
||||
b.texture = new TextureItem(bmp);
|
||||
|
||||
// We must set stipple values
|
||||
// The multipliers are determined empirically to
|
||||
// correspond to the representation at Mapsforge.
|
||||
b.stipple = b.texture.width * 3;
|
||||
b.strokeWidth *= 2 * mScale;
|
||||
|
||||
// Use texture color
|
||||
canvas.setBitmap(bitmap);
|
||||
canvas.drawBitmap(b.texture.bitmap, b.repeatStart, 0);
|
||||
b.texture = new TextureItem(bitmap);
|
||||
b.texture.mipmap = true;
|
||||
b.fixed = true;
|
||||
b.randomOffset = false;
|
||||
b.stipple = width;
|
||||
b.stippleWidth = 1;
|
||||
b.strokeWidth = height * 0.5f;
|
||||
b.stippleColor = Color.WHITE;
|
||||
b.fillColor = Color.TRANSPARENT;
|
||||
b.strokeColor = Color.TRANSPARENT;
|
||||
|
||||
b.fixed = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,9 @@ import static org.oscim.backend.canvas.Color.parseColor;
|
||||
|
||||
public final class LineStyle extends RenderStyle<LineStyle> {
|
||||
|
||||
public static final float REPEAT_START_DEFAULT = 30f;
|
||||
public static final float REPEAT_GAP_DEFAULT = 200f;
|
||||
|
||||
private final int level;
|
||||
public final String style;
|
||||
public final float width;
|
||||
@@ -50,24 +53,26 @@ public final class LineStyle extends RenderStyle<LineStyle> {
|
||||
public final int symbolPercent;
|
||||
|
||||
public final float[] dashArray;
|
||||
public final float repeatStart;
|
||||
public final float repeatGap;
|
||||
|
||||
public LineStyle(int stroke, float width) {
|
||||
this(0, "", stroke, width, Cap.BUTT, true, 0, 0, 0, -1, 0, false, null, true, null);
|
||||
this(0, "", stroke, width, Cap.BUTT, true, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT, REPEAT_GAP_DEFAULT);
|
||||
}
|
||||
|
||||
public LineStyle(int level, int stroke, float width) {
|
||||
this(level, "", stroke, width, Cap.BUTT, true, 0, 0, 0, -1, 0, false, null, true, null);
|
||||
this(level, "", stroke, width, Cap.BUTT, true, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT, REPEAT_GAP_DEFAULT);
|
||||
}
|
||||
|
||||
public LineStyle(int stroke, float width, Cap cap) {
|
||||
this(0, "", stroke, width, cap, true, 0, 0, 0, -1, 0, false, null, true, null);
|
||||
this(0, "", stroke, width, cap, true, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT, REPEAT_GAP_DEFAULT);
|
||||
}
|
||||
|
||||
public LineStyle(int level, String style, int color, float width,
|
||||
Cap cap, boolean fixed,
|
||||
int stipple, int stippleColor, float stippleWidth,
|
||||
int fadeScale, float blur, boolean isOutline, TextureItem texture,
|
||||
boolean randomOffset, float[] dashArray) {
|
||||
boolean randomOffset, float[] dashArray, float repeatStart, float repeatGap) {
|
||||
|
||||
this.level = level;
|
||||
this.style = style;
|
||||
@@ -94,6 +99,8 @@ public final class LineStyle extends RenderStyle<LineStyle> {
|
||||
this.symbolPercent = 100;
|
||||
|
||||
this.dashArray = dashArray;
|
||||
this.repeatStart = repeatStart;
|
||||
this.repeatGap = repeatGap;
|
||||
}
|
||||
|
||||
private LineStyle(LineBuilder<?> b) {
|
||||
@@ -119,6 +126,8 @@ public final class LineStyle extends RenderStyle<LineStyle> {
|
||||
this.symbolPercent = b.symbolPercent;
|
||||
|
||||
this.dashArray = b.dashArray;
|
||||
this.repeatStart = b.repeatStart;
|
||||
this.repeatGap = b.repeatGap;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -152,6 +161,8 @@ public final class LineStyle extends RenderStyle<LineStyle> {
|
||||
public int symbolPercent;
|
||||
|
||||
public float[] dashArray;
|
||||
public float repeatStart;
|
||||
public float repeatGap;
|
||||
|
||||
public LineBuilder() {
|
||||
}
|
||||
@@ -182,6 +193,8 @@ public final class LineStyle extends RenderStyle<LineStyle> {
|
||||
this.symbolPercent = line.symbolPercent;
|
||||
|
||||
this.dashArray = line.dashArray;
|
||||
this.repeatStart = line.repeatStart;
|
||||
this.repeatGap = line.repeatGap;
|
||||
|
||||
return self();
|
||||
}
|
||||
@@ -266,6 +279,16 @@ public final class LineStyle extends RenderStyle<LineStyle> {
|
||||
return self();
|
||||
}
|
||||
|
||||
public T repeatStart(float repeatStart) {
|
||||
this.repeatStart = repeatStart;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T repeatGap(float repeatGap) {
|
||||
this.repeatGap = repeatGap;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T reset() {
|
||||
level = -1;
|
||||
style = null;
|
||||
@@ -291,6 +314,8 @@ public final class LineStyle extends RenderStyle<LineStyle> {
|
||||
symbolPercent = 100;
|
||||
|
||||
dashArray = null;
|
||||
repeatStart = REPEAT_START_DEFAULT;
|
||||
repeatGap = REPEAT_GAP_DEFAULT;
|
||||
|
||||
return self();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user