aboutsummaryrefslogtreecommitdiffstats
path: root/libskrift_get_cluster_glyph.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2020-04-26 11:02:57 +0200
committerMattias Andrée <maandree@kth.se>2020-04-26 11:08:13 +0200
commit933799d9f0aaf811b37aebf71db2634c4f80e23b (patch)
tree856a96f1d7f91ebb9a690078d13c6e3201753dc7 /libskrift_get_cluster_glyph.c
downloadlibskrift-933799d9f0aaf811b37aebf71db2634c4f80e23b.tar.gz
libskrift-933799d9f0aaf811b37aebf71db2634c4f80e23b.tar.bz2
libskrift-933799d9f0aaf811b37aebf71db2634c4f80e23b.tar.xz
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libskrift_get_cluster_glyph.c')
-rw-r--r--libskrift_get_cluster_glyph.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/libskrift_get_cluster_glyph.c b/libskrift_get_cluster_glyph.c
new file mode 100644
index 0000000..e8d5724
--- /dev/null
+++ b/libskrift_get_cluster_glyph.c
@@ -0,0 +1,69 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+/* TODO try normalisation if not found, then try fallback fonts */
+
+ssize_t
+libskrift_get_cluster_glyph(LIBSKRIFT_CONTEXT *ctx, const char *text, struct libskrift_saved_grapheme *saved,
+ double x, double y, struct libskrift_glyph **glyphp)
+{
+ struct libskrift_glyph *glyph0, *glyph1, *glyph2;
+ uint32_t cp0, cp1;
+ int state = 0;
+ size_t r, len;
+
+ *glyphp = NULL;
+
+ if (saved && saved->cp) {
+ cp0 = saved->cp;
+ len = saved->len;
+ } else {
+ len = grapheme_decode(text, &cp0);
+ if (!len) {
+ errno = EINVAL;
+ return -1;
+ }
+ }
+
+ if (libskrift_get_grapheme_glyph(ctx, cp0, x, y, &glyph0))
+ return -1;
+
+ x += glyph0->advance;
+ for (; cp0; cp0 = cp1, len += r) {
+ r = grapheme_decode(&text[len], &cp1);
+ if (!r) {
+ if (saved) {
+ saved->cp = 0;
+ saved->len = 0;
+ }
+ break;
+ }
+ if (grapheme_boundary(cp0, cp1, &state)) {
+ if (saved) {
+ saved->cp = cp1;
+ saved->len = r;
+ }
+ break;
+ }
+
+ if (libskrift_get_grapheme_glyph(ctx, cp1, x, y, &glyph1)) {
+ free(glyph0);
+ return -1;
+ }
+ x += glyph1->advance;
+
+ if (libskrift_merge_glyphs(ctx, glyph0, glyph1, &glyph2)) {
+ free(glyph0);
+ free(glyph1);
+ return -1;
+ }
+
+ free(glyph0);
+ free(glyph1);
+ glyph0 = glyph2;
+ }
+
+ *glyphp = glyph0;
+
+ return (ssize_t)len;
+}