Search in sources :

Example 1 with FontResolver

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

the class StyledParagraph method addFonts.

/**
     * Resolve the given chars into Fonts using FontResolver, then add
     * font runs for each.
     */
private void addFonts(char[] chars, Map<? extends Attribute, ?> attributes, int start, int limit) {
    FontResolver resolver = FontResolver.getInstance();
    CodePointIterator iter = CodePointIterator.create(chars, start, limit);
    for (int runStart = iter.charIndex(); runStart < limit; runStart = iter.charIndex()) {
        int fontIndex = resolver.nextFontRunIndex(iter);
        addFont(resolver.getFont(fontIndex, attributes), runStart);
    }
}
Also used : CodePointIterator(sun.text.CodePointIterator) FontResolver(sun.font.FontResolver)

Example 2 with FontResolver

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

the class TextLayout method singleFont.

/*
     * Determines a font for the attributes, and if a single font can render
     * all the text on one baseline, return it, otherwise null.  If the
     * attributes specify a font, assume it can display all the text without
     * checking.
     * If the AttributeSet contains an embedded graphic, return null.
     */
private static Font singleFont(char[] text, int start, int limit, Map<? extends Attribute, ?> attributes) {
    if (attributes.get(TextAttribute.CHAR_REPLACEMENT) != null) {
        return null;
    }
    Font font = null;
    try {
        font = (Font) attributes.get(TextAttribute.FONT);
    } catch (ClassCastException e) {
    }
    if (font == null) {
        if (attributes.get(TextAttribute.FAMILY) != null) {
            font = Font.getFont(attributes);
            if (font.canDisplayUpTo(text, start, limit) != -1) {
                return null;
            }
        } else {
            FontResolver resolver = FontResolver.getInstance();
            CodePointIterator iter = CodePointIterator.create(text, start, limit);
            int fontIndex = resolver.nextFontRunIndex(iter);
            if (iter.charIndex() == limit) {
                font = resolver.getFont(fontIndex, attributes);
            }
        }
    }
    if (sameBaselineUpTo(font, text, start, limit) != limit) {
        return null;
    }
    return font;
}
Also used : CodePointIterator(sun.text.CodePointIterator) FontResolver(sun.font.FontResolver) Font(java.awt.Font)

Example 3 with FontResolver

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

the class TextLine method getFontAtCurrentPos.

static Font getFontAtCurrentPos(AttributedCharacterIterator aci) {
    Object value = aci.getAttribute(TextAttribute.FONT);
    if (value != null) {
        return (Font) value;
    }
    if (aci.getAttribute(TextAttribute.FAMILY) != null) {
        return Font.getFont(aci.getAttributes());
    }
    int ch = CodePointIterator.create(aci).next();
    if (ch != CodePointIterator.DONE) {
        FontResolver resolver = FontResolver.getInstance();
        return resolver.getFont(resolver.getFontIndex(ch), aci.getAttributes());
    }
    return null;
}
Also used : FontResolver(sun.font.FontResolver) Font(java.awt.Font)

Example 4 with FontResolver

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

the class StyledParagraph method insertChar.

/**
     * Return a StyledParagraph reflecting the insertion of a single character
     * into the text.  This method will attempt to reuse the given paragraph,
     * but may create a new paragraph.
     * @param aci an iterator over the text.  The text should be the same as the
     *     text used to create (or most recently update) oldParagraph, with
     *     the exception of inserting a single character at insertPos.
     * @param chars the characters in aci
     * @param insertPos the index of the new character in aci
     * @param oldParagraph a StyledParagraph for the text in aci before the
     *     insertion
     */
public static StyledParagraph insertChar(AttributedCharacterIterator aci, char[] chars, int insertPos, StyledParagraph oldParagraph) {
    // If the styles at insertPos match those at insertPos-1,
    // oldParagraph will be reused.  Otherwise we create a new
    // paragraph.
    char ch = aci.setIndex(insertPos);
    int relativePos = Math.max(insertPos - aci.getBeginIndex() - 1, 0);
    Map<? extends Attribute, ?> attributes = addInputMethodAttrs(aci.getAttributes());
    Decoration d = Decoration.getDecoration(attributes);
    if (!oldParagraph.getDecorationAt(relativePos).equals(d)) {
        return new StyledParagraph(aci, chars);
    }
    Object f = getGraphicOrFont(attributes);
    if (f == null) {
        FontResolver resolver = FontResolver.getInstance();
        int fontIndex = resolver.getFontIndex(ch);
        f = resolver.getFont(fontIndex, attributes);
    }
    if (!oldParagraph.getFontOrGraphicAt(relativePos).equals(f)) {
        return new StyledParagraph(aci, chars);
    }
    // insert into existing paragraph
    oldParagraph.length += 1;
    if (oldParagraph.decorations != null) {
        insertInto(relativePos, oldParagraph.decorationStarts, oldParagraph.decorations.size());
    }
    if (oldParagraph.fonts != null) {
        insertInto(relativePos, oldParagraph.fontStarts, oldParagraph.fonts.size());
    }
    return oldParagraph;
}
Also used : FontResolver(sun.font.FontResolver) Decoration(sun.font.Decoration)

Aggregations

FontResolver (sun.font.FontResolver)4 Font (java.awt.Font)2 CodePointIterator (sun.text.CodePointIterator)2 Decoration (sun.font.Decoration)1