prawn 0.13.1 → 0.13.2

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: 97df184b88392e64c3213125e2e3d49ed8921dfd
4
- data.tar.gz: ae198cc6d4e658db982a4fcab6119c6c082937d1
3
+ metadata.gz: 0a27927232c4c77d3933d18984c31230475c1b97
4
+ data.tar.gz: 711b6736c9a1a5bfc2131d0d0cec5e5ef3f2faad
5
5
  SHA512:
6
- metadata.gz: fcf93119b67b6497601c38ebdfce11c7ff22739941a5c2adafe7f0f2636bfeefdb86f7fd6a35285e387bc77dc76896c87b1120e44ce3e357ce99754ac0380d52
7
- data.tar.gz: afbfa0adfca9f371ada957a127e7737f6248a3be75f99fc401d1081199d22e9fdeac62e13ea752dd24418c76e29d6aaa3aad4e4bf503433dc585169f03b52e47
6
+ metadata.gz: cfc74a6d17392cf8d2e97257df8e80e2bb2fd36e55293fd1507efc900a5d8b40161dae98e3e99d6ff5b99052eb64f0d3bcc6654def35fd9384f83ece176237fc
7
+ data.tar.gz: 9355d24d34c93280b67f161c9aababa5360f8cf685fa081adafaa76fa1dddb4eecd07dacecb413ec671f6081d3aa5e09b728cdee627482f2ec4951903bb0089e
@@ -20,7 +20,7 @@ end
20
20
  require "set"
21
21
 
22
22
  module Prawn
23
- VERSION = "0.13.1"
23
+ VERSION = "0.13.2"
24
24
 
25
25
  extend self
26
26
 
@@ -7,12 +7,12 @@
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
9
  require "stringio"
10
- require "prawn/document/bounding_box"
11
- require "prawn/document/column_box"
12
- require "prawn/document/internals"
13
- require "prawn/document/span"
14
- require "prawn/document/snapshot"
15
- require "prawn/document/graphics_state"
10
+ require_relative "document/bounding_box"
11
+ require_relative "document/column_box"
12
+ require_relative "document/internals"
13
+ require_relative "document/span"
14
+ require_relative "document/snapshot"
15
+ require_relative "document/graphics_state"
16
16
 
17
17
  module Prawn
18
18
 
@@ -4,7 +4,8 @@
4
4
  #
5
5
  # Author Paul Ostazeski.
6
6
 
7
- require "prawn/document/bounding_box"
7
+ require_relative "bounding_box"
8
+
8
9
  module Prawn
9
10
  class Document
10
11
 
@@ -6,10 +6,10 @@
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
  #
9
- require "prawn/font/afm"
10
- require "prawn/font/ttf"
11
- require "prawn/font/dfont"
12
- require "prawn/font_metric_cache"
9
+ require_relative "font/afm"
10
+ require_relative "font/ttf"
11
+ require_relative "font/dfont"
12
+ require_relative "font_metric_cache"
13
13
 
14
14
  module Prawn
15
15
 
@@ -174,10 +174,9 @@ module Prawn
174
174
  # wish to support.
175
175
  #
176
176
  # By default the styles :bold, :italic, :bold_italic, and :normal are
177
- # defined for fonts "Courier", "Times-Roman" and "Helvetica".
178
- #
179
- # You probably want to provide those four styles, but are free to define
180
- # custom ones, like :thin, and use them in font calls.
177
+ # defined for fonts "Courier", "Times-Roman" and "Helvetica". When
178
+ # defining your own font families, you can map any or all of these
179
+ # styles to whatever font files you'd like.
181
180
  #
182
181
  def font_families
183
182
  @font_families ||= {}.merge!(
@@ -6,7 +6,7 @@
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
- require 'prawn/encoding'
9
+ require_relative '../../prawn/encoding'
10
10
 
11
11
  module Prawn
12
12
  class Font
@@ -6,7 +6,7 @@
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
  #
9
- require 'prawn/font/ttf'
9
+ require_relative 'ttf'
10
10
 
11
11
  module Prawn
12
12
  class Font
@@ -6,13 +6,14 @@
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
- require "prawn/graphics/color"
10
- require "prawn/graphics/dash"
11
- require "prawn/graphics/cap_style"
12
- require "prawn/graphics/join_style"
13
- require "prawn/graphics/transparency"
14
- require "prawn/graphics/transformation"
15
- require "prawn/graphics/patterns"
9
+
10
+ require_relative "graphics/color"
11
+ require_relative "graphics/dash"
12
+ require_relative "graphics/cap_style"
13
+ require_relative "graphics/join_style"
14
+ require_relative "graphics/transparency"
15
+ require_relative "graphics/transformation"
16
+ require_relative "graphics/patterns"
16
17
 
17
18
  module Prawn
18
19
 
@@ -1,5 +1,5 @@
1
- require "prawn/table"
2
- require 'prawn/layout/grid'
1
+ require_relative "table"
2
+ require_relative "layout/grid"
3
3
 
4
4
  module Prawn
5
5
 
@@ -5,7 +5,7 @@
5
5
  #
6
6
  # This is free software. Please see the LICENSE and COPYING files for details.
7
7
 
8
- require 'prawn/measurements'
8
+ require_relative 'measurements'
9
9
 
10
10
  class Numeric
11
11
  include Prawn::Measurements
@@ -6,13 +6,14 @@
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
- require 'prawn/table/cells'
10
- require 'prawn/table/cell'
11
- require 'prawn/table/cell/in_table'
12
- require 'prawn/table/cell/text'
13
- require 'prawn/table/cell/subtable'
14
- require 'prawn/table/cell/image'
15
- require 'prawn/table/cell/span_dummy'
9
+ require_relative 'table/column_width_calculator'
10
+ require_relative 'table/cells'
11
+ require_relative 'table/cell'
12
+ require_relative 'table/cell/in_table'
13
+ require_relative 'table/cell/text'
14
+ require_relative 'table/cell/subtable'
15
+ require_relative 'table/cell/image'
16
+ require_relative 'table/cell/span_dummy'
16
17
 
17
18
  module Prawn
18
19
 
@@ -549,21 +550,7 @@ module Prawn
549
550
  # Returns an array of each column's natural (unconstrained) width.
550
551
  #
551
552
  def natural_column_widths
552
- @natural_column_widths ||=
553
- begin
554
- widths_by_column = Hash.new(0)
555
- cells.each do |cell|
556
- next if cell.is_a?(Cell::SpanDummy)
557
-
558
- # Split the width of colspanned cells evenly by columns
559
- width_per_column = cell.width.to_f / cell.colspan
560
- cell.colspan.times do |i|
561
- widths_by_column[cell.column + i] =
562
- [widths_by_column[cell.column + i], width_per_column].max
563
- end
564
- end
565
- widths_by_column.sort_by { |col, _| col }.map { |_, w| w }
566
- end
553
+ @natural_column_widths ||= ColumnWidthCalculator.new(cells).natural_widths
567
554
  end
568
555
 
569
556
  # Returns the "natural" (unconstrained) width of the table. This may be
@@ -0,0 +1,55 @@
1
+ module Prawn
2
+ class Table
3
+ class ColumnWidthCalculator
4
+ def initialize(cells)
5
+ @cells = cells
6
+
7
+ @widths_by_column = Hash.new(0)
8
+ @rows_with_a_span_dummy = Hash.new(false)
9
+ end
10
+
11
+ def natural_widths
12
+ @cells.each do |cell|
13
+ @rows_with_a_span_dummy[cell.row] = true if cell.is_a?(Cell::SpanDummy)
14
+ end
15
+
16
+ #calculate natural column width for all rows that do not include a span dummy
17
+ @cells.each do |cell|
18
+ unless @rows_with_a_span_dummy[cell.row]
19
+ @widths_by_column[cell.column] =
20
+ [@widths_by_column[cell.column], cell.width.to_f].max
21
+ end
22
+ end
23
+
24
+ #integrate natural column widths for all rows that do include a span dummy
25
+ @cells.each do |cell|
26
+ next unless @rows_with_a_span_dummy[cell.row]
27
+ #the width of a SpanDummy cell will be calculated by the "mother" cell
28
+ next if cell.is_a?(Cell::SpanDummy)
29
+
30
+ if cell.colspan == 1
31
+ @widths_by_column[cell.column] =
32
+ [@widths_by_column[cell.column], cell.width.to_f].max
33
+ else
34
+ #calculate the current with of all cells that will be spanned by the current cell
35
+ current_width_of_spanned_cells =
36
+ @widths_by_column.to_a[cell.column..(cell.column + cell.colspan - 1)]
37
+ .collect{|key, value| value}.inject(0, :+)
38
+
39
+ #update the Hash only if the new with is at least equal to the old one
40
+ if cell.width.to_f > current_width_of_spanned_cells
41
+ # Split the width of colspanned cells evenly by columns
42
+ width_per_column = cell.width.to_f / cell.colspan
43
+ # Update the Hash
44
+ cell.colspan.times do |i|
45
+ @widths_by_column[cell.column + i] = width_per_column
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ @widths_by_column.sort_by { |col, _| col }.map { |_, w| w }
52
+ end
53
+ end
54
+ end
55
+ end
@@ -80,6 +80,25 @@ describe "Prawn::Table" do
80
80
 
81
81
  end
82
82
 
83
+ it "should not increase column width when rendering a subtable",
84
+ :unresolved, :issue => 612 do
85
+
86
+ pdf = Prawn::Document.new
87
+
88
+ first = {:content=>"Foooo fo foooooo",:width=>50,:align=>:center}
89
+ second = {:content=>"Foooo",:colspan=>2,:width=>70,:align=>:center}
90
+ third = {:content=>"fooooooooooo, fooooooooooooo, fooo, foooooo fooooo",:width=>50,:align=>:center}
91
+ fourth = {:content=>"Bar",:width=>20,:align=>:center}
92
+
93
+ table_content = [[
94
+ first,
95
+ [[second],[third,fourth]]
96
+ ]]
97
+
98
+ table = Prawn::Table.new table_content, pdf
99
+ table.column_widths.should == [50.0, 70.0]
100
+ end
101
+
83
102
  it "illustrate issue #533" do
84
103
  data = [['', '', '', '', '',''],
85
104
  ['',{:content => '', :colspan => 5}]]
@@ -91,15 +110,36 @@ describe "Prawn::Table" do
91
110
  pdf = Prawn::Document.new
92
111
  first = {:content=>"Foooo fo foooooo",:width=>50,:align=>:center}
93
112
  second = {:content=>"Foooo",:colspan=>2,:width=>70,:align=>:center}
94
- third = {:content=>"fooooooooooo, fooooooooooooo, fooo, foooooo fooooo",:width=>55,:align=>:center}
95
- fourth = {:content=>"Bar",:width=>15,:align=>:center}
113
+ third = {:content=>"fooooooooooo, fooooooooooooo, fooo, foooooo fooooo",:width=>50,:align=>:center}
114
+ fourth = {:content=>"Bar",:width=>20,:align=>:center}
96
115
  table_content = [[
97
116
  first,
98
117
  [[second],[third,fourth]]
99
118
  ]]
100
119
  pdf.move_down(20)
120
+ table = Prawn::Table.new table_content, pdf
101
121
  pdf.table(table_content)
102
122
  end
123
+
124
+ #https://github.com/prawnpdf/prawn/issues/407#issuecomment-28556698
125
+ it "correctly computes column widths with empty cells + colspan" do
126
+ data = [['', ''],
127
+ [{:content => '', :colspan => 2}]
128
+ ]
129
+ pdf = Prawn::Document.new
130
+
131
+ table = Prawn::Table.new data, pdf, :column_widths => [50, 200]
132
+ table.column_widths.should == [50.0, 200.0]
133
+ end
134
+
135
+ it "illustrates a variant of problem in issue #407 - comment 28556698" do
136
+ pdf = Prawn::Document.new
137
+ table_data = [["a", "b", "c"], [{:content=>"d", :colspan=>3}]]
138
+ column_widths = [50, 60, 400]
139
+
140
+ # Before we fixed #407, this line incorrectly raise a CannotFit error
141
+ pdf.table(table_data, :column_widths => column_widths)
142
+ end
103
143
  end
104
144
 
105
145
  describe "#initialize" do
@@ -408,4 +408,30 @@ describe "#text" do
408
408
  @pdf.text "VAT", :kerning => false
409
409
  end
410
410
  end
411
+
412
+ describe "#shrink_to_fit with special utf-8 text" do
413
+ it "Should not throw an exception",
414
+ :unresolved, :issue => 603 do
415
+ pages = 0
416
+ doc = Prawn::Document.new(page_size: 'A4', margin: [2, 2, 2, 2]) do |pdf|
417
+ add_unicode_fonts(pdf)
418
+ pdf.bounding_box([1, 1], :width => 90, :height => 50) do
419
+ broken_text = " Sample Text\nSAMPLE SAMPLE SAMPLEoddělení ZMĚN\nSAMPLE"
420
+ pdf.text broken_text, :overflow => :shrink_to_fit
421
+ end
422
+ end
423
+ end
424
+ end
425
+
426
+
427
+ def add_unicode_fonts(pdf)
428
+ dejavu = "#{::Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
429
+ pdf.font_families.update("dejavu" => {
430
+ :normal => dejavu,
431
+ :italic => dejavu,
432
+ :bold => dejavu,
433
+ :bold_italic => dejavu
434
+ })
435
+ pdf.fallback_fonts = ["dejavu"]
436
+ end
411
437
  end
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.1
4
+ version: 0.13.2
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: 2013-12-23 00:00:00.000000000 Z
15
+ date: 2014-01-06 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: pdf-reader
@@ -176,6 +176,7 @@ files:
176
176
  - lib/prawn/table/cell/text.rb
177
177
  - lib/prawn/table/cell.rb
178
178
  - lib/prawn/table/cells.rb
179
+ - lib/prawn/table/column_width_calculator.rb
179
180
  - lib/prawn/table.rb
180
181
  - lib/prawn/text/box.rb
181
182
  - lib/prawn/text/formatted/arranger.rb
@@ -507,3 +508,4 @@ test_files:
507
508
  - spec/text_spec.rb
508
509
  - spec/text_with_inline_formatting_spec.rb
509
510
  - spec/transparency_spec.rb
511
+ has_rdoc: