diff options
Diffstat (limited to 'src/ui/text.c')
-rw-r--r-- | src/ui/text.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/ui/text.c b/src/ui/text.c index 866ae7fa..0a8386e4 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -1824,7 +1824,6 @@ static iBool cbAdvanceOneLine_(iWrapText *d, iRangecc range, int origin, int adv | |||
1824 | } | 1824 | } |
1825 | 1825 | ||
1826 | iInt2 tryAdvance_Text(int fontId, iRangecc text, int width, const char **endPos) { | 1826 | iInt2 tryAdvance_Text(int fontId, iRangecc text, int width, const char **endPos) { |
1827 | /* FIXME: Get rid of this. Caller could use WrapText directly? */ | ||
1828 | iWrapText wrap = { .mode = word_WrapTextMode, | 1827 | iWrapText wrap = { .mode = word_WrapTextMode, |
1829 | .text = text, | 1828 | .text = text, |
1830 | .maxWidth = width, | 1829 | .maxWidth = width, |
@@ -1835,8 +1834,7 @@ iInt2 tryAdvance_Text(int fontId, iRangecc text, int width, const char **endPos) | |||
1835 | } | 1834 | } |
1836 | 1835 | ||
1837 | iInt2 tryAdvanceNoWrap_Text(int fontId, iRangecc text, int width, const char **endPos) { | 1836 | iInt2 tryAdvanceNoWrap_Text(int fontId, iRangecc text, int width, const char **endPos) { |
1838 | /* TODO: "NoWrap" means words aren't wrapped; the line is broken at nearest character. */ | 1837 | /* "NoWrap" means words aren't wrapped; the line is broken at nearest character. */ |
1839 | /* FIXME: Get rid of this. Caller could use WrapText directly? */ | ||
1840 | iWrapText wrap = { .mode = anyCharacter_WrapTextMode, | 1838 | iWrapText wrap = { .mode = anyCharacter_WrapTextMode, |
1841 | .text = text, | 1839 | .text = text, |
1842 | .maxWidth = width, | 1840 | .maxWidth = width, |
@@ -2019,6 +2017,27 @@ iTextMetrics measure_WrapText(iWrapText *d, int fontId) { | |||
2019 | 2017 | ||
2020 | iTextMetrics draw_WrapText(iWrapText *d, int fontId, iInt2 pos, int color) { | 2018 | iTextMetrics draw_WrapText(iWrapText *d, int fontId, iInt2 pos, int color) { |
2021 | iTextMetrics tm; | 2019 | iTextMetrics tm; |
2020 | #if !defined (LAGRANGE_ENABLE_HARFBUZZ) | ||
2021 | /* In simple mode, each line must be wrapped first so we can break at the right points | ||
2022 | and do wrap notifications before drawing. */ | ||
2023 | iRangecc text = d->text; | ||
2024 | iZap(tm); | ||
2025 | d->wrapRange_ = (iRangecc){ d->text.start, d->text.start }; | ||
2026 | const iInt2 orig = pos; | ||
2027 | while (!isEmpty_Range(&text)) { | ||
2028 | const char *endPos; | ||
2029 | const int width = d->mode == word_WrapTextMode | ||
2030 | ? tryAdvance_Text(fontId, text, d->maxWidth, &endPos).x | ||
2031 | : tryAdvanceNoWrap_Text(fontId, text, d->maxWidth, &endPos).x; | ||
2032 | notify_WrapText_(d, endPos, 0, width, iFalse); | ||
2033 | drawRange_Text(fontId, pos, color, (iRangecc){ text.start, endPos }); | ||
2034 | text.start = endPos; | ||
2035 | pos.y += lineHeight_Text(fontId); | ||
2036 | tm.bounds.size.x = iMax(tm.bounds.size.x, width); | ||
2037 | tm.bounds.size.y = pos.y - orig.y; | ||
2038 | } | ||
2039 | tm.advance = sub_I2(pos, orig); | ||
2040 | #else | ||
2022 | tm.bounds = run_Font_(font_Text_(fontId), | 2041 | tm.bounds = run_Font_(font_Text_(fontId), |
2023 | &(iRunArgs){ .mode = draw_RunMode | runFlagsFromId_(fontId) | | 2042 | &(iRunArgs){ .mode = draw_RunMode | runFlagsFromId_(fontId) | |
2024 | (color & permanent_ColorId ? permanentColorFlag_RunMode : 0) | | 2043 | (color & permanent_ColorId ? permanentColorFlag_RunMode : 0) | |
@@ -2029,6 +2048,7 @@ iTextMetrics draw_WrapText(iWrapText *d, int fontId, iInt2 pos, int color) { | |||
2029 | .color = color & mask_ColorId, | 2048 | .color = color & mask_ColorId, |
2030 | .cursorAdvance_out = &tm.advance, | 2049 | .cursorAdvance_out = &tm.advance, |
2031 | }); | 2050 | }); |
2051 | #endif | ||
2032 | return tm; | 2052 | return tm; |
2033 | } | 2053 | } |
2034 | 2054 | ||