prawn 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (278) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +0 -0
  4. data/Gemfile +1 -9
  5. data/Rakefile +12 -22
  6. data/lib/prawn.rb +29 -48
  7. data/lib/prawn/document.rb +148 -123
  8. data/lib/prawn/document/bounding_box.rb +33 -26
  9. data/lib/prawn/document/column_box.rb +5 -7
  10. data/lib/prawn/document/internals.rb +6 -6
  11. data/lib/prawn/document/span.rb +20 -17
  12. data/lib/prawn/encoding.rb +65 -67
  13. data/lib/prawn/errors.rb +10 -7
  14. data/lib/prawn/font.rb +78 -62
  15. data/lib/prawn/font/afm.rb +93 -66
  16. data/lib/prawn/font/dfont.rb +2 -10
  17. data/lib/prawn/font/ttc.rb +34 -0
  18. data/lib/prawn/font/ttf.rb +73 -65
  19. data/lib/prawn/font_metric_cache.rb +9 -8
  20. data/lib/prawn/graphics.rb +110 -70
  21. data/lib/prawn/graphics/blend_mode.rb +7 -8
  22. data/lib/prawn/graphics/cap_style.rb +2 -4
  23. data/lib/prawn/graphics/color.rb +23 -26
  24. data/lib/prawn/graphics/dash.rb +22 -12
  25. data/lib/prawn/graphics/join_style.rb +8 -4
  26. data/lib/prawn/graphics/patterns.rb +185 -96
  27. data/lib/prawn/graphics/transformation.rb +11 -9
  28. data/lib/prawn/graphics/transparency.rb +15 -13
  29. data/lib/prawn/grid.rb +20 -20
  30. data/lib/prawn/image_handler.rb +4 -6
  31. data/lib/prawn/images.rb +22 -15
  32. data/lib/prawn/images/image.rb +0 -1
  33. data/lib/prawn/images/jpg.rb +26 -22
  34. data/lib/prawn/images/png.rb +60 -57
  35. data/lib/prawn/measurement_extensions.rb +8 -9
  36. data/lib/prawn/measurements.rb +14 -15
  37. data/lib/prawn/outline.rb +96 -78
  38. data/lib/prawn/repeater.rb +12 -10
  39. data/lib/prawn/security.rb +66 -48
  40. data/lib/prawn/security/arcfour.rb +1 -3
  41. data/lib/prawn/soft_mask.rb +23 -25
  42. data/lib/prawn/stamp.rb +16 -12
  43. data/lib/prawn/text.rb +59 -45
  44. data/lib/prawn/text/box.rb +9 -8
  45. data/lib/prawn/text/formatted.rb +4 -6
  46. data/lib/prawn/text/formatted/arranger.rb +51 -30
  47. data/lib/prawn/text/formatted/box.rb +112 -88
  48. data/lib/prawn/text/formatted/fragment.rb +10 -15
  49. data/lib/prawn/text/formatted/line_wrap.rb +118 -61
  50. data/lib/prawn/text/formatted/parser.rb +134 -110
  51. data/lib/prawn/text/formatted/wrap.rb +42 -32
  52. data/lib/prawn/transformation_stack.rb +3 -4
  53. data/lib/prawn/utilities.rb +6 -21
  54. data/lib/prawn/version.rb +1 -3
  55. data/lib/prawn/view.rb +4 -2
  56. data/manual/basic_concepts/adding_pages.rb +4 -7
  57. data/manual/basic_concepts/basic_concepts.rb +29 -22
  58. data/manual/basic_concepts/creation.rb +8 -11
  59. data/manual/basic_concepts/cursor.rb +2 -5
  60. data/manual/basic_concepts/measurement.rb +3 -6
  61. data/manual/basic_concepts/origin.rb +3 -6
  62. data/manual/basic_concepts/other_cursor_helpers.rb +9 -12
  63. data/manual/basic_concepts/view.rb +20 -16
  64. data/manual/bounding_box/bounding_box.rb +27 -24
  65. data/manual/bounding_box/bounds.rb +9 -12
  66. data/manual/bounding_box/canvas.rb +2 -5
  67. data/manual/bounding_box/creation.rb +4 -7
  68. data/manual/bounding_box/indentation.rb +12 -15
  69. data/manual/bounding_box/nesting.rb +22 -17
  70. data/manual/bounding_box/russian_boxes.rb +8 -9
  71. data/manual/bounding_box/stretchy.rb +10 -13
  72. data/manual/contents.rb +26 -22
  73. data/manual/cover.rb +22 -20
  74. data/manual/document_and_page_options/background.rb +9 -13
  75. data/manual/document_and_page_options/document_and_page_options.rb +23 -20
  76. data/manual/document_and_page_options/metadata.rb +16 -16
  77. data/manual/document_and_page_options/page_margins.rb +16 -20
  78. data/manual/document_and_page_options/page_size.rb +11 -12
  79. data/manual/document_and_page_options/print_scaling.rb +15 -15
  80. data/manual/example_helper.rb +2 -4
  81. data/manual/graphics/blend_mode.rb +10 -9
  82. data/manual/graphics/circle_and_ellipse.rb +2 -5
  83. data/manual/graphics/color.rb +5 -9
  84. data/manual/graphics/common_lines.rb +5 -8
  85. data/manual/graphics/fill_and_stroke.rb +2 -5
  86. data/manual/graphics/fill_rules.rb +7 -10
  87. data/manual/graphics/gradients.rb +25 -21
  88. data/manual/graphics/graphics.rb +49 -43
  89. data/manual/graphics/helper.rb +10 -9
  90. data/manual/graphics/line_width.rb +5 -7
  91. data/manual/graphics/lines_and_curves.rb +5 -8
  92. data/manual/graphics/polygon.rb +4 -8
  93. data/manual/graphics/rectangle.rb +2 -5
  94. data/manual/graphics/rotate.rb +4 -7
  95. data/manual/graphics/scale.rb +12 -15
  96. data/manual/graphics/soft_masks.rb +1 -4
  97. data/manual/graphics/stroke_cap.rb +3 -6
  98. data/manual/graphics/stroke_dash.rb +9 -12
  99. data/manual/graphics/stroke_join.rb +2 -5
  100. data/manual/graphics/translate.rb +7 -10
  101. data/manual/graphics/transparency.rb +5 -8
  102. data/manual/how_to_read_this_manual.rb +4 -6
  103. data/manual/images/absolute_position.rb +4 -7
  104. data/manual/images/fit.rb +5 -8
  105. data/manual/images/horizontal.rb +6 -9
  106. data/manual/images/images.rb +25 -23
  107. data/manual/images/plain_image.rb +3 -6
  108. data/manual/images/scale.rb +7 -10
  109. data/manual/images/vertical.rb +10 -13
  110. data/manual/images/width_and_height.rb +8 -11
  111. data/manual/layout/boxes.rb +3 -6
  112. data/manual/layout/content.rb +5 -8
  113. data/manual/layout/layout.rb +16 -16
  114. data/manual/layout/simple_grid.rb +4 -7
  115. data/manual/outline/add_subsection_to.rb +18 -21
  116. data/manual/outline/insert_section_after.rb +13 -16
  117. data/manual/outline/outline.rb +19 -17
  118. data/manual/outline/sections_and_pages.rb +15 -18
  119. data/manual/repeatable_content/alternate_page_numbering.rb +19 -17
  120. data/manual/repeatable_content/page_numbering.rb +15 -16
  121. data/manual/repeatable_content/repeatable_content.rb +23 -19
  122. data/manual/repeatable_content/repeater.rb +12 -15
  123. data/manual/repeatable_content/stamp.rb +12 -15
  124. data/manual/security/encryption.rb +7 -10
  125. data/manual/security/permissions.rb +17 -14
  126. data/manual/security/security.rb +17 -16
  127. data/manual/table.rb +2 -4
  128. data/manual/text/alignment.rb +14 -17
  129. data/manual/text/color.rb +10 -11
  130. data/manual/text/column_box.rb +5 -8
  131. data/manual/text/fallback_fonts.rb +23 -21
  132. data/manual/text/font.rb +9 -12
  133. data/manual/text/font_size.rb +11 -14
  134. data/manual/text/font_style.rb +4 -7
  135. data/manual/text/formatted_callbacks.rb +23 -21
  136. data/manual/text/formatted_text.rb +31 -25
  137. data/manual/text/free_flowing_text.rb +18 -21
  138. data/manual/text/inline.rb +16 -19
  139. data/manual/text/kerning_and_character_spacing.rb +12 -15
  140. data/manual/text/leading.rb +5 -8
  141. data/manual/text/line_wrapping.rb +33 -17
  142. data/manual/text/paragraph_indentation.rb +11 -14
  143. data/manual/text/positioned_text.rb +13 -16
  144. data/manual/text/registering_families.rb +16 -19
  145. data/manual/text/rendering_and_color.rb +7 -10
  146. data/manual/text/right_to_left_text.rb +24 -19
  147. data/manual/text/rotation.rb +26 -23
  148. data/manual/text/single_usage.rb +6 -9
  149. data/manual/text/text.rb +56 -52
  150. data/manual/text/text_box_excess.rb +18 -17
  151. data/manual/text/text_box_extensions.rb +16 -15
  152. data/manual/text/text_box_overflow.rb +15 -18
  153. data/manual/text/utf8.rb +9 -12
  154. data/manual/text/win_ansi_charset.rb +18 -19
  155. data/prawn.gemspec +37 -27
  156. data/spec/extensions/encoding_helpers.rb +0 -2
  157. data/spec/manual_spec.rb +33 -0
  158. data/spec/prawn/document/bounding_box_spec.rb +546 -0
  159. data/spec/prawn/document/column_box_spec.rb +73 -0
  160. data/spec/prawn/document/security_spec.rb +173 -0
  161. data/spec/prawn/document_annotations_spec.rb +74 -0
  162. data/spec/prawn/document_destinations_spec.rb +13 -0
  163. data/spec/prawn/document_grid_spec.rb +96 -0
  164. data/spec/prawn/document_reference_spec.rb +25 -0
  165. data/spec/prawn/document_span_spec.rb +34 -0
  166. data/spec/prawn/document_spec.rb +751 -0
  167. data/spec/prawn/font_metric_cache_spec.rb +52 -0
  168. data/spec/prawn/font_spec.rb +513 -0
  169. data/spec/prawn/graphics/blend_mode_spec.rb +61 -0
  170. data/spec/prawn/graphics/transparency_spec.rb +79 -0
  171. data/spec/prawn/graphics_spec.rb +817 -0
  172. data/spec/prawn/graphics_stroke_styles_spec.rb +227 -0
  173. data/spec/{image_handler_spec.rb → prawn/image_handler_spec.rb} +13 -15
  174. data/spec/prawn/images/jpg_spec.rb +18 -0
  175. data/spec/prawn/images/png_spec.rb +281 -0
  176. data/spec/prawn/images_spec.rb +170 -0
  177. data/spec/prawn/measurements_extensions_spec.rb +22 -0
  178. data/spec/prawn/outline_spec.rb +408 -0
  179. data/spec/prawn/repeater_spec.rb +163 -0
  180. data/spec/prawn/soft_mask_spec.rb +72 -0
  181. data/spec/prawn/stamp_spec.rb +168 -0
  182. data/spec/prawn/text/box_spec.rb +1113 -0
  183. data/spec/prawn/text/formatted/arranger_spec.rb +464 -0
  184. data/spec/prawn/text/formatted/box_spec.rb +825 -0
  185. data/spec/prawn/text/formatted/fragment_spec.rb +341 -0
  186. data/spec/prawn/text/formatted/line_wrap_spec.rb +491 -0
  187. data/spec/prawn/text/formatted/parser_spec.rb +667 -0
  188. data/spec/prawn/text_draw_text_spec.rb +147 -0
  189. data/spec/prawn/text_rendering_mode_spec.rb +42 -0
  190. data/spec/prawn/text_spacing_spec.rb +93 -0
  191. data/spec/prawn/text_spec.rb +601 -0
  192. data/spec/prawn/text_with_inline_formatting_spec.rb +33 -0
  193. data/spec/{transformation_stack_spec.rb → prawn/transformation_stack_spec.rb} +21 -20
  194. data/spec/prawn/view_spec.rb +45 -0
  195. data/spec/spec_helper.rb +16 -16
  196. metadata +96 -151
  197. metadata.gz.sig +1 -0
  198. data/data/images/16bit.alpha +0 -0
  199. data/data/images/16bit.color +0 -0
  200. data/data/images/16bit.png +0 -0
  201. data/data/images/arrow.png +0 -0
  202. data/data/images/arrow2.png +0 -0
  203. data/data/images/blend_modes_bottom_layer.jpg +0 -0
  204. data/data/images/blend_modes_top_layer.jpg +0 -0
  205. data/data/images/dice.alpha +0 -0
  206. data/data/images/dice.color +0 -0
  207. data/data/images/dice.png +0 -0
  208. data/data/images/dice_interlaced.png +0 -0
  209. data/data/images/fractal.jpg +0 -0
  210. data/data/images/indexed_color.dat +0 -0
  211. data/data/images/indexed_color.png +0 -0
  212. data/data/images/indexed_transparency.png +0 -0
  213. data/data/images/indexed_transparency_alpha.dat +0 -0
  214. data/data/images/indexed_transparency_color.dat +0 -0
  215. data/data/images/letterhead.jpg +0 -0
  216. data/data/images/license.md +0 -8
  217. data/data/images/page_white_text.alpha +0 -0
  218. data/data/images/page_white_text.color +0 -0
  219. data/data/images/page_white_text.png +0 -0
  220. data/data/images/pigs.jpg +0 -0
  221. data/data/images/prawn.png +0 -0
  222. data/data/images/ruport.png +0 -0
  223. data/data/images/ruport_data.dat +0 -0
  224. data/data/images/ruport_transparent.png +0 -0
  225. data/data/images/ruport_type0.png +0 -0
  226. data/data/images/stef.jpg +0 -0
  227. data/data/images/tru256.bmp +0 -0
  228. data/data/images/web-links.dat +0 -1
  229. data/data/images/web-links.png +0 -0
  230. data/data/pdfs/complex_template.pdf +0 -0
  231. data/data/pdfs/contains_ttf_font.pdf +0 -0
  232. data/data/pdfs/encrypted.pdf +0 -0
  233. data/data/pdfs/form.pdf +1 -819
  234. data/data/pdfs/hexagon.pdf +0 -61
  235. data/data/pdfs/indirect_reference.pdf +0 -86
  236. data/data/pdfs/multipage_template.pdf +0 -127
  237. data/data/pdfs/nested_pages.pdf +0 -118
  238. data/data/pdfs/page_without_mediabox.pdf +0 -193
  239. data/data/pdfs/resources_as_indirect_object.pdf +0 -83
  240. data/data/pdfs/two_hexagons.pdf +0 -90
  241. data/data/pdfs/version_1_6.pdf +0 -61
  242. data/data/shift_jis_text.txt +0 -1
  243. data/spec/acceptance/png_spec.rb +0 -35
  244. data/spec/annotations_spec.rb +0 -67
  245. data/spec/blend_mode_spec.rb +0 -71
  246. data/spec/bounding_box_spec.rb +0 -501
  247. data/spec/column_box_spec.rb +0 -59
  248. data/spec/destinations_spec.rb +0 -13
  249. data/spec/document_spec.rb +0 -738
  250. data/spec/font_metric_cache_spec.rb +0 -52
  251. data/spec/font_spec.rb +0 -475
  252. data/spec/formatted_text_arranger_spec.rb +0 -452
  253. data/spec/formatted_text_box_spec.rb +0 -716
  254. data/spec/formatted_text_fragment_spec.rb +0 -299
  255. data/spec/graphics_spec.rb +0 -705
  256. data/spec/grid_spec.rb +0 -95
  257. data/spec/images_spec.rb +0 -167
  258. data/spec/inline_formatted_text_parser_spec.rb +0 -568
  259. data/spec/jpg_spec.rb +0 -23
  260. data/spec/line_wrap_spec.rb +0 -366
  261. data/spec/measurement_units_spec.rb +0 -22
  262. data/spec/outline_spec.rb +0 -409
  263. data/spec/png_spec.rb +0 -257
  264. data/spec/reference_spec.rb +0 -25
  265. data/spec/repeater_spec.rb +0 -154
  266. data/spec/security_spec.rb +0 -151
  267. data/spec/soft_mask_spec.rb +0 -78
  268. data/spec/span_spec.rb +0 -43
  269. data/spec/stamp_spec.rb +0 -179
  270. data/spec/stroke_styles_spec.rb +0 -208
  271. data/spec/text_at_spec.rb +0 -142
  272. data/spec/text_box_spec.rb +0 -1042
  273. data/spec/text_rendering_mode_spec.rb +0 -45
  274. data/spec/text_spacing_spec.rb +0 -93
  275. data/spec/text_spec.rb +0 -543
  276. data/spec/text_with_inline_formatting_spec.rb +0 -35
  277. data/spec/transparency_spec.rb +0 -91
  278. data/spec/view_spec.rb +0 -42
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
- #
3
1
  # Kerning is the process of adjusting the spacing between characters in a
4
2
  # proportional font. It is usually done with specific letter pairs. We can
5
3
  # switch it on and off if it is available with the current font. Just pass a
@@ -8,32 +6,31 @@
8
6
  # Character Spacing is the space between characters. It can be increased or
9
7
  # decreased and will have effect on the whole text. Just pass a number to the
10
8
  # <code>:character_spacing</code> option from the text methods.
11
- #
12
- require File.expand_path(File.join(File.dirname(__FILE__),
13
- %w[.. example_helper]))
9
+
10
+ require_relative '../example_helper'
14
11
 
15
12
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
16
13
  Prawn::ManualBuilder::Example.generate(filename) do
17
14
  font_size(30) do
18
- text_box "With kerning:", :kerning => true, :at => [0, y - 40]
19
- text_box "Without kerning:", :kerning => false, :at => [0, y - 80]
15
+ text_box 'With kerning:', kerning: true, at: [0, y - 40]
16
+ text_box 'Without kerning:', kerning: false, at: [0, y - 80]
20
17
 
21
- text_box "Tomato", :kerning => true, :at => [250, y - 40]
22
- text_box "Tomato", :kerning => false, :at => [250, y - 80]
18
+ text_box 'Tomato', kerning: true, at: [250, y - 40]
19
+ text_box 'Tomato', kerning: false, at: [250, y - 80]
23
20
 
24
- text_box "WAR", :kerning => true, :at => [400, y - 40]
25
- text_box "WAR", :kerning => false, :at => [400, y - 80]
21
+ text_box 'WAR', kerning: true, at: [400, y - 40]
22
+ text_box 'WAR', kerning: false, at: [400, y - 80]
26
23
 
27
- text_box "F.", :kerning => true, :at => [500, y - 40]
28
- text_box "F.", :kerning => false, :at => [500, y - 80]
24
+ text_box 'F.', kerning: true, at: [500, y - 40]
25
+ text_box 'F.', kerning: false, at: [500, y - 80]
29
26
  end
30
27
 
31
28
  move_down 80
32
29
 
33
- string = "What have you done to the space between the characters?"
30
+ string = 'What have you done to the space between the characters?'
34
31
  [-2, -1, 0, 0.5, 1, 2].each do |spacing|
35
32
  move_down 20
36
33
  text "#{string} (character_spacing: #{spacing})",
37
- :character_spacing => spacing
34
+ character_spacing: spacing
38
35
  end
39
36
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
- #
3
1
  # Leading is the additional space between lines of text.
4
2
  #
5
3
  # The leading can be set using the <code>default_leading</code> method which
@@ -7,19 +5,18 @@
7
5
  # text methods with the <code>:leading</code> option.
8
6
  #
9
7
  # The default leading is <code>0</code>.
10
- #
11
- require File.expand_path(File.join(File.dirname(__FILE__),
12
- %w[.. example_helper]))
8
+
9
+ require_require '../example_helper'
13
10
 
14
11
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
15
12
  Prawn::ManualBuilder::Example.generate(filename) do
16
- string = "Hey, what did you do with the space between my lines? " * 10
17
- text string, :leading => 0
13
+ string = 'Hey, what did you do with the space between my lines? ' * 10
14
+ text string, leading: 0
18
15
 
19
16
  move_down 20
20
17
  default_leading 5
21
18
  text string
22
19
 
23
20
  move_down 20
24
- text string, :leading => 10
21
+ text string, leading: 10
25
22
  end
@@ -1,41 +1,57 @@
1
- # encoding: utf-8
2
- #
3
1
  # Line wrapping happens on white space or hyphens. Soft hyphens can be used to
4
2
  # indicate where words can be hyphenated. Non-breaking spaces can be used to
5
3
  # display space without allowing for a break.
6
4
  #
7
5
  # For writing styles that do not make use of spaces, the zero width space serves
8
6
  # to mark word boundaries. Zero width spaces are available only with TTF fonts.
9
- #
10
- require File.expand_path(File.join(File.dirname(__FILE__),
11
- %w[.. example_helper]))
7
+
8
+ require_relative '../example_helper'
12
9
 
13
10
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
14
11
  Prawn::ManualBuilder::Example.generate(filename) do
15
- text "Hard hyphens:\n" +
16
- "Slip-sliding away, slip sliding awaaaay. You know the " +
17
- "nearer your destination the more you're slip-sliding away."
12
+ text "Hard hyphens:\n" \
13
+ 'Slip-sliding away, slip sliding awaaaay. You know the ' \
14
+ "nearer your destination the more you're slip-sliding away."
18
15
  move_down 20
19
16
 
20
17
  shy = Prawn::Text::SHY
21
- text "Soft hyphens:\n" +
22
- "Slip slid#{shy}ing away, slip slid#{shy}ing away. You know the " +
23
- "nearer your destinat#{shy}ion the more you're slip slid#{shy}ing away."
18
+ text "Soft hyphens:\n" \
19
+ "Slip slid#{shy}ing away, slip slid#{shy}ing away. You know the " \
20
+ "nearer your destinat#{shy}ion the more you're slip slid#{shy}ing away."
24
21
  move_down 20
25
22
 
26
23
  nbsp = Prawn::Text::NBSP
27
- text "Non-breaking spaces:\n" +
28
- "Slip#{nbsp}sliding away, slip#{nbsp}sliding awaaaay. You know the " +
29
- "nearer your destination the more you're slip#{nbsp}sliding away."
24
+ text "Non-breaking spaces:\n" \
25
+ "Slip#{nbsp}sliding away, slip#{nbsp}sliding awaaaay. You know the " \
26
+ "nearer your destination the more you're slip#{nbsp}sliding away."
30
27
  move_down 20
31
28
 
32
- font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf", :size => 16) do
33
- long_text = "No word boundaries:\n更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历您的DB中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事,这样的话,你就非常被动了。更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历您的DB中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事,这样的话,你就非常被动了。"
29
+ font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf", size: 16) do
30
+ long_text = "No word boundaries:\n更可怕的是,"\
31
+ '同质化竞争对手可以按照URL中后面这个ID来遍历您的DB中的内容,'\
32
+ '写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事,'\
33
+ '这样的话,你就非常被动了。更可怕的是,'\
34
+ '同质化竞争对手可以按照URL中后面这个ID来遍历您的DB中的内容,'\
35
+ '写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事,'\
36
+ '这样的话,你就非常被动了。'
34
37
  text long_text
35
38
  move_down 20
36
39
 
37
40
  zwsp = Prawn::Text::ZWSP
38
- long_text = "Invisible word boundaries:\n更#{zwsp}可怕的#{zwsp}是,#{zwsp}同质化#{zwsp}竞争#{zwsp}对#{zwsp}手#{zwsp}可以#{zwsp}按照#{zwsp}URL#{zwsp}中#{zwsp}后面#{zwsp}这个#{zwsp}ID#{zwsp}来#{zwsp}遍历#{zwsp}您的#{zwsp}DB#{zwsp}中的#{zwsp}内容,#{zwsp}写个#{zwsp}小爬虫#{zwsp}把#{zwsp}你的#{zwsp}页面#{zwsp}上的#{zwsp}关#{zwsp}键#{zwsp}信#{zwsp}息顺#{zwsp}次#{zwsp}爬#{zwsp}下来#{zwsp}也#{zwsp}不是#{zwsp}什么#{zwsp}难事,#{zwsp}这样的话,#{zwsp}你#{zwsp}就#{zwsp}非常#{zwsp}被动了。#{zwsp}更#{zwsp}可怕的#{zwsp}是,#{zwsp}同质化#{zwsp}竞争#{zwsp}对#{zwsp}手#{zwsp}可以#{zwsp}按照#{zwsp}URL#{zwsp}中#{zwsp}后面#{zwsp}这个#{zwsp}ID#{zwsp}来#{zwsp}遍历#{zwsp}您的#{zwsp}DB#{zwsp}中的#{zwsp}内容,#{zwsp}写个#{zwsp}小爬虫#{zwsp}把#{zwsp}你的#{zwsp}页面#{zwsp}上的#{zwsp}关#{zwsp}键#{zwsp}信#{zwsp}息顺#{zwsp}次#{zwsp}爬#{zwsp}下来#{zwsp}也#{zwsp}不是#{zwsp}什么#{zwsp}难事,#{zwsp}这样的话,#{zwsp}你#{zwsp}就#{zwsp}非常#{zwsp}被动了。"
41
+ long_text = "Invisible word boundaries:\n更#{zwsp}可怕的#{zwsp}是,"\
42
+ "#{zwsp}同质化#{zwsp}竞争#{zwsp}对#{zwsp}手#{zwsp}可以#{zwsp}按照#{zwsp}"\
43
+ "URL#{zwsp}中#{zwsp}后面#{zwsp}这个#{zwsp}ID#{zwsp}来#{zwsp}遍历#{zwsp}"\
44
+ "您的#{zwsp}DB#{zwsp}中的#{zwsp}内容,#{zwsp}写个#{zwsp}小爬虫#{zwsp}把"\
45
+ "#{zwsp}你的#{zwsp}页面#{zwsp}上的#{zwsp}关#{zwsp}键#{zwsp}信#{zwsp}息顺"\
46
+ "#{zwsp}次#{zwsp}爬#{zwsp}下来#{zwsp}也#{zwsp}不是#{zwsp}什么#{zwsp}"\
47
+ "难事,#{zwsp}这样的话,#{zwsp}你#{zwsp}就#{zwsp}非常#{zwsp}被动了。"\
48
+ "#{zwsp}更#{zwsp}可怕的#{zwsp}是,#{zwsp}同质化#{zwsp}竞争#{zwsp}对"\
49
+ "#{zwsp}手#{zwsp}可以#{zwsp}按照#{zwsp}URL#{zwsp}中#{zwsp}后面#{zwsp}"\
50
+ "这个#{zwsp}ID#{zwsp}来#{zwsp}遍历#{zwsp}您的#{zwsp}DB#{zwsp}中的#{zwsp}"\
51
+ "内容,#{zwsp}写个#{zwsp}小爬虫#{zwsp}把#{zwsp}你的#{zwsp}页面#{zwsp}"\
52
+ "上的#{zwsp}关#{zwsp}键#{zwsp}信#{zwsp}息顺#{zwsp}次#{zwsp}爬#{zwsp}下来"\
53
+ "#{zwsp}也#{zwsp}不是#{zwsp}什么#{zwsp}难事,#{zwsp}这样的话,#{zwsp}你"\
54
+ "#{zwsp}就#{zwsp}非常#{zwsp}被动了。"
39
55
  text long_text
40
56
  end
41
57
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
- #
3
1
  # Prawn strips all whitespace from the beginning and the end of strings so there
4
2
  # are two ways to indent paragraphs:
5
3
  #
@@ -9,25 +7,24 @@
9
7
  # The other is to use the <code>:indent_paragraphs</code> option with the text
10
8
  # methods. Just pass a number with the space to indent the first line in each
11
9
  # paragraph.
12
- #
13
- require File.expand_path(File.join(File.dirname(__FILE__),
14
- %w[.. example_helper]))
10
+
11
+ require_relative '../example_helper'
15
12
 
16
13
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
17
14
  Prawn::ManualBuilder::Example.generate(filename) do
18
15
  # Using non-breaking spaces
19
- text " " * 10 + "This paragraph won't be indented. " * 10 +
20
- "\n#{Prawn::Text::NBSP * 10}" + "This one will with NBSP. " * 10
16
+ text ' ' * 10 + "This paragraph won't be indented. " * 10 +
17
+ "\n#{Prawn::Text::NBSP * 10}" + 'This one will with NBSP. ' * 10
21
18
 
22
19
  move_down 20
23
- text "This paragraph will be indented. " * 10 +
24
- "\n" + "This one will too. " * 10,
25
- :indent_paragraphs => 60
20
+ text 'This paragraph will be indented. ' * 10 +
21
+ "\n" + 'This one will too. ' * 10,
22
+ indent_paragraphs: 60
26
23
 
27
24
  move_down 20
28
25
 
29
- text "FROM RIGHT TO LEFT:"
30
- text "This paragraph will be indented. " * 10 +
31
- "\n" + "This one will too. " * 10,
32
- :indent_paragraphs => 60, :direction => :rtl
26
+ text 'FROM RIGHT TO LEFT:'
27
+ text 'This paragraph will be indented. ' * 10 +
28
+ "\n" + 'This one will too. ' * 10,
29
+ indent_paragraphs: 60, direction: :rtl
33
30
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
- #
3
1
  # Sometimes we want the text on a specific position on the page. The
4
2
  # <code>text</code> method just won't help us.
5
3
  #
@@ -16,23 +14,22 @@
16
14
  # will flow to a new line if it reaches the right border.
17
15
  #
18
16
  # Given that, <code>text_box</code> is the better option available.
19
- #
20
- require File.expand_path(File.join(File.dirname(__FILE__),
21
- %w[.. example_helper]))
17
+
18
+ require_relative '../example_helper'
22
19
 
23
20
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
24
21
  Prawn::ManualBuilder::Example.generate(filename) do
25
- draw_text "This draw_text line is absolute positioned. However don't " +
26
- "expect it to flow even if it hits the document border",
27
- :at => [200, 300]
22
+ draw_text "This draw_text line is absolute positioned. However don't " \
23
+ 'expect it to flow even if it hits the document border',
24
+ at: [200, 300]
28
25
 
29
- text_box "This is a text box, you can control where it will flow by " +
30
- "specifying the :height and :width options",
31
- :at => [100, 250],
32
- :height => 100,
33
- :width => 100
26
+ text_box 'This is a text box, you can control where it will flow by ' \
27
+ 'specifying the :height and :width options',
28
+ at: [100, 250],
29
+ height: 100,
30
+ width: 100
34
31
 
35
- text_box "Another text box with no :width option passed, so it will " +
36
- "flow to a new line whenever it reaches the right margin. ",
37
- :at => [200, 100]
32
+ text_box 'Another text box with no :width option passed, so it will ' \
33
+ 'flow to a new line whenever it reaches the right margin. ',
34
+ at: [200, 100]
38
35
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
- #
3
1
  # Registering font families will help you when you want to use a font over and
4
2
  # over or if you would like to take advantage of the <code>:style</code> option
5
3
  # of the text methods and the <code>b</code> and <code>i</code> tags when using
@@ -7,46 +5,45 @@
7
5
  #
8
6
  # To register a font family update the <code>font_families</code>
9
7
  # hash with the font path for each style you want to use.
10
- #
11
- require File.expand_path(File.join(File.dirname(__FILE__),
12
- %w[.. example_helper]))
8
+
9
+ require_relative '../example_helper'
13
10
 
14
11
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
15
12
  Prawn::ManualBuilder::Example.generate(filename) do
16
13
  # Registering a single TTF font
17
14
  font_families.update(
18
- "DejaVu Sans" => {
19
- :normal => "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
15
+ 'DejaVu Sans' => {
16
+ normal: "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
20
17
  }
21
18
  )
22
19
 
23
- font("DejaVu Sans") do
24
- text "Using the DejaVu Sans font providing only its name to the font method"
20
+ font('DejaVu Sans') do
21
+ text 'Using the DejaVu Sans font providing only its name to the font method'
25
22
  end
26
23
  move_down 20
27
24
 
28
25
  # Registering a DFONT package
29
26
  font_path = "#{Prawn::DATADIR}/fonts/Panic+Sans.dfont"
30
27
  font_families.update(
31
- "Panic Sans" => {
32
- :normal => { :file => font_path, :font => "PanicSans" },
33
- :italic => { :file => font_path, :font => "PanicSans-Italic" },
34
- :bold => { :file => font_path, :font => "PanicSans-Bold" },
35
- :bold_italic => { :file => font_path, :font => "PanicSans-BoldItalic" }
28
+ 'Panic Sans' => {
29
+ normal: { file: font_path, font: 'PanicSans' },
30
+ italic: { file: font_path, font: 'PanicSans-Italic' },
31
+ bold: { file: font_path, font: 'PanicSans-Bold' },
32
+ bold_italic: { file: font_path, font: 'PanicSans-BoldItalic' }
36
33
  }
37
34
  )
38
35
 
39
- font "Panic Sans"
40
- text "Also using Panic Sans by providing only its name"
36
+ font 'Panic Sans'
37
+ text 'Also using Panic Sans by providing only its name'
41
38
  move_down 20
42
39
 
43
- text "Taking <b>advantage</b> of the <i>inline formatting</i>",
44
- :inline_format => true
40
+ text 'Taking <b>advantage</b> of the <i>inline formatting</i>',
41
+ inline_format: true
45
42
  move_down 20
46
43
 
47
44
  [:bold, :bold_italic, :italic, :normal].each do |style|
48
45
  text "Using the #{style} style option.",
49
- :style => style
46
+ style: style
50
47
  move_down 10
51
48
  end
52
49
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
- #
3
1
  # You have already seen how to set the text color using both inline formatting
4
2
  # and the format text methods. There is another way by using the graphics
5
3
  # methods <code>fill_color</code> and <code>stroke_color</code>.
@@ -11,27 +9,26 @@
11
9
  # being filled (the default mode) or just stroked or both filled and stroked.
12
10
  # This can be set using the <code>text_rendering_mode</code> method or the
13
11
  # <code>:mode</code> option on the text methods.
14
- #
15
- require File.expand_path(File.join(File.dirname(__FILE__),
16
- %w[.. example_helper]))
12
+
13
+ require_relative '../example_helper'
17
14
 
18
15
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
19
16
  Prawn::ManualBuilder::Example.generate(filename) do
20
- fill_color "00ff00"
21
- stroke_color "0000ff"
17
+ fill_color '00ff00'
18
+ stroke_color '0000ff'
22
19
 
23
20
  font_size(40) do
24
21
  # normal rendering mode: fill
25
- text "This text is filled with green."
22
+ text 'This text is filled with green.'
26
23
  move_down 20
27
24
 
28
25
  # inline rendering mode: stroke
29
- text "This text is stroked with blue", :mode => :stroke
26
+ text 'This text is stroked with blue', mode: :stroke
30
27
  move_down 20
31
28
 
32
29
  # block rendering mode: fill and stroke
33
30
  text_rendering_mode(:fill_stroke) do
34
- text "This text is filled with green and stroked with blue"
31
+ text 'This text is filled with green and stroked with blue'
35
32
  end
36
33
  end
37
34
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
- #
3
1
  # Prawn can be used with right-to-left text. The direction can be set
4
2
  # document-wide, on particular text, or on a text-box. Setting the direction to
5
3
  # <code>:rtl</code> automatically changes the default alignment to
@@ -13,35 +11,42 @@
13
11
  # languages is easy using the <code>bidi</code> Ruby Gem and its
14
12
  # <code>render_visual</code> function. See https://github.com/elad/ruby-bidi for
15
13
  # instructions and an example using Prawn.
16
- require File.expand_path(File.join(File.dirname(__FILE__),
17
- %w[.. example_helper]))
14
+
15
+ require_relative '../example_helper'
18
16
 
19
17
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
20
18
  Prawn::ManualBuilder::Example.generate(filename) do
21
19
  # set the direction document-wide
22
20
  self.text_direction = :rtl
23
21
 
24
- font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf", :size => 16) do
25
- long_text = "写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事写个小"
22
+ font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf", size: 16) do
23
+ long_text = '写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事写个'\
24
+ '小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事写个小爬虫把你的页'\
25
+ '面上的关键信息顺次爬下来也不是什么难事写个小'
26
26
  text long_text
27
27
  move_down 20
28
28
 
29
- text "You can override the document direction.", :direction => :ltr
29
+ text 'You can override the document direction.', direction: :ltr
30
30
  move_down 20
31
31
 
32
- formatted_text [{ :text => "更可怕的是,同质化竞争对手可以按照" },
33
- { :text => "URL", :direction => :ltr },
34
- { :text => "中后面这个" },
35
- { :text => "ID", :direction => :ltr },
36
- { :text => "来遍历您的" },
37
- { :text => "DB", :direction => :ltr },
38
- { :text => "中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事,这样的话,你就非常被动了。" }]
32
+ formatted_text [
33
+ { text: '更可怕的是,同质化竞争对手可以按照' },
34
+ { text: 'URL', direction: :ltr },
35
+ { text: '中后面这个' },
36
+ { text: 'ID', direction: :ltr },
37
+ { text: '来遍历您的' },
38
+ { text: 'DB', direction: :ltr },
39
+ { text: '中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么'\
40
+ '难事,这样的话,你就非常被动了。' }
41
+ ]
39
42
  move_down 20
40
43
 
41
- formatted_text [{ :text => "更可怕的是,同质化竞争对手可以按照" },
42
- { :text => "this", :direction => :ltr },
43
- { :text => "won't", :direction => :ltr, :size => 24 },
44
- { :text => "work", :direction => :ltr },
45
- { :text => "中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事" }]
44
+ formatted_text [
45
+ { text: '更可怕的是,同质化竞争对手可以按照' },
46
+ { text: 'this', direction: :ltr },
47
+ { text: "won't", direction: :ltr, size: 24 },
48
+ { text: 'work', direction: :ltr },
49
+ { text: '中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事' }
50
+ ]
46
51
  end
47
52
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
- #
3
1
  # Rotating text is best avoided on free flowing text, so this example
4
2
  # will only use the <code>text_box</code> method as we can have much more
5
3
  # control over its output.
@@ -7,36 +5,41 @@
7
5
  # To rotate text all we need to do is use the <code>:rotate</code> option
8
6
  # passing an angle in degrees and an optional <code>:rotate_around</code> to
9
7
  # indicate the origin of the rotation (the default is <code>:upper_left</code>).
10
- #
11
- require File.expand_path(File.join(File.dirname(__FILE__),
12
- %w[.. example_helper]))
8
+
9
+ require_relative '../example_helper'
13
10
 
14
11
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
15
12
  Prawn::ManualBuilder::Example.generate(filename) do
16
- width = 100
13
+ width = 100
17
14
  height = 60
18
- angle = 30
19
- x = 200
20
- y = cursor - 30
15
+ angle = 30
16
+ x = 200
17
+ y = cursor - 30
21
18
 
22
19
  stroke_rectangle [0, y], width, height
23
- text_box("This text was not rotated",
24
- :at => [0, y], :width => width, :height => height)
20
+ text_box(
21
+ 'This text was not rotated',
22
+ at: [0, y], width: width, height: height
23
+ )
25
24
 
26
25
  stroke_rectangle [0, y - 100], width, height
27
- text_box("This text was rotated around the center",
28
- :at => [0, y - 100], :width => width, :height => height,
29
- :rotate => angle, :rotate_around => :center)
26
+ text_box(
27
+ 'This text was rotated around the center',
28
+ at: [0, y - 100], width: width, height: height,
29
+ rotate: angle, rotate_around: :center
30
+ )
30
31
 
31
- [:lower_left, :upper_left,
32
- :lower_right, :upper_right].each_with_index do |corner, index|
33
- y = y - 100 if index == 2
32
+ [:lower_left, :upper_left, :lower_right, :upper_right]
33
+ .each_with_index do |corner, index|
34
+ y -= 100 if index == 2
34
35
  stroke_rectangle [x + (index % 2) * 200, y], width, height
35
- text_box("This text was rotated around the #{corner} corner.",
36
- :at => [x + (index % 2) * 200, y],
37
- :width => width,
38
- :height => height,
39
- :rotate => angle,
40
- :rotate_around => corner)
36
+ text_box(
37
+ "This text was rotated around the #{corner} corner.",
38
+ at: [x + (index % 2) * 200, y],
39
+ width: width,
40
+ height: height,
41
+ rotate: angle,
42
+ rotate_around: corner
43
+ )
41
44
  end
42
45
  end