prawn 0.13.1 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/prawn.rb +1 -1
- data/lib/prawn/document.rb +6 -6
- data/lib/prawn/document/column_box.rb +2 -1
- data/lib/prawn/font.rb +7 -8
- data/lib/prawn/font/afm.rb +1 -1
- data/lib/prawn/font/dfont.rb +1 -1
- data/lib/prawn/graphics.rb +8 -7
- data/lib/prawn/layout.rb +2 -2
- data/lib/prawn/measurement_extensions.rb +1 -1
- data/lib/prawn/table.rb +9 -22
- data/lib/prawn/table/column_width_calculator.rb +55 -0
- data/spec/table_spec.rb +42 -2
- data/spec/text_spec.rb +26 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a27927232c4c77d3933d18984c31230475c1b97
|
4
|
+
data.tar.gz: 711b6736c9a1a5bfc2131d0d0cec5e5ef3f2faad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfc74a6d17392cf8d2e97257df8e80e2bb2fd36e55293fd1507efc900a5d8b40161dae98e3e99d6ff5b99052eb64f0d3bcc6654def35fd9384f83ece176237fc
|
7
|
+
data.tar.gz: 9355d24d34c93280b67f161c9aababa5360f8cf685fa081adafaa76fa1dddb4eecd07dacecb413ec671f6081d3aa5e09b728cdee627482f2ec4951903bb0089e
|
data/lib/prawn.rb
CHANGED
data/lib/prawn/document.rb
CHANGED
@@ -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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
|
data/lib/prawn/font.rb
CHANGED
@@ -6,10 +6,10 @@
|
|
6
6
|
#
|
7
7
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
8
|
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
#
|
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!(
|
data/lib/prawn/font/afm.rb
CHANGED
data/lib/prawn/font/dfont.rb
CHANGED
data/lib/prawn/graphics.rb
CHANGED
@@ -6,13 +6,14 @@
|
|
6
6
|
#
|
7
7
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
|
data/lib/prawn/layout.rb
CHANGED
data/lib/prawn/table.rb
CHANGED
@@ -6,13 +6,14 @@
|
|
6
6
|
#
|
7
7
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
data/spec/table_spec.rb
CHANGED
@@ -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=>
|
95
|
-
fourth = {:content=>"Bar",:width=>
|
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
|
data/spec/text_spec.rb
CHANGED
@@ -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.
|
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:
|
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:
|