prawn 1.0.0.rc2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +9 -0
- data/COPYING +2 -2
- data/Gemfile +8 -15
- data/LICENSE +1 -1
- data/Rakefile +25 -16
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/license.md +8 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/lib/prawn.rb +85 -23
- data/lib/prawn/document.rb +134 -116
- data/lib/prawn/document/bounding_box.rb +33 -4
- data/lib/prawn/document/column_box.rb +18 -6
- data/lib/prawn/document/graphics_state.rb +11 -74
- data/lib/prawn/document/internals.rb +24 -23
- data/lib/prawn/document/span.rb +12 -10
- data/lib/prawn/encoding.rb +8 -9
- data/lib/prawn/errors.rb +13 -32
- data/lib/prawn/font.rb +137 -105
- data/lib/prawn/font/afm.rb +76 -32
- data/lib/prawn/font/dfont.rb +4 -3
- data/lib/prawn/font/ttf.rb +33 -25
- data/lib/prawn/font_metric_cache.rb +47 -0
- data/lib/prawn/graphics.rb +177 -57
- data/lib/prawn/graphics/cap_style.rb +4 -3
- data/lib/prawn/graphics/color.rb +5 -4
- data/lib/prawn/graphics/dash.rb +53 -31
- data/lib/prawn/graphics/join_style.rb +9 -7
- data/lib/prawn/graphics/patterns.rb +4 -15
- data/lib/prawn/graphics/transformation.rb +10 -9
- data/lib/prawn/graphics/transparency.rb +3 -1
- data/lib/prawn/{layout/grid.rb → grid.rb} +72 -54
- data/lib/prawn/image_handler.rb +42 -0
- data/lib/prawn/images.rb +58 -54
- data/lib/prawn/images/image.rb +6 -22
- data/lib/prawn/images/jpg.rb +20 -14
- data/lib/prawn/images/png.rb +58 -121
- data/lib/prawn/layout.rb +12 -15
- data/lib/prawn/measurement_extensions.rb +10 -6
- data/lib/prawn/measurements.rb +27 -21
- data/lib/prawn/outline.rb +108 -147
- data/lib/prawn/repeater.rb +10 -8
- data/lib/prawn/security.rb +59 -40
- data/lib/prawn/security/arcfour.rb +52 -0
- data/lib/prawn/soft_mask.rb +4 -4
- data/lib/prawn/stamp.rb +5 -3
- data/lib/prawn/table.rb +83 -60
- data/lib/prawn/table/cell.rb +17 -21
- data/lib/prawn/table/cell/image.rb +2 -3
- data/lib/prawn/table/cell/in_table.rb +8 -2
- data/lib/prawn/table/cell/span_dummy.rb +5 -0
- data/lib/prawn/table/cell/subtable.rb +3 -2
- data/lib/prawn/table/cell/text.rb +14 -12
- data/lib/prawn/table/cells.rb +58 -14
- data/lib/prawn/table/column_width_calculator.rb +61 -0
- data/lib/prawn/text.rb +27 -26
- data/lib/prawn/text/box.rb +12 -6
- data/lib/prawn/text/formatted.rb +5 -4
- data/lib/prawn/text/formatted/arranger.rb +290 -0
- data/lib/prawn/text/formatted/box.rb +85 -57
- data/lib/prawn/text/formatted/fragment.rb +11 -11
- data/lib/prawn/text/formatted/line_wrap.rb +266 -0
- data/lib/prawn/text/formatted/parser.rb +11 -4
- data/lib/prawn/text/formatted/wrap.rb +156 -0
- data/lib/prawn/utilities.rb +5 -3
- data/manual/document_and_page_options/document_and_page_options.rb +2 -1
- data/manual/document_and_page_options/metadata.rb +3 -3
- data/manual/document_and_page_options/page_size.rb +2 -2
- data/manual/document_and_page_options/print_scaling.rb +20 -0
- data/manual/example_file.rb +2 -7
- data/manual/example_helper.rb +62 -81
- data/manual/graphics/common_lines.rb +2 -0
- data/manual/graphics/helper.rb +11 -4
- data/manual/graphics/stroke_dash.rb +19 -14
- data/manual/manual/cover.rb +16 -0
- data/manual/manual/manual.rb +1 -5
- data/manual/text/fallback_fonts.rb +4 -4
- data/manual/text/formatted_text.rb +5 -5
- data/manual/text/inline.rb +2 -4
- data/manual/text/registering_families.rb +12 -12
- data/manual/text/single_usage.rb +4 -4
- data/manual/text/text.rb +0 -2
- data/prawn.gemspec +21 -13
- data/spec/acceptance/png.rb +23 -0
- data/spec/annotations_spec.rb +16 -32
- data/spec/bounding_box_spec.rb +22 -5
- data/spec/cell_spec.rb +49 -5
- data/spec/column_box_spec.rb +32 -0
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +112 -118
- data/spec/extensions/encoding_helpers.rb +5 -2
- data/spec/font_metric_cache_spec.rb +52 -0
- data/spec/font_spec.rb +121 -120
- data/spec/formatted_text_arranger_spec.rb +24 -24
- data/spec/formatted_text_box_spec.rb +31 -32
- data/spec/formatted_text_fragment_spec.rb +2 -2
- data/spec/graphics_spec.rb +63 -45
- data/spec/grid_spec.rb +24 -13
- data/spec/image_handler_spec.rb +54 -0
- data/spec/images_spec.rb +34 -21
- data/spec/inline_formatted_text_parser_spec.rb +69 -20
- data/spec/jpg_spec.rb +3 -3
- data/spec/line_wrap_spec.rb +25 -14
- data/spec/measurement_units_spec.rb +5 -5
- data/spec/outline_spec.rb +68 -64
- data/spec/png_spec.rb +15 -18
- data/spec/reference_spec.rb +2 -82
- data/spec/repeater_spec.rb +1 -1
- data/spec/security_spec.rb +41 -9
- data/spec/soft_mask_spec.rb +0 -40
- data/spec/span_spec.rb +6 -11
- data/spec/spec_helper.rb +20 -2
- data/spec/stamp_spec.rb +19 -20
- data/spec/stroke_styles_spec.rb +31 -13
- data/spec/table/span_dummy_spec.rb +17 -0
- data/spec/table_spec.rb +268 -43
- data/spec/text_at_spec.rb +13 -27
- data/spec/text_box_spec.rb +35 -30
- data/spec/text_spec.rb +56 -40
- data/spec/transparency_spec.rb +5 -5
- metadata +214 -217
- data/README.md +0 -98
- data/data/fonts/Action Man.dfont +0 -0
- data/data/fonts/Activa.ttf +0 -0
- data/data/fonts/Chalkboard.ttf +0 -0
- data/data/fonts/DejaVuSans.ttf +0 -0
- data/data/fonts/Dustismo_Roman.ttf +0 -0
- data/data/fonts/comicsans.ttf +0 -0
- data/data/fonts/gkai00mp.ttf +0 -0
- data/data/images/16bit.dat +0 -0
- data/data/images/barcode_issue.png +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/page_white_text.dat +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/lib/prawn/compatibility.rb +0 -87
- data/lib/prawn/core.rb +0 -87
- data/lib/prawn/core/annotations.rb +0 -61
- data/lib/prawn/core/byte_string.rb +0 -9
- data/lib/prawn/core/destinations.rb +0 -90
- data/lib/prawn/core/document_state.rb +0 -79
- data/lib/prawn/core/literal_string.rb +0 -16
- data/lib/prawn/core/name_tree.rb +0 -177
- data/lib/prawn/core/object_store.rb +0 -320
- data/lib/prawn/core/page.rb +0 -212
- data/lib/prawn/core/pdf_object.rb +0 -125
- data/lib/prawn/core/reference.rb +0 -119
- data/lib/prawn/core/text.rb +0 -268
- data/lib/prawn/core/text/formatted/arranger.rb +0 -294
- data/lib/prawn/core/text/formatted/line_wrap.rb +0 -288
- data/lib/prawn/core/text/formatted/wrap.rb +0 -153
- data/lib/prawn/document/page_geometry.rb +0 -136
- data/lib/prawn/document/snapshot.rb +0 -89
- data/manual/manual/foreword.rb +0 -13
- data/manual/templates/full_template.rb +0 -23
- data/manual/templates/page_template.rb +0 -47
- data/manual/templates/templates.rb +0 -26
- data/manual/text/group.rb +0 -29
- data/spec/name_tree_spec.rb +0 -112
- data/spec/object_store_spec.rb +0 -170
- data/spec/pdf_object_spec.rb +0 -172
- data/spec/snapshot_spec.rb +0 -186
- data/spec/template_spec.rb +0 -351
data/spec/reference_spec.rb
CHANGED
@@ -3,90 +3,10 @@
|
|
3
3
|
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
4
|
|
5
5
|
describe "A Reference object" do
|
6
|
-
it "should produce a PDF reference on #to_s call" do
|
7
|
-
ref = Prawn::Core::Reference(1,true)
|
8
|
-
ref.to_s.should == "1 0 R"
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should allow changing generation number" do
|
12
|
-
ref = Prawn::Core::Reference(1,true)
|
13
|
-
ref.gen = 1
|
14
|
-
ref.to_s.should == "1 1 R"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should generate a valid PDF object for the referenced data" do
|
18
|
-
ref = Prawn::Core::Reference(2,[1,"foo"])
|
19
|
-
ref.object.should == "2 0 obj\n#{Prawn::Core::PdfObject([1,"foo"])}\nendobj\n"
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should automatically open a stream when #<< is used" do
|
23
|
-
ref = Prawn::Core::Reference(1, :Length => 41)
|
24
|
-
ref << "BT\n/F1 12 Tf\n72 712 Td\n( A stream ) Tj\nET"
|
25
|
-
ref.object.should == "1 0 obj\n<< /Length 41\n>>\nstream"+
|
26
|
-
"\nBT\n/F1 12 Tf\n72 712 Td\n( A stream ) Tj\nET" +
|
27
|
-
"\nendstream\nendobj\n"
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should compress a stream upon request" do
|
31
|
-
ref = Prawn::Core::Reference(2,{})
|
32
|
-
ref << "Hi There " * 20
|
33
|
-
|
34
|
-
cref = Prawn::Core::Reference(2,{})
|
35
|
-
cref << "Hi There " * 20
|
36
|
-
cref.compress_stream
|
37
|
-
|
38
|
-
cref.stream.size.should be < ref.stream.size,
|
39
|
-
"compressed stream expected to be smaller than source but wasn't"
|
40
|
-
cref.data[:Filter].should == :FlateDecode
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should copy the data and stream from another ref on #replace" do
|
44
|
-
from = Prawn::Core::Reference(3, {:foo => 'bar'})
|
45
|
-
from << "has a stream too"
|
46
|
-
|
47
|
-
to = Prawn::Core::Reference(4, {:foo => 'baz'})
|
48
|
-
to.replace from
|
49
|
-
|
50
|
-
# should preserve identifier but copy data and stream
|
51
|
-
to.identifier.should == 4
|
52
|
-
to.data.should == from.data
|
53
|
-
to.stream.should == from.stream
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should copy a compressed stream from a compressed ref on #replace" do
|
57
|
-
from = Prawn::Core::Reference(5, {:foo => 'bar'})
|
58
|
-
from << "has a stream too " * 20
|
59
|
-
from.compress_stream
|
60
|
-
|
61
|
-
to = Prawn::Core::Reference(6, {:foo => 'baz'})
|
62
|
-
to.replace from
|
63
|
-
|
64
|
-
to.identifier.should == 6
|
65
|
-
to.data.should == from.data
|
66
|
-
to.stream.should == from.stream
|
67
|
-
to.compressed?.should == true
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should have Length if stream present" do
|
71
|
-
ref = Prawn::Core::Reference(7, {})
|
72
|
-
ref << "Hello"
|
73
|
-
|
74
|
-
ref.data[:Length].should == 5
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should update Length when stream is updated" do
|
78
|
-
ref = Prawn::Core::Reference(7, {})
|
79
|
-
ref << "Hello"
|
80
|
-
ref.data[:Length].should == 5
|
81
|
-
|
82
|
-
ref << " world"
|
83
|
-
ref.data[:Length].should == 11
|
84
|
-
end
|
85
|
-
|
86
6
|
describe "generated via Prawn::Document" do
|
87
7
|
it "should return a proper reference on ref!" do
|
88
8
|
pdf = Prawn::Document.new
|
89
|
-
pdf.ref!({}).is_a?(
|
9
|
+
pdf.ref!({}).is_a?(PDF::Core::Reference).should == true
|
90
10
|
end
|
91
11
|
|
92
12
|
it "should return an identifier on ref" do
|
@@ -99,7 +19,7 @@ describe "A Reference object" do
|
|
99
19
|
pdf = Prawn::Document.new :compress => false
|
100
20
|
ref = pdf.ref!({})
|
101
21
|
ref << 'Hello'
|
102
|
-
ref.data[:Length].should == 5
|
22
|
+
ref.stream.data[:Length].should == 5
|
103
23
|
end
|
104
24
|
end
|
105
25
|
end
|
data/spec/repeater_spec.rb
CHANGED
data/spec/security_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "tempfile"
|
3
3
|
|
4
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
5
5
|
|
6
6
|
describe "Document encryption" do
|
7
7
|
|
@@ -31,9 +31,9 @@ describe "Document encryption" do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
describe "Setting permissions" do
|
36
|
-
|
36
|
+
|
37
37
|
def doc_with_permissions(permissions)
|
38
38
|
pdf = Prawn::Document.new
|
39
39
|
|
@@ -106,21 +106,53 @@ describe "Document encryption" do
|
|
106
106
|
describe "EncryptedPdfObject" do
|
107
107
|
|
108
108
|
it "should delegate to PdfObject for simple types" do
|
109
|
-
|
110
|
-
|
109
|
+
PDF::Core::EncryptedPdfObject(true, nil, nil, nil).should == "true"
|
110
|
+
PDF::Core::EncryptedPdfObject(42, nil, nil, nil).should == "42"
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should encrypt strings properly" do
|
114
|
-
|
114
|
+
PDF::Core::EncryptedPdfObject("foo", "12345", 123, 0).should == "<4ad6e3>"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should encrypt literal strings properly" do
|
118
|
+
PDF::Core::EncryptedPdfObject(PDF::Core::LiteralString.new("foo"), "12345", 123, 0).should == bin_string("(J\xD6\xE3)")
|
119
|
+
PDF::Core::EncryptedPdfObject(PDF::Core::LiteralString.new("lhfbqg3do5u0satu3fjf"), nil, 123, 0).should == bin_string("(\xF1\x8B\\(\b\xBB\xE18S\x130~4*#\\(%\x87\xE7\x8E\\\n)")
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should encrypt time properly" do
|
123
|
+
PDF::Core::EncryptedPdfObject(Time.utc(2050, 04, 26, 10, 17, 10), "12345", 123, 0).should == bin_string("(h\x83\xBE\xDC\xEC\x99\x0F\xD7\\)%\x13\xD4$\xB8\xF0\x16\xB8\x80\xC5\xE91+\xCF)")
|
115
124
|
end
|
116
125
|
|
117
126
|
it "should properly handle compound types" do
|
118
|
-
|
127
|
+
PDF::Core::EncryptedPdfObject({:Bar => "foo"}, "12345", 123, 0).should ==
|
119
128
|
"<< /Bar <4ad6e3>\n>>"
|
120
|
-
|
129
|
+
PDF::Core::EncryptedPdfObject(["foo", "bar"], "12345", 123, 0).should ==
|
121
130
|
"[<4ad6e3> <4ed8fe>]"
|
122
131
|
end
|
123
|
-
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "Reference#encrypted_object" do
|
136
|
+
it "should encrypt references properly" do
|
137
|
+
ref = PDF::Core::Reference(1,["foo"])
|
138
|
+
ref.encrypted_object(nil).should == "1 0 obj\n[<4fca3f>]\nendobj\n"
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should encrypt references with streams properly" do
|
142
|
+
ref = PDF::Core::Reference(1, {})
|
143
|
+
ref << 'foo'
|
144
|
+
result = bin_string("1 0 obj\n<< /Length 3\n>>\nstream\nO\xCA?\nendstream\nendobj\n")
|
145
|
+
ref.encrypted_object(nil).should == result
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "String#encrypted_object" do
|
150
|
+
it "should encrypt stream properly" do
|
151
|
+
stream = PDF::Core::Stream.new
|
152
|
+
stream << "foo"
|
153
|
+
result = bin_string("stream\nO\xCA?\nendstream\n")
|
154
|
+
stream.encrypted_object(nil, 1, 0).should == result
|
155
|
+
end
|
124
156
|
end
|
125
157
|
|
126
158
|
end
|
data/spec/soft_mask_spec.rb
CHANGED
@@ -74,44 +74,4 @@ describe "Document with soft masks" do
|
|
74
74
|
extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates
|
75
75
|
extgstates.length.should == 1
|
76
76
|
end
|
77
|
-
|
78
|
-
it "should not have objects that are not used for extended graphic state" do
|
79
|
-
@pdf = Prawn::Document.new(:margin => 0, :optimize_objects => true)
|
80
|
-
|
81
|
-
make_soft_mask do
|
82
|
-
@pdf.fill_color '808080'
|
83
|
-
@pdf.fill_rectangle [100, 100], 200, 200
|
84
|
-
end
|
85
|
-
|
86
|
-
make_soft_mask do
|
87
|
-
@pdf.fill_color '808080'
|
88
|
-
@pdf.fill_rectangle [100, 100], 200, 200
|
89
|
-
end
|
90
|
-
|
91
|
-
reader = PDF::Reader.new(StringIO.open(@pdf.render))
|
92
|
-
|
93
|
-
groups = reader.objects.select { |obj|
|
94
|
-
o = obj[1]
|
95
|
-
o.is_a?(Hash) && o[:Type] == :Group
|
96
|
-
}
|
97
|
-
groups.length.should == 1
|
98
|
-
|
99
|
-
forms = reader.objects.select { |obj|
|
100
|
-
o = obj[1]
|
101
|
-
o.is_a?(PDF::Reader::Stream) && o.hash[:Type] == :XObject && o.hash[:Subtype] == :Form
|
102
|
-
}
|
103
|
-
forms.length.should == 1
|
104
|
-
|
105
|
-
masks = reader.objects.select { |obj|
|
106
|
-
o = obj[1]
|
107
|
-
o.is_a?(Hash) && o[:Type] == :Mask
|
108
|
-
}
|
109
|
-
masks.length.should == 1
|
110
|
-
|
111
|
-
ext_g_states = reader.objects.select { |obj|
|
112
|
-
o = obj[1]
|
113
|
-
o.is_a?(Hash) && o[:Type] == :ExtGState
|
114
|
-
}
|
115
|
-
ext_g_states.length.should == 1
|
116
|
-
end
|
117
77
|
end
|
data/spec/span_spec.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
4
|
|
5
|
-
describe "drawing span" do
|
6
|
-
|
5
|
+
describe "drawing span" do
|
6
|
+
|
7
7
|
before do
|
8
8
|
Prawn.debug = false
|
9
9
|
create_pdf
|
@@ -28,9 +28,8 @@ describe "drawing span" do
|
|
28
28
|
@pdf.span(350, :position => :center) do
|
29
29
|
@pdf.text "Here's some centered text in a 350 point column. " * 100
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
@pdf.bounds.should == margin_box
|
33
|
-
|
34
33
|
end
|
35
34
|
|
36
35
|
it "should do create a margin box" do
|
@@ -38,12 +37,8 @@ describe "drawing span" do
|
|
38
37
|
margin_box = @pdf.span(350, :position => :center) do
|
39
38
|
@pdf.text "Here's some centered text in a 350 point column. " * 100
|
40
39
|
end
|
41
|
-
|
40
|
+
|
42
41
|
margin_box.top.should == 792.0
|
43
|
-
margin_box.bottom.should == 0
|
44
|
-
|
45
|
-
end
|
46
|
-
|
42
|
+
margin_box.bottom.should == 0
|
43
|
+
end
|
47
44
|
end
|
48
|
-
|
49
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -5,7 +5,14 @@ puts "Prawn specs: Running on Ruby Version: #{RUBY_VERSION}"
|
|
5
5
|
require "bundler"
|
6
6
|
Bundler.setup
|
7
7
|
|
8
|
-
|
8
|
+
if ENV["COVERAGE"]
|
9
|
+
require "simplecov"
|
10
|
+
SimpleCov.start do
|
11
|
+
add_filter "/spec/"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
9
16
|
require "prawn"
|
10
17
|
|
11
18
|
Prawn.debug = true
|
@@ -23,11 +30,22 @@ Dir[File.dirname(__FILE__) + "/extensions/**/*.rb"].each {|f| require f }
|
|
23
30
|
RSpec.configure do |config|
|
24
31
|
config.mock_framework = :mocha
|
25
32
|
config.include EncodingHelpers
|
33
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
26
34
|
end
|
27
35
|
|
28
36
|
def create_pdf(klass=Prawn::Document)
|
29
37
|
@pdf = klass.new(:margin => 0)
|
30
|
-
end
|
38
|
+
end
|
39
|
+
|
40
|
+
RSpec::Matchers.define :have_parseable_xobjects do
|
41
|
+
match do |actual|
|
42
|
+
expect { PDF::Inspector::XObject.analyze(actual.render) }.not_to raise_error
|
43
|
+
true
|
44
|
+
end
|
45
|
+
failure_message_for_should do |actual|
|
46
|
+
"expected that #{actual}'s XObjects could be successfully parsed"
|
47
|
+
end
|
48
|
+
end
|
31
49
|
|
32
50
|
# Make some methods public to assist in testing
|
33
51
|
module Prawn::Graphics
|
data/spec/stamp_spec.rb
CHANGED
@@ -3,19 +3,20 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
|
3
3
|
describe "create_stamp before any page is added" do
|
4
4
|
it "should work with the font class" do
|
5
5
|
@pdf = Prawn::Document.new(:skip_page_creation => true)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
|
7
|
+
# If anything goes wrong, Prawn::Errors::NotOnPage will be raised
|
8
|
+
@pdf.create_stamp("my_stamp") do
|
9
|
+
@pdf.font.height
|
10
|
+
end
|
11
11
|
end
|
12
|
+
|
12
13
|
it "should work with setting color" do
|
13
14
|
@pdf = Prawn::Document.new(:skip_page_creation => true)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
|
16
|
+
# If anything goes wrong, Prawn::Errors::NotOnPage will be raised
|
17
|
+
@pdf.create_stamp("my_stamp") do
|
18
|
+
@pdf.fill_color = 'ff0000'
|
19
|
+
end
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -41,7 +42,7 @@ describe "Document with a stamp" do
|
|
41
42
|
@pdf.create_stamp("MyStamp")
|
42
43
|
}.should raise_error(Prawn::Errors::NameTaken)
|
43
44
|
end
|
44
|
-
|
45
|
+
|
45
46
|
it "should raise_error InvalidName error when attempt to create "+
|
46
47
|
"stamp with a blank name" do
|
47
48
|
create_pdf
|
@@ -49,14 +50,14 @@ describe "Document with a stamp" do
|
|
49
50
|
@pdf.create_stamp("")
|
50
51
|
}.should raise_error(Prawn::Errors::InvalidName)
|
51
52
|
end
|
52
|
-
|
53
|
+
|
53
54
|
it "a new XObject should be defined for each stamp created" do
|
54
55
|
create_pdf
|
55
56
|
@pdf.create_stamp("MyStamp")
|
56
57
|
@pdf.create_stamp("AnotherStamp")
|
57
58
|
@pdf.stamp("MyStamp")
|
58
59
|
@pdf.stamp("AnotherStamp")
|
59
|
-
|
60
|
+
|
60
61
|
inspector = PDF::Inspector::XObject.analyze(@pdf.render)
|
61
62
|
xobjects = inspector.page_xobjects.last
|
62
63
|
xobjects.length.should == 2
|
@@ -105,7 +106,7 @@ describe "Document with a stamp" do
|
|
105
106
|
end
|
106
107
|
end
|
107
108
|
end
|
108
|
-
|
109
|
+
|
109
110
|
it "stamp stream should be wrapped in a graphic state" do
|
110
111
|
create_pdf
|
111
112
|
@pdf.create_stamp("MyStamp") do
|
@@ -115,11 +116,11 @@ describe "Document with a stamp" do
|
|
115
116
|
stamps = PDF::Inspector::XObject.analyze(@pdf.render)
|
116
117
|
stamps.xobject_streams[:Stamp1].data.chomp.should =~ /q(.|\s)*Q\Z/
|
117
118
|
end
|
118
|
-
|
119
|
+
|
119
120
|
it "should not add to the page graphic state stack " do
|
120
121
|
create_pdf
|
121
122
|
@pdf.state.page.stack.stack.size.should == 1
|
122
|
-
|
123
|
+
|
123
124
|
@pdf.create_stamp("MyStamp") do
|
124
125
|
@pdf.save_graphics_state
|
125
126
|
@pdf.save_graphics_state
|
@@ -129,7 +130,7 @@ describe "Document with a stamp" do
|
|
129
130
|
end
|
130
131
|
@pdf.state.page.stack.stack.size.should == 1
|
131
132
|
end
|
132
|
-
|
133
|
+
|
133
134
|
it "should be able to change fill and stroke colors within the stamp stream" do
|
134
135
|
create_pdf
|
135
136
|
@pdf.create_stamp("MyStamp") do
|
@@ -142,7 +143,7 @@ describe "Document with a stamp" do
|
|
142
143
|
stamp_stream.should include("/DeviceCMYK cs\n1.000 1.000 0.200 0.000 scn")
|
143
144
|
stamp_stream.should include("/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN")
|
144
145
|
end
|
145
|
-
|
146
|
+
|
146
147
|
it "should save the color space even when same as current page color space" do
|
147
148
|
create_pdf
|
148
149
|
@pdf.stroke_color(100, 100, 20, 0)
|
@@ -154,6 +155,4 @@ describe "Document with a stamp" do
|
|
154
155
|
stamp_stream = stamps.xobject_streams[:Stamp1].data
|
155
156
|
stamp_stream.should include("/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN")
|
156
157
|
end
|
157
|
-
|
158
|
-
|
159
158
|
end
|
data/spec/stroke_styles_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe "When stroking with default settings" do
|
|
7
7
|
it "cap_style should be :butt" do
|
8
8
|
@pdf.cap_style.should == :butt
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
it "join_style should be :miter" do
|
12
12
|
@pdf.join_style.should == :miter
|
13
13
|
end
|
@@ -19,12 +19,12 @@ end
|
|
19
19
|
|
20
20
|
describe "Cap styles" do
|
21
21
|
before(:each) { create_pdf }
|
22
|
-
|
22
|
+
|
23
23
|
it "should be able to use assignment operator" do
|
24
24
|
@pdf.cap_style = :round
|
25
25
|
@pdf.cap_style.should == :round
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
describe "#cap_style(:butt)" do
|
29
29
|
it "rendered PDF should include butt style cap" do
|
30
30
|
@pdf.cap_style(:butt)
|
@@ -60,12 +60,12 @@ end
|
|
60
60
|
|
61
61
|
describe "Join styles" do
|
62
62
|
before(:each) { create_pdf }
|
63
|
-
|
63
|
+
|
64
64
|
it "should be able to use assignment operator" do
|
65
65
|
@pdf.join_style = :round
|
66
66
|
@pdf.join_style.should == :round
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
describe "#join_style(:miter)" do
|
70
70
|
it "rendered PDF should include miter style join" do
|
71
71
|
@pdf.join_style(:miter)
|
@@ -101,7 +101,7 @@ end
|
|
101
101
|
|
102
102
|
describe "Dashes" do
|
103
103
|
before(:each) { create_pdf }
|
104
|
-
|
104
|
+
|
105
105
|
it "should be able to use assignment operator" do
|
106
106
|
@pdf.dash = 2
|
107
107
|
@pdf.should be_dashed
|
@@ -143,6 +143,24 @@ describe "Dashes" do
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
+
describe "setting a dash by using an array" do
|
147
|
+
it "dash and spaces should be set from the array" do
|
148
|
+
@pdf.dash([1,2,3,4])
|
149
|
+
dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
|
150
|
+
dashes.stroke_dash.should == [[1, 2, 3, 4], 0]
|
151
|
+
end
|
152
|
+
it "space options has to be ignored" do
|
153
|
+
@pdf.dash([1,2,3,4], :space => 3)
|
154
|
+
dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
|
155
|
+
dashes.stroke_dash.should == [[1, 2, 3, 4], 0]
|
156
|
+
end
|
157
|
+
it "phase options should be correctly used" do
|
158
|
+
@pdf.dash([1,2,3,4], :phase => 3)
|
159
|
+
dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
|
160
|
+
dashes.stroke_dash.should == [[1, 2, 3, 4], 3]
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
146
164
|
describe "clearing stroke dash" do
|
147
165
|
it "should restore solid line" do
|
148
166
|
@pdf.dash(2)
|
@@ -151,7 +169,7 @@ describe "Dashes" do
|
|
151
169
|
dashes.stroke_dash.should == [[], 0]
|
152
170
|
end
|
153
171
|
end
|
154
|
-
|
172
|
+
|
155
173
|
it "should carry the current dash settings over to new pages" do
|
156
174
|
@pdf.dash(2)
|
157
175
|
@pdf.start_new_page
|
@@ -159,19 +177,19 @@ describe "Dashes" do
|
|
159
177
|
dashes.stroke_dash_count.should == 2
|
160
178
|
dashes.stroke_dash.should == [[2, 2], 0]
|
161
179
|
end
|
162
|
-
|
180
|
+
|
163
181
|
describe "#dashed?" do
|
164
|
-
|
182
|
+
|
165
183
|
it "an initial document should not be dashed" do
|
166
184
|
@pdf.dashed?.should == false
|
167
185
|
end
|
168
|
-
|
186
|
+
|
169
187
|
it "should return true if any of the currently active settings are dashed" do
|
170
188
|
@pdf.dash(2)
|
171
189
|
@pdf.save_graphics_state
|
172
190
|
@pdf.dashed?.should == true
|
173
191
|
end
|
174
|
-
|
192
|
+
|
175
193
|
it "should return false if the document was most recently undashed" do
|
176
194
|
@pdf.dash(2)
|
177
195
|
@pdf.save_graphics_state
|
@@ -179,7 +197,7 @@ describe "Dashes" do
|
|
179
197
|
@pdf.save_graphics_state
|
180
198
|
@pdf.dashed?.should == false
|
181
199
|
end
|
182
|
-
|
200
|
+
|
183
201
|
it "should return true when restoring to a state that was dashed" do
|
184
202
|
@pdf.dash(2)
|
185
203
|
@pdf.save_graphics_state
|
@@ -187,7 +205,7 @@ describe "Dashes" do
|
|
187
205
|
@pdf.restore_graphics_state
|
188
206
|
@pdf.dashed?.should == true
|
189
207
|
end
|
190
|
-
|
208
|
+
|
191
209
|
end
|
192
210
|
|
193
211
|
end
|