prawn 0.4.1 → 0.5.0.1

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.
Files changed (179) hide show
  1. data/lib/prawn.rb +2 -72
  2. metadata +33 -224
  3. data/COPYING +0 -340
  4. data/LICENSE +0 -56
  5. data/README +0 -40
  6. data/Rakefile +0 -79
  7. data/data/encodings/win_ansi.txt +0 -29
  8. data/data/fonts/Action Man.dfont +0 -0
  9. data/data/fonts/Activa.ttf +0 -0
  10. data/data/fonts/Chalkboard.ttf +0 -0
  11. data/data/fonts/Courier-Bold.afm +0 -342
  12. data/data/fonts/Courier-BoldOblique.afm +0 -342
  13. data/data/fonts/Courier-Oblique.afm +0 -342
  14. data/data/fonts/Courier.afm +0 -342
  15. data/data/fonts/DejaVuSans.ttf +0 -0
  16. data/data/fonts/Dustismo_Roman.ttf +0 -0
  17. data/data/fonts/Helvetica-Bold.afm +0 -2827
  18. data/data/fonts/Helvetica-BoldOblique.afm +0 -2827
  19. data/data/fonts/Helvetica-Oblique.afm +0 -3051
  20. data/data/fonts/Helvetica.afm +0 -3051
  21. data/data/fonts/MustRead.html +0 -19
  22. data/data/fonts/Symbol.afm +0 -213
  23. data/data/fonts/Times-Bold.afm +0 -2588
  24. data/data/fonts/Times-BoldItalic.afm +0 -2384
  25. data/data/fonts/Times-Italic.afm +0 -2667
  26. data/data/fonts/Times-Roman.afm +0 -2419
  27. data/data/fonts/ZapfDingbats.afm +0 -225
  28. data/data/fonts/comicsans.ttf +0 -0
  29. data/data/fonts/gkai00mp.ttf +0 -0
  30. data/data/images/arrow.png +0 -0
  31. data/data/images/arrow2.png +0 -0
  32. data/data/images/barcode_issue.png +0 -0
  33. data/data/images/dice.alpha +0 -0
  34. data/data/images/dice.dat +0 -0
  35. data/data/images/dice.png +0 -0
  36. data/data/images/fractal.jpg +0 -0
  37. data/data/images/letterhead.jpg +0 -0
  38. data/data/images/page_white_text.alpha +0 -0
  39. data/data/images/page_white_text.dat +0 -0
  40. data/data/images/page_white_text.png +0 -0
  41. data/data/images/pigs.jpg +0 -0
  42. data/data/images/rails.dat +0 -0
  43. data/data/images/rails.png +0 -0
  44. data/data/images/ruport.png +0 -0
  45. data/data/images/ruport_data.dat +0 -0
  46. data/data/images/ruport_transparent.png +0 -0
  47. data/data/images/ruport_type0.png +0 -0
  48. data/data/images/stef.jpg +0 -0
  49. data/data/images/web-links.dat +0 -1
  50. data/data/images/web-links.png +0 -0
  51. data/data/shift_jis_text.txt +0 -1
  52. data/examples/bounding_box/bounding_boxes.rb +0 -44
  53. data/examples/bounding_box/lazy_bounding_boxes.rb +0 -28
  54. data/examples/bounding_box/padded_box.rb +0 -24
  55. data/examples/bounding_box/russian_boxes.rb +0 -37
  56. data/examples/general/background.rb +0 -20
  57. data/examples/general/canvas.rb +0 -16
  58. data/examples/general/measurement_units.rb +0 -52
  59. data/examples/general/multi_page_layout.rb +0 -17
  60. data/examples/general/page_geometry.rb +0 -32
  61. data/examples/graphics/basic_images.rb +0 -27
  62. data/examples/graphics/cmyk.rb +0 -13
  63. data/examples/graphics/curves.rb +0 -12
  64. data/examples/graphics/hexagon.rb +0 -14
  65. data/examples/graphics/image_fit.rb +0 -16
  66. data/examples/graphics/image_flow.rb +0 -38
  67. data/examples/graphics/image_position.rb +0 -18
  68. data/examples/graphics/line.rb +0 -33
  69. data/examples/graphics/png_types.rb +0 -23
  70. data/examples/graphics/polygons.rb +0 -17
  71. data/examples/graphics/remote_images.rb +0 -12
  72. data/examples/graphics/ruport_style_helpers.rb +0 -20
  73. data/examples/graphics/stroke_bounds.rb +0 -23
  74. data/examples/m17n/chinese_text_wrapping.rb +0 -20
  75. data/examples/m17n/euro.rb +0 -16
  76. data/examples/m17n/sjis.rb +0 -29
  77. data/examples/m17n/utf8.rb +0 -14
  78. data/examples/m17n/win_ansi_charset.rb +0 -55
  79. data/examples/text/alignment.rb +0 -19
  80. data/examples/text/dfont.rb +0 -49
  81. data/examples/text/family_based_styling.rb +0 -25
  82. data/examples/text/flowing_text_with_header_and_footer.rb +0 -37
  83. data/examples/text/font_calculations.rb +0 -92
  84. data/examples/text/font_size.rb +0 -34
  85. data/examples/text/kerning.rb +0 -31
  86. data/examples/text/simple_text.rb +0 -18
  87. data/examples/text/simple_text_ttf.rb +0 -18
  88. data/examples/text/span.rb +0 -30
  89. data/examples/text/text_box.rb +0 -26
  90. data/examples/text/text_flow.rb +0 -68
  91. data/lib/prawn/compatibility.rb +0 -38
  92. data/lib/prawn/document.rb +0 -309
  93. data/lib/prawn/document/annotations.rb +0 -63
  94. data/lib/prawn/document/bounding_box.rb +0 -368
  95. data/lib/prawn/document/destinations.rb +0 -81
  96. data/lib/prawn/document/internals.rb +0 -126
  97. data/lib/prawn/document/page_geometry.rb +0 -79
  98. data/lib/prawn/document/span.rb +0 -55
  99. data/lib/prawn/document/text.rb +0 -185
  100. data/lib/prawn/document/text/box.rb +0 -76
  101. data/lib/prawn/document/text/wrapping.rb +0 -59
  102. data/lib/prawn/encoding.rb +0 -121
  103. data/lib/prawn/errors.rb +0 -40
  104. data/lib/prawn/font.rb +0 -277
  105. data/lib/prawn/font/afm.rb +0 -202
  106. data/lib/prawn/font/dfont.rb +0 -31
  107. data/lib/prawn/font/ttf.rb +0 -326
  108. data/lib/prawn/graphics.rb +0 -257
  109. data/lib/prawn/graphics/color.rb +0 -140
  110. data/lib/prawn/images.rb +0 -339
  111. data/lib/prawn/images/jpg.rb +0 -45
  112. data/lib/prawn/images/png.rb +0 -199
  113. data/lib/prawn/literal_string.rb +0 -14
  114. data/lib/prawn/measurement_extensions.rb +0 -46
  115. data/lib/prawn/measurements.rb +0 -71
  116. data/lib/prawn/name_tree.rb +0 -165
  117. data/lib/prawn/pdf_object.rb +0 -73
  118. data/lib/prawn/reference.rb +0 -59
  119. data/spec/annotations_spec.rb +0 -90
  120. data/spec/bounding_box_spec.rb +0 -141
  121. data/spec/destinations_spec.rb +0 -15
  122. data/spec/document_spec.rb +0 -193
  123. data/spec/font_spec.rb +0 -234
  124. data/spec/graphics_spec.rb +0 -209
  125. data/spec/images_spec.rb +0 -68
  126. data/spec/jpg_spec.rb +0 -25
  127. data/spec/measurement_units_spec.rb +0 -23
  128. data/spec/name_tree_spec.rb +0 -103
  129. data/spec/pdf_object_spec.rb +0 -112
  130. data/spec/png_spec.rb +0 -196
  131. data/spec/reference_spec.rb +0 -42
  132. data/spec/spec_helper.rb +0 -23
  133. data/spec/text_spec.rb +0 -178
  134. data/vendor/pdf-inspector/README +0 -18
  135. data/vendor/pdf-inspector/lib/pdf/inspector.rb +0 -25
  136. data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +0 -80
  137. data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +0 -16
  138. data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +0 -31
  139. data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +0 -19
  140. data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
  141. data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
  142. data/vendor/ttfunk/example.rb +0 -45
  143. data/vendor/ttfunk/lib/ttfunk.rb +0 -102
  144. data/vendor/ttfunk/lib/ttfunk/directory.rb +0 -17
  145. data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +0 -88
  146. data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +0 -69
  147. data/vendor/ttfunk/lib/ttfunk/reader.rb +0 -44
  148. data/vendor/ttfunk/lib/ttfunk/resource_file.rb +0 -78
  149. data/vendor/ttfunk/lib/ttfunk/subset.rb +0 -18
  150. data/vendor/ttfunk/lib/ttfunk/subset/base.rb +0 -141
  151. data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +0 -46
  152. data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +0 -48
  153. data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +0 -63
  154. data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +0 -51
  155. data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +0 -72
  156. data/vendor/ttfunk/lib/ttfunk/table.rb +0 -46
  157. data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +0 -34
  158. data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +0 -54
  159. data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +0 -126
  160. data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +0 -79
  161. data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +0 -64
  162. data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +0 -81
  163. data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +0 -37
  164. data/vendor/ttfunk/lib/ttfunk/table/head.rb +0 -44
  165. data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +0 -41
  166. data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +0 -47
  167. data/vendor/ttfunk/lib/ttfunk/table/kern.rb +0 -79
  168. data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +0 -62
  169. data/vendor/ttfunk/lib/ttfunk/table/loca.rb +0 -43
  170. data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +0 -40
  171. data/vendor/ttfunk/lib/ttfunk/table/name.rb +0 -119
  172. data/vendor/ttfunk/lib/ttfunk/table/os2.rb +0 -78
  173. data/vendor/ttfunk/lib/ttfunk/table/post.rb +0 -91
  174. data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +0 -43
  175. data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +0 -35
  176. data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +0 -23
  177. data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +0 -17
  178. data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +0 -17
  179. data/vendor/ttfunk/lib/ttfunk/table/simple.rb +0 -14
@@ -1,73 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # pdf_object.rb : Handles Ruby to PDF object serialization
4
- #
5
- # Copyright April 2008, Gregory Brown. All Rights Reserved.
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
8
-
9
- # Top level Module
10
- #
11
- module Prawn
12
-
13
- module_function
14
-
15
- # Serializes Ruby objects to their PDF equivalents. Most primitive objects
16
- # will work as expected, but please note that Name objects are represented
17
- # by Ruby Symbol objects and Dictionary objects are represented by Ruby hashes
18
- # (keyed by symbols)
19
- #
20
- # Examples:
21
- #
22
- # PdfObject(true) #=> "true"
23
- # PdfObject(false) #=> "false"
24
- # PdfObject(1.2124) #=> "1.2124"
25
- # PdfObject("foo bar") #=> "(foo bar)"
26
- # PdfObject(:Symbol) #=> "/Symbol"
27
- # PdfObject(["foo",:bar, [1,2]]) #=> "[foo /bar [1 2]]"
28
- #
29
- def PdfObject(obj, in_content_stream = false)
30
- case(obj)
31
- when NilClass then "null"
32
- when TrueClass then "true"
33
- when FalseClass then "false"
34
- when Numeric then String(obj)
35
- when Array
36
- "[" << obj.map { |e| PdfObject(e, in_content_stream) }.join(' ') << "]"
37
- when Prawn::LiteralString
38
- obj = obj.gsub(/[\\\n\(\)]/) { |m| "\\#{m}" }
39
- "(#{obj})"
40
- when String
41
- obj = "\xFE\xFF" + obj.unpack("U*").pack("n*") unless in_content_stream
42
- "<" << obj.unpack("H*").first << ">"
43
- when Symbol
44
- if (obj = obj.to_s) =~ /\s/
45
- raise Prawn::Errors::FailedObjectConversion,
46
- "A PDF Name cannot contain whitespace"
47
- else
48
- "/" << obj
49
- end
50
- when Hash
51
- output = "<< "
52
- obj.each do |k,v|
53
- unless String === k || Symbol === k
54
- raise Prawn::Errors::FailedObjectConversion,
55
- "A PDF Dictionary must be keyed by names"
56
- end
57
- output << PdfObject(k.to_sym, in_content_stream) << " " <<
58
- PdfObject(v, in_content_stream) << "\n"
59
- end
60
- output << ">>"
61
- when Prawn::Reference
62
- obj.to_s
63
- when Prawn::NameTree::Node
64
- PdfObject(obj.to_hash)
65
- when Prawn::NameTree::Value
66
- PdfObject(obj.name) + " " + PdfObject(obj.value)
67
- else
68
- raise Prawn::Errors::FailedObjectConversion,
69
- "This object cannot be serialized to PDF"
70
- end
71
- end
72
-
73
- end
@@ -1,59 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # reference.rb : Implementation of PDF indirect objects
4
- #
5
- # Copyright April 2008, Gregory Brown. All Rights Reserved.
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
8
-
9
- require 'zlib'
10
-
11
- module Prawn
12
-
13
- class Reference #:nodoc:
14
-
15
- attr_accessor :gen, :data, :offset
16
- attr_reader :identifier, :stream
17
-
18
- def initialize(id, data, &block)
19
- @identifier = id
20
- @gen = 0
21
- @data = data
22
- @compressed = false
23
- @on_encode = block
24
- end
25
-
26
- def object
27
- @on_encode.call(self) if @on_encode
28
- output = "#{@identifier} #{gen} obj\n" <<
29
- Prawn::PdfObject(data) << "\n"
30
- if @stream
31
- output << "stream\n" << @stream << "\nendstream\n"
32
- end
33
- output << "endobj\n"
34
- end
35
-
36
- def <<(data)
37
- raise 'Cannot add data to a stream that is compressed' if @compressed
38
- (@stream ||= "") << data
39
- end
40
-
41
- def to_s
42
- "#{@identifier} #{gen} R"
43
- end
44
-
45
- def compress_stream
46
- @stream = Zlib::Deflate.deflate(@stream)
47
- @data[:Filter] = :FlateDecode
48
- @data[:Length] ||= @stream.length
49
- @compressed = true
50
- end
51
- end
52
-
53
- module_function
54
-
55
- def Reference(*args, &block) #:nodoc:
56
- Reference.new(*args, &block)
57
- end
58
-
59
- end
@@ -1,90 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- class PageAnnotations
6
- attr_reader :pages
7
-
8
- def self.parse(document)
9
- receiver = new
10
- PDF::Reader.string(document.render, receiver)
11
- return receiver
12
- end
13
-
14
- def initialize
15
- @pages = []
16
- end
17
-
18
- def begin_page(params)
19
- @pages << params
20
- end
21
- end
22
-
23
- describe "When creating annotations" do
24
-
25
- before(:each) { create_pdf }
26
-
27
- it "should append annotation to current page" do
28
- @pdf.start_new_page
29
- @pdf.annotate(:Rect => [0,0,10,10], :Subtype => :Text, :Contents => "Hello world!")
30
- obj = PageAnnotations.parse(@pdf)
31
- obj.pages[0][:Annots].nil?.should == true
32
- obj.pages[1][:Annots].length.should == 1
33
- end
34
-
35
- it "should force :Type to be :Annot" do
36
- opts = @pdf.annotate(:Rect => [0,0,10,10], :Subtype => :Text, :Contents => "Hello world!")
37
- opts[:Type].should == :Annot
38
- opts = @pdf.annotate(:Type => :Bogus, :Rect => [0,0,10,10], :Subtype => :Text, :Contents => "Hello world!")
39
- opts[:Type].should == :Annot
40
- end
41
-
42
- end
43
-
44
- describe "When creating text annotations" do
45
-
46
- before(:each) do
47
- @rect = [0,0,10,10]
48
- @content = "Hello, world!"
49
- create_pdf
50
- end
51
-
52
- it "should build appropriate annotation" do
53
- opts = @pdf.text_annotation(@rect, @content)
54
- opts[:Type].should == :Annot
55
- opts[:Subtype].should == :Text
56
- opts[:Rect].should == @rect
57
- opts[:Contents].should == @content
58
- end
59
-
60
- it "should merge extra options" do
61
- opts = @pdf.text_annotation(@rect, @content, :Open => true, :Subtype => :Bogus)
62
- opts[:Subtype].should == :Text
63
- opts[:Open].should == true
64
- end
65
-
66
- end
67
-
68
- describe "When creating link annotations" do
69
-
70
- before(:each) do
71
- @rect = [0,0,10,10]
72
- @dest = "home"
73
- create_pdf
74
- end
75
-
76
- it "should build appropriate annotation" do
77
- opts = @pdf.link_annotation(@rect, :Dest => @dest)
78
- opts[:Type].should == :Annot
79
- opts[:Subtype].should == :Link
80
- opts[:Rect].should == @rect
81
- opts[:Dest].should == @dest
82
- end
83
-
84
- it "should merge extra options" do
85
- opts = @pdf.link_annotation(@rect, :Dest => @dest, :Subtype => :Bogus)
86
- opts[:Subtype].should == :Link
87
- opts[:Dest].should == @dest
88
- end
89
-
90
- end
@@ -1,141 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- describe "A bounding box" do
6
-
7
- before(:each) do
8
- @x = 100
9
- @y = 125
10
- @width = 50
11
- @height = 75
12
- @box = Prawn::Document::BoundingBox.new(nil, [@x,@y], :width => @width,
13
- :height => @height )
14
- end
15
-
16
- it "should have an anchor at (x, y - height)" do
17
- @box.anchor.should == [@x,@y-@height]
18
- end
19
-
20
- it "should have a left boundary of 0" do
21
- @box.left.should == 0
22
- end
23
-
24
- it "should have a right boundary equal to the width" do
25
- @box.right.should == @width
26
- end
27
-
28
- it "should have a top boundary of height" do
29
- @box.top.should == @height
30
- end
31
-
32
- it "should have a bottom boundary of 0" do
33
- @box.bottom.should == 0
34
- end
35
-
36
- it "should have a top-left of [0,height]" do
37
- @box.top_left.should == [0,@height]
38
- end
39
-
40
- it "should have a top-right of [width,height]" do
41
- @box.top_right.should == [@width,@height]
42
- end
43
-
44
- it "should have a bottom-left of [0,0]" do
45
- @box.bottom_left.should == [0,0]
46
- end
47
-
48
- it "should have a bottom-right of [width,0]" do
49
- @box.bottom_right.should == [@width,0]
50
- end
51
-
52
- it "should have an absolute left boundary of x" do
53
- @box.absolute_left.should == @x
54
- end
55
-
56
- it "should have an absolute right boundary of x + width" do
57
- @box.absolute_right.should == @x + @width
58
- end
59
-
60
- it "should have an absolute top boundary of y" do
61
- @box.absolute_top.should == @y
62
- end
63
-
64
- it "should have an absolute bottom boundary of y - height" do
65
- @box.absolute_bottom.should == @y - @height
66
- end
67
-
68
- it "should have an absolute bottom-left of [x,y-height]" do
69
- @box.absolute_bottom_left.should == [@x, @y - @height]
70
- end
71
-
72
- it "should have an absolute bottom-right of [x+width,y-height]" do
73
- @box.absolute_bottom_right.should == [@x + @width , @y - @height]
74
- end
75
-
76
- it "should have an absolute top-left of [x,y]" do
77
- @box.absolute_top_left.should == [@x, @y]
78
- end
79
-
80
- it "should have an absolute top-right of [x+width,y]" do
81
- @box.absolute_top_right.should == [@x + @width, @y]
82
- end
83
-
84
-
85
- end
86
-
87
- describe "drawing bounding boxes" do
88
-
89
- before(:each) { create_pdf }
90
-
91
- it "should restore the margin box when bounding box exits" do
92
- margin_box = @pdf.bounds
93
-
94
- @pdf.bounding_box [100,500] do
95
- #nothing
96
- end
97
-
98
- @pdf.bounds.should == margin_box
99
-
100
- end
101
-
102
- it "should restore the parent bounding box when calls are nested" do
103
- @pdf.bounding_box [100,500], :width => 300, :height => 300 do
104
-
105
- @pdf.bounds.absolute_top.should == 500 + @pdf.margin_box.absolute_bottom
106
- @pdf.bounds.absolute_left.should == 100 + @pdf.margin_box.absolute_left
107
-
108
- parent_box = @pdf.bounds
109
-
110
- @pdf.bounding_box [50,200], :width => 100, :height => 100 do
111
- @pdf.bounds.absolute_top.should == 200 + parent_box.absolute_bottom
112
- @pdf.bounds.absolute_left.should == 50 + parent_box.absolute_left
113
- end
114
-
115
- @pdf.bounds.absolute_top.should == 500 + @pdf.margin_box.absolute_bottom
116
- @pdf.bounds.absolute_left.should == 100 + @pdf.margin_box.absolute_left
117
-
118
- end
119
- end
120
-
121
- it "should calculate a height if none is specified" do
122
- @pdf.bounding_box([100, 500], :width => 100) do
123
- @pdf.text "The rain in Spain falls mainly on the plains."
124
- end
125
-
126
- @pdf.y.should.be.close 458.384, 0.001
127
- end
128
-
129
- end
130
-
131
- describe "A canvas" do
132
- before(:each) { create_pdf }
133
-
134
- it "should use whatever the last set y position is" do
135
- @pdf.canvas do
136
- @pdf.bounding_box([100,500],:width => 200) { @pdf.move_down 50 }
137
- end
138
- @pdf.y.should == 450
139
- end
140
- end
141
-
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- describe "When creating destinations" do
6
-
7
- before(:each) { create_pdf }
8
-
9
- it "should add entry to Dests name tree" do
10
- @pdf.dests.data.empty?.should == true
11
- @pdf.add_dest "candy", "chocolate"
12
- @pdf.dests.data.size.should == 1
13
- end
14
-
15
- end
@@ -1,193 +0,0 @@
1
- # encoding: utf-8
2
- require "tempfile"
3
-
4
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
5
-
6
- describe "The cursor" do
7
- it "should equal pdf.y - bounds.absolute_bottom" do
8
- pdf = Prawn::Document.new
9
- pdf.cursor.should == pdf.bounds.top
10
-
11
- pdf.y = 300
12
- pdf.cursor.should == pdf.y - pdf.bounds.absolute_bottom
13
- end
14
- end
15
-
16
- describe "when generating a document from a subclass" do
17
- it "should be an instance_eval of the subclass" do
18
- custom_document = Class.new(Prawn::Document)
19
- custom_document.generate(Tempfile.new("generate_test").path) do |e|
20
- e.class.should == custom_document
21
- assert e.kind_of?(Prawn::Document)
22
- end
23
- end
24
- end
25
-
26
-
27
- describe "When creating multi-page documents" do
28
-
29
- before(:each) { create_pdf }
30
-
31
- it "should initialize with a single page" do
32
- page_counter = PDF::Inspector::Page.analyze(@pdf.render)
33
-
34
- page_counter.pages.size.should == 1
35
- @pdf.page_count.should == 1
36
- end
37
-
38
- it "should provide an accurate page_count" do
39
- 3.times { @pdf.start_new_page }
40
- page_counter = PDF::Inspector::Page.analyze(@pdf.render)
41
-
42
- page_counter.pages.size.should == 4
43
- @pdf.page_count.should == 4
44
- end
45
-
46
- end
47
-
48
- describe "When beginning each new page" do
49
-
50
- it "should execute codeblock given to Document#header" do
51
- call_count = 0
52
-
53
- pdf = Prawn::Document.new
54
- pdf.header(pdf.margin_box.top_left) do
55
- call_count += 1
56
- end
57
-
58
- pdf.start_new_page
59
- pdf.start_new_page
60
- pdf.render
61
-
62
- call_count.should == 3
63
- end
64
- describe "Background template feature" do
65
- before(:each) do
66
- @filename = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
67
- @pdf = Prawn::Document.new(:background => @filename)
68
- end
69
- it "should place a background image if it is in options block" do
70
- output = @pdf.render
71
- images = PDF::Inspector::XObject.analyze(output)
72
- # there should be 2 images in the page resources
73
- images.page_xobjects.first.size.should == 1
74
- end
75
- it "should place a background image if it is in options block" do
76
- @pdf.instance_variable_defined?(:@background).should == true
77
- @pdf.instance_variable_get(:@background).should == @filename
78
- end
79
- end
80
-
81
- end
82
-
83
- describe "When ending each page" do
84
-
85
- it "should execute codeblock given to Document#footer" do
86
-
87
- call_count = 0
88
-
89
- pdf = Prawn::Document.new
90
- pdf.footer([pdf.margin_box.left, pdf.margin_box.bottom + 50]) do
91
- call_count += 1
92
- end
93
-
94
- pdf.start_new_page
95
- pdf.start_new_page
96
- pdf.render
97
-
98
- call_count.should == 3
99
- end
100
-
101
- it "should not compress the page content stream if compression is disabled" do
102
-
103
- pdf = Prawn::Document.new(:compress => false)
104
- content_stub = pdf.ref({})
105
- content_stub.stubs(:compress_stream).returns(true)
106
- content_stub.expects(:compress_stream).never
107
-
108
- pdf.instance_variable_set("@page_content", content_stub)
109
- pdf.text "Hi There" * 20
110
- pdf.render
111
- end
112
-
113
- it "should compress the page content stream if compression is enabled" do
114
-
115
- pdf = Prawn::Document.new(:compress => true)
116
- content_stub = pdf.ref({})
117
- content_stub.stubs(:compress_stream).returns(true)
118
- content_stub.expects(:compress_stream).once
119
-
120
- pdf.instance_variable_set("@page_content", content_stub)
121
- pdf.text "Hi There" * 20
122
- pdf.render
123
- end
124
-
125
- it "should result in a smaller file size when compressed" do
126
- doc_uncompressed = Prawn::Document.new
127
- doc_compressed = Prawn::Document.new(:compress => true)
128
- [doc_compressed, doc_uncompressed].each do |pdf|
129
- pdf.font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
130
- pdf.text "更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历" * 10
131
- end
132
-
133
- doc_compressed.render.length.should.be < doc_uncompressed.render.length
134
- end
135
-
136
- end
137
-
138
- describe "When setting page size" do
139
- it "should default to LETTER" do
140
- @pdf = Prawn::Document.new
141
- pages = PDF::Inspector::Page.analyze(@pdf.render).pages
142
- pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["LETTER"]
143
- end
144
-
145
- (Prawn::Document::PageGeometry::SIZES.keys - ["LETTER"]).each do |k|
146
- it "should provide #{k} geometry" do
147
- @pdf = Prawn::Document.new(:page_size => k)
148
- pages = PDF::Inspector::Page.analyze(@pdf.render).pages
149
- pages.first[:size].should == Prawn::Document::PageGeometry::SIZES[k]
150
- end
151
- end
152
-
153
- it "should allow custom page size" do
154
- @pdf = Prawn::Document.new(:page_size => [1920, 1080] )
155
- pages = PDF::Inspector::Page.analyze(@pdf.render).pages
156
- pages.first[:size].should == [1920, 1080]
157
- end
158
-
159
- end
160
-
161
- describe "When setting page layout" do
162
- it "should reverse coordinates for landscape" do
163
- @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
164
- pages = PDF::Inspector::Page.analyze(@pdf.render).pages
165
- pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["A4"].reverse
166
- end
167
- end
168
-
169
- describe "The mask() feature" do
170
- it "should allow transactional restoration of attributes" do
171
- @pdf = Prawn::Document.new
172
- y, line_width = @pdf.y, @pdf.line_width
173
- @pdf.mask(:y, :line_width) do
174
- @pdf.y = y + 1
175
- @pdf.line_width = line_width + 1
176
- @pdf.y.should.not == y
177
- @pdf.line_width.should.not == line_width
178
- end
179
- @pdf.y.should == y
180
- @pdf.line_width.should == line_width
181
- end
182
- end
183
-
184
- describe "The render() feature" do
185
- if "spec".respond_to?(:encode!)
186
- it "should return a 8 bit encoded string on a m17n aware VM" do
187
- @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
188
- @pdf.line [100,100], [200,200]
189
- str = @pdf.render
190
- str.encoding.to_s.should == "ASCII-8BIT"
191
- end
192
- end
193
- end