[Contents] [Back] [Prev] [Up] [Next] [Forward]

# Package Pango.Layout

This package provides a high-level object that is capable of arranging text in a visually correct manner. It supports international character sets, although all strings should be Utf8, supports left-to-right and right-to-left writing systems, is capable of handling multi-line texts, and properly aligns tab characters in the text.

This is the base type that is used in the standard gtk+ widget for all the widgets that display some text on the screen.

Since it works directly with Pango.Font.Pango_Font_Description fonts, it is also much better at handling resizing of text, wrapping,... than direct calls to Gdk.Drawable.Draw_Text.

The idea is that this widget is used to compute the layout of the characters (ie their screen position). It doesn't do any rendering, however, and should be used in conjonction with Gdk.Drawable.Draw_Layout to actually display something on the screen.

This widget is independent from any specific drawing systems, and might for instance be used to create postscript documents, for direct access to the win32 API,...

This widget represents one of the fundamental additions to gtk+ 2.0 over what previously existed in the gtk+ 1.x series. It obsoletes the package Gdk.Font, which should only be used for legacy applications.

- Pango.Layout Types
- Pango.Layout Subprograms

## Types

    type Pango_Alignment is
        (Pango_Align_Left,
         Pango_Align_Center,
         Pango_Align_Right);

    type Pango_Layout_Line is new Glib.C_Proxy;

    type Pango_Wrap_Mode is
        (Pango_Wrap_Word,
         Pango_Wrap_Char);

## Subprograms

### Creating a layout

A layout can be created in two ways: either from a widget (Gtk.Widget.Create_Pango_Layout), from which it will inherit the font and various other attributes, or directly from a Pango_Context.

    procedure Gdk_New
      (Layout             : out    Pango_Layout;
       Context            : access Pango.Context.Pango_Context_Record'Class);

| Create a new layout, based on context.

### Contexts

    function Get_Context
      (Layout             : access Pango_Layout_Record)
       return Pango.Context.Pango_Context;

| Return the context of the layout. The returned value is the internal context itself, so you must Glib.Object.Ref it if you need to keep a reference. You shouldn't Unref it.

    procedure Set_Font_Description
      (Layout             : access Pango_Layout_Record;
       Font               :        Pango.Font.Pango_Font_Description);

| Change the font used in the layout. If not font description is set for the layout, the font description from the layout's context is used.

    procedure Context_Changed
      (Layout             : access Pango_Layout_Record);

| Forces recomputation of any state in Layout that might depend on the layout's context. This function should be called if you make changes to the context subsequent to creating the layout.

### Lines

    function Get_Line
      (Layout             : access Pango_Layout_Record;
       Line               :        Natural)
       return Pango_Layout_Line;

| Retrieve a particular line from Layout. Line must be between 0 and Get_Line_Count (Layout) - 1. null is returned if the index is out of range. The layout line can be Ref'ed and retained, but will become invalid if changes are made to Layout.

    procedure Line_Ref
      (Line               :        Pango_Layout_Line);

| Increase the reference count of Line by 1.

    procedure Line_Unref
      (Line               :        Pango_Layout_Line);

| Decrease the reference count of Line by 1. If the result is 0, the line and all associated memory will be destroyed.

    function Line_Index_To_X
      (Line               :        Pango_Layout_Line;
       Index              :        Integer;
       Trailing           :        Integer)
       return Glib.Gint;

| Convert an index within a line to an X position. Index is the byte offset of a graphem within the layout. Trailing is an integer indicating the edge of the grapheme to retrieve the position of. If 0, the trailing edge of the grapheme, otherwise, the leading of the grapheme. The returned value is in pango units.

### Getting the size

Pango internally stores its sizes in pango units, which are a number of pixels (device units, when not drawing on the screen) multiplied by Pango_Scale. There are generally equivalent subprograms to get the sizes directly in pixels.

    procedure Get_Extents
      (Layout             : access Pango_Layout_Record;
       Ink_Rect           : out    Gdk.Rectangle.Gdk_Rectangle;
       Logical_Rect       : out    Gdk.Rectangle.Gdk_Rectangle);

| Compute the logical and ink extents of Layout. Logical extents are usually what you want for positioning things. The extents are given in pango units; layout coordinates begin at the top left corner of the layout. Logical_Rect is the overall size of the layout, ie it includes Ink_Rect (where the text is actually drawn) and a small border around it.

    procedure Get_Size
      (Layout             : access Pango_Layout_Record;
       Width              : out    Glib.Gint;
       Height             : out    Glib.Gint);

| Return the logical size, in pango units, of the layout. This is a convenience function around Get_Extents.

    procedure Get_Pixel_Extents
      (Layout             : access Pango_Layout_Record;
       Ink_Rect           : out    Gdk.Rectangle.Gdk_Rectangle;
       Logical_Rect       : out    Gdk.Rectangle.Gdk_Rectangle);

| Same as Get_Extents, but the returned values are in pixels (or device units when not drawing on the screen).

    procedure Get_Pixel_Size
      (Layout             : access Pango_Layout_Record;
       Width              : out    Glib.Gint;
       Height             : out    Glib.Gint);

| Same as Get_Size, but the returned values are in pixels.

    procedure XY_To_Index
      (Layout             : access Pango_Layout_Record;
       X_Pango, Y_Pango   :        Glib.Gint;
       Byte_Index         : out    Integer;
       Trailing           : out    Integer;
       Exact              : out    Boolean);

Convert from X and Y positions within a layout to the byte index of the
character at that logical position. X and Y are given in pango units, not pixels. If the position is not inside the layout, the closest position is chosen, and Exact is set to False. Trailing is the position in the grapheme where the user clicked. It will either be 0 (left side) or the number of characters in the grapheme. In some character sets, a given character can be represented by multiple signs on the screen, which is what Trailing relates to.

### Manipulating the text

When initially created with Gtk.Widget.Create_Pango_Layout, the layout contains some text. Of course, this text may also be changed later in the life of the layout.

    procedure Set_Text
      (Layout             : access Pango_Layout_Record;
       Text               :        String);

| Change the text that the layout displays Text must be a valid UTF8 string. See Glib.Convert for useful conversion functions.

    function Get_Text
      (Layout             : access Pango_Layout_Record)
       return String;

| Return the text currently displayed in the layout. It is more efficient to use the iterators on the layout than get text if you do not need Ada-specific subprograms to act on the text.

    function Get_Text
      (Layout             : access Pango_Layout_Record)
       return Gtkada.Types.Chars_Ptr;

| Same a Get_Text, but return directly the C string, which is more efficient. The returned value should not be freed or modified.

    function Get_Line_Count
      (Layout             : access Pango_Layout_Record)
       return Glib.Gint;

| Return the number of lines in Layout

    procedure Set_Markup
      (Layout             : access Pango_Layout_Record;
       Markup             :        Glib.UTF8_String);

| Change the text that layout displays. Markup must be a valid UTF8 String, and might contain markups as defined in the pango markup language.

### Layouting the text

    procedure Set_Justify
      (Layout             : access Pango_Layout_Record;
       Justify            :        Boolean);

| Set 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.

    function Get_Justify
      (Layout             : access Pango_Layout_Record)
       return Boolean;

| Return True if each complete line should be stretched to fill the entire width of the layout.

    procedure Set_Alignment
      (Layout             : access Pango_Layout_Record'Class;
       Alignment          :        Pango_Alignment);

| Set the alignment for the layout (how partial lines are positioned within the horizontal space available).

    function Get_Alignment
      (Layout             : access Pango_Layout_Record)
       return Pango_Alignment;

| Return the alignment for the layout.

    procedure Set_Width
      (Layout             : access Pango_Layout_Record;
       Width              :        Glib.Gint);

| Set the width to which the lines of Layout should be wrapped. No wrapping will be performed if Width is -1. Width is given in pango units.

    function Get_Width
      (Layout             : access Pango_Layout_Record)
       return Glib.Gint;

| Return the wrapping width of Layout

    procedure Set_Wrap
      (Layout             : access Pango_Layout_Record;
       Mode               :        Pango_Wrap_Mode);

| Sets the wrap style; the wrap style only has an effect if a width is set on the layout with pango_layout_set_width(). To turn off wrapping, set the width to -1.

    function Get_Wrap
      (Layout             : access Pango_Layout_Record)
       return Pango_Wrap_Mode;

| Return the current wrap style

### Attributes

    procedure Set_Attributes
      (Layout             : access Pango_Layout_Record;
       Attributes         :        Pango.Attributes.Pango_Attr_List);

| Set the text attributes for a layout object. Passing null removes the current list of attributes

    function Get_Attributes
      (Layout             : access Pango_Layout_Record)
       return Pango.Attributes.Pango_Attr_List;

| Get the text attributes from a layout object

[Contents] [Back] [Prev] [Up] [Next] [Forward]