Class Prawn::Format::State
In: lib/prawn/format/state.rb
lib/prawn/format/state.rb
Parent: Object

Methods

Constants

HTML_COLORS = { "aqua" => "00FFFF", "black" => "000000", "blue" => "0000FF", "fuchsia" => "FF00FF", "gray" => "808080", "green" => "008000", "lime" => "00FF00", "maroon" => "800000", "navy" => "000080", "olive" => "808000", "purple" => "800080", "red" => "FF0000", "silver" => "C0C0C0", "teal" => "008080", "white" => "FFFFFF", "yellow" => "FFFF00"
HTML_COLORS = { "aqua" => "00FFFF", "black" => "000000", "blue" => "0000FF", "fuchsia" => "FF00FF", "gray" => "808080", "green" => "008000", "lime" => "00FF00", "maroon" => "800000", "navy" => "000080", "olive" => "808000", "purple" => "800080", "red" => "FF0000", "silver" => "C0C0C0", "teal" => "008080", "white" => "FFFFFF", "yellow" => "FFFF00"

Attributes

document  [R] 
document  [R] 
original_style  [R] 
original_style  [R] 
style  [R] 
style  [R] 

Public Class methods

[Source]

    # File lib/prawn/format/state.rb, line 9
 9:       def initialize(document, options={})
10:         @document = document
11:         @previous = options[:previous]
12: 
13:         @original_style = (@previous && @previous.inheritable_style || {}).
14:           merge(options[:style] || {})
15: 
16:         compute_styles!
17: 
18:         @style[:kerning] = font.has_kerning_data? unless @style.key?(:kerning)
19:       end

[Source]

    # File lib/prawn/format/state.rb, line 9
 9:       def initialize(document, options={})
10:         @document = document
11:         @previous = options[:previous]
12: 
13:         @original_style = (@previous && @previous.inheritable_style || {}).
14:           merge(options[:style] || {})
15: 
16:         compute_styles!
17: 
18:         @style[:kerning] = font.has_kerning_data? unless @style.key?(:kerning)
19:       end

Public Instance methods

[Source]

     # File lib/prawn/format/state.rb, line 100
100:       def apply!(text_object, cookies)
101:         if cookies[:color] != color
102:           cookies[:color] = color
103:           text_object.fill_color(color)
104:         end
105: 
106:         if cookies[:vertical_align] != vertical_align
107:           cookies[:vertical_align] = vertical_align
108:           text_object.rise(vertical_align)
109:         end
110:       end

[Source]

     # File lib/prawn/format/state.rb, line 100
100:       def apply!(text_object, cookies)
101:         if cookies[:color] != color
102:           cookies[:color] = color
103:           text_object.fill_color(color)
104:         end
105: 
106:         if cookies[:vertical_align] != vertical_align
107:           cookies[:vertical_align] = vertical_align
108:           text_object.rise(vertical_align)
109:         end
110:       end

[Source]

     # File lib/prawn/format/state.rb, line 112
112:       def apply_font!(text_object, cookies, subset)
113:         if cookies[:font] != [font_family, pdf_font_style, font_size, subset]
114:           cookies[:font] = [font_family, pdf_font_style, font_size, subset]
115:           font = document.font(font_family, :style => pdf_font_style)
116:           font.add_to_current_page(subset)
117:           text_object.font(font.identifier_for(subset), font_size)
118:         end
119:       end

[Source]

     # File lib/prawn/format/state.rb, line 112
112:       def apply_font!(text_object, cookies, subset)
113:         if cookies[:font] != [font_family, pdf_font_style, font_size, subset]
114:           cookies[:font] = [font_family, pdf_font_style, font_size, subset]
115:           font = document.font(font_family, :style => pdf_font_style)
116:           font.add_to_current_page(subset)
117:           text_object.font(font.identifier_for(subset), font_size)
118:         end
119:       end

[Source]

     # File lib/prawn/format/state.rb, line 125
125:       def bold?
126:         font_weight == :bold
127:       end

[Source]

     # File lib/prawn/format/state.rb, line 125
125:       def bold?
126:         font_weight == :bold
127:       end

[Source]

    # File lib/prawn/format/state.rb, line 60
60:       def color
61:         @style[:color] || "000000"
62:       end

[Source]

    # File lib/prawn/format/state.rb, line 60
60:       def color
61:         @style[:color] || "000000"
62:       end

[Source]

    # File lib/prawn/format/state.rb, line 40
40:       def display
41:         @style[:display] || :inline
42:       end

[Source]

    # File lib/prawn/format/state.rb, line 40
40:       def display
41:         @style[:display] || :inline
42:       end

[Source]

    # File lib/prawn/format/state.rb, line 80
80:       def font
81:         @font ||= document.find_font(font_family, :style => pdf_font_style)
82:       end

[Source]

    # File lib/prawn/format/state.rb, line 80
80:       def font
81:         @font ||= document.find_font(font_family, :style => pdf_font_style)
82:       end

[Source]

    # File lib/prawn/format/state.rb, line 48
48:       def font_family
49:         @style[:font_family] || "Helvetica"
50:       end

[Source]

    # File lib/prawn/format/state.rb, line 48
48:       def font_family
49:         @style[:font_family] || "Helvetica"
50:       end

[Source]

    # File lib/prawn/format/state.rb, line 44
44:       def font_size
45:         @style[:font_size] || 12
46:       end

[Source]

    # File lib/prawn/format/state.rb, line 44
44:       def font_size
45:         @style[:font_size] || 12
46:       end

[Source]

    # File lib/prawn/format/state.rb, line 52
52:       def font_style
53:         @style[:font_style] || :normal
54:       end

[Source]

    # File lib/prawn/format/state.rb, line 52
52:       def font_style
53:         @style[:font_style] || :normal
54:       end

[Source]

    # File lib/prawn/format/state.rb, line 56
56:       def font_weight
57:         @style[:font_weight] || :normal
58:       end

[Source]

    # File lib/prawn/format/state.rb, line 56
56:       def font_weight
57:         @style[:font_weight] || :normal
58:       end

[Source]

    # File lib/prawn/format/state.rb, line 21
21:       def inheritable_style
22:         @inheritable_style ||= begin
23:           subset = original_style.dup
24:           subset.delete(:meta)
25:           subset.delete(:display)
26:           subset.delete(:width)
27: 
28:           # explicitly set font-size so that relative font-sizes don't get
29:           # recomputed upon each nesting.
30:           subset[:font_size] = font_size
31: 
32:           subset
33:         end
34:       end

[Source]

    # File lib/prawn/format/state.rb, line 21
21:       def inheritable_style
22:         @inheritable_style ||= begin
23:           subset = original_style.dup
24:           subset.delete(:meta)
25:           subset.delete(:display)
26:           subset.delete(:width)
27: 
28:           # explicitly set font-size so that relative font-sizes don't get
29:           # recomputed upon each nesting.
30:           subset[:font_size] = font_size
31: 
32:           subset
33:         end
34:       end

[Source]

     # File lib/prawn/format/state.rb, line 121
121:       def italic?
122:         font_style == :italic
123:       end

[Source]

     # File lib/prawn/format/state.rb, line 121
121:       def italic?
122:         font_style == :italic
123:       end

[Source]

    # File lib/prawn/format/state.rb, line 36
36:       def kerning?
37:         @style[:kerning]
38:       end

[Source]

    # File lib/prawn/format/state.rb, line 36
36:       def kerning?
37:         @style[:kerning]
38:       end

[Source]

    # File lib/prawn/format/state.rb, line 84
84:       def pdf_font_style
85:         if bold? && italic?
86:           :bold_italic
87:         elsif bold?
88:           :bold
89:         elsif italic?
90:           :italic
91:         else
92:           :normal
93:         end
94:       end

[Source]

    # File lib/prawn/format/state.rb, line 84
84:       def pdf_font_style
85:         if bold? && italic?
86:           :bold_italic
87:         elsif bold?
88:           :bold
89:         elsif italic?
90:           :italic
91:         else
92:           :normal
93:         end
94:       end

[Source]

     # File lib/prawn/format/state.rb, line 129
129:       def previous(attr=nil, default=nil)
130:         return @previous unless attr
131:         return default unless @previous
132:         return @previous.send(attr) || default
133:       end

[Source]

     # File lib/prawn/format/state.rb, line 129
129:       def previous(attr=nil, default=nil)
130:         return @previous unless attr
131:         return default unless @previous
132:         return @previous.send(attr) || default
133:       end

[Source]

    # File lib/prawn/format/state.rb, line 68
68:       def text_decoration
69:         @style[:text_decoration] || :none
70:       end

[Source]

    # File lib/prawn/format/state.rb, line 68
68:       def text_decoration
69:         @style[:text_decoration] || :none
70:       end

[Source]

    # File lib/prawn/format/state.rb, line 64
64:       def vertical_align
65:         @style[:vertical_align] || 0
66:       end

[Source]

    # File lib/prawn/format/state.rb, line 64
64:       def vertical_align
65:         @style[:vertical_align] || 0
66:       end

[Source]

    # File lib/prawn/format/state.rb, line 72
72:       def white_space
73:         @style[:white_space] || :normal
74:       end

[Source]

    # File lib/prawn/format/state.rb, line 72
72:       def white_space
73:         @style[:white_space] || :normal
74:       end

[Source]

    # File lib/prawn/format/state.rb, line 76
76:       def width
77:         @style[:width] || 0
78:       end

[Source]

    # File lib/prawn/format/state.rb, line 76
76:       def width
77:         @style[:width] || 0
78:       end

[Source]

    # File lib/prawn/format/state.rb, line 96
96:       def with_style(style)
97:         self.class.new(document, :previous => self, :style => style)
98:       end

[Source]

    # File lib/prawn/format/state.rb, line 96
96:       def with_style(style)
97:         self.class.new(document, :previous => self, :style => style)
98:       end

[Validate]