summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-04-05 12:19:55 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-04-05 12:19:55 +0300
commit6000db343bb2c1b44bed9eb4b14a179f839f3aa7 (patch)
tree72363eac22ff41977e3336d1786fd0dc383ca2fe /src
parentee0b5e2c30b68a906f76be388b47fac98a5f9e1f (diff)
Fixed color escapes in link visit date
A color escape may be longer than two characters. `run_Font_()` was not parsing extended color escapes correctly.
Diffstat (limited to 'src')
-rw-r--r--src/ui/color.c1
-rw-r--r--src/ui/documentwidget.c16
-rw-r--r--src/ui/text.c6
3 files changed, 11 insertions, 12 deletions
diff --git a/src/ui/color.c b/src/ui/color.c
index 79606cd0..d6d68816 100644
--- a/src/ui/color.c
+++ b/src/ui/color.c
@@ -462,6 +462,7 @@ const char *escape_Color(int color) {
462 if (color >= 0 && color < (int) iElemCount(esc)) { 462 if (color >= 0 && color < (int) iElemCount(esc)) {
463 return esc[color]; 463 return esc[color];
464 } 464 }
465 /* TODO: Conflict with format strings! "%" (37) may be used as the color value. */
465 /* Double-\r is used for range extension. */ 466 /* Double-\r is used for range extension. */
466 if (color + asciiBase_ColorEscape > 127) { 467 if (color + asciiBase_ColorEscape > 127) {
467 iAssert(color - asciiExtended_ColorEscape + asciiBase_ColorEscape <= 127); 468 iAssert(color - asciiExtended_ColorEscape + asciiBase_ColorEscape <= 127);
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 240b2d4a..ff89f5ec 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -3245,7 +3245,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
3245 showHost)) { 3245 showHost)) {
3246 format_String( 3246 format_String(
3247 &str, 3247 &str,
3248 " \u2014%s%s%s\r%c%s", 3248 " \u2014%s%s%s%s%s",
3249 showHost ? " " : "", 3249 showHost ? " " : "",
3250 showHost 3250 showHost
3251 ? (flags & mailto_GmLinkFlag ? cstr_String(url) 3251 ? (flags & mailto_GmLinkFlag ? cstr_String(url)
@@ -3256,9 +3256,8 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
3256 : "", 3256 : "",
3257 showHost && (showImage || showAudio) ? " \u2014" : "", 3257 showHost && (showImage || showAudio) ? " \u2014" : "",
3258 showImage || showAudio 3258 showImage || showAudio
3259 ? asciiBase_ColorEscape + fg 3259 ? escape_Color(fg)
3260 : (asciiBase_ColorEscape + 3260 : escape_Color(linkColor_GmDocument(doc, run->linkId, domain_GmLinkPart)),
3261 linkColor_GmDocument(doc, run->linkId, domain_GmLinkPart)),
3262 showImage || showAudio 3261 showImage || showAudio
3263 ? format_CStr(showImage ? " %s \U0001f5bb" : " %s \U0001f3b5", 3262 ? format_CStr(showImage ? " %s \U0001f5bb" : " %s \U0001f3b5",
3264 cstr_Lang(showImage ? "link.hint.image" : "link.hint.audio")) 3263 cstr_Lang(showImage ? "link.hint.image" : "link.hint.audio"))
@@ -3267,11 +3266,10 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
3267 if (run->flags & endOfLine_GmRunFlag && flags & visited_GmLinkFlag) { 3266 if (run->flags & endOfLine_GmRunFlag && flags & visited_GmLinkFlag) {
3268 iDate date; 3267 iDate date;
3269 init_Date(&date, linkTime_GmDocument(doc, run->linkId)); 3268 init_Date(&date, linkTime_GmDocument(doc, run->linkId));
3270 appendFormat_String(&str, 3269 appendCStr_String(&str, " \u2014 ");
3271 " \u2014 %s%s", 3270 appendCStr_String(
3272 escape_Color(linkColor_GmDocument(doc, run->linkId, 3271 &str, escape_Color(linkColor_GmDocument(doc, run->linkId, visited_GmLinkPart)));
3273 visited_GmLinkPart)), 3272 append_String(&str, collect_String(format_Date(&date, "%b %d")));
3274 cstr_String(collect_String(format_Date(&date, "%b %d"))));
3275 } 3273 }
3276 if (!isEmpty_String(&str)) { 3274 if (!isEmpty_String(&str)) {
3277 const iInt2 textSize = measure_Text(metaFont, cstr_String(&str)); 3275 const iInt2 textSize = measure_Text(metaFont, cstr_String(&str));
diff --git a/src/ui/text.c b/src/ui/text.c
index 83073d1f..68dce44d 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -995,11 +995,11 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
995 if (ch == '\r') { /* color change */ 995 if (ch == '\r') { /* color change */
996 iChar esc = nextChar_(&chPos, args->text.end); 996 iChar esc = nextChar_(&chPos, args->text.end);
997 int colorNum = args->color; 997 int colorNum = args->color;
998 if (esc != 0x24) { /* ASCII Cancel */ 998 if (esc == '\r') { /* Extended range. */
999 esc = nextChar_(&chPos, args->text.end) + asciiExtended_ColorEscape;
999 colorNum = esc - asciiBase_ColorEscape; 1000 colorNum = esc - asciiBase_ColorEscape;
1000 } 1001 }
1001 else if (esc == '\r') { /* Extended range. */ 1002 else if (esc != 0x24) { /* ASCII Cancel */
1002 esc = nextChar_(&chPos, args->text.end) + asciiExtended_ColorEscape;
1003 colorNum = esc - asciiBase_ColorEscape; 1003 colorNum = esc - asciiBase_ColorEscape;
1004 } 1004 }
1005 if (mode & draw_RunMode && ~mode & permanentColorFlag_RunMode) { 1005 if (mode & draw_RunMode && ~mode & permanentColorFlag_RunMode) {