Symbol scale option (#790)

This commit is contained in:
Emux 2020-11-15 17:20:52 +02:00 committed by GitHub
parent cde5d898c7
commit 3043173814
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 16 deletions

View File

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

View File

@ -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.
*/

View File

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

View File

@ -16,6 +16,8 @@ package org.oscim.utils;
public final class Parameters {
public enum SymbolScaling {ALL, POI}
/**
* If true the <code>Animator2</code> will be used instead of default <code>Animator</code>.
*/
@ -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.
*/