summaryrefslogtreecommitdiff
path: root/src/gmdocument.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r--src/gmdocument.c47
1 files changed, 39 insertions, 8 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index bd3fa788..c7d5501f 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -107,6 +107,7 @@ struct Impl_GmDocument {
107 iChar siteIcon; 107 iChar siteIcon;
108 iMedia * media; 108 iMedia * media;
109 iStringSet *openURLs; /* currently open URLs for highlighting links */ 109 iStringSet *openURLs; /* currently open URLs for highlighting links */
110 int warnings;
110 iBool isPaletteValid; 111 iBool isPaletteValid;
111 iColor palette[tmMax_ColorId]; /* copy of the color palette */ 112 iColor palette[tmMax_ColorId]; /* copy of the color palette */
112}; 113};
@@ -596,6 +597,8 @@ static void doLayout_GmDocument_(iGmDocument *d) {
596 isPreformat = iTrue; 597 isPreformat = iTrue;
597 isFirstText = iFalse; 598 isFirstText = iFalse;
598 } 599 }
600 d->warnings &= ~missingGlyphs_GmDocumentWarning;
601 checkMissing_Text(); /* clear the flag */
599 setAnsiFlags_Text(d->theme.ansiEscapes); 602 setAnsiFlags_Text(d->theme.ansiEscapes);
600 while (nextSplit_Rangecc(content, "\n", &contentLine)) { 603 while (nextSplit_Rangecc(content, "\n", &contentLine)) {
601 iRangecc line = contentLine; /* `line` will be trimmed; modifying would confuse `nextSplit_Rangecc` */ 604 iRangecc line = contentLine; /* `line` will be trimmed; modifying would confuse `nextSplit_Rangecc` */
@@ -1045,6 +1048,9 @@ static void doLayout_GmDocument_(iGmDocument *d) {
1045 } 1048 }
1046#endif 1049#endif
1047 d->size.y = pos.y; 1050 d->size.y = pos.y;
1051 if (checkMissing_Text()) {
1052 d->warnings |= missingGlyphs_GmDocumentWarning;
1053 }
1048 /* Go over the preformatted blocks and mark them wide if at least one run is wide. */ { 1054 /* Go over the preformatted blocks and mark them wide if at least one run is wide. */ {
1049 /* TODO: Store the dimensions and ranges for later access. */ 1055 /* TODO: Store the dimensions and ranges for later access. */
1050 iForEach(Array, i, &d->layout) { 1056 iForEach(Array, i, &d->layout) {
@@ -1084,6 +1090,7 @@ void init_GmDocument(iGmDocument *d) {
1084 d->siteIcon = 0; 1090 d->siteIcon = 0;
1085 d->media = new_Media(); 1091 d->media = new_Media();
1086 d->openURLs = NULL; 1092 d->openURLs = NULL;
1093 d->warnings = 0;
1087 d->isPaletteValid = iFalse; 1094 d->isPaletteValid = iFalse;
1088 iZap(d->palette); 1095 iZap(d->palette);
1089} 1096}
@@ -1123,16 +1130,28 @@ static void setDerivedThemeColors_(enum iGmDocumentTheme theme) {
1123 mix_Color(get_Color(tmBannerTitle_ColorId), 1130 mix_Color(get_Color(tmBannerTitle_ColorId),
1124 get_Color(tmBackground_ColorId), 1131 get_Color(tmBackground_ColorId),
1125 theme == colorfulDark_GmDocumentTheme ? 0.55f : 0)); 1132 theme == colorfulDark_GmDocumentTheme ? 0.55f : 0));
1126 const int bannerItemFg = isDark_GmDocumentTheme(currentTheme_()) ? white_ColorId : black_ColorId; 1133 /* Banner colors. */
1127 set_Color(tmBannerItemBackground_ColorId, mix_Color(get_Color(tmBannerBackground_ColorId), 1134 if (theme == highContrast_GmDocumentTheme) {
1128 get_Color(tmBannerTitle_ColorId), 0.1f)); 1135 set_Color(tmBannerItemBackground_ColorId, get_Color(tmBannerBackground_ColorId));
1129 set_Color(tmBannerItemFrame_ColorId, mix_Color(get_Color(tmBannerBackground_ColorId), 1136 set_Color(tmBannerItemFrame_ColorId, get_Color(tmBannerIcon_ColorId));
1130 get_Color(tmBannerTitle_ColorId), 0.4f)); 1137 set_Color(tmBannerItemTitle_ColorId, get_Color(tmBannerTitle_ColorId));
1131 set_Color(tmBannerItemText_ColorId, mix_Color(get_Color(tmBannerBackground_ColorId), 1138 set_Color(tmBannerItemText_ColorId, get_Color(tmBannerTitle_ColorId));
1132 get_Color(bannerItemFg), 0.75f)); 1139 }
1133 set_Color(tmBannerItemTitle_ColorId, get_Color(bannerItemFg)); 1140 else {
1141 const int bannerItemFg = isDark_GmDocumentTheme(currentTheme_()) ? white_ColorId : black_ColorId;
1142 set_Color(tmBannerItemBackground_ColorId, mix_Color(get_Color(tmBannerBackground_ColorId),
1143 get_Color(tmBannerTitle_ColorId), 0.1f));
1144 set_Color(tmBannerItemFrame_ColorId, mix_Color(get_Color(tmBannerBackground_ColorId),
1145 get_Color(tmBannerTitle_ColorId), 0.4f));
1146 set_Color(tmBannerItemText_ColorId, mix_Color(get_Color(tmBannerTitle_ColorId),
1147 get_Color(bannerItemFg), 0.5f));
1148 set_Color(tmBannerItemTitle_ColorId, get_Color(bannerItemFg));
1149 }
1150 /* Modified backgrounds. */
1134 set_Color(tmBackgroundAltText_ColorId, 1151 set_Color(tmBackgroundAltText_ColorId,
1135 mix_Color(get_Color(tmQuoteIcon_ColorId), get_Color(tmBackground_ColorId), 0.85f)); 1152 mix_Color(get_Color(tmQuoteIcon_ColorId), get_Color(tmBackground_ColorId), 0.85f));
1153 set_Color(tmFrameAltText_ColorId,
1154 mix_Color(get_Color(tmQuoteIcon_ColorId), get_Color(tmBackground_ColorId), 0.4f));
1136 set_Color(tmBackgroundOpenLink_ColorId, 1155 set_Color(tmBackgroundOpenLink_ColorId,
1137 mix_Color(get_Color(tmLinkText_ColorId), get_Color(tmBackground_ColorId), 0.90f)); 1156 mix_Color(get_Color(tmLinkText_ColorId), get_Color(tmBackground_ColorId), 0.90f));
1138 set_Color(tmFrameOpenLink_ColorId, 1157 set_Color(tmFrameOpenLink_ColorId,
@@ -2008,6 +2027,14 @@ void setSource_GmDocument(iGmDocument *d, const iString *source, int width, int
2008 /* Normalize and convert to Gemtext if needed. */ 2027 /* Normalize and convert to Gemtext if needed. */
2009 set_String(&d->unormSource, source); 2028 set_String(&d->unormSource, source);
2010 set_String(&d->source, source); 2029 set_String(&d->source, source);
2030 /* Detect use of ANSI escapes. */ {
2031 iRegExp *ansiEsc = new_RegExp("\x1b[[()]([0-9;AB]*?)m", 0);
2032 iRegExpMatch m;
2033 init_RegExpMatch(&m);
2034 const iBool found = matchString_RegExp(ansiEsc, &d->unormSource, &m);
2035 iChangeFlags(d->warnings, ansiEscapes_GmDocumentWarning, found);
2036 iRelease(ansiEsc);
2037 }
2011 if (d->format == gemini_SourceFormat) { 2038 if (d->format == gemini_SourceFormat) {
2012 d->theme.ansiEscapes = prefs_App()->gemtextAnsiEscapes; 2039 d->theme.ansiEscapes = prefs_App()->gemtextAnsiEscapes;
2013 } 2040 }
@@ -2157,6 +2184,10 @@ size_t memorySize_GmDocument(const iGmDocument *d) {
2157 memorySize_Media(d->media); 2184 memorySize_Media(d->media);
2158} 2185}
2159 2186
2187int warnings_GmDocument(const iGmDocument *d) {
2188 return d->warnings;
2189}
2190
2160iRangecc findText_GmDocument(const iGmDocument *d, const iString *text, const char *start) { 2191iRangecc findText_GmDocument(const iGmDocument *d, const iString *text, const char *start) {
2161 const char * src = constBegin_String(&d->source); 2192 const char * src = constBegin_String(&d->source);
2162 const size_t startPos = (start ? start - src : 0); 2193 const size_t startPos = (start ? start - src : 0);