#include "config.h"
#include "gtkprintoperation-private.h"
-#include "gtkalias.h"
typedef struct _GtkPrintContextClass GtkPrintContextClass;
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
{
GtkPrintContext *context = GTK_PRINT_CONTEXT (object);
- g_object_unref (context->fontmap);
if (context->page_setup)
g_object_unref (context->page_setup);
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,
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);
}
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:
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;
}
* 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
*
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
{
g_return_val_if_fail (GTK_IS_PRINT_CONTEXT (context), NULL);
- return context->fontmap;
+ return _gtk_print_context_get_fontmap (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;
}
return layout;
}
-
-
-#define __GTK_PRINT_CONTEXT_C__
-#include "gtkaliasdef.c"