prawn 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/prawn/document/bounding_box.rb +213 -141
- data/lib/prawn/document/column_box.rb +61 -26
- data/lib/prawn/document/internals.rb +25 -16
- data/lib/prawn/document/span.rb +20 -18
- data/lib/prawn/document.rb +257 -171
- data/lib/prawn/encoding.rb +2 -5
- data/lib/prawn/errors.rb +23 -34
- data/lib/prawn/font.rb +248 -135
- data/lib/prawn/font_metric_cache.rb +11 -10
- data/lib/prawn/fonts/afm.rb +85 -45
- data/lib/prawn/fonts/dfont.rb +7 -1
- data/lib/prawn/fonts/otf.rb +4 -1
- data/lib/prawn/fonts/to_unicode_cmap.rb +151 -0
- data/lib/prawn/fonts/ttc.rb +7 -2
- data/lib/prawn/fonts/ttf.rb +305 -93
- data/lib/prawn/fonts.rb +14 -0
- data/lib/prawn/graphics/blend_mode.rb +25 -28
- data/lib/prawn/graphics/cap_style.rb +9 -12
- data/lib/prawn/graphics/color.rb +57 -34
- data/lib/prawn/graphics/dash.rb +45 -42
- data/lib/prawn/graphics/join_style.rb +17 -11
- data/lib/prawn/graphics/patterns.rb +190 -69
- data/lib/prawn/graphics/transformation.rb +48 -41
- data/lib/prawn/graphics/transparency.rb +16 -40
- data/lib/prawn/graphics.rb +363 -253
- data/lib/prawn/grid.rb +184 -57
- data/lib/prawn/image_handler.rb +27 -10
- data/lib/prawn/images/image.rb +8 -10
- data/lib/prawn/images/jpg.rb +42 -19
- data/lib/prawn/images/png.rb +92 -41
- data/lib/prawn/images.rb +44 -57
- data/lib/prawn/measurement_extensions.rb +39 -8
- data/lib/prawn/measurements.rb +60 -5
- data/lib/prawn/outline.rb +114 -108
- data/lib/prawn/repeater.rb +51 -35
- data/lib/prawn/security/arcfour.rb +4 -4
- data/lib/prawn/security.rb +75 -70
- data/lib/prawn/soft_mask.rb +42 -30
- data/lib/prawn/stamp.rb +38 -42
- data/lib/prawn/text/box.rb +146 -96
- data/lib/prawn/text/formatted/arranger.rb +87 -26
- data/lib/prawn/text/formatted/box.rb +221 -150
- data/lib/prawn/text/formatted/fragment.rb +130 -14
- data/lib/prawn/text/formatted/line_wrap.rb +33 -24
- data/lib/prawn/text/formatted/parser.rb +112 -72
- data/lib/prawn/text/formatted/wrap.rb +12 -17
- data/lib/prawn/text/formatted.rb +75 -0
- data/lib/prawn/text.rb +441 -196
- data/lib/prawn/transformation_stack.rb +29 -10
- data/lib/prawn/utilities.rb +13 -13
- data/lib/prawn/version.rb +2 -1
- data/lib/prawn/view.rb +68 -53
- data/lib/prawn.rb +23 -18
- data.tar.gz.sig +0 -0
- metadata +54 -177
- metadata.gz.sig +0 -0
- data/.yardopts +0 -10
- data/Gemfile +0 -5
- data/Rakefile +0 -25
- data/manual/absolute_position.pdf +0 -0
- data/manual/basic_concepts/adding_pages.rb +0 -26
- data/manual/basic_concepts/basic_concepts.rb +0 -43
- data/manual/basic_concepts/creation.rb +0 -38
- data/manual/basic_concepts/cursor.rb +0 -32
- data/manual/basic_concepts/measurement.rb +0 -24
- data/manual/basic_concepts/origin.rb +0 -37
- data/manual/basic_concepts/other_cursor_helpers.rb +0 -39
- data/manual/basic_concepts/view.rb +0 -48
- data/manual/bounding_box/bounding_box.rb +0 -41
- data/manual/bounding_box/bounds.rb +0 -48
- data/manual/bounding_box/canvas.rb +0 -23
- data/manual/bounding_box/creation.rb +0 -22
- data/manual/bounding_box/indentation.rb +0 -45
- data/manual/bounding_box/nesting.rb +0 -52
- data/manual/bounding_box/russian_boxes.rb +0 -40
- data/manual/bounding_box/stretchy.rb +0 -29
- data/manual/contents.rb +0 -35
- data/manual/cover.rb +0 -43
- data/manual/document_and_page_options/background.rb +0 -29
- data/manual/document_and_page_options/document_and_page_options.rb +0 -34
- data/manual/document_and_page_options/metadata.rb +0 -25
- data/manual/document_and_page_options/page_margins.rb +0 -36
- data/manual/document_and_page_options/page_size.rb +0 -34
- data/manual/document_and_page_options/print_scaling.rb +0 -23
- data/manual/example_helper.rb +0 -8
- data/manual/graphics/blend_mode.rb +0 -52
- data/manual/graphics/circle_and_ellipse.rb +0 -21
- data/manual/graphics/color.rb +0 -22
- data/manual/graphics/common_lines.rb +0 -29
- data/manual/graphics/fill_and_stroke.rb +0 -41
- data/manual/graphics/fill_rules.rb +0 -38
- data/manual/graphics/gradients.rb +0 -43
- data/manual/graphics/graphics.rb +0 -64
- data/manual/graphics/helper.rb +0 -34
- data/manual/graphics/line_width.rb +0 -36
- data/manual/graphics/lines_and_curves.rb +0 -40
- data/manual/graphics/polygon.rb +0 -27
- data/manual/graphics/rectangle.rb +0 -20
- data/manual/graphics/rotate.rb +0 -25
- data/manual/graphics/scale.rb +0 -42
- data/manual/graphics/soft_masks.rb +0 -44
- data/manual/graphics/stroke_cap.rb +0 -30
- data/manual/graphics/stroke_dash.rb +0 -47
- data/manual/graphics/stroke_join.rb +0 -29
- data/manual/graphics/translate.rb +0 -29
- data/manual/graphics/transparency.rb +0 -33
- data/manual/how_to_read_this_manual.rb +0 -39
- data/manual/images/absolute_position.rb +0 -22
- data/manual/images/fit.rb +0 -20
- data/manual/images/horizontal.rb +0 -24
- data/manual/images/images.rb +0 -41
- data/manual/images/plain_image.rb +0 -17
- data/manual/images/scale.rb +0 -21
- data/manual/images/vertical.rb +0 -30
- data/manual/images/width_and_height.rb +0 -24
- data/manual/layout/boxes.rb +0 -26
- data/manual/layout/content.rb +0 -24
- data/manual/layout/layout.rb +0 -27
- data/manual/layout/simple_grid.rb +0 -22
- data/manual/outline/add_subsection_to.rb +0 -60
- data/manual/outline/insert_section_after.rb +0 -46
- data/manual/outline/outline.rb +0 -33
- data/manual/outline/sections_and_pages.rb +0 -66
- data/manual/repeatable_content/alternate_page_numbering.rb +0 -36
- data/manual/repeatable_content/page_numbering.rb +0 -55
- data/manual/repeatable_content/repeatable_content.rb +0 -35
- data/manual/repeatable_content/repeater.rb +0 -54
- data/manual/repeatable_content/stamp.rb +0 -40
- data/manual/security/encryption.rb +0 -28
- data/manual/security/permissions.rb +0 -43
- data/manual/security/security.rb +0 -28
- data/manual/table.rb +0 -16
- data/manual/text/alignment.rb +0 -43
- data/manual/text/color.rb +0 -24
- data/manual/text/column_box.rb +0 -30
- data/manual/text/fallback_fonts.rb +0 -41
- data/manual/text/font.rb +0 -40
- data/manual/text/font_size.rb +0 -44
- data/manual/text/font_style.rb +0 -25
- data/manual/text/formatted_callbacks.rb +0 -70
- data/manual/text/formatted_text.rb +0 -61
- data/manual/text/free_flowing_text.rb +0 -50
- data/manual/text/inline.rb +0 -40
- data/manual/text/kerning_and_character_spacing.rb +0 -38
- data/manual/text/leading.rb +0 -24
- data/manual/text/line_wrapping.rb +0 -60
- data/manual/text/paragraph_indentation.rb +0 -31
- data/manual/text/positioned_text.rb +0 -37
- data/manual/text/registering_families.rb +0 -51
- data/manual/text/rendering_and_color.rb +0 -36
- data/manual/text/right_to_left_text.rb +0 -54
- data/manual/text/rotation.rb +0 -52
- data/manual/text/single_usage.rb +0 -36
- data/manual/text/text.rb +0 -75
- data/manual/text/text_box_excess.rb +0 -35
- data/manual/text/text_box_extensions.rb +0 -48
- data/manual/text/text_box_overflow.rb +0 -51
- data/manual/text/utf8.rb +0 -27
- data/manual/text/win_ansi_charset.rb +0 -62
- data/prawn.gemspec +0 -51
- data/spec/data/curves.pdf +0 -66
- data/spec/extensions/encoding_helpers.rb +0 -11
- data/spec/prawn/document/bounding_box_spec.rb +0 -550
- data/spec/prawn/document/column_box_spec.rb +0 -75
- data/spec/prawn/document/security_spec.rb +0 -176
- data/spec/prawn/document_annotations_spec.rb +0 -76
- data/spec/prawn/document_destinations_spec.rb +0 -15
- data/spec/prawn/document_grid_spec.rb +0 -99
- data/spec/prawn/document_reference_spec.rb +0 -27
- data/spec/prawn/document_span_spec.rb +0 -44
- data/spec/prawn/document_spec.rb +0 -805
- data/spec/prawn/font_metric_cache_spec.rb +0 -54
- data/spec/prawn/font_spec.rb +0 -544
- data/spec/prawn/graphics/blend_mode_spec.rb +0 -63
- data/spec/prawn/graphics/transparency_spec.rb +0 -81
- data/spec/prawn/graphics_spec.rb +0 -872
- data/spec/prawn/graphics_stroke_styles_spec.rb +0 -229
- data/spec/prawn/image_handler_spec.rb +0 -53
- data/spec/prawn/images/jpg_spec.rb +0 -20
- data/spec/prawn/images/png_spec.rb +0 -283
- data/spec/prawn/images_spec.rb +0 -229
- data/spec/prawn/measurements_extensions_spec.rb +0 -24
- data/spec/prawn/outline_spec.rb +0 -512
- data/spec/prawn/repeater_spec.rb +0 -166
- data/spec/prawn/soft_mask_spec.rb +0 -74
- data/spec/prawn/stamp_spec.rb +0 -173
- data/spec/prawn/text/box_spec.rb +0 -1110
- data/spec/prawn/text/formatted/arranger_spec.rb +0 -466
- data/spec/prawn/text/formatted/box_spec.rb +0 -849
- data/spec/prawn/text/formatted/fragment_spec.rb +0 -343
- data/spec/prawn/text/formatted/line_wrap_spec.rb +0 -495
- data/spec/prawn/text/formatted/parser_spec.rb +0 -697
- data/spec/prawn/text_draw_text_spec.rb +0 -150
- data/spec/prawn/text_rendering_mode_spec.rb +0 -48
- data/spec/prawn/text_spacing_spec.rb +0 -95
- data/spec/prawn/text_spec.rb +0 -603
- data/spec/prawn/text_with_inline_formatting_spec.rb +0 -35
- data/spec/prawn/transformation_stack_spec.rb +0 -66
- data/spec/prawn/view_spec.rb +0 -63
- data/spec/prawn_manual_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -48
data/spec/prawn/images_spec.rb
DELETED
@@ -1,229 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'set'
|
5
|
-
require 'pathname'
|
6
|
-
|
7
|
-
describe Prawn::Images do
|
8
|
-
let(:pdf) { create_pdf }
|
9
|
-
let(:filename) { "#{Prawn::DATADIR}/images/pigs.jpg" }
|
10
|
-
|
11
|
-
it "onlies embed an image once, even if it's added multiple times" do
|
12
|
-
pdf.image filename, at: [100, 100]
|
13
|
-
pdf.image filename, at: [300, 300]
|
14
|
-
|
15
|
-
output = pdf.render
|
16
|
-
images = PDF::Inspector::XObject.analyze(output)
|
17
|
-
# there should be 2 images in the page resources
|
18
|
-
expect(images.page_xobjects.first.size).to eq(2)
|
19
|
-
# but only 1 image xobject
|
20
|
-
expect(output.scan(%r{/Type /XObject}).size).to eq(1)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'returns the image info object' do
|
24
|
-
info = pdf.image(filename)
|
25
|
-
|
26
|
-
expect(info).to be_a_kind_of(Prawn::Images::JPG)
|
27
|
-
|
28
|
-
expect(info.height).to eq(453)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'accepts IO objects' do
|
32
|
-
info =
|
33
|
-
File.open(filename, 'rb') do |file|
|
34
|
-
pdf.image(file)
|
35
|
-
end
|
36
|
-
|
37
|
-
expect(info.height).to eq(453)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'rewinds IO objects to be able to embed them multiply' do
|
41
|
-
info =
|
42
|
-
File.open(filename, 'rb') do |file|
|
43
|
-
pdf.image(file)
|
44
|
-
pdf.image(file)
|
45
|
-
end
|
46
|
-
|
47
|
-
expect(info.height).to eq(453)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'does not close passed-in IO objects' do
|
51
|
-
File.open(filename, 'rb') do |file|
|
52
|
-
pdf.image(file)
|
53
|
-
|
54
|
-
expect(file).to_not be_closed
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'accepts Pathname objects' do
|
59
|
-
info = pdf.image(Pathname.new(filename))
|
60
|
-
expect(info.height).to eq(453)
|
61
|
-
end
|
62
|
-
|
63
|
-
describe 'closes opened files again after getting Pathnames', issue: 975 do
|
64
|
-
describe 'spec with File message spy' do
|
65
|
-
let(:not_filename) { 'non-existent filename' }
|
66
|
-
let(:pathname_double) { instance_double('Pathname', file?: true) }
|
67
|
-
|
68
|
-
before do
|
69
|
-
file_content = File.new(filename, 'rb').read
|
70
|
-
allow(Pathname).to receive(:new).with(not_filename) { pathname_double }
|
71
|
-
allow(pathname_double).to receive(:binread) { file_content }
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'uses only binread, which closes opened files' do
|
75
|
-
# this implicitly tests that a file handle is closed again
|
76
|
-
# because only stubbed binread can be called on not_filename
|
77
|
-
_info = pdf.image(not_filename)
|
78
|
-
expect(pathname_double).to have_received(:binread)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
system_has_lsof = system('lsof -v > /dev/null 2>&1')
|
83
|
-
system_has_grep = system('grep --version > /dev/null 2>&1')
|
84
|
-
if system_has_lsof && system_has_grep
|
85
|
-
it 'closes opened files, spec with lsof' do
|
86
|
-
gc_was_disabled = GC.disable # GC of File would close the file
|
87
|
-
open_before = `lsof -c ruby | grep "#{filename}"`
|
88
|
-
_info = pdf.image(Pathname.new(filename))
|
89
|
-
open_after = `lsof -c ruby | grep "#{filename}"`
|
90
|
-
GC.enable unless gc_was_disabled
|
91
|
-
expect(open_after).to eq(open_before)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
if RUBY_PLATFORM != 'java'
|
96
|
-
it 'closes opened files, spec with ObjectSpace' do
|
97
|
-
gc_was_disabled = GC.disable # GC of File would close the file
|
98
|
-
open_before = ObjectSpace.each_object(File).count { |f| !f.closed? }
|
99
|
-
_info = pdf.image(Pathname.new(filename))
|
100
|
-
open_after = ObjectSpace.each_object(File).count { |f| !f.closed? }
|
101
|
-
GC.enable unless gc_was_disabled
|
102
|
-
expect(open_after).to eq(open_before)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe 'setting the length of the bytestream' do
|
108
|
-
it 'correctlies work with images from Pathname objects' do
|
109
|
-
pdf.image(Pathname.new(filename))
|
110
|
-
expect(pdf).to have_parseable_xobjects
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'correctlies work with images from IO objects' do
|
114
|
-
pdf.image(File.open(filename, 'rb'))
|
115
|
-
expect(pdf).to have_parseable_xobjects
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'correctlies work with images from IO objects not set to mode rb' do
|
119
|
-
pdf.image(File.open(filename, 'r'))
|
120
|
-
expect(pdf).to have_parseable_xobjects
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'raise_errors an UnsupportedImageType if passed a BMP' do
|
125
|
-
filename = "#{Prawn::DATADIR}/images/tru256.bmp"
|
126
|
-
expect { pdf.image filename, at: [100, 100] }
|
127
|
-
.to raise_error(Prawn::Errors::UnsupportedImageType)
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'raise_errors an UnsupportedImageType if passed an interlaced PNG' do
|
131
|
-
filename = "#{Prawn::DATADIR}/images/dice_interlaced.png"
|
132
|
-
expect { pdf.image filename, at: [100, 100] }
|
133
|
-
.to raise_error(Prawn::Errors::UnsupportedImageType)
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'bumps PDF version to 1.5 or greater on embedding 16-bit PNGs' do
|
137
|
-
pdf.image "#{Prawn::DATADIR}/images/16bit.png"
|
138
|
-
expect(pdf.state.version).to be >= 1.5
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'embeds 16-bit alpha channels for 16-bit PNGs' do
|
142
|
-
pdf.image "#{Prawn::DATADIR}/images/16bit.png"
|
143
|
-
|
144
|
-
output = pdf.render
|
145
|
-
expect(output).to match(%r{/BitsPerComponent 16})
|
146
|
-
expect(output).to_not match(%r{/BitsPerComponent 8})
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'flows an image to a new page if it will not fit on a page' do
|
150
|
-
pdf.image filename, fit: [600, 600]
|
151
|
-
pdf.image filename, fit: [600, 600]
|
152
|
-
output = StringIO.new(pdf.render, 'r+')
|
153
|
-
hash = PDF::Reader::ObjectHash.new(output)
|
154
|
-
pages = hash.values.find do |obj|
|
155
|
-
obj.is_a?(Hash) && obj[:Type] == :Pages
|
156
|
-
end[:Kids]
|
157
|
-
expect(pages.size).to eq(2)
|
158
|
-
expect(hash[pages[0]][:Resources][:XObject].keys).to eq([:I1])
|
159
|
-
expect(hash[pages[1]][:Resources][:XObject].keys).to eq([:I2])
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'does not flow an image to a new page if it will fit on one page' do
|
163
|
-
pdf.image filename, fit: [400, 400]
|
164
|
-
pdf.image filename, fit: [400, 400]
|
165
|
-
output = StringIO.new(pdf.render, 'r+')
|
166
|
-
hash = PDF::Reader::ObjectHash.new(output)
|
167
|
-
pages = hash.values.find do |obj|
|
168
|
-
obj.is_a?(Hash) && obj[:Type] == :Pages
|
169
|
-
end[:Kids]
|
170
|
-
expect(pages.size).to eq(1)
|
171
|
-
expect(Set.new(hash[pages[0]][:Resources][:XObject].keys)).to eq(
|
172
|
-
Set.new(%i[I1 I2])
|
173
|
-
)
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'does not start a new page just for a stretchy bounding box' do
|
177
|
-
allow(pdf).to receive(:start_new_page)
|
178
|
-
pdf.bounding_box([0, pdf.cursor], width: pdf.bounds.width) do
|
179
|
-
pdf.image filename
|
180
|
-
end
|
181
|
-
expect(pdf).to_not have_received(:start_new_page)
|
182
|
-
end
|
183
|
-
|
184
|
-
describe ':fit option' do
|
185
|
-
it 'fits inside the defined constraints' do
|
186
|
-
info = pdf.image filename, fit: [100, 400]
|
187
|
-
expect(info.scaled_width).to be <= 100
|
188
|
-
expect(info.scaled_height).to be <= 400
|
189
|
-
|
190
|
-
info = pdf.image filename, fit: [400, 100]
|
191
|
-
expect(info.scaled_width).to be <= 400
|
192
|
-
expect(info.scaled_height).to be <= 100
|
193
|
-
|
194
|
-
info = pdf.image filename, fit: [604, 453]
|
195
|
-
expect(info.scaled_width).to eq(604)
|
196
|
-
expect(info.scaled_height).to eq(453)
|
197
|
-
end
|
198
|
-
|
199
|
-
it 'moves text position' do
|
200
|
-
y = pdf.y
|
201
|
-
pdf.image filename, fit: [100, 400]
|
202
|
-
expect(pdf.y).to be < y
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
describe ':at option' do
|
207
|
-
it 'does not move text position' do
|
208
|
-
y = pdf.y
|
209
|
-
pdf.image filename, at: [100, 400]
|
210
|
-
expect(pdf.y).to eq(y)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
describe ':width option without :height option' do
|
215
|
-
it 'scales the width and height' do
|
216
|
-
info = pdf.image filename, width: 225
|
217
|
-
expect(info.scaled_height).to eq(168.75)
|
218
|
-
expect(info.scaled_width).to eq(225.0)
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
describe ':height option without :width option' do
|
223
|
-
it 'scales the width and height' do
|
224
|
-
info = pdf.image filename, height: 225
|
225
|
-
expect(info.scaled_height).to eq(225.0)
|
226
|
-
expect(info.scaled_width).to eq(300.0)
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'prawn/measurement_extensions'
|
5
|
-
|
6
|
-
describe Prawn::Measurements do
|
7
|
-
describe 'Numeric extensions' do
|
8
|
-
it 'converts units to PostScriptPoints' do
|
9
|
-
expect(1.mm).to be_within(0.000000001).of(2.834645669)
|
10
|
-
expect(1.mm).to eq(72 / 25.4)
|
11
|
-
expect(2.mm).to eq(2 * 72 / 25.4)
|
12
|
-
expect(3.mm).to eq(3 * 72 / 25.4)
|
13
|
-
expect(-3.mm).to eq(-3 * 72 / 25.4)
|
14
|
-
expect(1.cm).to eq(10 * 72 / 25.4)
|
15
|
-
expect(1.dm).to eq(100 * 72 / 25.4)
|
16
|
-
expect(1.m).to eq(1000 * 72 / 25.4)
|
17
|
-
|
18
|
-
expect(1.in).to eq(72)
|
19
|
-
expect(1.ft).to eq(72 * 12)
|
20
|
-
expect(1.yd).to eq(72 * 12 * 3)
|
21
|
-
expect(1.pt).to eq(1)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|