Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sandal/prawn
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Nelson committed Feb 12, 2011
2 parents c666c27 + 11b9b70 commit 65d39ef
Show file tree
Hide file tree
Showing 31 changed files with 636 additions and 71 deletions.
18 changes: 18 additions & 0 deletions bugs/looks_blank.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
require 'rubygems'
require 'bundler'
require 'prawn'
Bundler.require

##
# When this is fixed then Testing should appear with normal default black color in Acrobat reader

Prawn::Document.generate("looks_blank.pdf") do

repeat :all do
text "Testing", :size => 24, :style => :bold
end

fill_color '662255'

end
Binary file added data/pdfs/form.pdf
Binary file not shown.
29 changes: 16 additions & 13 deletions lib/prawn/graphics/color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,44 +198,47 @@ def update_colors
end

private

def current_color_space(type)
graphic_state.color_space[type]
end

def set_current_color_space(color_space, type)
save_graphics_state if graphic_state.nil?
return if state.page.in_stamp_stream?
save_graphics_state if graphic_state.nil?
graphic_state.color_space[type] = color_space
end
def current_fill_color

def current_fill_color
graphic_state.fill_color
end

def current_fill_color=(color)
def current_fill_color=(color)
return if state.page.in_stamp_stream?
graphic_state.fill_color = color
end
def current_stroke_color

def current_stroke_color
graphic_state.stroke_color
end

def current_stroke_color=(color)
def current_stroke_color=(color)
return if state.page.in_stamp_stream?
graphic_state.stroke_color = color
end

def write_fill_color
write_color(current_fill_color, 'scn')
end

def write_stroke_color
write_color(current_fill_color, 'SCN')
end

def write_color(color, operator)
add_content "#{color} #{operator}"
end

end
end
end
Expand Down
3 changes: 2 additions & 1 deletion manual/basic_concepts/basic_concepts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
{ :name => "creation", :eval_source => false, :full_source => true },
"origin",
"cursor",
"other_cursor_helpers",
"adding_pages",
"measurement"
],
]

) do

Expand Down
40 changes: 40 additions & 0 deletions manual/basic_concepts/other_cursor_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# encoding: utf-8
#
# Another group of helpers for changing the cursor position are the pad methods.
# They accept a numeric value and a block. <code>pad</code> will use the numeric
# value to move the cursor down both before and after the block content.
# <code>pad_top</code> will only move the cursor before the block while
# <code>pad_bottom</code> will only move after.
#
# <code>float</code> is a method for not changing the cursor. Pass it a block
# and the cursor will remain on the same place when the block returns.
#
require File.expand_path(File.join(File.dirname(__FILE__),
%w[.. example_helper]))

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::Example.generate(filename) do
stroke_horizontal_rule
pad(20) { text "Text padded both before and after." }

stroke_horizontal_rule
pad_top(20) { text "Text padded on the top." }

stroke_horizontal_rule
pad_bottom(20) { text "Text padded on the bottom." }

stroke_horizontal_rule
move_down 50

text "Text written before the float block."

float do
move_down 50
bounding_box [0, cursor], :width => 200 do
text "Text written inside the float block."
stroke_bounds
end
end

text "Text written after the float block."
end
5 changes: 3 additions & 2 deletions manual/bounding_box/bounding_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
],
[ "Advanced", [ "stretchy",
"nesting",
"indentation"
"indentation",
"canvas"
]
],
]
]

) do
Expand Down
24 changes: 24 additions & 0 deletions manual/bounding_box/canvas.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# encoding: utf-8
#
# The origin example already mentions that a new document already comes with
# a margin box whose bottom left corner is used as the origin for calculating
# coordinates.
#
# What has not been told is that there is one helper for "bypassing" the margin
# box: <code>canvas</code>. This method is a shortcut for creating a bounding
# box mapped to the absolute coordinates and evaluating the code inside it.
#
# The following snippet draws a circle on each of the four absolute corners.
#
require File.expand_path(File.join(File.dirname(__FILE__),
%w[.. example_helper]))

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::Example.generate(filename) do
canvas do
fill_circle_at [bounds.left, bounds.top], :radius => 30
fill_circle_at [bounds.right, bounds.top], :radius => 30
fill_circle_at [bounds.right, bounds.bottom], :radius => 30
fill_circle_at [0, 0], :radius => 30
end
end
27 changes: 27 additions & 0 deletions manual/document_and_page_options/background.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# encoding: utf-8
#
# This option can only be used on document creation. Pass an image path to the
# <code>:image</code> option and it will be used as the background for all
# pages.
#
require File.expand_path(File.join(File.dirname(__FILE__),
%w[.. example_helper]))

img = "#{Prawn::BASEDIR}/data/images/letterhead.jpg"

Prawn::Document.generate("background.pdf",
:background => img,
:margin => 100
) do
text "My report caption", :size => 18, :align => :right

move_down font.height * 2

text "Here is my text explaning this report. " * 20,
:size => 12, :align => :left, :leading => 2

move_down font.height

text "I'm using a soft background. " * 40,
:size => 12, :align => :left, :leading => 2
end
27 changes: 27 additions & 0 deletions manual/document_and_page_options/document_and_page_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# encoding: utf-8
#
# Examples for stamps and repeaters.
#
require File.expand_path(File.join(File.dirname(__FILE__),
%w[.. example_helper]))

Prawn::Example.generate("document_and_page_options.pdf") do
build_package("document_and_page_options", [
{:name => "page_size", :eval_source => false, :full_source => true},
{:name => "page_margins", :eval_source => false, :full_source => true},
{:name => "background", :eval_source => false, :full_source => true},
{:name => "metadata", :eval_source => false, :full_source => true}
]

) do
text "So far we've already seen how to create new documents and start new pages. This chapter expands on the previous examples by showing the options avialable. Some of the options are only available when creating new documents.
The examples show:"

list( "How to configure page size",
"How to configure page margins",
"How to use a background image",
"How to add metadata to the generated pdf"
)
end
end
23 changes: 23 additions & 0 deletions manual/document_and_page_options/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# encoding: utf-8
#
# To set the document metadata just pass a hash to the <code>:info</code>
# option when creating new documents.
#
require File.expand_path(File.join(File.dirname(__FILE__),
%w[.. example_helper]))

Prawn::Document.generate("metadata.pdf",
:info => {
:Title => "My title",
:Author => "John Doe",
:Subject => "My Subject",
:Keywords => "test metadata ruby pdf dry",
:Creator => "ACME Soft App",
:Producer => "Prawn",
:CreationDate => Time.now,
:Grok => "Test Property"
}) do

text "This is a test of setting metadata properties via the info option."
text "It allows one to specify no standard properties like 'Grok'."
end
38 changes: 38 additions & 0 deletions manual/document_and_page_options/page_margins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# encoding: utf-8
#
# The default margin for pages is 0.5 inch but you can change that with the
# <code>:margin</code> option or if you'd like to have different margins you
# can use the <code>:left_margin</code>, <code>:right_margin</code>,
# <code>:top_margin</code>, <code>:bottom_margin</code> options.
#
# These options are available both for starting new pages and creating new
# documents.
#
require File.expand_path(File.join(File.dirname(__FILE__),
%w[.. example_helper]))

Prawn::Document.generate("page_margins.pdf",
:margin => 100
) do
text "100 pts margins."
stroke_bounds

start_new_page(:left_margin => 300)
text "300 pts margin on the left."
stroke_bounds

start_new_page(:top_margin => 300)
text "300 pts margin both on the top and on the left. Notice that whenever " +
"you set an option for a new page it will remain the default for the " +
"following pages."
stroke_bounds

start_new_page(:margin => 50)
text "50 pts margins. Using the margin option will reset previous specific " +
"calls to left, right, top and bottom margins."
stroke_bounds

start_new_page(:margin => [50, 100, 150, 200])
text "There is also the shorthand CSS like syntax used here."
stroke_bounds
end
34 changes: 34 additions & 0 deletions manual/document_and_page_options/page_size.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# encoding: utf-8
#
# Prawn comes with support for most of the common page sizes so you'll only need
# to provide specific values if your intended format is not supported. To see a
# list with all supported sizes take a look at: https://github.com/sandal/prawn/blob/master/lib/prawn/document/page_geometry.rb
#
# To define the size use <code>:page_size</code> when creating new documents
# and <code>:size</code> when starting new pages. The default page size for new
# documents is LETTER (612.00 x 792.00).
#
# You may also define the orientation of the page to be either portrait
# (default) or landscape. Use <code>:page_layout</code> when creating new
# documents and <code>:layout</code> when starting new pages.
#
require File.expand_path(File.join(File.dirname(__FILE__),
%w[.. example_helper]))

Prawn::Document.generate("page_size.pdf",
:page_size => "EXECUTIVE",
:page_layout => :landscape
) do
text "EXECUTIVE landscape page."

custom_size = [275, 326]

["A4", "TABLOID", "B7", custom_size ].each do |size|

start_new_page(:size => size, :layout => :portrait)
text "#{size} portrait page."

start_new_page(:size => size, :layout => :landscape)
text "#{size} landscape page."
end
end
Loading

0 comments on commit 65d39ef

Please sign in to comment.