Class: Prawn::Format::State
- Inherits:
-
Object
- Object
- Prawn::Format::State
- Defined in:
- lib/prawn/format/state.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#original_style ⇒ Object
readonly
Returns the value of attribute original_style.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
Instance Method Summary collapse
- #apply!(text_object, cookies) ⇒ Object
- #apply_font!(text_object, cookies, subset) ⇒ Object
- #bold? ⇒ Boolean
- #color ⇒ Object
- #display ⇒ Object
- #font ⇒ Object
- #font_family ⇒ Object
- #font_size ⇒ Object
- #font_style ⇒ Object
- #font_weight ⇒ Object
- #inheritable_style ⇒ Object
-
#initialize(document, options = {}) ⇒ State
constructor
A new instance of State.
- #italic? ⇒ Boolean
- #kerning? ⇒ Boolean
- #pdf_font_style ⇒ Object
- #previous(attr = nil, default = nil) ⇒ Object
- #text_decoration ⇒ Object
- #vertical_align ⇒ Object
- #white_space ⇒ Object
- #width ⇒ Object
- #with_style(style) ⇒ Object
Constructor Details
#initialize(document, options = {}) ⇒ State
Returns a new instance of State.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/prawn/format/state.rb', line 9 def initialize(document, ={}) @document = document @previous = [:previous] @original_style = (@previous && @previous.inheritable_style || {}). merge([:style] || {}) compute_styles! @style[:kerning] = font.has_kerning_data? unless @style.key?(:kerning) end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
6 7 8 |
# File 'lib/prawn/format/state.rb', line 6 def document @document end |
#original_style ⇒ Object (readonly)
Returns the value of attribute original_style.
7 8 9 |
# File 'lib/prawn/format/state.rb', line 7 def original_style @original_style end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
7 8 9 |
# File 'lib/prawn/format/state.rb', line 7 def style @style end |
Instance Method Details
#apply!(text_object, cookies) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/prawn/format/state.rb', line 100 def apply!(text_object, ) if [:color] != color [:color] = color text_object.fill_color(color) end if [:vertical_align] != vertical_align [:vertical_align] = vertical_align text_object.rise(vertical_align) end end |
#apply_font!(text_object, cookies, subset) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/prawn/format/state.rb', line 112 def apply_font!(text_object, , subset) if [:font] != [font_family, pdf_font_style, font_size, subset] [:font] = [font_family, pdf_font_style, font_size, subset] font = document.font(font_family, :style => pdf_font_style) font.add_to_current_page(subset) text_object.font(font.identifier_for(subset), font_size) end end |
#bold? ⇒ Boolean
125 126 127 |
# File 'lib/prawn/format/state.rb', line 125 def bold? font_weight == :bold end |
#color ⇒ Object
60 61 62 |
# File 'lib/prawn/format/state.rb', line 60 def color @style[:color] || "000000" end |
#display ⇒ Object
40 41 42 |
# File 'lib/prawn/format/state.rb', line 40 def display @style[:display] || :inline end |
#font ⇒ Object
80 81 82 |
# File 'lib/prawn/format/state.rb', line 80 def font @font ||= document.find_font(font_family, :style => pdf_font_style) end |
#font_family ⇒ Object
48 49 50 |
# File 'lib/prawn/format/state.rb', line 48 def font_family @style[:font_family] || "Helvetica" end |
#font_size ⇒ Object
44 45 46 |
# File 'lib/prawn/format/state.rb', line 44 def font_size @style[:font_size] || 12 end |
#font_style ⇒ Object
52 53 54 |
# File 'lib/prawn/format/state.rb', line 52 def font_style @style[:font_style] || :normal end |
#font_weight ⇒ Object
56 57 58 |
# File 'lib/prawn/format/state.rb', line 56 def font_weight @style[:font_weight] || :normal end |
#inheritable_style ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/prawn/format/state.rb', line 21 def inheritable_style @inheritable_style ||= begin subset = original_style.dup subset.delete(:meta) subset.delete(:display) subset.delete(:width) # explicitly set font-size so that relative font-sizes don't get # recomputed upon each nesting. subset[:font_size] = font_size subset end end |
#italic? ⇒ Boolean
121 122 123 |
# File 'lib/prawn/format/state.rb', line 121 def italic? font_style == :italic end |
#kerning? ⇒ Boolean
36 37 38 |
# File 'lib/prawn/format/state.rb', line 36 def kerning? @style[:kerning] end |
#pdf_font_style ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/prawn/format/state.rb', line 84 def pdf_font_style if bold? && italic? :bold_italic elsif bold? :bold elsif italic? :italic else :normal end end |
#previous(attr = nil, default = nil) ⇒ Object
129 130 131 132 133 |
# File 'lib/prawn/format/state.rb', line 129 def previous(attr=nil, default=nil) return @previous unless attr return default unless @previous return @previous.send(attr) || default end |
#text_decoration ⇒ Object
68 69 70 |
# File 'lib/prawn/format/state.rb', line 68 def text_decoration @style[:text_decoration] || :none end |
#vertical_align ⇒ Object
64 65 66 |
# File 'lib/prawn/format/state.rb', line 64 def vertical_align @style[:vertical_align] || 0 end |
#white_space ⇒ Object
72 73 74 |
# File 'lib/prawn/format/state.rb', line 72 def white_space @style[:white_space] || :normal end |
#width ⇒ Object
76 77 78 |
# File 'lib/prawn/format/state.rb', line 76 def width @style[:width] || 0 end |
#with_style(style) ⇒ Object
96 97 98 |
# File 'lib/prawn/format/state.rb', line 96 def with_style(style) self.class.new(document, :previous => self, :style => style) end |