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
api-impl: implement Canvas text drawing as used by Gravity Defied
implements android.graphics.Typeface (always uses default typeface for now), one version of Canvas.drawText, one version of Paint.measureText, and Paint.ascend
This commit is contained in:
@@ -95,8 +95,7 @@ public class Canvas {
|
||||
* @param paint The paint used for the text (e.g. color, size, style)
|
||||
*/
|
||||
public void drawText(String text, float x, float y, Paint paint) {
|
||||
/* native_drawText(mNativeCanvas, text, 0, text.length(), x, y, paint.mBidiFlags,
|
||||
paint.mNativePaint);*/
|
||||
native_drawText(skia_canvas, text, 0, text.length(), x, y, paint.skia_font, paint.skia_paint);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -377,7 +376,7 @@ public class Canvas {
|
||||
}
|
||||
|
||||
public void setBitmap(Bitmap bitmap) {}
|
||||
|
||||
private static native void native_drawText(long skia_canvas, CharSequence text, int start, int end, float x, float y, long skia_font, long skia_paint);
|
||||
private static native void native_drawRect(long skia_canvas, float left, float top, float right, float bottom, long skia_paint);
|
||||
private static native void native_drawLine(long skia_canvas, long widget, float startX, float startY, float stopX, float stopY, long skia_paint);
|
||||
private static native void native_drawBitmap(long skia_canvas, long widget, long pixbuf, float src_x, float src_y, float dest_x, float dest_y, float dest_w, float dest_h, long skia_paint);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package android.graphics;
|
||||
|
||||
public class Paint {
|
||||
public long skia_paint = 0; // should probably be private, but then we'd need to get it from C
|
||||
|
||||
private native long native_constructor();
|
||||
private native void native_set_color(long skia_paint, int color);
|
||||
private native int native_get_color(long skia_paint);
|
||||
public long skia_paint = 0;
|
||||
private Typeface typeface = null;
|
||||
public long skia_font = 0;
|
||||
|
||||
public Paint() {
|
||||
skia_paint = native_constructor();
|
||||
@@ -32,21 +30,37 @@ public class Paint {
|
||||
|
||||
public void setAntiAlias(boolean aa) {}
|
||||
public void setStrokeWidth(float width) {}
|
||||
public void setTextSize(float textSize) {}
|
||||
public void setTextSize(float size) {
|
||||
if(skia_font == 0)
|
||||
skia_font = native_create_font();
|
||||
|
||||
native_set_text_size(skia_font, size);
|
||||
}
|
||||
|
||||
public Typeface setTypeface(Typeface typeface) {
|
||||
return new Typeface();
|
||||
this.typeface = typeface;
|
||||
if(skia_font == 0)
|
||||
skia_font = native_create_font();
|
||||
|
||||
native_set_typeface(skia_font, typeface.skia_typeface);
|
||||
return this.typeface;
|
||||
}
|
||||
public void getTextBounds(String text, int start, int end, Rect bounds) {}
|
||||
public void getTextBounds(char[] text, int index, int count, Rect bounds) {}
|
||||
public void setFlags(int flags) {}
|
||||
public void setFilterBitmap(boolean filter) {}
|
||||
public void setStyle(Style style) {}
|
||||
public float ascent() { return 0; }
|
||||
public float ascent() {
|
||||
if(skia_font == 0)
|
||||
return 0;
|
||||
return native_ascent(skia_font);
|
||||
}
|
||||
|
||||
public float measureText(char[] text, int index, int count) { return 10; }
|
||||
public float measureText(String text, int start, int end) { return 10; }
|
||||
public float measureText(String text) { return 10; }
|
||||
public float measureText(String text) {
|
||||
return native_measure_text(skia_font, text, 0, text.length(), skia_paint);
|
||||
}
|
||||
public float measureText(CharSequence text, int start, int end) { return 10; }
|
||||
|
||||
public enum Style {
|
||||
@@ -187,4 +201,13 @@ public class Paint {
|
||||
public void setStrokeCap(Cap cap) {}
|
||||
|
||||
public void setStrokeJoin(Join join) {}
|
||||
|
||||
private native long native_constructor();
|
||||
private native void native_set_color(long skia_paint, int color);
|
||||
private native int native_get_color(long skia_paint);
|
||||
private static native long native_create_font();
|
||||
private static native float native_ascent(long skia_font);
|
||||
private static native void native_set_typeface(long skia_font, long skia_typeface);
|
||||
private static native void native_set_text_size(long skia_font, float size);
|
||||
private static native float native_measure_text(long skia_font, CharSequence text, int start, int end, long skia_paint);
|
||||
}
|
||||
|
||||
@@ -7,25 +7,25 @@ public class Typeface {
|
||||
/**
|
||||
* The default NORMAL typeface object
|
||||
*/
|
||||
public static final Typeface DEFAULT = new Typeface();
|
||||
public static final Typeface DEFAULT = create((String)null, 0);
|
||||
/**
|
||||
* The default BOLD typeface object. Note: this may be not actually be
|
||||
* bold, depending on what fonts are installed. Call getStyle() to know
|
||||
* for sure.
|
||||
*/
|
||||
public static final Typeface DEFAULT_BOLD = new Typeface();
|
||||
public static final Typeface DEFAULT_BOLD = create((String)null, 0);
|
||||
/**
|
||||
* The NORMAL style of the default sans serif typeface.
|
||||
*/
|
||||
public static final Typeface SANS_SERIF = new Typeface();
|
||||
public static final Typeface SANS_SERIF = create((String)null, 0);
|
||||
/**
|
||||
* The NORMAL style of the default serif typeface.
|
||||
*/
|
||||
public static final Typeface SERIF = new Typeface();
|
||||
public static final Typeface SERIF = create((String)null, 0);
|
||||
/**
|
||||
* The NORMAL style of the default monospace typeface.
|
||||
*/
|
||||
public static final Typeface MONOSPACE = new Typeface();
|
||||
public static final Typeface MONOSPACE = create((String)null, 0);
|
||||
|
||||
// Style
|
||||
public static final int NORMAL = 0;
|
||||
@@ -33,15 +33,21 @@ public class Typeface {
|
||||
public static final int ITALIC = 2;
|
||||
public static final int BOLD_ITALIC = 3;
|
||||
|
||||
public long skia_typeface = 0;
|
||||
|
||||
public static Typeface createFromAsset(AssetManager mgr, String path) {
|
||||
return null;
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
public static Typeface create(String familyName, int style) {
|
||||
return null;
|
||||
public static Typeface create(String family_name, int style) {
|
||||
Typeface ret = new Typeface();
|
||||
ret.skia_typeface = native_create(family_name, style);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Typeface create(Typeface typeface, int style) {
|
||||
return null;
|
||||
return typeface;
|
||||
}
|
||||
|
||||
private static native long native_create(CharSequence family_name, int style);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user