Gtk2::TextTag
s and Gtk2::TextTagTable
s Gtk2::TextTag
s specify attributes that can be applied to a range of text in a Gtk2::TextBuffer
. Each Gtk2::TextBuffer
has a Gtk2::TextTagTable
that contains the Gtk2::TextTag
s that can be applied within the Gtk2::TextBuffer
. Gtk2::TextTagTable
s can be used with more than one Gtk2::TextBuffer
to provide consistent text styles.
Gtk2::TextTag
s Gtk2::TextTag
s can be named or anonymous. A Gtk2::TextTag
is created using the function:
texttag = Gtk2::TextTag->new ($name=undef) * $name (string or undef)If $name is not specified or is undef the tag will be anonymous.
Gtk2::TextTag
s can also be created using the Gtk2::TextBuffer
convenience method create_tag
which also allows you specify the tag attributes and adds the tag to the buffer's tag table (see Section 12.3).
The attributes that can be contained in a Gtk2::TextTag
are:
Table 12-2. Gtk2::TextTag
Attributes
name | Read / Write | Name of the text tag. undef if anonymous. |
background | Write | Background color as a string |
foreground | Write | Foreground color as a string |
background-gdk | Read / Write | Background color as a GdkColor |
foreground-gdk | Read / Write | Foreground color as a GdkColor |
background-stipple | Read / Write | Bitmap to use as a mask when drawing the text background |
foreground-stipple | Read / Write | Bitmap to use as a mask when drawing the text foreground |
font | Read / Write | Font description as a string, e.g. "Sans Italic 12" |
font-desc | Read / Write | Font description as a Gtk2::Pango::FontDescription |
family | Read / Write | Name of the font family, e.g. Sans, Helvetica, Times, Monospace |
style | Read / Write | Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC. |
variant | Read / Write | Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS. |
weight | Read / Write | Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD. |
stretch | Read / Write | Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED. |
size | Read / Write | Font size in Pango units. |
size-points | Read / Write | Font size in points |
scale | Read / Write | Font size as a scale factor relative to the default font size. This properly adapts to theme changes etc. so is recommended. Pango predefines some scales such as PANGO_SCALE_X_LARGE. |
pixels-above-lines | Read / Write | Pixels of blank space above paragraphs |
pixels-below-lines | Read / Write | Pixels of blank space below paragraphs |
pixels-inside-wrap | Read / Write | Pixels of blank space between wrapped lines in a paragraph |
editable | Read / Write | Whether the text can be modified by the user |
wrap-mode | Read / Write | Whether to wrap lines never, at word boundaries, or at character boundaries |
justification | Read / Write | Left, right, or center justification |
direction | Read / Write | Text direction, e.g. right-to-left or left-to-right |
left-margin | Read / Write | Width of the left margin in pixels |
indent | Read / Write | Amount to indent the paragraph, in pixels |
strikethrough | Read / Write | Whether to strike through the text |
right-margin | Read / Write | Width of the right margin in pixels |
underline | Read / Write | Style of underline for this text |
rise | Read / Write | Offset of text above the baseline (below the baseline if rise is negative) in pixels |
background-full-height | Read / Write | Whether the background color fills the entire line height or only the height of the tagged characters |
language | Read / Write | The language this text is in, as an ISO code. Pango can use this as a hint when rendering the text. If you don't understand this parameter, you probably don't need it. |
tabs | Read / Write | Custom tabs for this text |
invisible | Read / Write | Whether this text is hidden.Not implemented in GTK+ 2.0 |
The attributes can be set by using Glib::Object
's set_property
method:
$object->set_property (key => $value, ...)Where key is a string containing the name of the property and $value is what the property should be set to.
Likewise the attribute value can be retrieved with Glib::Object
's method:
list = $object->get_property (...)Since the tag does not have a value set for every attribute there are a set of boolean properties that indicate whether the attribute has been set in the tag:
Table 12-3. Gtk2::TextTag
Attributes
background-set | Read / Write |
foreground-set | Read / Write |
background-stipple-set | Read / Write |
foreground-stipple-set | Read / Write |
family-set | Read / Write |
style-set | Read / Write |
variant-set | Read / Write |
weight-set | Read / Write |
stretch-set | Read / Write |
size-set | Read / Write |
scale-set | Read / Write |
pixels-above-lines-set | Read / Write |
pixels-below-lines-set | Read / Write |
pixels-inside-wrap-set | Read / Write |
editable-set | Read / Write |
wrap-mode-set | Read / Write |
justification-set | Read / Write |
direction-set | Read / Write |
left-margin-set | Read / Write |
indent-set | Read / Write |
strikethrough-set | Read / Write |
right-margin-set | Read / Write |
underline-set | Read / Write |
rise-set | Read / Write |
background-full-height-set | Read / Write |
language-set | Read / Write |
tabs-set | Read / Write |
invisible-set | Read / Write |
Therefore to obtain the attribute from a tag, you have to first check whether the attribute has been set in the tag. For example to get a valid justification attribute you may have to do something like:
($object->get_property("justification-set"))&& ($justification = $object->get_property("justification"));The priority of a tag is by default the order in which they are added to the
Gtk2::TextTagTable
. The higher priority tag takes precedence if multiple tags try to set the same attribute for a range of text. The priority can be obtained and set with the methods:
integer = $tag->get_priority $tag->set_priority ($priority) * $priority (integer)The priority of a tag must be between 0 and one less than the
Gtk2::TextTagTable
size.
Gtk2::TextTagTable
A Gtk2::TextTagTable
will be created by default when a Gtk2::TextBuffer
is created. A Gtk2::TextTagTable
can also be created with the function:
texttagtable = Gtk2::TextTagTable->newA
Gtk2::TextTag
can be added to a Gtk2::TextTagTable
using the method:
$table->add ($tag) * $tag (Gtk2::TextTag)The tag must not be in the table and must not have the same name as another tag in the table.
You can find a Gtk2::TextTag
in a Gtk2::TextTagTable
using the method:
texttag = $table->lookup ($name) * $name (string)The method returns the tag in the table with $name or undef if no tag has $name.
A Gtk2::TextTag
can be removed from a Gtk2::TextTagTable
with the method:
$table->remove ($tag) * $tag (Gtk2::TextTag)The size of the
Gtk2::TextTagTable
can be obtained with the method:
integer = $table->get_size