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,5 +1,6 @@
/*
* Copyright 2016-2017 Longri
* Copyright 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
@@ -82,13 +83,25 @@ public class IosBitmap implements Bitmap {
CGImage image = new UIImage(data).getCGImage();
this.width = (int) image.getWidth();
this.height = (int) image.getHeight();
this.cgBitmapContext = CGBitmapContext.create(width, height, 8, 4 * width,
this.cgBitmapContext = CGBitmapContext.create(this.width, this.height, 8, 4 * this.width,
CGColorSpace.createDeviceRGB(), CGImageAlphaInfo.PremultipliedLast);
this.cgBitmapContext.drawImage(new CGRect(0, 0, width, height), image);
this.cgBitmapContext.drawImage(new CGRect(0, 0, this.width, this.height), image);
image.dispose();
}
/**
* Constructor<br>
* Create a IosBitmap from given InputStream
*
* @param inputStream
* @throws IOException
*/
public IosBitmap(InputStream inputStream, int width, int height, int percent) throws IOException {
// TODO Scaling
this(inputStream);
}
/**
* Constructor<br>
* Load a IosBitmap from Asset with given FilePath
@@ -256,4 +269,9 @@ public class IosBitmap implements Bitmap {
NSData data = uiImage.toPNGData();
return data.getBytes();
}
@Override
public void scaleTo(int width, int height) {
// TODO
}
}

View File

@@ -1,6 +1,6 @@
/*
* Copyright 2016 Longri
* Copyright 2016 devemux86
* Copyright 2016-2018 devemux86
* Copyright 2017 Longri
*
* This program is free software: you can redistribute it and/or modify it under the
@@ -59,6 +59,11 @@ public class IosGraphics extends CanvasAdapter {
return new IosBitmap(inputStream);
}
@Override
protected Bitmap decodeBitmapImpl(InputStream inputStream, int width, int height, int percent) throws IOException {
return new IosBitmap(inputStream, width, height, percent);
}
@Override
protected Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) throws IOException {
return new IosSvgBitmap(inputStream, width, height, percent);

View File

@@ -1,6 +1,6 @@
/*
* Copyright 2016 Longri
* Copyright 2016-2017 devemux86
* Copyright 2016-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
@@ -16,6 +16,7 @@
package org.oscim.ios.backend;
import org.oscim.backend.CanvasAdapter;
import org.oscim.utils.GraphicUtils;
import org.oscim.utils.IOUtils;
import org.robovm.apple.coregraphics.CGRect;
import org.robovm.apple.coregraphics.CGSize;
@@ -62,31 +63,9 @@ public class IosSvgBitmap extends IosBitmap {
double scale = scaleFactor / Math.sqrt((viewRect.getHeight() * viewRect.getWidth()) / defaultSize);
float bitmapWidth = (float) (viewRect.getWidth() * scale);
float bitmapHeight = (float) (viewRect.getHeight() * scale);
float[] bmpSize = GraphicUtils.imageSize((float) viewRect.getWidth(), (float) viewRect.getHeight(), (float) scale, width, height, percent);
float aspectRatio = (float) (viewRect.getWidth() / viewRect.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;
}
return renderer.asImageWithSize(new CGSize(bitmapWidth, bitmapHeight), 1);
return renderer.asImageWithSize(new CGSize(bmpSize[0], bmpSize[1]), 1);
}
private static UIImage getResourceBitmapImpl(InputStream inputStream, int width, int height, int percent) {