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 6806 - (hide annotations) (download) (as text)
Thu Jun 15 00:37:01 2017 UTC (6 years, 9 months ago) by doda
File MIME type: text/x-c++src
File size: 16295 byte(s)
TeraTerm Project としてのライセンス表記を追加

とりあえず Tera Term 本体分。
TeraTerm Project としての copyright 表記の年部分はコミットログを確認して書いたつもりだけど、ミスってたらすみません。

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

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