thinreports 0.10.0 → 0.12.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.
Files changed (191) hide show
  1. checksums.yaml +5 -5
  2. data/.github/CONTRIBUTING.md +2 -2
  3. data/.github/workflows/test.yml +51 -0
  4. data/.gitignore +1 -0
  5. data/CHANGELOG.md +49 -0
  6. data/Dockerfile +12 -0
  7. data/Gemfile +2 -1
  8. data/README.md +46 -21
  9. data/Rakefile +13 -29
  10. data/gemfiles/prawn-2.2.gemfile +5 -0
  11. data/gemfiles/prawn-2.3.gemfile +5 -0
  12. data/gemfiles/prawn-2.4.gemfile +5 -0
  13. data/lib/thinreports.rb +5 -0
  14. data/lib/thinreports/core/shape.rb +4 -3
  15. data/lib/thinreports/core/shape/base/interface.rb +0 -1
  16. data/lib/thinreports/core/shape/basic/format.rb +5 -0
  17. data/lib/thinreports/core/shape/image_block.rb +1 -1
  18. data/lib/thinreports/core/shape/list.rb +1 -1
  19. data/lib/thinreports/core/shape/list/manager.rb +1 -4
  20. data/lib/thinreports/core/shape/list/page.rb +2 -5
  21. data/lib/thinreports/core/shape/manager/internal.rb +0 -1
  22. data/lib/thinreports/core/shape/page_number.rb +1 -1
  23. data/lib/thinreports/core/shape/page_number/internal.rb +0 -1
  24. data/lib/thinreports/core/shape/stack_view.rb +17 -0
  25. data/lib/thinreports/core/shape/stack_view/format.rb +27 -0
  26. data/lib/thinreports/core/shape/stack_view/interface.rb +17 -0
  27. data/lib/thinreports/core/shape/stack_view/internal.rb +22 -0
  28. data/lib/thinreports/core/shape/stack_view/row_format.rb +39 -0
  29. data/lib/thinreports/core/shape/style/basic.rb +4 -1
  30. data/lib/thinreports/core/shape/text.rb +1 -1
  31. data/lib/thinreports/core/shape/text_block.rb +1 -1
  32. data/lib/thinreports/core/shape/text_block/formatter/number.rb +21 -9
  33. data/lib/thinreports/core/shape/text_block/internal.rb +0 -2
  34. data/lib/thinreports/core/utils.rb +6 -3
  35. data/lib/thinreports/generate.rb +11 -0
  36. data/lib/thinreports/generator/pdf/document/draw_shape.rb +31 -11
  37. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +1 -2
  38. data/lib/thinreports/generator/pdf/document/font.rb +16 -10
  39. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +0 -1
  40. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +0 -1
  41. data/lib/thinreports/generator/pdf/document/graphics/image.rb +19 -1
  42. data/lib/thinreports/generator/pdf/document/graphics/text.rb +10 -8
  43. data/lib/thinreports/generator/pdf/document/page.rb +13 -4
  44. data/lib/thinreports/generator/pdf/drawer/list.rb +0 -1
  45. data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +1 -3
  46. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +7 -7
  47. data/lib/thinreports/layout/base.rb +2 -4
  48. data/lib/thinreports/layout/format.rb +0 -1
  49. data/lib/thinreports/layout/legacy_schema.rb +2 -6
  50. data/lib/thinreports/layout/version.rb +1 -1
  51. data/lib/thinreports/report/internal.rb +4 -4
  52. data/lib/thinreports/report/page.rb +2 -7
  53. data/lib/thinreports/section_report/build.rb +32 -0
  54. data/lib/thinreports/section_report/builder/item_builder.rb +49 -0
  55. data/lib/thinreports/section_report/builder/report_builder.rb +82 -0
  56. data/lib/thinreports/section_report/builder/report_data.rb +13 -0
  57. data/lib/thinreports/section_report/builder/stack_view_builder.rb +55 -0
  58. data/lib/thinreports/section_report/builder/stack_view_data.rb +11 -0
  59. data/lib/thinreports/section_report/generate.rb +26 -0
  60. data/lib/thinreports/section_report/pdf/render.rb +23 -0
  61. data/lib/thinreports/section_report/pdf/renderer/draw_item.rb +68 -0
  62. data/lib/thinreports/section_report/pdf/renderer/group_renderer.rb +57 -0
  63. data/lib/thinreports/section_report/pdf/renderer/headers_renderer.rb +24 -0
  64. data/lib/thinreports/section_report/pdf/renderer/section_height.rb +100 -0
  65. data/lib/thinreports/section_report/pdf/renderer/section_renderer.rb +39 -0
  66. data/lib/thinreports/section_report/pdf/renderer/stack_view_renderer.rb +55 -0
  67. data/lib/thinreports/section_report/pdf/renderer/stack_view_row_renderer.rb +38 -0
  68. data/lib/thinreports/section_report/schema/loader.rb +28 -0
  69. data/lib/thinreports/section_report/schema/parser.rb +52 -0
  70. data/lib/thinreports/section_report/schema/report.rb +30 -0
  71. data/lib/thinreports/section_report/schema/section.rb +47 -0
  72. data/lib/thinreports/version.rb +1 -1
  73. data/thinreports.gemspec +11 -11
  74. metadata +48 -164
  75. data/.rubocop.yml +0 -41
  76. data/.travis.yml +0 -17
  77. data/examples/character_spacing/character_spacing.rb +0 -8
  78. data/examples/character_spacing/character_spacing.tlf +0 -293
  79. data/examples/dynamic_image/dynamic_image.rb +0 -31
  80. data/examples/dynamic_image/dynamic_image.tlf +0 -661
  81. data/examples/dynamic_image/img200x100.png +0 -0
  82. data/examples/dynamic_image/img50x50.png +0 -0
  83. data/examples/dynamic_style/dynamic_style.rb +0 -150
  84. data/examples/dynamic_style/dynamic_style.tlf +0 -1835
  85. data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
  86. data/examples/dynamic_style/image.png +0 -0
  87. data/examples/eudc/eudc.rb +0 -20
  88. data/examples/eudc/eudc.tlf +0 -180
  89. data/examples/eudc/eudc.ttf +0 -0
  90. data/examples/helper.rb +0 -50
  91. data/examples/hidden_shapes/hidden_shapes.rb +0 -9
  92. data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
  93. data/examples/list_events/list_events.rb +0 -32
  94. data/examples/list_events/list_events.tlf +0 -361
  95. data/examples/list_manual_generation/list_manual_generation.rb +0 -22
  96. data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
  97. data/examples/list_page_number/list_page_number.rb +0 -17
  98. data/examples/list_page_number/list_page_number.tlf +0 -254
  99. data/examples/page_number/page_number.rb +0 -33
  100. data/examples/page_number/page_number.tlf +0 -215
  101. data/examples/palleted_png/palleted_png.png +0 -0
  102. data/examples/palleted_png/palleted_png.rb +0 -9
  103. data/examples/palleted_png/palleted_png.tlf +0 -47
  104. data/examples/password_setting/password_setting.rb +0 -10
  105. data/examples/password_setting/password_setting.tlf +0 -45
  106. data/examples/report_callbacks/report_callbacks.rb +0 -14
  107. data/examples/report_callbacks/report_callbacks.tlf +0 -147
  108. data/examples/single_line_tblock/single_line_tblock.rb +0 -13
  109. data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
  110. data/examples/tblock_overflow/tblock_overflow.rb +0 -20
  111. data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
  112. data/examples/tblock_styles/font_size.tlf +0 -383
  113. data/examples/tblock_styles/tblock_styles.rb +0 -43
  114. data/examples/tblock_styles/tblock_styles.tlf +0 -889
  115. data/examples/text_align/text_align.rb +0 -8
  116. data/examples/text_align/text_align.tlf +0 -241
  117. data/examples/typeB_page_size/B4_ISO.tlf +0 -45
  118. data/examples/typeB_page_size/B4_JIS.tlf +0 -45
  119. data/examples/typeB_page_size/typeB_page_size.rb +0 -17
  120. data/examples/word_wrap/word_wrap.rb +0 -26
  121. data/examples/word_wrap/word_wrap.tlf +0 -297
  122. data/test/data/font.ttf +0 -0
  123. data/test/data/image_normal.jpg +0 -0
  124. data/test/data/image_normal.png +0 -0
  125. data/test/data/image_normal_jpg_noext +0 -0
  126. data/test/data/image_normal_png_noext +0 -0
  127. data/test/data/image_pallete_based.png +0 -0
  128. data/test/data/legacy_layout/all-items.tlf +0 -1
  129. data/test/schema_helper.rb +0 -122
  130. data/test/test_helper.rb +0 -48
  131. data/test/tmp/.gitkeep +0 -0
  132. data/test/unit/core/format/test_base.rb +0 -152
  133. data/test/unit/core/shape/base/test_internal.rb +0 -87
  134. data/test/unit/core/shape/basic/test_block_format.rb +0 -23
  135. data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
  136. data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
  137. data/test/unit/core/shape/basic/test_format.rb +0 -37
  138. data/test/unit/core/shape/basic/test_interface.rb +0 -108
  139. data/test/unit/core/shape/basic/test_internal.rb +0 -55
  140. data/test/unit/core/shape/image_block/test_interface.rb +0 -24
  141. data/test/unit/core/shape/image_block/test_internal.rb +0 -31
  142. data/test/unit/core/shape/list/test_format.rb +0 -111
  143. data/test/unit/core/shape/list/test_manager.rb +0 -67
  144. data/test/unit/core/shape/list/test_page.rb +0 -82
  145. data/test/unit/core/shape/list/test_page_state.rb +0 -31
  146. data/test/unit/core/shape/list/test_section_format.rb +0 -36
  147. data/test/unit/core/shape/list/test_section_interface.rb +0 -75
  148. data/test/unit/core/shape/list/test_section_internal.rb +0 -50
  149. data/test/unit/core/shape/manager/test_format.rb +0 -38
  150. data/test/unit/core/shape/manager/test_internal.rb +0 -132
  151. data/test/unit/core/shape/manager/test_target.rb +0 -140
  152. data/test/unit/core/shape/page_number/test_format.rb +0 -55
  153. data/test/unit/core/shape/page_number/test_interface.rb +0 -33
  154. data/test/unit/core/shape/page_number/test_internal.rb +0 -81
  155. data/test/unit/core/shape/styles/test_base.rb +0 -191
  156. data/test/unit/core/shape/styles/test_basic.rb +0 -24
  157. data/test/unit/core/shape/styles/test_graphic.rb +0 -50
  158. data/test/unit/core/shape/styles/test_text.rb +0 -97
  159. data/test/unit/core/shape/text/test_format.rb +0 -44
  160. data/test/unit/core/shape/text/test_internal.rb +0 -20
  161. data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
  162. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
  163. data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
  164. data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
  165. data/test/unit/core/shape/text_block/test_format.rb +0 -169
  166. data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
  167. data/test/unit/core/shape/text_block/test_interface.rb +0 -63
  168. data/test/unit/core/shape/text_block/test_internal.rb +0 -128
  169. data/test/unit/core/test_shape.rb +0 -52
  170. data/test/unit/core/test_utils.rb +0 -68
  171. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
  172. data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -46
  173. data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -46
  174. data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
  175. data/test/unit/generator/pdf/document/test_font.rb +0 -84
  176. data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
  177. data/test/unit/generator/pdf/document/test_page.rb +0 -122
  178. data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
  179. data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +0 -41
  180. data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +0 -22
  181. data/test/unit/generator/pdf/test_document.rb +0 -22
  182. data/test/unit/generator/test_pdf.rb +0 -26
  183. data/test/unit/layout/test_base.rb +0 -41
  184. data/test/unit/layout/test_format.rb +0 -100
  185. data/test/unit/layout/test_legacy_schema.rb +0 -574
  186. data/test/unit/layout/test_version.rb +0 -26
  187. data/test/unit/report/test_base.rb +0 -248
  188. data/test/unit/report/test_internal.rb +0 -206
  189. data/test/unit/test_config.rb +0 -36
  190. data/test/unit/test_layout.rb +0 -12
  191. data/test/unit/test_report.rb +0 -18
@@ -74,7 +74,6 @@ module Thinreports
74
74
 
75
75
  # @param [Thinreports::Report::Page] new_parent
76
76
  # @return [Thinreports::Core::Shape::List::Page]
77
- # rubocop:disable Metrics/AbcSize
78
77
  def copy(new_parent)
79
78
  if manager.auto_page_break?
80
79
  new_list = self.class.new(new_parent, internal.format,
@@ -87,12 +86,10 @@ module Thinreports
87
86
  internal.rows.each do |row|
88
87
  new_list.internal.rows << row.copy(new_list)
89
88
  end
90
- new_list.finalized!
89
+ new_list.internal.finalized!
91
90
  end
92
91
 
93
- if internal.format.has_header?
94
- new_list.internal.header = internal.header.copy(new_list)
95
- end
92
+ new_list.internal.header = internal.header.copy(new_list) if internal.format.has_header?
96
93
  new_list
97
94
  end
98
95
 
@@ -47,7 +47,6 @@ module Thinreports
47
47
 
48
48
  # @param [String, Symbol] id
49
49
  # @return [Thinreports::Core::Shape::Base::Interface, nil]
50
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
51
50
  def final_shape(id)
52
51
  shape = shapes[id]
53
52
 
@@ -4,7 +4,7 @@ module Thinreports
4
4
  module Core
5
5
  module Shape
6
6
  module PageNumber
7
- TYPE_NAME = 'page-number'.freeze
7
+ TYPE_NAME = 'page-number'
8
8
  end
9
9
  end
10
10
  end
@@ -19,7 +19,6 @@ module Thinreports
19
19
  states[:format] = format.to_s
20
20
  end
21
21
 
22
- # rubocop:disable Metrics/AbcSize
23
22
  def build_format(page_no, page_count)
24
23
  return '' if blank_value?(read_format)
25
24
 
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thinreports
4
+ module Core
5
+ module Shape
6
+ module StackView
7
+ TYPE_NAME = 'stack-view'.freeze
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ require_relative 'stack_view/format'
14
+ require_relative 'stack_view/interface'
15
+ require_relative 'stack_view/internal'
16
+
17
+ require_relative 'stack_view/row_format'
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thinreports
4
+ module Core
5
+ module Shape
6
+ module StackView
7
+ class Format < Basic::Format
8
+ attr_reader :rows
9
+
10
+ def initialize(*)
11
+ super
12
+ initialize_rows
13
+ end
14
+
15
+ private
16
+
17
+ def initialize_rows
18
+ @rows = []
19
+ attributes['rows'].each do |row|
20
+ @rows << StackView::RowFormat.new(row)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thinreports
4
+ module Core
5
+ module Shape
6
+ module StackView
7
+ class Interface < Basic::Interface
8
+ private
9
+
10
+ def init_internal(parent, format)
11
+ StackView::Internal.new(parent, format)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thinreports
4
+ module Core
5
+ module Shape
6
+ module StackView
7
+ class Internal < Basic::Internal
8
+ def initialize(parent, format)
9
+ super
10
+ @rows = []
11
+ end
12
+
13
+ attr_accessor :rows
14
+
15
+ def type_of?(type_name)
16
+ type_name == StackView::TYPE_NAME
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thinreports
4
+ module Core
5
+ module Shape
6
+ module StackView
7
+ class RowFormat < Core::Format::Base
8
+ config_reader :id
9
+ config_reader :height
10
+ config_checker true, :display
11
+ config_checker true, auto_stretch: 'auto-stretch'
12
+
13
+ attr_reader :items
14
+
15
+ def initialize(*)
16
+ super
17
+ @items = []
18
+ @item_with_ids = {}
19
+ initialize_items(attributes['items'])
20
+ end
21
+
22
+ def find_item(id)
23
+ @item_with_ids[id.to_sym]
24
+ end
25
+
26
+ private
27
+
28
+ def initialize_items(item_schemas)
29
+ item_schemas.each do |item_schema|
30
+ item = Core::Shape::Format(item_schema['type']).new(item_schema)
31
+ @items << item
32
+ @item_with_ids[item.id.to_sym] = item unless item.id.empty?
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -5,9 +5,12 @@ module Thinreports
5
5
  module Shape
6
6
  module Style
7
7
  class Basic < Style::Base
8
- style_accessible :visible
8
+ style_accessible :visible, :offset_x, :offset_y
9
9
  attr_accessor :visible
10
10
 
11
+ style_accessor :offset_x, 'offset-x'
12
+ style_accessor :offset_y, 'offset-y'
13
+
11
14
  def initialize(*args)
12
15
  super
13
16
  @visible = @format.display?
@@ -4,7 +4,7 @@ module Thinreports
4
4
  module Core
5
5
  module Shape
6
6
  module Text
7
- TYPE_NAME = 'text'.freeze
7
+ TYPE_NAME = 'text'
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module Thinreports
4
4
  module Core
5
5
  module Shape
6
6
  module TextBlock
7
- TYPE_NAME = 'text-block'.freeze
7
+ TYPE_NAME = 'text-block'
8
8
  end
9
9
  end
10
10
  end
@@ -15,12 +15,8 @@ module Thinreports
15
15
  delimiter = format.format_number_delimiter
16
16
 
17
17
  if_applicable value do |val|
18
- unless blank_value?(precision)
19
- val = number_with_precision(val, precision)
20
- end
21
- unless blank_value?(delimiter)
22
- val = number_with_delimiter(val, delimiter)
23
- end
18
+ val = number_with_precision(val, precision) unless blank_value?(precision)
19
+ val = number_with_delimiter(val, delimiter) unless blank_value?(delimiter)
24
20
  val
25
21
  end
26
22
  end
@@ -32,21 +28,37 @@ module Thinreports
32
28
 
33
29
  def normalize(value)
34
30
  if value.is_a?(String)
35
- # rubocop:disable Style/RescueModifier
36
- (Integer(value) rescue nil) || (Float(value) rescue nil)
31
+ convert_to_integer(value) || convert_to_float(value)
37
32
  else
38
33
  value
39
34
  end
40
35
  end
41
36
 
42
37
  def number_with_delimiter(value, delimiter = ',')
43
- value.to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/) { "#{$1}#{delimiter}" }
38
+ value_int, value_float = value.to_s.split('.')
39
+
40
+ [
41
+ value_int.gsub(/(\d)(?=(\d{3})+(?!\d))/) { "#{$1}#{delimiter}" },
42
+ value_float
43
+ ].compact.join('.')
44
44
  end
45
45
 
46
46
  def number_with_precision(value, precision = 3)
47
47
  value = BigDecimal(value.to_s).round(precision)
48
48
  sprintf("%.#{precision}f", value)
49
49
  end
50
+
51
+ def convert_to_integer(value)
52
+ Integer(value)
53
+ rescue ArgumentError
54
+ nil
55
+ end
56
+
57
+ def convert_to_float(value)
58
+ Float(value)
59
+ rescue ArgumentError
60
+ nil
61
+ end
50
62
  end
51
63
  end
52
64
  end
@@ -50,8 +50,6 @@ module Thinreports
50
50
  end
51
51
 
52
52
  def format_enabled?
53
- return false if multiple?
54
-
55
53
  if states.key?(:format_enabled)
56
54
  states[:format_enabled]
57
55
  else
@@ -6,13 +6,16 @@ module Thinreports
6
6
  klass.extend self
7
7
  end
8
8
 
9
- # rubocop:disable Style/RescueModifier
10
9
  def deep_copy(src)
11
10
  case src
12
11
  when Hash
13
- src.each_with_object({}) { |(k, v), h| h[k] = v.dup rescue v }
12
+ src.each_with_object({}) do |(k, v), h|
13
+ h[k] = v.dup rescue v
14
+ end
14
15
  when Array
15
- src.map { |a| a.dup rescue a }
16
+ src.map do |a|
17
+ a.dup rescue a
18
+ end
16
19
  else
17
20
  raise ArgumentError
18
21
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'section_report/generate'
4
+
5
+ module Thinreports
6
+ class Generate
7
+ def call(report_params, filename: nil)
8
+ SectionReport::Generate.new.call(report_params, filename: filename)
9
+ end
10
+ end
11
+ end
@@ -5,21 +5,26 @@ module Thinreports
5
5
  class PDF
6
6
  module DrawShape
7
7
  # @param [Thinreports::Core::Shape::TextBlock::Internal] shape
8
- # rubocop:disable Metrics/AbcSize
9
- def draw_shape_tblock(shape)
10
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
8
+ # @param [Numeric] height (nil) It will be used as rendering height if present.
9
+ # Otherwise, the rendering height is the height of schema.
10
+ # @param [:truncate, :shrink_to_fit, :expand] overflow (nil) It will be set the overflow attribute if present.
11
+ def draw_shape_tblock(shape, height: nil, overflow: nil, &block)
12
+ x, y, w = shape.format.attributes.values_at('x', 'y', 'width')
13
+
14
+ h = height || shape.format.attributes['height']
11
15
 
12
16
  content = shape.real_value.to_s
13
17
  return if content.empty?
14
18
 
15
19
  attrs = build_text_attributes(shape.style.finalized_styles)
20
+ attrs[:overflow] = overflow if overflow
16
21
 
17
22
  unless shape.multiple?
18
23
  content = content.tr("\n", ' ')
19
24
  attrs[:single] = true
20
25
  end
21
26
 
22
- text_box(content, x, y, w, h, attrs)
27
+ text_box(content, x, y, w, h, attrs, &block)
23
28
  end
24
29
 
25
30
  def draw_shape_pageno(shape, page_no, page_count)
@@ -45,6 +50,21 @@ module Thinreports
45
50
  style = shape.style.finalized_styles
46
51
 
47
52
  image_box(
53
+ shape.src, x, y, w, h,
54
+ position_x: image_position_x(style['position-x']),
55
+ position_y: image_position_y(style['position-y']),
56
+ offset_x: style['offset-x'],
57
+ offset_y: style['offset-y']
58
+ )
59
+ end
60
+
61
+ def shape_iblock_dimenions(shape)
62
+ return nil if blank_value?(shape.src)
63
+
64
+ x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
65
+ style = shape.style.finalized_styles
66
+
67
+ image_dimensions(
48
68
  shape.src, x, y, w, h,
49
69
  position_x: image_position_x(style['position-x']),
50
70
  position_y: image_position_y(style['position-y'])
@@ -52,10 +72,10 @@ module Thinreports
52
72
  end
53
73
 
54
74
  # @param [Thinreports::Core::Shape::Text::Internal] shape
55
- def draw_shape_text(shape)
75
+ def draw_shape_text(shape, dheight = 0)
56
76
  x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
57
77
  text(
58
- shape.texts.join("\n"), x, y, w, h,
78
+ shape.texts.join("\n"), x, y, w, h + dheight,
59
79
  build_text_attributes(shape.style.finalized_styles)
60
80
  )
61
81
  end
@@ -67,18 +87,18 @@ module Thinreports
67
87
  end
68
88
 
69
89
  # @param [Thinreports::Core::Shape::Basic::Internal] shape
70
- def draw_shape_line(shape)
90
+ def draw_shape_line(shape, dy1 = 0, dy2 = 0)
71
91
  x1, y1, x2, y2 = shape.format.attributes.values_at('x1', 'y1', 'x2', 'y2')
72
- line(x1, y1, x2, y2, build_graphic_attributes(shape.style.finalized_styles))
92
+ line(x1, y1 + dy1, x2, y2 + dy2, build_graphic_attributes(shape.style.finalized_styles))
73
93
  end
74
94
 
75
95
  # @param [Thinreports::Core::Shape::Basic::Internal] shape
76
- def draw_shape_rect(shape)
96
+ def draw_shape_rect(shape, dheight = 0)
77
97
  x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
78
98
  rect_attributes = build_graphic_attributes(shape.style.finalized_styles) do |attrs|
79
- attrs[:radius] = shape.format.attributes['rx']
99
+ attrs[:radius] = shape.format.attributes['border-radius']
80
100
  end
81
- rect(x, y, w, h, rect_attributes)
101
+ rect(x, y, w, h + dheight, rect_attributes)
82
102
  end
83
103
  end
84
104
  end
@@ -5,7 +5,6 @@ module Thinreports
5
5
  class PDF
6
6
  module DrawTemplateItems
7
7
  # @param [Array<Hash>] items
8
- # rubocop:disable Metrics/CyclomaticComplexity
9
8
  def draw_template_items(items)
10
9
  items.each do |item_attributes|
11
10
  next unless drawable?(item_attributes)
@@ -26,7 +25,7 @@ module Thinreports
26
25
  def draw_rect(item_attributes)
27
26
  x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
28
27
  graphic_attributes = build_graphic_attributes(item_attributes['style']) do |attrs|
29
- attrs[:radius] = item_attributes['rx']
28
+ attrs[:radius] = item_attributes['border-radius']
30
29
  end
31
30
 
32
31
  rect(x, y, w, h, graphic_attributes)
@@ -7,10 +7,10 @@ module Thinreports
7
7
  FONT_STORE = Thinreports.root.join('fonts')
8
8
 
9
9
  BUILTIN_FONTS = {
10
- 'IPAMincho' => { normal: FONT_STORE.join('ipam.ttf').to_s },
11
- 'IPAPMincho' => { normal: FONT_STORE.join('ipamp.ttf').to_s },
12
- 'IPAGothic' => { normal: FONT_STORE.join('ipag.ttf').to_s },
13
- 'IPAPGothic' => { normal: FONT_STORE.join('ipagp.ttf').to_s }
10
+ 'IPAMincho' => FONT_STORE.join('ipam.ttf').to_s,
11
+ 'IPAPMincho' => FONT_STORE.join('ipamp.ttf').to_s,
12
+ 'IPAGothic' => FONT_STORE.join('ipag.ttf').to_s,
13
+ 'IPAPGothic' => FONT_STORE.join('ipagp.ttf').to_s
14
14
  }.freeze
15
15
 
16
16
  DEFAULT_FALLBACK_FONTS = %w[IPAMincho].freeze
@@ -20,10 +20,11 @@ module Thinreports
20
20
  'Times New Roman' => 'Times-Roman'
21
21
  }.freeze
22
22
 
23
- # rubocop:disable Metrics/AbcSize
24
23
  def setup_fonts
25
24
  # Install built-in fonts.
26
- pdf.font_families.update(BUILTIN_FONTS)
25
+ BUILTIN_FONTS.each do |font_name, font_path|
26
+ install_font(font_name, font_path)
27
+ end
27
28
 
28
29
  # Create aliases from the font list provided by Prawn.
29
30
  PRAWN_BUINTIN_FONT_ALIASES.each do |alias_name, name|
@@ -70,11 +71,16 @@ module Thinreports
70
71
  pdf.font_families.key?(family) ? family : default_family
71
72
  end
72
73
 
73
- # @param [String] font
74
- # @param [Symbol] style
74
+ # @param [String] font_name
75
+ # @param [:bold, :italic] font_style
75
76
  # @return [Boolean]
76
- def font_has_style?(font, style)
77
- (f = pdf.font_families[font]) && f.key?(style)
77
+ def font_has_style?(font_name, font_style)
78
+ font = pdf.font_families[font_name]
79
+
80
+ return false unless font
81
+ return false unless font.key?(font_style)
82
+
83
+ font[font_style] != font[:normal]
78
84
  end
79
85
  end
80
86
  end