Module Prawn::Format
In: lib/prawn/format/effects/link.rb
lib/prawn/format/effects/underline.rb
lib/prawn/format/instructions/base.rb
lib/prawn/format/instructions/tag_close.rb
lib/prawn/format/instructions/tag_open.rb
lib/prawn/format/instructions/text.rb
lib/prawn/format/layout_builder.rb
lib/prawn/format/lexer.rb
lib/prawn/format/line.rb
lib/prawn/format/parser.rb
lib/prawn/format/state.rb
lib/prawn/format/text_object.rb
lib/prawn/format/version.rb
lib/prawn/format.rb
lib/prawn/format/effects/link.rb
lib/prawn/format/effects/underline.rb
lib/prawn/format/instructions/base.rb
lib/prawn/format/instructions/tag_close.rb
lib/prawn/format/instructions/tag_open.rb
lib/prawn/format/instructions/text.rb
lib/prawn/format/layout_builder.rb
lib/prawn/format/lexer.rb
lib/prawn/format/line.rb
lib/prawn/format/parser.rb
lib/prawn/format/state.rb
lib/prawn/format/text_object.rb
lib/prawn/format/version.rb
lib/prawn/format.rb

Methods

Classes and Modules

Module Prawn::Format::Effects
Module Prawn::Format::Instructions
Class Prawn::Format::LayoutBuilder
Class Prawn::Format::Lexer
Class Prawn::Format::Line
Class Prawn::Format::Parser
Class Prawn::Format::State
Class Prawn::Format::TextObject

Constants

VERSION = "0.2.0.1"
DEFAULT_TAGS = { :a => { :meta => { :name => :anchor, :href => :target }, :color => "0000ff", :text_decoration => :underline }, :b => { :font_weight => :bold }, :br => { :display => :break }, :code => { :font_family => "Courier", :font_size => "90%" }, :em => { :font_style => :italic }, :font => { :meta => { :face => :font_family, :color => :color, :size => :font_size } }, :i => { :font_style => :italic }, :pre => { :white_space => :pre, :font_family => "Courier", :font_size => "90%" }, :span => {}, :strong => { :font_weight => :bold }, :sub => { :vertical_align => :sub, :font_size => "70%" }, :sup => { :vertical_align => :super, :font_size => "70%" }, :tt => { :font_family => "Courier" }, :u => { :text_decoration => :underline }, }.freeze
VERSION = "0.2.0.1"
DEFAULT_TAGS = { :a => { :meta => { :name => :anchor, :href => :target }, :color => "0000ff", :text_decoration => :underline }, :b => { :font_weight => :bold }, :br => { :display => :break }, :code => { :font_family => "Courier", :font_size => "90%" }, :em => { :font_style => :italic }, :font => { :meta => { :face => :font_family, :color => :color, :size => :font_size } }, :i => { :font_style => :italic }, :pre => { :white_space => :pre, :font_family => "Courier", :font_size => "90%" }, :span => {}, :strong => { :font_weight => :bold }, :sub => { :vertical_align => :sub, :font_size => "70%" }, :sup => { :vertical_align => :super, :font_size => "70%" }, :tt => { :font_family => "Courier" }, :u => { :text_decoration => :underline }, }.freeze

Public Class methods

[Source]

    # File lib/prawn/format.rb, line 8
 8:     def self.included(mod)
 9:       mod.send :alias_method, :text_without_formatting, :text
10:       mod.send :alias_method, :text, :text_with_formatting
11: 
12:       mod.send :alias_method, :width_of_without_formatting, :width_of
13:       mod.send :alias_method, :width_of, :width_of_with_formatting
14: 
15:       mod.send :alias_method, :height_of_without_formatting, :height_of
16:       mod.send :alias_method, :height_of, :height_of_with_formatting
17:     end

[Source]

    # File lib/prawn/format.rb, line 8
 8:     def self.included(mod)
 9:       mod.send :alias_method, :text_without_formatting, :text
10:       mod.send :alias_method, :text, :text_with_formatting
11: 
12:       mod.send :alias_method, :width_of_without_formatting, :width_of
13:       mod.send :alias_method, :width_of, :width_of_with_formatting
14: 
15:       mod.send :alias_method, :height_of_without_formatting, :height_of
16:       mod.send :alias_method, :height_of, :height_of_with_formatting
17:     end

Public Instance methods

[Source]

    # File lib/prawn/format.rb, line 76
76:     def default_style
77:       { :font_family => font.family || font.name,
78:         :font_size   => font_size,
79:         :color       => fill_color }
80:     end

[Source]

    # File lib/prawn/format.rb, line 76
76:     def default_style
77:       { :font_family => font.family || font.name,
78:         :font_size   => font_size,
79:         :color       => fill_color }
80:     end

[Source]

     # File lib/prawn/format.rb, line 116
116:     def draw_lines(x, y, width, lines, options={})
117:       real_x, real_y = translate(x, y)
118: 
119:       state = options[:state] || {}
120:       options[:align] ||= :left
121: 
122:       state = state.merge(:width => width,
123:         :x => x, :y => y,
124:         :real_x => real_x, :real_y => real_y,
125:         :dx => 0, :dy => 0)
126: 
127:       state[:cookies] ||= {}
128:       state[:pending_effects] ||= []
129: 
130:       return state if lines.empty?
131: 
132:       text_object do |text|
133:         text.rotate(real_x, real_y, options[:rotate] || 0)
134:         state[:text] = text
135:         lines.each { |line| line.draw_on(self, state, options) }
136:       end
137: 
138:       state.delete(:text)
139: 
140:       #rectangle [x, y+state[:dy]], width, state[:dy]
141:       #stroke
142: 
143:       return state
144:     end

[Source]

     # File lib/prawn/format.rb, line 116
116:     def draw_lines(x, y, width, lines, options={})
117:       real_x, real_y = translate(x, y)
118: 
119:       state = options[:state] || {}
120:       options[:align] ||= :left
121: 
122:       state = state.merge(:width => width,
123:         :x => x, :y => y,
124:         :real_x => real_x, :real_y => real_y,
125:         :dx => 0, :dy => 0)
126: 
127:       state[:cookies] ||= {}
128:       state[:pending_effects] ||= []
129: 
130:       return state if lines.empty?
131: 
132:       text_object do |text|
133:         text.rotate(real_x, real_y, options[:rotate] || 0)
134:         state[:text] = text
135:         lines.each { |line| line.draw_on(self, state, options) }
136:       end
137: 
138:       state.delete(:text)
139: 
140:       #rectangle [x, y+state[:dy]], width, state[:dy]
141:       #stroke
142: 
143:       return state
144:     end

[Source]

     # File lib/prawn/format.rb, line 82
 82:     def evaluate_measure(measure, options={})
 83:       case measure
 84:       when nil then nil
 85:       when Numeric then return measure
 86:       when Symbol then
 87:         mappings = options[:mappings] || {}
 88:         raise ArgumentError, "unrecognized value #{measure.inspect}" unless mappings.key?(measure)
 89:         return evaluate_measure(mappings[measure], options)
 90:       when String then
 91:         operator, value, unit = measure.match(/^([-+]?)(\d+(?:\.\d+)?)(.*)$/)[1,3]
 92: 
 93:         value = case unit
 94:           when "%" then
 95:             relative = options[:relative] || 0
 96:             relative * value.to_f / 100
 97:           when "em" then
 98:             # not a true em, but good enough for approximating. patches welcome.
 99:             value.to_f * (options[:em] || font_size)
100:           when "", "pt" then return value.to_f
101:           when "pc" then return value.to_f * 12
102:           when "in" then return value.to_f * 72
103:           else raise ArgumentError, "unsupport units in style value: #{measure.inspect}"
104:           end
105: 
106:         current = options[:current] || 0
107:         case operator
108:         when "+" then return current + value
109:         when "-" then return current - value
110:         else return value
111:         end
112:       else return measure.to_f
113:       end
114:     end

[Source]

     # File lib/prawn/format.rb, line 82
 82:     def evaluate_measure(measure, options={})
 83:       case measure
 84:       when nil then nil
 85:       when Numeric then return measure
 86:       when Symbol then
 87:         mappings = options[:mappings] || {}
 88:         raise ArgumentError, "unrecognized value #{measure.inspect}" unless mappings.key?(measure)
 89:         return evaluate_measure(mappings[measure], options)
 90:       when String then
 91:         operator, value, unit = measure.match(/^([-+]?)(\d+(?:\.\d+)?)(.*)$/)[1,3]
 92: 
 93:         value = case unit
 94:           when "%" then
 95:             relative = options[:relative] || 0
 96:             relative * value.to_f / 100
 97:           when "em" then
 98:             # not a true em, but good enough for approximating. patches welcome.
 99:             value.to_f * (options[:em] || font_size)
100:           when "", "pt" then return value.to_f
101:           when "pc" then return value.to_f * 12
102:           when "in" then return value.to_f * 72
103:           else raise ArgumentError, "unsupport units in style value: #{measure.inspect}"
104:           end
105: 
106:         current = options[:current] || 0
107:         case operator
108:         when "+" then return current + value
109:         when "-" then return current - value
110:         else return value
111:         end
112:       else return measure.to_f
113:       end
114:     end

[Source]

     # File lib/prawn/format.rb, line 152
152:     def format(text, options={})
153:       if options[:at]
154:         x, y = options[:at]
155:         format_positioned_text(text, x, y, options)
156:       else
157:         format_wrapped_text(text, options)
158:       end
159:     end

[Source]

     # File lib/prawn/format.rb, line 152
152:     def format(text, options={})
153:       if options[:at]
154:         x, y = options[:at]
155:         format_positioned_text(text, x, y, options)
156:       else
157:         format_wrapped_text(text, options)
158:       end
159:     end

[Source]

     # File lib/prawn/format.rb, line 146
146:     def layout(text, options={})
147:       helper = Format::LayoutBuilder.new(self, text, options)
148:       yield helper if block_given?
149:       return helper
150:     end

[Source]

     # File lib/prawn/format.rb, line 146
146:     def layout(text, options={})
147:       helper = Format::LayoutBuilder.new(self, text, options)
148:       yield helper if block_given?
149:       return helper
150:     end

[Source]

    # File lib/prawn/format.rb, line 71
71:     def styles(update={})
72:       @styles ||= {}
73:       @styles.update(update)
74:     end

[Source]

    # File lib/prawn/format.rb, line 71
71:     def styles(update={})
72:       @styles ||= {}
73:       @styles.update(update)
74:     end

[Source]

    # File lib/prawn/format.rb, line 66
66:     def tags(update={})
67:       @tags ||= DEFAULT_TAGS.dup
68:       @tags.update(update)
69:     end

[Source]

    # File lib/prawn/format.rb, line 66
66:     def tags(update={})
67:       @tags ||= DEFAULT_TAGS.dup
68:       @tags.update(update)
69:     end

[Source]

     # File lib/prawn/format.rb, line 161
161:     def text_object
162:       object = TextObject.new
163: 
164:       if block_given?
165:         yield object.open
166:         add_content(object.close)
167:       end
168: 
169:       return object
170:     end

[Source]

     # File lib/prawn/format.rb, line 161
161:     def text_object
162:       object = TextObject.new
163: 
164:       if block_given?
165:         yield object.open
166:         add_content(object.close)
167:       end
168: 
169:       return object
170:     end

[Validate]