thinreports 0.10.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +5 -5
  2. data/.github/CONTRIBUTING.md +2 -2
  3. data/.github/workflows/test.yml +51 -0
  4. data/.gitignore +1 -0
  5. data/CHANGELOG.md +49 -0
  6. data/Dockerfile +12 -0
  7. data/Gemfile +2 -1
  8. data/README.md +46 -21
  9. data/Rakefile +13 -29
  10. data/gemfiles/prawn-2.2.gemfile +5 -0
  11. data/gemfiles/prawn-2.3.gemfile +5 -0
  12. data/gemfiles/prawn-2.4.gemfile +5 -0
  13. data/lib/thinreports.rb +5 -0
  14. data/lib/thinreports/core/shape.rb +4 -3
  15. data/lib/thinreports/core/shape/base/interface.rb +0 -1
  16. data/lib/thinreports/core/shape/basic/format.rb +5 -0
  17. data/lib/thinreports/core/shape/image_block.rb +1 -1
  18. data/lib/thinreports/core/shape/list.rb +1 -1
  19. data/lib/thinreports/core/shape/list/manager.rb +1 -4
  20. data/lib/thinreports/core/shape/list/page.rb +2 -5
  21. data/lib/thinreports/core/shape/manager/internal.rb +0 -1
  22. data/lib/thinreports/core/shape/page_number.rb +1 -1
  23. data/lib/thinreports/core/shape/page_number/internal.rb +0 -1
  24. data/lib/thinreports/core/shape/stack_view.rb +17 -0
  25. data/lib/thinreports/core/shape/stack_view/format.rb +27 -0
  26. data/lib/thinreports/core/shape/stack_view/interface.rb +17 -0
  27. data/lib/thinreports/core/shape/stack_view/internal.rb +22 -0
  28. data/lib/thinreports/core/shape/stack_view/row_format.rb +39 -0
  29. data/lib/thinreports/core/shape/style/basic.rb +4 -1
  30. data/lib/thinreports/core/shape/text.rb +1 -1
  31. data/lib/thinreports/core/shape/text_block.rb +1 -1
  32. data/lib/thinreports/core/shape/text_block/formatter/number.rb +21 -9
  33. data/lib/thinreports/core/shape/text_block/internal.rb +0 -2
  34. data/lib/thinreports/core/utils.rb +6 -3
  35. data/lib/thinreports/generate.rb +11 -0
  36. data/lib/thinreports/generator/pdf/document/draw_shape.rb +31 -11
  37. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +1 -2
  38. data/lib/thinreports/generator/pdf/document/font.rb +16 -10
  39. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +0 -1
  40. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +0 -1
  41. data/lib/thinreports/generator/pdf/document/graphics/image.rb +19 -1
  42. data/lib/thinreports/generator/pdf/document/graphics/text.rb +10 -8
  43. data/lib/thinreports/generator/pdf/document/page.rb +13 -4
  44. data/lib/thinreports/generator/pdf/drawer/list.rb +0 -1
  45. data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +1 -3
  46. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +7 -7
  47. data/lib/thinreports/layout/base.rb +2 -4
  48. data/lib/thinreports/layout/format.rb +0 -1
  49. data/lib/thinreports/layout/legacy_schema.rb +2 -6
  50. data/lib/thinreports/layout/version.rb +1 -1
  51. data/lib/thinreports/report/internal.rb +4 -4
  52. data/lib/thinreports/report/page.rb +2 -7
  53. data/lib/thinreports/section_report/build.rb +32 -0
  54. data/lib/thinreports/section_report/builder/item_builder.rb +49 -0
  55. data/lib/thinreports/section_report/builder/report_builder.rb +82 -0
  56. data/lib/thinreports/section_report/builder/report_data.rb +13 -0
  57. data/lib/thinreports/section_report/builder/stack_view_builder.rb +55 -0
  58. data/lib/thinreports/section_report/builder/stack_view_data.rb +11 -0
  59. data/lib/thinreports/section_report/generate.rb +26 -0
  60. data/lib/thinreports/section_report/pdf/render.rb +23 -0
  61. data/lib/thinreports/section_report/pdf/renderer/draw_item.rb +68 -0
  62. data/lib/thinreports/section_report/pdf/renderer/group_renderer.rb +57 -0
  63. data/lib/thinreports/section_report/pdf/renderer/headers_renderer.rb +24 -0
  64. data/lib/thinreports/section_report/pdf/renderer/section_height.rb +100 -0
  65. data/lib/thinreports/section_report/pdf/renderer/section_renderer.rb +39 -0
  66. data/lib/thinreports/section_report/pdf/renderer/stack_view_renderer.rb +55 -0
  67. data/lib/thinreports/section_report/pdf/renderer/stack_view_row_renderer.rb +38 -0
  68. data/lib/thinreports/section_report/schema/loader.rb +28 -0
  69. data/lib/thinreports/section_report/schema/parser.rb +52 -0
  70. data/lib/thinreports/section_report/schema/report.rb +30 -0
  71. data/lib/thinreports/section_report/schema/section.rb +47 -0
  72. data/lib/thinreports/version.rb +1 -1
  73. data/thinreports.gemspec +11 -11
  74. metadata +48 -164
  75. data/.rubocop.yml +0 -41
  76. data/.travis.yml +0 -17
  77. data/examples/character_spacing/character_spacing.rb +0 -8
  78. data/examples/character_spacing/character_spacing.tlf +0 -293
  79. data/examples/dynamic_image/dynamic_image.rb +0 -31
  80. data/examples/dynamic_image/dynamic_image.tlf +0 -661
  81. data/examples/dynamic_image/img200x100.png +0 -0
  82. data/examples/dynamic_image/img50x50.png +0 -0
  83. data/examples/dynamic_style/dynamic_style.rb +0 -150
  84. data/examples/dynamic_style/dynamic_style.tlf +0 -1835
  85. data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
  86. data/examples/dynamic_style/image.png +0 -0
  87. data/examples/eudc/eudc.rb +0 -20
  88. data/examples/eudc/eudc.tlf +0 -180
  89. data/examples/eudc/eudc.ttf +0 -0
  90. data/examples/helper.rb +0 -50
  91. data/examples/hidden_shapes/hidden_shapes.rb +0 -9
  92. data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
  93. data/examples/list_events/list_events.rb +0 -32
  94. data/examples/list_events/list_events.tlf +0 -361
  95. data/examples/list_manual_generation/list_manual_generation.rb +0 -22
  96. data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
  97. data/examples/list_page_number/list_page_number.rb +0 -17
  98. data/examples/list_page_number/list_page_number.tlf +0 -254
  99. data/examples/page_number/page_number.rb +0 -33
  100. data/examples/page_number/page_number.tlf +0 -215
  101. data/examples/palleted_png/palleted_png.png +0 -0
  102. data/examples/palleted_png/palleted_png.rb +0 -9
  103. data/examples/palleted_png/palleted_png.tlf +0 -47
  104. data/examples/password_setting/password_setting.rb +0 -10
  105. data/examples/password_setting/password_setting.tlf +0 -45
  106. data/examples/report_callbacks/report_callbacks.rb +0 -14
  107. data/examples/report_callbacks/report_callbacks.tlf +0 -147
  108. data/examples/single_line_tblock/single_line_tblock.rb +0 -13
  109. data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
  110. data/examples/tblock_overflow/tblock_overflow.rb +0 -20
  111. data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
  112. data/examples/tblock_styles/font_size.tlf +0 -383
  113. data/examples/tblock_styles/tblock_styles.rb +0 -43
  114. data/examples/tblock_styles/tblock_styles.tlf +0 -889
  115. data/examples/text_align/text_align.rb +0 -8
  116. data/examples/text_align/text_align.tlf +0 -241
  117. data/examples/typeB_page_size/B4_ISO.tlf +0 -45
  118. data/examples/typeB_page_size/B4_JIS.tlf +0 -45
  119. data/examples/typeB_page_size/typeB_page_size.rb +0 -17
  120. data/examples/word_wrap/word_wrap.rb +0 -26
  121. data/examples/word_wrap/word_wrap.tlf +0 -297
  122. data/test/data/font.ttf +0 -0
  123. data/test/data/image_normal.jpg +0 -0
  124. data/test/data/image_normal.png +0 -0
  125. data/test/data/image_normal_jpg_noext +0 -0
  126. data/test/data/image_normal_png_noext +0 -0
  127. data/test/data/image_pallete_based.png +0 -0
  128. data/test/data/legacy_layout/all-items.tlf +0 -1
  129. data/test/schema_helper.rb +0 -122
  130. data/test/test_helper.rb +0 -48
  131. data/test/tmp/.gitkeep +0 -0
  132. data/test/unit/core/format/test_base.rb +0 -152
  133. data/test/unit/core/shape/base/test_internal.rb +0 -87
  134. data/test/unit/core/shape/basic/test_block_format.rb +0 -23
  135. data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
  136. data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
  137. data/test/unit/core/shape/basic/test_format.rb +0 -37
  138. data/test/unit/core/shape/basic/test_interface.rb +0 -108
  139. data/test/unit/core/shape/basic/test_internal.rb +0 -55
  140. data/test/unit/core/shape/image_block/test_interface.rb +0 -24
  141. data/test/unit/core/shape/image_block/test_internal.rb +0 -31
  142. data/test/unit/core/shape/list/test_format.rb +0 -111
  143. data/test/unit/core/shape/list/test_manager.rb +0 -67
  144. data/test/unit/core/shape/list/test_page.rb +0 -82
  145. data/test/unit/core/shape/list/test_page_state.rb +0 -31
  146. data/test/unit/core/shape/list/test_section_format.rb +0 -36
  147. data/test/unit/core/shape/list/test_section_interface.rb +0 -75
  148. data/test/unit/core/shape/list/test_section_internal.rb +0 -50
  149. data/test/unit/core/shape/manager/test_format.rb +0 -38
  150. data/test/unit/core/shape/manager/test_internal.rb +0 -132
  151. data/test/unit/core/shape/manager/test_target.rb +0 -140
  152. data/test/unit/core/shape/page_number/test_format.rb +0 -55
  153. data/test/unit/core/shape/page_number/test_interface.rb +0 -33
  154. data/test/unit/core/shape/page_number/test_internal.rb +0 -81
  155. data/test/unit/core/shape/styles/test_base.rb +0 -191
  156. data/test/unit/core/shape/styles/test_basic.rb +0 -24
  157. data/test/unit/core/shape/styles/test_graphic.rb +0 -50
  158. data/test/unit/core/shape/styles/test_text.rb +0 -97
  159. data/test/unit/core/shape/text/test_format.rb +0 -44
  160. data/test/unit/core/shape/text/test_internal.rb +0 -20
  161. data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
  162. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
  163. data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
  164. data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
  165. data/test/unit/core/shape/text_block/test_format.rb +0 -169
  166. data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
  167. data/test/unit/core/shape/text_block/test_interface.rb +0 -63
  168. data/test/unit/core/shape/text_block/test_internal.rb +0 -128
  169. data/test/unit/core/test_shape.rb +0 -52
  170. data/test/unit/core/test_utils.rb +0 -68
  171. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
  172. data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -46
  173. data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -46
  174. data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
  175. data/test/unit/generator/pdf/document/test_font.rb +0 -84
  176. data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
  177. data/test/unit/generator/pdf/document/test_page.rb +0 -122
  178. data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
  179. data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +0 -41
  180. data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +0 -22
  181. data/test/unit/generator/pdf/test_document.rb +0 -22
  182. data/test/unit/generator/test_pdf.rb +0 -26
  183. data/test/unit/layout/test_base.rb +0 -41
  184. data/test/unit/layout/test_format.rb +0 -100
  185. data/test/unit/layout/test_legacy_schema.rb +0 -574
  186. data/test/unit/layout/test_version.rb +0 -26
  187. data/test/unit/report/test_base.rb +0 -248
  188. data/test/unit/report/test_internal.rb +0 -206
  189. data/test/unit/test_config.rb +0 -36
  190. data/test/unit/test_layout.rb +0 -12
  191. data/test/unit/test_report.rb +0 -18
@@ -1,135 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PDF::Graphics::TestAttributes < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- def setup
9
- @pdf = Thinreports::Generator::PDF::Document.new
10
- end
11
-
12
- def test_build_graphic_attributes
13
- graphic_styles = {
14
- 'border-color' => '#ff0000',
15
- 'border-width' => 2.0,
16
- 'border-style' => 'solid',
17
- 'fill-color' => '#000000'
18
- }
19
-
20
- assert_equal(
21
- {
22
- stroke: '#ff0000',
23
- stroke_width: 2.0,
24
- stroke_type: 'solid',
25
- fill: '#000000'
26
- },
27
- @pdf.build_graphic_attributes(graphic_styles)
28
- )
29
-
30
- customized_attributes = @pdf.build_graphic_attributes(graphic_styles) { |attrs| attrs[:stroke] = 'blue' }
31
- assert_equal 'blue', customized_attributes[:stroke]
32
- end
33
-
34
- def test_build_text_attributes
35
- text_styles = {
36
- 'font-family' => %w( Helvetica IPAMincho ),
37
- 'font-size' => 18.0,
38
- 'color' => 'red',
39
- 'text-align' => 'right',
40
- 'vertical-align' => 'bottom',
41
- 'font-style' => %w( bold italic ),
42
- 'letter-spacing' => 2.0,
43
- 'line-height' => 20.0,
44
- 'overflow' => 'expand',
45
- 'word-wrap' => 'break-word'
46
- }
47
-
48
- assert_equal(
49
- {
50
- font: 'Helvetica',
51
- size: 18.0,
52
- color: 'red',
53
- align: :right,
54
- valign: :bottom,
55
- styles: [:bold, :italic],
56
- letter_spacing: 2.0,
57
- line_height: 20.0,
58
- overflow: :expand,
59
- word_wrap: :break_word
60
- },
61
- @pdf.build_text_attributes(text_styles)
62
- )
63
-
64
- customized_attributes = @pdf.build_text_attributes(text_styles) { |attrs| attrs[:color] = 'blue' }
65
- assert_equal 'blue', customized_attributes[:color]
66
- end
67
-
68
- def test_font_family
69
- assert_equal 'IPAGothic', @pdf.font_family(%w( IPAGothic Helvetica ))
70
- assert_equal 'Helvetica', @pdf.font_family(%w( Unknown IPAMincho ))
71
- end
72
-
73
- def test_font_styles
74
- assert_equal [:bold, :italic, :underline, :strikethrough],
75
- @pdf.font_styles(%w( bold italic underline linethrough ))
76
- end
77
-
78
- def test_letter_spacing
79
- assert_equal 2.0, @pdf.letter_spacing(2.0)
80
- assert_nil @pdf.letter_spacing('')
81
- assert_nil @pdf.letter_spacing(nil)
82
- end
83
-
84
- def test_text_align
85
- assert_equal :left, @pdf.text_align('left')
86
- assert_equal :center, @pdf.text_align('center')
87
- assert_equal :right, @pdf.text_align('right')
88
- assert_equal :left, @pdf.text_align('')
89
- assert_equal :left, @pdf.text_align(nil)
90
- end
91
-
92
- def test_text_valign
93
- assert_equal :top, @pdf.text_valign('top')
94
- assert_equal :center, @pdf.text_valign('middle')
95
- assert_equal :bottom, @pdf.text_valign('bottom')
96
- assert_equal :top, @pdf.text_valign('')
97
- assert_equal :top, @pdf.text_valign(nil)
98
- end
99
-
100
- def test_text_overflow
101
- assert_equal :truncate, @pdf.text_overflow('truncate')
102
- assert_equal :shrink_to_fit, @pdf.text_overflow('fit')
103
- assert_equal :expand, @pdf.text_overflow('expand')
104
- assert_equal :truncate, @pdf.text_overflow('')
105
- assert_equal :truncate, @pdf.text_overflow(nil)
106
- end
107
-
108
- def test_word_wrap
109
- assert_equal :break_word, @pdf.word_wrap('break-word')
110
- assert_equal :none, @pdf.word_wrap('none')
111
- assert_equal :none, @pdf.word_wrap(nil)
112
- end
113
-
114
- def test_line_height
115
- assert_equal 20.9, @pdf.line_height(20.9)
116
- assert_nil @pdf.line_height('')
117
- assert_nil @pdf.line_height(nil)
118
- end
119
-
120
- def test_image_position_x
121
- assert_equal :left, @pdf.image_position_x('left')
122
- assert_equal :center, @pdf.image_position_x('center')
123
- assert_equal :right, @pdf.image_position_x('right')
124
- assert_equal :left, @pdf.image_position_x('')
125
- assert_equal :left, @pdf.image_position_x(nil)
126
- end
127
-
128
- def test_image_position_y
129
- assert_equal :top, @pdf.image_position_y('top')
130
- assert_equal :center, @pdf.image_position_y('middle')
131
- assert_equal :bottom, @pdf.image_position_y('bottom')
132
- assert_equal :top, @pdf.image_position_y('')
133
- assert_equal :top, @pdf.image_position_y(nil)
134
- end
135
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PDF::Graphics::TestBasic < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- def setup
9
- @pdf = Thinreports::Generator::PDF::Document.new
10
- end
11
-
12
- def test_build_stroke_styles
13
- style = {
14
- stroke: 'red',
15
- stroke_width: 2.0,
16
- stroke_type: 'solid'
17
- }
18
-
19
- assert_equal(
20
- {
21
- color: 'ff0000',
22
- width: 2.0,
23
- dash: nil
24
- },
25
- @pdf.build_stroke_styles(style)
26
- )
27
-
28
- style_stroke_dashed = style.merge(stroke_type: 'dashed')
29
- assert_equal [2, 2], @pdf.build_stroke_styles(style_stroke_dashed)[:dash]
30
-
31
- style_stroke_dotted = style.merge(stroke_type: 'dotted')
32
- assert_equal [1, 2], @pdf.build_stroke_styles(style_stroke_dotted)[:dash]
33
-
34
- assert_nil @pdf.build_stroke_styles(stroke: nil, stroke_width: 1)
35
- assert_nil @pdf.build_stroke_styles(stroke: 'none', stroke_width: 1)
36
-
37
- assert_nil @pdf.build_stroke_styles(stroke_width: nil, stroke: 'red')
38
- assert_nil @pdf.build_stroke_styles(stroke_width: 0, stroke: 'red')
39
- end
40
-
41
- def test_build_fill_styles
42
- assert_equal({ color: 'ff0000' }, @pdf.build_fill_styles(fill: 'red'))
43
- assert_nil @pdf.build_fill_styles(fill: nil)
44
- assert_nil @pdf.build_fill_styles(fill: 'none')
45
- end
46
- end
@@ -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,84 +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, font|
21
- assert_equal font, pdf.font_families[name]
22
- end
23
-
24
- Font::PRAWN_BUINTIN_FONT_ALIASES.each do |alias_font, original_font|
25
- assert_equal pdf.font_families[alias_font],
26
- pdf.font_families[original_font]
27
- end
28
-
29
- assert_equal Font::DEFAULT_FALLBACK_FONTS, %w[IPAMincho]
30
- end
31
-
32
- def test_setup_fonts_with_custom_fallback_fonts
33
- Thinreports.configure do |c|
34
- c.fallback_fonts = []
35
- end
36
- assert_equal Font::DEFAULT_FALLBACK_FONTS,
37
- document.pdf.fallback_fonts
38
-
39
- Thinreports.configure do |c|
40
- c.fallback_fonts = 'IPAGothic'
41
- end
42
- assert_equal ['IPAGothic'] + Font::DEFAULT_FALLBACK_FONTS,
43
- document.pdf.fallback_fonts
44
-
45
- Thinreports.configure do |c|
46
- c.fallback_fonts = ['IPAMincho']
47
- end
48
- assert_equal ['IPAMincho'] + Font::DEFAULT_FALLBACK_FONTS,
49
- document.pdf.fallback_fonts
50
-
51
- Thinreports.configure do |c|
52
- c.fallback_fonts = ['IPAMincho', data_file('font.ttf')]
53
- end
54
- assert_equal ['IPAMincho', 'Custom-fallback-font1'] + Font::DEFAULT_FALLBACK_FONTS,
55
- document.pdf.fallback_fonts
56
- end
57
-
58
- def test_setup_fonts_with_unknown_custom_fallback_fonts
59
- Thinreports.configure do |c|
60
- c.fallback_fonts = ['/path/to/unknown.ttf']
61
- end
62
-
63
- assert_raises Thinreports::Errors::FontFileNotFound do
64
- create_document
65
- end
66
- end
67
-
68
- def test_font_helpers
69
- doc = document
70
-
71
- assert_equal 'Helvetica', doc.default_family
72
-
73
- assert_equal 'Helvetica', doc.default_family_if_missing('unknown')
74
- assert_equal 'IPAMincho', doc.default_family_if_missing('IPAMincho')
75
-
76
- assert_equal false, doc.font_has_style?('IPAMincho', :bold)
77
- assert_equal true, doc.font_has_style?('Courier New', :bold)
78
- end
79
-
80
- def document
81
- Thinreports::Generator::PDF::Document.new
82
- end
83
- alias_method :create_document, :document
84
- end