The R Project SVN R

Rev

Rev 36820 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36820 Rev 37462
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 1999, 2000  Guido Masarotto
3
 *  Copyright (C) 1999, 2000  Guido Masarotto
4
 *
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
8
 *  (at your option) any later version.
9
 *
9
 *
10
 *  This program is distributed in the hope that it will be useful,
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
13
 *  GNU General Public License for more details.
14
 *
14
 *
15
 *  You should have received a copy of the GNU General Public License
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
18
 */
18
 */
19
 
19
 
20
/* Support for printer
20
/* Support for printer
21
 *  printer newprinter()  - return a printer object - to draw to the
21
 *  printer newprinter()  - return a printer object - to draw to the
22
 *                          printer use drawto(...) and the drawXXX
22
 *                          printer use drawto(...) and the drawXXX
23
 *                          functions + nextpage(printer)
23
 *                          functions + nextpage(printer)
24
 *                          printers can be deleted by 'del(printer)'
24
 *                          printers can be deleted by 'del(printer)'
25
 */
25
 */
26
 
26
 
27
#define ENABLE_NLS 1
27
#define ENABLE_NLS 1
28
#include "../win-nls.h"
28
#include "../win-nls.h"
29
#include "internal.h"
29
#include "internal.h"
30
#include "rui.h"
30
#include "rui.h"
31
 
31
 
32
 
32
 
33
/*
33
/*
34
 *  Internal printer deletion function.
34
 *  Internal printer deletion function.
35
 */
35
 */
36
static void private_delprinter(printer obj)
36
static void private_delprinter(printer obj)
37
{
37
{
38
    HDC h = (HDC) obj->handle;
38
    HDC h = (HDC) obj->handle;
39
    if (!obj || !h || (obj->kind != PrinterObject)) return;
39
    if (!obj || !h || (obj->kind != PrinterObject)) return;
40
    EndPage(h);
40
    EndPage(h);
41
    EndDoc(h);
41
    EndDoc(h);
42
    DeleteDC(h);
42
    DeleteDC(h);
43
    Rwin_fpset();
-
 
44
    return;
43
    return;
45
}
44
}
46
 
45
 
47
/*
46
/*
48
 *  Create/return the base printer object.
47
 *  Create/return the base printer object.
49
 */
48
 */
50
static object get_printer_base(void)
49
static object get_printer_base(void)
51
{
50
{
52
    static object printer_base = NULL;
51
    static object printer_base = NULL;
53
 
52
 
54
    if (! printer_base)
53
    if (! printer_base)
55
	printer_base = new_object(BaseObject, 0, NULL);
54
	printer_base = new_object(BaseObject, 0, NULL);
56
    return printer_base;
55
    return printer_base;
57
}
56
}
58
 
57
 
59
static HDC chooseprinter()
58
static HDC chooseprinter()
60
{
59
{
61
    PRINTDLG pd;
60
    PRINTDLG pd;
62
    HDC dc;
61
    HDC dc;
63
    DWORD rc;
62
    DWORD rc;
64
    char cwd[MAX_PATH];
63
    char cwd[MAX_PATH];
65
 
64
 
66
    GetCurrentDirectory(MAX_PATH,cwd);
65
    GetCurrentDirectory(MAX_PATH,cwd);
67
 
66
 
68
    pd.lStructSize = sizeof( PRINTDLG );
67
    pd.lStructSize = sizeof( PRINTDLG );
69
    pd.hwndOwner = NULL;
68
    pd.hwndOwner = NULL;
70
    pd.hDevMode = (HANDLE)NULL;
69
    pd.hDevMode = (HANDLE)NULL;
71
    pd.hDevNames = (HANDLE)NULL;
70
    pd.hDevNames = (HANDLE)NULL;
72
    pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS |
71
    pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS |
73
	PD_USEDEVMODECOPIES;
72
	PD_USEDEVMODECOPIES;
74
    pd.nFromPage = 0;
73
    pd.nFromPage = 0;
75
    pd.nToPage = 0;
74
    pd.nToPage = 0;
76
    pd.nMinPage = 0;
75
    pd.nMinPage = 0;
77
    pd.nMaxPage = 0;
76
    pd.nMaxPage = 0;
78
    pd.nCopies = 1;
77
    pd.nCopies = 1;
79
    pd.hInstance = (HINSTANCE)NULL;
78
    pd.hInstance = (HINSTANCE)NULL;
80
    pd.lCustData = (LPARAM)0;
79
    pd.lCustData = (LPARAM)0;
81
    pd.lpfnPrintHook = 0;
80
    pd.lpfnPrintHook = 0;
82
    pd.lpfnSetupHook = 0;
81
    pd.lpfnSetupHook = 0;
83
    pd.lpPrintTemplateName = (LPCSTR) 0;
82
    pd.lpPrintTemplateName = (LPCSTR) 0;
84
    pd.lpSetupTemplateName = (LPCSTR) 0;
83
    pd.lpSetupTemplateName = (LPCSTR) 0;
85
    pd.hPrintTemplate = (HGLOBAL)0;
84
    pd.hPrintTemplate = (HGLOBAL)0;
86
    pd.hSetupTemplate = (HGLOBAL)0;
85
    pd.hSetupTemplate = (HGLOBAL)0;
87
 
86
 
88
    dc = PrintDlg( &pd ) ? pd.hDC : NULL;
87
    dc = PrintDlg( &pd ) ? pd.hDC : NULL;
89
    SetCurrentDirectory(cwd);
88
    SetCurrentDirectory(cwd);
90
    if (!dc) {
89
    if (!dc) {
91
	rc = CommDlgExtendedError(); /* 0 means user cancelled */
90
	rc = CommDlgExtendedError(); /* 0 means user cancelled */
92
	if (rc) R_ShowMessage(_("Unable to choose printer"));
91
	if (rc) R_ShowMessage(_("Unable to choose printer"));
93
    }
92
    }
94
    return dc;
93
    return dc;
95
}
94
}
96
 
95
 
97
 
96
 
98
printer newprinter(double width, double height, char *name)
97
printer newprinter(double width, double height, char *name)
99
{
98
{
100
    DOCINFO docinfo;
99
    DOCINFO docinfo;
101
    printer obj;
100
    printer obj;
102
    HDC hDC;
101
    HDC hDC;
103
    double dd,AL;
102
    double dd,AL;
104
    int ww,hh,x0,y0;
103
    int ww,hh,x0,y0;
105
 
104
 
106
    if(strlen(name)) {
105
    if(strlen(name)) {
107
	OSVERSIONINFO verinfo;
106
	OSVERSIONINFO verinfo;
108
	verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
107
	verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
109
	GetVersionEx(&verinfo);
108
	GetVersionEx(&verinfo);
110
	switch(verinfo.dwPlatformId) {
109
	switch(verinfo.dwPlatformId) {
111
	case VER_PLATFORM_WIN32_NT:
110
	case VER_PLATFORM_WIN32_NT:
112
	    hDC = CreateDC("WINSPOOL", name, NULL, NULL);
111
	    hDC = CreateDC("WINSPOOL", name, NULL, NULL);
113
	default:
112
	default:
114
	    hDC = CreateDC(NULL, name, NULL, NULL);
113
	    hDC = CreateDC(NULL, name, NULL, NULL);
115
	}
114
	}
116
    } else hDC = chooseprinter();
115
    } else hDC = chooseprinter();
117
    if ( !hDC ) return NULL;
116
    if ( !hDC ) return NULL;
118
    obj = new_object(PrinterObject, (HANDLE) hDC, get_printer_base());
117
    obj = new_object(PrinterObject, (HANDLE) hDC, get_printer_base());
119
    if ( !obj ) {
118
    if ( !obj ) {
120
	R_ShowMessage(_("Insufficient memory for new printer"));
119
	R_ShowMessage(_("Insufficient memory for new printer"));
121
	DeleteDC(hDC);
120
	DeleteDC(hDC);
122
	return NULL;
121
	return NULL;
123
    }
122
    }
124
    if ((width == 0.0) && (height == 0.0)) {
123
    if ((width == 0.0) && (height == 0.0)) {
125
	ww = GetDeviceCaps(hDC, HORZRES);
124
	ww = GetDeviceCaps(hDC, HORZRES);
126
	hh = GetDeviceCaps(hDC, VERTRES);
125
	hh = GetDeviceCaps(hDC, VERTRES);
127
    }
126
    }
128
    else {
127
    else {
129
	if (width < 0.1) width = 0.1;
128
	if (width < 0.1) width = 0.1;
130
	if (height < 0.1) height = 0.1;
129
	if (height < 0.1) height = 0.1;
131
	dd =  GetDeviceCaps(hDC, HORZSIZE) / width;
130
	dd =  GetDeviceCaps(hDC, HORZSIZE) / width;
132
	AL = (dd < 1.0) ? dd : 1.0;
131
	AL = (dd < 1.0) ? dd : 1.0;
133
	dd = GetDeviceCaps(hDC, VERTSIZE) / height;
132
	dd = GetDeviceCaps(hDC, VERTSIZE) / height;
134
	AL = (dd < AL) ? dd : AL;
133
	AL = (dd < AL) ? dd : AL;
135
	ww = (AL * width) * GetDeviceCaps(hDC, LOGPIXELSX) / 25.4;
134
	ww = (AL * width) * GetDeviceCaps(hDC, LOGPIXELSX) / 25.4;
136
	hh = (AL * height) * GetDeviceCaps(hDC, LOGPIXELSY) / 25.4;
135
	hh = (AL * height) * GetDeviceCaps(hDC, LOGPIXELSY) / 25.4;
137
    }
136
    }
138
    x0 = (GetDeviceCaps(hDC, HORZRES) - ww) / 2;
137
    x0 = (GetDeviceCaps(hDC, HORZRES) - ww) / 2;
139
    y0 = (GetDeviceCaps(hDC, VERTRES) - hh) / 2;
138
    y0 = (GetDeviceCaps(hDC, VERTRES) - hh) / 2;
140
    obj->rect = rect(x0, y0, ww, hh);
139
    obj->rect = rect(x0, y0, ww, hh);
141
    obj->depth = GetDeviceCaps(hDC, BITSPIXEL)* GetDeviceCaps(hDC, PLANES);
140
    obj->depth = GetDeviceCaps(hDC, BITSPIXEL)* GetDeviceCaps(hDC, PLANES);
142
    obj->die = private_delprinter;
141
    obj->die = private_delprinter;
143
    obj->drawstate = copydrawstate();
142
    obj->drawstate = copydrawstate();
144
    obj->drawstate->dest = obj;
143
    obj->drawstate->dest = obj;
145
 
144
 
146
    docinfo.cbSize = sizeof(DOCINFO);	/* set this size... */
145
    docinfo.cbSize = sizeof(DOCINFO);	/* set this size... */
147
    docinfo.lpszDocName = "GraphAppPrintJob";
146
    docinfo.lpszDocName = "GraphAppPrintJob";
148
    docinfo.lpszOutput = 0;		/* no file output... */
147
    docinfo.lpszOutput = 0;		/* no file output... */
149
    docinfo.lpszDatatype = 0;
148
    docinfo.lpszDatatype = 0;
150
    docinfo.fwType = 0;
149
    docinfo.fwType = 0;
151
 
150
 
152
    if (StartDoc(hDC, &docinfo) <= 0) {
151
    if (StartDoc(hDC, &docinfo) <= 0) {
153
	R_ShowMessage(_("Unable to start the print job"));
152
	R_ShowMessage(_("Unable to start the print job"));
154
	del(obj);
153
	del(obj);
155
	return NULL;
154
	return NULL;
156
    }
155
    }
157
 
156
 
158
    StartPage(hDC);
157
    StartPage(hDC);
159
    Rwin_fpset();
-
 
160
    return obj;
158
    return obj;
161
}
159
}
162
 
160
 
163
 
161
 
164
void nextpage(printer p)
162
void nextpage(printer p)
165
{
163
{
166
    if (!p || (p->kind != PrinterObject)) return;
164
    if (!p || (p->kind != PrinterObject)) return;
167
    EndPage((HDC) p->handle);
165
    EndPage((HDC) p->handle);
168
    StartPage((HDC) p->handle);
166
    StartPage((HDC) p->handle);
169
    Rwin_fpset();
-
 
170
}
167
}