summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/text.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/ui/text.c b/src/ui/text.c
index 7e8c7871..411d82d3 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -766,19 +766,21 @@ struct Impl_AttributedText {
766iDefineTypeConstructionArgs(AttributedText, (iRangecc text, iFont *font, iColor fgColor), 766iDefineTypeConstructionArgs(AttributedText, (iRangecc text, iFont *font, iColor fgColor),
767 text, font, fgColor) 767 text, font, fgColor)
768 768
769static void finishRun_AttributedText_(iAttributedText *d, iAttributedRun *run,
770 const char *endAt) {
771 iAttributedRun finishedRun = *run;
772 finishedRun.text.end = endAt;
773 if (!isEmpty_Range(&finishedRun.text)) {
774 pushBack_Array(&d->runs, &finishedRun);
775 run->lineBreaks = 0;
776 }
777 run->text.start = endAt;
778}
779
769static void prepare_AttributedText_(iAttributedText *d) { 780static void prepare_AttributedText_(iAttributedText *d) {
770 iAssert(isEmpty_Array(&d->runs)); 781 iAssert(isEmpty_Array(&d->runs));
771 const char *chPos = d->text.start; 782 const char *chPos = d->text.start;
772 iAttributedRun run = { .text = d->text, .font = d->font, .fgColor = d->fgColor }; 783 iAttributedRun run = { .text = d->text, .font = d->font, .fgColor = d->fgColor };
773#define finishRun_() { \
774 iAttributedRun finishedRun = run; \
775 finishedRun.text.end = currentPos; \
776 if (!isEmpty_Range(&finishedRun.text)) { \
777 pushBack_Array(&d->runs, &finishedRun); \
778 run.lineBreaks = 0; \
779 } \
780 run.text.start = currentPos; \
781}
782 while (chPos < d->text.end) { 784 while (chPos < d->text.end) {
783 const char *currentPos = chPos; 785 const char *currentPos = chPos;
784 if (*chPos == 0x1b) { /* ANSI escape. */ 786 if (*chPos == 0x1b) { /* ANSI escape. */
@@ -786,7 +788,7 @@ static void prepare_AttributedText_(iAttributedText *d) {
786 iRegExpMatch m; 788 iRegExpMatch m;
787 init_RegExpMatch(&m); 789 init_RegExpMatch(&m);
788 if (match_RegExp(text_.ansiEscape, chPos, d->text.end - chPos, &m)) { 790 if (match_RegExp(text_.ansiEscape, chPos, d->text.end - chPos, &m)) {
789 finishRun_(); 791 finishRun_AttributedText_(d, &run, currentPos);
790 run.fgColor = ansiForeground_Color(capturedRange_RegExpMatch(&m, 1), 792 run.fgColor = ansiForeground_Color(capturedRange_RegExpMatch(&m, 1),
791 tmParagraph_ColorId); 793 tmParagraph_ColorId);
792 chPos = end_RegExpMatch(&m); 794 chPos = end_RegExpMatch(&m);
@@ -796,7 +798,7 @@ static void prepare_AttributedText_(iAttributedText *d) {
796 } 798 }
797 const iChar ch = nextChar_(&chPos, d->text.end); 799 const iChar ch = nextChar_(&chPos, d->text.end);
798 if (ch == '\v') { 800 if (ch == '\v') {
799 finishRun_(); 801 finishRun_AttributedText_(d, &run, currentPos);
800 /* An internal color escape. */ 802 /* An internal color escape. */
801 iChar esc = nextChar_(&chPos, d->text.end); 803 iChar esc = nextChar_(&chPos, d->text.end);
802 int colorNum = none_ColorId; /* default color */ 804 int colorNum = none_ColorId; /* default color */
@@ -813,7 +815,7 @@ static void prepare_AttributedText_(iAttributedText *d) {
813 continue; 815 continue;
814 } 816 }
815 if (ch == '\n') { 817 if (ch == '\n') {
816 finishRun_(); 818 finishRun_AttributedText_(d, &run, currentPos);
817 run.text.start = chPos; 819 run.text.start = chPos;
818 run.lineBreaks++; 820 run.lineBreaks++;
819 continue; 821 continue;
@@ -826,7 +828,7 @@ static void prepare_AttributedText_(iAttributedText *d) {
826 /* TODO: Look for ANSI/color escapes. */ 828 /* TODO: Look for ANSI/color escapes. */
827 if (index_Glyph_(glyph) && glyph->font != run.font) { 829 if (index_Glyph_(glyph) && glyph->font != run.font) {
828 /* A different font is being used for this glyph. */ 830 /* A different font is being used for this glyph. */
829 finishRun_(); 831 finishRun_AttributedText_(d, &run, currentPos);
830 run.font = glyph->font; 832 run.font = glyph->font;
831 } 833 }
832 } 834 }
@@ -1069,7 +1071,8 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1069 const float xAdvance = run->font->xScale * glyphPos[i].x_advance; 1071 const float xAdvance = run->font->xScale * glyphPos[i].x_advance;
1070 const float yAdvance = run->font->yScale * glyphPos[i].y_advance; 1072 const float yAdvance = run->font->yScale * glyphPos[i].y_advance;
1071 const iGlyph *glyph = glyphByIndex_Font_(run->font, glyphId); 1073 const iGlyph *glyph = glyphByIndex_Font_(run->font, glyphId);
1072 const int hoff = 0; /* TODO: which half? */ 1074 const float xf = xCursor + xOffset;
1075 const int hoff = enableHalfPixelGlyphs_Text ? (xf - ((int) xf) > 0.5f ? 1 : 0) : 0;
1073 /* draw_glyph(glyphid, cursor_x + x_offset, cursor_y + y_offset); */ 1076 /* draw_glyph(glyphid, cursor_x + x_offset, cursor_y + y_offset); */
1074 /* Draw the glyph. */ { 1077 /* Draw the glyph. */ {
1075 SDL_Rect dst = { orig.x + xCursor + xOffset + glyph->d[hoff].x, 1078 SDL_Rect dst = { orig.x + xCursor + xOffset + glyph->d[hoff].x,