| 1 | /* $Id: text.cpp,v 1.43 2004-01-15 11:18:58 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * GDI32 text apis
|
|---|
| 5 | *
|
|---|
| 6 | * Based on Wine/ReWind code (objects\text.c, objects\font.c)
|
|---|
| 7 | *
|
|---|
| 8 | * Copyright 1993, 1994 Alexandre Julliard
|
|---|
| 9 | * 1997 Alex Korobka
|
|---|
| 10 | *
|
|---|
| 11 | * Copyright 1999-2000 Christoph Bratschi
|
|---|
| 12 | * Copyright 2002-2003 Innotek Systemberatung GmbH (sandervl@innotek.de)
|
|---|
| 13 | *
|
|---|
| 14 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 15 | *
|
|---|
| 16 | */
|
|---|
| 17 | #include <os2win.h>
|
|---|
| 18 | #include <stdlib.h>
|
|---|
| 19 | #include <stdio.h>
|
|---|
| 20 | #include <misc.h>
|
|---|
| 21 | #include <string.h>
|
|---|
| 22 | #include <float.h>
|
|---|
| 23 | #include "oslibgpi.h"
|
|---|
| 24 | #include <dcdata.h>
|
|---|
| 25 | #include <unicode.h>
|
|---|
| 26 | #include "dibsect.h"
|
|---|
| 27 | #include "ft2supp.h"
|
|---|
| 28 | #include "font.h"
|
|---|
| 29 | #include <math.h>
|
|---|
| 30 |
|
|---|
| 31 | #define DBG_LOCALLOG DBG_text
|
|---|
| 32 | #include "dbglocal.h"
|
|---|
| 33 |
|
|---|
| 34 | #define ELLIPSIS "..."
|
|---|
| 35 | #define ELLIPSISLEN 3
|
|---|
| 36 |
|
|---|
| 37 | //******************************************************************************
|
|---|
| 38 | //******************************************************************************
|
|---|
| 39 | CHAR getBrokenDBCS( LPCSTR strA, INT lenA )
|
|---|
| 40 | {
|
|---|
| 41 | int i;
|
|---|
| 42 |
|
|---|
| 43 | for( i = 0; i < lenA; i++ )
|
|---|
| 44 | if( IsDBCSLeadByte( strA[ i ]))
|
|---|
| 45 | i++;
|
|---|
| 46 |
|
|---|
| 47 | if( lenA < i ) // terminated at DBCS lead byte
|
|---|
| 48 | return strA[ lenA ];
|
|---|
| 49 |
|
|---|
| 50 | return 0;
|
|---|
| 51 | }
|
|---|
| 52 | //******************************************************************************
|
|---|
| 53 | //******************************************************************************
|
|---|
| 54 | UINT WINAPI GetTextCharsetInfo(
|
|---|
| 55 | HDC hdc, /* [in] Handle to device context */
|
|---|
| 56 | LPFONTSIGNATURE fs, /* [out] Pointer to struct to receive data */
|
|---|
| 57 | DWORD flags) /* [in] Reserved - must be 0 */
|
|---|
| 58 | {
|
|---|
| 59 | HGDIOBJ hFont;
|
|---|
| 60 | UINT charSet = DEFAULT_CHARSET;
|
|---|
| 61 | LOGFONTW lf;
|
|---|
| 62 | CHARSETINFO csinfo;
|
|---|
| 63 |
|
|---|
| 64 | dprintf(("GetTextCharsetInfo %x %x %x", hdc, fs, flags));
|
|---|
| 65 |
|
|---|
| 66 | hFont = GetCurrentObject(hdc, OBJ_FONT);
|
|---|
| 67 | if (hFont == 0)
|
|---|
| 68 | return(DEFAULT_CHARSET);
|
|---|
| 69 | if ( GetObjectW(hFont, sizeof(LOGFONTW), &lf) != 0 )
|
|---|
| 70 | charSet = lf.lfCharSet;
|
|---|
| 71 |
|
|---|
| 72 | if (fs != NULL) {
|
|---|
| 73 | if (!TranslateCharsetInfo((LPDWORD)charSet, &csinfo, TCI_SRCCHARSET))
|
|---|
| 74 | return (DEFAULT_CHARSET);
|
|---|
| 75 | memcpy(fs, &csinfo.fs, sizeof(FONTSIGNATURE));
|
|---|
| 76 | }
|
|---|
| 77 | return charSet;
|
|---|
| 78 | }
|
|---|
| 79 | /***********************************************************************
|
|---|
| 80 | * GetTextCharset32 [GDI32.226] Gets character set for font in DC
|
|---|
| 81 | *
|
|---|
| 82 | * NOTES
|
|---|
| 83 | * Should it return a UINT32 instead of an INT32?
|
|---|
| 84 | * => YES, as GetTextCharsetInfo returns UINT32
|
|---|
| 85 | *
|
|---|
| 86 | * RETURNS
|
|---|
| 87 | * Success: Character set identifier
|
|---|
| 88 | * Failure: DEFAULT_CHARSET
|
|---|
| 89 | */
|
|---|
| 90 | UINT WINAPI GetTextCharset(HDC hdc) /* [in] Handle to device context */
|
|---|
| 91 | {
|
|---|
| 92 | /* MSDN docs say this is equivalent */
|
|---|
| 93 | return GetTextCharsetInfo(hdc, NULL, 0);
|
|---|
| 94 | }
|
|---|
| 95 | //******************************************************************************
|
|---|
| 96 | // todo: metafile support
|
|---|
| 97 | //#undef INVERT
|
|---|
| 98 | //#define INVERT_SETYINVERSION
|
|---|
| 99 | //******************************************************************************
|
|---|
| 100 | BOOL InternalTextOutAW(HDC hdc,int X,int Y,UINT fuOptions,
|
|---|
| 101 | CONST RECT *lprc, LPCSTR lpszStringA, LPCWSTR lpszStringW,
|
|---|
| 102 | INT cbCount,CONST INT *lpDx,BOOL IsExtTextOut, BOOL fUnicode)
|
|---|
| 103 | {
|
|---|
| 104 | pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);
|
|---|
| 105 | ULONG flOptions = 0;
|
|---|
| 106 | RECTLOS2 pmRect;
|
|---|
| 107 | POINTLOS2 ptl;
|
|---|
| 108 | LONG hits;
|
|---|
| 109 | RECT rect;
|
|---|
| 110 |
|
|---|
| 111 | if (!pHps || (cbCount < 0) || (((lpszStringA == NULL && !fUnicode) || (lpszStringW == NULL && fUnicode)) && (cbCount != 0)))
|
|---|
| 112 | {
|
|---|
| 113 | dprintf(("InternalTextOutA: invalid parameter"));
|
|---|
| 114 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 115 | return FALSE;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | if(cbCount == -1) {
|
|---|
| 119 | if(fUnicode)
|
|---|
| 120 | cbCount = lstrlenW(lpszStringW);
|
|---|
| 121 | else cbCount = lstrlenA(lpszStringA);
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | if (cbCount > 512)
|
|---|
| 125 | {
|
|---|
| 126 | dprintf(("InternalTextOutA: invalid parameter cbCount"));
|
|---|
| 127 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 128 | return FALSE;
|
|---|
| 129 | }
|
|---|
| 130 | if (fuOptions & ~((UINT)(ETO_CLIPPED | ETO_OPAQUE | ETO_GLYPH_INDEX)))
|
|---|
| 131 | {
|
|---|
| 132 | dprintf(("InternalTextOutA: invalid fuOptions"));
|
|---|
| 133 | //ETO_GLYPH_INDEX, ETO_RTLLEADING, ETO_NUMERICSLOCAL, ETO_NUMERICSLATIN, ETO_IGNORELANGUAGE, ETO_PDY are ignored
|
|---|
| 134 | return TRUE;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | #if defined(INVERT) && !defined(INVERT_SETYINVERSION)
|
|---|
| 138 | if(pHps->yInvert > 0) {
|
|---|
| 139 | Y = pHps->yInvert - Y;
|
|---|
| 140 | }
|
|---|
| 141 | #endif
|
|---|
| 142 |
|
|---|
| 143 | #ifdef INVERT_SETYINVERSION
|
|---|
| 144 | int oldyinv = GpiQueryYInversion(pHps->hps);
|
|---|
| 145 | Y = oldyinv - Y;
|
|---|
| 146 | #endif
|
|---|
| 147 |
|
|---|
| 148 | // When using font association, the height of DBCS and SBCS chars may be different.
|
|---|
| 149 | // In this case, background color make stair below chars
|
|---|
| 150 | if( IsDBCSEnv() && !lprc && ( GetBkMode( hdc ) & OPAQUE ))
|
|---|
| 151 | {
|
|---|
| 152 | SIZE size;
|
|---|
| 153 | TEXTMETRICA tmA;
|
|---|
| 154 |
|
|---|
| 155 | if( fUnicode )
|
|---|
| 156 | GetTextExtentPointW( hdc, lpszStringW, cbCount, &size );
|
|---|
| 157 | else
|
|---|
| 158 | GetTextExtentPointA( hdc, lpszStringA, cbCount, &size );
|
|---|
| 159 |
|
|---|
| 160 | GetTextMetricsA( hdc, &tmA );
|
|---|
| 161 |
|
|---|
| 162 | rect.left = X;
|
|---|
| 163 | rect.right = X + size.cx;
|
|---|
| 164 | rect.top = Y;
|
|---|
| 165 | rect.bottom = Y + tmA.tmHeight;
|
|---|
| 166 |
|
|---|
| 167 | lprc = ▭
|
|---|
| 168 | fuOptions |= ETO_OPAQUE;
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | //CB: add metafile info
|
|---|
| 172 |
|
|---|
| 173 | if (lprc)
|
|---|
| 174 | {
|
|---|
| 175 | if (fuOptions)
|
|---|
| 176 | {
|
|---|
| 177 | MapWin32ToOS2Rect(*lprc,pmRect);
|
|---|
| 178 | if (excludeBottomRightPoint(pHps,(PPOINTLOS2)&pmRect) == 0)
|
|---|
| 179 | {
|
|---|
| 180 | dprintf(("InternalTextOutA: excludeBottomRightPoint returned 0"));
|
|---|
| 181 | return TRUE;
|
|---|
| 182 | }
|
|---|
| 183 | #ifndef INVERT
|
|---|
| 184 | #ifdef INVERT_SETYINVERSION
|
|---|
| 185 | if (oldyinv) {
|
|---|
| 186 | int temp = oldyinv - pmRect.yTop;
|
|---|
| 187 | pmRect.yTop = oldyinv - pmRect.yBottom;
|
|---|
| 188 | pmRect.yBottom = temp;
|
|---|
| 189 | }
|
|---|
| 190 | #else
|
|---|
| 191 | if (pHps->yInvert > 0) {
|
|---|
| 192 | int temp = pHps->yInvert - pmRect.yTop;
|
|---|
| 193 | pmRect.yTop = pHps->yInvert - pmRect.yBottom;
|
|---|
| 194 | pmRect.yBottom = temp;
|
|---|
| 195 | }
|
|---|
| 196 | #endif
|
|---|
| 197 | #endif
|
|---|
| 198 |
|
|---|
| 199 | if (fuOptions & ETO_CLIPPED) flOptions |= CHSOS_CLIP;
|
|---|
| 200 | if (fuOptions & ETO_OPAQUE) flOptions |= CHSOS_OPAQUE;
|
|---|
| 201 | }
|
|---|
| 202 | }
|
|---|
| 203 | else
|
|---|
| 204 | {
|
|---|
| 205 | if (fuOptions & ~ETO_GLYPH_INDEX)
|
|---|
| 206 | {
|
|---|
| 207 | dprintf(("InternalTextOutA: ERROR_INVALID_PARAMETER"));
|
|---|
| 208 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 209 | return FALSE;
|
|---|
| 210 | }
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | if((lpszStringA || lpszStringW) && cbCount) {
|
|---|
| 214 | DIBSECTION_CHECK_IF_DIRTY(hdc);
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | if (cbCount == 0)
|
|---|
| 218 | {
|
|---|
| 219 | if (fuOptions & ETO_OPAQUE)
|
|---|
| 220 | {
|
|---|
| 221 | //SvL: This doesn't seem to work (anymore). Look at MFC apps for the missing border
|
|---|
| 222 | // between menu & button bar (all white). (e.g. odin app & acrobat reader 4.05)
|
|---|
| 223 | #if 0
|
|---|
| 224 | lpszString = " ";
|
|---|
| 225 | cbCount = 1;
|
|---|
| 226 | flOptions |= CHSOS_CLIP;
|
|---|
| 227 | #else
|
|---|
| 228 | HBRUSH hbrush = CreateSolidBrush(GetBkColor(hdc));
|
|---|
| 229 | HBRUSH oldbrush;
|
|---|
| 230 |
|
|---|
| 231 | oldbrush = SelectObject(hdc, hbrush);
|
|---|
| 232 | FillRect(hdc, lprc, hbrush);
|
|---|
| 233 | SelectObject(hdc, oldbrush);
|
|---|
| 234 | DeleteObject(hbrush);
|
|---|
| 235 |
|
|---|
| 236 | DIBSECTION_MARK_INVALID(hdc);
|
|---|
| 237 |
|
|---|
| 238 | return TRUE;
|
|---|
| 239 | #endif
|
|---|
| 240 | }
|
|---|
| 241 | else {
|
|---|
| 242 | dprintf(("InternalTextOutA: cbCount == 0"));
|
|---|
| 243 | return TRUE;
|
|---|
| 244 | }
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | #ifdef INVERT_SETYINVERSION
|
|---|
| 248 | GpiEnableYInversion(pHps->hps, 0);
|
|---|
| 249 | #endif
|
|---|
| 250 |
|
|---|
| 251 | if (lpDx)
|
|---|
| 252 | flOptions |= CHSOS_VECTOR;
|
|---|
| 253 |
|
|---|
| 254 | if (!getAlignUpdateCP(pHps))
|
|---|
| 255 | {
|
|---|
| 256 | ptl.x = X;
|
|---|
| 257 | ptl.y = Y;
|
|---|
| 258 |
|
|---|
| 259 | flOptions |= CHSOS_LEAVEPOS;
|
|---|
| 260 | }
|
|---|
| 261 | else OSLibGpiQueryCurrentPosition(pHps,&ptl);
|
|---|
| 262 |
|
|---|
| 263 | UINT align = GetTextAlign(hdc);
|
|---|
| 264 | LONG pmHAlign,pmVAlign;
|
|---|
| 265 |
|
|---|
| 266 | #if 0
|
|---|
| 267 | //SvL: This code is broken. TODO: Investigate
|
|---|
| 268 | //CB: TA_RIGHT not supported by PM, only TA_CENTER and TA_LEFT
|
|---|
| 269 | if ((align & 0x6) == TA_RIGHT)
|
|---|
| 270 | {
|
|---|
| 271 | BOOL rc;
|
|---|
| 272 | PPOINTLOS2 pts = (PPOINTLOS2)malloc((cbCount+1)*sizeof(POINTLOS2));
|
|---|
| 273 |
|
|---|
| 274 | rc = OSLibGpiQueryCharStringPosAt(pHps,&ptl,flOptions & CHSOS_VECTOR,cbCount,lpszString,lpDx,pts);
|
|---|
| 275 | if(rc) {
|
|---|
| 276 | for(int i=0;i<cbCount+1;i++) {
|
|---|
| 277 | dprintf(("OSLibGpiQueryCharStringPosAt %d (%d,%d)", pts[i].x, pts[i].y));
|
|---|
| 278 | }
|
|---|
| 279 | ptl.x -= pts[cbCount].x-pts[0].x;
|
|---|
| 280 | }
|
|---|
| 281 | free(pts);
|
|---|
| 282 | }
|
|---|
| 283 | #endif
|
|---|
| 284 |
|
|---|
| 285 | if (lprc && ((align & 0x18) == TA_BASELINE))
|
|---|
| 286 | {
|
|---|
| 287 | //CB: if TA_BASELINE is set, GPI doesn't fill rect
|
|---|
| 288 | // TA_BOTTOM fills rect
|
|---|
| 289 | OSLibGpiQueryTextAlignment(pHps,&pmHAlign,&pmVAlign);
|
|---|
| 290 | OSLibGpiSetTextAlignment(pHps,pmHAlign,(pmVAlign & ~TAOS_BASE) | TAOS_BOTTOM);
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 293 | #ifdef INVERT
|
|---|
| 294 | ptl.y += getWorldYDeltaFor1Pixel(pHps);
|
|---|
| 295 | #else
|
|---|
| 296 | ptl.y -= getWorldYDeltaFor1Pixel(pHps);
|
|---|
| 297 |
|
|---|
| 298 | int vertAdjust = 0;
|
|---|
| 299 | if ((pHps->taMode & 0x18) != TA_TOP)
|
|---|
| 300 | {
|
|---|
| 301 | vertAdjust = OSLibGpiQueryFontMaxHeight(pHps->hps);
|
|---|
| 302 | }
|
|---|
| 303 | ptl.y -= vertAdjust;
|
|---|
| 304 | #endif
|
|---|
| 305 |
|
|---|
| 306 | if(fUnicode)
|
|---|
| 307 | hits = FT2Module.Ft2CharStringPosAtW(pHps->hps,&ptl,&pmRect,flOptions,cbCount,lpszStringW,lpDx, fuOptions & ETO_GLYPH_INDEX);
|
|---|
| 308 | else hits = FT2Module.Ft2CharStringPosAtA(pHps->hps,&ptl,&pmRect,flOptions,cbCount,lpszStringA,lpDx, fuOptions & ETO_GLYPH_INDEX);
|
|---|
| 309 |
|
|---|
| 310 | if (lprc && ((align & 0x18) == TA_BASELINE))
|
|---|
| 311 | OSLibGpiSetTextAlignment(pHps,pmHAlign,pmVAlign);
|
|---|
| 312 |
|
|---|
| 313 | if(hits == GPIOS_ERROR) {
|
|---|
| 314 | dprintf(("InternalTextOutA: OSLibGpiCharStringPosAt returned GPIOS_ERROR"));
|
|---|
| 315 | #ifdef INVERT_SETYINVERSION
|
|---|
| 316 | GpiEnableYInversion(pHps->hps, oldyinv);
|
|---|
| 317 | #endif
|
|---|
| 318 | return FALSE;
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | if (getAlignUpdateCP(pHps))
|
|---|
| 322 | {
|
|---|
| 323 | OSLibGpiQueryCurrentPosition(pHps,&ptl);
|
|---|
| 324 | ptl.y -= getWorldYDeltaFor1Pixel(pHps);
|
|---|
| 325 | #ifndef INVERT
|
|---|
| 326 | ptl.y += vertAdjust;
|
|---|
| 327 | #endif
|
|---|
| 328 | OSLibGpiSetCurrentPosition(pHps,&ptl);
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | #ifdef INVERT_SETYINVERSION
|
|---|
| 332 | GpiEnableYInversion(pHps->hps, oldyinv);
|
|---|
| 333 | #endif
|
|---|
| 334 |
|
|---|
| 335 | DIBSECTION_MARK_INVALID(hdc);
|
|---|
| 336 |
|
|---|
| 337 | return TRUE;
|
|---|
| 338 | }
|
|---|
| 339 | //******************************************************************************
|
|---|
| 340 | //******************************************************************************
|
|---|
| 341 | BOOL WIN32API ExtTextOutA(HDC hdc,int X,int Y,UINT fuOptions,CONST RECT *lprc,LPCSTR lpszString,UINT cbCount,CONST INT *lpDx)
|
|---|
| 342 | {
|
|---|
| 343 | BOOL rc;
|
|---|
| 344 | SIZE size;
|
|---|
| 345 | int newy;
|
|---|
| 346 |
|
|---|
| 347 | if(lprc)
|
|---|
| 348 | {
|
|---|
| 349 | dprintf(("GDI32: ExtTextOutA %x %.*s (%d,%d) %x %d %x rect (%d,%d)(%d,%d)", hdc, cbCount, lpszString, X, Y, fuOptions, cbCount, lpDx, lprc->left, lprc->top, lprc->right, lprc->bottom));
|
|---|
| 350 | }
|
|---|
| 351 | else dprintf(("GDI32: ExtTextOutA %x %.*s (%d,%d) %x %d %x", hdc, cbCount, lpszString, X, Y, fuOptions, cbCount, lpDx));
|
|---|
| 352 |
|
|---|
| 353 | rc = InternalTextOutAW(hdc, X, Y, fuOptions, lprc, lpszString, NULL, cbCount, lpDx, TRUE, FALSE);
|
|---|
| 354 |
|
|---|
| 355 | return(rc);
|
|---|
| 356 | }
|
|---|
| 357 | //******************************************************************************
|
|---|
| 358 | //******************************************************************************
|
|---|
| 359 | BOOL WIN32API ExtTextOutW(HDC hdc,int X,int Y,UINT fuOptions,CONST RECT *lprc,LPCWSTR lpszString,UINT cbCount,CONST int *lpDx)
|
|---|
| 360 | {
|
|---|
| 361 | if(lprc) {
|
|---|
| 362 | dprintf(("GDI32: ExtTextOutW %x %.*ls (%d,%d) %x %d %x rect (%d,%d)(%d,%d)", hdc, cbCount, lpszString, X, Y, fuOptions, cbCount, lpDx, lprc->left, lprc->top, lprc->right, lprc->bottom));
|
|---|
| 363 | }
|
|---|
| 364 | else dprintf(("GDI32: ExtTextOutW %x %.*ls (%d,%d) %x %d %x", hdc, cbCount, lpszString, X, Y, fuOptions, cbCount, lpDx));
|
|---|
| 365 |
|
|---|
| 366 | return InternalTextOutAW(hdc, X, Y, fuOptions, lprc, NULL, lpszString, cbCount, lpDx, TRUE, TRUE);
|
|---|
| 367 | }
|
|---|
| 368 | //******************************************************************************
|
|---|
| 369 | //******************************************************************************
|
|---|
| 370 | BOOL WIN32API TextOutA(HDC hdc,int nXStart,int nYStart,LPCSTR lpszString,int cbString)
|
|---|
| 371 | {
|
|---|
| 372 | dprintf(("GDI32: TextOutA %x (%d,%d) %d %.*s", hdc, nXStart, nYStart, cbString, cbString, lpszString));
|
|---|
| 373 | return InternalTextOutAW(hdc,nXStart,nYStart,0,NULL,lpszString,NULL,cbString,NULL,FALSE, FALSE);
|
|---|
| 374 | }
|
|---|
| 375 | //******************************************************************************
|
|---|
| 376 | //******************************************************************************
|
|---|
| 377 | BOOL WIN32API TextOutW(HDC hdc,int nXStart,int nYStart,LPCWSTR lpszString,int cbString)
|
|---|
| 378 | {
|
|---|
| 379 | dprintf(("GDI32: TextOutW %x (%d,%d) %d %.*ls", hdc, nXStart, nYStart, cbString, cbString, lpszString));
|
|---|
| 380 | return InternalTextOutAW(hdc,nXStart,nYStart,0,NULL, NULL, lpszString,cbString,NULL,FALSE, TRUE);
|
|---|
| 381 | }
|
|---|
| 382 | //******************************************************************************
|
|---|
| 383 | //******************************************************************************
|
|---|
| 384 | BOOL WIN32API PolyTextOutA(HDC hdc,POLYTEXTA *pptxt,int cStrings)
|
|---|
| 385 | {
|
|---|
| 386 | dprintf(("GDI32: PolyTextOutA %x %x %d", hdc, pptxt, cStrings));
|
|---|
| 387 |
|
|---|
| 388 | for (INT x = 0;x < cStrings;x++)
|
|---|
| 389 | {
|
|---|
| 390 | BOOL rc;
|
|---|
| 391 |
|
|---|
| 392 | rc = ExtTextOutA(hdc,pptxt[x].x,pptxt[x].y,pptxt[x].uiFlags,&pptxt[x].rcl,pptxt[x].lpstr, pptxt[x].n,pptxt[x].pdx);
|
|---|
| 393 | if (!rc) return FALSE;
|
|---|
| 394 | }
|
|---|
| 395 |
|
|---|
| 396 | return TRUE;
|
|---|
| 397 | }
|
|---|
| 398 | //******************************************************************************
|
|---|
| 399 | //******************************************************************************
|
|---|
| 400 | BOOL WIN32API PolyTextOutW(HDC hdc,POLYTEXTW *pptxt,int cStrings)
|
|---|
| 401 | {
|
|---|
| 402 | dprintf(("GDI32: PolyTextOutW %x %x %d", hdc, pptxt, cStrings));
|
|---|
| 403 |
|
|---|
| 404 | for (INT x = 0;x < cStrings;x++)
|
|---|
| 405 | {
|
|---|
| 406 | BOOL rc;
|
|---|
| 407 |
|
|---|
| 408 | rc = ExtTextOutW(hdc,pptxt[x].x,pptxt[x].y,pptxt[x].uiFlags,&pptxt[x].rcl, pptxt[x].lpstr,pptxt[x].n,pptxt[x].pdx);
|
|---|
| 409 | if (!rc) return FALSE;
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | return TRUE;
|
|---|
| 413 | }
|
|---|
| 414 | //******************************************************************************
|
|---|
| 415 | // Note: GetTextExtentPoint behaves differently under certain circumstances
|
|---|
| 416 | // compared to GetTextExtentPoint32 (due to bugs).
|
|---|
| 417 | // We are treating both as the same thing which is not entirely correct.
|
|---|
| 418 | //
|
|---|
| 419 | //******************************************************************************
|
|---|
| 420 | BOOL WIN32API GetTextExtentPointA(HDC hdc, LPCTSTR lpsz, int cbString,
|
|---|
| 421 | LPSIZE lpsSize)
|
|---|
| 422 | {
|
|---|
| 423 | BOOL ret = FALSE;
|
|---|
| 424 | INT wlen;
|
|---|
| 425 | LPWSTR p;
|
|---|
| 426 | CHAR brokenDBCS = 0;
|
|---|
| 427 |
|
|---|
| 428 | if( IsDBCSEnv())
|
|---|
| 429 | brokenDBCS = getBrokenDBCS( lpsz, cbString );
|
|---|
| 430 |
|
|---|
| 431 | if( brokenDBCS )
|
|---|
| 432 | cbString--;
|
|---|
| 433 |
|
|---|
| 434 | p = FONT_mbtowc(hdc, lpsz, cbString, &wlen, NULL);
|
|---|
| 435 | if (p) {
|
|---|
| 436 | ret = GetTextExtentPointW( hdc, p, wlen, lpsSize );
|
|---|
| 437 | // For broken DBCS. Correct for FIXED WIDTH, but approx. for VARIABLE WIDTH
|
|---|
| 438 | if( brokenDBCS )
|
|---|
| 439 | {
|
|---|
| 440 | TEXTMETRICA tmA;
|
|---|
| 441 |
|
|---|
| 442 | GetTextMetricsA( hdc, &tmA );
|
|---|
| 443 | lpsSize->cx += tmA.tmAveCharWidth;
|
|---|
| 444 |
|
|---|
| 445 | if( cbString == 0 )
|
|---|
| 446 | lpsSize->cy = tmA.tmHeight;
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | HeapFree( GetProcessHeap(), 0, p );
|
|---|
| 450 | }
|
|---|
| 451 | else DebugInt3();
|
|---|
| 452 | return ret;
|
|---|
| 453 | }
|
|---|
| 454 | //******************************************************************************
|
|---|
| 455 | //******************************************************************************
|
|---|
| 456 | BOOL WIN32API GetTextExtentPointW(HDC hdc,
|
|---|
| 457 | LPCWSTR lpString,
|
|---|
| 458 | int cbString,
|
|---|
| 459 | PSIZE lpSize)
|
|---|
| 460 | {
|
|---|
| 461 | BOOL rc;
|
|---|
| 462 | POINTLOS2 widthHeight = { 0, 0};
|
|---|
| 463 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
|
|---|
| 464 |
|
|---|
| 465 | dprintf(("GDI32: GetTextExtentPointW %.*ls", cbString, lpString));
|
|---|
| 466 | if(pHps == NULL)
|
|---|
| 467 | {
|
|---|
| 468 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 469 | return FALSE;
|
|---|
| 470 | }
|
|---|
| 471 |
|
|---|
| 472 | if(lpString == NULL || cbString < 0 || lpSize == NULL)
|
|---|
| 473 | {
|
|---|
| 474 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 475 | return FALSE;
|
|---|
| 476 | }
|
|---|
| 477 |
|
|---|
| 478 | lpSize->cx = 0;
|
|---|
| 479 | lpSize->cy = 0;
|
|---|
| 480 |
|
|---|
| 481 | // Verified with NT4, SP6
|
|---|
| 482 | if(cbString == 0)
|
|---|
| 483 | {
|
|---|
| 484 | dprintf(("!WARNING!: GDI32: GetTextExtentPointW invalid parameter!"));
|
|---|
| 485 | SetLastError(ERROR_SUCCESS);
|
|---|
| 486 | return TRUE;
|
|---|
| 487 | }
|
|---|
| 488 |
|
|---|
| 489 | if(pHps->isPrinter)
|
|---|
| 490 | ReallySetCharAttrs(pHps);
|
|---|
| 491 |
|
|---|
| 492 | if(cbString > 512)
|
|---|
| 493 | {
|
|---|
| 494 | DWORD cbStringNew;
|
|---|
| 495 | SIZE newSize;
|
|---|
| 496 |
|
|---|
| 497 | dprintf(("WARNING: string longer than 512 chars; splitting up"));
|
|---|
| 498 | while(cbString) {
|
|---|
| 499 | cbStringNew = min(500, cbString);
|
|---|
| 500 | rc = GetTextExtentPointW(hdc, lpString, cbStringNew, &newSize);
|
|---|
| 501 | if(rc == FALSE) {
|
|---|
| 502 | return FALSE;
|
|---|
| 503 | }
|
|---|
| 504 | lpSize->cx += newSize.cx;
|
|---|
| 505 | lpSize->cy = max(newSize.cy, lpSize->cy);
|
|---|
| 506 | lpString += cbStringNew;
|
|---|
| 507 | cbString -= cbStringNew;
|
|---|
| 508 | }
|
|---|
| 509 | return TRUE;
|
|---|
| 510 | }
|
|---|
| 511 |
|
|---|
| 512 | rc = FT2Module.Ft2GetTextExtentW(pHps->hps, cbString, lpString, &widthHeight);
|
|---|
| 513 | if(rc == FALSE)
|
|---|
| 514 | {
|
|---|
| 515 | SetLastError(ERROR_INVALID_PARAMETER); //todo wrong error
|
|---|
| 516 | return FALSE;
|
|---|
| 517 | }
|
|---|
| 518 | lpSize->cx = widthHeight.x;
|
|---|
| 519 | lpSize->cy = widthHeight.y;
|
|---|
| 520 |
|
|---|
| 521 | if(pHps && pHps->isPrinter && pHps->hdc)
|
|---|
| 522 | {//scale for printer dcs
|
|---|
| 523 | LONG alArray[2];
|
|---|
| 524 |
|
|---|
| 525 | if(OSLibDevQueryCaps(pHps, OSLIB_CAPS_HORIZONTAL_RESOLUTION, 2, &alArray[0]))
|
|---|
| 526 | lpSize->cx = lpSize->cx * alArray[0] / alArray[1];
|
|---|
| 527 | }
|
|---|
| 528 |
|
|---|
| 529 | dprintf(("GDI32: GetTextExtentPointW %x %ls %d returned %d (%d,%d)", hdc, lpString, cbString, rc, lpSize->cx, lpSize->cy));
|
|---|
| 530 | SetLastError(ERROR_SUCCESS);
|
|---|
| 531 | return TRUE;
|
|---|
| 532 | }
|
|---|
| 533 | //******************************************************************************
|
|---|
| 534 | //******************************************************************************
|
|---|
| 535 | BOOL WIN32API GetTextExtentPoint32A( HDC hdc, LPCSTR lpsz, int cbString, PSIZE lpSize)
|
|---|
| 536 | {
|
|---|
| 537 | return GetTextExtentPointA(hdc, lpsz, cbString, lpSize);
|
|---|
| 538 | }
|
|---|
| 539 | //******************************************************************************
|
|---|
| 540 | //******************************************************************************
|
|---|
| 541 | BOOL WIN32API GetTextExtentPoint32W(HDC hdc, LPCWSTR lpsz, int cbString, PSIZE lpSize)
|
|---|
| 542 | {
|
|---|
| 543 | return GetTextExtentPointW(hdc, lpsz, cbString, lpSize);
|
|---|
| 544 | }
|
|---|
| 545 |
|
|---|
| 546 | typedef BOOL ( WIN32API *PFN_GETTEXTEXTENTPOINT32 )( HDC, PVOID, INT, LPSIZE );
|
|---|
| 547 |
|
|---|
| 548 | BOOL InternalGetTextExtentExPointAW(HDC hdc,
|
|---|
| 549 | PVOID str,
|
|---|
| 550 | INT count,
|
|---|
| 551 | INT maxExt,
|
|---|
| 552 | LPINT lpnFit,
|
|---|
| 553 | LPINT alpDx,
|
|---|
| 554 | LPSIZE size,
|
|---|
| 555 | BOOL fUnicode)
|
|---|
| 556 | {
|
|---|
| 557 | int i, nFit;
|
|---|
| 558 | SIZE tSize;
|
|---|
| 559 | BOOL ret = FALSE;
|
|---|
| 560 |
|
|---|
| 561 | PFN_GETTEXTEXTENTPOINT32 pfnGetTextExtentPoint32;
|
|---|
| 562 |
|
|---|
| 563 | if( fUnicode )
|
|---|
| 564 | pfnGetTextExtentPoint32 = ( PFN_GETTEXTEXTENTPOINT32 )GetTextExtentPoint32W;
|
|---|
| 565 | else
|
|---|
| 566 | pfnGetTextExtentPoint32 = ( PFN_GETTEXTEXTENTPOINT32 )GetTextExtentPoint32A;
|
|---|
| 567 |
|
|---|
| 568 | size->cx = size->cy = nFit = i = 0;
|
|---|
| 569 |
|
|---|
| 570 | if( lpnFit || alpDx )
|
|---|
| 571 | {
|
|---|
| 572 | for( i = 1; i <= count; i++ )
|
|---|
| 573 | {
|
|---|
| 574 | if( !pfnGetTextExtentPoint32( hdc, str, i, &tSize )) goto done;
|
|---|
| 575 |
|
|---|
| 576 | if( lpnFit && ( maxExt < tSize.cx ))
|
|---|
| 577 | break;
|
|---|
| 578 |
|
|---|
| 579 | if( alpDx )
|
|---|
| 580 | alpDx[ nFit ] = tSize.cx;
|
|---|
| 581 |
|
|---|
| 582 | nFit++;
|
|---|
| 583 | }
|
|---|
| 584 | }
|
|---|
| 585 |
|
|---|
| 586 | if(( count > 0 ) && ( i >= count ))
|
|---|
| 587 | {
|
|---|
| 588 | size->cx = tSize.cx;
|
|---|
| 589 | size->cy = tSize.cy; // The height of a font is constant.
|
|---|
| 590 | }
|
|---|
| 591 | else if( !pfnGetTextExtentPoint32( hdc, str, count, size )) goto done;
|
|---|
| 592 |
|
|---|
| 593 | if(lpnFit) *lpnFit = nFit;
|
|---|
| 594 | ret = TRUE;
|
|---|
| 595 |
|
|---|
| 596 | dprintf(("returning %d %ld x %ld\n",nFit,size->cx,size->cy));
|
|---|
| 597 |
|
|---|
| 598 | done:
|
|---|
| 599 | return ret;
|
|---|
| 600 | }
|
|---|
| 601 |
|
|---|
| 602 | //******************************************************************************
|
|---|
| 603 | //******************************************************************************
|
|---|
| 604 | BOOL WIN32API GetTextExtentExPointA(HDC hdc,
|
|---|
| 605 | LPCSTR str,
|
|---|
| 606 | int count,
|
|---|
| 607 | int maxExt,
|
|---|
| 608 | LPINT lpnFit,
|
|---|
| 609 | LPINT alpDx,
|
|---|
| 610 | LPSIZE size)
|
|---|
| 611 | {
|
|---|
| 612 | return InternalGetTextExtentExPointAW( hdc, ( PVOID )str, count, maxExt, lpnFit, alpDx, size, FALSE );
|
|---|
| 613 | }
|
|---|
| 614 | //******************************************************************************
|
|---|
| 615 | //******************************************************************************
|
|---|
| 616 | BOOL WIN32API GetTextExtentExPointW(HDC hdc,
|
|---|
| 617 | LPCWSTR str,
|
|---|
| 618 | int count,
|
|---|
| 619 | int maxExt,
|
|---|
| 620 | LPINT lpnFit,
|
|---|
| 621 | LPINT alpDx,
|
|---|
| 622 | LPSIZE size)
|
|---|
| 623 | {
|
|---|
| 624 | return InternalGetTextExtentExPointAW( hdc, ( PVOID )str, count, maxExt, lpnFit, alpDx, size, TRUE );
|
|---|
| 625 | }
|
|---|
| 626 | //******************************************************************************
|
|---|
| 627 | //******************************************************************************
|
|---|
| 628 | BOOL WIN32API GetCharWidth32A( HDC hdc, UINT iFirstChar, UINT iLastChar, PINT pWidthArray)
|
|---|
| 629 | {
|
|---|
| 630 | BOOL ret = FALSE;
|
|---|
| 631 |
|
|---|
| 632 | for (int i = iFirstChar; i <= iLastChar; i++)
|
|---|
| 633 | {
|
|---|
| 634 | SIZE size;
|
|---|
| 635 | CHAR c = i;
|
|---|
| 636 |
|
|---|
| 637 | if (GetTextExtentPointA(hdc, &c, 1, &size))
|
|---|
| 638 | {
|
|---|
| 639 | pWidthArray[i-iFirstChar] = size.cx;
|
|---|
| 640 | // at least one character was processed
|
|---|
| 641 | ret = TRUE;
|
|---|
| 642 | }
|
|---|
| 643 | else
|
|---|
| 644 | {
|
|---|
| 645 | // default value for unprocessed characters
|
|---|
| 646 | pWidthArray[i-iFirstChar] = 0;
|
|---|
| 647 | }
|
|---|
| 648 |
|
|---|
| 649 | dprintf2(("Char 0x%x('%c') -> width %d", i, i<256? i: '.', pWidthArray[i-iFirstChar]));
|
|---|
| 650 | }
|
|---|
| 651 |
|
|---|
| 652 | return ret;
|
|---|
| 653 | }
|
|---|
| 654 | //******************************************************************************
|
|---|
| 655 | //******************************************************************************
|
|---|
| 656 | BOOL WIN32API GetCharWidth32W(HDC hdc, UINT iFirstChar, UINT iLastChar, PINT pWidthArray)
|
|---|
| 657 | {
|
|---|
| 658 | BOOL ret = FALSE;
|
|---|
| 659 |
|
|---|
| 660 | for (int i = iFirstChar; i <= iLastChar; i++)
|
|---|
| 661 | {
|
|---|
| 662 | SIZE size;
|
|---|
| 663 | WCHAR wc = i;
|
|---|
| 664 |
|
|---|
| 665 | if (GetTextExtentPointW(hdc, &wc, 1, &size))
|
|---|
| 666 | {
|
|---|
| 667 | pWidthArray[i-iFirstChar] = size.cx;
|
|---|
| 668 | // at least one character was processed
|
|---|
| 669 | ret = TRUE;
|
|---|
| 670 | }
|
|---|
| 671 | else
|
|---|
| 672 | {
|
|---|
| 673 | // default value for unprocessed characters
|
|---|
| 674 | pWidthArray[i-iFirstChar] = 0;
|
|---|
| 675 | }
|
|---|
| 676 |
|
|---|
| 677 | dprintf2(("Char 0x%x('%c') -> width %d", i, i<256? i: '.', pWidthArray[i-iFirstChar]));
|
|---|
| 678 | }
|
|---|
| 679 |
|
|---|
| 680 | return ret;
|
|---|
| 681 | }
|
|---|
| 682 | //******************************************************************************
|
|---|
| 683 | // GetStringWidthW
|
|---|
| 684 | //
|
|---|
| 685 | // Return the width of each character in the string
|
|---|
| 686 | //
|
|---|
| 687 | // Parameters:
|
|---|
| 688 | // HDC hdc - device context handle
|
|---|
| 689 | // LPWSTR lpszString - unicod string pointer
|
|---|
| 690 | // UINT cbString - number of valid characters in string
|
|---|
| 691 | // PINT pWidthArray - array that receives the character width (must be
|
|---|
| 692 | // large enough to contain cbString elements
|
|---|
| 693 | //
|
|---|
| 694 | // Returns:
|
|---|
| 695 | // FALSE - failure
|
|---|
| 696 | // TRUE - success
|
|---|
| 697 | //
|
|---|
| 698 | //******************************************************************************
|
|---|
| 699 | BOOL WIN32API GetStringWidthW(HDC hdc, LPWSTR lpszString, UINT cbString, PINT pWidthArray)
|
|---|
| 700 | {
|
|---|
| 701 | return FT2Module.Ft2GetStringWidthW(hdc, lpszString, cbString, pWidthArray);
|
|---|
| 702 | }
|
|---|
| 703 | //******************************************************************************
|
|---|
| 704 | //******************************************************************************
|
|---|
| 705 | BOOL WIN32API GetCharWidthFloatA(HDC hdc, UINT iFirstChar, UINT iLastChar, PFLOAT pxBUffer)
|
|---|
| 706 | {
|
|---|
| 707 | dprintf(("ERROR: GDI32: GetCharWidthFloatA, not implemented\n"));
|
|---|
| 708 | DebugInt3();
|
|---|
| 709 | return(FALSE);
|
|---|
| 710 | }
|
|---|
| 711 | //******************************************************************************
|
|---|
| 712 | //******************************************************************************
|
|---|
| 713 | BOOL WIN32API GetCharWidthFloatW(HDC hdc, UINT iFirstChar, UINT iLastChar, PFLOAT pxBUffer)
|
|---|
| 714 | {
|
|---|
| 715 | dprintf(("ERROR: GDI32: GetCharWidthFloatW, not implemented\n"));
|
|---|
| 716 | DebugInt3();
|
|---|
| 717 | return(FALSE);
|
|---|
| 718 | }
|
|---|
| 719 | //******************************************************************************
|
|---|
| 720 | //******************************************************************************
|
|---|
| 721 | BOOL WIN32API GetCharABCWidthsA(HDC hdc, UINT firstChar, UINT lastChar, LPABC abc)
|
|---|
| 722 | {
|
|---|
| 723 | if(FT2Module.isEnabled() == FALSE)
|
|---|
| 724 | {//fallback method
|
|---|
| 725 | return O32_GetCharABCWidths(hdc, firstChar, lastChar, abc);
|
|---|
| 726 | }
|
|---|
| 727 |
|
|---|
| 728 | INT i, wlen, count = (INT)(lastChar - firstChar + 1);
|
|---|
| 729 | LPSTR str;
|
|---|
| 730 | LPWSTR wstr;
|
|---|
| 731 | BOOL ret = TRUE;
|
|---|
| 732 |
|
|---|
| 733 | if(count <= 0) {
|
|---|
| 734 | dprintf(("ERROR: Invalid parameter!!"));
|
|---|
| 735 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 736 | return FALSE;
|
|---|
| 737 | }
|
|---|
| 738 |
|
|---|
| 739 | str = (LPSTR)HeapAlloc(GetProcessHeap(), 0, count);
|
|---|
| 740 | for(i = 0; i < count; i++)
|
|---|
| 741 | str[i] = (BYTE)(firstChar + i);
|
|---|
| 742 |
|
|---|
| 743 | wstr = FONT_mbtowc(hdc, str, count, &wlen, NULL);
|
|---|
| 744 |
|
|---|
| 745 | for(i = 0; i < wlen; i++)
|
|---|
| 746 | {
|
|---|
| 747 | if(!GetCharABCWidthsW(hdc, wstr[i], wstr[i], abc))
|
|---|
| 748 | {
|
|---|
| 749 | ret = FALSE;
|
|---|
| 750 | break;
|
|---|
| 751 | }
|
|---|
| 752 | abc++;
|
|---|
| 753 | }
|
|---|
| 754 |
|
|---|
| 755 | HeapFree(GetProcessHeap(), 0, str);
|
|---|
| 756 | HeapFree(GetProcessHeap(), 0, wstr);
|
|---|
| 757 |
|
|---|
| 758 | return ret;
|
|---|
| 759 | }
|
|---|
| 760 | //******************************************************************************
|
|---|
| 761 | //******************************************************************************
|
|---|
| 762 | BOOL WIN32API GetCharABCWidthsW( HDC hdc, UINT firstChar, UINT lastChar, LPABC abc)
|
|---|
| 763 | {
|
|---|
| 764 | if(FT2Module.isEnabled() == FALSE)
|
|---|
| 765 | {//no fallback method (yet)
|
|---|
| 766 | DebugInt3();
|
|---|
| 767 | return FALSE;
|
|---|
| 768 | }
|
|---|
| 769 |
|
|---|
| 770 | int i;
|
|---|
| 771 | GLYPHMETRICS gm;
|
|---|
| 772 |
|
|---|
| 773 | for (i=firstChar;i<=lastChar;i++)
|
|---|
| 774 | {
|
|---|
| 775 | if(GetGlyphOutlineW(hdc, i, GGO_METRICS, &gm, 0, NULL, NULL) == GDI_ERROR)
|
|---|
| 776 | {
|
|---|
| 777 | dprintf(("ERROR: GetGlyphOutlineW failed!!"));
|
|---|
| 778 | return FALSE;
|
|---|
| 779 | }
|
|---|
| 780 | abc[i-firstChar].abcA = gm.gmptGlyphOrigin.x;
|
|---|
| 781 | abc[i-firstChar].abcB = gm.gmBlackBoxX;
|
|---|
| 782 | abc[i-firstChar].abcC = gm.gmCellIncX - gm.gmptGlyphOrigin.x - gm.gmBlackBoxX;
|
|---|
| 783 | dprintf2(("GetCharABCWidthsW %d (%d,%d,%d)", i, abc[i-firstChar].abcA, abc[i-firstChar].abcB, abc[i-firstChar].abcC));
|
|---|
| 784 | }
|
|---|
| 785 | return TRUE;
|
|---|
| 786 | }
|
|---|
| 787 | //******************************************************************************
|
|---|
| 788 | //******************************************************************************
|
|---|
| 789 | BOOL WIN32API GetCharABCWidthsFloatA(HDC hdc, UINT iFirstChar, UINT iLastChar, LPABCFLOAT pxBUffer)
|
|---|
| 790 | {
|
|---|
| 791 | dprintf(("ERROR: GDI32: GetCharABCWidthsFloatA, not implemented\n"));
|
|---|
| 792 | DebugInt3();
|
|---|
| 793 | return(FALSE);
|
|---|
| 794 | }
|
|---|
| 795 | //******************************************************************************
|
|---|
| 796 | //******************************************************************************
|
|---|
| 797 | BOOL WIN32API GetCharABCWidthsFloatW(HDC hdc,
|
|---|
| 798 | UINT iFirstChar,
|
|---|
| 799 | UINT iLastChar,
|
|---|
| 800 | LPABCFLOAT pxBUffer)
|
|---|
| 801 | {
|
|---|
| 802 | dprintf(("ERROR: GDI32: GetCharABCWidthsFloatA, not implemented\n"));
|
|---|
| 803 | DebugInt3();
|
|---|
| 804 | return(FALSE);
|
|---|
| 805 | }
|
|---|
| 806 | //******************************************************************************
|
|---|
| 807 | //******************************************************************************
|
|---|
| 808 |
|
|---|