Module: Pdfrb::Conformance::StructureElements
- Defined in:
- lib/pdfrb/conformance/structure_elements.rb
Overview
Per-structure-element validation rules derived from the PDF Association's "Tagged PDF Best Practice Guide: Syntax" (BPG).
Each standard structure type has expected children and attributes. This module provides a registry of structure-type validators (OCP: add a validator = register, no switch edits).
Constant Summary collapse
- TABLE_CHILDREN =
Standard PDF structure types (ISO 32000-2 §14.8.4).
%i[TR THead TBody TFoot].freeze
- STANDARD_TYPES =
%i[ Document Part Art Sect Div BlockQuote Caption TOC TOCI Index NonStruct Private H H1 H2 H3 H4 H5 H6 P L LI Lbl LBody Table TR TH TD THead TBody TFoot Span Quote Note Reference BibEntry Code Figure Formula Form Ruby RB RT RP Warichu WT WP Annot ].freeze
- EXPECTED_CHILDREN =
Map of structure type → expected child types (nil = any).
{ L: [:LI], LI: [:Lbl, :LBody], Table: [:THead, :TBody, :TFoot, :TR], TR: [:TH, :TD], Ruby: [:RB, :RT, :RP], Warichu: [:WT, :WP], TOC: [:TOCI], }.freeze
- REQUIRED_ATTRIBUTES =
Map of structure type → required attributes (besides /S).
{ Figure: [:Alt, :ActualText], # at least one required Formula: [:Alt, :ActualText], # at least one required }.freeze
Class Method Summary collapse
- .expected_children(type) ⇒ Object
- .required_attributes(type) ⇒ Object
- .standard?(type) ⇒ Boolean
- .standard_types ⇒ Object
- .validate(document) ⇒ Object
Class Method Details
.expected_children(type) ⇒ Object
49 50 51 |
# File 'lib/pdfrb/conformance/structure_elements.rb', line 49 def expected_children(type) EXPECTED_CHILDREN[type] end |
.required_attributes(type) ⇒ Object
53 54 55 |
# File 'lib/pdfrb/conformance/structure_elements.rb', line 53 def required_attributes(type) REQUIRED_ATTRIBUTES[type] end |
.standard?(type) ⇒ Boolean
57 58 59 |
# File 'lib/pdfrb/conformance/structure_elements.rb', line 57 def standard?(type) STANDARD_TYPES.include?(type.to_sym) end |
.standard_types ⇒ Object
45 46 47 |
# File 'lib/pdfrb/conformance/structure_elements.rb', line 45 def standard_types STANDARD_TYPES end |
.validate(document) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pdfrb/conformance/structure_elements.rb', line 61 def validate(document) violations = [] root_ref = document.catalog[:StructTreeRoot] return ValidationResult.new(profile: "structure-elements", violations: []) unless root_ref root = if root_ref.is_a?(Pdfrb::Model::Reference) document.object(root_ref) else root_ref end return ValidationResult.new(profile: "structure-elements", violations: []) unless root check_structure(document, root, violations) ValidationResult.new(profile: "structure-elements", violations: violations) end |