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:
@@ -4,7 +4,10 @@
|
||||
#include "util.h"
|
||||
|
||||
#include "../sk_area/include/c/sk_canvas.h"
|
||||
#include "../sk_area/include/c/sk_font.h"
|
||||
#include "../sk_area/include/c/sk_image.h"
|
||||
#include "../sk_area/include/c/sk_typeface.h"
|
||||
|
||||
#include "generated_headers/android_graphics_Canvas.h"
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1save(JNIEnv *env, jclass this, jlong skia_canvas, jlong widget)
|
||||
@@ -51,6 +54,18 @@ JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawRect(JNIEnv *env
|
||||
sk_canvas_draw_rect(canvas, &(sk_rect_t){left, top, right, bottom}, paint);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawText(JNIEnv *env, jclass this, jlong skia_canvas, jobject _text, jint start, jint end, jfloat x, jfloat y, jlong skia_font, jlong skia_paint)
|
||||
{
|
||||
sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas);
|
||||
sk_paint_t *paint = (sk_paint_t *)_PTR(skia_paint);
|
||||
sk_font_t *font = _PTR(skia_font);
|
||||
|
||||
const char *text = _CSTRING(_text);
|
||||
|
||||
/* TODO: handle start/end (here or in java) */
|
||||
sk_canvas_draw_simple_text(canvas, text + start, end - start, UTF8_SK_TEXT_ENCODING, x, y, font, paint);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1rotate(JNIEnv *env, jclass this, jlong skia_canvas, jlong widget, jfloat angle)
|
||||
{
|
||||
sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas);
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
#include "defines.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "../sk_area/include/c/sk_font.h"
|
||||
#include "../sk_area/include/c/sk_paint.h"
|
||||
#include "../sk_area/include/c/sk_typeface.h"
|
||||
#include "generated_headers/android_graphics_Paint.h"
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Paint_native_1constructor(JNIEnv *env, jobject this)
|
||||
@@ -25,3 +27,43 @@ JNIEXPORT jint JNICALL Java_android_graphics_Paint_native_1get_1color(JNIEnv *en
|
||||
|
||||
return sk_paint_get_color(paint);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Paint_native_1create_1font(JNIEnv *env, jclass this)
|
||||
{
|
||||
return _INTPTR(sk_font_new()); /* TODO: recycle this */
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1typeface(JNIEnv *env, jclass this, jlong skia_font, jlong skia_typeface)
|
||||
{
|
||||
sk_font_t *font = _PTR(skia_font);
|
||||
sk_typeface_t *typeface = _PTR(skia_typeface);
|
||||
|
||||
sk_font_set_typeface(font, typeface);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1text_1size(JNIEnv *env, jclass this, jlong skia_font, jfloat size)
|
||||
{
|
||||
sk_font_t *font = _PTR(skia_font);
|
||||
|
||||
sk_font_set_size(font, size);
|
||||
}
|
||||
|
||||
JNIEXPORT jfloat JNICALL Java_android_graphics_Paint_native_1ascent(JNIEnv *env, jclass this, jlong skia_font)
|
||||
{
|
||||
sk_font_t *font = _PTR(skia_font);
|
||||
|
||||
sk_fontmetrics_t metrics;
|
||||
sk_font_get_metrics(font, &metrics);
|
||||
|
||||
return metrics.fAscent;
|
||||
}
|
||||
|
||||
JNIEXPORT jfloat JNICALL Java_android_graphics_Paint_native_1measure_1text(JNIEnv *env, jclass this, jlong skia_font, jobject _text, jint start, jint end, jlong skia_paint)
|
||||
{
|
||||
sk_font_t *font = _PTR(skia_font);
|
||||
sk_paint_t *paint = (sk_paint_t *)_PTR(skia_paint);
|
||||
|
||||
const char *text = _CSTRING(_text);
|
||||
|
||||
return sk_font_measure_text(font, text + start, end - start, UTF8_SK_TEXT_ENCODING, NULL, paint);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,14 @@ JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1save
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1restore
|
||||
(JNIEnv *, jclass, jlong, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Canvas
|
||||
* Method: native_drawText
|
||||
* Signature: (JLjava/lang/CharSequence;IIFFJJ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawText
|
||||
(JNIEnv *, jclass, jlong, jobject, jint, jint, jfloat, jfloat, jlong, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Canvas
|
||||
* Method: native_drawRect
|
||||
|
||||
@@ -31,6 +31,46 @@ JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1color
|
||||
JNIEXPORT jint JNICALL Java_android_graphics_Paint_native_1get_1color
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Paint
|
||||
* Method: native_create_font
|
||||
* Signature: ()J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Paint_native_1create_1font
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Paint
|
||||
* Method: native_ascent
|
||||
* Signature: (J)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_android_graphics_Paint_native_1ascent
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Paint
|
||||
* Method: native_set_typeface
|
||||
* Signature: (JJ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1typeface
|
||||
(JNIEnv *, jclass, jlong, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Paint
|
||||
* Method: native_set_text_size
|
||||
* Signature: (JF)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1text_1size
|
||||
(JNIEnv *, jclass, jlong, jfloat);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Paint
|
||||
* Method: native_measure_text
|
||||
* Signature: (JLjava/lang/CharSequence;IIJ)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_android_graphics_Paint_native_1measure_1text
|
||||
(JNIEnv *, jclass, jlong, jobject, jint, jint, jlong);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class android_graphics_Typeface */
|
||||
|
||||
#ifndef _Included_android_graphics_Typeface
|
||||
#define _Included_android_graphics_Typeface
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#undef android_graphics_Typeface_NORMAL
|
||||
#define android_graphics_Typeface_NORMAL 0L
|
||||
#undef android_graphics_Typeface_BOLD
|
||||
#define android_graphics_Typeface_BOLD 1L
|
||||
#undef android_graphics_Typeface_ITALIC
|
||||
#define android_graphics_Typeface_ITALIC 2L
|
||||
#undef android_graphics_Typeface_BOLD_ITALIC
|
||||
#define android_graphics_Typeface_BOLD_ITALIC 3L
|
||||
/*
|
||||
* Class: android_graphics_Typeface
|
||||
* Method: native_create
|
||||
* Signature: (Ljava/lang/CharSequence;I)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Typeface_native_1create
|
||||
(JNIEnv *, jclass, jobject, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
14
src/api-impl-jni/graphics/android_graphics_Typeface.c
Normal file
14
src/api-impl-jni/graphics/android_graphics_Typeface.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "../defines.h"
|
||||
#include "../util.h"
|
||||
|
||||
#include "../../sk_area/include/c/sk_typeface.h"
|
||||
|
||||
#include "../generated_headers/android_graphics_Typeface.h"
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Typeface_native_1create(JNIEnv *env, jclass this, jobject _family_name, jint style)
|
||||
{
|
||||
/* TODO: use the family name */
|
||||
return _INTPTR(sk_typeface_create_default()); /* TODO: recycle this */
|
||||
}
|
||||
Reference in New Issue
Block a user