prawn 2.3.0 → 2.5.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 (203) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/prawn/document/bounding_box.rb +223 -143
  4. data/lib/prawn/document/column_box.rb +61 -26
  5. data/lib/prawn/document/internals.rb +25 -16
  6. data/lib/prawn/document/span.rb +21 -18
  7. data/lib/prawn/document.rb +273 -182
  8. data/lib/prawn/encoding.rb +2 -5
  9. data/lib/prawn/errors.rb +23 -34
  10. data/lib/prawn/font.rb +254 -139
  11. data/lib/prawn/font_metric_cache.rb +18 -16
  12. data/lib/prawn/fonts/afm.rb +99 -57
  13. data/lib/prawn/fonts/dfont.rb +7 -1
  14. data/lib/prawn/fonts/otf.rb +4 -1
  15. data/lib/prawn/fonts/to_unicode_cmap.rb +151 -0
  16. data/lib/prawn/fonts/ttc.rb +7 -2
  17. data/lib/prawn/fonts/ttf.rb +345 -107
  18. data/lib/prawn/fonts.rb +14 -0
  19. data/lib/prawn/graphics/blend_mode.rb +25 -28
  20. data/lib/prawn/graphics/cap_style.rb +9 -12
  21. data/lib/prawn/graphics/color.rb +75 -50
  22. data/lib/prawn/graphics/dash.rb +45 -42
  23. data/lib/prawn/graphics/join_style.rb +18 -12
  24. data/lib/prawn/graphics/patterns.rb +239 -110
  25. data/lib/prawn/graphics/transformation.rb +51 -44
  26. data/lib/prawn/graphics/transparency.rb +16 -40
  27. data/lib/prawn/graphics.rb +370 -260
  28. data/lib/prawn/grid.rb +219 -57
  29. data/lib/prawn/image_handler.rb +27 -10
  30. data/lib/prawn/images/image.rb +8 -10
  31. data/lib/prawn/images/jpg.rb +46 -20
  32. data/lib/prawn/images/png.rb +94 -42
  33. data/lib/prawn/images.rb +70 -81
  34. data/lib/prawn/measurement_extensions.rb +39 -8
  35. data/lib/prawn/measurements.rb +60 -5
  36. data/lib/prawn/outline.rb +120 -113
  37. data/lib/prawn/repeater.rb +52 -36
  38. data/lib/prawn/security/arcfour.rb +4 -4
  39. data/lib/prawn/security.rb +106 -98
  40. data/lib/prawn/soft_mask.rb +42 -30
  41. data/lib/prawn/stamp.rb +38 -42
  42. data/lib/prawn/text/box.rb +156 -105
  43. data/lib/prawn/text/formatted/arranger.rb +121 -41
  44. data/lib/prawn/text/formatted/box.rb +239 -163
  45. data/lib/prawn/text/formatted/fragment.rb +130 -14
  46. data/lib/prawn/text/formatted/line_wrap.rb +49 -38
  47. data/lib/prawn/text/formatted/parser.rb +116 -74
  48. data/lib/prawn/text/formatted/wrap.rb +25 -26
  49. data/lib/prawn/text/formatted.rb +75 -0
  50. data/lib/prawn/text.rb +456 -211
  51. data/lib/prawn/transformation_stack.rb +29 -10
  52. data/lib/prawn/utilities.rb +13 -13
  53. data/lib/prawn/version.rb +2 -1
  54. data/lib/prawn/view.rb +69 -54
  55. data/lib/prawn.rb +24 -18
  56. data.tar.gz.sig +0 -0
  57. metadata +55 -262
  58. metadata.gz.sig +3 -4
  59. data/.yardopts +0 -10
  60. data/Gemfile +0 -5
  61. data/Rakefile +0 -54
  62. data/manual/absolute_position.pdf +0 -0
  63. data/manual/basic_concepts/adding_pages.rb +0 -26
  64. data/manual/basic_concepts/basic_concepts.rb +0 -43
  65. data/manual/basic_concepts/creation.rb +0 -38
  66. data/manual/basic_concepts/cursor.rb +0 -32
  67. data/manual/basic_concepts/measurement.rb +0 -24
  68. data/manual/basic_concepts/origin.rb +0 -37
  69. data/manual/basic_concepts/other_cursor_helpers.rb +0 -39
  70. data/manual/basic_concepts/view.rb +0 -48
  71. data/manual/bounding_box/bounding_box.rb +0 -41
  72. data/manual/bounding_box/bounds.rb +0 -48
  73. data/manual/bounding_box/canvas.rb +0 -23
  74. data/manual/bounding_box/creation.rb +0 -22
  75. data/manual/bounding_box/indentation.rb +0 -45
  76. data/manual/bounding_box/nesting.rb +0 -52
  77. data/manual/bounding_box/russian_boxes.rb +0 -40
  78. data/manual/bounding_box/stretchy.rb +0 -29
  79. data/manual/contents.rb +0 -35
  80. data/manual/cover.rb +0 -43
  81. data/manual/document_and_page_options/background.rb +0 -25
  82. data/manual/document_and_page_options/document_and_page_options.rb +0 -34
  83. data/manual/document_and_page_options/metadata.rb +0 -25
  84. data/manual/document_and_page_options/page_margins.rb +0 -36
  85. data/manual/document_and_page_options/page_size.rb +0 -34
  86. data/manual/document_and_page_options/print_scaling.rb +0 -22
  87. data/manual/example_helper.rb +0 -8
  88. data/manual/graphics/blend_mode.rb +0 -52
  89. data/manual/graphics/circle_and_ellipse.rb +0 -21
  90. data/manual/graphics/color.rb +0 -22
  91. data/manual/graphics/common_lines.rb +0 -29
  92. data/manual/graphics/fill_and_stroke.rb +0 -41
  93. data/manual/graphics/fill_rules.rb +0 -37
  94. data/manual/graphics/gradients.rb +0 -43
  95. data/manual/graphics/graphics.rb +0 -64
  96. data/manual/graphics/helper.rb +0 -27
  97. data/manual/graphics/line_width.rb +0 -36
  98. data/manual/graphics/lines_and_curves.rb +0 -40
  99. data/manual/graphics/polygon.rb +0 -27
  100. data/manual/graphics/rectangle.rb +0 -20
  101. data/manual/graphics/rotate.rb +0 -25
  102. data/manual/graphics/scale.rb +0 -42
  103. data/manual/graphics/soft_masks.rb +0 -44
  104. data/manual/graphics/stroke_cap.rb +0 -30
  105. data/manual/graphics/stroke_dash.rb +0 -47
  106. data/manual/graphics/stroke_join.rb +0 -29
  107. data/manual/graphics/translate.rb +0 -28
  108. data/manual/graphics/transparency.rb +0 -33
  109. data/manual/how_to_read_this_manual.rb +0 -39
  110. data/manual/images/absolute_position.rb +0 -22
  111. data/manual/images/fit.rb +0 -20
  112. data/manual/images/horizontal.rb +0 -24
  113. data/manual/images/images.rb +0 -41
  114. data/manual/images/plain_image.rb +0 -17
  115. data/manual/images/scale.rb +0 -21
  116. data/manual/images/vertical.rb +0 -27
  117. data/manual/images/width_and_height.rb +0 -24
  118. data/manual/layout/boxes.rb +0 -26
  119. data/manual/layout/content.rb +0 -24
  120. data/manual/layout/layout.rb +0 -27
  121. data/manual/layout/simple_grid.rb +0 -22
  122. data/manual/outline/add_subsection_to.rb +0 -60
  123. data/manual/outline/insert_section_after.rb +0 -46
  124. data/manual/outline/outline.rb +0 -33
  125. data/manual/outline/sections_and_pages.rb +0 -66
  126. data/manual/repeatable_content/alternate_page_numbering.rb +0 -36
  127. data/manual/repeatable_content/page_numbering.rb +0 -55
  128. data/manual/repeatable_content/repeatable_content.rb +0 -35
  129. data/manual/repeatable_content/repeater.rb +0 -54
  130. data/manual/repeatable_content/stamp.rb +0 -40
  131. data/manual/security/encryption.rb +0 -28
  132. data/manual/security/permissions.rb +0 -41
  133. data/manual/security/security.rb +0 -28
  134. data/manual/table.rb +0 -16
  135. data/manual/text/alignment.rb +0 -43
  136. data/manual/text/color.rb +0 -24
  137. data/manual/text/column_box.rb +0 -30
  138. data/manual/text/fallback_fonts.rb +0 -41
  139. data/manual/text/font.rb +0 -40
  140. data/manual/text/font_size.rb +0 -44
  141. data/manual/text/font_style.rb +0 -22
  142. data/manual/text/formatted_callbacks.rb +0 -65
  143. data/manual/text/formatted_text.rb +0 -58
  144. data/manual/text/free_flowing_text.rb +0 -50
  145. data/manual/text/inline.rb +0 -40
  146. data/manual/text/kerning_and_character_spacing.rb +0 -38
  147. data/manual/text/leading.rb +0 -24
  148. data/manual/text/line_wrapping.rb +0 -60
  149. data/manual/text/paragraph_indentation.rb +0 -32
  150. data/manual/text/positioned_text.rb +0 -37
  151. data/manual/text/registering_families.rb +0 -51
  152. data/manual/text/rendering_and_color.rb +0 -36
  153. data/manual/text/right_to_left_text.rb +0 -54
  154. data/manual/text/rotation.rb +0 -47
  155. data/manual/text/single_usage.rb +0 -36
  156. data/manual/text/text.rb +0 -75
  157. data/manual/text/text_box_excess.rb +0 -35
  158. data/manual/text/text_box_extensions.rb +0 -48
  159. data/manual/text/text_box_overflow.rb +0 -49
  160. data/manual/text/utf8.rb +0 -27
  161. data/manual/text/win_ansi_charset.rb +0 -62
  162. data/prawn.gemspec +0 -57
  163. data/spec/data/curves.pdf +0 -66
  164. data/spec/extensions/encoding_helpers.rb +0 -11
  165. data/spec/prawn/document/bounding_box_spec.rb +0 -546
  166. data/spec/prawn/document/column_box_spec.rb +0 -75
  167. data/spec/prawn/document/security_spec.rb +0 -176
  168. data/spec/prawn/document_annotations_spec.rb +0 -76
  169. data/spec/prawn/document_destinations_spec.rb +0 -15
  170. data/spec/prawn/document_grid_spec.rb +0 -99
  171. data/spec/prawn/document_reference_spec.rb +0 -27
  172. data/spec/prawn/document_span_spec.rb +0 -36
  173. data/spec/prawn/document_spec.rb +0 -802
  174. data/spec/prawn/font_metric_cache_spec.rb +0 -54
  175. data/spec/prawn/font_spec.rb +0 -542
  176. data/spec/prawn/graphics/blend_mode_spec.rb +0 -63
  177. data/spec/prawn/graphics/transparency_spec.rb +0 -81
  178. data/spec/prawn/graphics_spec.rb +0 -837
  179. data/spec/prawn/graphics_stroke_styles_spec.rb +0 -229
  180. data/spec/prawn/image_handler_spec.rb +0 -53
  181. data/spec/prawn/images/jpg_spec.rb +0 -20
  182. data/spec/prawn/images/png_spec.rb +0 -283
  183. data/spec/prawn/images_spec.rb +0 -224
  184. data/spec/prawn/measurements_extensions_spec.rb +0 -24
  185. data/spec/prawn/outline_spec.rb +0 -412
  186. data/spec/prawn/repeater_spec.rb +0 -165
  187. data/spec/prawn/soft_mask_spec.rb +0 -74
  188. data/spec/prawn/stamp_spec.rb +0 -172
  189. data/spec/prawn/text/box_spec.rb +0 -1112
  190. data/spec/prawn/text/formatted/arranger_spec.rb +0 -466
  191. data/spec/prawn/text/formatted/box_spec.rb +0 -846
  192. data/spec/prawn/text/formatted/fragment_spec.rb +0 -343
  193. data/spec/prawn/text/formatted/line_wrap_spec.rb +0 -494
  194. data/spec/prawn/text/formatted/parser_spec.rb +0 -697
  195. data/spec/prawn/text_draw_text_spec.rb +0 -149
  196. data/spec/prawn/text_rendering_mode_spec.rb +0 -48
  197. data/spec/prawn/text_spacing_spec.rb +0 -95
  198. data/spec/prawn/text_spec.rb +0 -603
  199. data/spec/prawn/text_with_inline_formatting_spec.rb +0 -35
  200. data/spec/prawn/transformation_stack_spec.rb +0 -66
  201. data/spec/prawn/view_spec.rb +0 -63
  202. data/spec/prawn_manual_spec.rb +0 -35
  203. data/spec/spec_helper.rb +0 -48
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # This sets the dashed pattern for lines and curves. The (dash) length defines
4
- # how long each dash will be.
5
- #
6
- # The <code>:space</code> option defines the length of the space between the
7
- # dashes.
8
- #
9
- # The <code>:phase</code> option defines the start point of the sequence of
10
- # dashes and spaces.
11
- #
12
- # Complex dash patterns can be specified by using an array with alternating
13
- # dash/gap lengths for the first parameter (note that the <code>:space</code>
14
- # option is ignored in this case).
15
-
16
- require_relative '../example_helper'
17
-
18
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
19
- Prawn::ManualBuilder::Example.generate(filename) do
20
- stroke_axis
21
-
22
- dash([1, 2, 3, 2, 1, 5], phase: 6)
23
- stroke_horizontal_line 50, 500, at: 230
24
- dash([1, 2, 3, 4, 5, 6, 7, 8])
25
- stroke_horizontal_line 50, 500, at: 220
26
-
27
- base_y = 210
28
-
29
- 24.times do |i|
30
- length = (i / 4) + 1
31
- space = length # space between dashes same length as dash
32
- phase = 0 # start with dash
33
-
34
- case i % 4
35
- when 0 then base_y -= 5
36
- when 1 then phase = length # start with space between dashes
37
- when 2 then space = length * 0.5 # space between dashes half as long as dash
38
- when 3
39
- space = length * 0.5 # space between dashes half as long as dash
40
- phase = length # start with space between dashes
41
- end
42
- base_y -= 5
43
-
44
- dash(length, space: space, phase: phase)
45
- stroke_horizontal_line 50, 500, at: base_y - (2 * i)
46
- end
47
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # The join style defines how the intersection between two lines is drawn. There
4
- # are three types: <code>:miter</code> (the default), <code>:round</code> and
5
- # <code>:bevel</code>
6
- #
7
- # Just like <code>cap_style</code>, the difference between styles is better
8
- # seen with thicker lines.
9
-
10
- require_relative '../example_helper'
11
-
12
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
13
- Prawn::ManualBuilder::Example.generate(filename) do
14
- stroke_axis
15
-
16
- self.line_width = 25
17
-
18
- %i[miter round bevel].each_with_index do |style, i|
19
- self.join_style = style
20
-
21
- y = 200 - i * 100
22
- stroke do
23
- move_to(100, y)
24
- line_to(200, y + 100)
25
- line_to(300, y)
26
- end
27
- stroke_rectangle [400, y + 75], 50, 50
28
- end
29
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # This transformation is used to translate the user space. Just provide the
4
- # x and y coordinates for the new origin.
5
-
6
- require_relative '../example_helper'
7
-
8
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
9
- Prawn::ManualBuilder::Example.generate(filename) do
10
- stroke_axis
11
-
12
- 1.upto(3) do |i|
13
- x = i * 50
14
- y = i * 100
15
- translate(x, y) do
16
- # Draw a point on the new origin
17
- fill_circle [0, 0], 2
18
- draw_text "New origin after translation to [#{x}, #{y}]",
19
- at: [5, -2], size: 8
20
-
21
- stroke_rectangle [100, 75], 100, 50
22
- text_box 'Top left corner at [100,75]',
23
- at: [110, 65],
24
- width: 80,
25
- size: 8
26
- end
27
- end
28
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Although the name of the method is <code>transparency</code>, what we are
4
- # actually setting is the opacity for fill and stroke. So <code>0</code> means
5
- # completely transparent and <code>1.0</code> means completely opaque
6
- #
7
- # You may call it providing one or two values. The first value sets fill opacity
8
- # and the second value sets stroke opacity. If the second value is omitted fill
9
- # and stroke will have the same opacity.
10
-
11
- require_relative '../example_helper'
12
-
13
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
14
- Prawn::ManualBuilder::Example.generate(filename) do
15
- stroke_axis
16
-
17
- self.line_width = 5
18
- fill_color 'ff0000'
19
- fill_rectangle [0, 100], 500, 100
20
-
21
- fill_color '000000'
22
- stroke_color 'ffffff'
23
-
24
- base_x = 100
25
- [[0.5, 1], 0.5, [1, 0.5]].each do |args|
26
- transparent(*args) do
27
- fill_circle [base_x, 100], 50
28
- stroke_rectangle [base_x - 20, 100], 40, 80
29
- end
30
-
31
- base_x += 150
32
- end
33
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Prawn manual how to read this manual page.
4
-
5
- require_relative 'example_helper'
6
-
7
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
8
- Prawn::ManualBuilder::Example.generate(filename) do
9
- header('How to read this manual')
10
-
11
- prose <<-END_TEXT
12
- This manual is a collection of examples categorized by theme and organized from the least to the most complex. While it covers most of the common use cases it is not a comprehensive guide.
13
-
14
- The best way to read it depends on your previous knowledge of Prawn and what you need to accomplish.
15
-
16
- If you are beginning with Prawn the first chapter will teach you the most basic concepts and how to create pdf documents. For an overview of the other features each chapter beyond the first either has a Basics section (which offer enough insight on the feature without showing all the advanced stuff you might never use) or is simple enough with only a few examples.
17
-
18
- Once you understand the basics you might want to come back to this manual looking for examples that accomplish tasks you need.
19
-
20
- Advanced users are encouraged to go beyond this manual and read the source code directly if any doubt is not directly covered on this manual.
21
- END_TEXT
22
-
23
- move_down(Prawn::ManualBuilder::Example::BOX_MARGIN)
24
- header('Reading the examples')
25
-
26
- prose <<-END_TEXT
27
- The title of each example is the relative path from the Prawn source manual/ folder.
28
-
29
- The first body of text is the introductory text for the example. Generally it is a short description of the features illustrated by the example.
30
-
31
- Next comes the example source code block in fixed width font.
32
-
33
- Most of the example snippets illustrate features that alter the page in place. The effect of these snippets is shown right below a dashed line. If it doesn't make sense to evaluate the snippet inline, a box with the link for the example file is shown instead.
34
-
35
- Note that the <code>stroke_axis</code> method used throughout the manual is part of standard Prawn. It is defined in this file:
36
-
37
- https://github.com/prawnpdf/prawn/blob/master/lib/prawn/graphics.rb
38
- END_TEXT
39
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # One of the options that the <code>image</code> method accepts is
4
- # <code>:at</code>. If you've read some of the graphics examples you are
5
- # probably already familiar with it. Just provide it the upper-left corner where
6
- # you want the image placed.
7
- #
8
- # While sometimes useful this option won't be practical. Notice that the cursor
9
- # won't be moved after the image is rendered and there is nothing forbidding the
10
- # text to overlap with the image.
11
-
12
- require_relative '../example_helper'
13
-
14
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
15
- Prawn::ManualBuilder::Example.generate(filename) do
16
- y_position = cursor
17
- text "The image won't go below this line of text."
18
-
19
- image "#{Prawn::DATADIR}/images/fractal.jpg", at: [200, y_position]
20
-
21
- text 'And this line of text will go just below the previous one.'
22
- end
data/manual/images/fit.rb DELETED
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # <code>:fit</code> option is useful when you want the image to have the
4
- # maximum size within a container preserving the aspect ratio without
5
- # overlapping.
6
- #
7
- # Just provide the container width and height pair.
8
-
9
- require_relative '../example_helper'
10
-
11
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
12
- Prawn::ManualBuilder::Example.generate(filename) do
13
- size = 300
14
-
15
- text 'Using the fit option'
16
- bounding_box([0, cursor], width: size, height: size) do
17
- image "#{Prawn::DATADIR}/images/pigs.jpg", fit: [size, size]
18
- stroke_bounds
19
- end
20
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # The image may be positioned relatively to the current bounding box. The
4
- # horizontal position may be set with the <code>:position</code> option.
5
- #
6
- # It may be <code>:left</code>, <code>:center</code>, <code>:right</code> or a
7
- # number representing an x-offset from the left boundary.
8
-
9
- require_relative '../example_helper'
10
-
11
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
12
- Prawn::ManualBuilder::Example.generate(filename) do
13
- bounding_box([50, cursor], width: 400, height: 450) do
14
- stroke_bounds
15
-
16
- %i[left center right].each do |position|
17
- text "Image aligned to the #{position}."
18
- image "#{Prawn::DATADIR}/images/stef.jpg", position: position
19
- end
20
-
21
- text 'The next image has a 50 point offset from the left boundary'
22
- image "#{Prawn::DATADIR}/images/stef.jpg", position: 50
23
- end
24
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Examples for embedding images.
4
-
5
- require_relative '../example_helper'
6
-
7
- Prawn::ManualBuilder::Example.generate('images.pdf', page_size: 'FOLIO') do
8
- package 'images' do |p|
9
- p.section 'Basics' do |s|
10
- s.example 'plain_image'
11
- s.example 'absolute_position'
12
- end
13
-
14
- p.section 'Relative Positioning' do |s|
15
- s.example 'horizontal'
16
- s.example 'vertical'
17
- end
18
-
19
- p.section 'Size' do |s|
20
- s.example 'width_and_height'
21
- s.example 'scale'
22
- s.example 'fit'
23
- end
24
-
25
- p.intro do
26
- prose <<-TEXT
27
- Embedding images on PDF documents is fairly easy. Prawn supports both
28
- JPG and PNG images.
29
-
30
- The examples show:
31
- TEXT
32
-
33
- list(
34
- 'How to add an image to a page',
35
- 'How place the image on a specific position',
36
- 'How to configure the image dimensions by setting the width and '\
37
- 'height or by scaling it'
38
- )
39
- end
40
- end
41
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # To embed images onto your PDF file use the <code>image</code> method.
4
- # It accepts the file path of the image to be loaded and some optional
5
- # arguments.
6
- #
7
- # If only the image path is provided the image will be rendered starting on
8
- # the cursor position. No manipulation is done with the image even if it doesn't
9
- # fit entirely on the page like the following snippet.
10
-
11
- require_relative '../example_helper'
12
-
13
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
14
- Prawn::ManualBuilder::Example.generate(filename) do
15
- text 'The image will go right below this line of text.'
16
- image "#{Prawn::DATADIR}/images/pigs.jpg"
17
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # To scale an image use the <code>:scale</code> option.
4
- #
5
- # It scales the image proportionally given the provided value.
6
-
7
- require_relative '../example_helper'
8
-
9
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
10
- Prawn::ManualBuilder::Example.generate(filename) do
11
- text 'Normal size'
12
- image "#{Prawn::DATADIR}/images/stef.jpg"
13
- move_down 20
14
-
15
- text 'Scaled to 50%'
16
- image "#{Prawn::DATADIR}/images/stef.jpg", scale: 0.5
17
- move_down 20
18
-
19
- text 'Scaled to 200%'
20
- image "#{Prawn::DATADIR}/images/stef.jpg", scale: 2
21
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # To set the vertical position of an image use the <code>:vposition</code>
4
- # option.
5
- #
6
- # It may be <code>:top</code>, <code>:center</code>, <code>:bottom</code> or a
7
- # number representing the y-offset from the top boundary.
8
-
9
- require_relative '../example_helper'
10
-
11
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
12
- Prawn::ManualBuilder::Example.generate(filename) do
13
- bounding_box([0, cursor], width: 500, height: 450) do
14
- stroke_bounds
15
-
16
- %i[top center bottom].each do |vposition|
17
- text "Image vertically aligned to the #{vposition}.", valign: vposition
18
- image "#{Prawn::DATADIR}/images/stef.jpg",
19
- position: 250, vposition: vposition
20
- end
21
-
22
- text_box 'The next image has a 100 point offset from the top boundary',
23
- at: [bounds.width - 110, bounds.top - 10], width: 100
24
- image "#{Prawn::DATADIR}/images/stef.jpg",
25
- position: :right, vposition: 100
26
- end
27
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # The image size can be set with the <code>:width</code> and
4
- # <code>:height</code> options.
5
- #
6
- # If only one of those is provided, the image will be scaled proportionally.
7
- # When both are provided, the image will be stretched to fit the dimensions
8
- # without maintaining the aspect ratio.
9
-
10
- require_relative '../example_helper'
11
-
12
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
13
- Prawn::ManualBuilder::Example.generate(filename) do
14
- text 'Scale by setting only the width'
15
- image "#{Prawn::DATADIR}/images/pigs.jpg", width: 150
16
- move_down 20
17
-
18
- text 'Scale by setting only the height'
19
- image "#{Prawn::DATADIR}/images/pigs.jpg", height: 100
20
- move_down 20
21
-
22
- text 'Stretch to fit the width and height provided'
23
- image "#{Prawn::DATADIR}/images/pigs.jpg", width: 500, height: 100
24
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # After defined the grid is there but nothing happens. To start taking effect
4
- # we need to use the grid boxes.
5
- #
6
- # <code>grid</code> has three different return values based on the arguments
7
- # received. With no arguments it will return the grid itself. With integers it
8
- # will return the grid box at those indices. With two arrays it will return a
9
- # multi-box spanning the region of the two grid boxes at the arrays indices.
10
-
11
- require_relative '../example_helper'
12
-
13
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
14
- Prawn::ManualBuilder::Example.generate(filename) do
15
- # The grid only need to be defined once, but since all the examples should be
16
- # able to run alone we are repeating it on every example
17
- define_grid(columns: 5, rows: 8, gutter: 10)
18
-
19
- grid(4, 0).show
20
- grid(5, 1).show
21
-
22
- grid([6, 2], [7, 3]).show
23
-
24
- grid([4, 4], [7, 4]).show
25
- grid([7, 0], [7, 1]).show
26
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Now that we know how to access the boxes we might as well add some content
4
- # to them.
5
- #
6
- # This can be done by taping into the bounding box for a given grid box or
7
- # multi-box with the <code>bounding_box</code> method.
8
-
9
- require_relative '../example_helper'
10
-
11
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
12
- Prawn::ManualBuilder::Example.generate(filename) do
13
- # The grid only need to be defined once, but since all the examples should be
14
- # able to run alone we are repeating it on every example
15
- define_grid(columns: 5, rows: 8, gutter: 10)
16
-
17
- grid([5, 0], [7, 1]).bounding_box do
18
- text "Adding some content to this multi_box.\n" + ' _ ' * 200
19
- end
20
-
21
- grid(6, 3).bounding_box do
22
- text "Just a little snippet here.\n" + ' _ ' * 10
23
- end
24
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Examples for using grid layouts.
4
-
5
- require_relative '../example_helper'
6
-
7
- Prawn::ManualBuilder::Example.generate('layout.pdf', page_size: 'FOLIO') do
8
- package 'layout' do |p|
9
- p.example 'simple_grid'
10
- p.example 'boxes'
11
- p.example 'content'
12
-
13
- p.intro do
14
- prose <<-TEXT
15
- Prawn has support for two-dimensional grid based layouts out of the box.
16
-
17
- The examples show:
18
- TEXT
19
-
20
- list(
21
- 'How to define the document grid',
22
- 'How to configure the grid rows and columns gutters',
23
- 'How to create boxes according to the grid'
24
- )
25
- end
26
- end
27
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # The document grid on Prawn is just a table-like structure with a defined
4
- # number of rows and columns. There are some helpers to create boxes of content
5
- # based on the grid coordinates.
6
- #
7
- # <code>define_grid</code> accepts the following options which are pretty much
8
- # self-explanatory: <code>:rows</code>, <code>:columns</code>,
9
- # <code>:gutter</code>, <code>:row_gutter</code>, <code>:column_gutter</code>
10
-
11
- require_relative '../example_helper'
12
-
13
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
14
- Prawn::ManualBuilder::Example.generate(filename) do
15
- # The grid only need to be defined once, but since all the examples should be
16
- # able to run alone we are repeating it on every example
17
- define_grid(columns: 5, rows: 8, gutter: 10)
18
- text 'We defined the grid, roll over to the next page to see its outline'
19
-
20
- start_new_page
21
- grid.show_all
22
- end
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # We have already seen how to define an outline tree sequentially.
4
- #
5
- # If you'd like to add nodes to the middle of an outline tree the
6
- # <code>add_subsection_to</code> may help you.
7
- #
8
- # It allows you to insert sections to the outline tree at any point. Just
9
- # provide the <code>title</code> of the parent section, the
10
- # <code>position</code> you want the new subsection to be inserted
11
- # <code>:first</code> or <code>:last</code> (defaults to <code>:last</code>)
12
- # and a block to declare the subsection.
13
- #
14
- # The <code>add_subsection_to</code> block doesn't necessarily create new
15
- # sections, it may also create new pages.
16
- #
17
- # If the parent title provided is the title of a page. The page will be
18
- # converted into a section to receive the subsection created.
19
-
20
- require_relative '../example_helper'
21
-
22
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
23
- Prawn::ManualBuilder::Example.generate(filename) do
24
- # First we create 10 pages and some default outline
25
- (1..10).each do |index|
26
- text "Page #{index}"
27
- start_new_page
28
- end
29
-
30
- outline.define do
31
- section('Section 1', destination: 1) do
32
- page title: 'Page 2', destination: 2
33
- page title: 'Page 3', destination: 3
34
- end
35
- end
36
-
37
- # Now we will start adding nodes to the previous outline
38
- outline.add_subsection_to('Section 1', :first) do
39
- outline.section('Added later - first position') do
40
- outline.page title: 'Page 4', destination: 4
41
- outline.page title: 'Page 5', destination: 5
42
- end
43
- end
44
-
45
- outline.add_subsection_to('Section 1') do
46
- outline.page title: 'Added later - last position',
47
- destination: 6
48
- end
49
-
50
- outline.add_subsection_to('Added later - first position') do
51
- outline.page title: 'Another page added later',
52
- destination: 7
53
- end
54
-
55
- # The title provided is for a page which will be converted into a section
56
- outline.add_subsection_to('Page 3') do
57
- outline.page title: 'Last page added',
58
- destination: 8
59
- end
60
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Another way to insert nodes into an existing outline is the
4
- # <code>insert_section_after</code> method.
5
- #
6
- # It accepts the title of the node that the new section will go after and a
7
- # block declaring the new section.
8
- #
9
- # As is the case with <code>add_subsection_to</code> the section added
10
- # doesn't need to be a section, it may be just a page.
11
-
12
- require_relative '../example_helper'
13
-
14
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
15
- Prawn::ManualBuilder::Example.generate(filename) do
16
- # First we create 10 pages and some default outline
17
- (1..10).each do |index|
18
- text "Page #{index}"
19
- start_new_page
20
- end
21
-
22
- outline.define do
23
- section('Section 1', destination: 1) do
24
- page title: 'Page 2', destination: 2
25
- page title: 'Page 3', destination: 3
26
- end
27
- end
28
-
29
- # Now we will start adding nodes to the previous outline
30
- outline.insert_section_after('Page 2') do
31
- outline.section('Section after Page 2') do
32
- outline.page title: 'Page 4', destination: 4
33
- end
34
- end
35
-
36
- outline.insert_section_after('Section 1') do
37
- outline.section('Section after Section 1') do
38
- outline.page title: 'Page 5', destination: 5
39
- end
40
- end
41
-
42
- # Adding just a page
43
- outline.insert_section_after('Page 3') do
44
- outline.page title: 'Page after Page 3', destination: 6
45
- end
46
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Examples for defining the document outline.
4
-
5
- require_relative '../example_helper'
6
-
7
- Prawn::ManualBuilder::Example.generate('outline.pdf', page_size: 'FOLIO') do
8
- package 'outline' do |p|
9
- p.section 'Basics' do |s|
10
- s.example 'sections_and_pages', eval_source: false
11
- end
12
-
13
- p.section 'Adding nodes later' do |s|
14
- s.example 'add_subsection_to', eval_source: false
15
- s.example 'insert_section_after', eval_source: false
16
- end
17
-
18
- p.intro do
19
- prose <<-TEXT
20
- The outline of a PDF document is the table of contents tab you see to
21
- the right or left of your PDF viewer.
22
-
23
- The examples include:
24
- TEXT
25
-
26
- list(
27
- 'How to define sections and pages',
28
- 'How to insert sections and/or pages to a previously defined outline '\
29
- 'structure'
30
- )
31
- end
32
- end
33
- end