Improved SVG scaling

pull/215/head
M66B 4 months ago
parent 749153d75d
commit 7865c2317f

@ -286,13 +286,24 @@ class ImageHelper {
SVG svg = SVG.getFromInputStream(is); SVG svg = SVG.getFromInputStream(is);
float dw = svg.getDocumentWidth(); float dw = svg.getDocumentWidth();
float dh = svg.getDocumentHeight(); float dh = svg.getDocumentHeight();
if (dw <= 0 || dh <= 0) {
RectF rect = svg.getDocumentViewBox();
dw = rect.width();
dh = rect.height();
if (dw <= 0 || dh <= 0) { if (dw <= 0 || dh <= 0) {
dw = scaleToPixels; dw = scaleToPixels;
dh = scaleToPixels; dh = scaleToPixels;
} }
}
int w = scaleToPixels; int w, h;
int h = Math.round(scaleToPixels * dh / dw); if (dw > scaleToPixels || dh > scaleToPixels) {
w = scaleToPixels;
h = Math.round(scaleToPixels * dh / dw);
} else {
w = Math.round(dw);
h = Math.round(dh);
}
svg.setDocumentWidth("100%"); svg.setDocumentWidth("100%");
svg.setDocumentHeight("100%"); svg.setDocumentHeight("100%");

Loading…
Cancel
Save