Method: Prawn::Graphics::Transformation#scale

Defined in:
lib/prawn/graphics/transformation.rb

#scale(factor, options = {}, &block) ⇒ Object

Scale the user space. If a block is not provided, then you must save and restore the graphics state yourself.

Options

:origin

[number, number]. The point from which to scale. A block must be provided if using the :origin

raises Prawn::Errors::BlockRequired if an :origin option is provided, but no block is given

Example without a block:

save_graphics_state
scale 1.5
text "scaled text"
restore_graphics_state

Example with a block: scale a rectangle from its upper-left corner

x = 300
y = 300
width = 150
height = 200
factor = 1.5
pdf.scale(angle, :origin => [x, y]) do
  pdf.stroke_rectangle([x, y], width, height)
end


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/prawn/graphics/transformation.rb', line 114

def scale(factor, options={}, &block)
  Prawn.verify_options(:origin, options)
  if options[:origin].nil?
    transformation_matrix(factor, 0, 0, factor, 0, 0, &block)
  else
    raise Prawn::Errors::BlockRequired unless block_given?
    x = options[:origin][0] + bounds.absolute_left
    y = options[:origin][1] + bounds.absolute_bottom
    x_prime = factor * x
    y_prime = factor * y
    translate(x - x_prime, y - y_prime) do
      transformation_matrix(factor, 0, 0, factor, 0, 0, &block)
    end
  end
end