aboutsummaryrefslogtreecommitdiffstats
path: root/libskrift_get_cluster_glyph.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libskrift_get_cluster_glyph.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/libskrift_get_cluster_glyph.c b/libskrift_get_cluster_glyph.c
index e8d5724..fbc3a18 100644
--- a/libskrift_get_cluster_glyph.c
+++ b/libskrift_get_cluster_glyph.c
@@ -4,8 +4,8 @@
/* 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)
+libskrift_get_cluster_glyph(LIBSKRIFT_CONTEXT *ctx, const char *text, size_t text_length,
+ struct libskrift_saved_grapheme *saved, double x, double y, struct libskrift_glyph **glyphp)
{
struct libskrift_glyph *glyph0, *glyph1, *glyph2;
uint32_t cp0, cp1;
@@ -14,36 +14,31 @@ libskrift_get_cluster_glyph(LIBSKRIFT_CONTEXT *ctx, const char *text, struct lib
*glyphp = NULL;
- if (saved && saved->cp) {
+ if (!text_length) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (saved && saved->have_saved) {
cp0 = saved->cp;
len = saved->len;
} else {
- len = grapheme_decode(text, &cp0);
- if (!len) {
- errno = EINVAL;
- return -1;
- }
+ len = grapheme_cp_decode(&cp0, (const void *)text, text_length);
}
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;
- }
+ for (; len < text_length; cp0 = cp1, len += r) {
+ r = grapheme_cp_decode(&cp1, (const void *)&text[len], text_length - len);
if (grapheme_boundary(cp0, cp1, &state)) {
if (saved) {
+ saved->have_saved = 1;
saved->cp = cp1;
saved->len = r;
}
- break;
+ goto out;
}
if (libskrift_get_grapheme_glyph(ctx, cp1, x, y, &glyph1)) {
@@ -62,7 +57,13 @@ libskrift_get_cluster_glyph(LIBSKRIFT_CONTEXT *ctx, const char *text, struct lib
free(glyph1);
glyph0 = glyph2;
}
+ if (saved) {
+ saved->have_saved = 0;
+ saved->cp = 0;
+ saved->len = 0;
+ }
+out:
*glyphp = glyph0;
return (ssize_t)len;