rtf 0.1.0 → 0.3.0

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 (52) hide show
  1. data/CHANGES +5 -0
  2. data/LICENSE +20 -0
  3. data/{doc/README → README.rdoc} +10 -2
  4. data/Rakefile +47 -0
  5. data/VERSION.yml +5 -0
  6. data/examples/example01.rb +0 -0
  7. data/examples/example02.rb +0 -0
  8. data/examples/example03.rb +4 -4
  9. data/examples/example03.rtf +0 -0
  10. data/examples/example04.rb +50 -0
  11. data/examples/rubyrtf.bmp +0 -0
  12. data/examples/rubyrtf.jpg +0 -0
  13. data/examples/rubyrtf.png +0 -0
  14. data/lib/rtf.rb +0 -0
  15. data/lib/rtf/colour.rb +0 -0
  16. data/lib/rtf/font.rb +0 -0
  17. data/lib/rtf/information.rb +2 -3
  18. data/lib/rtf/node.rb +294 -29
  19. data/lib/rtf/paper.rb +0 -0
  20. data/lib/rtf/style.rb +0 -0
  21. data/test/{CharacterStyleTest.rb → character_style_test.rb} +1 -7
  22. data/test/{ColourTableTest.rb → colour_table_test.rb} +92 -97
  23. data/test/{ColourTest.rb → colour_test.rb} +116 -122
  24. data/test/{CommandNodeTest.rb → command_node_test.rb} +1 -7
  25. data/test/{ContainerNodeTest.rb → container_node_test.rb} +3 -9
  26. data/test/{DocumentStyleTest.rb → document_style_test.rb} +1 -7
  27. data/test/{DocumentTest.rb → document_test.rb} +1 -7
  28. data/test/fixtures/bitmap1.bmp +0 -0
  29. data/test/fixtures/bitmap2.bmp +0 -0
  30. data/test/fixtures/jpeg1.jpg +0 -0
  31. data/test/fixtures/jpeg2.jpg +0 -0
  32. data/test/fixtures/png1.png +0 -0
  33. data/test/fixtures/png2.png +0 -0
  34. data/test/{FontTableTest.rb → font_table_test.rb} +1 -6
  35. data/test/{FontTest.rb → font_test.rb} +1 -6
  36. data/test/{FooterNodeTest.rb → footer_node_test.rb} +1 -7
  37. data/test/{HeaderNodeTest.rb → header_node_test.rb} +1 -7
  38. data/test/image_node_test.rb +125 -0
  39. data/test/{InformationTest.rb → information_test.rb} +1 -7
  40. data/test/{NodeTest.rb → node_test.rb} +4 -10
  41. data/test/{ParagraphStyleTest.rb → paragraph_style_test.rb} +1 -7
  42. data/test/{StyleTest.rb → style_test.rb} +1 -7
  43. data/test/{TableCellNodeTest.rb → table_cell_node_test.rb} +1 -7
  44. data/test/{TableNodeTest.rb → table_node_test.rb} +1 -7
  45. data/test/{TableRowNodeTest.rb → table_row_node_test.rb} +1 -7
  46. data/test/test_helper.rb +13 -0
  47. data/test/{TextNodeTest.rb → text_node_test.rb} +4 -10
  48. metadata +119 -70
  49. data/doc/makedoc.bat +0 -2
  50. data/test/run.bat +0 -2
  51. data/test/unittest.bat +0 -2
  52. data/test/unittest.rb +0 -21
File without changes
File without changes
@@ -1,10 +1,4 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'test/unit'
5
- require 'rtf'
6
-
7
- include RTF
1
+ require 'test_helper'
8
2
 
9
3
  # Information class unit test class.
10
4
  class CharacterStyleTest < Test::Unit::TestCase
@@ -1,98 +1,93 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'rtf'
5
-
6
- include RTF
7
-
8
- # ColourTable class unit test class.
9
- class ColourTableTest < Test::Unit::TestCase
10
- def setup
11
- @colours = [Colour.new(0, 0, 0),
12
- Colour.new(100, 100, 100),
13
- Colour.new(150, 150, 150),
14
- Colour.new(200, 200, 200),
15
- Colour.new(250, 250, 250)]
16
- end
17
-
18
- def test_01
19
- tables = []
20
- tables.push(ColourTable.new)
21
- tables.push(ColourTable.new(@colours[0], @colours[2]))
22
- tables.push(ColourTable.new(*@colours))
23
- tables.push(ColourTable.new(@colours[0], @colours[1], @colours[0]))
24
-
25
- assert(tables[0].size == 0)
26
- assert(tables[1].size == 2)
27
- assert(tables[2].size == 5)
28
- assert(tables[3].size == 2)
29
-
30
- assert(tables[0][0] == nil)
31
- assert(tables[1][1] == @colours[2])
32
- assert(tables[2][3] == @colours[3])
33
- assert(tables[3][5] == nil)
34
-
35
- assert(tables[0].index(@colours[1]) == nil)
36
- assert(tables[1].index(@colours[2]) == 2)
37
- assert(tables[2].index(@colours[3]) == 4)
38
- assert(tables[3].index(@colours[4]) == nil)
39
-
40
- tables[0].add(@colours[0])
41
- assert(tables[0].size == 1)
42
- assert(tables[0].index(@colours[0]) == 1)
43
-
44
- tables[0] << @colours[1]
45
- assert(tables[0].size == 2)
46
- assert(tables[0].index(@colours[1]) == 2)
47
-
48
- tables[0].add(@colours[1])
49
- assert(tables[0].size == 2)
50
- assert([tables[0][0], tables[0][1]] == [@colours[0], @colours[1]])
51
-
52
- tables[0] << @colours[0]
53
- assert(tables[0].size == 2)
54
- assert([tables[0][0], tables[0][1]] == [@colours[0], @colours[1]])
55
-
56
- flags = [false, false, false, false, false]
57
- tables[2].each do |colour|
58
- flags[@colours.index(colour)] = true if @colours.index(colour) != nil
59
- end
60
- assert(flags.index(false) == nil)
61
-
62
- assert(tables[0].to_s(2) == " Colour Table (2 colours)\n"\
63
- " Colour (0/0/0)\n"\
64
- " Colour (100/100/100)")
65
- assert(tables[1].to_s(4) == " Colour Table (2 colours)\n"\
66
- " Colour (0/0/0)\n"\
67
- " Colour (150/150/150)")
68
- assert(tables[2].to_s(-6) == "Colour Table (5 colours)\n"\
69
- " Colour (0/0/0)\n"\
70
- " Colour (100/100/100)\n"\
71
- " Colour (150/150/150)\n"\
72
- " Colour (200/200/200)\n"\
73
- " Colour (250/250/250)")
74
- assert(tables[3].to_s == "Colour Table (2 colours)\n"\
75
- " Colour (0/0/0)\n"\
76
- " Colour (100/100/100)")
77
-
78
- assert(tables[0].to_rtf(3) == " {\\colortbl\n ;\n"\
79
- " \\red0\\green0\\blue0;\n"\
80
- " \\red100\\green100\\blue100;\n"\
81
- " }")
82
- assert(tables[1].to_rtf(6) == " {\\colortbl\n ;\n"\
83
- " \\red0\\green0\\blue0;\n"\
84
- " \\red150\\green150\\blue150;\n"\
85
- " }")
86
- assert(tables[2].to_rtf(-9) == "{\\colortbl\n;\n"\
87
- "\\red0\\green0\\blue0;\n"\
88
- "\\red100\\green100\\blue100;\n"\
89
- "\\red150\\green150\\blue150;\n"\
90
- "\\red200\\green200\\blue200;\n"\
91
- "\\red250\\green250\\blue250;\n"\
92
- "}")
93
- assert(tables[3].to_rtf == "{\\colortbl\n;\n"\
94
- "\\red0\\green0\\blue0;\n"\
95
- "\\red100\\green100\\blue100;\n"\
96
- "}")
97
- end
1
+ require 'test_helper'
2
+
3
+ # ColourTable class unit test class.
4
+ class ColourTableTest < Test::Unit::TestCase
5
+ def setup
6
+ @colours = [Colour.new(0, 0, 0),
7
+ Colour.new(100, 100, 100),
8
+ Colour.new(150, 150, 150),
9
+ Colour.new(200, 200, 200),
10
+ Colour.new(250, 250, 250)]
11
+ end
12
+
13
+ def test_01
14
+ tables = []
15
+ tables.push(ColourTable.new)
16
+ tables.push(ColourTable.new(@colours[0], @colours[2]))
17
+ tables.push(ColourTable.new(*@colours))
18
+ tables.push(ColourTable.new(@colours[0], @colours[1], @colours[0]))
19
+
20
+ assert(tables[0].size == 0)
21
+ assert(tables[1].size == 2)
22
+ assert(tables[2].size == 5)
23
+ assert(tables[3].size == 2)
24
+
25
+ assert(tables[0][0] == nil)
26
+ assert(tables[1][1] == @colours[2])
27
+ assert(tables[2][3] == @colours[3])
28
+ assert(tables[3][5] == nil)
29
+
30
+ assert(tables[0].index(@colours[1]) == nil)
31
+ assert(tables[1].index(@colours[2]) == 2)
32
+ assert(tables[2].index(@colours[3]) == 4)
33
+ assert(tables[3].index(@colours[4]) == nil)
34
+
35
+ tables[0].add(@colours[0])
36
+ assert(tables[0].size == 1)
37
+ assert(tables[0].index(@colours[0]) == 1)
38
+
39
+ tables[0] << @colours[1]
40
+ assert(tables[0].size == 2)
41
+ assert(tables[0].index(@colours[1]) == 2)
42
+
43
+ tables[0].add(@colours[1])
44
+ assert(tables[0].size == 2)
45
+ assert([tables[0][0], tables[0][1]] == [@colours[0], @colours[1]])
46
+
47
+ tables[0] << @colours[0]
48
+ assert(tables[0].size == 2)
49
+ assert([tables[0][0], tables[0][1]] == [@colours[0], @colours[1]])
50
+
51
+ flags = [false, false, false, false, false]
52
+ tables[2].each do |colour|
53
+ flags[@colours.index(colour)] = true if @colours.index(colour) != nil
54
+ end
55
+ assert(flags.index(false) == nil)
56
+
57
+ assert(tables[0].to_s(2) == " Colour Table (2 colours)\n"\
58
+ " Colour (0/0/0)\n"\
59
+ " Colour (100/100/100)")
60
+ assert(tables[1].to_s(4) == " Colour Table (2 colours)\n"\
61
+ " Colour (0/0/0)\n"\
62
+ " Colour (150/150/150)")
63
+ assert(tables[2].to_s(-6) == "Colour Table (5 colours)\n"\
64
+ " Colour (0/0/0)\n"\
65
+ " Colour (100/100/100)\n"\
66
+ " Colour (150/150/150)\n"\
67
+ " Colour (200/200/200)\n"\
68
+ " Colour (250/250/250)")
69
+ assert(tables[3].to_s == "Colour Table (2 colours)\n"\
70
+ " Colour (0/0/0)\n"\
71
+ " Colour (100/100/100)")
72
+
73
+ assert(tables[0].to_rtf(3) == " {\\colortbl\n ;\n"\
74
+ " \\red0\\green0\\blue0;\n"\
75
+ " \\red100\\green100\\blue100;\n"\
76
+ " }")
77
+ assert(tables[1].to_rtf(6) == " {\\colortbl\n ;\n"\
78
+ " \\red0\\green0\\blue0;\n"\
79
+ " \\red150\\green150\\blue150;\n"\
80
+ " }")
81
+ assert(tables[2].to_rtf(-9) == "{\\colortbl\n;\n"\
82
+ "\\red0\\green0\\blue0;\n"\
83
+ "\\red100\\green100\\blue100;\n"\
84
+ "\\red150\\green150\\blue150;\n"\
85
+ "\\red200\\green200\\blue200;\n"\
86
+ "\\red250\\green250\\blue250;\n"\
87
+ "}")
88
+ assert(tables[3].to_rtf == "{\\colortbl\n;\n"\
89
+ "\\red0\\green0\\blue0;\n"\
90
+ "\\red100\\green100\\blue100;\n"\
91
+ "}")
92
+ end
98
93
  end
@@ -1,122 +1,116 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'test/unit'
5
- require 'rtf'
6
-
7
- include RTF
8
-
9
- # Colour class unit test class.
10
- class ColourTest < Test::Unit::TestCase
11
- def test_01
12
- colours = []
13
- colours.push(Colour.new(255, 255, 255))
14
- colours.push(Colour.new(200, 0, 0))
15
- colours.push(Colour.new(0, 150, 0))
16
- colours.push(Colour.new(0, 0, 100))
17
- colours.push(Colour.new(0, 0, 0))
18
-
19
- assert(colours[0] == colours[0])
20
- assert(!(colours[1] == colours[2]))
21
- assert(colours[3] == Colour.new(0, 0, 100))
22
- assert(!(colours[4] == 12345))
23
-
24
- assert(colours[0].red == 255)
25
- assert(colours[0].green == 255)
26
- assert(colours[0].blue == 255)
27
-
28
- assert(colours[1].red == 200)
29
- assert(colours[1].green == 0)
30
- assert(colours[1].blue == 0)
31
-
32
- assert(colours[2].red == 0)
33
- assert(colours[2].green == 150)
34
- assert(colours[2].blue == 0)
35
-
36
- assert(colours[3].red == 0)
37
- assert(colours[3].green == 0)
38
- assert(colours[3].blue == 100)
39
-
40
- assert(colours[4].red == 0)
41
- assert(colours[4].green == 0)
42
- assert(colours[4].blue == 0)
43
-
44
- assert(colours[0].to_s(3) == ' Colour (255/255/255)')
45
- assert(colours[1].to_s(6) == ' Colour (200/0/0)')
46
- assert(colours[2].to_s(-20) == 'Colour (0/150/0)')
47
- assert(colours[3].to_s == 'Colour (0/0/100)')
48
- assert(colours[4].to_s == 'Colour (0/0/0)')
49
-
50
- assert(colours[0].to_rtf(2) == ' \red255\green255\blue255;')
51
- assert(colours[1].to_rtf(4) == ' \red200\green0\blue0;')
52
- assert(colours[2].to_rtf(-6) == '\red0\green150\blue0;')
53
- assert(colours[3].to_rtf == '\red0\green0\blue100;')
54
- assert(colours[4].to_rtf == '\red0\green0\blue0;')
55
-
56
- begin
57
- Colour.new(256, 0, 0)
58
- flunk("Successfully created a colour with an invalid red setting.")
59
- rescue RTFError
60
- rescue Test::Unit::AssertionFailedError => error
61
- raise error
62
- rescue => error
63
- flunk("Unexpected exception caught. Type: #{error.class.name}\n"\
64
- "Message: #{error.message}")
65
- end
66
-
67
- begin
68
- Colour.new(0, 1000, 0)
69
- flunk("Successfully created a colour with an invalid green setting.")
70
- rescue RTFError
71
- rescue Test::Unit::AssertionFailedError => error
72
- raise error
73
- rescue => error
74
- flunk("Unexpected exception caught. Type: #{error.class.name}\n"\
75
- "Message: #{error.message}")
76
- end
77
-
78
- begin
79
- Colour.new(0, 0, -300)
80
- flunk("Successfully created a colour with an invalid blue setting.")
81
- rescue RTFError
82
- rescue Test::Unit::AssertionFailedError => error
83
- raise error
84
- rescue => error
85
- flunk("Unexpected exception caught. Type: #{error.class.name}\n"\
86
- "Message: #{error.message}")
87
- end
88
-
89
- begin
90
- Colour.new('La la la', 0, 0)
91
- flunk("Successfully created a colour with an invalid red type.")
92
- rescue RTFError
93
- rescue Test::Unit::AssertionFailedError => error
94
- raise error
95
- rescue => error
96
- flunk("Unexpected exception caught. Type: #{error.class.name}\n"\
97
- "Message: #{error.message}")
98
- end
99
-
100
- begin
101
- Colour.new(0, {}, 0)
102
- flunk("Successfully created a colour with an invalid green type.")
103
- rescue RTFError
104
- rescue Test::Unit::AssertionFailedError => error
105
- raise error
106
- rescue => error
107
- flunk("Unexpected exception caught. Type: #{error.class.name}\n"\
108
- "Message: #{error.message}")
109
- end
110
-
111
- begin
112
- Colour.new(0, 0, [])
113
- flunk("Successfully created a colour with an invalid blue type.")
114
- rescue RTFError
115
- rescue Test::Unit::AssertionFailedError => error
116
- raise error
117
- rescue => error
118
- flunk("Unexpected exception caught. Type: #{error.class.name}\n"\
119
- "Message: #{error.message}")
120
- end
121
- end
122
- end
1
+ require 'test_helper'
2
+
3
+ # Colour class unit test class.
4
+ class ColourTest < Test::Unit::TestCase
5
+ def test_01
6
+ colours = []
7
+ colours.push(Colour.new(255, 255, 255))
8
+ colours.push(Colour.new(200, 0, 0))
9
+ colours.push(Colour.new(0, 150, 0))
10
+ colours.push(Colour.new(0, 0, 100))
11
+ colours.push(Colour.new(0, 0, 0))
12
+
13
+ assert(colours[0] == colours[0])
14
+ assert(!(colours[1] == colours[2]))
15
+ assert(colours[3] == Colour.new(0, 0, 100))
16
+ assert(!(colours[4] == 12345))
17
+
18
+ assert(colours[0].red == 255)
19
+ assert(colours[0].green == 255)
20
+ assert(colours[0].blue == 255)
21
+
22
+ assert(colours[1].red == 200)
23
+ assert(colours[1].green == 0)
24
+ assert(colours[1].blue == 0)
25
+
26
+ assert(colours[2].red == 0)
27
+ assert(colours[2].green == 150)
28
+ assert(colours[2].blue == 0)
29
+
30
+ assert(colours[3].red == 0)
31
+ assert(colours[3].green == 0)
32
+ assert(colours[3].blue == 100)
33
+
34
+ assert(colours[4].red == 0)
35
+ assert(colours[4].green == 0)
36
+ assert(colours[4].blue == 0)
37
+
38
+ assert(colours[0].to_s(3) == ' Colour (255/255/255)')
39
+ assert(colours[1].to_s(6) == ' Colour (200/0/0)')
40
+ assert(colours[2].to_s(-20) == 'Colour (0/150/0)')
41
+ assert(colours[3].to_s == 'Colour (0/0/100)')
42
+ assert(colours[4].to_s == 'Colour (0/0/0)')
43
+
44
+ assert(colours[0].to_rtf(2) == ' \red255\green255\blue255;')
45
+ assert(colours[1].to_rtf(4) == ' \red200\green0\blue0;')
46
+ assert(colours[2].to_rtf(-6) == '\red0\green150\blue0;')
47
+ assert(colours[3].to_rtf == '\red0\green0\blue100;')
48
+ assert(colours[4].to_rtf == '\red0\green0\blue0;')
49
+
50
+ begin
51
+ Colour.new(256, 0, 0)
52
+ flunk("Successfully created a colour with an invalid red setting.")
53
+ rescue RTFError
54
+ rescue Test::Unit::AssertionFailedError => error
55
+ raise error
56
+ rescue => error
57
+ flunk("Unexpected exception caught. Type: #{error.class.name}\n"\
58
+ "Message: #{error.message}")
59
+ end
60
+
61
+ begin
62
+ Colour.new(0, 1000, 0)
63
+ flunk("Successfully created a colour with an invalid green setting.")
64
+ rescue RTFError
65
+ rescue Test::Unit::AssertionFailedError => error
66
+ raise error
67
+ rescue => error
68
+ flunk("Unexpected exception caught. Type: #{error.class.name}\n"\
69
+ "Message: #{error.message}")
70
+ end
71
+
72
+ begin
73
+ Colour.new(0, 0, -300)
74
+ flunk("Successfully created a colour with an invalid blue setting.")
75
+ rescue RTFError
76
+ rescue Test::Unit::AssertionFailedError => error
77
+ raise error
78
+ rescue => error
79
+ flunk("Unexpected exception caught. Type: #{error.class.name}\n"\
80
+ "Message: #{error.message}")
81
+ end
82
+
83
+ begin
84
+ Colour.new('La la la', 0, 0)
85
+ flunk("Successfully created a colour with an invalid red type.")
86
+ rescue RTFError
87
+ rescue Test::Unit::AssertionFailedError => error
88
+ raise error
89
+ rescue => error
90
+ flunk("Unexpected exception caught. Type: #{error.class.name}\n"\
91
+ "Message: #{error.message}")
92
+ end
93
+
94
+ begin
95
+ Colour.new(0, {}, 0)
96
+ flunk("Successfully created a colour with an invalid green type.")
97
+ rescue RTFError
98
+ rescue Test::Unit::AssertionFailedError => error
99
+ raise error
100
+ rescue => error
101
+ flunk("Unexpected exception caught. Type: #{error.class.name}\n"\
102
+ "Message: #{error.message}")
103
+ end
104
+
105
+ begin
106
+ Colour.new(0, 0, [])
107
+ flunk("Successfully created a colour with an invalid blue type.")
108
+ rescue RTFError
109
+ rescue Test::Unit::AssertionFailedError => error
110
+ raise error
111
+ rescue => error
112
+ flunk("Unexpected exception caught. Type: #{error.class.name}\n"\
113
+ "Message: #{error.message}")
114
+ end
115
+ end
116
+ end
@@ -1,10 +1,4 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'test/unit'
5
- require 'rtf'
6
-
7
- include RTF
1
+ require 'test_helper'
8
2
 
9
3
  # Information class unit test class.
10
4
  class CommandNodeTest < Test::Unit::TestCase