Sha256: 24c78cd037e47c2f9d1558748112124e17cf757d94b8536abf5edc633b6a35c9

Contents?: true

Size: 1.58 KB

Versions: 13

Compression:

Stored size: 1.58 KB

Contents

# encoding: utf-8
#
# Demonstrates transformations
#
require "#{File.dirname(__FILE__)}/../example_helper.rb"

Prawn::Document.generate "transformations.pdf" do |pdf|
  width = 50
  height = 100

  # ROTATION
  x = 50
  y = pdf.bounds.top - 50

  pdf.stroke_rectangle([x, y], width, height)
  pdf.draw_text("reference rectangle", :at => [x + width, y - height])
  pdf.rotate(30, :origin => [x, y]) do
    pdf.stroke_rectangle([x, y], width, height)
    pdf.draw_text("rectangle rotated around upper-left corner", :at => [x + width, y - height])
  end

  x = 50
  y = pdf.bounds.top - 200

  pdf.stroke_rectangle([x, y], width, height)
  pdf.draw_text("reference rectangle", :at => [x + width, y - height])
  pdf.rotate(30, :origin => [x + width / 2, y - height / 2]) do
    pdf.stroke_rectangle([x, y], width, height)
    pdf.draw_text("rectangle rotated around center", :at => [x + width, y - height])
  end

  # SCALE
  x = 0
  y = pdf.bounds.top - 500

  pdf.stroke_rectangle([x, y], width, height)
  pdf.draw_text("reference rectangle", :at => [x + width, y - height])
  pdf.scale(2, :origin => [x, y]) do
    pdf.stroke_rectangle([x, y], width, height)
    pdf.draw_text("rectangle scaled from upper-left corner", :at => [x + width, y - height])
  end

  x = 150
  y = pdf.bounds.top - 400

  pdf.stroke_rectangle([x, y], width, height)
  pdf.draw_text("reference rectangle", :at => [x + width, y - height])
  pdf.scale(2, :origin => [x + width / 2, y - height / 2]) do
    pdf.stroke_rectangle([x, y], width, height)
    pdf.draw_text("rectangle scaled from center", :at => [x + width, y - height])
  end
end

Version data entries

13 entries across 13 versions & 6 rubygems

Version Path
piglop-prawn-0.10.2.3 examples/graphics/transformations.rb
piglop-prawn-0.10.2.2 examples/graphics/transformations.rb
piglop-prawn-0.10.2.1 examples/graphics/transformations.rb
prawn-0.11.1.pre examples/graphics/transformations.rb
goodwill-prawn-edge-0.10.0 examples/graphics/transformations.rb
alphasights-prawn-0.10.4 examples/graphics/transformations.rb
alphasights-prawn-0.10.3 examples/graphics/transformations.rb
alphasights-prawn-0.10.2 examples/graphics/transformations.rb
alphasights-prawn-0.10.1 examples/graphics/transformations.rb
alphasights-prawn-0.10.0 examples/graphics/transformations.rb
prawn-core-0.8.4 examples/graphics/transformations.rb
prawn-graph-0.0.2 vendor/prawn-core/examples/graphics/transformations.rb
prawn-graph-0.0.1 vendor/prawn-core/examples/graphics/transformations.rb