- Timestamp:
- 2015-04-25T14:00:05+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r8238 r8260 120 120 symbol = createSymbol(env); 121 121 } 122 final String rotationString = c.get("icon-rotation", null, String.class);123 122 RotationAngle rotationAngle = null; 124 if ("way".equalsIgnoreCase(rotationString)) { 125 rotationAngle = RotationAngle.buildWayDirectionRotation(); 126 } else if (rotationString != null) { 127 try { 128 rotationAngle = RotationAngle.buildStaticRotation(rotationString); 129 } catch (RuntimeException ignore) { 123 final Float angle = c.get(ICON_ROTATION, null, Float.class, true); 124 if (angle != null) { 125 rotationAngle = RotationAngle.buildStaticRotation(angle); 126 } else { 127 final Keyword rotationKW = c.get(ICON_ROTATION, null, Keyword.class); 128 if (rotationKW != null) { 129 if ("way".equals(rotationKW.val)) { 130 rotationAngle = RotationAngle.buildWayDirectionRotation(); 131 } else { 132 try { 133 rotationAngle = RotationAngle.buildStaticRotation(rotationKW.val); 134 } catch (IllegalArgumentException ignore) { 135 } 136 } 130 137 } 131 138 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java
r8087 r8260 21 21 String ICON_OFFSET_Y = "icon-offset-y"; 22 22 String ICON_OPACITY = "icon-opacity"; 23 String ICON_ROTATION = "icon-rotation"; 23 24 String ICON_WIDTH = "icon-width"; 24 25 String LINECAP = "linecap"; -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r8256 r8260 20 20 import org.openstreetmap.josm.gui.mappaint.mapcss.Expression; 21 21 import org.openstreetmap.josm.gui.mappaint.mapcss.ExpressionFactory; 22 import org.openstreetmap.josm.gui.mappaint.mapcss.ExpressionFactory.NullExpression; 22 23 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction; 23 24 import org.openstreetmap.josm.gui.mappaint.mapcss.LiteralExpression; … … 184 185 | < CARET: "^" > 185 186 | < FULLSTOP: "." > 187 | < DEG: "°" > 186 188 | < ELEMENT_OF: "∈" > 187 189 | < CROSSING: "⧉" > … … 1028 1030 fn=function() { return fn; } 1029 1031 | 1030 lit=literal() { return new LiteralExpression(lit); } 1032 lit=literal() 1033 { 1034 if (lit == null) 1035 return NullExpression.INSTANCE; 1036 return new LiteralExpression(lit); 1037 } 1031 1038 | 1032 1039 <LPAR> w() nested=expression() <RPAR> { return nested; } … … 1054 1061 String val, pref; 1055 1062 Token t; 1056 float f;1063 Float f; 1057 1064 } 1058 1065 { … … 1067 1074 <PLUS> f=ufloat() { return new Instruction.RelativeFloat(f); } 1068 1075 | 1076 LOOKAHEAD(2) 1077 f=ufloat_unit() { return f; } 1078 | 1069 1079 f=ufloat() { return f; } 1070 1080 | 1071 1081 t=<HEXCOLOR> { return ColorHelper.html2color(t.image); } 1082 } 1083 1084 /** 1085 * Number followed by a unit. 1086 * 1087 * Returns angles in radians and lengths in pixels. 1088 */ 1089 Float ufloat_unit() : 1090 { 1091 float f; 1092 String u; 1093 } 1094 { 1095 f=ufloat() ( u=ident() | <DEG> { u = "°"; } ) 1096 { 1097 Double m = unit_factor(u); 1098 if (m == null) 1099 return null; 1100 return (float) (f * m); 1101 } 1102 } 1103 1104 JAVACODE 1105 private Double unit_factor(String unit) { 1106 switch (unit) { 1107 case "deg": 1108 case "°": return Math.PI / 180; 1109 case "rad": return 1.; 1110 case "grad": return Math.PI / 200; 1111 case "turn": return 2 * Math.PI; 1112 case "px": return 1.; 1113 case "cm": return 96/2.54; 1114 case "mm": return 9.6/2.54; 1115 case "in": return 96.; 1116 case "q": return 2.4/2.54; 1117 case "pc": return 16.; 1118 case "pt": return 96./72; 1119 default: return null; 1120 } 1072 1121 } 1073 1122 -
trunk/src/org/openstreetmap/josm/gui/util/RotationAngle.java
r8251 r8260 41 41 */ 42 42 public static RotationAngle buildStaticRotation(final String string) { 43 final Pattern radiansPattern = Pattern.compile("(\\d+\\.?\\d*)\\s*(rad)?");44 final Pattern degreesPattern = Pattern.compile("(\\d+\\.?\\d*)\\s*(deg|°)");45 final Pattern gradianPattern = Pattern.compile("(\\d+\\.?\\d*)\\s*(grad)");46 final Pattern turnPattern = Pattern.compile("(\\d+\\.?\\d*)\\s*(turn)");47 43 final double value; 48 Matcher matcher; 49 if ((matcher = radiansPattern.matcher(string)).matches()) { 50 value = Double.parseDouble(matcher.group(1)); 51 } else if ((matcher = degreesPattern.matcher(string)).matches()) { 52 value = Math.toRadians(Double.parseDouble(matcher.group(1))); 53 } else if ((matcher = gradianPattern.matcher(string)).matches()) { 54 value = Double.parseDouble(matcher.group(1)) / 200 * Math.PI; 55 } else if ((matcher = turnPattern.matcher(string)).matches()) { 56 value = Double.parseDouble(matcher.group(1)) * 2 * Math.PI; 57 } else { 58 try { 59 value = parseCardinalRotation(string); 60 } catch (IllegalArgumentException ignore) { 61 throw new IllegalArgumentException("Invalid string: " + string); 62 } 44 try { 45 value = parseCardinalRotation(string); 46 } catch (IllegalArgumentException ignore) { 47 throw new IllegalArgumentException("Invalid string: " + string); 63 48 } 64 49 return buildStaticRotation(value);
Note:
See TracChangeset
for help on using the changeset viewer.