prawn 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/Gemfile +1 -1
- data/Rakefile +2 -2
- data/data/images/pal_bk.png +0 -0
- data/lib/prawn.rb +0 -1
- data/lib/prawn/document.rb +2 -2
- data/lib/prawn/document/internals.rb +2 -1
- data/lib/prawn/encoding.rb +0 -33
- data/lib/prawn/font/afm.rb +20 -11
- data/lib/prawn/font/ttf.rb +4 -0
- data/lib/prawn/font_metric_cache.rb +1 -2
- data/lib/prawn/graphics.rb +11 -8
- data/lib/prawn/graphics/dash.rb +5 -0
- data/lib/prawn/images.rb +2 -3
- data/lib/prawn/images/png.rb +3 -12
- data/lib/prawn/text.rb +15 -7
- data/lib/prawn/text/box.rb +1 -9
- data/lib/prawn/text/formatted/box.rb +9 -11
- data/lib/prawn/text/formatted/line_wrap.rb +5 -0
- data/lib/prawn/version.rb +1 -1
- data/manual/basic_concepts/measurement.rb +1 -1
- data/manual/bounding_box/bounds.rb +1 -1
- data/manual/cover.rb +1 -4
- data/manual/example_helper.rb +1 -0
- data/manual/how_to_read_this_manual.rb +2 -2
- data/manual/repeatable_content/alternate_page_numbering.rb +32 -0
- data/manual/repeatable_content/repeatable_content.rb +1 -0
- data/manual/security/security.rb +1 -1
- data/manual/text/paragraph_indentation.rb +8 -0
- data/manual/text/right_to_left_text.rb +4 -0
- data/manual/text/text.rb +1 -1
- data/manual/text/text_box_overflow.rb +1 -1
- data/manual/text/utf8.rb +4 -4
- data/manual/text/win_ansi_charset.rb +2 -1
- data/prawn.gemspec +4 -19
- data/spec/document_spec.rb +24 -1
- data/spec/font_spec.rb +25 -0
- data/spec/formatted_text_box_spec.rb +77 -33
- data/spec/graphics_spec.rb +26 -12
- data/spec/line_wrap_spec.rb +26 -10
- data/spec/png_spec.rb +9 -1
- data/spec/soft_mask_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -2
- data/spec/text_at_spec.rb +0 -1
- data/spec/text_box_spec.rb +2 -21
- data/spec/text_spacing_spec.rb +2 -2
- data/spec/text_spec.rb +102 -1
- metadata +12 -24
- data/data/encodings/win_ansi.txt +0 -29
@@ -102,6 +102,10 @@ module Prawn
|
|
102
102
|
|
103
103
|
if @accumulated_width + segment_width <= @width
|
104
104
|
@accumulated_width += segment_width
|
105
|
+
if segment[-1] == soft_hyphen
|
106
|
+
sh_width = @document.width_of("#{soft_hyphen}", :kerning => @kerning)
|
107
|
+
@accumulated_width -= sh_width
|
108
|
+
end
|
105
109
|
@fragment_output += segment
|
106
110
|
else
|
107
111
|
end_of_the_line_reached(segment)
|
@@ -124,6 +128,7 @@ module Prawn
|
|
124
128
|
"[#{whitespace}]+|" +
|
125
129
|
"#{hyphen}+[^#{break_chars}]*|" +
|
126
130
|
"#{soft_hyphen}"
|
131
|
+
|
127
132
|
Regexp.new(pattern)
|
128
133
|
end
|
129
134
|
|
data/lib/prawn/version.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# The base unit in Prawn is the PDF Point. One PDF Point is equal to 1/72 of
|
4
4
|
# an inch.
|
5
5
|
#
|
6
|
-
# There is no need to waste time converting this
|
6
|
+
# There is no need to waste time converting this measure. Prawn provides
|
7
7
|
# helpers for converting from other measurements
|
8
8
|
# to PDF Points.
|
9
9
|
#
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
3
|
# The <code>bounds</code> method returns the current bounding box. This is
|
4
|
-
# useful because the <code>Prawn::
|
4
|
+
# useful because the <code>Prawn::BoundingBox</code> exposes some nice boundary
|
5
5
|
# helpers.
|
6
6
|
#
|
7
7
|
# <code>top</code>, <code>bottom</code>, <code>left</code> and
|
data/manual/cover.rb
CHANGED
@@ -24,11 +24,8 @@ Prawn::ManualBuilder::Example.generate(filename) do
|
|
24
24
|
], :at => [170, cursor - 160])
|
25
25
|
|
26
26
|
if Dir.exist?("#{Prawn::BASEDIR}/.git")
|
27
|
-
#long git commit hash
|
28
|
-
#commit = `git show --pretty=%H`
|
29
|
-
#short git commit hash
|
30
27
|
commit = `git show --pretty=%h`
|
31
|
-
git_commit = "git commit: #{commit}"
|
28
|
+
git_commit = "git commit: #{commit.lines.first}"
|
32
29
|
else
|
33
30
|
git_commit = ""
|
34
31
|
end
|
data/manual/example_helper.rb
CHANGED
@@ -32,9 +32,9 @@ Prawn::ManualBuilder::Example.generate(filename) do
|
|
32
32
|
|
33
33
|
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.
|
34
34
|
|
35
|
-
Note that the <code>stroke_axis</code> method
|
35
|
+
Note that the <code>stroke_axis</code> method used throughout the manual is part of standard Prawn. It is defined in this file:
|
36
36
|
|
37
|
-
https://github.com/prawnpdf/prawn/blob/master/
|
37
|
+
https://github.com/prawnpdf/prawn/blob/master/lib/prawn/graphics.rb
|
38
38
|
END_TEXT
|
39
39
|
|
40
40
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Below is the code to generate page numbers that alternate being rendered
|
4
|
+
# on the right and left side of the page. The first page will have a "1" in
|
5
|
+
# the bottom right corner. The second page will have a "2" in the bottom
|
6
|
+
# left corner of the page. The third a "3" in the bottom right, etc.
|
7
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
8
|
+
%w[.. example_helper]))
|
9
|
+
|
10
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
11
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
12
|
+
text "This is the first page!"
|
13
|
+
|
14
|
+
10.times do
|
15
|
+
start_new_page
|
16
|
+
text "Here comes yet another page."
|
17
|
+
end
|
18
|
+
|
19
|
+
string = "<page>"
|
20
|
+
odd_options = { :at => [bounds.right - 150, 0],
|
21
|
+
:width => 150,
|
22
|
+
:align => :right,
|
23
|
+
:page_filter => :odd,
|
24
|
+
:start_count_at => 1 }
|
25
|
+
even_options = { :at => [0, bounds.left],
|
26
|
+
:width => 150,
|
27
|
+
:align => :left,
|
28
|
+
:page_filter => :even,
|
29
|
+
:start_count_at => 2 }
|
30
|
+
number_pages string, odd_options
|
31
|
+
number_pages string, even_options
|
32
|
+
end
|
@@ -12,6 +12,7 @@ Prawn::ManualBuilder::Example.generate("repeatable_content.pdf", :page_size => "
|
|
12
12
|
p.example "repeater", :eval_source => false
|
13
13
|
p.example "stamp"
|
14
14
|
p.example "page_numbering", :eval_source => false
|
15
|
+
p.example "alternate_page_numbering", :eval_source => false
|
15
16
|
|
16
17
|
p.intro do
|
17
18
|
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.
|
data/manual/security/security.rb
CHANGED
@@ -18,7 +18,7 @@ Prawn::ManualBuilder::Example.generate("security.pdf", :page_size => "FOLIO") do
|
|
18
18
|
The examples include:")
|
19
19
|
|
20
20
|
list( "How to encrypt the document without the need for a password",
|
21
|
-
"How to configure the regular user
|
21
|
+
"How to configure the regular user permissions",
|
22
22
|
"How to require a password for the regular user",
|
23
23
|
"How to set a owner password that bypass the document permissions"
|
24
24
|
)
|
@@ -23,4 +23,12 @@ Prawn::ManualBuilder::Example.generate(filename) do
|
|
23
23
|
text "This paragraph will be indented. " * 10 +
|
24
24
|
"\n" + "This one will too. " * 10,
|
25
25
|
:indent_paragraphs => 60
|
26
|
+
|
27
|
+
move_down 20
|
28
|
+
|
29
|
+
text "FROM RIGHT TO LEFT:"
|
30
|
+
text "This paragraph will be indented. " * 10 +
|
31
|
+
"\n" + "This one will too. " * 10,
|
32
|
+
:indent_paragraphs => 60, :direction => :rtl
|
33
|
+
|
26
34
|
end
|
@@ -9,6 +9,10 @@
|
|
9
9
|
# that two fragments going against the main direction cannot be placed next to
|
10
10
|
# each other without appearing in the wrong order.
|
11
11
|
#
|
12
|
+
# Writing bidirectional text that combines both left-to-right and right-to-left
|
13
|
+
# languages is easy using the <code>bidi</code> Ruby Gem and its
|
14
|
+
# <code>render_visual</code> function. See https://github.com/elad/ruby-bidi for
|
15
|
+
# instructions and an example using Prawn.
|
12
16
|
require File.expand_path(File.join(File.dirname(__FILE__),
|
13
17
|
%w[.. example_helper]))
|
14
18
|
|
data/manual/text/text.rb
CHANGED
@@ -42,7 +42,7 @@ Prawn::ManualBuilder::Example.generate("text.pdf", :page_size => "FOLIO") do
|
|
42
42
|
s.example "registering_families"
|
43
43
|
end
|
44
44
|
|
45
|
-
p.section "
|
45
|
+
p.section "Multilingualization" do |s|
|
46
46
|
s.example "utf8"
|
47
47
|
s.example "line_wrapping"
|
48
48
|
s.example "right_to_left_text"
|
@@ -9,7 +9,7 @@
|
|
9
9
|
# (the text font size will be shrunk to fit).
|
10
10
|
#
|
11
11
|
# If <code>:shrink_to_fit</code> mode is used with the
|
12
|
-
# <code>:min_font_size</code> option set
|
12
|
+
# <code>:min_font_size</code> option set, the font size will not be reduced to
|
13
13
|
# less than the value provided even if it means truncating some text.
|
14
14
|
#
|
15
15
|
# If the <code>:disable_wrap_by_char</code> is set to <code>true</code>
|
data/manual/text/utf8.rb
CHANGED
@@ -13,12 +13,12 @@ Prawn::ManualBuilder::Example.generate(filename) do
|
|
13
13
|
text "€", :size => 32
|
14
14
|
move_down 20
|
15
15
|
|
16
|
-
text "
|
17
|
-
|
16
|
+
text "This works, because € is one of the few "+
|
17
|
+
"non-ASCII glyphs supported in PDF built-in fonts."
|
18
|
+
|
18
19
|
move_down 20
|
19
20
|
|
20
|
-
text "
|
21
|
-
text "Let's try them with another font."
|
21
|
+
text "For full internationalized text support, we need to use TTF fonts:"
|
22
22
|
move_down 20
|
23
23
|
|
24
24
|
font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf") do
|
@@ -50,7 +50,8 @@ Prawn::ManualBuilder::Example.generate(filename) do
|
|
50
50
|
when :center then offset = (total_width - width)/2
|
51
51
|
end
|
52
52
|
|
53
|
-
text_box(field,
|
53
|
+
text_box(field.force_encoding("windows-1252").encode("UTF-8"),
|
54
|
+
:at => [dx + offset, y])
|
54
55
|
end
|
55
56
|
|
56
57
|
dx += total_width
|
data/prawn.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
"COPYING", "LICENSE", "GPLv2", "GPLv3",
|
16
16
|
".yardopts"]
|
17
17
|
spec.require_path = "lib"
|
18
|
-
spec.required_ruby_version = '>=
|
18
|
+
spec.required_ruby_version = '>= 2.0.0'
|
19
19
|
spec.required_rubygems_version = ">= 1.3.6"
|
20
20
|
|
21
21
|
spec.test_files = Dir[ "spec/*_spec.rb" ]
|
@@ -25,9 +25,9 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.licenses = ['RUBY', 'GPL-2', 'GPL-3']
|
26
26
|
|
27
27
|
spec.add_dependency('ttfunk', '~> 1.4.0')
|
28
|
-
spec.add_dependency('pdf-core', "~> 0.
|
28
|
+
spec.add_dependency('pdf-core', "~> 0.5.0")
|
29
29
|
|
30
|
-
spec.add_development_dependency('pdf-inspector', '~> 1.
|
30
|
+
spec.add_development_dependency('pdf-inspector', '~> 1.2.0')
|
31
31
|
spec.add_development_dependency('yard')
|
32
32
|
spec.add_development_dependency('rspec', '2.14.1')
|
33
33
|
spec.add_development_dependency('mocha')
|
@@ -35,26 +35,11 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_development_dependency('simplecov')
|
36
36
|
spec.add_development_dependency('prawn-manual_builder', ">= 0.2.0")
|
37
37
|
spec.add_development_dependency('pdf-reader', '~>1.2')
|
38
|
-
spec.add_development_dependency('rubocop', '0.
|
38
|
+
spec.add_development_dependency('rubocop', '0.28.0')
|
39
39
|
spec.add_development_dependency('code_statistics', '0.2.13')
|
40
40
|
|
41
41
|
spec.homepage = "http://prawn.majesticseacreature.com"
|
42
42
|
spec.description = <<END_DESC
|
43
43
|
Prawn is a fast, tiny, and nimble PDF generator for Ruby
|
44
|
-
END_DESC
|
45
|
-
spec.post_install_message = <<END_DESC
|
46
|
-
|
47
|
-
********************************************
|
48
|
-
|
49
|
-
|
50
|
-
A lot has changed recently in Prawn.
|
51
|
-
|
52
|
-
Please read the changelog for details:
|
53
|
-
|
54
|
-
https://github.com/prawnpdf/prawn/wiki/CHANGELOG
|
55
|
-
|
56
|
-
|
57
|
-
********************************************
|
58
|
-
|
59
44
|
END_DESC
|
60
45
|
end
|
data/spec/document_spec.rb
CHANGED
@@ -180,6 +180,10 @@ describe "on_page_create callback" do
|
|
180
180
|
create_pdf
|
181
181
|
end
|
182
182
|
|
183
|
+
it "should be delegated from Document to renderer" do
|
184
|
+
expect(@pdf.respond_to?(:on_page_create)).to be_true
|
185
|
+
end
|
186
|
+
|
183
187
|
it "should be invoked with document" do
|
184
188
|
called_with = nil
|
185
189
|
|
@@ -304,14 +308,33 @@ describe "When reopening pages" do
|
|
304
308
|
pages[2][:strings].should == ["Old page 2"]
|
305
309
|
end
|
306
310
|
|
307
|
-
it "should
|
311
|
+
it "should restore the layout of the page" do
|
308
312
|
Prawn::Document.new do
|
309
313
|
start_new_page :layout => :landscape
|
310
314
|
lsize = [bounds.width, bounds.height]
|
315
|
+
|
316
|
+
[bounds.width, bounds.height].should == lsize
|
311
317
|
go_to_page 1
|
312
318
|
[bounds.width, bounds.height].should == lsize.reverse
|
313
319
|
end
|
314
320
|
end
|
321
|
+
|
322
|
+
it "should restore the margin box of the page" do
|
323
|
+
Prawn::Document.new(:margin => [100, 100]) do
|
324
|
+
page1_bounds = bounds
|
325
|
+
|
326
|
+
start_new_page(:margin => [200, 200])
|
327
|
+
|
328
|
+
[bounds.width, bounds.height].should == [page1_bounds.width - 200,
|
329
|
+
page1_bounds.height - 200]
|
330
|
+
|
331
|
+
go_to_page(1)
|
332
|
+
|
333
|
+
bounds.width.should == page1_bounds.width
|
334
|
+
bounds.height.should == page1_bounds.height
|
335
|
+
end
|
336
|
+
|
337
|
+
end
|
315
338
|
end
|
316
339
|
|
317
340
|
describe "When setting page size" do
|
data/spec/font_spec.rb
CHANGED
@@ -80,6 +80,31 @@ describe "#width_of" do
|
|
80
80
|
styled_bold_hello.should == @bold_hello
|
81
81
|
end
|
82
82
|
|
83
|
+
it "should calculate styled widths correctly using TTFs" do
|
84
|
+
create_pdf
|
85
|
+
|
86
|
+
@pdf.font_families.update(
|
87
|
+
'DejaVu Sans' => {
|
88
|
+
:normal => "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf",
|
89
|
+
:bold => "#{Prawn::DATADIR}/fonts/DejaVuSans-Bold.ttf",
|
90
|
+
}
|
91
|
+
)
|
92
|
+
@pdf.font("DejaVu Sans") {
|
93
|
+
@styled_bold_hello = @pdf.width_of("hello", :style => :bold)
|
94
|
+
}
|
95
|
+
@pdf.font("DejaVu Sans", :style => :bold) {
|
96
|
+
@bold_hello = @pdf.width_of("hello")
|
97
|
+
}
|
98
|
+
|
99
|
+
@pdf.font("DejaVu Sans") {
|
100
|
+
@plain_hello = @pdf.width_of("hello")
|
101
|
+
}
|
102
|
+
|
103
|
+
@plain_hello.should_not == @bold_hello
|
104
|
+
|
105
|
+
@styled_bold_hello.should == @bold_hello
|
106
|
+
end
|
107
|
+
|
83
108
|
it "should not treat minus as if it were a hyphen", :issue => 578 do
|
84
109
|
create_pdf
|
85
110
|
|
@@ -18,9 +18,9 @@ describe "Text::Formatted::Box wrapping" do
|
|
18
18
|
text_box.text.should == "Hello\nWorld2"
|
19
19
|
end
|
20
20
|
|
21
|
-
it "should not raise an Encoding::CompatibilityError when keeping a TTF and an "
|
22
|
-
"AFM font together" do
|
21
|
+
it "should not raise an Encoding::CompatibilityError when keeping a TTF and an AFM font together" do
|
23
22
|
file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
|
23
|
+
|
24
24
|
@pdf.font_families["Kai"] = {
|
25
25
|
:normal => { :file => file, :font => "Kai" }
|
26
26
|
}
|
@@ -81,28 +81,6 @@ describe "Text::Formatted::Box wrapping" do
|
|
81
81
|
}.should_not raise_error
|
82
82
|
text_box.text.should == "Noua Delineatio Geographica\ngeneralis | Apostolicarum\nperegrinationum | S FRANCISCI\nXAUERII | Indiarum & Iaponi\346\nApostoli"
|
83
83
|
end
|
84
|
-
|
85
|
-
describe "Unicode" do
|
86
|
-
before do
|
87
|
-
@reset_value = [Encoding.default_external, Encoding.default_internal]
|
88
|
-
Encoding.default_external = Encoding::UTF_8
|
89
|
-
Encoding.default_internal = Encoding::UTF_8
|
90
|
-
end
|
91
|
-
|
92
|
-
after do
|
93
|
-
Encoding.default_external = @reset_value[0]
|
94
|
-
Encoding.default_internal = @reset_value[1]
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should properly handle empty slices using Unicode encoding" do
|
98
|
-
texts = [{ :text => "Noua Delineatio Geographica generalis | Apostolicarum peregrinationum | S FRANCISCI XAUERII | Indiarum & Iaponiæ Apostoli", :font => 'Courier', :size => 10 }]
|
99
|
-
text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Noua Delineatio Geographica gen"))
|
100
|
-
lambda {
|
101
|
-
text_box.render
|
102
|
-
}.should_not raise_error
|
103
|
-
text_box.text.should == "Noua Delineatio Geographica\ngeneralis | Apostolicarum\nperegrinationum | S FRANCISCI\nXAUERII | Indiarum & Iaponi\346\nApostoli"
|
104
|
-
end
|
105
|
-
end
|
106
84
|
end
|
107
85
|
|
108
86
|
describe "Text::Formatted::Box with :fallback_fonts option that includes" +
|
@@ -170,6 +148,12 @@ describe "Text::Formatted::Box with :fallback_fonts option and fragment " +
|
|
170
148
|
@pdf.font_families["Kai"] = {
|
171
149
|
:normal => { :file => file, :font => "Kai" }
|
172
150
|
}
|
151
|
+
|
152
|
+
file = "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
|
153
|
+
@pdf.font_families["DejaVu Sans"] = {
|
154
|
+
:normal => { :file => file }
|
155
|
+
}
|
156
|
+
|
173
157
|
formatted_text = [{ :text => "hello你好" },
|
174
158
|
{ :text => "再见goodbye", :font => "Times-Roman" }]
|
175
159
|
@pdf.formatted_text_box(formatted_text, :fallback_fonts => ["Kai"])
|
@@ -197,6 +181,13 @@ describe "Text::Formatted::Box" do
|
|
197
181
|
@pdf.font_families["Kai"] = {
|
198
182
|
:normal => { :file => file, :font => "Kai" }
|
199
183
|
}
|
184
|
+
|
185
|
+
file = "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
|
186
|
+
@pdf.font_families["DejaVu Sans"] = {
|
187
|
+
:normal => { :file => file }
|
188
|
+
}
|
189
|
+
|
190
|
+
|
200
191
|
@formatted_text = [{ :text => "hello你好" }]
|
201
192
|
@pdf.fallback_fonts(["Kai"])
|
202
193
|
@pdf.fallback_fonts = ["Kai"]
|
@@ -215,26 +206,35 @@ describe "Text::Formatted::Box" do
|
|
215
206
|
fonts_used[1].to_s.should =~ /GBZenKai-Medium/
|
216
207
|
end
|
217
208
|
it "should be able to override document-wide fallback_fonts" do
|
218
|
-
@pdf.
|
209
|
+
@pdf.fallback_fonts = ["DejaVu Sans"]
|
210
|
+
@pdf.formatted_text_box(@formatted_text, :fallback_fonts => ["Kai"])
|
219
211
|
|
220
212
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
221
213
|
|
222
214
|
fonts_used = text.font_settings.map { |e| e[:name] }
|
223
|
-
fonts_used.length.should ==
|
215
|
+
fonts_used.length.should == 2
|
224
216
|
fonts_used[0].should == :"Helvetica"
|
217
|
+
fonts_used[1].should =~ /Kai/
|
225
218
|
end
|
226
219
|
it "should omit the fallback fonts overhead when passing an empty array " +
|
227
220
|
"as the :fallback_fonts" do
|
221
|
+
@pdf.font("Kai")
|
222
|
+
|
228
223
|
box = Prawn::Text::Formatted::Box.new(@formatted_text,
|
229
224
|
:document => @pdf,
|
230
225
|
:fallback_fonts => [])
|
226
|
+
|
231
227
|
box.expects(:process_fallback_fonts).never
|
232
228
|
box.render
|
233
229
|
end
|
230
|
+
|
234
231
|
it "should be able to clear document-wide fallback_fonts" do
|
235
232
|
@pdf.fallback_fonts([])
|
236
233
|
box = Prawn::Text::Formatted::Box.new(@formatted_text,
|
237
234
|
:document => @pdf)
|
235
|
+
|
236
|
+
@pdf.font("Kai")
|
237
|
+
|
238
238
|
box.expects(:process_fallback_fonts).never
|
239
239
|
box.render
|
240
240
|
end
|
@@ -242,16 +242,15 @@ end
|
|
242
242
|
|
243
243
|
describe "Text::Formatted::Box with :fallback_fonts option " +
|
244
244
|
"with glyphs not in the primary or the fallback fonts" do
|
245
|
-
|
245
|
+
|
246
|
+
it "should raise an exception" do
|
247
|
+
file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
|
246
248
|
create_pdf
|
247
249
|
formatted_text = [{ :text => "hello world. 世界你好。" }]
|
248
|
-
@pdf.formatted_text_box(formatted_text, :fallback_fonts => ["Helvetica"])
|
249
250
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
fonts_used.length.should == 1
|
254
|
-
fonts_used[0].should == :"Helvetica"
|
251
|
+
lambda {
|
252
|
+
@pdf.formatted_text_box(formatted_text, :fallback_fonts => ["Courier"])
|
253
|
+
}.should raise_error(Prawn::Errors::IncompatibleStringEncoding)
|
255
254
|
end
|
256
255
|
end
|
257
256
|
|
@@ -616,6 +615,51 @@ describe "Text::Formatted::Box#render with :align => :justify" do
|
|
616
615
|
end
|
617
616
|
end
|
618
617
|
|
618
|
+
describe "Text::Formatted::Box#render with :valign => :center" do
|
619
|
+
it "should have a bottom gap equal to baseline and bottom of box" do
|
620
|
+
create_pdf
|
621
|
+
box_height = 100
|
622
|
+
y = 450
|
623
|
+
array = [{ :text => 'Vertical Align' }]
|
624
|
+
options = {
|
625
|
+
:document => @pdf,
|
626
|
+
:valign => :center,
|
627
|
+
:at => [0,y],
|
628
|
+
:width => 100,
|
629
|
+
:height => box_height,
|
630
|
+
:size => 16
|
631
|
+
}
|
632
|
+
text_box = Prawn::Text::Formatted::Box.new(array, options)
|
633
|
+
text_box.render
|
634
|
+
line_padding = (box_height - text_box.height + text_box.descender) * 0.5
|
635
|
+
baseline = y - line_padding
|
636
|
+
|
637
|
+
text_box.at[1].should be_within(0.01).of(baseline)
|
638
|
+
end
|
639
|
+
end
|
640
|
+
|
641
|
+
describe "Text::Formatted::Box#render with :valign => :bottom" do
|
642
|
+
it "should not render a gap between the text and bottom of box" do
|
643
|
+
create_pdf
|
644
|
+
box_height = 100
|
645
|
+
y = 450
|
646
|
+
array = [{ :text => 'Vertical Align' }]
|
647
|
+
options = {
|
648
|
+
:document => @pdf,
|
649
|
+
:valign => :bottom,
|
650
|
+
:at => [0,y],
|
651
|
+
:width => 100,
|
652
|
+
:height => box_height,
|
653
|
+
:size => 16
|
654
|
+
}
|
655
|
+
text_box = Prawn::Text::Formatted::Box.new(array, options)
|
656
|
+
text_box.render
|
657
|
+
top_padding = y - (box_height - text_box.height)
|
658
|
+
|
659
|
+
text_box.at[1].should be_within(0.01).of(top_padding)
|
660
|
+
end
|
661
|
+
end
|
662
|
+
|
619
663
|
class TestFragmentCallback
|
620
664
|
def initialize(string, number, options)
|
621
665
|
@document = options[:document]
|