RE: GtkPrintOperation and margins

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Just in case anyone wants to crib that code to correct the GTK print margins
in Windows, note that there was a typo in it as I posted it. The first
PHYSICALOFFSETY should be PHYSICALOFFSETX. Sorry.

> -----Original Message-----
> From: gtk-list-bounces@xxxxxxxxx [mailto:gtk-list-bounces@xxxxxxxxx] On
> Behalf Of Ian Puleston
> Sent: Thursday, November 30, 2006 10:50 AM
> 
> I added the function below into my code, called from the begin-print
> handler, to correct the margins in Windows, and with this they print at
> exactly 1" as they should
> 
> /*
>  * Sets the print margins.
>  *
>  * In Windows this needs to be called after the printer has been selected
>  *
>  * Margins are in inches
>  */
> void
> setPrintMargins(GtkPrintOperation *operation, gdouble topMargin,
>                 gdouble btmMargin, gdouble leftMargin)
> {
>     GtkPageSetup        *pageSetup;
> 
> #ifdef _WIN32
>     gdouble             offset_x, offset_y;
>     POINT               pt;
>     HDC                 hDc;
>     GtkPrintSettings    *settings;
>     const gchar         *printerName;
> 
>     settings = gtk_print_operation_get_print_settings(operation);
>     printerName = gtk_print_settings_get_printer(settings);
> 
>     hDc = CreateDC("WINSPOOL", printerName, NULL, NULL);
>     if (hDc)
>     {
>         pt.x = GetDeviceCaps(hDc, PHYSICALOFFSETY);
>         pt.y = GetDeviceCaps(hDc, PHYSICALOFFSETY);
>         /* Convert Windows logical units -> pixels and then -> inches */
>         LPtoDP(hDc, &pt, 1);
>         offset_x = (gdouble)pt.x / (gdouble)GetDeviceCaps(hDc,
> LOGPIXELSX);
>         offset_y = (gdouble)pt.y / (gdouble)GetDeviceCaps(hDc,
> LOGPIXELSY);
> 
>         topMargin -= offset_y;
>         leftMargin -= offset_x;
>         btmMargin -= offset_y;
>     }
> #endif
> 
>     /* Set the margins */
>     pageSetup = gtk_page_setup_new();
>     gtk_page_setup_set_top_margin(pageSetup, topMargin, GTK_UNIT_INCH);
>     gtk_page_setup_set_left_margin(pageSetup, leftMargin, GTK_UNIT_INCH);
>     gtk_page_setup_set_bottom_margin(pageSetup, btmMargin, GTK_UNIT_INCH);
>     gtk_print_operation_set_default_page_setup(operation, pageSetup);
> }
> 
> 
> 
> _______________________________________________
> gtk-list mailing list
> gtk-list@xxxxxxxxx
> http://mail.gnome.org/mailman/listinfo/gtk-list



_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux