rtf 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +5 -0
- data/LICENSE +20 -0
- data/{doc/README → README.rdoc} +10 -2
- data/Rakefile +47 -0
- data/VERSION.yml +5 -0
- data/examples/example01.rb +0 -0
- data/examples/example02.rb +0 -0
- data/examples/example03.rb +4 -4
- data/examples/example03.rtf +0 -0
- data/examples/example04.rb +50 -0
- data/examples/rubyrtf.bmp +0 -0
- data/examples/rubyrtf.jpg +0 -0
- data/examples/rubyrtf.png +0 -0
- data/lib/rtf.rb +0 -0
- data/lib/rtf/colour.rb +0 -0
- data/lib/rtf/font.rb +0 -0
- data/lib/rtf/information.rb +2 -3
- data/lib/rtf/node.rb +294 -29
- data/lib/rtf/paper.rb +0 -0
- data/lib/rtf/style.rb +0 -0
- data/test/{CharacterStyleTest.rb → character_style_test.rb} +1 -7
- data/test/{ColourTableTest.rb → colour_table_test.rb} +92 -97
- data/test/{ColourTest.rb → colour_test.rb} +116 -122
- data/test/{CommandNodeTest.rb → command_node_test.rb} +1 -7
- data/test/{ContainerNodeTest.rb → container_node_test.rb} +3 -9
- data/test/{DocumentStyleTest.rb → document_style_test.rb} +1 -7
- data/test/{DocumentTest.rb → document_test.rb} +1 -7
- data/test/fixtures/bitmap1.bmp +0 -0
- data/test/fixtures/bitmap2.bmp +0 -0
- data/test/fixtures/jpeg1.jpg +0 -0
- data/test/fixtures/jpeg2.jpg +0 -0
- data/test/fixtures/png1.png +0 -0
- data/test/fixtures/png2.png +0 -0
- data/test/{FontTableTest.rb → font_table_test.rb} +1 -6
- data/test/{FontTest.rb → font_test.rb} +1 -6
- data/test/{FooterNodeTest.rb → footer_node_test.rb} +1 -7
- data/test/{HeaderNodeTest.rb → header_node_test.rb} +1 -7
- data/test/image_node_test.rb +125 -0
- data/test/{InformationTest.rb → information_test.rb} +1 -7
- data/test/{NodeTest.rb → node_test.rb} +4 -10
- data/test/{ParagraphStyleTest.rb → paragraph_style_test.rb} +1 -7
- data/test/{StyleTest.rb → style_test.rb} +1 -7
- data/test/{TableCellNodeTest.rb → table_cell_node_test.rb} +1 -7
- data/test/{TableNodeTest.rb → table_node_test.rb} +1 -7
- data/test/{TableRowNodeTest.rb → table_row_node_test.rb} +1 -7
- data/test/test_helper.rb +13 -0
- data/test/{TextNodeTest.rb → text_node_test.rb} +4 -10
- metadata +119 -70
- data/doc/makedoc.bat +0 -2
- data/test/run.bat +0 -2
- data/test/unittest.bat +0 -2
- data/test/unittest.rb +0 -21
data/lib/rtf/paper.rb
CHANGED
File without changes
|
data/lib/rtf/style.rb
CHANGED
File without changes
|
@@ -1,98 +1,93 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
tables.
|
21
|
-
tables
|
22
|
-
tables.
|
23
|
-
tables
|
24
|
-
|
25
|
-
assert(tables[0]
|
26
|
-
assert(tables[1]
|
27
|
-
assert(tables[2]
|
28
|
-
assert(tables[3]
|
29
|
-
|
30
|
-
assert(tables[0][
|
31
|
-
assert(tables[1][
|
32
|
-
assert(tables[2][3] ==
|
33
|
-
assert(tables[3][
|
34
|
-
|
35
|
-
|
36
|
-
assert(tables[
|
37
|
-
assert(tables[
|
38
|
-
|
39
|
-
|
40
|
-
tables[0].
|
41
|
-
assert(tables[0].
|
42
|
-
|
43
|
-
|
44
|
-
tables[0]
|
45
|
-
assert(tables[0]
|
46
|
-
|
47
|
-
|
48
|
-
tables[0].
|
49
|
-
assert(tables[0]
|
50
|
-
|
51
|
-
|
52
|
-
tables[
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
tables[
|
58
|
-
|
59
|
-
|
60
|
-
assert(
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
"
|
80
|
-
"
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
"
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
colours
|
14
|
-
|
15
|
-
colours
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
assert(colours[0] ==
|
20
|
-
assert(
|
21
|
-
|
22
|
-
assert(
|
23
|
-
|
24
|
-
assert(colours[
|
25
|
-
|
26
|
-
assert(colours[
|
27
|
-
|
28
|
-
assert(colours[
|
29
|
-
|
30
|
-
assert(colours[
|
31
|
-
|
32
|
-
assert(colours[
|
33
|
-
|
34
|
-
assert(colours[
|
35
|
-
|
36
|
-
assert(colours[
|
37
|
-
|
38
|
-
assert(colours[
|
39
|
-
|
40
|
-
assert(colours[
|
41
|
-
assert(colours[
|
42
|
-
assert(colours[4].
|
43
|
-
|
44
|
-
assert(colours[0].
|
45
|
-
assert(colours[1].
|
46
|
-
assert(colours[2].
|
47
|
-
assert(colours[3].
|
48
|
-
assert(colours[4].
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
flunk("
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
flunk("
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
flunk("
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
flunk("
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
flunk("
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|