Changeset 3979 in josm for trunk/src/org


Ignore:
Timestamp:
2011-03-12T10:27:24+01:00 (13 years ago)
Author:
bastiK
Message:

mapcss: add text-halo-radius

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

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

    r3968 r3979  
    1212import java.awt.Polygon;
    1313import java.awt.Rectangle;
     14import java.awt.Shape;
    1415import java.awt.TexturePaint;
    1516import java.awt.font.FontRenderContext;
     
    315316            gv.setGlyphTransform(i, trfm);
    316317        }
    317         g.setColor(text.color);
    318         g.drawGlyphVector(gv, 0, 0);
    319 
     318        if (text.haloRadius != null) {
     319            Shape textOutline = gv.getOutline();
     320            g.setStroke(new BasicStroke(2*text.haloRadius, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
     321            g.setColor(text.haloColor);
     322            g.draw(textOutline);
     323            g.setStroke(new BasicStroke());
     324            g.setColor(text.color);
     325            g.fill(textOutline);
     326        } else {
     327            g.setColor(text.color);
     328            g.drawGlyphVector(gv, 0, 0);
     329        }
    320330    }
    321331
     
    489499            return;
    490500
    491         if (inactive || n.isDisabled()) {
    492             g.setColor(inactiveColor);
    493         } else {
    494             g.setColor(text.color);
    495         }
    496501        Font defaultFont = g.getFont();
    497502        g.setFont(text.font);
     
    538543            } else throw new AssertionError();
    539544        }
    540         g.drawString(s, x, y);
     545        if (inactive || n.isDisabled()) {
     546            g.setColor(inactiveColor);
     547        } else {
     548            g.setColor(text.color);
     549        }
     550        if (text.haloRadius != null) {
     551            g.setStroke(new BasicStroke(2*text.haloRadius, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
     552            g.setColor(text.haloColor);
     553            FontRenderContext frc = g.getFontRenderContext();
     554            GlyphVector gv = text.font.createGlyphVector(frc, s);
     555            Shape textOutline = gv.getOutline(x, y);
     556            g.draw(textOutline);
     557            g.setStroke(new BasicStroke());
     558            g.setColor(text.color);
     559            g.fill(textOutline);
     560        } else {
     561            g.drawString(s, x, y);
     562        }
    541563        g.setFont(defaultFont);
    542564    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r3969 r3979  
    66import java.awt.BasicStroke;
    77import java.awt.Color;
    8 import java.awt.Font;
    98import java.awt.Stroke;
    109
     
    9392        public VerticalTextAlignment vAlign;
    9493
    95         public NodeTextElement(String textKey, HorizontalTextAlignment hAlign, VerticalTextAlignment vAlign, Font font, int xOffset, int yOffset, Color color) {
    96             super(textKey, font, xOffset, yOffset, color);
     94        public NodeTextElement(TextElement text, HorizontalTextAlignment hAlign, VerticalTextAlignment vAlign) {
     95            super(text);
    9796            CheckParameterUtil.ensureParameterNotNull(hAlign);
    9897            CheckParameterUtil.ensureParameterNotNull(vAlign);
     
    192191                vAlign = VerticalTextAlignment.BELOW;
    193192            }
    194             text = new NodeTextElement(te.textKey, hAlign, vAlign, te.font, te.xOffset, te.yOffset, te.color);
     193            text = new NodeTextElement(te, hAlign, vAlign);
    195194        }
    196195       
  • trunk/src/org/openstreetmap/josm/gui/mappaint/TextElement.java

    r3967 r3979  
    1010
    1111import org.openstreetmap.josm.tools.CheckParameterUtil;
     12import org.openstreetmap.josm.tools.Utils;
    1213
    1314public class TextElement {
     
    1920    public int yOffset;
    2021    public Color color;
     22    public Float haloRadius;
     23    public Color haloColor;
    2124
    22     public TextElement(String textKey, Font font, int xOffset, int yOffset, Color color) {
     25    public TextElement(String textKey, Font font, int xOffset, int yOffset, Color color, Float haloRadius, Color haloColor) {
    2326        CheckParameterUtil.ensureParameterNotNull(font);
    2427        CheckParameterUtil.ensureParameterNotNull(color);
     
    2831        this.yOffset = yOffset;
    2932        this.color = color;
     33        this.haloRadius = haloRadius;
     34        this.haloColor = haloColor;
     35    }
     36
     37    public TextElement(TextElement other) {
     38        this.textKey = other.textKey;
     39        this.font = other.font;
     40        this.xOffset = other.xOffset;
     41        this.yOffset = other.yOffset;
     42        this.color = other.color;
     43        this.haloColor = other.haloColor;
     44        this.haloRadius = other.haloRadius;
    3045    }
    3146
     
    5873       
    5974        Color color = c.get("text-color", defTextColor, Color.class);
    60        
    61         return new TextElement(textKey, font, (int) xOffset, - (int) yOffset, color);
     75        float alpha = c.get("text-opacity", 1f, Float.class);
     76        color = new Color(color.getRed(), color.getGreen(),
     77                color.getBlue(), Utils.color_float2int(alpha));
     78
     79        Float haloRadius = c.get("text-halo-radius", null, Float.class);
     80        if (haloRadius != null && haloRadius <= 0) {
     81            haloRadius = null;
     82        }
     83        Color haloColor = null;
     84        if (haloRadius != null) {
     85            haloColor = c.get("text-halo-color", Utils.complement(color), Color.class);
     86            float haloAlpha = c.get("text-halo-opacity", 1f, Float.class);
     87            haloColor = new Color(haloColor.getRed(), haloColor.getGreen(),
     88                    haloColor.getBlue(), Utils.color_float2int(haloAlpha));
     89        }
     90
     91        return new TextElement(textKey, font, (int) xOffset, - (int) yOffset, color, haloRadius, haloColor);
    6292    }
    6393
     
    71101                xOffset == other.xOffset &&
    72102                yOffset == other.yOffset &&
    73                 equal(color, other.color);
     103                equal(color, other.color) &&
     104                equal(haloRadius, other.haloRadius) &&
     105                equal(haloColor, other.haloColor);
    74106    }
    75107
     
    82114        hash = 79 * hash + yOffset;
    83115        hash = 79 * hash + color.hashCode();
     116        hash = 79 * hash + (haloRadius != null ? Float.floatToIntBits(haloRadius) : 0);
     117        hash = 79 * hash + (haloColor != null ? haloColor.hashCode() : 0);
    84118        return hash;
    85119    }
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r3879 r3979  
    160160    }
    161161
     162    public static Color complement(Color clr) {
     163        return new Color(255 - clr.getRed(), 255 - clr.getGreen(), 255 - clr.getBlue(), clr.getAlpha());
     164    }
    162165}
Note: See TracChangeset for help on using the changeset viewer.