Rotate the user space. If a block is not provided, then you must save and restore the graphics state yourself.
| :origin | [number, number]. The point around which to rotate. 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 rotate 30 text "rotated text" restore_graphics_state
Example with a block: rotating a rectangle around its upper-left corner
x = 300
y = 300
width = 150
height = 200
angle = 30
pdf.rotate(angle, :origin => [x, y]) do
pdf.stroke_rectangle([x, y], width, height)
end
# File lib/prawn/graphics/transformation.rb, line 42
42: def rotate(angle, options={}, &block)
43: Prawn.verify_options(:origin, options)
44: rad = degree_to_rad(angle)
45: cos = Math.cos(rad)
46: sin = Math.sin(rad)
47: if options[:origin].nil?
48: transformation_matrix(cos, sin, -sin, cos, 0, 0, &block)
49: else
50: raise Prawn::Errors::BlockRequired unless block_given?
51: x = options[:origin][0] + bounds.absolute_left
52: y = options[:origin][1] + bounds.absolute_bottom
53: x_prime = x * cos - y * sin
54: y_prime = x * sin + y * cos
55: translate(x - x_prime, y - y_prime) do
56: transformation_matrix(cos, sin, -sin, cos, 0, 0, &block)
57: end
58: end
59: end
Scale the user space. If a block is not provided, then you must save and restore the graphics state yourself.
| :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
# File lib/prawn/graphics/transformation.rb, line 114
114: def scale(factor, options={}, &block)
115: Prawn.verify_options(:origin, options)
116: if options[:origin].nil?
117: transformation_matrix(factor, 0, 0, factor, 0, 0, &block)
118: else
119: raise Prawn::Errors::BlockRequired unless block_given?
120: x = options[:origin][0] + bounds.absolute_left
121: y = options[:origin][1] + bounds.absolute_bottom
122: x_prime = factor * x
123: y_prime = factor * y
124: translate(x - x_prime, y - y_prime) do
125: transformation_matrix(factor, 0, 0, factor, 0, 0, &block)
126: end
127: end
128: end
Transform the user space (see notes for rotate regarding graphics state) Generally, one would use the rotate, scale, translate, and skew convenience methods instead of calling transformation_matrix directly
# File lib/prawn/graphics/transformation.rb, line 144
144: def transformation_matrix(a, b, c, d, e, f)
145: values = [a, b, c, d, e, f].map { |x| "%.5f" % x }.join(" ")
146: save_graphics_state if block_given?
147: add_content "#{values} cm"
148: if block_given?
149: yield
150: restore_graphics_state
151: end
152: end
Translate the user space. If a block is not provided, then you must save and restore the graphics state yourself.
Example without a block: move the text up and over 10
save_graphics_state translate(10, 10) text "scaled text" restore_graphics_state
Example with a block: draw a rectangle with its upper-left corner at
x + 10, y + 10
x = 300
y = 300
width = 150
height = 200
pdf.translate(10, 10) do
pdf.stroke_rectangle([x, y], width, height)
end
# File lib/prawn/graphics/transformation.rb, line 82
82: def translate(x, y, &block)
83: transformation_matrix(1, 0, 0, 1, x, y, &block)
84: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.