当前位置: 首页>>代码示例>>Java>>正文


Java TextLayout.getPixelBounds方法代码示例

本文整理汇总了Java中java.awt.font.TextLayout.getPixelBounds方法的典型用法代码示例。如果您正苦于以下问题:Java TextLayout.getPixelBounds方法的具体用法?Java TextLayout.getPixelBounds怎么用?Java TextLayout.getPixelBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.font.TextLayout的用法示例。


在下文中一共展示了TextLayout.getPixelBounds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: measureText

import java.awt.font.TextLayout; //导入方法依赖的package包/类
static void measureText() {
    Font font = new Font(FONT, Font.PLAIN, 36);
    if (!font.getFamily(Locale.ENGLISH).equals(FONT)) {
        return;
    }
    FontRenderContext frc = new FontRenderContext(null, false, false);
    TextLayout tl1 = new TextLayout(STR1, font, frc);
    TextLayout tl2 = new TextLayout(STR2, font, frc);
    Rectangle r1 = tl1.getPixelBounds(frc, 0f, 0f);
    Rectangle r2 = tl2.getPixelBounds(frc, 0f, 0f);
    if (r1.height > r2.height) {
        System.out.println(font);
        System.out.println(r1);
        System.out.println(r2);
        throw new RuntimeException("BAD BOUNDS");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ArabicDiacriticTest.java

示例2: getWidth

import java.awt.font.TextLayout; //导入方法依赖的package包/类
/**
     * Compute a most appropriate width of the given text layout.
     */
    public static float getWidth(TextLayout textLayout, String textLayoutText, Font font) {
        // For italic fonts the textLayout.getAdvance() includes some extra horizontal space.
        // On the other hand index2X() for TL.getCharacterCount() is width along baseline
        // so when TL ends with e.g. 'd' char the end of 'd' char is cut off.
        float width;
        int tlLen = textLayoutText.length();
        if (!font.isItalic() ||
            tlLen == 0 ||
            Character.isWhitespace(textLayoutText.charAt(tlLen - 1)) ||
            Bidi.requiresBidi(textLayoutText.toCharArray(), 0, textLayoutText.length()))
        {
            width = textLayout.getAdvance();
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("TLUtils.getWidth(\"" + CharSequenceUtilities.debugText(textLayoutText) + // NOI18N
                        "\"): Using TL.getAdvance()=" + width + // NOI18N
//                        textLayoutDump(textLayout) + 
                        '\n');
            }
        } else {
            // Compute pixel bounds (with frc being null - means use textLayout's frc; and with default bounds)
            Rectangle pixelBounds = textLayout.getPixelBounds(null, 0, 0);
            width = (float) pixelBounds.getMaxX();
            // On Mac OS X with retina displays the TL.getPixelBounds() give incorrect results. Luckily
            // TL.getAdvance() gives a correct result in that case.
            // Therefore use a minimum of both values (on all platforms).
            float tlAdvance = textLayout.getAdvance();
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("TLUtils.getWidth(\"" + CharSequenceUtilities.debugText(textLayoutText) + // NOI18N
                        "\"): Using minimum of TL.getPixelBounds().getMaxX()=" + width + // NOI18N
                        " or TL.getAdvance()=" + tlAdvance +
                        textLayoutDump(textLayout) +
                        '\n');
            }
            width = Math.min(width, tlAdvance);
        }
        
        // For RTL text the hit-info of the first char is above the hit-info of ending char.
        // However textLayout.isLeftToRight() returns true in case of mixture of LTR and RTL text
        // in a single textLayout.
        
        // Ceil the width to avoid rendering artifacts.
        width = (float) Math.ceil(width);
        return width;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:48,代码来源:TextLayoutUtils.java


注:本文中的java.awt.font.TextLayout.getPixelBounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。