thinreports 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +3 -3
  3. data/.github/workflows/test.yml +28 -36
  4. data/.gitignore +1 -1
  5. data/CHANGELOG.md +19 -1
  6. data/Gemfile +11 -0
  7. data/README.md +12 -17
  8. data/Rakefile +17 -11
  9. data/lib/thinreports/basic_report/core/errors.rb +62 -0
  10. data/lib/thinreports/basic_report/core/format/base.rb +91 -0
  11. data/lib/thinreports/basic_report/core/shape/base/interface.rb +42 -0
  12. data/lib/thinreports/basic_report/core/shape/base/internal.rb +53 -0
  13. data/lib/thinreports/basic_report/core/shape/basic/block_format.rb +15 -0
  14. data/lib/thinreports/basic_report/core/shape/basic/block_interface.rb +34 -0
  15. data/lib/thinreports/basic_report/core/shape/basic/block_internal.rb +36 -0
  16. data/lib/thinreports/basic_report/core/shape/basic/format.rb +24 -0
  17. data/lib/thinreports/basic_report/core/shape/basic/interface.rb +87 -0
  18. data/lib/thinreports/basic_report/core/shape/basic/internal.rb +28 -0
  19. data/lib/thinreports/{core → basic_report/core}/shape/basic.rb +6 -4
  20. data/lib/thinreports/basic_report/core/shape/image_block/format.rb +14 -0
  21. data/lib/thinreports/basic_report/core/shape/image_block/interface.rb +25 -0
  22. data/lib/thinreports/basic_report/core/shape/image_block/internal.rb +19 -0
  23. data/lib/thinreports/{core → basic_report/core}/shape/image_block.rb +6 -4
  24. data/lib/thinreports/basic_report/core/shape/list/format.rb +92 -0
  25. data/lib/thinreports/basic_report/core/shape/list/manager.rb +231 -0
  26. data/lib/thinreports/basic_report/core/shape/list/page.rb +112 -0
  27. data/lib/thinreports/basic_report/core/shape/list/page_state.rb +50 -0
  28. data/lib/thinreports/basic_report/core/shape/list/section_format.rb +37 -0
  29. data/lib/thinreports/basic_report/core/shape/list/section_interface.rb +51 -0
  30. data/lib/thinreports/basic_report/core/shape/list/section_internal.rb +33 -0
  31. data/lib/thinreports/{core → basic_report/core}/shape/list.rb +6 -4
  32. data/lib/thinreports/basic_report/core/shape/manager/format.rb +33 -0
  33. data/lib/thinreports/basic_report/core/shape/manager/internal.rb +109 -0
  34. data/lib/thinreports/basic_report/core/shape/manager/target.rb +114 -0
  35. data/lib/thinreports/basic_report/core/shape/page_number/format.rb +32 -0
  36. data/lib/thinreports/basic_report/core/shape/page_number/interface.rb +31 -0
  37. data/lib/thinreports/basic_report/core/shape/page_number/internal.rb +57 -0
  38. data/lib/thinreports/{core → basic_report/core}/shape/page_number.rb +6 -4
  39. data/lib/thinreports/basic_report/core/shape/stack_view/format.rb +29 -0
  40. data/lib/thinreports/basic_report/core/shape/stack_view/interface.rb +19 -0
  41. data/lib/thinreports/basic_report/core/shape/stack_view/internal.rb +24 -0
  42. data/lib/thinreports/basic_report/core/shape/stack_view/row_format.rb +41 -0
  43. data/lib/thinreports/{core → basic_report/core}/shape/stack_view.rb +6 -4
  44. data/lib/thinreports/basic_report/core/shape/style/base.rb +149 -0
  45. data/lib/thinreports/basic_report/core/shape/style/basic.rb +24 -0
  46. data/lib/thinreports/basic_report/core/shape/style/graphic.rb +43 -0
  47. data/lib/thinreports/basic_report/core/shape/style/text.rb +122 -0
  48. data/lib/thinreports/basic_report/core/shape/text/format.rb +17 -0
  49. data/lib/thinreports/basic_report/core/shape/text/interface.rb +20 -0
  50. data/lib/thinreports/basic_report/core/shape/text/internal.rb +24 -0
  51. data/lib/thinreports/{core → basic_report/core}/shape/text.rb +6 -4
  52. data/lib/thinreports/basic_report/core/shape/text_block/format.rb +43 -0
  53. data/lib/thinreports/basic_report/core/shape/text_block/formatter/basic.rb +41 -0
  54. data/lib/thinreports/basic_report/core/shape/text_block/formatter/datetime.rb +25 -0
  55. data/lib/thinreports/basic_report/core/shape/text_block/formatter/number.rb +69 -0
  56. data/lib/thinreports/basic_report/core/shape/text_block/formatter/padding.rb +27 -0
  57. data/lib/thinreports/basic_report/core/shape/text_block/formatter.rb +38 -0
  58. data/lib/thinreports/basic_report/core/shape/text_block/interface.rb +37 -0
  59. data/lib/thinreports/basic_report/core/shape/text_block/internal.rb +75 -0
  60. data/lib/thinreports/{core → basic_report/core}/shape/text_block.rb +6 -4
  61. data/lib/thinreports/basic_report/core/shape.rb +44 -0
  62. data/lib/thinreports/basic_report/core/utils.rb +47 -0
  63. data/lib/thinreports/basic_report/generator/pdf/document/draw_shape.rb +108 -0
  64. data/lib/thinreports/basic_report/generator/pdf/document/draw_template_items.rb +71 -0
  65. data/lib/thinreports/basic_report/generator/pdf/document/font.rb +90 -0
  66. data/lib/thinreports/basic_report/generator/pdf/document/graphics/attributes.rb +149 -0
  67. data/lib/thinreports/basic_report/generator/pdf/document/graphics/basic.rb +137 -0
  68. data/lib/thinreports/basic_report/generator/pdf/document/graphics/image.rb +99 -0
  69. data/lib/thinreports/basic_report/generator/pdf/document/graphics/text.rb +180 -0
  70. data/lib/thinreports/basic_report/generator/pdf/document/graphics.rb +42 -0
  71. data/lib/thinreports/basic_report/generator/pdf/document/page.rb +96 -0
  72. data/lib/thinreports/basic_report/generator/pdf/document/parse_color.rb +51 -0
  73. data/lib/thinreports/basic_report/generator/pdf/document.rb +132 -0
  74. data/lib/thinreports/basic_report/generator/pdf/drawer/base.rb +50 -0
  75. data/lib/thinreports/basic_report/generator/pdf/drawer/list.rb +65 -0
  76. data/lib/thinreports/basic_report/generator/pdf/drawer/list_section.rb +51 -0
  77. data/lib/thinreports/basic_report/generator/pdf/drawer/page.rb +127 -0
  78. data/lib/thinreports/basic_report/generator/pdf/prawn_ext/calc_image_dimensions.rb +34 -0
  79. data/lib/thinreports/basic_report/generator/pdf/prawn_ext/width_of.rb +31 -0
  80. data/lib/thinreports/basic_report/generator/pdf.rb +66 -0
  81. data/lib/thinreports/basic_report/layout/base.rb +48 -0
  82. data/lib/thinreports/basic_report/layout/format.rb +67 -0
  83. data/lib/thinreports/basic_report/layout/legacy_schema.rb +383 -0
  84. data/lib/thinreports/basic_report/layout/version.rb +41 -0
  85. data/lib/thinreports/{layout.rb → basic_report/layout.rb} +6 -4
  86. data/lib/thinreports/basic_report/report/base.rb +173 -0
  87. data/lib/thinreports/basic_report/report/internal.rb +107 -0
  88. data/lib/thinreports/basic_report/report/page.rb +97 -0
  89. data/lib/thinreports/basic_report/report.rb +26 -0
  90. data/lib/thinreports/basic_report.rb +15 -0
  91. data/lib/thinreports/config.rb +1 -1
  92. data/lib/thinreports/section_report.rb +12 -0
  93. data/lib/thinreports/version.rb +1 -1
  94. data/lib/thinreports.rb +2 -13
  95. data/thinreports.gemspec +3 -7
  96. metadata +97 -154
  97. data/gemfiles/prawn-2.2.gemfile +0 -5
  98. data/gemfiles/prawn-2.3.gemfile +0 -5
  99. data/gemfiles/prawn-2.4.gemfile +0 -5
  100. data/lib/thinreports/core/errors.rb +0 -60
  101. data/lib/thinreports/core/format/base.rb +0 -89
  102. data/lib/thinreports/core/shape/base/interface.rb +0 -40
  103. data/lib/thinreports/core/shape/base/internal.rb +0 -51
  104. data/lib/thinreports/core/shape/basic/block_format.rb +0 -13
  105. data/lib/thinreports/core/shape/basic/block_interface.rb +0 -32
  106. data/lib/thinreports/core/shape/basic/block_internal.rb +0 -34
  107. data/lib/thinreports/core/shape/basic/format.rb +0 -22
  108. data/lib/thinreports/core/shape/basic/interface.rb +0 -85
  109. data/lib/thinreports/core/shape/basic/internal.rb +0 -26
  110. data/lib/thinreports/core/shape/image_block/format.rb +0 -12
  111. data/lib/thinreports/core/shape/image_block/interface.rb +0 -23
  112. data/lib/thinreports/core/shape/image_block/internal.rb +0 -17
  113. data/lib/thinreports/core/shape/list/format.rb +0 -90
  114. data/lib/thinreports/core/shape/list/manager.rb +0 -229
  115. data/lib/thinreports/core/shape/list/page.rb +0 -110
  116. data/lib/thinreports/core/shape/list/page_state.rb +0 -48
  117. data/lib/thinreports/core/shape/list/section_format.rb +0 -35
  118. data/lib/thinreports/core/shape/list/section_interface.rb +0 -49
  119. data/lib/thinreports/core/shape/list/section_internal.rb +0 -31
  120. data/lib/thinreports/core/shape/manager/format.rb +0 -31
  121. data/lib/thinreports/core/shape/manager/internal.rb +0 -107
  122. data/lib/thinreports/core/shape/manager/target.rb +0 -112
  123. data/lib/thinreports/core/shape/page_number/format.rb +0 -30
  124. data/lib/thinreports/core/shape/page_number/interface.rb +0 -29
  125. data/lib/thinreports/core/shape/page_number/internal.rb +0 -55
  126. data/lib/thinreports/core/shape/stack_view/format.rb +0 -27
  127. data/lib/thinreports/core/shape/stack_view/interface.rb +0 -17
  128. data/lib/thinreports/core/shape/stack_view/internal.rb +0 -22
  129. data/lib/thinreports/core/shape/stack_view/row_format.rb +0 -39
  130. data/lib/thinreports/core/shape/style/base.rb +0 -146
  131. data/lib/thinreports/core/shape/style/basic.rb +0 -22
  132. data/lib/thinreports/core/shape/style/graphic.rb +0 -41
  133. data/lib/thinreports/core/shape/style/text.rb +0 -120
  134. data/lib/thinreports/core/shape/text/format.rb +0 -15
  135. data/lib/thinreports/core/shape/text/interface.rb +0 -18
  136. data/lib/thinreports/core/shape/text/internal.rb +0 -22
  137. data/lib/thinreports/core/shape/text_block/format.rb +0 -41
  138. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +0 -39
  139. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +0 -23
  140. data/lib/thinreports/core/shape/text_block/formatter/number.rb +0 -67
  141. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +0 -25
  142. data/lib/thinreports/core/shape/text_block/formatter.rb +0 -34
  143. data/lib/thinreports/core/shape/text_block/interface.rb +0 -35
  144. data/lib/thinreports/core/shape/text_block/internal.rb +0 -73
  145. data/lib/thinreports/core/shape.rb +0 -42
  146. data/lib/thinreports/core/utils.rb +0 -45
  147. data/lib/thinreports/generate.rb +0 -11
  148. data/lib/thinreports/generator/pdf/document/draw_shape.rb +0 -106
  149. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +0 -69
  150. data/lib/thinreports/generator/pdf/document/font.rb +0 -88
  151. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +0 -147
  152. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +0 -135
  153. data/lib/thinreports/generator/pdf/document/graphics/image.rb +0 -98
  154. data/lib/thinreports/generator/pdf/document/graphics/text.rb +0 -178
  155. data/lib/thinreports/generator/pdf/document/graphics.rb +0 -40
  156. data/lib/thinreports/generator/pdf/document/page.rb +0 -94
  157. data/lib/thinreports/generator/pdf/document/parse_color.rb +0 -49
  158. data/lib/thinreports/generator/pdf/document.rb +0 -130
  159. data/lib/thinreports/generator/pdf/drawer/base.rb +0 -48
  160. data/lib/thinreports/generator/pdf/drawer/list.rb +0 -63
  161. data/lib/thinreports/generator/pdf/drawer/list_section.rb +0 -49
  162. data/lib/thinreports/generator/pdf/drawer/page.rb +0 -125
  163. data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +0 -32
  164. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +0 -29
  165. data/lib/thinreports/generator/pdf.rb +0 -63
  166. data/lib/thinreports/layout/base.rb +0 -46
  167. data/lib/thinreports/layout/format.rb +0 -65
  168. data/lib/thinreports/layout/legacy_schema.rb +0 -381
  169. data/lib/thinreports/layout/version.rb +0 -39
  170. data/lib/thinreports/report/base.rb +0 -169
  171. data/lib/thinreports/report/internal.rb +0 -105
  172. data/lib/thinreports/report/page.rb +0 -95
  173. data/lib/thinreports/report.rb +0 -24
  174. /data/lib/thinreports/{core → basic_report/core}/shape/base.rb +0 -0
  175. /data/lib/thinreports/{core → basic_report/core}/shape/manager.rb +0 -0
  176. /data/lib/thinreports/{core → basic_report/core}/shape/style.rb +0 -0
  177. /data/lib/thinreports/{generator → basic_report/generator}/pdf/prawn_ext.rb +0 -0
@@ -1,94 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
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
11
-
12
- # @param [Thinreports::Layout::Format] format
13
- def start_new_page(format)
14
- format_id =
15
- if change_page_format?(format)
16
- pdf.start_new_page(new_basic_page_options(format))
17
- @current_page_format = format
18
-
19
- create_format_stamp(format) unless format_stamp_registry.include?(format.identifier)
20
- format.identifier
21
- else
22
- pdf.start_new_page(new_basic_page_options(current_page_format))
23
- current_page_format.identifier
24
- end
25
-
26
- stamp(format_id.to_s)
27
- end
28
-
29
- def start_new_page_for_section_report(format)
30
- @current_page_format = format
31
- pdf.start_new_page(new_basic_page_options(current_page_format).merge(
32
- top_margin: current_page_format.page_margin[0],
33
- bottom_margin: current_page_format.page_margin[2]
34
- ))
35
- end
36
-
37
- def max_content_height
38
- pdf.margin_box.height
39
- end
40
-
41
- def add_blank_page
42
- pdf.start_new_page(pdf.page_count.zero? ? { size: 'A4' } : {})
43
- end
44
-
45
- private
46
-
47
- # @return [Thinreports::Layout::Format]
48
- attr_reader :current_page_format
49
-
50
- # @param [Thinreports::Layout::Format] new_format
51
- # @return [Boolean]
52
- def change_page_format?(new_format)
53
- !current_page_format ||
54
- current_page_format.identifier != new_format.identifier
55
- end
56
-
57
- # @param [Thinreports::Layout::Format] format
58
- def create_format_stamp(format)
59
- create_stamp(format.identifier.to_s) do
60
- draw_template_items(format.attributes['items'])
61
- end
62
- format_stamp_registry << format.identifier
63
- end
64
-
65
- # @return [Array]
66
- def format_stamp_registry
67
- @format_stamp_registry ||= []
68
- end
69
-
70
- # @param [Thinreports::Layout::Format] format
71
- # @return [Hash]
72
- def new_basic_page_options(format)
73
- options = { layout: format.page_orientation.to_sym }
74
-
75
- options[:size] =
76
- if format.user_paper_type?
77
- [format.page_width.to_f, format.page_height.to_f]
78
- else
79
- case format.page_paper_type
80
- # Convert B4(5)_ISO to B4(5)
81
- when 'B4_ISO', 'B5_ISO'
82
- format.page_paper_type.delete('_ISO')
83
- when 'B4', 'B5'
84
- JIS_SIZES[format.page_paper_type]
85
- else
86
- format.page_paper_type
87
- end
88
- end
89
- options
90
- end
91
- end
92
- end
93
- end
94
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
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
11
-
12
- if color =~ /^#?[\da-f]{6}$/
13
- color.delete('#')
14
- else
15
- find_color_from_name(color)
16
- end
17
- end
18
-
19
- private
20
-
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
-
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
46
- end
47
- end
48
- end
49
- end
@@ -1,130 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'document/font'
4
- require_relative 'document/parse_color'
5
- require_relative 'document/graphics'
6
- require_relative 'document/draw_shape'
7
- require_relative 'document/draw_template_items'
8
- require_relative 'document/page'
9
-
10
- module Thinreports
11
- module Generator
12
- class PDF
13
- class Document
14
- include Utils
15
-
16
- include PDF::Font
17
- include PDF::ParseColor
18
- include PDF::Graphics
19
- include PDF::DrawShape
20
- include PDF::DrawTemplateItems
21
- include PDF::Page
22
-
23
- # @return [Prawn::Document]
24
- attr_reader :pdf
25
-
26
- # @param [String] title (nil)
27
- # @param [Hash] security (nil)
28
- def initialize(title: nil, security: nil)
29
- @pdf = Prawn::Document.new(
30
- skip_page_creation: true,
31
- margin: [0, 0],
32
- info: {
33
- CreationDate: Time.now,
34
- Creator: 'Thinreports Generator for Ruby ' + Thinreports::VERSION,
35
- Title: title
36
- }
37
- )
38
- # Setup to Prawn::Document.
39
- setup_fonts
40
- setup_custom_graphic_states
41
-
42
- # Encrypts the document.
43
- @pdf.encrypt_document(security) if security
44
- end
45
-
46
- # Delegate to Prawn::Document#render
47
- # @see Prawn::Document#render
48
- def render
49
- result = pdf.render
50
- finalize
51
- result
52
- end
53
-
54
- # Delegate to Prawn::Document#render_file
55
- # @see Prawn::Document#render_file
56
- def render_file(*args)
57
- finalize
58
- pdf.render_file(*args)
59
- end
60
-
61
- # @param [Numeric, String] x
62
- # @param [Numeric, String] y
63
- def translate(x, y, &block)
64
- x, y = rpos(x, y)
65
- pdf.translate(x, y, &block)
66
- end
67
-
68
- # @param [String] stamp_id
69
- # @param [Array<Numeric>] at (nil)
70
- def stamp(stamp_id, at = nil)
71
- if at.nil?
72
- pdf.stamp(stamp_id)
73
- else
74
- pdf.stamp_at(stamp_id, rpos(*at))
75
- end
76
- end
77
-
78
- # Delegate to Prawn::Document#create_stamp
79
- # @param [String] id
80
- # @see Prawn::Document#create_stamp
81
- def create_stamp(id, &block)
82
- pdf.create_stamp(id, &block)
83
- end
84
-
85
- # @see #pdf
86
- def internal
87
- @pdf
88
- end
89
-
90
- private
91
-
92
- def finalize
93
- clean_temp_images
94
- end
95
-
96
- # @param [Array<String, Numeric>] values
97
- # @return [Numeric, Array<Numeric>, nil]
98
- def s2f(*values)
99
- return nil if values.empty?
100
-
101
- if values.size == 1
102
- value = values.first
103
- return nil unless value
104
- value.is_a?(::Numeric) ? value : value.to_f
105
- else
106
- values.map { |v| s2f(v) }
107
- end
108
- end
109
-
110
- # @param [Numeric, String] x
111
- # @param [Numeric, String] y
112
- # @return [Array<Float>]
113
- def map_to_upper_left_relative_position(x, y)
114
- x, y = s2f(x, y)
115
- [x, -y]
116
- end
117
- alias rpos map_to_upper_left_relative_position
118
-
119
- # @param [Numeric, String] x
120
- # @param [Numeric, String] y
121
- # @return [Array<Float>]
122
- def map_to_upper_left_position(x, y)
123
- x, y = s2f(x, y)
124
- [x, pdf.bounds.height - y]
125
- end
126
- alias pos map_to_upper_left_position
127
- end
128
- end
129
- end
130
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
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
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
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
13
-
14
- # @param [Thinreports::Core::Shape::List::PageState] list_page
15
- def draw(list_page)
16
- draw_section(list_page.header) if list_page.header
17
- list_page.rows.each do |row|
18
- draw_section(row)
19
- end
20
-
21
- # Returns Thinreports::Report::Page object
22
- manager = list_page.parent.manager
23
-
24
- list_id = list_page.id.to_s
25
- manager.format.shapes.each do |id, shape|
26
- next unless list_pageno?(list_id, shape)
27
-
28
- shape = manager.final_shape(id)
29
- @pdf.draw_shape_pageno(shape.internal,
30
- list_page.no, list_page.manager.page_count)
31
- end
32
- end
33
-
34
- private
35
-
36
- # @param [String] list_id
37
- # @param [Thinreports::Core::Shape::Base::Format] shape
38
- # @return [Boolean]
39
- def list_pageno?(list_id, shape)
40
- shape.type == Thinreports::Core::Shape::PageNumber::TYPE_NAME &&
41
- shape.target == list_id
42
- end
43
-
44
- # @param [Thinreports::Core::Shape::List::SectionInterface] section
45
- def draw_section(section)
46
- internal = section.internal
47
-
48
- base_top = @format.section_base_position_top(internal.section_name)
49
- position = [internal.relative_left, base_top + internal.relative_top]
50
-
51
- drawer(internal).draw(section, position)
52
- end
53
-
54
- # @param [Thinreports::Core::Shape::List::SectionInternal] section
55
- # @return [Thinreports::Generator::PDF::Drawer::ListSection]
56
- def drawer(section)
57
- @sections[section.section_name] ||= ListSection.new(@pdf, section)
58
- end
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
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
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,125 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Generator
5
- class PDF
6
- module Drawer
7
- class Page < Base
8
- # @param (see PDF::Drawer::Base#initialize)
9
- def initialize(pdf, format)
10
- super
11
- @lists = {}
12
- end
13
-
14
- # @param [Thinreports::Report::Page] page
15
- def draw(page)
16
- manager = page.manager
17
-
18
- manager.format.shapes.each_key do |id|
19
- shape = manager.final_shape(id)
20
- next unless shape
21
-
22
- shape = shape.internal
23
-
24
- if shape.type_of?(Core::Shape::PageNumber::TYPE_NAME)
25
- # Do not draw pageno if is not for Report
26
- draw_pageno_shape(shape, page) if page.count? && shape.for_report?
27
- else
28
- draw_shape(shape)
29
- end
30
- end
31
- end
32
-
33
- private
34
-
35
- def draw_shape(shape)
36
- if shape.type_of?(Core::Shape::TextBlock::TYPE_NAME)
37
- draw_tblock_shape(shape)
38
- elsif shape.type_of?(Core::Shape::List::TYPE_NAME)
39
- draw_list_shape(shape)
40
- elsif shape.type_of?(Core::Shape::ImageBlock::TYPE_NAME)
41
- draw_iblock_shape(shape)
42
- else
43
- id = shape.identifier
44
- unless @stamps.include?(id)
45
- create_basic_shape_stamp(shape)
46
- @stamps << id
47
- end
48
- pdf_stamp(shape)
49
- end
50
- end
51
-
52
- def draw_pageno_shape(shape, page)
53
- @pdf.draw_shape_pageno(shape, page.no, page.report.page_count)
54
- end
55
-
56
- # @see #draw_shape
57
- def draw_list_shape(shape)
58
- drawer = @lists[shape.id] ||= List.new(@pdf, shape.format)
59
- drawer.draw(shape)
60
- end
61
-
62
- # @see #draw_shape
63
- def draw_tblock_shape(shape)
64
- @pdf.draw_shape_tblock(shape)
65
- end
66
-
67
- # @see #draw_shape
68
- def draw_iblock_shape(shape)
69
- @pdf.draw_shape_iblock(shape)
70
- end
71
-
72
- # @param [Thinreports::Core::Shape::Base::Internal] shape
73
- def create_basic_shape_stamp(shape)
74
- if shape.type_of?('text')
75
- create_text_stamp(shape)
76
- elsif shape.type_of?('image')
77
- create_image_stamp(shape)
78
- elsif shape.type_of?('ellipse')
79
- create_ellipse_stamp(shape)
80
- elsif shape.type_of?('rect')
81
- create_rect_stamp(shape)
82
- elsif shape.type_of?('line')
83
- create_line_stamp(shape)
84
- end
85
- end
86
-
87
- # @see #create_basic_shape_stamp
88
- def create_image_stamp(shape)
89
- create_pdf_stamp(shape) do
90
- @pdf.draw_shape_image(shape)
91
- end
92
- end
93
-
94
- # @see #create_basic_shape_stamp
95
- def create_rect_stamp(shape)
96
- create_pdf_stamp(shape) do
97
- @pdf.draw_shape_rect(shape)
98
- end
99
- end
100
-
101
- # @see #create_basic_shape_stamp
102
- def create_ellipse_stamp(shape)
103
- create_pdf_stamp(shape) do
104
- @pdf.draw_shape_ellipse(shape)
105
- end
106
- end
107
-
108
- # @see #create_basic_shape_stamp
109
- def create_line_stamp(shape)
110
- create_pdf_stamp(shape) do
111
- @pdf.draw_shape_line(shape)
112
- end
113
- end
114
-
115
- # @see #create_basic_shape_stamp
116
- def create_text_stamp(shape)
117
- create_pdf_stamp(shape) do
118
- @pdf.draw_shape_text(shape)
119
- end
120
- end
121
- end
122
- end
123
- end
124
- end
125
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Generator
5
- module PrawnExt
6
- module CalcImageDimensions
7
- # Implement :auto_fit option for image size calculation.
8
- #
9
- # When the image is larger than the box, the original: fit option does not change
10
- # the image size. The :auto_fit option changes the image size to fit in the box
11
- # while maintaining the aspect ratio.
12
- #
13
- # Usage:
14
- # image '/path/to/image.png', at: [100, 100], auto_fit: [100, 100]
15
- #
16
- def calc_image_dimensions(options)
17
- if options[:auto_fit]
18
- image_width = options[:width] || width
19
- image_height = options[:height] || height
20
-
21
- box_width, box_height = options.delete(:auto_fit)
22
-
23
- options[:fit] = [box_width, box_height] if image_width > box_width || image_height > box_height
24
- end
25
- super(options)
26
- end
27
- end
28
- end
29
- end
30
- end
31
-
32
- Prawn::Images::Image.prepend Thinreports::Generator::PrawnExt::CalcImageDimensions
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Generator
5
- module PrawnExt
6
- module WidthOf
7
- # This patch fixes the character_spacing effect on text width calculation.
8
- #
9
- # The original #width_of:
10
- #
11
- # width_of('abcd') #=> 4 + 4 = 8
12
- #
13
- # The #width_of in this patch:
14
- #
15
- # width_of('abcd') #=> 4 + 3 = 7
16
- #
17
- def width_of(*)
18
- width = super - character_spacing
19
- width > 0 ? width : 0
20
- end
21
- end
22
- end
23
- end
24
- end
25
-
26
- # Prawn v2.3 and later includes this patch by https://github.com/prawnpdf/prawn/pull/1117.
27
- if Prawn::VERSION < '2.3.0'
28
- Prawn::Document.prepend Thinreports::Generator::PrawnExt::WidthOf
29
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'prawn'
4
-
5
- module Thinreports
6
- module Generator
7
- class PDF
8
- # @return [Thinreports::Report::Base]
9
- attr_reader :report
10
-
11
- # @param [Thinreports::Report::Base] report
12
- # @param [Hash] security (nil)
13
- def initialize(report, security: nil)
14
- report.finalize
15
-
16
- @report = report.internal
17
- title = default_layout ? default_layout.format.report_title : nil
18
-
19
- @document = Document.new(title: title, security: security)
20
- @drawers = {}
21
- end
22
-
23
- # @param [String, nil] filename
24
- # @return [String, nil]
25
- def generate(filename = nil)
26
- draw_report
27
- filename ? @document.render_file(filename) : @document.render
28
- end
29
-
30
- def default_layout
31
- report.default_layout
32
- end
33
-
34
- private
35
-
36
- def draw_report
37
- report.pages.each do |page|
38
- draw_page(page)
39
- end
40
- end
41
-
42
- def draw_page(page)
43
- return @document.add_blank_page if page.blank?
44
-
45
- format = page.layout.format
46
- @document.start_new_page(format)
47
-
48
- drawer(format).draw(page)
49
- end
50
-
51
- def drawer(format)
52
- @drawers[format.identifier] ||= Drawer::Page.new(@document, format)
53
- end
54
- end
55
- end
56
- end
57
-
58
- require_relative 'pdf/prawn_ext'
59
- require_relative 'pdf/document'
60
- require_relative 'pdf/drawer/base'
61
- require_relative 'pdf/drawer/page'
62
- require_relative 'pdf/drawer/list'
63
- require_relative 'pdf/drawer/list_section'