Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/teraprn.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9048 - (hide annotations) (download) (as text)
Wed Dec 16 12:24:13 2020 UTC (3 years, 3 months ago) by nmaya
File MIME type: text/x-c++src
File size: 16563 byte(s)
ソースファイルの著作権表記の "最後の発行の年" を削除

ticket #40996
1 doda 6806 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3 nmaya 9048 * (C) 2007- TeraTerm Project
4 doda 6806 * All rights reserved.
5     *
6 doda 6841 * Redistribution and use in source and binary forms, with or without
7     * modification, are permitted provided that the following conditions
8     * are met:
9 doda 6806 *
10 doda 6841 * 1. Redistributions of source code must retain the above copyright
11     * notice, this list of conditions and the following disclaimer.
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the distribution.
15     * 3. The name of the author may not be used to endorse or promote products
16     * derived from this software without specific prior written permission.
17 doda 6806 *
18 doda 6841 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 doda 6806 */
29 maya 3227
30     /* TERATERM.EXE, Printing routines */
31     #include "teraterm.h"
32     #include "tttypes.h"
33     #include <commdlg.h>
34     #include <stdio.h>
35 zmatsuo 7936 #include <crtdbg.h>
36 maya 3227
37     #include "ttwinman.h"
38     #include "commlib.h"
39     #include "ttcommon.h"
40     #include "ttlib.h"
41 zmatsuo 9040 #include "vtdisp.h"
42 maya 3227
43     #include "tt_res.h"
44 zmatsuo 7528 #include "tmfc.h"
45 maya 3227 #include "prnabort.h"
46    
47     #include "teraprn.h"
48    
49 zmatsuo 7936 #ifdef _DEBUG
50     #if defined(_MSC_VER)
51     #define new ::new(_NORMAL_BLOCK, __FILE__, __LINE__)
52 maya 3227 #endif
53 zmatsuo 7936 #endif
54 maya 3227
55     static HDC PrintDC;
56     static HFONT PrnFont[AttrFontMask+1];
57     static int PrnFW, PrnFH;
58     static RECT Margin;
59     static COLORREF White, Black;
60     static int PrnX, PrnY;
61     static TCharAttr PrnAttr;
62    
63     static BOOL Printing = FALSE;
64     static BOOL PrintAbortFlag = FALSE;
65    
66     /* pass-thru printing */
67 zmatsuo 9039 static wchar_t PrnFName[MAX_PATH];
68 zmatsuo 7290 static HANDLE HPrnFile = INVALID_HANDLE_VALUE;
69 maya 3227 static char PrnBuff[TermWidthMax];
70     static int PrnBuffCount = 0;
71    
72     static CPrnAbortDlg *PrnAbortDlg;
73     static HWND HPrnAbortDlg;
74    
75 zmatsuo 9040 static void PrnSetAttr(TCharAttr Attr);
76    
77 maya 3227 /* Print Abortion Call Back Function */
78 zmatsuo 7933 static BOOL CALLBACK PrnAbortProc(HDC PDC, int Code)
79 maya 3227 {
80 maya 3392 MSG m;
81 maya 3227
82 maya 3392 while ((! PrintAbortFlag) && PeekMessage(&m, 0,0,0, PM_REMOVE))
83     if ((HPrnAbortDlg==NULL) || (! IsDialogMessage(HPrnAbortDlg, &m))) {
84     TranslateMessage(&m);
85     DispatchMessage(&m);
86     }
87 maya 3227
88 maya 3392 if (PrintAbortFlag) {
89     HPrnAbortDlg = NULL;
90     PrnAbortDlg = NULL;
91     return FALSE;
92     }
93     else {
94     return TRUE;
95     }
96 maya 3227 }
97    
98 yutakapon 8331 static UINT_PTR CALLBACK PrintHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
99     {
100     return 0;
101     }
102    
103 maya 3227 HDC PrnBox(HWND HWin, PBOOL Sel)
104     {
105 maya 3392 /* initialize PrnDlg record */
106 zmatsuo 9038 PRINTDLGW PrnDlg = {};
107     PrnDlg.lStructSize = sizeof(PrnDlg);
108 maya 3392 PrnDlg.hwndOwner = HWin;
109 yutakapon 8331 PrnDlg.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_SHOWHELP | PD_ENABLEPRINTHOOK;
110 maya 3392 if (! *Sel) {
111 yutakapon 5196 PrnDlg.Flags = PrnDlg.Flags | PD_NOSELECTION; /* when there is nothing select, gray out the "Selection" radio button */
112     } else {
113     PrnDlg.Flags = PrnDlg.Flags | PD_SELECTION; /* when there is something select, select the "Selection" radio button by default */
114 maya 3392 }
115     PrnDlg.nCopies = 1;
116 yutakapon 8331 /*
117     * Windows NT�n���������A�����_�C�A���O���w���v�{�^�����\�����������A
118     * �v���V�[�W�����t�b�N�����B
119     */
120     PrnDlg.lpfnPrintHook = PrintHookProc;
121 maya 3227
122 maya 3392 /* 'Print' dialog box */
123 zmatsuo 9038 if (! PrintDlgW(&PrnDlg)) {
124 maya 3392 return NULL; /* if 'Cancel' button clicked, exit */
125     }
126     if (PrnDlg.hDC == NULL) {
127     return NULL;
128     }
129     *Sel = (PrnDlg.Flags & PD_SELECTION) != 0;
130 zmatsuo 9038 return PrnDlg.hDC;
131 maya 3227 }
132    
133     BOOL PrnStart(LPSTR DocumentName)
134     {
135 zmatsuo 7527 DOCINFOA Doc;
136 maya 3392 char DocName[50];
137 zmatsuo 7933 HWND hParent;
138 maya 3227
139 maya 3392 Printing = FALSE;
140     PrintAbortFlag = FALSE;
141 maya 3227
142 maya 3392 PrnAbortDlg = new CPrnAbortDlg();
143     if (PrnAbortDlg==NULL) {
144     return FALSE;
145     }
146     if (ActiveWin==IdVT) {
147 zmatsuo 7933 hParent = HVTWin;
148 maya 3392 }
149     else {
150 zmatsuo 7933 hParent = HTEKWin;
151 maya 3392 }
152 zmatsuo 7933 PrnAbortDlg->Create(hInst,hParent,&PrintAbortFlag,&ts);
153 maya 3392 HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd();
154 maya 3227
155 maya 3392 SetAbortProc(PrintDC,PrnAbortProc);
156 maya 3227
157 zmatsuo 7527 Doc.cbSize = sizeof(Doc);
158 maya 3392 strncpy_s(DocName,sizeof(DocName),DocumentName,_TRUNCATE);
159     Doc.lpszDocName = DocName;
160     Doc.lpszOutput = NULL;
161     Doc.lpszDatatype = NULL;
162     Doc.fwType = 0;
163 zmatsuo 7527 if (StartDocA(PrintDC, &Doc) > 0) {
164 maya 3392 Printing = TRUE;
165     }
166     else {
167     if (PrnAbortDlg != NULL) {
168     PrnAbortDlg->DestroyWindow();
169     PrnAbortDlg = NULL;
170     HPrnAbortDlg = NULL;
171     }
172     }
173     return Printing;
174 maya 3227 }
175    
176     void PrnStop()
177     {
178 maya 3392 if (Printing) {
179     EndDoc(PrintDC);
180     DeleteDC(PrintDC);
181     Printing = FALSE;
182     }
183     if (PrnAbortDlg != NULL) {
184     PrnAbortDlg->DestroyWindow();
185     PrnAbortDlg = NULL;
186     HPrnAbortDlg = NULL;
187     }
188 maya 3227 }
189    
190     int VTPrintInit(int PrnFlag)
191     // Initialize printing of VT window
192     // PrnFlag: specifies object to be printed
193     // = IdPrnScreen Current screen
194     // = IdPrnSelectedText Selected text
195     // = IdPrnScrollRegion Scroll region
196     // = IdPrnFile Spooled file (printer sequence)
197     // Return: print object ID specified by user
198     // = IdPrnCancel (user clicks "Cancel" button)
199     // = IdPrnScreen (user don't select "print selection" option)
200     // = IdPrnSelectedText (user selects "print selection")
201     // = IdPrnScrollRegion (always when PrnFlag=IdPrnScrollRegion)
202     // = IdPrnFile (always when PrnFlag=IdPrnFile)
203 doda 6435 {
204 maya 3392 BOOL Sel;
205     TEXTMETRIC Metrics;
206     POINT PPI, PPI2;
207     HDC DC;
208 zmatsuo 9040 TCharAttr TempAttr = DefCharAttr;
209 zmatsuo 9038 LOGFONTA Prnlf;
210 maya 3227
211 maya 3392 Sel = (PrnFlag & IdPrnSelectedText)!=0;
212 zmatsuo 9038 PrintDC = PrnBox(HVTWin,&Sel);
213     if (PrintDC == NULL) {
214 maya 3392 return (IdPrnCancel);
215     }
216 maya 3227
217 maya 3392 /* start printing */
218     if (! PrnStart(ts.Title)) {
219     return (IdPrnCancel);
220     }
221 maya 3227
222 maya 3392 /* initialization */
223     StartPage(PrintDC);
224 maya 3227
225 maya 3392 /* pixels per inch */
226     if ((ts.VTPPI.x>0) && (ts.VTPPI.y>0)) {
227     PPI = ts.VTPPI;
228     }
229     else {
230     PPI.x = GetDeviceCaps(PrintDC,LOGPIXELSX);
231     PPI.y = GetDeviceCaps(PrintDC,LOGPIXELSY);
232     }
233 maya 3227
234 maya 3392 /* left margin */
235     Margin.left = (int)((float)ts.PrnMargin[0] / 100.0 * (float)PPI.x);
236     /* right margin */
237     Margin.right = GetDeviceCaps(PrintDC,HORZRES) -
238     (int)((float)ts.PrnMargin[1] / 100.0 * (float)PPI.x);
239     /* top margin */
240     Margin.top = (int)((float)ts.PrnMargin[2] / 100.0 * (float)PPI.y);
241     /* bottom margin */
242     Margin.bottom = GetDeviceCaps(PrintDC,VERTRES) -
243     (int)((float)ts.PrnMargin[3] / 100.0 * (float)PPI.y);
244 maya 3227
245 maya 3392 /* create test font */
246 zmatsuo 7527 memset(&Prnlf, 0, sizeof(Prnlf));
247 maya 3227
248 maya 3392 if (ts.PrnFont[0]==0) {
249     Prnlf.lfHeight = ts.VTFontSize.y;
250     Prnlf.lfWidth = ts.VTFontSize.x;
251     Prnlf.lfCharSet = ts.VTFontCharSet;
252     strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName), ts.VTFont, _TRUNCATE);
253     }
254     else {
255     Prnlf.lfHeight = ts.PrnFontSize.y;
256     Prnlf.lfWidth = ts.PrnFontSize.x;
257     Prnlf.lfCharSet = ts.PrnFontCharSet;
258     strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName), ts.PrnFont, _TRUNCATE);
259     }
260     Prnlf.lfWeight = FW_NORMAL;
261     Prnlf.lfItalic = 0;
262     Prnlf.lfUnderline = 0;
263     Prnlf.lfStrikeOut = 0;
264     Prnlf.lfOutPrecision = OUT_CHARACTER_PRECIS;
265     Prnlf.lfClipPrecision = CLIP_CHARACTER_PRECIS;
266     Prnlf.lfQuality = DEFAULT_QUALITY;
267     Prnlf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
268 maya 3227
269 zmatsuo 7527 PrnFont[0] = CreateFontIndirectA(&Prnlf);
270 maya 3227
271 maya 3392 DC = GetDC(HVTWin);
272     SelectObject(DC, PrnFont[0]);
273     GetTextMetrics(DC, &Metrics);
274     PPI2.x = GetDeviceCaps(DC,LOGPIXELSX);
275     PPI2.y = GetDeviceCaps(DC,LOGPIXELSY);
276     ReleaseDC(HVTWin,DC);
277     DeleteObject(PrnFont[0]); /* Delete test font */
278 maya 3227
279 maya 3392 /* Adjust font size */
280     Prnlf.lfHeight = (int)((float)Metrics.tmHeight * (float)PPI.y / (float)PPI2.y);
281     Prnlf.lfWidth = (int)((float)Metrics.tmAveCharWidth * (float)PPI.x / (float)PPI2.x);
282 maya 3227
283 maya 3392 /* Create New Fonts */
284 maya 3227
285 maya 3392 /* Normal Font */
286     Prnlf.lfWeight = FW_NORMAL;
287     Prnlf.lfUnderline = 0;
288 zmatsuo 7527 PrnFont[0] = CreateFontIndirectA(&Prnlf);
289 maya 3392 SelectObject(PrintDC,PrnFont[0]);
290     GetTextMetrics(PrintDC, &Metrics);
291     PrnFW = Metrics.tmAveCharWidth;
292     PrnFH = Metrics.tmHeight;
293     /* Under line */
294     Prnlf.lfUnderline = 1;
295 zmatsuo 7527 PrnFont[AttrUnder] = CreateFontIndirectA(&Prnlf);
296 maya 3227
297 doda 3666 if (ts.FontFlag & FF_BOLD) {
298 maya 3392 /* Bold */
299     Prnlf.lfUnderline = 0;
300     Prnlf.lfWeight = FW_BOLD;
301 zmatsuo 7527 PrnFont[AttrBold] = CreateFontIndirectA(&Prnlf);
302 maya 3392 /* Bold + Underline */
303     Prnlf.lfUnderline = 1;
304 zmatsuo 7527 PrnFont[AttrBold | AttrUnder] = CreateFontIndirectA(&Prnlf);
305 maya 3392 }
306     else {
307     PrnFont[AttrBold] = PrnFont[AttrDefault];
308     PrnFont[AttrBold | AttrUnder] = PrnFont[AttrUnder];
309     }
310     /* Special font */
311     Prnlf.lfWeight = FW_NORMAL;
312     Prnlf.lfUnderline = 0;
313     Prnlf.lfWidth = PrnFW; /* adjust width */
314     Prnlf.lfHeight = PrnFH;
315     Prnlf.lfCharSet = SYMBOL_CHARSET;
316 maya 3227
317 maya 3392 strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName),"Tera Special", _TRUNCATE);
318 zmatsuo 7527 PrnFont[AttrSpecial] = CreateFontIndirectA(&Prnlf);
319 maya 3392 PrnFont[AttrSpecial | AttrBold] = PrnFont[AttrSpecial];
320     PrnFont[AttrSpecial | AttrUnder] = PrnFont[AttrSpecial];
321     PrnFont[AttrSpecial | AttrBold | AttrUnder] = PrnFont[AttrSpecial];
322 maya 3227
323 maya 3392 Black = RGB(0,0,0);
324     White = RGB(255,255,255);
325     PrnSetAttr(TempAttr);
326 maya 3227
327 maya 3392 PrnY = Margin.top;
328     PrnX = Margin.left;
329 maya 3227
330 maya 3392 if (PrnFlag == IdPrnScrollRegion) {
331     return (IdPrnScrollRegion);
332     }
333     if (PrnFlag == IdPrnFile) {
334     return (IdPrnFile);
335     }
336     if (Sel) {
337     return (IdPrnSelectedText);
338     }
339     else {
340     return (IdPrnScreen);
341     }
342 maya 3227 }
343 zmatsuo 7291
344 zmatsuo 9040 static void PrnSetAttr(TCharAttr Attr)
345 maya 3227 // Set text attribute of printing
346     //
347     {
348 maya 3392 PrnAttr = Attr;
349     SelectObject(PrintDC, PrnFont[Attr.Attr & AttrFontMask]);
350 maya 3227
351 maya 3392 if ((Attr.Attr & AttrReverse) != 0) {
352     SetTextColor(PrintDC,White);
353     SetBkColor( PrintDC,Black);
354     }
355     else {
356     SetTextColor(PrintDC,Black);
357     SetBkColor( PrintDC,White);
358     }
359 maya 3227 }
360    
361 zmatsuo 9040 void PrnSetupDC(TCharAttr Attr, BOOL reverse)
362 maya 3227 {
363 zmatsuo 9040 (void)reverse;
364     PrnSetAttr(Attr);
365     }
366 maya 3227
367 zmatsuo 9040 /**
368     * Print out text
369     * Buff: points text buffer
370     * Count: number of characters to be printed
371     */
372     void PrnOutText(const char *StrA, int Count, void *data)
373     {
374     if (PrnX+PrnFW > Margin.right) {
375     /* new line */
376     PrnX = Margin.left;
377     PrnY = PrnY + PrnFH;
378 maya 3392 }
379 zmatsuo 9040 if (PrnY+PrnFH > Margin.bottom) {
380     /* next page */
381     EndPage(PrintDC);
382     StartPage(PrintDC);
383     PrnSetAttr(PrnAttr);
384     PrnY = Margin.top;
385 maya 3392 }
386 maya 3227
387 zmatsuo 9040 DrawStrA(PrintDC, NULL, StrA, Count, PrnFW, PrnFH, PrnY, &PrnX);
388     }
389    
390     void PrnOutTextW(const wchar_t *StrW, const char *WidthInfo, int Count, void *data)
391     {
392     if (PrnX+PrnFW > Margin.right) {
393     /* new line */
394     PrnX = Margin.left;
395     PrnY = PrnY + PrnFH;
396 maya 3392 }
397 zmatsuo 9040 if (PrnY+PrnFH > Margin.bottom) {
398     /* next page */
399     EndPage(PrintDC);
400     StartPage(PrintDC);
401     PrnSetAttr(PrnAttr);
402     PrnY = Margin.top;
403     }
404 maya 3227
405 zmatsuo 9040 DrawStrW(PrintDC, NULL, StrW, WidthInfo, Count, PrnFW, PrnFH, PrnY, &PrnX);
406 maya 3227 }
407    
408     void PrnNewLine()
409     // Moves to the next line in printing
410     {
411 maya 3392 PrnX = Margin.left;
412     PrnY = PrnY + PrnFH;
413 maya 3227 }
414    
415     void VTPrintEnd()
416     {
417 maya 3392 int i, j;
418 maya 3227
419 maya 3392 EndPage(PrintDC);
420 maya 3227
421 maya 3392 for (i = 0 ; i <= AttrFontMask ; i++) {
422     for (j = i+1 ; j <= AttrFontMask ; j++) {
423     if (PrnFont[j]==PrnFont[i]) {
424     PrnFont[j] = NULL;
425     }
426     }
427     if (PrnFont[i] != NULL) {
428     DeleteObject(PrnFont[i]);
429     }
430     }
431 maya 3227
432 maya 3392 PrnStop();
433     return;
434 maya 3227 }
435    
436     /* printer emulation routines */
437     void OpenPrnFile()
438     {
439 zmatsuo 9039 KillTimer(HVTWin, IdPrnStartTimer);
440 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
441 maya 3392 return;
442     }
443     if (PrnFName[0] == 0) {
444 zmatsuo 9039 wchar_t Temp[MAX_PATH];
445     GetTempPathW(_countof(Temp), Temp);
446     if (GetTempFileNameW(Temp, L"tmp", 0, PrnFName) == 0) {
447 maya 3392 return;
448     }
449 zmatsuo 9039 HPrnFile =
450     CreateFileW(PrnFName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
451 maya 3392 }
452     else {
453 zmatsuo 9039 HPrnFile =
454     CreateFileW(PrnFName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
455 zmatsuo 7290 if (HPrnFile == INVALID_HANDLE_VALUE) {
456 zmatsuo 9039 HPrnFile = CreateFileW(PrnFName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
457     FILE_ATTRIBUTE_NORMAL, NULL);
458 maya 3392 }
459     }
460 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
461 zmatsuo 9039 SetFilePointer(HPrnFile, 0, NULL, FILE_END);
462 maya 3392 }
463 maya 3227 }
464    
465 zmatsuo 9039 static void PrintFile(void)
466 maya 3227 {
467 maya 3392 char Buff[256];
468     BOOL CRFlag = FALSE;
469     int c, i;
470     BYTE b;
471 maya 3227
472 maya 3392 if (VTPrintInit(IdPrnFile)==IdPrnFile) {
473 zmatsuo 9039 HPrnFile = CreateFileW(PrnFName,
474     GENERIC_READ, FILE_SHARE_READ, NULL,
475     OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
476    
477 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
478 maya 3392 do {
479     i = 0;
480     do {
481 zmatsuo 9039 DWORD NumberOfBytesRead;
482     BOOL r = ReadFile(HPrnFile, &b, 1, &NumberOfBytesRead, NULL);
483     c = 0;
484     if (r) {
485     c = NumberOfBytesRead;
486     }
487     if (c == 1) {
488 maya 3392 switch (b) {
489     case HT:
490     memset(&(Buff[i]),0x20,8);
491     i = i + 8;
492     CRFlag = FALSE;
493     break;
494     case LF:
495     CRFlag = ! CRFlag;
496     break;
497     case FF:
498     case CR:
499     CRFlag = TRUE;
500     break;
501     default:
502     if (b >= 0x20) {
503     Buff[i] = b;
504     i++;
505     }
506     CRFlag = FALSE;
507     break;
508     }
509     }
510     if (i>=(sizeof(Buff)-7)) {
511     CRFlag=TRUE;
512     }
513     } while ((c>0) && (! CRFlag));
514     if (i>0) {
515 zmatsuo 9040 PrnOutText(Buff, i, NULL);
516 maya 3392 }
517     if (CRFlag) {
518     PrnX = Margin.left;
519     if ((b==FF) && (ts.PrnConvFF==0)) { // new page
520     PrnY = Margin.bottom;
521     }
522     else { // new line
523     PrnY = PrnY + PrnFH;
524     }
525     }
526     CRFlag = (b==CR);
527     } while (c>0);
528 zmatsuo 9039 CloseHandle(HPrnFile);
529 maya 3227 }
530 zmatsuo 9039 HPrnFile = INVALID_HANDLE_VALUE;
531 maya 3392 VTPrintEnd();
532 maya 3227 }
533 zmatsuo 9039 DeleteFileW(PrnFName);
534 maya 3392 PrnFName[0] = 0;
535 maya 3227 }
536    
537 zmatsuo 9039 static void PrintFileDirect(void)
538 maya 3227 {
539 zmatsuo 7933 HWND hParent;
540 maya 3227
541 maya 3392 PrnAbortDlg = new CPrnAbortDlg();
542     if (PrnAbortDlg==NULL) {
543 zmatsuo 9039 DeleteFileW(PrnFName);
544 maya 3392 PrnFName[0] = 0;
545     return;
546     }
547     if (ActiveWin==IdVT) {
548 zmatsuo 7933 hParent = HVTWin;
549 maya 3392 }
550     else {
551 zmatsuo 7933 hParent = HTEKWin;
552 maya 3392 }
553 zmatsuo 7933 PrnAbortDlg->Create(hInst,hParent,&PrintAbortFlag,&ts);
554 maya 3392 HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd();
555 maya 3227
556 zmatsuo 9039 HPrnFile = CreateFileW(PrnFName,
557     GENERIC_READ, FILE_SHARE_READ, NULL,
558     OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
559 zmatsuo 7290 PrintAbortFlag = (HPrnFile == INVALID_HANDLE_VALUE) || ! PrnOpen(ts.PrnDev);
560 maya 3392 PrnBuffCount = 0;
561     SetTimer(HVTWin,IdPrnProcTimer,0,NULL);
562 maya 3227 }
563    
564     void PrnFileDirectProc()
565     {
566 maya 3392 int c;
567 maya 3227
568 zmatsuo 7290 if (HPrnFile==INVALID_HANDLE_VALUE) {
569 maya 3392 return;
570     }
571     if (PrintAbortFlag) {
572     HPrnAbortDlg = NULL;
573     PrnAbortDlg = NULL;
574     PrnCancel();
575     }
576 zmatsuo 7290 if (!PrintAbortFlag && (HPrnFile != INVALID_HANDLE_VALUE)) {
577 maya 3392 do {
578     if (PrnBuffCount==0) {
579 zmatsuo 9039 PrnBuffCount = 0;
580     DWORD NumberOfBytesRead;
581     BOOL r = ReadFile(HPrnFile, PrnBuff, 1, &NumberOfBytesRead, NULL);
582     if (r) {
583     PrnBuffCount = NumberOfBytesRead;
584     }
585 maya 3392 if (ts.Language==IdRussian) {
586     RussConvStr(ts.RussClient,ts.RussPrint,PrnBuff,PrnBuffCount);
587     }
588     }
589 maya 3227
590 maya 3392 if (PrnBuffCount==1) {
591     c = PrnWrite(PrnBuff,1);
592     if (c==0) {
593     SetTimer(HVTWin,IdPrnProcTimer,10,NULL);
594     return;
595     }
596     PrnBuffCount = 0;
597     }
598     else {
599     c = 0;
600     }
601     } while (c>0);
602 maya 3227 }
603 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
604 zmatsuo 9039 CloseHandle(HPrnFile);
605 maya 3392 }
606 zmatsuo 7290 HPrnFile = INVALID_HANDLE_VALUE;
607 maya 3392 PrnClose();
608 zmatsuo 9039 DeleteFileW(PrnFName);
609 maya 3392 PrnFName[0] = 0;
610     if (PrnAbortDlg!=NULL) {
611     PrnAbortDlg->DestroyWindow();
612     PrnAbortDlg = NULL;
613     HPrnAbortDlg = NULL;
614     }
615 maya 3227 }
616    
617     void PrnFileStart()
618     {
619 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
620 maya 3392 return;
621     }
622     if (PrnFName[0]==0) {
623     return;
624     }
625     if (ts.PrnDev[0]!=0) {
626     PrintFileDirect(); // send file directry to printer port
627     }
628     else { // print file by using Windows API
629     PrintFile();
630     }
631 maya 3227 }
632    
633     void ClosePrnFile()
634     {
635 maya 3392 PrnBuffCount = 0;
636 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
637 zmatsuo 9039 CloseHandle(HPrnFile);
638 maya 3392 }
639 zmatsuo 7290 HPrnFile = INVALID_HANDLE_VALUE;
640 maya 3392 SetTimer(HVTWin,IdPrnStartTimer,ts.PassThruDelay*1000,NULL);
641 maya 3227 }
642    
643     void WriteToPrnFile(BYTE b, BOOL Write)
644     // (b,Write) =
645     // (0,FALSE): clear buffer
646     // (0,TRUE): write buffer to file
647     // (b,FALSE): put b in buff
648     // (b,TRUE): put b in buff and
649     // write buffer to file
650     {
651 maya 3392 if ((b>0) && (PrnBuffCount<sizeof(PrnBuff))) {
652     PrnBuff[PrnBuffCount++] = b;
653     }
654 maya 3227
655 maya 3392 if (Write) {
656 zmatsuo 9039 DWORD NumberOfBytesWritten;
657     WriteFile(HPrnFile, PrnBuff, PrnBuffCount, &NumberOfBytesWritten, NULL);
658 maya 3392 PrnBuffCount = 0;
659     }
660     if ((b==0) && ! Write) {
661     PrnBuffCount = 0;
662     }
663 maya 3227 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26