Skip to content

Commit

Permalink
Make the rdoc pretty, so we can call this Proterozoic
Browse files Browse the repository at this point in the history
  • Loading branch information
practicingruby committed Jun 6, 2008
1 parent eb7cfbf commit 6cc14ce
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 49 deletions.
58 changes: 29 additions & 29 deletions lib/prawn/document.rb
Expand Up @@ -23,18 +23,18 @@ class Document
# The explicit receiver argument is necessary only when you need to make
# use of a closure.
#
# # Using implicit block form and rendering to a file
# Prawn::Document.generate "foo.pdf" do
# font "Times-Roman"
# text "Hello World", :at => [200,720], :size => 32
# end
#
# # Using explicit block form and rendering to a file
# content = "Hello World"
# Prawn::Document.generate "foo.pdf" do |pdf|
# pdf.font "Times-Roman"
# pdf.text content, :at => [200,720], :size => 32
# end
# # Using implicit block form and rendering to a file
# Prawn::Document.generate "foo.pdf" do
# font "Times-Roman"
# text "Hello World", :at => [200,720], :size => 32
# end
#
# # Using explicit block form and rendering to a file
# content = "Hello World"
# Prawn::Document.generate "foo.pdf" do |pdf|
# pdf.font "Times-Roman"
# pdf.text content, :at => [200,720], :size => 32
# end
#
def self.generate(filename,options={},&block)
pdf = Prawn::Document.new(options)
Expand All @@ -44,25 +44,25 @@ def self.generate(filename,options={},&block)

# Creates a new PDF Document. The following options are available:
#
# <tt>:page_size</tt>:: One of the Document::PageGeometry::SIZES (default: LETTER)
# <tt>:page_size</tt>:: One of the Document::PageGeometry::SIZES [LETTER]
# <tt>:page_layout</tt>:: Either <tt>:portrait</tt> or <tt>:landscape</tt>
# <tt>:on_page_start</tt>:: Optional proc run at each page start
# <tt>:on_page_stop</tt>:: Optional proc run at each page stop
# <tt>:left_margin</tt>:: Sets the left margin in points [default: 0.5 inch]
# <tt>:right_margin</tt>:: Sets the right margin in points [default: 0.5 inch]
# <tt>:top_margin</tt>:: Sets the top margin in points [default: 0.5 inch]
# <tt>:bottom_margin</tt>:: Sets the bottom margin in points [default: 0.5 inch]
# <tt>:left_margin</tt>:: Sets the left margin in points [ 0.5 inch]
# <tt>:right_margin</tt>:: Sets the right margin in points [ 0.5 inch]
# <tt>:top_margin</tt>:: Sets the top margin in points [ 0.5 inch]
# <tt>:bottom_margin</tt>:: Sets the bottom margin in points [0.5 inch]
#
#
# # New document, US Letter paper, portrait orientation
# pdf = Prawn::Document.new
# # New document, US Letter paper, portrait orientation
# pdf = Prawn::Document.new
#
# # New document, A4 paper, landscaped
# pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
# # New document, A4 paper, landscaped
# pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
#
# # New document, draws a line at the start of each new page
# pdf = Prawn::Document.new(:on_page_start =>
# lambda { |doc| doc.line [0,100], [300,100] } )
# # New document, draws a line at the start of each new page
# pdf = Prawn::Document.new(:on_page_start =>
# lambda { |doc| doc.line [0,100], [300,100] } )
#
def initialize(options={})
@objects = []
Expand Down Expand Up @@ -118,10 +118,10 @@ def start_new_page

# Returns the number of pages in the document
#
# pdf = Prawn::Document.new
# pdf.page_count #=> 1
# 3.times { pdf.start_new_page }
# pdf.page_count #=> 4
# pdf = Prawn::Document.new
# pdf.page_count #=> 1
# 3.times { pdf.start_new_page }
# pdf.page_count #=> 4
def page_count
@pages.data[:Count]
end
Expand All @@ -141,7 +141,7 @@ def render

# Renders the PDF document to file.
#
# pdf.render_file "foo.pdf"
# pdf.render_file "foo.pdf"
#
def render_file(filename)
File.open(filename,"wb") { |f| f << render }
Expand Down
18 changes: 9 additions & 9 deletions lib/prawn/document/bounding_box.rb
Expand Up @@ -28,14 +28,14 @@ class Document
# Take for example two triangles which share one point, drawn from the
# origin:
#
# pdf.polygon [0,250], [0,0], [150,100]
# pdf.polygon [100,0], [150,100], [200,0]
# pdf.polygon [0,250], [0,0], [150,100]
# pdf.polygon [100,0], [150,100], [200,0]
#
# It would be easy enough to translate these triangles to another point,
# e.g [200,200]
#
# pdf.polygon [200,450], [200,200], [350,300]
# pdf.polygon [300,200], [350,300], [400,200]
# pdf.polygon [200,450], [200,200], [350,300]
# pdf.polygon [300,200], [350,300], [400,200]
#
# However, each time you want to move the drawing, you'd need to alter
# every point in the drawing calls, which as you might imagine, can become
Expand All @@ -48,10 +48,10 @@ class Document
#
# Using the [200,200] example:
#
# pdf.bounding_box([200,450], :width => 200, :height => 250) do
# pdf.polygon [0,250], [0,0], [150,100]
# pdf.polygon [100,0], [150,100], [200,0]
# end
# pdf.bounding_box([200,450], :width => 200, :height => 250) do
# pdf.polygon [0,250], [0,0], [150,100]
# pdf.polygon [100,0], [150,100], [200,0]
# end
#
# Notice that the drawing is still relative to the origin. If we want to
# move this drawing around the document, we simply need to recalculate the
Expand Down Expand Up @@ -135,4 +135,4 @@ def height
end
end
end
end
end
31 changes: 24 additions & 7 deletions lib/prawn/document/text.rb
Expand Up @@ -27,9 +27,9 @@ module Text
# linebreaks, so if you want fully automated text wrapping, be sure to
# remove newlines before attempting to draw your string.
#
# pdf.text "Hello World", :at => [100,100]
# pdf.text "Goodbye World", :at => [50,50], :size => 16
# pdf.text "Will be wrapped when it hits the edge of your bounding box"
# pdf.text "Hello World", :at => [100,100]
# pdf.text "Goodbye World", :at => [50,50], :size => 16
# pdf.text "Will be wrapped when it hits the edge of your bounding box"
#
# Under Ruby 1.8 compatible implementations, all strings passed to this
# function should be encoded as UTF-8. If you gets unexpected characters
Expand Down Expand Up @@ -89,8 +89,8 @@ def text(text,options={})
# fonts supported by PDF, or the location of a TTF file. The BUILT_INS
# array specifies the valid built in font values.
#
# pdf.font "Times-Roman"
# pdf.font "Chalkboard.ttf"
# pdf.font "Times-Roman"
# pdf.font "Chalkboard.ttf"
#
# If a ttf font is specified, the full file will be embedded in the
# rendered PDF. This should be your preferred option in most cases.
Expand All @@ -108,15 +108,32 @@ def font(name)
set_current_font
end

# Sets the font size for all text nodes inside the block
# Sets the default font size for use within a block. Individual overrides
# can be used as desired. The previous font size will be stored after the
# block.
#
# Prawn::Document.generate("font_size.pdf") do
# font_size!(16)
# text "At size 16"
#
# font_size(10) do
# text "At size 10"
# text "At size 6", :size => 6
# text "At size 10"
# end
#
# text "At size 16"
# end
#
def font_size(size)
font_size_before_block = @font_size || DEFAULT_FONT_SIZE
font_size!(size)
yield
font_size!(font_size_before_block)
end

# Sets the default font size for the document
# Sets the default font size. See example in font_size
#
def font_size!(size)
@font_size = size unless size == nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/font/cmap.rb
Expand Up @@ -6,7 +6,7 @@

module Prawn
module Font #:nodoc:
class CMap
class CMap #:nodoc:

def initialize
@codes = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/font/metrics.rb
Expand Up @@ -9,7 +9,7 @@

module Prawn
module Font #:nodoc:
class Metrics
class Metrics #:nodoc:

include Prawn::Font::Wrapping

Expand Down
4 changes: 2 additions & 2 deletions lib/prawn/font/wrapping.rb
Expand Up @@ -4,8 +4,8 @@
#
# This is free software. Please see the LICENSE and COPYING files for details.
module Prawn
module Font
module Wrapping
module Font #:nodoc:
module Wrapping #:nodoc:

# TODO: Replace with TeX optimal algorithm
def naive_wrap(string, line_width, font_size)
Expand Down

0 comments on commit 6cc14ce

Please sign in to comment.