thinreports 0.9.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +39 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +59 -2
  5. data/Dockerfile +12 -0
  6. data/Gemfile +7 -4
  7. data/README.md +44 -22
  8. data/Rakefile +14 -31
  9. data/lib/thinreports.rb +16 -15
  10. data/lib/thinreports/config.rb +2 -24
  11. data/lib/thinreports/core/errors.rb +6 -17
  12. data/lib/thinreports/core/format/base.rb +62 -61
  13. data/lib/thinreports/core/shape.rb +10 -12
  14. data/lib/thinreports/core/shape/base.rb +3 -12
  15. data/lib/thinreports/core/shape/base/interface.rb +34 -32
  16. data/lib/thinreports/core/shape/base/internal.rb +45 -43
  17. data/lib/thinreports/core/shape/basic.rb +12 -12
  18. data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
  19. data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
  20. data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
  21. data/lib/thinreports/core/shape/basic/format.rb +11 -9
  22. data/lib/thinreports/core/shape/basic/interface.rb +79 -77
  23. data/lib/thinreports/core/shape/basic/internal.rb +17 -14
  24. data/lib/thinreports/core/shape/image_block.rb +9 -9
  25. data/lib/thinreports/core/shape/image_block/format.rb +7 -5
  26. data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
  27. data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
  28. data/lib/thinreports/core/shape/list.rb +13 -13
  29. data/lib/thinreports/core/shape/list/format.rb +83 -77
  30. data/lib/thinreports/core/shape/list/manager.rb +179 -176
  31. data/lib/thinreports/core/shape/list/page.rb +91 -93
  32. data/lib/thinreports/core/shape/list/page_state.rb +42 -40
  33. data/lib/thinreports/core/shape/list/section_format.rb +28 -26
  34. data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
  35. data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
  36. data/lib/thinreports/core/shape/manager.rb +4 -13
  37. data/lib/thinreports/core/shape/manager/format.rb +21 -19
  38. data/lib/thinreports/core/shape/manager/internal.rb +87 -84
  39. data/lib/thinreports/core/shape/manager/target.rb +93 -95
  40. data/lib/thinreports/core/shape/page_number.rb +9 -9
  41. data/lib/thinreports/core/shape/page_number/format.rb +20 -18
  42. data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
  43. data/lib/thinreports/core/shape/page_number/internal.rb +46 -44
  44. data/lib/thinreports/core/shape/style.rb +5 -14
  45. data/lib/thinreports/core/shape/style/base.rb +121 -120
  46. data/lib/thinreports/core/shape/style/basic.rb +12 -10
  47. data/lib/thinreports/core/shape/style/graphic.rb +35 -33
  48. data/lib/thinreports/core/shape/style/text.rb +113 -107
  49. data/lib/thinreports/core/shape/text.rb +9 -9
  50. data/lib/thinreports/core/shape/text/format.rb +10 -9
  51. data/lib/thinreports/core/shape/text/interface.rb +13 -11
  52. data/lib/thinreports/core/shape/text/internal.rb +14 -12
  53. data/lib/thinreports/core/shape/text_block.rb +10 -10
  54. data/lib/thinreports/core/shape/text_block/format.rb +35 -33
  55. data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
  56. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
  57. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
  58. data/lib/thinreports/core/shape/text_block/formatter/number.rb +52 -34
  59. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
  60. data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
  61. data/lib/thinreports/core/shape/text_block/internal.rb +66 -68
  62. data/lib/thinreports/core/utils.rb +7 -3
  63. data/lib/thinreports/generator/pdf.rb +24 -25
  64. data/lib/thinreports/generator/pdf/document.rb +109 -110
  65. data/lib/thinreports/generator/pdf/document/draw_shape.rb +57 -51
  66. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +50 -47
  67. data/lib/thinreports/generator/pdf/document/font.rb +67 -58
  68. data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
  69. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +121 -121
  70. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +112 -114
  71. data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
  72. data/lib/thinreports/generator/pdf/document/graphics/text.rb +149 -137
  73. data/lib/thinreports/generator/pdf/document/page.rb +60 -64
  74. data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
  75. data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
  76. data/lib/thinreports/generator/pdf/drawer/list.rb +56 -54
  77. data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
  78. data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
  79. data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
  80. data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +32 -0
  81. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +35 -0
  82. data/lib/thinreports/layout.rb +5 -7
  83. data/lib/thinreports/layout/base.rb +5 -9
  84. data/lib/thinreports/layout/format.rb +17 -13
  85. data/lib/thinreports/layout/legacy_schema.rb +17 -13
  86. data/lib/thinreports/layout/version.rb +22 -25
  87. data/lib/thinreports/report.rb +4 -6
  88. data/lib/thinreports/report/base.rb +24 -51
  89. data/lib/thinreports/report/internal.rb +13 -15
  90. data/lib/thinreports/report/page.rb +5 -11
  91. data/lib/thinreports/version.rb +2 -2
  92. data/thinreports.gemspec +10 -19
  93. metadata +13 -288
  94. data/.travis.yml +0 -19
  95. data/examples/character_spacing/character_spacing.rb +0 -8
  96. data/examples/character_spacing/character_spacing.tlf +0 -293
  97. data/examples/dynamic_image/dynamic_image.rb +0 -31
  98. data/examples/dynamic_image/dynamic_image.tlf +0 -661
  99. data/examples/dynamic_image/img200x100.png +0 -0
  100. data/examples/dynamic_image/img50x50.png +0 -0
  101. data/examples/dynamic_style/dynamic_style.rb +0 -150
  102. data/examples/dynamic_style/dynamic_style.tlf +0 -1835
  103. data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
  104. data/examples/dynamic_style/image.png +0 -0
  105. data/examples/eudc/eudc.rb +0 -20
  106. data/examples/eudc/eudc.tlf +0 -180
  107. data/examples/eudc/eudc.ttf +0 -0
  108. data/examples/helper.rb +0 -50
  109. data/examples/hidden_shapes/hidden_shapes.rb +0 -9
  110. data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
  111. data/examples/list_events/list_events.rb +0 -32
  112. data/examples/list_events/list_events.tlf +0 -361
  113. data/examples/list_manual_generation/list_manual_generation.rb +0 -22
  114. data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
  115. data/examples/list_page_number/list_page_number.rb +0 -17
  116. data/examples/list_page_number/list_page_number.tlf +0 -254
  117. data/examples/page_number/page_number.rb +0 -33
  118. data/examples/page_number/page_number.tlf +0 -215
  119. data/examples/palleted_png/palleted_png.png +0 -0
  120. data/examples/palleted_png/palleted_png.rb +0 -11
  121. data/examples/palleted_png/palleted_png.tlf +0 -47
  122. data/examples/password_setting/password_setting.rb +0 -10
  123. data/examples/password_setting/password_setting.tlf +0 -45
  124. data/examples/report_callbacks/report_callbacks.rb +0 -14
  125. data/examples/report_callbacks/report_callbacks.tlf +0 -147
  126. data/examples/single_line_tblock/single_line_tblock.rb +0 -13
  127. data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
  128. data/examples/tblock_overflow/tblock_overflow.rb +0 -20
  129. data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
  130. data/examples/tblock_styles/font_size.tlf +0 -383
  131. data/examples/tblock_styles/tblock_styles.rb +0 -43
  132. data/examples/tblock_styles/tblock_styles.tlf +0 -889
  133. data/examples/text_align/text_align.rb +0 -8
  134. data/examples/text_align/text_align.tlf +0 -241
  135. data/examples/typeB_page_size/B4_ISO.tlf +0 -45
  136. data/examples/typeB_page_size/B4_JIS.tlf +0 -45
  137. data/examples/typeB_page_size/typeB_page_size.rb +0 -17
  138. data/examples/word_wrap/word_wrap.rb +0 -26
  139. data/examples/word_wrap/word_wrap.tlf +0 -297
  140. data/lib/thinreports/generator.rb +0 -29
  141. data/lib/thinreports/generator/base.rb +0 -40
  142. data/lib/thinreports/generator/configuration.rb +0 -31
  143. data/lib/thinreports/report/events.rb +0 -32
  144. data/test/data/font.ttf +0 -0
  145. data/test/data/image_normal.jpg +0 -0
  146. data/test/data/image_normal.png +0 -0
  147. data/test/data/image_normal_jpg_noext +0 -0
  148. data/test/data/image_normal_png_noext +0 -0
  149. data/test/data/image_pallete_based.png +0 -0
  150. data/test/data/legacy_layout/all-items.tlf +0 -1
  151. data/test/schema_helper.rb +0 -121
  152. data/test/test_helper.rb +0 -42
  153. data/test/tmp/.gitkeep +0 -0
  154. data/test/unit/core/format/test_base.rb +0 -152
  155. data/test/unit/core/shape/base/test_internal.rb +0 -87
  156. data/test/unit/core/shape/basic/test_block_format.rb +0 -23
  157. data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
  158. data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
  159. data/test/unit/core/shape/basic/test_format.rb +0 -37
  160. data/test/unit/core/shape/basic/test_interface.rb +0 -108
  161. data/test/unit/core/shape/basic/test_internal.rb +0 -55
  162. data/test/unit/core/shape/image_block/test_interface.rb +0 -24
  163. data/test/unit/core/shape/image_block/test_internal.rb +0 -31
  164. data/test/unit/core/shape/list/test_format.rb +0 -111
  165. data/test/unit/core/shape/list/test_manager.rb +0 -67
  166. data/test/unit/core/shape/list/test_page.rb +0 -82
  167. data/test/unit/core/shape/list/test_page_state.rb +0 -31
  168. data/test/unit/core/shape/list/test_section_format.rb +0 -36
  169. data/test/unit/core/shape/list/test_section_interface.rb +0 -75
  170. data/test/unit/core/shape/list/test_section_internal.rb +0 -50
  171. data/test/unit/core/shape/manager/test_format.rb +0 -38
  172. data/test/unit/core/shape/manager/test_internal.rb +0 -132
  173. data/test/unit/core/shape/manager/test_target.rb +0 -140
  174. data/test/unit/core/shape/page_number/test_format.rb +0 -55
  175. data/test/unit/core/shape/page_number/test_interface.rb +0 -33
  176. data/test/unit/core/shape/page_number/test_internal.rb +0 -81
  177. data/test/unit/core/shape/styles/test_base.rb +0 -191
  178. data/test/unit/core/shape/styles/test_basic.rb +0 -24
  179. data/test/unit/core/shape/styles/test_graphic.rb +0 -50
  180. data/test/unit/core/shape/styles/test_text.rb +0 -97
  181. data/test/unit/core/shape/text/test_format.rb +0 -44
  182. data/test/unit/core/shape/text/test_internal.rb +0 -20
  183. data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
  184. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
  185. data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
  186. data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
  187. data/test/unit/core/shape/text_block/test_format.rb +0 -169
  188. data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
  189. data/test/unit/core/shape/text_block/test_interface.rb +0 -63
  190. data/test/unit/core/shape/text_block/test_internal.rb +0 -128
  191. data/test/unit/core/test_shape.rb +0 -52
  192. data/test/unit/core/test_utils.rb +0 -68
  193. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
  194. data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -45
  195. data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -150
  196. data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
  197. data/test/unit/generator/pdf/document/test_font.rb +0 -84
  198. data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
  199. data/test/unit/generator/pdf/document/test_page.rb +0 -122
  200. data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
  201. data/test/unit/generator/pdf/test_document.rb +0 -20
  202. data/test/unit/generator/test_base.rb +0 -40
  203. data/test/unit/generator/test_configuration.rb +0 -21
  204. data/test/unit/generator/test_pdf.rb +0 -24
  205. data/test/unit/layout/test_base.rb +0 -41
  206. data/test/unit/layout/test_format.rb +0 -100
  207. data/test/unit/layout/test_legacy_schema.rb +0 -574
  208. data/test/unit/layout/test_version.rb +0 -95
  209. data/test/unit/report/test_base.rb +0 -262
  210. data/test/unit/report/test_internal.rb +0 -206
  211. data/test/unit/test_config.rb +0 -51
  212. data/test/unit/test_layout.rb +0 -12
  213. data/test/unit/test_report.rb +0 -18
@@ -1,120 +1,125 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thinreports
4
- module Generator::PDF::Drawer
5
-
6
- class Page < Base
7
- # @param (see PDF::Drawer::Base#initialize)
8
- def initialize(pdf, format)
9
- super
10
- @lists = {}
11
- end
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
12
13
 
13
- # @param [Thinreports::Report::Page] page
14
- def draw(page)
15
- manager = page.manager
14
+ # @param [Thinreports::Report::Page] page
15
+ def draw(page)
16
+ manager = page.manager
16
17
 
17
- manager.format.shapes.each_key do |id|
18
- shape = manager.final_shape(id)
19
- next unless shape
18
+ manager.format.shapes.each_key do |id|
19
+ shape = manager.final_shape(id)
20
+ next unless shape
20
21
 
21
- shape = shape.internal
22
+ shape = shape.internal
22
23
 
23
- if shape.type_of?(Core::Shape::PageNumber::TYPE_NAME)
24
- # Do not draw pageno if is not for Report
25
- draw_pageno_shape(shape, page) if page.count? && shape.for_report?
26
- else
27
- draw_shape(shape)
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
28
31
  end
29
- end
30
- end
31
32
 
32
- private
33
-
34
- def draw_shape(shape)
35
- case
36
- when shape.type_of?(Core::Shape::TextBlock::TYPE_NAME)
37
- draw_tblock_shape(shape)
38
- when shape.type_of?(Core::Shape::List::TYPE_NAME)
39
- draw_list_shape(shape)
40
- when 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
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
47
50
  end
48
- pdf_stamp(shape)
49
- end
50
- end
51
51
 
52
- def draw_pageno_shape(shape, page)
53
- @pdf.draw_shape_pageno(shape, page.no, page.report.page_count)
54
- end
52
+ def draw_pageno_shape(shape, page)
53
+ @pdf.draw_shape_pageno(shape, page.no, page.report.page_count)
54
+ end
55
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
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
61
 
62
- # @see #draw_shape
63
- def draw_tblock_shape(shape)
64
- @pdf.draw_shape_tblock(shape)
65
- end
62
+ # @see #draw_shape
63
+ def draw_tblock_shape(shape)
64
+ @pdf.draw_shape_tblock(shape)
65
+ end
66
66
 
67
- # @see #draw_shape
68
- def draw_iblock_shape(shape)
69
- @pdf.draw_shape_iblock(shape)
70
- end
67
+ # @see #draw_shape
68
+ def draw_iblock_shape(shape)
69
+ @pdf.draw_shape_iblock(shape)
70
+ end
71
71
 
72
- # @param [Thinreports::Core::Shape::Base::Internal] shape
73
- def create_basic_shape_stamp(shape)
74
- case
75
- when shape.type_of?('text') then create_text_stamp(shape)
76
- when shape.type_of?('image') then create_image_stamp(shape)
77
- when shape.type_of?('ellipse') then create_ellipse_stamp(shape)
78
- when shape.type_of?('rect') then create_rect_stamp(shape)
79
- when shape.type_of?('line') then create_line_stamp(shape)
80
- end
81
- end
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
82
86
 
83
- # @see #create_basic_shape_stamp
84
- def create_image_stamp(shape)
85
- create_pdf_stamp(shape) do
86
- @pdf.draw_shape_image(shape)
87
- end
88
- end
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
89
93
 
90
- # @see #create_basic_shape_stamp
91
- def create_rect_stamp(shape)
92
- create_pdf_stamp(shape) do
93
- @pdf.draw_shape_rect(shape)
94
- end
95
- end
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
96
100
 
97
- # @see #create_basic_shape_stamp
98
- def create_ellipse_stamp(shape)
99
- create_pdf_stamp(shape) do
100
- @pdf.draw_shape_ellipse(shape)
101
- end
102
- end
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
103
107
 
104
- # @see #create_basic_shape_stamp
105
- def create_line_stamp(shape)
106
- create_pdf_stamp(shape) do
107
- @pdf.draw_shape_line(shape)
108
- end
109
- end
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
110
114
 
111
- # @see #create_basic_shape_stamp
112
- def create_text_stamp(shape)
113
- create_pdf_stamp(shape) do
114
- @pdf.draw_shape_text(shape)
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
115
121
  end
116
122
  end
117
123
  end
118
-
119
124
  end
120
125
  end
@@ -1,32 +1,6 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- module Prawn
4
- class Document
5
- alias_method :original_width_of, :width_of
3
+ require_relative 'prawn_ext/width_of'
4
+ require_relative 'prawn_ext/calc_image_dimensions'
6
5
 
7
- def width_of(string, options={})
8
- font.compute_width_of(string, options) +
9
- (character_spacing * (font.character_count(string) - 1))
10
- end
11
- end
12
-
13
- module Images
14
- class Image
15
- alias_method :original_calc_image_dimensions, :calc_image_dimensions
16
-
17
- def calc_image_dimensions(options)
18
- if options[:auto_fit]
19
- w = options[:width] || width
20
- h = options[:height] || height
21
-
22
- box_width, box_height = options.delete(:auto_fit)
23
-
24
- if w > box_width || h > box_height
25
- options[:fit] = [box_width, box_height]
26
- end
27
- end
28
- original_calc_image_dimensions(options)
29
- end
30
- end
31
- end
32
- end
6
+ Prawn::Font::AFM.hide_m17n_warning = true
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thinreports
4
+ module Generator
5
+ module PrawnExt
6
+ module WidthOf
7
+ # TODO: Remove this path when a version of prawn that includes the following PR is released:
8
+ # https://github.com/prawnpdf/prawn/pull/1117
9
+ #
10
+ # This PR makes this patch unnecessary.
11
+ #
12
+ #
13
+ # Subtract the width of one character space from the string width calculation result.
14
+ #
15
+ # The original Prawn::Document#width_of returns the following result:
16
+ #
17
+ # Width of Character is 1
18
+ # Width of Character Space is 1
19
+ #
20
+ # width_of('abcd') #=> 4 + 4 = 8
21
+ #
22
+ # In this width_of, returns the following result:
23
+ #
24
+ # width_of('abcd') #=> 4 + 3 = 7
25
+ #
26
+ def width_of(*)
27
+ width = super - character_spacing
28
+ width > 0 ? width : 0
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ Prawn::Document.prepend Thinreports::Generator::PrawnExt::WidthOf
@@ -1,17 +1,15 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thinreports
4
-
5
4
  module Layout
6
5
  # @see Thinreports::Layout::Base#initialize
7
6
  def self.new(filename, options = {})
8
7
  Base.new(filename, options)
9
8
  end
10
9
  end
11
-
12
10
  end
13
11
 
14
- require 'thinreports/layout/version'
15
- require 'thinreports/layout/base'
16
- require 'thinreports/layout/format'
17
- require 'thinreports/layout/legacy_schema'
12
+ require_relative 'layout/version'
13
+ require_relative 'layout/base'
14
+ require_relative 'layout/format'
15
+ require_relative 'layout/legacy_schema'
@@ -1,8 +1,7 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thinreports
4
4
  module Layout
5
-
6
5
  class Base
7
6
  EXT_NAME = 'tlf'
8
7
  include Utils
@@ -13,11 +12,9 @@ module Thinreports
13
12
  # @raise [Thinreports::Errors::InvalidLayoutFormat]
14
13
  # @raise [Thinreports::Errors::IncompatibleLayoutFormat]
15
14
  def load_format(filename)
16
- filename += ".#{EXT_NAME}" unless filename =~/\.#{EXT_NAME}$/
15
+ filename += ".#{EXT_NAME}" unless filename =~ /\.#{EXT_NAME}$/
17
16
 
18
- unless File.exist?(filename)
19
- raise Thinreports::Errors::LayoutFileNotFound
20
- end
17
+ raise Thinreports::Errors::LayoutFileNotFound unless File.exist?(filename)
21
18
  # Build format.
22
19
  Thinreports::Layout::Format.build(filename)
23
20
  end
@@ -36,8 +33,8 @@ module Thinreports
36
33
  # @option options [Symbol] :id (nil)
37
34
  def initialize(filename, options = {})
38
35
  @filename = filename
39
- @format = self.class.load_format(filename)
40
- @id = options[:id]
36
+ @format = self.class.load_format(filename)
37
+ @id = options[:id]
41
38
  end
42
39
 
43
40
  # @return [Boolean] Return the true if is default layout.
@@ -45,6 +42,5 @@ module Thinreports
45
42
  @id.nil?
46
43
  end
47
44
  end
48
-
49
45
  end
50
46
  end
@@ -1,28 +1,32 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'json'
3
4
 
4
5
  module Thinreports
5
6
  module Layout
6
7
  class Format < Core::Shape::Manager::Format
7
- config_reader last_version: %w( version )
8
- config_reader report_title: %w( title )
9
- config_reader page_paper_type: %w( report paper-type ),
10
- page_width: %w( report width ),
11
- page_height: %w( report height ),
12
- page_orientation: %w( report orientation )
8
+ config_reader last_version: %w[version]
9
+ config_reader report_title: %w[title]
10
+ config_reader page_paper_type: %w[report paper-type],
11
+ page_width: %w[report width],
12
+ page_height: %w[report height],
13
+ page_orientation: %w[report orientation]
13
14
 
14
15
  class << self
15
16
  def build(filename)
16
17
  schema = JSON.parse(read_file(filename))
18
+ schema_version = Layout::Version.new(schema['version'])
17
19
 
18
- unless Layout::Version.compatible?(schema['version'])
20
+ unless schema_version.compatible?
19
21
  raise Errors::IncompatibleLayoutFormat.new(
20
- filename, schema['version'], Thinreports::Layout::Version.inspect_required_rules
22
+ filename, schema['version'],
23
+ Layout::Version.compatible_rules.join(' and ')
21
24
  )
22
25
  end
23
26
 
24
- if schema['version'] < '0.9.0'
25
- warn '[DEPRECATION] Support for the layout file with old format that generated with Editor 0.8 or lower will be dropped in Thinreports 1.1.' \
27
+ if schema_version.legacy?
28
+ warn '[DEPRECATION] Support for the layout file with old format' \
29
+ ' that generated with Editor 0.8 or lower will be dropped in Thinreports 1.1.' \
26
30
  ' Please convert to new layout format using Thinreports Editor 0.9 or 1.0.'
27
31
  schema = Layout::LegacySchema.new(schema).upgrade
28
32
  end
@@ -31,7 +35,7 @@ module Thinreports
31
35
  end
32
36
 
33
37
  def read_file(filename)
34
- File.open(filename, 'r:UTF-8') {|f| f.read }
38
+ File.read(filename, encoding: 'UTF-8')
35
39
  end
36
40
  end
37
41
 
@@ -53,7 +57,7 @@ module Thinreports
53
57
  next if id.empty? && type != 'page-number'
54
58
 
55
59
  item = Core::Shape::Format(type).new(item_schema)
56
- self.shapes[item.id.to_sym] = item
60
+ shapes[item.id.to_sym] = item
57
61
  end
58
62
  end
59
63
  end