class HexaPDF::Layout::Style

Parent

A Style is a container for properties that describe the appearance of text or graphics.

Each property except font has a default value, so only the desired properties need to be changed.

Each property has three associated methods:

property_name

Getter method.

property_name(*args) and property_name=

Setter method.

property_name?

Tester method to see if a value has been set or if the default value has already been used.

Public Class Methods

new(**properties)

Creates a new Style object.

The properties hash may be used to set the initial values of properties by using keys equivalent to the property names.

Example:

Style.new(font_size: 15, align: :center, valign: center)

Public Instance Methods

align(direction = nil)

The horizontal alignment of text, defaults to :left.

Possible values:

:left

Left-align the text, i.e. the right side is rugged.

:center

Center the text horizontally.

:right

Right-align the text, i.e. the left side is rugged.

:justify

Justify the text, except for those lines that end in a hard line break.

background_color(color = nil)

The color used for backgrounds, defaults to nil (i.e. no background).

border(value = nil)

The border around the contents, defaults to no border.

calculated_font_size()

The calculated font size, taking superscript and subscript into account.

calculated_strikeout_position()

Returns the correct offset from the baseline for the strikeout line.

calculated_strikeout_thickness()

Returns the correct thickness for the strikeout line.

calculated_text_rise()

The calculated text rise, taking superscript and subscript into account.

calculated_underline_position()

Returns the correct offset from the baseline for the underline.

calculated_underline_thickness()

Returns the correct thickness for the underline.

character_spacing(amount = nil)

The character spacing, defaults to 0 (i.e. no additional character spacing).

See: Canvas#character_spacing

clear_cache()

Clears all cached values.

This method needs to be called if the following style properties are changed and values were already cached: font, #font_size, #character_spacing, #word_spacing, #horizontal_scaling, ascender, descender.

fill_alpha(alpha = nil)

The alpha value applied to filling operations (e.g. text), defaults to 1 (i.e. 100% opaque).

See: Canvas#opacity

fill_color(color = nil)

The color used for filling (e.g. text), defaults to black.

See: Canvas#fill_color

font(name = nil)

The font to be used, must be set to a valid font wrapper object before it can be used.

This is the only style property without a default value!

See: Canvas#font

font_features(features = nil)

The font features (e.g. kerning, ligatures, …) that should be applied by the shaping engine, defaults to {} (i.e. no font features are applied).

Each feature to be applied is indicated by a key with a truthy value.

See: TextShaper#shape_text for available features.

font_size(size = nil)

The font size, defaults to 10.

See: Canvas#font_size

horizontal_scaling(percent = nil)

The horizontal scaling, defaults to 100 (in percent, i.e. normal scaling).

See: Canvas#horizontal_scaling

margin(value = nil)

The margin around a box, defaults to 0 for all four sides.

overlays(layers = nil)

A Layers object containing all the layers that should be drawn over the box; defaults to no layers being drawn.

padding(value = nil)

The padding between the border and the contents, defaults to 0 for all four sides.

position(value = nil)

Specifies how a box should be positioned in a frame. The property position_hint provides additional, position specific data. Defaults to :default.

Possible values:

:default

Position the box at the current position. The exact horizontal position is given via the position hint. Space to the left/right of the box can't be used for other boxes.

:float

Position the box at the current position but let it “float” so that the space to the left/right can still be used. The position hint specifies where the box should float.

:absolute

Position the box at an absolute position relative to the frame. The coordinates are given via the position hint.

position_hint(value = nil)

Specifies additional information on how a box should be positioned in a frame. The exact meaning depends on the value of the position property.

Possible values depending on the position property:

:default
:left

(default) Align the box to the left side of the available region.

:right

Align the box to the right side of the available region.

:center

Horizontally center the box in the available region.

:float
:left

(default) Float the box to the left side of the available region.

:right

Float the box to the right side of the available region.

:absolute

An array with the x- and y-coordinates of the bottom left corner of the absolutely positioned box. The coordinates are taken as being relative to the bottom left corner of the frame into which the box is drawn.

scaled_character_spacing()

The character spacing scaled appropriately.

scaled_font_ascender()

The ascender of the font scaled appropriately.

scaled_font_descender()

The descender of the font scaled appropriately.

scaled_font_size()

The font size scaled appropriately.

scaled_horizontal_scaling()

The horizontal scaling scaled appropriately.

scaled_item_width(item)

Returns the width of the item scaled appropriately (by taking font size, characters spacing, word spacing and horizontal scaling into account).

The item may be a (singleton) glyph object or an integer/float, i.e. items that can appear inside a TextFragment.

scaled_word_spacing()

The word spacing scaled appropriately.

scaled_y_max()

The maximum y-coordinate, calculated using the scaled descender of the font.

scaled_y_min()

The minimum y-coordinate, calculated using the scaled descender of the font.

stroke_alpha(alpha = nil)

The alpha value applied to stroking operations (e.g. text outlines), defaults to 1 (i.e. 100% opaque).

See: Canvas#opacity

stroke_cap_style(style = nil)

The line cap style used for stroking operations (e.g. text outlines), defaults to :butt.

See: Canvas#line_cap_style

stroke_color(color = nil)

The color used for stroking (e.g. text outlines), defaults to black.

See: Canvas#stroke_color

stroke_join_style(style = nil)

The line join style used for stroking operations (e.g. text outlines), defaults to :miter.

See: Canvas#line_join_style

stroke_miter_limit(limit = nil)

The miter limit used for stroking operations (e.g. text outlines) when stroke_join_style is :miter, defaults to 10.0.

See: Canvas#miter_limit

stroke_width(width = nil)

The line width used for stroking operations (e.g. text outlines), defaults to 1.

See: Canvas#line_width

subscript(enable = false)

Render the text as subscript, i.e. lower and in a smaller font size; defaults to false.

If superscript is set, it will be deactivated.

superscript(enable = false)

Render the text as superscript, i.e. higher and in a smaller font size; defaults to false.

If subscript is set, it will be deactivated.

text_indent(amount = nil)

The indentation to be used for the first line of a sequence of text lines, defaults to 0.

text_line_wrapping_algorithm(algorithm = nil) {|items, width_block| block }

The line wrapping algorithm that should be used, defaults to TextLayouter::SimpleLineWrapping.

When setting the algorithm, either an object that responds to call or a block can be used. See TextLayouter::SimpleLineWrapping#call for the needed method signature.

text_rendering_mode(mode = nil)

The text rendering mode, i.e. whether text should be filled, stroked, clipped, invisible or a combination thereof, defaults to :fill.

See: Canvas#text_rendering_mode

text_rise(amount = nil)

The text rise, i.e. the vertical offset from the baseline, defaults to 0.

See: Canvas#text_rise

text_segmentation_algorithm(algorithm = nil) {|items| block }

The algorithm to use for text segmentation purposes, defaults to TextLayouter::SimpleTextSegmentation.

When setting the algorithm, either an object that responds to call(items) or a block can be used.

underlays(layers = nil)

A Layers object containing all the layers that should be drawn under the box; defaults to no layers being drawn.

update(**properties) → style

Updates the style's properties using the key-value pairs specified by the properties hash.

valign(direction = nil)

The vertical alignment of items (normally text) inside a box, defaults to :top.

Possible values:

:top

Vertically align the items to the top of the box.

:center

Vertically align the items in the center of the box.

:bottom

Vertically align the items to the bottom of the box.

word_spacing(amount = nil)

The word spacing, defaults to 0 (i.e. no additional word spacing).

See: Canvas#word_spacing