prawn 0.13.0 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/README.md +1 -0
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/lib/pdf/core/object_store.rb +3 -15
- data/lib/pdf/core/pdf_object.rb +8 -33
- data/lib/prawn.rb +1 -2
- data/lib/prawn/document.rb +2 -3
- data/lib/prawn/encoding.rb +1 -2
- data/lib/prawn/font/afm.rb +70 -29
- data/lib/prawn/font/ttf.rb +10 -2
- data/lib/prawn/images/jpg.rb +9 -10
- data/lib/prawn/images/png.rb +46 -118
- data/lib/prawn/text/formatted/arranger.rb +1 -5
- data/lib/prawn/text/formatted/box.rb +1 -1
- data/lib/prawn/text/formatted/fragment.rb +5 -11
- data/lib/prawn/text/formatted/line_wrap.rb +4 -25
- data/lib/prawn/text/formatted/wrap.rb +1 -4
- data/manual/example_file.rb +2 -7
- data/manual/manual/manual.rb +1 -1
- data/prawn.gemspec +0 -1
- data/spec/document_spec.rb +5 -7
- data/spec/extensions/encoding_helpers.rb +2 -3
- data/spec/filters_spec.rb +1 -1
- data/spec/font_spec.rb +3 -2
- data/spec/formatted_text_box_spec.rb +14 -25
- data/spec/images_spec.rb +2 -6
- data/spec/line_wrap_spec.rb +2 -2
- data/spec/outline_spec.rb +10 -10
- data/spec/png_spec.rb +9 -12
- data/spec/text_at_spec.rb +11 -26
- data/spec/text_box_spec.rb +6 -2
- data/spec/text_spec.rb +13 -27
- metadata +5 -20
- data/data/images/16bit.dat +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/page_white_text.dat +0 -0
- data/lib/prawn/compatibility.rb +0 -91
@@ -52,11 +52,7 @@ module Prawn
|
|
52
52
|
raise "Lines must be finalized before calling #line"
|
53
53
|
end
|
54
54
|
@fragments.collect do |fragment|
|
55
|
-
|
56
|
-
fragment.text
|
57
|
-
else
|
58
|
-
fragment.text.dup.force_encoding("utf-8")
|
59
|
-
end
|
55
|
+
fragment.text.dup.force_encoding(::Encoding::UTF_8)
|
60
56
|
end.join
|
61
57
|
end
|
62
58
|
|
@@ -392,7 +392,7 @@ module Prawn
|
|
392
392
|
# all fonts
|
393
393
|
fallback_fonts << fragment_font
|
394
394
|
|
395
|
-
hash[:text].
|
395
|
+
hash[:text].each_char do |char|
|
396
396
|
@document.font(fragment_font)
|
397
397
|
font_glyph_pairs << [find_font_for_this_glyph(char,
|
398
398
|
@document.font.family,
|
@@ -212,11 +212,7 @@ module Prawn
|
|
212
212
|
end
|
213
213
|
case direction
|
214
214
|
when :rtl
|
215
|
-
|
216
|
-
string.scan(/./mu).reverse.join
|
217
|
-
else
|
218
|
-
string.reverse
|
219
|
-
end
|
215
|
+
string.reverse
|
220
216
|
else
|
221
217
|
string
|
222
218
|
end
|
@@ -232,11 +228,9 @@ module Prawn
|
|
232
228
|
|
233
229
|
def process_soft_hyphens(string)
|
234
230
|
if string.length > 0 && normalized_soft_hyphen
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
end
|
239
|
-
}
|
231
|
+
if string.encoding != normalized_soft_hyphen.encoding
|
232
|
+
string.force_encoding(normalized_soft_hyphen.encoding)
|
233
|
+
end
|
240
234
|
string[0..-2].gsub(normalized_soft_hyphen, "") + string[-1..-1]
|
241
235
|
else
|
242
236
|
string
|
@@ -244,7 +238,7 @@ module Prawn
|
|
244
238
|
end
|
245
239
|
|
246
240
|
def strip_zero_width_spaces(string)
|
247
|
-
if
|
241
|
+
if string.encoding == ::Encoding::UTF_8
|
248
242
|
string.gsub(Prawn::Text::ZWSP, "")
|
249
243
|
else
|
250
244
|
string
|
@@ -119,7 +119,7 @@ module Prawn
|
|
119
119
|
"[#{whitespace}]+|" +
|
120
120
|
"#{hyphen}+[^#{break_chars}]*|" +
|
121
121
|
"#{soft_hyphen}"
|
122
|
-
|
122
|
+
Regexp.new(pattern)
|
123
123
|
end
|
124
124
|
|
125
125
|
# The pattern used to determine whether any word breaks exist on a
|
@@ -127,7 +127,7 @@ module Prawn
|
|
127
127
|
# word breaking is needed
|
128
128
|
#
|
129
129
|
def word_division_scan_pattern
|
130
|
-
|
130
|
+
Regexp.new("\\s|[#{zero_width_space}#{soft_hyphen}#{hyphen}]")
|
131
131
|
end
|
132
132
|
|
133
133
|
def break_chars
|
@@ -241,18 +241,9 @@ module Prawn
|
|
241
241
|
end
|
242
242
|
|
243
243
|
def wrap_by_char(segment)
|
244
|
-
# this conditional is only necessary for Ruby 1.8 compatibility
|
245
|
-
# String#unicode_characters is a helper which iterates over UTF-8 characters
|
246
|
-
# under Ruby 1.9, it is implemented simply by aliasing #each_char
|
247
244
|
font = @document.font
|
248
|
-
|
249
|
-
|
250
|
-
break unless append_char(char,font)
|
251
|
-
end
|
252
|
-
else
|
253
|
-
segment.each_char do |char|
|
254
|
-
break unless append_char(char,font)
|
255
|
-
end
|
245
|
+
segment.each_char do |char|
|
246
|
+
break unless append_char(char,font)
|
256
247
|
end
|
257
248
|
end
|
258
249
|
|
@@ -268,18 +259,6 @@ module Prawn
|
|
268
259
|
false
|
269
260
|
end
|
270
261
|
end
|
271
|
-
|
272
|
-
def new_regexp(pattern)
|
273
|
-
regexp = ruby_19 {
|
274
|
-
Regexp.new(pattern)
|
275
|
-
}
|
276
|
-
regexp = regexp || ruby_18 {
|
277
|
-
lang = @document.font.unicode? ? 'U' : 'N'
|
278
|
-
Regexp.new(pattern, 0, lang)
|
279
|
-
}
|
280
|
-
regexp
|
281
|
-
end
|
282
|
-
|
283
262
|
end
|
284
263
|
end
|
285
264
|
end
|
@@ -87,10 +87,7 @@ module Prawn
|
|
87
87
|
accumulated_width += fragment_this_line.width
|
88
88
|
end
|
89
89
|
|
90
|
-
|
91
|
-
printed_fragments.map! { |s| s.force_encoding("utf-8") }
|
92
|
-
end
|
93
|
-
@printed_lines << printed_fragments.join
|
90
|
+
@printed_lines << printed_fragments.map { |s| s.force_encoding(::Encoding::UTF_8) }.join
|
94
91
|
end
|
95
92
|
|
96
93
|
def word_spacing_for_this_line
|
data/manual/example_file.rb
CHANGED
@@ -103,13 +103,8 @@ module Prawn
|
|
103
103
|
def read_file(folder_name, filename)
|
104
104
|
data = File.read(File.expand_path(File.join(
|
105
105
|
File.dirname(__FILE__), folder_name, filename)))
|
106
|
-
|
107
|
-
|
108
|
-
# UTF-8, we will need to fix this to work on Ruby 1.9.
|
109
|
-
if data.respond_to?(:encode!)
|
110
|
-
data.encode!("UTF-8")
|
111
|
-
end
|
112
|
-
data
|
106
|
+
|
107
|
+
data.encode(::Encoding::UTF_8)
|
113
108
|
end
|
114
109
|
|
115
110
|
end
|
data/manual/manual/manual.rb
CHANGED
data/prawn.gemspec
CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
|
|
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
|
-
spec.add_dependency('afm')
|
27
26
|
spec.add_development_dependency('pdf-inspector', '~> 1.1.0')
|
28
27
|
spec.add_development_dependency('coderay', '~> 1.0.7')
|
29
28
|
spec.add_development_dependency('rdoc')
|
data/spec/document_spec.rb
CHANGED
@@ -447,13 +447,11 @@ describe "The group() feature" do
|
|
447
447
|
end
|
448
448
|
|
449
449
|
describe "The render() feature" do
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
str.encoding.to_s.should == "ASCII-8BIT"
|
456
|
-
end
|
450
|
+
it "should return a 8 bit encoded string on a m17n aware VM" do
|
451
|
+
@pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
|
452
|
+
@pdf.line [100,100], [200,200]
|
453
|
+
str = @pdf.render
|
454
|
+
str.encoding.to_s.should == "ASCII-8BIT"
|
457
455
|
end
|
458
456
|
|
459
457
|
it "should trigger before_render callbacks just before rendering" do
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module EncodingHelpers
|
2
2
|
def win1252_string(str)
|
3
|
-
|
4
|
-
str
|
3
|
+
str.force_encoding(Encoding::Windows_1252)
|
5
4
|
end
|
6
5
|
|
7
6
|
def bin_string(str)
|
8
|
-
|
7
|
+
str.force_encoding(Encoding::ASCII_8BIT)
|
9
8
|
end
|
10
9
|
end
|
data/spec/filters_spec.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
4
|
|
5
5
|
FILTERS = {
|
6
|
-
:FlateDecode => {'test' =>
|
6
|
+
:FlateDecode => {'test' => "x\x9C+I-.\x01\x00\x04]\x01\xC1".force_encoding(Encoding::ASCII_8BIT) },
|
7
7
|
:DCTDecode => {'test' => "test"}
|
8
8
|
}
|
9
9
|
|
data/spec/font_spec.rb
CHANGED
@@ -80,8 +80,9 @@ describe "#width_of" do
|
|
80
80
|
styled_bold_hello.should == @bold_hello
|
81
81
|
end
|
82
82
|
|
83
|
-
|
84
|
-
|
83
|
+
it "should not treat minus as if it were a hyphen", :issue => 578 do
|
84
|
+
create_pdf
|
85
|
+
|
85
86
|
@pdf.width_of("-0.75").should be < @pdf.width_of("25.00")
|
86
87
|
end
|
87
88
|
end
|
@@ -20,19 +20,17 @@ describe "Text::Formatted::Box wrapping" do
|
|
20
20
|
|
21
21
|
it "should not raise an Encoding::CompatibilityError when keeping a TTF and an " +
|
22
22
|
"AFM font together" do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
}
|
23
|
+
file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
|
24
|
+
@pdf.font_families["Kai"] = {
|
25
|
+
:normal => { :file => file, :font => "Kai" }
|
26
|
+
}
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
texts = [{ :text => "Hello " },
|
29
|
+
{ :text => "再见", :font => "Kai"},
|
30
|
+
{ :text => "World" }]
|
31
|
+
text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Hello World"))
|
33
32
|
|
34
|
-
|
35
|
-
end
|
33
|
+
text_box.render
|
36
34
|
end
|
37
35
|
|
38
36
|
it "should wrap between two fragments when the preceding fragment ends with white space" do
|
@@ -86,23 +84,14 @@ describe "Text::Formatted::Box wrapping" do
|
|
86
84
|
|
87
85
|
describe "Unicode" do
|
88
86
|
before do
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
else
|
93
|
-
@reset_value = [Encoding.default_external, Encoding.default_internal]
|
94
|
-
Encoding.default_external = Encoding::UTF_8
|
95
|
-
Encoding.default_internal = Encoding::UTF_8
|
96
|
-
end
|
87
|
+
@reset_value = [Encoding.default_external, Encoding.default_internal]
|
88
|
+
Encoding.default_external = Encoding::UTF_8
|
89
|
+
Encoding.default_internal = Encoding::UTF_8
|
97
90
|
end
|
98
91
|
|
99
92
|
after do
|
100
|
-
|
101
|
-
|
102
|
-
else
|
103
|
-
Encoding.default_external = @reset_value[0]
|
104
|
-
Encoding.default_internal = @reset_value[1]
|
105
|
-
end
|
93
|
+
Encoding.default_external = @reset_value[0]
|
94
|
+
Encoding.default_internal = @reset_value[1]
|
106
95
|
end
|
107
96
|
|
108
97
|
it "should properly handle empty slices using Unicode encoding" do
|
data/spec/images_spec.rb
CHANGED
@@ -83,16 +83,12 @@ describe "the image() function" do
|
|
83
83
|
@pdf.state.version.should >= 1.5
|
84
84
|
end
|
85
85
|
|
86
|
-
|
87
|
-
# channels. Verified experimentally [BE] but not confirmed in documentation
|
88
|
-
# or anything. OS X Preview handles those files just fine.
|
89
|
-
#
|
90
|
-
it "should embed 8-bit alpha channels for 16-bit PNGs" do
|
86
|
+
it "should embed 16-bit alpha channels for 16-bit PNGs" do
|
91
87
|
@pdf.image "#{Prawn::DATADIR}/images/16bit.png"
|
92
88
|
|
93
89
|
output = @pdf.render
|
94
90
|
output.should =~ /\/BitsPerComponent 16/
|
95
|
-
output.
|
91
|
+
output.should_not =~ /\/BitsPerComponent 8/
|
96
92
|
end
|
97
93
|
|
98
94
|
it "should flow an image to a new page if it will not fit on a page" do
|
data/spec/line_wrap_spec.rb
CHANGED
@@ -113,7 +113,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
|
|
113
113
|
:width => @one_word_width,
|
114
114
|
:document => @pdf)
|
115
115
|
expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
|
116
|
-
expected.force_encoding(
|
116
|
+
expected.force_encoding(Encoding::UTF_8)
|
117
117
|
string.should == expected
|
118
118
|
|
119
119
|
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
@@ -202,7 +202,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
|
|
202
202
|
:width => @one_word_width,
|
203
203
|
:document => @pdf)
|
204
204
|
expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
|
205
|
-
expected.force_encoding(
|
205
|
+
expected.force_encoding(Encoding::UTF_8)
|
206
206
|
string.should == expected
|
207
207
|
|
208
208
|
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
data/spec/outline_spec.rb
CHANGED
@@ -16,20 +16,20 @@ describe "Outline" do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
19
|
+
|
20
|
+
describe "outline encoding" do
|
21
|
+
it "should store all outline titles as UTF-16" do
|
22
|
+
render_and_find_objects
|
23
|
+
@hash.values.each do |obj|
|
24
|
+
if obj.is_a?(Hash) && obj[:Title]
|
25
|
+
title = obj[:Title].dup
|
26
|
+
title.force_encoding(Encoding::UTF_16LE)
|
27
|
+
title.valid_encoding?.should == true
|
29
28
|
end
|
30
29
|
end
|
31
30
|
end
|
32
31
|
end
|
32
|
+
|
33
33
|
describe "#generate_outline" do
|
34
34
|
before(:each) do
|
35
35
|
render_and_find_objects
|
data/spec/png_spec.rb
CHANGED
@@ -131,7 +131,7 @@ describe "When reading a greyscale+alpha PNG file (color type 4)" do
|
|
131
131
|
|
132
132
|
before(:each) do
|
133
133
|
@filename = "#{Prawn::DATADIR}/images/page_white_text.png"
|
134
|
-
@
|
134
|
+
@color_data_filename = "#{Prawn::DATADIR}/images/page_white_text.color"
|
135
135
|
@alpha_data_filename = "#{Prawn::DATADIR}/images/page_white_text.alpha"
|
136
136
|
@img_data = File.binread(@filename)
|
137
137
|
end
|
@@ -151,14 +151,14 @@ describe "When reading a greyscale+alpha PNG file (color type 4)" do
|
|
151
151
|
it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
|
152
152
|
png = Prawn::Images::PNG.new(@img_data)
|
153
153
|
png.split_alpha_channel!
|
154
|
-
data =
|
154
|
+
data = File.binread(@color_data_filename)
|
155
155
|
png.img_data.should == data
|
156
156
|
end
|
157
157
|
|
158
158
|
it "should correctly extract the alpha channel data from the image data chunk" do
|
159
159
|
png = Prawn::Images::PNG.new(@img_data)
|
160
160
|
png.split_alpha_channel!
|
161
|
-
data =
|
161
|
+
data = File.binread(@alpha_data_filename)
|
162
162
|
png.alpha_channel.should == data
|
163
163
|
end
|
164
164
|
end
|
@@ -167,7 +167,7 @@ describe "When reading an RGB+alpha PNG file (color type 6)" do
|
|
167
167
|
|
168
168
|
before(:each) do
|
169
169
|
@filename = "#{Prawn::DATADIR}/images/dice.png"
|
170
|
-
@
|
170
|
+
@color_data_filename = "#{Prawn::DATADIR}/images/dice.color"
|
171
171
|
@alpha_data_filename = "#{Prawn::DATADIR}/images/dice.alpha"
|
172
172
|
@img_data = File.binread(@filename)
|
173
173
|
end
|
@@ -187,17 +187,14 @@ describe "When reading an RGB+alpha PNG file (color type 6)" do
|
|
187
187
|
it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
|
188
188
|
png = Prawn::Images::PNG.new(@img_data)
|
189
189
|
png.split_alpha_channel!
|
190
|
-
data =
|
191
|
-
# compare decompressed rather than compressed image data
|
192
|
-
# because JRuby's implementation of Zlib is different from MRI --
|
193
|
-
# both generate valid gzipped data, but not bit-identical to each other
|
190
|
+
data = File.binread(@color_data_filename)
|
194
191
|
png.img_data.should == data
|
195
192
|
end
|
196
193
|
|
197
194
|
it "should correctly extract the alpha channel data from the image data chunk" do
|
198
195
|
png = Prawn::Images::PNG.new(@img_data)
|
199
196
|
png.split_alpha_channel!
|
200
|
-
data =
|
197
|
+
data = File.binread(@alpha_data_filename)
|
201
198
|
png.alpha_channel.should == data
|
202
199
|
end
|
203
200
|
end
|
@@ -206,7 +203,7 @@ describe "When reading a 16bit RGB+alpha PNG file (color type 6)" do
|
|
206
203
|
|
207
204
|
before(:each) do
|
208
205
|
@filename = "#{Prawn::DATADIR}/images/16bit.png"
|
209
|
-
@
|
206
|
+
@color_data_filename = "#{Prawn::DATADIR}/images/16bit.color"
|
210
207
|
# alpha channel truncated to 8-bit
|
211
208
|
@alpha_data_filename = "#{Prawn::DATADIR}/images/16bit.alpha"
|
212
209
|
@img_data = File.binread(@filename)
|
@@ -227,14 +224,14 @@ describe "When reading a 16bit RGB+alpha PNG file (color type 6)" do
|
|
227
224
|
it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
|
228
225
|
png = Prawn::Images::PNG.new(@img_data)
|
229
226
|
png.split_alpha_channel!
|
230
|
-
data =
|
227
|
+
data = File.binread(@color_data_filename)
|
231
228
|
png.img_data.should == data
|
232
229
|
end
|
233
230
|
|
234
231
|
it "should correctly extract the alpha channel data from the image data chunk" do
|
235
232
|
png = Prawn::Images::PNG.new(@img_data)
|
236
233
|
png.split_alpha_channel!
|
237
|
-
data =
|
234
|
+
data = File.binread(@alpha_data_filename)
|
238
235
|
png.alpha_channel.should == data
|
239
236
|
end
|
240
237
|
end
|
data/spec/text_at_spec.rb
CHANGED
@@ -98,33 +98,18 @@ describe "#draw_text" do
|
|
98
98
|
text.strings.first.should == str
|
99
99
|
end
|
100
100
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
Prawn::Errors::IncompatibleStringEncoding)
|
108
|
-
end
|
101
|
+
it "should raise_error an exception when a utf-8 incompatible string is rendered" do
|
102
|
+
str = "Blah \xDD"
|
103
|
+
str.force_encoding(Encoding::ASCII_8BIT)
|
104
|
+
lambda { @pdf.draw_text(str, :at => [0, 0]) }.should raise_error(
|
105
|
+
Prawn::Errors::IncompatibleStringEncoding)
|
106
|
+
end
|
109
107
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
108
|
+
it "should not raise an exception when a shift-jis string is rendered" do
|
109
|
+
datafile = "#{Prawn::DATADIR}/shift_jis_text.txt"
|
110
|
+
sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
|
111
|
+
@pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
|
114
112
|
|
115
|
-
|
116
|
-
end
|
117
|
-
else
|
118
|
-
# Handle non utf-8 string encodings in a sane way on non-M17N aware VMs
|
119
|
-
it "should raise_error an exception when a corrupt utf-8 string is rendered" do
|
120
|
-
str = "Blah \xDD"
|
121
|
-
lambda { @pdf.draw_text(str, :at => [0, 0]) }.should raise_error(
|
122
|
-
Prawn::Errors::IncompatibleStringEncoding)
|
123
|
-
end
|
124
|
-
it "should raise_error an exception when a shift-jis string is rendered" do
|
125
|
-
sjis_str = File.read("#{Prawn::DATADIR}/shift_jis_text.txt")
|
126
|
-
lambda { @pdf.draw_text(sjis_str, :at => [0, 0]) }.should raise_error(
|
127
|
-
Prawn::Errors::IncompatibleStringEncoding)
|
128
|
-
end
|
113
|
+
@pdf.draw_text(sjis_str, :at => [0, 0])
|
129
114
|
end
|
130
115
|
end
|