File: save_graphics_state.rb

package info (click to toggle)
ruby-prawn 1.0.0~rc1%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,248 kB
  • sloc: ruby: 17,499; sh: 44; makefile: 17
file content (21 lines) | stat: -rw-r--r-- 756 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
# encoding: utf-8
#
#
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
require 'rubygems'
require 'prawn'

##
# This bug is taken from issue #102 including the comments. 
# When the bug is fixed then the third rectangle should be yellow and not green.

pdf = Prawn::Document.generate("graphics_state.pdf", :page_layout => :landscape) do
  fill_color '000000'  # Prawn thinks color space is RGB
  fill { rectangle([10, bounds.top], 10, 10) }
  save_graphics_state
  fill_color 0, 0, 0, 0  # Prawn thinks color space is CMYK  
  fill { rectangle([20, bounds.top], 10, 10) }
  restore_graphics_state  # Oops, now PDF thinks color space is RGB again
  fill_color 0, 0, 100, 0  # This won't work!
  fill { rectangle([ 30, bounds.top ], 10, 10) }
end