prawn 0.11.1.pre → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +2 -340
- data/HACKING +1 -1
- data/LICENSE +3 -3
- data/Rakefile +17 -6
- data/data/encodings/win_ansi.txt +1 -1
- data/data/images/prawn.png +0 -0
- data/data/pdfs/form.pdf +820 -0
- data/data/pdfs/multipage_template.pdf +127 -0
- data/examples/bounding_box/bounding_boxes.rb +4 -3
- data/examples/bounding_box/indentation.rb +2 -1
- data/examples/bounding_box/russian_boxes.rb +3 -2
- data/examples/bounding_box/stretched_nesting.rb +2 -1
- data/examples/general/background.rb +2 -1
- data/examples/general/canvas.rb +2 -1
- data/examples/general/context_sensitive_headers.rb +2 -1
- data/examples/general/float.rb +2 -1
- data/examples/general/margin.rb +2 -1
- data/examples/general/measurement_units.rb +2 -1
- data/examples/general/metadata-info.rb +2 -1
- data/examples/general/multi_page_layout.rb +2 -1
- data/examples/general/outlines.rb +2 -1
- data/examples/general/page_geometry.rb +2 -1
- data/examples/general/page_numbering.rb +27 -2
- data/examples/general/page_templates.rb +20 -0
- data/examples/general/repeaters.rb +2 -1
- data/examples/general/stamp.rb +4 -3
- data/examples/general/templates.rb +2 -1
- data/examples/graphics/basic_images.rb +2 -1
- data/examples/graphics/cmyk.rb +2 -1
- data/examples/graphics/curves.rb +4 -3
- data/examples/graphics/gradient.rb +23 -0
- data/examples/graphics/hexagon.rb +3 -2
- data/examples/graphics/image_fit.rb +3 -2
- data/examples/graphics/image_flow.rb +2 -1
- data/examples/graphics/image_position.rb +3 -2
- data/examples/graphics/line.rb +2 -1
- data/examples/graphics/png_types.rb +3 -2
- data/examples/graphics/polygons.rb +3 -2
- data/examples/graphics/remote_images.rb +2 -1
- data/examples/graphics/rounded_polygons.rb +2 -1
- data/examples/graphics/rounded_rectangle.rb +2 -1
- data/examples/graphics/ruport_style_helpers.rb +3 -2
- data/examples/graphics/stroke_bounds.rb +2 -1
- data/examples/graphics/stroke_cap_and_join.rb +2 -1
- data/examples/graphics/stroke_dash.rb +2 -1
- data/examples/graphics/transformations.rb +2 -1
- data/examples/graphics/transparency.rb +4 -3
- data/examples/grid/bounding_boxes.rb +2 -1
- data/examples/grid/column_gutter_grid.rb +2 -1
- data/examples/grid/multi_boxes.rb +2 -1
- data/examples/grid/show_grid.rb +2 -1
- data/examples/grid/simple_grid.rb +2 -1
- data/examples/m17n/chinese_text_wrapping.rb +2 -1
- data/examples/m17n/euro.rb +3 -2
- data/examples/m17n/full_win_ansi_character_list.rb +20 -0
- data/examples/m17n/sjis.rb +2 -1
- data/examples/m17n/utf8.rb +3 -2
- data/examples/m17n/win_ansi_charset.rb +2 -1
- data/examples/security/hello_foo.rb +2 -1
- data/examples/table/bill.rb +2 -1
- data/examples/table/borders.rb +25 -0
- data/examples/table/cell.rb +3 -2
- data/examples/table/checkerboard.rb +2 -1
- data/examples/table/header.rb +3 -2
- data/examples/table/inline_format_table.rb +2 -1
- data/examples/table/multi_page_table.rb +2 -1
- data/examples/table/simple_table.rb +2 -1
- data/examples/table/subtable.rb +2 -1
- data/examples/table/widths.rb +2 -1
- data/examples/text/alignment.rb +2 -1
- data/examples/text/character_spacing.rb +2 -1
- data/examples/text/dfont.rb +2 -1
- data/examples/text/family_based_styling.rb +3 -2
- data/examples/text/font_calculations.rb +2 -1
- data/examples/text/font_size.rb +2 -1
- data/examples/text/hyphenation.rb +2 -2
- data/examples/text/indent_paragraphs.rb +7 -5
- data/examples/text/inline_format.rb +7 -6
- data/examples/text/kerning.rb +2 -1
- data/examples/text/rendering_mode.rb +21 -0
- data/examples/text/rotated.rb +2 -1
- data/examples/text/shaped_text_box.rb +2 -1
- data/examples/text/simple_text.rb +2 -1
- data/examples/text/simple_text_ttf.rb +2 -1
- data/examples/text/span.rb +3 -2
- data/examples/text/text_box.rb +7 -5
- data/examples/text/text_box_returning_excess.rb +4 -3
- data/examples/text/text_flow.rb +2 -1
- data/lib/prawn.rb +1 -1
- data/lib/prawn/core/object_store.rb +42 -14
- data/lib/prawn/core/page.rb +22 -8
- data/lib/prawn/core/text.rb +141 -13
- data/lib/prawn/core/text/formatted/arranger.rb +39 -12
- data/lib/prawn/core/text/formatted/line_wrap.rb +205 -60
- data/lib/prawn/core/text/formatted/wrap.rb +72 -35
- data/lib/prawn/document.rb +174 -70
- data/lib/prawn/document/bounding_box.rb +122 -83
- data/lib/prawn/document/column_box.rb +113 -0
- data/lib/prawn/document/graphics_state.rb +90 -2
- data/lib/prawn/document/internals.rb +5 -3
- data/lib/prawn/errors.rb +5 -0
- data/lib/prawn/font.rb +4 -4
- data/lib/prawn/font/afm.rb +11 -0
- data/lib/prawn/font/ttf.rb +5 -0
- data/lib/prawn/graphics.rb +77 -14
- data/lib/prawn/graphics/cap_style.rb +13 -5
- data/lib/prawn/graphics/color.rb +54 -35
- data/lib/prawn/graphics/dash.rb +27 -16
- data/lib/prawn/graphics/gradient.rb +84 -0
- data/lib/prawn/graphics/join_style.rb +12 -3
- data/lib/prawn/graphics/transparency.rb +4 -4
- data/lib/prawn/images.rb +18 -160
- data/lib/prawn/images/jpg.rb +39 -0
- data/lib/prawn/images/png.rb +130 -0
- data/lib/prawn/repeater.rb +6 -13
- data/lib/prawn/security.rb +6 -1
- data/lib/prawn/stamp.rb +12 -4
- data/lib/prawn/table.rb +36 -4
- data/lib/prawn/table/cell.rb +224 -63
- data/lib/prawn/table/cell/text.rb +20 -10
- data/lib/prawn/table/cells.rb +23 -6
- data/lib/prawn/text.rb +54 -91
- data/lib/prawn/text/box.rb +29 -283
- data/lib/prawn/text/formatted/box.rb +349 -24
- data/lib/prawn/text/formatted/fragment.rb +63 -2
- data/lib/prawn/text/formatted/parser.rb +2 -1
- data/prawn.gemspec +21 -5
- data/spec/bounding_box_spec.rb +61 -28
- data/spec/cell_spec.rb +168 -30
- data/spec/document_spec.rb +187 -3
- data/spec/extensions/mocha.rb +45 -0
- data/spec/font_spec.rb +32 -1
- data/spec/formatted_text_arranger_spec.rb +35 -40
- data/spec/formatted_text_box_spec.rb +287 -443
- data/spec/formatted_text_fragment_spec.rb +87 -0
- data/spec/graphics_spec.rb +128 -12
- data/spec/grid_spec.rb +1 -1
- data/spec/images_spec.rb +11 -3
- data/spec/inline_formatted_text_parser_spec.rb +8 -0
- data/spec/line_wrap_spec.rb +200 -208
- data/spec/object_store_spec.rb +10 -0
- data/spec/outline_spec.rb +7 -3
- data/spec/repeater_spec.rb +58 -10
- data/spec/security_spec.rb +6 -0
- data/spec/spec_helper.rb +12 -8
- data/spec/stamp_spec.rb +52 -1
- data/spec/stroke_styles_spec.rb +30 -0
- data/spec/table_spec.rb +93 -3
- data/spec/template_spec.rb +132 -6
- data/spec/text_at_spec.rb +14 -4
- data/spec/text_box_spec.rb +309 -70
- data/spec/text_rendering_mode_spec.rb +45 -0
- data/spec/text_spec.rb +60 -17
- data/spec/text_with_inline_formatting_spec.rb +4 -162
- metadata +241 -241
- data/lib/prawn/core/text/line_wrap.rb +0 -211
- data/lib/prawn/core/text/wrap.rb +0 -82
- data/vendor/pdf-inspector/README +0 -18
- data/vendor/pdf-inspector/lib/pdf/inspector.rb +0 -26
- data/vendor/pdf-inspector/lib/pdf/inspector/extgstate.rb +0 -18
- data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +0 -131
- data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +0 -25
- data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +0 -46
- data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +0 -19
- data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
- data/vendor/ttfunk/example.rb +0 -45
- data/vendor/ttfunk/lib/ttfunk.rb +0 -102
- data/vendor/ttfunk/lib/ttfunk/directory.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +0 -88
- data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +0 -69
- data/vendor/ttfunk/lib/ttfunk/reader.rb +0 -44
- data/vendor/ttfunk/lib/ttfunk/resource_file.rb +0 -78
- data/vendor/ttfunk/lib/ttfunk/subset.rb +0 -18
- data/vendor/ttfunk/lib/ttfunk/subset/base.rb +0 -141
- data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +0 -50
- data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +0 -48
- data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +0 -63
- data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +0 -55
- data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +0 -72
- data/vendor/ttfunk/lib/ttfunk/table.rb +0 -46
- data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +0 -34
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +0 -54
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +0 -126
- data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +0 -79
- data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +0 -64
- data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +0 -81
- data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +0 -37
- data/vendor/ttfunk/lib/ttfunk/table/head.rb +0 -44
- data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +0 -41
- data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +0 -47
- data/vendor/ttfunk/lib/ttfunk/table/kern.rb +0 -79
- data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +0 -62
- data/vendor/ttfunk/lib/ttfunk/table/loca.rb +0 -43
- data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +0 -40
- data/vendor/ttfunk/lib/ttfunk/table/name.rb +0 -125
- data/vendor/ttfunk/lib/ttfunk/table/os2.rb +0 -78
- data/vendor/ttfunk/lib/ttfunk/table/post.rb +0 -91
- data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +0 -43
- data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +0 -35
- data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +0 -23
- data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/table/simple.rb +0 -14
@@ -2,6 +2,59 @@
|
|
2
2
|
|
3
3
|
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
4
|
|
5
|
+
describe "Text::Formatted::Fragment#space_count" do
|
6
|
+
it "should return the number of spaces in the fragment" do
|
7
|
+
create_pdf
|
8
|
+
format_state = { }
|
9
|
+
fragment = Prawn::Text::Formatted::Fragment.new("hello world ",
|
10
|
+
format_state,
|
11
|
+
@pdf)
|
12
|
+
fragment.space_count.should == 2
|
13
|
+
end
|
14
|
+
it "should exclude trailing spaces from the count when " +
|
15
|
+
":exclude_trailing_white_space => true" do
|
16
|
+
create_pdf
|
17
|
+
format_state = { :exclude_trailing_white_space => true }
|
18
|
+
fragment = Prawn::Text::Formatted::Fragment.new("hello world ",
|
19
|
+
format_state,
|
20
|
+
@pdf)
|
21
|
+
fragment.space_count.should == 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "Text::Formatted::Fragment#include_trailing_white_space!" do
|
26
|
+
it "should make the fragment include trailing white space" do
|
27
|
+
create_pdf
|
28
|
+
format_state = { :exclude_trailing_white_space => true }
|
29
|
+
fragment = Prawn::Text::Formatted::Fragment.new("hello world ",
|
30
|
+
format_state,
|
31
|
+
@pdf)
|
32
|
+
fragment.space_count.should == 1
|
33
|
+
fragment.include_trailing_white_space!
|
34
|
+
fragment.space_count.should == 2
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "Text::Formatted::Fragment#text" do
|
39
|
+
it "should return the fragment text" do
|
40
|
+
create_pdf
|
41
|
+
format_state = { }
|
42
|
+
fragment = Prawn::Text::Formatted::Fragment.new("hello world ",
|
43
|
+
format_state,
|
44
|
+
@pdf)
|
45
|
+
fragment.text.should == "hello world "
|
46
|
+
end
|
47
|
+
it "should return the fragment text without trailing spaces when " +
|
48
|
+
":exclude_trailing_white_space => true" do
|
49
|
+
create_pdf
|
50
|
+
format_state = { :exclude_trailing_white_space => true }
|
51
|
+
fragment = Prawn::Text::Formatted::Fragment.new("hello world ",
|
52
|
+
format_state,
|
53
|
+
@pdf)
|
54
|
+
fragment.text.should == "hello world"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
5
58
|
describe "Text::Formatted::Fragment#word_spacing=" do
|
6
59
|
before(:each) do
|
7
60
|
create_pdf
|
@@ -209,3 +262,37 @@ describe "Text::Formatted::Fragment that is a superscript" do
|
|
209
262
|
end
|
210
263
|
end
|
211
264
|
end
|
265
|
+
|
266
|
+
describe "Text::Formatted::Fragment with :direction => :rtl" do
|
267
|
+
it "#text should be reversed" do
|
268
|
+
create_pdf
|
269
|
+
format_state = { :direction => :rtl }
|
270
|
+
fragment = Prawn::Text::Formatted::Fragment.new("hello world",
|
271
|
+
format_state,
|
272
|
+
@pdf)
|
273
|
+
fragment.text.should == "dlrow olleh"
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
describe "Text::Formatted::Fragment default_direction=" do
|
278
|
+
it "should set the direction if there is no fragment level direction " +
|
279
|
+
"specification" do
|
280
|
+
create_pdf
|
281
|
+
format_state = { }
|
282
|
+
fragment = Prawn::Text::Formatted::Fragment.new("hello world",
|
283
|
+
format_state,
|
284
|
+
@pdf)
|
285
|
+
fragment.default_direction = :rtl
|
286
|
+
fragment.direction.should == :rtl
|
287
|
+
end
|
288
|
+
it "should not set the direction if there is a fragment level direction " +
|
289
|
+
"specification" do
|
290
|
+
create_pdf
|
291
|
+
format_state = { :direction => :rtl }
|
292
|
+
fragment = Prawn::Text::Formatted::Fragment.new("hello world",
|
293
|
+
format_state,
|
294
|
+
@pdf)
|
295
|
+
fragment.default_direction = :ltr
|
296
|
+
fragment.direction.should == :rtl
|
297
|
+
end
|
298
|
+
end
|
data/spec/graphics_spec.rb
CHANGED
@@ -159,7 +159,7 @@ end
|
|
159
159
|
describe "When drawing an ellipse" do
|
160
160
|
before(:each) do
|
161
161
|
create_pdf
|
162
|
-
@pdf.
|
162
|
+
@pdf.ellipse [100,100], 25, 50
|
163
163
|
@curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
164
164
|
end
|
165
165
|
|
@@ -172,8 +172,8 @@ end
|
|
172
172
|
describe "When drawing a circle" do
|
173
173
|
before(:each) do
|
174
174
|
create_pdf
|
175
|
-
@pdf.
|
176
|
-
@pdf.
|
175
|
+
@pdf.circle [100,100], 25
|
176
|
+
@pdf.ellipse [100,100], 25, 25
|
177
177
|
@curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
178
178
|
end
|
179
179
|
|
@@ -203,26 +203,68 @@ describe "When setting colors" do
|
|
203
203
|
|
204
204
|
it "should reset the colors on each new page if they have been defined" do
|
205
205
|
@pdf.fill_color "ccff00"
|
206
|
-
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
206
|
+
#colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
207
207
|
|
208
|
-
colors.fill_color_count.should == 2
|
209
|
-
colors.stroke_color_count.should == 1
|
208
|
+
# colors.fill_color_count.should == 2
|
209
|
+
# colors.stroke_color_count.should == 1
|
210
210
|
@pdf.start_new_page
|
211
211
|
@pdf.stroke_color "ff00cc"
|
212
212
|
|
213
|
-
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
214
|
-
colors.fill_color_count.should == 3
|
215
|
-
colors.stroke_color_count.should == 3
|
213
|
+
#colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
214
|
+
# colors.fill_color_count.should == 3
|
216
215
|
|
217
216
|
@pdf.start_new_page
|
218
217
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
219
|
-
colors.fill_color_count.should ==
|
220
|
-
colors.stroke_color_count.should ==
|
218
|
+
colors.fill_color_count.should == 3
|
219
|
+
colors.stroke_color_count.should == 2
|
221
220
|
|
222
221
|
colors.fill_color.should == [0.8,1.0,0.0]
|
223
222
|
colors.stroke_color.should == [1.0,0.0,0.8]
|
224
223
|
end
|
224
|
+
|
225
|
+
it "should set the color space when setting colors on new pages to please fussy readers" do
|
226
|
+
@pdf.stroke_color "000000"
|
227
|
+
@pdf.stroke { @pdf.rectangle([10, 10], 10, 10) }
|
228
|
+
@pdf.start_new_page
|
229
|
+
@pdf.stroke_color "000000"
|
230
|
+
@pdf.stroke { @pdf.rectangle([10, 10], 10, 10) }
|
231
|
+
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
232
|
+
colors.stroke_color_space_count[:DeviceRGB].should == 2
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe "Gradients" do
|
237
|
+
before(:each) { create_pdf }
|
238
|
+
|
239
|
+
it "should create a /Pattern resource" do
|
240
|
+
@pdf.fill_gradient [0, @pdf.bounds.height],
|
241
|
+
@pdf.bounds.width, @pdf.bounds.height, 'FF0000', '0000FF'
|
242
|
+
|
243
|
+
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
244
|
+
pattern = grad.patterns[:SP1]
|
245
|
+
|
246
|
+
pattern.should.not.be.nil
|
247
|
+
assert pattern[:Shading][:Function][:C0].zip([1, 0, 0]).
|
248
|
+
all?{ |x1, x2| (x1-x2).abs < 0.01 }
|
249
|
+
assert pattern[:Shading][:Function][:C1].zip([0, 0, 1]).
|
250
|
+
all?{ |x1, x2| (x1-x2).abs < 0.01 }
|
251
|
+
end
|
252
|
+
|
253
|
+
it "fill_gradient should set fill color to the pattern" do
|
254
|
+
@pdf.fill_gradient [0, @pdf.bounds.height],
|
255
|
+
@pdf.bounds.width, @pdf.bounds.height, 'FF0000', '0000FF'
|
256
|
+
|
257
|
+
str = @pdf.render
|
258
|
+
str.should =~ %r{/Pattern\s+cs\s*/SP1\s+scn}
|
259
|
+
end
|
225
260
|
|
261
|
+
it "stroke_gradient should set stroke color to the pattern" do
|
262
|
+
@pdf.stroke_gradient [0, @pdf.bounds.height],
|
263
|
+
@pdf.bounds.width, @pdf.bounds.height, 'FF0000', '0000FF'
|
264
|
+
|
265
|
+
str = @pdf.render
|
266
|
+
str.should =~ %r{/Pattern\s+CS\s*/SP1\s+SCN}
|
267
|
+
end
|
226
268
|
end
|
227
269
|
|
228
270
|
describe "When using painting shortcuts" do
|
@@ -256,7 +298,7 @@ describe "When using graphics states" do
|
|
256
298
|
|
257
299
|
@pdf.save_graphics_state
|
258
300
|
end
|
259
|
-
|
301
|
+
|
260
302
|
it "should add the right content on restore_graphics_state" do
|
261
303
|
@pdf.expects(:add_content).with('Q')
|
262
304
|
|
@@ -273,6 +315,80 @@ describe "When using graphics states" do
|
|
273
315
|
@pdf.foo
|
274
316
|
end
|
275
317
|
end
|
318
|
+
|
319
|
+
it "should add the previous color space when restoring to a graphic state with different color space" do
|
320
|
+
@pdf.stroke_color '000000'
|
321
|
+
@pdf.save_graphics_state
|
322
|
+
@pdf.stroke_color 0, 0, 0, 0
|
323
|
+
@pdf.restore_graphics_state
|
324
|
+
@pdf.stroke_color 0, 0, 100, 0
|
325
|
+
@pdf.graphic_state.color_space.should == {:stroke=>:DeviceCMYK}
|
326
|
+
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
327
|
+
colors.color_space.should == :DeviceCMYK
|
328
|
+
colors.stroke_color_space_count[:DeviceCMYK].should == 2
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should use the correct dash setting after restoring and starting new page" do
|
332
|
+
@pdf.dash 5
|
333
|
+
@pdf.save_graphics_state
|
334
|
+
@pdf.dash 10
|
335
|
+
@pdf.graphic_state.dash[:dash].should == 10
|
336
|
+
@pdf.restore_graphics_state
|
337
|
+
@pdf.start_new_page
|
338
|
+
@pdf.graphic_state.dash[:dash].should == 5
|
339
|
+
end
|
340
|
+
|
341
|
+
it "the current graphic state should keep track of previous unchanged settings" do
|
342
|
+
@pdf.stroke_color '000000'
|
343
|
+
@pdf.save_graphics_state
|
344
|
+
@pdf.dash 5
|
345
|
+
@pdf.save_graphics_state
|
346
|
+
@pdf.cap_style :round
|
347
|
+
@pdf.save_graphics_state
|
348
|
+
@pdf.fill_color 0, 0, 100, 0
|
349
|
+
@pdf.save_graphics_state
|
350
|
+
|
351
|
+
@pdf.graphic_state.stroke_color.should == "000000"
|
352
|
+
@pdf.graphic_state.join_style.should == :miter
|
353
|
+
@pdf.graphic_state.fill_color.should == [0, 0, 100, 0]
|
354
|
+
@pdf.graphic_state.cap_style.should == :round
|
355
|
+
@pdf.graphic_state.color_space.should == {:fill=>:DeviceCMYK, :stroke=>:DeviceRGB}
|
356
|
+
@pdf.graphic_state.dash.should == {:space=>5, :phase=>0, :dash=>5}
|
357
|
+
@pdf.graphic_state.line_width.should == 1
|
358
|
+
end
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
it "should not add extra graphic space closings when rendering multiple times" do
|
363
|
+
@pdf.render
|
364
|
+
state = PDF::Inspector::Graphics::State.analyze(@pdf.render)
|
365
|
+
state.save_graphics_state_count.should == 1
|
366
|
+
state.restore_graphics_state_count.should == 1
|
367
|
+
end
|
368
|
+
|
369
|
+
it "should add extra graphic state enclosings when content is added on multiple renderings" do
|
370
|
+
@pdf.render
|
371
|
+
@pdf.text "Adding a bit more content"
|
372
|
+
state = PDF::Inspector::Graphics::State.analyze(@pdf.render)
|
373
|
+
state.save_graphics_state_count.should == 2
|
374
|
+
state.restore_graphics_state_count.should == 2
|
375
|
+
end
|
376
|
+
|
377
|
+
it "adds extra graphic state enclosings when new settings are applied on multiple renderings" do
|
378
|
+
@pdf.render
|
379
|
+
@pdf.stroke_color 0, 0, 0, 0
|
380
|
+
state = PDF::Inspector::Graphics::State.analyze(@pdf.render)
|
381
|
+
state.save_graphics_state_count.should == 2
|
382
|
+
state.restore_graphics_state_count.should == 2
|
383
|
+
end
|
384
|
+
|
385
|
+
|
386
|
+
it "should raise error if closing an empty graphic stack" do
|
387
|
+
assert_raise Prawn::Errors::EmptyGraphicStateStack do
|
388
|
+
@pdf.render
|
389
|
+
@pdf.restore_graphics_state
|
390
|
+
end
|
391
|
+
end
|
276
392
|
end
|
277
393
|
|
278
394
|
describe "When using transformation matrix" do
|
data/spec/grid_spec.rb
CHANGED
@@ -67,7 +67,7 @@ describe "A document's grid" do
|
|
67
67
|
|
68
68
|
# Hardcoded default color as I haven't been able to come up with a stable converter
|
69
69
|
# between fill_color without lots code.
|
70
|
-
colors.fill_color.should == [0.0,0.0,0.0]
|
70
|
+
#colors.fill_color.should == [0.0,0.0,0.0]
|
71
71
|
colors.stroke_color.should == [0.0,0.0,0.0]
|
72
72
|
end
|
73
73
|
|
data/spec/images_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
require 'set'
|
5
|
+
require 'pathname'
|
4
6
|
|
5
7
|
describe "the image() function" do
|
6
8
|
|
@@ -36,6 +38,11 @@ describe "the image() function" do
|
|
36
38
|
info.height.should == 453
|
37
39
|
end
|
38
40
|
|
41
|
+
it "should accept Pathname objects" do
|
42
|
+
info = @pdf.image(Pathname.new(@filename))
|
43
|
+
info.height.should == 453
|
44
|
+
end
|
45
|
+
|
39
46
|
it "should raise an UnsupportedImageType if passed a BMP" do
|
40
47
|
filename = "#{Prawn::BASEDIR}/data/images/tru256.bmp"
|
41
48
|
lambda { @pdf.image filename, :at => [100,100] }.should.raise(Prawn::Errors::UnsupportedImageType)
|
@@ -67,7 +74,7 @@ describe "the image() function" do
|
|
67
74
|
@pdf.image @filename, :fit => [600, 600]
|
68
75
|
@pdf.image @filename, :fit => [600, 600]
|
69
76
|
output = StringIO.new(@pdf.render, 'r+')
|
70
|
-
hash = PDF::
|
77
|
+
hash = PDF::Reader::ObjectHash.new(output)
|
71
78
|
pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
|
72
79
|
pages.size.should == 2
|
73
80
|
hash[pages[0]][:Resources][:XObject].keys.should == [:I1]
|
@@ -78,10 +85,11 @@ describe "the image() function" do
|
|
78
85
|
@pdf.image @filename, :fit => [400, 400]
|
79
86
|
@pdf.image @filename, :fit => [400, 400]
|
80
87
|
output = StringIO.new(@pdf.render, 'r+')
|
81
|
-
hash = PDF::
|
88
|
+
hash = PDF::Reader::ObjectHash.new(output)
|
82
89
|
pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
|
83
90
|
pages.size.should == 1
|
84
|
-
hash[pages[0]][:Resources][:XObject].keys.should ==
|
91
|
+
Set.new(hash[pages[0]][:Resources][:XObject].keys).should ==
|
92
|
+
Set.new([:I1, :I2])
|
85
93
|
end
|
86
94
|
|
87
95
|
describe ":fit option" do
|
@@ -499,4 +499,12 @@ describe "Text::Formatted::Parser#array_paragraphs" do
|
|
499
499
|
{ :text => "you" }]]
|
500
500
|
Prawn::Text::Formatted::Parser.array_paragraphs(array).should == target
|
501
501
|
end
|
502
|
+
|
503
|
+
it "should work properly if ending in an empty paragraph" do
|
504
|
+
array = [{ :text => "\nhello\nworld\n" }]
|
505
|
+
target = [[{ :text => "\n" }],
|
506
|
+
[{ :text => "hello" }],
|
507
|
+
[{ :text => "world" }]]
|
508
|
+
Prawn::Text::Formatted::Parser.array_paragraphs(array).should == target
|
509
|
+
end
|
502
510
|
end
|
data/spec/line_wrap_spec.rb
CHANGED
@@ -2,289 +2,231 @@
|
|
2
2
|
|
3
3
|
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
4
|
|
5
|
-
describe "Core::Text::LineWrap#wrap_line" do
|
5
|
+
describe "Core::Text::Formatted::LineWrap#wrap_line" do
|
6
6
|
before(:each) do
|
7
7
|
create_pdf
|
8
|
-
@
|
8
|
+
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
9
|
+
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
10
|
+
@one_word_width = 50
|
9
11
|
end
|
10
|
-
it "should strip
|
11
|
-
|
12
|
+
it "should strip leading and trailing spaces" do
|
13
|
+
array = [{ :text => " hello world, " },
|
14
|
+
{ :text => "goodbye ", :style => [:bold] }]
|
15
|
+
@arranger.format_array = array
|
16
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
12
17
|
:width => 300,
|
13
18
|
:document => @pdf)
|
14
|
-
string.should == "hello world"
|
19
|
+
string.should == "hello world, goodbye"
|
20
|
+
end
|
21
|
+
it "should strip trailing spaces when a white-space-only fragment was" +
|
22
|
+
" successfully pushed onto the end of a line but no other non-white" +
|
23
|
+
" space fragment fits after it" do
|
24
|
+
array = [{ :text => "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " },
|
25
|
+
{ :text => " ", :style => [:bold] },
|
26
|
+
{ :text => " bbbbbbbbbbbbbbbbbbbbbbbbbbbb" }]
|
27
|
+
@arranger.format_array = array
|
28
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
29
|
+
:width => 300,
|
30
|
+
:document => @pdf)
|
31
|
+
string.should == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
15
32
|
end
|
16
|
-
|
17
33
|
it "should raise CannotFit if a too-small width is given" do
|
34
|
+
array = [{ :text => " hello world, " },
|
35
|
+
{ :text => "goodbye ", :style => [:bold] }]
|
36
|
+
@arranger.format_array = array
|
18
37
|
lambda do
|
19
|
-
@line_wrap.wrap_line(
|
20
|
-
|
21
|
-
|
38
|
+
@line_wrap.wrap_line(:arranger => @arranger,
|
39
|
+
:width => 1,
|
40
|
+
:document => @pdf)
|
22
41
|
end.should.raise(Prawn::Errors::CannotFit)
|
23
42
|
end
|
24
|
-
end
|
25
43
|
|
26
|
-
describe "Core::Text::LineWrap#wrap_line" do
|
27
|
-
before(:each) do
|
28
|
-
create_pdf
|
29
|
-
@line_wrap = Prawn::Core::Text::LineWrap.new
|
30
|
-
@one_word_width = 50
|
31
|
-
end
|
32
44
|
it "should break on space" do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
45
|
+
array = [{ :text => "hello world" }]
|
46
|
+
@arranger.format_array = array
|
47
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
48
|
+
:width => @one_word_width,
|
49
|
+
:document => @pdf)
|
50
|
+
string.should == "hello"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should break on zero-width space" do
|
54
|
+
@pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
|
55
|
+
array = [{ :text => "hello#{Prawn::Text::ZWSP}world" }]
|
56
|
+
@arranger.format_array = array
|
57
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
58
|
+
:width => @one_word_width,
|
59
|
+
:document => @pdf)
|
37
60
|
string.should == "hello"
|
38
61
|
end
|
39
62
|
|
63
|
+
it "should not display zero-width space" do
|
64
|
+
@pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
|
65
|
+
array = [{ :text => "hello#{Prawn::Text::ZWSP}world" }]
|
66
|
+
@arranger.format_array = array
|
67
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
68
|
+
:width => 300,
|
69
|
+
:document => @pdf)
|
70
|
+
string.should == "helloworld"
|
71
|
+
end
|
72
|
+
|
40
73
|
it "should break on tab" do
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
74
|
+
array = [{ :text => "hello\tworld" }]
|
75
|
+
@arranger.format_array = array
|
76
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
77
|
+
:width => @one_word_width,
|
78
|
+
:document => @pdf)
|
45
79
|
string.should == "hello"
|
46
80
|
end
|
47
81
|
|
48
82
|
it "should break on hyphens" do
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
83
|
+
array = [{ :text => "hello-world" }]
|
84
|
+
@arranger.format_array = array
|
85
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
86
|
+
:width => @one_word_width,
|
87
|
+
:document => @pdf)
|
53
88
|
string.should == "hello-"
|
54
89
|
end
|
55
90
|
|
56
91
|
it "should not break after a hyphen that follows white space and" +
|
57
92
|
"precedes a word" do
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
93
|
+
array = [{ :text => "hello -" }]
|
94
|
+
@arranger.format_array = array
|
95
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
96
|
+
:width => @one_word_width,
|
97
|
+
:document => @pdf)
|
62
98
|
string.should == "hello -"
|
63
99
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
100
|
+
array = [{ :text => "hello -world" }]
|
101
|
+
@arranger.format_array = array
|
102
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
103
|
+
:width => @one_word_width,
|
104
|
+
:document => @pdf)
|
68
105
|
string.should == "hello"
|
69
106
|
end
|
70
107
|
|
71
108
|
it "should break on a soft hyphen" do
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
109
|
+
string = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}world")
|
110
|
+
array = [{ :text => string }]
|
111
|
+
@arranger.format_array = array
|
112
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
113
|
+
:width => @one_word_width,
|
114
|
+
:document => @pdf)
|
115
|
+
expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
|
116
|
+
expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
|
117
|
+
string.should == expected
|
78
118
|
|
79
119
|
@pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
|
80
|
-
@line_wrap = Prawn::Core::Text::LineWrap.new
|
120
|
+
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
81
121
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
122
|
+
string = "hello#{Prawn::Text::SHY}world"
|
123
|
+
array = [{ :text => string }]
|
124
|
+
@arranger.format_array = array
|
125
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
126
|
+
:width => @one_word_width,
|
127
|
+
:document => @pdf)
|
128
|
+
string.should == "hello#{Prawn::Text::SHY}"
|
87
129
|
end
|
88
130
|
|
89
131
|
it "should not display soft hyphens except at the end of a line" do
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
132
|
+
string = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}world")
|
133
|
+
array = [{ :text => string }]
|
134
|
+
@arranger.format_array = array
|
135
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
136
|
+
:width => 300,
|
137
|
+
:document => @pdf)
|
94
138
|
string.should == "helloworld"
|
95
139
|
|
96
|
-
|
97
140
|
@pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
|
98
|
-
@line_wrap = Prawn::Core::Text::LineWrap.new
|
141
|
+
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
99
142
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
143
|
+
string = "hello#{Prawn::Text::SHY}world"
|
144
|
+
array = [{ :text => string }]
|
145
|
+
@arranger.format_array = array
|
146
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
147
|
+
:width => 300,
|
148
|
+
:document => @pdf)
|
104
149
|
string.should == "helloworld"
|
105
150
|
end
|
106
151
|
|
107
152
|
it "should not break before a hard hyphen that follows a word" do
|
108
153
|
enough_width_for_hello_world = 60
|
109
|
-
normalized_string = @pdf.font.normalize_encoding("hello world")
|
110
|
-
string = @line_wrap.wrap_line(normalized_string,
|
111
|
-
:width => enough_width_for_hello_world,
|
112
|
-
:document => @pdf)
|
113
|
-
string.should == @pdf.font.normalize_encoding("hello world")
|
114
|
-
|
115
|
-
normalized_string = @pdf.font.normalize_encoding("hello world-")
|
116
|
-
string = @line_wrap.wrap_line(normalized_string,
|
117
|
-
:width => enough_width_for_hello_world,
|
118
|
-
:document => @pdf)
|
119
|
-
string.should == @pdf.font.normalize_encoding("hello")
|
120
|
-
|
121
|
-
@pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
|
122
|
-
@line_wrap = Prawn::Core::Text::LineWrap.new
|
123
|
-
enough_width_for_hello_world = 68
|
124
154
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
normalized_string = @pdf.font.normalize_encoding("hello world-")
|
132
|
-
string = @line_wrap.wrap_line(normalized_string,
|
133
|
-
:width => enough_width_for_hello_world,
|
134
|
-
:document => @pdf)
|
135
|
-
string.should == @pdf.font.normalize_encoding("hello")
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should not break after a hard hyphen that follows a soft hyphen and" +
|
139
|
-
"precedes a word" do
|
140
|
-
normalized_string = @pdf.font.normalize_encoding("hello-")
|
141
|
-
string = @line_wrap.wrap_line(normalized_string,
|
142
|
-
:width => @one_word_width,
|
143
|
-
:document => @pdf)
|
144
|
-
string.should == @pdf.font.normalize_encoding("hello-")
|
155
|
+
array = [{ :text => "hello world" }]
|
156
|
+
@arranger.format_array = array
|
157
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
158
|
+
:width => enough_width_for_hello_world,
|
159
|
+
:document => @pdf)
|
160
|
+
string.should == "hello world"
|
145
161
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
162
|
+
array = [{ :text => "hello world-" }]
|
163
|
+
@arranger.format_array = array
|
164
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
165
|
+
:width => enough_width_for_hello_world,
|
166
|
+
:document => @pdf)
|
167
|
+
string.should == "hello"
|
151
168
|
|
152
169
|
@pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
|
153
|
-
@line_wrap = Prawn::Core::Text::LineWrap.new
|
154
|
-
|
155
|
-
normalized_string = @pdf.font.normalize_encoding("hello-world")
|
156
|
-
string = @line_wrap.wrap_line(normalized_string,
|
157
|
-
:width => @one_word_width,
|
158
|
-
:document => @pdf)
|
159
|
-
string.should == @pdf.font.normalize_encoding("hello")
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
describe "Core::Text::LineWrap#consumed_char_count" do
|
164
|
-
before(:each) do
|
165
|
-
create_pdf
|
166
|
-
@line_wrap = Prawn::Core::Text::LineWrap.new
|
167
|
-
end
|
168
|
-
it "should return the total number of characters incorporated into" +
|
169
|
-
" or deleted from the last line" do
|
170
|
-
string = @line_wrap.wrap_line(" hello world ",
|
171
|
-
:width => 300,
|
172
|
-
:document => @pdf)
|
173
|
-
@line_wrap.consumed_char_count.should == 19
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
describe "Core::Text::LineWrap#width" do
|
178
|
-
before(:each) do
|
179
|
-
create_pdf
|
180
|
-
@line_wrap = Prawn::Core::Text::LineWrap.new
|
181
|
-
end
|
182
|
-
it "should return the width of the last wrapped line" do
|
183
|
-
@line_wrap.wrap_line("hello world" * 10,
|
184
|
-
:width => 300,
|
185
|
-
:document => @pdf)
|
186
|
-
@line_wrap.width.should.be > 0
|
187
|
-
@line_wrap.width.should.be <= 300
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
describe "Core::Text::LineWrap#space_count" do
|
192
|
-
before(:each) do
|
193
|
-
create_pdf
|
194
|
-
@line_wrap = Prawn::Core::Text::LineWrap.new
|
195
|
-
end
|
196
|
-
it "should return the number of spaces in the last wrapped line" do
|
197
|
-
@line_wrap.wrap_line("hello world, goobye",
|
198
|
-
:width => 300,
|
199
|
-
:document => @pdf)
|
200
|
-
@line_wrap.space_count.should == 2
|
201
|
-
end
|
202
|
-
it "should exclude trailing spaces from the count" do
|
203
|
-
@line_wrap.wrap_line("hello world, goobye ",
|
204
|
-
:width => 300,
|
205
|
-
:document => @pdf)
|
206
|
-
@line_wrap.space_count.should == 2
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
describe "Core::Text::Formatted::Wrap#line_wrap" do
|
211
|
-
before(:each) do
|
212
|
-
create_pdf
|
213
|
-
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
214
170
|
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
array = [{ :text => " hello world, " },
|
219
|
-
{ :text => "goodbye ", :style => [:bold] }]
|
171
|
+
enough_width_for_hello_world = 68
|
172
|
+
|
173
|
+
array = [{ :text => "hello world" }]
|
220
174
|
@arranger.format_array = array
|
221
175
|
string = @line_wrap.wrap_line(:arranger => @arranger,
|
222
|
-
|
223
|
-
|
224
|
-
string.should == "hello world
|
225
|
-
|
226
|
-
|
227
|
-
" fragment onto the end of a line that currently ends with a space" do
|
228
|
-
array = [{ :text => "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " },
|
229
|
-
{ :text => "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb ", :style => [:bold] }]
|
176
|
+
:width => enough_width_for_hello_world,
|
177
|
+
:document => @pdf)
|
178
|
+
string.should == "hello world"
|
179
|
+
|
180
|
+
array = [{ :text => "hello world-" }]
|
230
181
|
@arranger.format_array = array
|
231
182
|
string = @line_wrap.wrap_line(:arranger => @arranger,
|
232
|
-
|
233
|
-
|
234
|
-
string.should == "
|
183
|
+
:width => enough_width_for_hello_world,
|
184
|
+
:document => @pdf)
|
185
|
+
string.should == "hello"
|
235
186
|
end
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
{ :text => " bbbbbbbbbbbbbbbbbbbbbbbbbbbb" }]
|
187
|
+
|
188
|
+
it "should not break after a hard hyphen that follows a soft hyphen and" +
|
189
|
+
"precedes a word" do
|
190
|
+
string = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}-")
|
191
|
+
array = [{ :text => string }]
|
242
192
|
@arranger.format_array = array
|
243
193
|
string = @line_wrap.wrap_line(:arranger => @arranger,
|
244
|
-
|
245
|
-
|
246
|
-
string.should == "
|
247
|
-
end
|
248
|
-
it "should raise CannotFit if a too-small width is given" do
|
249
|
-
array = [{ :text => " hello world, " },
|
250
|
-
{ :text => "goodbye ", :style => [:bold] }]
|
251
|
-
@arranger.format_array = array
|
252
|
-
lambda do
|
253
|
-
@line_wrap.wrap_line(:arranger => @arranger,
|
254
|
-
:width => 1,
|
255
|
-
:document => @pdf)
|
256
|
-
end.should.raise(Prawn::Errors::CannotFit)
|
257
|
-
end
|
194
|
+
:width => @one_word_width,
|
195
|
+
:document => @pdf)
|
196
|
+
string.should == "hello-"
|
258
197
|
|
259
|
-
|
260
|
-
array = [{ :text =>
|
198
|
+
string = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}-world")
|
199
|
+
array = [{ :text => string }]
|
261
200
|
@arranger.format_array = array
|
262
201
|
string = @line_wrap.wrap_line(:arranger => @arranger,
|
263
202
|
:width => @one_word_width,
|
264
203
|
:document => @pdf)
|
265
|
-
|
266
|
-
|
204
|
+
expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
|
205
|
+
expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
|
206
|
+
string.should == expected
|
267
207
|
|
268
|
-
|
269
|
-
|
208
|
+
@pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
|
209
|
+
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
210
|
+
|
211
|
+
string = "hello#{Prawn::Text::SHY}-"
|
212
|
+
array = [{ :text => string }]
|
270
213
|
@arranger.format_array = array
|
271
214
|
string = @line_wrap.wrap_line(:arranger => @arranger,
|
272
215
|
:width => @one_word_width,
|
273
216
|
:document => @pdf)
|
274
|
-
string.should == "hello"
|
275
|
-
end
|
217
|
+
string.should == "hello-"
|
276
218
|
|
277
|
-
|
278
|
-
array = [{ :text =>
|
219
|
+
string = "hello#{Prawn::Text::SHY}-world"
|
220
|
+
array = [{ :text => string }]
|
279
221
|
@arranger.format_array = array
|
280
222
|
string = @line_wrap.wrap_line(:arranger => @arranger,
|
281
223
|
:width => @one_word_width,
|
282
224
|
:document => @pdf)
|
283
|
-
string.should == "hello
|
225
|
+
string.should == "hello#{Prawn::Text::SHY}"
|
284
226
|
end
|
285
227
|
end
|
286
228
|
|
287
|
-
describe "Core::Text::Formatted::
|
229
|
+
describe "Core::Text::Formatted::LineWrap#space_count" do
|
288
230
|
before(:each) do
|
289
231
|
create_pdf
|
290
232
|
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
@@ -310,7 +252,7 @@ describe "Core::Text::Formatted::Wrap#space_count" do
|
|
310
252
|
end
|
311
253
|
end
|
312
254
|
|
313
|
-
describe "Core::Text::Formatted::
|
255
|
+
describe "Core::Text::Formatted::LineWrap" do
|
314
256
|
before(:each) do
|
315
257
|
create_pdf
|
316
258
|
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
@@ -339,3 +281,53 @@ describe "Core::Text::Formatted::Wrap" do
|
|
339
281
|
line.should.be.empty
|
340
282
|
end
|
341
283
|
end
|
284
|
+
|
285
|
+
describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
|
286
|
+
before(:each) do
|
287
|
+
create_pdf
|
288
|
+
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
289
|
+
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
290
|
+
@one_word_width = 50
|
291
|
+
end
|
292
|
+
it "should be false when the last printed line is not the end of the paragraph" do
|
293
|
+
array = [{ :text => "hello world" }]
|
294
|
+
@arranger.format_array = array
|
295
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
296
|
+
:width => @one_word_width,
|
297
|
+
:document => @pdf)
|
298
|
+
|
299
|
+
@line_wrap.paragraph_finished?.should == false
|
300
|
+
end
|
301
|
+
it "should be true when the last printed line is the last fragment to print" do
|
302
|
+
array = [{ :text => "hello world" }]
|
303
|
+
@arranger.format_array = array
|
304
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
305
|
+
:width => @one_word_width,
|
306
|
+
:document => @pdf)
|
307
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
308
|
+
:width => @one_word_width,
|
309
|
+
:document => @pdf)
|
310
|
+
|
311
|
+
@line_wrap.paragraph_finished?.should == true
|
312
|
+
end
|
313
|
+
it "should be true when a newline exists on the current line" do
|
314
|
+
array = [{ :text => "hello\n world" }]
|
315
|
+
@arranger.format_array = array
|
316
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
317
|
+
:width => @one_word_width,
|
318
|
+
:document => @pdf)
|
319
|
+
|
320
|
+
@line_wrap.paragraph_finished?.should == true
|
321
|
+
end
|
322
|
+
it "should be true when a newline exists in the next fragment" do
|
323
|
+
array = [{ :text => "hello " },
|
324
|
+
{ :text => " \n" },
|
325
|
+
{ :text => "world" }]
|
326
|
+
@arranger.format_array = array
|
327
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
328
|
+
:width => @one_word_width,
|
329
|
+
:document => @pdf)
|
330
|
+
|
331
|
+
@line_wrap.paragraph_finished?.should == true
|
332
|
+
end
|
333
|
+
end
|