Module: Uniword::Docx::Reconciler::Theme

Included in:
Uniword::Docx::Reconciler
Defined in:
lib/uniword/docx/reconciler/theme.rb

Overview

Theme creation and repair.

Creates default theme when missing (profile-dependent) and repairs broken fmtScheme on loaded documents.

Instance Method Summary collapse

Instance Method Details

#reconcile_themeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/uniword/docx/reconciler/theme.rb', line 11

def reconcile_theme
  return unless profile
  return if package.theme

  theme_name = profile.system.default_theme_name
  return unless theme_name

  begin
    friendly = Themes::Theme.load(theme_name)
    word_theme = friendly.to_word_theme
    word_theme.name = "Office Theme"
    package.theme = word_theme
    record_fix(FixCodes::THEME_CREATED, "Created default theme with complete fmtScheme")
  rescue ArgumentError
    nil
  end
end

#repair_themeObject



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
61
62
# File 'lib/uniword/docx/reconciler/theme.rb', line 29

def repair_theme
  theme = package.theme
  return unless theme

  fmt = theme.theme_elements&.fmt_scheme
  return unless fmt

  repaired = false

  if count_fill_styles(fmt.fill_style_lst) < 2
    ensure_minimal_fill_list(fmt)
    repaired = true
  end

  if count_line_styles(fmt.ln_style_lst) < 3
    ensure_minimal_line_list(fmt)
    repaired = true
  end

  if count_effect_styles(fmt.effect_style_lst) < 3
    ensure_minimal_effect_list(fmt)
    repaired = true
  end

  if count_fill_styles(fmt.bg_fill_style_lst) < 2
    ensure_minimal_bg_fill_list(fmt)
    repaired = true
  end

  return unless repaired

  record_fix(FixCodes::THEME_CREATED,
             "Repaired theme fmtScheme with minimum required content")
end