source: osm/applications/editors/josm/plugins/smed2/src/render/Renderer.java@ 30314

Last change on this file since 30314 was 30314, checked in by malcolmh, 11 years ago

save

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