From 6cbd586d1439b7189e3349533ded31de37a2da43 Mon Sep 17 00:00:00 2001 From: William Joye Date: Mon, 27 Mar 2017 11:59:05 -0400 Subject: macosx print --- ds9/library/macosx.tcl | 70 +++++++++++++++++++++++++--------------------- ds9/library/mfile.tcl | 38 ++++++++++++++----------- ds9/library/plotdialog.tcl | 7 ++--- tkmacosx/macosxlib.M | 36 ++++++++++++++++++++++++ tkmacosx/tkmacosx.M | 57 ++++++++++++++++++++++++++++++++++--- tkmacosx/tkmacosx.h | 14 +++++++++- 6 files changed, 165 insertions(+), 57 deletions(-) diff --git a/ds9/library/macosx.tcl b/ds9/library/macosx.tcl index 782f11d..4f45ccc 100644 --- a/ds9/library/macosx.tcl +++ b/ds9/library/macosx.tcl @@ -46,37 +46,43 @@ proc MacOSXGetLocale {} { return [macosx locale] } -#proc MacOSXPrint {} { -# global ds9 -# +proc MacOSXPrint {} { + global ds9 + # we need to be realized -# RealizeDS9 + RealizeDS9 # need the colorbar levels updated -# UpdateColormapLevel -# -# if {[macosx pm print begin [winfo width $ds9(canvas)] [winfo height $ds9(canvas)] yes]} { -# foreach f $ds9(frames) { -# $f macosx print -# } -# colorbar macosx print -# colorbarrgb macosx print -# macosx pm print end -# } -#} - -#proc MacOSXPrintPre {} { -# global ds9 - -# if {[macosx pm print begin [winfo width $ds9(canvas)] [winfo height $ds9(canvas)] no]} { -# foreach f $ds9(frames) { -# $f macosx print -# } -# colorbar macosx print -# colorbarrgb macosx print -# macosx pm print end -# } -#} - -#proc MacOSXPageSetup {} { -# macosx pm pagesetup -#} + UpdateColormapLevel + + if {[catch {macosx pm print begin [winfo width $ds9(canvas)] [winfo height $ds9(canvas)] yes}]} { + Error "bad" + } else { + Info "good" + } + + if {0} { + foreach f $ds9(frames) { + $f macosx print + } + colorbar macosx print + colorbarrgb macosx print + macosx pm print end + } +} + +proc MacOSXPrintPre {} { + global ds9 + + if {[macosx pm print begin [winfo width $ds9(canvas)] [winfo height $ds9(canvas)] no]} { + foreach f $ds9(frames) { + $f macosx print + } + colorbar macosx print + colorbarrgb macosx print + macosx pm print end + } +} + +proc MacOSXPageSetup {} { + macosx pm pagesetup +} diff --git a/ds9/library/mfile.tcl b/ds9/library/mfile.tcl index 83f0629..0f8c949 100644 --- a/ds9/library/mfile.tcl +++ b/ds9/library/mfile.tcl @@ -60,15 +60,19 @@ proc FileMainMenu {} { } aqua { # accelerators don't work with dialog box - $ds9(mb).file add command -label "[msgcat::mc {Page Setup}]..." \ + $ds9(mb).file add command \ + -label "[msgcat::mc {Postscript Page Setup}]..." \ -command PSPageSetup - $ds9(mb).file add command -label "[msgcat::mc {Print}]..." \ + $ds9(mb).file add command \ + -label "[msgcat::mc {Postscript Print}]..." \ -command PSPrint -# $ds9(mb).file add command -label "[msgcat::mc {Postscript Page Setup}]..." -command PSPageSetup -# $ds9(mb).file add command -label "[msgcat::mc {Postscript Print}]..." -command PSPrint -# $ds9(mb).file add separator -# $ds9(mb).file add command -label "[msgcat::mc {Page Setup}]..." -command MacOSXPageSetup -# $ds9(mb).file add command -label "[msgcat::mc {Print}]..." -command MacOSXPrint + $ds9(mb).file add separator + $ds9(mb).file add command \ + -label "[msgcat::mc {Page Setup}]..." \ + -command MacOSXPageSetup + $ds9(mb).file add command \ + -label "[msgcat::mc {Print}]..." \ + -command MacOSXPrint } } switch $ds9(wm) { @@ -367,11 +371,9 @@ proc CreateButtonsFile {} { } aqua { ButtonButton $ds9(buttons).file.page \ - [string tolower [msgcat::mc {Page Setup}]] PSPageSetup + [string tolower [msgcat::mc {Page Setup}]] MacOSXPageSetup ButtonButton $ds9(buttons).file.print \ - [string tolower [msgcat::mc {Print}]] PSPrint -# ButtonButton $ds9(buttons).file.page [string tolower [msgcat::mc {Page Setup}]] MacOSXPageSetup -# ButtonButton $ds9(buttons).file.print [string tolower [msgcat::mc {Print}]] MacOSXPrint + [string tolower [msgcat::mc {Print}]] MacOSXPrint } } @@ -446,6 +448,15 @@ proc PrefsDialogButtonbarFile {f} { } aqua { $m add checkbutton \ + -label "[msgcat::mc {Postscript Page Setup}]..." \ + -variable pbuttons(file,pspage) \ + -command {UpdateButtons buttons(file)} + $m add checkbutton \ + -label "[msgcat::mc {Postscript Print}]..." \ + -variable pbuttons(file,psprint) \ + -command {UpdateButtons buttons(file)} + $m add separator + $m add checkbutton \ -label "[msgcat::mc {Page Setup}]..." \ -variable pbuttons(file,page) \ -command {UpdateButtons buttons(file)} @@ -453,11 +464,6 @@ proc PrefsDialogButtonbarFile {f} { -label "[msgcat::mc {Print}]..." \ -variable pbuttons(file,print) \ -command {UpdateButtons buttons(file)} -# $m add checkbutton -label "[msgcat::mc {Postscript Page Setup}]..." -variable pbuttons(file,pspage) -command {UpdateButtons buttons(file)} -# $m add checkbutton -label "[msgcat::mc {Postscript Print}]..." -variable pbuttons(file,psprint) -command {UpdateButtons buttons(file)} -# $m add separator -# $m add checkbutton -label "[msgcat::mc {Page Setup}]..." -variable pbuttons(file,page) -command {UpdateButtons buttons(file)} -# $m add checkbutton -label "[msgcat::mc {Print}]..." -variable pbuttons(file,print) -command {UpdateButtons buttons(file)} } } diff --git a/ds9/library/plotdialog.tcl b/ds9/library/plotdialog.tcl index 8c6fccb..e45482e 100644 --- a/ds9/library/plotdialog.tcl +++ b/ds9/library/plotdialog.tcl @@ -86,12 +86,11 @@ proc PlotDialog {varname wtt title xaxis yaxis} { } aqua { $var(mb).file add command \ - -label "[msgcat::mc {Page Setup}]..." \ + -label "[msgcat::mc {Postscript Page Setup}]..." \ -command PSPageSetup - $var(mb).file add command -label "[msgcat::mc {Print}]..." \ + $var(mb).file add command \ + -label "[msgcat::mc {Postscript Print}]..." \ -command [list PlotPSPrint $varname] -# $var(mb).file add command -label "[msgcat::mc {Postscript Page Setup}]..." -command PSPageSetup -# $var(mb).file add command -label "[msgcat::mc {Postscript Print}]..." -command [list PlotPSPrint $varname] } } $var(mb).file add separator diff --git a/tkmacosx/macosxlib.M b/tkmacosx/macosxlib.M index 65e51a8..37b5e44 100644 --- a/tkmacosx/macosxlib.M +++ b/tkmacosx/macosxlib.M @@ -7,18 +7,23 @@ void macosxBegin() { + /* if (tkmacosx) tkmacosx->begin(); + */ } void macosxEnd() { + /* if (tkmacosx) tkmacosx->end(); + */ } void macosxColor(XColor* clr) { + /* if (clr) { float red = clr->red/float(USHRT_MAX); float green = clr->green/float(USHRT_MAX); @@ -27,67 +32,85 @@ void macosxColor(XColor* clr) if (tkmacosx) tkmacosx->color(red,green,blue); } + */ } void macosxWidth(float ww) { + /* if (tkmacosx) tkmacosx->width(ww); + */ } void macosxDash(float* d, int n) { + /* if (tkmacosx) tkmacosx->dash(d,n); + */ } void macosxFont(const char* f, float s) { + /* if (tkmacosx) tkmacosx->font(f,s); + */ } void macosxClip(Vector v, Vector s) { + /* if (tkmacosx) { Vector vv1 = v*tkmacosx->getCanvasToPage(); Vector vv2 = (v+s)*tkmacosx->getCanvasToPage(); Vector ss = vv2-vv1; tkmacosx->clip(vv1[0],vv1[1],ss[0],ss[1]); } + */ } void macosxNewPath() { + /* if (tkmacosx) { tkmacosx->newpath(); } + */ } void macosxStroke() { + /* if (tkmacosx) { tkmacosx->stroke(); } + */ } void macosxFill() { + /* if (tkmacosx) { tkmacosx->fill(); } + */ } void macosxArc(Vector v, float rad, float ang1, float ang2) { + /* if (tkmacosx) { Vector vv = v*tkmacosx->getCanvasToPage(); tkmacosx->arc(vv[0], vv[1], rad, ang1, ang2); } + */ } void macosxCurve(Vector v0, Vector t0, Vector t1, Vector v1) { + /* if (tkmacosx) { Vector vv0 = v0*tkmacosx->getCanvasToPage(); Vector tt0 = t0*tkmacosx->getCanvasToPage(); @@ -97,18 +120,22 @@ void macosxCurve(Vector v0, Vector t0, Vector t1, Vector v1) tkmacosx->curve(vv0[0], vv0[1], tt0[0], tt0[1], tt1[0], tt1[1], vv1[0], vv1[1]); } + */ } void macosxDrawText(Vector v, float ang, const char* text) { + /* if (tkmacosx) { Vector vv = v*tkmacosx->getCanvasToPage(); tkmacosx->drawText(vv[0], vv[1], ang, text); } + */ } void macosxDrawLine(Vector v0, Vector v1) { + /* if (tkmacosx) { Vector vv0 = v0*tkmacosx->getCanvasToPage(); Vector vv1 = v1*tkmacosx->getCanvasToPage(); @@ -124,10 +151,12 @@ void macosxDrawLine(Vector v0, Vector v1) tkmacosx->drawLines(x,y,n); } + */ } void macosxDrawLines(Vector* v, int n) { + /* if (tkmacosx) { float xx[n]; float yy[n]; @@ -141,10 +170,12 @@ void macosxDrawLines(Vector* v, int n) tkmacosx->drawLines(xx,yy,n); } + */ } void macosxFillPolygon(Vector* v, int n) { + /* if (tkmacosx) { float xx[n]; float yy[n]; @@ -158,23 +189,28 @@ void macosxFillPolygon(Vector* v, int n) tkmacosx->fillPolygon(xx,yy,n); } + */ } void macosxDrawArc(Vector v, float rad, float ang1, float ang2) { + /* if (tkmacosx) { Vector vv = v*tkmacosx->getCanvasToPage(); tkmacosx->drawArc(vv[0], vv[1], rad, ang1, ang2); } + */ } void macosxBitmapCreate(void* img, int width, int height, const Vector& v, const Vector& s) { + /* if (tkmacosx) { Vector vv1 = v*tkmacosx->getCanvasToPage(); Vector vv2 = (v+s)*tkmacosx->getCanvasToPage(); Vector ss = vv2-vv1; tkmacosx->bitmapCreate(img, width, height, vv1[0], vv1[1], ss[0], ss[1]); } + */ } diff --git a/tkmacosx/tkmacosx.M b/tkmacosx/tkmacosx.M index 5f44984..585d33d 100644 --- a/tkmacosx/tkmacosx.M +++ b/tkmacosx/tkmacosx.M @@ -13,7 +13,7 @@ using namespace std; extern "C" { int Tkmacosx_Init(Tcl_Interp* interp); int TkmacosxCmd(ClientData data, Tcl_Interp *interp, int argc, - const char* argv[]); + const char* argv[]); } TkMacosx* tkmacosx=NULL; @@ -42,8 +42,7 @@ int TkmacosxCmd(ClientData data,Tcl_Interp *interp,int argc,const char* argv[]) if (argc>=2) { if (!strncmp(argv[1], "pm", 2)) return tkmacosx->pm(argc, argv); - - if (!strncmp(argv[1], "locale", 2)) + else if (!strncmp(argv[1], "locale", 2)) return tkmacosx->locale(argc, argv); else { Tcl_AppendResult(interp, "macosx: unknown command: ", argv[1], NULL); @@ -61,22 +60,26 @@ int TkmacosxCmd(ClientData data,Tcl_Interp *interp,int argc,const char* argv[]) TkMacosx::TkMacosx(Tcl_Interp* intp) { interp = intp; + pmView = NULL; + /* showDialog = 0; - status = noErr; pageFormat = kPMNoPageFormat; printSettings = kPMNoPrintSettings; printSession = NULL; context = NULL; + */ } TkMacosx::~TkMacosx() { + /* if (pageFormat != kPMNoPageFormat) PMRelease(pageFormat); if (printSettings != kPMNoPrintSettings) PMRelease(printSettings); + */ } // Locale @@ -149,8 +152,40 @@ int TkMacosx::pmPrint(int argc, const char* argv[]) return TCL_OK; } +@implementation PMView +- (PMView*)init +{ + self = [super init]; + return self; +} + +- (void)alloc +{ +} + +- (void)dealloc +{ + [super dealloc]; +} + +- (void)drawRect: (NSRect)rect +{ +} +@end + int TkMacosx::pmPrintBegin(int argc, const char* argv[]) { + pmView = [[PMView alloc] init]; + NSPrintInfo* printInfo = [NSPrintInfo sharedPrintInfo]; + NSPrintOperation* printOp = \ + [NSPrintOperation printOperationWithView:pmView printInfo:printInfo]; + // [printOp setCanSpawnSeparateThread:YES]; + NSGraphicsContext* context = [printOp createContext]; + + [printOp runOperation]; + return TCL_OK; + + /* // canvas width and height double width =0; double height =0; @@ -349,10 +384,13 @@ int TkMacosx::pmPrintBegin(int argc, const char* argv[]) error: cerr << "PM Error Code: " << status << endl; return TCL_ERROR; + */ + return TCL_OK; } int TkMacosx::pmPrintEnd() { + /* // status = PMSessionEndPage(printSession); if (status != noErr) goto error; @@ -373,10 +411,14 @@ int TkMacosx::pmPrintEnd() PMRelease(printSession); printSession = NULL; return TCL_ERROR; + */ + + return TCL_OK; } int TkMacosx::pmPrintText(int argc, const char* argv[]) { + /* const int fontSize =12; const float margin =36; @@ -641,10 +683,14 @@ int TkMacosx::pmPrintText(int argc, const char* argv[]) delete sstr; return TCL_ERROR; + */ + + return TCL_OK; } int TkMacosx::pmPageSetup() { + /* // print session status = PMCreateSession(&printSession); if (status != noErr) @@ -683,6 +729,9 @@ int TkMacosx::pmPageSetup() PMRelease(printSession); printSession = NULL; return TCL_ERROR; + */ + + return TCL_OK; } // drawing routines diff --git a/tkmacosx/tkmacosx.h b/tkmacosx/tkmacosx.h index 3c4d6a2..853b3ba 100644 --- a/tkmacosx/tkmacosx.h +++ b/tkmacosx/tkmacosx.h @@ -9,19 +9,31 @@ #include +@interface PMView : NSView +{ +} +- (PMView*)init; +- (void)alloc; +- (void)dealloc; +- (void)drawRect: (NSRect)rect; +@end + class TkMacosx { private: Tcl_Interp* interp; - int showDialog; Matrix canvasToPage; + PMView* pmView; + /* + int showDialog; CGContextRef context; OSStatus status; PMPageFormat pageFormat; PMPrintSettings printSettings; PMPrintSession printSession; + */ int pmPrint(int, const char**); int pmPrintBegin(int, const char**); -- cgit v0.12