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

Last change on this file since 10392 was 10392, checked in by sandervl, 22 years ago

logging fix

File size: 26.1 KB
Line 
1/* $Id: text.cpp,v 1.42 2004-01-14 16:53:25 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 rc = InternalTextOutAW(hdc, X, Y, fuOptions, lprc, lpszString, NULL, cbCount, lpDx, TRUE, FALSE);
354
355 return(rc);
356}
357//******************************************************************************
358//******************************************************************************
359BOOL 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//******************************************************************************
370BOOL 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//******************************************************************************
377BOOL 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//******************************************************************************
384BOOL 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//******************************************************************************
400BOOL 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//******************************************************************************
420BOOL 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//******************************************************************************
456BOOL 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//******************************************************************************
535BOOL WIN32API GetTextExtentPoint32A( HDC hdc, LPCSTR lpsz, int cbString, PSIZE lpSize)
536{
537 return GetTextExtentPointA(hdc, lpsz, cbString, lpSize);
538}
539//******************************************************************************
540//******************************************************************************
541BOOL WIN32API GetTextExtentPoint32W(HDC hdc, LPCWSTR lpsz, int cbString, PSIZE lpSize)
542{
543 return GetTextExtentPointW(hdc, lpsz, cbString, lpSize);
544}
545//******************************************************************************
546//******************************************************************************
547BOOL WIN32API GetTextExtentExPointA(HDC hdc,
548 LPCSTR str,
549 int count,
550 int maxExt,
551 LPINT lpnFit,
552 LPINT alpDx,
553 LPSIZE size)
554{
555 BOOL ret;
556 INT wlen;
557 LPWSTR p;
558 INT nFit;
559 TEXTMETRICA tmA;
560 CHAR brokenDBCS = 0;
561
562 if( IsDBCSEnv())
563 {
564 brokenDBCS = getBrokenDBCS( str, count );
565
566 GetTextMetricsA( hdc, &tmA );
567 }
568
569 if( brokenDBCS )
570 count--;
571
572 p = FONT_mbtowc( hdc, str, count, &wlen, NULL);
573 ret = GetTextExtentExPointW( hdc, p, wlen, maxExt, &nFit, alpDx, size);
574 nFit = WideCharToMultiByte(CP_ACP,0,p,nFit,NULL,0,NULL,NULL);
575 if( IsDBCSEnv() && alpDx ) // index of alpDx between ansi and wide may not match in DBCS !!!
576 {
577 LPINT alpDxNew = ( LPINT )HeapAlloc( GetProcessHeap(), 0, sizeof( alpDx[ 0 ] ) * ( nFit + 1 ));
578 INT prevDx;
579 int i, j;
580
581 for( i = j = 0; i < nFit; i++, j++ )
582 {
583 if( IsDBCSLeadByte( str[ i ]))
584 {
585 prevDx = ( i > 0 ) ? alpDxNew[ i - 1 ] : 0;
586 alpDxNew[ i++ ] = prevDx + tmA.tmAveCharWidth;
587 if( i >= nFit )
588 break;
589 }
590 alpDxNew[ i ] = alpDx[ j ];
591 }
592
593 if(( nFit < count ) && IsDBCSLeadByte( str[ nFit ]))
594 {
595 prevDx = ( nFit > 0 ) ? alpDxNew[ nFit - 1 ] : 0;
596 if( maxExt >= prevDx + tmA.tmAveCharWidth )
597 alpDxNew[ nFit++ ] = prevDx + tmA.tmAveCharWidth;
598 }
599
600 memcpy( alpDx, alpDxNew, sizeof( alpDx[ 0 ] ) * nFit );
601
602 HeapFree( GetProcessHeap(), 0, alpDxNew );
603 }
604
605 // for broken DBCS. correct for FIXED WIDTH, not approx. for VARIABLE WIDTH
606 if( brokenDBCS )
607 {
608 size->cx += tmA.tmAveCharWidth;
609 if( count == 0 )
610 size->cy = tmA.tmHeight;
611
612 if(( maxExt > size->cx ) && ( nFit <= count )) // decreaed count by 1 above
613 {
614 if( alpDx )
615 alpDx[ nFit ] = size->cx;
616
617 nFit++;
618 }
619 }
620
621 if (lpnFit) *lpnFit = nFit;
622
623 HeapFree( GetProcessHeap(), 0, p );
624 return ret;
625}
626//******************************************************************************
627//******************************************************************************
628BOOL WIN32API GetTextExtentExPointW(HDC hdc,
629 LPCWSTR str,
630 int count,
631 int maxExt,
632 LPINT lpnFit,
633 LPINT alpDx,
634 LPSIZE size)
635{
636 int i, nFit, extent;
637 SIZE tSize;
638 BOOL ret = FALSE;
639
640 size->cx = size->cy = nFit = extent = 0;
641
642 for( i = 1; i <= count; i++ )
643 {
644 if( !GetTextExtentPoint32W( hdc, str, i, &tSize )) goto done;
645
646 if( maxExt < tSize.cx )
647 break;
648
649 if( alpDx )
650 alpDx[ nFit ] = tSize.cx;
651
652 nFit++;
653 }
654
655 if( i >= count )
656 size->cx = tSize.cx;
657 else if( !GetTextExtentPoint32W( hdc, str, count, size )) goto done;
658
659 size->cy = tSize.cy; // The height of a font is constant.
660
661 if(lpnFit) *lpnFit = nFit;
662 ret = TRUE;
663
664 dprintf(("returning %d %ld x %ld\n",nFit,size->cx,size->cy));
665
666done:
667 return ret;
668}
669//******************************************************************************
670//******************************************************************************
671BOOL WIN32API GetCharWidth32A( HDC hdc, UINT iFirstChar, UINT iLastChar, PINT pWidthArray)
672{
673 BOOL ret = FALSE;
674
675 for (int i = iFirstChar; i <= iLastChar; i++)
676 {
677 SIZE size;
678 CHAR c = i;
679
680 if (GetTextExtentPointA(hdc, &c, 1, &size))
681 {
682 pWidthArray[i-iFirstChar] = size.cx;
683 // at least one character was processed
684 ret = TRUE;
685 }
686 else
687 {
688 // default value for unprocessed characters
689 pWidthArray[i-iFirstChar] = 0;
690 }
691
692 dprintf2(("Char 0x%x('%c') -> width %d", i, i<256? i: '.', pWidthArray[i-iFirstChar]));
693 }
694
695 return ret;
696}
697//******************************************************************************
698//******************************************************************************
699BOOL WIN32API GetCharWidth32W(HDC hdc, UINT iFirstChar, UINT iLastChar, PINT pWidthArray)
700{
701 BOOL ret = FALSE;
702
703 for (int i = iFirstChar; i <= iLastChar; i++)
704 {
705 SIZE size;
706 WCHAR wc = i;
707
708 if (GetTextExtentPointW(hdc, &wc, 1, &size))
709 {
710 pWidthArray[i-iFirstChar] = size.cx;
711 // at least one character was processed
712 ret = TRUE;
713 }
714 else
715 {
716 // default value for unprocessed characters
717 pWidthArray[i-iFirstChar] = 0;
718 }
719
720 dprintf2(("Char 0x%x('%c') -> width %d", i, i<256? i: '.', pWidthArray[i-iFirstChar]));
721 }
722
723 return ret;
724}
725//******************************************************************************
726// GetStringWidthW
727//
728// Return the width of each character in the string
729//
730// Parameters:
731// HDC hdc - device context handle
732// LPWSTR lpszString - unicod string pointer
733// UINT cbString - number of valid characters in string
734// PINT pWidthArray - array that receives the character width (must be
735// large enough to contain cbString elements
736//
737// Returns:
738// FALSE - failure
739// TRUE - success
740//
741//******************************************************************************
742BOOL WIN32API GetStringWidthW(HDC hdc, LPWSTR lpszString, UINT cbString, PINT pWidthArray)
743{
744 return FT2Module.Ft2GetStringWidthW(hdc, lpszString, cbString, pWidthArray);
745}
746//******************************************************************************
747//******************************************************************************
748BOOL WIN32API GetCharWidthFloatA(HDC hdc, UINT iFirstChar, UINT iLastChar, PFLOAT pxBUffer)
749{
750 dprintf(("ERROR: GDI32: GetCharWidthFloatA, not implemented\n"));
751 DebugInt3();
752 return(FALSE);
753}
754//******************************************************************************
755//******************************************************************************
756BOOL WIN32API GetCharWidthFloatW(HDC hdc, UINT iFirstChar, UINT iLastChar, PFLOAT pxBUffer)
757{
758 dprintf(("ERROR: GDI32: GetCharWidthFloatW, not implemented\n"));
759 DebugInt3();
760 return(FALSE);
761}
762//******************************************************************************
763//******************************************************************************
764BOOL WIN32API GetCharABCWidthsA(HDC hdc, UINT firstChar, UINT lastChar, LPABC abc)
765{
766 if(FT2Module.isEnabled() == FALSE)
767 {//fallback method
768 return O32_GetCharABCWidths(hdc, firstChar, lastChar, abc);
769 }
770
771 INT i, wlen, count = (INT)(lastChar - firstChar + 1);
772 LPSTR str;
773 LPWSTR wstr;
774 BOOL ret = TRUE;
775
776 if(count <= 0) {
777 dprintf(("ERROR: Invalid parameter!!"));
778 SetLastError(ERROR_INVALID_PARAMETER);
779 return FALSE;
780 }
781
782 str = (LPSTR)HeapAlloc(GetProcessHeap(), 0, count);
783 for(i = 0; i < count; i++)
784 str[i] = (BYTE)(firstChar + i);
785
786 wstr = FONT_mbtowc(hdc, str, count, &wlen, NULL);
787
788 for(i = 0; i < wlen; i++)
789 {
790 if(!GetCharABCWidthsW(hdc, wstr[i], wstr[i], abc))
791 {
792 ret = FALSE;
793 break;
794 }
795 abc++;
796 }
797
798 HeapFree(GetProcessHeap(), 0, str);
799 HeapFree(GetProcessHeap(), 0, wstr);
800
801 return ret;
802}
803//******************************************************************************
804//******************************************************************************
805BOOL WIN32API GetCharABCWidthsW( HDC hdc, UINT firstChar, UINT lastChar, LPABC abc)
806{
807 if(FT2Module.isEnabled() == FALSE)
808 {//no fallback method (yet)
809 DebugInt3();
810 return FALSE;
811 }
812
813 int i;
814 GLYPHMETRICS gm;
815
816 for (i=firstChar;i<=lastChar;i++)
817 {
818 if(GetGlyphOutlineW(hdc, i, GGO_METRICS, &gm, 0, NULL, NULL) == GDI_ERROR)
819 {
820 dprintf(("ERROR: GetGlyphOutlineW failed!!"));
821 return FALSE;
822 }
823 abc[i-firstChar].abcA = gm.gmptGlyphOrigin.x;
824 abc[i-firstChar].abcB = gm.gmBlackBoxX;
825 abc[i-firstChar].abcC = gm.gmCellIncX - gm.gmptGlyphOrigin.x - gm.gmBlackBoxX;
826 dprintf2(("GetCharABCWidthsW %d (%d,%d,%d)", i, abc[i-firstChar].abcA, abc[i-firstChar].abcB, abc[i-firstChar].abcC));
827 }
828 return TRUE;
829}
830//******************************************************************************
831//******************************************************************************
832BOOL WIN32API GetCharABCWidthsFloatA(HDC hdc, UINT iFirstChar, UINT iLastChar, LPABCFLOAT pxBUffer)
833{
834 dprintf(("ERROR: GDI32: GetCharABCWidthsFloatA, not implemented\n"));
835 DebugInt3();
836 return(FALSE);
837}
838//******************************************************************************
839//******************************************************************************
840BOOL WIN32API GetCharABCWidthsFloatW(HDC hdc,
841 UINT iFirstChar,
842 UINT iLastChar,
843 LPABCFLOAT pxBUffer)
844{
845 dprintf(("ERROR: GDI32: GetCharABCWidthsFloatA, not implemented\n"));
846 DebugInt3();
847 return(FALSE);
848}
849//******************************************************************************
850//******************************************************************************
851
Note: See TracBrowser for help on using the repository browser.