thinreports 0.9.1 → 0.11.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 (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,79 +1,85 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thinreports
4
4
  module Generator
5
+ class PDF
6
+ module DrawShape
7
+ # @param [Thinreports::Core::Shape::TextBlock::Internal] shape
8
+ def draw_shape_tblock(shape)
9
+ x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
5
10
 
6
- module PDF::DrawShape
7
- # @param [Thinreports::Core::Shape::TextBlock::Internal] shape
8
- def draw_shape_tblock(shape)
9
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
11
+ content = shape.real_value.to_s
12
+ return if content.empty?
10
13
 
11
- content = shape.real_value.to_s
12
- unless content.empty?
13
14
  attrs = build_text_attributes(shape.style.finalized_styles)
14
15
 
15
16
  unless shape.multiple?
16
- content = content.gsub(/\n/, ' ')
17
+ content = content.tr("\n", ' ')
17
18
  attrs[:single] = true
18
19
  end
20
+
19
21
  text_box(content, x, y, w, h, attrs)
20
22
  end
21
- end
22
23
 
23
- def draw_shape_pageno(shape, page_no, page_count)
24
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
24
+ def draw_shape_pageno(shape, page_no, page_count)
25
+ x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
25
26
 
26
- text_box(shape.build_format(page_no, page_count), x, y, w, h,
27
- build_text_attributes(shape.style.finalized_styles))
28
- end
27
+ attrs = build_text_attributes(shape.style.finalized_styles)
28
+ text_box(shape.build_format(page_no, page_count), x, y, w, h, attrs)
29
+ end
29
30
 
30
- # @param [Thinreports::Core::Shape::Basic::Internal] shape
31
- def draw_shape_image(shape)
32
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
31
+ # @param [Thinreports::Core::Shape::Basic::Internal] shape
32
+ def draw_shape_image(shape)
33
+ x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
33
34
 
34
- image_data = shape.format.attributes['data']
35
- base64image(image_data['mime-type'], image_data['base64'], x, y, w, h)
36
- end
35
+ image_data = shape.format.attributes['data']
36
+ base64image(image_data['base64'], x, y, w, h)
37
+ end
37
38
 
38
- # @param [Thinreports::Core::Shape::ImageBlock::Internal] shape
39
- def draw_shape_iblock(shape)
40
- return if blank_value?(shape.src)
39
+ # @param [Thinreports::Core::Shape::ImageBlock::Internal] shape
40
+ def draw_shape_iblock(shape)
41
+ return if blank_value?(shape.src)
41
42
 
42
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
43
- style = shape.style.finalized_styles
43
+ x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
44
+ style = shape.style.finalized_styles
44
45
 
45
- image_box(shape.src, x, y, w, h,
46
- position_x: image_position_x(style['position-x']),
47
- position_y: image_position_y(style['position-y']))
48
- end
46
+ image_box(
47
+ shape.src, x, y, w, h,
48
+ position_x: image_position_x(style['position-x']),
49
+ position_y: image_position_y(style['position-y'])
50
+ )
51
+ end
49
52
 
50
- # @param [Thinreports::Core::Shape::Text::Internal] shape
51
- def draw_shape_text(shape)
52
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
53
- text(shape.texts.join("\n"), x, y, w, h, build_text_attributes(shape.style.finalized_styles))
54
- end
53
+ # @param [Thinreports::Core::Shape::Text::Internal] shape
54
+ def draw_shape_text(shape)
55
+ x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
56
+ text(
57
+ shape.texts.join("\n"), x, y, w, h,
58
+ build_text_attributes(shape.style.finalized_styles)
59
+ )
60
+ end
55
61
 
56
- # @param [Thinreports::Core::Shape::Basic::Internal] shape
57
- def draw_shape_ellipse(shape)
58
- cx, cy, rx, ry = shape.format.attributes.values_at('cx', 'cy', 'rx', 'ry')
59
- ellipse(cx, cy, rx, ry, build_graphic_attributes(shape.style.finalized_styles))
60
- end
62
+ # @param [Thinreports::Core::Shape::Basic::Internal] shape
63
+ def draw_shape_ellipse(shape)
64
+ cx, cy, rx, ry = shape.format.attributes.values_at('cx', 'cy', 'rx', 'ry')
65
+ ellipse(cx, cy, rx, ry, build_graphic_attributes(shape.style.finalized_styles))
66
+ end
61
67
 
62
- # @param [Thinreports::Core::Shape::Basic::Internal] shape
63
- def draw_shape_line(shape)
64
- x1, y1, x2, y2 = shape.format.attributes.values_at('x1', 'y1', 'x2', 'y2')
65
- line(x1, y1, x2, y2, build_graphic_attributes(shape.style.finalized_styles))
66
- end
68
+ # @param [Thinreports::Core::Shape::Basic::Internal] shape
69
+ def draw_shape_line(shape)
70
+ x1, y1, x2, y2 = shape.format.attributes.values_at('x1', 'y1', 'x2', 'y2')
71
+ line(x1, y1, x2, y2, build_graphic_attributes(shape.style.finalized_styles))
72
+ end
67
73
 
68
- # @param [Thinreports::Core::Shape::Basic::Internal] shape
69
- def draw_shape_rect(shape)
70
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
71
- rect_attributes = build_graphic_attributes(shape.style.finalized_styles) do |attrs|
72
- attrs[:radius] = shape.format.attributes['rx']
74
+ # @param [Thinreports::Core::Shape::Basic::Internal] shape
75
+ def draw_shape_rect(shape)
76
+ x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
77
+ rect_attributes = build_graphic_attributes(shape.style.finalized_styles) do |attrs|
78
+ attrs[:radius] = shape.format.attributes['border-radius']
79
+ end
80
+ rect(x, y, w, h, rect_attributes)
73
81
  end
74
- rect(x, y, w, h, rect_attributes)
75
82
  end
76
83
  end
77
-
78
84
  end
79
85
  end
@@ -1,66 +1,69 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thinreports
4
4
  module Generator
5
+ class PDF
6
+ module DrawTemplateItems
7
+ # @param [Array<Hash>] items
8
+ def draw_template_items(items)
9
+ items.each do |item_attributes|
10
+ next unless drawable?(item_attributes)
5
11
 
6
- module PDF::DrawTemplateItems
7
- # @param [Array<Hash>] items
8
- def draw_template_items(items)
9
- items.each do |item_attributes|
10
- next unless drawable?(item_attributes)
11
-
12
- case item_attributes['type']
13
- when 'text' then draw_text(item_attributes)
14
- when 'image' then draw_image(item_attributes)
15
- when 'rect' then draw_rect(item_attributes)
16
- when 'ellipse' then draw_ellipse(item_attributes)
17
- when 'line' then draw_line(item_attributes)
12
+ case item_attributes['type']
13
+ when 'text' then draw_text(item_attributes)
14
+ when 'image' then draw_image(item_attributes)
15
+ when 'rect' then draw_rect(item_attributes)
16
+ when 'ellipse' then draw_ellipse(item_attributes)
17
+ when 'line' then draw_line(item_attributes)
18
+ end
18
19
  end
19
20
  end
20
- end
21
21
 
22
- private
22
+ private
23
23
 
24
- # @param [Hash] item_attributes
25
- def draw_rect(item_attributes)
26
- x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
27
- graphic_attributes = build_graphic_attributes(item_attributes['style']) do |attrs|
28
- attrs[:radius] = item_attributes['rx']
29
- end
24
+ # @param [Hash] item_attributes
25
+ def draw_rect(item_attributes)
26
+ x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
27
+ graphic_attributes = build_graphic_attributes(item_attributes['style']) do |attrs|
28
+ attrs[:radius] = item_attributes['border-radius']
29
+ end
30
30
 
31
- rect(x, y, w, h, graphic_attributes)
32
- end
31
+ rect(x, y, w, h, graphic_attributes)
32
+ end
33
33
 
34
- # @see #draw_rect
35
- def draw_ellipse(item_attributes)
36
- x, y, rx, ry = item_attributes.values_at('cx', 'cy', 'rx', 'ry')
37
- ellipse(x, y, rx, ry, build_graphic_attributes(item_attributes['style']))
38
- end
34
+ # @see #draw_rect
35
+ def draw_ellipse(item_attributes)
36
+ x, y, rx, ry = item_attributes.values_at('cx', 'cy', 'rx', 'ry')
37
+ ellipse(x, y, rx, ry, build_graphic_attributes(item_attributes['style']))
38
+ end
39
39
 
40
- # @see #draw_rect
41
- def draw_line(item_attributes)
42
- x1, y1, x2, y2 = item_attributes.values_at('x1', 'y1', 'x2', 'y2')
43
- line(x1, y1, x2, y2, build_graphic_attributes(item_attributes['style']))
44
- end
40
+ # @see #draw_rect
41
+ def draw_line(item_attributes)
42
+ x1, y1, x2, y2 = item_attributes.values_at('x1', 'y1', 'x2', 'y2')
43
+ line(x1, y1, x2, y2, build_graphic_attributes(item_attributes['style']))
44
+ end
45
45
 
46
- # @see #draw_rect
47
- def draw_text(item_attributes)
48
- x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
49
- text(item_attributes['texts'].join("\n"), x, y, w, h, build_text_attributes(item_attributes['style']))
50
- end
46
+ # @see #draw_rect
47
+ def draw_text(item_attributes)
48
+ x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
49
+ text(
50
+ item_attributes['texts'].join("\n"), x, y, w, h,
51
+ build_text_attributes(item_attributes['style'])
52
+ )
53
+ end
51
54
 
52
- # @see #draw_rect
53
- def draw_image(item_attributes)
54
- x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
55
- image_data = item_attributes['data']
55
+ # @see #draw_rect
56
+ def draw_image(item_attributes)
57
+ x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
58
+ image_data = item_attributes['data']
56
59
 
57
- base64image(image_data['mime-type'], image_data['base64'], x, y, w, h)
58
- end
60
+ base64image(image_data['base64'], x, y, w, h)
61
+ end
59
62
 
60
- def drawable?(item_attributes)
61
- item_attributes['id'].empty? && item_attributes['display']
63
+ def drawable?(item_attributes)
64
+ item_attributes['id'].empty? && item_attributes['display']
65
+ end
62
66
  end
63
67
  end
64
-
65
68
  end
66
69
  end
@@ -1,79 +1,88 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thinreports
4
4
  module Generator
5
+ class PDF
6
+ module Font
7
+ FONT_STORE = Thinreports.root.join('fonts')
5
8
 
6
- module PDF::Font
7
- FONT_STORE = File.join(Thinreports::ROOT, 'fonts')
9
+ BUILTIN_FONTS = {
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
+ }.freeze
8
15
 
9
- BUILTIN_FONTS = {
10
- 'IPAMincho' => { normal: File.join(FONT_STORE, 'ipam.ttf') },
11
- 'IPAPMincho' => { normal: File.join(FONT_STORE, 'ipamp.ttf') },
12
- 'IPAGothic' => { normal: File.join(FONT_STORE, 'ipag.ttf') },
13
- 'IPAPGothic' => { normal: File.join(FONT_STORE, 'ipagp.ttf') }
14
- }
16
+ DEFAULT_FALLBACK_FONTS = %w[IPAMincho].freeze
15
17
 
16
- DEFAULT_FALLBACK_FONTS = %w( Helvetica IPAMincho )
18
+ PRAWN_BUINTIN_FONT_ALIASES = {
19
+ 'Courier New' => 'Courier',
20
+ 'Times New Roman' => 'Times-Roman'
21
+ }.freeze
17
22
 
18
- PRAWN_BUINTIN_FONT_ALIASES = {
19
- 'Courier New' => 'Courier',
20
- 'Times New Roman' => 'Times-Roman'
21
- }
22
-
23
- def setup_fonts
24
- # Install built-in fonts.
25
- pdf.font_families.update(BUILTIN_FONTS)
23
+ def setup_fonts
24
+ # Install built-in fonts.
25
+ BUILTIN_FONTS.each do |font_name, font_path|
26
+ install_font(font_name, font_path)
27
+ end
26
28
 
27
- # Create aliases from the font list provided by Prawn.
28
- PRAWN_BUINTIN_FONT_ALIASES.each do |alias_name, name|
29
- pdf.font_families[alias_name] = pdf.font_families[name]
30
- end
29
+ # Create aliases from the font list provided by Prawn.
30
+ PRAWN_BUINTIN_FONT_ALIASES.each do |alias_name, name|
31
+ pdf.font_families[alias_name] = pdf.font_families[name]
32
+ end
31
33
 
32
- # Setup custom fallback fonts
33
- fallback_fonts = Thinreports.config.fallback_fonts.uniq
34
- fallback_fonts.map!.with_index do |font, i|
35
- unless pdf.font_families.key?(font)
36
- install_font "Custom-fallback-font#{i}", font
37
- else
38
- font
34
+ # Setup custom fallback fonts
35
+ fallback_fonts = Thinreports.config.fallback_fonts.uniq
36
+ fallback_fonts.map!.with_index do |font, i|
37
+ if pdf.font_families.key?(font)
38
+ font
39
+ else
40
+ install_font "Custom-fallback-font#{i}", font
41
+ end
39
42
  end
43
+
44
+ # Set fallback fonts
45
+ pdf.fallback_fonts(fallback_fonts + DEFAULT_FALLBACK_FONTS)
40
46
  end
41
47
 
42
- # Set fallback fonts
43
- pdf.fallback_fonts(fallback_fonts + DEFAULT_FALLBACK_FONTS)
44
- end
48
+ # @param [String] name
49
+ # @param [String] file
50
+ # @return [String] installed font name
51
+ def install_font(name, file)
52
+ raise Errors::FontFileNotFound unless File.exist?(file)
45
53
 
46
- # @param [String] name
47
- # @param [String] file
48
- # @return [String] installed font name
49
- def install_font(name, file)
50
- raise Errors::FontFileNotFound unless File.exist?(file)
54
+ pdf.font_families[name] = {
55
+ normal: file,
56
+ bold: file,
57
+ italic: file,
58
+ bold_italic: file
59
+ }
60
+ name
61
+ end
51
62
 
52
- pdf.font_families[name] = {normal: file,
53
- bold: file,
54
- italic: file,
55
- bold_italic: file}
56
- name
57
- end
63
+ # @return [String]
64
+ def default_family
65
+ 'Helvetica'
66
+ end
58
67
 
59
- # @return [String]
60
- def default_family
61
- 'Helvetica'
62
- end
68
+ # @param [String] family
69
+ # @return [String]
70
+ def default_family_if_missing(family)
71
+ pdf.font_families.key?(family) ? family : default_family
72
+ end
63
73
 
64
- # @param [String] family
65
- # @return [String]
66
- def default_family_if_missing(family)
67
- pdf.font_families.key?(family) ? family : default_family
68
- end
74
+ # @param [String] font_name
75
+ # @param [:bold, :italic] font_style
76
+ # @return [Boolean]
77
+ def font_has_style?(font_name, font_style)
78
+ font = pdf.font_families[font_name]
69
79
 
70
- # @param [String] font
71
- # @param [Symbol] style
72
- # @return [Boolean]
73
- def font_has_style?(font, style)
74
- (f = pdf.font_families[font]) && f.key?(style)
80
+ return false unless font
81
+ return false unless font.key?(font_style)
82
+
83
+ font[font_style] != font[:normal]
84
+ end
75
85
  end
76
86
  end
77
-
78
87
  end
79
88
  end
@@ -1,41 +1,40 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thinreports
4
4
  module Generator
5
-
6
- module PDF::Graphics
7
-
8
- BASE_LINE_WIDTH = 0.9
9
-
10
- private
11
-
12
- # Change the default graphic states defined by Prawn.
13
- def setup_custom_graphic_states
14
- pdf.line_width(BASE_LINE_WIDTH)
15
- end
16
-
17
- # @param [Numeric] width
18
- def line_width(width)
19
- pdf.line_width(width * BASE_LINE_WIDTH)
20
- end
21
-
22
- # Delegate to Prawn::Document#save_graphic_state
23
- # @see Prawn::Document#save_graphics_state
24
- def save_graphics_state
25
- pdf.save_graphics_state
26
- end
27
-
28
- # Delegate to Prawn::Document#restore_graphic_state
29
- # @see Prawn::Document#restore_graphics_state
30
- def restore_graphics_state
31
- pdf.restore_graphics_state
5
+ class PDF
6
+ module Graphics
7
+ BASE_LINE_WIDTH = 0.9
8
+
9
+ private
10
+
11
+ # Change the default graphic states defined by Prawn.
12
+ def setup_custom_graphic_states
13
+ pdf.line_width(BASE_LINE_WIDTH)
14
+ end
15
+
16
+ # @param [Numeric] width
17
+ def line_width(width)
18
+ pdf.line_width(width * BASE_LINE_WIDTH)
19
+ end
20
+
21
+ # Delegate to Prawn::Document#save_graphic_state
22
+ # @see Prawn::Document#save_graphics_state
23
+ def save_graphics_state
24
+ pdf.save_graphics_state
25
+ end
26
+
27
+ # Delegate to Prawn::Document#restore_graphic_state
28
+ # @see Prawn::Document#restore_graphics_state
29
+ def restore_graphics_state
30
+ pdf.restore_graphics_state
31
+ end
32
32
  end
33
33
  end
34
-
35
34
  end
36
35
  end
37
36
 
38
- require 'thinreports/generator/pdf/document/graphics/attributes'
39
- require 'thinreports/generator/pdf/document/graphics/basic'
40
- require 'thinreports/generator/pdf/document/graphics/image'
41
- require 'thinreports/generator/pdf/document/graphics/text'
37
+ require_relative 'graphics/attributes'
38
+ require_relative 'graphics/basic'
39
+ require_relative 'graphics/image'
40
+ require_relative 'graphics/text'