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

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

save

File size: 21.1 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 }
313 if (style.line != null) {
314 if (style.dash != null) {
315 float[] dash = new float[style.dash.length];
316 System.arraycopy(style.dash, 0, dash, 0, style.dash.length);
317 for (int i = 0; i < style.dash.length; i++) {
318 dash[i] *= (float) sScale;
319 }
320 g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1, dash, 0));
321 } else {
322 g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
323 }
324 g2.setPaint(style.line);
325 g2.draw(p);
326 }
327 if (style.fill != null) {
328 g2.setPaint(style.fill);
329 g2.fill(p);
330 }
331 }
332
333 public static void lineCircle(Feature feature, LineStyle style, double radius, UniHLU units) {
334 switch (units) {
335 case HLU_FEET:
336 radius /= 6076;
337 break;
338 case HLU_KMTR:
339 radius /= 1.852;
340 break;
341 case HLU_HMTR:
342 radius /= 18.52;
343 break;
344 case HLU_SMIL:
345 radius /= 1.15078;
346 break;
347 case HLU_NMIL:
348 break;
349 default:
350 radius /= 1852;
351 break;
352 }
353 radius *= context.mile(feature);
354 Symbol circle = new Symbol();
355 if (style.fill != null) {
356 circle.add(new Instr(Prim.FILL, style.fill));
357 circle.add(new Instr(Prim.RSHP, new Ellipse2D.Double(-radius,-radius,radius*2,radius*2)));
358 }
359 circle.add(new Instr(Prim.FILL, style.line));
360 circle.add(new Instr(Prim.STRK, new BasicStroke(style.width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, style.dash, 0)));
361 circle.add(new Instr(Prim.ELPS, new Ellipse2D.Double(-radius,-radius,radius*2,radius*2)));
362 Point2D point = context.getPoint(feature.centre);
363 Symbols.drawSymbol(g2, circle, 1, point.getX(), point.getY(), null, null);
364 }
365
366
367 public static void fillPattern(Feature feature, BufferedImage image) {
368 Path2D.Double p = new Path2D.Double();
369 p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
370 Point2D point;
371 switch (feature.flag) {
372 case POINT:
373 point = context.getPoint(feature.centre);
374 g2.drawImage(image, new AffineTransformOp(AffineTransform.getScaleInstance(sScale, sScale), AffineTransformOp.TYPE_NEAREST_NEIGHBOR),
375 (int)(point.getX() - (50 * sScale)), (int)(point.getY() - (50 * sScale)));
376 break;
377 case AREA:
378 for (Bound bound : map.areas.get(feature.refs)) {
379 BoundIterator bit = map.new BoundIterator(bound);
380 point = context.getPoint(bit.next());
381 p.moveTo(point.getX(), point.getY());
382 while (bit.hasNext()) {
383 point = context.getPoint(bit.next());
384 p.lineTo(point.getX(), point.getY());
385 }
386 }
387 g2.setPaint(new TexturePaint(image, new Rectangle(0, 0, 1 + (int)(100 * sScale), 1 + (int)(100 * sScale))));
388 g2.fill(p);
389 break;
390 }
391 }
392
393 public static void labelText(Feature feature, String str, Font font, LabelStyle style, Color fg) {
394 labelText(feature, str, font, style, fg, null, null);
395 }
396 public static void labelText(Feature feature, String str, Font font, LabelStyle style, Color fg, Color bg) {
397 labelText(feature, str, font, style, fg, bg, null);
398 }
399 public static void labelText(Feature feature, String str, Font font, LabelStyle style, Color fg, Delta delta) {
400 labelText(feature, str, font, style, fg, null, delta);
401 }
402 public static void labelText(Feature feature, String str, Font font, LabelStyle style, Color fg, Color bg, Delta delta) {
403 if (delta == null) delta = new Delta(Handle.CC);
404 if (bg == null) bg = new Color(0x00000000, true);
405 if ((str == null) || (str.isEmpty())) str = " ";
406 FontRenderContext frc = g2.getFontRenderContext();
407 GlyphVector gv = font.deriveFont((float)(font.getSize())).createGlyphVector(frc, str.equals(" ") ? "!" : str);
408 Rectangle2D bounds = gv.getVisualBounds();
409 double width = bounds.getWidth();
410 double height = bounds.getHeight();
411 Symbol label = new Symbol();
412 double lx, ly, tx, ty;
413 switch (style) {
414 case RRCT:
415 width += height * 1.0;
416 height *= 1.5;
417 if (width < height) width = height;
418 lx = -width / 2;
419 ly = -height / 2;
420 tx = lx + (height * 0.34);
421 ty = ly + (height * 0.17);
422 label.add(new Instr(Prim.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
423 label.add(new Instr(Prim.FILL, bg));
424 label.add(new Instr(Prim.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
425 label.add(new Instr(Prim.FILL, fg));
426 label.add(new Instr(Prim.STRK, new BasicStroke(1 + (int)(height/10), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
427 label.add(new Instr(Prim.RRCT, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
428 break;
429 case VCLR:
430 width += height * 1.0;
431 height *= 2.0;
432 if (width < height) width = height;
433 lx = -width / 2;
434 ly = -height / 2;
435 tx = lx + (height * 0.27);
436 ty = ly + (height * 0.25);
437 label.add(new Instr(Prim.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
438 label.add(new Instr(Prim.FILL, bg));
439 label.add(new Instr(Prim.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
440 label.add(new Instr(Prim.FILL, fg));
441 int sw = 1 + (int)(height/10);
442 double po = sw / 2;
443 label.add(new Instr(Prim.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
444 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));
445 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));
446 label.add(new Instr(Prim.PLIN, p));
447 break;
448 default:
449 lx = -width / 2;
450 ly = -height / 2;
451 tx = lx;
452 ty = ly;
453 label.add(new Instr(Prim.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
454 break;
455 }
456 label.add(new Instr(Prim.TEXT, new Caption(str, font, fg, new Delta(Handle.TL, AffineTransform.getTranslateInstance(tx, ty)))));
457 Point2D point = context.getPoint(feature.centre);
458 Symbols.drawSymbol(g2, label, sScale, point.getX(), point.getY(), null, delta);
459 }
460
461 public static void lineText(Feature feature, String str, Font font, Color colour, double offset, double dy) {
462 Area area;
463 switch (feature.flag) {
464 case LINE:
465 Edge edge = map.edges.get(feature.refs);
466 area = map.new Area();
467 area.add(map.new Bound(map.new Side(edge, true), true));
468 break;
469 case AREA:
470 area = map.areas.get(feature.refs);
471 break;
472 default:
473 return;
474 }
475// Rectangle prect = symbolSize(prisymb);
476 if (!str.isEmpty()) {
477 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
478 FontRenderContext frc = g2.getFontRenderContext();
479 GlyphVector gv = font.deriveFont((float)(font.getSize()*sScale)).createGlyphVector(frc, str);
480// double psize = Math.abs(prect.getX());
481 Point2D prev = new Point2D.Double();
482 Point2D next = new Point2D.Double();
483 Point2D curr = new Point2D.Double();
484 Point2D succ = new Point2D.Double();
485 boolean gap = true;
486 boolean piv = false;
487 double len = 0;
488 double angle = 0;
489 for (Bound bound : area) {
490 BoundIterator bit = map.new BoundIterator(bound);
491 boolean first = true;
492 while (bit.hasNext()) {
493 prev = next;
494 next = context.getPoint(bit.next());
495 angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
496 piv = true;
497 if (first) {
498 curr = succ = next;
499// gap = (space > 0);
500// len = gap ? psize * space * 0.5 : psize;
501 first = false;
502 } else {
503 while (curr.distance(next) >= len) {
504 if (piv) {
505 double rem = len;
506 double s = prev.distance(next);
507 double p = curr.distance(prev);
508 if ((s > 0) && (p > 0)) {
509 double n = curr.distance(next);
510 double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p);
511 double phi = Math.asin(p / len * Math.sin(theta));
512 rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta);
513 }
514 succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle)));
515 piv = false;
516 } else {
517 succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle)));
518 }
519 if (!gap) {
520// 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);
521 }
522 gap = false;
523 curr = succ;
524// len = psize;
525 }
526 }
527 }
528 }
529 }
530 }
531}
Note: See TracBrowser for help on using the repository browser.