Search in sources :

Example 1 with AttributeMap

use of sun.font.AttributeMap in project jdk8u_jdk by JetBrains.

the class Font method getFont.

/**
     * Returns a <code>Font</code> appropriate to the attributes.
     * If <code>attributes</code>contains a <code>FONT</code> attribute
     * with a valid <code>Font</code> as its value, it will be
     * merged with any remaining attributes.  See
     * {@link java.awt.font.TextAttribute#FONT} for more
     * information.
     *
     * @param attributes the attributes to assign to the new
     *          <code>Font</code>
     * @return a new <code>Font</code> created with the specified
     *          attributes
     * @throws NullPointerException if <code>attributes</code> is null.
     * @since 1.2
     * @see java.awt.font.TextAttribute
     */
public static Font getFont(Map<? extends Attribute, ?> attributes) {
    // avoid turning the attributemap into a regular map for no reason
    if (attributes instanceof AttributeMap && ((AttributeMap) attributes).getValues() != null) {
        AttributeValues values = ((AttributeMap) attributes).getValues();
        if (values.isNonDefault(EFONT)) {
            Font font = values.getFont();
            if (!values.anyDefined(SECONDARY_MASK)) {
                return font;
            }
            // merge
            values = font.getAttributeValues().clone();
            values.merge(attributes, SECONDARY_MASK);
            return new Font(values, font.name, font.style, font.createdFont, font.font2DHandle);
        }
        return new Font(attributes);
    }
    Font font = (Font) attributes.get(TextAttribute.FONT);
    if (font != null) {
        if (attributes.size() > 1) {
            // oh well, check for anything else
            AttributeValues values = font.getAttributeValues().clone();
            values.merge(attributes, SECONDARY_MASK);
            return new Font(values, font.name, font.style, font.createdFont, font.font2DHandle);
        }
        return font;
    }
    return new Font(attributes);
}
Also used : AttributeMap(sun.font.AttributeMap) AttributeValues(sun.font.AttributeValues) CompositeFont(sun.font.CompositeFont)

Aggregations

AttributeMap (sun.font.AttributeMap)1 AttributeValues (sun.font.AttributeValues)1 CompositeFont (sun.font.CompositeFont)1