use of android.text.TextPaint in project UltimateAndroid by cymcsg.
the class AutofitTextView method getTextSize.
/**
* Recursive binary search to find the best size for the text
*/
private static float getTextSize(CharSequence text, TextPaint paint, float targetWidth, int maxLines, float low, float high, float precision, DisplayMetrics displayMetrics) {
float mid = (low + high) / 2.0f;
int lineCount = 1;
StaticLayout layout = null;
paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, mid, displayMetrics));
if (maxLines != 1) {
layout = new StaticLayout(text, paint, (int) targetWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
lineCount = layout.getLineCount();
}
if (SPEW)
Log.d(TAG, "low=" + low + " high=" + high + " mid=" + mid + " target=" + targetWidth + " maxLines=" + maxLines + " lineCount=" + lineCount);
if (lineCount > maxLines) {
return getTextSize(text, paint, targetWidth, maxLines, low, mid, precision, displayMetrics);
} else if (lineCount < maxLines) {
return getTextSize(text, paint, targetWidth, maxLines, mid, high, precision, displayMetrics);
} else {
float maxLineWidth = 0;
if (maxLines == 1) {
maxLineWidth = paint.measureText(text, 0, text.length());
} else {
for (int i = 0; i < lineCount; i++) {
if (layout.getLineWidth(i) > maxLineWidth) {
maxLineWidth = layout.getLineWidth(i);
}
}
}
if ((high - low) < precision) {
return low;
} else if (maxLineWidth > targetWidth) {
return getTextSize(text, paint, targetWidth, maxLines, low, mid, precision, displayMetrics);
} else if (maxLineWidth < targetWidth) {
return getTextSize(text, paint, targetWidth, maxLines, mid, high, precision, displayMetrics);
} else {
return mid;
}
}
}
use of android.text.TextPaint in project android_frameworks_base by ParanoidAndroid.
the class TextAppearanceSpan method updateMeasureState.
@Override
public void updateMeasureState(TextPaint ds) {
if (mTypeface != null || mStyle != 0) {
Typeface tf = ds.getTypeface();
int style = 0;
if (tf != null) {
style = tf.getStyle();
}
style |= mStyle;
if (mTypeface != null) {
tf = Typeface.create(mTypeface, style);
} else if (tf == null) {
tf = Typeface.defaultFromStyle(style);
} else {
tf = Typeface.create(tf, style);
}
int fake = style & ~tf.getStyle();
if ((fake & Typeface.BOLD) != 0) {
ds.setFakeBoldText(true);
}
if ((fake & Typeface.ITALIC) != 0) {
ds.setTextSkewX(-0.25f);
}
ds.setTypeface(tf);
}
if (mTextSize > 0) {
ds.setTextSize(mTextSize);
}
}
use of android.text.TextPaint in project android_frameworks_base by AOSPA.
the class StaticLayoutTest method moveCursorToRightCursorableOffset.
private void moveCursorToRightCursorableOffset(EditorState state, TextPaint paint) {
assertEquals("The editor has selection", state.mSelectionStart, state.mSelectionEnd);
final Layout layout = builder().setText(state.mText.toString()).setPaint(paint).build();
final int newOffset = layout.getOffsetToRightOf(state.mSelectionStart);
state.mSelectionStart = state.mSelectionEnd = newOffset;
}
use of android.text.TextPaint in project android_frameworks_base by AOSPA.
the class StaticLayoutTest method moveCursorToLeftCursorableOffset.
private void moveCursorToLeftCursorableOffset(EditorState state, TextPaint paint) {
assertEquals("The editor has selection", state.mSelectionStart, state.mSelectionEnd);
final Layout layout = builder().setText(state.mText.toString()).setPaint(paint).build();
final int newOffset = layout.getOffsetToLeftOf(state.mSelectionStart);
state.mSelectionStart = state.mSelectionEnd = newOffset;
}
use of android.text.TextPaint in project ABPlayer by winkstu.
the class AndroidDisplayer method measure.
@Override
public void measure(BaseDanmaku danmaku) {
TextPaint paint = getPaint(danmaku);
if (HAS_STROKE) {
applyPaintConfig(danmaku, paint, true);
}
calcPaintWH(danmaku, paint);
if (HAS_STROKE) {
applyPaintConfig(danmaku, paint, false);
}
}
Aggregations