diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-17 07:24:23 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-17 07:24:23 +0300 |
commit | 115602cf34dfb2f151846673468a41f16712eb49 (patch) | |
tree | d6f4330d55799fdb18df2bcd5d96e2c04c8d51f5 /src/gmdocument.c | |
parent | a48aa018640b2d631f318585da23e4ec7f8e8bdc (diff) |
DocumentWidget: Permanent images
A dynamically generated page showing nothing but an image should not be treated the same way as an inline image. I.e., disallow hiding the image on an image page.
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r-- | src/gmdocument.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c index 723e3eaf..b2561ee0 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -64,11 +64,13 @@ struct Impl_GmImage { | |||
64 | size_t numBytes; | 64 | size_t numBytes; |
65 | iString mime; | 65 | iString mime; |
66 | iGmLinkId linkId; | 66 | iGmLinkId linkId; |
67 | iBool isPermanent; | ||
67 | SDL_Texture *texture; | 68 | SDL_Texture *texture; |
68 | }; | 69 | }; |
69 | 70 | ||
70 | void init_GmImage(iGmImage *d, const iBlock *data) { | 71 | void init_GmImage(iGmImage *d, const iBlock *data) { |
71 | init_String(&d->mime); | 72 | init_String(&d->mime); |
73 | d->isPermanent = iFalse; | ||
72 | d->numBytes = size_Block(data); | 74 | d->numBytes = size_Block(data); |
73 | uint8_t *imgData = stbi_load_from_memory( | 75 | uint8_t *imgData = stbi_load_from_memory( |
74 | constData_Block(data), size_Block(data), &d->size.x, &d->size.y, NULL, 4); | 76 | constData_Block(data), size_Block(data), &d->size.x, &d->size.y, NULL, 4); |
@@ -542,8 +544,14 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
542 | if (type == link_GmLineType) { | 544 | if (type == link_GmLineType) { |
543 | const size_t imgIndex = findLinkImage_GmDocument_(d, run.linkId); | 545 | const size_t imgIndex = findLinkImage_GmDocument_(d, run.linkId); |
544 | if (imgIndex != iInvalidPos) { | 546 | if (imgIndex != iInvalidPos) { |
545 | ((iGmLink *) at_PtrArray(&d->links, run.linkId - 1))->flags |= content_GmLinkFlag; | ||
546 | const iGmImage *img = constAt_PtrArray(&d->images, imgIndex); | 547 | const iGmImage *img = constAt_PtrArray(&d->images, imgIndex); |
548 | /* Mark the link as having content. */ { | ||
549 | iGmLink *link = at_PtrArray(&d->links, run.linkId - 1); | ||
550 | link->flags |= content_GmLinkFlag; | ||
551 | if (img->isPermanent) { | ||
552 | link->flags |= permanent_GmLinkFlag; | ||
553 | } | ||
554 | } | ||
547 | const int margin = 0.5f * lineHeight_Text(paragraph_FontId); | 555 | const int margin = 0.5f * lineHeight_Text(paragraph_FontId); |
548 | pos.y += margin; | 556 | pos.y += margin; |
549 | run.bounds.pos = pos; | 557 | run.bounds.pos = pos; |
@@ -952,7 +960,8 @@ void setSource_GmDocument(iGmDocument *d, const iString *source, int width, int | |||
952 | setWidth_GmDocument(d, width, forceBreakWidth); /* re-do layout */ | 960 | setWidth_GmDocument(d, width, forceBreakWidth); /* re-do layout */ |
953 | } | 961 | } |
954 | 962 | ||
955 | void setImage_GmDocument(iGmDocument *d, iGmLinkId linkId, const iString *mime, const iBlock *data) { | 963 | void setImage_GmDocument(iGmDocument *d, iGmLinkId linkId, const iString *mime, const iBlock *data, |
964 | iBool allowHide) { | ||
956 | if (!mime || !data) { | 965 | if (!mime || !data) { |
957 | iGmImage *img; | 966 | iGmImage *img; |
958 | if (take_PtrArray(&d->images, findLinkImage_GmDocument_(d, linkId), (void **) &img)) { | 967 | if (take_PtrArray(&d->images, findLinkImage_GmDocument_(d, linkId), (void **) &img)) { |
@@ -961,16 +970,17 @@ void setImage_GmDocument(iGmDocument *d, iGmLinkId linkId, const iString *mime, | |||
961 | } | 970 | } |
962 | else { | 971 | else { |
963 | /* TODO: check if we know this MIME type */ | 972 | /* TODO: check if we know this MIME type */ |
964 | /* Load the image. */ { | 973 | /* Upload the image. */ { |
965 | iGmImage *img = new_GmImage(data); | 974 | iGmImage *img = new_GmImage(data); |
966 | img->linkId = linkId; /* TODO: use a hash? */ | 975 | img->linkId = linkId; /* TODO: use a hash? */ |
976 | img->isPermanent = !allowHide; | ||
967 | set_String(&img->mime, mime); | 977 | set_String(&img->mime, mime); |
968 | if (img->texture) { | 978 | if (img->texture) { |
969 | pushBack_PtrArray(&d->images, img); | 979 | pushBack_PtrArray(&d->images, img); |
970 | } | 980 | } |
971 | else { | 981 | else { |
972 | delete_GmImage(img); | 982 | delete_GmImage(img); |
973 | } | 983 | } |
974 | } | 984 | } |
975 | } | 985 | } |
976 | doLayout_GmDocument_(d); | 986 | doLayout_GmDocument_(d); |