diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-10-08 15:27:14 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-10-08 15:27:14 +0300 |
commit | 52b6013cc01e17f4b500ea79fb786ccc14b1f7ec (patch) | |
tree | d3f1a91a282cbb225d8578fabf18a2690205738d /src/gmdocument.c | |
parent | deea4951aa8e4068daccb15b7960aa84ebfe906f (diff) |
Font configuration; Prefs has a string value array
Added a second version of Iosevka with more line spacing, to be used as the default monospace document font.
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r-- | src/gmdocument.c | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c index ce9fdec8..c98b0bb8 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -468,22 +468,23 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
468 | const iBool isDarkBg = isDark_GmDocumentTheme( | 468 | const iBool isDarkBg = isDark_GmDocumentTheme( |
469 | isDark_ColorTheme(colorTheme_App()) ? prefs->docThemeDark : prefs->docThemeLight); | 469 | isDark_ColorTheme(colorTheme_App()) ? prefs->docThemeDark : prefs->docThemeLight); |
470 | /* TODO: Collect these parameters into a GmTheme. */ | 470 | /* TODO: Collect these parameters into a GmTheme. */ |
471 | const enum iFontId headingFont = isMono ? documentMonospace_FontId : documentHeading_FontId; | ||
472 | const enum iFontId bodyFont = isMono ? documentMonospace_FontId : documentBody_FontId; | ||
471 | const int fonts[max_GmLineType] = { | 473 | const int fonts[max_GmLineType] = { |
472 | isMono ? regularMonospace_FontId : paragraph_FontId, | 474 | FONT_ID(bodyFont, regular_FontStyle, contentRegular_FontSize), /* text */ |
473 | isMono ? regularMonospace_FontId : paragraph_FontId, /* bullet */ | 475 | FONT_ID(bodyFont, regular_FontStyle, contentRegular_FontSize), /* bullet */ |
474 | preformatted_FontId, | 476 | preformatted_FontId, /* pre */ |
475 | isMono ? regularMonospace_FontId : quote_FontId, | 477 | isMono ? monospaceParagraph_FontId : quote_FontId, /* quote */ |
476 | heading1_FontId, | 478 | FONT_ID(headingFont, bold_FontStyle, contentHuge_FontSize), /* h1 */ |
477 | heading2_FontId, | 479 | FONT_ID(headingFont, bold_FontStyle, contentLarge_FontSize), /* h2 */ |
478 | heading3_FontId, | 480 | FONT_ID(headingFont, regular_FontStyle, contentBig_FontSize), /* h3 */ |
479 | isMono ? regularMonospace_FontId | 481 | FONT_ID(bodyFont, |
480 | : ((isDarkBg && prefs->boldLinkDark) || (!isDarkBg && prefs->boldLinkLight)) | 482 | ((isDarkBg && prefs->boldLinkDark) || (!isDarkBg && prefs->boldLinkLight)) |
481 | ? bold_FontId | 483 | ? semiBold_FontStyle |
482 | : paragraph_FontId, | 484 | : regular_FontStyle, |
483 | }; | 485 | contentRegular_FontSize) /* link */ |
484 | float indents[max_GmLineType] = { | ||
485 | 5, 10, 5, isNarrow ? 5 : 10, 0, 0, 0, 5 | ||
486 | }; | 486 | }; |
487 | float indents[max_GmLineType] = { 5, 10, 5, isNarrow ? 5 : 10, 0, 0, 0, 5 }; | ||
487 | if (isExtremelyNarrow) { | 488 | if (isExtremelyNarrow) { |
488 | /* Further reduce the margins. */ | 489 | /* Further reduce the margins. */ |
489 | indents[text_GmLineType] -= 5; | 490 | indents[text_GmLineType] -= 5; |
@@ -562,10 +563,13 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
562 | iGmPreMeta meta = { .bounds = line }; | 563 | iGmPreMeta meta = { .bounds = line }; |
563 | meta.pixelRect.size = measurePreformattedBlock_GmDocument_( | 564 | meta.pixelRect.size = measurePreformattedBlock_GmDocument_( |
564 | d, line.start, preFont, &meta.contents, &meta.bounds.end); | 565 | d, line.start, preFont, &meta.contents, &meta.bounds.end); |
565 | if (meta.pixelRect.size.x > | 566 | const float oversizeRatio = |
566 | d->size.x - (enableIndents ? indents[preformatted_GmLineType] : 0) * gap_Text) { | 567 | meta.pixelRect.size.x / |
567 | preFont = preformattedSmall_FontId; | 568 | (float) (d->size.x - |
568 | meta.pixelRect.size = measureRange_Text(preFont, meta.contents).bounds.size; | 569 | (enableIndents ? indents[preformatted_GmLineType] : 0) * gap_Text); |
570 | if (oversizeRatio > 1.0f) { | ||
571 | preFont--; /* one notch smaller in the font size */ | ||
572 | meta.pixelRect.size = measureRange_Text(preFont, meta.contents).bounds.size; | ||
569 | } | 573 | } |
570 | trimLine_Rangecc(&line, type, isNormalized); | 574 | trimLine_Rangecc(&line, type, isNormalized); |
571 | meta.altText = line; /* without the ``` */ | 575 | meta.altText = line; /* without the ``` */ |
@@ -611,7 +615,7 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
611 | continue; | 615 | continue; |
612 | } | 616 | } |
613 | run.preId = preId; | 617 | run.preId = preId; |
614 | run.font = (d->format == plainText_SourceFormat ? regularMonospace_FontId : preFont); | 618 | run.font = (d->format == plainText_SourceFormat ? plainText_FontId : preFont); |
615 | indent = indents[type]; | 619 | indent = indents[type]; |
616 | } | 620 | } |
617 | if (addSiteBanner) { | 621 | if (addSiteBanner) { |
@@ -719,11 +723,13 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
719 | if (type == bullet_GmLineType) { | 723 | if (type == bullet_GmLineType) { |
720 | /* TODO: Literata bullet is broken? */ | 724 | /* TODO: Literata bullet is broken? */ |
721 | iGmRun bulRun = run; | 725 | iGmRun bulRun = run; |
726 | #if 0 | ||
722 | if (prefs->font == literata_TextFont) { | 727 | if (prefs->font == literata_TextFont) { |
723 | /* Something wrong this the glyph in Literata, looks cropped. */ | 728 | /* Something wrong this the glyph in Literata, looks cropped. */ |
724 | bulRun.font = FONT_ID(default_FontId, regular_FontStyle, | 729 | bulRun.font = FONT_ID(default_FontId, regular_FontStyle, |
725 | contentRegular_FontSize); | 730 | contentRegular_FontSize); |
726 | } | 731 | } |
732 | #endif | ||
727 | bulRun.color = tmQuote_ColorId; | 733 | bulRun.color = tmQuote_ColorId; |
728 | bulRun.visBounds.pos = addX_I2(pos, (indents[text_GmLineType] - 0.55f) * gap_Text); | 734 | bulRun.visBounds.pos = addX_I2(pos, (indents[text_GmLineType] - 0.55f) * gap_Text); |
729 | bulRun.visBounds.size = | 735 | bulRun.visBounds.size = |
@@ -778,7 +784,7 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
778 | } | 784 | } |
779 | /* TODO: List bullets needs the same centering logic. */ | 785 | /* TODO: List bullets needs the same centering logic. */ |
780 | /* Special exception for the tiny bullet operator. */ | 786 | /* Special exception for the tiny bullet operator. */ |
781 | icon.font = equal_Rangecc(link->labelIcon, "\u2219") ? regularMonospace_FontId | 787 | icon.font = equal_Rangecc(link->labelIcon, "\u2219") ? preformatted_FontId |
782 | : paragraph_FontId; | 788 | : paragraph_FontId; |
783 | alignDecoration_GmRun_(&icon, iFalse); | 789 | alignDecoration_GmRun_(&icon, iFalse); |
784 | icon.color = linkColor_GmDocument(d, run.linkId, icon_GmLinkPart); | 790 | icon.color = linkColor_GmDocument(d, run.linkId, icon_GmLinkPart); |
@@ -882,9 +888,9 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
882 | break; | 888 | break; |
883 | } | 889 | } |
884 | clear_RunTypesetter_(&rts); | 890 | clear_RunTypesetter_(&rts); |
885 | rts.pos = pos; | 891 | rts.pos = pos; |
886 | rts.run.font = rts.fonts[text_GmLineType]; | 892 | rts.run.font = rts.fonts[text_GmLineType]; |
887 | rts.run.color = colors[text_GmLineType]; | 893 | rts.run.color = colors[text_GmLineType]; |
888 | isLedeParagraph = iFalse; | 894 | isLedeParagraph = iFalse; |
889 | } | 895 | } |
890 | pos = rts.pos; | 896 | pos = rts.pos; |
@@ -925,7 +931,7 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
925 | run.visBounds.pos.x = run.bounds.size.x / 2 - width_Rect(run.visBounds) / 2; | 931 | run.visBounds.pos.x = run.bounds.size.x / 2 - width_Rect(run.visBounds) / 2; |
926 | run.bounds.size.y = run.visBounds.size.y; | 932 | run.bounds.size.y = run.visBounds.size.y; |
927 | } | 933 | } |
928 | run.text = iNullRange; | 934 | run.text = iNullRange; |
929 | run.font = 0; | 935 | run.font = 0; |
930 | run.color = 0; | 936 | run.color = 0; |
931 | run.mediaType = image_GmRunMediaType; | 937 | run.mediaType = image_GmRunMediaType; |
@@ -944,9 +950,9 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
944 | run.bounds.size.y = lineHeight_Text(uiContent_FontId) + 3 * gap_UI; | 950 | run.bounds.size.y = lineHeight_Text(uiContent_FontId) + 3 * gap_UI; |
945 | run.visBounds = run.bounds; | 951 | run.visBounds = run.bounds; |
946 | run.text = iNullRange; | 952 | run.text = iNullRange; |
947 | run.color = 0; | 953 | run.color = 0; |
948 | run.mediaType = audio_GmRunMediaType; | 954 | run.mediaType = audio_GmRunMediaType; |
949 | run.mediaId = audioId; | 955 | run.mediaId = audioId; |
950 | pushBack_Array(&d->layout, &run); | 956 | pushBack_Array(&d->layout, &run); |
951 | pos.y += run.bounds.size.y + margin; | 957 | pos.y += run.bounds.size.y + margin; |
952 | } | 958 | } |