CtkFontChooser

CtkFontChooser — Interface implemented by widgets displaying fonts

Functions

Properties

char * font Read / Write
PangoFontDescription * font-desc Read / Write
char * font-features Read
char * language Read / Write
CtkFontChooserLevel level Read / Write
char * preview-text Read / Write
gboolean show-preview-entry Read / Write

Signals

void font-activated Run First

Types and Values

Object Hierarchy

    GInterface
    ╰── CtkFontChooser

Prerequisites

CtkFontChooser requires GObject.

Known Implementations

CtkFontChooser is implemented by CtkFontButton, CtkFontChooserDialog and CtkFontChooserWidget.

Includes

#include <ctk/ctk.h>

Description

CtkFontChooser is an interface that can be implemented by widgets displaying the list of fonts. In CTK+, the main objects that implement this interface are CtkFontChooserWidget, CtkFontChooserDialog and CtkFontButton. The CtkFontChooser interface has been introducted in CTK+ 3.2.

Functions

ctk_font_chooser_get_font_family ()

PangoFontFamily *
ctk_font_chooser_get_font_family (CtkFontChooser *fontchooser);

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

If the selected font is not installed, returns NULL.

Parameters

fontchooser

a CtkFontChooser

 

Returns

A PangoFontFamily representing the selected font family, or NULL. The returned object is owned by fontchooser and must not be modified or freed.

[nullable][transfer none]

Since: 3.2


ctk_font_chooser_get_font_face ()

PangoFontFace *
ctk_font_chooser_get_font_face (CtkFontChooser *fontchooser);

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

If the selected font is not installed, returns NULL.

Parameters

fontchooser

a CtkFontChooser

 

Returns

A PangoFontFace representing the selected font group details, or NULL. The returned object is owned by fontchooser and must not be modified or freed.

[nullable][transfer none]

Since: 3.2


ctk_font_chooser_get_font_size ()

gint
ctk_font_chooser_get_font_size (CtkFontChooser *fontchooser);

The selected font size.

Parameters

fontchooser

a CtkFontChooser

 

Returns

A n integer representing the selected font size, or -1 if no font size is selected.

Since: 3.2


ctk_font_chooser_get_font ()

gchar *
ctk_font_chooser_get_font (CtkFontChooser *fontchooser);

Gets the currently-selected font name.

Note that this can be a different string than what you set with ctk_font_chooser_set_font(), 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.

Parameters

fontchooser

a CtkFontChooser

 

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().

[nullable][transfer full]

Since: 3.2


ctk_font_chooser_set_font ()

void
ctk_font_chooser_set_font (CtkFontChooser *fontchooser,
                           const gchar *fontname);

Sets the currently-selected font.

Parameters

fontchooser

a CtkFontChooser

 

fontname

a font name like “Helvetica 12” or “Times Bold 18”

 

Since: 3.2


ctk_font_chooser_get_font_desc ()

PangoFontDescription *
ctk_font_chooser_get_font_desc (CtkFontChooser *fontchooser);

Gets the currently-selected font.

Note that this can be a different string than what you set with ctk_font_chooser_set_font(), 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.

Parameters

fontchooser

a CtkFontChooser

 

Returns

A PangoFontDescription for the current font, or NULL if no font is selected.

[nullable][transfer full]

Since: 3.2


ctk_font_chooser_set_font_desc ()

void
ctk_font_chooser_set_font_desc (CtkFontChooser *fontchooser,
                                const PangoFontDescription *font_desc);

Sets the currently-selected font from font_desc .

Parameters

fontchooser

a CtkFontChooser

 

font_desc

a PangoFontDescription

 

Since: 3.2


ctk_font_chooser_get_preview_text ()

gchar *
ctk_font_chooser_get_preview_text (CtkFontChooser *fontchooser);

Gets the text displayed in the preview area.

Parameters

fontchooser

a CtkFontChooser

 

Returns

the text displayed in the preview area.

[transfer full]

Since: 3.2


ctk_font_chooser_set_preview_text ()

void
ctk_font_chooser_set_preview_text (CtkFontChooser *fontchooser,
                                   const gchar *text);

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

Parameters

fontchooser

a CtkFontChooser

 

text

the text to display in the preview area.

[transfer none]

Since: 3.2


ctk_font_chooser_get_show_preview_entry ()

gboolean
ctk_font_chooser_get_show_preview_entry
                               (CtkFontChooser *fontchooser);

Returns whether the preview entry is shown or not.

Parameters

fontchooser

a CtkFontChooser

 

Returns

TRUE if the preview entry is shown or FALSE if it is hidden.

Since: 3.2


ctk_font_chooser_set_show_preview_entry ()

void
ctk_font_chooser_set_show_preview_entry
                               (CtkFontChooser *fontchooser,
                                gboolean show_preview_entry);

Shows or hides the editable preview entry.

Parameters

fontchooser

a CtkFontChooser

 

show_preview_entry

whether to show the editable preview entry or not

 

Since: 3.2


CtkFontFilterFunc ()

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

The type of function that is used for deciding what fonts get shown in a CtkFontChooser. See ctk_font_chooser_set_filter_func().

Parameters

family

a PangoFontFamily

 

face

a PangoFontFace belonging to family

 

data

user data passed to ctk_font_chooser_set_filter_func().

[closure]

Returns

TRUE if the font should be displayed


ctk_font_chooser_set_filter_func ()

void
ctk_font_chooser_set_filter_func (CtkFontChooser *fontchooser,
                                  CtkFontFilterFunc filter,
                                  gpointer user_data,
                                  GDestroyNotify destroy);

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

Parameters

fontchooser

a CtkFontChooser

 

filter

a CtkFontFilterFunc, or NULL.

[allow-none]

user_data

data to pass to filter

 

destroy

function to call to free data when it is no longer needed

 

Since: 3.2


ctk_font_chooser_set_font_map ()

void
ctk_font_chooser_set_font_map (CtkFontChooser *fontchooser,
                               PangoFontMap *fontmap);

Sets a custom font map to use for this font chooser widget. A custom font map can be used to present application-specific fonts instead of or in addition to the normal system fonts.

1
2
3
4
5
6
7
8
9
10
FcConfig *config;
PangoFontMap *fontmap;

config = FcInitLoadConfigAndFonts ();
FcConfigAppFontAddFile (config, my_app_font_file);

fontmap = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT);
pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (fontmap), config);

ctk_font_chooser_set_font_map (font_chooser, fontmap);

Note that other CTK+ widgets will only be able to use the application-specific font if it is present in the font map they use:

1
2
context = ctk_widget_get_pango_context (label);
pango_context_set_font_map (context, fontmap);

Parameters

fontchooser

a CtkFontChooser

 

fontmap

a PangoFontMap.

[allow-none]

Since: 3.18


ctk_font_chooser_get_font_map ()

PangoFontMap *
ctk_font_chooser_get_font_map (CtkFontChooser *fontchooser);

Gets the custom font map of this font chooser widget, or NULL if it does not have one.

Parameters

fontchooser

a CtkFontChooser

 

Returns

a PangoFontMap, or NULL.

[nullable][transfer full]

Since: 3.18


ctk_font_chooser_set_level ()

void
ctk_font_chooser_set_level (CtkFontChooser *fontchooser,
                            CtkFontChooserLevel level);

Sets the desired level of granularity for selecting fonts.

Parameters

fontchooser

a CtkFontChooser

 

level

the desired level of granularity

 

Since: 3.24


ctk_font_chooser_get_level ()

CtkFontChooserLevel
ctk_font_chooser_get_level (CtkFontChooser *fontchooser);

Returns the current level of granularity for selecting fonts.

Parameters

fontchooser

a CtkFontChooser

 

Returns

the current granularity level

Since: 3.24


ctk_font_chooser_get_font_features ()

char *
ctk_font_chooser_get_font_features (CtkFontChooser *fontchooser);

Gets the currently-selected font features.

Parameters

fontchooser

a CtkFontChooser

 

Returns

the currently selected font features

Since: 3.24


ctk_font_chooser_set_language ()

void
ctk_font_chooser_set_language (CtkFontChooser *fontchooser,
                               const char *language);

Sets the language to use for font features.

Parameters

fontchooser

a CtkFontChooser

 

language

a language

 

Since: 3.24


ctk_font_chooser_get_language ()

char *
ctk_font_chooser_get_language (CtkFontChooser *fontchooser);

Gets the language that is used for font features.

Parameters

fontchooser

a CtkFontChooser

 

Returns

the currently selected language

Since: 3.24

Types and Values

CtkFontChooser

typedef struct _CtkFontChooser CtkFontChooser;

Property Details

The “font” property

  “font”                     char *

The font description as a string, e.g. "Sans Italic 12".

Owner: CtkFontChooser

Flags: Read / Write

Default value: "Sans 10"


The “font-desc” property

  “font-desc”                PangoFontDescription *

The font description as a PangoFontDescription.

Owner: CtkFontChooser

Flags: Read / Write


The “font-features” property

  “font-features”            char *

The selected font features, in a format that is compatible with CSS and with Pango attributes.

Owner: CtkFontChooser

Flags: Read

Default value: ""

Since: 3.24.1


The “language” property

  “language”                 char *

The language for which the “font-features” were selected, in a format that is compatible with CSS and with Pango attributes.

Owner: CtkFontChooser

Flags: Read / Write

Default value: ""

Since: 3.24.1


The “level” property

  “level”                    CtkFontChooserLevel

The level of granularity to offer for selecting fonts.

Owner: CtkFontChooser

Flags: Read / Write

Default value: CTK_FONT_CHOOSER_LEVEL_STYLE | CTK_FONT_CHOOSER_LEVEL_SIZE

Since: 3.24.1


The “preview-text” property

  “preview-text”             char *

The string with which to preview the font.

Owner: CtkFontChooser

Flags: Read / Write

Default value: "The quick brown fox jumps over the lazy dog."


The “show-preview-entry” property

  “show-preview-entry”       gboolean

Whether to show an entry to change the preview text.

Owner: CtkFontChooser

Flags: Read / Write

Default value: TRUE

Signal Details

The “font-activated” signal

void
user_function (CtkFontChooser *self,
               char           *fontname,
               gpointer        user_data)

Emitted when a font is activated. This usually happens when the user double clicks an item, or an item is selected and the user presses one of the keys Space, Shift+Space, Return or Enter.

Parameters

self

the object which received the signal

 

fontname

the font name

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First

See Also

CtkFontChooserDialog, CtkFontChooserWidget, CtkFontButton