From 41c0e5bb186d461a9da7763518b6bcd277391f09 Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Tue, 5 Mar 2002 20:47:48 +0000 Subject: remove unneeded parameter from print_text_size everywhere 2002-03-05 JP Rosevear * gui/print.c: remove unneeded parameter from print_text_size everywhere (get_font_for_size): calculate a font size based on the available height (print_text): calculate the top of where the font should be drawn (print_text_size): use get_font_for_size (print_day_background): use get_font_for_size 2002-03-05 JP Rosevear * gui/e-meeting-time-sel-item.c (e_meeting_time_selector_item_draw): pass the real table to e_meeting_model_etable_view_to_model_row (e_meeting_time_selector_item_paint_busy_periods): ditto * gui/dialogs/meeting-page.c (right_click_cb): ditto * gui/e-meeting-model.h: update protos * gui/e-meeting-model.c (e_meeting_model_etable_model_to_view_row): take in to account the fact the table used the without model (e_meeting_model_etable_view_to_model_row): ditto svn path=/trunk/; revision=15926 --- calendar/ChangeLog | 26 ++++++ calendar/gui/dialogs/meeting-page.c | 5 +- calendar/gui/e-meeting-model.c | 18 ++++- calendar/gui/e-meeting-model.h | 4 +- calendar/gui/e-meeting-time-sel-item.c | 8 +- calendar/gui/print.c | 139 +++++++++++++++++++-------------- 6 files changed, 131 insertions(+), 69 deletions(-) diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 9156b15201..aaff472d9a 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,29 @@ +2002-03-05 JP Rosevear + + * gui/print.c: remove unneeded parameter from print_text_size + everywhere + (get_font_for_size): calculate a font size based on the available + height + (print_text): calculate the top of where the font should be drawn + (print_text_size): use get_font_for_size + (print_day_background): use get_font_for_size + +2002-03-05 JP Rosevear + + * gui/e-meeting-time-sel-item.c + (e_meeting_time_selector_item_draw): pass the real table + to e_meeting_model_etable_view_to_model_row + (e_meeting_time_selector_item_paint_busy_periods): ditto + + * gui/dialogs/meeting-page.c (right_click_cb): ditto + + * gui/e-meeting-model.h: update protos + + * gui/e-meeting-model.c + (e_meeting_model_etable_model_to_view_row): take in to account the + fact the table used the without model + (e_meeting_model_etable_view_to_model_row): ditto + 2002-03-04 Damon Chaplin * gui/tasks-control.c: added support for printing the Tasks table. diff --git a/calendar/gui/dialogs/meeting-page.c b/calendar/gui/dialogs/meeting-page.c index 51cfe045d9..7333380195 100644 --- a/calendar/gui/dialogs/meeting-page.c +++ b/calendar/gui/dialogs/meeting-page.c @@ -717,11 +717,12 @@ right_click_cb (ETable *etable, gint row, gint col, GdkEvent *event, gpointer da MeetingPage *mpage = MEETING_PAGE (data); MeetingPagePrivate *priv; GtkMenu *menu; - int enable_mask = 0, hide_mask = 0; + int enable_mask = 0, hide_mask = 0, view_row; priv = mpage->priv; - priv->row = e_meeting_model_etable_view_to_model_row (priv->model, row); + view_row = e_table_model_to_view_row (etable, row); + priv->row = e_meeting_model_etable_view_to_model_row (etable, priv->model, view_row); menu = e_popup_menu_create (context_menu, enable_mask, hide_mask, data); e_auto_kill_popup_menu_on_hide (menu); diff --git a/calendar/gui/e-meeting-model.c b/calendar/gui/e-meeting-model.c index 54b5bfd407..6adfb9c1c9 100644 --- a/calendar/gui/e-meeting-model.c +++ b/calendar/gui/e-meeting-model.c @@ -1528,29 +1528,39 @@ e_meeting_model_etable_from_model (EMeetingModel *im, const gchar *spec_file, co } int -e_meeting_model_etable_model_to_view_row (EMeetingModel *im, int model_row) +e_meeting_model_etable_model_to_view_row (ETable *et, EMeetingModel *im, int model_row) { EMeetingModelPrivate *priv; + int row; g_return_val_if_fail (im != NULL, -1); g_return_val_if_fail (E_IS_MEETING_MODEL (im), -1); priv = im->priv; - return e_table_subset_model_to_view_row (E_TABLE_SUBSET (priv->without), model_row); + row = e_table_model_to_view_row (et, model_row); + if (row == -1) + return -1; + + return e_table_subset_model_to_view_row (E_TABLE_SUBSET (priv->without), row); } int -e_meeting_model_etable_view_to_model_row (EMeetingModel *im, int view_row) +e_meeting_model_etable_view_to_model_row (ETable *et, EMeetingModel *im, int view_row) { EMeetingModelPrivate *priv; + int row; g_return_val_if_fail (im != NULL, -1); g_return_val_if_fail (E_IS_MEETING_MODEL (im), -1); priv = im->priv; - return e_table_subset_view_to_model_row (E_TABLE_SUBSET (priv->without), view_row); + row = e_table_view_to_model_row (et, view_row); + if (row == -1) + return -1; + + return e_table_subset_view_to_model_row (E_TABLE_SUBSET (priv->without), row); } diff --git a/calendar/gui/e-meeting-model.h b/calendar/gui/e-meeting-model.h index 431faf203b..7e1aa0758b 100644 --- a/calendar/gui/e-meeting-model.h +++ b/calendar/gui/e-meeting-model.h @@ -112,8 +112,8 @@ void e_meeting_model_refresh_busy_periods (EMeetingModel *im, /* Helpful functions */ ETableScrolled *e_meeting_model_etable_from_model (EMeetingModel *im, const gchar *spec_file, const gchar *state_file); -int e_meeting_model_etable_model_to_view_row (EMeetingModel *im, int model_row); -int e_meeting_model_etable_view_to_model_row (EMeetingModel *im, int view_row); +int e_meeting_model_etable_model_to_view_row (ETable *et, EMeetingModel *im, int model_row); +int e_meeting_model_etable_view_to_model_row (ETable *et, EMeetingModel *im, int view_row); void e_meeting_model_invite_others_dialog (EMeetingModel *im); diff --git a/calendar/gui/e-meeting-time-sel-item.c b/calendar/gui/e-meeting-time-sel-item.c index a796495451..d44a1f436d 100644 --- a/calendar/gui/e-meeting-time-sel-item.c +++ b/calendar/gui/e-meeting-time-sel-item.c @@ -272,6 +272,7 @@ e_meeting_time_selector_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, { EMeetingTimeSelector *mts; EMeetingTimeSelectorItem *mts_item; + ETable *real_table; EMeetingAttendee *ia; gint day_x, meeting_start_x, meeting_end_x, bar_y, bar_height; gint row, row_y, start_x, end_x; @@ -285,6 +286,8 @@ e_meeting_time_selector_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, gc = mts_item->main_gc; stipple_gc = mts_item->stipple_gc; + real_table = e_table_scrolled_get_table (E_TABLE_SCROLLED (mts->etable)); + is_display_top = (GTK_WIDGET (item->canvas) == mts->display_top) ? TRUE : FALSE; @@ -335,7 +338,8 @@ e_meeting_time_selector_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, row = y / mts->row_height; row_y = row * mts->row_height - y; while (row < e_meeting_model_count_actual_attendees (mts->model) && row_y < height) { - gint model_row = e_meeting_model_etable_view_to_model_row (mts->model, row); + gint model_row = e_meeting_model_etable_view_to_model_row (real_table, + mts->model, row); ia = e_meeting_model_find_attendee_at_row (mts->model, model_row); @@ -648,7 +652,7 @@ e_meeting_time_selector_item_paint_busy_periods (EMeetingTimeSelectorItem *mts_i /* Step through the attendees painting the busy periods. */ while (y < height && row < e_meeting_model_count_actual_attendees (mts->model)) { - model_row = e_meeting_model_etable_view_to_model_row (mts->model, row); + model_row = e_meeting_model_etable_view_to_model_row (real_table, mts->model, row); /* Find the first visible busy period. */ first_period = e_meeting_time_selector_item_find_first_busy_period (mts_item, date, model_row); diff --git a/calendar/gui/print.c b/calendar/gui/print.c index 41b72aeb02..6e385a065d 100644 --- a/calendar/gui/print.c +++ b/calendar/gui/print.c @@ -62,6 +62,9 @@ * what gnome-print uses. */ +/* The font to use */ +#define DEFAULT_FONT "Times" + /* The font size to use for normal text. */ #define DAY_NORMAL_FONT_SIZE 12 #define WEEK_NORMAL_FONT_SIZE 12 @@ -249,6 +252,25 @@ build_month (int month, int year, int *days, int *start, int *end) *end = d_week + d_month - 1; } +static GnomeFont * +get_font_for_size (double h, GnomeFontWeight weight, gboolean italic) +{ + GnomeFontFace *face; + GnomeFont *font; + double asc, desc, size; + + face = gnome_font_unsized_closest (DEFAULT_FONT, weight, italic); + asc = gnome_font_face_get_ascender (face); + desc = gnome_font_face_get_descender (face); + size = h * 1000 / (asc + desc); + g_print ("Print Info: %f, %f, %f\n", asc, desc, size); + + font = gnome_font_new_closest (DEFAULT_FONT, weight, italic, size); + + gtk_object_unref (GTK_OBJECT (face)); + + return font; +} enum align_box { ALIGN_LEFT=1, @@ -355,12 +377,9 @@ print_text(GnomePrintContext *pc, GnomeFont *font, const char *text, /* Make sure we don't go off the left edge. */ x = MAX (l, x); - /* Calculate the top of where the text should be. */ - y = (t + b + gnome_font_get_size (font)) / 2; - /* Now calculate the baseline. */ - y -= gnome_font_get_ascender (font) + 1; - + y = t - gnome_font_get_ascender (font); + /* Set a clipping rectangle. */ gnome_print_moveto (pc, l, t); gnome_print_lineto (pc, r, t); @@ -378,14 +397,26 @@ print_text(GnomePrintContext *pc, GnomeFont *font, const char *text, gnome_print_grestore (pc); } +/* gets/frees the font for you, as a book font */ +static void +print_text_size(GnomePrintContext *pc, const char *text, + enum align_box align, double l, double r, double t, double b) +{ + GnomeFont *font; + + font = get_font_for_size (t - b, GNOME_FONT_BOOK, FALSE); + print_text(pc, font, text, align, l, r, t, b); + gtk_object_unref (GTK_OBJECT (font)); +} + /* gets/frees the font for you, as a bold font */ static void -print_text_size(GnomePrintContext *pc, double size, const char *text, - enum align_box align, double l, double r, double t, double b) +print_text_size_bold(GnomePrintContext *pc, const char *text, + enum align_box align, double l, double r, double t, double b) { GnomeFont *font; - font = gnome_font_new_closest ("Times", GNOME_FONT_BOLD, 0, size); + font = get_font_for_size (t - b, GNOME_FONT_BOLD, FALSE); print_text(pc, font, text, align, l, r, t, b); gtk_object_unref (GTK_OBJECT (font)); } @@ -501,14 +532,13 @@ print_month_small (GnomePrintContext *pc, GnomeCalendar *gcal, time_t month, /* Print the title, e.g. 'June 2001', in the top 16% of the area. */ format_date (month, titleflags, buf, 100); header_size = (top - bottom) * 0.16; - font = gnome_font_new_closest ("Times", GNOME_FONT_BOLD, FALSE, - header_size * 0.8); + font = get_font_for_size (header_size, GNOME_FONT_BOLD, FALSE); if (bordertitle) { print_border (pc, left, right, top, top - header_size, 1.0, 0.9); } print_text (pc, font, buf, ALIGN_CENTER, left, right, - top - header_size * 0.1, top - header_size); + top, top - header_size); gtk_object_unref (GTK_OBJECT (font)); top -= header_size; @@ -523,24 +553,21 @@ print_month_small (GnomePrintContext *pc, GnomeCalendar *gcal, time_t month, /* First we need to calculate a reasonable font size. We start with a rough guess of just under the height of each row. */ - font_size = row_height * 0.9; + font_size = row_height; /* Check that it isn't going to be too wide. The characters are about twice as high as they are wide, but we need to fit two characters into each cell, so we don't want to go over col_width. */ max_font_size = col_width * 0.65; - font_size = MIN (font_size, max_font_size); - + font_size = row_height; /* get month days */ tm = *convert_timet_to_struct_tm (month, zone); build_month (tm.tm_mon, tm.tm_year + 1900, days, 0, 0); - font_normal = gnome_font_new_closest ("Times", GNOME_FONT_BOOK, 0, - font_size); - font_bold = gnome_font_new_closest ("Times", GNOME_FONT_BOLD, 0, - font_size); + font_normal = get_font_for_size (font_size, GNOME_FONT_BOOK, FALSE); + font_bold = get_font_for_size (font_size, GNOME_FONT_BOLD, FALSE); /* Get a reasonable estimate of the largest number we will need, and use it to calculate the offset from the right edge of the @@ -738,20 +765,16 @@ print_day_background (GnomePrintContext *pc, GnomeCalendar *gcal, /* Calculate the row height. */ yinc = (top - bottom) / (pdi->end_hour - pdi->start_hour); - /* Get the 2 fonts we need. */ + /* Get the 2 fonts we need. */ font_size = yinc * 0.6; max_font_size = width * 0.5; - font_size = MIN (font_size, max_font_size); - font_hour = gnome_font_new_closest ("Times", GNOME_FONT_BOLD, - 0, font_size); - hour_font_size = gnome_font_get_size (font_hour); + hour_font_size = MIN (font_size, max_font_size); + font_hour = get_font_for_size (hour_font_size, GNOME_FONT_BOLD, FALSE); font_size = yinc * 0.33; max_font_size = width * 0.25; - font_size = MIN (font_size, max_font_size); - font_minute = gnome_font_new_closest ("Times", GNOME_FONT_BOOK, - 0, font_size); - minute_font_size = gnome_font_get_size (font_minute); + minute_font_size = MIN (font_size, max_font_size); + font_minute = get_font_for_size (minute_font_size, GNOME_FONT_BOLD, FALSE); use_24_hour = calendar_config_get_24_hour_format (); @@ -1114,7 +1137,7 @@ print_day_details (GnomePrintContext *pc, GnomeCalendar *gcal, time_t whence, pdi.day_starts, &rows_in_top_display); /* Print the long events. */ - font = gnome_font_new_closest ("Times", GNOME_FONT_BOOK, 0, 12); + font = get_font_for_size (12, GNOME_FONT_BOOK, FALSE); for (i = 0; i < pdi.long_events->len; i++) { event = &g_array_index (pdi.long_events, EDayViewEvent, i); print_day_long_event (pc, font, left, right, top, bottom, @@ -1151,7 +1174,7 @@ print_day_details (GnomePrintContext *pc, GnomeCalendar *gcal, time_t whence, /* Print the short events. */ max_font_size = ((top - bottom) / pdi.rows) - 4; font_size = MIN (DAY_NORMAL_FONT_SIZE, max_font_size); - font = gnome_font_new_closest ("Times", GNOME_FONT_BOOK, 0, font_size); + font = get_font_for_size (font_size, GNOME_FONT_BOOK, FALSE); for (i = 0; i < pdi.events[0]->len; i++) { event = &g_array_index (pdi.events[0], EDayViewEvent, i); print_day_event (pc, font, left, right, top, bottom, @@ -1273,7 +1296,7 @@ print_week_long_event (GnomePrintContext *pc, GnomeFont *font, buffer, sizeof (buffer)); x1 += 4; - print_text (pc, font, buffer, ALIGN_LEFT, x1, x2, y1, y2); + print_text_size (pc, buffer, ALIGN_LEFT, x1, x2, y1, y2); x1 += gnome_font_get_width_utf8 (font, buffer); } @@ -1292,13 +1315,13 @@ print_week_long_event (GnomePrintContext *pc, GnomeFont *font, buffer, sizeof (buffer)); x2 -= 4; - print_text (pc, font, buffer, ALIGN_RIGHT, x1, x2, y1, y2); + print_text_size (pc, buffer, ALIGN_RIGHT, x1, x2, y1, y2); x2 -= gnome_font_get_width_utf8 (font, buffer); } x1 += 4; x2 -= 4; - print_text (pc, font, text, ALIGN_CENTER, x1, x2, y1, y2); + print_text_size (pc, text, ALIGN_CENTER, x1, x2, y1, y2); } @@ -1323,11 +1346,11 @@ print_week_day_event (GnomePrintContext *pc, GnomeFont *font, e_time_format_time (&date_tm, psi->use_24_hour_format, FALSE, buffer, sizeof (buffer)); - print_text (pc, font, buffer, ALIGN_LEFT, x1, x2, y1, y2); + print_text_size (pc, buffer, ALIGN_LEFT, x1, x2, y1, y2); x1 += gnome_font_get_width_utf8 (font, buffer); x1 += 4; - print_text (pc, font, text, ALIGN_LEFT, x1, x2, y1, y2); + print_text_size (pc, text, ALIGN_LEFT, x1, x2, y1, y2); } @@ -1464,8 +1487,8 @@ print_week_view_background (GnomePrintContext *pc, GnomeFont *font, strftime (buffer, sizeof (buffer), format_string, &tm); utf_str = e_utf8_from_locale_string (buffer); - print_text (pc, font, utf_str, ALIGN_RIGHT, - x1, x2 - 4, y1 - 2, y1 - 2 - font_size); + print_text_size (pc, utf_str, ALIGN_RIGHT, + x1, x2 - 4, y1 - 2, y1 - 2 - font_size); g_free (utf_str); } } @@ -1552,7 +1575,7 @@ print_week_summary (GnomePrintContext *pc, GnomeCalendar *gcal, psi.rows_per_compressed_cell = (cell_height - psi.header_row_height) / psi.row_height; - font = gnome_font_new_closest ("Times", GNOME_FONT_BOOK, 0, font_size); + font = get_font_for_size (font_size, GNOME_FONT_BOOK, FALSE); /* Draw the grid and the day names/numbers. */ print_week_view_background (pc, font, &psi, left, top, @@ -1659,8 +1682,7 @@ print_month_summary (GnomePrintContext *pc, GnomeCalendar *gcal, time_t whence, tm = *convert_timet_to_struct_tm (date, zone); tm.tm_mday = (tm.tm_mday % 7) + 7; - font = gnome_font_new_closest ("Times", GNOME_FONT_BOLD, 0, - MONTH_NORMAL_FONT_SIZE); + font = get_font_for_size (MONTH_NORMAL_FONT_SIZE, GNOME_FONT_BOLD, FALSE); font_size = gnome_font_get_size (font); gnome_print_setfont (pc, font); @@ -1688,7 +1710,7 @@ print_month_summary (GnomePrintContext *pc, GnomeCalendar *gcal, time_t whence, print_border (pc, x1, x2, y1, y2, 1.0, -1.0); utf_str = e_utf8_from_locale_string (buffer); - print_text (pc, font, utf_str, ALIGN_CENTER, x1, x2, y1, y2); + print_text_size (pc, utf_str, ALIGN_CENTER, x1, x2, y1, y2); g_free (utf_str); tm.tm_mday++; @@ -1724,8 +1746,7 @@ print_todo_details (GnomePrintContext *pc, GnomeCalendar *gcal, model = e_calendar_table_get_model (task_pad); client = gnome_calendar_get_task_pad_cal_client (gcal); - font_summary = gnome_font_new_closest ("Times", GNOME_FONT_BOOK, - 0, 10); + font_summary = get_font_for_size (10, GNOME_FONT_BOOK, FALSE); gnome_print_setrgbcolor (pc, 0, 0, 0); gnome_print_setlinewidth (pc, 0.0); @@ -1927,12 +1948,12 @@ print_day_view (GnomePrintContext *pc, GnomeCalendar *gcal, time_t date, /* Print the date, e.g. '8th May, 2001'. */ format_date (date, DATE_DAY | DATE_MONTH | DATE_YEAR, buf, 100); - print_text_size (pc, 24, buf, ALIGN_LEFT, - left + 4, todo, top - 4, top - 4 - 24); + print_text_size_bold (pc, buf, ALIGN_LEFT, + left + 4, todo, top - 4, top - 4 - 24); /* Print the day, e.g. 'Tuesday'. */ format_date (date, DATE_DAYNAME, buf, 100); - print_text_size (pc, 18, buf, ALIGN_LEFT, + print_text_size_bold (pc, buf, ALIGN_LEFT, left + 4, todo, top - 32, top - 32 - 18); gnome_print_showpage (pc); @@ -1999,14 +2020,14 @@ print_week_view (GnomePrintContext *pc, GnomeCalendar *gcal, time_t date, /* Print the start day of the week, e.g. '7th May 2001'. */ format_date (when, DATE_DAY | DATE_MONTH | DATE_YEAR, buf, 100); - print_text_size (pc, 24, buf, ALIGN_LEFT, - left + 3, right, top - 4, top - 4 - 24); - + print_text_size_bold (pc, buf, ALIGN_LEFT, + left + 3, right, top - 4, top - 4 - 24); + /* Print the end day of the week, e.g. '13th May 2001'. */ when = time_add_day_with_zone (when, 6, zone); format_date (when, DATE_DAY | DATE_MONTH | DATE_YEAR, buf, 100); - print_text_size (pc, 24, buf, ALIGN_LEFT, - left + 3, right, top - 24 - 3, top - 24 - 3 - 24); + print_text_size_bold (pc, buf, ALIGN_LEFT, + left + 3, right, top - 24 - 3, top - 24 - 3 - 24); gnome_print_showpage (pc); } @@ -2045,8 +2066,8 @@ print_month_view (GnomePrintContext *pc, GnomeCalendar *gcal, time_t date, /* Print the month, e.g. 'May 2001'. */ format_date (date, DATE_MONTH | DATE_YEAR, buf, 100); - print_text_size (pc, 24, buf, ALIGN_CENTER, - left + 3, right - 3, top - 3, top - 3 - 24); + print_text_size_bold (pc, buf, ALIGN_CENTER, + left + 3, right - 3, top - 3, top - 3 - 24); gnome_print_showpage (pc); } @@ -2066,8 +2087,8 @@ print_year_view (GnomePrintContext *pc, GnomeCalendar *gcal, time_t date, /* centered title */ format_date (date, DATE_YEAR, buf, 100); - print_text_size (pc, 24, buf, ALIGN_CENTER, - left+3, right, top-3, top - 27); + print_text_size_bold (pc, buf, ALIGN_CENTER, + left+3, right, top-3, top - 27); gnome_print_showpage (pc); } @@ -2178,8 +2199,8 @@ print_date_label (GnomePrintContext *pc, CalComponent *comp, CalClient *client, } utf_text = e_utf8_from_locale_string (buffer); - print_text_size (pc, 12, utf_text, ALIGN_LEFT, - left, right, top, top - 15); + print_text_size_bold (pc, utf_text, ALIGN_LEFT, + left, right, top, top - 15); g_free (utf_text); } @@ -2207,7 +2228,7 @@ print_comp_item (GnomePrintContext *pc, CalComponent *comp, CalClient *client, return; /* Print the title in a box at the top of the page. */ - font = gnome_font_new_closest ("Times", GNOME_FONT_BOLD, FALSE, 18); + font = get_font_for_size (18, GNOME_FONT_BOLD, FALSE); header_size = 50; print_border (pc, left, right, top, top - header_size, 1.0, 0.9); @@ -2218,7 +2239,7 @@ print_comp_item (GnomePrintContext *pc, CalComponent *comp, CalClient *client, top -= header_size + 10; /* Summary */ - font = gnome_font_new_closest ("Times", GNOME_FONT_BOLD, FALSE, 18); + font = get_font_for_size (18, GNOME_FONT_BOLD, FALSE); cal_component_get_summary (comp, &text); top = bound_text (pc, font, text.value, left, right, top - 3, bottom, 0); @@ -2228,7 +2249,7 @@ print_comp_item (GnomePrintContext *pc, CalComponent *comp, CalClient *client, print_date_label (pc, comp, client, left, right, top-3, top - 15); top -= 20; - font = gnome_font_new_closest ("Times", GNOME_FONT_BOOK, FALSE, 12); + font = get_font_for_size (12, GNOME_FONT_BOOK, FALSE); /* For a VTODO we print the Status, Priority, % Complete and URL. */ if (vtype == CAL_COMPONENT_TODO) { -- cgit v1.2.3