Render themes: PNG scaling, fix #595

This commit is contained in:
Emux
2018-10-11 10:56:58 +03:00
parent f853e54d77
commit a530070ecf
15 changed files with 207 additions and 108 deletions

View File

@@ -1,7 +1,7 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
* Copyright 2013-2014 Ludwig M Brinckmann
* Copyright 2014-2017 devemux86
* Copyright 2014-2018 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
@@ -24,6 +24,7 @@ import android.graphics.RectF;
import com.caverock.androidsvg.SVG;
import org.oscim.backend.CanvasAdapter;
import org.oscim.utils.GraphicUtils;
import java.io.IOException;
import java.io.InputStream;
@@ -41,34 +42,12 @@ public class AndroidSvgBitmap extends AndroidBitmap {
double scale = scaleFactor / Math.sqrt((picture.getHeight() * picture.getWidth()) / defaultSize);
float bitmapWidth = (float) (picture.getWidth() * scale);
float bitmapHeight = (float) (picture.getHeight() * scale);
float[] bmpSize = GraphicUtils.imageSize(picture.getWidth(), picture.getHeight(), (float) scale, width, height, percent);
float aspectRatio = (1f * picture.getWidth()) / picture.getHeight();
if (width != 0 && height != 0) {
// both width and height set, override any other setting
bitmapWidth = width;
bitmapHeight = height;
} else if (width == 0 && height != 0) {
// only width set, calculate from aspect ratio
bitmapWidth = height * aspectRatio;
bitmapHeight = height;
} else if (width != 0 && height == 0) {
// only height set, calculate from aspect ratio
bitmapHeight = width / aspectRatio;
bitmapWidth = width;
}
if (percent != 100) {
bitmapWidth *= percent / 100f;
bitmapHeight *= percent / 100f;
}
android.graphics.Bitmap bitmap = android.graphics.Bitmap.createBitmap((int) Math.ceil(bitmapWidth),
(int) Math.ceil(bitmapHeight), Bitmap.Config.ARGB_8888);
android.graphics.Bitmap bitmap = android.graphics.Bitmap.createBitmap((int) Math.ceil(bmpSize[0]),
(int) Math.ceil(bmpSize[1]), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawPicture(picture, new RectF(0, 0, bitmapWidth, bitmapHeight));
canvas.drawPicture(picture, new RectF(0, 0, bmpSize[0], bmpSize[1]));
return bitmap;
} catch (Exception e) {