-
Notifications
You must be signed in to change notification settings - Fork 0
/
TypefaceSpan.java
39 lines (31 loc) · 1.27 KB
/
TypefaceSpan.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.trindade.about.activity.model;
import android.util.LruCache;
import android.graphics.Typeface;
import android.text.style.MetricAffectingSpan;
import android.content.Context;
import android.text.TextPaint;
import android.graphics.Paint;
public class TypefaceSpan extends MetricAffectingSpan {
private static LruCache<String, Typeface> sTypefaceCache = new LruCache<String, Typeface>(12);
private Typeface mTypeface;
public TypefaceSpan(Context context, String typefaceName) {
mTypeface = sTypefaceCache.get(typefaceName);
if (mTypeface == null) {
mTypeface = Typeface.createFromAsset(context.getApplicationContext()
.getAssets(), typefaceName);
sTypefaceCache.put(typefaceName, mTypeface);
}
}
@Override
public void updateMeasureState(TextPaint p) {
p.setTypeface(mTypeface);
// Note: This flag is required for proper typeface rendering
p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
@Override
public void updateDrawState(TextPaint tp) {
tp.setTypeface(mTypeface);
// Note: This flag is required for proper typeface rendering
tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
}