summaryrefslogtreecommitdiff
path: root/src/gmdocument.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r--src/gmdocument.c159
1 files changed, 74 insertions, 85 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index c98b0bb8..c271ad94 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -27,6 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
27#include "ui/color.h" 27#include "ui/color.h"
28#include "ui/text.h" 28#include "ui/text.h"
29#include "ui/metrics.h" 29#include "ui/metrics.h"
30#include "ui/mediaui.h"
30#include "ui/window.h" 31#include "ui/window.h"
31#include "visited.h" 32#include "visited.h"
32#include "bookmarks.h" 33#include "bookmarks.h"
@@ -224,7 +225,7 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li
224 setScheme_GmLink_(link, finger_GmLinkScheme); 225 setScheme_GmLink_(link, finger_GmLinkScheme);
225 } 226 }
226 else if (equalCase_Rangecc(parts.scheme, "file")) { 227 else if (equalCase_Rangecc(parts.scheme, "file")) {
227 setScheme_GmLink_(link, file_GmLinkScheme); 228 setScheme_GmLink_(link, file_GmLinkScheme);
228 } 229 }
229 else if (equalCase_Rangecc(parts.scheme, "data")) { 230 else if (equalCase_Rangecc(parts.scheme, "data")) {
230 setScheme_GmLink_(link, data_GmLinkScheme); 231 setScheme_GmLink_(link, data_GmLinkScheme);
@@ -251,6 +252,9 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li
251 endsWithCase_String(path, ".mid") || endsWithCase_String(path, ".ogg")) { 252 endsWithCase_String(path, ".mid") || endsWithCase_String(path, ".ogg")) {
252 link->flags |= audioFileExtension_GmLinkFlag; 253 link->flags |= audioFileExtension_GmLinkFlag;
253 } 254 }
255 else if (endsWithCase_String(path, ".fontpack")) {
256 link->flags |= fontpackFileExtension_GmLinkFlag;
257 }
254 delete_String(path); 258 delete_String(path);
255 } 259 }
256 /* Check if visited. */ 260 /* Check if visited. */
@@ -503,7 +507,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
503 static const char *arrow = rightArrowhead_Icon; 507 static const char *arrow = rightArrowhead_Icon;
504 static const char *envelope = envelope_Icon; 508 static const char *envelope = envelope_Icon;
505 static const char *bullet = "\u2022"; 509 static const char *bullet = "\u2022";
506 static const char *folder = "\U0001f4c1"; 510 static const char *folder = file_Icon;
507 static const char *globe = globe_Icon; 511 static const char *globe = globe_Icon;
508 static const char *quote = "\u201c"; 512 static const char *quote = "\u201c";
509 static const char *magnifyingGlass = "\U0001f50d"; 513 static const char *magnifyingGlass = "\U0001f50d";
@@ -900,77 +904,77 @@ static void doLayout_GmDocument_(iGmDocument *d) {
900 ((iGmRun *) back_Array(&d->layout))->flags |= endOfLine_GmRunFlag; 904 ((iGmRun *) back_Array(&d->layout))->flags |= endOfLine_GmRunFlag;
901 /* Image or audio content. */ 905 /* Image or audio content. */
902 if (type == link_GmLineType) { 906 if (type == link_GmLineType) {
903 const iMediaId imageId = findLinkImage_Media(d->media, run.linkId); 907 /* TODO: Cleanup here? Move to a function of its own. */
904 const iMediaId audioId = !imageId ? findLinkAudio_Media(d->media, run.linkId) : 0; 908// enum iMediaType mediaType = none_MediaType;
905 const iMediaId downloadId = !imageId && !audioId ? findLinkDownload_Media(d->media, run.linkId) : 0; 909 const iMediaId media = findMediaForLink_Media(d->media, run.linkId, none_MediaType);
906 if (imageId) { 910 iGmMediaInfo info;
907 iGmMediaInfo img; 911 info_Media(d->media, media, &info);
908 imageInfo_Media(d->media, imageId, &img); 912 run.mediaType = media.type;
909 const iInt2 imgSize = imageSize_Media(d->media, imageId); 913 run.mediaId = media.id;
910 linkContentWasLaidOut_GmDocument_(d, &img, run.linkId); 914 run.text = iNullRange;
911 const int margin = lineHeight_Text(paragraph_FontId) / 2; 915 run.font = uiLabel_FontId;
916 run.color = 0;
917 const int margin = lineHeight_Text(paragraph_FontId) / 2;
918 if (media.type) {
912 pos.y += margin; 919 pos.y += margin;
913 run.bounds.pos = pos; 920 run.bounds.size.y = 0;
914 run.bounds.size.x = d->size.x;
915 const float aspect = (float) imgSize.y / (float) imgSize.x;
916 run.bounds.size.y = d->size.x * aspect;
917 /* Extend the image to full width, including outside margin, if the viewport
918 is narrow enough. */
919 if (isFullWidthImages) {
920 run.bounds.size.x += d->outsideMargin * 2;
921 run.bounds.size.y += d->outsideMargin * 2 * aspect;
922 run.bounds.pos.x -= d->outsideMargin;
923 }
924 run.visBounds = run.bounds;
925 const iInt2 maxSize = mulf_I2(imgSize, get_Window()->pixelRatio);
926 if (width_Rect(run.visBounds) > maxSize.x) {
927 /* Don't scale the image up. */
928 run.visBounds.size.y =
929 run.visBounds.size.y * maxSize.x / width_Rect(run.visBounds);
930 run.visBounds.size.x = maxSize.x;
931 run.visBounds.pos.x = run.bounds.size.x / 2 - width_Rect(run.visBounds) / 2;
932 run.bounds.size.y = run.visBounds.size.y;
933 }
934 run.text = iNullRange;
935 run.font = 0;
936 run.color = 0;
937 run.mediaType = image_GmRunMediaType;
938 run.mediaId = imageId;
939 pushBack_Array(&d->layout, &run);
940 pos.y += run.bounds.size.y + margin;
941 }
942 else if (audioId) {
943 iGmMediaInfo info;
944 audioInfo_Media(d->media, audioId, &info);
945 linkContentWasLaidOut_GmDocument_(d, &info, run.linkId); 921 linkContentWasLaidOut_GmDocument_(d, &info, run.linkId);
946 const int margin = lineHeight_Text(paragraph_FontId) / 2;
947 pos.y += margin;
948 run.bounds.pos = pos;
949 run.bounds.size.x = d->size.x;
950 run.bounds.size.y = lineHeight_Text(uiContent_FontId) + 3 * gap_UI;
951 run.visBounds = run.bounds;
952 run.text = iNullRange;
953 run.color = 0;
954 run.mediaType = audio_GmRunMediaType;
955 run.mediaId = audioId;
956 pushBack_Array(&d->layout, &run);
957 pos.y += run.bounds.size.y + margin;
958 } 922 }
959 else if (downloadId) { 923 switch (media.type) {
960 iGmMediaInfo info; 924 case image_MediaType: {
961 downloadInfo_Media(d->media, downloadId, &info); 925 const iInt2 imgSize = imageSize_Media(d->media, media);
962 linkContentWasLaidOut_GmDocument_(d, &info, run.linkId); 926 run.bounds.pos = pos;
963 const int margin = lineHeight_Text(paragraph_FontId) / 2; 927 run.bounds.size.x = d->size.x;
964 pos.y += margin; 928 const float aspect = (float) imgSize.y / (float) imgSize.x;
965 run.bounds.pos = pos; 929 run.bounds.size.y = d->size.x * aspect;
966 run.bounds.size.x = d->size.x; 930 /* Extend the image to full width, including outside margin, if the viewport
967 run.bounds.size.y = 2 * lineHeight_Text(uiContent_FontId) + 4 * gap_UI; 931 is narrow enough. */
968 run.visBounds = run.bounds; 932 if (isFullWidthImages) {
969 run.text = iNullRange; 933 run.bounds.size.x += d->outsideMargin * 2;
970 run.color = 0; 934 run.bounds.size.y += d->outsideMargin * 2 * aspect;
971 run.mediaType = download_GmRunMediaType; 935 run.bounds.pos.x -= d->outsideMargin;
972 run.mediaId = downloadId; 936 }
973 pushBack_Array(&d->layout, &run); 937 run.visBounds = run.bounds;
938 const iInt2 maxSize = mulf_I2(imgSize, get_Window()->pixelRatio);
939 if (width_Rect(run.visBounds) > maxSize.x) {
940 /* Don't scale the image up. */
941 run.visBounds.size.y =
942 run.visBounds.size.y * maxSize.x / width_Rect(run.visBounds);
943 run.visBounds.size.x = maxSize.x;
944 run.visBounds.pos.x = run.bounds.size.x / 2 - width_Rect(run.visBounds) / 2;
945 run.bounds.size.y = run.visBounds.size.y;
946 }
947 pushBack_Array(&d->layout, &run);
948 break;
949 }
950 case audio_MediaType: {
951 run.bounds.pos = pos;
952 run.bounds.size.x = d->size.x;
953 run.bounds.size.y = lineHeight_Text(uiContent_FontId) + 3 * gap_UI;
954 run.visBounds = run.bounds;
955 pushBack_Array(&d->layout, &run);
956 break;
957 }
958 case download_MediaType: {
959 run.bounds.pos = pos;
960 run.bounds.size.x = d->size.x;
961 run.bounds.size.y = 2 * lineHeight_Text(uiContent_FontId) + 4 * gap_UI;
962 run.visBounds = run.bounds;
963 pushBack_Array(&d->layout, &run);
964 break;
965 }
966 case fontpack_MediaType: {
967 run.bounds.pos = pos;
968 run.bounds.size.x = d->size.x;
969 run.bounds.size.y = height_FontpackUI(d->media, media.id, d->size.x);
970 run.visBounds = run.bounds;
971 pushBack_Array(&d->layout, &run);
972 break;
973 }
974 default:
975 break;
976 }
977 if (media.type && run.bounds.size.y) {
974 pos.y += run.bounds.size.y + margin; 978 pos.y += run.bounds.size.y + margin;
975 } 979 }
976 } 980 }
@@ -1057,21 +1061,6 @@ const iString *url_GmDocument(const iGmDocument *d) {
1057 return &d->url; 1061 return &d->url;
1058} 1062}
1059 1063
1060#if 0
1061void reset_GmDocument(iGmDocument *d) {
1062 clear_Media(d->media);
1063 clearLinks_GmDocument_(d);
1064 clear_Array(&d->layout);
1065 clear_Array(&d->headings);
1066 clear_Array(&d->preMeta);
1067 clear_String(&d->url);
1068 clear_String(&d->localHost);
1069 clear_String(&d->source);
1070 clear_String(&d->unormSource);
1071 d->themeSeed = 0;
1072}
1073#endif
1074
1075static void setDerivedThemeColors_(enum iGmDocumentTheme theme) { 1064static void setDerivedThemeColors_(enum iGmDocumentTheme theme) {
1076 set_Color(tmQuoteIcon_ColorId, 1065 set_Color(tmQuoteIcon_ColorId,
1077 mix_Color(get_Color(tmQuote_ColorId), get_Color(tmBackground_ColorId), 0.55f)); 1066 mix_Color(get_Color(tmQuote_ColorId), get_Color(tmBackground_ColorId), 0.55f));