diff --git a/.rubocop.yml b/.rubocop.yml index b9ec9ad0c..d6a537aa6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -29,8 +29,6 @@ AlignHash: Enabled: false LineLength: Enabled: false -TrailingWhitespace: - Enabled: false SpaceBeforeBlockBraces: Enabled: false AlignParameters: diff --git a/bench/afm_text_bench.rb b/bench/afm_text_bench.rb index 81e113dba..9deccde7f 100644 --- a/bench/afm_text_bench.rb +++ b/bench/afm_text_bench.rb @@ -1,20 +1,20 @@ # encoding: utf-8 $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 94808cc2e..7817b1ecb 100644 --- a/bench/png_type_6.rb +++ b/bench/png_type_6.rb @@ -1,17 +1,17 @@ # encoding: utf-8 -$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=100 - -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_file("dice.pdf") - end - end -end + end + end +end diff --git a/bench/table_bench.rb b/bench/table_bench.rb index d1011b981..70ccb5139 100644 --- a/bench/table_bench.rb +++ b/bench/table_bench.rb @@ -1,8 +1,8 @@ # encoding: utf-8 -$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" # Helpers for benchmark diff --git a/bench/ttf_text_bench.rb b/bench/ttf_text_bench.rb index dcc72e763..4e768bb50 100644 --- a/bench/ttf_text_bench.rb +++ b/bench/ttf_text_bench.rb @@ -1,21 +1,21 @@ # encoding: utf-8 -$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/lib/prawn.rb b/lib/prawn.rb index aec1a7cdc..18b358ccd 100644 --- a/lib/prawn.rb +++ b/lib/prawn.rb @@ -22,7 +22,7 @@ module Prawn # BASEDIR = File.expand_path(File.join(dir, '..')) DATADIR = File.expand_path(File.join(dir, '..', 'data')) - + FLOAT_PRECISION = 1.0e-9 # Whe set to true, Prawn will verify hash options to ensure only valid keys diff --git a/lib/prawn/document.rb b/lib/prawn/document.rb index adf867aac..563f029d0 100644 --- a/lib/prawn/document.rb +++ b/lib/prawn/document.rb @@ -97,7 +97,7 @@ def self.extensions end # @private - def self.inherited(base) + def self.inherited(base) extensions.each { |e| base.extensions << e } end @@ -587,7 +587,7 @@ def compression_enabled? # # @private def group(*a, &b) - raise NotImplementedError, + raise NotImplementedError, "Document#group has been disabled because its implementation "+ "lead to corrupted documents whenever a page boundary was "+ "crossed. We will try to work on reimplementing it in a "+ @@ -596,7 +596,7 @@ def group(*a, &b) # @private def transaction - raise NotImplementedError, + raise NotImplementedError, "Document#transaction has been disabled because its implementation "+ "lead to corrupted documents whenever a page boundary was "+ "crossed. We will try to work on reimplementing it in a "+ @@ -629,8 +629,8 @@ def page_match?(page_filter, page_number) end # @private - - def mask(*fields) + + def mask(*fields) # Stores the current state of the named attributes, executes the block, and # then restores the original values after the block has executed. # -- I will remove the nodoc if/when this feature is a little less hacky @@ -696,7 +696,7 @@ def generate_margin_box # we must update bounding box if not flowing from the previous page # - @bounding_box = @margin_box unless @bounding_box && @bounding_box.parent + @bounding_box = @margin_box unless @bounding_box && @bounding_box.parent end def apply_margin_options(options) diff --git a/lib/prawn/document/bounding_box.rb b/lib/prawn/document/bounding_box.rb index 285ac4cd2..6b8982620 100644 --- a/lib/prawn/document/bounding_box.rb +++ b/lib/prawn/document/bounding_box.rb @@ -199,7 +199,7 @@ def init_bounding_box(user_block, options={}, &init_block) # If the user actions did not modify the y position # restore the original y position before the bounding # box was created. - + if y == @bounding_box.absolute_top self.y = original_ypos end diff --git a/lib/prawn/document/column_box.rb b/lib/prawn/document/column_box.rb index 527d3e667..67364566d 100644 --- a/lib/prawn/document/column_box.rb +++ b/lib/prawn/document/column_box.rb @@ -20,12 +20,12 @@ class Document # # column_box accepts the same parameters as bounding_box, as well as the # number of :columns and a :spacer (in points) between columns. If resetting - # the top margin is desired on a new page (e.g. to allow for initial page + # the top margin is desired on a new page (e.g. to allow for initial page # wide column titles) the option :reflow_margins => true can be set. # - # Defaults are :columns = 3, :spacer = font_size, and + # Defaults are :columns = 3, :spacer = font_size, and # :reflow_margins => false - # + # # Under PDF::Writer, "spacer" was known as "gutter" # def column_box(*args, &block) diff --git a/lib/prawn/document/internals.rb b/lib/prawn/document/internals.rb index 89aa5fb63..4a2c1580e 100644 --- a/lib/prawn/document/internals.rb +++ b/lib/prawn/document/internals.rb @@ -15,7 +15,7 @@ class Document # are you won't need anything you find here. # # @private - 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. # diff --git a/lib/prawn/font/afm.rb b/lib/prawn/font/afm.rb index 93b881826..408941238 100644 --- a/lib/prawn/font/afm.rb +++ b/lib/prawn/font/afm.rb @@ -157,7 +157,7 @@ def find_font(file) end def parse_afm(file_name) - data = {:glyph_widths => {}, :bounding_boxes => {}, :kern_pairs => {}, :attributes => {}} + data = {:glyph_widths => {}, :bounding_boxes => {}, :kern_pairs => {}, :attributes => {}} section = [] File.foreach(file_name) do |line| @@ -187,7 +187,7 @@ def parse_afm(file_name) parse_generic_afm_attribute(line, data) end end - + # process data parsed from AFM file to build tables which # will be used when measuring and kerning text data[:glyph_table] = (0..255).map do |i| @@ -234,9 +234,9 @@ def kern(string) e.respond_to?(:force_encoding) ? e.force_encoding(::Encoding::Windows_1252) : e } end - + private - + def unscaled_width_of(string) string.bytes.inject(0) do |s,r| s + @glyph_table[r] diff --git a/lib/prawn/font_metric_cache.rb b/lib/prawn/font_metric_cache.rb index 2bc959bb7..684999c1d 100644 --- a/lib/prawn/font_metric_cache.rb +++ b/lib/prawn/font_metric_cache.rb @@ -13,7 +13,7 @@ module Prawn # of various strings for layout purposes. # # @private - class FontMetricCache + class FontMetricCache CacheEntry = Struct.new( :font, :options, :string ) diff --git a/lib/prawn/grid.rb b/lib/prawn/grid.rb index 098ae2a80..9567fbbfe 100644 --- a/lib/prawn/grid.rb +++ b/lib/prawn/grid.rb @@ -16,7 +16,7 @@ class Document # # Note that a completely new grid object is built each time define_grid() # is called. This means that all subsequent calls to grid() will use - # the newly defined Grid object -- grids are not nestable like + # the newly defined Grid object -- grids are not nestable like # bounding boxes are. def define_grid(options = {}) diff --git a/lib/prawn/image_handler.rb b/lib/prawn/image_handler.rb index 37c15e20c..9fc510450 100644 --- a/lib/prawn/image_handler.rb +++ b/lib/prawn/image_handler.rb @@ -8,7 +8,7 @@ module Prawn # @group Extension API - + def self.image_handler @image_handler ||= ImageHandler.new end diff --git a/lib/prawn/images/jpg.rb b/lib/prawn/images/jpg.rb index b4b99529f..999ac138c 100644 --- a/lib/prawn/images/jpg.rb +++ b/lib/prawn/images/jpg.rb @@ -16,7 +16,7 @@ module Images # class JPG < Image # @group Extension API - + attr_reader :width, :height, :bits, :channels attr_accessor :scaled_width, :scaled_height diff --git a/lib/prawn/measurement_extensions.rb b/lib/prawn/measurement_extensions.rb index b62031d3d..e7ff45492 100644 --- a/lib/prawn/measurement_extensions.rb +++ b/lib/prawn/measurement_extensions.rb @@ -15,7 +15,7 @@ class Numeric # 72 points per inch # @group Experimental API - + def mm return mm2pt(self) end diff --git a/lib/prawn/outline.rb b/lib/prawn/outline.rb index e4eb0e1ad..84232c4ed 100644 --- a/lib/prawn/outline.rb +++ b/lib/prawn/outline.rb @@ -3,7 +3,7 @@ module Prawn class Document # @group Stable API - + # Lazily instantiates a Prawn::Outline object for document. This is used as point of entry # to methods to build the outline tree for a document's table of contents. def outline diff --git a/lib/prawn/security.rb b/lib/prawn/security.rb index cfdb23fbd..687a564a2 100644 --- a/lib/prawn/security.rb +++ b/lib/prawn/security.rb @@ -213,7 +213,7 @@ module Core # from the indirect object referencing obj. # # @private - def EncryptedPdfObject(obj, key, id, gen, in_content_stream=false) + def EncryptedPdfObject(obj, key, id, gen, in_content_stream=false) case obj when Array "[" << obj.map { |e| diff --git a/lib/prawn/security/arcfour.rb b/lib/prawn/security/arcfour.rb index eeedd7c46..bca1c8a03 100644 --- a/lib/prawn/security/arcfour.rb +++ b/lib/prawn/security/arcfour.rb @@ -19,7 +19,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 = [] @@ -41,7 +41,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/table/cell.rb b/lib/prawn/table/cell.rb index 6331df012..242b83cb6 100644 --- a/lib/prawn/table/cell.rb +++ b/lib/prawn/table/cell.rb @@ -153,7 +153,7 @@ def max_width # this span group. They know their own width / height, but do not draw # anything. # - attr_reader :dummy_cells + attr_reader :dummy_cells # Instantiates a Cell based on the given options. The particular class of # cell returned depends on the :content argument. See the Prawn::Table diff --git a/lib/prawn/table/cells.rb b/lib/prawn/table/cells.rb index d726e8c3e..2dfd4343f 100644 --- a/lib/prawn/table/cells.rb +++ b/lib/prawn/table/cells.rb @@ -256,7 +256,7 @@ def aggregate_cell_values(row_or_column, meth, aggregate) #calculate future return value new_sum = cell.send(meth) * cell.colspan - #due to float rounding errors we need to ignore a small difference in the new + #due to float rounding errors we need to ignore a small difference in the new #and the old sum the same had to be done in #the column_width_calculator#natural_width spanned_width_needs_fixing = ((new_sum - old_sum) > Prawn::FLOAT_PRECISION) diff --git a/lib/prawn/table/column_width_calculator.rb b/lib/prawn/table/column_width_calculator.rb index 540957ac9..39f9fbf93 100644 --- a/lib/prawn/table/column_width_calculator.rb +++ b/lib/prawn/table/column_width_calculator.rb @@ -3,7 +3,7 @@ module Prawn class Table # @private - class ColumnWidthCalculator + class ColumnWidthCalculator def initialize(cells) @cells = cells @@ -19,7 +19,7 @@ def natural_widths #calculate natural column width for all rows that do not include a span dummy @cells.each do |cell| unless @rows_with_a_span_dummy[cell.row] - @widths_by_column[cell.column] = + @widths_by_column[cell.column] = [@widths_by_column[cell.column], cell.width.to_f].max end end @@ -31,20 +31,20 @@ def natural_widths next if cell.is_a?(Cell::SpanDummy) if cell.colspan == 1 - @widths_by_column[cell.column] = + @widths_by_column[cell.column] = [@widths_by_column[cell.column], cell.width.to_f].max else #calculate the current with of all cells that will be spanned by the current cell - current_width_of_spanned_cells = + current_width_of_spanned_cells = @widths_by_column.to_a[cell.column..(cell.column + cell.colspan - 1)] .collect{|key, value| value}.inject(0, :+) #update the Hash only if the new with is at least equal to the old one #due to arithmetic errors we need to ignore a small difference in the new and the old sum #the same had to be done in the column_widht_calculator#natural_width - update_hash = ((cell.width.to_f - current_width_of_spanned_cells) > + update_hash = ((cell.width.to_f - current_width_of_spanned_cells) > Prawn::FLOAT_PRECISION) - + if update_hash # Split the width of colspanned cells evenly by columns width_per_column = cell.width.to_f / cell.colspan diff --git a/lib/prawn/text.rb b/lib/prawn/text.rb index 6d5616940..6b9d35c96 100644 --- a/lib/prawn/text.rb +++ b/lib/prawn/text.rb @@ -27,7 +27,7 @@ module Text Prawn::Text::SHY = "­" # @group Stable API - + # If you want text to flow onto a new page or between columns, this is the # 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 diff --git a/lib/prawn/text/formatted/arranger.rb b/lib/prawn/text/formatted/arranger.rb index 07b7fd81c..7c484bb1c 100644 --- a/lib/prawn/text/formatted/arranger.rb +++ b/lib/prawn/text/formatted/arranger.rb @@ -12,7 +12,7 @@ module Text module Formatted #:nodoc: # @private - + class Arranger #:nodoc: attr_reader :max_line_height attr_reader :max_descender diff --git a/lib/prawn/text/formatted/box.rb b/lib/prawn/text/formatted/box.rb index 16ea2590e..a14e7c3db 100644 --- a/lib/prawn/text/formatted/box.rb +++ b/lib/prawn/text/formatted/box.rb @@ -11,7 +11,7 @@ module Prawn module Text module Formatted # @group Stable API - + # Draws the requested formatted text into a box. When the text overflows # the rectangle shrink to fit or truncate the text. Text boxes are # independent of the document y position. @@ -293,7 +293,7 @@ def draw_fragment(fragment, accumulated_width=0, line_width=0, word_spacing=0) # end # @group Extension API - + # Example (see Prawn::Text::Core::Formatted::Wrap for what is required # of the wrap method if you want to override the default wrapping # algorithm): diff --git a/lib/prawn/utilities.rb b/lib/prawn/utilities.rb index fe7862e62..bf9520874 100644 --- a/lib/prawn/utilities.rb +++ b/lib/prawn/utilities.rb @@ -17,7 +17,7 @@ module Prawn # We have two interchangeable thread-safe cache implementations: # @private - class SynchronizedCache + class SynchronizedCache # As an optimization, this could access the hash directly on VMs with a global interpreter lock (like MRI) def initialize @cache = {} @@ -30,9 +30,9 @@ def []=(key,value) @mutex.synchronize { @cache[key] = value } end end - + # @private - class ThreadLocalCache + class ThreadLocalCache def initialize @cache_id = "cache_#{self.object_id}".to_sym end diff --git a/manual/basic_concepts/adding_pages.rb b/manual/basic_concepts/adding_pages.rb index a31c84eea..574bd30b8 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 c7c3eb8e9..8289a7660 100644 --- a/manual/basic_concepts/basic_concepts.rb +++ b/manual/basic_concepts/basic_concepts.rb @@ -6,16 +6,16 @@ %w[.. example_helper])) Prawn::Example.generate("basic_concepts.pdf", :page_size => "FOLIO") do - + package "basic_concepts" do |p| - + p.example "creation", :eval_source => false, :full_source => true p.example "origin" p.example "cursor" p.example "other_cursor_helpers" p.example "adding_pages" p.example "measurement" - + p.intro do prose("This chapter covers the minimum amount of functionality you'll need to start using Prawn. diff --git a/manual/basic_concepts/cursor.rb b/manual/basic_concepts/cursor.rb index 4b6b51a16..6f88cc20d 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 4fd25f866..210004925 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 af4c6865e..2a29c121b 100644 --- a/manual/basic_concepts/origin.rb +++ b/manual/basic_concepts/origin.rb @@ -28,9 +28,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 79f9ec123..efcb41547 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 30 - + text "Text written before the float block." - + float do move_down 30 bounding_box([0, cursor], :width => 200) do diff --git a/manual/bounding_box/bounding_box.rb b/manual/bounding_box/bounding_box.rb index a3d3fa294..777af7fbc 100644 --- a/manual/bounding_box/bounding_box.rb +++ b/manual/bounding_box/bounding_box.rb @@ -6,14 +6,14 @@ %w[.. example_helper])) Prawn::Example.generate("bounding_box.pdf", :page_size => "FOLIO") do - + package "bounding_box" do |p| - + p.section "Basics" do |s| s.example "creation" s.example "bounds" end - + p.section "Advanced" do |s| s.example "stretchy" s.example "nesting" @@ -21,7 +21,7 @@ s.example "canvas" s.example "russian_boxes" end - + p.intro do prose("Bounding boxes are the basic containers for structuring the content flow. Even being low level building blocks sometimes their simplicity is very welcome. @@ -34,6 +34,6 @@ "Indent blocks" ) end - + end end diff --git a/manual/bounding_box/bounds.rb b/manual/bounding_box/bounds.rb index f340a241d..94744bb54 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 7db68e409..66d12b9a2 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 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 this horizontal 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 0498a1a07..f905abbad 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 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 transparent(0.5) { stroke_bounds } end - + gap = 20 bounding_box([50, cursor], :width => 400, :height => 200) do box_content("Fixed height") - + 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 height") end - + transparent(0.5) { dash(1); stroke_bounds; undash } end - + bounding_box([gap, cursor - gap], :width => 300, :height => 50) do box_content("Fixed height") 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 932a6a8c0..f40e48285 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 c7ed79ba9..e35fa9538 100644 --- a/manual/document_and_page_options/document_and_page_options.rb +++ b/manual/document_and_page_options/document_and_page_options.rb @@ -7,9 +7,9 @@ Prawn::Example.generate("document_and_page_options.pdf", :page_size => "FOLIO") do - + package "document_and_page_options" do |p| - + p.example "page_size", :eval_source => false, :full_source => true p.example "page_margins", :eval_source => false, :full_source => true p.example "background", :eval_source => false, :full_source => true @@ -27,6 +27,6 @@ "How to add metadata to the generated PDF" ) end - + end end diff --git a/manual/document_and_page_options/metadata.rb b/manual/document_and_page_options/metadata.rb index e96226ecb..3a9facab8 100644 --- a/manual/document_and_page_options/metadata.rb +++ b/manual/document_and_page_options/metadata.rb @@ -13,11 +13,11 @@ :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 }) do - + text "This is a test of setting metadata properties via the info option." text "While the keys are arbitrary, the above example sets common attributes." end diff --git a/manual/document_and_page_options/page_margins.rb b/manual/document_and_page_options/page_margins.rb index 59ea03e5d..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 " + @@ -31,7 +31,7 @@ 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 c41d65626..bab2068be 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_file.rb b/manual/example_file.rb index 93ab5bd74..0bc6ad9ab 100644 --- a/manual/example_file.rb +++ b/manual/example_file.rb @@ -1,63 +1,63 @@ # encoding: utf-8 module Prawn - + # The Prawn::ExampleFile class is a utility class to ease the manipulation # and extraction of source code and comments from the actual example files # class ExampleFile attr_reader :package, :filename - + # Stores the file data, filename and parent, which will be either an # ExampleSection or an ExamplePackage. # # 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) # def initialize(parent, filename, options={}) @parent = parent.is_a?(String) ? ExamplePackage.new(parent) : parent - + @filename = filename @data = read_file(@parent.folder_name, filename) - + @options = {:eval_source => true, :full_source => false}.merge(options) end - + # Return the example source code excluding the initial comments and # require calls # def full_source @data.gsub(/# encoding.*?\n.*require.*?\n\n/m, "\n").strip end - + # Return the example source contained inside the first generate block or # the full source if no generate block is found # def generate_block_source block = @data.slice(/\w+\.generate.*? do\n(.*)end/m, 1) - + return full_source unless block - + block.gsub(/^( ){2}/, "") end - + # Return either the full_source or the generate_block_source according # to the options # def source @options[:full_source] ? full_source : generate_block_source end - + # Return true if the example source should be evaluated inline within # the manual according to the options # def eval? @options[:eval_source] end - + # Retrieve the comments between the encoding declaration and the require # call for example_helper.rb # @@ -71,33 +71,33 @@ def introduction_text intro.rstrip! intro end - + # Returns a human friendly version of the example file name # def name @name ||= @filename[/(.*)\.rb/, 1].gsub("_", " ").capitalize end - + # Returns this example's parent original folder name # def parent_folder_name @parent.folder_name end - + # Returns the human friendly version of this example parent name # def parent_name @parent.name end - + # Renders this example to a pdf # def render(pdf) pdf.render_example(self) end - + private - + # Read the data from a file in a given package # def read_file(folder_name, filename) @@ -106,6 +106,6 @@ def read_file(folder_name, filename) data.encode(::Encoding::UTF_8) end - + end end diff --git a/manual/example_package.rb b/manual/example_package.rb index b357030d6..ea87dd50a 100644 --- a/manual/example_package.rb +++ b/manual/example_package.rb @@ -1,18 +1,18 @@ # encoding: utf-8 module Prawn - + # The Prawn::ExamplePackage class is a utility class to handle the packaging # of individual examples within a hierarchy when building the manual # class ExamplePackage attr_reader :intro_block, :folder_name - + def initialize(folder_name) @folder_name = folder_name @hierarchy = [] end - + # Stores a new ExampleSection in the hierarchy and yields it to a block # def section(name) @@ -20,31 +20,31 @@ def section(name) yield s @hierarchy << s end - + # Stores a new ExampleFile in the hierarchy # def example(filename, options={}) @hierarchy << ExampleFile.new(self, "#{filename}.rb", options) end - + # Stores a block with code to be evaluated when rendering the package cover # def intro(&block) @intro_block = block end - + # Returns a human friendly version of the package name # def name @name ||= @folder_name.gsub("_", " ").capitalize end - + # Renders a cover page for the package to a pdf and iterates the examples # hierarchy delegating the examples and sections to be rendered as well # def render(pdf) pdf.render_package_cover(self) - + @hierarchy.each do |node| node.render(pdf) end diff --git a/manual/example_section.rb b/manual/example_section.rb index b4fbf6b16..5f691df5a 100644 --- a/manual/example_section.rb +++ b/manual/example_section.rb @@ -1,19 +1,19 @@ # encoding: utf-8 module Prawn - + # The Prawn::ExampleSection class is a utility class to handle sections # of related examples within an ExamplePackage # class ExampleSection attr_reader :name - + def initialize(package, name) @package = package @name = name @examples = [] end - + # Stores a new ExampleFile in the examples list # def example(filename, options={}) @@ -25,19 +25,19 @@ def example(filename, options={}) def folder_name @package.folder_name end - + # Returns the human friendly version of this section's package name # def package_name @package.name end - + # Renders the section to a pdf and iterates the examples list delegating the # examples to be rendered as well # def render(pdf) pdf.render_section(self) - + @examples.each do |example| example.render(pdf) end diff --git a/manual/graphics/circle_and_ellipse.rb b/manual/graphics/circle_and_ellipse.rb index 0ea09f27a..4ceed6d48 100644 --- a/manual/graphics/circle_and_ellipse.rb +++ b/manual/graphics/circle_and_ellipse.rb @@ -13,10 +13,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 885fa729c..8690db901 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 using RGB fill_color "FFFFCC" fill_polygon [50, 150], [150, 200], [250, 150], [250, 50], [150, 0], [50, 50] - + # Stroke with Purple using CMYK stroke_color 50, 100, 0, 0 stroke_rectangle [300, 300], 200, 100 - + # Both together fill_and_stroke_circle [400, 100], 50 end diff --git a/manual/graphics/common_lines.rb b/manual/graphics/common_lines.rb index c1d02a3a9..e3672f799 100644 --- a/manual/graphics/common_lines.rb +++ b/manual/graphics/common_lines.rb @@ -17,14 +17,14 @@ stroke_axis stroke_color "ff0000" - + 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 22371d726..c2dcff657 100644 --- a/manual/graphics/fill_and_stroke.rb +++ b/manual/graphics/fill_and_stroke.rb @@ -24,18 +24,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 bdf593cfc..762743276 100644 --- a/manual/graphics/graphics.rb +++ b/manual/graphics/graphics.rb @@ -6,14 +6,14 @@ %w[.. example_helper])) Prawn::Example.generate("graphics.pdf", :page_size => "FOLIO") do - + package "graphics" do |p| - + p.section "Basics" do |s| s.example "helper" s.example "fill_and_stroke" end - + p.section "Shapes" do |s| s.example "lines_and_curves" s.example "common_lines" @@ -21,7 +21,7 @@ s.example "polygon" s.example "circle_and_ellipse" end - + p.section "Fill and Stroke settings" do |s| s.example "line_width" s.example "stroke_cap" @@ -33,13 +33,13 @@ s.example "soft_masks" s.example "fill_rules" end - + p.section "Transformations" do |s| s.example "rotate" s.example "translate" s.example "scale" end - + p.intro do prose("Here we show all the drawing methods provided by Prawn. Use them to draw the most beautiful imaginable things. @@ -53,6 +53,6 @@ "How to apply transformations to your drawing space" ) end - + end end diff --git a/manual/graphics/line_width.rb b/manual/graphics/line_width.rb index e8e050824..ce5dd2428 100644 --- a/manual/graphics/line_width.rb +++ b/manual/graphics/line_width.rb @@ -14,22 +14,22 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + y = 250 - + 3.times do |i| case i when 0 then line_width = 10 # This call will have no effect when 1 then self.line_width = 10 when 2 then 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 end diff --git a/manual/graphics/lines_and_curves.rb b/manual/graphics/lines_and_curves.rb index 943ebbd68..c86fa86a4 100644 --- a/manual/graphics/lines_and_curves.rb +++ b/manual/graphics/lines_and_curves.rb @@ -21,18 +21,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 3a3d8cf7b..55fa2e544 100644 --- a/manual/graphics/polygon.rb +++ b/manual/graphics/polygon.rb @@ -16,14 +16,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 6299d587d..ffe4d91ff 100644 --- a/manual/graphics/rectangle.rb +++ b/manual/graphics/rectangle.rb @@ -12,10 +12,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 899b6a9a8..baea20932 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 be1ab5fed..976a3c5e5 100644 --- a/manual/graphics/stroke_cap.rb +++ b/manual/graphics/stroke_cap.rb @@ -18,12 +18,12 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + self.line_width = 25 [:butt, :round, :projecting_square].each_with_index do |cap, i| self.cap_style = cap - + y = 250 - i*100 stroke_horizontal_line 100, 300, :at => y stroke_circle [400, y], 15 diff --git a/manual/graphics/stroke_join.rb b/manual/graphics/stroke_join.rb index a646fafdd..bc4ae4f20 100644 --- a/manual/graphics/stroke_join.rb +++ b/manual/graphics/stroke_join.rb @@ -13,12 +13,12 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do stroke_axis - + self.line_width = 25 - + [:miter, :round, :bevel].each_with_index do |style, i| self.join_style = style - + y = 200 - i*100 stroke do move_to(100, y) 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 a7e80bd9e..a40c6ec12 100644 --- a/manual/graphics/transparency.rb +++ b/manual/graphics/transparency.rb @@ -18,18 +18,18 @@ 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 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 b41da22c2..f8e5d7bf7 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/images.rb b/manual/images/images.rb index 2c0e6c22d..1db9d9fa1 100644 --- a/manual/images/images.rb +++ b/manual/images/images.rb @@ -6,25 +6,25 @@ %w[.. example_helper])) Prawn::Example.generate("images.pdf", :page_size => "FOLIO") do - + package "images" do |p| - + p.section "Basics" do |s| s.example "plain_image" s.example "absolute_position" end - + p.section "Relative Positioning" do |s| s.example "horizontal" s.example "vertical" end - + p.section "Size" do |s| s.example "width_and_height" s.example "scale" s.example "fit" end - + p.intro do prose("Embedding images on PDF documents is fairly easy. Prawn supports both JPG and PNG images. @@ -35,6 +35,6 @@ "How to configure the image dimensions by setting the width and height or by scaling it" ) end - + end end diff --git a/manual/images/scale.rb b/manual/images/scale.rb index 167909cdc..d002c42bb 100644 --- a/manual/images/scale.rb +++ b/manual/images/scale.rb @@ -12,11 +12,11 @@ text "Normal size" image "#{Prawn::DATADIR}/images/stef.jpg" move_down 20 - + text "Scaled to 50%" image "#{Prawn::DATADIR}/images/stef.jpg", :scale => 0.5 move_down 20 - + 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 666d96a3b..dfc40f94f 100644 --- a/manual/images/vertical.rb +++ b/manual/images/vertical.rb @@ -13,13 +13,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 4316b739b..6f67f1c4d 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 20 - + text "Scale by setting only the height" image "#{Prawn::DATADIR}/images/pigs.jpg", :height => 100 move_down 20 - + 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/layout.rb b/manual/layout/layout.rb index 775241d15..f452490a5 100644 --- a/manual/layout/layout.rb +++ b/manual/layout/layout.rb @@ -6,13 +6,13 @@ %w[.. example_helper])) Prawn::Example.generate("layout.pdf", :page_size => "FOLIO") do - + package "layout" do |p| - + p.example "simple_grid" p.example "boxes" p.example "content" - + p.intro do prose("Prawn has support for two-dimensional grid based layouts out of the box. @@ -23,6 +23,6 @@ "How to create boxes according to the grid" ) end - + end 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 3d9b3def9..280514e86 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} @@ -38,5 +38,5 @@ git_commit, :size => 12} ], :at => [390, cursor - 620]) - + end diff --git a/manual/manual/how_to_read_this_manual.rb b/manual/manual/how_to_read_this_manual.rb index 18ce91f46..ce05f964a 100644 --- a/manual/manual/how_to_read_this_manual.rb +++ b/manual/manual/how_to_read_this_manual.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,33 +8,33 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do header("How to read this manual") - + prose <<-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 is not directly covered on this manual. END_TEXT - + move_down(BOX_MARGIN) header("Reading the examples") - + prose <<-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 features illustrated by the example. - + Next comes the example source code block 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. If it doesn't make sense to evaluate the snippet inline, a box with the link for the example file is shown instead. 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 this file: - + https://github.com/prawnpdf/prawn/blob/master/manual/example_helper.rb END_TEXT diff --git a/manual/outline/add_subsection_to.rb b/manual/outline/add_subsection_to.rb index b0e190974..a4ccb6bbf 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 a3694aca5..67d4b762d 100644 --- a/manual/outline/outline.rb +++ b/manual/outline/outline.rb @@ -6,18 +6,18 @@ %w[.. example_helper])) Prawn::Example.generate("outline.pdf", :page_size => "FOLIO") do - + package "outline" do |p| - + p.section "Basics" do |s| s.example "sections_and_pages", :eval_source => false end - + p.section "Adding nodes later" do |s| s.example "add_subsection_to", :eval_source => false s.example "insert_section_after", :eval_source => false end - + p.intro do prose("The outline of a PDF document is the table of contents tab you see to the right or left of your PDF viewer. @@ -27,6 +27,6 @@ "How to insert sections and/or pages to a previously defined outline structure" ) end - + end end diff --git a/manual/outline/sections_and_pages.rb b/manual/outline/sections_and_pages.rb index 21f498c78..2a9bfe82c 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 6f896287b..eead0cd50 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 5faebd0cd..2477aab29 100644 --- a/manual/repeatable_content/repeatable_content.rb +++ b/manual/repeatable_content/repeatable_content.rb @@ -6,13 +6,13 @@ %w[.. example_helper])) Prawn::Example.generate("repeatable_content.pdf", :page_size => "FOLIO") do - + package "repeatable_content" do |p| - + p.example "repeater", :eval_source => false p.example "stamp" p.example "page_numbering", :eval_source => false - + p.intro do prose("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. @@ -26,6 +26,6 @@ "How to number the document pages with one simple call" ) end - + end end diff --git a/manual/repeatable_content/repeater.rb b/manual/repeatable_content/repeater.rb index 4ac18ec47..88f16b565 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 a36e87f21..eb63a6ab7 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/security/security.rb b/manual/security/security.rb index dc64d10b6..80234fe07 100644 --- a/manual/security/security.rb +++ b/manual/security/security.rb @@ -6,12 +6,12 @@ %w[.. example_helper])) Prawn::Example.generate("security.pdf", :page_size => "FOLIO") do - + package "security" do |p| - + p.example "encryption", :eval_source => false, :full_source => true p.example "permissions", :eval_source => false, :full_source => true - + p.intro do prose("Security lets you control who can read the document by defining a password. @@ -23,6 +23,6 @@ "How to set a owner password that bypass the document permissions" ) end - + end end diff --git a/manual/syntax_highlight.rb b/manual/syntax_highlight.rb index 4ad606de2..90aee8e2b 100644 --- a/manual/syntax_highlight.rb +++ b/manual/syntax_highlight.rb @@ -13,7 +13,7 @@ class PrawnEncoder < CodeRay::Encoders::Encoder register_for :to_prawn COLORS = { :default => "FFFFFF", - + :comment => "AEAEAE", :constant => "88A5D2", :instance_variable => "E8ED97", @@ -21,13 +21,13 @@ class PrawnEncoder < CodeRay::Encoders::Encoder :float => "C8FF0E", :inline_delimiter => "EF804F", # #{} within a string :keyword => "FEE100", - + # BUG: There appear to be some problem with this token. Method # definitions are considered as ident tokens # :method => "FF5C00", :string => "56D65E", - :symbol => "C8FF0E" + :symbol => "C8FF0E" } def setup(options) @@ -38,7 +38,7 @@ def setup(options) def text_token(text, kind) color = COLORS[kind] || COLORS[@open.last] || COLORS[:default] - + @out << {:text => text, :color => color} end diff --git a/manual/table/basic_block.rb b/manual/table/basic_block.rb index 1dcd69372..40e93cc0c 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_border_lines.rb b/manual/table/cell_border_lines.rb index 5e5d7e172..d83dc80a1 100644 --- a/manual/table/cell_border_lines.rb +++ b/manual/table/cell_border_lines.rb @@ -16,9 +16,9 @@ ["dotted bottom border", "", ""], ["dashed left border", "", ""] ] - + text "Cell :border_lines => [:dotted, :solid, :dotted, :dashed]" - - table(data, :cell_style => + + table(data, :cell_style => { :border_lines => [:dotted, :solid, :dotted, :dashed] }) 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 6c84edc72..a58affa45 100644 --- a/manual/table/content_and_subtables.rb +++ b/manual/table/content_and_subtables.rb @@ -24,13 +24,13 @@ 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"], ["..."] ] - + my_table = make_table([ ["..."], ["subtable from another table"], ["..."] ]) - + image_path = "#{Prawn::DATADIR}/images/stef.jpg" - + 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 414bcb734..52d97bf0f 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 it 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 01fc2d0d4..09dd31bc2 100644 --- a/manual/table/flow_and_header.rb +++ b/manual/table/flow_and_header.rb @@ -12,6 +12,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 14c46a963..17d7c8048 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/table.rb b/manual/table/table.rb index 591806e40..9d48d234a 100644 --- a/manual/table/table.rb +++ b/manual/table/table.rb @@ -6,16 +6,16 @@ %w[.. example_helper])) Prawn::Example.generate("table.pdf", :page_size => "FOLIO") do - + package "table" do |p| - + p.section "Basics" do |s| s.example "creation" s.example "content_and_subtables" s.example "flow_and_header" s.example "position" end - + p.section "Styling" do |s| s.example "column_widths" s.example "width" @@ -28,13 +28,13 @@ s.example "span" s.example "before_rendering_page" end - + p.section "Initializer Block" do |s| s.example "basic_block" s.example "filtering" s.example "style" end - + p.intro do prose("Prawn comes with table support out of the box. Tables can be styled in whatever way you see fit. The whole table, rows, columns and cells can be styled independently from each other. @@ -47,6 +47,6 @@ "How to use initializer blocks to style only specific portions of the table" ) end - + 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/text/fallback_fonts.rb b/manual/text/fallback_fonts.rb index 2f40d660d..ea23f2920 100644 --- a/manual/text/fallback_fonts.rb +++ b/manual/text/fallback_fonts.rb @@ -13,12 +13,12 @@ font_families["Kai"] = { :normal => { :file => file, :font => "Kai" } } - + file = "#{Prawn::DATADIR}/fonts/Panic+Sans.dfont" font_families["Panic Sans"] = { :normal => { :file => file, :font => "PanicSans" }, } - + font("Panic Sans") do text("When fallback fonts are included, each glyph will be rendered " + "using the first font that includes the glyph, starting with the " + diff --git a/manual/text/font.rb b/manual/text/font.rb index 663c3c402..bc6474ecb 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 @@ -19,22 +19,22 @@ 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}" - + move_down 20 font "Helvetica" text "Back to normal." diff --git a/manual/text/font_size.rb b/manual/text/font_size.rb index db48970ab..505810557 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. # @@ -17,28 +17,28 @@ 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 - + move_down 10 font("Helvetica", :size => 12) text "Back to normal" diff --git a/manual/text/font_style.rb b/manual/text/font_style.rb index 04e04641a..906ee3b13 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. # @@ -14,7 +14,7 @@ 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})" diff --git a/manual/text/formatted_callbacks.rb b/manual/text/formatted_callbacks.rb index 556a625ba..95bf7c640 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 3159c38d6..d11dd17e6 100644 --- a/manual/text/formatted_text.rb +++ b/manual/text/formatted_text.rb @@ -17,7 +17,7 @@ # :character_spacing (additional space between the characters), # :font (the name of a registered font), :color (the # same input accepted by fill_color and stroke_color), -# :link (an URL to create a link), and :local +# :link (an URL to create a link), and :local # (a link to a local file). require File.expand_path(File.join(File.dirname(__FILE__), @@ -39,7 +39,7 @@ :color => "0000FF", :local => "./local_file.txt" } ] - + 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 3f56b4b3c..e3d248867 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_cursor_to 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/inline.rb b/manual/text/inline.rb index 828c53156..e6bebcad5 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), @@ -22,18 +22,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" + "", 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 78c5e2ebf..9d171e108 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 @@ -15,11 +15,11 @@ 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 end diff --git a/manual/text/line_wrapping.rb b/manual/text/line_wrapping.rb index 7346aeed7..aec628917 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 36f52c26c..2b3eb5202 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: # @@ -18,7 +18,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 f2440fc4c..3f22121c5 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 68f0f837e..ec0069571 100644 --- a/manual/text/registering_families.rb +++ b/manual/text/registering_families.rb @@ -17,12 +17,12 @@ font_families.update("DejaVu Sans" => { :normal => "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf" }) - + font("DejaVu Sans") do text "Using the DejaVu Sans font providing only its name to the font method" end move_down 20 - + # Registering a DFONT package font_path = "#{Prawn::DATADIR}/fonts/Panic+Sans.dfont" font_families.update("Panic Sans" => { @@ -31,15 +31,15 @@ :bold => { :file => font_path, :font => "PanicSans-Bold" }, :bold_italic => { :file => font_path, :font => "PanicSans-BoldItalic" } }) - + font "Panic Sans" text "Also using Panic Sans 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 diff --git a/manual/text/rendering_and_color.rb b/manual/text/rendering_and_color.rb index 7b03aebf7..1dbc78f5c 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." diff --git a/manual/text/right_to_left_text.rb b/manual/text/right_to_left_text.rb index b411be0f2..8b24beff5 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 diff --git a/manual/text/rotation.rb b/manual/text/rotation.rb index 568b2d945..1ea789e17 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 |corner, index| - + y = y - 100 if index == 2 stroke_rectangle [x + (index % 2) * 200, y], width, height text_box("This text was rotated around the #{corner} corner.", diff --git a/manual/text/single_usage.rb b/manual/text/single_usage.rb index df64fb233..51316c282 100644 --- a/manual/text/single_usage.rb +++ b/manual/text/single_usage.rb @@ -23,10 +23,10 @@ text "Written with the DejaVu Sans TTF font." end move_down 20 - + text "Written with the default font." move_down 20 - + # Using an DFONT font file font("#{Prawn::DATADIR}/fonts/Panic+Sans.dfont") do text "Written with the Panic Sans DFONT font" diff --git a/manual/text/text.rb b/manual/text/text.rb index fdecf6b7d..d901850ed 100644 --- a/manual/text/text.rb +++ b/manual/text/text.rb @@ -6,9 +6,9 @@ %w[.. example_helper])) Prawn::Example.generate("text.pdf", :page_size => "FOLIO") do - + package "text" do |p| - + p.section "Basics" do |s| s.example "free_flowing_text" s.example "positioned_text" @@ -16,7 +16,7 @@ s.example "text_box_excess" s.example "column_box" end - + p.section "Styling" do |s| s.example "font" s.example "font_size" @@ -28,7 +28,7 @@ s.example "paragraph_indentation" s.example "rotation" end - + p.section "Advanced Styling" do |s| s.example "inline" s.example "formatted_text" @@ -36,12 +36,12 @@ s.example "rendering_and_color" s.example "text_box_extensions" end - + p.section "External Fonts" do |s| s.example "single_usage" s.example "registering_families" end - + p.section "M17n" do |s| s.example "utf8" s.example "line_wrapping" @@ -49,7 +49,7 @@ s.example "fallback_fonts" s.example "win_ansi_charset" end - + p.intro do prose("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 configurable options. @@ -68,6 +68,6 @@ "What happens when rendering text in different languages" ) end - + end end diff --git a/manual/text/text_box_excess.rb b/manual/text/text_box_excess.rb index 371b0f839..449dc60fb 100644 --- a/manual/text/text_box_excess.rb +++ b/manual/text/text_box_excess.rb @@ -25,7 +25,7 @@ :overflow => :truncate, :at => [100, y_position], :size => 18 - + text_box excess_text, :width => 300, :at => [100, y_position - 100] diff --git a/manual/text/text_box_extensions.rb b/manual/text/text_box_extensions.rb index 3529c1971..74cc050b9 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/acceptance/png.rb b/spec/acceptance/png.rb index fe88132ec..aef90dd47 100644 --- a/spec/acceptance/png.rb +++ b/spec/acceptance/png.rb @@ -17,9 +17,9 @@ fill_color "FF0000" fill_rectangle bounds.top_left, bounds.width, bounds.height - text header - + text header + image file, :at => [50,450] - end + end end diff --git a/spec/column_box_spec.rb b/spec/column_box_spec.rb index 8ac409153..c115446fc 100644 --- a/spec/column_box_spec.rb +++ b/spec/column_box_spec.rb @@ -58,7 +58,7 @@ @pdf.bounds.move_past_bottom @pdf.bounds.move_past_bottom - @pdf.bounds.absolute_top.should == page_top + @pdf.bounds.absolute_top.should == page_top @pdf.bounds.absolute_top.should_not == init_column_top end end diff --git a/spec/table_spec.rb b/spec/table_spec.rb index 7a4811ad4..6ee7d20da 100644 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -53,9 +53,9 @@ ] #we need values with lots of decimals so that arithmetic errors will occur #the values are not arbitrary but where found converting mm to pdf pt - column_widths=[137, 40, 40, 54.69291338582678, 54.69291338582678, - 54.69291338582678, 54.69291338582678, 54.69291338582678, - 54.69291338582678, 54.69291338582678, 54.69291338582678, + column_widths=[137, 40, 40, 54.69291338582678, 54.69291338582678, + 54.69291338582678, 54.69291338582678, 54.69291338582678, + 54.69291338582678, 54.69291338582678, 54.69291338582678, 54.69291338582678] pdf = Prawn::Document.new({:page_size => 'A4', :page_layout => :landscape}) @@ -63,10 +63,10 @@ table.column_widths.should == column_widths end - it "should work with two different given colspans", :issue => 628 do + it "should work with two different given colspans", :issue => 628 do data = [ - [" ", " ", " "], - [{:content=>" ", :colspan=>3}], + [" ", " ", " "], + [{:content=>" ", :colspan=>3}], [" ", {:content=>" ", :colspan=>2}] ] column_widths = [60, 240, 60] @@ -114,17 +114,17 @@ :unresolved, :issue => 612 do pdf = Prawn::Document.new - + first = {:content=>"Foooo fo foooooo",:width=>50,:align=>:center} second = {:content=>"Foooo",:colspan=>2,:width=>70,:align=>:center} third = {:content=>"fooooooooooo, fooooooooooooo, fooo, foooooo fooooo",:width=>50,:align=>:center} fourth = {:content=>"Bar",:width=>20,:align=>:center} - + table_content = [[ first, [[second],[third,fourth]] ]] - + table = Prawn::Table.new table_content, pdf table.column_widths.should == [50.0, 70.0] end @@ -162,7 +162,7 @@ table.column_widths.should == [50.0, 200.0] end - it "illustrates a variant of problem in issue #407 - comment 28556698" do + it "illustrates a variant of problem in issue #407 - comment 28556698" do pdf = Prawn::Document.new table_data = [["a", "b", "c"], [{:content=>"d", :colspan=>3}]] column_widths = [50, 60, 400] diff --git a/spec/text_spec.rb b/spec/text_spec.rb index 06eb79a22..b3c2a4be6 100644 --- a/spec/text_spec.rb +++ b/spec/text_spec.rb @@ -410,7 +410,7 @@ end describe "#shrink_to_fit with special utf-8 text" do - it "Should not throw an exception", + it "Should not throw an exception", :unresolved, :issue => 603 do pages = 0 doc = Prawn::Document.new(page_size: 'A4', margin: [2, 2, 2, 2]) do |pdf|