Ticket #7624: mapcss-allow-left-right-encasing.patch
| File mapcss-allow-left-right-encasing.patch, 13.6 KB (added by , 14 years ago) |
|---|
-
src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
126 126 * e.g. oneway street or waterway 127 127 * @param onewayReversed for oneway=-1 and similar 128 128 */ 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, 130 130 boolean showOrientation, boolean showHeadArrowOnly, 131 131 boolean showOneway, boolean onewayReversed) { 132 132 … … 258 258 public class OffsetIterator implements Iterator<Point> { 259 259 260 260 private List<Node> nodes; 261 private int offset;261 private float offset; 262 262 private int idx; 263 263 264 264 private Point prev = null; … … 268 268 */ 269 269 private int x_prev0, y_prev0; 270 270 271 public OffsetIterator(List<Node> nodes, int offset) {271 public OffsetIterator(List<Node> nodes, float offset) { 272 272 this.nodes = nodes; 273 273 this.offset = offset; 274 274 idx = 0; … … 281 281 282 282 @Override 283 283 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++)); 285 285 286 286 Point current = nc.getPoint(nodes.get(idx)); 287 287 … … 860 860 861 861 if ((pb.width >= nb.getWidth() && pb.height >= nb.getHeight()) && // quick check 862 862 area.contains(centeredNBounds) // slow but nice 863 ) {863 ) { 864 864 g.setColor(text.color); 865 865 Font defaultFont = g.getFont(); 866 866 g.setFont (text.font); -
src/org/openstreetmap/josm/gui/mappaint/mapcss/Expression.java
19 19 import org.openstreetmap.josm.gui.mappaint.Cascade; 20 20 import org.openstreetmap.josm.gui.mappaint.Environment; 21 21 import org.openstreetmap.josm.tools.CheckParameterUtil; 22 import org.openstreetmap.josm.tools.ColorHelper; 22 23 import org.openstreetmap.josm.tools.Utils; 23 24 24 25 public interface Expression { … … 115 116 return c; 116 117 } 117 118 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 118 127 public float red(Color c) { 119 128 return Utils.color_int2float(c.getRed()); 120 129 } -
src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
32 32 private BasicStroke line; 33 33 public Color color; 34 34 public Color dashesBackground; 35 public int offset;35 public float offset; 36 36 public float realWidth; // the real width of this line in meter 37 37 38 38 private BasicStroke dashesLine; 39 39 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) { 41 41 super(c, 0f); 42 42 this.line = line; 43 43 this.color = color; … … 48 48 } 49 49 50 50 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; 52 70 } 53 71 54 72 public static LineElemStyle createCasing(Environment env) { 55 LineElemStyle casing = createImpl(env, true);73 LineElemStyle casing = createImpl(env, "casing-"); 56 74 if (casing != null) { 57 75 casing.z_index += -100; 58 76 casing.isModifier = true; … … 60 78 return casing; 61 79 } 62 80 63 private static LineElemStyle createImpl(Environment env, boolean casing) {81 private static LineElemStyle createImpl(Environment env, String prefix) { 64 82 Cascade c = env.mc.getCascade(env.layer); 65 83 Cascade c_def = env.mc.getCascade("default"); 66 84 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); 77 89 } 78 79 90 if (width == null) 80 91 return null; 81 92 … … 96 107 } 97 108 } 98 109 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 99 139 Color color = c.get(prefix + "color", null, Color.class); 100 if ( !casing&& color == null) {140 if (prefix.isEmpty() && color == null) { 101 141 color = c.get("fill-color", null, Color.class); 102 142 } 103 143 if (color == null) { … … 176 216 BasicStroke line = new BasicStroke(width, cap, join, miterlimit, dashes, dashesOffset); 177 217 BasicStroke dashesLine = null; 178 218 179 float offset = c.get("offset", 0f, Float.class);180 181 219 if (dashes != null && dashesBackground != null) { 182 220 float[] dashes2 = new float[dashes.length]; 183 221 System.arraycopy(dashes, 0, dashes2, 1, dashes.length - 1); … … 185 223 dashesLine = new BasicStroke(width, cap, join, miterlimit, dashes2, dashes2[0] + dashesOffset); 186 224 } 187 225 188 return new LineElemStyle(c, line, color, dashesLine, dashesBackground, (int)offset, realWidth);226 return new LineElemStyle(c, line, color, dashesLine, dashesBackground, offset, realWidth); 189 227 } 190 228 191 229 @Override … … 258 296 return false; 259 297 final LineElemStyle other = (LineElemStyle) obj; 260 298 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; 266 304 } 267 305 268 306 @Override … … 272 310 hash = 29 * hash + color.hashCode(); 273 311 hash = 29 * hash + (dashesLine != null ? dashesLine.hashCode() : 0); 274 312 hash = 29 * hash + (dashesBackground != null ? dashesBackground.hashCode() : 0); 275 hash = 29 * hash + offset;313 hash = 29 * hash + Float.floatToIntBits(offset); 276 314 hash = 29 * hash + Float.floatToIntBits(realWidth); 277 315 return hash; 278 316 } … … 280 318 @Override 281 319 public String toString() { 282 320 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 '}'; 291 329 } 292 330 293 331 public String linejoinToString(int linejoin) { 294 332 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; 299 337 } 300 338 } 301 339 public String linecapToString(int linecap) { 302 340 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; 307 345 } 308 346 } 309 347 } -
src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
310 310 addIfNotNull(sl, AreaElemStyle.create(c)); 311 311 addIfNotNull(sl, LinePatternElemStyle.create(env)); 312 312 addIfNotNull(sl, LineElemStyle.createLine(env)); 313 addIfNotNull(sl, LineElemStyle.createLeftCasing(env)); 314 addIfNotNull(sl, LineElemStyle.createRightCasing(env)); 313 315 addIfNotNull(sl, LineElemStyle.createCasing(env)); 314 316 addIfNotNull(sl, LineTextElemStyle.create(env)); 315 317 } else if (osm instanceof Node) { … … 346 348 * Draw a default node symbol for nodes that have no style? 347 349 */ 348 350 private boolean isDefaultNodes() { 349 if (defaultNodesIdx == cacheIdx) {351 if (defaultNodesIdx == cacheIdx) 350 352 return defaultNodes; 351 }352 353 defaultNodes = fromCanvas("default-points", true, Boolean.class); 353 354 defaultNodesIdx = cacheIdx; 354 355 return defaultNodes; … … 358 359 * Draw a default line for ways that do not have an own line style? 359 360 */ 360 361 private boolean isDefaultLines() { 361 if (defaultLinesIdx == cacheIdx) {362 if (defaultLinesIdx == cacheIdx) 362 363 return defaultLines; 363 }364 364 defaultLines = fromCanvas("default-lines", true, Boolean.class); 365 365 defaultLinesIdx = cacheIdx; 366 366 return defaultLines; … … 419 419 * @return first AreaElemStyle found or {@code null}. 420 420 */ 421 421 public static AreaElemStyle getAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed) { 422 if (MapPaintStyles.getStyles() == null) {422 if (MapPaintStyles.getStyles() == null) 423 423 return null; 424 }425 424 for (ElemStyle s : MapPaintStyles.getStyles().generateStyles(p, 1.0, null, pretendWayIsClosed).a) { 426 if (s instanceof AreaElemStyle) {425 if (s instanceof AreaElemStyle) 427 426 return (AreaElemStyle) s; 428 }429 427 } 430 428 return null; 431 429 }
