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 9309 - (hide annotations) (download) (as text)
Sat Jun 12 15:29:57 2021 UTC (2 years, 9 months ago) by zmatsuo
File MIME type: text/x-c++src
File size: 18175 byte(s)
layer_for_unicodeを使用するよう修正
1 doda 6806 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3 nmaya 9048 * (C) 2007- TeraTerm Project
4 doda 6806 * 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 9115 #define _CRTDBG_MAP_ALLOC
36     #include <stdlib.h>
37 zmatsuo 7936 #include <crtdbg.h>
38 maya 3227
39     #include "ttwinman.h"
40     #include "commlib.h"
41     #include "ttcommon.h"
42     #include "ttlib.h"
43 zmatsuo 9115 #include "codeconv.h"
44 zmatsuo 9040 #include "vtdisp.h"
45 zmatsuo 9309 #include "layer_for_unicode.h"
46 maya 3227
47     #include "tt_res.h"
48 zmatsuo 7528 #include "tmfc.h"
49 maya 3227 #include "prnabort.h"
50    
51     #include "teraprn.h"
52    
53 zmatsuo 7936 #ifdef _DEBUG
54     #if defined(_MSC_VER)
55     #define new ::new(_NORMAL_BLOCK, __FILE__, __LINE__)
56 maya 3227 #endif
57 zmatsuo 7936 #endif
58 maya 3227
59     static HDC PrintDC;
60     static HFONT PrnFont[AttrFontMask+1];
61     static int PrnFW, PrnFH;
62     static RECT Margin;
63     static COLORREF White, Black;
64     static int PrnX, PrnY;
65     static TCharAttr PrnAttr;
66    
67     static BOOL Printing = FALSE;
68     static BOOL PrintAbortFlag = FALSE;
69    
70     static CPrnAbortDlg *PrnAbortDlg;
71     static HWND HPrnAbortDlg;
72    
73 zmatsuo 9040 static void PrnSetAttr(TCharAttr Attr);
74    
75 maya 3227 /* Print Abortion Call Back Function */
76 zmatsuo 7933 static BOOL CALLBACK PrnAbortProc(HDC PDC, int Code)
77 maya 3227 {
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 yutakapon 8331 static UINT_PTR CALLBACK PrintHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
97     {
98     return 0;
99     }
100    
101 maya 3227 HDC PrnBox(HWND HWin, PBOOL Sel)
102     {
103 maya 3392 /* initialize PrnDlg record */
104 zmatsuo 9038 PRINTDLGW PrnDlg = {};
105     PrnDlg.lStructSize = sizeof(PrnDlg);
106 maya 3392 PrnDlg.hwndOwner = HWin;
107 yutakapon 8331 PrnDlg.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_SHOWHELP | PD_ENABLEPRINTHOOK;
108 maya 3392 if (! *Sel) {
109 yutakapon 5196 PrnDlg.Flags = PrnDlg.Flags | PD_NOSELECTION; /* when there is nothing select, gray out the "Selection" radio button */
110     } else {
111     PrnDlg.Flags = PrnDlg.Flags | PD_SELECTION; /* when there is something select, select the "Selection" radio button by default */
112 maya 3392 }
113     PrnDlg.nCopies = 1;
114 yutakapon 8331 /*
115     * Windows NT�n���������A�����_�C�A���O���w���v�{�^�����\�����������A
116     * �v���V�[�W�����t�b�N�����B
117     */
118     PrnDlg.lpfnPrintHook = PrintHookProc;
119 maya 3227
120 maya 3392 /* 'Print' dialog box */
121 zmatsuo 9038 if (! PrintDlgW(&PrnDlg)) {
122 maya 3392 return NULL; /* if 'Cancel' button clicked, exit */
123     }
124     if (PrnDlg.hDC == NULL) {
125     return NULL;
126     }
127     *Sel = (PrnDlg.Flags & PD_SELECTION) != 0;
128 zmatsuo 9038 return PrnDlg.hDC;
129 maya 3227 }
130    
131     BOOL PrnStart(LPSTR DocumentName)
132     {
133 zmatsuo 7527 DOCINFOA Doc;
134 maya 3392 char DocName[50];
135 zmatsuo 7933 HWND hParent;
136 maya 3227
137 maya 3392 Printing = FALSE;
138     PrintAbortFlag = FALSE;
139 maya 3227
140 maya 3392 PrnAbortDlg = new CPrnAbortDlg();
141     if (PrnAbortDlg==NULL) {
142     return FALSE;
143     }
144     if (ActiveWin==IdVT) {
145 zmatsuo 7933 hParent = HVTWin;
146 maya 3392 }
147     else {
148 zmatsuo 7933 hParent = HTEKWin;
149 maya 3392 }
150 zmatsuo 7933 PrnAbortDlg->Create(hInst,hParent,&PrintAbortFlag,&ts);
151 maya 3392 HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd();
152 maya 3227
153 maya 3392 SetAbortProc(PrintDC,PrnAbortProc);
154 maya 3227
155 zmatsuo 7527 Doc.cbSize = sizeof(Doc);
156 maya 3392 strncpy_s(DocName,sizeof(DocName),DocumentName,_TRUNCATE);
157     Doc.lpszDocName = DocName;
158     Doc.lpszOutput = NULL;
159     Doc.lpszDatatype = NULL;
160     Doc.fwType = 0;
161 zmatsuo 7527 if (StartDocA(PrintDC, &Doc) > 0) {
162 maya 3392 Printing = TRUE;
163     }
164     else {
165     if (PrnAbortDlg != NULL) {
166     PrnAbortDlg->DestroyWindow();
167     PrnAbortDlg = NULL;
168     HPrnAbortDlg = NULL;
169     }
170     }
171     return Printing;
172 maya 3227 }
173    
174     void PrnStop()
175     {
176 maya 3392 if (Printing) {
177     EndDoc(PrintDC);
178     DeleteDC(PrintDC);
179     Printing = FALSE;
180     }
181     if (PrnAbortDlg != NULL) {
182     PrnAbortDlg->DestroyWindow();
183     PrnAbortDlg = NULL;
184     HPrnAbortDlg = NULL;
185     }
186 maya 3227 }
187    
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 zmatsuo 9040 TCharAttr TempAttr = DefCharAttr;
207 zmatsuo 9038 LOGFONTA Prnlf;
208 maya 3227
209 maya 3392 Sel = (PrnFlag & IdPrnSelectedText)!=0;
210 zmatsuo 9038 PrintDC = PrnBox(HVTWin,&Sel);
211     if (PrintDC == NULL) {
212 maya 3392 return (IdPrnCancel);
213     }
214 maya 3227
215 maya 3392 /* start printing */
216     if (! PrnStart(ts.Title)) {
217     return (IdPrnCancel);
218     }
219 maya 3227
220 maya 3392 /* initialization */
221     StartPage(PrintDC);
222 maya 3227
223 maya 3392 /* pixels per inch */
224     if ((ts.VTPPI.x>0) && (ts.VTPPI.y>0)) {
225     PPI = ts.VTPPI;
226     }
227     else {
228     PPI.x = GetDeviceCaps(PrintDC,LOGPIXELSX);
229     PPI.y = GetDeviceCaps(PrintDC,LOGPIXELSY);
230     }
231 maya 3227
232 maya 3392 /* left margin */
233     Margin.left = (int)((float)ts.PrnMargin[0] / 100.0 * (float)PPI.x);
234     /* right margin */
235     Margin.right = GetDeviceCaps(PrintDC,HORZRES) -
236     (int)((float)ts.PrnMargin[1] / 100.0 * (float)PPI.x);
237     /* top margin */
238     Margin.top = (int)((float)ts.PrnMargin[2] / 100.0 * (float)PPI.y);
239     /* bottom margin */
240     Margin.bottom = GetDeviceCaps(PrintDC,VERTRES) -
241     (int)((float)ts.PrnMargin[3] / 100.0 * (float)PPI.y);
242 maya 3227
243 maya 3392 /* create test font */
244 zmatsuo 7527 memset(&Prnlf, 0, sizeof(Prnlf));
245 maya 3227
246 maya 3392 if (ts.PrnFont[0]==0) {
247     Prnlf.lfHeight = ts.VTFontSize.y;
248     Prnlf.lfWidth = ts.VTFontSize.x;
249     Prnlf.lfCharSet = ts.VTFontCharSet;
250     strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName), ts.VTFont, _TRUNCATE);
251     }
252     else {
253     Prnlf.lfHeight = ts.PrnFontSize.y;
254     Prnlf.lfWidth = ts.PrnFontSize.x;
255     Prnlf.lfCharSet = ts.PrnFontCharSet;
256     strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName), ts.PrnFont, _TRUNCATE);
257     }
258     Prnlf.lfWeight = FW_NORMAL;
259     Prnlf.lfItalic = 0;
260     Prnlf.lfUnderline = 0;
261     Prnlf.lfStrikeOut = 0;
262     Prnlf.lfOutPrecision = OUT_CHARACTER_PRECIS;
263     Prnlf.lfClipPrecision = CLIP_CHARACTER_PRECIS;
264     Prnlf.lfQuality = DEFAULT_QUALITY;
265     Prnlf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
266 maya 3227
267 zmatsuo 7527 PrnFont[0] = CreateFontIndirectA(&Prnlf);
268 maya 3227
269 maya 3392 DC = GetDC(HVTWin);
270     SelectObject(DC, PrnFont[0]);
271     GetTextMetrics(DC, &Metrics);
272     PPI2.x = GetDeviceCaps(DC,LOGPIXELSX);
273     PPI2.y = GetDeviceCaps(DC,LOGPIXELSY);
274     ReleaseDC(HVTWin,DC);
275     DeleteObject(PrnFont[0]); /* Delete test font */
276 maya 3227
277 maya 3392 /* Adjust font size */
278     Prnlf.lfHeight = (int)((float)Metrics.tmHeight * (float)PPI.y / (float)PPI2.y);
279     Prnlf.lfWidth = (int)((float)Metrics.tmAveCharWidth * (float)PPI.x / (float)PPI2.x);
280 maya 3227
281 maya 3392 /* Create New Fonts */
282 maya 3227
283 maya 3392 /* Normal Font */
284     Prnlf.lfWeight = FW_NORMAL;
285     Prnlf.lfUnderline = 0;
286 zmatsuo 7527 PrnFont[0] = CreateFontIndirectA(&Prnlf);
287 maya 3392 SelectObject(PrintDC,PrnFont[0]);
288     GetTextMetrics(PrintDC, &Metrics);
289     PrnFW = Metrics.tmAveCharWidth;
290     PrnFH = Metrics.tmHeight;
291     /* Under line */
292     Prnlf.lfUnderline = 1;
293 zmatsuo 7527 PrnFont[AttrUnder] = CreateFontIndirectA(&Prnlf);
294 maya 3227
295 doda 3666 if (ts.FontFlag & FF_BOLD) {
296 maya 3392 /* Bold */
297     Prnlf.lfUnderline = 0;
298     Prnlf.lfWeight = FW_BOLD;
299 zmatsuo 7527 PrnFont[AttrBold] = CreateFontIndirectA(&Prnlf);
300 maya 3392 /* Bold + Underline */
301     Prnlf.lfUnderline = 1;
302 zmatsuo 7527 PrnFont[AttrBold | AttrUnder] = CreateFontIndirectA(&Prnlf);
303 maya 3392 }
304     else {
305     PrnFont[AttrBold] = PrnFont[AttrDefault];
306     PrnFont[AttrBold | AttrUnder] = PrnFont[AttrUnder];
307     }
308     /* Special font */
309     Prnlf.lfWeight = FW_NORMAL;
310     Prnlf.lfUnderline = 0;
311     Prnlf.lfWidth = PrnFW; /* adjust width */
312     Prnlf.lfHeight = PrnFH;
313     Prnlf.lfCharSet = SYMBOL_CHARSET;
314 maya 3227
315 maya 3392 strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName),"Tera Special", _TRUNCATE);
316 zmatsuo 7527 PrnFont[AttrSpecial] = CreateFontIndirectA(&Prnlf);
317 maya 3392 PrnFont[AttrSpecial | AttrBold] = PrnFont[AttrSpecial];
318     PrnFont[AttrSpecial | AttrUnder] = PrnFont[AttrSpecial];
319     PrnFont[AttrSpecial | AttrBold | AttrUnder] = PrnFont[AttrSpecial];
320 maya 3227
321 maya 3392 Black = RGB(0,0,0);
322     White = RGB(255,255,255);
323     PrnSetAttr(TempAttr);
324 maya 3227
325 maya 3392 PrnY = Margin.top;
326     PrnX = Margin.left;
327 maya 3227
328 maya 3392 if (PrnFlag == IdPrnScrollRegion) {
329     return (IdPrnScrollRegion);
330     }
331     if (PrnFlag == IdPrnFile) {
332     return (IdPrnFile);
333     }
334     if (Sel) {
335     return (IdPrnSelectedText);
336     }
337     else {
338     return (IdPrnScreen);
339     }
340 maya 3227 }
341 zmatsuo 7291
342 zmatsuo 9040 static void PrnSetAttr(TCharAttr Attr)
343 maya 3227 // Set text attribute of printing
344     //
345     {
346 maya 3392 PrnAttr = Attr;
347     SelectObject(PrintDC, PrnFont[Attr.Attr & AttrFontMask]);
348 maya 3227
349 maya 3392 if ((Attr.Attr & AttrReverse) != 0) {
350     SetTextColor(PrintDC,White);
351     SetBkColor( PrintDC,Black);
352     }
353     else {
354     SetTextColor(PrintDC,Black);
355     SetBkColor( PrintDC,White);
356     }
357 maya 3227 }
358    
359 zmatsuo 9040 void PrnSetupDC(TCharAttr Attr, BOOL reverse)
360 maya 3227 {
361 zmatsuo 9040 (void)reverse;
362     PrnSetAttr(Attr);
363     }
364 maya 3227
365 zmatsuo 9040 /**
366     * Print out text
367     * Buff: points text buffer
368     * Count: number of characters to be printed
369     */
370     void PrnOutText(const char *StrA, int Count, void *data)
371     {
372     if (PrnX+PrnFW > Margin.right) {
373     /* new line */
374     PrnX = Margin.left;
375     PrnY = PrnY + PrnFH;
376 maya 3392 }
377 zmatsuo 9040 if (PrnY+PrnFH > Margin.bottom) {
378     /* next page */
379     EndPage(PrintDC);
380     StartPage(PrintDC);
381     PrnSetAttr(PrnAttr);
382     PrnY = Margin.top;
383 maya 3392 }
384 maya 3227
385 zmatsuo 9040 DrawStrA(PrintDC, NULL, StrA, Count, PrnFW, PrnFH, PrnY, &PrnX);
386     }
387    
388     void PrnOutTextW(const wchar_t *StrW, const char *WidthInfo, int Count, void *data)
389     {
390     if (PrnX+PrnFW > Margin.right) {
391     /* new line */
392     PrnX = Margin.left;
393     PrnY = PrnY + PrnFH;
394 maya 3392 }
395 zmatsuo 9040 if (PrnY+PrnFH > Margin.bottom) {
396     /* next page */
397     EndPage(PrintDC);
398     StartPage(PrintDC);
399     PrnSetAttr(PrnAttr);
400     PrnY = Margin.top;
401     }
402 maya 3227
403 zmatsuo 9040 DrawStrW(PrintDC, NULL, StrW, WidthInfo, Count, PrnFW, PrnFH, PrnY, &PrnX);
404 maya 3227 }
405    
406     void PrnNewLine()
407     // Moves to the next line in printing
408     {
409 maya 3392 PrnX = Margin.left;
410     PrnY = PrnY + PrnFH;
411 maya 3227 }
412    
413     void VTPrintEnd()
414     {
415 maya 3392 int i, j;
416 maya 3227
417 maya 3392 EndPage(PrintDC);
418 maya 3227
419 maya 3392 for (i = 0 ; i <= AttrFontMask ; i++) {
420     for (j = i+1 ; j <= AttrFontMask ; j++) {
421     if (PrnFont[j]==PrnFont[i]) {
422     PrnFont[j] = NULL;
423     }
424     }
425     if (PrnFont[i] != NULL) {
426     DeleteObject(PrnFont[i]);
427     }
428     }
429 maya 3227
430 maya 3392 PrnStop();
431     return;
432 maya 3227 }
433    
434 zmatsuo 9115 /* pass-thru printing */
435     typedef struct PrintFileTag {
436     wchar_t *PrnFName;
437     HANDLE HPrnFile;
438     unsigned int PrnBuff[TermWidthMax*2];
439     int PrnBuffCount;
440     void (*FinishCallback)(PrintFile *handle);
441     } PrintFile;
442    
443 maya 3227 /* printer emulation routines */
444 zmatsuo 9115 PrintFile *OpenPrnFile(void)
445 maya 3227 {
446 zmatsuo 9115 PrintFile *p = (PrintFile *)calloc(sizeof(PrintFile),1 );
447     if (p == NULL) {
448     return NULL;
449     }
450    
451 zmatsuo 9039 KillTimer(HVTWin, IdPrnStartTimer);
452 zmatsuo 9115
453     wchar_t TempPath[MAX_PATH];
454 zmatsuo 9309 _GetTempPathW(_countof(TempPath), TempPath);
455 zmatsuo 9115 wchar_t Temp[MAX_PATH];
456 zmatsuo 9309 if (_GetTempFileNameW(TempPath, L"tmp", 0, Temp) == 0) {
457 zmatsuo 9115 free(p);
458     return NULL;
459 maya 3392 }
460 zmatsuo 9115 p->PrnFName = _wcsdup(Temp);
461    
462 zmatsuo 9309 HANDLE h = _CreateFileW(p->PrnFName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
463 zmatsuo 9115 if (h == INVALID_HANDLE_VALUE) {
464     free(p);
465     return NULL;
466 maya 3392 }
467 zmatsuo 9115 SetFilePointer(h, 0, NULL, FILE_END);
468     p->HPrnFile = h;
469    
470     return p;
471     }
472    
473     static void DeletePrintFile(PrintFile *handle)
474     {
475     if (handle->PrnFName == NULL) {
476     return;
477 maya 3392 }
478 zmatsuo 9309 _DeleteFileW(handle->PrnFName);
479 zmatsuo 9115 free(handle->PrnFName);
480     handle->PrnFName = NULL;
481 maya 3227 }
482    
483 zmatsuo 9115 void PrnFinish(PrintFile *handle)
484 maya 3227 {
485 zmatsuo 9115 DeletePrintFile(handle);
486     free(handle);
487     }
488 maya 3227
489 zmatsuo 9115 /**
490     * �����p���������������t�@�C��������������
491     */
492     static void PrintFile_(PrintFile *handle)
493     {
494 maya 3392 if (VTPrintInit(IdPrnFile)==IdPrnFile) {
495 zmatsuo 9309 HANDLE HPrnFile = _CreateFileW(handle->PrnFName,
496     GENERIC_READ, FILE_SHARE_READ, NULL,
497     OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
498 zmatsuo 9039
499 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
500 zmatsuo 9115 char BuffA[TermWidthMax];
501     size_t len_a;
502     wchar_t BuffW[TermWidthMax];
503     size_t len_w;
504     BOOL CRFlag = FALSE;
505     int c;
506     unsigned int u32;
507 maya 3392 do {
508 zmatsuo 9115 len_a = 0;
509     len_w = 0;
510 maya 3392 do {
511 zmatsuo 9039 DWORD NumberOfBytesRead;
512 zmatsuo 9115 BOOL r = ReadFile(HPrnFile, &u32, sizeof(u32), &NumberOfBytesRead, NULL);
513     if (r == TRUE && NumberOfBytesRead != 0) {
514     // �����p��
515     c = 1;
516 zmatsuo 9039 }
517 zmatsuo 9115 else {
518     c = 0;
519     }
520 zmatsuo 9039 if (c == 1) {
521 zmatsuo 9115 switch (u32) {
522 maya 3392 case LF:
523     CRFlag = ! CRFlag;
524     break;
525     case FF:
526     case CR:
527     CRFlag = TRUE;
528     break;
529 zmatsuo 9115 #if 0
530     case HT:
531     memset(&(Buff[i]),0x20,8);
532     i = i + 8;
533     CRFlag = FALSE;
534     break;
535     #endif
536 maya 3392 default:
537 zmatsuo 9115 if (u32 >= 0x20) {
538     int codepage = CP_ACP; // �����p�R�[�h�y�[�W
539     size_t out_len = UTF32ToUTF16(u32, &BuffW[len_w], _countof(BuffW) - len_w);
540     len_w += out_len;
541     out_len = UTF32ToMBCP(u32, codepage, &BuffA[len_a], _countof(BuffA) - len_a);
542     len_a += out_len;
543 maya 3392 }
544     CRFlag = FALSE;
545     break;
546     }
547     }
548 zmatsuo 9115 if (len_w >= (_countof(BuffW)-7)) {
549 maya 3392 CRFlag=TRUE;
550     }
551     } while ((c>0) && (! CRFlag));
552 zmatsuo 9115 if (len_a >0) {
553     PrnOutText(BuffA, len_a, NULL);
554     //PrnOutTextW(BuffW, NULL, len_w, NULL);
555 maya 3392 }
556     if (CRFlag) {
557     PrnX = Margin.left;
558 zmatsuo 9115 if ((u32==FF) && (ts.PrnConvFF==0)) { // new page
559 maya 3392 PrnY = Margin.bottom;
560     }
561     else { // new line
562     PrnY = PrnY + PrnFH;
563     }
564     }
565 zmatsuo 9115 CRFlag = (u32==CR);
566 maya 3392 } while (c>0);
567 zmatsuo 9039 CloseHandle(HPrnFile);
568 maya 3227 }
569 zmatsuo 9039 HPrnFile = INVALID_HANDLE_VALUE;
570 maya 3392 VTPrintEnd();
571 maya 3227 }
572 zmatsuo 9115 handle->FinishCallback(handle);
573 maya 3227 }
574    
575 zmatsuo 9115 static void PrintFileDirect(PrintFile *handle)
576 maya 3227 {
577 zmatsuo 7933 HWND hParent;
578 maya 3227
579 maya 3392 PrnAbortDlg = new CPrnAbortDlg();
580     if (PrnAbortDlg==NULL) {
581 zmatsuo 9115 DeletePrintFile(handle);
582 maya 3392 return;
583     }
584     if (ActiveWin==IdVT) {
585 zmatsuo 7933 hParent = HVTWin;
586 maya 3392 }
587     else {
588 zmatsuo 7933 hParent = HTEKWin;
589 maya 3392 }
590 zmatsuo 7933 PrnAbortDlg->Create(hInst,hParent,&PrintAbortFlag,&ts);
591 maya 3392 HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd();
592 maya 3227
593 zmatsuo 9309 handle->HPrnFile = _CreateFileW(handle->PrnFName,
594     GENERIC_READ, FILE_SHARE_READ, NULL,
595     OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
596 zmatsuo 9115 PrintAbortFlag = (handle->HPrnFile == INVALID_HANDLE_VALUE) || ! PrnOpen(ts.PrnDev);
597     handle->PrnBuffCount = 0;
598 maya 3392 SetTimer(HVTWin,IdPrnProcTimer,0,NULL);
599 maya 3227 }
600    
601 zmatsuo 9115 void PrnFileDirectProc(PrintFile *handle)
602 maya 3227 {
603 zmatsuo 9115 HANDLE HPrnFile = handle->HPrnFile;
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 zmatsuo 9115 int c;
614 maya 3392 do {
615 zmatsuo 9115 if (handle->PrnBuffCount==0) {
616     handle->PrnBuffCount = 0;
617 zmatsuo 9039 DWORD NumberOfBytesRead;
618 zmatsuo 9115 BOOL r = ReadFile(HPrnFile, handle->PrnBuff, sizeof(handle->PrnBuff[0]), &NumberOfBytesRead, NULL);
619 zmatsuo 9039 if (r) {
620 zmatsuo 9115 handle->PrnBuffCount = NumberOfBytesRead;
621 zmatsuo 9039 }
622 maya 3392 }
623 maya 3227
624 zmatsuo 9115 if (handle->PrnBuffCount != 0) {
625     // UTF-32
626     unsigned int u32 = handle->PrnBuff[0];
627     int codepage = CP_ACP; // �����p�R�[�h�y�[�W
628     char str[5];
629     size_t out_len = UTF32ToMBCP(u32, codepage, str, _countof(str));
630     c = PrnWrite(str, out_len);
631 maya 3392 if (c==0) {
632     SetTimer(HVTWin,IdPrnProcTimer,10,NULL);
633     return;
634     }
635 zmatsuo 9115 handle->PrnBuffCount = 0;
636 maya 3392 }
637     else {
638     c = 0;
639     }
640     } while (c>0);
641 maya 3227 }
642 maya 3392 PrnClose();
643 zmatsuo 9115
644 maya 3392 if (PrnAbortDlg!=NULL) {
645     PrnAbortDlg->DestroyWindow();
646     PrnAbortDlg = NULL;
647     HPrnAbortDlg = NULL;
648     }
649 zmatsuo 9115
650     handle->FinishCallback(handle);
651 maya 3227 }
652    
653 zmatsuo 9115 /**
654     * �^�C�}�[�������o���A�������J�n����
655     * ClosePrnFile() �� SetTimer(IdPrnStartTimer) ���g���K
656     */
657     void PrnFileStart(PrintFile *handle)
658 maya 3227 {
659 zmatsuo 9115 if (handle->HPrnFile != INVALID_HANDLE_VALUE) {
660 maya 3392 return;
661     }
662 zmatsuo 9115 if (handle->PrnFName == NULL) {
663 maya 3392 return;
664     }
665     if (ts.PrnDev[0]!=0) {
666 zmatsuo 9115 PrintFileDirect(handle); // send file directry to printer port
667 maya 3392 }
668     else { // print file by using Windows API
669 zmatsuo 9115 PrintFile_(handle);
670 maya 3392 }
671 maya 3227 }
672    
673 zmatsuo 9115 /**
674     * �v�����g�p�t�@�C���������������I��
675     * �v�����g���J�n�^�C�}�[���Z�b�g����
676     */
677     void ClosePrnFile(PrintFile *handle, void (*finish_callback)(PrintFile *handle))
678 maya 3227 {
679 zmatsuo 9115 PrintFile *p = handle;
680     p->PrnBuffCount = 0;
681     p->FinishCallback = finish_callback;
682     if (p->HPrnFile != INVALID_HANDLE_VALUE) {
683     CloseHandle(p->HPrnFile);
684     p->HPrnFile = INVALID_HANDLE_VALUE;
685 maya 3392 }
686     SetTimer(HVTWin,IdPrnStartTimer,ts.PassThruDelay*1000,NULL);
687 maya 3227 }
688    
689 zmatsuo 9115 /**
690     * (b,Write) =
691     * (0,FALSE): clear buffer
692     * (0,TRUE): write buffer to file
693     * (b,FALSE): put b in buff
694     * (b,TRUE): put b in buff and
695     * write buffer to file
696     */
697     void WriteToPrnFileUTF32(PrintFile *handle, unsigned int u32, BOOL Write)
698 maya 3227 {
699 zmatsuo 9115 PrintFile *p = handle;
700     if ((u32 > 0) && p->PrnBuffCount < _countof(p->PrnBuff)) {
701     p->PrnBuff[p->PrnBuffCount++] = u32;
702 maya 3392 }
703 maya 3227
704 maya 3392 if (Write) {
705 zmatsuo 9039 DWORD NumberOfBytesWritten;
706 zmatsuo 9115 WriteFile(p->HPrnFile, p->PrnBuff, sizeof(p->PrnBuff[0]) * p->PrnBuffCount, &NumberOfBytesWritten, NULL);
707     p->PrnBuffCount = 0;
708 maya 3392 }
709 zmatsuo 9115 if ((u32 == 0) && !Write) {
710     p->PrnBuffCount = 0;
711 maya 3392 }
712 maya 3227 }
713 zmatsuo 9115
714     void WriteToPrnFile(PrintFile *handle, BYTE b, BOOL Write)
715     {
716     WriteToPrnFileUTF32(handle, b, Write);
717     }

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