]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkprintcontext.c
gtk/: fully remove gtkalias hacks
[~andy/gtk] / gtk / gtkprintcontext.c
index 219a830ea6807426b15c437de2f743f58171292f..105f1182621ea1a93492766d9a3e3f3d836caa33 100644 (file)
@@ -20,7 +20,6 @@
 
 #include "config.h"
 #include "gtkprintoperation-private.h"
-#include "gtkalias.h"
 
 typedef struct _GtkPrintContextClass GtkPrintContextClass;
 
@@ -38,13 +37,19 @@ struct _GtkPrintContext
   GtkPrintOperation *op;
   cairo_t *cr;
   GtkPageSetup *page_setup;
-  PangoFontMap *fontmap;
 
   gdouble surface_dpi_x;
   gdouble surface_dpi_y;
   
   gdouble pixels_per_unit_x;
   gdouble pixels_per_unit_y;
+
+  gboolean has_hard_margins;
+  gdouble hard_margin_top;
+  gdouble hard_margin_bottom;
+  gdouble hard_margin_left;
+  gdouble hard_margin_right;
+
 };
 
 struct _GtkPrintContextClass
@@ -59,7 +64,6 @@ gtk_print_context_finalize (GObject *object)
 {
   GtkPrintContext *context = GTK_PRINT_CONTEXT (object);
 
-  g_object_unref (context->fontmap);
   if (context->page_setup)
     g_object_unref (context->page_setup);
 
@@ -92,11 +96,33 @@ _gtk_print_context_new (GtkPrintOperation *op)
 
   context->op = op;
   context->cr = NULL;
-  context->fontmap = pango_cairo_font_map_new ();
+  context->has_hard_margins = FALSE;
   
   return context;
 }
 
+static PangoFontMap *
+_gtk_print_context_get_fontmap (GtkPrintContext *context)
+{
+  return pango_cairo_font_map_get_default ();
+}
+
+/**
+ * gtk_print_context_set_cairo_context:
+ * @context: a #GtkPrintContext
+ * @cr: the cairo context
+ * @dpi_x: the horizontal resolution to use with @cr
+ * @dpi_y: the vertical resolution to use with @cr
+ *
+ * Sets a new cairo context on a print context. 
+ * 
+ * This function is intended to be used when implementing
+ * an internal print preview, it is not needed for printing,
+ * since GTK+ itself creates a suitable cairo context in that
+ * case.
+ *
+ * Since: 2.10 
+ */
 void
 gtk_print_context_set_cairo_context (GtkPrintContext *context,
                                     cairo_t         *cr,
@@ -134,10 +160,6 @@ gtk_print_context_set_cairo_context (GtkPrintContext *context,
   cairo_scale (context->cr,
               context->pixels_per_unit_x,
               context->pixels_per_unit_y);
-    
-  /* We use the unit-scaled resolution, as we still want fonts given in points to work */
-  pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (context->fontmap),
-                                      dpi_y / context->pixels_per_unit_y);
 }
 
 
@@ -162,11 +184,11 @@ _gtk_print_context_rotate_according_to_orientation (GtkPrintContext *context)
     case GTK_PAGE_ORIENTATION_PORTRAIT:
       break;
     case GTK_PAGE_ORIENTATION_LANDSCAPE:
-      cairo_translate (cr, width, 0);
+      cairo_translate (cr, 0, height);
       cairo_matrix_init (&matrix,
-                         0,  1,
-                        -1,  0,
-                         0,  0);
+                        0, -1,
+                        1,  0,
+                        0,  0);
       cairo_transform (cr, &matrix);
       break;
     case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT:
@@ -178,11 +200,11 @@ _gtk_print_context_rotate_according_to_orientation (GtkPrintContext *context)
       cairo_transform (cr, &matrix);
       break;
     case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE:
-      cairo_translate (cr, 0, height);
+      cairo_translate (cr, width, 0);
       cairo_matrix_init (&matrix,
-                        0, -1,
-                        1,  0,
-                        0,  0);
+                         0,  1,
+                        -1,  0,
+                         0,  0);
       cairo_transform (cr, &matrix);
       break;
     }
@@ -295,7 +317,7 @@ gtk_print_context_get_width (GtkPrintContext *context)
  * gtk_print_context_get_height:
  * @context: a #GtkPrintContext
  * 
- * Obtains the width of the #GtkPrintContext, in pixels.
+ * Obtains the height of the #GtkPrintContext, in pixels.
  *
  * Return value: the height of @context
  *
@@ -358,6 +380,62 @@ gtk_print_context_get_dpi_y (GtkPrintContext *context)
   return context->surface_dpi_y;
 }
 
+/**
+ * gtk_print_context_get_hard_margins:
+ * @context: a #GtkPrintContext
+ * @top: top hardware printer margin
+ * @bottom: bottom hardware printer margin
+ * @left: left hardware printer margin
+ * @right: right hardware printer margin
+ *
+ * Obtains the hardware printer margins of the #GtkPrintContext, in units.
+ *
+ * Return value: %TRUE if the hard margins were retrieved
+ *
+ * Since: 2.20
+ */
+gboolean
+gtk_print_context_get_hard_margins (GtkPrintContext *context,
+                                   gdouble         *top,
+                                   gdouble         *bottom,
+                                   gdouble         *left,
+                                   gdouble         *right)
+{
+  if (context->has_hard_margins)
+    {
+      *top    = context->hard_margin_top / context->pixels_per_unit_y;
+      *bottom = context->hard_margin_bottom / context->pixels_per_unit_y;
+      *left   = context->hard_margin_left / context->pixels_per_unit_x;
+      *right  = context->hard_margin_right / context->pixels_per_unit_x;
+    }
+
+  return context->has_hard_margins;
+}
+
+/**
+ * gtk_print_context_set_hard_margins:
+ * @context: a #GtkPrintContext
+ * @top: top hardware printer margin
+ * @bottom: bottom hardware printer margin
+ * @left: left hardware printer margin
+ * @right: right hardware printer margin
+ *
+ * set the hard margins in pixel coordinates
+ */
+void
+_gtk_print_context_set_hard_margins (GtkPrintContext *context,
+                                    gdouble          top,
+                                    gdouble          bottom,
+                                    gdouble          left,
+                                    gdouble          right)
+{
+  context->hard_margin_top    = top;
+  context->hard_margin_bottom = bottom;
+  context->hard_margin_left   = left;
+  context->hard_margin_right  = right;
+  context->has_hard_margins   = TRUE;
+}
+
 /**
  * gtk_print_context_get_pango_fontmap:
  * @context: a #GtkPrintContext
@@ -374,7 +452,7 @@ gtk_print_context_get_pango_fontmap (GtkPrintContext *context)
 {
   g_return_val_if_fail (GTK_IS_PRINT_CONTEXT (context), NULL);
 
-  return context->fontmap;
+  return _gtk_print_context_get_fontmap (context);
 }
 
 /**
@@ -396,13 +474,18 @@ gtk_print_context_create_pango_context (GtkPrintContext *context)
 
   g_return_val_if_fail (GTK_IS_PRINT_CONTEXT (context), NULL);
   
-  pango_context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (context->fontmap));
+  pango_context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (_gtk_print_context_get_fontmap (context)));
 
   options = cairo_font_options_create ();
   cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF);
   pango_cairo_context_set_font_options (pango_context, options);
   cairo_font_options_destroy (options);
   
+  /* We use the unit-scaled resolution, as we still want 
+   * fonts given in points to work 
+   */
+  pango_cairo_context_set_resolution (pango_context,
+                                     context->surface_dpi_y / context->pixels_per_unit_y);
   return pango_context;
 }
 
@@ -433,7 +516,3 @@ gtk_print_context_create_pango_layout (GtkPrintContext *context)
 
   return layout;
 }
-
-
-#define __GTK_PRINT_CONTEXT_C__
-#include "gtkaliasdef.c"