|
|
| version 1.7, 2005/02/11 21:17:23 | version 1.8, 2005/02/12 12:14:00 |
|---|---|
| Line 1 | Line 1 |
| #include "compiler.h" | #include "compiler.h" |
| #if defined(UNICODE) && defined(OSLANG_UTF8) | |
| #include "codecnv.h" | |
| #endif | |
| #include "fontmng.h" | #include "fontmng.h" |
| Line 39 typedef struct { | Line 42 typedef struct { |
| static const TCHAR deffontface[] = _T("MS ゴシック"); | static const TCHAR deffontface[] = _T("MS ゴシック"); |
| static const TCHAR deffontface2[] = _T("MS Pゴシック"); | static const TCHAR deffontface2[] = _T("MS Pゴシック"); |
| #ifndef _WIN32_WCE | #if !defined(_WIN32_WCE) |
| #define TEXTALPHABASE (FDAT_DEPTH * 0x60 / 256) | #define TEXTALPHABASE (FDAT_DEPTH * 0x60 / 256) |
| #else | #else |
| #define TEXTALPHABASE (FDAT_DEPTH * 0x40 / 256) | #define TEXTALPHABASE (FDAT_DEPTH * 0x40 / 256) |
| Line 153 void *fontmng_create(int size, UINT type | Line 156 void *fontmng_create(int size, UINT type |
| ret->hdcimage = CreateCompatibleDC(hdc); | ret->hdcimage = CreateCompatibleDC(hdc); |
| ReleaseDC(NULL, hdc); | ReleaseDC(NULL, hdc); |
| ret->hBitmap = (HBITMAP)SelectObject(ret->hdcimage, ret->hBitmap); | ret->hBitmap = (HBITMAP)SelectObject(ret->hdcimage, ret->hBitmap); |
| #ifndef _WIN32_WCE | #if !defined(_WIN32_WCE) |
| SetDIBColorTable(ret->hdcimage, 0, 2, bi->bmiColors); | SetDIBColorTable(ret->hdcimage, 0, 2, bi->bmiColors); |
| #endif | #endif |
| Line 161 void *fontmng_create(int size, UINT type | Line 164 void *fontmng_create(int size, UINT type |
| lf.lfWidth = 0; | lf.lfWidth = 0; |
| lf.lfEscapement = FW_DONTCARE; | lf.lfEscapement = FW_DONTCARE; |
| lf.lfOrientation = FW_DONTCARE; | lf.lfOrientation = FW_DONTCARE; |
| #ifdef _WIN32_WCE | #if !defined(_WIN32_WCE) |
| lf.lfWeight = (type & FDAT_BOLD)?FW_BOLD:FW_THIN; | |
| #else | |
| lf.lfWeight = (type & FDAT_BOLD)?FW_BOLD:FW_REGULAR; | lf.lfWeight = (type & FDAT_BOLD)?FW_BOLD:FW_REGULAR; |
| #else | |
| lf.lfWeight = (type & FDAT_BOLD)?FW_BOLD:FW_THIN; | |
| #endif | #endif |
| lf.lfItalic = FALSE; | lf.lfItalic = FALSE; |
| lf.lfUnderline = FALSE; | lf.lfUnderline = FALSE; |
| Line 204 void fontmng_destroy(void *hdl) { | Line 207 void fontmng_destroy(void *hdl) { |
| // ---- | // ---- |
| #ifdef UNICODE | static void getlength1(FNTMNG fhdl, FNTDAT fdat, |
| static void getlength1(FNTMNG fhdl, FNTDAT fdat, LPCTSTR string, | const TCHAR *string, int length) { |
| int tleng, int length) { | |
| SIZE fntsize; | SIZE fntsize; |
| if ((fhdl->fonttype & FDAT_PROPORTIONAL) && | if (GetTextExtentPoint32(fhdl->hdcimage, string, length, &fntsize)) { |
| (GetTextExtentPoint32(fhdl->hdcimage, string, tleng, &fntsize))) { | |
| if (fhdl->fonttype & FDAT_ALIAS) { | if (fhdl->fonttype & FDAT_ALIAS) { |
| fntsize.cx = min(fntsize.cx, fhdl->bmpwidth); | fntsize.cx = min(fntsize.cx, fhdl->bmpwidth); |
| fdat->width = (fntsize.cx + 1) >> 1; | fdat->width = (fntsize.cx + 1) >> 1; |
| fdat->pitch = fntsize.cx >> 1; | fdat->pitch = fntsize.cx >> 1; |
| fdat->height = fhdl->bmpheight >> 1; | |
| } | } |
| else { | else { |
| #if 1 // PocketPCのみ戻り値が変らしい? | #if !defined(_WIN32_WCE) // PocketPCのみ戻り値が変らしい? |
| fdat->width = min(fntsize.cx, fhdl->bmpwidth); | fdat->width = min(fntsize.cx, fhdl->bmpwidth); |
| #else | #else |
| fdat->width = min(fntsize.cx + 1, fhdl->bmpwidth); | fdat->width = min(fntsize.cx + 1, fhdl->bmpwidth); |
| #endif | #endif |
| fdat->pitch = min(fntsize.cx, fhdl->bmpwidth); | fdat->pitch = min(fntsize.cx, fhdl->bmpwidth); |
| fdat->height = fhdl->bmpheight; | |
| } | } |
| } | } |
| else { | else { |
| if (length < 2) { | |
| fdat->pitch = fhdl->fontsize >> 1; | |
| } | |
| else { | |
| fdat->pitch = fhdl->fontsize; | |
| } | |
| if (fhdl->fonttype & FDAT_ALIAS) { | if (fhdl->fonttype & FDAT_ALIAS) { |
| fdat->width = fhdl->bmpwidth >> 1; | fdat->width = fhdl->bmpwidth >> 1; |
| fdat->height = fhdl->bmpheight >> 1; | |
| } | } |
| else { | else { |
| fdat->width = fhdl->bmpwidth; | fdat->width = fhdl->bmpwidth; |
| fdat->height = fhdl->bmpheight; | |
| } | } |
| fdat->pitch = (fhdl->fontsize + 1) >> 1; | |
| } | } |
| } | if (fhdl->fonttype & FDAT_ALIAS) { |
| fdat->height = fhdl->bmpheight >> 1; | |
| static void fontmng_getchar(FNTMNG fhdl, FNTDAT fdat, const char *string) { | |
| TCHAR txtwork[4]; | |
| DWORD len; | |
| int leng; | |
| FillRect(fhdl->hdcimage, &fhdl->rect, | |
| (HBRUSH)GetStockObject(BLACK_BRUSH)); | |
| leng = strlen(string); | |
| len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, string, -1, | |
| txtwork, sizeof(txtwork)/sizeof(TCHAR)) - 1; | |
| ExtTextOut(fhdl->hdcimage, 0, 0, ETO_OPAQUE, NULL, | |
| txtwork, len, NULL); | |
| getlength1(fhdl, fdat, txtwork, len, leng); | |
| } | |
| BOOL fontmng_getsize(void *hdl, const char *string, POINT_T *pt) { | |
| TCHAR txtwork[4]; | |
| char buf[4]; | |
| _FNTDAT fdat; | |
| int width; | |
| DWORD len; | |
| int leng; | |
| if ((hdl == NULL) || (string == NULL)) { | |
| goto fmgs_exit; | |
| } | |
| width = 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 { | |
| break; | |
| } | |
| len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, buf, -1, | |
| txtwork, sizeof(txtwork)/sizeof(TCHAR)) - 1; | |
| getlength1((FNTMNG)hdl, &fdat, txtwork, len, leng); | |
| width += fdat.pitch; | |
| } while(1); | |
| if (pt) { | |
| pt->x = width; | |
| pt->y = ((FNTMNG)hdl)->fontsize; | |
| } | |
| return(SUCCESS); | |
| fmgs_exit: | |
| return(FAILURE); | |
| } | |
| BOOL fontmng_getdrawsize(void *hdl, const char *string, POINT_T *pt) { | |
| TCHAR txtwork[4]; | |
| char buf[4]; | |
| _FNTDAT fdat; | |
| int width; | |
| int posx; | |
| DWORD len; | |
| int leng; | |
| if ((hdl == NULL) || (string == NULL)) { | |
| goto fmgds_exit; | |
| } | |
| 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 { | |
| break; | |
| } | |
| len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, buf, -1, | |
| txtwork, sizeof(txtwork)/sizeof(TCHAR)) - 1; | |
| getlength1((FNTMNG)hdl, &fdat, txtwork, len, leng); | |
| width = posx + max(fdat.width, fdat.pitch); | |
| posx += fdat.pitch; | |
| } while(1); | |
| if (pt) { | |
| pt->x = width; | |
| pt->y = ((FNTMNG)hdl)->fontsize; | |
| } | |
| return(SUCCESS); | |
| fmgds_exit: | |
| return(FAILURE); | |
| } | |
| #else | |
| static void getlength1(FNTMNG fhdl, FNTDAT fdat, | |
| const char *string, int length) { | |
| SIZE fntsize; | |
| if ((fhdl->fonttype & FDAT_PROPORTIONAL) && | |
| (GetTextExtentPoint32(fhdl->hdcimage, string, length, &fntsize))) { | |
| if (fhdl->fonttype & FDAT_ALIAS) { | |
| fntsize.cx = min(fntsize.cx, fhdl->bmpwidth); | |
| fdat->width = (fntsize.cx + 1) >> 1; | |
| fdat->pitch = fntsize.cx >> 1; | |
| fdat->height = fhdl->bmpheight >> 1; | |
| } | |
| else { | |
| fntsize.cx = min(fntsize.cx, fhdl->bmpwidth); | |
| fdat->width = fntsize.cx; | |
| fdat->pitch = fntsize.cx; | |
| fdat->height = fhdl->bmpheight; | |
| } | |
| } | } |
| else { | else { |
| if (length < 2) { | fdat->height = fhdl->bmpheight; |
| fdat->pitch = fhdl->fontsize >> 1; | |
| } | |
| else { | |
| fdat->pitch = fhdl->fontsize; | |
| } | |
| if (fhdl->fonttype & FDAT_ALIAS) { | |
| fdat->width = fhdl->bmpwidth >> 1; | |
| fdat->height = fhdl->bmpheight >> 1; | |
| } | |
| else { | |
| fdat->width = fhdl->bmpwidth; | |
| fdat->height = fhdl->bmpheight; | |
| } | |
| } | } |
| } | } |
| static void fontmng_getchar(FNTMNG fhdl, FNTDAT fdat, const char *string) { | static void fontmng_getchar(FNTMNG fhdl, FNTDAT fdat, |
| const TCHAR *string, int length) { | |
| int leng; | |
| FillRect(fhdl->hdcimage, &fhdl->rect, | FillRect(fhdl->hdcimage, &fhdl->rect, |
| (HBRUSH)GetStockObject(BLACK_BRUSH)); | (HBRUSH)GetStockObject(BLACK_BRUSH)); |
| leng = strlen(string); | TextOut(fhdl->hdcimage, 0, 0, string, length); |
| TextOut(fhdl->hdcimage, 0, 0, string, leng); | getlength1(fhdl, fdat, string, length); |
| getlength1(fhdl, fdat, string, leng); | |
| } | } |
| BOOL fontmng_getsize(void *hdl, const char *string, POINT_T *pt) { | BRESULT fontmng_getsize(void *hdl, const OEMCHAR *string, POINT_T *pt) { |
| char buf[4]; | |
| _FNTDAT fdat; | _FNTDAT fdat; |
| int width; | int width; |
| int leng; | int leng; |
| Line 421 BOOL fontmng_getsize(void *hdl, const ch | Line 264 BOOL fontmng_getsize(void *hdl, const ch |
| goto fmgs_exit; | goto fmgs_exit; |
| } | } |
| buf[2] = '\0'; | while(1) { |
| do { | leng = milstr_charsize(string); |
| buf[0] = *string++; | if (!leng) { |
| 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 { | |
| break; | break; |
| } | } |
| getlength1((FNTMNG)hdl, &fdat, buf, leng); | #if defined(UNICODE) && defined(OSLANG_UTF8) |
| UINT16 unistr[2]; | |
| codecnv_utf8toucs2(unistr, NELEMENTS(unistr), string, (UINT)-1); | |
| getlength1((FNTMNG)hdl, &fdat, unistr, 1); | |
| #else | |
| getlength1((FNTMNG)hdl, &fdat, string, leng); | |
| #endif | |
| string += leng; | |
| width += fdat.pitch; | width += fdat.pitch; |
| } while(1); | } |
| if (pt) { | if (pt) { |
| pt->x = width; | pt->x = width; |
| Line 452 fmgs_exit: | Line 290 fmgs_exit: |
| return(FAILURE); | return(FAILURE); |
| } | } |
| BOOL fontmng_getdrawsize(void *hdl, const char *string, POINT_T *pt) { | BRESULT fontmng_getdrawsize(void *hdl, const OEMCHAR *string, POINT_T *pt) { |
| char buf[4]; | |
| _FNTDAT fdat; | _FNTDAT fdat; |
| int width; | int width; |
| int posx; | int posx; |
| Line 466 BOOL fontmng_getdrawsize(void *hdl, cons | Line 303 BOOL fontmng_getdrawsize(void *hdl, cons |
| width = 0; | width = 0; |
| posx = 0; | posx = 0; |
| buf[2] = '\0'; | while(1) { |
| do { | leng = milstr_charsize(string); |
| buf[0] = *string++; | if (!leng) { |
| 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 { | |
| break; | break; |
| } | } |
| getlength1((FNTMNG)hdl, &fdat, buf, leng); | #if defined(UNICODE) && defined(OSLANG_UTF8) |
| UINT16 unistr[2]; | |
| codecnv_utf8toucs2(unistr, NELEMENTS(unistr), string, (UINT)-1); | |
| getlength1((FNTMNG)hdl, &fdat, unistr, 1); | |
| #else | |
| getlength1((FNTMNG)hdl, &fdat, string, leng); | |
| #endif | |
| string += leng; | |
| width = posx + max(fdat.width, fdat.pitch); | width = posx + max(fdat.width, fdat.pitch); |
| posx += fdat.pitch; | posx += fdat.pitch; |
| } while(1); | } |
| if (pt) { | if (pt) { |
| pt->x = width; | pt->x = width; |
| pt->y = ((FNTMNG)hdl)->fontsize; | pt->y = ((FNTMNG)hdl)->fontsize; |
| Line 497 BOOL fontmng_getdrawsize(void *hdl, cons | Line 328 BOOL fontmng_getdrawsize(void *hdl, cons |
| fmgds_exit: | fmgds_exit: |
| return(FAILURE); | return(FAILURE); |
| } | } |
| #endif | |
| static void fontmng_setpat(FNTMNG fhdl, FNTDAT fdat) { | static void fontmng_setpat(FNTMNG fhdl, FNTDAT fdat) { |
| Line 602 FNTDAT fontmng_get(void *hdl, const OEMC | Line 432 FNTDAT fontmng_get(void *hdl, const OEMC |
| UINT prev; | UINT prev; |
| UINT cnt; | UINT cnt; |
| #if defined(OSLANG_SJIS) || defined(OSLANG_SJIS) | #if defined(OSLANG_SJIS) || defined(OSLANG_UTF8) |
| int len; | int len; |
| len = milstr_charsize(string); | len = milstr_charsize(string); |
| switch(len) { | str = (UINT8)string[0]; |
| default: | if (len >= 2) { |
| str = (UINT8)string[0]; | str |= ((UINT8)string[1]) << 8; |
| break; | } |
| if (len >= 3) { | |
| case 2: | str |= ((UINT8)string[2]) << 16; |
| str = (UINT8)string[0] + (((UINT8)string[1]) << 8); | } |
| break; | if (len >= 4) { |
| str |= ((UINT8)string[3]) << 24; | |
| case 3: | |
| str = (UINT8)string[0] + (((UINT8)string[1]) << 8) + (((UINT8)string[2]) << 16); | |
| break; | |
| case 4: | |
| str = (UINT8)string[0] + (((UINT8)string[1]) << 8) + (((UINT8)string[2]) << 16) + (((UINT8)string[2]) << 24); | |
| break; | |
| } | } |
| #else | #else |
| str = (UINT)string[0]; | str = (UINT)string[0]; |
| Line 656 FNTDAT fontmng_get(void *hdl, const OEMC | Line 479 FNTDAT fontmng_get(void *hdl, const OEMC |
| fdat = (FNTDAT)(fhdl + 1); | fdat = (FNTDAT)(fhdl + 1); |
| #endif | #endif |
| fontmng_getchar(fhdl, fdat, string); | #if defined(UNICODE) && defined(OSLANG_UTF8) |
| UINT16 unistr[2]; | |
| codecnv_utf8toucs2(unistr, NELEMENTS(unistr), string, (UINT)-1); | |
| fontmng_getchar(fhdl, fdat, unistr, 1); | |
| #else | |
| fontmng_getchar(fhdl, fdat, string, milstr_charsize(string)); | |
| #endif | |
| fontmng_setpat(fhdl, fdat); | fontmng_setpat(fhdl, fdat); |
| return(fdat); | return(fdat); |