thinreports 0.9.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +39 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +59 -2
  5. data/Dockerfile +12 -0
  6. data/Gemfile +7 -4
  7. data/README.md +44 -22
  8. data/Rakefile +14 -31
  9. data/lib/thinreports.rb +16 -15
  10. data/lib/thinreports/config.rb +2 -24
  11. data/lib/thinreports/core/errors.rb +6 -17
  12. data/lib/thinreports/core/format/base.rb +62 -61
  13. data/lib/thinreports/core/shape.rb +10 -12
  14. data/lib/thinreports/core/shape/base.rb +3 -12
  15. data/lib/thinreports/core/shape/base/interface.rb +34 -32
  16. data/lib/thinreports/core/shape/base/internal.rb +45 -43
  17. data/lib/thinreports/core/shape/basic.rb +12 -12
  18. data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
  19. data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
  20. data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
  21. data/lib/thinreports/core/shape/basic/format.rb +11 -9
  22. data/lib/thinreports/core/shape/basic/interface.rb +79 -77
  23. data/lib/thinreports/core/shape/basic/internal.rb +17 -14
  24. data/lib/thinreports/core/shape/image_block.rb +9 -9
  25. data/lib/thinreports/core/shape/image_block/format.rb +7 -5
  26. data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
  27. data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
  28. data/lib/thinreports/core/shape/list.rb +13 -13
  29. data/lib/thinreports/core/shape/list/format.rb +83 -77
  30. data/lib/thinreports/core/shape/list/manager.rb +179 -176
  31. data/lib/thinreports/core/shape/list/page.rb +91 -93
  32. data/lib/thinreports/core/shape/list/page_state.rb +42 -40
  33. data/lib/thinreports/core/shape/list/section_format.rb +28 -26
  34. data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
  35. data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
  36. data/lib/thinreports/core/shape/manager.rb +4 -13
  37. data/lib/thinreports/core/shape/manager/format.rb +21 -19
  38. data/lib/thinreports/core/shape/manager/internal.rb +87 -84
  39. data/lib/thinreports/core/shape/manager/target.rb +93 -95
  40. data/lib/thinreports/core/shape/page_number.rb +9 -9
  41. data/lib/thinreports/core/shape/page_number/format.rb +20 -18
  42. data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
  43. data/lib/thinreports/core/shape/page_number/internal.rb +46 -44
  44. data/lib/thinreports/core/shape/style.rb +5 -14
  45. data/lib/thinreports/core/shape/style/base.rb +121 -120
  46. data/lib/thinreports/core/shape/style/basic.rb +12 -10
  47. data/lib/thinreports/core/shape/style/graphic.rb +35 -33
  48. data/lib/thinreports/core/shape/style/text.rb +113 -107
  49. data/lib/thinreports/core/shape/text.rb +9 -9
  50. data/lib/thinreports/core/shape/text/format.rb +10 -9
  51. data/lib/thinreports/core/shape/text/interface.rb +13 -11
  52. data/lib/thinreports/core/shape/text/internal.rb +14 -12
  53. data/lib/thinreports/core/shape/text_block.rb +10 -10
  54. data/lib/thinreports/core/shape/text_block/format.rb +35 -33
  55. data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
  56. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
  57. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
  58. data/lib/thinreports/core/shape/text_block/formatter/number.rb +52 -34
  59. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
  60. data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
  61. data/lib/thinreports/core/shape/text_block/internal.rb +66 -68
  62. data/lib/thinreports/core/utils.rb +7 -3
  63. data/lib/thinreports/generator/pdf.rb +24 -25
  64. data/lib/thinreports/generator/pdf/document.rb +109 -110
  65. data/lib/thinreports/generator/pdf/document/draw_shape.rb +57 -51
  66. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +50 -47
  67. data/lib/thinreports/generator/pdf/document/font.rb +67 -58
  68. data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
  69. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +121 -121
  70. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +112 -114
  71. data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
  72. data/lib/thinreports/generator/pdf/document/graphics/text.rb +149 -137
  73. data/lib/thinreports/generator/pdf/document/page.rb +60 -64
  74. data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
  75. data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
  76. data/lib/thinreports/generator/pdf/drawer/list.rb +56 -54
  77. data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
  78. data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
  79. data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
  80. data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +32 -0
  81. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +35 -0
  82. data/lib/thinreports/layout.rb +5 -7
  83. data/lib/thinreports/layout/base.rb +5 -9
  84. data/lib/thinreports/layout/format.rb +17 -13
  85. data/lib/thinreports/layout/legacy_schema.rb +17 -13
  86. data/lib/thinreports/layout/version.rb +22 -25
  87. data/lib/thinreports/report.rb +4 -6
  88. data/lib/thinreports/report/base.rb +24 -51
  89. data/lib/thinreports/report/internal.rb +13 -15
  90. data/lib/thinreports/report/page.rb +5 -11
  91. data/lib/thinreports/version.rb +2 -2
  92. data/thinreports.gemspec +10 -19
  93. metadata +13 -288
  94. data/.travis.yml +0 -19
  95. data/examples/character_spacing/character_spacing.rb +0 -8
  96. data/examples/character_spacing/character_spacing.tlf +0 -293
  97. data/examples/dynamic_image/dynamic_image.rb +0 -31
  98. data/examples/dynamic_image/dynamic_image.tlf +0 -661
  99. data/examples/dynamic_image/img200x100.png +0 -0
  100. data/examples/dynamic_image/img50x50.png +0 -0
  101. data/examples/dynamic_style/dynamic_style.rb +0 -150
  102. data/examples/dynamic_style/dynamic_style.tlf +0 -1835
  103. data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
  104. data/examples/dynamic_style/image.png +0 -0
  105. data/examples/eudc/eudc.rb +0 -20
  106. data/examples/eudc/eudc.tlf +0 -180
  107. data/examples/eudc/eudc.ttf +0 -0
  108. data/examples/helper.rb +0 -50
  109. data/examples/hidden_shapes/hidden_shapes.rb +0 -9
  110. data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
  111. data/examples/list_events/list_events.rb +0 -32
  112. data/examples/list_events/list_events.tlf +0 -361
  113. data/examples/list_manual_generation/list_manual_generation.rb +0 -22
  114. data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
  115. data/examples/list_page_number/list_page_number.rb +0 -17
  116. data/examples/list_page_number/list_page_number.tlf +0 -254
  117. data/examples/page_number/page_number.rb +0 -33
  118. data/examples/page_number/page_number.tlf +0 -215
  119. data/examples/palleted_png/palleted_png.png +0 -0
  120. data/examples/palleted_png/palleted_png.rb +0 -11
  121. data/examples/palleted_png/palleted_png.tlf +0 -47
  122. data/examples/password_setting/password_setting.rb +0 -10
  123. data/examples/password_setting/password_setting.tlf +0 -45
  124. data/examples/report_callbacks/report_callbacks.rb +0 -14
  125. data/examples/report_callbacks/report_callbacks.tlf +0 -147
  126. data/examples/single_line_tblock/single_line_tblock.rb +0 -13
  127. data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
  128. data/examples/tblock_overflow/tblock_overflow.rb +0 -20
  129. data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
  130. data/examples/tblock_styles/font_size.tlf +0 -383
  131. data/examples/tblock_styles/tblock_styles.rb +0 -43
  132. data/examples/tblock_styles/tblock_styles.tlf +0 -889
  133. data/examples/text_align/text_align.rb +0 -8
  134. data/examples/text_align/text_align.tlf +0 -241
  135. data/examples/typeB_page_size/B4_ISO.tlf +0 -45
  136. data/examples/typeB_page_size/B4_JIS.tlf +0 -45
  137. data/examples/typeB_page_size/typeB_page_size.rb +0 -17
  138. data/examples/word_wrap/word_wrap.rb +0 -26
  139. data/examples/word_wrap/word_wrap.tlf +0 -297
  140. data/lib/thinreports/generator.rb +0 -29
  141. data/lib/thinreports/generator/base.rb +0 -40
  142. data/lib/thinreports/generator/configuration.rb +0 -31
  143. data/lib/thinreports/report/events.rb +0 -32
  144. data/test/data/font.ttf +0 -0
  145. data/test/data/image_normal.jpg +0 -0
  146. data/test/data/image_normal.png +0 -0
  147. data/test/data/image_normal_jpg_noext +0 -0
  148. data/test/data/image_normal_png_noext +0 -0
  149. data/test/data/image_pallete_based.png +0 -0
  150. data/test/data/legacy_layout/all-items.tlf +0 -1
  151. data/test/schema_helper.rb +0 -121
  152. data/test/test_helper.rb +0 -42
  153. data/test/tmp/.gitkeep +0 -0
  154. data/test/unit/core/format/test_base.rb +0 -152
  155. data/test/unit/core/shape/base/test_internal.rb +0 -87
  156. data/test/unit/core/shape/basic/test_block_format.rb +0 -23
  157. data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
  158. data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
  159. data/test/unit/core/shape/basic/test_format.rb +0 -37
  160. data/test/unit/core/shape/basic/test_interface.rb +0 -108
  161. data/test/unit/core/shape/basic/test_internal.rb +0 -55
  162. data/test/unit/core/shape/image_block/test_interface.rb +0 -24
  163. data/test/unit/core/shape/image_block/test_internal.rb +0 -31
  164. data/test/unit/core/shape/list/test_format.rb +0 -111
  165. data/test/unit/core/shape/list/test_manager.rb +0 -67
  166. data/test/unit/core/shape/list/test_page.rb +0 -82
  167. data/test/unit/core/shape/list/test_page_state.rb +0 -31
  168. data/test/unit/core/shape/list/test_section_format.rb +0 -36
  169. data/test/unit/core/shape/list/test_section_interface.rb +0 -75
  170. data/test/unit/core/shape/list/test_section_internal.rb +0 -50
  171. data/test/unit/core/shape/manager/test_format.rb +0 -38
  172. data/test/unit/core/shape/manager/test_internal.rb +0 -132
  173. data/test/unit/core/shape/manager/test_target.rb +0 -140
  174. data/test/unit/core/shape/page_number/test_format.rb +0 -55
  175. data/test/unit/core/shape/page_number/test_interface.rb +0 -33
  176. data/test/unit/core/shape/page_number/test_internal.rb +0 -81
  177. data/test/unit/core/shape/styles/test_base.rb +0 -191
  178. data/test/unit/core/shape/styles/test_basic.rb +0 -24
  179. data/test/unit/core/shape/styles/test_graphic.rb +0 -50
  180. data/test/unit/core/shape/styles/test_text.rb +0 -97
  181. data/test/unit/core/shape/text/test_format.rb +0 -44
  182. data/test/unit/core/shape/text/test_internal.rb +0 -20
  183. data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
  184. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
  185. data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
  186. data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
  187. data/test/unit/core/shape/text_block/test_format.rb +0 -169
  188. data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
  189. data/test/unit/core/shape/text_block/test_interface.rb +0 -63
  190. data/test/unit/core/shape/text_block/test_internal.rb +0 -128
  191. data/test/unit/core/test_shape.rb +0 -52
  192. data/test/unit/core/test_utils.rb +0 -68
  193. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
  194. data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -45
  195. data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -150
  196. data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
  197. data/test/unit/generator/pdf/document/test_font.rb +0 -84
  198. data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
  199. data/test/unit/generator/pdf/document/test_page.rb +0 -122
  200. data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
  201. data/test/unit/generator/pdf/test_document.rb +0 -20
  202. data/test/unit/generator/test_base.rb +0 -40
  203. data/test/unit/generator/test_configuration.rb +0 -21
  204. data/test/unit/generator/test_pdf.rb +0 -24
  205. data/test/unit/layout/test_base.rb +0 -41
  206. data/test/unit/layout/test_format.rb +0 -100
  207. data/test/unit/layout/test_legacy_schema.rb +0 -574
  208. data/test/unit/layout/test_version.rb +0 -95
  209. data/test/unit/report/test_base.rb +0 -262
  210. data/test/unit/report/test_internal.rb +0 -206
  211. data/test/unit/test_config.rb +0 -51
  212. data/test/unit/test_layout.rb +0 -12
  213. data/test/unit/test_report.rb +0 -18
@@ -1,20 +0,0 @@
1
- # coding: utf-8
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_without_page_creation
12
- pdf = Document.new
13
- assert_equal pdf.internal.page_count, 0
14
- end
15
-
16
- def test_new_with_zero_margin_canvas
17
- pdf = Document.new
18
- assert_equal pdf.internal.page.margins.values, [0, 0, 0, 0]
19
- end
20
- end
@@ -1,40 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::TestBase < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- Generator = Thinreports::Generator
9
-
10
- class FooGenerator < Generator::Base; end
11
-
12
- def test_registring_generator
13
- assert_same FooGenerator, Generator.registry.delete(:foogenerator)
14
- end
15
-
16
- def test_new
17
- report = Thinreports::Report.new layout: layout_file.path
18
-
19
- refute report.finalized?
20
- Generator::Base.new report
21
- assert report.finalized?
22
- end
23
-
24
- def test_generate
25
- report = Thinreports::Report.new layout: layout_file.path
26
-
27
- generator = Generator::Base.new report
28
- assert_raises NotImplementedError do
29
- generator.generate
30
- end
31
- end
32
-
33
- def test_default_layout
34
- layout_filename = layout_file.path
35
- report = Thinreports::Report.new layout: layout_filename
36
-
37
- generator = Generator::Base.new report
38
- assert_equal layout_filename, generator.default_layout.filename
39
- end
40
- end
@@ -1,21 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::TestConfiguration < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- def setup
9
- @config = Thinreports::Generator::Configuration.new
10
- end
11
-
12
- def test_default_should_return_pdf_by_default
13
- assert_equal @config.default, :pdf
14
- end
15
-
16
- def test_default_should_raise_when_value_is_unknown_generator_type
17
- assert_raises Thinreports::Errors::UnknownGeneratorType do
18
- @config.default = :unknown
19
- end
20
- end
21
- end
@@ -1,24 +0,0 @@
1
- # coding: utf-8
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_new_should_set_title_as_metadata
11
- report = Thinreports::Report.new layout: layout_file.path
12
- report.start_new_page
13
-
14
- actual_pdf_title = nil
15
- PDF::Document.define_singleton_method(:new) {|_options, meta|
16
- actual_pdf_title = meta[:Title]
17
- }
18
- PDF.new report, {}
19
-
20
- assert_equal 'Report Title', actual_pdf_title
21
- ensure
22
- PDF::Document.singleton_class.send(:remove_method, :new)
23
- end
24
- end
@@ -1,41 +0,0 @@
1
- # coding: utf-8
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
@@ -1,100 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Layout::TestFormat < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- LAYOUT_SCHEMA = {
9
- 'version' => '0.9.0',
10
- 'title' => 'Report Title',
11
- 'report' => {
12
- 'paper-type' => 'A4',
13
- 'width' => 100.0,
14
- 'height' => 200.0,
15
- 'orientation' => 'landscape',
16
- 'margin' => [100.0, 200.0, 300.0, 999.9]
17
- },
18
- 'state' => {
19
- 'layout-guides' => [
20
- { 'type' => 'x', 'position' => 0.1 }
21
- ]
22
- },
23
- 'items' => [
24
- { 'type'=> 'rect', 'id'=> '', 'x'=> 100.0, 'y'=> 100.0, 'width'=> 100.0, 'height'=> 100.0, 'style'=> {'stroke-width'=> 1}},
25
- { 'type'=> 'text-block', 'id'=> 'text_block', 'x'=> 100.0, 'y'=> 100.0 },
26
- { 'type'=> 'page-number', 'id'=> '', 'x'=> 100.0, 'y'=> 100.0 }
27
- ]
28
- }
29
-
30
- Shape = Thinreports::Core::Shape
31
- Layout = Thinreports::Layout
32
-
33
- def test_attribute_readers
34
- format = Layout::Format.new(layout_schema)
35
-
36
- assert_equal 'Report Title', format.report_title
37
- assert_equal Thinreports::VERSION, format.last_version
38
- assert_equal 'A4', format.page_paper_type
39
- assert_equal 100.0, format.page_width
40
- assert_equal 200.0, format.page_height
41
- assert_equal 'landscape', format.page_orientation
42
- end
43
-
44
- def test_user_paper_type?
45
- format_paper_type_is_not_user = Layout::Format.new(layout_schema)
46
- assert_equal false, format_paper_type_is_not_user.user_paper_type?
47
-
48
- format_paper_type_is_user = Layout::Format.new(layout_schema.merge(
49
- {
50
- 'report' => {
51
- 'paper-type' => 'user'
52
- }
53
- }
54
- ))
55
- assert_equal true, format_paper_type_is_user.user_paper_type?
56
- end
57
-
58
- def test_build
59
- compatible_layout_file = layout_file
60
- assert_instance_of Layout::Format, Layout::Format.build(compatible_layout_file.path)
61
-
62
- incompatible_layout_file = layout_file(version: '0.0.1')
63
- assert_raises Thinreports::Errors::IncompatibleLayoutFormat do
64
- Layout::Format.build(incompatible_layout_file.path)
65
- end
66
- end
67
-
68
- def test_build_legacy_layout
69
- format = nil
70
-
71
- assert_deprecated { format = Layout::Format.build(data_file('legacy_layout', 'all-items.tlf')) }
72
-
73
- assert_equal 'Report Title', format.report_title
74
- assert_equal '0.8.2', format.last_version
75
- assert_equal 'A4', format.page_paper_type
76
- assert_equal 'portrait', format.page_orientation
77
-
78
- item_types = format.attributes['items'].map { |items| items['type'] }
79
-
80
- assert_equal 9, item_types.count
81
- assert_equal %w( rect ellipse line image image-block text-block list page-number text ).sort,
82
- item_types.sort
83
- end
84
-
85
- def test_initialize_items
86
- format = Layout::Format.new(layout_schema)
87
-
88
- assert_equal 2, format.shapes.count
89
-
90
- shape_classes = format.shapes.values.map(&:class)
91
- assert_includes shape_classes, Shape::TextBlock::Format
92
- assert_includes shape_classes, Shape::PageNumber::Format
93
- end
94
-
95
- private
96
-
97
- def layout_schema(version = Thinreports::VERSION)
98
- LAYOUT_SCHEMA.merge('version' => version)
99
- end
100
- end
@@ -1,574 +0,0 @@
1
- # coding: utf-8
2
- require 'test_helper'
3
-
4
- class Thinreports::Layout::TestLegacySchema < Minitest::Test
5
- include Thinreports::TestHelper
6
-
7
- Layout = Thinreports::Layout
8
-
9
- def test_upgrade
10
- legacy_schema = {
11
- 'version' => '0.8.2',
12
- 'finger-print' => 'abcd',
13
- 'config' => {
14
- 'title' => 'Report Title',
15
- 'page' => {
16
- 'paper-type' => 'A4',
17
- 'width' => '100.0',
18
- 'height' => '200.0',
19
- 'orientation' => 'landscape',
20
- 'margin-top' => '0.1',
21
- 'margin-right' => '0.2',
22
- 'margin-bottom' => '0.3',
23
- 'margin-left' => '0.4'
24
- }
25
- },
26
- 'svg' => '<svg><g class="canvas"></g></svg>',
27
- 'state' => {
28
- 'layout-guide' => []
29
- }
30
- }
31
-
32
- assert_equal(
33
- {
34
- 'version' => '0.8.2',
35
- 'title' => 'Report Title',
36
- 'report' => {
37
- 'paper-type' => 'A4',
38
- 'width' => 100.0,
39
- 'height' => 200.0,
40
- 'orientation' => 'landscape',
41
- 'margin' => [0.1, 0.2, 0.3, 0.4]
42
- },
43
- 'items' => []
44
- },
45
- Layout::LegacySchema.new(legacy_schema).upgrade
46
- )
47
- end
48
-
49
- def test_text_item_schema
50
- legacy_attributes = {
51
- 'x-id' => 'text_id',
52
- 'x-left' => '100.1',
53
- 'x-top' => '200.1',
54
- 'x-width' => '300.1',
55
- 'x-height' => '400.1',
56
- 'x-display' => 'true',
57
- 'font-family' => 'Helvetica',
58
- 'font-size' => '18',
59
- 'font-weight' => 'normal',
60
- 'font-style' => 'normal',
61
- 'text-decoration' => 'underline line-through',
62
- 'fill' => 'red',
63
- 'text-anchor' => 'start',
64
- 'x-valign' => 'top',
65
- 'x-line-height' => '20.1',
66
- 'kerning' => '2.1'
67
- }
68
- legacy_texts = %w( line1 line2 )
69
-
70
- assert_equal(
71
- {
72
- 'id' => 'text_id',
73
- 'type' => 'text',
74
- 'x' => 100.1,
75
- 'y' => 200.1,
76
- 'width' => 300.1,
77
- 'height' => 400.1,
78
- 'display' => true,
79
- 'texts' => %w( line1 line2 ),
80
- 'style' => {
81
- 'font-family' => %w( Helvetica ),
82
- 'font-size' => 18.0,
83
- 'color' => 'red',
84
- 'font-style' => %w( underline linethrough ),
85
- 'text-align' => 'left',
86
- 'vertical-align' => 'top',
87
- 'line-height' => 20.1,
88
- 'letter-spacing' => 2.1
89
- }
90
- },
91
- layout_legacy_schema.text_item_schema(legacy_attributes, legacy_texts)
92
- )
93
- end
94
-
95
- def test_rect_item_schema
96
- legacy_attributes = {
97
- 'x-id' => 'rect_id',
98
- 'x' => '100.1',
99
- 'y' => '200.1',
100
- 'width' => '300.1',
101
- 'height' => '400.1',
102
- 'x-display' => 'false',
103
- 'stroke-width' => '2.5',
104
- 'stroke' => '#ff0000',
105
- 'x-stroke-type' => 'dotted',
106
- 'fill' => 'red'
107
- }
108
- assert_equal(
109
- {
110
- 'id' => 'rect_id',
111
- 'type' => 'rect',
112
- 'x' => 100.1,
113
- 'y' => 200.1,
114
- 'width' => 300.1,
115
- 'height' => 400.1,
116
- 'display' => false,
117
- 'style' => {
118
- 'border-width' => 2.5,
119
- 'border-color' => '#ff0000',
120
- 'border-style' => 'dotted',
121
- 'fill-color' => 'red'
122
- }
123
- },
124
- layout_legacy_schema.rect_item_schema(legacy_attributes)
125
- )
126
- end
127
-
128
- def test_line_item_schema
129
- legacy_attributes = {
130
- 'x-id' => 'line_id',
131
- 'x1' => '100.1',
132
- 'y1' => '200.1',
133
- 'x2' => '300.1',
134
- 'y2' => '400.1',
135
- 'x-display' => 'true',
136
- 'stroke-width' => '1',
137
- 'stroke' => 'red',
138
- 'x-stroke-type' => 'solid'
139
- }
140
- assert_equal(
141
- {
142
- 'id' => 'line_id',
143
- 'type' => 'line',
144
- 'x1' => 100.1,
145
- 'y1' => 200.1,
146
- 'x2' => 300.1,
147
- 'y2' => 400.1,
148
- 'display' => true,
149
- 'style' => {
150
- 'border-width' => 1.0,
151
- 'border-color' => 'red',
152
- 'border-style' => 'solid'
153
- }
154
- },
155
- layout_legacy_schema.line_item_schema(legacy_attributes)
156
- )
157
- end
158
-
159
- def test_ellipse_item_schema
160
- legacy_attributes = {
161
- 'x-id' => 'ellipse_id',
162
- 'cx' => '100.1',
163
- 'cy' => '200.1',
164
- 'rx' => '300.1',
165
- 'ry' => '400.1',
166
- 'x-display' => 'true',
167
- 'stroke-width' => '1',
168
- 'stroke' => 'red',
169
- 'x-stroke-type' => 'solid',
170
- 'fill' => 'blue'
171
- }
172
- assert_equal(
173
- {
174
- 'id' => 'ellipse_id',
175
- 'type' => 'ellipse',
176
- 'cx' => 100.1,
177
- 'cy' => 200.1,
178
- 'rx' => 300.1,
179
- 'ry' => 400.1,
180
- 'display' => true,
181
- 'style' => {
182
- 'border-width' => 1.0,
183
- 'border-color' => 'red',
184
- 'border-style' => 'solid',
185
- 'fill-color' => 'blue'
186
- }
187
- },
188
- layout_legacy_schema.ellipse_item_schema(legacy_attributes)
189
- )
190
- end
191
-
192
- def test_image_item_schema
193
- legacy_attributes = {
194
- 'x-id' => 'image_id',
195
- 'x' => '100.1',
196
- 'y' => '200.1',
197
- 'width' => '300.1',
198
- 'height' => '400.1',
199
- 'x-display' => 'true',
200
- 'xlink:href' => 'data:image/png;base64,xxxxxxxxxxxxx'
201
- }
202
- assert_equal(
203
- {
204
- 'id' => 'image_id',
205
- 'type' => 'image',
206
- 'x' => 100.1,
207
- 'y' => 200.1,
208
- 'width' => 300.1,
209
- 'height' => 400.1,
210
- 'display' => true,
211
- 'data' => {
212
- 'mime-type' => 'image/png',
213
- 'base64' => 'xxxxxxxxxxxxx'
214
- }
215
- },
216
- layout_legacy_schema.image_item_schema(legacy_attributes)
217
- )
218
- end
219
-
220
- def test_page_number_item_schema
221
- legacy_attributes = {
222
- 'x-id' => 'page_number_id',
223
- 'x-left' => '100.1',
224
- 'x-top' => '200.1',
225
- 'x-width' => '300.1',
226
- 'x-height' => '400.1',
227
- 'x-format' => '{page}',
228
- 'x-target' => 'report',
229
- 'x-display' => 'true',
230
- 'font-family' => 'IPAMincho',
231
- 'font-size' => '18.5',
232
- 'fill' => 'red',
233
- 'font-weight' => 'bold',
234
- 'font-style' => 'italic',
235
- 'text-decoration' => '',
236
- 'text-anchor' => 'end',
237
- 'x-overflow' => 'fit'
238
- }
239
- assert_equal(
240
- {
241
- 'id' => 'page_number_id',
242
- 'type' => 'page-number',
243
- 'x' => 100.1,
244
- 'y' => 200.1,
245
- 'width' => 300.1,
246
- 'height' => 400.1,
247
- 'format' => '{page}',
248
- 'target' => 'report',
249
- 'display' => true,
250
- 'style' => {
251
- 'font-family' => %w( IPAMincho ),
252
- 'font-size' => 18.5,
253
- 'color' => 'red',
254
- 'font-style' => %w( bold italic ),
255
- 'text-align' => 'right',
256
- 'overflow' => 'fit'
257
- }
258
- },
259
- layout_legacy_schema.page_number_item_schema(legacy_attributes)
260
- )
261
- end
262
-
263
- def test_image_block_item_schema
264
- legacy_attributes = {
265
- 'x-id' => 'image_block_id',
266
- 'x-left' => '100.1',
267
- 'x-top' => '200.1',
268
- 'x-width' => '300.1',
269
- 'x-height' => '400.1',
270
- 'x-display' => 'false',
271
- 'x-position-x' => 'right',
272
- 'x-position-y' => 'bottom'
273
- }
274
- assert_equal(
275
- {
276
- 'id' => 'image_block_id',
277
- 'type' => 'image-block',
278
- 'x' => 100.1,
279
- 'y' => 200.1,
280
- 'width' => 300.1,
281
- 'height' => 400.1,
282
- 'display' => false,
283
- 'style' => {
284
- 'position-x' => 'right',
285
- 'position-y' => 'bottom'
286
- }
287
- },
288
- layout_legacy_schema.image_block_item_schema(legacy_attributes)
289
- )
290
- end
291
-
292
- def test_text_block_schema
293
- base_legacy_attributes = {
294
- 'x-id' => 'text_block_id',
295
- 'x-left' => '100.1',
296
- 'x-top' => '200.1',
297
- 'x-width' => '300.1',
298
- 'x-height' => '400.1',
299
- 'x-display' => 'true',
300
- 'x-value' => 'default value',
301
- 'x-multiple' => 'true',
302
- 'font-family' => 'Helvetica',
303
- 'font-size' => '18',
304
- 'font-weight' => 'bold',
305
- 'font-style' => 'normal',
306
- 'text-decoration' => 'line-through',
307
- 'fill' => 'red',
308
- 'text-anchor' => 'start',
309
- 'x-valign' => 'top',
310
- 'x-line-height' => '20.1',
311
- 'kerning' => '2.1',
312
- 'x-overflow' => 'expand',
313
- 'x-word-wrap' => 'break-word',
314
- 'x-format-base' => '$ {value}',
315
- 'x-format-type' => '',
316
- 'x-ref-id' => 'other_text_block_id'
317
- }
318
- assert_equal(
319
- {
320
- 'id' => 'text_block_id',
321
- 'type' => 'text-block',
322
- 'x' => 100.1,
323
- 'y' => 200.1,
324
- 'width' => 300.1,
325
- 'height' => 400.1,
326
- 'display' => true,
327
- 'value' => 'default value',
328
- 'multiple-line' => true,
329
- 'reference-id' => 'other_text_block_id',
330
- 'format' => {
331
- 'base' => '$ {value}',
332
- 'type' => ''
333
- },
334
- 'style' => {
335
- 'font-family' => %w( Helvetica ),
336
- 'font-size' => 18.0,
337
- 'color' => 'red',
338
- 'font-style' => %w( bold linethrough ),
339
- 'text-align' => 'left',
340
- 'vertical-align' => 'top',
341
- 'line-height' => 20.1,
342
- 'letter-spacing' => 2.1,
343
- 'overflow' => 'expand',
344
- 'word-wrap' => 'break-word'
345
- }
346
- },
347
- layout_legacy_schema.text_block_item_schema(base_legacy_attributes)
348
- )
349
-
350
- schema_with_datetime_format = layout_legacy_schema.text_block_item_schema(base_legacy_attributes.merge(
351
- 'x-format-type' => 'datetime',
352
- 'x-format-datetime-format' => '%Y'
353
- ))
354
- assert_equal(
355
- {
356
- 'base' => '$ {value}',
357
- 'type' => 'datetime',
358
- 'datetime' => {
359
- 'format' => '%Y'
360
- }
361
- },
362
- schema_with_datetime_format['format']
363
- )
364
-
365
- schema_with_number_format = layout_legacy_schema.text_block_item_schema(base_legacy_attributes.merge(
366
- 'x-format-type' => 'number',
367
- 'x-format-number-precision' => '1',
368
- 'x-format-number-delimiter' => ','
369
- ))
370
- assert_equal(
371
- {
372
- 'base' => '$ {value}',
373
- 'type' => 'number',
374
- 'number' => {
375
- 'delimiter' => ',',
376
- 'precision' => 1
377
- }
378
- },
379
- schema_with_number_format['format']
380
- )
381
-
382
- schema_with_padding_format = layout_legacy_schema.text_block_item_schema(base_legacy_attributes.merge(
383
- 'x-format-type' => 'padding',
384
- 'x-format-padding-char' => '0',
385
- 'x-format-padding-length' => '10',
386
- 'x-format-padding-direction' => 'L'
387
- ))
388
- assert_equal(
389
- {
390
- 'base' => '$ {value}',
391
- 'type' => 'padding',
392
- 'padding' => {
393
- 'length' => 10,
394
- 'char' => '0',
395
- 'direction' => 'L'
396
- }
397
- },
398
- schema_with_padding_format['format']
399
- )
400
- end
401
-
402
- def test_list_item_schema
403
- legacy_schema = {
404
- 'id' => 'default',
405
- 'type' => 's-list',
406
- 'content-height' => '300',
407
- 'page-break' => 'true',
408
- 'display' => 'false',
409
- 'header-enabled' => 'false',
410
- 'page-footer-enabled' => 'true',
411
- 'footer-enabled' => 'true',
412
- 'header' => {
413
- 'height' => '100.1',
414
- 'translate' => {
415
- 'x' => '100',
416
- 'y' => '200'
417
- },
418
- 'svg' => { 'content' => '' }
419
- },
420
- 'detail' => {
421
- 'height' => '200.1',
422
- 'translate' => {
423
- 'x' => '300',
424
- 'y' => '400'
425
- },
426
- 'svg' => { 'content' => '' }
427
- },
428
- 'page-footer' => {
429
- 'height' => '300.1',
430
- 'translate' => {
431
- 'x' => '500',
432
- 'y' => '600'
433
- },
434
- 'svg' => { 'content' => '' }
435
- },
436
- 'footer' => {
437
- 'height' => '400.1',
438
- 'translate' => {
439
- 'x' => '700',
440
- 'y' => '800'
441
- },
442
- 'svg' => { 'content' => '' }
443
- }
444
- }
445
-
446
- layout_legacy_schema.stubs(:legacy_item_schemas).returns({ 'default' => legacy_schema })
447
-
448
- legacy_element = mock()
449
- legacy_element.stubs(:attributes).returns({ 'x-id' => 'default' })
450
- legacy_element.stubs(:elements).returns({})
451
-
452
- assert_equal(
453
- {
454
- 'id' => 'default',
455
- 'type' => 'list',
456
- 'content-height' => 300.0,
457
- 'auto-page-break' => true,
458
- 'display' => false,
459
- 'header' => {
460
- 'height' => 100.1,
461
- 'translate' => {
462
- 'x' => 100.0,
463
- 'y' => 200.0
464
- },
465
- 'items' => [],
466
- 'enabled' => false
467
- },
468
- 'detail' => {
469
- 'height' => 200.1,
470
- 'translate' => {
471
- 'x' => 300.0,
472
- 'y' => 400.0
473
- },
474
- 'items' => []
475
- },
476
- 'page-footer' => {
477
- 'height' => 300.1,
478
- 'translate' => {
479
- 'x' => 500.0,
480
- 'y' => 800.1
481
- },
482
- 'items' => [],
483
- 'enabled' => true
484
- },
485
- 'footer' => {
486
- 'height' => 400.1,
487
- 'translate' => {
488
- 'x' => 700.0,
489
- 'y' => 1300.2
490
- },
491
- 'items' => [],
492
- 'enabled' => true
493
- }
494
- },
495
- layout_legacy_schema.list_item_schema(legacy_element)
496
- )
497
- end
498
-
499
- def test_image_position_y
500
- assert_equal 'top', layout_legacy_schema.image_position_y('top')
501
- assert_equal 'middle', layout_legacy_schema.image_position_y('center')
502
- assert_equal 'bottom', layout_legacy_schema.image_position_y('bottom')
503
- end
504
-
505
- def test_display
506
- assert_equal true, layout_legacy_schema.display('true')
507
- assert_equal false, layout_legacy_schema.display('false')
508
- end
509
-
510
- def test_font_style
511
- no_style = {
512
- 'font-weight' => 'normal',
513
- 'font-style' => 'normal',
514
- 'text-decoration' => 'none'
515
- }
516
- assert_equal [], layout_legacy_schema.font_style(no_style)
517
- assert_equal %w( bold ), layout_legacy_schema.font_style(no_style.merge('font-weight' => 'bold'))
518
- assert_equal %w( italic ), layout_legacy_schema.font_style(no_style.merge('font-style' => 'italic'))
519
- assert_equal %w( underline ), layout_legacy_schema.font_style(no_style.merge('text-decoration' => 'underline'))
520
- assert_equal %w( linethrough ), layout_legacy_schema.font_style(no_style.merge('text-decoration' => 'line-through'))
521
- assert_equal %w( underline linethrough ), layout_legacy_schema.font_style(no_style.merge('text-decoration' => 'line-through underline'))
522
- end
523
-
524
- def test_text_align
525
- assert_equal 'left', layout_legacy_schema.text_align('start')
526
- assert_equal 'center', layout_legacy_schema.text_align('middle')
527
- assert_equal 'right', layout_legacy_schema.text_align('end')
528
- end
529
-
530
- def test_vertical_align
531
- assert_equal '', layout_legacy_schema.vertical_align(nil)
532
- assert_equal 'top', layout_legacy_schema.vertical_align('top')
533
- assert_equal 'middle', layout_legacy_schema.vertical_align('center')
534
- assert_equal 'bottom', layout_legacy_schema.vertical_align('bottom')
535
- assert_equal 'top', layout_legacy_schema.vertical_align('')
536
- end
537
-
538
- def test_line_height
539
- assert_equal '', layout_legacy_schema.line_height('')
540
- assert_equal '', layout_legacy_schema.line_height(nil)
541
- assert_equal 20.1, layout_legacy_schema.line_height('20.1')
542
- end
543
-
544
- def test_letter_spacing
545
- assert_equal '', layout_legacy_schema.letter_spacing('')
546
- assert_equal '', layout_legacy_schema.letter_spacing('auto')
547
- assert_equal 2.5, layout_legacy_schema.letter_spacing('2.5')
548
- end
549
-
550
- def test_extract_item_schemas
551
- svg = <<-SVG
552
- <!--SHAPE{"id":"item1"}SHAPE-->
553
- <!--LAYOUT<rect id="item2"/>LAYOUT-->
554
- <!--SHAPE{"id":"item3"}SHAPE-->
555
- SVG
556
- assert_equal(
557
- { 'item1' => { 'id' => 'item1' }, 'item3' => { 'id' => 'item3' } },
558
- layout_legacy_schema.extract_legacy_item_schemas(svg)
559
- )
560
- end
561
-
562
- def test_normalize_svg
563
- svg = '<!--SHAPE{"id":"item1"}SHAPE--><!--LAYOUT<rect id="item2"/>LAYOUT--><!--SHAPE{"id":"item2"}SHAPE-->'
564
-
565
- layout_legacy_schema.normalize_svg!(svg)
566
- assert_equal '<rect id="item2"/>', svg
567
- end
568
-
569
- private
570
-
571
- def layout_legacy_schema
572
- @layout_legacy_schema ||= Layout::LegacySchema.new({ 'svg' => '' })
573
- end
574
- end