eideticpdf 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. data/fonts/AntiqueOlive-Bold.afm +406 -0
  2. data/fonts/AntiqueOlive-Bold.inf +27 -0
  3. data/fonts/AntiqueOlive-Compact.afm +401 -0
  4. data/fonts/AntiqueOlive-Compact.inf +27 -0
  5. data/fonts/AntiqueOlive-Italic.afm +401 -0
  6. data/fonts/AntiqueOlive-Italic.inf +27 -0
  7. data/fonts/AntiqueOlive-Roman.afm +409 -0
  8. data/fonts/AntiqueOlive-Roman.inf +27 -0
  9. data/fonts/AvantGarde-Book.afm +667 -0
  10. data/fonts/AvantGarde-Book.inf +26 -0
  11. data/fonts/AvantGarde-BookOblique.afm +667 -0
  12. data/fonts/AvantGarde-BookOblique.inf +26 -0
  13. data/fonts/AvantGarde-Demi.afm +673 -0
  14. data/fonts/AvantGarde-Demi.inf +26 -0
  15. data/fonts/AvantGarde-DemiOblique.afm +673 -0
  16. data/fonts/AvantGarde-DemiOblique.inf +26 -0
  17. data/fonts/Bookman-Demi.afm +669 -0
  18. data/fonts/Bookman-Demi.inf +25 -0
  19. data/fonts/Bookman-DemiItalic.afm +669 -0
  20. data/fonts/Bookman-DemiItalic.inf +25 -0
  21. data/fonts/Bookman-Light.afm +643 -0
  22. data/fonts/Bookman-Light.inf +25 -0
  23. data/fonts/Bookman-LightItalic.afm +620 -0
  24. data/fonts/Bookman-LightItalic.inf +25 -0
  25. data/fonts/Clarendon-Bold.afm +412 -0
  26. data/fonts/Clarendon-Bold.inf +27 -0
  27. data/fonts/Clarendon-Light.afm +410 -0
  28. data/fonts/Clarendon-Light.inf +27 -0
  29. data/fonts/Clarendon.afm +410 -0
  30. data/fonts/Clarendon.inf +27 -0
  31. data/fonts/CooperBlack-Italic.afm +421 -0
  32. data/fonts/CooperBlack-Italic.inf +26 -0
  33. data/fonts/CooperBlack.afm +427 -0
  34. data/fonts/CooperBlack.inf +26 -0
  35. data/fonts/Coronet-Regular.afm +327 -0
  36. data/fonts/Coronet-Regular.inf +25 -0
  37. data/fonts/Courier-Bold.afm +342 -0
  38. data/fonts/Courier-Bold.inf +26 -0
  39. data/fonts/Courier-BoldOblique.afm +342 -0
  40. data/fonts/Courier-BoldOblique.inf +26 -0
  41. data/fonts/Courier-Oblique.afm +342 -0
  42. data/fonts/Courier-Oblique.inf +26 -0
  43. data/fonts/Courier.afm +342 -0
  44. data/fonts/Courier.inf +26 -0
  45. data/fonts/Eurostile.afm +419 -0
  46. data/fonts/Eurostile.inf +27 -0
  47. data/fonts/Goudy-ExtraBold.afm +412 -0
  48. data/fonts/Goudy-ExtraBold.inf +27 -0
  49. data/fonts/Helvetica-Bold.afm +2827 -0
  50. data/fonts/Helvetica-Bold.inf +26 -0
  51. data/fonts/Helvetica-BoldOblique.afm +2827 -0
  52. data/fonts/Helvetica-BoldOblique.inf +26 -0
  53. data/fonts/Helvetica-Condensed-Bold.afm +623 -0
  54. data/fonts/Helvetica-Condensed-Bold.inf +25 -0
  55. data/fonts/Helvetica-Condensed-BoldObl.afm +623 -0
  56. data/fonts/Helvetica-Condensed-BoldObl.inf +25 -0
  57. data/fonts/Helvetica-Condensed-Oblique.afm +528 -0
  58. data/fonts/Helvetica-Condensed-Oblique.inf +25 -0
  59. data/fonts/Helvetica-Condensed.afm +528 -0
  60. data/fonts/Helvetica-Condensed.inf +25 -0
  61. data/fonts/Helvetica-Narrow-Bold.afm +1439 -0
  62. data/fonts/Helvetica-Narrow-Bold.inf +26 -0
  63. data/fonts/Helvetica-Narrow-BoldOblique.afm +1439 -0
  64. data/fonts/Helvetica-Narrow-BoldOblique.inf +26 -0
  65. data/fonts/Helvetica-Narrow-Oblique.afm +1556 -0
  66. data/fonts/Helvetica-Narrow-Oblique.inf +26 -0
  67. data/fonts/Helvetica-Narrow.afm +1556 -0
  68. data/fonts/Helvetica-Narrow.inf +26 -0
  69. data/fonts/Helvetica-Oblique.afm +3051 -0
  70. data/fonts/Helvetica-Oblique.inf +26 -0
  71. data/fonts/Helvetica.afm +3051 -0
  72. data/fonts/Helvetica.inf +26 -0
  73. data/fonts/LetterGothic-Bold.afm +443 -0
  74. data/fonts/LetterGothic-Bold.inf +26 -0
  75. data/fonts/LetterGothic-BoldSlanted.afm +443 -0
  76. data/fonts/LetterGothic-BoldSlanted.inf +26 -0
  77. data/fonts/LetterGothic-Slanted.afm +443 -0
  78. data/fonts/LetterGothic-Slanted.inf +26 -0
  79. data/fonts/LetterGothic.afm +443 -0
  80. data/fonts/LetterGothic.inf +26 -0
  81. data/fonts/LubalinGraph-Book.afm +351 -0
  82. data/fonts/LubalinGraph-Book.inf +25 -0
  83. data/fonts/LubalinGraph-BookOblique.afm +351 -0
  84. data/fonts/LubalinGraph-BookOblique.inf +25 -0
  85. data/fonts/LubalinGraph-Demi.afm +351 -0
  86. data/fonts/LubalinGraph-Demi.inf +25 -0
  87. data/fonts/LubalinGraph-DemiOblique.afm +351 -0
  88. data/fonts/LubalinGraph-DemiOblique.inf +25 -0
  89. data/fonts/Marigold.afm +491 -0
  90. data/fonts/Marigold.inf +27 -0
  91. data/fonts/MonaLisa-Recut.afm +663 -0
  92. data/fonts/MonaLisa-Recut.inf +27 -0
  93. data/fonts/NewCenturySchlbk-Bold.afm +886 -0
  94. data/fonts/NewCenturySchlbk-Bold.inf +25 -0
  95. data/fonts/NewCenturySchlbk-BoldItalic.afm +1521 -0
  96. data/fonts/NewCenturySchlbk-BoldItalic.inf +26 -0
  97. data/fonts/NewCenturySchlbk-Italic.afm +1113 -0
  98. data/fonts/NewCenturySchlbk-Italic.inf +26 -0
  99. data/fonts/NewCenturySchlbk-Roman.afm +1067 -0
  100. data/fonts/NewCenturySchlbk-Roman.inf +26 -0
  101. data/fonts/Optima-Bold.afm +515 -0
  102. data/fonts/Optima-Bold.inf +27 -0
  103. data/fonts/Optima-BoldItalic.afm +712 -0
  104. data/fonts/Optima-BoldItalic.inf +26 -0
  105. data/fonts/Optima-Italic.afm +737 -0
  106. data/fonts/Optima-Italic.inf +26 -0
  107. data/fonts/Optima.afm +501 -0
  108. data/fonts/Optima.inf +27 -0
  109. data/fonts/Palatino-Bold.afm +675 -0
  110. data/fonts/Palatino-Bold.inf +26 -0
  111. data/fonts/Palatino-BoldItalic.afm +702 -0
  112. data/fonts/Palatino-BoldItalic.inf +26 -0
  113. data/fonts/Palatino-Italic.afm +700 -0
  114. data/fonts/Palatino-Italic.inf +26 -0
  115. data/fonts/Palatino-Roman.afm +718 -0
  116. data/fonts/Palatino-Roman.inf +26 -0
  117. data/fonts/StempelGaramond-Bold.afm +412 -0
  118. data/fonts/StempelGaramond-Bold.inf +27 -0
  119. data/fonts/StempelGaramond-BoldItalic.afm +413 -0
  120. data/fonts/StempelGaramond-BoldItalic.inf +27 -0
  121. data/fonts/StempelGaramond-Italic.afm +413 -0
  122. data/fonts/StempelGaramond-Italic.inf +27 -0
  123. data/fonts/StempelGaramond-Roman.afm +412 -0
  124. data/fonts/StempelGaramond-Roman.inf +27 -0
  125. data/fonts/Symbol.afm +213 -0
  126. data/fonts/Symbol.inf +27 -0
  127. data/fonts/Times-Bold.afm +2588 -0
  128. data/fonts/Times-Bold.inf +26 -0
  129. data/fonts/Times-BoldItalic.afm +2384 -0
  130. data/fonts/Times-BoldItalic.inf +26 -0
  131. data/fonts/Times-Italic.afm +2667 -0
  132. data/fonts/Times-Italic.inf +26 -0
  133. data/fonts/Times-Roman.afm +2419 -0
  134. data/fonts/Times-Roman.inf +26 -0
  135. data/fonts/Univers-Bold.afm +712 -0
  136. data/fonts/Univers-Bold.inf +27 -0
  137. data/fonts/Univers-BoldOblique.afm +712 -0
  138. data/fonts/Univers-BoldOblique.inf +27 -0
  139. data/fonts/Univers-Condensed.afm +403 -0
  140. data/fonts/Univers-Condensed.inf +27 -0
  141. data/fonts/Univers-CondensedOblique.afm +403 -0
  142. data/fonts/Univers-CondensedOblique.inf +27 -0
  143. data/fonts/Univers-Light.afm +737 -0
  144. data/fonts/Univers-Light.inf +27 -0
  145. data/fonts/Univers-LightOblique.afm +737 -0
  146. data/fonts/Univers-LightOblique.inf +27 -0
  147. data/fonts/Univers-Oblique.afm +656 -0
  148. data/fonts/Univers-Oblique.inf +27 -0
  149. data/fonts/Univers.afm +656 -0
  150. data/fonts/Univers.inf +27 -0
  151. data/fonts/ZapfChancery-MediumItalic.afm +842 -0
  152. data/fonts/ZapfChancery-MediumItalic.inf +26 -0
  153. data/fonts/ZapfDingbats.afm +225 -0
  154. data/fonts/ZapfDingbats.inf +26 -0
  155. data/lib/epdfafm.rb +334 -0
  156. data/lib/epdfdw.rb +710 -0
  157. data/lib/epdfk.rb +3142 -0
  158. data/lib/epdfo.rb +882 -0
  159. data/lib/epdfpw.rb +1749 -0
  160. data/lib/epdfs.rb +101 -0
  161. data/lib/epdfsw.rb +267 -0
  162. data/lib/epdft.rb +145 -0
  163. data/lib/epdftt.rb +458 -0
  164. data/test/pdf_tests.rb +16 -0
  165. data/test/test.rb +816 -0
  166. data/test/test_epdfafm.rb +202 -0
  167. data/test/test_epdfdw.rb +369 -0
  168. data/test/test_epdfk.rb +47 -0
  169. data/test/test_epdfo.rb +762 -0
  170. data/test/test_epdfpw.rb +129 -0
  171. data/test/test_epdfs.rb +54 -0
  172. data/test/test_epdfsw.rb +314 -0
  173. data/test/test_epdft.rb +198 -0
  174. data/test/test_epdftt.rb +34 -0
  175. data/test/test_helpers.rb +18 -0
  176. data/test/testimg.jpg +0 -0
  177. metadata +247 -0
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Brent Rowland on 2007-07-14.
4
+ # Copyright (c) 2007, 2008 Eidetic Software. All rights reserved.
5
+ #
6
+ # Eidetic PDF PageWriter Test Cases
7
+
8
+ $: << File.dirname(__FILE__) + '/../lib'
9
+ require 'test/unit'
10
+ require 'epdfpw'
11
+ require 'epdfdw'
12
+
13
+ include EideticPDF
14
+
15
+ class PageStyleTestCases < Test::Unit::TestCase
16
+ def setup
17
+ @ps_default = PageStyle.new
18
+ @ps_default_landscape = PageStyle.new(:orientation => :landscape)
19
+ @ps_letter_portrait = PageStyle.new(:page_size => :letter)
20
+ @ps_letter_landscape = PageStyle.new(:page_size => :letter, :orientation => :landscape)
21
+ @ps_legal_portrait = PageStyle.new(:page_size => :legal)
22
+ @ps_legal_landscape = PageStyle.new(:page_size => :legal, :orientation => :landscape)
23
+ @ps_A4_portrait = PageStyle.new(:page_size => :A4)
24
+ @ps_A4_landscape = PageStyle.new(:page_size => :A4, :orientation => :landscape)
25
+ @ps_B5_portrait = PageStyle.new(:page_size => :B5)
26
+ @ps_B5_landscape = PageStyle.new(:page_size => :B5, :orientation => :landscape)
27
+ @ps_C5_portrait = PageStyle.new(:page_size => :C5)
28
+ @ps_C5_landscape = PageStyle.new(:page_size => :C5, :orientation => :landscape)
29
+ end
30
+
31
+ def assert_rectangle(x1, y1, x2, y2, rect)
32
+ assert_equal(x1, rect.x1)
33
+ assert_equal(y1, rect.y1)
34
+ assert_equal(x2, rect.x2)
35
+ assert_equal(y2, rect.y2)
36
+ end
37
+
38
+ def test_page_size
39
+ assert_rectangle(0, 0, 612, 792, @ps_default.page_size)
40
+ assert_rectangle(0, 0, 792, 612, @ps_default_landscape.page_size)
41
+ assert_rectangle(0, 0, 612, 792, @ps_letter_portrait.page_size)
42
+ assert_rectangle(0, 0, 792, 612, @ps_letter_landscape.page_size)
43
+ assert_rectangle(0, 0, 612, 1008, @ps_legal_portrait.page_size)
44
+ assert_rectangle(0, 0, 1008, 612, @ps_legal_landscape.page_size)
45
+ assert_rectangle(0, 0, 595, 842, @ps_A4_portrait.page_size)
46
+ assert_rectangle(0, 0, 842, 595, @ps_A4_landscape.page_size)
47
+ assert_rectangle(0, 0, 499, 708, @ps_B5_portrait.page_size)
48
+ assert_rectangle(0, 0, 708, 499, @ps_B5_landscape.page_size)
49
+ assert_rectangle(0, 0, 459, 649, @ps_C5_portrait.page_size)
50
+ assert_rectangle(0, 0, 649, 459, @ps_C5_landscape.page_size)
51
+ end
52
+
53
+ def test_crop_size
54
+ assert_rectangle(0, 0, 612, 792, @ps_default.crop_size)
55
+ assert_rectangle(0, 0, 792, 612, @ps_default_landscape.crop_size)
56
+ assert_rectangle(0, 0, 612, 792, @ps_letter_portrait.crop_size)
57
+ assert_rectangle(0, 0, 792, 612, @ps_letter_landscape.crop_size)
58
+ assert_rectangle(0, 0, 612, 1008, @ps_legal_portrait.crop_size)
59
+ assert_rectangle(0, 0, 1008, 612, @ps_legal_landscape.crop_size)
60
+ assert_rectangle(0, 0, 595, 842, @ps_A4_portrait.crop_size)
61
+ assert_rectangle(0, 0, 842, 595, @ps_A4_landscape.crop_size)
62
+ assert_rectangle(0, 0, 499, 708, @ps_B5_portrait.crop_size)
63
+ assert_rectangle(0, 0, 708, 499, @ps_B5_landscape.crop_size)
64
+ assert_rectangle(0, 0, 459, 649, @ps_C5_portrait.crop_size)
65
+ assert_rectangle(0, 0, 649, 459, @ps_C5_landscape.crop_size)
66
+ end
67
+
68
+ def test_orientation
69
+ assert_equal(:portrait, @ps_default.orientation)
70
+ assert_equal(:landscape, @ps_default_landscape.orientation)
71
+ assert_equal(:portrait, @ps_letter_portrait.orientation)
72
+ assert_equal(:landscape, @ps_letter_landscape.orientation)
73
+ assert_equal(:portrait, @ps_legal_portrait.orientation)
74
+ assert_equal(:landscape, @ps_legal_landscape.orientation)
75
+ assert_equal(:portrait, @ps_A4_portrait.orientation)
76
+ assert_equal(:landscape, @ps_A4_landscape.orientation)
77
+ assert_equal(:portrait, @ps_B5_portrait.orientation)
78
+ assert_equal(:landscape, @ps_B5_landscape.orientation)
79
+ assert_equal(:portrait, @ps_C5_portrait.orientation)
80
+ assert_equal(:landscape, @ps_C5_landscape.orientation)
81
+ end
82
+
83
+ def test_landscape
84
+ assert_equal(false, @ps_default.landscape)
85
+ assert_equal(true, @ps_default_landscape.landscape)
86
+ assert_equal(false, @ps_letter_portrait.landscape)
87
+ assert_equal(true, @ps_letter_landscape.landscape)
88
+ assert_equal(false, @ps_legal_portrait.landscape)
89
+ assert_equal(true, @ps_legal_landscape.landscape)
90
+ assert_equal(false, @ps_A4_portrait.landscape)
91
+ assert_equal(true, @ps_A4_landscape.landscape)
92
+ assert_equal(false, @ps_B5_portrait.landscape)
93
+ assert_equal(true, @ps_B5_landscape.landscape)
94
+ assert_equal(false, @ps_C5_portrait.landscape)
95
+ assert_equal(true, @ps_C5_landscape.landscape)
96
+ end
97
+ end
98
+
99
+ class PageWriterTestCases < Test::Unit::TestCase
100
+ def setup
101
+ @doc = DocumentWriter.new
102
+ @doc.open
103
+ @page = @doc.open_page
104
+ end
105
+
106
+ def teardown
107
+ @page.close
108
+ @doc.close
109
+ end
110
+
111
+ def test_units
112
+ [:pt, :cm, :in].each do |units|
113
+ @page.units(units)
114
+ assert_equal(units, @page.units)
115
+ end
116
+ end
117
+ end
118
+
119
+ def assert_array_in_delta(expected_floats, actual_floats, delta)
120
+ expected_floats.each_with_index { |e, i| assert_in_delta(e, actual_floats[i], delta) }
121
+ end
122
+
123
+ def assert_close(expected, actual)
124
+ if expected.respond_to?(:each_with_index) and actual.respond_to?(:[])
125
+ expected.each_with_index { |e, i| assert_in_delta(e, actual[i], 2 ** -20) }
126
+ else
127
+ assert_in_delta(expected, actual, 2 ** -20)
128
+ end
129
+ end
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Brent Rowland on 2008-01-12.
4
+ # Copyright (c) 2008, Eidetic Software. All rights reserved.
5
+
6
+ $: << File.dirname(__FILE__) + '/../lib'
7
+ require 'test/unit'
8
+ require 'epdfs'
9
+
10
+ include EideticPDF
11
+
12
+ class NumericTestCases < Test::Unit::TestCase
13
+ def test_degrees
14
+ assert_equal(Math::PI, 180.degrees)
15
+ end
16
+
17
+ def test_even?
18
+ assert(2.even?, "2 is even")
19
+ assert(!1.even?, "1 is not even")
20
+ end
21
+
22
+ def test_odd?
23
+ assert(1.odd?, "1 is odd")
24
+ assert(!2.odd?, "2 is not odd")
25
+ end
26
+ end
27
+
28
+ class StatisticsTestCases < Test::Unit::TestCase
29
+ def setup
30
+ @ary = [2, 3].extend(Statistics)
31
+ end
32
+
33
+ def test_sum
34
+ assert_equal(5, @ary.sum)
35
+ end
36
+
37
+ def test_mean
38
+ assert_equal(2.5, @ary.mean)
39
+ end
40
+ end
41
+
42
+ class JpegInfoTestCases < Test::Unit::TestCase
43
+ def setup
44
+ @@image ||= IO.read(File.join(File.dirname(__FILE__), "testimg.jpg"))
45
+ end
46
+
47
+ def test_jpeg?
48
+ assert JpegInfo.jpeg?(@@image)
49
+ end
50
+
51
+ def test_jpeg_dimensions
52
+ assert_equal([227, 149, 3, 8], JpegInfo.jpeg_dimensions(@@image))
53
+ end
54
+ end
@@ -0,0 +1,314 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Brent Rowland on 2007-07-14.
4
+ # Copyright (c) 2007, 2008 Eidetic Software. All rights reserved.
5
+ #
6
+ # Eidetic PDF Stream Writer Test Cases
7
+
8
+ $: << File.dirname(__FILE__) + '/../lib'
9
+ require 'test/unit'
10
+ require 'epdfsw'
11
+
12
+ include EideticPDF
13
+
14
+ class MiscWriterTestCases < Test::Unit::TestCase
15
+ def setup
16
+ @stream = ''
17
+ @writer = MiscWriter.new(@stream)
18
+ end
19
+
20
+ def test_set_gray_fill
21
+ @writer.set_gray_fill(0.4)
22
+ assert_equal("0.4 g\n", @stream)
23
+ end
24
+
25
+ def test_set_gray_stroke
26
+ @writer.set_gray_stroke(0.9)
27
+ assert_equal("0.9 G\n", @stream)
28
+ end
29
+
30
+ def test_set_cmyk_color_fill
31
+ @writer.set_cmyk_color_fill(0.5, 0.5, 0.5, 0.5)
32
+ assert_equal("0.5 0.5 0.5 0.5 k\n", @stream)
33
+ end
34
+
35
+ def test_set_cmyk_color_stroke
36
+ @writer.set_cmyk_color_stroke(0.5, 0.5, 0.5, 0.5)
37
+ assert_equal("0.5 0.5 0.5 0.5 K\n", @stream)
38
+ end
39
+
40
+ def test_set_rgb_color_fill
41
+ @writer.set_rgb_color_fill(0.3, 0.6, 0.9)
42
+ assert_equal("0.3 0.6 0.9 rg\n", @stream)
43
+ end
44
+
45
+ def test_set_rgb_color_stroke
46
+ @writer.set_rgb_color_stroke(0.3, 0.6, 0.9)
47
+ assert_equal("0.3 0.6 0.9 RG\n", @stream)
48
+ end
49
+
50
+ def test_set_color_space_fill
51
+ @writer.set_color_space_fill('DeviceGray')
52
+ assert_equal("/DeviceGray cs\n", @stream)
53
+ end
54
+
55
+ def test_set_color_space_stroke
56
+ @writer.set_color_space_stroke('DeviceGray')
57
+ assert_equal("/DeviceGray CS\n", @stream)
58
+ end
59
+
60
+ def test_set_color_fill
61
+ @writer.set_color_fill([0.1, 0.2, 0.3, 0.4])
62
+ assert_equal("0.1 0.2 0.3 0.4 sc\n", @stream)
63
+ end
64
+
65
+ def test_set_color_stroke
66
+ @writer.set_color_stroke([0.1, 0.2, 0.3, 0.4])
67
+ assert_equal("0.1 0.2 0.3 0.4 SC\n", @stream)
68
+ end
69
+
70
+ # xxx scn, SCN: patterns and separations
71
+ def test_set_color_rendering_intent
72
+ @writer.set_color_rendering_intent("RelativeColorimetric")
73
+ assert_equal("/RelativeColorimetric ri\n", @stream)
74
+ end
75
+
76
+ def test_x_object
77
+ @writer.x_object('Image1')
78
+ assert_equal("/Image1 Do\n", @stream)
79
+ end
80
+ end
81
+
82
+ class GraphWriterTestCases < Test::Unit::TestCase
83
+ def setup
84
+ @stream = ''
85
+ @writer = GraphWriter.new(@stream)
86
+ end
87
+
88
+ def test_save_graphics_state
89
+ @writer.save_graphics_state
90
+ assert_equal("q\n", @stream)
91
+ end
92
+
93
+ def test_restore_graphics_state
94
+ @writer.restore_graphics_state
95
+ assert_equal("Q\n", @stream)
96
+ end
97
+
98
+ def test_concat_matrix
99
+ @writer.concat_matrix(1.1, 2.2, 3.3, 4.4, 5.5, 6.6)
100
+ assert_equal("1.1 2.2 3.3 4.4 5.5 6.6 cm\n", @stream)
101
+ end
102
+
103
+ def test_set_flatness
104
+ @writer.set_flatness(50)
105
+ assert_equal("50 i\n", @stream)
106
+ end
107
+
108
+ def test_set_line_cap_style
109
+ @writer.set_line_cap_style(0)
110
+ assert_equal("0 J\n", @stream)
111
+ end
112
+
113
+ def test_set_line_dash_pattern
114
+ @writer.set_line_dash_pattern('[2 3] 11')
115
+ assert_equal("[2 3] 11 d\n", @stream)
116
+ end
117
+
118
+ def test_set_line_join_style
119
+ @writer.set_line_join_style(0)
120
+ assert_equal("0 j\n", @stream)
121
+ end
122
+
123
+ def test_set_line_width
124
+ @writer.set_line_width(3)
125
+ assert_equal("3 w\n", @stream)
126
+ end
127
+
128
+ def test_set_miter_limit
129
+ @writer.set_miter_limit(3.6)
130
+ assert_equal("3.6 M\n", @stream)
131
+ end
132
+
133
+ def test_move_to
134
+ @writer.move_to(4, 5.55)
135
+ assert_equal("4 5.55 m\n", @stream)
136
+ end
137
+
138
+ def test_line_to
139
+ @writer.line_to(5.55, 4)
140
+ assert_equal("5.55 4 l\n", @stream)
141
+ end
142
+
143
+ def test_curve_to
144
+ @writer.curve_to(1.1, 2.2, 3.3, 4.4, 5.5, 6.6)
145
+ assert_equal("1.1 2.2 3.3 4.4 5.5 6.6 c\n", @stream)
146
+ end
147
+
148
+ def test_rectangle
149
+ @writer.rectangle(5.5, 5.5, 4, 6)
150
+ assert_equal("5.5 5.5 4 6 re\n", @stream)
151
+ end
152
+
153
+ def test_close_path
154
+ @writer.close_path
155
+ assert_equal("h\n", @stream)
156
+ end
157
+
158
+ def test_new_path
159
+ @writer.new_path
160
+ assert_equal("n\n", @stream)
161
+ end
162
+
163
+ def test_stroke
164
+ @writer.stroke
165
+ assert_equal("S\n", @stream)
166
+ end
167
+
168
+ def test_close_path_and_stroke
169
+ @writer.close_path_and_stroke
170
+ assert_equal("s\n", @stream)
171
+ end
172
+
173
+ def test_fill
174
+ @writer.fill
175
+ assert_equal("f\n", @stream)
176
+ end
177
+
178
+ def test_eo_fill
179
+ @writer.eo_fill
180
+ assert_equal("f*\n", @stream)
181
+ end
182
+
183
+ def test_fill_and_stroke
184
+ @writer.fill_and_stroke
185
+ assert_equal("B\n", @stream)
186
+ end
187
+
188
+ def test_close_path_fill_and_stroke
189
+ @writer.close_path_fill_and_stroke
190
+ assert_equal("b\n", @stream)
191
+ end
192
+
193
+ def test_eo_fill_and_stroke
194
+ @writer.eo_fill_and_stroke
195
+ assert_equal("B*\n", @stream)
196
+ end
197
+
198
+ def test_close_path_eo_fill_and_stroke
199
+ @writer.close_path_eo_fill_and_stroke
200
+ assert_equal("b*\n", @stream)
201
+ end
202
+
203
+ def test_clip
204
+ @writer.clip
205
+ assert_equal("W\n", @stream)
206
+ end
207
+
208
+ def test_eo_clip
209
+ @writer.eo_clip
210
+ assert_equal("W*\n", @stream)
211
+ end
212
+
213
+ def test_make_line_dash_pattern
214
+ assert_equal("[1 2 3] 2", @writer.make_line_dash_pattern([1, 2, 3], 2))
215
+ end
216
+ end
217
+
218
+ class TextWriterTestCases < Test::Unit::TestCase
219
+ def setup
220
+ @stream = ''
221
+ @writer = TextWriter.new(@stream)
222
+ end
223
+
224
+ def test_open
225
+ @writer.open
226
+ assert_equal("BT\n", @stream)
227
+ end
228
+
229
+ def test_close
230
+ @writer.close
231
+ assert_equal("ET\n", @stream)
232
+ end
233
+
234
+ def test_set_char_spacing
235
+ @writer.set_char_spacing(5)
236
+ assert_equal("5 Tc\n", @stream)
237
+ end
238
+
239
+ def test_set_word_spacing
240
+ @writer.set_word_spacing(5)
241
+ assert_equal("5 Tw\n", @stream)
242
+ end
243
+
244
+ def test_set_horiz_scaling
245
+ @writer.set_horiz_scaling(90)
246
+ assert_equal("90 Tz\n", @stream)
247
+ end
248
+
249
+ def test_set_leading
250
+ @writer.set_leading(8)
251
+ assert_equal("8 TL\n", @stream)
252
+ end
253
+
254
+ def test_set_font_and_size
255
+ @writer.set_font_and_size("Arial", 12)
256
+ assert_equal("/Arial 12 Tf\n", @stream)
257
+ end
258
+
259
+ def test_set_rendering_mode
260
+ @writer.set_rendering_mode(0)
261
+ assert_equal("0 Tr\n", @stream)
262
+ end
263
+
264
+ def test_set_rise
265
+ @writer.set_rise(0)
266
+ assert_equal("0 Ts\n", @stream)
267
+ end
268
+
269
+ def test_move_by
270
+ @writer.move_by(7, 11.5)
271
+ assert_equal("7 11.5 Td\n", @stream)
272
+ end
273
+
274
+ def test_move_by_and_set_leading
275
+ @writer.move_by_and_set_leading(5.5, 12)
276
+ assert_equal("5.5 12 TD\n", @stream)
277
+ end
278
+
279
+ def test_set_matrix
280
+ @writer.set_matrix(1.1, 2, 3.3, 4, 5.5, 6)
281
+ assert_equal("1.1 2 3.3 4 5.5 6 Tm\n", @stream)
282
+ end
283
+
284
+ def test_next_line
285
+ @writer.next_line
286
+ assert_equal("T*\n", @stream)
287
+ end
288
+
289
+ def test_show
290
+ @writer.show("Hello")
291
+ assert_equal("(Hello) Tj\n", @stream)
292
+ end
293
+
294
+ def test_next_line_show
295
+ @writer.next_line_show("Goodbye")
296
+ assert_equal("(Goodbye) '", @stream)
297
+ end
298
+
299
+ def test_set_spacing_next_line_show
300
+ @writer.set_spacing_next_line_show(5, 11.5, "Hello and goodbye")
301
+ assert_equal("5 11.5 (Hello and goodbye) \"\n", @stream)
302
+ end
303
+
304
+ def test_show_with_dispacements
305
+ a = PdfObjects::PdfArray.new([
306
+ PdfObjects::PdfString.new('H'),
307
+ PdfObjects::PdfInteger.new(120),
308
+ PdfObjects::PdfString.new('e'),
309
+ PdfObjects::PdfInteger.new(80),
310
+ PdfObjects::PdfString.new('y')])
311
+ @writer.show_with_dispacements(a)
312
+ assert_equal("[(H) 120 (e) 80 (y) ] TJ\n", @stream)
313
+ end
314
+ end
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Brent Rowland on 2007-11-27.
4
+ # Copyright (c) 2007, Eidetic Software. All rights reserved.
5
+
6
+ $: << File.dirname(__FILE__) + '/../lib'
7
+ require 'test/unit'
8
+ require File.join(File.dirname(__FILE__), 'test_helpers')
9
+ require 'epdft'
10
+ require 'epdfk'
11
+
12
+ include EideticPDF
13
+
14
+ Font = Struct.new(:name, :size, :style, :color, :encoding, :sub_type, :widths, :ascent, :descent, :height)
15
+
16
+ class RichTextTestCases < Test::Unit::TestCase
17
+ def setup
18
+ lorem = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n" <<
19
+ "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute " <<
20
+ "irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\n" <<
21
+ "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
22
+ fm = PdfK::font_metrics('Helvetica')
23
+ font = Font.new('Helvetica', 12, '', nil, 'WinAnsiEncoding', 'Type1', fm.widths, fm.ascent, fm.descent, fm.ascent + fm.descent.abs)
24
+ @wrapper = PdfText::RichText.new(lorem, font)
25
+ end
26
+
27
+ def test_initialize
28
+ assert_not_nil(@wrapper)
29
+ assert_not_nil(@wrapper.words)
30
+ assert_equal(137, @wrapper.words.size)
31
+ assert_equal("Lorem", @wrapper.words.first.text)
32
+ end
33
+
34
+ def test_next
35
+ assert_equal("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut", @wrapper.next(500).first.text)
36
+ assert_equal("labore et dolore magna aliqua.\n", @wrapper.next(500).first.text)
37
+ assert_equal("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea", @wrapper.next(500).first.text)
38
+ assert_equal("commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum", @wrapper.next(500).first.text)
39
+ assert_equal("dolore eu fugiat nulla pariatur.\n", @wrapper.next(500).first.text)
40
+ assert_equal("Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim", @wrapper.next(500).first.text)
41
+ assert_equal("id est laborum.", @wrapper.next(500).first.text)
42
+ assert_equal(nil, @wrapper.next(500))
43
+ end
44
+
45
+ def test_max_height
46
+ line = @wrapper.next(500)
47
+ assert_in_delta(11.1, line.height, 0.1)
48
+ assert_in_delta(8.6, line.ascent, 0.1)
49
+ assert_in_delta(-2.5, line.descent, 0.1)
50
+ end
51
+
52
+ def count_lines(rich_text)
53
+ result = 0
54
+ result += 1 while rich_text.next(500)
55
+ result
56
+ end
57
+
58
+ def test_clone
59
+ word_count = @wrapper.words.size
60
+ assert_equal(137, word_count)
61
+ first_text = @wrapper.words.first.text
62
+ wrapper_clone = @wrapper.clone
63
+ assert(!first_text.equal?(wrapper_clone.words.first.text), "text not cloned")
64
+ line_count = count_lines(wrapper_clone)
65
+ assert_equal(7, line_count)
66
+ assert_equal(0, wrapper_clone.words.size)
67
+ assert_equal(word_count, @wrapper.words.size)
68
+ assert_equal(line_count, count_lines(@wrapper))
69
+ end
70
+
71
+ def test_lines
72
+ lines = @wrapper.lines(500)
73
+ assert_equal(7, lines.size)
74
+ end
75
+
76
+ def test_height
77
+ assert_close(11.1, @wrapper.height)
78
+ assert_close(77.7, @wrapper.height(500))
79
+ end
80
+
81
+ def test_width
82
+ assert_close(490.86, @wrapper.width(500))
83
+ end
84
+ end
85
+
86
+ class RichTextTestCases2 < Test::Unit::TestCase
87
+ def setup
88
+ lorem = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n" <<
89
+ "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute " <<
90
+ "irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\n" <<
91
+ "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
92
+ fm = PdfK::font_metrics('Helvetica')
93
+ fm_b = PdfK::font_metrics('Helvetica-Bold')
94
+ fm_i = PdfK::font_metrics('Helvetica-Oblique')
95
+ fm_bi = PdfK::font_metrics('Helvetica-BoldOblique')
96
+ @helv = Font.new('Helvetica', 12, '', nil, 'WinAnsiEncoding', 'Type1', fm.widths, fm.ascent, fm.descent, fm.ascent + fm.descent.abs)
97
+ @helv_b = Font.new('Helvetica-Bold', 12, '', nil, 'WinAnsiEncoding', 'Type1', fm_b.widths, fm_b.ascent, fm_b.descent, fm_b.ascent + fm_b.descent.abs)
98
+ @helv_i = Font.new('Helvetica-Italic', 12, '', nil, 'WinAnsiEncoding', 'Type1', fm_i.widths, fm_i.ascent, fm_i.descent, fm_i.ascent + fm_i.descent.abs)
99
+ @helv_bi = Font.new('Helvetica-BoldItalic', 12, '', nil, 'WinAnsiEncoding', 'Type1', fm_bi.widths, fm_bi.ascent, fm_bi.descent, fm_bi.ascent + fm_bi.descent.abs)
100
+ end
101
+
102
+ def test_bold
103
+ rt = PdfText::RichText.new
104
+ rt.add("Here is some ", @helv)
105
+ rt.add("Bold", @helv_b)
106
+ rt.add(" text.", @helv)
107
+ assert_in_delta(126, rt.width(500), 1)
108
+ assert_in_delta(11.1, rt.height, 0.1)
109
+ pieces = rt.next(500)
110
+ assert_equal(3, pieces.size)
111
+ assert_equal(@helv, pieces[0].font)
112
+ assert_equal(@helv_b, pieces[1].font)
113
+ assert_equal(@helv, pieces[2].font)
114
+ end
115
+
116
+ def test_italic
117
+ rt = PdfText::RichText.new
118
+ rt.add("Here is some ", @helv)
119
+ rt.add("Italic", @helv_i)
120
+ rt.add(" text.", @helv)
121
+ assert_in_delta(124, rt.width(500), 1)
122
+ assert_in_delta(11.1, rt.height, 0.1)
123
+ pieces = rt.next(500)
124
+ assert_equal(3, pieces.size)
125
+ assert_equal(@helv, pieces[0].font)
126
+ assert_equal(@helv_i, pieces[1].font)
127
+ assert_equal(@helv, pieces[2].font)
128
+ end
129
+
130
+ def test_bold_italic
131
+ rt = PdfText::RichText.new
132
+ rt.add("Here is some ", @helv)
133
+ rt.add("Bold, Italic", @helv_bi)
134
+ rt.add(" text.", @helv)
135
+ assert_in_delta(160, rt.width(500), 1)
136
+ assert_in_delta(11.1, rt.height, 0.1)
137
+ pieces = rt.next(500)
138
+ assert_equal(3, pieces.size)
139
+ assert_equal(@helv, pieces[0].font)
140
+ assert_equal(@helv_bi, pieces[1].font)
141
+ assert_equal(@helv, pieces[2].font)
142
+ end
143
+
144
+ def test_color
145
+ rt = PdfText::RichText.new
146
+ rt.add("Here is some ", @helv)
147
+ rt.add("Red", @helv, :color => 'Red')
148
+ rt.add(" text.", @helv)
149
+ assert_in_delta(122, rt.width(500), 1)
150
+ assert_in_delta(11.1, rt.height, 0.1)
151
+ pieces = rt.next(500)
152
+ assert_equal(3, pieces.size)
153
+ assert_equal(@helv, pieces[0].font)
154
+ assert_equal('Red', pieces[1].color)
155
+ assert_equal(@helv, pieces[2].font)
156
+ end
157
+
158
+ def test_underline
159
+ rt = PdfText::RichText.new
160
+ rt.add("Here is some ", @helv)
161
+ rt.add("Underlined", @helv, :underline => true)
162
+ rt.add(" text.", @helv)
163
+ assert_in_delta(158, rt.width(500), 1)
164
+ assert_in_delta(11.1, rt.height, 0.1)
165
+ pieces = rt.next(500)
166
+ assert_equal(3, pieces.size)
167
+ assert_equal(@helv, pieces[0].font)
168
+ assert(pieces[1].underline)
169
+ assert_equal(@helv, pieces[2].font)
170
+ end
171
+ end
172
+
173
+ class RichTextTestCases3 < Test::Unit::TestCase
174
+ def setup
175
+ fm = PdfK::font_metrics('Helvetica')
176
+ @font12 = Font.new('Helvetica', 12, '', nil, 'WinAnsiEncoding', 'Type1', fm.widths, fm.ascent, fm.descent, fm.ascent + fm.descent.abs)
177
+ @font16 = Font.new('Helvetica', 16, '', nil, 'WinAnsiEncoding', 'Type1', fm.widths, fm.ascent, fm.descent, fm.ascent + fm.descent.abs)
178
+ @font20 = Font.new('Helvetica', 20, '', nil, 'WinAnsiEncoding', 'Type1', fm.widths, fm.ascent, fm.descent, fm.ascent + fm.descent.abs)
179
+ end
180
+
181
+ def test_max_ascent
182
+ t1 = PdfText::RichText.new("World! ", @font20)
183
+ t2 = PdfText::RichText.new
184
+ t2.add "Hello ", @font12
185
+ t2.add "World! ", @font20
186
+ t2.add "What's up?", @font16
187
+ assert_equal t1.ascent, t2.ascent
188
+ end
189
+
190
+ def test_max_height
191
+ t1 = PdfText::RichText.new("World! ", @font20)
192
+ t2 = PdfText::RichText.new
193
+ t2.add "Hello ", @font12
194
+ t2.add "World! ", @font20
195
+ t2.add "What's up?", @font16
196
+ assert_equal t1.height, t2.height
197
+ end
198
+ end