Use pango_layout_get_pixel_extents() to remove a large number of '/

Sun Jul  2 17:06:40 2000  Owen Taylor  <otaylor@redhat.com>

        * gtk/gtkcalendar.c gtk/gtkclist.c gtk/gtkctree.c gtk/gtkhscale.c
	gtk/gtkprogressbar.c gtk/gtkscale.c gtk/gtkvscale.c gtk/gtkaccellabel.c: Use
	pango_layout_get_pixel_extents() to remove a large number of '/ PANGO_SCALE'.

	* gtk/gtk[hv]ruler.c gtk/gtklabel.c: replace some / PANGO_SCALE with
	PANGO_PIXELS() macro.
This commit is contained in:
Owen Taylor 2000-07-02 21:32:56 +00:00 committed by Owen Taylor
parent b02ebc65e4
commit bf87b7c628
23 changed files with 368 additions and 130 deletions

View File

@ -1,3 +1,28 @@
Sun Jul 2 17:06:40 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcalendar.c gtk/gtkclist.c gtk/gtkctree.c gtk/gtkhscale.c
gtk/gtkprogressbar.c gtk/gtkscale.c gtk/gtkvscale.c gtk/gtkaccellabel.c: Use
pango_layout_get_pixel_extents() to remove a large number of '/ PANGO_SCALE'.
* gtk/gtk[hv]ruler.c gtk/gtklabel.c: replace some / PANGO_SCALE with
PANGO_PIXELS() macro.
Sun Jul 2 15:24:41 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.[ch] (gtk_widget_get_pango_context): Add new function
that returns a PangoContext owned by the widget and updated to
match future changes in the widget. Also, make
gtk_widget_create_pango_layout() use this context. If we ever
add a ::changed signal to PangoContext, this will make things
much more convenient.
* gtk/gtkentry.c gtk/gtklabel.c: Call pango_layout_context_changed()
in the appropriate places instead of destroying the layouts and
creating new ones.
* gtk/gtkfontsel.[ch] gtk/gtkclist.c: Use gtk_widget_get_pango_context()
in a few strategic places.
Sun Jul 2 14:37:58 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkoptionmenu.c (gtk_option_menu_size_request): Call

View File

@ -1,3 +1,28 @@
Sun Jul 2 17:06:40 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcalendar.c gtk/gtkclist.c gtk/gtkctree.c gtk/gtkhscale.c
gtk/gtkprogressbar.c gtk/gtkscale.c gtk/gtkvscale.c gtk/gtkaccellabel.c: Use
pango_layout_get_pixel_extents() to remove a large number of '/ PANGO_SCALE'.
* gtk/gtk[hv]ruler.c gtk/gtklabel.c: replace some / PANGO_SCALE with
PANGO_PIXELS() macro.
Sun Jul 2 15:24:41 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.[ch] (gtk_widget_get_pango_context): Add new function
that returns a PangoContext owned by the widget and updated to
match future changes in the widget. Also, make
gtk_widget_create_pango_layout() use this context. If we ever
add a ::changed signal to PangoContext, this will make things
much more convenient.
* gtk/gtkentry.c gtk/gtklabel.c: Call pango_layout_context_changed()
in the appropriate places instead of destroying the layouts and
creating new ones.
* gtk/gtkfontsel.[ch] gtk/gtkclist.c: Use gtk_widget_get_pango_context()
in a few strategic places.
Sun Jul 2 14:37:58 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkoptionmenu.c (gtk_option_menu_size_request): Call

View File

@ -1,3 +1,28 @@
Sun Jul 2 17:06:40 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcalendar.c gtk/gtkclist.c gtk/gtkctree.c gtk/gtkhscale.c
gtk/gtkprogressbar.c gtk/gtkscale.c gtk/gtkvscale.c gtk/gtkaccellabel.c: Use
pango_layout_get_pixel_extents() to remove a large number of '/ PANGO_SCALE'.
* gtk/gtk[hv]ruler.c gtk/gtklabel.c: replace some / PANGO_SCALE with
PANGO_PIXELS() macro.
Sun Jul 2 15:24:41 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.[ch] (gtk_widget_get_pango_context): Add new function
that returns a PangoContext owned by the widget and updated to
match future changes in the widget. Also, make
gtk_widget_create_pango_layout() use this context. If we ever
add a ::changed signal to PangoContext, this will make things
much more convenient.
* gtk/gtkentry.c gtk/gtklabel.c: Call pango_layout_context_changed()
in the appropriate places instead of destroying the layouts and
creating new ones.
* gtk/gtkfontsel.[ch] gtk/gtkclist.c: Use gtk_widget_get_pango_context()
in a few strategic places.
Sun Jul 2 14:37:58 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkoptionmenu.c (gtk_option_menu_size_request): Call

View File

@ -1,3 +1,28 @@
Sun Jul 2 17:06:40 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcalendar.c gtk/gtkclist.c gtk/gtkctree.c gtk/gtkhscale.c
gtk/gtkprogressbar.c gtk/gtkscale.c gtk/gtkvscale.c gtk/gtkaccellabel.c: Use
pango_layout_get_pixel_extents() to remove a large number of '/ PANGO_SCALE'.
* gtk/gtk[hv]ruler.c gtk/gtklabel.c: replace some / PANGO_SCALE with
PANGO_PIXELS() macro.
Sun Jul 2 15:24:41 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.[ch] (gtk_widget_get_pango_context): Add new function
that returns a PangoContext owned by the widget and updated to
match future changes in the widget. Also, make
gtk_widget_create_pango_layout() use this context. If we ever
add a ::changed signal to PangoContext, this will make things
much more convenient.
* gtk/gtkentry.c gtk/gtklabel.c: Call pango_layout_context_changed()
in the appropriate places instead of destroying the layouts and
creating new ones.
* gtk/gtkfontsel.[ch] gtk/gtkclist.c: Use gtk_widget_get_pango_context()
in a few strategic places.
Sun Jul 2 14:37:58 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkoptionmenu.c (gtk_option_menu_size_request): Call

View File

@ -1,3 +1,28 @@
Sun Jul 2 17:06:40 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcalendar.c gtk/gtkclist.c gtk/gtkctree.c gtk/gtkhscale.c
gtk/gtkprogressbar.c gtk/gtkscale.c gtk/gtkvscale.c gtk/gtkaccellabel.c: Use
pango_layout_get_pixel_extents() to remove a large number of '/ PANGO_SCALE'.
* gtk/gtk[hv]ruler.c gtk/gtklabel.c: replace some / PANGO_SCALE with
PANGO_PIXELS() macro.
Sun Jul 2 15:24:41 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.[ch] (gtk_widget_get_pango_context): Add new function
that returns a PangoContext owned by the widget and updated to
match future changes in the widget. Also, make
gtk_widget_create_pango_layout() use this context. If we ever
add a ::changed signal to PangoContext, this will make things
much more convenient.
* gtk/gtkentry.c gtk/gtklabel.c: Call pango_layout_context_changed()
in the appropriate places instead of destroying the layouts and
creating new ones.
* gtk/gtkfontsel.[ch] gtk/gtkclist.c: Use gtk_widget_get_pango_context()
in a few strategic places.
Sun Jul 2 14:37:58 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkoptionmenu.c (gtk_option_menu_size_request): Call

View File

@ -1,3 +1,28 @@
Sun Jul 2 17:06:40 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcalendar.c gtk/gtkclist.c gtk/gtkctree.c gtk/gtkhscale.c
gtk/gtkprogressbar.c gtk/gtkscale.c gtk/gtkvscale.c gtk/gtkaccellabel.c: Use
pango_layout_get_pixel_extents() to remove a large number of '/ PANGO_SCALE'.
* gtk/gtk[hv]ruler.c gtk/gtklabel.c: replace some / PANGO_SCALE with
PANGO_PIXELS() macro.
Sun Jul 2 15:24:41 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.[ch] (gtk_widget_get_pango_context): Add new function
that returns a PangoContext owned by the widget and updated to
match future changes in the widget. Also, make
gtk_widget_create_pango_layout() use this context. If we ever
add a ::changed signal to PangoContext, this will make things
much more convenient.
* gtk/gtkentry.c gtk/gtklabel.c: Call pango_layout_context_changed()
in the appropriate places instead of destroying the layouts and
creating new ones.
* gtk/gtkfontsel.[ch] gtk/gtkclist.c: Use gtk_widget_get_pango_context()
in a few strategic places.
Sun Jul 2 14:37:58 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkoptionmenu.c (gtk_option_menu_size_request): Call

View File

@ -1,3 +1,28 @@
Sun Jul 2 17:06:40 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcalendar.c gtk/gtkclist.c gtk/gtkctree.c gtk/gtkhscale.c
gtk/gtkprogressbar.c gtk/gtkscale.c gtk/gtkvscale.c gtk/gtkaccellabel.c: Use
pango_layout_get_pixel_extents() to remove a large number of '/ PANGO_SCALE'.
* gtk/gtk[hv]ruler.c gtk/gtklabel.c: replace some / PANGO_SCALE with
PANGO_PIXELS() macro.
Sun Jul 2 15:24:41 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.[ch] (gtk_widget_get_pango_context): Add new function
that returns a PangoContext owned by the widget and updated to
match future changes in the widget. Also, make
gtk_widget_create_pango_layout() use this context. If we ever
add a ::changed signal to PangoContext, this will make things
much more convenient.
* gtk/gtkentry.c gtk/gtklabel.c: Call pango_layout_context_changed()
in the appropriate places instead of destroying the layouts and
creating new ones.
* gtk/gtkfontsel.[ch] gtk/gtkclist.c: Use gtk_widget_get_pango_context()
in a few strategic places.
Sun Jul 2 14:37:58 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gtkoptionmenu.c (gtk_option_menu_size_request): Call

View File

@ -231,7 +231,7 @@ gtk_accel_label_size_request (GtkWidget *widget,
{
GtkAccelLabel *accel_label;
PangoLayout *layout;
PangoRectangle logical_rect;
gint width;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_ACCEL_LABEL (widget));
@ -244,9 +244,9 @@ gtk_accel_label_size_request (GtkWidget *widget,
layout = gtk_widget_create_pango_layout (widget);
pango_layout_set_text (layout, accel_label->accel_string, -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_size (layout, &width, NULL);
accel_label->accel_string_width = width;
accel_label->accel_string_width = logical_rect.width / PANGO_SCALE;
g_object_unref (G_OBJECT (layout));
}

View File

@ -1182,20 +1182,20 @@ gtk_calendar_size_request (GtkWidget *widget,
for (i = 0; i < 12; i++)
{
pango_layout_set_text (layout, default_monthname[i], -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
private_data->max_month_width = MAX (private_data->max_month_width,
logical_rect.width / PANGO_SCALE + 8);
max_header_height = MAX (max_header_height, logical_rect.height / PANGO_SCALE);
logical_rect.width + 8);
max_header_height = MAX (max_header_height, logical_rect.height);
}
private_data->max_year_width = 0;
for (i=0; i<10; i++)
{
sprintf (buffer, "%d%d%d%d", i,i,i,i);
pango_layout_set_text (layout, buffer, -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
private_data->max_year_width = MAX (private_data->max_year_width,
logical_rect.width / PANGO_SCALE + 8);
max_header_height = MAX (max_header_height, logical_rect.height / PANGO_SCALE);
logical_rect.width + 8);
max_header_height = MAX (max_header_height, logical_rect.height);
}
}
else
@ -1220,14 +1220,14 @@ gtk_calendar_size_request (GtkWidget *widget,
{
sprintf (buffer, "%d%d", i, i);
pango_layout_set_text (layout, buffer, -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
private_data->min_day_width = MAX (private_data->max_day_char_width,
logical_rect.width / PANGO_SCALE);
logical_rect.width);
private_data->max_day_char_ascent = MAX (private_data->max_label_char_ascent,
PANGO_ASCENT (logical_rect) / PANGO_SCALE);
PANGO_ASCENT (logical_rect));
private_data->max_day_char_descent = MAX (private_data->max_label_char_descent,
PANGO_DESCENT (logical_rect) / PANGO_SCALE);
PANGO_DESCENT (logical_rect));
}
/* We add one to max_day_char_width to be able to make the marked day "bold" */
private_data->max_day_char_width = private_data->min_day_width / 2 +1;
@ -1236,13 +1236,13 @@ gtk_calendar_size_request (GtkWidget *widget,
for (i = 0; i < 7; i++)
{
pango_layout_set_text (layout, default_abbreviated_dayname[i], -1);
pango_layout_line_get_extents (pango_layout_get_lines (layout)->data, NULL, &logical_rect);
pango_layout_line_get_pixel_extents (pango_layout_get_lines (layout)->data, NULL, &logical_rect);
private_data->min_day_width = MAX (private_data->min_day_width, logical_rect.width / PANGO_SCALE);
private_data->min_day_width = MAX (private_data->min_day_width, logical_rect.width);
private_data->max_label_char_ascent = MAX (private_data->max_label_char_ascent,
PANGO_ASCENT (logical_rect) / PANGO_SCALE);
PANGO_ASCENT (logical_rect));
private_data->max_label_char_descent = MAX (private_data->max_label_char_descent,
PANGO_DESCENT (logical_rect) / PANGO_SCALE);
PANGO_DESCENT (logical_rect));
}
private_data->max_week_char_width = 0;
@ -1251,9 +1251,9 @@ gtk_calendar_size_request (GtkWidget *widget,
{
sprintf (buffer, "%d%d", i, i);
pango_layout_set_text (layout, buffer, -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
private_data->max_week_char_width = MAX (private_data->max_week_char_width,
logical_rect.width / PANGO_SCALE / 2);
logical_rect.width / 2);
}
main_width = (7 * (private_data->min_day_width + DAY_XPAD * 2) + (DAY_XSEP * 6) + CALENDAR_MARGIN * 2
@ -1565,19 +1565,19 @@ gtk_calendar_paint_header (GtkWidget *widget)
sprintf (buffer, "%d", calendar->year);
pango_layout_set_text (layout, buffer, -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
/* Draw title */
y = (private_data->header_h - logical_rect.height / PANGO_SCALE) / 2;
y = (private_data->header_h - logical_rect.height) / 2;
/* Draw year and its arrows */
if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
x = header_width - (3 + max_year_width
- (max_year_width - logical_rect.width / PANGO_SCALE)/2);
- (max_year_width - logical_rect.width)/2);
else
x = header_width - (3 + private_data->arrow_width + max_year_width
- (max_year_width - logical_rect.width / PANGO_SCALE)/2);
- (max_year_width - logical_rect.width)/2);
gdk_gc_set_foreground (gc, HEADER_FG_COLOR (GTK_WIDGET (calendar)));
@ -1586,12 +1586,12 @@ gtk_calendar_paint_header (GtkWidget *widget)
/* Draw month */
sprintf (buffer, "%s", default_monthname[calendar->month]);
pango_layout_set_text (layout, buffer, -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
x = 3 + (max_month_width - logical_rect.width / PANGO_SCALE) / 2;
x = 3 + (max_month_width - logical_rect.width) / 2;
else
x = 3 + private_data->arrow_width + (max_month_width - logical_rect.width / PANGO_SCALE)/2;
x = 3 + private_data->arrow_width + (max_month_width - logical_rect.width)/2;
gdk_draw_layout (private_data->header_win, gc, x, y, layout);
@ -1679,14 +1679,14 @@ gtk_calendar_paint_day_names (GtkWidget *widget)
sprintf (buffer, "%s", default_abbreviated_dayname[day]);
pango_layout_set_text (layout, buffer, -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
gdk_draw_layout (private_data->day_name_win, gc,
((private_data->week_width ? CALENDAR_XSEP : CALENDAR_MARGIN)
+ day_wid_sep * i
+ private_data->week_width
+ (day_width - logical_rect.width / PANGO_SCALE)/2),
CALENDAR_MARGIN + DAY_YPAD + private_data->max_label_char_ascent + logical_rect.y / PANGO_SCALE,
+ (day_width - logical_rect.width)/2),
CALENDAR_MARGIN + DAY_YPAD + private_data->max_label_char_ascent + logical_rect.y,
layout);
}
@ -1768,12 +1768,12 @@ gtk_calendar_paint_week_numbers (GtkWidget *widget)
sprintf (buffer, "%d", week);
pango_layout_set_text (layout, buffer, -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
y_loc = top_y_for_row (calendar, row) + (day_height - logical_rect.height / PANGO_SCALE) / 2;
y_loc = top_y_for_row (calendar, row) + (day_height - logical_rect.height) / 2;
x_loc = (private_data->week_width
- logical_rect.width / PANGO_SCALE
- logical_rect.width
- CALENDAR_XSEP - DAY_XPAD);
gdk_draw_layout (private_data->week_win, gc, x_loc, y_loc, layout);
@ -1904,11 +1904,11 @@ gtk_calendar_paint_day (GtkWidget *widget,
sprintf (buffer, "%d", day);
pango_layout_set_text (layout, buffer, -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
x_loc -= logical_rect.width / PANGO_SCALE;
x_loc -= logical_rect.width;
y_loc = y_top + (day_height - logical_rect.height / PANGO_SCALE) / 2;
y_loc = y_top + (day_height - logical_rect.height) / 2;
gdk_draw_layout (private_data->main_win, gc,
x_loc, y_loc, layout);
if (calendar->marked_date[day-1]

View File

@ -2557,10 +2557,10 @@ cell_size_request (GtkCList *clist,
layout = _gtk_clist_create_cell_layout (clist, clist_row, column);
if (layout)
{
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
requisition->width = logical_rect.width / PANGO_SCALE;
requisition->height = logical_rect.height / PANGO_SCALE;
requisition->width = logical_rect.width;
requisition->height = logical_rect.height;
g_object_unref (G_OBJECT (layout));
}
@ -3019,7 +3019,7 @@ gtk_clist_set_row_height (GtkCList *clist,
if (widget->style->font_desc)
{
PangoContext *context = gtk_widget_create_pango_context (widget);
PangoContext *context = gtk_widget_get_pango_context (widget);
PangoFontMetrics metrics;
PangoFont *font = pango_context_load_font (context, widget->style->font_desc);
gchar *lang = pango_context_get_lang (context);
@ -3028,10 +3028,9 @@ gtk_clist_set_row_height (GtkCList *clist,
g_free (lang);
g_object_unref (G_OBJECT (font));
g_object_unref (G_OBJECT (context));
if (!GTK_CLIST_ROW_HEIGHT_SET(clist))
clist->row_height = (metrics.ascent + metrics.descent) / PANGO_SCALE;
clist->row_height = PANGO_PIXELS (metrics.ascent + metrics.descent);
}
CLIST_REFRESH (clist);
@ -5847,8 +5846,8 @@ draw_row (GtkCList *clist,
layout = _gtk_clist_create_cell_layout (clist, clist_row, i);
if (layout)
{
pango_layout_get_extents (layout, NULL, &logical_rect);
width = logical_rect.width / PANGO_SCALE;
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
width = logical_rect.width;
}
else
width = 0;
@ -5914,7 +5913,7 @@ draw_row (GtkCList *clist,
case GTK_CELL_TEXT:
if (layout)
{
gint row_center_offset = 1.5 + (clist->row_height - logical_rect.height / PANGO_SCALE - 1) / 2;
gint row_center_offset = 1.5 + (clist->row_height - logical_rect.height - 1) / 2;
gdk_gc_set_clip_rectangle (fg_gc, &clip_rectangle);
gdk_draw_layout (clist->clist_window, fg_gc,

View File

@ -1791,8 +1791,8 @@ draw_row (GtkCList *clist,
layout = _gtk_clist_create_cell_layout (clist, clist_row, i);
if (layout)
{
pango_layout_get_extents (layout, NULL, &logical_rect);
width = logical_rect.width / PANGO_SCALE;
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
width = logical_rect.width;
}
else
width = 0;
@ -1872,7 +1872,7 @@ draw_row (GtkCList *clist,
case GTK_CELL_TEXT:
if (layout)
{
gint row_center_offset = 1.5 + (clist->row_height - logical_rect.height / PANGO_SCALE - 1) / 2;
gint row_center_offset = 1.5 + (clist->row_height - logical_rect.height - 1) / 2;
gdk_gc_set_clip_rectangle (fg_gc, &clip_rectangle);
gdk_draw_layout (clist->clist_window, fg_gc,
@ -1935,7 +1935,7 @@ draw_row (GtkCList *clist,
if (layout)
{
gint row_center_offset = 1.5 + (clist->row_height - logical_rect.height / PANGO_SCALE - 1) / 2;
gint row_center_offset = 1.5 + (clist->row_height - logical_rect.height - 1) / 2;
if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
{
@ -2815,10 +2815,10 @@ cell_size_request (GtkCList *clist,
layout = _gtk_clist_create_cell_layout (clist, clist_row, column);
if (layout)
{
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
requisition->width = logical_rect.width / PANGO_SCALE;
requisition->height = logical_rect.height / PANGO_SCALE;
requisition->width = logical_rect.width;
requisition->height = logical_rect.height;
g_object_unref (G_OBJECT (layout));
}

View File

@ -1975,10 +1975,7 @@ gtk_entry_style_set (GtkWidget *widget,
}
if (entry->layout)
{
g_object_unref (G_OBJECT (entry->layout));
entry->layout = NULL;
}
pango_layout_context_changed (entry->layout);
}
static void
@ -1988,10 +1985,7 @@ gtk_entry_direction_changed (GtkWidget *widget,
GtkEntry *entry = GTK_ENTRY (widget);
if (entry->layout)
{
g_object_unref (G_OBJECT (entry->layout));
entry->layout = NULL;
}
pango_layout_context_changed (entry->layout);
GTK_WIDGET_CLASS (parent_class)->direction_changed (widget, previous_dir);
}

View File

@ -178,7 +178,6 @@ gtk_font_selection_init(GtkFontSelection *fontsel)
GtkWidget *text_box;
GtkWidget *table, *label;
fontsel->context = gtk_widget_create_pango_context (GTK_WIDGET (fontsel));
fontsel->font_desc = pango_font_description_from_string ("sans 12");
/* Create the table of font, style & size. */
@ -348,7 +347,6 @@ gtk_font_selection_finalize (GObject *object)
fontsel = GTK_FONT_SELECTION (object);
g_object_unref (G_OBJECT (fontsel->context));
pango_font_description_free (fontsel->font_desc);
if (fontsel->font)
@ -449,7 +447,8 @@ gtk_font_selection_show_available_fonts (GtkFontSelection *fontsel)
gchar **families;
int n_families, i;
pango_context_list_families (fontsel->context, &families, &n_families);
pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)),
&families, &n_families);
qsort (families, n_families, sizeof(char *), cmp_strings);
gtk_clist_freeze (GTK_CLIST (fontsel->font_clist));
@ -562,7 +561,8 @@ gtk_font_selection_show_available_styles (GtkFontSelection *fontsel)
gint match_row = 0;
gchar *str;
pango_context_list_fonts (fontsel->context, fontsel->font_desc->family_name, &descs, &n_descs);
pango_context_list_fonts (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)),
fontsel->font_desc->family_name, &descs, &n_descs);
qsort (descs, n_descs, sizeof(PangoFontDescription *), font_description_sort_func);
gtk_clist_freeze (GTK_CLIST (fontsel->font_style_clist));
@ -833,7 +833,8 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
/* Check to make sure that this is in the list of allowed fonts */
pango_context_list_fonts (fontsel->context, new_desc->family_name, &descs, &n_descs);
pango_context_list_fonts (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)),
new_desc->family_name, &descs, &n_descs);
for (i=0; i<n_descs; i++)
{

View File

@ -79,7 +79,6 @@ struct _GtkFontSelection
GtkWidget *filter_button;
GtkWidget *preview_entry;
PangoContext *context;
PangoFontDescription *font_desc;
GdkFont *font; /* Cache for gdk_font_selection_get_font, so we can preserve
* refcounting behavior

View File

@ -169,14 +169,14 @@ gtk_hruler_draw_ticks (GtkRuler *ruler)
xthickness = widget->style->xthickness;
ythickness = widget->style->ythickness;
digit_height = ink_rect.height / PANGO_SCALE + 2;
digit_height = PANGO_PIXELS (ink_rect.height) + 2;
digit_offset = ink_rect.y;
layout = gtk_widget_create_pango_layout (widget);
pango_layout_set_text (layout, "012456789", -1);
pango_layout_get_extents (layout, &ink_rect, &logical_rect);
digit_height = ink_rect.height / PANGO_SCALE + 1;
digit_height = PANGO_PIXELS (ink_rect.height) + 1;
digit_offset = ink_rect.y;
width = widget->allocation.width;
@ -263,7 +263,7 @@ gtk_hruler_draw_ticks (GtkRuler *ruler)
pango_layout_get_extents (layout, &logical_rect, NULL);
gdk_draw_layout (ruler->backing_store, gc,
pos + 2, ythickness + (logical_rect.y - digit_offset) / PANGO_SCALE,
pos + 2, ythickness + PANGO_PIXELS (logical_rect.y - digit_offset),
layout);
}
}

View File

@ -528,7 +528,7 @@ gtk_hscale_draw_value (GtkScale *scale)
layout = gtk_widget_create_pango_layout (widget);
pango_layout_set_text (layout, buffer, -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
switch (scale->value_pos)
{
@ -536,15 +536,15 @@ gtk_hscale_draw_value (GtkScale *scale)
gdk_window_get_position (GTK_RANGE (scale)->trough, &x, &y);
gdk_window_get_size (GTK_RANGE (scale)->trough, &width, &height);
x -= SCALE_CLASS (scale)->value_spacing + logical_rect.width / PANGO_SCALE;
y += (height - logical_rect.height / PANGO_SCALE) / 2;
x -= SCALE_CLASS (scale)->value_spacing + logical_rect.width;
y += (height - logical_rect.height) / 2;
break;
case GTK_POS_RIGHT:
gdk_window_get_position (GTK_RANGE (scale)->trough, &x, &y);
gdk_window_get_size (GTK_RANGE (scale)->trough, &width, &height);
x += width + SCALE_CLASS (scale)->value_spacing;
y += (height - logical_rect.height / PANGO_SCALE) / 2;
y += (height - logical_rect.height) / 2;
break;
case GTK_POS_TOP:
gdk_window_get_position (GTK_RANGE (scale)->slider, &x, NULL);
@ -552,10 +552,10 @@ gtk_hscale_draw_value (GtkScale *scale)
gdk_window_get_size (GTK_RANGE (scale)->slider, &width, NULL);
gdk_window_get_size (GTK_RANGE (scale)->trough, NULL, &height);
x += widget->allocation.x + (width - logical_rect.width / PANGO_SCALE) / 2;
x += widget->allocation.x + (width - logical_rect.width) / 2;
x = CLAMP (x, widget->allocation.x,
widget->allocation.x + widget->allocation.width - logical_rect.width / PANGO_SCALE);
y -= logical_rect.height / PANGO_SCALE;
widget->allocation.x + widget->allocation.width - logical_rect.width);
y -= logical_rect.height;
break;
case GTK_POS_BOTTOM:
gdk_window_get_position (GTK_RANGE (scale)->slider, &x, NULL);
@ -563,9 +563,9 @@ gtk_hscale_draw_value (GtkScale *scale)
gdk_window_get_size (GTK_RANGE (scale)->slider, &width, NULL);
gdk_window_get_size (GTK_RANGE (scale)->trough, NULL, &height);
x += widget->allocation.x + (width - logical_rect.width / PANGO_SCALE) / 2;
x += widget->allocation.x + (width - logical_rect.width) / 2;
x = CLAMP (x, widget->allocation.x,
widget->allocation.x + widget->allocation.width - logical_rect.width / PANGO_SCALE);
widget->allocation.x + widget->allocation.width - logical_rect.width);
y += height;
break;
}

View File

@ -443,7 +443,7 @@ gtk_label_size_request (GtkWidget *widget,
pango_layout_get_extents (label->layout, NULL, &logical_rect);
requisition->width += aux_info->width;
requisition->height += logical_rect.height / PANGO_SCALE;
requisition->height += PANGO_PIXELS (logical_rect.height);
}
else
{
@ -510,8 +510,8 @@ gtk_label_size_request (GtkWidget *widget,
}
pango_layout_set_width (label->layout, width);
requisition->width += real_width / PANGO_SCALE;
requisition->height += height / PANGO_SCALE;
requisition->width += PANGO_PIXELS (real_width);
requisition->height += PANGO_PIXELS (height);
}
}
else /* !label->wrap */
@ -519,8 +519,8 @@ gtk_label_size_request (GtkWidget *widget,
pango_layout_set_width (label->layout, -1);
pango_layout_get_extents (label->layout, NULL, &logical_rect);
requisition->width += logical_rect.width / PANGO_SCALE;
requisition->height += logical_rect.height / PANGO_SCALE;
requisition->width += PANGO_PIXELS (logical_rect.width);
requisition->height += PANGO_PIXELS (logical_rect.height);
}
}
@ -535,10 +535,7 @@ gtk_label_style_set (GtkWidget *widget,
label = GTK_LABEL (widget);
if (previous_style && label->layout)
{
g_object_unref (G_OBJECT (label->layout));
label->layout = NULL;
}
pango_layout_context_changed (label->layout);
}
static void
@ -548,10 +545,7 @@ gtk_label_direction_changed (GtkWidget *widget,
GtkLabel *label = GTK_LABEL (widget);
if (label->layout)
{
g_object_unref (G_OBJECT (label->layout));
label->layout = NULL;
}
pango_layout_context_changed (label->layout);
GTK_WIDGET_CLASS (parent_class)->direction_changed (widget, previous_dir);
}

View File

@ -365,7 +365,7 @@ gtk_progress_bar_size_request (GtkWidget *widget,
layout = gtk_widget_create_pango_layout (widget);
pango_layout_set_text (layout, buf, -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
g_object_unref (G_OBJECT (layout));
g_free (buf);
@ -378,11 +378,11 @@ gtk_progress_bar_size_request (GtkWidget *widget,
{
requisition->width = MAX (MIN_HORIZONTAL_BAR_WIDTH,
2 * widget->style->xthickness + 3 +
logical_rect.width / PANGO_SCALE + 2 * TEXT_SPACING);
logical_rect.width + 2 * TEXT_SPACING);
requisition->height = MAX (MIN_HORIZONTAL_BAR_HEIGHT,
2 * widget->style->ythickness + 3 +
logical_rect.height / PANGO_SCALE + 2 * TEXT_SPACING);
logical_rect.height + 2 * TEXT_SPACING);
}
else
{
@ -396,11 +396,11 @@ gtk_progress_bar_size_request (GtkWidget *widget,
{
requisition->width = MAX (MIN_VERTICAL_BAR_WIDTH,
2 * widget->style->xthickness + 3 +
logical_rect.width / PANGO_SCALE + 2 * TEXT_SPACING);
logical_rect.width + 2 * TEXT_SPACING);
requisition->height = MAX (MIN_VERTICAL_BAR_HEIGHT,
2 * widget->style->ythickness + 3 +
logical_rect.height / PANGO_SCALE + 2 * TEXT_SPACING);
logical_rect.height + 2 * TEXT_SPACING);
}
else
{
@ -712,16 +712,16 @@ gtk_progress_bar_paint (GtkProgress *progress)
layout = gtk_widget_create_pango_layout (widget);
pango_layout_set_text (layout, buf, -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
x = widget->style->xthickness + 1 +
(widget->allocation.width - 2 * widget->style->xthickness -
3 - logical_rect.width / PANGO_SCALE)
3 - logical_rect.width)
* progress->x_align;
y = widget->style->ythickness + 1 +
(widget->allocation.height - 2 * widget->style->ythickness -
3 - logical_rect.height / PANGO_SCALE)
3 - logical_rect.height)
* progress->y_align;
rect.x = widget->style->xthickness + 1;

View File

@ -300,12 +300,12 @@ gtk_scale_get_value_size (GtkScale *scale,
buffer[i] = '\0';
pango_layout_set_text (layout, buffer, i);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
if (width)
*width = logical_rect.width / PANGO_SCALE;
*width = logical_rect.width;
if (height)
*height = logical_rect.width / PANGO_SCALE;
*height = logical_rect.width;
value = ABS (range->adjustment->upper);
if (value == 0) value = 1;
@ -325,12 +325,12 @@ gtk_scale_get_value_size (GtkScale *scale,
buffer[i] = '\0';
pango_layout_set_text (layout, buffer, i);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
if (width)
*width = MAX (*width, logical_rect.width / PANGO_SCALE);
*width = MAX (*width, logical_rect.width);
if (height)
*height = MAX (*height, logical_rect.height / PANGO_SCALE);
*height = MAX (*height, logical_rect.height);
g_object_unref (G_OBJECT (layout));
}

View File

@ -171,7 +171,7 @@ gtk_vruler_draw_ticks (GtkRuler *ruler)
pango_layout_set_text (layout, "012456789", -1);
pango_layout_get_extents (layout, &ink_rect, &logical_rect);
digit_height = ink_rect.height / PANGO_SCALE + 2;
digit_height = PANGO_PIXELS (ink_rect.height) + 2;
digit_offset = ink_rect.y;
width = widget->allocation.height;
@ -260,7 +260,7 @@ gtk_vruler_draw_ticks (GtkRuler *ruler)
gdk_draw_layout (ruler->backing_store, gc,
xthickness + 1,
pos + digit_height * j + 2 + (logical_rect.y - digit_offset) / PANGO_SCALE,
pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset),
layout);
}
}

View File

@ -532,7 +532,7 @@ gtk_vscale_draw_value (GtkScale *scale)
layout = gtk_widget_create_pango_layout (widget);
pango_layout_set_text (layout, buffer, strlen (buffer));
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
switch (scale->value_pos)
{
@ -542,9 +542,9 @@ gtk_vscale_draw_value (GtkScale *scale)
gdk_window_get_size (GTK_RANGE (scale)->trough, &width, NULL);
gdk_window_get_size (GTK_RANGE (scale)->slider, NULL, &height);
x -= SCALE_CLASS (scale)->value_spacing + logical_rect.width / PANGO_SCALE;
y += widget->allocation.y + (height - logical_rect.height / PANGO_SCALE) / 2 +
PANGO_ASCENT (logical_rect) / PANGO_SCALE;
x -= SCALE_CLASS (scale)->value_spacing + logical_rect.width;
y += widget->allocation.y + (height - logical_rect.height) / 2 +
PANGO_ASCENT (logical_rect);
break;
case GTK_POS_RIGHT:
gdk_window_get_position (GTK_RANGE (scale)->trough, &x, NULL);
@ -553,24 +553,24 @@ gtk_vscale_draw_value (GtkScale *scale)
gdk_window_get_size (GTK_RANGE (scale)->slider, NULL, &height);
x += width + SCALE_CLASS (scale)->value_spacing;
y += widget->allocation.y + (height - logical_rect.height / PANGO_SCALE) / 2 +
PANGO_ASCENT (logical_rect) / PANGO_SCALE;
y += widget->allocation.y + (height - logical_rect.height) / 2 +
PANGO_ASCENT (logical_rect);
break;
case GTK_POS_TOP:
gdk_window_get_position (GTK_RANGE (scale)->trough, &x, &y);
gdk_window_get_size (GTK_RANGE (scale)->slider, &width, NULL);
gdk_window_get_size (GTK_RANGE (scale)->trough, NULL, &height);
x += (width - logical_rect.width / PANGO_SCALE) / 2;
y -= PANGO_DESCENT (logical_rect) / PANGO_SCALE;
x += (width - logical_rect.width) / 2;
y -= PANGO_DESCENT (logical_rect);
break;
case GTK_POS_BOTTOM:
gdk_window_get_position (GTK_RANGE (scale)->trough, &x, &y);
gdk_window_get_size (GTK_RANGE (scale)->slider, &width, NULL);
gdk_window_get_size (GTK_RANGE (scale)->trough, NULL, &height);
x += (width - logical_rect.width / PANGO_SCALE) / 2;
y += height + PANGO_ASCENT (logical_rect) / PANGO_SCALE;
x += (width - logical_rect.width) / 2;
y += height + PANGO_ASCENT (logical_rect);
break;
}

View File

@ -168,8 +168,9 @@ static void gtk_widget_direction_changed (GtkWidget *widget,
GtkTextDirection previous_direction);
static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
static GdkColormap* gtk_widget_peek_colormap (void);
static GtkStyle* gtk_widget_peek_style (void);
static GdkColormap* gtk_widget_peek_colormap (void);
static GtkStyle* gtk_widget_peek_style (void);
static PangoContext *gtk_widget_peek_pango_context (GtkWidget *widget);
static void gtk_widget_reparent_container_child (GtkWidget *widget,
gpointer client_data);
@ -208,6 +209,8 @@ static const gchar *saved_default_style_key = "gtk-saved-default-style";
static guint saved_default_style_key_id = 0;
static const gchar *shape_info_key = "gtk-shape-info";
static const gchar *colormap_key = "gtk-colormap";
static const gchar *pango_context_key = "gtk-pango-context";
static guint pango_context_key_id = 0;
static const gchar *rc_style_key = "gtk-rc-style";
static guint rc_style_key_id = 0;
@ -3052,6 +3055,13 @@ gtk_widget_modify_style (GtkWidget *widget,
gtk_widget_set_rc_style (widget);
}
static void
gtk_widget_direction_changed (GtkWidget *widget,
GtkTextDirection previous_direction)
{
gtk_widget_queue_resize (widget);
}
static void
gtk_widget_style_set (GtkWidget *widget,
GtkStyle *previous_style)
@ -3061,13 +3071,6 @@ gtk_widget_style_set (GtkWidget *widget,
gtk_style_set_background (widget->style, widget->window, widget->state);
}
static void
gtk_widget_direction_changed (GtkWidget *widget,
GtkTextDirection previous_direction)
{
gtk_widget_queue_resize (widget);
}
static void
gtk_widget_set_style_internal (GtkWidget *widget,
GtkStyle *style,
@ -3076,6 +3079,13 @@ gtk_widget_set_style_internal (GtkWidget *widget,
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (style != NULL);
if (widget->style != style || initial_emission)
{
PangoContext *context = gtk_widget_peek_pango_context (widget);
if (context)
pango_context_set_font_description (context, widget->style->font_desc);
}
if (widget->style != style)
{
@ -3200,13 +3210,60 @@ gtk_widget_pop_style (void)
}
}
static PangoContext *
gtk_widget_peek_pango_context (GtkWidget *widget)
{
if (!pango_context_key_id)
pango_context_key_id = g_quark_from_static_string (pango_context_key);
return gtk_object_get_data_by_id (GTK_OBJECT (widget), pango_context_key_id);
}
/**
* gtk_widget_get_pango_context:
* @widget: a #GtkWidget
*
* Get a #PangoContext with the appropriate colormap, font description
* and base direction for this widget. Unlike the context returned
* by gtk_widget_create_pango_context(), this context is owned by
* the widget (it can be used as long as widget exists), and will
* be updated to match any changes to the widget's attributes.
*
* If you create and keep a #PangoLayout using this context, you must
* deal with changes to the context by calling pango_layout_context_changed()
* on the layout in response to the ::style_set and ::direction_set signals
* for the widget.
*
* Return value: the #PangoContext for the widget.
**/
PangoContext *
gtk_widget_get_pango_context (GtkWidget *widget)
{
PangoContext *context;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
if (!pango_context_key_id)
pango_context_key_id = g_quark_from_static_string (pango_context_key);
context = gtk_object_get_data_by_id (GTK_OBJECT (widget), pango_context_key_id);
if (!context)
{
context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
gtk_object_set_data_by_id_full (GTK_OBJECT (widget), pango_context_key_id, context,
(GDestroyNotify)g_object_unref);
}
return context;
}
/**
* gtk_widget_create_pango_context:
* @widget: a #PangoWidget
*
* Create a new pango context with the appropriate colormap,
* font description, and base direction for drawing text for
* this widget.
* this widget. See also gtk_widget_get_pango_context()
*
* Return value: the new #PangoContext
**/
@ -3240,6 +3297,11 @@ gtk_widget_create_pango_context (GtkWidget *widget)
* Create a new #PangoLayout with the appropriate colormap,
* font description, and base direction for drawing text for
* this widget.
*
* If you keep a #PangoLayout created in this way around, in order
* notify the layout of changes to the base direction or font of this
* widget, you must call pango_layout_context_changed() in response to
* the ::style_set and ::direction_set signals for the widget.
*
* Return value: the new #PangoLayout
**/
@ -3251,9 +3313,8 @@ gtk_widget_create_pango_layout (GtkWidget *widget)
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
context = gtk_widget_create_pango_context (widget);
context = gtk_widget_get_pango_context (widget);
layout = pango_layout_new (context);
g_object_unref (G_OBJECT (context));
return layout;
}
@ -3870,6 +3931,20 @@ gtk_widget_get_default_visual (void)
return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
}
static void
gtk_widget_emit_direction_changed (GtkWidget *widget,
GtkTextDirection old_dir)
{
PangoContext *context = gtk_widget_peek_pango_context (widget);
if (context)
pango_context_set_base_dir (context,
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
gtk_signal_emit (GTK_OBJECT (widget), widget_signals[DIRECTION_CHANGED], old_dir);
}
/**
* gtk_widget_set_direction:
* @widget: a #GtkWidget
@ -3912,7 +3987,7 @@ gtk_widget_set_direction (GtkWidget *widget,
}
if (old_dir != gtk_widget_get_direction (widget))
gtk_signal_emit (GTK_OBJECT (widget), widget_signals[DIRECTION_CHANGED], old_dir);
gtk_widget_emit_direction_changed (widget, old_dir);
}
/**
@ -3944,7 +4019,7 @@ gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
g_object_ref (G_OBJECT (widget));
if (!GTK_WIDGET_DIRECTION_SET (widget))
gtk_signal_emit (GTK_OBJECT (widget), widget_signals[DIRECTION_CHANGED], old_dir);
gtk_widget_emit_direction_changed (widget, old_dir);
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget),

View File

@ -576,6 +576,7 @@ void gtk_widget_modify_style (GtkWidget *widget,
GtkRcStyle *style);
PangoContext *gtk_widget_create_pango_context (GtkWidget *widget);
PangoContext *gtk_widget_get_pango_context (GtkWidget *widget);
PangoLayout *gtk_widget_create_pango_layout (GtkWidget *widget);
/* handle composite names for GTK_COMPOSITE_CHILD widgets,