forked from AuroraMiddleware/gtk
gtk: Use context's font
Instead of using gtk_style_context_get_font() in pango_context_get_metrics(), use pango_context_get_font_description(). The context contains the font description we are about to use after all.
This commit is contained in:
parent
a405c9917c
commit
7747910b9d
@ -2128,8 +2128,6 @@ gtk_cell_renderer_text_get_preferred_width (GtkCellRenderer *cell,
|
||||
{
|
||||
GtkCellRendererTextPrivate *priv;
|
||||
GtkCellRendererText *celltext;
|
||||
GtkStyleContext *style_context;
|
||||
const PangoFontDescription *font_desc;
|
||||
PangoLayout *layout;
|
||||
PangoContext *context;
|
||||
PangoFontMetrics *metrics;
|
||||
@ -2149,8 +2147,6 @@ gtk_cell_renderer_text_get_preferred_width (GtkCellRenderer *cell,
|
||||
celltext = GTK_CELL_RENDERER_TEXT (cell);
|
||||
priv = celltext->priv;
|
||||
|
||||
style_context = gtk_widget_get_style_context (widget);
|
||||
|
||||
gtk_cell_renderer_get_padding (cell, &xpad, NULL);
|
||||
|
||||
layout = get_layout (celltext, widget, NULL, 0);
|
||||
@ -2162,8 +2158,8 @@ gtk_cell_renderer_text_get_preferred_width (GtkCellRenderer *cell,
|
||||
|
||||
/* Fetch the average size of a charachter */
|
||||
context = pango_layout_get_context (layout);
|
||||
font_desc = gtk_style_context_get_font (style_context, 0);
|
||||
metrics = pango_context_get_metrics (context, font_desc,
|
||||
metrics = pango_context_get_metrics (context,
|
||||
pango_context_get_font_description (context),
|
||||
pango_context_get_language (context));
|
||||
|
||||
char_width = pango_font_metrics_get_approximate_char_width (metrics);
|
||||
|
@ -5446,12 +5446,9 @@ gtk_combo_box_get_preferred_width (GtkWidget *widget,
|
||||
gint font_size, arrow_size;
|
||||
PangoContext *context;
|
||||
PangoFontMetrics *metrics;
|
||||
const PangoFontDescription *font_desc;
|
||||
GtkWidget *child;
|
||||
gint minimum_width = 0, natural_width = 0;
|
||||
gint child_min, child_nat;
|
||||
GtkStyleContext *style_context;
|
||||
GtkStateFlags state;
|
||||
GtkBorder padding;
|
||||
gfloat arrow_scaling;
|
||||
|
||||
@ -5465,14 +5462,11 @@ gtk_combo_box_get_preferred_width (GtkWidget *widget,
|
||||
"arrow-scaling", &arrow_scaling,
|
||||
NULL);
|
||||
|
||||
style_context = gtk_widget_get_style_context (widget);
|
||||
state = gtk_widget_get_state_flags (widget);
|
||||
|
||||
get_widget_padding_and_border (widget, &padding);
|
||||
font_desc = gtk_style_context_get_font (style_context, state);
|
||||
|
||||
context = gtk_widget_get_pango_context (GTK_WIDGET (widget));
|
||||
metrics = pango_context_get_metrics (context, font_desc,
|
||||
metrics = pango_context_get_metrics (context,
|
||||
pango_context_get_font_description (context),
|
||||
pango_context_get_language (context));
|
||||
font_size = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
|
||||
pango_font_metrics_get_descent (metrics));
|
||||
|
@ -3216,19 +3216,14 @@ gtk_entry_get_preferred_width (GtkWidget *widget,
|
||||
PangoFontMetrics *metrics;
|
||||
GtkBorder borders;
|
||||
PangoContext *context;
|
||||
GtkStyleContext *style_context;
|
||||
GtkStateFlags state;
|
||||
gint icon_widths = 0;
|
||||
gint icon_width, i;
|
||||
gint width;
|
||||
|
||||
context = gtk_widget_get_pango_context (widget);
|
||||
|
||||
style_context = gtk_widget_get_style_context (widget);
|
||||
state = gtk_widget_get_state_flags (widget);
|
||||
|
||||
metrics = pango_context_get_metrics (context,
|
||||
gtk_style_context_get_font (style_context, state),
|
||||
pango_context_get_font_description (context),
|
||||
pango_context_get_language (context));
|
||||
|
||||
_gtk_entry_get_borders (entry, &borders);
|
||||
@ -3269,8 +3264,6 @@ gtk_entry_get_preferred_height (GtkWidget *widget,
|
||||
GtkEntryPrivate *priv = entry->priv;
|
||||
PangoFontMetrics *metrics;
|
||||
GtkBorder borders;
|
||||
GtkStyleContext *style_context;
|
||||
GtkStateFlags state;
|
||||
PangoContext *context;
|
||||
gint height;
|
||||
PangoLayout *layout;
|
||||
@ -3278,11 +3271,8 @@ gtk_entry_get_preferred_height (GtkWidget *widget,
|
||||
layout = gtk_entry_ensure_layout (entry, TRUE);
|
||||
context = gtk_widget_get_pango_context (widget);
|
||||
|
||||
style_context = gtk_widget_get_style_context (widget);
|
||||
state = gtk_widget_get_state_flags (widget);
|
||||
|
||||
metrics = pango_context_get_metrics (context,
|
||||
gtk_style_context_get_font (style_context, state),
|
||||
pango_context_get_font_description (context),
|
||||
pango_context_get_language (context));
|
||||
|
||||
priv->ascent = pango_font_metrics_get_ascent (metrics);
|
||||
@ -6574,8 +6564,6 @@ gtk_entry_move_adjustments (GtkEntry *entry)
|
||||
GtkAdjustment *adjustment;
|
||||
PangoContext *context;
|
||||
PangoFontMetrics *metrics;
|
||||
GtkStyleContext *style_context;
|
||||
GtkStateFlags state;
|
||||
GtkBorder borders;
|
||||
gint x, layout_x;
|
||||
gint char_width;
|
||||
@ -6594,11 +6582,9 @@ gtk_entry_move_adjustments (GtkEntry *entry)
|
||||
|
||||
/* Approximate width of a char, so user can see what is ahead/behind */
|
||||
context = gtk_widget_get_pango_context (widget);
|
||||
style_context = gtk_widget_get_style_context (widget);
|
||||
state = gtk_widget_get_state_flags (widget);
|
||||
|
||||
metrics = pango_context_get_metrics (context,
|
||||
gtk_style_context_get_font (style_context, state),
|
||||
pango_context_get_font_description (context),
|
||||
pango_context_get_language (context));
|
||||
char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
|
||||
|
||||
|
@ -3136,23 +3136,6 @@ gtk_label_clear_layout (GtkLabel *label)
|
||||
}
|
||||
}
|
||||
|
||||
static PangoFontMetrics *
|
||||
get_font_metrics (PangoContext *context, GtkWidget *widget)
|
||||
{
|
||||
GtkStyleContext *style_context;
|
||||
const PangoFontDescription *font;
|
||||
PangoFontMetrics *retval;
|
||||
|
||||
style_context = gtk_widget_get_style_context (widget);
|
||||
font = gtk_style_context_get_font (style_context, GTK_STATE_FLAG_NORMAL);
|
||||
|
||||
retval = pango_context_get_metrics (context,
|
||||
font,
|
||||
pango_context_get_language (context));
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_label_get_measuring_layout:
|
||||
* @label: the label
|
||||
@ -3485,7 +3468,9 @@ get_char_pixels (GtkWidget *label,
|
||||
gint char_width, digit_width;
|
||||
|
||||
context = pango_layout_get_context (layout);
|
||||
metrics = get_font_metrics (context, GTK_WIDGET (label));
|
||||
metrics = pango_context_get_metrics (context,
|
||||
pango_context_get_font_description (context),
|
||||
pango_context_get_language (context));
|
||||
char_width = pango_font_metrics_get_approximate_char_width (metrics);
|
||||
digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
|
||||
pango_font_metrics_unref (metrics);
|
||||
|
@ -758,8 +758,6 @@ get_arrow_size (GtkWidget *widget,
|
||||
gint *size,
|
||||
gint *spacing)
|
||||
{
|
||||
GtkStyleContext *style_context;
|
||||
GtkStateFlags state;
|
||||
PangoContext *context;
|
||||
PangoFontMetrics *metrics;
|
||||
gfloat arrow_scaling;
|
||||
@ -776,11 +774,9 @@ get_arrow_size (GtkWidget *widget,
|
||||
*spacing = arrow_spacing;
|
||||
|
||||
context = gtk_widget_get_pango_context (child);
|
||||
style_context = gtk_widget_get_style_context (child);
|
||||
state = gtk_widget_get_state_flags (child);
|
||||
|
||||
metrics = pango_context_get_metrics (context,
|
||||
gtk_style_context_get_font (style_context, state),
|
||||
pango_context_get_font_description (context),
|
||||
pango_context_get_language (context));
|
||||
|
||||
*size = (PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
|
||||
@ -814,19 +810,15 @@ gtk_menu_item_accel_width_foreach (GtkWidget *widget,
|
||||
static gint
|
||||
get_minimum_width (GtkWidget *widget)
|
||||
{
|
||||
GtkStyleContext *style_context;
|
||||
GtkStateFlags state;
|
||||
PangoContext *context;
|
||||
PangoFontMetrics *metrics;
|
||||
gint width;
|
||||
gint width_chars;
|
||||
|
||||
context = gtk_widget_get_pango_context (widget);
|
||||
style_context = gtk_widget_get_style_context (widget);
|
||||
state = gtk_widget_get_state_flags (widget);
|
||||
|
||||
metrics = pango_context_get_metrics (context,
|
||||
gtk_style_context_get_font (style_context, state),
|
||||
pango_context_get_font_description (context),
|
||||
pango_context_get_language (context));
|
||||
|
||||
width = pango_font_metrics_get_approximate_char_width (metrics);
|
||||
|
@ -556,15 +556,15 @@ gtk_progress_bar_get_preferred_width (GtkWidget *widget,
|
||||
|
||||
if (priv->ellipsize)
|
||||
{
|
||||
const PangoFontDescription *font_desc;
|
||||
PangoContext *context;
|
||||
PangoFontMetrics *metrics;
|
||||
gint char_width;
|
||||
|
||||
/* The minimum size for ellipsized text is ~ 3 chars */
|
||||
context = pango_layout_get_context (layout);
|
||||
font_desc = gtk_style_context_get_font (style_context, state);
|
||||
metrics = pango_context_get_metrics (context, font_desc, pango_context_get_language (context));
|
||||
metrics = pango_context_get_metrics (context,
|
||||
pango_context_get_font_description (context),
|
||||
pango_context_get_language (context));
|
||||
|
||||
char_width = pango_font_metrics_get_approximate_char_width (metrics);
|
||||
pango_font_metrics_unref (metrics);
|
||||
|
@ -3336,18 +3336,12 @@ calculate_max_homogeneous_pixels (GtkWidget *widget)
|
||||
{
|
||||
PangoContext *context;
|
||||
PangoFontMetrics *metrics;
|
||||
const PangoFontDescription *font_desc;
|
||||
GtkStyleContext *style_context;
|
||||
GtkStateFlags state;
|
||||
gint char_width;
|
||||
|
||||
context = gtk_widget_get_pango_context (widget);
|
||||
style_context = gtk_widget_get_style_context (widget);
|
||||
state = gtk_widget_get_state_flags (widget);
|
||||
|
||||
font_desc = gtk_style_context_get_font (style_context, state);
|
||||
|
||||
metrics = pango_context_get_metrics (context, font_desc,
|
||||
metrics = pango_context_get_metrics (context,
|
||||
pango_context_get_font_description (context),
|
||||
pango_context_get_language (context));
|
||||
char_width = pango_font_metrics_get_approximate_char_width (metrics);
|
||||
pango_font_metrics_unref (metrics);
|
||||
|
Loading…
Reference in New Issue
Block a user