summaryrefslogtreecommitdiff
path: root/src/ui/documentwidget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-10-17 20:33:14 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-10-17 20:33:14 +0300
commitb3ae7efcb9adb1de3d02f0753e2a79888bdb71ac (patch)
tree57fb9f82f2d19a1c8e6d1aa85865f9df210e2c4b /src/ui/documentwidget.c
parent2e2b823bfb5d34d42c6b6c1b289193c854459b45 (diff)
FontPack management via "about:fonts"
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r--src/ui/documentwidget.c75
1 files changed, 30 insertions, 45 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 1aca895c..a1992967 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -1257,7 +1257,7 @@ static const char *zipPageHeading_(const iRangecc mime) {
1257 return book_Icon " Gempub"; 1257 return book_Icon " Gempub";
1258 } 1258 }
1259 else if (equalCase_Rangecc(mime, mimeType_FontPack)) { 1259 else if (equalCase_Rangecc(mime, mimeType_FontPack)) {
1260 return "\U0001f520 Fontpack"; 1260 return fontpack_Icon " Fontpack";
1261 } 1261 }
1262 iRangecc type = iNullRange; 1262 iRangecc type = iNullRange;
1263 nextSplit_Rangecc(mime, "/", &type); /* skip the part before the slash */ 1263 nextSplit_Rangecc(mime, "/", &type); /* skip the part before the slash */
@@ -1435,13 +1435,6 @@ static void postProcessRequestContent_DocumentWidget_(iDocumentWidget *d, iBool
1435 } 1435 }
1436 } 1436 }
1437 } 1437 }
1438 /* Local fontpacks are automatically shown. */
1439 if (preloadLocalFontpackForPreview_Fonts(d->doc)) {
1440 documentRunsInvalidated_DocumentWidget_(d);
1441 redoLayout_GmDocument(d->doc);
1442 updateVisible_DocumentWidget_(d);
1443 invalidate_DocumentWidget_(d);
1444 }
1445} 1438}
1446 1439
1447static void updateDocument_DocumentWidget_(iDocumentWidget *d, 1440static void updateDocument_DocumentWidget_(iDocumentWidget *d,
@@ -1503,6 +1496,25 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d,
1503 appendFormat_String(&str, 1496 appendFormat_String(&str,
1504 cstr_Lang("doc.archive"), 1497 cstr_Lang("doc.archive"),
1505 cstr_Rangecc(baseName_Path(d->mod.url))); 1498 cstr_Rangecc(baseName_Path(d->mod.url)));
1499 if (isRequestFinished) {
1500 if (equal_Rangecc(param, mimeType_FontPack)) {
1501 /* Show some information about fontpacks, and set up footer actions. */
1502 iArchive *zip = iClob(new_Archive());
1503 if (openData_Archive(zip, &d->sourceContent)) {
1504 iFontPack *fp = new_FontPack();
1505 setUrl_FontPack(fp, d->mod.url);
1506 setStandalone_FontPack(fp, iTrue);
1507 if (loadArchive_FontPack(fp, zip)) {
1508 appendFormat_String(&str, "\n\n%s",
1509 cstrCollect_String(infoText_FontPack(fp)));
1510 }
1511 const iArray *actions = actions_FontPack(fp);
1512 makeFooterButtons_DocumentWidget_(d, constData_Array(actions),
1513 size_Array(actions));
1514 delete_FontPack(fp);
1515 }
1516 }
1517 }
1506 appendCStr_String(&str, "\n\n"); 1518 appendCStr_String(&str, "\n\n");
1507 iString *localPath = localFilePathFromUrl_String(d->mod.url); 1519 iString *localPath = localFilePathFromUrl_String(d->mod.url);
1508 if (!localPath) { 1520 if (!localPath) {
@@ -2916,27 +2928,6 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
2916 updateMedia_DocumentWidget_(d); 2928 updateMedia_DocumentWidget_(d);
2917 return iFalse; 2929 return iFalse;
2918 } 2930 }
2919 else if (equal_Command(cmd, "media.fontpack.updated")) {
2920 iMedia *media = pointerLabel_Command(cmd, "media");
2921 if (media == media_GmDocument(d->doc)) {
2922 /*iGmMediaInfo info;
2923 if (info_Media(media,
2924 (iMediaId){ fontpack_MediaType, argU32Label_Command(cmd, "id")},
2925 &info)) {
2926
2927 }*/
2928
2929// findCachedContent_App(<#const iString *url#>, <#iString *mime_out#>, <#iBlock *data_out#>)
2930// setData_Media(media,
2931 }
2932 return iFalse;
2933 }
2934 else if (equal_Command(cmd, "media.fontpack.install")) {
2935 if (pointerLabel_Command(cmd, "media") == media_GmDocument(d->doc)) {
2936 /* TODO: This is ours, we may have a MediaRequest with the data in memory. */
2937 }
2938 return iFalse;
2939 }
2940 else if (equal_Command(cmd, "document.stop") && document_App() == d) { 2931 else if (equal_Command(cmd, "document.stop") && document_App() == d) {
2941 if (cancelRequest_DocumentWidget_(d, iTrue /* navigate back */)) { 2932 if (cancelRequest_DocumentWidget_(d, iTrue /* navigate back */)) {
2942 return iTrue; 2933 return iTrue;
@@ -3253,7 +3244,16 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
3253 return handleSwipe_DocumentWidget_(d, cmd); 3244 return handleSwipe_DocumentWidget_(d, cmd);
3254 } 3245 }
3255 else if (equal_Command(cmd, "document.setmediatype") && document_App() == d) { 3246 else if (equal_Command(cmd, "document.setmediatype") && document_App() == d) {
3256 setUrlAndSource_DocumentWidget(d, d->mod.url, string_Command(cmd, "mime"), &d->sourceContent); 3247 if (!isRequestOngoing_DocumentWidget(d)) {
3248 setUrlAndSource_DocumentWidget(d, d->mod.url, string_Command(cmd, "mime"),
3249 &d->sourceContent);
3250 }
3251 return iTrue;
3252 }
3253 else if (equalWidget_Command(cmd, w, "fontpack.install")) {
3254 const iString *id = idFromUrl_FontPack(d->mod.url);
3255 install_Fonts(id, &d->sourceContent);
3256 postCommandf_App("open gotoheading:%s url:about:fonts", cstr_String(id));
3257 return iTrue; 3257 return iTrue;
3258 } 3258 }
3259 return iFalse; 3259 return iFalse;
@@ -3302,15 +3302,6 @@ static iBool processMediaEvents_DocumentWidget_(iDocumentWidget *d, const SDL_Ev
3302 const iInt2 mouse = init_I2(ev->button.x, ev->button.y); 3302 const iInt2 mouse = init_I2(ev->button.x, ev->button.y);
3303 iConstForEach(PtrArray, i, &d->visibleMedia) { 3303 iConstForEach(PtrArray, i, &d->visibleMedia) {
3304 const iGmRun *run = i.ptr; 3304 const iGmRun *run = i.ptr;
3305 if (run->mediaType == fontpack_MediaType) {
3306 iFontpackUI ui;
3307 init_FontpackUI(&ui, media_GmDocument(d->doc), run->mediaId,
3308 runRect_DocumentWidget_(d, run));
3309 if (processEvent_FontpackUI(&ui, ev)) {
3310 refresh_Widget(d);
3311 return iTrue;
3312 }
3313 }
3314 if (run->mediaType != audio_MediaType) { 3305 if (run->mediaType != audio_MediaType) {
3315 continue; 3306 continue;
3316 } 3307 }
@@ -4685,12 +4676,6 @@ static void drawMedia_DocumentWidget_(const iDocumentWidget *d, iPaint *p) {
4685 runRect_DocumentWidget_(d, run)); 4676 runRect_DocumentWidget_(d, run));
4686 draw_DownloadUI(&ui, p); 4677 draw_DownloadUI(&ui, p);
4687 } 4678 }
4688 else if (run->mediaType == fontpack_MediaType) {
4689 iFontpackUI ui;
4690 init_FontpackUI(&ui, constMedia_GmDocument(d->doc), run->mediaId,
4691 runRect_DocumentWidget_(d, run));
4692 draw_FontpackUI(&ui, p);
4693 }
4694 } 4679 }
4695} 4680}
4696 4681