diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2022-01-04 08:23:47 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2022-01-04 08:26:30 +0200 |
commit | 784ca2d73117c044cfb20ce75e51c4269c9cbfa8 (patch) | |
tree | 5dd3a0d75875eedb8221b16423562bdd38e1e43a | |
parent | 60776cc0385dd0cddeb2faa6d78e094cfa45bb73 (diff) |
Text: Light and regular font weight via ANSI escapes
SGR codes 2 and 10.
-rw-r--r-- | src/gmdocument.c | 18 | ||||
-rw-r--r-- | src/ui/text.c | 25 | ||||
-rw-r--r-- | src/ui/text.h | 3 |
3 files changed, 39 insertions, 7 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c index fd13bc82..60773e0b 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -556,16 +556,22 @@ static const int maxLedeLines_ = 10; | |||
556 | 556 | ||
557 | static void applyAttributes_RunTypesetter_(iRunTypesetter *d, iTextAttrib attrib) { | 557 | static void applyAttributes_RunTypesetter_(iRunTypesetter *d, iTextAttrib attrib) { |
558 | /* WARNING: This is duplicated in run_Font_(). Make sure they behave identically. */ | 558 | /* WARNING: This is duplicated in run_Font_(). Make sure they behave identically. */ |
559 | if (attrib.bold) { | 559 | if (attrib.monospace) { |
560 | d->run.font = fontWithStyle_Text(d->baseFont, bold_FontStyle); | 560 | d->run.font = fontWithFamily_Text(d->baseFont, monospace_FontId); |
561 | d->run.color = tmFirstParagraph_ColorId; | 561 | d->run.color = tmPreformatted_ColorId; |
562 | } | 562 | } |
563 | else if (attrib.italic) { | 563 | else if (attrib.italic) { |
564 | d->run.font = fontWithStyle_Text(d->baseFont, italic_FontStyle); | 564 | d->run.font = fontWithStyle_Text(d->baseFont, italic_FontStyle); |
565 | } | 565 | } |
566 | else if (attrib.monospace) { | 566 | else if (attrib.regular) { |
567 | d->run.font = fontWithFamily_Text(d->baseFont, monospace_FontId); | 567 | d->run.font = fontWithStyle_Text(d->baseFont, regular_FontStyle); |
568 | d->run.color = tmPreformatted_ColorId; | 568 | } |
569 | else if (attrib.bold) { | ||
570 | d->run.font = fontWithStyle_Text(d->baseFont, bold_FontStyle); | ||
571 | d->run.color = tmFirstParagraph_ColorId; | ||
572 | } | ||
573 | else if (attrib.light) { | ||
574 | d->run.font = fontWithStyle_Text(d->baseFont, light_FontStyle); | ||
569 | } | 575 | } |
570 | else { | 576 | else { |
571 | d->run.font = d->baseFont; | 577 | d->run.font = d->baseFont; |
diff --git a/src/ui/text.c b/src/ui/text.c index 116c5eba..4b43f872 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -453,6 +453,10 @@ void setAnsiFlags_Text(int ansiFlags) { | |||
453 | activeText_->ansiFlags = ansiFlags; | 453 | activeText_->ansiFlags = ansiFlags; |
454 | } | 454 | } |
455 | 455 | ||
456 | int ansiFlags_Text(void) { | ||
457 | return activeText_->ansiFlags; | ||
458 | } | ||
459 | |||
456 | void setDocumentFontSize_Text(iText *d, float fontSizeFactor) { | 460 | void setDocumentFontSize_Text(iText *d, float fontSizeFactor) { |
457 | fontSizeFactor *= contentScale_Text_; | 461 | fontSizeFactor *= contentScale_Text_; |
458 | iAssert(fontSizeFactor > 0); | 462 | iAssert(fontSizeFactor > 0); |
@@ -834,7 +838,6 @@ static void prepare_AttributedText_(iAttributedText *d, int overrideBaseDir, iCh | |||
834 | .font = d->font, | 838 | .font = d->font, |
835 | }; | 839 | }; |
836 | const int *logToSource = constData_Array(&d->logicalToSourceOffset); | 840 | const int *logToSource = constData_Array(&d->logicalToSourceOffset); |
837 | const int * logToVis = constData_Array(&d->logicalToVisual); | ||
838 | const iChar * logicalText = constData_Array(&d->logical); | 841 | const iChar * logicalText = constData_Array(&d->logical); |
839 | iBool isRTL = d->isBaseRTL; | 842 | iBool isRTL = d->isBaseRTL; |
840 | int numNonSpace = 0; | 843 | int numNonSpace = 0; |
@@ -874,17 +877,34 @@ static void prepare_AttributedText_(iAttributedText *d, int overrideBaseDir, iCh | |||
874 | /* Note: This styling is hardcoded to match `typesetOneLine_RunTypesetter_()`. */ | 877 | /* Note: This styling is hardcoded to match `typesetOneLine_RunTypesetter_()`. */ |
875 | if (ansi & allowFontStyle_AnsiFlag && equal_Rangecc(sequence, "1")) { | 878 | if (ansi & allowFontStyle_AnsiFlag && equal_Rangecc(sequence, "1")) { |
876 | run.attrib.bold = iTrue; | 879 | run.attrib.bold = iTrue; |
880 | run.attrib.regular = iFalse; | ||
881 | run.attrib.light = iFalse; | ||
877 | if (d->baseFgColorId == tmParagraph_ColorId) { | 882 | if (d->baseFgColorId == tmParagraph_ColorId) { |
878 | setFgColor_AttributedRun_(&run, tmFirstParagraph_ColorId); | 883 | setFgColor_AttributedRun_(&run, tmFirstParagraph_ColorId); |
879 | } | 884 | } |
880 | attribFont = font_Text_(fontWithStyle_Text(fontId_Text_(d->baseFont), | 885 | attribFont = font_Text_(fontWithStyle_Text(fontId_Text_(d->baseFont), |
881 | bold_FontStyle)); | 886 | bold_FontStyle)); |
882 | } | 887 | } |
888 | else if (ansi & allowFontStyle_AnsiFlag && equal_Rangecc(sequence, "2")) { | ||
889 | run.attrib.light = iTrue; | ||
890 | run.attrib.regular = iFalse; | ||
891 | run.attrib.bold = iFalse; | ||
892 | attribFont = font_Text_(fontWithStyle_Text(fontId_Text_(d->baseFont), | ||
893 | light_FontStyle)); | ||
894 | } | ||
883 | else if (ansi & allowFontStyle_AnsiFlag && equal_Rangecc(sequence, "3")) { | 895 | else if (ansi & allowFontStyle_AnsiFlag && equal_Rangecc(sequence, "3")) { |
884 | run.attrib.italic = iTrue; | 896 | run.attrib.italic = iTrue; |
885 | attribFont = font_Text_(fontWithStyle_Text(fontId_Text_(d->baseFont), | 897 | attribFont = font_Text_(fontWithStyle_Text(fontId_Text_(d->baseFont), |
886 | italic_FontStyle)); | 898 | italic_FontStyle)); |
887 | } | 899 | } |
900 | else if (ansi & allowFontStyle_AnsiFlag && equal_Rangecc(sequence, "10")) { | ||
901 | run.attrib.regular = iTrue; | ||
902 | run.attrib.bold = iFalse; | ||
903 | run.attrib.light = iFalse; | ||
904 | run.attrib.italic = iFalse; | ||
905 | attribFont = font_Text_(fontWithStyle_Text(fontId_Text_(d->baseFont), | ||
906 | regular_FontStyle)); | ||
907 | } | ||
888 | else if (ansi & allowFontStyle_AnsiFlag && equal_Rangecc(sequence, "11")) { | 908 | else if (ansi & allowFontStyle_AnsiFlag && equal_Rangecc(sequence, "11")) { |
889 | run.attrib.monospace = iTrue; | 909 | run.attrib.monospace = iTrue; |
890 | setFgColor_AttributedRun_(&run, tmPreformatted_ColorId); | 910 | setFgColor_AttributedRun_(&run, tmPreformatted_ColorId); |
@@ -892,7 +912,9 @@ static void prepare_AttributedText_(iAttributedText *d, int overrideBaseDir, iCh | |||
892 | monospace_FontId)); | 912 | monospace_FontId)); |
893 | } | 913 | } |
894 | else if (equal_Rangecc(sequence, "0")) { | 914 | else if (equal_Rangecc(sequence, "0")) { |
915 | run.attrib.regular = iFalse; | ||
895 | run.attrib.bold = iFalse; | 916 | run.attrib.bold = iFalse; |
917 | run.attrib.light = iFalse; | ||
896 | run.attrib.italic = iFalse; | 918 | run.attrib.italic = iFalse; |
897 | run.attrib.monospace = iFalse; | 919 | run.attrib.monospace = iFalse; |
898 | attribFont = run.font = d->baseFont; | 920 | attribFont = run.font = d->baseFont; |
@@ -973,6 +995,7 @@ static void prepare_AttributedText_(iAttributedText *d, int overrideBaseDir, iCh | |||
973 | pushBack_Array(&d->runs, &run); | 995 | pushBack_Array(&d->runs, &run); |
974 | } | 996 | } |
975 | #if 0 | 997 | #if 0 |
998 | const int *logToVis = constData_Array(&d->logicalToVisual); | ||
976 | printf("[AttributedText] %zu runs:\n", size_Array(&d->runs)); | 999 | printf("[AttributedText] %zu runs:\n", size_Array(&d->runs)); |
977 | iConstForEach(Array, i, &d->runs) { | 1000 | iConstForEach(Array, i, &d->runs) { |
978 | const iAttributedRun *run = i.value; | 1001 | const iAttributedRun *run = i.value; |
diff --git a/src/ui/text.h b/src/ui/text.h index cb29adad..c8bb6f85 100644 --- a/src/ui/text.h +++ b/src/ui/text.h | |||
@@ -161,6 +161,7 @@ enum iAnsiFlag { | |||
161 | void setOpacity_Text (float opacity); | 161 | void setOpacity_Text (float opacity); |
162 | void setBaseAttributes_Text (int fontId, int fgColorId); /* current "normal" text attributes */ | 162 | void setBaseAttributes_Text (int fontId, int fgColorId); /* current "normal" text attributes */ |
163 | void setAnsiFlags_Text (int ansiFlags); | 163 | void setAnsiFlags_Text (int ansiFlags); |
164 | int ansiFlags_Text (void); | ||
164 | 165 | ||
165 | void cache_Text (int fontId, iRangecc text); /* pre-render glyphs */ | 166 | void cache_Text (int fontId, iRangecc text); /* pre-render glyphs */ |
166 | 167 | ||
@@ -192,7 +193,9 @@ struct Impl_TextAttrib { | |||
192 | int16_t fgColorId; | 193 | int16_t fgColorId; |
193 | int16_t bgColorId; | 194 | int16_t bgColorId; |
194 | struct { | 195 | struct { |
196 | uint16_t regular : 1; | ||
195 | uint16_t bold : 1; | 197 | uint16_t bold : 1; |
198 | uint16_t light : 1; | ||
196 | uint16_t italic : 1; | 199 | uint16_t italic : 1; |
197 | uint16_t monospace : 1; | 200 | uint16_t monospace : 1; |
198 | uint16_t isBaseRTL : 1; | 201 | uint16_t isBaseRTL : 1; |