File: scale.rb

package info (click to toggle)
ruby-prawn 2.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,320 kB
  • sloc: ruby: 15,654; sh: 43; makefile: 20
file content (40 lines) | stat: -rw-r--r-- 1,121 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# This transformation is used to scale the user space. Give it an scale factor
# and an <code>:origin</code> point and everything inside the block will be
# scaled using the origin point as reference.
#
# If you omit the <code>:origin</code> option the page origin will be used.

require_relative '../example_helper'

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::ManualBuilder::Example.generate(filename) do
  stroke_axis

  width = 100
  height = 50

  x = 50
  y = 200

  stroke_rectangle [x, y], width, height
  text_box 'reference rectangle', at: [x + 10, y - 10], width: width - 20

  scale(2, origin: [x, y]) do
    stroke_rectangle [x, y], width, height
    text_box 'rectangle scaled from upper-left corner',
      at: [x, y - height - 5],
      width: width
  end

  x = 350

  stroke_rectangle [x, y], width, height
  text_box 'reference rectangle', at: [x + 10, y - 10], width: width - 20

  scale(2, origin: [x + width / 2, y - height / 2]) do
    stroke_rectangle [x, y], width, height
    text_box 'rectangle scaled from center',
      at: [x, y - height - 5],
      width: width
  end
end