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
Line 
1/* $Id: text.cpp,v 1.45 2004-05-07 10:27:50 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//******************************************************************************
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//******************************************************************************
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//******************************************************************************
96// todo: metafile support
97//#undef INVERT
98//#define INVERT_SETYINVERSION
99//******************************************************************************
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)
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 = &rect;
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
309 {
310 INT *lpDxNew = NULL;
311
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
338 if (lprc && ((align & 0x18) == TA_BASELINE))
339 OSLibGpiSetTextAlignment(pHps,pmHAlign,pmVAlign);
340
341 if(hits == GPIOS_ERROR) {
342 dprintf(("InternalTextOutA: OSLibGpiCharStringPosAt returned GPIOS_ERROR"));
343#ifdef INVERT_SETYINVERSION
344 GpiEnableYInversion(pHps->hps, oldyinv);
345#endif
346 return FALSE;
347 }
348
349 if (getAlignUpdateCP(pHps))
350 {
351 OSLibGpiQueryCurrentPosition(pHps,&ptl);
352 ptl.y -= getWorldYDeltaFor1Pixel(pHps);
353#ifndef INVERT
354 ptl.y += vertAdjust;
355#endif
356 OSLibGpiSetCurrentPosition(pHps,&ptl);
357 }
358
359#ifdef INVERT_SETYINVERSION
360 GpiEnableYInversion(pHps->hps, oldyinv);
361#endif
362
363 DIBSECTION_MARK_INVALID(hdc);
364
365 return TRUE;
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{
371 BOOL rc;
372 SIZE size;
373 int newy;
374
375 if(lprc)
376 {
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));
378 }
379 else dprintf(("GDI32: ExtTextOutA %x %.*s (%d,%d) %x %d %x", hdc, cbCount, lpszString, X, Y, fuOptions, cbCount, lpDx));
380
381 if(lpDx) {
382 for(int i=0;i<cbCount;i++) {
383 dprintf2(("Inc %d", lpDx[i]));
384 }
385 }
386
387 rc = InternalTextOutAW(hdc, X, Y, fuOptions, lprc, lpszString, NULL, cbCount, lpDx, TRUE, FALSE);
388
389 return(rc);
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{
395 if(lprc) {
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));
397 }
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);
401}
402//******************************************************************************
403//******************************************************************************
404BOOL WIN32API TextOutA(HDC hdc,int nXStart,int nYStart,LPCSTR lpszString,int cbString)
405{
406 dprintf(("GDI32: TextOutA %x (%d,%d) %d %.*s", hdc, nXStart, nYStart, cbString, cbString, lpszString));
407 return InternalTextOutAW(hdc,nXStart,nYStart,0,NULL,lpszString,NULL,cbString,NULL,FALSE, FALSE);
408}
409//******************************************************************************
410//******************************************************************************
411BOOL WIN32API TextOutW(HDC hdc,int nXStart,int nYStart,LPCWSTR lpszString,int cbString)
412{
413 dprintf(("GDI32: TextOutW %x (%d,%d) %d %.*ls", hdc, nXStart, nYStart, cbString, cbString, lpszString));
414 return InternalTextOutAW(hdc,nXStart,nYStart,0,NULL, NULL, lpszString,cbString,NULL,FALSE, TRUE);
415}
416//******************************************************************************
417//******************************************************************************
418BOOL WIN32API PolyTextOutA(HDC hdc,POLYTEXTA *pptxt,int cStrings)
419{
420 dprintf(("GDI32: PolyTextOutA %x %x %d", hdc, pptxt, cStrings));
421
422 for (INT x = 0;x < cStrings;x++)
423 {
424 BOOL rc;
425
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;
428 }
429
430 return TRUE;
431}
432//******************************************************************************
433//******************************************************************************
434BOOL WIN32API PolyTextOutW(HDC hdc,POLYTEXTW *pptxt,int cStrings)
435{
436 dprintf(("GDI32: PolyTextOutW %x %x %d", hdc, pptxt, cStrings));
437
438 for (INT x = 0;x < cStrings;x++)
439 {
440 BOOL rc;
441
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;
444 }
445
446 return TRUE;
447}
448//******************************************************************************
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//
453//******************************************************************************
454BOOL WIN32API GetTextExtentPointA(HDC hdc, LPCTSTR lpsz, int cbString,
455 LPSIZE lpsSize)
456{
457 BOOL ret = FALSE;
458 INT wlen;
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);
469 if (p) {
470 ret = GetTextExtentPointW( hdc, p, wlen, lpsSize );
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
483 HeapFree( GetProcessHeap(), 0, p );
484 }
485 else DebugInt3();
486 return ret;
487}
488//******************************************************************************
489//******************************************************************************
490BOOL WIN32API GetTextExtentPointW(HDC hdc,
491 LPCWSTR lpString,
492 int cbString,
493 PSIZE lpSize)
494{
495 BOOL rc;
496 POINTLOS2 widthHeight = { 0, 0};
497 pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
498
499 dprintf(("GDI32: GetTextExtentPointW %.*ls", cbString, lpString));
500 if(pHps == NULL)
501 {
502 SetLastError(ERROR_INVALID_HANDLE);
503 return FALSE;
504 }
505
506 if(lpString == NULL || cbString < 0 || lpSize == NULL)
507 {
508 SetLastError(ERROR_INVALID_PARAMETER);
509 return FALSE;
510 }
511
512 lpSize->cx = 0;
513 lpSize->cy = 0;
514
515 // Verified with NT4, SP6
516 if(cbString == 0)
517 {
518 dprintf(("!WARNING!: GDI32: GetTextExtentPointW invalid parameter!"));
519 SetLastError(ERROR_SUCCESS);
520 return TRUE;
521 }
522
523 if(pHps->isPrinter)
524 ReallySetCharAttrs(pHps);
525
526 if(cbString > 512)
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);
534 rc = GetTextExtentPointW(hdc, lpString, cbStringNew, &newSize);
535 if(rc == FALSE) {
536 return FALSE;
537 }
538 lpSize->cx += newSize.cx;
539 lpSize->cy = max(newSize.cy, lpSize->cy);
540 lpString += cbStringNew;
541 cbString -= cbStringNew;
542 }
543 return TRUE;
544 }
545
546 rc = FT2Module.Ft2GetTextExtentW(pHps->hps, cbString, lpString, &widthHeight);
547 if(rc == FALSE)
548 {
549 SetLastError(ERROR_INVALID_PARAMETER); //todo wrong error
550 return FALSE;
551 }
552 lpSize->cx = widthHeight.x;
553 lpSize->cy = widthHeight.y;
554
555 if(pHps && pHps->isPrinter && pHps->hdc)
556 {//scale for printer dcs
557 LONG alArray[2];
558
559 if(OSLibDevQueryCaps(pHps, OSLIB_CAPS_HORIZONTAL_RESOLUTION, 2, &alArray[0]))
560 lpSize->cx = lpSize->cx * alArray[0] / alArray[1];
561 }
562
563 dprintf(("GDI32: GetTextExtentPointW %x %ls %d returned %d (%d,%d)", hdc, lpString, cbString, rc, lpSize->cx, lpSize->cy));
564 SetLastError(ERROR_SUCCESS);
565 return TRUE;
566}
567//******************************************************************************
568//******************************************************************************
569BOOL WIN32API GetTextExtentPoint32A( HDC hdc, LPCSTR lpsz, int cbString, PSIZE lpSize)
570{
571 return GetTextExtentPointA(hdc, lpsz, cbString, lpSize);
572}
573//******************************************************************************
574//******************************************************************************
575BOOL WIN32API GetTextExtentPoint32W(HDC hdc, LPCWSTR lpsz, int cbString, PSIZE lpSize)
576{
577 return GetTextExtentPointW(hdc, lpsz, cbString, lpSize);
578}
579
580typedef BOOL ( WIN32API *PFN_GETTEXTEXTENTPOINT32 )( HDC, PVOID, INT, LPSIZE );
581
582BOOL InternalGetTextExtentExPointAW(HDC hdc,
583 PVOID str,
584 INT count,
585 INT maxExt,
586 LPINT lpnFit,
587 LPINT alpDx,
588 LPSIZE size,
589 BOOL fUnicode)
590{
591 int i, nFit;
592 SIZE tSize;
593 BOOL ret = FALSE;
594
595 PFN_GETTEXTEXTENTPOINT32 pfnGetTextExtentPoint32;
596
597 if( fUnicode )
598 pfnGetTextExtentPoint32 = ( PFN_GETTEXTEXTENTPOINT32 )GetTextExtentPoint32W;
599 else
600 pfnGetTextExtentPoint32 = ( PFN_GETTEXTEXTENTPOINT32 )GetTextExtentPoint32A;
601
602 size->cx = size->cy = nFit = i = 0;
603
604 if( lpnFit || alpDx )
605 {
606 for( i = 1; i <= count; i++ )
607 {
608 if( !pfnGetTextExtentPoint32( hdc, str, i, &tSize )) goto done;
609
610 if( lpnFit && ( maxExt < tSize.cx ))
611 break;
612
613 if( alpDx )
614 alpDx[ nFit ] = tSize.cx;
615
616 nFit++;
617 }
618 }
619
620 if(( count > 0 ) && ( i >= count ))
621 {
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;
626
627 if(lpnFit) *lpnFit = nFit;
628 ret = TRUE;
629
630 dprintf(("returning %d %ld x %ld\n",nFit,size->cx,size->cy));
631
632done:
633 return ret;
634}
635
636//******************************************************************************
637//******************************************************************************
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//******************************************************************************
650BOOL WIN32API GetTextExtentExPointW(HDC hdc,
651 LPCWSTR str,
652 int count,
653 int maxExt,
654 LPINT lpnFit,
655 LPINT alpDx,
656 LPSIZE size)
657{
658 return InternalGetTextExtentExPointAW( hdc, ( PVOID )str, count, maxExt, lpnFit, alpDx, size, TRUE );
659}
660//******************************************************************************
661//******************************************************************************
662BOOL WIN32API GetCharWidth32A( HDC hdc, UINT iFirstChar, UINT iLastChar, PINT pWidthArray)
663{
664 BOOL ret = FALSE;
665
666 for (int i = iFirstChar; i <= iLastChar; i++)
667 {
668 SIZE size;
669 CHAR c = i;
670
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 }
682
683 dprintf2(("Char 0x%x('%c') -> width %d", i, i<256? i: '.', pWidthArray[i-iFirstChar]));
684 }
685
686 return ret;
687}
688//******************************************************************************
689//******************************************************************************
690BOOL WIN32API GetCharWidth32W(HDC hdc, UINT iFirstChar, UINT iLastChar, PINT pWidthArray)
691{
692 BOOL ret = FALSE;
693
694 for (int i = iFirstChar; i <= iLastChar; i++)
695 {
696 SIZE size;
697 WCHAR wc = i;
698
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 }
710
711 dprintf2(("Char 0x%x('%c') -> width %d", i, i<256? i: '.', pWidthArray[i-iFirstChar]));
712 }
713
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
725// PINT pWidthArray - array that receives the character width (must be
726// large enough to contain cbString elements
727//
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{
757 if(FT2Module.isEnabled() == FALSE)
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++)
775 str[i] = (BYTE)(firstChar + i);
776
777 wstr = FONT_mbtowc(hdc, str, count, &wlen, NULL);
778
779 for(i = 0; i < wlen; i++)
780 {
781 if(!GetCharABCWidthsW(hdc, wstr[i], wstr[i], abc))
782 {
783 ret = FALSE;
784 break;
785 }
786 abc++;
787 }
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{
798 if(FT2Module.isEnabled() == FALSE)
799 {//no fallback method (yet)
800 DebugInt3();
801 return FALSE;
802 }
803
804 int i;
805 GLYPHMETRICS gm;
806
807 for (i=firstChar;i<=lastChar;i++)
808 {
809 if(GetGlyphOutlineW(hdc, i, GGO_METRICS, &gm, 0, NULL, NULL) == GDI_ERROR)
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//******************************************************************************
842
Note: See TracBrowser for help on using the repository browser.