Changeset 5403 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2012-08-07T18:33:42+02:00 (12 years ago)
Author:
bastiK
Message:

fixed #7841 - Flying street name labels

File:
1 edited

Legend:

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

    r5375 r5403  
    402402    }
    403403
     404    private static Boolean IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG = null;
     405
     406    /**
     407     * Check, if this System has the GlyphVector double translation bug.
     408     *
     409     * With this bug, <code>gv.setGlyphTransform(i, trfm)</code> has a different
     410     * effect than on most other systems, namely the translation components
     411     * ("m02" & "m12", {@link AffineTransform}) appear to be twice as large, as
     412     * they actually are. The rotation is unaffected (scale & shear not tested
     413     * so far).
     414     *
     415     * This bug has only been observed on Mac OS X, see #7841.
     416     *
     417     * @return true, if the GlyphVector double translation bug is present on
     418     * this System
     419     */
     420    public static boolean isGlyphVectorDoubleTranslationBug() {
     421        if (IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG != null)
     422            return IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG;
     423        FontRenderContext frc = new FontRenderContext(null, false, false);
     424        Font font = new Font("Dialog", Font.PLAIN, 12);
     425        GlyphVector gv = font.createGlyphVector(frc, "x");
     426        gv.setGlyphTransform(0, AffineTransform.getTranslateInstance(1000, 1000));
     427        Shape shape = gv.getGlyphOutline(0);
     428        // x is about 1000 on normal stystems and about 2000 when the bug occurs
     429        int x = shape.getBounds().x;
     430        IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG = x > 1500;
     431        return IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG;
     432    }
     433
    404434    public void drawTextOnPath(Way way, TextElement text) {
    405435        if (way == null || text == null)
     
    470500                double off = -rect.getY() - rect.getHeight()/2 + text.yOffset;
    471501                trfm.translate(-rect.getWidth()/2, off);
     502                if (isGlyphVectorDoubleTranslationBug()) {
     503                    // scale the translation components by one half
     504                    AffineTransform tmp = AffineTransform.getTranslateInstance(-0.5 * trfm.getTranslateX(), -0.5 * trfm.getTranslateY());
     505                    tmp.concatenate(trfm);
     506                    trfm = tmp;
     507                }
    472508                gv.setGlyphTransform(i, trfm);
    473509            }
Note: See TracChangeset for help on using the changeset viewer.