You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the reader's settings, the fontSelection index is zero-based and indicates the chosen item from an array of choices (zero means "default publisher font", other integers mean "custom reading system font"):
Note that although the url field of each JSON font object can be a relative path, in fact the getFontFaces() function at the bottom of the Javascript source file takes a URLprefix parameter to complete the final array of fonts with absolute URLs. In other words, a native app must ensure that each font's HTTP URL resolves to the correct payload, which is typically a CSS file that declares the font faces, for example OpenDyslexic:
The fontFamily string of characters in the JSON font object is meant to be used as-is in a CSS font-family statement, and will be applied automatically by the readium-shared-js layout / rendering engine when a the fontSelection setting changes:
* @param $epubHtml: The html that is to have font attributes added.
* @param fontSize: The font size that is to be added to the element at all locations.
* @param fontObj: The font Object containing at minimum the URL, and fontFamilyName (In fields url and fontFamily) respectively. Pass in null's on the object's fields to signal no font.
* @param callback: function invoked when "done", which means that if there are asynchronous operations such as font-face loading via injected stylesheets, then the UpdateHtmlFontAttributes() function returns immediately but the caller should wait for the callback function call if fully-loaded font-face *stylesheets* are required on the caller's side (note that the caller's side may still need to detect *actual font loading*, via the FontLoader API or some sort of ResizeSensor to indicate that the updated font-family has been used to render the document).
style.appendChild($epubHtml[0].ownerDocument.createTextNode('html * { font-family: "'+fontObj.fontFamily+'" !important; }'));// this technique works for text-align too (e.g. text-align: justify !important;)
docHead[0].appendChild(style);
//fontFamilyStyle = $(style);
}
}
// The code below does not work because jQuery $element.css() on html.body somehow "resets" the font: CSS directive by removing it entirely (font-family: works with !important, but unfortunately further deep inside the DOM there may be CSS applied with the font: directive, which somehow seems to take precedence! ... as shown in Chrome's developer tools)
// ...thus why we use the above routine instead, to insert a new head>style element
// Note that font-family is handled differently, using an injected stylesheet with a catch-all selector that pushes an "!important" CSS value in the document's cascade.
In the reader's settings, the
fontSelection
index is zero-based and indicates the chosen item from an array of choices (zero means "default publisher font", other integers mean "custom reading system font"):readium-shared-js/js/models/viewer_settings.js
Lines 44 to 50 in 9bb1df0
The reader's array of custom fonts is provided at construction time:
readium-shared-js/js/views/reader_view.js
Line 77 in 9bb1df0
Here is a concrete example of such array, as configured in ReadiumJS (cloud / web reader + Chrome app / extension):
https://github.com/readium/readium-js-viewer/blob/2a41a144ad75cb33058c0684a817aa2fe332f907/src/fonts/fonts.js#L1-L42
Note that although the
url
field of each JSON font object can be a relative path, in fact thegetFontFaces()
function at the bottom of the Javascript source file takes aURLprefix
parameter to complete the final array of fonts with absolute URLs. In other words, a native app must ensure that each font's HTTP URL resolves to the correct payload, which is typically a CSS file that declares the font faces, for example OpenDyslexic:https://github.com/readium/readium-js-viewer/tree/2a41a144ad75cb33058c0684a817aa2fe332f907/src/fonts/OpenDyslexic
The
fontFamily
string of characters in the JSON font object is meant to be used as-is in a CSSfont-family
statement, and will be applied automatically by thereadium-shared-js
layout / rendering engine when a thefontSelection
setting changes:readium-shared-js/js/views/reader_view.js
Lines 582 to 646 in 9bb1df0
The actual DOM/CSS logic is implemented in:
readium-shared-js/js/helpers.js
Lines 248 to 457 in 9bb1df0
The text was updated successfully, but these errors were encountered: