From 304317381415ed8d269d52c430b73375d00bf408 Mon Sep 17 00:00:00 2001 From: Emux Date: Sun, 15 Nov 2020 17:20:52 +0200 Subject: [PATCH] Symbol scale option (#790) --- docs/Changelog.md | 2 + vtm/src/org/oscim/backend/CanvasAdapter.java | 7 +++- vtm/src/org/oscim/theme/XmlThemeBuilder.java | 39 ++++++++++++-------- vtm/src/org/oscim/utils/Parameters.java | 7 ++++ 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index 3a2d5d07..36c9e734 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -6,6 +6,8 @@ - Mapsforge: map stream support [#784](https://github.com/mapsforge/vtm/pull/784) - Render theme from Android content providers [#783](https://github.com/mapsforge/vtm/pull/783) - Render theme xml pull parser [#786](https://github.com/mapsforge/vtm/pull/786) +- Symbol scale option [#790](https://github.com/mapsforge/vtm/pull/790) + - `Parameters.SYMBOL_SCALING` - Many other minor improvements and bug fixes - [Solved issues](https://github.com/mapsforge/vtm/issues?q=is%3Aclosed+milestone%3A0.15.0) diff --git a/vtm/src/org/oscim/backend/CanvasAdapter.java b/vtm/src/org/oscim/backend/CanvasAdapter.java index 05814757..04a0c273 100644 --- a/vtm/src/org/oscim/backend/CanvasAdapter.java +++ b/vtm/src/org/oscim/backend/CanvasAdapter.java @@ -1,6 +1,6 @@ /* * Copyright 2013 Hannes Janetzek - * Copyright 2016-2018 devemux86 + * Copyright 2016-2020 devemux86 * Copyright 2017 Longri * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). @@ -59,6 +59,11 @@ public abstract class CanvasAdapter { */ public static Platform platform = Platform.UNKNOWN; + /** + * The symbol scale. + */ + public static float symbolScale = 1; + /** * The text scale. */ diff --git a/vtm/src/org/oscim/theme/XmlThemeBuilder.java b/vtm/src/org/oscim/theme/XmlThemeBuilder.java index c660dadb..e3693e23 100644 --- a/vtm/src/org/oscim/theme/XmlThemeBuilder.java +++ b/vtm/src/org/oscim/theme/XmlThemeBuilder.java @@ -50,6 +50,7 @@ import org.oscim.theme.styles.SymbolStyle.SymbolBuilder; import org.oscim.theme.styles.TextStyle.TextBuilder; import org.oscim.utils.FastMath; import org.oscim.utils.IOUtils; +import org.oscim.utils.Parameters; import org.oscim.utils.Utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,10 +62,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.*; -import static java.lang.Boolean.parseBoolean; -import static java.lang.Float.parseFloat; -import static java.lang.Integer.parseInt; - public class XmlThemeBuilder { private static final Logger log = LoggerFactory.getLogger(XmlThemeBuilder.class); @@ -565,7 +562,7 @@ public class XmlThemeBuilder { b.color(value); else if ("width".equals(name) || "stroke-width".equals(name)) { - b.strokeWidth = parseFloat(value) * mScale * mStrokeScale; + b.strokeWidth = Float.parseFloat(value) * mScale * mStrokeScale; if (line == null) { if (!isOutline) validateNonNegative("width", b.strokeWidth); @@ -579,16 +576,16 @@ public class XmlThemeBuilder { b.cap = Cap.valueOf(value.toUpperCase(Locale.ENGLISH)); else if ("fix".equals(name)) - b.fixed = parseBoolean(value); + b.fixed = Boolean.parseBoolean(value); else if ("stipple".equals(name)) - b.stipple = Math.round(parseInt(value) * mScale * mStrokeScale); + b.stipple = Math.round(Integer.parseInt(value) * mScale * mStrokeScale); else if ("stipple-stroke".equals(name)) b.stippleColor(value); else if ("stipple-width".equals(name)) - b.stippleWidth = parseFloat(value); + b.stippleWidth = Float.parseFloat(value); else if ("fade".equals(name)) b.fadeScale = Integer.parseInt(value); @@ -597,7 +594,7 @@ public class XmlThemeBuilder { ; //min = Float.parseFloat(value); else if ("blur".equals(name)) - b.blur = parseFloat(value); + b.blur = Float.parseFloat(value); else if ("style".equals(name)) ; // ignore @@ -667,8 +664,10 @@ public class XmlThemeBuilder { b.stippleWidth = 1; b.stippleColor = b.fillColor; } else { - if (src != null) - b.texture = Utils.loadTexture(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, b.symbolPercent); + if (src != null) { + float symbolScale = Parameters.SYMBOL_SCALING == Parameters.SymbolScaling.ALL ? CanvasAdapter.symbolScale : 1; + b.texture = Utils.loadTexture(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, (int) (b.symbolPercent * symbolScale)); + } if (b.texture != null && hasSymbol) { // Line symbol @@ -1063,7 +1062,7 @@ public class XmlThemeBuilder { else if ("dy".equals(name)) // NB: minus.. - b.dy = -Float.parseFloat(value) * mScale; + b.dy = -Float.parseFloat(value) * mScale * CanvasAdapter.symbolScale; else if ("symbol".equals(name)) symbol = value; @@ -1088,7 +1087,7 @@ public class XmlThemeBuilder { if (b.dy == 0) { value = "above".equals(value) ? "20" : "-20"; // NB: minus.. - b.dy = -Float.parseFloat(value) * mScale; + b.dy = -Float.parseFloat(value) * mScale * CanvasAdapter.symbolScale; } } else @@ -1103,7 +1102,7 @@ public class XmlThemeBuilder { String lowValue = symbol.toLowerCase(Locale.ENGLISH); if (lowValue.endsWith(".png") || lowValue.endsWith(".svg")) { try { - b.bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), symbol, b.symbolWidth, b.symbolHeight, b.symbolPercent); + b.bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), symbol, b.symbolWidth, b.symbolHeight, (int) (b.symbolPercent * CanvasAdapter.symbolScale)); } catch (Exception e) { log.error("{}: {}", symbol, e.getMessage()); } @@ -1247,7 +1246,17 @@ public class XmlThemeBuilder { String lowSrc = b.src.toLowerCase(Locale.ENGLISH); if (lowSrc.endsWith(".png") || lowSrc.endsWith(".svg")) { try { - Bitmap bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), b.src, b.symbolWidth, b.symbolHeight, b.symbolPercent); + float symbolScale = 1; + switch (Parameters.SYMBOL_SCALING) { + case ALL: + symbolScale = CanvasAdapter.symbolScale; + break; + case POI: + if (!b.repeat) + symbolScale = CanvasAdapter.symbolScale; + break; + } + Bitmap bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), b.src, b.symbolWidth, b.symbolHeight, (int) (b.symbolPercent * symbolScale)); if (bitmap != null) return buildSymbol(b, b.src, bitmap); } catch (Exception e) { diff --git a/vtm/src/org/oscim/utils/Parameters.java b/vtm/src/org/oscim/utils/Parameters.java index 2467c83d..2d72252b 100644 --- a/vtm/src/org/oscim/utils/Parameters.java +++ b/vtm/src/org/oscim/utils/Parameters.java @@ -16,6 +16,8 @@ package org.oscim.utils; public final class Parameters { + public enum SymbolScaling {ALL, POI} + /** * If true the Animator2 will be used instead of default Animator. */ @@ -73,6 +75,11 @@ public final class Parameters { */ public static int SIMPLIFICATION_TOLERANCE = 0; + /** + * Symbol scaling mode. + */ + public static SymbolScaling SYMBOL_SCALING = SymbolScaling.POI; + /** * Texture atlas in themes. */