thinreports 0.7.7 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -6
  3. data/.travis.yml +4 -10
  4. data/CHANGELOG.md +220 -0
  5. data/Gemfile +3 -3
  6. data/MIT-LICENSE +1 -1
  7. data/README.md +286 -0
  8. data/Rakefile +38 -8
  9. data/examples/character_spacing/character_spacing.rb +8 -0
  10. data/examples/character_spacing/character_spacing.tlf +1 -0
  11. data/examples/dynamic_image/dynamic_image.rb +31 -0
  12. data/examples/dynamic_image/dynamic_image.tlf +1 -0
  13. data/{test/case → examples}/dynamic_image/img200x100.png +0 -0
  14. data/{test/case → examples}/dynamic_image/img50x50.png +0 -0
  15. data/examples/dynamic_style/dynamic_style.rb +150 -0
  16. data/examples/dynamic_style/dynamic_style.tlf +1 -0
  17. data/examples/dynamic_style/dynamic_style_in_list.tlf +1 -0
  18. data/{test/case → examples}/dynamic_style/image.png +0 -0
  19. data/examples/eudc/eudc.rb +20 -0
  20. data/examples/eudc/eudc.tlf +1 -0
  21. data/{test/case → examples}/eudc/eudc.ttf +0 -0
  22. data/{test/case → examples}/helper.rb +14 -12
  23. data/examples/hidden_shapes/hidden_shapes.rb +9 -0
  24. data/examples/hidden_shapes/hidden_shapes.tlf +1 -0
  25. data/examples/list_events/list_events.rb +59 -0
  26. data/examples/list_events/list_events_0_7_7.tlf +1 -0
  27. data/examples/list_events/list_events_0_8.tlf +1 -0
  28. data/{test/case → examples}/list_manual_generation/list_manual_generation.rb +4 -4
  29. data/examples/list_manual_generation/list_manual_generation.tlf +1 -0
  30. data/{test/case → examples}/list_page_number/list_page_number.rb +3 -3
  31. data/examples/list_page_number/list_page_number.tlf +1 -0
  32. data/examples/page_number/page_number.rb +33 -0
  33. data/examples/page_number/page_number.tlf +1 -0
  34. data/examples/password_setting/password_setting.rb +10 -0
  35. data/examples/password_setting/password_setting.tlf +1 -0
  36. data/examples/report_callbacks/report_callbacks.rb +31 -0
  37. data/examples/report_callbacks/report_callbacks.tlf +1 -0
  38. data/{test/case → examples}/single_line_tblock/single_line_tblock.rb +2 -2
  39. data/examples/single_line_tblock/single_line_tblock.tlf +1 -0
  40. data/examples/tblock_overflow/tblock_overflow.rb +20 -0
  41. data/examples/tblock_overflow/tblock_overflow.tlf +1 -0
  42. data/examples/tblock_styles/font_size.tlf +1 -0
  43. data/examples/tblock_styles/tblock_styles.rb +43 -0
  44. data/examples/tblock_styles/tblock_styles.tlf +1 -0
  45. data/examples/text_align/text_align.rb +8 -0
  46. data/examples/text_align/text_align.tlf +1 -0
  47. data/examples/typeB_page_size/B4_ISO.tlf +1 -0
  48. data/examples/typeB_page_size/B4_JIS.tlf +1 -0
  49. data/{test/case → examples}/typeB_page_size/typeB_page_size.rb +3 -3
  50. data/examples/word_wrap/word_wrap.rb +26 -0
  51. data/examples/word_wrap/word_wrap.tlf +1 -0
  52. data/{resources/fonts → fonts}/IPA_Font_License_Agreement_v1.0.txt +0 -0
  53. data/{resources/fonts → fonts}/ipag.ttf +0 -0
  54. data/{resources/fonts → fonts}/ipagp.ttf +0 -0
  55. data/{resources/fonts → fonts}/ipam.ttf +0 -0
  56. data/{resources/fonts → fonts}/ipamp.ttf +0 -0
  57. data/lib/thinreports.rb +14 -2
  58. data/lib/thinreports/config.rb +30 -10
  59. data/lib/thinreports/core/errors.rb +23 -20
  60. data/lib/thinreports/core/events.rb +18 -19
  61. data/lib/thinreports/core/format/base.rb +20 -20
  62. data/lib/thinreports/core/format/builder.rb +14 -22
  63. data/lib/thinreports/core/shape.rb +9 -13
  64. data/lib/thinreports/core/shape/base.rb +4 -5
  65. data/lib/thinreports/core/shape/base/interface.rb +15 -15
  66. data/lib/thinreports/core/shape/base/internal.rb +15 -20
  67. data/lib/thinreports/core/shape/basic.rb +1 -1
  68. data/lib/thinreports/core/shape/basic/block_format.rb +3 -4
  69. data/lib/thinreports/core/shape/basic/block_interface.rb +9 -4
  70. data/lib/thinreports/core/shape/basic/block_internal.rb +9 -10
  71. data/lib/thinreports/core/shape/basic/format.rb +11 -10
  72. data/lib/thinreports/core/shape/basic/interface.rb +3 -3
  73. data/lib/thinreports/core/shape/basic/internal.rb +4 -5
  74. data/lib/thinreports/core/shape/image_block.rb +1 -1
  75. data/lib/thinreports/core/shape/image_block/format.rb +5 -6
  76. data/lib/thinreports/core/shape/image_block/interface.rb +9 -7
  77. data/lib/thinreports/core/shape/image_block/internal.rb +5 -6
  78. data/lib/thinreports/core/shape/list.rb +1 -1
  79. data/lib/thinreports/core/shape/list/configuration.rb +30 -15
  80. data/lib/thinreports/core/shape/list/events.rb +11 -11
  81. data/lib/thinreports/core/shape/list/format.rb +27 -28
  82. data/lib/thinreports/core/shape/list/manager.rb +128 -95
  83. data/lib/thinreports/core/shape/list/page.rb +54 -50
  84. data/lib/thinreports/core/shape/list/page_state.rb +15 -16
  85. data/lib/thinreports/core/shape/list/section_format.rb +14 -15
  86. data/lib/thinreports/core/shape/list/section_interface.rb +15 -16
  87. data/lib/thinreports/core/shape/list/section_internal.rb +7 -8
  88. data/lib/thinreports/core/shape/list/store.rb +10 -11
  89. data/lib/thinreports/core/shape/manager.rb +1 -1
  90. data/lib/thinreports/core/shape/manager/format.rb +10 -11
  91. data/lib/thinreports/core/shape/manager/internal.rb +21 -20
  92. data/lib/thinreports/core/shape/manager/target.rb +63 -34
  93. data/lib/thinreports/core/shape/page_number.rb +1 -1
  94. data/lib/thinreports/core/shape/page_number/format.rb +3 -3
  95. data/lib/thinreports/core/shape/page_number/interface.rb +2 -2
  96. data/lib/thinreports/core/shape/page_number/internal.rb +3 -3
  97. data/lib/thinreports/core/shape/style.rb +1 -1
  98. data/lib/thinreports/core/shape/style/base.rb +29 -29
  99. data/lib/thinreports/core/shape/style/basic.rb +1 -1
  100. data/lib/thinreports/core/shape/style/graphic.rb +10 -25
  101. data/lib/thinreports/core/shape/style/text.rb +36 -30
  102. data/lib/thinreports/core/shape/text.rb +1 -1
  103. data/lib/thinreports/core/shape/text/format.rb +8 -9
  104. data/lib/thinreports/core/shape/text/interface.rb +2 -2
  105. data/lib/thinreports/core/shape/text/internal.rb +6 -7
  106. data/lib/thinreports/core/shape/text_block.rb +1 -1
  107. data/lib/thinreports/core/shape/text_block/format.rb +17 -18
  108. data/lib/thinreports/core/shape/text_block/formatter.rb +7 -8
  109. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +13 -12
  110. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +8 -9
  111. data/lib/thinreports/core/shape/text_block/formatter/number.rb +11 -12
  112. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +9 -32
  113. data/lib/thinreports/core/shape/text_block/interface.rb +2 -2
  114. data/lib/thinreports/core/shape/text_block/internal.rb +19 -20
  115. data/lib/thinreports/core/utils.rb +33 -32
  116. data/lib/thinreports/generator.rb +6 -8
  117. data/lib/thinreports/generator/base.rb +15 -24
  118. data/lib/thinreports/generator/configuration.rb +10 -9
  119. data/lib/thinreports/generator/pdf.rb +27 -30
  120. data/lib/thinreports/generator/pdf/configuration.rb +11 -6
  121. data/lib/thinreports/generator/pdf/document.rb +28 -28
  122. data/lib/thinreports/generator/pdf/document/draw_shape.rb +30 -31
  123. data/lib/thinreports/generator/pdf/document/font.rb +53 -44
  124. data/lib/thinreports/generator/pdf/document/graphics.rb +8 -9
  125. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +25 -25
  126. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +25 -25
  127. data/lib/thinreports/generator/pdf/document/graphics/image.rb +15 -15
  128. data/lib/thinreports/generator/pdf/document/graphics/text.rb +40 -41
  129. data/lib/thinreports/generator/pdf/document/page.rb +20 -21
  130. data/lib/thinreports/generator/pdf/document/parse_color.rb +9 -10
  131. data/lib/thinreports/generator/pdf/document/parse_svg.rb +14 -15
  132. data/lib/thinreports/generator/pdf/drawer/base.rb +13 -14
  133. data/lib/thinreports/generator/pdf/drawer/list.rb +13 -14
  134. data/lib/thinreports/generator/pdf/drawer/list_section.rb +13 -14
  135. data/lib/thinreports/generator/pdf/drawer/page.rb +16 -17
  136. data/lib/thinreports/generator/pdf/prawn_ext.rb +17 -33
  137. data/lib/thinreports/layout.rb +2 -2
  138. data/lib/thinreports/layout/base.rb +22 -36
  139. data/lib/thinreports/layout/configuration.rb +11 -9
  140. data/lib/thinreports/layout/format.rb +26 -27
  141. data/lib/thinreports/layout/version.rb +8 -9
  142. data/lib/thinreports/report.rb +10 -14
  143. data/lib/thinreports/report/base.rb +104 -126
  144. data/lib/thinreports/report/events.rb +5 -5
  145. data/lib/thinreports/report/internal.rb +41 -33
  146. data/lib/thinreports/{core → report}/page.rb +38 -30
  147. data/lib/thinreports/version.rb +2 -3
  148. data/test/data/font.ttf +0 -0
  149. data/test/data/layout_block.tlf +1 -0
  150. data/test/data/layout_list.tlf +1 -0
  151. data/test/data/layout_list_noheader.tlf +1 -0
  152. data/test/data/layout_text1.tlf +1 -0
  153. data/test/data/layout_text2.tlf +1 -0
  154. data/test/test_helper.rb +74 -0
  155. data/test/{unit/tmp → tmp}/.gitkeep +0 -0
  156. data/test/unit/core/format/test_base.rb +14 -14
  157. data/test/unit/core/format/test_builder.rb +19 -23
  158. data/test/unit/core/shape/base/test_internal.rb +34 -37
  159. data/test/unit/core/shape/basic/test_basic_format.rb +4 -4
  160. data/test/unit/core/shape/basic/test_basic_interface.rb +15 -13
  161. data/test/unit/core/shape/basic/test_basic_internal.rb +19 -16
  162. data/test/unit/core/shape/basic/test_format.rb +4 -4
  163. data/test/unit/core/shape/basic/test_interface.rb +36 -46
  164. data/test/unit/core/shape/basic/test_internal.rb +23 -20
  165. data/test/unit/core/shape/image_block/test_format.rb +5 -5
  166. data/test/unit/core/shape/image_block/test_interface.rb +17 -16
  167. data/test/unit/core/shape/image_block/test_internal.rb +19 -16
  168. data/test/unit/core/shape/list/test_configuration.rb +45 -33
  169. data/test/unit/core/shape/list/test_events.rb +7 -7
  170. data/test/unit/core/shape/list/test_format.rb +16 -18
  171. data/test/unit/core/shape/list/test_manager.rb +5 -5
  172. data/test/unit/core/shape/list/test_page.rb +80 -22
  173. data/test/unit/core/shape/list/test_page_state.rb +12 -12
  174. data/test/unit/core/shape/list/test_section_format.rb +16 -17
  175. data/test/unit/core/shape/list/test_section_interface.rb +30 -22
  176. data/test/unit/core/shape/list/test_section_internal.rb +21 -19
  177. data/test/unit/core/shape/list/test_store.rb +7 -7
  178. data/test/unit/core/shape/manager/test_format.rb +11 -15
  179. data/test/unit/core/shape/manager/test_internal.rb +9 -9
  180. data/test/unit/core/shape/manager/test_target.rb +85 -57
  181. data/test/unit/core/shape/page_number/test_format.rb +4 -4
  182. data/test/unit/core/shape/page_number/test_interface.rb +11 -8
  183. data/test/unit/core/shape/page_number/test_internal.rb +5 -5
  184. data/test/unit/core/shape/styles/test_base.rb +9 -9
  185. data/test/unit/core/shape/styles/test_basic.rb +5 -5
  186. data/test/unit/core/shape/styles/test_graphic.rb +19 -33
  187. data/test/unit/core/shape/styles/test_text.rb +18 -7
  188. data/test/unit/core/shape/text/test_format.rb +6 -6
  189. data/test/unit/core/shape/text/test_internal.rb +11 -12
  190. data/test/unit/core/shape/text_block/formatter/test_basic.rb +16 -16
  191. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +4 -4
  192. data/test/unit/core/shape/text_block/formatter/test_number.rb +34 -34
  193. data/test/unit/core/shape/text_block/formatter/test_padding.rb +44 -44
  194. data/test/unit/core/shape/text_block/test_format.rb +8 -8
  195. data/test/unit/core/shape/text_block/test_formatter.rb +17 -17
  196. data/test/unit/core/shape/text_block/test_interface.rb +37 -20
  197. data/test/unit/core/shape/text_block/test_internal.rb +38 -38
  198. data/test/unit/core/test_events.rb +5 -5
  199. data/test/unit/core/test_shape.rb +6 -6
  200. data/test/unit/core/test_utils.rb +68 -0
  201. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +4 -4
  202. data/test/unit/generator/pdf/document/graphics/test_text.rb +60 -53
  203. data/test/unit/generator/pdf/document/test_draw_shape.rb +9 -7
  204. data/test/unit/generator/pdf/document/test_font.rb +79 -58
  205. data/test/unit/generator/pdf/document/test_graphics.rb +18 -19
  206. data/test/unit/generator/pdf/document/test_page.rb +44 -45
  207. data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
  208. data/test/unit/generator/pdf/test_configuration.rb +16 -9
  209. data/test/unit/generator/pdf/test_document.rb +8 -16
  210. data/test/unit/generator/test_base.rb +31 -42
  211. data/test/unit/generator/test_configuration.rb +6 -6
  212. data/test/unit/generator/test_pdf.rb +17 -14
  213. data/test/unit/layout/test_base.rb +34 -79
  214. data/test/unit/layout/test_configuration.rb +12 -37
  215. data/test/unit/layout/test_format.rb +36 -39
  216. data/test/unit/layout/test_version.rb +4 -4
  217. data/test/unit/report/test_base.rb +134 -213
  218. data/test/unit/report/test_events.rb +4 -4
  219. data/test/unit/report/test_internal.rb +84 -86
  220. data/test/unit/test_config.rb +31 -12
  221. data/test/unit/test_layout.rb +7 -7
  222. data/test/unit/test_report.rb +12 -24
  223. data/thinreports.gemspec +18 -22
  224. metadata +101 -200
  225. data/LICENSE +0 -1
  226. data/README.rdoc +0 -166
  227. data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
  228. data/lib/thinreports/core.rb +0 -20
  229. data/lib/thinreports/core/ext.rb +0 -5
  230. data/lib/thinreports/core/ext/array.rb +0 -19
  231. data/lib/thinreports/core/ext/hash.rb +0 -19
  232. data/lib/thinreports/core/ext/object.rb +0 -25
  233. data/lib/thinreports/core/format.rb +0 -14
  234. data/lib/thinreports/core/ordered_hash.rb +0 -39
  235. data/lib/thinreports/generator/pdf/drawer.rb +0 -16
  236. data/tasks/doc.rake +0 -12
  237. data/tasks/test.rake +0 -56
  238. data/test/benchmark/basic_estimate.tlf +0 -1
  239. data/test/benchmark/bench_basic_estimate.rb +0 -95
  240. data/test/case/character_spacing/character_spacing.rb +0 -8
  241. data/test/case/character_spacing/character_spacing.tlf +0 -1
  242. data/test/case/dynamic_image/dynamic_image.rb +0 -41
  243. data/test/case/dynamic_image/dynamic_image.tlf +0 -1
  244. data/test/case/dynamic_style/dynamic_style.rb +0 -154
  245. data/test/case/dynamic_style/dynamic_style.tlf +0 -1
  246. data/test/case/dynamic_style/dynamic_style_in_list.tlf +0 -1
  247. data/test/case/eudc/eudc.rb +0 -20
  248. data/test/case/eudc/eudc.tlf +0 -1
  249. data/test/case/hidden_shapes/hidden_shapes.rb +0 -9
  250. data/test/case/hidden_shapes/hidden_shapes.tlf +0 -1
  251. data/test/case/list_events/list_events.rb +0 -32
  252. data/test/case/list_events/list_events.tlf +0 -1
  253. data/test/case/list_manual_generation/list_manual_generation.tlf +0 -1
  254. data/test/case/list_page_number/list_page_number.tlf +0 -1
  255. data/test/case/page_number/page_number.rb +0 -33
  256. data/test/case/page_number/page_number.tlf +0 -1
  257. data/test/case/password_setting/password_setting.rb +0 -10
  258. data/test/case/password_setting/password_setting.tlf +0 -1
  259. data/test/case/single_line_tblock/single_line_tblock.tlf +0 -1
  260. data/test/case/tblock_overflow/tblock_overflow.rb +0 -20
  261. data/test/case/tblock_overflow/tblock_overflow.tlf +0 -1
  262. data/test/case/tblock_styles/tblock_styles.rb +0 -27
  263. data/test/case/tblock_styles/tblock_styles.tlf +0 -1
  264. data/test/case/text_align/text_align.rb +0 -8
  265. data/test/case/text_align/text_align.tlf +0 -1
  266. data/test/case/typeB_page_size/B4_ISO.tlf +0 -1
  267. data/test/case/typeB_page_size/B4_JIS.tlf +0 -1
  268. data/test/case/word_wrap/word_wrap.rb +0 -26
  269. data/test/case/word_wrap/word_wrap.tlf +0 -1
  270. data/test/unit/core/ext/array_spec.rb +0 -29
  271. data/test/unit/core/ext/hash_spec.rb +0 -29
  272. data/test/unit/core/ext/object_spec.rb +0 -30
  273. data/test/unit/core/ordered_hash_spec.rb +0 -51
  274. data/test/unit/core/shape/base/test_interface.rb +0 -52
  275. data/test/unit/core/utils_spec.rb +0 -56
  276. data/test/unit/data/basic_layout1.tlf +0 -1
  277. data/test/unit/data/basic_layout2.tlf +0 -1
  278. data/test/unit/data/basic_list_layout.tlf +0 -1
  279. data/test/unit/data/basic_list_noheader_layout.tlf +0 -1
  280. data/test/unit/helper.rb +0 -87
@@ -1,12 +1,12 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'test/unit/helper'
3
+ require 'test_helper'
4
4
 
5
- class ThinReports::Core::TestEvents < MiniTest::Unit::TestCase
6
- include ThinReports::TestHelpers
5
+ class Thinreports::Core::TestEvents < Minitest::Test
6
+ include Thinreports::TestHelper
7
7
 
8
8
  # Alias
9
- Events = ThinReports::Core::Events
9
+ Events = Thinreports::Core::Events
10
10
 
11
11
  def setup
12
12
  @events = Events.new(:load, :change, :blur)
@@ -33,7 +33,7 @@ class ThinReports::Core::TestEvents < MiniTest::Unit::TestCase
33
33
  end
34
34
 
35
35
  def test_listen_raise_error_when_unknown_event_type_is_set
36
- assert_raises ThinReports::Errors::UnknownEventType do
36
+ assert_raises Thinreports::Errors::UnknownEventType do
37
37
  @events.listen(:unknown) {|e| e.type }
38
38
  end
39
39
  end
@@ -1,12 +1,12 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'test/unit/helper'
3
+ require 'test_helper'
4
4
 
5
- class ThinReports::Core::TestShape < MiniTest::Unit::TestCase
6
- include ThinReports::TestHelpers
5
+ class Thinreports::Core::TestShape < Minitest::Test
6
+ include Thinreports::TestHelper
7
7
 
8
8
  # Alias
9
- ShapeModule = ThinReports::Core::Shape
9
+ ShapeModule = Thinreports::Core::Shape
10
10
 
11
11
  def test_find_by_type_should_return_PageNumber
12
12
  assert_same ShapeModule.find_by_type('s-pageno'), ShapeModule::PageNumber
@@ -45,7 +45,7 @@ class ThinReports::Core::TestShape < MiniTest::Unit::TestCase
45
45
  end
46
46
 
47
47
  def test_find_by_type_should_raise
48
- assert_raises ThinReports::Errors::UnknownShapeType do
48
+ assert_raises Thinreports::Errors::UnknownShapeType do
49
49
  ShapeModule.find_by_type('unknown')
50
50
  end
51
51
  end
@@ -57,7 +57,7 @@ class ThinReports::Core::TestShape < MiniTest::Unit::TestCase
57
57
 
58
58
  def test_Configuration_should_raise
59
59
  # When shape don't have a Configuration
60
- assert_raises ThinReports::Errors::NoConfigurationFound do
60
+ assert_raises Thinreports::Errors::NoConfigurationFound do
61
61
  ShapeModule::Configuration('s-line')
62
62
  end
63
63
  end
@@ -0,0 +1,68 @@
1
+ # coding: utf-8
2
+
3
+ require 'test_helper'
4
+
5
+ class Thinreports::Core::TestShape < Minitest::Test
6
+ include Thinreports::TestHelper
7
+ include Thinreports::Utils
8
+
9
+ def test_call_block_in
10
+ expected = '123'
11
+ assert_same expected, call_block_in(expected)
12
+
13
+ assert_equal '321', call_block_in('123', &proc { reverse! })
14
+ assert_equal [1, 2, 3], call_block_in([2, 1, 3], &proc { |a| a.sort! })
15
+ end
16
+
17
+ def test_deep_copy_in_unsupported_object
18
+ [123, nil, Struct.new(:foo).new].each do |unsupported_value|
19
+ assert_raises ArgumentError do
20
+ deep_copy(unsupported_value)
21
+ end
22
+ end
23
+ end
24
+
25
+ def test_deep_copy_in_Array
26
+ src = ['string', Time.now]
27
+ dup = deep_copy(src)
28
+
29
+ refute_same dup, src
30
+
31
+ src.each_with_index do |e, i|
32
+ assert_equal dup[i], e
33
+ refute_same dup[i], e
34
+ end
35
+ end
36
+
37
+ def test_deep_copy_in_Hash
38
+ src = { a: 'string', b: Time.now }
39
+ dup = deep_copy(src)
40
+
41
+ refute_same dup, src
42
+
43
+ src.each do |k, v|
44
+ assert_equal dup[k], v
45
+ refute_same dup[k], v
46
+ end
47
+ end
48
+
49
+ def test_blank_value_in_String
50
+ ["", ''].each do |val|
51
+ assert_equal true, blank_value?(val)
52
+ end
53
+
54
+ [' ', ' ', 'abc', 'あいう'].each do |val|
55
+ assert_equal false, blank_value?(val)
56
+ end
57
+ end
58
+
59
+ def test_blank_value_in_NilClass
60
+ assert_equal true, blank_value?(nil)
61
+ end
62
+
63
+ def test_blank_value_in_other_classes
64
+ [0, 1, -1, 9.99, true, false, Time.now].each do |val|
65
+ assert_equal false, blank_value?(val)
66
+ end
67
+ end
68
+ end
@@ -1,12 +1,12 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'test/unit/helper'
3
+ require 'test_helper'
4
4
 
5
- class ThinReports::Generator::PDF::Graphics::TestAttributes < MiniTest::Unit::TestCase
6
- include ThinReports::TestHelpers
5
+ class Thinreports::Generator::PDF::Graphics::TestAttributes < Minitest::Test
6
+ include Thinreports::TestHelper
7
7
 
8
8
  def setup
9
- @pdf = ThinReports::Generator::PDF::Document.new
9
+ @pdf = Thinreports::Generator::PDF::Document.new
10
10
  end
11
11
 
12
12
  def test_common_graphic_attrs_should_return_converted_Hash_as_attributes
@@ -1,164 +1,171 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'test/unit/helper'
3
+ require 'test_helper'
4
+
5
+ class Thinreports::Generator::PDF::Graphics::TestText < Minitest::Test
6
+ include Thinreports::TestHelper
4
7
 
5
- class ThinReports::Generator::PDF::Graphics::TestText < MiniTest::Unit::TestCase
6
- include ThinReports::TestHelpers
7
-
8
8
  def setup
9
- @pdf = ThinReports::Generator::PDF::Document.new
9
+ @pdf = Thinreports::Generator::PDF::Document.new
10
10
  @pdf.internal.start_new_page
11
11
  end
12
-
12
+
13
13
  def exec_with_font_styles(attrs = nil, font = nil, &block)
14
- attrs ||= {:styles => [:bold]}
15
- font ||= {:name => 'IPAMincho', :size => 18, :color => 'ff0000'}
16
-
14
+ attrs ||= {styles: [:bold]}
15
+ font ||= {name: 'IPAMincho', size: 18, color: 'ff0000'}
16
+
17
17
  @pdf.send(:with_font_styles, attrs, font, &block)
18
18
  end
19
-
19
+
20
20
  def exec_with_text_styles(attrs = {}, &block)
21
- default_attrs = {:font => 'Helvetica',
22
- :color => 'ff0000',
23
- :size => 18}
21
+ default_attrs = {font: 'Helvetica',
22
+ color: 'ff0000',
23
+ size: 18}
24
24
  @pdf.send(:with_text_styles, default_attrs.merge(attrs), &block)
25
25
  end
26
-
26
+
27
27
  def test_with_text_styles_should_not_operate_when_color_is_none
28
- exec_with_text_styles(:color => 'none') do |attrs, styles|
28
+ exec_with_text_styles(color: 'none') do |attrs, styles|
29
29
  flunk
30
30
  end
31
31
  end
32
-
32
+
33
33
  def test_with_text_styles_should_set_leading_via_line_height_attribute
34
- exec_with_text_styles(:line_height => 30) do |attrs, styles|
34
+ exec_with_text_styles(line_height: 30) do |attrs, styles|
35
35
  expected = @pdf.send(:text_line_leading,
36
36
  @pdf.send(:s2f, 30),
37
- :name => 'Helvetica', :size => 18)
37
+ name: 'Helvetica', size: 18)
38
38
  assert_equal attrs[:leading], expected
39
39
  end
40
40
  end
41
-
41
+
42
42
  def test_with_text_styles_should_not_set_leading_when_line_height_is_not_specified
43
43
  exec_with_text_styles do |attrs, styles|
44
44
  refute_includes attrs.keys, :leading
45
45
  end
46
46
  end
47
-
47
+
48
48
  def test_with_text_styles_should_set_character_spacing_via_letter_spacing_attribute
49
- exec_with_text_styles(:letter_spacing => 5) do |attrs, styles|
49
+ exec_with_text_styles(letter_spacing: 5) do |attrs, styles|
50
50
  assert_equal attrs[:character_spacing], @pdf.send(:s2f, 5)
51
51
  end
52
52
  end
53
-
53
+
54
54
  def test_with_text_styles_should_not_set_character_spacing_when_letter_spacing_is_not_specified
55
55
  exec_with_text_styles do |attrs, styles|
56
56
  refute_includes attrs.keys, :character_spacing
57
57
  end
58
58
  end
59
-
59
+
60
60
  def test_with_text_styles_should_parse_color
61
- exec_with_text_styles(:color => '#ff0000') do |attrs, styles|
61
+ exec_with_text_styles(color: '#ff0000') do |attrs, styles|
62
62
  assert_equal @pdf.internal.fill_color, 'ff0000'
63
63
  end
64
64
  end
65
-
65
+
66
66
  def test_with_font_styles_should_set_fill_color_using_color_of_font
67
67
  exec_with_font_styles do |attrs, styles|
68
68
  assert_equal @pdf.internal.fill_color, 'ff0000'
69
69
  end
70
70
  end
71
-
71
+
72
72
  def test_with_font_styles_should_perform_manual_style_when_bold_style_cannot_be_applied
73
73
  exec_with_font_styles do |attrs, styles|
74
74
  assert_empty styles
75
75
  end
76
76
  end
77
-
77
+
78
78
  def test_with_font_styles_should_perform_manual_style_when_italic_style_cannot_be_applied
79
79
  exec_with_font_styles do |attrs, styles|
80
80
  assert_empty styles
81
81
  end
82
82
  end
83
-
83
+
84
84
  def test_with_font_styles_should_set_stroke_color_using_color_of_font_when_bold_style_cannot_be_applied
85
85
  exec_with_font_styles do |attrs, styles|
86
86
  assert_equal @pdf.internal.stroke_color, 'ff0000'
87
87
  end
88
88
  end
89
-
89
+
90
90
  def test_with_font_styles_should_set_line_width_calculated_from_font_size_when_bold_style_cannot_be_applied
91
91
  exec_with_font_styles do |attrs, styles|
92
92
  assert_equal @pdf.internal.line_width, 18 * 0.025
93
93
  end
94
94
  end
95
-
95
+
96
96
  def test_with_font_styles_should_set_mode_to_fill_stroke_when_bold_style_cannot_be_applied
97
97
  exec_with_font_styles do |attrs, styles|
98
98
  assert_equal attrs[:mode], :fill_stroke
99
99
  end
100
100
  end
101
-
101
+
102
102
  def test_with_font_styles_should_not_perform_a_manual_style_when_bold_style_can_be_applied
103
- exec_with_font_styles(nil, :name => 'Helvetica', :size => 12, :color => '0000ff') do |attrs, styles|
103
+ exec_with_font_styles(nil, name: 'Helvetica', size: 12, color: '0000ff') do |attrs, styles|
104
104
  assert_includes styles, :bold
105
105
  end
106
106
  end
107
-
107
+
108
108
  def test_with_font_styles_should_not_perform_a_manual_style_when_italic_style_can_be_applied
109
- exec_with_font_styles({:styles => [:italic]}, :name => 'Helvetica', :size => 12, :color => 'ff0000') do |attrs, styles|
109
+ exec_with_font_styles({styles: [:italic]}, name: 'Helvetica', size: 12, color: 'ff0000') do |attrs, styles|
110
110
  assert_includes styles, :italic
111
111
  end
112
112
  end
113
-
113
+
114
114
  def test_text_line_leading_should_return_a_specified_leading_value_minus_the_font_height
115
- font = {:name => 'IPAMincho', :size => 36}
116
- font_height = @pdf.internal.font(font[:name], :size => font[:size]).height
117
-
115
+ font = {name: 'IPAMincho', size: 36}
116
+ font_height = @pdf.internal.font(font[:name], size: font[:size]).height
117
+
118
118
  assert_equal @pdf.send(:text_line_leading, 100, font), 100 - font_height
119
119
  end
120
-
120
+
121
121
  def test_text_without_line_wrap_should_replace_the_spaces_NBSP
122
122
  assert_equal @pdf.send(:text_without_line_wrap, ' ' * 2), Prawn::Text::NBSP * 2
123
123
  end
124
-
124
+
125
125
  def test_text_box_should_not_raise_PrawnCannotFitError
126
- @pdf.text_box('foo', 0, 0, 1, 1, :font => 'IPAMincho',
127
- :size => 100,
128
- :color => '000000')
126
+ @pdf.text_box('foo', 0, 0, 1, 1, font: 'IPAMincho',
127
+ size: 100,
128
+ color: '000000')
129
129
  rescue Prawn::Errors::CannotFit
130
130
  flunk('Raise Prawn::Errors::CannotFit.')
131
131
  end
132
-
132
+
133
133
  def test_text_box_attrs_should_return_a_Hash_containing_a_at_and_width_options
134
134
  attrs = @pdf.send(:text_box_attrs, 0, 0, 50, 100)
135
-
135
+
136
136
  assert_equal attrs.values_at(:at, :width),
137
137
  [@pdf.send(:pos, 0, 0), @pdf.send(:s2f, 50)]
138
138
  end
139
-
139
+
140
140
  def test_text_box_attrs_should_return_a_Hash_which_doesnt_contain_the_single_line_option_when_single_is_true_but_overflow_is_expand
141
- attrs = @pdf.send(:text_box_attrs, 0, 0, 100, 100, :single => true, :overflow => :expand)
141
+ attrs = @pdf.send(:text_box_attrs, 0, 0, 100, 100, single: true, overflow: :expand)
142
142
  refute attrs.key?(:single_line)
143
143
  end
144
-
144
+
145
145
  def test_text_box_attrs_should_return_a_Hash_containing_a_single_line_option_when_single_is_true_and_overflow_isnot_expand
146
- attrs = @pdf.send(:text_box_attrs, 0, 0, 100, 100, :single => true, :overflow => :truncate)
146
+ attrs = @pdf.send(:text_box_attrs, 0, 0, 100, 100, single: true, overflow: :truncate)
147
147
  assert_equal attrs[:single_line], true
148
148
  end
149
-
149
+
150
150
  def test_text_box_attrs_should_return_a_Hash_which_does_not_contain_a_height_option_when_single_is_true
151
- attrs = @pdf.send(:text_box_attrs, 0, 0, 100, 100, :single => true)
151
+ attrs = @pdf.send(:text_box_attrs, 0, 0, 100, 100, single: true)
152
152
  refute attrs.key?(:height)
153
153
  end
154
-
154
+
155
155
  def test_text_box_attrs_should_return_a_Hash_which_does_not_contain_a_single_line_option_when_single_is_not_specified
156
156
  attrs = @pdf.send(:text_box_attrs, 0, 0, 100, 100)
157
157
  refute attrs.key?(:single_line)
158
158
  end
159
-
159
+
160
160
  def test_text_box_attrs_should_return_a_Hash_containing_a_height_optin_when_single_is_not_specified
161
161
  attrs = @pdf.send(:text_box_attrs, 0, 0, 100, 200)
162
162
  assert_equal attrs[:height], 200
163
163
  end
164
+
165
+ def test_text
166
+ @pdf.expects(:text_box).
167
+ with('contents', 100, 200, 150, 250, { overflow: :shirink_to_fit }).once
168
+
169
+ @pdf.text('contents', 100, 200, 150, 250)
170
+ end
164
171
  end
@@ -1,17 +1,20 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'test/unit/helper'
3
+ require 'test_helper'
4
4
 
5
- class ThinReports::Generator::PDF::TestDrawShape < MiniTest::Unit::TestCase
6
- include ThinReports::TestHelpers
5
+ class Thinreports::Generator::PDF::TestDrawShape < Minitest::Test
6
+ include Thinreports::TestHelper
7
7
 
8
8
  def setup
9
- @pdf = ThinReports::Generator::PDF::Document.new
9
+ @pdf = Thinreports::Generator::PDF::Document.new
10
10
  end
11
11
 
12
12
  def create_tblock_interface(format_config = {})
13
- format = ThinReports::Core::Shape::TextBlock::Format.new(format_config)
14
- ThinReports::Core::Shape::TextBlock::Interface.new(flexmock('parent'), format)
13
+ report = new_report 'layout_text1'
14
+ parent = report.start_new_page
15
+
16
+ format = Thinreports::Core::Shape::TextBlock::Format.new format_config
17
+ Thinreports::Core::Shape::TextBlock::Interface.new parent, format
15
18
  end
16
19
 
17
20
  def test_shape_text_attrs_should_return_attrs_containing_an_overflow_property
@@ -39,4 +42,3 @@ class ThinReports::Generator::PDF::TestDrawShape < MiniTest::Unit::TestCase
39
42
  assert_includes @pdf.send(:shape_text_attrs, tblock.internal).keys, :word_wrap
40
43
  end
41
44
  end
42
-
@@ -1,69 +1,90 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'test/unit/helper'
4
-
5
- class ThinReports::Generator::PDF::TestFont < MiniTest::Unit::TestCase
6
- include ThinReports::TestHelpers
7
-
8
- # Alias
9
- Font = ThinReports::Generator::PDF::Font
10
-
11
- def setup
12
- @doc = ThinReports::Generator::PDF::Document.new
13
- end
14
-
15
- def test_setup_fonts_install_builtin_fonts
16
- Font::BUILTIN_FONTS.each_key do |font|
17
- assert_includes @doc.internal.font_families.keys, font
3
+ require 'test_helper'
4
+
5
+ class Thinreports::Generator::PDF::TestFont < Minitest::Test
6
+ include Thinreports::TestHelper
7
+
8
+ Font = Thinreports::Generator::PDF::Font
9
+
10
+ def teardown
11
+ # Reset font settings
12
+ Thinreports.configure do |c|
13
+ c.fallback_fonts = []
14
+ c.generator.pdf.eudc_fonts = []
18
15
  end
19
16
  end
20
-
21
- def test_setup_fonts_install_fallback_font
22
- assert_includes @doc.internal.font_families.keys, 'DefaultFont'
23
- assert_includes @doc.internal.fallback_fonts, 'DefaultFont'
24
- end
25
-
26
- def test_setup_fonts_install_eudc_fonts
27
- ThinReports.config.generator.pdf.eudc_fonts = ['eudc1.ttf', 'eudc2.ttf']
28
- setup
29
-
30
- assert_includes @doc.internal.font_families.keys, 'EUDC0'
31
- assert_includes @doc.internal.font_families.keys, 'EUDC1'
32
- end
33
-
34
- def test_setup_fonts_install_fallback_fonts_as_eudc
35
- ThinReports.config.generator.pdf.eudc_fonts = 'eudc.ttf'
36
- setup
37
-
38
- assert_includes @doc.internal.fallback_fonts, 'EUDC0'
39
- end
40
-
41
- def test_fallback_font_has_all_styles_as_normal_IPAMincho
42
- ipam = Font::BUILTIN_FONTS['IPAMincho'][:normal]
43
- [:normal, :bold, :italic, :bold_italic].each do |style|
44
- assert_same @doc.internal.font_families['DefaultFont'][style], ipam
17
+
18
+ def test_setup_fonts
19
+ pdf = document.pdf
20
+
21
+ Font::BUILTIN_FONTS.each do |name, font|
22
+ assert_equal font, pdf.font_families[name]
23
+ end
24
+
25
+ Font::PRAWN_BUINTIN_FONT_ARIASES.each do |alias_font, original_font|
26
+ assert_equal pdf.font_families[alias_font],
27
+ pdf.font_families[original_font]
45
28
  end
29
+
30
+ assert_equal Font::DEFAULT_FALLBACK_FONTS, pdf.fallback_fonts[-2..-1]
46
31
  end
47
-
48
- def test_setup_fonts_install_alias_fonts_of_CourierNew_and_TimesNewRoman
49
- assert_same @doc.internal.font_families['Courier New'],
50
- @doc.internal.font_families['Courier']
51
- assert_same @doc.internal.font_families['Times New Roman'],
52
- @doc.internal.font_families['Times-Roman']
32
+
33
+ def test_setup_fonts_with_custom_fallback_fonts
34
+ Thinreports.configure do |c|
35
+ c.fallback_fonts = []
36
+ c.generator.pdf.eudc_fonts = []
37
+ end
38
+ assert_equal Font::DEFAULT_FALLBACK_FONTS,
39
+ document.pdf.fallback_fonts
40
+
41
+ Thinreports.configure do |c|
42
+ c.fallback_fonts = 'IPAGothic'
43
+ c.generator.pdf.eudc_fonts = []
44
+ end
45
+ assert_equal ['IPAGothic'] + Font::DEFAULT_FALLBACK_FONTS,
46
+ document.pdf.fallback_fonts
47
+
48
+ Thinreports.configure do |c|
49
+ c.fallback_fonts = ['IPAMincho']
50
+ c.generator.pdf.eudc_fonts = [data_file('font.ttf')]
51
+ end
52
+ assert_equal ['Custom-fallback-font0', 'IPAMincho'] + Font::DEFAULT_FALLBACK_FONTS,
53
+ document.pdf.fallback_fonts
54
+
55
+ Thinreports.configure do |c|
56
+ c.generator.pdf.eudc_fonts = [data_file('font.ttf')]
57
+ c.fallback_fonts = ['IPAMincho', 'IPAMincho', data_file('font.ttf')]
58
+ end
59
+ assert_equal ['Custom-fallback-font0', 'IPAMincho'] + Font::DEFAULT_FALLBACK_FONTS,
60
+ document.pdf.fallback_fonts
53
61
  end
54
-
55
- def test_default_family
56
- assert_equal @doc.send(:default_family), 'Helvetica'
62
+
63
+ def test_setup_fonts_with_unknown_custom_fallback_fonts
64
+ Thinreports.configure do |c|
65
+ c.fallback_fonts = ['/path/to/unknown.ttf']
66
+ c.generator.pdf.eudc_fonts = []
67
+ end
68
+
69
+ assert_raises Thinreports::Errors::FontFileNotFound do
70
+ create_document
71
+ end
57
72
  end
58
-
59
- def test_default_family_if_missing
60
- assert_equal @doc.send(:default_family_if_missing, 'unknown font'),
61
- @doc.send(:default_family)
62
- assert_equal @doc.send(:default_family_if_missing, 'IPAMincho'), 'IPAMincho'
73
+
74
+ def test_font_helpers
75
+ doc = document
76
+
77
+ assert_equal 'Helvetica', doc.default_family
78
+
79
+ assert_equal 'Helvetica', doc.default_family_if_missing('unknown')
80
+ assert_equal 'IPAMincho', doc.default_family_if_missing('IPAMincho')
81
+
82
+ assert_equal false, doc.font_has_style?('IPAMincho', :bold)
83
+ assert_equal true, doc.font_has_style?('Courier New', :bold)
63
84
  end
64
-
65
- def test_font_has_style?
66
- assert_equal @doc.send(:font_has_style?, 'IPAMincho', :bold), false
67
- assert_equal @doc.send(:font_has_style?, 'Courier New', :bold), true
85
+
86
+ def document
87
+ Thinreports::Generator::PDF::Document.new
68
88
  end
89
+ alias_method :create_document, :document
69
90
  end