aboutsummaryrefslogtreecommitdiffstats
path: root/libskrift_draw_text.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2020-04-28 18:47:10 +0200
committerMattias Andrée <maandree@kth.se>2020-04-28 18:47:10 +0200
commit9761455b328c86d8caedbf2f8ebd1bec8936e749 (patch)
tree81dd4f0982ae15a4dfe9f15ff5ce9342756f5a81 /libskrift_draw_text.c
parentAdd code (untested) for applying glyphs to an image (diff)
downloadlibskrift-9761455b328c86d8caedbf2f8ebd1bec8936e749.tar.gz
libskrift-9761455b328c86d8caedbf2f8ebd1bec8936e749.tar.bz2
libskrift-9761455b328c86d8caedbf2f8ebd1bec8936e749.tar.xz
Fix drawing issues (there is still some left)
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--libskrift_draw_text.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/libskrift_draw_text.c b/libskrift_draw_text.c
new file mode 100644
index 0000000..8f46df4
--- /dev/null
+++ b/libskrift_draw_text.c
@@ -0,0 +1,27 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+int
+libskrift_draw_text(LIBSKRIFT_CONTEXT *ctx, const char *text, const struct libskrift_colour *colour,
+ int16_t x, int16_t y, struct libskrift_image *image)
+{
+ struct libskrift_saved_grapheme saved = LIBSKRIFT_NO_SAVED_GRAPHEME;
+ struct libskrift_glyph *glyph;
+ double xpos = 0;
+ ssize_t len;
+ int r;
+
+ for (; *text; text += len) {
+ len = libskrift_get_cluster_glyph(ctx, text, &saved, xpos, 0, &glyph);
+ if (len < 0)
+ return -1;
+
+ r = libskrift_apply_glyph(ctx, glyph, colour, x, y, image);
+ xpos += glyph->advance;
+ free(glyph);
+ if (r)
+ return -1;
+ }
+
+ return 0;
+}