Next: , Previous: Tab Stops, Up: Top


10 Text Attributes

Font and other attributes for annotating text

10.1 Overview

Attributed text is used in a number of places in Pango. It is used as the input to the itemization process and also when creating a <pango-layout>. The data types and functions in this section are used to represent and manipulate sets of attributes applied to a portion of text.

10.2 Usage

— Class: <pango-attribute>

Opaque pointer.

This class defines no direct slots.

— Class: <pango-color>

Derives from <gboxed>.

This class defines no direct slots.

— Class: <pango-language>

Derives from <gboxed>.

This class defines no direct slots.

— Class: <pango-attr-list>

Derives from <gboxed>.

This class defines no direct slots.

— Class: <pango-attr-iterator>

Opaque pointer.

This class defines no direct slots.

— Function: pango-attr-type-register (name mchars) ⇒  (ret <pango-attr-type>)

Allocate a new attribute type ID.

name
an identifier for the type (currently unused.)
ret
the new type ID.
— Function: pango-attribute-copy (self <pango-attribute>) ⇒  (ret <pango-attribute>)

Make a copy of an attribute.

attr
a <pango-attribute>
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attribute-equal (self <pango-attribute>) (attr2 <pango-attribute>) ⇒  (ret bool)

Compare two attributes for equality. This compares only the actual value of the two attributes and not the ranges that the attributes apply to.

attr1
a <pango-attribute>
attr2
another <pango-attribute>
ret
#t’ if the two attributes have the same value.
— Function: pango-attr-language-new (language <pango-language>) ⇒  (ret <pango-attribute>)

Create a new language tag attribute.

language
language tag
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-family-new (family mchars) ⇒  (ret <pango-attribute>)

Create a new font family attribute.

family
the family or comma separated list of families
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-style-new (style <pango-style>) ⇒  (ret <pango-attribute>)

Create a new font slant style attribute.

style
the slant style
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-variant-new (variant <pango-variant>) ⇒  (ret <pango-attribute>)

Create a new font variant attribute (normal or small caps)

variant
the variant
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-stretch-new (stretch <pango-stretch>) ⇒  (ret <pango-attribute>)

Create a new font stretch attribute

stretch
the stretch
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-weight-new (weight <pango-weight>) ⇒  (ret <pango-attribute>)

Create a new font weight attribute.

weight
the weight
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-size-new (size int) ⇒  (ret <pango-attribute>)

Create a new font-size attribute in fractional points.

size
the font size, in ‘PANGO_SCALE’ths of a point.
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-size-new-absolute (size int) ⇒  (ret <pango-attribute>)

Create a new font-size attribute in device units.

size
the font size, in ‘PANGO_SCALE’ths of a device unit.
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.

Since 1.8

— Function: pango-attr-font-desc-new (desc <pango-font-description>) ⇒  (ret <pango-attribute>)

Create a new font description attribute. This attribute allows setting family, style, weight, variant, stretch, and size simultaneously.

desc
the font description
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-foreground-new (red unsigned-int16) (green unsigned-int16) (blue unsigned-int16) ⇒  (ret <pango-attribute>)

Create a new foreground color attribute.

red
the red value (ranging from 0 to 65535)
green
the green value
blue
the blue value
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-background-new (red unsigned-int16) (green unsigned-int16) (blue unsigned-int16) ⇒  (ret <pango-attribute>)

Create a new background color attribute.

red
the red value (ranging from 0 to 65535)
green
the green value
blue
the blue value
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-strikethrough-new (strikethrough bool) ⇒  (ret <pango-attribute>)

Create a new strike-through attribute.

strikethrough
#t’ if the text should be struck-through.
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-strikethrough-color-new (red unsigned-int16) (green unsigned-int16) (blue unsigned-int16) ⇒  (ret <pango-attribute>)

Create a new strikethrough color attribute. This attribute modifies the color of strikethrough lines. If not set, strikethrough lines will use the foreground color.

red
the red value (ranging from 0 to 65535)
green
the green value
blue
the blue value
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.

Since 1.8

— Function: pango-attr-underline-new (underline <pango-underline>) ⇒  (ret <pango-attribute>)

Create a new underline-style attribute.

underline
the underline style.
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-underline-color-new (red unsigned-int16) (green unsigned-int16) (blue unsigned-int16) ⇒  (ret <pango-attribute>)

Create a new underline color attribute. This attribute modifies the color of underlines. If not set, underlines will use the foreground color.

red
the red value (ranging from 0 to 65535)
green
the green value
blue
the blue value
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.

Since 1.8

— Function: pango-attr-shape-new (ink_rect <pango-rectangle>) (logical_rect <pango-rectangle>) ⇒  (ret <pango-attribute>)

Create a new shape attribute. A shape is used to impose a particular ink and logical rectangle on the result of shaping a particular glyph. This might be used, for instance, for embedding a picture or a widget inside a <pango-layout>.

ink-rect
ink rectangle to assign to each character
logical-rect
logical rectangle to assign to each character
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-scale-new (scale_factor double) ⇒  (ret <pango-attribute>)

Create a new font size scale attribute. The base font for the affected text will have its size multiplied by scale-factor.

scale-factor
factor to scale the font
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-fallback-new (enable_fallback bool) ⇒  (ret <pango-attribute>)

Create a new font fallback attribute.

If fallback is disabled, characters will only be used from the closest matching font on the system. No fallback will be done to other fonts on the system that might contain the characters in the text.

enable-fallback
#t’ if we should fall back on other fonts for characters the active font is missing.
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.

Since 1.4

— Function: pango-attr-rise-new (rise int) ⇒  (ret <pango-attribute>)

Create a new baseline displacement attribute.

rise
the amount that the text should be displaced vertically, in Pango units. Positive values displace the text upwards.
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.
— Function: pango-attr-letter-spacing-new (letter_spacing int) ⇒  (ret <pango-attribute>)

Create a new letter-spacing attribute.

letter-spacing
amount of extra space to add between graphemes of the text, in Pango units.
ret
the newly allocated <pango-attribute>, which should be freed with pango-attribute-destroy.

Since 1.6

— Function: pango-color-parse (self <pango-color>) (spec mchars) ⇒  (ret bool)

Fill in the fields of a color from a string specification. The string can either one of a large set of standard names. (Taken from the X11 rgb.txt file), or it can be a hex value in the form '&#x0023;rgb' '&#x0023;rrggbb' '&#x0023;rrrgggbbb' or '&#x0023;rrrrggggbbbb' where 'r', 'g' and 'b' are hex digits of the red, green, and blue components of the color, respectively. (White in the four forms is '&#x0023;fff' '&#x0023;ffffff' '&#x0023;fffffffff' and '&#x0023;ffffffffffff')

color
a <pango-color> structure in which to store the result
spec
a string specifying the new color
ret
#t’ if parsing of the specifier succeeded, otherwise false.
— Function: pango-color-copy (self <pango-color>) ⇒  (ret <pango-color>)

Creates a copy of src, which should be freed with pango-color-free. Primarily used by language bindings, not that useful otherwise (since colors can just be copied by assignment in C).

src
color to copy
ret
the newly allocated <pango-color>, which should be freed with pango-color-free.
— Function: pango-language-from-string (language mchars) ⇒  (ret <pango-language>)

Take a RFC-3066 format language tag as a string and convert it to a <pango-language> pointer that can be efficiently copied (copy the pointer) and compared with other language tags (compare the pointer.)

This function first canonicalizes the string by converting it to lowercase, mapping '_' to '-', and stripping all characters other than letters and '-'.

language
a string representing a language tag
ret
an opaque pointer to a <pango-language> structure. this will be valid forever after.
— Function: pango-language-matches (self <pango-language>) (range_list mchars) ⇒  (ret bool)

Checks if a language tag matches one of the elements in a list of language ranges. A language tag is considered to match a range in the list if the range is '*', the range is exactly the tag, or the range is a prefix of the tag, and the character after it in the tag is '-'.

language
a language tag (see pango-language-from-string), ‘#f’ is allowed and matches nothing but '*'
range-list
a list of language ranges, separated by ';', ':', ',', or space characters. Each element must either be '*', or a RFC 3066 language range canonicalized as by pango-language-from-string
ret
#t’ if a match was found.
— Function: pango-attr-list-new ⇒  (ret <pango-attr-list>)

Create a new empty attribute list with a reference count of one.

ret
the newly allocated <pango-attr-list>, which should be freed with pango-attr-list-unref.
— Function: pango-attr-list-copy (self <pango-attr-list>) ⇒  (ret <pango-attr-list>)

Copy list and return an identical new list.

list
a <pango-attr-list>
ret
the newly allocated <pango-attr-list>, with a reference count of one, which should be freed with pango-attr-list-unref.
— Function: pango-attr-list-insert (self <pango-attr-list>) (attr <pango-attribute>)

Insert the given attribute into the <pango-attr-list>. It will be inserted after all other attributes with a matching start-index.

list
a <pango-attr-list>
attr
the attribute to insert. Ownership of this value is assumed by the list.
— Function: pango-attr-list-insert-before (self <pango-attr-list>) (attr <pango-attribute>)

Insert the given attribute into the <pango-attr-list>. It will be inserted before all other attributes with a matching start-index.

list
a <pango-attr-list>
attr
the attribute to insert. Ownership of this value is assumed by the list.
— Function: pango-attr-list-change (self <pango-attr-list>) (attr <pango-attribute>)

Insert the given attribute into the <pango-attr-list>. It will replace any attributes of the same type on that segment and be merged with any adjoining attributes that are identical.

This function is slower than pango-attr-list-insert for creating a attribute list in order (potentially much slower for large lists). However, pango-attr-list-insert is not suitable for continually changing a set of attributes since it never removes or combines existing attributes.

list
a <pango-attr-list>
attr
the attribute to insert. Ownership of this value is assumed by the list.
— Function: pango-attr-list-splice (self <pango-attr-list>) (other <pango-attr-list>) (pos int) (len int)

This function opens up a hole in list, fills it in with attributes from the left, and then merges other on top of the hole.

This operation is equivalent to stretching every attribute that applies at position pos in list by an amount len, and then calling pango-attr-list-change with a copy of each attribute in other in sequence (offset in position by pos).

This operation proves useful for, for instance, inserting a pre-edit string in the middle of an edit buffer.

list
a <pango-attr-list>
other
another <pango-attr-list>
pos
the position in list at which to insert other
len
the length of the spliced segment. (Note that this must be specified since the attributes in other may only be present at some subsection of this range)
— Function: pango-attr-list-get-iterator (self <pango-attr-list>) ⇒  (ret <pango-attr-iterator>)

Create a iterator initialized to the beginning of the list. list must not be modified until this iterator is freed.

list
a <pango-attr-list>
ret
the newly allocated <pango-attr-iterator>, which should be freed with pango-attr-iterator-destroy.
— Function: pango-attr-iterator-copy (self <pango-attr-iterator>) ⇒  (ret <pango-attr-iterator>)

Copy a <pango-attr-iterator>

iterator
a <pango-attr-iterator>.
ret
the newly allocated <pango-attr-iterator>, which should be freed with pango-attr-iterator-destroy.
— Function: pango-attr-iterator-next (self <pango-attr-iterator>) ⇒  (ret bool)

Advance the iterator until the next change of style.

iterator
a <pango-attr-iterator>
ret
#f’ if the iterator is at the end of the list, otherwise ‘#t
— Function: pango-attr-iterator-range (self <pango-attr-iterator>) ⇒  (start int) (end int)

Get the range of the current segment. Note that the stored return values are signed, not unsigned like the values in <pango-attribute>. To deal with this API oversight, stored return values that wouldn't fit into a signed integer are clamped to ‘G_MAXINT’.

iterator
a <pango-attr-iterator>
start
location to store the start of the range
end
location to store the end of the range
— Function: pango-attr-iterator-get (self <pango-attr-iterator>) (type <pango-attr-type>) ⇒  (ret <pango-attribute>)

Find the current attribute of a particular type at the iterator location. When multiple attributes of the same type overlap, the attribute whose range starts closest to the current location is used.

iterator
a <pango-attr-iterator>
type
the type of attribute to find.
ret
the current attribute of the given type, or ‘#f’ if no attribute of that type applies to the current location.
— Function: pango-attr-iterator-get-attrs (self <pango-attr-iterator>) ⇒  (ret gslist-of)

Gets a list of all attributes at the current position of the iterator.

iterator
a <pango-attr-iterator>
ret
a list of all attributes for the current range. To free this value, call pango-attribute-destroy on each value and g-slist-free on the list.

Since 1.2