Changeset 11752 in josm
- Timestamp:
- 2017-03-20T23:26:37+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/placement/OnLineStrategy.java
r11749 r11752 49 49 } 50 50 51 private double upsideTheta(HalfSegment best) {51 private static double upsideTheta(HalfSegment best) { 52 52 double theta = theta(best.start, best.end); 53 53 if (theta < -Math.PI / 2) { … … 68 68 public List<GlyphVector> generateGlyphVectors(MapViewPath path, Rectangle2D nb, List<GlyphVector> gvs, 69 69 boolean isDoubleTranslationBug) { 70 // Find the position on the way the font should be placed. 71 // If none is found, use the middle of the way. 70 72 double middleOffset = findOptimalWayPosition(nb, path).map(segment -> segment.offset) 71 73 .orElse(path.getLength() / 2); 72 74 75 // Check that segment of the way. Compute in which direction the text should be rendered. 76 // It is rendered in a way that ensures that at least 50% of the text are rotated with the right side up. 73 77 UpsideComputingVisitor upside = new UpsideComputingVisitor(middleOffset - nb.getWidth() / 2, 74 78 middleOffset + nb.getWidth() / 2); 75 79 path.visitLine(upside); 76 77 boolean doRotateText = upside.shouldMirrorText(); 80 boolean doRotateText = upside.shouldRotateText(); 81 82 // Compute the list of glyphs to draw, along with their offset on the current line. 78 83 List<OffsetGlyph> offsetGlyphs = computeOffsetGlyphs(gvs, 79 84 middleOffset + (doRotateText ? 1 : -1) * nb.getWidth() / 2, doRotateText); 80 85 86 // Order the glyphs along the line to ensure that they are drawn corretly. 87 Collections.sort(offsetGlyphs, Comparator.comparing(e -> e.offset)); 88 89 // Now translate all glyphs. This will modify the glyphs stored in gvs. 81 90 path.visitLine(new GlyphRotatingVisitor(offsetGlyphs, isDoubleTranslationBug)); 82 91 return gvs; … … 100 109 offset += (rotateText ? -1 : 1) + gv.getLogicalBounds().getBounds2D().getWidth(); 101 110 } 102 Collections.sort(offsetGlyphs, Comparator.comparing(e -> e.offset));103 111 return offsetGlyphs; 104 112 } 105 113 106 private Optional<HalfSegment> findOptimalWayPosition(Rectangle2D rect, MapViewPath path) {114 private static Optional<HalfSegment> findOptimalWayPosition(Rectangle2D rect, MapViewPath path) { 107 115 // find half segments that are long enough to draw text on (don't draw text over the cross hair in the center of each segment) 108 116 List<HalfSegment> longHalfSegment = new ArrayList<>(); … … 192 200 private final double endOffset; 193 201 194 private double upsideUpLines = 0;195 private double upsideDownLines = 0;202 private double upsideUpLines; 203 private double upsideDownLines; 196 204 197 205 UpsideComputingVisitor(double startOffset, double endOffset) { … … 223 231 } 224 232 225 public boolean shouldMirrorText() { 233 /** 234 * Check if the text should be rotated by 180° 235 * @return if the text should be rotated. 236 */ 237 boolean shouldRotateText() { 226 238 return upsideUpLines < upsideDownLines; 227 239 } … … 236 248 private OffsetGlyph next; 237 249 250 /** 251 * Create a new {@link GlyphRotatingVisitor} 252 * @param gvs The glyphs to draw. Sorted along the line 253 * @param isDoubleTranslationBug true to fix a double translation bug. 254 */ 238 255 GlyphRotatingVisitor(List<OffsetGlyph> gvs, boolean isDoubleTranslationBug) { 239 256 this.isDoubleTranslationBug = isDoubleTranslationBug;
Note:
See TracChangeset
for help on using the changeset viewer.