thinreports 0.7.6 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -5
  3. data/.travis.yml +8 -4
  4. data/CHANGELOG.md +220 -0
  5. data/Gemfile +2 -9
  6. data/MIT-LICENSE +1 -1
  7. data/README.md +286 -0
  8. data/Rakefile +38 -8
  9. data/examples/character_spacing/character_spacing.rb +8 -0
  10. data/examples/character_spacing/character_spacing.tlf +1 -0
  11. data/examples/dynamic_image/dynamic_image.rb +31 -0
  12. data/examples/dynamic_image/dynamic_image.tlf +1 -0
  13. data/examples/dynamic_style/dynamic_style.rb +150 -0
  14. data/examples/dynamic_style/dynamic_style.tlf +1 -0
  15. data/examples/dynamic_style/dynamic_style_in_list.tlf +1 -0
  16. data/examples/eudc/eudc.rb +20 -0
  17. data/examples/eudc/eudc.tlf +1 -0
  18. data/examples/helper.rb +50 -0
  19. data/examples/hidden_shapes/hidden_shapes.rb +9 -0
  20. data/examples/hidden_shapes/hidden_shapes.tlf +1 -0
  21. data/examples/list_events/list_events.rb +59 -0
  22. data/examples/list_events/list_events_0_7_7.tlf +1 -0
  23. data/examples/list_events/list_events_0_8.tlf +1 -0
  24. data/examples/list_manual_generation/list_manual_generation.rb +22 -0
  25. data/examples/list_manual_generation/list_manual_generation.tlf +1 -0
  26. data/examples/list_page_number/list_page_number.rb +17 -0
  27. data/examples/list_page_number/list_page_number.tlf +1 -0
  28. data/examples/page_number/page_number.rb +33 -0
  29. data/examples/page_number/page_number.tlf +1 -0
  30. data/examples/password_setting/password_setting.rb +10 -0
  31. data/examples/password_setting/password_setting.tlf +1 -0
  32. data/examples/report_callbacks/report_callbacks.rb +31 -0
  33. data/examples/report_callbacks/report_callbacks.tlf +1 -0
  34. data/examples/single_line_tblock/single_line_tblock.rb +13 -0
  35. data/examples/single_line_tblock/single_line_tblock.tlf +1 -0
  36. data/examples/tblock_overflow/tblock_overflow.rb +20 -0
  37. data/examples/tblock_overflow/tblock_overflow.tlf +1 -0
  38. data/examples/tblock_styles/font_size.tlf +1 -0
  39. data/examples/tblock_styles/tblock_styles.rb +43 -0
  40. data/examples/tblock_styles/tblock_styles.tlf +1 -0
  41. data/examples/text_align/text_align.rb +8 -0
  42. data/examples/text_align/text_align.tlf +1 -0
  43. data/examples/typeB_page_size/B4_ISO.tlf +1 -0
  44. data/examples/typeB_page_size/B4_JIS.tlf +1 -0
  45. data/examples/typeB_page_size/typeB_page_size.rb +17 -0
  46. data/examples/word_wrap/word_wrap.rb +26 -0
  47. data/examples/word_wrap/word_wrap.tlf +1 -0
  48. data/lib/thinreports/config.rb +30 -10
  49. data/lib/thinreports/core/errors.rb +23 -20
  50. data/lib/thinreports/core/events.rb +18 -19
  51. data/lib/thinreports/core/format/base.rb +20 -25
  52. data/lib/thinreports/core/format/builder.rb +19 -27
  53. data/lib/thinreports/core/shape/base/interface.rb +15 -15
  54. data/lib/thinreports/core/shape/base/internal.rb +15 -20
  55. data/lib/thinreports/core/shape/base.rb +4 -5
  56. data/lib/thinreports/core/shape/basic/block_format.rb +3 -4
  57. data/lib/thinreports/core/shape/basic/block_interface.rb +9 -4
  58. data/lib/thinreports/core/shape/basic/block_internal.rb +9 -10
  59. data/lib/thinreports/core/shape/basic/format.rb +11 -10
  60. data/lib/thinreports/core/shape/basic/interface.rb +3 -3
  61. data/lib/thinreports/core/shape/basic/internal.rb +9 -6
  62. data/lib/thinreports/core/shape/basic.rb +1 -1
  63. data/lib/thinreports/core/shape/image_block/format.rb +5 -6
  64. data/lib/thinreports/core/shape/image_block/interface.rb +9 -7
  65. data/lib/thinreports/core/shape/image_block/internal.rb +5 -6
  66. data/lib/thinreports/core/shape/image_block.rb +1 -1
  67. data/lib/thinreports/core/shape/list/configuration.rb +37 -16
  68. data/lib/thinreports/core/shape/list/events.rb +11 -11
  69. data/lib/thinreports/core/shape/list/format.rb +27 -28
  70. data/lib/thinreports/core/shape/list/manager.rb +135 -95
  71. data/lib/thinreports/core/shape/list/page.rb +57 -51
  72. data/lib/thinreports/core/shape/list/page_state.rb +19 -17
  73. data/lib/thinreports/core/shape/list/section_format.rb +14 -15
  74. data/lib/thinreports/core/shape/list/section_interface.rb +15 -16
  75. data/lib/thinreports/core/shape/list/section_internal.rb +7 -8
  76. data/lib/thinreports/core/shape/list/store.rb +10 -11
  77. data/lib/thinreports/core/shape/list.rb +1 -1
  78. data/lib/thinreports/core/shape/manager/format.rb +10 -11
  79. data/lib/thinreports/core/shape/manager/internal.rb +22 -21
  80. data/lib/thinreports/core/shape/manager/target.rb +63 -34
  81. data/lib/thinreports/core/shape/manager.rb +1 -1
  82. data/lib/thinreports/core/shape/page_number/format.rb +25 -0
  83. data/lib/thinreports/core/shape/page_number/interface.rb +27 -0
  84. data/lib/thinreports/core/shape/page_number/internal.rb +57 -0
  85. data/lib/thinreports/core/shape/page_number.rb +15 -0
  86. data/lib/thinreports/core/shape/style/base.rb +29 -29
  87. data/lib/thinreports/core/shape/style/basic.rb +1 -1
  88. data/lib/thinreports/core/shape/style/graphic.rb +10 -25
  89. data/lib/thinreports/core/shape/style/text.rb +41 -31
  90. data/lib/thinreports/core/shape/style.rb +1 -1
  91. data/lib/thinreports/core/shape/text/format.rb +8 -9
  92. data/lib/thinreports/core/shape/text/interface.rb +2 -2
  93. data/lib/thinreports/core/shape/text/internal.rb +6 -7
  94. data/lib/thinreports/core/shape/text.rb +1 -1
  95. data/lib/thinreports/core/shape/text_block/format.rb +17 -17
  96. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +13 -12
  97. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +8 -9
  98. data/lib/thinreports/core/shape/text_block/formatter/number.rb +11 -12
  99. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +9 -32
  100. data/lib/thinreports/core/shape/text_block/formatter.rb +7 -8
  101. data/lib/thinreports/core/shape/text_block/interface.rb +2 -2
  102. data/lib/thinreports/core/shape/text_block/internal.rb +19 -20
  103. data/lib/thinreports/core/shape/text_block.rb +1 -1
  104. data/lib/thinreports/core/shape.rb +11 -13
  105. data/lib/thinreports/core/utils.rb +33 -32
  106. data/lib/thinreports/generator/base.rb +15 -24
  107. data/lib/thinreports/generator/configuration.rb +10 -9
  108. data/lib/thinreports/generator/pdf/configuration.rb +11 -6
  109. data/lib/thinreports/generator/pdf/document/draw_shape.rb +41 -32
  110. data/lib/thinreports/generator/pdf/document/font.rb +53 -44
  111. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +34 -25
  112. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +25 -25
  113. data/lib/thinreports/generator/pdf/document/graphics/image.rb +15 -15
  114. data/lib/thinreports/generator/pdf/document/graphics/text.rb +43 -41
  115. data/lib/thinreports/generator/pdf/document/graphics.rb +8 -9
  116. data/lib/thinreports/generator/pdf/document/page.rb +37 -23
  117. data/lib/thinreports/generator/pdf/document/parse_color.rb +9 -10
  118. data/lib/thinreports/generator/pdf/document/parse_svg.rb +14 -15
  119. data/lib/thinreports/generator/pdf/document.rb +28 -28
  120. data/lib/thinreports/generator/pdf/drawer/base.rb +16 -22
  121. data/lib/thinreports/generator/pdf/drawer/list.rb +39 -21
  122. data/lib/thinreports/generator/pdf/drawer/list_section.rb +17 -18
  123. data/lib/thinreports/generator/pdf/drawer/page.rb +37 -26
  124. data/lib/thinreports/generator/pdf/prawn_ext.rb +18 -17
  125. data/lib/thinreports/generator/pdf.rb +28 -31
  126. data/lib/thinreports/generator.rb +6 -8
  127. data/lib/thinreports/layout/base.rb +24 -36
  128. data/lib/thinreports/layout/configuration.rb +11 -9
  129. data/lib/thinreports/layout/format.rb +26 -31
  130. data/lib/thinreports/layout/version.rb +8 -9
  131. data/lib/thinreports/layout.rb +2 -2
  132. data/lib/thinreports/report/base.rb +117 -109
  133. data/lib/thinreports/report/events.rb +5 -5
  134. data/lib/thinreports/report/internal.rb +48 -38
  135. data/lib/thinreports/{core → report}/page.rb +42 -32
  136. data/lib/thinreports/report.rb +10 -14
  137. data/lib/thinreports/version.rb +2 -3
  138. data/lib/thinreports.rb +14 -2
  139. data/test/data/font.ttf +0 -0
  140. data/test/data/layout_block.tlf +1 -0
  141. data/test/data/layout_list.tlf +1 -0
  142. data/test/data/layout_list_noheader.tlf +1 -0
  143. data/test/data/layout_text1.tlf +1 -0
  144. data/test/data/layout_text2.tlf +1 -0
  145. data/test/test_helper.rb +74 -0
  146. data/test/tmp/.gitkeep +0 -0
  147. data/test/unit/core/format/test_base.rb +14 -14
  148. data/test/unit/core/format/test_builder.rb +20 -25
  149. data/test/unit/core/shape/base/test_internal.rb +34 -37
  150. data/test/unit/core/shape/basic/test_basic_format.rb +4 -4
  151. data/test/unit/core/shape/basic/test_basic_interface.rb +15 -13
  152. data/test/unit/core/shape/basic/test_basic_internal.rb +19 -16
  153. data/test/unit/core/shape/basic/test_format.rb +4 -4
  154. data/test/unit/core/shape/basic/test_interface.rb +36 -46
  155. data/test/unit/core/shape/basic/test_internal.rb +29 -18
  156. data/test/unit/core/shape/image_block/test_format.rb +5 -5
  157. data/test/unit/core/shape/image_block/test_interface.rb +17 -16
  158. data/test/unit/core/shape/image_block/test_internal.rb +19 -16
  159. data/test/unit/core/shape/list/test_configuration.rb +50 -33
  160. data/test/unit/core/shape/list/test_events.rb +7 -7
  161. data/test/unit/core/shape/list/test_format.rb +16 -18
  162. data/test/unit/core/shape/list/test_manager.rb +15 -5
  163. data/test/unit/core/shape/list/test_page.rb +80 -22
  164. data/test/unit/core/shape/list/test_page_state.rb +13 -13
  165. data/test/unit/core/shape/list/test_section_format.rb +16 -17
  166. data/test/unit/core/shape/list/test_section_interface.rb +30 -22
  167. data/test/unit/core/shape/list/test_section_internal.rb +21 -19
  168. data/test/unit/core/shape/list/test_store.rb +7 -7
  169. data/test/unit/core/shape/manager/test_format.rb +11 -15
  170. data/test/unit/core/shape/manager/test_internal.rb +9 -9
  171. data/test/unit/core/shape/manager/test_target.rb +85 -57
  172. data/test/unit/core/shape/page_number/test_format.rb +73 -0
  173. data/test/unit/core/shape/page_number/test_interface.rb +33 -0
  174. data/test/unit/core/shape/page_number/test_internal.rb +81 -0
  175. data/test/unit/core/shape/styles/test_base.rb +9 -9
  176. data/test/unit/core/shape/styles/test_basic.rb +5 -5
  177. data/test/unit/core/shape/styles/test_graphic.rb +19 -33
  178. data/test/unit/core/shape/styles/test_text.rb +29 -7
  179. data/test/unit/core/shape/text/test_format.rb +6 -6
  180. data/test/unit/core/shape/text/test_internal.rb +11 -12
  181. data/test/unit/core/shape/text_block/formatter/test_basic.rb +16 -16
  182. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +22 -20
  183. data/test/unit/core/shape/text_block/formatter/test_number.rb +34 -34
  184. data/test/unit/core/shape/text_block/formatter/test_padding.rb +44 -44
  185. data/test/unit/core/shape/text_block/test_format.rb +13 -8
  186. data/test/unit/core/shape/text_block/test_formatter.rb +17 -17
  187. data/test/unit/core/shape/text_block/test_interface.rb +37 -20
  188. data/test/unit/core/shape/text_block/test_internal.rb +38 -38
  189. data/test/unit/core/test_events.rb +10 -8
  190. data/test/unit/core/test_shape.rb +11 -7
  191. data/test/unit/core/test_utils.rb +68 -0
  192. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +10 -4
  193. data/test/unit/generator/pdf/document/graphics/test_text.rb +60 -53
  194. data/test/unit/generator/pdf/document/test_draw_shape.rb +14 -6
  195. data/test/unit/generator/pdf/document/test_font.rb +79 -58
  196. data/test/unit/generator/pdf/document/test_graphics.rb +18 -19
  197. data/test/unit/generator/pdf/document/test_page.rb +68 -43
  198. data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
  199. data/test/unit/generator/pdf/test_configuration.rb +16 -9
  200. data/test/unit/generator/pdf/test_document.rb +8 -16
  201. data/test/unit/generator/test_base.rb +31 -42
  202. data/test/unit/generator/test_configuration.rb +6 -6
  203. data/test/unit/generator/test_pdf.rb +15 -21
  204. data/test/unit/layout/test_base.rb +34 -79
  205. data/test/unit/layout/test_configuration.rb +12 -37
  206. data/test/unit/layout/test_format.rb +36 -39
  207. data/test/unit/layout/test_version.rb +4 -4
  208. data/test/unit/report/test_base.rb +160 -192
  209. data/test/unit/report/test_events.rb +4 -4
  210. data/test/unit/report/test_internal.rb +102 -82
  211. data/test/unit/test_config.rb +31 -12
  212. data/test/unit/test_layout.rb +7 -7
  213. data/test/unit/test_report.rb +12 -24
  214. data/thinreports.gemspec +23 -26
  215. metadata +118 -181
  216. data/.yardopts +0 -1
  217. data/LICENSE +0 -1
  218. data/README.rdoc +0 -167
  219. data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
  220. data/lib/thinreports/core/ext/array.rb +0 -19
  221. data/lib/thinreports/core/ext/hash.rb +0 -19
  222. data/lib/thinreports/core/ext/object.rb +0 -25
  223. data/lib/thinreports/core/ext.rb +0 -5
  224. data/lib/thinreports/core/format.rb +0 -14
  225. data/lib/thinreports/core/ordered_hash.rb +0 -39
  226. data/lib/thinreports/core.rb +0 -20
  227. data/lib/thinreports/generator/pdf/drawer.rb +0 -16
  228. data/tasks/doc.rake +0 -13
  229. data/tasks/test.rake +0 -56
  230. data/test/benchmark/basic_estimate.tlf +0 -1
  231. data/test/benchmark/bench_basic_estimate.rb +0 -95
  232. data/test/case/character_spacing/character_spacing.rb +0 -7
  233. data/test/case/character_spacing/character_spacing.tlf +0 -1
  234. data/test/case/dynamic_image/dynamic_image.rb +0 -41
  235. data/test/case/dynamic_image/dynamic_image.tlf +0 -1
  236. data/test/case/dynamic_style/dynamic_style.rb +0 -154
  237. data/test/case/dynamic_style/dynamic_style.tlf +0 -1
  238. data/test/case/dynamic_style/dynamic_style_in_list.tlf +0 -1
  239. data/test/case/eudc/eudc.rb +0 -20
  240. data/test/case/eudc/eudc.tlf +0 -1
  241. data/test/case/helper.rb +0 -29
  242. data/test/case/hidden_shapes/hidden_shapes.rb +0 -13
  243. data/test/case/hidden_shapes/hidden_shapes.tlf +0 -1
  244. data/test/case/list_events/list_events.rb +0 -32
  245. data/test/case/list_events/list_events.tlf +0 -1
  246. data/test/case/list_header_inheriting/list_header_inheriting.rb +0 -17
  247. data/test/case/list_header_inheriting/list_header_inheriting.tlf +0 -1
  248. data/test/case/list_manual_generation/list_manual_generation.rb +0 -22
  249. data/test/case/list_manual_generation/list_manual_generation.tlf +0 -1
  250. data/test/case/single_line_tblock/single_line_tblock.rb +0 -15
  251. data/test/case/single_line_tblock/single_line_tblock.tlf +0 -1
  252. data/test/case/tblock_overflow/tblock_overflow.rb +0 -20
  253. data/test/case/tblock_overflow/tblock_overflow.tlf +0 -1
  254. data/test/case/tblock_styles/tblock_styles.rb +0 -27
  255. data/test/case/tblock_styles/tblock_styles.tlf +0 -1
  256. data/test/case/text_align/text_align.rb +0 -9
  257. data/test/case/text_align/text_align.tlf +0 -1
  258. data/test/unit/core/ext/array_spec.rb +0 -29
  259. data/test/unit/core/ext/hash_spec.rb +0 -29
  260. data/test/unit/core/ext/object_spec.rb +0 -30
  261. data/test/unit/core/ordered_hash_spec.rb +0 -51
  262. data/test/unit/core/shape/base/test_interface.rb +0 -52
  263. data/test/unit/core/utils_spec.rb +0 -56
  264. data/test/unit/data/basic_layout1.tlf +0 -1
  265. data/test/unit/data/basic_layout2.tlf +0 -1
  266. data/test/unit/data/basic_list_layout.tlf +0 -1
  267. data/test/unit/data/basic_list_noheader_layout.tlf +0 -1
  268. data/test/unit/helper.rb +0 -65
  269. /data/{test/case → examples}/dynamic_image/img200x100.png +0 -0
  270. /data/{test/case → examples}/dynamic_image/img50x50.png +0 -0
  271. /data/{test/case → examples}/dynamic_style/image.png +0 -0
  272. /data/{test/case → examples}/eudc/eudc.ttf +0 -0
  273. /data/{resources/fonts → fonts}/IPA_Font_License_Agreement_v1.0.txt +0 -0
  274. /data/{resources/fonts → fonts}/ipag.ttf +0 -0
  275. /data/{resources/fonts → fonts}/ipagp.ttf +0 -0
  276. /data/{resources/fonts → fonts}/ipam.ttf +0 -0
  277. /data/{resources/fonts → fonts}/ipamp.ttf +0 -0
@@ -1,38 +1,37 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Generator
5
-
6
- # @private
5
+
7
6
  module PDF::Graphics
8
-
7
+
9
8
  BASE_LINE_WIDTH = 0.9
10
-
9
+
11
10
  private
12
11
 
13
12
  # Change the default graphic states defined by Prawn.
14
13
  def setup_custom_graphic_states
15
14
  pdf.line_width(BASE_LINE_WIDTH)
16
15
  end
17
-
16
+
18
17
  # @param [Numeric] width
19
18
  def line_width(width)
20
19
  pdf.line_width(width * BASE_LINE_WIDTH)
21
20
  end
22
-
21
+
23
22
  # Delegate to Prawn::Document#save_graphic_state
24
23
  # @see Prawn::Document#save_graphics_state
25
24
  def save_graphics_state
26
25
  pdf.save_graphics_state
27
26
  end
28
-
27
+
29
28
  # Delegate to Prawn::Document#restore_graphic_state
30
29
  # @see Prawn::Document#restore_graphics_state
31
30
  def restore_graphics_state
32
31
  pdf.restore_graphics_state
33
32
  end
34
33
  end
35
-
34
+
36
35
  end
37
36
  end
38
37
 
@@ -1,17 +1,21 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Generator
5
-
6
- # @private
5
+
7
6
  module PDF::Page
8
-
9
- # @param [ThinReports::Layout::Format] format
7
+ # Add JIS-B4,B5 page geometry
8
+ ::PDF::Core::PageGeometry::SIZES.update(
9
+ 'B4_JIS' => [728.5, 1031.8],
10
+ 'B5_JIS' => [515.9, 728.5]
11
+ )
12
+
13
+ # @param [Thinreports::Layout::Format] format
10
14
  def start_new_page(format)
11
15
  format_id = if change_page_format?(format)
12
16
  pdf.start_new_page(new_basic_page_options(format))
13
17
  @current_page_format = format
14
-
18
+
15
19
  unless format_stamp_registry.include?(format.identifier)
16
20
  create_format_stamp(format)
17
21
  end
@@ -20,51 +24,61 @@ module ThinReports
20
24
  pdf.start_new_page(new_basic_page_options(current_page_format))
21
25
  current_page_format.identifier
22
26
  end
23
-
27
+
24
28
  stamp(format_id.to_s)
25
29
  end
26
-
30
+
27
31
  def add_blank_page
28
- pdf.start_new_page(pdf.page_count.zero? ? {:size => 'A4'} : {})
32
+ pdf.start_new_page(pdf.page_count.zero? ? {size: 'A4'} : {})
29
33
  end
30
-
34
+
31
35
  private
32
-
33
- # @return [ThinReports::Layout::Format]
36
+
37
+ # @return [Thinreports::Layout::Format]
34
38
  attr_reader :current_page_format
35
-
36
- # @param [ThinReports::Layout::Format] new_format
39
+
40
+ # @param [Thinreports::Layout::Format] new_format
37
41
  # @return [Boolean]
38
42
  def change_page_format?(new_format)
39
43
  !current_page_format ||
40
44
  current_page_format.identifier != new_format.identifier
41
45
  end
42
-
43
- # @param [ThinReports::Layout::Format] format
46
+
47
+ # @param [Thinreports::Layout::Format] format
44
48
  def create_format_stamp(format)
45
49
  create_stamp(format.identifier.to_s) do
46
50
  parse_svg(format.layout, '/svg/g')
47
51
  end
48
52
  format_stamp_registry << format.identifier
49
53
  end
50
-
54
+
51
55
  # @return [Array]
52
56
  def format_stamp_registry
53
57
  @format_stamp_registry ||= []
54
58
  end
55
-
56
- # @param [ThinReports::Layout::Format] format
59
+
60
+ # @param [Thinreports::Layout::Format] format
57
61
  # @return [Hash]
58
62
  def new_basic_page_options(format)
59
- options = {:layout => format.page_orientation.to_sym}
63
+ options = {layout: format.page_orientation.to_sym}
64
+
60
65
  options[:size] = if format.user_paper_type?
61
66
  [format.page_width.to_f, format.page_height.to_f]
62
67
  else
63
- format.page_paper_type
68
+ case format.page_paper_type
69
+ # Convert B4(5)_ISO to B4(5)
70
+ when 'B4_ISO', 'B5_ISO'
71
+ format.page_paper_type.delete('_ISO')
72
+ # Convert B4(5) to B4(5)_JIS
73
+ when 'B4', 'B5'
74
+ "#{format.page_paper_type}_JIS"
75
+ else
76
+ format.page_paper_type
77
+ end
64
78
  end
65
79
  options
66
80
  end
67
81
  end
68
-
82
+
69
83
  end
70
- end
84
+ end
@@ -1,24 +1,23 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Generator
5
-
6
- # @private
5
+
7
6
  module PDF::ParseColor
8
7
  # @param [String] color
9
8
  # @return [String]
10
9
  def parse_color(color)
11
10
  color = color.downcase
12
-
11
+
13
12
  unless color =~ /^#?[\da-f]{6}$/
14
13
  find_color_from_name(color)
15
14
  else
16
15
  color.delete('#')
17
16
  end
18
17
  end
19
-
18
+
20
19
  private
21
-
20
+
22
21
  # Supported only SAFE COLORS.
23
22
  SUPPORTED_COLOR_NAMES = {
24
23
  'red' => 'ff0000',
@@ -38,14 +37,14 @@ module ThinReports
38
37
  'silver' => 'c0c0c0',
39
38
  'white' => 'ffffff'
40
39
  }
41
-
40
+
42
41
  def find_color_from_name(name)
43
42
  unless color = SUPPORTED_COLOR_NAMES[name]
44
- raise ThinReports::Errors::UnsupportedColorName, name
43
+ raise Thinreports::Errors::UnsupportedColorName, name
45
44
  end
46
45
  color
47
46
  end
48
47
  end
49
-
48
+
50
49
  end
51
- end
50
+ end
@@ -2,16 +2,15 @@
2
2
 
3
3
  require 'rexml/document'
4
4
 
5
- module ThinReports
5
+ module Thinreports
6
6
  module Generator
7
-
8
- # @private
7
+
9
8
  module PDF::ParseSVG
10
9
  # @param [String] source
11
10
  # @param [String] base_path
12
11
  def parse_svg(source, base_path)
13
12
  svg = REXML::Document.new(clean_svg(source))
14
-
13
+
15
14
  svg.elements[base_path].each do |elm|
16
15
  case elm.attributes['class']
17
16
  when 's-text' then draw_svg_text(elm)
@@ -23,15 +22,15 @@ module ThinReports
23
22
  end
24
23
  svg = nil
25
24
  end
26
-
25
+
27
26
  private
28
-
27
+
29
28
  # @param [String] source
30
29
  # @return [String]
31
30
  def clean_svg(source)
32
31
  source.gsub(/<%.+?%>/, '')
33
32
  end
34
-
33
+
35
34
  # @param [REXML::Element] elm
36
35
  # @param [Array<String>] keys
37
36
  # @return [Array<String>]
@@ -41,7 +40,7 @@ module ThinReports
41
40
  values << attrs[key]
42
41
  end
43
42
  end
44
-
43
+
45
44
  # @param [REXML::Element] elm
46
45
  def draw_svg_rect(elm)
47
46
  x, y, w, h = element_attributes_values_at(elm, 'x', 'y', 'width', 'height')
@@ -50,21 +49,21 @@ module ThinReports
50
49
  end
51
50
  rect(x, y, w, h, attributes)
52
51
  end
53
-
52
+
54
53
  # @see #draw_svg_rect
55
54
  def draw_svg_ellipse(elm)
56
55
  x, y, rx, ry = element_attributes_values_at(elm, 'cx', 'cy', 'rx', 'ry')
57
56
  ellipse(x, y, rx, ry,
58
57
  common_graphic_attrs(elm.attributes))
59
58
  end
60
-
59
+
61
60
  # @see #draw_svg_rect
62
61
  def draw_svg_line(elm)
63
62
  x1, y1, x2, y2 = element_attributes_values_at(elm, 'x1', 'y1', 'x2', 'y2')
64
63
  line(x1, y1, x2, y2,
65
64
  common_graphic_attrs(elm.attributes))
66
65
  end
67
-
66
+
68
67
  # @see #draw_svg_rect
69
68
  def draw_svg_text(elm)
70
69
  x, y, w, h = element_attributes_values_at(elm, 'x-left', 'x-top',
@@ -75,14 +74,14 @@ module ThinReports
75
74
  end
76
75
  text(content.join("\n"), x, y, w, h, svg_text_attrs(elm.attributes))
77
76
  end
78
-
77
+
79
78
  # @see #draw_svg_rect
80
79
  def draw_svg_image(elm)
81
80
  x, y, w, h = element_attributes_values_at(elm, 'x', 'y', 'width', 'height')
82
81
  base64image(extract_base64_string(elm.attributes['xlink:href']),
83
82
  x, y, w, h)
84
83
  end
85
-
84
+
86
85
  # @param [Hash] attributes
87
86
  # @return [Hash]
88
87
  def svg_text_attrs(attributes)
@@ -95,8 +94,8 @@ module ThinReports
95
94
  attrs[:valign] = text_valign(attributes['x-valign'])
96
95
  end
97
96
  end
98
-
97
+
99
98
  end
100
-
99
+
101
100
  end
102
101
  end
@@ -7,39 +7,43 @@ require 'thinreports/generator/pdf/document/draw_shape'
7
7
  require 'thinreports/generator/pdf/document/parse_svg'
8
8
  require 'thinreports/generator/pdf/document/page'
9
9
 
10
- module ThinReports
10
+ module Thinreports
11
11
  module Generator
12
-
13
- # @private
12
+
14
13
  class PDF::Document
14
+ include Utils
15
+
15
16
  include PDF::Font
16
17
  include PDF::ParseColor
17
18
  include PDF::Graphics
18
19
  include PDF::DrawShape
19
20
  include PDF::ParseSVG
20
21
  include PDF::Page
21
-
22
- # @param options (see ThinReports::Generator::PDF#initialize)
22
+
23
+ # @return [Prawn::Document]
24
+ attr_reader :pdf
25
+
26
+ # @param options (see Thinreports::Generator::PDF#initialize)
23
27
  # @param [Hash] metadata
24
28
  # @option metadata [String] :Title
25
29
  def initialize(options = {}, metadata = {})
26
30
  @pdf = Prawn::Document.new(
27
- :skip_page_creation => true,
28
- :margin => [0, 0],
29
- :info => {:CreationDate => Time.now,
30
- :Creator => 'ThinReports Generator for Ruby ' +
31
- ThinReports::VERSION}.merge(metadata)
31
+ skip_page_creation: true,
32
+ margin: [0, 0],
33
+ info: {CreationDate: Time.now,
34
+ Creator: 'Thinreports Generator for Ruby ' +
35
+ Thinreports::VERSION}.merge(metadata)
32
36
  )
33
37
  # Setup to Prawn::Document.
34
38
  setup_fonts
35
39
  setup_custom_graphic_states
36
-
40
+
37
41
  # Encrypts the document.
38
42
  if options[:security]
39
43
  @pdf.encrypt_document(options[:security])
40
44
  end
41
45
  end
42
-
46
+
43
47
  # Delegate to Prawn::Document#render
44
48
  # @see Prawn::Document#render
45
49
  def render
@@ -47,21 +51,21 @@ module ThinReports
47
51
  finalize
48
52
  result
49
53
  end
50
-
54
+
51
55
  # Delegate to Prawn::Document#render_file
52
56
  # @see Prawn::Document#render_file
53
57
  def render_file(*args)
54
58
  finalize
55
59
  pdf.render_file(*args)
56
60
  end
57
-
61
+
58
62
  # @param [Numeric, String] x
59
63
  # @param [Numeric, String] y
60
64
  def translate(x, y, &block)
61
65
  x, y = rpos(x, y)
62
66
  pdf.translate(x, y, &block)
63
67
  end
64
-
68
+
65
69
  # @param [String] stamp_id
66
70
  # @param [Array<Numeric>] at (nil)
67
71
  def stamp(stamp_id, at = nil)
@@ -71,34 +75,30 @@ module ThinReports
71
75
  pdf.stamp(stamp_id)
72
76
  end
73
77
  end
74
-
78
+
75
79
  # Delegate to Prawn::Document#create_stamp
76
80
  # @param [String] id
77
81
  # @see Prawn::Document#create_stamp
78
82
  def create_stamp(id, &block)
79
83
  pdf.create_stamp(id, &block)
80
84
  end
81
-
82
- # @private
85
+
83
86
  # @see #pdf
84
87
  def internal
85
88
  @pdf
86
89
  end
87
-
90
+
88
91
  private
89
-
90
- # @return [Prawn::Document]
91
- attr_reader :pdf
92
-
92
+
93
93
  def finalize
94
94
  clean_temp_images
95
95
  end
96
-
96
+
97
97
  # @param [Array<String, Numeric>] values
98
98
  # @return [Numeric, Array<Numeric>, nil]
99
99
  def s2f(*values)
100
100
  return nil if values.empty?
101
-
101
+
102
102
  if values.size == 1
103
103
  if value = values.first
104
104
  value.is_a?(::Numeric) ? value : value.to_f
@@ -107,7 +107,7 @@ module ThinReports
107
107
  values.map {|v| s2f(v) }
108
108
  end
109
109
  end
110
-
110
+
111
111
  # @param [Numeric, String] x
112
112
  # @param [Numeric, String] y
113
113
  # @return [Array<Float>]
@@ -116,7 +116,7 @@ module ThinReports
116
116
  [x, -y]
117
117
  end
118
118
  alias_method :rpos, :map_to_upper_left_relative_position
119
-
119
+
120
120
  # @param [Numeric, String] x
121
121
  # @param [Numeric, String] y
122
122
  # @return [Array<Float>]
@@ -126,6 +126,6 @@ module ThinReports
126
126
  end
127
127
  alias_method :pos, :map_to_upper_left_position
128
128
  end
129
-
129
+
130
130
  end
131
131
  end
@@ -1,54 +1,48 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
4
- module Generator
5
-
3
+ module Thinreports
4
+ module Generator::PDF::Drawer
5
+
6
6
  # @abstract
7
- # @private
8
- class PDF::Drawer::Base
9
- # @param [ThinReports::Generator::PDF::Document] pdf
10
- # @param [ThinReports::Core::Shape::Manager::Format] format
7
+ class Base
8
+ # @param [Thinreports::Generator::PDF::Document] pdf
9
+ # @param [Thinreports::Core::Shape::Manager::Format] format
11
10
  def initialize(pdf, format)
12
11
  @pdf = pdf
13
12
  @format = format
14
13
  @stamps = []
15
14
  @draw_at = nil
16
15
  end
17
-
16
+
18
17
  # @abstract
19
18
  def draw
20
19
  raise NotImplementedError
21
20
  end
22
-
21
+
23
22
  private
24
-
25
- # @param [ThinReports::Core::Shape::Base::Internal] shape
23
+
24
+ # @param [Thinreports::Core::Shape::Base::Internal] shape
26
25
  # @return [String]
27
26
  def pdf_stamp_id(shape)
28
- "#{@format.identifier}#{shape_stamp_id(shape)}"
27
+ "#{@format.identifier}#{shape.identifier}"
29
28
  end
30
-
31
- # @see #pdf_stamp_id
32
- def shape_stamp_id(shape)
33
- "#{shape.id}#{shape.style.identifier}"
34
- end
35
-
29
+
36
30
  # @overload pdf_stamp(shape_id)
37
31
  # @param [String] shape_id
38
32
  # @overload pdf_stamp(shape)
39
- # @param [ThinReports::Core::Shape::Base::Internal] shape
33
+ # @param [Thinreports::Core::Shape::Base::Internal] shape
40
34
  def pdf_stamp(shape)
41
35
  unless shape.is_a?(::String)
42
36
  shape = pdf_stamp_id(shape)
43
37
  end
44
38
  @pdf.stamp(shape, @draw_at)
45
39
  end
46
-
47
- # @param [ThinReports::Core::Shape::Base::Internal] shape
40
+
41
+ # @param [Thinreports::Core::Shape::Base::Internal] shape
48
42
  def create_pdf_stamp(shape, &block)
49
43
  @pdf.create_stamp(pdf_stamp_id(shape), &block)
50
44
  end
51
45
  end
52
-
46
+
53
47
  end
54
48
  end
@@ -1,39 +1,57 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
4
- module Generator
5
-
6
- # @private
7
- class PDF::Drawer::List < PDF::Drawer::Base
3
+ module Thinreports
4
+ module Generator::PDF::Drawer
5
+
6
+ class List < Base
8
7
  # @param (see PDF::Drawer::Base#initialize)
9
8
  def initialize(pdf, format)
10
9
  super
11
10
  @sections = {}
12
11
  end
13
-
14
- # @param [ThinReports::Core::Shape::List::PageState] list
15
- def draw(list)
16
- draw_section(list.header) if list.header
17
- list.rows.each do |row|
12
+
13
+ # @param [Thinreports::Core::Shape::List::PageState] list_page
14
+ def draw(list_page)
15
+ draw_section(list_page.header) if list_page.header
16
+ list_page.rows.each do |row|
18
17
  draw_section(row)
19
18
  end
19
+
20
+ # Returns Thinreports::Report::Page object
21
+ manager = list_page.parent.manager
22
+
23
+ list_id = list_page.id.to_s
24
+ manager.format.shapes.each do |id, shape|
25
+ next unless list_pageno?(list_id, shape)
26
+
27
+ shape = manager.final_shape(id)
28
+ @pdf.draw_shape_pageno(shape.internal,
29
+ list_page.no, list_page.manager.page_count)
30
+ end
20
31
  end
21
-
22
- private
23
-
24
- # @param [ThinReports::Core::Shape::List::SectionInterface] section
32
+
33
+ private
34
+
35
+ # @param [String] list_id
36
+ # @param [Thinreports::Core::Shape::Base::Format] shape
37
+ # @return [Boolean]
38
+ def list_pageno?(list_id, shape)
39
+ shape.type == Thinreports::Core::Shape::PageNumber::TYPE_NAME &&
40
+ shape.target == list_id
41
+ end
42
+
43
+ # @param [Thinreports::Core::Shape::List::SectionInterface] section
25
44
  def draw_section(section)
26
45
  internal = section.internal
27
- drawer(internal).draw(section.manager, internal.relative_position)
46
+ drawer(internal).draw(section, internal.relative_position)
28
47
  end
29
-
30
- # @param [ThinReports::Core::Shape::List::SectionInternal] section
31
- # @return [ThinReports::Generator::PDF::Drawer::ListSection]
48
+
49
+ # @param [Thinreports::Core::Shape::List::SectionInternal] section
50
+ # @return [Thinreports::Generator::PDF::Drawer::ListSection]
32
51
  def drawer(section)
33
- @sections[section.section_name] ||=
34
- PDF::Drawer::ListSection.new(@pdf, section)
52
+ @sections[section.section_name] ||= ListSection.new(@pdf, section)
35
53
  end
36
54
  end
37
-
55
+
38
56
  end
39
57
  end
@@ -1,31 +1,30 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
4
- module Generator
5
-
6
- # @private
7
- class PDF::Drawer::ListSection < PDF::Drawer::Page
3
+ module Thinreports
4
+ module Generator::PDF::Drawer
5
+
6
+ class ListSection < Page
8
7
  # @param pdf (see PDF::Drawer::Page#initialize)
9
- # @param section [ThinReports::Core::Shape::List::SectionInternal] section
8
+ # @param section [Thinreports::Core::Shape::List::SectionInternal] section
10
9
  def initialize(pdf, section)
11
10
  super(pdf, section.format)
12
11
  @section = section
13
12
  @stamp_created = false
14
13
  end
15
-
16
- # @param [ThinReports::Core::Shape::Manager::Internal] manager
14
+
15
+ # @param [Thinreports::Core::Shape::List::SectionInternal] section
17
16
  # @param [Array<Numeric>] at
18
- def draw(manager, at)
17
+ def draw(section, at)
19
18
  @draw_at = at
20
19
  draw_section
21
- super(manager)
20
+ super(section)
22
21
  end
23
-
22
+
24
23
  private
25
-
24
+
26
25
  def draw_section
27
26
  id = @format.identifier.to_s
28
-
27
+
29
28
  unless @stamp_created
30
29
  @pdf.create_stamp(id) do
31
30
  @pdf.parse_svg('<svg xmlns:xlink="http://www.w3.org/1999/xlink">' +
@@ -35,17 +34,17 @@ module ThinReports
35
34
  end
36
35
  pdf_stamp(id)
37
36
  end
38
-
39
- # @see ThinReports::Generator::PDF::Drawer::Page#draw_tblock_shape
37
+
38
+ # @see Thinreports::Generator::PDF::Drawer::Page#draw_tblock_shape
40
39
  def draw_tblock_shape(shape)
41
40
  @pdf.translate(*@draw_at) { super }
42
41
  end
43
-
44
- # @see ThinReports::Generator::PDF::Drawer::Page#draw_iblock_shape
42
+
43
+ # @see Thinreports::Generator::PDF::Drawer::Page#draw_iblock_shape
45
44
  def draw_iblock_shape(shape)
46
45
  @pdf.translate(*@draw_at) { super }
47
46
  end
48
47
  end
49
-
48
+
50
49
  end
51
50
  end