Ticket #9995: hidpi-mapview.patch

File hidpi-mapview.patch, 6.0 KB (added by bastiK, 7 weeks ago)
  • src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

     
    11491149        }
    11501150        displayText(() -> {
    11511151            AffineTransform defaultTransform = g.getTransform();
    1152             g.setTransform(at);
     1152            g.transform(at);
    11531153            g.setFont(text.font);
    11541154            g.drawString(name, 0, 0);
    11551155            g.setTransform(defaultTransform);
  • src/org/openstreetmap/josm/gui/MapView.java

     
    88import java.awt.Graphics2D;
    99import java.awt.Point;
    1010import java.awt.Rectangle;
     11import java.awt.Shape;
    1112import java.awt.event.ComponentAdapter;
    1213import java.awt.event.ComponentEvent;
    1314import java.awt.event.KeyEvent;
     
    1415import java.awt.event.MouseAdapter;
    1516import java.awt.event.MouseEvent;
    1617import java.awt.event.MouseMotionListener;
     18import java.awt.geom.AffineTransform;
    1719import java.awt.geom.Area;
    1820import java.awt.image.BufferedImage;
    1921import java.beans.PropertyChangeEvent;
     
    487489    }
    488490
    489491    private void drawMapContent(Graphics g) {
     492        Graphics2D gg = (Graphics2D) g;
     493        AffineTransform trOrig = gg.getTransform();
     494        double uiScaleX = gg.getTransform().getScaleX();
     495        double uiScaleY = gg.getTransform().getScaleY();
     496        int width = (int) Math.round(getWidth() * uiScaleX);
     497        int height = (int) Math.round(getHeight() * uiScaleY);
     498
     499        AffineTransform trDef = AffineTransform.getScaleInstance(uiScaleX, uiScaleY);
     500        Shape scaledClip = trDef.createTransformedShape(g.getClip());
     501       
    490502        List<Layer> visibleLayers = layerManager.getVisibleLayersInZOrder();
    491503
    492504        int nonChangedLayersCount = 0;
     
    505517                && lastClipBounds.contains(g.getClipBounds())
    506518                && nonChangedLayers.equals(visibleLayers.subList(0, nonChangedLayers.size()));
    507519
    508         if (null == offscreenBuffer || offscreenBuffer.getWidth() != getWidth() || offscreenBuffer.getHeight() != getHeight()) {
    509             offscreenBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_3BYTE_BGR);
     520        if (null == offscreenBuffer || offscreenBuffer.getWidth() != width || offscreenBuffer.getHeight() != height) {
     521            offscreenBuffer = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
    510522        }
    511523
    512         Graphics2D tempG = offscreenBuffer.createGraphics();
    513         tempG.setClip(g.getClip());
    514 
    515524        if (!canUseBuffer || nonChangedLayersBuffer == null) {
    516525            if (null == nonChangedLayersBuffer
    517                     || nonChangedLayersBuffer.getWidth() != getWidth() || nonChangedLayersBuffer.getHeight() != getHeight()) {
    518                 nonChangedLayersBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_3BYTE_BGR);
     526                    || nonChangedLayersBuffer.getWidth() != width || nonChangedLayersBuffer.getHeight() != height) {
     527                nonChangedLayersBuffer = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
    519528            }
    520529            Graphics2D g2 = nonChangedLayersBuffer.createGraphics();
    521             g2.setClip(g.getClip());
     530            g2.setClip(scaledClip);
     531            g2.setTransform(trDef);
    522532            g2.setColor(PaintColors.getBackgroundColor());
    523             g2.fillRect(0, 0, getWidth(), getHeight());
     533            g2.fillRect(0, 0, width, height);
    524534
    525535            for (int i = 0; i < nonChangedLayersCount; i++) {
    526536                paintLayer(visibleLayers.get(i), g2);
     
    529539            // Maybe there were more unchanged layers then last time - draw them to buffer
    530540            if (nonChangedLayers.size() != nonChangedLayersCount) {
    531541                Graphics2D g2 = nonChangedLayersBuffer.createGraphics();
    532                 g2.setClip(g.getClip());
     542                g2.setClip(scaledClip);
     543                g2.setTransform(trDef);
    533544                for (int i = nonChangedLayers.size(); i < nonChangedLayersCount; i++) {
    534545                    paintLayer(visibleLayers.get(i), g2);
    535546                }
     
    541552        lastViewID = getViewID();
    542553        lastClipBounds = g.getClipBounds();
    543554
     555        Graphics2D tempG = offscreenBuffer.createGraphics();
     556        tempG.setClip(scaledClip);
     557        tempG.setTransform(new AffineTransform());
    544558        tempG.drawImage(nonChangedLayersBuffer, 0, 0, null);
    545 
     559        tempG.setTransform(trDef);
     560       
    546561        for (int i = nonChangedLayersCount; i < visibleLayers.size(); i++) {
    547562            paintLayer(visibleLayers.get(i), tempG);
    548563        }
    549564
    550565        try {
    551             drawTemporaryLayers(tempG, getLatLonBounds(g.getClipBounds()));
     566            drawTemporaryLayers(tempG, getLatLonBounds(new Rectangle(
     567                    (int) Math.round(g.getClipBounds().x * uiScaleX),
     568                    (int) Math.round(g.getClipBounds().y * uiScaleY))));
    552569        } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) {
    553570            BugReport.intercept(e).put("temporaryLayers", temporaryLayers).warn();
    554571        }
     
    573590        }
    574591
    575592        try {
    576             g.drawImage(offscreenBuffer, 0, 0, null);
     593            gg.setTransform(new AffineTransform(1, 0, 0, 1, trOrig.getTranslateX(), trOrig.getTranslateY()));
     594            gg.drawImage(offscreenBuffer, 0, 0, null);
    577595        } catch (ClassCastException e) {
    578596            // See #11002 and duplicate tickets. On Linux with Java >= 8 Many users face this error here:
    579597            //
     
    599617            //
    600618            // But the application seems to work fine after, so let's just log the error
    601619            Logging.error(e);
     620        } finally {
     621            gg.setTransform(trOrig);
    602622        }
    603623    }
    604624