prawn 0.4.1 → 0.5.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
data/spec/font_spec.rb DELETED
@@ -1,234 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
- require 'iconv'
5
-
6
- describe "Font behavior" do
7
-
8
- it "should default to Helvetica if no font is specified" do
9
- @pdf = Prawn::Document.new
10
- @pdf.font.name.should == "Helvetica"
11
- end
12
-
13
- end
14
-
15
- describe "font style support" do
16
- before(:each) { create_pdf }
17
-
18
- it "should allow specifying font style by style name and font family" do
19
- @pdf.font "Courier", :style => :bold
20
- @pdf.text "In Courier bold"
21
-
22
- @pdf.font "Courier", :style => :bold_italic
23
- @pdf.text "In Courier bold-italic"
24
-
25
- @pdf.font "Courier", :style => :italic
26
- @pdf.text "In Courier italic"
27
-
28
- @pdf.font "Courier", :style => :normal
29
- @pdf.text "In Normal Courier"
30
-
31
- @pdf.font "Helvetica"
32
- @pdf.text "In Normal Helvetica"
33
-
34
- text = PDF::Inspector::Text.analyze(@pdf.render)
35
- text.font_settings.map { |e| e[:name] }.should ==
36
- [:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
37
- :Courier, :Helvetica]
38
- end
39
-
40
- it "should allow font familes to be defined in a single dfont" do
41
- file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
42
- @pdf.font_families["Action Man"] = {
43
- :normal => { :file => file, :font => "ActionMan" },
44
- :italic => { :file => file, :font => "ActionMan-Italic" },
45
- :bold => { :file => file, :font => "ActionMan-Bold" },
46
- :bold_italic => { :file => file, :font => "ActionMan-BoldItalic" }
47
- }
48
-
49
- @pdf.font "Action Man", :style => :italic
50
- @pdf.text "In ActionMan-Italic"
51
-
52
- text = PDF::Inspector::Text.analyze(@pdf.render)
53
- name = text.font_settings.map { |e| e[:name] }.first
54
- name = name.unpack("n*")[2..-1].pack("U*")
55
- name = name.sub(/\w+\+/, "subset+")
56
- name.should == "subset+ActionMan-Italic"
57
- end
58
- end
59
-
60
- describe "Transactional font handling" do
61
- before(:each) { create_pdf }
62
-
63
- it "should allow setting of size directly when font is created" do
64
- @pdf.font "Courier", :size => 16
65
- @pdf.font_size.should == 16
66
- end
67
-
68
- it "should allow temporary setting of a new font using a transaction" do
69
- @pdf.font "Helvetica", :size => 12
70
-
71
- @pdf.font "Courier", :size => 16 do
72
- @pdf.font.name.should == "Courier"
73
- @pdf.font_size.should == 16
74
- end
75
-
76
- @pdf.font.name.should == "Helvetica"
77
- @pdf.font_size.should == 12
78
- end
79
-
80
- it "should mask font size when using a transacation" do
81
- @pdf.font "Courier", :size => 16 do
82
- @pdf.font_size.should == 16
83
- end
84
-
85
- @pdf.font "Times-Roman"
86
- @pdf.font "Courier"
87
-
88
- @pdf.font_size.should == 12
89
- end
90
-
91
- end
92
-
93
- describe "Document#page_fonts" do
94
- before(:each) { create_pdf }
95
-
96
- it "should register fonts properly by page" do
97
- @pdf.font "Courier"; @pdf.text("hello")
98
- @pdf.font "Helvetica"; @pdf.text("hello")
99
- @pdf.font "Times-Roman"; @pdf.text("hello")
100
- ["Courier","Helvetica","Times-Roman"].each { |f|
101
- page_should_include_font(f)
102
- }
103
-
104
- @pdf.start_new_page
105
- @pdf.font "Helvetica"; @pdf.text("hello")
106
- page_should_include_font("Helvetica")
107
- page_should_not_include_font("Courier")
108
- page_should_not_include_font("Times-Roman")
109
- end
110
-
111
- def page_includes_font?(font)
112
- @pdf.page_fonts.values.map { |e| e.data[:BaseFont] }.include?(font.to_sym)
113
- end
114
-
115
- def page_should_include_font(font)
116
- assert_block("Expected page to include font: #{font}") do
117
- page_includes_font?(font)
118
- end
119
- end
120
-
121
- def page_should_not_include_font(font)
122
- assert_block("Did not expect page to include font: #{font}") do
123
- not page_includes_font?(font)
124
- end
125
- end
126
-
127
- end
128
-
129
- describe "AFM fonts" do
130
-
131
- setup do
132
- create_pdf
133
- @times = @pdf.find_font "Times-Roman"
134
- @iconv = ::Iconv.new('Windows-1252', 'utf-8')
135
- end
136
-
137
- it "should calculate string width taking into account accented characters" do
138
- @times.width_of(@iconv.iconv("é"), :size => 12).should == @times.width_of("e", :size => 12)
139
- end
140
-
141
- it "should calculate string width taking into account kerning pairs" do
142
- @times.width_of(@iconv.iconv("To"), :size => 12).should == 13.332
143
- @times.width_of(@iconv.iconv("To"), :size => 12, :kerning => true).should == 12.372
144
- @times.width_of(@iconv.iconv("Tö"), :size => 12, :kerning => true).should == 12.372
145
- end
146
-
147
- it "should encode text without kerning by default" do
148
- @times.encode_text(@iconv.iconv("To")).should == [[0, "To"]]
149
- @times.encode_text(@iconv.iconv("Télé")).should == [[0, @iconv.iconv("Télé")]]
150
- @times.encode_text(@iconv.iconv("Technology")).should == [[0, "Technology"]]
151
- @times.encode_text(@iconv.iconv("Technology...")).should == [[0, "Technology..."]]
152
- end
153
-
154
- it "should encode text with kerning if requested" do
155
- @times.encode_text(@iconv.iconv("To"), :kerning => true).should == [[0, ["T", 80, "o"]]]
156
- @times.encode_text(@iconv.iconv("Télé"), :kerning => true).should == [[0, ["T", 70, @iconv.iconv("élé")]]]
157
- @times.encode_text(@iconv.iconv("Technology"), :kerning => true).should == [[0, ["T", 70, "echnology"]]]
158
- @times.encode_text(@iconv.iconv("Technology..."), :kerning => true).should == [[0, ["T", 70, "echnology", 65, "..."]]]
159
- end
160
-
161
- end
162
-
163
- describe "TTF fonts" do
164
-
165
- setup do
166
- create_pdf
167
- @activa = @pdf.find_font "#{Prawn::BASEDIR}/data/fonts/Activa.ttf"
168
- end
169
-
170
- it "should calculate string width taking into account accented characters" do
171
- @activa.width_of("é", :size => 12).should == @activa.width_of("e", :size => 12)
172
- end
173
-
174
- it "should calculate string width taking into account kerning pairs" do
175
- @activa.width_of("To", :size => 12).should == 15.228
176
- @activa.width_of("To", :size => 12, :kerning => true).should == 12.996
177
- end
178
-
179
- it "should encode text without kerning by default" do
180
- @activa.encode_text("To").should == [[0, "To"]]
181
- @activa.encode_text("Télé").should == [[0, "T\216l\216"]]
182
- @activa.encode_text("Technology").should == [[0, "Technology"]]
183
- @activa.encode_text("Technology...").should == [[0, "Technology..."]]
184
- @activa.encode_text("Teχnology...").should == [[0, "Te"], [1, "!"], [0, "nology..."]]
185
- end
186
-
187
- it "should encode text with kerning if requested" do
188
- @activa.encode_text("To", :kerning => true).should == [[0, ["T", 186.0, "o"]]]
189
- @activa.encode_text("To", :kerning => true).should == [[0, ["T", 186.0, "o"]]]
190
- @activa.encode_text("Technology", :kerning => true).should == [[0, ["T", 186.0, "echnology"]]]
191
- @activa.encode_text("Technology...", :kerning => true).should == [[0, ["T", 186.0, "echnology", 88.0, "..."]]]
192
- @activa.encode_text("Teχnology...", :kerning => true).should == [[0, ["T", 186.0, "e"]], [1, "!"], [0, ["nology", 88.0, "..."]]]
193
- end
194
-
195
- end
196
-
197
- describe "DFont fonts" do
198
- setup do
199
- create_pdf
200
- @file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
201
- end
202
-
203
- it "should list all named fonts" do
204
- list = Prawn::Font::DFont.named_fonts(@file)
205
- list.sort.should == %w(ActionMan ActionMan-Italic ActionMan-Bold ActionMan-BoldItalic).sort
206
- end
207
-
208
- it "should count the number of fonts in the file" do
209
- Prawn::Font::DFont.font_count(@file).should == 4
210
- end
211
-
212
- it "should default selected font to the first one if not specified" do
213
- font = @pdf.find_font(@file)
214
- font.basename.should == "ActionMan"
215
- end
216
-
217
- it "should allow font to be selected by index" do
218
- font = @pdf.find_font(@file, :font => 2)
219
- font.basename.should == "ActionMan-Italic"
220
- end
221
-
222
- it "should allow font to be selected by name" do
223
- font = @pdf.find_font(@file, :font => "ActionMan-BoldItalic")
224
- font.basename.should == "ActionMan-BoldItalic"
225
- end
226
-
227
- it "should cache font object based on selected font" do
228
- f1 = @pdf.find_font(@file, :font => "ActionMan")
229
- f2 = @pdf.find_font(@file, :font => "ActionMan-Bold")
230
- assert_not_equal f1.object_id, f2.object_id
231
- assert_equal f1.object_id, @pdf.find_font(@file, :font => "ActionMan").object_id
232
- assert_equal f2.object_id, @pdf.find_font(@file, :font => "ActionMan-Bold").object_id
233
- end
234
- end
@@ -1,209 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- describe "When drawing a line" do
6
-
7
- before(:each) { create_pdf }
8
-
9
- it "should draw a line from (100,600) to (100,500)" do
10
- @pdf.line([100,600],[100,500])
11
-
12
- line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
13
-
14
- line_drawing.points.should == [[100,600],[100,500]]
15
- end
16
-
17
- it "should draw two lines at (100,600) to (100,500) " +
18
- "and (75,100) to (50,125)" do
19
- @pdf.line(100,600,100,500)
20
- @pdf.line(75,100,50,125)
21
-
22
- line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
23
-
24
- line_drawing.points.should ==
25
- [[100.0, 600.0], [100.0, 500.0], [75.0, 100.0], [50.0, 125.0]]
26
- end
27
-
28
- it "should properly set line width via line_width=" do
29
- @pdf.line_width = 10
30
- line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
31
- line.widths.first.should == 10
32
- end
33
-
34
- it "should properly set line width via line_width(width)" do
35
- @pdf.line_width(10)
36
- line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
37
- line.widths.first.should == 10
38
- end
39
-
40
- describe "(Horizontally)" do
41
- it "should draw from [x1,pdf.y],[x2,pdf.y]" do
42
- @pdf.horizontal_line(100,150)
43
- @line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
44
- @line.points.should == [[100.0 + @pdf.bounds.absolute_left, @pdf.y],
45
- [150.0 + @pdf.bounds.absolute_left, @pdf.y]]
46
- end
47
-
48
- it "should draw a line from (200, 250) to (300, 250)" do
49
- @pdf.horizontal_line(200,300,:at => 250)
50
- line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
51
- line_drawing.points.should == [[200,250],[300,250]]
52
- end
53
- end
54
-
55
- describe "(Vertically)" do
56
- it "should draw a line from (350, 300) to (350, 400)" do
57
- @pdf.vertical_line(300,400,:at => 350)
58
- line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
59
- line_drawing.points.should == [[350,300],[350,400]]
60
- end
61
- it "should require a y coordinate" do
62
- lambda { @pdf.vertical_line(400,500) }.
63
- should.raise(ArgumentError)
64
- end
65
- end
66
-
67
- end
68
-
69
- describe "When drawing a polygon" do
70
-
71
- before(:each) { create_pdf }
72
-
73
- it "should draw each line passed to polygon()" do
74
- @pdf.polygon([100,500],[100,400],[200,400])
75
-
76
- line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
77
- line_drawing.points.should == [[100,500],[100,400],[200,400],[100,500]]
78
- end
79
-
80
- end
81
-
82
- describe "When drawing a rectangle" do
83
-
84
- before(:each) { create_pdf }
85
-
86
- it "should use a point, width, and height for coords" do
87
- @pdf.rectangle [200,200], 50, 100
88
-
89
- rectangles = PDF::Inspector::Graphics::Rectangle.
90
- analyze(@pdf.render).rectangles
91
- # PDF uses bottom left corner
92
- rectangles[0][:point].should == [200,100]
93
- rectangles[0][:width].should == 50
94
- rectangles[0][:height].should == 100
95
-
96
- end
97
-
98
- end
99
-
100
- describe "When drawing a curve" do
101
-
102
- before(:each) { create_pdf }
103
-
104
- it "should draw a bezier curve from 50,50 to 100,100" do
105
- @pdf.move_to [50,50]
106
- @pdf.curve_to [100,100],:bounds => [[20,90], [90,70]]
107
- curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
108
- curve.coords.should == [50.0, 50.0, 20.0, 90.0, 90.0, 70.0, 100.0, 100.0]
109
- end
110
-
111
- it "should draw a bezier curve from 100,100 to 50,50" do
112
- @pdf.curve [100,100], [50,50], :bounds => [[20,90], [90,75]]
113
- curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
114
- curve.coords.should == [100.0, 100.0, 20.0, 90.0, 90.0, 75.0, 50.0, 50.0]
115
- end
116
-
117
- end
118
-
119
- describe "When drawing an ellipse" do
120
- before(:each) do
121
- create_pdf
122
- @pdf.ellipse_at [100,100], 25, 50
123
- @curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
124
- end
125
-
126
- it "should move the pointer to the center of the ellipse after drawing" do
127
- @curve.coords[-2..-1].should == [100,100]
128
- end
129
-
130
- end
131
-
132
- describe "When drawing a circle" do
133
- before(:each) do
134
- create_pdf
135
- @pdf.circle_at [100,100], :radius => 25
136
- @pdf.ellipse_at [100,100], 25, 25
137
- @curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
138
- end
139
-
140
- it "should stroke the same path as the equivalent ellipse" do
141
- middle = @curve.coords.length / 2
142
- @curve.coords[0...middle].should == @curve.coords[middle..-1]
143
- end
144
- end
145
-
146
- describe "When setting colors" do
147
-
148
- before(:each) { create_pdf }
149
-
150
- it "should set stroke colors" do
151
- @pdf.stroke_color "ffcccc"
152
- colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
153
- # 100% red, 80% green, 80% blue
154
- colors.stroke_color.should == [1.0, 0.8, 0.8]
155
- end
156
-
157
- it "should set fill colors" do
158
- @pdf.fill_color "ccff00"
159
- colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
160
- # 80% red, 100% green, 0% blue
161
- colors.fill_color.should == [0.8,1.0,0]
162
- end
163
-
164
- it "should reset the colors on each new page if they have been defined" do
165
- @pdf.fill_color "ccff00"
166
- colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
167
-
168
- colors.fill_color_count.should == 2
169
- colors.stroke_color_count.should == 1
170
- @pdf.start_new_page
171
- @pdf.stroke_color "ff00cc"
172
-
173
- colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
174
- colors.fill_color_count.should == 3
175
- colors.stroke_color_count.should == 3
176
-
177
- @pdf.start_new_page
178
- colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
179
- colors.fill_color_count.should == 4
180
- colors.stroke_color_count.should == 4
181
-
182
- colors.fill_color.should == [0.8,1.0,0.0]
183
- colors.stroke_color.should == [1.0,0.0,0.8]
184
- end
185
-
186
- end
187
-
188
- describe "When using painting shortcuts" do
189
- before(:each) { create_pdf }
190
-
191
- it "should convert stroke_some_method(args) into some_method(args); stroke" do
192
- @pdf.expects(:line_to).with([100,100])
193
- @pdf.expects(:stroke)
194
-
195
- @pdf.stroke_line_to [100,100]
196
- end
197
-
198
- it "should convert fill_some_method(args) into some_method(args); fill" do
199
- @pdf.expects(:line_to).with([100,100])
200
- @pdf.expects(:fill)
201
-
202
- @pdf.fill_line_to [100,100]
203
- end
204
-
205
- it "should not break method_missing" do
206
- lambda { @pdf.i_have_a_pretty_girlfriend_named_jia }.
207
- should.raise(NoMethodError)
208
- end
209
- end
data/spec/images_spec.rb DELETED
@@ -1,68 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- describe "the image() function" do
6
-
7
- before(:each) do
8
- @filename = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
9
- create_pdf
10
- end
11
-
12
- it "should only embed an image once, even if it's added multiple times" do
13
- @pdf.image @filename, :at => [100,100]
14
- @pdf.image @filename, :at => [300,300]
15
-
16
- output = @pdf.render
17
- images = PDF::Inspector::XObject.analyze(output)
18
- # there should be 2 images in the page resources
19
- images.page_xobjects.first.size.should == 2
20
- # but only 1 image xobject
21
- output.scan(/\/Type \/XObject/).size.should == 1
22
- end
23
-
24
- it "should return the image info object" do
25
- info = @pdf.image(@filename)
26
-
27
- assert info.kind_of?(Prawn::Images::JPG)
28
-
29
- info.height.should == 453
30
- end
31
-
32
- it "should accept IO objects" do
33
- file = File.open(@filename, "rb")
34
- info = @pdf.image(file)
35
-
36
- info.height.should == 453
37
- end
38
-
39
- describe ":fit option" do
40
- it "should fit inside the defined constraints" do
41
- info = @pdf.image @filename, :fit => [100,400]
42
- info.scaled_width.should <= 100
43
- info.scaled_height.should <= 400
44
-
45
- info = @pdf.image @filename, :fit => [400,100]
46
- info.scaled_width.should <= 400
47
- info.scaled_height.should <= 100
48
-
49
- info = @pdf.image @filename, :fit => [604,453]
50
- info.scaled_width.should == 604
51
- info.scaled_height.should == 453
52
- end
53
- it "should move text position" do
54
- @y = @pdf.y
55
- info = @pdf.image @filename, :fit => [100,400]
56
- @pdf.y.should < @y
57
- end
58
- end
59
- describe ":at option" do
60
- it "should not move text position" do
61
- @y = @pdf.y
62
- info = @pdf.image @filename, :at => [100,400]
63
- @pdf.y.should == @y
64
- end
65
- end
66
-
67
- end
68
-