Render themes: stroke dash array improvements, fix #131

This commit is contained in:
Emux 2017-09-23 15:40:20 +03:00
parent 7c12c2ae9b
commit 7865867973
2 changed files with 32 additions and 40 deletions

View File

@ -553,7 +553,7 @@ public class XmlMapsforgeThemeBuilder extends DefaultHandler {
else if ("style".equals(name)) else if ("style".equals(name))
; // ignore ; // ignore
else if ("stroke-dasharray".equals(name)) { else if ("dasharray".equals(name) || "stroke-dasharray".equals(name)) {
b.dashArray = parseFloatArray(value); b.dashArray = parseFloatArray(value);
for (int j = 0; j < b.dashArray.length; ++j) { for (int j = 0; j < b.dashArray.length; ++j) {
b.dashArray[j] = b.dashArray[j] * mScale; b.dashArray[j] = b.dashArray[j] * mScale;
@ -576,38 +576,34 @@ public class XmlMapsforgeThemeBuilder extends DefaultHandler {
} }
if (b.dashArray != null) { if (b.dashArray != null) {
// Create a dashed texture // Stroke dash array
int bmpWidth = 0; int width = 0;
int bmpHeight = (int) (b.strokeWidth); int height = (int) (b.strokeWidth);
if (bmpHeight < 1) if (height < 1)
bmpHeight = 2; height = 1;
for (float f : b.dashArray) { for (float f : b.dashArray) {
if (f < 1) if (f < 1)
f = 1; f = 1;
bmpWidth += f; width += f;
} }
Bitmap bitmap = CanvasAdapter.newBitmap(width, height, 0);
int factor = 10;
Bitmap bmp = CanvasAdapter.newBitmap(bmpWidth * factor, bmpHeight * factor, 0);
Canvas canvas = CanvasAdapter.newCanvas(); Canvas canvas = CanvasAdapter.newCanvas();
canvas.setBitmap(bmp); canvas.setBitmap(bitmap);
boolean bw = false;
int x = 0; int x = 0;
boolean transparent = false;
for (float f : b.dashArray) { for (float f : b.dashArray) {
if (f < 1) if (f < 1)
f = 1; f = 1;
canvas.fillRectangle(x * factor, 0, f * factor, bmpHeight * factor, (bw ? Color.TRANSPARENT : Color.WHITE)); canvas.fillRectangle(x, 0, f, height, transparent ? Color.TRANSPARENT : Color.WHITE);
x += f; x += f;
bw = !bw; transparent = !transparent;
} }
b.texture = new TextureItem(bmp); b.texture = new TextureItem(bitmap);
b.texture.mipmap = false; b.texture.mipmap = true;
b.stipple = (int) (bmpWidth * 1.2f);
b.stippleWidth = bmpWidth;
b.fixed = false; b.fixed = false;
b.randomOffset = false; b.randomOffset = false;
b.stipple = width;
b.stippleWidth = 1;
b.stippleColor = b.fillColor; b.stippleColor = b.fillColor;
b.fillColor = Color.TRANSPARENT; b.fillColor = Color.TRANSPARENT;
b.strokeColor = Color.TRANSPARENT; b.strokeColor = Color.TRANSPARENT;

View File

@ -551,7 +551,7 @@ public class XmlThemeBuilder extends DefaultHandler {
else if ("style".equals(name)) else if ("style".equals(name))
; // ignore ; // ignore
else if ("dasharray".equals(name)) { else if ("dasharray".equals(name) || "stroke-dasharray".equals(name)) {
b.dashArray = parseFloatArray(value); b.dashArray = parseFloatArray(value);
for (int j = 0; j < b.dashArray.length; ++j) { for (int j = 0; j < b.dashArray.length; ++j) {
b.dashArray[j] = b.dashArray[j] * mScale; b.dashArray[j] = b.dashArray[j] * mScale;
@ -574,38 +574,34 @@ public class XmlThemeBuilder extends DefaultHandler {
} }
if (b.dashArray != null) { if (b.dashArray != null) {
// Create a dashed texture // Stroke dash array
int bmpWidth = 0; int width = 0;
int bmpHeight = (int) (b.strokeWidth); int height = (int) (b.strokeWidth);
if (bmpHeight < 1) if (height < 1)
bmpHeight = 2; height = 1;
for (float f : b.dashArray) { for (float f : b.dashArray) {
if (f < 1) if (f < 1)
f = 1; f = 1;
bmpWidth += f; width += f;
} }
Bitmap bitmap = CanvasAdapter.newBitmap(width, height, 0);
int factor = 10;
Bitmap bmp = CanvasAdapter.newBitmap(bmpWidth * factor, bmpHeight * factor, 0);
Canvas canvas = CanvasAdapter.newCanvas(); Canvas canvas = CanvasAdapter.newCanvas();
canvas.setBitmap(bmp); canvas.setBitmap(bitmap);
boolean bw = false;
int x = 0; int x = 0;
boolean transparent = false;
for (float f : b.dashArray) { for (float f : b.dashArray) {
if (f < 1) if (f < 1)
f = 1; f = 1;
canvas.fillRectangle(x * factor, 0, f * factor, bmpHeight * factor, (bw ? Color.TRANSPARENT : Color.WHITE)); canvas.fillRectangle(x, 0, f, height, transparent ? Color.TRANSPARENT : Color.WHITE);
x += f; x += f;
bw = !bw; transparent = !transparent;
} }
b.texture = new TextureItem(bmp); b.texture = new TextureItem(bitmap);
b.texture.mipmap = false; b.texture.mipmap = true;
b.stipple = (int) (bmpWidth * 1.2f);
b.stippleWidth = bmpWidth;
b.fixed = false; b.fixed = false;
b.randomOffset = false; b.randomOffset = false;
b.stipple = width;
b.stippleWidth = 1;
b.stippleColor = b.fillColor; b.stippleColor = b.fillColor;
b.fillColor = Color.TRANSPARENT; b.fillColor = Color.TRANSPARENT;
b.strokeColor = Color.TRANSPARENT; b.strokeColor = Color.TRANSPARENT;