Changeset 13737 in josm for trunk


Ignore:
Timestamp:
2018-05-13T01:39:07+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #16201 - Fixes calculation of scaling factor (patch by floscher)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r13723 r13737  
    15681568        final float sourceWidth = svg.getWidth();
    15691569        final float sourceHeight = svg.getHeight();
    1570         final int realWidth;
    1571         final int realHeight;
     1570        final float realWidth;
     1571        final float realHeight;
    15721572        if (dim.width >= 0) {
    15731573            realWidth = dim.width;
     
    15751575                realHeight = dim.height;
    15761576            } else {
    1577                 realHeight = Math.round(sourceHeight * realWidth / sourceWidth);
     1577                realHeight = sourceHeight * realWidth / sourceWidth;
    15781578            }
    15791579        } else if (dim.height >= 0) {
    15801580            realHeight = dim.height;
    1581             realWidth = Math.round(sourceWidth * realHeight / sourceHeight);
     1581            realWidth = sourceWidth * realHeight / sourceHeight;
    15821582        } else {
    1583             realWidth = Math.round(GuiSizesHelper.getSizeDpiAdjusted(sourceWidth));
    1584             realHeight = Math.round(GuiSizesHelper.getSizeDpiAdjusted(sourceHeight));
    1585         }
    1586         final Double scaleX = (double) realWidth / sourceWidth;
    1587         final Double scaleY = (double) realHeight / sourceHeight;
     1583            realWidth = GuiSizesHelper.getSizeDpiAdjusted(sourceWidth);
     1584            realHeight = GuiSizesHelper.getSizeDpiAdjusted(sourceHeight);
     1585        }
    15881586
    15891587        if (realWidth == 0 || realHeight == 0) {
    15901588            return null;
    15911589        }
    1592         BufferedImage img = new BufferedImage(realWidth, realHeight, BufferedImage.TYPE_INT_ARGB);
     1590        BufferedImage img = new BufferedImage(Math.round(realWidth), Math.round(realHeight), BufferedImage.TYPE_INT_ARGB);
    15931591        Graphics2D g = img.createGraphics();
    1594         g.setClip(0, 0, realWidth, realHeight);
    1595         g.scale(scaleX, scaleY);
     1592        g.setClip(0, 0, img.getWidth(), img.getHeight());
     1593        g.scale(realWidth / sourceWidth, realHeight / sourceHeight);
    15961594        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    15971595        try {
Note: See TracChangeset for help on using the changeset viewer.