prawn 2.3.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
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
data/lib/prawn/text.rb CHANGED
@@ -1,154 +1,153 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # text.rb : Implements PDF text primitives
4
- #
5
- # Copyright May 2008, Gregory Brown. All Rights Reserved.
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
8
-
9
3
  require 'zlib'
10
4
 
11
5
  require_relative 'text/formatted'
12
6
  require_relative 'text/box'
13
7
 
14
8
  module Prawn
9
+ # PDF text primitives.
15
10
  module Text
16
11
  include PDF::Core::Text
17
12
  include Prawn::Text::Formatted
18
13
 
19
14
  # No-Break Space
20
15
  NBSP = "\u00A0"
16
+
21
17
  # Zero Width Space (indicate word boundaries without a space)
22
18
  ZWSP = "\u200B"
19
+
23
20
  # Soft Hyphen (invisible, except when causing a line break)
24
21
  SHY = "\u00AD"
25
22
 
26
23
  # @group Stable API
27
24
 
25
+ # Draws text on the page.
26
+ #
28
27
  # If you want text to flow onto a new page or between columns, this is the
29
- # method to use. If, instead, if you want to place bounded text outside of
30
- # the flow of a document (for captions, labels, charts, etc.), use Text::Box
31
- # or its convenience method text_box.
28
+ # method to use. If, instead, you want to place bounded text outside of the
29
+ # flow of a document (for captions, labels, charts, etc.), use {Text::Box}
30
+ # or its convenience method {text_box}.
32
31
  #
33
- # Draws text on the page. Prawn attempts to wrap the text to fit within your
34
- # current bounding box (or margin_box if no bounding box is being used).
35
- # Text will flow onto the next page when it reaches the bottom of the
36
- # bounding box. Text wrap in Prawn does not re-flow linebreaks, so if you
37
- # want fully automated text wrapping, be sure to remove newlines before
38
- # attempting to draw your string.
32
+ # Prawn attempts to wrap the text to fit within your current bounding box
33
+ # (or `margin_box` if no bounding box is being used). Text will flow onto
34
+ # the next page when it reaches the bottom of the bounding box. Text wrap in
35
+ # Prawn does not re-flow line breaks, so if you want fully automated text
36
+ # wrapping, be sure to remove newlines before attempting to draw your
37
+ # string.
39
38
  #
40
- # == Examples
39
+ # #### Examples
41
40
  #
42
- # pdf.text "Will be wrapped when it hits the edge of your bounding box"
43
- # pdf.text "This will be centered", :align => :center
44
- # pdf.text "This will be right aligned", :align => :right
45
- # pdf.text "This <i>includes <b>inline</b></i> <font size='24'>" +
46
- # "formatting</font>", :inline_format => true
41
+ # ```ruby
42
+ # pdf.text "Will be wrapped when it hits the edge of your bounding box"
43
+ # pdf.text "This will be centered", align: :center
44
+ # pdf.text "This will be right aligned", align: :right
45
+ # pdf.text "This <i>includes <b>inline</b></i> <font size='24'>formatting</font>", inline_format: true
46
+ # ```
47
47
  #
48
- # If your font contains kerning pair data that Prawn can parse, the
49
- # text will be kerned by default. You can disable kerning by including
50
- # a false <tt>:kerning</tt> option. If you want to disable kerning on an
51
- # entire document, set default_kerning = false for that document
48
+ # If your font contains kerning pair data that Prawn can parse, the text
49
+ # will be kerned by default. You can disable kerning by including a `false`
50
+ # `:kerning` option. If you want to disable kerning on an entire document,
51
+ # set `default_kerning = false` for that document.
52
52
  #
53
- # === Text Positioning Details
53
+ # #### Text Positioning Details
54
54
  #
55
- # The text is positioned at font.ascender below the baseline,
56
- # making it easy to use this method within bounding boxes and spans.
55
+ # The text is positioned at `font.ascender` below the baseline, making it
56
+ # easy to use this method within bounding boxes and spans.
57
57
  #
58
- # == Encoding
58
+ # #### Encoding
59
59
  #
60
- # Note that strings passed to this function should be encoded as UTF-8.
61
- # If you get unexpected characters appearing in your rendered document,
62
- # check this.
60
+ # Note that strings passed to this function should be encoded as UTF-8. If
61
+ # you get unexpected characters appearing in your rendered document, check
62
+ # this.
63
63
  #
64
- # If the current font is a built-in one, although the string must be
65
- # encoded as UTF-8, only characters that are available in WinAnsi
66
- # are allowed.
64
+ # If the current font is a built-in one, although the string must be encoded
65
+ # as UTF-8, only characters that are available in WinAnsi are allowed.
67
66
  #
68
67
  # If an empty box is rendered to your PDF instead of the character you
69
68
  # wanted it usually means the current font doesn't include that character.
70
69
  #
71
- # == Options (default values marked in [])
72
- #
73
- # <tt>:inline_format</tt>::
74
- # <tt>boolean</tt>. If true, then the string parameter is interpreted
75
- # as a HTML-esque string that recognizes the following tags
76
- # (assuming the default text formatter is used):
77
- # <tt>\<b></b></tt>:: bold
78
- # <tt>\<i></i></tt>:: italic
79
- # <tt>\<u></u></tt>:: underline
80
- # <tt>\<strikethrough></strikethrough></tt>:: strikethrough
81
- # <tt>\<sub></sub></tt>:: subscript
82
- # <tt>\<sup></sup></tt>:: superscript
83
- # <tt>\<font></font></tt>::
84
- # with the following attributes (using double or single quotes)
85
- # <tt>size="24"</tt>::
86
- # attribute for setting size
87
- # <tt>character_spacing="2.5"</tt>::
88
- # attribute for setting character spacing
89
- # <tt>name="Helvetica"</tt>::
90
- # attribute for setting the font. The font name must be an
91
- # AFM font with the desired faces or must be a font that is
92
- # already registered using Prawn::Document#font_families
93
- # <tt>\<color></color></tt>::
94
- # with the following attributes
95
- # <tt>rgb="ffffff" or rgb="#ffffff"</tt>::
96
- # <tt>c="100" m="100" y="100" k="100"</tt>::
97
- # <tt>\<link></link></tt>::
98
- # with the following attributes
99
- # <tt>href="http://example.com"</tt>:: an external link
100
- # Note that you must explicitly underline and color using the
101
- # appropriate tags if you which to draw attention to the link
102
- #
103
- # <tt>:kerning</tt>:: <tt>boolean</tt>. Whether or not to use kerning (if it
104
- # is available with the current font)
105
- # [value of document.default_kerning?]
106
- # <tt>:size</tt>:: <tt>number</tt>. The font size to use. [current font
107
- # size]
108
- # <tt>:color</tt>:: an RGB color ("ff0000") or CMYK array [10, 20, 30, 40].
109
- # <tt>:character_spacing</tt>:: <tt>number</tt>. The amount of space to add
110
- # to or remove from the default character
111
- # spacing. [0]
112
- # <tt>:style</tt>:: The style to use. The requested style must be part of
113
- # the current font familly. [current style]
114
- # <tt>:indent_paragraphs</tt>:: <tt>number</tt>. The amount to indent the
115
- # first line of each paragraph. Omit this
116
- # option if you do not want indenting.
117
- # <tt>:direction</tt>::
118
- # <tt>:ltr</tt>, <tt>:rtl</tt>, Direction of the text (left-to-right
119
- # or right-to-left) [value of document.text_direction]
120
- # <tt>:fallback_fonts</tt>::
121
- # An array of font names. Each name must be the name of an AFM font or
122
- # the name that was used to register a family of TTF fonts (see
123
- # Prawn::Document#font_families). If present, then each glyph will be
124
- # rendered using the first font that includes the glyph, starting with
125
- # the current font and then moving through :fallback_fonts from
126
- # left to right.
127
- # <tt>:align</tt>::
128
- # <tt>:left</tt>, <tt>:center</tt>, <tt>:right</tt>, or
129
- # <tt>:justify</tt> Alignment within the bounding box
130
- # [:left if direction is :ltr, :right if direction is :rtl]
131
- # <tt>:valign</tt>:: <tt>:top</tt>, <tt>:center</tt>, or <tt>:bottom</tt>.
132
- # Vertical alignment within the bounding box [:top]
133
- # <tt>:leading</tt>::
134
- # <tt>number</tt>. Additional space between lines [value of
135
- # document.default_leading]
136
- # <tt>:final_gap</tt>:: <tt>boolean</tt>. If true, then the space between
137
- # each line is included below the last line;
138
- # otherwise, document.y is placed just below the
139
- # descender of the last line printed [true]
140
- # <tt>:mode</tt>:: The text rendering mode to use. Use this to specify if
141
- # the text should render with the fill color, stroke color
142
- # or both. See the comments to text_rendering_mode() to see
143
- # a list of valid options. [0]
144
- #
145
- # == Exceptions
146
- #
147
- # Raises <tt>ArgumentError</tt> if <tt>:at</tt> option included
148
- #
149
- # Raises <tt>Prawn::Errrors::CannotFit</tt> if not wide enough to print
150
- # any text
151
- #
70
+ # @param string [String]
71
+ # @param options [Hash{Symbol => any}]
72
+ # @option options :inline_format [Boolean]
73
+ # If `true`, then the string parameter is interpreted as a HTML-esque
74
+ # string that recognizes the following tags (assuming the default text
75
+ # formatter is used):
76
+ # - `<b></b>`{:.language-html} --- bold style.
77
+ # - `<i></i>`{:.language-html} --- italic style.
78
+ # - `<u></u>`{:.language-html} --- underline.
79
+ # - `<strikethrough></strikethrough>`{:.language-html} --- strikethrough.
80
+ # - `<sub></sub>`{:.language-html} --- subscript.
81
+ # - `<sup></sup>`{:.language-html} --- superscript.
82
+ # - `<font></font>`{:.language-html} --- with the following attributes
83
+ # (using double or single quotes):
84
+ # - `name="Helvetica"`{:.language-html} --- the font. The font name must
85
+ # be an AFM font with the desired faces or must be a font that is
86
+ # already registered using {Prawn::Document#font_families}.
87
+ # - `size="24"`{:.language-html} --- attribute for setting size.
88
+ # - `character_spacing="2.5"`{:.language-html} --- character spacing.
89
+ # - `<color></color>`{:.language-html} --- text color
90
+ # - `rgb="ffffff"`{:.language-html} or `rgb="#ffffff"`{:.language-html}
91
+ # --- RGB color
92
+ # - `c="100" m="100" y="100" k="100"`{:.language-html} --- CMYK color
93
+ # - `<link></link>`{:.language-html} - link, with the following
94
+ # attributes:
95
+ # - `href="http://example.com"`{:.language-html} --- an external link.
96
+ # Note that you must explicitly underline and color using the
97
+ # appropriate tags if you which to draw attention to the link.
98
+ # @option options :kerning [Boolean] (value of document.default_kerning?)
99
+ # Whether or not to use kerning (if it is available with the current
100
+ # font).
101
+ # @option options :size [Number] (current ofnt size) The font size to use.
102
+ # @option options :color [Color]
103
+ # @option options :character_spacing [Number] (0)
104
+ # The amount of space to add to or remove from the default character
105
+ # spacing.
106
+ # @option options :style [Symbol] (current style)
107
+ # The style to use. The requested style must be part of the current font
108
+ # family.
109
+ # @option options :indent_paragraphs [Number]
110
+ # The amount to indent the first line of each paragraph. Omit this option
111
+ # if you do not want indenting.
112
+ # @option options :direction [:ltr, :rtl] (value of document.text_direction)
113
+ # Direction of the text.
114
+ # @option options :fallback_fonts [Array<String>]
115
+ # An array of font names. Each name must be the name of an AFM font or the
116
+ # name that was used to register a family of TTF fonts (see
117
+ # {Prawn::Document#font_families}). If present, then each glyph will be
118
+ # rendered using the first font that includes the glyph, starting with the
119
+ # current font and then moving through `:fallback_fonts`.
120
+ # @option option :align [:left, :center, :right, :justify]
121
+ # (:left if direction is :ltr, :right if direction is :rtl)
122
+ # Alignment within the bounding box.
123
+ # @option options :valign [:top, :center, :bottom] (:top)
124
+ # Vertical alignment within the bounding box.
125
+ # @option options :leading (Number) (value of document.default_leading)
126
+ # Additional space between lines.
127
+ # @option options :final_gap [Boolean] (true)
128
+ # If `true`, then the space between each line is included below the last
129
+ # line; otherwise, {Document.y} is placed just below the descender of the
130
+ # last line printed.
131
+ # @option options :mode [Symbol] (:fill)
132
+ # The text rendering mode to use. Use this to specify if the text should
133
+ # render with the fill color, stroke color or both.
134
+ # * `:fill` - fill text (default)
135
+ # * `:stroke` - stroke text
136
+ # * `:fill_stroke` - fill, then stroke text
137
+ # * `:invisible` - invisible text
138
+ # * `:fill_clip` - fill text then add to path for clipping
139
+ # * `:stroke_clip` - stroke text then add to path for clipping
140
+ # * `:fill_stroke_clip` - fill then stroke text, then add to path for
141
+ # clipping
142
+ # * `:clip` - add text to path for clipping
143
+ #
144
+ # @return [void]
145
+ #
146
+ # @raise [ArgumentError] if `:at` option included
147
+ # @raise [Prawn::Errrors::CannotFit] if not wide enough to print any text
148
+ #
149
+ # @see PDF::Core::Text#text_rendering_mode()
150
+ # for a list of valid text rendering modes.
152
151
  def text(string, options = {})
153
152
  return false if string.nil?
154
153
 
@@ -168,45 +167,117 @@ module Prawn
168
167
  end
169
168
 
170
169
  # Draws formatted text to the page.
171
- # Formatted text is comprised of an array of hashes, where each hash defines
172
- # text and format information. See Text::Formatted#formatted_text_box for
173
- # more information on the structure of this array
174
170
  #
175
- # == Example
171
+ # Formatted text is an array of hashes, where each hash defines text and
172
+ # format information.
176
173
  #
174
+ # @example
177
175
  # text([{ :text => "hello" },
178
176
  # { :text => "world",
179
177
  # :size => 24,
180
178
  # :styles => [:bold, :italic] }])
181
179
  #
182
- # == Options
183
- #
184
- # Accepts the same options as #text
185
- #
186
- # == Exceptions
187
- #
188
- # Same as for #text
189
- #
180
+ # @param array [Array<Hash>] array of text fragments. See
181
+ # {Text::Formatted#formatted_text_box} for more information on the
182
+ # structure of this array.
183
+ # @param options [Hash{Symbol => any}]
184
+ # @option options :inline_format [Boolean]
185
+ # If `true`, then the string parameter is interpreted as a HTML-esque
186
+ # string that recognizes the following tags (assuming the default text
187
+ # formatter is used):
188
+ # - `<b></b>`{:.language-html} --- bold style.
189
+ # - `<i></i>`{:.language-html} --- italic style.
190
+ # - `<u></u>`{:.language-html} --- underline.
191
+ # - `<strikethrough></strikethrough>`{:.language-html} --- strikethrough.
192
+ # - `<sub></sub>`{:.language-html} --- subscript.
193
+ # - `<sup></sup>`{:.language-html} --- superscript.
194
+ # - `<font></font>`{:.language-html} --- with the following attributes
195
+ # (using double or single quotes):
196
+ # - `name="Helvetica"`{:.language-html} --- the font. The font name must
197
+ # be an AFM font with the desired faces or must be a font that is
198
+ # already registered using {Prawn::Document#font_families}.
199
+ # - `size="24"`{:.language-html} --- attribute for setting size.
200
+ # - `character_spacing="2.5"`{:.language-html} --- character spacing.
201
+ # - `<color></color>`{:.language-html} --- text color
202
+ # - `rgb="ffffff"`{:.language-html} or `rgb="#ffffff"`{:.language-html}
203
+ # --- RGB color
204
+ # - `c="100" m="100" y="100" k="100"`{:.language-html} --- CMYK color
205
+ # - `<link></link>`{:.language-html} - link, with the following
206
+ # attributes:
207
+ # - `href="http://example.com"`{:.language-html} --- an external link.
208
+ # Note that you must explicitly underline and color using the
209
+ # appropriate tags if you which to draw attention to the link.
210
+ # @option options :kerning [Boolean] (value of document.default_kerning?)
211
+ # Whether or not to use kerning (if it is available with the current
212
+ # font).
213
+ # @option options :size [Number] (current ofnt size) The font size to use.
214
+ # @option options :color [Color]
215
+ # @option options :character_spacing [Number] (0)
216
+ # The amount of space to add to or remove from the default character
217
+ # spacing.
218
+ # @option options :style [Symbol] (current style)
219
+ # The style to use. The requested style must be part of the current font
220
+ # family.
221
+ # @option options :indent_paragraphs [Number]
222
+ # The amount to indent the first line of each paragraph. Omit this option
223
+ # if you do not want indenting.
224
+ # @option options :direction [:ltr, :rtl] (value of document.text_direction)
225
+ # Direction of the text.
226
+ # @option options :fallback_fonts [Array<String>]
227
+ # An array of font names. Each name must be the name of an AFM font or the
228
+ # name that was used to register a family of TTF fonts (see
229
+ # {Prawn::Document#font_families}). If present, then each glyph will be
230
+ # rendered using the first font that includes the glyph, starting with the
231
+ # current font and then moving through `:fallback_fonts`.
232
+ # @option option :align [:left, :center, :right, :justify]
233
+ # (:left if direction is :ltr, :right if direction is :rtl)
234
+ # Alignment within the bounding box.
235
+ # @option options :valign [:top, :center, :bottom] (:top)
236
+ # Vertical alignment within the bounding box.
237
+ # @option options :leading (Number) (value of document.default_leading)
238
+ # Additional space between lines.
239
+ # @option options :final_gap [Boolean] (true)
240
+ # If `true`, then the space between each line is included below the last
241
+ # line; otherwise, {Document.y} is placed just below the descender of the
242
+ # last line printed.
243
+ # @option options :mode [Symbol] (:fill)
244
+ # The text rendering mode to use. Use this to specify if the text should
245
+ # render with the fill color, stroke color or both.
246
+ # * `:fill` - fill text (default)
247
+ # * `:stroke` - stroke text
248
+ # * `:fill_stroke` - fill, then stroke text
249
+ # * `:invisible` - invisible text
250
+ # * `:fill_clip` - fill text then add to path for clipping
251
+ # * `:stroke_clip` - stroke text then add to path for clipping
252
+ # * `:fill_stroke_clip` - fill then stroke text, then add to path for
253
+ # clipping
254
+ # * `:clip` - add text to path for clipping
255
+ #
256
+ # @return [void]
257
+ #
258
+ # @raise [ArgumentError] if `:at` option included
259
+ # @raise [Prawn::Errrors::CannotFit] if not wide enough to print any text
260
+ #
261
+ # @see PDF::Core::Text#text_rendering_mode()
262
+ # for a list of valid text rendering modes.
190
263
  def formatted_text(array, options = {})
191
264
  options = inspect_options_for_text(options.dup)
192
265
 
193
266
  color = options.delete(:color)
194
267
  if color
195
- array = array.map do |fragment|
196
- fragment[:color] ? fragment : fragment.merge(color: color)
197
- end
268
+ array =
269
+ array.map { |fragment|
270
+ fragment[:color] ? fragment : fragment.merge(color: color)
271
+ }
198
272
  end
199
273
 
200
274
  if @indent_paragraphs
201
275
  text_formatter.array_paragraphs(array).each do |paragraph|
202
276
  remaining_text = draw_indented_formatted_line(paragraph, options)
203
277
 
204
- if @no_text_printed
205
- # unless this paragraph was an empty line
206
- unless @all_text_printed
207
- @bounding_box.move_past_bottom
208
- remaining_text = draw_indented_formatted_line(paragraph, options)
209
- end
278
+ if @no_text_printed && !@all_text_printed
279
+ @bounding_box.move_past_bottom
280
+ remaining_text = draw_indented_formatted_line(paragraph, options)
210
281
  end
211
282
 
212
283
  unless @all_text_printed
@@ -220,61 +291,57 @@ module Prawn
220
291
  end
221
292
  end
222
293
 
223
- # Draws text on the page, beginning at the point specified by the :at option
224
- # the string is assumed to be pre-formatted to properly fit the page.
294
+ # Draws text on the page, beginning at the point specified by the `:at`
295
+ # option the string is assumed to be pre-formatted to properly fit the page.
225
296
  #
226
- # pdf.draw_text "Hello World", :at => [100,100]
227
- # pdf.draw_text "Goodbye World", :at => [50,50], :size => 16
297
+ # ```ruby
298
+ # pdf.draw_text "Hello World", at: [100, 100]
299
+ # pdf.draw_text "Goodbye World", at: [50,50], size: 16
300
+ # ```
228
301
  #
229
302
  # If your font contains kerning pair data that Prawn can parse, the
230
303
  # text will be kerned by default. You can disable kerning by including
231
- # a false <tt>:kerning</tt> option. If you want to disable kerning on an
232
- # entire document, set default_kerning = false for that document
304
+ # a `false` `:kerning` option. If you want to disable kerning on an
305
+ # entire document, set `default_kerning = false` for that document
233
306
  #
234
- # === Text Positioning Details:
307
+ # #### Text Positioning Details
235
308
  #
236
309
  # Prawn will position your text by the left-most edge of its baseline, and
237
- # flow along a single line. (This means that :align will not work)
310
+ # flow along a single line. (This means that `:align` will not work)
238
311
  #
239
- # == Rotation
312
+ # #### Rotation
240
313
  #
241
314
  # Text can be rotated before it is placed on the canvas by specifying the
242
- # <tt>:rotate</tt> option with a given angle. Rotation occurs
243
- # counter-clockwise.
315
+ # `:rotate` option with a given angle. Rotation occurs counter-clockwise.
244
316
  #
245
- # == Encoding
317
+ # #### Encoding
246
318
  #
247
- # Note that strings passed to this function should be encoded as UTF-8.
248
- # If you get unexpected characters appearing in your rendered document,
249
- # check this.
319
+ # Note that strings passed to this function should be encoded as UTF-8. If
320
+ # you get unexpected characters appearing in your rendered document, check
321
+ # this.
250
322
  #
251
- # If the current font is a built-in one, although the string must be
252
- # encoded as UTF-8, only characters that are available in WinAnsi
253
- # are allowed.
323
+ # If the current font is a built-in one, although the string must be encoded
324
+ # as UTF-8, only characters that are available in WinAnsi are allowed.
254
325
  #
255
326
  # If an empty box is rendered to your PDF instead of the character you
256
327
  # wanted it usually means the current font doesn't include that character.
257
328
  #
258
- # == Options (default values marked in [])
259
- #
260
- # <tt>:at</tt>:: <tt>[x, y]</tt>(required). The position at which to start
261
- # the text
262
- # <tt>:kerning</tt>:: <tt>boolean</tt>. Whether or not to use kerning (if it
263
- # is available with the current font)
264
- # [value of default_kerning?]
265
- # <tt>:size</tt>:: <tt>number</tt>. The font size to use. [current font
266
- # size]
267
- # <tt>:style</tt>:: The style to use. The requested style must be part of
268
- # the current font familly. [current style]
269
- #
270
- # <tt>:rotate</tt>:: <tt>number</tt>. The angle to which to rotate text
271
- #
272
- # == Exceptions
273
- #
274
- # Raises <tt>ArgumentError</tt> if <tt>:at</tt> option omitted
275
- #
276
- # Raises <tt>ArgumentError</tt> if <tt>:align</tt> option included
277
- #
329
+ # @param text [String]
330
+ # @param options [Hash{Symbol => any}]
331
+ # @option options :at [Array(Number, Number)] **Required**.
332
+ # The position at which to start the text.
333
+ # @option options :kerning [Boolean] (value of default_kerning?)
334
+ # Whether or not to use kerning (if it is available with the current
335
+ # font).
336
+ # @option options :size [Number] (current font size)
337
+ # The font size to use.
338
+ # @option options :style [Symbol] (current style)
339
+ # The style to use. The requested style must be part of the current font
340
+ # family.
341
+ # @option options :rotate [Number] The angle to which to rotate text.
342
+ # @return [void]
343
+ # @raise [ArgumentError]
344
+ # If `:at` option is omitted or `:align</tt> option is included.
278
345
  def draw_text(text, options)
279
346
  options = inspect_options_for_draw_text(options.dup)
280
347
 
@@ -287,16 +354,33 @@ module Prawn
287
354
  end
288
355
  end
289
356
 
290
- # Low level text placement method. All font and size alterations
291
- # should already be set
292
- #
357
+ # Low level text placement method.
358
+ #
359
+ # All font and size alterations should already be set.
360
+ #
361
+ # @param text [String]
362
+ # @param options [Hash{Symbol => any}]
363
+ # @option options :at [Array(Number, Number)]
364
+ # The position at which to start the text.
365
+ # @option options :kerning [Boolean]
366
+ # Whether or not to use kerning (if it is available with the current
367
+ # font).
368
+ # @option options :size [Number]
369
+ # The font size to use.
370
+ # @option options :style [Symbol]
371
+ # The style to use. The requested style must be part of the current font
372
+ # family.
373
+ # @option options :rotate [Number] The angle to which to rotate text.
374
+ # @return [void]
293
375
  def draw_text!(text, options)
294
376
  unless font.unicode? || font.class.hide_m17n_warning || text.ascii_only?
295
- warn "PDF's built-in fonts have very limited support for " \
296
- "internationalized text.\nIf you need full UTF-8 support, " \
297
- "consider using an external font instead.\n\nTo disable this " \
298
- "warning, add the following line to your code:\n" \
299
- "Prawn::Fonts::AFM.hide_m17n_warning = true\n"
377
+ warn(
378
+ "PDF's built-in fonts have very limited support for " \
379
+ "internationalized text.\nIf you need full UTF-8 support, " \
380
+ "consider using an external font instead.\n\nTo disable this " \
381
+ "warning, add the following line to your code:\n" \
382
+ "Prawn::Fonts::AFM.hide_m17n_warning = true\n",
383
+ )
300
384
 
301
385
  font.class.hide_m17n_warning = true
302
386
  end
@@ -306,44 +390,197 @@ module Prawn
306
390
  end
307
391
 
308
392
  # Gets height of text in PDF points.
309
- # Same options as #text, except as noted.
310
- # Not compatible with :indent_paragraphs option
311
- #
312
- # ==Example
313
- #
314
- # height_of("hello\nworld")
315
- #
316
- # == Exceptions
317
- #
318
- # Raises <tt>NotImplementedError</tt> if <tt>:indent_paragraphs</tt>
319
- # option included
320
- #
321
- # Raises <tt>Prawn::Errrors::CannotFit</tt> if not wide enough to print
322
- # any text
323
393
  #
394
+ # @note This method takes the same options as {#text}, _except_
395
+ # `:indent_paragraphs`.
396
+ #
397
+ # @example
398
+ # text_height = height_of("hello\nworld")
399
+ #
400
+ # @param string [String]
401
+ # @param options [Hash{Symbol => any}]
402
+ # @option options :inline_format [Boolean]
403
+ # If `true`, then the string parameter is interpreted as a HTML-esque
404
+ # string that recognizes the following tags (assuming the default text
405
+ # formatter is used):
406
+ # - `<b></b>`{:.language-html} --- bold style.
407
+ # - `<i></i>`{:.language-html} --- italic style.
408
+ # - `<u></u>`{:.language-html} --- underline.
409
+ # - `<strikethrough></strikethrough>`{:.language-html} --- strikethrough.
410
+ # - `<sub></sub>`{:.language-html} --- subscript.
411
+ # - `<sup></sup>`{:.language-html} --- superscript.
412
+ # - `<font></font>`{:.language-html} --- with the following attributes
413
+ # (using double or single quotes):
414
+ # - `name="Helvetica"`{:.language-html} --- the font. The font name must
415
+ # be an AFM font with the desired faces or must be a font that is
416
+ # already registered using {Prawn::Document#font_families}.
417
+ # - `size="24"`{:.language-html} --- attribute for setting size.
418
+ # - `character_spacing="2.5"`{:.language-html} --- character spacing.
419
+ # - `<color></color>`{:.language-html} --- text color
420
+ # - `rgb="ffffff"`{:.language-html} or `rgb="#ffffff"`{:.language-html}
421
+ # --- RGB color
422
+ # - `c="100" m="100" y="100" k="100"`{:.language-html} --- CMYK color
423
+ # - `<link></link>`{:.language-html} - link, with the following
424
+ # attributes:
425
+ # - `href="http://example.com"`{:.language-html} --- an external link.
426
+ # Note that you must explicitly underline and color using the
427
+ # appropriate tags if you which to draw attention to the link.
428
+ # @option options :kerning [Boolean] (value of document.default_kerning?)
429
+ # Whether or not to use kerning (if it is available with the current
430
+ # font).
431
+ # @option options :size [Number] (current ofnt size) The font size to use.
432
+ # @option options :color [Color]
433
+ # @option options :character_spacing [Number] (0)
434
+ # The amount of space to add to or remove from the default character
435
+ # spacing.
436
+ # @option options :style [Symbol] (current style)
437
+ # The style to use. The requested style must be part of the current font
438
+ # family.
439
+ # @option options :direction [:ltr, :rtl] (value of document.text_direction)
440
+ # Direction of the text.
441
+ # @option options :fallback_fonts [Array<String>]
442
+ # An array of font names. Each name must be the name of an AFM font or the
443
+ # name that was used to register a family of TTF fonts (see
444
+ # {Prawn::Document#font_families}). If present, then each glyph will be
445
+ # rendered using the first font that includes the glyph, starting with the
446
+ # current font and then moving through `:fallback_fonts`.
447
+ # @option option :align [:left, :center, :right, :justify]
448
+ # (:left if direction is :ltr, :right if direction is :rtl)
449
+ # Alignment within the bounding box.
450
+ # @option options :valign [:top, :center, :bottom] (:top)
451
+ # Vertical alignment within the bounding box.
452
+ # @option options :leading (Number) (value of document.default_leading)
453
+ # Additional space between lines.
454
+ # @option options :final_gap [Boolean] (true)
455
+ # If `true`, then the space between each line is included below the last
456
+ # line; otherwise, {Document.y} is placed just below the descender of the
457
+ # last line printed.
458
+ # @option options :mode [Symbol] (:fill)
459
+ # The text rendering mode to use. Use this to specify if the text should
460
+ # render with the fill color, stroke color or both.
461
+ # * `:fill` - fill text (default)
462
+ # * `:stroke` - stroke text
463
+ # * `:fill_stroke` - fill, then stroke text
464
+ # * `:invisible` - invisible text
465
+ # * `:fill_clip` - fill text then add to path for clipping
466
+ # * `:stroke_clip` - stroke text then add to path for clipping
467
+ # * `:fill_stroke_clip` - fill then stroke text, then add to path for
468
+ # clipping
469
+ # * `:clip` - add text to path for clipping
470
+ #
471
+ # @return [void]
472
+ #
473
+ # @raise [ArgumentError] if `:at` option included
474
+ # @raise [Prawn::Errrors::CannotFit] if not wide enough to print any text
475
+ # @raise [NotImplementedError] if `:indent_paragraphs` option included.
476
+ #
477
+ # @see PDF::Core::Text#text_rendering_mode()
478
+ # for a list of valid text rendering modes.
479
+ # @see height_of_formatted
324
480
  def height_of(string, options = {})
325
481
  height_of_formatted([{ text: string }], options)
326
482
  end
327
483
 
328
484
  # Gets height of formatted text in PDF points.
329
- # See documentation for #height_of.
330
485
  #
331
- # ==Example
486
+ # @note This method takes the same options as {#text}, _except_
487
+ # `:indent_paragraphs`.
332
488
  #
489
+ # @example
333
490
  # height_of_formatted([{ :text => "hello" },
334
491
  # { :text => "world",
335
492
  # :size => 24,
336
493
  # :styles => [:bold, :italic] }])
337
494
  #
495
+ # @param array [Array<Hash>] text fragments.
496
+ # @param options [Hash{Symbol => any}]
497
+ # @option options :inline_format [Boolean]
498
+ # If `true`, then the string parameter is interpreted as a HTML-esque
499
+ # string that recognizes the following tags (assuming the default text
500
+ # formatter is used):
501
+ # - `<b></b>`{:.language-html} --- bold style.
502
+ # - `<i></i>`{:.language-html} --- italic style.
503
+ # - `<u></u>`{:.language-html} --- underline.
504
+ # - `<strikethrough></strikethrough>`{:.language-html} --- strikethrough.
505
+ # - `<sub></sub>`{:.language-html} --- subscript.
506
+ # - `<sup></sup>`{:.language-html} --- superscript.
507
+ # - `<font></font>`{:.language-html} --- with the following attributes
508
+ # (using double or single quotes):
509
+ # - `name="Helvetica"`{:.language-html} --- the font. The font name must
510
+ # be an AFM font with the desired faces or must be a font that is
511
+ # already registered using {Prawn::Document#font_families}.
512
+ # - `size="24"`{:.language-html} --- attribute for setting size.
513
+ # - `character_spacing="2.5"`{:.language-html} --- character spacing.
514
+ # - `<color></color>`{:.language-html} --- text color
515
+ # - `rgb="ffffff"`{:.language-html} or `rgb="#ffffff"`{:.language-html}
516
+ # --- RGB color
517
+ # - `c="100" m="100" y="100" k="100"`{:.language-html} --- CMYK color
518
+ # - `<link></link>`{:.language-html} - link, with the following
519
+ # attributes:
520
+ # - `href="http://example.com"`{:.language-html} --- an external link.
521
+ # Note that you must explicitly underline and color using the
522
+ # appropriate tags if you which to draw attention to the link.
523
+ # @option options :kerning [Boolean] (value of document.default_kerning?)
524
+ # Whether or not to use kerning (if it is available with the current
525
+ # font).
526
+ # @option options :size [Number] (current ofnt size) The font size to use.
527
+ # @option options :color [Color]
528
+ # @option options :character_spacing [Number] (0)
529
+ # The amount of space to add to or remove from the default character
530
+ # spacing.
531
+ # @option options :style [Symbol] (current style)
532
+ # The style to use. The requested style must be part of the current font
533
+ # family.
534
+ # @option options :direction [:ltr, :rtl] (value of document.text_direction)
535
+ # Direction of the text.
536
+ # @option options :fallback_fonts [Array<String>]
537
+ # An array of font names. Each name must be the name of an AFM font or the
538
+ # name that was used to register a family of TTF fonts (see
539
+ # {Prawn::Document#font_families}). If present, then each glyph will be
540
+ # rendered using the first font that includes the glyph, starting with the
541
+ # current font and then moving through `:fallback_fonts`.
542
+ # @option option :align [:left, :center, :right, :justify]
543
+ # (:left if direction is :ltr, :right if direction is :rtl)
544
+ # Alignment within the bounding box.
545
+ # @option options :valign [:top, :center, :bottom] (:top)
546
+ # Vertical alignment within the bounding box.
547
+ # @option options :leading (Number) (value of document.default_leading)
548
+ # Additional space between lines.
549
+ # @option options :final_gap [Boolean] (true)
550
+ # If `true`, then the space between each line is included below the last
551
+ # line; otherwise, {Document.y} is placed just below the descender of the
552
+ # last line printed.
553
+ # @option options :mode [Symbol] (:fill)
554
+ # The text rendering mode to use. Use this to specify if the text should
555
+ # render with the fill color, stroke color or both.
556
+ # * `:fill` - fill text (default)
557
+ # * `:stroke` - stroke text
558
+ # * `:fill_stroke` - fill, then stroke text
559
+ # * `:invisible` - invisible text
560
+ # * `:fill_clip` - fill text then add to path for clipping
561
+ # * `:stroke_clip` - stroke text then add to path for clipping
562
+ # * `:fill_stroke_clip` - fill then stroke text, then add to path for
563
+ # clipping
564
+ # * `:clip` - add text to path for clipping
565
+ #
566
+ # @return [void]
567
+ #
568
+ # @raise [ArgumentError] if `:at` option included
569
+ # @raise [Prawn::Errrors::CannotFit] if not wide enough to print any text
570
+ # @raise [NotImplementedError] if `:indent_paragraphs` option included.
571
+ #
572
+ # @see PDF::Core::Text#text_rendering_mode()
573
+ # for a list of valid text rendering modes.
574
+ # @see height_of
338
575
  def height_of_formatted(array, options = {})
339
576
  if options[:indent_paragraphs]
340
- raise NotImplementedError, ':indent_paragraphs option not available' \
341
- 'with height_of'
577
+ raise NotImplementedError,
578
+ ':indent_paragraphs option not available with height_of'
342
579
  end
343
580
  process_final_gap_option(options)
344
581
  box = Text::Formatted::Box.new(
345
582
  array,
346
- options.merge(height: 100_000_000, document: self)
583
+ options.merge(height: 100_000_000, document: self),
347
584
  )
348
585
  box.render(dry_run: true)
349
586
 
@@ -364,11 +601,12 @@ module Prawn
364
601
  end
365
602
 
366
603
  def draw_indented_formatted_line(string, options)
367
- gap = if options.fetch(:direction, text_direction) == :ltr
368
- [@indent_paragraphs, 0]
369
- else
370
- [0, @indent_paragraphs]
371
- end
604
+ gap =
605
+ if options.fetch(:direction, text_direction) == :ltr
606
+ [@indent_paragraphs, 0]
607
+ else
608
+ [0, @indent_paragraphs]
609
+ end
372
610
 
373
611
  indent(*gap) do
374
612
  fill_formatted_text_box(string, options.dup.merge(single_line: true))
@@ -383,7 +621,13 @@ module Prawn
383
621
  @all_text_printed = box.everything_printed?
384
622
 
385
623
  self.y -= box.height
386
- self.y -= box.line_gap + box.leading if @final_gap
624
+
625
+ # If there's no remaining_text we don't really want to treat this line
626
+ # in a special way, we printed everything we wanted so the special
627
+ # single_line logic should not be triggered here.
628
+ if @final_gap || (options[:single_line] && !@all_text_printed)
629
+ self.y -= box.line_gap + box.leading
630
+ end
387
631
 
388
632
  remaining_text
389
633
  end
@@ -400,7 +644,7 @@ module Prawn
400
644
  options[:width] = bounds.width
401
645
  options[:at] = [
402
646
  @bounding_box.left_side - @bounding_box.absolute_left,
403
- y - @bounding_box.absolute_bottom
647
+ y - @bounding_box.absolute_bottom,
404
648
  ]
405
649
  end
406
650
 
@@ -421,8 +665,9 @@ module Prawn
421
665
 
422
666
  def inspect_options_for_text(options)
423
667
  if options[:at]
424
- raise ArgumentError, ':at is no longer a valid option with text.' \
425
- 'use draw_text or text_box instead'
668
+ raise ArgumentError,
669
+ ':at is no longer a valid option with text.' \
670
+ 'use draw_text or text_box instead'
426
671
  end
427
672
  process_final_gap_option(options)
428
673
  process_indent_paragraphs_option(options)