MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / drawText

Method drawText

ij/src/main/java/ij/gui/TextRoi.java:281–335  ·  view source on GitHub ↗
(Graphics g)

Source from the content-addressed store, hash-verified

279 }
280
281 void drawText(Graphics g) {
282 g.setColor( strokeColor!=null? strokeColor:ROIColor);
283 Java2.setAntialiasedText(g, getAntiAlias());
284 double mag = getMagnification();
285 int xi = (int)Math.round(getXBase());
286 int yi = (int)Math.round(getYBase());
287 double widthd = bounds!=null?bounds.width:this.width;
288 double heightd = bounds!=null?bounds.height:this.height;
289 int widthi = (int)Math.round(widthd);
290 int heighti = (int)Math.round(heightd);
291 Font font = getScaledFont();
292 FontMetrics metrics = g.getFontMetrics(font);
293 int fontHeight = metrics.getHeight();
294 int descent = metrics.getDescent();
295 g.setFont(font);
296 Graphics2D g2d = (Graphics2D)g;
297 int sx = nonScalable?xi:screenXD(getXBase());
298 int sy = nonScalable?yi:screenYD(getYBase());
299 int sw = nonScalable?widthi:(int)(getMagnification()*widthd);
300 int sh = nonScalable?heighti:(int)(getMagnification()*heightd);
301 AffineTransform at = null;
302 if (angle!=0.0) {
303 at = g2d.getTransform();
304 double cx=sx, cy=sy;
305 double theta = Math.toRadians(angle);
306 g2d.rotate(-theta, cx, cy);
307 }
308 int i = 0;
309 if (fillColor!=null) {
310 Color c = g.getColor();
311 int alpha = fillColor.getAlpha();
312 g.setColor(fillColor);
313 g.fillRect(sx, sy, sw, sh);
314 g.setColor(c);
315 }
316 while (i<MAX_LINES && theText[i]!=null) {
317 switch (justification) {
318 case LEFT:
319 g.drawString(theText[i], sx, sy+fontHeight-descent);
320 break;
321 case CENTER:
322 int tw = metrics.stringWidth(theText[i]);
323 g.drawString(theText[i], sx+(sw-tw)/2, sy+fontHeight-descent);
324 break;
325 case RIGHT:
326 tw = metrics.stringWidth(theText[i]);
327 g.drawString(theText[i], sx+sw-tw, sy+fontHeight-descent);
328 break;
329 }
330 i++;
331 sy += fontHeight;
332 }
333 if (at!=null) // restore transformation matrix used to rotate text
334 g2d.setTransform(at);
335 }
336
337 /** Returns the name of the default font. Use getCurrentFont().getName()
338 to get the name of the font that this TextRoi is using. */

Callers 3

drawMethod · 0.95
drawOverlayMethod · 0.95
drawRoiMethod · 0.45

Calls 15

setAntialiasedTextMethod · 0.95
getScaledFontMethod · 0.95
getAntiAliasMethod · 0.80
getXBaseMethod · 0.80
getYBaseMethod · 0.80
fillRectMethod · 0.80
stringWidthMethod · 0.80
setColorMethod · 0.65
setFontMethod · 0.65
getColorMethod · 0.65
getMagnificationMethod · 0.45
roundMethod · 0.45

Tested by

no test coverage detected