2.8 <PangoAttrList>

Structure: <PangoAttrList>

A <PangoAttrList> represents a list of attributes that apply to a section of text.

The attributes in a <PangoAttrList> are, in general, allowed to overlap in an arbitrary fashion. However, if the attributes are manipulated only through attr-list:change, the overlap between properties will meet stricter criteria.

Since the <PangoAttrList> structure is stored as a linear list, it is not suitable for storing attributes for large amounts of text. In general, you should not use a single <PangoAttrList> for more than one paragraph of text.

Procedures

Method: attr-list:change self attr
Method: change self attr

Insert the given attribute into the <PangoAttrList>.

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 attr-list:insert for creating an attribute list in order (potentially much slower for large lists). However, attr-list:insert is not suitable for continually changing a set of attributes since it never removes or combines existing attributes.

self

Passed: a <PangoAttrList>.

a <PangoAttrList>

attr

Passed: a <PangoAttribute>.

the attribute to insert

Method: attr-list:copy self ⇒ %return
Method: copy self ⇒ %return

Copy self and return an identical new list.

self

Passed: a <PangoAttrList>.

a <PangoAttrList>

%return

Returned: a <PangoAttrList>, or #f.

the newly allocated <PangoAttrList>, with a reference count of one, which should be freed with attr-list:unref. Returns #f if self was #f.

Method: attr-list:equal? self other-list ⇒ %return
Method: equal? self other-list ⇒ %return

Checks whether self and other-list contain the same attributes and whether those attributes apply to the same ranges.

Beware that this will return wrong values if any list contains duplicates.

self

Passed: a <PangoAttrList>.

a <PangoAttrList>

other-list

Passed: a <PangoAttrList>.

the other <PangoAttrList>

%return

Returned: a boolean.

#t if the lists are equal, #f if they aren’t

Method: attr-list:filter self func ⇒ %return
Method: filter self func ⇒ %return

Given a <PangoAttrList> and callback function, removes any elements of self for which func returns #t and inserts them into a new list.

self

Passed: a <PangoAttrList>.

a <PangoAttrList>

func

Passed: a procedure.

callback function; returns #t if an attribute should be filtered out

See PangoAttrFilterFunc for how it is called.

%return

Returned: a <PangoAttrList>, or #f.

the new <PangoAttrList> or #f if no attributes of the given types were found

data

Not passed: guile-gi supplies it.

Data to be passed to func

Procedure: attr-list:from-string text ⇒ %return

Deserializes a <PangoAttrList> from a string.

This is the counterpart to attr-list:to-string. See that functions for details about the format.

text

Passed: a string.

a string

%return

Returned: a <PangoAttrList>, or #f.

a new <PangoAttrList>

Method: attr-list:get-attributes self ⇒ %return
Method: get-attributes self ⇒ %return

Gets a list of all attributes in self.

self

Passed: a <PangoAttrList>.

a <PangoAttrList>

%return

Returned: a list, each a <PangoAttribute>.

a list of all attributes in self. To free this value, call attribute:destroy on each value and g_slist_free() on the list.

Method: attr-list:get-iterator self ⇒ %return
Method: get-iterator self ⇒ %return

Create a iterator initialized to the beginning of the list.

self must not be modified until this iterator is freed.

self

Passed: a <PangoAttrList>.

a <PangoAttrList>

%return

Returned: a <PangoAttrIterator>.

the newly allocated <PangoAttrIterator>, which should be freed with attr-iterator:destroy

Method: attr-list:insert self attr
Method: insert self attr

Insert the given attribute into the <PangoAttrList>.

It will be inserted after all other attributes with a matching start-index.

self

Passed: a <PangoAttrList>.

a <PangoAttrList>

attr

Passed: a <PangoAttribute>.

the attribute to insert

Method: attr-list:insert-before self attr
Method: insert-before self attr

Insert the given attribute into the <PangoAttrList>.

It will be inserted before all other attributes with a matching start-index.

self

Passed: a <PangoAttrList>.

a <PangoAttrList>

attr

Passed: a <PangoAttribute>.

the attribute to insert

Procedure: attr-list:new ⇒ %return

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

%return

Returned: a <PangoAttrList>.

the newly allocated <PangoAttrList>, which should be freed with attr-list:unref

Method: attr-list:ref self ⇒ %return
Method: ref self ⇒ %return

Increase the reference count of the given attribute list by one.

self

Passed: a <PangoAttrList>.

a <PangoAttrList>

%return

Returned: a <PangoAttrList>.

The attribute list passed in

Method: attr-list:splice self other pos len
Method: splice self other pos len

This function opens up a hole in self, 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 self by an amount len, and then calling attr-list:change with a copy of each attribute in other in sequence (offset in position by pos, and limited in length to len).

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

For backwards compatibility, the function behaves differently when len is 0. In this case, the attributes from other are not imited to len, and are just overlayed on top of self.

This mode is useful for merging two lists of attributes together.

self

Passed: a <PangoAttrList>.

a <PangoAttrList>

other

Passed: a <PangoAttrList>.

another <PangoAttrList>

pos

Passed: a 32-bit integer.

the position in self at which to insert other

len

Passed: a 32-bit integer.

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)

Method: attr-list:to-string self ⇒ %return
Method: to-string self ⇒ %return

Serializes a <PangoAttrList> to a string.

In the resulting string, serialized attributes are separated by newlines or commas. Individual attributes are serialized to a string of the form

[START END] TYPE VALUE

Where START and END are the indices (with -1 being accepted in place of MAXUINT), TYPE is the nickname of the attribute value type, e.g. _weight_ or _stretch_, and the value is serialized according to its type:

Optionally, START and END can be omitted to indicate unlimited extent.

  • enum values as nick or numeric value
  • boolean values as _true_ or _false_
  • integers and floats as numbers
  • strings as string, optionally quoted
  • font features as quoted string
  • PangoLanguage as string
  • PangoFontDescription as serialized by font-description:to-string, quoted
  • PangoColor as serialized by color:to-string

Examples:

0 10 foreground red, 5 15 weight bold, 0 200 font-desc "Sans 10"

0 -1 weight 700 0 100 family Times

weight bold

To parse the returned value, use attr-list:from-string.

Note that shape attributes can not be serialized.

self

Passed: a <PangoAttrList>.

a <PangoAttrList>

%return

Returned: a string.

a newly allocated string

Method: attr-list:unref self
Method: unref self

Decrease the reference count of the given attribute list by one.

If the result is zero, free the attribute list and the attributes it contains.

self

Passed: a <PangoAttrList>.

a <PangoAttrList>

Method: attr-list:update self pos remove add
Method: update self pos remove add

Update indices of attributes in self for a change in the text they refer to.

The change that this function applies is removing remove bytes at position pos and inserting add bytes instead.

Attributes that fall entirely in the (pos, pos + remove) range are removed.

Attributes that start or end inside the (pos, pos + remove) range are shortened to reflect the removal.

Attributes start and end positions are updated if they are behind pos + remove.

self

Passed: a <PangoAttrList>.

a <PangoAttrList>

pos

Passed: a 32-bit integer.

the position of the change

remove

Passed: a 32-bit integer.

the number of removed bytes

add

Passed: a 32-bit integer.

the number of added bytes