Module: OoxmlParser::DocxParagraphRunHelpers

Included in:
DocxParagraphRun
Defined in:
lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/docx_paragraph_run_helpers.rb

Overview

Module for some helpers for ParagraphRun

Instance Method Summary collapse

Instance Method Details

#background_colorOoxmlParser::Color

Temp method to return background color Need to be compatible with older versions

Returns:



78
79
80
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/docx_paragraph_run_helpers.rb', line 78

def background_color
  shade.to_background_color
end

#parse_properties(node) ⇒ DocxParagraphRun

Parse other properties

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



9
10
11
12
13
14
15
16
17
18
19
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/docx_paragraph_run_helpers.rb', line 9

def parse_properties(node)
  self.font_style = FontStyle.new
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'rFonts'
      run_fonts = RunFonts.new(parent: self).parse(node_child)
      node_child.attributes.each do |font_attribute, value|
        case font_attribute
        when 'asciiTheme'
          next unless root_object.theme

          self.font = root_object.theme.font_scheme.major_font.latin.typeface if run_fonts.ascii_theme.include?('major')
          self.font = root_object.theme.font_scheme.minor_font.latin.typeface if run_fonts.ascii_theme.include?('minor')
        when 'ascii'
          self.font = value.value
          break
        end
      end
    when 'sz'
      @size_object = ValuedChild.new(:integer, parent: self).parse(node_child)
      self.size = @size_object.value.to_i / 2.0
    when 'highlight'
      @highlight_object = ValuedChild.new(:string, parent: self).parse(node_child)
      self.highlight = @highlight_object.value
    when 'vertAlign'
      @vertical_align_object = ValuedChild.new(:symbol, parent: self).parse(node_child)
      self.vertical_align = @vertical_align_object.value
    when 'effect'
      @effect_object = ValuedChild.new(:string, parent: self).parse(node_child)
      self.effect = @effect_object.value
    when 'position'
      @position_object = ValuedChild.new(:integer, parent: self).parse(node_child)
      self.position = (@position_object.value.to_f / (28.0 + (1.0 / 3.0)) / 2.0).round(1)
    when 'em'
      @em_object = ValuedChild.new(:string, parent: self).parse(node_child)
      self.em = @em_object.value
    when 'spacing'
      @spacing_object = RunSpacing.new(parent: self).parse(node_child)
      self.spacing = (@spacing_object.value.value.to_f / 566.9).round(1)
    when 'textFill'
      self.text_fill = TextFill.new(parent: self).parse(node_child)
    when 'textOutline'
      self.text_outline = TextOutline.new(parent: self).parse(node_child)
    when 'bCs', 'b'
      font_style.bold = option_enabled?(node_child)
    when 'iCs', 'i'
      font_style.italic = option_enabled?(node_child)
    when 'caps'
      self.caps = :caps
    when 'smallCaps'
      self.caps = :small_caps if option_enabled?(node_child)
    when 'color'
      parse_color_tag(node_child)
    when 'shd'
      @shade = Shade.new(parent: self).parse(node_child)
    when 'u', 'uCs'
      parse_underline(node_child)
    when 'strike'
      font_style.strike = :single if option_enabled?(node_child)
    when 'dstrike'
      font_style.strike = :double if option_enabled?(node_child)
    end
  end
  self
end