Prawn::Format

Constants

DEFAULT_TAGS
VERSION

Public Instance Methods

default_style() click to toggle source
# File lib/prawn/format.rb, line 62
def default_style
  { :font_family => font.family || font.name,
    :font_size   => font_size,
    :color       => fill_color }
end
draw_lines(x, y, width, lines, options={}) click to toggle source
# File lib/prawn/format.rb, line 102
def draw_lines(x, y, width, lines, options={})
  real_x, real_y = translate(x, y)

  state = options[:state] || {}
  options[:align] ||= :left

  state = state.merge(:width => width,
    :x => x, :y => y,
    :real_x => real_x, :real_y => real_y,
    :dx => 0, :dy => 0)

  state[:cookies] ||= {}
  state[:pending_effects] ||= []

  return state if lines.empty?

  text_object do |text|
    text.rotate(real_x, real_y, options[:rotate] || 0)
    state[:text] = text
    lines.each { |line| line.draw_on(self, state, options) }
  end

  state.delete(:text)

  #rectangle [x, y+state[:dy]], width, state[:dy]
  #stroke

  return state
end
evaluate_measure(measure, options={}) click to toggle source
# File lib/prawn/format.rb, line 68
def evaluate_measure(measure, options={})
  case measure
  when nil then nil
  when Numeric then return measure
  when Symbol then
    mappings = options[:mappings] || {}
    raise ArgumentError, "unrecognized value #{measure.inspect}" unless mappings.key?(measure)
    return evaluate_measure(mappings[measure], options)
  when String then
    operator, value, unit = measure.match(/^([-+]?)(\d+(?:\.\d+)?)(.*)$/)[1,3]

    value = case unit
      when "%" then
        relative = options[:relative] || 0
        relative * value.to_f / 100
      when "em" then
        # not a true em, but good enough for approximating. patches welcome.
        value.to_f * (options[:em] || font_size)
      when "", "pt" then return value.to_f
      when "pc" then return value.to_f * 12
      when "in" then return value.to_f * 72
      else raise ArgumentError, "unsupport units in style value: #{measure.inspect}"
      end

    current = options[:current] || 0
    case operator
    when "+" then return current + value
    when "-" then return current - value
    else return value
    end
  else return measure.to_f
  end
end
format(text, options={}) click to toggle source
# File lib/prawn/format.rb, line 138
def format(text, options={})
  if options[:at]
    x, y = options[:at]
    format_positioned_text(text, x, y, options)
  else
    format_wrapped_text(text, options)
  end
end
layout(text, options={}) click to toggle source
# File lib/prawn/format.rb, line 132
def layout(text, options={})
  helper = Format::LayoutBuilder.new(self, text, options)
  yield helper if block_given?
  return helper
end
styles(update={}) click to toggle source
# File lib/prawn/format.rb, line 57
def styles(update={})
  @styles ||= {}
  @styles.update(update)
end
tags(update={}) click to toggle source
# File lib/prawn/format.rb, line 52
def tags(update={})
  @tags ||= DEFAULT_TAGS.dup
  @tags.update(update)
end
text_object() click to toggle source
# File lib/prawn/format.rb, line 147
def text_object
  object = TextObject.new

  if block_given?
    yield object.open
    add_content(object.close)
  end

  return object
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.