Add ebook font to preferences

Choose from a list of preset font stacks, or any font on your system.
This commit is contained in:
Abe Jellinek 2023-05-19 16:19:43 +03:00 committed by Dan Stillman
parent 378277206a
commit f5381403c0
5 changed files with 98 additions and 31 deletions

View file

@ -54,6 +54,7 @@ Zotero_Preferences.General = {
this.refreshLocale();
this.updateAutoRenameFilesUI();
this._updateFileHandlerUI();
this._initEbookFontFamilyMenu();
},
_getAutomaticLocaleMenuLabel: function () {
@ -364,5 +365,54 @@ Zotero_Preferences.General = {
setTimeout(() => {
this.updateOpenURLResolversMenu();
});
}
},
EBOOK_FONT_STACKS: {
Baskerville: 'Baskerville, serif',
Charter: 'Charter, serif',
Futura: 'Futura, sans-serif',
Georgia: 'Georgia, serif',
// Helvetica and equivalent-ish
Helvetica: 'Helvetica, Arial, Open Sans, Liberation Sans, sans-serif',
Iowan: 'Iowan, serif',
'New York': 'New York, serif',
OpenDyslexic: 'OpenDyslexic, eulexia, serif',
// Windows has called Palatino by many names
Palatino: 'Palatino, Palatino Linotype, Adobe Palatino, Book Antiqua, URW Palladio L, FPL Neu, Domitian, serif',
// Times New Roman and equivalent-ish
'Times New Roman': 'Times New Roman, Linux Libertine, Liberation Serif, serif',
},
async _initEbookFontFamilyMenu() {
let enumerator = Cc["@mozilla.org/gfx/fontenumerator;1"].createInstance(Ci.nsIFontEnumerator);
let fonts = new Set(await enumerator.EnumerateAllFontsAsync());
let menulist = document.getElementById('reader-ebook-font-family');
let popup = menulist.menupopup;
for (let [label, stack] of Object.entries(this.EBOOK_FONT_STACKS)) {
// If no font in the stack exists on the user's system, don't add it to the list
// Exclude the generic family name at the end, which is only there in case no font specified by name in the
// stack supports a specific character (e.g. non-Latin)
if (!stack.split(', ').slice(0, -1).some(font => fonts.has(font))) {
continue;
}
let menuitem = document.createXULElement('menuitem');
menuitem.label = label;
menuitem.value = stack;
menuitem.style.fontFamily = stack;
popup.append(menuitem);
}
if (popup.childElementCount && fonts.size) {
popup.append(document.createXULElement('menuseparator'));
}
for (let font of fonts) {
let menuitem = document.createXULElement('menuitem');
menuitem.label = font;
menuitem.value = font;
menuitem.style.fontFamily = `'${font.replace(/'/g, "\\'")}'`;
popup.append(menuitem);
}
},
}

View file

@ -139,33 +139,40 @@
<label value="&zotero.preferences.trashAutoEmptyDaysPost;"/>
</hbox>
</groupbox>
<groupbox id="zotero-prefpane-reader-groupbox">
<label><html:h2>&zotero.preferences.pdfReader;</html:h2></label>
<hbox align="center">
<label value="&zotero.preferences.reader.tabsTitle.label;" control="reader-tabs-title"/>
<menulist id="reader-tabs-title" preference="extensions.zotero.tabs.title.reader" native="true">
<menupopup>
<menuitem label="&zotero.preferences.reader.tabsTitle.titleCreatorYear;" value="titleCreatorYear"/>
<menuitem label="&zotero.preferences.reader.tabsTitle.creatorYearTitle;" value="creatorYearTitle"/>
<menuitem label="&zotero.preferences.reader.tabsTitle.filename;" value="filename"/>
</menupopup>
</menulist>
</hbox>
</groupbox>
<groupbox>
<label><html:h2>&zotero.preferences.groups;</html:h2></label>
<label value="&zotero.preferences.groups.whenCopyingInclude;"/>
<vbox style="margin-left: 2em">
<checkbox label="&zotero.preferences.groups.childNotes;" preference="extensions.zotero.groups.copyChildNotes" native="true"/>
<checkbox label="&zotero.preferences.groups.childFiles;" preference="extensions.zotero.groups.copyChildFileAttachments" native="true"/>
<checkbox label="&zotero.preferences.groups.annotations;" preference="extensions.zotero.groups.copyAnnotations" native="true"/>
<checkbox label="&zotero.preferences.groups.childLinks;" preference="extensions.zotero.groups.copyChildLinks" native="true"/>
<checkbox label="&zotero.preferences.groups.tags;" preference="extensions.zotero.groups.copyTags" native="true"/>
</vbox>
</groupbox>
</vbox>
<groupbox id="zotero-prefpane-reader-groupbox">
<label><html:h2>&zotero.preferences.reader;</html:h2></label>
<hbox align="center">
<label value="&zotero.preferences.reader.tabsTitle.label;" control="reader-tabs-title"/>
<menulist id="reader-tabs-title" preference="extensions.zotero.tabs.title.reader" native="true">
<menupopup>
<menuitem label="&zotero.preferences.reader.tabsTitle.titleCreatorYear;" value="titleCreatorYear"/>
<menuitem label="&zotero.preferences.reader.tabsTitle.creatorYearTitle;" value="creatorYearTitle"/>
<menuitem label="&zotero.preferences.reader.tabsTitle.filename;" value="filename"/>
</menupopup>
</menulist>
</hbox>
<hbox align="center">
<label value="&zotero.preferences.reader.ebookFontFamily;" control="reader-ebook-font-family"/>
<menulist id="reader-ebook-font-family" preference="extensions.zotero.reader.ebookFontFamily" native="true">
<menupopup/>
</menulist>
</hbox>
</groupbox>
<groupbox>
<label><html:h2>&zotero.preferences.groups;</html:h2></label>
<label value="&zotero.preferences.groups.whenCopyingInclude;"/>
<vbox style="margin-left: 2em">
<checkbox label="&zotero.preferences.groups.childNotes;" preference="extensions.zotero.groups.copyChildNotes" native="true"/>
<checkbox label="&zotero.preferences.groups.childFiles;" preference="extensions.zotero.groups.copyChildFileAttachments" native="true"/>
<checkbox label="&zotero.preferences.groups.annotations;" preference="extensions.zotero.groups.copyAnnotations" native="true"/>
<checkbox label="&zotero.preferences.groups.childLinks;" preference="extensions.zotero.groups.copyChildLinks" native="true"/>
<checkbox label="&zotero.preferences.groups.tags;" preference="extensions.zotero.groups.copyTags" native="true"/>
</vbox>
</groupbox>
</vbox>

View file

@ -181,6 +181,7 @@ class ReaderInstance {
...Zotero.Intl.getPrefixedStrings('pdfReader.')
},
showAnnotations: true,
fontFamily: Zotero.Prefs.get('reader.ebookFontFamily'),
onOpenContextMenu: () => {
// Functions can only be passed over wrappedJSObject (we call back onClick for context menu items)
this._openContextMenu(this._iframeWindow.wrappedJSObject.contextMenuParams);
@ -472,7 +473,8 @@ class ReaderInstance {
this._prefObserverIDs = [
Zotero.Prefs.registerObserver('fontSize', this._handleFontSizeChange),
Zotero.Prefs.registerObserver('tabs.title.reader', this._handleTabTitlePrefChange)
Zotero.Prefs.registerObserver('tabs.title.reader', this._handleTabTitlePrefChange),
Zotero.Prefs.registerObserver('reader.ebookFontFamily', this._handleFontFamilyChange),
];
return true;
@ -703,6 +705,10 @@ class ReaderInstance {
this._internalReader.setFontSize(Zotero.Prefs.get('fontSize'));
};
_handleFontFamilyChange = () => {
this._internalReader.setFontFamily(Zotero.Prefs.get('reader.ebookFontFamily'));
};
_dataURLtoBlob(dataurl) {
let parts = dataurl.split(',');
let mime = parts[0].match(/:(.*?);/)[1];

View file

@ -29,11 +29,12 @@
<!ENTITY zotero.preferences.trashAutoEmptyDaysPre "Automatically remove items in the trash deleted more than">
<!ENTITY zotero.preferences.trashAutoEmptyDaysPost "days ago">
<!ENTITY zotero.preferences.pdfReader "PDF Reader">
<!ENTITY zotero.preferences.reader "PDFs, Ebooks, and Snapshots">
<!ENTITY zotero.preferences.reader.tabsTitle.label "Show tabs as">
<!ENTITY zotero.preferences.reader.tabsTitle.creatorYearTitle "Creator - Year - Title">
<!ENTITY zotero.preferences.reader.tabsTitle.titleCreatorYear "Title - Creator - Year">
<!ENTITY zotero.preferences.reader.tabsTitle.filename "Filename">
<!ENTITY zotero.preferences.reader.ebookFontFamily "Ebook font:">
<!ENTITY zotero.preferences.groups "Groups">
<!ENTITY zotero.preferences.groups.whenCopyingInclude "When copying items between libraries, include:">

View file

@ -212,3 +212,6 @@ pref("extensions.zotero.scaffold.eslint.enabled", true);
// Tabs
pref("extensions.zotero.tabs.title.reader", "titleCreatorYear");
// Reader
pref("extensions.zotero.reader.ebookFontFamily", "Georgia, serif");