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

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

save

File size: 21.2 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.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 public static final Color Yland = new Color(0x50b0ff);
30 public static final Color Mline = new Color(0x80c480);
31 public static final Color Msymb = new Color(0xa30075);
32
33 static final EnumMap<ColCOL, Color> bodyColours = new EnumMap<ColCOL, Color>(ColCOL.class);
34 static {
35 bodyColours.put(ColCOL.COL_UNK, new Color(0, true));
36 bodyColours.put(ColCOL.COL_WHT, new Color(0xffffff));
37 bodyColours.put(ColCOL.COL_BLK, new Color(0x000000));
38 bodyColours.put(ColCOL.COL_RED, new Color(0xd40000));
39 bodyColours.put(ColCOL.COL_GRN, new Color(0x00d400));
40 bodyColours.put(ColCOL.COL_BLU, Color.blue);
41 bodyColours.put(ColCOL.COL_YEL, new Color(0xffd400));
42 bodyColours.put(ColCOL.COL_GRY, Color.gray);
43 bodyColours.put(ColCOL.COL_BRN, new Color(0x8b4513));
44 bodyColours.put(ColCOL.COL_AMB, new Color(0xfbf00f));
45 bodyColours.put(ColCOL.COL_VIO, new Color(0xee82ee));
46 bodyColours.put(ColCOL.COL_ORG, Color.orange);
47 bodyColours.put(ColCOL.COL_MAG, new Color(0xf000f0));
48 bodyColours.put(ColCOL.COL_PNK, Color.pink);
49 }
50
51 static final EnumMap<ColPAT, Patt> pattMap = new EnumMap<ColPAT, Patt>(ColPAT.class);
52 static {
53 pattMap.put(ColPAT.PAT_UNKN, Patt.Z);
54 pattMap.put(ColPAT.PAT_HORI, Patt.H);
55 pattMap.put(ColPAT.PAT_VERT, Patt.V);
56 pattMap.put(ColPAT.PAT_DIAG, Patt.D);
57 pattMap.put(ColPAT.PAT_BRDR, Patt.B);
58 pattMap.put(ColPAT.PAT_SQUR, Patt.S);
59 pattMap.put(ColPAT.PAT_CROS, Patt.C);
60 pattMap.put(ColPAT.PAT_SALT, Patt.X);
61 pattMap.put(ColPAT.PAT_STRP, Patt.H);
62 }
63
64 public enum LabelStyle { NONE, RRCT, RECT, ELPS, CIRC, VCLR, HCLR }
65
66 static MapContext context;
67 static SeaMap map;
68 static double sScale;
69 static Graphics2D g2;
70 static int zoom;
71
72 public static void reRender(Graphics2D g, int z, double factor, SeaMap m, MapContext c) {
73 g2 = g;
74 zoom = z;
75 context = c;
76 map = m;
77 sScale = symbolScale[zoom] * factor;
78 if (map != null) {
79 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
80 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
81 g2.setStroke(new BasicStroke(0, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
82 Rules.rules(map, zoom);
83 }
84 }
85
86 public static void symbol(Feature feature, Symbol symbol) {
87 Point2D point = context.getPoint(feature.centre);
88 Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), null, null);
89 }
90 public static void symbol(Feature feature, Symbol symbol, Scheme scheme) {
91 Point2D point = context.getPoint(feature.centre);
92 Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), scheme, null);
93 }
94 public static void symbol(Feature feature, Symbol symbol, Delta delta) {
95 Point2D point = context.getPoint(feature.centre);
96 Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), null, delta);
97 }
98 public static void symbol(Feature feature, Symbol symbol, Scheme scheme, Delta delta) {
99 Point2D point = context.getPoint(feature.centre);
100 Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), scheme, delta);
101 }
102
103 public static void cluster(Feature feature, ArrayList<Symbol> symbols) {
104 Rectangle2D.Double bbox = null;
105 if (symbols.size() > 4) {
106 for (Instr instr : symbols.get(0)) {
107 if (instr.type == Prim.BBOX) {
108 bbox = (Rectangle2D.Double) instr.params;
109 break;
110 }
111 }
112 if (bbox == null) return;
113 }
114 switch (symbols.size()) {
115 case 1:
116 symbol(feature, symbols.get(0), new Delta(Handle.CC, new AffineTransform()));
117 break;
118 case 2:
119 symbol(feature, symbols.get(0), new Delta(Handle.RC, new AffineTransform()));
120 symbol(feature, symbols.get(1), new Delta(Handle.LC, new AffineTransform()));
121 break;
122 case 3:
123 symbol(feature, symbols.get(0), new Delta(Handle.BC, new AffineTransform()));
124 symbol(feature, symbols.get(1), new Delta(Handle.TR, new AffineTransform()));
125 symbol(feature, symbols.get(2), new Delta(Handle.TL, new AffineTransform()));
126 break;
127 case 4:
128 symbol(feature, symbols.get(0), new Delta(Handle.BR, new AffineTransform()));
129 symbol(feature, symbols.get(1), new Delta(Handle.BL, new AffineTransform()));
130 symbol(feature, symbols.get(2), new Delta(Handle.TR, new AffineTransform()));
131 symbol(feature, symbols.get(3), new Delta(Handle.TL, new AffineTransform()));
132 break;
133 case 5:
134 symbol(feature, symbols.get(0), new Delta(Handle.BR, new AffineTransform()));
135 symbol(feature, symbols.get(1), new Delta(Handle.BL, new AffineTransform()));
136 symbol(feature, symbols.get(2), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
137 symbol(feature, symbols.get(3), new Delta(Handle.TC, new AffineTransform()));
138 symbol(feature, symbols.get(4), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
139 break;
140 case 6:
141 symbol(feature, symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
142 symbol(feature, symbols.get(1), new Delta(Handle.BC, new AffineTransform()));
143 symbol(feature, symbols.get(2), new Delta(Handle.BL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
144 symbol(feature, symbols.get(3), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
145 symbol(feature, symbols.get(4), new Delta(Handle.TC, new AffineTransform()));
146 symbol(feature, symbols.get(5), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
147 break;
148 case 7:
149 symbol(feature, symbols.get(0), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
150 symbol(feature, symbols.get(1), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
151 symbol(feature, symbols.get(2), new Delta(Handle.CC, new AffineTransform()));
152 symbol(feature, symbols.get(3), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
153 symbol(feature, symbols.get(4), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
154 symbol(feature, symbols.get(5), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
155 symbol(feature, symbols.get(6), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
156 break;
157 case 8:
158 symbol(feature, symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
159 symbol(feature, symbols.get(1), new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
160 symbol(feature, symbols.get(2), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
161 symbol(feature, symbols.get(3), new Delta(Handle.CC, new AffineTransform()));
162 symbol(feature, symbols.get(4), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
163 symbol(feature, symbols.get(5), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
164 symbol(feature, symbols.get(6), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
165 symbol(feature, symbols.get(7), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
166 break;
167 case 9:
168 symbol(feature, symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(-bbox.width/2, -bbox.height/2)));
169 symbol(feature, symbols.get(1), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
170 symbol(feature, symbols.get(2), new Delta(Handle.BL, AffineTransform.getTranslateInstance(bbox.width/2, -bbox.height/2)));
171 symbol(feature, symbols.get(3), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
172 symbol(feature, symbols.get(4), new Delta(Handle.CC, new AffineTransform()));
173 symbol(feature, symbols.get(5), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
174 symbol(feature, symbols.get(6), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
175 symbol(feature, symbols.get(7), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
176 symbol(feature, symbols.get(8), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
177 break;
178 }
179 }
180
181 private static Rectangle2D.Double symbolSize(Symbol symbol) {
182 Symbol ssymb = symbol;
183 while (ssymb != null) {
184 for (Instr item : symbol) {
185 if (item.type == Prim.BBOX) {
186 return (Rectangle2D.Double) item.params;
187 }
188 if (item.type == Prim.SYMB) {
189 ssymb = ((SubSymbol) item.params).instr;
190 break;
191 }
192 }
193 if (ssymb == symbol)
194 break;
195 }
196 return null;
197 }
198
199 public static void lineSymbols(Feature feature, Symbol prisymb, double space, Symbol secsymb, Symbol tersymb, int ratio, Color col) {
200 Area area;
201 switch (feature.flag) {
202 case LINE:
203 Edge edge = map.edges.get(feature.refs);
204 area = map.new Area();
205 area.add(map.new Bound(map.new Side(edge, true), true));
206 break;
207 case AREA:
208 area = map.areas.get(feature.refs);
209 break;
210 default:
211 return;
212 }
213 Rectangle2D.Double prect = symbolSize(prisymb);
214 Rectangle2D.Double srect = symbolSize(secsymb);
215 Rectangle2D.Double trect = symbolSize(tersymb);
216 if (srect == null)
217 ratio = 0;
218 if (prect != null) {
219 double psize = Math.abs(prect.getY()) * sScale;
220 double ssize = (srect != null) ? Math.abs(srect.getY()) * sScale : 0;
221 double tsize = (trect != null) ? Math.abs(srect.getY()) * sScale : 0;
222 Point2D prev = new Point2D.Double();
223 Point2D next = new Point2D.Double();
224 Point2D curr = new Point2D.Double();
225 Point2D succ = new Point2D.Double();
226 boolean gap = true;
227 boolean piv = false;
228 double len = 0;
229 double angle = 0;
230 int stcount = ratio;
231 boolean stflag = false;
232 Symbol symbol = prisymb;
233 for (Bound bound : area) {
234 BoundIterator bit = map.new BoundIterator(bound);
235 boolean first = true;
236 while (bit.hasNext()) {
237 prev = next;
238 next = context.getPoint(bit.next());
239 angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
240 piv = true;
241 if (first) {
242 curr = succ = next;
243 gap = (space > 0);
244 stcount = ratio - 1;
245 symbol = prisymb;
246 len = gap ? psize * space * 0.5 : psize;
247 first = false;
248 } else {
249 while (curr.distance(next) >= len) {
250 if (piv) {
251 double rem = len;
252 double s = prev.distance(next);
253 double p = curr.distance(prev);
254 if ((s > 0) && (p > 0)) {
255 double n = curr.distance(next);
256 double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p);
257 double phi = Math.asin(p / len * Math.sin(theta));
258 rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta);
259 }
260 succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle)));
261 piv = false;
262 } else {
263 succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle)));
264 }
265 if (!gap) {
266 Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), new Scheme(col),
267 new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())) + Math.toRadians(90))));
268 }
269 if (space > 0)
270 gap = !gap;
271 curr = succ;
272 len = gap ? (psize * space) : (--stcount == 0) ? (stflag ? tsize : ssize) : psize;
273 if (stcount == 0) {
274 symbol = stflag ? tersymb : secsymb;
275 if (trect != null) stflag = !stflag;
276 stcount = ratio;
277 } else {
278 symbol = prisymb;
279 }
280 }
281 }
282 }
283 }
284 }
285 }
286
287 public static void lineVector(Feature feature, LineStyle style) {
288 Path2D.Double p = new Path2D.Double();
289 p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
290 Point2D point;
291 switch (feature.flag) {
292 case LINE:
293 EdgeIterator eit = map.new EdgeIterator(map.edges.get(feature.refs), true);
294 point = context.getPoint(eit.next());
295 p.moveTo(point.getX(), point.getY());
296 while (eit.hasNext()) {
297 point = context.getPoint(eit.next());
298 p.lineTo(point.getX(), point.getY());
299 }
300 break;
301 case AREA:
302 for (Bound bound : map.areas.get(feature.refs)) {
303 BoundIterator bit = map.new BoundIterator(bound);
304 point = context.getPoint(bit.next());
305 p.moveTo(point.getX(), point.getY());
306 while (bit.hasNext()) {
307 point = context.getPoint(bit.next());
308 p.lineTo(point.getX(), point.getY());
309 }
310 }
311 break;
312 default:
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 default:
393 break;
394 }
395 }
396
397 public static void labelText(Feature feature, String str, Font font, LabelStyle style, Color fg) {
398 labelText(feature, str, font, style, fg, null, null);
399 }
400 public static void labelText(Feature feature, String str, Font font, LabelStyle style, Color fg, Color bg) {
401 labelText(feature, str, font, style, fg, bg, null);
402 }
403 public static void labelText(Feature feature, String str, Font font, LabelStyle style, Color fg, Delta delta) {
404 labelText(feature, str, font, style, fg, null, delta);
405 }
406 public static void labelText(Feature feature, String str, Font font, LabelStyle style, Color fg, Color bg, Delta delta) {
407 if (delta == null) delta = new Delta(Handle.CC);
408 if (bg == null) bg = new Color(0x00000000, true);
409 if ((str == null) || (str.isEmpty())) str = " ";
410 FontRenderContext frc = g2.getFontRenderContext();
411 GlyphVector gv = font.deriveFont((float)(font.getSize())).createGlyphVector(frc, str.equals(" ") ? "!" : str);
412 Rectangle2D bounds = gv.getVisualBounds();
413 double width = bounds.getWidth();
414 double height = bounds.getHeight();
415 Symbol label = new Symbol();
416 double lx, ly, tx, ty;
417 switch (style) {
418 case RRCT:
419 width += height * 1.0;
420 height *= 1.5;
421 if (width < height) width = height;
422 lx = -width / 2;
423 ly = -height / 2;
424 tx = lx + (height * 0.34);
425 ty = ly + (height * 0.17);
426 label.add(new Instr(Prim.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
427 label.add(new Instr(Prim.FILL, bg));
428 label.add(new Instr(Prim.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
429 label.add(new Instr(Prim.FILL, fg));
430 label.add(new Instr(Prim.STRK, new BasicStroke(1 + (int)(height/10), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
431 label.add(new Instr(Prim.RRCT, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
432 break;
433 case VCLR:
434 width += height * 1.0;
435 height *= 2.0;
436 if (width < height) width = height;
437 lx = -width / 2;
438 ly = -height / 2;
439 tx = lx + (height * 0.27);
440 ty = ly + (height * 0.25);
441 label.add(new Instr(Prim.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
442 label.add(new Instr(Prim.FILL, bg));
443 label.add(new Instr(Prim.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
444 label.add(new Instr(Prim.FILL, fg));
445 int sw = 1 + (int)(height/10);
446 double po = sw / 2;
447 label.add(new Instr(Prim.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
448 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));
449 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));
450 label.add(new Instr(Prim.PLIN, p));
451 break;
452 default:
453 lx = -width / 2;
454 ly = -height / 2;
455 tx = lx;
456 ty = ly;
457 label.add(new Instr(Prim.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
458 break;
459 }
460 label.add(new Instr(Prim.TEXT, new Caption(str, font, fg, new Delta(Handle.TL, AffineTransform.getTranslateInstance(tx, ty)))));
461 Point2D point = context.getPoint(feature.centre);
462 Symbols.drawSymbol(g2, label, sScale, point.getX(), point.getY(), null, delta);
463 }
464
465 public static void lineText(Feature feature, String str, Font font, Color colour, double offset, double dy) {
466 Area area;
467 switch (feature.flag) {
468 case LINE:
469 Edge edge = map.edges.get(feature.refs);
470 area = map.new Area();
471 area.add(map.new Bound(map.new Side(edge, true), true));
472 break;
473 case AREA:
474 area = map.areas.get(feature.refs);
475 break;
476 default:
477 return;
478 }
479// Rectangle prect = symbolSize(prisymb);
480 if (!str.isEmpty()) {
481 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
482 FontRenderContext frc = g2.getFontRenderContext();
483 GlyphVector gv = font.deriveFont((float)(font.getSize()*sScale)).createGlyphVector(frc, str);
484// double psize = Math.abs(prect.getX());
485 Point2D prev = new Point2D.Double();
486 Point2D next = new Point2D.Double();
487 Point2D curr = new Point2D.Double();
488 Point2D succ = new Point2D.Double();
489 boolean gap = true;
490 boolean piv = false;
491 double len = 0;
492 double angle = 0;
493 for (Bound bound : area) {
494 BoundIterator bit = map.new BoundIterator(bound);
495 boolean first = true;
496 while (bit.hasNext()) {
497 prev = next;
498 next = context.getPoint(bit.next());
499 angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
500 piv = true;
501 if (first) {
502 curr = succ = next;
503// gap = (space > 0);
504// len = gap ? psize * space * 0.5 : psize;
505 first = false;
506 } else {
507 while (curr.distance(next) >= len) {
508 if (piv) {
509 double rem = len;
510 double s = prev.distance(next);
511 double p = curr.distance(prev);
512 if ((s > 0) && (p > 0)) {
513 double n = curr.distance(next);
514 double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p);
515 double phi = Math.asin(p / len * Math.sin(theta));
516 rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta);
517 }
518 succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle)));
519 piv = false;
520 } else {
521 succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle)));
522 }
523 if (!gap) {
524// 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);
525 }
526 gap = false;
527 curr = succ;
528// len = psize;
529 }
530 }
531 }
532 }
533 }
534 }
535}
Note: See TracBrowser for help on using the repository browser.