Java Code Examples for android.graphics.Paint#getTypeface()

The following examples show how to use android.graphics.Paint#getTypeface() . 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: TypefaceSpan.java    From JotaTextEditor with Apache License 2.0 6 votes vote down vote up
private static void apply(Paint paint, String family) {
    int oldStyle;

    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    Typeface tf = Typeface.create(family, oldStyle);
    int fake = oldStyle & ~tf.getStyle();

    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 2
Source File: CustomTypefaceSpan.java    From DeviceInfo with Apache License 2.0 6 votes vote down vote up
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 3
Source File: CustomTypefaceSpan.java    From Cook-It-Android-XML-Template with MIT License 6 votes vote down vote up
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 4
Source File: TextUtils.java    From glimmr with Apache License 2.0 6 votes vote down vote up
private void applyCustomTypeface(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }
    paint.setTypeface(tf);
}
 
Example 5
Source File: RobotoLightTypefaceSpan.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 6
Source File: JavaFontRenderingBox.java    From AndroidMathKeyboard with Apache License 2.0 6 votes vote down vote up
public void draw(Canvas g2, float x, float y) {
		drawDebug(g2, x, y);
//		Paint st=AjLatexMath.getPaint();
//		st.setTextSize(AjLatexMath.getTextSize());
		Paint st =new Paint();
		float w = st.getStrokeWidth();
		Style s = st.getStyle();
		Typeface f = st.getTypeface();
		st.setStrokeWidth(0);//
		st.setStyle(Style.FILL_AND_STROKE);
		st.setTypeface(font);
		g2.save();
		g2.translate(x, y);
		g2.scale(0.5f * size, 0.5f * size);
//		g2.drawText(str, x, y, st);
		g2.drawText(str, 0, 0, st);
		g2.restore();
		st.setStyle(s);
		st.setStrokeWidth(w);
		st.setTypeface(f);
	}
 
Example 7
Source File: CustomTypefaceSpan.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 8
Source File: CalligraphyTypefaceSpan.java    From Calligraphy with Apache License 2.0 5 votes vote down vote up
private void apply(final Paint paint) {
    final Typeface oldTypeface = paint.getTypeface();
    final int oldStyle = oldTypeface != null ? oldTypeface.getStyle() : 0;
    final int fakeStyle = oldStyle & ~typeface.getStyle();

    if ((fakeStyle & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fakeStyle & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(typeface);
}
 
Example 9
Source File: TypefaceSpan.java    From memoir with Apache License 2.0 5 votes vote down vote up
private void applyCustomTypeFace(Paint paint, Typeface tf) {
    Typeface old = paint.getTypeface();
    int oldStyle = old == null ? 0 : old.getStyle();

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 10
Source File: TypefaceUtils.java    From simple-keyboard with Apache License 2.0 5 votes vote down vote up
private static int getCharGeometryCacheKey(final char referenceChar, final Paint paint) {
    final int labelSize = (int)paint.getTextSize();
    final Typeface face = paint.getTypeface();
    final int codePointOffset = referenceChar << 15;
    if (face == Typeface.DEFAULT) {
        return codePointOffset + labelSize;
    } else if (face == Typeface.DEFAULT_BOLD) {
        return codePointOffset + labelSize + 0x1000;
    } else if (face == Typeface.MONOSPACE) {
        return codePointOffset + labelSize + 0x2000;
    } else {
        return codePointOffset + labelSize;
    }
}
 
Example 11
Source File: FontPreferenceCompat.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
private void apply(final Paint paint) {
    final Typeface oldTypeface = paint.getTypeface();
    final int oldStyle = oldTypeface != null ? oldTypeface.getStyle() : 0;
    final int fakeStyle = oldStyle & ~_typeface.getStyle();

    if ((fakeStyle & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fakeStyle & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(_typeface);
}
 
Example 12
Source File: WXCustomStyleSpan.java    From weex with Apache License 2.0 5 votes vote down vote up
private static void apply(Paint paint, int style, int weight, String family) {
  int oldStyle;
  Typeface typeface = paint.getTypeface();
  if (typeface == null) {
    oldStyle = 0;
  } else {
    oldStyle = typeface.getStyle();
  }

  int want = 0;
  if ((weight == Typeface.BOLD)
      || ((oldStyle & Typeface.BOLD) != 0 && weight == WXStyle.UNSET)) {
    want |= Typeface.BOLD;
  }

  if ((style == Typeface.ITALIC)
      || ((oldStyle & Typeface.ITALIC) != 0 && style == WXStyle.UNSET)) {
    want |= Typeface.ITALIC;
  }

  if (family != null) {
    typeface = getOrCreateTypeface(family, want);
  }

  if (typeface != null) {
    paint.setTypeface(Typeface.create(typeface, want));
  } else {
    paint.setTypeface(Typeface.defaultFromStyle(want));
  }
}
 
Example 13
Source File: TypefaceSpan.java    From Android-RTEditor with Apache License 2.0 5 votes vote down vote up
private void applyCustomTypeFace(Paint paint, Typeface tf) {
    Typeface old = paint.getTypeface();
    int oldStyle = old == null ? 0 : old.getStyle();

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 14
Source File: StyleSpan.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static void apply(Paint paint, int style) {
    int oldStyle;

    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int want = oldStyle | style;

    Typeface tf;
    if (old == null) {
        tf = Typeface.defaultFromStyle(want);
    } else {
        tf = Typeface.create(old, want);
    }

    int fake = want & ~tf.getStyle();

    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 15
Source File: HtmlHelper.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    Typeface old = paint.getTypeface();
    int oldStyle = (old == null ? 0 : old.getStyle());
    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0)
        paint.setFakeBoldText(true);
    if ((fake & Typeface.ITALIC) != 0)
        paint.setTextSkewX(-0.25f);
    paint.setTypeface(tf);
}
 
Example 16
Source File: Trestle.java    From Trestle with Apache License 2.0 5 votes vote down vote up
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    Typeface old = paint.getTypeface();
    int oldStyle = old == null ? 0 : old.getStyle();

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 17
Source File: AndroidEmoji.java    From Faceless with GNU General Public License v3.0 5 votes vote down vote up
private void apply(final Paint paint) {
	final Typeface oldTypeface = paint.getTypeface();
	final int oldStyle = oldTypeface != null ? oldTypeface.getStyle() : 0;
	final int fakeStyle = oldStyle & ~mTypeface.getStyle();
	
	if ((fakeStyle & Typeface.BOLD) != 0) {
		paint.setFakeBoldText(true);
	}
	
	if ((fakeStyle & Typeface.ITALIC) != 0) {
		paint.setTextSkewX(-0.25f);
	}
	
	paint.setTypeface(mTypeface);
}
 
Example 18
Source File: TypefaceUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
private static int getCharGeometryCacheKey(final char referenceChar, final Paint paint) {
    final int labelSize = (int)paint.getTextSize();
    final Typeface face = paint.getTypeface();
    final int codePointOffset = referenceChar << 15;
    if (face == Typeface.DEFAULT) {
        return codePointOffset + labelSize;
    } else if (face == Typeface.DEFAULT_BOLD) {
        return codePointOffset + labelSize + 0x1000;
    } else if (face == Typeface.MONOSPACE) {
        return codePointOffset + labelSize + 0x2000;
    } else {
        return codePointOffset + labelSize;
    }
}
 
Example 19
Source File: CustomTypefaceSpan.java    From custom-typeface with Apache License 2.0 5 votes vote down vote up
private void apply(Paint paint) {
    Typeface oldTypeface = paint.getTypeface();
    int oldStyle = oldTypeface != null ? oldTypeface.getStyle() : 0;
    int fakeStyle = oldStyle &~ mTypeface.getStyle();

    if ((fakeStyle & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fakeStyle & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(mTypeface);
}
 
Example 20
Source File: HeadSpan.java    From RichEditor with MIT License 5 votes vote down vote up
private static void applyStyle(Paint paint) {
    int style = Typeface.BOLD;
    int oldStyle;

    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int want = oldStyle | style;

    Typeface tf;
    if (old == null) {
        tf = Typeface.defaultFromStyle(want);
    } else {
        tf = Typeface.create(old, want);
    }

    int fake = want & ~tf.getStyle();

    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}