File: translate.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 (26 lines) | stat: -rw-r--r-- 677 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
# This transformation is used to translate the user space. Just provide the
# x and y coordinates for the new origin.

require_relative '../example_helper'

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

  1.upto(3) do |i|
    x = i * 50
    y = i * 100
    translate(x, y) do
      # Draw a point on the new origin
      fill_circle [0, 0], 2
      draw_text "New origin after translation to [#{x}, #{y}]",
        at: [5, -2], size: 8

      stroke_rectangle [100, 75], 100, 50
      text_box 'Top left corner at [100,75]',
        at: [110, 65],
        width: 80,
        size: 8
    end
  end
end