source: trunk/src/gdi32/text.cpp

Last change on this file was 21997, checked in by dmik, 13 years ago

gdi32: Fix lost text in TextOut when used with non-identity trasformation matrix.

This was a regression of r21628 wchich I completely reverted. See #81 for details.

File size: 26.2 KB
RevLine 
[10600]1/* $Id: text.cpp,v 1.45 2004-05-07 10:27:50 sandervl Exp $ */
[1931]2
3/*
4 * GDI32 text apis
5 *
[10374]6 * Based on Wine/ReWind code (objects\text.c, objects\font.c)
[1931]7 *
8 * Copyright 1993, 1994 Alexandre Julliard
[10374]9 * 1997 Alex Korobka
10 *
[4012]11 * Copyright 1999-2000 Christoph Bratschi
[10374]12 * Copyright 2002-2003 Innotek Systemberatung GmbH (sandervl@innotek.de)
[1931]13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 */
17#include <os2win.h>
18#include <stdlib.h>
[7721]19#include <stdio.h>
[1931]20#include <misc.h>
21#include <string.h>
[2558]22#include <float.h>
[2049]23#include "oslibgpi.h"
[4602]24#include <dcdata.h>
[5472]25#include <unicode.h>
[10374]26#include "dibsect.h"
27#include "ft2supp.h"
[10349]28#include "font.h"
[10391]29#include <math.h>
[1931]30
[4012]31#define DBG_LOCALLOG DBG_text
[2802]32#include "dbglocal.h"
33
[2092]34#define ELLIPSIS "..."
35#define ELLIPSISLEN 3
36
[1931]37//******************************************************************************
38//******************************************************************************
[10391]39CHAR 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//******************************************************************************
[1931]54UINT 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 */
90UINT 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//******************************************************************************
[2049]96// todo: metafile support
[21997]97//#undef INVERT
98//#define INVERT_SETYINVERSION
[2049]99//******************************************************************************
[10374]100BOOL 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)
[2049]103{
[4602]104 pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);
[2049]105 ULONG flOptions = 0;
106 RECTLOS2 pmRect;
107 POINTLOS2 ptl;
108 LONG hits;
[10391]109 RECT rect;
[2049]110
[10374]111 if (!pHps || (cbCount < 0) || (((lpszStringA == NULL && !fUnicode) || (lpszStringW == NULL && fUnicode)) && (cbCount != 0)))
[1961]112 {
[4012]113 dprintf(("InternalTextOutA: invalid parameter"));
114 SetLastError(ERROR_INVALID_HANDLE);
115 return FALSE;
[1961]116 }
117
[10374]118 if(cbCount == -1) {
[10391]119 if(fUnicode)
[10374]120 cbCount = lstrlenW(lpszStringW);
121 else cbCount = lstrlenA(lpszStringA);
122 }
123
[2049]124 if (cbCount > 512)
125 {
[4012]126 dprintf(("InternalTextOutA: invalid parameter cbCount"));
127 SetLastError(ERROR_INVALID_PARAMETER);
128 return FALSE;
[2049]129 }
[10374]130 if (fuOptions & ~((UINT)(ETO_CLIPPED | ETO_OPAQUE | ETO_GLYPH_INDEX)))
[2049]131 {
[4012]132 dprintf(("InternalTextOutA: invalid fuOptions"));
133 //ETO_GLYPH_INDEX, ETO_RTLLEADING, ETO_NUMERICSLOCAL, ETO_NUMERICSLATIN, ETO_IGNORELANGUAGE, ETO_PDY are ignored
134 return TRUE;
[2049]135 }
[1961]136
[21997]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
[10391]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 = &rect;
168 fuOptions |= ETO_OPAQUE;
169 }
170
[2049]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 {
[4012]180 dprintf(("InternalTextOutA: excludeBottomRightPoint returned 0"));
[2049]181 return TRUE;
182 }
[21997]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
[2049]198
199 if (fuOptions & ETO_CLIPPED) flOptions |= CHSOS_CLIP;
200 if (fuOptions & ETO_OPAQUE) flOptions |= CHSOS_OPAQUE;
201 }
[4012]202 }
[3648]203 else
[2049]204 {
[10374]205 if (fuOptions & ~ETO_GLYPH_INDEX)
[2049]206 {
[10374]207 dprintf(("InternalTextOutA: ERROR_INVALID_PARAMETER"));
208 SetLastError(ERROR_INVALID_PARAMETER);
[4012]209 return FALSE;
[2049]210 }
211 }
212
[10374]213 if((lpszStringA || lpszStringW) && cbCount) {
214 DIBSECTION_CHECK_IF_DIRTY(hdc);
215 }
216
[2049]217 if (cbCount == 0)
218 {
219 if (fuOptions & ETO_OPAQUE)
220 {
[5868]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
[4012]224 lpszString = " ";
225 cbCount = 1;
226 flOptions |= CHSOS_CLIP;
[5868]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);
[6384]234 DeleteObject(hbrush);
[10374]235
236 DIBSECTION_MARK_INVALID(hdc);
237
[5868]238 return TRUE;
239#endif
[4012]240 }
[3648]241 else {
[4012]242 dprintf(("InternalTextOutA: cbCount == 0"));
243 return TRUE;
[3648]244 }
[2049]245 }
[9737]246
[21997]247#ifdef INVERT_SETYINVERSION
248 GpiEnableYInversion(pHps->hps, 0);
249#endif
250
[2049]251 if (lpDx)
252 flOptions |= CHSOS_VECTOR;
253
[2092]254 if (!getAlignUpdateCP(pHps))
[2049]255 {
256 ptl.x = X;
257 ptl.y = Y;
258
259 flOptions |= CHSOS_LEAVEPOS;
[4012]260 }
[3648]261 else OSLibGpiQueryCurrentPosition(pHps,&ptl);
[2049]262
263 UINT align = GetTextAlign(hdc);
264 LONG pmHAlign,pmVAlign;
265
[9609]266#if 0
267 //SvL: This code is broken. TODO: Investigate
[2092]268 //CB: TA_RIGHT not supported by PM, only TA_CENTER and TA_LEFT
[2049]269 if ((align & 0x6) == TA_RIGHT)
270 {
[9609]271 BOOL rc;
[2049]272 PPOINTLOS2 pts = (PPOINTLOS2)malloc((cbCount+1)*sizeof(POINTLOS2));
[10163]273
[9609]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 }
[2049]281 free(pts);
282 }
[9609]283#endif
[2049]284
[2221]285 if (lprc && ((align & 0x18) == TA_BASELINE))
[2049]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
[9737]293#ifdef INVERT
[2049]294 ptl.y += getWorldYDeltaFor1Pixel(pHps);
[9737]295#else
296 ptl.y -= getWorldYDeltaFor1Pixel(pHps);
[2049]297
[4602]298 int vertAdjust = 0;
[10163]299 if ((pHps->taMode & 0x18) != TA_TOP)
[4602]300 {
301 vertAdjust = OSLibGpiQueryFontMaxHeight(pHps->hps);
302 }
303 ptl.y -= vertAdjust;
304#endif
305
[10391]306 if(fUnicode)
[10374]307 hits = FT2Module.Ft2CharStringPosAtW(pHps->hps,&ptl,&pmRect,flOptions,cbCount,lpszStringW,lpDx, fuOptions & ETO_GLYPH_INDEX);
[10600]308 else
309 {
310 INT *lpDxNew = NULL;
[2049]311
[10600]312 // KOMH : OS/2 uses width of lead byte for whole DBCS width and is not concerned about
313 // trail byte, while Win can apportion width between lead byte and trail byte
314 if( IsDBCSEnv() && lpDx )
315 {
316 int i;
317
318 lpDxNew = ( INT * )malloc(( cbCount + 1 ) * sizeof( INT )); // 1 for broken DBCS char
319 for( i = 0; i < cbCount; i++ )
320 {
321 lpDxNew[ i ] = lpDx[ i ];
322 if( IsDBCSLeadByte( lpszStringA[ i ] ))
323 {
324 lpDxNew[ i ] += lpDx[ i + 1 ];
325 lpDxNew[ ++i ] = 0; // for the sake of possibility
326 }
327 }
328
329 lpDx = lpDxNew;
330 }
331
332 hits = FT2Module.Ft2CharStringPosAtA(pHps->hps,&ptl,&pmRect,flOptions,cbCount,lpszStringA,lpDx, fuOptions & ETO_GLYPH_INDEX);
333
334 if( lpDxNew )
335 free( lpDxNew );
336 }
337
[2221]338 if (lprc && ((align & 0x18) == TA_BASELINE))
[10374]339 OSLibGpiSetTextAlignment(pHps,pmHAlign,pmVAlign);
[2049]340
[3648]341 if(hits == GPIOS_ERROR) {
[10374]342 dprintf(("InternalTextOutA: OSLibGpiCharStringPosAt returned GPIOS_ERROR"));
[21997]343#ifdef INVERT_SETYINVERSION
344 GpiEnableYInversion(pHps->hps, oldyinv);
345#endif
[10374]346 return FALSE;
[3648]347 }
[2092]348
[2049]349 if (getAlignUpdateCP(pHps))
350 {
[10374]351 OSLibGpiQueryCurrentPosition(pHps,&ptl);
352 ptl.y -= getWorldYDeltaFor1Pixel(pHps);
[4602]353#ifndef INVERT
[10374]354 ptl.y += vertAdjust;
[4602]355#endif
[10374]356 OSLibGpiSetCurrentPosition(pHps,&ptl);
[2049]357 }
358
[21997]359#ifdef INVERT_SETYINVERSION
360 GpiEnableYInversion(pHps->hps, oldyinv);
361#endif
362
[10374]363 DIBSECTION_MARK_INVALID(hdc);
[10163]364
[10374]365 return TRUE;
[1961]366}
367//******************************************************************************
368//******************************************************************************
369BOOL WIN32API ExtTextOutA(HDC hdc,int X,int Y,UINT fuOptions,CONST RECT *lprc,LPCSTR lpszString,UINT cbCount,CONST INT *lpDx)
370{
[9886]371 BOOL rc;
[10374]372 SIZE size;
373 int newy;
[9886]374
375 if(lprc)
376 {
[10374]377 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));
[9886]378 }
[10374]379 else dprintf(("GDI32: ExtTextOutA %x %.*s (%d,%d) %x %d %x", hdc, cbCount, lpszString, X, Y, fuOptions, cbCount, lpDx));
[5511]380
[10594]381 if(lpDx) {
382 for(int i=0;i<cbCount;i++) {
383 dprintf2(("Inc %d", lpDx[i]));
384 }
385 }
[10600]386
[10374]387 rc = InternalTextOutAW(hdc, X, Y, fuOptions, lprc, lpszString, NULL, cbCount, lpDx, TRUE, FALSE);
[9886]388
389 return(rc);
[1961]390}
391//******************************************************************************
392//******************************************************************************
393BOOL WIN32API ExtTextOutW(HDC hdc,int X,int Y,UINT fuOptions,CONST RECT *lprc,LPCWSTR lpszString,UINT cbCount,CONST int *lpDx)
394{
[5511]395 if(lprc) {
[10374]396 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));
[5511]397 }
[10374]398 else dprintf(("GDI32: ExtTextOutW %x %.*ls (%d,%d) %x %d %x", hdc, cbCount, lpszString, X, Y, fuOptions, cbCount, lpDx));
399
400 return InternalTextOutAW(hdc, X, Y, fuOptions, lprc, NULL, lpszString, cbCount, lpDx, TRUE, TRUE);
[1961]401}
402//******************************************************************************
403//******************************************************************************
404BOOL WIN32API TextOutA(HDC hdc,int nXStart,int nYStart,LPCSTR lpszString,int cbString)
405{
[8760]406 dprintf(("GDI32: TextOutA %x (%d,%d) %d %.*s", hdc, nXStart, nYStart, cbString, cbString, lpszString));
[10374]407 return InternalTextOutAW(hdc,nXStart,nYStart,0,NULL,lpszString,NULL,cbString,NULL,FALSE, FALSE);
[1961]408}
409//******************************************************************************
410//******************************************************************************
411BOOL WIN32API TextOutW(HDC hdc,int nXStart,int nYStart,LPCWSTR lpszString,int cbString)
412{
[8760]413 dprintf(("GDI32: TextOutW %x (%d,%d) %d %.*ls", hdc, nXStart, nYStart, cbString, cbString, lpszString));
[10374]414 return InternalTextOutAW(hdc,nXStart,nYStart,0,NULL, NULL, lpszString,cbString,NULL,FALSE, TRUE);
[1961]415}
416//******************************************************************************
417//******************************************************************************
[2092]418BOOL WIN32API PolyTextOutA(HDC hdc,POLYTEXTA *pptxt,int cStrings)
419{
[7682]420 dprintf(("GDI32: PolyTextOutA %x %x %d", hdc, pptxt, cStrings));
[2092]421
422 for (INT x = 0;x < cStrings;x++)
423 {
[10374]424 BOOL rc;
[2092]425
[10374]426 rc = ExtTextOutA(hdc,pptxt[x].x,pptxt[x].y,pptxt[x].uiFlags,&pptxt[x].rcl,pptxt[x].lpstr, pptxt[x].n,pptxt[x].pdx);
427 if (!rc) return FALSE;
[2092]428 }
429
430 return TRUE;
431}
432//******************************************************************************
433//******************************************************************************
434BOOL WIN32API PolyTextOutW(HDC hdc,POLYTEXTW *pptxt,int cStrings)
435{
[7682]436 dprintf(("GDI32: PolyTextOutW %x %x %d", hdc, pptxt, cStrings));
[2092]437
438 for (INT x = 0;x < cStrings;x++)
439 {
[10374]440 BOOL rc;
[2092]441
[10374]442 rc = ExtTextOutW(hdc,pptxt[x].x,pptxt[x].y,pptxt[x].uiFlags,&pptxt[x].rcl, pptxt[x].lpstr,pptxt[x].n,pptxt[x].pdx);
443 if (!rc) return FALSE;
[2092]444 }
445
446 return TRUE;
447}
[4602]448//******************************************************************************
[10374]449// Note: GetTextExtentPoint behaves differently under certain circumstances
450// compared to GetTextExtentPoint32 (due to bugs).
451// We are treating both as the same thing which is not entirely correct.
452//
[4602]453//******************************************************************************
454BOOL WIN32API GetTextExtentPointA(HDC hdc, LPCTSTR lpsz, int cbString,
455 LPSIZE lpsSize)
456{
[10349]457 BOOL ret = FALSE;
458 INT wlen;
[10391]459 LPWSTR p;
460 CHAR brokenDBCS = 0;
461
462 if( IsDBCSEnv())
463 brokenDBCS = getBrokenDBCS( lpsz, cbString );
464
465 if( brokenDBCS )
466 cbString--;
467
468 p = FONT_mbtowc(hdc, lpsz, cbString, &wlen, NULL);
[10349]469 if (p) {
470 ret = GetTextExtentPointW( hdc, p, wlen, lpsSize );
[10391]471 // For broken DBCS. Correct for FIXED WIDTH, but approx. for VARIABLE WIDTH
472 if( brokenDBCS )
473 {
474 TEXTMETRICA tmA;
475
476 GetTextMetricsA( hdc, &tmA );
477 lpsSize->cx += tmA.tmAveCharWidth;
478
479 if( cbString == 0 )
480 lpsSize->cy = tmA.tmHeight;
481 }
482
[10349]483 HeapFree( GetProcessHeap(), 0, p );
[7721]484 }
[10349]485 else DebugInt3();
486 return ret;
487}
488//******************************************************************************
489//******************************************************************************
490BOOL WIN32API GetTextExtentPointW(HDC hdc,
491 LPCWSTR lpString,
492 int cbString,
493 PSIZE lpSize)
494{
[4602]495 BOOL rc;
496 POINTLOS2 widthHeight = { 0, 0};
497 pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
498
[10392]499 dprintf(("GDI32: GetTextExtentPointW %.*ls", cbString, lpString));
[4602]500 if(pHps == NULL)
501 {
502 SetLastError(ERROR_INVALID_HANDLE);
503 return FALSE;
504 }
505
[10349]506 if(lpString == NULL || cbString < 0 || lpSize == NULL)
[4602]507 {
508 SetLastError(ERROR_INVALID_PARAMETER);
509 return FALSE;
510 }
511
[10349]512 lpSize->cx = 0;
513 lpSize->cy = 0;
[4602]514
515 // Verified with NT4, SP6
516 if(cbString == 0)
517 {
[10374]518 dprintf(("!WARNING!: GDI32: GetTextExtentPointW invalid parameter!"));
[4602]519 SetLastError(ERROR_SUCCESS);
520 return TRUE;
521 }
[10374]522
523 if(pHps->isPrinter)
524 ReallySetCharAttrs(pHps);
525
[10163]526 if(cbString > 512)
[5755]527 {
528 DWORD cbStringNew;
529 SIZE newSize;
530
531 dprintf(("WARNING: string longer than 512 chars; splitting up"));
532 while(cbString) {
533 cbStringNew = min(500, cbString);
[10349]534 rc = GetTextExtentPointW(hdc, lpString, cbStringNew, &newSize);
[5755]535 if(rc == FALSE) {
536 return FALSE;
537 }
[10349]538 lpSize->cx += newSize.cx;
539 lpSize->cy = max(newSize.cy, lpSize->cy);
[10374]540 lpString += cbStringNew;
[5755]541 cbString -= cbStringNew;
542 }
543 return TRUE;
[4602]544 }
545
[10391]546 rc = FT2Module.Ft2GetTextExtentW(pHps->hps, cbString, lpString, &widthHeight);
[4602]547 if(rc == FALSE)
548 {
[10163]549 SetLastError(ERROR_INVALID_PARAMETER); //todo wrong error
[4602]550 return FALSE;
551 }
[10349]552 lpSize->cx = widthHeight.x;
553 lpSize->cy = widthHeight.y;
[4602]554
555 if(pHps && pHps->isPrinter && pHps->hdc)
556 {//scale for printer dcs
557 LONG alArray[2];
558
[10374]559 if(OSLibDevQueryCaps(pHps, OSLIB_CAPS_HORIZONTAL_RESOLUTION, 2, &alArray[0]))
560 lpSize->cx = lpSize->cx * alArray[0] / alArray[1];
[4602]561 }
562
[10365]563 dprintf(("GDI32: GetTextExtentPointW %x %ls %d returned %d (%d,%d)", hdc, lpString, cbString, rc, lpSize->cx, lpSize->cy));
[4602]564 SetLastError(ERROR_SUCCESS);
565 return TRUE;
566}
567//******************************************************************************
568//******************************************************************************
569BOOL WIN32API GetTextExtentPoint32A( HDC hdc, LPCSTR lpsz, int cbString, PSIZE lpSize)
570{
[7721]571 return GetTextExtentPointA(hdc, lpsz, cbString, lpSize);
[4602]572}
573//******************************************************************************
574//******************************************************************************
[7721]575BOOL WIN32API GetTextExtentPoint32W(HDC hdc, LPCWSTR lpsz, int cbString, PSIZE lpSize)
[4602]576{
[7721]577 return GetTextExtentPointW(hdc, lpsz, cbString, lpSize);
[4602]578}
[10400]579
580typedef BOOL ( WIN32API *PFN_GETTEXTEXTENTPOINT32 )( HDC, PVOID, INT, LPSIZE );
581
582BOOL InternalGetTextExtentExPointAW(HDC hdc,
583 PVOID str,
584 INT count,
585 INT maxExt,
[10349]586 LPINT lpnFit,
587 LPINT alpDx,
[10400]588 LPSIZE size,
589 BOOL fUnicode)
[10349]590{
[10400]591 int i, nFit;
592 SIZE tSize;
593 BOOL ret = FALSE;
[10391]594
[10400]595 PFN_GETTEXTEXTENTPOINT32 pfnGetTextExtentPoint32;
[10391]596
[10400]597 if( fUnicode )
598 pfnGetTextExtentPoint32 = ( PFN_GETTEXTEXTENTPOINT32 )GetTextExtentPoint32W;
599 else
600 pfnGetTextExtentPoint32 = ( PFN_GETTEXTEXTENTPOINT32 )GetTextExtentPoint32A;
[10391]601
[10400]602 size->cx = size->cy = nFit = i = 0;
[10391]603
[10400]604 if( lpnFit || alpDx )
[10391]605 {
[10400]606 for( i = 1; i <= count; i++ )
[10365]607 {
[10400]608 if( !pfnGetTextExtentPoint32( hdc, str, i, &tSize )) goto done;
[10365]609
[10400]610 if( lpnFit && ( maxExt < tSize.cx ))
611 break;
[10365]612
[10400]613 if( alpDx )
614 alpDx[ nFit ] = tSize.cx;
[10365]615
[10400]616 nFit++;
617 }
[10365]618 }
[10391]619
[10400]620 if(( count > 0 ) && ( i >= count ))
[10391]621 {
[10400]622 size->cx = tSize.cx;
623 size->cy = tSize.cy; // The height of a font is constant.
624 }
625 else if( !pfnGetTextExtentPoint32( hdc, str, count, size )) goto done;
[10391]626
[10400]627 if(lpnFit) *lpnFit = nFit;
628 ret = TRUE;
[10391]629
[10400]630 dprintf(("returning %d %ld x %ld\n",nFit,size->cx,size->cy));
[10391]631
[10400]632done:
[10349]633 return ret;
634}
[10400]635
[10349]636//******************************************************************************
637//******************************************************************************
[10400]638BOOL WIN32API GetTextExtentExPointA(HDC hdc,
639 LPCSTR str,
640 int count,
641 int maxExt,
642 LPINT lpnFit,
643 LPINT alpDx,
644 LPSIZE size)
645{
646 return InternalGetTextExtentExPointAW( hdc, ( PVOID )str, count, maxExt, lpnFit, alpDx, size, FALSE );
647}
648//******************************************************************************
649//******************************************************************************
[10349]650BOOL WIN32API GetTextExtentExPointW(HDC hdc,
651 LPCWSTR str,
652 int count,
653 int maxExt,
654 LPINT lpnFit,
655 LPINT alpDx,
656 LPSIZE size)
657{
[10400]658 return InternalGetTextExtentExPointAW( hdc, ( PVOID )str, count, maxExt, lpnFit, alpDx, size, TRUE );
[10349]659}
660//******************************************************************************
661//******************************************************************************
[10374]662BOOL WIN32API GetCharWidth32A( HDC hdc, UINT iFirstChar, UINT iLastChar, PINT pWidthArray)
663{
664 BOOL ret = FALSE;
[10391]665
[10374]666 for (int i = iFirstChar; i <= iLastChar; i++)
667 {
668 SIZE size;
669 CHAR c = i;
[10391]670
[10374]671 if (GetTextExtentPointA(hdc, &c, 1, &size))
672 {
673 pWidthArray[i-iFirstChar] = size.cx;
674 // at least one character was processed
675 ret = TRUE;
676 }
677 else
678 {
679 // default value for unprocessed characters
680 pWidthArray[i-iFirstChar] = 0;
681 }
[10391]682
[10374]683 dprintf2(("Char 0x%x('%c') -> width %d", i, i<256? i: '.', pWidthArray[i-iFirstChar]));
684 }
[10391]685
[10374]686 return ret;
687}
688//******************************************************************************
689//******************************************************************************
690BOOL WIN32API GetCharWidth32W(HDC hdc, UINT iFirstChar, UINT iLastChar, PINT pWidthArray)
691{
692 BOOL ret = FALSE;
[10391]693
[10374]694 for (int i = iFirstChar; i <= iLastChar; i++)
695 {
696 SIZE size;
697 WCHAR wc = i;
[10391]698
[10374]699 if (GetTextExtentPointW(hdc, &wc, 1, &size))
700 {
701 pWidthArray[i-iFirstChar] = size.cx;
702 // at least one character was processed
703 ret = TRUE;
704 }
705 else
706 {
707 // default value for unprocessed characters
708 pWidthArray[i-iFirstChar] = 0;
709 }
[10391]710
[10374]711 dprintf2(("Char 0x%x('%c') -> width %d", i, i<256? i: '.', pWidthArray[i-iFirstChar]));
712 }
[10391]713
[10374]714 return ret;
715}
716//******************************************************************************
717// GetStringWidthW
718//
719// Return the width of each character in the string
720//
721// Parameters:
722// HDC hdc - device context handle
723// LPWSTR lpszString - unicod string pointer
724// UINT cbString - number of valid characters in string
[10391]725// PINT pWidthArray - array that receives the character width (must be
[10374]726// large enough to contain cbString elements
[10391]727//
[10374]728// Returns:
729// FALSE - failure
730// TRUE - success
731//
732//******************************************************************************
733BOOL WIN32API GetStringWidthW(HDC hdc, LPWSTR lpszString, UINT cbString, PINT pWidthArray)
734{
735 return FT2Module.Ft2GetStringWidthW(hdc, lpszString, cbString, pWidthArray);
736}
737//******************************************************************************
738//******************************************************************************
739BOOL WIN32API GetCharWidthFloatA(HDC hdc, UINT iFirstChar, UINT iLastChar, PFLOAT pxBUffer)
740{
741 dprintf(("ERROR: GDI32: GetCharWidthFloatA, not implemented\n"));
742 DebugInt3();
743 return(FALSE);
744}
745//******************************************************************************
746//******************************************************************************
747BOOL WIN32API GetCharWidthFloatW(HDC hdc, UINT iFirstChar, UINT iLastChar, PFLOAT pxBUffer)
748{
749 dprintf(("ERROR: GDI32: GetCharWidthFloatW, not implemented\n"));
750 DebugInt3();
751 return(FALSE);
752}
753//******************************************************************************
754//******************************************************************************
755BOOL WIN32API GetCharABCWidthsA(HDC hdc, UINT firstChar, UINT lastChar, LPABC abc)
756{
[10391]757 if(FT2Module.isEnabled() == FALSE)
[10374]758 {//fallback method
759 return O32_GetCharABCWidths(hdc, firstChar, lastChar, abc);
760 }
761
762 INT i, wlen, count = (INT)(lastChar - firstChar + 1);
763 LPSTR str;
764 LPWSTR wstr;
765 BOOL ret = TRUE;
766
767 if(count <= 0) {
768 dprintf(("ERROR: Invalid parameter!!"));
769 SetLastError(ERROR_INVALID_PARAMETER);
770 return FALSE;
771 }
772
773 str = (LPSTR)HeapAlloc(GetProcessHeap(), 0, count);
774 for(i = 0; i < count; i++)
[10391]775 str[i] = (BYTE)(firstChar + i);
[10374]776
777 wstr = FONT_mbtowc(hdc, str, count, &wlen, NULL);
778
779 for(i = 0; i < wlen; i++)
780 {
[10391]781 if(!GetCharABCWidthsW(hdc, wstr[i], wstr[i], abc))
782 {
783 ret = FALSE;
784 break;
[10374]785 }
[10391]786 abc++;
787 }
[10374]788
789 HeapFree(GetProcessHeap(), 0, str);
790 HeapFree(GetProcessHeap(), 0, wstr);
791
792 return ret;
793}
794//******************************************************************************
795//******************************************************************************
796BOOL WIN32API GetCharABCWidthsW( HDC hdc, UINT firstChar, UINT lastChar, LPABC abc)
797{
[10391]798 if(FT2Module.isEnabled() == FALSE)
[10374]799 {//no fallback method (yet)
800 DebugInt3();
801 return FALSE;
802 }
803
804 int i;
805 GLYPHMETRICS gm;
806
[10391]807 for (i=firstChar;i<=lastChar;i++)
[10374]808 {
[10391]809 if(GetGlyphOutlineW(hdc, i, GGO_METRICS, &gm, 0, NULL, NULL) == GDI_ERROR)
[10374]810 {
811 dprintf(("ERROR: GetGlyphOutlineW failed!!"));
812 return FALSE;
813 }
814 abc[i-firstChar].abcA = gm.gmptGlyphOrigin.x;
815 abc[i-firstChar].abcB = gm.gmBlackBoxX;
816 abc[i-firstChar].abcC = gm.gmCellIncX - gm.gmptGlyphOrigin.x - gm.gmBlackBoxX;
817 dprintf2(("GetCharABCWidthsW %d (%d,%d,%d)", i, abc[i-firstChar].abcA, abc[i-firstChar].abcB, abc[i-firstChar].abcC));
818 }
819 return TRUE;
820}
821//******************************************************************************
822//******************************************************************************
823BOOL WIN32API GetCharABCWidthsFloatA(HDC hdc, UINT iFirstChar, UINT iLastChar, LPABCFLOAT pxBUffer)
824{
825 dprintf(("ERROR: GDI32: GetCharABCWidthsFloatA, not implemented\n"));
826 DebugInt3();
827 return(FALSE);
828}
829//******************************************************************************
830//******************************************************************************
831BOOL WIN32API GetCharABCWidthsFloatW(HDC hdc,
832 UINT iFirstChar,
833 UINT iLastChar,
834 LPABCFLOAT pxBUffer)
835{
836 dprintf(("ERROR: GDI32: GetCharABCWidthsFloatA, not implemented\n"));
837 DebugInt3();
838 return(FALSE);
839}
840//******************************************************************************
841//******************************************************************************
[10391]842
Note: See TracBrowser for help on using the repository browser.