diff --git a/LICENSE b/LICENSE index db402265a..12f0f9330 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Prawn is copyrighted free software produced by Gregory Brown along with +Prawn is copyrighted free software produced by Gregory Brown along with community contributions. See git log for authorship information. Licensing terms follow (License of Ruby): @@ -42,11 +42,11 @@ or GPLv3 (see GPLv2 and GPLv3 files), or the conditions below: d) make other distribution arrangements with the author. 4. You may modify and include the part of the software into any other - software (possibly commercial). + software (possibly commercial). - 5. The scripts and library files supplied as input to or produced as + 5. The scripts and library files supplied as input to or produced as output from the software do not automatically fall under the - copyright of the software, but belong to whomever generated them, + copyright of the software, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this software. diff --git a/Rakefile b/Rakefile index 7c5a47186..bb6059279 100644 --- a/Rakefile +++ b/Rakefile @@ -5,10 +5,10 @@ Bundler.setup require 'rake' require 'rake/testtask' require "rake/rdoctask" -require "rake/gempackagetask" +require "rake/gempackagetask" task :default => [:test] - + desc "Run all tests, test-spec, mocha, and pdf-reader required" Rake::TestTask.new do |test| # test.ruby_opts << "-w" # .should == true triggers a lot of warnings @@ -20,8 +20,8 @@ end desc "Show library's code statistics" task :stats do require 'code_statistics' - CodeStatistics::TEST_TYPES << "Specs" - CodeStatistics.new( ["Prawn", "lib"], + CodeStatistics::TEST_TYPES << "Specs" + CodeStatistics.new( ["Prawn", "lib"], ["Specs", "spec"] ).to_s end @@ -29,7 +29,7 @@ desc "genrates documentation" Rake::RDocTask.new do |rdoc| rdoc.rdoc_files.include( "README", "COPYING", - "LICENSE", + "LICENSE", "HACKING", "lib/" ) rdoc.main = "README" rdoc.rdoc_dir = "doc/html" diff --git a/bench/afm_text_bench.rb b/bench/afm_text_bench.rb index 1e36df045..ee99fbeea 100644 --- a/bench/afm_text_bench.rb +++ b/bench/afm_text_bench.rb @@ -1,18 +1,18 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) -require "prawn" -require "benchmark" +require "prawn" +require "benchmark" N=2000 - -Benchmark.bmbm do |x| + +Benchmark.bmbm do |x| x.report("AFM text") do - Prawn::Document.new { - N.times do + Prawn::Document.new { + N.times do (1..5).each do |i| draw_text "Hello Prawn", :at => [200, i * 100] - end - start_new_page - end - }.render - end + end + start_new_page + end + }.render + end end diff --git a/bench/png_type_6.rb b/bench/png_type_6.rb index a0febebe1..d0659a2c8 100644 --- a/bench/png_type_6.rb +++ b/bench/png_type_6.rb @@ -1,15 +1,15 @@ -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) -require "prawn" -require "benchmark" +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) +require "prawn" +require "benchmark" N=5 - -Benchmark.bmbm do |x| - x.report("PNG Type 6") do + +Benchmark.bmbm do |x| + x.report("PNG Type 6") do N.times do - Prawn::Document.new do + Prawn::Document.new do image "#{Prawn::DATADIR}/images/dice.png" end.render - end - end -end \ No newline at end of file + end + end +end \ No newline at end of file diff --git a/bench/ttf_text_bench.rb b/bench/ttf_text_bench.rb index bad28d776..55e737dbd 100644 --- a/bench/ttf_text_bench.rb +++ b/bench/ttf_text_bench.rb @@ -1,19 +1,19 @@ -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) -require "prawn" -require "benchmark" +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) +require "prawn" +require "benchmark" N=2000 - -Benchmark.bmbm do |x| + +Benchmark.bmbm do |x| x.report("TTF text") do - Prawn::Document.new { - font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf" - N.times do + Prawn::Document.new { + font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf" + N.times do (1..5).each do |i| draw_text "Hello Prawn", :at => [200, i * 100] - end - start_new_page - end - }.render - end + end + start_new_page + end + }.render + end end diff --git a/bugs/indentation_across_pagebreaks.rb b/bugs/indentation_across_pagebreaks.rb index 0219986d4..16ddee36a 100644 --- a/bugs/indentation_across_pagebreaks.rb +++ b/bugs/indentation_across_pagebreaks.rb @@ -12,4 +12,4 @@ end end end - + diff --git a/bugs/resolved/canvas_sets_y_to_0.rb b/bugs/resolved/canvas_sets_y_to_0.rb index 0a577d3ed..2654253cc 100644 --- a/bugs/resolved/canvas_sets_y_to_0.rb +++ b/bugs/resolved/canvas_sets_y_to_0.rb @@ -1,5 +1,5 @@ # As of 7e94d25828021732f7872934cb91430ef798cd86, Document#canvas -# sets pdf.y to 0 after executing a block, which is probably not useful for +# sets pdf.y to 0 after executing a block, which is probably not useful for # anyone. It should retain the y position present at the end of the block. # # This was resolved in 998a5c3fad40c9e0a79e1468e3a83815ed948a74 [#88] @@ -8,8 +8,8 @@ require "prawn/core" Prawn::Document.generate("canvas_sets_y_to_0.pdf") do - + canvas { text "blah" } - + text "Here's my sentence. by satoko" end diff --git a/bugs/resolved/color_space_issues.rb b/bugs/resolved/color_space_issues.rb index aedbd5120..0c72f86e4 100644 --- a/bugs/resolved/color_space_issues.rb +++ b/bugs/resolved/color_space_issues.rb @@ -6,7 +6,7 @@ require 'prawn' ## -# This bug is simplification of issue #183. +# This bug is simplification of issue #183. # When the bug is fixed then a rectangle should show on both pages in Acrobat Reader. pdf = Prawn::Document.generate("color_space_issues.pdf", :page_layout => :landscape) do @@ -16,4 +16,3 @@ stroke_color "000000" stroke { rectangle([10, bounds.top], 10, 10) } end - \ No newline at end of file diff --git a/bugs/resolved/layout/cell_width_miscalculation.rb b/bugs/resolved/layout/cell_width_miscalculation.rb index 8a30598d2..66829efd6 100644 --- a/bugs/resolved/layout/cell_width_miscalculation.rb +++ b/bugs/resolved/layout/cell_width_miscalculation.rb @@ -11,14 +11,14 @@ require "prawn" require "prawn/layout" -Prawn::Document.generate("broken_table.pdf") do +Prawn::Document.generate("broken_table.pdf") do font "#{Prawn::DATADIR}/fonts/comicsans.ttf" table [["foo", "baaar", "1" ], ["This is","a sample", "2" ], ["Table", "dont\ncha\nknow?", "3" ]], - :font_size => 30, - :padding => 10, - :border => 2, + :font_size => 30, + :padding => 10, + :border => 2, :position => :center end - + diff --git a/bugs/resolved/layout/fill_color.rb b/bugs/resolved/layout/fill_color.rb index 227b7d805..f56518901 100644 --- a/bugs/resolved/layout/fill_color.rb +++ b/bugs/resolved/layout/fill_color.rb @@ -9,6 +9,6 @@ Prawn::Document.generate("fill_color.pdf") do fill_color "ff0000" - table [%w[1 2 3],%w[4 5 6],%w[7 8 9]], + table [%w[1 2 3],%w[4 5 6],%w[7 8 9]], end diff --git a/bugs/resolved/layout/table_header_overrun.rb b/bugs/resolved/layout/table_header_overrun.rb index df3cdc644..890d20bcd 100644 --- a/bugs/resolved/layout/table_header_overrun.rb +++ b/bugs/resolved/layout/table_header_overrun.rb @@ -1,4 +1,4 @@ -# Text was overflowing into following cells because of some issues with +# Text was overflowing into following cells because of some issues with # floating point numbers in naive wrap. # # Resolved in: 9c357bc488d26e7bbc2e442606106106d349e232 @@ -15,7 +15,7 @@ :top_margin => 36, :bottom_margin => 36} -Prawn::Document.generate("table_header_overrun.pdf", @prawn_document_options) do +Prawn::Document.generate("table_header_overrun.pdf", @prawn_document_options) do headers = [ "Customer", "Grand\nHijynx", "Kh", "Red\nCorvette", "Rushmore", "bPnr", "lGh", "retail\nPantaloons", "sRsm", "Total\nBoxes"] data = [[1,0,1,0,1,0,1,0,1,0], [0,1,0,1,0,1,0,1,0,1]] @@ -26,10 +26,10 @@ :horizontal_padding => 5, :vertical_padding => 3, :border => 2, - :position => :center) - + :position => :center) + start_new_page - + table [['MyString']], :headers=>['Field1'] end diff --git a/bugs/resolved/layout/table_ignores_align_headers.rb b/bugs/resolved/layout/table_ignores_align_headers.rb index f6b7e2585..9d94711ae 100644 --- a/bugs/resolved/layout/table_ignores_align_headers.rb +++ b/bugs/resolved/layout/table_ignores_align_headers.rb @@ -2,8 +2,8 @@ # Prawn ignores :align_headers property in tables # when :border_style => :grid is present (Lighthouse issue #119). # -# NOTES: -# +# NOTES: +# # * This issue can only be reproduced when :border_style => :grid is used # # Resolved as of 47297900dcf3f16c4765ca817f17c53fb0a5a079 @@ -21,8 +21,8 @@ left = "Left justified" left2 = "left" center = "centered" - table [[left, left], [left2, left2]], :headers => [center, center], - :align => :left, + table [[left, left], [left2, left2]], :headers => [center, center], + :align => :left, :align_headers => :center, :border_style => :grid end diff --git a/bugs/resolved/layout/table_in_bounding_box_without_height.rb b/bugs/resolved/layout/table_in_bounding_box_without_height.rb index d8660094d..5ef6dfcf4 100644 --- a/bugs/resolved/layout/table_in_bounding_box_without_height.rb +++ b/bugs/resolved/layout/table_in_bounding_box_without_height.rb @@ -1,11 +1,11 @@ -# encoding: utf-8 +# encoding: utf-8 # # Issue with tables within stretchy bounding boxes. Changes to the way # bounding boxes work caused tables to not properly render within stretchy -# bounding boxes. +# bounding boxes. # # A fix in 200fc36455fa3bee0e1e3bb25d1b5bf73dbf3b52 makes it so the bottom -# of the margin_box will be used as the page boundary in stretchy bounding +# of the margin_box will be used as the page boundary in stretchy bounding # boxes. Ideally, this would instead use the nesting bounding box dimensions # [#80] , but this works for now. # @@ -14,7 +14,7 @@ require "prawn" require "prawn/layout" -Prawn::Document.generate("table_in_bounding_box_without_height.pdf") do +Prawn::Document.generate("table_in_bounding_box_without_height.pdf") do bounding_box bounds.top_left, :width => 200 do table [%w(These should all be), %w(on the same page)] end diff --git a/bugs/resolved/layout/table_row_background_color_issue.rb b/bugs/resolved/layout/table_row_background_color_issue.rb index 099146767..f4873778a 100644 --- a/bugs/resolved/layout/table_row_background_color_issue.rb +++ b/bugs/resolved/layout/table_row_background_color_issue.rb @@ -1,10 +1,10 @@ # As of 96f660660345c7c22923ba51d0124022a3a189ab, table is currently not taking # in account border widths when filling in rows with background coloring. This -# means the larger the border, the larger the visible gap between rows. +# means the larger the border, the larger the visible gap between rows. # # This problem was fixed in 97d9bf083fd9423d17fd1efca36ea675ff34a6d7, but # there remains a very minor issue when the border size is 1 for the headers. -# Because this almost appears to be a feature display-wise, we will leave it +# Because this almost appears to be a feature display-wise, we will leave it # alone for now. # $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib') @@ -12,32 +12,32 @@ require "prawn" require "prawn/layout" -Prawn::Document.generate("table_with_background_color_problems.pdf") do +Prawn::Document.generate("table_with_background_color_problems.pdf") do font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf" table [["ὕαλον ϕαγεῖν", "baaar", "1" ], ["This is","a sample", "2" ], ["Table", "dont\ncha\nknow?", "3" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules\nwith an iron fist", "x" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ], - [ "It", "Rules", "4" ]], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules\nwith an iron fist", "x" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ], + [ "It", "Rules", "4" ]], - :font_size => 10, + :font_size => 10, :horizontal_padding => 10, :vertical_padding => 3, :border => 1, @@ -49,7 +49,7 @@ text "This should appear in the original font size" end - table [[ "Wide", "columns", "streeetch"], + table [[ "Wide", "columns", "streeetch"], ["are","mighty fine", "streeeeeeeech"]], :column_widths => { 0 => 200, 1 => 250 }, :position => 5 diff --git a/bugs/resolved/layout/table_suppress_newline.rb b/bugs/resolved/layout/table_suppress_newline.rb index 4d9d4daca..54d0a0a0f 100644 --- a/bugs/resolved/layout/table_suppress_newline.rb +++ b/bugs/resolved/layout/table_suppress_newline.rb @@ -11,6 +11,6 @@ Prawn::Document.generate("table_supresses_newlines.pdf") do table [["test\n\naaaa","test\n\nbbbb"], ["test\n\ncccc", "test\n\ndddd"]], :border_style => :grid - + cell [100,100], :text => "test\n\naaaa" end diff --git a/bugs/resolved/save_graphics_state.rb b/bugs/resolved/save_graphics_state.rb index 5d03c63b5..f62389c80 100644 --- a/bugs/resolved/save_graphics_state.rb +++ b/bugs/resolved/save_graphics_state.rb @@ -6,14 +6,14 @@ require 'prawn' ## -# This bug is taken from issue #102 including the comments. +# 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_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! diff --git a/bugs/resolved/stamp_color_issues.rb b/bugs/resolved/stamp_color_issues.rb index 0e4c3d453..3eef391e0 100644 --- a/bugs/resolved/stamp_color_issues.rb +++ b/bugs/resolved/stamp_color_issues.rb @@ -6,7 +6,7 @@ require 'prawn' ## -# This bug was reported in comments in issue #200 +# This bug was reported in comments in issue #200 # When the bug is fixed the stamp text and shape color should be set to a blue CMYK color pdf = Prawn::Document.generate("stamp_color_issues.pdf", :margin => [40, 45, 50, 45]) do diff --git a/bugs/resolved/ttf_fails_in_transactions.rb b/bugs/resolved/ttf_fails_in_transactions.rb index 1ad97d0bf..f8a5d944e 100644 --- a/bugs/resolved/ttf_fails_in_transactions.rb +++ b/bugs/resolved/ttf_fails_in_transactions.rb @@ -3,7 +3,7 @@ # As of f952055d03f9b21b78ec2844bd873cf62005d00a # Transactions fail when using TTF fonts. # -# This is because we use an on_encode Proc that gets included in the +# This is because we use an on_encode Proc that gets included in the # @current_page object, which breaks snapshots. We can surely write # around this to either split out the Proc into non-marshalled data # or set up some sort of callback that is indicated by something that @@ -15,7 +15,7 @@ # Resolved in 36ef89c2bc21e504df623f61d918c5bfdc1fdab1. $LOAD_PATH << File.join(File.dirname(__FILE__), '..', '..','lib') -require 'prawn/core' +require 'prawn/core' Prawn::Document.generate("err.pdf") do font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf" diff --git a/data/fonts/Courier-Bold.afm b/data/fonts/Courier-Bold.afm index eb80542b1..9c1b7b0a9 100644 --- a/data/fonts/Courier-Bold.afm +++ b/data/fonts/Courier-Bold.afm @@ -10,7 +10,7 @@ Weight Bold ItalicAngle 0 IsFixedPitch true CharacterSet ExtendedRoman -FontBBox -113 -250 749 801 +FontBBox -113 -250 749 801 UnderlinePosition -100 UnderlineThickness 50 Version 003.000 diff --git a/data/fonts/Courier-BoldOblique.afm b/data/fonts/Courier-BoldOblique.afm index 29d3b8b10..a3394564e 100644 --- a/data/fonts/Courier-BoldOblique.afm +++ b/data/fonts/Courier-BoldOblique.afm @@ -10,7 +10,7 @@ Weight Bold ItalicAngle -12 IsFixedPitch true CharacterSet ExtendedRoman -FontBBox -57 -250 869 801 +FontBBox -57 -250 869 801 UnderlinePosition -100 UnderlineThickness 50 Version 003.000 diff --git a/data/fonts/Courier-Oblique.afm b/data/fonts/Courier-Oblique.afm index 3dc163f77..ef7a9c2d4 100644 --- a/data/fonts/Courier-Oblique.afm +++ b/data/fonts/Courier-Oblique.afm @@ -10,7 +10,7 @@ Weight Medium ItalicAngle -12 IsFixedPitch true CharacterSet ExtendedRoman -FontBBox -27 -250 849 805 +FontBBox -27 -250 849 805 UnderlinePosition -100 UnderlineThickness 50 Version 003.000 diff --git a/data/fonts/Courier.afm b/data/fonts/Courier.afm index 2f7be81d5..05186226e 100644 --- a/data/fonts/Courier.afm +++ b/data/fonts/Courier.afm @@ -10,7 +10,7 @@ Weight Medium ItalicAngle 0 IsFixedPitch true CharacterSet ExtendedRoman -FontBBox -23 -250 715 805 +FontBBox -23 -250 715 805 UnderlinePosition -100 UnderlineThickness 50 Version 003.000 diff --git a/data/fonts/Helvetica-Bold.afm b/data/fonts/Helvetica-Bold.afm index 837c594e0..e3fd831e2 100644 --- a/data/fonts/Helvetica-Bold.afm +++ b/data/fonts/Helvetica-Bold.afm @@ -10,7 +10,7 @@ Weight Bold ItalicAngle 0 IsFixedPitch false CharacterSet ExtendedRoman -FontBBox -170 -228 1003 962 +FontBBox -170 -228 1003 962 UnderlinePosition -100 UnderlineThickness 50 Version 002.000 diff --git a/data/fonts/Helvetica-BoldOblique.afm b/data/fonts/Helvetica-BoldOblique.afm index 1715b2104..5a2947b99 100644 --- a/data/fonts/Helvetica-BoldOblique.afm +++ b/data/fonts/Helvetica-BoldOblique.afm @@ -10,7 +10,7 @@ Weight Bold ItalicAngle -12 IsFixedPitch false CharacterSet ExtendedRoman -FontBBox -174 -228 1114 962 +FontBBox -174 -228 1114 962 UnderlinePosition -100 UnderlineThickness 50 Version 002.000 diff --git a/data/fonts/Helvetica-Oblique.afm b/data/fonts/Helvetica-Oblique.afm index 7a7af0017..166086fd3 100644 --- a/data/fonts/Helvetica-Oblique.afm +++ b/data/fonts/Helvetica-Oblique.afm @@ -10,7 +10,7 @@ Weight Medium ItalicAngle -12 IsFixedPitch false CharacterSet ExtendedRoman -FontBBox -170 -225 1116 931 +FontBBox -170 -225 1116 931 UnderlinePosition -100 UnderlineThickness 50 Version 002.000 diff --git a/data/fonts/Helvetica.afm b/data/fonts/Helvetica.afm index bd32af54d..d1285e2d1 100644 --- a/data/fonts/Helvetica.afm +++ b/data/fonts/Helvetica.afm @@ -10,7 +10,7 @@ Weight Medium ItalicAngle 0 IsFixedPitch false CharacterSet ExtendedRoman -FontBBox -166 -225 1000 931 +FontBBox -166 -225 1000 931 UnderlinePosition -100 UnderlineThickness 50 Version 002.000 diff --git a/data/fonts/Symbol.afm b/data/fonts/Symbol.afm index 6a5386a91..4196ea5fd 100644 --- a/data/fonts/Symbol.afm +++ b/data/fonts/Symbol.afm @@ -10,7 +10,7 @@ Weight Medium ItalicAngle 0 IsFixedPitch false CharacterSet Special -FontBBox -180 -293 1090 1010 +FontBBox -180 -293 1090 1010 UnderlinePosition -100 UnderlineThickness 50 Version 001.008 diff --git a/data/fonts/Times-Bold.afm b/data/fonts/Times-Bold.afm index 559ebaeb6..c2cd05683 100644 --- a/data/fonts/Times-Bold.afm +++ b/data/fonts/Times-Bold.afm @@ -10,7 +10,7 @@ Weight Bold ItalicAngle 0 IsFixedPitch false CharacterSet ExtendedRoman -FontBBox -168 -218 1000 935 +FontBBox -168 -218 1000 935 UnderlinePosition -100 UnderlineThickness 50 Version 002.000 diff --git a/data/fonts/Times-BoldItalic.afm b/data/fonts/Times-BoldItalic.afm index 2301dfd23..0e9ad5ef4 100644 --- a/data/fonts/Times-BoldItalic.afm +++ b/data/fonts/Times-BoldItalic.afm @@ -10,7 +10,7 @@ Weight Bold ItalicAngle -15 IsFixedPitch false CharacterSet ExtendedRoman -FontBBox -200 -218 996 921 +FontBBox -200 -218 996 921 UnderlinePosition -100 UnderlineThickness 50 Version 002.000 diff --git a/data/fonts/Times-Italic.afm b/data/fonts/Times-Italic.afm index b0eaee40f..70cc242c8 100644 --- a/data/fonts/Times-Italic.afm +++ b/data/fonts/Times-Italic.afm @@ -10,7 +10,7 @@ Weight Medium ItalicAngle -15.5 IsFixedPitch false CharacterSet ExtendedRoman -FontBBox -169 -217 1010 883 +FontBBox -169 -217 1010 883 UnderlinePosition -100 UnderlineThickness 50 Version 002.000 diff --git a/data/fonts/Times-Roman.afm b/data/fonts/Times-Roman.afm index a0953f280..811f21e52 100644 --- a/data/fonts/Times-Roman.afm +++ b/data/fonts/Times-Roman.afm @@ -10,7 +10,7 @@ Weight Roman ItalicAngle 0 IsFixedPitch false CharacterSet ExtendedRoman -FontBBox -168 -218 1000 898 +FontBBox -168 -218 1000 898 UnderlinePosition -100 UnderlineThickness 50 Version 002.000 diff --git a/data/fonts/ZapfDingbats.afm b/data/fonts/ZapfDingbats.afm index b2745053e..c5b28c0af 100644 --- a/data/fonts/ZapfDingbats.afm +++ b/data/fonts/ZapfDingbats.afm @@ -10,7 +10,7 @@ Weight Medium ItalicAngle 0 IsFixedPitch false CharacterSet Special -FontBBox -1 -143 981 820 +FontBBox -1 -143 981 820 UnderlinePosition -100 UnderlineThickness 50 Version 002.000 diff --git a/lib/prawn/compatibility.rb b/lib/prawn/compatibility.rb index 26080c8ad..61e1d8c6e 100644 --- a/lib/prawn/compatibility.rb +++ b/lib/prawn/compatibility.rb @@ -22,30 +22,30 @@ def each_char #:nodoc: end end -unless File.respond_to?(:binread) +unless File.respond_to?(:binread) def File.binread(file) #:nodoc: - File.open(file,"rb") { |f| f.read } + File.open(file,"rb") { |f| f.read } end end if RUBY_VERSION < "1.9" - - def ruby_18 #:nodoc: + + def ruby_18 #:nodoc: yield end - - def ruby_19 #:nodoc: + + def ruby_19 #:nodoc: false end - -else - - def ruby_18 #:nodoc: - false + +else + + def ruby_18 #:nodoc: + false end - - def ruby_19 #:nodoc: + + def ruby_19 #:nodoc: yield - end - -end + end + +end diff --git a/lib/prawn/core.rb b/lib/prawn/core.rb index 5a02c5568..248fa41f4 100644 --- a/lib/prawn/core.rb +++ b/lib/prawn/core.rb @@ -26,10 +26,10 @@ module Prawn file = __FILE__ file = File.readlink(file) if File.symlink?(file) dir = File.dirname(file) - + # The base source directory for Prawn as installed on the system # - # + # BASEDIR = File.expand_path(File.join(dir, '..','..')) DATADIR = File.expand_path(File.join(dir, '..', '..', 'data')) @@ -38,12 +38,12 @@ module Prawn # # Example: # >> Prawn::Document.new(:tomato => "Juicy") - # Prawn::Errors::UnknownOption: + # Prawn::Errors::UnknownOption: # Detected unknown option(s): [:tomato] # Accepted options are: [:page_size, :page_layout, :left_margin, ...] # attr_accessor :debug - + def verify_options(accepted, actual) #:nodoc: return unless debug || $DEBUG unless (act=Set[*actual.keys]).subset?(acc=Set[*accepted]) @@ -53,7 +53,7 @@ def verify_options(accepted, actual) #:nodoc: end yield if block_given? end - + module Configurable #:nodoc: def configuration(*args) @config ||= Marshal.load(Marshal.dump(default_configuration)) @@ -67,11 +67,11 @@ def configuration(*args) @config end end - + alias_method :C, :configuration end end - + require "prawn/compatibility" require "prawn/errors" require "prawn/core/pdf_object" diff --git a/lib/prawn/core/annotations.rb b/lib/prawn/core/annotations.rb index 276f6170d..38e7185bf 100644 --- a/lib/prawn/core/annotations.rb +++ b/lib/prawn/core/annotations.rb @@ -7,12 +7,12 @@ # This is free software. Please see the LICENSE and COPYING files for details. # module Prawn - module Core - - # Provides very low-level support for annotations. + module Core + + # Provides very low-level support for annotations. # module Annotations #:nodoc: - + # Adds a new annotation (section 8.4 in PDF spec) to the current page. # +options+ must be a Hash describing the annotation. # @@ -55,7 +55,7 @@ def sanitize_annotation_hash(options) options end - + end end end diff --git a/lib/prawn/core/destinations.rb b/lib/prawn/core/destinations.rb index ff1141220..34558692f 100644 --- a/lib/prawn/core/destinations.rb +++ b/lib/prawn/core/destinations.rb @@ -9,10 +9,10 @@ module Prawn module Core module Destinations #:nodoc: - + # The maximum number of children to fit into a single node in the Dests tree. NAME_TREE_CHILDREN_LIMIT = 20 #:nodoc: - + # The Dests name tree in the Name dictionary (see Prawn::Document::Internal#names). # This name tree is used to store named destinations (PDF spec 8.2.1). # (For more on name trees, see section 3.8.4 in the PDF spec.) diff --git a/lib/prawn/core/document_state.rb b/lib/prawn/core/document_state.rb index 27da9ec9d..4a37db10d 100644 --- a/lib/prawn/core/document_state.rb +++ b/lib/prawn/core/document_state.rb @@ -68,7 +68,7 @@ def render_body(output) store.compact if optimize_objects store.each do |ref| ref.offset = output.size - output << (@encrypt ? ref.encrypted_object(@encryption_key) : + output << (@encrypt ? ref.encrypted_object(@encryption_key) : ref.object) end end diff --git a/lib/prawn/core/pdf_object.rb b/lib/prawn/core/pdf_object.rb index 11d7aca19..fda31e36c 100644 --- a/lib/prawn/core/pdf_object.rb +++ b/lib/prawn/core/pdf_object.rb @@ -8,9 +8,9 @@ # Top level Module # -module Prawn +module Prawn module Core #:nodoc: - + module_function if "".respond_to?(:encode) @@ -48,24 +48,24 @@ def string_to_hex(str) str.unpack("H*").first end end - + # Serializes Ruby objects to their PDF equivalents. Most primitive objects - # will work as expected, but please note that Name objects are represented + # will work as expected, but please note that Name objects are represented # by Ruby Symbol objects and Dictionary objects are represented by Ruby hashes - # (keyed by symbols) + # (keyed by symbols) # # Examples: # # PdfObject(true) #=> "true" - # PdfObject(false) #=> "false" + # PdfObject(false) #=> "false" # PdfObject(1.2124) #=> "1.2124" - # PdfObject("foo bar") #=> "(foo bar)" + # PdfObject("foo bar") #=> "(foo bar)" # PdfObject(:Symbol) #=> "/Symbol" # PdfObject(["foo",:bar, [1,2]]) #=> "[foo /bar [1 2]]" - # + # def PdfObject(obj, in_content_stream = false) - case(obj) - when NilClass then "null" + case(obj) + when NilClass then "null" when TrueClass then "true" when FalseClass then "false" when Numeric @@ -89,7 +89,7 @@ def PdfObject(obj, in_content_stream = false) when String obj = utf8_to_utf16(obj) unless in_content_stream "<" << string_to_hex(obj) << ">" - when Symbol + when Symbol "/" + obj.to_s.unpack("C*").map { |n| if n < 33 || n > 126 || [35,40,41,47,60,62].include?(n) "#" + n.to_s(16).upcase @@ -97,19 +97,19 @@ def PdfObject(obj, in_content_stream = false) [n].pack("C*") end }.join - when Hash + when Hash output = "<< " - obj.each do |k,v| + obj.each do |k,v| unless String === k || Symbol === k - raise Prawn::Errors::FailedObjectConversion, + raise Prawn::Errors::FailedObjectConversion, "A PDF Dictionary must be keyed by names" - end - output << PdfObject(k.to_sym, in_content_stream) << " " << + end + output << PdfObject(k.to_sym, in_content_stream) << " " << PdfObject(v, in_content_stream) << "\n" - end - output << ">>" + end + output << ">>" when Prawn::Core::Reference - obj.to_s + obj.to_s when Prawn::Core::NameTree::Node PdfObject(obj.to_hash) when Prawn::Core::NameTree::Value @@ -117,9 +117,9 @@ def PdfObject(obj, in_content_stream = false) when Prawn::OutlineRoot, Prawn::OutlineItem PdfObject(obj.to_hash) else - raise Prawn::Errors::FailedObjectConversion, + raise Prawn::Errors::FailedObjectConversion, "This object cannot be serialized to PDF (#{obj.inspect})" - end - end + end + end end end diff --git a/lib/prawn/core/reference.rb b/lib/prawn/core/reference.rb index c02042bcf..47cb35016 100644 --- a/lib/prawn/core/reference.rb +++ b/lib/prawn/core/reference.rb @@ -8,36 +8,36 @@ require 'zlib' -module Prawn +module Prawn module Core - + class Reference #:nodoc: attr_accessor :gen, :data, :offset, :stream, :live, :identifier - + def initialize(id, data) - @identifier = id - @gen = 0 - @data = data + @identifier = id + @gen = 0 + @data = data @compressed = false @stream = nil - end - - def object + end + + def object output = "#{@identifier} #{gen} obj\n" << Prawn::Core::PdfObject(data) << "\n" if @stream - output << "stream\n" << @stream << "\nendstream\n" + output << "stream\n" << @stream << "\nendstream\n" end output << "endobj\n" - end - + end + def <<(data) raise 'Cannot add data to a stream that is compressed' if @compressed - (@stream ||= "") << data - end - - def to_s + (@stream ||= "") << data + end + + def to_s "#{@identifier} #{gen} R" end @@ -73,7 +73,7 @@ def deep_copy(share=[]) r.stream = Marshal.load(Marshal.dump(r.stream)) r end - + # Replaces the data and stream with that of other_ref. Preserves compressed # status. def replace(other_ref) @@ -104,12 +104,12 @@ def referenced_objects(obj=@data) end.flatten.grep(self.class) end - end + end module_function - + def Reference(*args, &block) #:nodoc: Reference.new(*args, &block) - end + end end end diff --git a/lib/prawn/core/text/formatted/arranger.rb b/lib/prawn/core/text/formatted/arranger.rb index fd270a9b3..79be3a456 100644 --- a/lib/prawn/core/text/formatted/arranger.rb +++ b/lib/prawn/core/text/formatted/arranger.rb @@ -285,7 +285,7 @@ def set_line_measurement_maximums(fragment) @max_descender = [@max_descender, fragment.descender].compact.max @max_ascender = [@max_ascender, fragment.ascender].compact.max end - + end end diff --git a/lib/prawn/core/text/formatted/line_wrap.rb b/lib/prawn/core/text/formatted/line_wrap.rb index 6b57df6b4..86d72d5b7 100644 --- a/lib/prawn/core/text/formatted/line_wrap.rb +++ b/lib/prawn/core/text/formatted/line_wrap.rb @@ -1,6 +1,6 @@ # encoding: utf-8 -# core/text/formatted/line_wrap.rb : Implements individual line wrapping of +# core/text/formatted/line_wrap.rb : Implements individual line wrapping of # formatted text # # Copyright February 2010, Daniel Nelson. All Rights Reserved. @@ -12,7 +12,7 @@ module Prawn module Core module Text module Formatted #:nodoc: - + class LineWrap #:nodoc: # The width of the last wrapped line diff --git a/lib/prawn/core/text/formatted/wrap.rb b/lib/prawn/core/text/formatted/wrap.rb index 6c4771419..41b426c56 100644 --- a/lib/prawn/core/text/formatted/wrap.rb +++ b/lib/prawn/core/text/formatted/wrap.rb @@ -12,7 +12,7 @@ def initialize(array, options) @arranger = Prawn::Core::Text::Formatted::Arranger.new(@document, :kerning => options[:kerning]) end - + # See the developer documentation for Prawn::Core::Text#wrap # diff --git a/lib/prawn/document.rb b/lib/prawn/document.rb index d985a34c1..dca31286f 100644 --- a/lib/prawn/document.rb +++ b/lib/prawn/document.rb @@ -539,15 +539,15 @@ def @bounding_box.move_past_bottom # through existing pages after they are created. # # Parameters are: - # - # string:: Template string for page number wording. + # + # string:: Template string for page number wording. # Should include '' and, optionally, ''. # options:: A hash for page numbering and text box options. - # :page_filter:: A filter to specify which pages to place page numbers on. + # :page_filter:: A filter to specify which pages to place page numbers on. # Refer to the method 'page_match?' # :start_count_at:: The starting count to increment pages from. # :total_pages:: If provided, will replace with the value given. - # Useful to override the total number of pages when using + # Useful to override the total number of pages when using # the start_count_at option. # :color:: Text fill color. # @@ -558,7 +558,7 @@ def @bounding_box.move_past_bottom # five. # # Prawn::Document.generate("page_with_numbering.pdf") do - # number_pages " in a total of ", + # number_pages " in a total of ", # {:start_count_at => 5, # :page_filter => lambda{ |pg| pg != 1 }, # :at => [bounds.right - 50, 0], @@ -578,7 +578,7 @@ def number_pages(string, options={}) txtcolor = opts.delete(:color) # An explicit height so that we can draw page numbers in the margins opts[:height] = 50 - + start_count = false pseudopage = 0 (1..page_count).each do |p| @@ -589,7 +589,7 @@ def number_pages(string, options={}) else start_count_at.to_i end - end + end if page_match?(page_filter, p) go_to_page(p) # have to use fill_color here otherwise text reverts back to default fill color @@ -598,13 +598,13 @@ def number_pages(string, options={}) str = string.gsub("","#{pseudopage}").gsub("","#{total_pages}") text_box str, opts start_count = true # increment page count as soon as first match found - end + end pseudopage += 1 if start_count end end # Provides a way to execute a block of code repeatedly based on a - # page_filter. + # page_filter. # # Available page filters are: # :all repeats on every page @@ -612,7 +612,7 @@ def number_pages(string, options={}) # :even repeats on even pages # some_array repeats on every page listed in the array # some_range repeats on every page included in the range - # some_lambda yields page number and repeats for true return values + # some_lambda yields page number and repeats for true return values def page_match?(page_filter, page_number) case page_filter when :all @@ -626,7 +626,7 @@ def page_match?(page_filter, page_number) when Proc page_filter.call(page_number) end - end + end # Returns true if content streams will be compressed before rendering, diff --git a/lib/prawn/document/column_box.rb b/lib/prawn/document/column_box.rb index 71495486f..e9199e067 100644 --- a/lib/prawn/document/column_box.rb +++ b/lib/prawn/document/column_box.rb @@ -17,9 +17,9 @@ class Document # number of :columns and a :spacer (in points) between columns. # # Defaults are :columns = 3 and :spacer = font_size - # + # # Under PDF::Writer, "spacer" was known as "gutter" - # + # def column_box(*args, &block) init_column_box(block) do |parent_box| map_to_absolute!(args[0]) @@ -40,7 +40,7 @@ def init_column_box(user_block, options={}, &init_block) @bounding_box = parent_box end - + # Implements the necessary functionality to allow Document#column_box to # work. # @@ -99,7 +99,7 @@ def right # Moves to the next column or starts a new page if currently positioned at # the rightmost column. - def move_past_bottom + def move_past_bottom @current_column = (@current_column + 1) % @columns @document.y = @y if 0 == @current_column diff --git a/lib/prawn/document/graphics_state.rb b/lib/prawn/document/graphics_state.rb index 2f6dad098..c30f6f35f 100644 --- a/lib/prawn/document/graphics_state.rb +++ b/lib/prawn/document/graphics_state.rb @@ -10,27 +10,27 @@ module Prawn class GraphicStateStack attr_accessor :stack - + def initialize(previous_state = nil) self.stack = [GraphicState.new(previous_state)] end - + def save_graphic_state(graphic_state = nil) stack.push(GraphicState.new(graphic_state || current_state)) end - + def restore_graphic_state if stack.empty? - raise Prawn::Errors::EmptyGraphicStateStack, - "\n You have reached the end of the graphic state stack" + raise Prawn::Errors::EmptyGraphicStateStack, + "\n You have reached the end of the graphic state stack" end stack.pop end - + def current_state stack.last end - + def present? stack.size > 0 end @@ -38,12 +38,12 @@ def present? def empty? stack.empty? end - + end - + class GraphicState attr_accessor :color_space, :dash, :cap_style, :join_style, :line_width, :fill_color, :stroke_color - + def initialize(previous_state = nil) @color_space = previous_state ? previous_state.color_space.dup : {} @fill_color = previous_state ? previous_state.fill_color : "000000" @@ -53,24 +53,24 @@ def initialize(previous_state = nil) @join_style = previous_state ? previous_state.join_style : :miter @line_width = previous_state ? previous_state.line_width : 1 end - + def dash_setting "[#{@dash[:dash]} #{@dash[:space]}] #{@dash[:phase]} d" end end - + module Core class Page module GraphicsState - + def graphic_state stack.current_state end - + end end end - + class Document module GraphicsState @@ -93,15 +93,15 @@ module GraphicsState # text "rotated text" # end # - + def open_graphics_state add_content "q" end - + def close_graphics_state add_content "Q" end - + def save_graphics_state(graphic_state = nil) graphic_stack.save_graphic_state(graphic_state) open_graphics_state @@ -115,22 +115,22 @@ def save_graphics_state(graphic_state = nil) # restores the state to those values def restore_graphics_state if graphic_stack.empty? - raise Prawn::Errors::EmptyGraphicStateStack, - "\n You have reached the end of the graphic state stack" + raise Prawn::Errors::EmptyGraphicStateStack, + "\n You have reached the end of the graphic state stack" end - close_graphics_state + close_graphics_state graphic_stack.restore_graphic_state end - + def graphic_stack state.page.stack end - + def graphic_state save_graphics_state unless graphic_stack.current_state - graphic_stack.current_state + graphic_stack.current_state end - + end end end diff --git a/lib/prawn/document/internals.rb b/lib/prawn/document/internals.rb index 31a05ce48..f19a4ec8f 100644 --- a/lib/prawn/document/internals.rb +++ b/lib/prawn/document/internals.rb @@ -7,26 +7,26 @@ # This is free software. Please see the LICENSE and COPYING files for details. module Prawn - class Document - + class Document + # This module exposes a few low-level PDF features for those who want # to extend Prawn's core functionality. If you are not comfortable with # low level PDF functionality as defined by Adobe's specification, chances - # are you won't need anything you find here. + # are you won't need anything you find here. # - module Internals - + module Internals + # Creates a new Prawn::Reference and adds it to the Document's object - # list. The +data+ argument is anything that Prawn::PdfObject() can convert. + # list. The +data+ argument is anything that Prawn::PdfObject() can convert. + # + # Returns the identifier which points to the reference in the ObjectStore # - # Returns the identifier which points to the reference in the ObjectStore - # def ref(data) ref!(data).identifier - end + end # Like ref, but returns the actual reference instead of its identifier. - # + # # While you can use this to build up nested references within the object # tree, it is recommended to persist only identifiers, and them provide # helper methods to look up the actual references in the ObjectStore @@ -46,17 +46,17 @@ def deref(obj) end # Appends a raw string to the current page content. - # - # # Raw line drawing example: + # + # # Raw line drawing example: # x1,y1,x2,y2 = 100,500,300,550 - # pdf.add_content("%.3f %.3f m" % [ x1, y1 ]) # move + # pdf.add_content("%.3f %.3f m" % [ x1, y1 ]) # move # pdf.add_content("%.3f %.3f l" % [ x2, y2 ]) # draw path - # pdf.add_content("S") # stroke + # pdf.add_content("S") # stroke # def add_content(str) save_graphics_state if graphic_state.nil? state.page.content << str << "\n" - end + end # The Name dictionary (PDF spec 3.6.3) for this document. It is # lazily initialized, so that documents that do not need a name @@ -67,7 +67,7 @@ def names end # Returns true if the Names dictionary is in use for this document. - # + # def names? state.store.root.data[:Names] end @@ -87,8 +87,8 @@ def on_page_create(&block) state.on_page_create_callback = nil end end - - private + + private # adds a new, empty content stream to each page. Used in templating so # that imported content streams can be left pristine @@ -156,18 +156,18 @@ def render_xref(output) # Write out the PDF Trailer, as per spec 3.4.4 # def render_trailer(output) - trailer_hash = {:Size => state.store.size + 1, + trailer_hash = {:Size => state.store.size + 1, :Root => state.store.root, :Info => state.store.info} trailer_hash.merge!(state.trailer) if state.trailer output << "trailer\n" output << Prawn::Core::PdfObject(trailer_hash) << "\n" - output << "startxref\n" + output << "startxref\n" output << @xref_offset << "\n" output << "%%EOF" << "\n" end - + end end end diff --git a/lib/prawn/document/page_geometry.rb b/lib/prawn/document/page_geometry.rb index 47ca1121e..be2138267 100644 --- a/lib/prawn/document/page_geometry.rb +++ b/lib/prawn/document/page_geometry.rb @@ -8,25 +8,25 @@ module Prawn class Document - + # Dimensions pulled from PDF::Writer, rubyforge.org/projects/ruby-pdf - # + # # All of these dimensions are in PDF Points, see Prawn::Measurements for # conversion utilities. - # + # # Additionally, if the size you are after is not listed below, you can always # specify your size by passing an array of width and height to Prawn::Document.new # like: - # + # # Prawn::Document.new(:page_size => [1000, 20000]) # # The sizes below can be used by passing the appropriate string to :size: - # + # # Prawn::Document.new(:page_size => '2A0') - # + # # ===Inbuilt Sizes: - # - # + # + # # 4A0:: => 4767.87 x 6740.79 # 2A0:: => 3370.39 x 4767.87 # A0:: => 2383.94 x 3370.39 @@ -76,7 +76,7 @@ class Document # FOLIO:: => 612.00 x 936.00 # LEGAL:: => 612.00 x 1008.00 # LETTER:: => 612.00 x 792.00 - # TABLOID:: => 792.00 x 1224.00 + # TABLOID:: => 792.00 x 1224.00 # module PageGeometry diff --git a/lib/prawn/document/snapshot.rb b/lib/prawn/document/snapshot.rb index 6d45f8391..be20aa799 100644 --- a/lib/prawn/document/snapshot.rb +++ b/lib/prawn/document/snapshot.rb @@ -27,7 +27,7 @@ def rollback # +rollback+ is called or a RollbackTransaction exception is raised # inside the block, all actions taken inside the block will be rolled # back (with the exception of y-position, which you must restore - # yourself). + # yourself). # # Returns true on success, or false if the transaction was rolled back. # @@ -41,7 +41,7 @@ def transaction end private - + # Takes a current snapshot of the document's state, sufficient to # reconstruct it after it was amended. # @@ -80,7 +80,7 @@ def restore_snapshot(shot) self.bounds = BoundingBox.restore_deep_copy(shot[:bounds], self) if shot[:dests] - names.data[:Dests] = shot[:dests] + names.data[:Dests] = shot[:dests] end end diff --git a/lib/prawn/document/span.rb b/lib/prawn/document/span.rb index b7c1e8cfa..bbb0498b3 100644 --- a/lib/prawn/document/span.rb +++ b/lib/prawn/document/span.rb @@ -8,8 +8,8 @@ module Prawn class Document - # A span is a special purpose bounding box that allows a column of - # elements to be positioned relative to the margin_box. + # A span is a special purpose bounding box that allows a column of + # elements to be positioned relative to the margin_box. # # Arguments: # +width+:: The width of the column in PDF points @@ -17,17 +17,17 @@ class Document # Options: # :position:: One of :left, :center, :right or an x offset # - # This method is typically used for flowing a column of text from one + # This method is typically used for flowing a column of text from one # page to the next. # # span(350, :position => :center) do # text "Here's some centered text in a 350 point column. " * 100 # end - # + # def span(width, options={}) Prawn.verify_options [:position], options - original_position = self.y - + original_position = self.y + # FIXME: Any way to move this upstream? left_boundary = case(options[:position] || :left) when :left @@ -41,15 +41,15 @@ def span(width, options={}) else raise ArgumentError, "Invalid option for :position" end - + # we need to bust out of whatever nested bounding boxes we're in. canvas do - bounding_box([left_boundary, + bounding_box([left_boundary, margin_box.absolute_top], :width => width) do self.y = original_position yield end - end + end end end end diff --git a/lib/prawn/encoding.rb b/lib/prawn/encoding.rb index 13244d3ed..d85dc2823 100644 --- a/lib/prawn/encoding.rb +++ b/lib/prawn/encoding.rb @@ -18,7 +18,7 @@ class WinAnsi #:nodoc: .notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef - + space exclam quotedbl numbersign dollar percent ampersand quotesingle parenleft parenright asterisk plus @@ -54,7 +54,7 @@ class WinAnsi #:nodoc: quotedblright bullet endash emdash tilde trademark scaron guilsinglright oe .notdef zcaron ydieresis - + space exclamdown cent sterling currency yen brokenbar section dieresis copyright ordfeminine guillemotleft @@ -81,8 +81,8 @@ class WinAnsi #:nodoc: ocircumflex otilde odieresis divide oslash ugrave uacute ucircumflex udieresis yacute thorn ydieresis - ] - + ] + def initialize @mapping_file = "#{Prawn::DATADIR}/encodings/win_ansi.txt" load_mapping if self.class.mapping.empty? @@ -100,7 +100,7 @@ def [](codepoint) # Replace anything else with an underscore self.class.mapping[codepoint] || 95 end - + def self.mapping @mapping ||= {} end diff --git a/lib/prawn/errors.rb b/lib/prawn/errors.rb index 3e52c0470..8f44370cf 100644 --- a/lib/prawn/errors.rb +++ b/lib/prawn/errors.rb @@ -8,25 +8,25 @@ # module Prawn module Errors - + # This error is raised when Prawn::PdfObject() encounters a Ruby object it # cannot convert to PDF # FailedObjectConversion = Class.new(StandardError) - + # This error is raised when Document#page_layout is set to anything - # other than :portrait or :landscape + # other than :portrait or :landscape # - InvalidPageLayout = Class.new(StandardError) - - # This error is raised when a method requiring a current page is called + InvalidPageLayout = Class.new(StandardError) + + # This error is raised when a method requiring a current page is called # without being on a page. # NotOnPage = Class.new(StandardError) - - # This error is raised when Prawn cannot find a specified font + + # This error is raised when Prawn cannot find a specified font # - UnknownFont = Class.new(StandardError) + UnknownFont = Class.new(StandardError) # Raised when Prawn is asked to draw something into a too-small box # @@ -35,18 +35,18 @@ module Errors # Raised if group() is called with a block that is too big to be # rendered in the current context. # - CannotGroup = Class.new(StandardError) + CannotGroup = Class.new(StandardError) # This error is raised when Prawn is being used on a M17N aware VM, # and the user attempts to add text that isn't compatible with UTF-8 # to their document # IncompatibleStringEncoding = Class.new(StandardError) - + # This error is raised when Prawn encounters an unknown key in functions # that accept an options hash. This usually means there is a typo in your # code or that the option you are trying to use has a different name than - # what you have specified. + # what you have specified. # UnknownOption = Class.new(StandardError) @@ -66,30 +66,30 @@ module Errors # This error is raised when an object is attempted to be # referenced by name, but no such name is associated with an object UndefinedObjectName = Class.new(StandardError) - + # This error is raised when a required option has not been set RequiredOption = Class.new(StandardError) - + # This error is raised when a requested outline item with a given title does not exist UnknownOutlineTitle = Class.new(StandardError) # This error is raised when a block is required, but not provided BlockRequired = Class.new(StandardError) - + # This error is rased when a graphics method is called with improper arguments InvalidGraphicsPath = Class.new(StandardError) - + # This error is raised when Prawn fails to load a template file # TemplateError = Class.new(StandardError) - - # This error is raise when trying to restore a graphic state that + + # This error is raise when trying to restore a graphic state that # EmptyGraphicStateStack = Class.new(StandardError) # Raised when unrecognized content is provided for a table cell. # UnrecognizedTableContent = Class.new(StandardError) - + end -end +end diff --git a/lib/prawn/font.rb b/lib/prawn/font.rb index 89d9a3a5d..7a9143f62 100644 --- a/lib/prawn/font.rb +++ b/lib/prawn/font.rb @@ -38,7 +38,7 @@ class Document # # If a ttf font is specified, the glyphs necessary to render your document # will be embedded in the rendered PDF. This should be your preferred option - # in most cases. It will increase the size of the resulting file, but also + # in most cases. It will increase the size of the resulting file, but also # make it more portable. # # The options parameter is an optional hash providing size and style. To use @@ -49,9 +49,9 @@ def font(name=nil, options={}) return((defined?(@font) && @font) || font("Helvetica")) if name.nil? if state.pages.empty? && !state.page.in_stamp_stream? - raise Prawn::Errors::NotOnPage + raise Prawn::Errors::NotOnPage end - + new_font = find_font(name.to_s, options) if block_given? @@ -134,18 +134,18 @@ def save_font # font will be embedded twice. Since we do font subsetting, this double # embedding won't be catastrophic, just annoying. # ++ - def find_font(name, options={}) #:nodoc: - if font_families.key?(name) - family, name = name, font_families[name][options[:style] || :normal] - if name.is_a?(Hash) - options = options.merge(name) - name = options[:file] - end - end - key = "#{name}:#{options[:font] || 0}" - font_registry[key] ||= Font.load(self, name, options.merge(:family => family)) - end - + def find_font(name, options={}) #:nodoc: + if font_families.key?(name) + family, name = name, font_families[name][options[:style] || :normal] + if name.is_a?(Hash) + options = options.merge(name) + name = options[:file] + end + end + key = "#{name}:#{options[:font] || 0}" + font_registry[key] ||= Font.load(self, name, options.merge(:family => family)) + end + # Hash of Font objects keyed by names # def font_registry #:nodoc: @@ -277,7 +277,7 @@ def initialize(document,name,options={}) #:nodoc: @references = {} end - # The size of the font ascender in PDF points + # The size of the font ascender in PDF points # def ascender @ascender / 1000.0 * size diff --git a/lib/prawn/font/afm.rb b/lib/prawn/font/afm.rb index 78a9187f6..ba38609ed 100644 --- a/lib/prawn/font/afm.rb +++ b/lib/prawn/font/afm.rb @@ -205,19 +205,19 @@ def kern(string) kerned << -k << [byte] else kerned.last << byte - end + end last_byte = byte end - kerned.map { |e| + kerned.map { |e| e = (Array === e ? e.pack("C*") : e) - e.respond_to?(:force_encoding) ? e.force_encoding("Windows-1252") : e + e.respond_to?(:force_encoding) ? e.force_encoding("Windows-1252") : e } end def latin_kern_pairs_table return @kern_pairs_table if defined?(@kern_pairs_table) - + character_hash = Hash[Encoding::WinAnsi::CHARACTERS.zip((0..Encoding::WinAnsi::CHARACTERS.size).to_a)] @kern_pairs_table = @kern_pairs.inject({}) do |h,p| h[p[0].map { |n| character_hash[n] }] = p[1] @@ -230,12 +230,12 @@ def latin_glyphs_table @glyph_widths[Encoding::WinAnsi::CHARACTERS[i]].to_i end end - + private - + def unscaled_width_of(string) glyph_table = latin_glyphs_table - + string.unpack("C*").inject(0) do |s,r| s + glyph_table[r] end diff --git a/lib/prawn/font/dfont.rb b/lib/prawn/font/dfont.rb index 384150e71..955a87fec 100644 --- a/lib/prawn/font/dfont.rb +++ b/lib/prawn/font/dfont.rb @@ -11,7 +11,7 @@ module Prawn class Font class DFont < TTF - + # Returns a list of the names of all named fonts in the given dfont file. # Note that fonts are not required to be named in a dfont file, so the # list may be empty even if the file does contain fonts. Also, note that @@ -32,7 +32,7 @@ def self.font_count(file) end end - private + private def read_ttf_file TTFunk::File.from_dfont(@name, @options[:font] || 0) diff --git a/lib/prawn/font/ttf.rb b/lib/prawn/font/ttf.rb index 69e5c8171..7a7ad2aef 100644 --- a/lib/prawn/font/ttf.rb +++ b/lib/prawn/font/ttf.rb @@ -2,7 +2,7 @@ # prawn/font/ttf.rb : Implements AFM font support for Prawn # -# Copyright May 2008, Gregory Brown / James Healy / Jamis Buck +# Copyright May 2008, Gregory Brown / James Healy / Jamis Buck # All Rights Reserved. # # This is free software. Please see the LICENSE and COPYING files for details. @@ -18,7 +18,7 @@ class TTF < Font def unicode? true end - + def initialize(document, name, options={}) super @@ -26,8 +26,8 @@ def initialize(document, name, options={}) @subsets = TTFunk::SubsetCollection.new(@ttf) @attributes = {} - @bounding_boxes = {} - @char_widths = {} + @bounding_boxes = {} + @char_widths = {} @has_kerning_data = @ttf.kerning.exists? && @ttf.kerning.tables.any? @ascender = Integer(@ttf.ascent * scale_factor) @@ -42,7 +42,7 @@ def compute_width_of(string, options={}) #:nodoc: kern(string).inject(0) do |s,r| if r.is_a?(Numeric) s - r - else + else r.inject(s) { |s2, u| s2 + character_width_by_code(u) } end end * scale @@ -51,17 +51,17 @@ def compute_width_of(string, options={}) #:nodoc: s + character_width_by_code(r) end * scale end - end - + end + # The font bbox, as an array of integers - # + # def bbox @bbox ||= @ttf.bbox.map { |i| Integer(i * scale_factor) } end # Returns true if the font has kerning data, false otherwise def has_kerning_data? - @has_kerning_data + @has_kerning_data end # Perform any changes to the string that need to happen @@ -77,7 +77,7 @@ def encode_text(text,options={}) if options[:kerning] last_subset = nil - kern(text).inject([]) do |result, element| + kern(text).inject([]) do |result, element| if element.is_a?(Numeric) result.last[1] = [result.last[1]] unless result.last[1].is_a?(Array) result.last[1] << element @@ -102,7 +102,7 @@ def encode_text(text,options={}) @subsets.encode(text.unpack("U*")) end end - + def basename @basename ||= @ttf.name.postscript_name end @@ -205,7 +205,7 @@ def character_count(str) def cmap @cmap ||= @ttf.cmap.unicode.first or raise("no unicode cmap for font") end - + # +string+ must be UTF8-encoded. # # Returns an array. If an element is a numeric, it represents the @@ -241,7 +241,7 @@ def hmtx @hmtx ||= @ttf.horizontal_metrics end - def character_width_by_code(code) + def character_width_by_code(code) return 0 unless cmap[code] # Some TTF fonts have nonzero widths for \n (UTF-8 / ASCII code: 10). @@ -249,7 +249,7 @@ def character_width_by_code(code) return 0.0 if code == 10 @char_widths[code] ||= Integer(hmtx.widths[cmap[code]] * scale_factor) - end + end def scale_factor @scale ||= 1000.0 / @ttf.header.units_per_em @@ -259,7 +259,7 @@ def register(subset) temp_name = @ttf.name.postscript_name.gsub("\0","").to_sym ref = @document.ref!(:Type => :Font, :BaseFont => temp_name) - # Embed the font metrics in the document after everything has been + # Embed the font metrics in the document after everything has been # drawn, just before the document is emitted. @document.before_render { |doc| embed(ref, subset) } diff --git a/lib/prawn/graphics.rb b/lib/prawn/graphics.rb index 561c3719e..4edfbcc5b 100644 --- a/lib/prawn/graphics.rb +++ b/lib/prawn/graphics.rb @@ -82,9 +82,9 @@ def rectangle(point,width,height) x,y = map_to_absolute(point) add_content("%.3f %.3f %.3f %.3f re" % [ x, y - height, width, height ]) end - + # Draws a rounded rectangle given point, width and - # height and radius for the rounded corner. The rectangle + # height and radius for the rounded corner. The rectangle # is bounded by its upper-left corner. # # pdf.rounded_rectangle [300,300], 100, 200, 10 @@ -93,7 +93,7 @@ def rounded_rectangle(point,width,height,radius) x, y = point rounded_polygon(radius, point, [x + width, y], [x + width, y - height], [x, y - height]) end - + ########################################################### # Higher level functions: May use relative coords # @@ -138,7 +138,7 @@ def line(*points) # current y position, or the position specified by the :at option. # # # draw a line from [25, 75] to [100, 75] - # horizontal_line 25, 100, :at => 75 + # horizontal_line 25, 100, :at => 75 # def horizontal_line(x1,x2,options={}) if options[:at] @@ -146,7 +146,7 @@ def horizontal_line(x1,x2,options={}) else y1 = y - bounds.absolute_bottom end - + line(x1,y1,x2,y1) end @@ -252,7 +252,7 @@ def polygon(*points) # close the path add_content "h" end - + # Draws a rounded polygon from specified points using the radius to define bezier curves # # # draws a rounded filled in polygon @@ -268,8 +268,8 @@ def rounded_polygon(radius, *points) # close the path add_content "h" end - - + + # Creates a rounded vertex for a line segment used for building a rounded polygon # requires a radius to define bezier curve and three points. The first two points define # the line segment and the third point helps define the curve for the vertex. @@ -281,7 +281,7 @@ def rounded_vertex(radius, *points) bezier_point_2 = point_on_line((radius - radius*KAPPA), points[2], points[1]) line_to(radial_point_1) curve_to(radial_point_2, :bounds => [bezier_point_1, bezier_point_2]) - end + end # Strokes the current path. If a block is provided, yields to the block # before closing the path. See Graphics::Color for color details. @@ -298,7 +298,7 @@ def close_and_stroke yield if block_given? add_content "s" end - + # Draws and strokes a rectangle represented by the current bounding box # def stroke_bounds @@ -357,15 +357,15 @@ def method_missing(id,*args,&block) end private - + def current_line_width graphic_state.line_width end - + def current_line_width=(width) graphic_state.line_width = width end - + def write_line_width add_content("#{current_line_width} w") end @@ -382,7 +382,7 @@ def map_to_absolute!(point) def degree_to_rad(angle) angle * Math::PI / 180 end - + # Returns the coordinates for a point on a line that is a given distance away from the second # point defining the line segement def point_on_line(distance_from_end, *points) @@ -393,6 +393,6 @@ def point_on_line(distance_from_end, *points) yr = y0 + p*(y1 - y0) [xr, yr] end - + end end diff --git a/lib/prawn/graphics/cap_style.rb b/lib/prawn/graphics/cap_style.rb index b6d6d73d0..eae059409 100644 --- a/lib/prawn/graphics/cap_style.rb +++ b/lib/prawn/graphics/cap_style.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# encoding: utf-8 # cap_style.rb : Implements stroke cap styling # @@ -30,11 +30,11 @@ def cap_style(style=nil) private - def current_cap_style + def current_cap_style graphic_state.cap_style end - def current_cap_style=(style) + def current_cap_style=(style) graphic_state.cap_style = style end diff --git a/lib/prawn/graphics/color.rb b/lib/prawn/graphics/color.rb index d6853fc69..189156fa0 100644 --- a/lib/prawn/graphics/color.rb +++ b/lib/prawn/graphics/color.rb @@ -159,7 +159,7 @@ def set_color(type, color, options = {}) if options[:pattern] set_color_space type, :Pattern add_content "/#{color} #{operator}" - else + else set_color_space type, color_space(color) color = color_to_s(color) write_color(color, operator) @@ -167,7 +167,7 @@ def set_color(type, color, options = {}) end def set_fill_color(color = nil) - set_color :fill, color || current_fill_color + set_color :fill, color || current_fill_color end def set_stroke_color(color = nil) @@ -185,7 +185,7 @@ def current_color_space(type) graphic_state.color_space[type] end - def set_current_color_space(color_space, type) + def set_current_color_space(color_space, type) save_graphics_state if graphic_state.nil? graphic_state.color_space[type] = color_space end @@ -194,7 +194,7 @@ def current_fill_color graphic_state.fill_color end - def current_fill_color=(color) + def current_fill_color=(color) graphic_state.fill_color = color end diff --git a/lib/prawn/graphics/dash.rb b/lib/prawn/graphics/dash.rb index 50b6d704f..d66d58986 100644 --- a/lib/prawn/graphics/dash.rb +++ b/lib/prawn/graphics/dash.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# encoding: utf-8 # dash.rb : Implements stroke dashing # @@ -27,17 +27,17 @@ module Dash # integers or floats may be used for length and the options # # dash units are in PDF points ( 1/72 in ) - # - def dash(length=nil, options={}) + # + def dash(length=nil, options={}) return current_dash_state || undash_hash if length.nil? - self.current_dash_state = { :dash => length, - :space => options[:space] || length, + self.current_dash_state = { :dash => length, + :space => options[:space] || length, :phase => options[:phase] || 0 } write_stroke_dash end - + alias_method :dash=, :dash # Stops dashing, restoring solid stroked lines and curves @@ -46,37 +46,37 @@ def undash self.current_dash_state = undashed_setting write_stroke_dash end - + # Returns when stroke is dashed, false otherwise # def dashed? current_dash_state != undashed_setting end - + def write_stroke_dash add_content dash_setting end private - + def undashed_setting { :dash => nil, :space => nil, :phase => 0 } end - - private - - def current_dash_state=(dash_options) + + private + + def current_dash_state=(dash_options) graphic_state.dash = dash_options end - + def current_dash_state graphic_state.dash end - + def dash_setting graphic_state.dash_setting end - + end end end diff --git a/lib/prawn/graphics/join_style.rb b/lib/prawn/graphics/join_style.rb index 4c0e6d07f..4dc58b0e5 100644 --- a/lib/prawn/graphics/join_style.rb +++ b/lib/prawn/graphics/join_style.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# encoding: utf-8 # join_style.rb : Implements stroke join styling # @@ -10,7 +10,7 @@ module Prawn module Graphics module JoinStyle JOIN_STYLES = { :miter => 0, :round => 1, :bevel => 2 } - + # Sets the join style for stroked lines and curves # # style is one of :miter, :round, or :bevel @@ -25,19 +25,19 @@ def join_style(style=nil) write_stroke_join_style end - + alias_method :join_style=, :join_style private - - def current_join_style + + def current_join_style graphic_state.join_style end - def current_join_style=(style) + def current_join_style=(style) graphic_state.join_style = style end - + def write_stroke_join_style add_content "#{JOIN_STYLES[current_join_style]} j" diff --git a/lib/prawn/graphics/transformation.rb b/lib/prawn/graphics/transformation.rb index 316066aab..eeaed3965 100644 --- a/lib/prawn/graphics/transformation.rb +++ b/lib/prawn/graphics/transformation.rb @@ -1,7 +1,7 @@ # encoding: utf-8 # # transformation.rb: Implements rotate, translate, skew, scale and a generic -# transformation_matrix +# transformation_matrix # # Copyright January 2010, Michael Witrant. All Rights Reserved. # @@ -10,7 +10,7 @@ module Prawn module Graphics module Transformation - + # Rotate the user space. If a block is not provided, then you must save # and restore the graphics state yourself. # @@ -22,7 +22,7 @@ module Transformation # provided, but no block is given # # Example without a block: - # + # # save_graphics_state # rotate 30 # text "rotated text" @@ -62,7 +62,7 @@ def rotate(angle, options={}, &block) # and restore the graphics state yourself. # # Example without a block: move the text up and over 10 - # + # # save_graphics_state # translate(10, 10) # text "scaled text" @@ -82,7 +82,7 @@ def rotate(angle, options={}, &block) def translate(x, y, &block) transformation_matrix(1, 0, 0, 1, x, y, &block) end - + # Scale the user space. If a block is not provided, then you must save # and restore the graphics state yourself. # @@ -94,7 +94,7 @@ def translate(x, y, &block) # provided, but no block is given # # Example without a block: - # + # # save_graphics_state # scale 1.5 # text "scaled text" @@ -126,7 +126,7 @@ def scale(factor, options={}, &block) end end end - + # The following definition of skew would only work in a clearly # predicatable manner when if the document had no margin. don't provide # this shortcut until it behaves in a clearly understood manner @@ -137,7 +137,7 @@ def scale(factor, options={}, &block) # Math.tan(degree_to_rad(b)), # 1, 0, 0, &block) # end - + # Transform the user space (see notes for rotate regarding graphics state) # Generally, one would use the rotate, scale, translate, and skew # convenience methods instead of calling transformation_matrix directly @@ -150,7 +150,7 @@ def transformation_matrix(a, b, c, d, e, f) restore_graphics_state end end - + end end end diff --git a/lib/prawn/graphics/transparency.rb b/lib/prawn/graphics/transparency.rb index d6dcfed30..c4bef6d02 100644 --- a/lib/prawn/graphics/transparency.rb +++ b/lib/prawn/graphics/transparency.rb @@ -86,7 +86,7 @@ def opacity_dictionary_name(opacity, stroke_opacity) ) dictionary_name = "Tr#{next_opacity_dictionary_id}" - opacity_dictionary_registry[key] = { :name => dictionary_name, + opacity_dictionary_registry[key] = { :name => dictionary_name, :obj => dictionary } end diff --git a/lib/prawn/images.rb b/lib/prawn/images.rb index 53637f4b6..b7092717e 100644 --- a/lib/prawn/images.rb +++ b/lib/prawn/images.rb @@ -25,22 +25,22 @@ module Images # Options: # :at:: an array [x,y] with the location of the top left corner of the image. # :position:: One of (:left, :center, :right) or an x-offset - # :vposition:: One of (:top, :center, :center) or an y-offset + # :vposition:: One of (:top, :center, :center) or an y-offset # :height:: the height of the image [actual height of the image] # :width:: the width of the image [actual width of the image] # :scale:: scale the dimensions of the image proportionally # :fit:: scale the dimensions of the image proportionally to fit inside [width,height] - # - # Prawn::Document.generate("image2.pdf", :page_layout => :landscape) do - # pigs = "#{Prawn::DATADIR}/images/pigs.jpg" - # image pigs, :at => [50,450], :width => 450 + # + # Prawn::Document.generate("image2.pdf", :page_layout => :landscape) do + # pigs = "#{Prawn::DATADIR}/images/pigs.jpg" + # image pigs, :at => [50,450], :width => 450 # # dice = "#{Prawn::DATADIR}/images/dice.png" - # image dice, :at => [50, 450], :scale => 0.75 - # end + # image dice, :at => [50, 450], :scale => 0.75 + # end # # If only one of :width / :height are provided, the image will be scaled - # proportionally. When both are provided, the image will be stretched to + # proportionally. When both are provided, the image will be stretched to # fit the dimensions without maintaining the aspect ratio. # # @@ -54,16 +54,16 @@ module Images # # require "open-uri" # - # Prawn::Document.generate("remote_images.pdf") do + # Prawn::Document.generate("remote_images.pdf") do # image open("http://prawn.majesticseacreature.com/media/prawn_logo.png") # end # # This method returns an image info object which can be used to check the - # dimensions of an image object if needed. + # dimensions of an image object if needed. # (See also: Prawn::Images::PNG , Prawn::Images::JPG) - # + # def image(file, options={}) - Prawn.verify_options [:at, :position, :vposition, :height, + Prawn.verify_options [:at, :position, :vposition, :height, :width, :scale, :fit], options pdf_obj, info = build_image_object(file) @@ -79,10 +79,10 @@ def build_image_object(file) if file.respond_to?(:read) image_content = file.read else - raise ArgumentError, "#{file} not found" unless File.file?(file) + raise ArgumentError, "#{file} not found" unless File.file?(file) image_content = File.binread(file) end - + image_sha1 = Digest::SHA1.hexdigest(image_content) # if this image has already been embedded, just reuse it @@ -114,14 +114,14 @@ def build_image_object(file) # given. # def embed_image(pdf_obj, info, options) - # find where the image will be placed and how big it will be + # find where the image will be placed and how big it will be w,h = info.calc_image_dimensions(options) - if options[:at] - x,y = map_to_absolute(options[:at]) - else - x,y = image_position(w,h,options) - move_text_position h + if options[:at] + x,y = map_to_absolute(options[:at]) + else + x,y = image_position(w,h,options) + move_text_position h end # add a reference to the image object to the current page @@ -133,17 +133,17 @@ def embed_image(pdf_obj, info, options) instruct = "\nq\n%.3f 0 0 %.3f %.3f %.3f cm\n/%s Do\nQ" add_content instruct % [ w, h, x, y - h, label ] end - - private + + private def image_position(w,h,options) options[:position] ||= :left - - x = case options[:position] + + x = case options[:position] when :left bounds.absolute_left when :center - bounds.absolute_left + (bounds.width - w) / 2.0 + bounds.absolute_left + (bounds.width - w) / 2.0 when :right bounds.absolute_right - w when Numeric @@ -163,19 +163,19 @@ def image_position(w,h,options) determine_y_with_page_flow(h) end return [x,y] - end - + end + def determine_y_with_page_flow(h) if overruns_page?(h) start_new_page - bounds.absolute_top + bounds.absolute_top else self.y end - end - + end + def overruns_page?(h) - (self.y - h) < reference_bounds.absolute_bottom + (self.y - h) < reference_bounds.absolute_bottom end def image_registry diff --git a/lib/prawn/images/image.rb b/lib/prawn/images/image.rb index 49b805496..204c2ccdd 100644 --- a/lib/prawn/images/image.rb +++ b/lib/prawn/images/image.rb @@ -16,17 +16,17 @@ def calc_image_dimensions(options) h = options[:height] || height if options[:width] && !options[:height] - wp = w / width.to_f + wp = w / width.to_f w = width * wp h = height * wp - elsif options[:height] && !options[:width] + elsif options[:height] && !options[:width] hp = h / height.to_f w = width * hp - h = height * hp - elsif options[:scale] + h = height * hp + elsif options[:scale] w = width * options[:scale] h = height * options[:scale] - elsif options[:fit] + elsif options[:fit] bw, bh = options[:fit] bp = bw / bh.to_f ip = width / height.to_f @@ -45,7 +45,7 @@ def calc_image_dimensions(options) end def self.detect_image_format(content) - top = content[0,128] + top = content[0,128] # Unpack before comparing for JPG header, so as to avoid having to worry # about the source string encoding. We just want a byte-by-byte compare. diff --git a/lib/prawn/images/jpg.rb b/lib/prawn/images/jpg.rb index ca97b6292..9939ef42a 100644 --- a/lib/prawn/images/jpg.rb +++ b/lib/prawn/images/jpg.rb @@ -16,7 +16,7 @@ module Images class JPG < Image attr_reader :width, :height, :bits, :channels attr_accessor :scaled_width, :scaled_height - + JPEG_SOF_BLOCKS = %W(\xc0 \xc1 \xc2 \xc3 \xc5 \xc6 \xc7 \xc9 \xca \xcb \xcd \xce \xcf) JPEG_APP_BLOCKS = %W(\xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea \xeb \xec \xed \xee \xef) @@ -67,7 +67,7 @@ def build_pdf_object(document) :Width => width, :Height => height, :Length => @data.size - ) + ) # add extra decode params for CMYK images. By swapping the # min and max values from the default, we invert the colours. See diff --git a/lib/prawn/images/png.rb b/lib/prawn/images/png.rb index cc64077ca..2599322de 100644 --- a/lib/prawn/images/png.rb +++ b/lib/prawn/images/png.rb @@ -182,7 +182,7 @@ def build_pdf_object(document) # append the actual image data to the object as a stream obj << img_data - + # sort out the colours of the image if palette.empty? obj.data[:ColorSpace] = color @@ -192,7 +192,7 @@ def build_pdf_object(document) palette_obj << palette # build the color space array for the image - obj.data[:ColorSpace] = [:Indexed, + obj.data[:ColorSpace] = [:Indexed, :DeviceRGB, (palette.size / 3) -1, palette_obj] diff --git a/lib/prawn/layout.rb b/lib/prawn/layout.rb index 9aa71bf5a..9d553908f 100644 --- a/lib/prawn/layout.rb +++ b/lib/prawn/layout.rb @@ -2,9 +2,9 @@ require 'prawn/layout/grid' module Prawn - + module Errors - + # This error is raised when table data is malformed # InvalidTableData = Class.new(StandardError) diff --git a/lib/prawn/layout/grid.rb b/lib/prawn/layout/grid.rb index 0e3fdf227..a1b12362b 100644 --- a/lib/prawn/layout/grid.rb +++ b/lib/prawn/layout/grid.rb @@ -1,15 +1,15 @@ module Prawn class Document - - # Defines the grid system for a particular document. Takes the number of - # rows and columns and the width to use for the gutter as the + + # Defines the grid system for a particular document. Takes the number of + # rows and columns and the width to use for the gutter as the # keys :rows, :columns, :gutter, :row_gutter, :column_gutter # def define_grid(options = {}) @grid = Grid.new(self, options) end - - # A method that can either be used to access a particular grid on the page + + # A method that can either be used to access a particular grid on the page # or work with the grid system directly. # # @pdf.grid # Get the Grid directly @@ -22,7 +22,7 @@ def grid(*args) @grid else g1, g2 = args - if(g1.class == Array && g2.class == Array && + if(g1.class == Array && g2.class == Array && g1.length == 2 && g2.length == 2) multi_box(single_box(*g1), single_box(*g2)) else @@ -30,15 +30,15 @@ def grid(*args) end end end - - # A Grid represents the entire grid system of a Page and calculates + + # A Grid represents the entire grid system of a Page and calculates # the column width and row height of the base box. class Grid attr_reader :pdf, :columns, :rows, :gutter, :row_gutter, :column_gutter def initialize(pdf, options = {}) # :nodoc: valid_options = [:columns, :rows, :gutter, :row_gutter, :column_gutter] Prawn.verify_options valid_options, options - + @pdf = pdf @columns = options[:columns] @rows = options[:rows] @@ -49,7 +49,7 @@ def initialize(pdf, options = {}) # :nodoc: def column_width @column_width ||= subdivide(pdf.bounds.width, columns, column_gutter) end - + # Calculates the base height of boxes. def row_height @row_height ||= subdivide(pdf.bounds.height, rows, row_gutter) @@ -65,11 +65,11 @@ def show_all(color = "CCCCCC") end private - + def subdivide(total, num, gutter) (total.to_f - (gutter * (num - 1).to_f)) / num.to_f end - + def set_gutter(options) if options.has_key?(:gutter) @gutter = options[:gutter].to_f @@ -81,92 +81,92 @@ def set_gutter(options) end end end - - # A Box is a class that represents a bounded area of a page. - # A Grid object has methods that allow easy access to the coordinates of + + # A Box is a class that represents a bounded area of a page. + # A Grid object has methods that allow easy access to the coordinates of # its corners, which can be plugged into most existing prawnmethods. # class Box #:nodoc: attr_reader :pdf - + def initialize(pdf, i, j) @pdf = pdf @i = i @j = j end - - # Mostly diagnostic method that outputs the name of a box as + + # Mostly diagnostic method that outputs the name of a box as # col_num, row_num # def name "#{@i.to_s},#{@j.to_s}" end - + # :nodoc def total_height pdf.bounds.height.to_f end - + # Width of a box def width grid.column_width.to_f end - + # Height of a box def height grid.row_height.to_f end - + # Width of the gutter def gutter grid.gutter.to_f end - + # x-coordinate of left side def left @left ||= (width + grid.column_gutter) * @j.to_f end - - # x-coordinate of right side + + # x-coordinate of right side def right @right ||= left + width end - + # y-coordinate of the top def top @top ||= total_height - ((height + grid.row_gutter) * @i.to_f) end - + # y-coordinate of the bottom def bottom @bottom ||= top - height end - + # x,y coordinates of top left corner def top_left [left, top] end - - # x,y coordinates of top right corner + + # x,y coordinates of top right corner def top_right [right, top] end - + # x,y coordinates of bottom left corner def bottom_left [left, bottom] end - + # x,y coordinates of bottom right corner def bottom_right [right, bottom] end - + # Creates a standard bounding box based on the grid box. def bounding_box(&blk) pdf.bounding_box(top_left, :width => width, :height => height, &blk) end - + # Diagnostic method def show(grid_color = "CCCCCC") self.bounding_box do @@ -175,28 +175,28 @@ def show(grid_color = "CCCCCC") pdf.stroke_color = grid_color pdf.text self.name pdf.stroke_bounds - + pdf.stroke_color = original_stroke_color end end - + private def grid pdf.grid end end - + # A MultiBox is specified by 2 Boxes and spans the areas between. class MultiBox < Box #:nodoc: def initialize(pdf, b1, b2) @pdf = pdf @bs = [b1, b2] end - + def name @bs.map {|b| b.name}.join(":") end - + def total_height @bs[0].total_height end @@ -204,54 +204,54 @@ def total_height def width right_box.right - left_box.left end - + def height top_box.top - bottom_box.bottom end - + def gutter @bs[0].gutter end - + def left left_box.left end - + def right right_box.right end - + def top top_box.top end - + def bottom bottom_box.bottom end - + private def left_box @left_box ||= @bs.min {|a,b| a.left <=> b.left} end - + def right_box @right_box ||= @bs.max {|a,b| a.right <=> b.right} end - + def top_box @top_box ||= @bs.max {|a,b| a.top <=> b.top} end - + def bottom_box @bottom_box ||= @bs.min {|a,b| a.bottom <=> b.bottom} end end - + private def single_box(i, j) Box.new(self, i, j) end - + def multi_box(b1, b2) MultiBox.new(self, b1, b2) end diff --git a/lib/prawn/measurement_extensions.rb b/lib/prawn/measurement_extensions.rb index e5e6d5b78..cbbb0ee0e 100644 --- a/lib/prawn/measurement_extensions.rb +++ b/lib/prawn/measurement_extensions.rb @@ -8,8 +8,8 @@ require 'prawn/measurements' class Numeric - include Prawn::Measurements - # prawns' basic unit is PostScript-Point + include Prawn::Measurements + # prawns' basic unit is PostScript-Point # 72 points per inch def mm @@ -39,8 +39,8 @@ def yd def ft return ft2pt(self) end - + def pt return self end -end +end diff --git a/lib/prawn/measurements.rb b/lib/prawn/measurements.rb index e2fb0dfcb..450c3498e 100644 --- a/lib/prawn/measurements.rb +++ b/lib/prawn/measurements.rb @@ -3,68 +3,68 @@ # # Copyright December 2008, Florian Witteler. All Rights Reserved. # -module Prawn +module Prawn module Measurements - + # ============================================================================ #metric conversions def cm2mm(cm) return cm*10 end - + def dm2mm(dm) - return dm*100 + return dm*100 end - + def m2mm(m) return m*1000 end - + # ============================================================================ - # imperial conversions + # imperial conversions # from http://en.wikipedia.org/wiki/Imperial_units - + def ft2in(ft) return ft * 12 - end + end def yd2in(yd) return yd*36 end - + # ============================================================================ # PostscriptPoint-converisons - + def in2pt(inch) - return inch * 72 + return inch * 72 end - + def ft2pt(ft) return in2pt(ft2in(ft)) end - + def yd2pt(yd) return in2pt(yd2in(yd)) end - + def mm2pt(mm) return mm*(72 / 25.4) end - + def cm2pt(cm) return mm2pt(cm2mm(cm)) end - + def dm2pt(dm) return mm2pt(dm2mm(dm)) end - + def m2pt(m) return mm2pt(m2mm(m)) end - - def pt2mm(pt) + + def pt2mm(pt) return pt * 1 / mm2pt(1)# (25.4 / 72) end end diff --git a/lib/prawn/outline.rb b/lib/prawn/outline.rb index 28b643d06..59c63edf5 100644 --- a/lib/prawn/outline.rb +++ b/lib/prawn/outline.rb @@ -7,51 +7,51 @@ require 'forwardable' module Prawn - + class Document # Lazily instantiates an Outline object for document. This is used as point of entry # to methods to build the outline tree. def outline @outline ||= Outline.new(self) - end + end end - + # The Outline class organizes the outline tree items for the document. - # Note that the prev and parent instance variables are adjusted while navigating - # through the nested blocks. These variables along with the presence or absense + # Note that the prev and parent instance variables are adjusted while navigating + # through the nested blocks. These variables along with the presence or absense # of blocks are the primary means by which the relations for the various # OutlineItems and the OutlineRoot are set. Unfortunately, the best way to # understand how this works is to follow the method calls through a real example. # - # Some ideas for the organization of this class were gleaned from name_tree. In - # particular the way in which the OutlineItems are finally rendered into document + # Some ideas for the organization of this class were gleaned from name_tree. In + # particular the way in which the OutlineItems are finally rendered into document # objects in PdfObject through a hash. # class Outline - + extend Forwardable def_delegator :@document, :page_number - + attr_accessor :parent attr_accessor :prev attr_accessor :document attr_accessor :items - + def initialize(document) @document = document @parent = root @prev = nil @items = {} - end - + end + # Defines/Updates an outline for the document. - # The outline is an optional nested index that appears on the side of a PDF - # document usually with direct links to pages. The outline DSL is defined by nested - # blocks involving two methods: section and page; see the documentation on those methods - # for their arguments and options. Note that one can also use outline#update - # to add more sections to the end of the outline tree using the same syntax and scope. + # The outline is an optional nested index that appears on the side of a PDF + # document usually with direct links to pages. The outline DSL is defined by nested + # blocks involving two methods: section and page; see the documentation on those methods + # for their arguments and options. Note that one can also use outline#update + # to add more sections to the end of the outline tree using the same syntax and scope. # # The syntax is best illustrated with an example: # @@ -61,107 +61,107 @@ def initialize(document) # text "Page 2. More in the first Chapter. " # start_new_page # outline.define do - # section 'Chapter 1', :destination => 1, :closed => true do + # section 'Chapter 1', :destination => 1, :closed => true do # page :destination => 1, :title => 'Page 1' # page :destination => 2, :title => 'Page 2' # end - # end + # end # start_new_page do - # outline.update do + # outline.update do # section 'Chapter 2', :destination => 2, do # page :destination => 3, :title => 'Page 3' # end # end - # end + # end # def define(&block) instance_eval(&block) if block end - - alias :update :define - + + alias :update :define + # Inserts an outline section to the outline tree (see outline#define). - # Although you will probably choose to exclusively use outline#define so + # Although you will probably choose to exclusively use outline#define so # that your outline tree is contained and easy to manage, this method # gives you the option to insert sections to the outline tree at any point - # during document generation. This method allows you to add a child subsection - # to any other item at any level in the outline tree. - # Currently the only way to locate the place of entry is with the title for the + # during document generation. This method allows you to add a child subsection + # to any other item at any level in the outline tree. + # Currently the only way to locate the place of entry is with the title for the # item. If your title names are not unique consider using define_outline. # The method takes the following arguments: # title: a string that must match an outline title to add the subsection to - # position: either :first or :last(the default) where the subsection will be placed relative - # to other child elements. If you need to position your subsection in between - # other elements then consider using #insert_section_after - # block: uses the same DSL syntax as outline#define, for example: + # position: either :first or :last(the default) where the subsection will be placed relative + # to other child elements. If you need to position your subsection in between + # other elements then consider using #insert_section_after + # block: uses the same DSL syntax as outline#define, for example: # # Consider using this method inside of outline.update if you want to have the outline object # to be scoped as self (see #insert_section_after example). - # + # # go_to_page 2 # start_new_page # text "Inserted Page" - # outline.add_subsection_to :title => 'Page 2', :first do + # outline.add_subsection_to :title => 'Page 2', :first do # outline.page :destination => page_number, :title => "Inserted Page" # end - # + # def add_subsection_to(title, position = :last, &block) @parent = items[title] - raise Prawn::Errors::UnknownOutlineTitle, + raise Prawn::Errors::UnknownOutlineTitle, "\n No outline item with title: '#{title}' exists in the outline tree" unless @parent @prev = position == :first ? nil : @parent.data.last nxt = position == :first ? @parent.data.first : nil - insert_section(nxt, &block) + insert_section(nxt, &block) end - + # Inserts an outline section to the outline tree (see outline#define). - # Although you will probably choose to exclusively use outline#define so + # Although you will probably choose to exclusively use outline#define so # that your outline tree is contained and easy to manage, this method # gives you the option to insert sections to the outline tree at any point - # during document generation. Unlike outline.add_section, this method allows - # you to enter a section after any other item at any level in the outline tree. - # Currently the only way to locate the place of entry is with the title for the + # during document generation. Unlike outline.add_section, this method allows + # you to enter a section after any other item at any level in the outline tree. + # Currently the only way to locate the place of entry is with the title for the # item. If your title names are not unique consider using define_outline. # The method takes the following arguments: # title: the title of other section or page to insert new section after - # block: uses the same DSL syntax as outline#define, for example: - # + # block: uses the same DSL syntax as outline#define, for example: + # # go_to_page 2 # start_new_page # text "Inserted Page" # update_outline do - # insert_section_after :title => 'Page 2' do - # page :destination => page_number, :title => "Inserted Page" + # insert_section_after :title => 'Page 2' do + # page :destination => page_number, :title => "Inserted Page" # end # end # def insert_section_after(title, &block) @prev = items[title] - raise Prawn::Errors::UnknownOutlineTitle, + raise Prawn::Errors::UnknownOutlineTitle, "\n No outline item with title: '#{title}' exists in the outline tree" unless @prev @parent = @prev.data.parent nxt = @prev.data.next - insert_section(nxt, &block) + insert_section(nxt, &block) end - + # See outline#define above for documentation on how this is used in that context # # Adds an outine section to the outline tree. - # Although you will probably choose to exclusively use outline#define so + # Although you will probably choose to exclusively use outline#define so # that your outline tree is contained and easy to manage, this method # gives you the option to add sections to the outline tree at any point - # during document generation. When not being called from within another #section block - # the section will be added at the top level after the other root elements of the outline. - # For more flexible placement try using outline#insert_section_after and/or - # outline#add_subsection_to + # during document generation. When not being called from within another #section block + # the section will be added at the top level after the other root elements of the outline. + # For more flexible placement try using outline#insert_section_after and/or + # outline#add_subsection_to # Takes the following arguments: # title: the outline text that appears for the section. # options: destination - optional integer defining the page number for a destination link. # - currently only :FIT destination supported with link to top of page. # closed - whether the section should show its nested outline elements. - # - defaults to false. - # block: more nested subsections and/or page blocks - # + # - defaults to false. + # block: more nested subsections and/or page blocks + # # example usage: # # outline.section 'Added Section', :destination => 3 do @@ -169,49 +169,49 @@ def insert_section_after(title, &block) # end def section(title, options = {}, &block) add_outline_item(title, options, &block) - end - + end + # See Outline#define above for more documentation on how it is used in that context # # Adds a page to the outline. - # Although you will probably choose to exclusively use outline#define so + # Although you will probably choose to exclusively use outline#define so # that your outline tree is contained and easy to manage, this method also # gives you the option to add pages to the root of outline tree at any point - # during document generation. Note that the page will be added at the + # during document generation. Note that the page will be added at the # top level after the other root outline elements. For more flexible placement try # using outline#insert_section_after and/or outline#add_subsection_to. - # + # # Takes the following arguments: # options: - # title - REQUIRED. The outline text that appears for the page. + # title - REQUIRED. The outline text that appears for the page. # destination - integer defining the page number for the destination link. # currently only :FIT destination supported with link to top of page. # closed - whether the section should show its nested outline elements. # - defaults to false. # example usage: # - # outline.page :title => "Very Last Page" - # Note: this method is almost identical to section except that it does not accept a block - # thereby defining the outline item as a leaf on the outline tree structure. + # outline.page :title => "Very Last Page" + # Note: this method is almost identical to section except that it does not accept a block + # thereby defining the outline item as a leaf on the outline tree structure. def page(options = {}) if options[:title] - title = options[:title] + title = options[:title] else - raise Prawn::Errors::RequiredOption, + raise Prawn::Errors::RequiredOption, "\nTitle is a required option for page" end add_outline_item(title, options) end - - private - + + private + # The Outline dictionary (12.3.3) for this document. It is # lazily initialized, so that documents that do not have an outline # do not incur the additional overhead. def root document.state.store.root.data[:Outlines] ||= document.ref!(OutlineRoot.new) end - + def add_outline_item(title, options, &block) outline_item = create_outline_item(title, options) set_relations(outline_item) @@ -220,25 +220,25 @@ def add_outline_item(title, options, &block) block.call if block reset_parent(outline_item) end - + def create_outline_item(title, options) outline_item = OutlineItem.new(title, parent, options) if options[:destination] page_index = options[:destination] - 1 - outline_item.dest = [document.state.pages[page_index].dictionary, :Fit] + outline_item.dest = [document.state.pages[page_index].dictionary, :Fit] end outline_item.prev = prev if @prev items[title] = document.ref!(outline_item) end - + def set_relations(outline_item) prev.data.next = outline_item if prev parent.data.first = outline_item unless prev parent.data.last = outline_item end - + def increase_count counting_parent = parent while counting_parent @@ -250,19 +250,19 @@ def increase_count end end end - + def set_variables_for_block(outline_item, block) self.prev = block ? nil : outline_item self.parent = outline_item if block end - + def reset_parent(outline_item) if parent == outline_item self.prev = outline_item self.parent = outline_item.data.parent end - end - + end + def insert_section(nxt, &block) last = @parent.data.last if block @@ -271,56 +271,56 @@ def insert_section(nxt, &block) adjust_relations(nxt, last) reset_root_positioning end - + def adjust_relations(nxt, last) - if nxt + if nxt nxt.data.prev = @prev @prev.data.next = nxt @parent.data.last = last end - end - + end + def reset_root_positioning @parent = root @prev = root.data.last end - + end - + class OutlineRoot #:nodoc: attr_accessor :count, :first, :last - + def initialize @count = 0 end - + def to_hash {:Type => :Outlines, :Count => count, :First => first, :Last => last} end end - + class OutlineItem #:nodoc: attr_accessor :count, :first, :last, :next, :prev, :parent, :title, :dest, :closed - + def initialize(title, parent, options) @closed = options[:closed] @title = title @parent = parent @count = 0 end - + def to_hash hash = { :Title => title, :Parent => parent, :Count => closed ? -count : count } - [{:First => first}, {:Last => last}, {:Next => @next}, + [{:First => first}, {:Last => last}, {:Next => @next}, {:Prev => prev}, {:Dest => dest}].each do |h| unless h.values.first.nil? hash.merge!(h) end end - hash + hash end - end + end end - + diff --git a/lib/prawn/repeater.rb b/lib/prawn/repeater.rb index ef03907b5..0c366c742 100644 --- a/lib/prawn/repeater.rb +++ b/lib/prawn/repeater.rb @@ -29,10 +29,10 @@ def repeaters # :even -- repeats on even pages # some_array -- repeats on every page listed in the array # some_range -- repeats on every page included in the range - # some_lambda -- yields page number and repeats for true return values + # some_lambda -- yields page number and repeats for true return values # - # Also accepts an optional second argument for dynamic content which executes the code - # in the context of the filtered pages without using a Stamp. + # Also accepts an optional second argument for dynamic content which executes the code + # in the context of the filtered pages without using a Stamp. # # Example: # @@ -49,8 +49,8 @@ def repeaters # repeat :even do # draw_text "EVEN", :at => [0,0] # end - # - # repeat [1,2] do + # + # repeat [1,2] do # draw_text "[1,2]", :at => [100,0] # end # @@ -62,11 +62,11 @@ def repeaters # draw_text "Every third", :at => [250, 20] # end # - # 10.times do + # 10.times do # start_new_page # draw_text "A wonderful page", :at => [400,400] # end - # + # # repeat(:all, :dynamic => true) do # text page_number, :at => [500, 0] # end diff --git a/lib/prawn/security.rb b/lib/prawn/security.rb index c4e555311..2e0eb52cc 100644 --- a/lib/prawn/security.rb +++ b/lib/prawn/security.rb @@ -12,25 +12,25 @@ module Prawn class Document - + # Implements PDF encryption (password protection and permissions) as # specified in the PDF Reference, version 1.3, section 3.5 "Encryption". module Security include Prawn::Core - + # Encrypts the document, to protect confidential data or control # modifications to the document. The encryption algorithm used is # detailed in the PDF Reference 1.3, section 3.5 "Encryption", and it is # implemented by all major PDF readers. # # +options+ can contain the following: - # - # :user_password:: Password required to open the document. If + # + # :user_password:: Password required to open the document. If # this is omitted or empty, no password will be # required. The document will still be # encrypted, but anyone can read it. # - # :owner_password:: Password required to make modifications to + # :owner_password:: Password required to make modifications to # the document or change or override its # permissions. If this is set to # :random, a random password will be @@ -52,7 +52,7 @@ module Security # # :copy_contents:: Copy text and graphics from document. # - # :modify_annotations:: Add or modify text annotations and + # :modify_annotations:: Add or modify text annotations and # interactive form fields. # # == Examples @@ -66,8 +66,8 @@ module Security # both the user and the owner: # # encrypt_document :user_password => 'foo', :owner_password => 'bar' - # - # Set no passwords, grant all permissions (This is useful because the + # + # Set no passwords, grant all permissions (This is useful because the # default in some readers, if no permissions are specified, is "deny"): # # encrypt_document @@ -77,10 +77,10 @@ module Security # * The encryption used is weak; the key is password-derived and is # limited to 40 bits, due to US export controls in effect at the time # the PDF standard was written. - # + # # * There is nothing technologically requiring PDF readers to respect the # permissions embedded in a document. Many PDF readers do not. - # + # # * In short, you have no security at all against a moderately # motivated person. Don't use this for anything super-serious. This is # not a limitation of Prawn, but is rather a built-in limitation of the @@ -104,7 +104,7 @@ def encrypt_document(options={}) state.encrypt = true state.encryption_key = user_encryption_key end - + # Encrypts the given string under the given key, also requiring the # object ID and generation number of the reference. # See Algorithm 3.1. @@ -136,7 +136,7 @@ def encryption_dictionary :modify_contents => 4, :copy_contents => 5, :modify_annotations => 6 } - + FullPermissions = 0b1111_1111_1111_1111_1111_1111_1111_1111 def permissions=(perms={}) @@ -162,10 +162,10 @@ def permissions_value @permissions || FullPermissions end - PasswordPadding = + PasswordPadding = "28BF4E5E4E758A4164004E56FFFA01082E2E00B6D0683E802F0CA9FE6453697A". scan(/../).map{|x| x.to_i(16)}.pack("c*") - + # Pads or truncates a password to 32 bytes as per Alg 3.2. def pad_password(password) password = password[0, 32] diff --git a/lib/prawn/security/arcfour.rb b/lib/prawn/security/arcfour.rb index a01e9316b..da0b6c67b 100644 --- a/lib/prawn/security/arcfour.rb +++ b/lib/prawn/security/arcfour.rb @@ -16,7 +16,7 @@ def initialize(key) # 1. Allocate an 256 element array of 8 bit bytes to be used as an S-box # 2. Initialize the S-box. Fill each entry first with it's index @sbox = (0..255).to_a - + # 3. Fill another array of the same size (256) with the key, repeating # bytes as necessary. s2 = [] @@ -38,7 +38,7 @@ def initialize(key) def encrypt(string) string.unpack('c*').map{|byte| byte ^ key_byte}.pack('c*') end - + private # Produces the next byte of key material in the stream (3.2 Stream Generation) diff --git a/lib/prawn/stamp.rb b/lib/prawn/stamp.rb index 741d2f2b8..0fbcef532 100644 --- a/lib/prawn/stamp.rb +++ b/lib/prawn/stamp.rb @@ -80,7 +80,7 @@ def create_stamp(name, &block) state.page.stamp_stream(dictionary, &block) end - + private def stamp_dictionary_registry @@ -121,12 +121,12 @@ def create_stamp_dictionary(name) :stamp_dictionary => dictionary } dictionary end - + def freeze_stamp_graphics update_colors write_line_width write_stroke_cap_style - write_stroke_join_style + write_stroke_join_style write_stroke_dash end diff --git a/lib/prawn/table.rb b/lib/prawn/table.rb index a8c542576..8f9a3e8d6 100644 --- a/lib/prawn/table.rb +++ b/lib/prawn/table.rb @@ -16,7 +16,7 @@ module Prawn class Document - + # Set up and draw a table on this document. A block can be given, which will # be run after cell setup but before layout and drawing. # @@ -50,7 +50,7 @@ def make_table(data, options={}, &block) # Produces a text cell. This is the most common usage. # Prawn::Table::Cell:: # If you have already built a Cell or have a custom subclass of Cell you - # want to use in a table, you can pass through Cell objects. + # want to use in a table, you can pass through Cell objects. # Prawn::Table:: # Creates a subtable (a table within a cell). You can use # Prawn::Document#make_table to create a table for use as a subtable @@ -77,7 +77,7 @@ def make_table(data, options={}, &block) # (for styling and other row-specific options) always indexes based on # your data array. Whether or not you have a header, row(n) always refers # to the nth element (starting from 0) of the +data+ array. - # +column_widths+:: + # +column_widths+:: # Sets widths for individual columns. Manually setting widths can give # better results than letting Prawn guess at them, as Prawn's algorithm # for defaulting widths is currently pretty boneheaded. If you experience @@ -100,7 +100,7 @@ def make_table(data, options={}, &block) # pdf.table(data) do |table| # table.rows(1..3).width = 72 # end - # + # # As with Prawn::Document#initialize, if the block has no arguments, it will # be evaluated in the context of the object itself. The above code could be # rewritten as: @@ -109,7 +109,7 @@ def make_table(data, options={}, &block) # rows(1..3).width = 72 # end # - class Table + class Table # Set up a table on the given document. Arguments: # @@ -136,7 +136,7 @@ def initialize(data, document, options={}, &block) set_column_widths set_row_heights position_cells - end + end # Number of rows in the table. # @@ -164,9 +164,9 @@ def width # Sets column widths for the table. The argument can be one of the following # types: # - # +Array+:: + # +Array+:: # [w0, w1, w2, ...] (specify a width for each column) - # +Hash+:: + # +Hash+:: # {0 => w0, 1 => w1, ...} (keys are column names, values are # widths) # +Numeric+:: @@ -287,14 +287,14 @@ def draw offset = @pdf.y - cell.y started_new_page_at_row = cell.row end - + # Don't modify cell.x / cell.y here, as we want to reuse the original # values when re-inking the table. #draw should be able to be called # multiple times. x, y = cell.x, cell.y - y += offset + y += offset - # Translate coordinates to the bounds we are in, since drawing is + # Translate coordinates to the bounds we are in, since drawing is # relative to the cursor, not ref_bounds. x += @pdf.bounds.left_side - @pdf.bounds.absolute_left y -= @pdf.bounds.absolute_bottom @@ -376,7 +376,7 @@ def make_cells(data) assert_proper_table_data(data) cells = [] - + @row_length = data.length @column_length = data.map{ |r| r.length }.max @@ -442,7 +442,7 @@ def natural_width # values that will be used to ink the table. # def set_column_widths - column_widths.each_with_index do |w, col_num| + column_widths.each_with_index do |w, col_num| column(col_num).width = w end end @@ -459,7 +459,7 @@ def set_row_heights # def position_cells # Calculate x- and y-positions as running sums of widths / heights. - x_positions = column_widths.inject([0]) { |ary, x| + x_positions = column_widths.inject([0]) { |ary, x| ary << (ary.last + x); ary }[0..-2] x_positions.each_with_index { |x, i| column(i).x = x } diff --git a/lib/prawn/table/cell.rb b/lib/prawn/table/cell.rb index dab6e936f..d9f39daed 100644 --- a/lib/prawn/table/cell.rb +++ b/lib/prawn/table/cell.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# encoding: utf-8 # cell.rb: Table cell drawing. # @@ -10,7 +10,7 @@ module Prawn class Document - # Instantiates and draws a cell on the document. + # Instantiates and draws a cell on the document. # # cell(:content => "Hello world!", :at => [12, 34]) # @@ -21,9 +21,9 @@ def cell(options={}) cell.draw cell end - - # Set up, but do not draw, a cell. Useful for creating cells with - # formatting options to be inserted into a Table. Call +draw+ on the + + # Set up, but do not draw, a cell. Useful for creating cells with + # formatting options to be inserted into a Table. Call +draw+ on the # resulting Cell to ink it. # # See the documentation on Prawn::Cell for details on the arguments. @@ -35,7 +35,7 @@ def make_cell(content, options={}) end class Table - + # A Cell is a rectangular area of the page into which content is drawn. It # has a framework for sizing itself and adding padding and simple styling. # There are several standard Cell subclasses that handle things like text, @@ -55,12 +55,12 @@ class Cell attr_reader :padding # If provided, the minimum width that this cell will permit. - # + # def min_width set_width_constraints @min_width end - + # If provided, the maximum width that this cell can be drawn in. # def max_width @@ -89,7 +89,7 @@ def max_width # "Data" section of the Prawn::Table documentation for details on cellable # objects. # - attr_accessor :content + attr_accessor :content # The background color, if any, for this cell. Specified in HTML RGB # format, e.g., "ccffff". The background is drawn under the whole cell, @@ -105,7 +105,7 @@ def self.make(pdf, content, options={}) at = options.delete(:at) || [0, pdf.cursor] content = content.to_s if content.nil? || content.kind_of?(Numeric) || content.kind_of?(Date) - + if content.is_a?(Hash) if img = content[:image] return Cell::Image.new(pdf, at, content) @@ -203,7 +203,7 @@ def content_width # constraints. Must be implemented in subclasses. # def natural_content_width - raise NotImplementedError, + raise NotImplementedError, "subclasses must implement natural_content_width" end @@ -221,7 +221,7 @@ def content_height if @height # manually set return @height - padding_top - padding_bottom end - + natural_content_height end @@ -229,7 +229,7 @@ def content_height # constraints. Must be implemented in subclasses. # def natural_content_height - raise NotImplementedError, + raise NotImplementedError, "subclasses must implement natural_content_height" end @@ -264,7 +264,7 @@ def self.draw_cells(cells) # def draw_bounded_content(pt) @pdf.float do - @pdf.bounding_box([pt[0] + padding_left, pt[1] - padding_top], + @pdf.bounding_box([pt[0] + padding_left, pt[1] - padding_top], :width => content_width + FPTolerance, :height => content_height + FPTolerance) do draw_content @@ -324,7 +324,7 @@ def padding=(pad) def padding_top @padding[0] end - + def padding_top=(val) @padding[0] = val end @@ -332,7 +332,7 @@ def padding_top=(val) def padding_right @padding[1] end - + def padding_right=(val) @padding[1] = val end @@ -340,7 +340,7 @@ def padding_right=(val) def padding_bottom @padding[2] end - + def padding_bottom=(val) @padding[2] = val end @@ -348,7 +348,7 @@ def padding_bottom=(val) def padding_left @padding[3] end - + def padding_left=(val) @padding[3] = val end diff --git a/lib/prawn/table/cell/image.rb b/lib/prawn/table/cell/image.rb index 589dc522a..4482b5d51 100644 --- a/lib/prawn/table/cell/image.rb +++ b/lib/prawn/table/cell/image.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# encoding: utf-8 # image.rb: Table image cells. # diff --git a/lib/prawn/table/cell/in_table.rb b/lib/prawn/table/cell/in_table.rb index 642b900bb..8ee0e64e0 100644 --- a/lib/prawn/table/cell/in_table.rb +++ b/lib/prawn/table/cell/in_table.rb @@ -3,7 +3,7 @@ # Accessors for using a Cell inside a Table. module Prawn - class Table + class Table class Cell # This module extends Cell objects when they are used in a table (as @@ -15,7 +15,7 @@ module InTable # Row number (0-based). # attr_accessor :row - + # Column number (0-based). # attr_accessor :column diff --git a/lib/prawn/table/cell/subtable.rb b/lib/prawn/table/cell/subtable.rb index fd90c26f6..4403db995 100644 --- a/lib/prawn/table/cell/subtable.rb +++ b/lib/prawn/table/cell/subtable.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# encoding: utf-8 # subtable.rb: Yo dawg. # @@ -47,7 +47,7 @@ def max_width @subtable.cells.max_width end - # Proxied to subtable. + # Proxied to subtable. # def natural_content_height @subtable.cells.height diff --git a/lib/prawn/table/cell/text.rb b/lib/prawn/table/cell/text.rb index f51288a6e..175756933 100644 --- a/lib/prawn/table/cell/text.rb +++ b/lib/prawn/table/cell/text.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# encoding: utf-8 # text.rb: Text table cells. # @@ -64,10 +64,10 @@ def natural_content_height # Draws the text content into its bounding box. # def draw_content - with_font do + with_font do @pdf.move_down((@pdf.font.line_gap + @pdf.font.descender)/2) with_text_color do - text_box(:width => content_width + FPTolerance, + text_box(:width => content_width + FPTolerance, :height => content_height + FPTolerance, :at => [0, @pdf.cursor]).render end @@ -103,7 +103,7 @@ def with_text_color ensure @pdf.fill_color(old_color) end - + def text_box(extra_options={}) if @text_options[:inline_format] options = @text_options.dup diff --git a/lib/prawn/table/cells.rb b/lib/prawn/table/cells.rb index ba5e2d773..a79ed8688 100644 --- a/lib/prawn/table/cells.rb +++ b/lib/prawn/table/cells.rb @@ -60,7 +60,7 @@ def rows(row_spec) row_spec.include?(c.row) : row_spec === c.row }) end alias_method :row, :rows - + # Limits selection to the given column or columns. +col_spec+ can be # anything that responds to the === operator selecting a set of 0-based # column numbers; most commonly a number or a range. @@ -72,7 +72,7 @@ def columns(col_spec) index_cells unless @indexed col_spec = transform_spec(col_spec, @column_count) Cells.new(@columns[col_spec] ||= select { |c| - col_spec.respond_to?(:include?) ? + col_spec.respond_to?(:include?) ? col_spec.include?(c.column) : col_spec === c.column }) end alias_method :column, :columns @@ -88,7 +88,7 @@ def filter(&block) # Retrieves a cell based on its 0-based row and column. Returns an # individual Cell, not a Cells collection. - # + # # table.cells[0, 0].content # => "First cell content" # def [](row, col) @@ -117,8 +117,8 @@ def style(options={}, &block) # def width column_widths = {} - each do |cell| - column_widths[cell.column] = + each do |cell| + column_widths[cell.column] = [column_widths[cell.column], cell.width].compact.max end column_widths.values.inject(0) { |sum, width| sum + width } @@ -128,8 +128,8 @@ def width # def min_width column_min_widths = {} - each do |cell| - column_min_widths[cell.column] = + each do |cell| + column_min_widths[cell.column] = [column_min_widths[cell.column], cell.min_width].compact.max end column_min_widths.values.inject(0) { |sum, width| sum + width } @@ -139,8 +139,8 @@ def min_width # def max_width column_max_widths = {} - each do |cell| - column_max_widths[cell.column] = + each do |cell| + column_max_widths[cell.column] = [column_max_widths[cell.column], cell.max_width].compact.min end column_max_widths.values.inject(0) { |sum, width| sum + width } @@ -150,8 +150,8 @@ def max_width # def height row_heights = {} - each do |cell| - row_heights[cell.row] = + each do |cell| + row_heights[cell.row] = [row_heights[cell.row], cell.height].compact.max end row_heights.values.inject(0) { |sum, width| sum + width } @@ -166,13 +166,13 @@ def method_missing(id, *args, &block) end protected - + # Defers indexing until rows() or columns() is actually called on the # Cells object. Without this, we would needlessly index the leaf nodes of # the object graph, the ones that are only there to be iterated over. # # Make sure to call this before using @rows or @columns. - # + # def index_cells @rows = {} @columns = {} diff --git a/lib/prawn/text.rb b/lib/prawn/text.rb index 6708650bb..defd22f04 100644 --- a/lib/prawn/text.rb +++ b/lib/prawn/text.rb @@ -27,7 +27,7 @@ module Text # method to use. If, instead, if you want to place bounded text outside of # the flow of a document (for captions, labels, charts, etc.), use Text::Box # or its convenience method text_box. - # + # # Draws text on the page. Prawn attempts to wrap the text to fit within your # current bounding box (or margin_box if no bounding box is being used). # Text will flow onto the next page when it reaches the bottom of the @@ -49,21 +49,21 @@ module Text # entire document, set default_kerning = false for that document # # === Text Positioning Details - # + # # The text is positioned at font.ascender below the baseline, # making it easy to use this method within bounding boxes and spans. # # == Encoding # # Note that strings passed to this function should be encoded as UTF-8. - # If you get unexpected characters appearing in your rendered document, + # If you get unexpected characters appearing in your rendered document, # check this. # # If the current font is a built-in one, although the string must be # encoded as UTF-8, only characters that are available in WinAnsi # are allowed. # - # If an empty box is rendered to your PDF instead of the character you + # If an empty box is rendered to your PDF instead of the character you # wanted it usually means the current font doesn't include that character. # # == Options (default values marked in []) @@ -98,7 +98,7 @@ module Text # where the value of the anchor attribute is the name of a # destination that has already been or will be registered # using Prawn::Core::Destinations#add_dest. A clickable link - # will be created to that destination. + # will be created to that destination. # Note that you must explicitly underline and color using the # appropriate tags if you which to draw attention to the link # @@ -143,7 +143,7 @@ module Text # text should render with the fill color, stroke color or # both. See the comments to text_rendering_mode() to see # a list of valid options. [0] - # + # # == Exceptions # # Raises ArgumentError if :at option included @@ -190,7 +190,7 @@ def formatted_text(array, options={}) options = inspect_options_for_text(options.dup) if color = options.delete(:color) - array = array.map do |fragment| + array = array.map do |fragment| fragment[:color] ? fragment : fragment.merge(:color => color) end end @@ -223,7 +223,7 @@ def formatted_text(array, options={}) # Draws text on the page, beginning at the point specified by the :at option # the string is assumed to be pre-formatted to properly fit the page. - # + # # pdf.draw_text "Hello World", :at => [100,100] # pdf.draw_text "Goodbye World", :at => [50,50], :size => 16 # @@ -245,14 +245,14 @@ def formatted_text(array, options={}) # == Encoding # # Note that strings passed to this function should be encoded as UTF-8. - # If you get unexpected characters appearing in your rendered document, + # If you get unexpected characters appearing in your rendered document, # check this. # # If the current font is a built-in one, although the string must be # encoded as UTF-8, only characters that are available in WinAnsi # are allowed. # - # If an empty box is rendered to your PDF instead of the character you + # If an empty box is rendered to your PDF instead of the character you # wanted it usually means the current font doesn't include that character. # # == Options (default values marked in []) diff --git a/lib/prawn/text/box.rb b/lib/prawn/text/box.rb index c29d0f928..72d606970 100644 --- a/lib/prawn/text/box.rb +++ b/lib/prawn/text/box.rb @@ -17,14 +17,14 @@ module Text # == Encoding # # Note that strings passed to this function should be encoded as UTF-8. - # If you get unexpected characters appearing in your rendered document, + # If you get unexpected characters appearing in your rendered document, # check this. # # If the current font is a built-in one, although the string must be # encoded as UTF-8, only characters that are available in WinAnsi # are allowed. # - # If an empty box is rendered to your PDF instead of the character you + # If an empty box is rendered to your PDF instead of the character you # wanted it usually means the current font doesn't include that character. # # == Options (default values marked in []) @@ -67,7 +67,7 @@ module Text # :valign:: # :top, :center, or :bottom. Vertical # alignment within the bounding box [:top] - # + # # :rotate:: # number. The angle to rotate the text # :rotate_around:: @@ -119,7 +119,7 @@ def text_box(string, options={}) end # Generally, one would use the Prawn::Text#text_box convenience - # method. However, using Text::Box.new in conjunction with + # method. However, using Text::Box.new in conjunction with # #render(:dry_run=> true) enables one to do look-ahead calculations prior # to placing text on the page, or to determine how much vertical space was # consumed by the printed text diff --git a/lib/prawn/text/formatted/box.rb b/lib/prawn/text/formatted/box.rb index 7d503bacc..355f35a90 100644 --- a/lib/prawn/text/formatted/box.rb +++ b/lib/prawn/text/formatted/box.rb @@ -139,7 +139,7 @@ def line_gap # Example (see Prawn::Text::Core::Formatted::Wrap for what is required # of the wrap method if you want to override the default wrapping # algorithm): - # + # # # module MyWrap # @@ -273,7 +273,7 @@ def available_width end # The height actually used during the previous render - # + # def height return 0 if @baseline_y.nil? || @descender.nil? (@baseline_y - @descender).abs @@ -540,7 +540,7 @@ def draw_fragment_overlay_styles(fragment) if underline @document.stroke_line(fragment.underline_points) end - + strikethrough = fragment.styles.include?(:strikethrough) if strikethrough @document.stroke_line(fragment.strikethrough_points) diff --git a/lib/prawn/text/formatted/parser.rb b/lib/prawn/text/formatted/parser.rb index 8b745a9eb..d20666994 100644 --- a/lib/prawn/text/formatted/parser.rb +++ b/lib/prawn/text/formatted/parser.rb @@ -125,7 +125,7 @@ def self.array_from_tokens(tokens) fonts = [] sizes = [] character_spacings = [] - + while token = tokens.shift case token when "", "" @@ -179,7 +179,7 @@ def self.array_from_tokens(tokens) # intend to support rgb="#ffffff" or rgb='#ffffff', # r="255" g="255" b="255" or r='255' g='255' b='255', # and c="100" m="100" y="100" k="100" or - # c='100' m='100' y='100' k='100' + # c='100' m='100' y='100' k='100' # color = { :rgb => "#ffffff" } # color = { :r => 255, :g => 255, :b => 255 } # color = { :c => 100, :m => 100, :y => 100, :k => 100 } diff --git a/manual/basic_concepts/adding_pages.rb b/manual/basic_concepts/adding_pages.rb index 953bdb261..8aa449cb1 100644 --- a/manual/basic_concepts/adding_pages.rb +++ b/manual/basic_concepts/adding_pages.rb @@ -20,8 +20,8 @@ Prawn::Example.generate(filename) do text "We are still on the initial page for this example. Now I'll ask " + "Prawn to gently start a new page. Please follow me to the next page." - + start_new_page - + text "See. We've left the previous page behind." end diff --git a/manual/basic_concepts/basic_concepts.rb b/manual/basic_concepts/basic_concepts.rb index e2ddcebf9..0224c262f 100644 --- a/manual/basic_concepts/basic_concepts.rb +++ b/manual/basic_concepts/basic_concepts.rb @@ -14,15 +14,15 @@ "adding_pages", "measurement" ] - + ) do - + text "This chapter covers the minimum amount of functionality you'll need to start using Prawn. - + If you are new to Prawn this is the first chapter to read. Once you are comfortable with the concepts shown here you might want to check the Basics section of the Graphics, Bounding Box and Text sections. - + The examples show:" - + list( "How to create new pdf documents in every possible way", "Where the origin for the document coordinates is. What are Bounding Boxes and how they interact with the origin", "How the cursor behaves", diff --git a/manual/basic_concepts/cursor.rb b/manual/basic_concepts/cursor.rb index 2f8146ea0..6dc816aa5 100644 --- a/manual/basic_concepts/cursor.rb +++ b/manual/basic_concepts/cursor.rb @@ -18,16 +18,16 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + text "the cursor is here: #{cursor}" text "now it is here: #{cursor}" - + move_down 200 text "on the first move the cursor went down to: #{cursor}" - + move_up 100 text "on the second move the cursor went up to: #{cursor}" - + move_cursor_to 50 text "on the last move the cursor went directly to: #{cursor}" end diff --git a/manual/basic_concepts/measurement.rb b/manual/basic_concepts/measurement.rb index 96146f18e..aff33ee0d 100644 --- a/manual/basic_concepts/measurement.rb +++ b/manual/basic_concepts/measurement.rb @@ -17,7 +17,7 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do require "prawn/measurement_extensions" - + [:mm, :cm, :dm, :m, :in, :yd, :ft].each do |measurement| text "1 #{measurement} in PDF Points: #{1.send(measurement)} pt" move_down 5.mm diff --git a/manual/basic_concepts/origin.rb b/manual/basic_concepts/origin.rb index f189d43c4..d24820fbd 100644 --- a/manual/basic_concepts/origin.rb +++ b/manual/basic_concepts/origin.rb @@ -27,9 +27,9 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + stroke_circle [0, 0], 10 - + bounding_box [100, 300], :width => 300, :height => 200 do stroke_bounds stroke_circle [0, 0], 10 diff --git a/manual/basic_concepts/other_cursor_helpers.rb b/manual/basic_concepts/other_cursor_helpers.rb index 4493b43d5..b18848b32 100644 --- a/manual/basic_concepts/other_cursor_helpers.rb +++ b/manual/basic_concepts/other_cursor_helpers.rb @@ -16,18 +16,18 @@ 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 diff --git a/manual/bounding_box/bounding_box.rb b/manual/bounding_box/bounding_box.rb index 74ab0c95d..e69acc5e5 100644 --- a/manual/bounding_box/bounding_box.rb +++ b/manual/bounding_box/bounding_box.rb @@ -19,10 +19,10 @@ ] ] ] - + ) do text "Bounding boxes are the basic containers for structuring the content flow. Even being low level building blocks sometimes their simplicity is very welcome. - + The examples show:" list( "How to create bounding boxes with specific dimensions", diff --git a/manual/bounding_box/bounds.rb b/manual/bounding_box/bounds.rb index 7a5887864..263f5695e 100644 --- a/manual/bounding_box/bounds.rb +++ b/manual/bounding_box/bounds.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # The bounds method returns the current bounding box. This is # useful because the Prawn::BoundinBox exposes some nice boundary # helpers. @@ -27,19 +27,19 @@ def print_coordinates text "bottom: #{bounds.bottom}" text "left: #{bounds.left}" text "right: #{bounds.right}" - + move_down 10 - + text "absolute top: #{sprintf "%.2f", bounds.absolute_top}" text "absolute bottom: #{sprintf "%.2f", bounds.absolute_bottom}" text "absolute left: #{sprintf "%.2f", bounds.absolute_left}" text "absolute right: #{sprintf "%.2f", bounds.absolute_right}" end - + text "Margin box bounds:" move_down 5 print_coordinates - + bounding_box([250, cursor + 140], :width => 200, :height => 150) do text "This bounding box bounds:" move_down 5 diff --git a/manual/bounding_box/canvas.rb b/manual/bounding_box/canvas.rb index e975dd4f5..cf3385b22 100644 --- a/manual/bounding_box/canvas.rb +++ b/manual/bounding_box/canvas.rb @@ -1,5 +1,5 @@ # 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. diff --git a/manual/bounding_box/creation.rb b/manual/bounding_box/creation.rb index f8db37cf1..823ec7390 100644 --- a/manual/bounding_box/creation.rb +++ b/manual/bounding_box/creation.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # If you've read the basic concepts examples you probably know that the origin # of a page is on the bottom left corner and that the content flows from top to # bottom. @@ -17,7 +17,7 @@ Prawn::Example.generate(filename) do bounding_box([200, cursor - 100], :width => 200, :height => 100) do text "Just your regular bounding box" - + transparent(0.5) { stroke_bounds } end end diff --git a/manual/bounding_box/indentation.rb b/manual/bounding_box/indentation.rb index 9066b06ed..e280b826f 100644 --- a/manual/bounding_box/indentation.rb +++ b/manual/bounding_box/indentation.rb @@ -1,11 +1,11 @@ # encoding: utf-8 -# +# # Sometimes you just need to indent a portion of the contents of a bounding box, and # using a nested bounding box is just pure overkill. The indent # method is what you might need. # # Just provide a number for it to indent all content generated inside the -# block. +# block. # require File.expand_path(File.join(File.dirname(__FILE__), %w[.. example_helper])) @@ -17,28 +17,28 @@ text "Some indentation inside an indent block." end move_down 20 - + bounding_box([50, cursor], :width => 400, :height => cursor) do transparent(0.5) { stroke_bounds } - + move_down 10 text "No indentation inside this bounding box." indent(40) do text "Inside an indent block. And so is the following line:" - + stroke_horizontal_rule end move_down 10 text "No indentation" - + move_down 20 indent(60) do text "Another indent block." - + bounding_box([0, cursor], :width => 200) do text "Note that this bounding box coordinates are relative to the " + "indent block" - + transparent(0.5) { stroke_bounds } end end diff --git a/manual/bounding_box/nesting.rb b/manual/bounding_box/nesting.rb index e36ff4fa0..f1500125c 100644 --- a/manual/bounding_box/nesting.rb +++ b/manual/bounding_box/nesting.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # Normally when we provide the top left corner of a bounding box we # express the coordinates are relative to the margin box. This is not the # case when we have nested bounding boxes. Once nested the inner bounding box @@ -18,26 +18,26 @@ def box_content(string) text "#{string} height" transparent(0.5) { stroke_bounds } end - + gap = 20 bounding_box([50, cursor], :width => 400, :height => 200) do box_content("Fixed") - + bounding_box([gap, cursor - gap], :width => 300) do text "Stretchy height" - + bounding_box([gap, bounds.top - gap], :width => 100) do text "Stretchy height" transparent(0.5) { dash(1); stroke_bounds; undash } end - + bounding_box([gap * 7, bounds.top - gap], :width => 100, :height => 50) do box_content("Fixed") end - + transparent(0.5) { dash(1); stroke_bounds; undash } end - + bounding_box([gap, cursor - gap], :width => 300, :height => 50) do box_content("Fixed") end diff --git a/manual/bounding_box/stretchy.rb b/manual/bounding_box/stretchy.rb index 4f3e5ce2a..f539a47de 100644 --- a/manual/bounding_box/stretchy.rb +++ b/manual/bounding_box/stretchy.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # Bounding Boxes accept an optional :height parameter. Unless it # is provided the bounding box will be stretchy. It will expand the height to # fit all content generated inside it. @@ -13,19 +13,19 @@ bounding_box([0, y_position], :width => 200, :height => 100) do text "This bounding box has a height of 100. If this text gets too large " + "it will flow to the next page." - + transparent(0.5) { stroke_bounds } end - + bounding_box([300, y_position], :width => 200) do text "This bounding box has variable height. No matter how much text is " + "written here, the height will expand to fit." - + text " _" * 100 - + text " *" * 100 - + transparent(0.5) { stroke_bounds } end - + end diff --git a/manual/document_and_page_options/background.rb b/manual/document_and_page_options/background.rb index bf6602e26..063f39efa 100644 --- a/manual/document_and_page_options/background.rb +++ b/manual/document_and_page_options/background.rb @@ -2,7 +2,7 @@ # # Pass an image path to the :background option and it will be used # as the background for all pages. -# This option can only be used on document creation. +# This option can only be used on document creation. # require File.expand_path(File.join(File.dirname(__FILE__), %w[.. example_helper])) @@ -17,7 +17,7 @@ move_down font.height * 2 - text "Here is my text explaning this report. " * 20, + text "Here is my text explaning this report. " * 20, :size => 12, :align => :left, :leading => 2 move_down font.height diff --git a/manual/document_and_page_options/document_and_page_options.rb b/manual/document_and_page_options/document_and_page_options.rb index 447f463d1..dbc44531e 100644 --- a/manual/document_and_page_options/document_and_page_options.rb +++ b/manual/document_and_page_options/document_and_page_options.rb @@ -12,7 +12,7 @@ {: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. diff --git a/manual/document_and_page_options/metadata.rb b/manual/document_and_page_options/metadata.rb index b863160c8..38b1509d8 100644 --- a/manual/document_and_page_options/metadata.rb +++ b/manual/document_and_page_options/metadata.rb @@ -12,12 +12,12 @@ :Author => "John Doe", :Subject => "My Subject", :Keywords => "test metadata ruby pdf dry", - :Creator => "ACME Soft App", + :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 non standard properties like 'Grok'." end diff --git a/manual/document_and_page_options/page_margins.rb b/manual/document_and_page_options/page_margins.rb index fe62940f7..7ce473ab2 100644 --- a/manual/document_and_page_options/page_margins.rb +++ b/manual/document_and_page_options/page_margins.rb @@ -20,7 +20,7 @@ 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 " + @@ -28,10 +28,10 @@ stroke_bounds start_new_page(:margin => 50) - text "50 pts margins. Using the margin option will reset previous specific " + + 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 diff --git a/manual/document_and_page_options/page_size.rb b/manual/document_and_page_options/page_size.rb index a7196fda8..933e33f43 100644 --- a/manual/document_and_page_options/page_size.rb +++ b/manual/document_and_page_options/page_size.rb @@ -22,12 +22,12 @@ 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 diff --git a/manual/example_helper.rb b/manual/example_helper.rb index 4c601c503..141d54754 100644 --- a/manual/example_helper.rb +++ b/manual/example_helper.rb @@ -14,7 +14,7 @@ Prawn.debug = true module Prawn - + # The Prawn::Example class holds all the helper methods used to generate the # Prawn by example manual. # @@ -39,7 +39,7 @@ class Example < Prawn::Document def load_package(package) load_file(package, package) end - + # Loads a page with outline support. Used on the manual. # def load_page(page, page_name = nil) @@ -57,7 +57,7 @@ def load_file(package, file) data = read_file(package, "#{file}.rb") eval extract_generate_block(data) end - + # Create a package cover and load the examples provided in examples_outline # with outline support. Accepts an optional block to be used as the cover # content. Used by the package files. @@ -65,7 +65,7 @@ def load_file(package, file) def build_package(package, examples_outline, &block) title = package.gsub("_", " ").capitalize header(title) - + if block_given? instance_eval(&block) end @@ -73,51 +73,51 @@ def build_package(package, examples_outline, &block) outline.define do section(title, :destination => page_number, :closed => true) end - + build_package_examples(package, title, examples_outline) end - + # Recursively iterates through the examples subsections or pages according # to the examples_outline. # def build_package_examples(package, title, examples_outline) examples_outline.each do |example_or_subsection| - + case example_or_subsection when Array - - outline.add_subsection_to(title) do + + outline.add_subsection_to(title) do outline.section(example_or_subsection.first, :closed => true) end - + build_package_examples(package, example_or_subsection.first, example_or_subsection.last) - + when Hash example = example_or_subsection.delete(:name) load_example(package, "#{example}.rb", example_or_subsection) - - outline.add_subsection_to(title) do + + outline.add_subsection_to(title) do outline.page(:destination => page_number, :title => example.gsub("_", " ").capitalize) end - + else initial_page = page_number + 1 load_example(package, "#{example_or_subsection}.rb") - - outline.add_subsection_to(title) do + + outline.add_subsection_to(title) do outline.page(:destination => initial_page, :title => example_or_subsection.gsub("_", " ").capitalize) end end end end - + # Starts a new page to load an example from a given package. Renders an # introductory text and the example source. Available boolean options are: - # + # # :eval_source:: Evals the example source code (default: true) # :full_source:: Extract the full source code when true. Extract # only the code between the generate block when false (default: false) @@ -126,21 +126,21 @@ def load_example(package, example, options={}) options = { :eval_source => true, :full_source => false }.merge(options) - + data = read_file(package, example) - + if options[:full_source] example_source = extract_full_source(data) - else + else example_source = extract_generate_block(data) end - + start_new_page - + text("#{package}/#{example}", :size => 20, :inline_format => true) move_down 10 - + text(extract_introduction_text(data), :inline_format => true) kai_file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf" @@ -156,13 +156,13 @@ def load_example(package, example, options={}) text(example_source.gsub(' ', Prawn::Text::NBSP), :fallback_fonts => ["DejaVu", "Kai"]) end - + if options[:eval_source] move_down 10 dash(3) stroke_horizontal_line(-36, bounds.width + 36) undash - + move_down 10 begin eval example_source @@ -174,7 +174,7 @@ def load_example(package, example, options={}) end end end - + # Returns the data read from a file in a given package # def read_file(package, file) @@ -188,7 +188,7 @@ def read_file(package, file) end data end - + # Render a page header. Used on the manual lone pages and package # introductory pages # @@ -198,17 +198,17 @@ def header(str) stroke_horizontal_rule move_down 30 end - + # Render the arguments as a bulleted list. Used on the manual package # introductory pages # def list(*items) move_down 20 - + items.each do |li| float { text "•" } indent(10) do - text li.gsub(/\s+/," "), + text li.gsub(/\s+/," "), :inline_format => true, :leading => 2 end @@ -216,7 +216,7 @@ def list(*items) move_down 10 end end - + # Draws X and Y axis rulers beginning at the margin box origin. Used on # examples. # @@ -224,14 +224,14 @@ def stroke_axis(options={}) options = { :height => (cursor - 20).to_i, :width => bounds.width.to_i }.merge(options) - + dash(1, :space => 4) stroke_horizontal_line(-21, options[:width], :at => 0) stroke_vertical_line(-21, options[:height], :at => 0) undash - + fill_circle [0, 0], 1 - + (100..options[:width]).step(100) do |point| fill_circle [point, 0], 1 draw_text point, :at => [point-5, -10], :size => 7 @@ -242,7 +242,7 @@ def stroke_axis(options={}) draw_text point, :at => [-17, point-2], :size => 7 end end - + # Reset some of the drawing settings to their defaults. Used on examples. # def reset_drawing_settings @@ -261,13 +261,13 @@ def reset_drawing_settings def extract_full_source(source) source.gsub(/# encoding.*?\n.*require.*?\n\n/m, "\n") end - + # Retrieve the code inside the generate block # def extract_generate_block(source) source.slice(/\w+\.generate.*? do(.*)end/m, 1) or source end - + # Retrieve the comments between the encoding declaration and the require # call for example_helper.rb # @@ -279,15 +279,15 @@ def extract_introduction_text(source) intro.gsub!(/^#/, '') intro.gsub!("\n", "\n\n") intro.rstrip! - + # Process the tags intro.gsub!(/([^<]+?)<\/code>/, "\\1<\/font>") - + # Process the links intro.gsub!(/(https?:\/\/\S+)/, "\\1") - + intro end end diff --git a/manual/graphics/circle_and_ellipse.rb b/manual/graphics/circle_and_ellipse.rb index 6eada0618..2ec309ed9 100644 --- a/manual/graphics/circle_and_ellipse.rb +++ b/manual/graphics/circle_and_ellipse.rb @@ -12,10 +12,10 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + stroke_circle [100, 300], 100 - + fill_ellipse [200, 100], 100, 50 - + fill_ellipse [400, 100], 50 end diff --git a/manual/graphics/color.rb b/manual/graphics/color.rb index b6bf70364..d5a832109 100644 --- a/manual/graphics/color.rb +++ b/manual/graphics/color.rb @@ -9,16 +9,16 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + # Fill with Yellow fill_color "FFFFCC" # RGB fill_polygon [50, 150], [150, 200], [250, 150], [250, 50], [150, 0], [50, 50] - + # Stroke with Purple stroke_color 50, 100, 0, 0 # CMYK stroke_rectangle [300, 300], 200, 100 - + # Both together fill_and_stroke_circle [400, 100], 50 @@ -27,6 +27,6 @@ bounding_box [10, 300], :width => 450, :height => 150 do text "Gradient!", :size => 60 end - + reset_drawing_settings end diff --git a/manual/graphics/common_lines.rb b/manual/graphics/common_lines.rb index 468d7bceb..4fdf78039 100644 --- a/manual/graphics/common_lines.rb +++ b/manual/graphics/common_lines.rb @@ -15,14 +15,14 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + stroke do # just lower the current y position - move_down 50 + move_down 50 horizontal_rule - + vertical_line 100, 300, :at => 50 - + horizontal_line 200, 500, :at => 150 end end diff --git a/manual/graphics/fill_and_stroke.rb b/manual/graphics/fill_and_stroke.rb index b160a6128..9402bf708 100644 --- a/manual/graphics/fill_and_stroke.rb +++ b/manual/graphics/fill_and_stroke.rb @@ -23,18 +23,18 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + # No block line [0, 200], [100, 150] stroke - + rectangle [0, 100], 100, 100 fill - + # With block stroke { line [200, 200], [300, 150] } fill { rectangle [200, 100], 100, 100 } - + # Method hook stroke_line [400, 200], [500, 150] fill_rectangle [400, 100], 100, 100 diff --git a/manual/graphics/graphics.rb b/manual/graphics/graphics.rb index 0d821140b..c2b48ec5b 100644 --- a/manual/graphics/graphics.rb +++ b/manual/graphics/graphics.rb @@ -33,14 +33,14 @@ ] ] ] - + ) do text "Here we show all the drawing methods provided by Prawn. Use them to draw the most beautiful imaginable things. - + Most of the content that you'll add to your pdf document will use the graphics package. Even text is rendered on a page just like a rectangle is so even if you never use any of the shapes described here you should at least read the basic examples. - + The examples show:" - + list( "All the possible ways that you can fill or stroke shapes on a page", "How to draw all the shapes that Prawn has to offer from a measly line to a mighty polygon or ellipse", "What the configuration options are for stroking lines and filling shapes.", diff --git a/manual/graphics/line_width.rb b/manual/graphics/line_width.rb index 6f509ac91..2c583fccf 100644 --- a/manual/graphics/line_width.rb +++ b/manual/graphics/line_width.rb @@ -14,25 +14,25 @@ Prawn::Example.generate(filename) do # Prawn::Document.generate() do stroke_axis - + y = 250 - + 3.times do |i| case i when 0; line_width = 10 # This call will have no effect when 1; self.line_width = 10 when 2; self.line_width = 25 end - + stroke do horizontal_line 50, 150, :at => y rectangle [275, y + 25], 50, 50 circle [500, y], 25 end - + y -= 100 end - + # Return line_width back to normal self.line_width = 1 end diff --git a/manual/graphics/lines_and_curves.rb b/manual/graphics/lines_and_curves.rb index 576e0884a..cc33d9c5e 100644 --- a/manual/graphics/lines_and_curves.rb +++ b/manual/graphics/lines_and_curves.rb @@ -20,18 +20,18 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + # line_to and curve_to stroke do move_to 0, 0 - + line_to 100, 100 line_to 0, 100 - + curve_to [150, 250], :bounds => [[20, 200], [120, 200]] curve_to [200, 0], :bounds => [[150, 200], [450, 10]] end - + # line and curve stroke do line [300,200], [400,50] diff --git a/manual/graphics/polygon.rb b/manual/graphics/polygon.rb index d48e431f6..c56cb2d61 100644 --- a/manual/graphics/polygon.rb +++ b/manual/graphics/polygon.rb @@ -15,14 +15,14 @@ # Triangle stroke_polygon [50, 200], [50, 300], [150, 300] - + # Hexagon fill_polygon [50, 150], [150, 200], [250, 150], [250, 50], [150, 0], [50, 50] - + # Pentagram pentagon_points = [500, 100], [430, 5], [319, 41], [319, 159], [430, 195] pentagram_points = [0, 2, 4, 1, 3].map{|i| pentagon_points[i]} - + stroke_rounded_polygon(20, *pentagram_points) end diff --git a/manual/graphics/rectangle.rb b/manual/graphics/rectangle.rb index 3d57a3560..e1e4e3610 100644 --- a/manual/graphics/rectangle.rb +++ b/manual/graphics/rectangle.rb @@ -11,10 +11,10 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + stroke do rectangle [100, 300], 100, 200 - + rounded_rectangle [300, 300], 100, 200, 20 end end diff --git a/manual/graphics/rotate.rb b/manual/graphics/rotate.rb index e1fed7f8e..738603c53 100644 --- a/manual/graphics/rotate.rb +++ b/manual/graphics/rotate.rb @@ -14,13 +14,13 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + fill_circle [250, 200], 2 - + 12.times do |i| - + rotate(i * 30, :origin => [250, 200]) do - + stroke_rectangle [350, 225], 100, 50 draw_text "Rotated #{i * 30}°", :size => 10, :at => [360, 205] end diff --git a/manual/graphics/scale.rb b/manual/graphics/scale.rb index 0b25c0dca..1cd00535c 100644 --- a/manual/graphics/scale.rb +++ b/manual/graphics/scale.rb @@ -12,16 +12,16 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + width = 100 height = 50 - + x = 50 y = 200 stroke_rectangle [x, y], width, height text_box "reference rectangle", :at => [x + 10, y - 10], :width => width - 20 - + scale(2, :origin => [x, y]) do stroke_rectangle [x, y], width, height text_box "rectangle scaled from upper-left corner", @@ -32,7 +32,7 @@ stroke_rectangle [x, y], width, height text_box "reference rectangle", :at => [x + 10, y - 10], :width => width - 20 - + scale(2, :origin => [x + width / 2, y - height / 2]) do stroke_rectangle [x, y], width, height text_box "rectangle scaled from center", diff --git a/manual/graphics/stroke_cap.rb b/manual/graphics/stroke_cap.rb index bb70cdb8c..349e2d4f0 100644 --- a/manual/graphics/stroke_cap.rb +++ b/manual/graphics/stroke_cap.rb @@ -18,7 +18,7 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + self.line_width = 25 y = 250 @@ -28,12 +28,12 @@ when 1; self.cap_style = :round when 2; self.cap_style = :projecting_square end - + stroke_horizontal_line 100, 300, :at => y stroke_circle [400, y], 15 - + y -= 100 end - + reset_drawing_settings end diff --git a/manual/graphics/stroke_dash.rb b/manual/graphics/stroke_dash.rb index 151e4813e..310c27292 100644 --- a/manual/graphics/stroke_dash.rb +++ b/manual/graphics/stroke_dash.rb @@ -8,7 +8,7 @@ # dashes. # # The :phase option defines the start point of the sequence of -# dashes and spaces. +# dashes and spaces. # require File.expand_path(File.join(File.dirname(__FILE__), %w[.. example_helper])) @@ -16,14 +16,14 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + base_y = 210 - + 24.times do |i| length = (i / 4) + 1 space = length # space between dashes same length as dash phase = 0 # start with dash - + case i % 4 when 0 base_y -= 5 @@ -36,10 +36,10 @@ phase = length # start with space between dashes end base_y -= 5 - + dash(length, :space => space, :phase => phase) stroke_horizontal_line 50, 500, :at => base_y - (2 * i) end - + undash # revert stroke back to normal end diff --git a/manual/graphics/stroke_join.rb b/manual/graphics/stroke_join.rb index 77bb081d1..1d9ffd965 100644 --- a/manual/graphics/stroke_join.rb +++ b/manual/graphics/stroke_join.rb @@ -13,26 +13,26 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + self.line_width = 25 y = 200 - + 3.times do |i| case i when 0; self.join_style = :miter when 1; self.join_style = :round when 2; self.join_style = :bevel end - + stroke do move_to(100, y) line_to(200, y + 100) line_to(300, y) end stroke_rectangle [400, y + 75], 50, 50 - + y -= 100 end - + reset_drawing_settings end diff --git a/manual/graphics/translate.rb b/manual/graphics/translate.rb index ac4f2514f..0f4e814f1 100644 --- a/manual/graphics/translate.rb +++ b/manual/graphics/translate.rb @@ -9,18 +9,18 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::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 diff --git a/manual/graphics/transparency.rb b/manual/graphics/transparency.rb index 2d37ce219..0b69680a8 100644 --- a/manual/graphics/transparency.rb +++ b/manual/graphics/transparency.rb @@ -18,20 +18,20 @@ self.line_width = 5 fill_color "ff0000" fill_rectangle [0, 100], 500, 100 - + fill_color "000000" stroke_color "ffffff" - + base_x = 100 [[0.5, 1], 0.5, [1, 0.5]].each do |args| - + transparent(*args) do fill_circle [base_x, 100], 50 stroke_rectangle [base_x - 20, 100], 40, 80 end - + base_x += 150 end - + reset_drawing_settings end diff --git a/manual/images/absolute_position.rb b/manual/images/absolute_position.rb index 75f1dac1e..7575d4bb9 100644 --- a/manual/images/absolute_position.rb +++ b/manual/images/absolute_position.rb @@ -16,8 +16,8 @@ Prawn::Example.generate(filename) do y_position = cursor text "The image won't go below this line of text." - + image "#{Prawn::DATADIR}/images/fractal.jpg", :at => [200, y_position] - + text "And this line of text will go just below the previous one." end diff --git a/manual/images/fit.rb b/manual/images/fit.rb index 11dc67be9..456f069e5 100644 --- a/manual/images/fit.rb +++ b/manual/images/fit.rb @@ -12,7 +12,7 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do size = 300 - + text "Using the fit option" bounding_box([0, cursor], :width => size, :height => size) do image "#{Prawn::DATADIR}/images/pigs.jpg", :fit => [size, size] diff --git a/manual/images/horizontal.rb b/manual/images/horizontal.rb index 120f95fa1..f53287bb1 100644 --- a/manual/images/horizontal.rb +++ b/manual/images/horizontal.rb @@ -13,12 +13,12 @@ Prawn::Example.generate(filename) do bounding_box([50, cursor], :width => 400, :height => 450) do stroke_bounds - + [:left, :center, :right].each do |position| text "Image aligned to the #{position}." image "#{Prawn::DATADIR}/images/stef.jpg", :position => position end - + text "The next image has a 50 point offset from the left boundary" image "#{Prawn::DATADIR}/images/stef.jpg", :position => 50 end diff --git a/manual/images/scale.rb b/manual/images/scale.rb index d0f23d9c5..4f0ee0c9b 100644 --- a/manual/images/scale.rb +++ b/manual/images/scale.rb @@ -13,11 +13,11 @@ text "Normal size" image "#{Prawn::DATADIR}/images/stef.jpg" move_down 10 - + text "Scaled to 50%" image "#{Prawn::DATADIR}/images/stef.jpg", :scale => 0.5 move_down 10 - + text "Scaled to 200%" image "#{Prawn::DATADIR}/images/stef.jpg", :scale => 2 end diff --git a/manual/images/vertical.rb b/manual/images/vertical.rb index 9f2b99977..d46c2aa06 100644 --- a/manual/images/vertical.rb +++ b/manual/images/vertical.rb @@ -12,13 +12,13 @@ Prawn::Example.generate(filename) do bounding_box([0, cursor], :width => 500, :height => 450) do stroke_bounds - + [:top, :center, :bottom].each do |vposition| text "Image vertically aligned to the #{vposition}.", :valign => vposition image "#{Prawn::DATADIR}/images/stef.jpg", :position => 250, :vposition => vposition end - + text_box "The next image has a 100 point offset from the top boundary", :at => [bounds.width - 110, bounds.top - 10], :width => 100 image "#{Prawn::DATADIR}/images/stef.jpg", :position => :right, diff --git a/manual/images/width_and_height.rb b/manual/images/width_and_height.rb index 6304334a1..48e7c641d 100644 --- a/manual/images/width_and_height.rb +++ b/manual/images/width_and_height.rb @@ -15,11 +15,11 @@ text "Scale by setting only the width" image "#{Prawn::DATADIR}/images/pigs.jpg", :width => 150 move_down 10 - + text "Scale by setting only the height" image "#{Prawn::DATADIR}/images/pigs.jpg", :height => 100 move_down 10 - + text "Stretch to fit the width and height provided" image "#{Prawn::DATADIR}/images/pigs.jpg", :width => 500, :height => 100 end diff --git a/manual/layout/boxes.rb b/manual/layout/boxes.rb index ba782a523..14e39e4b5 100644 --- a/manual/layout/boxes.rb +++ b/manual/layout/boxes.rb @@ -16,12 +16,12 @@ # The grid only need to be defined once, but since all the examples should be # able to run alone we are repeating it on every example define_grid(:columns => 5, :rows => 8, :gutter => 10) - + grid(4,0).show grid(5,1).show - + grid([6,2], [7,3]).show - + grid([4,4], [7,4]).show grid([7,0], [7,1]).show end diff --git a/manual/layout/content.rb b/manual/layout/content.rb index b1671c80e..c4f063cd0 100644 --- a/manual/layout/content.rb +++ b/manual/layout/content.rb @@ -14,11 +14,11 @@ # The grid only need to be defined once, but since all the examples should be # able to run alone we are repeating it on every example define_grid(:columns => 5, :rows => 8, :gutter => 10) - + grid([5,0], [7,1]).bounding_box do text "Adding some content to this multi_box.\n" + " _ " * 200 end - + grid(6,3).bounding_box do text "Just a little snippet here.\n" + " _ " * 10 end diff --git a/manual/layout/simple_grid.rb b/manual/layout/simple_grid.rb index 3e91e3ce4..8ac978a17 100644 --- a/manual/layout/simple_grid.rb +++ b/manual/layout/simple_grid.rb @@ -17,7 +17,7 @@ # able to run alone we are repeating it on every example define_grid(:columns => 5, :rows => 8, :gutter => 10) text "We defined the grid, roll over to the next page to see its outline" - + start_new_page grid.show_all end diff --git a/manual/manual/cover.rb b/manual/manual/cover.rb index 5c0a4450c..e0dde83fd 100644 --- a/manual/manual/cover.rb +++ b/manual/manual/cover.rb @@ -1,6 +1,6 @@ # encoding: utf-8 # -# Prawn manual how to read this manual page. +# Prawn manual how to read this manual page. # require File.expand_path(File.join(File.dirname(__FILE__), %w[.. example_helper])) @@ -12,7 +12,7 @@ image "#{Prawn::DATADIR}/images/prawn.png", :scale => 0.9, :at => [10, cursor] - + formatted_text_box([ {:text => "Prawn\n", :styles => [:bold], :size => 100} @@ -22,5 +22,5 @@ :font => 'Courier', :size => 60} ], :at => [170, cursor - 160]) - + end diff --git a/manual/manual/foreword.rb b/manual/manual/foreword.rb index 7d2a900cb..c5f25bc4a 100644 --- a/manual/manual/foreword.rb +++ b/manual/manual/foreword.rb @@ -1,6 +1,6 @@ # encoding: utf-8 # -# Prawn manual foreword page. +# Prawn manual foreword page. # require File.expand_path(File.join(File.dirname(__FILE__), %w[.. example_helper])) diff --git a/manual/manual/how_to_read.rb b/manual/manual/how_to_read.rb index fa3c6117d..a1a1d338d 100644 --- a/manual/manual/how_to_read.rb +++ b/manual/manual/how_to_read.rb @@ -1,6 +1,6 @@ # encoding: utf-8 # -# Prawn manual how to read this manual page. +# Prawn manual how to read this manual page. # require File.expand_path(File.join(File.dirname(__FILE__), %w[.. example_helper])) @@ -8,26 +8,26 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do header("How to read this manual") - + text <<-END_TEXT This manual is a collection of examples categorized by theme and organized from the least to the most complex. While it covers most of the common use cases it is not a comprehensive guide. - + The best way to read it depends on your previous knowledge of Prawn and what you need to accomplish. - + If you are beginning with Prawn the first chapter will teach you the most basic concepts and how to create pdf documents. For an overview of the other features each chapter beyond the first either has a Basics section (which offer enough insight on the feature without showing all the advanced stuff you might never use) or is simple enough with only a few examples. - + Once you understand the basics you might want to come back to this manual looking for examples that accomplish tasks you need. - + Advanced users are encouraged to go beyond this manual and read the source code directly if any doubt you have is not directly covered on this manual. END_TEXT - + header("Reading the examples") - + text <<-END_TEXT The title of each example is the relative path from the Prawn source manual/ folder. - + The first body of text is the introductory text for the example. Generaly it is a short description of the feature or features illustrated by the example. - + Next comes the example source code in fixed width font. Most of the example snippets illustrate features that alter the page in place. The effect of these snippets is shown right below a dashed line. Note that the 'stroke_axis' method, used occasionally in the manual, is not part of standard Prawn and is used for demonstrative purposes. It is defined in manual/example_helper.rb. diff --git a/manual/manual/manual.rb b/manual/manual/manual.rb index 30e91ef6f..f5a878fc8 100644 --- a/manual/manual/manual.rb +++ b/manual/manual/manual.rb @@ -9,13 +9,13 @@ load_page "cover" load_page "foreword" load_page "how_to_read", "How to read this manual" - + # Core chapters load_package "basic_concepts" load_package "graphics" load_package "text" load_package "bounding_box" - + # Remaining chapters load_package "layout" load_package "table" diff --git a/manual/outline/add_subsection_to.rb b/manual/outline/add_subsection_to.rb index 2c728ed66..d2b621d9f 100644 --- a/manual/outline/add_subsection_to.rb +++ b/manual/outline/add_subsection_to.rb @@ -27,14 +27,14 @@ text "Page #{index}" start_new_page end - + outline.define do - section("Section 1", :destination => 1) do + section("Section 1", :destination => 1) do page :title => "Page 2", :destination => 2 page :title => "Page 3", :destination => 3 end end - + # Now we will start adding nodes to the previous outline outline.add_subsection_to("Section 1", :first) do outline.section("Added later - first position") do @@ -42,17 +42,17 @@ outline.page :title => "Page 5", :destination => 5 end end - + outline.add_subsection_to("Section 1") do outline.page :title => "Added later - last position", :destination => 6 end - + outline.add_subsection_to("Added later - first position") do outline.page :title => "Another page added later", :destination => 7 end - + # The title provided is for a page which will be converted into a section outline.add_subsection_to("Page 3") do outline.page :title => "Last page added", diff --git a/manual/outline/insert_section_after.rb b/manual/outline/insert_section_after.rb index 22a9e5e19..a2b7356f5 100644 --- a/manual/outline/insert_section_after.rb +++ b/manual/outline/insert_section_after.rb @@ -19,14 +19,14 @@ text "Page #{index}" start_new_page end - + outline.define do - section("Section 1", :destination => 1) do + section("Section 1", :destination => 1) do page :title => "Page 2", :destination => 2 page :title => "Page 3", :destination => 3 end end - + # Now we will start adding nodes to the previous outline outline.insert_section_after("Page 2") do outline.section("Section after Page 2") do @@ -39,7 +39,7 @@ outline.page :title => "Page 5", :destination => 5 end end - + # Adding just a page outline.insert_section_after("Page 3") do outline.page :title => "Page after Page 3", :destination => 6 diff --git a/manual/outline/outline.rb b/manual/outline/outline.rb index d2ccfc763..fc8f2721a 100644 --- a/manual/outline/outline.rb +++ b/manual/outline/outline.rb @@ -19,7 +19,7 @@ ] ] ] - + ) do text "The outline of a PDF document is the table of contents tab you see to the right or left of your PDF viewer. diff --git a/manual/outline/sections_and_pages.rb b/manual/outline/sections_and_pages.rb index edd61550e..18b1dcb86 100644 --- a/manual/outline/sections_and_pages.rb +++ b/manual/outline/sections_and_pages.rb @@ -34,33 +34,33 @@ text "Page #{index}" start_new_page end - + outline.define do - section("Section 1", :destination => 1) do + section("Section 1", :destination => 1) do page :title => "Page 2", :destination => 2 page :title => "Page 3", :destination => 3 end - + section("Section 2", :destination => 4) do page :title => "Page 5", :destination => 5 - + section("Subsection 2.1", :destination => 6, :closed => true) do page :title => "Page 7", :destination => 7 end end end - + # Outside of the define block outline.section "Section 3", :destination => 8 do outline.page :title => "Page 9", :destination => 9 end - + outline.page :title => "Page 10", :destination => 10 - + # Section and Pages without links. While a section without a link may be # useful to group some pages, a page without a link is useless outline.update do # update is an alias to define - section("Section without link") do + section("Section without link") do page :title => "Page without link" end end diff --git a/manual/repeatable_content/page_numbering.rb b/manual/repeatable_content/page_numbering.rb index 1a9a1aeee..cbe1c7cf3 100644 --- a/manual/repeatable_content/page_numbering.rb +++ b/manual/repeatable_content/page_numbering.rb @@ -27,7 +27,7 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do text "This is the first page!" - + 10.times do start_new_page text "Here comes yet another page." @@ -48,7 +48,7 @@ options[:start_count_at] = 8 options[:color] = "333333" number_pages string, options - + start_new_page text "See. This page isn't numbered and doesn't count towards the total." end diff --git a/manual/repeatable_content/repeatable_content.rb b/manual/repeatable_content/repeatable_content.rb index 2d6b17d63..c230b3afe 100644 --- a/manual/repeatable_content/repeatable_content.rb +++ b/manual/repeatable_content/repeatable_content.rb @@ -11,10 +11,10 @@ "stamp", {:name => "page_numbering", :eval_source => false} ] - + ) do text "Prawn offers two ways to handle repeatable content blocks. Repeater is useful for content that gets repeated at well defined intervals while Stamp is more appropriate if you need better control of when to repeat it. - + There is also one very specific helper for numbering pages. The examples show:" diff --git a/manual/repeatable_content/repeater.rb b/manual/repeatable_content/repeater.rb index 2c8450f58..c2b8fbf17 100644 --- a/manual/repeatable_content/repeater.rb +++ b/manual/repeatable_content/repeater.rb @@ -32,7 +32,7 @@ draw_text "Only even pages", :at => [0,0] end - repeat [1,3,7] do + repeat [1,3,7] do draw_text "Only on pages 1, 3 and 7", :at => [100,0] end @@ -43,12 +43,12 @@ repeat(lambda { |pg| pg % 3 == 0 }) do draw_text "Every third page", :at => [250, 20] end - + repeat(:all, :dynamic => true) do draw_text page_number, :at => [500, 0] end - 10.times do + 10.times do start_new_page draw_text "A wonderful page", :at => [400,400] end diff --git a/manual/repeatable_content/stamp.rb b/manual/repeatable_content/stamp.rb index 6a68ec565..9f045fb47 100644 --- a/manual/repeatable_content/stamp.rb +++ b/manual/repeatable_content/stamp.rb @@ -26,7 +26,7 @@ stroke_color "FF3333" stroke_ellipse [0, 0], 29, 15 stroke_color "000000" - + fill_color "993333" font("Times-Roman") do draw_text "Approved", :at => [-23, -3] @@ -34,8 +34,8 @@ fill_color "000000" end end - + stamp "approved" - + stamp_at "approved", [200, 200] end diff --git a/manual/table/basic_block.rb b/manual/table/basic_block.rb index f0fa8b4c8..d7e768f93 100644 --- a/manual/table/basic_block.rb +++ b/manual/table/basic_block.rb @@ -37,17 +37,17 @@ data = [ ["Header", "A " * 5, "B"], ["Data row", "C", "D " * 5], ["Another data row", "E", "F"]] - + table(data) do cells.padding = 12 cells.borders = [] - + row(0).borders = [:bottom] row(0).border_width = 2 row(0).font_style = :bold - + columns(0..1).borders = [:right] - + row(0).columns(0..1).borders = [:bottom, :right] end end diff --git a/manual/table/cell_borders_and_bg.rb b/manual/table/cell_borders_and_bg.rb index dcd5efeba..e43004a86 100644 --- a/manual/table/cell_borders_and_bg.rb +++ b/manual/table/cell_borders_and_bg.rb @@ -16,16 +16,16 @@ data = [ ["Look at how the cells will look when styled", "", ""], ["They probably won't look the same", "", ""] ] - + { :borders => [:top, :left], :border_width => 3, :border_color => "FF0000"}.each do |property, value| - + text "Cell #{property}: #{value.inspect}" table(data, :cell_style => {property => value}) move_down 20 end - + text "Cell background_color: FFFFCC" table(data, :cell_style => {:background_color => "FFFFCC"}) end diff --git a/manual/table/cell_dimensions.rb b/manual/table/cell_dimensions.rb index 94f78d362..07d45ad33 100644 --- a/manual/table/cell_dimensions.rb +++ b/manual/table/cell_dimensions.rb @@ -18,13 +18,13 @@ data = [ ["Look at how the cells will look when styled", "", ""], ["They probably won't look the same", "", ""] ] - + {:width => 160, :height => 50, :padding => 12}.each do |property, value| text "Cell's #{property}: #{value}" table(data, :cell_style => {property => value}) move_down 20 end - + text "Padding can also be set with an array: [0, 0, 0, 30]" table(data, :cell_style => {:padding => [0, 0, 0, 30]}) end diff --git a/manual/table/cell_text.rb b/manual/table/cell_text.rb index a7c37f974..68ffdee57 100644 --- a/manual/table/cell_text.rb +++ b/manual/table/cell_text.rb @@ -18,21 +18,21 @@ data = [ ["Look at how the cells will look when styled", "", ""], ["They probably won't look the same", "", ""] ] - + table data, :cell_style => { :font => "Times-Roman", :font_style => :italic } move_down 20 - + table data, :cell_style => { :size => 18, :text_color => "346842" } move_down 20 - + table [["Just some inline", "", ""], ["styles being applied here", "", ""]], :cell_style => { :inline_format => true } move_down 20 - + table [["1", "2", "3", "rotate"]], :cell_style => { :rotate => 30 } move_down 20 - + table data, :cell_style => { :overflow => :shrink_to_fit, :min_font_size => 8, :width => 60, :height => 30 } end diff --git a/manual/table/column_widths.rb b/manual/table/column_widths.rb index 49e08a215..ad98371ca 100644 --- a/manual/table/column_widths.rb +++ b/manual/table/column_widths.rb @@ -16,15 +16,15 @@ data = [ ["this is not quite as long as the others", "here we have a line that is long but with smaller words", "this is so very looooooooooooooooooooooooooooooong"] ] - + text "Prawn trying to guess the column widths" table(data) move_down 20 - + text "Manually setting all the column widths" table(data, :column_widths => [100, 200, 240]) move_down 20 - + text "Setting only the last column width" table(data, :column_widths => {2 => 240}) end diff --git a/manual/table/content_and_subtables.rb b/manual/table/content_and_subtables.rb index aa833a1d6..86dab74c6 100644 --- a/manual/table/content_and_subtables.rb +++ b/manual/table/content_and_subtables.rb @@ -20,15 +20,15 @@ Prawn::Example.generate(filename) do cell_1 = make_cell(:content => "this row content comes directly ") cell_2 = make_cell(:content => "from cell objects") - + two_dimensional_array = [ ["..."], ["subtable from an array"], ["..."] ] - + inner_table = make_table([ ["..."], ["subtable from another table"], ["..."] ]) - + table([ ["just a regular row", "", "", "blah blah blah"], [cell_1, cell_2, "", ""], ["", "", two_dimensional_array, ""], diff --git a/manual/table/creation.rb b/manual/table/creation.rb index 8423f91dd..75a23c343 100644 --- a/manual/table/creation.rb +++ b/manual/table/creation.rb @@ -20,7 +20,7 @@ ["this is the second row"] ]) t.draw move_down 20 - + table([ ["short", "short", "loooooooooooooooooooong"], ["short", "loooooooooooooooooooong", "short"], ["loooooooooooooooooooong", "short", "short"] ]) diff --git a/manual/table/filtering.rb b/manual/table/filtering.rb index 5ad91ea2f..3129d235b 100644 --- a/manual/table/filtering.rb +++ b/manual/table/filtering.rb @@ -3,7 +3,7 @@ # Another way to reduce the number of cells is to filter the table. # # filter is just like Enumerable#select. Pass is a -# block and it will iterate through the cells returning a new +# block and it will iterate through the cells returning a new # Prawn::Table::Cells instance containing only those cells for # which the block was not false. # @@ -17,20 +17,20 @@ ["Fridge", 62, 30], ["Microwave", 71, 47] ] - + table(data) do values = cells.columns(1..-1).rows(1..-1) - + bad_sales = values.filter do |cell| cell.content.to_i < 40 end - + bad_sales.background_color = "FFAAAA" good_sales = values.filter do |cell| cell.content.to_i > 70 end - + good_sales.background_color = "AAFFAA" end end diff --git a/manual/table/flow_and_header.rb b/manual/table/flow_and_header.rb index 731dd6596..bd72f43e9 100644 --- a/manual/table/flow_and_header.rb +++ b/manual/table/flow_and_header.rb @@ -11,6 +11,6 @@ Prawn::Example.generate(filename) do data = [["This row should be repeated on every new page"]] data += [["..."]] * 30 - + table(data, :header => true) end diff --git a/manual/table/row_colors.rb b/manual/table/row_colors.rb index 579c17cf0..fd2a6377a 100644 --- a/manual/table/row_colors.rb +++ b/manual/table/row_colors.rb @@ -13,8 +13,8 @@ Prawn::Example.generate(filename) do data = [["This row should have one color"], ["And this row should have another"]] - + data += [["..."]] * 10 - + table(data, :row_colors => ["F0F0F0", "FFFFCC"]) end diff --git a/manual/table/style.rb b/manual/table/style.rb index a09c9b6fd..ab7040f1d 100644 --- a/manual/table/style.rb +++ b/manual/table/style.rb @@ -14,8 +14,8 @@ Prawn::Example.generate(filename) do table [[""] * 8] * 8 do cells.style(:width => 24, :height => 24) - - cells.style do |c| + + cells.style do |c| c.background_color = ((c.row + c.column) % 2).zero? ? '000000' : 'ffffff' end end diff --git a/manual/table/width.rb b/manual/table/width.rb index cddf89922..6e8d854f2 100644 --- a/manual/table/width.rb +++ b/manual/table/width.rb @@ -13,7 +13,7 @@ text "Normal width:" table [%w[A B C]] move_down 20 - + text "Fixed width:" table([%w[A B C]], :width => 300) move_down 20 @@ -21,7 +21,7 @@ text "Normal width:" table([["A", "Blah " * 20, "C"]]) move_down 20 - + text "Fixed width:" table([["A", "Blah " * 20, "C"]], :width => 300) end diff --git a/manual/templates/full_template.rb b/manual/templates/full_template.rb index 2f1c4b55f..00fe5d111 100644 --- a/manual/templates/full_template.rb +++ b/manual/templates/full_template.rb @@ -15,9 +15,9 @@ Prawn::Example.generate("full_template.pdf", :template => filename) do go_to_page(page_count) - + start_new_page - + text "Previous pages and content imported.", :align => :center text "This page and content is brand new.", :align => :center end diff --git a/manual/templates/page_template.rb b/manual/templates/page_template.rb index b53f62452..014d4292e 100644 --- a/manual/templates/page_template.rb +++ b/manual/templates/page_template.rb @@ -21,20 +21,20 @@ text "You also might want to look at the pdf used as a template: " url = "https://github.com/sandal/prawn/raw/master/data/pdfs/form.pdf" formatted_text [{:text => url, :link => url}] - + filename = "#{Prawn::DATADIR}/pdfs/form.pdf" start_new_page(:template => filename) - + start_new_page(:template => filename, :template_page => 2) - + start_new_page(:template => filename, :template_page => 2) - + fill_color "FF8888" - + text_box "John Doe", :at => [75, cursor-75] text_box "john@doe.com", :at => [75, cursor-105] text_box "John Doe inc", :at => [75, cursor-135] text_box "You didn't think I'd tell, did you?", :at => [75, cursor-165] - + fill_color "000000" end diff --git a/manual/templates/templates.rb b/manual/templates/templates.rb index 6912e0bb4..81b1f08ea 100644 --- a/manual/templates/templates.rb +++ b/manual/templates/templates.rb @@ -13,7 +13,7 @@ }, "page_template" ] - + ) do text "Templates let you embed other PDF documents inside the current one. diff --git a/manual/text/font.rb b/manual/text/font.rb index fc6d46298..1148b1062 100644 --- a/manual/text/font.rb +++ b/manual/text/font.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # The font method can be used in three different ways. # # If we don't pass it any arguments it will return the current font being used @@ -17,21 +17,21 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do text "Let's see which font we are using: #{font.inspect}" - + move_down 20 font "Times-Roman" text "Written in Times." - + move_down 20 font("Courier") do text "Written in Courier because we are inside the block." end - + move_down 20 text "Written in Times again as we left the previous block." - + move_down 20 text "Let's see which font we are using again: #{font.inspect}" - + font "Helvetica" # back to normal end diff --git a/manual/text/font_size.rb b/manual/text/font_size.rb index 330725e12..8587d4e71 100644 --- a/manual/text/font_size.rb +++ b/manual/text/font_size.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # The font_size method works just like the font method. # # In fact we can even use font with the :size option @@ -14,27 +14,27 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do text "Let's see which is the current font_size: #{font_size.inspect}" - + move_down 10 font_size 16 text "Yeah, something bigger!" - + move_down 10 font_size(25) { text "Even bigger!" } - + move_down 10 text "Back to 16 again." - + move_down 10 text "Single line on 20 using the :size option.", :size => 20 - + move_down 10 text "Back to 16 once more." - + move_down 10 font("Courier", :size => 10) do text "Yeah, using Courier 10 courtesy of the font method." end - + font("Helvetica", :size => 12) # back to normal end diff --git a/manual/text/font_style.rb b/manual/text/font_style.rb index 1e189ee78..fd13873fd 100644 --- a/manual/text/font_style.rb +++ b/manual/text/font_style.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # Most font families come with some styles other than normal. Most common are # bold, italic and bold_italic. # @@ -13,16 +13,16 @@ Prawn::Example.generate(filename) do ["Courier", "Helvetica", "Times-Roman"].each do |example_font| move_down 20 - + [:bold, :bold_italic, :italic, :normal].each do |style| font example_font, :style => style text "I'm writing in #{example_font} (#{style})" end end - + move_down 20 font "Helvetica" - + text "Normal" text "Bold", :style => :bold text "Bold Italic", :style => :bold_italic diff --git a/manual/text/formatted_callbacks.rb b/manual/text/formatted_callbacks.rb index c691b7ee7..773cc5267 100644 --- a/manual/text/formatted_callbacks.rb +++ b/manual/text/formatted_callbacks.rb @@ -40,7 +40,7 @@ def initialize(options) def render_in_front(fragment) @document.stroke_polygon(fragment.top_left, fragment.top_right, fragment.bottom_right, fragment.bottom_left) - + @document.fill_circle(fragment.top_left, @radius) @document.fill_circle(fragment.top_right, @radius) @document.fill_circle(fragment.bottom_right, @radius) @@ -50,7 +50,7 @@ def render_in_front(fragment) highlight = HighlightCallback.new(:color => 'ffff00', :document => self) border = ConnectedBorderCallback.new(:radius => 2.5, :document => self) - + formatted_text [ { :text => "hello", :callback => highlight }, { :text => " " }, { :text => "world", :callback => border }, diff --git a/manual/text/formatted_text.rb b/manual/text/formatted_text.rb index 177a9fb36..ef1bdb326 100644 --- a/manual/text/formatted_text.rb +++ b/manual/text/formatted_text.rb @@ -39,7 +39,7 @@ :color => "0000FF", :anchor => "Text Reference" } ] - + formatted_text_box [ { :text => "Just your regular" }, { :text => " text_box ", :font => "Courier" }, { :text => "with some additional formatting options " + diff --git a/manual/text/free_flowing_text.rb b/manual/text/free_flowing_text.rb index ad35a96ce..bd49732bd 100644 --- a/manual/text/free_flowing_text.rb +++ b/manual/text/free_flowing_text.rb @@ -20,26 +20,26 @@ Prawn::Example.generate(filename) do move_cursor_to 50 text "This text will flow to the next page. " * 20 - + y_position = cursor - 50 bounding_box [0, y_position], :width => 200, :height => 150 do transparent(0.5) { stroke_bounds } text "This text will flow along this bounding box we created for it. " * 5 end - + bounding_box [300, y_position], :width => 200, :height => 150 do transparent(0.5) { stroke_bounds } # This will stroke on one page - + text "Now look what happens when the free flowing text reaches the end " + "of a bounding box that is narrower than the margin box." + " . " * 200 + "It continues on the next page as if the previous bounding box " + "was cloned. If we want it to have the same border as the one on " + "the previous page we will need to stroke the boundaries again." - + transparent(0.5) { stroke_bounds } # And this will stroke on the next end - + move_down 200 span(350, :position => :center) do text "Span is a different kind of bounding box as it lets the text " + diff --git a/manual/text/group.rb b/manual/text/group.rb index 31c3f3c5e..343f41093 100644 --- a/manual/text/group.rb +++ b/manual/text/group.rb @@ -19,7 +19,7 @@ Prawn::Example.generate(filename) do move_cursor_to 80 text "Let's move to the end of the page so that you can see group in action." - + group do text "This block of text was too big to be rendered on the bottom of the " + " previous page. So it was rendered entirely on this new page. " + diff --git a/manual/text/inline.rb b/manual/text/inline.rb index a262bfdd8..55074ea32 100644 --- a/manual/text/inline.rb +++ b/manual/text/inline.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # Inline formatting gives you the option to format specific portions of a text. # It uses HTML-esque syntax inside the text string. Supported tags are: # b (bold), i (italic), u (underline), @@ -23,18 +23,18 @@ :inline_format => true move_down 10 end - + text "This line uses " + "all the font tag attributes in " + "a single line. ", :inline_format => true move_down 10 - + text "Coloring in both RGB " + "and CMYK", :inline_format => true move_down 10 - + text "This an external link to the " + "Prawn wiki" + " and this is a link to the " + diff --git a/manual/text/kerning_and_character_spacing.rb b/manual/text/kerning_and_character_spacing.rb index df682eeca..228a5243f 100644 --- a/manual/text/kerning_and_character_spacing.rb +++ b/manual/text/kerning_and_character_spacing.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # Kerning is the process of adjusting the spacing between characters in a # proportional font. It is usually done with specific letter pairs. We can # switch it on and off if it is available with the current font. Just pass a @@ -17,19 +17,19 @@ font_size(30) do text_box "With kerning:", :kerning => true, :at => [0, y - 40] text_box "Without kerning:", :kerning => false, :at => [0, y - 80] - + text_box "Tomato", :kerning => true, :at => [250, y - 40] text_box "Tomato", :kerning => false, :at => [250, y - 80] - + text_box "WAR", :kerning => true, :at => [400, y - 40] text_box "WAR", :kerning => false, :at => [400, y - 80] - + text_box "F.", :kerning => true, :at => [500, y - 40] text_box "F.", :kerning => false, :at => [500, y - 80] end - + move_down 80 - + string = "What have you done to the space between the characters?" [-2, -1, 0, 0.5, 1, 2].each do |spacing| move_down 20 diff --git a/manual/text/leading.rb b/manual/text/leading.rb index 51f125461..2098851cb 100644 --- a/manual/text/leading.rb +++ b/manual/text/leading.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # Leading is the additional space between lines of text. # # The leading can be set using the default_leading method which @@ -13,13 +13,13 @@ Prawn::Example.generate(filename) do string = "Hey, what did you do with the space between my lines? " * 10 text string, :leading => 0 - + move_down 20 default_leading 5 text string - + move_down 20 text string, :leading => 10 - + default_leading 0 # back to normal end diff --git a/manual/text/line_wrapping.rb b/manual/text/line_wrapping.rb index 553b9b38e..b584cef27 100644 --- a/manual/text/line_wrapping.rb +++ b/manual/text/line_wrapping.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # Line wrapping happens on white space or hyphens. Soft hyphens can be used to # indicate where words can be hyphenated. Non-breaking spaces can be used to # display space without allowing for a break. @@ -22,7 +22,7 @@ "Slip slid#{shy}ing away, slip slid#{shy}ing away. You know the " + "nearer your destinat#{shy}ion the more you're slip slid#{shy}ing away." move_down 20 - + nbsp = Prawn::Text::NBSP text "Non-breaking spaces:\n" + "Slip#{nbsp}sliding away, slip#{nbsp}sliding awaaaay. You know the " + @@ -33,7 +33,7 @@ long_text = "No word boundaries:\n更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历您的DB中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事,这样的话,你就非常被动了。更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历您的DB中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事,这样的话,你就非常被动了。" text long_text move_down 20 - + zwsp = Prawn::Text::ZWSP long_text = "Invisible word boundaries:\n更#{zwsp}可怕的#{zwsp}是,#{zwsp}同质化#{zwsp}竞争#{zwsp}对#{zwsp}手#{zwsp}可以#{zwsp}按照#{zwsp}URL#{zwsp}中#{zwsp}后面#{zwsp}这个#{zwsp}ID#{zwsp}来#{zwsp}遍历#{zwsp}您的#{zwsp}DB#{zwsp}中的#{zwsp}内容,#{zwsp}写个#{zwsp}小爬虫#{zwsp}把#{zwsp}你的#{zwsp}页面#{zwsp}上的#{zwsp}关#{zwsp}键#{zwsp}信#{zwsp}息顺#{zwsp}次#{zwsp}爬#{zwsp}下来#{zwsp}也#{zwsp}不是#{zwsp}什么#{zwsp}难事,#{zwsp}这样的话,#{zwsp}你#{zwsp}就#{zwsp}非常#{zwsp}被动了。#{zwsp}更#{zwsp}可怕的#{zwsp}是,#{zwsp}同质化#{zwsp}竞争#{zwsp}对#{zwsp}手#{zwsp}可以#{zwsp}按照#{zwsp}URL#{zwsp}中#{zwsp}后面#{zwsp}这个#{zwsp}ID#{zwsp}来#{zwsp}遍历#{zwsp}您的#{zwsp}DB#{zwsp}中的#{zwsp}内容,#{zwsp}写个#{zwsp}小爬虫#{zwsp}把#{zwsp}你的#{zwsp}页面#{zwsp}上的#{zwsp}关#{zwsp}键#{zwsp}信#{zwsp}息顺#{zwsp}次#{zwsp}爬#{zwsp}下来#{zwsp}也#{zwsp}不是#{zwsp}什么#{zwsp}难事,#{zwsp}这样的话,#{zwsp}你#{zwsp}就#{zwsp}非常#{zwsp}被动了。" text long_text diff --git a/manual/text/paragraph_indentation.rb b/manual/text/paragraph_indentation.rb index 8cb7d8ec2..774339126 100644 --- a/manual/text/paragraph_indentation.rb +++ b/manual/text/paragraph_indentation.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # Prawn strips all whitespace from the beginning and the end of strings so there # are two ways to indent paragraphs: # @@ -17,7 +17,7 @@ # Using non-breaking spaces text " " * 10 + "This paragraph won't be indented. " * 10 + "\n#{Prawn::Text::NBSP * 10}" + "This one will with NBSP. " * 10 - + move_down 20 text "This paragraph will be indented. " * 10 + "\n" + "This one will too. " * 10, diff --git a/manual/text/positioned_text.rb b/manual/text/positioned_text.rb index 0323048b3..df6e12978 100644 --- a/manual/text/positioned_text.rb +++ b/manual/text/positioned_text.rb @@ -25,13 +25,13 @@ draw_text "This draw_text line is absolute positioned. However don't " + "expect it to flow even if it hits the document border", :at => [200, 300] - + text_box "This is a text box, you can control where it will flow by " + "specifying the :height and :width options", :at => [100, 250], :height => 100, :width => 100 - + text_box "Another text box with no :width option passed, so it will " + "flow to a new line whenever it reaches the right margin. ", :at => [200, 100] diff --git a/manual/text/registering_families.rb b/manual/text/registering_families.rb index bf6d784a7..43da5892f 100644 --- a/manual/text/registering_families.rb +++ b/manual/text/registering_families.rb @@ -17,12 +17,12 @@ font_families.update("Chalkboard" => { :normal => "#{Prawn::DATADIR}/fonts/Chalkboard.ttf" }) - + font("Chalkboard") do text "Using the Chalkboard font providing only its name to the font method" end move_down 20 - + # Registering a DFONT package font_path = "#{Prawn::DATADIR}/fonts/Action Man.dfont" font_families.update("Action Man" => { @@ -31,20 +31,20 @@ :bold => { :file => font_path, :font => "ActionMan-Bold" }, :bold_italic => { :file => font_path, :font => "ActionMan-BoldItalic" } }) - + font "Action Man" text "Also using the Action Man by providing only its name" move_down 20 - + text "Taking advantage of the inline formatting", :inline_format => true move_down 20 - + [:bold, :bold_italic, :italic, :normal].each do |style| text "Using the #{style} style option.", :style => style move_down 10 end - + font "Helvetica" # Back to normal end diff --git a/manual/text/rendering_and_color.rb b/manual/text/rendering_and_color.rb index 963d3c17b..e79ea7213 100644 --- a/manual/text/rendering_and_color.rb +++ b/manual/text/rendering_and_color.rb @@ -19,7 +19,7 @@ Prawn::Example.generate(filename) do fill_color "00ff00" stroke_color "0000ff" - + font_size(40) do # normal rendering mode: fill text "This text is filled with green." @@ -34,6 +34,6 @@ text "This text is filled with green and stroked with blue" end end - + reset_drawing_settings end diff --git a/manual/text/right_to_left_text.rb b/manual/text/right_to_left_text.rb index 236fcb1e9..806fae063 100644 --- a/manual/text/right_to_left_text.rb +++ b/manual/text/right_to_left_text.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # Prawn can be used with right-to-left text. The direction can be set # document-wide, on particular text, or on a text-box. Setting the direction to # :rtl automatically changes the default alignment to :right diff --git a/manual/text/rotation.rb b/manual/text/rotation.rb index 302536cc2..afa7dca06 100644 --- a/manual/text/rotation.rb +++ b/manual/text/rotation.rb @@ -22,15 +22,15 @@ stroke_rectangle [0, y], width, height text_box("This text was not rotated", :at => [0, y], :width => width, :height => height) - + stroke_rectangle [0, y - 100], width, height text_box("This text was rotated around the center", :at => [0, y - 100], :width => width, :height => height, :rotate => angle, :rotate_around => :center) - + [:lower_left, :upper_left, :lower_right, :upper_right].each_with_index do |around, index| - + y = y - 100 if index == 2 stroke_rectangle [x + (index % 2) * 200, y], width, height text_box("This text was rotated around the #{around} corner.", diff --git a/manual/text/single_usage.rb b/manual/text/single_usage.rb index 772280297..9f38ea119 100644 --- a/manual/text/single_usage.rb +++ b/manual/text/single_usage.rb @@ -21,10 +21,10 @@ text "Written with the Chalkboard TTF font." end move_down 20 - + text "Written with the default font." move_down 20 - + # Using an DFONT font file font "#{Prawn::DATADIR}/fonts/Action Man.dfont" do text "Written with the Action Man DFONT font" diff --git a/manual/text/text.rb b/manual/text/text.rb index 608566957..76171f714 100644 --- a/manual/text/text.rb +++ b/manual/text/text.rb @@ -45,7 +45,7 @@ ] ] ] - + ) do text "This is probably the feature people will use the most. There is no shortage of options when it comes to text. You'll be hard pressed to find a use case that is not covered by one of the text methods and confgurable options. diff --git a/manual/text/text_box_excess.rb b/manual/text/text_box_excess.rb index 56f3a0576..72190b44b 100644 --- a/manual/text/text_box_excess.rb +++ b/manual/text/text_box_excess.rb @@ -24,7 +24,7 @@ :overflow => :truncate, :at => [100, y_position], :size => 18 - + text_box excess_text, :width => 300, :at => [100, y_position - 50] diff --git a/manual/text/text_box_extensions.rb b/manual/text/text_box_extensions.rb index 71c5388e8..d9ff907b6 100644 --- a/manual/text/text_box_extensions.rb +++ b/manual/text/text_box_extensions.rb @@ -24,14 +24,14 @@ def available_width y_position = cursor - 10 width = 100 height = 100 - + Prawn::Text::Box.extensions << TriangleBox stroke_rectangle([0, y_position], width, height) text_box("A" * 100, :at => [0, y_position], :width => width, :height => height) - + Prawn::Text::Formatted::Box.extensions << TriangleBox stroke_rectangle([200, y_position], width, height) formatted_text_box([:text => "A" * 100, :color => "009900"], diff --git a/manual/text/text_box_overflow.rb b/manual/text/text_box_overflow.rb index ae8ef503b..474bacd6f 100644 --- a/manual/text/text_box_overflow.rb +++ b/manual/text/text_box_overflow.rb @@ -21,17 +21,17 @@ "behave with the various overflow options used." text string - + y_position = cursor - 20 [:truncate, :expand, :shrink_to_fit].each_with_index do |mode, i| text_box string, :at => [i * 150, y_position], :width => 100, :height => 50, :overflow => mode end - + string = "If the box is too small for the text, :shrink_to_fit " + "can render the text in a really small font size." - + move_down 120 text string y_position = cursor - 20 diff --git a/manual/text/utf8.rb b/manual/text/utf8.rb index 5ef234e41..df79ed674 100644 --- a/manual/text/utf8.rb +++ b/manual/text/utf8.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # Multilingualization isn't much of a problem on Prawn as its default encoding # is UTF-8. The only thing you need to worry about is if the font support the # glyphs of your language. @@ -12,15 +12,15 @@ text "Take this example, a simple Euro sign:" text "€", :size => 32 move_down 20 - + text "Seems ok. Now let's try something more complex:" text "ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει." move_down 20 - + text "Looks like the current font (#{font.inspect}) doesn't support those." text "Let's try them with another font." move_down 20 - + font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf") do text "ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει." text "There you go." diff --git a/spec/annotations_spec.rb b/spec/annotations_spec.rb index 2943b1898..0496cd8ad 100644 --- a/spec/annotations_spec.rb +++ b/spec/annotations_spec.rb @@ -1,7 +1,7 @@ # encoding: utf-8 -require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") - +require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") + class PageAnnotations attr_reader :pages @@ -20,11 +20,11 @@ def begin_page(params) end end -describe "When creating annotations" do - +describe "When creating annotations" do + before(:each) { create_pdf } - - it "should append annotation to current page" do + + it "should append annotation to current page" do @pdf.start_new_page @pdf.annotate(:Rect => [0,0,10,10], :Subtype => :Text, :Contents => "Hello world!") obj = PageAnnotations.parse(@pdf) @@ -42,14 +42,14 @@ def begin_page(params) end describe "When creating text annotations" do - + before(:each) do @rect = [0,0,10,10] @content = "Hello, world!" create_pdf end - - it "should build appropriate annotation" do + + it "should build appropriate annotation" do opts = @pdf.text_annotation(@rect, @content) opts[:Type].should == :Annot opts[:Subtype].should == :Text @@ -57,7 +57,7 @@ def begin_page(params) opts[:Contents].should == @content end - it "should merge extra options" do + it "should merge extra options" do opts = @pdf.text_annotation(@rect, @content, :Open => true, :Subtype => :Bogus) opts[:Subtype].should == :Text opts[:Open].should == true @@ -66,14 +66,14 @@ def begin_page(params) end describe "When creating link annotations" do - + before(:each) do @rect = [0,0,10,10] @dest = "home" create_pdf end - - it "should build appropriate annotation" do + + it "should build appropriate annotation" do opts = @pdf.link_annotation(@rect, :Dest => @dest) opts[:Type].should == :Annot opts[:Subtype].should == :Link @@ -81,7 +81,7 @@ def begin_page(params) opts[:Dest].should == @dest end - it "should merge extra options" do + it "should merge extra options" do opts = @pdf.link_annotation(@rect, :Dest => @dest, :Subtype => :Bogus) opts[:Subtype].should == :Link opts[:Dest].should == @dest diff --git a/spec/cell_spec.rb b/spec/cell_spec.rb index 28e6b9e7c..d6cc7ffc0 100644 --- a/spec/cell_spec.rb +++ b/spec/cell_spec.rb @@ -1,6 +1,6 @@ # encoding: utf-8 -require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") +require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") module CellHelpers @@ -56,20 +56,20 @@ def close?(actual, expected, epsilon=0.01) @pdf.expects(:move_down) @pdf.expects(:draw_text!).with { |text, options| text == "hello world" } - @pdf.cell(:content => "hello world", + @pdf.cell(:content => "hello world", :at => [10, 20], :padding => [30, 40], - :size => 7, + :size => 7, :font_style => :bold) end end - + describe "Prawn::Document#make_cell" do it "should not draw the cell" do Prawn::Table::Cell::Text.any_instance.expects(:draw).never @pdf.make_cell("text") end - + it "should return a Cell" do @pdf.make_cell("text", :size => 7).should.be.a.kind_of Prawn::Table::Cell end @@ -117,7 +117,7 @@ def close?(actual, expected, epsilon=0.01) it "should return proper width with size set" do text = "text " * 4 c = cell(:content => text, :size => 7) - c.width.should == + c.width.should == @pdf.width_of(text, :size => 7) + c.padding[1] + c.padding[3] end @@ -164,7 +164,7 @@ def close?(actual, expected, epsilon=0.01) it "should be calculated for text" do c = cell(:content => "text") - c.height.should == + c.height.should == @pdf.height_of("text", :width => @pdf.width_of("text")) + c.padding[0] + c.padding[3] end @@ -211,7 +211,7 @@ def close?(actual, expected, epsilon=0.01) c = cell(:content => "text", :padding => 10) c.content_height.should == @pdf.height_of("text") end - + it "content_height should exclude padding even with manual :height" do c = cell(:content => "text", :padding => 10, :height => 400) c.content_height.should.be.close(380, 0.01) @@ -235,7 +235,7 @@ def close?(actual, expected, epsilon=0.01) c = cell(:content => "text", :padding => [20, 30]) c.padding.should == [20, 30, 20, 30] end - + it "should accept [t,h,b]" do c = cell(:content => "text", :padding => [10, 20, 30]) c.padding.should == [10, 20, 30, 20] diff --git a/spec/destinations_spec.rb b/spec/destinations_spec.rb index c31204d3e..b9205049e 100644 --- a/spec/destinations_spec.rb +++ b/spec/destinations_spec.rb @@ -1,12 +1,12 @@ # encoding: utf-8 -require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") +require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") + +describe "When creating destinations" do -describe "When creating destinations" do - before(:each) { create_pdf } - - it "should add entry to Dests name tree" do + + it "should add entry to Dests name tree" do @pdf.dests.data.empty?.should == true @pdf.add_dest "candy", "chocolate" @pdf.dests.data.size.should == 1 diff --git a/spec/document_spec.rb b/spec/document_spec.rb index e1624cd80..232139a23 100644 --- a/spec/document_spec.rb +++ b/spec/document_spec.rb @@ -1,7 +1,7 @@ # encoding: utf-8 require "tempfile" -require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") +require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") describe "Prawn::Document.new" do it "should not modify its argument" do @@ -15,9 +15,9 @@ it "should equal pdf.y - bounds.absolute_bottom" do pdf = Prawn::Document.new pdf.cursor.should == pdf.bounds.top - + pdf.y = 300 - pdf.cursor.should == pdf.y - pdf.bounds.absolute_bottom + pdf.cursor.should == pdf.y - pdf.bounds.absolute_bottom end it "should be able to move relative to the bottom margin" do @@ -27,12 +27,12 @@ pdf.cursor.should == 10 pdf.y.should == pdf.cursor + pdf.bounds.absolute_bottom end -end +end describe "when generating a document from a subclass" do it "should be an instance of the subclass" do custom_document = Class.new(Prawn::Document) - custom_document.generate(Tempfile.new("generate_test").path) do |e| + custom_document.generate(Tempfile.new("generate_test").path) do |e| e.class.should == custom_document e.should.be.kind_of(Prawn::Document) end @@ -63,27 +63,27 @@ end - -describe "When creating multi-page documents" do - + +describe "When creating multi-page documents" do + before(:each) { create_pdf } - - it "should initialize with a single page" do + + it "should initialize with a single page" do page_counter = PDF::Inspector::Page.analyze(@pdf.render) - - page_counter.pages.size.should == 1 - @pdf.page_count.should == 1 + + page_counter.pages.size.should == 1 + @pdf.page_count.should == 1 end - + it "should provide an accurate page_count" do - 3.times { @pdf.start_new_page } + 3.times { @pdf.start_new_page } page_counter = PDF::Inspector::Page.analyze(@pdf.render) - + page_counter.pages.size.should == 4 @pdf.page_count.should == 4 - end - -end + end + +end describe "When beginning each new page" do @@ -102,11 +102,11 @@ @pdf.instance_variable_defined?(:@background).should == true @pdf.instance_variable_get(:@background).should == @filename end - - + + end - - + + end describe "Prawn::Document#float" do @@ -119,7 +119,7 @@ it "should teleport across pages if necessary" do create_pdf - + @pdf.float do @pdf.text "Foo" @pdf.start_new_page @@ -156,7 +156,7 @@ describe "on_page_create callback" do before do - create_pdf + create_pdf end it "should be invoked with document" do @@ -177,34 +177,34 @@ 5.times { @pdf.start_new_page } end - + it "should be replaceable" do trigger1 = mock() trigger1.expects(:fire).times(1) - + trigger2 = mock() trigger2.expects(:fire).times(1) @pdf.on_page_create { trigger1.fire } - + @pdf.start_new_page - + @pdf.on_page_create { trigger2.fire } - + @pdf.start_new_page end - + it "should be clearable by calling on_page_create without a block" do trigger = mock() trigger.expects(:fire).times(1) @pdf.on_page_create { trigger.fire } - @pdf.start_new_page - + @pdf.start_new_page + @pdf.on_page_create - - @pdf.start_new_page + + @pdf.start_new_page end end @@ -240,9 +240,9 @@ end doc_compressed.render.length.should.be < doc_uncompressed.render.length - end + end -end +end describe "Document metadata" do it "should output strings as UTF-16 with a byte order mark" do @@ -262,7 +262,7 @@ pdf.go_to_page 1 pdf.text "More for page 1" end - + # MalformedPDFError raised if content stream actual length does not match # dictionary length lambda{ PDF::Inspector::Page.analyze(@pdf.render) }. @@ -298,21 +298,21 @@ it "should default to LETTER" do @pdf = Prawn::Document.new pages = PDF::Inspector::Page.analyze(@pdf.render).pages - pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["LETTER"] - end - + pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["LETTER"] + end + (Prawn::Document::PageGeometry::SIZES.keys - ["LETTER"]).each do |k| it "should provide #{k} geometry" do @pdf = Prawn::Document.new(:page_size => k) - pages = PDF::Inspector::Page.analyze(@pdf.render).pages + pages = PDF::Inspector::Page.analyze(@pdf.render).pages pages.first[:size].should == Prawn::Document::PageGeometry::SIZES[k] end end - - it "should allow custom page size" do + + it "should allow custom page size" do @pdf = Prawn::Document.new(:page_size => [1920, 1080] ) - pages = PDF::Inspector::Page.analyze(@pdf.render).pages - pages.first[:size].should == [1920, 1080] + pages = PDF::Inspector::Page.analyze(@pdf.render).pages + pages.first[:size].should == [1920, 1080] end @@ -325,14 +325,14 @@ end end -end +end describe "When setting page layout" do it "should reverse coordinates for landscape" do @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape) - pages = PDF::Inspector::Page.analyze(@pdf.render).pages + pages = PDF::Inspector::Page.analyze(@pdf.render).pages pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["A4"].reverse - end + end it "should retain page layout by default when starting a new page" do @pdf = Prawn::Document.new(:page_layout => :landscape) @@ -362,7 +362,7 @@ @pdf.line_width.should.not == line_width end @pdf.y.should == y - @pdf.line_width.should == line_width + @pdf.line_width.should == line_width end end @@ -433,14 +433,14 @@ it "should trigger before_render callbacks just before rendering" do pdf = Prawn::Document.new - + seq = sequence("callback_order") # Verify the order: finalize -> fire callbacks -> render body pdf.expects(:finalize_all_page_contents).in_sequence(seq) trigger = mock() trigger.expects(:fire).in_sequence(seq) - + # Store away the render_body method to be called below render_body = pdf.method(:render_body) pdf.expects(:render_body).in_sequence(seq) @@ -464,10 +464,10 @@ describe "The :optimize_objects option" do before(:all) do @wasteful_doc = lambda do |pdf| - pdf.transaction do + pdf.transaction do pdf.start_new_page pdf.text "Hidden text" - pdf.rollback + pdf.rollback end pdf.text "Hello world" @@ -483,7 +483,7 @@ it "should default to :false" do default_pdf = Prawn::Document.new(&@wasteful_doc) - wasteful_pdf = Prawn::Document.new(:optimize_objects => false, + wasteful_pdf = Prawn::Document.new(:optimize_objects => false, &@wasteful_doc) default_pdf.render.size.should == wasteful_pdf.render.size end @@ -565,25 +565,25 @@ before do @pdf = Prawn::Document.new(:skip_page_creation => true) end - + it "replaces the '' string with the proper page number" do @pdf.start_new_page @pdf.expects(:text_box).with("1, test", { :height => 50 }) @pdf.number_pages ", test", {:page_filter => :all} end - + it "replaces the '' string with the total page count" do @pdf.start_new_page @pdf.expects(:text_box).with("test, 1", { :height => 50 }) @pdf.number_pages "test, ", {:page_filter => :all} end - + it "must print each page if given the :all page_filter" do 10.times { @pdf.start_new_page } @pdf.expects(:text_box).times(10) @pdf.number_pages "test", {:page_filter => :all} end - + it "must print each page if no :page_filter is specified" do 10.times { @pdf.start_new_page } @pdf.expects(:text_box).times(10) @@ -595,8 +595,8 @@ @pdf.expects(:text_box).never @pdf.number_pages "test", {:page_filter => nil} end - - context "start_count_at option" do + + context "start_count_at option" do [1, 2].each do |startat| context "equal to #{startat}" do it "increments the pages" do @@ -605,10 +605,10 @@ @pdf.expects(:text_box).with("#{startat} 2", { :height => 50 }) @pdf.expects(:text_box).with("#{startat+1} 2", { :height => 50 }) @pdf.number_pages " ", options - end + end end end - + [0, nil].each do |val| context "equal to #{val}" do it "defaults to start at page 1" do @@ -622,7 +622,7 @@ end end end - + context "total_pages option" do it "allows the total pages count to be overridden" do 2.times { @pdf.start_new_page } @@ -631,7 +631,7 @@ @pdf.number_pages " ", :page_filter => :all, :total_pages => 10 end end - + context "special page filter" do context "such as :odd" do it "increments the pages" do @@ -683,11 +683,11 @@ @pdf = Prawn::Document.new(:skip_page_creation => true) 10.times {@pdf.start_new_page} end - + it "returns nil given no filter" do assert ! @pdf.page_match?(:nil, 1) end - + it "must provide an :all filter" do assert (1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) } end @@ -711,5 +711,5 @@ it "must be able to filter by an arbitrary proc" do fltr = lambda { |x| x == 1 or x % 3 == 0 } assert_equal [1,3,6,9], (1..10).select { |i| @pdf.page_match?(fltr, i) } - end + end end diff --git a/spec/font_spec.rb b/spec/font_spec.rb index 2efa142ac..ebc05244c 100644 --- a/spec/font_spec.rb +++ b/spec/font_spec.rb @@ -1,9 +1,9 @@ # encoding: utf-8 -require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") +require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") require 'iconv' -describe "Font behavior" do +describe "Font behavior" do it "should default to Helvetica if no font is specified" do @pdf = Prawn::Document.new @@ -38,7 +38,7 @@ @pdf.font("Helvetica", :style => :bold) { @bold_hello = @pdf.width_of("hello") } - + inline_bold_hello.should.be > normal_hello inline_bold_hello.should == @bold_hello end @@ -65,33 +65,33 @@ describe "font style support" do before(:each) { create_pdf } - + it "should complain if there is no @current_page" do pdf_without_page = Prawn::Document.new(:skip_page_creation => true) lambda{ pdf_without_page.font "Helvetica" }. should.raise(Prawn::Errors::NotOnPage) end - - it "should allow specifying font style by style name and font family" do + + it "should allow specifying font style by style name and font family" do @pdf.font "Courier", :style => :bold - @pdf.text "In Courier bold" - + @pdf.text "In Courier bold" + @pdf.font "Courier", :style => :bold_italic - @pdf.text "In Courier bold-italic" - + @pdf.text "In Courier bold-italic" + @pdf.font "Courier", :style => :italic - @pdf.text "In Courier italic" - + @pdf.text "In Courier italic" + @pdf.font "Courier", :style => :normal - @pdf.text "In Normal Courier" - + @pdf.text "In Normal Courier" + @pdf.font "Helvetica" - @pdf.text "In Normal Helvetica" - + @pdf.text "In Normal Helvetica" + text = PDF::Inspector::Text.analyze(@pdf.render) - text.font_settings.map { |e| e[:name] }.should == - [:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique", + text.font_settings.map { |e| e[:name] }.should == + [:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique", :Courier, :Helvetica] end @@ -116,20 +116,20 @@ describe "Transactional font handling" do before(:each) { create_pdf } - + it "should allow setting of size directly when font is created" do @pdf.font "Courier", :size => 16 - @pdf.font_size.should == 16 + @pdf.font_size.should == 16 end - + it "should allow temporary setting of a new font using a transaction" do @pdf.font "Helvetica", :size => 12 - + @pdf.font "Courier", :size => 16 do @pdf.font.name.should == "Courier" @pdf.font_size.should == 16 end - + @pdf.font.name.should == "Helvetica" @pdf.font_size.should == 12 end @@ -144,57 +144,57 @@ @pdf.font_size.should == 12 end - + end describe "Document#page_fonts" do - before(:each) { create_pdf } - + before(:each) { create_pdf } + it "should register fonts properly by page" do @pdf.font "Courier"; @pdf.text("hello") @pdf.font "Helvetica"; @pdf.text("hello") @pdf.font "Times-Roman"; @pdf.text("hello") ["Courier","Helvetica","Times-Roman"].each { |f| page_should_include_font(f) - } - - @pdf.start_new_page + } + + @pdf.start_new_page @pdf.font "Helvetica"; @pdf.text("hello") page_should_include_font("Helvetica") page_should_not_include_font("Courier") page_should_not_include_font("Times-Roman") - end - + end + def page_includes_font?(font) @pdf.page.fonts.values.map { |e| e.data[:BaseFont] }.include?(font.to_sym) - end - - def page_should_include_font(font) + end + + def page_should_include_font(font) assert_block("Expected page to include font: #{font}") do page_includes_font?(font) end - end - + end + def page_should_not_include_font(font) assert_block("Did not expect page to include font: #{font}") do - not page_includes_font?(font) + not page_includes_font?(font) end end - + end - + describe "AFM fonts" do - + setup do create_pdf @times = @pdf.find_font "Times-Roman" @iconv = ::Iconv.new('Windows-1252', 'utf-8') end - + it "should calculate string width taking into account accented characters" do @times.compute_width_of(@iconv.iconv("é"), :size => 12).should == @times.compute_width_of("e", :size => 12) end - + it "should calculate string width taking into account kerning pairs" do @times.compute_width_of(@iconv.iconv("To"), :size => 12).should == 13.332 @times.compute_width_of(@iconv.iconv("To"), :size => 12, :kerning => true).should == 12.372 @@ -236,7 +236,7 @@ def page_should_not_include_font(font) font_dict = zapf.send(:register, nil) font_dict.data[:Encoding].should == nil end - + end describe "#glyph_present" do @@ -267,21 +267,21 @@ def page_should_not_include_font(font) end describe "TTF fonts" do - + setup do create_pdf @activa = @pdf.find_font "#{Prawn::DATADIR}/fonts/Activa.ttf" end - + it "should calculate string width taking into account accented characters" do @activa.compute_width_of("é", :size => 12).should == @activa.compute_width_of("e", :size => 12) end - + it "should calculate string width taking into account kerning pairs" do @activa.compute_width_of("To", :size => 12).should == 15.228 @activa.compute_width_of("To", :size => 12, :kerning => true).should == 12.996 end - + it "should encode text without kerning by default" do @activa.encode_text("To").should == [[0, "To"]] @@ -332,7 +332,7 @@ def page_should_not_include_font(font) end describe "when used with snapshots or transactions" do - + it "should allow TTF fonts to be used alongside document transactions" do lambda { Prawn::Document.new do @@ -358,7 +358,7 @@ def page_should_not_include_font(font) end end - + end describe "DFont fonts" do diff --git a/spec/formatted_text_box_spec.rb b/spec/formatted_text_box_spec.rb index 022a0a430..b1c6205c8 100644 --- a/spec/formatted_text_box_spec.rb +++ b/spec/formatted_text_box_spec.rb @@ -84,7 +84,7 @@ end text_box.text.should == "Noua Delineatio Geographica\ngeneralis | Apostolicarum\nperegrinationum | S FRANCISCI\nXAUERII | Indiarum & Iaponi\346\nApostoli" end - + describe "Unicode" do before do if RUBY_VERSION < '1.9' @@ -96,7 +96,7 @@ Encoding.default_internal = Encoding::UTF_8 end end - + after do if RUBY_VERSION < '1.9' $KCODE=@reset_value diff --git a/spec/formatted_text_fragment_spec.rb b/spec/formatted_text_fragment_spec.rb index a1c0dfac3..385cc8cf2 100644 --- a/spec/formatted_text_fragment_spec.rb +++ b/spec/formatted_text_fragment_spec.rb @@ -75,7 +75,7 @@ @fragment.ascender = 17 @fragment.word_spacing = 10 end - + it "should account for word_spacing in #width" do @fragment.width.should == 110 end @@ -122,7 +122,7 @@ @fragment.descender = 7 @fragment.ascender = 17 end - + describe "#width" do it "should return the width" do @fragment.width.should == 100 diff --git a/spec/graphics_spec.rb b/spec/graphics_spec.rb index 6aeb83caf..a4dae93b4 100644 --- a/spec/graphics_spec.rb +++ b/spec/graphics_spec.rb @@ -121,7 +121,7 @@ curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render) curve.coords.should == [100.0, 100.0, 20.0, 90.0, 90.0, 75.0, 50.0, 50.0] end - + end @@ -141,19 +141,19 @@ line_points.zip(curves).flatten.each_slice(2) {|p| @all_coords << p } @all_coords.unshift @original_point end - + it "should draw a rectangle by connecting lines with rounded bezier curves" do - @all_coords.should == [[60.0, 550.0],[90.0, 550.0], [95.523, 550.0], [100.0, 545.523], [100.0, 540.0], - [100.0, 460.0], [100.0, 454.477], [95.523, 450.0], [90.0, 450.0], - [60.0, 450.0], [54.477, 450.0], [50.0, 454.477], [50.0, 460.0], + @all_coords.should == [[60.0, 550.0],[90.0, 550.0], [95.523, 550.0], [100.0, 545.523], [100.0, 540.0], + [100.0, 460.0], [100.0, 454.477], [95.523, 450.0], [90.0, 450.0], + [60.0, 450.0], [54.477, 450.0], [50.0, 454.477], [50.0, 460.0], [50.0, 540.0], [50.0, 545.523], [54.477, 550.0], [60.0, 550.0]] end - + it "should start and end with the same point" do @original_point.should == @all_coords.last end - - + + end describe "When drawing an ellipse" do @@ -162,27 +162,27 @@ @pdf.ellipse [100,100], 25, 50 @curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render) end - + it "should use a Bézier approximation" do - @curve.coords.should == + @curve.coords.should == [125.0, 100.0, 125.0, 127.614, 113.807, 150, 100.0, 150.0, - + 86.193, 150.0, 75.0, 127.614, 75.0, 100.0, - + 75.0, 72.386, 86.193, 50.0, 100.0, 50.0, - + 113.807, 50.0, 125.0, 72.386, 125.0, 100.0, - + 100.0, 100.0] end @@ -268,7 +268,7 @@ colors.fill_color.should == [0.8,1.0,0.0] colors.stroke_color.should == [1.0,0.0,0.8] end - + it "should set the color space when setting colors on new pages to please fussy readers" do @pdf.stroke_color "000000" @pdf.stroke { @pdf.rectangle([10, 10], 10, 10) } @@ -339,80 +339,80 @@ describe "When using graphics states" do before(:each) { create_pdf } - + it "should add the right content on save_graphics_state" do @pdf.expects(:add_content).with('q') - + @pdf.save_graphics_state end - + it "should add the right content on restore_graphics_state" do @pdf.expects(:add_content).with('Q') - + @pdf.restore_graphics_state end - + it "should save and restore when save_graphics_state is used with a block" do state = sequence "state" @pdf.expects(:add_content).with('q').in_sequence(state) @pdf.expects(:foo).in_sequence(state) @pdf.expects(:add_content).with('Q').in_sequence(state) - + @pdf.save_graphics_state do @pdf.foo end end - + it "should add the previous color space when restoring to a graphic state with different color space" do @pdf.stroke_color '000000' @pdf.save_graphics_state @pdf.stroke_color 0, 0, 0, 0 - @pdf.restore_graphics_state + @pdf.restore_graphics_state @pdf.stroke_color 0, 0, 100, 0 @pdf.graphic_state.color_space.should == {:stroke=>:DeviceCMYK} colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render) colors.color_space.should == :DeviceCMYK colors.stroke_color_space_count[:DeviceCMYK].should == 2 end - + it "should use the correct dash setting after restoring and starting new page" do @pdf.dash 5 @pdf.save_graphics_state @pdf.dash 10 @pdf.graphic_state.dash[:dash].should == 10 - @pdf.restore_graphics_state + @pdf.restore_graphics_state @pdf.start_new_page @pdf.graphic_state.dash[:dash].should == 5 end - + it "the current graphic state should keep track of previous unchanged settings" do @pdf.stroke_color '000000' @pdf.save_graphics_state @pdf.dash 5 @pdf.save_graphics_state @pdf.cap_style :round - @pdf.save_graphics_state + @pdf.save_graphics_state @pdf.fill_color 0, 0, 100, 0 @pdf.save_graphics_state - - @pdf.graphic_state.stroke_color.should == "000000" + + @pdf.graphic_state.stroke_color.should == "000000" @pdf.graphic_state.join_style.should == :miter - @pdf.graphic_state.fill_color.should == [0, 0, 100, 0] - @pdf.graphic_state.cap_style.should == :round - @pdf.graphic_state.color_space.should == {:fill=>:DeviceCMYK, :stroke=>:DeviceRGB} + @pdf.graphic_state.fill_color.should == [0, 0, 100, 0] + @pdf.graphic_state.cap_style.should == :round + @pdf.graphic_state.color_space.should == {:fill=>:DeviceCMYK, :stroke=>:DeviceRGB} @pdf.graphic_state.dash.should == {:space=>5, :phase=>0, :dash=>5} @pdf.graphic_state.line_width.should == 1 end - - - + + + it "should not add extra graphic space closings when rendering multiple times" do @pdf.render state = PDF::Inspector::Graphics::State.analyze(@pdf.render) state.save_graphics_state_count.should == 1 state.restore_graphics_state_count.should == 1 end - + it "should add extra graphic state enclosings when content is added on multiple renderings" do @pdf.render @pdf.text "Adding a bit more content" @@ -420,7 +420,7 @@ state.save_graphics_state_count.should == 2 state.restore_graphics_state_count.should == 2 end - + it "adds extra graphic state enclosings when new settings are applied on multiple renderings" do @pdf.render @pdf.stroke_color 0, 0, 0, 0 @@ -428,8 +428,8 @@ state.save_graphics_state_count.should == 2 state.restore_graphics_state_count.should == 2 end - - + + it "should raise error if closing an empty graphic stack" do assert_raise Prawn::Errors::EmptyGraphicStateStack do @pdf.render @@ -443,19 +443,19 @@ # Note: The (approximate) number of significant decimal digits of precision in fractional # part is 5 (PDF Reference, Third Edition, p. 706) - + it "should send the right content on transformation_matrix" do @pdf.expects(:add_content).with('1.00000 0.00000 0.12346 -1.00000 5.50000 20.00000 cm') @pdf.transformation_matrix 1, 0, 0.123456789, -1.0, 5.5, 20 end - + it "should use fixed digits with very small number" do values = Array.new(6, 0.000000000001) string = Array.new(6, "0.00000").join " " @pdf.expects(:add_content).with("#{string} cm") @pdf.transformation_matrix *values end - + it "should be received by the inspector" do @pdf.transformation_matrix 1, 0, 0, -1, 5.5, 20 matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render) @@ -466,7 +466,7 @@ values = Array.new(6, 0.000000000001) string = Array.new(6, "0.00000").join " " process = sequence "process" - + @pdf.expects(:save_graphics_state).with().in_sequence(process) @pdf.expects(:add_content).with("#{string} cm").in_sequence(process) @pdf.expects(:do_something).with().in_sequence(process) @@ -475,7 +475,7 @@ @pdf.do_something end end - + end describe "When using transformations shortcuts" do diff --git a/spec/grid_spec.rb b/spec/grid_spec.rb index 64f6ab053..c5c849600 100644 --- a/spec/grid_spec.rb +++ b/spec/grid_spec.rb @@ -1,46 +1,46 @@ # encoding: utf-8 -require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") +require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") describe "A document's grid" do before do @pdf = Prawn::Document.new end - + it "should allow definition of a grid" do @pdf.define_grid(:columns => 5, :rows => 8, :gutter => 0.1) @pdf.grid.columns.should == 5 @pdf.grid.rows.should == 8 @pdf.grid.gutter.should == 0.1 end - + describe "when a grid is defined" do before do @num_columns = 5 @num_rows = 8 @gutter = 10.0 @pdf.define_grid( - :columns => @num_columns, - :rows => @num_rows, + :columns => @num_columns, + :rows => @num_rows, :gutter => @gutter ) end - + it "should compute the column width" do - (@pdf.grid.column_width * @num_columns.to_f + + (@pdf.grid.column_width * @num_columns.to_f + @gutter * (@num_columns - 1).to_f).should == @pdf.bounds.width end - + it "should compute the row height" do - (@pdf.grid.row_height * @num_rows.to_f + + (@pdf.grid.row_height * @num_rows.to_f + @gutter * (@num_rows - 1).to_f).should == @pdf.bounds.height end it "should give the edges of a grid box" do - grid_width = (@pdf.bounds.width.to_f - + grid_width = (@pdf.bounds.width.to_f - (@gutter * (@num_columns - 1).to_f )) / @num_columns.to_f - grid_height = (@pdf.bounds.height.to_f - + grid_height = (@pdf.bounds.height.to_f - (@gutter * (@num_rows - 1).to_f ))/ @num_rows.to_f - + exp_tl_x = (grid_width + @gutter.to_f) * 4.0 exp_tl_y = @pdf.bounds.height.to_f - (grid_height + @gutter.to_f) @@ -64,7 +64,7 @@ colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render) colors.fill_color.should.not == [0.8,0.8,0.8] colors.stroke_color.should.not == [0.8,0.8,0.8] - + # Hardcoded default color as I haven't been able to come up with a stable converter # between fill_color without lots code. #colors.fill_color.should == [0.0,0.0,0.0] diff --git a/spec/images_spec.rb b/spec/images_spec.rb index 825b908d7..8612dd525 100644 --- a/spec/images_spec.rb +++ b/spec/images_spec.rb @@ -1,40 +1,40 @@ # encoding: utf-8 -require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") +require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") require 'set' require 'pathname' describe "the image() function" do before(:each) do - @filename = "#{Prawn::DATADIR}/images/pigs.jpg" + @filename = "#{Prawn::DATADIR}/images/pigs.jpg" create_pdf end it "should only embed an image once, even if it's added multiple times" do @pdf.image @filename, :at => [100,100] @pdf.image @filename, :at => [300,300] - + output = @pdf.render images = PDF::Inspector::XObject.analyze(output) # there should be 2 images in the page resources images.page_xobjects.first.size.should == 2 # but only 1 image xobject output.scan(/\/Type \/XObject/).size.should == 1 - end - + end + it "should return the image info object" do info = @pdf.image(@filename) - + info.should.be.kind_of(Prawn::Images::JPG) - + info.height.should == 453 end - + it "should accept IO objects" do file = File.open(@filename, "rb") info = @pdf.image(file) - + info.height.should == 453 end @@ -69,25 +69,25 @@ output.should =~ /\/BitsPerComponent 16/ output.should =~ /\/BitsPerComponent 8/ end - + it "should flow an image to a new page if it will not fit on a page" do @pdf.image @filename, :fit => [600, 600] @pdf.image @filename, :fit => [600, 600] output = StringIO.new(@pdf.render, 'r+') hash = PDF::Reader::ObjectHash.new(output) pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids] - pages.size.should == 2 + pages.size.should == 2 hash[pages[0]][:Resources][:XObject].keys.should == [:I1] hash[pages[1]][:Resources][:XObject].keys.should == [:I2] - end - + end + it "should not flow an image to a new page if it will fit on one page" do @pdf.image @filename, :fit => [400, 400] @pdf.image @filename, :fit => [400, 400] output = StringIO.new(@pdf.render, 'r+') hash = PDF::Reader::ObjectHash.new(output) pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids] - pages.size.should == 1 + pages.size.should == 1 Set.new(hash[pages[0]][:Resources][:XObject].keys).should == Set.new([:I1, :I2]) end @@ -98,7 +98,7 @@ @pdf.image @filename end end - + describe ":fit option" do it "should fit inside the defined constraints" do info = @pdf.image @filename, :fit => [100,400] diff --git a/spec/jpg_spec.rb b/spec/jpg_spec.rb index a36b55547..78f51837f 100644 --- a/spec/jpg_spec.rb +++ b/spec/jpg_spec.rb @@ -4,7 +4,7 @@ # contents of palette and transparency to ensure they're correct. # Need to find files that have these sections first. -require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") +require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") describe "When reading a JPEG file" do @@ -12,10 +12,10 @@ @filename = "#{Prawn::DATADIR}/images/pigs.jpg" @img_data = File.open(@filename, "rb") { |f| f.read } end - + it "should read the basic attributes correctly" do jpg = Prawn::Images::JPG.new(@img_data) - + jpg.width.should == 604 jpg.height.should == 453 jpg.bits.should == 8 diff --git a/spec/measurement_units_spec.rb b/spec/measurement_units_spec.rb index d283e5084..24944b1e0 100644 --- a/spec/measurement_units_spec.rb +++ b/spec/measurement_units_spec.rb @@ -1,8 +1,8 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") +require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") require "prawn/measurement_extensions" describe "Measurement units" do - + it "should convert units to PostScriptPoints" do 1.mm.should.be.close(2.834645669, 0.000000001) 1.mm.should == (72 / 25.4) @@ -12,12 +12,11 @@ 1.cm.should == 10 * 72 / 25.4 1.dm.should == 100 * 72 / 25.4 1.m.should == 1000 * 72 / 25.4 - + 1.in.should == 72 1.ft.should == 72 * 12 1.yd.should == 72 * 12 * 3 1.pt.should == 1 end - + end - \ No newline at end of file diff --git a/spec/name_tree_spec.rb b/spec/name_tree_spec.rb index 74bab1b1f..9ede56ef3 100644 --- a/spec/name_tree_spec.rb +++ b/spec/name_tree_spec.rb @@ -24,7 +24,7 @@ def object_store end end -describe "Name Tree" do +describe "Name Tree" do before(:each) { create_pdf(RefExposingDocument) } it "should have no children when first initialized" do @@ -50,7 +50,7 @@ def object_store tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4]) @pdf.object_store.length.should.equal ref_count+2 end - + it "should create a one new reference when subtree is split" do node = Prawn::Core::NameTree::Node.new(@pdf, 3) tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4]) diff --git a/spec/object_store_spec.rb b/spec/object_store_spec.rb index b28f5211a..de43dd8a7 100644 --- a/spec/object_store_spec.rb +++ b/spec/object_store_spec.rb @@ -99,7 +99,7 @@ store.ref(:some => "structure") old_size = store.size store.compact - + store.size.should.be < old_size store.map{ |o| o.identifier }.should == (1..store.size).to_a end @@ -110,7 +110,7 @@ store.info.data[:Blah] = :overwritten old_size = store.size store.compact - + store.size.should.be < old_size store.map{ |o| o.identifier }.should == (1..store.size).to_a end diff --git a/spec/outline_spec.rb b/spec/outline_spec.rb index 94c70838c..bc9403696 100644 --- a/spec/outline_spec.rb +++ b/spec/outline_spec.rb @@ -120,11 +120,11 @@ @outline_root[:Count].should == 5 end - end - - describe "#outline.add_subsection_to" do + end + + describe "#outline.add_subsection_to" do context "positioned last" do - + before(:each) do @pdf.start_new_page @pdf.text "Page 3. An added subsection " @@ -133,45 +133,45 @@ section 'Added SubSection', :destination => 3 do page :destination => 3, :title => 'Added Page 3' end - end + end end render_and_find_objects end - + it "should add new outline items to document" do [@subsection, @added_page_3].each { |item| assert_not_nil item} end - + it "should reset the last item for parent item dictionary" do referenced_object(@section_1[:First]).should == @page_1 referenced_object(@section_1[:Last]).should == @subsection end - + it "should set the prev relation for the new subsection to its parent's old last item" do referenced_object(@subsection[:Prev]).should == @page_2 end - - + + it "the subsection should become the next relation for its parent's old last item" do referenced_object(@page_2[:Next]).should == @subsection end - + it "should set the first relation for the new subsection" do referenced_object(@subsection[:First]).should == @added_page_3 end - + it "should set the correct last relation of the added to section" do referenced_object(@subsection[:Last]).should == @added_page_3 end - + it "should increase the count of root outline dictionary" do @outline_root[:Count].should == 5 end - - end - + + end + context "positioned first" do - + before(:each) do @pdf.start_new_page @pdf.text "Page 3. An added subsection " @@ -193,7 +193,7 @@ referenced_object(@section_1[:First]).should == @subsection referenced_object(@section_1[:Last]).should == @page_2 end - + it "should set the next relation for the new subsection to its parent's old first item" do referenced_object(@subsection[:Next]).should == @page_1 end @@ -215,7 +215,7 @@ end end - + it "should require an existing title" do assert_raise Prawn::Errors::UnknownOutlineTitle do @pdf.go_to_page 1 @@ -229,7 +229,7 @@ render_and_find_objects end end - end + end describe "#outline.insert_section_after" do describe "inserting in the middle of another section" do @@ -248,45 +248,45 @@ render_and_find_objects assert_not_nil @inserted_page end - + it "should adjust the count of all ancestors" do render_and_find_objects @outline_root[:Count].should == 4 @section_1[:Count].should.abs == 3 end - + describe "#adjust_relations" do - + it "should reset the sibling relations of adjoining items to inserted item" do render_and_find_objects referenced_object(@page_1[:Next]).should == @inserted_page referenced_object(@page_2[:Prev]).should == @inserted_page end - + it "should set the sibling relation of added item to adjoining items" do render_and_find_objects referenced_object(@inserted_page[:Next]).should == @page_2 referenced_object(@inserted_page[:Prev]).should == @page_1 end - + it "should not affect the first and last relations of parent item" do render_and_find_objects referenced_object(@section_1[:First]).should == @page_1 referenced_object(@section_1[:Last]).should == @page_2 end - - end - - - context "when adding another section afterwards" do + + end + + + context "when adding another section afterwards" do it "should have reset the root position so that a new section is added at the end of root sections" do @pdf.start_new_page @pdf.text "Another Inserted Page" @pdf.outline.update do section 'Added Section' do page :destination => page_number, :title => "Inserted Page" - end - end + end + end render_and_find_objects referenced_object(@outline_root[:Last]).should == @section_2 referenced_object(@section_1[:Next]).should == @section_2 @@ -305,7 +305,7 @@ @pdf.outline.update do insert_section_after 'Page 2' do page :destination => page_number, :title => "Inserted Page" - end + end end render_and_find_objects end @@ -357,7 +357,7 @@ end end end - + context "foreign character encoding" do before(:each) do pdf = Prawn::Document.new() do @@ -384,7 +384,7 @@ def render_and_find_objects @page_2 = find_by_title('Page 2') @section_2 = find_by_title('Added Section') @page_3 = find_by_title('Page 3') - @inserted_page = find_by_title('Inserted Page') + @inserted_page = find_by_title('Inserted Page') @subsection = find_by_title('Added SubSection') @added_page_3 = find_by_title('Added Page 3') end diff --git a/spec/pdf_object_spec.rb b/spec/pdf_object_spec.rb index c015256c9..8d2d191b0 100644 --- a/spec/pdf_object_spec.rb +++ b/spec/pdf_object_spec.rb @@ -2,40 +2,40 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") -# See PDF Reference, Sixth Edition (1.7) pp51-60 for details -describe "PDF Object Serialization" do - +# See PDF Reference, Sixth Edition (1.7) pp51-60 for details +describe "PDF Object Serialization" do + it "should convert Ruby's nil to PDF null" do Prawn::Core::PdfObject(nil).should == "null" end - + it "should convert Ruby booleans to PDF booleans" do Prawn::Core::PdfObject(true).should == "true" Prawn::Core::PdfObject(false).should == "false" end - + it "should convert a Ruby number to PDF number" do Prawn::Core::PdfObject(1).should == "1" - Prawn::Core::PdfObject(1.214112421).should == "1.214112421" + Prawn::Core::PdfObject(1.214112421).should == "1.214112421" # scientific notation is not valid in PDF Prawn::Core::PdfObject(0.000005).should == "0.000005" end - + it "should convert a Ruby time object to a PDF timestamp" do t = Time.now Prawn::Core::PdfObject(t).should == t.strftime("(D:%Y%m%d%H%M%S%z").chop.chop + "'00')" end - - it "should convert a Ruby string to PDF string when inside a content stream" do + + it "should convert a Ruby string to PDF string when inside a content stream" do s = "I can has a string" PDF::Inspector.parse(Prawn::Core::PdfObject(s, true)).should == s - end + end - it "should convert a Ruby string to a UTF-16 PDF string when outside a content stream" do + it "should convert a Ruby string to a UTF-16 PDF string when outside a content stream" do s = "I can has a string" s_utf16 = "\xFE\xFF" + s.unpack("U*").pack("n*") PDF::Inspector.parse(Prawn::Core::PdfObject(s, false)).should == s_utf16 - end + end it "should convert a Ruby string with characters outside the BMP to its " + "UTF-16 representation with a BOM" do @@ -48,16 +48,16 @@ Prawn::Core::PdfObject(Prawn::Core::ByteString.new("\xDE\xAD\xBE\xEF")).upcase. should == "" end - + it "should escape parens when converting from Ruby string to PDF" do - s = 'I )(can has a string' + s = 'I )(can has a string' PDF::Inspector.parse(Prawn::Core::PdfObject(s, true)).should == s - end - + end + it "should handle ruby escaped parens when converting to PDF string" do s = 'I can \\)( has string' - PDF::Inspector.parse(Prawn::Core::PdfObject(s, true)).should == s - end + PDF::Inspector.parse(Prawn::Core::PdfObject(s, true)).should == s + end it "should escape various strings correctly when converting a LiteralString" do ls = Prawn::Core::LiteralString.new("abc") @@ -100,7 +100,7 @@ Prawn::Core::PdfObject(:"A;Name_With-Various***Characters?").should == "/A;Name_With-Various***Characters?" end - + it "should convert a whitespace or delimiter containing Ruby symbol to a PDF name" do Prawn::Core::PdfObject(:"my symbol").should == "/my#20symbol" Prawn::Core::PdfObject(:"my#symbol").should == "/my#23symbol" @@ -110,52 +110,52 @@ Prawn::Core::PdfObject(:"mysymbol").should == "/my#3Esymbol" end - + it "should convert a Ruby array to PDF Array when inside a content stream" do Prawn::Core::PdfObject([1,2,3]).should == "[1 2 3]" - PDF::Inspector.parse(Prawn::Core::PdfObject([[1,2],:foo,"Bar"], true)).should == + PDF::Inspector.parse(Prawn::Core::PdfObject([[1,2],:foo,"Bar"], true)).should == [[1,2],:foo, "Bar"] - end + end it "should convert a Ruby array to PDF Array when outside a content stream" do bar = "\xFE\xFF" + "Bar".unpack("U*").pack("n*") Prawn::Core::PdfObject([1,2,3]).should == "[1 2 3]" - PDF::Inspector.parse(Prawn::Core::PdfObject([[1,2],:foo,"Bar"], false)).should == + PDF::Inspector.parse(Prawn::Core::PdfObject([[1,2],:foo,"Bar"], false)).should == [[1,2],:foo, bar] - end - + end + it "should convert a Ruby hash to a PDF Dictionary when inside a content stream" do - dict = Prawn::Core::PdfObject( {:foo => :bar, - "baz" => [1,2,3], - :bang => {:a => "what", :b => [:you, :say] }}, true ) + dict = Prawn::Core::PdfObject( {:foo => :bar, + "baz" => [1,2,3], + :bang => {:a => "what", :b => [:you, :say] }}, true ) - res = PDF::Inspector.parse(dict) + res = PDF::Inspector.parse(dict) res[:foo].should == :bar res[:baz].should == [1,2,3] res[:bang].should == { :a => "what", :b => [:you, :say] } - end + end it "should convert a Ruby hash to a PDF Dictionary when outside a content stream" do what = "\xFE\xFF" + "what".unpack("U*").pack("n*") - dict = Prawn::Core::PdfObject( {:foo => :bar, - "baz" => [1,2,3], + dict = Prawn::Core::PdfObject( {:foo => :bar, + "baz" => [1,2,3], :bang => {:a => "what", :b => [:you, :say] }}, false ) - res = PDF::Inspector.parse(dict) + res = PDF::Inspector.parse(dict) res[:foo].should == :bar res[:baz].should == [1,2,3] res[:bang].should == { :a => what, :b => [:you, :say] } - end - + end + it "should not allow keys other than strings or symbols for PDF dicts" do lambda { Prawn::Core::PdfObject(:foo => :bar, :baz => :bang, 1 => 4) }. - should.raise(Prawn::Errors::FailedObjectConversion) - end - + should.raise(Prawn::Errors::FailedObjectConversion) + end + it "should convert a Prawn::Reference to a PDF indirect object reference" do ref = Prawn::Core::Reference(1,true) Prawn::Core::PdfObject(ref).should == ref.to_s diff --git a/spec/reference_spec.rb b/spec/reference_spec.rb index fe40f7eab..f38b051df 100644 --- a/spec/reference_spec.rb +++ b/spec/reference_spec.rb @@ -6,22 +6,22 @@ it "should produce a PDF reference on #to_s call" do ref = Prawn::Core::Reference(1,true) ref.to_s.should == "1 0 R" - end - + end + it "should allow changing generation number" do ref = Prawn::Core::Reference(1,true) ref.gen = 1 ref.to_s.should == "1 1 R" end - + it "should generate a valid PDF object for the referenced data" do - ref = Prawn::Core::Reference(2,[1,"foo"]) - ref.object.should == "2 0 obj\n#{Prawn::Core::PdfObject([1,"foo"])}\nendobj\n" - end - + ref = Prawn::Core::Reference(2,[1,"foo"]) + ref.object.should == "2 0 obj\n#{Prawn::Core::PdfObject([1,"foo"])}\nendobj\n" + end + it "should automatically open a stream when #<< is used" do ref = Prawn::Core::Reference(1, :Length => 41) - ref << "BT\n/F1 12 Tf\n72 712 Td\n( A stream ) Tj\nET" + ref << "BT\n/F1 12 Tf\n72 712 Td\n( A stream ) Tj\nET" ref.object.should == "1 0 obj\n<< /Length 41\n>>\nstream"+ "\nBT\n/F1 12 Tf\n72 712 Td\n( A stream ) Tj\nET" + "\nendstream\nendobj\n" @@ -35,7 +35,7 @@ cref << "Hi There " * 20 cref.compress_stream - assert cref.stream.size < ref.stream.size, + assert cref.stream.size < ref.stream.size, "compressed stream expected to be smaller than source but wasn't" cref.data[:Filter].should == :FlateDecode end diff --git a/spec/repeater_spec.rb b/spec/repeater_spec.rb index bfbed6b16..036521a69 100644 --- a/spec/repeater_spec.rb +++ b/spec/repeater_spec.rb @@ -150,7 +150,7 @@ def repeater(*args, &b) text.strings.include?("cap_style: round").should == false text.strings.include?("cap_style: butt").should == true end - + end end diff --git a/spec/security_spec.rb b/spec/security_spec.rb index 12ac86bf8..2ebf286f5 100644 --- a/spec/security_spec.rb +++ b/spec/security_spec.rb @@ -1,7 +1,7 @@ # encoding: utf-8 require "tempfile" -require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") +require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") describe "Document encryption" do @@ -31,9 +31,9 @@ end end - + describe "Setting permissions" do - + def doc_with_permissions(permissions) pdf = Prawn::Document.new @@ -120,7 +120,7 @@ class << @pdf Prawn::Core::EncryptedPdfObject(["foo", "bar"], "12345", 123, 0).should == "[<4ad6e3> <4ed8fe>]" end - + end end diff --git a/spec/snapshot_spec.rb b/spec/snapshot_spec.rb index ed8bd9dce..a7c9fc945 100644 --- a/spec/snapshot_spec.rb +++ b/spec/snapshot_spec.rb @@ -23,7 +23,7 @@ end text = PDF::Inspector::Text.analyze(pdf.render) text.strings.should == [] - end + end it "should return true/false value indicating success of the transaction" do Prawn::Document.new do @@ -34,7 +34,7 @@ success.should == false end end - + it "should support nested transactions" do pdf = Prawn::Document.new do transaction do @@ -144,7 +144,7 @@ def add_lines(pdf) lambda { pdf.transaction{} }.should.not.raise end end - + describe "with a stamp dictionary present" do it "should properly commit if no error is raised" do @@ -167,7 +167,7 @@ def add_lines(pdf) end end pdf.render.should.not =~ /\/Stamp1 Do/ - end + end end diff --git a/spec/span_spec.rb b/spec/span_spec.rb index c1dabaa06..d73eda651 100644 --- a/spec/span_spec.rb +++ b/spec/span_spec.rb @@ -2,8 +2,8 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") -describe "drawing span" do - +describe "drawing span" do + def setup Prawn.debug = false create_pdf @@ -28,9 +28,9 @@ def teardown @pdf.span(350, :position => :center) do @pdf.text "Here's some centered text in a 350 point column. " * 100 end - + @pdf.bounds.should == margin_box - + end it "should do create a margin box" do @@ -38,12 +38,12 @@ def teardown margin_box = @pdf.span(350, :position => :center) do @pdf.text "Here's some centered text in a 350 point column. " * 100 end - + margin_box.top.should == 792.0 - margin_box.bottom.should == 0 - - end - + margin_box.bottom.should == 0 + + end + end - + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7fd215fcd..96e394a9c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,7 +6,7 @@ require "bundler" Bundler.setup -$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') +$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') require "prawn" Prawn.debug = true @@ -18,7 +18,7 @@ def create_pdf(klass=Prawn::Document) @pdf = klass.new(:margin => 0) -end +end # Make some methods public to assist in testing module Prawn::Graphics diff --git a/spec/stamp_spec.rb b/spec/stamp_spec.rb index ad245c7f8..cefc62482 100644 --- a/spec/stamp_spec.rb +++ b/spec/stamp_spec.rb @@ -41,7 +41,7 @@ @pdf.create_stamp("MyStamp") }.should.raise(Prawn::Errors::NameTaken) end - + it "should raise InvalidName error when attempt to create "+ "stamp with a blank name" do create_pdf @@ -49,14 +49,14 @@ @pdf.create_stamp("") }.should.raise(Prawn::Errors::InvalidName) end - + it "a new XObject should be defined for each stamp created" do create_pdf @pdf.create_stamp("MyStamp") @pdf.create_stamp("AnotherStamp") @pdf.stamp("MyStamp") @pdf.stamp("AnotherStamp") - + inspector = PDF::Inspector::XObject.analyze(@pdf.render) xobjects = inspector.page_xobjects.last xobjects.length.should == 2 @@ -105,7 +105,7 @@ end end end - + it "stamp stream should be wrapped in a graphic state" do create_pdf @pdf.create_stamp("MyStamp") do @@ -115,11 +115,11 @@ stamps = PDF::Inspector::XObject.analyze(@pdf.render) stamps.xobject_streams[:Stamp1].data.chomp.should =~ /q(.|\s)*Q\Z/ end - + it "should not add to the page graphic state stack " do create_pdf @pdf.state.page.stack.stack.size.should == 1 - + @pdf.create_stamp("MyStamp") do @pdf.save_graphics_state @pdf.save_graphics_state @@ -129,7 +129,7 @@ end @pdf.state.page.stack.stack.size.should == 1 end - + it "should be able to change fill and stroke colors within the stamp stream" do create_pdf @pdf.create_stamp("MyStamp") do @@ -142,7 +142,7 @@ stamp_stream.should.include "/DeviceCMYK cs\n1.000 1.000 0.200 0.000 scn" stamp_stream.should.include "/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN" end - + it "should save the color space even when same as current page color space" do create_pdf @pdf.stroke_color(100, 100, 20, 0) @@ -154,6 +154,6 @@ stamp_stream = stamps.xobject_streams[:Stamp1].data stamp_stream.should.include "/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN" end - + end diff --git a/spec/stroke_styles_spec.rb b/spec/stroke_styles_spec.rb index e6e5ae14d..cca0ed947 100644 --- a/spec/stroke_styles_spec.rb +++ b/spec/stroke_styles_spec.rb @@ -7,7 +7,7 @@ it "cap_style should be :butt" do @pdf.cap_style.should == :butt end - + it "join_style should be :miter" do @pdf.join_style.should == :miter end @@ -19,12 +19,12 @@ describe "Cap styles" do before(:each) { create_pdf } - + it "should be able to use assignment operator" do @pdf.cap_style = :round @pdf.cap_style.should == :round end - + describe "#cap_style(:butt)" do it "rendered PDF should include butt style cap" do @pdf.cap_style(:butt) @@ -60,12 +60,12 @@ describe "Join styles" do before(:each) { create_pdf } - + it "should be able to use assignment operator" do @pdf.join_style = :round @pdf.join_style.should == :round end - + describe "#join_style(:miter)" do it "rendered PDF should include miter style join" do @pdf.join_style(:miter) @@ -101,7 +101,7 @@ describe "Dashes" do before(:each) { create_pdf } - + it "should be able to use assignment operator" do @pdf.dash = 2 @pdf.should.be.dashed @@ -151,7 +151,7 @@ dashes.stroke_dash.should == [[], 0] end end - + it "should carry the current dash settings over to new pages" do @pdf.dash(2) @pdf.start_new_page @@ -159,19 +159,19 @@ dashes.stroke_dash_count.should == 2 dashes.stroke_dash.should == [[2, 2], 0] end - + describe "#dashed?" do - + it "an initial document should not be dashed" do @pdf.dashed?.should == false end - + it "should return true if any of the currently active settings are dashed" do @pdf.dash(2) @pdf.save_graphics_state @pdf.dashed?.should == true end - + it "should return false if the document was most recently undashed" do @pdf.dash(2) @pdf.save_graphics_state @@ -179,7 +179,7 @@ @pdf.save_graphics_state @pdf.dashed?.should == false end - + it "should return true when restoring to a state that was dashed" do @pdf.dash(2) @pdf.save_graphics_state @@ -187,7 +187,7 @@ @pdf.restore_graphics_state @pdf.dashed?.should == true end - + end end diff --git a/spec/table_spec.rb b/spec/table_spec.rb index b613032ed..7a4dcb796 100644 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -1,6 +1,6 @@ # encoding: utf-8 -require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") +require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") require 'set' describe "Prawn::Table" do @@ -30,7 +30,7 @@ data = [["foo","bar"],["baz",""]] @pdf.table(data) }.should.not.raise - end + end it "should allow a table with a header but no body" do lambda { @pdf.table([["Header"]], :header => true) }.should.not.raise @@ -97,14 +97,14 @@ end it "should select rows by number or range" do - Set.new(@table.row(0).map { |c| c.content }).should == + Set.new(@table.row(0).map { |c| c.content }).should == Set.new(%w[R0C0 R0C1]) - Set.new(@table.rows(0..1).map { |c| c.content }).should == + Set.new(@table.rows(0..1).map { |c| c.content }).should == Set.new(%w[R0C0 R0C1 R1C0 R1C1]) end it "should select rows by array" do - Set.new(@table.rows([0, 1]).map { |c| c.content }).should == + Set.new(@table.rows([0, 1]).map { |c| c.content }).should == Set.new(%w[R0C0 R0C1 R1C0 R1C1]) end @@ -118,14 +118,14 @@ end it "should select columns by number or range" do - Set.new(@table.column(0).map { |c| c.content }).should == + Set.new(@table.column(0).map { |c| c.content }).should == Set.new(%w[R0C0 R1C0]) - Set.new(@table.columns(0..1).map { |c| c.content }).should == + Set.new(@table.columns(0..1).map { |c| c.content }).should == Set.new(%w[R0C0 R0C1 R1C0 R1C1]) end it "should select columns by array" do - Set.new(@table.columns([0, 1]).map { |c| c.content }).should == + Set.new(@table.columns([0, 1]).map { |c| c.content }).should == Set.new(%w[R0C0 R0C1 R1C0 R1C1]) end @@ -143,7 +143,7 @@ end it "should accept a filter block, returning a cell proxy" do - @table.cells.filter { |c| c.content =~ /R0/ }.column(1).map{ |c| + @table.cells.filter { |c| c.content =~ /R0/ }.column(1).map{ |c| c.content }.should == ["R0C1"] end @@ -253,13 +253,13 @@ "column widths within a single table" do hpad, fs = 10, 6 stretchy_columns = 2 - + col0_width = 50 col1_width = @pdf.width_of("foo", :size => fs) col2_width = @pdf.width_of("foobar", :size => fs) col3_width = 150 - table = Prawn::Table.new( [%w[snake foo b apple], + table = Prawn::Table.new( [%w[snake foo b apple], %w[kitten d foobar banana]], @pdf, :cell_style => { :padding => hpad, :size => fs }) do @@ -267,8 +267,8 @@ column(3).width = col3_width end - table.width.should == col1_width + col2_width + - 2*stretchy_columns*hpad + + table.width.should == col1_width + col2_width + + 2*stretchy_columns*hpad + col0_width + col3_width end @@ -277,7 +277,7 @@ col1_width = 20 col3_width = 60 - table = Prawn::Table.new( [["snake", "foo", "b", + table = Prawn::Table.new( [["snake", "foo", "b", "some long, long text that will wrap"], %w[kitten d foobar banana]], @pdf, :width => 150) do @@ -298,7 +298,7 @@ expected_width = @pdf.margin_box.width data = [ ['This is a column with a lot of text that should comfortably exceed '+ - 'the width of a normal document margin_box width', 'Some more text', + 'the width of a normal document margin_box width', 'Some more text', 'and then some more', 'Just a bit more to be extra sure'] ] table = Prawn::Table.new(data, @pdf) @@ -311,20 +311,20 @@ expected_width = @pdf.margin_box.width data = [ ['This is a column with a lot of text that should comfortably exceed '+ - 'the width of a normal document margin_box width', 'Some more text', + 'the width of a normal document margin_box width', 'Some more text', 'and then some more', 'Just a bit more to be extra sure'] ] table = Prawn::Table.new(data, @pdf) { column(1).width = 100 } table.width.should == expected_width end - + it "scales down only the non-preset column widths when the natural width" + "exceeds the maximum width of the margin_box" do expected_width = @pdf.margin_box.width data = [ ['This is a column with a lot of text that should comfortably exceed '+ - 'the width of a normal document margin_box width', 'Some more text', + 'the width of a normal document margin_box width', 'Some more text', 'and then some more', 'Just a bit more to be extra sure'] ] table = Prawn::Table.new(data, @pdf) { column(1).width = 100; column(3).width = 50 } @@ -371,7 +371,7 @@ it "should be the width of the :width parameter" do expected_width = 300 - table = Prawn::Table.new( [%w[snake foo b apple], + table = Prawn::Table.new( [%w[snake foo b apple], %w[kitten d foobar banana]], @pdf, :width => expected_width) @@ -382,7 +382,7 @@ expected_width = 400 data = [ ['This is a column with a lot of text that should comfortably exceed '+ - 'the width of a normal document margin_box width', 'Some more text', + 'the width of a normal document margin_box width', 'Some more text', 'and then some more', 'Just a bit more to be extra sure'] ] table = Prawn::Table.new(data, @pdf, :width => expected_width) @@ -394,7 +394,7 @@ expected_width = 400 data = [ ['This is a column with a lot of text that should comfortably exceed '+ - 'the width of a normal document margin_box width', 'Some more text', + 'the width of a normal document margin_box width', 'Some more text', 'and then some more', 'Just a bit more to be extra sure'] ] table = Prawn::Table.new(data, @pdf, :width => expected_width) do @@ -445,9 +445,9 @@ (t.height - 10).should.be < h*1.5 end - it "should have a height of n rows" do + it "should have a height of n rows" do data = [["foo"],["bar"],["baaaz"]] - + vpad = 4 origin = @pdf.y @pdf.table data, :cell_style => { :padding => vpad } @@ -610,7 +610,7 @@ it "should default to {} for the hash argument" do stylable = stub() stylable.expects(:style).with({}).once - + Prawn::Document.new do table([["x"]]) { style(stylable) } end @@ -628,12 +628,12 @@ it "should ignore headers" do data = [["header"], ["foo"], ["bar"], ["baz"]] pdf = Prawn::Document.new - t = pdf.table(data, :header => true, + t = pdf.table(data, :header => true, :row_colors => ['cccccc', 'ffffff']) do row(0).background_color = '333333' end - t.cells.map{|x| x.background_color}.should == + t.cells.map{|x| x.background_color}.should == %w[333333 cccccc ffffff cccccc] end @@ -654,7 +654,7 @@ it "should set the x-position of each cell based on widths" do @table = @pdf.table([["foo", "bar", "baz"]]) - + x = 0 (0..2).each do |col| cell = @table.cells[0, col] @@ -734,7 +734,7 @@ describe "in stretchy bounding boxes" do it "should draw all cells on a row at the same y-position" do pdf = Prawn::Document.new - + text_y = pdf.y.to_i - 5 # text starts 5pt below current y pos (padding) pdf.bounding_box([0, pdf.cursor], :width => pdf.bounds.width) do @@ -753,7 +753,7 @@ data = [["a", "b"], ["foo","bar"],["baz","bang"]] @pdf = Prawn::Document.new @pdf.table(data, :header => true) - output = PDF::Inspector::Text.analyze(@pdf.render) + output = PDF::Inspector::Text.analyze(@pdf.render) output.strings.should == data.flatten end @@ -762,7 +762,7 @@ headers = ["baz","foobar"] @pdf = Prawn::Document.new @pdf.table([headers] + data, :header => true) - output = PDF::Inspector::Text.analyze(@pdf.render) + output = PDF::Inspector::Text.analyze(@pdf.render) output.strings.should == headers + data.flatten[0..-3] + headers + data.flatten[-2..-1] end @@ -771,7 +771,7 @@ @pdf = Prawn::Document.new @pdf.y = 0 @pdf.table([["Header"], ["Body"]], :header => true) - output = PDF::Inspector::Text.analyze(@pdf.render) + output = PDF::Inspector::Text.analyze(@pdf.render) output.strings.should == ["Header", "Body"] end end @@ -796,7 +796,7 @@ it "has a subtable accessor" do @table.cells[0, 0].subtable.should == @subtable end - + it "determines its dimensions from the subtable" do @table.cells[0, 0].width.should == @subtable.width @table.cells[0, 0].height.should == @subtable.height @@ -805,12 +805,12 @@ end describe "An invalid table" do - + before(:each) do @pdf = Prawn::Document.new @bad_data = ["Single Nested Array"] end - + it "should raise error when invalid table data is given" do assert_raises(Prawn::Errors::InvalidTableData) do @pdf.table(@bad_data) @@ -823,7 +823,7 @@ @pdf = Prawn::Document.new @pdf.table(data) }.should.raise( Prawn::Errors::EmptyTable ) - end + end it "should raise an EmptyTableError with nil table data" do lambda { @@ -831,7 +831,7 @@ @pdf = Prawn::Document.new @pdf.table(data) }.should.raise( Prawn::Errors::EmptyTable ) - end + end end diff --git a/spec/template_spec.rb b/spec/template_spec.rb index 9a0f5346c..c5ef46cec 100644 --- a/spec/template_spec.rb +++ b/spec/template_spec.rb @@ -40,7 +40,7 @@ :bottom => 36 } - + end it "should not add an extra restore_graphics_state operator to the end of any content stream" do @@ -57,7 +57,7 @@ data.include?("QQ").should == false end end - + it "should have a single page object if importing a single page template" do filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf" @@ -166,19 +166,19 @@ describe "Document#start_new_page with :template option" do filename = "#{Prawn::BASEDIR}/spec/data/curves.pdf" - + it "should set the imported page's parent to the document pages catalog" do @pdf = Prawn::Document.new() @pdf.start_new_page(:template => filename) @pdf.state.page.dictionary.data[:Parent].should == @pdf.state.store.pages end - + it "should set start the Y cursor at the top of the page" do @pdf = Prawn::Document.new() @pdf.start_new_page(:template => filename) (@pdf.y == nil).should == false end - + it "should respect margins set by Prawn" do @pdf = Prawn::Document.new(:margin => 0) @pdf.start_new_page(:template => filename) @@ -199,7 +199,7 @@ :top => 36, :bottom => 36 } end - + it "should not add an extra restore_graphics_state operator to the end of any content stream" do @pdf = Prawn::Document.new @pdf.start_new_page(:template => filename) @@ -213,7 +213,7 @@ data.include?("QQ").should == false end end - + it "should have two content streams if importing a single page template" do filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf" @pdf = Prawn::Document.new() @@ -224,7 +224,7 @@ template_page = hash[pages[1]] template_page[:Contents].size.should == 2 end - + it "should have balance q/Q operators on all content streams" do filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf" @@ -241,7 +241,7 @@ data.scan("Q").size.should == 1 end end - + it "should allow text to be added to a single page template" do @pdf = Prawn::Document.new() @@ -252,7 +252,7 @@ text = PDF::Inspector::Text.analyze(@pdf.render) text.strings.first.should == "Adding some text" end - + it "should allow PDFs with page resources behind an indirect object to be used as templates" do filename = "#{Prawn::DATADIR}/pdfs/resources_as_indirect_object.pdf" @@ -265,7 +265,7 @@ all_text = text.strings.join all_text.include?("Adding some text").should == true end - + it "should correctly add a TTF font to a template that has existing fonts" do filename = "#{Prawn::DATADIR}/pdfs/contains_ttf_font.pdf" @pdf = Prawn::Document.new() @@ -283,7 +283,7 @@ fonts = resources[:Font] fonts.size.should == 2 end - + context "using template_page option" do it "uses the specified page option" do filename = "#{Prawn::DATADIR}/pdfs/multipage_template.pdf" diff --git a/spec/text_box_spec.rb b/spec/text_box_spec.rb index d2743b889..1ee6f2844 100644 --- a/spec/text_box_spec.rb +++ b/spec/text_box_spec.rb @@ -116,7 +116,7 @@ end it "should default to document-wide leading if no" + "leading option is provided" do - + end end @@ -517,7 +517,7 @@ :document => @pdf } end - + it "printed text should match requested text, except that preceding and " + "trailing white space will be stripped from each line, and newlines may " + "be inserted" do @@ -525,7 +525,7 @@ text_box.render text_box.text.gsub("\n", " ").should == @text.strip end - + it "render should return an empty string because no text remains unprinted" do text_box = Prawn::Text::Box.new(@text, @options) text_box.render.should == "" @@ -551,7 +551,7 @@ :document => @pdf } end - + it "should have the expected height" do expected_height = @options.delete(:height) text_box = Prawn::Text::Box.new(@text, @options) @@ -608,7 +608,7 @@ describe "Text::Box printing UTF-8 string with higher bit characters" do before(:each) do - create_pdf + create_pdf @text = "©" # not enough height to print any text, so we can directly compare against # the input string @@ -663,7 +663,7 @@ describe "Text::Box with more text than can fit in the box" do before(:each) do - create_pdf + create_pdf @text = "Oh hai text rect. " * 30 @bounding_height = 162.0 @options = { @@ -672,7 +672,7 @@ :document => @pdf } end - + context "truncated overflow" do before(:each) do @options[:overflow] = :truncate @@ -710,7 +710,7 @@ end end end - + context "truncated with text and size taken from the manual" do it "should return the right text" do @text = "This is the beginning of the text. It will be cut somewhere and " + @@ -809,8 +809,8 @@ end -describe "drawing bounding boxes" do - before(:each) { create_pdf } +describe "drawing bounding boxes" do + before(:each) { create_pdf } it "should restore the margin box when bounding box exits" do margin_box = @pdf.bounds @@ -845,7 +845,7 @@ text_box.text.should == "hello\nworld" end end - + describe "Text::Box wrapping" do before(:each) do create_pdf diff --git a/spec/text_spec.rb b/spec/text_spec.rb index 1a4624f53..2741ab3a3 100644 --- a/spec/text_spec.rb +++ b/spec/text_spec.rb @@ -256,7 +256,7 @@ it "should raise an exception when an unknown font is used" do lambda { @pdf.font "Pao bu" }.should.raise(Prawn::Errors::UnknownFont) end - + it "should not raise an exception when providing Pathname instance as font" do lambda { @pdf.font Pathname.new("#{Prawn::DATADIR}/fonts/comicsans.ttf") diff --git a/spec/transparency_spec.rb b/spec/transparency_spec.rb index 8c77ab605..590acfb02 100644 --- a/spec/transparency_spec.rb +++ b/spec/transparency_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") +require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") module TransparencyHelper def make_transparent(opacity, stroke_opacity=opacity) @@ -17,7 +17,7 @@ def make_transparent(opacity, stroke_opacity=opacity) str = @pdf.render str[0,8].should == "%PDF-1.4" end - + it "a new extended graphics state should be created for "+ "each unique transparency setting" do create_pdf @@ -27,7 +27,7 @@ def make_transparent(opacity, stroke_opacity=opacity) extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates extgstates.length.should == 2 end - + it "a new extended graphics state should not be created for "+ "each duplicate transparency setting" do create_pdf @@ -70,7 +70,7 @@ def make_transparent(opacity, stroke_opacity=opacity) extgstate[:opacity].should == 1.0 extgstate[:stroke_opacity].should == 1.0 end - + describe "with more than one page" do include TransparencyHelper @@ -78,7 +78,7 @@ def make_transparent(opacity, stroke_opacity=opacity) create_pdf make_transparent(0.5, 0.2) @pdf.start_new_page - make_transparent(0.5, 0.2) + make_transparent(0.5, 0.2) extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates extgstate = extgstates[0] extgstates.length.should == 2 diff --git a/www/index.html b/www/index.html index 7b6eb1c42..2724eafb4 100644 --- a/www/index.html +++ b/www/index.html @@ -1,4 +1,4 @@ - + @@ -6,43 +6,43 @@ - +
-
+
- +

Prawn is Free Software under the License of Ruby, developed by Gregory Brown and the Ruby community.
The Prawn logo was created by maso and is distributed under - the CC Attribution-Share Alike license. -

-
+ the CC Attribution-Share Alike license. +

+
- + + diff --git a/www/prawn-Chinese.html b/www/prawn-Chinese.html index debe022b2..e217a5443 100644 --- a/www/prawn-Chinese.html +++ b/www/prawn-Chinese.html @@ -1,101 +1,101 @@ - + - +
-
    +

    Prawn: 小巧的Ruby PDF生成库

    -RubyGems安装 : gem install prawn -
    -
    +RubyGems安装 : gem install prawn +
    + -

    轻而易举创建PDF打印文档

    - +

    轻而易举创建PDF打印文档

    +

    - 在包括Ruby在内的几乎所有编程语言中,将文档转换成PDF格式一直是一件令人头痛的事情。Prawn可以帮你大大减轻这种痛苦,并且仍然保持高效简洁。Prawn, 中文意为虾,也暗含了小巧迅速的意味。 + 在包括Ruby在内的几乎所有编程语言中,将文档转换成PDF格式一直是一件令人头痛的事情。Prawn可以帮你大大减轻这种痛苦,并且仍然保持高效简洁。Prawn, 中文意为虾,也暗含了小巧迅速的意味。

    方便地获取所需功能

    - +

    Prawn是 速度最快,功能最纯粹的基于Ruby的PDF生成类库。, 在接下来的内容中,你会看到Prawn的一些具体代码, 点击代码本身可以看到代码所产生的PDF文档。 -

    - +

    +

    -- 内置支持UTF-8

    - +

    在Prawn中生成国际化文字和生成UTF-8字符串一样简单,当然前提条件是你有国际化文字的标准字体文件(Unicode aware TTF font)在你的系统中。使用Ruby 1.9的人,所有可以被转化成UTF-8的代码都可以直接使用。 -

    +

    - +

    -- 轻松的图像嵌入

    - +

    在Prawn中插入JPEG和PNG格式的图像相当方便。Prawn支持Alpha透明,定位和缩放都可以很容易实现,从而使在文档中插入图像轻而易举。 -

    +

    - +

    -- 灵活的表格绘制

    Prawn内置支持以表格的形式呈现文字,从而实现基本的报表功能。将用户从编写低端画图代码中解脱出来,而能够真正将精力用在编辑文档的内容上。。 -

    +

    - +

    -- 简化的定位系统

    - +

    写过低端绘图软件的人一定记得处理好各种坐标系不是一件容易的事情。Prawn将这个过程大大简化。你可以将文档的任何一个部分界成一个独特的区域(bounding box),并拥有这个区域独立的坐标系。你可以在文档中随意移动这个区域的位置,但是这个区域内部组分的相对位置不会改变,从而保持了代码的简洁。在这样的特定区域内,文字也可以自动分行,所以在海报上分栏书写变得非常容易。 -

    +

    -- 更多功能即将实现

    -Prawn现在只处于开发的初级阶段, 新的功能每天都会出现。在不久的将来我们会将它整合到现有的 Ruby报表软件系统(Ruport)。 如果你希望知道最新的功能,只需点击 例子和代码, 它包含上面显示的各种代码和更多其它有关的内容。 +Prawn现在只处于开发的初级阶段, 新的功能每天都会出现。在不久的将来我们会将它整合到现有的 Ruby报表软件系统(Ruport)。 如果你希望知道最新的功能,只需点击 例子和代码, 它包含上面显示的各种代码和更多其它有关的内容。 -

    来自Ruby社区的支持

    +

    来自Ruby社区的支持

    -

    Prawn的开发很大一部分是基于社区对Gregory Brown的 ”Ruby之乞“ 计划的捐赠。在人们的支持下,此计划一经产生就迅速成长了起来,并成了现实。

    +

    Prawn的开发很大一部分是基于社区对Gregory Brown的 ”Ruby之乞“ 计划的捐赠。在人们的支持下,此计划一经产生就迅速成长了起来,并成了现实。

    自从2008年四月Prawn开始之始,包括在代码的表达,错误的监察,以及功能的制定等各个方面都有Ruby爱好者们的积极地参与。你们可以从 Github -network graph上找到他们的足迹。在为Prawn提供了插件的所有人中,特别感谢 James HealyMichael Daines 为他们对Prawn的不可取代的贡献。

    +network graph上找到他们的足迹。在为Prawn提供了插件的所有人中,特别感谢 James HealyMichael Daines 为他们对Prawn的不可取代的贡献。

    如果你希望能够在Rails的程序中用到Prawn,你可以试试使用另一个社区产品,thorny_sun的 Prawnto Rails的插件。虽然这个并不是Prawn的正式部件,我们会尽力使这个插件保持发挥作用。

    请加入我们开发Prawn的队伍,使它真正成为符合客户选择的生成PDF的Ruby类库。 你可以加入我们的 邮件组 或者加入我们在irc.freenode.net上 #prawn 频道的聊天组。需要做的事情还很多,你的帮助会使我们离目标更近一步!

    - +

    快来一试!

    从RubyGems安装: gem install prawn 从github下载: 地址为: git://github.com/sandal/prawn.git

    -
+
- +

Prawn is Free Software under the License of Ruby, developed by Gregory Brown and the Ruby community.
The Prawn logo was created by maso and is distributed under - the CC Attribution-Share Alike license. -

-
+ the CC Attribution-Share Alike license. +

+
- + + diff --git a/www/prawn.css b/www/prawn.css index 17bfd5c71..99baefe0e 100644 --- a/www/prawn.css +++ b/www/prawn.css @@ -6,53 +6,53 @@ body { font: Verdana, "Lucida Grande", "Lucida Sans", sans-serif; background-color: #000000; - color: #ffffff; + color: #ffffff; margin-bottom: 1em; -} +} h2, h3, h4, h5, h6, p, pre, blockquote, form, fieldset, table, ul { margin: 1em 0; -} +} h2 { font-size: 1.75em; } -h2, h3 { +h2, h3 { color: #00bb77; -} +} h1 { - color: #bb5566; - font-size: 1.1em; + color: #bb5566; + font-size: 1.1em; margin-top: 0.5em; -} +} -a { - color: #ffffff; +a { + color: #ffffff; text-decoration: none; - outline: none; + outline: none; } -a:visited { +a:visited { color: #ffffff; } -a:hover, a:active { +a:hover, a:active { color: #2299ff; } - + a img { border:none; } -#contents { +#contents { background-color: #101010; width: 740px; margin: 0 auto; border: 1px solid #fff; margin-top: 1em; padding: 1em 1em 1em 3em; -} +} #sidebar { width: 180px; @@ -62,24 +62,24 @@ a img { } -#screenshots { +#screenshots { margin-top: 2em; float: right; -} +} -ul { - text-align: center; +ul { + text-align: center; float: right; -} +} -li { +li { display: inline; - border-top: 1px solid #fff; - border-right: 1px solid #fff; - border-bottom: 1px solid #666; - border-left: 1px solid #666; + border-top: 1px solid #fff; + border-right: 1px solid #fff; + border-bottom: 1px solid #666; + border-left: 1px solid #666; margin-right: 5px; - padding-left: 10px; + padding-left: 10px; padding-right: 10px; color: #fff; font-weight: bold; diff --git a/www/twilight.css b/www/twilight.css index 263f4e2c6..c2c0a0efe 100644 --- a/www/twilight.css +++ b/www/twilight.css @@ -4,7 +4,7 @@ /* Stylesheet generated from TextMate theme * * Twilight - * + * * */