Render themes: line symbol, fix #124

This commit is contained in:
Emux 2017-09-23 18:32:37 +03:00
parent 7865867973
commit 0046f5c159
14 changed files with 86 additions and 99 deletions

View File

@ -190,6 +190,8 @@
<xs:attribute name="fade" default="-1" type="xs:integer" use="optional" />
<xs:attribute name="blur" default="-1" type="xs:float" use="optional" />
<xs:attribute name="fix" default="false" type="xs:boolean" use="optional" />
<xs:attribute name="repeat-gap" default="200" type="xs:float" use="optional" />
<xs:attribute name="repeat-start" default="30" type="xs:float" use="optional" />
<!-- stipple repeat in 'pixel' -->
<xs:attribute name="stipple" default="0" type="xs:integer" use="optional" />
@ -200,25 +202,6 @@
</xs:complexType>
<!--<xs:complexType name="outline">
<xs:attribute name="cat" type="xs:string" use="optional" />
<xs:attribute name="name" default="0" type="xs:string" use="optional" />
<xs:attribute name="src" type="tns:src" use="optional" />
<xs:attribute name="symbol-width" type="xs:positiveInteger" use="optional" />
<xs:attribute name="symbol-height" type="xs:positiveInteger" use="optional" />
<xs:attribute name="symbol-percent" type="xs:positiveInteger" use="optional" />
<xs:attribute name="stroke" default="#000000" type="tns:color" use="optional" />
<xs:attribute name="stroke-width" default="0" type="tns:nonNegativeFloat" use="optional" />
</xs:complexType>-->
<xs:complexType name="lineSymbol">
<xs:attribute name="cat" type="xs:string" use="optional" />
<xs:attribute name="src" type="tns:src" use="required" />
<xs:attribute name="symbol-width" type="xs:positiveInteger" use="optional" />
<xs:attribute name="symbol-height" type="xs:positiveInteger" use="optional" />
<xs:attribute name="symbol-percent" type="xs:positiveInteger" use="optional" />
</xs:complexType>
<xs:complexType name="text">
<xs:attribute name="cat" type="xs:string" use="optional" />
@ -266,7 +249,7 @@
<xs:element name="circle" type="tns:circle" />
<xs:element name="line" type="tns:line" />
<xs:element name="outline" type="tns:line" />
<xs:element name="lineSymbol" type="tns:lineSymbol" />
<xs:element name="lineSymbol" type="tns:line" />
<xs:element name="text" type="tns:text" />
<xs:element name="extrusion" type="tns:extrusion" />
<xs:element name="symbol" type="tns:symbol" />

View File

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

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="4640" height="290" version="1.1">
<metadata id="metadata7"/>
<g inkscape:label="Ebene 1" inkscape:groupmode="layer" id="layer1" transform="translate(0,-472.36218)">
<path d="m 2382.0792,530.4022 c 0,23.62174 0,47.24349 0,70.86523 -107.9543,0.24577 -215.9507,-0.50756 -323.8789,0.39258 -12.6443,2.23959 -16.8481,21.44126 -5.8203,28.40039 9.7713,6.40448 21.8892,1.7557 32.6992,3.20508 99,0 198,0 297,0 0,24.70443 0,49.40885 0,74.11328 68.6624,-30.00684 137.3253,-60.01234 205.9883,-90.01758 -68.663,-30.00467 -137.326,-60.00938 -205.9883,-90.01562 0,1.01888 0,2.03776 0,3.05664 z" id="path2994" inkscape:connector-curvature="0" visibility="visible" shape-rendering="auto" mix-blend-mode="normal" color-interpolation-filters="linearRGB" isolation="auto" stroke-dasharray="none" stroke-opacity="1" white-space="normal" opacity="1" fill="#ffffff" solid-opacity="1" stroke-miterlimit="4" image-rendering="auto" fill-opacity="1" solid-color="#000000" stroke="#ffffff" display="inline" color="#000000" fill-rule="nonzero" stroke-linecap="round" stroke-linejoin="miter" stroke-width="8" color-rendering="auto" stroke-dashoffset="0" color-interpolation="sRGB"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" version="1.1" height="22" width="22">
<metadata id="metadata3025"/>
<path stroke-miterlimit="10" inkscape:connector-curvature="0" d="m 4.8081,9.8895 7.3149,0.066 C 11.202,9.1774 10.289,8.3996 9.3792,7.6219 l 3.3408,0 c 1.415,1.1264 2.832,2.2522 4.248,3.3781 -1.416,1.125 -2.833,2.251 -4.25,3.377 l -3.3406,0 C 10.287,13.599 11.2,12.822 12.11,12.044 l -7.292,0 z" id="path8070" sodipodi:nodetypes="cccccccccc" opacity="0.809" fill="#ffffff" stroke="#ffffff" stroke-linecap="square" stroke-width="1.75"/>
<path id="path8097" d="M 4.7991,9.8793 C 3.9666,9.854 12.087,9.9512 12.087,9.9512 11.177,9.1731 10.266,8.3951 9.3549,7.6172 l 3.3411,0 4.249,3.3778 c -1.416,1.125 -2.833,2.25 -4.249,3.375 l -3.3411,0 c 0.9111,-0.776 1.8221,-1.554 2.7321,-2.331 l -7.2879,0.02 0,-2.1828 z" stroke-miterlimit="10" inkscape:connector-curvature="0" sodipodi:nodetypes="ccccccccccc" opacity="0.749" stroke-opacity="0.914" fill="#2c2c2c" stroke-linecap="square" stroke-width="0.714"/>
<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="580" height="580">
<metadata id="metadata10"/>
<path id="path4151" d="m 30,261 286,0 0,-72.5 234,101.85 -234,101.15 0,-72.5 -286,0 z" mix-blend-mode="normal" solid-color="#000000" opacity="0.8" color-interpolation-filters="linearRGB" filter-gaussianBlur-deviation="0" color="#000000" image-rendering="auto" color-rendering="auto" stroke-width="64" isolation="auto" color-interpolation="sRGB" solid-opacity="1" fill="none" stroke-linejoin="round" filter-blend-mode="normal" stroke="#ffffff" shape-rendering="auto"/>
<path d="m 30,261 286,0 0,-72.5 234,101.85 -234,101.15 0,-72.5 -286,0 z" id="path4136" fill="#6a6a6a"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 745 B

View File

@ -966,8 +966,7 @@
<m k="area" v="~|false|no">
<m k="highway">
<m k="oneway" v="yes|true" zoom-min="16">
<line fix="true" src="assets:patterns/oneway.svg" stipple="320"
stipple-stroke="#666666" width="12" />
<lineSymbol src="assets:symbols/oneway.svg" />
</m>
</m>
</m>

View File

@ -963,8 +963,7 @@
<m k="area" v="~|false|no">
<m k="kind_detail">
<m k="oneway" v="yes|true" zoom-min="16">
<line fix="true" src="assets:patterns/oneway.svg" stipple="320"
stipple-stroke="#666666" width="12" />
<lineSymbol src="assets:symbols/oneway.svg" />
</m>
</m>
</m>

View File

@ -996,8 +996,7 @@
<m k="area" v="~|false|no">
<m k="highway">
<m k="oneway" v="yes|true" zoom-min="16">
<line fix="true" src="assets:patterns/oneway.svg" stipple="320"
stipple-stroke="#666666" width="12" />
<lineSymbol src="assets:symbols/oneway.svg" />
</m>
</m>
</m>

View File

@ -962,8 +962,7 @@
<m k="area" v="~|false|no">
<m k="highway">
<m k="oneway" v="yes|true" zoom-min="16">
<line fix="true" src="assets:patterns/oneway.svg" stipple="320"
stipple-stroke="#666666" width="12" />
<lineSymbol src="assets:symbols/oneway.svg" />
</m>
</m>
</m>

View File

@ -940,8 +940,7 @@
<m k="area" v="~|false|no">
<m k="highway">
<m k="oneway" v="yes|true" zoom-min="16">
<line fix="true" src="assets:patterns/oneway.svg" stipple="320"
stipple-stroke="#666666" width="12" />
<lineSymbol src="assets:symbols/oneway.svg" />
</m>
</m>
</m>

View File

@ -940,8 +940,7 @@
<m k="area" v="~|false|no">
<m k="highway">
<m k="oneway" v="yes|true" zoom-min="16">
<line fix="true" src="assets:patterns/oneway.svg" stipple="320"
stipple-stroke="#666666" width="12" />
<lineSymbol src="assets:symbols/oneway.svg" />
</m>
</m>
</m>

View File

@ -989,8 +989,7 @@
<m k="area" v="~|false|no">
<m k="highway">
<m k="oneway" v="yes|true" zoom-min="16">
<line fix="true" src="assets:patterns/oneway.svg" stipple="320"
stipple-stroke="#666666" width="12" />
<lineSymbol src="assets:symbols/oneway.svg" />
</m>
</m>
</m>

View File

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

View File

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

View File

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