Revision: 9040 https://osdn.net/projects/ttssh2/scm/svn/commits/9040 Author: zmatsuo Date: 2020-11-30 00:26:40 +0900 (Mon, 30 Nov 2020) Log Message: ----------- [ファイル]/[印刷]からの印刷をUnicodeに対応した - 文字描画関数 DrawStrW(), DrawStrA() を vtdisp.c に追加 - 画面描画、印刷から利用 - vtwinで背景付きのとき描画が乱れていたのを修正 - DispStr(), PrnOutText() 内で描画時にキリル文字変換を行っていたのを削除 - RussConvStr() - 従来も無効化していた - 内部バッファに文字をUnicodeで保存したときに、表示に適したANSI文字コードに変換して保存している Modified Paths: -------------- trunk/teraterm/teraterm/buffer.c trunk/teraterm/teraterm/teraprn.cpp trunk/teraterm/teraterm/teraprn.h trunk/teraterm/teraterm/vtdisp.c trunk/teraterm/teraterm/vtdisp.h -------------- next part -------------- Modified: trunk/teraterm/teraterm/buffer.c =================================================================== --- trunk/teraterm/teraterm/buffer.c 2020-11-29 15:26:29 UTC (rev 9039) +++ trunk/teraterm/teraterm/buffer.c 2020-11-29 15:26:40 UTC (rev 9040) @@ -118,6 +118,7 @@ static int CodePage = 932; static void BuffDrawLineI(int DrawX, int DrawY, int SY, int IStart, int IEnd); +static void BuffDrawLineIPrn(int SY, int IStart, int IEnd); static void BuffSetChar2(buff_char_t *buff, char32_t u32, char property, BOOL half_width, char emoji) { @@ -2030,8 +2031,8 @@ { int Id; POINT PrintStart, PrintEnd; - TCharAttr CurAttr, TempAttr; - int i, j, count; + TCharAttr TempAttr; + int j; int IStart, IEnd; LONG TmpPtr; @@ -2091,58 +2092,7 @@ IEnd = NumOfColumns - 1; } - while ((IEnd>=IStart) && - (CodeBuffW[TmpPtr+IEnd].u32 == 0x20) && - (CodeBuffW[TmpPtr+IEnd].attr==AttrDefault) && - (CodeBuffW[TmpPtr+IEnd].attr2==AttrDefault)) { - IEnd--; - } - - i = IStart; - while (i <= IEnd) { - CurAttr.Attr = CodeBuffW[TmpPtr+i].attr & ~ AttrKanji; - CurAttr.Attr2 = CodeBuffW[TmpPtr+i].attr2; - CurAttr.Fore = CodeBuffW[TmpPtr+i].fg; - CurAttr.Back = CodeBuffW[TmpPtr+i].bg; - - count = 1; - while ((i+count <= IEnd) && - (CurAttr.Attr == (CodeBuffW[TmpPtr+i+count].attr & ~ AttrKanji)) && - (CurAttr.Attr2 == CodeBuffW[TmpPtr+i+count].attr2) && - (CurAttr.Fore == CodeBuffW[TmpPtr+i].fg) && - (CurAttr.Back == CodeBuffW[TmpPtr+i].bg) || - (i+count<NumOfColumns) && - ((CodeBuffW[TmpPtr+i+count-1].attr & AttrKanji) != 0)) { - count++; - } - - if (TCharAttrCmp(CurAttr, TempAttr) != 0) { - PrnSetAttr(CurAttr); - TempAttr = CurAttr; - } - - // TODO \x82Ƃ肠\x82\xA6\x82\xB8 ANSI \x82Ŏ\xC0\x91\x95 - { - char bufA[TermWidthMax+1]; - int k; - char *p = bufA; - const buff_char_t *b = &CodeBuffW[TmpPtr + i]; - - for (k = 0; k < count; b++,k++) { - unsigned short c; - if (IsBuffPadding(b)) { - continue; - } - c = b->ansi_char; - *p++ = (c & 0xff); - if (c >= 0x100) { - *p++ = ((c >> 8) & 0xff); - } - } - PrnOutText(bufA, count); - i = i+count; - } - } + BuffDrawLineIPrn(j, IStart, IEnd); PrnNewLine(); TmpPtr = NextLinePtr(TmpPtr); } @@ -3083,16 +3033,21 @@ /** * 1\x8Ds\x95`\x89\xE6 * - * @param DrawX,Y Clint\x97̈\xE6\x95`\x89\xE6\x88ʒu(pixel) * @param SY \x83X\x83N\x83\x8A\x81[\x83\x93\x8F\xE3\x82̈ʒu(Charactor) !\x83o\x83b\x83t\x83@\x8F\xE3\x82̈ʒu * PageStart + YStart \x82Ȃ\xC7 * @param IStart,IEnd \x83X\x83N\x83\x8A\x81[\x83\x93\x8F\xE3\x82̈ʒu(Charactor) * \x8Ew\x92肵\x82\xBD\x8AԂ\xF0\x95`\x89悷\x82\xE9 + * @param disp_strW() wchar_t \x95\xB6\x8E\x9A\x82\xF0\x95`\x89\xE6\x97p\x8A\x94 (Unicode\x97p) + * @param disp_strA() char \x95\xB6\x8E\x9A\x82\xF0\x95`\x89\xE6\x97p\x8A\x94 (ANSI\x97p) + * @param disp_setup_dc() \x83A\x83g\x83\x8A\x83r\x83\x85\x81[\x83g\x90ݒ\xE8\x8A\x94 + * @param data disp_strW(A)() \x82ɓn\x82\xB3\x82\xEA\x82\xE9\x83f\x81[\x83^ */ -static void BuffDrawLineI(int DrawX, int DrawY, int SY, int IStart, int IEnd) +void BuffGetDrawInfoW(int SY, int IStart, int IEnd, + void (*disp_strW)(const wchar_t *bufW, const char *width_info, int count, void *data), + void (*disp_strA)(const char *buf, int count, void *data), + void (*disp_setup_dc)(TCharAttr Attr, BOOL Reverse), + void *data) { - int X = DrawX; - int Y = DrawY; const LONG TmpPtr = GetLinePtr(SY); int istart = IStart; char bufA[TermWidthMax+1]; @@ -3108,23 +3063,6 @@ #if 0 OutputDebugPrintf("BuffDrawLineI(%d,%d, %d,%d-%d)\n", DrawX, DrawY, SY, IStart, IEnd); #endif - { - // \x83J\x81[\x83\\x83\x8B\x88ʒu\x81A\x95\\x8E\xA6\x8AJ\x8En\x88ʒu\x82\xA9\x82\xE7\x95`\x89\xE6\x88ʒu\x82\xAA\x82킩\x82\xE9\x82͂\xB8 - int X2 = IStart; - int Y2 = SY - PageStart; - if (! IsLineVisible(&X2, &Y2)) { - // \x95`\x89\xE6\x95s\x97v\x8Ds - //assert(FALSE); - return; - } - if (X != -1 && Y != -1) { - assert(X == X2 && Y == Y2); - } - else { - X = X2; - Y = Y2; - } - } if (IEnd >= NumOfColumns) { IEnd = NumOfColumns - 1; } @@ -3140,7 +3078,8 @@ // \x8Dŏ\x89\x82\xCC1\x95\xB6\x8E\x9A\x96\xDA int ptr = TmpPtr + istart + count; if (IsBuffPadding(b)) { - // \x8Dŏ\x89\x82ɕ\\x8E\xA6\x82\xB5\x82悤\x82Ƃ\xB5\x82\xBD\x95\xB6\x8E\x9A\x82\xAA\x91S\x8Ap\x82̉E\x82\xBE\x82\xC1\x82\xBD\x8Fꍇ + // \x8Dŏ\x89\x82ɕ\\x8E\xA6\x82\xB5\x82悤\x82Ƃ\xB5\x82\xBD\x95\xB6\x8E\x9A\x82\xAA2cell\x82̉E\x91\xA4\x82\xBE\x82\xC1\x82\xBD\x8Fꍇ + // assert(FALSE); ptr--; } CurAttr.Attr = CodeBuffW[ptr].attr & ~ AttrKanji; @@ -3152,7 +3091,7 @@ } if (IsBuffPadding(b)) { - // \x91S\x8Ap\x82̎\x9F\x82̕\xB6\x8E\x9A,\x8F\x88\x97\x9D\x95s\x97v + // 2cell\x82̎\x9F\x82̕\xB6\x8E\x9A,\x8F\x88\x97\x9D\x95s\x97v } else { if (count == 0) { // \x8Dŏ\x89\x82\xCC1\x95\xB6\x8E\x9A\x96\xDA @@ -3235,12 +3174,12 @@ OutputDebugPrintfW(L"W[%d] '%s'\n", lenW, bufW); #endif - DispSetupDC(CurAttr, CurSelected); + disp_setup_dc(CurAttr, CurSelected); if (UseUnicodeApi) { - DispStrW(bufW, bufWW, lenW, Y, &X); + disp_strW(bufW, bufWW, lenW, data); } else { - DispStr(bufA, lenA, Y, &X); + disp_strA(bufA, lenA, data); } lenA = 0; @@ -3254,6 +3193,89 @@ } } +typedef struct { + int draw_x; + int draw_y; +} disp_data_t; + +static void l_disp_strW(const wchar_t *bufW, const char *width_info, int count, void *data_) +{ + disp_data_t *data = (disp_data_t *)data_; + int x = data->draw_x; + int y = data->draw_y; + DispStrW(bufW, width_info, count, y, &x); + data->draw_x = x; +} + +static void l_disp_strA(const char *buf, int count, void *data_) +{ + disp_data_t *data = (disp_data_t *)data_; + int x = data->draw_x; + int y = data->draw_y; + DispStr(buf, count, y, &x); + data->draw_x = x; +} + +/** + * 1\x8Ds\x95`\x89\xE6 \x89\xE6\x96ʗp + * + * @param DrawX,Y Clint\x97̈\xE6\x95`\x89\xE6\x88ʒu(pixel) + * @param SY \x83X\x83N\x83\x8A\x81[\x83\x93\x8F\xE3\x82̈ʒu(Charactor) !\x83o\x83b\x83t\x83@\x8F\xE3\x82̈ʒu + * PageStart + YStart \x82Ȃ\xC7 + * @param IStart,IEnd \x83X\x83N\x83\x8A\x81[\x83\x93\x8F\xE3\x82̈ʒu(Charactor) + * \x8Ew\x92肵\x82\xBD\x8AԂ\xF0\x95`\x89悷\x82\xE9 + */ +static void BuffDrawLineI(int DrawX, int DrawY, int SY, int IStart, int IEnd) +{ + int X = DrawX; + int Y = DrawY; + { + // \x83J\x81[\x83\\x83\x8B\x88ʒu\x81A\x95\\x8E\xA6\x8AJ\x8En\x88ʒu\x82\xA9\x82\xE7\x95`\x89\xE6\x88ʒu\x82\xAA\x82킩\x82\xE9\x82͂\xB8 + int X2 = IStart; + int Y2 = SY - PageStart; + if (! IsLineVisible(&X2, &Y2)) { + // \x95`\x89\xE6\x95s\x97v\x8Ds + //assert(FALSE); + return; + } + if (X != -1 && Y != -1) { + assert(X == X2 && Y == Y2); + } + else { + X = X2; + Y = Y2; + } + } + if (IEnd >= NumOfColumns) { + IEnd = NumOfColumns - 1; + } + + { + disp_data_t data; + data.draw_x = X; + data.draw_y = Y; + + BuffGetDrawInfoW(SY, IStart, IEnd, l_disp_strW, l_disp_strA, DispSetupDC, &data); + } +} + +/** + * 1\x8Ds\x95`\x89\xE6 \x83v\x83\x8A\x83\x93\x83^\x97p + * + * @param SY \x83X\x83N\x83\x8A\x81[\x83\x93\x8F\xE3\x82̈ʒu(Charactor) !\x83o\x83b\x83t\x83@\x8F\xE3\x82̈ʒu + * PageStart + YStart \x82Ȃ\xC7 + * @param IStart,IEnd \x83X\x83N\x83\x8A\x81[\x83\x93\x8F\xE3\x82̈ʒu(Charactor) + * \x8Ew\x92肵\x82\xBD\x8AԂ\xF0\x95`\x89悷\x82\xE9 + */ +static void BuffDrawLineIPrn(int SY, int IStart, int IEnd) +{ + if (IEnd >= NumOfColumns) { + IEnd = NumOfColumns - 1; + } + + BuffGetDrawInfoW(SY, IStart, IEnd, PrnOutTextW, PrnOutText, PrnSetupDC, NULL); +} + void BuffUpdateRect (int XStart, int YStart, int XEnd, int YEnd) // Display text in a rectangular region in the screen @@ -5279,7 +5301,7 @@ return -1; memset(buf, 0, bufsize * sizeof(wchar_t)); - copysize = min(NumOfColumns, bufsize - 1); + copysize = min((size_t)NumOfColumns, bufsize - 1); Ptr = GetLinePtr(offset_y); b = &CodeBuffW[Ptr]; idx = 0; Modified: trunk/teraterm/teraterm/teraprn.cpp =================================================================== --- trunk/teraterm/teraterm/teraprn.cpp 2020-11-29 15:26:29 UTC (rev 9039) +++ trunk/teraterm/teraterm/teraprn.cpp 2020-11-29 15:26:40 UTC (rev 9040) @@ -38,7 +38,7 @@ #include "commlib.h" #include "ttcommon.h" #include "ttlib.h" -//#include "win16api.h" +#include "vtdisp.h" #include "tt_res.h" #include "tmfc.h" @@ -58,7 +58,6 @@ static RECT Margin; static COLORREF White, Black; static int PrnX, PrnY; -static int PrnDx[256]; static TCharAttr PrnAttr; static BOOL Printing = FALSE; @@ -73,6 +72,8 @@ static CPrnAbortDlg *PrnAbortDlg; static HWND HPrnAbortDlg; +static void PrnSetAttr(TCharAttr Attr); + /* Print Abortion Call Back Function */ static BOOL CALLBACK PrnAbortProc(HDC PDC, int Code) { @@ -204,13 +205,7 @@ TEXTMETRIC Metrics; POINT PPI, PPI2; HDC DC; - int i; - TCharAttr TempAttr = { - AttrDefault, - AttrDefault, - AttrDefaultFG, - AttrDefaultBG - }; + TCharAttr TempAttr = DefCharAttr; LOGFONTA Prnlf; Sel = (PrnFlag & IdPrnSelectedText)!=0; @@ -327,9 +322,6 @@ Black = RGB(0,0,0); White = RGB(255,255,255); - for (i = 0 ; i <= 255 ; i++) { - PrnDx[i] = PrnFW; - } PrnSetAttr(TempAttr); PrnY = Margin.top; @@ -349,7 +341,7 @@ } } -void PrnSetAttr(TCharAttr Attr) +static void PrnSetAttr(TCharAttr Attr) // Set text attribute of printing // { @@ -366,79 +358,51 @@ } } -void PrnOutText(PCHAR Buff, int Count) -// Print out text -// Buff: points text buffer -// Count: number of characters to be printed +void PrnSetupDC(TCharAttr Attr, BOOL reverse) { - int i; - RECT RText; - PCHAR Ptr, Ptr1, Ptr2; - char Buff2[256]; + (void)reverse; + PrnSetAttr(Attr); +} - if (Count<=0) { - return; +/** + * Print out text + * Buff: points text buffer + * Count: number of characters to be printed + */ +void PrnOutText(const char *StrA, int Count, void *data) +{ + if (PrnX+PrnFW > Margin.right) { + /* new line */ + PrnX = Margin.left; + PrnY = PrnY + PrnFH; } - if (Count>(sizeof(Buff2)-1)) { - Count=sizeof(Buff2)-1; + if (PrnY+PrnFH > Margin.bottom) { + /* next page */ + EndPage(PrintDC); + StartPage(PrintDC); + PrnSetAttr(PrnAttr); + PrnY = Margin.top; } - memcpy(Buff2,Buff,Count); - Buff2[Count] = 0; - Ptr = Buff2; - if (ts.Language==IdRussian) { - if (ts.PrnFont[0]==0) { - RussConvStr(ts.RussClient,ts.RussFont,Buff2,Count); - } - else { - RussConvStr(ts.RussClient,ts.RussPrint,Buff2,Count); - } + DrawStrA(PrintDC, NULL, StrA, Count, PrnFW, PrnFH, PrnY, &PrnX); +} + +void PrnOutTextW(const wchar_t *StrW, const char *WidthInfo, int Count, void *data) +{ + if (PrnX+PrnFW > Margin.right) { + /* new line */ + PrnX = Margin.left; + PrnY = PrnY + PrnFH; } + if (PrnY+PrnFH > Margin.bottom) { + /* next page */ + EndPage(PrintDC); + StartPage(PrintDC); + PrnSetAttr(PrnAttr); + PrnY = Margin.top; + } - do { - if (PrnX+PrnFW > Margin.right) { - /* new line */ - PrnX = Margin.left; - PrnY = PrnY + PrnFH; - } - if (PrnY+PrnFH > Margin.bottom) { - /* next page */ - EndPage(PrintDC); - StartPage(PrintDC); - PrnSetAttr(PrnAttr); - PrnY = Margin.top; - } - - i = (Margin.right-PrnX) / PrnFW; - if (i==0) { - i=1; - } - if (i>Count) { - i=Count; - } - - if (i<Count) { - Ptr2 = Ptr; - do { - Ptr1 = Ptr2; - Ptr2 = CharNextA(Ptr1); - } while ((Ptr2!=NULL) && ((Ptr2-Ptr)<=i)); - i = Ptr1-Ptr; - if (i<=0) { - i=1; - } - } - - RText.left = PrnX; - RText.right = PrnX + i*PrnFW; - RText.top = PrnY; - RText.bottom = PrnY+PrnFH; - ExtTextOutA(PrintDC,PrnX,PrnY,6,&RText,Ptr,i,&PrnDx[0]); - PrnX = RText.right; - Count=Count-i; - Ptr = Ptr + i; - } while (Count>0); - + DrawStrW(PrintDC, NULL, StrW, WidthInfo, Count, PrnFW, PrnFH, PrnY, &PrnX); } void PrnNewLine() @@ -548,7 +512,7 @@ } } while ((c>0) && (! CRFlag)); if (i>0) { - PrnOutText(Buff, i); + PrnOutText(Buff, i, NULL); } if (CRFlag) { PrnX = Margin.left; Modified: trunk/teraterm/teraterm/teraprn.h =================================================================== --- trunk/teraterm/teraterm/teraprn.h 2020-11-29 15:26:29 UTC (rev 9039) +++ trunk/teraterm/teraterm/teraprn.h 2020-11-29 15:26:40 UTC (rev 9040) @@ -47,8 +47,9 @@ #define IdPrnFile 8 int VTPrintInit(int PrnFlag); -void PrnSetAttr(TCharAttr Attr); -void PrnOutText(PCHAR Buff, int Count); +void PrnSetupDC(TCharAttr Attr, BOOL reverse); +void PrnOutText(const char *Buff, int Count, void *data); +void PrnOutTextW(const wchar_t *StrW, const char *WidthInfo, int Count, void *data); void PrnNewLine(); void VTPrintEnd(); @@ -61,4 +62,3 @@ #ifdef __cplusplus } #endif - Modified: trunk/teraterm/teraterm/vtdisp.c =================================================================== --- trunk/teraterm/teraterm/vtdisp.c 2020-11-29 15:26:29 UTC (rev 9039) +++ trunk/teraterm/teraterm/vtdisp.c 2020-11-29 15:26:40 UTC (rev 9040) @@ -46,6 +46,7 @@ #include "vtdisp.h" #define CurWidth 2 +// #define DRAW_RED_BOX 1 static const BYTE DefaultColorTable[256][3] = { { 0, 0, 0}, {255, 0, 0}, { 0,255, 0}, {255,255, 0}, { 0, 0,255}, {255, 0,255}, { 0,255,255}, {255,255,255}, // 0 - 7 @@ -107,7 +108,6 @@ static int WinWidthOld, WinHeightOld; static HBRUSH Background; static COLORREF ANSIColor[256]; -static int Dx[TermWidthMax]; // caret variables static int CaretStatus; @@ -1963,9 +1963,6 @@ VTFont[AttrSpecial | AttrBold] = VTFont[AttrSpecial]; VTFont[AttrSpecial | AttrBold | AttrUnder] = VTFont[AttrSpecial | AttrUnder]; } - - for (i = 0 ; i < TermWidthMax; i++) - Dx[i] = FontWidth; } void ResetIME() @@ -2716,187 +2713,193 @@ } } -// Display a string -// Buff: points the string -// Y: vertical position in window cordinate -// *X: horizontal position -// Return: -// *X: horizontal position shifted by the width of the string -void DispStr(PCHAR Buff, int Count, int Y, int* X) +// draw red box for debug +#if DRAW_RED_BOX +static void DrawRedBox(HDC DC, int sx, int sy, int width, int height) { -#ifdef ALPHABLEND_TYPE2 - const BOOL draw_bg_enable = BGEnable; -#else - const BOOL draw_bg_enable = FALSE; + HPEN red_pen = CreatePen(PS_SOLID, 0, RGB(0xff, 0, 0)); + HGDIOBJ old_pen = SelectObject(DC, red_pen); + MoveToEx(DC, sx, sy, NULL); + LineTo(DC, sx + width, sy); + LineTo(DC, sx + width, sy + height); + LineTo(DC, sx, sy + height); + LineTo(DC, sx, sy); + MoveToEx(DC, sx, sy, NULL); + LineTo(DC, sx + width, sy + height); + MoveToEx(DC, sx + width, sy, NULL); + LineTo(DC, sx, sy + height); + SelectObject(DC, old_pen); + DeleteObject(red_pen); +} #endif -#if 0 - { - char b[128]; - memcpy(b, Buff, Count); - b[Count] = 0; - OutputDebugPrintf("(%d,%d)'%s'\n", *X, Y, b); +/** + * 1\x8Ds\x95`\x89\xE6 ANSI + */ +void DrawStrA(HDC DC, HDC BGDC, const char *StrA, int Count, int font_width, int font_height, int Y, int *X) +{ + int Dx[TermWidthMax]; + int i; + int width; + int height; + + for (i = 0; i < Count; i++) { + Dx[i] = font_width; } -#endif -#if !UNICODE_INTERNAL_BUFF - if ((ts.Language==IdRussian) && - (ts.RussClient!=ts.RussFont)) - RussConvStr(ts.RussClient,ts.RussFont,Buff,Count); -#endif - - if(!draw_bg_enable) - { + // \x83e\x83L\x83X\x83g\x95`\x89\xE6\x97̈\xE6 + width = Count * font_width; + height = font_height; + if (BGDC == NULL) { RECT RText; - RText.top = Y; - RText.bottom = Y+FontHeight; - RText.left = *X; - RText.right = *X + Count*FontWidth; + SetRect(&RText, *X, Y, *X + width, Y + height); - ExtTextOutA(VTDC,*X+ts.FontDX,Y+ts.FontDY, - ETO_CLIPPED | ETO_OPAQUE, - &RText,Buff,Count,&Dx[0]); + ExtTextOutA(DC, *X + ts.FontDX, Y + ts.FontDY, ETO_CLIPPED | ETO_OPAQUE, &RText, StrA, Count, &Dx[0]); } -#ifdef ALPHABLEND_TYPE2 else { HFONT hPrevFont; - RECT rect; - int eto_options; - const int width = Count*FontWidth; - const int height = FontHeight; - SetRect(&rect,0,0,width,height); + RECT rect; + int eto_options; - //hdcBGBuffer \x82̑\xAE\x90\xAB\x82\xF0\x90ݒ\xE8 - hPrevFont = SelectObject(hdcBGBuffer,GetCurrentObject(VTDC,OBJ_FONT)); - SetTextColor(hdcBGBuffer,GetTextColor(VTDC)); - SetBkColor(hdcBGBuffer,GetBkColor(VTDC)); + SetRect(&rect, 0, 0, 0 + width, 0 + height); + // BGDC \x82̑\xAE\x90\xAB\x82\xF0\x90ݒ\xE8 + hPrevFont = SelectObject(BGDC, GetCurrentObject(DC, OBJ_FONT)); + SetTextColor(BGDC, GetTextColor(DC)); + SetBkColor(BGDC, GetBkColor(DC)); + // \x95\xB6\x8E\x9A\x82̔w\x8Ci\x82\xF0\x95`\x89\xE6 - DrawTextBGImage(hdcBGBuffer, *X, Y, width, height); + DrawTextBGImage(BGDC, *X, Y, width, height); // \x95\xB6\x8E\x9A\x82\xF0\x95`\x89\xE6 eto_options = ETO_CLIPPED; - if(BGReverseText == TRUE && BGReverseTextAlpha < 255) { + if (BGReverseText == TRUE && BGReverseTextAlpha < 255) { eto_options |= ETO_OPAQUE; } - ExtTextOutA(hdcBGBuffer,ts.FontDX,ts.FontDY,eto_options,&rect,Buff,Count,&Dx[0]); + ExtTextOutA(BGDC, ts.FontDX, ts.FontDY, eto_options, &rect, StrA, Count, &Dx[0]); // Window\x82ɓ\\x82\xE8\x95t\x82\xAF - BitBlt(VTDC,*X,Y,width,height,hdcBGBuffer,0,0,SRCCOPY); + BitBlt(DC, *X, Y, width, height, BGDC, 0, 0, SRCCOPY); - SelectObject(hdcBGBuffer,hPrevFont); + SelectObject(BGDC, hPrevFont); } + +#if DRAW_RED_BOX + DrawRedBox(DC, *X, Y, width, height); #endif - *X += Count*FontWidth; - -#if !UNICODE_INTERNAL_BUFF - if ((ts.Language==IdRussian) && (ts.RussClient!=ts.RussFont)) - RussConvStr(ts.RussFont,ts.RussClient,Buff,Count); -#endif + *X += width; } /** - * DispStr() \x82\xCC wchar_t\x94\xC5 + * 1\x8Ds\x95`\x89\xE6 Unicode * Windows 95 \x82ɂ\xE0 ExtTextOutW() \x82͑\xB6\x8D݂\xB7\x82邪 * \x93\xAE\x8D삪\x88قȂ\xE9\x82悤\x82\xBE + * TODO \x95\xB6\x8E\x9A\x8AԂɑΉ\x9E\x82\xB5\x82Ă\xA2\x82Ȃ\xA2? */ -void DispStrW(const wchar_t *StrW, const char *WidthInfo, int Count, int Y, int* X) +void DrawStrW(HDC DC, HDC BGDC, const wchar_t *StrW, const char *WidthInfo, int Count, int font_width, int font_height, + int Y, int *X) { -#ifdef ALPHABLEND_TYPE2 - const BOOL draw_bg_enable = BGEnable; -#else - const BOOL draw_bg_enable = FALSE; -#endif - -#if 0 - { - wchar_t b[TermWidthMax]; - memcpy(b, StrW, Count*sizeof(wchar_t)); - b[Count] = 0; - OutputDebugPrintfW(L"(%d,%d)'%s'\n", *X, Y, b); - OutputDebugPrintfW(L" '%hs'\n", WidthInfo); - } -#endif - - int Dx2[TermWidthMax]; - int dx3 = 0; + int Dx[TermWidthMax]; int HalfCharCount = 0; int i; - for(i=0; i<Count; i++) { + int width; + int height; + + for (i = 0; i < Count; i++) { if (WidthInfo[i] == 'H') { HalfCharCount++; - dx3++; - Dx2[i] = FontWidth; - } else if (WidthInfo[i] == '0') { + Dx[i] = font_width; + } + else if (WidthInfo[i] == '0') { if (i == 0) { - Dx2[i] = 0; - } else { - Dx2[i] = Dx2[i-1]; - Dx2[i-1] = 0; + Dx[i] = 0; } - } else { + else { + Dx[i] = Dx[i - 1]; + Dx[i - 1] = 0; + } + } + else { HalfCharCount += 2; - Dx2[i] = FontWidth * 2; - dx3 += 2; + Dx[i] = font_width * 2; } } - if(!draw_bg_enable) - { + // \x83e\x83L\x83X\x83g\x95`\x89\xE6\x97̈\xE6 + width = HalfCharCount * font_width; + height = font_height; + if (BGDC == NULL) { RECT RText; - RText.top = Y; - RText.bottom = Y+FontHeight; - RText.left = *X; - RText.right = *X + HalfCharCount * FontWidth; - RText.right = *X + dx3 * FontWidth; + SetRect(&RText, *X, Y, *X + width, Y + height); -#if 0 - ExtTextOutW(VTDC, *X + ts.FontDX, Y + ts.FontDY, - ETO_CLIPPED | ETO_OPAQUE, - &RText, Buff, Count, &Dx[0]); -#endif - ExtTextOutW(VTDC, *X + ts.FontDX, Y + ts.FontDY, - ETO_CLIPPED | ETO_OPAQUE, - &RText, StrW, Count, &Dx2[0]); + ExtTextOutW(DC, *X + ts.FontDX, Y + ts.FontDY, ETO_CLIPPED | ETO_OPAQUE, &RText, StrW, Count, &Dx[0]); } -#ifdef ALPHABLEND_TYPE2 else { HFONT hPrevFont; - RECT rect; - int eto_options; - const int width = Count*FontWidth*2; - const int height = FontHeight; - SetRect(&rect,0,0,width,height); + RECT rect; + int eto_options; - //hdcBGBuffer \x82̑\xAE\x90\xAB\x82\xF0\x90ݒ\xE8 - hPrevFont = SelectObject(hdcBGBuffer,GetCurrentObject(VTDC,OBJ_FONT)); - SetTextColor(hdcBGBuffer,GetTextColor(VTDC)); - SetBkColor(hdcBGBuffer,GetBkColor(VTDC)); + SetRect(&rect, 0, 0, 0 + width, 0 + height); + // BGDC \x82̑\xAE\x90\xAB\x82\xF0\x90ݒ\xE8 + hPrevFont = SelectObject(BGDC, GetCurrentObject(DC, OBJ_FONT)); + SetTextColor(BGDC, GetTextColor(DC)); + SetBkColor(BGDC, GetBkColor(DC)); + // \x95\xB6\x8E\x9A\x82̔w\x8Ci\x82\xF0\x95`\x89\xE6 - DrawTextBGImage(hdcBGBuffer, *X, Y, width, height); + DrawTextBGImage(BGDC, *X, Y, width, height); // \x95\xB6\x8E\x9A\x82\xF0\x95`\x89\xE6 eto_options = ETO_CLIPPED; - if(BGReverseText == TRUE && BGReverseTextAlpha < 255) { + if (BGReverseText == TRUE && BGReverseTextAlpha < 255) { eto_options |= ETO_OPAQUE; } -#if 0 - ExtTextOutW(hdcBGBuffer,ts.FontDX,ts.FontDY,eto_options,&rect, StrW,Count,&Dx[0]); -#endif - ExtTextOutW(hdcBGBuffer,ts.FontDX,ts.FontDY,eto_options,&rect, StrW,Count,&Dx2[0]); + ExtTextOutW(BGDC, ts.FontDX, ts.FontDY, eto_options, &rect, StrW, Count, &Dx[0]); // Window\x82ɓ\\x82\xE8\x95t\x82\xAF - BitBlt(VTDC,*X,Y,width,height,hdcBGBuffer,0,0,SRCCOPY); + BitBlt(DC, *X, Y, width, height, BGDC, 0, 0, SRCCOPY); - SelectObject(hdcBGBuffer,hPrevFont); + SelectObject(BGDC, hPrevFont); } + +#if DRAW_RED_BOX + DrawRedBox(DC, *X, Y, width, height); #endif - *X += dx3 *FontWidth; + *X += width; } +/** + * Display a string + * @param Buff points the string + * @param Y vertical position in window cordinate + * @param[in] *X horizontal position + * @param[out] *X horizontal position shifted by the width of the string + */ +void DispStr(const char *Buff, int Count, int Y, int* X) +{ +#ifdef ALPHABLEND_TYPE2 + HDC BGDC = BGEnable ? hdcBGBuffer : NULL; +#else + HDC BGDC = NULL; +#endif + DrawStrA(VTDC, BGDC, Buff, Count, FontWidth, FontHeight, Y, X); +} + +/** + * DispStr() \x82\xCC wchar_t\x94\xC5 + */ +void DispStrW(const wchar_t *StrW, const char *WidthInfo, int Count, int Y, int* X) +{ +#ifdef ALPHABLEND_TYPE2 + HDC BGDC = BGEnable ? hdcBGBuffer : NULL; +#else + HDC BGDC = NULL; +#endif + DrawStrW(VTDC, BGDC, StrW, WidthInfo, Count, FontWidth, FontHeight, Y, X); +} + void DispEraseCurToEnd(int YEnd) { RECT R; Modified: trunk/teraterm/teraterm/vtdisp.h =================================================================== --- trunk/teraterm/teraterm/vtdisp.h 2020-11-29 15:26:29 UTC (rev 9039) +++ trunk/teraterm/teraterm/vtdisp.h 2020-11-29 15:26:40 UTC (rev 9040) @@ -82,7 +82,7 @@ void DispInitDC(); void DispReleaseDC(); void DispSetupDC(TCharAttr Attr, BOOL Reverse); -void DispStr(PCHAR Buff, int Count, int Y, int* X); +void DispStr(const char *Buff, int Count, int Y, int* X); void DispStrW(const wchar_t *StrW, const char *WidthInfo, int Count, int Y, int* X); void DispEraseCurToEnd(int YEnd); void DispEraseHomeToCur(int YHome); @@ -120,6 +120,10 @@ void DispGetRootWinSize(int *x, int *y, BOOL inPixels); int DispFindClosestColor(int red, int green, int blue); void UpdateBGBrush(void); +void DrawStrW(HDC DC, HDC BGDC, const wchar_t *StrW, const char *WidthInfo, int Count, + int font_width, int font_height, int Y, int* X); +void DrawStrA(HDC DC, HDC BGDC, const char *StrA, int Count, + int font_width, int font_height, int Y, int* X); extern int WinWidth, WinHeight; extern HFONT VTFont[AttrFontMask+1];