Ticket #18468: 18468.patch

File 18468.patch, 7.8 KB (added by simon04, 6 years ago)
  • src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
    index c477314de..9482e05d6 100644
    a b public void drawBoxText(INode n, BoxTextElement bs) {  
    660660            } else throw new AssertionError();
    661661        }
    662662
    663         displayText(n, text, s, bounds, new MapViewPositionAndRotation(mapState.getForView(x, y), 0));
     663        displayText(n, text, s, bounds, new MapViewPositionAndRotation(mapState.getForView(x, y), text.rotationAngle.getRotationAngle(n)));
    664664        g.setFont(defaultFont);
    665665    }
    666666
  • src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java

    diff --git a/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java b/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java
    index 1b45272cb..53a216257 100644
    a b  
    9090     * MapCSS icon-rotation property key
    9191     */
    9292    String ICON_ROTATION = "icon-rotation";
     93    /**
     94     * MapCSS text-rotation property key
     95     */
     96    String TEXT_ROTATION = "text-rotation";
    9397    /**
    9498     * MapCSS icon-width property key
    9599     */
  • src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java

    diff --git a/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java b/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java
    index a0a184537..f89530a00 100644
    a b static NodeElement create(Environment env, float defaultMajorZindex, boolean all  
    8686     * @since 11670
    8787     */
    8888    public static RotationAngle createRotationAngle(Environment env) {
     89        return createRotationAngle(env, ICON_ROTATION);
     90    }
     91
     92    public static RotationAngle createTextRotationAngle(Environment env) {
     93        return createRotationAngle(env, TEXT_ROTATION);
     94    }
     95
     96    private static RotationAngle createRotationAngle(Environment env, String key) {
    8997        Cascade c = env.mc.getCascade(env.layer);
    9098
    9199        RotationAngle rotationAngle = RotationAngle.NO_ROTATION;
    92         final Float angle = c.get(ICON_ROTATION, null, Float.class, true);
     100        final Float angle = c.get(key, null, Float.class, true);
    93101        if (angle != null) {
    94102            rotationAngle = RotationAngle.buildStaticRotation(angle);
    95103        } else {
    96             final Keyword rotationKW = c.get(ICON_ROTATION, null, Keyword.class);
     104            final Keyword rotationKW = c.get(key, null, Keyword.class);
    97105            if (rotationKW != null) {
    98106                if ("way".equals(rotationKW.val)) {
    99107                    rotationAngle = RotationAngle.buildWayDirectionRotation();
  • src/org/openstreetmap/josm/gui/mappaint/styleelement/TextLabel.java

    diff --git a/src/org/openstreetmap/josm/gui/mappaint/styleelement/TextLabel.java b/src/org/openstreetmap/josm/gui/mappaint/styleelement/TextLabel.java
    index 829385f8a..a45b0b0dc 100644
    a b  
    1717import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.StaticLabelCompositionStrategy;
    1818import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy;
    1919import org.openstreetmap.josm.tools.CheckParameterUtil;
     20import org.openstreetmap.josm.tools.RotationAngle;
    2021import org.openstreetmap.josm.tools.Utils;
    2122
    2223/**
     
    3839     * the font to be used when rendering
    3940     */
    4041    public Font font;
     42    public RotationAngle rotationAngle;
    4143    /**
    4244     * The color to draw the text in, includes alpha.
    4345     */
     
    5759     * @param strategy the strategy indicating how the text is composed for a specific {@link OsmPrimitive} to be rendered.
    5860     * If null, no label is rendered.
    5961     * @param font the font to be used. Must not be null.
     62     * @param rotationAngle the rotation angle to be used. Must not be null.
    6063     * @param color the color to be used. Must not be null
    6164     * @param haloRadius halo radius
    6265     * @param haloColor halo color
    6366     */
    64     protected TextLabel(LabelCompositionStrategy strategy, Font font, Color color, Float haloRadius,
    65             Color haloColor) {
     67    protected TextLabel(LabelCompositionStrategy strategy, Font font, RotationAngle rotationAngle, Color color, Float haloRadius,
     68                        Color haloColor) {
    6669        this.labelCompositionStrategy = strategy;
    6770        this.font = Objects.requireNonNull(font, "font");
     71        this.rotationAngle = Objects.requireNonNull(rotationAngle, "rotationAngle");
    6872        this.color = Objects.requireNonNull(color, "color");
    6973        this.haloRadius = haloRadius;
    7074        this.haloColor = haloColor;
    protected TextLabel(LabelCompositionStrategy strategy, Font font, Color color, F  
    7882    public TextLabel(TextLabel other) {
    7983        this.labelCompositionStrategy = other.labelCompositionStrategy;
    8084        this.font = other.font;
     85        this.rotationAngle = other.rotationAngle;
    8186        this.color = other.color;
    8287        this.haloColor = other.haloColor;
    8388        this.haloRadius = other.haloRadius;
    public static TextLabel create(Environment env, Color defaultTextColor, boolean  
    136141        String s = strategy.compose(env.osm);
    137142        if (s == null) return null;
    138143        Font font = StyleElement.getFont(c, s);
     144        RotationAngle rotationAngle = NodeElement.createTextRotationAngle(env);
    139145
    140146        Color color = c.get(TEXT_COLOR, defaultTextColor, Color.class);
    141147        float alpha = c.get(TEXT_OPACITY, 1f, Float.class);
    public static TextLabel create(Environment env, Color defaultTextColor, boolean  
    152158            haloColor = Utils.alphaMultiply(haloColor, haloAlphaFactor);
    153159        }
    154160
    155         return new TextLabel(strategy, font, color, haloRadius, haloColor);
     161        return new TextLabel(strategy, font, rotationAngle, color, haloRadius, haloColor);
    156162    }
    157163
    158164    /**
    protected String toStringImpl() {  
    198204        StringBuilder sb = new StringBuilder(96);
    199205        sb.append("labelCompositionStrategy=").append(labelCompositionStrategy)
    200206          .append(" font=").append(font)
    201           .append(" color=").append(Utils.toString(color));
     207          .append(" color=").append(Utils.toString(color))
     208          .append(" rotationAngle=").append(rotationAngle);
    202209        if (haloRadius != null) {
    203210            sb.append(" haloRadius=").append(haloRadius)
    204211              .append(" haloColor=").append(haloColor);
    protected String toStringImpl() {  
    208215
    209216    @Override
    210217    public int hashCode() {
    211         return Objects.hash(labelCompositionStrategy, font, color, haloRadius, haloColor);
     218        return Objects.hash(labelCompositionStrategy, font, rotationAngle, color, haloRadius, haloColor);
    212219    }
    213220
    214221    @Override
    public boolean equals(Object obj) {  
    218225        TextLabel textLabel = (TextLabel) obj;
    219226        return Objects.equals(labelCompositionStrategy, textLabel.labelCompositionStrategy) &&
    220227                Objects.equals(font, textLabel.font) &&
     228                Objects.equals(rotationAngle, textLabel.rotationAngle) &&
    221229                Objects.equals(color, textLabel.color) &&
    222230                Objects.equals(haloRadius, textLabel.haloRadius) &&
    223231                Objects.equals(haloColor, textLabel.haloColor);
  • styles/standard/elemstyles.mapcss

    diff --git a/styles/standard/elemstyles.mapcss b/styles/standard/elemstyles.mapcss
    index 9d7a62948..7b23d5424 100644
    a b node[amenity=cafe] {  
    25852585    set icon_z17;
    25862586}
    25872587node[amenity=restaurant] {
     2588    text-rotation: 45;
    25882589    icon-image: "presets/food/restaurant.svg";
    25892590    set icon_z17;
    25902591}