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,75 +1,84 @@
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::Font
8
- FONT_STORE = File.join(ThinReports::ROOTDIR, 'resources', 'fonts')
9
-
7
+ FONT_STORE = File.join(Thinreports::ROOT, 'fonts')
8
+
10
9
  BUILTIN_FONTS = {
11
- 'IPAMincho' => {:normal => File.join(FONT_STORE, 'ipam.ttf')},
12
- 'IPAPMincho' => {:normal => File.join(FONT_STORE, 'ipamp.ttf')},
13
- 'IPAGothic' => {:normal => File.join(FONT_STORE, 'ipag.ttf')},
14
- 'IPAPGothic' => {:normal => File.join(FONT_STORE, 'ipagp.ttf')}
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
+ }
15
+
16
+ DEFAULT_FALLBACK_FONTS = %w( Helvetica IPAMincho )
17
+
18
+ PRAWN_BUINTIN_FONT_ARIASES = {
19
+ 'Courier New' => 'Courier',
20
+ 'Times New Roman' => 'Times-Roman'
15
21
  }
16
-
17
- private
18
-
22
+
19
23
  def setup_fonts
20
24
  # Install built-in fonts.
21
25
  pdf.font_families.update(BUILTIN_FONTS)
22
-
26
+
27
+ # Create aliases from the font list provided by Prawn.
28
+ PRAWN_BUINTIN_FONT_ARIASES.each do |alias_name, name|
29
+ pdf.font_families[alias_name] = pdf.font_families[name]
30
+ end
31
+
32
+ # Setup custom fallback fonts
23
33
  fallback_fonts = []
24
-
25
- # Install EUDC fonts.
26
- ThinReports.config.generator.pdf.eudc_fonts.each_with_index do |eudc, i|
27
- eudc_name = "EUDC#{i}"
28
- install_font_family(eudc_name, eudc)
29
- fallback_fonts << eudc_name
34
+ # For compatible to v0.7 or less
35
+ fallback_fonts |= Thinreports.config.generator.pdf.eudc_fonts
36
+ fallback_fonts |= Thinreports.config.fallback_fonts
37
+ fallback_fonts.uniq!
38
+
39
+ fallback_fonts.map!.with_index do |font, i|
40
+ unless pdf.font_families.key?(font)
41
+ install_font "Custom-fallback-font#{i}", font
42
+ else
43
+ font
44
+ end
30
45
  end
31
-
32
- # Install fall-back font(default font) that IPAMincho.
33
- install_font_family('DefaultFont', BUILTIN_FONTS['IPAMincho'][:normal])
34
- fallback_fonts << 'DefaultFont'
35
-
36
- # Setup fallback fonts.
37
- pdf.fallback_fonts(fallback_fonts)
38
-
39
- # Create aliases from the font list provided by Prawn.
40
- pdf.font_families.update(
41
- 'Courier New' => pdf.font_families['Courier'],
42
- 'Times New Roman' => pdf.font_families['Times-Roman']
43
- )
46
+
47
+ # Set fallback fonts
48
+ pdf.fallback_fonts(fallback_fonts + DEFAULT_FALLBACK_FONTS)
44
49
  end
45
-
50
+
46
51
  # @param [String] name
47
52
  # @param [String] file
48
- def install_font_family(name, file)
49
- pdf.font_families[name] = {:normal => file,
50
- :bold => file,
51
- :italic => file,
52
- :bold_italic => file}
53
+ # @return [String] installed font name
54
+ def install_font(name, file)
55
+ raise Errors::FontFileNotFound unless File.exists?(file)
56
+
57
+ pdf.font_families[name] = {normal: file,
58
+ bold: file,
59
+ italic: file,
60
+ bold_italic: file}
61
+ name
53
62
  end
54
-
63
+
55
64
  # @return [String]
56
65
  def default_family
57
66
  'Helvetica'
58
67
  end
59
-
68
+
60
69
  # @param [String] family
61
70
  # @return [String]
62
71
  def default_family_if_missing(family)
63
72
  pdf.font_families.key?(family) ? family : default_family
64
73
  end
65
-
74
+
66
75
  # @param [String] font
67
76
  # @param [Symbol] style
68
77
  # @return [Boolean]
69
78
  def font_has_style?(font, style)
70
79
  (f = pdf.font_families[font]) && f.key?(style)
71
- end
80
+ end
72
81
  end
73
-
82
+
74
83
  end
75
- end
84
+ end
@@ -1,23 +1,23 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Generator
5
-
5
+
6
6
  module PDF::Graphics
7
7
  # @param [Hash] svg_attrs
8
8
  # @yield [attrs]
9
9
  # @yieldparam [Hash] attrs
10
10
  # @return [Hash]
11
11
  def common_graphic_attrs(svg_attrs, &block)
12
- attrs = {:stroke => svg_attrs['stroke'],
13
- :stroke_width => svg_attrs['stroke-width'],
14
- :fill => svg_attrs['fill']}
15
-
12
+ attrs = {stroke: svg_attrs['stroke'],
13
+ stroke_width: svg_attrs['stroke-width'],
14
+ fill: svg_attrs['fill']}
15
+
16
16
  # Set 0 to stroke_width if stroke_opacity is '0'.
17
17
  if svg_attrs['stroke-opacity'] == '0'
18
18
  attrs[:stroke_width] = 0
19
19
  end
20
-
20
+
21
21
  # Setting for stroke dash.
22
22
  if (dash = svg_attrs['stroke-dasharray']) && dash != 'none'
23
23
  attrs[:stroke_dash] = dash.split(',')
@@ -25,40 +25,40 @@ module ThinReports
25
25
  block.call(attrs) if block_given?
26
26
  attrs
27
27
  end
28
-
28
+
29
29
  # @param [Hash] svg_attrs
30
30
  # @yield [attrs]
31
31
  # @yieldparam [Hash] attrs
32
32
  # @return [Hash]
33
33
  def common_text_attrs(svg_attrs, &block)
34
- attrs = {:font => default_family_if_missing(svg_attrs['font-family']),
35
- :size => svg_attrs['font-size'],
36
- :color => svg_attrs['fill'],
37
- :align => text_align(svg_attrs['text-anchor']),
38
- :styles => font_styles(svg_attrs)}
39
-
34
+ attrs = {font: default_family_if_missing(svg_attrs['font-family']),
35
+ size: svg_attrs['font-size'],
36
+ color: svg_attrs['fill'],
37
+ align: text_align(svg_attrs['text-anchor']),
38
+ styles: font_styles(svg_attrs)}
39
+
40
40
  # The Letter Spacing Property.
41
- #
41
+ #
42
42
  # When the version of Layout is
43
- # smaller then 0.6.0:
43
+ # smaller then 0.6.0:
44
44
  # Use letter-spacing attribute (normal is none).
45
45
  # 0.6.0 or more:
46
46
  # Use kerning attribute (auto is none).
47
- #
47
+ #
48
48
  if space = text_letter_spacing(svg_attrs['kerning'] || svg_attrs['letter-spacing'])
49
49
  attrs[:letter_spacing] = space
50
50
  end
51
51
  block.call(attrs) if block_given?
52
52
  attrs
53
53
  end
54
-
54
+
55
55
  # @param [Hash] svg_attrs
56
56
  # @return [Array<Symbol>]
57
57
  def font_styles(svg_attrs)
58
58
  styles = []
59
59
  styles << :bold if svg_attrs['font-weight'] == 'bold'
60
60
  styles << :italic if svg_attrs['font-style'] == 'italic'
61
-
61
+
62
62
  if (deco = svg_attrs['text-decoration']) && deco != 'none'
63
63
  deco = deco.split(' ')
64
64
  styles << :underline if deco.include?('underline')
@@ -66,13 +66,13 @@ module ThinReports
66
66
  end
67
67
  styles
68
68
  end
69
-
69
+
70
70
  # @param [String] space
71
71
  # @return [String, nil]
72
72
  def text_letter_spacing(space)
73
73
  %w( normal auto ).include?(space) ? nil : space
74
74
  end
75
-
75
+
76
76
  # @param [String] svg_align
77
77
  # @return [Symbol]
78
78
  def text_align(svg_align)
@@ -83,7 +83,7 @@ module ThinReports
83
83
  else :left
84
84
  end
85
85
  end
86
-
86
+
87
87
  # @param [String] svg_valign
88
88
  # @return [Symbol]
89
89
  def text_valign(svg_valign)
@@ -94,7 +94,7 @@ module ThinReports
94
94
  else :top
95
95
  end
96
96
  end
97
-
97
+
98
98
  # @param [String] overflow
99
99
  # @return [Symbol]
100
100
  def text_overflow(overflow)
@@ -105,13 +105,22 @@ module ThinReports
105
105
  else :truncate
106
106
  end
107
107
  end
108
-
108
+
109
+ # @param [String] word_wrap
110
+ # @return [Symbol]
111
+ def text_word_wrap(word_wrap)
112
+ case word_wrap
113
+ when 'break-word' then :break_word
114
+ else :none
115
+ end
116
+ end
117
+
109
118
  # @param [String] xlink
110
119
  # @return [String]
111
120
  def extract_base64_string(xlink)
112
121
  xlink.sub(%r{^data:image/[a-z]+?;base64,}, '')
113
122
  end
114
123
  end
115
-
124
+
116
125
  end
117
126
  end
@@ -1,8 +1,8 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Generator
5
-
5
+
6
6
  module PDF::Graphics
7
7
  # @param [Numeric, String] x1
8
8
  # @param [Numeric, String] y1
@@ -17,7 +17,7 @@ module ThinReports
17
17
  pdf.line(pos(x1, y1), pos(x2, y2))
18
18
  end
19
19
  end
20
-
20
+
21
21
  # @param [Numeric, String] x
22
22
  # @param [Numeric, String] y
23
23
  # @param [Numeric, String] w width
@@ -31,7 +31,7 @@ module ThinReports
31
31
  def rect(x, y, w, h, attrs = {})
32
32
  w, h = s2f(w, h)
33
33
  radius = s2f(attrs[:radius])
34
-
34
+
35
35
  with_graphic_styles(attrs) do
36
36
  if radius && !radius.zero?
37
37
  pdf.rounded_rectangle(pos(x, y), w, h, radius)
@@ -40,7 +40,7 @@ module ThinReports
40
40
  end
41
41
  end
42
42
  end
43
-
43
+
44
44
  # @param [Numeric, String] x center-x
45
45
  # @param [Numeric, String] y center-y
46
46
  # @param [Numeric, String] rx
@@ -52,30 +52,30 @@ module ThinReports
52
52
  # @option attrs [String] :fill
53
53
  def ellipse(x, y, rx, ry, attrs = {})
54
54
  rx, ry = s2f(rx, ry)
55
-
55
+
56
56
  with_graphic_styles(attrs) do
57
57
  pdf.ellipse(pos(x, y), rx, ry)
58
58
  end
59
59
  end
60
-
60
+
61
61
  private
62
-
62
+
63
63
  # @param [Hash] attrs
64
64
  def with_graphic_styles(attrs, &block)
65
65
  stroke = build_stroke_styles(attrs)
66
66
  fill = build_fill_styles(attrs)
67
-
67
+
68
68
  # Do not draw if no colors given.
69
69
  return unless fill || stroke
70
-
70
+
71
71
  save_graphics_state
72
72
 
73
73
  # Apply stroke-dashed.
74
74
  if stroke && stroke[:dash]
75
75
  length, space = stroke[:dash]
76
- pdf.dash(length, :space => space)
76
+ pdf.dash(length, space: space)
77
77
  end
78
-
78
+
79
79
  case
80
80
  # Draw with fill and stroke.
81
81
  when fill && stroke
@@ -99,34 +99,34 @@ module ThinReports
99
99
  block.call
100
100
  }
101
101
  end
102
-
102
+
103
103
  restore_graphics_state
104
- end
105
-
104
+ end
105
+
106
106
  # @param [Hash] styles
107
107
  # @return [Hash, nil]
108
108
  def build_stroke_styles(styles)
109
109
  color = styles[:stroke]
110
110
  width = styles[:stroke_width]
111
-
111
+
112
112
  if color && color != 'none' && width && width != 0
113
- {:color => parse_color(color),
114
- :width => s2f(width),
115
- :dash => s2f(*styles[:stroke_dash])}
113
+ {color: parse_color(color),
114
+ width: s2f(width),
115
+ dash: s2f(*styles[:stroke_dash])}
116
116
  end
117
117
  end
118
-
118
+
119
119
  # @param [Hash] styles
120
120
  # @return [Hash, nil]
121
121
  def build_fill_styles(styles)
122
122
  color = styles[:fill]
123
-
123
+
124
124
  if color && color != 'none'
125
- {:color => parse_color(color)}
125
+ {color: parse_color(color)}
126
126
  end
127
- end
128
-
127
+ end
128
+
129
129
  end
130
-
130
+
131
131
  end
132
132
  end
@@ -3,9 +3,9 @@
3
3
  require 'tempfile'
4
4
  require 'base64'
5
5
 
6
- module ThinReports
6
+ module Thinreports
7
7
  module Generator
8
-
8
+
9
9
  module PDF::Graphics
10
10
  # @param [String] filename
11
11
  # @param [Numeric, Strng] x
@@ -14,9 +14,9 @@ module ThinReports
14
14
  # @param [Numeric, Strng] h
15
15
  def image(filename, x, y, w, h)
16
16
  w, h = s2f(w, h)
17
- pdf.image(filename, :at => pos(x, y), :width => w, :height => h)
17
+ pdf.image(filename, at: pos(x, y), width: w, height: h)
18
18
  end
19
-
19
+
20
20
  # @param [String] base64
21
21
  # @param [Numeric, Strng] x
22
22
  # @param [Numeric, Strng] y
@@ -26,7 +26,7 @@ module ThinReports
26
26
  image = create_temp_imagefile(base64)
27
27
  image(image.path, x, y, w, h)
28
28
  end
29
-
29
+
30
30
  # @param file (see Prawn#image)
31
31
  # @param [Numeric, Strng] x
32
32
  # @param [Numeric, Strng] y
@@ -37,23 +37,23 @@ module ThinReports
37
37
  # @option options [:top, :center, :bottom] :position_y (:top)
38
38
  def image_box(file, x, y, w, h, options = {})
39
39
  w, h = s2f(w, h)
40
- pdf.bounding_box(pos(x, y), :width => w, :height => h) do
41
- pdf.image(file, :position => options[:position_x] || :left,
42
- :vposition => options[:position_y] || :top,
43
- :auto_fit => [w, h])
40
+ pdf.bounding_box(pos(x, y), width: w, height: h) do
41
+ pdf.image(file, position: options[:position_x] || :left,
42
+ vposition: options[:position_y] || :top,
43
+ auto_fit: [w, h])
44
44
  end
45
45
  end
46
-
46
+
47
47
  private
48
-
48
+
49
49
  def clean_temp_images
50
50
  temp_image_registry.each {|tmp| tmp.unlink }
51
51
  end
52
-
52
+
53
53
  def temp_image_registry
54
54
  @temp_image_registry ||= []
55
55
  end
56
-
56
+
57
57
  # @param [String] base64
58
58
  # @return [Tempfile]
59
59
  def create_temp_imagefile(base64)
@@ -64,8 +64,8 @@ module ThinReports
64
64
  file
65
65
  ensure
66
66
  file.close
67
- end
67
+ end
68
68
  end
69
-
69
+
70
70
  end
71
71
  end
@@ -1,8 +1,8 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Generator
5
-
5
+
6
6
  module PDF::Graphics
7
7
  # @param [String] content
8
8
  # @param [Numeric, String] x
@@ -21,32 +21,34 @@ module ThinReports
21
21
  # @option attrs [Numeric, String] :letter_spacing
22
22
  # @option attrs [Boolean] :single (false)
23
23
  # @option attrs [:trancate, :shrink_to_fit, :expand] :overflow (:trancate)
24
+ # @option attrs [:none, :break_word] :word_wrap (:none)
24
25
  def text_box(content, x, y, w, h, attrs = {})
25
26
  w, h = s2f(w, h)
26
- box_attrs = text_box_attrs(x, y, w, h, :single => attrs.delete(:single),
27
- :overflow => attrs[:overflow])
28
-
27
+ box_attrs = text_box_attrs(x, y, w, h, single: attrs.delete(:single),
28
+ overflow: attrs[:overflow])
29
+ # Do not break by word unless :word_wrap is :break_word
30
+ content = text_without_line_wrap(content) if attrs[:word_wrap] == :none
31
+
29
32
  with_text_styles(attrs) do |built_attrs, font_styles|
30
- pdf.formatted_text_box([{:text => text_without_line_wrap(content),
31
- :styles => font_styles}],
32
- built_attrs.merge(box_attrs))
33
+ pdf.formatted_text_box([{ text: content, styles: font_styles }],
34
+ built_attrs.merge(box_attrs))
33
35
  end
34
36
  rescue Prawn::Errors::CannotFit => e
35
37
  # Nothing to do.
36
- #
38
+ #
37
39
  # When the area is too small compared
38
40
  # with the content and the style of the text.
39
41
  # (See prawn/core/text/formatted/line_wrap.rb#L185)
40
42
  end
41
-
43
+
42
44
  # @see #text_box
43
45
  def text(content, x, y, w, h, attrs = {})
44
46
  # Set the :overflow property to :shirink_to_fit.
45
- text_box(content, x, y, w, h, {:overflow => :shrink_to_fit}.merge(attrs))
47
+ text_box(content, x, y, w, h, { overflow: :shirink_to_fit }.merge(attrs))
46
48
  end
47
-
49
+
48
50
  private
49
-
51
+
50
52
  # @param x (see #text_box)
51
53
  # @param y (see #text_box)
52
54
  # @param w (see #text_box)
@@ -56,15 +58,15 @@ module ThinReports
56
58
  # @option states [Symbold] :overflow
57
59
  # @return [Hash]
58
60
  def text_box_attrs(x, y, w, h, states = {})
59
- attrs = {:at => pos(x, y),
60
- :width => s2f(w)}
61
+ attrs = {at: pos(x, y),
62
+ width: s2f(w)}
61
63
  if states[:single]
62
- states[:overflow] != :expand ? attrs.merge(:single_line => true) : attrs
64
+ states[:overflow] != :expand ? attrs.merge(single_line: true) : attrs
63
65
  else
64
- attrs.merge(:height => s2f(h))
66
+ attrs.merge(height: s2f(h))
65
67
  end
66
68
  end
67
-
69
+
68
70
  # @param attrs (see #text)
69
71
  # @yield [built_attrs, font_styles]
70
72
  # @yieldparam [Hash] built_attrs The finalized attributes.
@@ -72,48 +74,48 @@ module ThinReports
72
74
  def with_text_styles(attrs, &block)
73
75
  # When no color is given, do not draw.
74
76
  return unless attrs.key?(:color) && attrs[:color] != 'none'
75
-
77
+
76
78
  save_graphics_state
77
-
78
- fontinfo = {:name => attrs.delete(:font).to_s,
79
- :color => parse_color(attrs.delete(:color)),
80
- :size => s2f(attrs.delete(:size))}
81
-
79
+
80
+ fontinfo = {name: attrs.delete(:font).to_s,
81
+ color: parse_color(attrs.delete(:color)),
82
+ size: s2f(attrs.delete(:size))}
83
+
82
84
  # Add the specified value to :leading option.
83
85
  if line_height = attrs.delete(:line_height)
84
86
  attrs[:leading] = text_line_leading(s2f(line_height),
85
- :name => fontinfo[:name],
86
- :size => fontinfo[:size])
87
+ name: fontinfo[:name],
88
+ size: fontinfo[:size])
87
89
  end
88
-
90
+
89
91
  # Set the :character_spacing option.
90
92
  if space = attrs.delete(:letter_spacing)
91
93
  attrs[:character_spacing] = s2f(space)
92
94
  end
93
-
95
+
94
96
  # Or... with_font_styles(attrs, fontinfo, &block)
95
97
  with_font_styles(attrs, fontinfo) do |modified_attrs, styles|
96
98
  block.call(modified_attrs, styles)
97
99
  end
98
-
100
+
99
101
  restore_graphics_state
100
102
  end
101
-
103
+
102
104
  # @param [Numeric] line_height
103
105
  # @param [Hash] font
104
106
  # @option font [String] :name Name of font.
105
107
  # @option font [Numeric] :size Size of font.
106
108
  # @return [Numeric]
107
109
  def text_line_leading(line_height, font)
108
- line_height - pdf.font(font[:name], :size => font[:size]).height
110
+ line_height - pdf.font(font[:name], size: font[:size]).height
109
111
  end
110
-
112
+
111
113
  # @param [String] content
112
114
  # @return [String]
113
115
  def text_without_line_wrap(content)
114
116
  content.gsub(/ /, Prawn::Text::NBSP)
115
117
  end
116
-
118
+
117
119
  # @param [Hash] attrs
118
120
  # @param [Hash] font
119
121
  # @option font [String] :color
@@ -129,29 +131,29 @@ module ThinReports
129
131
  [:bold, :italic].include?(style) && !font_has_style?(font[:name], style)
130
132
  end
131
133
  end
132
-
134
+
133
135
  # Emulate bold style.
134
136
  if manual && manual.include?(:bold)
135
137
  pdf.stroke_color(font[:color])
136
138
  pdf.line_width(font[:size] * 0.025)
137
-
139
+
138
140
  # Change rendering mode to :fill_stroke.
139
141
  attrs[:mode] = :fill_stroke
140
142
  end
141
-
143
+
142
144
  # Emulate italic style.
143
145
  if manual && manual.include?(:italic)
144
146
  # FIXME
145
147
  # pdf.transformation_matrix(1, 0, 0.26, 1, 0, 0)
146
148
  end
147
-
148
- pdf.font(font[:name], :size => font[:size]) do
149
+
150
+ pdf.font(font[:name], size: font[:size]) do
149
151
  pdf.fill_color(font[:color])
150
152
  block.call(attrs, styles || [])
151
153
  end
152
- end
153
-
154
+ end
155
+
154
156
  end
155
-
157
+
156
158
  end
157
159
  end