Class: Layout::Label

Inherits:
Entity show all

Overview

This is an interface to a label entity. A Label consists of a FormattedText and the label leader Path. A Label may be connected to another Entity via a ConnectionPoint.

Version:

  • LayOut 2018

Constant Summary #

Layout::Label::CONNECTION_TYPE_NONE
Layout::Label::CONNECTION_TYPE_AUTO
Layout::Label::CONNECTION_TYPE_REVERSE_AUTO
Layout::Label::CONNECTION_TYPE_TOP_LEFT
Layout::Label::CONNECTION_TYPE_CENTER_LEFT
Layout::Label::CONNECTION_TYPE_BOTTOM_LEFT
Layout::Label::CONNECTION_TYPE_TOP_RIGHT
Layout::Label::CONNECTION_TYPE_CENTER_RIGHT
Layout::Label::CONNECTION_TYPE_BOTTOM_RIGHT
Layout::Label::LEADER_LINE_TYPE_SINGLE_SEGMENT
Layout::Label::LEADER_LINE_TYPE_TWO_SEGMENT
Layout::Label::LEADER_LINE_TYPE_BEZIER
Layout::Label::LEADER_LINE_TYPE_UNKNOWN

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, #style=, #transform!, #transformation, #untransformed_bounds, #untransformed_bounds=

Constructor Details

#initialize(text, leader_type, target_point, bounds) ⇒ Layout::Label #initialize(text, leader_type, target_point, anchor_point, anchor_type) ⇒ Layout::Label

The #initialize method creates a new disconnected Layout::Label.

Examples:

text = "A label"
leader_type = Layout::Label::LEADER_LINE_TYPE_BEZIER
target_point = Geom::Point2d.new(1, 1)
bounds = Geom::Bounds2d.new(2, 1, 1, 1)
label_from_bounds = Layout::Label.new(text, leader_type, target_point,
  bounds)
anchor_point = Geom::Point2d.new(2, 2)
anchor_type = Layout::FormattedText::ANCHOR_TYPE_TOP_RIGHT
label_from_point = Layout::Label.new(text, leader_type, target_point,
  anchor_point, anchor_type)

Overloads:

  • #initialize(text, leader_type, target_point, bounds) ⇒ Layout::Label

    Parameters:

    • text (String)

      The label text

    • leader_type (Integer)

      The leader line type

    • target_point (Geom::Point2d)

      Where the label leader should point to

    • bounds (Geom::Bounds2d)
  • #initialize(text, leader_type, target_point, anchor_point, anchor_type) ⇒ Layout::Label

    Parameters:

    • text (String)

      The label text

    • leader_type (Integer)

      The leader line type

    • target_point (Geom::Point2d)

      Where the label leader should point to

    • anchor_point (Geom::Point2d)

      The anchor point for the label text's position.

    • anchor_type (Integer)

      Defines which point of the label text is set by anchor_point.

Raises:

  • (ArgumentError)

    if anchor_type is not a valid anchor type

  • (ArgumentError)

    if leader_type is not a valid leader line type

  • (ArgumentError)

    if bounds is zero size

  • (ArgumentError)

    if plain_text is an empty string

Version:

  • LayOut 2018

Instance Method Details

#connect(connection_point) ⇒ Object

The #connect method connects the Layout::Label to the given ConnectionPoint. The leader line will be adjusted to point at the ConnectionPoint. The Layout::Label must be in the same Document as the ConnectionPoint. If both the Layout::Label and the ConnectionPoint's Entity are on non-shared Layout::Layers, they must be on the same Page.

Examples:

text = "A label"
leader_type = Layout::Label::LEADER_LINE_TYPE_BEZIER
target_point = Geom::Point2d.new(1, 1)
bounds = Geom::Bounds2d.new(2, 1, 1, 1)
label = Layout::Label.new(text, leader_type, target_point, bounds)
rect = Layout::Rectangle.new([4, 4, 4, 4])

doc = Layout::Document.new
doc.add_entity(label, doc.layers.first, doc.pages.first)
doc.add_entity(rect, doc.layers.first, doc.pages.first)

point = Geom::Point2d.new(4, 4)
# Create a Connection Point to a LayOut Entity in the Document
cp = Layout::ConnectionPoint.new(rect, point)
label.connect(cp)

Parameters:

Raises:

Version:

  • LayOut 2018

#connection_typeInteger

The #connection_type method returns the type of the text connection for the Layout::Label.

The leader line type can be one of the following values:

Layout::Label::CONNECTION_TYPE_NONE
Layout::Label::CONNECTION_TYPE_AUTO
Layout::Label::CONNECTION_TYPE_REVERSE_AUTO
Layout::Label::CONNECTION_TYPE_TOP_LEFT
Layout::Label::CONNECTION_TYPE_CENTER_LEFT
Layout::Label::CONNECTION_TYPE_BOTTOM_LEFT
Layout::Label::CONNECTION_TYPE_TOP_RIGHT
Layout::Label::CONNECTION_TYPE_CENTER_RIGHT
Layout::Label::CONNECTION_TYPE_BOTTOM_RIGHT

Examples:

text = "A label"
leader_type = Layout::Label::LEADER_LINE_TYPE_BEZIER
target_point = Geom::Point2d.new(1, 1)
bounds = Geom::Bounds2d.new(2, 1, 1, 1)
label_from_bounds = Layout::Label.new(text, leader_type, target_point,
  bounds)
text_connection_type = label_from_bounds.connection_type

Returns:

  • (Integer)

Version:

  • LayOut 2018

#connection_type=(connection_type) ⇒ Object

The #connection_type= method sets the type of the text connection for the Layout::Label.

The leader line type can be one of the following values:

Layout::Label::CONNECTION_TYPE_NONE
Layout::Label::CONNECTION_TYPE_AUTO
Layout::Label::CONNECTION_TYPE_REVERSE_AUTO
Layout::Label::CONNECTION_TYPE_TOP_LEFT
Layout::Label::CONNECTION_TYPE_CENTER_LEFT
Layout::Label::CONNECTION_TYPE_BOTTOM_LEFT
Layout::Label::CONNECTION_TYPE_TOP_RIGHT
Layout::Label::CONNECTION_TYPE_CENTER_RIGHT
Layout::Label::CONNECTION_TYPE_BOTTOM_RIGHT

Examples:

text = "A label"
leader_type = Layout::Label::LEADER_LINE_TYPE_BEZIER
target_point = Geom::Point2d.new(1, 1)
bounds = Geom::Bounds2d.new(2, 1, 1, 1)
label_from_bounds = Layout::Label.new(text, leader_type, target_point,
  bounds)
label_from_bounds.connection_type = Layout::Label::CONNECTION_TYPE_TOP_LEFT

Parameters:

  • connection_type (Integer)

Raises:

Version:

  • LayOut 2018

#disconnectObject

The #disconnect method disconnects the Layout::Label from its ConnectionPoint. The leader line will not be adjusted by disconnecting from a ConnectionPoint.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
label = doc.pages.first.entities.first
label.disconnect

Raises:

Version:

  • LayOut 2018

#entitiesLayout::Entities #entities(page) ⇒ Layout::Entities

The #entities method returns the Entities that represent the Layout::Label in its exploded form.

Examples:

text = "A label"
leader_type = Layout::Label::LEADER_LINE_TYPE_BEZIER
target_point = Geom::Point2d.new(1, 1)
bounds = Geom::Bounds2d.new(2, 1, 1, 1)
label_from_bounds = Layout::Label.new(text, leader_type, target_point,
  bounds)
entities = label_from_bounds.entities

Overloads:

Raises:

  • (ArgumentError)

    if page does not belong to the same document as the

    Layout::Label

Version:

  • LayOut 2018

#leader_lineLayout::Path

The #leader_line method returns a copy of the leader line.

Examples:

text = "A label"
leader_type = Layout::Label::LEADER_LINE_TYPE_BEZIER
target_point = Geom::Point2d.new(1, 1)
bounds = Geom::Bounds2d.new(2, 1, 1, 1)
label_from_bounds = Layout::Label.new(text, leader_type, target_point,
  bounds)
leader = label_from_bounds.leader_line

Returns:

Version:

  • LayOut 2018

#leader_line=(leader_path) ⇒ Object

The #leader_line= method sets the leader line.

Examples:

text = "A label"
leader_type = Layout::Label::LEADER_LINE_TYPE_BEZIER
target_point = Geom::Point2d.new(1, 1)
bounds = Geom::Bounds2d.new(2, 1, 1, 1)
label_from_bounds = Layout::Label.new(text, leader_type, target_point,
  bounds)
path = Layout::Path.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(2, 3))
label_from_bounds.leader_line = path

Parameters:

Raises:

Version:

  • LayOut 2018

#leader_line_typeInteger

The #leader_line_type method returns the type of the leader line for the Layout::Label.

The leader line type can be one of the following values:

Layout::Label::LEADER_LINE_TYPE_SINGLE_SEGMENT
Layout::Label::LEADER_LINE_TYPE_TWO_SEGMENT
Layout::Label::LEADER_LINE_TYPE_BEZIER
Layout::Label::LEADER_LINE_TYPE_UNKNOWN

Examples:

text = "A label"
leader_type = Layout::Label::LEADER_LINE_TYPE_BEZIER
target_point = Geom::Point2d.new(1, 1)
bounds = Geom::Bounds2d.new(2, 1, 1, 1)
label_from_bounds = Layout::Label.new(text, leader_type, target_point,
  bounds)
leader_type = label_from_bounds.leader_line_type

Returns:

  • (Integer)

Version:

  • LayOut 2018

#leader_line_type=(leader_type) ⇒ Object

The #leader_line_type= method sets the type of the leader line for the Layout::Label.

The leader line type can be one of the following values:

Layout::Label::LEADER_LINE_TYPE_SINGLE_SEGMENT
Layout::Label::LEADER_LINE_TYPE_TWO_SEGMENT
Layout::Label::LEADER_LINE_TYPE_BEZIER
Layout::Label::LEADER_LINE_TYPE_UNKNOWN

Examples:

text = "A label"
leader_type = Layout::Label::LEADER_LINE_TYPE_BEZIER
target_point = Geom::Point2d.new(1, 1)
bounds = Geom::Bounds2d.new(2, 1, 1, 1)
label_from_bounds = Layout::Label.new(text, leader_type, target_point,
  bounds)
label_from_bounds.leader_line_type = Layout::Label::LEADER_LINE_TYPE_BEZIER

Parameters:

  • leader_type (Integer)

Raises:

Version:

  • LayOut 2018

#textLayout::FormattedText

The #text method returns a copy of the FormattedText of the Layout::Label.

Examples:

text = "A label"
leader_type = Layout::Label::LEADER_LINE_TYPE_BEZIER
target_point = Geom::Point2d.new(1, 1)
bounds = Geom::Bounds2d.new(2, 1, 1, 1)
label_from_bounds = Layout::Label.new(text, leader_type, target_point,
  bounds)
text = label_from_bounds.text

Returns:

Version:

  • LayOut 2018

#text=(new_text) ⇒ Object

The #text= method sets the FormattedText of the Layout::Label.

Examples:

text = "A label"
leader_type = Layout::Label::LEADER_LINE_TYPE_BEZIER
target_point = Geom::Point2d.new(1, 1)
bounds = Geom::Bounds2d.new(2, 1, 1, 1)
label_from_bounds = Layout::Label.new(text, leader_type, target_point,
  bounds)
anchor = Geom::Point2d.new(1, 1)
anchor_type = Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT
text = Layout::FormattedText.new("Test", anchor, anchor_type)
label_from_bounds.text = text

Parameters:

Raises:

Version:

  • LayOut 2018