diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-14 10:03:50 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-14 10:03:50 +0300 |
commit | ddf6c998bf3be91bc72be5d2258577c46e60b0ad (patch) | |
tree | 87d1a2aa6dd49389e039b5e20e28aa83ba478b50 /src/ui | |
parent | d939dcd1109d7c92e6290976eaf84b94984abef3 (diff) |
Cleanup
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/text.c | 60 |
1 files changed, 21 insertions, 39 deletions
diff --git a/src/ui/text.c b/src/ui/text.c index 03ce46c7..a2d9f681 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -782,7 +782,6 @@ iDeclareType(AttributedRun) | |||
782 | 782 | ||
783 | struct Impl_AttributedRun { | 783 | struct Impl_AttributedRun { |
784 | iRangei logical; /* UTF-32 codepoint indices in the logical-order text */ | 784 | iRangei logical; /* UTF-32 codepoint indices in the logical-order text */ |
785 | //iRangei visual; /* UTF-32 codepoint indices in the visual-order text */ | ||
786 | iFont * font; | 785 | iFont * font; |
787 | iColor fgColor; | 786 | iColor fgColor; |
788 | struct { | 787 | struct { |
@@ -796,18 +795,17 @@ iDeclareTypeConstructionArgs(AttributedText, iRangecc text, size_t maxLen, iFont | |||
796 | iColor fgColor, int baseDir) | 795 | iColor fgColor, int baseDir) |
797 | 796 | ||
798 | struct Impl_AttributedText { | 797 | struct Impl_AttributedText { |
799 | iRangecc source; /* original source text */ | 798 | iRangecc source; /* original source text */ |
800 | size_t maxLen; | 799 | size_t maxLen; |
801 | iFont * font; | 800 | iFont * font; |
802 | iColor fgColor; | 801 | iColor fgColor; |
803 | iArray runs; | 802 | iArray runs; |
804 | iArray logical; /* UTF-32 text in logical order (mixed directions; matches source) */ | 803 | iArray logical; /* UTF-32 text in logical order (mixed directions; matches source) */ |
805 | iArray visual; /* UTF-32 text in visual order (LTR) */ | 804 | iArray visual; /* UTF-32 text in visual order (LTR) */ |
806 | iArray logicalToVisual; /* map visual index to logical index */ | 805 | iArray logicalToVisual; /* map visual index to logical index */ |
807 | iArray visualToLogical; /* map visual index to logical index */ | 806 | iArray logicalToSourceOffset; /* map logical character to an UTF-8 offset in the source text */ |
808 | iArray logicalToSourceOffset; /* map logical character to an UTF-8 offset in the source text */ | 807 | char * bidiLevels; |
809 | char * bidiLevels; | 808 | iBool isBaseRTL; |
810 | iBool isBaseRTL; | ||
811 | }; | 809 | }; |
812 | 810 | ||
813 | iDefineTypeConstructionArgs(AttributedText, | 811 | iDefineTypeConstructionArgs(AttributedText, |
@@ -829,6 +827,7 @@ static iRangecc sourceRange_AttributedText_(const iAttributedText *d, iRangei lo | |||
829 | return range; | 827 | return range; |
830 | } | 828 | } |
831 | 829 | ||
830 | #if 0 | ||
832 | static iBool isAllSpace_AttributedText_(const iAttributedText *d, iRangei range) { | 831 | static iBool isAllSpace_AttributedText_(const iAttributedText *d, iRangei range) { |
833 | const iChar *logicalText = constData_Array(&d->logical); | 832 | const iChar *logicalText = constData_Array(&d->logical); |
834 | for (size_t i = range.start; i < range.end; i++) { | 833 | for (size_t i = range.start; i < range.end; i++) { |
@@ -838,14 +837,12 @@ static iBool isAllSpace_AttributedText_(const iAttributedText *d, iRangei range) | |||
838 | } | 837 | } |
839 | return iTrue; | 838 | return iTrue; |
840 | } | 839 | } |
840 | #endif | ||
841 | 841 | ||
842 | static void finishRun_AttributedText_(iAttributedText *d, iAttributedRun *run, int endAt) { | 842 | static void finishRun_AttributedText_(iAttributedText *d, iAttributedRun *run, int endAt) { |
843 | iAttributedRun finishedRun = *run; | 843 | iAttributedRun finishedRun = *run; |
844 | iAssert(endAt >= 0 && endAt <= size_Array(&d->logical)); | 844 | iAssert(endAt >= 0 && endAt <= size_Array(&d->logical)); |
845 | finishedRun.logical.end = endAt; | 845 | finishedRun.logical.end = endAt; |
846 | // if (isAllSpace_AttributedText_(d, finishedRun.logical)) { | ||
847 | // return; | ||
848 | // } | ||
849 | if (!isEmpty_Range(&finishedRun.logical)) { | 846 | if (!isEmpty_Range(&finishedRun.logical)) { |
850 | pushBack_Array(&d->runs, &finishedRun); | 847 | pushBack_Array(&d->runs, &finishedRun); |
851 | run->flags.isLineBreak = iFalse; | 848 | run->flags.isLineBreak = iFalse; |
@@ -888,7 +885,6 @@ static void prepare_AttributedText_(iAttributedText *d, int overrideBaseDir) { | |||
888 | /* Use FriBidi to reorder the codepoints. */ | 885 | /* Use FriBidi to reorder the codepoints. */ |
889 | resize_Array(&d->visual, length); | 886 | resize_Array(&d->visual, length); |
890 | resize_Array(&d->logicalToVisual, length); | 887 | resize_Array(&d->logicalToVisual, length); |
891 | resize_Array(&d->visualToLogical, length); | ||
892 | d->bidiLevels = malloc(length); | 888 | d->bidiLevels = malloc(length); |
893 | FriBidiParType baseDir = (FriBidiParType) FRIBIDI_TYPE_ON; | 889 | FriBidiParType baseDir = (FriBidiParType) FRIBIDI_TYPE_ON; |
894 | fribidi_log2vis(constData_Array(&d->logical), | 890 | fribidi_log2vis(constData_Array(&d->logical), |
@@ -896,7 +892,7 @@ static void prepare_AttributedText_(iAttributedText *d, int overrideBaseDir) { | |||
896 | &baseDir, | 892 | &baseDir, |
897 | data_Array(&d->visual), | 893 | data_Array(&d->visual), |
898 | data_Array(&d->logicalToVisual), | 894 | data_Array(&d->logicalToVisual), |
899 | data_Array(&d->visualToLogical), | 895 | NULL, |
900 | (FriBidiLevel *) d->bidiLevels); | 896 | (FriBidiLevel *) d->bidiLevels); |
901 | d->isBaseRTL = (overrideBaseDir == 0 ? FRIBIDI_IS_RTL(baseDir) : (overrideBaseDir < 0)); | 897 | d->isBaseRTL = (overrideBaseDir == 0 ? FRIBIDI_IS_RTL(baseDir) : (overrideBaseDir < 0)); |
902 | #endif | 898 | #endif |
@@ -911,7 +907,6 @@ static void prepare_AttributedText_(iAttributedText *d, int overrideBaseDir) { | |||
911 | const int * logToSource = constData_Array(&d->logicalToSourceOffset); | 907 | const int * logToSource = constData_Array(&d->logicalToSourceOffset); |
912 | const int * logToVis = constData_Array(&d->logicalToVisual); | 908 | const int * logToVis = constData_Array(&d->logicalToVisual); |
913 | const iChar * logicalText = constData_Array(&d->logical); | 909 | const iChar * logicalText = constData_Array(&d->logical); |
914 | // const iChar * visualText = constData_Array(&d->visual); | ||
915 | iBool isRTL = d->isBaseRTL; | 910 | iBool isRTL = d->isBaseRTL; |
916 | int numNonSpace = 0; | 911 | int numNonSpace = 0; |
917 | for (int pos = 0; pos < length; pos++) { | 912 | for (int pos = 0; pos < length; pos++) { |
@@ -1029,7 +1024,6 @@ void init_AttributedText(iAttributedText *d, iRangecc text, size_t maxLen, iFont | |||
1029 | init_Array(&d->logical, sizeof(iChar)); | 1024 | init_Array(&d->logical, sizeof(iChar)); |
1030 | init_Array(&d->visual, sizeof(iChar)); | 1025 | init_Array(&d->visual, sizeof(iChar)); |
1031 | init_Array(&d->logicalToVisual, sizeof(int)); | 1026 | init_Array(&d->logicalToVisual, sizeof(int)); |
1032 | init_Array(&d->visualToLogical, sizeof(int)); | ||
1033 | init_Array(&d->logicalToSourceOffset, sizeof(int)); | 1027 | init_Array(&d->logicalToSourceOffset, sizeof(int)); |
1034 | d->bidiLevels = NULL; | 1028 | d->bidiLevels = NULL; |
1035 | d->isBaseRTL = iFalse; | 1029 | d->isBaseRTL = iFalse; |
@@ -1040,7 +1034,6 @@ void deinit_AttributedText(iAttributedText *d) { | |||
1040 | free(d->bidiLevels); | 1034 | free(d->bidiLevels); |
1041 | deinit_Array(&d->logicalToSourceOffset); | 1035 | deinit_Array(&d->logicalToSourceOffset); |
1042 | deinit_Array(&d->logicalToVisual); | 1036 | deinit_Array(&d->logicalToVisual); |
1043 | deinit_Array(&d->visualToLogical); | ||
1044 | deinit_Array(&d->visual); | 1037 | deinit_Array(&d->visual); |
1045 | deinit_Array(&d->logical); | 1038 | deinit_Array(&d->logical); |
1046 | deinit_Array(&d->runs); | 1039 | deinit_Array(&d->runs); |
@@ -1295,20 +1288,18 @@ struct Impl_GlyphBuffer { | |||
1295 | hb_buffer_t * hb; | 1288 | hb_buffer_t * hb; |
1296 | iFont * font; | 1289 | iFont * font; |
1297 | const iChar * logicalText; | 1290 | const iChar * logicalText; |
1298 | // const int * visToLog; | ||
1299 | hb_glyph_info_t * glyphInfo; | 1291 | hb_glyph_info_t * glyphInfo; |
1300 | hb_glyph_position_t *glyphPos; | 1292 | hb_glyph_position_t *glyphPos; |
1301 | unsigned int glyphCount; | 1293 | unsigned int glyphCount; |
1302 | }; | 1294 | }; |
1303 | 1295 | ||
1304 | static void init_GlyphBuffer_(iGlyphBuffer *d, iFont *font, const iChar *logicalText) { | 1296 | static void init_GlyphBuffer_(iGlyphBuffer *d, iFont *font, const iChar *logicalText) { |
1305 | d->hb = hb_buffer_create(); | 1297 | d->hb = hb_buffer_create(); |
1306 | d->font = font; | 1298 | d->font = font; |
1307 | d->logicalText = logicalText; | 1299 | d->logicalText = logicalText; |
1308 | // d->visToLog = visToLog; | 1300 | d->glyphInfo = NULL; |
1309 | d->glyphInfo = NULL; | 1301 | d->glyphPos = NULL; |
1310 | d->glyphPos = NULL; | 1302 | d->glyphCount = 0; |
1311 | d->glyphCount = 0; | ||
1312 | } | 1303 | } |
1313 | 1304 | ||
1314 | static void deinit_GlyphBuffer_(iGlyphBuffer *d) { | 1305 | static void deinit_GlyphBuffer_(iGlyphBuffer *d) { |
@@ -1395,7 +1386,6 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1395 | const iChar *logicalText = constData_Array(&attrText.logical); | 1386 | const iChar *logicalText = constData_Array(&attrText.logical); |
1396 | const iChar *visualText = constData_Array(&attrText.visual); | 1387 | const iChar *visualText = constData_Array(&attrText.visual); |
1397 | const int * logToVis = constData_Array(&attrText.logicalToVisual); | 1388 | const int * logToVis = constData_Array(&attrText.logicalToVisual); |
1398 | // const int * visToLog = constData_Array(&attrText.visualToLogical); | ||
1399 | const size_t runCount = size_Array(&attrText.runs); | 1389 | const size_t runCount = size_Array(&attrText.runs); |
1400 | iArray buffers; | 1390 | iArray buffers; |
1401 | init_Array(&buffers, sizeof(iGlyphBuffer)); | 1391 | init_Array(&buffers, sizeof(iGlyphBuffer)); |
@@ -1540,10 +1530,8 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1540 | iArray runOrder; | 1530 | iArray runOrder; |
1541 | init_Array(&runOrder, sizeof(size_t)); | 1531 | init_Array(&runOrder, sizeof(size_t)); |
1542 | size_t rtlStartIndex = iInvalidPos; | 1532 | size_t rtlStartIndex = iInvalidPos; |
1543 | iBool wasRtl = attrText.isBaseRTL; | ||
1544 | for (size_t runIndex = wrapRuns.start; runIndex < wrapRuns.end; runIndex++) { | 1533 | for (size_t runIndex = wrapRuns.start; runIndex < wrapRuns.end; runIndex++) { |
1545 | const iAttributedRun *run = at_Array(&attrText.runs, runIndex); | 1534 | if (attrText.isBaseRTL) { |
1546 | if (wasRtl) { //} || run->flags.isRTL) { | ||
1547 | if (rtlStartIndex == iInvalidPos) { | 1535 | if (rtlStartIndex == iInvalidPos) { |
1548 | rtlStartIndex = size_Array(&runOrder); | 1536 | rtlStartIndex = size_Array(&runOrder); |
1549 | } | 1537 | } |
@@ -1552,7 +1540,6 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1552 | else { | 1540 | else { |
1553 | pushBack_Array(&runOrder, &runIndex); | 1541 | pushBack_Array(&runOrder, &runIndex); |
1554 | } | 1542 | } |
1555 | // wasRtl = run->flags.isRTL; | ||
1556 | } | 1543 | } |
1557 | #if 0 | 1544 | #if 0 |
1558 | printf("Run order: "); | 1545 | printf("Run order: "); |
@@ -1566,12 +1553,7 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1566 | iAssert(size_Array(&runOrder) == size_Range(&wrapRuns)); | 1553 | iAssert(size_Array(&runOrder) == size_Range(&wrapRuns)); |
1567 | /* Alignment. */ | 1554 | /* Alignment. */ |
1568 | int origin = 0; | 1555 | int origin = 0; |
1569 | iBool isRightAligned = attrText.isBaseRTL; // iFalse; | 1556 | iBool isRightAligned = attrText.isBaseRTL; |
1570 | // /* Right-align if the last run is RTL. */ { | ||
1571 | // const size_t lastIndex = *(size_t *) back_Array(&runOrder); | ||
1572 | // const iAttributedRun *run = at_Array(&attrText.runs, lastIndex); | ||
1573 | // isRightAligned = run->flags.isRTL; | ||
1574 | // } | ||
1575 | if (isRightAligned) { | 1557 | if (isRightAligned) { |
1576 | if (layoutBound > 0) { | 1558 | if (layoutBound > 0) { |
1577 | origin = layoutBound - wrapAdvance; | 1559 | origin = layoutBound - wrapAdvance; |