Skip to content

Commit

Permalink
Merge pull request #737 from mapsforge/bg
Browse files Browse the repository at this point in the history
Render themes: text background color (highway shields)
  • Loading branch information
devemux86 authored Aug 6, 2019
2 parents e613716 + dcb7b0d commit 53b262f
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 12 deletions.
2 changes: 2 additions & 0 deletions resources/rendertheme.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<xs:attribute name="font-family" default="default" type="tns:fontFamily" use="optional" />
<xs:attribute name="style" default="normal" type="tns:fontStyle" use="optional" />
<xs:attribute name="size" default="0" type="tns:nonNegativeFloat" use="optional" />
<xs:attribute name="bg-fill" default="#00000000" type="tns:color" use="optional" />
<xs:attribute name="fill" default="#000000" type="tns:color" 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" />
Expand Down Expand Up @@ -219,6 +220,7 @@
<xs:attribute name="font-family" default="default" type="tns:fontFamily" use="optional" />
<xs:attribute name="style" default="normal" type="tns:fontStyle" use="optional" />
<xs:attribute name="size" default="0" type="tns:nonNegativeFloat" use="optional" />
<xs:attribute name="bg-fill" default="#00000000" type="tns:color" use="optional" />
<xs:attribute name="fill" default="#000000" type="tns:color" 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" />
Expand Down
5 changes: 3 additions & 2 deletions vtm-android/src/org/oscim/android/canvas/AndroidCanvas.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016-2017 devemux86
* Copyright 2016-2019 devemux86
* Copyright 2017 nebular
* Copyright 2017 Longri
*
Expand All @@ -21,8 +21,8 @@

import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;

import org.oscim.backend.canvas.Bitmap;
import org.oscim.backend.canvas.Canvas;
import org.oscim.backend.canvas.Paint;
Expand Down Expand Up @@ -93,6 +93,7 @@ public void fillRectangle(float x, float y, float width, float height, int color
RectF rect = new RectF(x, y, x + width, y + height);
android.graphics.Paint paint = new android.graphics.Paint();
paint.setColor(color);
paint.setXfermode(new PorterDuffXfermode(color == Color.TRANSPARENT ? PorterDuff.Mode.CLEAR : PorterDuff.Mode.SRC_OVER));
canvas.drawRect(rect, paint);
}

Expand Down
3 changes: 2 additions & 1 deletion vtm-themes/resources/assets/vtm/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
<!--references-->
<style-text style="bold" fill="#606060" id="ref" k="ref" priority="2" size="12" stroke="#ffffff"
stroke-width="2.0" />
<style-text caption="true" id="ref-caption" use="ref" />
<style-text caption="true" style="bold" fill="#ffffff" id="ref-caption" k="ref" priority="2"
size="12" bg-fill="#45a976" />
<!--ferry-->
<style-text style="bold" fill="#606060" id="ferry" k="name" size="12" stroke="#ffffff"
stroke-width="2.0" />
Expand Down
3 changes: 2 additions & 1 deletion vtm-themes/resources/assets/vtm/mapzen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

<style-text style="bold" fill="#606060" id="ref" k="ref" priority="2" size="12" stroke="#ffffff"
stroke-width="2.0" />
<style-text caption="true" id="ref-caption" use="ref" />
<style-text caption="true" style="bold" fill="#ffffff" id="ref-caption" k="ref" priority="2"
size="12" bg-fill="#45a976" />

<style-text style="bold" fill="#606060" id="ferry" k="name" size="12" stroke="#ffffff"
stroke-width="2.0" />
Expand Down
3 changes: 2 additions & 1 deletion vtm-themes/resources/assets/vtm/newtron.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
<!--references-->
<style-text style="bold" fill="#606060" id="ref" k="ref" priority="2" size="12" stroke="#ffffff"
stroke-width="2.0" />
<style-text caption="true" id="ref-caption" use="ref" />
<style-text caption="true" style="bold" fill="#ffffff" id="ref-caption" k="ref" priority="2"
size="12" bg-fill="#45a976" />


<!--###### AREA styles ######-->
Expand Down
3 changes: 2 additions & 1 deletion vtm-themes/resources/assets/vtm/openmaptiles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
<!--references-->
<style-text style="bold" fill="#606060" id="ref" k="ref" priority="2" size="12" stroke="#ffffff"
stroke-width="2.0" />
<style-text caption="true" id="ref-caption" use="ref" />
<style-text caption="true" style="bold" fill="#ffffff" id="ref-caption" k="ref" priority="2"
size="12" bg-fill="#45a976" />
<!--ferry-->
<style-text style="bold" fill="#606060" id="ferry" k="name" size="12" stroke="#ffffff"
stroke-width="2.0" />
Expand Down
3 changes: 2 additions & 1 deletion vtm-themes/resources/assets/vtm/osmagray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
<!--references-->
<style-text style="bold" fill="#606060" id="ref" k="ref" priority="2" size="12" stroke="#ffffff"
stroke-width="2.0" />
<style-text caption="true" id="ref-caption" use="ref" />
<style-text caption="true" style="bold" fill="#ffffff" id="ref-caption" k="ref" priority="2"
size="12" bg-fill="#5b5b5b" />


<!--###### AREA styles ######-->
Expand Down
3 changes: 2 additions & 1 deletion vtm-themes/resources/assets/vtm/osmarender.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
<!--references-->
<style-text style="bold" fill="#606060" id="ref" k="ref" priority="2" size="12" stroke="#ffffff"
stroke-width="2.0" />
<style-text caption="true" id="ref-caption" use="ref" />
<style-text caption="true" style="bold" fill="#ffffff" id="ref-caption" k="ref" priority="2"
size="12" bg-fill="#007f00" />


<!--###### AREA styles ######-->
Expand Down
3 changes: 2 additions & 1 deletion vtm-themes/resources/assets/vtm/tronrender.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
<!--references-->
<style-text style="bold" fill="#606060" id="ref" k="ref" priority="2" size="12" stroke="#ffffff"
stroke-width="2.0" />
<style-text caption="true" id="ref-caption" use="ref" />
<style-text caption="true" style="bold" fill="#ffffff" id="ref-caption" k="ref" priority="2"
size="12" bg-fill="#45a976" />


<!--###### AREA styles ######-->
Expand Down
11 changes: 8 additions & 3 deletions vtm/src/org/oscim/renderer/bucket/TextBucket.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2012 Hannes Janetzek
* Copyright 2019 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
Expand Down Expand Up @@ -89,7 +90,7 @@ public void prepare() {
int advanceY = 0;
float x = 0;
float y = 0;
float yy;
float xx, yy;

TextureItem t = pool.get();
textures = t;
Expand Down Expand Up @@ -127,14 +128,18 @@ public void prepare() {
}
}

xx = x + mFontPadX;
yy = y + height - it.text.fontDescent;

mCanvas.drawText(it.label, x, yy, it.text.paint, it.text.stroke);

// FIXME !!!
if (width > TEXTURE_WIDTH)
width = TEXTURE_WIDTH;

if (it.text.bgFill != null)
mCanvas.fillRectangle(x + mFontPadX, y + 1, width - 2 * mFontPadX, height, it.text.bgFill.getColor());

mCanvas.drawText(it.label, xx, yy, it.text.paint, it.text.stroke);

while (it != null) {
addItem(it, width, height, x, y);

Expand Down
3 changes: 3 additions & 0 deletions vtm/src/org/oscim/theme/XmlThemeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,9 @@ else if ("style".equals(name) || "font-style".equals(name))
else if ("size".equals(name) || "font-size".equals(name))
b.fontSize = Float.parseFloat(value);

else if ("bg-fill".equals(name))
b.bgFillColor = Color.parseColor(value);

else if ("fill".equals(name))
b.fillColor = Color.parseColor(value);

Expand Down
29 changes: 29 additions & 0 deletions vtm/src/org/oscim/theme/styles/TextStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.oscim.backend.canvas.Paint.FontStyle;
import org.oscim.renderer.atlas.TextureRegion;

import static org.oscim.backend.canvas.Color.parseColor;

public final class TextStyle extends RenderStyle<TextStyle> {

public static class TextBuilder<T extends TextBuilder<T>> extends StyleBuilder<T> {
Expand All @@ -46,6 +48,8 @@ public static class TextBuilder<T extends TextBuilder<T>> extends StyleBuilder<T
public int symbolHeight;
public int symbolPercent;

public int bgFillColor;

public T reset() {
cat = null;
fontFamily = FontFamily.DEFAULT;
Expand All @@ -67,6 +71,8 @@ public T reset() {
symbolHeight = 0;
symbolPercent = 100;

bgFillColor = Color.TRANSPARENT;

return self();
}

Expand Down Expand Up @@ -151,6 +157,16 @@ public T symbolPercent(int symbolPercent) {
return self();
}

public T bgFillColor(int color) {
this.bgFillColor = color;
return self();
}

public T bgFillColor(String color) {
this.bgFillColor = parseColor(color);
return self();
}

public T from(TextBuilder<?> other) {
cat = other.cat;
fontFamily = other.fontFamily;
Expand All @@ -172,6 +188,8 @@ public T from(TextBuilder<?> other) {
symbolHeight = other.symbolHeight;
symbolPercent = other.symbolPercent;

bgFillColor = other.bgFillColor;

return self();
}

Expand Down Expand Up @@ -201,6 +219,9 @@ public TextBuilder<?> set(TextStyle text) {
this.symbolHeight = text.symbolHeight;
this.symbolPercent = text.symbolPercent;

if (text.bgFill != null)
this.bgFillColor = themeCallback != null ? themeCallback.getColor(text, text.bgFill.getColor()) : text.bgFill.getColor();

return self();
}
}
Expand Down Expand Up @@ -241,6 +262,12 @@ public TextBuilder<?> set(TextStyle text) {
this.symbolWidth = b.symbolWidth;
this.symbolHeight = b.symbolHeight;
this.symbolPercent = b.symbolPercent;

if (b.bgFillColor != Color.TRANSPARENT) {
bgFill = CanvasAdapter.newPaint();
bgFill.setColor(b.themeCallback != null ? b.themeCallback.getColor(this, b.bgFillColor) : b.bgFillColor);
} else
bgFill = null;
}

public final String style;
Expand All @@ -267,6 +294,8 @@ public TextBuilder<?> set(TextStyle text) {
public final int symbolHeight;
public final int symbolPercent;

public final Paint bgFill;

@Override
public void dispose() {
if (bitmap != null)
Expand Down

0 comments on commit 53b262f

Please sign in to comment.