Loading tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java +6 −2 Original line number Original line Diff line number Diff line Loading @@ -178,7 +178,9 @@ public class FontFamily_Delegate { desiredStyle.mIsItalic = isItalic; desiredStyle.mIsItalic = isItalic; FontInfo bestFont = null; FontInfo bestFont = null; int bestMatch = Integer.MAX_VALUE; int bestMatch = Integer.MAX_VALUE; for (FontInfo font : mFonts) { //noinspection ForLoopReplaceableByForEach (avoid iterator instantiation) for (int i = 0, n = mFonts.size(); i < n; i++) { FontInfo font = mFonts.get(i); int match = computeMatch(font, desiredStyle); int match = computeMatch(font, desiredStyle); if (match < bestMatch) { if (match < bestMatch) { bestMatch = match; bestMatch = match; Loading Loading @@ -415,7 +417,9 @@ public class FontFamily_Delegate { boolean isItalic = fontInfo.mIsItalic; boolean isItalic = fontInfo.mIsItalic; // The list is usually just two fonts big. So iterating over all isn't as bad as it looks. // The list is usually just two fonts big. So iterating over all isn't as bad as it looks. // It's biggest for roboto where the size is 12. // It's biggest for roboto where the size is 12. for (FontInfo font : mFonts) { //noinspection ForLoopReplaceableByForEach (avoid iterator instantiation) for (int i = 0, n = mFonts.size(); i < n; i++) { FontInfo font = mFonts.get(i); if (font.mWeight == weight && font.mIsItalic == isItalic) { if (font.mWeight == weight && font.mIsItalic == isItalic) { return false; return false; } } Loading tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java +55 −17 Original line number Original line Diff line number Diff line Loading @@ -480,9 +480,11 @@ public class Paint_Delegate { return; return; } } if (delegate.mTextSize != textSize) { delegate.mTextSize = textSize; delegate.mTextSize = textSize; delegate.updateFontObject(); delegate.updateFontObject(); } } } @LayoutlibDelegate @LayoutlibDelegate /*package*/ static float getTextScaleX(Paint thisPaint) { /*package*/ static float getTextScaleX(Paint thisPaint) { Loading @@ -503,9 +505,11 @@ public class Paint_Delegate { return; return; } } if (delegate.mTextScaleX != scaleX) { delegate.mTextScaleX = scaleX; delegate.mTextScaleX = scaleX; delegate.updateFontObject(); delegate.updateFontObject(); } } } @LayoutlibDelegate @LayoutlibDelegate /*package*/ static float getTextSkewX(Paint thisPaint) { /*package*/ static float getTextSkewX(Paint thisPaint) { Loading @@ -526,9 +530,11 @@ public class Paint_Delegate { return; return; } } if (delegate.mTextSkewX != skewX) { delegate.mTextSkewX = skewX; delegate.mTextSkewX = skewX; delegate.updateFontObject(); delegate.updateFontObject(); } } } @LayoutlibDelegate @LayoutlibDelegate /*package*/ static float ascent(Paint thisPaint) { /*package*/ static float ascent(Paint thisPaint) { Loading Loading @@ -897,9 +903,12 @@ public class Paint_Delegate { return 0; return 0; } } Typeface_Delegate typefaceDelegate = Typeface_Delegate.getDelegate(typeface); if (delegate.mTypeface != typefaceDelegate || delegate.mNativeTypeface != typeface) { delegate.mTypeface = Typeface_Delegate.getDelegate(typeface); delegate.mTypeface = Typeface_Delegate.getDelegate(typeface); delegate.mNativeTypeface = typeface; delegate.mNativeTypeface = typeface; delegate.updateFontObject(); delegate.updateFontObject(); } return typeface; return typeface; } } Loading Loading @@ -1214,13 +1223,31 @@ public class Paint_Delegate { mCap = paint.mCap; mCap = paint.mCap; mJoin = paint.mJoin; mJoin = paint.mJoin; mTextAlign = paint.mTextAlign; mTextAlign = paint.mTextAlign; boolean needsFontUpdate = false; if (mTypeface != paint.mTypeface || mNativeTypeface != paint.mNativeTypeface) { mTypeface = paint.mTypeface; mTypeface = paint.mTypeface; mNativeTypeface = paint.mNativeTypeface; mNativeTypeface = paint.mNativeTypeface; mStrokeWidth = paint.mStrokeWidth; needsFontUpdate = true; mStrokeMiter = paint.mStrokeMiter; } if (mTextSize != paint.mTextSize) { mTextSize = paint.mTextSize; mTextSize = paint.mTextSize; needsFontUpdate = true; } if (mTextScaleX != paint.mTextScaleX) { mTextScaleX = paint.mTextScaleX; mTextScaleX = paint.mTextScaleX; needsFontUpdate = true; } if (mTextSkewX != paint.mTextSkewX) { mTextSkewX = paint.mTextSkewX; mTextSkewX = paint.mTextSkewX; needsFontUpdate = true; } mStrokeWidth = paint.mStrokeWidth; mStrokeMiter = paint.mStrokeMiter; mXfermode = paint.mXfermode; mXfermode = paint.mXfermode; mColorFilter = paint.mColorFilter; mColorFilter = paint.mColorFilter; mShader = paint.mShader; mShader = paint.mShader; Loading @@ -1228,8 +1255,11 @@ public class Paint_Delegate { mMaskFilter = paint.mMaskFilter; mMaskFilter = paint.mMaskFilter; mRasterizer = paint.mRasterizer; mRasterizer = paint.mRasterizer; mHintingMode = paint.mHintingMode; mHintingMode = paint.mHintingMode; if (needsFontUpdate) { updateFontObject(); updateFontObject(); } } } private void reset() { private void reset() { mFlags = Paint.HIDDEN_DEFAULT_PAINT_FLAGS; mFlags = Paint.HIDDEN_DEFAULT_PAINT_FLAGS; Loading Loading @@ -1264,10 +1294,18 @@ public class Paint_Delegate { // Get the fonts from the TypeFace object. // Get the fonts from the TypeFace object. List<Font> fonts = mTypeface.getFonts(mFontVariant); List<Font> fonts = mTypeface.getFonts(mFontVariant); if (fonts.isEmpty()) { mFonts = Collections.emptyList(); return; } // create new font objects as well as FontMetrics, based on the current text size // create new font objects as well as FontMetrics, based on the current text size // and skew info. // and skew info. ArrayList<FontInfo> infoList = new ArrayList<FontInfo>(fonts.size()); int nFonts = fonts.size(); for (Font font : fonts) { ArrayList<FontInfo> infoList = new ArrayList<FontInfo>(nFonts); //noinspection ForLoopReplaceableByForEach (avoid iterator instantiation) for (int i = 0; i < nFonts; i++) { Font font = fonts.get(i); if (font == null) { if (font == null) { // If the font is null, add null to infoList. When rendering the text, if this // If the font is null, add null to infoList. When rendering the text, if this // null is reached, a warning will be logged. // null is reached, a warning will be logged. Loading Loading
tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java +6 −2 Original line number Original line Diff line number Diff line Loading @@ -178,7 +178,9 @@ public class FontFamily_Delegate { desiredStyle.mIsItalic = isItalic; desiredStyle.mIsItalic = isItalic; FontInfo bestFont = null; FontInfo bestFont = null; int bestMatch = Integer.MAX_VALUE; int bestMatch = Integer.MAX_VALUE; for (FontInfo font : mFonts) { //noinspection ForLoopReplaceableByForEach (avoid iterator instantiation) for (int i = 0, n = mFonts.size(); i < n; i++) { FontInfo font = mFonts.get(i); int match = computeMatch(font, desiredStyle); int match = computeMatch(font, desiredStyle); if (match < bestMatch) { if (match < bestMatch) { bestMatch = match; bestMatch = match; Loading Loading @@ -415,7 +417,9 @@ public class FontFamily_Delegate { boolean isItalic = fontInfo.mIsItalic; boolean isItalic = fontInfo.mIsItalic; // The list is usually just two fonts big. So iterating over all isn't as bad as it looks. // The list is usually just two fonts big. So iterating over all isn't as bad as it looks. // It's biggest for roboto where the size is 12. // It's biggest for roboto where the size is 12. for (FontInfo font : mFonts) { //noinspection ForLoopReplaceableByForEach (avoid iterator instantiation) for (int i = 0, n = mFonts.size(); i < n; i++) { FontInfo font = mFonts.get(i); if (font.mWeight == weight && font.mIsItalic == isItalic) { if (font.mWeight == weight && font.mIsItalic == isItalic) { return false; return false; } } Loading
tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java +55 −17 Original line number Original line Diff line number Diff line Loading @@ -480,9 +480,11 @@ public class Paint_Delegate { return; return; } } if (delegate.mTextSize != textSize) { delegate.mTextSize = textSize; delegate.mTextSize = textSize; delegate.updateFontObject(); delegate.updateFontObject(); } } } @LayoutlibDelegate @LayoutlibDelegate /*package*/ static float getTextScaleX(Paint thisPaint) { /*package*/ static float getTextScaleX(Paint thisPaint) { Loading @@ -503,9 +505,11 @@ public class Paint_Delegate { return; return; } } if (delegate.mTextScaleX != scaleX) { delegate.mTextScaleX = scaleX; delegate.mTextScaleX = scaleX; delegate.updateFontObject(); delegate.updateFontObject(); } } } @LayoutlibDelegate @LayoutlibDelegate /*package*/ static float getTextSkewX(Paint thisPaint) { /*package*/ static float getTextSkewX(Paint thisPaint) { Loading @@ -526,9 +530,11 @@ public class Paint_Delegate { return; return; } } if (delegate.mTextSkewX != skewX) { delegate.mTextSkewX = skewX; delegate.mTextSkewX = skewX; delegate.updateFontObject(); delegate.updateFontObject(); } } } @LayoutlibDelegate @LayoutlibDelegate /*package*/ static float ascent(Paint thisPaint) { /*package*/ static float ascent(Paint thisPaint) { Loading Loading @@ -897,9 +903,12 @@ public class Paint_Delegate { return 0; return 0; } } Typeface_Delegate typefaceDelegate = Typeface_Delegate.getDelegate(typeface); if (delegate.mTypeface != typefaceDelegate || delegate.mNativeTypeface != typeface) { delegate.mTypeface = Typeface_Delegate.getDelegate(typeface); delegate.mTypeface = Typeface_Delegate.getDelegate(typeface); delegate.mNativeTypeface = typeface; delegate.mNativeTypeface = typeface; delegate.updateFontObject(); delegate.updateFontObject(); } return typeface; return typeface; } } Loading Loading @@ -1214,13 +1223,31 @@ public class Paint_Delegate { mCap = paint.mCap; mCap = paint.mCap; mJoin = paint.mJoin; mJoin = paint.mJoin; mTextAlign = paint.mTextAlign; mTextAlign = paint.mTextAlign; boolean needsFontUpdate = false; if (mTypeface != paint.mTypeface || mNativeTypeface != paint.mNativeTypeface) { mTypeface = paint.mTypeface; mTypeface = paint.mTypeface; mNativeTypeface = paint.mNativeTypeface; mNativeTypeface = paint.mNativeTypeface; mStrokeWidth = paint.mStrokeWidth; needsFontUpdate = true; mStrokeMiter = paint.mStrokeMiter; } if (mTextSize != paint.mTextSize) { mTextSize = paint.mTextSize; mTextSize = paint.mTextSize; needsFontUpdate = true; } if (mTextScaleX != paint.mTextScaleX) { mTextScaleX = paint.mTextScaleX; mTextScaleX = paint.mTextScaleX; needsFontUpdate = true; } if (mTextSkewX != paint.mTextSkewX) { mTextSkewX = paint.mTextSkewX; mTextSkewX = paint.mTextSkewX; needsFontUpdate = true; } mStrokeWidth = paint.mStrokeWidth; mStrokeMiter = paint.mStrokeMiter; mXfermode = paint.mXfermode; mXfermode = paint.mXfermode; mColorFilter = paint.mColorFilter; mColorFilter = paint.mColorFilter; mShader = paint.mShader; mShader = paint.mShader; Loading @@ -1228,8 +1255,11 @@ public class Paint_Delegate { mMaskFilter = paint.mMaskFilter; mMaskFilter = paint.mMaskFilter; mRasterizer = paint.mRasterizer; mRasterizer = paint.mRasterizer; mHintingMode = paint.mHintingMode; mHintingMode = paint.mHintingMode; if (needsFontUpdate) { updateFontObject(); updateFontObject(); } } } private void reset() { private void reset() { mFlags = Paint.HIDDEN_DEFAULT_PAINT_FLAGS; mFlags = Paint.HIDDEN_DEFAULT_PAINT_FLAGS; Loading Loading @@ -1264,10 +1294,18 @@ public class Paint_Delegate { // Get the fonts from the TypeFace object. // Get the fonts from the TypeFace object. List<Font> fonts = mTypeface.getFonts(mFontVariant); List<Font> fonts = mTypeface.getFonts(mFontVariant); if (fonts.isEmpty()) { mFonts = Collections.emptyList(); return; } // create new font objects as well as FontMetrics, based on the current text size // create new font objects as well as FontMetrics, based on the current text size // and skew info. // and skew info. ArrayList<FontInfo> infoList = new ArrayList<FontInfo>(fonts.size()); int nFonts = fonts.size(); for (Font font : fonts) { ArrayList<FontInfo> infoList = new ArrayList<FontInfo>(nFonts); //noinspection ForLoopReplaceableByForEach (avoid iterator instantiation) for (int i = 0; i < nFonts; i++) { Font font = fonts.get(i); if (font == null) { if (font == null) { // If the font is null, add null to infoList. When rendering the text, if this // If the font is null, add null to infoList. When rendering the text, if this // null is reached, a warning will be logged. // null is reached, a warning will be logged. Loading