summaryrefslogtreecommitdiff
path: root/src/gmdocument.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r--src/gmdocument.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index b9832f38..75f6f06b 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -82,6 +82,7 @@ struct Impl_GmDocument {
82 iString url; /* for resolving relative links */ 82 iString url; /* for resolving relative links */
83 iString localHost; 83 iString localHost;
84 iInt2 size; 84 iInt2 size;
85 int outsideMargin;
85 iArray layout; /* contents of source, laid out in document space */ 86 iArray layout; /* contents of source, laid out in document space */
86 iPtrArray links; 87 iPtrArray links;
87 enum iGmDocumentBanner bannerType; 88 enum iGmDocumentBanner bannerType;
@@ -239,7 +240,10 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li
239 iString *path = newRange_String(parts.path); 240 iString *path = newRange_String(parts.path);
240 if (endsWithCase_String(path, ".gif") || endsWithCase_String(path, ".jpg") || 241 if (endsWithCase_String(path, ".gif") || endsWithCase_String(path, ".jpg") ||
241 endsWithCase_String(path, ".jpeg") || endsWithCase_String(path, ".png") || 242 endsWithCase_String(path, ".jpeg") || endsWithCase_String(path, ".png") ||
242 endsWithCase_String(path, ".tga") || endsWithCase_String(path, ".psd") || 243 endsWithCase_String(path, ".tga") || endsWithCase_String(path, ".psd") ||
244#if defined (LAGRANGE_ENABLE_WEBP)
245 endsWithCase_String(path, ".webp") ||
246#endif
243 endsWithCase_String(path, ".hdr") || endsWithCase_String(path, ".pic")) { 247 endsWithCase_String(path, ".hdr") || endsWithCase_String(path, ".pic")) {
244 link->flags |= imageFileExtension_GmLinkFlag; 248 link->flags |= imageFileExtension_GmLinkFlag;
245 } 249 }
@@ -896,6 +900,12 @@ static void doLayout_GmDocument_(iGmDocument *d) {
896 pos.y += margin; 900 pos.y += margin;
897 run.bounds.pos = pos; 901 run.bounds.pos = pos;
898 run.bounds.size.x = d->size.x; 902 run.bounds.size.x = d->size.x;
903 /* Extend the image to full width, including outside margin, if the viewport
904 is narrow enough. */
905 if (d->outsideMargin < 5 * gap_UI) {
906 run.bounds.size.x += d->outsideMargin * 2;
907 run.bounds.pos.x -= d->outsideMargin;
908 }
899 const float aspect = (float) imgSize.y / (float) imgSize.x; 909 const float aspect = (float) imgSize.y / (float) imgSize.x;
900 run.bounds.size.y = d->size.x * aspect; 910 run.bounds.size.y = d->size.x * aspect;
901 run.visBounds = run.bounds; 911 run.visBounds = run.bounds;
@@ -990,6 +1000,7 @@ void init_GmDocument(iGmDocument *d) {
990 init_String(&d->url); 1000 init_String(&d->url);
991 init_String(&d->localHost); 1001 init_String(&d->localHost);
992 d->bannerType = siteDomain_GmDocumentBanner; 1002 d->bannerType = siteDomain_GmDocumentBanner;
1003 d->outsideMargin = 0;
993 d->size = zero_I2(); 1004 d->size = zero_I2();
994 init_Array(&d->layout, sizeof(iGmRun)); 1005 init_Array(&d->layout, sizeof(iGmRun));
995 init_PtrArray(&d->links); 1006 init_PtrArray(&d->links);
@@ -1543,8 +1554,9 @@ void setBanner_GmDocument(iGmDocument *d, enum iGmDocumentBanner type) {
1543 d->bannerType = type; 1554 d->bannerType = type;
1544} 1555}
1545 1556
1546void setWidth_GmDocument(iGmDocument *d, int width) { 1557void setWidth_GmDocument(iGmDocument *d, int width, int outsideMargin) {
1547 d->size.x = width; 1558 d->size.x = width;
1559 d->outsideMargin = outsideMargin; /* distance to edge of the viewport */
1548 doLayout_GmDocument_(d); /* TODO: just flag need-layout and do it later */ 1560 doLayout_GmDocument_(d); /* TODO: just flag need-layout and do it later */
1549} 1561}
1550 1562
@@ -1698,7 +1710,7 @@ void setUrl_GmDocument(iGmDocument *d, const iString *url) {
1698 updateIconBasedOnUrl_GmDocument_(d); 1710 updateIconBasedOnUrl_GmDocument_(d);
1699} 1711}
1700 1712
1701void setSource_GmDocument(iGmDocument *d, const iString *source, int width, 1713void setSource_GmDocument(iGmDocument *d, const iString *source, int width, int outsideMargin,
1702 enum iGmDocumentUpdate updateType) { 1714 enum iGmDocumentUpdate updateType) {
1703// printf("[GmDocument] source update (%zu bytes), width:%d, final:%d\n", 1715// printf("[GmDocument] source update (%zu bytes), width:%d, final:%d\n",
1704// size_String(source), width, updateType == final_GmDocumentUpdate); 1716// size_String(source), width, updateType == final_GmDocumentUpdate);
@@ -1713,7 +1725,7 @@ void setSource_GmDocument(iGmDocument *d, const iString *source, int width,
1713 if (isNormalized_GmDocument_(d)) { 1725 if (isNormalized_GmDocument_(d)) {
1714 normalize_GmDocument(d); 1726 normalize_GmDocument(d);
1715 } 1727 }
1716 setWidth_GmDocument(d, width); /* re-do layout */ 1728 setWidth_GmDocument(d, width, outsideMargin); /* re-do layout */
1717} 1729}
1718 1730
1719void foldPre_GmDocument(iGmDocument *d, uint16_t preId) { 1731void foldPre_GmDocument(iGmDocument *d, uint16_t preId) {