aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/e-day-view-time-item.c
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/gui/e-day-view-time-item.c')
-rw-r--r--calendar/gui/e-day-view-time-item.c71
1 files changed, 52 insertions, 19 deletions
diff --git a/calendar/gui/e-day-view-time-item.c b/calendar/gui/e-day-view-time-item.c
index 276c6062e4..b6e902e318 100644
--- a/calendar/gui/e-day-view-time-item.c
+++ b/calendar/gui/e-day-view-time-item.c
@@ -180,10 +180,12 @@ e_day_view_time_item_get_column_width (EDayViewTimeItem *dvtmitem)
{
EDayView *day_view;
GtkStyle *style;
- GdkFont *small_font, *large_font;
+ GdkFont *small_font;
+ PangoFontMetrics *large_font_metrics;
gint digit, large_digit_width, max_large_digit_width = 0;
gint max_suffix_width, max_minute_or_suffix_width;
gint column_width_default, column_width_60_min_rows;
+ PangoContext *context;
day_view = dvtmitem->day_view;
g_return_val_if_fail (day_view != NULL, 0);
@@ -192,11 +194,24 @@ e_day_view_time_item_get_column_width (EDayViewTimeItem *dvtmitem)
g_return_val_if_fail (style != NULL, 0);
small_font = gtk_style_get_font (style);
g_return_val_if_fail (small_font != NULL, 0);
- large_font = day_view->large_font;
- g_return_val_if_fail (large_font != NULL, 0);
+ context = gtk_widget_get_pango_context (GTK_WIDGET (day_view));
+
+ /* Find the maximum width a digit can have. FIXME: We could use pango's
+ * approximation function, but I worry it won't be precise enough. Also
+ * it needs a language tag that I don't know where to get. */
for (digit = '0'; digit <= '9'; digit++) {
- large_digit_width = gdk_char_width (large_font, digit);
+ PangoLayout *layout;
+ gchar digit_str [2];
+
+ digit_str [0] = digit;
+ digit_str [1] = '\0';
+
+ layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), digit_str);
+ pango_layout_set_font_description (layout, day_view->large_font_desc);
+ pango_layout_get_pixel_size (layout, &large_digit_width, NULL);
+ g_object_unref (layout);
+
max_large_digit_width = MAX (max_large_digit_width,
large_digit_width);
}
@@ -245,7 +260,7 @@ e_day_view_time_item_draw (GnomeCanvasItem *canvas_item,
EDayView *day_view;
EDayViewTimeItem *dvtmitem;
GtkStyle *style;
- GdkFont *small_font, *large_font;
+ GdkFont *small_font;
GdkGC *fg_gc, *dark_gc;
gchar buffer[64], *suffix;
gint hour, display_hour, minute, row;
@@ -254,6 +269,10 @@ e_day_view_time_item_draw (GnomeCanvasItem *canvas_item,
gint large_hour_x2, minute_x2;
gint hour_width, minute_width, suffix_width;
gint max_suffix_width, max_minute_or_suffix_width;
+ PangoLayout *layout;
+ PangoContext *context;
+ PangoFontDescription *small_font_desc;
+ PangoFontMetrics *large_font_metrics;
dvtmitem = E_DAY_VIEW_TIME_ITEM (canvas_item);
day_view = dvtmitem->day_view;
@@ -261,7 +280,11 @@ e_day_view_time_item_draw (GnomeCanvasItem *canvas_item,
style = gtk_widget_get_style (GTK_WIDGET (day_view));
small_font = gtk_style_get_font (style);
- large_font = day_view->large_font;
+ small_font_desc = style->font_desc;
+
+ context = gtk_widget_get_pango_context (GTK_WIDGET (day_view));
+ large_font_metrics = pango_context_get_metrics (context, day_view->large_font_desc, NULL);
+
fg_gc = style->fg_gc[GTK_STATE_NORMAL];
dark_gc = style->dark_gc[GTK_STATE_NORMAL];
@@ -302,16 +325,18 @@ e_day_view_time_item_draw (GnomeCanvasItem *canvas_item,
minute = day_view->first_minute_shown;
/* The offset of the large hour string from the top of the row. */
- large_hour_y_offset = large_font->ascent + E_DVTMI_LARGE_HOUR_Y_PAD;
+ large_hour_y_offset = E_DVTMI_LARGE_HOUR_Y_PAD;
/* The offset of the small time/minute string from top of row. */
- small_font_y_offset = small_font->ascent + E_DVTMI_SMALL_FONT_Y_PAD;
+ small_font_y_offset = E_DVTMI_SMALL_FONT_Y_PAD;
/* Calculate the minimum y position of the first row we need to draw.
This is normally one row height above the 0 position, but if we
are using the large font we may have to go back a bit further. */
start_y = 0 - MAX (day_view->row_height,
- large_hour_y_offset + large_font->descent);
+ (pango_font_metrics_get_ascent (large_font_metrics) +
+ pango_font_metrics_get_descent (large_font_metrics)) / PANGO_SCALE +
+ E_DVTMI_LARGE_HOUR_Y_PAD);
/* Step through each row, drawing the times and the horizontal lines
between them. */
@@ -349,10 +374,13 @@ e_day_view_time_item_draw (GnomeCanvasItem *canvas_item,
display_hour, suffix);
}
minute_width = gdk_string_width (small_font, buffer);
- gdk_draw_string (drawable, small_font, fg_gc,
+
+ layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer);
+ gdk_draw_layout (drawable, fg_gc,
minute_x2 - minute_width,
row_y + small_font_y_offset,
- buffer);
+ layout);
+ g_object_unref (layout);
} else {
/* 5/10/15/30 minute intervals. */
@@ -366,12 +394,15 @@ e_day_view_time_item_draw (GnomeCanvasItem *canvas_item,
g_snprintf (buffer, sizeof (buffer), "%i",
display_hour);
- hour_width = gdk_string_width (large_font,
- buffer);
- gdk_draw_string (drawable, large_font, fg_gc,
+
+ layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer);
+ pango_layout_set_font_description (layout, day_view->large_font_desc);
+ pango_layout_get_pixel_size (layout, &hour_width, NULL);
+ gdk_draw_layout (drawable, fg_gc,
large_hour_x2 - hour_width,
row_y + large_hour_y_offset,
- buffer);
+ layout);
+ g_object_unref (layout);
} else {
/* Within the hour - draw a short line before
the time. */
@@ -393,12 +424,14 @@ e_day_view_time_item_draw (GnomeCanvasItem *canvas_item,
g_snprintf (buffer, sizeof (buffer),
"%02i", minute);
}
- minute_width = gdk_string_width (small_font,
- buffer);
- gdk_draw_string (drawable, small_font, fg_gc,
+
+ layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer);
+ pango_layout_get_pixel_size (layout, &minute_width, NULL);
+ gdk_draw_layout (drawable, fg_gc,
minute_x2 - minute_width,
row_y + small_font_y_offset,
- buffer);
+ layout);
+ g_object_unref (layout);
}
}