prawn-shadings 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/BSDL +24 -0
- data/Gemfile +13 -0
- data/LICENSE +56 -0
- data/README.md +68 -0
- data/Rakefile +18 -0
- data/lib/prawn-shadings.rb +1 -0
- data/lib/prawn/shadings.rb +649 -0
- data/spec/lib/prawn/shadings_spec.rb +862 -0
- data/spec/spec_helper.rb +22 -0
- metadata +134 -0
@@ -0,0 +1,862 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "Shadingns" do
|
6
|
+
before(:each) { create_pdf }
|
7
|
+
|
8
|
+
describe 'linear gradients' do
|
9
|
+
it "should create a /Pattern resource" do
|
10
|
+
@pdf.fill_gradient [0, @pdf.bounds.height],
|
11
|
+
[@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
|
12
|
+
|
13
|
+
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
14
|
+
pattern = grad.patterns.values.first
|
15
|
+
|
16
|
+
pattern.should_not be_nil
|
17
|
+
pattern[:Shading][:ShadingType].should == 2
|
18
|
+
pattern[:Shading][:Coords].should == [0, 0, @pdf.bounds.width, 0]
|
19
|
+
pattern[:Shading][:Function][:C0].zip([1, 0, 0]).all?{ |x1, x2|
|
20
|
+
(x1-x2).abs < 0.01
|
21
|
+
}.should be_true
|
22
|
+
pattern[:Shading][:Function][:C1].zip([0, 0, 1]).all?{ |x1, x2|
|
23
|
+
(x1-x2).abs < 0.01
|
24
|
+
}.should be_true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "fill_gradient should set fill color to the pattern" do
|
28
|
+
@pdf.fill_gradient [0, @pdf.bounds.height],
|
29
|
+
[@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
|
30
|
+
|
31
|
+
str = @pdf.render
|
32
|
+
str.should =~ %r{/Pattern\s+cs\s*/SP-?\d+\s+scn}
|
33
|
+
end
|
34
|
+
|
35
|
+
it "stroke_gradient should set stroke color to the pattern" do
|
36
|
+
@pdf.stroke_gradient [0, @pdf.bounds.height],
|
37
|
+
[@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
|
38
|
+
|
39
|
+
str = @pdf.render
|
40
|
+
str.should =~ %r{/Pattern\s+CS\s*/SP-?\d+\s+SCN}
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be reused if used twice on page" do
|
44
|
+
2.times do
|
45
|
+
@pdf.fill_gradient [0, @pdf.bounds.height],
|
46
|
+
[@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
|
47
|
+
end
|
48
|
+
|
49
|
+
@pdf.page.resources[:Pattern].length.should == 1
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should validate colors to be in the same color space" do
|
53
|
+
lambda {
|
54
|
+
@pdf.fill_gradient [0, @pdf.bounds.height],
|
55
|
+
[@pdf.bounds.width, @pdf.bounds.height], 'FF0000', [1.0, 1.0, 1.0, 1.0]
|
56
|
+
}.should raise_error(ArgumentError)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'radial gradients' do
|
61
|
+
it "should create a /Pattern resource" do
|
62
|
+
@pdf.fill_gradient [0, @pdf.bounds.height], 10,
|
63
|
+
[@pdf.bounds.width, @pdf.bounds.height], 20, 'FF0000', '0000FF'
|
64
|
+
|
65
|
+
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
66
|
+
pattern = grad.patterns.values.first
|
67
|
+
|
68
|
+
pattern.should_not be_nil
|
69
|
+
pattern[:Shading][:ShadingType].should == 3
|
70
|
+
pattern[:Shading][:Coords].should == [0, 0, 10, @pdf.bounds.width, 0, 20]
|
71
|
+
pattern[:Shading][:Function][:C0].zip([1, 0, 0]).all?{ |x1, x2|
|
72
|
+
(x1-x2).abs < 0.01
|
73
|
+
}.should be_true
|
74
|
+
pattern[:Shading][:Function][:C1].zip([0, 0, 1]).all?{ |x1, x2|
|
75
|
+
(x1-x2).abs < 0.01
|
76
|
+
}.should be_true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "fill_gradient should set fill color to the pattern" do
|
80
|
+
@pdf.fill_gradient [0, @pdf.bounds.height], 10,
|
81
|
+
[@pdf.bounds.width, @pdf.bounds.height], 20, 'FF0000', '0000FF'
|
82
|
+
|
83
|
+
str = @pdf.render
|
84
|
+
str.should =~ %r{/Pattern\s+cs\s*/SP-?\d+\s+scn}
|
85
|
+
end
|
86
|
+
|
87
|
+
it "stroke_gradient should set stroke color to the pattern" do
|
88
|
+
@pdf.stroke_gradient [0, @pdf.bounds.height], 10,
|
89
|
+
[@pdf.bounds.width, @pdf.bounds.height], 20, 'FF0000', '0000FF'
|
90
|
+
|
91
|
+
str = @pdf.render
|
92
|
+
str.should =~ %r{/Pattern\s+CS\s*/SP-?\d+\s+SCN}
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should be reused if used twice on page" do
|
96
|
+
2.times do
|
97
|
+
@pdf.stroke_gradient [0, @pdf.bounds.height], 10,
|
98
|
+
[@pdf.bounds.width, @pdf.bounds.height], 20, 'FF0000', '0000FF'
|
99
|
+
end
|
100
|
+
|
101
|
+
@pdf.page.resources[:Pattern].length.should == 1
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should validate colors to be in the same color space" do
|
105
|
+
lambda {
|
106
|
+
@pdf.stroke_gradient [0, @pdf.bounds.height], 10,
|
107
|
+
[@pdf.bounds.width, @pdf.bounds.height], 20, 'FF0000', [1.0, 1.0, 1.0, 1.0]
|
108
|
+
}.should raise_error(ArgumentError)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'Free-Form Gouraud-Shaded Triangle Mesh' do
|
113
|
+
it "should create a /Pattern resource" do
|
114
|
+
@pdf.fill_gradient :ffgstm do
|
115
|
+
[
|
116
|
+
[0, 0, 0, 'ff0000'],
|
117
|
+
[0, 0, 100, '00ff00'],
|
118
|
+
[0, 100, 0, '0000ff']
|
119
|
+
]
|
120
|
+
end
|
121
|
+
|
122
|
+
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
123
|
+
pattern = grad.patterns.values.first
|
124
|
+
|
125
|
+
pattern.should_not be_nil
|
126
|
+
shading = pattern[:Shading].hash
|
127
|
+
shading[:ShadingType].should == 4
|
128
|
+
|
129
|
+
shading[:Decode].should == [0, 100, 0, 100, 0, 1, 0, 1, 0, 1]
|
130
|
+
pattern[:Shading].data.length.should == 36
|
131
|
+
pattern[:Shading].data.should == [0, 0, 0, 0xff, 0, 0, 0, 0, 0xffffffff, 0, 0xff, 0, 0, 0xffffffff, 0, 0, 0, 0xff].pack("CNNCCC" * 3)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "fill_gradient should set fill color to the pattern" do
|
135
|
+
@pdf.fill_gradient :ffgstm do
|
136
|
+
[
|
137
|
+
[0, 0, 0, 'ff0000'],
|
138
|
+
[0, 0, 100, '00ff00'],
|
139
|
+
[0, 100, 0, '0000ff']
|
140
|
+
]
|
141
|
+
end
|
142
|
+
|
143
|
+
str = @pdf.render
|
144
|
+
str.should =~ %r{/Pattern\s+cs\s*/SP-?\d+\s+scn}
|
145
|
+
end
|
146
|
+
|
147
|
+
it "stroke_gradient should set stroke color to the pattern" do
|
148
|
+
@pdf.stroke_gradient :ffgstm do
|
149
|
+
[
|
150
|
+
[0, 0, 0, 'ff0000'],
|
151
|
+
[0, 0, 100, '00ff00'],
|
152
|
+
[0, 100, 0, '0000ff']
|
153
|
+
]
|
154
|
+
end
|
155
|
+
|
156
|
+
str = @pdf.render
|
157
|
+
str.should =~ %r{/Pattern\s+CS\s*/SP-?\d+\s+SCN}
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should be reused if used twice on page" do
|
161
|
+
2.times do
|
162
|
+
@pdf.fill_gradient :ffgstm do
|
163
|
+
[
|
164
|
+
[0, 0, 0, 'ff0000'],
|
165
|
+
[0, 0, 100, '00ff00'],
|
166
|
+
[0, 100, 0, '0000ff']
|
167
|
+
]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
@pdf.page.resources[:Pattern].length.should == 1
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should validate flag" do
|
175
|
+
lambda {
|
176
|
+
@pdf.fill_gradient :ffgstm do
|
177
|
+
[
|
178
|
+
[0, 0, 0, 'ff0000'],
|
179
|
+
[2, 0, 100, '00ff00'],
|
180
|
+
[100, 100, 0, '0000ff']
|
181
|
+
]
|
182
|
+
end
|
183
|
+
}.should raise_error(ArgumentError, /flag/i)
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should validate vertices colorspace" do
|
187
|
+
lambda {
|
188
|
+
@pdf.fill_gradient :ffgstm do
|
189
|
+
[
|
190
|
+
[0, 0, 0, 'ff0000'],
|
191
|
+
[0, 0, 100, [0, 1, 0, 1]],
|
192
|
+
[0, 100, 0, '0000ff']
|
193
|
+
]
|
194
|
+
end
|
195
|
+
}.should raise_error(ArgumentError, /color space/i)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe 'Lattice-Form Gouraud-Shaded Triangle Mesh' do
|
200
|
+
it "should create a /Pattern resource" do
|
201
|
+
@pdf.fill_gradient :lfgstm do
|
202
|
+
[
|
203
|
+
[ [0, 100, '000000'], [100, 100, 'ff0000'] ],
|
204
|
+
[ [0, 0, 'ff0000'], [100, 0, '000000'] ]
|
205
|
+
]
|
206
|
+
end
|
207
|
+
|
208
|
+
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
209
|
+
pattern = grad.patterns.values.first
|
210
|
+
|
211
|
+
pattern.should_not be_nil
|
212
|
+
shading = pattern[:Shading].hash
|
213
|
+
shading[:ShadingType].should == 5
|
214
|
+
|
215
|
+
shading[:Decode].should == [0, 100, 0, 100, 0, 1, 0, 1, 0, 1]
|
216
|
+
pattern[:Shading].data.length.should == 44
|
217
|
+
pattern[:Shading].data.should == [0, 0xffffffff, 0, 0, 0, 0xffffffff, 0xffffffff, 0xff, 0, 0, 0, 0, 0xff, 0, 0, 0xffffffff, 0, 0, 0, 0].pack("NNCCC" * 4)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "fill_gradient should set fill color to the pattern" do
|
221
|
+
@pdf.fill_gradient :lfgstm do
|
222
|
+
[
|
223
|
+
[ [0, 100, '000000'], [100, 100, 'ff0000'] ],
|
224
|
+
[ [0, 0, 'ff0000'], [100, 0, '000000'] ]
|
225
|
+
]
|
226
|
+
end
|
227
|
+
|
228
|
+
str = @pdf.render
|
229
|
+
str.should =~ %r{/Pattern\s+cs\s*/SP-?\d+\s+scn}
|
230
|
+
end
|
231
|
+
|
232
|
+
it "stroke_gradient should set stroke color to the pattern" do
|
233
|
+
@pdf.stroke_gradient :lfgstm do
|
234
|
+
[
|
235
|
+
[ [0, 100, '000000'], [100, 100, 'ff0000'] ],
|
236
|
+
[ [0, 0, 'ff0000'], [100, 0, '000000'] ]
|
237
|
+
]
|
238
|
+
end
|
239
|
+
|
240
|
+
str = @pdf.render
|
241
|
+
str.should =~ %r{/Pattern\s+CS\s*/SP-?\d+\s+SCN}
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should be reused if used twice on page" do
|
245
|
+
2.times do
|
246
|
+
@pdf.fill_gradient :lfgstm do
|
247
|
+
[
|
248
|
+
[ [0, 100, '000000'], [100, 100, 'ff0000'] ],
|
249
|
+
[ [0, 0, 'ff0000'], [100, 0, '000000'] ]
|
250
|
+
]
|
251
|
+
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
@pdf.page.resources[:Pattern].length.should == 1
|
256
|
+
end
|
257
|
+
|
258
|
+
it "should validate number of rows" do
|
259
|
+
lambda {
|
260
|
+
@pdf.fill_gradient :lfgstm do
|
261
|
+
[
|
262
|
+
[ [0, 0, 'ff0000'], [100, 0, '000000'] ]
|
263
|
+
]
|
264
|
+
end
|
265
|
+
}.should raise_error(ArgumentError, /rows/i)
|
266
|
+
end
|
267
|
+
|
268
|
+
it "should validate number of vertices in all rows" do
|
269
|
+
lambda {
|
270
|
+
@pdf.fill_gradient :lfgstm do
|
271
|
+
[
|
272
|
+
[ [0, 100, '000000'] ],
|
273
|
+
[ [0, 0, 'ff0000'], [100, 0, '000000'] ]
|
274
|
+
]
|
275
|
+
end
|
276
|
+
}.should raise_error(ArgumentError, /at least 2 vertices per row/i)
|
277
|
+
end
|
278
|
+
|
279
|
+
it "should validate number of vertices in all rows" do
|
280
|
+
lambda {
|
281
|
+
@pdf.fill_gradient :lfgstm do
|
282
|
+
[
|
283
|
+
[ [0, 100, '000000'], [100, 100, 'ff0000'], [200, 100, '00ff00'] ],
|
284
|
+
[ [0, 0, 'ff0000'], [100, 0, '000000'] ]
|
285
|
+
]
|
286
|
+
end
|
287
|
+
}.should raise_error(ArgumentError, /rectangular matrix/i)
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should validate vertices colorspace" do
|
291
|
+
lambda {
|
292
|
+
@pdf.fill_gradient :lfgstm do
|
293
|
+
[
|
294
|
+
[ [0, 100, '000000'], [100, 100, [1, 1, 1, 1]] ],
|
295
|
+
[ [0, 0, 'ff0000'], [100, 0, '000000'] ]
|
296
|
+
]
|
297
|
+
|
298
|
+
end
|
299
|
+
}.should raise_error(ArgumentError, /color space/i)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
describe 'Coons Patch Mesh' do
|
304
|
+
it "should create a /Pattern resource" do
|
305
|
+
@pdf.fill_gradient :cpm do
|
306
|
+
[
|
307
|
+
[
|
308
|
+
0,
|
309
|
+
0, 0,
|
310
|
+
0, 0,
|
311
|
+
0, 100,
|
312
|
+
0, 100,
|
313
|
+
0, 100,
|
314
|
+
100, 100,
|
315
|
+
100, 100,
|
316
|
+
100, 100,
|
317
|
+
100, 0,
|
318
|
+
100, 0,
|
319
|
+
100, 0,
|
320
|
+
0, 0,
|
321
|
+
'ffff00', 'ff0000', '00ff00', '0000ff'
|
322
|
+
]
|
323
|
+
]
|
324
|
+
end
|
325
|
+
|
326
|
+
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
327
|
+
pattern = grad.patterns.values.first
|
328
|
+
|
329
|
+
pattern.should_not be_nil
|
330
|
+
shading = pattern[:Shading].hash
|
331
|
+
shading[:ShadingType].should == 6
|
332
|
+
|
333
|
+
shading[:Decode].should == [0, 100, 0, 100, 0, 1, 0, 1, 0, 1]
|
334
|
+
pattern[:Shading].data.length.should == 109
|
335
|
+
pattern[:Shading].data.should == [0,
|
336
|
+
0, 0,
|
337
|
+
0, 0,
|
338
|
+
0, 0xffffffff,
|
339
|
+
0, 0xffffffff,
|
340
|
+
0, 0xffffffff,
|
341
|
+
0xffffffff, 0xffffffff,
|
342
|
+
0xffffffff, 0xffffffff,
|
343
|
+
0xffffffff, 0xffffffff,
|
344
|
+
0xffffffff, 0,
|
345
|
+
0xffffffff, 0,
|
346
|
+
0xffffffff, 0,
|
347
|
+
0, 0,
|
348
|
+
0xff, 0xff, 0,
|
349
|
+
0xff, 0, 0,
|
350
|
+
0, 0xff, 0,
|
351
|
+
0, 0, 0xff].pack("CN24C12")
|
352
|
+
end
|
353
|
+
|
354
|
+
it "should create a /Pattern resource with reused vertices" do
|
355
|
+
@pdf.fill_gradient :cpm do
|
356
|
+
[
|
357
|
+
[
|
358
|
+
0,
|
359
|
+
0, 0,
|
360
|
+
0, 0,
|
361
|
+
0, 100,
|
362
|
+
0, 100,
|
363
|
+
0, 100,
|
364
|
+
100, 100,
|
365
|
+
100, 100,
|
366
|
+
100, 100,
|
367
|
+
100, 0,
|
368
|
+
100, 0,
|
369
|
+
100, 0,
|
370
|
+
0, 0,
|
371
|
+
'ffff00', 'ff0000', '00ff00', '0000ff'
|
372
|
+
],
|
373
|
+
[
|
374
|
+
1,
|
375
|
+
0, 100,
|
376
|
+
100, 100,
|
377
|
+
100, 100,
|
378
|
+
100, 100,
|
379
|
+
100, 0,
|
380
|
+
100, 0,
|
381
|
+
100, 0,
|
382
|
+
0, 0,
|
383
|
+
'00ff00', '0000ff'
|
384
|
+
],
|
385
|
+
|
386
|
+
]
|
387
|
+
end
|
388
|
+
|
389
|
+
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
390
|
+
pattern = grad.patterns.values.first
|
391
|
+
|
392
|
+
pattern.should_not be_nil
|
393
|
+
shading = pattern[:Shading].hash
|
394
|
+
shading[:ShadingType].should == 6
|
395
|
+
|
396
|
+
shading[:Decode].should == [0, 100, 0, 100, 0, 1, 0, 1, 0, 1]
|
397
|
+
pattern[:Shading].data.length.should == 180
|
398
|
+
pattern[:Shading].data.should == [0,
|
399
|
+
0, 0,
|
400
|
+
0, 0,
|
401
|
+
0, 0xffffffff,
|
402
|
+
0, 0xffffffff,
|
403
|
+
0, 0xffffffff,
|
404
|
+
0xffffffff, 0xffffffff,
|
405
|
+
0xffffffff, 0xffffffff,
|
406
|
+
0xffffffff, 0xffffffff,
|
407
|
+
0xffffffff, 0,
|
408
|
+
0xffffffff, 0,
|
409
|
+
0xffffffff, 0,
|
410
|
+
0, 0,
|
411
|
+
0xff, 0xff, 0,
|
412
|
+
0xff, 0, 0,
|
413
|
+
0, 0xff, 0,
|
414
|
+
0, 0, 0xff,
|
415
|
+
|
416
|
+
1,
|
417
|
+
0, 0xffffffff,
|
418
|
+
0xffffffff, 0xffffffff,
|
419
|
+
0xffffffff, 0xffffffff,
|
420
|
+
0xffffffff, 0xffffffff,
|
421
|
+
0xffffffff, 0,
|
422
|
+
0xffffffff, 0,
|
423
|
+
0xffffffff, 0,
|
424
|
+
0, 0,
|
425
|
+
0, 0xff, 0,
|
426
|
+
0, 0, 0xff
|
427
|
+
].pack("CN24C12CN16C6")
|
428
|
+
end
|
429
|
+
|
430
|
+
it "fill_gradient should set fill color to the pattern" do
|
431
|
+
@pdf.fill_gradient :cpm do
|
432
|
+
[
|
433
|
+
[
|
434
|
+
0,
|
435
|
+
0, 0,
|
436
|
+
0, 0,
|
437
|
+
0, 100,
|
438
|
+
0, 100,
|
439
|
+
0, 100,
|
440
|
+
100, 100,
|
441
|
+
100, 100,
|
442
|
+
100, 100,
|
443
|
+
100, 0,
|
444
|
+
100, 0,
|
445
|
+
100, 0,
|
446
|
+
0, 0,
|
447
|
+
'ffff00', 'ff0000', '00ff00', '0000ff'
|
448
|
+
]
|
449
|
+
]
|
450
|
+
end
|
451
|
+
|
452
|
+
str = @pdf.render
|
453
|
+
str.should =~ %r{/Pattern\s+cs\s*/SP-?\d+\s+scn}
|
454
|
+
end
|
455
|
+
|
456
|
+
it "stroke_gradient should set stroke color to the pattern" do
|
457
|
+
@pdf.stroke_gradient :cpm do
|
458
|
+
[
|
459
|
+
[
|
460
|
+
0,
|
461
|
+
0, 0,
|
462
|
+
0, 0,
|
463
|
+
0, 100,
|
464
|
+
0, 100,
|
465
|
+
0, 100,
|
466
|
+
100, 100,
|
467
|
+
100, 100,
|
468
|
+
100, 100,
|
469
|
+
100, 0,
|
470
|
+
100, 0,
|
471
|
+
100, 0,
|
472
|
+
0, 0,
|
473
|
+
'ffff00', 'ff0000', '00ff00', '0000ff'
|
474
|
+
]
|
475
|
+
]
|
476
|
+
|
477
|
+
end
|
478
|
+
|
479
|
+
str = @pdf.render
|
480
|
+
str.should =~ %r{/Pattern\s+CS\s*/SP-?\d+\s+SCN}
|
481
|
+
end
|
482
|
+
|
483
|
+
it "should be reused if used twice on page" do
|
484
|
+
2.times do
|
485
|
+
@pdf.fill_gradient :cpm do
|
486
|
+
[
|
487
|
+
[
|
488
|
+
0,
|
489
|
+
0, 0,
|
490
|
+
0, 0,
|
491
|
+
0, 100,
|
492
|
+
0, 100,
|
493
|
+
0, 100,
|
494
|
+
100, 100,
|
495
|
+
100, 100,
|
496
|
+
100, 100,
|
497
|
+
100, 0,
|
498
|
+
100, 0,
|
499
|
+
100, 0,
|
500
|
+
0, 0,
|
501
|
+
'ffff00', 'ff0000', '00ff00', '0000ff'
|
502
|
+
]
|
503
|
+
]
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
507
|
+
@pdf.page.resources[:Pattern].length.should == 1
|
508
|
+
end
|
509
|
+
|
510
|
+
it "should validate flags" do
|
511
|
+
lambda {
|
512
|
+
@pdf.fill_gradient :cpm do
|
513
|
+
[
|
514
|
+
[
|
515
|
+
20,
|
516
|
+
0, 0,
|
517
|
+
0, 0,
|
518
|
+
0, 100,
|
519
|
+
0, 100,
|
520
|
+
0, 100,
|
521
|
+
100, 100,
|
522
|
+
100, 100,
|
523
|
+
100, 100,
|
524
|
+
100, 0,
|
525
|
+
100, 0,
|
526
|
+
100, 0,
|
527
|
+
0, 0,
|
528
|
+
'ffff00', 'ff0000', '00ff00', '0000ff'
|
529
|
+
]
|
530
|
+
]
|
531
|
+
end
|
532
|
+
}.should raise_error(ArgumentError, /flag/i)
|
533
|
+
end
|
534
|
+
|
535
|
+
it "should validate vertices colorspace" do
|
536
|
+
lambda {
|
537
|
+
@pdf.fill_gradient :cpm do
|
538
|
+
[
|
539
|
+
[
|
540
|
+
0,
|
541
|
+
0, 0,
|
542
|
+
0, 0,
|
543
|
+
0, 100,
|
544
|
+
0, 100,
|
545
|
+
0, 100,
|
546
|
+
100, 100,
|
547
|
+
100, 100,
|
548
|
+
100, 100,
|
549
|
+
100, 0,
|
550
|
+
100, 0,
|
551
|
+
100, 0,
|
552
|
+
0, 0,
|
553
|
+
'ffff00', 'ff0000', '00ff00', [1, 1, 1, 1]
|
554
|
+
]
|
555
|
+
]
|
556
|
+
end
|
557
|
+
}.should raise_error(ArgumentError, /color space/i)
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
561
|
+
describe 'Tensor-Product Patch Mesh' do
|
562
|
+
it "should create a /Pattern resource" do
|
563
|
+
@pdf.fill_gradient :tppm do
|
564
|
+
[
|
565
|
+
[
|
566
|
+
0,
|
567
|
+
0, 0,
|
568
|
+
0, 0,
|
569
|
+
0, 100,
|
570
|
+
0, 100,
|
571
|
+
0, 100,
|
572
|
+
100, 100,
|
573
|
+
100, 100,
|
574
|
+
100, 100,
|
575
|
+
100, 0,
|
576
|
+
100, 0,
|
577
|
+
100, 0,
|
578
|
+
0, 0,
|
579
|
+
50, 50,
|
580
|
+
50, 50,
|
581
|
+
50, 50,
|
582
|
+
50, 50,
|
583
|
+
'ffff00', 'ff0000', '00ff00', '0000ff'
|
584
|
+
]
|
585
|
+
]
|
586
|
+
end
|
587
|
+
|
588
|
+
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
589
|
+
pattern = grad.patterns.values.first
|
590
|
+
|
591
|
+
pattern.should_not be_nil
|
592
|
+
shading = pattern[:Shading].hash
|
593
|
+
shading[:ShadingType].should == 7
|
594
|
+
|
595
|
+
shading[:Decode].should == [0, 100, 0, 100, 0, 1, 0, 1, 0, 1]
|
596
|
+
pattern[:Shading].data.length.should == 141
|
597
|
+
pattern[:Shading].data.should == [0,
|
598
|
+
0, 0,
|
599
|
+
0, 0,
|
600
|
+
0, 0xffffffff,
|
601
|
+
0, 0xffffffff,
|
602
|
+
0, 0xffffffff,
|
603
|
+
0xffffffff, 0xffffffff,
|
604
|
+
0xffffffff, 0xffffffff,
|
605
|
+
0xffffffff, 0xffffffff,
|
606
|
+
0xffffffff, 0,
|
607
|
+
0xffffffff, 0,
|
608
|
+
0xffffffff, 0,
|
609
|
+
0, 0,
|
610
|
+
0x80000000, 0x80000000,
|
611
|
+
0x80000000, 0x80000000,
|
612
|
+
0x80000000, 0x80000000,
|
613
|
+
0x80000000, 0x80000000,
|
614
|
+
0xff, 0xff, 0,
|
615
|
+
0xff, 0, 0,
|
616
|
+
0, 0xff, 0,
|
617
|
+
0, 0, 0xff].pack("CN32C12")
|
618
|
+
end
|
619
|
+
|
620
|
+
it "should create a /Pattern resource with reused vertices" do
|
621
|
+
@pdf.fill_gradient :tppm do
|
622
|
+
[
|
623
|
+
[
|
624
|
+
0,
|
625
|
+
0, 0,
|
626
|
+
0, 0,
|
627
|
+
0, 100,
|
628
|
+
0, 100,
|
629
|
+
0, 100,
|
630
|
+
100, 100,
|
631
|
+
100, 100,
|
632
|
+
100, 100,
|
633
|
+
100, 0,
|
634
|
+
100, 0,
|
635
|
+
100, 0,
|
636
|
+
0, 0,
|
637
|
+
50, 50,
|
638
|
+
50, 50,
|
639
|
+
50, 50,
|
640
|
+
50, 50,
|
641
|
+
'ffff00', 'ff0000', '00ff00', '0000ff'
|
642
|
+
],
|
643
|
+
[
|
644
|
+
1,
|
645
|
+
0, 100,
|
646
|
+
100, 100,
|
647
|
+
100, 100,
|
648
|
+
100, 100,
|
649
|
+
100, 0,
|
650
|
+
100, 0,
|
651
|
+
100, 0,
|
652
|
+
0, 0,
|
653
|
+
50, 50,
|
654
|
+
50, 50,
|
655
|
+
50, 50,
|
656
|
+
50, 50,
|
657
|
+
'00ff00', '0000ff'
|
658
|
+
],
|
659
|
+
|
660
|
+
]
|
661
|
+
end
|
662
|
+
|
663
|
+
grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
|
664
|
+
pattern = grad.patterns.values.first
|
665
|
+
|
666
|
+
pattern.should_not be_nil
|
667
|
+
shading = pattern[:Shading].hash
|
668
|
+
shading[:ShadingType].should == 7
|
669
|
+
|
670
|
+
shading[:Decode].should == [0, 100, 0, 100, 0, 1, 0, 1, 0, 1]
|
671
|
+
pattern[:Shading].data.length.should == 244
|
672
|
+
pattern[:Shading].data.should == [0,
|
673
|
+
0, 0,
|
674
|
+
0, 0,
|
675
|
+
0, 0xffffffff,
|
676
|
+
0, 0xffffffff,
|
677
|
+
0, 0xffffffff,
|
678
|
+
0xffffffff, 0xffffffff,
|
679
|
+
0xffffffff, 0xffffffff,
|
680
|
+
0xffffffff, 0xffffffff,
|
681
|
+
0xffffffff, 0,
|
682
|
+
0xffffffff, 0,
|
683
|
+
0xffffffff, 0,
|
684
|
+
0, 0,
|
685
|
+
0x80000000, 0x80000000,
|
686
|
+
0x80000000, 0x80000000,
|
687
|
+
0x80000000, 0x80000000,
|
688
|
+
0x80000000, 0x80000000,
|
689
|
+
0xff, 0xff, 0,
|
690
|
+
0xff, 0, 0,
|
691
|
+
0, 0xff, 0,
|
692
|
+
0, 0, 0xff,
|
693
|
+
|
694
|
+
1,
|
695
|
+
0, 0xffffffff,
|
696
|
+
0xffffffff, 0xffffffff,
|
697
|
+
0xffffffff, 0xffffffff,
|
698
|
+
0xffffffff, 0xffffffff,
|
699
|
+
0xffffffff, 0,
|
700
|
+
0xffffffff, 0,
|
701
|
+
0xffffffff, 0,
|
702
|
+
0, 0,
|
703
|
+
0x80000000, 0x80000000,
|
704
|
+
0x80000000, 0x80000000,
|
705
|
+
0x80000000, 0x80000000,
|
706
|
+
0x80000000, 0x80000000,
|
707
|
+
0, 0xff, 0,
|
708
|
+
0, 0, 0xff
|
709
|
+
].pack("CN32C12CN24C6")
|
710
|
+
end
|
711
|
+
|
712
|
+
it "fill_gradient should set fill color to the pattern" do
|
713
|
+
@pdf.fill_gradient :tppm do
|
714
|
+
[
|
715
|
+
[
|
716
|
+
0,
|
717
|
+
0, 0,
|
718
|
+
0, 0,
|
719
|
+
0, 100,
|
720
|
+
0, 100,
|
721
|
+
0, 100,
|
722
|
+
100, 100,
|
723
|
+
100, 100,
|
724
|
+
100, 100,
|
725
|
+
100, 0,
|
726
|
+
100, 0,
|
727
|
+
100, 0,
|
728
|
+
0, 0,
|
729
|
+
50, 50,
|
730
|
+
50, 50,
|
731
|
+
50, 50,
|
732
|
+
50, 50,
|
733
|
+
'ffff00', 'ff0000', '00ff00', '0000ff'
|
734
|
+
]
|
735
|
+
]
|
736
|
+
end
|
737
|
+
|
738
|
+
str = @pdf.render
|
739
|
+
str.should =~ %r{/Pattern\s+cs\s*/SP-?\d+\s+scn}
|
740
|
+
end
|
741
|
+
|
742
|
+
it "stroke_gradient should set stroke color to the pattern" do
|
743
|
+
@pdf.stroke_gradient :tppm do
|
744
|
+
[
|
745
|
+
[
|
746
|
+
0,
|
747
|
+
0, 0,
|
748
|
+
0, 0,
|
749
|
+
0, 100,
|
750
|
+
0, 100,
|
751
|
+
0, 100,
|
752
|
+
100, 100,
|
753
|
+
100, 100,
|
754
|
+
100, 100,
|
755
|
+
100, 0,
|
756
|
+
100, 0,
|
757
|
+
100, 0,
|
758
|
+
0, 0,
|
759
|
+
50, 50,
|
760
|
+
50, 50,
|
761
|
+
50, 50,
|
762
|
+
50, 50,
|
763
|
+
'ffff00', 'ff0000', '00ff00', '0000ff'
|
764
|
+
]
|
765
|
+
]
|
766
|
+
|
767
|
+
end
|
768
|
+
|
769
|
+
str = @pdf.render
|
770
|
+
str.should =~ %r{/Pattern\s+CS\s*/SP-?\d+\s+SCN}
|
771
|
+
end
|
772
|
+
|
773
|
+
it "should be reused if used twice on page" do
|
774
|
+
2.times do
|
775
|
+
@pdf.fill_gradient :tppm do
|
776
|
+
[
|
777
|
+
[
|
778
|
+
0,
|
779
|
+
0, 0,
|
780
|
+
0, 0,
|
781
|
+
0, 100,
|
782
|
+
0, 100,
|
783
|
+
0, 100,
|
784
|
+
100, 100,
|
785
|
+
100, 100,
|
786
|
+
100, 100,
|
787
|
+
100, 0,
|
788
|
+
100, 0,
|
789
|
+
100, 0,
|
790
|
+
0, 0,
|
791
|
+
50, 50,
|
792
|
+
50, 50,
|
793
|
+
50, 50,
|
794
|
+
50, 50,
|
795
|
+
'ffff00', 'ff0000', '00ff00', '0000ff'
|
796
|
+
]
|
797
|
+
]
|
798
|
+
end
|
799
|
+
end
|
800
|
+
|
801
|
+
@pdf.page.resources[:Pattern].length.should == 1
|
802
|
+
end
|
803
|
+
|
804
|
+
it "should validate flags" do
|
805
|
+
lambda {
|
806
|
+
@pdf.fill_gradient :tppm do
|
807
|
+
[
|
808
|
+
[
|
809
|
+
20,
|
810
|
+
0, 0,
|
811
|
+
0, 0,
|
812
|
+
0, 100,
|
813
|
+
0, 100,
|
814
|
+
0, 100,
|
815
|
+
100, 100,
|
816
|
+
100, 100,
|
817
|
+
100, 100,
|
818
|
+
100, 0,
|
819
|
+
100, 0,
|
820
|
+
100, 0,
|
821
|
+
0, 0,
|
822
|
+
50, 50,
|
823
|
+
50, 50,
|
824
|
+
50, 50,
|
825
|
+
50, 50,
|
826
|
+
'ffff00', 'ff0000', '00ff00', '0000ff'
|
827
|
+
]
|
828
|
+
]
|
829
|
+
end
|
830
|
+
}.should raise_error(ArgumentError, /flag/i)
|
831
|
+
end
|
832
|
+
|
833
|
+
it "should validate vertices colorspace" do
|
834
|
+
lambda {
|
835
|
+
@pdf.fill_gradient :tppm do
|
836
|
+
[
|
837
|
+
[
|
838
|
+
0,
|
839
|
+
0, 0,
|
840
|
+
0, 0,
|
841
|
+
0, 100,
|
842
|
+
0, 100,
|
843
|
+
0, 100,
|
844
|
+
100, 100,
|
845
|
+
100, 100,
|
846
|
+
100, 100,
|
847
|
+
100, 0,
|
848
|
+
100, 0,
|
849
|
+
100, 0,
|
850
|
+
0, 0,
|
851
|
+
50, 50,
|
852
|
+
50, 50,
|
853
|
+
50, 50,
|
854
|
+
50, 50,
|
855
|
+
'ffff00', 'ff0000', '00ff00', [1, 1, 1, 1]
|
856
|
+
]
|
857
|
+
]
|
858
|
+
end
|
859
|
+
}.should raise_error(ArgumentError, /color space/i)
|
860
|
+
end
|
861
|
+
end
|
862
|
+
end
|