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 7528 - (hide annotations) (download) (as text)
Thu Mar 28 16:38:54 2019 UTC (5 years ago) by zmatsuo
File MIME type: text/x-c++src
File size: 15997 byte(s)
vtwin,teratermでMFCを使用しないようにした
1 doda 6806 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3     * (C) 2007-2017 TeraTerm Project
4     * 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    
36     #include "ttwinman.h"
37     #include "commlib.h"
38     #include "ttcommon.h"
39     #include "ttlib.h"
40 zmatsuo 7290 #include "win16api.h"
41 maya 3227
42     #include "tt_res.h"
43 zmatsuo 7528 #include "tmfc.h"
44 maya 3227 #include "prnabort.h"
45    
46     #include "teraprn.h"
47    
48 zmatsuo 7527 #if 0 //def _DEBUG
49 maya 3227 #define new DEBUG_NEW
50     #undef THIS_FILE
51     static char THIS_FILE[] = __FILE__;
52     #endif
53    
54 zmatsuo 7528 #define CWnd TTCWnd
55 zmatsuo 7527
56 maya 3227 static PRINTDLG PrnDlg;
57    
58     static HDC PrintDC;
59 zmatsuo 7527 static LOGFONTA Prnlf;
60 maya 3227 static HFONT PrnFont[AttrFontMask+1];
61     static int PrnFW, PrnFH;
62     static RECT Margin;
63     static COLORREF White, Black;
64     static int PrnX, PrnY;
65     static int PrnDx[256];
66     static TCharAttr PrnAttr;
67    
68     static BOOL Printing = FALSE;
69     static BOOL PrintAbortFlag = FALSE;
70    
71     /* pass-thru printing */
72 maya 4031 static char PrnFName[MAX_PATH];
73 zmatsuo 7290 static HANDLE HPrnFile = INVALID_HANDLE_VALUE;
74 maya 3227 static char PrnBuff[TermWidthMax];
75     static int PrnBuffCount = 0;
76    
77     static CPrnAbortDlg *PrnAbortDlg;
78     static HWND HPrnAbortDlg;
79    
80     /* Print Abortion Call Back Function */
81     BOOL CALLBACK PrnAbortProc(HDC PDC, int Code)
82     {
83 maya 3392 MSG m;
84 maya 3227
85 maya 3392 while ((! PrintAbortFlag) && PeekMessage(&m, 0,0,0, PM_REMOVE))
86     if ((HPrnAbortDlg==NULL) || (! IsDialogMessage(HPrnAbortDlg, &m))) {
87     TranslateMessage(&m);
88     DispatchMessage(&m);
89     }
90 maya 3227
91 maya 3392 if (PrintAbortFlag) {
92     HPrnAbortDlg = NULL;
93     PrnAbortDlg = NULL;
94     return FALSE;
95     }
96     else {
97     return TRUE;
98     }
99 maya 3227 }
100    
101     HDC PrnBox(HWND HWin, PBOOL Sel)
102     {
103 maya 3392 /* initialize PrnDlg record */
104     memset(&PrnDlg, 0, sizeof(PRINTDLG));
105     PrnDlg.lStructSize = sizeof(PRINTDLG);
106     PrnDlg.hwndOwner = HWin;
107     PrnDlg.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_SHOWHELP;
108     if (! *Sel) {
109 yutakapon 5196 PrnDlg.Flags = PrnDlg.Flags | PD_NOSELECTION; /* when there is nothing select, gray out the "Selection" radio button */
110     } else {
111     PrnDlg.Flags = PrnDlg.Flags | PD_SELECTION; /* when there is something select, select the "Selection" radio button by default */
112 maya 3392 }
113     PrnDlg.nCopies = 1;
114 maya 3227
115 maya 3392 /* 'Print' dialog box */
116     if (! PrintDlg(&PrnDlg)) {
117     return NULL; /* if 'Cancel' button clicked, exit */
118     }
119     if (PrnDlg.hDC == NULL) {
120     return NULL;
121     }
122     PrintDC = PrnDlg.hDC;
123     *Sel = (PrnDlg.Flags & PD_SELECTION) != 0;
124     return PrintDC;
125 maya 3227 }
126    
127     BOOL PrnStart(LPSTR DocumentName)
128     {
129 zmatsuo 7527 DOCINFOA Doc;
130 maya 3392 char DocName[50];
131     CWnd* pParent;
132 maya 3227
133 maya 3392 Printing = FALSE;
134     PrintAbortFlag = FALSE;
135 maya 3227
136 maya 3392 PrnAbortDlg = new CPrnAbortDlg();
137     if (PrnAbortDlg==NULL) {
138     return FALSE;
139     }
140     if (ActiveWin==IdVT) {
141     pParent = (CWnd*)pVTWin;
142     }
143     else {
144     pParent = (CWnd*)pTEKWin;
145     }
146 zmatsuo 7174 PrnAbortDlg->Create(hInst, pParent->GetSafeHwnd(),&PrintAbortFlag,&ts);
147 maya 3392 HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd();
148 maya 3227
149 maya 3392 SetAbortProc(PrintDC,PrnAbortProc);
150 maya 3227
151 zmatsuo 7527 Doc.cbSize = sizeof(Doc);
152 maya 3392 strncpy_s(DocName,sizeof(DocName),DocumentName,_TRUNCATE);
153     Doc.lpszDocName = DocName;
154     Doc.lpszOutput = NULL;
155     Doc.lpszDatatype = NULL;
156     Doc.fwType = 0;
157 zmatsuo 7527 if (StartDocA(PrintDC, &Doc) > 0) {
158 maya 3392 Printing = TRUE;
159     }
160     else {
161     if (PrnAbortDlg != NULL) {
162     PrnAbortDlg->DestroyWindow();
163     PrnAbortDlg = NULL;
164     HPrnAbortDlg = NULL;
165     }
166     }
167     return Printing;
168 maya 3227 }
169    
170     void PrnStop()
171     {
172 maya 3392 if (Printing) {
173     EndDoc(PrintDC);
174     DeleteDC(PrintDC);
175     Printing = FALSE;
176     }
177     if (PrnAbortDlg != NULL) {
178     PrnAbortDlg->DestroyWindow();
179     PrnAbortDlg = NULL;
180     HPrnAbortDlg = NULL;
181     }
182 maya 3227 }
183    
184     int VTPrintInit(int PrnFlag)
185     // Initialize printing of VT window
186     // PrnFlag: specifies object to be printed
187     // = IdPrnScreen Current screen
188     // = IdPrnSelectedText Selected text
189     // = IdPrnScrollRegion Scroll region
190     // = IdPrnFile Spooled file (printer sequence)
191     // Return: print object ID specified by user
192     // = IdPrnCancel (user clicks "Cancel" button)
193     // = IdPrnScreen (user don't select "print selection" option)
194     // = IdPrnSelectedText (user selects "print selection")
195     // = IdPrnScrollRegion (always when PrnFlag=IdPrnScrollRegion)
196     // = IdPrnFile (always when PrnFlag=IdPrnFile)
197 doda 6435 {
198 maya 3392 BOOL Sel;
199     TEXTMETRIC Metrics;
200     POINT PPI, PPI2;
201     HDC DC;
202     int i;
203     TCharAttr TempAttr = {
204     AttrDefault,
205     AttrDefault,
206     AttrDefaultFG,
207     AttrDefaultBG
208     };
209 maya 3227
210 maya 3392 Sel = (PrnFlag & IdPrnSelectedText)!=0;
211     if (PrnBox(HVTWin,&Sel)==NULL) {
212     return (IdPrnCancel);
213     }
214 maya 3227
215 maya 3392 if (PrintDC==0) {
216     return (IdPrnCancel);
217     }
218 maya 3227
219 maya 3392 /* start printing */
220     if (! PrnStart(ts.Title)) {
221     return (IdPrnCancel);
222     }
223 maya 3227
224 maya 3392 /* initialization */
225     StartPage(PrintDC);
226 maya 3227
227 maya 3392 /* pixels per inch */
228     if ((ts.VTPPI.x>0) && (ts.VTPPI.y>0)) {
229     PPI = ts.VTPPI;
230     }
231     else {
232     PPI.x = GetDeviceCaps(PrintDC,LOGPIXELSX);
233     PPI.y = GetDeviceCaps(PrintDC,LOGPIXELSY);
234     }
235 maya 3227
236 maya 3392 /* left margin */
237     Margin.left = (int)((float)ts.PrnMargin[0] / 100.0 * (float)PPI.x);
238     /* right margin */
239     Margin.right = GetDeviceCaps(PrintDC,HORZRES) -
240     (int)((float)ts.PrnMargin[1] / 100.0 * (float)PPI.x);
241     /* top margin */
242     Margin.top = (int)((float)ts.PrnMargin[2] / 100.0 * (float)PPI.y);
243     /* bottom margin */
244     Margin.bottom = GetDeviceCaps(PrintDC,VERTRES) -
245     (int)((float)ts.PrnMargin[3] / 100.0 * (float)PPI.y);
246 maya 3227
247 maya 3392 /* create test font */
248 zmatsuo 7527 memset(&Prnlf, 0, sizeof(Prnlf));
249 maya 3227
250 maya 3392 if (ts.PrnFont[0]==0) {
251     Prnlf.lfHeight = ts.VTFontSize.y;
252     Prnlf.lfWidth = ts.VTFontSize.x;
253     Prnlf.lfCharSet = ts.VTFontCharSet;
254     strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName), ts.VTFont, _TRUNCATE);
255     }
256     else {
257     Prnlf.lfHeight = ts.PrnFontSize.y;
258     Prnlf.lfWidth = ts.PrnFontSize.x;
259     Prnlf.lfCharSet = ts.PrnFontCharSet;
260     strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName), ts.PrnFont, _TRUNCATE);
261     }
262     Prnlf.lfWeight = FW_NORMAL;
263     Prnlf.lfItalic = 0;
264     Prnlf.lfUnderline = 0;
265     Prnlf.lfStrikeOut = 0;
266     Prnlf.lfOutPrecision = OUT_CHARACTER_PRECIS;
267     Prnlf.lfClipPrecision = CLIP_CHARACTER_PRECIS;
268     Prnlf.lfQuality = DEFAULT_QUALITY;
269     Prnlf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
270 maya 3227
271 zmatsuo 7527 PrnFont[0] = CreateFontIndirectA(&Prnlf);
272 maya 3227
273 maya 3392 DC = GetDC(HVTWin);
274     SelectObject(DC, PrnFont[0]);
275     GetTextMetrics(DC, &Metrics);
276     PPI2.x = GetDeviceCaps(DC,LOGPIXELSX);
277     PPI2.y = GetDeviceCaps(DC,LOGPIXELSY);
278     ReleaseDC(HVTWin,DC);
279     DeleteObject(PrnFont[0]); /* Delete test font */
280 maya 3227
281 maya 3392 /* Adjust font size */
282     Prnlf.lfHeight = (int)((float)Metrics.tmHeight * (float)PPI.y / (float)PPI2.y);
283     Prnlf.lfWidth = (int)((float)Metrics.tmAveCharWidth * (float)PPI.x / (float)PPI2.x);
284 maya 3227
285 maya 3392 /* Create New Fonts */
286 maya 3227
287 maya 3392 /* Normal Font */
288     Prnlf.lfWeight = FW_NORMAL;
289     Prnlf.lfUnderline = 0;
290 zmatsuo 7527 PrnFont[0] = CreateFontIndirectA(&Prnlf);
291 maya 3392 SelectObject(PrintDC,PrnFont[0]);
292     GetTextMetrics(PrintDC, &Metrics);
293     PrnFW = Metrics.tmAveCharWidth;
294     PrnFH = Metrics.tmHeight;
295     /* Under line */
296     Prnlf.lfUnderline = 1;
297 zmatsuo 7527 PrnFont[AttrUnder] = CreateFontIndirectA(&Prnlf);
298 maya 3227
299 doda 3666 if (ts.FontFlag & FF_BOLD) {
300 maya 3392 /* Bold */
301     Prnlf.lfUnderline = 0;
302     Prnlf.lfWeight = FW_BOLD;
303 zmatsuo 7527 PrnFont[AttrBold] = CreateFontIndirectA(&Prnlf);
304 maya 3392 /* Bold + Underline */
305     Prnlf.lfUnderline = 1;
306 zmatsuo 7527 PrnFont[AttrBold | AttrUnder] = CreateFontIndirectA(&Prnlf);
307 maya 3392 }
308     else {
309     PrnFont[AttrBold] = PrnFont[AttrDefault];
310     PrnFont[AttrBold | AttrUnder] = PrnFont[AttrUnder];
311     }
312     /* Special font */
313     Prnlf.lfWeight = FW_NORMAL;
314     Prnlf.lfUnderline = 0;
315     Prnlf.lfWidth = PrnFW; /* adjust width */
316     Prnlf.lfHeight = PrnFH;
317     Prnlf.lfCharSet = SYMBOL_CHARSET;
318 maya 3227
319 maya 3392 strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName),"Tera Special", _TRUNCATE);
320 zmatsuo 7527 PrnFont[AttrSpecial] = CreateFontIndirectA(&Prnlf);
321 maya 3392 PrnFont[AttrSpecial | AttrBold] = PrnFont[AttrSpecial];
322     PrnFont[AttrSpecial | AttrUnder] = PrnFont[AttrSpecial];
323     PrnFont[AttrSpecial | AttrBold | AttrUnder] = PrnFont[AttrSpecial];
324 maya 3227
325 maya 3392 Black = RGB(0,0,0);
326     White = RGB(255,255,255);
327     for (i = 0 ; i <= 255 ; i++) {
328     PrnDx[i] = PrnFW;
329     }
330     PrnSetAttr(TempAttr);
331 maya 3227
332 maya 3392 PrnY = Margin.top;
333     PrnX = Margin.left;
334 maya 3227
335 maya 3392 if (PrnFlag == IdPrnScrollRegion) {
336     return (IdPrnScrollRegion);
337     }
338     if (PrnFlag == IdPrnFile) {
339     return (IdPrnFile);
340     }
341     if (Sel) {
342     return (IdPrnSelectedText);
343     }
344     else {
345     return (IdPrnScreen);
346     }
347 maya 3227 }
348 zmatsuo 7291
349 maya 3227 void PrnSetAttr(TCharAttr Attr)
350     // Set text attribute of printing
351     //
352     {
353 maya 3392 PrnAttr = Attr;
354     SelectObject(PrintDC, PrnFont[Attr.Attr & AttrFontMask]);
355 maya 3227
356 maya 3392 if ((Attr.Attr & AttrReverse) != 0) {
357     SetTextColor(PrintDC,White);
358     SetBkColor( PrintDC,Black);
359     }
360     else {
361     SetTextColor(PrintDC,Black);
362     SetBkColor( PrintDC,White);
363     }
364 maya 3227 }
365    
366     void PrnOutText(PCHAR Buff, int Count)
367     // Print out text
368     // Buff: points text buffer
369     // Count: number of characters to be printed
370     {
371 maya 3392 int i;
372     RECT RText;
373     PCHAR Ptr, Ptr1, Ptr2;
374     char Buff2[256];
375 maya 3227
376 maya 3392 if (Count<=0) {
377     return;
378     }
379     if (Count>(sizeof(Buff2)-1)) {
380     Count=sizeof(Buff2)-1;
381     }
382     memcpy(Buff2,Buff,Count);
383     Buff2[Count] = 0;
384     Ptr = Buff2;
385 maya 3227
386 maya 3392 if (ts.Language==IdRussian) {
387     if (ts.PrnFont[0]==0) {
388     RussConvStr(ts.RussClient,ts.RussFont,Buff2,Count);
389     }
390     else {
391     RussConvStr(ts.RussClient,ts.RussPrint,Buff2,Count);
392     }
393     }
394 maya 3227
395 maya 3392 do {
396     if (PrnX+PrnFW > Margin.right) {
397     /* new line */
398     PrnX = Margin.left;
399     PrnY = PrnY + PrnFH;
400     }
401     if (PrnY+PrnFH > Margin.bottom) {
402     /* next page */
403     EndPage(PrintDC);
404     StartPage(PrintDC);
405     PrnSetAttr(PrnAttr);
406     PrnY = Margin.top;
407     }
408 maya 3227
409 maya 3392 i = (Margin.right-PrnX) / PrnFW;
410     if (i==0) {
411     i=1;
412     }
413     if (i>Count) {
414     i=Count;
415     }
416 maya 3227
417 maya 3392 if (i<Count) {
418     Ptr2 = Ptr;
419     do {
420     Ptr1 = Ptr2;
421 zmatsuo 7527 Ptr2 = CharNextA(Ptr1);
422 maya 3392 } while ((Ptr2!=NULL) && ((Ptr2-Ptr)<=i));
423     i = Ptr1-Ptr;
424     if (i<=0) {
425     i=1;
426     }
427     }
428 maya 3227
429 maya 3392 RText.left = PrnX;
430     RText.right = PrnX + i*PrnFW;
431     RText.top = PrnY;
432     RText.bottom = PrnY+PrnFH;
433 zmatsuo 7527 ExtTextOutA(PrintDC,PrnX,PrnY,6,&RText,Ptr,i,&PrnDx[0]);
434 maya 3392 PrnX = RText.right;
435     Count=Count-i;
436     Ptr = Ptr + i;
437     } while (Count>0);
438 maya 3227
439     }
440    
441     void PrnNewLine()
442     // Moves to the next line in printing
443     {
444 maya 3392 PrnX = Margin.left;
445     PrnY = PrnY + PrnFH;
446 maya 3227 }
447    
448     void VTPrintEnd()
449     {
450 maya 3392 int i, j;
451 maya 3227
452 maya 3392 EndPage(PrintDC);
453 maya 3227
454 maya 3392 for (i = 0 ; i <= AttrFontMask ; i++) {
455     for (j = i+1 ; j <= AttrFontMask ; j++) {
456     if (PrnFont[j]==PrnFont[i]) {
457     PrnFont[j] = NULL;
458     }
459     }
460     if (PrnFont[i] != NULL) {
461     DeleteObject(PrnFont[i]);
462     }
463     }
464 maya 3227
465 maya 3392 PrnStop();
466     return;
467 maya 3227 }
468    
469     /* printer emulation routines */
470     void OpenPrnFile()
471     {
472 maya 4031 char Temp[MAX_PATH];
473 maya 3227
474 maya 3392 KillTimer(HVTWin,IdPrnStartTimer);
475 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
476 maya 3392 return;
477     }
478     if (PrnFName[0] == 0) {
479 zmatsuo 7527 GetTempPathA(sizeof(Temp),Temp);
480     if (GetTempFileNameA(Temp,"tmp",0,PrnFName)==0) {
481 maya 3392 return;
482     }
483     HPrnFile = _lcreat(PrnFName,0);
484     }
485     else {
486     HPrnFile = _lopen(PrnFName,OF_WRITE);
487 zmatsuo 7290 if (HPrnFile == INVALID_HANDLE_VALUE) {
488 maya 3392 HPrnFile = _lcreat(PrnFName,0);
489     }
490     }
491 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
492 maya 3392 _llseek(HPrnFile,0,2);
493     }
494 maya 3227 }
495    
496     void PrintFile()
497     {
498 maya 3392 char Buff[256];
499     BOOL CRFlag = FALSE;
500     int c, i;
501     BYTE b;
502 maya 3227
503 maya 3392 if (VTPrintInit(IdPrnFile)==IdPrnFile) {
504     HPrnFile = _lopen(PrnFName,OF_READ);
505 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
506 maya 3392 do {
507     i = 0;
508     do {
509     c = _lread(HPrnFile,&b,1);
510     if (c==1) {
511     switch (b) {
512     case HT:
513     memset(&(Buff[i]),0x20,8);
514     i = i + 8;
515     CRFlag = FALSE;
516     break;
517     case LF:
518     CRFlag = ! CRFlag;
519     break;
520     case FF:
521     case CR:
522     CRFlag = TRUE;
523     break;
524     default:
525     if (b >= 0x20) {
526     Buff[i] = b;
527     i++;
528     }
529     CRFlag = FALSE;
530     break;
531     }
532     }
533     if (i>=(sizeof(Buff)-7)) {
534     CRFlag=TRUE;
535     }
536     } while ((c>0) && (! CRFlag));
537     if (i>0) {
538     PrnOutText(Buff, i);
539     }
540     if (CRFlag) {
541     PrnX = Margin.left;
542     if ((b==FF) && (ts.PrnConvFF==0)) { // new page
543     PrnY = Margin.bottom;
544     }
545     else { // new line
546     PrnY = PrnY + PrnFH;
547     }
548     }
549     CRFlag = (b==CR);
550     } while (c>0);
551     _lclose(HPrnFile);
552 maya 3227 }
553 maya 3392 HPrnFile = 0;
554     VTPrintEnd();
555 maya 3227 }
556 maya 3392 remove(PrnFName);
557     PrnFName[0] = 0;
558 maya 3227 }
559    
560     void PrintFileDirect()
561     {
562 maya 3392 CWnd* pParent;
563 maya 3227
564 maya 3392 PrnAbortDlg = new CPrnAbortDlg();
565     if (PrnAbortDlg==NULL) {
566     remove(PrnFName);
567     PrnFName[0] = 0;
568     return;
569     }
570     if (ActiveWin==IdVT) {
571     pParent = (CWnd*)pVTWin;
572     }
573     else {
574     pParent = (CWnd*)pTEKWin;
575     }
576 zmatsuo 7174 PrnAbortDlg->Create(hInst, pParent->GetSafeHwnd(),&PrintAbortFlag,&ts);
577 maya 3392 HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd();
578 maya 3227
579 maya 3392 HPrnFile = _lopen(PrnFName,OF_READ);
580 zmatsuo 7290 PrintAbortFlag = (HPrnFile == INVALID_HANDLE_VALUE) || ! PrnOpen(ts.PrnDev);
581 maya 3392 PrnBuffCount = 0;
582     SetTimer(HVTWin,IdPrnProcTimer,0,NULL);
583 maya 3227 }
584    
585     void PrnFileDirectProc()
586     {
587 maya 3392 int c;
588 maya 3227
589 zmatsuo 7290 if (HPrnFile==INVALID_HANDLE_VALUE) {
590 maya 3392 return;
591     }
592     if (PrintAbortFlag) {
593     HPrnAbortDlg = NULL;
594     PrnAbortDlg = NULL;
595     PrnCancel();
596     }
597 zmatsuo 7290 if (!PrintAbortFlag && (HPrnFile != INVALID_HANDLE_VALUE)) {
598 maya 3392 do {
599     if (PrnBuffCount==0) {
600     PrnBuffCount = _lread(HPrnFile,PrnBuff,1);
601     if (ts.Language==IdRussian) {
602     RussConvStr(ts.RussClient,ts.RussPrint,PrnBuff,PrnBuffCount);
603     }
604     }
605 maya 3227
606 maya 3392 if (PrnBuffCount==1) {
607     c = PrnWrite(PrnBuff,1);
608     if (c==0) {
609     SetTimer(HVTWin,IdPrnProcTimer,10,NULL);
610     return;
611     }
612     PrnBuffCount = 0;
613     }
614     else {
615     c = 0;
616     }
617     } while (c>0);
618 maya 3227 }
619 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
620 maya 3392 _lclose(HPrnFile);
621     }
622 zmatsuo 7290 HPrnFile = INVALID_HANDLE_VALUE;
623 maya 3392 PrnClose();
624     remove(PrnFName);
625     PrnFName[0] = 0;
626     if (PrnAbortDlg!=NULL) {
627     PrnAbortDlg->DestroyWindow();
628     PrnAbortDlg = NULL;
629     HPrnAbortDlg = NULL;
630     }
631 maya 3227 }
632    
633     void PrnFileStart()
634     {
635 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
636 maya 3392 return;
637     }
638     if (PrnFName[0]==0) {
639     return;
640     }
641     if (ts.PrnDev[0]!=0) {
642     PrintFileDirect(); // send file directry to printer port
643     }
644     else { // print file by using Windows API
645     PrintFile();
646     }
647 maya 3227 }
648    
649     void ClosePrnFile()
650     {
651 maya 3392 PrnBuffCount = 0;
652 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
653 maya 3392 _lclose(HPrnFile);
654     }
655 zmatsuo 7290 HPrnFile = INVALID_HANDLE_VALUE;
656 maya 3392 SetTimer(HVTWin,IdPrnStartTimer,ts.PassThruDelay*1000,NULL);
657 maya 3227 }
658    
659     void WriteToPrnFile(BYTE b, BOOL Write)
660     // (b,Write) =
661     // (0,FALSE): clear buffer
662     // (0,TRUE): write buffer to file
663     // (b,FALSE): put b in buff
664     // (b,TRUE): put b in buff and
665     // write buffer to file
666     {
667 maya 3392 if ((b>0) && (PrnBuffCount<sizeof(PrnBuff))) {
668     PrnBuff[PrnBuffCount++] = b;
669     }
670 maya 3227
671 maya 3392 if (Write) {
672     _lwrite(HPrnFile,PrnBuff,PrnBuffCount);
673     PrnBuffCount = 0;
674     }
675     if ((b==0) && ! Write) {
676     PrnBuffCount = 0;
677     }
678 maya 3227 }

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