Module: Idml::Render::StructureMapper

Defined in:
lib/idml/render/structure_mapper.rb

Overview

Maps IDML page-item classes to PDF structure types (PDF 1.7 §14.8.4). Each visible page item becomes one structure element when tagged output is enabled.

Mapping rationale:

TextFrame 

The PDF spec reserves lowercase for standard types; pdfrb's add_element(type:) accepts a Symbol which is serialised as /Type. We use Title-case Symbols to match the spec's typical spelling (P, Sect, Table, Figure, Path).

Class Method Summary collapse

Class Method Details

.alt_for(item) ⇒ Object

Optional Alt text for Figure elements. IDML doesn't have a dedicated alt-text attribute on <Image>, but the parent page item's Name (if present) is a useful fallback.



41
42
43
44
45
46
# File 'lib/idml/render/structure_mapper.rb', line 41

def self.alt_for(item)
  case item
  when Idml::Elements::Rectangle, Idml::Elements::Polygon
    image?(item) ? item.name : nil
  end
end

.type_for(item) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/idml/render/structure_mapper.rb', line 22

def self.type_for(item)
  case item
  when Idml::Elements::TextFrame then :P
  when Idml::Elements::Group then :Sect
  when Idml::Elements::Table then :Table
  when Idml::Elements::GraphicLine then :Path
  when Idml::Elements::Rectangle, Idml::Elements::Polygon
    shape_type(item)
  end
end