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