source: osm/applications/editors/josm/plugins/smed2/src/seamap/Renderer.java@ 30123

Last change on this file since 30123 was 30123, checked in by malcolmh, 12 years ago

save

File size: 23.3 KB
Line 
1/* Copyright 2013 Malcolm Herring
2 *
3 * This is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License.
6 *
7 * For a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>.
8 */
9
10package seamap;
11
12import java.awt.*;
13import java.awt.font.*;
14import java.awt.geom.*;
15import java.awt.image.*;
16import java.util.*;
17
18import s57.S57val.*;
19import seamap.SeaMap;
20import seamap.SeaMap.*;
21import seamap.SeaMap.Area;
22import symbols.Areas;
23import symbols.Harbours;
24import symbols.Symbols;
25import symbols.Symbols.*;
26
27public class Renderer {
28
29 public static final double symbolScale[] = { 256.0, 128.0, 64.0, 32.0, 16.0, 8.0, 4.0, 2.0, 1.0, 0.61, 0.372, 0.227, 0.138, 0.0843, 0.0514, 0.0313, 0.0191, 0.0117, 0.007, 0.138 };
30
31 public static final Color Yland = new Color(0x50b0ff);
32 public static final Color Mline = new Color(0xc480ff);
33 public static final Color Msymb = new Color(0xa30075);
34
35 static final EnumMap<ColCOL, Color> bodyColours = new EnumMap<ColCOL, Color>(ColCOL.class);
36 static {
37 bodyColours.put(ColCOL.COL_UNK, new Color(0, true));
38 bodyColours.put(ColCOL.COL_WHT, new Color(0xffffff));
39 bodyColours.put(ColCOL.COL_BLK, new Color(0x000000));
40 bodyColours.put(ColCOL.COL_RED, new Color(0xd40000));
41 bodyColours.put(ColCOL.COL_GRN, new Color(0x00d400));
42 bodyColours.put(ColCOL.COL_BLU, Color.blue);
43 bodyColours.put(ColCOL.COL_YEL, new Color(0xffd400));
44 bodyColours.put(ColCOL.COL_GRY, Color.gray);
45 bodyColours.put(ColCOL.COL_BRN, new Color(0x8b4513));
46 bodyColours.put(ColCOL.COL_AMB, new Color(0xfbf00f));
47 bodyColours.put(ColCOL.COL_VIO, new Color(0xee82ee));
48 bodyColours.put(ColCOL.COL_ORG, Color.orange);
49 bodyColours.put(ColCOL.COL_MAG, new Color(0xf000f0));
50 bodyColours.put(ColCOL.COL_PNK, Color.pink);
51 }
52
53 static final EnumMap<ColPAT, Patt> pattMap = new EnumMap<ColPAT, Patt>(ColPAT.class);
54 static {
55 pattMap.put(ColPAT.PAT_UNKN, Patt.Z);
56 pattMap.put(ColPAT.PAT_HORI, Patt.H);
57 pattMap.put(ColPAT.PAT_VERT, Patt.V);
58 pattMap.put(ColPAT.PAT_DIAG, Patt.D);
59 pattMap.put(ColPAT.PAT_BRDR, Patt.B);
60 pattMap.put(ColPAT.PAT_SQUR, Patt.S);
61 pattMap.put(ColPAT.PAT_CROS, Patt.C);
62 pattMap.put(ColPAT.PAT_SALT, Patt.X);
63 pattMap.put(ColPAT.PAT_STRP, Patt.H);
64 }
65
66 public enum LabelStyle { NONE, RRCT, RECT, ELPS, CIRC, VCLR, PCLR, HCLR }
67
68 static MapContext context;
69 static SeaMap map;
70 static double sScale;
71 static Graphics2D g2;
72 static int zoom;
73
74 public static void reRender(Graphics2D g, int z, double factor, SeaMap m, MapContext c) {
75 g2 = g;
76 zoom = z;
77 context = c;
78 map = m;
79 sScale = symbolScale[zoom] * factor;
80 if (map != null) {
81 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
82 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
83 g2.setStroke(new BasicStroke(0, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
84 Rules.rules(map, zoom);
85 }
86 }
87
88 public static void symbol(Feature feature, Symbol symbol) {
89 Point2D point = context.getPoint(feature.centre);
90 Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), null, null);
91 }
92 public static void symbol(Feature feature, Symbol symbol, Scheme scheme) {
93 Point2D point = context.getPoint(feature.centre);
94 Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), scheme, null);
95 }
96 public static void symbol(Feature feature, Symbol symbol, Delta delta) {
97 Point2D point = context.getPoint(feature.centre);
98 Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), null, delta);
99 }
100 public static void symbol(Feature feature, Symbol symbol, Scheme scheme, Delta delta) {
101 Point2D point = context.getPoint(feature.centre);
102 Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), scheme, delta);
103 }
104
105 public static void cluster(Feature feature, ArrayList<Symbol> symbols) {
106 Rectangle2D.Double bbox = null;
107 if (symbols.size() > 4) {
108 for (Instr instr : symbols.get(0)) {
109 if (instr.type == Prim.BBOX) {
110 bbox = (Rectangle2D.Double) instr.params;
111 break;
112 }
113 }
114 if (bbox == null) return;
115 }
116 switch (symbols.size()) {
117 case 1:
118 symbol(feature, symbols.get(0), new Delta(Handle.CC, new AffineTransform()));
119 break;
120 case 2:
121 symbol(feature, symbols.get(0), new Delta(Handle.RC, new AffineTransform()));
122 symbol(feature, symbols.get(1), new Delta(Handle.LC, new AffineTransform()));
123 break;
124 case 3:
125 symbol(feature, symbols.get(0), new Delta(Handle.BC, new AffineTransform()));
126 symbol(feature, symbols.get(1), new Delta(Handle.TR, new AffineTransform()));
127 symbol(feature, symbols.get(2), new Delta(Handle.TL, new AffineTransform()));
128 break;
129 case 4:
130 symbol(feature, symbols.get(0), new Delta(Handle.BR, new AffineTransform()));
131 symbol(feature, symbols.get(1), new Delta(Handle.BL, new AffineTransform()));
132 symbol(feature, symbols.get(2), new Delta(Handle.TR, new AffineTransform()));
133 symbol(feature, symbols.get(3), new Delta(Handle.TL, new AffineTransform()));
134 break;
135 case 5:
136 symbol(feature, symbols.get(0), new Delta(Handle.BR, new AffineTransform()));
137 symbol(feature, symbols.get(1), new Delta(Handle.BL, new AffineTransform()));
138 symbol(feature, symbols.get(2), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
139 symbol(feature, symbols.get(3), new Delta(Handle.TC, new AffineTransform()));
140 symbol(feature, symbols.get(4), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
141 break;
142 case 6:
143 symbol(feature, symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
144 symbol(feature, symbols.get(1), new Delta(Handle.BC, new AffineTransform()));
145 symbol(feature, symbols.get(2), new Delta(Handle.BL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
146 symbol(feature, symbols.get(3), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
147 symbol(feature, symbols.get(4), new Delta(Handle.TC, new AffineTransform()));
148 symbol(feature, symbols.get(5), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
149 break;
150 case 7:
151 symbol(feature, symbols.get(0), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
152 symbol(feature, symbols.get(1), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
153 symbol(feature, symbols.get(2), new Delta(Handle.CC, new AffineTransform()));
154 symbol(feature, symbols.get(3), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
155 symbol(feature, symbols.get(4), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
156 symbol(feature, symbols.get(5), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
157 symbol(feature, symbols.get(6), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
158 break;
159 case 8:
160 symbol(feature, symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
161 symbol(feature, symbols.get(1), new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
162 symbol(feature, symbols.get(2), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
163 symbol(feature, symbols.get(3), new Delta(Handle.CC, new AffineTransform()));
164 symbol(feature, symbols.get(4), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
165 symbol(feature, symbols.get(5), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
166 symbol(feature, symbols.get(6), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
167 symbol(feature, symbols.get(7), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
168 break;
169 case 9:
170 symbol(feature, symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(-bbox.width/2, -bbox.height/2)));
171 symbol(feature, symbols.get(1), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
172 symbol(feature, symbols.get(2), new Delta(Handle.BL, AffineTransform.getTranslateInstance(bbox.width/2, -bbox.height/2)));
173 symbol(feature, symbols.get(3), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
174 symbol(feature, symbols.get(4), new Delta(Handle.CC, new AffineTransform()));
175 symbol(feature, symbols.get(5), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
176 symbol(feature, symbols.get(6), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
177 symbol(feature, symbols.get(7), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
178 symbol(feature, symbols.get(8), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
179 break;
180 }
181 }
182
183 private static Rectangle2D.Double symbolSize(Symbol symbol) {
184 Symbol ssymb = symbol;
185 while (ssymb != null) {
186 for (Instr item : symbol) {
187 if (item.type == Prim.BBOX) {
188 return (Rectangle2D.Double) item.params;
189 }
190 if (item.type == Prim.SYMB) {
191 ssymb = ((SubSymbol) item.params).instr;
192 break;
193 }
194 }
195 if (ssymb == symbol)
196 break;
197 }
198 return null;
199 }
200
201 public static void lineSymbols(Feature feature, Symbol prisymb, double space, Symbol secsymb, Symbol tersymb, int ratio, Color col) {
202 Area area;
203 switch (feature.flag) {
204 case LINE:
205 Edge edge = map.edges.get(feature.refs);
206 area = map.new Area();
207 area.add(map.new Bound(map.new Side(edge, true), true));
208 break;
209 case AREA:
210 area = map.areas.get(feature.refs);
211 break;
212 default:
213 return;
214 }
215 Rectangle2D.Double prect = symbolSize(prisymb);
216 Rectangle2D.Double srect = symbolSize(secsymb);
217 Rectangle2D.Double trect = symbolSize(tersymb);
218 if (srect == null)
219 ratio = 0;
220 if (prect != null) {
221 double psize = Math.abs(prect.getY()) * sScale;
222 double ssize = (srect != null) ? Math.abs(srect.getY()) * sScale : 0;
223 double tsize = (trect != null) ? Math.abs(srect.getY()) * sScale : 0;
224 Point2D prev = new Point2D.Double();
225 Point2D next = new Point2D.Double();
226 Point2D curr = new Point2D.Double();
227 Point2D succ = new Point2D.Double();
228 boolean gap = true;
229 boolean piv = false;
230 double len = 0;
231 double angle = 0;
232 int stcount = ratio;
233 boolean stflag = false;
234 Symbol symbol = prisymb;
235 for (Bound bound : area) {
236 BoundIterator bit = map.new BoundIterator(bound);
237 boolean first = true;
238 while (bit.hasNext()) {
239 prev = next;
240 next = context.getPoint(bit.next());
241 angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
242 piv = true;
243 if (first) {
244 curr = succ = next;
245 gap = (space > 0);
246 stcount = ratio - 1;
247 symbol = prisymb;
248 len = gap ? psize * space * 0.5 : psize;
249 first = false;
250 } else {
251 while (curr.distance(next) >= len) {
252 if (piv) {
253 double rem = len;
254 double s = prev.distance(next);
255 double p = curr.distance(prev);
256 if ((s > 0) && (p > 0)) {
257 double n = curr.distance(next);
258 double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p);
259 double phi = Math.asin(p / len * Math.sin(theta));
260 rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta);
261 }
262 succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle)));
263 piv = false;
264 } else {
265 succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle)));
266 }
267 if (!gap) {
268 Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), new Scheme(col),
269 new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())) + Math.toRadians(90))));
270 }
271 if (space > 0)
272 gap = !gap;
273 curr = succ;
274 len = gap ? (psize * space) : (--stcount == 0) ? (stflag ? tsize : ssize) : psize;
275 if (stcount == 0) {
276 symbol = stflag ? tersymb : secsymb;
277 if (trect != null) stflag = !stflag;
278 stcount = ratio;
279 } else {
280 symbol = prisymb;
281 }
282 }
283 }
284 }
285 }
286 }
287 }
288
289 public static void lineVector(Feature feature, LineStyle style) {
290 Path2D.Double p = new Path2D.Double();
291 p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
292 Point2D point;
293 switch (feature.flag) {
294 case LINE:
295 EdgeIterator eit = map.new EdgeIterator(map.edges.get(feature.refs), true);
296 point = context.getPoint(eit.next());
297 p.moveTo(point.getX(), point.getY());
298 while (eit.hasNext()) {
299 point = context.getPoint(eit.next());
300 p.lineTo(point.getX(), point.getY());
301 }
302 break;
303 case AREA:
304 for (Bound bound : map.areas.get(feature.refs)) {
305 BoundIterator bit = map.new BoundIterator(bound);
306 point = context.getPoint(bit.next());
307 p.moveTo(point.getX(), point.getY());
308 while (bit.hasNext()) {
309 point = context.getPoint(bit.next());
310 p.lineTo(point.getX(), point.getY());
311 }
312 }
313 break;
314 }
315 if (style.line != null) {
316 if (style.dash != null) {
317 float[] dash = new float[style.dash.length];
318 System.arraycopy(style.dash, 0, dash, 0, style.dash.length);
319 for (int i = 0; i < style.dash.length; i++) {
320 dash[i] *= (float) sScale;
321 }
322 g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1, dash, 0));
323 } else {
324 g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
325 }
326 g2.setPaint(style.line);
327 g2.draw(p);
328 }
329 if (style.fill != null) {
330 g2.setPaint(style.fill);
331 g2.fill(p);
332 }
333 }
334
335 public static void lineCircle(Feature feature, LineStyle style, double radius, UniHLU units) {
336 switch (units) {
337 case HLU_FEET:
338 radius /= 6076;
339 break;
340 case HLU_KMTR:
341 radius /= 1.852;
342 break;
343 case HLU_HMTR:
344 radius /= 18.52;
345 break;
346 case HLU_SMIL:
347 radius /= 1.15078;
348 break;
349 case HLU_NMIL:
350 break;
351 default:
352 radius /= 1852;
353 break;
354 }
355 radius *= context.mile(feature);
356 Symbol circle = new Symbol();
357 if (style.fill != null) {
358 circle.add(new Instr(Prim.FILL, style.fill));
359 circle.add(new Instr(Prim.RSHP, new Ellipse2D.Double(-radius,-radius,radius*2,radius*2)));
360 }
361 circle.add(new Instr(Prim.FILL, style.line));
362 circle.add(new Instr(Prim.STRK, new BasicStroke(style.width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, style.dash, 0)));
363 circle.add(new Instr(Prim.ELPS, new Ellipse2D.Double(-radius,-radius,radius*2,radius*2)));
364 Point2D point = context.getPoint(feature.centre);
365 Symbols.drawSymbol(g2, circle, 1, point.getX(), point.getY(), null, null);
366 }
367
368
369 public static void fillPattern(Feature feature, BufferedImage image) {
370 Path2D.Double p = new Path2D.Double();
371 p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
372 Point2D point;
373 switch (feature.flag) {
374 case POINT:
375 point = context.getPoint(feature.centre);
376 g2.drawImage(image, new AffineTransformOp(AffineTransform.getScaleInstance(sScale, sScale), AffineTransformOp.TYPE_NEAREST_NEIGHBOR),
377 (int)(point.getX() - (50 * sScale)), (int)(point.getY() - (50 * sScale)));
378 break;
379 case AREA:
380 for (Bound bound : map.areas.get(feature.refs)) {
381 BoundIterator bit = map.new BoundIterator(bound);
382 point = context.getPoint(bit.next());
383 p.moveTo(point.getX(), point.getY());
384 while (bit.hasNext()) {
385 point = context.getPoint(bit.next());
386 p.lineTo(point.getX(), point.getY());
387 }
388 }
389 g2.setPaint(new TexturePaint(image, new Rectangle(0, 0, 1 + (int)(100 * sScale), 1 + (int)(100 * sScale))));
390 g2.fill(p);
391 break;
392 }
393 }
394
395 public static void labelText(Feature feature, String str, Font font, LabelStyle style, Color fg) {
396 labelText(feature, str, font, style, fg, null, null);
397 }
398 public static void labelText(Feature feature, String str, Font font, LabelStyle style, Color fg, Color bg) {
399 labelText(feature, str, font, style, fg, bg, null);
400 }
401 public static void labelText(Feature feature, String str, Font font, LabelStyle style, Color fg, Delta delta) {
402 labelText(feature, str, font, style, fg, null, delta);
403 }
404 public static void labelText(Feature feature, String str, Font font, LabelStyle style, Color fg, Color bg, Delta delta) {
405 if (delta == null) delta = new Delta(Handle.CC);
406 if (bg == null) bg = new Color(0x00000000, true);
407 if ((str == null) || (str.isEmpty())) str = " ";
408 FontRenderContext frc = g2.getFontRenderContext();
409 GlyphVector gv = font.deriveFont((float)(font.getSize())).createGlyphVector(frc, str.equals(" ") ? "!" : str);
410 Rectangle2D bounds = gv.getVisualBounds();
411 double width = bounds.getWidth();
412 double height = bounds.getHeight();
413 Symbol label = new Symbol();
414 double lx, ly, tx, ty;
415 switch (style) {
416 case RRCT:
417 width += height * 1.0;
418 height *= 1.5;
419 if (width < height) width = height;
420 lx = -width / 2;
421 ly = -height / 2;
422 tx = lx + (height * 0.34);
423 ty = ly + (height * 0.17);
424 label.add(new Instr(Prim.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
425 label.add(new Instr(Prim.FILL, bg));
426 label.add(new Instr(Prim.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
427 label.add(new Instr(Prim.FILL, fg));
428 label.add(new Instr(Prim.STRK, new BasicStroke(1 + (int)(height/10), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
429 label.add(new Instr(Prim.RRCT, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
430 break;
431 case VCLR:
432 width += height * 1.0;
433 height *= 2.0;
434 if (width < height) width = height;
435 lx = -width / 2;
436 ly = -height / 2;
437 tx = lx + (height * 0.27);
438 ty = ly + (height * 0.25);
439 label.add(new Instr(Prim.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
440 label.add(new Instr(Prim.FILL, bg));
441 label.add(new Instr(Prim.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
442 label.add(new Instr(Prim.FILL, fg));
443 int sw = 1 + (int)(height/10);
444 double po = sw / 2;
445 label.add(new Instr(Prim.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
446 Path2D.Double p = new Path2D.Double(); p.moveTo(-height*0.2,-ly-po); p.lineTo(height*0.2,-ly-po); p.moveTo(0,-ly-po); p.lineTo(0,-ly-po-(height*0.15));
447 p.moveTo(-height*0.2,ly+po); p.lineTo((height*0.2),ly+po); p.moveTo(0,ly+po); p.lineTo(0,ly+po+(height*0.15));
448 label.add(new Instr(Prim.PLIN, p));
449 break;
450 case PCLR:
451 width += height * 1.0;
452 height *= 2.0;
453 if (width < height) width = height;
454 lx = -width / 2;
455 ly = -height / 2;
456 tx = lx + (height * 0.27);
457 ty = ly + (height * 0.25);
458 label.add(new Instr(Prim.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
459 label.add(new Instr(Prim.FILL, bg));
460 label.add(new Instr(Prim.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
461 label.add(new Instr(Prim.FILL, fg));
462 sw = 1 + (int)(height/10);
463 po = sw / 2;
464 label.add(new Instr(Prim.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
465 p = new Path2D.Double(); p.moveTo(-height*0.2,-ly-po); p.lineTo(height*0.2,-ly-po); p.moveTo(0,-ly-po); p.lineTo(0,-ly-po-(height*0.15));
466 p.moveTo(-height*0.2,ly+po); p.lineTo((height*0.2),ly+po); p.moveTo(0,ly+po); p.lineTo(0,ly+po+(height*0.15));
467 label.add(new Instr(Prim.PLIN, p));
468 label.add(new Instr(Prim.SYMB, new Symbols.SubSymbol(Areas.CableFlash, 1, 0, 0, null, new Delta(Handle.CC, new AffineTransform(0,-1,1,0,-width/2,0)))));
469 label.add(new Instr(Prim.SYMB, new Symbols.SubSymbol(Areas.CableFlash, 1, 0, 0, null, new Delta(Handle.CC, new AffineTransform(0,-1,1,0,width/2,0)))));
470 break;
471 case HCLR:
472 width += height * 1.5;
473 height *= 1.5;
474 if (width < height) width = height;
475 lx = -width / 2;
476 ly = -height / 2;
477 tx = lx + (height * 0.5);
478 ty = ly + (height * 0.17);
479 label.add(new Instr(Prim.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
480 label.add(new Instr(Prim.FILL, bg));
481 label.add(new Instr(Prim.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
482 label.add(new Instr(Prim.FILL, fg));
483 sw = 1 + (int)(height/10);
484 double vo = height / 4;
485 label.add(new Instr(Prim.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
486 p = new Path2D.Double(); p.moveTo(-width*0.4-sw,-ly-vo); p.lineTo(-width*0.4-sw,ly+vo); p.moveTo(-width*0.4-sw,0); p.lineTo(-width*0.4+sw,0);
487 p.moveTo(width*0.4+sw,-ly-vo); p.lineTo(width*0.4+sw,ly+vo); p.moveTo(width*0.4-sw,0); p.lineTo(width*0.4+sw,0);
488 label.add(new Instr(Prim.PLIN, p));
489 break;
490 default:
491 lx = -width / 2;
492 ly = -height / 2;
493 tx = lx;
494 ty = ly;
495 label.add(new Instr(Prim.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
496 break;
497 }
498 label.add(new Instr(Prim.TEXT, new Caption(str, font, fg, new Delta(Handle.TL, AffineTransform.getTranslateInstance(tx, ty)))));
499 Point2D point = context.getPoint(feature.centre);
500 Symbols.drawSymbol(g2, label, sScale, point.getX(), point.getY(), null, delta);
501 }
502
503 public static void lineText(Feature feature, String str, Font font, Color colour, double offset, double dy) {
504 Area area;
505 switch (feature.flag) {
506 case LINE:
507 Edge edge = map.edges.get(feature.refs);
508 area = map.new Area();
509 area.add(map.new Bound(map.new Side(edge, true), true));
510 break;
511 case AREA:
512 area = map.areas.get(feature.refs);
513 break;
514 default:
515 return;
516 }
517// Rectangle prect = symbolSize(prisymb);
518 if (!str.isEmpty()) {
519 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
520 FontRenderContext frc = g2.getFontRenderContext();
521 GlyphVector gv = font.deriveFont((float)(font.getSize()*sScale)).createGlyphVector(frc, str);
522// double psize = Math.abs(prect.getX());
523 Point2D prev = new Point2D.Double();
524 Point2D next = new Point2D.Double();
525 Point2D curr = new Point2D.Double();
526 Point2D succ = new Point2D.Double();
527 boolean gap = true;
528 boolean piv = false;
529 double len = 0;
530 double angle = 0;
531 for (Bound bound : area) {
532 BoundIterator bit = map.new BoundIterator(bound);
533 boolean first = true;
534 while (bit.hasNext()) {
535 prev = next;
536 next = context.getPoint(bit.next());
537 angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
538 piv = true;
539 if (first) {
540 curr = succ = next;
541// gap = (space > 0);
542// len = gap ? psize * space * 0.5 : psize;
543 first = false;
544 } else {
545 while (curr.distance(next) >= len) {
546 if (piv) {
547 double rem = len;
548 double s = prev.distance(next);
549 double p = curr.distance(prev);
550 if ((s > 0) && (p > 0)) {
551 double n = curr.distance(next);
552 double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p);
553 double phi = Math.asin(p / len * Math.sin(theta));
554 rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta);
555 }
556 succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle)));
557 piv = false;
558 } else {
559 succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle)));
560 }
561 if (!gap) {
562// Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())) + Math.toRadians(90))), null);
563 }
564 gap = false;
565 curr = succ;
566// len = psize;
567 }
568 }
569 }
570 }
571 }
572 }
573}
Note: See TracBrowser for help on using the repository browser.