Changeset 7383 in josm


Ignore:
Timestamp:
2014-08-13T16:42:17+02:00 (10 years ago)
Author:
bastiK
Message:

applied #10301 - extend display of maxspeed nodes (patch by Klumbumbus)
Include Droid Sans font in the JOSM binary distribution.
This unifies the font rendering on different platforms and allows geometric constructions with text (as demonstrated for maxspeed). Both regular and bold style are available.

Location:
trunk
Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r7343 r7383  
    6060import org.openstreetmap.josm.plugins.PluginInformation;
    6161import org.openstreetmap.josm.tools.BugReportExceptionHandler;
     62import org.openstreetmap.josm.tools.FontsManager;
    6263import org.openstreetmap.josm.tools.I18n;
    6364import org.openstreetmap.josm.tools.ImageProvider;
     
    346347        Main.pref.updateSystemProperties();
    347348
     349        FontsManager.initialize();
     350       
    348351        final JFrame mainFrame = new JFrame(tr("Java OpenStreetMap Editor"));
    349352        Main.parent = mainFrame;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java

    r7136 r7383  
    3434    }
    3535
    36     public static AreaElemStyle create(Cascade c) {
     36    public static AreaElemStyle create(final Environment env) {
     37        final Cascade c = env.mc.getCascade(env.layer);
    3738        MapImage fillImage = null;
    3839        Color color = null;
     
    7576        Keyword textPos = c.get(TEXT_POSITION, null, Keyword.class);
    7677        if (textPos == null || "center".equals(textPos.val)) {
    77             text = TextElement.create(c, PaintColors.AREA_TEXT.get(), true);
     78            text = TextElement.create(env, PaintColors.AREA_TEXT.get(), true);
    7879        }
    7980
  • trunk/src/org/openstreetmap/josm/gui/mappaint/BoxTextElemStyle.java

    r7083 r7383  
    111111        Cascade c = env.mc.getCascade(env.layer);
    112112
    113         TextElement text = TextElement.create(c, DEFAULT_TEXT_COLOR, false);
     113        TextElement text = TextElement.create(env, DEFAULT_TEXT_COLOR, false);
    114114        if (text == null) return null;
    115115        // Skip any primitives that don't have text to draw. (Styles are recreated for any tag change.)
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java

    r7083 r7383  
    112112                n = DEFAULT_FONT_NAME;
    113113                if (n == null) {
    114                     DEFAULT_FONT_NAME = n = Main.pref.get("mappaint.font", "Helvetica");
     114                    DEFAULT_FONT_NAME = n = Main.pref.get("mappaint.font", "Droid Sans");
    115115                }
    116116            }
     
    174174    }
    175175
    176     protected static Font getFont(Cascade c) {
     176    protected static Font getFont(Cascade c, String s) {
    177177        String name = c.get("font-family", getDefaultFontName(), String.class);
    178178        float size = c.get("font-size", getDefaultFontSize(), Float.class);
     
    185185            style = Font.ITALIC;
    186186        }
    187         return getCachedFont(name, style | weight, Math.round(size));
     187        Font f = getCachedFont(name, style | weight, Math.round(size));
     188        if (f.canDisplayUpTo(s) == -1)
     189            return f;
     190        else {
     191            // fallback if the string contains characters that cannot be
     192            // rendered by the selected font
     193            return getCachedFont("SansSerif", style | weight, Math.round(size));
     194        }
    188195    }
    189196
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r7191 r7383  
    337337            Cascade c = e.getValue();
    338338            if (osm instanceof Way) {
    339                 addIfNotNull(sl, AreaElemStyle.create(c));
     339                addIfNotNull(sl, AreaElemStyle.create(env));
    340340                addIfNotNull(sl, RepeatImageElemStyle.create(env));
    341341                addIfNotNull(sl, LineElemStyle.createLine(env));
     
    354354            } else if (osm instanceof Relation) {
    355355                if (((Relation)osm).isMultipolygon()) {
    356                     addIfNotNull(sl, AreaElemStyle.create(c));
     356                    addIfNotNull(sl, AreaElemStyle.create(env));
    357357                    addIfNotNull(sl, RepeatImageElemStyle.create(env));
    358358                    addIfNotNull(sl, LineElemStyle.createLine(env));
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineTextElemStyle.java

    r7083 r7383  
    1818        this.text = text;
    1919    }
    20     public static LineTextElemStyle create(Environment env) {
    21         Cascade c = env.mc.getCascade(env.layer);
     20    public static LineTextElemStyle create(final Environment env) {
     21        final Cascade c = env.mc.getCascade(env.layer);
    2222
    2323        Keyword textPos = c.get(TEXT_POSITION, null, Keyword.class);
     
    2525            return null;
    2626
    27         TextElement text = TextElement.create(c, PaintColors.TEXT.get(), false);
     27        TextElement text = TextElement.create(env, PaintColors.TEXT.get(), false);
    2828        if (text == null)
    2929            return null;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/TextElement.java

    r7083 r7383  
    116116     * @throws IllegalArgumentException thrown if {@code defaultTextColor} is null
    117117     */
    118     public static TextElement create(Cascade c, Color defaultTextColor, boolean defaultAnnotate)  throws IllegalArgumentException{
     118    public static TextElement create(Environment env, Color defaultTextColor, boolean defaultAnnotate)  throws IllegalArgumentException{
    119119        CheckParameterUtil.ensureParameterNotNull(defaultTextColor);
     120        Cascade c = env.mc.getCascade(env.layer);
    120121
    121122        LabelCompositionStrategy strategy = buildLabelCompositionStrategy(c, defaultAnnotate);
    122123        if (strategy == null) return null;
    123         Font font = ElemStyle.getFont(c);
     124        String s = strategy.compose(env.osm);
     125        if (s == null) return null;
     126        Font font = ElemStyle.getFont(c, s);
    124127
    125128        float xOffset = 0;
  • trunk/styles/standard/elemstyles.mapcss

    r7378 r7383  
    272272node[maxlength] {
    273273    icon-image: "vehicle/restriction/maxlength.png";
    274 }
    275 node[maxspeed] {
    276     icon-image: "vehicle/restriction/speed.png";
    277274}
    278275node[minspeed] {
     
    35463543}
    35473544
     3545/******************/
     3546/* maxspeed nodes */
     3547/******************/
     3548node[maxspeed=none] {
     3549    icon-image: "vehicle/restriction/maxspeed_none.svg";
     3550}
     3551node[maxspeed=~/^[0-9]+$/] {
     3552    maxspeedprop: tag(maxspeed);
     3553    set maxspeedclass;
     3554}
     3555node[maxspeed=signals] {
     3556    maxspeedprop: " ?";
     3557    set maxspeedclass;
     3558}
     3559node[maxspeed=~/^[0-9]+ mph/] {
     3560    maxspeedprop: get(split(" mph",tag(maxspeed)),0);
     3561    set maxspeedclass;
     3562}
     3563node[maxspeed=~/[0-9]+ km\/h/] {
     3564    maxspeedprop: get(split(" km/h",tag(maxspeed)),0);
     3565    set maxspeedclass;
     3566}
     3567node[maxspeed=~/[0-9]+ knots/] {
     3568    maxspeedprop: get(split(" knots",tag(maxspeed)),0);
     3569    set maxspeedclass;
     3570}
     3571node[prop(maxspeedclass, default)][!is_prop_set(icon-image, default)]::core_maxnodebg {
     3572    /* background (white) */
     3573    symbol-shape: circle;
     3574    symbol-size: 17;
     3575    symbol-fill-color: white;
     3576    major-z-index: 4.2;
     3577}
     3578node[maxspeed]["maxspeed:variable"]["maxspeed:variable"!="no"][!is_prop_set(icon-image, default)]::core_maxnodebg,
     3579node[maxspeed=signals][!is_prop_set(icon-image, default)]::core_maxnodebg {
     3580    /* background (black) */
     3581    symbol-fill-color: black;
     3582}
     3583node[prop(maxspeedclass, default)][!is_prop_set(icon-image, default)]::core_maxnodefg {
     3584    /* foreground (black text and red circle) */
     3585    symbol-shape: circle;
     3586    symbol-size: 15;
     3587    symbol-stroke-color: crimson;
     3588    symbol-stroke-width: 2;
     3589    text: prop(maxspeedprop, default);
     3590    font-size: 8;
     3591    font-weight: bold;
     3592    font-family: "Droid Sans";
     3593    text-color: black;
     3594    text-anchor-horizontal: center;
     3595    text-anchor-vertical: center;
     3596    text-offset-x: 0;
     3597    text-offset-y: -1;
     3598    major-z-index: 4.2;
     3599}
     3600node[maxspeed]["maxspeed:variable"]["maxspeed:variable"!="no"][!is_prop_set(icon-image, default)]::core_maxnodefg,
     3601node[maxspeed=signals][!is_prop_set(icon-image, default)]::core_maxnodefg {
     3602    /* foreground (white text) */
     3603    text-color: white;
     3604}
     3605
    35483606/***************/
    35493607/* zoom levels */
     
    35903648}
    35913649
    3592 node|z20,area|z20   { font-size: 9; }
    3593 node|z21,area|z21   { font-size: 10; }
    3594 node|z22-,area|z22- { font-size: 11; }
     3650node|z19,area|z19   { font-size: 9; }
     3651node|z20-,area|z20-   { font-size: 10; }
    35953652
    35963653/**************/
Note: See TracChangeset for help on using the changeset viewer.