ModraUp Ruby API Documentation Ruby API Reference

Class: Layout::Style

Inherits:
Object
  • Object
show all

Overview

Graphical and text styles (value objects). Layout::Entity#style returns a copy; changes must be assigned back using Layout::Entity#style= for them to take effect, similar to LayOut. Only properties relevant to the object type will be applied.

Units: line width, arrow size, font size in points (1 point ≈ 0.353 mm).

Note: ModraUp extension. Supported line types: STROKE_PATTERN_SOLID, DASH, CENTER (dashed), DOT, SHORT_DASH, PHANTOM (double-dashed); arrow types: ARROW_NONE, OPEN_TRIANGLE, FILLED_TRIANGLE, FILLED_CIRCLE, FILLED_SQUARE, FILLED_DIAMOND, SLASH_RIGHT. Other official constants will raise ArgumentError when set. Fill patterns are defined using #fill_pattern=.

Examples:

Dashed thick border

frame = Layout::Rectangle.new(Geom::Bounds2d.new(5.mm, 5.mm, 410.mm, 287.mm))
s = frame.style
s.stroke_width = 2.0
s.stroke_pattern = Layout::Style::STROKE_PATTERN_DASH
s.solid_filled = false
frame.style = s

Constants # collapse

Layout::Style::JOIN_STYLE_MITER

Miter join.

Returns:

  • (Integer)

Examples:

Layout::Style::JOIN_STYLE_MITER
Layout::Style::JOIN_STYLE_ROUND

Round corner connection.

Returns:

  • (Integer)

Examples:

Layout::Style::JOIN_STYLE_ROUND
Layout::Style::JOIN_STYLE_BEVEL

Bevel join (default).

Returns:

  • (Integer)

Examples:

Layout::Style::JOIN_STYLE_BEVEL
Layout::Style::CAP_STYLE_FLAT

Flat endpoints (default).

Returns:

  • (Integer)

Examples:

Layout::Style::CAP_STYLE_FLAT
Layout::Style::CAP_STYLE_ROUND

Round cap endpoint.

Returns:

  • (Integer)

Examples:

Layout::Style::CAP_STYLE_ROUND
Layout::Style::CAP_STYLE_SQUARE

Square cap endpoints.

Returns:

  • (Integer)

Examples:

Layout::Style::CAP_STYLE_SQUARE
Layout::Style::STROKE_PATTERN_SOLID

Line type: Solid.

Returns:

  • (Integer)

Examples:

Layout::Style::STROKE_PATTERN_SOLID
Layout::Style::STROKE_PATTERN_DASH

Line type: Dashed.

Returns:

  • (Integer)

Examples:

Layout::Style::STROKE_PATTERN_DASH
Layout::Style::STROKE_PATTERN_DOT

Line Type: Dot Dash.

Returns:

  • (Integer)

Examples:

Layout::Style::STROKE_PATTERN_DOT
Layout::Style::STROKE_PATTERN_DASH_DOT

Line type constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this line type, and an ArgumentError is raised when setting it.

Examples:

Layout::Style::STROKE_PATTERN_DASH_DOT
Layout::Style::STROKE_PATTERN_DASH_DOT_DOT

Line type constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this line type, and an ArgumentError is raised when setting it.

Examples:

Layout::Style::STROKE_PATTERN_DASH_DOT_DOT
Layout::Style::STROKE_PATTERN_DASH_SPACE

Line type constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this line type, and an ArgumentError is raised when setting it.

Examples:

Layout::Style::STROKE_PATTERN_DASH_SPACE
Layout::Style::STROKE_PATTERN_DASH_DOT_DOT_DOT

Line type constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this line type, and an ArgumentError is raised when setting it.

Examples:

Layout::Style::STROKE_PATTERN_DASH_DOT_DOT_DOT
Layout::Style::STROKE_PATTERN_DASH_DASH_DOT

Line type constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this line type, and an ArgumentError is raised when setting it.

Examples:

Layout::Style::STROKE_PATTERN_DASH_DASH_DOT
Layout::Style::STROKE_PATTERN_DASH_DASH_DOT_DOT

Line type constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this line type, and an ArgumentError is raised when setting it.

Examples:

Layout::Style::STROKE_PATTERN_DASH_DASH_DOT_DOT
Layout::Style::STROKE_PATTERN_DASH_DASH_DOT_DOT_DOT

Line type constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this line type, and an ArgumentError is raised when setting it.

Examples:

Layout::Style::STROKE_PATTERN_DASH_DASH_DOT_DOT_DOT
Layout::Style::STROKE_PATTERN_CENTER

Line Type: Center Dash Dot

Returns:

  • (Integer)

Examples:

Layout::Style::STROKE_PATTERN_CENTER
Layout::Style::STROKE_PATTERN_PHANTOM

Stroke pattern: Dotted and dashed.

Returns:

  • (Integer)

Examples:

Layout::Style::STROKE_PATTERN_PHANTOM
Layout::Style::STROKE_PATTERN_SHORT_DASH

Line type: Short dash.

Returns:

  • (Integer)

Examples:

Layout::Style::STROKE_PATTERN_SHORT_DASH
Layout::Style::ARROW_NONE

Arrows: None.

Returns:

  • (Integer)

Examples:

Layout::Style::ARROW_NONE
Layout::Style::ARROW_FILLED_TRIANGLE

Arrow: Filled Triangle.

Returns:

  • (Integer)

Examples:

Layout::Style::ARROW_FILLED_TRIANGLE
Layout::Style::ARROW_OPEN_TRIANGLE

Arrow: Hollow Triangle.

Returns:

  • (Integer)

Examples:

Layout::Style::ARROW_OPEN_TRIANGLE
Layout::Style::ARROW_FILLED_SKINNY_TRIANGLE

Arrow constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this arrow, and an ArgumentError is raised when applied to an object.

Examples:

Layout::Style::ARROW_FILLED_SKINNY_TRIANGLE
Layout::Style::ARROW_OPEN_SKINNY_TRIANGLE

Arrow constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this arrow, and an ArgumentError is raised when applied to an object.

Examples:

Layout::Style::ARROW_OPEN_SKINNY_TRIANGLE
Layout::Style::ARROW_OPEN_ARROW_90

Arrow constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this arrow, and an ArgumentError is raised when applied to an object.

Examples:

Layout::Style::ARROW_OPEN_ARROW_90
Layout::Style::ARROW_OPEN_ARROW_120

Arrow constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this arrow, and an ArgumentError is raised when applied to an object.

Examples:

Layout::Style::ARROW_OPEN_ARROW_120
Layout::Style::ARROW_FILLED_CIRCLE

Arrow: Filled Circle.

Returns:

  • (Integer)

Examples:

Layout::Style::ARROW_FILLED_CIRCLE
Layout::Style::ARROW_OPEN_CIRCLE

Arrow constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this arrow, and an ArgumentError is raised when applied to an object.

Examples:

Layout::Style::ARROW_OPEN_CIRCLE
Layout::Style::ARROW_FILLED_SQUARE

Arrow: Filled Square.

Returns:

  • (Integer)

Examples:

Layout::Style::ARROW_FILLED_SQUARE
Layout::Style::ARROW_OPEN_SQUARE

Arrow constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this arrow, and an ArgumentError is raised when applied to an object.

Examples:

Layout::Style::ARROW_OPEN_SQUARE
Layout::Style::ARROW_FILLED_DIAMOND

Arrow: Filled Diamond.

Returns:

  • (Integer)

Examples:

Layout::Style::ARROW_FILLED_DIAMOND
Layout::Style::ARROW_OPEN_DIAMOND

Arrow constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this arrow, and an ArgumentError is raised when applied to an object.

Examples:

Layout::Style::ARROW_OPEN_DIAMOND
Layout::Style::ARROW_STAR

Arrow constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this arrow, and an ArgumentError is raised when applied to an object.

Examples:

Layout::Style::ARROW_STAR
Layout::Style::ARROW_T

Arrow constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this arrow, and an ArgumentError is raised when applied to an object.

Examples:

Layout::Style::ARROW_T
Layout::Style::ARROW_SLASH_RIGHT

Arrow: Slash (architectural dimension leader).

Returns:

  • (Integer)

Examples:

Layout::Style::ARROW_SLASH_RIGHT
Layout::Style::ARROW_SLASH_LEFT

Arrow constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this arrow, and an ArgumentError is raised when applied to an object.

Examples:

Layout::Style::ARROW_SLASH_LEFT
Layout::Style::ARROW_UNDERRUN

Arrow constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this arrow, and an ArgumentError is raised when applied to an object.

Examples:

Layout::Style::ARROW_UNDERRUN
Layout::Style::ARROW_OVERRUN

Arrow constant (LayOut name).

Returns:

  • (Integer)
Note: ModraUp extension. OpenSu does not support this arrow, and an ArgumentError is raised when applied to an object.

Examples:

Layout::Style::ARROW_OVERRUN
Layout::Style::ALIGN_LEFT

Align text to the left.

Returns:

  • (Integer)

Examples:

Layout::Style::ALIGN_LEFT
Layout::Style::ALIGN_RIGHT

Align text to the right.

Returns:

  • (Integer)

Examples:

Layout::Style::ALIGN_RIGHT
Layout::Style::ALIGN_CENTER

Center the text.

Returns:

  • (Integer)

Examples:

Layout::Style::ALIGN_CENTER

Class Method Summary # collapse

  • .new ⇒ Layout::Style
    Empty Style: Unset properties read their default values, and when applied to an object, only set properties are applied.

Instance Method Summary # collapse

Class Method Details

Layout::Style.new ⇒ Layout::Style

Empty Style: Unset properties read their default values, and when applied to an object, only set properties are applied.

Returns:

  • (Layout::Style)

Examples:

s = Layout::Style.new
s.stroke_color = ModraUp::Color.new(255, 0, 0)

Instance Method Details

style.dup ⇒ Layout::Style

Copy the style.

Parameters:

  • other (Layout::Style)

Returns:

  • (Layout::Style)

Examples:

Layout::Style.new.dup

style.stroked ⇒ Boolean

Returns whether the outline is drawn.

Returns:

  • (Boolean)

Examples:

Layout::Style.new.stroked  #=> true

style.stroked = stroked

Set whether to stroke.

Parameters:

  • stroked (Boolean)

Returns:

  • (Boolean)

Examples:

Layout::Style.new.stroked = false

style.stroke_color ⇒ ModraUp::Color

Stroke color (for lines and text color).

Returns:

  • (ModraUp::Color)

Examples:

Layout::Style.new.stroke_color

style.stroke_color = color

Sets the line color.

Parameters:

  • color (ModraUp::Color, String)

Returns:

  • (ModraUp::Color, String)

Raises:

  • [ArgumentError] not a color

Examples:

Layout::Style.new.stroke_color = ModraUp::Color.new(200, 0, 0)

style.stroke_width ⇒ Float

Line width in points.

Returns:

  • (Float)

Examples:

Layout::Style.new.stroke_width

style.stroke_width = points

Set the line width in pounds (path as 0.05~5 mm, dimensions and leaders as 0.02~5 mm).

Parameters:

  • points (Numeric)

Returns:

  • (Numeric)

Raises:

  • [ArgumentError] Out of range

Examples:

Approximately 0.7 mm

Layout::Style.new.stroke_width = 2.0

style.stroke_pattern ⇒ Integer

Line patterns, STROKE_PATTERN_*.

Returns:

  • (Integer)

Examples:

Layout::Style.new.stroke_pattern == Layout::Style::STROKE_PATTERN_SOLID  #=> true

style.stroke_pattern = pattern

Set the line pattern.

Parameters:

  • pattern (Integer) STROKE_PATTERN_SOLID、DASH、CENTER、DOT、SHORT_DASH or PHANTOM

Returns:

  • (Integer)

Raises:

  • [ArgumentError] Unsupported line pattern

Examples:

Layout::Style.new.stroke_pattern = Layout::Style::STROKE_PATTERN_CENTER

style.stroke_pattern_scale ⇒ Float

Line type scale.

Returns:

  • (Float)

Examples:

Layout::Style.new.stroke_pattern_scale  #=> 1.0

style.stroke_pattern_scale = scale

Set the line pattern scale.

Parameters:

  • scale (Numeric) 0.1~10

Returns:

  • (Numeric)

Raises:

  • [ArgumentError] Out of range

Examples:

Layout::Style.new.stroke_pattern_scale = 2

style.stroke_join_style ⇒ Integer

Line segment connection style, JOIN_STYLE_*.

Returns:

  • (Integer)

Examples:

Layout::Style.new.stroke_join_style

style.stroke_join_style = join

Set the connection style.

Parameters:

  • join (Integer) JOIN_STYLE_*

Returns:

  • (Integer)

Raises:

  • [ArgumentError] Unknown constant

Examples:

Layout::Style.new.stroke_join_style = Layout::Style::JOIN_STYLE_ROUND

style.stroke_cap_style ⇒ Integer

Endpoint style, CAP_STYLE_*.

Returns:

  • (Integer)

Examples:

Layout::Style.new.stroke_cap_style

style.stroke_cap_style = cap

Set the endpoint style.

Parameters:

  • cap (Integer) CAP_STYLE_*

Returns:

  • (Integer)

Raises:

  • [ArgumentError] Unknown constant

Examples:

Layout::Style.new.stroke_cap_style = Layout::Style::CAP_STYLE_ROUND

style.solid_filled ⇒ Boolean

Whether to use solid color filling.

Returns:

  • (Boolean)

Examples:

Layout::Style.new.solid_filled  #=> false

style.solid_filled = filled

Set solid color filling.

Parameters:

  • filled (Boolean)

Returns:

  • (Boolean)

Examples:

Layout::Style.new.solid_filled = true

style.fill_color ⇒ ModraUp::Color

Fill color.

Returns:

  • (ModraUp::Color)

Examples:

Layout::Style.new.fill_color

style.fill_color = color

Sets the fill color.

Parameters:

  • color (ModraUp::Color, String)

Returns:

  • (ModraUp::Color, String)

Raises:

  • [ArgumentError] not a color

Examples:

Layout::Style.new.fill_color = "LightGray"

style.pattern_filled ⇒ Boolean

Does the pattern fill exist?

Returns:

  • (Boolean)

Examples:

Layout::Style.new.pattern_filled  #=> false

style.pattern_filled = filled

Enable or disable pattern filling; when enabled, use diagonal lines if no pattern is selected.

Parameters:

  • filled (Boolean)

Returns:

  • (Boolean)
Note: ModraUp extension. OpenSu supports 6 built-in patterns, not image fills; select a pattern using #fill_pattern=.

Examples:

Layout::Style.new.pattern_filled = true

style.fill_pattern ⇒ Symbol

Built-in fill patterns: :none, :horizontal, :vertical, :diagonal, :back_diagonal, :crosshatch, :dots.

Returns:

  • (Symbol)
Note: ModraUp extension.

Examples:

Layout::Style.new.fill_pattern  #=> :none

style.fill_pattern = pattern

Select a built-in fill pattern with 3 mm spacing on the sheet.

Parameters:

  • pattern (Symbol)

Returns:

  • (Symbol)

Raises:

  • [ArgumentError] Unknown fill pattern
Note: ModraUp extension.

Examples:

Layout::Style.new.fill_pattern = :crosshatch

style.pattern_fill_path ⇒ raises

Does not support: OpenSu has no image fill.

Raises:

  • [NotImplementedError]
Note: ModraUp extension. Unlike in LayOut, use #fill_pattern=.

Examples:

Layout::Style.new.pattern_fill_path rescue puts $!.message

style.pattern_fill_path = path ⇒ raises

Does not support: OpenSu has no image fill.

Parameters:

  • path (String)

Raises:

  • [NotImplementedError]
Note: ModraUp extension. Unlike in LayOut, use #fill_pattern=.

Examples:

(Layout::Style.new.pattern_fill_path = "a.png") rescue puts $!.message

style.start_arrow_type ⇒ Integer

Start arrow, ARROW_*.

Returns:

  • (Integer)

Examples:

Layout::Style.new.start_arrow_type

style.start_arrow_type = type

Sets the start arrow. Only applicable to open paths, leaders, and dimensions.

Parameters:

  • type (Integer) ARROW_*

Returns:

  • (Integer)

Raises:

  • [ArgumentError] Unknown constant; also raises when the type is not supported for the object.

Examples:

Layout::Style.new.start_arrow_type = Layout::Style::ARROW_FILLED_TRIANGLE

style.end_arrow_type ⇒ Integer

End arrow, ARROW_*.

Returns:

  • (Integer)

Examples:

Layout::Style.new.end_arrow_type

style.end_arrow_type = type

Set the end arrow type.

Parameters:

  • type (Integer) ARROW_*

Returns:

  • (Integer)

Raises:

  • [ArgumentError] Unknown constant
Note: ModraUp extension. Both ends of the dimension share the same symbol; an ArgumentError will be raised if different values are set for both ends.

Examples:

Layout::Style.new.end_arrow_type = Layout::Style::ARROW_OPEN_TRIANGLE

style.start_arrow_size ⇒ Float

Start arrow size in points.

Returns:

  • (Float)

Examples:

Layout::Style.new.start_arrow_size

style.start_arrow_size = points

Set the size of the start arrow.

Parameters:

  • points (Numeric) 0.5~72

Returns:

  • (Numeric)

Raises:

  • [ArgumentError] Out of range

Examples:

Layout::Style.new.start_arrow_size = 6

style.end_arrow_size ⇒ Float

The size of the end arrow, in points.

Returns:

  • (Float)

Examples:

Layout::Style.new.end_arrow_size

style.end_arrow_size = points

Set the size of the end arrow.

Parameters:

  • points (Numeric) 0.5~72

Returns:

  • (Numeric)

Raises:

  • [ArgumentError] Out of range

Examples:

Layout::Style.new.end_arrow_size = 6

style.font_family ⇒ String

Font family; an empty string if unknown.

Returns:

  • (String)

Examples:

Layout::Style.new.font_family

style.font_family = family

Set the font family. An ArgumentError is raised if the font is not installed.

Parameters:

  • family (String)

Returns:

  • (String)

Raises:

  • [ArgumentError] empty string

Examples:

Layout::Style.new.font_family = "Source Han Sans SC"

style.font_size ⇒ Float

Font size, points (point size = font_size × 0.353 mm).

Returns:

  • (Float)

Examples:

Layout::Style.new.font_size

style.font_size = points

Set the font size in points. The height of the text characters is limited to 1~30 mm, with dimensions and notes ranging from 0.5~30 mm.

Parameters:

  • points (Numeric)

Returns:

  • (Numeric)

Raises:

  • [ArgumentError] Out of range

Examples:

Layout::Style.new.font_size = 14

style.text_color ⇒ ModraUp::Color

Text color.

Returns:

  • (ModraUp::Color)

Examples:

Layout::Style.new.text_color

style.text_color = color

Set the text color.

Parameters:

  • color (ModraUp::Color, String)

Returns:

  • (ModraUp::Color, String)

Raises:

  • [ArgumentError] not a color

Examples:

Layout::Style.new.text_color = ModraUp::Color.new(0, 0, 0)

style.text_bold ⇒ Boolean

Is bold.

Returns:

  • (Boolean)

Examples:

Layout::Style.new.text_bold  #=> false

style.text_bold = bold

Set text to bold (effective only for text).

Parameters:

  • bold (Boolean)

Returns:

  • (Boolean)

Examples:

Layout::Style.new.text_bold = true

style.text_italic ⇒ Boolean

Whether the text is italic.

Returns:

  • (Boolean)

Examples:

Layout::Style.new.text_italic  #=> false

style.text_italic = italic

Set text in italic (effective only for text).

Parameters:

  • italic (Boolean)

Returns:

  • (Boolean)

Examples:

Layout::Style.new.text_italic = true

style.text_alignment ⇒ Integer

Paragraph alignment, ALIGN_*.

Returns:

  • (Integer)

Examples:

Layout::Style.new.text_alignment == Layout::Style::ALIGN_LEFT  #=> true

style.text_alignment = align

Set paragraph alignment (only effective for text).

Parameters:

  • align (Integer) ALIGN_LEFT, ALIGN_CENTER, or ALIGN_RIGHT

Returns:

  • (Integer)

Raises:

  • [ArgumentError] Unknown constant

Examples:

Layout::Style.new.text_alignment = Layout::Style::ALIGN_CENTER