Search in sources :

Example 21 with FontRenderContext

use of java.awt.font.FontRenderContext in project intellij-community by JetBrains.

the class TextPainter method getCharWidth.

private double getCharWidth(Graphics2D g) {
    if (myCharWidth < 0) {
        FontRenderContext fontRenderContext = (g).getFontRenderContext();
        myCharWidth = myPlainFont.getStringBounds(DEFAULT_MEASURE_WIDTH_TEXT, fontRenderContext).getWidth();
    }
    return myCharWidth;
}
Also used : FontRenderContext(java.awt.font.FontRenderContext)

Example 22 with FontRenderContext

use of java.awt.font.FontRenderContext in project intellij-community by JetBrains.

the class TextPainter method getLineHeight.

private float getLineHeight(Graphics g) {
    if (myLineHeight >= 0) {
        return myLineHeight;
    }
    FontRenderContext fontRenderContext = ((Graphics2D) g).getFontRenderContext();
    LineMetrics lineMetrics = myPlainFont.getLineMetrics(DEFAULT_MEASURE_HEIGHT_TEXT, fontRenderContext);
    myLineHeight = lineMetrics.getHeight();
    return myLineHeight;
}
Also used : FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics)

Example 23 with FontRenderContext

use of java.awt.font.FontRenderContext in project intellij-community by JetBrains.

the class SimpleColoredComponent method computeStringWidth.

private float computeStringWidth(int fragmentIndex, Font font) {
    String text = myFragments.get(fragmentIndex);
    if (StringUtil.isEmpty(text))
        return 0;
    FontRenderContext fontRenderContext = getFontMetrics(font).getFontRenderContext();
    TextLayout layout = getTextLayout(fragmentIndex, font, fontRenderContext);
    if (layout != null) {
        return layout.getAdvance();
    } else {
        return (float) font.getStringBounds(text, fontRenderContext).getWidth();
    }
}
Also used : AttributedString(java.text.AttributedString) FontRenderContext(java.awt.font.FontRenderContext) TextLayout(java.awt.font.TextLayout)

Example 24 with FontRenderContext

use of java.awt.font.FontRenderContext in project poi by apache.

the class BaseTestBugzillaIssues method computeCellWidthManually.

// FIXME: this function is a self-fulfilling prophecy: this test will always pass as long
// as the code-under-test and the testcase code are written the same way (have the same bugs). 
private double computeCellWidthManually(Cell cell0, Font font) {
    final FontRenderContext fontRenderContext = new FontRenderContext(null, true, true);
    RichTextString rt = cell0.getRichStringCellValue();
    String[] lines = rt.getString().split("\\n");
    assertEquals(1, lines.length);
    String txt = lines[0] + "0";
    AttributedString str = new AttributedString(txt);
    copyAttributes(font, str, txt.length());
    // TODO: support rich text fragments
    /*if (rt.numFormattingRuns() > 0) {
        }*/
    TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext);
    double frameWidth = getFrameWidth(layout);
    return ((frameWidth / 1) / 8);
}
Also used : AttributedString(java.text.AttributedString) FontRenderContext(java.awt.font.FontRenderContext) AttributedString(java.text.AttributedString) TextLayout(java.awt.font.TextLayout)

Example 25 with FontRenderContext

use of java.awt.font.FontRenderContext in project limelight by slagyr.

the class PropPanelTest method hasChangesWhenTextIsChanged.

@Test
public void hasChangesWhenTextIsChanged() throws Exception {
    TextPanel.staticFontRenderingContext = new FontRenderContext(new AffineTransform(), true, true);
    Layouts.on(panel, panel.getDefaultLayout());
    panel.resetNeededLayout();
    panel.setText("blah");
    assertEquals(true, panel.needsLayout());
    panel.resetNeededLayout();
    panel.setText("blah");
    assertEquals(false, panel.needsLayout());
    panel.setText("new text");
    assertEquals(true, panel.needsLayout());
}
Also used : AffineTransform(java.awt.geom.AffineTransform) FontRenderContext(java.awt.font.FontRenderContext) Test(org.junit.Test)

Aggregations

FontRenderContext (java.awt.font.FontRenderContext)79 Font (java.awt.Font)27 TextLayout (java.awt.font.TextLayout)25 GlyphVector (java.awt.font.GlyphVector)18 Graphics2D (java.awt.Graphics2D)17 Rectangle2D (java.awt.geom.Rectangle2D)17 AttributedString (java.text.AttributedString)14 AffineTransform (java.awt.geom.AffineTransform)13 Paint (java.awt.Paint)8 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)7 AttributedCharacterIterator (java.text.AttributedCharacterIterator)7 Color (java.awt.Color)5 Shape (java.awt.Shape)5 LineMetrics (java.awt.font.LineMetrics)5 BufferedImage (java.awt.image.BufferedImage)5 ArrayList (java.util.ArrayList)5 Point (java.awt.Point)4 BasicStroke (java.awt.BasicStroke)3 FontMetrics (java.awt.FontMetrics)3 Rectangle (java.awt.Rectangle)3