thinreports 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +41 -0
  3. data/.travis.yml +4 -6
  4. data/CHANGELOG.md +21 -2
  5. data/Gemfile +2 -4
  6. data/README.md +4 -5
  7. data/Rakefile +7 -8
  8. data/examples/character_spacing/character_spacing.rb +1 -1
  9. data/examples/dynamic_image/dynamic_image.rb +3 -3
  10. data/examples/dynamic_style/dynamic_style.rb +1 -1
  11. data/examples/eudc/eudc.rb +1 -1
  12. data/examples/helper.rb +2 -2
  13. data/examples/hidden_shapes/hidden_shapes.rb +1 -1
  14. data/examples/list_events/list_events.rb +1 -1
  15. data/examples/list_manual_generation/list_manual_generation.rb +1 -1
  16. data/examples/list_page_number/list_page_number.rb +1 -1
  17. data/examples/page_number/page_number.rb +1 -1
  18. data/examples/palleted_png/palleted_png.rb +1 -3
  19. data/examples/password_setting/password_setting.rb +1 -1
  20. data/examples/report_callbacks/report_callbacks.rb +1 -1
  21. data/examples/single_line_tblock/single_line_tblock.rb +1 -1
  22. data/examples/tblock_overflow/tblock_overflow.rb +1 -1
  23. data/examples/tblock_styles/tblock_styles.rb +1 -1
  24. data/examples/text_align/text_align.rb +1 -1
  25. data/examples/typeB_page_size/typeB_page_size.rb +1 -1
  26. data/examples/word_wrap/word_wrap.rb +1 -1
  27. data/lib/thinreports.rb +16 -15
  28. data/lib/thinreports/config.rb +2 -24
  29. data/lib/thinreports/core/errors.rb +6 -17
  30. data/lib/thinreports/core/format/base.rb +62 -61
  31. data/lib/thinreports/core/shape.rb +13 -14
  32. data/lib/thinreports/core/shape/base.rb +3 -12
  33. data/lib/thinreports/core/shape/base/interface.rb +35 -32
  34. data/lib/thinreports/core/shape/base/internal.rb +45 -43
  35. data/lib/thinreports/core/shape/basic.rb +12 -12
  36. data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
  37. data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
  38. data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
  39. data/lib/thinreports/core/shape/basic/format.rb +11 -9
  40. data/lib/thinreports/core/shape/basic/interface.rb +79 -77
  41. data/lib/thinreports/core/shape/basic/internal.rb +17 -14
  42. data/lib/thinreports/core/shape/image_block.rb +9 -9
  43. data/lib/thinreports/core/shape/image_block/format.rb +7 -5
  44. data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
  45. data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
  46. data/lib/thinreports/core/shape/list.rb +13 -13
  47. data/lib/thinreports/core/shape/list/format.rb +83 -77
  48. data/lib/thinreports/core/shape/list/manager.rb +182 -176
  49. data/lib/thinreports/core/shape/list/page.rb +94 -93
  50. data/lib/thinreports/core/shape/list/page_state.rb +42 -40
  51. data/lib/thinreports/core/shape/list/section_format.rb +28 -26
  52. data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
  53. data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
  54. data/lib/thinreports/core/shape/manager.rb +4 -13
  55. data/lib/thinreports/core/shape/manager/format.rb +21 -19
  56. data/lib/thinreports/core/shape/manager/internal.rb +88 -84
  57. data/lib/thinreports/core/shape/manager/target.rb +93 -95
  58. data/lib/thinreports/core/shape/page_number.rb +9 -9
  59. data/lib/thinreports/core/shape/page_number/format.rb +20 -18
  60. data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
  61. data/lib/thinreports/core/shape/page_number/internal.rb +47 -44
  62. data/lib/thinreports/core/shape/style.rb +5 -14
  63. data/lib/thinreports/core/shape/style/base.rb +121 -120
  64. data/lib/thinreports/core/shape/style/basic.rb +12 -10
  65. data/lib/thinreports/core/shape/style/graphic.rb +35 -33
  66. data/lib/thinreports/core/shape/style/text.rb +113 -107
  67. data/lib/thinreports/core/shape/text.rb +9 -9
  68. data/lib/thinreports/core/shape/text/format.rb +10 -9
  69. data/lib/thinreports/core/shape/text/interface.rb +13 -11
  70. data/lib/thinreports/core/shape/text/internal.rb +14 -12
  71. data/lib/thinreports/core/shape/text_block.rb +10 -10
  72. data/lib/thinreports/core/shape/text_block/format.rb +35 -33
  73. data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
  74. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
  75. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
  76. data/lib/thinreports/core/shape/text_block/formatter/number.rb +45 -39
  77. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
  78. data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
  79. data/lib/thinreports/core/shape/text_block/internal.rb +68 -68
  80. data/lib/thinreports/core/utils.rb +4 -3
  81. data/lib/thinreports/generator/pdf.rb +24 -25
  82. data/lib/thinreports/generator/pdf/document.rb +109 -110
  83. data/lib/thinreports/generator/pdf/document/draw_shape.rb +58 -51
  84. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +51 -47
  85. data/lib/thinreports/generator/pdf/document/font.rb +62 -59
  86. data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
  87. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +122 -121
  88. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +113 -114
  89. data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
  90. data/lib/thinreports/generator/pdf/document/graphics/text.rb +152 -137
  91. data/lib/thinreports/generator/pdf/document/page.rb +63 -64
  92. data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
  93. data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
  94. data/lib/thinreports/generator/pdf/drawer/list.rb +48 -45
  95. data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
  96. data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
  97. data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
  98. data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +34 -0
  99. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +29 -0
  100. data/lib/thinreports/layout.rb +5 -7
  101. data/lib/thinreports/layout/base.rb +5 -7
  102. data/lib/thinreports/layout/format.rb +18 -13
  103. data/lib/thinreports/layout/legacy_schema.rb +18 -10
  104. data/lib/thinreports/layout/version.rb +22 -25
  105. data/lib/thinreports/report.rb +4 -6
  106. data/lib/thinreports/report/base.rb +24 -51
  107. data/lib/thinreports/report/internal.rb +9 -11
  108. data/lib/thinreports/report/page.rb +5 -6
  109. data/lib/thinreports/version.rb +2 -2
  110. data/test/schema_helper.rb +4 -3
  111. data/test/test_helper.rb +9 -3
  112. data/test/unit/core/format/test_base.rb +1 -1
  113. data/test/unit/core/shape/base/test_internal.rb +1 -1
  114. data/test/unit/core/shape/basic/test_block_format.rb +1 -1
  115. data/test/unit/core/shape/basic/test_block_interface.rb +1 -1
  116. data/test/unit/core/shape/basic/test_block_internal.rb +1 -1
  117. data/test/unit/core/shape/basic/test_format.rb +1 -1
  118. data/test/unit/core/shape/basic/test_interface.rb +1 -1
  119. data/test/unit/core/shape/basic/test_internal.rb +1 -1
  120. data/test/unit/core/shape/image_block/test_interface.rb +1 -1
  121. data/test/unit/core/shape/image_block/test_internal.rb +1 -1
  122. data/test/unit/core/shape/list/test_format.rb +1 -1
  123. data/test/unit/core/shape/list/test_manager.rb +4 -4
  124. data/test/unit/core/shape/list/test_page.rb +1 -1
  125. data/test/unit/core/shape/list/test_page_state.rb +1 -1
  126. data/test/unit/core/shape/list/test_section_format.rb +1 -1
  127. data/test/unit/core/shape/list/test_section_interface.rb +2 -2
  128. data/test/unit/core/shape/list/test_section_internal.rb +1 -1
  129. data/test/unit/core/shape/manager/test_format.rb +2 -2
  130. data/test/unit/core/shape/manager/test_internal.rb +3 -3
  131. data/test/unit/core/shape/manager/test_target.rb +1 -1
  132. data/test/unit/core/shape/page_number/test_format.rb +1 -1
  133. data/test/unit/core/shape/page_number/test_interface.rb +1 -1
  134. data/test/unit/core/shape/page_number/test_internal.rb +1 -1
  135. data/test/unit/core/shape/styles/test_base.rb +1 -1
  136. data/test/unit/core/shape/styles/test_basic.rb +1 -1
  137. data/test/unit/core/shape/styles/test_graphic.rb +1 -1
  138. data/test/unit/core/shape/styles/test_text.rb +1 -1
  139. data/test/unit/core/shape/text/test_format.rb +1 -1
  140. data/test/unit/core/shape/text/test_internal.rb +1 -1
  141. data/test/unit/core/shape/text_block/formatter/test_basic.rb +1 -1
  142. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +1 -1
  143. data/test/unit/core/shape/text_block/formatter/test_number.rb +1 -1
  144. data/test/unit/core/shape/text_block/formatter/test_padding.rb +2 -2
  145. data/test/unit/core/shape/text_block/test_format.rb +1 -1
  146. data/test/unit/core/shape/text_block/test_formatter.rb +1 -1
  147. data/test/unit/core/shape/text_block/test_interface.rb +1 -1
  148. data/test/unit/core/shape/text_block/test_internal.rb +3 -3
  149. data/test/unit/core/test_shape.rb +1 -1
  150. data/test/unit/core/test_utils.rb +2 -2
  151. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +1 -1
  152. data/test/unit/generator/pdf/document/graphics/test_basic.rb +2 -1
  153. data/test/unit/generator/pdf/document/graphics/test_image.rb +27 -131
  154. data/test/unit/generator/pdf/document/graphics/test_text.rb +1 -1
  155. data/test/unit/generator/pdf/document/test_font.rb +2 -2
  156. data/test/unit/generator/pdf/document/test_graphics.rb +1 -1
  157. data/test/unit/generator/pdf/document/test_page.rb +7 -7
  158. data/test/unit/generator/pdf/document/test_parse_color.rb +1 -1
  159. data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +41 -0
  160. data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +22 -0
  161. data/test/unit/generator/pdf/test_document.rb +8 -6
  162. data/test/unit/generator/test_pdf.rb +12 -10
  163. data/test/unit/layout/test_base.rb +1 -1
  164. data/test/unit/layout/test_format.rb +2 -2
  165. data/test/unit/layout/test_legacy_schema.rb +4 -4
  166. data/test/unit/layout/test_version.rb +11 -80
  167. data/test/unit/report/test_base.rb +45 -59
  168. data/test/unit/report/test_internal.rb +1 -1
  169. data/test/unit/test_config.rb +1 -16
  170. data/test/unit/test_layout.rb +1 -1
  171. data/test/unit/test_report.rb +1 -1
  172. data/thinreports.gemspec +11 -14
  173. metadata +42 -103
  174. data/lib/thinreports/generator.rb +0 -29
  175. data/lib/thinreports/generator/base.rb +0 -40
  176. data/lib/thinreports/generator/configuration.rb +0 -31
  177. data/lib/thinreports/report/events.rb +0 -32
  178. data/test/unit/generator/test_base.rb +0 -40
  179. data/test/unit/generator/test_configuration.rb +0 -21
@@ -1,79 +1,86 @@
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
+ # rubocop:disable Metrics/AbcSize
9
+ def draw_shape_tblock(shape)
10
+ x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
5
11
 
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')
12
+ content = shape.real_value.to_s
13
+ return if content.empty?
10
14
 
11
- content = shape.real_value.to_s
12
- unless content.empty?
13
15
  attrs = build_text_attributes(shape.style.finalized_styles)
14
16
 
15
17
  unless shape.multiple?
16
- content = content.gsub(/\n/, ' ')
18
+ content = content.tr("\n", ' ')
17
19
  attrs[:single] = true
18
20
  end
21
+
19
22
  text_box(content, x, y, w, h, attrs)
20
23
  end
21
- end
22
24
 
23
- def draw_shape_pageno(shape, page_no, page_count)
24
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
25
+ def draw_shape_pageno(shape, page_no, page_count)
26
+ x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
25
27
 
26
- text_box(shape.build_format(page_no, page_count), x, y, w, h,
27
- build_text_attributes(shape.style.finalized_styles))
28
- end
28
+ attrs = build_text_attributes(shape.style.finalized_styles)
29
+ text_box(shape.build_format(page_no, page_count), x, y, w, h, attrs)
30
+ end
29
31
 
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')
32
+ # @param [Thinreports::Core::Shape::Basic::Internal] shape
33
+ def draw_shape_image(shape)
34
+ x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
33
35
 
34
- image_data = shape.format.attributes['data']
35
- base64image(image_data['mime-type'], image_data['base64'], x, y, w, h)
36
- end
36
+ image_data = shape.format.attributes['data']
37
+ base64image(image_data['base64'], x, y, w, h)
38
+ end
37
39
 
38
- # @param [Thinreports::Core::Shape::ImageBlock::Internal] shape
39
- def draw_shape_iblock(shape)
40
- return if blank_value?(shape.src)
40
+ # @param [Thinreports::Core::Shape::ImageBlock::Internal] shape
41
+ def draw_shape_iblock(shape)
42
+ return if blank_value?(shape.src)
41
43
 
42
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
43
- style = shape.style.finalized_styles
44
+ x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
45
+ style = shape.style.finalized_styles
44
46
 
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
47
+ image_box(
48
+ shape.src, x, y, w, h,
49
+ position_x: image_position_x(style['position-x']),
50
+ position_y: image_position_y(style['position-y'])
51
+ )
52
+ end
49
53
 
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
54
+ # @param [Thinreports::Core::Shape::Text::Internal] shape
55
+ def draw_shape_text(shape)
56
+ x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
57
+ text(
58
+ shape.texts.join("\n"), x, y, w, h,
59
+ build_text_attributes(shape.style.finalized_styles)
60
+ )
61
+ end
55
62
 
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
63
+ # @param [Thinreports::Core::Shape::Basic::Internal] shape
64
+ def draw_shape_ellipse(shape)
65
+ cx, cy, rx, ry = shape.format.attributes.values_at('cx', 'cy', 'rx', 'ry')
66
+ ellipse(cx, cy, rx, ry, build_graphic_attributes(shape.style.finalized_styles))
67
+ end
61
68
 
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
69
+ # @param [Thinreports::Core::Shape::Basic::Internal] shape
70
+ def draw_shape_line(shape)
71
+ 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))
73
+ end
67
74
 
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']
75
+ # @param [Thinreports::Core::Shape::Basic::Internal] shape
76
+ def draw_shape_rect(shape)
77
+ x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
78
+ rect_attributes = build_graphic_attributes(shape.style.finalized_styles) do |attrs|
79
+ attrs[:radius] = shape.format.attributes['rx']
80
+ end
81
+ rect(x, y, w, h, rect_attributes)
73
82
  end
74
- rect(x, y, w, h, rect_attributes)
75
83
  end
76
84
  end
77
-
78
85
  end
79
86
  end
@@ -1,66 +1,70 @@
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
+ # rubocop:disable Metrics/CyclomaticComplexity
9
+ def draw_template_items(items)
10
+ items.each do |item_attributes|
11
+ next unless drawable?(item_attributes)
5
12
 
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)
13
+ case item_attributes['type']
14
+ when 'text' then draw_text(item_attributes)
15
+ when 'image' then draw_image(item_attributes)
16
+ when 'rect' then draw_rect(item_attributes)
17
+ when 'ellipse' then draw_ellipse(item_attributes)
18
+ when 'line' then draw_line(item_attributes)
19
+ end
18
20
  end
19
21
  end
20
- end
21
22
 
22
- private
23
+ private
23
24
 
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
25
+ # @param [Hash] item_attributes
26
+ def draw_rect(item_attributes)
27
+ x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
28
+ graphic_attributes = build_graphic_attributes(item_attributes['style']) do |attrs|
29
+ attrs[:radius] = item_attributes['rx']
30
+ end
30
31
 
31
- rect(x, y, w, h, graphic_attributes)
32
- end
32
+ rect(x, y, w, h, graphic_attributes)
33
+ end
33
34
 
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
35
+ # @see #draw_rect
36
+ def draw_ellipse(item_attributes)
37
+ x, y, rx, ry = item_attributes.values_at('cx', 'cy', 'rx', 'ry')
38
+ ellipse(x, y, rx, ry, build_graphic_attributes(item_attributes['style']))
39
+ end
39
40
 
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
41
+ # @see #draw_rect
42
+ def draw_line(item_attributes)
43
+ x1, y1, x2, y2 = item_attributes.values_at('x1', 'y1', 'x2', 'y2')
44
+ line(x1, y1, x2, y2, build_graphic_attributes(item_attributes['style']))
45
+ end
45
46
 
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
47
+ # @see #draw_rect
48
+ def draw_text(item_attributes)
49
+ x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
50
+ text(
51
+ item_attributes['texts'].join("\n"), x, y, w, h,
52
+ build_text_attributes(item_attributes['style'])
53
+ )
54
+ end
51
55
 
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']
56
+ # @see #draw_rect
57
+ def draw_image(item_attributes)
58
+ x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
59
+ image_data = item_attributes['data']
56
60
 
57
- base64image(image_data['mime-type'], image_data['base64'], x, y, w, h)
58
- end
61
+ base64image(image_data['base64'], x, y, w, h)
62
+ end
59
63
 
60
- def drawable?(item_attributes)
61
- item_attributes['id'].empty? && item_attributes['display']
64
+ def drawable?(item_attributes)
65
+ item_attributes['id'].empty? && item_attributes['display']
66
+ end
62
67
  end
63
68
  end
64
-
65
69
  end
66
70
  end
@@ -1,79 +1,82 @@
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' => { 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 }
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
- }
23
+ # rubocop:disable Metrics/AbcSize
24
+ def setup_fonts
25
+ # Install built-in fonts.
26
+ pdf.font_families.update(BUILTIN_FONTS)
22
27
 
23
- def setup_fonts
24
- # Install built-in fonts.
25
- pdf.font_families.update(BUILTIN_FONTS)
26
-
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
28
+ # Create aliases from the font list provided by Prawn.
29
+ PRAWN_BUINTIN_FONT_ALIASES.each do |alias_name, name|
30
+ pdf.font_families[alias_name] = pdf.font_families[name]
31
+ end
31
32
 
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
33
+ # Setup custom fallback fonts
34
+ fallback_fonts = Thinreports.config.fallback_fonts.uniq
35
+ fallback_fonts.map!.with_index do |font, i|
36
+ if pdf.font_families.key?(font)
37
+ font
38
+ else
39
+ install_font "Custom-fallback-font#{i}", font
40
+ end
39
41
  end
40
- end
41
42
 
42
- # Set fallback fonts
43
- pdf.fallback_fonts(fallback_fonts + DEFAULT_FALLBACK_FONTS)
44
- end
43
+ # Set fallback fonts
44
+ pdf.fallback_fonts(fallback_fonts + DEFAULT_FALLBACK_FONTS)
45
+ end
45
46
 
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)
47
+ # @param [String] name
48
+ # @param [String] file
49
+ # @return [String] installed font name
50
+ def install_font(name, file)
51
+ raise Errors::FontFileNotFound unless File.exist?(file)
51
52
 
52
- pdf.font_families[name] = {normal: file,
53
- bold: file,
54
- italic: file,
55
- bold_italic: file}
56
- name
57
- end
53
+ pdf.font_families[name] = {
54
+ normal: file,
55
+ bold: file,
56
+ italic: file,
57
+ bold_italic: file
58
+ }
59
+ name
60
+ end
58
61
 
59
- # @return [String]
60
- def default_family
61
- 'Helvetica'
62
- end
62
+ # @return [String]
63
+ def default_family
64
+ 'Helvetica'
65
+ end
63
66
 
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
67
+ # @param [String] family
68
+ # @return [String]
69
+ def default_family_if_missing(family)
70
+ pdf.font_families.key?(family) ? family : default_family
71
+ end
69
72
 
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)
73
+ # @param [String] font
74
+ # @param [Symbol] style
75
+ # @return [Boolean]
76
+ def font_has_style?(font, style)
77
+ (f = pdf.font_families[font]) && f.key?(style)
78
+ end
75
79
  end
76
80
  end
77
-
78
81
  end
79
82
  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'