Class: Uniword::Wordprocessingml::FontReplacer
- Inherits:
-
Object
- Object
- Uniword::Wordprocessingml::FontReplacer
- Defined in:
- lib/uniword/wordprocessingml/font_replacer.rb
Overview
Replaces one font family with another across a document — Word's Home → Replace → Replace Fonts as an API.
Covers style definitions and defaults, body content (paragraphs, tables, hyperlinks), headers and footers, footnotes, endnotes, comments, and numbering levels. Theme font references (asciiTheme/hAnsiTheme/...) are NOT rewritten — those are controlled by the theme's font scheme (see DocumentRoot#apply_font_scheme).
Constant Summary collapse
- FONT_ATTRIBUTES =
RunFonts attributes rewritten by font replacement.
%i[ascii h_ansi east_asia cs].freeze
Instance Attribute Summary collapse
-
#count ⇒ Integer
readonly
Number of rFonts attribute values replaced so far.
Instance Method Summary collapse
-
#initialize(from:, to:) ⇒ FontReplacer
constructor
Create a replacer.
-
#replace(document) ⇒ Integer
Replace @from with @to throughout the document (mutated).
Constructor Details
#initialize(from:, to:) ⇒ FontReplacer
Create a replacer.
28 29 30 31 32 |
# File 'lib/uniword/wordprocessingml/font_replacer.rb', line 28 def initialize(from:, to:) @from = from.to_s @to = to.to_s @count = 0 end |
Instance Attribute Details
#count ⇒ Integer (readonly)
Number of rFonts attribute values replaced so far.
37 38 39 |
# File 'lib/uniword/wordprocessingml/font_replacer.rb', line 37 def count @count end |
Instance Method Details
#replace(document) ⇒ Integer
Replace @from with @to throughout the document (mutated).
43 44 45 46 47 48 49 50 51 |
# File 'lib/uniword/wordprocessingml/font_replacer.rb', line 43 def replace(document) replace_in_styles(document.styles_configuration) replace_in_numbering(document.numbering_configuration) replace_in_container(document.body) part_containers(document).each do |container| replace_in_paragraphs(container) end count end |