diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-04 18:34:41 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-04 18:34:41 +0300 |
commit | e3aee0c423f9f4403fcedf3392f8dfa5ba1ee495 (patch) | |
tree | c1ab9b98d97280bed6d34d27b99bc45021e88e79 | |
parent | 9ffc5aeb1349bb954582278e3e6f4d9a824f4284 (diff) |
Cleanup
-rw-r--r-- | src/ui/text.c | 77 |
1 files changed, 4 insertions, 73 deletions
diff --git a/src/ui/text.c b/src/ui/text.c index a21845b6..73b521fa 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -773,8 +773,7 @@ static iBool isControl_Char_(iChar c) { | |||
773 | iDeclareType(AttributedRun) | 773 | iDeclareType(AttributedRun) |
774 | 774 | ||
775 | struct Impl_AttributedRun { | 775 | struct Impl_AttributedRun { |
776 | iRangei visual; /* UTF-32 codepoint indices */ | 776 | iRangei visual; /* UTF-32 codepoint indices in the visual-order text */ |
777 | // iRangecc source; | ||
778 | iFont * font; | 777 | iFont * font; |
779 | iColor fgColor; | 778 | iColor fgColor; |
780 | int lineBreaks; | 779 | int lineBreaks; |
@@ -818,13 +817,11 @@ static void finishRun_AttributedText_(iAttributedText *d, iAttributedRun *run, i | |||
818 | iAttributedRun finishedRun = *run; | 817 | iAttributedRun finishedRun = *run; |
819 | iAssert(endAt >= 0 && endAt <= size_Array(&d->visual)); | 818 | iAssert(endAt >= 0 && endAt <= size_Array(&d->visual)); |
820 | finishedRun.visual.end = endAt; | 819 | finishedRun.visual.end = endAt; |
821 | // finishedRun.source.end = sourcePtr_AttributedText_(d, endAt); | ||
822 | if (!isEmpty_Range(&finishedRun.visual)) { | 820 | if (!isEmpty_Range(&finishedRun.visual)) { |
823 | pushBack_Array(&d->runs, &finishedRun); | 821 | pushBack_Array(&d->runs, &finishedRun); |
824 | run->lineBreaks = 0; | 822 | run->lineBreaks = 0; |
825 | } | 823 | } |
826 | run->visual.start = endAt; | 824 | run->visual.start = endAt; |
827 | // run->source.start = finishedRun.source.end; | ||
828 | } | 825 | } |
829 | 826 | ||
830 | size_t length_Rangecc(const iRangecc d) { | 827 | size_t length_Rangecc(const iRangecc d) { |
@@ -852,20 +849,6 @@ static void prepare_AttributedText_(iAttributedText *d) { | |||
852 | } | 849 | } |
853 | #if defined (LAGRANGE_ENABLE_FRIBIDI) | 850 | #if defined (LAGRANGE_ENABLE_FRIBIDI) |
854 | /* Use FriBidi to reorder the codepoints. */ | 851 | /* Use FriBidi to reorder the codepoints. */ |
855 | // iArray u32; | ||
856 | // iArray logToRun; | ||
857 | // init_Array(&u32, sizeof(uint32_t)); | ||
858 | // init_Array(&logToRun, sizeof(FriBidiStrIndex)); | ||
859 | // for (const char *pos = runText.start; pos < runText.end; ) { | ||
860 | // iChar ucp = 0; | ||
861 | // const int len = decodeBytes_MultibyteChar(pos, runText.end, &ucp); | ||
862 | // if (len > 0) { | ||
863 | // pushBack_Array(&u32, &ucp); | ||
864 | // pushBack_Array(&logToRun, &(int){ pos - runText.start }); | ||
865 | // pos += len; | ||
866 | // } | ||
867 | // else break; | ||
868 | // } | ||
869 | const size_t len = size_Array(&d->visual); | 852 | const size_t len = size_Array(&d->visual); |
870 | iArray ordered; | 853 | iArray ordered; |
871 | iArray visToLog; | 854 | iArray visToLog; |
@@ -882,9 +865,6 @@ static void prepare_AttributedText_(iAttributedText *d) { | |||
882 | NULL, | 865 | NULL, |
883 | data_Array(&visToLog), | 866 | data_Array(&visToLog), |
884 | (FriBidiLevel *) d->bidiLevels); | 867 | (FriBidiLevel *) d->bidiLevels); |
885 | // if (FRIBIDI_IS_RTL(baseDir)) { | ||
886 | // isRunRTL = iTrue; | ||
887 | // } | ||
888 | /* Replace with the visually ordered codepoints. */ | 868 | /* Replace with the visually ordered codepoints. */ |
889 | setCopy_Array(&d->visual, &ordered); | 869 | setCopy_Array(&d->visual, &ordered); |
890 | deinit_Array(&ordered); | 870 | deinit_Array(&ordered); |
@@ -900,23 +880,13 @@ static void prepare_AttributedText_(iAttributedText *d) { | |||
900 | setCopy_Array(&d->visualToSourceOffset, &orderedMapToSource); | 880 | setCopy_Array(&d->visualToSourceOffset, &orderedMapToSource); |
901 | deinit_Array(&orderedMapToSource); | 881 | deinit_Array(&orderedMapToSource); |
902 | deinit_Array(&visToLog); | 882 | deinit_Array(&visToLog); |
903 | //const FriBidiStrIndex *logToRunIndex = constData_Array(&logToRun); | ||
904 | // iConstForEach(Array, v, &vis32) { | ||
905 | // hb_buffer_add(hbBuf, | ||
906 | // *(const hb_codepoint_t *) v.value, | ||
907 | // logToRunIndex[visToLogIndex[index_ArrayConstIterator(&v)]]); | ||
908 | // } | ||
909 | // deinit_Array(&visToLog); | ||
910 | // deinit_Array(&vis32); | ||
911 | // deinit_Array(&logToRun); | ||
912 | // deinit_Array(&u32); | ||
913 | #endif | 883 | #endif |
914 | } | 884 | } |
915 | /* The mapping needs to include the terminating NULL position. */ { | 885 | /* The mapping needs to include the terminating NULL position. */ { |
916 | pushBack_Array(&d->visualToSourceOffset, &(int){ d->source.end - d->source.start }); | 886 | pushBack_Array(&d->visualToSourceOffset, &(int){ d->source.end - d->source.start }); |
917 | } | 887 | } |
918 | iRangei visText = { 0, size_Array(&d->visual) }; | 888 | iRangei visText = { 0, size_Array(&d->visual) }; |
919 | size_t avail = d->maxLen; | 889 | size_t avail = d->maxLen; |
920 | iAttributedRun run = { .visual = visText, | 890 | iAttributedRun run = { .visual = visText, |
921 | .font = d->font, | 891 | .font = d->font, |
922 | .fgColor = d->fgColor }; | 892 | .fgColor = d->fgColor }; |
@@ -928,49 +898,39 @@ static void prepare_AttributedText_(iAttributedText *d) { | |||
928 | pos++; | 898 | pos++; |
929 | const char *srcPos = d->source.start + mapToSource[pos]; | 899 | const char *srcPos = d->source.start + mapToSource[pos]; |
930 | /* Do a regexp match in the source text. */ | 900 | /* Do a regexp match in the source text. */ |
901 | /* TODO: Does this work in RTL regions?! */ | ||
931 | iRegExpMatch m; | 902 | iRegExpMatch m; |
932 | init_RegExpMatch(&m); | 903 | init_RegExpMatch(&m); |
933 | if (match_RegExp(text_.ansiEscape, srcPos, d->source.end - srcPos, &m)) { | 904 | if (match_RegExp(text_.ansiEscape, srcPos, d->source.end - srcPos, &m)) { |
934 | finishRun_AttributedText_(d, &run, pos - 1); | 905 | finishRun_AttributedText_(d, &run, pos - 1); |
935 | run.fgColor = ansiForeground_Color(capturedRange_RegExpMatch(&m, 1), | 906 | run.fgColor = ansiForeground_Color(capturedRange_RegExpMatch(&m, 1), |
936 | tmParagraph_ColorId); | 907 | tmParagraph_ColorId); |
937 | //chPos = end_RegExpMatch(&m); | ||
938 | //run.source.start = end_RegExpMatch(&m);// chPos; | ||
939 | pos += length_Rangecc(capturedRange_RegExpMatch(&m, 0)); | 908 | pos += length_Rangecc(capturedRange_RegExpMatch(&m, 0)); |
940 | iAssert(mapToSource[pos] == end_RegExpMatch(&m) - d->source.start); | 909 | iAssert(mapToSource[pos] == end_RegExpMatch(&m) - d->source.start); |
941 | /* The run continues after the escape sequence. */ | 910 | /* The run continues after the escape sequence. */ |
942 | run.visual.start = pos--; /* loop increments `pos` */ | 911 | run.visual.start = pos--; /* loop increments `pos` */ |
943 | // const char *endPos = d->source.start + mapToSource[pos]; | ||
944 | // printf("ANSI Escape: {%s}\n", cstr_Rangecc((iRangecc){ srcPos, endPos })); | ||
945 | continue; | 912 | continue; |
946 | } | 913 | } |
947 | } | 914 | } |
948 | //const iChar ch = nextChar_(&chPos, visText.end); | ||
949 | if (ch == '\v') { | 915 | if (ch == '\v') { |
950 | finishRun_AttributedText_(d, &run, pos); | 916 | finishRun_AttributedText_(d, &run, pos); |
951 | /* An internal color escape. */ | 917 | /* An internal color escape. */ |
952 | //iChar esc = nextChar_(&chPos, visText.end); | ||
953 | iChar esc = visualText[++pos]; | 918 | iChar esc = visualText[++pos]; |
954 | // srcPos++; | ||
955 | int colorNum = none_ColorId; /* default color */ | 919 | int colorNum = none_ColorId; /* default color */ |
956 | if (esc == '\v') { /* Extended range. */ | 920 | if (esc == '\v') { /* Extended range. */ |
957 | esc = visualText[++pos] + asciiExtended_ColorEscape; | 921 | esc = visualText[++pos] + asciiExtended_ColorEscape; |
958 | // srcPos++; | ||
959 | colorNum = esc - asciiBase_ColorEscape; | 922 | colorNum = esc - asciiBase_ColorEscape; |
960 | } | 923 | } |
961 | else if (esc != 0x24) { /* ASCII Cancel */ | 924 | else if (esc != 0x24) { /* ASCII Cancel */ |
962 | colorNum = esc - asciiBase_ColorEscape; | 925 | colorNum = esc - asciiBase_ColorEscape; |
963 | } | 926 | } |
964 | run.visual.start = pos + 1; | 927 | run.visual.start = pos + 1; |
965 | // run.source.start = srcPos; | ||
966 | run.fgColor = (colorNum >= 0 ? get_Color(colorNum) : d->fgColor); | 928 | run.fgColor = (colorNum >= 0 ? get_Color(colorNum) : d->fgColor); |
967 | //prevCh = 0; | ||
968 | continue; | 929 | continue; |
969 | } | 930 | } |
970 | if (ch == '\n') { | 931 | if (ch == '\n') { |
971 | finishRun_AttributedText_(d, &run, pos); | 932 | finishRun_AttributedText_(d, &run, pos); |
972 | run.visual.start = pos + 1; | 933 | run.visual.start = pos + 1; |
973 | // run.source.start = srcPos + 1; | ||
974 | run.lineBreaks++; | 934 | run.lineBreaks++; |
975 | continue; | 935 | continue; |
976 | } | 936 | } |
@@ -980,7 +940,6 @@ static void prepare_AttributedText_(iAttributedText *d) { | |||
980 | if (avail-- == 0) { | 940 | if (avail-- == 0) { |
981 | /* TODO: Check the combining class; only count base characters here. */ | 941 | /* TODO: Check the combining class; only count base characters here. */ |
982 | run.visual.end = pos; | 942 | run.visual.end = pos; |
983 | // run.source.end = srcPos; | ||
984 | break; | 943 | break; |
985 | } | 944 | } |
986 | iFont *currentFont = d->font; | 945 | iFont *currentFont = d->font; |
@@ -1308,7 +1267,6 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1308 | for (size_t runIndex = 0; runIndex < size_Array(&attrText.runs); runIndex++) { | 1267 | for (size_t runIndex = 0; runIndex < size_Array(&attrText.runs); runIndex++) { |
1309 | const iAttributedRun *run = at_Array(&attrText.runs, runIndex); | 1268 | const iAttributedRun *run = at_Array(&attrText.runs, runIndex); |
1310 | iRangei runVisual = run->visual; | 1269 | iRangei runVisual = run->visual; |
1311 | //iRangecc runSource = run->source; | ||
1312 | if (wrapResumePos >= 0) { | 1270 | if (wrapResumePos >= 0) { |
1313 | xCursor = 0.0f; | 1271 | xCursor = 0.0f; |
1314 | yCursor += d->height; | 1272 | yCursor += d->height; |
@@ -1349,11 +1307,8 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1349 | if (isMonospaced) { | 1307 | if (isMonospaced) { |
1350 | for (unsigned int i = 0; i < glyphCount; ++i) { | 1308 | for (unsigned int i = 0; i < glyphCount; ++i) { |
1351 | const hb_glyph_info_t *info = &glyphInfo[i]; | 1309 | const hb_glyph_info_t *info = &glyphInfo[i]; |
1352 | // const hb_codepoint_t glyphId = info->codepoint; | ||
1353 | // const char *textPos = sourceText.start + visToSource[info->cluster]; | ||
1354 | if (glyphPos[i].x_advance > 0 && run->font != d) { | 1310 | if (glyphPos[i].x_advance > 0 && run->font != d) { |
1355 | const iChar ch = visualText[info->cluster]; | 1311 | const iChar ch = visualText[info->cluster]; |
1356 | // decodeBytes_MultibyteChar(textPos, runSource.end, &ch); | ||
1357 | if (isPictograph_Char(ch) || isEmoji_Char(ch)) { | 1312 | if (isPictograph_Char(ch) || isEmoji_Char(ch)) { |
1358 | const float dw = run->font->xScale * glyphPos[i].x_advance - monoAdvance; | 1313 | const float dw = run->font->xScale * glyphPos[i].x_advance - monoAdvance; |
1359 | glyphPos[i].x_offset -= dw / 2 / run->font->xScale - 1; | 1314 | glyphPos[i].x_offset -= dw / 2 / run->font->xScale - 1; |
@@ -1371,7 +1326,6 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1371 | for (unsigned int i = 0; i < glyphCount; i++) { | 1326 | for (unsigned int i = 0; i < glyphCount; i++) { |
1372 | const hb_glyph_info_t *info = &glyphInfo[i]; | 1327 | const hb_glyph_info_t *info = &glyphInfo[i]; |
1373 | const hb_codepoint_t glyphId = info->codepoint; | 1328 | const hb_codepoint_t glyphId = info->codepoint; |
1374 | // const char *textPos = sourceText.start + info->cluster; | ||
1375 | const int visPos = info->cluster; | 1329 | const int visPos = info->cluster; |
1376 | const iGlyph *glyph = glyphByIndex_Font_(run->font, glyphId); | 1330 | const iGlyph *glyph = glyphByIndex_Font_(run->font, glyphId); |
1377 | const int glyphFlags = hb_glyph_info_get_glyph_flags(info); | 1331 | const int glyphFlags = hb_glyph_info_get_glyph_flags(info); |
@@ -1380,12 +1334,6 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1380 | if (args->wrap->mode == word_WrapTextMode) { | 1334 | if (args->wrap->mode == word_WrapTextMode) { |
1381 | /* When word wrapping, only consider certain places breakable. */ | 1335 | /* When word wrapping, only consider certain places breakable. */ |
1382 | const iChar ch = visualText[info->cluster]; | 1336 | const iChar ch = visualText[info->cluster]; |
1383 | // decodeBytes_MultibyteChar(textPos, runSource.end, &ch); | ||
1384 | /*if (prevCh == 0xad) { | ||
1385 | safeBreak = textPos; | ||
1386 | isSoftHyphenBreak = iTrue; | ||
1387 | } | ||
1388 | else*/ | ||
1389 | if ((ch >= 128 || !ispunct(ch)) && (prevCh == '-' || prevCh == '/')) { | 1337 | if ((ch >= 128 || !ispunct(ch)) && (prevCh == '-' || prevCh == '/')) { |
1390 | safeBreak = visPos; | 1338 | safeBreak = visPos; |
1391 | // isSoftHyphenBreak = iFalse; | 1339 | // isSoftHyphenBreak = iFalse; |
@@ -1436,9 +1384,6 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1436 | for (unsigned int i = 0; i < glyphCount; i++) { | 1384 | for (unsigned int i = 0; i < glyphCount; i++) { |
1437 | const hb_glyph_info_t *info = &glyphInfo[i]; | 1385 | const hb_glyph_info_t *info = &glyphInfo[i]; |
1438 | const hb_codepoint_t glyphId = info->codepoint; | 1386 | const hb_codepoint_t glyphId = info->codepoint; |
1439 | // const char *textPos = runText.start + info->cluster; | ||
1440 | // iAssert(textPos >= runText.start); | ||
1441 | // iAssert(textPos < runText.end); | ||
1442 | const int visPos = info->cluster; | 1387 | const int visPos = info->cluster; |
1443 | const float xOffset = run->font->xScale * glyphPos[i].x_offset; | 1388 | const float xOffset = run->font->xScale * glyphPos[i].x_offset; |
1444 | const float yOffset = run->font->yScale * glyphPos[i].y_offset; | 1389 | const float yOffset = run->font->yScale * glyphPos[i].y_offset; |
@@ -1606,20 +1551,6 @@ iInt2 tryAdvanceNoWrap_Text(int fontId, iRangecc text, int width, const char **e | |||
1606 | .wrapFunc = cbAdvanceOneLine_, .context = endPos }; | 1551 | .wrapFunc = cbAdvanceOneLine_, .context = endPos }; |
1607 | const int x = advance_WrapText(&wrap, fontId).x; | 1552 | const int x = advance_WrapText(&wrap, fontId).x; |
1608 | return init_I2(x, lineHeight_Text(fontId)); | 1553 | return init_I2(x, lineHeight_Text(fontId)); |
1609 | |||
1610 | #if 0 | ||
1611 | int advance; | ||
1612 | const int height = run_Font_(font_Text_(fontId), | ||
1613 | &(iRunArgs){ .mode = measure_RunMode | noWrapFlag_RunMode | | ||
1614 | stopAtNewline_RunMode | | ||
1615 | runFlagsFromId_(fontId), | ||
1616 | .text = text, | ||
1617 | .xposLimit = width, | ||
1618 | .continueFrom_out = endPos, | ||
1619 | .runAdvance_out = &advance }) | ||
1620 | .size.y; | ||
1621 | return init_I2(advance, height); | ||
1622 | #endif | ||
1623 | } | 1554 | } |
1624 | 1555 | ||
1625 | iInt2 advance_WrapText(iWrapText *d, int fontId) { | 1556 | iInt2 advance_WrapText(iWrapText *d, int fontId) { |