piglop-prawn 0.10.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (276) hide show
  1. data/COPYING +340 -0
  2. data/HACKING +49 -0
  3. data/LICENSE +56 -0
  4. data/README +140 -0
  5. data/Rakefile +52 -0
  6. data/data/encodings/win_ansi.txt +29 -0
  7. data/data/fonts/Action Man.dfont +0 -0
  8. data/data/fonts/Activa.ttf +0 -0
  9. data/data/fonts/Chalkboard.ttf +0 -0
  10. data/data/fonts/Courier-Bold.afm +342 -0
  11. data/data/fonts/Courier-BoldOblique.afm +342 -0
  12. data/data/fonts/Courier-Oblique.afm +342 -0
  13. data/data/fonts/Courier.afm +342 -0
  14. data/data/fonts/DejaVuSans.ttf +0 -0
  15. data/data/fonts/Dustismo_Roman.ttf +0 -0
  16. data/data/fonts/Helvetica-Bold.afm +2827 -0
  17. data/data/fonts/Helvetica-BoldOblique.afm +2827 -0
  18. data/data/fonts/Helvetica-Oblique.afm +3051 -0
  19. data/data/fonts/Helvetica.afm +3051 -0
  20. data/data/fonts/MustRead.html +19 -0
  21. data/data/fonts/Symbol.afm +213 -0
  22. data/data/fonts/Times-Bold.afm +2588 -0
  23. data/data/fonts/Times-BoldItalic.afm +2384 -0
  24. data/data/fonts/Times-Italic.afm +2667 -0
  25. data/data/fonts/Times-Roman.afm +2419 -0
  26. data/data/fonts/ZapfDingbats.afm +225 -0
  27. data/data/fonts/comicsans.ttf +0 -0
  28. data/data/fonts/gkai00mp.ttf +0 -0
  29. data/data/images/16bit.alpha +0 -0
  30. data/data/images/16bit.dat +0 -0
  31. data/data/images/16bit.png +0 -0
  32. data/data/images/arrow.png +0 -0
  33. data/data/images/arrow2.png +0 -0
  34. data/data/images/barcode_issue.png +0 -0
  35. data/data/images/dice.alpha +0 -0
  36. data/data/images/dice.dat +0 -0
  37. data/data/images/dice.png +0 -0
  38. data/data/images/dice_interlaced.png +0 -0
  39. data/data/images/fractal.jpg +0 -0
  40. data/data/images/letterhead.jpg +0 -0
  41. data/data/images/page_white_text.alpha +0 -0
  42. data/data/images/page_white_text.dat +0 -0
  43. data/data/images/page_white_text.png +0 -0
  44. data/data/images/pigs.jpg +0 -0
  45. data/data/images/rails.dat +0 -0
  46. data/data/images/rails.png +0 -0
  47. data/data/images/ruport.png +0 -0
  48. data/data/images/ruport_data.dat +0 -0
  49. data/data/images/ruport_transparent.png +0 -0
  50. data/data/images/ruport_type0.png +0 -0
  51. data/data/images/stef.jpg +0 -0
  52. data/data/images/tru256.bmp +0 -0
  53. data/data/images/web-links.dat +1 -0
  54. data/data/images/web-links.png +0 -0
  55. data/data/pdfs/complex_template.pdf +0 -0
  56. data/data/pdfs/contains_ttf_font.pdf +0 -0
  57. data/data/pdfs/encrypted.pdf +0 -0
  58. data/data/pdfs/hexagon.pdf +61 -0
  59. data/data/pdfs/indirect_reference.pdf +86 -0
  60. data/data/pdfs/nested_pages.pdf +118 -0
  61. data/data/pdfs/resources_as_indirect_object.pdf +83 -0
  62. data/data/pdfs/two_hexagons.pdf +90 -0
  63. data/data/pdfs/version_1_6.pdf +61 -0
  64. data/data/shift_jis_text.txt +1 -0
  65. data/examples/bounding_box/bounding_boxes.rb +43 -0
  66. data/examples/bounding_box/indentation.rb +34 -0
  67. data/examples/bounding_box/russian_boxes.rb +36 -0
  68. data/examples/bounding_box/stretched_nesting.rb +67 -0
  69. data/examples/example_helper.rb +4 -0
  70. data/examples/general/background.rb +23 -0
  71. data/examples/general/canvas.rb +15 -0
  72. data/examples/general/context_sensitive_headers.rb +37 -0
  73. data/examples/general/float.rb +11 -0
  74. data/examples/general/margin.rb +36 -0
  75. data/examples/general/measurement_units.rb +51 -0
  76. data/examples/general/metadata-info.rb +16 -0
  77. data/examples/general/multi_page_layout.rb +18 -0
  78. data/examples/general/outlines.rb +50 -0
  79. data/examples/general/page_geometry.rb +31 -0
  80. data/examples/general/page_numbering.rb +15 -0
  81. data/examples/general/repeaters.rb +47 -0
  82. data/examples/general/stamp.rb +41 -0
  83. data/examples/general/templates.rb +13 -0
  84. data/examples/graphics/basic_images.rb +23 -0
  85. data/examples/graphics/cmyk.rb +12 -0
  86. data/examples/graphics/curves.rb +11 -0
  87. data/examples/graphics/hexagon.rb +13 -0
  88. data/examples/graphics/image_fit.rb +15 -0
  89. data/examples/graphics/image_flow.rb +37 -0
  90. data/examples/graphics/image_position.rb +17 -0
  91. data/examples/graphics/line.rb +32 -0
  92. data/examples/graphics/png_types.rb +22 -0
  93. data/examples/graphics/polygons.rb +16 -0
  94. data/examples/graphics/remote_images.rb +12 -0
  95. data/examples/graphics/rounded_polygons.rb +19 -0
  96. data/examples/graphics/rounded_rectangle.rb +20 -0
  97. data/examples/graphics/ruport_style_helpers.rb +19 -0
  98. data/examples/graphics/stroke_bounds.rb +20 -0
  99. data/examples/graphics/stroke_cap_and_join.rb +45 -0
  100. data/examples/graphics/stroke_dash.rb +42 -0
  101. data/examples/graphics/transformations.rb +52 -0
  102. data/examples/graphics/transparency.rb +26 -0
  103. data/examples/m17n/chinese_text_wrapping.rb +17 -0
  104. data/examples/m17n/euro.rb +15 -0
  105. data/examples/m17n/sjis.rb +28 -0
  106. data/examples/m17n/utf8.rb +13 -0
  107. data/examples/m17n/win_ansi_charset.rb +54 -0
  108. data/examples/security/hello_foo.rb +8 -0
  109. data/examples/table/bill.rb +53 -0
  110. data/examples/table/cell.rb +12 -0
  111. data/examples/table/checkerboard.rb +22 -0
  112. data/examples/table/header.rb +14 -0
  113. data/examples/table/inline_format_table.rb +12 -0
  114. data/examples/table/multi_page_table.rb +9 -0
  115. data/examples/table/simple_table.rb +24 -0
  116. data/examples/table/subtable.rb +12 -0
  117. data/examples/table/widths.rb +20 -0
  118. data/examples/text/alignment.rb +18 -0
  119. data/examples/text/dfont.rb +48 -0
  120. data/examples/text/family_based_styling.rb +24 -0
  121. data/examples/text/font_calculations.rb +91 -0
  122. data/examples/text/font_size.rb +33 -0
  123. data/examples/text/hyphenation.rb +45 -0
  124. data/examples/text/indent_paragraphs.rb +18 -0
  125. data/examples/text/inline_format.rb +72 -0
  126. data/examples/text/kerning.rb +30 -0
  127. data/examples/text/rotated.rb +98 -0
  128. data/examples/text/shaped_text_box.rb +31 -0
  129. data/examples/text/simple_text.rb +17 -0
  130. data/examples/text/simple_text_ttf.rb +17 -0
  131. data/examples/text/text_box.rb +88 -0
  132. data/examples/text/text_box_returning_excess.rb +51 -0
  133. data/examples/text/text_flow.rb +67 -0
  134. data/lib/prawn/compatibility.rb +51 -0
  135. data/lib/prawn/core/annotations.rb +61 -0
  136. data/lib/prawn/core/byte_string.rb +9 -0
  137. data/lib/prawn/core/destinations.rb +90 -0
  138. data/lib/prawn/core/document_state.rb +84 -0
  139. data/lib/prawn/core/literal_string.rb +16 -0
  140. data/lib/prawn/core/name_tree.rb +165 -0
  141. data/lib/prawn/core/object_store.rb +219 -0
  142. data/lib/prawn/core/page.rb +179 -0
  143. data/lib/prawn/core/pdf_object.rb +83 -0
  144. data/lib/prawn/core/reference.rb +112 -0
  145. data/lib/prawn/core/text/formatted/arranger.rb +260 -0
  146. data/lib/prawn/core/text/formatted/line_wrap.rb +127 -0
  147. data/lib/prawn/core/text/formatted/wrap.rb +113 -0
  148. data/lib/prawn/core/text/line_wrap.rb +198 -0
  149. data/lib/prawn/core/text/wrap.rb +80 -0
  150. data/lib/prawn/core/text.rb +115 -0
  151. data/lib/prawn/core.rb +89 -0
  152. data/lib/prawn/document/bounding_box.rb +425 -0
  153. data/lib/prawn/document/graphics_state.rb +48 -0
  154. data/lib/prawn/document/internals.rb +176 -0
  155. data/lib/prawn/document/page_geometry.rb +136 -0
  156. data/lib/prawn/document/snapshot.rb +87 -0
  157. data/lib/prawn/document.rb +573 -0
  158. data/lib/prawn/encoding.rb +121 -0
  159. data/lib/prawn/errors.rb +94 -0
  160. data/lib/prawn/font/afm.rb +225 -0
  161. data/lib/prawn/font/dfont.rb +42 -0
  162. data/lib/prawn/font/ttf.rb +350 -0
  163. data/lib/prawn/font.rb +342 -0
  164. data/lib/prawn/graphics/cap_style.rb +38 -0
  165. data/lib/prawn/graphics/color.rb +205 -0
  166. data/lib/prawn/graphics/dash.rb +71 -0
  167. data/lib/prawn/graphics/join_style.rb +38 -0
  168. data/lib/prawn/graphics/transformation.rb +156 -0
  169. data/lib/prawn/graphics/transparency.rb +99 -0
  170. data/lib/prawn/graphics.rb +321 -0
  171. data/lib/prawn/images/jpg.rb +46 -0
  172. data/lib/prawn/images/png.rb +226 -0
  173. data/lib/prawn/images.rb +348 -0
  174. data/lib/prawn/measurement_extensions.rb +46 -0
  175. data/lib/prawn/measurements.rb +71 -0
  176. data/lib/prawn/outline.rb +278 -0
  177. data/lib/prawn/repeater.rb +129 -0
  178. data/lib/prawn/security/arcfour.rb +51 -0
  179. data/lib/prawn/security.rb +262 -0
  180. data/lib/prawn/stamp.rb +126 -0
  181. data/lib/prawn/table/accessors.rb +180 -0
  182. data/lib/prawn/table/cell/in_table.rb +27 -0
  183. data/lib/prawn/table/cell/subtable.rb +65 -0
  184. data/lib/prawn/table/cell/text.rb +128 -0
  185. data/lib/prawn/table/cell.rb +330 -0
  186. data/lib/prawn/table.rb +421 -0
  187. data/lib/prawn/text/box.rb +380 -0
  188. data/lib/prawn/text/formatted/box.rb +215 -0
  189. data/lib/prawn/text/formatted/fragment.rb +127 -0
  190. data/lib/prawn/text/formatted/parser.rb +202 -0
  191. data/lib/prawn/text/formatted.rb +4 -0
  192. data/lib/prawn/text.rb +442 -0
  193. data/lib/prawn.rb +25 -0
  194. data/spec/annotations_spec.rb +90 -0
  195. data/spec/bounding_box_spec.rb +190 -0
  196. data/spec/cell_spec.rb +337 -0
  197. data/spec/destinations_spec.rb +15 -0
  198. data/spec/document_spec.rb +461 -0
  199. data/spec/font_spec.rb +314 -0
  200. data/spec/formatted_text_arranger_spec.rb +400 -0
  201. data/spec/formatted_text_box_spec.rb +659 -0
  202. data/spec/formatted_text_fragment_spec.rb +211 -0
  203. data/spec/graphics_spec.rb +446 -0
  204. data/spec/images_spec.rb +96 -0
  205. data/spec/inline_formatted_text_parser_spec.rb +446 -0
  206. data/spec/jpg_spec.rb +25 -0
  207. data/spec/line_wrap_spec.rb +341 -0
  208. data/spec/measurement_units_spec.rb +23 -0
  209. data/spec/name_tree_spec.rb +112 -0
  210. data/spec/object_store_spec.rb +160 -0
  211. data/spec/outline_spec.rb +229 -0
  212. data/spec/pdf_object_spec.rb +127 -0
  213. data/spec/png_spec.rb +237 -0
  214. data/spec/reference_spec.rb +82 -0
  215. data/spec/repeater_spec.rb +96 -0
  216. data/spec/security_spec.rb +120 -0
  217. data/spec/snapshot_spec.rb +138 -0
  218. data/spec/spec_helper.rb +26 -0
  219. data/spec/stamp_spec.rb +108 -0
  220. data/spec/stroke_styles_spec.rb +163 -0
  221. data/spec/table_spec.rb +583 -0
  222. data/spec/template_spec.rb +158 -0
  223. data/spec/text_at_spec.rb +119 -0
  224. data/spec/text_box_spec.rb +675 -0
  225. data/spec/text_spacing_spec.rb +57 -0
  226. data/spec/text_spec.rb +328 -0
  227. data/spec/text_with_inline_formatting_spec.rb +193 -0
  228. data/spec/transparency_spec.rb +75 -0
  229. data/vendor/pdf-inspector/README +18 -0
  230. data/vendor/pdf-inspector/lib/pdf/inspector/extgstate.rb +18 -0
  231. data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +131 -0
  232. data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +25 -0
  233. data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +46 -0
  234. data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +19 -0
  235. data/vendor/pdf-inspector/lib/pdf/inspector.rb +26 -0
  236. data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
  237. data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
  238. data/vendor/ttfunk/example.rb +45 -0
  239. data/vendor/ttfunk/lib/ttfunk/directory.rb +17 -0
  240. data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +88 -0
  241. data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +69 -0
  242. data/vendor/ttfunk/lib/ttfunk/reader.rb +44 -0
  243. data/vendor/ttfunk/lib/ttfunk/resource_file.rb +78 -0
  244. data/vendor/ttfunk/lib/ttfunk/subset/base.rb +141 -0
  245. data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +50 -0
  246. data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +48 -0
  247. data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +63 -0
  248. data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +55 -0
  249. data/vendor/ttfunk/lib/ttfunk/subset.rb +18 -0
  250. data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +72 -0
  251. data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +54 -0
  252. data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +126 -0
  253. data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +79 -0
  254. data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +34 -0
  255. data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +81 -0
  256. data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +37 -0
  257. data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +64 -0
  258. data/vendor/ttfunk/lib/ttfunk/table/head.rb +44 -0
  259. data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +41 -0
  260. data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +47 -0
  261. data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +62 -0
  262. data/vendor/ttfunk/lib/ttfunk/table/kern.rb +79 -0
  263. data/vendor/ttfunk/lib/ttfunk/table/loca.rb +43 -0
  264. data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +40 -0
  265. data/vendor/ttfunk/lib/ttfunk/table/name.rb +125 -0
  266. data/vendor/ttfunk/lib/ttfunk/table/os2.rb +78 -0
  267. data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +43 -0
  268. data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +35 -0
  269. data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +23 -0
  270. data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +17 -0
  271. data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +17 -0
  272. data/vendor/ttfunk/lib/ttfunk/table/post.rb +91 -0
  273. data/vendor/ttfunk/lib/ttfunk/table/simple.rb +14 -0
  274. data/vendor/ttfunk/lib/ttfunk/table.rb +46 -0
  275. data/vendor/ttfunk/lib/ttfunk.rb +102 -0
  276. metadata +364 -0
@@ -0,0 +1,96 @@
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
+ info.should.be.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
+ it "should raise an UnsupportedImageType if passed a BMP" do
40
+ filename = "#{Prawn::BASEDIR}/data/images/tru256.bmp"
41
+ lambda { @pdf.image filename, :at => [100,100] }.should.raise(Prawn::Errors::UnsupportedImageType)
42
+ end
43
+
44
+ it "should raise an UnsupportedImageType if passed an interlaced PNG" do
45
+ filename = "#{Prawn::BASEDIR}/data/images/dice_interlaced.png"
46
+ lambda { @pdf.image filename, :at => [100,100] }.should.raise(Prawn::Errors::UnsupportedImageType)
47
+ end
48
+
49
+ it "should bump PDF version to 1.5 or greater on embedding 16-bit PNGs" do
50
+ @pdf.image "#{Prawn::BASEDIR}/data/images/16bit.png"
51
+ @pdf.state.version.should >= 1.5
52
+ end
53
+
54
+ # to support Adobe Reader, which apparently doesn't handle 16-bit alpha
55
+ # channels. Verified experimentally [BE] but not confirmed in documentation
56
+ # or anything. OS X Preview handles those files just fine.
57
+ #
58
+ it "should embed 8-bit alpha channels for 16-bit PNGs" do
59
+ @pdf.image "#{Prawn::BASEDIR}/data/images/16bit.png"
60
+
61
+ output = @pdf.render
62
+ output.should =~ /\/BitsPerComponent 16/
63
+ output.should =~ /\/BitsPerComponent 8/
64
+ end
65
+
66
+ describe ":fit option" do
67
+ it "should fit inside the defined constraints" do
68
+ info = @pdf.image @filename, :fit => [100,400]
69
+ info.scaled_width.should <= 100
70
+ info.scaled_height.should <= 400
71
+
72
+ info = @pdf.image @filename, :fit => [400,100]
73
+ info.scaled_width.should <= 400
74
+ info.scaled_height.should <= 100
75
+
76
+ info = @pdf.image @filename, :fit => [604,453]
77
+ info.scaled_width.should == 604
78
+ info.scaled_height.should == 453
79
+ end
80
+ it "should move text position" do
81
+ @y = @pdf.y
82
+ info = @pdf.image @filename, :fit => [100,400]
83
+ @pdf.y.should < @y
84
+ end
85
+ end
86
+
87
+ describe ":at option" do
88
+ it "should not move text position" do
89
+ @y = @pdf.y
90
+ info = @pdf.image @filename, :at => [100,400]
91
+ @pdf.y.should == @y
92
+ end
93
+ end
94
+
95
+ end
96
+
@@ -0,0 +1,446 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
3
+
4
+ describe "Text::Formatted::Parser#to_array" do
5
+ it "should handle sup" do
6
+ string = "<sup>superscript</sup>"
7
+ array = Prawn::Text::Formatted::Parser.to_array(string)
8
+ array[0].should == { :text => "superscript",
9
+ :styles => [:superscript],
10
+ :color => nil,
11
+ :link => nil,
12
+ :anchor => nil,
13
+ :font => nil,
14
+ :size => nil }
15
+ end
16
+ it "should handle sub" do
17
+ string = "<sub>subscript</sub>"
18
+ array = Prawn::Text::Formatted::Parser.to_array(string)
19
+ array[0].should == { :text => "subscript",
20
+ :styles => [:subscript],
21
+ :color => nil,
22
+ :link => nil,
23
+ :anchor => nil,
24
+ :font => nil,
25
+ :size => nil }
26
+ end
27
+ it "should handle rgb" do
28
+ string = "<color rgb='#ff0000'>red text</color>"
29
+ array = Prawn::Text::Formatted::Parser.to_array(string)
30
+ array[0].should == { :text => "red text",
31
+ :styles => [],
32
+ :color => "ff0000",
33
+ :link => nil,
34
+ :anchor => nil,
35
+ :font => nil,
36
+ :size => nil }
37
+ end
38
+ it "# should be optional in rgb" do
39
+ string = "<color rgb='ff0000'>red text</color>"
40
+ array = Prawn::Text::Formatted::Parser.to_array(string)
41
+ array[0].should == { :text => "red text",
42
+ :styles => [],
43
+ :color => "ff0000",
44
+ :link => nil,
45
+ :anchor => nil,
46
+ :font => nil,
47
+ :size => nil }
48
+ end
49
+ it "should handle cmyk" do
50
+ string = "<color c='0' m='100' y='0' k='0'>magenta text</color>"
51
+ array = Prawn::Text::Formatted::Parser.to_array(string)
52
+ array[0].should == { :text => "magenta text",
53
+ :styles => [],
54
+ :color => [0, 100, 0, 0],
55
+ :link => nil,
56
+ :anchor => nil,
57
+ :font => nil,
58
+ :size => nil }
59
+ end
60
+ it "should handle fonts" do
61
+ string = "<font name='Courier'>Courier text</font>"
62
+ array = Prawn::Text::Formatted::Parser.to_array(string)
63
+ array[0].should == { :text => "Courier text",
64
+ :styles => [],
65
+ :color => nil,
66
+ :link => nil,
67
+ :anchor => nil,
68
+ :font => "Courier",
69
+ :size => nil }
70
+ end
71
+ it "should handle size" do
72
+ string = "<font size='14'>14 point text</font>"
73
+ array = Prawn::Text::Formatted::Parser.to_array(string)
74
+ array[0].should == { :text => "14 point text",
75
+ :styles => [],
76
+ :color => nil,
77
+ :link => nil,
78
+ :anchor => nil,
79
+ :font => nil,
80
+ :size => 14 }
81
+ end
82
+ it "should handle links" do
83
+ string = "<link href='http://example.com'>external link</link>"
84
+ array = Prawn::Text::Formatted::Parser.to_array(string)
85
+ array[0].should == { :text => "external link",
86
+ :styles => [],
87
+ :color => nil,
88
+ :link => "http://example.com",
89
+ :anchor => nil,
90
+ :font => nil,
91
+ :size => nil }
92
+ end
93
+ it "should handle anchors" do
94
+ string = "<link anchor='ToC'>internal link</link>"
95
+ array = Prawn::Text::Formatted::Parser.to_array(string)
96
+ array[0].should == { :text => "internal link",
97
+ :styles => [],
98
+ :color => nil,
99
+ :link => nil,
100
+ :anchor => "ToC",
101
+ :font => nil,
102
+ :size => nil }
103
+ end
104
+ it "should handle higher order characters properly" do
105
+ string = "<b>©\n©</b>"
106
+ array = Prawn::Text::Formatted::Parser.to_array(string)
107
+ array[0].should == { :text => "©",
108
+ :styles => [:bold],
109
+ :color => nil,
110
+ :link => nil,
111
+ :anchor => nil,
112
+ :font => nil,
113
+ :size => nil }
114
+ array[1].should == { :text => "\n",
115
+ :styles => [:bold],
116
+ :color => nil,
117
+ :link => nil,
118
+ :anchor => nil,
119
+ :font => nil,
120
+ :size => nil }
121
+ array[2].should == { :text => "©",
122
+ :styles => [:bold],
123
+ :color => nil,
124
+ :link => nil,
125
+ :anchor => nil,
126
+ :font => nil,
127
+ :size => nil }
128
+ end
129
+ it "should convert &lt; &gt;, and &amp; to <, >, and &, respectively" do
130
+ string = "hello <b>&lt;, &gt;, and &amp;</b>"
131
+ array = Prawn::Text::Formatted::Parser.to_array(string)
132
+ array[1].should == { :text => "<, >, and &",
133
+ :styles => [:bold],
134
+ :color => nil,
135
+ :link => nil,
136
+ :anchor => nil,
137
+ :font => nil,
138
+ :size => nil }
139
+ end
140
+ it "should handle double qoutes around tag attributes" do
141
+ string = 'some <font size="14">sized</font> text'
142
+ array = Prawn::Text::Formatted::Parser.to_array(string)
143
+ array[1].should == { :text => "sized",
144
+ :styles => [],
145
+ :color => nil,
146
+ :link => nil,
147
+ :anchor => nil,
148
+ :font => nil,
149
+ :size => 14 }
150
+ end
151
+ it "should handle single qoutes around tag attributes" do
152
+ string = "some <font size='14'>sized</font> text"
153
+ array = Prawn::Text::Formatted::Parser.to_array(string)
154
+ array[1].should == { :text => "sized",
155
+ :styles => [],
156
+ :color => nil,
157
+ :link => nil,
158
+ :anchor => nil,
159
+ :font => nil,
160
+ :size => 14 }
161
+ end
162
+ it "should construct a formatted text array from a string" do
163
+ string = "hello <b>world\nhow <i>are</i></b> you?"
164
+ array = Prawn::Text::Formatted::Parser.to_array(string)
165
+
166
+ array[0].should == { :text => "hello ",
167
+ :styles => [],
168
+ :color => nil,
169
+ :link => nil,
170
+ :anchor => nil,
171
+ :font => nil,
172
+ :size => nil }
173
+ array[1].should == { :text => "world",
174
+ :styles => [:bold],
175
+ :color => nil,
176
+ :link => nil,
177
+ :anchor => nil,
178
+ :font => nil,
179
+ :size => nil }
180
+ array[2].should == { :text => "\n",
181
+ :styles => [:bold],
182
+ :color => nil,
183
+ :link => nil,
184
+ :anchor => nil,
185
+ :font => nil,
186
+ :size => nil }
187
+ array[3].should == { :text => "how ",
188
+ :styles => [:bold],
189
+ :color => nil,
190
+ :link => nil,
191
+ :anchor => nil,
192
+ :font => nil,
193
+ :size => nil }
194
+ array[4].should == { :text => "are",
195
+ :styles => [:bold, :italic],
196
+ :color => nil,
197
+ :link => nil,
198
+ :anchor => nil,
199
+ :font => nil,
200
+ :size => nil }
201
+ array[5].should == { :text => " you?",
202
+ :styles => [],
203
+ :color => nil,
204
+ :link => nil,
205
+ :anchor => nil,
206
+ :font => nil,
207
+ :size => nil }
208
+ end
209
+ it "should accept <strong> as an alternative to <b>" do
210
+ string = "<strong>bold</strong> not bold"
211
+ array = Prawn::Text::Formatted::Parser.to_array(string)
212
+
213
+ array[0].should == { :text => "bold",
214
+ :styles => [:bold],
215
+ :color => nil,
216
+ :link => nil,
217
+ :anchor => nil,
218
+ :font => nil,
219
+ :size => nil }
220
+ array[1].should == { :text => " not bold",
221
+ :styles => [],
222
+ :color => nil,
223
+ :link => nil,
224
+ :anchor => nil,
225
+ :font => nil,
226
+ :size => nil }
227
+ end
228
+ it "should accept <em> as an alternative to <i>" do
229
+ string = "<em>italic</em> not italic"
230
+ array = Prawn::Text::Formatted::Parser.to_array(string)
231
+
232
+ array[0].should == { :text => "italic",
233
+ :styles => [:italic],
234
+ :color => nil,
235
+ :link => nil,
236
+ :anchor => nil,
237
+ :font => nil,
238
+ :size => nil }
239
+ array[1].should == { :text => " not italic",
240
+ :styles => [],
241
+ :color => nil,
242
+ :link => nil,
243
+ :anchor => nil,
244
+ :font => nil,
245
+ :size => nil }
246
+ end
247
+ it "should accept <a> as an alternative to <link>" do
248
+ string = "<a href='http://example.com'>link</a> not a link"
249
+ array = Prawn::Text::Formatted::Parser.to_array(string)
250
+
251
+ array[0].should == { :text => "link",
252
+ :styles => [],
253
+ :color => nil,
254
+ :link => "http://example.com",
255
+ :anchor => nil,
256
+ :font => nil,
257
+ :size => nil }
258
+ array[1].should == { :text => " not a link",
259
+ :styles => [],
260
+ :color => nil,
261
+ :link => nil,
262
+ :anchor => nil,
263
+ :font => nil,
264
+ :size => nil }
265
+ end
266
+ end
267
+
268
+
269
+ describe "Text::Formatted::Parser#to_string" do
270
+ it "should handle sup" do
271
+ string = "<sup>superscript</sup>"
272
+ array = [{ :text => "superscript",
273
+ :styles => [:superscript],
274
+ :color => nil,
275
+ :link => nil,
276
+ :anchor => nil,
277
+ :font => nil,
278
+ :size => nil }]
279
+ Prawn::Text::Formatted::Parser.to_string(array).should == string
280
+ end
281
+ it "should handle sub" do
282
+ string = "<sub>subscript</sub>"
283
+ array = [{ :text => "subscript",
284
+ :styles => [:subscript],
285
+ :color => nil,
286
+ :link => nil,
287
+ :anchor => nil,
288
+ :font => nil,
289
+ :size => nil }]
290
+ Prawn::Text::Formatted::Parser.to_string(array).should == string
291
+ end
292
+ it "should handle rgb" do
293
+ string = "<color rgb='ff0000'>red text</color>"
294
+ array = [{ :text => "red text",
295
+ :styles => [],
296
+ :color => "ff0000",
297
+ :link => nil,
298
+ :anchor => nil,
299
+ :font => nil,
300
+ :size => nil }]
301
+ Prawn::Text::Formatted::Parser.to_string(array).should == string
302
+ end
303
+ it "should handle cmyk" do
304
+ string = "<color c='0' m='100' y='0' k='0'>magenta text</color>"
305
+ array = [{ :text => "magenta text",
306
+ :styles => [],
307
+ :color => [0, 100, 0, 0],
308
+ :link => nil,
309
+ :anchor => nil,
310
+ :font => nil,
311
+ :size => nil }]
312
+ Prawn::Text::Formatted::Parser.to_string(array).should == string
313
+ end
314
+ it "should handle fonts" do
315
+ string = "<font name='Courier'>Courier text</font>"
316
+ array = [{ :text => "Courier text",
317
+ :styles => [],
318
+ :color => nil,
319
+ :link => nil,
320
+ :anchor => nil,
321
+ :font => "Courier",
322
+ :size => nil }]
323
+ Prawn::Text::Formatted::Parser.to_string(array).should == string
324
+ end
325
+ it "should handle size" do
326
+ string = "<font size='14'>14 point text</font>"
327
+ array = [{ :text => "14 point text",
328
+ :styles => [],
329
+ :color => nil,
330
+ :link => nil,
331
+ :anchor => nil,
332
+ :font => nil,
333
+ :size => 14 }]
334
+ Prawn::Text::Formatted::Parser.to_string(array).should == string
335
+ end
336
+ it "should handle size" do
337
+ array = [{ :text => "external link",
338
+ :styles => [],
339
+ :color => nil,
340
+ :link => "http://example.com",
341
+ :anchor => nil,
342
+ :font => nil,
343
+ :size => nil }]
344
+ string = "<link href='http://example.com'>external link</link>"
345
+ Prawn::Text::Formatted::Parser.to_string(array).should == string
346
+ end
347
+ it "should handle links" do
348
+ array = [{ :text => "external link",
349
+ :styles => [],
350
+ :color => nil,
351
+ :link => "http://example.com",
352
+ :anchor => nil,
353
+ :font => nil,
354
+ :size => nil }]
355
+ string = "<link href='http://example.com'>external link</link>"
356
+ Prawn::Text::Formatted::Parser.to_string(array).should == string
357
+ end
358
+ it "should handle anchors" do
359
+ array = [{ :text => "internal link",
360
+ :styles => [],
361
+ :color => nil,
362
+ :link => nil,
363
+ :anchor => "ToC",
364
+ :font => nil,
365
+ :size => nil }]
366
+ string = "<link anchor='ToC'>internal link</link>"
367
+ Prawn::Text::Formatted::Parser.to_string(array).should == string
368
+ end
369
+ it "should convert <, >, and & to &lt; &gt;, and &amp;, respectively" do
370
+ array = [{ :text => "hello ",
371
+ :styles => [],
372
+ :color => nil,
373
+ :link => nil,
374
+ :font => nil,
375
+ :size => nil },
376
+ { :text => "<, >, and &",
377
+ :styles => [:bold],
378
+ :color => nil,
379
+ :link => nil,
380
+ :font => nil,
381
+ :size => nil }]
382
+ string = "hello <b>&lt;, &gt;, and &amp;</b>"
383
+ Prawn::Text::Formatted::Parser.to_string(array).should == string
384
+ end
385
+ it "should construct an HTML-esque string from a formatted" +
386
+ " text array" do
387
+ array = [
388
+ { :text => "hello ",
389
+ :styles => [],
390
+ :color => nil,
391
+ :link => nil,
392
+ :font => nil,
393
+ :size => 14 },
394
+ { :text => "world",
395
+ :styles => [:bold],
396
+ :color => nil,
397
+ :link => nil,
398
+ :font => nil,
399
+ :size => nil },
400
+ { :text => "\n",
401
+ :styles => [:bold],
402
+ :color => nil,
403
+ :link => nil,
404
+ :font => nil,
405
+ :size => nil },
406
+ { :text => "how ",
407
+ :styles => [:bold],
408
+ :color => nil,
409
+ :link => nil,
410
+ :font => nil,
411
+ :size => nil },
412
+ { :text => "are",
413
+ :styles => [:bold, :italic],
414
+ :color => nil,
415
+ :link => nil,
416
+ :font => nil,
417
+ :size => nil },
418
+ { :text => " you?",
419
+ :styles => [],
420
+ :color => nil,
421
+ :link => nil,
422
+ :font => nil,
423
+ :size => nil }
424
+ ]
425
+ string = "<font size='14'>hello </font><b>world</b><b>\n</b><b>how </b><b><i>are</i></b> you?"
426
+ Prawn::Text::Formatted::Parser.to_string(array).should == string
427
+ end
428
+ end
429
+
430
+ describe "Text::Formatted::Parser#array_paragraphs" do
431
+ it "should group fragments separated by newlines" do
432
+ array = [{ :text => "\nhello\nworld" },
433
+ { :text => "\n\n" },
434
+ { :text => "how" },
435
+ { :text => "are" },
436
+ { :text => "you" }]
437
+ target = [[{ :text => "\n"}],
438
+ [{ :text => "hello" }],
439
+ [{ :text => "world" }],
440
+ [{ :text => "\n"}],
441
+ [{ :text => "how" },
442
+ { :text => "are" },
443
+ { :text => "you" }]]
444
+ Prawn::Text::Formatted::Parser.array_paragraphs(array).should == target
445
+ end
446
+ end
data/spec/jpg_spec.rb ADDED
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ # Spec'ing the PNG class. Not complete yet - still needs to check the
4
+ # contents of palette and transparency to ensure they're correct.
5
+ # Need to find files that have these sections first.
6
+
7
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
8
+
9
+ describe "When reading a JPEG file" do
10
+
11
+ before(:each) do
12
+ @filename = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
13
+ @img_data = File.open(@filename, "rb") { |f| f.read }
14
+ end
15
+
16
+ it "should read the basic attributes correctly" do
17
+ jpg = Prawn::Images::JPG.new(@img_data)
18
+
19
+ jpg.width.should == 604
20
+ jpg.height.should == 453
21
+ jpg.bits.should == 8
22
+ jpg.channels.should == 3
23
+ end
24
+ end
25
+