List of usage examples for java.awt.font TextLayout getAscent
public float getAscent()
From source file:org.pentaho.reporting.engine.classic.core.layout.process.text.ComplexTextMinorAxisLayoutStep.java
private void addCompleteLine(final ParagraphRenderBox box, final ParagraphPoolBox lineBoxContainer, final StyleSheet layoutContext) { RichTextSpec richText = RichTextSpecProducer.compute(lineBoxContainer, metaData, resourceManager); final FontRenderContext fontRenderContext = createFontRenderContext(layoutContext); final TextLayout textLayout = new TextLayout(richText.createAttributedCharacterIterator(), fontRenderContext);//w ww.j a v a 2 s. c o m double height = textLayout.getAscent() + textLayout.getDescent() + textLayout.getLeading(); final RenderableComplexText text = richText.create(lineBoxContainer); text.setTextLayout(textLayout); ParagraphFontMetricsImpl metrics = new ParagraphFontMetricsImpl(); metrics.update(textLayout); final RenderBox line = generateLine(box, lineBoxContainer, text, height, metrics); // and finally add the line to the paragraph getNodeContext().updateX2(line.getCachedX2()); box.addGeneratedChild(line); }
From source file:ru.runa.wfe.graph.image.figure.AbstractFigure.java
private int drawText(Graphics2D graphics, String text, int hOffset) { Rectangle r = getTextBoundsRectangle(); Rectangle2D textBounds = graphics.getFontMetrics().getStringBounds(text, graphics); if (textBounds.getWidth() > r.getWidth() - 4) { int y = coords[1] + hOffset; AttributedString attributedString = new AttributedString(text); attributedString.addAttribute(TextAttribute.FONT, graphics.getFont()); AttributedCharacterIterator characterIterator = attributedString.getIterator(); LineBreakMeasurer measurer = new LineBreakMeasurer(characterIterator, graphics.getFontRenderContext()); while (measurer.getPosition() < characterIterator.getEndIndex()) { TextLayout textLayout = measurer.nextLayout((float) r.getWidth() - 4); y += textLayout.getAscent(); float x = (float) (r.getCenterX() + 2 - textLayout.getBounds().getCenterX()); textLayout.draw(graphics, x, y); y += textLayout.getDescent() + textLayout.getLeading(); }//from w ww . j av a2s . c o m return y - coords[1]; } else { graphics.drawString(text, (float) (r.getCenterX() + 2 - textBounds.getCenterX()), (float) (coords[1] + textBounds.getHeight() + hOffset)); return (int) (textBounds.getHeight() + hOffset + 3); } }