com.facebook.react.views.text.ReactFontManager Java Examples
The following examples show how to use
com.facebook.react.views.text.ReactFontManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextImagePostProcessor.java From react-native-image-filter-kit with MIT License | 6 votes |
public TextImagePostProcessor( int width, int height, @Nullable JSONObject config, final Context context ) { super(width, height, config); InputConverter converter = new InputConverter(width, height); mText = converter.convertText(config, "text", ""); mFontName = converter.convertText(config, "fontName", null); mFontSize = converter.convertDistance(config, "fontSize", "16"); mColor = converter.convertColor(config, "color", Color.BLACK); mTypeface = ReactFontManager.getInstance() .getTypeface(mFontName, Typeface.NORMAL, context.getAssets()); }
Example #2
Source File: ReactAztecManager.java From react-native-aztec with GNU General Public License v2.0 | 5 votes |
@ReactProp(name = ViewProps.FONT_FAMILY) public void setFontFamily(ReactAztecText view, String fontFamily) { int style = Typeface.NORMAL; if (view.getTypeface() != null) { style = view.getTypeface().getStyle(); } Typeface newTypeface = ReactFontManager.getInstance().getTypeface( fontFamily, style, view.getContext().getAssets()); view.setTypeface(newTypeface); }
Example #3
Source File: RNTextSizeConf.java From react-native-text-size with BSD 2-Clause "Simplified" License | 5 votes |
/** * Make a Typeface from the supplied font family and style. */ @Nonnull static Typeface getFont( @Nonnull final ReactApplicationContext context, @Nullable String family, final int style ) { final Typeface typeface = family != null ? ReactFontManager.getInstance().getTypeface(family, style, context.getAssets()) : null; return typeface != null ? typeface : Typeface.defaultFromStyle(style); }
Example #4
Source File: ReactTextInputManager.java From react-native-GPay with MIT License | 5 votes |
@ReactProp(name = ViewProps.FONT_FAMILY) public void setFontFamily(ReactEditText view, String fontFamily) { int style = Typeface.NORMAL; if (view.getTypeface() != null) { style = view.getTypeface().getStyle(); } Typeface newTypeface = ReactFontManager.getInstance().getTypeface( fontFamily, style, view.getContext().getAssets()); view.setTypeface(newTypeface); }
Example #5
Source File: CollapsingToolbarLayoutManager.java From react-native-collapsing-toolbar with MIT License | 5 votes |
@ReactProp(name = "collapsedTitleTypeface") public void setCollapsedTitleTypeface(CollapsingToolbarLayoutView view, String font) { try { Typeface face = ReactFontManager.getInstance().getTypeface(font, Typeface.NORMAL, view.getContext().getAssets()); view.setCollapsedTitleTypeface(face); } catch (Exception e) { } }
Example #6
Source File: CollapsingToolbarLayoutManager.java From react-native-collapsing-toolbar with MIT License | 5 votes |
@ReactProp(name = "expandedTitleTypeface") public void setExpandedTitleTypeface(CollapsingToolbarLayoutView view, String font) { try { Typeface face = ReactFontManager.getInstance().getTypeface(font, Typeface.NORMAL, view.getContext().getAssets()); view.setExpandedTitleTypeface(face); } catch (Exception e) { } }
Example #7
Source File: DynamicFontsModule.java From react-native-dynamic-fonts with MIT License | 5 votes |
@ReactMethod public void loadFontFromFile(final ReadableMap options, final Callback callback) { Activity currentActivity = getCurrentActivity(); if (currentActivity == null) { callback.invoke("Invalid activity"); return; } String filePath = options.hasKey("filePath") ? options.getString("filePath") : null, name = (options.hasKey("name")) ? options.getString("name") : null; if (filePath == null || filePath.length() == 0) { callback.invoke("filePath property empty"); return; } File f = new File(filePath); if (f.exists() && f.canRead()) { boolean wasLoaded = false; try { Typeface typeface = Typeface.createFromFile(f); //Cache the font for react ReactFontManager.getInstance().setTypeface(name, typeface.getStyle(), typeface); wasLoaded = true; } catch (Throwable e) { callback.invoke(e.getMessage()); } finally { if (wasLoaded) { callback.invoke(null, name); } } } else { callback.invoke("invalid file"); } }
Example #8
Source File: BridgeUtils.java From react-native-mp-android-chart with MIT License | 5 votes |
/** * fontStyle: NORMAL = 0, BOLD = 1, ITALIC = 2, BOLD_ITALIC = 3 */ public static Typeface parseTypeface(Context context, ReadableMap propMap, String styleKey, String familyKey) { String fontFamily = null; if (propMap.hasKey(familyKey)) { fontFamily = propMap.getString(familyKey); } int style = 0; if (propMap.hasKey(styleKey)) { style = propMap.getInt(styleKey); } return ReactFontManager.getInstance().getTypeface(fontFamily, style, context.getAssets()); }
Example #9
Source File: DynamicFontsModule.java From react-native-dynamic-fonts with MIT License | 4 votes |
@ReactMethod public void loadFont(final ReadableMap options, final Callback callback) throws Exception { Activity currentActivity = getCurrentActivity(); if (currentActivity == null) { callback.invoke("Invalid activity"); return; } String name = (options.hasKey("name")) ? options.getString("name") : null, data = (options.hasKey("data")) ? options.getString("data") : null, type = null; if (name == null || name.length() == 0) { callback.invoke("Name property empty"); return; } if (data == null || data.length() == 0) { callback.invoke("Data property empty"); return; } if (("data:").equalsIgnoreCase(data.substring(0, 5))) { Integer pos = data.indexOf(','); if (pos > 0) { String[] encodingParams = data.substring(5, pos).split(";"); String mimeType = encodingParams[0]; data = data.substring(pos + 1); if (("application/x-font-ttf").equalsIgnoreCase(mimeType) || ("application/x-font-truetype").equalsIgnoreCase(mimeType) || ("font/ttf").equalsIgnoreCase(mimeType)) { type = "ttf"; } else if (("application/x-font-opentype").equalsIgnoreCase(mimeType) || ("font/opentype").equalsIgnoreCase(mimeType)) { type = "otf"; } } } if (options.hasKey("type")) type = options.getString("type"); if (type == null) type = "ttf"; try { byte[] decodedBytes = Base64.decode(data, Base64.DEFAULT); File cacheFile = new File(currentActivity.getCacheDir(), "tempFont" + (tempNameCounter++) + type); FileOutputStream stream = new FileOutputStream(cacheFile); try { stream.write(decodedBytes); } finally { stream.close(); } //Load the font from the temporary file we just created Typeface typeface = Typeface.createFromFile(cacheFile); if (typeface.isBold()) name = name + "_bold"; if (typeface.isItalic()) name = name + "_italic"; //Cache the font for react ReactFontManager.getInstance().setTypeface(name, typeface.getStyle(), typeface); cacheFile.delete(); } catch(Exception e) { callback.invoke(e.getMessage()); } finally { callback.invoke(null, name); } }