java.awt.Font#hasLayoutAttributes ( )源码实例Demo

下面列出了java.awt.Font#hasLayoutAttributes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk1.8-source-analysis   文件: TextLayout.java
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and a {@link Font}.  All the text is styled using the specified
 * <code>Font</code>.
 * <p>
 * The <code>String</code> must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a <code>Font</code> used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map<? extends Attribute, ?> attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
源代码2 项目: openjdk-8   文件: TextSourceLabel.java
public AffineTransform getBaselineTransform() {
    Font font = source.getFont();
    if (font.hasLayoutAttributes()) {
        return AttributeValues.getBaselineTransform(font.getAttributes());
    }
    return null;
}
 
源代码3 项目: openjdk-8   文件: TextLayout.java
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and a {@link Font}.  All the text is styled using the specified
 * <code>Font</code>.
 * <p>
 * The <code>String</code> must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a <code>Font</code> used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map<? extends Attribute, ?> attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
源代码4 项目: jdk8u-jdk   文件: StandardGlyphVector.java
private float getTracking(Font font) {
    if (font.hasLayoutAttributes()) {
        AttributeValues values = ((AttributeMap)font.getAttributes()).getValues();
        return values.getTracking();
    }
    return 0;
}
 
源代码5 项目: jdk8u-dev-jdk   文件: TextLayout.java
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and a {@link Font}.  All the text is styled using the specified
 * <code>Font</code>.
 * <p>
 * The <code>String</code> must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a <code>Font</code> used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map<? extends Attribute, ?> attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
源代码6 项目: openjdk-jdk8u-backup   文件: TextSourceLabel.java
public AffineTransform getBaselineTransform() {
    Font font = source.getFont();
    if (font.hasLayoutAttributes()) {
        return AttributeValues.getBaselineTransform(font.getAttributes());
    }
    return null;
}
 
源代码7 项目: TencentKona-8   文件: StandardGlyphVector.java
private float getTracking(Font font) {
    if (font.hasLayoutAttributes()) {
        AttributeValues values = ((AttributeMap)font.getAttributes()).getValues();
        return values.getTracking();
    }
    return 0;
}
 
源代码8 项目: jdk8u-dev-jdk   文件: TextSourceLabel.java
public AffineTransform getBaselineTransform() {
    Font font = source.getFont();
    if (font.hasLayoutAttributes()) {
        return AttributeValues.getBaselineTransform(font.getAttributes());
    }
    return null;
}
 
源代码9 项目: jdk8u_jdk   文件: TextLayout.java
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and a {@link Font}.  All the text is styled using the specified
 * <code>Font</code>.
 * <p>
 * The <code>String</code> must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a <code>Font</code> used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map<? extends Attribute, ?> attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
源代码10 项目: jdk8u-jdk   文件: StandardGlyphVector.java
private float getTracking(Font font) {
    if (font.hasLayoutAttributes()) {
        AttributeValues values = ((AttributeMap)font.getAttributes()).getValues();
        return values.getTracking();
    }
    return 0;
}
 
源代码11 项目: openjdk-8   文件: StandardGlyphVector.java
private float getTracking(Font font) {
    if (font.hasLayoutAttributes()) {
        AttributeValues values = ((AttributeMap)font.getAttributes()).getValues();
        return values.getTracking();
    }
    return 0;
}
 
源代码12 项目: JDKSourceCode1.8   文件: TextLayout.java
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and a {@link Font}.  All the text is styled using the specified
 * <code>Font</code>.
 * <p>
 * The <code>String</code> must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a <code>Font</code> used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map<? extends Attribute, ?> attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
源代码13 项目: hottub   文件: TextLayout.java
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and a {@link Font}.  All the text is styled using the specified
 * <code>Font</code>.
 * <p>
 * The <code>String</code> must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a <code>Font</code> used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map<? extends Attribute, ?> attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
源代码14 项目: jdk8u-jdk   文件: TextSourceLabel.java
public AffineTransform getBaselineTransform() {
    Font font = source.getFont();
    if (font.hasLayoutAttributes()) {
        return AttributeValues.getBaselineTransform(font.getAttributes());
    }
    return null;
}
 
源代码15 项目: openjdk-jdk8u   文件: StandardGlyphVector.java
private float getTracking(Font font) {
    if (font.hasLayoutAttributes()) {
        AttributeValues values = ((AttributeMap)font.getAttributes()).getValues();
        return values.getTracking();
    }
    return 0;
}
 
源代码16 项目: openjdk-jdk8u   文件: TextSourceLabel.java
public AffineTransform getBaselineTransform() {
    Font font = source.getFont();
    if (font.hasLayoutAttributes()) {
        return AttributeValues.getBaselineTransform(font.getAttributes());
    }
    return null;
}
 
源代码17 项目: Java8CN   文件: TextLayout.java
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and a {@link Font}.  All the text is styled using the specified
 * <code>Font</code>.
 * <p>
 * The <code>String</code> must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a <code>Font</code> used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map<? extends Attribute, ?> attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
源代码18 项目: openjdk-8-source   文件: TextLayout.java
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and a {@link Font}.  All the text is styled using the specified
 * <code>Font</code>.
 * <p>
 * The <code>String</code> must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a <code>Font</code> used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map<? extends Attribute, ?> attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
源代码19 项目: openjdk-jdk9   文件: PSPathGraphics.java
protected void drawString(String str, float x, float y,
                          Font font, FontRenderContext frc, float w) {
    if (str.length() == 0) {
        return;
    }

    /* If the Font has layout attributes we need to delegate to TextLayout.
     * TextLayout renders text as GlyphVectors. We try to print those
     * using printer fonts - ie using Postscript text operators so
     * we may be reinvoked. In that case the "!printingGlyphVector" test
     * prevents us recursing and instead sends us into the body of the
     * method where we can safely ignore layout attributes as those
     * are already handled by TextLayout.
     */
    if (font.hasLayoutAttributes() && !printingGlyphVector) {
        TextLayout layout = new TextLayout(str, font, frc);
        layout.draw(this, x, y);
        return;
    }

    Font oldFont = getFont();
    if (!oldFont.equals(font)) {
        setFont(font);
    } else {
        oldFont = null;
    }

    boolean drawnWithPS = false;

    float translateX = 0f, translateY = 0f;
    boolean fontisTransformed = getFont().isTransformed();

    if (fontisTransformed) {
        AffineTransform fontTx = getFont().getTransform();
        int transformType = fontTx.getType();
        /* TYPE_TRANSLATION is a flag bit but we can do "==" here
         * because we want to detect when its just that bit set and
         *
         */
        if (transformType == AffineTransform.TYPE_TRANSLATION) {
            translateX = (float)(fontTx.getTranslateX());
            translateY = (float)(fontTx.getTranslateY());
            if (Math.abs(translateX) < 0.00001) translateX = 0f;
            if (Math.abs(translateY) < 0.00001) translateY = 0f;
            fontisTransformed = false;
        }
    }

    boolean directToPS = !fontisTransformed;

    if (!PSPrinterJob.shapeTextProp && directToPS) {

        PSPrinterJob psPrinterJob = (PSPrinterJob) getPrinterJob();
        if (psPrinterJob.setFont(getFont())) {

            /* Set the text color.
             * We should not be in this shape printing path
             * if the application is drawing with non-solid
             * colors. We should be in the raster path. Because
             * we are here in the shape path, the cast of the
             * paint to a Color should be fine.
             */
            try {
                psPrinterJob.setColor((Color)getPaint());
            } catch (ClassCastException e) {
                if (oldFont != null) {
                    setFont(oldFont);
                }
                throw new IllegalArgumentException(
                                            "Expected a Color instance");
            }

            psPrinterJob.setTransform(getTransform());
            psPrinterJob.setClip(getClip());

            drawnWithPS = psPrinterJob.textOut(this, str,
                                               x+translateX, y+translateY,
                                               font, frc, w);
        }
    }

    /* The text could not be converted directly to PS text
     * calls so decompose the text into a shape.
     */
    if (drawnWithPS == false) {
        if (oldFont != null) {
            setFont(oldFont);
            oldFont = null;
        }
        super.drawString(str, x, y, font, frc, w);
    }

    if (oldFont != null) {
        setFont(oldFont);
    }
}
 
源代码20 项目: Bytecoder   文件: PSPathGraphics.java
protected void drawString(String str, float x, float y,
                          Font font, FontRenderContext frc, float w) {
    if (str.length() == 0) {
        return;
    }

    /* If the Font has layout attributes we need to delegate to TextLayout.
     * TextLayout renders text as GlyphVectors. We try to print those
     * using printer fonts - ie using Postscript text operators so
     * we may be reinvoked. In that case the "!printingGlyphVector" test
     * prevents us recursing and instead sends us into the body of the
     * method where we can safely ignore layout attributes as those
     * are already handled by TextLayout.
     */
    if (font.hasLayoutAttributes() && !printingGlyphVector) {
        TextLayout layout = new TextLayout(str, font, frc);
        layout.draw(this, x, y);
        return;
    }

    Font oldFont = getFont();
    if (!oldFont.equals(font)) {
        setFont(font);
    } else {
        oldFont = null;
    }

    boolean drawnWithPS = false;

    float translateX = 0f, translateY = 0f;
    boolean fontisTransformed = getFont().isTransformed();

    if (fontisTransformed) {
        AffineTransform fontTx = getFont().getTransform();
        int transformType = fontTx.getType();
        /* TYPE_TRANSLATION is a flag bit but we can do "==" here
         * because we want to detect when its just that bit set and
         *
         */
        if (transformType == AffineTransform.TYPE_TRANSLATION) {
            translateX = (float)(fontTx.getTranslateX());
            translateY = (float)(fontTx.getTranslateY());
            if (Math.abs(translateX) < 0.00001) translateX = 0f;
            if (Math.abs(translateY) < 0.00001) translateY = 0f;
            fontisTransformed = false;
        }
    }

    boolean directToPS = !fontisTransformed;

    if (!PSPrinterJob.shapeTextProp && directToPS) {

        PSPrinterJob psPrinterJob = (PSPrinterJob) getPrinterJob();
        if (psPrinterJob.setFont(getFont())) {

            /* Set the text color.
             * We should not be in this shape printing path
             * if the application is drawing with non-solid
             * colors. We should be in the raster path. Because
             * we are here in the shape path, the cast of the
             * paint to a Color should be fine.
             */
            try {
                psPrinterJob.setColor((Color)getPaint());
            } catch (ClassCastException e) {
                if (oldFont != null) {
                    setFont(oldFont);
                }
                throw new IllegalArgumentException(
                                            "Expected a Color instance");
            }

            psPrinterJob.setTransform(getTransform());
            psPrinterJob.setClip(getClip());

            drawnWithPS = psPrinterJob.textOut(this, str,
                                               x+translateX, y+translateY,
                                               font, frc, w);
        }
    }

    /* The text could not be converted directly to PS text
     * calls so decompose the text into a shape.
     */
    if (drawnWithPS == false) {
        if (oldFont != null) {
            setFont(oldFont);
            oldFont = null;
        }
        super.drawString(str, x, y, font, frc, w);
    }

    if (oldFont != null) {
        setFont(oldFont);
    }
}