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.3"
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.3"
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 Instance methods

[Source]

    # File lib/prawn/format.rb, line 63
63:     def default_style
64:       { :font_family => font.family || font.name,
65:         :font_size   => font_size,
66:         :color       => fill_color }
67:     end

[Source]

    # File lib/prawn/format.rb, line 63
63:     def default_style
64:       { :font_family => font.family || font.name,
65:         :font_size   => font_size,
66:         :color       => fill_color }
67:     end

[Source]

     # File lib/prawn/format.rb, line 103
103:     def draw_lines(x, y, width, lines, options={})
104:       real_x, real_y = translate(x, y)
105: 
106:       state = options[:state] || {}
107:       options[:align] ||= :left
108: 
109:       state = state.merge(:width => width,
110:         :x => x, :y => y,
111:         :real_x => real_x, :real_y => real_y,
112:         :dx => 0, :dy => 0)
113: 
114:       state[:cookies] ||= {}
115:       state[:pending_effects] ||= []
116: 
117:       return state if lines.empty?
118: 
119:       text_object do |text|
120:         text.rotate(real_x, real_y, options[:rotate] || 0)
121:         state[:text] = text
122:         lines.each { |line| line.draw_on(self, state, options) }
123:       end
124: 
125:       state.delete(:text)
126: 
127:       #rectangle [x, y+state[:dy]], width, state[:dy]
128:       #stroke
129: 
130:       return state
131:     end

[Source]

     # File lib/prawn/format.rb, line 103
103:     def draw_lines(x, y, width, lines, options={})
104:       real_x, real_y = translate(x, y)
105: 
106:       state = options[:state] || {}
107:       options[:align] ||= :left
108: 
109:       state = state.merge(:width => width,
110:         :x => x, :y => y,
111:         :real_x => real_x, :real_y => real_y,
112:         :dx => 0, :dy => 0)
113: 
114:       state[:cookies] ||= {}
115:       state[:pending_effects] ||= []
116: 
117:       return state if lines.empty?
118: 
119:       text_object do |text|
120:         text.rotate(real_x, real_y, options[:rotate] || 0)
121:         state[:text] = text
122:         lines.each { |line| line.draw_on(self, state, options) }
123:       end
124: 
125:       state.delete(:text)
126: 
127:       #rectangle [x, y+state[:dy]], width, state[:dy]
128:       #stroke
129: 
130:       return state
131:     end

[Source]

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

[Source]

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

[Source]

     # File lib/prawn/format.rb, line 139
139:     def format(text, options={})
140:       if options[:at]
141:         x, y = options[:at]
142:         format_positioned_text(text, x, y, options)
143:       else
144:         format_wrapped_text(text, options)
145:       end
146:     end

[Source]

     # File lib/prawn/format.rb, line 139
139:     def format(text, options={})
140:       if options[:at]
141:         x, y = options[:at]
142:         format_positioned_text(text, x, y, options)
143:       else
144:         format_wrapped_text(text, options)
145:       end
146:     end

[Source]

     # File lib/prawn/format.rb, line 133
133:     def layout(text, options={})
134:       helper = Format::LayoutBuilder.new(self, text, options)
135:       yield helper if block_given?
136:       return helper
137:     end

[Source]

     # File lib/prawn/format.rb, line 133
133:     def layout(text, options={})
134:       helper = Format::LayoutBuilder.new(self, text, options)
135:       yield helper if block_given?
136:       return helper
137:     end

[Source]

    # File lib/prawn/format.rb, line 58
58:     def styles(update={})
59:       @styles ||= {}
60:       @styles.update(update)
61:     end

[Source]

    # File lib/prawn/format.rb, line 58
58:     def styles(update={})
59:       @styles ||= {}
60:       @styles.update(update)
61:     end

[Source]

    # File lib/prawn/format.rb, line 53
53:     def tags(update={})
54:       @tags ||= DEFAULT_TAGS.dup
55:       @tags.update(update)
56:     end

[Source]

    # File lib/prawn/format.rb, line 53
53:     def tags(update={})
54:       @tags ||= DEFAULT_TAGS.dup
55:       @tags.update(update)
56:     end

[Source]

     # File lib/prawn/format.rb, line 148
148:     def text_object
149:       object = TextObject.new
150: 
151:       if block_given?
152:         yield object.open
153:         add_content(object.close)
154:       end
155: 
156:       return object
157:     end

[Source]

     # File lib/prawn/format.rb, line 148
148:     def text_object
149:       object = TextObject.new
150: 
151:       if block_given?
152:         yield object.open
153:         add_content(object.close)
154:       end
155: 
156:       return object
157:     end

[Validate]