From 17fcc9440f9f6f6bbed9c746cb035dd3c4716355 Mon Sep 17 00:00:00 2001 From: sospartan Date: Mon, 8 Feb 2016 10:09:15 -0800 Subject: [PATCH] allow use external typeface in native code Summary: Expose method to implement changing font family cache. Like ide suggested in #4420 , this will helpful for using remote font file (use `Typeface#createFromFile` to load downloaded font file). iOS's CoreText already allow this in native code. Closes https://github.com/facebook/react-native/pull/4696 Reviewed By: bestander Differential Revision: D2911762 Pulled By: andreicoman11 fb-gh-sync-id: a931e2e711dd94fa0df6fdd066827756d862a4ba --- .../react/views/text/ReactFontManager.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java index 10e2a4d7b..1e63a2094 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java @@ -72,6 +72,25 @@ public class ReactFontManager { return typeface; } + /** + * Add additional font family, or replace the exist one in the font memory cache. + * @param style + * @see {@link Typeface#DEFAULT} + * @see {@link Typeface#BOLD} + * @see {@link Typeface#ITALIC} + * @see {@link Typeface#BOLD_ITALIC} + */ + public void setTypeface(String fontFamilyName, int style, Typeface typeface) { + if (typeface != null) { + FontFamily fontFamily = mFontCache.get(fontFamilyName); + if (fontFamily == null) { + fontFamily = new FontFamily(); + mFontCache.put(fontFamilyName, fontFamily); + } + fontFamily.setTypeface(style, typeface); + } + } + private static @Nullable Typeface createTypeface( String fontFamilyName,