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 10345 - (hide annotations) (download) (as text)
Wed Nov 2 13:43:19 2022 UTC (17 months, 1 week ago) by zmatsuo
File MIME type: text/x-c++src
File size: 18706 byte(s)
TERATERM.INI の UnknownUnicodeCharacterAsWide を削除

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

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