Changeset 7752 in josm for trunk


Ignore:
Timestamp:
2014-11-27T17:45:21+01:00 (6 years ago)
Author:
bastiK
Message:

fixed #7841 - Flying street name labels on Mac
(Behaviour is different for each font, so check each font.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r7621 r7752  
    2828import java.util.Collection;
    2929import java.util.Collections;
     30import java.util.HashMap;
    3031import java.util.Iterator;
    3132import java.util.List;
     33import java.util.Map;
    3234import java.util.concurrent.Callable;
    3335import java.util.concurrent.ExecutionException;
     
    235237    }
    236238
    237     private static Boolean IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG = null;
     239    private static Map<Font,Boolean> IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG = new HashMap<>();
    238240
    239241    /**
     
    259261     * method which apparently no longer gives a useful result for Java 7.
    260262     */
    261     public static boolean isGlyphVectorDoubleTranslationBug() {
    262         if (IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG != null)
    263             return IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG;
    264         String overridePref = Main.pref.get("glyph-bug", "false");
     263    public static boolean isGlyphVectorDoubleTranslationBug(Font font) {
     264        Boolean cached  = IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG.get(font);
     265        if (cached != null)
     266            return cached;
     267        String overridePref = Main.pref.get("glyph-bug", "auto");
    265268        if ("auto".equals(overridePref)) {
    266269            FontRenderContext frc = new FontRenderContext(null, false, false);
    267             Font font = new Font("Dialog", Font.PLAIN, 12);
    268270            GlyphVector gv = font.createGlyphVector(frc, "x");
    269271            gv.setGlyphTransform(0, AffineTransform.getTranslateInstance(1000, 1000));
     
    272274            // x is about 1000 on normal stystems and about 2000 when the bug occurs
    273275            int x = shape.getBounds().x;
    274             IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG = x > 1500;
    275             return IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG;
     276            boolean isBug = x > 1500;
     277            IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG.put(font, isBug);
     278            return isBug;
    276279        } else {
    277280            boolean override = Boolean.parseBoolean(overridePref);
    278             IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG = override;
    279             return IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG;
     281            IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG.put(font, override);
     282            return override;
    280283        }
    281284    }
     
    12061209                double off = -rect.getY() - rect.getHeight()/2 + text.yOffset;
    12071210                trfm.translate(-rect.getWidth()/2, off);
    1208                 if (isGlyphVectorDoubleTranslationBug()) {
     1211                if (isGlyphVectorDoubleTranslationBug(text.font)) {
    12091212                    // scale the translation components by one half
    12101213                    AffineTransform tmp = AffineTransform.getTranslateInstance(-0.5 * trfm.getTranslateX(), -0.5 * trfm.getTranslateY());
Note: See TracChangeset for help on using the changeset viewer.