thinreports 0.10.3 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +39 -0
  3. data/CHANGELOG.md +20 -0
  4. data/Dockerfile +12 -0
  5. data/Gemfile +5 -0
  6. data/README.md +37 -13
  7. data/Rakefile +1 -0
  8. data/lib/thinreports/core/shape/image_block.rb +1 -1
  9. data/lib/thinreports/core/shape/list.rb +1 -1
  10. data/lib/thinreports/core/shape/page_number.rb +1 -1
  11. data/lib/thinreports/core/shape/text.rb +1 -1
  12. data/lib/thinreports/core/shape/text_block.rb +1 -1
  13. data/lib/thinreports/core/shape/text_block/formatter/number.rb +6 -1
  14. data/lib/thinreports/core/shape/text_block/internal.rb +0 -2
  15. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +6 -0
  16. data/lib/thinreports/layout/base.rb +1 -1
  17. data/lib/thinreports/layout/version.rb +1 -1
  18. data/lib/thinreports/report/internal.rb +2 -0
  19. data/lib/thinreports/version.rb +1 -1
  20. data/thinreports.gemspec +5 -9
  21. metadata +6 -204
  22. data/.travis.yml +0 -32
  23. data/test/data/font.ttf +0 -0
  24. data/test/data/image_normal.jpg +0 -0
  25. data/test/data/image_normal.png +0 -0
  26. data/test/data/image_normal_jpg_noext +0 -0
  27. data/test/data/image_normal_png_noext +0 -0
  28. data/test/data/image_pallete_based.png +0 -0
  29. data/test/data/legacy_layout/all-items.tlf +0 -1
  30. data/test/features/dynamic_style/expect.pdf +0 -3714
  31. data/test/features/dynamic_style/image.png +0 -0
  32. data/test/features/dynamic_style/templates/styles.tlf +0 -1835
  33. data/test/features/dynamic_style/templates/styles_in_list.tlf +0 -344
  34. data/test/features/dynamic_style/test_dynamic_style.rb +0 -152
  35. data/test/features/eudc/eudc.ttf +0 -0
  36. data/test/features/eudc/expect.pdf +0 -0
  37. data/test/features/eudc/template.tlf +0 -180
  38. data/test/features/eudc/test_eudc.rb +0 -27
  39. data/test/features/feature_test.rb +0 -58
  40. data/test/features/graphics/expect.pdf +0 -475
  41. data/test/features/graphics/template.tlf +0 -309
  42. data/test/features/graphics/test_graphics.rb +0 -12
  43. data/test/features/hidden_item/expect.pdf +0 -0
  44. data/test/features/hidden_item/template.tlf +0 -449
  45. data/test/features/hidden_item/test_hidden_item.rb +0 -12
  46. data/test/features/image_block/expect.pdf +0 -0
  47. data/test/features/image_block/img200x100.png +0 -0
  48. data/test/features/image_block/img50x50.png +0 -0
  49. data/test/features/image_block/template.tlf +0 -661
  50. data/test/features/image_block/test_image_block.rb +0 -35
  51. data/test/features/list_events/expect.pdf +0 -659
  52. data/test/features/list_events/template.tlf +0 -361
  53. data/test/features/list_events/test_list_events.rb +0 -36
  54. data/test/features/list_manually/expect.pdf +0 -599
  55. data/test/features/list_manually/template.tlf +0 -132
  56. data/test/features/list_manually/test_list_manually.rb +0 -25
  57. data/test/features/page_number/expect.pdf +0 -400
  58. data/test/features/page_number/template.tlf +0 -215
  59. data/test/features/page_number/test_page_number.rb +0 -24
  60. data/test/features/page_number_with_list/expect.pdf +0 -721
  61. data/test/features/page_number_with_list/template.tlf +0 -254
  62. data/test/features/page_number_with_list/test_page_number_with_list.rb +0 -21
  63. data/test/features/palleted_png/expect.pdf +0 -0
  64. data/test/features/palleted_png/palleted_png.png +0 -0
  65. data/test/features/palleted_png/template.tlf +0 -47
  66. data/test/features/palleted_png/test_palleted_png.rb +0 -14
  67. data/test/features/report_callbacks/expect.pdf +0 -169
  68. data/test/features/report_callbacks/template.tlf +0 -147
  69. data/test/features/report_callbacks/test_report_callbacks.rb +0 -18
  70. data/test/features/text_align/expect.pdf +0 -0
  71. data/test/features/text_align/template.tlf +0 -241
  72. data/test/features/text_align/test_text_align.rb +0 -12
  73. data/test/features/text_block_overflow/expect.pdf +0 -0
  74. data/test/features/text_block_overflow/template.tlf +0 -538
  75. data/test/features/text_block_overflow/test_text_block_overflow.rb +0 -25
  76. data/test/features/text_block_singleline/expect.pdf +0 -0
  77. data/test/features/text_block_singleline/template.tlf +0 -170
  78. data/test/features/text_block_singleline/test_text_block_singleline.rb +0 -15
  79. data/test/features/text_block_style/expect.pdf +0 -1391
  80. data/test/features/text_block_style/templates/basic_styles.tlf +0 -889
  81. data/test/features/text_block_style/templates/font_size.tlf +0 -383
  82. data/test/features/text_block_style/test_text_block_style.rb +0 -47
  83. data/test/features/text_character_spacing/expect.pdf +0 -0
  84. data/test/features/text_character_spacing/template.tlf +0 -293
  85. data/test/features/text_character_spacing/test_text_character_spacing.rb +0 -12
  86. data/test/features/text_word_wrap/expect.pdf +0 -0
  87. data/test/features/text_word_wrap/template.tlf +0 -297
  88. data/test/features/text_word_wrap/test_text_word_wrap.rb +0 -30
  89. data/test/schema_helper.rb +0 -122
  90. data/test/test_helper.rb +0 -39
  91. data/test/units/core/format/test_base.rb +0 -152
  92. data/test/units/core/shape/base/test_internal.rb +0 -87
  93. data/test/units/core/shape/basic/test_block_format.rb +0 -23
  94. data/test/units/core/shape/basic/test_block_interface.rb +0 -29
  95. data/test/units/core/shape/basic/test_block_internal.rb +0 -55
  96. data/test/units/core/shape/basic/test_format.rb +0 -37
  97. data/test/units/core/shape/basic/test_interface.rb +0 -108
  98. data/test/units/core/shape/basic/test_internal.rb +0 -55
  99. data/test/units/core/shape/image_block/test_interface.rb +0 -24
  100. data/test/units/core/shape/image_block/test_internal.rb +0 -31
  101. data/test/units/core/shape/list/test_format.rb +0 -111
  102. data/test/units/core/shape/list/test_manager.rb +0 -67
  103. data/test/units/core/shape/list/test_page.rb +0 -156
  104. data/test/units/core/shape/list/test_page_state.rb +0 -31
  105. data/test/units/core/shape/list/test_section_format.rb +0 -36
  106. data/test/units/core/shape/list/test_section_interface.rb +0 -75
  107. data/test/units/core/shape/list/test_section_internal.rb +0 -50
  108. data/test/units/core/shape/manager/test_format.rb +0 -38
  109. data/test/units/core/shape/manager/test_internal.rb +0 -132
  110. data/test/units/core/shape/manager/test_target.rb +0 -140
  111. data/test/units/core/shape/page_number/test_format.rb +0 -55
  112. data/test/units/core/shape/page_number/test_interface.rb +0 -33
  113. data/test/units/core/shape/page_number/test_internal.rb +0 -81
  114. data/test/units/core/shape/styles/test_base.rb +0 -191
  115. data/test/units/core/shape/styles/test_basic.rb +0 -24
  116. data/test/units/core/shape/styles/test_graphic.rb +0 -50
  117. data/test/units/core/shape/styles/test_text.rb +0 -97
  118. data/test/units/core/shape/text/test_format.rb +0 -44
  119. data/test/units/core/shape/text/test_internal.rb +0 -20
  120. data/test/units/core/shape/text_block/formatter/test_basic.rb +0 -24
  121. data/test/units/core/shape/text_block/formatter/test_datetime.rb +0 -49
  122. data/test/units/core/shape/text_block/formatter/test_number.rb +0 -76
  123. data/test/units/core/shape/text_block/formatter/test_padding.rb +0 -77
  124. data/test/units/core/shape/text_block/test_format.rb +0 -169
  125. data/test/units/core/shape/text_block/test_formatter.rb +0 -28
  126. data/test/units/core/shape/text_block/test_interface.rb +0 -63
  127. data/test/units/core/shape/text_block/test_internal.rb +0 -128
  128. data/test/units/core/test_shape.rb +0 -52
  129. data/test/units/core/test_utils.rb +0 -68
  130. data/test/units/generator/pdf/document/graphics/test_attributes.rb +0 -135
  131. data/test/units/generator/pdf/document/graphics/test_basic.rb +0 -46
  132. data/test/units/generator/pdf/document/graphics/test_image.rb +0 -46
  133. data/test/units/generator/pdf/document/graphics/test_text.rb +0 -171
  134. data/test/units/generator/pdf/document/test_font.rb +0 -110
  135. data/test/units/generator/pdf/document/test_graphics.rb +0 -42
  136. data/test/units/generator/pdf/document/test_page.rb +0 -122
  137. data/test/units/generator/pdf/document/test_parse_color.rb +0 -30
  138. data/test/units/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +0 -41
  139. data/test/units/generator/pdf/prawn_ext/test_width_of.rb +0 -22
  140. data/test/units/generator/pdf/test_document.rb +0 -22
  141. data/test/units/generator/test_pdf.rb +0 -26
  142. data/test/units/layout/test_base.rb +0 -41
  143. data/test/units/layout/test_format.rb +0 -100
  144. data/test/units/layout/test_legacy_schema.rb +0 -576
  145. data/test/units/layout/test_version.rb +0 -26
  146. data/test/units/report/test_base.rb +0 -248
  147. data/test/units/report/test_internal.rb +0 -206
  148. data/test/units/test_config.rb +0 -36
  149. data/test/units/test_layout.rb +0 -12
  150. data/test/units/test_report.rb +0 -18
@@ -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,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