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