RE: GtkPrintOperation and margins



> I wrote:
> in its Win32 port ... I set the top and left margins to one inch ...
> but the text is printed with top and left margins that are about one
> and a quarter inches.

OK, I tried this in Linux too now. Better, but not quite. I get exactly 1
inch margin on the left, but something like 3/4 inch at the top of the page.

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 (but the top margin is still too small in Linux).
But I should not need to do this correction - it should be handled by the
GtkPrintOperation;

I will put in bug reports on both these (Windows and Linux) problems.



/*
 * 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);
}






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