Class: DynamicImageElements::TextElement
- Inherits:
-
Object
- Object
- DynamicImageElements::TextElement
- Includes:
- ElementInterface
- Defined in:
- lib/elements/text_element.rb
Overview
Element providing drawing of stylized text. You can use markup language of text specified by developer.gnome.org/pango/stable/PangoMarkupFormat.html
Instance Method Summary collapse
-
#initialize(content, options, parent, &block) ⇒ TextElement
constructor
Text element accepts content as text and options
Hash
.
Methods included from ElementInterface
#final_size, #set_height, #set_width
Constructor Details
#initialize(content, options, parent, &block) ⇒ TextElement
Text element accepts content as text and options Hash
. Block can be given and class provides original Pango::Layout object to modify it.
Options
Options can contain general attributes specified by BlockElement if it’s created by it. Most of TextElement options are based on Pango::Layout object.
- :align
-
Alignment of paragraphs. Valid values are :left, :center and :right.
- :auto_dir
-
If true, compute the bidirectional base direction from the layout’s contents.
- :color
-
Sets foreground of text element. Accepts value for DynamicImageSources::SourceFactory.
- :crop_to
-
Crop text to reach a specified size. Use an Array or String separated by space chars to provide further arguments.
Valid crop_to methods are :letters, :words and :sentences. Default method is :words if no one is given. Sentence is determined by one of “.!?”.
Add :lines (or :line) as second argument if size is for lines number, not by method. Lines are determined by parent container or :width if it’s given. See examples for more details.
Examples
-
:crop_to => 10
will crop text down to 10 words -
:crop_to => [10, :letters]
will crop text down to 10 letters and it’s same as:crop => "10 letters"
-
:crop_to => [3, :lines]
will crop text down by words to 3 lines -
:crop_to => [1, :line, :letters]
will crop text down by letters to 1 line
-
- :crop_suffix
-
It’s value is added at end of text in case it’s cropped. It can be caused by :crop and :to_fit options.
- :font
-
Creates a new font description from a string representation in the form “[FAMILY-LIST] [STYLE-OPTIONS] [SIZE]”, where FAMILY-LIST is a comma separated list of families optionally terminated by a comma, STYLE_OPTIONS is a whitespace separated list of words where each WORD describes one of style, variant, weight, or stretch, and SIZE is an decimal number (size in points). Any one of the options may be absent. If FAMILY-LIST is absent, then the family_name field of the resulting font description will be initialized to nil. If STYLE-OPTIONS is missing, then all style options will be set to the default values. If SIZE is missing, the size in the resulting font description will be set to 0. If str is nil, creates a new font description structure with all fields unset.
- :indent
-
Sets the width to indent each paragraph.
- :justify
-
Sets whether or not each complete line should be stretched to fill the entire width of the layout. This stretching is typically done by adding whitespace, but for some scripts (such as Arabic), the justification is done by extending the characters.
- :spacing
-
Sets the amount of spacing between the lines of the layout.
- :to_fit
-
Sets method how to deform text to fit its parent element. You can use an Array or String separated by space chars to provide further arguments.
Valid values are :crop and :resize.
Further argument for :crop are method of cropping (:letters, :words, :sentences). Default method is :words if no one is given. Sentence is determined by one of “.!?”. You can specify text to add at end of text if it’s cropped by :crop_suffix.
You can combine methods in your own order by setting further method in next positions of Array or String. Stop value must be set between methods to determine when to use next method.
Example
For one method use:
-
:to_fit => :crop
is same as:to_fit => [:crop]
and:to_fit => "crop"
-
:to_fit => :resize
-
:to_fit => [:crop, :letters]
will crop text by letters to fit its parent container and its same as:to_fit => "crop letters"
For more methods use:
-
:to_fit => [:crop, 10, :resize]
will crop down to 10 words to fit, if it’s not enough it will reduce size of font -
:to_fit => [:crop, :letters, 10, :resize]
will crop down to 10 letters to fit, if it’s not enough it will reduce size of font -
:to_fit => [:resize, 6, :crop]
will reduce size down to 6 pt letters to fit, if it’s not enough it will crop words -
:to_fit => [:resize, 6, :crop, :letters]
will reduce size down to 6 pt letters to fit, if it’s not enough it will crop letters -
:to_fit => [:crop, 2, :resize, 8, :crop, :letters]
will crop text down to 2 words, if it’s not enough to fit it will resize font down, but only to 8 pt and if it’s still not enough it will continue with cropping text by letters
-
64 65 66 67 68 69 70 |
# File 'lib/elements/text_element.rb', line 64 def initialize(content, , parent, &block) # :yields: pango_layout @content = content @options = @parent = parent @block = block :margin end |