From a14f3c5f994ac4ff201efd28cede0a35a1ac88bb Mon Sep 17 00:00:00 2001 From: Kevin Walzer Date: Wed, 19 May 2021 02:02:31 +0000 Subject: Canvas printing works! --- library/print.tcl | 39 +++++++++++++++++---------------------- win/tkWinGDI.c | 12 ++++++------ 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/library/print.tcl b/library/print.tcl index 2f42fcb..43095af 100644 --- a/library/print.tcl +++ b/library/print.tcl @@ -57,6 +57,7 @@ namespace eval ::tk::print { set printargs(resx) $::tk::print::dpi_x set printargs(resy) $::tk::print::dpi_y set printargs(copies) $::tk::print::copies + set printargs(resolution) [list $::tk::print::dpi_x $::tk::print::dpi_y] } @@ -239,7 +240,7 @@ namespace eval ::tk::print { variable printargs - _set_dc + _set_dc array get printargs @@ -267,22 +268,18 @@ namespace eval ::tk::print { set window_y [ winfo height $wid ] } - set pd "page dimensions" - set pm "page margins" - set ppi "pixels per inch" - - set printer_x [ expr ( $printargs(pw) - \ - $printargs(lm)- \ - $printargs(rm) \ - ) * \ + set printer_x [ expr ( $printargs(pw) - \ + $printargs(lm) - \ + $printargs(rm) \ + ) * \ $printargs(resx) / 1000.0 ] - set printer_y [ expr ( $printargs(pl) - \ - $printargs(tm) - \ - $printargs(bm) 1000 \ - ) * \ + set printer_y [ expr ( $printargs(pl) - \ + $printargs(tm) - \ + $printargs(bm) \ + ) * \ $printargs(resy) / 1000.0 ] - set factor_x [ expr $window_x / $printer_x ] - set factor_y [ expr $window_y / $printer_y ] + set factor_x [ expr $window_x / $printer_x ] + set factor_y [ expr $window_y / $printer_y ] if { $factor_x < $factor_y } { set lo $window_y @@ -292,14 +289,14 @@ namespace eval ::tk::print { set ph $printer_x } - ::tk::print::_gdi map $printargs(hDC) -logical $lo -physical $ph -offset $printargs(resx) + ::tk::print::_gdi map $printargs(hDC) -logical $lo -physical $ph -offset $printargs(resolution) # handling of canvas widgets # additional procs can be added for other widget types switch [winfo class $wid] { Canvas { # if {[catch { - _print_canvas [lindex $printargs(hDC) 0] $wid + _print_canvas $printargs(hDC) $wid # } msg]} { # debug_puts "print_widget: $msg" # error "Windows Printing Problem: $msg" @@ -415,7 +412,7 @@ namespace eval ::tk::print { variable printargs array get printargs - set color [print_canvas.TransColor [$cw itemcget $id -outline]] + set color [_print_canvas.TransColor [$cw itemcget $id -outline]] if { [string match $vtgPrint(printer.bg) $color] } { return } @@ -496,7 +493,7 @@ namespace eval ::tk::print { set fcolor [_print_canvas.TransColor [$cw itemcget $id -fill]] if {![string length $fcolor]} {set fcolor $vtgPrint(printer.bg)} - set ocolor [print_canvas.TransColor [$cw itemcget $id -outline]] + set ocolor [_print_canvas.TransColor [$cw itemcget $id -outline]] if {![string length $ocolor]} {set ocolor $vtgPrint(printer.bg)} set coords [$cw coords $id] set wdth [$cw itemcget $id -width] @@ -524,7 +521,7 @@ namespace eval ::tk::print { set fcolor [_print_canvas.TransColor [$cw itemcget $id -fill]] if {![string length $fcolor]} {set fcolor $vtgPrint(printer.bg)} - set ocolor [print_canvas.TransColor [$cw itemcget $id -outline]] + set ocolor [_print_canvas.TransColor [$cw itemcget $id -outline]] if {![string length $ocolor]} {set ocolor $vtgPrint(printer.bg)} set coords [$cw coords $id] set wdth [$cw itemcget $id -width] @@ -546,8 +543,6 @@ namespace eval ::tk::print { proc _print_canvas.text {hdc cw id} { variable vtgPrint - _set_dc - variable printargs array get printargs diff --git a/win/tkWinGDI.c b/win/tkWinGDI.c index 37b97b2..0c53112 100644 --- a/win/tkWinGDI.c +++ b/win/tkWinGDI.c @@ -1515,9 +1515,9 @@ static int GdiCharWidths( /* Now, get the widths using the correct function for font type. */ - if ( (retval = GetCharWidth32(hDC, 0, 255, widths)) == FALSE ) + if ( (retval = GetCharWidth32(hDC, 0, 255, widths)) == FALSE ) { - retval = GetCharWidth (hDC, 0, 255, widths ); + retval = GetCharWidth (hDC, 0, 255, widths ); } /* @@ -4963,10 +4963,10 @@ static int PrintSelectPrinter(ClientData clientData, Tcl_Interp *interp, int arg paper_width = (int) localDevmode->dmPaperWidth / 0.254; /* Convert to logical points.*/ copies = pd.nCopies; printDC = CreateDC( - "WINSPOOL", - printerName, - NULL, - localDevmode); + "WINSPOOL", + printerName, + NULL, + localDevmode); } else { -- cgit v0.12