Ignore:
Timestamp:
2020-04-11T09:55:52+02:00 (4 years ago)
Author:
simon04
Message:

fix #18468 - MapCSS: add support for text-rotation

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint
Files:
3 edited

Legend:

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

    r12381 r16253  
    9292    String ICON_ROTATION = "icon-rotation";
    9393    /**
     94     * MapCSS text-rotation property key
     95     */
     96    String TEXT_ROTATION = "text-rotation";
     97    /**
    9498     * MapCSS icon-width property key
    9599     */
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java

    r16252 r16253  
    8888     */
    8989    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) {
    90104        Cascade c = env.mc.getCascade(env.layer);
    91105
    92106        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);
    94108        if (angle != null) {
    95109            rotationAngle = RotationAngle.buildStaticRotation(angle);
    96110        } else {
    97             final Keyword rotationKW = c.get(ICON_ROTATION, null, Keyword.class);
     111            final Keyword rotationKW = c.get(key, null, Keyword.class);
    98112            if (rotationKW != null) {
    99113                if ("way".equals(rotationKW.val)) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/TextLabel.java

    r16252 r16253  
    1919import org.openstreetmap.josm.tools.CheckParameterUtil;
    2020import org.openstreetmap.josm.tools.ColorHelper;
     21import org.openstreetmap.josm.tools.RotationAngle;
    2122
    2223/**
     
    4041    public Font font;
    4142    /**
     43     * The rotation angle to be used when rendering
     44     */
     45    public RotationAngle rotationAngle;
     46    /**
    4247     * The color to draw the text in, includes alpha.
    4348     */
     
    5863     * If null, no label is rendered.
    5964     * @param font the font to be used. Must not be null.
     65     * @param rotationAngle the rotation angle to be used. Must not be null.
    6066     * @param color the color to be used. Must not be null
    6167     * @param haloRadius halo radius
    6268     * @param haloColor halo color
    6369     */
    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) {
    6672        this.labelCompositionStrategy = strategy;
    6773        this.font = Objects.requireNonNull(font, "font");
     74        this.rotationAngle = Objects.requireNonNull(rotationAngle, "rotationAngle");
    6875        this.color = Objects.requireNonNull(color, "color");
    6976        this.haloRadius = haloRadius;
     
    7986        this.labelCompositionStrategy = other.labelCompositionStrategy;
    8087        this.font = other.font;
     88        this.rotationAngle = other.rotationAngle;
    8189        this.color = other.color;
    8290        this.haloColor = other.haloColor;
     
    137145        if (s == null) return null;
    138146        Font font = StyleElement.getFont(c, s);
     147        RotationAngle rotationAngle = NodeElement.createTextRotationAngle(env);
    139148
    140149        Color color = c.get(TEXT_COLOR, defaultTextColor, Color.class);
     
    153162        }
    154163
    155         return new TextLabel(strategy, font, color, haloRadius, haloColor);
     164        return new TextLabel(strategy, font, rotationAngle, color, haloRadius, haloColor);
    156165    }
    157166
     
    199208        sb.append("labelCompositionStrategy=").append(labelCompositionStrategy)
    200209          .append(" font=").append(font)
     210          .append(" rotationAngle=").append(rotationAngle)
    201211          .append(" color=").append(ColorHelper.color2html(color));
    202212        if (haloRadius != null) {
     
    209219    @Override
    210220    public int hashCode() {
    211         return Objects.hash(labelCompositionStrategy, font, color, haloRadius, haloColor);
     221        return Objects.hash(labelCompositionStrategy, font, rotationAngle, color, haloRadius, haloColor);
    212222    }
    213223
     
    219229        return Objects.equals(labelCompositionStrategy, textLabel.labelCompositionStrategy) &&
    220230                Objects.equals(font, textLabel.font) &&
     231                Objects.equals(rotationAngle, textLabel.rotationAngle) &&
    221232                Objects.equals(color, textLabel.color) &&
    222233                Objects.equals(haloRadius, textLabel.haloRadius) &&
Note: See TracChangeset for help on using the changeset viewer.