Method: HexaPDF::Content::Canvas#scale
- Defined in:
- lib/hexapdf/content/canvas.rb
#scale(sx, sy = sx, origin: nil, &block) ⇒ Object
:call-seq:
canvas.scale(sx, sy = sx, origin: nil) => canvas
canvas.scale(sx, sy = sx, origin: nil) { block } => canvas
Scales the coordinate system sx units in the horizontal and sy units in the vertical direction and returns self. If the optional origin is specified, scaling is done from that point.
If invoked with a block, the scaling is only active during the block by saving and restoring the graphics state.
Note that the origin of the coordinate system itself doesn’t change even if the origin argument is given!
- origin
-
The point from which the coordinate system should be scaled.
Examples:
#>pdf-center
canvas.stroke_color("hp-gray-light").
rectangle(10, 10, 10, 10).stroke # The rectangle that gets scaled
canvas.scale(4, 2) do # Scale from origin
canvas.stroke_color("hp-blue").
rectangle(10, 10, 10, 10).stroke # Actually (40, 20) to (80, 40)
end
canvas.scale(-2, 4, origin: [10, 10]) do # Scale from (10, 10)
canvas.stroke_color("hp-orange").
rectangle(10, 10, 10, 10).stroke # Actually (10, 10) to (-10, 40)
end
See: #transform
510 511 512 513 514 515 516 |
# File 'lib/hexapdf/content/canvas.rb', line 510 def scale(sx, sy = sx, origin: nil, &block) # As with rotation, scaling is performed around the coordinate system origin but points # are translated so that the scaled scaling origin coincides with the unscaled one. tx = (origin ? origin[0] - origin[0] * sx : 0) ty = (origin ? origin[1] - origin[1] * sy : 0) transform(sx, 0, 0, sy, tx, ty, &block) end |