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 9039 - (hide annotations) (download) (as text)
Sun Nov 29 15:26:29 2020 UTC (3 years, 4 months ago) by zmatsuo
File MIME type: text/x-c++src
File size: 17046 byte(s)
Win16APIをWin32API,Unicode版に置き換え
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 "teraterm.h"
32     #include "tttypes.h"
33     #include <commdlg.h>
34     #include <stdio.h>
35 zmatsuo 7936 #include <crtdbg.h>
36 maya 3227
37     #include "ttwinman.h"
38     #include "commlib.h"
39     #include "ttcommon.h"
40     #include "ttlib.h"
41 zmatsuo 9039 //#include "win16api.h"
42 maya 3227
43     #include "tt_res.h"
44 zmatsuo 7528 #include "tmfc.h"
45 maya 3227 #include "prnabort.h"
46    
47     #include "teraprn.h"
48    
49 zmatsuo 7936 #ifdef _DEBUG
50     #if defined(_MSC_VER)
51     #define new ::new(_NORMAL_BLOCK, __FILE__, __LINE__)
52 maya 3227 #endif
53 zmatsuo 7936 #endif
54 maya 3227
55     static HDC PrintDC;
56     static HFONT PrnFont[AttrFontMask+1];
57     static int PrnFW, PrnFH;
58     static RECT Margin;
59     static COLORREF White, Black;
60     static int PrnX, PrnY;
61     static int PrnDx[256];
62     static TCharAttr PrnAttr;
63    
64     static BOOL Printing = FALSE;
65     static BOOL PrintAbortFlag = FALSE;
66    
67     /* pass-thru printing */
68 zmatsuo 9039 static wchar_t PrnFName[MAX_PATH];
69 zmatsuo 7290 static HANDLE HPrnFile = INVALID_HANDLE_VALUE;
70 maya 3227 static char PrnBuff[TermWidthMax];
71     static int PrnBuffCount = 0;
72    
73     static CPrnAbortDlg *PrnAbortDlg;
74     static HWND HPrnAbortDlg;
75    
76     /* Print Abortion Call Back Function */
77 zmatsuo 7933 static BOOL CALLBACK PrnAbortProc(HDC PDC, int Code)
78 maya 3227 {
79 maya 3392 MSG m;
80 maya 3227
81 maya 3392 while ((! PrintAbortFlag) && PeekMessage(&m, 0,0,0, PM_REMOVE))
82     if ((HPrnAbortDlg==NULL) || (! IsDialogMessage(HPrnAbortDlg, &m))) {
83     TranslateMessage(&m);
84     DispatchMessage(&m);
85     }
86 maya 3227
87 maya 3392 if (PrintAbortFlag) {
88     HPrnAbortDlg = NULL;
89     PrnAbortDlg = NULL;
90     return FALSE;
91     }
92     else {
93     return TRUE;
94     }
95 maya 3227 }
96    
97 yutakapon 8331 static UINT_PTR CALLBACK PrintHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
98     {
99     return 0;
100     }
101    
102 maya 3227 HDC PrnBox(HWND HWin, PBOOL Sel)
103     {
104 maya 3392 /* initialize PrnDlg record */
105 zmatsuo 9038 PRINTDLGW PrnDlg = {};
106     PrnDlg.lStructSize = sizeof(PrnDlg);
107 maya 3392 PrnDlg.hwndOwner = HWin;
108 yutakapon 8331 PrnDlg.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_SHOWHELP | PD_ENABLEPRINTHOOK;
109 maya 3392 if (! *Sel) {
110 yutakapon 5196 PrnDlg.Flags = PrnDlg.Flags | PD_NOSELECTION; /* when there is nothing select, gray out the "Selection" radio button */
111     } else {
112     PrnDlg.Flags = PrnDlg.Flags | PD_SELECTION; /* when there is something select, select the "Selection" radio button by default */
113 maya 3392 }
114     PrnDlg.nCopies = 1;
115 yutakapon 8331 /*
116     * Windows NT�n���������A�����_�C�A���O���w���v�{�^�����\�����������A
117     * �v���V�[�W�����t�b�N�����B
118     */
119     PrnDlg.lpfnPrintHook = PrintHookProc;
120 maya 3227
121 maya 3392 /* 'Print' dialog box */
122 zmatsuo 9038 if (! PrintDlgW(&PrnDlg)) {
123 maya 3392 return NULL; /* if 'Cancel' button clicked, exit */
124     }
125     if (PrnDlg.hDC == NULL) {
126     return NULL;
127     }
128     *Sel = (PrnDlg.Flags & PD_SELECTION) != 0;
129 zmatsuo 9038 return PrnDlg.hDC;
130 maya 3227 }
131    
132     BOOL PrnStart(LPSTR DocumentName)
133     {
134 zmatsuo 7527 DOCINFOA Doc;
135 maya 3392 char DocName[50];
136 zmatsuo 7933 HWND hParent;
137 maya 3227
138 maya 3392 Printing = FALSE;
139     PrintAbortFlag = FALSE;
140 maya 3227
141 maya 3392 PrnAbortDlg = new CPrnAbortDlg();
142     if (PrnAbortDlg==NULL) {
143     return FALSE;
144     }
145     if (ActiveWin==IdVT) {
146 zmatsuo 7933 hParent = HVTWin;
147 maya 3392 }
148     else {
149 zmatsuo 7933 hParent = HTEKWin;
150 maya 3392 }
151 zmatsuo 7933 PrnAbortDlg->Create(hInst,hParent,&PrintAbortFlag,&ts);
152 maya 3392 HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd();
153 maya 3227
154 maya 3392 SetAbortProc(PrintDC,PrnAbortProc);
155 maya 3227
156 zmatsuo 7527 Doc.cbSize = sizeof(Doc);
157 maya 3392 strncpy_s(DocName,sizeof(DocName),DocumentName,_TRUNCATE);
158     Doc.lpszDocName = DocName;
159     Doc.lpszOutput = NULL;
160     Doc.lpszDatatype = NULL;
161     Doc.fwType = 0;
162 zmatsuo 7527 if (StartDocA(PrintDC, &Doc) > 0) {
163 maya 3392 Printing = TRUE;
164     }
165     else {
166     if (PrnAbortDlg != NULL) {
167     PrnAbortDlg->DestroyWindow();
168     PrnAbortDlg = NULL;
169     HPrnAbortDlg = NULL;
170     }
171     }
172     return Printing;
173 maya 3227 }
174    
175     void PrnStop()
176     {
177 maya 3392 if (Printing) {
178     EndDoc(PrintDC);
179     DeleteDC(PrintDC);
180     Printing = FALSE;
181     }
182     if (PrnAbortDlg != NULL) {
183     PrnAbortDlg->DestroyWindow();
184     PrnAbortDlg = NULL;
185     HPrnAbortDlg = NULL;
186     }
187 maya 3227 }
188    
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 zmatsuo 9038 LOGFONTA Prnlf;
215 maya 3227
216 maya 3392 Sel = (PrnFlag & IdPrnSelectedText)!=0;
217 zmatsuo 9038 PrintDC = PrnBox(HVTWin,&Sel);
218     if (PrintDC == NULL) {
219 maya 3392 return (IdPrnCancel);
220     }
221 maya 3227
222 maya 3392 /* start printing */
223     if (! PrnStart(ts.Title)) {
224     return (IdPrnCancel);
225     }
226 maya 3227
227 maya 3392 /* initialization */
228     StartPage(PrintDC);
229 maya 3227
230 maya 3392 /* pixels per inch */
231     if ((ts.VTPPI.x>0) && (ts.VTPPI.y>0)) {
232     PPI = ts.VTPPI;
233     }
234     else {
235     PPI.x = GetDeviceCaps(PrintDC,LOGPIXELSX);
236     PPI.y = GetDeviceCaps(PrintDC,LOGPIXELSY);
237     }
238 maya 3227
239 maya 3392 /* left margin */
240     Margin.left = (int)((float)ts.PrnMargin[0] / 100.0 * (float)PPI.x);
241     /* right margin */
242     Margin.right = GetDeviceCaps(PrintDC,HORZRES) -
243     (int)((float)ts.PrnMargin[1] / 100.0 * (float)PPI.x);
244     /* top margin */
245     Margin.top = (int)((float)ts.PrnMargin[2] / 100.0 * (float)PPI.y);
246     /* bottom margin */
247     Margin.bottom = GetDeviceCaps(PrintDC,VERTRES) -
248     (int)((float)ts.PrnMargin[3] / 100.0 * (float)PPI.y);
249 maya 3227
250 maya 3392 /* create test font */
251 zmatsuo 7527 memset(&Prnlf, 0, sizeof(Prnlf));
252 maya 3227
253 maya 3392 if (ts.PrnFont[0]==0) {
254     Prnlf.lfHeight = ts.VTFontSize.y;
255     Prnlf.lfWidth = ts.VTFontSize.x;
256     Prnlf.lfCharSet = ts.VTFontCharSet;
257     strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName), ts.VTFont, _TRUNCATE);
258     }
259     else {
260     Prnlf.lfHeight = ts.PrnFontSize.y;
261     Prnlf.lfWidth = ts.PrnFontSize.x;
262     Prnlf.lfCharSet = ts.PrnFontCharSet;
263     strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName), ts.PrnFont, _TRUNCATE);
264     }
265     Prnlf.lfWeight = FW_NORMAL;
266     Prnlf.lfItalic = 0;
267     Prnlf.lfUnderline = 0;
268     Prnlf.lfStrikeOut = 0;
269     Prnlf.lfOutPrecision = OUT_CHARACTER_PRECIS;
270     Prnlf.lfClipPrecision = CLIP_CHARACTER_PRECIS;
271     Prnlf.lfQuality = DEFAULT_QUALITY;
272     Prnlf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
273 maya 3227
274 zmatsuo 7527 PrnFont[0] = CreateFontIndirectA(&Prnlf);
275 maya 3227
276 maya 3392 DC = GetDC(HVTWin);
277     SelectObject(DC, PrnFont[0]);
278     GetTextMetrics(DC, &Metrics);
279     PPI2.x = GetDeviceCaps(DC,LOGPIXELSX);
280     PPI2.y = GetDeviceCaps(DC,LOGPIXELSY);
281     ReleaseDC(HVTWin,DC);
282     DeleteObject(PrnFont[0]); /* Delete test font */
283 maya 3227
284 maya 3392 /* Adjust font size */
285     Prnlf.lfHeight = (int)((float)Metrics.tmHeight * (float)PPI.y / (float)PPI2.y);
286     Prnlf.lfWidth = (int)((float)Metrics.tmAveCharWidth * (float)PPI.x / (float)PPI2.x);
287 maya 3227
288 maya 3392 /* Create New Fonts */
289 maya 3227
290 maya 3392 /* Normal Font */
291     Prnlf.lfWeight = FW_NORMAL;
292     Prnlf.lfUnderline = 0;
293 zmatsuo 7527 PrnFont[0] = CreateFontIndirectA(&Prnlf);
294 maya 3392 SelectObject(PrintDC,PrnFont[0]);
295     GetTextMetrics(PrintDC, &Metrics);
296     PrnFW = Metrics.tmAveCharWidth;
297     PrnFH = Metrics.tmHeight;
298     /* Under line */
299     Prnlf.lfUnderline = 1;
300 zmatsuo 7527 PrnFont[AttrUnder] = CreateFontIndirectA(&Prnlf);
301 maya 3227
302 doda 3666 if (ts.FontFlag & FF_BOLD) {
303 maya 3392 /* Bold */
304     Prnlf.lfUnderline = 0;
305     Prnlf.lfWeight = FW_BOLD;
306 zmatsuo 7527 PrnFont[AttrBold] = CreateFontIndirectA(&Prnlf);
307 maya 3392 /* Bold + Underline */
308     Prnlf.lfUnderline = 1;
309 zmatsuo 7527 PrnFont[AttrBold | AttrUnder] = CreateFontIndirectA(&Prnlf);
310 maya 3392 }
311     else {
312     PrnFont[AttrBold] = PrnFont[AttrDefault];
313     PrnFont[AttrBold | AttrUnder] = PrnFont[AttrUnder];
314     }
315     /* Special font */
316     Prnlf.lfWeight = FW_NORMAL;
317     Prnlf.lfUnderline = 0;
318     Prnlf.lfWidth = PrnFW; /* adjust width */
319     Prnlf.lfHeight = PrnFH;
320     Prnlf.lfCharSet = SYMBOL_CHARSET;
321 maya 3227
322 maya 3392 strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName),"Tera Special", _TRUNCATE);
323 zmatsuo 7527 PrnFont[AttrSpecial] = CreateFontIndirectA(&Prnlf);
324 maya 3392 PrnFont[AttrSpecial | AttrBold] = PrnFont[AttrSpecial];
325     PrnFont[AttrSpecial | AttrUnder] = PrnFont[AttrSpecial];
326     PrnFont[AttrSpecial | AttrBold | AttrUnder] = PrnFont[AttrSpecial];
327 maya 3227
328 maya 3392 Black = RGB(0,0,0);
329     White = RGB(255,255,255);
330     for (i = 0 ; i <= 255 ; i++) {
331     PrnDx[i] = PrnFW;
332     }
333     PrnSetAttr(TempAttr);
334 maya 3227
335 maya 3392 PrnY = Margin.top;
336     PrnX = Margin.left;
337 maya 3227
338 maya 3392 if (PrnFlag == IdPrnScrollRegion) {
339     return (IdPrnScrollRegion);
340     }
341     if (PrnFlag == IdPrnFile) {
342     return (IdPrnFile);
343     }
344     if (Sel) {
345     return (IdPrnSelectedText);
346     }
347     else {
348     return (IdPrnScreen);
349     }
350 maya 3227 }
351 zmatsuo 7291
352 maya 3227 void PrnSetAttr(TCharAttr Attr)
353     // Set text attribute of printing
354     //
355     {
356 maya 3392 PrnAttr = Attr;
357     SelectObject(PrintDC, PrnFont[Attr.Attr & AttrFontMask]);
358 maya 3227
359 maya 3392 if ((Attr.Attr & AttrReverse) != 0) {
360     SetTextColor(PrintDC,White);
361     SetBkColor( PrintDC,Black);
362     }
363     else {
364     SetTextColor(PrintDC,Black);
365     SetBkColor( PrintDC,White);
366     }
367 maya 3227 }
368    
369     void PrnOutText(PCHAR Buff, int Count)
370     // Print out text
371     // Buff: points text buffer
372     // Count: number of characters to be printed
373     {
374 maya 3392 int i;
375     RECT RText;
376     PCHAR Ptr, Ptr1, Ptr2;
377     char Buff2[256];
378 maya 3227
379 maya 3392 if (Count<=0) {
380     return;
381     }
382     if (Count>(sizeof(Buff2)-1)) {
383     Count=sizeof(Buff2)-1;
384     }
385     memcpy(Buff2,Buff,Count);
386     Buff2[Count] = 0;
387     Ptr = Buff2;
388 maya 3227
389 maya 3392 if (ts.Language==IdRussian) {
390     if (ts.PrnFont[0]==0) {
391     RussConvStr(ts.RussClient,ts.RussFont,Buff2,Count);
392     }
393     else {
394     RussConvStr(ts.RussClient,ts.RussPrint,Buff2,Count);
395     }
396     }
397 maya 3227
398 maya 3392 do {
399     if (PrnX+PrnFW > Margin.right) {
400     /* new line */
401     PrnX = Margin.left;
402     PrnY = PrnY + PrnFH;
403     }
404     if (PrnY+PrnFH > Margin.bottom) {
405     /* next page */
406     EndPage(PrintDC);
407     StartPage(PrintDC);
408     PrnSetAttr(PrnAttr);
409     PrnY = Margin.top;
410     }
411 maya 3227
412 maya 3392 i = (Margin.right-PrnX) / PrnFW;
413     if (i==0) {
414     i=1;
415     }
416     if (i>Count) {
417     i=Count;
418     }
419 maya 3227
420 maya 3392 if (i<Count) {
421     Ptr2 = Ptr;
422     do {
423     Ptr1 = Ptr2;
424 zmatsuo 7527 Ptr2 = CharNextA(Ptr1);
425 maya 3392 } while ((Ptr2!=NULL) && ((Ptr2-Ptr)<=i));
426     i = Ptr1-Ptr;
427     if (i<=0) {
428     i=1;
429     }
430     }
431 maya 3227
432 maya 3392 RText.left = PrnX;
433     RText.right = PrnX + i*PrnFW;
434     RText.top = PrnY;
435     RText.bottom = PrnY+PrnFH;
436 zmatsuo 7527 ExtTextOutA(PrintDC,PrnX,PrnY,6,&RText,Ptr,i,&PrnDx[0]);
437 maya 3392 PrnX = RText.right;
438     Count=Count-i;
439     Ptr = Ptr + i;
440     } while (Count>0);
441 maya 3227
442     }
443    
444     void PrnNewLine()
445     // Moves to the next line in printing
446     {
447 maya 3392 PrnX = Margin.left;
448     PrnY = PrnY + PrnFH;
449 maya 3227 }
450    
451     void VTPrintEnd()
452     {
453 maya 3392 int i, j;
454 maya 3227
455 maya 3392 EndPage(PrintDC);
456 maya 3227
457 maya 3392 for (i = 0 ; i <= AttrFontMask ; i++) {
458     for (j = i+1 ; j <= AttrFontMask ; j++) {
459     if (PrnFont[j]==PrnFont[i]) {
460     PrnFont[j] = NULL;
461     }
462     }
463     if (PrnFont[i] != NULL) {
464     DeleteObject(PrnFont[i]);
465     }
466     }
467 maya 3227
468 maya 3392 PrnStop();
469     return;
470 maya 3227 }
471    
472     /* printer emulation routines */
473     void OpenPrnFile()
474     {
475 zmatsuo 9039 KillTimer(HVTWin, IdPrnStartTimer);
476 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
477 maya 3392 return;
478     }
479     if (PrnFName[0] == 0) {
480 zmatsuo 9039 wchar_t Temp[MAX_PATH];
481     GetTempPathW(_countof(Temp), Temp);
482     if (GetTempFileNameW(Temp, L"tmp", 0, PrnFName) == 0) {
483 maya 3392 return;
484     }
485 zmatsuo 9039 HPrnFile =
486     CreateFileW(PrnFName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
487 maya 3392 }
488     else {
489 zmatsuo 9039 HPrnFile =
490     CreateFileW(PrnFName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
491 zmatsuo 7290 if (HPrnFile == INVALID_HANDLE_VALUE) {
492 zmatsuo 9039 HPrnFile = CreateFileW(PrnFName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
493     FILE_ATTRIBUTE_NORMAL, NULL);
494 maya 3392 }
495     }
496 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
497 zmatsuo 9039 SetFilePointer(HPrnFile, 0, NULL, FILE_END);
498 maya 3392 }
499 maya 3227 }
500    
501 zmatsuo 9039 static void PrintFile(void)
502 maya 3227 {
503 maya 3392 char Buff[256];
504     BOOL CRFlag = FALSE;
505     int c, i;
506     BYTE b;
507 maya 3227
508 maya 3392 if (VTPrintInit(IdPrnFile)==IdPrnFile) {
509 zmatsuo 9039 HPrnFile = CreateFileW(PrnFName,
510     GENERIC_READ, FILE_SHARE_READ, NULL,
511     OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
512    
513 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
514 maya 3392 do {
515     i = 0;
516     do {
517 zmatsuo 9039 DWORD NumberOfBytesRead;
518     BOOL r = ReadFile(HPrnFile, &b, 1, &NumberOfBytesRead, NULL);
519     c = 0;
520     if (r) {
521     c = NumberOfBytesRead;
522     }
523     if (c == 1) {
524 maya 3392 switch (b) {
525     case HT:
526     memset(&(Buff[i]),0x20,8);
527     i = i + 8;
528     CRFlag = FALSE;
529     break;
530     case LF:
531     CRFlag = ! CRFlag;
532     break;
533     case FF:
534     case CR:
535     CRFlag = TRUE;
536     break;
537     default:
538     if (b >= 0x20) {
539     Buff[i] = b;
540     i++;
541     }
542     CRFlag = FALSE;
543     break;
544     }
545     }
546     if (i>=(sizeof(Buff)-7)) {
547     CRFlag=TRUE;
548     }
549     } while ((c>0) && (! CRFlag));
550     if (i>0) {
551     PrnOutText(Buff, i);
552     }
553     if (CRFlag) {
554     PrnX = Margin.left;
555     if ((b==FF) && (ts.PrnConvFF==0)) { // new page
556     PrnY = Margin.bottom;
557     }
558     else { // new line
559     PrnY = PrnY + PrnFH;
560     }
561     }
562     CRFlag = (b==CR);
563     } while (c>0);
564 zmatsuo 9039 CloseHandle(HPrnFile);
565 maya 3227 }
566 zmatsuo 9039 HPrnFile = INVALID_HANDLE_VALUE;
567 maya 3392 VTPrintEnd();
568 maya 3227 }
569 zmatsuo 9039 DeleteFileW(PrnFName);
570 maya 3392 PrnFName[0] = 0;
571 maya 3227 }
572    
573 zmatsuo 9039 static void PrintFileDirect(void)
574 maya 3227 {
575 zmatsuo 7933 HWND hParent;
576 maya 3227
577 maya 3392 PrnAbortDlg = new CPrnAbortDlg();
578     if (PrnAbortDlg==NULL) {
579 zmatsuo 9039 DeleteFileW(PrnFName);
580 maya 3392 PrnFName[0] = 0;
581     return;
582     }
583     if (ActiveWin==IdVT) {
584 zmatsuo 7933 hParent = HVTWin;
585 maya 3392 }
586     else {
587 zmatsuo 7933 hParent = HTEKWin;
588 maya 3392 }
589 zmatsuo 7933 PrnAbortDlg->Create(hInst,hParent,&PrintAbortFlag,&ts);
590 maya 3392 HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd();
591 maya 3227
592 zmatsuo 9039 HPrnFile = CreateFileW(PrnFName,
593     GENERIC_READ, FILE_SHARE_READ, NULL,
594     OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
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 zmatsuo 9039 PrnBuffCount = 0;
616     DWORD NumberOfBytesRead;
617     BOOL r = ReadFile(HPrnFile, PrnBuff, 1, &NumberOfBytesRead, NULL);
618     if (r) {
619     PrnBuffCount = NumberOfBytesRead;
620     }
621 maya 3392 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 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
640 zmatsuo 9039 CloseHandle(HPrnFile);
641 maya 3392 }
642 zmatsuo 7290 HPrnFile = INVALID_HANDLE_VALUE;
643 maya 3392 PrnClose();
644 zmatsuo 9039 DeleteFileW(PrnFName);
645 maya 3392 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 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
656 maya 3392 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     void ClosePrnFile()
670     {
671 maya 3392 PrnBuffCount = 0;
672 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
673 zmatsuo 9039 CloseHandle(HPrnFile);
674 maya 3392 }
675 zmatsuo 7290 HPrnFile = INVALID_HANDLE_VALUE;
676 maya 3392 SetTimer(HVTWin,IdPrnStartTimer,ts.PassThruDelay*1000,NULL);
677 maya 3227 }
678    
679     void WriteToPrnFile(BYTE b, BOOL Write)
680     // (b,Write) =
681     // (0,FALSE): clear buffer
682     // (0,TRUE): write buffer to file
683     // (b,FALSE): put b in buff
684     // (b,TRUE): put b in buff and
685     // write buffer to file
686     {
687 maya 3392 if ((b>0) && (PrnBuffCount<sizeof(PrnBuff))) {
688     PrnBuff[PrnBuffCount++] = b;
689     }
690 maya 3227
691 maya 3392 if (Write) {
692 zmatsuo 9039 DWORD NumberOfBytesWritten;
693     WriteFile(HPrnFile, PrnBuff, PrnBuffCount, &NumberOfBytesWritten, NULL);
694 maya 3392 PrnBuffCount = 0;
695     }
696     if ((b==0) && ! Write) {
697     PrnBuffCount = 0;
698     }
699 maya 3227 }

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