Loading tools/layoutlib/bridge/src/android/graphics/BidiRenderer.java +4 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,10 @@ public class BidiRenderer { mText = text; mFonts = new ArrayList<Font>(paint.getFonts().size()); for (FontInfo fontInfo : paint.getFonts()) { if (fontInfo == null) { mFonts.add(null); continue; } mFonts.add(fontInfo.mFont); } mBounds = new RectF(); Loading tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java +31 −0 Original line number Diff line number Diff line Loading @@ -27,7 +27,11 @@ import java.awt.Font; import java.awt.FontFormatException; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import static android.graphics.Typeface_Delegate.SYSTEM_FONTS; Loading @@ -51,6 +55,14 @@ public class FontFamily_Delegate { private static final String FONT_SUFFIX_BOLD = "Bold.ttf"; private static final String FONT_SUFFIX_ITALIC = "Italic.ttf"; private static final Set<String> MISSING_FONTS = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList( "NotoSansHans-Regular.otf", "NotoSansHant-Regular.otf", "NotoSansJP-Regular.otf", "NotoSansKR-Regular.otf" ))); /** * A class associating {@link Font} with its metadata. */ Loading Loading @@ -82,6 +94,8 @@ public class FontFamily_Delegate { private FontVariant mVariant; // Path of fonts that haven't been created since sFontLoader hasn't been initialized. private List<String> mPath = new ArrayList<String>(); /** @see #isValid() */ private boolean mValid = false; // ---- Public helper class ---- Loading Loading @@ -132,6 +146,16 @@ public class FontFamily_Delegate { return mVariant; } /** * Returns if the FontFamily should contain any fonts. If this returns true and * {@link #getFont(int)} returns an empty list, it means that an error occurred while loading * the fonts. However, some fonts are deliberately skipped, for example they are not bundled * with the SDK. In such a case, this method returns false. */ public boolean isValid() { return mValid; } /*package*/ static int getFontStyle(String path) { int style = Font.PLAIN; String fontName = path.substring(path.lastIndexOf('/')); Loading Loading @@ -201,6 +225,13 @@ public class FontFamily_Delegate { /*package*/ static boolean nAddFont(long nativeFamily, String path) { FontFamily_Delegate delegate = getDelegate(nativeFamily); if (delegate != null) { // If the font to be added is known to be missing from the SDK, don't try to load it and // mark the FontFamily to be not valid. if (path.startsWith(SYSTEM_FONTS) && MISSING_FONTS.contains(path.substring(SYSTEM_FONTS.length()))) { return delegate.mValid = false; } delegate.mValid = true; if (sFontLocation == null) { delegate.mPath.add(path); return true; Loading tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java +8 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,8 @@ public class Paint_Delegate { new DelegateManager<Paint_Delegate>(Paint_Delegate.class); // ---- delegate helper data ---- // This list can contain null elements. private List<FontInfo> mFonts; // ---- delegate data ---- Loading Loading @@ -1171,6 +1173,12 @@ public class Paint_Delegate { // and skew info. ArrayList<FontInfo> infoList = new ArrayList<FontInfo>(fonts.size()); for (Font font : fonts) { if (font == null) { // If the font is null, add null to infoList. When rendering the text, if this // null is reached, a warning will be logged. infoList.add(null); continue; } FontInfo info = new FontInfo(); info.mFont = font.deriveFont(mTextSize); if (mTextScaleX != 1.0 || mTextSkewX != 0) { Loading tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java +11 −1 Original line number Diff line number Diff line Loading @@ -74,6 +74,10 @@ public final class Typeface_Delegate { * 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} */ Loading @@ -83,7 +87,7 @@ public final class Typeface_Delegate { List<Font> fonts = new ArrayList<Font>(mFontFamilies.length); for (int i = 0; i < mFontFamilies.length; i++) { FontFamily_Delegate ffd = mFontFamilies[i]; if (ffd != null) { if (ffd != null && ffd.isValid()) { Font font = ffd.getFont(mStyle); if (font != null) { FontVariant ffdVariant = ffd.getVariant(); Loading @@ -107,6 +111,12 @@ public final class Typeface_Delegate { } 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); } } } Loading Loading
tools/layoutlib/bridge/src/android/graphics/BidiRenderer.java +4 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,10 @@ public class BidiRenderer { mText = text; mFonts = new ArrayList<Font>(paint.getFonts().size()); for (FontInfo fontInfo : paint.getFonts()) { if (fontInfo == null) { mFonts.add(null); continue; } mFonts.add(fontInfo.mFont); } mBounds = new RectF(); Loading
tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java +31 −0 Original line number Diff line number Diff line Loading @@ -27,7 +27,11 @@ import java.awt.Font; import java.awt.FontFormatException; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import static android.graphics.Typeface_Delegate.SYSTEM_FONTS; Loading @@ -51,6 +55,14 @@ public class FontFamily_Delegate { private static final String FONT_SUFFIX_BOLD = "Bold.ttf"; private static final String FONT_SUFFIX_ITALIC = "Italic.ttf"; private static final Set<String> MISSING_FONTS = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList( "NotoSansHans-Regular.otf", "NotoSansHant-Regular.otf", "NotoSansJP-Regular.otf", "NotoSansKR-Regular.otf" ))); /** * A class associating {@link Font} with its metadata. */ Loading Loading @@ -82,6 +94,8 @@ public class FontFamily_Delegate { private FontVariant mVariant; // Path of fonts that haven't been created since sFontLoader hasn't been initialized. private List<String> mPath = new ArrayList<String>(); /** @see #isValid() */ private boolean mValid = false; // ---- Public helper class ---- Loading Loading @@ -132,6 +146,16 @@ public class FontFamily_Delegate { return mVariant; } /** * Returns if the FontFamily should contain any fonts. If this returns true and * {@link #getFont(int)} returns an empty list, it means that an error occurred while loading * the fonts. However, some fonts are deliberately skipped, for example they are not bundled * with the SDK. In such a case, this method returns false. */ public boolean isValid() { return mValid; } /*package*/ static int getFontStyle(String path) { int style = Font.PLAIN; String fontName = path.substring(path.lastIndexOf('/')); Loading Loading @@ -201,6 +225,13 @@ public class FontFamily_Delegate { /*package*/ static boolean nAddFont(long nativeFamily, String path) { FontFamily_Delegate delegate = getDelegate(nativeFamily); if (delegate != null) { // If the font to be added is known to be missing from the SDK, don't try to load it and // mark the FontFamily to be not valid. if (path.startsWith(SYSTEM_FONTS) && MISSING_FONTS.contains(path.substring(SYSTEM_FONTS.length()))) { return delegate.mValid = false; } delegate.mValid = true; if (sFontLocation == null) { delegate.mPath.add(path); return true; Loading
tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java +8 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,8 @@ public class Paint_Delegate { new DelegateManager<Paint_Delegate>(Paint_Delegate.class); // ---- delegate helper data ---- // This list can contain null elements. private List<FontInfo> mFonts; // ---- delegate data ---- Loading Loading @@ -1171,6 +1173,12 @@ public class Paint_Delegate { // and skew info. ArrayList<FontInfo> infoList = new ArrayList<FontInfo>(fonts.size()); for (Font font : fonts) { if (font == null) { // If the font is null, add null to infoList. When rendering the text, if this // null is reached, a warning will be logged. infoList.add(null); continue; } FontInfo info = new FontInfo(); info.mFont = font.deriveFont(mTextSize); if (mTextScaleX != 1.0 || mTextSkewX != 0) { Loading
tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java +11 −1 Original line number Diff line number Diff line Loading @@ -74,6 +74,10 @@ public final class Typeface_Delegate { * 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} */ Loading @@ -83,7 +87,7 @@ public final class Typeface_Delegate { List<Font> fonts = new ArrayList<Font>(mFontFamilies.length); for (int i = 0; i < mFontFamilies.length; i++) { FontFamily_Delegate ffd = mFontFamilies[i]; if (ffd != null) { if (ffd != null && ffd.isValid()) { Font font = ffd.getFont(mStyle); if (font != null) { FontVariant ffdVariant = ffd.getVariant(); Loading @@ -107,6 +111,12 @@ public final class Typeface_Delegate { } 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); } } } Loading