Changeset 16253 in josm for trunk/src/org
- Timestamp:
- 2020-04-11T09:55:52+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r16208 r16253 88 88 import org.openstreetmap.josm.tools.JosmRuntimeException; 89 89 import org.openstreetmap.josm.tools.Logging; 90 import org.openstreetmap.josm.tools.RotationAngle; 90 91 import org.openstreetmap.josm.tools.ShapeClipper; 91 92 import org.openstreetmap.josm.tools.Utils; … … 620 621 Rectangle2D bounds = text.font.getStringBounds(s, frc); 621 622 622 double x = Math.round(p.getInViewX()) + bs.xOffset + bounds.getCenterX();623 double y = Math.round(p.getInViewY()) + bs.yOffset + bounds.getCenterY();623 double x = p.getInViewX() + bs.xOffset; 624 double y = p.getInViewY() + bs.yOffset; 624 625 /** 625 626 * … … 660 661 } 661 662 662 displayText(n, text, s, bounds, new MapViewPositionAndRotation(mapState.getForView(x, y), 0)); 663 final MapViewPoint viewPoint = mapState.getForView(x, y); 664 final AffineTransform at = new AffineTransform(); 665 at.setToTranslation( 666 Math.round(viewPoint.getInViewX()), 667 Math.round(viewPoint.getInViewY())); 668 if (!RotationAngle.NO_ROTATION.equals(text.rotationAngle)) { 669 at.rotate(text.rotationAngle.getRotationAngle(n)); 670 } 671 displayText(n, text, s, at); 663 672 g.setFont(defaultFont); 664 673 } … … 1188 1197 if (Math.abs(center.getRotation()) < .01) { 1189 1198 // Explicitly no rotation: move to full pixels. 1190 at.setToTranslation(Math.round(center.getPoint().getInViewX() - nb.getCenterX()), 1199 at.setToTranslation( 1200 Math.round(center.getPoint().getInViewX() - nb.getCenterX()), 1191 1201 Math.round(center.getPoint().getInViewY() - nb.getCenterY())); 1192 1202 } else { 1193 at.setToTranslation(center.getPoint().getInViewX(), center.getPoint().getInViewY()); 1203 at.setToTranslation( 1204 center.getPoint().getInViewX(), 1205 center.getPoint().getInViewY()); 1194 1206 at.rotate(center.getRotation()); 1195 1207 at.translate(-nb.getCenterX(), -nb.getCenterY()); 1196 1208 } 1209 displayText(osm, text, name, at); 1210 } 1211 1212 private void displayText(IPrimitive osm, TextLabel text, String name, AffineTransform at) { 1197 1213 displayText(() -> { 1198 1214 AffineTransform defaultTransform = g.getTransform(); -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java
r12381 r16253 92 92 String ICON_ROTATION = "icon-rotation"; 93 93 /** 94 * MapCSS text-rotation property key 95 */ 96 String TEXT_ROTATION = "text-rotation"; 97 /** 94 98 * MapCSS icon-width property key 95 99 */ -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java
r16252 r16253 88 88 */ 89 89 public static RotationAngle createRotationAngle(Environment env) { 90 return createRotationAngle(env, ICON_ROTATION); 91 } 92 93 /** 94 * Reads the text-rotation property and creates a rotation angle from it. 95 * @param env The environment 96 * @return The angle 97 * @since 16253 98 */ 99 public static RotationAngle createTextRotationAngle(Environment env) { 100 return createRotationAngle(env, TEXT_ROTATION); 101 } 102 103 private static RotationAngle createRotationAngle(Environment env, String key) { 90 104 Cascade c = env.mc.getCascade(env.layer); 91 105 92 106 RotationAngle rotationAngle = RotationAngle.NO_ROTATION; 93 final Float angle = c.get( ICON_ROTATION, null, Float.class, true);107 final Float angle = c.get(key, null, Float.class, true); 94 108 if (angle != null) { 95 109 rotationAngle = RotationAngle.buildStaticRotation(angle); 96 110 } else { 97 final Keyword rotationKW = c.get( ICON_ROTATION, null, Keyword.class);111 final Keyword rotationKW = c.get(key, null, Keyword.class); 98 112 if (rotationKW != null) { 99 113 if ("way".equals(rotationKW.val)) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/TextLabel.java
r16252 r16253 19 19 import org.openstreetmap.josm.tools.CheckParameterUtil; 20 20 import org.openstreetmap.josm.tools.ColorHelper; 21 import org.openstreetmap.josm.tools.RotationAngle; 21 22 22 23 /** … … 40 41 public Font font; 41 42 /** 43 * The rotation angle to be used when rendering 44 */ 45 public RotationAngle rotationAngle; 46 /** 42 47 * The color to draw the text in, includes alpha. 43 48 */ … … 58 63 * If null, no label is rendered. 59 64 * @param font the font to be used. Must not be null. 65 * @param rotationAngle the rotation angle to be used. Must not be null. 60 66 * @param color the color to be used. Must not be null 61 67 * @param haloRadius halo radius 62 68 * @param haloColor halo color 63 69 */ 64 protected TextLabel(LabelCompositionStrategy strategy, Font font, Color color, Float haloRadius,65 Color haloColor) {70 protected TextLabel(LabelCompositionStrategy strategy, Font font, RotationAngle rotationAngle, 71 Color color, Float haloRadius, Color haloColor) { 66 72 this.labelCompositionStrategy = strategy; 67 73 this.font = Objects.requireNonNull(font, "font"); 74 this.rotationAngle = Objects.requireNonNull(rotationAngle, "rotationAngle"); 68 75 this.color = Objects.requireNonNull(color, "color"); 69 76 this.haloRadius = haloRadius; … … 79 86 this.labelCompositionStrategy = other.labelCompositionStrategy; 80 87 this.font = other.font; 88 this.rotationAngle = other.rotationAngle; 81 89 this.color = other.color; 82 90 this.haloColor = other.haloColor; … … 137 145 if (s == null) return null; 138 146 Font font = StyleElement.getFont(c, s); 147 RotationAngle rotationAngle = NodeElement.createTextRotationAngle(env); 139 148 140 149 Color color = c.get(TEXT_COLOR, defaultTextColor, Color.class); … … 153 162 } 154 163 155 return new TextLabel(strategy, font, color, haloRadius, haloColor);164 return new TextLabel(strategy, font, rotationAngle, color, haloRadius, haloColor); 156 165 } 157 166 … … 199 208 sb.append("labelCompositionStrategy=").append(labelCompositionStrategy) 200 209 .append(" font=").append(font) 210 .append(" rotationAngle=").append(rotationAngle) 201 211 .append(" color=").append(ColorHelper.color2html(color)); 202 212 if (haloRadius != null) { … … 209 219 @Override 210 220 public int hashCode() { 211 return Objects.hash(labelCompositionStrategy, font, color, haloRadius, haloColor);221 return Objects.hash(labelCompositionStrategy, font, rotationAngle, color, haloRadius, haloColor); 212 222 } 213 223 … … 219 229 return Objects.equals(labelCompositionStrategy, textLabel.labelCompositionStrategy) && 220 230 Objects.equals(font, textLabel.font) && 231 Objects.equals(rotationAngle, textLabel.rotationAngle) && 221 232 Objects.equals(color, textLabel.color) && 222 233 Objects.equals(haloRadius, textLabel.haloRadius) &&
Note:
See TracChangeset
for help on using the changeset viewer.