summaryrefslogtreecommitdiff
path: root/src/ui/text_simple.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-06-30 08:23:11 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-06-30 08:23:11 +0300
commit2c82b88220bf9f0592b0015d1c0099d126249522 (patch)
tree281278054dd46df892f3399c670bcaed3436931e /src/ui/text_simple.c
parent73a721fc93c3be7b13361dea41d4431ad14a3fdd (diff)
Text: Use HarfBuzz to shape text
This kind of already works! HarfBuzz will composite glyphs as expected. Still missing: half-pixel offsets, line wrapping, color escapes, monospace grid alignment. FriBidi will still be required to determine/reorder text direction within each run.
Diffstat (limited to 'src/ui/text_simple.c')
-rw-r--r--src/ui/text_simple.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/ui/text_simple.c b/src/ui/text_simple.c
index baa87e4b..575d00cb 100644
--- a/src/ui/text_simple.c
+++ b/src/ui/text_simple.c
@@ -22,10 +22,44 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
22 22
23/* this file is included from text.c, so it doesn't use includes of its own */ 23/* this file is included from text.c, so it doesn't use includes of its own */
24 24
25iLocalDef iBool isWrapPunct_(iChar c) {
26 /* Punctuation that participates in word-wrapping. */
27 return (c == '/' || c == '\\' || c == '=' || c == '-' || c == ',' || c == ';' || c == '.' || c == ':' || c == 0xad);
28}
29
30iLocalDef iBool isClosingBracket_(iChar c) {
31 return (c == ')' || c == ']' || c == '}' || c == '>');
32}
33
34iLocalDef iBool isWrapBoundary_(iChar prevC, iChar c) {
35 /* Line wrapping boundaries are determined by looking at a character and the
36 last character processed. We want to wrap at natural word boundaries where
37 possible, so normally we wrap at a space followed a non-space character. As
38 an exception, we also wrap after punctuation used to break up words, so we
39 can wrap text like foo/bar/baz-abc-def.xyz at any puncation boundaries,
40 without wrapping on other punctuation used for expressive purposes like
41 emoticons :-) */
42 if (isClosingBracket_(prevC) && !isWrapPunct_(c)) {
43 return iTrue;
44 }
45 if (isSpace_Char(prevC)) {
46 return iFalse;
47 }
48 if ((prevC == '/' || prevC == '\\' || prevC == '-' || prevC == '_' || prevC == '+') &&
49 !isWrapPunct_(c)) {
50 return iTrue;
51 }
52 return isSpace_Char(c);
53}
54
55iLocalDef iBool isMeasuring_(enum iRunMode mode) {
56 return (mode & modeMask_RunMode) == measure_RunMode;
57}
58
25static iRect runSimple_Font_(iFont *d, const iRunArgs *args) { 59static iRect runSimple_Font_(iFont *d, const iRunArgs *args) {
26 /* This function shapes text using a simplified, incomplete algorithm. It works for English 60 /* This function shapes text using a simplified, incomplete algorithm. It works for English
27 and other simple LTR scripts. Composed glyphs are not supported (must rely on text being 61 and other non-complex LTR scripts. Composed glyphs are not supported (must rely on text
28 in a pre-composed form). This algorithm is used if HarfBuzz is not available. */ 62 being in a pre-composed form). This algorithm is used if HarfBuzz is not available. */
29 iRect bounds = zero_Rect(); 63 iRect bounds = zero_Rect();
30 const iInt2 orig = args->pos; 64 const iInt2 orig = args->pos;
31 float xpos = orig.x; 65 float xpos = orig.x;