thinreports 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +41 -0
  3. data/.travis.yml +4 -6
  4. data/CHANGELOG.md +21 -2
  5. data/Gemfile +2 -4
  6. data/README.md +4 -5
  7. data/Rakefile +7 -8
  8. data/examples/character_spacing/character_spacing.rb +1 -1
  9. data/examples/dynamic_image/dynamic_image.rb +3 -3
  10. data/examples/dynamic_style/dynamic_style.rb +1 -1
  11. data/examples/eudc/eudc.rb +1 -1
  12. data/examples/helper.rb +2 -2
  13. data/examples/hidden_shapes/hidden_shapes.rb +1 -1
  14. data/examples/list_events/list_events.rb +1 -1
  15. data/examples/list_manual_generation/list_manual_generation.rb +1 -1
  16. data/examples/list_page_number/list_page_number.rb +1 -1
  17. data/examples/page_number/page_number.rb +1 -1
  18. data/examples/palleted_png/palleted_png.rb +1 -3
  19. data/examples/password_setting/password_setting.rb +1 -1
  20. data/examples/report_callbacks/report_callbacks.rb +1 -1
  21. data/examples/single_line_tblock/single_line_tblock.rb +1 -1
  22. data/examples/tblock_overflow/tblock_overflow.rb +1 -1
  23. data/examples/tblock_styles/tblock_styles.rb +1 -1
  24. data/examples/text_align/text_align.rb +1 -1
  25. data/examples/typeB_page_size/typeB_page_size.rb +1 -1
  26. data/examples/word_wrap/word_wrap.rb +1 -1
  27. data/lib/thinreports.rb +16 -15
  28. data/lib/thinreports/config.rb +2 -24
  29. data/lib/thinreports/core/errors.rb +6 -17
  30. data/lib/thinreports/core/format/base.rb +62 -61
  31. data/lib/thinreports/core/shape.rb +13 -14
  32. data/lib/thinreports/core/shape/base.rb +3 -12
  33. data/lib/thinreports/core/shape/base/interface.rb +35 -32
  34. data/lib/thinreports/core/shape/base/internal.rb +45 -43
  35. data/lib/thinreports/core/shape/basic.rb +12 -12
  36. data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
  37. data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
  38. data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
  39. data/lib/thinreports/core/shape/basic/format.rb +11 -9
  40. data/lib/thinreports/core/shape/basic/interface.rb +79 -77
  41. data/lib/thinreports/core/shape/basic/internal.rb +17 -14
  42. data/lib/thinreports/core/shape/image_block.rb +9 -9
  43. data/lib/thinreports/core/shape/image_block/format.rb +7 -5
  44. data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
  45. data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
  46. data/lib/thinreports/core/shape/list.rb +13 -13
  47. data/lib/thinreports/core/shape/list/format.rb +83 -77
  48. data/lib/thinreports/core/shape/list/manager.rb +182 -176
  49. data/lib/thinreports/core/shape/list/page.rb +94 -93
  50. data/lib/thinreports/core/shape/list/page_state.rb +42 -40
  51. data/lib/thinreports/core/shape/list/section_format.rb +28 -26
  52. data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
  53. data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
  54. data/lib/thinreports/core/shape/manager.rb +4 -13
  55. data/lib/thinreports/core/shape/manager/format.rb +21 -19
  56. data/lib/thinreports/core/shape/manager/internal.rb +88 -84
  57. data/lib/thinreports/core/shape/manager/target.rb +93 -95
  58. data/lib/thinreports/core/shape/page_number.rb +9 -9
  59. data/lib/thinreports/core/shape/page_number/format.rb +20 -18
  60. data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
  61. data/lib/thinreports/core/shape/page_number/internal.rb +47 -44
  62. data/lib/thinreports/core/shape/style.rb +5 -14
  63. data/lib/thinreports/core/shape/style/base.rb +121 -120
  64. data/lib/thinreports/core/shape/style/basic.rb +12 -10
  65. data/lib/thinreports/core/shape/style/graphic.rb +35 -33
  66. data/lib/thinreports/core/shape/style/text.rb +113 -107
  67. data/lib/thinreports/core/shape/text.rb +9 -9
  68. data/lib/thinreports/core/shape/text/format.rb +10 -9
  69. data/lib/thinreports/core/shape/text/interface.rb +13 -11
  70. data/lib/thinreports/core/shape/text/internal.rb +14 -12
  71. data/lib/thinreports/core/shape/text_block.rb +10 -10
  72. data/lib/thinreports/core/shape/text_block/format.rb +35 -33
  73. data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
  74. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
  75. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
  76. data/lib/thinreports/core/shape/text_block/formatter/number.rb +45 -39
  77. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
  78. data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
  79. data/lib/thinreports/core/shape/text_block/internal.rb +68 -68
  80. data/lib/thinreports/core/utils.rb +4 -3
  81. data/lib/thinreports/generator/pdf.rb +24 -25
  82. data/lib/thinreports/generator/pdf/document.rb +109 -110
  83. data/lib/thinreports/generator/pdf/document/draw_shape.rb +58 -51
  84. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +51 -47
  85. data/lib/thinreports/generator/pdf/document/font.rb +62 -59
  86. data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
  87. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +122 -121
  88. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +113 -114
  89. data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
  90. data/lib/thinreports/generator/pdf/document/graphics/text.rb +152 -137
  91. data/lib/thinreports/generator/pdf/document/page.rb +63 -64
  92. data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
  93. data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
  94. data/lib/thinreports/generator/pdf/drawer/list.rb +48 -45
  95. data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
  96. data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
  97. data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
  98. data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +34 -0
  99. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +29 -0
  100. data/lib/thinreports/layout.rb +5 -7
  101. data/lib/thinreports/layout/base.rb +5 -7
  102. data/lib/thinreports/layout/format.rb +18 -13
  103. data/lib/thinreports/layout/legacy_schema.rb +18 -10
  104. data/lib/thinreports/layout/version.rb +22 -25
  105. data/lib/thinreports/report.rb +4 -6
  106. data/lib/thinreports/report/base.rb +24 -51
  107. data/lib/thinreports/report/internal.rb +9 -11
  108. data/lib/thinreports/report/page.rb +5 -6
  109. data/lib/thinreports/version.rb +2 -2
  110. data/test/schema_helper.rb +4 -3
  111. data/test/test_helper.rb +9 -3
  112. data/test/unit/core/format/test_base.rb +1 -1
  113. data/test/unit/core/shape/base/test_internal.rb +1 -1
  114. data/test/unit/core/shape/basic/test_block_format.rb +1 -1
  115. data/test/unit/core/shape/basic/test_block_interface.rb +1 -1
  116. data/test/unit/core/shape/basic/test_block_internal.rb +1 -1
  117. data/test/unit/core/shape/basic/test_format.rb +1 -1
  118. data/test/unit/core/shape/basic/test_interface.rb +1 -1
  119. data/test/unit/core/shape/basic/test_internal.rb +1 -1
  120. data/test/unit/core/shape/image_block/test_interface.rb +1 -1
  121. data/test/unit/core/shape/image_block/test_internal.rb +1 -1
  122. data/test/unit/core/shape/list/test_format.rb +1 -1
  123. data/test/unit/core/shape/list/test_manager.rb +4 -4
  124. data/test/unit/core/shape/list/test_page.rb +1 -1
  125. data/test/unit/core/shape/list/test_page_state.rb +1 -1
  126. data/test/unit/core/shape/list/test_section_format.rb +1 -1
  127. data/test/unit/core/shape/list/test_section_interface.rb +2 -2
  128. data/test/unit/core/shape/list/test_section_internal.rb +1 -1
  129. data/test/unit/core/shape/manager/test_format.rb +2 -2
  130. data/test/unit/core/shape/manager/test_internal.rb +3 -3
  131. data/test/unit/core/shape/manager/test_target.rb +1 -1
  132. data/test/unit/core/shape/page_number/test_format.rb +1 -1
  133. data/test/unit/core/shape/page_number/test_interface.rb +1 -1
  134. data/test/unit/core/shape/page_number/test_internal.rb +1 -1
  135. data/test/unit/core/shape/styles/test_base.rb +1 -1
  136. data/test/unit/core/shape/styles/test_basic.rb +1 -1
  137. data/test/unit/core/shape/styles/test_graphic.rb +1 -1
  138. data/test/unit/core/shape/styles/test_text.rb +1 -1
  139. data/test/unit/core/shape/text/test_format.rb +1 -1
  140. data/test/unit/core/shape/text/test_internal.rb +1 -1
  141. data/test/unit/core/shape/text_block/formatter/test_basic.rb +1 -1
  142. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +1 -1
  143. data/test/unit/core/shape/text_block/formatter/test_number.rb +1 -1
  144. data/test/unit/core/shape/text_block/formatter/test_padding.rb +2 -2
  145. data/test/unit/core/shape/text_block/test_format.rb +1 -1
  146. data/test/unit/core/shape/text_block/test_formatter.rb +1 -1
  147. data/test/unit/core/shape/text_block/test_interface.rb +1 -1
  148. data/test/unit/core/shape/text_block/test_internal.rb +3 -3
  149. data/test/unit/core/test_shape.rb +1 -1
  150. data/test/unit/core/test_utils.rb +2 -2
  151. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +1 -1
  152. data/test/unit/generator/pdf/document/graphics/test_basic.rb +2 -1
  153. data/test/unit/generator/pdf/document/graphics/test_image.rb +27 -131
  154. data/test/unit/generator/pdf/document/graphics/test_text.rb +1 -1
  155. data/test/unit/generator/pdf/document/test_font.rb +2 -2
  156. data/test/unit/generator/pdf/document/test_graphics.rb +1 -1
  157. data/test/unit/generator/pdf/document/test_page.rb +7 -7
  158. data/test/unit/generator/pdf/document/test_parse_color.rb +1 -1
  159. data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +41 -0
  160. data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +22 -0
  161. data/test/unit/generator/pdf/test_document.rb +8 -6
  162. data/test/unit/generator/test_pdf.rb +12 -10
  163. data/test/unit/layout/test_base.rb +1 -1
  164. data/test/unit/layout/test_format.rb +2 -2
  165. data/test/unit/layout/test_legacy_schema.rb +4 -4
  166. data/test/unit/layout/test_version.rb +11 -80
  167. data/test/unit/report/test_base.rb +45 -59
  168. data/test/unit/report/test_internal.rb +1 -1
  169. data/test/unit/test_config.rb +1 -16
  170. data/test/unit/test_layout.rb +1 -1
  171. data/test/unit/test_report.rb +1 -1
  172. data/thinreports.gemspec +11 -14
  173. metadata +42 -103
  174. data/lib/thinreports/generator.rb +0 -29
  175. data/lib/thinreports/generator/base.rb +0 -40
  176. data/lib/thinreports/generator/configuration.rb +0 -31
  177. data/lib/thinreports/report/events.rb +0 -32
  178. data/test/unit/generator/test_base.rb +0 -40
  179. data/test/unit/generator/test_configuration.rb +0 -21
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -29,7 +29,7 @@ class Thinreports::Core::Shape::List::TestManager < Minitest::Test
29
29
 
30
30
  def test_switch_current_should_replace_own_current_page_property_by_the_given_page
31
31
  report = create_report {|r| r.start_new_page }
32
- list = report.page.list
32
+ list = report.page.list
33
33
  new_page = List::Page.new(report.page, list.internal.format)
34
34
 
35
35
  list.manager.switch_current!(new_page)
@@ -39,7 +39,7 @@ class Thinreports::Core::Shape::List::TestManager < Minitest::Test
39
39
 
40
40
  def test_switch_current_should_replace_own_current_page_state_property_by_internal_property_of_the_given_page
41
41
  report = create_report {|r| r.start_new_page }
42
- list = report.page.list
42
+ list = report.page.list
43
43
  new_page = List::Page.new(report.page, list.internal.format)
44
44
 
45
45
  list.manager.switch_current!(new_page)
@@ -49,7 +49,7 @@ class Thinreports::Core::Shape::List::TestManager < Minitest::Test
49
49
 
50
50
  def test_switch_current_should_return_the_self
51
51
  report = create_report {|r| r.start_new_page }
52
- list = report.page.list
52
+ list = report.page.list
53
53
  new_page = List::Page.new(report.page, list.internal.format)
54
54
 
55
55
  assert_same list.manager.switch_current!(new_page), list.manager
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -62,7 +62,7 @@ class Thinreports::Core::Shape::List::TestSectionInterface < Minitest::Test
62
62
  end
63
63
 
64
64
  def copied_list(list, &block)
65
- tblock = Thinreports::Core::Shape::TextBlock
65
+ tblock = Thinreports::Core::Shape::TextBlock
66
66
  new_parent = @report.start_new_page
67
67
 
68
68
  %w( foo bar hoge ).each do |id|
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -26,7 +26,7 @@ class Thinreports::Core::Shape::Manager::TestFormat < Minitest::Test
26
26
 
27
27
  def test_find_shape_should_return_format_of_shape_when_shape_is_found
28
28
  format = TestFormat.new({}) do |f|
29
- f.shapes[:foo] = Thinreports::Core::Shape::TextBlock::Format.new('id' => 'foo',
29
+ f.shapes[:foo] = Thinreports::Core::Shape::TextBlock::Format.new('id' => 'foo',
30
30
  'type' => 'text-block')
31
31
  end
32
32
  assert_equal format.find_shape(:foo).id, 'foo'
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -9,8 +9,8 @@ class Thinreports::Core::Shape::Manager::TestInternal < Minitest::Test
9
9
  Shape = Thinreports::Core::Shape
10
10
 
11
11
  def create_shape_format(type, id, other_config = {})
12
- Shape::Format(type).new({'id' => id,
13
- 'type' => type,
12
+ Shape::Format(type).new({'id' => id,
13
+ 'type' => type,
14
14
  'display' => true}.merge(other_config))
15
15
  end
16
16
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -34,7 +34,7 @@ class Thinreports::Core::Shape::TextBlock::Formatter::TestPadding < Minitest::Te
34
34
  def test_apply_padding_formats_with_right_direction
35
35
  formatter = init_formatter(format_padding_length: 5,
36
36
  format_padding_char: '0',
37
- :format_padding_rdir? => true)
37
+ :format_padding_rdir? => true)
38
38
 
39
39
  assert_equal formatter.apply(123), '12300'
40
40
  end
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -13,7 +13,7 @@ class Thinreports::Core::Shape::TextBlock::TestInternal < Minitest::Test
13
13
  report.start_new_page do |page|
14
14
  # Add to force TextBlock shape.
15
15
  page.manager.format.shapes[:foo] = TextBlock::Format.new('type' => 'text-block',
16
- 'id' => 'foo')
16
+ 'id' => 'foo')
17
17
  # Set value to TextBlock.
18
18
  page.item(:foo).value('foo value')
19
19
  end
@@ -66,7 +66,7 @@ class Thinreports::Core::Shape::TextBlock::TestInternal < Minitest::Test
66
66
  end
67
67
 
68
68
  def test_real_value_should_return_the_formatted_value_when_tblock_has_any_format
69
- tblock = create_internal('format' => {'type' => 'datetime',
69
+ tblock = create_internal('format' => {'type' => 'datetime',
70
70
  'datetime' => {'format' => '%Y/%m/%d'}})
71
71
  tblock.write_value(value = Time.now)
72
72
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -10,7 +10,7 @@ class Thinreports::Core::TestShape < Minitest::Test
10
10
  expected = '123'
11
11
  assert_same expected, call_block_in(expected)
12
12
 
13
- assert_equal '321', call_block_in('123', &proc { reverse! })
13
+ assert_equal [1, 2, 3], call_block_in([2, 1, 3], &proc { sort! })
14
14
  assert_equal [1, 2, 3], call_block_in([2, 1, 3], &proc { |a| a.sort! })
15
15
  end
16
16
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,5 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class Thinreports::Generator::PDF::Graphics::TestBasic < Minitest::Test
@@ -1,150 +1,46 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
-
5
4
  require 'base64'
6
- require 'digest/md5'
7
5
 
8
6
  class Thinreports::Generator::PDF::Graphics::TestImage < Minitest::Test
9
7
  include Thinreports::TestHelper
10
8
 
11
- class TestImage
12
- include Thinreports::Generator::PDF::Graphics
13
- end
14
-
15
- def test_normalize_image_from_base64_in_disabled
16
- Thinreports.config.convert_palleted_transparency_png = false
17
-
18
- test_image = TestImage.new
19
- base64_image = Base64.encode64(read_data_file('image_normal.png'))
20
-
21
- # Should not be normalized
22
- TestImage::PNGNormalizer.stubs(:load_blob).never
23
- test_image.normalize_image_from_base64('image/png', base64_image)
24
-
25
- image_registry = test_image.temp_image_registry
26
- assert_equal 1, image_registry.count
27
- end
28
-
29
- def test_normalize_image_from_file_in_disabled
30
- Thinreports.config.convert_palleted_transparency_png = false
31
-
32
- original_image_path = data_file('image_pallete_based.png')
33
-
34
- test_image = TestImage.new
35
- returned_image_path = test_image.normalize_image_from_file(original_image_path)
36
-
37
- # Should not be normalized
38
- assert_empty test_image.temp_image_registry
39
- assert_same original_image_path, returned_image_path
9
+ def setup
10
+ format = Thinreports::Layout::Format.build(self.layout_file.path)
11
+ @document = Thinreports::Generator::PDF::Document.new.tap { |doc|
12
+ doc.start_new_page(format)
13
+ }
40
14
  end
41
15
 
42
- def test_normalize_image_from_base64_with_normal_images
43
- Thinreports.config.convert_palleted_transparency_png = true
44
-
45
- [
46
- ['image/png', 'image_normal.png'],
47
- ['image/jpeg', 'image_normal.jpg']
48
- ]
49
- .each do |(image_type, image_file)|
50
- base64_normal_image = Base64.encode64(read_data_file(image_file))
51
-
52
- test_image = TestImage.new
53
-
54
- normalized_image_path = test_image.normalize_image_from_base64(image_type, base64_normal_image)
55
-
56
- image_registry = test_image.temp_image_registry
57
- assert_equal 1, image_registry.count
58
-
59
- image_id = Digest::MD5.hexdigest(base64_normal_image)
60
- assert_includes image_registry.keys, image_id
61
- assert_equal normalized_image_path, image_registry[image_id].path
62
-
63
- assert equal_image(data_file(image_file), normalized_image_path)
64
-
65
- assert_equal normalized_image_path,
66
- test_image.normalize_image_from_base64(image_type, base64_normal_image)
16
+ def test_image
17
+ each_image do |image_filename|
18
+ @document.image(data_file(image_filename), 0, 0, 100, 100)
19
+ @document.image(StringIO.new(read_data_file(image_filename)), 0, 100, 100, 100)
67
20
  end
21
+ assert_equal 6, analyze_pdf_images(@document.render).count
68
22
  end
69
23
 
70
- def test_normalize_image_from_base64_with_palette_transparency_png
71
- Thinreports.config.convert_palleted_transparency_png = true
72
-
73
- base64_palleted_png = Base64.encode64(read_data_file('image_pallete_based.png'))
74
-
75
- test_image = TestImage.new
76
-
77
- normalized_image_path = test_image.normalize_image_from_base64('image/png', base64_palleted_png)
78
-
79
- image_registry = test_image.temp_image_registry
80
- assert_equal 1, image_registry.count
81
-
82
- image_id = Digest::MD5.hexdigest(base64_palleted_png)
83
- assert_includes image_registry.keys, image_id
84
- assert_equal normalized_image_path, image_registry[image_id].path
85
-
86
- refute equal_image(data_file('image_pallete_based.png'), normalized_image_path)
87
-
88
- assert_not_palette_based_transparency_png File.read(normalized_image_path)
89
-
90
- # 2nd time
91
- assert_equal normalized_image_path,
92
- test_image.normalize_image_from_base64('image/png', base64_palleted_png)
93
- assert_equal 1, test_image.temp_image_registry.count
94
- end
95
-
96
- def test_normalize_image_from_file_with_normal_images
97
- Thinreports.config.convert_palleted_transparency_png = true
98
-
99
- [
100
- data_file('image_normal.png'),
101
- data_file('iamge_normal.jpg'),
102
- data_file('image_normal_png_noext'),
103
- data_file('image_normal_jpg_noext')
104
- ]
105
- .each do |original_image_path|
106
- test_image = TestImage.new
107
- image_path = test_image.normalize_image_from_file(original_image_path)
108
-
109
- assert_equal original_image_path, image_path
110
- assert_empty test_image.temp_image_registry
24
+ def test_base64image
25
+ each_image do |image_filename|
26
+ @document.base64image(Base64.encode64(read_data_file(image_filename)), 0, 0, 100, 100)
111
27
  end
28
+ assert_equal 3, analyze_pdf_images(@document.render).count
112
29
  end
113
30
 
114
- def test_normalize_image_from_file_with_palette_transparency_png
115
- Thinreports.config.convert_palleted_transparency_png = true
116
-
117
- original_image_path = data_file('image_pallete_based.png')
118
-
119
- test_image = TestImage.new
120
-
121
- normalized_image_path = test_image.normalize_image_from_file(original_image_path)
122
- image_registry = test_image.temp_image_registry
123
-
124
- assert_equal 1, image_registry.count
125
- assert_includes image_registry.keys, original_image_path
126
-
127
- refute equal_image(original_image_path, normalized_image_path)
128
-
129
- assert_not_palette_based_transparency_png File.read(normalized_image_path)
130
-
131
- # It should never called in 2nd time or subsequent.
132
- TestImage::PNGNormalizer.stubs(:load_file).never
133
- assert_equal normalized_image_path,
134
- test_image.normalize_image_from_file(original_image_path)
135
- end
136
-
137
- def assert_not_palette_based_transparency_png(data)
138
- image_data = ChunkyPNG::Image.from_blob(data)
139
- datastream = ChunkyPNG::Datastream.from_blob(data)
140
-
141
- assert_equal ChunkyPNG::COLOR_INDEXED, image_data.palette.best_color_settings.first
142
- assert_equal nil, datastream.transparency_chunk
31
+ def test_image_box
32
+ each_image do |image_filename|
33
+ @document.image_box(data_file(image_filename), 0, 0, 100, 100)
34
+ @document.image(StringIO.new(read_data_file(image_filename)), 0, 100, 100, 100)
35
+ end
36
+ assert_equal 6, analyze_pdf_images(@document.render).count
143
37
  end
144
38
 
145
- def equal_image(expect_path, actual_path)
146
- expect_image = File.binread(expect_path)
147
- actual_image = File.binread(actual_path)
148
- expect_image == actual_image
39
+ def each_image(&block)
40
+ %w(
41
+ image_normal.png
42
+ image_normal.jpg
43
+ image_pallete_based.png
44
+ ).each { |image_filename| block.call(image_filename) }
149
45
  end
150
46
  end