--- np2/win9xc/fontmng.cpp 2003/10/16 17:59:20 1.1.1.1 +++ np2/win9xc/fontmng.cpp 2005/03/20 08:58:20 1.3 @@ -11,7 +11,7 @@ typedef struct { // ¤¢¤È¤Ï³ÈÄ¥¡Á HDC hdcimage; HBITMAP hBitmap; - BYTE *image; + UINT8 *image; HFONT hfont; RECT rect; int bmpwidth; @@ -20,8 +20,8 @@ typedef struct { } _FNTMNG, *FNTMNG; -static const TCHAR deffontface[] = "£Í£Ó ¥´¥·¥Ã¥¯"; -static const TCHAR deffontface2[] = "£Í£Ó £Ð¥´¥·¥Ã¥¯"; +static const TCHAR deffontface[] = _T("£Í£Ó ¥´¥·¥Ã¥¯"); +static const TCHAR deffontface2[] = _T("£Í£Ó £Ð¥´¥·¥Ã¥¯"); void *fontmng_create(int size, UINT type, const TCHAR *fontface) { @@ -35,7 +35,7 @@ void *fontmng_create(int size, UINT type int fontwidth; int fontheight; int weight; - DWORD pitch; + UINT pitch; if (size < 0) { size *= -1; @@ -73,7 +73,7 @@ void *fontmng_create(int size, UINT type ret->bmpalign = (((ret->bmpwidth + 31) / 8) & ~3); - bi = (BITMAPINFO *)(((BYTE *)(ret + 1)) + fontalign); + bi = (BITMAPINFO *)(((UINT8 *)(ret + 1)) + fontalign); bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bi->bmiHeader.biWidth = ret->bmpwidth; bi->bmiHeader.biHeight = ret->bmpheight; @@ -92,7 +92,7 @@ void *fontmng_create(int size, UINT type bi->bmiColors[i].rgbReserved = PC_RESERVED; } - hdc = GetDC(NULL); + hdc = GetDC(NULL); ret->hBitmap = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, (void **)&ret->image, NULL, 0); ret->hdcimage = CreateCompatibleDC(hdc); @@ -117,7 +117,6 @@ void *fontmng_create(int size, UINT type return(ret); } - void fontmng_destroy(void *hdl) { FNTMNG fhdl; @@ -132,61 +131,59 @@ void fontmng_destroy(void *hdl) { } +// ---- + static void getlength1(FNTMNG fhdl, FNTDAT fdat, - const char *string, int length) { + const TCHAR *string, int length) { SIZE fntsize; - if ((fhdl->fonttype & FDAT_PROPORTIONAL) && - (GetTextExtentPoint32(fhdl->hdcimage, string, length, &fntsize))) { + if (GetTextExtentPoint32(fhdl->hdcimage, string, length, &fntsize)) { fntsize.cx = min(fntsize.cx, fhdl->bmpwidth); fdat->width = fntsize.cx; fdat->pitch = fntsize.cx; } - else if (length < 2) { - fdat->width = fhdl->fontwidth; - fdat->pitch = (fhdl->fontsize + 1) >> 1; - } else { fdat->width = fhdl->fontwidth; - fdat->pitch = fhdl->fontsize; + fdat->pitch = (fhdl->fontsize + 1) >> 1; } fdat->height = fhdl->fontheight; } +static void fontmng_getchar(FNTMNG fhdl, FNTDAT fdat, const TCHAR *string) { -BOOL fontmng_getsize(void *hdl, const char *string, POINT_T *pt) { + int leng; + + FillRect(fhdl->hdcimage, &fhdl->rect, + (HBRUSH)GetStockObject(BLACK_BRUSH)); + leng = milstr_charsize(string); + TextOut(fhdl->hdcimage, 0, 0, string, leng); + getlength1(fhdl, fdat, string, leng); +} + +BRESULT fontmng_getsize(void *hdl, const TCHAR *string, POINT_T *pt) { - char buf[4]; - _FNTDAT fdat; int width; + TCHAR buf[4]; + _FNTDAT fdat; int leng; - width = 0; if ((hdl == NULL) || (string == NULL)) { goto fmgs_exit; } - buf[2] = '\0'; - do { - buf[0] = *string++; - if ((((buf[0] ^ 0x20) - 0xa1) & 0xff) < 0x3c) { - buf[1] = *string++; - if (buf[1] == '\0') { - break; - } - leng = 2; - } - else if (buf[0]) { - buf[1] = '\0'; - leng = 1; - } - else { + width = 0; + while(1) { + leng = milstr_charsize(string); + if (!leng) { break; } + CopyMemory(buf, string, leng * sizeof(TCHAR)); + buf[leng] = '\0'; + string += leng; getlength1((FNTMNG)hdl, &fdat, buf, leng); width += fdat.pitch; - } while(1); + } if (pt) { pt->x = width; @@ -198,10 +195,9 @@ fmgs_exit: return(FAILURE); } +BRESULT fontmng_getdrawsize(void *hdl, const TCHAR *string, POINT_T *pt) { -BOOL fontmng_getdrawsize(void *hdl, const char *string, POINT_T *pt) { - - char buf[4]; + TCHAR buf[4]; _FNTDAT fdat; int width; int posx; @@ -213,27 +209,18 @@ BOOL fontmng_getdrawsize(void *hdl, cons width = 0; posx = 0; - buf[2] = '\0'; - do { - buf[0] = *string++; - if ((((buf[0] ^ 0x20) - 0xa1) & 0xff) < 0x3c) { - buf[1] = *string++; - if (buf[1] == '\0') { - break; - } - leng = 2; - } - else if (buf[0]) { - buf[1] = '\0'; - leng = 1; - } - else { + while(1) { + leng = milstr_charsize(string); + if (!leng) { break; } + CopyMemory(buf, string, leng * sizeof(TCHAR)); + buf[leng] = '\0'; + string += leng; getlength1((FNTMNG)hdl, &fdat, buf, leng); width = posx + max(fdat.width, fdat.pitch); posx += fdat.pitch; - } while(1); + } if (pt) { pt->x = width; @@ -245,28 +232,15 @@ fmgds_exit: return(FAILURE); } - -static void fontmng_getchar(FNTMNG fhdl, FNTDAT fdat, const char *string) { - - int leng; - - FillRect(fhdl->hdcimage, &fhdl->rect, - (HBRUSH)GetStockObject(BLACK_BRUSH)); - leng = strlen(string); - TextOut(fhdl->hdcimage, 0, 0, string, leng); - getlength1(fhdl, fdat, string, leng); -} - - static void fontmng_setpat(FNTMNG fhdl, FNTDAT fdat) { - DWORD remx; - DWORD remy; - BYTE *src; - BYTE *dst; - BYTE *s; - BYTE bit; - BYTE b1 = 0; // for cygwin + UINT remx; + UINT remy; + UINT8 *src; + UINT8 *dst; + UINT8 *s; + UINT8 bit; + UINT8 b1 = 0; // for cygwin int align; align = fhdl->bmpalign; @@ -275,7 +249,7 @@ static void fontmng_setpat(FNTMNG fhdl, goto fmsp_end; } - dst = (BYTE *)(fdat + 1); + dst = (UINT8 *)(fdat + 1); align *= -1; remy = fdat->height; @@ -301,7 +275,7 @@ fmsp_end: // ---- -FNTDAT fontmng_get(void *hdl, const char *string) { +FNTDAT fontmng_get(void *hdl, const TCHAR *string) { FNTMNG fhdl; FNTDAT fdat;