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
make android.text.Layout.draw() compatible custom Canvas classes
TextAndroidCanvas is a proxy canvas class which prevents us from accessing the GtkSnapshot of the real canvas. To solve this problem, we call Canvas.drawText() for each line.
This commit is contained in:
@@ -136,6 +136,11 @@ public class GskCanvas extends Canvas {
|
||||
native_concat(snapshot, matrix.native_instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) {
|
||||
drawText(text.toString().substring(start, end), x, y, paint);
|
||||
}
|
||||
|
||||
protected native void native_drawBitmap(long snapshot, long texture, int x, int y, int width, int height, long paint);
|
||||
protected native void native_drawRect(long snapshot, float left, float top, float right, float bottom, long paint);
|
||||
protected native void native_drawPath(long snapshot, long path, long paint);
|
||||
|
||||
@@ -2,6 +2,7 @@ package android.text;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.GskCanvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
|
||||
public class Layout {
|
||||
@@ -59,8 +60,6 @@ public class Layout {
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
System.out.println("height = " + native_get_height(layout));
|
||||
System.out.println("should be " + ((int)(paint.measureText("_") * 3)));
|
||||
return native_get_height(layout);
|
||||
}
|
||||
|
||||
@@ -68,7 +67,7 @@ public class Layout {
|
||||
if (canvas instanceof GskCanvas)
|
||||
native_draw(layout, ((GskCanvas)canvas).snapshot, paint.paint);
|
||||
else
|
||||
canvas.drawText(text.toString(), 0, 0, paint);
|
||||
native_draw_custom_canvas(layout, canvas, paint);
|
||||
}
|
||||
|
||||
public int getParagraphDirection(int line) {
|
||||
@@ -251,4 +250,5 @@ public class Layout {
|
||||
protected native void native_set_ellipsize(long layout, int ellipsize_mode, float ellipsize_width);
|
||||
protected native int native_get_ellipsis_count(long layout, int line);
|
||||
protected native void native_draw(long layout, long snapshot, long paint);
|
||||
protected native void native_draw_custom_canvas(long layout, Canvas canvas, Paint paint);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user