|
|
| version 1.3, 2003/12/01 21:15:13 | version 1.13, 2005/05/17 00:10:40 |
|---|---|
| Line 1 | Line 1 |
| #include "compiler.h" | #include "compiler.h" |
| #include "oemtext.h" | |
| #include "fontmng.h" | #include "fontmng.h" |
| Line 6 | Line 7 |
| #if defined(FONTMNG_CACHE) | #if defined(FONTMNG_CACHE) |
| typedef struct { | typedef struct { |
| WORD str; | UINT str; |
| WORD next; | UINT next; |
| } FNTCTBL; | } FNTCTBL; |
| #endif | #endif |
| Line 21 typedef struct { | Line 22 typedef struct { |
| // あとは拡張〜 | // あとは拡張〜 |
| HDC hdcimage; | HDC hdcimage; |
| HBITMAP hBitmap; | HBITMAP hBitmap; |
| BYTE *image; | UINT8 *image; |
| HFONT hfont; | HFONT hfont; |
| RECT rect; | RECT rect; |
| int bmpwidth; | int bmpwidth; |
| Line 29 typedef struct { | Line 30 typedef struct { |
| int bmpalign; | int bmpalign; |
| #if defined(FONTMNG_CACHE) | #if defined(FONTMNG_CACHE) |
| DWORD caches; | UINT caches; |
| DWORD cachehead; | UINT cachehead; |
| FNTCTBL cache[FONTMNG_CACHE]; | FNTCTBL cache[FONTMNG_CACHE]; |
| #endif | #endif |
| } _FNTMNG, *FNTMNG; | } _FNTMNG, *FNTMNG; |
| static const TCHAR deffontface[] = STRLITERAL("MS ゴシック"); | static const TCHAR deffontface[] = _T("MS ゴシック"); |
| static const TCHAR deffontface2[] = STRLITERAL("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 128 void *fontmng_create(int size, UINT type | Line 129 void *fontmng_create(int size, UINT type |
| ret->bmpheight = bmpheight; | ret->bmpheight = bmpheight; |
| ret->bmpalign = (((bmpwidth + 31) / 8) & (~3)); | ret->bmpalign = (((bmpwidth + 31) / 8) & (~3)); |
| bi = (BITMAPINFO *)(((BYTE *)(ret + 1)) + fontwork); | bi = (BITMAPINFO *)(((UINT8 *)(ret + 1)) + fontwork); |
| bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
| bi->bmiHeader.biWidth = ret->bmpwidth; | bi->bmiHeader.biWidth = ret->bmpwidth; |
| bi->bmiHeader.biHeight = ret->bmpheight; | bi->bmiHeader.biHeight = ret->bmpheight; |
| Line 153 void *fontmng_create(int size, UINT type | Line 154 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 162 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 201 void fontmng_destroy(void *hdl) { | Line 202 void fontmng_destroy(void *hdl) { |
| } | } |
| } | } |
| int fontmng_getpoint(void *hdl) { | |
| if (hdl) { | // ---- |
| } | |
| return(0); | |
| } | |
| #ifdef _WIN32_WCE | 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 !defined(WIN32_PLATFORM_PSPC) // PocketPCのみ戻り値が変らしい? | |
| fdat->width = min(fntsize.cx, fhdl->bmpwidth); | |
| #else | |
| fdat->width = min(fntsize.cx + 1, fhdl->bmpwidth); | fdat->width = min(fntsize.cx + 1, fhdl->bmpwidth); |
| #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; | |
| } | |
| } | |
| } | |
| 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, | fdat->pitch = (fhdl->fontsize + 1) >> 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; | |
| } | } |
| if (fhdl->fonttype & FDAT_ALIAS) { | |
| width = 0; | fdat->height = fhdl->bmpheight >> 1; |
| 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; | |
| #if 1 // sig3は バグあるらすー | |
| ZeroMemory(fhdl->image, fhdl->bmpalign * fhdl->bmpheight); | |
| #else | |
| FillRect(fhdl->hdcimage, &fhdl->rect, | FillRect(fhdl->hdcimage, &fhdl->rect, |
| (HBRUSH)GetStockObject(BLACK_BRUSH)); | (HBRUSH)GetStockObject(BLACK_BRUSH)); |
| leng = strlen(string); | #endif |
| TextOut(fhdl->hdcimage, 0, 0, string, leng); | #if !defined(_WIN32_WCE) |
| getlength1(fhdl, fdat, string, leng); | TextOut(fhdl->hdcimage, 0, 0, string, length); |
| #else | |
| ExtTextOut(fhdl->hdcimage, 0, 0, ETO_OPAQUE, NULL, string, length, NULL); | |
| #endif | |
| getlength1(fhdl, fdat, string, length); | |
| } | } |
| 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; | |
| int width; | int width; |
| _FNTDAT fdat; | |
| int leng; | int leng; |
| width = 0; | |
| if ((hdl == NULL) || (string == NULL)) { | if ((hdl == NULL) || (string == NULL)) { |
| goto fmgs_exit; | goto fmgs_exit; |
| } | } |
| buf[2] = '\0'; | width = 0; |
| do { | while(1) { |
| buf[0] = *string++; | leng = milstr_charsize(string); |
| if ((((buf[0] ^ 0x20) - 0xa1) & 0xff) < 0x3c) { | if (!leng) { |
| 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(OEMCHAR_SAME_TCHAR) |
| getlength1((FNTMNG)hdl, &fdat, string, leng); | |
| #else | |
| TCHAR tcharstr[4]; | |
| UINT tlen = oemtotchar(tcharstr, NELEMENTS(tcharstr), string, leng); | |
| getlength1((FNTMNG)hdl, &fdat, tcharstr, tlen); | |
| #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 296 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 309 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(OEMCHAR_SAME_TCHAR) |
| getlength1((FNTMNG)hdl, &fdat, string, leng); | |
| #else | |
| TCHAR tcharstr[4]; | |
| UINT tlen = oemtotchar(tcharstr, NELEMENTS(tcharstr), string, leng); | |
| getlength1((FNTMNG)hdl, &fdat, tcharstr, tlen); | |
| #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 334 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) { |
| DWORD remx; | UINT remx; |
| DWORD remy; | UINT remy; |
| BYTE *src; | UINT8 *src; |
| BYTE *dst; | UINT8 *dst; |
| BYTE *s1, *s2; | UINT8 *s1; |
| BYTE bit; | UINT8 *s2; |
| BYTE b1, b2; | UINT8 bit; |
| UINT b1; | |
| UINT b2; | |
| int align; | int align; |
| int c; | int c; |
| Line 517 static void fontmng_setpat(FNTMNG fhdl, | Line 355 static void fontmng_setpat(FNTMNG fhdl, |
| goto fmsp_end; | goto fmsp_end; |
| } | } |
| dst = (BYTE *)(fdat + 1); | dst = (UINT8 *)(fdat + 1); |
| align *= -1; | align *= -1; |
| if (fhdl->fonttype & FDAT_ALIAS) { | if (fhdl->fonttype & FDAT_ALIAS) { |
| Line 549 static void fontmng_setpat(FNTMNG fhdl, | Line 387 static void fontmng_setpat(FNTMNG fhdl, |
| c += (FDAT_DEPTH - TEXTALPHABASE); | c += (FDAT_DEPTH - TEXTALPHABASE); |
| } | } |
| if (c) { | if (c) { |
| *dst++ = (BYTE)(TEXTALPHABASE + (c / 4)); | *dst++ = (UINT8)(TEXTALPHABASE + (c / 4)); |
| } | } |
| else { | else { |
| *dst++ = 0; | *dst++ = 0; |
| Line 582 fmsp_end: | Line 420 fmsp_end: |
| return; | return; |
| } | } |
| FNTDAT fontmng_get(void *hdl, const char *string) { | FNTDAT fontmng_get(void *hdl, const OEMCHAR *string) { |
| FNTMNG fhdl; | FNTMNG fhdl; |
| FNTDAT fdat; | FNTDAT fdat; |
| UINT leng; | |
| if ((hdl == NULL) || (string == NULL)) { | if ((hdl == NULL) || (string == NULL)) { |
| goto ftmggt_err; | goto ftmggt_err; |
| } | } |
| fhdl = (FNTMNG)hdl; | fhdl = (FNTMNG)hdl; |
| leng = milstr_charsize(string); | |
| #if defined(FONTMNG_CACHE) | #if defined(FONTMNG_CACHE) |
| { | { |
| FNTCTBL *fct; | FNTCTBL *fct; |
| DWORD str; | UINT str; |
| DWORD pos; | UINT pos; |
| DWORD prev; | UINT prev; |
| DWORD cnt; | UINT cnt; |
| str = string[0] & 0xff; | #if defined(OSLANG_SJIS) || defined(OSLANG_UTF8) |
| str |= (string[1] & 0xff) << 8; | str = (UINT8)string[0]; |
| if (leng >= 2) { | |
| str |= ((UINT8)string[1]) << 8; | |
| } | |
| if (leng >= 3) { | |
| str |= ((UINT8)string[2]) << 16; | |
| } | |
| if (leng >= 4) { | |
| str |= ((UINT8)string[3]) << 24; | |
| } | |
| #else | |
| str = (UINT)string[0]; | |
| #endif | |
| fct = fhdl->cache; | fct = fhdl->cache; |
| cnt = fhdl->caches; | cnt = fhdl->caches; |
| Line 615 FNTDAT fontmng_get(void *hdl, const char | Line 467 FNTDAT fontmng_get(void *hdl, const char |
| } | } |
| if (prev < FONTMNG_CACHE) { | if (prev < FONTMNG_CACHE) { |
| fct[prev].next = fct[pos].next; | fct[prev].next = fct[pos].next; |
| fct[pos].next = (WORD)fhdl->cachehead; | fct[pos].next = fhdl->cachehead; |
| fhdl->cachehead = pos; | fhdl->cachehead = pos; |
| } | } |
| return((FNTDAT)(((BYTE *)(fhdl + 1)) + (pos * fhdl->fontalign))); | return((FNTDAT)(((UINT8 *)(fhdl + 1)) + (pos * fhdl->fontalign))); |
| } | } |
| if (fhdl->caches < FONTMNG_CACHE) { | if (fhdl->caches < FONTMNG_CACHE) { |
| prev = fhdl->caches; | prev = fhdl->caches; |
| fhdl->caches++; | fhdl->caches++; |
| } | } |
| fct[prev].str = (WORD)str; | fct[prev].str = str; |
| fct[prev].next = (WORD)fhdl->cachehead; | fct[prev].next = fhdl->cachehead; |
| fhdl->cachehead = prev; | fhdl->cachehead = prev; |
| fdat = (FNTDAT)(((BYTE *)(fhdl + 1)) + (prev * fhdl->fontalign)); | fdat = (FNTDAT)(((UINT8 *)(fhdl + 1)) + (prev * fhdl->fontalign)); |
| } | } |
| #else | #else |
| fdat = (FNTDAT)(fhdl + 1); | fdat = (FNTDAT)(fhdl + 1); |
| #endif | #endif |
| fontmng_getchar(fhdl, fdat, string); | #if defined(OEMCHAR_SAME_TCHAR) |
| fontmng_getchar(fhdl, fdat, string, leng); | |
| #else | |
| { | |
| TCHAR tcharstr[4]; | |
| UINT tlen = oemtotchar(tcharstr, NELEMENTS(tcharstr), string, leng); | |
| fontmng_getchar(fhdl, fdat, tcharstr, tlen); | |
| } | |
| #endif | |
| fontmng_setpat(fhdl, fdat); | fontmng_setpat(fhdl, fdat); |
| return(fdat); | return(fdat); |