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 <atk/atk.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"
|
2011-09-11 23:49:26 +00:00
|
|
|
#include "gtkcellrenderertext.h"
|
2016-09-30 03:11:19 +00:00
|
|
|
#include "gtkcssnumbervalueprivate.h"
|
2011-09-11 23:49:26 +00:00
|
|
|
#include "gtkentry.h"
|
2012-06-12 02:45:31 +00:00
|
|
|
#include "gtksearchentry.h"
|
2012-03-03 18:41:55 +00:00
|
|
|
#include "gtkgrid.h"
|
|
|
|
#include "gtkfontchooser.h"
|
|
|
|
#include "gtkfontchooserutils.h"
|
|
|
|
#include "gtkintl.h"
|
2011-09-11 23:49:26 +00:00
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkliststore.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"
|
2011-09-11 23:49:26 +00:00
|
|
|
#include "gtkspinbutton.h"
|
2016-09-30 03:11:19 +00:00
|
|
|
#include "gtkstylecontextprivate.h"
|
2012-03-03 18:41:55 +00:00
|
|
|
#include "gtktextview.h"
|
|
|
|
#include "gtktreeselection.h"
|
|
|
|
#include "gtktreeview.h"
|
2011-09-11 23:49:26 +00:00
|
|
|
#include "gtkwidget.h"
|
2015-05-06 04:52:23 +00:00
|
|
|
#include "gtksettings.h"
|
2015-08-10 18:32:22 +00:00
|
|
|
#include "gtkdialog.h"
|
2018-01-03 04:46:37 +00:00
|
|
|
#include "gtkradiobutton.h"
|
|
|
|
#include "gtkcombobox.h"
|
|
|
|
#include "gtkgesturemultipress.h"
|
|
|
|
|
|
|
|
#if defined(HAVE_HARFBUZZ) && defined(HAVE_PANGOFT)
|
|
|
|
#include <pango/pangofc-font.h>
|
|
|
|
#include <hb.h>
|
|
|
|
#include <hb-ot.h>
|
|
|
|
#include <hb-ft.h>
|
|
|
|
#include <freetype/freetype.h>
|
|
|
|
#include <freetype/ftmm.h>
|
|
|
|
#include "language-names.h"
|
|
|
|
#include "script-names.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "open-type-layout.h"
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
/**
|
2012-02-04 00:39:10 +00:00
|
|
|
* SECTION:gtkfontchooserwidget
|
2011-09-11 23:49:26 +00:00
|
|
|
* @Short_description: A widget for selecting fonts
|
|
|
|
* @Title: GtkFontChooserWidget
|
2011-09-11 22:13:26 +00:00
|
|
|
* @See_also: #GtkFontChooserDialog
|
2011-09-11 23:49:26 +00:00
|
|
|
*
|
2011-09-11 01:48:20 +00:00
|
|
|
* The #GtkFontChooserWidget widget lists the available fonts,
|
|
|
|
* styles and sizes, allowing the user to select a font. It is
|
2011-09-11 22:13:26 +00:00
|
|
|
* used in the #GtkFontChooserDialog widget to provide a
|
2011-09-11 01:48:20 +00:00
|
|
|
* dialog box for selecting fonts.
|
2011-09-11 23:49:26 +00:00
|
|
|
*
|
|
|
|
* To set the font which is initially selected, use
|
2011-09-11 22:13:26 +00:00
|
|
|
* gtk_font_chooser_set_font() or gtk_font_chooser_set_font_desc().
|
2011-09-11 23:49:26 +00:00
|
|
|
*
|
2011-09-11 22:13:26 +00:00
|
|
|
* To get the selected font use gtk_font_chooser_get_font() or
|
|
|
|
* gtk_font_chooser_get_font_desc().
|
2011-09-11 23:49:26 +00:00
|
|
|
*
|
|
|
|
* To change the text which is shown in the preview area, use
|
2011-09-05 11:26:49 +00:00
|
|
|
* gtk_font_chooser_set_preview_text().
|
2011-09-11 23:49:26 +00:00
|
|
|
*
|
2016-01-14 04:42:35 +00:00
|
|
|
* # CSS nodes
|
|
|
|
*
|
|
|
|
* GtkFontChooserWidget has a single CSS node with name fontchooser.
|
2016-02-08 21:49:01 +00:00
|
|
|
*
|
|
|
|
* Since: 3.2
|
2011-09-11 23:49:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct _GtkFontChooserWidgetPrivate
|
|
|
|
{
|
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;
|
2013-03-26 09:50:01 +00:00
|
|
|
GtkTreeViewColumn *family_face_column;
|
2011-09-22 16:00:37 +00:00
|
|
|
GtkCellRenderer *family_face_cell;
|
2011-09-11 23:49:26 +00:00
|
|
|
GtkWidget *list_scrolled_window;
|
2015-05-07 22:28:39 +00:00
|
|
|
GtkWidget *list_stack;
|
2011-09-20 15:07:44 +00:00
|
|
|
GtkTreeModel *model;
|
2011-09-11 23:49:26 +00:00
|
|
|
GtkTreeModel *filter_model;
|
|
|
|
|
|
|
|
GtkWidget *preview;
|
2018-01-03 03:52:05 +00:00
|
|
|
GtkWidget *preview2;
|
|
|
|
GtkWidget *font_name_label;
|
2011-09-11 23:49:26 +00:00
|
|
|
gchar *preview_text;
|
|
|
|
gboolean show_preview_entry;
|
|
|
|
|
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;
|
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;
|
|
|
|
GtkWidget *feature_language_combo;
|
|
|
|
|
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;
|
|
|
|
PangoLanguage *font_language;
|
2011-09-20 22:07:21 +00:00
|
|
|
GtkTreeIter font_iter; /* invalid if font not available or pointer into model
|
|
|
|
(not filter_model) to the row containing font */
|
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;
|
2011-09-11 23:49:26 +00:00
|
|
|
};
|
|
|
|
|
2013-03-26 09:50:01 +00:00
|
|
|
/* Keep in line with GtkTreeStore defined in gtkfontchooserwidget.ui */
|
2011-09-11 23:49:26 +00:00
|
|
|
enum {
|
|
|
|
FAMILY_COLUMN,
|
|
|
|
FACE_COLUMN,
|
2011-09-19 15:58:51 +00:00
|
|
|
FONT_DESC_COLUMN,
|
2011-09-11 23:49:26 +00:00
|
|
|
PREVIEW_TITLE_COLUMN
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2017-10-30 21:19:02 +00:00
|
|
|
static void gtk_font_chooser_widget_display_changed (GtkWidget *widget,
|
|
|
|
GdkDisplay *previous_display);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-20 23:04:00 +00:00
|
|
|
static gboolean gtk_font_chooser_widget_find_font (GtkFontChooserWidget *fontchooser,
|
|
|
|
const PangoFontDescription *font_desc,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
static void gtk_font_chooser_widget_ensure_selection (GtkFontChooserWidget *fontchooser);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-12 11:57:10 +00:00
|
|
|
static gchar *gtk_font_chooser_widget_get_font (GtkFontChooserWidget *fontchooser);
|
|
|
|
static void gtk_font_chooser_widget_set_font (GtkFontChooserWidget *fontchooser,
|
|
|
|
const gchar *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,
|
|
|
|
const PangoFontDescription *font_desc,
|
|
|
|
GtkTreeIter *iter);
|
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);
|
|
|
|
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static const gchar *gtk_font_chooser_widget_get_preview_text (GtkFontChooserWidget *fontchooser);
|
|
|
|
static void gtk_font_chooser_widget_set_preview_text (GtkFontChooserWidget *fontchooser,
|
|
|
|
const gchar *text);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2013-03-26 09:50:01 +00:00
|
|
|
static void gtk_font_chooser_widget_set_cell_size (GtkFontChooserWidget *fontchooser);
|
2015-05-05 03:21:17 +00:00
|
|
|
static void gtk_font_chooser_widget_load_fonts (GtkFontChooserWidget *fontchooser,
|
|
|
|
gboolean force);
|
2018-01-03 04:46:37 +00:00
|
|
|
static void gtk_font_chooser_widget_populate_features (GtkFontChooserWidget *fontchooser);
|
2013-03-26 09:50:01 +00:00
|
|
|
static gboolean visible_func (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data);
|
|
|
|
static void gtk_font_chooser_widget_cell_data_func (GtkTreeViewColumn *column,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data);
|
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-01-03 03:52:05 +00:00
|
|
|
static void selection_changed (GtkTreeSelection *selection,
|
|
|
|
GtkFontChooserWidget *fontchooser);
|
2018-01-03 04:46:37 +00:00
|
|
|
static void update_font_features (GtkFontChooserWidget *fontchooser);
|
|
|
|
static void update_language (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,
|
2013-06-27 19:02:52 +00:00
|
|
|
G_ADD_PRIVATE (GtkFontChooserWidget)
|
2011-09-11 23:49:26 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_FONT_CHOOSER,
|
|
|
|
gtk_font_chooser_widget_iface_init))
|
|
|
|
|
2015-07-22 13:04:34 +00:00
|
|
|
typedef struct _GtkDelayedFontDescription GtkDelayedFontDescription;
|
|
|
|
struct _GtkDelayedFontDescription {
|
|
|
|
PangoFontFace *face;
|
|
|
|
PangoFontDescription *desc;
|
|
|
|
guint ref_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static GtkDelayedFontDescription *
|
|
|
|
gtk_delayed_font_description_new (PangoFontFace *face)
|
|
|
|
{
|
|
|
|
GtkDelayedFontDescription *result;
|
|
|
|
|
|
|
|
result = g_slice_new0 (GtkDelayedFontDescription);
|
|
|
|
|
|
|
|
result->face = g_object_ref (face);
|
|
|
|
result->desc = NULL;
|
|
|
|
result->ref_count = 1;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkDelayedFontDescription *
|
|
|
|
gtk_delayed_font_description_ref (GtkDelayedFontDescription *desc)
|
|
|
|
{
|
|
|
|
desc->ref_count++;
|
|
|
|
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_delayed_font_description_unref (GtkDelayedFontDescription *desc)
|
|
|
|
{
|
|
|
|
desc->ref_count--;
|
|
|
|
|
|
|
|
if (desc->ref_count > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_object_unref (desc->face);
|
|
|
|
if (desc->desc)
|
|
|
|
pango_font_description_free (desc->desc);
|
|
|
|
|
|
|
|
g_slice_free (GtkDelayedFontDescription, desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const PangoFontDescription *
|
|
|
|
gtk_delayed_font_description_get (GtkDelayedFontDescription *desc)
|
|
|
|
{
|
|
|
|
if (desc->desc == NULL)
|
|
|
|
desc->desc = pango_font_face_describe (desc->face);
|
|
|
|
|
|
|
|
return desc->desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GTK_TYPE_DELAYED_FONT_DESCRIPTION (gtk_delayed_font_description_get_type ())
|
2016-10-15 20:34:52 +00:00
|
|
|
GType gtk_delayed_font_description_get_type (void);
|
|
|
|
|
2015-07-22 13:04:34 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GtkDelayedFontDescription, gtk_delayed_font_description,
|
|
|
|
gtk_delayed_font_description_ref,
|
|
|
|
gtk_delayed_font_description_unref)
|
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)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
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:
|
|
|
|
gtk_font_chooser_widget_set_level (fontchooser, g_value_get_enum (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)
|
|
|
|
{
|
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:
|
|
|
|
g_value_set_enum (value, gtk_font_chooser_widget_get_level (fontchooser));
|
|
|
|
break;
|
2018-01-03 04:52:24 +00:00
|
|
|
case GTK_FONT_CHOOSER_PROP_FONT_FEATURES:
|
|
|
|
g_value_set_string (value, fontchooser->priv->font_features);
|
|
|
|
break;
|
|
|
|
case GTK_FONT_CHOOSER_PROP_LANGUAGE:
|
|
|
|
g_value_set_string (value, pango_language_to_string (fontchooser->priv->font_language));
|
|
|
|
break;
|
2011-09-11 23:49:26 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-21 03:49:43 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_refilter_font_list (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (fontchooser->priv->filter_model));
|
|
|
|
gtk_font_chooser_widget_ensure_selection (fontchooser);
|
|
|
|
}
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void
|
2012-06-12 02:45:31 +00:00
|
|
|
text_changed_cb (GtkEntry *entry,
|
2011-09-11 23:49:26 +00:00
|
|
|
GtkFontChooserWidget *fc)
|
|
|
|
{
|
2011-09-21 03:49:43 +00:00
|
|
|
gtk_font_chooser_widget_refilter_font_list (fc);
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
2015-08-10 18:15:26 +00:00
|
|
|
static void
|
|
|
|
stop_search_cb (GtkEntry *entry,
|
|
|
|
GtkFontChooserWidget *fc)
|
|
|
|
{
|
2015-08-10 18:32:22 +00:00
|
|
|
if (gtk_entry_get_text (entry)[0] != 0)
|
|
|
|
gtk_entry_set_text (entry, "");
|
|
|
|
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;
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
PangoFontDescription *font_desc;
|
2011-09-11 23:49:26 +00:00
|
|
|
gdouble 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 ();
|
2011-09-12 19:26:21 +00:00
|
|
|
if (pango_font_description_get_size_is_absolute (priv->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;
|
|
|
|
gchar *text;
|
|
|
|
gdouble value;
|
|
|
|
|
|
|
|
adjustment = gtk_spin_button_get_adjustment (spin);
|
|
|
|
value = gtk_adjustment_get_value (adjustment);
|
|
|
|
text = g_strdup_printf ("%2.4g", value);
|
2017-05-04 18:49:27 +00:00
|
|
|
gtk_spin_button_set_text (spin, text);
|
2014-08-15 18:57:31 +00:00
|
|
|
g_free (text);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void
|
2011-09-21 00:40:26 +00:00
|
|
|
gtk_font_chooser_widget_update_marks (GtkFontChooserWidget *fontchooser)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2011-09-21 00:40:26 +00:00
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
2013-08-02 13:51:33 +00:00
|
|
|
GtkAdjustment *adj, *spin_adj;
|
2011-09-21 00:40:26 +00:00
|
|
|
const int *sizes;
|
|
|
|
gint *font_sizes;
|
|
|
|
gint i, n_sizes;
|
2013-08-02 13:51:33 +00:00
|
|
|
gdouble value, spin_value;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-21 00:40:26 +00:00
|
|
|
if (gtk_list_store_iter_is_valid (GTK_LIST_STORE (priv->model), &priv->font_iter))
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2011-09-21 00:40:26 +00:00
|
|
|
PangoFontFace *face;
|
|
|
|
|
|
|
|
gtk_tree_model_get (priv->model, &priv->font_iter,
|
|
|
|
FACE_COLUMN, &face,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
g_object_unref (face);
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
static const gint fallback_sizes[] = {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_scale_clear_marks (GTK_SCALE (priv->size_slider));
|
2018-01-03 03:52:05 +00:00
|
|
|
gtk_scale_clear_marks (GTK_SCALE (priv->size_slider2));
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2013-08-02 13:51:33 +00:00
|
|
|
adj = gtk_range_get_adjustment (GTK_RANGE (priv->size_slider));
|
|
|
|
spin_adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin));
|
|
|
|
spin_value = gtk_adjustment_get_value (spin_adj);
|
|
|
|
|
|
|
|
if (spin_value < sizes[0])
|
|
|
|
value = (gdouble) sizes[0];
|
|
|
|
else if (spin_value > sizes[n_sizes - 1])
|
|
|
|
value = (gdouble)sizes[n_sizes - 1];
|
|
|
|
else
|
|
|
|
value = (gdouble)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 */
|
|
|
|
g_signal_handlers_block_by_func (adj, size_change_cb, fontchooser);
|
|
|
|
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));
|
|
|
|
g_signal_handlers_unblock_by_func (adj, size_change_cb, fontchooser);
|
|
|
|
|
|
|
|
for (i = 0; i < n_sizes; i++)
|
|
|
|
{
|
|
|
|
gtk_scale_add_mark (GTK_SCALE (priv->size_slider),
|
|
|
|
sizes[i],
|
|
|
|
GTK_POS_BOTTOM, NULL);
|
2018-01-03 03:52:05 +00:00
|
|
|
gtk_scale_add_mark (GTK_SCALE (priv->size_slider2),
|
|
|
|
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
|
|
|
|
row_activated_cb (GtkTreeView *view,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *column,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2011-09-12 11:57:10 +00:00
|
|
|
GtkFontChooserWidget *fontchooser = user_data;
|
2011-09-11 23:49:26 +00:00
|
|
|
gchar *fontname;
|
|
|
|
|
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
|
|
|
|
cursor_changed_cb (GtkTreeView *treeview,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2011-09-20 22:19:51 +00:00
|
|
|
GtkFontChooserWidget *fontchooser = user_data;
|
2011-09-11 23:49:26 +00:00
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
2015-07-22 13:04:34 +00:00
|
|
|
GtkDelayedFontDescription *desc;
|
2011-09-21 00:51:08 +00:00
|
|
|
GtkTreeIter filter_iter, iter;
|
2011-09-20 22:14:02 +00:00
|
|
|
GtkTreePath *path = NULL;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
gtk_tree_view_get_cursor (treeview, &path, NULL);
|
|
|
|
|
|
|
|
if (!path)
|
|
|
|
return;
|
|
|
|
|
2011-09-21 00:51:08 +00:00
|
|
|
if (!gtk_tree_model_get_iter (priv->filter_model, &filter_iter, path))
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
2011-09-21 00:51:08 +00:00
|
|
|
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (priv->filter_model),
|
|
|
|
&iter,
|
|
|
|
&filter_iter);
|
2015-07-29 19:57:22 +00:00
|
|
|
gtk_tree_model_get (priv->model, &iter,
|
2015-07-22 13:04:34 +00:00
|
|
|
FONT_DESC_COLUMN, &desc,
|
|
|
|
-1);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
pango_font_description_set_variations (priv->font_desc, NULL);
|
2015-07-22 13:04:34 +00:00
|
|
|
gtk_font_chooser_widget_merge_font_desc (fontchooser,
|
|
|
|
gtk_delayed_font_description_get (desc),
|
|
|
|
&iter);
|
|
|
|
|
|
|
|
gtk_delayed_font_description_unref (desc);
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2013-07-21 18:46:30 +00:00
|
|
|
resize_by_scroll_cb (GtkWidget *scrolled_window,
|
|
|
|
GdkEventScroll *event,
|
|
|
|
gpointer user_data)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2011-09-20 22:19:51 +00:00
|
|
|
GtkFontChooserWidget *fc = user_data;
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fc->priv;
|
2011-09-11 23:49:26 +00:00
|
|
|
GtkAdjustment *adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin));
|
2017-08-25 14:46:28 +00:00
|
|
|
GdkScrollDirection direction;
|
|
|
|
gdouble delta_x, delta_y;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2017-08-25 14:46:28 +00:00
|
|
|
if (!gdk_event_get_scroll_direction ((GdkEvent *) event, &direction))
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
gdk_event_get_scroll_deltas ((GdkEvent *) event, &delta_x, &delta_y);
|
|
|
|
|
|
|
|
if (direction == GDK_SCROLL_UP || direction == GDK_SCROLL_RIGHT)
|
2011-09-11 23:49:26 +00:00
|
|
|
gtk_adjustment_set_value (adj,
|
|
|
|
gtk_adjustment_get_value (adj) +
|
|
|
|
gtk_adjustment_get_step_increment (adj));
|
2017-08-25 14:46:28 +00:00
|
|
|
else if (direction == GDK_SCROLL_DOWN || direction == GDK_SCROLL_LEFT)
|
2011-09-11 23:49:26 +00:00
|
|
|
gtk_adjustment_set_value (adj,
|
|
|
|
gtk_adjustment_get_value (adj) -
|
|
|
|
gtk_adjustment_get_step_increment (adj));
|
2017-08-25 14:46:28 +00:00
|
|
|
else if (direction == GDK_SCROLL_SMOOTH && delta_x != 0.0)
|
2013-07-21 18:46:30 +00:00
|
|
|
gtk_adjustment_set_value (adj,
|
|
|
|
gtk_adjustment_get_value (adj) +
|
2017-08-25 14:46:28 +00:00
|
|
|
gtk_adjustment_get_step_increment (adj) * delta_x);
|
|
|
|
else if (direction == GDK_SCROLL_SMOOTH && delta_y != 0.0)
|
2013-07-21 18:46:30 +00:00
|
|
|
gtk_adjustment_set_value (adj,
|
|
|
|
gtk_adjustment_get_value (adj) -
|
2017-08-25 14:46:28 +00:00
|
|
|
gtk_adjustment_get_step_increment (adj) * delta_y);
|
2013-07-21 18:46:30 +00:00
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-10-03 04:17:12 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_update_preview_attributes (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
|
|
|
|
priv = fontchooser->priv;
|
|
|
|
|
|
|
|
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 */
|
2014-10-03 04:17:12 +00:00
|
|
|
pango_attr_list_insert (attrs, pango_attr_font_desc_new (priv->font_desc));
|
2018-01-03 04:46:37 +00:00
|
|
|
if (priv->font_features)
|
|
|
|
pango_attr_list_insert (attrs, pango_attr_font_features_new (priv->font_features));
|
|
|
|
if (priv->font_language)
|
|
|
|
pango_attr_list_insert (attrs, pango_attr_language_new (priv->font_language));
|
2014-10-03 04:17:12 +00:00
|
|
|
|
|
|
|
gtk_entry_set_attributes (GTK_ENTRY (priv->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
|
2017-12-19 19:17:55 +00:00
|
|
|
rows_changed_cb (GtkFontChooserWidget *fontchooser)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
2011-09-20 22:19:51 +00:00
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
2018-01-03 03:52:05 +00:00
|
|
|
const char *page;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2017-12-19 19:17:55 +00:00
|
|
|
if (gtk_tree_model_iter_n_children (priv->filter_model, NULL) == 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";
|
|
|
|
|
|
|
|
if (strcmp (gtk_stack_get_visible_child_name (GTK_STACK (priv->list_stack)), page) != 0)
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (priv->list_stack), page);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (widget);
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (priv->search_entry), "");
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "list");
|
|
|
|
g_simple_action_set_state (G_SIMPLE_ACTION (priv->tweak_action), g_variant_new_boolean (FALSE));
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->map (widget);
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 19:49:00 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_measure (GtkWidget *widget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural,
|
|
|
|
int *minimum_baseline,
|
|
|
|
int *natural_baseline)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (widget);
|
|
|
|
GtkFontChooserWidgetPrivate *priv = gtk_font_chooser_widget_get_instance_private (self);
|
|
|
|
|
2018-01-03 03:52:05 +00:00
|
|
|
gtk_widget_measure (priv->stack, orientation, for_size,
|
2017-03-25 19:49:00 +00:00
|
|
|
minimum, natural,
|
|
|
|
minimum_baseline, natural_baseline);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_snapshot (GtkWidget *widget,
|
|
|
|
GtkSnapshot *snapshot)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (widget);
|
|
|
|
GtkFontChooserWidgetPrivate *priv = gtk_font_chooser_widget_get_instance_private (self);
|
|
|
|
|
2018-01-03 03:52:05 +00:00
|
|
|
gtk_widget_snapshot_child (widget, priv->stack, snapshot);
|
2017-03-25 19:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-11 07:58:21 +00:00
|
|
|
gtk_font_chooser_widget_size_allocate (GtkWidget *widget,
|
|
|
|
const GtkAllocation *allocation,
|
|
|
|
int baseline,
|
|
|
|
GtkAllocation *out_clip)
|
2017-03-25 19:49:00 +00:00
|
|
|
{
|
|
|
|
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (widget);
|
|
|
|
GtkFontChooserWidgetPrivate *priv = gtk_font_chooser_widget_get_instance_private (self);
|
|
|
|
|
2017-07-11 07:58:21 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->size_allocate (widget, allocation, -1, out_clip);
|
2017-04-30 19:53:05 +00:00
|
|
|
|
2018-01-03 03:52:05 +00:00
|
|
|
gtk_widget_size_allocate (priv->stack, allocation, -1, out_clip);
|
2017-03-25 19:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (object);
|
|
|
|
GtkFontChooserWidgetPrivate *priv = gtk_font_chooser_widget_get_instance_private (self);
|
|
|
|
|
2018-01-03 03:52:05 +00:00
|
|
|
if (priv->stack)
|
2017-03-25 19:49:00 +00:00
|
|
|
{
|
2018-01-03 03:52:05 +00:00
|
|
|
gtk_widget_unparent (priv->stack);
|
|
|
|
priv->stack = NULL;
|
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);
|
|
|
|
|
2015-07-22 13:04:34 +00:00
|
|
|
g_type_ensure (GTK_TYPE_DELAYED_FONT_DESCRIPTION);
|
2015-12-04 21:59:29 +00:00
|
|
|
g_type_ensure (G_TYPE_THEMED_ICON);
|
2015-07-22 13:04:34 +00:00
|
|
|
|
2017-10-30 21:19:02 +00:00
|
|
|
widget_class->display_changed = gtk_font_chooser_widget_display_changed;
|
2017-03-25 19:49:00 +00:00
|
|
|
widget_class->measure = gtk_font_chooser_widget_measure;
|
|
|
|
widget_class->size_allocate = gtk_font_chooser_widget_size_allocate;
|
|
|
|
widget_class->snapshot = gtk_font_chooser_widget_snapshot;
|
2018-01-03 03:52:05 +00:00
|
|
|
widget_class->map = gtk_font_chooser_widget_map;
|
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;
|
|
|
|
|
|
|
|
_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
|
|
|
|
2013-07-26 20:29:12 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, search_entry);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, family_face_list);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, family_face_column);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, family_face_cell);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, list_scrolled_window);
|
2015-05-07 22:28:39 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, list_stack);
|
2013-07-26 20:29:12 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, model);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, filter_model);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, preview);
|
2018-01-03 03:52:05 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, preview2);
|
2017-12-21 15:51:04 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, size_label);
|
2013-07-26 20:29:12 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, size_spin);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, size_slider);
|
2018-01-03 03:52:05 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, size_slider2);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, stack);
|
2017-03-25 19:49:00 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, grid);
|
2018-01-03 03:52:05 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, font_name_label);
|
2018-01-03 04:46:37 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, feature_box);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, feature_language_combo);
|
2018-01-03 18:28:33 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, axis_grid);
|
2013-07-26 17:49:49 +00:00
|
|
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, text_changed_cb);
|
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, cursor_changed_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, row_activated_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, gtk_font_chooser_widget_set_cell_size);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, resize_by_scroll_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);
|
2018-01-03 03:52:05 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, selection_changed);
|
2018-01-03 04:46:37 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, update_language);
|
2016-01-14 04:42:35 +00:00
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
gtk_entry_grab_focus_without_selecting (GTK_ENTRY (fontchooser->priv->preview2));
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (fontchooser->priv->stack), "tweaks");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_entry_grab_focus_without_selecting (GTK_ENTRY (fontchooser->priv->search_entry));
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (fontchooser->priv->stack), "list");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_simple_action_set_state (action, state);
|
|
|
|
}
|
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
#if defined(HAVE_HARFBUZZ) && defined(HAVE_PANGOFT)
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
guint32 tag;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
Axis *a = value;
|
|
|
|
|
|
|
|
gtk_widget_destroy (a->label);
|
|
|
|
gtk_widget_destroy (a->scale);
|
|
|
|
gtk_widget_destroy (a->spin);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
axis_free (gpointer v)
|
|
|
|
{
|
|
|
|
Axis *a = v;
|
|
|
|
|
|
|
|
g_free (a);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
2011-09-20 22:19:51 +00:00
|
|
|
GtkFontChooserWidgetPrivate *priv;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
fontchooser->priv = gtk_font_chooser_widget_get_instance_private (fontchooser);
|
2011-09-11 23:49:26 +00:00
|
|
|
priv = fontchooser->priv;
|
|
|
|
|
2017-03-25 19:49:00 +00:00
|
|
|
gtk_widget_set_has_window (GTK_WIDGET (fontchooser), FALSE);
|
|
|
|
|
2013-03-26 09:50:01 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (fontchooser));
|
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
#if defined(HAVE_HARFBUZZ) && defined(HAVE_PANGOFT)
|
|
|
|
priv->axes = g_hash_table_new_full (axis_hash, axis_equal, NULL, axis_free);
|
|
|
|
#endif
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
/* Default preview string */
|
|
|
|
priv->preview_text = g_strdup (pango_language_get_sample_string (NULL));
|
|
|
|
priv->show_preview_entry = TRUE;
|
2011-09-19 23:17:29 +00:00
|
|
|
priv->font_desc = pango_font_description_new ();
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
/* Set default preview text */
|
2014-08-15 21:29:34 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (priv->preview), priv->preview_text);
|
|
|
|
|
2014-10-03 04:17:12 +00:00
|
|
|
gtk_font_chooser_widget_update_preview_attributes (fontchooser);
|
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 */
|
|
|
|
gtk_spin_button_set_range (GTK_SPIN_BUTTON (priv->size_spin),
|
2013-08-02 13:56:54 +00:00
|
|
|
1.0, (gdouble)(G_MAXINT / PANGO_SCALE));
|
2013-03-26 09:50:01 +00:00
|
|
|
gtk_adjustment_set_upper (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider)),
|
|
|
|
(gdouble)(G_MAXINT / PANGO_SCALE));
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2013-03-26 09:50:01 +00:00
|
|
|
/* Setup treeview/model auxilary functions */
|
|
|
|
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->filter_model),
|
|
|
|
visible_func, (gpointer)priv, NULL);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2013-03-26 09:50:01 +00:00
|
|
|
gtk_tree_view_column_set_cell_data_func (priv->family_face_column,
|
|
|
|
priv->family_face_cell,
|
|
|
|
gtk_font_chooser_widget_cell_data_func,
|
|
|
|
fontchooser,
|
|
|
|
NULL);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2018-01-03 03:52:05 +00:00
|
|
|
priv->tweak_action = G_ACTION (g_simple_action_new_stateful ("tweak", NULL, g_variant_new_boolean (FALSE)));
|
|
|
|
g_signal_connect (priv->tweak_action, "change-state", G_CALLBACK (change_tweak), fontchooser);
|
|
|
|
|
2014-10-02 04:30:52 +00:00
|
|
|
/* Load data and set initial style-dependent parameters */
|
2015-05-05 03:21:17 +00:00
|
|
|
gtk_font_chooser_widget_load_fonts (fontchooser, TRUE);
|
2018-01-03 04:46:37 +00:00
|
|
|
gtk_font_chooser_widget_populate_features (fontchooser);
|
2013-03-26 09:50:01 +00:00
|
|
|
gtk_font_chooser_widget_set_cell_size (fontchooser);
|
2011-09-12 11:57:10 +00:00
|
|
|
gtk_font_chooser_widget_take_font_desc (fontchooser, NULL);
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_font_chooser_widget_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GtkFontChooserWidget.
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: a new #GtkFontChooserWidget
|
2011-09-11 23:49:26 +00:00
|
|
|
*
|
|
|
|
* Since: 3.2
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_font_chooser_widget_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_FONT_CHOOSER_WIDGET, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cmp_families (const void *a,
|
|
|
|
const void *b)
|
|
|
|
{
|
|
|
|
const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a);
|
|
|
|
const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b);
|
|
|
|
|
|
|
|
return g_utf8_collate (a_name, b_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-05-05 03:21:17 +00:00
|
|
|
gtk_font_chooser_widget_load_fonts (GtkFontChooserWidget *fontchooser,
|
|
|
|
gboolean force)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
2011-09-20 15:06:18 +00:00
|
|
|
GtkListStore *list_store;
|
2011-09-11 23:49:26 +00:00
|
|
|
gint n_families, i;
|
|
|
|
PangoFontFamily **families;
|
2015-05-04 12:25:27 +00:00
|
|
|
guint fontconfig_timestamp;
|
2015-05-05 03:21:17 +00:00
|
|
|
gboolean need_reload;
|
|
|
|
PangoFontMap *font_map;
|
2015-05-04 12:25:27 +00:00
|
|
|
|
|
|
|
g_object_get (gtk_widget_get_settings (GTK_WIDGET (fontchooser)),
|
|
|
|
"gtk-fontconfig-timestamp", &fontconfig_timestamp,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* The fontconfig timestamp is only set on systems with fontconfig; every
|
|
|
|
* other platform will set it to 0. For those systems, we fall back to
|
|
|
|
* reloading the fonts every time.
|
|
|
|
*/
|
2015-05-05 03:21:17 +00:00
|
|
|
need_reload = fontconfig_timestamp == 0 ||
|
|
|
|
fontconfig_timestamp != priv->last_fontconfig_timestamp;
|
2015-05-04 12:25:27 +00:00
|
|
|
|
|
|
|
priv->last_fontconfig_timestamp = fontconfig_timestamp;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2015-05-05 03:21:17 +00:00
|
|
|
if (!need_reload && !force)
|
|
|
|
return;
|
|
|
|
|
2011-09-20 15:06:18 +00:00
|
|
|
list_store = GTK_LIST_STORE (priv->model);
|
|
|
|
|
2015-05-05 03:21:17 +00:00
|
|
|
if (priv->font_map)
|
|
|
|
font_map = priv->font_map;
|
|
|
|
else
|
|
|
|
font_map = pango_cairo_font_map_get_default ();
|
|
|
|
pango_font_map_list_families (font_map, &families, &n_families);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
|
|
|
|
|
2015-05-05 03:21:17 +00:00
|
|
|
g_signal_handlers_block_by_func (priv->family_face_list, cursor_changed_cb, fontchooser);
|
2017-12-19 16:37:05 +00:00
|
|
|
g_signal_handlers_block_by_func (priv->filter_model, rows_changed_cb, fontchooser);
|
2011-09-20 15:06:18 +00:00
|
|
|
gtk_list_store_clear (list_store);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
/* Iterate over families and faces */
|
|
|
|
for (i = 0; i < n_families; i++)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
PangoFontFace **faces;
|
|
|
|
int j, n_faces;
|
|
|
|
const gchar *fam_name = pango_font_family_get_name (families[i]);
|
|
|
|
|
|
|
|
pango_font_family_list_faces (families[i], &faces, &n_faces);
|
|
|
|
|
|
|
|
for (j = 0; j < n_faces; j++)
|
|
|
|
{
|
2015-07-22 13:04:34 +00:00
|
|
|
GtkDelayedFontDescription *desc;
|
2011-09-11 23:49:26 +00:00
|
|
|
const gchar *face_name;
|
2017-12-21 15:51:04 +00:00
|
|
|
char *title;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
face_name = pango_font_face_get_face_name (faces[j]);
|
|
|
|
|
2017-12-21 15:51:04 +00:00
|
|
|
if (priv->level == GTK_FONT_CHOOSER_LEVEL_FAMILY)
|
|
|
|
title = g_strdup (fam_name);
|
|
|
|
else
|
|
|
|
title = g_strconcat (fam_name, " ", face_name, NULL);
|
|
|
|
|
2015-07-22 13:04:34 +00:00
|
|
|
desc = gtk_delayed_font_description_new (faces[j]);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-20 15:06:18 +00:00
|
|
|
gtk_list_store_insert_with_values (list_store, &iter, -1,
|
2011-09-16 08:21:58 +00:00
|
|
|
FAMILY_COLUMN, families[i],
|
|
|
|
FACE_COLUMN, faces[j],
|
2015-07-22 13:04:34 +00:00
|
|
|
FONT_DESC_COLUMN, desc,
|
2017-12-21 15:51:04 +00:00
|
|
|
PREVIEW_TITLE_COLUMN, title,
|
2011-09-16 08:21:58 +00:00
|
|
|
-1);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2017-12-21 15:51:04 +00:00
|
|
|
g_free (title);
|
2015-07-22 13:04:34 +00:00
|
|
|
gtk_delayed_font_description_unref (desc);
|
2017-12-21 15:51:04 +00:00
|
|
|
|
|
|
|
if (priv->level == GTK_FONT_CHOOSER_LEVEL_FAMILY)
|
|
|
|
break;
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (faces);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (families);
|
2011-09-20 23:04:00 +00:00
|
|
|
|
2017-12-19 19:17:55 +00:00
|
|
|
rows_changed_cb (fontchooser);
|
2017-12-19 16:37:05 +00:00
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (priv->filter_model, rows_changed_cb, fontchooser);
|
|
|
|
g_signal_handlers_unblock_by_func (priv->family_face_list, cursor_changed_cb, fontchooser);
|
|
|
|
|
2011-09-20 23:04:00 +00:00
|
|
|
/* now make sure the font list looks right */
|
2015-05-05 03:21:17 +00:00
|
|
|
if (!gtk_font_chooser_widget_find_font (fontchooser, priv->font_desc, &priv->font_iter))
|
2011-09-20 23:04:00 +00:00
|
|
|
memset (&priv->font_iter, 0, sizeof (GtkTreeIter));
|
|
|
|
|
|
|
|
gtk_font_chooser_widget_ensure_selection (fontchooser);
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
visible_func (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2011-09-16 08:14:15 +00:00
|
|
|
GtkFontChooserWidgetPrivate *priv = user_data;
|
2011-09-11 23:49:26 +00:00
|
|
|
gboolean result = TRUE;
|
2011-09-16 08:14:15 +00:00
|
|
|
const gchar *search_text;
|
|
|
|
gchar **split_terms;
|
2011-09-21 02:21:42 +00:00
|
|
|
gchar *font_name, *font_name_casefold;
|
2011-09-16 08:14:15 +00:00
|
|
|
guint i;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-19 13:45:24 +00:00
|
|
|
if (priv->filter_func != NULL)
|
|
|
|
{
|
|
|
|
PangoFontFamily *family;
|
|
|
|
PangoFontFace *face;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
FAMILY_COLUMN, &family,
|
|
|
|
FACE_COLUMN, &face,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
result = priv->filter_func (family, face, priv->filter_data);
|
|
|
|
|
|
|
|
g_object_unref (family);
|
|
|
|
g_object_unref (face);
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
/* If there's no filter string we show the item */
|
2011-09-16 08:14:15 +00:00
|
|
|
search_text = gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
|
2011-09-11 23:49:26 +00:00
|
|
|
if (strlen (search_text) == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
PREVIEW_TITLE_COLUMN, &font_name,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (font_name == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
split_terms = g_strsplit (search_text, " ", 0);
|
2011-09-16 08:14:15 +00:00
|
|
|
font_name_casefold = g_utf8_casefold (font_name, -1);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-16 08:14:15 +00:00
|
|
|
for (i = 0; split_terms[i] && result; i++)
|
|
|
|
{
|
|
|
|
gchar* term_casefold = g_utf8_casefold (split_terms[i], -1);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-16 08:14:15 +00:00
|
|
|
if (!strstr (font_name_casefold, term_casefold))
|
|
|
|
result = FALSE;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-16 08:14:15 +00:00
|
|
|
g_free (term_casefold);
|
|
|
|
}
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-16 08:14:15 +00:00
|
|
|
g_free (font_name_casefold);
|
2011-09-11 23:49:26 +00:00
|
|
|
g_free (font_name);
|
|
|
|
g_strfreev (split_terms);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-09-21 18:31:06 +00:00
|
|
|
/* in pango units */
|
|
|
|
static int
|
|
|
|
gtk_font_chooser_widget_get_preview_text_height (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
GtkWidget *treeview = fontchooser->priv->family_face_list;
|
2016-09-30 03:11:19 +00:00
|
|
|
GtkStyleContext *context;
|
2011-09-21 18:31:06 +00:00
|
|
|
double dpi, font_size;
|
|
|
|
|
2016-09-30 03:11:19 +00:00
|
|
|
context = gtk_widget_get_style_context (treeview);
|
|
|
|
dpi = _gtk_css_number_value_get (_gtk_style_context_peek_property (context,
|
|
|
|
GTK_CSS_PROPERTY_DPI),
|
|
|
|
100);
|
|
|
|
gtk_style_context_get (context,
|
2011-09-21 18:31:06 +00:00
|
|
|
"font-size", &font_size,
|
|
|
|
NULL);
|
|
|
|
|
2011-12-15 18:38:48 +00:00
|
|
|
return (dpi < 0.0 ? 96.0 : dpi) / 72.0 * PANGO_SCALE_X_LARGE * font_size * PANGO_SCALE;
|
2011-09-21 18:31:06 +00:00
|
|
|
}
|
|
|
|
|
2011-09-22 15:34:56 +00:00
|
|
|
static PangoAttrList *
|
|
|
|
gtk_font_chooser_widget_get_preview_attributes (GtkFontChooserWidget *fontchooser,
|
2017-12-19 22:10:34 +00:00
|
|
|
const PangoFontDescription *font_desc)
|
2011-09-22 15:34:56 +00:00
|
|
|
{
|
|
|
|
PangoAttribute *attribute;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
|
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
|
2011-09-22 16:00:37 +00:00
|
|
|
if (font_desc)
|
|
|
|
{
|
|
|
|
attribute = pango_attr_font_desc_new (font_desc);
|
|
|
|
pango_attr_list_insert (attrs, attribute);
|
|
|
|
}
|
2011-09-22 15:34:56 +00:00
|
|
|
|
|
|
|
attribute = pango_attr_size_new_absolute (gtk_font_chooser_widget_get_preview_text_height (fontchooser));
|
|
|
|
pango_attr_list_insert (attrs, attribute);
|
|
|
|
|
|
|
|
return attrs;
|
|
|
|
}
|
|
|
|
|
2011-09-20 14:32:15 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_cell_data_func (GtkTreeViewColumn *column,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = user_data;
|
2015-07-22 13:04:34 +00:00
|
|
|
GtkDelayedFontDescription *desc;
|
2011-09-21 01:27:43 +00:00
|
|
|
PangoAttrList *attrs;
|
2017-12-19 22:10:34 +00:00
|
|
|
char *preview_title;
|
2011-09-20 14:32:15 +00:00
|
|
|
|
2014-08-15 17:27:00 +00:00
|
|
|
gtk_tree_model_get (tree_model, iter,
|
|
|
|
PREVIEW_TITLE_COLUMN, &preview_title,
|
2015-07-22 13:04:34 +00:00
|
|
|
FONT_DESC_COLUMN, &desc,
|
2014-08-15 17:27:00 +00:00
|
|
|
-1);
|
|
|
|
|
2017-12-19 22:10:34 +00:00
|
|
|
attrs = gtk_font_chooser_widget_get_preview_attributes (fontchooser,
|
|
|
|
gtk_delayed_font_description_get (desc));
|
2011-09-20 14:32:15 +00:00
|
|
|
|
|
|
|
g_object_set (cell,
|
2017-12-19 22:10:34 +00:00
|
|
|
"xpad", 20,
|
|
|
|
"ypad", 10,
|
2011-09-21 01:27:43 +00:00
|
|
|
"attributes", attrs,
|
2017-12-19 22:10:34 +00:00
|
|
|
"text", preview_title,
|
2011-09-20 14:32:15 +00:00
|
|
|
NULL);
|
|
|
|
|
2015-07-22 13:04:34 +00:00
|
|
|
gtk_delayed_font_description_unref (desc);
|
2011-09-21 01:27:43 +00:00
|
|
|
pango_attr_list_unref (attrs);
|
2014-10-15 03:59:25 +00:00
|
|
|
g_free (preview_title);
|
2011-09-20 14:32:15 +00:00
|
|
|
}
|
|
|
|
|
2011-09-22 16:00:37 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_set_cell_size (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
GtkRequisition size;
|
|
|
|
|
|
|
|
gtk_cell_renderer_set_fixed_size (priv->family_face_cell, -1, -1);
|
|
|
|
|
2017-12-19 22:10:34 +00:00
|
|
|
attrs = gtk_font_chooser_widget_get_preview_attributes (fontchooser, NULL);
|
2011-09-22 16:00:37 +00:00
|
|
|
|
|
|
|
g_object_set (priv->family_face_cell,
|
2017-12-19 22:10:34 +00:00
|
|
|
"xpad", 20,
|
|
|
|
"ypad", 10,
|
2011-09-22 16:00:37 +00:00
|
|
|
"attributes", attrs,
|
2017-12-19 22:10:34 +00:00
|
|
|
"text", "x",
|
2011-09-22 16:00:37 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
pango_attr_list_unref (attrs);
|
|
|
|
|
|
|
|
gtk_cell_renderer_get_preferred_size (priv->family_face_cell,
|
|
|
|
priv->family_face_list,
|
|
|
|
&size,
|
|
|
|
NULL);
|
|
|
|
gtk_cell_renderer_set_fixed_size (priv->family_face_cell, size.width, size.height);
|
|
|
|
}
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (object);
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
|
2011-09-11 22:13:26 +00:00
|
|
|
if (priv->font_desc)
|
|
|
|
pango_font_description_free (priv->font_desc);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
if (priv->filter_data_destroy)
|
|
|
|
priv->filter_data_destroy (priv->filter_data);
|
|
|
|
|
2014-10-15 03:59:25 +00:00
|
|
|
g_free (priv->preview_text);
|
|
|
|
|
2015-05-05 03:21:17 +00:00
|
|
|
g_clear_object (&priv->font_map);
|
|
|
|
|
2018-01-03 03:52:05 +00:00
|
|
|
g_object_unref (priv->tweak_action);
|
|
|
|
|
2018-01-03 04:46:37 +00:00
|
|
|
g_list_free_full (priv->feature_items, g_free);
|
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
if (priv->axes)
|
|
|
|
g_hash_table_unref (priv->axes);
|
|
|
|
|
2018-01-03 04:46:37 +00:00
|
|
|
g_free (priv->font_features);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-09-20 00:54:42 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_font_chooser_widget_find_font (GtkFontChooserWidget *fontchooser,
|
|
|
|
const PangoFontDescription *font_desc,
|
|
|
|
/* out arguments */
|
2011-09-20 22:31:26 +00:00
|
|
|
GtkTreeIter *iter)
|
2011-09-20 00:54:42 +00:00
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
2014-10-23 19:13:29 +00:00
|
|
|
gboolean valid;
|
2011-09-20 00:54:42 +00:00
|
|
|
|
2011-09-21 03:44:22 +00:00
|
|
|
if (pango_font_description_get_family (font_desc) == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-09-20 15:07:44 +00:00
|
|
|
for (valid = gtk_tree_model_get_iter_first (priv->model, iter);
|
2014-10-23 19:13:29 +00:00
|
|
|
valid;
|
2011-09-20 15:07:44 +00:00
|
|
|
valid = gtk_tree_model_iter_next (priv->model, iter))
|
2011-09-20 00:54:42 +00:00
|
|
|
{
|
2015-07-22 13:04:34 +00:00
|
|
|
GtkDelayedFontDescription *desc;
|
|
|
|
PangoFontDescription *merged;
|
2014-10-23 19:13:29 +00:00
|
|
|
PangoFontFamily *family;
|
|
|
|
|
2011-09-21 03:44:22 +00:00
|
|
|
gtk_tree_model_get (priv->model, iter,
|
|
|
|
FAMILY_COLUMN, &family,
|
2015-07-22 13:04:34 +00:00
|
|
|
FONT_DESC_COLUMN, &desc,
|
2011-09-21 03:44:22 +00:00
|
|
|
-1);
|
|
|
|
|
|
|
|
if (!my_pango_font_family_equal (pango_font_description_get_family (font_desc),
|
|
|
|
pango_font_family_get_name (family)))
|
2015-07-22 13:04:34 +00:00
|
|
|
{
|
|
|
|
gtk_delayed_font_description_unref (desc);
|
|
|
|
g_object_unref (family);
|
|
|
|
continue;
|
|
|
|
}
|
2011-09-21 03:44:22 +00:00
|
|
|
|
2015-07-22 13:04:34 +00:00
|
|
|
merged = pango_font_description_copy_static (gtk_delayed_font_description_get (desc));
|
2011-09-20 00:54:42 +00:00
|
|
|
|
2015-07-22 13:04:34 +00:00
|
|
|
pango_font_description_merge_static (merged, font_desc, FALSE);
|
|
|
|
if (pango_font_description_equal (merged, font_desc))
|
|
|
|
{
|
|
|
|
gtk_delayed_font_description_unref (desc);
|
|
|
|
pango_font_description_free (merged);
|
|
|
|
g_object_unref (family);
|
|
|
|
break;
|
|
|
|
}
|
2011-09-20 00:54:42 +00:00
|
|
|
|
2015-07-22 13:04:34 +00:00
|
|
|
gtk_delayed_font_description_unref (desc);
|
|
|
|
pango_font_description_free (merged);
|
|
|
|
g_object_unref (family);
|
2011-09-20 00:54:42 +00:00
|
|
|
}
|
2018-01-03 03:52:05 +00:00
|
|
|
|
2014-10-23 19:13:29 +00:00
|
|
|
return valid;
|
2011-09-20 00:54:42 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 03:21:17 +00:00
|
|
|
static void
|
|
|
|
fontconfig_changed (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
gtk_font_chooser_widget_load_fonts (fontchooser, TRUE);
|
|
|
|
}
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void
|
2017-10-30 21:19:02 +00:00
|
|
|
gtk_font_chooser_widget_display_changed (GtkWidget *widget,
|
|
|
|
GdkDisplay *previous_display)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (widget);
|
2015-05-06 04:52:23 +00:00
|
|
|
GtkSettings *settings;
|
2011-09-11 22:13:26 +00:00
|
|
|
|
2017-10-30 21:19:02 +00:00
|
|
|
if (GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->display_changed)
|
|
|
|
GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->display_changed (widget, previous_display);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2017-10-30 21:19:02 +00:00
|
|
|
if (previous_display)
|
2015-05-06 04:52:23 +00:00
|
|
|
{
|
2017-10-30 21:19:02 +00:00
|
|
|
settings = gtk_settings_get_for_display (previous_display);
|
2015-05-05 03:21:17 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (settings, fontconfig_changed, widget);
|
2015-05-06 04:52:23 +00:00
|
|
|
}
|
|
|
|
settings = gtk_widget_get_settings (widget);
|
|
|
|
g_signal_connect_object (settings, "notify::gtk-fontconfig-timestamp",
|
2015-05-05 03:21:17 +00:00
|
|
|
G_CALLBACK (fontconfig_changed), widget, G_CONNECT_SWAPPED);
|
2015-05-06 04:52:23 +00:00
|
|
|
|
2017-10-30 21:19:02 +00:00
|
|
|
if (previous_display == NULL)
|
|
|
|
previous_display = gdk_display_get_default ();
|
2011-09-19 16:35:57 +00:00
|
|
|
|
2017-10-30 21:19:02 +00:00
|
|
|
if (previous_display == gtk_widget_get_display (widget))
|
2011-09-19 16:35:57 +00:00
|
|
|
return;
|
|
|
|
|
2015-05-05 03:21:17 +00:00
|
|
|
gtk_font_chooser_widget_load_fonts (fontchooser, FALSE);
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PangoFontFamily *
|
|
|
|
gtk_font_chooser_widget_get_family (GtkFontChooser *chooser)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
|
2011-09-20 22:31:26 +00:00
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
PangoFontFamily *family;
|
|
|
|
|
|
|
|
if (!gtk_list_store_iter_is_valid (GTK_LIST_STORE (priv->model), &priv->font_iter))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
gtk_tree_model_get (priv->model, &priv->font_iter,
|
|
|
|
FAMILY_COLUMN, &family,
|
|
|
|
-1);
|
|
|
|
g_object_unref (family);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-20 22:31:26 +00:00
|
|
|
return family;
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PangoFontFace *
|
|
|
|
gtk_font_chooser_widget_get_face (GtkFontChooser *chooser)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
|
2011-09-20 22:31:26 +00:00
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
PangoFontFace *face;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-20 22:31:26 +00:00
|
|
|
if (!gtk_list_store_iter_is_valid (GTK_LIST_STORE (priv->model), &priv->font_iter))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
gtk_tree_model_get (priv->model, &priv->font_iter,
|
|
|
|
FACE_COLUMN, &face,
|
|
|
|
-1);
|
|
|
|
g_object_unref (face);
|
|
|
|
|
|
|
|
return face;
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
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 *
|
2011-09-12 11:57:10 +00:00
|
|
|
gtk_font_chooser_widget_get_font_desc (GtkFontChooserWidget *fontchooser)
|
2011-09-11 22:13:26 +00:00
|
|
|
{
|
2018-01-03 03:52:05 +00:00
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->family_face_list));
|
|
|
|
if (gtk_tree_selection_count_selected_rows (selection) > 0)
|
|
|
|
return fontchooser->priv->font_desc;
|
|
|
|
|
|
|
|
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,
|
|
|
|
const gchar *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 03:52:05 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_update_font_name (GtkFontChooserWidget *fontchooser,
|
|
|
|
GtkTreeSelection *selection)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
PangoFontFamily *family;
|
|
|
|
PangoFontFace *face;
|
|
|
|
GtkDelayedFontDescription *desc;
|
|
|
|
const PangoFontDescription *font_desc;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
const char *fam_name;
|
|
|
|
const char *face_name;
|
|
|
|
char *title;
|
|
|
|
|
|
|
|
gtk_tree_selection_get_selected (selection, &model, &iter);
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
FAMILY_COLUMN, &family,
|
|
|
|
FACE_COLUMN, &face,
|
|
|
|
FONT_DESC_COLUMN, &desc,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
fam_name = pango_font_family_get_name (family);
|
|
|
|
face_name = pango_font_face_get_face_name (face);
|
|
|
|
font_desc = gtk_delayed_font_description_get (desc);
|
|
|
|
|
|
|
|
g_object_unref (family);
|
|
|
|
g_object_unref (face);
|
2018-01-05 02:19:28 +00:00
|
|
|
gtk_delayed_font_description_unref (desc);
|
2018-01-03 03:52:05 +00:00
|
|
|
|
|
|
|
if (priv->level == GTK_FONT_CHOOSER_LEVEL_FAMILY)
|
|
|
|
title = g_strdup (fam_name);
|
|
|
|
else
|
|
|
|
title = g_strconcat (fam_name, " ", face_name, NULL);
|
|
|
|
|
|
|
|
attrs = gtk_font_chooser_widget_get_preview_attributes (fontchooser, font_desc);
|
|
|
|
gtk_label_set_attributes (GTK_LABEL (priv->font_name_label), attrs);
|
|
|
|
pango_attr_list_unref (attrs);
|
|
|
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (priv->font_name_label), title);
|
|
|
|
g_free (title);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
selection_changed (GtkTreeSelection *selection,
|
|
|
|
GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (fontchooser), "font");
|
|
|
|
g_object_notify (G_OBJECT (fontchooser), "font-desc");
|
|
|
|
|
|
|
|
if (gtk_tree_selection_count_selected_rows (selection) > 0)
|
|
|
|
{
|
|
|
|
gtk_font_chooser_widget_update_font_name (fontchooser, selection);
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (priv->tweak_action), TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_simple_action_set_state (G_SIMPLE_ACTION (priv->tweak_action), g_variant_new_boolean (FALSE));
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (priv->tweak_action), FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-11 22:13:26 +00:00
|
|
|
static void
|
2011-09-20 23:04:00 +00:00
|
|
|
gtk_font_chooser_widget_ensure_selection (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeIter filter_iter;
|
2018-01-03 03:52:05 +00:00
|
|
|
|
2011-09-20 23:04:00 +00:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->family_face_list));
|
|
|
|
|
|
|
|
if (gtk_list_store_iter_is_valid (GTK_LIST_STORE (priv->model), &priv->font_iter) &&
|
|
|
|
gtk_tree_model_filter_convert_child_iter_to_iter (GTK_TREE_MODEL_FILTER (priv->filter_model),
|
|
|
|
&filter_iter,
|
|
|
|
&priv->font_iter))
|
|
|
|
{
|
2012-09-16 17:17:08 +00:00
|
|
|
GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter_model),
|
|
|
|
&filter_iter);
|
|
|
|
|
2011-09-20 23:04:00 +00:00
|
|
|
gtk_tree_selection_select_iter (selection, &filter_iter);
|
2012-09-16 17:17:08 +00:00
|
|
|
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->family_face_list),
|
|
|
|
path, NULL, FALSE, 0.0, 0.0);
|
|
|
|
gtk_tree_path_free (path);
|
2011-09-20 23:04:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_tree_selection_unselect_all (selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-03 04:46:37 +00:00
|
|
|
#if defined(HAVE_HARFBUZZ) && defined(HAVE_PANGOFT)
|
|
|
|
|
2018-01-03 18:28:33 +00:00
|
|
|
/* OpenType variations */
|
|
|
|
|
|
|
|
#define FixedToFloat(f) (((float)(f))/65536.0)
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_font_variations (GtkFontChooserWidget *fontchooser,
|
|
|
|
GString *s)
|
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
Axis *axis;
|
|
|
|
const char *sep = "";
|
|
|
|
char buf[G_ASCII_DTOSTR_BUF_SIZE];
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, fontchooser->priv->axes);
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *)NULL, (gpointer *)&axis))
|
|
|
|
{
|
|
|
|
char tag[5];
|
|
|
|
double value;
|
|
|
|
|
|
|
|
tag[0] = (axis->tag >> 24) & 0xff;
|
|
|
|
tag[1] = (axis->tag >> 16) & 0xff;
|
|
|
|
tag[2] = (axis->tag >> 8) & 0xff;
|
|
|
|
tag[3] = (axis->tag >> 0) & 0xff;
|
|
|
|
tag[4] = '\0';
|
|
|
|
value = gtk_adjustment_get_value (axis->adjustment);
|
|
|
|
g_string_append_printf (s, "%s%s=%s", sep, tag, g_ascii_dtostr (buf, sizeof(buf), value));
|
|
|
|
sep = ",";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
adjustment_changed (GtkAdjustment *adjustment,
|
|
|
|
Axis *axis)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (axis->fontchooser);
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
PangoFontDescription *font_desc;
|
|
|
|
GString *s;
|
|
|
|
|
|
|
|
priv->updating_variations = TRUE;
|
|
|
|
|
|
|
|
s = g_string_new ("");
|
|
|
|
add_font_variations (fontchooser, s);
|
|
|
|
|
|
|
|
if (s->len > 0)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_free (s, TRUE);
|
|
|
|
|
|
|
|
priv->updating_variations = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
should_show_axis (FT_Var_Axis *ax)
|
|
|
|
{
|
|
|
|
/* FIXME use FT_Get_Var_Axis_Flags */
|
|
|
|
if (ax->tag == FT_MAKE_TAG ('o', 'p', 's', 'z'))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_named_instance (FT_Face face)
|
|
|
|
{
|
|
|
|
return (face->face_index >> 16) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
guint32 tag;
|
|
|
|
const char *name;
|
|
|
|
} axis_names[] = {
|
|
|
|
{ FT_MAKE_TAG ('w', 'd', 't', 'h'), N_("Width") },
|
|
|
|
{ FT_MAKE_TAG ('w', 'g', 'h', 't'), N_("Weight") },
|
|
|
|
{ FT_MAKE_TAG ('i', 't', 'a', 'l'), N_("Italic") },
|
|
|
|
{ FT_MAKE_TAG ('s', 'l', 'n', 't'), N_("Slant") },
|
|
|
|
{ FT_MAKE_TAG ('o', 'p', 's', 'z'), N_("Optical Size") },
|
|
|
|
};
|
|
|
|
|
2018-01-03 19:06:00 +00:00
|
|
|
static gboolean
|
2018-01-03 18:28:33 +00:00
|
|
|
add_axis (GtkFontChooserWidget *fontchooser,
|
|
|
|
FT_Face face,
|
|
|
|
FT_Var_Axis *ax,
|
|
|
|
FT_Fixed value,
|
|
|
|
int row)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
Axis *axis;
|
|
|
|
const char *name;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
axis = g_new (Axis, 1);
|
|
|
|
axis->tag = ax->tag;
|
|
|
|
axis->fontchooser = GTK_WIDGET (fontchooser);
|
|
|
|
|
|
|
|
name = ax->name;
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (axis_names); i++)
|
|
|
|
{
|
|
|
|
if (axis_names[i].tag == ax->tag)
|
|
|
|
{
|
|
|
|
name = _(axis_names[i].name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
axis->label = gtk_label_new (name);
|
|
|
|
gtk_widget_set_halign (axis->label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (axis->label, GTK_ALIGN_BASELINE);
|
|
|
|
gtk_grid_attach (GTK_GRID (priv->axis_grid), axis->label, 0, row, 1, 1);
|
|
|
|
axis->adjustment = gtk_adjustment_new ((double)FixedToFloat(value),
|
|
|
|
(double)FixedToFloat(ax->minimum),
|
|
|
|
(double)FixedToFloat(ax->maximum),
|
|
|
|
1.0, 10.0, 0.0);
|
|
|
|
axis->scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, axis->adjustment);
|
|
|
|
gtk_scale_add_mark (GTK_SCALE (axis->scale), (double)FixedToFloat(ax->def), GTK_POS_TOP, NULL);
|
|
|
|
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);
|
|
|
|
gtk_grid_attach (GTK_GRID (priv->axis_grid), axis->scale, 1, row, 1, 1);
|
|
|
|
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);
|
|
|
|
gtk_grid_attach (GTK_GRID (priv->axis_grid), axis->spin, 2, row, 1, 1);
|
|
|
|
|
|
|
|
g_hash_table_add (priv->axes, axis);
|
|
|
|
|
|
|
|
adjustment_changed (axis->adjustment, axis);
|
|
|
|
g_signal_connect (axis->adjustment, "value-changed", G_CALLBACK (adjustment_changed), axis);
|
|
|
|
if (is_named_instance (face) || !should_show_axis (ax))
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
PangoFont *pango_font;
|
|
|
|
FT_Face ft_face;
|
|
|
|
FT_MM_Var *ft_mm_var;
|
|
|
|
FT_Error ret;
|
2018-01-03 19:06:00 +00:00
|
|
|
gboolean has_axis = FALSE;
|
2018-01-03 18:28:33 +00:00
|
|
|
|
|
|
|
if (priv->updating_variations)
|
2018-01-03 19:06:00 +00:00
|
|
|
return FALSE;
|
2018-01-03 18:28:33 +00:00
|
|
|
|
|
|
|
g_hash_table_foreach (priv->axes, axis_remove, NULL);
|
|
|
|
g_hash_table_remove_all (priv->axes);
|
|
|
|
|
|
|
|
pango_font = pango_context_load_font (gtk_widget_get_pango_context (GTK_WIDGET (fontchooser)),
|
|
|
|
priv->font_desc);
|
|
|
|
ft_face = pango_fc_font_lock_face (PANGO_FC_FONT (pango_font));
|
|
|
|
|
|
|
|
ret = FT_Get_MM_Var (ft_face, &ft_mm_var);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FT_Fixed *coords;
|
|
|
|
|
|
|
|
coords = g_new (FT_Fixed, ft_mm_var->num_axis);
|
|
|
|
for (i = 0; i < ft_mm_var->num_axis; i++)
|
|
|
|
coords[i] = ft_mm_var->axis[i].def;
|
|
|
|
|
|
|
|
if (ft_face->face_index > 0)
|
|
|
|
{
|
|
|
|
int instance_id = ft_face->face_index >> 16;
|
|
|
|
if (instance_id && instance_id <= ft_mm_var->num_namedstyles)
|
|
|
|
{
|
|
|
|
FT_Var_Named_Style *instance = &ft_mm_var->namedstyle[instance_id - 1];
|
|
|
|
memcpy (coords, instance->coords, ft_mm_var->num_axis * sizeof (*coords));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ft_mm_var->num_axis; i++)
|
2018-01-03 19:06:00 +00:00
|
|
|
{
|
|
|
|
if (add_axis (fontchooser, ft_face, &ft_mm_var->axis[i], coords[i], i + 4))
|
|
|
|
has_axis = TRUE;
|
|
|
|
}
|
2018-01-03 18:28:33 +00:00
|
|
|
|
|
|
|
g_free (coords);
|
|
|
|
free (ft_mm_var);
|
|
|
|
}
|
|
|
|
|
|
|
|
pango_fc_font_unlock_face (PANGO_FC_FONT (pango_font));
|
|
|
|
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-01-03 04:46:37 +00:00
|
|
|
static void
|
|
|
|
add_script (GtkListStore *store,
|
|
|
|
guint script_index,
|
|
|
|
hb_tag_t script,
|
|
|
|
guint lang_index,
|
|
|
|
hb_tag_t lang)
|
|
|
|
{
|
|
|
|
char langbuf[5];
|
|
|
|
const char *langname;
|
|
|
|
|
|
|
|
if (lang == HB_OT_TAG_DEFAULT_LANGUAGE)
|
|
|
|
langname = C_("Language", "Default");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
langname = get_language_name_for_tag (lang);
|
|
|
|
if (!langname)
|
|
|
|
{
|
|
|
|
hb_tag_to_string (lang, langbuf);
|
|
|
|
langbuf[4] = 0;
|
|
|
|
langname = langbuf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_list_store_insert_with_values (store, NULL, -1,
|
|
|
|
0, langname,
|
|
|
|
1, script_index,
|
|
|
|
2, lang_index,
|
|
|
|
3, lang,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
feature_language_sort_func (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *a,
|
|
|
|
GtkTreeIter *b,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
char *sa, *sb;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, a, 0, &sa, -1);
|
|
|
|
gtk_tree_model_get (model, b, 0, &sb, -1);
|
|
|
|
|
|
|
|
ret = strcmp (sa, sb);
|
|
|
|
|
|
|
|
g_free (sa);
|
|
|
|
g_free (sb);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
hb_tag_t script_tag;
|
|
|
|
hb_tag_t lang_tag;
|
|
|
|
unsigned int script_index;
|
|
|
|
unsigned int lang_index;
|
|
|
|
} TagPair;
|
|
|
|
|
|
|
|
static guint
|
|
|
|
tag_pair_hash (gconstpointer data)
|
|
|
|
{
|
|
|
|
const TagPair *pair = data;
|
|
|
|
|
|
|
|
return pair->script_tag + pair->lang_tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
tag_pair_equal (gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
const TagPair *pair_a = a;
|
|
|
|
const TagPair *pair_b = b;
|
|
|
|
|
|
|
|
return pair_a->script_tag == pair_b->script_tag && pair_a->lang_tag == pair_b->lang_tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_language_combo (GtkFontChooserWidget *fontchooser,
|
|
|
|
hb_face_t *hb_face)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
GtkListStore *store;
|
|
|
|
gint i, j, k;
|
|
|
|
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 };
|
|
|
|
GHashTable *tags;
|
|
|
|
GHashTableIter iter;
|
|
|
|
TagPair *pair;
|
|
|
|
|
|
|
|
tags = g_hash_table_new_full (tag_pair_hash, tag_pair_equal, g_free, NULL);
|
|
|
|
|
|
|
|
pair = g_new (TagPair, 1);
|
|
|
|
pair->script_tag = HB_OT_TAG_DEFAULT_SCRIPT;
|
|
|
|
pair->lang_tag = HB_OT_TAG_DEFAULT_LANGUAGE;
|
|
|
|
g_hash_table_add (tags, pair);
|
|
|
|
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
pair = g_new (TagPair, 1);
|
|
|
|
pair->script_tag = scripts[j];
|
|
|
|
pair->lang_tag = languages[k];
|
|
|
|
pair->script_index = j;
|
|
|
|
pair->lang_index = k;
|
|
|
|
g_hash_table_add (tags, pair);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, tags);
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *)&pair, NULL))
|
|
|
|
add_script (store, pair->script_index, pair->script_tag, pair->lang_index, pair->lang_tag);
|
|
|
|
|
|
|
|
g_hash_table_unref (tags);
|
|
|
|
|
|
|
|
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
|
|
|
|
feature_language_sort_func, NULL, NULL);
|
|
|
|
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
|
|
|
|
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
|
|
|
|
GTK_SORT_ASCENDING);
|
|
|
|
gtk_combo_box_set_model (GTK_COMBO_BOX (priv->feature_language_combo), GTK_TREE_MODEL (store));
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (priv->feature_language_combo), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
hb_tag_t tag;
|
|
|
|
const char *name;
|
|
|
|
GtkWidget *feat;
|
|
|
|
} FeatureItem;
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
get_feature_display_name (hb_tag_t tag)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (open_type_layout_features); i++)
|
|
|
|
{
|
|
|
|
if (tag == open_type_layout_features[i].tag)
|
|
|
|
return g_dpgettext2 (NULL, "OpenType layout", open_type_layout_features[i].name);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
feat_clicked (GtkWidget *feat,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (feat, feat_clicked, NULL);
|
|
|
|
|
|
|
|
if (gtk_check_button_get_inconsistent (GTK_CHECK_BUTTON (feat)))
|
|
|
|
{
|
|
|
|
set_inconsistent (GTK_CHECK_BUTTON (feat), FALSE);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (feat), TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (feat, feat_clicked, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
feat_pressed (GtkGesture *gesture,
|
|
|
|
int n_press,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
GtkWidget *feat)
|
|
|
|
{
|
|
|
|
gboolean inconsistent;
|
|
|
|
|
|
|
|
inconsistent = gtk_check_button_get_inconsistent (GTK_CHECK_BUTTON (feat));
|
|
|
|
set_inconsistent (GTK_CHECK_BUTTON (feat), !inconsistent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_check_group (GtkFontChooserWidget *fontchooser,
|
|
|
|
const char *title,
|
|
|
|
const char **tags)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *group;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
group = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_widget_set_halign (group, GTK_ALIGN_START);
|
|
|
|
|
|
|
|
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_container_add (GTK_CONTAINER (group), label);
|
|
|
|
|
|
|
|
for (i = 0; tags[i]; i++)
|
|
|
|
{
|
|
|
|
hb_tag_t tag;
|
|
|
|
GtkWidget *feat;
|
|
|
|
FeatureItem *item;
|
|
|
|
GtkGesture *gesture;
|
|
|
|
|
|
|
|
tag = hb_tag_from_string (tags[i], -1);
|
|
|
|
|
|
|
|
feat = gtk_check_button_new_with_label (get_feature_display_name (tag));
|
|
|
|
set_inconsistent (GTK_CHECK_BUTTON (feat), TRUE);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (feat, "notify::active", G_CALLBACK (update_font_features), fontchooser);
|
|
|
|
g_signal_connect_swapped (feat, "notify::inconsistent", G_CALLBACK (update_font_features), fontchooser);
|
|
|
|
g_signal_connect (feat, "clicked", G_CALLBACK (feat_clicked), NULL);
|
|
|
|
|
|
|
|
gesture = gtk_gesture_multi_press_new (feat);
|
|
|
|
g_object_set_data_full (G_OBJECT (feat), "press", gesture, g_object_unref);
|
|
|
|
|
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY);
|
|
|
|
g_signal_connect (gesture, "pressed", G_CALLBACK (feat_pressed), feat);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (group), feat);
|
|
|
|
|
|
|
|
item = g_new (FeatureItem, 1);
|
|
|
|
item->name = tags[i];
|
|
|
|
item->tag = tag;
|
|
|
|
item->feat = feat;
|
|
|
|
|
|
|
|
priv->feature_items = g_list_prepend (priv->feature_items, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->feature_box), group);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_radio_group (GtkFontChooserWidget *fontchooser,
|
|
|
|
const char *title,
|
|
|
|
const char **tags)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *group;
|
|
|
|
int i;
|
|
|
|
GtkWidget *group_button = NULL;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
|
|
|
|
group = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_widget_set_halign (group, GTK_ALIGN_START);
|
|
|
|
|
|
|
|
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_container_add (GTK_CONTAINER (group), label);
|
|
|
|
|
|
|
|
for (i = 0; tags[i]; i++)
|
|
|
|
{
|
|
|
|
hb_tag_t tag;
|
|
|
|
GtkWidget *feat;
|
|
|
|
FeatureItem *item;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
tag = hb_tag_from_string (tags[i], -1);
|
|
|
|
name = get_feature_display_name (tag);
|
|
|
|
|
|
|
|
feat = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (group_button),
|
|
|
|
name ? name : _("Default"));
|
|
|
|
if (group_button == NULL)
|
|
|
|
group_button = feat;
|
|
|
|
|
|
|
|
g_signal_connect_swapped (feat, "notify::active", G_CALLBACK (update_font_features), fontchooser);
|
|
|
|
g_object_set_data (G_OBJECT (feat), "default", group_button);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (group), feat);
|
|
|
|
|
|
|
|
item = g_new (FeatureItem, 1);
|
|
|
|
item->name = tags[i];
|
|
|
|
item->tag = tag;
|
|
|
|
item->feat = feat;
|
|
|
|
|
|
|
|
priv->feature_items = g_list_prepend (priv->feature_items, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->feature_box), group);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_populate_features (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
const char *ligatures[] = { "liga", "dlig", "hlig", "clig", NULL };
|
|
|
|
const char *letter_case[] = { "smcp", "c2sc", "pcap", "c2pc", "unic", "cpsp", "case", NULL };
|
|
|
|
const char *number_case[] = { "xxxx", "lnum", "onum", NULL };
|
|
|
|
const char *number_spacing[] = { "xxxx", "pnum", "tnum", NULL };
|
|
|
|
const char *number_formatting[] = { "zero", "nalt", NULL };
|
|
|
|
const char *char_variants[] = { "swsh", "cswh", "calt", "falt", "hist", "salt", "jalt", "titl", "rand", NULL };
|
|
|
|
|
|
|
|
add_check_group (fontchooser, _("Ligatures"), ligatures);
|
|
|
|
add_check_group (fontchooser, _("Letter Case"), letter_case);
|
|
|
|
add_radio_group (fontchooser, _("Number Case"), number_case);
|
|
|
|
add_radio_group (fontchooser, _("Number Spacing"), number_spacing);
|
|
|
|
add_check_group (fontchooser, _("Number Formatting"), number_formatting);
|
|
|
|
add_check_group (fontchooser, _("Character Variants"), char_variants);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
PangoFont *pango_font;
|
|
|
|
FT_Face ft_face;
|
|
|
|
hb_font_t *hb_font;
|
|
|
|
hb_tag_t script_tag = FT_MAKE_TAG('l','a','t','n');
|
|
|
|
hb_tag_t lang_tag = FT_MAKE_TAG('D','E','U',' ');
|
|
|
|
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
|
|
|
|
|
|
|
gtk_widget_hide (priv->feature_language_combo);
|
|
|
|
|
|
|
|
for (l = priv->feature_items; l; l = l->next)
|
|
|
|
{
|
|
|
|
FeatureItem *item = l->data;
|
|
|
|
gtk_widget_hide (item->feat);
|
|
|
|
gtk_widget_hide (gtk_widget_get_parent (item->feat));
|
|
|
|
}
|
|
|
|
|
|
|
|
pango_font = pango_context_load_font (gtk_widget_get_pango_context (GTK_WIDGET (fontchooser)),
|
|
|
|
priv->font_desc);
|
|
|
|
ft_face = pango_fc_font_lock_face (PANGO_FC_FONT (pango_font)),
|
|
|
|
hb_font = hb_ft_font_create (ft_face, NULL);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
hb_face = hb_font_get_face (hb_font);
|
|
|
|
|
|
|
|
update_language_combo (fontchooser, hb_face);
|
|
|
|
|
|
|
|
n_features = 0;
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
hb_ot_layout_table_find_script (hb_face, table[i], script_tag, &script_index);
|
|
|
|
hb_ot_layout_script_find_language (hb_face, table[i], script_index, lang_tag, &lang_index);
|
|
|
|
count = G_N_ELEMENTS (features);
|
|
|
|
hb_ot_layout_language_get_feature_tags (hb_face,
|
|
|
|
table[i],
|
|
|
|
script_index,
|
|
|
|
lang_index,
|
|
|
|
n_features,
|
|
|
|
&count,
|
|
|
|
features);
|
|
|
|
n_features += count;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < n_features; j++)
|
|
|
|
{
|
|
|
|
for (l = priv->feature_items; l; l = l->next)
|
|
|
|
{
|
|
|
|
FeatureItem *item = l->data;
|
|
|
|
if (item->tag != features[j])
|
|
|
|
continue;
|
|
|
|
|
2018-01-03 19:06:00 +00:00
|
|
|
has_feature = TRUE;
|
2018-01-03 04:46:37 +00:00
|
|
|
gtk_widget_show (item->feat);
|
|
|
|
gtk_widget_show (gtk_widget_get_parent (item->feat));
|
|
|
|
gtk_widget_show (priv->feature_language_combo);
|
|
|
|
|
|
|
|
if (GTK_IS_RADIO_BUTTON (item->feat))
|
|
|
|
{
|
|
|
|
GtkWidget *def = GTK_WIDGET (g_object_get_data (G_OBJECT (item->feat), "default"));
|
|
|
|
gtk_widget_show (def);
|
|
|
|
}
|
|
|
|
else if (GTK_IS_CHECK_BUTTON (item->feat))
|
|
|
|
{
|
|
|
|
set_inconsistent (GTK_CHECK_BUTTON (item->feat), TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-05 03:24:21 +00:00
|
|
|
hb_font_destroy (hb_font);
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pango_fc_font_unlock_face (PANGO_FC_FONT (pango_font));
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
GString *s;
|
|
|
|
GList *l;
|
|
|
|
|
2018-01-03 18:41:20 +00:00
|
|
|
s = g_string_new ("");
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
for (l = priv->feature_items; l; l = l->next)
|
|
|
|
{
|
|
|
|
FeatureItem *item = l->data;
|
|
|
|
|
|
|
|
if (!gtk_widget_is_sensitive (item->feat))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (GTK_IS_RADIO_BUTTON (item->feat))
|
|
|
|
{
|
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (item->feat)) &&
|
|
|
|
strcmp (item->name, "xxxx") != 0)
|
|
|
|
{
|
2018-01-04 02:21:58 +00:00
|
|
|
g_string_append_printf (s, "%s\"%s\" %d", s->len > 0 ? ", " : "", item->name, 1);
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (GTK_IS_CHECK_BUTTON (item->feat))
|
|
|
|
{
|
|
|
|
if (gtk_check_button_get_inconsistent (GTK_CHECK_BUTTON (item->feat)))
|
|
|
|
continue;
|
|
|
|
|
2018-01-04 02:21:58 +00:00
|
|
|
g_string_append_printf (s, "%s\"%s\" %d",
|
|
|
|
s->len > 0 ? ", " : "", item->name,
|
|
|
|
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (item->feat)));
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_strcmp0 (priv->font_features, s->str) != 0)
|
|
|
|
{
|
|
|
|
g_free (priv->font_features);
|
|
|
|
priv->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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_language (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->feature_language_combo), &iter))
|
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
PangoLanguage *lang;
|
|
|
|
hb_tag_t lang_tag;
|
|
|
|
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->feature_language_combo));
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
3, &lang_tag,
|
|
|
|
-1);
|
|
|
|
lang = pango_language_from_string (hb_language_to_string (hb_ot_tag_to_language (lang_tag)));
|
|
|
|
if (priv->font_language != lang)
|
|
|
|
{
|
|
|
|
priv->font_language = lang;
|
2018-01-03 04:52:24 +00:00
|
|
|
g_object_notify (G_OBJECT (fontchooser), "language");
|
2018-01-03 04:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_font_chooser_widget_update_preview_attributes (fontchooser);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
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,
|
|
|
|
const PangoFontDescription *font_desc,
|
|
|
|
GtkTreeIter *iter)
|
2011-09-11 23:49:26 +00:00
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
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);
|
|
|
|
|
|
|
|
/* sucky test, because we can't restrict the comparison to
|
|
|
|
* only the parts that actually do get merged */
|
|
|
|
if (pango_font_description_equal (font_desc, priv->font_desc))
|
2015-07-22 13:04:34 +00:00
|
|
|
return;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-19 23:17:29 +00:00
|
|
|
pango_font_description_merge (priv->font_desc, font_desc, TRUE);
|
|
|
|
|
|
|
|
if (mask & PANGO_FONT_MASK_SIZE)
|
|
|
|
{
|
|
|
|
double font_size = (double) pango_font_description_get_size (priv->font_desc) / PANGO_SCALE;
|
|
|
|
/* XXX: This clamps, which can cause it to reloop into here, do we need
|
|
|
|
* to block its signal handler? */
|
|
|
|
gtk_range_set_value (GTK_RANGE (priv->size_slider), font_size);
|
|
|
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->size_spin), font_size);
|
|
|
|
}
|
|
|
|
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-20 23:04:00 +00:00
|
|
|
if (&priv->font_iter != iter)
|
|
|
|
{
|
|
|
|
if (iter == NULL)
|
|
|
|
memset (&priv->font_iter, 0, sizeof (GtkTreeIter));
|
|
|
|
else
|
|
|
|
memcpy (&priv->font_iter, iter, sizeof (GtkTreeIter));
|
2018-01-03 19:06:00 +00:00
|
|
|
|
2011-09-20 23:04:00 +00:00
|
|
|
gtk_font_chooser_widget_ensure_selection (fontchooser);
|
|
|
|
}
|
2011-09-21 00:40:26 +00:00
|
|
|
|
|
|
|
gtk_font_chooser_widget_update_marks (fontchooser);
|
2018-01-03 04:46:37 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_HARFBUZZ) && defined(HAVE_PANGOFT)
|
2018-01-03 19:06:00 +00:00
|
|
|
has_tweak = gtk_font_chooser_widget_update_font_variations (fontchooser) ||
|
|
|
|
gtk_font_chooser_widget_update_font_features (fontchooser);
|
2018-01-03 04:46:37 +00:00
|
|
|
#endif
|
2018-01-03 19:06:00 +00:00
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (priv->tweak_action), has_tweak);
|
2011-09-20 23:04:00 +00:00
|
|
|
}
|
2011-09-19 23:17:29 +00:00
|
|
|
|
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
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
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);
|
|
|
|
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
|
|
|
{
|
2011-09-20 23:04:00 +00:00
|
|
|
GtkTreeIter iter;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2014-10-02 04:30:52 +00:00
|
|
|
if (gtk_font_chooser_widget_find_font (fontchooser, font_desc, &iter))
|
|
|
|
gtk_font_chooser_widget_merge_font_desc (fontchooser, font_desc, &iter);
|
2011-09-20 23:04:00 +00:00
|
|
|
else
|
2014-10-02 04:30:52 +00:00
|
|
|
gtk_font_chooser_widget_merge_font_desc (fontchooser, font_desc, NULL);
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
2011-09-20 00:54:42 +00:00
|
|
|
else
|
2011-09-11 22:13:26 +00:00
|
|
|
{
|
2014-10-02 04:30:52 +00:00
|
|
|
gtk_font_chooser_widget_merge_font_desc (fontchooser, font_desc, &priv->font_iter);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar*
|
|
|
|
gtk_font_chooser_widget_get_preview_text (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
2011-09-11 22:13:26 +00:00
|
|
|
return fontchooser->priv->preview_text;
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_set_preview_text (GtkFontChooserWidget *fontchooser,
|
|
|
|
const gchar *text)
|
|
|
|
{
|
2011-09-20 14:49:49 +00:00
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-20 14:49:49 +00:00
|
|
|
g_free (priv->preview_text);
|
|
|
|
priv->preview_text = g_strdup (text);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2011-09-20 14:49:49 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (priv->preview), text);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (fontchooser), "preview-text");
|
2011-09-20 14:49:49 +00:00
|
|
|
|
|
|
|
/* XXX: There's no API to tell the treeview that a column has changed,
|
|
|
|
* so we just */
|
|
|
|
gtk_widget_queue_draw (priv->family_face_list);
|
2011-09-11 23:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_font_chooser_widget_get_show_preview_entry (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
return fontchooser->priv->show_preview_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_set_show_preview_entry (GtkFontChooserWidget *fontchooser,
|
|
|
|
gboolean show_preview_entry)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
|
|
|
|
if (priv->show_preview_entry != show_preview_entry)
|
|
|
|
{
|
|
|
|
fontchooser->priv->show_preview_entry = show_preview_entry;
|
|
|
|
|
|
|
|
if (show_preview_entry)
|
|
|
|
gtk_widget_show (fontchooser->priv->preview);
|
|
|
|
else
|
|
|
|
gtk_widget_hide (fontchooser->priv->preview);
|
|
|
|
|
|
|
|
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
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
|
|
|
|
if (g_set_object (&priv->font_map, fontmap))
|
|
|
|
{
|
|
|
|
PangoContext *context;
|
|
|
|
|
|
|
|
if (!fontmap)
|
|
|
|
fontmap = pango_cairo_font_map_get_default ();
|
|
|
|
|
|
|
|
context = gtk_widget_get_pango_context (priv->family_face_list);
|
|
|
|
pango_context_set_font_map (context, fontmap);
|
|
|
|
|
2015-05-09 05:58:32 +00:00
|
|
|
context = gtk_widget_get_pango_context (priv->preview);
|
|
|
|
pango_context_set_font_map (context, fontmap);
|
|
|
|
|
2015-05-05 03:21:17 +00:00
|
|
|
gtk_font_chooser_widget_load_fonts (fontchooser, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
|
|
|
|
return priv->font_map;
|
|
|
|
}
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_widget_set_filter_func (GtkFontChooser *chooser,
|
|
|
|
GtkFontFilterFunc filter,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify destroy)
|
|
|
|
{
|
2011-09-20 22:19:51 +00:00
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
|
2011-09-11 23:49:26 +00:00
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
|
|
|
|
if (priv->filter_data_destroy)
|
|
|
|
priv->filter_data_destroy (priv->filter_data);
|
|
|
|
|
|
|
|
priv->filter_func = filter;
|
|
|
|
priv->filter_data = data;
|
|
|
|
priv->filter_data_destroy = destroy;
|
|
|
|
|
2011-09-21 03:49:43 +00:00
|
|
|
gtk_font_chooser_widget_refilter_font_list (fontchooser);
|
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)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
|
|
|
|
if (priv->level == level)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->level = level;
|
|
|
|
|
|
|
|
if (level == GTK_FONT_CHOOSER_LEVEL_FONT)
|
|
|
|
{
|
|
|
|
gtk_widget_show (priv->size_label);
|
|
|
|
gtk_widget_show (priv->size_slider);
|
|
|
|
gtk_widget_show (priv->size_spin);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_hide (priv->size_label);
|
|
|
|
gtk_widget_hide (priv->size_slider);
|
|
|
|
gtk_widget_hide (priv->size_spin);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_font_chooser_widget_load_fonts (fontchooser, TRUE);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (fontchooser), "level");
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkFontChooserLevel
|
|
|
|
gtk_font_chooser_widget_get_level (GtkFontChooserWidget *fontchooser)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
|
|
|
|
return priv->level;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
gboolean
|
|
|
|
gtk_font_chooser_widget_handle_event (GtkWidget *widget,
|
|
|
|
GdkEventKey *key_event)
|
|
|
|
{
|
|
|
|
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (widget);
|
|
|
|
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
|
|
|
|
GdkEvent *event = (GdkEvent *)key_event;
|
|
|
|
|
|
|
|
return gtk_search_entry_handle_event (GTK_SEARCH_ENTRY (priv->search_entry), event);
|
|
|
|
}
|
2018-01-03 03:52:05 +00:00
|
|
|
|
|
|
|
GAction *
|
|
|
|
gtk_font_chooser_widget_get_tweak_action (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
return GTK_FONT_CHOOSER_WIDGET (widget)->priv->tweak_action;
|
|
|
|
}
|
|
|
|
|