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

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