aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2020-04-28 23:55:26 +0200
committerMattias Andrée <maandree@kth.se>2020-04-28 23:55:26 +0200
commitedfb8291b029193883ce7383f4dcdce24d9e7e5b (patch)
treeaa77fcff110eefec6d95f6619707f308a074233b
parentThread-safety (diff)
downloadlibskrift-edfb8291b029193883ce7383f4dcdce24d9e7e5b.tar.gz
libskrift-edfb8291b029193883ce7383f4dcdce24d9e7e5b.tar.bz2
libskrift-edfb8291b029193883ce7383f4dcdce24d9e7e5b.tar.xz
Add support for character transformation
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--demo.c6
-rw-r--r--libskrift.h31
-rw-r--r--libskrift_create_context.c29
3 files changed, 50 insertions, 16 deletions
diff --git a/demo.c b/demo.c
index 60ba4bb..a4d998c 100644
--- a/demo.c
+++ b/demo.c
@@ -23,6 +23,12 @@ main(void)
perror("libskrift_open_font_file");
return -1;
}
+ rendering.char_transformation[0] = 1;
+ rendering.char_transformation[1] = 0.25;
+ rendering.char_transformation[2] = 0;
+ rendering.char_transformation[3] = 0;
+ rendering.char_transformation[4] = 1;
+ rendering.char_transformation[5] = 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.h b/libskrift.h
index aeeaad2..843de6e 100644
--- a/libskrift.h
+++ b/libskrift.h
@@ -89,21 +89,22 @@ enum libskrift_hinting {
#define LIBSKRIFT_REMOVE_GAMMA 0x00000001L
#define LIBSKRIFT_Y_INCREASES_UPWARDS 0x00000002L /* SFT_DOWNWARD_Y otherwise */
#define LIBSKRIFT_FLIP_TEXT 0x00000004L
-#define LIBSKRIFT_MIRROR_TEXT 0x00000008L
-#define LIBSKRIFT_MIRROR_CHARS 0x00000010L
-#define LIBSKRIFT_TRANSPOSE_TEXT 0x00000020L
-#define LIBSKRIFT_TRANSPOSE_CHARS 0x00000040L
-#define LIBSKRIFT_NO_LIGATURES 0x00000080L
-#define LIBSKRIFT_ADVANCE_CHAR_TO_GRID 0x00000100L
-#define LIBSKRIFT_REGRESS_CHAR_TO_GRID 0x00000200L /* Combine with LIBSKRIFT_ADVANCE_CHAR_TO_GRID for closest alternative */
-#define LIBSKRIFT_ADVANCE_WORD_TO_GRID 0x00000400L
-#define LIBSKRIFT_REGRESS_WORD_TO_GRID 0x00000800L /* Combine with LIBSKRIFT_ADVANCE_WORD_TO_GRID for closest alternative */
-#define LIBSKRIFT_USE_SUBPIXEL_GRID 0x00001000L
-#define LIBSKRIFT_VERTICAL_TEXT 0x00002000L
-#define LIBSKRIFT_AUTOHINTING 0x00004000L /* Use autohinter even if hint information exists */
-#define LIBSKRIFT_NO_AUTOHINTING 0x00008000L /* Use autohinter if no hint information exist */
-#define LIBSKRIFT_AUTOKERNING 0x00010000L /* Use autokerner even if kerning information exists */
-#define LIBSKRIFT_NO_AUTOKERNING 0x00020000L /* Use autokerner if no kerning information exist */
+#define LIBSKRIFT_FLIP_CHARS 0x00000008L
+#define LIBSKRIFT_MIRROR_TEXT 0x00000010L
+#define LIBSKRIFT_MIRROR_CHARS 0x00000020L
+#define LIBSKRIFT_TRANSPOSE_TEXT 0x00000040L
+#define LIBSKRIFT_TRANSPOSE_CHARS 0x00000080L
+#define LIBSKRIFT_NO_LIGATURES 0x00000100L
+#define LIBSKRIFT_ADVANCE_CHAR_TO_GRID 0x00000200L
+#define LIBSKRIFT_REGRESS_CHAR_TO_GRID 0x00000400L /* Combine with LIBSKRIFT_ADVANCE_CHAR_TO_GRID for closest alternative */
+#define LIBSKRIFT_ADVANCE_WORD_TO_GRID 0x00000800L
+#define LIBSKRIFT_REGRESS_WORD_TO_GRID 0x00001000L /* Combine with LIBSKRIFT_ADVANCE_WORD_TO_GRID for closest alternative */
+#define LIBSKRIFT_USE_SUBPIXEL_GRID 0x00002000L
+#define LIBSKRIFT_VERTICAL_TEXT 0x00004000L
+#define LIBSKRIFT_AUTOHINTING 0x00008000L /* Use autohinter even if hint information exists */
+#define LIBSKRIFT_NO_AUTOHINTING 0x00010000L /* Use autohinter if no hint information exist */
+#define LIBSKRIFT_AUTOKERNING 0x00020000L /* Use autokerner even if kerning information exists */
+#define LIBSKRIFT_NO_AUTOKERNING 0x00040000L /* Use autokerner if no kerning information exist */
struct libskrift_rendering {
int struct_version;
diff --git a/libskrift_create_context.c b/libskrift_create_context.c
index fd8d086..cf67826 100644
--- a/libskrift_create_context.c
+++ b/libskrift_create_context.c
@@ -13,6 +13,26 @@
static const struct libskrift_rendering default_rendering = LIBSKRIFT_DEFAULT_RENDERING;
+static int
+transformation_hook(void *hook_data, double advance, double transform[6])
+{
+ LIBSKRIFT_CONTEXT *ctx = hook_data;
+ double r1c1b = ctx->rendering.char_transformation[0], r1c1a = transform[0];
+ double r1c2b = ctx->rendering.char_transformation[1], r1c2a = transform[2];
+ double r1c3b = ctx->rendering.char_transformation[2], r1c3a = transform[4];
+ double r2c1b = ctx->rendering.char_transformation[3], r2c1a = transform[1];
+ double r2c2b = ctx->rendering.char_transformation[4], r2c2a = transform[3];
+ double r2c3b = ctx->rendering.char_transformation[5], r2c3a = transform[5];
+ transform[0] = r1c1a * r1c1b + r1c2a * r2c1b;
+ transform[2] = r1c1a * r1c2b + r1c2a * r2c2b;
+ transform[4] = r1c1a * r1c3b + r1c2a * r2c3b + r1c3a;
+ transform[1] = r2c1a * r1c1b + r2c2a * r2c1b;
+ transform[3] = r2c1a * r1c2b + r2c2a * r2c2b;
+ transform[5] = r2c1a * r1c3b + r2c2a * r2c3b + r2c3a;
+ (void) advance;
+ return 0;
+}
+
int
libskrift_create_context(LIBSKRIFT_CONTEXT **ctxp, LIBSKRIFT_FONT **fonts, size_t nfonts, double height,
const struct libskrift_rendering *rendering, void *caching)
@@ -53,7 +73,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, char_transformation);
COPY_ARRAY((*ctxp)->rendering, default_rendering, text_transformation);
} else {
memcpy(&(*ctxp)->rendering, &default_rendering, sizeof(default_rendering));
@@ -72,6 +91,14 @@ libskrift_create_context(LIBSKRIFT_CONTEXT **ctxp, LIBSKRIFT_FONT **fonts, size_
(*ctxp)->schrift_ctx.xScale = (*ctxp)->schrift_ctx.yScale;
(*ctxp)->schrift_ctx.xScale *= (*ctxp)->rendering.horizontal_dpi / (*ctxp)->rendering.vertical_dpi;
+ (*ctxp)->schrift_ctx.hook_data = (*ctxp);
+ if (fpclassify((*ctxp)->rendering.char_transformation[0] - 1) != FP_ZERO ||
+ fpclassify((*ctxp)->rendering.char_transformation[1]) != FP_ZERO ||
+ 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)
+ (*ctxp)->schrift_ctx.transformation_hook = transformation_hook;
if ((*ctxp)->rendering.smoothing == LIBSKRIFT_SUBPIXEL) {
if ((*ctxp)->rendering.subpixel_order == LIBSKRIFT_RGB) {