Search in sources :

Example 56 with FontRenderContext

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

the class TextPainter method drawHeaderOrFooterLine.

private double drawHeaderOrFooterLine(Graphics2D g, double x, double y, double w, String headerText, String alignment) {
    FontRenderContext fontRenderContext = g.getFontRenderContext();
    LineMetrics lineMetrics = getHeaderFooterLineMetrics(g);
    float lineHeight = lineMetrics.getHeight();
    if (myPerformActualDrawing) {
        headerText = convertHeaderText(headerText);
        g.setFont(myHeaderFont);
        g.setColor(Color.black);
        float descent = lineMetrics.getDescent();
        double width = myHeaderFont.getStringBounds(headerText, fontRenderContext).getWidth() + getCharWidth(g);
        float yPos = (float) (lineHeight - descent + y);
        if (PrintSettings.LEFT.equals(alignment)) {
            drawStringToGraphics(g, headerText, x, yPos);
        } else if (PrintSettings.CENTER.equals(alignment)) {
            drawStringToGraphics(g, headerText, (float) (x + (w - width) / 2), yPos);
        } else if (PrintSettings.RIGHT.equals(alignment)) {
            drawStringToGraphics(g, headerText, (float) (x + w - width), yPos);
        }
    }
    return lineHeight;
}
Also used : FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics)

Example 57 with FontRenderContext

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

the class EditorView method checkFontRenderContext.

private void checkFontRenderContext(FontRenderContext context) {
    FontRenderContext oldContext = myFontRenderContext;
    setFontRenderContext(context);
    if (!myFontRenderContext.equals(oldContext)) {
        myTextLayoutCache.resetToDocumentSize(false);
        invalidateFoldRegionLayouts();
    }
}
Also used : FontRenderContext(java.awt.font.FontRenderContext)

Example 58 with FontRenderContext

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

the class UIUtil method getStringY.

public static int getStringY(@NotNull final String string, @NotNull final Rectangle bounds, @NotNull final Graphics2D g) {
    final int centerY = bounds.height / 2;
    final Font font = g.getFont();
    final FontRenderContext frc = g.getFontRenderContext();
    final Rectangle stringBounds = font.getStringBounds(string, frc).getBounds();
    return (int) (centerY - stringBounds.height / 2.0 - stringBounds.y);
}
Also used : FontRenderContext(java.awt.font.FontRenderContext)

Example 59 with FontRenderContext

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

the class ParameterHintsPresentationManager method getFontMetrics.

private static MyFontMetrics getFontMetrics(@NotNull Editor editor) {
    String familyName = UIManager.getFont("Label.font").getFamily();
    int size = Math.max(1, editor.getColorsScheme().getEditorFontSize() - 1);
    MyFontMetrics metrics = editor.getUserData(HINT_FONT_METRICS);
    if (metrics != null) {
        Font font = metrics.getFont();
        if (!familyName.equals(font.getFamily()) || size != font.getSize())
            metrics = null;
        else {
            FontRenderContext currentContext = FontInfo.getFontRenderContext(editor.getContentComponent());
            if (currentContext.equals(metrics.metrics.getFontRenderContext()))
                metrics = null;
        }
    }
    if (metrics == null) {
        Font font = new Font(familyName, Font.PLAIN, size);
        metrics = new MyFontMetrics(editor, font);
        editor.putUserData(HINT_FONT_METRICS, metrics);
    }
    return metrics;
}
Also used : FontRenderContext(java.awt.font.FontRenderContext)

Example 60 with FontRenderContext

use of java.awt.font.FontRenderContext in project adempiere by adempiere.

the class StringElement method calculateSize.

//	translate
/**************************************************************************
	 * 	Layout and Calculate Size.
	 * 	Set p_width & p_height
	 * 	@return Size
	 */
protected boolean calculateSize() {
    if (p_sizeCalculated)
        return true;
    //
    FontRenderContext frc = new FontRenderContext(null, true, true);
    TextLayout layout = null;
    p_height = 0f;
    p_width = 0f;
    //	No Limit
    if (p_maxWidth == 0f && p_maxHeight == 0f) {
        for (int i = 0; i < m_string_paper.length; i++) {
            AttributedCharacterIterator iter = m_string_paper[i].getIterator();
            if (iter.getBeginIndex() == iter.getEndIndex())
                continue;
            //	Check for Tab (just first)
            int tabPos = -1;
            for (char c = iter.first(); c != CharacterIterator.DONE && tabPos == -1; c = iter.next()) {
                if (c == '\t')
                    tabPos = iter.getIndex();
            }
            if (tabPos == -1) {
                layout = new TextLayout(iter, frc);
                p_height += layout.getAscent() + layout.getDescent() + layout.getLeading();
                if (p_width < layout.getAdvance())
                    p_width = layout.getAdvance();
            } else //	with tab
            {
                LineBreakMeasurer measurer = new LineBreakMeasurer(iter, frc);
                layout = measurer.nextLayout(9999, tabPos, false);
                p_height += layout.getAscent() + layout.getDescent() + layout.getLeading();
                float width = getTabPos(0, layout.getAdvance());
                layout = measurer.nextLayout(9999, iter.getEndIndex(), true);
                width += layout.getAdvance();
                if (p_width < width)
                    p_width = width;
            }
        }
        //	Add CheckBox Size
        if (m_check != null) {
            p_width += LayoutEngine.IMAGE_SIZE.width;
            if (p_height < LayoutEngine.IMAGE_SIZE.height)
                p_height = LayoutEngine.IMAGE_SIZE.height;
        }
    } else //	Size Limits
    {
        p_width = p_maxWidth;
        for (int i = 0; i < m_string_paper.length; i++) {
            AttributedCharacterIterator iter = m_string_paper[i].getIterator();
            if (iter.getBeginIndex() == iter.getEndIndex())
                continue;
            LineBreakMeasurer measurer = new LineBreakMeasurer(iter, frc);
            //	System.out.println("StringLength=" + m_originalString.length() + " MaxWidth=" + p_maxWidth + " MaxHeight=" + p_maxHeight);
            while (measurer.getPosition() < iter.getEndIndex()) {
                //	no need to expand tab space for limited space
                layout = measurer.nextLayout(p_maxWidth);
                float lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
                //	System.out.println("  LineWidth=" + layout.getAdvance() + "  LineHeight=" + lineHeight);
                if (//	one line only
                p_maxHeight == -1f && i == 0)
                    p_maxHeight = lineHeight;
                if (p_maxHeight == 0f || (p_height + lineHeight) <= p_maxHeight)
                    p_height += lineHeight;
            }
        }
        //	Add CheckBox Size
        if (m_check != null) {
            //	p_width += LayoutEngine.IMAGE_SIZE.width;
            if (p_height < LayoutEngine.IMAGE_SIZE.height)
                p_height = LayoutEngine.IMAGE_SIZE.height;
        }
    //	System.out.println("  Width=" + p_width + "  Height=" + p_height);
    }
    //	Enlarge Size when aligned and max size is given
    if (p_FieldAlignmentType != null) {
        boolean changed = false;
        if (p_height < p_maxHeight) {
            p_height = p_maxHeight;
            changed = true;
        }
        if (p_width < p_maxWidth) {
            p_width = p_maxWidth;
            changed = true;
        }
    //	if (changed)
    //		System.out.println("StringElement.calculate size - Width="
    //			+ p_width + "(" + p_maxWidth + ") - Height=" + p_height + "(" + p_maxHeight + ")");
    }
    return true;
}
Also used : LineBreakMeasurer(java.awt.font.LineBreakMeasurer) FontRenderContext(java.awt.font.FontRenderContext) Point(java.awt.Point) Paint(java.awt.Paint) TextLayout(java.awt.font.TextLayout) AttributedCharacterIterator(java.text.AttributedCharacterIterator)

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