Class: SvgConform::Remediations::FontEmbeddingRemediation
- Inherits:
-
BaseRemediation
- Object
- Lutaml::Model::Serializable
- BaseRemediation
- SvgConform::Remediations::FontEmbeddingRemediation
- Defined in:
- lib/svg_conform/remediations/font_embedding_remediation.rb
Overview
Remediation for embedding external fonts NOTE: This is a placeholder - actual font embedding would require fetching external fonts and converting them to data URIs
Instance Method Summary collapse
Methods inherited from BaseRemediation
#execute, #should_execute?, #to_s
Instance Method Details
#apply(document, _context) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/svg_conform/remediations/font_embedding_remediation.rb', line 20 def apply(document, _context) changes = [] # Find all style elements with @font-face rules document.xpath("//style").each do |style_node| content = style_node.text || "" next unless content.include?("@font-face") modified_content = (content, changes) if modified_content != content style_node.content = modified_content end end # Find font-face elements with external references document.xpath("//font-face-src/font-face-uri").each do |uri_node| href = get_attribute(uri_node, "xlink:href") || get_attribute(uri_node, "href") next unless href && !href.start_with?("data:", "#") # Convert external font to data URI = (href) if set_attribute(uri_node, "xlink:href", ) changes << { type: "font_embedded", element: "font-face-uri", message: "Embedded external font: #{href}", } else changes << { type: "font_embedding_failed", element: "font-face-uri", message: "Failed to embed font: #{href}", } end end changes end |
#can_remediate? ⇒ Boolean
61 62 63 |
# File 'lib/svg_conform/remediations/font_embedding_remediation.rb', line 61 def can_remediate? true end |