source: trunk/src/gdi32/ft2supp.cpp@ 21628

Last change on this file since 21628 was 21628, checked in by dmik, 14 years ago

gdi32: Fixed broken TextOut API family that would draw text flipped along the base line.

File size: 25.2 KB
Line 
1/*
2 * GDI32 FreeType2 Support Class
3 *
4 * Copyright 2003 Innotek Systemberatung GmbH (sandervl@innotek.de)
5 * (stauff@innotek.de)
6 *
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 */
10
11/*****************************************************************************
12 * Includes *
13 *****************************************************************************/
14
15#define INCL_DOS
16#define INCL_GPI
17#define INCL_WIN
18#define INCL_SHLERRORS
19#define INCL_WINERRORS
20#include <os2wrap.h> //Odin32 OS/2 api wrappers
21#include <stdlib.h>
22#include <string.h>
23#include <win32type.h>
24#include <dbglog.h>
25#include <win32api.h>
26#include <winconst.h>
27#include <winnls.h>
28#include <heapstring.h>
29#include <winuser32.h>
30#include <odinlx.h>
31#include "oslibgpi.h"
32
33#include "ft2supp.h"
34
35CFT2Module FT2Module;
36
37static BOOL fFT2LIBIntegration = FALSE;
38
39//******************************************************************************
40//******************************************************************************
41void WIN32API SetFreeTypeIntegration(BOOL fEnabled)
42{
43 fFT2LIBIntegration = fEnabled;
44
45 FT2Module.init();
46}
47//******************************************************************************
48// Constructor
49//******************************************************************************
50CFT2Module::CFT2Module(char* sModuleName): bEnabled(FALSE), hftModule(0), pfnGetGlyphIndices(NULL),
51 pfnFt2GetTextExtentW(NULL), pfnFt2EnableFontEngine(NULL),
52 pfnFt2GetGlyphOutline(NULL), pfnFt2CharStringPosAtA(NULL),
53 pfnFt2CharStringPosAtW(NULL), pfnFt2GetFontData(NULL),
54 pfnFt2RegisterUconv(NULL), pfnFt2QueryStringWidthW(NULL),
55 pfnFt2GetVersion(NULL)
56{
57 pszModuleName = sModuleName; //must be static
58}
59//******************************************************************************
60//******************************************************************************
61void CFT2Module::init()
62{
63 APIRET rc;
64 UCHAR Loaderror[ 256 ];
65 LONG major = 0, minor = 0, buildnr = 0;
66
67 if(!fFT2LIBIntegration) {
68 dprintf(("No FT2LIB integration!!"));
69 goto failure;
70 }
71
72 rc = DosLoadModule((PSZ)Loaderror, sizeof(Loaderror), pszModuleName, &hftModule);
73 if (rc != 0)
74 dprintf(("Freetype2 library load error: return code = %u\n", rc));
75 else
76 bEnabled = TRUE;
77
78 if(bEnabled) {
79 pfnFt2GetVersion = (PFN_FT2GETVERSION)QueryProcAddress("Ft2GetVersion");
80 if(!pfnFt2GetVersion) {
81 dprintf(("Ft2GetVersion not found!!"));
82 goto failure;
83 }
84 pfnFt2GetVersion(&major, &minor, &buildnr);
85 if(major != FT2LIB_MAJOR_VERSION) {
86 dprintf(("Incorrect major version %d; expected %d!!", major, FT2LIB_MAJOR_VERSION));
87 goto failure;
88 }
89 if(minor < FT2LIB_MINOR_VERSION) {
90 dprintf(("Incorrect minor version %d; expected >= %d!!", minor, FT2LIB_MINOR_VERSION));
91 goto failure;
92 }
93
94 pfnFt2EnableFontEngine = (PFN_FT2ENABLEFONTENGINE)QueryProcAddress("Ft2EnableFontEngine");
95 if(!pfnFt2EnableFontEngine) dprintf(("Ft2EnableFontEngine not found!!"));
96 else pfnFt2EnableFontEngine(bEnabled);
97
98 pfnGetGlyphIndices = (PFN_FT2GETGLYPHINDICES)QueryProcAddress("Ft2GetGlyphIndices");
99 if(!pfnGetGlyphIndices) dprintf(("Ft2GetGlyphIndices not found!!"));
100
101 pfnFt2GetTextExtentW = (PFN_FT2GETTEXTEXTENTW)QueryProcAddress("Ft2GetTextExtentW");
102 if(!pfnFt2GetTextExtentW) dprintf(("Ft2GetTextExtentW not found!!"));
103
104 pfnFt2CharStringPosAtA = (PFN_FT2CHARSTRINGPOSATA)QueryProcAddress("Ft2CharStringPosAtA");
105 if(!pfnFt2CharStringPosAtA) dprintf(("Ft2CharStringPosAtA not found!!"));
106 pfnFt2CharStringPosAtW = (PFN_FT2CHARSTRINGPOSATW)QueryProcAddress("Ft2CharStringPosAtW");
107 if(!pfnFt2CharStringPosAtW) dprintf(("Ft2CharStringPosAtW not found!!"));
108
109 pfnFt2GetGlyphOutline = (PFN_FT2GETGLYPHOUTLINE)QueryProcAddress("Ft2GetGlyphOutline");
110 if(!pfnFt2GetGlyphOutline) dprintf(("Ft2GetGlyphOutline not found!!"));
111
112 pfnFt2GetFontData = (PFN_FT2GETFONTDATA)QueryProcAddress("Ft2GetFontData");
113 if(!pfnFt2GetFontData) dprintf(("Ft2GetFontData not found!!"));
114
115 pfnFt2QueryFontType = (PFN_FT2QUERYFONTTYPE)QueryProcAddress("Ft2QueryFontType");
116 if(!pfnFt2QueryFontType) dprintf(("Ft2QueryFontType not found!!"));
117
118 pfnFt2QueryStringWidthW = (PFN_FT2QUERYSTRINGWIDTHW)QueryProcAddress("Ft2QueryStringWidthW");
119 if(!pfnFt2QueryStringWidthW) dprintf(("Ft2QueryStringWidthW not found!!"));
120
121 pfnFt2GetCharacterPlacementW = (PFN_FT2GETCHARACTERPLACEMENTW)QueryProcAddress("Ft2GetCharacterPlacementW");
122 if(!pfnFt2GetCharacterPlacementW) dprintf(("pfnFt2GetCharacterPlacementW not found!!"));
123
124 // Do not register functions for Mozilla plugins
125 if(IsDummyExeLoaded() == FALSE)
126 {
127 pfnFt2RegisterUconv = (PFN_FT2REGISTERUCONV)QueryProcAddress("Ft2RegisterUconv");
128 if(pfnFt2RegisterUconv)
129 pfnFt2RegisterUconv(WideCharToMultiByte, MultiByteToWideChar);
130 else dprintf(("Ft2QueryFontType not found!!"));
131 }
132 dprintf(("Freetype2 library enabled state %d",bEnabled));
133 }
134 return;
135
136failure:
137 if(pfnFt2RegisterUconv)
138 pfnFt2RegisterUconv(NULL, NULL);
139 if(pfnFt2EnableFontEngine)
140 pfnFt2EnableFontEngine(FALSE);
141
142 pfnGetGlyphIndices = NULL;
143 pfnFt2GetTextExtentW = NULL;
144 pfnFt2EnableFontEngine = NULL;
145 pfnFt2GetGlyphOutline = NULL;
146 pfnFt2CharStringPosAtA = NULL;
147 pfnFt2CharStringPosAtW = NULL;
148 pfnFt2GetFontData = NULL;
149 pfnFt2RegisterUconv = NULL;
150 pfnFt2QueryStringWidthW= NULL;
151 pfnFt2GetVersion = NULL;
152 bEnabled = FALSE;
153 if (hftModule) {
154 DosFreeModule(hftModule);
155 hftModule = 0;
156 }
157 return;
158}
159//******************************************************************************
160// Destructor
161//******************************************************************************
162CFT2Module::~CFT2Module()
163{
164 if (hftModule)
165 DosFreeModule(hftModule);
166
167 bEnabled = FALSE;
168}
169//******************************************************************************
170//******************************************************************************
171PFN CFT2Module::QueryProcAddress(int ordinal)
172{
173 APIRET rc;
174 PFN ModuleAddr;
175
176 rc = DosQueryProcAddr(hftModule, ordinal, NULL, &ModuleAddr);
177 if (rc != 0) {
178 dprintf(("FreeType2 QueryProcAddr error: return code = %u\n", rc));
179 return 0;
180 }
181 return ModuleAddr;
182}
183//******************************************************************************
184//******************************************************************************
185PFN CFT2Module::QueryProcAddress(char * procname)
186{
187 APIRET rc;
188 PFN ModuleAddr;
189
190 rc = DosQueryProcAddr(hftModule, 0, procname, &ModuleAddr);
191 if (rc != 0) {
192 dprintf(("FreeType2 QueryProcAddr error: return code = %u\n", rc));
193 return 0;
194 }
195 return ModuleAddr;
196}
197//******************************************************************************
198//******************************************************************************
199DWORD CFT2Module::Ft2GetGlyphIndices(HPS hps, LPCWSTR str, int c, LPWORD pgi, DWORD fl)
200{
201 DWORD ret;
202 USHORT sel;
203
204 // All FreeType calls should be wrapped for saving FS
205 if(pfnGetGlyphIndices) {
206 sel = RestoreOS2FS();
207 ret = pfnGetGlyphIndices(hps, (WCHAR*)str, c, (ULONG*)pgi, fl);
208 SetFS(sel);
209 return ret;
210 }
211 //no fallback
212 SetLastError(ERROR_CALL_NOT_IMPLEMENTED_W);
213 return GDI_ERROR;
214}
215//******************************************************************************
216//******************************************************************************
217DWORD CFT2Module::Ft2GetGlyphOutline(HPS hps, UINT glyph, UINT format, LPGLYPHMETRICS lpgm, DWORD buflen, LPVOID buf, const MAT2* lpmat)
218{
219 DWORD ret;
220 USHORT sel;
221
222 // All FreeType calls should be wrapped for saving FS
223 if (pfnFt2GetGlyphOutline)
224 {
225 sel = RestoreOS2FS();
226 ret = pfnFt2GetGlyphOutline (hps, glyph, format, lpgm, buflen, buf, lpmat);
227 SetFS(sel);
228 return ret;
229 }
230
231 //no fallback
232 SetLastError(ERROR_INVALID_FUNCTION_W);
233 return GDI_ERROR;
234}
235//******************************************************************************
236//
237// This is basically the same as Ft2QueryTextBoxW, but it behaves as the Win32
238// API GetTextExtent (which ignores character attributes and underhang/overhang)
239//
240// The fallback case is not accurate!! (but the same as our old code)
241//
242//******************************************************************************
243BOOL CFT2Module::Ft2GetTextExtentW(HPS hps, LONG lCount1,LPCWSTR pchString, PPOINTLOS2 pwidthHeight)
244{
245 DWORD ret;
246 USHORT sel;
247 POINTLOS2 aptlPoints[TXTBOX_COUNT];
248
249 // All FreeType calls should be wrapped for saving FS
250 if(pfnFt2GetTextExtentW)
251 {
252 sel = RestoreOS2FS();
253 ret = pfnFt2GetTextExtentW(hps, lCount1, pchString, TXTBOX_COUNT, aptlPoints);
254 SetFS(sel);
255 if(ret || (ret == FALSE && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
256 {
257 calcDimensions(aptlPoints, pwidthHeight);
258 return ret;
259 }
260 }
261 //else fall back to GPI
262 INT lenA;
263 LPSTR strA;
264 POINTLOS2 start = { 0, 0 };
265 PPOINTLOS2 pplos2;
266 INT cx;
267 INT cy;
268
269 pDCData pHps = (pDCData)OSLibGpiQueryDCData(hps);
270
271 lenA = WideCharToMultiByte( CP_ACP, 0, pchString, lCount1, 0, 0, 0, 0 );
272 strA = ( LPSTR )malloc( lenA + 1 );
273 lstrcpynWtoA( strA, pchString, lenA + 1 );
274 pplos2 = ( PPOINTLOS2 )malloc(( lenA + 1 ) * sizeof( POINTLOS2 ));
275
276 ret = OSLibGpiQueryCharStringPosAt( pHps, &start, 0, lenA, strA, NULL, pplos2 );
277 if( ret )
278 {
279 TEXTMETRICW tmW;
280
281 cx = labs( pplos2[ lenA ].x - pplos2[ 0 ].x );
282 cy = labs( pplos2[ lenA ].y - pplos2[ 0 ].y );
283
284 aptlPoints[ TXTBOX_BOTTOMLEFT ].x = 0;
285 aptlPoints[ TXTBOX_BOTTOMLEFT ].y = 0;
286 aptlPoints[ TXTBOX_BOTTOMRIGHT ].x = cx;
287 aptlPoints[ TXTBOX_BOTTOMRIGHT ].y = cy;
288 aptlPoints[ TXTBOX_TOPLEFT ].x = 0;
289 aptlPoints[ TXTBOX_TOPLEFT ].y = 0;
290 aptlPoints[ TXTBOX_TOPRIGHT ].x = cx;
291 aptlPoints[ TXTBOX_TOPRIGHT ].y = cy;
292 aptlPoints[ TXTBOX_CONCAT ].x = cx;
293 aptlPoints[ TXTBOX_CONCAT ].y = cy;
294
295 calcDimensions(aptlPoints, pwidthHeight);
296
297 DecreaseLogCount();
298 if(GetTextMetricsW( hps, &tmW ) == TRUE)
299 {
300 pwidthHeight->y = tmW.tmHeight; // *Must* use the maximum height of the font
301 }
302#ifdef DEBUG
303 else DebugInt3();
304#endif
305 IncreaseLogCount();
306 }
307
308 free( pplos2 );
309 free( strA );
310
311 return ret;
312}
313//******************************************************************************
314//******************************************************************************
315struct CTISTATE
316{
317 pDCData pHps;
318 BOOL restoreInversion;
319 BOOL restoreMatrix;
320 LONG oldYInversion;
321 MATRIXLF mlf;
322};
323
324static void CompensateTextInversion(pDCData pHps, PPOINTLOS2 ptl, PRECTLOS2 rct,
325 CTISTATE *state)
326{
327 state->pHps = pHps;
328 state->restoreInversion = FALSE;
329 state->restoreMatrix = FALSE;
330
331 // The target HPS is most likely set up for Y inversion, to bring the origin
332 // from the bottom-left corner (PM) to the top-left (Win). However, PM text
333 // drawing routines make an exception for themselves and produce correct
334 // top-left oriented glyphs despite the bottom-left oriented coordinate
335 // space. Having the mentioned Y inversion makes them flip and display
336 // glyphs top to bottom. We need to cancel this flip to get the correct
337 // text orientation.
338
339 GpiQueryDefaultViewMatrix(pHps->hps, 9, &state->mlf);
340
341 if (state->mlf.fxM11 == MAKEFIXED(1, 0) && state->mlf.fxM12 == 0 &&
342 state->mlf.lM13 == 0 &&
343 state->mlf.fxM21 == 0 && state->mlf.fxM22 == MAKEFIXED(1, 0) &&
344 state->mlf.lM23 == 0 &&
345 state->mlf.lM31 == 0 && state->mlf.lM32 == 0 && state->mlf.lM33 == 1)
346 {
347 // the most common case: the identity matrix, the inversion is done...
348#ifdef INVERT
349 // ...through the special GPI call, cancel it and correct ptl/rct
350 state->oldYInversion = GpiQueryYInversion(pHps->hps);
351 if (state->oldYInversion != 0)
352 {
353 ptl->y = state->oldYInversion - ptl->y;
354 if (rct)
355 {
356 LONG temp = state->oldYInversion - rct->yBottom;
357 rct->yBottom = state->oldYInversion - rct->yTop;
358 rct->yTop = temp;
359 }
360
361 GpiEnableYInversion(pHps->hps, 0);
362
363 state->restoreInversion = TRUE;
364 }
365#else
366 // through the raw yInvert value
367 if (pHps->yInvert > 0)
368 {
369 LONG temp = pHps->yInvert - rct->yBottom;
370 rct->yBottom = pHps->yInvert - rct->yTop;
371 rct->yTop = temp;
372 }
373#endif
374 }
375 else
376 {
377 // the complex case: append a matrix transformation that will flip the
378 // text along the ptl's Y coordinate
379 MATRIXLF mlf;
380 mlf.fxM11 = MAKEFIXED(1, 0);
381 mlf.fxM12 = 0;
382 mlf.lM13 = 0;
383 mlf.fxM21 = 0;
384 mlf.fxM22 = MAKEFIXED(-1, 0);
385 mlf.lM23 = 0;
386 mlf.lM31 = 0;
387 mlf.lM32 = ptl->y * 2;
388 GpiSetDefaultViewMatrix(pHps->hps, 8, &mlf, TRANSFORM_ADD);
389
390 state->restoreMatrix = TRUE;
391 }
392}
393
394static void UncompensateTextInversion(CTISTATE *state)
395{
396 if (state->restoreInversion)
397 GpiEnableYInversion(state->pHps->hps, state->oldYInversion);
398 if (state->restoreMatrix)
399 GpiSetDefaultViewMatrix(state->pHps->hps, 9, &state->mlf,
400 TRANSFORM_REPLACE);
401}
402//******************************************************************************
403//******************************************************************************
404BOOL CFT2Module::Ft2CharStringPosAtA(HPS hps,PPOINTLOS2 ptl,PRECTLOS2 rct,ULONG flOptions,LONG lCount,LPCSTR pchString,CONST INT *alAdx, DWORD fuWin32Options)
405{
406 DWORD ret;
407 USHORT sel;
408 pDCData pHps;
409
410 pHps = (pDCData)OSLibGpiQueryDCData(hps);
411
412 CTISTATE ctiState;
413 CompensateTextInversion(pHps, ptl, rct, &ctiState);
414
415 BOOL fallback = TRUE;
416
417 if(pfnFt2CharStringPosAtA)
418 {
419 // All FreeType calls should be wrapped for saving FS
420 sel = RestoreOS2FS();
421 ret = pfnFt2CharStringPosAtA(hps, ptl,rct,flOptions,lCount,pchString,alAdx, fuWin32Options);
422 SetFS(sel);
423 if(ret || (ret == FALSE && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
424 fallback = FALSE;
425 }
426
427 if (fallback)
428 {
429 //else fall back to GPI
430 //NOTE: We don't support fuWin32Options in the fallback case
431 ret = OSLibGpiCharStringPosAt(pHps,ptl,rct,flOptions,lCount,pchString,alAdx);
432 }
433
434 UncompensateTextInversion(&ctiState);
435
436 return ret;
437}
438//******************************************************************************
439//******************************************************************************
440BOOL CFT2Module::Ft2CharStringPosAtW(HPS hps, PPOINTLOS2 ptl,PRECTLOS2 rct,ULONG flOptions,LONG lCount,LPCWSTR pchString,CONST INT *alAdx, DWORD fuWin32Options)
441{
442 DWORD ret;
443 USHORT sel;
444 pDCData pHps;
445
446 pHps = (pDCData)OSLibGpiQueryDCData(hps);
447
448 CTISTATE ctiState;
449 CompensateTextInversion(pHps, ptl, rct, &ctiState);
450
451 BOOL fallback = TRUE;
452
453 if (pfnFt2CharStringPosAtW)
454 {
455 // All FreeType calls should be wrapped for saving FS
456 sel = RestoreOS2FS();
457 ret = pfnFt2CharStringPosAtW(hps, ptl,rct,flOptions,lCount,pchString,alAdx, fuWin32Options);
458 SetFS(sel);
459 if(ret || (ret == FALSE && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
460 fallback = FALSE;
461 }
462
463 if (fallback)
464 {
465 // fall back to GPI
466 // NOTE: We don't support fuWin32Options in the fallback case
467 int len;
468 LPSTR astring;
469
470 LPINT lpDx = NULL;
471
472 len = WideCharToMultiByte( CP_ACP, 0, pchString, lCount, 0, 0, NULL, NULL );
473 astring = (char *)malloc( len + 1 );
474 lstrcpynWtoA(astring, pchString, len + 1 );
475
476 if( IsDBCSEnv() && alAdx )
477 {
478 int i, j;
479
480 lpDx = ( LPINT )malloc( len * sizeof( INT ));
481 for( i = j = 0; i < len; i++, j++ )
482 {
483 lpDx[ i ] = alAdx[ j ];
484 if( IsDBCSLeadByte( astring[ i ]))
485 lpDx[ ++i ] = 0;
486 }
487
488 alAdx = ( CONST INT * )lpDx;
489 }
490
491 ret = OSLibGpiCharStringPosAt(pHps,ptl,rct,flOptions,len,astring,alAdx);
492
493 if( lpDx )
494 free( lpDx );
495
496 free(astring);
497 }
498
499 UncompensateTextInversion(&ctiState);
500
501 return ret;
502}
503//******************************************************************************
504//******************************************************************************
505DWORD CFT2Module::Ft2GetFontData(HPS hps, DWORD dwTable, DWORD dwOffset,
506 LPVOID lpvBuffer, DWORD cbData)
507{
508 DWORD ret;
509 USHORT sel;
510
511 // All FreeType calls should be wrapped for saving FS
512 if(pfnFt2GetFontData) {
513 sel = RestoreOS2FS();
514 ret = pfnFt2GetFontData(hps, dwTable, dwOffset, lpvBuffer, cbData);
515 SetFS(sel);
516 if(ret || (ret == GDI_ERROR && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
517 return ret;
518 }
519 //no fallback
520 SetLastError(ERROR_CALL_NOT_IMPLEMENTED_W);
521 return(GDI_ERROR);
522}
523//******************************************************************************
524// Query the font type current selected into the presentation space, or,
525// when hps == NULL, query the type of the font with the specified name
526//******************************************************************************
527DWORD CFT2Module::Ft2QueryFontType(HPS hps, LPCSTR lpszFontName)
528{
529 DWORD ret;
530 USHORT sel;
531
532 // All FreeType calls should be wrapped for saving FS
533 if(pfnFt2QueryFontType) {
534 sel = RestoreOS2FS();
535 ret = pfnFt2QueryFontType(hps, lpszFontName);
536 SetFS(sel);
537 if(ret || (ret == GDI_ERROR && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
538 return ret;
539 }
540 //no fallback
541 return FT2_FONTTYPE_UNKNOWN;
542}
543//******************************************************************************
544//******************************************************************************
545BOOL CFT2Module::Ft2GetStringWidthW(HDC hdc, LPWSTR lpszString, UINT cbString, PINT pWidthArray)
546{
547 DWORD ret;
548 USHORT sel;
549 pDCData pHps;
550
551 pHps = (pDCData)OSLibGpiQueryDCData(hdc);
552 if(pHps == NULL) {
553 DebugInt3();
554 SetLastError(ERROR_INVALID_HANDLE_W);
555 return 0;
556 }
557
558 // All FreeType calls should be wrapped for saving FS
559 if(pfnFt2QueryStringWidthW) {
560 sel = RestoreOS2FS();
561 ret = pfnFt2QueryStringWidthW((HPS)hdc, lpszString, cbString, (LONG *)pWidthArray);
562 SetFS(sel);
563 if(ret || (ret == GDI_ERROR && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
564 {
565 if(pHps && pHps->isPrinter && pHps->hdc)
566 {//scale for printer dcs
567 LONG alArray[2];
568
569 if(OSLibDevQueryCaps(pHps, OSLIB_CAPS_HORIZONTAL_RESOLUTION, 2, &alArray[0]) &&
570 alArray[0] != alArray[1])
571 {
572 dprintf(("Different hor/vert resolutions (%d,%d)", alArray[0], alArray[1]));
573 for (int i = 0; i < cbString; i++)
574 {
575 pWidthArray[i] = pWidthArray[i] * alArray[0] / alArray[1];
576 }
577 }
578 }
579 return ret;
580 }
581 }
582 //fallback method
583 int c, i;
584 for (i = 0; i < cbString; i++)
585 {
586 if (GetCharWidth32W(hdc, lpszString[i], lpszString[i], (LPINT)&c)) {
587 dprintf(("%c pWidthArray[%d] = %d", lpszString[i], i, c));
588 pWidthArray[i]= c;
589 }
590 else {
591 dprintf(("WARNING: GetCharWidth32W failed for %c!!!", lpszString[i]));
592 pWidthArray[i] = 0;
593 }
594 }
595 return TRUE;
596}
597/*****************************************************************************
598 * Name : DWORD GetCharacterPlacementW
599 * Purpose : The GetCharacterPlacementW function retrieves information about
600 * a character string, such as character widths, caret positioning,
601 * ordering within the string, and glyph rendering. The type of
602 * information returned depends on the dwFlags parameter and is
603 * based on the currently selected font in the given display context.
604 * The function copies the information to the specified GCP_RESULTSW
605 * structure or to one or more arrays specified by the structure.
606 * Parameters: HDC hdc handle to device context
607 * LPCSTR lpString pointer to string
608 * int nCount number of characters in string
609 * int nMaxExtent maximum extent for displayed string
610 * GCP_RESULTSW *lpResults pointer to buffer for placement result
611 * DWORD dwFlags placement flags
612 * Variables :
613 * Result :
614 * Remark :
615 * Status : Partly working
616 *
617 * Author : Borrowed Rewind Code
618 *****************************************************************************/
619DWORD CFT2Module::Ft2GetCharacterPlacementW(HDC hdc,
620 LPCWSTR lpString,
621 int uCount,
622 int nMaxExtent,
623 GCP_RESULTSW *lpResults,
624 DWORD dwFlags)
625{
626 DWORD ret;
627 USHORT sel;
628 SIZE size;
629 UINT i, nSet;
630 pDCData pHps;
631
632 pHps = (pDCData)OSLibGpiQueryDCData(hdc);
633 if(pHps == NULL) {
634 DebugInt3();
635 SetLastError(ERROR_INVALID_HANDLE_W);
636 return 0;
637 }
638
639 dprintf(("%ls, %d, %d, 0x%08lx\n", lpString, uCount, nMaxExtent, dwFlags));
640
641 dprintf(("lStructSize=%ld, lpOutString=%p, lpOrder=%p, lpDx=%p, lpCaretPos=%p, lpClass=%p, lpGlyphs=%p, nGlyphs=%u, nMaxFit=%d\n",
642 lpResults->lStructSize, lpResults->lpOutString, lpResults->lpOrder,
643 lpResults->lpDx, lpResults->lpCaretPos, lpResults->lpClass,
644 lpResults->lpGlyphs, lpResults->nGlyphs, lpResults->nMaxFit));
645
646 if(dwFlags&(~0)) dprintf(("unsupported flags 0x%08lx\n", dwFlags));
647 if(lpResults->lpCaretPos) dprintf(("caret positions not implemented\n"));
648 if(lpResults->lpClass) dprintf(("classes not implemented\n"));
649
650 nSet = (UINT)uCount;
651 if(nSet > lpResults->nGlyphs)
652 nSet = lpResults->nGlyphs;
653
654 /* return number of initialized fields */
655 lpResults->nGlyphs = nSet;
656 lpResults->nMaxFit = nSet;
657
658 /* Treat the case where no special handling was requested in a fastpath way */
659 /* copy will do if the GCP_REORDER flag is not set */
660 if(lpResults->lpOutString)
661 strncpyW( lpResults->lpOutString, lpString, nSet );
662
663 if(lpResults->lpOrder)
664 for(i = 0; i < nSet; i++)
665 lpResults->lpOrder[i] = i;
666
667 // All FreeType calls should be wrapped for saving FS
668 if(pfnFt2GetCharacterPlacementW) {
669 sel = RestoreOS2FS();
670 ret = pfnFt2GetCharacterPlacementW((HPS)hdc, lpString, nSet, nMaxExtent, lpResults, dwFlags);
671 SetFS(sel);
672 if(ret || (ret == 0 && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
673 {
674#ifdef DEBUG
675 if(ret && lpResults->lpDx) {
676 for (i = 0; i < nSet; i++)
677 {
678 dprintf(("%c pWidthArray[%d] = %d", lpString[i], i, lpResults->lpDx[i]));
679 }
680 }
681#endif
682 if(pHps && pHps->isPrinter && pHps->hdc)
683 {//scale for printer dcs
684 LONG alArray[2];
685
686 if(OSLibDevQueryCaps(pHps, OSLIB_CAPS_HORIZONTAL_RESOLUTION, 2, &alArray[0]) &&
687 alArray[0] != alArray[1])
688 {
689 dprintf(("Different hor/vert resolutions (%d,%d)", alArray[0], alArray[1]));
690 if(lpResults->lpDx) {
691 for (i = 0; i < nSet; i++)
692 {
693 lpResults->lpDx[i] = lpResults->lpDx[i] * alArray[0] / alArray[1];
694 }
695 }
696 ULONG x = (ret & 0xffff);
697 x = x * alArray[0] / alArray[1];
698 ret &= ~0xffff;
699 ret |= (x & 0xffff);
700 }
701 }
702 return ret;
703 }
704 }
705 //fallback method
706
707 /* FIXME: Will use the placement chars */
708 if (lpResults->lpDx)
709 {
710 Ft2GetStringWidthW(hdc, (LPWSTR)lpString, nSet, lpResults->lpDx);
711 }
712
713 if(lpResults->lpGlyphs)
714 GetGlyphIndicesW(hdc, lpString, nSet, lpResults->lpGlyphs, 0);
715
716 if (GetTextExtentPoint32W(hdc, lpString, uCount, &size))
717 ret = MAKELONG(size.cx, size.cy);
718 else ret = 0;
719
720 return ret;
721}
722//******************************************************************************
723//******************************************************************************
Note: See TracBrowser for help on using the repository browser.