Java Code Examples for android.graphics.Typeface#isBold()
The following examples show how to use
android.graphics.Typeface#isBold() .
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: WheelView.java From WheelPicker with Apache License 2.0 | 5 votes |
/** * 设置当前字体 * * @param typeface 字体 * @param isBoldForSelectedItem 是否设置选中条目字体加粗,其他条目不会加粗 */ public void setTypeface(Typeface typeface, boolean isBoldForSelectedItem) { if (typeface == null || mPaint.getTypeface() == typeface) { return; } //强制滚动完成 forceFinishScroll(); mIsBoldForSelectedItem = isBoldForSelectedItem; if (mIsBoldForSelectedItem) { //如果设置了选中条目字体加粗,其他条目不会加粗,则拆分两份字体 if (typeface.isBold()) { mNormalTypeface = Typeface.create(typeface, Typeface.NORMAL); mBoldTypeface = typeface; } else { mNormalTypeface = typeface; mBoldTypeface = Typeface.create(typeface, Typeface.BOLD); } //测量时 使用加粗字体测量,因为加粗字体比普通字体宽,以大的为准进行测量 mPaint.setTypeface(mBoldTypeface); } else { mPaint.setTypeface(typeface); } calculateTextSize(); calculateDrawStart(); //字体大小变化,偏移距离也变化了 mScrollOffsetY = mSelectedItemPosition * mItemHeight; calculateLimitY(); requestLayout(); invalidate(); }
Example 2
Source File: TypefaceResourceSpan.java From md2tv with MIT License | 5 votes |
@Override public void updateMeasureState(TextPaint p) { Typeface old=p.getTypeface(); if ( old != null && !old.isBold() && tf_.isBold() ) { p.setFakeBoldText(true); } if ( old != null && !old.isItalic() && tf_.isItalic() ) { p.setTextSkewX(-0.25f); } p.setTypeface(tf_); }
Example 3
Source File: TypefaceResourceSpan.java From md2tv with MIT License | 5 votes |
@Override public void updateDrawState(TextPaint tp) { Typeface old=tp.getTypeface(); if ( old != null && !old.isBold() && tf_.isBold() ) { tp.setFakeBoldText(true); } if ( old != null && !old.isItalic() && tf_.isItalic() ) { tp.setTextSkewX(-0.25f); } tp.setTypeface(tf_); }
Example 4
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); } }