Class: Layout::FormattedText

Inherits:
Entity
  • Object
show all

Overview

A formatted text entity.

Version:

  • LayOut 2018

Constant Summary #

Layout::FormattedText::GROW_MODE_UNBOUNDED
Layout::FormattedText::GROW_MODE_BOUNDED
Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT
Layout::FormattedText::ANCHOR_TYPE_CENTER_LEFT
Layout::FormattedText::ANCHOR_TYPE_BOTTOM_LEFT
Layout::FormattedText::ANCHOR_TYPE_TOP_RIGHT
Layout::FormattedText::ANCHOR_TYPE_CENTER_RIGHT
Layout::FormattedText::ANCHOR_TYPE_BOTTOM_RIGHT
Layout::FormattedText::ANCHOR_TYPE_TOP_CENTER
Layout::FormattedText::ANCHOR_TYPE_CENTER_CENTER
Layout::FormattedText::ANCHOR_TYPE_BOTTOM_CENTER

Class Method Summary # collapse

Instance Method Summary # collapse

Methods inherited from Entity

#==, #bounds, #document, #drawing_bounds, #group, #layer_instance, #locked=, #locked?, #move_to_group, #move_to_layer, #on_shared_layer?, #page, #style=, #transform!, #transformation, #untransformed_bounds, #untransformed_bounds=

Constructor Details

#initialize(text, bounds) ⇒ Layout::FormattedText #initialize(text, anchor_point, anchor_type) ⇒ Layout::FormattedText

The #initialize method creates a new Layout::FormattedText.

The anchor type can be one of the following values:

ANCHOR_TYPE_TOP_LEFT
ANCHOR_TYPE_CENTER_LEFT
ANCHOR_TYPE_BOTTOM_LEFT
ANCHOR_TYPE_TOP_RIGHT
ANCHOR_TYPE_CENTER_RIGHT
ANCHOR_TYPE_BOTTOM_RIGHT
ANCHOR_TYPE_TOP_CENTER
ANCHOR_TYPE_CENTER_CENTER
ANCHOR_TYPE_BOTTOM_CENTER

Examples:

anchor = Geom::Point2d.new(1, 1)
text = Layout::FormattedText.new("Test", anchor, Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)

Overloads:

Raises:

  • (ArgumentError)

    if the passed in string is empty

  • (ArgumentError)

    if bounds is zero size

Version:

  • LayOut 2018

Class Method Details

.new_from_file(path, bounds) ⇒ Layout::FormattedText .new_from_file(path, anchor_point, anchor_type) ⇒ Layout::FormattedText

The new_from_file method creates a new Layout::FormattedText from a text file.

The anchor type can be one of the following values:

ANCHOR_TYPE_TOP_LEFT
ANCHOR_TYPE_CENTER_LEFT
ANCHOR_TYPE_BOTTOM_LEFT
ANCHOR_TYPE_TOP_RIGHT
ANCHOR_TYPE_CENTER_RIGHT
ANCHOR_TYPE_BOTTOM_RIGHT
ANCHOR_TYPE_TOP_CENTER
ANCHOR_TYPE_CENTER_CENTER
ANCHOR_TYPE_BOTTOM_CENTER

Examples:

anchor = Geom::Point2d.new(1, 1)
text = Layout::FormattedText.new("C:/Test.txt", anchor, Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)

Overloads:

Raises:

  • (ArgumentError)

    if the passed in string is empty

  • (ArgumentError)

    if bounds is zero size

  • (ArgumentError)

    if path does not refer to a valid file

Version:

  • LayOut 2018

Instance Method Details

#append_plain_text(plain_text, style) ⇒ Object

Note:

This method does not support more than two different style runs in a single text string.

The #append_plain_text method appends new text with a given style to the end of the existing plain text of the Layout::FormattedText.

Examples:

anchor = Geom::Point2d.new(1, 1)
text = Layout::FormattedText.new("Test", anchor, Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
style = text.style(0)
text.append_plain_text("foo", style)

Parameters:

Raises:

Version:

  • LayOut 2018

#apply_style(style, index = 0, length = length_to_end_of_text) ⇒ Object

The #apply_style method sets the Style for the text starting at the given character index, and running for the given number of characters.

Examples:

anchor = Geom::Point2d.new(1, 1)
text = Layout::FormattedText.new("Test", anchor, Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
style = text.style(0)
style.text_bold = true
text.apply_style(style, 2, 4)

Parameters:

  • style (Layout::Style)
  • index (Integer) (defaults to: 0)
  • length (Integer) (defaults to: length_to_end_of_text)

Raises:

Version:

  • LayOut 2018

#display_text(page = nil) ⇒ String

Note:

Passing an invalid Page will prevent an auto text tag from being substituted with its display representation.

The #display_text method returns the display text representation of the Layout::FormattedText.

Examples:

anchor = Geom::Point2d.new(1, 1)
text = Layout::FormattedText.new("<PageNumber>", anchor, Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
doc.add_entity(text, doc.layers.first, doc.pages.first)
text = text.display_text(doc.pages.first)

Parameters:

  • page (Layout::Page) (defaults to: nil)

    The Page to use to convert an auto text tag to display text

Returns:

Raises:

Version:

  • LayOut 2018

#grow_modeInteger

The #grow_mode method returns the mode for how the Layout::FormattedText sizes itself.

The grow mode can be one of the following values:

Layout::FormattedText::GROW_MODE_BOUNDED
Layout::FormattedText::GROW_MODE_UNBOUNDED

Examples:

anchor = Geom::Point2d.new(1, 1)
text = Layout::FormattedText.new("Test", anchor, Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
mode = text.grow_mode

Returns:

  • (Integer)

    grow_mode

Version:

  • LayOut 2018

#grow_mode=(grow_mode) ⇒ Integer

The #grow_mode= method sets the mode for how the Layout::FormattedText sizes itself.

The grow mode can be one of the following values:

Layout::FormattedText::GROW_MODE_BOUNDED
Layout::FormattedText::GROW_MODE_UNBOUNDED

Examples:

anchor = Geom::Point2d.new(1, 1)
text = Layout::FormattedText.new("Test", anchor, Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
text.grow_mode = GROW_MODE_UNBOUNDED

Returns:

  • (Integer)

    grow_mode

Raises:

Version:

  • LayOut 2018

#plain_textString

The #plain_text method returns the plain text representation of the Layout::FormattedText.

Examples:

anchor = Geom::Point2d.new(1, 1)
text = Layout::FormattedText.new("Test", anchor, Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
text = text.plain_text

Returns:

Version:

  • LayOut 2018

#plain_text=(plain_text) ⇒ Object

The #plain_text= method sets the plain text representation of the Layout::FormattedText.

Examples:

anchor = Geom::Point2d.new(1, 1)
text = Layout::FormattedText.new("Test", anchor, Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
text.plain_text = "foo"

Parameters:

Raises:

Version:

  • LayOut 2018

#rtfString #rtf(page) ⇒ String

Note:

Passing an invalid Page will prevent an auto text tag from being substituted with its display representation.

The #rtf method returns the raw RTF representation of the Layout::FormattedText.

Examples:

anchor = Geom::Point2d.new(1, 1)
text = Layout::FormattedText.new("Test", anchor, Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
rtf_text = text.rtf

Overloads:

Raises:

Version:

  • LayOut 2018

#rtf=(rtf_text) ⇒ Object

The #rtf= method sets the raw RTF representation of the Layout::FormattedText.

Examples:

anchor = Geom::Point2d.new(1, 1)
text = Layout::FormattedText.new("Test", anchor, Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
text.rtf = "{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard This is some {\b bold} text.\par}"

Parameters:

Raises:

Version:

  • LayOut 2018

#style(index = 0, length = 1) ⇒ Layout::Style

The #style method returns a Style for the text starting at the given character index, and running for the given length.

Examples:

anchor = Geom::Point2d.new(1, 1)
text = Layout::FormattedText.new("Test", anchor, Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
style = text.style(0)

Parameters:

  • index (Integer) (defaults to: 0)
  • length (Integer) (defaults to: 1)

Returns:

Raises:

  • (IndexError)

    if index is out of range

  • (ArgumentError)

    if length is not greater than zero

  • (RangeError)

    if the range specified by index and length is not valid for this Layout::FormattedText

Version:

  • LayOut 2018