2011-09-11 23:49:26 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2011 Alberto Ruiz <aruiz@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-09-11 23:49:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <glib/gprintf.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gtkfontchooserwidget.h"
|
2017-12-27 22:21:30 +00:00
|
|
|
#include "gtkfontchooserwidgetprivate.h"
|
2012-03-03 18:41:55 +00:00
|
|
|
|
|
|
|
#include "gtkadjustment.h"
|
|
|
|
#include "gtkbuildable.h"
|
|
|
|
#include "gtkbox.h"
|
2019-09-23 15:02:03 +00:00
|
|
|
#include "gtkbinlayout.h"
|
2020-08-30 20:41:02 +00:00
|
|
|
#include "gtkcheckbutton.h"
|
2019-11-28 03:00:39 +00:00
|
|
|
#include "gtkcustomfilter.h"
|
2011-09-11 23:49:26 +00:00
|
|
|
#include "gtkentry.h"
|
2019-11-28 03:00:39 +00:00
|
|
|
#include "gtkfilter.h"
|
2020-09-24 09:37:32 +00:00
|
|
|
#include "gtkframe.h"
|
2012-03-03 18:41:55 +00:00
|
|
|
#include "gtkgrid.h"
|
|
|
|
#include "gtkfontchooser.h"
|
|
|
|
#include "gtkfontchooserutils.h"
|
2022-09-24 13:07:56 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2011-09-11 23:49:26 +00:00
|
|
|
#include "gtklabel.h"
|
2019-11-28 03:00:39 +00:00
|
|
|
#include "gtksingleselection.h"
|
2015-05-07 22:28:39 +00:00
|
|
|
#include "gtkstack.h"
|
2011-09-11 23:49:26 +00:00
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtkscale.h"
|
2012-03-03 18:41:55 +00:00
|
|
|
#include "gtkscrolledwindow.h"
|
2019-11-28 03:00:39 +00:00
|
|
|
#include "gtksearchentry.h"
|
2011-09-11 23:49:26 +00:00
|
|
|
#include "gtkspinbutton.h"
|
2012-03-03 18:41:55 +00:00
|
|
|
#include "gtktextview.h"
|
2020-04-08 11:43:28 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2015-05-06 04:52:23 +00:00
|
|
|
#include "gtksettings.h"
|
2015-08-10 18:32:22 +00:00
|
|
|
#include "gtkdialog.h"
|
2019-05-29 17:10:46 +00:00
|
|
|
#include "gtkgestureclick.h"
|
2018-01-01 05:49:38 +00:00
|
|
|
#include "gtkeventcontrollerscroll.h"
|
2019-04-27 15:59:45 +00:00
|
|
|
#include "gtkroot.h"
|
2019-11-28 03:00:39 +00:00
|
|
|
#include "gtkfilterlistmodel.h"
|
|
|
|
#include "gtkflattenlistmodel.h"
|
2020-08-25 19:13:39 +00:00
|
|
|
#include "gtkslicelistmodel.h"
|
2019-11-28 03:00:39 +00:00
|
|
|
#include "gtkmaplistmodel.h"
|
2020-09-08 23:51:12 +00:00
|
|
|
#include "gtklistitem.h"
|
|
|
|
#include "gtksignallistitemfactory.h"
|
|
|
|
#include "gtkstringlist.h"
|
|
|
|
#include "gtklistview.h"
|
|
|
|
#include "gtksortlistmodel.h"
|
|
|
|
#include "gtkstringsorter.h"
|
2022-08-26 02:26:07 +00:00
|
|
|
#include "gtkdropdown.h"
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
#include <hb-ot.h>
|
2019-07-24 12:02:07 +00:00
|
|
|
|
2018-01-03 04:46:37 +00:00
|
|
|
#include "language-names.h"
|
|
|
|
#include "open-type-layout.h"
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-26 21:11:29 +00:00
|
|
|
* GtkFontChooserWidget:
|
2011-09-11 23:49:26 +00:00
|
|
|
*
|
2021-02-26 21:11:29 +00:00
|
|
|
* The `GtkFontChooserWidget` widget lets the user select a font.
|
|
|
|
*
|
|
|
|
* It is used in the `GtkFontChooserDialog` widget to provide a
|
|
|
|
* dialog for selecting fonts.
|
2011-09-11 23:49:26 +00:00
|
|
|
*
|
|
|
|
* To set the font which is initially selected, use
|
2021-02-26 21:11:29 +00:00
|
|
|
* [method@Gtk.FontChooser.set_font] or [method@Gtk.FontChooser.set_font_desc].
|
2011-09-11 23:49:26 +00:00
|
|
|
*
|
2021-02-26 21:11:29 +00:00
|
|
|
* To get the selected font use [method@Gtk.FontChooser.get_font] or
|
|
|
|
* [method@Gtk.FontChooser.get_font_desc].
|
2011-09-11 23:49:26 +00:00
|
|
|
*
|
|
|
|
* To change the text which is shown in the preview area, use
|
2021-02-26 21:11:29 +00:00
|
|
|
* [method@Gtk.FontChooser.set_preview_text].
|
2011-09-11 23:49:26 +00:00
|
|
|
*
|
2016-01-14 04:42:35 +00:00
|
|
|
* # CSS nodes
|
|
|
|
*
|
2021-02-26 21:11:29 +00:00
|
|
|
* `GtkFontChooserWidget` has a single CSS node with name fontchooser.
|
2011-09-11 23:49:26 +00:00
|
|
|
*/
|
|
|
|
|
2019-05-28 00:56:41 +00:00
|
|
|
typedef struct _GtkFontChooserWidgetClass GtkFontChooserWidgetClass;
|
|
|
|
|
|
|
|
struct _GtkFontChooserWidget
|
|
|
|
{
|
|
|
|
GtkWidget parent_instance;
|
|
|
|
|
2018-01-03 03:52:05 +00:00
|
|
|
GtkWidget *stack;
|
2017-03-25 19:49:00 +00:00
|
|
|
GtkWidget *grid;
|
2011-09-11 23:49:26 +00:00
|
|
|
GtkWidget *search_entry;
|
|
|
|
GtkWidget *family_face_list;
|
2015-05-07 22:28:39 +00:00
|
|
|
GtkWidget *list_stack;
|
2019-11-28 03:00:39 +00:00
|
|
|
GtkSingleSelection *selection;
|
|
|
|
GtkCustomFilter *custom_filter;
|
2020-09-08 23:51:12 +00:00
|
|
|
GtkCustomFilter *user_filter;
|
2019-11-28 03:00:39 +00:00
|
|
|
GtkFilterListModel *filter_model;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
GtkWidget *preview;
|
2018-01-03 03:52:05 +00:00
|
|
|
GtkWidget *preview2;
|
|
|
|
GtkWidget *font_name_label;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *preview_text;
|
2011-09-11 23:49:26 +00:00
|
|
|
gboolean show_preview_entry;
|
2020-09-08 19:14:17 +00:00
|
|
|
gboolean preview_text_set;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2017-12-21 15:51:04 +00:00
|
|
|
GtkWidget *size_label;
|
2011-09-11 23:49:26 +00:00
|
|
|
GtkWidget *size_spin;
|
|
|
|
GtkWidget *size_slider;
|
2022-07-03 16:50:40 +00:00
|
|
|
GtkWidget *size_label2;
|
|
|
|
GtkWidget *size_spin2;
|
2018-01-03 03:52:05 +00:00
|
|
|
GtkWidget *size_slider2;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
GtkWidget *axis_grid;
|
2018-01-03 04:46:37 +00:00
|
|
|
GtkWidget *feature_box;
|
|
|
|
|
2020-09-24 09:37:32 +00:00
|
|
|
GtkFrame *language_button;
|
|
|
|
GtkFrame *language_frame;
|
2020-09-08 23:51:12 +00:00
|
|
|
GtkWidget *language_list;
|
|
|
|
GtkStringList *languages;
|
|
|
|
GHashTable *language_table;
|
|
|
|
|
|
|
|
PangoLanguage *filter_language;
|
|
|
|
gboolean filter_by_language;
|
|
|
|
gboolean filter_by_monospace;
|
|
|
|
|
2015-05-05 03:21:17 +00:00
|
|
|
PangoFontMap *font_map;
|
|
|
|
|
2011-09-11 22:13:26 +00:00
|
|
|
PangoFontDescription *font_desc;
|
2018-01-03 04:46:37 +00:00
|
|
|
char *font_features;
|
2018-04-02 17:34:22 +00:00
|
|
|
PangoLanguage *language;
|
2019-11-28 03:00:39 +00:00
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
GtkFontFilterFunc filter_func;
|
|
|
|
gpointer filter_data;
|
|
|
|
GDestroyNotify filter_data_destroy;
|
2015-05-04 12:25:27 +00:00
|
|
|
|
|
|
|
guint last_fontconfig_timestamp;
|
2017-12-21 15:51:04 +00:00
|
|
|
|
|
|
|
GtkFontChooserLevel level;
|
2018-01-03 03:52:05 +00:00
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
GHashTable *axes;
|
|
|
|
gboolean updating_variations;
|
|
|
|
|
2018-01-03 04:46:37 +00:00
|
|
|
GList *feature_items;
|
|
|
|
|
2018-01-03 03:52:05 +00:00
|
|
|
GAction *tweak_action;
|
2021-12-31 14:17:42 +00:00
|
|
|
|
|
|
|
hb_map_t *glyphmap;
|
2011-09-11 23:49:26 +00:00
|
|
|
};
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
struct _GtkFontChooserWidgetClass
|
|
|
|
{
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
};
|
|
|
|
|
2018-03-27 18:50:11 +00:00
|
|
|
enum {
|
|
|
|
PROP_ZERO,
|
|
|
|
PROP_TWEAK_ACTION
|
|
|
|
};
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void gtk_font_chooser_widget_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_font_chooser_widget_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_font_chooser_widget_finalize (GObject *object);
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
static char *gtk_font_chooser_widget_get_font (GtkFontChooserWidget *fontchooser);
|
2011-09-12 11:57:10 +00:00
|
|
|
static void gtk_font_chooser_widget_set_font (GtkFontChooserWidget *fontchooser,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *fontname);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-12 11:57:10 +00:00
|
|
|
static PangoFontDescription *gtk_font_chooser_widget_get_font_desc (GtkFontChooserWidget *fontchooser);
|
2015-07-22 13:04:34 +00:00
|
|
|
static void gtk_font_chooser_widget_merge_font_desc(GtkFontChooserWidget *fontchooser,
|
2019-11-28 03:00:39 +00:00
|
|
|
const PangoFontDescription *font_desc);
|
2011-09-12 11:57:10 +00:00
|
|
|
static void gtk_font_chooser_widget_take_font_desc (GtkFontChooserWidget *fontchooser,
|
2011-09-11 22:13:26 +00:00
|
|
|
PangoFontDescription *font_desc);
|
|
|
|
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
static const char *gtk_font_chooser_widget_get_preview_text (GtkFontChooserWidget *fontchooser);
|
2011-09-11 23:49:26 +00:00
|
|
|
static void gtk_font_chooser_widget_set_preview_text (GtkFontChooserWidget *fontchooser,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *text);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
static gboolean gtk_font_chooser_widget_get_show_preview_entry (GtkFontChooserWidget *fontchooser);
|
|
|
|
static void gtk_font_chooser_widget_set_show_preview_entry (GtkFontChooserWidget *fontchooser,
|
|
|
|
gboolean show_preview_entry);
|
|
|
|
|
2018-01-03 04:46:37 +00:00
|
|
|
static void gtk_font_chooser_widget_populate_features (GtkFontChooserWidget *fontchooser);
|
2017-12-21 15:51:04 +00:00
|
|
|
static void gtk_font_chooser_widget_set_level (GtkFontChooserWidget *fontchooser,
|
|
|
|
GtkFontChooserLevel level);
|
|
|
|
static GtkFontChooserLevel gtk_font_chooser_widget_get_level (GtkFontChooserWidget *fontchooser);
|
2018-04-02 17:34:22 +00:00
|
|
|
static void gtk_font_chooser_widget_set_language (GtkFontChooserWidget *fontchooser,
|
|
|
|
const char *language);
|
2018-01-03 04:46:37 +00:00
|
|
|
static void update_font_features (GtkFontChooserWidget *fontchooser);
|
2013-03-26 09:50:01 +00:00
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void gtk_font_chooser_widget_iface_init (GtkFontChooserIface *iface);
|
|
|
|
|
2017-03-25 19:49:00 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkFontChooserWidget, gtk_font_chooser_widget, GTK_TYPE_WIDGET,
|
2011-09-11 23:49:26 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_FONT_CHOOSER,
|
|
|
|
gtk_font_chooser_widget_iface_init))
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2011-09-05 11:26:49 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_FONT:
|
2011-09-12 11:57:10 +00:00
|
|
|
gtk_font_chooser_widget_set_font (fontchooser, g_value_get_string (value));
|
2011-09-11 23:49:26 +00:00
|
|
|
break;
|
2011-09-11 22:13:26 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_FONT_DESC:
|
2011-09-12 11:57:10 +00:00
|
|
|
gtk_font_chooser_widget_take_font_desc (fontchooser, g_value_dup_boxed (value));
|
2011-09-11 22:13:26 +00:00
|
|
|
break;
|
2011-09-11 23:49:26 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT:
|
|
|
|
gtk_font_chooser_widget_set_preview_text (fontchooser, g_value_get_string (value));
|
2020-09-08 19:14:17 +00:00
|
|
|
fontchooser->preview_text_set = TRUE;
|
2011-09-11 23:49:26 +00:00
|
|
|
break;
|
|
|
|
case GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY:
|
|
|
|
gtk_font_chooser_widget_set_show_preview_entry (fontchooser, g_value_get_boolean (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_chooser_widget_set_level (fontchooser, g_value_get_flags (value));
|
2017-12-21 15:51:04 +00:00
|
|
|
break;
|
2018-04-02 17:34:22 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_LANGUAGE:
|
|
|
|
gtk_font_chooser_widget_set_language (fontchooser, g_value_get_string (value));
|
|
|
|
break;
|
2011-09-11 23:49:26 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2018-03-27 18:50:11 +00:00
|
|
|
case PROP_TWEAK_ACTION:
|
2020-04-26 19:23:21 +00:00
|
|
|
g_value_set_object (value, G_OBJECT (fontchooser->tweak_action));
|
2018-03-27 18:50:11 +00:00
|
|
|
break;
|
2011-09-05 11:26:49 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_FONT:
|
2011-09-12 11:57:10 +00:00
|
|
|
g_value_take_string (value, gtk_font_chooser_widget_get_font (fontchooser));
|
2011-09-11 23:49:26 +00:00
|
|
|
break;
|
2011-09-11 22:13:26 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_FONT_DESC:
|
2011-09-12 11:57:10 +00:00
|
|
|
g_value_set_boxed (value, gtk_font_chooser_widget_get_font_desc (fontchooser));
|
2011-09-11 22:13:26 +00:00
|
|
|
break;
|
2011-09-11 23:49:26 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT:
|
|
|
|
g_value_set_string (value, gtk_font_chooser_widget_get_preview_text (fontchooser));
|
|
|
|
break;
|
|
|
|
case GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY:
|
|
|
|
g_value_set_boolean (value, gtk_font_chooser_widget_get_show_preview_entry (fontchooser));
|
|
|
|
break;
|
2017-12-21 15:51:04 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_LEVEL:
|
2018-03-27 20:10:19 +00:00
|
|
|
g_value_set_flags (value, gtk_font_chooser_widget_get_level (fontchooser));
|
2017-12-21 15:51:04 +00:00
|
|
|
break;
|
2018-01-03 04:52:24 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_FONT_FEATURES:
|
2020-04-26 19:23:21 +00:00
|
|
|
g_value_set_string (value, fontchooser->font_features);
|
2018-01-03 04:52:24 +00:00
|
|
|
break;
|
|
|
|
case GTK_FONT_CHOOSER_PROP_LANGUAGE:
|
2020-04-26 19:23:21 +00:00
|
|
|
g_value_set_string (value, pango_language_to_string (fontchooser->language));
|
2018-01-03 04:52:24 +00:00
|
|
|
break;
|
2011-09-11 23:49:26 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-10 18:15:26 +00:00
|
|
|
static void
|
2019-02-17 19:48:08 +00:00
|
|
|
stop_search_cb (GtkSearchEntry *entry,
|
2015-08-10 18:15:26 +00:00
|
|
|
GtkFontChooserWidget *fc)
|
|
|
|
{
|
2019-02-17 19:48:08 +00:00
|
|
|
if (gtk_editable_get_text (GTK_EDITABLE (entry))[0] != 0)
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (entry), "");
|
2015-08-10 18:32:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *button = NULL;
|
|
|
|
|
|
|
|
dialog = gtk_widget_get_ancestor (GTK_WIDGET (fc), GTK_TYPE_DIALOG);
|
|
|
|
if (dialog)
|
|
|
|
button = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
|
|
|
|
|
|
|
|
if (button)
|
|
|
|
gtk_widget_activate (button);
|
|
|
|
}
|
2015-08-10 18:15:26 +00:00
|
|
|
}
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void
|
2011-09-19 23:17:29 +00:00
|
|
|
size_change_cb (GtkAdjustment *adjustment,
|
2011-09-11 23:49:26 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
2011-09-19 23:17:29 +00:00
|
|
|
GtkFontChooserWidget *fontchooser = user_data;
|
|
|
|
PangoFontDescription *font_desc;
|
2020-07-24 20:32:16 +00:00
|
|
|
double size = gtk_adjustment_get_value (adjustment);
|
2011-09-12 19:26:21 +00:00
|
|
|
|
2011-09-19 23:17:29 +00:00
|
|
|
font_desc = pango_font_description_new ();
|
2020-04-26 19:23:21 +00:00
|
|
|
if (pango_font_description_get_size_is_absolute (fontchooser->font_desc))
|
2011-09-19 23:17:29 +00:00
|
|
|
pango_font_description_set_absolute_size (font_desc, size * PANGO_SCALE);
|
2011-09-12 19:26:21 +00:00
|
|
|
else
|
2011-09-19 23:17:29 +00:00
|
|
|
pango_font_description_set_size (font_desc, size * PANGO_SCALE);
|
2011-09-12 19:26:21 +00:00
|
|
|
|
2011-09-19 23:17:29 +00:00
|
|
|
gtk_font_chooser_widget_take_font_desc (fontchooser, font_desc);
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
2014-08-15 18:57:31 +00:00
|
|
|
static gboolean
|
|
|
|
output_cb (GtkSpinButton *spin,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkAdjustment *adjustment;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *text;
|
2020-07-24 20:32:16 +00:00
|
|
|
double value;
|
2014-08-15 18:57:31 +00:00
|
|
|
|
|
|
|
adjustment = gtk_spin_button_get_adjustment (spin);
|
|
|
|
value = gtk_adjustment_get_value (adjustment);
|
|
|
|
text = g_strdup_printf ("%2.4g", value);
|
2019-02-28 19:31:36 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (spin), text);
|
2014-08-15 18:57:31 +00:00
|
|
|
g_free (text);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-09-08 23:51:12 +00:00
|
|
|
static gboolean
|
|
|
|
user_filter_cb (gpointer item,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (data);
|
|
|
|
PangoFontFamily *family;
|
|
|
|
PangoFontFace *face;
|
|
|
|
|
|
|
|
if (PANGO_IS_FONT_FAMILY (item))
|
|
|
|
{
|
|
|
|
family = item;
|
|
|
|
face = pango_font_family_get_face (family, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
face = PANGO_FONT_FACE (item);
|
|
|
|
family = pango_font_face_get_family (face);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self->filter_by_monospace &&
|
|
|
|
!pango_font_family_is_monospace (family))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (self->filter_by_language &&
|
|
|
|
self->filter_language)
|
|
|
|
{
|
|
|
|
PangoFontDescription *desc;
|
|
|
|
PangoContext *context;
|
|
|
|
PangoFont *font;
|
|
|
|
gboolean ret;
|
2021-12-31 03:35:08 +00:00
|
|
|
PangoLanguage **langs;
|
2020-09-08 23:51:12 +00:00
|
|
|
|
|
|
|
desc = pango_font_face_describe (face);
|
|
|
|
pango_font_description_set_size (desc, 20);
|
|
|
|
|
|
|
|
context = gtk_widget_get_pango_context (GTK_WIDGET (self));
|
|
|
|
font = pango_context_load_font (context, desc);
|
|
|
|
|
2021-12-31 03:35:08 +00:00
|
|
|
ret = FALSE;
|
2020-09-08 23:51:12 +00:00
|
|
|
|
2021-12-31 03:35:08 +00:00
|
|
|
langs = pango_font_get_languages (font);
|
|
|
|
if (langs)
|
2020-09-08 23:51:12 +00:00
|
|
|
{
|
2021-12-31 03:35:08 +00:00
|
|
|
for (int i = 0; langs[i]; i++)
|
|
|
|
{
|
|
|
|
if (langs[i] == self->filter_language)
|
|
|
|
{
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-09-08 23:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (font);
|
|
|
|
pango_font_description_free (desc);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
monospace_check_changed (GtkCheckButton *check,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkFontChooserWidget *self)
|
|
|
|
{
|
|
|
|
self->filter_by_monospace = gtk_check_button_get_active (check);
|
|
|
|
gtk_filter_changed (GTK_FILTER (self->user_filter),
|
|
|
|
self->filter_by_monospace ? GTK_FILTER_CHANGE_MORE_STRICT
|
|
|
|
: GTK_FILTER_CHANGE_LESS_STRICT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
language_check_changed (GtkCheckButton *check,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkFontChooserWidget *self)
|
|
|
|
{
|
|
|
|
self->filter_by_language = gtk_check_button_get_active (check);
|
|
|
|
gtk_filter_changed (GTK_FILTER (self->user_filter),
|
|
|
|
self->filter_by_language ? GTK_FILTER_CHANGE_MORE_STRICT
|
|
|
|
: GTK_FILTER_CHANGE_LESS_STRICT);
|
|
|
|
}
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_font_chooser_widget_update_marks (GtkFontChooserWidget *self)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2013-08-02 13:51:33 +00:00
|
|
|
GtkAdjustment *adj, *spin_adj;
|
2011-09-21 00:40:26 +00:00
|
|
|
const int *sizes;
|
2020-07-24 13:54:49 +00:00
|
|
|
int *font_sizes;
|
|
|
|
int i, n_sizes;
|
2020-07-24 20:32:16 +00:00
|
|
|
double value, spin_value;
|
2019-11-28 03:00:39 +00:00
|
|
|
gpointer item;
|
|
|
|
|
|
|
|
item = gtk_single_selection_get_selected_item (self->selection);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
if (item)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2011-09-21 00:40:26 +00:00
|
|
|
PangoFontFace *face;
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
if (PANGO_IS_FONT_FAMILY (item))
|
|
|
|
face = pango_font_family_get_face (item, NULL);
|
|
|
|
else
|
|
|
|
face = item;
|
2011-09-21 00:40:26 +00:00
|
|
|
|
|
|
|
pango_font_face_list_sizes (face, &font_sizes, &n_sizes);
|
|
|
|
|
|
|
|
/* It seems not many fonts actually have a sane set of sizes */
|
|
|
|
for (i = 0; i < n_sizes; i++)
|
|
|
|
font_sizes[i] = font_sizes[i] / PANGO_SCALE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
font_sizes = NULL;
|
|
|
|
n_sizes = 0;
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
2011-09-21 00:40:26 +00:00
|
|
|
if (n_sizes < 2)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
static const int fallback_sizes[] = {
|
2011-09-21 00:40:26 +00:00
|
|
|
6, 8, 9, 10, 11, 12, 13, 14, 16, 20, 24, 36, 48, 72
|
|
|
|
};
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-21 00:40:26 +00:00
|
|
|
sizes = fallback_sizes;
|
|
|
|
n_sizes = G_N_ELEMENTS (fallback_sizes);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sizes = font_sizes;
|
|
|
|
}
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_scale_clear_marks (GTK_SCALE (self->size_slider));
|
|
|
|
gtk_scale_clear_marks (GTK_SCALE (self->size_slider2));
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
adj = gtk_range_get_adjustment (GTK_RANGE (self->size_slider));
|
|
|
|
spin_adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (self->size_spin));
|
2013-08-02 13:51:33 +00:00
|
|
|
spin_value = gtk_adjustment_get_value (spin_adj);
|
|
|
|
|
|
|
|
if (spin_value < sizes[0])
|
2020-07-24 20:32:16 +00:00
|
|
|
value = (double) sizes[0];
|
2013-08-02 13:51:33 +00:00
|
|
|
else if (spin_value > sizes[n_sizes - 1])
|
2020-07-24 20:32:16 +00:00
|
|
|
value = (double)sizes[n_sizes - 1];
|
2013-08-02 13:51:33 +00:00
|
|
|
else
|
2020-07-24 20:32:16 +00:00
|
|
|
value = (double)spin_value;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-21 00:40:26 +00:00
|
|
|
/* ensure clamping doesn't callback into font resizing code */
|
2019-11-28 03:00:39 +00:00
|
|
|
g_signal_handlers_block_by_func (adj, size_change_cb, self);
|
2011-09-21 00:40:26 +00:00
|
|
|
gtk_adjustment_configure (adj,
|
2013-08-02 13:51:33 +00:00
|
|
|
value,
|
2011-09-21 00:40:26 +00:00
|
|
|
sizes[0],
|
|
|
|
sizes[n_sizes - 1],
|
|
|
|
gtk_adjustment_get_step_increment (adj),
|
|
|
|
gtk_adjustment_get_page_increment (adj),
|
|
|
|
gtk_adjustment_get_page_size (adj));
|
2019-11-28 03:00:39 +00:00
|
|
|
g_signal_handlers_unblock_by_func (adj, size_change_cb, self);
|
2011-09-21 00:40:26 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n_sizes; i++)
|
|
|
|
{
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_scale_add_mark (GTK_SCALE (self->size_slider),
|
2011-09-21 00:40:26 +00:00
|
|
|
sizes[i],
|
|
|
|
GTK_POS_BOTTOM, NULL);
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_scale_add_mark (GTK_SCALE (self->size_slider2),
|
2018-01-03 03:52:05 +00:00
|
|
|
sizes[i],
|
|
|
|
GTK_POS_BOTTOM, NULL);
|
2011-09-21 00:40:26 +00:00
|
|
|
}
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-21 00:40:26 +00:00
|
|
|
g_free (font_sizes);
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-28 03:00:39 +00:00
|
|
|
row_activated_cb (GtkWidget *view,
|
|
|
|
guint pos,
|
|
|
|
gpointer user_data)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2011-09-12 11:57:10 +00:00
|
|
|
GtkFontChooserWidget *fontchooser = user_data;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *fontname;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-12 11:57:10 +00:00
|
|
|
fontname = gtk_font_chooser_widget_get_font (fontchooser);
|
|
|
|
_gtk_font_chooser_font_activated (GTK_FONT_CHOOSER (fontchooser), fontname);
|
2011-09-11 23:49:26 +00:00
|
|
|
g_free (fontname);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-28 03:00:39 +00:00
|
|
|
resize_by_scroll_cb (GtkEventControllerScroll *controller,
|
|
|
|
double dx,
|
|
|
|
double dy,
|
|
|
|
gpointer user_data)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2019-11-28 03:00:39 +00:00
|
|
|
GtkFontChooserWidget *self = user_data;
|
|
|
|
GtkAdjustment *adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (self->size_spin));
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_adjustment_set_value (adj,
|
|
|
|
gtk_adjustment_get_value (adj) +
|
|
|
|
gtk_adjustment_get_step_increment (adj) * dx);
|
|
|
|
}
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2020-09-08 19:14:17 +00:00
|
|
|
static void
|
|
|
|
maybe_update_preview_text (GtkFontChooserWidget *self,
|
|
|
|
PangoFontFace *face,
|
|
|
|
PangoFontDescription *desc)
|
|
|
|
{
|
|
|
|
PangoContext *context;
|
|
|
|
PangoFont *font;
|
|
|
|
const char *sample;
|
2021-12-31 03:35:08 +00:00
|
|
|
PangoLanguage **languages;
|
|
|
|
GHashTable *langs = NULL;
|
|
|
|
PangoLanguage *default_lang;
|
|
|
|
PangoLanguage *alt_default = NULL;
|
|
|
|
PangoLanguage *lang = NULL;
|
|
|
|
int i;
|
|
|
|
const char *p;
|
2020-09-08 19:14:17 +00:00
|
|
|
|
|
|
|
/* If the user has typed text into the entry, we don't touch it */
|
|
|
|
if (self->preview_text_set)
|
|
|
|
return;
|
|
|
|
|
2020-09-09 16:38:35 +00:00
|
|
|
if (self->filter_by_language && self->filter_language)
|
|
|
|
{
|
|
|
|
sample = pango_language_get_sample_string (self->filter_language);
|
|
|
|
gtk_font_chooser_widget_set_preview_text (self, sample);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-08 19:14:17 +00:00
|
|
|
/* We do the work only once, and cache the result on the PangoFontFace */
|
|
|
|
sample = (const char *)g_object_get_data (G_OBJECT (face), "gtk-sample-text");
|
|
|
|
if (sample)
|
|
|
|
{
|
|
|
|
gtk_font_chooser_widget_set_preview_text (self, sample);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
context = gtk_widget_get_pango_context (GTK_WIDGET (self));
|
|
|
|
font = pango_context_load_font (context, desc);
|
|
|
|
|
2021-12-31 03:35:08 +00:00
|
|
|
default_lang = pango_language_get_default ();
|
|
|
|
p = pango_language_to_string (default_lang);
|
|
|
|
|
|
|
|
/* The default language tends to be of the form en-us.
|
|
|
|
* Since fontconfig languages just have the language part,
|
|
|
|
* and we want to use direct pointer comparisons, we need
|
|
|
|
* an PangoLanguage for the shortened default language.
|
|
|
|
*/
|
|
|
|
if (strchr (p, '-'))
|
2020-09-08 19:14:17 +00:00
|
|
|
{
|
2021-12-31 03:35:08 +00:00
|
|
|
char q[10];
|
|
|
|
for (i = 0; p[i] != '-' && i < 9; i++)
|
|
|
|
q[i] = p[i];
|
|
|
|
q[i] = '\0';
|
|
|
|
alt_default = pango_language_from_string (q);
|
|
|
|
}
|
2020-09-08 19:14:17 +00:00
|
|
|
|
2021-12-31 03:35:08 +00:00
|
|
|
languages = pango_font_get_languages (font);
|
2020-09-08 19:14:17 +00:00
|
|
|
|
2021-12-31 03:35:08 +00:00
|
|
|
/* If the font supports the default language, just use it. */
|
|
|
|
if (languages)
|
|
|
|
for (i = 0; languages[i]; i++)
|
|
|
|
{
|
|
|
|
if (languages[i] == default_lang || languages[i] == alt_default)
|
2021-08-02 02:43:43 +00:00
|
|
|
{
|
2021-12-31 03:35:08 +00:00
|
|
|
lang = default_lang;
|
|
|
|
goto found;
|
2021-08-02 02:43:43 +00:00
|
|
|
}
|
2021-12-31 03:35:08 +00:00
|
|
|
}
|
2020-09-08 19:14:17 +00:00
|
|
|
|
2021-12-31 03:35:08 +00:00
|
|
|
/* Otherwise, we make a list of representative languages */
|
|
|
|
langs = g_hash_table_new (NULL, NULL);
|
2020-09-08 19:14:17 +00:00
|
|
|
|
2021-12-31 14:49:40 +00:00
|
|
|
if (languages)
|
|
|
|
for (i = 0; languages[i]; i++)
|
|
|
|
{
|
|
|
|
const PangoScript *scripts;
|
|
|
|
int num, j;
|
2020-09-08 19:14:17 +00:00
|
|
|
|
2021-12-31 14:49:40 +00:00
|
|
|
scripts = pango_language_get_scripts (languages[i], &num);
|
|
|
|
for (j = 0; j < num; j++)
|
|
|
|
{
|
|
|
|
lang = pango_script_get_sample_language (scripts[j]);
|
|
|
|
if (lang)
|
|
|
|
g_hash_table_add (langs, lang);
|
|
|
|
}
|
|
|
|
}
|
2020-09-08 19:14:17 +00:00
|
|
|
|
2021-12-31 03:35:08 +00:00
|
|
|
/* ... and compare it to the users default and preferred languages */
|
|
|
|
if (g_hash_table_contains (langs, default_lang) ||
|
|
|
|
g_hash_table_contains (langs, alt_default))
|
|
|
|
{
|
|
|
|
lang = default_lang;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PangoLanguage **preferred;
|
|
|
|
|
|
|
|
preferred = pango_language_get_preferred ();
|
|
|
|
if (preferred)
|
|
|
|
{
|
|
|
|
for (i = 0; preferred[i]; i++)
|
2020-09-08 19:14:17 +00:00
|
|
|
{
|
2021-12-31 03:35:08 +00:00
|
|
|
if (g_hash_table_contains (langs, preferred[i]))
|
2020-09-08 19:14:17 +00:00
|
|
|
{
|
2021-12-31 03:35:08 +00:00
|
|
|
lang = preferred[i];
|
|
|
|
break;
|
2020-09-08 19:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-31 03:35:08 +00:00
|
|
|
|
2020-09-08 19:14:17 +00:00
|
|
|
g_hash_table_unref (langs);
|
|
|
|
|
|
|
|
found:
|
|
|
|
sample = pango_language_get_sample_string (lang);
|
|
|
|
gtk_font_chooser_widget_set_preview_text (self, sample);
|
|
|
|
g_object_set_data (G_OBJECT (face), "gtk-sample-text", (gpointer)sample);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (font);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
static void
|
|
|
|
selection_changed_cb (GtkSingleSelection *selection,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkFontChooserWidget *self)
|
|
|
|
{
|
|
|
|
gpointer item;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
item = gtk_single_selection_get_selected_item (selection);
|
|
|
|
if (item)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2019-11-28 03:00:39 +00:00
|
|
|
PangoFontFace *face;
|
|
|
|
PangoFontDescription *desc;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
if (PANGO_IS_FONT_FAMILY (item))
|
|
|
|
face = pango_font_family_get_face (item, NULL);
|
|
|
|
else
|
|
|
|
face = item;
|
|
|
|
desc = pango_font_face_describe (face);
|
|
|
|
pango_font_description_set_variations (self->font_desc, NULL);
|
|
|
|
gtk_font_chooser_widget_merge_font_desc (self, desc);
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (self->tweak_action), TRUE);
|
2020-09-08 19:14:17 +00:00
|
|
|
|
|
|
|
maybe_update_preview_text (self, face, desc);
|
|
|
|
|
|
|
|
pango_font_description_free (desc);
|
2019-11-28 03:00:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_simple_action_set_state (G_SIMPLE_ACTION (self->tweak_action), g_variant_new_boolean (FALSE));
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (self->tweak_action), FALSE);
|
|
|
|
}
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
g_object_notify (G_OBJECT (self), "font");
|
|
|
|
g_object_notify (G_OBJECT (self), "font-desc");
|
|
|
|
}
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
static char *
|
|
|
|
get_font_name (GObject *ignore,
|
|
|
|
gpointer item)
|
|
|
|
{
|
|
|
|
if (item == NULL)
|
|
|
|
return NULL;
|
2015-07-22 13:04:34 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
if (PANGO_IS_FONT_FACE (item))
|
|
|
|
{
|
|
|
|
return g_strconcat (pango_font_family_get_name (pango_font_face_get_family (item)),
|
|
|
|
" ",
|
|
|
|
pango_font_face_get_face_name (item),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return g_strdup (pango_font_family_get_name (item));
|
|
|
|
}
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
static PangoAttrList *
|
|
|
|
get_font_attributes (GObject *ignore,
|
|
|
|
gpointer item)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2019-11-28 03:00:39 +00:00
|
|
|
PangoAttribute *attribute;
|
|
|
|
PangoAttrList *attrs;
|
2013-07-21 18:46:30 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
PangoFontFace *face;
|
|
|
|
PangoFontDescription *font_desc;
|
|
|
|
|
|
|
|
if (PANGO_IS_FONT_FAMILY (item))
|
|
|
|
face = pango_font_family_get_face (item, NULL);
|
|
|
|
else
|
|
|
|
face = item;
|
2020-09-20 14:39:24 +00:00
|
|
|
if (face)
|
|
|
|
{
|
|
|
|
font_desc = pango_font_face_describe (face);
|
|
|
|
attribute = pango_attr_font_desc_new (font_desc);
|
|
|
|
pango_attr_list_insert (attrs, attribute);
|
|
|
|
pango_font_description_free (font_desc);
|
|
|
|
}
|
2019-11-28 03:00:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return attrs;
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
2014-10-03 04:17:12 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_update_preview_attributes (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
|
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
|
|
|
|
/* Prevent font fallback */
|
|
|
|
pango_attr_list_insert (attrs, pango_attr_fallback_new (FALSE));
|
|
|
|
|
2018-01-03 04:46:37 +00:00
|
|
|
/* Force current font and features */
|
2020-04-26 19:23:21 +00:00
|
|
|
pango_attr_list_insert (attrs, pango_attr_font_desc_new (fontchooser->font_desc));
|
|
|
|
if (fontchooser->font_features)
|
|
|
|
pango_attr_list_insert (attrs, pango_attr_font_features_new (fontchooser->font_features));
|
|
|
|
if (fontchooser->language)
|
|
|
|
pango_attr_list_insert (attrs, pango_attr_language_new (fontchooser->language));
|
2014-10-03 04:17:12 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_entry_set_attributes (GTK_ENTRY (fontchooser->preview), attrs);
|
2018-01-03 03:52:05 +00:00
|
|
|
|
2014-10-03 04:17:12 +00:00
|
|
|
pango_attr_list_unref (attrs);
|
|
|
|
}
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void
|
2019-11-28 03:00:39 +00:00
|
|
|
rows_changed_cb (GtkFontChooserWidget *self)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2018-01-03 03:52:05 +00:00
|
|
|
const char *page;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2020-09-19 14:25:45 +00:00
|
|
|
if (g_list_model_get_n_items (G_LIST_MODEL (self->selection)) == 0 &&
|
|
|
|
gtk_filter_list_model_get_pending (GTK_FILTER_LIST_MODEL (self->filter_model)) == 0)
|
2018-01-03 03:52:05 +00:00
|
|
|
page = "empty";
|
2017-12-19 16:37:05 +00:00
|
|
|
else
|
2018-01-03 03:52:05 +00:00
|
|
|
page = "list";
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
if (strcmp (gtk_stack_get_visible_child_name (GTK_STACK (self->list_stack)), page) != 0)
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (self->list_stack), page);
|
2018-01-03 03:52:05 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 15:59:45 +00:00
|
|
|
static void
|
|
|
|
update_key_capture (GtkWidget *chooser)
|
|
|
|
{
|
2019-05-28 02:27:47 +00:00
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
|
2019-04-27 15:59:45 +00:00
|
|
|
GtkWidget *capture_widget;
|
|
|
|
|
|
|
|
if (gtk_widget_get_mapped (chooser) &&
|
2020-04-26 19:23:21 +00:00
|
|
|
g_str_equal (gtk_stack_get_visible_child_name (GTK_STACK (fontchooser->stack)), "list"))
|
2019-04-27 15:59:45 +00:00
|
|
|
{
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
GtkWidget *focus;
|
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
toplevel = GTK_WIDGET (gtk_widget_get_root (chooser));
|
2019-04-27 15:59:45 +00:00
|
|
|
focus = gtk_root_get_focus (GTK_ROOT (toplevel));
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
if (GTK_IS_EDITABLE (focus) && focus != fontchooser->search_entry)
|
2019-04-27 15:59:45 +00:00
|
|
|
capture_widget = NULL;
|
|
|
|
else
|
|
|
|
capture_widget = chooser;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
capture_widget = NULL;
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (fontchooser->search_entry),
|
2019-04-27 15:59:45 +00:00
|
|
|
capture_widget);
|
|
|
|
}
|
|
|
|
|
2018-01-03 03:52:05 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (widget);
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (fontchooser->search_entry), "");
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (fontchooser->stack), "list");
|
|
|
|
g_simple_action_set_state (G_SIMPLE_ACTION (fontchooser->tweak_action), g_variant_new_boolean (FALSE));
|
2018-01-03 03:52:05 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->map (widget);
|
2019-04-27 15:59:45 +00:00
|
|
|
|
|
|
|
update_key_capture (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_unmap (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
update_key_capture (widget);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->unmap (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_root (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->root (widget);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (gtk_widget_get_root (widget), "notify::focus-widget",
|
|
|
|
G_CALLBACK (update_key_capture), widget);
|
2019-11-28 03:00:39 +00:00
|
|
|
}
|
2019-04-27 15:59:45 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_unroot (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (gtk_widget_get_root (widget),
|
|
|
|
update_key_capture, widget);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->unroot (widget);
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 19:49:00 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (object);
|
|
|
|
|
2020-09-19 14:44:50 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (self->selection, rows_changed_cb, self);
|
|
|
|
g_signal_handlers_disconnect_by_func (self->filter_model, rows_changed_cb, self);
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
self->filter_func = NULL;
|
|
|
|
g_clear_pointer (&self->filter_data, self->filter_data_destroy);
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
g_clear_pointer (&self->stack, gtk_widget_unparent);
|
2020-09-08 23:51:12 +00:00
|
|
|
g_clear_pointer (&self->language_table, g_hash_table_unref);
|
2017-03-25 19:49:00 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_font_chooser_widget_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2013-03-26 09:50:01 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2018-03-27 18:50:11 +00:00
|
|
|
GParamSpec *pspec;
|
2013-03-26 09:50:01 +00:00
|
|
|
|
2015-12-04 21:59:29 +00:00
|
|
|
g_type_ensure (G_TYPE_THEMED_ICON);
|
2015-07-22 13:04:34 +00:00
|
|
|
|
2019-04-27 15:59:45 +00:00
|
|
|
widget_class->root = gtk_font_chooser_widget_root;
|
|
|
|
widget_class->unroot = gtk_font_chooser_widget_unroot;
|
2018-01-03 03:52:05 +00:00
|
|
|
widget_class->map = gtk_font_chooser_widget_map;
|
2019-04-27 15:59:45 +00:00
|
|
|
widget_class->unmap = gtk_font_chooser_widget_unmap;
|
2013-03-26 09:50:01 +00:00
|
|
|
|
|
|
|
gobject_class->finalize = gtk_font_chooser_widget_finalize;
|
2017-03-25 19:49:00 +00:00
|
|
|
gobject_class->dispose = gtk_font_chooser_widget_dispose;
|
2013-03-26 09:50:01 +00:00
|
|
|
gobject_class->set_property = gtk_font_chooser_widget_set_property;
|
|
|
|
gobject_class->get_property = gtk_font_chooser_widget_get_property;
|
|
|
|
|
2018-03-27 18:50:11 +00:00
|
|
|
/**
|
|
|
|
* GtkFontChooserWidget:tweak-action:
|
|
|
|
*
|
|
|
|
* A toggle action that can be used to switch to the tweak page
|
|
|
|
* of the font chooser widget, which lets the user tweak the
|
|
|
|
* OpenType features and variation axes of the selected font.
|
|
|
|
*
|
|
|
|
* The action will be enabled or disabled depending on whether
|
|
|
|
* the selected font has any features or axes.
|
|
|
|
*/
|
2022-05-11 12:19:39 +00:00
|
|
|
pspec = g_param_spec_object ("tweak-action", NULL, NULL,
|
2018-03-27 18:50:11 +00:00
|
|
|
G_TYPE_ACTION,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TWEAK_ACTION, pspec);
|
|
|
|
|
2013-03-26 09:50:01 +00:00
|
|
|
_gtk_font_chooser_install_properties (gobject_class);
|
|
|
|
|
2013-07-26 12:41:09 +00:00
|
|
|
/* Bind class to template */
|
2013-03-26 09:50:01 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class,
|
2014-01-23 23:59:20 +00:00
|
|
|
"/org/gtk/libgtk/ui/gtkfontchooserwidget.ui");
|
2013-03-26 09:50:01 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, search_entry);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, family_face_list);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, list_stack);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, filter_model);
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, selection);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, custom_filter);
|
2020-09-08 23:51:12 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, user_filter);
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, preview);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, preview2);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, size_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, size_spin);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, size_slider);
|
2022-07-03 16:50:40 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, size_label2);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, size_spin2);
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, size_slider2);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, stack);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, grid);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, font_name_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, feature_box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, axis_grid);
|
2020-09-24 09:37:32 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, language_button);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, language_frame);
|
2020-09-08 23:51:12 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, language_list);
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, get_font_name);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, get_font_attributes);
|
2015-08-10 18:15:26 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, stop_search_cb);
|
2013-07-26 17:49:49 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, row_activated_cb);
|
2017-12-19 16:37:05 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, rows_changed_cb);
|
2013-07-26 17:49:49 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, size_change_cb);
|
2014-08-15 18:57:31 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, output_cb);
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, selection_changed_cb);
|
2018-03-10 17:29:57 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, resize_by_scroll_cb);
|
2020-09-08 23:51:12 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, monospace_check_changed);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, language_check_changed);
|
2018-03-28 04:57:28 +00:00
|
|
|
|
2019-09-23 15:02:03 +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_("fontchooser"));
|
2013-03-26 09:50:01 +00:00
|
|
|
}
|
|
|
|
|
2018-01-03 03:52:05 +00:00
|
|
|
static void
|
|
|
|
change_tweak (GSimpleAction *action,
|
|
|
|
GVariant *state,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = data;
|
|
|
|
gboolean tweak = g_variant_get_boolean (state);
|
|
|
|
|
|
|
|
if (tweak)
|
|
|
|
{
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_entry_grab_focus_without_selecting (GTK_ENTRY (fontchooser->preview2));
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (fontchooser->stack), "tweaks");
|
2018-01-03 03:52:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_widget_grab_focus (fontchooser->search_entry);
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (fontchooser->stack), "list");
|
2018-01-03 03:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_simple_action_set_state (action, state);
|
|
|
|
}
|
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
typedef struct {
|
|
|
|
guint32 tag;
|
2021-11-27 15:10:53 +00:00
|
|
|
float default_value;
|
2018-01-03 18:28:33 +00:00
|
|
|
GtkAdjustment *adjustment;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *scale;
|
|
|
|
GtkWidget *spin;
|
|
|
|
GtkWidget *fontchooser;
|
|
|
|
} Axis;
|
|
|
|
|
|
|
|
static guint
|
|
|
|
axis_hash (gconstpointer v)
|
|
|
|
{
|
|
|
|
const Axis *a = v;
|
|
|
|
|
|
|
|
return a->tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
axis_equal (gconstpointer v1, gconstpointer v2)
|
|
|
|
{
|
|
|
|
const Axis *a1 = v1;
|
|
|
|
const Axis *a2 = v2;
|
|
|
|
|
|
|
|
return a1->tag == a2->tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
axis_remove (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2020-05-09 14:33:02 +00:00
|
|
|
GtkFontChooserWidget *fontchooser = data;
|
2018-01-03 18:28:33 +00:00
|
|
|
Axis *a = value;
|
|
|
|
|
2020-05-07 18:23:36 +00:00
|
|
|
gtk_grid_remove (GTK_GRID (fontchooser->axis_grid), a->label);
|
|
|
|
gtk_grid_remove (GTK_GRID (fontchooser->axis_grid), a->scale);
|
|
|
|
gtk_grid_remove (GTK_GRID (fontchooser->axis_grid), a->spin);
|
2018-01-03 18:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
axis_free (gpointer v)
|
|
|
|
{
|
|
|
|
Axis *a = v;
|
|
|
|
|
|
|
|
g_free (a);
|
|
|
|
}
|
|
|
|
|
2020-09-08 23:51:12 +00:00
|
|
|
static void
|
|
|
|
select_added (GListModel *model,
|
|
|
|
guint position,
|
|
|
|
guint removed,
|
|
|
|
guint added,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkSingleSelection *selection = GTK_SINGLE_SELECTION (model);
|
|
|
|
|
|
|
|
g_assert (removed == 0);
|
|
|
|
g_assert (added == 1);
|
|
|
|
|
|
|
|
gtk_single_selection_set_selected (selection, position);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_languages_from_font (GtkFontChooserWidget *self,
|
|
|
|
gpointer item)
|
|
|
|
{
|
|
|
|
PangoFontFace *face;
|
|
|
|
PangoFontDescription *desc;
|
|
|
|
PangoFont *font;
|
|
|
|
PangoContext *context;
|
2021-12-31 03:35:08 +00:00
|
|
|
GtkSelectionModel *model = gtk_list_view_get_model (GTK_LIST_VIEW (self->language_list));
|
|
|
|
PangoLanguage *default_lang = pango_language_get_default ();
|
|
|
|
PangoLanguage **langs;
|
|
|
|
int i;
|
2020-09-08 23:51:12 +00:00
|
|
|
|
|
|
|
if (PANGO_IS_FONT_FAMILY (item))
|
|
|
|
face = pango_font_family_get_face (PANGO_FONT_FAMILY (item), NULL);
|
|
|
|
else
|
|
|
|
face = PANGO_FONT_FACE (item);
|
|
|
|
|
2020-09-20 14:39:24 +00:00
|
|
|
if (!face)
|
|
|
|
return;
|
|
|
|
|
2020-09-08 23:51:12 +00:00
|
|
|
desc = pango_font_face_describe (face);
|
|
|
|
pango_font_description_set_size (desc, 20);
|
|
|
|
|
|
|
|
context = gtk_widget_get_pango_context (GTK_WIDGET (self));
|
|
|
|
font = pango_context_load_font (context, desc);
|
|
|
|
|
2021-12-31 03:35:08 +00:00
|
|
|
langs = pango_font_get_languages (font);
|
|
|
|
if (langs)
|
2020-09-08 23:51:12 +00:00
|
|
|
{
|
2021-12-31 03:35:08 +00:00
|
|
|
for (i = 0; langs[i]; i++)
|
|
|
|
{
|
|
|
|
if (!g_hash_table_contains (self->language_table, langs[i]))
|
|
|
|
{
|
|
|
|
g_hash_table_add (self->language_table, langs[i]);
|
|
|
|
if (get_language_name (langs[i]))
|
|
|
|
{
|
|
|
|
const char *l = pango_language_to_string (langs[i]);
|
|
|
|
gulong id = 0;
|
2020-09-08 23:51:12 +00:00
|
|
|
|
2021-12-31 03:35:08 +00:00
|
|
|
/* Pre-select the default language */
|
|
|
|
if (pango_language_matches (default_lang, l))
|
|
|
|
id = g_signal_connect (model, "items-changed", G_CALLBACK (select_added), NULL);
|
|
|
|
|
|
|
|
gtk_string_list_append (self->languages, l);
|
|
|
|
|
|
|
|
if (id)
|
|
|
|
g_signal_handler_disconnect (model, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-08 23:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (font);
|
|
|
|
pango_font_description_free (desc);
|
|
|
|
}
|
|
|
|
|
2021-03-02 22:55:30 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_font_chooser_widget_ensure_matching_selection (GtkFontChooserWidget *self);
|
|
|
|
|
2020-08-25 19:13:39 +00:00
|
|
|
/* We incrementally populate our fontlist to prevent blocking
|
|
|
|
* the font chooser for a long time with expensive FcFontSort
|
|
|
|
* calls in pango for every row in the list).
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
add_to_fontlist (GtkWidget *widget,
|
|
|
|
GdkFrameClock *clock,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (widget);
|
|
|
|
GtkSliceListModel *model = user_data;
|
|
|
|
GListModel *child_model;
|
2020-09-24 09:37:32 +00:00
|
|
|
guint i G_GNUC_UNUSED;
|
|
|
|
guint n G_GNUC_UNUSED;
|
2020-08-25 19:13:39 +00:00
|
|
|
|
|
|
|
if (gtk_filter_list_model_get_model (self->filter_model) != G_LIST_MODEL (model))
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
|
|
|
|
child_model = gtk_slice_list_model_get_model (model);
|
|
|
|
|
|
|
|
n = gtk_slice_list_model_get_size (model);
|
|
|
|
|
2020-09-08 23:51:12 +00:00
|
|
|
for (i = n; i < n + 10; i++)
|
|
|
|
{
|
|
|
|
gpointer item = g_list_model_get_item (child_model, i);
|
|
|
|
if (!item)
|
|
|
|
break;
|
|
|
|
add_languages_from_font (self, item);
|
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
|
2020-08-25 19:13:39 +00:00
|
|
|
n += 10;
|
|
|
|
|
|
|
|
if (n >= g_list_model_get_n_items (child_model))
|
|
|
|
n = G_MAXUINT;
|
|
|
|
|
|
|
|
gtk_slice_list_model_set_size (model, n);
|
|
|
|
|
2021-03-02 22:55:30 +00:00
|
|
|
if (gtk_single_selection_get_selected (GTK_SINGLE_SELECTION (self->selection)) == GTK_INVALID_LIST_POSITION)
|
|
|
|
gtk_font_chooser_widget_ensure_matching_selection (self);
|
|
|
|
|
2020-08-25 19:13:39 +00:00
|
|
|
if (n == G_MAXUINT)
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
else
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void
|
2019-11-28 03:00:39 +00:00
|
|
|
update_fontlist (GtkFontChooserWidget *self)
|
|
|
|
{
|
|
|
|
PangoFontMap *fontmap;
|
|
|
|
GListModel *model;
|
|
|
|
|
|
|
|
fontmap = self->font_map;
|
|
|
|
if (!fontmap)
|
|
|
|
fontmap = pango_cairo_font_map_get_default ();
|
|
|
|
|
|
|
|
if ((self->level & GTK_FONT_CHOOSER_LEVEL_STYLE) == 0)
|
2022-01-01 20:35:23 +00:00
|
|
|
model = g_object_ref (G_LIST_MODEL (fontmap));
|
2019-11-28 03:00:39 +00:00
|
|
|
else
|
2022-01-01 20:35:23 +00:00
|
|
|
model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (g_object_ref (fontmap))));
|
2020-08-25 19:13:39 +00:00
|
|
|
|
|
|
|
model = G_LIST_MODEL (gtk_slice_list_model_new (model, 0, 20));
|
|
|
|
gtk_widget_add_tick_callback (GTK_WIDGET (self), add_to_fontlist, g_object_ref (model), g_object_unref);
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_filter_list_model_set_model (self->filter_model, model);
|
|
|
|
g_object_unref (model);
|
|
|
|
}
|
|
|
|
|
2020-09-08 23:51:12 +00:00
|
|
|
static void
|
|
|
|
setup_lang_item (GtkSignalListItemFactory *factory,
|
|
|
|
gpointer item,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0);
|
|
|
|
gtk_list_item_set_child (GTK_LIST_ITEM (item), label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_lang_item (GtkSignalListItemFactory *factory,
|
|
|
|
gpointer item,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
gpointer obj;
|
|
|
|
const char *str;
|
|
|
|
PangoLanguage *language;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
obj = gtk_list_item_get_item (GTK_LIST_ITEM (item));
|
|
|
|
str = gtk_string_object_get_string (GTK_STRING_OBJECT (obj));
|
2020-09-24 09:37:32 +00:00
|
|
|
|
2020-09-08 23:51:12 +00:00
|
|
|
language = pango_language_from_string (str);
|
|
|
|
name = get_language_name (language);
|
|
|
|
|
|
|
|
label = gtk_list_item_get_child (GTK_LIST_ITEM (item));
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
get_lang_name (gpointer this,
|
|
|
|
const char *lang)
|
|
|
|
{
|
|
|
|
return g_strdup (get_language_name (pango_language_from_string (lang)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
language_selection_changed (GtkSelectionModel *model,
|
|
|
|
guint position,
|
|
|
|
guint n_items,
|
|
|
|
GtkFontChooserWidget *self)
|
|
|
|
{
|
|
|
|
gpointer obj;
|
|
|
|
|
|
|
|
obj = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (model));
|
|
|
|
|
|
|
|
if (obj)
|
|
|
|
self->filter_language = pango_language_from_string (gtk_string_object_get_string (obj));
|
|
|
|
else
|
|
|
|
self->filter_language = NULL;
|
|
|
|
|
|
|
|
if (self->filter_by_language)
|
|
|
|
gtk_filter_changed (GTK_FILTER (self->user_filter), GTK_FILTER_CHANGE_DIFFERENT);
|
|
|
|
}
|
|
|
|
|
2020-09-24 09:37:32 +00:00
|
|
|
static gboolean
|
2020-09-08 23:51:12 +00:00
|
|
|
setup_language_list (GtkFontChooserWidget *self)
|
|
|
|
{
|
|
|
|
GtkListItemFactory *factory;
|
|
|
|
GtkExpression *expression;
|
|
|
|
GListModel *model;
|
|
|
|
GtkSelectionModel *selection;
|
|
|
|
|
|
|
|
self->languages = gtk_string_list_new (NULL);
|
|
|
|
self->language_table = g_hash_table_new (NULL, NULL);
|
|
|
|
|
|
|
|
expression = gtk_property_expression_new (GTK_TYPE_STRING_OBJECT, NULL, "string");
|
|
|
|
expression = gtk_cclosure_expression_new (G_TYPE_STRING, NULL, 1, &expression, (GCallback)get_lang_name, NULL, NULL);
|
|
|
|
|
|
|
|
model = G_LIST_MODEL (gtk_sort_list_model_new (G_LIST_MODEL (self->languages),
|
|
|
|
GTK_SORTER (gtk_string_sorter_new (expression))));
|
|
|
|
|
|
|
|
selection = GTK_SELECTION_MODEL (gtk_single_selection_new (model));
|
|
|
|
g_signal_connect (selection, "selection-changed", G_CALLBACK (language_selection_changed), self);
|
|
|
|
gtk_list_view_set_model (GTK_LIST_VIEW (self->language_list), selection);
|
|
|
|
g_object_unref (selection);
|
|
|
|
|
|
|
|
factory = gtk_signal_list_item_factory_new ();
|
|
|
|
g_signal_connect (factory, "setup", G_CALLBACK (setup_lang_item), self);
|
|
|
|
g_signal_connect (factory, "bind", G_CALLBACK (bind_lang_item), self);
|
|
|
|
gtk_list_view_set_factory (GTK_LIST_VIEW (self->language_list), factory);
|
|
|
|
g_object_unref (factory);
|
2020-09-24 09:37:32 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2020-09-08 23:51:12 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_init (GtkFontChooserWidget *self)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
2013-03-26 09:50:01 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
self->axes = g_hash_table_new_full (axis_hash, axis_equal, NULL, axis_free);
|
2018-01-03 18:28:33 +00:00
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
/* Default preview string */
|
2019-11-28 03:00:39 +00:00
|
|
|
self->preview_text = g_strdup (pango_language_get_sample_string (NULL));
|
|
|
|
self->show_preview_entry = TRUE;
|
|
|
|
self->font_desc = pango_font_description_new ();
|
|
|
|
self->level = GTK_FONT_CHOOSER_LEVEL_FAMILY |
|
2018-03-27 20:10:19 +00:00
|
|
|
GTK_FONT_CHOOSER_LEVEL_STYLE |
|
2018-04-01 01:01:47 +00:00
|
|
|
GTK_FONT_CHOOSER_LEVEL_SIZE;
|
2019-11-28 03:00:39 +00:00
|
|
|
self->language = pango_language_get_default ();
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
/* Set default preview text */
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (self->preview), self->preview_text);
|
2014-08-15 21:29:34 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_font_chooser_widget_update_preview_attributes (self);
|
2014-08-15 21:29:34 +00:00
|
|
|
|
2013-03-26 09:50:01 +00:00
|
|
|
/* Set the upper values of the spin/scale with G_MAXINT / PANGO_SCALE */
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_spin_button_set_range (GTK_SPIN_BUTTON (self->size_spin),
|
2020-07-24 20:32:16 +00:00
|
|
|
1.0, (double)(G_MAXINT / PANGO_SCALE));
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_adjustment_set_upper (gtk_range_get_adjustment (GTK_RANGE (self->size_slider)),
|
2020-07-24 20:32:16 +00:00
|
|
|
(double)(G_MAXINT / PANGO_SCALE));
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
self->tweak_action = G_ACTION (g_simple_action_new_stateful ("tweak", NULL, g_variant_new_boolean (FALSE)));
|
|
|
|
g_signal_connect (self->tweak_action, "change-state", G_CALLBACK (change_tweak), self);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
update_fontlist (self);
|
2018-01-03 03:52:05 +00:00
|
|
|
|
2014-10-02 04:30:52 +00:00
|
|
|
/* Load data and set initial style-dependent parameters */
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_font_chooser_widget_populate_features (self);
|
2018-03-28 04:57:28 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_font_chooser_widget_take_font_desc (self, NULL);
|
2020-09-08 23:51:12 +00:00
|
|
|
|
|
|
|
gtk_custom_filter_set_filter_func (self->user_filter, user_filter_cb, self, NULL);
|
2020-09-24 09:37:32 +00:00
|
|
|
|
2020-09-08 23:51:12 +00:00
|
|
|
setup_language_list (self);
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_font_chooser_widget_new:
|
|
|
|
*
|
2021-02-26 21:11:29 +00:00
|
|
|
* Creates a new `GtkFontChooserWidget`.
|
2011-09-11 23:49:26 +00:00
|
|
|
*
|
2021-02-26 21:11:29 +00:00
|
|
|
* Returns: a new `GtkFontChooserWidget`
|
2011-09-11 23:49:26 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_font_chooser_widget_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_FONT_CHOOSER_WIDGET, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (object);
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
if (fontchooser->font_desc)
|
|
|
|
pango_font_description_free (fontchooser->font_desc);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
if (fontchooser->filter_data_destroy)
|
|
|
|
fontchooser->filter_data_destroy (fontchooser->filter_data);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
g_free (fontchooser->preview_text);
|
2014-10-15 03:59:25 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
g_clear_object (&fontchooser->font_map);
|
2015-05-05 03:21:17 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
g_object_unref (fontchooser->tweak_action);
|
2018-01-03 03:52:05 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
g_list_free_full (fontchooser->feature_items, g_free);
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
g_hash_table_unref (fontchooser->axes);
|
2018-01-03 18:28:33 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
g_free (fontchooser->font_features);
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
G_OBJECT_CLASS (gtk_font_chooser_widget_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2011-09-21 03:44:22 +00:00
|
|
|
static gboolean
|
|
|
|
my_pango_font_family_equal (const char *familya,
|
|
|
|
const char *familyb)
|
|
|
|
{
|
|
|
|
return g_ascii_strcasecmp (familya, familyb) == 0;
|
|
|
|
}
|
|
|
|
|
2021-03-02 22:55:30 +00:00
|
|
|
static gboolean
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_font_chooser_widget_ensure_matching_selection (GtkFontChooserWidget *self)
|
2011-09-20 00:54:42 +00:00
|
|
|
{
|
2019-11-28 03:00:39 +00:00
|
|
|
const char *desc_family;
|
|
|
|
guint i, n;
|
2011-09-20 00:54:42 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
desc_family = pango_font_description_get_family (self->font_desc);
|
|
|
|
if (desc_family == NULL)
|
|
|
|
{
|
|
|
|
gtk_single_selection_set_selected (self->selection, GTK_INVALID_LIST_POSITION);
|
2021-03-02 22:55:30 +00:00
|
|
|
return TRUE;
|
2019-11-28 03:00:39 +00:00
|
|
|
}
|
2011-09-21 03:44:22 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
n = g_list_model_get_n_items (G_LIST_MODEL (self->selection));
|
|
|
|
for (i = 0; i < n; i++)
|
2011-09-20 00:54:42 +00:00
|
|
|
{
|
2020-11-10 14:07:40 +00:00
|
|
|
gpointer item;
|
2019-11-28 03:00:39 +00:00
|
|
|
PangoFontFace *face;
|
2014-10-23 19:13:29 +00:00
|
|
|
PangoFontFamily *family;
|
2019-11-28 03:00:39 +00:00
|
|
|
PangoFontDescription *merged;
|
2014-10-23 19:13:29 +00:00
|
|
|
|
2020-11-10 14:07:40 +00:00
|
|
|
item = g_list_model_get_item (G_LIST_MODEL (self->selection), i);
|
|
|
|
g_object_unref (item);
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
if (PANGO_IS_FONT_FAMILY (item))
|
|
|
|
{
|
|
|
|
family = item;
|
|
|
|
face = pango_font_family_get_face (family, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
face = item;
|
|
|
|
family = pango_font_face_get_family (face);
|
|
|
|
}
|
|
|
|
if (!my_pango_font_family_equal (desc_family, pango_font_family_get_name (family)))
|
2020-11-10 14:07:40 +00:00
|
|
|
continue;
|
2011-09-21 03:44:22 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
merged = pango_font_face_describe (face);
|
|
|
|
pango_font_description_merge_static (merged, self->font_desc, FALSE);
|
2011-09-20 00:54:42 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
if (pango_font_description_equal (merged, self->font_desc))
|
2015-07-22 13:04:34 +00:00
|
|
|
{
|
|
|
|
pango_font_description_free (merged);
|
|
|
|
break;
|
|
|
|
}
|
2011-09-20 00:54:42 +00:00
|
|
|
|
2015-07-22 13:04:34 +00:00
|
|
|
pango_font_description_free (merged);
|
2011-09-20 00:54:42 +00:00
|
|
|
}
|
2018-01-03 03:52:05 +00:00
|
|
|
|
2021-03-02 22:55:30 +00:00
|
|
|
if (i < n)
|
|
|
|
{
|
|
|
|
gtk_single_selection_set_selected (self->selection, i);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2011-09-20 00:54:42 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
static PangoFontFace *
|
|
|
|
gtk_font_chooser_widget_get_face (GtkFontChooser *chooser)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2019-11-28 03:00:39 +00:00
|
|
|
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (chooser);
|
|
|
|
gpointer item;
|
2011-09-20 22:31:26 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
item = gtk_single_selection_get_selected_item (self->selection);
|
|
|
|
if (PANGO_IS_FONT_FAMILY (item))
|
|
|
|
return pango_font_family_get_face (item, NULL);
|
|
|
|
else
|
|
|
|
return item;
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
static PangoFontFamily *
|
|
|
|
gtk_font_chooser_widget_get_family (GtkFontChooser *chooser)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2019-11-28 03:00:39 +00:00
|
|
|
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (chooser);
|
|
|
|
gpointer item;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
item = gtk_single_selection_get_selected_item (self->selection);
|
|
|
|
if (item == NULL)
|
2011-09-20 22:31:26 +00:00
|
|
|
return NULL;
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
if (PANGO_IS_FONT_FAMILY (item))
|
|
|
|
return item;
|
|
|
|
else
|
|
|
|
return pango_font_face_get_family (item);
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
static int
|
2011-09-11 23:49:26 +00:00
|
|
|
gtk_font_chooser_widget_get_size (GtkFontChooser *chooser)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
|
2018-01-03 03:52:05 +00:00
|
|
|
PangoFontDescription *desc = gtk_font_chooser_widget_get_font_desc (fontchooser);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2018-01-03 03:52:05 +00:00
|
|
|
if (desc)
|
|
|
|
return pango_font_description_get_size (desc);
|
|
|
|
|
|
|
|
return -1;
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
static char *
|
2011-09-12 11:57:10 +00:00
|
|
|
gtk_font_chooser_widget_get_font (GtkFontChooserWidget *fontchooser)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2018-01-03 03:52:05 +00:00
|
|
|
PangoFontDescription *desc = gtk_font_chooser_widget_get_font_desc (fontchooser);
|
|
|
|
|
|
|
|
if (desc)
|
|
|
|
return pango_font_description_to_string (desc);
|
|
|
|
|
|
|
|
return NULL;
|
2011-09-11 22:13:26 +00:00
|
|
|
}
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-11 22:13:26 +00:00
|
|
|
static PangoFontDescription *
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_font_chooser_widget_get_font_desc (GtkFontChooserWidget *self)
|
2011-09-11 22:13:26 +00:00
|
|
|
{
|
2019-11-28 03:00:39 +00:00
|
|
|
if (gtk_single_selection_get_selected_item (self->selection))
|
|
|
|
return self->font_desc;
|
2018-01-03 03:52:05 +00:00
|
|
|
|
|
|
|
return NULL;
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 20:45:44 +00:00
|
|
|
static void
|
2011-09-12 11:57:10 +00:00
|
|
|
gtk_font_chooser_widget_set_font (GtkFontChooserWidget *fontchooser,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *fontname)
|
2011-09-11 22:13:26 +00:00
|
|
|
{
|
|
|
|
PangoFontDescription *font_desc;
|
|
|
|
|
|
|
|
font_desc = pango_font_description_from_string (fontname);
|
2011-09-12 11:57:10 +00:00
|
|
|
gtk_font_chooser_widget_take_font_desc (fontchooser, font_desc);
|
2011-09-11 22:13:26 +00:00
|
|
|
}
|
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
/* OpenType variations */
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_font_variations (GtkFontChooserWidget *fontchooser,
|
|
|
|
GString *s)
|
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
Axis *axis;
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
g_hash_table_iter_init (&iter, fontchooser->axes);
|
2018-01-03 18:28:33 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *)NULL, (gpointer *)&axis))
|
|
|
|
{
|
|
|
|
double value;
|
2022-01-03 02:34:05 +00:00
|
|
|
char buf[128];
|
2018-01-03 18:28:33 +00:00
|
|
|
|
2021-11-27 15:10:53 +00:00
|
|
|
value = gtk_adjustment_get_value (axis->adjustment);
|
2022-01-03 02:34:05 +00:00
|
|
|
|
2021-11-27 15:10:53 +00:00
|
|
|
if (value == axis->default_value)
|
|
|
|
continue;
|
|
|
|
|
2022-01-03 02:34:05 +00:00
|
|
|
hb_variation_to_string (&(hb_variation_t) { axis->tag, value }, buf, sizeof (buf));
|
|
|
|
|
|
|
|
if (s->len > 0)
|
|
|
|
g_string_append_c (s, ',');
|
|
|
|
g_string_append (s, buf);
|
2018-01-03 18:28:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
adjustment_changed (GtkAdjustment *adjustment,
|
|
|
|
Axis *axis)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (axis->fontchooser);
|
|
|
|
PangoFontDescription *font_desc;
|
|
|
|
GString *s;
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
fontchooser->updating_variations = TRUE;
|
2018-01-03 18:28:33 +00:00
|
|
|
|
|
|
|
s = g_string_new ("");
|
|
|
|
add_font_variations (fontchooser, s);
|
|
|
|
|
2021-11-27 15:10:53 +00:00
|
|
|
font_desc = pango_font_description_new ();
|
|
|
|
pango_font_description_set_variations (font_desc, s->str);
|
|
|
|
gtk_font_chooser_widget_take_font_desc (fontchooser, font_desc);
|
2018-01-03 18:28:33 +00:00
|
|
|
|
|
|
|
g_string_free (s, TRUE);
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
fontchooser->updating_variations = FALSE;
|
2018-01-03 18:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-07-24 12:02:07 +00:00
|
|
|
should_show_axis (hb_ot_var_axis_info_t *ax)
|
2018-01-03 18:28:33 +00:00
|
|
|
{
|
2022-01-03 02:34:05 +00:00
|
|
|
return (ax->flags & HB_OT_VAR_AXIS_FLAG_HIDDEN) == 0;
|
2018-01-03 18:28:33 +00:00
|
|
|
}
|
|
|
|
|
2022-01-01 20:35:31 +00:00
|
|
|
static gboolean
|
|
|
|
is_named_instance (hb_font_t *font)
|
|
|
|
{
|
|
|
|
/* FIXME */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
static struct {
|
|
|
|
guint32 tag;
|
|
|
|
const char *name;
|
|
|
|
} axis_names[] = {
|
2022-01-03 02:34:05 +00:00
|
|
|
{ HB_OT_TAG_VAR_AXIS_WIDTH, NC_("Font variation axis", "Width") },
|
|
|
|
{ HB_OT_TAG_VAR_AXIS_WEIGHT, NC_("Font variation axis", "Weight") },
|
|
|
|
{ HB_OT_TAG_VAR_AXIS_ITALIC, NC_("Font variation axis", "Italic") },
|
|
|
|
{ HB_OT_TAG_VAR_AXIS_SLANT, NC_("Font variation axis", "Slant") },
|
|
|
|
{ HB_OT_TAG_VAR_AXIS_OPTICAL_SIZE, NC_("Font variation axis", "Optical Size") },
|
2018-01-03 18:28:33 +00:00
|
|
|
};
|
|
|
|
|
2018-01-03 19:06:00 +00:00
|
|
|
static gboolean
|
2019-07-24 12:02:07 +00:00
|
|
|
add_axis (GtkFontChooserWidget *fontchooser,
|
|
|
|
hb_font_t *hb_font,
|
|
|
|
hb_ot_var_axis_info_t *ax,
|
|
|
|
int value,
|
|
|
|
int row)
|
2018-01-03 18:28:33 +00:00
|
|
|
{
|
2019-07-24 12:02:07 +00:00
|
|
|
hb_face_t *hb_face;
|
2018-01-03 18:28:33 +00:00
|
|
|
Axis *axis;
|
|
|
|
const char *name;
|
2019-07-24 12:02:07 +00:00
|
|
|
char buffer[20];
|
|
|
|
unsigned int buffer_len = 20;
|
2018-01-03 18:28:33 +00:00
|
|
|
int i;
|
|
|
|
|
2019-07-24 12:02:07 +00:00
|
|
|
hb_face = hb_font_get_face (hb_font);
|
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
axis = g_new (Axis, 1);
|
|
|
|
axis->tag = ax->tag;
|
2021-11-27 15:10:53 +00:00
|
|
|
axis->default_value = ax->default_value;
|
2018-01-03 18:28:33 +00:00
|
|
|
axis->fontchooser = GTK_WIDGET (fontchooser);
|
|
|
|
|
2019-07-24 12:02:07 +00:00
|
|
|
hb_ot_name_get_utf8 (hb_face, ax->name_id, HB_LANGUAGE_INVALID, &buffer_len, buffer);
|
|
|
|
name = buffer;
|
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (axis_names); i++)
|
|
|
|
{
|
|
|
|
if (axis_names[i].tag == ax->tag)
|
|
|
|
{
|
2022-01-03 02:34:05 +00:00
|
|
|
name = g_dpgettext2 (NULL, "Font variation axis", axis_names[i].name);
|
2018-01-03 18:28:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-07-24 12:02:07 +00:00
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
axis->label = gtk_label_new (name);
|
2019-07-24 12:02:07 +00:00
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
gtk_widget_set_halign (axis->label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (axis->label, GTK_ALIGN_BASELINE);
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (fontchooser->axis_grid), axis->label, 0, row, 1, 1);
|
2019-07-24 12:02:07 +00:00
|
|
|
axis->adjustment = gtk_adjustment_new ((double)value,
|
|
|
|
(double)ax->min_value,
|
|
|
|
(double)ax->max_value,
|
2018-01-03 18:28:33 +00:00
|
|
|
1.0, 10.0, 0.0);
|
|
|
|
axis->scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, axis->adjustment);
|
2019-07-24 12:02:07 +00:00
|
|
|
gtk_scale_add_mark (GTK_SCALE (axis->scale), (double)ax->default_value, GTK_POS_TOP, NULL);
|
2018-01-03 18:28:33 +00:00
|
|
|
gtk_widget_set_valign (axis->scale, GTK_ALIGN_BASELINE);
|
|
|
|
gtk_widget_set_hexpand (axis->scale, TRUE);
|
|
|
|
gtk_widget_set_size_request (axis->scale, 100, -1);
|
|
|
|
gtk_scale_set_draw_value (GTK_SCALE (axis->scale), FALSE);
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (fontchooser->axis_grid), axis->scale, 1, row, 1, 1);
|
2018-01-03 18:28:33 +00:00
|
|
|
axis->spin = gtk_spin_button_new (axis->adjustment, 0, 0);
|
|
|
|
g_signal_connect (axis->spin, "output", G_CALLBACK (output_cb), fontchooser);
|
|
|
|
gtk_widget_set_valign (axis->spin, GTK_ALIGN_BASELINE);
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (fontchooser->axis_grid), axis->spin, 2, row, 1, 1);
|
2018-01-03 18:28:33 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
g_hash_table_add (fontchooser->axes, axis);
|
2018-01-03 18:28:33 +00:00
|
|
|
|
|
|
|
adjustment_changed (axis->adjustment, axis);
|
|
|
|
g_signal_connect (axis->adjustment, "value-changed", G_CALLBACK (adjustment_changed), axis);
|
2022-01-01 20:35:31 +00:00
|
|
|
if (is_named_instance (hb_font) || !should_show_axis (ax))
|
2018-01-03 18:28:33 +00:00
|
|
|
{
|
|
|
|
gtk_widget_hide (axis->label);
|
|
|
|
gtk_widget_hide (axis->scale);
|
|
|
|
gtk_widget_hide (axis->spin);
|
2018-01-03 19:06:00 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2018-01-03 18:28:33 +00:00
|
|
|
}
|
2018-01-03 19:06:00 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2018-01-03 18:28:33 +00:00
|
|
|
}
|
|
|
|
|
2022-01-02 17:03:52 +00:00
|
|
|
#if HB_VERSION_ATLEAST (3, 3, 0)
|
|
|
|
static void
|
|
|
|
get_axes_and_values (hb_font_t *font,
|
|
|
|
unsigned int n_axes,
|
|
|
|
hb_ot_var_axis_info_t *axes,
|
|
|
|
float *coords)
|
|
|
|
{
|
|
|
|
const float *dcoords;
|
|
|
|
unsigned int length = n_axes;
|
|
|
|
|
|
|
|
hb_ot_var_get_axis_infos (hb_font_get_face (font), 0, &length, axes);
|
|
|
|
|
|
|
|
dcoords = hb_font_get_var_coords_design (font, &length);
|
|
|
|
if (dcoords)
|
|
|
|
memcpy (coords, dcoords, sizeof (float) * length);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < n_axes; i++)
|
|
|
|
{
|
|
|
|
hb_ot_var_axis_info_t *axis = &axes[i];
|
|
|
|
coords[axis->axis_index] = axis->default_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2019-07-24 12:02:07 +00:00
|
|
|
/* FIXME: This doesn't work if the font has an avar table */
|
|
|
|
static float
|
|
|
|
denorm_coord (hb_ot_var_axis_info_t *axis, int coord)
|
|
|
|
{
|
|
|
|
float r = coord / 16384.0;
|
|
|
|
|
|
|
|
if (coord < 0)
|
|
|
|
return axis->default_value + r * (axis->default_value - axis->min_value);
|
|
|
|
else
|
|
|
|
return axis->default_value + r * (axis->max_value - axis->default_value);
|
|
|
|
}
|
|
|
|
|
2022-01-02 17:03:52 +00:00
|
|
|
static void
|
|
|
|
get_axes_and_values (hb_font_t *font,
|
|
|
|
unsigned int n_axes,
|
|
|
|
hb_ot_var_axis_info_t *axes,
|
|
|
|
float *coords)
|
|
|
|
{
|
|
|
|
const int *ncoords;
|
|
|
|
unsigned int length = n_axes;
|
|
|
|
|
|
|
|
hb_ot_var_get_axis_infos (hb_font_get_face (font), 0, &length, axes);
|
|
|
|
|
|
|
|
ncoords = hb_font_get_var_coords_normalized (font, &length);
|
|
|
|
|
|
|
|
for (int i = 0; i < n_axes; i++)
|
|
|
|
{
|
|
|
|
hb_ot_var_axis_info_t *axis = &axes[i];
|
|
|
|
int idx = axis->axis_index;
|
|
|
|
if (ncoords)
|
|
|
|
coords[idx] = denorm_coord (axis, ncoords[idx]);
|
|
|
|
else
|
|
|
|
coords[idx] = axis->default_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-01-03 19:06:00 +00:00
|
|
|
static gboolean
|
2018-01-03 18:28:33 +00:00
|
|
|
gtk_font_chooser_widget_update_font_variations (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
PangoFont *pango_font;
|
2019-07-24 12:02:07 +00:00
|
|
|
hb_font_t *hb_font;
|
|
|
|
hb_face_t *hb_face;
|
|
|
|
unsigned int n_axes;
|
|
|
|
hb_ot_var_axis_info_t *axes;
|
2022-01-02 17:03:52 +00:00
|
|
|
float *coords;
|
2018-01-03 19:06:00 +00:00
|
|
|
gboolean has_axis = FALSE;
|
2019-07-24 12:02:07 +00:00
|
|
|
int i;
|
2018-01-03 18:28:33 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
if (fontchooser->updating_variations)
|
2018-01-03 19:06:00 +00:00
|
|
|
return FALSE;
|
2018-01-03 18:28:33 +00:00
|
|
|
|
2020-05-09 14:33:02 +00:00
|
|
|
g_hash_table_foreach (fontchooser->axes, axis_remove, fontchooser);
|
2020-04-26 19:23:21 +00:00
|
|
|
g_hash_table_remove_all (fontchooser->axes);
|
2018-01-03 18:28:33 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
if ((fontchooser->level & GTK_FONT_CHOOSER_LEVEL_VARIATIONS) == 0)
|
2018-03-27 20:10:19 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
pango_font = pango_context_load_font (gtk_widget_get_pango_context (GTK_WIDGET (fontchooser)),
|
2020-04-26 19:23:21 +00:00
|
|
|
fontchooser->font_desc);
|
2019-07-24 12:02:07 +00:00
|
|
|
hb_font = pango_font_get_hb_font (pango_font);
|
|
|
|
hb_face = hb_font_get_face (hb_font);
|
2018-01-03 18:28:33 +00:00
|
|
|
|
2019-07-24 12:02:07 +00:00
|
|
|
if (!hb_ot_var_has_data (hb_face))
|
|
|
|
return FALSE;
|
2018-01-03 18:28:33 +00:00
|
|
|
|
2019-07-24 12:02:07 +00:00
|
|
|
n_axes = hb_ot_var_get_axis_count (hb_face);
|
2022-01-02 17:03:52 +00:00
|
|
|
axes = g_alloca (sizeof (hb_ot_var_axis_info_t) * n_axes);
|
|
|
|
coords = g_alloca (sizeof (float) * n_axes);
|
|
|
|
get_axes_and_values (hb_font, n_axes, axes, coords);
|
2018-01-03 18:28:33 +00:00
|
|
|
|
2019-07-24 12:02:07 +00:00
|
|
|
for (i = 0; i < n_axes; i++)
|
|
|
|
{
|
2022-01-02 17:03:52 +00:00
|
|
|
if (add_axis (fontchooser, hb_font, &axes[i], coords[axes[i].axis_index], i + 4))
|
2019-07-24 12:02:07 +00:00
|
|
|
has_axis = TRUE;
|
2018-01-03 18:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (pango_font);
|
2018-01-03 19:06:00 +00:00
|
|
|
|
|
|
|
return has_axis;
|
2018-01-03 18:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* OpenType features */
|
|
|
|
|
2018-04-02 17:34:22 +00:00
|
|
|
/* look for a lang / script combination that matches the
|
|
|
|
* language property and is supported by the hb_face. If
|
|
|
|
* none is found, return the default lang / script tags.
|
|
|
|
*/
|
2018-01-03 04:46:37 +00:00
|
|
|
static void
|
2018-04-02 17:34:22 +00:00
|
|
|
find_language_and_script (GtkFontChooserWidget *fontchooser,
|
|
|
|
hb_face_t *hb_face,
|
|
|
|
hb_tag_t *lang_tag,
|
|
|
|
hb_tag_t *script_tag)
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int i, j, k;
|
2018-01-03 04:46:37 +00:00
|
|
|
hb_tag_t scripts[80];
|
|
|
|
unsigned int n_scripts;
|
|
|
|
unsigned int count;
|
|
|
|
hb_tag_t table[2] = { HB_OT_TAG_GSUB, HB_OT_TAG_GPOS };
|
2018-04-02 17:34:22 +00:00
|
|
|
hb_language_t lang;
|
|
|
|
const char *langname, *p;
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
langname = pango_language_to_string (fontchooser->language);
|
2018-04-02 17:34:22 +00:00
|
|
|
p = strchr (langname, '-');
|
|
|
|
lang = hb_language_from_string (langname, p ? p - langname : -1);
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
n_scripts = 0;
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
count = G_N_ELEMENTS (scripts);
|
|
|
|
hb_ot_layout_table_get_script_tags (hb_face, table[i], n_scripts, &count, scripts);
|
|
|
|
n_scripts += count;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < n_scripts; j++)
|
|
|
|
{
|
|
|
|
hb_tag_t languages[80];
|
|
|
|
unsigned int n_languages;
|
|
|
|
|
|
|
|
n_languages = 0;
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
count = G_N_ELEMENTS (languages);
|
|
|
|
hb_ot_layout_script_get_language_tags (hb_face, table[i], j, n_languages, &count, languages);
|
|
|
|
n_languages += count;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (k = 0; k < n_languages; k++)
|
|
|
|
{
|
2018-04-02 21:46:41 +00:00
|
|
|
if (lang == hb_ot_tag_to_language (languages[k]))
|
2018-04-02 17:34:22 +00:00
|
|
|
{
|
|
|
|
*script_tag = scripts[j];
|
|
|
|
*lang_tag = languages[k];
|
|
|
|
return;
|
|
|
|
}
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 17:34:22 +00:00
|
|
|
*lang_tag = HB_OT_TAG_DEFAULT_LANGUAGE;
|
|
|
|
*script_tag = HB_OT_TAG_DEFAULT_SCRIPT;
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
hb_tag_t tag;
|
|
|
|
const char *name;
|
2018-04-01 23:35:55 +00:00
|
|
|
GtkWidget *top;
|
2018-01-03 04:46:37 +00:00
|
|
|
GtkWidget *feat;
|
2018-04-01 23:35:55 +00:00
|
|
|
GtkWidget *example;
|
2018-01-03 04:46:37 +00:00
|
|
|
} FeatureItem;
|
|
|
|
|
2022-07-03 11:38:24 +00:00
|
|
|
static char *
|
2018-01-03 04:46:37 +00:00
|
|
|
get_feature_display_name (hb_tag_t tag)
|
|
|
|
{
|
|
|
|
int i;
|
2022-07-03 11:38:24 +00:00
|
|
|
char buf[5] = { 0, };
|
|
|
|
|
|
|
|
hb_tag_to_string (tag, buf);
|
|
|
|
|
|
|
|
if (buf[0] == 's' && buf[1] == 's' && g_ascii_isdigit (buf[2]) && g_ascii_isdigit (buf[3]))
|
|
|
|
{
|
|
|
|
int num = (buf[2] - '0') * 10 + (buf[3] - '0');
|
|
|
|
return g_strdup_printf (g_dpgettext2 (NULL, "OpenType layout", "Stylistic Set %d"), num);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf[0] == 'c' && buf[1] == 'v' && g_ascii_isdigit (buf[2]) && g_ascii_isdigit (buf[3]))
|
|
|
|
{
|
|
|
|
int num = (buf[2] - '0') * 10 + (buf[3] - '0');
|
|
|
|
return g_strdup_printf (g_dpgettext2 (NULL, "OpenType layout", "Character Variant %d"), num);
|
|
|
|
}
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (open_type_layout_features); i++)
|
|
|
|
{
|
|
|
|
if (tag == open_type_layout_features[i].tag)
|
2022-07-03 11:38:24 +00:00
|
|
|
return g_strdup (g_dpgettext2 (NULL, "OpenType layout", open_type_layout_features[i].name));
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_inconsistent (GtkCheckButton *button,
|
|
|
|
gboolean inconsistent)
|
|
|
|
{
|
|
|
|
gtk_check_button_set_inconsistent (GTK_CHECK_BUTTON (button), inconsistent);
|
|
|
|
gtk_widget_set_opacity (gtk_widget_get_first_child (GTK_WIDGET (button)), inconsistent ? 0.0 : 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-08-07 03:45:30 +00:00
|
|
|
feat_pressed (GtkGestureClick *gesture,
|
|
|
|
int n_press,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
GtkWidget *feat)
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
const guint button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
if (button == GDK_BUTTON_PRIMARY)
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
g_signal_handlers_block_by_func (feat, feat_pressed, NULL);
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
if (gtk_check_button_get_inconsistent (GTK_CHECK_BUTTON (feat)))
|
|
|
|
{
|
|
|
|
set_inconsistent (GTK_CHECK_BUTTON (feat), FALSE);
|
2020-08-30 20:41:02 +00:00
|
|
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (feat), TRUE);
|
2020-08-07 03:45:30 +00:00
|
|
|
}
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
g_signal_handlers_unblock_by_func (feat, feat_pressed, NULL);
|
|
|
|
}
|
|
|
|
else if (button == GDK_BUTTON_SECONDARY)
|
|
|
|
{
|
|
|
|
gboolean inconsistent = gtk_check_button_get_inconsistent (GTK_CHECK_BUTTON (feat));
|
|
|
|
set_inconsistent (GTK_CHECK_BUTTON (feat), !inconsistent);
|
|
|
|
}
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
|
2018-04-01 23:35:55 +00:00
|
|
|
static char *
|
2021-12-31 14:17:42 +00:00
|
|
|
find_affected_text (GtkFontChooserWidget *fontchooser,
|
|
|
|
hb_tag_t feature_tag,
|
|
|
|
hb_font_t *hb_font,
|
|
|
|
hb_tag_t script_tag,
|
|
|
|
hb_tag_t lang_tag,
|
|
|
|
int max_chars)
|
2018-04-01 23:35:55 +00:00
|
|
|
{
|
2019-07-24 12:02:07 +00:00
|
|
|
hb_face_t *hb_face;
|
2018-04-01 23:35:55 +00:00
|
|
|
unsigned int script_index = 0;
|
|
|
|
unsigned int lang_index = 0;
|
|
|
|
unsigned int feature_index = 0;
|
|
|
|
GString *chars;
|
|
|
|
|
2019-07-24 12:02:07 +00:00
|
|
|
hb_face = hb_font_get_face (hb_font);
|
|
|
|
|
2018-04-01 23:35:55 +00:00
|
|
|
chars = g_string_new ("");
|
|
|
|
|
|
|
|
hb_ot_layout_table_find_script (hb_face, HB_OT_TAG_GSUB, script_tag, &script_index);
|
2019-04-12 17:40:08 +00:00
|
|
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
2018-04-01 23:35:55 +00:00
|
|
|
hb_ot_layout_script_find_language (hb_face, HB_OT_TAG_GSUB, script_index, lang_tag, &lang_index);
|
2019-04-12 17:40:08 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
|
|
|
2022-07-03 11:38:24 +00:00
|
|
|
if (hb_ot_layout_language_find_feature (hb_face,
|
|
|
|
HB_OT_TAG_GSUB,
|
|
|
|
script_index,
|
|
|
|
lang_index,
|
|
|
|
feature_tag,
|
|
|
|
&feature_index))
|
2018-04-01 23:35:55 +00:00
|
|
|
{
|
|
|
|
unsigned int lookup_indexes[32];
|
|
|
|
unsigned int lookup_count = 32;
|
2022-08-26 02:26:07 +00:00
|
|
|
unsigned int count;
|
2018-04-01 23:35:55 +00:00
|
|
|
int n_chars = 0;
|
|
|
|
|
2022-08-26 02:26:07 +00:00
|
|
|
count = hb_ot_layout_feature_get_characters (hb_face,
|
|
|
|
HB_OT_TAG_GSUB,
|
|
|
|
feature_index,
|
|
|
|
0,
|
|
|
|
NULL, NULL);
|
2018-04-01 23:35:55 +00:00
|
|
|
if (count > 0)
|
|
|
|
{
|
2022-08-26 02:26:07 +00:00
|
|
|
hb_codepoint_t *ch;
|
|
|
|
|
|
|
|
ch = g_alloca (sizeof (hb_codepoint_t) * count);
|
|
|
|
hb_ot_layout_feature_get_characters (hb_face,
|
|
|
|
HB_OT_TAG_GSUB,
|
|
|
|
feature_index,
|
|
|
|
0,
|
|
|
|
&count,
|
|
|
|
ch);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < MIN (count, max_chars); i++)
|
|
|
|
g_string_append_unichar (chars, ch[i]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
count = hb_ot_layout_feature_get_lookups (hb_face,
|
|
|
|
HB_OT_TAG_GSUB,
|
|
|
|
feature_index,
|
|
|
|
0,
|
|
|
|
&lookup_count,
|
|
|
|
lookup_indexes);
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
hb_set_t *glyphs_before = NULL;
|
|
|
|
hb_set_t *glyphs_after = NULL;
|
|
|
|
hb_set_t *glyphs_output = NULL;
|
|
|
|
hb_set_t *glyphs_input;
|
|
|
|
hb_codepoint_t gid;
|
|
|
|
char buf[5] = { 0, };
|
2018-04-01 23:35:55 +00:00
|
|
|
|
2022-08-26 02:26:07 +00:00
|
|
|
hb_tag_to_string (feature_tag, buf);
|
2018-04-01 23:35:55 +00:00
|
|
|
|
2022-08-26 02:26:07 +00:00
|
|
|
glyphs_input = hb_set_create ();
|
2018-04-01 23:35:55 +00:00
|
|
|
|
2022-08-26 02:26:07 +00:00
|
|
|
for (int i = 0; i < count; i++)
|
2021-12-31 14:17:42 +00:00
|
|
|
{
|
2022-08-26 02:26:07 +00:00
|
|
|
hb_ot_layout_lookup_collect_glyphs (hb_face,
|
|
|
|
HB_OT_TAG_GSUB,
|
|
|
|
lookup_indexes[i],
|
|
|
|
glyphs_before,
|
|
|
|
glyphs_input,
|
|
|
|
glyphs_after,
|
|
|
|
glyphs_output);
|
2021-12-31 14:17:42 +00:00
|
|
|
}
|
|
|
|
|
2022-08-26 02:26:07 +00:00
|
|
|
if (!fontchooser->glyphmap)
|
2021-12-31 14:17:42 +00:00
|
|
|
{
|
2022-08-26 02:26:07 +00:00
|
|
|
fontchooser->glyphmap = hb_map_create ();
|
|
|
|
for (hb_codepoint_t ch = 0; ch < 0xffff; ch++)
|
|
|
|
{
|
|
|
|
hb_codepoint_t glyph = 0;
|
|
|
|
if (hb_font_get_nominal_glyph (hb_font, ch, &glyph) &&
|
|
|
|
!hb_map_has (fontchooser->glyphmap, glyph))
|
|
|
|
hb_map_set (fontchooser->glyphmap, glyph, ch);
|
|
|
|
}
|
2021-12-31 14:17:42 +00:00
|
|
|
}
|
2022-08-26 02:26:07 +00:00
|
|
|
|
|
|
|
gid = HB_SET_VALUE_INVALID;
|
|
|
|
while (hb_set_next (glyphs_input, &gid))
|
2021-12-31 14:17:42 +00:00
|
|
|
{
|
2022-08-26 02:26:07 +00:00
|
|
|
hb_codepoint_t ch;
|
|
|
|
|
|
|
|
if (n_chars == max_chars)
|
|
|
|
{
|
|
|
|
g_string_append (chars, "…");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ch = hb_map_get (fontchooser->glyphmap, gid);
|
|
|
|
if (ch != HB_MAP_VALUE_INVALID)
|
|
|
|
{
|
|
|
|
g_string_append_unichar (chars, (gunichar)ch);
|
|
|
|
n_chars++;
|
|
|
|
}
|
2021-12-31 14:17:42 +00:00
|
|
|
}
|
|
|
|
|
2022-08-26 02:26:07 +00:00
|
|
|
hb_set_destroy (glyphs_input);
|
|
|
|
}
|
2018-04-01 23:35:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_string_free (chars, FALSE);
|
|
|
|
}
|
|
|
|
|
2022-08-26 02:26:07 +00:00
|
|
|
static char *
|
|
|
|
get_name (hb_face_t *hb_face,
|
|
|
|
hb_ot_name_id_t id)
|
|
|
|
{
|
|
|
|
unsigned int len;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
len = hb_ot_name_get_utf8 (hb_face, id, HB_LANGUAGE_INVALID, NULL, NULL);
|
|
|
|
len++;
|
|
|
|
name = g_new (char, len);
|
|
|
|
hb_ot_name_get_utf8 (hb_face, id, HB_LANGUAGE_INVALID, &len, name);
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2022-07-03 11:38:24 +00:00
|
|
|
static void
|
|
|
|
update_feature_label (GtkFontChooserWidget *fontchooser,
|
|
|
|
FeatureItem *item,
|
|
|
|
hb_font_t *hb_font,
|
|
|
|
hb_tag_t script_tag,
|
|
|
|
hb_tag_t lang_tag)
|
|
|
|
{
|
|
|
|
hb_face_t *hb_face;
|
|
|
|
unsigned int script_index, lang_index, feature_index;
|
2022-08-26 02:26:07 +00:00
|
|
|
hb_ot_name_id_t label_id, first_param_id;
|
|
|
|
unsigned int num_params;
|
2022-08-28 21:02:56 +00:00
|
|
|
const char *feat[] = { "salt", "swsh", "nalt", NULL };
|
2022-07-03 11:38:24 +00:00
|
|
|
|
|
|
|
hb_face = hb_font_get_face (hb_font);
|
|
|
|
|
2022-08-28 21:02:56 +00:00
|
|
|
if (!g_strv_contains (feat, item->name) &&
|
|
|
|
(!(g_str_has_prefix (item->name, "ss") || g_str_has_prefix (item->name, "cv")) ||
|
|
|
|
!g_ascii_isdigit (item->name[2]) || !g_ascii_isdigit (item->name[3])))
|
2022-07-03 11:38:24 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
hb_ot_layout_table_find_script (hb_face, HB_OT_TAG_GSUB, script_tag, &script_index);
|
|
|
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
hb_ot_layout_script_find_language (hb_face, HB_OT_TAG_GSUB, script_index, lang_tag, &lang_index);
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
|
|
|
2022-08-28 21:02:56 +00:00
|
|
|
if (hb_ot_layout_language_find_feature (hb_face, HB_OT_TAG_GSUB, script_index, lang_index, item->tag, &feature_index))
|
2022-07-03 11:38:24 +00:00
|
|
|
{
|
2022-08-28 21:02:56 +00:00
|
|
|
char *label;
|
|
|
|
|
|
|
|
if (!hb_ot_layout_feature_get_name_ids (hb_face, HB_OT_TAG_GSUB, feature_index, &label_id, NULL, NULL, &num_params, &first_param_id))
|
2022-08-26 02:26:07 +00:00
|
|
|
{
|
2022-08-28 21:02:56 +00:00
|
|
|
label_id = HB_OT_NAME_ID_INVALID;
|
|
|
|
num_params = 0;
|
2022-08-26 02:26:07 +00:00
|
|
|
}
|
2022-08-28 21:02:56 +00:00
|
|
|
|
|
|
|
if (label_id != HB_OT_NAME_ID_INVALID)
|
|
|
|
label = get_name (hb_face, label_id);
|
|
|
|
else
|
|
|
|
label = get_feature_display_name (item->tag);
|
|
|
|
|
|
|
|
if (GTK_IS_CHECK_BUTTON (item->feat))
|
|
|
|
gtk_check_button_set_label (GTK_CHECK_BUTTON (item->feat), label);
|
2022-08-26 02:26:07 +00:00
|
|
|
else
|
|
|
|
{
|
2022-08-28 21:02:56 +00:00
|
|
|
GtkWidget *l = gtk_widget_get_prev_sibling (item->feat);
|
|
|
|
gtk_label_set_label (GTK_LABEL (l), label);
|
2022-08-26 02:26:07 +00:00
|
|
|
}
|
2022-07-03 11:38:24 +00:00
|
|
|
|
2022-08-28 21:02:56 +00:00
|
|
|
g_free (label);
|
|
|
|
|
2022-08-26 02:26:07 +00:00
|
|
|
if (GTK_IS_DROP_DOWN (item->feat))
|
|
|
|
{
|
|
|
|
unsigned int n_lookups;
|
|
|
|
GtkStringList *strings;
|
|
|
|
unsigned int *lookups;
|
|
|
|
unsigned int n_alternates;
|
|
|
|
|
|
|
|
n_lookups = hb_ot_layout_feature_get_lookups (hb_face,
|
|
|
|
HB_OT_TAG_GSUB,
|
|
|
|
feature_index,
|
|
|
|
0,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
lookups = g_alloca (sizeof (unsigned int) * n_lookups);
|
|
|
|
hb_ot_layout_feature_get_lookups (hb_face,
|
|
|
|
HB_OT_TAG_GSUB,
|
|
|
|
feature_index,
|
|
|
|
0,
|
|
|
|
&n_lookups,
|
|
|
|
lookups);
|
|
|
|
|
|
|
|
n_alternates = 0;
|
|
|
|
for (unsigned int l = 0; l < n_lookups; l++)
|
|
|
|
{
|
|
|
|
hb_set_t *glyphs;
|
|
|
|
hb_codepoint_t glyph_index;
|
|
|
|
unsigned int lookup = lookups[l];
|
2022-07-03 11:38:24 +00:00
|
|
|
|
2022-08-26 02:26:07 +00:00
|
|
|
glyphs = hb_set_create ();
|
|
|
|
|
|
|
|
hb_ot_layout_lookup_collect_glyphs (hb_face,
|
|
|
|
HB_OT_TAG_GSUB,
|
|
|
|
lookup,
|
|
|
|
NULL,
|
|
|
|
glyphs,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
glyph_index = HB_SET_VALUE_INVALID;
|
|
|
|
while (hb_set_next (glyphs, &glyph_index))
|
|
|
|
n_alternates = MAX (n_alternates,
|
|
|
|
hb_ot_layout_lookup_get_glyph_alternates (hb_face,
|
|
|
|
lookup,
|
|
|
|
glyph_index,
|
|
|
|
0, NULL, NULL));
|
|
|
|
|
|
|
|
hb_set_destroy (glyphs);
|
|
|
|
}
|
|
|
|
|
|
|
|
strings = gtk_string_list_new (NULL);
|
2022-08-29 02:07:44 +00:00
|
|
|
gtk_string_list_append (strings, C_("Font feature value", "Default"));
|
2022-08-26 02:26:07 +00:00
|
|
|
for (unsigned int i = 0; i < num_params; i++)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
name = get_name (hb_face, first_param_id + i);
|
|
|
|
gtk_string_list_append (strings, name);
|
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = num_params; i < n_alternates; i++)
|
|
|
|
{
|
|
|
|
char buf[64];
|
|
|
|
g_snprintf (buf, sizeof (buf), "%d", i + 1);
|
|
|
|
gtk_string_list_append (strings, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_list_model_get_n_items (G_LIST_MODEL (strings)) == 1)
|
|
|
|
gtk_string_list_append (strings, C_("Font feature value", "Enable"));
|
|
|
|
|
|
|
|
gtk_drop_down_set_model (GTK_DROP_DOWN (item->feat), G_LIST_MODEL (strings));
|
|
|
|
g_object_unref (strings);
|
|
|
|
}
|
2022-07-03 11:38:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-26 02:26:07 +00:00
|
|
|
char *label = get_feature_display_name (item->tag);
|
2022-07-03 11:38:24 +00:00
|
|
|
gtk_check_button_set_label (GTK_CHECK_BUTTON (item->feat), label);
|
|
|
|
g_free (label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-01 23:35:55 +00:00
|
|
|
static void
|
2021-12-31 14:17:42 +00:00
|
|
|
update_feature_example (GtkFontChooserWidget *fontchooser,
|
|
|
|
FeatureItem *item,
|
2019-07-24 12:02:07 +00:00
|
|
|
hb_font_t *hb_font,
|
2018-04-01 23:35:55 +00:00
|
|
|
hb_tag_t script_tag,
|
|
|
|
hb_tag_t lang_tag,
|
|
|
|
PangoFontDescription *font_desc)
|
|
|
|
{
|
|
|
|
const char *letter_case[] = { "smcp", "c2sc", "pcap", "c2pc", "unic", "cpsp", "case", NULL };
|
2022-08-28 21:02:56 +00:00
|
|
|
const char *number_case[] = { "xxnc", "lnum", "onum", NULL };
|
|
|
|
const char *number_spacing[] = { "xxns", "pnum", "tnum", NULL };
|
|
|
|
const char *fraction[] = { "xxnf", "frac", "afrc", NULL };
|
2018-04-01 23:35:55 +00:00
|
|
|
const char *char_variants[] = {
|
2022-08-26 02:26:07 +00:00
|
|
|
"zero", "nalt",
|
2018-04-01 23:35:55 +00:00
|
|
|
"swsh", "cswh", "calt", "falt", "hist", "salt", "jalt", "titl", "rand",
|
|
|
|
"ss01", "ss02", "ss03", "ss04", "ss05", "ss06", "ss07", "ss08", "ss09", "ss10",
|
|
|
|
"ss11", "ss12", "ss13", "ss14", "ss15", "ss16", "ss17", "ss18", "ss19", "ss20",
|
2022-08-26 02:26:07 +00:00
|
|
|
"cv01", "cv02", "cv03", "cv04", "cv05", "cv06", "cv07", "cv08", "cv09", "cv10",
|
|
|
|
"cv11", "cv12", "cv13", "cv14", "cv15", "cv16", "cv17", "cv18", "cv19", "cv20",
|
|
|
|
"cv21", "cv22", "cv23", "cv24", "cv25", "cv26", "cv27", "cv28", "cv29", "cv30",
|
|
|
|
"cv31", "cv32", "cv33", "cv34", "cv35", "cv36", "cv37", "cv38", "cv39", "cv40",
|
|
|
|
"cv41", "cv42", "cv43", "cv44", "cv45", "cv46", "cv47", "cv48", "cv49", "cv50",
|
|
|
|
"cv51", "cv52", "cv53", "cv54", "cv55", "cv56", "cv57", "cv58", "cv59", "cv60",
|
|
|
|
"cv61", "cv62", "cv63", "cv64", "cv65", "cv66", "cv67", "cv68", "cv69", "cv70",
|
|
|
|
"cv71", "cv72", "cv73", "cv74", "cv75", "cv76", "cv77", "cv78", "cv79", "cv80",
|
|
|
|
"cv81", "cv82", "cv83", "cv84", "cv85", "cv86", "cv87", "cv88", "cv89", "cv90",
|
|
|
|
"cv91", "cv92", "cv93", "cv94", "cv95", "cv96", "cv97", "cv98", "cv99",
|
2018-04-01 23:35:55 +00:00
|
|
|
NULL };
|
|
|
|
|
|
|
|
if (g_strv_contains (number_case, item->name) ||
|
2022-08-26 02:26:07 +00:00
|
|
|
g_strv_contains (number_spacing, item->name) ||
|
|
|
|
g_strv_contains (fraction, item->name))
|
2018-04-01 23:35:55 +00:00
|
|
|
{
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
PangoAttribute *attr;
|
|
|
|
PangoFontDescription *desc;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
|
|
|
|
desc = pango_font_description_copy (font_desc);
|
|
|
|
pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE);
|
|
|
|
pango_attr_list_insert (attrs, pango_attr_font_desc_new (desc));
|
|
|
|
pango_font_description_free (desc);
|
|
|
|
str = g_strconcat (item->name, " 1", NULL);
|
|
|
|
attr = pango_attr_font_features_new (str);
|
|
|
|
pango_attr_list_insert (attrs, attr);
|
|
|
|
|
2022-08-26 02:26:07 +00:00
|
|
|
if (g_strv_contains (fraction, item->name))
|
|
|
|
gtk_label_set_text (GTK_LABEL (item->example), "1/2 2/3 7/8");
|
|
|
|
else
|
|
|
|
gtk_label_set_text (GTK_LABEL (item->example), "0123456789");
|
2018-04-01 23:35:55 +00:00
|
|
|
gtk_label_set_attributes (GTK_LABEL (item->example), attrs);
|
|
|
|
|
|
|
|
pango_attr_list_unref (attrs);
|
|
|
|
}
|
|
|
|
else if (g_strv_contains (letter_case, item->name) ||
|
|
|
|
g_strv_contains (char_variants, item->name))
|
|
|
|
{
|
|
|
|
char *input = NULL;
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
if (strcmp (item->name, "case") == 0)
|
|
|
|
input = g_strdup ("A-B[Cq]");
|
|
|
|
else if (g_strv_contains (letter_case, item->name))
|
|
|
|
input = g_strdup ("AaBbCc…");
|
|
|
|
else if (strcmp (item->name, "zero") == 0)
|
|
|
|
input = g_strdup ("0");
|
|
|
|
else
|
2021-12-31 14:17:42 +00:00
|
|
|
input = find_affected_text (fontchooser, item->tag, hb_font, script_tag, lang_tag, 10);
|
2018-04-01 23:35:55 +00:00
|
|
|
|
|
|
|
if (input[0] != '\0')
|
|
|
|
{
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
PangoAttribute *attr;
|
|
|
|
PangoFontDescription *desc;
|
|
|
|
char *str;
|
|
|
|
|
2022-08-26 02:26:07 +00:00
|
|
|
text = g_strconcat (input, " → ", input, NULL);
|
2018-04-01 23:35:55 +00:00
|
|
|
|
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
|
|
|
|
desc = pango_font_description_copy (font_desc);
|
|
|
|
pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE);
|
|
|
|
pango_attr_list_insert (attrs, pango_attr_font_desc_new (desc));
|
|
|
|
pango_font_description_free (desc);
|
|
|
|
str = g_strconcat (item->name, " 0", NULL);
|
|
|
|
attr = pango_attr_font_features_new (str);
|
|
|
|
attr->start_index = 0;
|
|
|
|
attr->end_index = strlen (input);
|
|
|
|
pango_attr_list_insert (attrs, attr);
|
2022-08-26 02:26:07 +00:00
|
|
|
attr = pango_attr_fallback_new (FALSE);
|
|
|
|
attr->start_index = 0;
|
|
|
|
attr->end_index = strlen (input);
|
|
|
|
pango_attr_list_insert (attrs, attr);
|
2018-04-01 23:35:55 +00:00
|
|
|
str = g_strconcat (item->name, " 1", NULL);
|
|
|
|
attr = pango_attr_font_features_new (str);
|
2022-08-26 02:26:07 +00:00
|
|
|
attr->start_index = strlen (input) + strlen (" → ");
|
|
|
|
attr->end_index = attr->start_index + strlen (input);
|
|
|
|
pango_attr_list_insert (attrs, attr);
|
|
|
|
attr = pango_attr_fallback_new (FALSE);
|
|
|
|
attr->start_index = strlen (input) + strlen (" → ");
|
2018-04-01 23:35:55 +00:00
|
|
|
attr->end_index = attr->start_index + strlen (input);
|
|
|
|
pango_attr_list_insert (attrs, attr);
|
|
|
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (item->example), text);
|
|
|
|
gtk_label_set_attributes (GTK_LABEL (item->example), attrs);
|
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
pango_attr_list_unref (attrs);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_label_set_markup (GTK_LABEL (item->example), "");
|
|
|
|
g_free (input);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
static void
|
|
|
|
font_feature_toggled_cb (GtkCheckButton *check_button,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = user_data;
|
|
|
|
|
|
|
|
set_inconsistent (check_button, FALSE);
|
|
|
|
update_font_features (fontchooser);
|
|
|
|
}
|
|
|
|
|
2018-01-03 04:46:37 +00:00
|
|
|
static void
|
2022-08-26 02:26:07 +00:00
|
|
|
add_check_group (GtkFontChooserWidget *fontchooser,
|
|
|
|
const char *title,
|
|
|
|
const char **tags,
|
|
|
|
unsigned int n_tags)
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *group;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
group = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2018-04-01 23:35:55 +00:00
|
|
|
gtk_widget_set_halign (group, GTK_ALIGN_FILL);
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
label = gtk_label_new (title);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
g_object_set (label, "margin-top", 10, "margin-bottom", 10, NULL);
|
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
|
|
|
|
gtk_label_set_attributes (GTK_LABEL (label), attrs);
|
|
|
|
pango_attr_list_unref (attrs);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (group), label);
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2022-08-26 02:26:07 +00:00
|
|
|
for (i = 0; i < n_tags; i++)
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
|
|
|
hb_tag_t tag;
|
|
|
|
GtkWidget *feat;
|
|
|
|
FeatureItem *item;
|
|
|
|
GtkGesture *gesture;
|
2018-04-01 23:35:55 +00:00
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *example;
|
2022-07-03 11:38:24 +00:00
|
|
|
char *name;
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
tag = hb_tag_from_string (tags[i], -1);
|
|
|
|
|
2022-07-03 11:38:24 +00:00
|
|
|
name = get_feature_display_name (tag);
|
|
|
|
feat = gtk_check_button_new_with_label (name);
|
|
|
|
g_free (name);
|
2018-01-03 04:46:37 +00:00
|
|
|
set_inconsistent (GTK_CHECK_BUTTON (feat), TRUE);
|
2020-08-07 03:45:30 +00:00
|
|
|
g_signal_connect (feat, "toggled", G_CALLBACK (font_feature_toggled_cb), fontchooser);
|
2018-01-03 04:46:37 +00:00
|
|
|
g_signal_connect_swapped (feat, "notify::inconsistent", G_CALLBACK (update_font_features), fontchooser);
|
|
|
|
|
2019-05-29 17:10:46 +00:00
|
|
|
gesture = gtk_gesture_click_new ();
|
2018-01-03 04:46:37 +00:00
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY);
|
|
|
|
g_signal_connect (gesture, "pressed", G_CALLBACK (feat_pressed), feat);
|
2018-03-09 05:14:59 +00:00
|
|
|
gtk_widget_add_controller (feat, GTK_EVENT_CONTROLLER (gesture));
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2018-04-01 23:35:55 +00:00
|
|
|
example = gtk_label_new ("");
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (example), TRUE);
|
|
|
|
gtk_widget_set_halign (example, GTK_ALIGN_START);
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
|
|
|
gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), feat);
|
|
|
|
gtk_box_append (GTK_BOX (box), example);
|
|
|
|
gtk_box_append (GTK_BOX (group), box);
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
item = g_new (FeatureItem, 1);
|
|
|
|
item->name = tags[i];
|
|
|
|
item->tag = tag;
|
2018-04-01 23:35:55 +00:00
|
|
|
item->top = box;
|
2018-01-03 04:46:37 +00:00
|
|
|
item->feat = feat;
|
2018-04-01 23:35:55 +00:00
|
|
|
item->example = example;
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
fontchooser->feature_items = g_list_prepend (fontchooser->feature_items, item);
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (fontchooser->feature_box), group);
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-08-26 02:26:07 +00:00
|
|
|
font_enum_feature_changed_cb (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = data;
|
|
|
|
|
|
|
|
update_font_features (fontchooser);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_enum_group (GtkFontChooserWidget *fontchooser,
|
|
|
|
const char *title,
|
|
|
|
const char **tags,
|
|
|
|
unsigned int n_tags)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *group;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
group = gtk_grid_new ();
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (group), 6);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (group), 12);
|
|
|
|
|
2022-08-28 21:02:56 +00:00
|
|
|
if (title)
|
|
|
|
{
|
|
|
|
label = gtk_label_new (title);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
g_object_set (label, "margin-top", 10, "margin-bottom", 10, NULL);
|
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
|
|
|
|
gtk_label_set_attributes (GTK_LABEL (label), attrs);
|
|
|
|
pango_attr_list_unref (attrs);
|
|
|
|
gtk_grid_attach (GTK_GRID (group), label, 0, -1, 3, 1);
|
|
|
|
}
|
2022-08-26 02:26:07 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n_tags; i++)
|
|
|
|
{
|
|
|
|
hb_tag_t tag;
|
|
|
|
GtkWidget *feat;
|
|
|
|
FeatureItem *item;
|
|
|
|
GtkWidget *example;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
tag = hb_tag_from_string (tags[i], -1);
|
|
|
|
|
|
|
|
name = get_feature_display_name (tag);
|
|
|
|
label = gtk_label_new (name);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0);
|
|
|
|
gtk_grid_attach (GTK_GRID (group), label, 0, i, 1, 1);
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
feat = gtk_drop_down_new (NULL, NULL);
|
|
|
|
gtk_grid_attach (GTK_GRID (group), feat, 1, i, 1, 1);
|
|
|
|
|
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), feat);
|
|
|
|
|
|
|
|
g_signal_connect (feat, "notify::selected", G_CALLBACK (font_enum_feature_changed_cb), fontchooser);
|
|
|
|
|
|
|
|
example = gtk_label_new ("");
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (example), TRUE);
|
|
|
|
gtk_widget_set_halign (example, GTK_ALIGN_START);
|
|
|
|
|
|
|
|
gtk_grid_attach (GTK_GRID (group), example, 2, i, 1, 1);
|
|
|
|
|
|
|
|
item = g_new (FeatureItem, 1);
|
|
|
|
item->name = tags[i];
|
|
|
|
item->tag = tag;
|
|
|
|
item->top = NULL;
|
|
|
|
item->feat = feat;
|
|
|
|
item->example = example;
|
|
|
|
|
|
|
|
fontchooser->feature_items = g_list_prepend (fontchooser->feature_items, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_box_append (GTK_BOX (fontchooser->feature_box), group);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_radio_group (GtkFontChooserWidget *fontchooser,
|
|
|
|
const char *title,
|
|
|
|
const char **tags,
|
|
|
|
unsigned int n_tags)
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *group;
|
|
|
|
int i;
|
|
|
|
GtkWidget *group_button = NULL;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
|
|
|
|
group = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2018-04-01 23:35:55 +00:00
|
|
|
gtk_widget_set_halign (group, GTK_ALIGN_FILL);
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
label = gtk_label_new (title);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
g_object_set (label, "margin-top", 10, "margin-bottom", 10, NULL);
|
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
|
|
|
|
gtk_label_set_attributes (GTK_LABEL (label), attrs);
|
|
|
|
pango_attr_list_unref (attrs);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (group), label);
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2022-08-26 02:26:07 +00:00
|
|
|
for (i = 0; i < n_tags; i++)
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
|
|
|
hb_tag_t tag;
|
|
|
|
GtkWidget *feat;
|
|
|
|
FeatureItem *item;
|
2022-07-03 11:38:24 +00:00
|
|
|
char *name;
|
2018-04-01 23:35:55 +00:00
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *example;
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
tag = hb_tag_from_string (tags[i], -1);
|
|
|
|
name = get_feature_display_name (tag);
|
2020-08-30 20:41:02 +00:00
|
|
|
feat = gtk_check_button_new_with_label (name ? name : _("Default"));
|
2022-07-03 11:38:24 +00:00
|
|
|
g_free (name);
|
2018-01-03 04:46:37 +00:00
|
|
|
if (group_button == NULL)
|
|
|
|
group_button = feat;
|
2020-08-30 20:41:02 +00:00
|
|
|
else
|
|
|
|
gtk_check_button_set_group (GTK_CHECK_BUTTON (feat), GTK_CHECK_BUTTON (group_button));
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
g_signal_connect_swapped (feat, "notify::active", G_CALLBACK (update_font_features), fontchooser);
|
|
|
|
g_object_set_data (G_OBJECT (feat), "default", group_button);
|
|
|
|
|
2018-04-01 23:35:55 +00:00
|
|
|
example = gtk_label_new ("");
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (example), TRUE);
|
|
|
|
gtk_widget_set_halign (example, GTK_ALIGN_START);
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
|
|
|
gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), feat);
|
|
|
|
gtk_box_append (GTK_BOX (box), example);
|
|
|
|
gtk_box_append (GTK_BOX (group), box);
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
item = g_new (FeatureItem, 1);
|
|
|
|
item->name = tags[i];
|
|
|
|
item->tag = tag;
|
2018-04-01 23:35:55 +00:00
|
|
|
item->top = box;
|
2018-01-03 04:46:37 +00:00
|
|
|
item->feat = feat;
|
2018-04-01 23:35:55 +00:00
|
|
|
item->example = example;
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
fontchooser->feature_items = g_list_prepend (fontchooser->feature_items, item);
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (fontchooser->feature_box), group);
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_populate_features (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
2022-08-26 02:26:07 +00:00
|
|
|
const char *ligatures[] = { "liga", "dlig", "hlig", "clig" };
|
|
|
|
const char *letter_case[] = { "smcp", "c2sc", "pcap", "c2pc", "unic", "cpsp", "case" };
|
2022-08-28 21:02:56 +00:00
|
|
|
const char *number_case[] = { "xxnc", "lnum", "onum" };
|
|
|
|
const char *number_spacing[] = { "xxns", "pnum", "tnum" };
|
|
|
|
const char *fractions[] = { "xxnf", "frac", "afrc" };
|
2022-08-26 02:26:07 +00:00
|
|
|
const char *style_variants[] = {
|
2022-08-28 21:02:56 +00:00
|
|
|
"zero", "cswh", "calt", "falt", "hist", "jalt", "titl", "rand",
|
2018-04-01 23:35:55 +00:00
|
|
|
"ss01", "ss02", "ss03", "ss04", "ss05", "ss06", "ss07", "ss08", "ss09", "ss10",
|
|
|
|
"ss11", "ss12", "ss13", "ss14", "ss15", "ss16", "ss17", "ss18", "ss19", "ss20",
|
2022-08-26 02:26:07 +00:00
|
|
|
};
|
2022-08-28 21:02:56 +00:00
|
|
|
const char *style_variants2[] = {
|
|
|
|
"swsh", "salt", "nalt"
|
|
|
|
};
|
2022-08-26 02:26:07 +00:00
|
|
|
const char *char_variants[] = {
|
|
|
|
"cv01", "cv02", "cv03", "cv04", "cv05", "cv06", "cv07", "cv08", "cv09", "cv10",
|
|
|
|
"cv11", "cv12", "cv13", "cv14", "cv15", "cv16", "cv17", "cv18", "cv19", "cv20",
|
|
|
|
"cv21", "cv22", "cv23", "cv24", "cv25", "cv26", "cv27", "cv28", "cv29", "cv30",
|
|
|
|
"cv31", "cv32", "cv33", "cv34", "cv35", "cv36", "cv37", "cv38", "cv39", "cv40",
|
|
|
|
"cv41", "cv42", "cv43", "cv44", "cv45", "cv46", "cv47", "cv48", "cv49", "cv50",
|
|
|
|
"cv51", "cv52", "cv53", "cv54", "cv55", "cv56", "cv57", "cv58", "cv59", "cv60",
|
|
|
|
"cv61", "cv62", "cv63", "cv64", "cv65", "cv66", "cv67", "cv68", "cv69", "cv70",
|
|
|
|
"cv71", "cv72", "cv73", "cv74", "cv75", "cv76", "cv77", "cv78", "cv79", "cv80",
|
|
|
|
"cv81", "cv82", "cv83", "cv84", "cv85", "cv86", "cv87", "cv88", "cv89", "cv90",
|
|
|
|
"cv91", "cv92", "cv93", "cv94", "cv95", "cv96", "cv97", "cv98", "cv99",
|
|
|
|
};
|
|
|
|
|
|
|
|
add_check_group (fontchooser, _("Ligatures"), ligatures, G_N_ELEMENTS (ligatures));
|
|
|
|
add_check_group (fontchooser, _("Letter Case"), letter_case, G_N_ELEMENTS (letter_case));
|
|
|
|
add_radio_group (fontchooser, _("Number Case"), number_case, G_N_ELEMENTS (number_case));
|
|
|
|
add_radio_group (fontchooser, _("Number Spacing"), number_spacing, G_N_ELEMENTS (number_spacing));
|
|
|
|
add_radio_group (fontchooser, _("Fractions"), fractions, G_N_ELEMENTS (fractions));
|
|
|
|
add_check_group (fontchooser, _("Style Variations"), style_variants, G_N_ELEMENTS (style_variants));
|
2022-08-28 21:02:56 +00:00
|
|
|
add_enum_group (fontchooser, NULL, style_variants2, G_N_ELEMENTS (style_variants2));
|
2022-08-26 02:26:07 +00:00
|
|
|
add_enum_group (fontchooser, _("Character Variations"), char_variants, G_N_ELEMENTS (char_variants));
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
update_font_features (fontchooser);
|
|
|
|
}
|
|
|
|
|
2018-01-03 19:06:00 +00:00
|
|
|
static gboolean
|
2018-01-03 04:46:37 +00:00
|
|
|
gtk_font_chooser_widget_update_font_features (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
PangoFont *pango_font;
|
|
|
|
hb_font_t *hb_font;
|
2018-04-02 17:34:22 +00:00
|
|
|
hb_tag_t script_tag;
|
|
|
|
hb_tag_t lang_tag;
|
2018-01-03 04:46:37 +00:00
|
|
|
guint script_index = 0;
|
|
|
|
guint lang_index = 0;
|
|
|
|
int i, j;
|
|
|
|
GList *l;
|
2018-01-03 19:06:00 +00:00
|
|
|
gboolean has_feature = FALSE;
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
for (l = fontchooser->feature_items; l; l = l->next)
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
|
|
|
FeatureItem *item = l->data;
|
2022-08-26 02:26:07 +00:00
|
|
|
if (item->top)
|
|
|
|
{
|
|
|
|
gtk_widget_hide (item->top);
|
|
|
|
gtk_widget_hide (gtk_widget_get_parent (item->top));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_hide (gtk_widget_get_parent (item->feat));
|
|
|
|
gtk_widget_hide (item->feat);
|
|
|
|
gtk_widget_hide (gtk_widget_get_prev_sibling (item->feat));
|
|
|
|
gtk_widget_hide (item->example);
|
|
|
|
}
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
if ((fontchooser->level & GTK_FONT_CHOOSER_LEVEL_FEATURES) == 0)
|
2018-03-27 20:10:19 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2018-01-03 04:46:37 +00:00
|
|
|
pango_font = pango_context_load_font (gtk_widget_get_pango_context (GTK_WIDGET (fontchooser)),
|
2020-04-26 19:23:21 +00:00
|
|
|
fontchooser->font_desc);
|
2019-07-24 12:02:07 +00:00
|
|
|
hb_font = pango_font_get_hb_font (pango_font);
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
if (hb_font)
|
|
|
|
{
|
|
|
|
hb_tag_t table[2] = { HB_OT_TAG_GSUB, HB_OT_TAG_GPOS };
|
|
|
|
hb_face_t *hb_face;
|
|
|
|
hb_tag_t features[80];
|
|
|
|
unsigned int count;
|
|
|
|
unsigned int n_features;
|
2022-08-26 02:26:07 +00:00
|
|
|
hb_tag_t *feat;
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
hb_face = hb_font_get_face (hb_font);
|
|
|
|
|
2018-04-02 17:34:22 +00:00
|
|
|
find_language_and_script (fontchooser, hb_face, &lang_tag, &script_tag);
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
n_features = 0;
|
2022-08-26 02:26:07 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (table); i++)
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
|
|
|
hb_ot_layout_table_find_script (hb_face, table[i], script_tag, &script_index);
|
2019-04-12 17:40:08 +00:00
|
|
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
2018-01-03 04:46:37 +00:00
|
|
|
hb_ot_layout_script_find_language (hb_face, table[i], script_index, lang_tag, &lang_index);
|
2019-04-12 17:40:08 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
|
|
|
2022-08-26 02:26:07 +00:00
|
|
|
feat = features + n_features;
|
|
|
|
count = G_N_ELEMENTS (features) - n_features;
|
2018-01-03 04:46:37 +00:00
|
|
|
hb_ot_layout_language_get_feature_tags (hb_face,
|
|
|
|
table[i],
|
|
|
|
script_index,
|
|
|
|
lang_index,
|
|
|
|
n_features,
|
|
|
|
&count,
|
2022-08-26 02:26:07 +00:00
|
|
|
feat);
|
2018-01-03 04:46:37 +00:00
|
|
|
n_features += count;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < n_features; j++)
|
|
|
|
{
|
2020-04-26 19:23:21 +00:00
|
|
|
for (l = fontchooser->feature_items; l; l = l->next)
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
|
|
|
FeatureItem *item = l->data;
|
2022-08-28 21:02:56 +00:00
|
|
|
|
|
|
|
if (strncmp (item->name, "xx", 2) == 0)
|
|
|
|
{
|
|
|
|
update_feature_example (fontchooser, item, hb_font, script_tag, lang_tag, fontchooser->font_desc);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-01-03 04:46:37 +00:00
|
|
|
if (item->tag != features[j])
|
|
|
|
continue;
|
|
|
|
|
2018-01-03 19:06:00 +00:00
|
|
|
has_feature = TRUE;
|
2022-08-26 02:26:07 +00:00
|
|
|
if (item->top)
|
|
|
|
{
|
|
|
|
gtk_widget_show (item->top);
|
|
|
|
gtk_widget_show (gtk_widget_get_parent (item->top));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_show (gtk_widget_get_parent (item->feat));
|
|
|
|
gtk_widget_show (item->feat);
|
|
|
|
gtk_widget_show (gtk_widget_get_prev_sibling (item->feat));
|
|
|
|
gtk_widget_show (item->example);
|
|
|
|
}
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2022-07-03 11:38:24 +00:00
|
|
|
update_feature_label (fontchooser, item, hb_font, script_tag, lang_tag);
|
2021-12-31 14:17:42 +00:00
|
|
|
update_feature_example (fontchooser, item, hb_font, script_tag, lang_tag, fontchooser->font_desc);
|
2018-04-01 23:35:55 +00:00
|
|
|
|
2020-08-30 20:41:02 +00:00
|
|
|
if (GTK_IS_CHECK_BUTTON (item->feat))
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
|
|
|
GtkWidget *def = GTK_WIDGET (g_object_get_data (G_OBJECT (item->feat), "default"));
|
2020-08-30 20:41:02 +00:00
|
|
|
if (def)
|
|
|
|
{
|
|
|
|
gtk_widget_show (def);
|
|
|
|
gtk_widget_show (gtk_widget_get_parent (def));
|
|
|
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (def), TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
set_inconsistent (GTK_CHECK_BUTTON (item->feat), TRUE);
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-31 14:17:42 +00:00
|
|
|
|
|
|
|
if (fontchooser->glyphmap)
|
|
|
|
{
|
|
|
|
hb_map_destroy (fontchooser->glyphmap);
|
|
|
|
fontchooser->glyphmap = NULL;
|
|
|
|
}
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (pango_font);
|
2018-01-03 19:06:00 +00:00
|
|
|
|
|
|
|
return has_feature;
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_font_features (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
GString *s;
|
|
|
|
GList *l;
|
2022-01-03 02:34:05 +00:00
|
|
|
char buf[128];
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2018-01-03 18:41:20 +00:00
|
|
|
s = g_string_new ("");
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
for (l = fontchooser->feature_items; l; l = l->next)
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
|
|
|
FeatureItem *item = l->data;
|
|
|
|
|
|
|
|
if (!gtk_widget_is_sensitive (item->feat))
|
|
|
|
continue;
|
|
|
|
|
2020-08-30 20:41:02 +00:00
|
|
|
if (GTK_IS_CHECK_BUTTON (item->feat) && g_object_get_data (G_OBJECT (item->feat), "default"))
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
2020-08-30 20:41:02 +00:00
|
|
|
if (gtk_check_button_get_active (GTK_CHECK_BUTTON (item->feat)) &&
|
2022-08-28 21:02:56 +00:00
|
|
|
strncmp (item->name, "xx", 2) != 0)
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
2022-01-03 02:34:05 +00:00
|
|
|
hb_feature_to_string (&(hb_feature_t) { item->tag, 1, 0, -1 }, buf, sizeof (buf));
|
|
|
|
if (s->len > 0)
|
|
|
|
g_string_append_c (s, ',');
|
|
|
|
g_string_append (s, buf);
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (GTK_IS_CHECK_BUTTON (item->feat))
|
|
|
|
{
|
2022-01-03 02:34:05 +00:00
|
|
|
guint32 value;
|
|
|
|
|
2018-01-03 04:46:37 +00:00
|
|
|
if (gtk_check_button_get_inconsistent (GTK_CHECK_BUTTON (item->feat)))
|
|
|
|
continue;
|
|
|
|
|
2022-01-03 02:34:05 +00:00
|
|
|
value = gtk_check_button_get_active (GTK_CHECK_BUTTON (item->feat));
|
|
|
|
hb_feature_to_string (&(hb_feature_t) { item->tag, value, 0, -1 }, buf, sizeof (buf));
|
|
|
|
if (s->len > 0)
|
|
|
|
g_string_append_c (s, ',');
|
|
|
|
g_string_append (s, buf);
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
2022-08-26 02:26:07 +00:00
|
|
|
else if (GTK_IS_DROP_DOWN (item->feat))
|
|
|
|
{
|
|
|
|
guint value;
|
|
|
|
|
|
|
|
value = gtk_drop_down_get_selected (GTK_DROP_DOWN (item->feat));
|
|
|
|
if (value == 0 || value == GTK_INVALID_LIST_POSITION)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hb_feature_to_string (&(hb_feature_t) { item->tag, value, 0, -1 }, buf, sizeof (buf));
|
|
|
|
if (s->len > 0)
|
|
|
|
g_string_append_c (s, ',');
|
|
|
|
g_string_append (s, buf);
|
|
|
|
}
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
if (g_strcmp0 (fontchooser->font_features, s->str) != 0)
|
2018-01-03 04:46:37 +00:00
|
|
|
{
|
2020-04-26 19:23:21 +00:00
|
|
|
g_free (fontchooser->font_features);
|
|
|
|
fontchooser->font_features = g_string_free (s, FALSE);
|
2018-01-03 04:52:24 +00:00
|
|
|
g_object_notify (G_OBJECT (fontchooser), "font-features");
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
g_string_free (s, TRUE);
|
|
|
|
|
|
|
|
gtk_font_chooser_widget_update_preview_attributes (fontchooser);
|
|
|
|
}
|
|
|
|
|
2011-09-20 23:04:00 +00:00
|
|
|
static void
|
2015-07-22 13:04:34 +00:00
|
|
|
gtk_font_chooser_widget_merge_font_desc (GtkFontChooserWidget *fontchooser,
|
2019-11-28 03:00:39 +00:00
|
|
|
const PangoFontDescription *font_desc)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2011-09-19 23:17:29 +00:00
|
|
|
PangoFontMask mask;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-20 23:04:00 +00:00
|
|
|
g_assert (font_desc != NULL);
|
|
|
|
/* iter may be NULL if the font doesn't exist on the list */
|
|
|
|
|
|
|
|
mask = pango_font_description_get_set_fields (font_desc);
|
|
|
|
|
2021-11-27 15:10:53 +00:00
|
|
|
/* sucky test, because we can't restrict the comparison to
|
2011-09-20 23:04:00 +00:00
|
|
|
* only the parts that actually do get merged */
|
2020-04-26 19:23:21 +00:00
|
|
|
if (pango_font_description_equal (font_desc, fontchooser->font_desc))
|
2015-07-22 13:04:34 +00:00
|
|
|
return;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
pango_font_description_merge (fontchooser->font_desc, font_desc, TRUE);
|
2021-11-27 15:10:53 +00:00
|
|
|
|
2011-09-19 23:17:29 +00:00
|
|
|
if (mask & PANGO_FONT_MASK_SIZE)
|
|
|
|
{
|
2020-04-26 19:23:21 +00:00
|
|
|
double font_size = (double) pango_font_description_get_size (fontchooser->font_desc) / PANGO_SCALE;
|
2011-09-19 23:17:29 +00:00
|
|
|
/* XXX: This clamps, which can cause it to reloop into here, do we need
|
2022-01-03 02:34:05 +00:00
|
|
|
* to block its signal handler?
|
|
|
|
*/
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_range_set_value (GTK_RANGE (fontchooser->size_slider), font_size);
|
|
|
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (fontchooser->size_spin), font_size);
|
2011-09-19 23:17:29 +00:00
|
|
|
}
|
|
|
|
if (mask & (PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_STYLE | PANGO_FONT_MASK_VARIANT |
|
|
|
|
PANGO_FONT_MASK_WEIGHT | PANGO_FONT_MASK_STRETCH))
|
2011-09-20 23:04:00 +00:00
|
|
|
{
|
2018-01-03 19:06:00 +00:00
|
|
|
gboolean has_tweak = FALSE;
|
|
|
|
|
2011-09-21 00:40:26 +00:00
|
|
|
gtk_font_chooser_widget_update_marks (fontchooser);
|
2018-01-03 04:46:37 +00:00
|
|
|
|
2018-03-31 22:49:15 +00:00
|
|
|
if (gtk_font_chooser_widget_update_font_features (fontchooser))
|
|
|
|
has_tweak = TRUE;
|
|
|
|
if (gtk_font_chooser_widget_update_font_variations (fontchooser))
|
|
|
|
has_tweak = TRUE;
|
2019-07-24 12:02:07 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (fontchooser->tweak_action), has_tweak);
|
2011-09-20 23:04:00 +00:00
|
|
|
}
|
2011-09-19 23:17:29 +00:00
|
|
|
|
2021-11-27 15:10:53 +00:00
|
|
|
if (mask & PANGO_FONT_MASK_VARIATIONS)
|
|
|
|
{
|
|
|
|
if (pango_font_description_get_variations (fontchooser->font_desc)[0] == '\0')
|
|
|
|
pango_font_description_unset_fields (fontchooser->font_desc, PANGO_FONT_MASK_VARIANT);
|
|
|
|
}
|
|
|
|
|
2014-10-03 04:17:12 +00:00
|
|
|
gtk_font_chooser_widget_update_preview_attributes (fontchooser);
|
2011-09-19 23:17:29 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (fontchooser), "font");
|
|
|
|
g_object_notify (G_OBJECT (fontchooser), "font-desc");
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 20:45:44 +00:00
|
|
|
static void
|
2011-09-20 23:04:00 +00:00
|
|
|
gtk_font_chooser_widget_take_font_desc (GtkFontChooserWidget *fontchooser,
|
|
|
|
PangoFontDescription *font_desc)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2011-09-20 23:04:00 +00:00
|
|
|
PangoFontMask mask;
|
|
|
|
|
|
|
|
if (font_desc == NULL)
|
|
|
|
font_desc = pango_font_description_from_string (GTK_FONT_CHOOSER_DEFAULT_FONT_NAME);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-20 23:04:00 +00:00
|
|
|
mask = pango_font_description_get_set_fields (font_desc);
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_font_chooser_widget_merge_font_desc (fontchooser, font_desc);
|
|
|
|
|
2011-09-20 23:04:00 +00:00
|
|
|
if (mask & (PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_STYLE | PANGO_FONT_MASK_VARIANT |
|
|
|
|
PANGO_FONT_MASK_WEIGHT | PANGO_FONT_MASK_STRETCH))
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2021-03-02 22:55:30 +00:00
|
|
|
gtk_single_selection_set_selected (fontchooser->selection, GTK_INVALID_LIST_POSITION);
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_font_chooser_widget_ensure_matching_selection (fontchooser);
|
2011-09-11 22:13:26 +00:00
|
|
|
}
|
2015-07-22 13:04:34 +00:00
|
|
|
|
|
|
|
pango_font_description_free (font_desc);
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
static const char *
|
2011-09-11 23:49:26 +00:00
|
|
|
gtk_font_chooser_widget_get_preview_text (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
2019-05-28 02:27:47 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
return fontchooser->preview_text;
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_set_preview_text (GtkFontChooserWidget *fontchooser,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *text)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2020-09-08 19:14:17 +00:00
|
|
|
if (fontchooser->preview_text == text)
|
|
|
|
return;
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
g_free (fontchooser->preview_text);
|
|
|
|
fontchooser->preview_text = g_strdup (text);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (fontchooser->preview), text);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (fontchooser), "preview-text");
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_font_chooser_widget_get_show_preview_entry (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
2020-04-26 19:23:21 +00:00
|
|
|
return fontchooser->show_preview_entry;
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_set_show_preview_entry (GtkFontChooserWidget *fontchooser,
|
|
|
|
gboolean show_preview_entry)
|
|
|
|
{
|
2020-04-26 19:23:21 +00:00
|
|
|
if (fontchooser->show_preview_entry != show_preview_entry)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2020-04-26 19:23:21 +00:00
|
|
|
fontchooser->show_preview_entry = show_preview_entry;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
if (show_preview_entry)
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_widget_show (fontchooser->preview);
|
2011-09-11 23:49:26 +00:00
|
|
|
else
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_widget_hide (fontchooser->preview);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (fontchooser), "show-preview-entry");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-05 03:21:17 +00:00
|
|
|
static void
|
2015-06-13 03:55:30 +00:00
|
|
|
gtk_font_chooser_widget_set_font_map (GtkFontChooser *chooser,
|
|
|
|
PangoFontMap *fontmap)
|
2015-05-05 03:21:17 +00:00
|
|
|
{
|
2015-06-13 03:55:30 +00:00
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
|
2015-05-05 03:21:17 +00:00
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
if (g_set_object (&fontchooser->font_map, fontmap))
|
2015-05-05 03:21:17 +00:00
|
|
|
{
|
|
|
|
PangoContext *context;
|
|
|
|
|
|
|
|
if (!fontmap)
|
|
|
|
fontmap = pango_cairo_font_map_get_default ();
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
context = gtk_widget_get_pango_context (fontchooser->family_face_list);
|
2015-05-05 03:21:17 +00:00
|
|
|
pango_context_set_font_map (context, fontmap);
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
context = gtk_widget_get_pango_context (fontchooser->preview);
|
2015-05-09 05:58:32 +00:00
|
|
|
pango_context_set_font_map (context, fontmap);
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
update_fontlist (fontchooser);
|
2015-05-05 03:21:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-13 03:55:30 +00:00
|
|
|
static PangoFontMap *
|
|
|
|
gtk_font_chooser_widget_get_font_map (GtkFontChooser *chooser)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
return fontchooser->font_map;
|
2015-06-13 03:55:30 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_font_chooser_widget_filter_cb (gpointer item,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (data);
|
|
|
|
PangoFontFamily *family;
|
|
|
|
PangoFontFace *face;
|
|
|
|
|
|
|
|
if (PANGO_IS_FONT_FAMILY (item))
|
|
|
|
{
|
|
|
|
family = item;
|
|
|
|
face = pango_font_family_get_face (family, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
face = item;
|
|
|
|
family = pango_font_face_get_family (face);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self->filter_func (family, face, self->filter_data);
|
|
|
|
}
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void
|
2019-11-28 03:00:39 +00:00
|
|
|
gtk_font_chooser_widget_set_filter_func (GtkFontChooser *chooser,
|
2011-09-11 23:49:26 +00:00
|
|
|
GtkFontFilterFunc filter,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify destroy)
|
|
|
|
{
|
2019-11-28 03:00:39 +00:00
|
|
|
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (chooser);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
if (self->filter_data_destroy)
|
|
|
|
self->filter_data_destroy (self->filter_data);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
self->filter_func = filter;
|
|
|
|
self->filter_data = data;
|
|
|
|
self->filter_data_destroy = destroy;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
if (filter)
|
|
|
|
{
|
|
|
|
gtk_custom_filter_set_filter_func (self->custom_filter,
|
|
|
|
gtk_font_chooser_widget_filter_cb,
|
|
|
|
self,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_custom_filter_set_filter_func (self->custom_filter, NULL, NULL, NULL);
|
|
|
|
}
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 15:51:04 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_set_level (GtkFontChooserWidget *fontchooser,
|
|
|
|
GtkFontChooserLevel level)
|
|
|
|
{
|
2020-04-26 19:23:21 +00:00
|
|
|
if (fontchooser->level == level)
|
2017-12-21 15:51:04 +00:00
|
|
|
return;
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
fontchooser->level = level;
|
2017-12-21 15:51:04 +00:00
|
|
|
|
2018-03-27 20:10:19 +00:00
|
|
|
if ((level & GTK_FONT_CHOOSER_LEVEL_SIZE) != 0)
|
2017-12-21 15:51:04 +00:00
|
|
|
{
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_widget_show (fontchooser->size_label);
|
|
|
|
gtk_widget_show (fontchooser->size_slider);
|
|
|
|
gtk_widget_show (fontchooser->size_spin);
|
2022-07-03 16:50:40 +00:00
|
|
|
gtk_widget_show (fontchooser->size_label2);
|
|
|
|
gtk_widget_show (fontchooser->size_slider2);
|
|
|
|
gtk_widget_show (fontchooser->size_spin2);
|
2017-12-21 15:51:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-26 19:23:21 +00:00
|
|
|
gtk_widget_hide (fontchooser->size_label);
|
|
|
|
gtk_widget_hide (fontchooser->size_slider);
|
|
|
|
gtk_widget_hide (fontchooser->size_spin);
|
2022-07-03 16:50:40 +00:00
|
|
|
gtk_widget_hide (fontchooser->size_label2);
|
|
|
|
gtk_widget_hide (fontchooser->size_slider2);
|
|
|
|
gtk_widget_hide (fontchooser->size_spin2);
|
2017-12-21 15:51:04 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 03:00:39 +00:00
|
|
|
update_fontlist (fontchooser);
|
2017-12-21 15:51:04 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (fontchooser), "level");
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkFontChooserLevel
|
|
|
|
gtk_font_chooser_widget_get_level (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
2020-04-26 19:23:21 +00:00
|
|
|
return fontchooser->level;
|
2017-12-21 15:51:04 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 17:34:22 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_set_language (GtkFontChooserWidget *fontchooser,
|
|
|
|
const char *language)
|
|
|
|
{
|
|
|
|
PangoLanguage *lang;
|
|
|
|
|
|
|
|
lang = pango_language_from_string (language);
|
2020-04-26 19:23:21 +00:00
|
|
|
if (fontchooser->language == lang)
|
2018-04-02 17:34:22 +00:00
|
|
|
return;
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
fontchooser->language = lang;
|
2018-04-02 17:34:22 +00:00
|
|
|
g_object_notify (G_OBJECT (fontchooser), "language");
|
|
|
|
|
|
|
|
gtk_font_chooser_widget_update_preview_attributes (fontchooser);
|
|
|
|
}
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_iface_init (GtkFontChooserIface *iface)
|
|
|
|
{
|
|
|
|
iface->get_font_family = gtk_font_chooser_widget_get_family;
|
|
|
|
iface->get_font_face = gtk_font_chooser_widget_get_face;
|
|
|
|
iface->get_font_size = gtk_font_chooser_widget_get_size;
|
|
|
|
iface->set_filter_func = gtk_font_chooser_widget_set_filter_func;
|
2015-06-13 03:55:30 +00:00
|
|
|
iface->set_font_map = gtk_font_chooser_widget_set_font_map;
|
|
|
|
iface->get_font_map = gtk_font_chooser_widget_get_font_map;
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
2017-12-27 22:21:30 +00:00
|
|
|
|
2018-01-03 03:52:05 +00:00
|
|
|
GAction *
|
|
|
|
gtk_font_chooser_widget_get_tweak_action (GtkWidget *widget)
|
|
|
|
{
|
2019-05-28 02:27:47 +00:00
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (widget);
|
|
|
|
|
2020-04-26 19:23:21 +00:00
|
|
|
return fontchooser->tweak_action;
|
2018-01-03 03:52:05 +00:00
|
|
|
}
|