diff options
Diffstat (limited to '')
-rw-r--r-- | README | 4 | ||||
-rw-r--r-- | common.h | 3 | ||||
-rw-r--r-- | demo.c | 5 | ||||
-rw-r--r-- | libskrift_create_context.c | 18 | ||||
-rw-r--r-- | libskrift_draw_text.c | 7 |
5 files changed, 26 insertions, 11 deletions
@@ -36,7 +36,7 @@ Currently implemented: sRGB gamma function. - Affine transformations on glyphs. + Affine transformations on glyphs and texts. Pending support in libschift: @@ -55,8 +55,6 @@ Pending support in libschift: Not implemented yet - Affine transformations on texts. - Glyph caching. Normalise text when glyphs are missing. @@ -31,6 +31,9 @@ struct libskrift_context { char subpixel_horizontally; char subpixel_vertically; char subpixel_bgr; + double x_advancement; + double y_advancement; + double transformation[6]; size_t nfonts; LIBSKRIFT_FONT *fonts[]; }; @@ -17,13 +17,14 @@ main(void) rendering.smoothing = LIBSKRIFT_SUBPIXEL; rendering.subpixel_order = LIBSKRIFT_NONE; - rendering.flags = LIBSKRIFT_MIRROR_CHARS; + rendering.flags = LIBSKRIFT_MIRROR_CHARS * 0; if (libskrift_open_font_file(&font, DEMO_FONT)) { perror("libskrift_open_font_file"); return -1; } - libskrift_add_rotation_degrees(rendering.char_transformation, 10); + libskrift_add_rotation_degrees(rendering.text_transformation, -10); + libskrift_add_shear(rendering.char_transformation, .75f, 0); height = libskrift_points_to_pixels(72, &rendering); if (libskrift_create_context(&ctx, &font, 1, height, &rendering, NULL)) { perror("libskrift_create_context"); diff --git a/libskrift_create_context.c b/libskrift_create_context.c index 1500b20..f034240 100644 --- a/libskrift_create_context.c +++ b/libskrift_create_context.c @@ -39,7 +39,7 @@ transformation_hook(void *hook_data, double advance, double transform[6]) double m1[6] = {1, 0, 0, 0, 1, 0}, m2[6] = {1, 0, 0, 0, 1, 0}; if (((ctx->rendering.flags / LIBSKRIFT_MIRROR_CHARS) ^ (ctx->rendering.flags / LIBSKRIFT_MIRROR_TEXT)) & 1) multiply_matrices((double []){-1, 0, advance / schrift[0], 0, 1, 0}, m2, m1); - multiply_matrices(ctx->rendering.char_transformation, m1, m2); + multiply_matrices(ctx->transformation, m1, m2); multiply_matrices(schrift, m2, m1); transform[0] = m1[0]; transform[2] = m1[1]; @@ -76,6 +76,8 @@ libskrift_create_context(LIBSKRIFT_CONTEXT **ctxp, LIBSKRIFT_FONT **fonts, size_ (*ctxp)->schrift_ctx.font = fonts[0]->font; (*ctxp)->schrift_ctx.yScale = height; + (*ctxp)->x_advancement = 1; + (*ctxp)->y_advancement = 0; (*ctxp)->nfonts = nfonts; for (i = 0; i < nfonts; i++) { (*ctxp)->fonts[i] = fonts[i]; @@ -90,7 +92,6 @@ libskrift_create_context(LIBSKRIFT_CONTEXT **ctxp, LIBSKRIFT_FONT **fonts, size_ COPY_ARRAY((*ctxp)->rendering, default_rendering, top_transformation); COPY_ARRAY((*ctxp)->rendering, default_rendering, bottom_transformation); COPY_ARRAY((*ctxp)->rendering, default_rendering, poststroke_transformation_rotation); - COPY_ARRAY((*ctxp)->rendering, default_rendering, text_transformation); } else { memcpy(&(*ctxp)->rendering, &default_rendering, sizeof(default_rendering)); } @@ -116,8 +117,19 @@ libskrift_create_context(LIBSKRIFT_CONTEXT **ctxp, LIBSKRIFT_FONT **fonts, size_ fpclassify((*ctxp)->rendering.char_transformation[2]) != FP_ZERO || fpclassify((*ctxp)->rendering.char_transformation[3]) != FP_ZERO || fpclassify((*ctxp)->rendering.char_transformation[4] - 1) != FP_ZERO || - fpclassify((*ctxp)->rendering.char_transformation[5]) != FP_ZERO) + fpclassify((*ctxp)->rendering.char_transformation[5]) != FP_ZERO || + fpclassify((*ctxp)->rendering.text_transformation[0] - 1) != FP_ZERO || + fpclassify((*ctxp)->rendering.text_transformation[1]) != FP_ZERO || + fpclassify((*ctxp)->rendering.text_transformation[2]) != FP_ZERO || + fpclassify((*ctxp)->rendering.text_transformation[3]) != FP_ZERO || + fpclassify((*ctxp)->rendering.text_transformation[4] - 1) != FP_ZERO || + fpclassify((*ctxp)->rendering.text_transformation[5]) != FP_ZERO) { + memcpy((*ctxp)->transformation, (*ctxp)->rendering.char_transformation, sizeof((*ctxp)->transformation)); + libskrift_add_transformation((*ctxp)->transformation, (*ctxp)->rendering.text_transformation); + (*ctxp)->x_advancement = (*ctxp)->rendering.text_transformation[0]; + (*ctxp)->y_advancement = (*ctxp)->rendering.text_transformation[3]; (*ctxp)->schrift_ctx.transformation_hook = transformation_hook; + } if ((*ctxp)->rendering.smoothing == LIBSKRIFT_SUBPIXEL) { if ((*ctxp)->rendering.subpixel_order == LIBSKRIFT_RGB) { diff --git a/libskrift_draw_text.c b/libskrift_draw_text.c index 8f46df4..95fd523 100644 --- a/libskrift_draw_text.c +++ b/libskrift_draw_text.c @@ -7,17 +7,18 @@ libskrift_draw_text(LIBSKRIFT_CONTEXT *ctx, const char *text, const struct libsk { struct libskrift_saved_grapheme saved = LIBSKRIFT_NO_SAVED_GRAPHEME; struct libskrift_glyph *glyph; - double xpos = 0; + double xpos = 0, ypos = 0; ssize_t len; int r; for (; *text; text += len) { - len = libskrift_get_cluster_glyph(ctx, text, &saved, xpos, 0, &glyph); + len = libskrift_get_cluster_glyph(ctx, text, &saved, xpos, ypos, &glyph); if (len < 0) return -1; r = libskrift_apply_glyph(ctx, glyph, colour, x, y, image); - xpos += glyph->advance; + xpos += glyph->advance * ctx->x_advancement; + ypos += glyph->advance * ctx->y_advancement; free(glyph); if (r) return -1; |