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 7174 - (hide annotations) (download) (as text)
Sun Aug 5 13:28:57 2018 UTC (5 years, 8 months ago) by zmatsuo
File MIME type: text/x-c++src
File size: 15871 byte(s)
teraterm/teraterm/dnddlg.cpp フォントの削除をNCDESTROYで行うようにした
teraterm/teraterm/prnabort.cpp,h MFCを使わないようにした
teraterm/common/dlglib.c,h dnddlgからSetDlgFonts()を移動

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

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