Class: BbEPUB::Transform::Rendition
- Inherits:
-
Bookbinder::Transform
- Object
- Bookbinder::Transform
- BbEPUB::Transform::Rendition
- Defined in:
- lib/bb-epub/transform/rendition.rb
Overview
For the original Apple extension to EPUB 2, see any version of the iBooks Asset Guide prior to version 5. Here’s a link to version 4.7:
http://www.mobileread.com/forums/attachment.php?attachmentid=74234
In particular, see the section titled “Configuring Display Options”
For the EPUB 3 Fixed Layout specification (actually a Mixed Layout specification), see:
http://www.idpf.org/epub/301/spec/epub-publications.html#sec-package-metadata-fxl
NOTE: a potential gotcha. The EPUB3 properties are ‘rendition:…’, with a colon, whereas the Openbook form follows the dash convention for property names, ie ‘rendition-…’.
Constant Summary collapse
- RENDITION_DEFAULT_PROPERTIES =
{ 'rendition:flow' => 'paginated', 'rendition:layout' => 'reflowable', 'rendition:spread' => 'auto', 'rendition:orientation' => 'auto', 'rendition:viewport' => nil }
- APPLE_FXL_PATH =
'META-INF/com.apple.ibooks.display-options.xml'
Instance Method Summary collapse
Instance Method Details
#dependencies ⇒ Object
29 30 31 |
# File 'lib/bb-epub/transform/rendition.rb', line 29 def dependencies [BbEPUB::Transform::Spine, BbEPUB::Transform::Metadata] end |
#from_map(package) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/bb-epub/transform/rendition.rb', line 42 def from_map(package) first_cmpt = package.map['spine'][0] book_properties = { 'rendition:flow' => first_cmpt['rendition-flow'], 'rendition:layout' => first_cmpt['rendition-layout'], 'rendition:spread' => first_cmpt['rendition-spread'], 'rendition:orientation' => first_cmpt['rendition-orientation'], 'rendition:viewport' => first_cmpt['rendition-viewport'] } opf_doc = package.file(:opf).document opf_doc.add_prefix('rendition') book_properties.each_pair { |prop, content| if content && RENDITION_DEFAULT_PROPERTIES[prop] != content (opf_doc, prop, content) end } opf_doc.each('opf|spine > opf|itemref') { |itemref| # Update the itemref properties attribute. cmpt = component_for_itemref(package, itemref) props = (itemref['properties'] || '').split book_properties.each_pair { |prop, book_content| key = prop.gsub(':', '-') if cmpt[key] != book_content cmpt_content = cmpt[key] || RENDITION_DEFAULT_PROPERTIES[prop] props.push("#{prop}-#{cmpt_content}") end } if ['left', 'right'].include?(cmpt['rendition-position']) props.push('page-spread-'+cmpt['rendition-position']) elsif cmpt['rendition-position'] == 'center' props.push('rendition:page-spread-center') end if cmpt['rendition-align-x-center'] props.push('rendition:align-x-center') end itemref['properties'] = props.join(' ') if props.any? # Update the viewport/viewBox attribute in the component file. add_icb_to_component( package.file(cmpt['path']), cmpt['rendition-viewport'] ) if cmpt['rendition-viewport'] } end |
#to_map(package) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/bb-epub/transform/rendition.rb', line 34 def to_map(package) package.map['rendition-format'] = 'ebook' book_properties = (package) book_properties.update(book_properties_from_opf(package)) component_rendition_properties_from_opf(package, book_properties) end |