From 0046f5c15965820330db7f3844244934cace90e9 Mon Sep 17 00:00:00 2001 From: Emux Date: Sat, 23 Sep 2017 18:32:37 +0300 Subject: [PATCH] Render themes: line symbol, fix #124 --- resources/rendertheme.xsd | 23 ++--------- .../src/org/oscim/test/LineRenderTest.java | 13 +++--- .../resources/assets/patterns/oneway.svg | 7 ---- .../resources/assets/symbols/oneway.svg | 8 ++-- vtm-themes/resources/assets/vtm/default.xml | 3 +- vtm-themes/resources/assets/vtm/mapzen.xml | 3 +- vtm-themes/resources/assets/vtm/newtron.xml | 3 +- .../resources/assets/vtm/openmaptiles.xml | 3 +- vtm-themes/resources/assets/vtm/osmagray.xml | 3 +- .../resources/assets/vtm/osmarender.xml | 3 +- .../resources/assets/vtm/tronrender.xml | 3 +- .../oscim/theme/XmlMapsforgeThemeBuilder.java | 40 +++++++++---------- vtm/src/org/oscim/theme/XmlThemeBuilder.java | 40 +++++++++---------- vtm/src/org/oscim/theme/styles/LineStyle.java | 33 +++++++++++++-- 14 files changed, 86 insertions(+), 99 deletions(-) delete mode 100644 vtm-themes/resources/assets/patterns/oneway.svg diff --git a/resources/rendertheme.xsd b/resources/rendertheme.xsd index f5d19ff7..906b3cde 100644 --- a/resources/rendertheme.xsd +++ b/resources/rendertheme.xsd @@ -190,6 +190,8 @@ + + @@ -200,25 +202,6 @@ - - - - - - - - - - @@ -266,7 +249,7 @@ - + diff --git a/vtm-playground/src/org/oscim/test/LineRenderTest.java b/vtm-playground/src/org/oscim/test/LineRenderTest.java index fa956089..8fc980a1 100644 --- a/vtm-playground/src/org/oscim/test/LineRenderTest.java +++ b/vtm-playground/src/org/oscim/test/LineRenderTest.java @@ -1,5 +1,6 @@ /* - * Copyright 2016 devemux86 + * Copyright 2014 Hannes Janetzek + * Copyright 2016-2017 devemux86 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -72,9 +73,9 @@ public class LineRenderTest extends GdxMap { line2 = new LineStyle(Color.GREEN, 1); line4 = new LineStyle(Color.LTGRAY, 3); } else { - line1 = new LineStyle(0, null, Color.fade(Color.RED, 0.5f), 4.0f, Cap.BUTT, false, 0, 0, 0, 0, 1f, false, null, true, null); - line2 = new LineStyle(0, null, Color.GREEN, 6.0f, Cap.BUTT, false, 0, 0, 0, 0, 1f, false, null, true, null); - line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, false, null, true, null); + line1 = new LineStyle(0, null, Color.fade(Color.RED, 0.5f), 4.0f, Cap.BUTT, false, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); + line2 = new LineStyle(0, null, Color.GREEN, 6.0f, Cap.BUTT, false, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); + line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); } TextureItem tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/dot.png")); @@ -90,8 +91,8 @@ public class LineRenderTest extends GdxMap { .randomOffset(true) .build(); - LineStyle outline = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, true, null, true, null); - LineStyle outline2 = new LineStyle(0, null, Color.RED, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 0, true, null, true, null); + LineStyle outline = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, true, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); + LineStyle outline2 = new LineStyle(0, null, Color.RED, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 0, true, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); LineBucket ol = l.buckets.addLineBucket(0, outline); LineBucket ol2 = l.buckets.addLineBucket(5, outline2); diff --git a/vtm-themes/resources/assets/patterns/oneway.svg b/vtm-themes/resources/assets/patterns/oneway.svg deleted file mode 100644 index f2280854..00000000 --- a/vtm-themes/resources/assets/patterns/oneway.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/vtm-themes/resources/assets/symbols/oneway.svg b/vtm-themes/resources/assets/symbols/oneway.svg index b920d471..68dcf823 100644 --- a/vtm-themes/resources/assets/symbols/oneway.svg +++ b/vtm-themes/resources/assets/symbols/oneway.svg @@ -1,6 +1,6 @@ - - - - + + + + diff --git a/vtm-themes/resources/assets/vtm/default.xml b/vtm-themes/resources/assets/vtm/default.xml index 5f2b2758..d8d8652a 100644 --- a/vtm-themes/resources/assets/vtm/default.xml +++ b/vtm-themes/resources/assets/vtm/default.xml @@ -966,8 +966,7 @@ - + diff --git a/vtm-themes/resources/assets/vtm/mapzen.xml b/vtm-themes/resources/assets/vtm/mapzen.xml index 8b1ecd7b..6f5b607c 100644 --- a/vtm-themes/resources/assets/vtm/mapzen.xml +++ b/vtm-themes/resources/assets/vtm/mapzen.xml @@ -963,8 +963,7 @@ - + diff --git a/vtm-themes/resources/assets/vtm/newtron.xml b/vtm-themes/resources/assets/vtm/newtron.xml index 5e75b4fe..1af7174f 100644 --- a/vtm-themes/resources/assets/vtm/newtron.xml +++ b/vtm-themes/resources/assets/vtm/newtron.xml @@ -996,8 +996,7 @@ - + diff --git a/vtm-themes/resources/assets/vtm/openmaptiles.xml b/vtm-themes/resources/assets/vtm/openmaptiles.xml index ae15c6a5..537c119f 100644 --- a/vtm-themes/resources/assets/vtm/openmaptiles.xml +++ b/vtm-themes/resources/assets/vtm/openmaptiles.xml @@ -962,8 +962,7 @@ - + diff --git a/vtm-themes/resources/assets/vtm/osmagray.xml b/vtm-themes/resources/assets/vtm/osmagray.xml index 2d1b0e0d..651b8e6e 100644 --- a/vtm-themes/resources/assets/vtm/osmagray.xml +++ b/vtm-themes/resources/assets/vtm/osmagray.xml @@ -940,8 +940,7 @@ - + diff --git a/vtm-themes/resources/assets/vtm/osmarender.xml b/vtm-themes/resources/assets/vtm/osmarender.xml index b106fdca..d32aea65 100644 --- a/vtm-themes/resources/assets/vtm/osmarender.xml +++ b/vtm-themes/resources/assets/vtm/osmarender.xml @@ -940,8 +940,7 @@ - + diff --git a/vtm-themes/resources/assets/vtm/tronrender.xml b/vtm-themes/resources/assets/vtm/tronrender.xml index d8a8a98b..038574e8 100644 --- a/vtm-themes/resources/assets/vtm/tronrender.xml +++ b/vtm-themes/resources/assets/vtm/tronrender.xml @@ -989,8 +989,7 @@ - + diff --git a/vtm/src/org/oscim/theme/XmlMapsforgeThemeBuilder.java b/vtm/src/org/oscim/theme/XmlMapsforgeThemeBuilder.java index 468cc45c..1acded80 100644 --- a/vtm/src/org/oscim/theme/XmlMapsforgeThemeBuilder.java +++ b/vtm/src/org/oscim/theme/XmlMapsforgeThemeBuilder.java @@ -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; } } diff --git a/vtm/src/org/oscim/theme/XmlThemeBuilder.java b/vtm/src/org/oscim/theme/XmlThemeBuilder.java index a9b7c1ee..d40d3440 100644 --- a/vtm/src/org/oscim/theme/XmlThemeBuilder.java +++ b/vtm/src/org/oscim/theme/XmlThemeBuilder.java @@ -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; } } diff --git a/vtm/src/org/oscim/theme/styles/LineStyle.java b/vtm/src/org/oscim/theme/styles/LineStyle.java index 162b80dc..41ee9b03 100644 --- a/vtm/src/org/oscim/theme/styles/LineStyle.java +++ b/vtm/src/org/oscim/theme/styles/LineStyle.java @@ -27,6 +27,9 @@ import static org.oscim.backend.canvas.Color.parseColor; public final class LineStyle extends RenderStyle { + 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 { 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 { 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 { 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 { public int symbolPercent; public float[] dashArray; + public float repeatStart; + public float repeatGap; public LineBuilder() { } @@ -182,6 +193,8 @@ public final class LineStyle extends RenderStyle { 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 { 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 { symbolPercent = 100; dashArray = null; + repeatStart = REPEAT_START_DEFAULT; + repeatGap = REPEAT_GAP_DEFAULT; return self(); }