Ticket #7624: mapcss-allow-left-right-encasing.patch

File mapcss-allow-left-right-encasing.patch, 13.6 KB (added by cmuelle8, 14 years ago)

mapcss-allow-left-right-encasing.patch

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

     
    126126     *              e.g. oneway street or waterway
    127127     * @param onewayReversed for oneway=-1 and similar
    128128     */
    129     public void drawWay(Way way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor, int offset,
     129    public void drawWay(Way way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor, float offset,
    130130            boolean showOrientation, boolean showHeadArrowOnly,
    131131            boolean showOneway, boolean onewayReversed) {
    132132
     
    258258    public class OffsetIterator implements Iterator<Point> {
    259259
    260260        private List<Node> nodes;
    261         private int offset;
     261        private float offset;
    262262        private int idx;
    263263
    264264        private Point prev = null;
     
    268268         */
    269269        private int x_prev0, y_prev0;
    270270
    271         public OffsetIterator(List<Node> nodes, int offset) {
     271        public OffsetIterator(List<Node> nodes, float offset) {
    272272            this.nodes = nodes;
    273273            this.offset = offset;
    274274            idx = 0;
     
    281281
    282282        @Override
    283283        public Point next() {
    284             if (offset == 0) return nc.getPoint(nodes.get(idx++));
     284            if (Math.abs(offset) < 0.1f) return nc.getPoint(nodes.get(idx++));
    285285
    286286            Point current = nc.getPoint(nodes.get(idx));
    287287
     
    860860
    861861            if ((pb.width >= nb.getWidth() && pb.height >= nb.getHeight()) && // quick check
    862862                    area.contains(centeredNBounds) // slow but nice
    863                     ) {
     863            ) {
    864864                g.setColor(text.color);
    865865                Font defaultFont = g.getFont();
    866866                g.setFont (text.font);
  • src/org/openstreetmap/josm/gui/mappaint/mapcss/Expression.java

     
    1919import org.openstreetmap.josm.gui.mappaint.Cascade;
    2020import org.openstreetmap.josm.gui.mappaint.Environment;
    2121import org.openstreetmap.josm.tools.CheckParameterUtil;
     22import org.openstreetmap.josm.tools.ColorHelper;
    2223import org.openstreetmap.josm.tools.Utils;
    2324
    2425public interface Expression {
     
    115116                return c;
    116117            }
    117118
     119            public Color html2color(String html) {
     120                return ColorHelper.html2color(html);
     121            }
     122
     123            public String color2html(Color c) {
     124                return ColorHelper.color2html(c);
     125            }
     126
    118127            public float red(Color c) {
    119128                return Utils.color_int2float(c.getRed());
    120129            }
  • src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

     
    3232    private BasicStroke line;
    3333    public Color color;
    3434    public Color dashesBackground;
    35     public int offset;
     35    public float offset;
    3636    public float realWidth; // the real width of this line in meter
    3737
    3838    private BasicStroke dashesLine;
    3939
    40     protected LineElemStyle(Cascade c, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, int offset, float realWidth) {
     40    protected LineElemStyle(Cascade c, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, float offset, float realWidth) {
    4141        super(c, 0f);
    4242        this.line = line;
    4343        this.color = color;
     
    4848    }
    4949
    5050    public static LineElemStyle createLine(Environment env) {
    51         return createImpl(env, false);
     51        return createImpl(env, "");
     52    }
     53
     54    public static LineElemStyle createLeftCasing(Environment env) {
     55        LineElemStyle leftCasing = createImpl(env, "left-casing-");
     56        if (leftCasing != null) {
     57            leftCasing.z_index += -90;
     58            leftCasing.isModifier = true;
     59        }
     60        return leftCasing;
     61    }
     62
     63    public static LineElemStyle createRightCasing(Environment env) {
     64        LineElemStyle rightCasing = createImpl(env, "right-casing-");
     65        if (rightCasing != null) {
     66            rightCasing.z_index += -90;
     67            rightCasing.isModifier = true;
     68        }
     69        return rightCasing;
    5270    }
    5371
    5472    public static LineElemStyle createCasing(Environment env) {
    55         LineElemStyle casing =  createImpl(env, true);
     73        LineElemStyle casing = createImpl(env, "casing-");
    5674        if (casing != null) {
    5775            casing.z_index += -100;
    5876            casing.isModifier = true;
     
    6078        return casing;
    6179    }
    6280
    63     private static LineElemStyle createImpl(Environment env, boolean casing) {
     81    private static LineElemStyle createImpl(Environment env, String prefix) {
    6482        Cascade c = env.mc.getCascade(env.layer);
    6583        Cascade c_def = env.mc.getCascade("default");
    6684
    67         String prefix = casing ? "casing-" : "";
    68 
    69         Float width;
    70         if (casing) {
    71             Float widthOnDefault = getWidth(c_def, "width", null);
    72             Float widthLine = getWidth(c, "width", widthOnDefault);
    73             width = getWidth(c, "casing-width", widthLine);
    74         } else {
    75             Float widthOnDefault = getWidth(c_def, "width", null);
    76             width = getWidth(c, "width", widthOnDefault);
     85        Float widthOnDefault = getWidth(c_def, "width", null);
     86        Float width = getWidth(c, "width", widthOnDefault);
     87        if (!prefix.isEmpty()) {
     88            width = getWidth(c, prefix + "width", width);
    7789        }
    78 
    7990        if (width == null)
    8091            return null;
    8192
     
    96107            }
    97108        }
    98109
     110        Float offsetOnDefault = getWidth(c_def, "offset", null);
     111        Float offset = getWidth(c, "offset", offsetOnDefault);
     112        if (offset == null) {
     113            offset = 0f;
     114        }
     115        if (!prefix.isEmpty()) {
     116            Float base_width = getWidth(c, "width", widthOnDefault);
     117            Float base_offset = offset;
     118            if (base_width == null || base_width < 2f) {
     119                base_width = 2f;
     120            }
     121            /* pre-calculate an offset */
     122            if (prefix.startsWith("left") || prefix.startsWith("right")) {
     123                offset = base_width/2 + width/2;
     124            } else {
     125                offset = 0f;
     126            }
     127            /* overwrites (e.g. "4") or adjusts (e.g. "+4") a prefixed -offset */
     128            if (getWidth(c, prefix + "offset", offset) != null) {
     129                offset = getWidth(c, prefix + "offset", offset);
     130            }
     131            /* flip sign for the right-casing-offset */
     132            if (prefix.startsWith("right")) {
     133                offset *= -1f;
     134            }
     135            /* use base_offset as the reference center */
     136            offset += base_offset;
     137        }
     138
    99139        Color color = c.get(prefix + "color", null, Color.class);
    100         if (!casing && color == null) {
     140        if (prefix.isEmpty() && color == null) {
    101141            color = c.get("fill-color", null, Color.class);
    102142        }
    103143        if (color == null) {
     
    176216        BasicStroke line = new BasicStroke(width, cap, join, miterlimit, dashes, dashesOffset);
    177217        BasicStroke dashesLine = null;
    178218
    179         float offset = c.get("offset", 0f, Float.class);
    180 
    181219        if (dashes != null && dashesBackground != null) {
    182220            float[] dashes2 = new float[dashes.length];
    183221            System.arraycopy(dashes, 0, dashes2, 1, dashes.length - 1);
     
    185223            dashesLine = new BasicStroke(width, cap, join, miterlimit, dashes2, dashes2[0] + dashesOffset);
    186224        }
    187225
    188         return new LineElemStyle(c, line, color, dashesLine, dashesBackground, (int) offset, realWidth);
     226        return new LineElemStyle(c, line, color, dashesLine, dashesBackground, offset, realWidth);
    189227    }
    190228
    191229    @Override
     
    258296            return false;
    259297        final LineElemStyle other = (LineElemStyle) obj;
    260298        return  equal(line, other.line) &&
    261             equal(color, other.color) &&
    262             equal(dashesLine, other.dashesLine) &&
    263             equal(dashesBackground, other.dashesBackground) &&
    264             offset == other.offset &&
    265             realWidth == other.realWidth;
     299        equal(color, other.color) &&
     300        equal(dashesLine, other.dashesLine) &&
     301        equal(dashesBackground, other.dashesBackground) &&
     302        offset == other.offset &&
     303        realWidth == other.realWidth;
    266304    }
    267305
    268306    @Override
     
    272310        hash = 29 * hash + color.hashCode();
    273311        hash = 29 * hash + (dashesLine != null ? dashesLine.hashCode() : 0);
    274312        hash = 29 * hash + (dashesBackground != null ? dashesBackground.hashCode() : 0);
    275         hash = 29 * hash + offset;
     313        hash = 29 * hash + Float.floatToIntBits(offset);
    276314        hash = 29 * hash + Float.floatToIntBits(realWidth);
    277315        return hash;
    278316    }
     
    280318    @Override
    281319    public String toString() {
    282320        return "LineElemStyle{" + super.toString() + "width=" + line.getLineWidth() +
    283             " realWidth=" + realWidth + " color=" + Utils.toString(color) +
    284             " dashed=" + Arrays.toString(line.getDashArray()) +
    285             (line.getDashPhase() == 0f ? "" : " dashesOffses=" + line.getDashPhase()) +
    286             " dashedColor=" + Utils.toString(dashesBackground) +
    287             " linejoin=" + linejoinToString(line.getLineJoin()) +
    288             " linecap=" + linecapToString(line.getEndCap()) +
    289             (offset == 0 ? "" : " offset=" + offset) +
    290             '}';
     321        " realWidth=" + realWidth + " color=" + Utils.toString(color) +
     322        " dashed=" + Arrays.toString(line.getDashArray()) +
     323        (line.getDashPhase() == 0f ? "" : " dashesOffses=" + line.getDashPhase()) +
     324        " dashedColor=" + Utils.toString(dashesBackground) +
     325        " linejoin=" + linejoinToString(line.getLineJoin()) +
     326        " linecap=" + linecapToString(line.getEndCap()) +
     327        (offset == 0 ? "" : " offset=" + offset) +
     328        '}';
    291329    }
    292330
    293331    public String linejoinToString(int linejoin) {
    294332        switch (linejoin) {
    295             case BasicStroke.JOIN_BEVEL: return "bevel";
    296             case BasicStroke.JOIN_ROUND: return "round";
    297             case BasicStroke.JOIN_MITER: return "miter";
    298             default: return null;
     333        case BasicStroke.JOIN_BEVEL: return "bevel";
     334        case BasicStroke.JOIN_ROUND: return "round";
     335        case BasicStroke.JOIN_MITER: return "miter";
     336        default: return null;
    299337        }
    300338    }
    301339    public String linecapToString(int linecap) {
    302340        switch (linecap) {
    303             case BasicStroke.CAP_BUTT: return "none";
    304             case BasicStroke.CAP_ROUND: return "round";
    305             case BasicStroke.CAP_SQUARE: return "square";
    306             default: return null;
     341        case BasicStroke.CAP_BUTT: return "none";
     342        case BasicStroke.CAP_ROUND: return "round";
     343        case BasicStroke.CAP_SQUARE: return "square";
     344        default: return null;
    307345        }
    308346    }
    309347}
  • src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

     
    310310                addIfNotNull(sl, AreaElemStyle.create(c));
    311311                addIfNotNull(sl, LinePatternElemStyle.create(env));
    312312                addIfNotNull(sl, LineElemStyle.createLine(env));
     313                addIfNotNull(sl, LineElemStyle.createLeftCasing(env));
     314                addIfNotNull(sl, LineElemStyle.createRightCasing(env));
    313315                addIfNotNull(sl, LineElemStyle.createCasing(env));
    314316                addIfNotNull(sl, LineTextElemStyle.create(env));
    315317            } else if (osm instanceof Node) {
     
    346348     * Draw a default node symbol for nodes that have no style?
    347349     */
    348350    private boolean isDefaultNodes() {
    349         if (defaultNodesIdx == cacheIdx) {
     351        if (defaultNodesIdx == cacheIdx)
    350352            return defaultNodes;
    351         }
    352353        defaultNodes = fromCanvas("default-points", true, Boolean.class);
    353354        defaultNodesIdx = cacheIdx;
    354355        return defaultNodes;
     
    358359     * Draw a default line for ways that do not have an own line style?
    359360     */
    360361    private boolean isDefaultLines() {
    361         if (defaultLinesIdx == cacheIdx) {
     362        if (defaultLinesIdx == cacheIdx)
    362363            return defaultLines;
    363         }
    364364        defaultLines = fromCanvas("default-lines", true, Boolean.class);
    365365        defaultLinesIdx = cacheIdx;
    366366        return defaultLines;
     
    419419     * @return first AreaElemStyle found or {@code null}.
    420420     */
    421421    public static AreaElemStyle getAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed) {
    422         if (MapPaintStyles.getStyles() == null) {
     422        if (MapPaintStyles.getStyles() == null)
    423423            return null;
    424         }
    425424        for (ElemStyle s : MapPaintStyles.getStyles().generateStyles(p, 1.0, null, pretendWayIsClosed).a) {
    426             if (s instanceof AreaElemStyle) {
     425            if (s instanceof AreaElemStyle)
    427426                return (AreaElemStyle) s;
    428             }
    429427        }
    430428        return null;
    431429    }