Class: Uniword::Validation::Rules::FontsRule
- Inherits:
-
Base
- Object
- Base
- Uniword::Validation::Rules::FontsRule
show all
- Defined in:
- lib/uniword/validation/rules/fonts_rule.rb
Overview
Validates font references.
DOC-070: Fonts referenced in document.xml exist in fontTable.xml DOC-071: Panose signatures present for non-symbol fonts
Constant Summary
collapse
- W_NS =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main"
Instance Method Summary
collapse
Methods inherited from Base
#description, #validity_rule
Instance Method Details
#applicable?(context) ⇒ Boolean
19
20
21
22
|
# File 'lib/uniword/validation/rules/fonts_rule.rb', line 19
def applicable?(context)
context.part_exists?("word/document.xml") &&
context.part_exists?("word/fontTable.xml")
end
|
#category ⇒ Object
16
|
# File 'lib/uniword/validation/rules/fonts_rule.rb', line 16
def category = :fonts
|
#check(context) ⇒ Object
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
60
|
# File 'lib/uniword/validation/rules/fonts_rule.rb', line 24
def check(context)
issues = []
doc = context.document_xml
return issues unless doc
ft = context.font_table_xml
return issues unless ft
defined_fonts = Set.new
ft.root.xpath(".//w:font/@w:name", "w" => W_NS).each do |attr|
defined_fonts << attr.value
end
referenced = Set.new
doc.root.xpath(".//w:rFonts/@w:ascii", "w" => W_NS).each do |attr|
referenced << attr.value
end
doc.root.xpath(".//w:rFonts/@w:hAnsi", "w" => W_NS).each do |attr|
referenced << attr.value
end
doc.root.xpath(".//w:rFonts/@w:eastAsia", "w" => W_NS).each do |attr|
referenced << attr.value
end
(referenced - defined_fonts).each do |font|
issues << issue(
"Font '#{font}' referenced but not in fontTable.xml",
part: "word/document.xml",
suggestion: "The font may render incorrectly. Add it to " \
"fontTable.xml or substitute with an available font.",
)
end
issues
end
|
#code ⇒ Object
15
|
# File 'lib/uniword/validation/rules/fonts_rule.rb', line 15
def code = "DOC-070"
|
#severity ⇒ Object
17
|
# File 'lib/uniword/validation/rules/fonts_rule.rb', line 17
def severity = "notice"
|