summaryrefslogtreecommitdiff
path: root/src/gmdocument.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-11-15 07:43:27 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-11-15 07:43:27 +0200
commite9048baadbe738c7b63e2f49f3918053341d720e (patch)
tree307b1dbadbe276c02b12b753d92d49e77b9074a6 /src/gmdocument.c
parentaf08260b09786a89007e5fad7116520fab96acbf (diff)
Added a preference for monospace body text
Monospace body font can be set separately for Gemini and Gopher.
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r--src/gmdocument.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index 4e8b5ace..923c20c9 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -235,24 +235,29 @@ static void clearLinks_GmDocument_(iGmDocument *d) {
235 clear_PtrArray(&d->links); 235 clear_PtrArray(&d->links);
236} 236}
237 237
238#if 0 238static iBool isForcedMonospace_GmDocument_(const iGmDocument *d) {
239static iBool isGopher_GmDocument_(const iGmDocument *d) { 239 const iRangecc scheme = urlScheme_String(&d->url);
240 return equalCase_Rangecc(urlScheme_String(&d->url), "gopher"); 240 if (equalCase_Rangecc(scheme, "gemini")) {
241 return prefs_App()->monospaceGemini;
242 }
243 if (equalCase_Rangecc(scheme, "gopher")) {
244 return prefs_App()->monospaceGopher;
245 }
246 return iFalse;
241} 247}
242#endif
243 248
244static void doLayout_GmDocument_(iGmDocument *d) { 249static void doLayout_GmDocument_(iGmDocument *d) {
245 const iBool isGemini = iTrue; // !isGopher_GmDocument_(d); 250 const iBool isMono = isForcedMonospace_GmDocument_(d);
246 /* TODO: Collect these parameters into a GmTheme. */ 251 /* TODO: Collect these parameters into a GmTheme. */
247 const int fonts[max_GmLineType] = { 252 const int fonts[max_GmLineType] = {
248 isGemini ? paragraph_FontId : preformatted_FontId, 253 isMono ? regularMonospace_FontId : paragraph_FontId,
249 isGemini ? paragraph_FontId : preformatted_FontId, /* bullet */ 254 isMono ? regularMonospace_FontId : paragraph_FontId, /* bullet */
250 preformatted_FontId, 255 preformatted_FontId,
251 quote_FontId, 256 isMono ? regularMonospace_FontId : quote_FontId,
252 isGemini ? heading1_FontId : preformatted_FontId, 257 heading1_FontId,
253 isGemini ? heading2_FontId : preformatted_FontId, 258 heading2_FontId,
254 isGemini ? heading3_FontId : preformatted_FontId, 259 heading3_FontId,
255 regular_FontId, 260 isMono ? regularMonospace_FontId : regular_FontId,
256 }; 261 };
257 static const int colors[max_GmLineType] = { 262 static const int colors[max_GmLineType] = {
258 tmParagraph_ColorId, 263 tmParagraph_ColorId,
@@ -292,7 +297,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
292 const iRangecc content = range_String(&d->source); 297 const iRangecc content = range_String(&d->source);
293 iRangecc contentLine = iNullRange; 298 iRangecc contentLine = iNullRange;
294 iInt2 pos = zero_I2(); 299 iInt2 pos = zero_I2();
295 iBool isFirstText = isGemini && prefs->bigFirstParagraph; 300 iBool isFirstText = prefs->bigFirstParagraph;
296 iBool addQuoteIcon = prefs->quoteIcon; 301 iBool addQuoteIcon = prefs->quoteIcon;
297 iBool isPreformat = iFalse; 302 iBool isPreformat = iFalse;
298 iRangecc preAltText = iNullRange; 303 iRangecc preAltText = iNullRange;
@@ -363,7 +368,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
363 addSiteBanner = iFalse; /* overrides the banner */ 368 addSiteBanner = iFalse; /* overrides the banner */
364 continue; 369 continue;
365 } 370 }
366 run.font = preFont; 371 run.font = (d->format == plainText_GmDocumentFormat ? regularMonospace_FontId : preFont);
367 indent = indents[type]; 372 indent = indents[type];
368 } 373 }
369 if (addSiteBanner) { 374 if (addSiteBanner) {
@@ -463,6 +468,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
463 : link->flags & mailto_GmLinkFlag 468 : link->flags & mailto_GmLinkFlag
464 ? envelope 469 ? envelope
465 : link->flags & remote_GmLinkFlag ? globe : arrow); 470 : link->flags & remote_GmLinkFlag ? globe : arrow);
471 icon.font = regular_FontId;
466 if (link->flags & remote_GmLinkFlag) { 472 if (link->flags & remote_GmLinkFlag) {
467 icon.visBounds.pos.x -= gap_Text / 2; 473 icon.visBounds.pos.x -= gap_Text / 2;
468 } 474 }
@@ -477,7 +483,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
477 /* Special formatting for the first paragraph (e.g., subtitle, introduction, or lede). */ 483 /* Special formatting for the first paragraph (e.g., subtitle, introduction, or lede). */
478 int bigCount = 0; 484 int bigCount = 0;
479 if (type == text_GmLineType && isFirstText) { 485 if (type == text_GmLineType && isFirstText) {
480 run.font = firstParagraph_FontId; 486 if (!isMono) run.font = firstParagraph_FontId;
481 run.color = tmFirstParagraph_ColorId; 487 run.color = tmFirstParagraph_ColorId;
482 bigCount = 15; /* max lines -- what if the whole document is one paragraph? */ 488 bigCount = 15; /* max lines -- what if the whole document is one paragraph? */
483 isFirstText = iFalse; 489 isFirstText = iFalse;
@@ -520,7 +526,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
520 trimStart_Rangecc(&runLine); 526 trimStart_Rangecc(&runLine);
521 pos.y += lineHeight_Text(run.font); 527 pos.y += lineHeight_Text(run.font);
522 if (--bigCount == 0) { 528 if (--bigCount == 0) {
523 run.font = paragraph_FontId; 529 run.font = fonts[text_GmLineType];
524 run.color = colors[text_GmLineType]; 530 run.color = colors[text_GmLineType];
525 } 531 }
526 } 532 }