/* unicode*/ BOOL WINAPI ExtTextOutW(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc, LPCWSTR lpszString, UINT cbCount, CONST INT *lpDx) { return MwExtTextOut(hdc, x, y, fuOptions, lprc, lpszString, cbCount, lpDx, MWTF_UC16); }
/* ascii or utf8 */ BOOL WINAPI ExtTextOut(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc, LPCSTR lpszString, UINT cbCount, CONST INT *lpDx) { return MwExtTextOut(hdc, x, y, fuOptions, lprc, lpszString, cbCount, lpDx, mwTextCoding); }
/* ascii or utf8 */ BOOL WINAPI TextOut(HDC hdc, int x, int y, LPCSTR lpszString, int cbString) { /* kaffe port wants MWTF_UTF8 here...*/ return MwExtTextOut(hdc, x, y, 0, NULL, lpszString, cbString, NULL, mwTextCoding); }
/* internal version of DrawText, passed flags for text data type*/ static int MwDrawText(HDC hdc, LPCVOID lpString, int nCount, LPRECT lpRect, UINT uFormat, int flags) { MWCOORD x, y, width, height, baseline; if(nCount == -1) nCount = strlen(lpString); if(uFormat & (DT_CALCRECT|DT_CENTER|DT_RIGHT)) { if(!hdc) return 0; GdGetTextSize(hdc->font->pfont, lpString, nCount, &width, &height, &baseline, MWTF_ASCII); } x = lpRect->left; y = lpRect->top; if(uFormat & DT_CALCRECT) { lpRect->right = x + width; lpRect->bottom = y + height; return height; } if(uFormat & DT_CENTER) x = (lpRect->left + lpRect->right - width) / 2; else if(uFormat & DT_RIGHT) x += lpRect->right - width; /* draw text at DT_TOP using current fg, bg and bkmode*/ MwExtTextOut(hdc, x, y, 0, NULL, lpString, nCount, NULL, flags); return height; }
/* * MwDrawText Support routine: given a position, a string and length, * process underline, ampersands and tabs, and output * using mwExtTextOut ormwTabbedTextOut */ static void mwDrawTextOut(HDC hDC, int x, int y, LPSTR str, int len, UINT uFormat, int flags) { int i, j, k, dx, dy, x1; MWCOORD baseline; if(!hDC) return; for (i = 0, j = 0, k = 0, x1 = 0; i < len; i++) { if (str[i] == '&') { if (i) { if (uFormat & DT_EXPANDTABS) { mwTabbedTextOut(hDC, x, y, &str[j], i, 0, 0, x, FALSE, flags); x += LOWORD(mwTabbedTextOut(hDC, x, y, &str[j], i, 0, 0, 0, TRUE, flags)); } else { MwExtTextOut(hDC, x, y, 0, NULL, &str[j], i - j, NULL, flags); GdGetTextSize(hDC->font->pfont, &str[j], i - j, &dx, &dy, &baseline, flags); x += dx; } } if (str[i + 1] == '&') { TextOut(hDC, x, y, "&", 1); GdGetTextSize(hDC->font->pfont, "&", 1, &dx, &dy, &baseline, flags); x += dx; i++; } else { x1 = x; k = i + 1; } j = i + 1; } } if (i > j) { if (uFormat & DT_EXPANDTABS) mwTabbedTextOut(hDC, x, y, &str[j], i - j, 0, 0, x, FALSE, flags); else MwExtTextOut(hDC, x, y, 0, NULL, &str[j], i - j, NULL, flags); if (k && str[k] != ' ') { GdGetTextSize(hDC->font->pfont, &str[k], 1, &dx, &dy, &baseline, flags); dy -= dy / 18 + 1; /* underline position */ MoveToEx(hDC, x1, y + dy, NULL); LineTo(hDC, x1 + dx, y + dy); } } }
/* internal version of DrawText, passed flags for text data type*/ static int MwDrawText(HDC hdc, LPCVOID lpString, int nCount, LPRECT lpRect, UINT uFormat, int flags) { MWCOORD x, y, width, height, baseline; LPCSTR lpStrDup = NULL; RECT rcUline; if(!hdc) return 0; if(nCount == -1) nCount = strlen(lpString); if (!(uFormat & DT_NOPREFIX) && (lpStrDup = MwCheckUnderlineChar(hdc, lpString, &nCount, &rcUline))) lpString = lpStrDup; if(uFormat & (DT_CALCRECT|DT_CENTER|DT_RIGHT)) { GdGetTextSize(hdc->font->pfont, lpString, nCount, &width, &height, &baseline, flags); } x = lpRect->left; y = lpRect->top; if(uFormat & DT_CALCRECT) { #if 0 if (!(uFormat & DT_SINGLELINE)) { char *p=(char*)lpString, *pLast=p, *pMax=p; int iLenCur, iLenMax = 0, iLines = 0; long lMaxWidth = lpRect->right - lpRect->left; /* Determine line with maximum width */ for (pLast=p, pMax=p; ; p++) { if (*p=='\n' || !*p) { if (lMaxWidth) { do { iLenCur = p - pLast; GdGetTextSize(hdc->font->pfont, pLast, iLenCur, &width, &height, &baseline, flags); if (width <= lMaxWidth) break; while (p>(char*)lpString && (*p==' ' || *p=='\t')) p--; while (p>(char*)lpString && !(*p==' ' || *p=='\t')) p--; } while (width > lMaxWidth && p>(char*)lpString); } if ((iLenCur = p - pLast) > iLenMax) { iLenMax = iLenCur; pMax = pLast; } pLast = p+1; iLines++; } if (!*p) break; } GdGetTextSize(hdc->font->pfont, pMax, iLenMax, &width, &height, &baseline, flags); height *= iLines; } #endif lpRect->right = x + width; lpRect->bottom = y + height; if (lpStrDup) free(lpStrDup); return height; } if(uFormat & DT_CENTER) x = (lpRect->left + lpRect->right - width) / 2; else if(uFormat & DT_RIGHT) x = lpRect->right - width; if(uFormat & DT_VCENTER) y = lpRect->bottom / 2 - (height / 2); if(uFormat & DT_BOTTOM) { flags |= MWTF_BOTTOM; y = lpRect->bottom; } /* draw text at DT_TOP using current fg, bg and bkmode*/ MwExtTextOut(hdc, x, y, 0, NULL, lpString, nCount, NULL, flags); if (lpStrDup) { OffsetRect(&rcUline, x, y); SelectObject(hdc, GetStockObject(BLACK_PEN)); MoveToEx(hdc, rcUline.left, rcUline.bottom, NULL); LineTo(hdc, rcUline.right, rcUline.bottom); free(lpStrDup); } return height; }