thinreports 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +41 -0
- data/.travis.yml +4 -6
- data/CHANGELOG.md +21 -2
- data/Gemfile +2 -4
- data/README.md +4 -5
- data/Rakefile +7 -8
- data/examples/character_spacing/character_spacing.rb +1 -1
- data/examples/dynamic_image/dynamic_image.rb +3 -3
- data/examples/dynamic_style/dynamic_style.rb +1 -1
- data/examples/eudc/eudc.rb +1 -1
- data/examples/helper.rb +2 -2
- data/examples/hidden_shapes/hidden_shapes.rb +1 -1
- data/examples/list_events/list_events.rb +1 -1
- data/examples/list_manual_generation/list_manual_generation.rb +1 -1
- data/examples/list_page_number/list_page_number.rb +1 -1
- data/examples/page_number/page_number.rb +1 -1
- data/examples/palleted_png/palleted_png.rb +1 -3
- data/examples/password_setting/password_setting.rb +1 -1
- data/examples/report_callbacks/report_callbacks.rb +1 -1
- data/examples/single_line_tblock/single_line_tblock.rb +1 -1
- data/examples/tblock_overflow/tblock_overflow.rb +1 -1
- data/examples/tblock_styles/tblock_styles.rb +1 -1
- data/examples/text_align/text_align.rb +1 -1
- data/examples/typeB_page_size/typeB_page_size.rb +1 -1
- data/examples/word_wrap/word_wrap.rb +1 -1
- data/lib/thinreports.rb +16 -15
- data/lib/thinreports/config.rb +2 -24
- data/lib/thinreports/core/errors.rb +6 -17
- data/lib/thinreports/core/format/base.rb +62 -61
- data/lib/thinreports/core/shape.rb +13 -14
- data/lib/thinreports/core/shape/base.rb +3 -12
- data/lib/thinreports/core/shape/base/interface.rb +35 -32
- data/lib/thinreports/core/shape/base/internal.rb +45 -43
- data/lib/thinreports/core/shape/basic.rb +12 -12
- data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
- data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
- data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
- data/lib/thinreports/core/shape/basic/format.rb +11 -9
- data/lib/thinreports/core/shape/basic/interface.rb +79 -77
- data/lib/thinreports/core/shape/basic/internal.rb +17 -14
- data/lib/thinreports/core/shape/image_block.rb +9 -9
- data/lib/thinreports/core/shape/image_block/format.rb +7 -5
- data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
- data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
- data/lib/thinreports/core/shape/list.rb +13 -13
- data/lib/thinreports/core/shape/list/format.rb +83 -77
- data/lib/thinreports/core/shape/list/manager.rb +182 -176
- data/lib/thinreports/core/shape/list/page.rb +94 -93
- data/lib/thinreports/core/shape/list/page_state.rb +42 -40
- data/lib/thinreports/core/shape/list/section_format.rb +28 -26
- data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
- data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
- data/lib/thinreports/core/shape/manager.rb +4 -13
- data/lib/thinreports/core/shape/manager/format.rb +21 -19
- data/lib/thinreports/core/shape/manager/internal.rb +88 -84
- data/lib/thinreports/core/shape/manager/target.rb +93 -95
- data/lib/thinreports/core/shape/page_number.rb +9 -9
- data/lib/thinreports/core/shape/page_number/format.rb +20 -18
- data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
- data/lib/thinreports/core/shape/page_number/internal.rb +47 -44
- data/lib/thinreports/core/shape/style.rb +5 -14
- data/lib/thinreports/core/shape/style/base.rb +121 -120
- data/lib/thinreports/core/shape/style/basic.rb +12 -10
- data/lib/thinreports/core/shape/style/graphic.rb +35 -33
- data/lib/thinreports/core/shape/style/text.rb +113 -107
- data/lib/thinreports/core/shape/text.rb +9 -9
- data/lib/thinreports/core/shape/text/format.rb +10 -9
- data/lib/thinreports/core/shape/text/interface.rb +13 -11
- data/lib/thinreports/core/shape/text/internal.rb +14 -12
- data/lib/thinreports/core/shape/text_block.rb +10 -10
- data/lib/thinreports/core/shape/text_block/format.rb +35 -33
- data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +45 -39
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
- data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
- data/lib/thinreports/core/shape/text_block/internal.rb +68 -68
- data/lib/thinreports/core/utils.rb +4 -3
- data/lib/thinreports/generator/pdf.rb +24 -25
- data/lib/thinreports/generator/pdf/document.rb +109 -110
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +58 -51
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +51 -47
- data/lib/thinreports/generator/pdf/document/font.rb +62 -59
- data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +122 -121
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +113 -114
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +152 -137
- data/lib/thinreports/generator/pdf/document/page.rb +63 -64
- data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
- data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
- data/lib/thinreports/generator/pdf/drawer/list.rb +48 -45
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
- data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
- data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
- data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +34 -0
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +29 -0
- data/lib/thinreports/layout.rb +5 -7
- data/lib/thinreports/layout/base.rb +5 -7
- data/lib/thinreports/layout/format.rb +18 -13
- data/lib/thinreports/layout/legacy_schema.rb +18 -10
- data/lib/thinreports/layout/version.rb +22 -25
- data/lib/thinreports/report.rb +4 -6
- data/lib/thinreports/report/base.rb +24 -51
- data/lib/thinreports/report/internal.rb +9 -11
- data/lib/thinreports/report/page.rb +5 -6
- data/lib/thinreports/version.rb +2 -2
- data/test/schema_helper.rb +4 -3
- data/test/test_helper.rb +9 -3
- data/test/unit/core/format/test_base.rb +1 -1
- data/test/unit/core/shape/base/test_internal.rb +1 -1
- data/test/unit/core/shape/basic/test_block_format.rb +1 -1
- data/test/unit/core/shape/basic/test_block_interface.rb +1 -1
- data/test/unit/core/shape/basic/test_block_internal.rb +1 -1
- data/test/unit/core/shape/basic/test_format.rb +1 -1
- data/test/unit/core/shape/basic/test_interface.rb +1 -1
- data/test/unit/core/shape/basic/test_internal.rb +1 -1
- data/test/unit/core/shape/image_block/test_interface.rb +1 -1
- data/test/unit/core/shape/image_block/test_internal.rb +1 -1
- data/test/unit/core/shape/list/test_format.rb +1 -1
- data/test/unit/core/shape/list/test_manager.rb +4 -4
- data/test/unit/core/shape/list/test_page.rb +1 -1
- data/test/unit/core/shape/list/test_page_state.rb +1 -1
- data/test/unit/core/shape/list/test_section_format.rb +1 -1
- data/test/unit/core/shape/list/test_section_interface.rb +2 -2
- data/test/unit/core/shape/list/test_section_internal.rb +1 -1
- data/test/unit/core/shape/manager/test_format.rb +2 -2
- data/test/unit/core/shape/manager/test_internal.rb +3 -3
- data/test/unit/core/shape/manager/test_target.rb +1 -1
- data/test/unit/core/shape/page_number/test_format.rb +1 -1
- data/test/unit/core/shape/page_number/test_interface.rb +1 -1
- data/test/unit/core/shape/page_number/test_internal.rb +1 -1
- data/test/unit/core/shape/styles/test_base.rb +1 -1
- data/test/unit/core/shape/styles/test_basic.rb +1 -1
- data/test/unit/core/shape/styles/test_graphic.rb +1 -1
- data/test/unit/core/shape/styles/test_text.rb +1 -1
- data/test/unit/core/shape/text/test_format.rb +1 -1
- data/test/unit/core/shape/text/test_internal.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_number.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +2 -2
- data/test/unit/core/shape/text_block/test_format.rb +1 -1
- data/test/unit/core/shape/text_block/test_formatter.rb +1 -1
- data/test/unit/core/shape/text_block/test_interface.rb +1 -1
- data/test/unit/core/shape/text_block/test_internal.rb +3 -3
- data/test/unit/core/test_shape.rb +1 -1
- data/test/unit/core/test_utils.rb +2 -2
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +1 -1
- data/test/unit/generator/pdf/document/graphics/test_basic.rb +2 -1
- data/test/unit/generator/pdf/document/graphics/test_image.rb +27 -131
- data/test/unit/generator/pdf/document/graphics/test_text.rb +1 -1
- data/test/unit/generator/pdf/document/test_font.rb +2 -2
- data/test/unit/generator/pdf/document/test_graphics.rb +1 -1
- data/test/unit/generator/pdf/document/test_page.rb +7 -7
- data/test/unit/generator/pdf/document/test_parse_color.rb +1 -1
- data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +41 -0
- data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +22 -0
- data/test/unit/generator/pdf/test_document.rb +8 -6
- data/test/unit/generator/test_pdf.rb +12 -10
- data/test/unit/layout/test_base.rb +1 -1
- data/test/unit/layout/test_format.rb +2 -2
- data/test/unit/layout/test_legacy_schema.rb +4 -4
- data/test/unit/layout/test_version.rb +11 -80
- data/test/unit/report/test_base.rb +45 -59
- data/test/unit/report/test_internal.rb +1 -1
- data/test/unit/test_config.rb +1 -16
- data/test/unit/test_layout.rb +1 -1
- data/test/unit/test_report.rb +1 -1
- data/thinreports.gemspec +11 -14
- metadata +42 -103
- data/lib/thinreports/generator.rb +0 -29
- data/lib/thinreports/generator/base.rb +0 -40
- data/lib/thinreports/generator/configuration.rb +0 -31
- data/lib/thinreports/report/events.rb +0 -32
- data/test/unit/generator/test_base.rb +0 -40
- data/test/unit/generator/test_configuration.rb +0 -21
|
@@ -1,86 +1,85 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Thinreports
|
|
4
4
|
module Generator
|
|
5
|
+
class PDF
|
|
6
|
+
module Page
|
|
7
|
+
JIS_SIZES = {
|
|
8
|
+
'B4' => [728.5, 1031.8],
|
|
9
|
+
'B5' => [515.9, 728.5]
|
|
10
|
+
}.freeze
|
|
5
11
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
# @param [Thinreports::Layout::Format] format
|
|
13
|
+
# rubocop:disable Metrics/AbcSize
|
|
14
|
+
def start_new_page(format)
|
|
15
|
+
format_id =
|
|
16
|
+
if change_page_format?(format)
|
|
17
|
+
pdf.start_new_page(new_basic_page_options(format))
|
|
18
|
+
@current_page_format = format
|
|
12
19
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
unless format_stamp_registry.include?(format.identifier)
|
|
21
|
-
create_format_stamp(format)
|
|
20
|
+
unless format_stamp_registry.include?(format.identifier)
|
|
21
|
+
create_format_stamp(format)
|
|
22
|
+
end
|
|
23
|
+
format.identifier
|
|
24
|
+
else
|
|
25
|
+
pdf.start_new_page(new_basic_page_options(current_page_format))
|
|
26
|
+
current_page_format.identifier
|
|
22
27
|
end
|
|
23
|
-
format.identifier
|
|
24
|
-
else
|
|
25
|
-
pdf.start_new_page(new_basic_page_options(current_page_format))
|
|
26
|
-
current_page_format.identifier
|
|
27
|
-
end
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
stamp(format_id.to_s)
|
|
30
|
+
end
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
def add_blank_page
|
|
33
|
+
pdf.start_new_page(pdf.page_count.zero? ? { size: 'A4' } : {})
|
|
34
|
+
end
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
private
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
# @return [Thinreports::Layout::Format]
|
|
39
|
+
attr_reader :current_page_format
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
# @param [Thinreports::Layout::Format] new_format
|
|
42
|
+
# @return [Boolean]
|
|
43
|
+
def change_page_format?(new_format)
|
|
44
|
+
!current_page_format ||
|
|
45
|
+
current_page_format.identifier != new_format.identifier
|
|
46
|
+
end
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
# @param [Thinreports::Layout::Format] format
|
|
49
|
+
def create_format_stamp(format)
|
|
50
|
+
create_stamp(format.identifier.to_s) do
|
|
51
|
+
draw_template_items(format.attributes['items'])
|
|
52
|
+
end
|
|
53
|
+
format_stamp_registry << format.identifier
|
|
52
54
|
end
|
|
53
|
-
format_stamp_registry << format.identifier
|
|
54
|
-
end
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
# @return [Array]
|
|
57
|
+
def format_stamp_registry
|
|
58
|
+
@format_stamp_registry ||= []
|
|
59
|
+
end
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
# @param [Thinreports::Layout::Format] format
|
|
62
|
+
# @return [Hash]
|
|
63
|
+
def new_basic_page_options(format)
|
|
64
|
+
options = { layout: format.page_orientation.to_sym }
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
else
|
|
70
|
-
case format.page_paper_type
|
|
71
|
-
# Convert B4(5)_ISO to B4(5)
|
|
72
|
-
when 'B4_ISO', 'B5_ISO'
|
|
73
|
-
format.page_paper_type.delete('_ISO')
|
|
74
|
-
# Convert B4(5) to B4(5)_JIS
|
|
75
|
-
when 'B4', 'B5'
|
|
76
|
-
"#{format.page_paper_type}_JIS"
|
|
66
|
+
options[:size] =
|
|
67
|
+
if format.user_paper_type?
|
|
68
|
+
[format.page_width.to_f, format.page_height.to_f]
|
|
77
69
|
else
|
|
78
|
-
format.page_paper_type
|
|
70
|
+
case format.page_paper_type
|
|
71
|
+
# Convert B4(5)_ISO to B4(5)
|
|
72
|
+
when 'B4_ISO', 'B5_ISO'
|
|
73
|
+
format.page_paper_type.delete('_ISO')
|
|
74
|
+
when 'B4', 'B5'
|
|
75
|
+
JIS_SIZES[format.page_paper_type]
|
|
76
|
+
else
|
|
77
|
+
format.page_paper_type
|
|
78
|
+
end
|
|
79
79
|
end
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
options
|
|
81
|
+
end
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
|
-
|
|
85
84
|
end
|
|
86
85
|
end
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Thinreports
|
|
4
4
|
module Generator
|
|
5
|
+
class PDF
|
|
6
|
+
module ParseColor
|
|
7
|
+
# @param [String] color
|
|
8
|
+
# @return [String]
|
|
9
|
+
def parse_color(color)
|
|
10
|
+
color = color.downcase
|
|
5
11
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
unless color =~ /^#?[\da-f]{6}$/
|
|
13
|
-
find_color_from_name(color)
|
|
14
|
-
else
|
|
15
|
-
color.delete('#')
|
|
12
|
+
if color =~ /^#?[\da-f]{6}$/
|
|
13
|
+
color.delete('#')
|
|
14
|
+
else
|
|
15
|
+
find_color_from_name(color)
|
|
16
|
+
end
|
|
16
17
|
end
|
|
17
|
-
end
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
private
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
# Supported only SAFE COLORS.
|
|
22
|
+
SUPPORTED_COLOR_NAMES = {
|
|
23
|
+
'red' => 'ff0000',
|
|
24
|
+
'yellow' => 'fff000',
|
|
25
|
+
'lime' => '00ff00',
|
|
26
|
+
'aqua' => '00ffff',
|
|
27
|
+
'blue' => '0000ff',
|
|
28
|
+
'fuchsia' => 'ff00ff',
|
|
29
|
+
'maroon' => '800000',
|
|
30
|
+
'olive' => '808000',
|
|
31
|
+
'green' => '008800',
|
|
32
|
+
'teal' => '008080',
|
|
33
|
+
'navy' => '000080',
|
|
34
|
+
'purple' => '800080',
|
|
35
|
+
'black' => '000000',
|
|
36
|
+
'gray' => '808080',
|
|
37
|
+
'silver' => 'c0c0c0',
|
|
38
|
+
'white' => 'ffffff'
|
|
39
|
+
}.freeze
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
def find_color_from_name(name)
|
|
42
|
+
color = SUPPORTED_COLOR_NAMES[name]
|
|
43
|
+
raise Thinreports::Errors::UnsupportedColorName, name unless color
|
|
44
|
+
color
|
|
45
|
+
end
|
|
45
46
|
end
|
|
46
47
|
end
|
|
47
|
-
|
|
48
48
|
end
|
|
49
49
|
end
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Thinreports
|
|
4
|
-
module Generator
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
4
|
+
module Generator
|
|
5
|
+
class PDF
|
|
6
|
+
module Drawer
|
|
7
|
+
# @abstract
|
|
8
|
+
class Base
|
|
9
|
+
# @param [Thinreports::Generator::PDF::Document] pdf
|
|
10
|
+
# @param [Thinreports::Core::Shape::Manager::Format] format
|
|
11
|
+
def initialize(pdf, format)
|
|
12
|
+
@pdf = pdf
|
|
13
|
+
@format = format
|
|
14
|
+
@stamps = []
|
|
15
|
+
@draw_at = nil
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @abstract
|
|
19
|
+
def draw
|
|
20
|
+
raise NotImplementedError
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
# @param [Thinreports::Core::Shape::Base::Internal] shape
|
|
26
|
+
# @return [String]
|
|
27
|
+
def pdf_stamp_id(shape)
|
|
28
|
+
"#{@format.identifier}#{shape.identifier}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @overload pdf_stamp(shape_id)
|
|
32
|
+
# @param [String] shape_id
|
|
33
|
+
# @overload pdf_stamp(shape)
|
|
34
|
+
# @param [Thinreports::Core::Shape::Base::Internal] shape
|
|
35
|
+
def pdf_stamp(shape)
|
|
36
|
+
shape = pdf_stamp_id(shape) unless shape.is_a?(::String)
|
|
37
|
+
@pdf.stamp(shape, @draw_at)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @param [Thinreports::Core::Shape::Base::Internal] shape
|
|
41
|
+
def create_pdf_stamp(shape, &block)
|
|
42
|
+
@pdf.create_stamp(pdf_stamp_id(shape), &block)
|
|
43
|
+
end
|
|
37
44
|
end
|
|
38
|
-
@pdf.stamp(shape, @draw_at)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# @param [Thinreports::Core::Shape::Base::Internal] shape
|
|
42
|
-
def create_pdf_stamp(shape, &block)
|
|
43
|
-
@pdf.create_stamp(pdf_stamp_id(shape), &block)
|
|
44
45
|
end
|
|
45
46
|
end
|
|
46
|
-
|
|
47
47
|
end
|
|
48
48
|
end
|
|
@@ -1,61 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Thinreports
|
|
4
|
-
module Generator
|
|
4
|
+
module Generator
|
|
5
|
+
class PDF
|
|
6
|
+
module Drawer
|
|
7
|
+
class List < Base
|
|
8
|
+
# @param (see PDF::Drawer::Base#initialize)
|
|
9
|
+
def initialize(pdf, format)
|
|
10
|
+
super
|
|
11
|
+
@sections = {}
|
|
12
|
+
end
|
|
5
13
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
# @param [Thinreports::Core::Shape::List::PageState] list_page
|
|
15
|
+
# rubocop:disable Metrics/AbcSize
|
|
16
|
+
def draw(list_page)
|
|
17
|
+
draw_section(list_page.header) if list_page.header
|
|
18
|
+
list_page.rows.each do |row|
|
|
19
|
+
draw_section(row)
|
|
20
|
+
end
|
|
12
21
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
draw_section(list_page.header) if list_page.header
|
|
16
|
-
list_page.rows.each do |row|
|
|
17
|
-
draw_section(row)
|
|
18
|
-
end
|
|
22
|
+
# Returns Thinreports::Report::Page object
|
|
23
|
+
manager = list_page.parent.manager
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
list_id = list_page.id.to_s
|
|
26
|
+
manager.format.shapes.each do |id, shape|
|
|
27
|
+
next unless list_pageno?(list_id, shape)
|
|
22
28
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
shape = manager.final_shape(id)
|
|
30
|
+
@pdf.draw_shape_pageno(shape.internal,
|
|
31
|
+
list_page.no, list_page.manager.page_count)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
26
34
|
|
|
27
|
-
|
|
28
|
-
@pdf.draw_shape_pageno(shape.internal,
|
|
29
|
-
list_page.no, list_page.manager.page_count)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
35
|
+
private
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
# @param [String] list_id
|
|
38
|
+
# @param [Thinreports::Core::Shape::Base::Format] shape
|
|
39
|
+
# @return [Boolean]
|
|
40
|
+
def list_pageno?(list_id, shape)
|
|
41
|
+
shape.type == Thinreports::Core::Shape::PageNumber::TYPE_NAME &&
|
|
42
|
+
shape.target == list_id
|
|
43
|
+
end
|
|
34
44
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def list_pageno?(list_id, shape)
|
|
39
|
-
shape.type == Thinreports::Core::Shape::PageNumber::TYPE_NAME &&
|
|
40
|
-
shape.target == list_id
|
|
41
|
-
end
|
|
45
|
+
# @param [Thinreports::Core::Shape::List::SectionInterface] section
|
|
46
|
+
def draw_section(section)
|
|
47
|
+
internal = section.internal
|
|
42
48
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
internal = section.internal
|
|
49
|
+
base_top = @format.section_base_position_top(internal.section_name)
|
|
50
|
+
position = [internal.relative_left, base_top + internal.relative_top]
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
drawer(internal).draw(section, position)
|
|
53
|
+
end
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
@sections[section.section_name] ||= ListSection.new(@pdf, section)
|
|
55
|
+
# @param [Thinreports::Core::Shape::List::SectionInternal] section
|
|
56
|
+
# @return [Thinreports::Generator::PDF::Drawer::ListSection]
|
|
57
|
+
def drawer(section)
|
|
58
|
+
@sections[section.section_name] ||= ListSection.new(@pdf, section)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
57
61
|
end
|
|
58
62
|
end
|
|
59
|
-
|
|
60
63
|
end
|
|
61
64
|
end
|
|
@@ -1,47 +1,49 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Thinreports
|
|
4
|
-
module Generator
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
4
|
+
module Generator
|
|
5
|
+
class PDF
|
|
6
|
+
module Drawer
|
|
7
|
+
class ListSection < Page
|
|
8
|
+
# @param pdf (see PDF::Drawer::Page#initialize)
|
|
9
|
+
# @param section [Thinreports::Core::Shape::List::SectionInternal] section
|
|
10
|
+
def initialize(pdf, section)
|
|
11
|
+
super(pdf, section.format)
|
|
12
|
+
@section = section
|
|
13
|
+
@stamp_created = false
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @param [Thinreports::Core::Shape::List::SectionInternal] section
|
|
17
|
+
# @param [Array<Numeric>] at
|
|
18
|
+
def draw(section, at)
|
|
19
|
+
@draw_at = at
|
|
20
|
+
draw_section
|
|
21
|
+
super(section)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def draw_section
|
|
27
|
+
id = @format.identifier.to_s
|
|
28
|
+
|
|
29
|
+
unless @stamp_created
|
|
30
|
+
@pdf.create_stamp(id) { @pdf.draw_template_items(@format.attributes['items']) }
|
|
31
|
+
@stamp_created = true
|
|
32
|
+
end
|
|
33
|
+
pdf_stamp(id)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @see Thinreports::Generator::PDF::Drawer::Page#draw_tblock_shape
|
|
37
|
+
def draw_tblock_shape(shape)
|
|
38
|
+
@pdf.translate(*@draw_at) { super }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @see Thinreports::Generator::PDF::Drawer::Page#draw_iblock_shape
|
|
42
|
+
def draw_iblock_shape(shape)
|
|
43
|
+
@pdf.translate(*@draw_at) { super }
|
|
44
|
+
end
|
|
31
45
|
end
|
|
32
|
-
pdf_stamp(id)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# @see Thinreports::Generator::PDF::Drawer::Page#draw_tblock_shape
|
|
36
|
-
def draw_tblock_shape(shape)
|
|
37
|
-
@pdf.translate(*@draw_at) { super }
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# @see Thinreports::Generator::PDF::Drawer::Page#draw_iblock_shape
|
|
41
|
-
def draw_iblock_shape(shape)
|
|
42
|
-
@pdf.translate(*@draw_at) { super }
|
|
43
46
|
end
|
|
44
47
|
end
|
|
45
|
-
|
|
46
48
|
end
|
|
47
49
|
end
|