prawn 2.0.1 → 2.0.2
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 +4 -4
- data/Rakefile +7 -5
- data/lib/prawn.rb +4 -4
- data/lib/prawn/document.rb +47 -46
- data/lib/prawn/document/bounding_box.rb +13 -19
- data/lib/prawn/document/column_box.rb +3 -5
- data/lib/prawn/document/internals.rb +0 -1
- data/lib/prawn/document/span.rb +12 -12
- data/lib/prawn/errors.rb +32 -33
- data/lib/prawn/font.rb +29 -36
- data/lib/prawn/font/afm.rb +20 -20
- data/lib/prawn/font/dfont.rb +0 -1
- data/lib/prawn/font/ttf.rb +30 -27
- data/lib/prawn/font_metric_cache.rb +4 -8
- data/lib/prawn/graphics.rb +37 -42
- data/lib/prawn/graphics/cap_style.rb +1 -1
- data/lib/prawn/graphics/color.rb +21 -23
- data/lib/prawn/graphics/dash.rb +5 -6
- data/lib/prawn/graphics/join_style.rb +1 -2
- data/lib/prawn/graphics/patterns.rb +25 -21
- data/lib/prawn/graphics/transformation.rb +4 -5
- data/lib/prawn/graphics/transparency.rb +6 -8
- data/lib/prawn/grid.rb +21 -14
- data/lib/prawn/image_handler.rb +2 -2
- data/lib/prawn/images.rb +29 -31
- data/lib/prawn/images/image.rb +1 -1
- data/lib/prawn/images/jpg.rb +10 -12
- data/lib/prawn/images/png.rb +13 -13
- data/lib/prawn/measurements.rb +7 -14
- data/lib/prawn/outline.rb +6 -6
- data/lib/prawn/repeater.rb +1 -5
- data/lib/prawn/security.rb +17 -25
- data/lib/prawn/security/arcfour.rb +1 -1
- data/lib/prawn/soft_mask.rb +11 -12
- data/lib/prawn/stamp.rb +16 -8
- data/lib/prawn/text.rb +23 -20
- data/lib/prawn/text/box.rb +3 -6
- data/lib/prawn/text/formatted/arranger.rb +9 -12
- data/lib/prawn/text/formatted/box.rb +23 -22
- data/lib/prawn/text/formatted/fragment.rb +0 -4
- data/lib/prawn/text/formatted/line_wrap.rb +13 -24
- data/lib/prawn/text/formatted/parser.rb +16 -20
- data/lib/prawn/text/formatted/wrap.rb +2 -7
- data/lib/prawn/utilities.rb +6 -3
- data/lib/prawn/version.rb +1 -1
- data/manual/basic_concepts/basic_concepts.rb +0 -2
- data/manual/basic_concepts/view.rb +1 -1
- data/manual/bounding_box/bounding_box.rb +0 -3
- data/manual/bounding_box/russian_boxes.rb +7 -8
- data/manual/bounding_box/stretchy.rb +0 -1
- data/manual/contents.rb +2 -2
- data/manual/cover.rb +11 -12
- data/manual/document_and_page_options/document_and_page_options.rb +2 -5
- data/manual/document_and_page_options/metadata.rb +10 -10
- data/manual/document_and_page_options/page_size.rb +0 -1
- data/manual/graphics/fill_rules.rb +5 -4
- data/manual/graphics/graphics.rb +0 -3
- data/manual/graphics/lines_and_curves.rb +1 -1
- data/manual/graphics/rotate.rb +0 -2
- data/manual/graphics/scale.rb +4 -2
- data/manual/graphics/soft_masks.rb +0 -1
- data/manual/graphics/stroke_cap.rb +1 -1
- data/manual/graphics/stroke_join.rb +1 -1
- data/manual/graphics/translate.rb +3 -3
- data/manual/graphics/transparency.rb +0 -1
- data/manual/how_to_read_this_manual.rb +0 -1
- data/manual/images/images.rb +0 -3
- data/manual/layout/boxes.rb +5 -5
- data/manual/layout/content.rb +2 -2
- data/manual/layout/layout.rb +0 -3
- data/manual/outline/outline.rb +0 -3
- data/manual/repeatable_content/page_numbering.rb +1 -1
- data/manual/repeatable_content/repeatable_content.rb +0 -3
- data/manual/repeatable_content/repeater.rb +6 -6
- data/manual/security/encryption.rb +0 -2
- data/manual/security/permissions.rb +0 -2
- data/manual/security/security.rb +0 -3
- data/manual/text/alignment.rb +3 -3
- data/manual/text/color.rb +0 -1
- data/manual/text/column_box.rb +0 -1
- data/manual/text/fallback_fonts.rb +2 -2
- data/manual/text/formatted_callbacks.rb +3 -2
- data/manual/text/paragraph_indentation.rb +2 -3
- data/manual/text/registering_families.rb +13 -9
- data/manual/text/rotation.rb +0 -1
- data/manual/text/text.rb +0 -3
- data/manual/text/text_box_overflow.rb +7 -5
- data/manual/text/utf8.rb +1 -1
- data/manual/text/win_ansi_charset.rb +2 -2
- data/prawn.gemspec +4 -4
- data/spec/acceptance/png.rb +6 -7
- data/spec/annotations_spec.rb +21 -28
- data/spec/bounding_box_spec.rb +100 -109
- data/spec/column_box_spec.rb +26 -32
- data/spec/destinations_spec.rb +2 -4
- data/spec/document_spec.rb +145 -151
- data/spec/extensions/mocha.rb +0 -1
- data/spec/font_metric_cache_spec.rb +7 -7
- data/spec/font_spec.rb +103 -102
- data/spec/formatted_text_arranger_spec.rb +76 -74
- data/spec/formatted_text_box_spec.rb +170 -159
- data/spec/formatted_text_fragment_spec.rb +57 -56
- data/spec/graphics_spec.rb +158 -175
- data/spec/grid_spec.rb +28 -29
- data/spec/image_handler_spec.rb +4 -5
- data/spec/images_spec.rb +50 -36
- data/spec/inline_formatted_text_parser_spec.rb +397 -393
- data/spec/jpg_spec.rb +4 -6
- data/spec/line_wrap_spec.rb +54 -55
- data/spec/measurement_units_spec.rb +12 -15
- data/spec/outline_spec.rb +77 -98
- data/spec/png_spec.rb +55 -65
- data/spec/reference_spec.rb +3 -3
- data/spec/repeater_spec.rb +20 -26
- data/spec/security_spec.rb +42 -49
- data/spec/soft_mask_spec.rb +4 -5
- data/spec/span_spec.rb +5 -6
- data/spec/spec_helper.rb +2 -4
- data/spec/stamp_spec.rb +41 -22
- data/spec/stroke_styles_spec.rb +36 -39
- data/spec/text_at_spec.rb +28 -29
- data/spec/text_box_spec.rb +160 -165
- data/spec/text_rendering_mode_spec.rb +9 -9
- data/spec/text_spacing_spec.rb +13 -13
- data/spec/text_spec.rb +116 -124
- data/spec/text_with_inline_formatting_spec.rb +5 -5
- data/spec/transparency_spec.rb +20 -20
- data/spec/view_spec.rb +0 -1
- metadata +7 -7
@@ -5,20 +5,20 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
|
5
5
|
describe "Text::Formatted::Fragment#space_count" do
|
6
6
|
it "should return the number of spaces in the fragment" do
|
7
7
|
create_pdf
|
8
|
-
format_state = {
|
8
|
+
format_state = {}
|
9
9
|
fragment = Prawn::Text::Formatted::Fragment.new("hello world ",
|
10
|
-
|
11
|
-
|
12
|
-
fragment.space_count.
|
10
|
+
format_state,
|
11
|
+
@pdf)
|
12
|
+
expect(fragment.space_count).to eq(2)
|
13
13
|
end
|
14
|
-
it "should exclude trailing spaces from the count when "
|
14
|
+
it "should exclude trailing spaces from the count when " \
|
15
15
|
":exclude_trailing_white_space => true" do
|
16
16
|
create_pdf
|
17
17
|
format_state = { :exclude_trailing_white_space => true }
|
18
18
|
fragment = Prawn::Text::Formatted::Fragment.new("hello world ",
|
19
|
-
|
20
|
-
|
21
|
-
fragment.space_count.
|
19
|
+
format_state,
|
20
|
+
@pdf)
|
21
|
+
expect(fragment.space_count).to eq(1)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -27,31 +27,31 @@ describe "Text::Formatted::Fragment#include_trailing_white_space!" do
|
|
27
27
|
create_pdf
|
28
28
|
format_state = { :exclude_trailing_white_space => true }
|
29
29
|
fragment = Prawn::Text::Formatted::Fragment.new("hello world ",
|
30
|
-
|
31
|
-
|
32
|
-
fragment.space_count.
|
30
|
+
format_state,
|
31
|
+
@pdf)
|
32
|
+
expect(fragment.space_count).to eq(1)
|
33
33
|
fragment.include_trailing_white_space!
|
34
|
-
fragment.space_count.
|
34
|
+
expect(fragment.space_count).to eq(2)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "Text::Formatted::Fragment#text" do
|
39
39
|
it "should return the fragment text" do
|
40
40
|
create_pdf
|
41
|
-
format_state = {
|
41
|
+
format_state = {}
|
42
42
|
fragment = Prawn::Text::Formatted::Fragment.new("hello world ",
|
43
|
-
|
44
|
-
|
45
|
-
fragment.text.
|
43
|
+
format_state,
|
44
|
+
@pdf)
|
45
|
+
expect(fragment.text).to eq("hello world ")
|
46
46
|
end
|
47
|
-
it "should return the fragment text without trailing spaces when "
|
47
|
+
it "should return the fragment text without trailing spaces when " \
|
48
48
|
":exclude_trailing_white_space => true" do
|
49
49
|
create_pdf
|
50
50
|
format_state = { :exclude_trailing_white_space => true }
|
51
51
|
fragment = Prawn::Text::Formatted::Fragment.new("hello world ",
|
52
|
-
|
53
|
-
|
54
|
-
fragment.text.
|
52
|
+
format_state,
|
53
|
+
@pdf)
|
54
|
+
expect(fragment.text).to eq("hello world")
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -77,11 +77,11 @@ describe "Text::Formatted::Fragment#word_spacing=" do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should account for word_spacing in #width" do
|
80
|
-
@fragment.width.
|
80
|
+
expect(@fragment.width).to eq(110)
|
81
81
|
end
|
82
82
|
it "should account for word_spacing in #bounding_box" do
|
83
83
|
target_box = [50, 193, 160, 217]
|
84
|
-
@fragment.bounding_box.
|
84
|
+
expect(@fragment.bounding_box).to eq(target_box)
|
85
85
|
end
|
86
86
|
it "should account for word_spacing in #absolute_bounding_box" do
|
87
87
|
target_box = [50, 193, 160, 217]
|
@@ -89,17 +89,17 @@ describe "Text::Formatted::Fragment#word_spacing=" do
|
|
89
89
|
target_box[1] += @pdf.bounds.absolute_bottom
|
90
90
|
target_box[2] += @pdf.bounds.absolute_left
|
91
91
|
target_box[3] += @pdf.bounds.absolute_bottom
|
92
|
-
@fragment.absolute_bounding_box.
|
92
|
+
expect(@fragment.absolute_bounding_box).to eq(target_box)
|
93
93
|
end
|
94
94
|
it "should account for word_spacing in #underline_points" do
|
95
95
|
y = 198.75
|
96
96
|
target_points = [[50, y], [160, y]]
|
97
|
-
@fragment.underline_points.
|
97
|
+
expect(@fragment.underline_points).to eq(target_points)
|
98
98
|
end
|
99
99
|
it "should account for word_spacing in #strikethrough_points" do
|
100
100
|
y = 200 + @fragment.ascender * 0.3
|
101
101
|
target_points = [[50, y], [160, y]]
|
102
|
-
@fragment.strikethrough_points.
|
102
|
+
expect(@fragment.strikethrough_points).to eq(target_points)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
@@ -125,13 +125,13 @@ describe "Text::Formatted::Fragment" do
|
|
125
125
|
|
126
126
|
describe "#width" do
|
127
127
|
it "should return the width" do
|
128
|
-
@fragment.width.
|
128
|
+
expect(@fragment.width).to eq(100)
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
132
|
describe "#styles" do
|
133
133
|
it "should return the styles array" do
|
134
|
-
@fragment.styles.
|
134
|
+
expect(@fragment.styles).to eq([:bold, :italic])
|
135
135
|
end
|
136
136
|
it "should never return nil" do
|
137
137
|
format_state = { :styles => nil,
|
@@ -143,50 +143,51 @@ describe "Text::Formatted::Fragment" do
|
|
143
143
|
fragment = Prawn::Text::Formatted::Fragment.new("hello world",
|
144
144
|
format_state,
|
145
145
|
@pdf)
|
146
|
-
fragment.styles.
|
146
|
+
expect(fragment.styles).to eq([])
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
150
|
describe "#line_height" do
|
151
151
|
it "should return the line_height" do
|
152
|
-
@fragment.line_height.
|
152
|
+
expect(@fragment.line_height).to eq(27)
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
156
|
describe "#ascender" do
|
157
157
|
it "should return the ascender" do
|
158
|
-
@fragment.ascender.
|
158
|
+
expect(@fragment.ascender).to eq(17)
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
162
162
|
describe "#descender" do
|
163
163
|
it "should return the descender" do
|
164
|
-
@fragment.descender.
|
164
|
+
expect(@fragment.descender).to eq(7)
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
168
|
describe "#y_offset" do
|
169
169
|
it "should be zero" do
|
170
|
-
@fragment.y_offset.
|
170
|
+
expect(@fragment.y_offset).to eq(0)
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
174
|
describe "#bounding_box" do
|
175
175
|
it "should return the bounding box surrounding the fragment" do
|
176
176
|
target_box = [50, 193, 150, 217]
|
177
|
-
@fragment.bounding_box.
|
177
|
+
expect(@fragment.bounding_box).to eq(target_box)
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
181
181
|
describe "#absolute_bounding_box" do
|
182
|
-
it "should return the bounding box surrounding the fragment"
|
182
|
+
it "should return the bounding box surrounding the fragment" \
|
183
183
|
" in absolute coordinates" do
|
184
184
|
target_box = [50, 193, 150, 217]
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
185
|
+
target_box[0] += @pdf.bounds.absolute_left
|
186
|
+
target_box[1] += @pdf.bounds.absolute_bottom
|
187
|
+
target_box[2] += @pdf.bounds.absolute_left
|
188
|
+
target_box[3] += @pdf.bounds.absolute_bottom
|
189
|
+
|
190
|
+
expect(@fragment.absolute_bounding_box).to eq(target_box)
|
190
191
|
end
|
191
192
|
end
|
192
193
|
|
@@ -194,7 +195,7 @@ describe "Text::Formatted::Fragment" do
|
|
194
195
|
it "should define a line under the fragment" do
|
195
196
|
y = 198.75
|
196
197
|
target_points = [[50, y], [150, y]]
|
197
|
-
@fragment.underline_points.
|
198
|
+
expect(@fragment.underline_points).to eq(target_points)
|
198
199
|
end
|
199
200
|
end
|
200
201
|
|
@@ -202,7 +203,7 @@ describe "Text::Formatted::Fragment" do
|
|
202
203
|
it "should define a line through the fragment" do
|
203
204
|
y = 200 + @fragment.ascender * 0.3
|
204
205
|
target_points = [[50, y], [150, y]]
|
205
|
-
@fragment.strikethrough_points.
|
206
|
+
expect(@fragment.strikethrough_points).to eq(target_points)
|
206
207
|
end
|
207
208
|
end
|
208
209
|
end
|
@@ -225,12 +226,12 @@ describe "Text::Formatted::Fragment that is a subscript" do
|
|
225
226
|
end
|
226
227
|
describe "#subscript?" do
|
227
228
|
it "should be_true" do
|
228
|
-
@fragment.
|
229
|
+
expect(@fragment).to be_subscript
|
229
230
|
end
|
230
231
|
end
|
231
232
|
describe "#y_offset" do
|
232
233
|
it "should return a negative value" do
|
233
|
-
@fragment.y_offset.
|
234
|
+
expect(@fragment.y_offset).to be < 0
|
234
235
|
end
|
235
236
|
end
|
236
237
|
end
|
@@ -253,12 +254,12 @@ describe "Text::Formatted::Fragment that is a superscript" do
|
|
253
254
|
end
|
254
255
|
describe "#superscript?" do
|
255
256
|
it "should be_true" do
|
256
|
-
@fragment.
|
257
|
+
expect(@fragment).to be_superscript
|
257
258
|
end
|
258
259
|
end
|
259
260
|
describe "#y_offset" do
|
260
261
|
it "should return a positive value" do
|
261
|
-
@fragment.y_offset.
|
262
|
+
expect(@fragment.y_offset).to be > 0
|
262
263
|
end
|
263
264
|
end
|
264
265
|
end
|
@@ -268,31 +269,31 @@ describe "Text::Formatted::Fragment with :direction => :rtl" do
|
|
268
269
|
create_pdf
|
269
270
|
format_state = { :direction => :rtl }
|
270
271
|
fragment = Prawn::Text::Formatted::Fragment.new("hello world",
|
271
|
-
|
272
|
-
|
273
|
-
fragment.text.
|
272
|
+
format_state,
|
273
|
+
@pdf)
|
274
|
+
expect(fragment.text).to eq("dlrow olleh")
|
274
275
|
end
|
275
276
|
end
|
276
277
|
|
277
278
|
describe "Text::Formatted::Fragment default_direction=" do
|
278
|
-
it "should set the direction if there is no fragment level direction "
|
279
|
+
it "should set the direction if there is no fragment level direction " \
|
279
280
|
"specification" do
|
280
281
|
create_pdf
|
281
|
-
format_state = {
|
282
|
+
format_state = {}
|
282
283
|
fragment = Prawn::Text::Formatted::Fragment.new("hello world",
|
283
|
-
|
284
|
-
|
284
|
+
format_state,
|
285
|
+
@pdf)
|
285
286
|
fragment.default_direction = :rtl
|
286
|
-
fragment.direction.
|
287
|
+
expect(fragment.direction).to eq(:rtl)
|
287
288
|
end
|
288
|
-
it "should not set the direction if there is a fragment level direction "
|
289
|
+
it "should not set the direction if there is a fragment level direction " \
|
289
290
|
"specification" do
|
290
291
|
create_pdf
|
291
292
|
format_state = { :direction => :rtl }
|
292
293
|
fragment = Prawn::Text::Formatted::Fragment.new("hello world",
|
293
|
-
|
294
|
+
format_state,
|
294
295
|
@pdf)
|
295
296
|
fragment.default_direction = :ltr
|
296
|
-
fragment.direction.
|
297
|
+
expect(fragment.direction).to eq(:rtl)
|
297
298
|
end
|
298
299
|
end
|
data/spec/graphics_spec.rb
CHANGED
@@ -3,126 +3,116 @@
|
|
3
3
|
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
4
|
|
5
5
|
describe "When drawing a line" do
|
6
|
-
|
7
6
|
before(:each) { create_pdf }
|
8
7
|
|
9
8
|
it "should draw a line from (100,600) to (100,500)" do
|
10
|
-
@pdf.line([100,600],[100,500])
|
9
|
+
@pdf.line([100, 600], [100, 500])
|
11
10
|
|
12
11
|
line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
13
12
|
|
14
|
-
line_drawing.points.
|
13
|
+
expect(line_drawing.points).to eq([[100, 600], [100, 500]])
|
15
14
|
end
|
16
15
|
|
17
|
-
it "should draw two lines at (100,600) to (100,500) "
|
16
|
+
it "should draw two lines at (100,600) to (100,500) " \
|
18
17
|
"and (75,100) to (50,125)" do
|
19
|
-
@pdf.line(100,600,100,500)
|
20
|
-
@pdf.line(75,100,50,125)
|
18
|
+
@pdf.line(100, 600, 100, 500)
|
19
|
+
@pdf.line(75, 100, 50, 125)
|
21
20
|
|
22
21
|
line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
23
22
|
|
24
|
-
line_drawing.points.
|
23
|
+
expect(line_drawing.points).to eq(
|
25
24
|
[[100.0, 600.0], [100.0, 500.0], [75.0, 100.0], [50.0, 125.0]]
|
25
|
+
)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should properly set line width via line_width=" do
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
@pdf.line_width = 10
|
30
|
+
line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
31
|
+
expect(line.widths.first).to eq(10)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should properly set line width via line_width(width)" do
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
@pdf.line_width(10)
|
36
|
+
line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
37
|
+
expect(line.widths.first).to eq(10)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should carry the current line width settings over to new pages" do
|
41
41
|
@pdf.line_width(10)
|
42
42
|
@pdf.start_new_page
|
43
43
|
line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
44
|
-
line.widths.length.
|
45
|
-
line.widths[1].
|
44
|
+
expect(line.widths.length).to eq(2)
|
45
|
+
expect(line.widths[1]).to eq(10)
|
46
46
|
end
|
47
47
|
|
48
48
|
describe "(Horizontally)" do
|
49
49
|
it "should draw from [x1,pdf.y],[x2,pdf.y]" do
|
50
|
-
@pdf.horizontal_line(100,150)
|
50
|
+
@pdf.horizontal_line(100, 150)
|
51
51
|
@line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
52
|
-
@line.points.
|
53
|
-
|
52
|
+
expect(@line.points).to eq([[100.0 + @pdf.bounds.absolute_left, @pdf.y],
|
53
|
+
[150.0 + @pdf.bounds.absolute_left, @pdf.y]])
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should draw a line from (200, 250) to (300, 250)" do
|
57
|
-
@pdf.horizontal_line(200,300
|
57
|
+
@pdf.horizontal_line(200, 300, :at => 250)
|
58
58
|
line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
59
|
-
line_drawing.points.
|
59
|
+
expect(line_drawing.points).to eq([[200, 250], [300, 250]])
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
describe "(Vertically)" do
|
64
64
|
it "should draw a line from (350, 300) to (350, 400)" do
|
65
|
-
@pdf.vertical_line(300,400
|
65
|
+
@pdf.vertical_line(300, 400, :at => 350)
|
66
66
|
line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
67
|
-
line_drawing.points.
|
67
|
+
expect(line_drawing.points).to eq([[350, 300], [350, 400]])
|
68
68
|
end
|
69
69
|
it "should require a y coordinate" do
|
70
|
-
|
71
|
-
|
70
|
+
expect { @pdf.vertical_line(400, 500) }.
|
71
|
+
to raise_error(ArgumentError)
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
75
74
|
end
|
76
75
|
|
77
76
|
describe "When drawing a polygon" do
|
78
|
-
|
79
77
|
before(:each) { create_pdf }
|
80
78
|
|
81
79
|
it "should draw each line passed to polygon()" do
|
82
|
-
@pdf.polygon([100,500],[100,400],[200,400])
|
80
|
+
@pdf.polygon([100, 500], [100, 400], [200, 400])
|
83
81
|
|
84
82
|
line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
85
|
-
line_drawing.points.
|
83
|
+
expect(line_drawing.points).to eq([[100, 500], [100, 400], [200, 400], [100, 500]])
|
86
84
|
end
|
87
|
-
|
88
85
|
end
|
89
86
|
|
90
87
|
describe "When drawing a rectangle" do
|
91
|
-
|
92
88
|
before(:each) { create_pdf }
|
93
89
|
|
94
90
|
it "should use a point, width, and height for coords" do
|
95
|
-
@pdf.rectangle [200,200], 50, 100
|
91
|
+
@pdf.rectangle [200, 200], 50, 100
|
96
92
|
|
97
|
-
rectangles = PDF::Inspector::Graphics::Rectangle.
|
98
|
-
analyze(@pdf.render).rectangles
|
93
|
+
rectangles = PDF::Inspector::Graphics::Rectangle.analyze(@pdf.render).rectangles
|
99
94
|
# PDF uses bottom left corner
|
100
|
-
rectangles[0][:point].
|
101
|
-
rectangles[0][:width].
|
102
|
-
rectangles[0][:height].
|
103
|
-
|
95
|
+
expect(rectangles[0][:point]).to eq([200, 100])
|
96
|
+
expect(rectangles[0][:width]).to eq(50)
|
97
|
+
expect(rectangles[0][:height]).to eq(100)
|
104
98
|
end
|
105
|
-
|
106
99
|
end
|
107
100
|
|
108
101
|
describe "When drawing a curve" do
|
109
|
-
|
110
102
|
before(:each) { create_pdf }
|
111
103
|
|
112
104
|
it "should draw a bezier curve from 50,50 to 100,100" do
|
113
|
-
@pdf.move_to
|
114
|
-
@pdf.curve_to [100,100]
|
105
|
+
@pdf.move_to [50, 50]
|
106
|
+
@pdf.curve_to [100, 100], :bounds => [[20, 90], [90, 70]]
|
115
107
|
curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
116
|
-
curve.coords.
|
108
|
+
expect(curve.coords).to eq([50.0, 50.0, 20.0, 90.0, 90.0, 70.0, 100.0, 100.0])
|
117
109
|
end
|
118
110
|
|
119
111
|
it "should draw a bezier curve from 100,100 to 50,50" do
|
120
|
-
@pdf.curve [100,100], [50,50], :bounds => [[20,90], [90,75]]
|
112
|
+
@pdf.curve [100, 100], [50, 50], :bounds => [[20, 90], [90, 75]]
|
121
113
|
curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
122
|
-
curve.coords.
|
114
|
+
expect(curve.coords).to eq([100.0, 100.0, 20.0, 90.0, 90.0, 75.0, 50.0, 50.0])
|
123
115
|
end
|
124
|
-
|
125
|
-
|
126
116
|
end
|
127
117
|
|
128
118
|
describe "When drawing a rounded rectangle" do
|
@@ -131,42 +121,40 @@ describe "When drawing a rounded rectangle" do
|
|
131
121
|
@pdf.rounded_rectangle([50, 550], 50, 100, 10)
|
132
122
|
curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
133
123
|
curve_points = []
|
134
|
-
curve.coords.each_slice(2) {|p| curve_points << p}
|
124
|
+
curve.coords.each_slice(2) { |p| curve_points << p }
|
135
125
|
@original_point = curve_points.shift
|
136
126
|
curves = []
|
137
|
-
curve_points.each_slice(3) {|c| curves << c}
|
127
|
+
curve_points.each_slice(3) { |c| curves << c }
|
138
128
|
line_points = PDF::Inspector::Graphics::Line.analyze(@pdf.render).points
|
139
129
|
line_points.shift
|
140
130
|
@all_coords = []
|
141
|
-
line_points.zip(curves).flatten.each_slice(2) {|p| @all_coords << p }
|
131
|
+
line_points.zip(curves).flatten.each_slice(2) { |p| @all_coords << p }
|
142
132
|
@all_coords.unshift @original_point
|
143
133
|
end
|
144
134
|
|
145
135
|
it "should draw a rectangle by connecting lines with rounded bezier curves" do
|
146
|
-
@all_coords.
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
136
|
+
expect(@all_coords).to eq([[60.0, 550.0], [90.0, 550.0], [95.5228, 550.0],
|
137
|
+
[100.0, 545.5228], [100.0, 540.0], [100.0, 460.0],
|
138
|
+
[100.0, 454.4772], [95.5228, 450.0], [90.0, 450.0],
|
139
|
+
[60.0, 450.0], [54.4772, 450.0], [50.0, 454.4772],
|
140
|
+
[50.0, 460.0], [50.0, 540.0], [50.0, 545.5228],
|
141
|
+
[54.4772, 550.0], [60.0, 550.0]])
|
152
142
|
end
|
153
143
|
|
154
144
|
it "should start and end with the same point" do
|
155
|
-
@original_point.
|
145
|
+
expect(@original_point).to eq(@all_coords.last)
|
156
146
|
end
|
157
|
-
|
158
|
-
|
159
147
|
end
|
160
148
|
|
161
149
|
describe "When drawing an ellipse" do
|
162
150
|
before(:each) do
|
163
151
|
create_pdf
|
164
|
-
@pdf.ellipse [100,100], 25, 50
|
152
|
+
@pdf.ellipse [100, 100], 25, 50
|
165
153
|
@curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
166
154
|
end
|
167
155
|
|
168
156
|
it "should use a Bézier approximation" do
|
169
|
-
@curve.coords.
|
157
|
+
expect(@curve.coords).to eq(
|
170
158
|
[125.0, 100.0,
|
171
159
|
|
172
160
|
125.0, 127.6142,
|
@@ -186,25 +174,25 @@ describe "When drawing an ellipse" do
|
|
186
174
|
125.0, 100.0,
|
187
175
|
|
188
176
|
100.0, 100.0]
|
177
|
+
)
|
189
178
|
end
|
190
179
|
|
191
180
|
it "should move the pointer to the center of the ellipse after drawing" do
|
192
|
-
@curve.coords[-2..-1].
|
181
|
+
expect(@curve.coords[-2..-1]).to eq([100, 100])
|
193
182
|
end
|
194
|
-
|
195
183
|
end
|
196
184
|
|
197
185
|
describe "When drawing a circle" do
|
198
186
|
before(:each) do
|
199
187
|
create_pdf
|
200
|
-
@pdf.circle [100,100], 25
|
201
|
-
@pdf.ellipse [100,100], 25, 25
|
188
|
+
@pdf.circle [100, 100], 25
|
189
|
+
@pdf.ellipse [100, 100], 25, 25
|
202
190
|
@curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
203
191
|
end
|
204
192
|
|
205
193
|
it "should stroke the same path as the equivalent ellipse" do
|
206
194
|
middle = @curve.coords.length / 2
|
207
|
-
@curve.coords[0...middle].
|
195
|
+
expect(@curve.coords[0...middle]).to eq(@curve.coords[middle..-1])
|
208
196
|
end
|
209
197
|
end
|
210
198
|
|
@@ -233,42 +221,35 @@ describe "When filling" do
|
|
233
221
|
end
|
234
222
|
|
235
223
|
describe "When setting colors" do
|
236
|
-
|
237
224
|
before(:each) { create_pdf }
|
238
225
|
|
239
226
|
it "should set stroke colors" do
|
240
227
|
@pdf.stroke_color "ffcccc"
|
241
228
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
242
229
|
# 100% red, 80% green, 80% blue
|
243
|
-
colors.stroke_color.
|
230
|
+
expect(colors.stroke_color).to eq([1.0, 0.8, 0.8])
|
244
231
|
end
|
245
232
|
|
246
233
|
it "should set fill colors" do
|
247
234
|
@pdf.fill_color "ccff00"
|
248
235
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
249
236
|
# 80% red, 100% green, 0% blue
|
250
|
-
colors.fill_color.
|
237
|
+
expect(colors.fill_color).to eq([0.8, 1.0, 0])
|
251
238
|
end
|
252
239
|
|
253
240
|
it "should reset the colors on each new page if they have been defined" do
|
254
241
|
@pdf.fill_color "ccff00"
|
255
|
-
#colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
256
242
|
|
257
|
-
# colors.fill_color_count.should == 2
|
258
|
-
# colors.stroke_color_count.should == 1
|
259
243
|
@pdf.start_new_page
|
260
244
|
@pdf.stroke_color "ff00cc"
|
261
245
|
|
262
|
-
#colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
263
|
-
# colors.fill_color_count.should == 3
|
264
|
-
|
265
246
|
@pdf.start_new_page
|
266
247
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
267
|
-
colors.fill_color_count.
|
268
|
-
colors.stroke_color_count.
|
248
|
+
expect(colors.fill_color_count).to eq(3)
|
249
|
+
expect(colors.stroke_color_count).to eq(2)
|
269
250
|
|
270
|
-
colors.fill_color.
|
271
|
-
colors.stroke_color.
|
251
|
+
expect(colors.fill_color).to eq([0.8, 1.0, 0.0])
|
252
|
+
expect(colors.stroke_color).to eq([1.0, 0.0, 0.8])
|
272
253
|
end
|
273
254
|
|
274
255
|
it "should set the color space when setting colors on new pages to please fussy readers" do
|
@@ -278,7 +259,7 @@ describe "When setting colors" do
|
|
278
259
|
@pdf.stroke_color "000000"
|
279
260
|
@pdf.stroke { @pdf.rectangle([10, 10], 10, 10) }
|
280
261
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
281
|
-
colors.stroke_color_space_count[:DeviceRGB].
|
262
|
+
expect(colors.stroke_color_space_count[:DeviceRGB]).to eq(2)
|
282
263
|
end
|
283
264
|
end
|
284
265
|
|
@@ -288,72 +269,78 @@ describe "Patterns" do
|
|
288
269
|
describe 'linear gradients' do
|
289
270
|
it "should create a /Pattern resource" do
|
290
271
|
@pdf.fill_gradient [0, @pdf.bounds.height],
|
291
|
-
|
272
|
+
[@pdf.bounds.width, @pdf.bounds.height],
|
273
|
+
'FF0000', '0000FF'
|
292
274
|
|
293
275
|
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
294
276
|
pattern = grad.patterns.values.first
|
295
277
|
|
296
|
-
pattern.
|
297
|
-
pattern[:Shading][:ShadingType].
|
298
|
-
pattern[:Shading][:Coords].
|
299
|
-
pattern[:Shading][:Function][:C0].zip([1, 0, 0]).all?{ |x1, x2|
|
300
|
-
(x1-x2).abs < 0.01
|
301
|
-
}.
|
302
|
-
pattern[:Shading][:Function][:C1].zip([0, 0, 1]).all?{ |x1, x2|
|
303
|
-
(x1-x2).abs < 0.01
|
304
|
-
}.
|
278
|
+
expect(pattern).not_to be_nil
|
279
|
+
expect(pattern[:Shading][:ShadingType]).to eq(2)
|
280
|
+
expect(pattern[:Shading][:Coords]).to eq([0, 0, @pdf.bounds.width, 0])
|
281
|
+
expect(pattern[:Shading][:Function][:C0].zip([1, 0, 0]).all?{ |x1, x2|
|
282
|
+
(x1 - x2).abs < 0.01
|
283
|
+
}).to be_true
|
284
|
+
expect(pattern[:Shading][:Function][:C1].zip([0, 0, 1]).all?{ |x1, x2|
|
285
|
+
(x1 - x2).abs < 0.01
|
286
|
+
}).to be_true
|
305
287
|
end
|
306
288
|
|
307
289
|
it "fill_gradient should set fill color to the pattern" do
|
308
290
|
@pdf.fill_gradient [0, @pdf.bounds.height],
|
309
|
-
|
291
|
+
[@pdf.bounds.width, @pdf.bounds.height],
|
292
|
+
'FF0000', '0000FF'
|
310
293
|
|
311
294
|
str = @pdf.render
|
312
|
-
str.
|
295
|
+
expect(str).to match(%r{/Pattern\s+cs\s*/SP-?\d+\s+scn})
|
313
296
|
end
|
314
297
|
|
315
298
|
it "stroke_gradient should set stroke color to the pattern" do
|
316
299
|
@pdf.stroke_gradient [0, @pdf.bounds.height],
|
317
|
-
|
300
|
+
[@pdf.bounds.width, @pdf.bounds.height],
|
301
|
+
'FF0000', '0000FF'
|
318
302
|
|
319
303
|
str = @pdf.render
|
320
|
-
str.
|
304
|
+
expect(str).to match(%r{/Pattern\s+CS\s*/SP-?\d+\s+SCN})
|
321
305
|
end
|
322
306
|
end
|
323
307
|
|
324
308
|
describe 'radial gradients' do
|
325
309
|
it "should create a /Pattern resource" do
|
326
310
|
@pdf.fill_gradient [0, @pdf.bounds.height], 10,
|
327
|
-
|
311
|
+
[@pdf.bounds.width, @pdf.bounds.height], 20,
|
312
|
+
'FF0000', '0000FF'
|
328
313
|
|
329
314
|
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
330
315
|
pattern = grad.patterns.values.first
|
331
316
|
|
332
|
-
pattern.
|
333
|
-
pattern[:Shading][:ShadingType].
|
334
|
-
pattern[:Shading][:Coords].
|
335
|
-
pattern[:Shading][:Function][:C0].zip([1, 0, 0]).all?{ |x1, x2|
|
336
|
-
(x1-x2).abs < 0.01
|
337
|
-
}.
|
338
|
-
pattern[:Shading][:Function][:C1].zip([0, 0, 1]).all?{ |x1, x2|
|
339
|
-
(x1-x2).abs < 0.01
|
340
|
-
}.
|
317
|
+
expect(pattern).not_to be_nil
|
318
|
+
expect(pattern[:Shading][:ShadingType]).to eq(3)
|
319
|
+
expect(pattern[:Shading][:Coords]).to eq([0, 0, 10, @pdf.bounds.width, 0, 20])
|
320
|
+
expect(pattern[:Shading][:Function][:C0].zip([1, 0, 0]).all?{ |x1, x2|
|
321
|
+
(x1 - x2).abs < 0.01
|
322
|
+
}).to be_true
|
323
|
+
expect(pattern[:Shading][:Function][:C1].zip([0, 0, 1]).all?{ |x1, x2|
|
324
|
+
(x1 - x2).abs < 0.01
|
325
|
+
}).to be_true
|
341
326
|
end
|
342
327
|
|
343
328
|
it "fill_gradient should set fill color to the pattern" do
|
344
329
|
@pdf.fill_gradient [0, @pdf.bounds.height], 10,
|
345
|
-
|
330
|
+
[@pdf.bounds.width, @pdf.bounds.height], 20,
|
331
|
+
'FF0000', '0000FF'
|
346
332
|
|
347
333
|
str = @pdf.render
|
348
|
-
str.
|
334
|
+
expect(str).to match(%r{/Pattern\s+cs\s*/SP-?\d+\s+scn})
|
349
335
|
end
|
350
336
|
|
351
337
|
it "stroke_gradient should set stroke color to the pattern" do
|
352
338
|
@pdf.stroke_gradient [0, @pdf.bounds.height], 10,
|
353
|
-
|
339
|
+
[@pdf.bounds.width, @pdf.bounds.height], 20,
|
340
|
+
'FF0000', '0000FF'
|
354
341
|
|
355
342
|
str = @pdf.render
|
356
|
-
str.
|
343
|
+
expect(str).to match(%r{/Pattern\s+CS\s*/SP-?\d+\s+SCN})
|
357
344
|
end
|
358
345
|
end
|
359
346
|
end
|
@@ -362,22 +349,22 @@ describe "When using painting shortcuts" do
|
|
362
349
|
before(:each) { create_pdf }
|
363
350
|
|
364
351
|
it "should convert stroke_some_method(args) into some_method(args); stroke" do
|
365
|
-
@pdf.expects(:line_to).with([100,100])
|
352
|
+
@pdf.expects(:line_to).with([100, 100])
|
366
353
|
@pdf.expects(:stroke)
|
367
354
|
|
368
|
-
@pdf.stroke_line_to [100,100]
|
355
|
+
@pdf.stroke_line_to [100, 100]
|
369
356
|
end
|
370
357
|
|
371
358
|
it "should convert fill_some_method(args) into some_method(args); fill" do
|
372
|
-
@pdf.expects(:line_to).with([100,100])
|
359
|
+
@pdf.expects(:line_to).with([100, 100])
|
373
360
|
@pdf.expects(:fill)
|
374
361
|
|
375
|
-
@pdf.fill_line_to [100,100]
|
362
|
+
@pdf.fill_line_to [100, 100]
|
376
363
|
end
|
377
364
|
|
378
365
|
it "should not break method_missing" do
|
379
|
-
|
380
|
-
|
366
|
+
expect { @pdf.i_have_a_pretty_girlfriend_named_jia }.
|
367
|
+
to raise_error(NoMethodError)
|
381
368
|
end
|
382
369
|
end
|
383
370
|
|
@@ -413,32 +400,32 @@ describe "When using graphics states" do
|
|
413
400
|
@pdf.stroke_color 0, 0, 0, 0
|
414
401
|
@pdf.restore_graphics_state
|
415
402
|
@pdf.stroke_color 0, 0, 100, 0
|
416
|
-
@pdf.graphic_state.color_space.
|
403
|
+
expect(@pdf.graphic_state.color_space).to eq(:stroke => :DeviceCMYK)
|
417
404
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
418
|
-
colors.color_space.
|
419
|
-
colors.stroke_color_space_count[:DeviceCMYK].
|
405
|
+
expect(colors.color_space).to eq(:DeviceCMYK)
|
406
|
+
expect(colors.stroke_color_space_count[:DeviceCMYK]).to eq(2)
|
420
407
|
end
|
421
408
|
|
422
409
|
it "should use the correct dash setting after restoring and starting new page" do
|
423
410
|
@pdf.dash 5
|
424
411
|
@pdf.save_graphics_state
|
425
412
|
@pdf.dash 10
|
426
|
-
@pdf.graphic_state.dash[:dash].
|
413
|
+
expect(@pdf.graphic_state.dash[:dash]).to eq(10)
|
427
414
|
@pdf.restore_graphics_state
|
428
415
|
@pdf.start_new_page
|
429
|
-
@pdf.graphic_state.dash[:dash].
|
416
|
+
expect(@pdf.graphic_state.dash[:dash]).to eq(5)
|
430
417
|
end
|
431
418
|
|
432
419
|
it "should round dash values to four decimal places" do
|
433
420
|
@pdf.dash 5.12345
|
434
|
-
@pdf.graphic_state.dash_setting.
|
421
|
+
expect(@pdf.graphic_state.dash_setting).to eq("[5.1235 5.1235] 0.0 d")
|
435
422
|
end
|
436
423
|
|
437
424
|
it "should raise an error when dash is called w. a zero length or space" do
|
438
425
|
expect { @pdf.dash(0) }.to raise_error(ArgumentError)
|
439
426
|
expect { @pdf.dash([0]) }.to raise_error(ArgumentError)
|
440
|
-
expect { @pdf.dash([0,0]) }.to raise_error(ArgumentError)
|
441
|
-
expect { @pdf.dash([0,0,0,1]) }.to raise_error(ArgumentError)
|
427
|
+
expect { @pdf.dash([0, 0]) }.to raise_error(ArgumentError)
|
428
|
+
expect { @pdf.dash([0, 0, 0, 1]) }.to raise_error(ArgumentError)
|
442
429
|
end
|
443
430
|
|
444
431
|
it "the current graphic state should keep track of previous unchanged settings" do
|
@@ -451,54 +438,51 @@ describe "When using graphics states" do
|
|
451
438
|
@pdf.fill_color 0, 0, 100, 0
|
452
439
|
@pdf.save_graphics_state
|
453
440
|
|
454
|
-
@pdf.graphic_state.stroke_color.
|
455
|
-
@pdf.graphic_state.join_style.
|
456
|
-
@pdf.graphic_state.fill_color.
|
457
|
-
@pdf.graphic_state.cap_style.
|
458
|
-
@pdf.graphic_state.color_space.
|
459
|
-
@pdf.graphic_state.dash.
|
460
|
-
@pdf.graphic_state.line_width.
|
441
|
+
expect(@pdf.graphic_state.stroke_color).to eq("000000")
|
442
|
+
expect(@pdf.graphic_state.join_style).to eq(:miter)
|
443
|
+
expect(@pdf.graphic_state.fill_color).to eq([0, 0, 100, 0])
|
444
|
+
expect(@pdf.graphic_state.cap_style).to eq(:round)
|
445
|
+
expect(@pdf.graphic_state.color_space).to eq(:fill => :DeviceCMYK, :stroke => :DeviceRGB)
|
446
|
+
expect(@pdf.graphic_state.dash).to eq(:space => 5, :phase => 0, :dash => 5)
|
447
|
+
expect(@pdf.graphic_state.line_width).to eq(1)
|
461
448
|
end
|
462
449
|
|
463
|
-
|
464
|
-
|
465
450
|
it "should not add extra graphic space closings when rendering multiple times" do
|
466
451
|
@pdf.render
|
467
452
|
state = PDF::Inspector::Graphics::State.analyze(@pdf.render)
|
468
|
-
state.save_graphics_state_count.
|
469
|
-
state.restore_graphics_state_count.
|
453
|
+
expect(state.save_graphics_state_count).to eq(1)
|
454
|
+
expect(state.restore_graphics_state_count).to eq(1)
|
470
455
|
end
|
471
456
|
|
472
457
|
it "should add extra graphic state enclosings when content is added on multiple renderings" do
|
473
458
|
@pdf.render
|
474
459
|
@pdf.text "Adding a bit more content"
|
475
460
|
state = PDF::Inspector::Graphics::State.analyze(@pdf.render)
|
476
|
-
state.save_graphics_state_count.
|
477
|
-
state.restore_graphics_state_count.
|
461
|
+
expect(state.save_graphics_state_count).to eq(2)
|
462
|
+
expect(state.restore_graphics_state_count).to eq(2)
|
478
463
|
end
|
479
464
|
|
480
465
|
it "adds extra graphic state enclosings when new settings are applied on multiple renderings" do
|
481
466
|
@pdf.render
|
482
467
|
@pdf.stroke_color 0, 0, 0, 0
|
483
468
|
state = PDF::Inspector::Graphics::State.analyze(@pdf.render)
|
484
|
-
state.save_graphics_state_count.
|
485
|
-
state.restore_graphics_state_count.
|
469
|
+
expect(state.save_graphics_state_count).to eq(2)
|
470
|
+
expect(state.restore_graphics_state_count).to eq(2)
|
486
471
|
end
|
487
472
|
|
488
|
-
|
489
473
|
it "should raise_error error if closing an empty graphic stack" do
|
490
|
-
|
474
|
+
expect {
|
491
475
|
@pdf.render
|
492
476
|
@pdf.restore_graphics_state
|
493
|
-
}.
|
477
|
+
}.to raise_error(PDF::Core::Errors::EmptyGraphicStateStack)
|
494
478
|
end
|
495
479
|
|
496
480
|
it "should copy mutable attributes when passing a previous_state to the initializer" do
|
497
481
|
new_state = PDF::Core::GraphicState.new(@pdf.graphic_state)
|
498
482
|
|
499
483
|
[:color_space, :dash, :fill_color, :stroke_color].each do |attr|
|
500
|
-
new_state.send(attr).
|
501
|
-
new_state.send(attr).
|
484
|
+
expect(new_state.send(attr)).to eq(@pdf.graphic_state.send(attr))
|
485
|
+
expect(new_state.send(attr)).not_to equal(@pdf.graphic_state.send(attr))
|
502
486
|
end
|
503
487
|
end
|
504
488
|
|
@@ -506,8 +490,8 @@ describe "When using graphics states" do
|
|
506
490
|
new_state = @pdf.graphic_state.dup
|
507
491
|
|
508
492
|
[:color_space, :dash, :fill_color, :stroke_color].each do |attr|
|
509
|
-
new_state.send(attr).
|
510
|
-
new_state.send(attr).
|
493
|
+
expect(new_state.send(attr)).to eq(@pdf.graphic_state.send(attr))
|
494
|
+
expect(new_state.send(attr)).not_to equal(@pdf.graphic_state.send(attr))
|
511
495
|
end
|
512
496
|
end
|
513
497
|
end
|
@@ -527,13 +511,13 @@ describe "When using transformation matrix" do
|
|
527
511
|
values = Array.new(6, 0.000000000001)
|
528
512
|
string = Array.new(6, "0.00000").join " "
|
529
513
|
@pdf.renderer.expects(:add_content).with("#{string} cm")
|
530
|
-
@pdf.transformation_matrix
|
514
|
+
@pdf.transformation_matrix(*values)
|
531
515
|
end
|
532
516
|
|
533
517
|
it "should be received by the inspector" do
|
534
518
|
@pdf.transformation_matrix 1, 0, 0, -1, 5.5, 20
|
535
519
|
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
536
|
-
matrices.matrices.
|
520
|
+
expect(matrices.matrices).to eq([[1, 0, 0, -1, 5.5, 20]])
|
537
521
|
end
|
538
522
|
|
539
523
|
it "should save the graphics state inside the given block" do
|
@@ -541,15 +525,14 @@ describe "When using transformation matrix" do
|
|
541
525
|
string = Array.new(6, "0.00000").join " "
|
542
526
|
process = sequence "process"
|
543
527
|
|
544
|
-
@pdf.expects(:save_graphics_state).with
|
528
|
+
@pdf.expects(:save_graphics_state).with.in_sequence(process)
|
545
529
|
@pdf.renderer.expects(:add_content).with("#{string} cm").in_sequence(process)
|
546
|
-
@pdf.expects(:do_something).with
|
547
|
-
@pdf.expects(:restore_graphics_state).with
|
530
|
+
@pdf.expects(:do_something).with.in_sequence(process)
|
531
|
+
@pdf.expects(:restore_graphics_state).with.in_sequence(process)
|
548
532
|
@pdf.transformation_matrix(*values) do
|
549
533
|
@pdf.do_something
|
550
534
|
end
|
551
535
|
end
|
552
|
-
|
553
536
|
end
|
554
537
|
|
555
538
|
describe "When using transformations shortcuts" do
|
@@ -577,13 +560,13 @@ describe "When using transformations shortcuts" do
|
|
577
560
|
@pdf.rotate(@angle, :origin => [@x, @y]) { @pdf.text('hello world') }
|
578
561
|
|
579
562
|
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
580
|
-
matrices.matrices[0].
|
581
|
-
|
582
|
-
|
583
|
-
matrices.matrices[1].
|
584
|
-
|
585
|
-
|
586
|
-
|
563
|
+
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
564
|
+
reduce_precision(@x - x_prime),
|
565
|
+
reduce_precision(@y - y_prime)])
|
566
|
+
expect(matrices.matrices[1]).to eq([reduce_precision(@cos),
|
567
|
+
reduce_precision(@sin),
|
568
|
+
reduce_precision(-@sin),
|
569
|
+
reduce_precision(@cos), 0, 0])
|
587
570
|
end
|
588
571
|
|
589
572
|
it "should rotate around the origin in a document with a margin" do
|
@@ -597,19 +580,19 @@ describe "When using transformations shortcuts" do
|
|
597
580
|
y_prime = x * @sin + y * @cos
|
598
581
|
|
599
582
|
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
600
|
-
matrices.matrices[0].
|
601
|
-
|
602
|
-
|
603
|
-
matrices.matrices[1].
|
604
|
-
|
605
|
-
|
606
|
-
|
583
|
+
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
584
|
+
reduce_precision(x - x_prime),
|
585
|
+
reduce_precision(y - y_prime)])
|
586
|
+
expect(matrices.matrices[1]).to eq([reduce_precision(@cos),
|
587
|
+
reduce_precision(@sin),
|
588
|
+
reduce_precision(-@sin),
|
589
|
+
reduce_precision(@cos), 0, 0])
|
607
590
|
end
|
608
591
|
|
609
592
|
it "should raise_error BlockRequired if no block is given" do
|
610
|
-
|
593
|
+
expect {
|
611
594
|
@pdf.rotate(@angle, :origin => [@x, @y])
|
612
|
-
}.
|
595
|
+
}.to raise_error(Prawn::Errors::BlockRequired)
|
613
596
|
end
|
614
597
|
|
615
598
|
def reduce_precision(float)
|
@@ -640,10 +623,10 @@ describe "When using transformations shortcuts" do
|
|
640
623
|
@pdf.scale(@factor, :origin => [@x, @y]) { @pdf.text('hello world') }
|
641
624
|
|
642
625
|
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
643
|
-
matrices.matrices[0].
|
644
|
-
|
645
|
-
|
646
|
-
matrices.matrices[1].
|
626
|
+
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
627
|
+
reduce_precision(@x - x_prime),
|
628
|
+
reduce_precision(@y - y_prime)])
|
629
|
+
expect(matrices.matrices[1]).to eq([@factor, 0, 0, @factor, 0, 0])
|
647
630
|
end
|
648
631
|
|
649
632
|
it "should scale from the origin in a document with a margin" do
|
@@ -656,16 +639,16 @@ describe "When using transformations shortcuts" do
|
|
656
639
|
@pdf.scale(@factor, :origin => [@x, @y]) { @pdf.text('hello world') }
|
657
640
|
|
658
641
|
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
659
|
-
matrices.matrices[0].
|
660
|
-
|
661
|
-
|
662
|
-
matrices.matrices[1].
|
642
|
+
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
643
|
+
reduce_precision(x - x_prime),
|
644
|
+
reduce_precision(y - y_prime)])
|
645
|
+
expect(matrices.matrices[1]).to eq([@factor, 0, 0, @factor, 0, 0])
|
663
646
|
end
|
664
647
|
|
665
648
|
it "should raise_error BlockRequired if no block is given" do
|
666
|
-
|
649
|
+
expect {
|
667
650
|
@pdf.scale(@factor, :origin => [@x, @y])
|
668
|
-
}.
|
651
|
+
}.to raise_error(Prawn::Errors::BlockRequired)
|
669
652
|
end
|
670
653
|
|
671
654
|
def reduce_precision(float)
|