Search in sources :

Example 1 with FontVariant

use of android.graphics.FontFamily_Delegate.FontVariant in project platform_frameworks_base by android.

the class Typeface_Delegate method getFonts.

/**
     * Return a list of fonts that match the style and variant. The list is ordered according to
     * preference of fonts.
     *
     * The list may contain null when the font failed to load. If null is reached when trying to
     * render with this list of fonts, then a warning should be logged letting the user know that
     * some font failed to load.
     *
     * @param variant The variant preferred. Can only be {@link FontVariant#COMPACT} or
     *                {@link FontVariant#ELEGANT}
     */
@NonNull
public List<Font> getFonts(FontVariant variant) {
    assert variant != FontVariant.NONE;
    // Calculate the required weight based on style and weight of this typeface.
    int weight = mWeight + ((mStyle & Font.BOLD) == 0 ? 0 : FontFamily_Delegate.BOLD_FONT_WEIGHT_DELTA);
    if (weight > 900) {
        weight = 900;
    }
    final boolean isItalic = (mStyle & Font.ITALIC) != 0;
    List<Font> fonts = new ArrayList<Font>(mFontFamilies.length);
    for (int i = 0; i < mFontFamilies.length; i++) {
        FontFamily_Delegate ffd = mFontFamilies[i];
        if (ffd != null && ffd.isValid()) {
            Font font = ffd.getFont(weight, isItalic);
            if (font != null) {
                FontVariant ffdVariant = ffd.getVariant();
                if (ffdVariant == FontVariant.NONE) {
                    fonts.add(font);
                    continue;
                }
                // always appear in pairs.
                assert i < mFontFamilies.length - 1;
                FontFamily_Delegate ffd2 = mFontFamilies[++i];
                assert ffd2 != null;
                FontVariant ffd2Variant = ffd2.getVariant();
                Font font2 = ffd2.getFont(weight, isItalic);
                assert ffd2Variant != FontVariant.NONE && ffd2Variant != ffdVariant && font2 != null;
                // Add the font with the matching variant to the list.
                if (variant == ffd.getVariant()) {
                    fonts.add(font);
                } else {
                    fonts.add(font2);
                }
            } else {
                // The FontFamily is valid but doesn't contain any matching font. This means
                // that the font failed to load. We add null to the list of fonts. Don't throw
                // the warning just yet. If this is a non-english font, we don't want to warn
                // users who are trying to render only english text.
                fonts.add(null);
            }
        }
    }
    return fonts;
}
Also used : FontVariant(android.graphics.FontFamily_Delegate.FontVariant) ArrayList(java.util.ArrayList) Font(java.awt.Font) NonNull(android.annotation.NonNull)

Example 2 with FontVariant

use of android.graphics.FontFamily_Delegate.FontVariant in project android_frameworks_base by AOSPA.

the class Typeface_Delegate method getFonts.

/**
     * Return a list of fonts that match the style and variant. The list is ordered according to
     * preference of fonts.
     *
     * The list may contain null when the font failed to load. If null is reached when trying to
     * render with this list of fonts, then a warning should be logged letting the user know that
     * some font failed to load.
     *
     * @param variant The variant preferred. Can only be {@link FontVariant#COMPACT} or
     *                {@link FontVariant#ELEGANT}
     */
@NonNull
public List<Font> getFonts(FontVariant variant) {
    assert variant != FontVariant.NONE;
    // Calculate the required weight based on style and weight of this typeface.
    int weight = mWeight + ((mStyle & Font.BOLD) == 0 ? 0 : FontFamily_Delegate.BOLD_FONT_WEIGHT_DELTA);
    if (weight > 900) {
        weight = 900;
    }
    final boolean isItalic = (mStyle & Font.ITALIC) != 0;
    List<Font> fonts = new ArrayList<Font>(mFontFamilies.length);
    for (int i = 0; i < mFontFamilies.length; i++) {
        FontFamily_Delegate ffd = mFontFamilies[i];
        if (ffd != null && ffd.isValid()) {
            Font font = ffd.getFont(weight, isItalic);
            if (font != null) {
                FontVariant ffdVariant = ffd.getVariant();
                if (ffdVariant == FontVariant.NONE) {
                    fonts.add(font);
                    continue;
                }
                // always appear in pairs.
                assert i < mFontFamilies.length - 1;
                FontFamily_Delegate ffd2 = mFontFamilies[++i];
                assert ffd2 != null;
                FontVariant ffd2Variant = ffd2.getVariant();
                Font font2 = ffd2.getFont(weight, isItalic);
                assert ffd2Variant != FontVariant.NONE && ffd2Variant != ffdVariant && font2 != null;
                // Add the font with the matching variant to the list.
                if (variant == ffd.getVariant()) {
                    fonts.add(font);
                } else {
                    fonts.add(font2);
                }
            } else {
                // The FontFamily is valid but doesn't contain any matching font. This means
                // that the font failed to load. We add null to the list of fonts. Don't throw
                // the warning just yet. If this is a non-english font, we don't want to warn
                // users who are trying to render only english text.
                fonts.add(null);
            }
        }
    }
    return fonts;
}
Also used : FontVariant(android.graphics.FontFamily_Delegate.FontVariant) ArrayList(java.util.ArrayList) Font(java.awt.Font) NonNull(android.annotation.NonNull)

Example 3 with FontVariant

use of android.graphics.FontFamily_Delegate.FontVariant in project android_frameworks_base by DirtyUnicorns.

the class Typeface_Delegate method getFonts.

/**
     * Return a list of fonts that match the style and variant. The list is ordered according to
     * preference of fonts.
     *
     * The list may contain null when the font failed to load. If null is reached when trying to
     * render with this list of fonts, then a warning should be logged letting the user know that
     * some font failed to load.
     *
     * @param variant The variant preferred. Can only be {@link FontVariant#COMPACT} or
     *                {@link FontVariant#ELEGANT}
     */
@NonNull
public List<Font> getFonts(FontVariant variant) {
    assert variant != FontVariant.NONE;
    // Calculate the required weight based on style and weight of this typeface.
    int weight = mWeight + ((mStyle & Font.BOLD) == 0 ? 0 : FontFamily_Delegate.BOLD_FONT_WEIGHT_DELTA);
    if (weight > 900) {
        weight = 900;
    }
    final boolean isItalic = (mStyle & Font.ITALIC) != 0;
    List<Font> fonts = new ArrayList<Font>(mFontFamilies.length);
    for (int i = 0; i < mFontFamilies.length; i++) {
        FontFamily_Delegate ffd = mFontFamilies[i];
        if (ffd != null && ffd.isValid()) {
            Font font = ffd.getFont(weight, isItalic);
            if (font != null) {
                FontVariant ffdVariant = ffd.getVariant();
                if (ffdVariant == FontVariant.NONE) {
                    fonts.add(font);
                    continue;
                }
                // always appear in pairs.
                assert i < mFontFamilies.length - 1;
                FontFamily_Delegate ffd2 = mFontFamilies[++i];
                assert ffd2 != null;
                FontVariant ffd2Variant = ffd2.getVariant();
                Font font2 = ffd2.getFont(weight, isItalic);
                assert ffd2Variant != FontVariant.NONE && ffd2Variant != ffdVariant && font2 != null;
                // Add the font with the matching variant to the list.
                if (variant == ffd.getVariant()) {
                    fonts.add(font);
                } else {
                    fonts.add(font2);
                }
            } else {
                // The FontFamily is valid but doesn't contain any matching font. This means
                // that the font failed to load. We add null to the list of fonts. Don't throw
                // the warning just yet. If this is a non-english font, we don't want to warn
                // users who are trying to render only english text.
                fonts.add(null);
            }
        }
    }
    return fonts;
}
Also used : FontVariant(android.graphics.FontFamily_Delegate.FontVariant) ArrayList(java.util.ArrayList) Font(java.awt.Font) NonNull(android.annotation.NonNull)

Example 4 with FontVariant

use of android.graphics.FontFamily_Delegate.FontVariant in project android_frameworks_base by ResurrectionRemix.

the class Typeface_Delegate method getFonts.

/**
     * Return a list of fonts that match the style and variant. The list is ordered according to
     * preference of fonts.
     *
     * The list may contain null when the font failed to load. If null is reached when trying to
     * render with this list of fonts, then a warning should be logged letting the user know that
     * some font failed to load.
     *
     * @param variant The variant preferred. Can only be {@link FontVariant#COMPACT} or
     *                {@link FontVariant#ELEGANT}
     */
@NonNull
public List<Font> getFonts(FontVariant variant) {
    assert variant != FontVariant.NONE;
    // Calculate the required weight based on style and weight of this typeface.
    int weight = mWeight + ((mStyle & Font.BOLD) == 0 ? 0 : FontFamily_Delegate.BOLD_FONT_WEIGHT_DELTA);
    if (weight > 900) {
        weight = 900;
    }
    final boolean isItalic = (mStyle & Font.ITALIC) != 0;
    List<Font> fonts = new ArrayList<Font>(mFontFamilies.length);
    for (int i = 0; i < mFontFamilies.length; i++) {
        FontFamily_Delegate ffd = mFontFamilies[i];
        if (ffd != null && ffd.isValid()) {
            Font font = ffd.getFont(weight, isItalic);
            if (font != null) {
                FontVariant ffdVariant = ffd.getVariant();
                if (ffdVariant == FontVariant.NONE) {
                    fonts.add(font);
                    continue;
                }
                // always appear in pairs.
                assert i < mFontFamilies.length - 1;
                FontFamily_Delegate ffd2 = mFontFamilies[++i];
                assert ffd2 != null;
                FontVariant ffd2Variant = ffd2.getVariant();
                Font font2 = ffd2.getFont(weight, isItalic);
                assert ffd2Variant != FontVariant.NONE && ffd2Variant != ffdVariant && font2 != null;
                // Add the font with the matching variant to the list.
                if (variant == ffd.getVariant()) {
                    fonts.add(font);
                } else {
                    fonts.add(font2);
                }
            } else {
                // The FontFamily is valid but doesn't contain any matching font. This means
                // that the font failed to load. We add null to the list of fonts. Don't throw
                // the warning just yet. If this is a non-english font, we don't want to warn
                // users who are trying to render only english text.
                fonts.add(null);
            }
        }
    }
    return fonts;
}
Also used : FontVariant(android.graphics.FontFamily_Delegate.FontVariant) ArrayList(java.util.ArrayList) Font(java.awt.Font) NonNull(android.annotation.NonNull)

Example 5 with FontVariant

use of android.graphics.FontFamily_Delegate.FontVariant in project android_frameworks_base by crdroidandroid.

the class Typeface_Delegate method getFonts.

/**
     * Return a list of fonts that match the style and variant. The list is ordered according to
     * preference of fonts.
     *
     * The list may contain null when the font failed to load. If null is reached when trying to
     * render with this list of fonts, then a warning should be logged letting the user know that
     * some font failed to load.
     *
     * @param variant The variant preferred. Can only be {@link FontVariant#COMPACT} or
     *                {@link FontVariant#ELEGANT}
     */
@NonNull
public List<Font> getFonts(FontVariant variant) {
    assert variant != FontVariant.NONE;
    // Calculate the required weight based on style and weight of this typeface.
    int weight = mWeight + ((mStyle & Font.BOLD) == 0 ? 0 : FontFamily_Delegate.BOLD_FONT_WEIGHT_DELTA);
    if (weight > 900) {
        weight = 900;
    }
    final boolean isItalic = (mStyle & Font.ITALIC) != 0;
    List<Font> fonts = new ArrayList<Font>(mFontFamilies.length);
    for (int i = 0; i < mFontFamilies.length; i++) {
        FontFamily_Delegate ffd = mFontFamilies[i];
        if (ffd != null && ffd.isValid()) {
            Font font = ffd.getFont(weight, isItalic);
            if (font != null) {
                FontVariant ffdVariant = ffd.getVariant();
                if (ffdVariant == FontVariant.NONE) {
                    fonts.add(font);
                    continue;
                }
                // always appear in pairs.
                assert i < mFontFamilies.length - 1;
                FontFamily_Delegate ffd2 = mFontFamilies[++i];
                assert ffd2 != null;
                FontVariant ffd2Variant = ffd2.getVariant();
                Font font2 = ffd2.getFont(weight, isItalic);
                assert ffd2Variant != FontVariant.NONE && ffd2Variant != ffdVariant && font2 != null;
                // Add the font with the matching variant to the list.
                if (variant == ffd.getVariant()) {
                    fonts.add(font);
                } else {
                    fonts.add(font2);
                }
            } else {
                // The FontFamily is valid but doesn't contain any matching font. This means
                // that the font failed to load. We add null to the list of fonts. Don't throw
                // the warning just yet. If this is a non-english font, we don't want to warn
                // users who are trying to render only english text.
                fonts.add(null);
            }
        }
    }
    return fonts;
}
Also used : FontVariant(android.graphics.FontFamily_Delegate.FontVariant) ArrayList(java.util.ArrayList) Font(java.awt.Font) NonNull(android.annotation.NonNull)

Aggregations

NonNull (android.annotation.NonNull)5 FontVariant (android.graphics.FontFamily_Delegate.FontVariant)5 Font (java.awt.Font)5 ArrayList (java.util.ArrayList)5