Changeset 5374 in josm


Ignore:
Timestamp:
2012-07-28T15:19:01+02:00 (9 years ago)
Author:
Don-vip
Message:

fix #7907 - NPE when rendering way name at low zoom

File:
1 edited

Legend:

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

    r5348 r5374  
    403403
    404404    public void drawTextOnPath(Way way, TextElement text) {
    405         if (text == null)
     405        if (way == null || text == null)
    406406            return;
    407407        String name = text.getString(way);
    408         if (name == null || name.equals(""))
     408        if (name == null || name.isEmpty())
    409409            return;
    410410
     
    438438        double[] p1 = pointAt(t1, poly, pathLength);
    439439        double[] p2 = pointAt(t2, poly, pathLength);
     440       
     441        if (p1 == null || p2 == null)
     442                return;
    440443
    441444        double angleOffset;
     
    462465            double t = tStart + offsetSign * (rect.getX() + rect.getWidth()/2) / pathLength;
    463466            double[] p = pointAt(t, poly, pathLength);
    464             AffineTransform trfm = AffineTransform.getTranslateInstance(p[0] - rect.getX(), p[1]);
    465             trfm.rotate(p[2]+angleOffset);
    466             double off = -rect.getY() - rect.getHeight()/2 + text.yOffset;
    467             trfm.translate(-rect.getWidth()/2, off);
    468             gv.setGlyphTransform(i, trfm);
     467            if (p != null) {
     468                    AffineTransform trfm = AffineTransform.getTranslateInstance(p[0] - rect.getX(), p[1]);
     469                    trfm.rotate(p[2]+angleOffset);
     470                    double off = -rect.getY() - rect.getHeight()/2 + text.yOffset;
     471                    trfm.translate(-rect.getWidth()/2, off);
     472                    gv.setGlyphTransform(i, trfm);
     473            }
    469474        }
    470475        if (text.haloRadius != null) {
     
    488493        double segLen;
    489494
    490         // Yes, it is ineffecient to iterate from the beginning for each glyph.
     495        // Yes, it is inefficient to iterate from the beginning for each glyph.
    491496        // Can be optimized if it turns out to be slow.
    492497        for (int i = 1; i < poly.npoints; ++i) {
     
    498503                continue;
    499504            }
    500             return new double[] {poly.xpoints[i-1]+(totalLen - curLen)/segLen*dx,
     505            return new double[] {
     506                        poly.xpoints[i-1]+(totalLen - curLen)/segLen*dx,
    501507                    poly.ypoints[i-1]+(totalLen - curLen)/segLen*dy,
    502508                    Math.atan2(dy, dx)};
Note: See TracChangeset for help on using the changeset viewer.