-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,41 @@ ReadiumSDK.Helpers.Rect.fromElement = function($element) { | |
return new ReadiumSDK.Helpers.Rect(offsetLeft, offsetTop, offsetWidth, offsetHeight); | ||
}; | ||
|
||
ReadiumSDK.Helpers.UpdateHtmlFontSize = function($epubHtml, fontSize){ | ||
var factor = fontSize/100; | ||
var win = $epubHtml[0].ownerDocument.defaultView; | ||
var $textblocks = $('p, div, span', $epubHtml); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ryanackley
Author
Contributor
|
||
|
||
|
||
// need to do two passes because it is possible to have nested text blocks. | ||
// If you change the font size of the parent this will then create an inaccurate | ||
// font size for any children. | ||
for (var i = 0; i < $textblocks.length; i++){ | ||
var ele = $textblocks[i], | ||
fontSizeAttr = ele.getAttribute('data-original-font-size'); | ||
|
||
if (!fontSizeAttr){ | ||
var style = win.getComputedStyle(ele); | ||
var originalFontSize = parseInt(style.fontSize); | ||
var originalLineHeight = parseInt(style.lineHeight); | ||
This comment has been minimized.
Sorry, something went wrong.
danielweck
Member
|
||
ele.setAttribute('data-original-font-size', originalFontSize); | ||
ele.setAttribute('data-original-line-height', originalLineHeight) | ||
} | ||
} | ||
|
||
for (var i = 0; i < $textblocks.length; i++){ | ||
var ele = $textblocks[i], | ||
fontSizeAttr = ele.getAttribute('data-original-font-size'), | ||
lineHeightAttr = ele.getAttribute('data-original-line-height'), | ||
originalFontSize = Number(fontSizeAttr), | ||
originalLineHeight = Number(lineHeightAttr); | ||
|
||
ele.style.fontSize = (originalFontSize * factor) + 'px'; | ||
ele.style.lineHeight = (originalLineHeight * factor) + 'px'; | ||
|
||
} | ||
} | ||
|
||
|
||
/** | ||
* @return {string} | ||
|
I was testing "accessible epub3" from Readium's bundled EPUB samples, unfortunately the text of HTML headings is not resizing because the "h" markup does not have "p, div, span" descendants or ancestors. Same problem with list items ("li") in other test books. I guess there are potentially many more use-cases, due to the great variety of HTML5 elements that do not necessarily have "p, div, span" descendants or ancestors.
Perhaps we should add to the "$textblock" list the most commonly-expected elements (headings, list items, blockquote, etc.), and add the font-size="percent%" to the HTML/BODY root (just as before). This way, the font-size="pixel value" remains forced on the descendants scanned here, and the other elements have a chance to adjust too (unless of course the original authored value is fixed pixel unit, but that would be a known caveat). Alternatively, the "$textblock" list could contain all possible element names (* wildcard)...not that I am recommending this though! :(