thinreports 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CONTRIBUTING.md +2 -0
  3. data/.travis.yml +3 -3
  4. data/CHANGELOG.md +98 -1
  5. data/README.md +0 -9
  6. data/Rakefile +1 -2
  7. data/examples/character_spacing/character_spacing.tlf +293 -1
  8. data/examples/dynamic_image/dynamic_image.tlf +661 -1
  9. data/examples/dynamic_style/dynamic_style.rb +4 -4
  10. data/examples/dynamic_style/dynamic_style.tlf +1835 -1
  11. data/examples/dynamic_style/dynamic_style_in_list.tlf +344 -1
  12. data/examples/eudc/eudc.tlf +180 -1
  13. data/examples/hidden_shapes/hidden_shapes.tlf +449 -1
  14. data/examples/list_events/list_events.rb +1 -28
  15. data/examples/list_events/list_events.tlf +361 -0
  16. data/examples/list_manual_generation/list_manual_generation.tlf +132 -1
  17. data/examples/list_page_number/list_page_number.tlf +254 -1
  18. data/examples/page_number/page_number.tlf +215 -1
  19. data/examples/palleted_png/palleted_png.rb +2 -0
  20. data/examples/palleted_png/palleted_png.tlf +47 -1
  21. data/examples/password_setting/password_setting.tlf +45 -1
  22. data/examples/report_callbacks/report_callbacks.rb +1 -18
  23. data/examples/report_callbacks/report_callbacks.tlf +147 -1
  24. data/examples/single_line_tblock/single_line_tblock.tlf +170 -1
  25. data/examples/tblock_overflow/tblock_overflow.tlf +538 -1
  26. data/examples/tblock_styles/font_size.tlf +383 -1
  27. data/examples/tblock_styles/tblock_styles.tlf +889 -1
  28. data/examples/text_align/text_align.tlf +241 -1
  29. data/examples/typeB_page_size/B4_ISO.tlf +45 -1
  30. data/examples/typeB_page_size/B4_JIS.tlf +45 -1
  31. data/examples/word_wrap/word_wrap.tlf +297 -1
  32. data/lib/thinreports.rb +0 -1
  33. data/lib/thinreports/config.rb +3 -0
  34. data/lib/thinreports/core/errors.rb +0 -3
  35. data/lib/thinreports/core/format/base.rb +4 -4
  36. data/lib/thinreports/core/shape.rb +1 -9
  37. data/lib/thinreports/core/shape/basic.rb +3 -3
  38. data/lib/thinreports/core/shape/basic/block_format.rb +1 -1
  39. data/lib/thinreports/core/shape/basic/format.rb +2 -14
  40. data/lib/thinreports/core/shape/basic/internal.rb +2 -2
  41. data/lib/thinreports/core/shape/image_block.rb +3 -3
  42. data/lib/thinreports/core/shape/image_block/format.rb +0 -2
  43. data/lib/thinreports/core/shape/image_block/internal.rb +1 -1
  44. data/lib/thinreports/core/shape/list.rb +3 -7
  45. data/lib/thinreports/core/shape/list/format.rb +37 -24
  46. data/lib/thinreports/core/shape/list/manager.rb +1 -36
  47. data/lib/thinreports/core/shape/list/page.rb +0 -15
  48. data/lib/thinreports/core/shape/list/page_state.rb +1 -1
  49. data/lib/thinreports/core/shape/list/section_format.rb +14 -12
  50. data/lib/thinreports/core/shape/list/section_internal.rb +4 -7
  51. data/lib/thinreports/core/shape/manager/format.rb +0 -2
  52. data/lib/thinreports/core/shape/manager/internal.rb +1 -1
  53. data/lib/thinreports/core/shape/page_number.rb +1 -1
  54. data/lib/thinreports/core/shape/page_number/format.rb +9 -6
  55. data/lib/thinreports/core/shape/page_number/interface.rb +1 -1
  56. data/lib/thinreports/core/shape/page_number/internal.rb +2 -6
  57. data/lib/thinreports/core/shape/style/base.rb +11 -13
  58. data/lib/thinreports/core/shape/style/basic.rb +4 -4
  59. data/lib/thinreports/core/shape/style/graphic.rb +4 -10
  60. data/lib/thinreports/core/shape/style/text.rb +36 -69
  61. data/lib/thinreports/core/shape/text.rb +3 -3
  62. data/lib/thinreports/core/shape/text/format.rb +3 -13
  63. data/lib/thinreports/core/shape/text/internal.rb +2 -2
  64. data/lib/thinreports/core/shape/text_block.rb +3 -3
  65. data/lib/thinreports/core/shape/text_block/format.rb +9 -6
  66. data/lib/thinreports/core/shape/text_block/interface.rb +7 -7
  67. data/lib/thinreports/core/shape/text_block/internal.rb +1 -1
  68. data/lib/thinreports/generator/pdf.rb +0 -1
  69. data/lib/thinreports/generator/pdf/document.rb +2 -2
  70. data/lib/thinreports/generator/pdf/document/draw_shape.rb +25 -51
  71. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +66 -0
  72. data/lib/thinreports/generator/pdf/document/font.rb +3 -8
  73. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +97 -77
  74. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +18 -13
  75. data/lib/thinreports/generator/pdf/document/graphics/image.rb +17 -12
  76. data/lib/thinreports/generator/pdf/document/page.rb +1 -1
  77. data/lib/thinreports/generator/pdf/drawer/list.rb +5 -1
  78. data/lib/thinreports/generator/pdf/drawer/list_section.rb +1 -4
  79. data/lib/thinreports/generator/pdf/drawer/page.rb +9 -9
  80. data/lib/thinreports/layout.rb +3 -3
  81. data/lib/thinreports/layout/base.rb +0 -16
  82. data/lib/thinreports/layout/format.rb +38 -57
  83. data/lib/thinreports/layout/legacy_schema.rb +354 -0
  84. data/lib/thinreports/layout/version.rb +1 -1
  85. data/lib/thinreports/report.rb +0 -1
  86. data/lib/thinreports/report/base.rb +3 -17
  87. data/lib/thinreports/report/internal.rb +13 -55
  88. data/lib/thinreports/report/page.rb +1 -1
  89. data/lib/thinreports/version.rb +1 -1
  90. data/test/data/legacy_layout/all-items.tlf +1 -0
  91. data/test/schema_helper.rb +121 -0
  92. data/test/test_helper.rb +13 -50
  93. data/test/unit/core/format/test_base.rb +35 -31
  94. data/test/unit/core/shape/base/test_internal.rb +1 -1
  95. data/test/unit/core/shape/basic/test_block_format.rb +23 -0
  96. data/test/unit/core/shape/basic/{test_basic_interface.rb → test_block_interface.rb} +1 -1
  97. data/test/unit/core/shape/basic/{test_basic_internal.rb → test_block_internal.rb} +4 -7
  98. data/test/unit/core/shape/basic/test_format.rb +25 -47
  99. data/test/unit/core/shape/basic/test_interface.rb +5 -5
  100. data/test/unit/core/shape/basic/test_internal.rb +6 -11
  101. data/test/unit/core/shape/image_block/test_interface.rb +5 -5
  102. data/test/unit/core/shape/image_block/test_internal.rb +2 -2
  103. data/test/unit/core/shape/list/test_format.rb +86 -44
  104. data/test/unit/core/shape/list/test_manager.rb +10 -65
  105. data/test/unit/core/shape/list/test_page.rb +10 -61
  106. data/test/unit/core/shape/list/test_page_state.rb +1 -1
  107. data/test/unit/core/shape/list/test_section_format.rb +19 -28
  108. data/test/unit/core/shape/list/test_section_interface.rb +14 -6
  109. data/test/unit/core/shape/list/test_section_internal.rb +17 -23
  110. data/test/unit/core/shape/manager/test_format.rb +1 -1
  111. data/test/unit/core/shape/manager/test_internal.rb +59 -98
  112. data/test/unit/core/shape/manager/test_target.rb +21 -30
  113. data/test/unit/core/shape/page_number/test_format.rb +34 -52
  114. data/test/unit/core/shape/page_number/test_interface.rb +1 -1
  115. data/test/unit/core/shape/page_number/test_internal.rb +2 -2
  116. data/test/unit/core/shape/styles/test_base.rb +16 -41
  117. data/test/unit/core/shape/styles/test_basic.rb +7 -7
  118. data/test/unit/core/shape/styles/test_graphic.rb +27 -32
  119. data/test/unit/core/shape/styles/test_text.rb +68 -311
  120. data/test/unit/core/shape/text/test_format.rb +30 -59
  121. data/test/unit/core/shape/text/test_internal.rb +5 -5
  122. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +13 -13
  123. data/test/unit/core/shape/text_block/test_format.rb +145 -146
  124. data/test/unit/core/shape/text_block/test_interface.rb +9 -9
  125. data/test/unit/core/shape/text_block/test_internal.rb +9 -9
  126. data/test/unit/core/test_shape.rb +19 -31
  127. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +112 -122
  128. data/test/unit/generator/pdf/document/graphics/test_basic.rb +45 -0
  129. data/test/unit/generator/pdf/document/graphics/test_image.rb +5 -5
  130. data/test/unit/generator/pdf/document/test_font.rb +4 -10
  131. data/test/unit/generator/pdf/document/test_page.rb +13 -11
  132. data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
  133. data/test/unit/generator/test_base.rb +5 -5
  134. data/test/unit/generator/test_configuration.rb +4 -8
  135. data/test/unit/generator/test_pdf.rb +3 -2
  136. data/test/unit/layout/test_base.rb +16 -22
  137. data/test/unit/layout/test_format.rb +66 -86
  138. data/test/unit/layout/test_legacy_schema.rb +587 -0
  139. data/test/unit/layout/test_version.rb +20 -20
  140. data/test/unit/report/test_base.rb +32 -45
  141. data/test/unit/report/test_internal.rb +43 -99
  142. data/test/unit/test_config.rb +4 -2
  143. data/test/unit/test_layout.rb +1 -1
  144. metadata +20 -48
  145. data/examples/list_events/list_events_0_7_7.tlf +0 -1
  146. data/examples/list_events/list_events_0_8.tlf +0 -1
  147. data/lib/thinreports/core/events.rb +0 -69
  148. data/lib/thinreports/core/format/builder.rb +0 -62
  149. data/lib/thinreports/core/shape/list/configuration.rb +0 -54
  150. data/lib/thinreports/core/shape/list/events.rb +0 -47
  151. data/lib/thinreports/core/shape/list/store.rb +0 -33
  152. data/lib/thinreports/generator/pdf/configuration.rb +0 -33
  153. data/lib/thinreports/generator/pdf/document/parse_svg.rb +0 -104
  154. data/lib/thinreports/layout/configuration.rb +0 -29
  155. data/test/data/layout_block.tlf +0 -1
  156. data/test/data/layout_list.tlf +0 -1
  157. data/test/data/layout_list_noheader.tlf +0 -1
  158. data/test/data/layout_text1.tlf +0 -1
  159. data/test/data/layout_text2.tlf +0 -1
  160. data/test/unit/core/format/test_builder.rb +0 -109
  161. data/test/unit/core/shape/basic/test_basic_format.rb +0 -30
  162. data/test/unit/core/shape/image_block/test_format.rb +0 -58
  163. data/test/unit/core/shape/list/test_configuration.rb +0 -69
  164. data/test/unit/core/shape/list/test_events.rb +0 -36
  165. data/test/unit/core/shape/list/test_store.rb +0 -41
  166. data/test/unit/core/test_events.rb +0 -93
  167. data/test/unit/generator/pdf/document/test_draw_shape.rb +0 -44
  168. data/test/unit/generator/pdf/test_configuration.rb +0 -31
  169. data/test/unit/layout/test_configuration.rb +0 -21
  170. data/test/unit/report/test_events.rb +0 -22
@@ -4,337 +4,94 @@ require 'test_helper'
4
4
 
5
5
  class Thinreports::Core::Shape::Style::TestText < Minitest::Test
6
6
  include Thinreports::TestHelper
7
-
8
- def create_format(format = {})
9
- Thinreports::Core::Shape::Text::Format.new(format)
10
- end
11
-
12
- def create_text_style(format = nil)
13
- format ||= create_format
14
- Thinreports::Core::Shape::Style::Text.new(format)
7
+
8
+ def test_color
9
+ style = create_text_style('color' => 'red')
10
+ assert_equal 'red', style.color
11
+
12
+ style.color = 'blue'
13
+ assert_equal 'blue', style.styles['color']
14
+ assert_equal 'blue', style.color
15
15
  end
16
16
 
17
17
  def test_font_size
18
- format = create_format('svg' => {'attrs' => {'font-size' => '12'}})
19
- style = create_text_style(format)
20
-
21
- assert_equal style.font_size, '12'
18
+ style = create_text_style('font-size' => 18.0)
19
+ assert_equal 18.0, style.font_size
22
20
 
23
21
  style.font_size = 19
24
-
25
- assert_equal style.styles['font-size'], 19
22
+ assert_equal 19, style.styles['font-size']
23
+ assert_equal 19, style.font_size
26
24
  end
27
25
 
28
- def test_bold_should_return_true_when_font_weight_property_of_format_is_bold
29
- format = create_format('svg' => {'attrs' => {'font-weight' => 'bold'}})
30
- style = create_text_style(format)
31
-
32
- assert_equal style.bold, true
33
- end
34
-
35
- def test_bold_should_return_false_when_font_weight_property_of_format_is_not_bold
36
- format = create_format('svg' => {'attrs' => {'font-weight' => 'normal'}})
37
- style = create_text_style(format)
38
-
39
- assert_equal style.bold, false
26
+ def test_initialize_font_style
27
+ default_font_style = ['bold', 'italic']
28
+ style = create_text_style('font-style' => default_font_style)
29
+
30
+ refute_same default_font_style, style.styles['font-style']
31
+ assert_equal default_font_style, style.styles['font-style']
40
32
  end
41
-
42
- def test_bold_should_set_normal_to_font_weight_style_when_value_is_false
43
- style = create_text_style
33
+
34
+ def test_bold
35
+ style = create_text_style('font-style' => ['bold'])
36
+ assert_equal true, style.bold
37
+
44
38
  style.bold = false
45
-
46
- assert_equal style.styles['font-weight'], 'normal'
47
- end
48
-
49
- def test_bold_should_set_bold_to_font_weight_style_when_value_is_true
50
- style = create_text_style
51
- style.bold = true
52
-
53
- assert_equal style.styles['font-weight'], 'bold'
54
- end
55
-
56
- def test_bold_should_return_true_when_font_weight_of_internal_style_is_bold
57
- style = create_text_style
58
- style.styles['font-weight'] = 'bold'
59
-
60
- assert_equal style.bold, true
39
+ assert_equal [], style.styles['font-style']
40
+ assert_equal false, style.bold
61
41
  end
62
-
63
- def test_bold_should_return_false_when_font_weight_of_internal_style_is_not_bold
64
- style = create_text_style
65
- style.styles['font-weight'] = 'normal'
66
-
67
- assert_equal style.bold, false
68
- end
69
-
70
- def test_italic_should_return_true_when_font_style_property_of_format_is_italic
71
- format = create_format('svg' => {'attrs' => {'font-style' => 'italic'}})
72
- style = create_text_style(format)
73
-
74
- assert_equal style.italic, true
75
- end
76
-
77
- def test_italic_should_return_false_when_font_style_property_of_format_is_not_italic
78
- format = create_format('svg' => {'attrs' => {'font-style' => 'normal'}})
79
- style = create_text_style(format)
80
-
81
- assert_equal style.italic, false
82
- end
83
-
84
- def test_italic_should_set_normal_to_font_style_style_when_value_is_false
85
- style = create_text_style
42
+
43
+ def test_italic
44
+ style = create_text_style('font-style' => ['italic'])
45
+ assert_equal true, style.italic
46
+
86
47
  style.italic = false
87
-
88
- assert_equal style.styles['font-style'], 'normal'
89
- end
90
-
91
- def test_italic_should_set_italic_to_font_style_style_when_value_is_true
92
- style = create_text_style
93
- style.italic = true
94
-
95
- assert_equal style.styles['font-style'], 'italic'
96
- end
97
-
98
- def test_italic_should_return_false_when_font_style_of_internal_style_is_not_italic
99
- style = create_text_style
100
- style.styles['font-style'] = 'normal'
101
-
102
- assert_equal style.italic, false
103
- end
104
-
105
- def test_italic_should_return_true_when_font_style_of_internal_style_is_italic
106
- style = create_text_style
107
- style.styles['font-style'] = 'italic'
108
-
109
- assert_equal style.italic, true
110
- end
111
-
112
- def test_underline_should_return_true_when_underline_is_included_in_text_decoration_property_of_format
113
- format = create_format('svg' => {'attrs' => {'text-decoration' => 'underline line-through'}})
114
- style = create_text_style(format)
115
-
116
- assert_equal style.underline, true
117
- end
118
-
119
- def test_underline_should_return_false_when_underline_is_not_included_in_text_decoration_property_of_format
120
- format = create_format('svg' => {'attrs' => {'text-decoration' => 'line-through'}})
121
- style = create_text_style(format)
122
-
123
- assert_equal style.underline, false
124
- end
125
-
126
- def test_underline_should_return_true_when_underline_is_included_in_text_decoration_of_internal_style
127
- style = create_text_style
128
- style.styles['text-decoration'] = 'underline line-through'
129
-
130
- assert_equal style.underline, true
131
- end
132
-
133
- def test_underline_should_return_false_when_underline_is_not_included_in_text_decoration_of_internal_style
134
- style = create_text_style
135
- style.styles['text-decoration'] = 'none'
136
-
137
- assert_equal style.underline, false
48
+ assert_equal [], style.styles['font-style']
49
+ assert_equal false, style.italic
138
50
  end
139
-
140
- def test_underline_should_include_underline_in_text_decoration_when_value_is_true
141
- format = create_format('svg' => {'attrs' => {'text-decoration' => 'line-through'}})
142
- style = create_text_style(format)
143
- style.underline = true
144
-
145
- assert_includes style.styles['text-decoration'], 'underline'
146
- end
147
-
148
- def test_underline_should_remove_underline_from_text_decoration_when_value_is_false
149
- format = create_format('svg' => {'attrs' => {'text-decoration' => 'underline line-through'}})
150
- style = create_text_style(format)
51
+
52
+ def test_underline
53
+ style = create_text_style('font-style' => ['underline'])
54
+ assert_equal true, style.underline
55
+
151
56
  style.underline = false
152
-
153
- refute_includes style.styles['text-decoration'], 'underline'
154
- end
155
-
156
- def test_linethrough_should_return_true_when_line_through_is_included_in_text_decoration_property_of_format
157
- format = create_format('svg' => {'attrs' => {'text-decoration' => 'underline line-through'}})
158
- style = create_text_style(format)
159
-
160
- assert_equal style.linethrough, true
161
- end
162
-
163
- def test_linethrough_should_return_false_when_line_through_is_not_included_in_text_decoration_property_of_format
164
- format = create_format('svg' => {'attrs' => {'text-decoration' => 'underline'}})
165
- style = create_text_style(format)
166
-
167
- assert_equal style.linethrough, false
168
- end
169
-
170
- def test_linethrough_should_return_true_when_line_through_is_included_in_text_decoration_of_internal_style
171
- style = create_text_style
172
- style.styles['text-decoration'] = 'underline line-through'
173
-
174
- assert_equal style.linethrough, true
175
- end
176
-
177
- def test_linethrough_should_return_false_when_line_through_is_not_included_in_text_decoration_of_internal_style
178
- style = create_text_style
179
- style.styles['text-decoration'] = 'underline'
180
-
181
- assert_equal style.linethrough, false
57
+ assert_equal [], style.styles['font-style']
58
+ assert_equal false, style.underline
182
59
  end
183
-
184
- def test_linethrough_should_include_line_through_in_text_decoration_when_value_is_true
185
- format = create_format('svg' => {'attrs' => {'text-decoration' => 'none'}})
186
- style = create_text_style(format)
187
- style.linethrough = true
188
-
189
- assert_includes style.styles['text-decoration'], 'line-through'
190
- end
191
-
192
- def test_linethrough_should_remove_line_through_from_text_decoration_when_value_is_false
193
- format = create_format('svg' => {'attrs' => {'text-decoration' => 'underline line-through'}})
194
- style = create_text_style(format)
60
+
61
+ def test_linethrough
62
+ style = create_text_style('font-style' => ['linethrough'])
63
+ assert_equal true, style.linethrough
64
+
195
65
  style.linethrough = false
196
-
197
- refute_includes style.styles['text-decoration'], 'line-through'
198
- end
199
-
200
- def test_text_decoration_should_return_none
201
- assert_equal create_text_style.send(:text_decoration, false, false), 'none'
202
- end
203
-
204
- def test_text_decoration_should_return_underline
205
- assert_equal create_text_style.send(:text_decoration, true, false), 'underline'
206
- end
207
-
208
- def test_text_decoration_should_return_line_through
209
- assert_equal create_text_style.send(:text_decoration, false, true), 'line-through'
210
- end
211
-
212
- def test_text_decoration_should_return_underline_line_through
213
- assert_equal create_text_style.send(:text_decoration, true, true), 'underline line-through'
214
- end
215
-
216
- def test_interface_text_align_should_return_Symbol_left_when_value_is_undefined
217
- assert_equal create_text_style.send(:interface_text_align, nil), :left
218
- end
219
-
220
- def test_interface_text_align_should_return_Symbol_left_when_value_is_String_start
221
- assert_equal create_text_style.send(:interface_text_align, 'start'), :left
222
- end
223
-
224
- def test_interface_text_align_should_return_Symbol_left_when_value_is_unknown_align_type
225
- assert_equal create_text_style.send(:interface_text_align, 'unknown'), :left
226
- end
227
-
228
- def test_interface_text_align_should_return_Symbol_center_when_value_is_String_middle
229
- assert_equal create_text_style.send(:interface_text_align, 'middle'), :center
230
- end
231
-
232
- def test_interface_text_align_should_return_Symbol_right_when_value_is_String_end
233
- assert_equal create_text_style.send(:interface_text_align, 'end'), :right
234
- end
235
-
236
- def test_internal_text_align_should_return_nil_when_value_is_unknown
237
- assert_equal create_text_style.send(:internal_text_align, :unknown), nil
238
- end
239
-
240
- def test_internal_text_align_should_return_String_start_when_value_is_Symbol_left
241
- assert_equal create_text_style.send(:internal_text_align, :left), 'start'
242
- end
243
-
244
- def test_internal_text_align_should_return_String_middle_when_value_is_Symbol_center
245
- assert_equal create_text_style.send(:internal_text_align, :center), 'middle'
246
- end
247
-
248
- def test_internal_text_align_should_return_String_end_when_value_is_Symbol_right
249
- assert_equal create_text_style.send(:internal_text_align, :right), 'end'
66
+ assert_equal [], style.styles['font-style']
67
+ assert_equal false, style.linethrough
250
68
  end
251
-
252
- def test_align_should_properly_return_align_type_with_reference_to_text_anchor_property_of_format
253
- result = []
254
-
255
- format_left = create_format('svg' => {'attrs' => {'text-anchor' => 'start'}})
256
- format_center = create_format('svg' => {'attrs' => {'text-anchor' => 'middle'}})
257
- format_right = create_format('svg' => {'attrs' => {'text-anchor' => 'end'}})
258
-
259
- result << create_text_style(format_left).align
260
- result << create_text_style(format_center).align
261
- result << create_text_style(format_right).align
262
-
263
- assert_equal result, [:left, :center, :right]
264
- end
265
-
266
- def test_copy_should_properly_copy_the_valign_property_of_the_original
267
- style = create_text_style
268
- style.valign = :center
269
-
270
- assert_equal style.copy.valign, :center
271
- end
272
-
273
- def test_align_should_property_return_align_type_with_reference_to_text_anchor_of_internal_style
274
- style = create_text_style
275
- style.styles['text-anchor'] = 'middle'
276
-
277
- assert_equal style.align, :center
278
- end
279
-
280
- def test_align_should_set_interface_align_type_to_text_anchor
281
- style = create_text_style
69
+
70
+ def test_align
71
+ style = create_text_style('text-align' => 'center')
72
+ assert_equal :center, style.align
73
+
282
74
  style.align = :right
283
-
284
- assert_equal style.styles['text-anchor'], 'end'
285
- end
286
-
287
- def test_align_should_raise_when_the_specified_type_is_unknown
288
- assert_raises ArgumentError do
289
- create_text_style.align = :unknown
290
- end
291
- end
292
-
293
- def test_valign_should_return_top_when_valign_of_format_is_blank
294
- assert_equal create_text_style.valign, :top
295
- end
296
-
297
- def test_valign_should_return_valign_type_of_format_as_default
298
- format = create_format('valign' => 'bottom')
299
- style = create_text_style(format)
300
-
301
- assert_equal style.valign, :bottom
302
- end
303
-
304
- def test_valign_should_properly_set_valign_type
305
- style = create_text_style
306
- style.valign = :center
307
-
308
- assert_equal style.valign, :center
309
- end
310
-
311
- def test_valign_should_raise_when_the_specified_type_is_unknown
312
- assert_raises ArgumentError do
313
- create_text_style.valign = :unknonw
314
- end
75
+ assert_equal 'right', style.styles['text-align']
76
+ assert_equal :right, style.align
315
77
  end
316
78
 
317
- def test_initialize
318
- klass = Class.new(Thinreports::Core::Shape::Style::Text)
319
- klass.class_eval do
320
- accessible_styles.delete(:valign)
321
- end
79
+ def test_valign
80
+ style = create_text_style('vertical-align' => '')
81
+ assert_equal :top, style.valign
322
82
 
323
- style = klass.new(create_format('valign' => ''))
324
- assert_equal style.valign, :top, 'should be set :top as default to @valign style ' +
325
- 'if :valign is not accessible'
326
- end
327
-
328
- def test_identifier_should_return_the_same_value_as_create_identifier_method_when_valign_has_not_been_changed
329
- style = create_text_style
330
- assert_equal style.identifier, style.send(:create_identifier, style.styles)
83
+ style.valign = :middle
84
+ assert_equal 'middle', style.styles['vertical-align']
85
+ assert_equal :middle, style.valign
86
+
87
+ assert_deprecated { style.valign = :center }
88
+ assert_equal :middle, style.valign
331
89
  end
332
-
333
- def test_identifier_should_return_the_value_which_added_valign_to_the_value_of_create_identifier_when_valign_has_been_changed
334
- style = create_text_style
335
- style.valign = :bottom
336
-
337
- assert_equal style.identifier,
338
- style.send(:create_identifier, style.styles) + 'bottom'
90
+
91
+ private
92
+
93
+ def create_text_style(default_style = {})
94
+ format = Thinreports::Core::Shape::Text::Format.new('style' => default_style)
95
+ Thinreports::Core::Shape::Style::Text.new(format)
339
96
  end
340
97
  end
@@ -5,69 +5,40 @@ require 'test_helper'
5
5
  class Thinreports::Core::Shape::Text::TestFormat < Minitest::Test
6
6
  include Thinreports::TestHelper
7
7
 
8
- TEST_TEXT_FORMAT = {
9
- "type" => "s-text",
10
- "id" => "text_1",
11
- "display" => "true",
12
- "text" => ["Text Content1", "Text Content2"],
13
- "valign" => "top",
14
- "line-height" => 60,
15
- "box" => {
16
- "x" => 100.0,
17
- "y" => 100.0,
18
- "width" => 100.0,
19
- "height" => 100.0
20
- },
21
- "svg" => {
22
- "tag" => "g",
23
- "attrs" => {
24
- "stroke-width" => "0",
25
- "font-weight" => "normal",
26
- "font-style" => "normal",
27
- "font-family" => "Arial",
28
- "font-size" => "12",
29
- "text-anchor" => "start",
30
- "fill" => "#000000",
31
- "fill-opacity" => "1",
32
- "text-decoration" => "none",
33
- "letter-spacing" => "normal"
34
- },
35
- "content" => "<text class=\"s-text-l0\" xml:space=\"preserve\" " +
36
- "stroke=\"none\" fill=\"inherit\" fill-opacity=\"1\" " +
37
- "text-decoration=\"none\" x=\"92\" y=\"93\">" +
38
- "Text Content1</text>" +
39
- "<text class=\"s-text-l1\" xml:space=\"preserve\" " +
40
- "stroke=\"none\" fill=\"inherit\" fill-opacity=\"1\" " +
41
- "text-decoration=\"none\" x=\"92\" y=\"107\">" +
42
- "Text Content2</text>"
8
+ TEXT_FORMAT = {
9
+ 'id' => 'text_1',
10
+ 'type' => 'text',
11
+ 'x' => 100.0,
12
+ 'y' => 200.0,
13
+ 'width' => 300.0,
14
+ 'height' => 400.0,
15
+ 'description' => 'Description for item',
16
+ 'display' => true,
17
+ 'texts' => [
18
+ '1st text line',
19
+ '2nd text line'
20
+ ],
21
+ 'valign' => 'top',
22
+ 'style' => {
23
+ 'font-family' => ['Arial'],
24
+ 'font-size' => 12,
25
+ 'color' => '#000000',
26
+ 'font-style' => ['bold', 'italic', 'linethrough', 'underline'],
27
+ 'text-align' => 'left',
28
+ 'vertical-align' => 'top',
29
+ 'line-height' => 60,
30
+ 'line-height-ratio' => 1.5,
31
+ 'letter-spacing' => 'normal'
43
32
  }
44
33
  }
45
34
 
46
- # Alias
47
- Format = Thinreports::Core::Shape::Text::Format
35
+ Text = Thinreports::Core::Shape::Text
48
36
 
49
- def test_build_format
50
- build_format
51
- rescue => e
52
- flunk exception_details(e, 'Building failed.')
53
- end
37
+ def test_attribute_readers
38
+ format = Text::Format.new(TEXT_FORMAT)
54
39
 
55
- def test_config_readers
56
- format = Format.new(TEST_TEXT_FORMAT)
57
-
58
- assert_instance_of ::Hash, format.box
59
- assert_equal format.box['x'], 100.0
60
-
61
- assert_instance_of ::Array, format.text
62
- assert_equal format.text.first, 'Text Content1'
63
-
64
- assert_equal format.valign, 'top'
65
- assert_equal format.line_height, 60
66
-
67
- assert_equal format.svg_content, TEST_TEXT_FORMAT['svg']['content']
68
- end
69
-
70
- def build_format
71
- Format.build(TEST_TEXT_FORMAT)
40
+ assert_equal TEXT_FORMAT['texts'], format.texts
41
+ assert_equal 'top', format.valign
42
+ assert_equal 60, format.line_height
72
43
  end
73
44
  end