From 6e797e23b7c3eb2c4df3418ec007f2196cd3ccd4 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 1 Sep 2020 08:11:37 +0300 Subject: Text: Fixed color escape ASCII overflow --- src/ui/color.c | 3 ++- src/ui/color.h | 40 +++++++++++++++++++++------------------- src/ui/documentwidget.c | 4 ++-- src/ui/labelwidget.c | 4 ++-- src/ui/text.c | 2 +- 5 files changed, 28 insertions(+), 25 deletions(-) (limited to 'src/ui') diff --git a/src/ui/color.c b/src/ui/color.c index e6130aad..723e9805 100644 --- a/src/ui/color.c +++ b/src/ui/color.c @@ -401,7 +401,8 @@ const char *escape_Color(int color) { if (color >= 0 && color < (int) iElemCount(esc)) { return esc[color]; } - return format_CStr("\r%c", color + '0'); + iAssert(asciiBase_ColorEscape + color <= 127); + return format_CStr("\r%c", asciiBase_ColorEscape + color); } iHSLColor setSat_HSLColor(iHSLColor d, float sat) { diff --git a/src/ui/color.h b/src/ui/color.h index 46e7b56a..76e5b2a7 100644 --- a/src/ui/color.h +++ b/src/ui/color.h @@ -68,6 +68,7 @@ enum iColorId { uiText_ColorId, uiTextPressed_ColorId, uiTextSelected_ColorId, + uiTextDisabled_ColorId, uiTextFramelessHover_ColorId, uiTextFramelessSelected_ColorId, uiTextStrong_ColorId, @@ -101,7 +102,6 @@ enum iColorId { uiSeparator_ColorId, uiMarked_ColorId, uiMatching_ColorId, - uiTextDisabled_ColorId, /* content theme colors */ tmFirst_ColorId, @@ -163,24 +163,26 @@ iLocalDef iBool isRegularText_ColorId(enum iColorId d) { #define mask_ColorId 0x7f #define permanent_ColorId 0x80 /* cannot be changed via escapes */ -#define black_ColorEscape "\r0" -#define gray25_ColorEscape "\r1" -#define gray50_ColorEscape "\r2" -#define gray75_ColorEscape "\r3" -#define white_ColorEscape "\r4" -#define brown_ColorEscape "\r5" -#define orange_ColorEscape "\r6" -#define teal_ColorEscape "\r7" -#define cyan_ColorEscape "\r8" -#define yellow_ColorEscape "\r9" -#define red_ColorEscape "\r:" -#define magenta_ColorEscape "\r;" -#define blue_ColorEscape "\r<" -#define green_ColorEscape "\r=" -#define uiText_ColorEscape "\rC" -#define uiTextAction_ColorEscape "\rJ" -#define uiTextCaution_ColorEscape "\rK" -#define uiHeading_ColorEscape "\r`" +#define asciiBase_ColorEscape 33 + +#define black_ColorEscape "\r!" +#define gray25_ColorEscape "\r\"" +#define gray50_ColorEscape "\r#" +#define gray75_ColorEscape "\r$" +#define white_ColorEscape "\r%" +#define brown_ColorEscape "\r&" +#define orange_ColorEscape "\r'" +#define teal_ColorEscape "\r(" +#define cyan_ColorEscape "\r)" +#define yellow_ColorEscape "\r*" +#define red_ColorEscape "\r+" +#define magenta_ColorEscape "\r," +#define blue_ColorEscape "\r-" +#define green_ColorEscape "\r." +#define uiText_ColorEscape "\r4" +#define uiTextAction_ColorEscape "\r<" +#define uiTextCaution_ColorEscape "\r=" +#define uiHeading_ColorEscape "\rR" iDeclareType(Color) iDeclareType(HSLColor) diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 676c94bd..6ca6e4c2 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -1718,8 +1718,8 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { : "", showHost && (showImage || showAudio) ? " \u2014" : "", showImage || showAudio - ? '0' + fg - : ('0' + linkColor_GmDocument(doc, run->linkId, domain_GmLinkPart)), + ? asciiBase_ColorEscape + fg + : (asciiBase_ColorEscape + linkColor_GmDocument(doc, run->linkId, domain_GmLinkPart)), showImage ? " View Image \U0001f5bc" : showAudio ? " Play Audio \U0001f3b5" : ""); } diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c index d41cc73c..8b2506e7 100644 --- a/src/ui/labelwidget.c +++ b/src/ui/labelwidget.c @@ -175,11 +175,11 @@ static void getColors_LabelWidget_(const iLabelWidget *d, int *bg, int *fg, int /* Frames matching color escaped text. */ if (startsWith_String(&d->label, "\r")) { if (isDark_ColorTheme(colorTheme_App())) { - *frame1 = cstr_String(&d->label)[1] - '0'; + *frame1 = cstr_String(&d->label)[1] - asciiBase_ColorEscape; *frame2 = darker_Color(*frame1); } else { - *bg = *frame1 = *frame2 = cstr_String(&d->label)[1] - '0'; + *bg = *frame1 = *frame2 = cstr_String(&d->label)[1] - asciiBase_ColorEscape; *fg = uiBackground_ColorId | permanent_ColorId; } } diff --git a/src/ui/text.c b/src/ui/text.c index a4a3804d..836d540f 100644 --- a/src/ui/text.c +++ b/src/ui/text.c @@ -460,7 +460,7 @@ static iRect run_Font_(iFont *d, enum iRunMode mode, iRangecc text, size_t maxLe if (ch == '\r') { const iChar esc = nextChar_(&chPos, text.end); if (mode == draw_RunMode) { - const iColor clr = get_Color(esc - '0'); + const iColor clr = get_Color(esc - asciiBase_ColorEscape); SDL_SetTextureColorMod(text_.cache, clr.r, clr.g, clr.b); } prevCh = 0; -- cgit v1.2.3