Changeset 27313 in osm for applications/editors/josm/plugins/print/src/org
- Timestamp:
- 2011-12-23T10:39:53+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableMapView.java
r27283 r27313 27 27 28 28 import java.awt.AlphaComposite; 29 import java.awt.BasicStroke; 29 30 import java.awt.Color; 30 31 import java.awt.Dimension; … … 33 34 import java.awt.Graphics2D; 34 35 import java.awt.Image; 36 import java.awt.Shape; 35 37 import java.awt.event.ActionEvent; 36 38 import java.awt.event.KeyEvent; 39 import java.awt.font.FontRenderContext; 40 import java.awt.font.GlyphVector; 37 41 import java.awt.geom.AffineTransform; 38 42 import java.awt.geom.Rectangle2D; … … 303 307 int ws = (int)(distScale * 20.0); // length of a segment 304 308 305 /* white background & shadow*/309 /* white background */ 306 310 g2d.setColor(Color.WHITE); 307 311 g2d.fillRect(xLeft-1, yBar-1, w+2, h+2); 308 g2d.setFont(labelFont.deriveFont(AffineTransform.getTranslateInstance(0.5,0.4)));309 g2d.drawString("0", 0, yLabel);310 g2d.drawString(rightLabel, xRight, yLabel);311 312 312 313 /* black foreground */ … … 317 318 g2d.fillRect(xLeft+w-ws, yBar, ws, h); 318 319 g2d.setFont(labelFont); 319 g2d.drawString("0", 0, yLabel);320 g2d.drawString(rightLabel, xRight, yLabel);320 paintText(g2d, "0", 0, yLabel); 321 paintText(g2d, rightLabel, xRight, yLabel); 321 322 322 323 /* lexical scale */ … … 328 329 bound = g2d.getFontMetrics().getStringBounds(lexicalScale, g2d); 329 330 int xLexical = Math.max(0, xLeft + (w - (int)bound.getWidth()) / 2); 330 g2d.setColor(Color.WHITE); 331 g2d.setFont(scaleFront.deriveFont(AffineTransform.getTranslateInstance(0.5,0.4))); 332 g2d.drawString(lexicalScale, xLexical, yLexical); 333 g2d.setColor(Color.BLACK); 334 g2d.setFont(scaleFront); 335 g2d.drawString(lexicalScale, xLexical, yLexical); 331 paintText(g2d, lexicalScale, xLexical, yLexical); 336 332 } 337 333 … … 344 340 public void paintMapAttribution(Graphics2D g2d, PageFormat pageFormat) { 345 341 String text = Main.pref.get("print.attribution", PrintPlugin.DEF_ATTRIBUTION); 346 if (text == null || text.length() > 0) { 342 if (text != null && text.length() > 0) { 343 text += " "; 344 347 345 Font attributionFont = new Font("Arial", Font.PLAIN, FONT_SIZE * 8 / 10); 348 346 g2d.setFont(attributionFont); … … 350 348 int x = (int)((pageFormat.getImageableWidth() - bound.getWidth())); 351 349 int y = FONT_SIZE * 3 / 2; 350 paintText(g2d, text, x, y); 351 } 352 } 353 354 /** 355 * Paint a text. 356 * 357 * This method will not only draw the letters but also a background 358 * which improves redability. 359 * 360 * @param g2d the graphics context to use for painting 361 * @param text the text to be drawn 362 * @param x the x coordinate 363 * @param y the y coordinate 364 */ 365 366 public void paintText(Graphics2D g2d, String text, int x, int y) { 367 AffineTransform ax = g2d.getTransform(); 368 g2d.translate(x,y); 369 370 FontRenderContext frc = g2d.getFontRenderContext(); 371 GlyphVector gv = g2d.getFont().createGlyphVector(frc, text); 372 Shape textOutline = gv.getOutline(); 373 374 g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); 352 375 g2d.setColor(Color.WHITE); 353 g2d.setFont(attributionFont.deriveFont(AffineTransform.getTranslateInstance(0.5,0.4))); 354 g2d.drawString(text, x, y); 376 g2d.draw(textOutline); 377 378 g2d.setStroke(new BasicStroke()); 355 379 g2d.setColor(Color.BLACK); 356 g2d. setFont(attributionFont);357 g2d.drawString(text, x, y); 358 }380 g2d.drawString(text, 0, 0); 381 382 g2d.setTransform(ax); 359 383 } 360 384
Note:
See TracChangeset
for help on using the changeset viewer.