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 6841 - (hide annotations) (download) (as text)
Tue Jul 4 15:02:28 2017 UTC (6 years, 9 months ago) by doda
File MIME type: text/x-c++src
File size: 16291 byte(s)
TeraTerm Project としてのライセンス表記を追加

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

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