Ticket #8934: 8934-3a-DisplayTextRefactor.patch

File 8934-3a-DisplayTextRefactor.patch, 5.3 KB (added by AlfonZ, 13 years ago)

Patch to be applied after patch#2.
Moved halo drawing from drawArea, drawBoxText and drawTextOnPath to displayText.

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

     
    441441        }
    442442    }
    443443
     444    /**
     445     * Displays text at specified position including its halo, if applicable.
     446     *
     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}
     449     * @param x X position
     450     * @param y Y position
     451     * @param disabled {@code true} if element is disabled (filtered out)
     452     * @param text text style to use
     453     */
     454    private void displayText(GlyphVector gv, String s, int x, int y, boolean disabled, TextElement text) {
     455        if (isInactiveMode || disabled) {
     456            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            }
     463        } else if (text.haloRadius != null) {
     464            g.setStroke(new BasicStroke(2*text.haloRadius, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
     465            g.setColor(text.haloColor);
     466            if (gv == null) {
     467                FontRenderContext frc = g.getFontRenderContext();
     468                gv = text.font.createGlyphVector(frc, s);
     469            }
     470            Shape textOutline = gv.getOutline(x, y);
     471            g.draw(textOutline);
     472            g.setStroke(new BasicStroke());
     473            g.setColor(text.color);
     474            g.fill(textOutline);
     475        } else {
     476            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            }
     483        }
     484    }
     485   
    444486    protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage fillImage, TextElement text) {
    445487
    446488        Shape area = path.createTransformedShape(nc.getAffineTransform());
     
    502544                Font defaultFont = g.getFont();
    503545                int x = (int)(centeredNBounds.getMinX() - nb.getMinX());
    504546                int y = (int)(centeredNBounds.getMinY() - nb.getMinY());
    505                 if (isInactiveMode || osm.isDisabled()) {
    506                     g.setColor(inactiveColor);
    507                     g.setFont (text.font);
    508                     g.drawString(name, x, y);
    509                 } else if (text.haloRadius != null) {
    510                     g.setStroke(new BasicStroke(2*text.haloRadius, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    511                     g.setColor(text.haloColor);
    512                     FontRenderContext frc = g.getFontRenderContext();
    513                     GlyphVector gv = text.font.createGlyphVector(frc, name);
    514                     Shape textOutline = gv.getOutline(x, y);
    515                     g.draw(textOutline);
    516                     g.setStroke(new BasicStroke());
    517                     g.setColor(text.color);
    518                     g.fill(textOutline);
    519                 } else {
    520                     g.setColor(text.color);
    521                     g.setFont (text.font);
    522                     g.drawString(name, x, y);
    523                 }
     547                displayText(null, name, x, y, osm.isDisabled(), text);
    524548                g.setFont(defaultFont);
    525549            }
    526550        }
     
    599623                y += box.y + box.height + metrics.getAscent() + 2;
    600624            } else throw new AssertionError();
    601625        }
    602         if (isInactiveMode || n.isDisabled()) {
    603             g.setColor(inactiveColor);
    604             g.drawString(s, x, y);
    605         } else if (text.haloRadius != null) {
    606             g.setStroke(new BasicStroke(2*text.haloRadius, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    607             g.setColor(text.haloColor);
    608             FontRenderContext frc = g.getFontRenderContext();
    609             GlyphVector gv = text.font.createGlyphVector(frc, s);
    610             Shape textOutline = gv.getOutline(x, y);
    611             g.draw(textOutline);
    612             g.setStroke(new BasicStroke());
    613             g.setColor(text.color);
    614             g.fill(textOutline);
    615         } else {
    616             g.setColor(text.color);
    617             g.drawString(s, x, y);
    618         }
     626        displayText(null, s, x, y, n.isDisabled(), text);
    619627        g.setFont(defaultFont);
    620628    }
    621629
     
    11611169                gv.setGlyphTransform(i, trfm);
    11621170            }
    11631171        }
    1164         if (isInactiveMode || way.isDisabled()) {
    1165             g.setColor(inactiveColor);
    1166             g.drawGlyphVector(gv, 0, 0);
    1167         } else if (text.haloRadius != null) {
    1168             Shape textOutline = gv.getOutline();
    1169             g.setStroke(new BasicStroke(2*text.haloRadius, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    1170             g.setColor(text.haloColor);
    1171             g.draw(textOutline);
    1172             g.setStroke(new BasicStroke());
    1173             g.setColor(text.color);
    1174             g.fill(textOutline);
    1175         } else {
    1176             g.setColor(text.color);
    1177             g.drawGlyphVector(gv, 0, 0);
    1178         }
     1172        displayText(gv, null, 0, 0, way.isDisabled(), text);
    11791173    }
    11801174
    11811175    /**