Ticket #8934: 8934-4a-String2GlyphVector.patch

File 8934-4a-String2GlyphVector.patch, 3.7 KB (added by AlfonZ, 11 years ago)

Patch to be applied after patch#3.
Replace multiple selections between String and GlyphVector by converting String to GlyphVector beforehand.

  • src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

     
    444444    /**
    445445     * Displays text at specified position including its halo, if applicable.
    446446     *
    447      * @param gv Text's glyphs to display. If {@code null}, use text from {@code s} instead.
    448      * @param s text to display if {@code gv} is {@code null}
     447     * @param s text to display
    449448     * @param x X position
    450449     * @param y Y position
    451450     * @param disabled {@code true} if element is disabled (filtered out)
    452451     * @param text text style to use
    453452     */
    454     private void displayText(GlyphVector gv, String s, int x, int y, boolean disabled, TextElement text) {
     453    private void displayText(String s, int x, int y, boolean disabled, TextElement text) {
     454        FontRenderContext frc = g.getFontRenderContext();
     455        GlyphVector gv = text.font.createGlyphVector(frc, s);
     456        displayText(gv, x, y, disabled, text);
     457    }
     458   
     459    /**
     460     * Displays text at specified position including its halo, if applicable.
     461     *
     462     * @param gv text's glyphs to display
     463     * @param x X position
     464     * @param y Y position
     465     * @param disabled {@code true} if element is disabled (filtered out)
     466     * @param text text style to use
     467     */
     468    private void displayText(GlyphVector gv, int x, int y, boolean disabled, TextElement text) {
    455469        if (isInactiveMode || disabled) {
    456470            g.setColor(inactiveColor);
    457             if (gv != null) {
    458                 g.drawGlyphVector(gv, x, y);
    459             } else {
    460                 g.setFont(text.font);
    461                 g.drawString(s, x, y);
    462             }
     471            g.drawGlyphVector(gv, x, y);
    463472        } else if (text.haloRadius != null) {
    464473            g.setStroke(new BasicStroke(2*text.haloRadius, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    465474            g.setColor(text.haloColor);
    466             if (gv == null) {
    467                 FontRenderContext frc = g.getFontRenderContext();
    468                 gv = text.font.createGlyphVector(frc, s);
    469             }
    470475            Shape textOutline = gv.getOutline(x, y);
    471476            g.draw(textOutline);
    472477            g.setStroke(new BasicStroke());
     
    474479            g.fill(textOutline);
    475480        } else {
    476481            g.setColor(text.color);
    477             if (gv != null) {
    478                 g.drawGlyphVector(gv, x, y);
    479             } else {
    480                 g.setFont(text.font);
    481                 g.drawString(s, x, y);
    482             }
     482            g.drawGlyphVector(gv, x, y);
    483483        }
    484484    }
    485485   
     
    544544                Font defaultFont = g.getFont();
    545545                int x = (int)(centeredNBounds.getMinX() - nb.getMinX());
    546546                int y = (int)(centeredNBounds.getMinY() - nb.getMinY());
    547                 displayText(null, name, x, y, osm.isDisabled(), text);
     547                displayText(name, x, y, osm.isDisabled(), text);
    548548                g.setFont(defaultFont);
    549549            }
    550550        }
     
    623623                y += box.y + box.height + metrics.getAscent() + 2;
    624624            } else throw new AssertionError();
    625625        }
    626         displayText(null, s, x, y, n.isDisabled(), text);
     626        displayText(s, x, y, n.isDisabled(), text);
    627627        g.setFont(defaultFont);
    628628    }
    629629
     
    11691169                gv.setGlyphTransform(i, trfm);
    11701170            }
    11711171        }
    1172         displayText(gv, null, 0, 0, way.isDisabled(), text);
     1172        displayText(gv, 0, 0, way.isDisabled(), text);
    11731173    }
    11741174
    11751175    /**