You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
TextView: make sure getPaint().getTextSize() returns the expected value
Using pango_font_description_set_absolute_size() now to prevent previous rounding errors when converting from pixels to points and back. This is needed to prevent androidx AppCompatTextViewAutoSizeHelper from constantly requesting a relayout.
This commit is contained in:
@@ -117,13 +117,13 @@ JNIEXPORT jint JNICALL Java_android_graphics_Paint_native_1get_1stroke_1join(JNI
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1text_1size(JNIEnv *env, jclass clazz, jlong paint_ptr, jfloat size)
|
||||
{
|
||||
struct AndroidPaint *paint = _PTR(paint_ptr);
|
||||
pango_font_description_set_size(paint->font, size * .8f * PANGO_SCALE);
|
||||
pango_font_description_set_absolute_size(paint->font, roundf(size * PANGO_SCALE));
|
||||
}
|
||||
|
||||
JNIEXPORT jfloat JNICALL Java_android_graphics_Paint_native_1get_1text_1size(JNIEnv *env, jclass clazz, jlong paint_ptr)
|
||||
{
|
||||
struct AndroidPaint *paint = _PTR(paint_ptr);
|
||||
return pango_font_description_get_size(paint->font) / .8f / PANGO_SCALE;
|
||||
return (jfloat)pango_font_description_get_size(paint->font) / PANGO_SCALE;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1color_1filter(JNIEnv *env, jclass clazz, jlong paint_ptr, jint mode, jint color)
|
||||
|
||||
@@ -30,6 +30,7 @@ import android.view.View;
|
||||
public class TextView extends View {
|
||||
private ColorStateList colors = new ColorStateList(new int[][] {new int[0]}, new int[1]);
|
||||
private CharSequence text = "";
|
||||
private TextPaint paint = new TextPaint();
|
||||
|
||||
public TextView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
@@ -158,7 +159,7 @@ public class TextView extends View {
|
||||
public static ColorStateList getTextColors(Context context, TypedArray attrs) { return new ColorStateList(new int[][] {new int[0]}, new int[1]); }
|
||||
|
||||
public TextPaint getPaint() {
|
||||
return new TextPaint();
|
||||
return paint;
|
||||
}
|
||||
|
||||
public void addTextChangedListener(TextWatcher watcher) {}
|
||||
|
||||
Reference in New Issue
Block a user