Class: Parchment::DOCX::Style
- Defined in:
- lib/parchment/formats/docx/style.rb
Constant Summary
Constants inherited from Style
Instance Attribute Summary
Attributes inherited from Style
#family, #font_size, #font_style, #font_weight, #id, #name, #parent_style_name, #text_align, #text_underline_style
Class Method Summary collapse
-
.new_default_style(node) ⇒ Object
The OfficeOpen format has a spcific docDefaults block which describes the globals for the document.
-
.new_from_node(node) ⇒ Object
Creates a new Style from the XML w:style element passed in.
Instance Method Summary collapse
-
#initialize ⇒ Style
constructor
– I don’t like particularly how this is set up, but the OfficeOpen format has styles split up between a global docDefaults and separate styles which relate to the ones set up in word.
Methods inherited from Style
#aligned_center?, #aligned_left?, #aligned_right?, #bold?, #italic?, #paragraph?, #text?, #underline?
Constructor Details
#initialize ⇒ Style
– I don’t like particularly how this is set up, but the OfficeOpen format has styles split up between a global docDefaults and separate styles which relate to the ones set up in word. Unlike ODT, all the styles are set on paragraphs and runs individually, rather than referring to an embedded style. But, we still want a style Object, so there’s two creation methods here. ++
15 16 |
# File 'lib/parchment/formats/docx/style.rb', line 15 def initialize end |
Class Method Details
.new_default_style(node) ⇒ Object
The OfficeOpen format has a spcific docDefaults block which describes the globals for the document. This creates a Style Object from that element.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/parchment/formats/docx/style.rb', line 32 def self.new_default_style(node) style = self.new # Right now, only concerned about document global font size. # # OfficeOpen specifications store the font size as half-points. Meaning if # something is at 12 points, it will be 24. We want actual full-point size. # font_size_tag = node.xpath('//w:docDefaults//w:rPrDefault//w:rPr//w:sz').first font_size = font_size_tag ? font_size_tag.attributes['val'].value.to_i / 2 : nil style.instance_variable_set('@font_size', font_size) return style end |
.new_from_node(node) ⇒ Object
Creates a new Style from the XML w:style element passed in.
20 21 22 23 24 25 26 |
# File 'lib/parchment/formats/docx/style.rb', line 20 def self.new_from_node(node) style = self.new @node = node instance_variable_set('@family',@node.attributes['type'].value) instance_variable_set('@id', @node.attributes['styleId'].value) return style end |