source: trunk/src/gdi32/text.cpp@ 10594

Last change on this file since 10594 was 10594, checked in by sandervl, 21 years ago

drawSingleLinePoint: wrong pen style checks; logging updates

File size: 25.4 KB
Line 
1/* $Id: text.cpp,v 1.44 2004-04-30 13:27:19 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 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//******************************************************************************
341BOOL 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 if(lpDx) {
354 for(int i=0;i<cbCount;i++) {
355 dprintf2(("Inc %d", lpDx[i]));
356 }
357 }
358 rc = InternalTextOutAW(hdc, X, Y, fuOptions, lprc, lpszString, NULL, cbCount, lpDx, TRUE, FALSE);
359
360 return(rc);
361}
362//******************************************************************************
363//******************************************************************************
364BOOL WIN32API ExtTextOutW(HDC hdc,int X,int Y,UINT fuOptions,CONST RECT *lprc,LPCWSTR lpszString,UINT cbCount,CONST int *lpDx)
365{
366 if(lprc) {
367 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));
368 }
369 else dprintf(("GDI32: ExtTextOutW %x %.*ls (%d,%d) %x %d %x", hdc, cbCount, lpszString, X, Y, fuOptions, cbCount, lpDx));
370
371 return InternalTextOutAW(hdc, X, Y, fuOptions, lprc, NULL, lpszString, cbCount, lpDx, TRUE, TRUE);
372}
373//******************************************************************************
374//******************************************************************************
375BOOL WIN32API TextOutA(HDC hdc,int nXStart,int nYStart,LPCSTR lpszString,int cbString)
376{
377 dprintf(("GDI32: TextOutA %x (%d,%d) %d %.*s", hdc, nXStart, nYStart, cbString, cbString, lpszString));
378 return InternalTextOutAW(hdc,nXStart,nYStart,0,NULL,lpszString,NULL,cbString,NULL,FALSE, FALSE);
379}
380//******************************************************************************
381//******************************************************************************
382BOOL WIN32API TextOutW(HDC hdc,int nXStart,int nYStart,LPCWSTR lpszString,int cbString)
383{
384 dprintf(("GDI32: TextOutW %x (%d,%d) %d %.*ls", hdc, nXStart, nYStart, cbString, cbString, lpszString));
385 return InternalTextOutAW(hdc,nXStart,nYStart,0,NULL, NULL, lpszString,cbString,NULL,FALSE, TRUE);
386}
387//******************************************************************************
388//******************************************************************************
389BOOL WIN32API PolyTextOutA(HDC hdc,POLYTEXTA *pptxt,int cStrings)
390{
391 dprintf(("GDI32: PolyTextOutA %x %x %d", hdc, pptxt, cStrings));
392
393 for (INT x = 0;x < cStrings;x++)
394 {
395 BOOL rc;
396
397 rc = ExtTextOutA(hdc,pptxt[x].x,pptxt[x].y,pptxt[x].uiFlags,&pptxt[x].rcl,pptxt[x].lpstr, pptxt[x].n,pptxt[x].pdx);
398 if (!rc) return FALSE;
399 }
400
401 return TRUE;
402}
403//******************************************************************************
404//******************************************************************************
405BOOL WIN32API PolyTextOutW(HDC hdc,POLYTEXTW *pptxt,int cStrings)
406{
407 dprintf(("GDI32: PolyTextOutW %x %x %d", hdc, pptxt, cStrings));
408
409 for (INT x = 0;x < cStrings;x++)
410 {
411 BOOL rc;
412
413 rc = ExtTextOutW(hdc,pptxt[x].x,pptxt[x].y,pptxt[x].uiFlags,&pptxt[x].rcl, pptxt[x].lpstr,pptxt[x].n,pptxt[x].pdx);
414 if (!rc) return FALSE;
415 }
416
417 return TRUE;
418}
419//******************************************************************************
420// Note: GetTextExtentPoint behaves differently under certain circumstances
421// compared to GetTextExtentPoint32 (due to bugs).
422// We are treating both as the same thing which is not entirely correct.
423//
424//******************************************************************************
425BOOL WIN32API GetTextExtentPointA(HDC hdc, LPCTSTR lpsz, int cbString,
426 LPSIZE lpsSize)
427{
428 BOOL ret = FALSE;
429 INT wlen;
430 LPWSTR p;
431 CHAR brokenDBCS = 0;
432
433 if( IsDBCSEnv())
434 brokenDBCS = getBrokenDBCS( lpsz, cbString );
435
436 if( brokenDBCS )
437 cbString--;
438
439 p = FONT_mbtowc(hdc, lpsz, cbString, &wlen, NULL);
440 if (p) {
441 ret = GetTextExtentPointW( hdc, p, wlen, lpsSize );
442 // For broken DBCS. Correct for FIXED WIDTH, but approx. for VARIABLE WIDTH
443 if( brokenDBCS )
444 {
445 TEXTMETRICA tmA;
446
447 GetTextMetricsA( hdc, &tmA );
448 lpsSize->cx += tmA.tmAveCharWidth;
449
450 if( cbString == 0 )
451 lpsSize->cy = tmA.tmHeight;
452 }
453
454 HeapFree( GetProcessHeap(), 0, p );
455 }
456 else DebugInt3();
457 return ret;
458}
459//******************************************************************************
460//******************************************************************************
461BOOL WIN32API GetTextExtentPointW(HDC hdc,
462 LPCWSTR lpString,
463 int cbString,
464 PSIZE lpSize)
465{
466 BOOL rc;
467 POINTLOS2 widthHeight = { 0, 0};
468 pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
469
470 dprintf(("GDI32: GetTextExtentPointW %.*ls", cbString, lpString));
471 if(pHps == NULL)
472 {
473 SetLastError(ERROR_INVALID_HANDLE);
474 return FALSE;
475 }
476
477 if(lpString == NULL || cbString < 0 || lpSize == NULL)
478 {
479 SetLastError(ERROR_INVALID_PARAMETER);
480 return FALSE;
481 }
482
483 lpSize->cx = 0;
484 lpSize->cy = 0;
485
486 // Verified with NT4, SP6
487 if(cbString == 0)
488 {
489 dprintf(("!WARNING!: GDI32: GetTextExtentPointW invalid parameter!"));
490 SetLastError(ERROR_SUCCESS);
491 return TRUE;
492 }
493
494 if(pHps->isPrinter)
495 ReallySetCharAttrs(pHps);
496
497 if(cbString > 512)
498 {
499 DWORD cbStringNew;
500 SIZE newSize;
501
502 dprintf(("WARNING: string longer than 512 chars; splitting up"));
503 while(cbString) {
504 cbStringNew = min(500, cbString);
505 rc = GetTextExtentPointW(hdc, lpString, cbStringNew, &newSize);
506 if(rc == FALSE) {
507 return FALSE;
508 }
509 lpSize->cx += newSize.cx;
510 lpSize->cy = max(newSize.cy, lpSize->cy);
511 lpString += cbStringNew;
512 cbString -= cbStringNew;
513 }
514 return TRUE;
515 }
516
517 rc = FT2Module.Ft2GetTextExtentW(pHps->hps, cbString, lpString, &widthHeight);
518 if(rc == FALSE)
519 {
520 SetLastError(ERROR_INVALID_PARAMETER); //todo wrong error
521 return FALSE;
522 }
523 lpSize->cx = widthHeight.x;
524 lpSize->cy = widthHeight.y;
525
526 if(pHps && pHps->isPrinter && pHps->hdc)
527 {//scale for printer dcs
528 LONG alArray[2];
529
530 if(OSLibDevQueryCaps(pHps, OSLIB_CAPS_HORIZONTAL_RESOLUTION, 2, &alArray[0]))
531 lpSize->cx = lpSize->cx * alArray[0] / alArray[1];
532 }
533
534 dprintf(("GDI32: GetTextExtentPointW %x %ls %d returned %d (%d,%d)", hdc, lpString, cbString, rc, lpSize->cx, lpSize->cy));
535 SetLastError(ERROR_SUCCESS);
536 return TRUE;
537}
538//******************************************************************************
539//******************************************************************************
540BOOL WIN32API GetTextExtentPoint32A( HDC hdc, LPCSTR lpsz, int cbString, PSIZE lpSize)
541{
542 return GetTextExtentPointA(hdc, lpsz, cbString, lpSize);
543}
544//******************************************************************************
545//******************************************************************************
546BOOL WIN32API GetTextExtentPoint32W(HDC hdc, LPCWSTR lpsz, int cbString, PSIZE lpSize)
547{
548 return GetTextExtentPointW(hdc, lpsz, cbString, lpSize);
549}
550
551typedef BOOL ( WIN32API *PFN_GETTEXTEXTENTPOINT32 )( HDC, PVOID, INT, LPSIZE );
552
553BOOL InternalGetTextExtentExPointAW(HDC hdc,
554 PVOID str,
555 INT count,
556 INT maxExt,
557 LPINT lpnFit,
558 LPINT alpDx,
559 LPSIZE size,
560 BOOL fUnicode)
561{
562 int i, nFit;
563 SIZE tSize;
564 BOOL ret = FALSE;
565
566 PFN_GETTEXTEXTENTPOINT32 pfnGetTextExtentPoint32;
567
568 if( fUnicode )
569 pfnGetTextExtentPoint32 = ( PFN_GETTEXTEXTENTPOINT32 )GetTextExtentPoint32W;
570 else
571 pfnGetTextExtentPoint32 = ( PFN_GETTEXTEXTENTPOINT32 )GetTextExtentPoint32A;
572
573 size->cx = size->cy = nFit = i = 0;
574
575 if( lpnFit || alpDx )
576 {
577 for( i = 1; i <= count; i++ )
578 {
579 if( !pfnGetTextExtentPoint32( hdc, str, i, &tSize )) goto done;
580
581 if( lpnFit && ( maxExt < tSize.cx ))
582 break;
583
584 if( alpDx )
585 alpDx[ nFit ] = tSize.cx;
586
587 nFit++;
588 }
589 }
590
591 if(( count > 0 ) && ( i >= count ))
592 {
593 size->cx = tSize.cx;
594 size->cy = tSize.cy; // The height of a font is constant.
595 }
596 else if( !pfnGetTextExtentPoint32( hdc, str, count, size )) goto done;
597
598 if(lpnFit) *lpnFit = nFit;
599 ret = TRUE;
600
601 dprintf(("returning %d %ld x %ld\n",nFit,size->cx,size->cy));
602
603done:
604 return ret;
605}
606
607//******************************************************************************
608//******************************************************************************
609BOOL WIN32API GetTextExtentExPointA(HDC hdc,
610 LPCSTR str,
611 int count,
612 int maxExt,
613 LPINT lpnFit,
614 LPINT alpDx,
615 LPSIZE size)
616{
617 return InternalGetTextExtentExPointAW( hdc, ( PVOID )str, count, maxExt, lpnFit, alpDx, size, FALSE );
618}
619//******************************************************************************
620//******************************************************************************
621BOOL WIN32API GetTextExtentExPointW(HDC hdc,
622 LPCWSTR str,
623 int count,
624 int maxExt,
625 LPINT lpnFit,
626 LPINT alpDx,
627 LPSIZE size)
628{
629 return InternalGetTextExtentExPointAW( hdc, ( PVOID )str, count, maxExt, lpnFit, alpDx, size, TRUE );
630}
631//******************************************************************************
632//******************************************************************************
633BOOL WIN32API GetCharWidth32A( HDC hdc, UINT iFirstChar, UINT iLastChar, PINT pWidthArray)
634{
635 BOOL ret = FALSE;
636
637 for (int i = iFirstChar; i <= iLastChar; i++)
638 {
639 SIZE size;
640 CHAR c = i;
641
642 if (GetTextExtentPointA(hdc, &c, 1, &size))
643 {
644 pWidthArray[i-iFirstChar] = size.cx;
645 // at least one character was processed
646 ret = TRUE;
647 }
648 else
649 {
650 // default value for unprocessed characters
651 pWidthArray[i-iFirstChar] = 0;
652 }
653
654 dprintf2(("Char 0x%x('%c') -> width %d", i, i<256? i: '.', pWidthArray[i-iFirstChar]));
655 }
656
657 return ret;
658}
659//******************************************************************************
660//******************************************************************************
661BOOL WIN32API GetCharWidth32W(HDC hdc, UINT iFirstChar, UINT iLastChar, PINT pWidthArray)
662{
663 BOOL ret = FALSE;
664
665 for (int i = iFirstChar; i <= iLastChar; i++)
666 {
667 SIZE size;
668 WCHAR wc = i;
669
670 if (GetTextExtentPointW(hdc, &wc, 1, &size))
671 {
672 pWidthArray[i-iFirstChar] = size.cx;
673 // at least one character was processed
674 ret = TRUE;
675 }
676 else
677 {
678 // default value for unprocessed characters
679 pWidthArray[i-iFirstChar] = 0;
680 }
681
682 dprintf2(("Char 0x%x('%c') -> width %d", i, i<256? i: '.', pWidthArray[i-iFirstChar]));
683 }
684
685 return ret;
686}
687//******************************************************************************
688// GetStringWidthW
689//
690// Return the width of each character in the string
691//
692// Parameters:
693// HDC hdc - device context handle
694// LPWSTR lpszString - unicod string pointer
695// UINT cbString - number of valid characters in string
696// PINT pWidthArray - array that receives the character width (must be
697// large enough to contain cbString elements
698//
699// Returns:
700// FALSE - failure
701// TRUE - success
702//
703//******************************************************************************
704BOOL WIN32API GetStringWidthW(HDC hdc, LPWSTR lpszString, UINT cbString, PINT pWidthArray)
705{
706 return FT2Module.Ft2GetStringWidthW(hdc, lpszString, cbString, pWidthArray);
707}
708//******************************************************************************
709//******************************************************************************
710BOOL WIN32API GetCharWidthFloatA(HDC hdc, UINT iFirstChar, UINT iLastChar, PFLOAT pxBUffer)
711{
712 dprintf(("ERROR: GDI32: GetCharWidthFloatA, not implemented\n"));
713 DebugInt3();
714 return(FALSE);
715}
716//******************************************************************************
717//******************************************************************************
718BOOL WIN32API GetCharWidthFloatW(HDC hdc, UINT iFirstChar, UINT iLastChar, PFLOAT pxBUffer)
719{
720 dprintf(("ERROR: GDI32: GetCharWidthFloatW, not implemented\n"));
721 DebugInt3();
722 return(FALSE);
723}
724//******************************************************************************
725//******************************************************************************
726BOOL WIN32API GetCharABCWidthsA(HDC hdc, UINT firstChar, UINT lastChar, LPABC abc)
727{
728 if(FT2Module.isEnabled() == FALSE)
729 {//fallback method
730 return O32_GetCharABCWidths(hdc, firstChar, lastChar, abc);
731 }
732
733 INT i, wlen, count = (INT)(lastChar - firstChar + 1);
734 LPSTR str;
735 LPWSTR wstr;
736 BOOL ret = TRUE;
737
738 if(count <= 0) {
739 dprintf(("ERROR: Invalid parameter!!"));
740 SetLastError(ERROR_INVALID_PARAMETER);
741 return FALSE;
742 }
743
744 str = (LPSTR)HeapAlloc(GetProcessHeap(), 0, count);
745 for(i = 0; i < count; i++)
746 str[i] = (BYTE)(firstChar + i);
747
748 wstr = FONT_mbtowc(hdc, str, count, &wlen, NULL);
749
750 for(i = 0; i < wlen; i++)
751 {
752 if(!GetCharABCWidthsW(hdc, wstr[i], wstr[i], abc))
753 {
754 ret = FALSE;
755 break;
756 }
757 abc++;
758 }
759
760 HeapFree(GetProcessHeap(), 0, str);
761 HeapFree(GetProcessHeap(), 0, wstr);
762
763 return ret;
764}
765//******************************************************************************
766//******************************************************************************
767BOOL WIN32API GetCharABCWidthsW( HDC hdc, UINT firstChar, UINT lastChar, LPABC abc)
768{
769 if(FT2Module.isEnabled() == FALSE)
770 {//no fallback method (yet)
771 DebugInt3();
772 return FALSE;
773 }
774
775 int i;
776 GLYPHMETRICS gm;
777
778 for (i=firstChar;i<=lastChar;i++)
779 {
780 if(GetGlyphOutlineW(hdc, i, GGO_METRICS, &gm, 0, NULL, NULL) == GDI_ERROR)
781 {
782 dprintf(("ERROR: GetGlyphOutlineW failed!!"));
783 return FALSE;
784 }
785 abc[i-firstChar].abcA = gm.gmptGlyphOrigin.x;
786 abc[i-firstChar].abcB = gm.gmBlackBoxX;
787 abc[i-firstChar].abcC = gm.gmCellIncX - gm.gmptGlyphOrigin.x - gm.gmBlackBoxX;
788 dprintf2(("GetCharABCWidthsW %d (%d,%d,%d)", i, abc[i-firstChar].abcA, abc[i-firstChar].abcB, abc[i-firstChar].abcC));
789 }
790 return TRUE;
791}
792//******************************************************************************
793//******************************************************************************
794BOOL WIN32API GetCharABCWidthsFloatA(HDC hdc, UINT iFirstChar, UINT iLastChar, LPABCFLOAT pxBUffer)
795{
796 dprintf(("ERROR: GDI32: GetCharABCWidthsFloatA, not implemented\n"));
797 DebugInt3();
798 return(FALSE);
799}
800//******************************************************************************
801//******************************************************************************
802BOOL WIN32API GetCharABCWidthsFloatW(HDC hdc,
803 UINT iFirstChar,
804 UINT iLastChar,
805 LPABCFLOAT pxBUffer)
806{
807 dprintf(("ERROR: GDI32: GetCharABCWidthsFloatA, not implemented\n"));
808 DebugInt3();
809 return(FALSE);
810}
811//******************************************************************************
812//******************************************************************************
813
Note: See TracBrowser for help on using the repository browser.