Ticket #8934: 8934-4b-HaloedTextsRefactored2.patch

File 8934-4b-HaloedTextsRefactored2.patch, 4.7 KB (added by AlfonZ, 13 years ago)

Combined patch#2, patch#3 and patch#4.
Moved halo drawing from drawArea, drawBoxText and drawTextOnPath to displayTexts.
Doing that, areas now have haloed texts, disabled nodes' haloed texts use inactiveColor and disabled ways' texts use inactiveColor.
Avoid multiple selections between String and GlyphVector by converting String to GlyphVector beforehand (used by nodes and areas).

  • 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 s text to display
     448     * @param x X position
     449     * @param y Y position
     450     * @param disabled {@code true} if element is disabled (filtered out)
     451     * @param text text style to use
     452     */
     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) {
     469        if (isInactiveMode || disabled) {
     470            g.setColor(inactiveColor);
     471            g.drawGlyphVector(gv, x, y);
     472        } else if (text.haloRadius != null) {
     473            g.setStroke(new BasicStroke(2*text.haloRadius, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
     474            g.setColor(text.haloColor);
     475            Shape textOutline = gv.getOutline(x, y);
     476            g.draw(textOutline);
     477            g.setStroke(new BasicStroke());
     478            g.setColor(text.color);
     479            g.fill(textOutline);
     480        } else {
     481            g.setColor(text.color);
     482            g.drawGlyphVector(gv, x, y);
     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());
     
    499541            if ((pb.width >= nb.getWidth() && pb.height >= nb.getHeight()) && // quick check
    500542                    area.contains(centeredNBounds) // slow but nice
    501543            ) {
    502                 if (isInactiveMode || osm.isDisabled()) {
    503                     g.setColor(inactiveColor);
    504                 } else {
    505                     g.setColor(text.color);
    506                 }
    507544                Font defaultFont = g.getFont();
    508                 g.setFont (text.font);
    509                 g.drawString (name,
    510                         (int)(centeredNBounds.getMinX() - nb.getMinX()),
    511                         (int)(centeredNBounds.getMinY() - nb.getMinY()));
     545                int x = (int)(centeredNBounds.getMinX() - nb.getMinX());
     546                int y = (int)(centeredNBounds.getMinY() - nb.getMinY());
     547                displayText(name, x, y, osm.isDisabled(), text);
    512548                g.setFont(defaultFont);
    513549            }
    514550        }
     
    587623                y += box.y + box.height + metrics.getAscent() + 2;
    588624            } else throw new AssertionError();
    589625        }
    590         if (isInactiveMode || n.isDisabled()) {
    591             g.setColor(inactiveColor);
    592         } else {
    593             g.setColor(text.color);
    594         }
    595         if (text.haloRadius != null) {
    596             g.setStroke(new BasicStroke(2*text.haloRadius, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    597             g.setColor(text.haloColor);
    598             FontRenderContext frc = g.getFontRenderContext();
    599             GlyphVector gv = text.font.createGlyphVector(frc, s);
    600             Shape textOutline = gv.getOutline(x, y);
    601             g.draw(textOutline);
    602             g.setStroke(new BasicStroke());
    603             g.setColor(text.color);
    604             g.fill(textOutline);
    605         } else {
    606             g.drawString(s, x, y);
    607         }
     626        displayText(s, x, y, n.isDisabled(), text);
    608627        g.setFont(defaultFont);
    609628    }
    610629
     
    11501169                gv.setGlyphTransform(i, trfm);
    11511170            }
    11521171        }
    1153         if (text.haloRadius != null) {
    1154             Shape textOutline = gv.getOutline();
    1155             g.setStroke(new BasicStroke(2*text.haloRadius, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    1156             g.setColor(text.haloColor);
    1157             g.draw(textOutline);
    1158             g.setStroke(new BasicStroke());
    1159             g.setColor(text.color);
    1160             g.fill(textOutline);
    1161         } else {
    1162             g.setColor(text.color);
    1163             g.drawGlyphVector(gv, 0, 0);
    1164         }
     1172        displayText(gv, 0, 0, way.isDisabled(), text);
    11651173    }
    11661174
    11671175    /**