diff options
Diffstat (limited to 'vendor')
| -rw-r--r-- | vendor/text.c | 27 | ||||
| -rw-r--r-- | vendor/text.h | 6 |
2 files changed, 33 insertions, 0 deletions
diff --git a/vendor/text.c b/vendor/text.c index 818597d..09e3902 100644 --- a/vendor/text.c +++ b/vendor/text.c @@ -185,3 +185,30 @@ int sk_text_shape(int face, float px, const char *utf8, size_t len, SkGlyph *out *advance = pen; return n; } + +int32_t sk_text_run(int face, float px, const char *utf8, size_t len, float *xs, + int32_t *ascent, int32_t *height) { + static SkGlyph *glyphs; + static int room; + int32_t advance = 0; + int n = sk_text_shape(face, px, utf8, len, glyphs, room, &advance, ascent, height); + if (!xs) return advance; + if (n > room) { + SkGlyph *more = realloc(glyphs, (size_t)n * sizeof *glyphs); + if (!more) n = room; + else { + glyphs = more; + room = n; + sk_text_shape(face, px, utf8, len, glyphs, room, &advance, ascent, height); + } + } + for (size_t i = 0; i < len; i++) xs[i] = -1; + for (int k = 0; k < n; k++) + if (glyphs[k].cluster < len && xs[glyphs[k].cluster] < 0) xs[glyphs[k].cluster] = glyphs[k].x > 0 ? (float)glyphs[k].x : 0; + float last = 0; + for (size_t i = 0; i < len; i++) { + if (xs[i] < 0) xs[i] = last; + last = xs[i]; + } + return advance; +} diff --git a/vendor/text.h b/vendor/text.h index dd4eecf..355ad90 100644 --- a/vendor/text.h +++ b/vendor/text.h @@ -31,6 +31,12 @@ typedef struct { int sk_text_shape(int face, float px, const char *utf8, size_t len, SkGlyph *out, int max, int32_t *advance, int32_t *ascent, int32_t *height); +/* `sk_text_shape` measured: the run's advance, with `xs` (when not NULL, + `len` of them) the x of each byte from the run's start, a byte inside a + cluster at its cluster's. What `abi.Host.VTable.textRun` serves. */ +int32_t sk_text_run(int face, float px, const char *utf8, size_t len, float *xs, + int32_t *ascent, int32_t *height); + /* `glyph`'s own advance in `face` at `px`, in whole pixels (what the renderer centres font.c's raster in, so the glyph lands on its origin). */ int32_t sk_text_advance(int face, float px, uint32_t glyph); |
