summaryrefslogtreecommitdiff
path: root/src/gmdocument.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r--src/gmdocument.c52
1 files changed, 40 insertions, 12 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index 4d4ba603..4414b04f 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -331,6 +331,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
331 static const char *globe = "\U0001f310"; 331 static const char *globe = "\U0001f310";
332 static const char *quote = "\u201c"; 332 static const char *quote = "\u201c";
333 const float midRunSkip = 0; /*0.120f;*/ /* extra space between wrapped text/quote lines */ 333 const float midRunSkip = 0; /*0.120f;*/ /* extra space between wrapped text/quote lines */
334 const iPrefs *prefs = prefs_App();
334 clear_Array(&d->layout); 335 clear_Array(&d->layout);
335 clearLinks_GmDocument_(d); 336 clearLinks_GmDocument_(d);
336 clear_Array(&d->headings); 337 clear_Array(&d->headings);
@@ -341,7 +342,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
341 const iRangecc content = range_String(&d->source); 342 const iRangecc content = range_String(&d->source);
342 iRangecc contentLine = iNullRange; 343 iRangecc contentLine = iNullRange;
343 iInt2 pos = zero_I2(); 344 iInt2 pos = zero_I2();
344 iBool isFirstText = isGemini; 345 iBool isFirstText = isGemini && prefs->bigFirstParagraph;
345 iBool addQuoteIcon = iTrue; 346 iBool addQuoteIcon = iTrue;
346 iBool isPreformat = iFalse; 347 iBool isPreformat = iFalse;
347 iRangecc preAltText = iNullRange; 348 iRangecc preAltText = iNullRange;
@@ -620,7 +621,8 @@ void init_GmDocument(iGmDocument *d) {
620 init_String(&d->title); 621 init_String(&d->title);
621 init_Array(&d->headings, sizeof(iGmHeading)); 622 init_Array(&d->headings, sizeof(iGmHeading));
622 init_PtrArray(&d->images); 623 init_PtrArray(&d->images);
623 setThemeSeed_GmDocument(d, NULL); 624 d->themeSeed = 0;
625 d->siteIcon = 0;
624} 626}
625 627
626void deinit_GmDocument(iGmDocument *d) { 628void deinit_GmDocument(iGmDocument *d) {
@@ -649,9 +651,11 @@ void reset_GmDocument(iGmDocument *d) {
649} 651}
650 652
651void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { 653void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
652 const float saturationLevel = 1.0f; /* TODO: user setting */ 654 const iPrefs * prefs = prefs_App();
653 const iBool isLightMode = isLight_ColorTheme(colorTheme_App()); 655 enum iGmDocumentTheme theme =
654 const iBool isDarkMode = !isLightMode; 656 (isDark_ColorTheme(colorTheme_App()) ? prefs->docThemeDark : prefs->docThemeLight);
657// const iBool isLightMode = isLight_ColorTheme(colorTheme_App());
658// const iBool isDarkMode = !isLightMode;
655 static const iChar siteIcons[] = { 659 static const iChar siteIcons[] = {
656 0x203b, 0x2042, 0x205c, 0x2182, 0x25ed, 0x2600, 0x2601, 0x2604, 0x2605, 0x2606, 660 0x203b, 0x2042, 0x205c, 0x2182, 0x25ed, 0x2600, 0x2601, 0x2604, 0x2605, 0x2606,
657 0x265c, 0x265e, 0x2690, 0x2691, 0x2693, 0x2698, 0x2699, 0x26f0, 0x270e, 0x2728, 661 0x265c, 0x265e, 0x2690, 0x2691, 0x2693, 0x2698, 0x2699, 0x26f0, 0x270e, 0x2728,
@@ -661,7 +665,7 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
661 0x1f533, 0x1f657, 0x1f659, 0x1f665, 0x1f668, 0x1f66b, 0x1f78b, 0x1f796, 0x1f79c, 665 0x1f533, 0x1f657, 0x1f659, 0x1f665, 0x1f668, 0x1f66b, 0x1f78b, 0x1f796, 0x1f79c,
662 }; 666 };
663 /* Default colors. */ { 667 /* Default colors. */ {
664 if (isDarkMode) { 668 if (theme == colorfulDark_GmDocumentTheme) {
665 const iHSLColor base = { 200, 0, 0.15f, 1.0f }; 669 const iHSLColor base = { 200, 0, 0.15f, 1.0f };
666 setHsl_Color(tmBackground_ColorId, base); 670 setHsl_Color(tmBackground_ColorId, base);
667 set_Color(tmParagraph_ColorId, get_Color(gray75_ColorId)); 671 set_Color(tmParagraph_ColorId, get_Color(gray75_ColorId));
@@ -783,7 +787,7 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
783 // printf("background: %d %f %f\n", (int) base.hue, base.sat, base.lum); 787 // printf("background: %d %f %f\n", (int) base.hue, base.sat, base.lum);
784 // printf("isDarkBgSat: %d\n", isDarkBgSat); 788 // printf("isDarkBgSat: %d\n", isDarkBgSat);
785 789
786 if (isDarkMode) { 790 if (theme == colorfulDark_GmDocumentTheme) {
787 iHSLColor base = { hues[primIndex], 791 iHSLColor base = { hues[primIndex],
788 0.8f * (d->themeSeed >> 24) / 255.0f, 792 0.8f * (d->themeSeed >> 24) / 255.0f,
789 0.06f + 0.09f * ((d->themeSeed >> 5) & 0x7) / 7.0f, 793 0.06f + 0.09f * ((d->themeSeed >> 5) & 0x7) / 7.0f,
@@ -835,7 +839,7 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
835 /* Adjust colors based on light/dark mode. */ 839 /* Adjust colors based on light/dark mode. */
836 for (int i = tmFirst_ColorId; i < max_ColorId; i++) { 840 for (int i = tmFirst_ColorId; i < max_ColorId; i++) {
837 iHSLColor color = hsl_Color(get_Color(i)); 841 iHSLColor color = hsl_Color(get_Color(i));
838 if (isLightMode) { 842 if (theme == white_GmDocumentTheme) {
839#if 0 843#if 0
840 if (isLink_ColorId(i)) continue; 844 if (isLink_ColorId(i)) continue;
841 color.lum = 1.0f - color.lum; /* All colors invert lightness. */ 845 color.lum = 1.0f - color.lum; /* All colors invert lightness. */
@@ -893,7 +897,9 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
893 } 897 }
894 } 898 }
895 /* Modify overall saturation. */ 899 /* Modify overall saturation. */
896 color.sat *= saturationLevel; 900 if (!isLink_ColorId(i)) {
901 color.sat *= prefs->saturation;
902 }
897 setHsl_Color(i, color); 903 setHsl_Color(i, color);
898 } 904 }
899 } 905 }
@@ -1082,13 +1088,29 @@ iRangecc findTextBefore_GmDocument(const iGmDocument *d, const iString *text, co
1082 1088
1083const iGmRun *findRun_GmDocument(const iGmDocument *d, iInt2 pos) { 1089const iGmRun *findRun_GmDocument(const iGmDocument *d, iInt2 pos) {
1084 /* TODO: Perf optimization likely needed; use a block map? */ 1090 /* TODO: Perf optimization likely needed; use a block map? */
1091 const iGmRun *last = NULL;
1092 iBool isFirstNonDecoration = iTrue;
1085 iConstForEach(Array, i, &d->layout) { 1093 iConstForEach(Array, i, &d->layout) {
1086 const iGmRun *run = i.value; 1094 const iGmRun *run = i.value;
1087 if (contains_Rect(run->bounds, pos)) { 1095 if (run->flags & decoration_GmRunFlag) continue;
1088 return run; 1096 const iRangei span = ySpan_Rect(run->bounds);
1097 if (contains_Range(&span, pos.y)) {
1098 last = run;
1099 break;
1089 } 1100 }
1101 if (isFirstNonDecoration && pos.y < top_Rect(run->bounds)) {
1102 last = run;
1103 break;
1104 }
1105 if (top_Rect(run->bounds) > pos.y) break; /* Below the point. */
1106 last = run;
1107 isFirstNonDecoration = iFalse;
1090 } 1108 }
1091 return NULL; 1109// if (last) {
1110// printf("found run at (%d,%d): %p [%s]\n", pos.x, pos.y, last, cstr_Rangecc(last->text));
1111// fflush(stdout);
1112// }
1113 return last;
1092} 1114}
1093 1115
1094const char *findLoc_GmDocument(const iGmDocument *d, iInt2 pos) { 1116const char *findLoc_GmDocument(const iGmDocument *d, iInt2 pos) {
@@ -1228,7 +1250,13 @@ iChar siteIcon_GmDocument(const iGmDocument *d) {
1228} 1250}
1229 1251
1230const char *findLoc_GmRun(const iGmRun *d, iInt2 pos) { 1252const char *findLoc_GmRun(const iGmRun *d, iInt2 pos) {
1253 if (pos.y < top_Rect(d->bounds)) {
1254 return d->text.start;
1255 }
1231 const int x = pos.x - left_Rect(d->bounds); 1256 const int x = pos.x - left_Rect(d->bounds);
1257 if (x <= 0) {
1258 return d->text.start;
1259 }
1232 const char *loc; 1260 const char *loc;
1233 tryAdvanceNoWrap_Text(d->font, d->text, x, &loc); 1261 tryAdvanceNoWrap_Text(d->font, d->text, x, &loc);
1234 return loc; 1262 return loc;