Skip to content

Commit

Permalink
SVG resources scaling, closes #214
Browse files Browse the repository at this point in the history
  • Loading branch information
devemux86 committed Dec 8, 2016
1 parent 6344542 commit 4cd1146
Show file tree
Hide file tree
Showing 16 changed files with 378 additions and 135 deletions.
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Polygon label position enhancements [#80](https://github.com/mapsforge/vtm/issues/80)
- vtm-web modules update [#51](https://github.com/mapsforge/vtm/issues/51)
- Mapbox vector tiles [#57](https://github.com/mapsforge/vtm/issues/57)
- SVG resources scaling [#214](https://github.com/mapsforge/vtm/issues/214)
- Circle map style [#122](https://github.com/mapsforge/vtm/issues/122)
- PathLayer (vtm) fix disappearing segments [#108](https://github.com/mapsforge/vtm/issues/108)
- House numbers (nodes) fix visibility [#168](https://github.com/mapsforge/vtm/issues/168)
Expand Down
20 changes: 19 additions & 1 deletion resources/rendertheme.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
<xs:attribute name="id" default="0" type="xs:string" use="optional" />
<xs:attribute name="use" 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="fill" default="#000000" type="tns:color" use="optional" />
<xs:attribute name="stroke" default="#00000000" type="tns:color" use="optional" />
<xs:attribute name="stroke-width" default="0" type="tns:nonNegativeFloat" use="optional" />
Expand All @@ -147,8 +150,11 @@
<xs:attribute name="area-size" default="0" type="tns:nonNegativeFloat" use="optional" />
<!-- priority for label placement, 0 = highest priority -->
<xs:attribute name="priority" default="0" type="xs:integer" use="optional" />
<!-- symbol src name in atlas -->
<!-- symbol src name -->
<xs:attribute name="symbol" 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:complexType>

<xs:complexType name="circle">
Expand All @@ -170,6 +176,9 @@
<xs:attribute name="use" 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="width" default="0" type="xs:float" use="optional" />
<!-- minimum scaled width to draw outline -->
Expand All @@ -194,13 +203,19 @@
<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:attribute name="align-center" default="false" type="xs:boolean" use="optional" />
<xs:attribute name="repeat" default="false" type="xs:boolean" use="optional" />
</xs:complexType>
Expand Down Expand Up @@ -229,6 +244,9 @@
<xs:complexType name="symbol">
<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="extrusion">
Expand Down
8 changes: 4 additions & 4 deletions vtm-android/src/org/oscim/android/canvas/AndroidGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ public Bitmap decodeBitmapImpl(InputStream inputStream) {
}

@Override
public Bitmap decodeSvgBitmapImpl(InputStream inputStream) {
public Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) {
try {
return new AndroidSvgBitmap(inputStream);
return new AndroidSvgBitmap(inputStream, width, height, percent);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}

@Override
public Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src) {
public Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) {
try {
return createBitmap(relativePathPrefix, src);
return createBitmap(relativePathPrefix, src, width, height, percent);
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
12 changes: 7 additions & 5 deletions vtm-android/src/org/oscim/android/canvas/AndroidSvgBitmap.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*
* Copyright 2016 devemux86
* Copyright 2010, 2011, 2012 mapsforge.org
* Copyright 2013-2014 Ludwig M Brinckmann
* Copyright 2014-2016 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
Expand Down Expand Up @@ -74,13 +76,13 @@ public static android.graphics.Bitmap getResourceBitmap(InputStream inputStream,
}
}

private static android.graphics.Bitmap getResourceBitmapImpl(InputStream inputStream) throws IOException {
private static android.graphics.Bitmap getResourceBitmapImpl(InputStream inputStream, int width, int height, int percent) throws IOException {
synchronized (SVG.getVersion()) {
return getResourceBitmap(inputStream, CanvasAdapter.dpi / CanvasAdapter.DEFAULT_DPI, DEFAULT_SIZE, 0, 0, 100);
return getResourceBitmap(inputStream, CanvasAdapter.dpi / CanvasAdapter.DEFAULT_DPI, DEFAULT_SIZE, width, height, percent);
}
}

public AndroidSvgBitmap(InputStream inputStream) throws IOException {
super(getResourceBitmapImpl(inputStream));
public AndroidSvgBitmap(InputStream inputStream, int width, int height, int percent) throws IOException {
super(getResourceBitmapImpl(inputStream, width, height, percent));
}
}
8 changes: 4 additions & 4 deletions vtm-desktop/src/org/oscim/awt/AwtGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ public Bitmap decodeBitmapImpl(InputStream inputStream) {
}

@Override
public Bitmap decodeSvgBitmapImpl(InputStream inputStream) {
public Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) {
try {
return new AwtSvgBitmap(inputStream);
return new AwtSvgBitmap(inputStream, width, height, percent);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}

@Override
public Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src) {
public Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) {
try {
return createBitmap(relativePathPrefix, src);
return createBitmap(relativePathPrefix, src, width, height, percent);
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
10 changes: 5 additions & 5 deletions vtm-desktop/src/org/oscim/awt/AwtSvgBitmap.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 devemux86
* Copyright 2015-2016 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
Expand Down Expand Up @@ -77,13 +77,13 @@ public static BufferedImage getResourceBitmap(InputStream inputStream, float sca
}
}

private static BufferedImage getResourceBitmapImpl(InputStream inputStream) throws IOException {
private static BufferedImage getResourceBitmapImpl(InputStream inputStream, int width, int height, int percent) throws IOException {
synchronized (SVGCache.getSVGUniverse()) {
return getResourceBitmap(inputStream, CanvasAdapter.dpi / CanvasAdapter.DEFAULT_DPI, DEFAULT_SIZE, 0, 0, 100);
return getResourceBitmap(inputStream, CanvasAdapter.dpi / CanvasAdapter.DEFAULT_DPI, DEFAULT_SIZE, width, height, percent);
}
}

public AwtSvgBitmap(InputStream inputStream) throws IOException {
super(getResourceBitmapImpl(inputStream));
public AwtSvgBitmap(InputStream inputStream, int width, int height, int percent) throws IOException {
super(getResourceBitmapImpl(inputStream, width, height, percent));
}
}
10 changes: 5 additions & 5 deletions vtm-ios/src/org/oscim/ios/backend/IosGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public class IosGraphics extends CanvasAdapter {

static final Logger log = LoggerFactory.getLogger(IosGraphics.class);
private static final Logger log = LoggerFactory.getLogger(IosGraphics.class);

public static void init() {
CanvasAdapter.init(new IosGraphics());
Expand Down Expand Up @@ -62,19 +62,19 @@ protected Bitmap decodeBitmapImpl(InputStream inputStream) {
}

@Override
protected Bitmap decodeSvgBitmapImpl(InputStream inputStream) {
protected Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) {
try {
return new IosSvgBitmap(inputStream);
return new IosSvgBitmap(inputStream, width, height, percent);
} catch (IOException e) {
log.error("decodeSvgBitmapImpl", e);
return null;
}
}

@Override
protected Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src) {
protected Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) {
try {
return createBitmap(relativePathPrefix, src);
return createBitmap(relativePathPrefix, src, width, height, percent);
} catch (IOException e) {
log.error("loadBitmapAssetImpl", e);
return null;
Expand Down
8 changes: 4 additions & 4 deletions vtm-ios/src/org/oscim/ios/backend/IosSvgBitmap.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public static UIImage getResourceBitmap(InputStream inputStream, float scaleFact
return renderer.asImageWithSize(new CGSize(bitmapWidth, bitmapHeight), 1);
}

private static UIImage getResourceBitmapImpl(InputStream inputStream) {
return getResourceBitmap(inputStream, CanvasAdapter.dpi / CanvasAdapter.DEFAULT_DPI, DEFAULT_SIZE, 0, 0, 100);
private static UIImage getResourceBitmapImpl(InputStream inputStream, int width, int height, int percent) {
return getResourceBitmap(inputStream, CanvasAdapter.dpi / CanvasAdapter.DEFAULT_DPI, DEFAULT_SIZE, width, height, percent);
}

public IosSvgBitmap(InputStream inputStream) throws IOException {
super(getResourceBitmapImpl(inputStream));
public IosSvgBitmap(InputStream inputStream, int width, int height, int percent) throws IOException {
super(getResourceBitmapImpl(inputStream, width, height, percent));
}
}
6 changes: 3 additions & 3 deletions vtm-web/src/org/oscim/gdx/client/GwtGdxGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ public static synchronized float getTextWidth(String text, String font) {
}

@Override
public Bitmap decodeBitmapImpl(InputStream in) {
public Bitmap decodeBitmapImpl(InputStream inputStream) {
// TODO
return null;
}

@Override
public Bitmap decodeSvgBitmapImpl(InputStream in) {
public Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) {
// TODO
return null;
}

@Override
public Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src) {
public Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) {
String pathName = (relativePathPrefix == null || relativePathPrefix.length() == 0 ? "" : relativePathPrefix + File.separatorChar) + src;
return new GwtBitmap(pathName);
}
Expand Down
18 changes: 11 additions & 7 deletions vtm/src/org/oscim/backend/CanvasAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ public static Bitmap decodeBitmap(InputStream inputStream) {
* @param inputStream the input stream
* @return the SVG bitmap
*/
protected abstract Bitmap decodeSvgBitmapImpl(InputStream inputStream);
protected abstract Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent);

public static Bitmap decodeSvgBitmap(InputStream inputStream) {
return g.decodeSvgBitmapImpl(inputStream);
public static Bitmap decodeSvgBitmap(InputStream inputStream, int width, int height, int percent) {
return g.decodeSvgBitmapImpl(inputStream, width, height, percent);
}

/**
Expand All @@ -130,13 +130,17 @@ public static Bitmap decodeSvgBitmap(InputStream inputStream) {
* @param src the resource
* @return the bitmap
*/
protected abstract Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src);
protected abstract Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent);

public static Bitmap getBitmapAsset(String relativePathPrefix, String src) {
return g.loadBitmapAssetImpl(relativePathPrefix, src);
return getBitmapAsset(relativePathPrefix, src, 0, 0, 100);
}

protected static Bitmap createBitmap(String relativePathPrefix, String src) throws IOException {
public static Bitmap getBitmapAsset(String relativePathPrefix, String src, int width, int height, int percent) {
return g.loadBitmapAssetImpl(relativePathPrefix, src, width, height, percent);
}

protected static Bitmap createBitmap(String relativePathPrefix, String src, int width, int height, int percent) throws IOException {
if (src == null || src.length() == 0) {
// no image source defined
return null;
Expand All @@ -163,7 +167,7 @@ protected static Bitmap createBitmap(String relativePathPrefix, String src) thro

Bitmap bitmap;
if (src.toLowerCase(Locale.ENGLISH).endsWith(".svg"))
bitmap = decodeSvgBitmap(inputStream);
bitmap = decodeSvgBitmap(inputStream, width, height, percent);
else
bitmap = decodeBitmap(inputStream);
inputStream.close();
Expand Down
Loading

0 comments on commit 4cd1146

Please sign in to comment.