class HexaPDF::Layout::Style
- already been used.
property_name? - Tester method to see if a value has been set or if the default value has
property_name(*args) and property_name= - Setter method.
property_name -
Getter method.
Each property has three associated methods:
changed.
Each property except #font has a default value, so only the desired properties need to be
A Style is a container for properties that describe the appearance of text or graphics.
- Setter method.
- Tester method to see if a value has been set or if the default value has
def self.create(style)
* is created.
* If +style+ is a hash, a new Style object with the style properties specified by the hash
* If +style+ is already a Style object, it is just returned.
Creates a Style object based on the +style+ argument and returns it:
Style.create(properties_hash) -> style
Style.create(style) -> style
:call-seq:
def self.create(style) case style when self then style when Hash then new(**style) when nil then new else raise ArgumentError, "Invalid argument class #{style.class}" end end
def calculated_font_size
def calculated_font_size (superscript || subscript ? 0.583 : 1) * font_size end
def calculated_strikeout_position
def calculated_strikeout_position calculated_text_rise + font.wrapped_font.strikeout_position * font.scaling_factor * font.pdf_object.glyph_scaling_factor * calculated_font_size - calculated_strikeout_thickness / 2.0 end
def calculated_strikeout_thickness
def calculated_strikeout_thickness font.wrapped_font.strikeout_thickness * font.scaling_factor * font.pdf_object.glyph_scaling_factor * calculated_font_size end
def calculated_text_rise
def calculated_text_rise if superscript text_rise + font_size * 0.33 elsif subscript text_rise - font_size * 0.20 else text_rise end end
def calculated_underline_position
def calculated_underline_position calculated_text_rise + font.wrapped_font.underline_position * font.scaling_factor * font.pdf_object.glyph_scaling_factor * calculated_font_size - calculated_underline_thickness / 2.0 end
def calculated_underline_thickness
def calculated_underline_thickness font.wrapped_font.underline_thickness * font.scaling_factor * font.pdf_object.glyph_scaling_factor * calculated_font_size end
def clear_cache
already cached: font, font_size, character_spacing, word_spacing, horizontal_scaling,
This method needs to be called if the following style properties are changed and values were
Clears all cached values.
def clear_cache @scaled_font_size = @scaled_character_spacing = @scaled_word_spacing = nil @scaled_horizontal_scaling = @scaled_font_ascender = @scaled_font_descender = nil @scaled_y_min = @scaled_y_max = nil @scaled_item_widths.clear end
def default_color
def default_color GlobalConfiguration.constantize('color_space.map', :DeviceGray).new.default_color end
def initialize(**properties)
Example:
equivalent to the property names.
The +properties+ hash may be used to set the initial values of properties by using keys
Creates a new Style object.
def initialize(**properties) update(**properties) @scaled_item_widths = {}.compare_by_identity end
def initialize_copy(other)
def initialize_copy(other) super @scaled_item_widths = {}.compare_by_identity clear_cache @font_features = @font_features.dup if defined?(@font_features) @padding = @padding.dup if defined?(@padding) @margin = @margin.dup if defined?(@margin) @border = @border.dup if defined?(@border) @overlays = @overlays.dup if defined?(@overlays) @underlays = @underlays.dup if defined?(@underlays) end
def scaled_character_spacing
def scaled_character_spacing @scaled_character_spacing ||= character_spacing * scaled_horizontal_scaling end
def scaled_font_ascender
def scaled_font_ascender @scaled_font_ascender ||= font.wrapped_font.ascender * font.scaling_factor * font.pdf_object.glyph_scaling_factor * font_size end
def scaled_font_descender
def scaled_font_descender @scaled_font_descender ||= font.wrapped_font.descender * font.scaling_factor * font.pdf_object.glyph_scaling_factor * font_size end
def scaled_font_size
def scaled_font_size @scaled_font_size ||= calculated_font_size * font.pdf_object.glyph_scaling_factor * scaled_horizontal_scaling end
def scaled_horizontal_scaling
def scaled_horizontal_scaling @scaled_horizontal_scaling ||= horizontal_scaling / 100.0 end
def scaled_item_width(item)
The item may be a (singleton) glyph object or an integer/float, i.e. items that can appear
word spacing and horizontal scaling into account).
Returns the width of the item scaled appropriately (by taking font size, characters spacing,
def scaled_item_width(item) @scaled_item_widths[item] ||= if item.kind_of?(Numeric) -item * scaled_font_size else item.width * scaled_font_size + scaled_character_spacing + (item.apply_word_spacing? ? scaled_word_spacing : 0) end end
def scaled_word_spacing
def scaled_word_spacing @scaled_word_spacing ||= word_spacing * scaled_horizontal_scaling end
def scaled_y_max
The maximum y-coordinate, calculated using the scaled ascender of the font and the line
def scaled_y_max @scaled_y_max ||= scaled_font_ascender * (line_height || font_size) / font_size.to_f + calculated_text_rise end
def scaled_y_min
The minimum y-coordinate, calculated using the scaled descender of the font and the line
def scaled_y_min @scaled_y_min ||= scaled_font_descender * (line_height || font_size) / font_size.to_f + calculated_text_rise end
def update(**properties)
style.update(**properties) -> style
:call-seq:
def update(**properties) properties.each {|key, value| send(key, value) } self end