Fix printing under Windows

For some reason the Scintilla widget's Pango context don't have a
resolution set on Windows, so we get an invalid one.  Fix this by
correctly peek the resolution from the map if the context doesn't
have one by itself.

https://developer.gnome.org/pango/stable/pango-Cairo-Rendering.html#pango-cairo-context-get-resolution

Thanks to Matthew Brush for debugging this!

Closes #961.
This commit is contained in:
Colomban Wendling 2013-08-19 14:07:27 +02:00
parent 791cad3059
commit 1fe7b4848e

View File

@ -334,6 +334,7 @@ static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context,
DocInfo *dinfo = user_data;
PangoContext *pango_ctx, *widget_pango_ctx;
PangoFontDescription *desc;
gdouble pango_res, widget_res;
if (dinfo == NULL)
return;
@ -358,9 +359,18 @@ static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context,
* Pango context out of the Cairo target, and the resolution is in the GtkPrintOperation's
* Pango context */
pango_ctx = gtk_print_context_create_pango_context(context);
widget_pango_ctx = gtk_widget_get_pango_context(GTK_WIDGET(dinfo->sci));
dinfo->sci_scale = pango_cairo_context_get_resolution(pango_ctx) / pango_cairo_context_get_resolution(widget_pango_ctx);
pango_res = pango_cairo_context_get_resolution(pango_ctx);
g_object_unref(pango_ctx);
widget_pango_ctx = gtk_widget_get_pango_context(GTK_WIDGET(dinfo->sci));
widget_res = pango_cairo_context_get_resolution(widget_ctx);
/* On Windows, for some reason the widget's resolution is -1, so follow
* Pango docs and peek the font map's one. */
if (widget_res < 0)
{
widget_res = pango_cairo_font_map_get_resolution(
(PangoCairoFontMap*) pango_context_get_font_map(widget_pango_ctx));
}
dinfo->sci_scale = pango_res / widget_res;
dinfo->pages = g_array_new(FALSE, FALSE, sizeof(gint));