summaryrefslogtreecommitdiff
path: root/src/ui/documentwidget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-10-20 07:57:30 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-10-20 07:57:30 +0300
commit57cbcc6e864abd368bde93154b3580147936201c (patch)
tree157ecbb534f85d83ef39dcb68850e42d7cce6580 /src/ui/documentwidget.c
parent5b8c606183df3054c4691f89c97e346786947914 (diff)
Installing individual TTF files; generate fontpack.ini
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r--src/ui/documentwidget.c82
1 files changed, 67 insertions, 15 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 1039fc2b..48ce5b5f 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -1130,7 +1130,8 @@ static void makeFooterButtons_DocumentWidget_(iDocumentWidget *d, const iMenuIte
1130 d->footerButtons, 1130 d->footerButtons,
1131 iClob(newKeyMods_LabelWidget( 1131 iClob(newKeyMods_LabelWidget(
1132 items[i].label, items[i].key, items[i].kmods, items[i].command)), 1132 items[i].label, items[i].key, items[i].kmods, items[i].command)),
1133 alignLeft_WidgetFlag | drawKey_WidgetFlag); 1133 alignLeft_WidgetFlag | drawKey_WidgetFlag | extraPadding_WidgetFlag);
1134 setPadding1_Widget(as_Widget(button), gap_UI / 2);
1134 checkIcon_LabelWidget(button); 1135 checkIcon_LabelWidget(button);
1135 setFont_LabelWidget(button, uiContent_FontId); 1136 setFont_LabelWidget(button, uiContent_FontId);
1136 } 1137 }
@@ -1473,7 +1474,7 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d,
1473 trim_Rangecc(&param); 1474 trim_Rangecc(&param);
1474 /* Detect fontpacks even if the server doesn't use the right media type. */ 1475 /* Detect fontpacks even if the server doesn't use the right media type. */
1475 if (isRequestFinished && equal_Rangecc(param, "application/octet-stream")) { 1476 if (isRequestFinished && equal_Rangecc(param, "application/octet-stream")) {
1476 if (detect_FontPack(&d->sourceContent)) { 1477 if (detect_FontPack(&response->body)) {
1477 param = range_CStr(mimeType_FontPack); 1478 param = range_CStr(mimeType_FontPack);
1478 } 1479 }
1479 } 1480 }
@@ -1492,6 +1493,42 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d,
1492 docFormat = plainText_SourceFormat; 1493 docFormat = plainText_SourceFormat;
1493 setRange_String(&d->sourceMime, param); 1494 setRange_String(&d->sourceMime, param);
1494 } 1495 }
1496 else if (isRequestFinished && equal_Rangecc(param, "font/ttf")) {
1497 clear_String(&str);
1498 docFormat = gemini_SourceFormat;
1499 setRange_String(&d->sourceMime, param);
1500 format_String(&str, "# TrueType Font\n");
1501 iString *decUrl = collect_String(urlDecode_String(d->mod.url));
1502 iRangecc name = baseName_Path(decUrl);
1503 iBool isInstalled = iFalse;
1504 if (startsWith_String(collect_String(localFilePathFromUrl_String(d->mod.url)),
1505 cstr_String(dataDir_App()))) {
1506 isInstalled = iTrue;
1507 }
1508 appendCStr_String(&str, "## ");
1509 appendRange_String(&str, name);
1510 appendCStr_String(&str, "\n\n");
1511 appendCStr_String(
1512 &str, cstr_Lang(isInstalled ? "truetype.help.installed" : "truetype.help"));
1513 appendCStr_String(&str, "\n");
1514 if (!isInstalled) {
1515 makeFooterButtons_DocumentWidget_(
1516 d,
1517 (iMenuItem[]){
1518 { add_Icon " ${fontpack.install.ttf}",
1519 SDLK_RETURN,
1520 0,
1521 format_CStr("!fontpack.install ttf:1 name:%s",
1522 cstr_Rangecc(name)) },
1523 { folder_Icon " ${fontpack.open.fontsdir}",
1524 SDLK_d,
1525 0,
1526 format_CStr("!open url:%s/fonts",
1527 cstrCollect_String(makeFileUrl_String(dataDir_App())))
1528 }
1529 }, 2);
1530 }
1531 }
1495 else if (isRequestFinished && 1532 else if (isRequestFinished &&
1496 (equal_Rangecc(param, "application/zip") || 1533 (equal_Rangecc(param, "application/zip") ||
1497 (startsWith_Rangecc(param, "application/") && 1534 (startsWith_Rangecc(param, "application/") &&
@@ -1499,32 +1536,39 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d,
1499 clear_String(&str); 1536 clear_String(&str);
1500 docFormat = gemini_SourceFormat; 1537 docFormat = gemini_SourceFormat;
1501 setRange_String(&d->sourceMime, param); 1538 setRange_String(&d->sourceMime, param);
1502 iString *key = collectNew_String();
1503 toString_Sym(SDLK_s, KMOD_PRIMARY, key);
1504 format_String(&str, "# %s\n", zipPageHeading_(param)); 1539 format_String(&str, "# %s\n", zipPageHeading_(param));
1505 appendFormat_String(&str,
1506 cstr_Lang("doc.archive"),
1507 cstr_Rangecc(baseName_Path(d->mod.url)));
1508 if (equal_Rangecc(param, mimeType_FontPack)) { 1540 if (equal_Rangecc(param, mimeType_FontPack)) {
1509 /* Show some information about fontpacks, and set up footer actions. */ 1541 /* Show some information about fontpacks, and set up footer actions. */
1510 iArchive *zip = iClob(new_Archive()); 1542 iArchive *zip = iClob(new_Archive());
1511 if (openData_Archive(zip, &d->sourceContent)) { 1543 if (openData_Archive(zip, &response->body)) {
1512 iFontPack *fp = new_FontPack(); 1544 iFontPack *fp = new_FontPack();
1513 setUrl_FontPack(fp, d->mod.url); 1545 setUrl_FontPack(fp, d->mod.url);
1514 setStandalone_FontPack(fp, iTrue); 1546 setStandalone_FontPack(fp, iTrue);
1515 if (loadArchive_FontPack(fp, zip)) { 1547 if (loadArchive_FontPack(fp, zip)) {
1516 appendFormat_String(&str, "\n\n%s", 1548 appendFormat_String(&str, "## %s\n%s",
1549 cstr_String(id_FontPack(fp).id),
1517 cstrCollect_String(infoText_FontPack(fp))); 1550 cstrCollect_String(infoText_FontPack(fp)));
1518 } 1551 }
1519 const iArray *actions = actions_FontPack(fp); 1552 appendCStr_String(&str, "\n");
1553 appendCStr_String(&str, cstr_Lang("fontpack.help"));
1554 appendCStr_String(&str, "\n");
1555 const iArray *actions = actions_FontPack(fp, iTrue);
1520 makeFooterButtons_DocumentWidget_(d, constData_Array(actions), 1556 makeFooterButtons_DocumentWidget_(d, constData_Array(actions),
1521 size_Array(actions)); 1557 size_Array(actions));
1522 delete_FontPack(fp); 1558 delete_FontPack(fp);
1523 } 1559 }
1524 } 1560 }
1525 appendCStr_String(&str, "\n\n"); 1561 else {
1562 appendFormat_String(&str,
1563 cstr_Lang("doc.archive"),
1564 cstr_Rangecc(baseName_Path(d->mod.url)));
1565 appendCStr_String(&str, "\n");
1566 }
1567 appendCStr_String(&str, "\n");
1526 iString *localPath = localFilePathFromUrl_String(d->mod.url); 1568 iString *localPath = localFilePathFromUrl_String(d->mod.url);
1527 if (!localPath) { 1569 if (!localPath) {
1570 iString *key = collectNew_String();
1571 toString_Sym(SDLK_s, KMOD_PRIMARY, key);
1528 appendFormat_String(&str, "%s\n\n", 1572 appendFormat_String(&str, "%s\n\n",
1529 format_CStr(cstr_Lang("error.unsupported.suggestsave"), 1573 format_CStr(cstr_Lang("error.unsupported.suggestsave"),
1530 cstr_String(key), 1574 cstr_String(key),
@@ -3267,10 +3311,17 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
3267 } 3311 }
3268 return iTrue; 3312 return iTrue;
3269 } 3313 }
3270 else if (equalWidget_Command(cmd, w, "fontpack.install")) { 3314 else if (equal_Command(cmd, "fontpack.install") && document_App() == d) {
3271 const iString *id = idFromUrl_FontPack(d->mod.url); 3315 if (argLabel_Command(cmd, "ttf")) {
3272 install_Fonts(id, &d->sourceContent); 3316 iAssert(!cmp_String(&d->sourceMime, "font/ttf"));
3273 postCommandf_App("open gotoheading:%s url:about:fonts", cstr_String(id)); 3317 installFontFile_Fonts(collect_String(suffix_Command(cmd, "name")), &d->sourceContent);
3318 postCommand_App("open url:about:fonts");
3319 }
3320 else {
3321 const iString *id = idFromUrl_FontPack(d->mod.url);
3322 install_Fonts(id, &d->sourceContent);
3323 postCommandf_App("open gotoheading:%s url:about:fonts", cstr_String(id));
3324 }
3274 return iTrue; 3325 return iTrue;
3275 } 3326 }
3276 return iFalse; 3327 return iFalse;
@@ -5199,6 +5250,7 @@ void updateSize_DocumentWidget(iDocumentWidget *d) {
5199 d->drawBufs->flags |= updateSideBuf_DrawBufsFlag; 5250 d->drawBufs->flags |= updateSideBuf_DrawBufsFlag;
5200 updateVisible_DocumentWidget_(d); 5251 updateVisible_DocumentWidget_(d);
5201 invalidate_DocumentWidget_(d); 5252 invalidate_DocumentWidget_(d);
5253 arrange_Widget(d->footerButtons);
5202} 5254}
5203 5255
5204#if 0 5256#if 0