thinreports 0.7.6 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -5
  3. data/.travis.yml +8 -4
  4. data/CHANGELOG.md +220 -0
  5. data/Gemfile +2 -9
  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/examples/dynamic_style/dynamic_style.rb +150 -0
  14. data/examples/dynamic_style/dynamic_style.tlf +1 -0
  15. data/examples/dynamic_style/dynamic_style_in_list.tlf +1 -0
  16. data/examples/eudc/eudc.rb +20 -0
  17. data/examples/eudc/eudc.tlf +1 -0
  18. data/examples/helper.rb +50 -0
  19. data/examples/hidden_shapes/hidden_shapes.rb +9 -0
  20. data/examples/hidden_shapes/hidden_shapes.tlf +1 -0
  21. data/examples/list_events/list_events.rb +59 -0
  22. data/examples/list_events/list_events_0_7_7.tlf +1 -0
  23. data/examples/list_events/list_events_0_8.tlf +1 -0
  24. data/examples/list_manual_generation/list_manual_generation.rb +22 -0
  25. data/examples/list_manual_generation/list_manual_generation.tlf +1 -0
  26. data/examples/list_page_number/list_page_number.rb +17 -0
  27. data/examples/list_page_number/list_page_number.tlf +1 -0
  28. data/examples/page_number/page_number.rb +33 -0
  29. data/examples/page_number/page_number.tlf +1 -0
  30. data/examples/password_setting/password_setting.rb +10 -0
  31. data/examples/password_setting/password_setting.tlf +1 -0
  32. data/examples/report_callbacks/report_callbacks.rb +31 -0
  33. data/examples/report_callbacks/report_callbacks.tlf +1 -0
  34. data/examples/single_line_tblock/single_line_tblock.rb +13 -0
  35. data/examples/single_line_tblock/single_line_tblock.tlf +1 -0
  36. data/examples/tblock_overflow/tblock_overflow.rb +20 -0
  37. data/examples/tblock_overflow/tblock_overflow.tlf +1 -0
  38. data/examples/tblock_styles/font_size.tlf +1 -0
  39. data/examples/tblock_styles/tblock_styles.rb +43 -0
  40. data/examples/tblock_styles/tblock_styles.tlf +1 -0
  41. data/examples/text_align/text_align.rb +8 -0
  42. data/examples/text_align/text_align.tlf +1 -0
  43. data/examples/typeB_page_size/B4_ISO.tlf +1 -0
  44. data/examples/typeB_page_size/B4_JIS.tlf +1 -0
  45. data/examples/typeB_page_size/typeB_page_size.rb +17 -0
  46. data/examples/word_wrap/word_wrap.rb +26 -0
  47. data/examples/word_wrap/word_wrap.tlf +1 -0
  48. data/lib/thinreports/config.rb +30 -10
  49. data/lib/thinreports/core/errors.rb +23 -20
  50. data/lib/thinreports/core/events.rb +18 -19
  51. data/lib/thinreports/core/format/base.rb +20 -25
  52. data/lib/thinreports/core/format/builder.rb +19 -27
  53. data/lib/thinreports/core/shape/base/interface.rb +15 -15
  54. data/lib/thinreports/core/shape/base/internal.rb +15 -20
  55. data/lib/thinreports/core/shape/base.rb +4 -5
  56. data/lib/thinreports/core/shape/basic/block_format.rb +3 -4
  57. data/lib/thinreports/core/shape/basic/block_interface.rb +9 -4
  58. data/lib/thinreports/core/shape/basic/block_internal.rb +9 -10
  59. data/lib/thinreports/core/shape/basic/format.rb +11 -10
  60. data/lib/thinreports/core/shape/basic/interface.rb +3 -3
  61. data/lib/thinreports/core/shape/basic/internal.rb +9 -6
  62. data/lib/thinreports/core/shape/basic.rb +1 -1
  63. data/lib/thinreports/core/shape/image_block/format.rb +5 -6
  64. data/lib/thinreports/core/shape/image_block/interface.rb +9 -7
  65. data/lib/thinreports/core/shape/image_block/internal.rb +5 -6
  66. data/lib/thinreports/core/shape/image_block.rb +1 -1
  67. data/lib/thinreports/core/shape/list/configuration.rb +37 -16
  68. data/lib/thinreports/core/shape/list/events.rb +11 -11
  69. data/lib/thinreports/core/shape/list/format.rb +27 -28
  70. data/lib/thinreports/core/shape/list/manager.rb +135 -95
  71. data/lib/thinreports/core/shape/list/page.rb +57 -51
  72. data/lib/thinreports/core/shape/list/page_state.rb +19 -17
  73. data/lib/thinreports/core/shape/list/section_format.rb +14 -15
  74. data/lib/thinreports/core/shape/list/section_interface.rb +15 -16
  75. data/lib/thinreports/core/shape/list/section_internal.rb +7 -8
  76. data/lib/thinreports/core/shape/list/store.rb +10 -11
  77. data/lib/thinreports/core/shape/list.rb +1 -1
  78. data/lib/thinreports/core/shape/manager/format.rb +10 -11
  79. data/lib/thinreports/core/shape/manager/internal.rb +22 -21
  80. data/lib/thinreports/core/shape/manager/target.rb +63 -34
  81. data/lib/thinreports/core/shape/manager.rb +1 -1
  82. data/lib/thinreports/core/shape/page_number/format.rb +25 -0
  83. data/lib/thinreports/core/shape/page_number/interface.rb +27 -0
  84. data/lib/thinreports/core/shape/page_number/internal.rb +57 -0
  85. data/lib/thinreports/core/shape/page_number.rb +15 -0
  86. data/lib/thinreports/core/shape/style/base.rb +29 -29
  87. data/lib/thinreports/core/shape/style/basic.rb +1 -1
  88. data/lib/thinreports/core/shape/style/graphic.rb +10 -25
  89. data/lib/thinreports/core/shape/style/text.rb +41 -31
  90. data/lib/thinreports/core/shape/style.rb +1 -1
  91. data/lib/thinreports/core/shape/text/format.rb +8 -9
  92. data/lib/thinreports/core/shape/text/interface.rb +2 -2
  93. data/lib/thinreports/core/shape/text/internal.rb +6 -7
  94. data/lib/thinreports/core/shape/text.rb +1 -1
  95. data/lib/thinreports/core/shape/text_block/format.rb +17 -17
  96. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +13 -12
  97. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +8 -9
  98. data/lib/thinreports/core/shape/text_block/formatter/number.rb +11 -12
  99. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +9 -32
  100. data/lib/thinreports/core/shape/text_block/formatter.rb +7 -8
  101. data/lib/thinreports/core/shape/text_block/interface.rb +2 -2
  102. data/lib/thinreports/core/shape/text_block/internal.rb +19 -20
  103. data/lib/thinreports/core/shape/text_block.rb +1 -1
  104. data/lib/thinreports/core/shape.rb +11 -13
  105. data/lib/thinreports/core/utils.rb +33 -32
  106. data/lib/thinreports/generator/base.rb +15 -24
  107. data/lib/thinreports/generator/configuration.rb +10 -9
  108. data/lib/thinreports/generator/pdf/configuration.rb +11 -6
  109. data/lib/thinreports/generator/pdf/document/draw_shape.rb +41 -32
  110. data/lib/thinreports/generator/pdf/document/font.rb +53 -44
  111. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +34 -25
  112. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +25 -25
  113. data/lib/thinreports/generator/pdf/document/graphics/image.rb +15 -15
  114. data/lib/thinreports/generator/pdf/document/graphics/text.rb +43 -41
  115. data/lib/thinreports/generator/pdf/document/graphics.rb +8 -9
  116. data/lib/thinreports/generator/pdf/document/page.rb +37 -23
  117. data/lib/thinreports/generator/pdf/document/parse_color.rb +9 -10
  118. data/lib/thinreports/generator/pdf/document/parse_svg.rb +14 -15
  119. data/lib/thinreports/generator/pdf/document.rb +28 -28
  120. data/lib/thinreports/generator/pdf/drawer/base.rb +16 -22
  121. data/lib/thinreports/generator/pdf/drawer/list.rb +39 -21
  122. data/lib/thinreports/generator/pdf/drawer/list_section.rb +17 -18
  123. data/lib/thinreports/generator/pdf/drawer/page.rb +37 -26
  124. data/lib/thinreports/generator/pdf/prawn_ext.rb +18 -17
  125. data/lib/thinreports/generator/pdf.rb +28 -31
  126. data/lib/thinreports/generator.rb +6 -8
  127. data/lib/thinreports/layout/base.rb +24 -36
  128. data/lib/thinreports/layout/configuration.rb +11 -9
  129. data/lib/thinreports/layout/format.rb +26 -31
  130. data/lib/thinreports/layout/version.rb +8 -9
  131. data/lib/thinreports/layout.rb +2 -2
  132. data/lib/thinreports/report/base.rb +117 -109
  133. data/lib/thinreports/report/events.rb +5 -5
  134. data/lib/thinreports/report/internal.rb +48 -38
  135. data/lib/thinreports/{core → report}/page.rb +42 -32
  136. data/lib/thinreports/report.rb +10 -14
  137. data/lib/thinreports/version.rb +2 -3
  138. data/lib/thinreports.rb +14 -2
  139. data/test/data/font.ttf +0 -0
  140. data/test/data/layout_block.tlf +1 -0
  141. data/test/data/layout_list.tlf +1 -0
  142. data/test/data/layout_list_noheader.tlf +1 -0
  143. data/test/data/layout_text1.tlf +1 -0
  144. data/test/data/layout_text2.tlf +1 -0
  145. data/test/test_helper.rb +74 -0
  146. data/test/tmp/.gitkeep +0 -0
  147. data/test/unit/core/format/test_base.rb +14 -14
  148. data/test/unit/core/format/test_builder.rb +20 -25
  149. data/test/unit/core/shape/base/test_internal.rb +34 -37
  150. data/test/unit/core/shape/basic/test_basic_format.rb +4 -4
  151. data/test/unit/core/shape/basic/test_basic_interface.rb +15 -13
  152. data/test/unit/core/shape/basic/test_basic_internal.rb +19 -16
  153. data/test/unit/core/shape/basic/test_format.rb +4 -4
  154. data/test/unit/core/shape/basic/test_interface.rb +36 -46
  155. data/test/unit/core/shape/basic/test_internal.rb +29 -18
  156. data/test/unit/core/shape/image_block/test_format.rb +5 -5
  157. data/test/unit/core/shape/image_block/test_interface.rb +17 -16
  158. data/test/unit/core/shape/image_block/test_internal.rb +19 -16
  159. data/test/unit/core/shape/list/test_configuration.rb +50 -33
  160. data/test/unit/core/shape/list/test_events.rb +7 -7
  161. data/test/unit/core/shape/list/test_format.rb +16 -18
  162. data/test/unit/core/shape/list/test_manager.rb +15 -5
  163. data/test/unit/core/shape/list/test_page.rb +80 -22
  164. data/test/unit/core/shape/list/test_page_state.rb +13 -13
  165. data/test/unit/core/shape/list/test_section_format.rb +16 -17
  166. data/test/unit/core/shape/list/test_section_interface.rb +30 -22
  167. data/test/unit/core/shape/list/test_section_internal.rb +21 -19
  168. data/test/unit/core/shape/list/test_store.rb +7 -7
  169. data/test/unit/core/shape/manager/test_format.rb +11 -15
  170. data/test/unit/core/shape/manager/test_internal.rb +9 -9
  171. data/test/unit/core/shape/manager/test_target.rb +85 -57
  172. data/test/unit/core/shape/page_number/test_format.rb +73 -0
  173. data/test/unit/core/shape/page_number/test_interface.rb +33 -0
  174. data/test/unit/core/shape/page_number/test_internal.rb +81 -0
  175. data/test/unit/core/shape/styles/test_base.rb +9 -9
  176. data/test/unit/core/shape/styles/test_basic.rb +5 -5
  177. data/test/unit/core/shape/styles/test_graphic.rb +19 -33
  178. data/test/unit/core/shape/styles/test_text.rb +29 -7
  179. data/test/unit/core/shape/text/test_format.rb +6 -6
  180. data/test/unit/core/shape/text/test_internal.rb +11 -12
  181. data/test/unit/core/shape/text_block/formatter/test_basic.rb +16 -16
  182. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +22 -20
  183. data/test/unit/core/shape/text_block/formatter/test_number.rb +34 -34
  184. data/test/unit/core/shape/text_block/formatter/test_padding.rb +44 -44
  185. data/test/unit/core/shape/text_block/test_format.rb +13 -8
  186. data/test/unit/core/shape/text_block/test_formatter.rb +17 -17
  187. data/test/unit/core/shape/text_block/test_interface.rb +37 -20
  188. data/test/unit/core/shape/text_block/test_internal.rb +38 -38
  189. data/test/unit/core/test_events.rb +10 -8
  190. data/test/unit/core/test_shape.rb +11 -7
  191. data/test/unit/core/test_utils.rb +68 -0
  192. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +10 -4
  193. data/test/unit/generator/pdf/document/graphics/test_text.rb +60 -53
  194. data/test/unit/generator/pdf/document/test_draw_shape.rb +14 -6
  195. data/test/unit/generator/pdf/document/test_font.rb +79 -58
  196. data/test/unit/generator/pdf/document/test_graphics.rb +18 -19
  197. data/test/unit/generator/pdf/document/test_page.rb +68 -43
  198. data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
  199. data/test/unit/generator/pdf/test_configuration.rb +16 -9
  200. data/test/unit/generator/pdf/test_document.rb +8 -16
  201. data/test/unit/generator/test_base.rb +31 -42
  202. data/test/unit/generator/test_configuration.rb +6 -6
  203. data/test/unit/generator/test_pdf.rb +15 -21
  204. data/test/unit/layout/test_base.rb +34 -79
  205. data/test/unit/layout/test_configuration.rb +12 -37
  206. data/test/unit/layout/test_format.rb +36 -39
  207. data/test/unit/layout/test_version.rb +4 -4
  208. data/test/unit/report/test_base.rb +160 -192
  209. data/test/unit/report/test_events.rb +4 -4
  210. data/test/unit/report/test_internal.rb +102 -82
  211. data/test/unit/test_config.rb +31 -12
  212. data/test/unit/test_layout.rb +7 -7
  213. data/test/unit/test_report.rb +12 -24
  214. data/thinreports.gemspec +23 -26
  215. metadata +118 -181
  216. data/.yardopts +0 -1
  217. data/LICENSE +0 -1
  218. data/README.rdoc +0 -167
  219. data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
  220. data/lib/thinreports/core/ext/array.rb +0 -19
  221. data/lib/thinreports/core/ext/hash.rb +0 -19
  222. data/lib/thinreports/core/ext/object.rb +0 -25
  223. data/lib/thinreports/core/ext.rb +0 -5
  224. data/lib/thinreports/core/format.rb +0 -14
  225. data/lib/thinreports/core/ordered_hash.rb +0 -39
  226. data/lib/thinreports/core.rb +0 -20
  227. data/lib/thinreports/generator/pdf/drawer.rb +0 -16
  228. data/tasks/doc.rake +0 -13
  229. data/tasks/test.rake +0 -56
  230. data/test/benchmark/basic_estimate.tlf +0 -1
  231. data/test/benchmark/bench_basic_estimate.rb +0 -95
  232. data/test/case/character_spacing/character_spacing.rb +0 -7
  233. data/test/case/character_spacing/character_spacing.tlf +0 -1
  234. data/test/case/dynamic_image/dynamic_image.rb +0 -41
  235. data/test/case/dynamic_image/dynamic_image.tlf +0 -1
  236. data/test/case/dynamic_style/dynamic_style.rb +0 -154
  237. data/test/case/dynamic_style/dynamic_style.tlf +0 -1
  238. data/test/case/dynamic_style/dynamic_style_in_list.tlf +0 -1
  239. data/test/case/eudc/eudc.rb +0 -20
  240. data/test/case/eudc/eudc.tlf +0 -1
  241. data/test/case/helper.rb +0 -29
  242. data/test/case/hidden_shapes/hidden_shapes.rb +0 -13
  243. data/test/case/hidden_shapes/hidden_shapes.tlf +0 -1
  244. data/test/case/list_events/list_events.rb +0 -32
  245. data/test/case/list_events/list_events.tlf +0 -1
  246. data/test/case/list_header_inheriting/list_header_inheriting.rb +0 -17
  247. data/test/case/list_header_inheriting/list_header_inheriting.tlf +0 -1
  248. data/test/case/list_manual_generation/list_manual_generation.rb +0 -22
  249. data/test/case/list_manual_generation/list_manual_generation.tlf +0 -1
  250. data/test/case/single_line_tblock/single_line_tblock.rb +0 -15
  251. data/test/case/single_line_tblock/single_line_tblock.tlf +0 -1
  252. data/test/case/tblock_overflow/tblock_overflow.rb +0 -20
  253. data/test/case/tblock_overflow/tblock_overflow.tlf +0 -1
  254. data/test/case/tblock_styles/tblock_styles.rb +0 -27
  255. data/test/case/tblock_styles/tblock_styles.tlf +0 -1
  256. data/test/case/text_align/text_align.rb +0 -9
  257. data/test/case/text_align/text_align.tlf +0 -1
  258. data/test/unit/core/ext/array_spec.rb +0 -29
  259. data/test/unit/core/ext/hash_spec.rb +0 -29
  260. data/test/unit/core/ext/object_spec.rb +0 -30
  261. data/test/unit/core/ordered_hash_spec.rb +0 -51
  262. data/test/unit/core/shape/base/test_interface.rb +0 -52
  263. data/test/unit/core/utils_spec.rb +0 -56
  264. data/test/unit/data/basic_layout1.tlf +0 -1
  265. data/test/unit/data/basic_layout2.tlf +0 -1
  266. data/test/unit/data/basic_list_layout.tlf +0 -1
  267. data/test/unit/data/basic_list_noheader_layout.tlf +0 -1
  268. data/test/unit/helper.rb +0 -65
  269. /data/{test/case → examples}/dynamic_image/img200x100.png +0 -0
  270. /data/{test/case → examples}/dynamic_image/img50x50.png +0 -0
  271. /data/{test/case → examples}/dynamic_style/image.png +0 -0
  272. /data/{test/case → examples}/eudc/eudc.ttf +0 -0
  273. /data/{resources/fonts → fonts}/IPA_Font_License_Agreement_v1.0.txt +0 -0
  274. /data/{resources/fonts → fonts}/ipag.ttf +0 -0
  275. /data/{resources/fonts → fonts}/ipagp.ttf +0 -0
  276. /data/{resources/fonts → fonts}/ipam.ttf +0 -0
  277. /data/{resources/fonts → fonts}/ipamp.ttf +0 -0
@@ -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
@@ -1,43 +1,42 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'test/unit/helper'
3
+ require 'test_helper'
4
+
5
+ class Thinreports::Generator::PDF::TestGraphics < Minitest::Test
6
+ include Thinreports::TestHelper
4
7
 
5
- class ThinReports::Generator::PDF::TestGraphics < MiniTest::Unit::TestCase
6
- include ThinReports::TestHelpers
7
-
8
8
  class TestGraphics
9
9
  attr_accessor :pdf
10
- include ThinReports::Generator::PDF::Graphics
10
+ include Thinreports::Generator::PDF::Graphics
11
11
  end
12
-
12
+
13
13
  def setup
14
- @g = TestGraphics.new
15
- @g.pdf = flexmock('pdf')
14
+ @g = TestGraphics.new
15
+ @g.pdf = mock('pdf')
16
16
  end
17
-
17
+
18
18
  def test_setup_custom_graphic_states
19
- @g.pdf.
20
- should_receive(:line_width).
19
+ @g.pdf.expects(:line_width).
21
20
  with(TestGraphics::BASE_LINE_WIDTH).once
22
-
21
+
23
22
  @g.send(:setup_custom_graphic_states)
24
23
  end
25
-
24
+
26
25
  def test_line_width
27
26
  @g.pdf.
28
- should_receive(:line_width).
27
+ expects(:line_width).
29
28
  with(10 * TestGraphics::BASE_LINE_WIDTH).once
30
-
29
+
31
30
  @g.send(:line_width, 10)
32
31
  end
33
-
32
+
34
33
  def test_save_graphics_state
35
- @g.pdf.should_receive(:save_graphics_state).once
34
+ @g.pdf.expects(:save_graphics_state).once
36
35
  @g.send(:save_graphics_state)
37
36
  end
38
-
37
+
39
38
  def test_restore_graphics_state
40
- @g.pdf.should_receive(:restore_graphics_state).once
39
+ @g.pdf.expects(:restore_graphics_state).once
41
40
  @g.send(:restore_graphics_state)
42
41
  end
43
42
  end
@@ -1,95 +1,120 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'test/unit/helper'
3
+ require 'test_helper'
4
+
5
+ class Thinreports::Generator::PDF::Document::TestPage < Minitest::Test
6
+ include Thinreports::TestHelper
4
7
 
5
- class ThinReports::Generator::PDF::Document::TestPage < MiniTest::Unit::TestCase
6
- include ThinReports::TestHelpers
7
-
8
8
  def create_pdf
9
- @pdf = ThinReports::Generator::PDF::Document.new
9
+ @pdf = Thinreports::Generator::PDF::Document.new
10
+ end
11
+
12
+ def test_page_geometry
13
+ page_geometry = ::PDF::Core::PageGeometry::SIZES
14
+ assert_equal page_geometry['B4_JIS'], [728.5, 1031.8]
15
+ assert_equal page_geometry['B5_JIS'], [515.9, 728.5]
16
+ end
17
+
18
+ def test_B4_paper_size_should_be_converted_to_B4_JIS
19
+ create_pdf
20
+
21
+ format = new_layout_format('layout_text1.tlf')
22
+ format.stubs(page_paper_type: 'B4')
23
+
24
+ @pdf.start_new_page(format)
25
+ assert_equal @pdf.internal.page.size, 'B4_JIS'
10
26
  end
11
-
27
+
28
+ def test_B4_ISO_paper_size_should_be_converted_to_B4
29
+ create_pdf
30
+
31
+ format = new_layout_format('layout_text1.tlf')
32
+ format.stubs(page_paper_type: 'B4_ISO')
33
+
34
+ @pdf.start_new_page(format)
35
+ assert_equal @pdf.internal.page.size, 'B4'
36
+ end
37
+
12
38
  def test_change_page_format_should_return_true_at_first_time
13
39
  create_pdf
14
- format = create_basic_layout_format('basic_layout1.tlf')
15
-
40
+ format = new_layout_format('layout_text1.tlf')
41
+
16
42
  assert_equal @pdf.send(:change_page_format?, format), true
17
43
  end
18
-
44
+
19
45
  def test_change_page_format_should_return_false_when_given_the_same_format
20
46
  create_pdf
21
- format = create_basic_layout_format('basic_layout1.tlf')
22
-
47
+ format = new_layout_format('layout_text1.tlf')
48
+
23
49
  @pdf.instance_variable_set(:@current_page_format, format)
24
50
  assert_equal @pdf.send(:change_page_format?, format), false
25
51
  end
26
-
52
+
27
53
  def test_change_page_format_should_return_true_when_given_the_other_format
28
54
  create_pdf
29
- format1 = create_basic_layout_format('basic_layout1.tlf')
30
- format2 = create_basic_layout_format('basic_layout2.tlf')
31
-
55
+ format1 = new_layout_format('layout_text1.tlf')
56
+ format2 = new_layout_format('layout_text2.tlf')
57
+
32
58
  @pdf.instance_variable_set(:@current_page_format, format1)
33
59
  assert_equal @pdf.send(:change_page_format?, format2), true
34
60
  end
35
-
61
+
36
62
  def test_new_basic_page_options
37
- format = create_basic_layout_format('basic_layout1.tlf')
63
+ format = new_layout_format('layout_text1.tlf')
38
64
  options = create_pdf.send(:new_basic_page_options, format)
39
-
65
+
40
66
  assert_equal options[:layout], format.page_orientation.to_sym
41
67
  assert_equal options[:size], format.page_paper_type
42
68
  end
43
-
69
+
44
70
  def test_new_basic_page_options_when_the_layout_has_customize_size
45
- format = flexmock('format').
46
- should_receive(:user_paper_type? => true,
47
- :page_width => 100,
48
- :page_height => 100,
49
- :page_orientation => 'portrait').mock
50
-
71
+ format = stub user_paper_type?: true,
72
+ page_width: 100,
73
+ page_height: 100,
74
+ page_orientation: 'portrait'
75
+
51
76
  options = create_pdf.send(:new_basic_page_options, format)
52
77
  assert_equal options[:size], [100, 100]
53
78
  end
54
-
79
+
55
80
  def test_start_new_page_should_create_stamp
56
81
  create_pdf
57
- format = create_basic_layout_format('basic_layout1.tlf')
82
+ format = new_layout_format('layout_text1.tlf')
58
83
  @pdf.start_new_page(format)
59
-
84
+
60
85
  assert_includes @pdf.send(:format_stamp_registry), format.identifier
61
86
  end
62
-
87
+
63
88
  def test_start_new_page_should_not_create_stamp
64
89
  create_pdf
65
- format = create_basic_layout_format('basic_layout1.tlf')
90
+ format = new_layout_format('layout_text1.tlf')
66
91
  @pdf.start_new_page(format)
67
92
  @pdf.start_new_page(format)
68
-
93
+
69
94
  assert_equal @pdf.send(:format_stamp_registry).size, 1
70
95
  end
71
-
96
+
72
97
  def test_start_new_page_should_stamp_constantly
73
98
  create_pdf
74
- format = create_basic_layout_format('basic_layout1.tlf')
75
- flexmock(@pdf).should_receive(:stamp).with(format.identifier.to_s).times(2)
76
-
99
+ format = new_layout_format('layout_text1.tlf')
100
+ @pdf.expects(:stamp).with(format.identifier.to_s).times(2)
101
+
77
102
  @pdf.start_new_page(format)
78
103
  @pdf.start_new_page(format)
79
104
  end
80
-
105
+
81
106
  def test_add_blank_page_should_create_an_A4_size_page_in_first_page
82
107
  create_pdf
83
- flexmock(@pdf.internal).should_receive(:start_new_page).with(:size => 'A4').once
84
-
108
+ @pdf.internal.expects(:start_new_page).with(size: 'A4').once
109
+
85
110
  @pdf.add_blank_page
86
111
  end
87
-
112
+
88
113
  def test_add_blank_page_should_call_with_no_arguments_since_second_page
89
114
  create_pdf
90
- @pdf.start_new_page(create_basic_layout_format('basic_layout1.tlf'))
91
- flexmock(@pdf.internal).should_receive(:start_new_page).with(Hash.new).once
92
-
115
+ @pdf.start_new_page(new_layout_format('layout_text1.tlf'))
116
+ @pdf.internal.expects(:start_new_page).with({}).once
117
+
93
118
  @pdf.add_blank_page
94
119
  end
95
- end
120
+ 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::TestParseColor < MiniTest::Unit::TestCase
6
- include ThinReports::TestHelpers
5
+ class Thinreports::Generator::PDF::TestParseColor < Minitest::Test
6
+ include Thinreports::TestHelper
7
7
 
8
8
  class TestColorParser
9
- include ThinReports::Generator::PDF::ParseColor
9
+ include Thinreports::Generator::PDF::ParseColor
10
10
  end
11
11
 
12
12
  def setup
@@ -23,7 +23,7 @@ class ThinReports::Generator::PDF::TestParseColor < MiniTest::Unit::TestCase
23
23
  end
24
24
 
25
25
  def test_parse_color_with_colorname_raise_when_unknown_name_given
26
- assert_raises ThinReports::Errors::UnsupportedColorName do
26
+ assert_raises Thinreports::Errors::UnsupportedColorName do
27
27
  @parser.parse_color('whitesmoke')
28
28
  end
29
29
  end
@@ -1,15 +1,22 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'test/unit/helper'
3
+ require 'test_helper'
4
+
5
+ class Thinreports::Generator::PDF::TestConfiguration < Minitest::Test
6
+ include Thinreports::TestHelper
4
7
 
5
- class ThinReports::Generator::PDF::TestConfiguration < MiniTest::Unit::TestCase
6
- include ThinReports::TestHelpers
7
-
8
8
  def setup
9
- @config = ThinReports::Generator::PDF::Configuration.new
9
+ @config = Thinreports::Generator::PDF::Configuration.new
10
+ end
11
+
12
+ def test_eudc_fonts_is_deprecated
13
+ out, err = capture_io do
14
+ @config.eudc_fonts = []
15
+ end
16
+ assert_includes err, '[DEPRECATION]'
10
17
  end
11
-
12
- def test_eudc_fonts_can_only_set_font_of_TTF
18
+
19
+ def test_eudc_fonts_should_be_able_to_set_only_TTF
13
20
  assert_raises ArgumentError do
14
21
  @config.eudc_fonts = '/path/to/eudc'
15
22
  end
@@ -17,8 +24,8 @@ class ThinReports::Generator::PDF::TestConfiguration < MiniTest::Unit::TestCase
17
24
  @config.eudc_fonts = %w( /path/to/eudc1.ttf /path/to/eudc2 )
18
25
  end
19
26
  end
20
-
27
+
21
28
  def test_eudc_fonts_should_return_empty_array_by_default
22
29
  assert_equal @config.eudc_fonts, []
23
30
  end
24
- end
31
+ end
@@ -1,28 +1,20 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'test/unit/helper'
3
+ require 'test_helper'
4
+
5
+ class Thinreports::Generator::PDF::TestDocument < Minitest::Test
6
+ include Thinreports::TestHelper
4
7
 
5
- class ThinReports::Generator::PDF::TestDocument < MiniTest::Unit::TestCase
6
- include ThinReports::TestHelpers
7
-
8
8
  # Alias
9
- Document = ThinReports::Generator::PDF::Document
10
-
9
+ Document = Thinreports::Generator::PDF::Document
10
+
11
11
  def test_new_without_page_creation
12
12
  pdf = Document.new
13
13
  assert_equal pdf.internal.page_count, 0
14
14
  end
15
-
15
+
16
16
  def test_new_with_zero_margin_canvas
17
17
  pdf = Document.new
18
18
  assert_equal pdf.internal.page.margins.values, [0, 0, 0, 0]
19
19
  end
20
-
21
- def test_new_with_security_settings
22
- flexmock(Prawn::Document).new_instances.
23
- should_receive(:encrypt_document).once.
24
- with(:user_password => 'foo')
25
-
26
- Document.new(:security => {:user_password => 'foo'})
27
- end
28
- end
20
+ end
@@ -1,51 +1,40 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'test/unit/helper'
4
-
5
- class ThinReports::Generator::TestBase < MiniTest::Unit::TestCase
6
- include ThinReports::TestHelpers
7
-
8
- # Alias
9
- Generator = ThinReports::Generator
10
-
11
- class FooHoge < Generator::Base; end
12
-
13
- def test_subcclasses_are_registered_as_generator_when_inherited
14
- assert_same FooHoge, Generator.registry.delete(:foohoge)
15
- end
16
-
17
- def test_initialize_finalize_given_the_report
18
- report = flexmock('report').
19
- should_receive(:finalize).once.
20
- should_receive(:internal).once.mock
21
-
22
- Generator::Base.new(report)
3
+ require 'test_helper'
4
+
5
+ class Thinreports::Generator::TestBase < Minitest::Test
6
+ include Thinreports::TestHelper
7
+
8
+ Generator = Thinreports::Generator
9
+
10
+ class FooGenerator < Generator::Base; end
11
+
12
+ def test_registring_generator
13
+ assert_same FooGenerator, Generator.registry.delete(:foogenerator)
23
14
  end
24
-
25
- def test_generate_is_abstract_method
26
- assert_raises NotImplementedError do
27
- new_generator.generate
28
- end
15
+
16
+ def test_new
17
+ report = new_report 'layout_text1.tlf'
18
+
19
+ refute report.finalized?
20
+ Generator::Base.new report
21
+ assert report.finalized?
29
22
  end
30
-
31
- def test_generate_file_is_abstract_method
23
+
24
+ def test_generate
25
+ report = new_report 'layout_text1.tlf'
26
+
27
+ generator = Generator::Base.new report
32
28
  assert_raises NotImplementedError do
33
- new_generator.generate_file('output.pdf')
29
+ generator.generate
34
30
  end
35
31
  end
36
-
32
+
37
33
  def test_default_layout
38
- generator = new_generator
39
- flexmock(generator.report).
40
- should_receive(:default_layout).and_return(flexmock('default_layout')).once
41
-
42
- assert_equal generator.default_layout.flexmock_name, 'default_layout'
43
- end
44
-
45
- def new_generator
46
- report = flexmock('report').
47
- should_receive(:finalize).
48
- should_receive(:internal).and_return(flexmock('report_internal')).mock
49
- Generator::Base.new(report)
34
+ report = new_report 'layout_text1.tlf'
35
+
36
+ generator = Generator::Base.new report
37
+ assert_equal data_file('layout_text1.tlf'),
38
+ generator.default_layout.filename
50
39
  end
51
- end
40
+ end
@@ -1,16 +1,16 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'test/unit/helper'
3
+ require 'test_helper'
4
4
 
5
- class ThinReports::Generator::TestConfiguration < MiniTest::Unit::TestCase
6
- include ThinReports::TestHelpers
5
+ class Thinreports::Generator::TestConfiguration < Minitest::Test
6
+ include Thinreports::TestHelper
7
7
 
8
8
  def setup
9
- @config = ThinReports::Generator::Configuration.new
9
+ @config = Thinreports::Generator::Configuration.new
10
10
  end
11
11
 
12
12
  def test_pdf_should_return_configuration_of_pdf
13
- assert_instance_of ThinReports::Generator::PDF::Configuration, @config.pdf
13
+ assert_instance_of Thinreports::Generator::PDF::Configuration, @config.pdf
14
14
  end
15
15
 
16
16
  def test_default_should_return_pdf_by_default
@@ -18,7 +18,7 @@ class ThinReports::Generator::TestConfiguration < MiniTest::Unit::TestCase
18
18
  end
19
19
 
20
20
  def test_default_should_raise_when_value_is_unknown_generator_type
21
- assert_raises ThinReports::Errors::UnknownGeneratorType do
21
+ assert_raises Thinreports::Errors::UnknownGeneratorType do
22
22
  @config.default = :unknown
23
23
  end
24
24
  end
@@ -1,29 +1,23 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'test/unit/helper'
3
+ require 'test_helper'
4
4
 
5
- class ThinReports::Generator::TestPDF < MiniTest::Unit::TestCase
6
- include ThinReports::TestHelpers
7
-
8
- # Alias
9
- PDF = ThinReports::Generator::PDF
10
-
11
- def test_new_should_set_empty_title_when_the_default_layout_is_not_set
12
- report = ThinReports::Report.new
13
- report.start_new_page :layout => data_file('basic_layout1.tlf')
5
+ class Thinreports::Generator::TestPDF < Minitest::Test
6
+ include Thinreports::TestHelper
14
7
 
15
- flexmock(PDF::Document).should_receive(:new).
16
- with(Hash, :Title => nil).once
17
-
18
- PDF.new(report, {})
19
- end
8
+ PDF = Thinreports::Generator::PDF
20
9
 
21
10
  def test_new_should_set_title_as_metadata
22
- report = create_basic_report('basic_layout1.tlf') {|r| r.start_new_page }
23
-
24
- flexmock(PDF::Document).should_receive(:new).
25
- with(Hash, :Title => 'Basic Layout').once
26
-
27
- PDF.new(report, {})
11
+ report = new_report('layout_text1.tlf') {|r| r.start_new_page }
12
+
13
+ actual_pdf_title = nil
14
+ PDF::Document.define_singleton_method(:new) {|options, meta|
15
+ actual_pdf_title = meta[:Title]
16
+ }
17
+ PDF.new report, {}
18
+
19
+ assert_equal 'Basic Layout', actual_pdf_title
20
+ ensure
21
+ PDF::Document.singleton_class.send(:remove_method, :new)
28
22
  end
29
23
  end