Changeset 32380 in osm for applications/editors/josm/plugins/seachart/src/render
- Timestamp:
- 2016-06-23T14:17:55+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/seachart/src/render
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified applications/editors/josm/plugins/seachart/src/render/Renderer.java ¶
r32101 r32380 391 391 if ((str == null) || (str.isEmpty())) str = " "; 392 392 FontRenderContext frc = g2.getFontRenderContext(); 393 GlyphVector gv = font.deriveFont((float)(font.getSize())).createGlyphVector(frc, str.equals(" ") ? " !" : str);393 GlyphVector gv = font.deriveFont((float)(font.getSize())).createGlyphVector(frc, str.equals(" ") ? "M" : str); 394 394 Rectangle2D bounds = gv.getVisualBounds(); 395 395 double width = bounds.getWidth(); … … 485 485 } 486 486 487 public static void lineText(String str, Font font, Color colour, double offset, doubledy) {487 public static void lineText(String str, Font font, Color colour, double dy) { 488 488 if (!str.isEmpty()) { 489 489 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 490 g2.setPaint(colour); 491 FontRenderContext frc = g2.getFontRenderContext(); 492 GlyphVector gv = font.deriveFont(font.getSize2D() * (float)sScale).createGlyphVector(frc, (" " + str)); 493 GeneralPath path = new GeneralPath(); 494 Point2D prev = new Point2D.Double(); 495 Point2D next = new Point2D.Double(); 496 Point2D curr = new Point2D.Double(); 497 Point2D succ = new Point2D.Double(); 498 boolean piv = false; 499 double angle = 0; 500 int index = 0; 501 double gwidth = offset * (Rules.feature.geom.length * context.mile(Rules.feature) - gv.getLogicalBounds().getWidth()) + gv.getGlyphMetrics(0).getAdvance(); 502 GeomIterator git = map.new GeomIterator(Rules.feature.geom); 503 while (git.hasComp()) { 504 git.nextComp(); 505 boolean first = true; 506 while (git.hasEdge()) { 507 git.nextEdge(); 508 while (git.hasNode()) { 509 Snode node = git.next(); 510 if (node == null) continue; 511 prev = next; 512 next = context.getPoint(node); 513 angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX()); 514 piv = true; 515 if (first) { 516 curr = succ = next; 517 first = false; 518 } else { 519 while (curr.distance(next) >= gwidth) { 520 if (piv) { 521 double rem = gwidth; 522 double s = prev.distance(next); 523 double p = curr.distance(prev); 524 if ((s > 0) && (p > 0)) { 525 double n = curr.distance(next); 526 double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p); 527 double phi = Math.asin(p / gwidth * Math.sin(theta)); 528 rem = gwidth * Math.sin(Math.PI - theta - phi) / Math.sin(theta); 529 } 530 succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle))); 531 piv = false; 490 g2.setPaint(colour); 491 FontRenderContext frc = g2.getFontRenderContext(); 492 GlyphVector gv = font.deriveFont(font.getSize2D() * (float) sScale).createGlyphVector(frc, str); 493 double width = gv.getVisualBounds().getWidth(); 494 double height = gv.getVisualBounds().getHeight(); 495 double offset = (Rules.feature.geom.length * context.mile(Rules.feature) - width) / 2; 496 if (offset > 0) { 497 Point2D before = null; 498 Point2D after = null; 499 ArrayList<Point2D> between = new ArrayList<>(); 500 Point2D prev = null; 501 Point2D next = null; 502 double length = 0; 503 double lb = 0; 504 double la = 0; 505 GeomIterator git = map.new GeomIterator(Rules.feature.geom); 506 if (git.hasComp()) { 507 git.nextComp(); 508 while (git.hasEdge()) { 509 git.nextEdge(); 510 while (git.hasNode()) { 511 Snode node = git.next(); 512 if (node == null) 513 continue; 514 prev = next; 515 next = context.getPoint(node); 516 if (prev != null) 517 length += Math.sqrt(Math.pow((next.getX() - prev.getX()), 2) + Math.pow((next.getY() - prev.getY()), 2)); 518 if (length < offset) { 519 before = next; 520 lb = la = length; 521 } else if (after == null) { 522 if (length > (offset + width)) { 523 after = next; 524 la = length; 525 break; 532 526 } else { 533 succ = new Point2D.Double(curr.getX() + (gwidth * Math.cos(angle)), curr.getY() + (gwidth * Math.sin(angle))); 534 } 535 Shape shape = gv.getGlyphOutline(index); 536 Point2D point = gv.getGlyphPosition(index); 537 AffineTransform at = AffineTransform.getTranslateInstance(curr.getX(), curr.getY()); 538 at.rotate(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX()))); 539 at.translate(-point.getX(), -point.getY() + (dy * sScale)); 540 path.append(at.createTransformedShape(shape), false); 541 curr = succ; 542 if (++index < gv.getNumGlyphs()) { 543 gwidth = gv.getGlyphMetrics(index).getAdvance(); 544 } else { 545 g2.fill(path); 546 return; 527 between.add(next); 547 528 } 548 529 } 549 530 } 531 if (after != null) 532 break; 550 533 } 534 } 535 if (after != null) { 536 double angle = Math.atan2((after.getY() - before.getY()), (after.getX() - before.getX())); 537 double rotate = Math.abs(angle) < (Math.PI / 2) ? angle : angle + Math.PI; 538 Point2D mid = new Point2D.Double((before.getX() + after.getX()) / 2, (before.getY() + after.getY()) / 2); 539 Point2D centre = context.getPoint(Rules.feature.geom.centre); 540 AffineTransform pos = AffineTransform.getTranslateInstance(-dy * Math.sin(rotate), dy * Math.cos(rotate)); 541 pos.rotate(rotate); 542 pos.translate((mid.getX() - centre.getX()), (mid.getY() - centre.getY())); 543 Symbol label = new Symbol(); 544 label.add(new Instr(Form.BBOX, new Rectangle2D.Double((-width / 2), (-height), width, height))); 545 label.add(new Instr(Form.TEXT, new Caption(str, font, colour, new Delta(Handle.BC)))); 546 Symbols.drawSymbol(g2, label, sScale, centre.getX(), centre.getY(), null, new Delta(Handle.BC, pos)); 551 547 } 552 548 } … … 580 576 } 581 577 if ((str != null) && (!str.isEmpty())) { 582 FontRenderContext frc = g2.getFontRenderContext();583 578 Font font = new Font("Arial", Font.PLAIN, 40); 584 GlyphVector gv = font.deriveFont(font.getSize2D() * (float)sScale).createGlyphVector(frc, str);585 579 double arc = (s2 > s1) ? (s2 - s1) : (s2 - s1 + 360); 586 580 double awidth = (Math.toRadians(arc) * radial); … … 589 583 radial += 30 * sScale; 590 584 AffineTransform at = AffineTransform.getTranslateInstance(-radial * Math.sin(phi) / sScale, radial * Math.cos(phi) / sScale); 591 if ( gv.getLogicalBounds().getWidth() < awidth) {585 if ((font.getSize() * sScale * str.length()) < awidth) { 592 586 at.rotate(Math.toRadians(mid + (hand ? 0 : 180))); 593 Renderer.labelText(str, font, Color.black, new Delta(Handle.CC, at));594 } else if ( gv.getLogicalBounds().getHeight() < awidth) {587 labelText(str, font, Color.black, new Delta(Handle.CC, at)); 588 } else if ((font.getSize() * sScale) < awidth) { 595 589 hand = (mid < 180); 596 590 at.rotate(Math.toRadians(mid + (hand ? -90 : 90))); 597 Renderer.labelText(str, font, Color.black, hand ? new Delta(Handle.RC, at) : new Delta(Handle.LC, at));591 labelText(str, font, Color.black, hand ? new Delta(Handle.RC, at) : new Delta(Handle.LC, at)); 598 592 } 599 593 if (dir != null) { … … 605 599 at = AffineTransform.getTranslateInstance(-radial * Math.sin(phi) / sScale, radial * Math.cos(phi) / sScale); 606 600 at.rotate(Math.toRadians(dir + (hand ? 90 : -90))); 607 Renderer.labelText(str, font, Color.black, hand ? new Delta(Handle.BR, at) : new Delta(Handle.BL, at));601 labelText(str, font, Color.black, hand ? new Delta(Handle.BR, at) : new Delta(Handle.BL, at)); 608 602 } 609 603 } -
TabularUnified applications/editors/josm/plugins/seachart/src/render/Rules.java ¶
r32105 r32380 215 215 if (testObject(Obj.ROADWY)) for (Feature f : objects) if (testFeature(f)) highways(); 216 216 if (testObject(Obj.RAILWY)) for (Feature f : objects) if (testFeature(f)) highways(); 217 } 218 if (Renderer.context.ruleset() == RuleSet.ALL) { 219 if (testObject(Obj.SOUNDG)) for (Feature f : objects) if (testFeature(f)) depths(); 220 if (testObject(Obj.DEPCNT)) for (Feature f : objects) if (testFeature(f)) depths(); 217 221 } 218 222 if (testObject(Obj.SLCONS)) for (Feature f : objects) if (testFeature(f)) shoreline(); … … 388 392 if ((Renderer.zoom >= 10) && (name != null)) 389 393 if (feature.geom.prim == Pflag.LINE) { 390 Renderer.lineText(name, new Font("Arial", Font.PLAIN, 150), Color.black, 0.5,-40);394 Renderer.lineText(name, new Font("Arial", Font.PLAIN, 150), Color.black, -40); 391 395 } else { 392 396 Renderer.labelText(name, new Font("Arial", Font.PLAIN, 150), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -40))); … … 396 400 if ((Renderer.zoom >= 12) && (name != null)) 397 401 if (feature.geom.prim == Pflag.LINE) { 398 Renderer.lineText(name, new Font("Arial", Font.PLAIN, 150), Color.black, 0.5,-40);402 Renderer.lineText(name, new Font("Arial", Font.PLAIN, 150), Color.black, -40); 399 403 } else { 400 404 Renderer.labelText(name, new Font("Arial", Font.PLAIN, 150), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -40))); … … 411 415 } else if (feature.geom.prim == Pflag.LINE) { 412 416 if (name != null) { 413 Renderer.lineText(name, new Font("Arial", Font.ITALIC, 75), Color.black, 0.5,-40);414 Renderer.lineText("(Shoal)", new Font("Arial", Font.PLAIN, 60), Color.black, 0 .5, 0);417 Renderer.lineText(name, new Font("Arial", Font.ITALIC, 75), Color.black, -40); 418 Renderer.lineText("(Shoal)", new Font("Arial", Font.PLAIN, 60), Color.black, 0); 415 419 } 416 420 } else { … … 503 507 } 504 508 } 509 if (hasObject(Obj.NOTMRK)) 510 notices(); 505 511 addName(15, new Font("Arial", Font.BOLD, 40), new Delta(Handle.BL, AffineTransform.getTranslateInstance(60, -50))); 506 512 Signals.addSignals(); … … 608 614 Renderer.labelText(("Ch." + chn), new Font("Arial", Font.PLAIN, 50), Color.black, new Delta(Handle.TC, AffineTransform.getTranslateInstance(0,50))); 609 615 } 616 } 617 } 618 619 private static void depths() { 620 switch (feature.type) { 621 case SOUNDG: 622 if ((Renderer.zoom >= 14) && hasAttribute(Obj.SOUNDG, Att.VALSOU)) { 623 double depth = (double)getAttVal(Obj.SOUNDG, Att.VALSOU); 624 String dstr = df.format(depth); 625 String tok[] = dstr.split("[-.]"); 626 String ul = ""; 627 String id = tok[0]; 628 String dd = ""; 629 if (tok[0].equals("")) { 630 for (int i = 0; i < tok[1].length(); i++) 631 ul += "_"; 632 id = tok[1]; 633 dd = (tok.length == 3) ? tok[2] : ""; 634 } else { 635 dd = (tok.length == 2) ? tok[1] : ""; 636 } 637 Renderer.labelText(ul, new Font("Arial", Font.PLAIN, 30), Color.black, new Delta(Handle.RC, AffineTransform.getTranslateInstance(10,15))); 638 Renderer.labelText(id, new Font("Arial", Font.PLAIN, 30), Color.black, new Delta(Handle.RC, AffineTransform.getTranslateInstance(10,0))); 639 Renderer.labelText(dd, new Font("Arial", Font.PLAIN, 20), Color.black, new Delta(Handle.LC, AffineTransform.getTranslateInstance(15,10))); 640 } 641 break; 642 case DEPCNT: 643 break; 644 default: 645 break; 610 646 } 611 647 } … … 700 736 case ACHBRT: 701 737 if (Renderer.zoom >= 14) { 702 Renderer.symbol(Harbours.Anchor age, new Scheme(Symbols.Mline));738 Renderer.symbol(Harbours.Anchor, new Scheme(Symbols.Msymb)); 703 739 if (Renderer.zoom >= 15) { 704 Renderer.labelText(name == null ? "" : name, new Font("Arial", Font.PLAIN, 30), Symbols.Msymb, LabelStyle.RRCT, Symbols.M line, Color.white, new Delta(Handle.BC));740 Renderer.labelText(name == null ? "" : name, new Font("Arial", Font.PLAIN, 30), Symbols.Msymb, LabelStyle.RRCT, Symbols.Msymb, Color.white, new Delta(Handle.BC)); 705 741 } 706 742 } … … 993 1029 } 994 1030 1031 @SuppressWarnings("unchecked") 995 1032 private static void notices() { 996 1033 if (Renderer.zoom >= 14) { … … 1002 1039 case BCNSAW: 1003 1040 case BCNSPP: 1004 dy = 45.0; 1041 if (testAttribute(Obj.TOPMAR, Att.TOPSHP, TopSHP.TOP_BORD) || testAttribute(Obj.DAYMAR, Att.TOPSHP, TopSHP.TOP_BORD)) { 1042 dy = -100.0; 1043 } else { 1044 dy = -45.0; 1045 } 1005 1046 break; 1006 1047 case NOTMRK: … … 1023 1064 int i = 0; 1024 1065 for (AttMap atts : objs.values()) { 1025 if (atts.get(Att.MARSYS) != null) sys = ( MarSYS)(getAttEnum(Obj.NOTMRK,Att.MARSYS));1026 if (atts.get(Att.BNKWTW) != null) bnk = ( BnkWTW)(getAttEnum(Obj.NOTMRK,Att.BNKWTW));1066 if (atts.get(Att.MARSYS) != null) sys = ((ArrayList<MarSYS>)(atts.get(Att.MARSYS).val)).get(0); 1067 if (atts.get(Att.BNKWTW) != null) bnk = ((ArrayList<BnkWTW>)(atts.get(Att.BNKWTW).val)).get(0); 1027 1068 CatNMK cat = CatNMK.NMK_UNKN; 1028 if (atts.get(Att.CATNMK) != null) cat = ( CatNMK)(getAttEnum(Obj.NOTMRK,Att.CATNMK));1069 if (atts.get(Att.CATNMK) != null) cat = ((ArrayList<CatNMK>)(atts.get(Att.CATNMK).val)).get(0); 1029 1070 Symbol sym = Notices.getNotice(cat, sys, bnk); 1030 1071 Scheme sch = Notices.getScheme(sys, bnk); 1072 ArrayList<AddMRK> add = new ArrayList<>(); 1073 if (atts.get(Att.ADDMRK) != null) add = (ArrayList<AddMRK>)(atts.get(Att.ADDMRK).val); 1031 1074 Handle h = Handle.CC; 1075 double ax = 0.0; 1076 double ay = 0.0; 1032 1077 switch (i) { 1033 1078 case 0: … … 1035 1080 break; 1036 1081 case 1: 1037 if (n <= 3) 1082 if (n <= 3) { 1038 1083 h = Handle.RC; 1039 else 1084 ax = -30; 1085 ay = dy; 1086 } 1087 else { 1040 1088 h = Handle.BR; 1089 } 1041 1090 break; 1042 1091 case 2: … … 1056 1105 break; 1057 1106 } 1058 if (h != null) Renderer.symbol(sym, sch, new Delta(h, AffineTransform.getTranslateInstance(dx, dy))); 1107 if (h != null) { 1108 Renderer.symbol(sym, sch, new Delta(h, AffineTransform.getTranslateInstance(dx, dy))); 1109 if (!add.isEmpty()) Renderer.symbol(Notices.NoticeBoard, new Delta(Handle.BC, AffineTransform.getTranslateInstance(ax, ay - 30))); 1110 } 1059 1111 i++; 1060 1112 } … … 1069 1121 Renderer.lineVector(new LineStyle(Color.black, 5, new float[] { 20, 20 }, null)); 1070 1122 if (Renderer.zoom >= 15) { 1071 Renderer.lineText("Boom", new Font("Arial", Font.PLAIN, 80), Color.black, 0.5,-20);1123 Renderer.lineText("Boom", new Font("Arial", Font.PLAIN, 80), Color.black, -20); 1072 1124 } 1073 1125 default: … … 1186 1238 Renderer.lineVector(new LineStyle(Color.black, 10, new float[] { 40, 40 }, null)); 1187 1239 if (Renderer.zoom >= 15) 1188 Renderer.lineText("(covers)", new Font("Arial", Font.PLAIN, 60), Color.black, 0.5,80);1240 Renderer.lineText("(covers)", new Font("Arial", Font.PLAIN, 60), Color.black, 80); 1189 1241 } else { 1190 1242 Renderer.lineVector(new LineStyle(Color.black, 10, null, null)); 1191 1243 } 1192 1244 if (Renderer.zoom >= 15) 1193 Renderer.lineText("Training Wall", new Font("Arial", Font.PLAIN, 60), Color.black, 0.5,-30);1245 Renderer.lineText("Training Wall", new Font("Arial", Font.PLAIN, 60), Color.black, -30); 1194 1246 break; 1195 1247 case SLC_SWAY: … … 1333 1385 str += df.format(ort) + "º"; 1334 1386 if (!str.isEmpty()) 1335 Renderer.lineText(str, new Font("Arial", Font.PLAIN, 80), Color.black, 0.5,-20);1387 Renderer.lineText(str, new Font("Arial", Font.PLAIN, 80), Color.black, -20); 1336 1388 } 1337 1389 }
Note:
See TracChangeset
for help on using the changeset viewer.