Class: SvgConform::Requirements::TextAsPathRequirement
- Inherits:
-
BaseRequirement
- Object
- Lutaml::Model::Serializable
- BaseRequirement
- SvgConform::Requirements::TextAsPathRequirement
- Defined in:
- lib/svg_conform/requirements/text_as_path_requirement.rb
Overview
Detects SVG files where text is rendered as outlined path glyphs
instead of native
An SVG is flagged when ALL of these conditions are met:
1. No <text> element present
2. No <image> element present
3. Contains bezier curves (C/c/Q/q commands) in path d attributes
4. Longest single path d string >= min_d_length
These files are problematic because:
- Text cannot be indexed or copied
- Glyph outlines are much larger than text elements
- Poorly rendered in many graphics viewers
This is a quality check (severity: warning), not a schema violation. There is no remediation since outlined text cannot be auto-converted.
Defined Under Namespace
Classes: State
Instance Method Summary collapse
- #collect_sax_data(element, context) ⇒ Object
- #needs_deferred_validation? ⇒ Boolean
-
#validate_document(document, context) ⇒ Object
Override validate_document to do nothing since this requirement only supports SAX-based deferred validation.
- #validate_sax_complete(context) ⇒ Object
Methods inherited from BaseRequirement
#check, #get_attributes, #should_check_node?, #skip_attribute_validation?, #to_s, #validate_sax_element
Methods included from Interfaces::RequirementInterface
#check, #reset_state, #should_check_node?, #to_s, #validate_sax_element
Methods included from NodeHelpers
#element?, #get_attribute, #has_attribute?, #remove_attribute, #set_attribute, #text?
Instance Method Details
#collect_sax_data(element, context) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/svg_conform/requirements/text_as_path_requirement.rb', line 59 def collect_sax_data(element, context) state = context.state_for(self) case element.name when "text" state.has_text_element = true when "image" state.has_image_element = true when "path" d_value = element["d"] state.path_ds << d_value if d_value && !d_value.empty? end end |
#needs_deferred_validation? ⇒ Boolean
47 48 49 |
# File 'lib/svg_conform/requirements/text_as_path_requirement.rb', line 47 def needs_deferred_validation? true end |
#validate_document(document, context) ⇒ Object
Override validate_document to do nothing since this requirement only supports SAX-based deferred validation. DOM validation is not supported because we need to collect all path data before making a determination.
55 56 57 |
# File 'lib/svg_conform/requirements/text_as_path_requirement.rb', line 55 def validate_document(document, context) # No-op: This requirement only works with SAX deferred validation end |
#validate_sax_complete(context) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/svg_conform/requirements/text_as_path_requirement.rb', line 73 def validate_sax_complete(context) state = context.state_for(self) # Skip if has text or image elements (not text-as-path) return if state.has_text_element || state.has_image_element return if state.path_ds.empty? # Calculate metrics longest_d = state.path_ds.map(&:length).max total_bezier = state.path_ds.sum { |d| d.scan(/[CQcq]/).count } # Check if this is a text-as-path SVG if longest_d >= min_d_length && total_bezier >= min_bezier context.add_error( requirement_id: id, message: "Text appears to be rendered as paths (d-length: #{longest_d}, " \ "beziers: #{total_bezier}). Consider using <text> elements " \ "for better accessibility and smaller file size.", node: nil, severity: :warning, ) end end |