pango.Attribute
Prev | The pango Class Reference | Next

## pango.Attribute

pango.Attribute — an attribute that applies to a section of text

## Synopsis

    class pango.Attribute:
        def copy()

    Functions

        def pango.attr_type_register(name)
        def pango.AttrLanguage(language, start_index=0, end_index=1)
        def pango.AttrFamily(family, start_index=0, end_index=1)
        def pango.AttrForeground(red, green, blue, start_index=0, end_index=1)
        def pango.AttrBackground(red, green, blue, start_index=0, end_index=1)
        def pango.AttrSize(size, start_index=0, end_index=1)
        def pango.AttrStyle(style, start_index=0, end_index=1)
        def pango.AttrWeight(weight, start_index=0, end_index=1)
        def pango.AttrVariant(variant, start_index=0, end_index=1)
        def pango.AttrStretch(stretch, start_index=0, end_index=1)
        def pango.AttrFontDesc(desc, start_index=0, end_index=1)
        def pango.AttrUnderline(underline, start_index=0, end_index=1)
        def pango.AttrStrikethrough(strikethrough, start_index=0, end_index=1)
        def pango.AttrRise(rise, start_index=0, end_index=1)
        def pango.AttrShape(ink_rect, logical_rect, start_index=0, end_index=1)
        def pango.AttrScale(scale, start_index=0, end_index=1)
        def pango.AttrFallback(fallback, start_index=0, end_index=1)
        def pango.AttrSizeAbsolute(size, start_index=0, end_index=1)
        def pango.AttrUnderlineColor(red, green, blue, start_index=0, end_index=1)
        def pango.AttrStrikethroughColor(red, green, blue, start_index=0, end_index=1)
        def pango.AttrLetterSpacing(letter_spacing, start_index=0, end_index=1)

## Attributes

All `pango.Attribute` objects support the following three attributes.

"end_index" | Read-Write | The index of the end of the application of the attribute in the associated text.
"start_index" | Read-Write | The index of the start of the application of the attribute in the associated text.
"type" | Read | The attribute type.

In addition each `pango.Attribute` type supports one or more additional attributes that are specific to the type:

"value" | Read | `ATTR_LANGUAGE` | The `pango.Language`.
"value" | Read | `ATTR_FAMILY` | The string containing the font family name list (e.g. "normal,sans,serif,monospace")
"value" | Read | `ATTR_STYLE` | The font slant style. See the `pango.AttrStyle`() function for more details.
"value" | Read | `ATTR_WEIGHT` | The font weight. See the `pango.AttrWeight`() function for more detail.
"value" | Read | `ATTR_VARIANT` | The font variant. See the `pango.AttrVariant`() function for more detail.
"value" | Read | `ATTR_STRETCH` | The font stretch. See the `pango.AttrStretch`() function for more details.
"value" | Read | `ATTR_SIZE` | The font size in thousandths of a point.
"desc" | Read | `ATTR_FONT_DESC` | The `pango.FontDescription` object.
"color" | Read | `ATTR_FOREGROUND` | The foreground `pango.Color` object.
"color" | Read | `ATTR_BACKGROUND` | The background `pango.Color` object.
"value" | Read | `ATTR_UNDERLINE` | The underline style. See the `pango.AttrUnderline`() function for more details.
"value" | Read | `ATTR_STRIKETHROUGH` | `True` if the text is struck through.
"value" | Read | `ATTR_RISE` | The displacement of the text from the baseline.
"ink_rect" | Read | `ATTR_SHAPE` | The 4-tuple specifying the ink rectangle. See the `pango.AttrShape`() function for more details.
"logical_rect" | Read | `ATTR_SHAPE` | The 4-tuple specifying the logical rectangle. See the `pango.AttrShape`() function for more details.
"value" | Read | `ATTR_SCALE` | The font size scale factor as a float.
"value" | Read | `ATTR_FALLBACK` | `True` if font fallback is enabled.
"value" | Read | `ATTR_LETTER_SPACING` | The extra space between graphemes.
"color" | Read | `ATTR_UNDERLINE_COLOR` | The `pango.Color` object used for the color of the underline.
"color" | Read | `ATTR_STRIKETHROUGH_COLOR` | The `pango.Color` object used for the color of the strikethrough.
"value" | Read | `ATTR_ABSOLUTE_SIZE` | The font size in device units.

## Description

The `pango.Attribute` object contains an attribute that applies to a section of text. The predefined attribute types are:

`pango.ATTR_LANGUAGE` | Specifies a `pango.Language`.
`pango.ATTR_FAMILY` | Specifies a font family name list as a string.
`pango.ATTR_STYLE` | Specifies a font slant style. See the `pango.AttrStyle`() function for more details.
`pango.ATTR_WEIGHT` | Specifies a font weight. See the `pango.AttrWeight`() function for more detail.
`pango.ATTR_VARIANT` | Specifies a font variant (normal or small caps). See the `pango.AttrVariant`() function for more detail.
`pango.ATTR_STRETCH` | Specifies a font stretch. See the `pango.AttrStretch`() function for more details.
`pango.ATTR_SIZE` | Specifies a font size in thousandths of a point.
`pango.ATTR_FONT_DESC` | Specifies a `pango.FontDescription`.
`pango.ATTR_FOREGROUND` | Specifies a foreground `pango.Color`.
`pango.ATTR_BACKGROUND` | Specifies a background `pango.Color`.
`pango.ATTR_UNDERLINE` | Specifies an underline style. See the `pango.AttrUnderline`() function for more details.
`pango.ATTR_STRIKETHROUGH` | If `True` the text is struck through.
`pango.ATTR_RISE` | Specifies the displacement of the text from the baseline.
`pango.ATTR_SHAPE` | Specifies a shape. See the `pango.AttrShape`() function for more details.
`pango.ATTR_SCALE` | Specifies a font size scale factor.
`pango.ATTR_FALLBACK` | if `True`, fallback to other fonts is enabled.
`pango.ATTR_LETTER_SPACING` | Specifies the extra space between graphemes.
`pango.ATTR_UNDERLINE_COLOR` | Specifies the color of the underline.
`pango.ATTR_STRIKETHROUGH_COLOR` | Specifies the color of the strikethrough.
`pango.ATTR_ABSOLUTE_SIZE` | Specifies the font size in device units.

Additional attribute types can be registered with the `pango.attr_type_register`() function.

## Methods

### pango.Attribute.copy

        def copy()

Returns : | a new `pango.Attribute` object

The `copy`() method returns a new `pango.Attribute` object that is a copy of this attribute.

## Functions

### pango.attr_type_register

        def pango.attr_type_register(name)

`name` : | a name for the type. (Currently not used.)
Returns : | the new attribute type ID integer.

The `attr_type_register`() function returns a new attribute type ID integer value.

### pango.AttrLanguage

        def pango.AttrLanguage(language, start_index=0, end_index=1)

`language` : | a `pango.Language` object.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object.

The `AttrLanguage`() function creates a new `pango.Attribute` object of the type `pango.ATTR_LANGUAGE` with the `pango.Language` specified by `language` and the text range specified by `start_index` and `end_index`.

### pango.AttrFamily

        def pango.AttrFamily(family, start_index=0, end_index=1)

`family` : | the string containing a font family name list.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object.

The `AttrFamily`() function creates a new `pango.Attribute` object of the type `pango.ATTR_FAMILY` with the font family name list specified by the string `family` and the text range specified by `start_index` and `end_index`.

### pango.AttrForeground

        def pango.AttrForeground(red, green, blue, start_index=0, end_index=1)

`red` : | the red component of the color in the range 0 to 65535.
`green` : | the green component of the color in the range 0 to 65535.
`blue` : | the blue component of the color in the range 0 to 65535.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object.

The `AttrForeground`() function creates a new `pango.Attribute` of the type `pango.ATTR_FOREGROUND` with the RGB color specified by `red`, `green` and `blue` and the text range specified by `start_index` and `end_index`.

### pango.AttrBackground

        def pango.AttrBackground(red, green, blue, start_index=0, end_index=1)

`red` : | the red component of the color in the range 0 to 65535.
`green` : | the green component of the color in the range 0 to 65535.
`blue` : | the blue component of the color in the range 0 to 65535.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object.

The `AttrBackground`() function creates a new pangoAttribute of the type `pango.ATTR_BACKGROUND` with the RGB color specified by `red`, `green` and `blue` and the text range specified by `start_index` and `end_index`.

### pango.AttrSize

        def pango.AttrSize(size, start_index=0, end_index=1)

`size` : | the font size in thousandths of a point.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object

The `AttrSize`() function creates a new `pango.Attribute` object of the type `pango.ATTR_SIZE` with the font size specified by `size` and the text range specified by `start_index` and `end_index`.

### pango.AttrStyle

        def pango.AttrStyle(style, start_index=0, end_index=1)

`style` : | the font slant style.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object

The `AttrStyle`() function creates a new `pango.Attribute` object of the type `pango.ATTR_STYLE` with the font slant style specified by `style` and the text range specified by `start_index` and `end_index`. The value of `style` must be one of:

`pango.STYLE_NORMAL` | The font is upright.
`pango.STYLE_OBLIQUE` | The font is slanted in a roman style.
`pango.STYLE_ITALIC` | The font is slanted in an italic style.

### pango.AttrWeight

        def pango.AttrWeight(weight, start_index=0, end_index=1)

`weight` : | the font weight.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object

The `AttrWeight`() function creates a new `pango.Attribute` object of the type `pango.ATTR_WEIGHT` with the font weight specified by `weight` and the text range specified by `start_index` and `end_index`. The value of `style` must be one of:

`pango.WEIGHT_ULTRALIGHT` | The ultralight weight (= 200).
`pango.WEIGHT_LIGHT` | The light weight (=300).
`pango.WEIGHT_NORMAL` | The default weight (= 400).
`pango.WEIGHT_BOLD` | The bold weight (= 700).
`pango.WEIGHT_ULTRABOLD` | The ultrabold weight (= 800).
`pango.WEIGHT_HEAVY` | The heavy weight (= 900).

### pango.AttrVariant

        def pango.AttrVariant(variant, start_index=0, end_index=1)

`variant` : | the font variant.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object

The `AttrVariant`() function creates a new `pango.Attribute` object of the type `pango.ATTR_VARIANT` with the font variant specified by `variant` and the text range specified by `start_index` and `end_index`. The value of `variant` must be one of:

`pango.VARIANT_NORMAL` | A normal font.
`pango.VARIANT_SMALL_CAPS` | A font with the lower case characters replaced by smaller variants of the capital characters.

### pango.AttrStretch

        def pango.AttrStretch(stretch, start_index=0, end_index=1)

`stretch` : | the font stretch style.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object

The `AttrStretch`() function creates a new `pango.Attribute` object of the type `pango.ATTR_STRETCH` with the font stretch style specified by `stretch` and the text range specified by `start_index` and `end_index`. The value of `stretch` must be one of:

`pango.STRETCH_ULTRA_CONDENSED` | The most narrow width
`pango.STRETCH_EXTRA_CONDENSED` |
`pango.STRETCH_CONDENSED` |
`pango.STRETCH_SEMI_CONDENSED` |
`pango.STRETCH_NORMAL` | The normal width.
`pango.STRETCH_SEMI_EXPANDED` |
`pango.STRETCH_EXPANDED` |
`pango.STRETCH_EXTRA_EXPANDED` |
`pango.STRETCH_ULTRA_EXPANDED` | The most expanded width

### pango.AttrFontDesc

        def pango.AttrFontDesc(desc, start_index=0, end_index=1)

`desc` : | a `pango.FontDescription` object.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object

The `AttrFontDesc`() function creates a new `pango.Attribute` object of the type `pango.ATTR_FONT_DESC` with the `pango.FontDescription` specified by `desc` and the text range specified by `start_index` and `end_index`.

### pango.AttrUnderline

        def pango.AttrUnderline(underline, start_index=0, end_index=1)

`underline` : | the underline style.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object

The `AttrUnderline`() function creates a new `pango.Attribute` object of the type `pango.ATTR_UNDERLINE` with the underline style specified by `underline` and the text range specified by `start_index` and `end_index`. The value of `underline` must be one of:

`pango.UNDERLINE_NONE` | No underline should be drawn.
`pango.UNDERLINE_SINGLE` | A single underline should be drawn.
`pango.UNDERLINE_DOUBLE` | A double underline should be drawn.
`pango.UNDERLINE_LOW` | A single underline should be drawn at a position beneath the ink extents of the text being underlined. This should be used only for underlining single characters, such as for keyboard accelerators. `pango.UNDERLINE_SINGLE` should be used for extended portions of text.

### pango.AttrStrikethrough

        def pango.AttrStrikethrough(strikethrough, start_index=0, end_index=1)

`strikethrough` : | if `True` the text should be struck through.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object

The `AttrStrikethrough`() function creates a new `pango.Attribute` object of the type `pango.ATTR_STRIKETHROUGH` with the value specified by `strikethrough` and the text range specified by `start_index` and `end_index`. If strikethough is `True` the text should be struck through.

### pango.AttrRise

        def pango.AttrRise(rise, start_index=0, end_index=1)

`rise` : | the displacement of the text from the baseline.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object

The `AttrRise`() function creates a new `pango.Attribute` object of the type `pango.ATTR_RISE` with the text displacement from the baseline specified by `rise` and the text range specified by `start_index` and `end_index`.

### pango.AttrShape

        def pango.AttrShape(ink_rect, logical_rect, start_index=0, end_index=1)

`ink_rect` : | the ink rectangle of the shape.
`logical_rect` : | the logical rectangle of the shape.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object

The `AttrShape`() function creates a new `pango.Attribute` object of the type `pango.ATTR_SHAPE` with the shape rectangles specified by `ink_rect` and `logical_rect` and the text range specified by `start_index` and `end_index`. A shape is used to impose a particular ink and logical rect 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`.

### pango.AttrScale

        def pango.AttrScale(scale, start_index=0, end_index=1)

`scale` : | the font size scale factor as a float.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object

The `AttrScale`() function creates a new `pango.Attribute` object of the type `pango.ATTR_SCALE` with the font size scale factor specified by `scale` and the text range specified by `start_index` and `end_index`. The value of `scale` can also be one of the following pre-defined values:

`pango.SCALE_XX_SMALL` | 0.5787037037037 - the scale factor for three shrinking steps (1 / (1.2 * 1.2 * 1.2)).
`pango.SCALE_X_SMALL` | 0.6444444444444 - the scale factor for two shrinking steps (1 / (1.2 * 1.2)).
`pango.SCALE_SMALL` | 0.8333333333333 - the scale factor for one shrinking step (1 / 1.2).
`pango.SCALE_MEDIUM` | 1.0 - The scale factor for normal size.
`pango.SCALE_LARGE` | 1.2 - the scale factor for one magnification step.
`pango.SCALE_X_LARGE` | 1.4399999999999 - the scale factor for two magnification steps (1.2 * 1.2).
`pango.SCALE_XX_LARGE` | 1.728 - the scale factor for three magnification steps (1.2 * 1.2 * 1.2).

### pango.AttrFallback

        def pango.AttrFallback(fallback, start_index=0, end_index=1)

`fallback` : | if `True`, we should fall back on other fonts for characters the active font is missing.
`start_index` : | the index of the start of the attribute application in the text.
`end_index` : | the index of the end of the attribute application in the text.
Returns : | a new `pango.Attribute` object

### Note

This function is available in PyGTK 2.4 and above.

The `AttrFallback`() function creates a new `pango.Attribute` object of the type `pango.ATTR_FALLBACK`. If fallback is `True` other fonts on the system can be used to provide characters missing from the current font. Otherwise, only characters from the closest matching font can be used.

Prev | Up | Next
The pango Class Reference | Home | pango.AttrIterator