GtkFontChooser

## GtkFontChooser GtkFontChooser — A widget for selecting fonts |

## Synopsis

    #include <gtk/gtk.h>

    struct              GtkFontChooser;
    GtkWidget *         gtk_font_chooser_new                (void);
    PangoFontFamily *   gtk_font_chooser_get_family         (GtkFontChooser *fontchooser);
    PangoFontFace *     gtk_font_chooser_get_face           (GtkFontChooser *fontchooser);
    gint                gtk_font_chooser_get_size           (GtkFontChooser *fontchooser);
    gchar *             gtk_font_chooser_get_font_name      (GtkFontChooser *fontchooser);
    gboolean            gtk_font_chooser_set_font_name      (GtkFontChooser *fontchooser,
                                                             const gchar *fontname);
    const gchar *       gtk_font_chooser_get_preview_text   (GtkFontChooser *fontchooser);
    void                gtk_font_chooser_set_preview_text   (GtkFontChooser *fontchooser,
                                                             const gchar *text);
    gboolean            gtk_font_chooser_get_show_preview_entry
                                                            (GtkFontChooser *fontchooser);
    void                gtk_font_chooser_set_show_preview_entry
                                                            (GtkFontChooser *fontchooser,
                                                             gboolean show_preview_entry);
    gboolean            (*GtkFontFilterFunc)                (const PangoFontFamily *family,
                                                             const PangoFontFace *face,
                                                             gpointer data);
    void                gtk_font_chooser_set_filter_func    (GtkFontChooser *fontchooser,
                                                             GtkFontFilterFunc filter,
                                                             gpointer data,
                                                             GDestroyNotify destroy);

## Description

The GtkFontChooser widget lists the available fonts, styles and sizes, allowing the user to select a font. It is used in the GtkFontChooserDialog widget to provide a dialog box for selecting fonts.

To set the font which is initially selected, use `gtk_font_chooser_set_font_name()`.

To get the selected font use `gtk_font_chooser_get_font_name()`.

To change the text which is shown in the preview area, use `gtk_font_chooser_set_preview_text()`.

## Details

### struct GtkFontChooser

    struct GtkFontChooser {
      GtkBox parent_instance;
    };

### gtk_font_chooser_new ()

    GtkWidget *         gtk_font_chooser_new                (void);

Creates a new GtkFontChooser.

Returns : | a new GtkFontChooser

Since 3.2

### gtk_font_chooser_get_family ()

    PangoFontFamily *   gtk_font_chooser_get_family         (GtkFontChooser *fontchooser);

Gets the PangoFontFamily representing the selected font family. Font families are a collection of font faces.

`fontchooser` : | a GtkFontChooser
Returns : | A PangoFontFamily representing the selected font family. The returned object is owned by `fontchooser` and must not be modified or freed. [transfer none]

Since 3.2

### gtk_font_chooser_get_face ()

    PangoFontFace *     gtk_font_chooser_get_face           (GtkFontChooser *fontchooser);

Gets the PangoFontFace representing the selected font group details (i.e. family, slant, weight, width, etc).

`fontchooser` : | a GtkFontChooser
Returns : | A PangoFontFace representing the selected font group details. The returned object is owned by `fontchooser` and must not be modified or freed. [transfer none]

Since 3.2

### gtk_font_chooser_get_size ()

    gint                gtk_font_chooser_get_size           (GtkFontChooser *fontchooser);

The selected font size.

`fontchooser` : | a GtkFontChooser
Returns : | A n integer representing the selected font size, or -1 if no font size is selected.

Since 3.2

### gtk_font_chooser_get_font_name ()

    gchar *             gtk_font_chooser_get_font_name      (GtkFontChooser *fontchooser);

Gets the currently-selected font name.

Note that this can be a different string than what you set with `gtk_font_chooser_set_font_name()`, as the font chooser widget may normalize font names and thus return a string with a different structure. For example, "Helvetica Italic Bold 12" could be normalized to "Helvetica Bold Italic 12".

Use `pango_font_description_equal()` if you want to compare two font descriptions.

`fontchooser` : | a GtkFontChooser
Returns : | A string with the name of the current font, or `NULL` if no font is selected. You must free this string with `g_free()`. [transfer full][allow-none]

Since 3.2

### gtk_font_chooser_set_font_name ()

    gboolean            gtk_font_chooser_set_font_name      (GtkFontChooser *fontchooser,
                                                             const gchar *fontname);

Sets the currently-selected font.

`fontchooser` : | a GtkFontChooser
`fontname` : | a font name like "Helvetica 12" or "Times Bold 18"
Returns : | `TRUE` if the font could be set successfully; `FALSE` if no such font exists or if the `fontchooser` doesn't belong to a particular screen yet.

Since 3.2

### gtk_font_chooser_get_preview_text ()

    const gchar *       gtk_font_chooser_get_preview_text   (GtkFontChooser *fontchooser);

Gets the text displayed in the preview area.

`fontchooser` : | a GtkFontChooser
Returns : | the text displayed in the preview area. This string is owned by the widget and should not be modified or freed. [transfer none]

Since 3.2

### gtk_font_chooser_set_preview_text ()

    void                gtk_font_chooser_set_preview_text   (GtkFontChooser *fontchooser,
                                                             const gchar *text);

Sets the text displayed in the preview area. The `text` is used to show how the selected font looks.

`fontchooser` : | a GtkFontChooser
`text` : | the text to display in the preview area. [transfer none]

Since 3.2

### gtk_font_chooser_get_show_preview_entry ()

    gboolean            gtk_font_chooser_get_show_preview_entry
                                                            (GtkFontChooser *fontchooser);

Returns whether the preview entry is shown or not.

`fontchooser` : | a GtkFontChooser
Returns : | `TRUE` if the preview entry is shown or `FALSE` if it is hidden.

Since 3.2

### gtk_font_chooser_set_show_preview_entry ()

    void                gtk_font_chooser_set_show_preview_entry
                                                            (GtkFontChooser *fontchooser,
                                                             gboolean show_preview_entry);

Shows or hides the editable preview entry.

`fontchooser` : | a GtkFontChooser
`show_preview_entry` : | whether to show the editable preview entry or not

Since 3.2

### GtkFontFilterFunc ()

    gboolean            (*GtkFontFilterFunc)                (const PangoFontFamily *family,
                                                             const PangoFontFace *face,
                                                             gpointer data);

The type of function that is used for deciding what fonts get shown in a GtkFontChooser. See `gtk_font_chooser_set_filter_func()`.

`family` : | a PangoFontFamily
`face` : | a PangoFontFace belonging to `family` `data` (closure): user data passed to `gtk_font_chooser_set_filter_func()`
Returns : | `TRUE` if the font should be displayed

### gtk_font_chooser_set_filter_func ()

    void                gtk_font_chooser_set_filter_func    (GtkFontChooser *fontchooser,
                                                             GtkFontFilterFunc filter,
                                                             gpointer data,
                                                             GDestroyNotify destroy);

Adds a filter function that decides which fonts to display in the font chooser.

`fontchooser` : | a GtkFontChooser
`filter` : | a GtkFontFilterFunc, or `NULL`. [allow-none]
`data` : | data to pass to `filter`
`destroy` : | function to call to free `data` when it is no longer needed

Since 3.2

## See Also

GtkFontChooserDialog