Gtksourceview printing on Windows

I’m having trouble getting gtksourceview printing working on
Windows. This is using gtk 2.14.2 and gtksourceview 2.10.5 on Windows
10 (but I had the same problem with earlier Windows releases).

A one-page script prints fine on Linux but on Windows it takes several
pages, with a few short (mostly one-word) lines at the top left corner
of each page.

I’ve tracked down the problem (I think) but have not managed to solve
it yet. Via a bunch of debugging statements in the “begin_print”
callback for GtkPrintOperation I’ve found that these points are
exactly the same on Linux and Windows:

  • via GtkPrintSettings (gtk_print_operation_get_print_settings): the
    x and y resolutions are both 300.

  • via GtkPageSetup (gtk_print_context_get_page_setup): the paper width
    and height are 8.5 x 11 inches or 612 x 792 points.

But here’s the difference (via GtkPrintContext):

On Linux the context dimensions are x=576, y=733.68, with 72 dpi in
both dimensions. On Windows the context dimensions are x=4800, y=6114
with 600 dpi in both dimensions.

If on Windows the cairo context is 4800 x 6114 but the page is 612 x
792 it “makes sense” that only a small fragment of text can be shown
on each printed page. But why is the context 8.33 (600/72) times
bigger than it should be?

Thanks for any suggestions.

You’re using GTK 2.14? A release from 12 years ago, from a branch that has been declared in deep maintenance mode for nearly 10 years? GtkSourceView 2.10 is also 9 years old.

Have you tried using GTK 2.24, at least?

It could also be a Cairo issue, considering that we’re creating Cairo surfaces to print on.

Sorry, gtk 2.14 was a typo; I’m using 2.24.2. And GtkSourceView 2.10 is (I take it) “latest stable” compatible with gtk2. But I agree, it could be a Cairo issue and I’ll investigate that.

Updating to current Cairo didn’t help, but for the record I finally found a fix: specify

gtk_print_operation_set_unit(operation, GTK_UNIT_POINTS);

This isn’t needed on Linux or macOS but it makes all the difference on Windows.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.