Paint: implement textAlign and text bounds

This commit is contained in:
Julian Winkler
2025-02-18 18:58:58 +01:00
parent 587aeaba74
commit 4bb5dfd86e
5 changed files with 70 additions and 7 deletions

View File

@@ -102,6 +102,13 @@ JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawText(JNIEnv *
const char *str = (*env)->GetStringUTFChars(env, text, NULL);
pango_layout_set_text(layout, str, -1);
(*env)->ReleaseStringUTFChars(env, text, str);
PangoRectangle rect;
pango_layout_get_pixel_extents(layout, NULL, &rect);
y -= rect.height;
if (paint->alignment == PANGO_ALIGN_CENTER)
x -= rect.width / 2.f;
else if (paint->alignment == PANGO_ALIGN_RIGHT)
x -= rect.width;
gtk_snapshot_translate(snapshot, &GRAPHENE_POINT_INIT(x, y));
gtk_snapshot_append_layout(snapshot, layout, &paint->color);
gtk_snapshot_translate(snapshot, &GRAPHENE_POINT_INIT(-x, -y));