2003-07-01 19:52:07 +00:00
|
|
|
/*
|
2008-07-01 22:57:50 +00:00
|
|
|
* GTK - The GIMP Toolkit
|
2003-07-01 19:52:07 +00:00
|
|
|
* Copyright (C) 1998 David Abilleira Freijeiro <odaf@nexo.es>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Based on gnome-color-picker by Federico Mena <federico@nuclecu.unam.mx>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Modified by the GTK+ Team and others 2003. See the AUTHORS
|
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
#include "gtkfontbutton.h"
|
|
|
|
|
2019-09-13 09:53:24 +00:00
|
|
|
#include "gtkbinlayout.h"
|
2011-08-28 05:54:55 +00:00
|
|
|
#include "gtkbox.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
#include "gtkcssprovider.h"
|
2011-09-11 23:49:26 +00:00
|
|
|
#include "gtkfontchooser.h"
|
2011-07-27 23:22:22 +00:00
|
|
|
#include "gtkfontchooserdialog.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
#include "gtkfontchooserutils.h"
|
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtklabel.h"
|
2003-07-01 19:52:07 +00:00
|
|
|
#include "gtkmarshalers.h"
|
2005-03-22 02:14:55 +00:00
|
|
|
#include "gtkprivate.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
#include "gtkseparator.h"
|
|
|
|
#include "gtkstylecontext.h"
|
2020-04-08 11:43:28 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2003-09-30 22:48:10 +00:00
|
|
|
|
2011-04-11 01:47:43 +00:00
|
|
|
/**
|
2021-02-22 00:42:45 +00:00
|
|
|
* GtkFontButton:
|
|
|
|
*
|
|
|
|
* The `GtkFontButton` allows to open a font chooser dialog to change
|
|
|
|
* the font.
|
|
|
|
*
|
|
|
|
* ![An example GtkFontButton](font-button.png)
|
2011-04-11 01:47:43 +00:00
|
|
|
*
|
|
|
|
* It is suitable widget for selecting a font in a preference dialog.
|
2015-10-30 21:09:59 +00:00
|
|
|
*
|
|
|
|
* # CSS nodes
|
|
|
|
*
|
2020-12-23 13:57:04 +00:00
|
|
|
* |[<!-- language="plain" -->
|
|
|
|
* fontbutton
|
|
|
|
* ╰── button.font
|
|
|
|
* ╰── [content]
|
|
|
|
*]|
|
|
|
|
*
|
2021-02-22 00:42:45 +00:00
|
|
|
* `GtkFontButton` has a single CSS node with name fontbutton which
|
2020-12-23 13:57:04 +00:00
|
|
|
* contains a button node with the .font style class.
|
2011-04-11 01:47:43 +00:00
|
|
|
*/
|
|
|
|
|
2019-05-28 00:55:28 +00:00
|
|
|
typedef struct _GtkFontButtonClass GtkFontButtonClass;
|
|
|
|
|
|
|
|
struct _GtkFontButton
|
|
|
|
{
|
|
|
|
GtkWidget parent_instance;
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
char *title;
|
|
|
|
char *fontname;
|
2015-05-05 03:21:17 +00:00
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
guint use_font : 1;
|
|
|
|
guint use_size : 1;
|
2011-09-05 12:10:20 +00:00
|
|
|
guint show_preview_entry : 1;
|
2020-04-13 04:28:34 +00:00
|
|
|
guint modal : 1;
|
2015-05-05 03:21:17 +00:00
|
|
|
|
2020-07-25 02:57:34 +00:00
|
|
|
GtkFontChooserLevel level;
|
|
|
|
|
2017-01-19 19:15:43 +00:00
|
|
|
GtkWidget *button;
|
2003-07-01 19:52:07 +00:00
|
|
|
GtkWidget *font_dialog;
|
|
|
|
GtkWidget *font_label;
|
|
|
|
GtkWidget *size_label;
|
2013-03-30 08:35:54 +00:00
|
|
|
GtkWidget *font_size_box;
|
2011-09-05 12:10:20 +00:00
|
|
|
|
2020-07-25 02:57:34 +00:00
|
|
|
int font_size;
|
2011-09-11 22:13:26 +00:00
|
|
|
PangoFontDescription *font_desc;
|
|
|
|
PangoFontFamily *font_family;
|
|
|
|
PangoFontFace *font_face;
|
2015-05-05 03:21:17 +00:00
|
|
|
PangoFontMap *font_map;
|
2018-01-03 04:52:24 +00:00
|
|
|
char *font_features;
|
2018-04-02 17:34:22 +00:00
|
|
|
PangoLanguage *language;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *preview_text;
|
2011-09-11 22:13:26 +00:00
|
|
|
GtkFontFilterFunc font_filter;
|
|
|
|
gpointer font_filter_data;
|
|
|
|
GDestroyNotify font_filter_data_destroy;
|
2014-10-02 04:05:43 +00:00
|
|
|
GtkCssProvider *provider;
|
2020-04-13 04:32:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkFontButtonClass
|
|
|
|
{
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
|
|
|
|
void (* font_set) (GtkFontButton *gfp);
|
|
|
|
};
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/* Signals */
|
2015-05-05 03:21:17 +00:00
|
|
|
enum
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
|
|
|
FONT_SET,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_TITLE,
|
2020-04-13 04:28:34 +00:00
|
|
|
PROP_MODAL,
|
2003-07-01 19:52:07 +00:00
|
|
|
PROP_USE_FONT,
|
2017-12-21 16:58:20 +00:00
|
|
|
PROP_USE_SIZE
|
2003-07-01 19:52:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Prototypes */
|
|
|
|
static void gtk_font_button_finalize (GObject *object);
|
|
|
|
static void gtk_font_button_get_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_font_button_set_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
2017-01-19 19:15:43 +00:00
|
|
|
static void gtk_font_button_clicked (GtkButton *button,
|
|
|
|
gpointer user_data);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/* Dialog response functions */
|
2011-07-27 23:22:22 +00:00
|
|
|
static void response_cb (GtkDialog *dialog,
|
2020-07-24 13:54:49 +00:00
|
|
|
int response_id,
|
2003-07-01 19:52:07 +00:00
|
|
|
gpointer data);
|
|
|
|
static void dialog_destroy (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
/* Auxiliary functions */
|
|
|
|
static void gtk_font_button_label_use_font (GtkFontButton *gfs);
|
|
|
|
static void gtk_font_button_update_font_info (GtkFontButton *gfs);
|
|
|
|
|
2017-12-21 16:10:44 +00:00
|
|
|
static void gtk_font_button_set_font_name (GtkFontButton *button,
|
|
|
|
const char *fontname);
|
|
|
|
static const char *gtk_font_button_get_font_name (GtkFontButton *button);
|
2017-12-21 15:51:04 +00:00
|
|
|
static void gtk_font_button_set_level (GtkFontButton *font_button,
|
|
|
|
GtkFontChooserLevel level);
|
2018-04-02 17:34:22 +00:00
|
|
|
static void gtk_font_button_set_language (GtkFontButton *button,
|
|
|
|
const char *language);
|
2017-12-21 16:10:44 +00:00
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
static guint font_button_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2018-06-18 11:11:06 +00:00
|
|
|
static PangoFontFamily * gtk_font_button_font_chooser_get_font_family (GtkFontChooser *chooser);
|
|
|
|
static PangoFontFace * gtk_font_button_font_chooser_get_font_face (GtkFontChooser *chooser);
|
|
|
|
static int gtk_font_button_font_chooser_get_font_size (GtkFontChooser *chooser);
|
|
|
|
static void gtk_font_button_font_chooser_set_filter_func (GtkFontChooser *chooser,
|
|
|
|
GtkFontFilterFunc filter_func,
|
|
|
|
gpointer filter_data,
|
|
|
|
GDestroyNotify data_destroy);
|
|
|
|
static void gtk_font_button_font_chooser_set_font_map (GtkFontChooser *chooser,
|
|
|
|
PangoFontMap *font_map);
|
|
|
|
static PangoFontMap * gtk_font_button_font_chooser_get_font_map (GtkFontChooser *chooser);
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_button_font_chooser_iface_init (GtkFontChooserIface *iface)
|
|
|
|
{
|
|
|
|
iface->get_font_family = gtk_font_button_font_chooser_get_font_family;
|
|
|
|
iface->get_font_face = gtk_font_button_font_chooser_get_font_face;
|
|
|
|
iface->get_font_size = gtk_font_button_font_chooser_get_font_size;
|
|
|
|
iface->set_filter_func = gtk_font_button_font_chooser_set_filter_func;
|
|
|
|
iface->set_font_map = gtk_font_button_font_chooser_set_font_map;
|
|
|
|
iface->get_font_map = gtk_font_button_font_chooser_get_font_map;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkFontButton, gtk_font_button, GTK_TYPE_WIDGET,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_FONT_CHOOSER,
|
|
|
|
gtk_font_button_font_chooser_iface_init))
|
|
|
|
|
2011-09-11 23:18:58 +00:00
|
|
|
static void
|
|
|
|
clear_font_data (GtkFontButton *font_button)
|
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
g_clear_object (&font_button->font_family);
|
|
|
|
g_clear_object (&font_button->font_face);
|
|
|
|
g_clear_pointer (&font_button->font_desc, pango_font_description_free);
|
|
|
|
g_clear_pointer (&font_button->fontname, g_free);
|
|
|
|
g_clear_pointer (&font_button->font_features, g_free);
|
2011-09-11 23:18:58 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 12:10:20 +00:00
|
|
|
static void
|
|
|
|
clear_font_filter_data (GtkFontButton *font_button)
|
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_filter_data_destroy)
|
|
|
|
font_button->font_filter_data_destroy (font_button->font_filter_data);
|
|
|
|
font_button->font_filter = NULL;
|
|
|
|
font_button->font_filter_data = NULL;
|
|
|
|
font_button->font_filter_data_destroy = NULL;
|
2011-09-05 12:10:20 +00:00
|
|
|
}
|
|
|
|
|
2011-09-11 23:18:58 +00:00
|
|
|
static gboolean
|
|
|
|
font_description_style_equal (const PangoFontDescription *a,
|
|
|
|
const PangoFontDescription *b)
|
|
|
|
{
|
|
|
|
return (pango_font_description_get_weight (a) == pango_font_description_get_weight (b) &&
|
|
|
|
pango_font_description_get_style (a) == pango_font_description_get_style (b) &&
|
|
|
|
pango_font_description_get_stretch (a) == pango_font_description_get_stretch (b) &&
|
|
|
|
pango_font_description_get_variant (a) == pango_font_description_get_variant (b));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_button_update_font_data (GtkFontButton *font_button)
|
|
|
|
{
|
|
|
|
PangoFontFamily **families;
|
|
|
|
PangoFontFace **faces;
|
2020-07-24 13:54:49 +00:00
|
|
|
int n_families, n_faces, i;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *family;
|
2011-09-11 23:18:58 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
g_assert (font_button->font_desc != NULL);
|
2011-09-11 23:18:58 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->fontname = pango_font_description_to_string (font_button->font_desc);
|
2011-09-11 23:18:58 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
family = pango_font_description_get_family (font_button->font_desc);
|
2011-09-11 23:18:58 +00:00
|
|
|
if (family == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
n_families = 0;
|
|
|
|
families = NULL;
|
|
|
|
pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (font_button)),
|
|
|
|
&families, &n_families);
|
|
|
|
n_faces = 0;
|
|
|
|
faces = NULL;
|
|
|
|
for (i = 0; i < n_families; i++)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name = pango_font_family_get_name (families[i]);
|
2011-09-11 23:18:58 +00:00
|
|
|
|
|
|
|
if (!g_ascii_strcasecmp (name, family))
|
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->font_family = g_object_ref (families[i]);
|
2011-09-11 23:18:58 +00:00
|
|
|
|
|
|
|
pango_font_family_list_faces (families[i], &faces, &n_faces);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free (families);
|
|
|
|
|
|
|
|
for (i = 0; i < n_faces; i++)
|
|
|
|
{
|
|
|
|
PangoFontDescription *tmp_desc = pango_font_face_describe (faces[i]);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_description_style_equal (tmp_desc, font_button->font_desc))
|
2011-09-11 23:18:58 +00:00
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->font_face = g_object_ref (faces[i]);
|
2011-09-11 23:18:58 +00:00
|
|
|
|
|
|
|
pango_font_description_free (tmp_desc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pango_font_description_free (tmp_desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (faces);
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
static char *
|
2011-09-05 12:10:20 +00:00
|
|
|
gtk_font_button_get_preview_text (GtkFontButton *font_button)
|
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_dialog)
|
|
|
|
return gtk_font_chooser_get_preview_text (GTK_FONT_CHOOSER (font_button->font_dialog));
|
2011-09-05 12:10:20 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
return g_strdup (font_button->preview_text);
|
2011-09-05 12:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_button_set_preview_text (GtkFontButton *font_button,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *preview_text)
|
2011-09-05 12:10:20 +00:00
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_dialog)
|
2011-09-05 12:10:20 +00:00
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
gtk_font_chooser_set_preview_text (GTK_FONT_CHOOSER (font_button->font_dialog),
|
2011-09-05 12:10:20 +00:00
|
|
|
preview_text);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
g_free (font_button->preview_text);
|
|
|
|
font_button->preview_text = g_strdup (preview_text);
|
2011-09-05 12:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_font_button_get_show_preview_entry (GtkFontButton *font_button)
|
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_dialog)
|
|
|
|
return gtk_font_chooser_get_show_preview_entry (GTK_FONT_CHOOSER (font_button->font_dialog));
|
2011-09-05 12:10:20 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
return font_button->show_preview_entry;
|
2011-09-05 12:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_button_set_show_preview_entry (GtkFontButton *font_button,
|
|
|
|
gboolean show)
|
|
|
|
{
|
2014-06-08 15:57:47 +00:00
|
|
|
show = show != FALSE;
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->show_preview_entry != show)
|
2014-06-08 15:57:47 +00:00
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->show_preview_entry = show;
|
|
|
|
if (font_button->font_dialog)
|
|
|
|
gtk_font_chooser_set_show_preview_entry (GTK_FONT_CHOOSER (font_button->font_dialog), show);
|
2014-06-08 15:57:47 +00:00
|
|
|
g_object_notify (G_OBJECT (font_button), "show-preview-entry");
|
|
|
|
}
|
2011-09-05 12:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PangoFontFamily *
|
|
|
|
gtk_font_button_font_chooser_get_font_family (GtkFontChooser *chooser)
|
|
|
|
{
|
|
|
|
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
return font_button->font_family;
|
2011-09-05 12:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PangoFontFace *
|
|
|
|
gtk_font_button_font_chooser_get_font_face (GtkFontChooser *chooser)
|
|
|
|
{
|
|
|
|
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
return font_button->font_face;
|
2011-09-05 12:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gtk_font_button_font_chooser_get_font_size (GtkFontChooser *chooser)
|
|
|
|
{
|
|
|
|
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
return font_button->font_size;
|
2011-09-05 12:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_button_font_chooser_set_filter_func (GtkFontChooser *chooser,
|
|
|
|
GtkFontFilterFunc filter_func,
|
|
|
|
gpointer filter_data,
|
|
|
|
GDestroyNotify data_destroy)
|
|
|
|
{
|
|
|
|
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_dialog)
|
2011-09-05 12:10:20 +00:00
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
gtk_font_chooser_set_filter_func (GTK_FONT_CHOOSER (font_button->font_dialog),
|
2011-09-05 12:10:20 +00:00
|
|
|
filter_func,
|
|
|
|
filter_data,
|
|
|
|
data_destroy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear_font_filter_data (font_button);
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->font_filter = filter_func;
|
|
|
|
font_button->font_filter_data = filter_data;
|
|
|
|
font_button->font_filter_data_destroy = data_destroy;
|
2011-09-05 12:10:20 +00:00
|
|
|
}
|
|
|
|
|
2011-09-11 22:13:26 +00:00
|
|
|
static void
|
|
|
|
gtk_font_button_take_font_desc (GtkFontButton *font_button,
|
|
|
|
PangoFontDescription *font_desc)
|
|
|
|
{
|
|
|
|
GObject *object = G_OBJECT (font_button);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_desc && font_desc &&
|
|
|
|
pango_font_description_equal (font_button->font_desc, font_desc))
|
2011-09-11 22:13:26 +00:00
|
|
|
{
|
|
|
|
pango_font_description_free (font_desc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_freeze_notify (object);
|
|
|
|
|
2011-09-11 23:18:58 +00:00
|
|
|
clear_font_data (font_button);
|
|
|
|
|
2011-09-11 22:13:26 +00:00
|
|
|
if (font_desc)
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->font_desc = font_desc; /* adopted */
|
2011-09-11 22:13:26 +00:00
|
|
|
else
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->font_desc = pango_font_description_from_string (_("Sans 12"));
|
2011-09-11 22:13:26 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (pango_font_description_get_size_is_absolute (font_button->font_desc))
|
|
|
|
font_button->font_size = pango_font_description_get_size (font_button->font_desc);
|
2015-05-05 03:21:17 +00:00
|
|
|
else
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->font_size = pango_font_description_get_size (font_button->font_desc) / PANGO_SCALE;
|
2011-09-12 19:26:21 +00:00
|
|
|
|
2011-09-11 23:18:58 +00:00
|
|
|
gtk_font_button_update_font_data (font_button);
|
2011-09-11 22:13:26 +00:00
|
|
|
gtk_font_button_update_font_info (font_button);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_dialog)
|
|
|
|
gtk_font_chooser_set_font_desc (GTK_FONT_CHOOSER (font_button->font_dialog),
|
|
|
|
font_button->font_desc);
|
2011-09-11 22:13:26 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (font_button), "font");
|
|
|
|
g_object_notify (G_OBJECT (font_button), "font-desc");
|
|
|
|
|
|
|
|
g_object_thaw_notify (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const PangoFontDescription *
|
|
|
|
gtk_font_button_get_font_desc (GtkFontButton *font_button)
|
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
return font_button->font_desc;
|
2011-09-11 22:13:26 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 03:21:17 +00:00
|
|
|
static void
|
2015-06-13 03:55:30 +00:00
|
|
|
gtk_font_button_font_chooser_set_font_map (GtkFontChooser *chooser,
|
|
|
|
PangoFontMap *font_map)
|
2015-05-05 03:21:17 +00:00
|
|
|
{
|
2015-06-13 03:55:30 +00:00
|
|
|
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (g_set_object (&font_button->font_map, font_map))
|
2015-05-05 03:21:17 +00:00
|
|
|
{
|
|
|
|
PangoContext *context;
|
|
|
|
|
|
|
|
if (!font_map)
|
|
|
|
font_map = pango_cairo_font_map_get_default ();
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
context = gtk_widget_get_pango_context (font_button->font_label);
|
2015-05-05 03:21:17 +00:00
|
|
|
pango_context_set_font_map (context, font_map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-13 03:55:30 +00:00
|
|
|
static PangoFontMap *
|
|
|
|
gtk_font_button_font_chooser_get_font_map (GtkFontChooser *chooser)
|
|
|
|
{
|
|
|
|
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
return font_button->font_map;
|
2015-06-13 03:55:30 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 12:10:20 +00:00
|
|
|
static void
|
|
|
|
gtk_font_button_font_chooser_notify (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
/* We do not forward the notification of the "font" property to the dialog! */
|
|
|
|
if (pspec->name == I_("preview-text") ||
|
|
|
|
pspec->name == I_("show-preview-entry"))
|
|
|
|
g_object_notify_by_pspec (user_data, pspec);
|
|
|
|
}
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
static void
|
|
|
|
gtk_font_button_class_init (GtkFontButtonClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2013-03-30 08:35:54 +00:00
|
|
|
GtkWidgetClass *widget_class;
|
2019-09-13 09:53:24 +00:00
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
2013-03-30 08:35:54 +00:00
|
|
|
widget_class = (GtkWidgetClass *) klass;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
gobject_class->finalize = gtk_font_button_finalize;
|
|
|
|
gobject_class->set_property = gtk_font_button_set_property;
|
|
|
|
gobject_class->get_property = gtk_font_button_get_property;
|
2017-01-19 19:15:43 +00:00
|
|
|
|
2020-04-08 11:43:28 +00:00
|
|
|
widget_class->grab_focus = gtk_widget_grab_focus_child;
|
|
|
|
widget_class->focus = gtk_widget_focus_child;
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
klass->font_set = NULL;
|
|
|
|
|
2011-09-05 12:10:20 +00:00
|
|
|
_gtk_font_chooser_install_properties (gobject_class);
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
/**
|
2021-02-25 23:21:38 +00:00
|
|
|
* GtkFontButton:title: (attributes org.gtk.Property.get=gtk_font_button_get_title org.gtk.Property.set=gtk_font_button_set_title)
|
2021-02-22 00:42:45 +00:00
|
|
|
*
|
2011-07-27 23:22:22 +00:00
|
|
|
* The title of the font chooser dialog.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_TITLE,
|
|
|
|
g_param_spec_string ("title",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Title"),
|
2011-07-27 23:22:22 +00:00
|
|
|
P_("The title of the font chooser dialog"),
|
2003-11-05 23:23:05 +00:00
|
|
|
_("Pick a Font"),
|
2014-06-08 15:59:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-25 23:21:38 +00:00
|
|
|
* GtkFontButton:use-font: (attributes org.gtk.Property.get=gtk_font_button_get_use_font org.gtk.Property.set=gtk_font_button_set_use_font)
|
2021-02-22 00:42:45 +00:00
|
|
|
*
|
|
|
|
* Whether the buttons label will be drawn in the selected font.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_USE_FONT,
|
2005-03-09 06:15:13 +00:00
|
|
|
g_param_spec_boolean ("use-font",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Use font in label"),
|
|
|
|
P_("Whether the label is drawn in the selected font"),
|
2003-07-01 19:52:07 +00:00
|
|
|
FALSE,
|
2014-06-09 12:56:30 +00:00
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-25 23:21:38 +00:00
|
|
|
* GtkFontButton:use-size: (attributes org.gtk.Property.get=gtk_font_button_get_use_size org.gtk.Property.set=gtk_font_button_set_use_size)
|
2021-02-22 00:42:45 +00:00
|
|
|
*
|
|
|
|
* Whether the buttons label will use the selected font size.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_USE_SIZE,
|
2005-03-09 06:15:13 +00:00
|
|
|
g_param_spec_boolean ("use-size",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Use size in label"),
|
|
|
|
P_("Whether the label is drawn with the selected font size"),
|
2003-07-01 19:52:07 +00:00
|
|
|
FALSE,
|
2014-06-09 12:56:30 +00:00
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2021-02-22 00:42:45 +00:00
|
|
|
/**
|
2021-02-25 23:21:38 +00:00
|
|
|
* GtkFontButton:modal: (attributes org.gtk.Property.get=gtk_font_button_get_modal org.gtk.Property.set=gtk_font_button_set_modal)
|
2021-02-22 00:42:45 +00:00
|
|
|
*
|
|
|
|
* Whether the font chooser dialog should be modal.
|
|
|
|
*/
|
2020-04-13 04:28:34 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_MODAL,
|
|
|
|
g_param_spec_boolean ("modal",
|
|
|
|
P_("Modal"),
|
|
|
|
P_("Whether the dialog is modal"),
|
|
|
|
TRUE,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
/**
|
|
|
|
* GtkFontButton::font-set:
|
2021-02-22 00:42:45 +00:00
|
|
|
* @widget: the object which received the signal
|
|
|
|
*
|
|
|
|
* Emitted when the user selects a font.
|
|
|
|
*
|
|
|
|
* When handling this signal, use [method@Gtk.FontChooser.get_font]
|
2006-05-31 04:06:12 +00:00
|
|
|
* to find out which font was just selected.
|
|
|
|
*
|
2021-02-22 00:42:45 +00:00
|
|
|
* Note that this signal is only emitted when the user changes the font.
|
|
|
|
* If you need to react to programmatic font changes as well, use
|
|
|
|
* the notify::font signal.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
2005-09-01 05:11:46 +00:00
|
|
|
font_button_signals[FONT_SET] = g_signal_new (I_("font-set"),
|
2003-07-01 19:52:07 +00:00
|
|
|
G_TYPE_FROM_CLASS (gobject_class),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GtkFontButtonClass, font_set),
|
|
|
|
NULL, NULL,
|
2019-05-29 20:05:19 +00:00
|
|
|
NULL,
|
2003-07-01 19:52:07 +00:00
|
|
|
G_TYPE_NONE, 0);
|
2013-03-30 08:35:54 +00:00
|
|
|
|
2019-09-13 09:53:24 +00:00
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
2017-11-18 03:49:57 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("fontbutton"));
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_button_init (GtkFontButton *font_button)
|
|
|
|
{
|
2017-01-19 19:15:43 +00:00
|
|
|
GtkWidget *box;
|
2015-10-30 21:09:59 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->button = gtk_button_new ();
|
|
|
|
g_signal_connect (font_button->button, "clicked", G_CALLBACK (gtk_font_button_clicked), font_button);
|
|
|
|
font_button->font_label = gtk_label_new (_("Font"));
|
|
|
|
gtk_widget_set_hexpand (font_button->font_label, TRUE);
|
|
|
|
font_button->size_label = gtk_label_new ("14");
|
|
|
|
font_button->font_size_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2017-01-19 19:15:43 +00:00
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), font_button->font_label);
|
2017-01-21 07:45:44 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (font_button->font_size_box), gtk_separator_new (GTK_ORIENTATION_VERTICAL));
|
|
|
|
gtk_box_append (GTK_BOX (font_button->font_size_box), font_button->size_label);
|
|
|
|
gtk_box_append (GTK_BOX (box), font_button->font_size_box);
|
2017-01-19 19:15:43 +00:00
|
|
|
|
2020-05-02 07:05:19 +00:00
|
|
|
gtk_button_set_child (GTK_BUTTON (font_button->button), box);
|
2020-04-13 04:32:50 +00:00
|
|
|
gtk_widget_set_parent (font_button->button, GTK_WIDGET (font_button));
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/* Initialize fields */
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->modal = TRUE;
|
|
|
|
font_button->use_font = FALSE;
|
|
|
|
font_button->use_size = FALSE;
|
|
|
|
font_button->show_preview_entry = TRUE;
|
|
|
|
font_button->font_dialog = NULL;
|
|
|
|
font_button->font_family = NULL;
|
|
|
|
font_button->font_face = NULL;
|
|
|
|
font_button->font_size = -1;
|
|
|
|
font_button->title = g_strdup (_("Pick a Font"));
|
|
|
|
font_button->level = GTK_FONT_CHOOSER_LEVEL_FAMILY |
|
|
|
|
GTK_FONT_CHOOSER_LEVEL_STYLE |
|
|
|
|
GTK_FONT_CHOOSER_LEVEL_SIZE;
|
|
|
|
font_button->language = pango_language_get_default ();
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2011-09-11 22:13:26 +00:00
|
|
|
gtk_font_button_take_font_desc (font_button, NULL);
|
2015-10-30 21:09:59 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
gtk_widget_add_css_class (font_button->button, "font");
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_button_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkFontButton *font_button = GTK_FONT_BUTTON (object);
|
|
|
|
|
2020-05-09 14:26:22 +00:00
|
|
|
if (font_button->font_dialog != NULL)
|
|
|
|
gtk_window_destroy (GTK_WINDOW (font_button->font_dialog));
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
g_free (font_button->title);
|
2011-09-05 12:10:20 +00:00
|
|
|
|
2011-09-11 23:18:58 +00:00
|
|
|
clear_font_data (font_button);
|
2011-09-05 12:10:20 +00:00
|
|
|
clear_font_filter_data (font_button);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
g_free (font_button->preview_text);
|
2014-10-02 04:05:43 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
g_clear_object (&font_button->provider);
|
2011-09-05 12:10:20 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
gtk_widget_unparent (font_button->button);
|
2017-01-19 19:15:43 +00:00
|
|
|
|
2006-05-02 23:56:43 +00:00
|
|
|
G_OBJECT_CLASS (gtk_font_button_parent_class)->finalize (object);
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_button_set_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkFontButton *font_button = GTK_FONT_BUTTON (object);
|
2011-09-05 12:10:20 +00:00
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
switch (param_id)
|
|
|
|
{
|
2011-09-05 12:10:20 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT:
|
|
|
|
gtk_font_button_set_preview_text (font_button, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
case GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY:
|
|
|
|
gtk_font_button_set_show_preview_entry (font_button, g_value_get_boolean (value));
|
|
|
|
break;
|
2003-07-01 19:52:07 +00:00
|
|
|
case PROP_TITLE:
|
|
|
|
gtk_font_button_set_title (font_button, g_value_get_string (value));
|
|
|
|
break;
|
2020-04-13 04:28:34 +00:00
|
|
|
case PROP_MODAL:
|
|
|
|
gtk_font_button_set_modal (font_button, g_value_get_boolean (value));
|
|
|
|
break;
|
2011-09-11 22:13:26 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_FONT_DESC:
|
|
|
|
gtk_font_button_take_font_desc (font_button, g_value_dup_boxed (value));
|
|
|
|
break;
|
2018-04-02 17:34:22 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_LANGUAGE:
|
|
|
|
gtk_font_button_set_language (font_button, g_value_get_string (value));
|
|
|
|
break;
|
2017-12-21 15:51:04 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_LEVEL:
|
2018-03-27 20:10:19 +00:00
|
|
|
gtk_font_button_set_level (font_button, g_value_get_flags (value));
|
2017-12-21 15:51:04 +00:00
|
|
|
break;
|
2011-09-05 12:10:20 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_FONT:
|
2003-07-01 19:52:07 +00:00
|
|
|
gtk_font_button_set_font_name (font_button, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
case PROP_USE_FONT:
|
|
|
|
gtk_font_button_set_use_font (font_button, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
case PROP_USE_SIZE:
|
|
|
|
gtk_font_button_set_use_size (font_button, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_button_get_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkFontButton *font_button = GTK_FONT_BUTTON (object);
|
|
|
|
|
|
|
|
switch (param_id)
|
|
|
|
{
|
2011-09-05 12:10:20 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT:
|
|
|
|
g_value_set_string (value, gtk_font_button_get_preview_text (font_button));
|
|
|
|
break;
|
|
|
|
case GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY:
|
|
|
|
g_value_set_boolean (value, gtk_font_button_get_show_preview_entry (font_button));
|
|
|
|
break;
|
2003-07-01 19:52:07 +00:00
|
|
|
case PROP_TITLE:
|
|
|
|
g_value_set_string (value, gtk_font_button_get_title (font_button));
|
|
|
|
break;
|
2020-04-13 04:28:34 +00:00
|
|
|
case PROP_MODAL:
|
|
|
|
g_value_set_boolean (value, gtk_font_button_get_modal (font_button));
|
|
|
|
break;
|
2011-09-11 22:13:26 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_FONT_DESC:
|
|
|
|
g_value_set_boxed (value, gtk_font_button_get_font_desc (font_button));
|
|
|
|
break;
|
2018-01-03 04:52:24 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_FONT_FEATURES:
|
2020-04-13 04:32:50 +00:00
|
|
|
g_value_set_string (value, font_button->font_features);
|
2018-01-03 04:52:24 +00:00
|
|
|
break;
|
|
|
|
case GTK_FONT_CHOOSER_PROP_LANGUAGE:
|
2020-04-13 04:32:50 +00:00
|
|
|
g_value_set_string (value, pango_language_to_string (font_button->language));
|
2018-01-03 04:52:24 +00:00
|
|
|
break;
|
2017-12-21 15:51:04 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_LEVEL:
|
2020-04-13 04:32:50 +00:00
|
|
|
g_value_set_flags (value, font_button->level);
|
2017-12-21 15:51:04 +00:00
|
|
|
break;
|
2011-09-05 12:10:20 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_FONT:
|
2003-07-01 19:52:07 +00:00
|
|
|
g_value_set_string (value, gtk_font_button_get_font_name (font_button));
|
|
|
|
break;
|
|
|
|
case PROP_USE_FONT:
|
|
|
|
g_value_set_boolean (value, gtk_font_button_get_use_font (font_button));
|
|
|
|
break;
|
|
|
|
case PROP_USE_SIZE:
|
|
|
|
g_value_set_boolean (value, gtk_font_button_get_use_size (font_button));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2015-05-05 03:21:17 +00:00
|
|
|
}
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_font_button_new:
|
|
|
|
*
|
|
|
|
* Creates a new font picker widget.
|
|
|
|
*
|
|
|
|
* Returns: a new font picker widget.
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_font_button_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_FONT_BUTTON, NULL);
|
2015-05-05 03:21:17 +00:00
|
|
|
}
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_font_button_new_with_font:
|
2011-07-27 23:22:22 +00:00
|
|
|
* @fontname: Name of font to display in font chooser dialog
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2021-02-22 00:42:45 +00:00
|
|
|
* Creates a new font picker widget showing the given font.
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Returns: a new font picker widget.
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
2020-07-24 18:40:36 +00:00
|
|
|
gtk_font_button_new_with_font (const char *fontname)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2017-12-21 16:37:53 +00:00
|
|
|
return g_object_new (GTK_TYPE_FONT_BUTTON, "font", fontname, NULL);
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 23:21:38 +00:00
|
|
|
* gtk_font_button_set_title: (attributes org.gtk.Method.set_property=title)
|
2021-02-22 00:42:45 +00:00
|
|
|
* @font_button: a `GtkFontButton`
|
2011-07-27 23:22:22 +00:00
|
|
|
* @title: a string containing the font chooser dialog title
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2021-02-22 00:42:45 +00:00
|
|
|
* Sets the title for the font chooser dialog.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_font_button_set_title (GtkFontButton *font_button,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *title)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *old_title;
|
2003-07-01 19:52:07 +00:00
|
|
|
g_return_if_fail (GTK_IS_FONT_BUTTON (font_button));
|
2018-06-18 11:11:06 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
old_title = font_button->title;
|
|
|
|
font_button->title = g_strdup (title);
|
2003-07-01 19:52:07 +00:00
|
|
|
g_free (old_title);
|
2018-06-18 11:11:06 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_dialog)
|
|
|
|
gtk_window_set_title (GTK_WINDOW (font_button->font_dialog), font_button->title);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (font_button), "title");
|
2018-06-18 11:11:06 +00:00
|
|
|
}
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-25 23:21:38 +00:00
|
|
|
* gtk_font_button_get_title: (attributes org.gtk.Method.get_property=title)
|
2021-02-22 00:42:45 +00:00
|
|
|
* @font_button: a `GtkFontButton`
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2011-07-27 23:22:22 +00:00
|
|
|
* Retrieves the title of the font chooser dialog.
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2021-02-22 00:42:45 +00:00
|
|
|
* Returns: an internal copy of the title string
|
|
|
|
* which must not be freed.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *
|
2003-07-01 19:52:07 +00:00
|
|
|
gtk_font_button_get_title (GtkFontButton *font_button)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), NULL);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
return font_button->title;
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-13 04:28:34 +00:00
|
|
|
/**
|
2021-02-25 23:21:38 +00:00
|
|
|
* gtk_font_button_set_modal: (attributes org.gtk.Method.set_property=modal)
|
2021-02-22 00:42:45 +00:00
|
|
|
* @font_button: a `GtkFontButton`
|
2020-04-13 04:28:34 +00:00
|
|
|
* @modal: %TRUE to make the dialog modal
|
|
|
|
*
|
|
|
|
* Sets whether the dialog should be modal.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_font_button_set_modal (GtkFontButton *font_button,
|
|
|
|
gboolean modal)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_FONT_BUTTON (font_button));
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->modal == modal)
|
2020-04-13 04:28:34 +00:00
|
|
|
return;
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->modal = modal;
|
2020-04-13 04:28:34 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_dialog)
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (font_button->font_dialog), font_button->modal);
|
2020-04-13 04:28:34 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (font_button), "modal");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 23:21:38 +00:00
|
|
|
* gtk_font_button_get_modal: (attributes org.gtk.Method.get_property=modal)
|
2021-02-22 00:42:45 +00:00
|
|
|
* @font_button: a `GtkFontButton`
|
2020-04-13 04:28:34 +00:00
|
|
|
*
|
|
|
|
* Gets whether the dialog is modal.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the dialog is modal
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_font_button_get_modal (GtkFontButton *font_button)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
return font_button->modal;
|
2020-04-13 04:28:34 +00:00
|
|
|
}
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
/**
|
2021-02-25 23:21:38 +00:00
|
|
|
* gtk_font_button_get_use_font: (attributes org.gtk.Method.get_property=use-font)
|
2021-02-22 00:42:45 +00:00
|
|
|
* @font_button: a `GtkFontButton`
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Returns whether the selected font is used in the label.
|
|
|
|
*
|
|
|
|
* Returns: whether the selected font is used in the label.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_font_button_get_use_font (GtkFontButton *font_button)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
return font_button->use_font;
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 23:21:38 +00:00
|
|
|
* gtk_font_button_set_use_font: (attributes org.gtk.Method.set_property=use-font)
|
2021-02-22 00:42:45 +00:00
|
|
|
* @font_button: a `GtkFontButton`
|
2003-07-01 19:52:07 +00:00
|
|
|
* @use_font: If %TRUE, font name will be written using font chosen.
|
|
|
|
*
|
2021-02-22 00:42:45 +00:00
|
|
|
* If @use_font is %TRUE, the font name will be written
|
|
|
|
* using the selected font.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
2021-02-22 00:42:45 +00:00
|
|
|
void
|
2003-07-01 19:52:07 +00:00
|
|
|
gtk_font_button_set_use_font (GtkFontButton *font_button,
|
|
|
|
gboolean use_font)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_FONT_BUTTON (font_button));
|
2018-06-18 11:11:06 +00:00
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
use_font = (use_font != FALSE);
|
2018-06-18 11:11:06 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->use_font != use_font)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->use_font = use_font;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2011-09-22 19:27:22 +00:00
|
|
|
gtk_font_button_label_use_font (font_button);
|
2018-06-18 11:11:06 +00:00
|
|
|
|
2011-09-22 19:27:22 +00:00
|
|
|
g_object_notify (G_OBJECT (font_button), "use-font");
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
2018-06-18 11:11:06 +00:00
|
|
|
}
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-25 23:21:38 +00:00
|
|
|
* gtk_font_button_get_use_size: (attributes org.gtk.Method.get_property=use-size)
|
2021-02-22 00:42:45 +00:00
|
|
|
* @font_button: a `GtkFontButton`
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Returns whether the selected size is used in the label.
|
|
|
|
*
|
|
|
|
* Returns: whether the selected size is used in the label.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_font_button_get_use_size (GtkFontButton *font_button)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
return font_button->use_size;
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 23:21:38 +00:00
|
|
|
* gtk_font_button_set_use_size: (attributes org.gtk.Method.set_property=use-size)
|
2021-02-22 00:42:45 +00:00
|
|
|
* @font_button: a `GtkFontButton`
|
|
|
|
* @use_size: If %TRUE, font name will be written using the
|
|
|
|
* selected size.
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2021-02-22 00:42:45 +00:00
|
|
|
* If @use_size is %TRUE, the font name will be written using
|
|
|
|
* the selected size.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
2018-06-18 11:11:06 +00:00
|
|
|
void
|
2003-07-01 19:52:07 +00:00
|
|
|
gtk_font_button_set_use_size (GtkFontButton *font_button,
|
2011-07-27 23:22:22 +00:00
|
|
|
gboolean use_size)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_FONT_BUTTON (font_button));
|
2018-06-18 11:11:06 +00:00
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
use_size = (use_size != FALSE);
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->use_size != use_size)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->use_size = use_size;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2011-09-22 19:27:22 +00:00
|
|
|
gtk_font_button_label_use_font (font_button);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2005-03-26 05:49:15 +00:00
|
|
|
g_object_notify (G_OBJECT (font_button), "use-size");
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
2018-06-18 11:11:06 +00:00
|
|
|
}
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
static const char *
|
2003-07-01 19:52:07 +00:00
|
|
|
gtk_font_button_get_font_name (GtkFontButton *font_button)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), NULL);
|
2011-09-11 22:13:26 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
return font_button->fontname;
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 16:10:44 +00:00
|
|
|
static void
|
2003-07-01 19:52:07 +00:00
|
|
|
gtk_font_button_set_font_name (GtkFontButton *font_button,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *fontname)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2011-09-11 22:13:26 +00:00
|
|
|
PangoFontDescription *font_desc;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2011-09-11 22:13:26 +00:00
|
|
|
font_desc = pango_font_description_from_string (fontname);
|
|
|
|
gtk_font_button_take_font_desc (font_button, font_desc);
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-01-19 19:15:43 +00:00
|
|
|
gtk_font_button_clicked (GtkButton *button,
|
|
|
|
gpointer user_data)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2011-09-11 23:49:26 +00:00
|
|
|
GtkFontChooser *font_dialog;
|
2017-01-19 19:15:43 +00:00
|
|
|
GtkFontButton *font_button = user_data;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (!font_button->font_dialog)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
|
|
|
GtkWidget *parent;
|
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
parent = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (font_button)));
|
2011-09-05 12:10:20 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->font_dialog = gtk_font_chooser_dialog_new (font_button->title, NULL);
|
|
|
|
gtk_window_set_hide_on_close (GTK_WINDOW (font_button->font_dialog), TRUE);
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (font_button->font_dialog), font_button->modal);
|
2017-12-31 15:43:01 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
font_dialog = GTK_FONT_CHOOSER (font_button->font_dialog);
|
2011-09-05 12:10:20 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_map)
|
|
|
|
gtk_font_chooser_set_font_map (font_dialog, font_button->font_map);
|
2017-12-21 15:51:04 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
gtk_font_chooser_set_show_preview_entry (font_dialog, font_button->show_preview_entry);
|
|
|
|
gtk_font_chooser_set_level (GTK_FONT_CHOOSER (font_dialog), font_button->level);
|
|
|
|
gtk_font_chooser_set_language (GTK_FONT_CHOOSER (font_dialog), pango_language_to_string (font_button->language));
|
2011-09-05 12:10:20 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->preview_text)
|
2011-09-05 12:10:20 +00:00
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
gtk_font_chooser_set_preview_text (font_dialog, font_button->preview_text);
|
|
|
|
g_free (font_button->preview_text);
|
|
|
|
font_button->preview_text = NULL;
|
2011-09-05 12:10:20 +00:00
|
|
|
}
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_filter)
|
2011-09-05 12:10:20 +00:00
|
|
|
{
|
|
|
|
gtk_font_chooser_set_filter_func (font_dialog,
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->font_filter,
|
|
|
|
font_button->font_filter_data,
|
|
|
|
font_button->font_filter_data_destroy);
|
|
|
|
font_button->font_filter = NULL;
|
|
|
|
font_button->font_filter_data = NULL;
|
|
|
|
font_button->font_filter_data_destroy = NULL;
|
2011-09-05 12:10:20 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 03:31:03 +00:00
|
|
|
if (GTK_IS_WINDOW (parent))
|
2006-05-24 19:44:20 +00:00
|
|
|
{
|
|
|
|
if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (font_dialog)))
|
2011-07-27 23:22:22 +00:00
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (font_dialog), GTK_WINDOW (parent));
|
|
|
|
|
2020-04-13 04:28:34 +00:00
|
|
|
if (gtk_window_get_modal (GTK_WINDOW (parent)))
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (font_dialog), TRUE);
|
2011-07-27 23:22:22 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 12:10:20 +00:00
|
|
|
g_signal_connect (font_dialog, "notify",
|
|
|
|
G_CALLBACK (gtk_font_button_font_chooser_notify), button);
|
|
|
|
|
2011-07-27 23:22:22 +00:00
|
|
|
g_signal_connect (font_dialog, "response",
|
|
|
|
G_CALLBACK (response_cb), font_button);
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
g_signal_connect (font_dialog, "destroy",
|
|
|
|
G_CALLBACK (dialog_destroy), font_button);
|
|
|
|
}
|
2017-12-31 15:43:01 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (!gtk_widget_get_visible (font_button->font_dialog))
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
font_dialog = GTK_FONT_CHOOSER (font_button->font_dialog);
|
|
|
|
gtk_font_chooser_set_font_desc (font_dialog, font_button->font_desc);
|
2017-12-31 15:43:01 +00:00
|
|
|
}
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
gtk_window_present (GTK_WINDOW (font_button->font_dialog));
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
2011-07-27 23:22:22 +00:00
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
static void
|
2011-07-27 23:22:22 +00:00
|
|
|
response_cb (GtkDialog *dialog,
|
2020-07-24 13:54:49 +00:00
|
|
|
int response_id,
|
2011-07-27 23:22:22 +00:00
|
|
|
gpointer data)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
|
|
|
GtkFontButton *font_button = GTK_FONT_BUTTON (data);
|
2011-09-05 12:10:20 +00:00
|
|
|
GtkFontChooser *font_chooser;
|
2011-09-11 22:13:26 +00:00
|
|
|
GObject *object;
|
2011-09-05 12:10:20 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
gtk_widget_hide (font_button->font_dialog);
|
2011-07-27 23:22:22 +00:00
|
|
|
|
|
|
|
if (response_id != GTK_RESPONSE_OK)
|
|
|
|
return;
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
font_chooser = GTK_FONT_CHOOSER (font_button->font_dialog);
|
2011-09-11 22:13:26 +00:00
|
|
|
object = G_OBJECT (font_chooser);
|
|
|
|
|
|
|
|
g_object_freeze_notify (object);
|
|
|
|
|
2011-09-11 23:18:58 +00:00
|
|
|
clear_font_data (font_button);
|
2011-09-05 12:10:20 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->font_desc = gtk_font_chooser_get_font_desc (font_chooser);
|
|
|
|
if (font_button->font_desc)
|
|
|
|
font_button->fontname = pango_font_description_to_string (font_button->font_desc);
|
|
|
|
font_button->font_family = gtk_font_chooser_get_font_family (font_chooser);
|
|
|
|
if (font_button->font_family)
|
|
|
|
g_object_ref (font_button->font_family);
|
|
|
|
font_button->font_face = gtk_font_chooser_get_font_face (font_chooser);
|
|
|
|
if (font_button->font_face)
|
|
|
|
g_object_ref (font_button->font_face);
|
|
|
|
font_button->font_size = gtk_font_chooser_get_font_size (font_chooser);
|
|
|
|
g_free (font_button->font_features);
|
|
|
|
font_button->font_features = gtk_font_chooser_get_font_features (font_chooser);
|
|
|
|
font_button->language = pango_language_from_string (gtk_font_chooser_get_language (font_chooser));
|
2011-09-05 12:10:20 +00:00
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
/* Set label font */
|
|
|
|
gtk_font_button_update_font_info (font_button);
|
|
|
|
|
2011-09-05 12:10:20 +00:00
|
|
|
g_object_notify (G_OBJECT (font_button), "font");
|
2011-09-11 22:13:26 +00:00
|
|
|
g_object_notify (G_OBJECT (font_button), "font-desc");
|
2018-03-27 18:47:36 +00:00
|
|
|
g_object_notify (G_OBJECT (font_button), "font-features");
|
2011-09-11 22:13:26 +00:00
|
|
|
|
|
|
|
g_object_thaw_notify (object);
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
/* Emit font_set signal */
|
|
|
|
g_signal_emit (font_button, font_button_signals[FONT_SET], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dialog_destroy (GtkWidget *widget,
|
2011-07-27 23:22:22 +00:00
|
|
|
gpointer data)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
|
|
|
GtkFontButton *font_button = GTK_FONT_BUTTON (data);
|
2018-06-18 11:11:06 +00:00
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
/* Dialog will get destroyed so reference is not valid now */
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->font_dialog = NULL;
|
2018-06-18 11:11:06 +00:00
|
|
|
}
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2017-12-20 14:11:04 +00:00
|
|
|
static void
|
|
|
|
add_css_variations (GString *s,
|
|
|
|
const char *variations)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
const char *sep = "";
|
|
|
|
|
|
|
|
if (variations == NULL || variations[0] == '\0')
|
|
|
|
{
|
|
|
|
g_string_append (s, "normal");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = variations;
|
|
|
|
while (p && *p)
|
|
|
|
{
|
|
|
|
const char *start;
|
|
|
|
const char *end, *end2;
|
|
|
|
double value;
|
|
|
|
char name[5];
|
|
|
|
|
|
|
|
while (g_ascii_isspace (*p)) p++;
|
|
|
|
|
|
|
|
start = p;
|
|
|
|
end = strchr (p, ',');
|
|
|
|
if (end && (end - p < 6))
|
|
|
|
goto skip;
|
|
|
|
|
|
|
|
name[0] = p[0];
|
|
|
|
name[1] = p[1];
|
|
|
|
name[2] = p[2];
|
|
|
|
name[3] = p[3];
|
|
|
|
name[4] = '\0';
|
|
|
|
|
|
|
|
p += 4;
|
|
|
|
while (g_ascii_isspace (*p)) p++;
|
|
|
|
if (*p == '=') p++;
|
|
|
|
|
|
|
|
if (p - start < 5)
|
|
|
|
goto skip;
|
|
|
|
|
|
|
|
value = g_ascii_strtod (p, (char **) &end2);
|
|
|
|
|
|
|
|
while (end2 && g_ascii_isspace (*end2)) end2++;
|
|
|
|
|
|
|
|
if (end2 && (*end2 != ',' && *end2 != '\0'))
|
|
|
|
goto skip;
|
|
|
|
|
|
|
|
g_string_append_printf (s, "%s\"%s\" %g", sep, name, value);
|
|
|
|
sep = ", ";
|
|
|
|
|
|
|
|
skip:
|
|
|
|
p = end ? end + 1 : NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
static char *
|
2018-01-03 04:52:24 +00:00
|
|
|
pango_font_description_to_css (PangoFontDescription *desc,
|
|
|
|
const char *features,
|
|
|
|
const char *language)
|
2016-04-18 19:04:37 +00:00
|
|
|
{
|
|
|
|
GString *s;
|
|
|
|
PangoFontMask set;
|
|
|
|
|
|
|
|
s = g_string_new ("* { ");
|
|
|
|
|
|
|
|
set = pango_font_description_get_set_fields (desc);
|
|
|
|
if (set & PANGO_FONT_MASK_FAMILY)
|
|
|
|
{
|
|
|
|
g_string_append (s, "font-family: ");
|
|
|
|
g_string_append (s, pango_font_description_get_family (desc));
|
|
|
|
g_string_append (s, "; ");
|
|
|
|
}
|
|
|
|
if (set & PANGO_FONT_MASK_STYLE)
|
|
|
|
{
|
|
|
|
switch (pango_font_description_get_style (desc))
|
|
|
|
{
|
|
|
|
case PANGO_STYLE_NORMAL:
|
|
|
|
g_string_append (s, "font-style: normal; ");
|
|
|
|
break;
|
|
|
|
case PANGO_STYLE_OBLIQUE:
|
|
|
|
g_string_append (s, "font-style: oblique; ");
|
|
|
|
break;
|
|
|
|
case PANGO_STYLE_ITALIC:
|
|
|
|
g_string_append (s, "font-style: italic; ");
|
|
|
|
break;
|
2017-10-06 19:19:42 +00:00
|
|
|
default:
|
|
|
|
break;
|
2016-04-18 19:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (set & PANGO_FONT_MASK_VARIANT)
|
|
|
|
{
|
|
|
|
switch (pango_font_description_get_variant (desc))
|
|
|
|
{
|
|
|
|
case PANGO_VARIANT_NORMAL:
|
|
|
|
g_string_append (s, "font-variant: normal; ");
|
|
|
|
break;
|
|
|
|
case PANGO_VARIANT_SMALL_CAPS:
|
|
|
|
g_string_append (s, "font-variant: small-caps; ");
|
|
|
|
break;
|
2017-10-06 19:19:42 +00:00
|
|
|
default:
|
|
|
|
break;
|
2016-04-18 19:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (set & PANGO_FONT_MASK_WEIGHT)
|
|
|
|
{
|
|
|
|
switch (pango_font_description_get_weight (desc))
|
|
|
|
{
|
|
|
|
case PANGO_WEIGHT_THIN:
|
|
|
|
g_string_append (s, "font-weight: 100; ");
|
|
|
|
break;
|
|
|
|
case PANGO_WEIGHT_ULTRALIGHT:
|
|
|
|
g_string_append (s, "font-weight: 200; ");
|
|
|
|
break;
|
|
|
|
case PANGO_WEIGHT_LIGHT:
|
|
|
|
case PANGO_WEIGHT_SEMILIGHT:
|
|
|
|
g_string_append (s, "font-weight: 300; ");
|
|
|
|
break;
|
|
|
|
case PANGO_WEIGHT_BOOK:
|
|
|
|
case PANGO_WEIGHT_NORMAL:
|
|
|
|
g_string_append (s, "font-weight: 400; ");
|
|
|
|
break;
|
|
|
|
case PANGO_WEIGHT_MEDIUM:
|
|
|
|
g_string_append (s, "font-weight: 500; ");
|
|
|
|
break;
|
|
|
|
case PANGO_WEIGHT_SEMIBOLD:
|
|
|
|
g_string_append (s, "font-weight: 600; ");
|
|
|
|
break;
|
|
|
|
case PANGO_WEIGHT_BOLD:
|
|
|
|
g_string_append (s, "font-weight: 700; ");
|
|
|
|
break;
|
|
|
|
case PANGO_WEIGHT_ULTRABOLD:
|
|
|
|
g_string_append (s, "font-weight: 800; ");
|
|
|
|
break;
|
|
|
|
case PANGO_WEIGHT_HEAVY:
|
|
|
|
case PANGO_WEIGHT_ULTRAHEAVY:
|
|
|
|
g_string_append (s, "font-weight: 900; ");
|
|
|
|
break;
|
2017-10-06 19:19:42 +00:00
|
|
|
default:
|
|
|
|
break;
|
2016-04-18 19:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (set & PANGO_FONT_MASK_STRETCH)
|
|
|
|
{
|
|
|
|
switch (pango_font_description_get_stretch (desc))
|
|
|
|
{
|
|
|
|
case PANGO_STRETCH_ULTRA_CONDENSED:
|
|
|
|
g_string_append (s, "font-stretch: ultra-condensed; ");
|
|
|
|
break;
|
|
|
|
case PANGO_STRETCH_EXTRA_CONDENSED:
|
|
|
|
g_string_append (s, "font-stretch: extra-condensed; ");
|
|
|
|
break;
|
|
|
|
case PANGO_STRETCH_CONDENSED:
|
|
|
|
g_string_append (s, "font-stretch: condensed; ");
|
|
|
|
break;
|
|
|
|
case PANGO_STRETCH_SEMI_CONDENSED:
|
|
|
|
g_string_append (s, "font-stretch: semi-condensed; ");
|
|
|
|
break;
|
|
|
|
case PANGO_STRETCH_NORMAL:
|
|
|
|
g_string_append (s, "font-stretch: normal; ");
|
|
|
|
break;
|
|
|
|
case PANGO_STRETCH_SEMI_EXPANDED:
|
|
|
|
g_string_append (s, "font-stretch: semi-expanded; ");
|
|
|
|
break;
|
|
|
|
case PANGO_STRETCH_EXPANDED:
|
|
|
|
g_string_append (s, "font-stretch: expanded; ");
|
|
|
|
break;
|
|
|
|
case PANGO_STRETCH_EXTRA_EXPANDED:
|
|
|
|
break;
|
|
|
|
case PANGO_STRETCH_ULTRA_EXPANDED:
|
|
|
|
g_string_append (s, "font-stretch: ultra-expanded; ");
|
|
|
|
break;
|
2017-10-06 19:19:42 +00:00
|
|
|
default:
|
|
|
|
break;
|
2016-04-18 19:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (set & PANGO_FONT_MASK_SIZE)
|
|
|
|
{
|
2017-12-20 14:11:04 +00:00
|
|
|
g_string_append_printf (s, "font-size: %dpt; ", pango_font_description_get_size (desc) / PANGO_SCALE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set & PANGO_FONT_MASK_VARIATIONS)
|
|
|
|
{
|
|
|
|
const char *variations;
|
|
|
|
|
|
|
|
g_string_append (s, "font-variation-settings: ");
|
|
|
|
variations = pango_font_description_get_variations (desc);
|
|
|
|
add_css_variations (s, variations);
|
|
|
|
g_string_append (s, "; ");
|
2016-04-18 19:04:37 +00:00
|
|
|
}
|
2018-01-03 04:52:24 +00:00
|
|
|
if (features)
|
|
|
|
{
|
|
|
|
g_string_append_printf (s, "font-feature-settings: %s;", features);
|
|
|
|
}
|
2016-04-18 19:04:37 +00:00
|
|
|
|
|
|
|
g_string_append (s, "}");
|
|
|
|
|
|
|
|
return g_string_free (s, FALSE);
|
|
|
|
}
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
static void
|
|
|
|
gtk_font_button_label_use_font (GtkFontButton *font_button)
|
|
|
|
{
|
2014-10-02 04:05:43 +00:00
|
|
|
GtkStyleContext *context;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
context = gtk_widget_get_style_context (font_button->font_label);
|
2011-09-11 22:13:26 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (!font_button->use_font)
|
2014-10-02 04:05:43 +00:00
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->provider)
|
2014-10-02 04:05:43 +00:00
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
gtk_style_context_remove_provider (context, GTK_STYLE_PROVIDER (font_button->provider));
|
|
|
|
g_clear_object (&font_button->provider);
|
2014-10-02 04:05:43 +00:00
|
|
|
}
|
2011-09-22 19:27:22 +00:00
|
|
|
}
|
|
|
|
else
|
2014-10-02 04:05:43 +00:00
|
|
|
{
|
|
|
|
PangoFontDescription *desc;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *data;
|
2014-10-02 04:05:43 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (!font_button->provider)
|
2014-10-02 04:05:43 +00:00
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->provider = gtk_css_provider_new ();
|
2014-10-02 04:05:43 +00:00
|
|
|
gtk_style_context_add_provider (context,
|
2020-04-13 04:32:50 +00:00
|
|
|
GTK_STYLE_PROVIDER (font_button->provider),
|
2014-10-02 04:05:43 +00:00
|
|
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
|
|
|
}
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
desc = pango_font_description_copy (font_button->font_desc);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (!font_button->use_size)
|
2014-10-02 04:05:43 +00:00
|
|
|
pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE);
|
|
|
|
|
2018-04-05 10:22:43 +00:00
|
|
|
data = pango_font_description_to_css (desc,
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->font_features,
|
|
|
|
pango_language_to_string (font_button->language));
|
|
|
|
gtk_css_provider_load_from_data (font_button->provider, data, -1);
|
2004-01-23 22:55:47 +00:00
|
|
|
|
2014-10-02 04:05:43 +00:00
|
|
|
g_free (data);
|
|
|
|
pango_font_description_free (desc);
|
|
|
|
}
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_button_update_font_info (GtkFontButton *font_button)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *fam_name;
|
|
|
|
const char *face_name;
|
|
|
|
char *family_style;
|
2011-09-11 22:13:26 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_family)
|
|
|
|
fam_name = pango_font_family_get_name (font_button->font_family);
|
2014-08-15 19:15:45 +00:00
|
|
|
else
|
2016-02-16 23:33:16 +00:00
|
|
|
fam_name = C_("font", "None");
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_face)
|
|
|
|
face_name = pango_font_face_get_face_name (font_button->font_face);
|
2014-08-15 19:15:45 +00:00
|
|
|
else
|
|
|
|
face_name = "";
|
2011-09-11 22:13:26 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if ((font_button->level & GTK_FONT_CHOOSER_LEVEL_STYLE) != 0)
|
2017-12-21 16:58:20 +00:00
|
|
|
family_style = g_strconcat (fam_name, " ", face_name, NULL);
|
2018-03-27 20:10:19 +00:00
|
|
|
else
|
|
|
|
family_style = g_strdup (fam_name);
|
2011-09-11 23:18:58 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL (font_button->font_label), family_style);
|
2003-07-01 19:52:07 +00:00
|
|
|
g_free (family_style);
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if ((font_button->level & GTK_FONT_CHOOSER_LEVEL_SIZE) != 0)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2011-09-22 19:35:25 +00:00
|
|
|
/* mirror Pango, which doesn't translate this either */
|
2020-07-24 18:40:36 +00:00
|
|
|
char *size = g_strdup_printf ("%2.4g%s",
|
2020-04-13 04:32:50 +00:00
|
|
|
pango_font_description_get_size (font_button->font_desc) / (double)PANGO_SCALE,
|
|
|
|
pango_font_description_get_size_is_absolute (font_button->font_desc) ? "px" : "");
|
2017-12-21 16:58:20 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL (font_button->size_label), size);
|
2017-12-21 16:58:20 +00:00
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
g_free (size);
|
2017-12-21 16:58:20 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
gtk_widget_show (font_button->font_size_box);
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
2017-12-21 16:58:20 +00:00
|
|
|
else
|
2020-04-13 04:32:50 +00:00
|
|
|
gtk_widget_hide (font_button->font_size_box);
|
2017-12-21 16:58:20 +00:00
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
gtk_font_button_label_use_font (font_button);
|
2017-12-21 16:58:20 +00:00
|
|
|
}
|
2017-12-21 15:51:04 +00:00
|
|
|
|
|
|
|
static void
|
2018-06-18 11:11:06 +00:00
|
|
|
gtk_font_button_set_level (GtkFontButton *font_button,
|
2017-12-21 15:51:04 +00:00
|
|
|
GtkFontChooserLevel level)
|
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->level == level)
|
2017-12-21 15:51:04 +00:00
|
|
|
return;
|
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->level = level;
|
2017-12-21 15:51:04 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_dialog)
|
|
|
|
gtk_font_chooser_set_level (GTK_FONT_CHOOSER (font_button->font_dialog), level);
|
2017-12-21 15:51:04 +00:00
|
|
|
|
2018-06-18 11:11:06 +00:00
|
|
|
gtk_font_button_update_font_info (font_button);
|
2017-12-21 15:51:04 +00:00
|
|
|
|
2018-06-18 11:11:06 +00:00
|
|
|
g_object_notify (G_OBJECT (font_button), "level");
|
2017-12-21 15:51:04 +00:00
|
|
|
}
|
2018-04-02 17:34:22 +00:00
|
|
|
|
|
|
|
static void
|
2018-06-18 11:11:06 +00:00
|
|
|
gtk_font_button_set_language (GtkFontButton *font_button,
|
2018-04-02 17:34:22 +00:00
|
|
|
const char *language)
|
|
|
|
{
|
2020-04-13 04:32:50 +00:00
|
|
|
font_button->language = pango_language_from_string (language);
|
2018-04-02 17:34:22 +00:00
|
|
|
|
2020-04-13 04:32:50 +00:00
|
|
|
if (font_button->font_dialog)
|
|
|
|
gtk_font_chooser_set_language (GTK_FONT_CHOOSER (font_button->font_dialog), language);
|
2018-04-02 17:34:22 +00:00
|
|
|
|
2018-06-18 11:11:06 +00:00
|
|
|
g_object_notify (G_OBJECT (font_button), "language");
|
2018-04-02 17:34:22 +00:00
|
|
|
}
|