thinreports 0.10.2 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CONTRIBUTING.md +2 -2
  3. data/.github/dependabot.yml +11 -0
  4. data/.github/workflows/test.yml +50 -0
  5. data/.gitignore +1 -0
  6. data/CHANGELOG.md +43 -0
  7. data/Gemfile +2 -1
  8. data/{MIT-LICENSE → LICENSE.txt} +2 -0
  9. data/README.md +70 -56
  10. data/Rakefile +12 -25
  11. data/gemfiles/prawn-2.2.gemfile +5 -0
  12. data/gemfiles/prawn-2.3.gemfile +5 -0
  13. data/gemfiles/prawn-2.4.gemfile +5 -0
  14. data/lib/thinreports/core/shape/basic/format.rb +5 -0
  15. data/lib/thinreports/core/shape/image_block.rb +1 -1
  16. data/lib/thinreports/core/shape/list.rb +1 -1
  17. data/lib/thinreports/core/shape/page_number.rb +1 -1
  18. data/lib/thinreports/core/shape/stack_view/format.rb +27 -0
  19. data/lib/thinreports/core/shape/stack_view/interface.rb +17 -0
  20. data/lib/thinreports/core/shape/stack_view/internal.rb +22 -0
  21. data/lib/thinreports/core/shape/stack_view/row_format.rb +39 -0
  22. data/lib/thinreports/core/shape/stack_view.rb +17 -0
  23. data/lib/thinreports/core/shape/style/basic.rb +4 -1
  24. data/lib/thinreports/core/shape/text.rb +1 -1
  25. data/lib/thinreports/core/shape/text_block/formatter/number.rb +6 -1
  26. data/lib/thinreports/core/shape/text_block/internal.rb +0 -2
  27. data/lib/thinreports/core/shape/text_block.rb +1 -1
  28. data/lib/thinreports/core/shape.rb +2 -0
  29. data/lib/thinreports/generate.rb +11 -0
  30. data/lib/thinreports/generator/pdf/document/draw_shape.rb +31 -10
  31. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +1 -1
  32. data/lib/thinreports/generator/pdf/document/graphics/image.rb +19 -1
  33. data/lib/thinreports/generator/pdf/document/graphics/text.rb +10 -5
  34. data/lib/thinreports/generator/pdf/document/page.rb +12 -0
  35. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +7 -7
  36. data/lib/thinreports/layout/base.rb +1 -1
  37. data/lib/thinreports/layout/legacy_schema.rb +1 -0
  38. data/lib/thinreports/layout/version.rb +1 -1
  39. data/lib/thinreports/report/internal.rb +2 -0
  40. data/lib/thinreports/report.rb +2 -2
  41. data/lib/thinreports/section_report/build.rb +32 -0
  42. data/lib/thinreports/section_report/builder/item_builder.rb +49 -0
  43. data/lib/thinreports/section_report/builder/report_builder.rb +82 -0
  44. data/lib/thinreports/section_report/builder/report_data.rb +13 -0
  45. data/lib/thinreports/section_report/builder/stack_view_builder.rb +53 -0
  46. data/lib/thinreports/section_report/builder/stack_view_data.rb +11 -0
  47. data/lib/thinreports/section_report/generate.rb +26 -0
  48. data/lib/thinreports/section_report/pdf/render.rb +23 -0
  49. data/lib/thinreports/section_report/pdf/renderer/draw_item.rb +68 -0
  50. data/lib/thinreports/section_report/pdf/renderer/group_renderer.rb +57 -0
  51. data/lib/thinreports/section_report/pdf/renderer/section_height.rb +100 -0
  52. data/lib/thinreports/section_report/pdf/renderer/section_renderer.rb +39 -0
  53. data/lib/thinreports/section_report/pdf/renderer/stack_view_renderer.rb +55 -0
  54. data/lib/thinreports/section_report/pdf/renderer/stack_view_row_renderer.rb +38 -0
  55. data/lib/thinreports/section_report/schema/loader.rb +28 -0
  56. data/lib/thinreports/section_report/schema/parser.rb +52 -0
  57. data/lib/thinreports/section_report/schema/report.rb +30 -0
  58. data/lib/thinreports/section_report/schema/section.rb +47 -0
  59. data/lib/thinreports/version.rb +1 -1
  60. data/lib/thinreports.rb +5 -0
  61. data/thinreports.gemspec +11 -10
  62. metadata +48 -150
  63. data/.travis.yml +0 -16
  64. data/examples/character_spacing/character_spacing.rb +0 -8
  65. data/examples/character_spacing/character_spacing.tlf +0 -293
  66. data/examples/dynamic_image/dynamic_image.rb +0 -31
  67. data/examples/dynamic_image/dynamic_image.tlf +0 -661
  68. data/examples/dynamic_image/img200x100.png +0 -0
  69. data/examples/dynamic_image/img50x50.png +0 -0
  70. data/examples/dynamic_style/dynamic_style.rb +0 -150
  71. data/examples/dynamic_style/dynamic_style.tlf +0 -1835
  72. data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
  73. data/examples/dynamic_style/image.png +0 -0
  74. data/examples/eudc/eudc.rb +0 -20
  75. data/examples/eudc/eudc.tlf +0 -180
  76. data/examples/eudc/eudc.ttf +0 -0
  77. data/examples/helper.rb +0 -50
  78. data/examples/hidden_shapes/hidden_shapes.rb +0 -9
  79. data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
  80. data/examples/list_events/list_events.rb +0 -32
  81. data/examples/list_events/list_events.tlf +0 -361
  82. data/examples/list_manual_generation/list_manual_generation.rb +0 -22
  83. data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
  84. data/examples/list_page_number/list_page_number.rb +0 -17
  85. data/examples/list_page_number/list_page_number.tlf +0 -254
  86. data/examples/page_number/page_number.rb +0 -33
  87. data/examples/page_number/page_number.tlf +0 -215
  88. data/examples/palleted_png/palleted_png.png +0 -0
  89. data/examples/palleted_png/palleted_png.rb +0 -9
  90. data/examples/palleted_png/palleted_png.tlf +0 -47
  91. data/examples/password_setting/password_setting.rb +0 -10
  92. data/examples/password_setting/password_setting.tlf +0 -45
  93. data/examples/report_callbacks/report_callbacks.rb +0 -14
  94. data/examples/report_callbacks/report_callbacks.tlf +0 -147
  95. data/examples/single_line_tblock/single_line_tblock.rb +0 -13
  96. data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
  97. data/examples/tblock_overflow/tblock_overflow.rb +0 -20
  98. data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
  99. data/examples/tblock_styles/font_size.tlf +0 -383
  100. data/examples/tblock_styles/tblock_styles.rb +0 -43
  101. data/examples/tblock_styles/tblock_styles.tlf +0 -889
  102. data/examples/text_align/text_align.rb +0 -8
  103. data/examples/text_align/text_align.tlf +0 -241
  104. data/examples/typeB_page_size/B4_ISO.tlf +0 -45
  105. data/examples/typeB_page_size/B4_JIS.tlf +0 -45
  106. data/examples/typeB_page_size/typeB_page_size.rb +0 -17
  107. data/examples/word_wrap/word_wrap.rb +0 -26
  108. data/examples/word_wrap/word_wrap.tlf +0 -297
  109. data/test/data/font.ttf +0 -0
  110. data/test/data/image_normal.jpg +0 -0
  111. data/test/data/image_normal.png +0 -0
  112. data/test/data/image_normal_jpg_noext +0 -0
  113. data/test/data/image_normal_png_noext +0 -0
  114. data/test/data/image_pallete_based.png +0 -0
  115. data/test/data/legacy_layout/all-items.tlf +0 -1
  116. data/test/schema_helper.rb +0 -122
  117. data/test/test_helper.rb +0 -48
  118. data/test/tmp/.gitkeep +0 -0
  119. data/test/unit/core/format/test_base.rb +0 -152
  120. data/test/unit/core/shape/base/test_internal.rb +0 -87
  121. data/test/unit/core/shape/basic/test_block_format.rb +0 -23
  122. data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
  123. data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
  124. data/test/unit/core/shape/basic/test_format.rb +0 -37
  125. data/test/unit/core/shape/basic/test_interface.rb +0 -108
  126. data/test/unit/core/shape/basic/test_internal.rb +0 -55
  127. data/test/unit/core/shape/image_block/test_interface.rb +0 -24
  128. data/test/unit/core/shape/image_block/test_internal.rb +0 -31
  129. data/test/unit/core/shape/list/test_format.rb +0 -111
  130. data/test/unit/core/shape/list/test_manager.rb +0 -67
  131. data/test/unit/core/shape/list/test_page.rb +0 -156
  132. data/test/unit/core/shape/list/test_page_state.rb +0 -31
  133. data/test/unit/core/shape/list/test_section_format.rb +0 -36
  134. data/test/unit/core/shape/list/test_section_interface.rb +0 -75
  135. data/test/unit/core/shape/list/test_section_internal.rb +0 -50
  136. data/test/unit/core/shape/manager/test_format.rb +0 -38
  137. data/test/unit/core/shape/manager/test_internal.rb +0 -132
  138. data/test/unit/core/shape/manager/test_target.rb +0 -140
  139. data/test/unit/core/shape/page_number/test_format.rb +0 -55
  140. data/test/unit/core/shape/page_number/test_interface.rb +0 -33
  141. data/test/unit/core/shape/page_number/test_internal.rb +0 -81
  142. data/test/unit/core/shape/styles/test_base.rb +0 -191
  143. data/test/unit/core/shape/styles/test_basic.rb +0 -24
  144. data/test/unit/core/shape/styles/test_graphic.rb +0 -50
  145. data/test/unit/core/shape/styles/test_text.rb +0 -97
  146. data/test/unit/core/shape/text/test_format.rb +0 -44
  147. data/test/unit/core/shape/text/test_internal.rb +0 -20
  148. data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
  149. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
  150. data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
  151. data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
  152. data/test/unit/core/shape/text_block/test_format.rb +0 -169
  153. data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
  154. data/test/unit/core/shape/text_block/test_interface.rb +0 -63
  155. data/test/unit/core/shape/text_block/test_internal.rb +0 -128
  156. data/test/unit/core/test_shape.rb +0 -52
  157. data/test/unit/core/test_utils.rb +0 -68
  158. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
  159. data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -46
  160. data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -46
  161. data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
  162. data/test/unit/generator/pdf/document/test_font.rb +0 -110
  163. data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
  164. data/test/unit/generator/pdf/document/test_page.rb +0 -122
  165. data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
  166. data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +0 -41
  167. data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +0 -22
  168. data/test/unit/generator/pdf/test_document.rb +0 -22
  169. data/test/unit/generator/test_pdf.rb +0 -26
  170. data/test/unit/layout/test_base.rb +0 -41
  171. data/test/unit/layout/test_format.rb +0 -100
  172. data/test/unit/layout/test_legacy_schema.rb +0 -574
  173. data/test/unit/layout/test_version.rb +0 -26
  174. data/test/unit/report/test_base.rb +0 -248
  175. data/test/unit/report/test_internal.rb +0 -206
  176. data/test/unit/test_config.rb +0 -36
  177. data/test/unit/test_layout.rb +0 -12
  178. data/test/unit/test_report.rb +0 -18
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'base64'
5
-
6
- class Thinreports::Generator::PDF::Graphics::TestImage < Minitest::Test
7
- include Thinreports::TestHelper
8
-
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
- }
14
- end
15
-
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)
20
- end
21
- assert_equal 6, analyze_pdf_images(@document.render).count
22
- end
23
-
24
- def test_base64image
25
- each_image do |image_filename|
26
- @document.base64image(Base64.encode64(read_data_file(image_filename)), 0, 0, 100, 100)
27
- end
28
- assert_equal 3, analyze_pdf_images(@document.render).count
29
- end
30
-
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
37
- end
38
-
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) }
45
- end
46
- end
@@ -1,171 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PDF::Graphics::TestText < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- def setup
9
- @pdf = Thinreports::Generator::PDF::Document.new
10
- @pdf.internal.start_new_page
11
- end
12
-
13
- def exec_with_font_styles(attrs = nil, font = nil, &block)
14
- attrs ||= {styles: [:bold]}
15
- font ||= {name: 'IPAMincho', size: 18, color: 'ff0000'}
16
-
17
- @pdf.send(:with_font_styles, attrs, font, &block)
18
- end
19
-
20
- def exec_with_text_styles(attrs = {}, &block)
21
- default_attrs = {font: 'Helvetica',
22
- color: 'ff0000',
23
- size: 18}
24
- @pdf.send(:with_text_styles, default_attrs.merge(attrs), &block)
25
- end
26
-
27
- def test_with_text_styles_should_not_operate_when_color_is_none
28
- exec_with_text_styles(color: 'none') do |_attrs, _styles|
29
- flunk
30
- end
31
- end
32
-
33
- def test_with_text_styles_should_set_leading_via_line_height_attribute
34
- exec_with_text_styles(line_height: 30) do |attrs, _styles|
35
- expected = @pdf.send(:text_line_leading,
36
- @pdf.send(:s2f, 30),
37
- name: 'Helvetica', size: 18)
38
- assert_equal attrs[:leading], expected
39
- end
40
- end
41
-
42
- def test_with_text_styles_should_not_set_leading_when_line_height_is_not_specified
43
- exec_with_text_styles do |attrs, _styles|
44
- refute_includes attrs.keys, :leading
45
- end
46
- end
47
-
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|
50
- assert_equal attrs[:character_spacing], @pdf.send(:s2f, 5)
51
- end
52
- end
53
-
54
- def test_with_text_styles_should_not_set_character_spacing_when_letter_spacing_is_not_specified
55
- exec_with_text_styles do |attrs, _styles|
56
- refute_includes attrs.keys, :character_spacing
57
- end
58
- end
59
-
60
- def test_with_text_styles_should_parse_color
61
- exec_with_text_styles(color: '#ff0000') do |_attrs, _styles|
62
- assert_equal @pdf.internal.fill_color, 'ff0000'
63
- end
64
- end
65
-
66
- def test_with_font_styles_should_set_fill_color_using_color_of_font
67
- exec_with_font_styles do |_attrs, _styles|
68
- assert_equal @pdf.internal.fill_color, 'ff0000'
69
- end
70
- end
71
-
72
- def test_with_font_styles_should_perform_manual_style_when_bold_style_cannot_be_applied
73
- exec_with_font_styles do |_attrs, styles|
74
- assert_empty styles
75
- end
76
- end
77
-
78
- def test_with_font_styles_should_perform_manual_style_when_italic_style_cannot_be_applied
79
- exec_with_font_styles do |_attrs, styles|
80
- assert_empty styles
81
- end
82
- end
83
-
84
- def test_with_font_styles_should_set_stroke_color_using_color_of_font_when_bold_style_cannot_be_applied
85
- exec_with_font_styles do |_attrs, _styles|
86
- assert_equal @pdf.internal.stroke_color, 'ff0000'
87
- end
88
- end
89
-
90
- def test_with_font_styles_should_set_line_width_calculated_from_font_size_when_bold_style_cannot_be_applied
91
- exec_with_font_styles do |_attrs, _styles|
92
- assert_equal @pdf.internal.line_width, 18 * 0.025
93
- end
94
- end
95
-
96
- def test_with_font_styles_should_set_mode_to_fill_stroke_when_bold_style_cannot_be_applied
97
- exec_with_font_styles do |attrs, _styles|
98
- assert_equal attrs[:mode], :fill_stroke
99
- end
100
- end
101
-
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|
104
- assert_includes styles, :bold
105
- end
106
- end
107
-
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|
110
- assert_includes styles, :italic
111
- end
112
- end
113
-
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
-
118
- assert_equal @pdf.send(:text_line_leading, 100, font), 100 - font_height
119
- end
120
-
121
- def test_text_without_line_wrap_should_replace_the_spaces_NBSP
122
- assert_equal @pdf.send(:text_without_line_wrap, ' ' * 2), Prawn::Text::NBSP * 2
123
- end
124
-
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')
129
- rescue Prawn::Errors::CannotFit
130
- flunk('Raise Prawn::Errors::CannotFit.')
131
- end
132
-
133
- def test_text_box_attrs_should_return_a_Hash_containing_a_at_and_width_options
134
- attrs = @pdf.send(:text_box_attrs, 0, 0, 50, 100)
135
-
136
- assert_equal attrs.values_at(:at, :width),
137
- [@pdf.send(:pos, 0, 0), @pdf.send(:s2f, 50)]
138
- end
139
-
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)
142
- refute attrs.key?(:single_line)
143
- end
144
-
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)
147
- assert_equal attrs[:single_line], true
148
- end
149
-
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)
152
- refute attrs.key?(:height)
153
- end
154
-
155
- def test_text_box_attrs_should_return_a_Hash_which_does_not_contain_a_single_line_option_when_single_is_not_specified
156
- attrs = @pdf.send(:text_box_attrs, 0, 0, 100, 100)
157
- refute attrs.key?(:single_line)
158
- end
159
-
160
- def test_text_box_attrs_should_return_a_Hash_containing_a_height_optin_when_single_is_not_specified
161
- attrs = @pdf.send(:text_box_attrs, 0, 0, 100, 200)
162
- assert_equal attrs[:height], 200
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
171
- end
@@ -1,110 +0,0 @@
1
- # frozen_string_literal: true
2
-
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
- end
15
- end
16
-
17
- def test_setup_fonts
18
- pdf = document.pdf
19
-
20
- Font::BUILTIN_FONTS.each do |name, path|
21
- expected_font = {
22
- normal: path,
23
- bold: path,
24
- italic: path,
25
- bold_italic: path
26
- }
27
- assert_equal expected_font, pdf.font_families[name]
28
- end
29
-
30
- Font::PRAWN_BUINTIN_FONT_ALIASES.each do |alias_font, original_font|
31
- assert_equal pdf.font_families[alias_font],
32
- pdf.font_families[original_font]
33
- end
34
-
35
- assert_equal Font::DEFAULT_FALLBACK_FONTS, %w[IPAMincho]
36
- end
37
-
38
- def test_setup_fonts_with_custom_fallback_fonts
39
- Thinreports.configure do |c|
40
- c.fallback_fonts = []
41
- end
42
- assert_equal Font::DEFAULT_FALLBACK_FONTS,
43
- document.pdf.fallback_fonts
44
-
45
- Thinreports.configure do |c|
46
- c.fallback_fonts = 'IPAGothic'
47
- end
48
- assert_equal ['IPAGothic'] + Font::DEFAULT_FALLBACK_FONTS,
49
- document.pdf.fallback_fonts
50
-
51
- Thinreports.configure do |c|
52
- c.fallback_fonts = ['IPAMincho']
53
- end
54
- assert_equal ['IPAMincho'] + Font::DEFAULT_FALLBACK_FONTS,
55
- document.pdf.fallback_fonts
56
-
57
- Thinreports.configure do |c|
58
- c.fallback_fonts = ['IPAMincho', data_file('font.ttf')]
59
- end
60
- assert_equal ['IPAMincho', 'Custom-fallback-font1'] + Font::DEFAULT_FALLBACK_FONTS,
61
- document.pdf.fallback_fonts
62
- end
63
-
64
- def test_setup_fonts_with_unknown_custom_fallback_fonts
65
- Thinreports.configure do |c|
66
- c.fallback_fonts = ['/path/to/unknown.ttf']
67
- end
68
-
69
- assert_raises Thinreports::Errors::FontFileNotFound do
70
- create_document
71
- end
72
- end
73
-
74
- def test_default_family
75
- assert_equal 'Helvetica', document.default_family
76
- end
77
-
78
- def test_default_family_if_mmissing
79
- assert_equal 'Helvetica', document.default_family_if_missing('unknown')
80
- assert_equal 'IPAMincho', document.default_family_if_missing('IPAMincho')
81
- end
82
-
83
- def test_font_has_style?
84
- doc = create_document
85
-
86
- assert_equal false, doc.font_has_style?('unknown', :bold)
87
-
88
- doc.pdf.font_families['font_foo'] = {
89
- normal: '/path/to/foo.ttf'
90
- }
91
- assert_equal false, doc.font_has_style?('font_foo', :italic)
92
-
93
- doc.pdf.font_families['font_foo'] = {
94
- normal: '/path/to/foo.ttf',
95
- bold: '/path/to/foo.ttf'
96
- }
97
- assert_equal false, doc.font_has_style?('font_foo', :bold)
98
-
99
- doc.pdf.font_families['font_foo'] = {
100
- normal: '/path/to/foo.ttf',
101
- bold: '/path/to/foo_bold.ttf'
102
- }
103
- assert_equal true, doc.font_has_style?('font_foo', :bold)
104
- end
105
-
106
- def document
107
- Thinreports::Generator::PDF::Document.new
108
- end
109
- alias_method :create_document, :document
110
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PDF::TestGraphics < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- class TestGraphics
9
- attr_accessor :pdf
10
- include Thinreports::Generator::PDF::Graphics
11
- end
12
-
13
- def setup
14
- @g = TestGraphics.new
15
- @g.pdf = mock('pdf')
16
- end
17
-
18
- def test_setup_custom_graphic_states
19
- @g.pdf.expects(:line_width).
20
- with(TestGraphics::BASE_LINE_WIDTH).once
21
-
22
- @g.send(:setup_custom_graphic_states)
23
- end
24
-
25
- def test_line_width
26
- @g.pdf.
27
- expects(:line_width).
28
- with(10 * TestGraphics::BASE_LINE_WIDTH).once
29
-
30
- @g.send(:line_width, 10)
31
- end
32
-
33
- def test_save_graphics_state
34
- @g.pdf.expects(:save_graphics_state).once
35
- @g.send(:save_graphics_state)
36
- end
37
-
38
- def test_restore_graphics_state
39
- @g.pdf.expects(:restore_graphics_state).once
40
- @g.send(:restore_graphics_state)
41
- end
42
- end
@@ -1,122 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PDF::Document::TestPage < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- def create_pdf
9
- @pdf = Thinreports::Generator::PDF::Document.new
10
- end
11
-
12
- def test_JIS_page_size
13
- sizes = Thinreports::Generator::PDF::Document::JIS_SIZES
14
- assert_equal sizes['B4'], [728.5, 1031.8]
15
- assert_equal sizes['B5'], [515.9, 728.5]
16
- end
17
-
18
- def test_B4_paper_size_should_returns_size_as_B4_JIS
19
- create_pdf
20
-
21
- format = Thinreports::Layout::Format.build(layout_file.path)
22
- format.stubs(page_paper_type: 'B4')
23
-
24
- @pdf.start_new_page(format)
25
- assert_equal @pdf.internal.page.size, [728.5, 1031.8]
26
- end
27
-
28
- def test_B4_ISO_paper_size_should_be_converted_to_B4
29
- create_pdf
30
-
31
- format = Thinreports::Layout::Format.build(layout_file.path)
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
-
38
- def test_change_page_format_should_return_true_at_first_time
39
- create_pdf
40
- format = Thinreports::Layout::Format.build(layout_file.path)
41
-
42
- assert_equal @pdf.send(:change_page_format?, format), true
43
- end
44
-
45
- def test_change_page_format_should_return_false_when_given_the_same_format
46
- create_pdf
47
- format = Thinreports::Layout::Format.build(layout_file.path)
48
-
49
- @pdf.instance_variable_set(:@current_page_format, format)
50
- assert_equal @pdf.send(:change_page_format?, format), false
51
- end
52
-
53
- def test_change_page_format_should_return_true_when_given_the_other_format
54
- create_pdf
55
- format1 = Thinreports::Layout::Format.build(layout_file.path)
56
- format2 = Thinreports::Layout::Format.build(layout_file.path)
57
-
58
- @pdf.instance_variable_set(:@current_page_format, format1)
59
- assert_equal @pdf.send(:change_page_format?, format2), true
60
- end
61
-
62
- def test_new_basic_page_options
63
- format = Thinreports::Layout::Format.build(layout_file.path)
64
- options = create_pdf.send(:new_basic_page_options, format)
65
-
66
- assert_equal options[:layout], format.page_orientation.to_sym
67
- assert_equal options[:size], format.page_paper_type
68
- end
69
-
70
- def test_new_basic_page_options_when_the_layout_has_customize_size
71
- format = stub user_paper_type?: true,
72
- page_width: 100,
73
- page_height: 100,
74
- page_orientation: 'portrait'
75
-
76
- options = create_pdf.send(:new_basic_page_options, format)
77
- assert_equal options[:size], [100, 100]
78
- end
79
-
80
- def test_start_new_page_should_create_stamp
81
- create_pdf
82
- format = Thinreports::Layout::Format.build(layout_file.path)
83
- @pdf.start_new_page(format)
84
-
85
- assert_includes @pdf.send(:format_stamp_registry), format.identifier
86
- end
87
-
88
- def test_start_new_page_should_not_create_stamp
89
- create_pdf
90
- format = Thinreports::Layout::Format.build(layout_file.path)
91
- @pdf.start_new_page(format)
92
- @pdf.start_new_page(format)
93
-
94
- assert_equal @pdf.send(:format_stamp_registry).size, 1
95
- end
96
-
97
- def test_start_new_page_should_stamp_constantly
98
- create_pdf
99
- format = Thinreports::Layout::Format.build(layout_file.path)
100
- @pdf.expects(:stamp).with(format.identifier.to_s).times(2)
101
-
102
- @pdf.start_new_page(format)
103
- @pdf.start_new_page(format)
104
- end
105
-
106
- def test_add_blank_page_should_create_an_A4_size_page_in_first_page
107
- create_pdf
108
- @pdf.internal.expects(:start_new_page).with(size: 'A4').once
109
-
110
- @pdf.add_blank_page
111
- end
112
-
113
- def test_add_blank_page_should_call_with_no_arguments_since_second_page
114
- create_pdf
115
- format = Thinreports::Layout::Format.build(layout_file.path)
116
-
117
- @pdf.start_new_page(format)
118
- @pdf.internal.expects(:start_new_page).with({}).once
119
-
120
- @pdf.add_blank_page
121
- end
122
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PDF::TestParseColor < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- class TestColorParser
9
- include Thinreports::Generator::PDF::ParseColor
10
- end
11
-
12
- def setup
13
- @parser = TestColorParser.new
14
- end
15
-
16
- def test_parse_color_with_hexcolor
17
- assert_equal @parser.parse_color('#ff0000'), 'ff0000'
18
- assert_equal @parser.parse_color('000000'), '000000'
19
- end
20
-
21
- def test_parse_color_with_colorname
22
- assert_equal @parser.parse_color('red'), 'ff0000'
23
- end
24
-
25
- def test_parse_color_with_colorname_raise_when_unknown_name_given
26
- assert_raises Thinreports::Errors::UnsupportedColorName do
27
- @parser.parse_color('whitesmoke')
28
- end
29
- end
30
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PrawnExt::TestCalcImageDimensions < Minitest::Test
6
- class Klass
7
- prepend Thinreports::Generator::PrawnExt::CalcImageDimensions
8
-
9
- def calc_image_dimensions(options)
10
- options
11
- end
12
- end
13
-
14
- def setup
15
- @klass = Klass.new
16
- end
17
-
18
- def test_calc_image_dimensions
19
- res_options = @klass.calc_image_dimensions(
20
- auto_fit: [100, 200],
21
- width: 101,
22
- height: 199
23
- )
24
- assert_equal [100, 200], res_options[:fit]
25
- refute_includes res_options.keys, :auto_fit
26
-
27
- res_options = @klass.calc_image_dimensions(
28
- auto_fit: [100, 200],
29
- width: 99,
30
- height: 201
31
- )
32
- assert_equal [100, 200], res_options[:fit]
33
-
34
- res_options = @klass.calc_image_dimensions(
35
- auto_fit: [100, 200],
36
- width: 99,
37
- height: 199
38
- )
39
- refute_includes res_options.keys, :fit
40
- end
41
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PrawnExt::TestWidthOf < Minitest::Test
6
- def setup
7
- @pdf = Prawn::Document.new
8
- end
9
-
10
- def test_width_of
11
- text_width = @pdf.width_of('abcd')
12
-
13
- @pdf.character_spacing(1) do
14
- expected_character_space_width = 1 * 3
15
- assert_equal text_width + expected_character_space_width, @pdf.width_of('abcd')
16
- end
17
-
18
- @pdf.character_spacing(1) do
19
- assert_equal 0, @pdf.width_of('')
20
- end
21
- end
22
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PDF::TestDocument < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- # Alias
9
- Document = Thinreports::Generator::PDF::Document
10
-
11
- def test_new
12
- pdf = Document.new
13
- assert_equal pdf.internal.page_count, 0
14
- assert_equal pdf.internal.page.margins.values, [0, 0, 0, 0]
15
-
16
- pdf = Document.new(security: { owner_password: 'abc' })
17
- assert_equal true, pdf.internal.state.encrypt
18
-
19
- pdf = Document.new(title: 'Title')
20
- assert_equal 'Title', pdf.internal.state.store.info.data[:Title]
21
- end
22
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::TestPDF < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- PDF = Thinreports::Generator::PDF
9
-
10
- def test_default_layout
11
- layout_filename = layout_file.path
12
- report = Thinreports::Report.new layout: layout_filename
13
-
14
- generator = PDF.new report
15
- assert_equal layout_filename, generator.default_layout.filename
16
- end
17
-
18
- def test_initialize
19
- report = Thinreports::Report.new layout: layout_file.path
20
- report.start_new_page
21
-
22
- PDF.new(report)
23
-
24
- assert_equal true, report.finalized?
25
- end
26
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Layout::TestBase < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- Layout = Thinreports::Layout
9
-
10
- def test_load_format
11
- assert_instance_of Layout::Format, Layout::Base.load_format(layout_file.path)
12
- assert_raises Thinreports::Errors::LayoutFileNotFound do
13
- Layout::Base.load_format 'unknown.tlf'
14
- end
15
- end
16
-
17
- def test_new
18
- layout_filename = layout_file.path
19
- layout = Layout::Base.new(layout_filename)
20
-
21
- assert_nil layout.id
22
- assert_equal layout_filename, layout.filename
23
- assert_instance_of Layout::Format, layout.format
24
- end
25
-
26
- def test_id
27
- layout_without_id = Layout::Base.new(layout_file.path)
28
- assert_nil layout_without_id.id
29
-
30
- layout_with_id = Layout::Base.new(layout_file.path, id: 'foo')
31
- assert_equal 'foo', layout_with_id.id
32
- end
33
-
34
- def test_default?
35
- layout_without_id = Layout::Base.new(layout_file.path)
36
- assert_equal true, layout_without_id.default?
37
-
38
- layout_with_id = Layout::Base.new(layout_file.path, id: 'bar')
39
- assert_equal false, layout_with_id.default?
40
- end
41
- end