Module: Prawn::Text

Includes:
PDF::Core::Text, Formatted
Included in:
Document
Defined in:
lib/prawn/text.rb,
lib/prawn/text/box.rb,
lib/prawn/text/formatted.rb,
lib/prawn/text/formatted/box.rb,
lib/prawn/text/formatted/wrap.rb,
lib/prawn/text/formatted/parser.rb,
lib/prawn/text/formatted/arranger.rb,
lib/prawn/text/formatted/fragment.rb,
lib/prawn/text/formatted/line_wrap.rb

Overview

rubocop: disable Style/Documentation

Defined Under Namespace

Modules: Formatted Classes: Box

Constant Summary collapse

NBSP =

No-Break Space

"\u00A0"
ZWSP =

Zero Width Space (indicate word boundaries without a space)

"\u200B"
SHY =

Soft Hyphen (invisible, except when causing a line break)

"\u00AD"

Stable API collapse

Instance Method Details

#draw_text(text, options) ⇒ void

This method returns an undefined value.

Draws text on the page, beginning at the point specified by the :at option the string is assumed to be pre-formatted to properly fit the page.

pdf.draw_text "Hello World", at: [100, 100]
pdf.draw_text "Goodbye World", at: [50,50], size: 16

If your font contains kerning pair data that Prawn can parse, the text will be kerned by default. You can disable kerning by including a false :kerning option. If you want to disable kerning on an entire document, set default_kerning = false for that document

Text Positioning Details

Prawn will position your text by the left-most edge of its baseline, and flow along a single line. (This means that :align will not work)

Rotation

Text can be rotated before it is placed on the canvas by specifying the :rotate option with a given angle. Rotation occurs counter-clockwise.

Encoding

Note that strings passed to this function should be encoded as UTF-8. If you get unexpected characters appearing in your rendered document, check this.

If the current font is a built-in one, although the string must be encoded as UTF-8, only characters that are available in WinAnsi are allowed.

If an empty box is rendered to your PDF instead of the character you wanted it usually means the current font doesn’t include that character.

Parameters:

  • text (String)
  • options (Hash{Symbol => any})

Options Hash (options):

  • :at (Array(Number, Number))

    Required. The position at which to start the text.

  • :kerning (Boolean) — default: value of default_kerning?

    Whether or not to use kerning (if it is available with the current font).

  • :size (Number) — default: current font size

    The font size to use.

  • :style (Symbol) — default: current style

    The style to use. The requested style must be part of the current font family.

  • :rotate (Number)

    The angle to which to rotate text.

Raises:

  • (ArgumentError)

    If :at option is omitted or `:align</tt> option is included.

Source Code
lib/prawn/text.rb, line 345
345
def draw_text(text, options)
346
  options = inspect_options_for_draw_text(options.dup)
347
348
  # dup because normalize_encoding changes the string
349
  text = text.to_s.dup
350
  save_font do
351
    process_text_options(options)
352
    text = font.normalize_encoding(text)
353
    font_size(options[:size]) { draw_text!(text, options) }
354
  end
355
end

#draw_text!(text, options) ⇒ void

This method returns an undefined value.

Low level text placement method.

All font and size alterations should already be set.

Parameters:

  • text (String)
  • options (Hash{Symbol => any})

Options Hash (options):

  • :at (Array(Number, Number))

    The position at which to start the text.

  • :kerning (Boolean)

    Whether or not to use kerning (if it is available with the current font).

  • :size (Number)

    The font size to use.

  • :style (Symbol)

    The style to use. The requested style must be part of the current font family.

  • :rotate (Number)

    The angle to which to rotate text.

Source Code
lib/prawn/text.rb, line 375
375
def draw_text!(text, options)
376
  unless font.unicode? || font.class.hide_m17n_warning || text.ascii_only?
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
    )
384
385
    font.class.hide_m17n_warning = true
386
  end
387
388
  x, y = map_to_absolute(options[:at])
389
  add_text_content(text, x, y, options)
390
end

#formatted_text(array, options = {}) ⇒ void

This method returns an undefined value.

Draws formatted text to the page.

Formatted text is an array of hashes, where each hash defines text and format information.

Examples:

text([{ :text => "hello" },
      { :text => "world",
        :size => 24,
        :styles => [:bold, :italic] }])

Parameters:

  • array (Array<Hash>)

    array of text fragments. See Prawn::Text::Formatted#formatted_text_box for more information on the structure of this array.

  • options (Hash{Symbol => any}) (defaults to: {})
  • option (Hash)

    a customizable set of options

Options Hash (options):

  • :inline_format (Boolean)

    If true, then the string parameter is interpreted as a HTML-esque string that recognizes the following tags (assuming the default text formatter is used):

    • <b></b> — bold style.
    • <i></i> — italic style.
    • <u></u> — underline.
    • <strikethrough></strikethrough> — strikethrough.
    • <sub></sub> — subscript.
    • <sup></sup> — superscript.
    • <font></font> — with the following attributes (using double or single quotes):
      • name="Helvetica" — the font. The font name must be an AFM font with the desired faces or must be a font that is already registered using Document#font_families.
      • size="24" — attribute for setting size.
      • character_spacing="2.5" — character spacing.
    • <color></color> — text color
      • rgb="ffffff" or rgb="#ffffff" — RGB color
      • c="100" m="100" y="100" k="100" — CMYK color
    • <link></link> - link, with the following attributes:
      • href="http://example.com" — an external link. Note that you must explicitly underline and color using the appropriate tags if you which to draw attention to the link.
  • :kerning (Boolean) — default: value of document.default_kerning?

    Whether or not to use kerning (if it is available with the current font).

  • :size (Number) — default: current ofnt size

    The font size to use.

  • :color (Color)
  • :character_spacing (Number) — default: 0

    The amount of space to add to or remove from the default character spacing.

  • :style (Symbol) — default: current style

    The style to use. The requested style must be part of the current font family.

  • :indent_paragraphs (Number)

    The amount to indent the first line of each paragraph. Omit this option if you do not want indenting.

  • :direction (:ltr, :rtl) — default: value of document.text_direction

    Direction of the text.

  • :fallback_fonts (Array<String>)

    An array of font names. Each name must be the name of an AFM font or the name that was used to register a family of TTF fonts (see Document#font_families). If present, then each glyph will be rendered using the first font that includes the glyph, starting with the current font and then moving through :fallback_fonts.

  • :valign (:top, :center, :bottom) — default: :top

    Vertical alignment within the bounding box.

  • :leading (Object) — default: Number

    (value of document.default_leading) Additional space between lines.

  • :final_gap (Boolean) — default: true

    If true, then the space between each line is included below the last line; otherwise, Document#y is placed just below the descender of the last line printed.

  • :mode (Symbol) — default: :fill

    The text rendering mode to use. Use this to specify if the text should render with the fill color, stroke color or both.

    • :fill - fill text (default)
    • :stroke - stroke text
    • :fill_stroke - fill, then stroke text
    • :invisible - invisible text
    • :fill_clip - fill text then add to path for clipping
    • :stroke_clip - stroke text then add to path for clipping
    • :fill_stroke_clip - fill then stroke text, then add to path for clipping
    • :clip - add text to path for clipping

Raises:

  • (ArgumentError)

    if :at option included

  • (Prawn::Errrors::CannotFit)

    if not wide enough to print any text

See Also:

  • for a list of valid text rendering modes.
Source Code
lib/prawn/text.rb, line 263
263
def formatted_text(array, options = {})
264
  options = inspect_options_for_text(options.dup)
265
266
  color = options.delete(:color)
267
  if color
268
    array =
269
      array.map { |fragment|
270
        fragment[:color] ? fragment : fragment.merge(color: color)
271
      }
272
  end
273
274
  if @indent_paragraphs
275
    text_formatter.array_paragraphs(array).each do |paragraph|
276
      remaining_text = draw_indented_formatted_line(paragraph, options)
277
278
      if @no_text_printed && !@all_text_printed
279
        @bounding_box.move_past_bottom
280
        remaining_text = draw_indented_formatted_line(paragraph, options)
281
      end
282
283
      unless @all_text_printed
284
        remaining_text = fill_formatted_text_box(remaining_text, options)
285
        draw_remaining_formatted_text_on_new_pages(remaining_text, options)
286
      end
287
    end
288
  else
289
    remaining_text = fill_formatted_text_box(array, options)
290
    draw_remaining_formatted_text_on_new_pages(remaining_text, options)
291
  end
292
end

#formatted_text_box(array, options = {}) ⇒ Array<Hash> Originally defined in module Formatted

Draws the requested formatted text into a box.

When the text overflows the rectangle shrink to fit or truncate the text. Text boxes are independent of the document y position.

Examples:

formatted_text_box([{ :text => "hello" },
                    { :text => "world",
                      :size => 24,
                      :styles => [:bold, :italic] }])

Parameters:

  • array (Array<Hash{Symbol => any}>)

    Formatted text is an array of hashes, where each hash defines text and format information. The following hash options are supported:

    • :text — the text to format according to the other hash options.
    • :styles — an array of styles to apply to this text. Available styles include :bold, :italic, :underline, :strikethrough, :subscript, and :superscript.
    • :size —a number denoting the font size to apply to this text.
    • :character_spacing — a number denoting how much to increase or decrease the default spacing between characters.
    • :font — the name of a font. The name must be an AFM font with the desired faces or must be a font that is already registered using Document#font_families.
    • :color — anything compatible with Graphics::Color#fill_color and Graphics::Color#stroke_color.
    • :link` — a URL to which to create a link. A clickable link will be created to that URL. Note that you must explicitly underline and color using the appropriate tags if you which to draw attention to the link.
    • :anchor — a destination that has already been or will be registered using PDF::Core::Destinations#add_dest. A clickable link will be created to that destination. Note that you must explicitly underline and color using the appropriate tags if you which to draw attention to the link.
    • :local — a file or application to be opened locally. A clickable link will be created to the provided local file or application. If the file is another PDF, it will be opened in a new window. Note that you must explicitly underline and color using the appropriate options if you which to draw attention to the link.
    • :draw_text_callback — if provided, this Proc will be called instead of Prawn::Text#draw_text! once per fragment for every low-level addition of text to the page.
    • :callback — an object (or array of such objects) with two methods: #render_behind and #render_in_front, which are called immediately prior to and immediately after rendering the text fragment and which are passed the fragment as an argument.
  • options (Hash{Symbol => any}) (defaults to: {})

    Accepts the same options as Box.

Returns:

  • (Array<Hash>)

    A formatted text array representing any text that did not print under the current settings.

Raises:

  • (Prawn::Text::Formatted::Arranger::BadFontFamily)

    If no font family is defined for the current font.

  • (Prawn::Errors::CannotFit)

    If not wide enough to print any text.

#height_of(string, options = {}) ⇒ void

Note:

This method takes the same options as #text, except :indent_paragraphs.

This method returns an undefined value.

Gets height of text in PDF points.

Examples:

text_height = height_of("hello\nworld")

Parameters:

  • string (String)
  • options (Hash{Symbol => any}) (defaults to: {})
  • option (Hash)

    a customizable set of options

Options Hash (options):

  • :inline_format (Boolean)

    If true, then the string parameter is interpreted as a HTML-esque string that recognizes the following tags (assuming the default text formatter is used):

    • <b></b> — bold style.
    • <i></i> — italic style.
    • <u></u> — underline.
    • <strikethrough></strikethrough> — strikethrough.
    • <sub></sub> — subscript.
    • <sup></sup> — superscript.
    • <font></font> — with the following attributes (using double or single quotes):
      • name="Helvetica" — the font. The font name must be an AFM font with the desired faces or must be a font that is already registered using Document#font_families.
      • size="24" — attribute for setting size.
      • character_spacing="2.5" — character spacing.
    • <color></color> — text color
      • rgb="ffffff" or rgb="#ffffff" — RGB color
      • c="100" m="100" y="100" k="100" — CMYK color
    • <link></link> - link, with the following attributes:
      • href="http://example.com" — an external link. Note that you must explicitly underline and color using the appropriate tags if you which to draw attention to the link.
  • :kerning (Boolean) — default: value of document.default_kerning?

    Whether or not to use kerning (if it is available with the current font).

  • :size (Number) — default: current ofnt size

    The font size to use.

  • :color (Color)
  • :character_spacing (Number) — default: 0

    The amount of space to add to or remove from the default character spacing.

  • :style (Symbol) — default: current style

    The style to use. The requested style must be part of the current font family.

  • :direction (:ltr, :rtl) — default: value of document.text_direction

    Direction of the text.

  • :fallback_fonts (Array<String>)

    An array of font names. Each name must be the name of an AFM font or the name that was used to register a family of TTF fonts (see Document#font_families). If present, then each glyph will be rendered using the first font that includes the glyph, starting with the current font and then moving through :fallback_fonts.

  • :valign (:top, :center, :bottom) — default: :top

    Vertical alignment within the bounding box.

  • :leading (Object) — default: Number

    (value of document.default_leading) Additional space between lines.

  • :final_gap (Boolean) — default: true

    If true, then the space between each line is included below the last line; otherwise, Document#y is placed just below the descender of the last line printed.

  • :mode (Symbol) — default: :fill

    The text rendering mode to use. Use this to specify if the text should render with the fill color, stroke color or both.

    • :fill - fill text (default)
    • :stroke - stroke text
    • :fill_stroke - fill, then stroke text
    • :invisible - invisible text
    • :fill_clip - fill text then add to path for clipping
    • :stroke_clip - stroke text then add to path for clipping
    • :fill_stroke_clip - fill then stroke text, then add to path for clipping
    • :clip - add text to path for clipping

Raises:

  • (ArgumentError)

    if :at option included

  • (Prawn::Errrors::CannotFit)

    if not wide enough to print any text

  • (NotImplementedError)

    if :indent_paragraphs option included.

See Also:

Source Code
lib/prawn/text.rb, line 480
480
def height_of(string, options = {})
481
  height_of_formatted([{ text: string }], options)
482
end

#height_of_formatted(array, options = {}) ⇒ void

Note:

This method takes the same options as #text, except :indent_paragraphs.

This method returns an undefined value.

Gets height of formatted text in PDF points.

Examples:

height_of_formatted([{ :text => "hello" },
                     { :text => "world",
                       :size => 24,
                       :styles => [:bold, :italic] }])

Parameters:

  • array (Array<Hash>)

    text fragments.

  • options (Hash{Symbol => any}) (defaults to: {})
  • option (Hash)

    a customizable set of options

Options Hash (options):

  • :inline_format (Boolean)

    If true, then the string parameter is interpreted as a HTML-esque string that recognizes the following tags (assuming the default text formatter is used):

    • <b></b> — bold style.
    • <i></i> — italic style.
    • <u></u> — underline.
    • <strikethrough></strikethrough> — strikethrough.
    • <sub></sub> — subscript.
    • <sup></sup> — superscript.
    • <font></font> — with the following attributes (using double or single quotes):
      • name="Helvetica" — the font. The font name must be an AFM font with the desired faces or must be a font that is already registered using Document#font_families.
      • size="24" — attribute for setting size.
      • character_spacing="2.5" — character spacing.
    • <color></color> — text color
      • rgb="ffffff" or rgb="#ffffff" — RGB color
      • c="100" m="100" y="100" k="100" — CMYK color
    • <link></link> - link, with the following attributes:
      • href="http://example.com" — an external link. Note that you must explicitly underline and color using the appropriate tags if you which to draw attention to the link.
  • :kerning (Boolean) — default: value of document.default_kerning?

    Whether or not to use kerning (if it is available with the current font).

  • :size (Number) — default: current ofnt size

    The font size to use.

  • :color (Color)
  • :character_spacing (Number) — default: 0

    The amount of space to add to or remove from the default character spacing.

  • :style (Symbol) — default: current style

    The style to use. The requested style must be part of the current font family.

  • :direction (:ltr, :rtl) — default: value of document.text_direction

    Direction of the text.

  • :fallback_fonts (Array<String>)

    An array of font names. Each name must be the name of an AFM font or the name that was used to register a family of TTF fonts (see Document#font_families). If present, then each glyph will be rendered using the first font that includes the glyph, starting with the current font and then moving through :fallback_fonts.

  • :valign (:top, :center, :bottom) — default: :top

    Vertical alignment within the bounding box.

  • :leading (Object) — default: Number

    (value of document.default_leading) Additional space between lines.

  • :final_gap (Boolean) — default: true

    If true, then the space between each line is included below the last line; otherwise, Document#y is placed just below the descender of the last line printed.

  • :mode (Symbol) — default: :fill

    The text rendering mode to use. Use this to specify if the text should render with the fill color, stroke color or both.

    • :fill - fill text (default)
    • :stroke - stroke text
    • :fill_stroke - fill, then stroke text
    • :invisible - invisible text
    • :fill_clip - fill text then add to path for clipping
    • :stroke_clip - stroke text then add to path for clipping
    • :fill_stroke_clip - fill then stroke text, then add to path for clipping
    • :clip - add text to path for clipping

Raises:

  • (ArgumentError)

    if :at option included

  • (Prawn::Errrors::CannotFit)

    if not wide enough to print any text

  • (NotImplementedError)

    if :indent_paragraphs option included.

See Also:

  • for a list of valid text rendering modes.
  • #height_of
Source Code
lib/prawn/text.rb, line 575
575
def height_of_formatted(array, options = {})
576
  if options[:indent_paragraphs]
577
    raise NotImplementedError,
578
      ':indent_paragraphs option not available with height_of'
579
  end
580
  process_final_gap_option(options)
581
  box = Text::Formatted::Box.new(
582
    array,
583
    options.merge(height: 100_000_000, document: self),
584
  )
585
  box.render(dry_run: true)
586
587
  height = box.height
588
  height += box.line_gap + box.leading if @final_gap
589
  height
590
end

#text(string, options = {}) ⇒ void

This method returns an undefined value.

Draws text on the page.

If you want text to flow onto a new page or between columns, this is the method to use. If, instead, you want to place bounded text outside of the flow of a document (for captions, labels, charts, etc.), use Box or its convenience method #text_box.

Prawn attempts to wrap the text to fit within your current bounding box (or margin_box if no bounding box is being used). Text will flow onto the next page when it reaches the bottom of the bounding box. Text wrap in Prawn does not re-flow line breaks, so if you want fully automated text wrapping, be sure to remove newlines before attempting to draw your string.

Examples

pdf.text "Will be wrapped when it hits the edge of your bounding box"
pdf.text "This will be centered", align: :center
pdf.text "This will be right aligned", align: :right
pdf.text "This <i>includes <b>inline</b></i> <font size='24'>formatting</font>", inline_format: true

If your font contains kerning pair data that Prawn can parse, the text will be kerned by default. You can disable kerning by including a false :kerning option. If you want to disable kerning on an entire document, set default_kerning = false for that document.

Text Positioning Details

The text is positioned at font.ascender below the baseline, making it easy to use this method within bounding boxes and spans.

Encoding

Note that strings passed to this function should be encoded as UTF-8. If you get unexpected characters appearing in your rendered document, check this.

If the current font is a built-in one, although the string must be encoded as UTF-8, only characters that are available in WinAnsi are allowed.

If an empty box is rendered to your PDF instead of the character you wanted it usually means the current font doesn’t include that character.

Parameters:

  • string (String)
  • options (Hash{Symbol => any}) (defaults to: {})
  • option (Hash)

    a customizable set of options

Options Hash (options):

  • :inline_format (Boolean)

    If true, then the string parameter is interpreted as a HTML-esque string that recognizes the following tags (assuming the default text formatter is used):

    • <b></b> — bold style.
    • <i></i> — italic style.
    • <u></u> — underline.
    • <strikethrough></strikethrough> — strikethrough.
    • <sub></sub> — subscript.
    • <sup></sup> — superscript.
    • <font></font> — with the following attributes (using double or single quotes):
      • name="Helvetica" — the font. The font name must be an AFM font with the desired faces or must be a font that is already registered using Document#font_families.
      • size="24" — attribute for setting size.
      • character_spacing="2.5" — character spacing.
    • <color></color> — text color
      • rgb="ffffff" or rgb="#ffffff" — RGB color
      • c="100" m="100" y="100" k="100" — CMYK color
    • <link></link> - link, with the following attributes:
      • href="http://example.com" — an external link. Note that you must explicitly underline and color using the appropriate tags if you which to draw attention to the link.
  • :kerning (Boolean) — default: value of document.default_kerning?

    Whether or not to use kerning (if it is available with the current font).

  • :size (Number) — default: current ofnt size

    The font size to use.

  • :color (Color)
  • :character_spacing (Number) — default: 0

    The amount of space to add to or remove from the default character spacing.

  • :style (Symbol) — default: current style

    The style to use. The requested style must be part of the current font family.

  • :indent_paragraphs (Number)

    The amount to indent the first line of each paragraph. Omit this option if you do not want indenting.

  • :direction (:ltr, :rtl) — default: value of document.text_direction

    Direction of the text.

  • :fallback_fonts (Array<String>)

    An array of font names. Each name must be the name of an AFM font or the name that was used to register a family of TTF fonts (see Document#font_families). If present, then each glyph will be rendered using the first font that includes the glyph, starting with the current font and then moving through :fallback_fonts.

  • :valign (:top, :center, :bottom) — default: :top

    Vertical alignment within the bounding box.

  • :leading (Object) — default: Number

    (value of document.default_leading) Additional space between lines.

  • :final_gap (Boolean) — default: true

    If true, then the space between each line is included below the last line; otherwise, Document#y is placed just below the descender of the last line printed.

  • :mode (Symbol) — default: :fill

    The text rendering mode to use. Use this to specify if the text should render with the fill color, stroke color or both.

    • :fill - fill text (default)
    • :stroke - stroke text
    • :fill_stroke - fill, then stroke text
    • :invisible - invisible text
    • :fill_clip - fill text then add to path for clipping
    • :stroke_clip - stroke text then add to path for clipping
    • :fill_stroke_clip - fill then stroke text, then add to path for clipping
    • :clip - add text to path for clipping

Raises:

  • (ArgumentError)

    if :at option included

  • (Prawn::Errrors::CannotFit)

    if not wide enough to print any text

See Also:

  • for a list of valid text rendering modes.
Source Code
lib/prawn/text.rb, line 151
151
def text(string, options = {})
152
  return false if string.nil?
153
154
  # we modify the options. don't change the user's hash
155
  options = options.dup
156
157
  p = options[:inline_format]
158
  if p
159
    p = [] unless p.is_a?(Array)
160
    options.delete(:inline_format)
161
    array = text_formatter.format(string, *p)
162
  else
163
    array = [{ text: string }]
164
  end
165
166
  formatted_text(array, options)
167
end

#text_box(string, options = {}) ⇒ String

Draws the requested text into a box.

When the text overflows the rectangle, you shrink to fit, or truncate the text. Text boxes are independent of the document y position.

Encoding

Note that strings passed to this function should be encoded as UTF-8. If you get unexpected characters appearing in your rendered document, check this.

If the current font is a built-in one, although the string must be encoded as UTF-8, only characters that are available in WinAnsi are allowed.

If an empty box is rendered to your PDF instead of the character you wanted it usually means the current font doesn’t include that character.

Parameters:

  • string (String)
  • options (Hash{Symbol => any}) (defaults to: {})
  • option (Hash)

    a customizable set of options

Options Hash (options):

  • :kerning (Boolean) — default: value of document.default_kerning?

    Whether or not to use kerning (if it is available with the current font).

  • :size (Number) — default: current font size

    The font size to use.

  • :character_spacing (Number) — default: 0

    The amount of space to add to or remove from the default character spacing.

  • :disable_wrap_by_char (Boolean) — default: false

    Whether or not to prevent mid-word breaks when text does not fit in box.

  • :mode (Symbol) — default: :fill

    The text rendering mode. See documentation for Document#text_rendering_mode for a list of valid options.

  • :width (Number) — default: bounds.right - at[0]

    The width of the box.

  • :height (Number) — default: default_height()

    The height of the box.

  • :direction (:ltr, :rtl) — default: value of document.text_direction

    Direction of the text (left-to-right or right-to-left).

  • :fallback_fonts (Array<String>)

    An array of font names. Each name must be the name of an AFM font or the name that was used to register a family of external fonts (see Document#font_families). If present, then each glyph will be rendered using the first font that includes the glyph, starting with the current font and then moving through :fallback_fonts.

  • :align (:left, :center, :right, :justify) — default: :left if direction is :ltr, :right if direction is :rtl

    Alignment within the bounding box.

  • :valign (:top, :center, :bottom) — default: :top

    Vertical alignment within the bounding box.

  • :rotate (Number)

    The angle to rotate the text.

  • :rotate_around (Object)

    [:center, :upper_left, :upper_right, :lower_right, :lower_left] (:upper_left) The point around which to rotate the text.

  • :leading (Number) — default: value of document.default_leading

    Additional space between lines.

  • :single_line (Boolean) — default: false

    If true, then only the first line will be drawn.

  • :overflow (:truncate, :shrink_to_fit, :expand) — default: :truncate

    This controls the behavior when the amount of text exceeds the available space.

  • :min_font_size (Number) — default: 5

    The minimum font size to use when :overflow is set to :shrink_to_fit (that is the font size will not be reduced to less than this value, even if it means that some text will be cut off).

Returns:

  • (String)

    Any text that did not print under the current settings.

Raises:

Source Code
lib/prawn/text/box.rb, line 83
83
def text_box(string, options = {})
84
  options = options.dup
85
  options[:document] = self
86
87
  box =
88
    if options[:inline_format]
89
      p = options.delete(:inline_format)
90
      p = [] unless p.is_a?(Array)
91
      array = text_formatter.format(string, *p)
92
      Text::Formatted::Box.new(array, options)
93
    else
94
      Text::Box.new(string, options)
95
    end
96
97
  box.render
98
end