prawn 0.13.2 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a27927232c4c77d3933d18984c31230475c1b97
4
- data.tar.gz: 711b6736c9a1a5bfc2131d0d0cec5e5ef3f2faad
3
+ metadata.gz: d83c112e79d7d99ade30524585cf7d7cb7d4de52
4
+ data.tar.gz: a0143b1b1ebf8db3776daafe04dbceeedb62db6b
5
5
  SHA512:
6
- metadata.gz: cfc74a6d17392cf8d2e97257df8e80e2bb2fd36e55293fd1507efc900a5d8b40161dae98e3e99d6ff5b99052eb64f0d3bcc6654def35fd9384f83ece176237fc
7
- data.tar.gz: 9355d24d34c93280b67f161c9aababa5360f8cf685fa081adafaa76fa1dddb4eecd07dacecb413ec671f6081d3aa5e09b728cdee627482f2ec4951903bb0089e
6
+ metadata.gz: 6f9ac40edd92c31df1f2a63e73684f983069edcb8f1dd15ffb26f9bcc85256ac4adc0f476aa6ef5b4fa2248318515c56a39dc68e5f2352711e30dd4863aa4989
7
+ data.tar.gz: 7ecbae3e281cae29a8a7234fc32c0148eaae4d27dabc35cecba01073d28319c5480c50dcc1cce2f1bdb5b1c99b4a11e80168d62b8c7c94faa8a1a1f7995f0043
@@ -0,0 +1,9 @@
1
+ --charset UTF-8
2
+ --main README.md
3
+ --title 'Prawn Documentation'
4
+ lib/**/*.rb
5
+ -
6
+ CONTRIBUTING.md
7
+ COPYING
8
+ LICENSE
9
+ README.md
data/Gemfile CHANGED
@@ -1,17 +1,11 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "ttfunk", "~>1.0.3"
4
- gem "pdf-reader", "~> 1.2"
5
- gem "ruby-rc4"
3
+ gemspec
6
4
 
7
- group :development do
8
- gem "coderay", "~> 1.0.7"
9
- gem "rdoc"
10
- end
11
-
12
- group :test do
13
- gem "pdf-inspector", "~> 1.1.0", :require => "pdf/inspector"
14
- gem "rspec"
15
- gem "mocha", :require => false
16
- gem "rake"
5
+ if ENV["CI"]
6
+ platforms :rbx do
7
+ gem "rubysl-singleton", "~> 2.0"
8
+ gem "rubysl-digest", "~> 2.0"
9
+ gem "rubysl-enumerator", "~> 2.0"
10
+ end
17
11
  end
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ Bundler.setup
3
3
 
4
4
  require 'rake'
5
5
  require 'rspec/core/rake_task'
6
- require 'rdoc/task'
6
+ require 'yard'
7
7
  require 'rubygems/package_task'
8
8
 
9
9
  task :default => [:spec]
@@ -21,16 +21,11 @@ task :stats do
21
21
  ["Specs", "spec"] ).to_s
22
22
  end
23
23
 
24
- desc "genrates documentation"
25
- RDoc::Task.new do |rdoc|
26
- rdoc.rdoc_files.include( "README.md",
27
- "COPYING",
28
- "LICENSE",
29
- "lib/" )
30
- rdoc.main = "README.md"
31
- rdoc.rdoc_dir = "doc/html"
32
- rdoc.title = "Prawn Documentation"
24
+ YARD::Rake::YardocTask.new do |t|
25
+ t.options = ['--output-dir', 'doc/html']
33
26
  end
27
+ task :docs => :yard
28
+
34
29
 
35
30
  desc "Generate the 'Prawn by Example' manual"
36
31
  task :manual do
@@ -5,10 +5,11 @@ module PDF
5
5
  normalize_metadata(options)
6
6
 
7
7
  if options[:template]
8
- @store = PDF::Core::ObjectStore.new(:template => options[:template])
8
+ @store = PDF::Core::ObjectStore.new(:template => options[:template],
9
+ :print_scaling => options[:print_scaling])
9
10
  @store.info.data.merge!(options[:info]) if options[:info]
10
11
  else
11
- @store = PDF::Core::ObjectStore.new(:info => options[:info])
12
+ @store = PDF::Core::ObjectStore.new(:info => options[:info], :print_scaling => options[:print_scaling])
12
13
  end
13
14
 
14
15
  @version = 1.3
@@ -43,17 +43,23 @@ module PDF
43
43
 
44
44
  end
45
45
 
46
+ # NOTE: This class may be a good candidate for a copy-on-write hash.
46
47
  class GraphicState
47
- attr_accessor :color_space, :dash, :cap_style, :join_style, :line_width, :fill_color, :stroke_color
48
+ attr_accessor :color_space, :dash, :cap_style, :join_style, :line_width,
49
+ :fill_color, :stroke_color
48
50
 
49
51
  def initialize(previous_state = nil)
50
- @color_space = previous_state ? previous_state.color_space.dup : {}
51
- @fill_color = previous_state ? previous_state.fill_color : "000000"
52
- @stroke_color = previous_state ? previous_state.stroke_color : "000000"
53
- @dash = previous_state ? previous_state.dash : { :dash => nil, :space => nil, :phase => 0 }
54
- @cap_style = previous_state ? previous_state.cap_style : :butt
55
- @join_style = previous_state ? previous_state.join_style : :miter
56
- @line_width = previous_state ? previous_state.line_width : 1
52
+ if previous_state
53
+ initialize_copy(previous_state)
54
+ else
55
+ @color_space = {}
56
+ @fill_color = "000000"
57
+ @stroke_color = "000000"
58
+ @dash = { :dash => nil, :space => nil, :phase => 0 }
59
+ @cap_style = :butt
60
+ @join_style = :miter
61
+ @line_width = 1
62
+ end
57
63
  end
58
64
 
59
65
  def dash_setting
@@ -63,6 +69,21 @@ module PDF
63
69
  "[#{@dash[:dash]} #{@dash[:space]}] #{@dash[:phase]} d"
64
70
  end
65
71
  end
72
+
73
+ private
74
+
75
+ def initialize_copy(other)
76
+ # mutable state
77
+ @color_space = other.color_space.dup
78
+ @fill_color = other.fill_color.dup
79
+ @stroke_color = other.stroke_color.dup
80
+ @dash = other.dash.dup
81
+
82
+ # immutable state that doesn't need to be duped
83
+ @cap_style = other.cap_style
84
+ @join_style = other.join_style
85
+ @line_width = other.line_width
86
+ end
66
87
  end
67
88
  end
68
89
  end
@@ -26,6 +26,9 @@ module PDF
26
26
 
27
27
  @info ||= ref(opts[:info] || {}).identifier
28
28
  @root ||= ref(:Type => :Catalog).identifier
29
+ if opts[:print_scaling] == :none
30
+ root.data[:ViewerPreferences] = {:PrintScaling => :None}
31
+ end
29
32
  if pages.nil?
30
33
  root.data[:Pages] = ref(:Type => :Pages, :Count => 0, :Kids => [])
31
34
  end
@@ -20,7 +20,7 @@ end
20
20
  require "set"
21
21
 
22
22
  module Prawn
23
- VERSION = "0.13.2"
23
+ VERSION = "0.14.0"
24
24
 
25
25
  extend self
26
26
 
@@ -62,6 +62,14 @@ module Prawn
62
62
  include Prawn::Stamp
63
63
  include Prawn::SoftMask
64
64
 
65
+ # NOTE: We probably need to rethink the options validation system, but this
66
+ # constant temporarily allows for extensions to modify the list.
67
+
68
+ VALID_OPTIONS = [:page_size, :page_layout, :margin, :left_margin,
69
+ :right_margin, :top_margin, :bottom_margin, :skip_page_creation,
70
+ :compress, :skip_encoding, :background, :info,
71
+ :optimize_objects, :text_formatter, :print_scaling]
72
+
65
73
  # Any module added to this array will be included into instances of
66
74
  # Prawn::Document at the per-object level. These will also be inherited by
67
75
  # any subclasses.
@@ -138,7 +146,6 @@ module Prawn
138
146
  # <tt>:background</tt>:: An image path to be used as background on all pages [nil]
139
147
  # <tt>:background_scale</tt>:: Backgound image scale [1] [nil]
140
148
  # <tt>:info</tt>:: Generic hash allowing for custom metadata properties [nil]
141
- # <tt>:template</tt>:: The path to an existing PDF file to use as a template [nil]
142
149
  # <tt>:text_formatter</tt>: The text formatter to use for <tt>:inline_format</tt>ted text [Prawn::Text::Formatted::Parser]
143
150
  #
144
151
  # Setting e.g. the :margin to 100 points and the :left_margin to 50 will result in margins
@@ -173,10 +180,7 @@ module Prawn
173
180
  def initialize(options={},&block)
174
181
  options = options.dup
175
182
 
176
- Prawn.verify_options [:page_size, :page_layout, :margin, :left_margin,
177
- :right_margin, :top_margin, :bottom_margin, :skip_page_creation,
178
- :compress, :skip_encoding, :background, :info,
179
- :optimize_objects, :template, :text_formatter], options
183
+ Prawn.verify_options VALID_OPTIONS, options
180
184
 
181
185
  # need to fix, as the refactoring breaks this
182
186
  # raise NotImplementedError if options[:skip_page_creation]
@@ -186,6 +190,8 @@ module Prawn
186
190
  @internal_state.populate_pages_from_store(self)
187
191
  min_version(state.store.min_version) if state.store.min_version
188
192
 
193
+ min_version(1.6) if options[:print_scaling] == :none
194
+
189
195
  @background = options[:background]
190
196
  @background_scale = options[:background_scale] || 1
191
197
  @font_size = 12
@@ -200,16 +206,7 @@ module Prawn
200
206
  options[:size] = options.delete(:page_size)
201
207
  options[:layout] = options.delete(:page_layout)
202
208
 
203
- if options[:template]
204
- fresh_content_streams(options)
205
- go_to_page(1)
206
- else
207
- if options[:skip_page_creation] || options[:template]
208
- start_new_page(options.merge(:orphan => true))
209
- else
210
- start_new_page(options)
211
- end
212
- end
209
+ initialize_first_page(options)
213
210
 
214
211
  @bounding_box = @margin_box
215
212
 
@@ -232,6 +229,14 @@ module Prawn
232
229
  state.page
233
230
  end
234
231
 
232
+ def initialize_first_page(options)
233
+ if options[:skip_page_creation]
234
+ start_new_page(options.merge(:orphan => true))
235
+ else
236
+ start_new_page(options)
237
+ end
238
+ end
239
+
235
240
  # Creates and advances to a new page in the document.
236
241
  #
237
242
  # Page size, margins, and layout can also be set when generating a
@@ -242,14 +247,6 @@ module Prawn
242
247
  # pdf.start_new_page(:left_margin => 50, :right_margin => 50)
243
248
  # pdf.start_new_page(:margin => 100)
244
249
  #
245
- # A template for a page can be specified by pointing to the path of and existing pdf.
246
- # One can also specify which page of the template which defaults otherwise to 1.
247
- #
248
- # pdf.start_new_page(:template => multipage_template.pdf, :template_page => 2)
249
- #
250
- # Note: templates get indexed by either the object_id of the filename or stream
251
- # entered so that if you reuse the same template multiple times be sure to use the
252
- # same instance for more efficient use of resources and smaller rendered pdfs.
253
250
  def start_new_page(options = {})
254
251
  if last_page = state.page
255
252
  last_page_size = last_page.size
@@ -266,7 +263,6 @@ module Prawn
266
263
  new_graphic_state.color_space = {} if new_graphic_state
267
264
  page_options.merge!(:graphic_state => new_graphic_state)
268
265
  end
269
- merge_template_options(page_options, options) if options[:template]
270
266
 
271
267
  state.page = PDF::Core::Page.new(self, page_options)
272
268
 
@@ -279,9 +275,7 @@ module Prawn
279
275
  @bounding_box = @margin_box
280
276
  end
281
277
 
282
- state.page.new_content_stream if options[:template]
283
- use_graphic_settings(options[:template])
284
- forget_text_rendering_mode! if options[:template]
278
+ use_graphic_settings
285
279
 
286
280
  unless options[:orphan]
287
281
  state.insert_page(state.page, @page_number)
@@ -651,13 +645,8 @@ module Prawn
651
645
 
652
646
  private
653
647
 
654
- def merge_template_options(page_options, options)
655
- object_id = state.store.import_page(options[:template], options[:template_page] || 1)
656
- page_options.merge!(:object_id => object_id, :page_template => true)
657
- end
658
-
659
648
  # setting override_settings to true ensures that a new graphic state does not end up using
660
- # previous settings especially from imported template streams
649
+ # previous settings.
661
650
  def use_graphic_settings(override_settings = false)
662
651
  set_fill_color if current_fill_color != "000000" || override_settings
663
652
  set_stroke_color if current_stroke_color != "000000" || override_settings
@@ -188,10 +188,21 @@ module Prawn
188
188
 
189
189
  parent_box = @bounding_box
190
190
 
191
+ original_ypos = y
192
+
191
193
  init_block.call(parent_box)
192
194
 
193
195
  self.y = @bounding_box.absolute_top
194
196
  user_block.call
197
+
198
+ # If the user actions did not modify the y position
199
+ # restore the original y position before the bounding
200
+ # box was created.
201
+
202
+ if y == @bounding_box.absolute_top
203
+ self.y = original_ypos
204
+ end
205
+
195
206
  unless options[:hold_position] || @bounding_box.stretchy?
196
207
  self.y = @bounding_box.absolute_bottom
197
208
  end
@@ -15,10 +15,13 @@ module Prawn
15
15
  # filled.
16
16
  #
17
17
  # column_box accepts the same parameters as bounding_box, as well as the
18
- # number of :columns and a :spacer (in points) between columns.
19
- #
20
- # Defaults are :columns = 3 and :spacer = font_size
18
+ # number of :columns and a :spacer (in points) between columns. If resetting
19
+ # the top margin is desired on a new page (e.g. to allow for initial page
20
+ # wide column titles) the option :reflow_margins => true can be set.
21
21
  #
22
+ # Defaults are :columns = 3, :spacer = font_size, and
23
+ # :reflow_margins => false
24
+ #
22
25
  # Under PDF::Writer, "spacer" was known as "gutter"
23
26
  #
24
27
  def column_box(*args, &block)
@@ -52,6 +55,7 @@ module Prawn
52
55
  @columns = options[:columns] || 3
53
56
  @spacer = options[:spacer] || @document.font_size
54
57
  @current_column = 0
58
+ @reflow_margins = options[:reflow_margins]
55
59
  end
56
60
 
57
61
  # The column width, not the width of the whole box,
@@ -104,6 +108,9 @@ module Prawn
104
108
  @current_column = (@current_column + 1) % @columns
105
109
  @document.y = @y
106
110
  if 0 == @current_column
111
+ if @reflow_margins
112
+ @y = @parent.absolute_top
113
+ end
107
114
  @document.start_new_page
108
115
  end
109
116
  end
@@ -18,6 +18,10 @@ module Prawn
18
18
  @handlers.unshift handler
19
19
  end
20
20
 
21
+ def unregister(handler)
22
+ @handlers.reject!{ |h| h == handler }
23
+ end
24
+
21
25
  def find(image_blob)
22
26
  handler = @handlers.find{ |h| h.can_render? image_blob }
23
27
 
@@ -12,13 +12,8 @@ module Prawn
12
12
 
13
13
  module Images
14
14
  # Add the image at filename to the current page. Currently only
15
- # JPG and PNG files are supported.
16
- #
17
- # NOTE: Prawn is very slow at rendering PNGs with alpha channels, and this
18
- # uses a lot of RAM. The workaround for those who don't mind installing
19
- # RMagick is to use:
20
- #
21
- # http://github.com/amberbit/prawn-fast-png
15
+ # JPG and PNG files are supported. (Note that processing PNG
16
+ # images with alpha channels can be processor and memory intensive.)
22
17
  #
23
18
  # Arguments:
24
19
  # <tt>file</tt>:: path to file or an object that responds to #read
@@ -240,6 +240,9 @@ module Prawn
240
240
  end
241
241
  end
242
242
 
243
+ #if there are only colspanned or rowspanned cells in a table
244
+ spanned_width_needs_fixing = true
245
+
243
246
  each do |cell|
244
247
  index = cell.send(row_or_column)
245
248
  if cell.colspan > 1
@@ -251,8 +254,9 @@ module Prawn
251
254
 
252
255
  #calculate future return value
253
256
  new_sum = cell.send(meth) * cell.colspan
257
+ spanned_width_needs_fixing = (new_sum > old_sum)
254
258
 
255
- if new_sum >= old_sum
259
+ if spanned_width_needs_fixing
256
260
  #not entirely sure why we need this line, but with it the tests pass
257
261
  values[index] = [values[index], cell.send(meth)].compact.send(aggregate)
258
262
  #overwrite the old values with the new ones, but only if all entries existed
@@ -263,7 +267,7 @@ module Prawn
263
267
  }
264
268
  end
265
269
  else
266
- if cell.class == Prawn::Table::Cell::SpanDummy
270
+ if spanned_width_needs_fixing && cell.class == Prawn::Table::Cell::SpanDummy
267
271
  values[index] = [values[index], cell.send(meth)].compact.send(aggregate)
268
272
  end
269
273
  end
@@ -0,0 +1,75 @@
1
+ warn "Templates are no longer supported in Prawn!\n" +
2
+ "This code is for experimental testing only, and\n" +
3
+ "will extracted into its own gem in a future Prawn release"
4
+
5
+ module Prawn
6
+ module Templates
7
+ def initialize_first_page(options)
8
+ return super unless options[:template]
9
+
10
+ fresh_content_streams(options)
11
+ go_to_page(1)
12
+ end
13
+
14
+ ## FIXME: This is going to be terribly brittle because
15
+ # it copy-pastes the start_new_page method. But at least
16
+ # it should only run when templates are used.
17
+
18
+ def start_new_page(options = {})
19
+ return super unless options[:template]
20
+
21
+ if last_page = state.page
22
+ last_page_size = last_page.size
23
+ last_page_layout = last_page.layout
24
+ last_page_margins = last_page.margins
25
+ end
26
+
27
+ page_options = {:size => options[:size] || last_page_size,
28
+ :layout => options[:layout] || last_page_layout,
29
+ :margins => last_page_margins}
30
+ if last_page
31
+ new_graphic_state = last_page.graphic_state.dup if last_page.graphic_state
32
+ #erase the color space so that it gets reset on new page for fussy pdf-readers
33
+ new_graphic_state.color_space = {} if new_graphic_state
34
+ page_options.merge!(:graphic_state => new_graphic_state)
35
+ end
36
+
37
+ merge_template_options(page_options, options)
38
+
39
+ state.page = PDF::Core::Page.new(self, page_options)
40
+
41
+ apply_margin_options(options)
42
+ generate_margin_box
43
+
44
+ # Reset the bounding box if the new page has different size or layout
45
+ if last_page && (last_page.size != state.page.size ||
46
+ last_page.layout != state.page.layout)
47
+ @bounding_box = @margin_box
48
+ end
49
+
50
+ state.page.new_content_stream
51
+ use_graphic_settings(true)
52
+ forget_text_rendering_mode!
53
+
54
+ unless options[:orphan]
55
+ state.insert_page(state.page, @page_number)
56
+ @page_number += 1
57
+
58
+ canvas { image(@background, :scale => @background_scale, :at => bounds.top_left) } if @background
59
+ @y = @bounding_box.absolute_top
60
+
61
+ float do
62
+ state.on_page_create_action(self)
63
+ end
64
+ end
65
+ end
66
+
67
+ def merge_template_options(page_options, options)
68
+ object_id = state.store.import_page(options[:template], options[:template_page] || 1)
69
+ page_options.merge!(:object_id => object_id, :page_template => true)
70
+ end
71
+ end
72
+ end
73
+
74
+ Prawn::Document::VALID_OPTIONS << :template
75
+ Prawn::Document.extensions << Prawn::Templates
@@ -14,7 +14,8 @@ Prawn::Example.generate("document_and_page_options.pdf",
14
14
  p.example "page_margins", :eval_source => false, :full_source => true
15
15
  p.example "background", :eval_source => false, :full_source => true
16
16
  p.example "metadata", :eval_source => false, :full_source => true
17
-
17
+ p.example "print_scaling",:eval_source => false, :full_source => true
18
+
18
19
  p.intro do
19
20
  prose("So far we've already seen how to create new documents and start new pages. This chapter expands on the previous examples by showing other options avialable. Some of the options are only available when creating new documents.
20
21
 
@@ -2,6 +2,7 @@
2
2
  #
3
3
  # To set the document metadata just pass a hash to the <code>:info</code>
4
4
  # option when creating new documents.
5
+ # The keys in the example below are arbitrary, so you may add whatever keys you want
5
6
  #
6
7
  require File.expand_path(File.join(File.dirname(__FILE__),
7
8
  %w[.. example_helper]))
@@ -14,10 +15,9 @@ Prawn::Document.generate("metadata.pdf",
14
15
  :Keywords => "test metadata ruby pdf dry",
15
16
  :Creator => "ACME Soft App",
16
17
  :Producer => "Prawn",
17
- :CreationDate => Time.now,
18
- :Grok => "Test Property"
18
+ :CreationDate => Time.now
19
19
  }) do
20
20
 
21
21
  text "This is a test of setting metadata properties via the info option."
22
- text "It allows one to specify non standard properties like 'Grok'."
22
+ text "While the keys are arbitrary, the above example sets common attributes."
23
23
  end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ #
3
+ # (Optional; PDF 1.6) The page scaling option to be selected when a print dialog is displayed for this document.
4
+ # Valid values are <code>None</code>, which indicates that the print dialog should reflect no page scaling,
5
+ # and <code>AppDefault</code>, which indicates that applications should use the current print scaling.
6
+ # If this entry has an unrecognized value, applications should use the current print scaling.
7
+ # Default value: <code>AppDefault</code>.
8
+ #
9
+ # Note: If the print dialog is suppressed and its parameters are provided directly by the application, the value of this entry should still be used.
10
+ #
11
+
12
+ require File.expand_path(File.join(File.dirname(__FILE__),
13
+ %w[.. example_helper]))
14
+
15
+ Prawn::Document.generate("print_scaling.pdf",
16
+ :page_layout => :landscape,
17
+ :print_scaling => :none
18
+ ) do
19
+ text "When you print this document, the scale to fit in print preview should be disabled by default."
20
+ end
@@ -27,8 +27,9 @@ Prawn::Example.generate(filename) do
27
27
  #commit = `git show --pretty=%H`
28
28
  #short git commit hash
29
29
  commit = `git show --pretty=%h`
30
- formatted_text_box([ {:text => "Last Update: #{Time.now.strftime("%Y-%m-%d")}\n
31
- git commit: #{commit}",
30
+ formatted_text_box([ {:text => "Last Update: #{Time.now.strftime("%Y-%m-%d")}\n"+
31
+ "Prawn Version: #{Prawn::VERSION}\n"+
32
+ "git commit: #{commit}",
32
33
  :size => 12}
33
34
  ], :at => [390, cursor - 620])
34
35
 
@@ -30,6 +30,5 @@ Prawn::Example.generate("manual.pdf",
30
30
  load_package "document_and_page_options"
31
31
  load_package "outline"
32
32
  load_package "repeatable_content"
33
- load_package "templates"
34
33
  load_package "security"
35
34
  end
@@ -8,24 +8,29 @@ Gem::Specification.new do |spec|
8
8
  Dir.glob("data/fonts/{MustRead.html,*.afm}") +
9
9
  ["data/shift_jis_text.txt"] +
10
10
  ["Rakefile", "prawn.gemspec", "Gemfile",
11
- "COPYING", "LICENSE", "GPLv2", "GPLv3"]
11
+ "COPYING", "LICENSE", "GPLv2", "GPLv3",
12
+ ".yardopts"]
12
13
  spec.require_path = "lib"
13
14
  spec.required_ruby_version = '>= 1.9.3'
14
15
  spec.required_rubygems_version = ">= 1.3.6"
15
16
 
16
17
  spec.test_files = Dir[ "spec/*_spec.rb" ]
17
- spec.extra_rdoc_files = %w{README.md LICENSE COPYING GPLv2 GPLv3}
18
- spec.rdoc_options << '--title' << 'Prawn Documentation' <<
19
- '--main' << 'README.md' << '-q'
20
18
  spec.authors = ["Gregory Brown","Brad Ediger","Daniel Nelson","Jonathan Greenberg","James Healy"]
21
19
  spec.email = ["gregory.t.brown@gmail.com","brad@bradediger.com","dnelson@bluejade.com","greenberg@entryway.net","jimmy@deefa.com"]
22
20
  spec.rubyforge_project = "prawn"
21
+ spec.licenses = ['RUBY', 'GPL-2', 'GPL-3']
22
+
23
23
  spec.add_dependency('pdf-reader', '~>1.2')
24
24
  spec.add_dependency('ttfunk', '~>1.0.3')
25
25
  spec.add_dependency('ruby-rc4')
26
+
26
27
  spec.add_development_dependency('pdf-inspector', '~> 1.1.0')
27
28
  spec.add_development_dependency('coderay', '~> 1.0.7')
28
- spec.add_development_dependency('rdoc')
29
+ spec.add_development_dependency('yard')
30
+ spec.add_development_dependency('rspec')
31
+ spec.add_development_dependency('mocha')
32
+ spec.add_development_dependency('rake')
33
+
29
34
  spec.homepage = "http://prawn.majesticseacreature.com"
30
35
  spec.description = <<END_DESC
31
36
  Prawn is a fast, tiny, and nimble PDF generator for Ruby
@@ -378,6 +378,18 @@ describe "A canvas" do
378
378
  end
379
379
  @pdf.y.should == 450
380
380
  end
381
+
382
+ it "should restore the original ypos after execution", :issue => 523 do
383
+ doc = Prawn::Document.new(:skip_page_creation => true)
384
+ doc.start_new_page
385
+
386
+ original_ypos = doc.y
387
+
388
+ doc.canvas {}
389
+
390
+ doc.y.should == original_ypos
391
+ end
392
+
381
393
  end
382
394
 
383
395
  describe "Deep-copying" do
@@ -30,4 +30,36 @@ describe "A column box" do
30
30
  @pdf.bounds.right.should == 500
31
31
  end
32
32
  end
33
+
34
+ it "does not reset the top margin on a new page by default" do
35
+ create_pdf
36
+ page_top = @pdf.cursor
37
+ @pdf.move_down 50
38
+ init_column_top = @pdf.cursor
39
+ @pdf.column_box [0, @pdf.cursor], :width => 500,
40
+ :height => 200, :columns => 2 do
41
+
42
+ @pdf.bounds.move_past_bottom
43
+ @pdf.bounds.move_past_bottom
44
+
45
+ @pdf.bounds.absolute_top.should == init_column_top
46
+ @pdf.bounds.absolute_top.should_not == page_top
47
+ end
48
+ end
49
+
50
+ it "does reset the top margin when reflow_margins is set" do
51
+ create_pdf
52
+ page_top = @pdf.cursor
53
+ @pdf.move_down 50
54
+ init_column_top = @pdf.cursor
55
+ @pdf.column_box [0, @pdf.cursor], :width => 500, :reflow_margins => true,
56
+ :height => 200, :columns => 2 do
57
+
58
+ @pdf.bounds.move_past_bottom
59
+ @pdf.bounds.move_past_bottom
60
+
61
+ @pdf.bounds.absolute_top.should == page_top
62
+ @pdf.bounds.absolute_top.should_not == init_column_top
63
+ end
64
+ end
33
65
  end
@@ -478,6 +478,24 @@ describe "When using graphics states" do
478
478
  @pdf.restore_graphics_state
479
479
  }.should raise_error(PDF::Core::Errors::EmptyGraphicStateStack)
480
480
  end
481
+
482
+ it "should copy mutable attributes when passing a previous_state to the initializer" do
483
+ new_state = PDF::Core::GraphicState.new(@pdf.graphic_state)
484
+
485
+ [:color_space, :dash, :fill_color, :stroke_color].each do |attr|
486
+ new_state.send(attr).should == @pdf.graphic_state.send(attr)
487
+ new_state.send(attr).should_not equal(@pdf.graphic_state.send(attr))
488
+ end
489
+ end
490
+
491
+ it "should copy mutable attributes when duping" do
492
+ new_state = @pdf.graphic_state.dup
493
+
494
+ [:color_space, :dash, :fill_color, :stroke_color].each do |attr|
495
+ new_state.send(attr).should == @pdf.graphic_state.send(attr)
496
+ new_state.send(attr).should_not equal(@pdf.graphic_state.send(attr))
497
+ end
498
+ end
481
499
  end
482
500
 
483
501
  describe "When using transformation matrix" do
@@ -28,6 +28,18 @@ describe "ImageHandler" do
28
28
  handler.should == handler_b
29
29
  end
30
30
 
31
+ it "can unregister a handler" do
32
+ handler_b.expects(:can_render? => true)
33
+
34
+ image_handler.register(handler_a)
35
+ image_handler.register(handler_b)
36
+
37
+ image_handler.unregister(handler_a)
38
+
39
+ handler = image_handler.find('arbitrary blob')
40
+ handler.should == handler_b
41
+ end
42
+
31
43
  it "raises an error when no matching handler is found" do
32
44
  handler_a.expects(:can_render? => false)
33
45
  handler_b.expects(:can_render? => false)
@@ -82,6 +82,12 @@ describe "Prawn::ObjectStore" do
82
82
  end
83
83
  @store.map{|ref| ref.identifier}[-3..-1].should == [10, 11, 12]
84
84
  end
85
+
86
+ it "should accept option to disabling PDF scaling in PDF clients" do
87
+ @store = PDF::Core::ObjectStore.new(:print_scaling => :none)
88
+ @store.root.data[:ViewerPreferences].should == {:PrintScaling => :None}
89
+ end
90
+
85
91
  end
86
92
 
87
93
  describe "Prawn::ObjectStore#compact" do
@@ -46,6 +46,19 @@ describe "Prawn::Table" do
46
46
  end
47
47
 
48
48
  describe "You can explicitly set the column widths and use a colspan > 1" do
49
+ it "should work with two different given colspans", :issue => 628 do
50
+ data = [
51
+ [" ", " ", " "],
52
+ [{:content=>" ", :colspan=>3}],
53
+ [" ", {:content=>" ", :colspan=>2}]
54
+ ]
55
+ column_widths = [60, 240, 60]
56
+ pdf = Prawn::Document.new
57
+ #the next line raised an Prawn::Errors::CannotFit exception before issue 628 was fixed
58
+ table = Prawn::Table.new data, pdf, :column_widths => column_widths
59
+ table.column_widths.should == column_widths
60
+ end
61
+
49
62
  it "should work with a colspan > 1 with given column_widths (issue #407)" do
50
63
  #normal entries in line 1
51
64
  data = [
@@ -1,4 +1,5 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
1
+ require_relative "spec_helper"
2
+ require_relative "../lib/prawn/templates"
2
3
 
3
4
  describe "Document built from a template" do
4
5
  it "should have the same page count as the source document" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Brown
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-01-06 00:00:00.000000000 Z
15
+ date: 2014-01-16 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: pdf-reader
@@ -85,7 +85,49 @@ dependencies:
85
85
  - !ruby/object:Gem::Version
86
86
  version: 1.0.7
87
87
  - !ruby/object:Gem::Dependency
88
- name: rdoc
88
+ name: yard
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ - !ruby/object:Gem::Dependency
102
+ name: rspec
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ - !ruby/object:Gem::Dependency
116
+ name: mocha
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ - !ruby/object:Gem::Dependency
130
+ name: rake
89
131
  requirement: !ruby/object:Gem::Requirement
90
132
  requirements:
91
133
  - - '>='
@@ -108,12 +150,7 @@ email:
108
150
  - jimmy@deefa.com
109
151
  executables: []
110
152
  extensions: []
111
- extra_rdoc_files:
112
- - README.md
113
- - LICENSE
114
- - COPYING
115
- - GPLv2
116
- - GPLv3
153
+ extra_rdoc_files: []
117
154
  files:
118
155
  - lib/pdf/core/annotations.rb
119
156
  - lib/pdf/core/byte_string.rb
@@ -178,6 +215,7 @@ files:
178
215
  - lib/prawn/table/cells.rb
179
216
  - lib/prawn/table/column_width_calculator.rb
180
217
  - lib/prawn/table.rb
218
+ - lib/prawn/templates.rb
181
219
  - lib/prawn/text/box.rb
182
220
  - lib/prawn/text/formatted/arranger.rb
183
221
  - lib/prawn/text/formatted/box.rb
@@ -230,7 +268,7 @@ files:
230
268
  - spec/stroke_styles_spec.rb
231
269
  - spec/table/span_dummy_spec.rb
232
270
  - spec/table_spec.rb
233
- - spec/template_spec.rb
271
+ - spec/template_spec_obsolete.rb
234
272
  - spec/text_at_spec.rb
235
273
  - spec/text_box_spec.rb
236
274
  - spec/text_rendering_mode_spec.rb
@@ -258,6 +296,7 @@ files:
258
296
  - manual/document_and_page_options/metadata.rb
259
297
  - manual/document_and_page_options/page_margins.rb
260
298
  - manual/document_and_page_options/page_size.rb
299
+ - manual/document_and_page_options/print_scaling.rb
261
300
  - manual/example_file.rb
262
301
  - manual/example_helper.rb
263
302
  - manual/example_package.rb
@@ -328,9 +367,6 @@ files:
328
367
  - manual/table/style.rb
329
368
  - manual/table/table.rb
330
369
  - manual/table/width.rb
331
- - manual/templates/full_template.rb
332
- - manual/templates/page_template.rb
333
- - manual/templates/templates.rb
334
370
  - manual/text/alignment.rb
335
371
  - manual/text/color.rb
336
372
  - manual/text/column_box.rb
@@ -422,9 +458,12 @@ files:
422
458
  - LICENSE
423
459
  - GPLv2
424
460
  - GPLv3
425
- - README.md
461
+ - .yardopts
426
462
  homepage: http://prawn.majesticseacreature.com
427
- licenses: []
463
+ licenses:
464
+ - RUBY
465
+ - GPL-2
466
+ - GPL-3
428
467
  metadata: {}
429
468
  post_install_message: |2+
430
469
 
@@ -440,12 +479,7 @@ post_install_message: |2+
440
479
 
441
480
  ********************************************
442
481
 
443
- rdoc_options:
444
- - --title
445
- - Prawn Documentation
446
- - --main
447
- - README.md
448
- - -q
482
+ rdoc_options: []
449
483
  require_paths:
450
484
  - lib
451
485
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -500,7 +534,6 @@ test_files:
500
534
  - spec/stream_spec.rb
501
535
  - spec/stroke_styles_spec.rb
502
536
  - spec/table_spec.rb
503
- - spec/template_spec.rb
504
537
  - spec/text_at_spec.rb
505
538
  - spec/text_box_spec.rb
506
539
  - spec/text_rendering_mode_spec.rb
data/README.md DELETED
@@ -1,110 +0,0 @@
1
- # Prawn: Fast, Nimble PDF Generation For Ruby
2
-
3
- [![Build Status](https://secure.travis-ci.org/prawnpdf/prawn.png)](http://travis-ci.org/prawnpdf/prawn)
4
- [![Gem Version](https://badge.fury.io/rb/prawn.png)](http://badge.fury.io/rb/prawn)
5
-
6
- Prawn is a pure Ruby PDF generation library that provides a lot of great functionality while trying to remain simple and reasonably performant. Here are some of the important features we provide:
7
-
8
- * Vector drawing support, including lines, polygons, curves, ellipses, etc.
9
- * Extensive text rendering support, including flowing text and limited inline formatting options.
10
- * Support for both PDF builtin fonts as well as embedded TrueType fonts
11
- * A variety of low level tools for basic layout needs, including a simple grid system
12
- * PNG and JPG image embedding, with flexible scaling options
13
- * Reporting tools for rendering complex data tables, with pagination support
14
- * Security features including encryption and password protection
15
- * Tools for rendering repeatable content (i.e headers, footers, and page numbers)
16
- * Comprehensive internationalization features, including full support for UTF-8 based fonts, right-to-left text rendering, fallback font support, and extension points for customizable text wrapping.
17
- * Support for PDF outlines for document navigation
18
- * Low level PDF features, allowing users to create custom extensions by dropping down all the way to the PDF object tree layer. (Mostly useful to those with knowledge of the PDF specification)
19
- * Lots of other stuff!
20
-
21
- ## Should You Use Prawn?
22
-
23
- If you are looking for a highly flexible PDF document generation system, Prawn might be the tool for you. It is not a reporting tool or a publishing toolchain, though it could be fairly easily used to build those things.
24
-
25
- One thing Prawn is not, and will never be, is an HTML to PDF generator. For those needs, consider looking into FlyingSaucer via JRuby, or one of the webkit based tools, like Wicked or PDFKit. We do have basic support for inline styling but it is limited to a very small subset of functionality and is not suitable for rendering rich HTML documents.
26
-
27
- ## Supported Ruby Versions and Implementations
28
-
29
- Because Prawn is pure Ruby and virtually all of its dependencies are maintained by our core team, it should run pretty much anywhere, including Rubinius, JRuby, MacRuby, etc. We officially support MRI {1.9.3 and 2.0.0} and jruby 1.7.x in 1.9 mode, however we will accept patches to fix problems on other Ruby platforms if they aren't too invasive.
30
-
31
- ## Installing Prawn
32
-
33
- Prawn is distributed via RubyGems, and can be installed the usual way that you install gems: by simply typing `gem install prawn` on the command line.
34
-
35
- You can also install from git if you'd like, the _master_ branch contains the latest developments, and _stable_ represents the latest bug fixes to the currently released version of Prawn. If you go this route, using Bundler is encouraged.
36
-
37
- ## Release Policies
38
-
39
- We may introduce backwards incompatible changes each time our minor version number is bumped, but that any tiny version number bump should be bug fixes and internal changes only. Be sure to read the release notes each time we cut a new release and lock your gems accordingly. You can find the project CHANGELOG at: https://github.com/prawnpdf/prawn/wiki/CHANGELOG
40
-
41
- ## Hello World!
42
-
43
- If the following code runs and produces a working PDF file, you've successfully installed Prawn.
44
-
45
- require "prawn"
46
-
47
- Prawn::Document.generate("hello.pdf") do
48
- text "Hello World!"
49
- end
50
-
51
- Of course, you'll probably want to do more interesting things than that...
52
-
53
- ## Manual
54
-
55
- Mendicant University student Felipe Doria provided us with a beautiful system for generating a user manual from our examples. This can be generated from the prawn source or you can download a pre-generated snapshot of it at http://prawn.majesticseacreature.com/manual.pdf
56
-
57
- Note that while we will try to keep the downloadable manual up to date, that it's provided as a convenience only and you should generate the manual yourself if you want to be sure the code in it actually runs and works as expected. To build the manual, here's what you need to do:
58
-
59
- 1. clone the repository
60
- 2. switch to the stable branch (optional, stay on master for development version)
61
- 3. install bundler if necessay
62
- 4. run `bundle install`
63
- 5. run `bundle exec rake manual`, which will generate _manual.pdf_ in the project root
64
-
65
- ## Support
66
-
67
- The easiest way to get help with Prawn is to post a message to our mailing list:
68
-
69
- <http://groups.google.com/group/prawn-ruby>
70
-
71
- Feel free to post any Prawn related question there, our community is very responsive and will be happy to help you figure out how to use Prawn, or help you determine whether it's the right tool for the task you are working on.
72
-
73
- Please make your posts to the list as specific as possible, including code samples and output where relevant. Do not post any information that should not be shared publicly, and be sure to reduce your example code as much as possible so that those who are responding to your question can more easily see what the issue might be.
74
-
75
- ## Contributing
76
-
77
- If you've found a bug, want to submit a patch, or have a feature request, please enter a ticket into our github tracker:
78
-
79
- <http://github.com/prawnpdf/prawn/issues>
80
-
81
- We strongly encourage bug reports to come with failing tests or at least a reduced example that demonstrates the problem. Similarly, patches should include tests, API documentation, and an update to the manual where relevant. Feel free to send a pull request early though, if you just want some feedback or a code review before preparing your code to be merged.
82
-
83
- If you are unsure about whether or not you've found a bug, or want to check to see whether we'd be interested in the feature you want to add before you start working on it, feel free to post to our mailing list.
84
-
85
- You can run our test suite in a few different ways:
86
-
87
- 1. Running `rake` will run the entire test suite excluding any unresolved issues
88
- 2. Running `rspec` will run the entire test suite including unresolved issues
89
- 3. Running `rspec -t unresolved` will run *only* unresolved issues
90
- 4. Running `rspec -t issue:NUMBER` will run the tests for a specific issue
91
-
92
- These filters make it possible for us to add failing test cases for bugs that
93
- are currently being researched or worked on, without breaking the typical
94
- full suite run.
95
-
96
- ## Authorship
97
-
98
- Prawn was originally developed by Gregory Brown, under the auspices of the Ruby Mendicant Project, a grassroots initiative in which the Ruby community collectively provided funding so that Gregory could take several months off of work to focus on this project.
99
-
100
- Over the last several years, we've received code contributions from over 50 people, which is amazing considering the low-level nature of this project. In 2010, Gregory officially handed the project off to the Prawn core team. Currently active maintainers include Brad Ediger, Daniel Nelson, James Healy, and Jonathan Greenberg.
101
-
102
- While he was only with us for a short time before moving on to other things, we'd also like to thank Prawn core team emeritus Jamis Buck for his contributions. He was responsible for introducing font subsetting as well as the first implementation of our inline formatting support.
103
-
104
- You can find the full list of folks who have at least one patch accepted to Prawn on github at https://github.com/prawnpdf/prawn/contributors
105
-
106
- ## License
107
-
108
- Prawn is released under a slightly modified form of the License of Ruby, allowing you to choose between Matz's terms, the GPLv2, or GPLv3. For details, please see the LICENSE, GPLv2, and GPLv3 files.
109
-
110
- If you wish to contribute to Prawn, you will retain your own copyright but must agree to license your code under the same terms as the project itself.
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- #<b>NOTE: Templates are currently unmaintained and may be removed by Prawn 1.0!</b>
4
- #
5
- # You may load another PDF while creating a new one. Just pass the loaded PDF
6
- # filename to the <code>:template</code> option when creating/generating the new
7
- # PDF.
8
- #
9
- # The provided PDF will be loaded and its first page will be set as the
10
- # current page. If you'd like to resume the document you may take advantage of
11
- # two helpers: <code>page_count</code> and <code>go_to_page</code>.
12
- #
13
- require File.expand_path(File.join(File.dirname(__FILE__),
14
- %w[.. example_helper]))
15
-
16
- filename = "#{Prawn::DATADIR}/pdfs/multipage_template.pdf"
17
-
18
- Prawn::Example.generate("full_template.pdf", :template => filename) do
19
- go_to_page(page_count)
20
-
21
- start_new_page
22
-
23
- text "Previous pages and content imported.", :align => :center
24
- text "This page and content is brand new.", :align => :center
25
- end
@@ -1,48 +0,0 @@
1
- # encoding: utf-8
2
- # <b>NOTE: Templates are currently unmaintained and may be removed by Prawn 1.0!</b>
3
- #
4
- # If you only need to load some pages from another PDF, you can accomplish it
5
- # with the <code>start_new_page</code> method. You may pass it a
6
- # <code>:template</code> option with the path for an existing pdf and a
7
- # <code>:template_page</code> option to specify which page to load.
8
- # You can also load a <code>:template</code> using a URI:
9
- #
10
- # <code>require 'open-uri'</code>
11
- #
12
- # <code>start_new_page(:template => open('url_for_your.pdf'))</code>
13
- #
14
- # The following example loads some pages from an existing PDF. If we don't
15
- # specify the <code>:template_page</code> option, the first page of the template
16
- # PDF will be loaded. That's what happens on the first load below. Then we load
17
- # a page by specifying the <code>:template_page</code> option and then we do it
18
- # again this time adding some content to the loaded page.
19
- #
20
- require File.expand_path(File.join(File.dirname(__FILE__),
21
- %w[.. example_helper]))
22
-
23
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
24
- Prawn::Example.generate(filename) do
25
- text "Please scan the next 3 pages to see the page templates in action."
26
- move_down 10
27
- text "You also might want to look at the pdf used as a template: "
28
- url = "https://github.com/prawnpdf/prawn/raw/master/data/pdfs/form.pdf"
29
- move_down 10
30
-
31
- formatted_text [{:text => url, :link => url}]
32
-
33
- filename = "#{Prawn::DATADIR}/pdfs/form.pdf"
34
- start_new_page(:template => filename)
35
-
36
- start_new_page(:template => filename, :template_page => 2)
37
-
38
- start_new_page(:template => filename, :template_page => 2)
39
-
40
- fill_color "FF8888"
41
-
42
- text_box "John Doe", :at => [75, cursor-75]
43
- text_box "john@doe.com", :at => [75, cursor-105]
44
- text_box "John Doe inc", :at => [75, cursor-135]
45
- text_box "You didn't think I'd tell, did you?", :at => [75, cursor-165]
46
-
47
- fill_color "000000"
48
- end
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Examples for loading existing pdfs.
4
- #
5
- require File.expand_path(File.join(File.dirname(__FILE__),
6
- %w[.. example_helper]))
7
-
8
- Prawn::Example.generate("templates.pdf", :page_size => "FOLIO") do
9
-
10
- package "templates" do |p|
11
-
12
- p.example "full_template", :eval_source => false, :full_source => true
13
- p.example "page_template"
14
-
15
- p.intro do
16
- prose("<b>NOTE: Templates are currently unmaintained and may be removed by Prawn 1.0!</b>")
17
- prose("Templates let you embed other PDF documents inside the current one.
18
-
19
- The examples show:")
20
-
21
- list( "How to load the whole content from another PDF",
22
- "How to load single pages from another PDF"
23
- )
24
- end
25
-
26
- end
27
- end