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,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
@@ -1,100 +0,0 @@
1
- # frozen_string_literal: true
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,576 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Layout::TestLegacySchema < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- Layout = Thinreports::Layout
9
-
10
- def test_upgrade
11
- legacy_schema = {
12
- 'version' => '0.8.2',
13
- 'finger-print' => 'abcd',
14
- 'config' => {
15
- 'title' => 'Report Title',
16
- 'page' => {
17
- 'paper-type' => 'A4',
18
- 'width' => '100.0',
19
- 'height' => '200.0',
20
- 'orientation' => 'landscape',
21
- 'margin-top' => '0.1',
22
- 'margin-right' => '0.2',
23
- 'margin-bottom' => '0.3',
24
- 'margin-left' => '0.4'
25
- }
26
- },
27
- 'svg' => '<svg><g class="canvas"></g></svg>',
28
- 'state' => {
29
- 'layout-guide' => []
30
- }
31
- }
32
-
33
- assert_equal(
34
- {
35
- 'version' => '0.8.2',
36
- 'title' => 'Report Title',
37
- 'report' => {
38
- 'paper-type' => 'A4',
39
- 'width' => 100.0,
40
- 'height' => 200.0,
41
- 'orientation' => 'landscape',
42
- 'margin' => [0.1, 0.2, 0.3, 0.4]
43
- },
44
- 'items' => []
45
- },
46
- Layout::LegacySchema.new(legacy_schema).upgrade
47
- )
48
- end
49
-
50
- def test_text_item_schema
51
- legacy_attributes = {
52
- 'x-id' => 'text_id',
53
- 'x-left' => '100.1',
54
- 'x-top' => '200.1',
55
- 'x-width' => '300.1',
56
- 'x-height' => '400.1',
57
- 'x-display' => 'true',
58
- 'font-family' => 'Helvetica',
59
- 'font-size' => '18',
60
- 'font-weight' => 'normal',
61
- 'font-style' => 'normal',
62
- 'text-decoration' => 'underline line-through',
63
- 'fill' => 'red',
64
- 'text-anchor' => 'start',
65
- 'x-valign' => 'top',
66
- 'x-line-height' => '20.1',
67
- 'kerning' => '2.1'
68
- }
69
- legacy_texts = %w( line1 line2 )
70
-
71
- assert_equal(
72
- {
73
- 'id' => 'text_id',
74
- 'type' => 'text',
75
- 'x' => 100.1,
76
- 'y' => 200.1,
77
- 'width' => 300.1,
78
- 'height' => 400.1,
79
- 'display' => true,
80
- 'texts' => %w( line1 line2 ),
81
- 'style' => {
82
- 'font-family' => %w( Helvetica ),
83
- 'font-size' => 18.0,
84
- 'color' => 'red',
85
- 'font-style' => %w( underline linethrough ),
86
- 'text-align' => 'left',
87
- 'vertical-align' => 'top',
88
- 'line-height' => 20.1,
89
- 'letter-spacing' => 2.1
90
- }
91
- },
92
- layout_legacy_schema.text_item_schema(legacy_attributes, legacy_texts)
93
- )
94
- end
95
-
96
- def test_rect_item_schema
97
- legacy_attributes = {
98
- 'x-id' => 'rect_id',
99
- 'x' => '100.1',
100
- 'y' => '200.1',
101
- 'width' => '300.1',
102
- 'height' => '400.1',
103
- 'x-display' => 'false',
104
- 'stroke-width' => '2.5',
105
- 'stroke' => '#ff0000',
106
- 'x-stroke-type' => 'dotted',
107
- 'fill' => 'red',
108
- 'rx' => '2'
109
- }
110
- assert_equal(
111
- {
112
- 'id' => 'rect_id',
113
- 'type' => 'rect',
114
- 'x' => 100.1,
115
- 'y' => 200.1,
116
- 'width' => 300.1,
117
- 'height' => 400.1,
118
- 'display' => false,
119
- 'border-radius' => 2,
120
- 'style' => {
121
- 'border-width' => 2.5,
122
- 'border-color' => '#ff0000',
123
- 'border-style' => 'dotted',
124
- 'fill-color' => 'red'
125
- }
126
- },
127
- layout_legacy_schema.rect_item_schema(legacy_attributes)
128
- )
129
- end
130
-
131
- def test_line_item_schema
132
- legacy_attributes = {
133
- 'x-id' => 'line_id',
134
- 'x1' => '100.1',
135
- 'y1' => '200.1',
136
- 'x2' => '300.1',
137
- 'y2' => '400.1',
138
- 'x-display' => 'true',
139
- 'stroke-width' => '1',
140
- 'stroke' => 'red',
141
- 'x-stroke-type' => 'solid'
142
- }
143
- assert_equal(
144
- {
145
- 'id' => 'line_id',
146
- 'type' => 'line',
147
- 'x1' => 100.1,
148
- 'y1' => 200.1,
149
- 'x2' => 300.1,
150
- 'y2' => 400.1,
151
- 'display' => true,
152
- 'style' => {
153
- 'border-width' => 1.0,
154
- 'border-color' => 'red',
155
- 'border-style' => 'solid'
156
- }
157
- },
158
- layout_legacy_schema.line_item_schema(legacy_attributes)
159
- )
160
- end
161
-
162
- def test_ellipse_item_schema
163
- legacy_attributes = {
164
- 'x-id' => 'ellipse_id',
165
- 'cx' => '100.1',
166
- 'cy' => '200.1',
167
- 'rx' => '300.1',
168
- 'ry' => '400.1',
169
- 'x-display' => 'true',
170
- 'stroke-width' => '1',
171
- 'stroke' => 'red',
172
- 'x-stroke-type' => 'solid',
173
- 'fill' => 'blue'
174
- }
175
- assert_equal(
176
- {
177
- 'id' => 'ellipse_id',
178
- 'type' => 'ellipse',
179
- 'cx' => 100.1,
180
- 'cy' => 200.1,
181
- 'rx' => 300.1,
182
- 'ry' => 400.1,
183
- 'display' => true,
184
- 'style' => {
185
- 'border-width' => 1.0,
186
- 'border-color' => 'red',
187
- 'border-style' => 'solid',
188
- 'fill-color' => 'blue'
189
- }
190
- },
191
- layout_legacy_schema.ellipse_item_schema(legacy_attributes)
192
- )
193
- end
194
-
195
- def test_image_item_schema
196
- legacy_attributes = {
197
- 'x-id' => 'image_id',
198
- 'x' => '100.1',
199
- 'y' => '200.1',
200
- 'width' => '300.1',
201
- 'height' => '400.1',
202
- 'x-display' => 'true',
203
- 'xlink:href' => 'data:image/png;base64,xxxxxxxxxxxxx'
204
- }
205
- assert_equal(
206
- {
207
- 'id' => 'image_id',
208
- 'type' => 'image',
209
- 'x' => 100.1,
210
- 'y' => 200.1,
211
- 'width' => 300.1,
212
- 'height' => 400.1,
213
- 'display' => true,
214
- 'data' => {
215
- 'mime-type' => 'image/png',
216
- 'base64' => 'xxxxxxxxxxxxx'
217
- }
218
- },
219
- layout_legacy_schema.image_item_schema(legacy_attributes)
220
- )
221
- end
222
-
223
- def test_page_number_item_schema
224
- legacy_attributes = {
225
- 'x-id' => 'page_number_id',
226
- 'x-left' => '100.1',
227
- 'x-top' => '200.1',
228
- 'x-width' => '300.1',
229
- 'x-height' => '400.1',
230
- 'x-format' => '{page}',
231
- 'x-target' => 'report',
232
- 'x-display' => 'true',
233
- 'font-family' => 'IPAMincho',
234
- 'font-size' => '18.5',
235
- 'fill' => 'red',
236
- 'font-weight' => 'bold',
237
- 'font-style' => 'italic',
238
- 'text-decoration' => '',
239
- 'text-anchor' => 'end',
240
- 'x-overflow' => 'fit'
241
- }
242
- assert_equal(
243
- {
244
- 'id' => 'page_number_id',
245
- 'type' => 'page-number',
246
- 'x' => 100.1,
247
- 'y' => 200.1,
248
- 'width' => 300.1,
249
- 'height' => 400.1,
250
- 'format' => '{page}',
251
- 'target' => 'report',
252
- 'display' => true,
253
- 'style' => {
254
- 'font-family' => %w( IPAMincho ),
255
- 'font-size' => 18.5,
256
- 'color' => 'red',
257
- 'font-style' => %w( bold italic ),
258
- 'text-align' => 'right',
259
- 'overflow' => 'fit'
260
- }
261
- },
262
- layout_legacy_schema.page_number_item_schema(legacy_attributes)
263
- )
264
- end
265
-
266
- def test_image_block_item_schema
267
- legacy_attributes = {
268
- 'x-id' => 'image_block_id',
269
- 'x-left' => '100.1',
270
- 'x-top' => '200.1',
271
- 'x-width' => '300.1',
272
- 'x-height' => '400.1',
273
- 'x-display' => 'false',
274
- 'x-position-x' => 'right',
275
- 'x-position-y' => 'bottom'
276
- }
277
- assert_equal(
278
- {
279
- 'id' => 'image_block_id',
280
- 'type' => 'image-block',
281
- 'x' => 100.1,
282
- 'y' => 200.1,
283
- 'width' => 300.1,
284
- 'height' => 400.1,
285
- 'display' => false,
286
- 'style' => {
287
- 'position-x' => 'right',
288
- 'position-y' => 'bottom'
289
- }
290
- },
291
- layout_legacy_schema.image_block_item_schema(legacy_attributes)
292
- )
293
- end
294
-
295
- def test_text_block_schema
296
- base_legacy_attributes = {
297
- 'x-id' => 'text_block_id',
298
- 'x-left' => '100.1',
299
- 'x-top' => '200.1',
300
- 'x-width' => '300.1',
301
- 'x-height' => '400.1',
302
- 'x-display' => 'true',
303
- 'x-value' => 'default value',
304
- 'x-multiple' => 'true',
305
- 'font-family' => 'Helvetica',
306
- 'font-size' => '18',
307
- 'font-weight' => 'bold',
308
- 'font-style' => 'normal',
309
- 'text-decoration' => 'line-through',
310
- 'fill' => 'red',
311
- 'text-anchor' => 'start',
312
- 'x-valign' => 'top',
313
- 'x-line-height' => '20.1',
314
- 'kerning' => '2.1',
315
- 'x-overflow' => 'expand',
316
- 'x-word-wrap' => 'break-word',
317
- 'x-format-base' => '$ {value}',
318
- 'x-format-type' => '',
319
- 'x-ref-id' => 'other_text_block_id'
320
- }
321
- assert_equal(
322
- {
323
- 'id' => 'text_block_id',
324
- 'type' => 'text-block',
325
- 'x' => 100.1,
326
- 'y' => 200.1,
327
- 'width' => 300.1,
328
- 'height' => 400.1,
329
- 'display' => true,
330
- 'value' => 'default value',
331
- 'multiple-line' => true,
332
- 'reference-id' => 'other_text_block_id',
333
- 'format' => {
334
- 'base' => '$ {value}',
335
- 'type' => ''
336
- },
337
- 'style' => {
338
- 'font-family' => %w( Helvetica ),
339
- 'font-size' => 18.0,
340
- 'color' => 'red',
341
- 'font-style' => %w( bold linethrough ),
342
- 'text-align' => 'left',
343
- 'vertical-align' => 'top',
344
- 'line-height' => 20.1,
345
- 'letter-spacing' => 2.1,
346
- 'overflow' => 'expand',
347
- 'word-wrap' => 'break-word'
348
- }
349
- },
350
- layout_legacy_schema.text_block_item_schema(base_legacy_attributes)
351
- )
352
-
353
- schema_with_datetime_format = layout_legacy_schema.text_block_item_schema(base_legacy_attributes.merge(
354
- 'x-format-type' => 'datetime',
355
- 'x-format-datetime-format' => '%Y'
356
- ))
357
- assert_equal(
358
- {
359
- 'base' => '$ {value}',
360
- 'type' => 'datetime',
361
- 'datetime' => {
362
- 'format' => '%Y'
363
- }
364
- },
365
- schema_with_datetime_format['format']
366
- )
367
-
368
- schema_with_number_format = layout_legacy_schema.text_block_item_schema(base_legacy_attributes.merge(
369
- 'x-format-type' => 'number',
370
- 'x-format-number-precision' => '1',
371
- 'x-format-number-delimiter' => ','
372
- ))
373
- assert_equal(
374
- {
375
- 'base' => '$ {value}',
376
- 'type' => 'number',
377
- 'number' => {
378
- 'delimiter' => ',',
379
- 'precision' => 1
380
- }
381
- },
382
- schema_with_number_format['format']
383
- )
384
-
385
- schema_with_padding_format = layout_legacy_schema.text_block_item_schema(base_legacy_attributes.merge(
386
- 'x-format-type' => 'padding',
387
- 'x-format-padding-char' => '0',
388
- 'x-format-padding-length' => '10',
389
- 'x-format-padding-direction' => 'L'
390
- ))
391
- assert_equal(
392
- {
393
- 'base' => '$ {value}',
394
- 'type' => 'padding',
395
- 'padding' => {
396
- 'length' => 10,
397
- 'char' => '0',
398
- 'direction' => 'L'
399
- }
400
- },
401
- schema_with_padding_format['format']
402
- )
403
- end
404
-
405
- def test_list_item_schema
406
- legacy_schema = {
407
- 'id' => 'default',
408
- 'type' => 's-list',
409
- 'content-height' => '300',
410
- 'page-break' => 'true',
411
- 'display' => 'false',
412
- 'header-enabled' => 'false',
413
- 'page-footer-enabled' => 'true',
414
- 'footer-enabled' => 'true',
415
- 'header' => {
416
- 'height' => '100.1',
417
- 'translate' => {
418
- 'x' => '100',
419
- 'y' => '200'
420
- },
421
- 'svg' => { 'content' => '' }
422
- },
423
- 'detail' => {
424
- 'height' => '200.1',
425
- 'translate' => {
426
- 'x' => '300',
427
- 'y' => '400'
428
- },
429
- 'svg' => { 'content' => '' }
430
- },
431
- 'page-footer' => {
432
- 'height' => '300.1',
433
- 'translate' => {
434
- 'x' => '500',
435
- 'y' => '600'
436
- },
437
- 'svg' => { 'content' => '' }
438
- },
439
- 'footer' => {
440
- 'height' => '400.1',
441
- 'translate' => {
442
- 'x' => '700',
443
- 'y' => '800'
444
- },
445
- 'svg' => { 'content' => '' }
446
- }
447
- }
448
-
449
- layout_legacy_schema.stubs(:legacy_item_schemas).returns({ 'default' => legacy_schema })
450
-
451
- legacy_element = mock()
452
- legacy_element.stubs(:attributes).returns({ 'x-id' => 'default' })
453
- legacy_element.stubs(:elements).returns({})
454
-
455
- assert_equal(
456
- {
457
- 'id' => 'default',
458
- 'type' => 'list',
459
- 'content-height' => 300.0,
460
- 'auto-page-break' => true,
461
- 'display' => false,
462
- 'header' => {
463
- 'height' => 100.1,
464
- 'translate' => {
465
- 'x' => 100.0,
466
- 'y' => 200.0
467
- },
468
- 'items' => [],
469
- 'enabled' => false
470
- },
471
- 'detail' => {
472
- 'height' => 200.1,
473
- 'translate' => {
474
- 'x' => 300.0,
475
- 'y' => 400.0
476
- },
477
- 'items' => []
478
- },
479
- 'page-footer' => {
480
- 'height' => 300.1,
481
- 'translate' => {
482
- 'x' => 500.0,
483
- 'y' => 800.1
484
- },
485
- 'items' => [],
486
- 'enabled' => true
487
- },
488
- 'footer' => {
489
- 'height' => 400.1,
490
- 'translate' => {
491
- 'x' => 700.0,
492
- 'y' => 1300.2
493
- },
494
- 'items' => [],
495
- 'enabled' => true
496
- }
497
- },
498
- layout_legacy_schema.list_item_schema(legacy_element)
499
- )
500
- end
501
-
502
- def test_image_position_y
503
- assert_equal 'top', layout_legacy_schema.image_position_y('top')
504
- assert_equal 'middle', layout_legacy_schema.image_position_y('center')
505
- assert_equal 'bottom', layout_legacy_schema.image_position_y('bottom')
506
- end
507
-
508
- def test_display
509
- assert_equal true, layout_legacy_schema.display('true')
510
- assert_equal false, layout_legacy_schema.display('false')
511
- end
512
-
513
- def test_font_style
514
- no_style = {
515
- 'font-weight' => 'normal',
516
- 'font-style' => 'normal',
517
- 'text-decoration' => 'none'
518
- }
519
- assert_equal [], layout_legacy_schema.font_style(no_style)
520
- assert_equal %w( bold ), layout_legacy_schema.font_style(no_style.merge('font-weight' => 'bold'))
521
- assert_equal %w( italic ), layout_legacy_schema.font_style(no_style.merge('font-style' => 'italic'))
522
- assert_equal %w( underline ), layout_legacy_schema.font_style(no_style.merge('text-decoration' => 'underline'))
523
- assert_equal %w( linethrough ), layout_legacy_schema.font_style(no_style.merge('text-decoration' => 'line-through'))
524
- assert_equal %w( underline linethrough ), layout_legacy_schema.font_style(no_style.merge('text-decoration' => 'line-through underline'))
525
- end
526
-
527
- def test_text_align
528
- assert_equal 'left', layout_legacy_schema.text_align('start')
529
- assert_equal 'center', layout_legacy_schema.text_align('middle')
530
- assert_equal 'right', layout_legacy_schema.text_align('end')
531
- end
532
-
533
- def test_vertical_align
534
- assert_equal '', layout_legacy_schema.vertical_align(nil)
535
- assert_equal 'top', layout_legacy_schema.vertical_align('top')
536
- assert_equal 'middle', layout_legacy_schema.vertical_align('center')
537
- assert_equal 'bottom', layout_legacy_schema.vertical_align('bottom')
538
- assert_equal 'top', layout_legacy_schema.vertical_align('')
539
- end
540
-
541
- def test_line_height
542
- assert_equal '', layout_legacy_schema.line_height('')
543
- assert_equal '', layout_legacy_schema.line_height(nil)
544
- assert_equal 20.1, layout_legacy_schema.line_height('20.1')
545
- end
546
-
547
- def test_letter_spacing
548
- assert_equal '', layout_legacy_schema.letter_spacing('')
549
- assert_equal '', layout_legacy_schema.letter_spacing('auto')
550
- assert_equal 2.5, layout_legacy_schema.letter_spacing('2.5')
551
- end
552
-
553
- def test_extract_item_schemas
554
- svg = <<-SVG
555
- <!--SHAPE{"id":"item1"}SHAPE-->
556
- <!--LAYOUT<rect id="item2"/>LAYOUT-->
557
- <!--SHAPE{"id":"item3"}SHAPE-->
558
- SVG
559
- assert_equal(
560
- { 'item1' => { 'id' => 'item1' }, 'item3' => { 'id' => 'item3' } },
561
- layout_legacy_schema.extract_legacy_item_schemas(svg)
562
- )
563
- end
564
-
565
- def test_cleanup_svg
566
- svg = '<!--SHAPE{"id":"item1"}SHAPE--><!--LAYOUT<rect id="item2"/>LAYOUT--><!--SHAPE{"id":"item2"}SHAPE-->'
567
-
568
- assert_equal '<rect id="item2"/>', layout_legacy_schema.cleanup_svg(svg)
569
- end
570
-
571
- private
572
-
573
- def layout_legacy_schema
574
- @layout_legacy_schema ||= Layout::LegacySchema.new({ 'svg' => '' })
575
- end
576
- end