Class: SvgConform::Requirements::FontFamilyRequirement

Inherits:
BaseRequirement
  • Object
show all
Defined in:
lib/svg_conform/requirements/font_family_requirement.rb

Overview

Validates font family restrictions

Instance Method Summary collapse

Methods inherited from BaseRequirement

#collect_sax_data, #element?, #get_attribute, #get_attributes, #has_attribute?, #needs_deferred_validation?, #remove_attribute, #set_attribute, #should_check_node?, #text?, #to_s, #validate_document, #validate_sax_complete

Instance Method Details

#check(node, context) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/svg_conform/requirements/font_family_requirement.rb', line 27

def check(node, context)
  return unless element?(node)

  # Check font-family attribute only (not style properties)
  # Style properties are handled by StylePromotionRequirement to avoid duplication
  font_family = get_attribute(node, "font-family")
  return unless font_family

  if svgcheck_compatibility
    check_font_family_svgcheck_mode(node, context, font_family,
                                    "font-family")
  elsif !valid_font_family?(font_family)
    context.add_error(
      requirement_id: id,
      message: "Font family '#{font_family}' is not allowed in this profile",
      node: node,
      severity: :error,
      data: { attribute: "font-family", value: font_family },
    )
  end
end

#validate_sax_element(element, context) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/svg_conform/requirements/font_family_requirement.rb', line 49

def validate_sax_element(element, context)
  # Skip if parent is structurally invalid
  return if element.parent && context.node_structurally_invalid?(element.parent)

  # Check font-family attribute only
  font_family = element.raw_attributes["font-family"]
  return unless font_family

  if svgcheck_compatibility
    check_font_family_svgcheck_mode(element, context, font_family,
                                    "font-family")
  elsif !valid_font_family?(font_family)
    context.add_error(
      requirement_id: id,
      message: "Font family '#{font_family}' is not allowed in this profile",
      node: element,
      severity: :error,
      data: { attribute: "font-family", value: font_family },
    )
  end
end