Gtksourceview printing on Windows (original) (raw)

September 20, 2020, 6:58pm 1

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:

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.

ebassi (Emmanuele Bassi) September 20, 2020, 9:38pm 2

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.

cottrell (Allin Cottrell) September 20, 2020, 10:43pm 3

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.

cottrell (Allin Cottrell) September 22, 2020, 3:47pm 4

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.

system (system) Closed October 6, 2020, 4:01pm 5

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