prawn 2.0.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/GPLv2 +20 -21
- data/Gemfile +3 -9
- data/Rakefile +20 -23
- data/lib/prawn.rb +37 -49
- data/lib/prawn/document.rb +181 -133
- data/lib/prawn/document/bounding_box.rb +41 -29
- data/lib/prawn/document/column_box.rb +7 -7
- data/lib/prawn/document/internals.rb +18 -8
- data/lib/prawn/document/span.rb +21 -16
- data/lib/prawn/encoding.rb +69 -68
- data/lib/prawn/errors.rb +12 -7
- data/lib/prawn/font.rb +115 -69
- data/lib/prawn/font_metric_cache.rb +14 -8
- data/lib/prawn/{font → fonts}/afm.rb +102 -68
- data/lib/prawn/{font → fonts}/dfont.rb +5 -11
- data/lib/prawn/fonts/otf.rb +11 -0
- data/lib/prawn/fonts/ttc.rb +36 -0
- data/lib/prawn/{font → fonts}/ttf.rb +87 -68
- data/lib/prawn/graphics.rb +120 -80
- data/lib/prawn/graphics/blend_mode.rb +65 -0
- data/lib/prawn/graphics/cap_style.rb +3 -3
- data/lib/prawn/graphics/color.rb +27 -25
- data/lib/prawn/graphics/dash.rb +23 -11
- data/lib/prawn/graphics/join_style.rb +9 -3
- data/lib/prawn/graphics/patterns.rb +197 -67
- data/lib/prawn/graphics/transformation.rb +17 -8
- data/lib/prawn/graphics/transparency.rb +17 -13
- data/lib/prawn/grid.rb +48 -47
- data/lib/prawn/image_handler.rb +5 -5
- data/lib/prawn/images.rb +39 -30
- data/lib/prawn/images/image.rb +2 -1
- data/lib/prawn/images/jpg.rb +28 -22
- data/lib/prawn/images/png.rb +107 -66
- data/lib/prawn/measurement_extensions.rb +10 -9
- data/lib/prawn/measurements.rb +19 -15
- data/lib/prawn/outline.rb +97 -77
- data/lib/prawn/repeater.rb +14 -10
- data/lib/prawn/security.rb +81 -61
- data/lib/prawn/security/arcfour.rb +2 -2
- data/lib/prawn/soft_mask.rb +26 -26
- data/lib/prawn/stamp.rb +20 -13
- data/lib/prawn/text.rb +68 -52
- data/lib/prawn/text/box.rb +11 -8
- data/lib/prawn/text/formatted.rb +5 -5
- data/lib/prawn/text/formatted/arranger.rb +78 -49
- data/lib/prawn/text/formatted/box.rb +134 -100
- data/lib/prawn/text/formatted/fragment.rb +11 -14
- data/lib/prawn/text/formatted/line_wrap.rb +121 -63
- data/lib/prawn/text/formatted/parser.rb +139 -117
- data/lib/prawn/text/formatted/wrap.rb +43 -31
- data/lib/prawn/transformation_stack.rb +44 -0
- data/lib/prawn/utilities.rb +7 -22
- data/lib/prawn/version.rb +2 -2
- data/lib/prawn/view.rb +17 -7
- data/manual/basic_concepts/adding_pages.rb +6 -7
- data/manual/basic_concepts/basic_concepts.rb +31 -22
- data/manual/basic_concepts/creation.rb +10 -11
- data/manual/basic_concepts/cursor.rb +4 -5
- data/manual/basic_concepts/measurement.rb +6 -7
- data/manual/basic_concepts/origin.rb +5 -6
- data/manual/basic_concepts/other_cursor_helpers.rb +11 -12
- data/manual/basic_concepts/view.rb +22 -16
- data/manual/bounding_box/bounding_box.rb +29 -24
- data/manual/bounding_box/bounds.rb +11 -12
- data/manual/bounding_box/canvas.rb +4 -5
- data/manual/bounding_box/creation.rb +6 -7
- data/manual/bounding_box/indentation.rb +14 -15
- data/manual/bounding_box/nesting.rb +24 -17
- data/manual/bounding_box/russian_boxes.rb +14 -13
- data/manual/bounding_box/stretchy.rb +12 -13
- data/manual/contents.rb +28 -22
- data/manual/cover.rb +33 -28
- data/manual/document_and_page_options/background.rb +11 -13
- data/manual/document_and_page_options/document_and_page_options.rb +25 -20
- data/manual/document_and_page_options/metadata.rb +18 -16
- data/manual/document_and_page_options/page_margins.rb +18 -20
- data/manual/document_and_page_options/page_size.rb +13 -12
- data/manual/document_and_page_options/print_scaling.rb +17 -15
- data/manual/example_helper.rb +5 -4
- data/manual/graphics/blend_mode.rb +52 -0
- data/manual/graphics/circle_and_ellipse.rb +4 -5
- data/manual/graphics/color.rb +7 -9
- data/manual/graphics/common_lines.rb +7 -8
- data/manual/graphics/fill_and_stroke.rb +4 -5
- data/manual/graphics/fill_rules.rb +9 -10
- data/manual/graphics/gradients.rb +27 -21
- data/manual/graphics/graphics.rb +48 -39
- data/manual/graphics/helper.rb +12 -9
- data/manual/graphics/line_width.rb +8 -7
- data/manual/graphics/lines_and_curves.rb +7 -8
- data/manual/graphics/polygon.rb +6 -8
- data/manual/graphics/rectangle.rb +4 -5
- data/manual/graphics/rotate.rb +6 -7
- data/manual/graphics/scale.rb +14 -15
- data/manual/graphics/soft_masks.rb +4 -5
- data/manual/graphics/stroke_cap.rb +6 -7
- data/manual/graphics/stroke_dash.rb +11 -12
- data/manual/graphics/stroke_join.rb +5 -6
- data/manual/graphics/translate.rb +9 -10
- data/manual/graphics/transparency.rb +7 -8
- data/manual/how_to_read_this_manual.rb +6 -6
- data/manual/images/absolute_position.rb +6 -7
- data/manual/images/fit.rb +7 -8
- data/manual/images/horizontal.rb +9 -10
- data/manual/images/images.rb +28 -24
- data/manual/images/plain_image.rb +5 -6
- data/manual/images/scale.rb +9 -10
- data/manual/images/vertical.rb +13 -14
- data/manual/images/width_and_height.rb +10 -11
- data/manual/layout/boxes.rb +5 -6
- data/manual/layout/content.rb +7 -8
- data/manual/layout/layout.rb +18 -16
- data/manual/layout/simple_grid.rb +6 -7
- data/manual/outline/add_subsection_to.rb +20 -21
- data/manual/outline/insert_section_after.rb +15 -16
- data/manual/outline/outline.rb +21 -17
- data/manual/outline/sections_and_pages.rb +17 -18
- data/manual/repeatable_content/alternate_page_numbering.rb +21 -17
- data/manual/repeatable_content/page_numbering.rb +17 -16
- data/manual/repeatable_content/repeatable_content.rb +25 -19
- data/manual/repeatable_content/repeater.rb +14 -15
- data/manual/repeatable_content/stamp.rb +14 -15
- data/manual/security/encryption.rb +9 -10
- data/manual/security/permissions.rb +19 -14
- data/manual/security/security.rb +19 -16
- data/manual/table.rb +3 -3
- data/manual/text/alignment.rb +16 -17
- data/manual/text/color.rb +12 -11
- data/manual/text/column_box.rb +9 -10
- data/manual/text/fallback_fonts.rb +25 -21
- data/manual/text/font.rb +11 -12
- data/manual/text/font_size.rb +13 -14
- data/manual/text/font_style.rb +7 -8
- data/manual/text/formatted_callbacks.rb +25 -21
- data/manual/text/formatted_text.rb +33 -25
- data/manual/text/free_flowing_text.rb +20 -21
- data/manual/text/inline.rb +18 -19
- data/manual/text/kerning_and_character_spacing.rb +14 -15
- data/manual/text/leading.rb +7 -8
- data/manual/text/line_wrapping.rb +37 -18
- data/manual/text/paragraph_indentation.rb +13 -14
- data/manual/text/positioned_text.rb +15 -16
- data/manual/text/registering_families.rb +20 -21
- data/manual/text/rendering_and_color.rb +9 -10
- data/manual/text/right_to_left_text.rb +26 -19
- data/manual/text/rotation.rb +28 -23
- data/manual/text/single_usage.rb +8 -9
- data/manual/text/text.rb +57 -52
- data/manual/text/text_box_excess.rb +20 -17
- data/manual/text/text_box_extensions.rb +18 -15
- data/manual/text/text_box_overflow.rb +18 -19
- data/manual/text/utf8.rb +11 -12
- data/manual/text/win_ansi_charset.rb +21 -19
- data/prawn.gemspec +45 -33
- data/spec/extensions/encoding_helpers.rb +3 -3
- data/spec/prawn/document/bounding_box_spec.rb +546 -0
- data/spec/prawn/document/column_box_spec.rb +75 -0
- data/spec/prawn/document/security_spec.rb +176 -0
- data/spec/prawn/document_annotations_spec.rb +76 -0
- data/spec/prawn/document_destinations_spec.rb +15 -0
- data/spec/prawn/document_grid_spec.rb +99 -0
- data/spec/prawn/document_reference_spec.rb +27 -0
- data/spec/prawn/document_span_spec.rb +36 -0
- data/spec/prawn/document_spec.rb +802 -0
- data/spec/prawn/font_metric_cache_spec.rb +54 -0
- data/spec/prawn/font_spec.rb +542 -0
- data/spec/prawn/graphics/blend_mode_spec.rb +63 -0
- data/spec/prawn/graphics/transparency_spec.rb +81 -0
- data/spec/prawn/graphics_spec.rb +837 -0
- data/spec/prawn/graphics_stroke_styles_spec.rb +229 -0
- data/spec/prawn/image_handler_spec.rb +53 -0
- data/spec/prawn/images/jpg_spec.rb +20 -0
- data/spec/prawn/images/png_spec.rb +283 -0
- data/spec/prawn/images_spec.rb +224 -0
- data/spec/prawn/measurements_extensions_spec.rb +24 -0
- data/spec/prawn/outline_spec.rb +412 -0
- data/spec/prawn/repeater_spec.rb +165 -0
- data/spec/prawn/soft_mask_spec.rb +74 -0
- data/spec/prawn/stamp_spec.rb +172 -0
- data/spec/prawn/text/box_spec.rb +1112 -0
- data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
- data/spec/prawn/text/formatted/box_spec.rb +846 -0
- data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
- data/spec/prawn/text/formatted/line_wrap_spec.rb +494 -0
- data/spec/prawn/text/formatted/parser_spec.rb +697 -0
- data/spec/prawn/text_draw_text_spec.rb +149 -0
- data/spec/prawn/text_rendering_mode_spec.rb +48 -0
- data/spec/prawn/text_spacing_spec.rb +95 -0
- data/spec/prawn/text_spec.rb +603 -0
- data/spec/prawn/text_with_inline_formatting_spec.rb +35 -0
- data/spec/prawn/transformation_stack_spec.rb +66 -0
- data/spec/prawn/view_spec.rb +63 -0
- data/spec/prawn_manual_spec.rb +35 -0
- data/spec/spec_helper.rb +19 -23
- metadata +145 -185
- metadata.gz.sig +4 -0
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/16bit.png +0 -0
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/dice_interlaced.png +0 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/license.md +0 -8
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/data/images/page_white_text.png +0 -0
- data/data/images/pal_bk.png +0 -0
- data/data/images/pigs.jpg +0 -0
- data/data/images/prawn.png +0 -0
- data/data/images/ruport.png +0 -0
- data/data/images/ruport_data.dat +0 -0
- data/data/images/ruport_transparent.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/data/images/stef.jpg +0 -0
- data/data/images/tru256.bmp +0 -0
- data/data/images/web-links.dat +0 -1
- data/data/images/web-links.png +0 -0
- data/data/pdfs/complex_template.pdf +0 -0
- data/data/pdfs/contains_ttf_font.pdf +0 -0
- data/data/pdfs/encrypted.pdf +0 -0
- data/data/pdfs/form.pdf +1 -819
- data/data/pdfs/hexagon.pdf +0 -61
- data/data/pdfs/indirect_reference.pdf +0 -86
- data/data/pdfs/multipage_template.pdf +0 -127
- data/data/pdfs/nested_pages.pdf +0 -118
- data/data/pdfs/page_without_mediabox.pdf +0 -193
- data/data/pdfs/resources_as_indirect_object.pdf +0 -83
- data/data/pdfs/two_hexagons.pdf +0 -90
- data/data/pdfs/version_1_6.pdf +0 -61
- data/data/shift_jis_text.txt +0 -1
- data/spec/acceptance/png.rb +0 -24
- data/spec/annotations_spec.rb +0 -67
- data/spec/bounding_box_spec.rb +0 -501
- data/spec/column_box_spec.rb +0 -59
- data/spec/destinations_spec.rb +0 -13
- data/spec/document_spec.rb +0 -742
- data/spec/extensions/mocha.rb +0 -45
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/font_spec.rb +0 -475
- data/spec/formatted_text_arranger_spec.rb +0 -423
- data/spec/formatted_text_box_spec.rb +0 -716
- data/spec/formatted_text_fragment_spec.rb +0 -299
- data/spec/graphics_spec.rb +0 -666
- data/spec/grid_spec.rb +0 -95
- data/spec/image_handler_spec.rb +0 -53
- data/spec/images_spec.rb +0 -167
- data/spec/inline_formatted_text_parser_spec.rb +0 -568
- data/spec/jpg_spec.rb +0 -23
- data/spec/line_wrap_spec.rb +0 -366
- data/spec/measurement_units_spec.rb +0 -22
- data/spec/outline_spec.rb +0 -409
- data/spec/png_spec.rb +0 -235
- data/spec/reference_spec.rb +0 -25
- data/spec/repeater_spec.rb +0 -154
- data/spec/security_spec.rb +0 -151
- data/spec/soft_mask_spec.rb +0 -78
- data/spec/span_spec.rb +0 -43
- data/spec/stamp_spec.rb +0 -179
- data/spec/stroke_styles_spec.rb +0 -208
- data/spec/text_at_spec.rb +0 -142
- data/spec/text_box_spec.rb +0 -1038
- data/spec/text_rendering_mode_spec.rb +0 -45
- data/spec/text_spacing_spec.rb +0 -93
- data/spec/text_spec.rb +0 -549
- data/spec/text_with_inline_formatting_spec.rb +0 -35
- data/spec/transparency_spec.rb +0 -91
- data/spec/view_spec.rb +0 -42
data/spec/jpg_spec.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# Spec'ing the PNG class. Not complete yet - still needs to check the
|
4
|
-
# contents of palette and transparency to ensure they're correct.
|
5
|
-
# Need to find files that have these sections first.
|
6
|
-
|
7
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
8
|
-
|
9
|
-
describe "When reading a JPEG file" do
|
10
|
-
before(:each) do
|
11
|
-
@filename = "#{Prawn::DATADIR}/images/pigs.jpg"
|
12
|
-
@img_data = File.open(@filename, "rb") { |f| f.read }
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should read the basic attributes correctly" do
|
16
|
-
jpg = Prawn::Images::JPG.new(@img_data)
|
17
|
-
|
18
|
-
expect(jpg.width).to eq(604)
|
19
|
-
expect(jpg.height).to eq(453)
|
20
|
-
expect(jpg.bits).to eq(8)
|
21
|
-
expect(jpg.channels).to eq(3)
|
22
|
-
end
|
23
|
-
end
|
data/spec/line_wrap_spec.rb
DELETED
@@ -1,366 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
-
|
5
|
-
describe "Core::Text::Formatted::LineWrap#wrap_line" do
|
6
|
-
before(:each) do
|
7
|
-
create_pdf
|
8
|
-
@arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
9
|
-
@line_wrap = Prawn::Text::Formatted::LineWrap.new
|
10
|
-
@one_word_width = 50
|
11
|
-
end
|
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,
|
17
|
-
:width => 300,
|
18
|
-
:document => @pdf)
|
19
|
-
expect(string).to eq("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
|
-
expect(string).to eq("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
32
|
-
end
|
33
|
-
it "should raise_error CannotFit if a too-small width is given" do
|
34
|
-
array = [{ :text => " hello world, " },
|
35
|
-
{ :text => "goodbye ", :style => [:bold] }]
|
36
|
-
@arranger.format_array = array
|
37
|
-
expect do
|
38
|
-
@line_wrap.wrap_line(:arranger => @arranger,
|
39
|
-
:width => 1,
|
40
|
-
:document => @pdf)
|
41
|
-
end.to raise_error(Prawn::Errors::CannotFit)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should break on space" do
|
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
|
-
expect(string).to eq("hello")
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should break on zero-width space" do
|
54
|
-
@pdf.font("#{Prawn::DATADIR}/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)
|
60
|
-
expect(string).to eq("hello")
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should not display zero-width space" do
|
64
|
-
@pdf.font("#{Prawn::DATADIR}/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
|
-
expect(string).to eq("helloworld")
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should break on tab" do
|
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)
|
79
|
-
expect(string).to eq("hello")
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should break on hyphens" do
|
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)
|
88
|
-
expect(string).to eq("hello-")
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should not break after a hyphen that follows white space and" \
|
92
|
-
"precedes a word" do
|
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)
|
98
|
-
expect(string).to eq("hello -")
|
99
|
-
|
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)
|
105
|
-
expect(string).to eq("hello")
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should break on a soft hyphen" do
|
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(Encoding::UTF_8)
|
117
|
-
expect(string).to eq(expected)
|
118
|
-
|
119
|
-
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
120
|
-
@line_wrap = Prawn::Text::Formatted::LineWrap.new
|
121
|
-
|
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
|
-
expect(string).to eq("hello#{Prawn::Text::SHY}")
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should ignore width of a soft-hyphen during adding fragments to line", :issue => 775 do
|
132
|
-
hyphen_string = "Hy#{Prawn::Text::SHY}phe#{Prawn::Text::SHY}nat#{Prawn::Text::SHY}ions "
|
133
|
-
string1 = @pdf.font.normalize_encoding(hyphen_string * 5)
|
134
|
-
string2 = @pdf.font.normalize_encoding("Hyphenations " * 3 + hyphen_string)
|
135
|
-
|
136
|
-
array1 = [{ text: string1 }]
|
137
|
-
array2 = [{ text: string2 }]
|
138
|
-
|
139
|
-
@arranger.format_array = array1
|
140
|
-
|
141
|
-
res1 = @line_wrap.wrap_line(:arranger => @arranger,
|
142
|
-
:width => 300,
|
143
|
-
:document => @pdf)
|
144
|
-
|
145
|
-
@line_wrap = Prawn::Text::Formatted::LineWrap.new
|
146
|
-
|
147
|
-
@arranger.format_array = array2
|
148
|
-
|
149
|
-
res2 = @line_wrap.wrap_line(:arranger => @arranger,
|
150
|
-
:width => 300,
|
151
|
-
:document => @pdf)
|
152
|
-
expect(res1).to eq(res2)
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should not display soft hyphens except at the end of a line " \
|
156
|
-
"for more than one element in format_array", :issue => 347 do
|
157
|
-
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
158
|
-
@line_wrap = Prawn::Text::Formatted::LineWrap.new
|
159
|
-
|
160
|
-
string1 = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}world ")
|
161
|
-
string2 = @pdf.font.normalize_encoding("hi#{Prawn::Text::SHY}earth")
|
162
|
-
array = [{ :text => string1 }, { :text => string2 }]
|
163
|
-
@arranger.format_array = array
|
164
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
165
|
-
:width => 300,
|
166
|
-
:document => @pdf)
|
167
|
-
expect(string).to eq("helloworld hiearth")
|
168
|
-
end
|
169
|
-
|
170
|
-
it "should not break before a hard hyphen that follows a word" do
|
171
|
-
enough_width_for_hello_world = 60
|
172
|
-
|
173
|
-
array = [{ :text => "hello world" }]
|
174
|
-
@arranger.format_array = array
|
175
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
176
|
-
:width => enough_width_for_hello_world,
|
177
|
-
:document => @pdf)
|
178
|
-
expect(string).to eq("hello world")
|
179
|
-
|
180
|
-
array = [{ :text => "hello world-" }]
|
181
|
-
@arranger.format_array = array
|
182
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
183
|
-
:width => enough_width_for_hello_world,
|
184
|
-
:document => @pdf)
|
185
|
-
expect(string).to eq("hello")
|
186
|
-
|
187
|
-
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
188
|
-
@line_wrap = Prawn::Text::Formatted::LineWrap.new
|
189
|
-
enough_width_for_hello_world = 68
|
190
|
-
|
191
|
-
array = [{ :text => "hello world" }]
|
192
|
-
@arranger.format_array = array
|
193
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
194
|
-
:width => enough_width_for_hello_world,
|
195
|
-
:document => @pdf)
|
196
|
-
expect(string).to eq("hello world")
|
197
|
-
|
198
|
-
array = [{ :text => "hello world-" }]
|
199
|
-
@arranger.format_array = array
|
200
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
201
|
-
:width => enough_width_for_hello_world,
|
202
|
-
:document => @pdf)
|
203
|
-
expect(string).to eq("hello")
|
204
|
-
end
|
205
|
-
|
206
|
-
it "should not break after a hard hyphen that follows a soft hyphen and" \
|
207
|
-
"precedes a word" do
|
208
|
-
string = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}-")
|
209
|
-
array = [{ :text => string }]
|
210
|
-
@arranger.format_array = array
|
211
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
212
|
-
:width => @one_word_width,
|
213
|
-
:document => @pdf)
|
214
|
-
expect(string).to eq("hello-")
|
215
|
-
|
216
|
-
string = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}-world")
|
217
|
-
array = [{ :text => string }]
|
218
|
-
@arranger.format_array = array
|
219
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
220
|
-
:width => @one_word_width,
|
221
|
-
:document => @pdf)
|
222
|
-
expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
|
223
|
-
expected.force_encoding(Encoding::UTF_8)
|
224
|
-
expect(string).to eq(expected)
|
225
|
-
|
226
|
-
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
227
|
-
@line_wrap = Prawn::Text::Formatted::LineWrap.new
|
228
|
-
|
229
|
-
string = "hello#{Prawn::Text::SHY}-"
|
230
|
-
array = [{ :text => string }]
|
231
|
-
@arranger.format_array = array
|
232
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
233
|
-
:width => @one_word_width,
|
234
|
-
:document => @pdf)
|
235
|
-
expect(string).to eq("hello-")
|
236
|
-
|
237
|
-
string = "hello#{Prawn::Text::SHY}-world"
|
238
|
-
array = [{ :text => string }]
|
239
|
-
@arranger.format_array = array
|
240
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
241
|
-
:width => @one_word_width,
|
242
|
-
:document => @pdf)
|
243
|
-
expect(string).to eq("hello#{Prawn::Text::SHY}")
|
244
|
-
end
|
245
|
-
|
246
|
-
it "should process UTF-8 chars", :unresolved, :issue => 693 do
|
247
|
-
array = [{ :text => "Test" }]
|
248
|
-
@arranger.format_array = array
|
249
|
-
|
250
|
-
# Should not raise an encoding error
|
251
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
252
|
-
:width => 300,
|
253
|
-
:document => @pdf)
|
254
|
-
expect(string).to eq("Test")
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
describe "Core::Text::Formatted::LineWrap#space_count" do
|
259
|
-
before(:each) do
|
260
|
-
create_pdf
|
261
|
-
@arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
262
|
-
@line_wrap = Prawn::Text::Formatted::LineWrap.new
|
263
|
-
end
|
264
|
-
it "should return the number of spaces in the last wrapped line" do
|
265
|
-
array = [{ :text => "hello world, " },
|
266
|
-
{ :text => "goodbye", :style => [:bold] }]
|
267
|
-
@arranger.format_array = array
|
268
|
-
@line_wrap.wrap_line(:arranger => @arranger,
|
269
|
-
:width => 300,
|
270
|
-
:document => @pdf)
|
271
|
-
expect(@line_wrap.space_count).to eq(2)
|
272
|
-
end
|
273
|
-
it "should exclude preceding and trailing spaces from the count" do
|
274
|
-
array = [{ :text => " hello world, " },
|
275
|
-
{ :text => "goodbye ", :style => [:bold] }]
|
276
|
-
@arranger.format_array = array
|
277
|
-
@line_wrap.wrap_line(:arranger => @arranger,
|
278
|
-
:width => 300,
|
279
|
-
:document => @pdf)
|
280
|
-
expect(@line_wrap.space_count).to eq(2)
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
describe "Core::Text::Formatted::LineWrap" do
|
285
|
-
before(:each) do
|
286
|
-
create_pdf
|
287
|
-
@arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
288
|
-
array = [{ :text => "hello\nworld\n\n\nhow are you?" },
|
289
|
-
{ :text => "\n" },
|
290
|
-
{ :text => "\n" },
|
291
|
-
{ :text => "" },
|
292
|
-
{ :text => "fine, thanks. " * 4 },
|
293
|
-
{ :text => "" },
|
294
|
-
{ :text => "\n" },
|
295
|
-
{ :text => "" }]
|
296
|
-
@arranger.format_array = array
|
297
|
-
@line_wrap = Prawn::Text::Formatted::LineWrap.new
|
298
|
-
end
|
299
|
-
it "should only return an empty string if nothing fit or there" \
|
300
|
-
"was nothing to wrap" do
|
301
|
-
8.times do
|
302
|
-
line = @line_wrap.wrap_line(:arranger => @arranger,
|
303
|
-
:width => 200,
|
304
|
-
:document => @pdf)
|
305
|
-
expect(line).not_to be_empty
|
306
|
-
end
|
307
|
-
line = @line_wrap.wrap_line(:arranger => @arranger,
|
308
|
-
:width => 200,
|
309
|
-
:document => @pdf)
|
310
|
-
expect(line).to be_empty
|
311
|
-
end
|
312
|
-
it "should tokenize a string using the scan_pattern" do
|
313
|
-
tokens = @line_wrap.tokenize("one two three")
|
314
|
-
expect(tokens.length).to eq(6)
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
|
319
|
-
before(:each) do
|
320
|
-
create_pdf
|
321
|
-
@arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
322
|
-
@line_wrap = Prawn::Text::Formatted::LineWrap.new
|
323
|
-
@one_word_width = 50
|
324
|
-
end
|
325
|
-
it "should be_false when the last printed line is not the end of the paragraph" do
|
326
|
-
array = [{ :text => "hello world" }]
|
327
|
-
@arranger.format_array = array
|
328
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
329
|
-
:width => @one_word_width,
|
330
|
-
:document => @pdf)
|
331
|
-
|
332
|
-
expect(@line_wrap.paragraph_finished?).to eq(false)
|
333
|
-
end
|
334
|
-
it "should be_true when the last printed line is the last fragment to print" do
|
335
|
-
array = [{ :text => "hello world" }]
|
336
|
-
@arranger.format_array = array
|
337
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
338
|
-
:width => @one_word_width,
|
339
|
-
:document => @pdf)
|
340
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
341
|
-
:width => @one_word_width,
|
342
|
-
:document => @pdf)
|
343
|
-
|
344
|
-
expect(@line_wrap.paragraph_finished?).to eq(true)
|
345
|
-
end
|
346
|
-
it "should be_true when a newline exists on the current line" do
|
347
|
-
array = [{ :text => "hello\n world" }]
|
348
|
-
@arranger.format_array = array
|
349
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
350
|
-
:width => @one_word_width,
|
351
|
-
:document => @pdf)
|
352
|
-
|
353
|
-
expect(@line_wrap.paragraph_finished?).to eq(true)
|
354
|
-
end
|
355
|
-
it "should be_true when a newline exists in the next fragment" do
|
356
|
-
array = [{ :text => "hello " },
|
357
|
-
{ :text => " \n" },
|
358
|
-
{ :text => "world" }]
|
359
|
-
@arranger.format_array = array
|
360
|
-
string = @line_wrap.wrap_line(:arranger => @arranger,
|
361
|
-
:width => @one_word_width,
|
362
|
-
:document => @pdf)
|
363
|
-
|
364
|
-
expect(@line_wrap.paragraph_finished?).to eq(true)
|
365
|
-
end
|
366
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
-
require "prawn/measurement_extensions"
|
5
|
-
|
6
|
-
describe "Measurement units" do
|
7
|
-
it "should convert units to PostScriptPoints" do
|
8
|
-
expect(1.mm).to be_within(0.000000001).of(2.834645669)
|
9
|
-
expect(1.mm).to eq(72 / 25.4)
|
10
|
-
expect(2.mm).to eq(2 * 72 / 25.4)
|
11
|
-
expect(3.mm).to eq(3 * 72 / 25.4)
|
12
|
-
expect(-3.mm).to eq(-3 * 72 / 25.4)
|
13
|
-
expect(1.cm).to eq(10 * 72 / 25.4)
|
14
|
-
expect(1.dm).to eq(100 * 72 / 25.4)
|
15
|
-
expect(1.m).to eq(1000 * 72 / 25.4)
|
16
|
-
|
17
|
-
expect(1.in).to eq(72)
|
18
|
-
expect(1.ft).to eq(72 * 12)
|
19
|
-
expect(1.yd).to eq(72 * 12 * 3)
|
20
|
-
expect(1.pt).to eq(1)
|
21
|
-
end
|
22
|
-
end
|
data/spec/outline_spec.rb
DELETED
@@ -1,409 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
3
|
-
|
4
|
-
describe "Outline" do
|
5
|
-
before(:each) do
|
6
|
-
@pdf = Prawn::Document.new do
|
7
|
-
text "Page 1. This is the first Chapter. "
|
8
|
-
start_new_page
|
9
|
-
text "Page 2. More in the first Chapter. "
|
10
|
-
start_new_page
|
11
|
-
outline.define do
|
12
|
-
section 'Chapter 1', :destination => 1, :closed => true do
|
13
|
-
page :destination => 1, :title => 'Page 1'
|
14
|
-
page :destination => 2, :title => 'Page 2'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
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
|
-
expect(title.valid_encoding?).to eq(true)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "#generate_outline" do
|
34
|
-
before(:each) do
|
35
|
-
render_and_find_objects
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should create a root outline dictionary item" do
|
39
|
-
expect(@outline_root).not_to be_nil
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should set the first and last top items of the root outline dictionary item" do
|
43
|
-
expect(referenced_object(@outline_root[:First])).to eq(@section_1)
|
44
|
-
expect(referenced_object(@outline_root[:Last])).to eq(@section_1)
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#create_outline_item" do
|
48
|
-
it "should create outline items for each section and page" do
|
49
|
-
[@section_1, @page_1, @page_2].each { |item| expect(item).not_to be_nil }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#set_relations, #set_variables_for_block, and #reset_parent" do
|
54
|
-
it "should link sibling items" do
|
55
|
-
expect(referenced_object(@page_1[:Next])).to eq(@page_2)
|
56
|
-
expect(referenced_object(@page_2[:Prev])).to eq(@page_1)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should link child items to parent item" do
|
60
|
-
[@page_1, @page_2].each { |page| expect(referenced_object(page[:Parent])).to eq(@section_1) }
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should set the first and last child items for parent item" do
|
64
|
-
expect(referenced_object(@section_1[:First])).to eq(@page_1)
|
65
|
-
expect(referenced_object(@section_1[:Last])).to eq(@page_2)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "#increase_count" do
|
70
|
-
it "should add the count of all descendant items" do
|
71
|
-
expect(@outline_root[:Count]).to eq(3)
|
72
|
-
expect(@section_1[:Count].abs).to eq(2)
|
73
|
-
expect(@page_1[:Count]).to eq(0)
|
74
|
-
expect(@page_2[:Count]).to eq(0)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "closed option" do
|
79
|
-
it "should set the item's integer count to negative" do
|
80
|
-
expect(@section_1[:Count]).to eq(-2)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "adding a custom destination" do
|
86
|
-
before(:each) do
|
87
|
-
@pdf.start_new_page
|
88
|
-
@pdf.text "Page 3 with a destination"
|
89
|
-
@pdf.add_dest('customdest', @pdf.dest_xyz(200, 200))
|
90
|
-
pdf = @pdf
|
91
|
-
@pdf.outline.update do
|
92
|
-
page :destination => pdf.dest_xyz(200, 200), :title => 'Custom Destination'
|
93
|
-
end
|
94
|
-
render_and_find_objects
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should create an outline item" do
|
98
|
-
expect(@custom_dest).not_to be_nil
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should reference the custom destination" do
|
102
|
-
expect(referenced_object(@custom_dest[:Dest].first)).to eq(referenced_object(@pages.last))
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "addding a section later with outline#section" do
|
107
|
-
before(:each) do
|
108
|
-
@pdf.start_new_page
|
109
|
-
@pdf.text "Page 3. An added section "
|
110
|
-
@pdf.outline.update do
|
111
|
-
section 'Added Section', :destination => 3 do
|
112
|
-
page :destination => 3, :title => 'Page 3'
|
113
|
-
end
|
114
|
-
end
|
115
|
-
render_and_find_objects
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should add new outline items to document" do
|
119
|
-
[@section_2, @page_3].each { |item| expect(item).not_to be_nil }
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should reset the last items for root outline dictionary" do
|
123
|
-
expect(referenced_object(@outline_root[:First])).to eq(@section_1)
|
124
|
-
expect(referenced_object(@outline_root[:Last])).to eq(@section_2)
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should reset the next relation for the previous last top level item" do
|
128
|
-
expect(referenced_object(@section_1[:Next])).to eq(@section_2)
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should set the previous relation of the addded to section" do
|
132
|
-
expect(referenced_object(@section_2[:Prev])).to eq(@section_1)
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should increase the count of root outline dictionary" do
|
136
|
-
expect(@outline_root[:Count]).to eq(5)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "#outline.add_subsection_to" do
|
141
|
-
context "positioned last" do
|
142
|
-
before(:each) do
|
143
|
-
@pdf.start_new_page
|
144
|
-
@pdf.text "Page 3. An added subsection "
|
145
|
-
@pdf.outline.update do
|
146
|
-
add_subsection_to 'Chapter 1' do
|
147
|
-
section 'Added SubSection', :destination => 3 do
|
148
|
-
page :destination => 3, :title => 'Added Page 3'
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
render_and_find_objects
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should add new outline items to document" do
|
156
|
-
[@subsection, @added_page_3].each { |item| expect(item).not_to be_nil }
|
157
|
-
end
|
158
|
-
|
159
|
-
it "should reset the last item for parent item dictionary" do
|
160
|
-
expect(referenced_object(@section_1[:First])).to eq(@page_1)
|
161
|
-
expect(referenced_object(@section_1[:Last])).to eq(@subsection)
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should set the prev relation for the new subsection to its parent's old last item" do
|
165
|
-
expect(referenced_object(@subsection[:Prev])).to eq(@page_2)
|
166
|
-
end
|
167
|
-
|
168
|
-
it "the subsection should become the next relation for its parent's old last item" do
|
169
|
-
expect(referenced_object(@page_2[:Next])).to eq(@subsection)
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should set the first relation for the new subsection" do
|
173
|
-
expect(referenced_object(@subsection[:First])).to eq(@added_page_3)
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should set the correct last relation of the added to section" do
|
177
|
-
expect(referenced_object(@subsection[:Last])).to eq(@added_page_3)
|
178
|
-
end
|
179
|
-
|
180
|
-
it "should increase the count of root outline dictionary" do
|
181
|
-
expect(@outline_root[:Count]).to eq(5)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
context "positioned first" do
|
186
|
-
before(:each) do
|
187
|
-
@pdf.start_new_page
|
188
|
-
@pdf.text "Page 3. An added subsection "
|
189
|
-
@pdf.outline.update do
|
190
|
-
add_subsection_to 'Chapter 1', :first do
|
191
|
-
section 'Added SubSection', :destination => 3 do
|
192
|
-
page :destination => 3, :title => 'Added Page 3'
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
render_and_find_objects
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should add new outline items to document" do
|
200
|
-
[@subsection, @added_page_3].each { |item| expect(item).not_to be_nil }
|
201
|
-
end
|
202
|
-
|
203
|
-
it "should reset the first item for parent item dictionary" do
|
204
|
-
expect(referenced_object(@section_1[:First])).to eq(@subsection)
|
205
|
-
expect(referenced_object(@section_1[:Last])).to eq(@page_2)
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should set the next relation for the new subsection to its parent's old first item" do
|
209
|
-
expect(referenced_object(@subsection[:Next])).to eq(@page_1)
|
210
|
-
end
|
211
|
-
|
212
|
-
it "the subsection should become the prev relation for its parent's old first item" do
|
213
|
-
expect(referenced_object(@page_1[:Prev])).to eq(@subsection)
|
214
|
-
end
|
215
|
-
|
216
|
-
it "should set the first relation for the new subsection" do
|
217
|
-
expect(referenced_object(@subsection[:First])).to eq(@added_page_3)
|
218
|
-
end
|
219
|
-
|
220
|
-
it "should set the correct last relation of the added to section" do
|
221
|
-
expect(referenced_object(@subsection[:Last])).to eq(@added_page_3)
|
222
|
-
end
|
223
|
-
|
224
|
-
it "should increase the count of root outline dictionary" do
|
225
|
-
expect(@outline_root[:Count]).to eq(5)
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
it "should require an existing title" do
|
230
|
-
expect do
|
231
|
-
@pdf.go_to_page 1
|
232
|
-
@pdf.start_new_page
|
233
|
-
@pdf.text "Inserted Page"
|
234
|
-
@pdf.outline.update do
|
235
|
-
add_subsection_to 'Wrong page' do
|
236
|
-
page page_number, :title => "Inserted Page"
|
237
|
-
end
|
238
|
-
end
|
239
|
-
render_and_find_objects
|
240
|
-
end.to raise_error(Prawn::Errors::UnknownOutlineTitle)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
describe "#outline.insert_section_after" do
|
245
|
-
describe "inserting in the middle of another section" do
|
246
|
-
before(:each) do
|
247
|
-
@pdf.go_to_page 1
|
248
|
-
@pdf.start_new_page
|
249
|
-
@pdf.text "Inserted Page"
|
250
|
-
@pdf.outline.update do
|
251
|
-
insert_section_after 'Page 1' do
|
252
|
-
page :destination => page_number, :title => "Inserted Page"
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
it "should insert new outline items to document" do
|
258
|
-
render_and_find_objects
|
259
|
-
expect(@inserted_page).not_to be_nil
|
260
|
-
end
|
261
|
-
|
262
|
-
it "should adjust the count of all ancestors" do
|
263
|
-
render_and_find_objects
|
264
|
-
expect(@outline_root[:Count]).to eq(4)
|
265
|
-
expect(@section_1[:Count].abs).to eq(3)
|
266
|
-
end
|
267
|
-
|
268
|
-
describe "#adjust_relations" do
|
269
|
-
it "should reset the sibling relations of adjoining items to inserted item" do
|
270
|
-
render_and_find_objects
|
271
|
-
expect(referenced_object(@page_1[:Next])).to eq(@inserted_page)
|
272
|
-
expect(referenced_object(@page_2[:Prev])).to eq(@inserted_page)
|
273
|
-
end
|
274
|
-
|
275
|
-
it "should set the sibling relation of added item to adjoining items" do
|
276
|
-
render_and_find_objects
|
277
|
-
expect(referenced_object(@inserted_page[:Next])).to eq(@page_2)
|
278
|
-
expect(referenced_object(@inserted_page[:Prev])).to eq(@page_1)
|
279
|
-
end
|
280
|
-
|
281
|
-
it "should not affect the first and last relations of parent item" do
|
282
|
-
render_and_find_objects
|
283
|
-
expect(referenced_object(@section_1[:First])).to eq(@page_1)
|
284
|
-
expect(referenced_object(@section_1[:Last])).to eq(@page_2)
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
context "when adding another section afterwards" do
|
289
|
-
it "should have reset the root position so that a new section is added at the end of root sections" do
|
290
|
-
@pdf.start_new_page
|
291
|
-
@pdf.text "Another Inserted Page"
|
292
|
-
@pdf.outline.update do
|
293
|
-
section 'Added Section' do
|
294
|
-
page :destination => page_number, :title => "Inserted Page"
|
295
|
-
end
|
296
|
-
end
|
297
|
-
render_and_find_objects
|
298
|
-
expect(referenced_object(@outline_root[:Last])).to eq(@section_2)
|
299
|
-
expect(referenced_object(@section_1[:Next])).to eq(@section_2)
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
describe "inserting at the end of another section" do
|
305
|
-
before(:each) do
|
306
|
-
@pdf.go_to_page 2
|
307
|
-
@pdf.start_new_page
|
308
|
-
@pdf.text "Inserted Page"
|
309
|
-
@pdf.outline.update do
|
310
|
-
insert_section_after 'Page 2' do
|
311
|
-
page :destination => page_number, :title => "Inserted Page"
|
312
|
-
end
|
313
|
-
end
|
314
|
-
render_and_find_objects
|
315
|
-
end
|
316
|
-
|
317
|
-
describe "#adjust_relations" do
|
318
|
-
it "should reset the sibling relations of adjoining item to inserted item" do
|
319
|
-
expect(referenced_object(@page_2[:Next])).to eq(@inserted_page)
|
320
|
-
end
|
321
|
-
|
322
|
-
it "should set the sibling relation of added item to adjoining items" do
|
323
|
-
expect(referenced_object(@inserted_page[:Next])).to be_nil
|
324
|
-
expect(referenced_object(@inserted_page[:Prev])).to eq(@page_2)
|
325
|
-
end
|
326
|
-
|
327
|
-
it "should adjust the last relation of parent item" do
|
328
|
-
expect(referenced_object(@section_1[:Last])).to eq(@inserted_page)
|
329
|
-
end
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
it "should require an existing title" do
|
334
|
-
expect do
|
335
|
-
@pdf.go_to_page 1
|
336
|
-
@pdf.start_new_page
|
337
|
-
@pdf.text "Inserted Page"
|
338
|
-
@pdf.outline.update do
|
339
|
-
insert_section_after 'Wrong page' do
|
340
|
-
page :destination => page_number, :title => "Inserted Page"
|
341
|
-
end
|
342
|
-
end
|
343
|
-
render_and_find_objects
|
344
|
-
end.to raise_error(Prawn::Errors::UnknownOutlineTitle)
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
describe "#page" do
|
349
|
-
it "should require a title option to be set" do
|
350
|
-
expect do
|
351
|
-
@pdf = Prawn::Document.new do
|
352
|
-
text "Page 1. This is the first Chapter. "
|
353
|
-
outline.define do
|
354
|
-
page :destination => 1, :title => nil
|
355
|
-
end
|
356
|
-
end
|
357
|
-
end.to raise_error(Prawn::Errors::RequiredOption)
|
358
|
-
end
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
describe "foreign character encoding" do
|
363
|
-
before(:each) do
|
364
|
-
pdf = Prawn::Document.new do
|
365
|
-
outline.define do
|
366
|
-
section 'La pomme croquée', :destination => 1, :closed => true
|
367
|
-
end
|
368
|
-
end
|
369
|
-
@hash = PDF::Reader::ObjectHash.new(StringIO.new(pdf.render, 'r+'))
|
370
|
-
end
|
371
|
-
|
372
|
-
it "should handle other encodings for the title" do
|
373
|
-
object = find_by_title('La pomme croquée')
|
374
|
-
expect(object).not_to be_nil
|
375
|
-
end
|
376
|
-
end
|
377
|
-
|
378
|
-
def render_and_find_objects
|
379
|
-
output = StringIO.new(@pdf.render, 'r+')
|
380
|
-
@hash = PDF::Reader::ObjectHash.new(output)
|
381
|
-
@outline_root = @hash.values.find { |obj| obj.is_a?(Hash) && obj[:Type] == :Outlines }
|
382
|
-
@pages = @hash.values.find { |obj| obj.is_a?(Hash) && obj[:Type] == :Pages }[:Kids]
|
383
|
-
@section_1 = find_by_title('Chapter 1')
|
384
|
-
@page_1 = find_by_title('Page 1')
|
385
|
-
@page_2 = find_by_title('Page 2')
|
386
|
-
@section_2 = find_by_title('Added Section')
|
387
|
-
@page_3 = find_by_title('Page 3')
|
388
|
-
@inserted_page = find_by_title('Inserted Page')
|
389
|
-
@subsection = find_by_title('Added SubSection')
|
390
|
-
@added_page_3 = find_by_title('Added Page 3')
|
391
|
-
@custom_dest = find_by_title('Custom Destination')
|
392
|
-
end
|
393
|
-
|
394
|
-
# Outline titles are stored as UTF-16. This method accepts a UTF-8 outline title
|
395
|
-
# and returns the PDF Object that contains an outline with that name
|
396
|
-
def find_by_title(title)
|
397
|
-
@hash.values.find {|obj|
|
398
|
-
if obj.is_a?(Hash) && obj[:Title]
|
399
|
-
title_codepoints = obj[:Title].unpack("n*")
|
400
|
-
title_codepoints.shift
|
401
|
-
utf8_title = title_codepoints.pack("U*")
|
402
|
-
utf8_title == title ? obj : nil
|
403
|
-
end
|
404
|
-
}
|
405
|
-
end
|
406
|
-
|
407
|
-
def referenced_object(reference)
|
408
|
-
@hash[reference]
|
409
|
-
end
|