--- calendar/gui/print.c.orig	2010-06-21 16:04:38.256309815 -0700
+++ calendar/gui/print.c	2010-06-22 16:15:10.741955174 -0700
@@ -118,6 +118,9 @@
 /* The font size to use for normal text. */
 #define DAY_NORMAL_FONT_SIZE	12
 #define WEEK_NORMAL_FONT_SIZE	12
+#define WEEK_EVENT_FONT_SIZE	9
+#define WEEK_SMALL_FONT_SIZE	8
+
 #define MONTH_NORMAL_FONT_SIZE	8
 
 /* The height of the header bar across the top of the Day, Week & Month views,
@@ -126,7 +129,7 @@
 
 /* The width of the small calendar months, the space from the right edge of
    the header rectangle, and the space between the months. */
-#define SMALL_MONTH_WIDTH	100
+#define SMALL_MONTH_WIDTH	120
 #define SMALL_MONTH_PAD		5
 #define SMALL_MONTH_SPACING	20
 
@@ -404,13 +407,41 @@
 	cairo_restore (cr);
 }
 
+/* Recreate the layout by shrinking the text string if we have a line that's
+ * too high.
+ */
+PangoLayout *shrink_text_to_line(PangoLayout *layout,
+            gint layout_width, gint layout_height,
+            GtkPrintContext *context, PangoFontDescription *desc,
+            const gchar *text, PangoAlignment alignment,
+            gdouble x1, gdouble x2, gdouble y1, gdouble y2){
+
+
+	if (layout_width==0 || x2-x1 < EPSILON) return layout; // Do nothing
+
+	gint new_length = (gint)floor(pango_units_from_double(x2-x1)/(gdouble)layout_width *
+		(gdouble) strlen(text));
+
+	if (new_length<strlen(text)){
+		g_object_unref (layout); // Destroy old layout
+		layout = gtk_print_context_create_pango_layout (context);
+
+		pango_layout_set_font_description (layout, desc);
+		pango_layout_set_alignment (layout, alignment);
+		pango_layout_set_text (layout, text, new_length);
+	}
+
+	return layout;
+
+}
+
 /* Prints 1 line of aligned text in a box. It is centered vertically, and
    the horizontal alignment can be either PANGO_ALIGN_LEFT, PANGO_ALIGN_RIGHT,
-   or PANGO_ALIGN_CENTER. */
+   or PANGO_ALIGN_CENTER. Text is truncated if too long for cell. */
 static double
-print_text (GtkPrintContext *context, PangoFontDescription *desc,
+print_text_line (GtkPrintContext *context, PangoFontDescription *desc,
             const gchar *text, PangoAlignment alignment,
-            gdouble x1, gdouble x2, gdouble y1, gdouble y2)
+            gdouble x1, gdouble x2, gdouble y1, gdouble y2, gboolean shrink)
 {
 	PangoLayout *layout;
 	gint layout_width, layout_height;
@@ -426,6 +457,11 @@
 	/* Grab the width before expanding the layout. */
 	pango_layout_get_size (layout, &layout_width, &layout_height);
 
+	if (shrink && layout_width>pango_units_from_double (x2 - x1)) // Too wide
+		layout = shrink_text_to_line(layout, layout_width, layout_height,
+			context, desc, text, alignment,
+			x1, x2, y1, y2);
+
 	pango_layout_set_width (layout, pango_units_from_double (x2 - x1));
 
 	cairo_save (cr);
@@ -433,7 +469,7 @@
 	/* Set a clipping rectangle. */
 	cairo_move_to (cr, x1, y1);
 	cairo_rectangle (cr, x1, y1, x2 - x1, y2 - y1);
-	cairo_clip (cr);    
+	cairo_clip (cr);
 
 	cairo_new_path (cr);
 	cairo_set_source_rgb (cr, 0, 0, 0);
@@ -450,6 +486,20 @@
 	return pango_units_to_double (layout_width);
 }
 
+/* Prints 1 or more lines of aligned text in a box. It is centered vertically, and
+   the horizontal alignment can be either PANGO_ALIGN_LEFT, PANGO_ALIGN_RIGHT,
+   or PANGO_ALIGN_CENTER. */
+static double
+print_text (GtkPrintContext *context, PangoFontDescription *desc,
+            const gchar *text, PangoAlignment alignment,
+            gdouble x1, gdouble x2, gdouble y1, gdouble y2)
+{
+	return print_text_line (context, desc,
+		text, alignment,
+		x1, x2, y1, y2, FALSE);
+}
+
+
 /* gets/frees the font for you, as a normal font */
 static double
 print_text_size (GtkPrintContext *context, const gchar *text,
@@ -482,6 +532,41 @@
 	return w;
 }
 
+/* gets/frees the font for you, as a normal font - absolute size parameter */
+static double
+print_text_abs (GtkPrintContext *context, const gchar *text,
+                 gdouble font_size,
+                 PangoAlignment alignment, gdouble x1, gdouble x2,
+                 gdouble y1, gdouble y2)
+{
+	PangoFontDescription *font;
+	double w;
+
+	font = get_font_for_size (font_size, PANGO_WEIGHT_NORMAL);
+	w = print_text_line (context, font, text, alignment, x1, x2, y1, y2, TRUE);
+	pango_font_description_free (font);
+
+	return w;
+}
+
+/* gets/frees the font for you, as a bold font - absolute size parameter */
+static double
+print_text_abs_bold (GtkPrintContext *context, const gchar *text,
+                      gdouble font_size,
+                      PangoAlignment alignment, gdouble x1, gdouble x2,
+                      gdouble y1, gdouble y2)
+{
+	PangoFontDescription *font;
+	double w;
+
+	font = get_font_for_size (font_size, PANGO_WEIGHT_BOLD);
+	w = print_text_line (context, font, text, alignment, x1, x2, y1, y2, TRUE);
+	pango_font_description_free (font);
+
+	return w;
+}
+
+
 static void
 titled_box (GtkPrintContext *context, const gchar *text,
             PangoFontDescription *font, PangoAlignment alignment,
@@ -1152,7 +1237,7 @@
 
 	x1 += 4;
 	x2 -= 4;
-	print_text (context, font, text, PANGO_ALIGN_CENTER, x1, x2, y1, y2);
+	print_text_line (context, font, text, PANGO_ALIGN_CENTER, x1, x2, y1, y2, TRUE);
 
 	g_free (text);
 }
@@ -1342,7 +1427,7 @@
 
 		/* Right align - 10 comes from print_day_long_event  too */
 		x = right - gdk_pixbuf_get_width (pixbuf) * 0.5 - 10;
-		/* Placing '...' at mid height. 4 and 7 constant come from print_day_long_event 
+		/* Placing '...' at mid height. 4 and 7 constant come from print_day_long_event
 		   (offsets used to place events boxes in their respective cells) */
 		y = top + DAY_VIEW_ROW_HEIGHT * i + (DAY_VIEW_ROW_HEIGHT - 4 - 7) * 0.5;
 
@@ -1440,10 +1525,12 @@
 	if (event->end > psi->day_starts[span->start_day + span->num_days])
 		right_triangle_width = 4;
 
-	print_border_with_triangles (context, x1, x2, y1, y1 + row_height, 0.0, red, green, blue,
+	print_border_with_triangles (context, x1+6, x2-6, y1, y1 + row_height, 0.0, red, green, blue,
 				     left_triangle_width,
 				     right_triangle_width);
 
+	x1+=6;
+	x2-=6;
 	/* If the event starts after the first day being printed, we need to
 	   print the start time. */
 	if (event->start > psi->day_starts[span->start_day]) {
@@ -1458,8 +1545,9 @@
 		e_time_format_time (&date_tm, psi->use_24_hour_format, FALSE,
 				    buffer, sizeof (buffer));
 
-		x1 += 4;
-		x1 += print_text_size (context, buffer, PANGO_ALIGN_LEFT, x1, x2, y1, y1 + row_height);
+		x1 += 2;
+		x1 += print_text_line (context, font, buffer, PANGO_ALIGN_LEFT,
+			x1, x2-2, y1, y1 + row_height, TRUE);
 	}
 
 	/* If the event ends before the end of the last day being printed,
@@ -1476,13 +1564,15 @@
 		e_time_format_time (&date_tm, psi->use_24_hour_format, FALSE,
 				    buffer, sizeof (buffer));
 
-		x2 -= 4;
-		x2 -= print_text_size (context, buffer, PANGO_ALIGN_RIGHT, x1, x2, y1, y1 + row_height);
+		x2 -= 2;
+		x2 -= print_text_line (context, font, buffer, PANGO_ALIGN_RIGHT,
+			x1+2, x2, y1, y1 + row_height, TRUE);
 	}
 
-	x1 += 4;
-	x2 -= 4;
-	print_text_size (context, text, PANGO_ALIGN_CENTER, x1, x2, y1, y1 + row_height);
+	x1 += 2;
+	x2 -= 2;
+	print_text_line (context, font, text, PANGO_ALIGN_CENTER,
+		x1, x2, y1, y1 + row_height, TRUE);
 }
 
 static void
@@ -1505,8 +1595,9 @@
 
 	e_time_format_time (&date_tm, psi->use_24_hour_format, FALSE,
 			    buffer, sizeof (buffer));
-	print_rectangle (context, x1, y1, x2 - x1, row_height, red, green, blue);
-	x1 += print_text_size (context, buffer, PANGO_ALIGN_LEFT, x1, x2, y1, y1 + row_height) + 4;
+	print_rectangle (context, x1+1, y1, x2 - x1-2, row_height, red, green, blue);
+	x1 += print_text_line (context, font, buffer, PANGO_ALIGN_LEFT,
+		x1+2, x2-3, y1, y1 + row_height, TRUE) + 4;
 
 	if (psi->weeks_shown <= 2) {
 		date_tm.tm_hour = event->end_minute / 60;
@@ -1515,11 +1606,13 @@
 		e_time_format_time (&date_tm, psi->use_24_hour_format, FALSE,
 				    buffer, sizeof (buffer));
 
-		print_rectangle (context, x1, y1, x2 - x1, row_height, red, green, blue);
-		x1 += print_text_size (context, buffer, PANGO_ALIGN_LEFT, x1, x2, y1, y1 + row_height) + 4;
+		//print_rectangle (context, x1, y1, x2 - x1, row_height, red, green, blue);
+		x1 += print_text_line (context, font, buffer, PANGO_ALIGN_LEFT,
+			x1, x2-3, y1, y1 + row_height, TRUE) + 4;
 	}
 
-	print_text_size (context, text, PANGO_ALIGN_LEFT, x1, x2, y1, y1 + row_height);
+	print_text_line (context, font, text, PANGO_ALIGN_LEFT,
+		x1, x2-3, y1, y1 + row_height, TRUE);
 }
 
 static void
@@ -1575,12 +1668,12 @@
 					 &end_x, &end_y, &end_h);
 			}
 
-			x1 = left + start_x * cell_width + 6;
-			x2 = left + (end_x + 1) * cell_width - 6;
+			x1 = left + start_x * cell_width;
+			x2 = left + (end_x + 1) * cell_width;
 			y1 = top + start_y * cell_height
 				 + psi->header_row_height
 				 + span->row * (psi->row_height + 2);
-			y2 = y1 + psi->row_height * 0.5;
+			y2 = y1 + psi->row_height*0.5; // TODO handle multiple rows
 
 			red = .9;
 			green = .9;
@@ -1712,8 +1805,8 @@
 
 		e_utf8_strftime (buffer, sizeof (buffer), format_string, &tm);
 
-		 print_text_size (context, buffer, PANGO_ALIGN_RIGHT,
-				 x1, x2 - 4, y1 + 2, y1 + 2 + font_size);
+		 print_text_line (context, font, buffer, PANGO_ALIGN_RIGHT,
+				 x1, x2 - 4, y1 + 2, y1 + 2 + font_size, TRUE);
 	}
 }
 
@@ -1766,7 +1859,7 @@
 static void
 print_week_summary (GtkPrintContext *context, GnomeCalendar *gcal,
 		    time_t whence, gboolean multi_week_view, gint weeks_shown,
-		    gint month, double font_size,
+		    gint month, double font_size, double font_size_background,
 		    double left, double right, double top, double bottom)
 {
 	icaltimezone *zone = calendar_config_get_icaltimezone ();
@@ -1775,7 +1868,7 @@
 	time_t day_start;
 	gint rows_per_day[E_WEEK_VIEW_MAX_WEEKS * 7], day, event_num;
 	GArray *spans;
-	PangoFontDescription *font;
+	PangoFontDescription *font, *font_background;
 	double cell_width, cell_height;
 	ECalModel *model = gnome_calendar_get_calendar_model (gcal);
 
@@ -1841,11 +1934,14 @@
 	psi.rows_per_compressed_cell = (cell_height - psi.header_row_height)
 		/ psi.row_height;
 
-	font = get_font_for_size (font_size, PANGO_WEIGHT_NORMAL);
 	/* Draw the grid and the day names/numbers. */
-	print_week_view_background (context, font, &psi, left, top,
+	font_background = get_font_for_size (font_size_background, PANGO_WEIGHT_NORMAL);
+	print_week_view_background (context, font_background, &psi, left, top,
 				    cell_width, cell_height);
+	pango_font_description_free (font_background);
+
 	/* Print the events. */
+	font = get_font_for_size (font_size, PANGO_WEIGHT_NORMAL);
 	for (event_num = 0; event_num < psi.events->len; event_num++) {
 		event = &g_array_index (psi.events, EWeekViewEvent, event_num);
 		print_week_event (context, font, &psi, left, top,
@@ -1854,6 +1950,7 @@
 
 	pango_font_description_free (font);
 
+
 	/* Free everything. */
 	for (event_num = 0; event_num < psi.events->len; event_num++) {
 		event = &g_array_index (psi.events, EWeekViewEvent, event_num);
@@ -1972,7 +2069,8 @@
 		x2 = x1 + cell_width;
 
 		print_border (context, x1, x2, y1, y2, 1.0, -1.0);
-		print_text_size (context, buffer, PANGO_ALIGN_CENTER, x1, x2, y1, y2);
+		print_text_line (context, font, buffer, PANGO_ALIGN_CENTER,
+			x1, x2, y1, y2, TRUE);
 
 		tm.tm_mday++;
 		tm.tm_wday = (tm.tm_wday + 1) % 7;
@@ -1981,7 +2079,7 @@
 
 	top = y2;
 	print_week_summary (context, gcal, date, TRUE, 6, month,
-			    MONTH_NORMAL_FONT_SIZE,
+			    MONTH_NORMAL_FONT_SIZE, MONTH_NORMAL_FONT_SIZE,
 			    left, right, top, bottom);
 }
 
@@ -2179,7 +2277,7 @@
 
 	/* Print the main week view. */
 	print_week_summary (context, gcal, when, FALSE, 1, 0,
-			    WEEK_NORMAL_FONT_SIZE,
+			    WEEK_EVENT_FONT_SIZE, WEEK_SMALL_FONT_SIZE,
 			    0.0, width,
 			    HEADER_HEIGHT + 20, height);
 
@@ -2208,14 +2306,14 @@
 
 	/* 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_bold (context, buf, PANGO_ALIGN_LEFT,
+	print_text_abs_bold (context, buf, WEEK_NORMAL_FONT_SIZE, PANGO_ALIGN_LEFT,
 			      3, width,
 			      4, 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_bold (context, buf, PANGO_ALIGN_LEFT,
+	print_text_abs_bold (context, buf, WEEK_NORMAL_FONT_SIZE, PANGO_ALIGN_LEFT,
 			      3, width,
 			      24 + 3, 24 + 3 + 24);
 }
@@ -2250,7 +2348,8 @@
 
 	print_month_small (context, gcal,
 			   time_add_month_with_zone (date, -1, zone),
-			   8, 4, width / 7 + 20, HEADER_HEIGHT + 4,
+			   SMALL_MONTH_PAD, 4, SMALL_MONTH_PAD+SMALL_MONTH_WIDTH,
+			   HEADER_HEIGHT + 4,
 			   DATE_MONTH | DATE_YEAR, 0, 0, FALSE);
 
 	/* Print the month, e.g. 'May 2001'. */
