diff options
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r-- | src/gmdocument.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c index 8b24ce29..0027bdb3 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -161,10 +161,9 @@ struct Impl_GmDocument { | |||
161 | iInt2 size; | 161 | iInt2 size; |
162 | int outsideMargin; | 162 | int outsideMargin; |
163 | iBool enableCommandLinks; /* `about:command?` only allowed on selected pages */ | 163 | iBool enableCommandLinks; /* `about:command?` only allowed on selected pages */ |
164 | iBool isLayoutInvalidated; | ||
164 | iArray layout; /* contents of source, laid out in document space */ | 165 | iArray layout; /* contents of source, laid out in document space */ |
165 | iPtrArray links; | 166 | iPtrArray links; |
166 | // enum iGmDocumentBanner bannerType; | ||
167 | // iString bannerText; | ||
168 | iString title; /* the first top-level title */ | 167 | iString title; /* the first top-level title */ |
169 | iArray headings; | 168 | iArray headings; |
170 | iArray preMeta; /* metadata about preformatted blocks */ | 169 | iArray preMeta; /* metadata about preformatted blocks */ |
@@ -607,6 +606,7 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
607 | // const iBool isDarkBg = isDark_GmDocumentTheme( | 606 | // const iBool isDarkBg = isDark_GmDocumentTheme( |
608 | // isDark_ColorTheme(colorTheme_App()) ? prefs->docThemeDark : prefs->docThemeLight); | 607 | // isDark_ColorTheme(colorTheme_App()) ? prefs->docThemeDark : prefs->docThemeLight); |
609 | initTheme_GmDocument_(d); | 608 | initTheme_GmDocument_(d); |
609 | d->isLayoutInvalidated = iFalse; | ||
610 | /* TODO: Collect these parameters into a GmTheme. */ | 610 | /* TODO: Collect these parameters into a GmTheme. */ |
611 | float indents[max_GmLineType] = { 5, 10, 5, isNarrow ? 5 : 10, 0, 0, 0, 5 }; | 611 | float indents[max_GmLineType] = { 5, 10, 5, isNarrow ? 5 : 10, 0, 0, 0, 5 }; |
612 | if (isExtremelyNarrow) { | 612 | if (isExtremelyNarrow) { |
@@ -968,6 +968,7 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
968 | ? 4 : 0) * gap_Text; | 968 | ? 4 : 0) * gap_Text; |
969 | } | 969 | } |
970 | if (!isMono) { | 970 | if (!isMono) { |
971 | #if 0 | ||
971 | /* Upper-level headings are typeset a bit tighter. */ | 972 | /* Upper-level headings are typeset a bit tighter. */ |
972 | if (type == heading1_GmLineType) { | 973 | if (type == heading1_GmLineType) { |
973 | rts.lineHeightReduction = 0.10f; | 974 | rts.lineHeightReduction = 0.10f; |
@@ -975,6 +976,7 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
975 | else if (type == heading2_GmLineType) { | 976 | else if (type == heading2_GmLineType) { |
976 | rts.lineHeightReduction = 0.06f; | 977 | rts.lineHeightReduction = 0.06f; |
977 | } | 978 | } |
979 | #endif | ||
978 | /* Visited links are never bold. */ | 980 | /* Visited links are never bold. */ |
979 | if (run.linkId && !prefs->boldLinkVisited && | 981 | if (run.linkId && !prefs->boldLinkVisited && |
980 | linkFlags_GmDocument(d, run.linkId) & visited_GmLinkFlag) { | 982 | linkFlags_GmDocument(d, run.linkId) & visited_GmLinkFlag) { |
@@ -1142,13 +1144,12 @@ void init_GmDocument(iGmDocument *d) { | |||
1142 | init_String(&d->source); | 1144 | init_String(&d->source); |
1143 | init_String(&d->url); | 1145 | init_String(&d->url); |
1144 | init_String(&d->localHost); | 1146 | init_String(&d->localHost); |
1145 | // d->bannerType = siteDomain_GmDocumentBanner; | ||
1146 | d->outsideMargin = 0; | 1147 | d->outsideMargin = 0; |
1147 | d->size = zero_I2(); | 1148 | d->size = zero_I2(); |
1148 | d->enableCommandLinks = iFalse; | 1149 | d->enableCommandLinks = iFalse; |
1150 | d->isLayoutInvalidated = iFalse; | ||
1149 | init_Array(&d->layout, sizeof(iGmRun)); | 1151 | init_Array(&d->layout, sizeof(iGmRun)); |
1150 | init_PtrArray(&d->links); | 1152 | init_PtrArray(&d->links); |
1151 | // init_String(&d->bannerText); | ||
1152 | init_String(&d->title); | 1153 | init_String(&d->title); |
1153 | init_Array(&d->headings, sizeof(iGmHeading)); | 1154 | init_Array(&d->headings, sizeof(iGmHeading)); |
1154 | init_Array(&d->preMeta, sizeof(iGmPreMeta)); | 1155 | init_Array(&d->preMeta, sizeof(iGmPreMeta)); |
@@ -1164,7 +1165,6 @@ void init_GmDocument(iGmDocument *d) { | |||
1164 | void deinit_GmDocument(iGmDocument *d) { | 1165 | void deinit_GmDocument(iGmDocument *d) { |
1165 | iReleasePtr(&d->openURLs); | 1166 | iReleasePtr(&d->openURLs); |
1166 | delete_Media(d->media); | 1167 | delete_Media(d->media); |
1167 | // deinit_String(&d->bannerText); | ||
1168 | deinit_String(&d->title); | 1168 | deinit_String(&d->title); |
1169 | clearLinks_GmDocument_(d); | 1169 | clearLinks_GmDocument_(d); |
1170 | deinit_PtrArray(&d->links); | 1170 | deinit_PtrArray(&d->links); |
@@ -1720,22 +1720,28 @@ void setFormat_GmDocument(iGmDocument *d, enum iSourceFormat format) { | |||
1720 | d->format = format; | 1720 | d->format = format; |
1721 | } | 1721 | } |
1722 | 1722 | ||
1723 | #if 0 | 1723 | void setWidth_GmDocument(iGmDocument *d, int width, int canvasWidth) { |
1724 | void setBanner_GmDocument(iGmDocument *d, enum iGmDocumentBanner type) { | 1724 | d->size.x = width; |
1725 | d->bannerType = type; | 1725 | d->outsideMargin = iMax(0, (canvasWidth - width) / 2); /* distance to edge of the canvas */ |
1726 | doLayout_GmDocument_(d); /* TODO: just flag need-layout and do it later */ | ||
1726 | } | 1727 | } |
1727 | #endif | ||
1728 | 1728 | ||
1729 | void setWidth_GmDocument(iGmDocument *d, int width, int outsideMargin) { | 1729 | iBool updateWidth_GmDocument(iGmDocument *d, int width, int canvasWidth) { |
1730 | d->size.x = width; | 1730 | if (d->size.x != width || d->isLayoutInvalidated) { |
1731 | d->outsideMargin = outsideMargin; /* distance to edge of the viewport */ | 1731 | setWidth_GmDocument(d, width, canvasWidth); |
1732 | doLayout_GmDocument_(d); /* TODO: just flag need-layout and do it later */ | 1732 | return iTrue; |
1733 | } | ||
1734 | return iFalse; | ||
1733 | } | 1735 | } |
1734 | 1736 | ||
1735 | void redoLayout_GmDocument(iGmDocument *d) { | 1737 | void redoLayout_GmDocument(iGmDocument *d) { |
1736 | doLayout_GmDocument_(d); | 1738 | doLayout_GmDocument_(d); |
1737 | } | 1739 | } |
1738 | 1740 | ||
1741 | void invalidateLayout_GmDocument(iGmDocument *d) { | ||
1742 | d->isLayoutInvalidated = iTrue; | ||
1743 | } | ||
1744 | |||
1739 | static void markLinkRunsVisited_GmDocument_(iGmDocument *d, const iIntSet *linkIds) { | 1745 | static void markLinkRunsVisited_GmDocument_(iGmDocument *d, const iIntSet *linkIds) { |
1740 | iForEach(Array, r, &d->layout) { | 1746 | iForEach(Array, r, &d->layout) { |
1741 | iGmRun *run = r.value; | 1747 | iGmRun *run = r.value; |
@@ -2080,7 +2086,7 @@ static void convertMarkdownToGemtext_GmDocument_(iGmDocument *d) { | |||
2080 | d->format = gemini_SourceFormat; | 2086 | d->format = gemini_SourceFormat; |
2081 | } | 2087 | } |
2082 | 2088 | ||
2083 | void setSource_GmDocument(iGmDocument *d, const iString *source, int width, int outsideMargin, | 2089 | void setSource_GmDocument(iGmDocument *d, const iString *source, int width, int canvasWidth, |
2084 | enum iGmDocumentUpdate updateType) { | 2090 | enum iGmDocumentUpdate updateType) { |
2085 | /* TODO: This API has been set up to allow partial/progressive updating of the content. | 2091 | /* TODO: This API has been set up to allow partial/progressive updating of the content. |
2086 | Currently the entire source is replaced every time, though. */ | 2092 | Currently the entire source is replaced every time, though. */ |
@@ -2122,7 +2128,7 @@ void setSource_GmDocument(iGmDocument *d, const iString *source, int width, int | |||
2122 | if (isNormalized_GmDocument_(d)) { | 2128 | if (isNormalized_GmDocument_(d)) { |
2123 | normalize_GmDocument(d); | 2129 | normalize_GmDocument(d); |
2124 | } | 2130 | } |
2125 | setWidth_GmDocument(d, width, outsideMargin); /* re-do layout */ | 2131 | setWidth_GmDocument(d, width, canvasWidth); /* re-do layout */ |
2126 | } | 2132 | } |
2127 | 2133 | ||
2128 | void foldPre_GmDocument(iGmDocument *d, uint16_t preId) { | 2134 | void foldPre_GmDocument(iGmDocument *d, uint16_t preId) { |