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

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