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 |
|
---|
35 | CFT2Module FT2Module;
|
---|
36 |
|
---|
37 | static BOOL fFT2LIBIntegration = FALSE;
|
---|
38 |
|
---|
39 | //******************************************************************************
|
---|
40 | //******************************************************************************
|
---|
41 | void WIN32API SetFreeTypeIntegration(BOOL fEnabled)
|
---|
42 | {
|
---|
43 | fFT2LIBIntegration = fEnabled;
|
---|
44 |
|
---|
45 | FT2Module.init();
|
---|
46 | }
|
---|
47 | //******************************************************************************
|
---|
48 | // Constructor
|
---|
49 | //******************************************************************************
|
---|
50 | CFT2Module::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 | //******************************************************************************
|
---|
61 | void 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 | pfnFt2GetTextExtentW = (PFN_FT2GETTEXTEXTENTW)QueryProcAddress("Ft2GetTextExtentW");
|
---|
99 | if(!pfnFt2GetTextExtentW) dprintf(("Ft2GetTextExtentW not found!!"));
|
---|
100 |
|
---|
101 | pfnFt2CharStringPosAtA = (PFN_FT2CHARSTRINGPOSATA)QueryProcAddress("Ft2CharStringPosAtA");
|
---|
102 | if(!pfnFt2CharStringPosAtA) dprintf(("Ft2CharStringPosAtA not found!!"));
|
---|
103 | pfnFt2CharStringPosAtW = (PFN_FT2CHARSTRINGPOSATW)QueryProcAddress("Ft2CharStringPosAtW");
|
---|
104 | if(!pfnFt2CharStringPosAtW) dprintf(("Ft2CharStringPosAtW not found!!"));
|
---|
105 |
|
---|
106 | pfnFt2QueryFontType = (PFN_FT2QUERYFONTTYPE)QueryProcAddress("Ft2QueryFontType");
|
---|
107 | if(!pfnFt2QueryFontType) dprintf(("Ft2QueryFontType not found!!"));
|
---|
108 |
|
---|
109 | pfnFt2QueryStringWidthW = (PFN_FT2QUERYSTRINGWIDTHW)QueryProcAddress("Ft2QueryStringWidthW");
|
---|
110 | if(!pfnFt2QueryStringWidthW) dprintf(("Ft2QueryStringWidthW not found!!"));
|
---|
111 |
|
---|
112 | // Do not register functions for Mozilla plugins
|
---|
113 | if(IsDummyExeLoaded() == FALSE)
|
---|
114 | {
|
---|
115 | pfnFt2RegisterUconv = (PFN_FT2REGISTERUCONV)QueryProcAddress("Ft2RegisterUconv");
|
---|
116 | if(pfnFt2RegisterUconv)
|
---|
117 | pfnFt2RegisterUconv(WideCharToMultiByte, MultiByteToWideChar);
|
---|
118 | else dprintf(("Ft2QueryFontType not found!!"));
|
---|
119 | }
|
---|
120 | dprintf(("Freetype2 library enabled state %d",bEnabled));
|
---|
121 | }
|
---|
122 | return;
|
---|
123 |
|
---|
124 | failure:
|
---|
125 | if(pfnFt2RegisterUconv)
|
---|
126 | pfnFt2RegisterUconv(NULL, NULL);
|
---|
127 | if(pfnFt2EnableFontEngine)
|
---|
128 | pfnFt2EnableFontEngine(FALSE);
|
---|
129 |
|
---|
130 | pfnGetGlyphIndices = NULL;
|
---|
131 | pfnFt2GetTextExtentW = NULL;
|
---|
132 | pfnFt2EnableFontEngine = NULL;
|
---|
133 | pfnFt2GetGlyphOutline = NULL;
|
---|
134 | pfnFt2CharStringPosAtA = NULL;
|
---|
135 | pfnFt2CharStringPosAtW = NULL;
|
---|
136 | pfnFt2GetFontData = NULL;
|
---|
137 | pfnFt2RegisterUconv = NULL;
|
---|
138 | pfnFt2QueryStringWidthW= NULL;
|
---|
139 | pfnFt2GetVersion = NULL;
|
---|
140 | bEnabled = FALSE;
|
---|
141 | if (hftModule) {
|
---|
142 | DosFreeModule(hftModule);
|
---|
143 | hftModule = 0;
|
---|
144 | }
|
---|
145 | return;
|
---|
146 | }
|
---|
147 | //******************************************************************************
|
---|
148 | // Destructor
|
---|
149 | //******************************************************************************
|
---|
150 | CFT2Module::~CFT2Module()
|
---|
151 | {
|
---|
152 | if (hftModule)
|
---|
153 | DosFreeModule(hftModule);
|
---|
154 |
|
---|
155 | bEnabled = FALSE;
|
---|
156 | }
|
---|
157 | //******************************************************************************
|
---|
158 | //******************************************************************************
|
---|
159 | PFN CFT2Module::QueryProcAddress(int ordinal)
|
---|
160 | {
|
---|
161 | APIRET rc;
|
---|
162 | PFN ModuleAddr;
|
---|
163 |
|
---|
164 | rc = DosQueryProcAddr(hftModule, ordinal, NULL, &ModuleAddr);
|
---|
165 | if (rc != 0) {
|
---|
166 | dprintf(("FreeType2 QueryProcAddr error: return code = %u\n", rc));
|
---|
167 | return 0;
|
---|
168 | }
|
---|
169 | return ModuleAddr;
|
---|
170 | }
|
---|
171 | //******************************************************************************
|
---|
172 | //******************************************************************************
|
---|
173 | PFN CFT2Module::QueryProcAddress(char * procname)
|
---|
174 | {
|
---|
175 | APIRET rc;
|
---|
176 | PFN ModuleAddr;
|
---|
177 |
|
---|
178 | rc = DosQueryProcAddr(hftModule, 0, procname, &ModuleAddr);
|
---|
179 | if (rc != 0) {
|
---|
180 | dprintf(("FreeType2 QueryProcAddr error: return code = %u\n", rc));
|
---|
181 | return 0;
|
---|
182 | }
|
---|
183 | return ModuleAddr;
|
---|
184 | }
|
---|
185 | //******************************************************************************
|
---|
186 | //******************************************************************************
|
---|
187 | DWORD CFT2Module::Ft2GetGlyphIndices(HPS hps, LPCWSTR str, int c, LPWORD pgi, DWORD fl)
|
---|
188 | {
|
---|
189 | //no fallback
|
---|
190 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED_W);
|
---|
191 | return GDI_ERROR;
|
---|
192 | }
|
---|
193 | //******************************************************************************
|
---|
194 | //******************************************************************************
|
---|
195 | DWORD CFT2Module::Ft2GetGlyphOutline(HPS hps, UINT glyph, UINT format, LPGLYPHMETRICS lpgm, DWORD buflen, LPVOID buf, const MAT2* lpmat)
|
---|
196 | {
|
---|
197 | //no fallback
|
---|
198 | SetLastError(ERROR_INVALID_FUNCTION_W);
|
---|
199 | return GDI_ERROR;
|
---|
200 | }
|
---|
201 | //******************************************************************************
|
---|
202 | //
|
---|
203 | // This is basically the same as Ft2QueryTextBoxW, but it behaves as the Win32
|
---|
204 | // API GetTextExtent (which ignores character attributes and underhang/overhang)
|
---|
205 | //
|
---|
206 | // The fallback case is not accurate!! (but the same as our old code)
|
---|
207 | //
|
---|
208 | //******************************************************************************
|
---|
209 | BOOL CFT2Module::Ft2GetTextExtentW(HPS hps, LONG lCount1,LPCWSTR pchString, PPOINTLOS2 pwidthHeight)
|
---|
210 | {
|
---|
211 | DWORD ret;
|
---|
212 | USHORT sel;
|
---|
213 | POINTLOS2 aptlPoints[TXTBOX_COUNT];
|
---|
214 |
|
---|
215 | // All FreeType calls should be wrapped for saving FS
|
---|
216 | if(pfnFt2GetTextExtentW)
|
---|
217 | {
|
---|
218 | sel = RestoreOS2FS();
|
---|
219 | ret = pfnFt2GetTextExtentW(hps, lCount1, pchString, TXTBOX_COUNT, aptlPoints);
|
---|
220 | SetFS(sel);
|
---|
221 | if(ret || (ret == FALSE && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
|
---|
222 | {
|
---|
223 | calcDimensions(aptlPoints, pwidthHeight);
|
---|
224 | return ret;
|
---|
225 | }
|
---|
226 | }
|
---|
227 | //else fall back to GPI
|
---|
228 | INT lenA;
|
---|
229 | LPSTR strA;
|
---|
230 | POINTLOS2 start = { 0, 0 };
|
---|
231 | PPOINTLOS2 pplos2;
|
---|
232 | INT cx;
|
---|
233 | INT cy;
|
---|
234 |
|
---|
235 | pDCData pHps = (pDCData)OSLibGpiQueryDCData(hps);
|
---|
236 |
|
---|
237 | lenA = WideCharToMultiByte( CP_ACP, 0, pchString, lCount1, 0, 0, 0, 0 );
|
---|
238 | strA = ( LPSTR )malloc( lenA + 1 );
|
---|
239 | lstrcpynWtoA( strA, pchString, lenA + 1 );
|
---|
240 | pplos2 = ( PPOINTLOS2 )malloc(( lenA + 1 ) * sizeof( POINTLOS2 ));
|
---|
241 |
|
---|
242 | ret = OSLibGpiQueryCharStringPosAt( pHps, &start, 0, lenA, strA, NULL, pplos2 );
|
---|
243 | if( ret )
|
---|
244 | {
|
---|
245 | TEXTMETRICW tmW;
|
---|
246 |
|
---|
247 | cx = labs( pplos2[ lenA ].x - pplos2[ 0 ].x );
|
---|
248 | cy = labs( pplos2[ lenA ].y - pplos2[ 0 ].y );
|
---|
249 |
|
---|
250 | aptlPoints[ TXTBOX_BOTTOMLEFT ].x = 0;
|
---|
251 | aptlPoints[ TXTBOX_BOTTOMLEFT ].y = 0;
|
---|
252 | aptlPoints[ TXTBOX_BOTTOMRIGHT ].x = cx;
|
---|
253 | aptlPoints[ TXTBOX_BOTTOMRIGHT ].y = cy;
|
---|
254 | aptlPoints[ TXTBOX_TOPLEFT ].x = 0;
|
---|
255 | aptlPoints[ TXTBOX_TOPLEFT ].y = 0;
|
---|
256 | aptlPoints[ TXTBOX_TOPRIGHT ].x = cx;
|
---|
257 | aptlPoints[ TXTBOX_TOPRIGHT ].y = cy;
|
---|
258 | aptlPoints[ TXTBOX_CONCAT ].x = cx;
|
---|
259 | aptlPoints[ TXTBOX_CONCAT ].y = cy;
|
---|
260 |
|
---|
261 | calcDimensions(aptlPoints, pwidthHeight);
|
---|
262 |
|
---|
263 | DecreaseLogCount();
|
---|
264 | if(GetTextMetricsW( hps, &tmW ) == TRUE)
|
---|
265 | {
|
---|
266 | pwidthHeight->y = tmW.tmHeight; // *Must* use the maximum height of the font
|
---|
267 | }
|
---|
268 | #ifdef DEBUG
|
---|
269 | else DebugInt3();
|
---|
270 | #endif
|
---|
271 | IncreaseLogCount();
|
---|
272 | }
|
---|
273 |
|
---|
274 | free( pplos2 );
|
---|
275 | free( strA );
|
---|
276 |
|
---|
277 | return ret;
|
---|
278 | }
|
---|
279 | //******************************************************************************
|
---|
280 | //******************************************************************************
|
---|
281 | BOOL CFT2Module::Ft2CharStringPosAtA(HPS hps,PPOINTLOS2 ptl,PRECTLOS2 rct,ULONG flOptions,LONG lCount,LPCSTR pchString,CONST INT *alAdx, DWORD fuWin32Options)
|
---|
282 | {
|
---|
283 | DWORD ret;
|
---|
284 | USHORT sel;
|
---|
285 |
|
---|
286 | // All FreeType calls should be wrapped for saving FS
|
---|
287 | if(pfnFt2CharStringPosAtA) {
|
---|
288 | sel = RestoreOS2FS();
|
---|
289 | ret = pfnFt2CharStringPosAtA(hps, ptl,rct,flOptions,lCount,pchString,alAdx, fuWin32Options);
|
---|
290 | SetFS(sel);
|
---|
291 | if(ret || (ret == FALSE && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
|
---|
292 | return ret;
|
---|
293 | }
|
---|
294 | //else fall back to GPI
|
---|
295 | //NOTE: We don't support fuWin32Options in the fallback case
|
---|
296 | pDCData pHps = (pDCData)OSLibGpiQueryDCData(hps);
|
---|
297 | return OSLibGpiCharStringPosAt(pHps,ptl,rct,flOptions,lCount,pchString,alAdx);
|
---|
298 | }
|
---|
299 | //******************************************************************************
|
---|
300 | //******************************************************************************
|
---|
301 | BOOL CFT2Module::Ft2CharStringPosAtW(HPS hps, PPOINTLOS2 ptl,PRECTLOS2 rct,ULONG flOptions,LONG lCount,LPCWSTR pchString,CONST INT *alAdx, DWORD fuWin32Options)
|
---|
302 | {
|
---|
303 | DWORD ret;
|
---|
304 | USHORT sel;
|
---|
305 |
|
---|
306 | // All FreeType calls should be wrapped for saving FS
|
---|
307 | if(pfnFt2CharStringPosAtW) {
|
---|
308 | sel = RestoreOS2FS();
|
---|
309 | ret = pfnFt2CharStringPosAtW(hps, ptl,rct,flOptions,lCount,pchString,alAdx, fuWin32Options);
|
---|
310 | SetFS(sel);
|
---|
311 | if(ret || (ret == FALSE && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
|
---|
312 | return ret;
|
---|
313 | }
|
---|
314 | //else fall back to GPI
|
---|
315 | //NOTE: We don't support fuWin32Options in the fallback case
|
---|
316 | int len;
|
---|
317 | LPSTR astring;
|
---|
318 | LPINT lpDx = NULL;
|
---|
319 |
|
---|
320 | pDCData pHps = (pDCData)OSLibGpiQueryDCData(hps);
|
---|
321 |
|
---|
322 | len = WideCharToMultiByte( CP_ACP, 0, pchString, lCount, 0, 0, NULL, NULL );
|
---|
323 | astring = (char *)malloc( len + 1 );
|
---|
324 | lstrcpynWtoA(astring, pchString, len + 1 );
|
---|
325 |
|
---|
326 | if( IsDBCSEnv() && alAdx )
|
---|
327 | {
|
---|
328 | int i, j;
|
---|
329 |
|
---|
330 | lpDx = ( LPINT )malloc( len * sizeof( INT ));
|
---|
331 | for( i = j = 0; i < len; i++, j++ )
|
---|
332 | {
|
---|
333 | lpDx[ i ] = alAdx[ j ];
|
---|
334 | if( IsDBCSLeadByte( astring[ i ]))
|
---|
335 | lpDx[ ++i ] = 0;
|
---|
336 | }
|
---|
337 |
|
---|
338 | alAdx = ( CONST INT * )lpDx;
|
---|
339 | }
|
---|
340 |
|
---|
341 | ret = OSLibGpiCharStringPosAt(pHps,ptl,rct,flOptions,len,astring,alAdx);
|
---|
342 |
|
---|
343 | if( lpDx )
|
---|
344 | free( lpDx );
|
---|
345 |
|
---|
346 | free(astring);
|
---|
347 |
|
---|
348 | return ret;
|
---|
349 | }
|
---|
350 | //******************************************************************************
|
---|
351 | //******************************************************************************
|
---|
352 | DWORD CFT2Module::Ft2GetFontData(HPS hps, DWORD dwTable, DWORD dwOffset,
|
---|
353 | LPVOID lpvBuffer, DWORD cbData)
|
---|
354 | {
|
---|
355 | //no fallback
|
---|
356 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED_W);
|
---|
357 | return(GDI_ERROR);
|
---|
358 | }
|
---|
359 | //******************************************************************************
|
---|
360 | // Query the font type current selected into the presentation space, or,
|
---|
361 | // when hps == NULL, query the type of the font with the specified name
|
---|
362 | //******************************************************************************
|
---|
363 | DWORD CFT2Module::Ft2QueryFontType(HPS hps, LPCSTR lpszFontName)
|
---|
364 | {
|
---|
365 | DWORD ret;
|
---|
366 | USHORT sel;
|
---|
367 |
|
---|
368 | // All FreeType calls should be wrapped for saving FS
|
---|
369 | if(pfnFt2QueryFontType) {
|
---|
370 | sel = RestoreOS2FS();
|
---|
371 | ret = pfnFt2QueryFontType(hps, lpszFontName);
|
---|
372 | SetFS(sel);
|
---|
373 | if(ret || (ret == GDI_ERROR && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
|
---|
374 | return ret;
|
---|
375 | }
|
---|
376 | //no fallback
|
---|
377 | return FT2_FONTTYPE_UNKNOWN;
|
---|
378 | }
|
---|
379 | //******************************************************************************
|
---|
380 | //******************************************************************************
|
---|
381 | BOOL CFT2Module::Ft2GetStringWidthW(HDC hdc, LPWSTR lpszString, UINT cbString, PINT pWidthArray)
|
---|
382 | {
|
---|
383 | DWORD ret;
|
---|
384 | USHORT sel;
|
---|
385 | pDCData pHps;
|
---|
386 |
|
---|
387 | pHps = (pDCData)OSLibGpiQueryDCData(hdc);
|
---|
388 | if(pHps == NULL) {
|
---|
389 | DebugInt3();
|
---|
390 | SetLastError(ERROR_INVALID_HANDLE_W);
|
---|
391 | return 0;
|
---|
392 | }
|
---|
393 |
|
---|
394 | // All FreeType calls should be wrapped for saving FS
|
---|
395 | if(pfnFt2QueryStringWidthW) {
|
---|
396 | sel = RestoreOS2FS();
|
---|
397 | ret = pfnFt2QueryStringWidthW((HPS)hdc, lpszString, cbString, (LONG *)pWidthArray);
|
---|
398 | SetFS(sel);
|
---|
399 | if(ret || (ret == GDI_ERROR && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
|
---|
400 | {
|
---|
401 | if(pHps && pHps->isPrinter && pHps->hdc)
|
---|
402 | {//scale for printer dcs
|
---|
403 | LONG alArray[2];
|
---|
404 |
|
---|
405 | if(OSLibDevQueryCaps(pHps, OSLIB_CAPS_HORIZONTAL_RESOLUTION, 2, &alArray[0]) &&
|
---|
406 | alArray[0] != alArray[1])
|
---|
407 | {
|
---|
408 | dprintf(("Different hor/vert resolutions (%d,%d)", alArray[0], alArray[1]));
|
---|
409 | for (int i = 0; i < cbString; i++)
|
---|
410 | {
|
---|
411 | pWidthArray[i] = pWidthArray[i] * alArray[0] / alArray[1];
|
---|
412 | }
|
---|
413 | }
|
---|
414 | }
|
---|
415 | return ret;
|
---|
416 | }
|
---|
417 | }
|
---|
418 | //fallback method
|
---|
419 | int c, i;
|
---|
420 | for (i = 0; i < cbString; i++)
|
---|
421 | {
|
---|
422 | if (GetCharWidth32W(hdc, lpszString[i], lpszString[i], (LPINT)&c)) {
|
---|
423 | dprintf(("%c pWidthArray[%d] = %d", lpszString[i], i, c));
|
---|
424 | pWidthArray[i]= c;
|
---|
425 | }
|
---|
426 | else {
|
---|
427 | dprintf(("WARNING: GetCharWidth32W failed for %c!!!", lpszString[i]));
|
---|
428 | pWidthArray[i] = 0;
|
---|
429 | }
|
---|
430 | }
|
---|
431 | return TRUE;
|
---|
432 | }
|
---|
433 | /*****************************************************************************
|
---|
434 | * Name : DWORD GetCharacterPlacementW
|
---|
435 | * Purpose : The GetCharacterPlacementW function retrieves information about
|
---|
436 | * a character string, such as character widths, caret positioning,
|
---|
437 | * ordering within the string, and glyph rendering. The type of
|
---|
438 | * information returned depends on the dwFlags parameter and is
|
---|
439 | * based on the currently selected font in the given display context.
|
---|
440 | * The function copies the information to the specified GCP_RESULTSW
|
---|
441 | * structure or to one or more arrays specified by the structure.
|
---|
442 | * Parameters: HDC hdc handle to device context
|
---|
443 | * LPCSTR lpString pointer to string
|
---|
444 | * int nCount number of characters in string
|
---|
445 | * int nMaxExtent maximum extent for displayed string
|
---|
446 | * GCP_RESULTSW *lpResults pointer to buffer for placement result
|
---|
447 | * DWORD dwFlags placement flags
|
---|
448 | * Variables :
|
---|
449 | * Result :
|
---|
450 | * Remark :
|
---|
451 | * Status : Partly working
|
---|
452 | *
|
---|
453 | * Author : Borrowed Rewind Code
|
---|
454 | *****************************************************************************/
|
---|
455 | DWORD CFT2Module::Ft2GetCharacterPlacementW(HDC hdc,
|
---|
456 | LPCWSTR lpString,
|
---|
457 | int uCount,
|
---|
458 | int nMaxExtent,
|
---|
459 | GCP_RESULTSW *lpResults,
|
---|
460 | DWORD dwFlags)
|
---|
461 | {
|
---|
462 | DWORD ret;
|
---|
463 | USHORT sel;
|
---|
464 | SIZE size;
|
---|
465 | UINT i, nSet;
|
---|
466 | pDCData pHps;
|
---|
467 |
|
---|
468 | pHps = (pDCData)OSLibGpiQueryDCData(hdc);
|
---|
469 | if(pHps == NULL) {
|
---|
470 | DebugInt3();
|
---|
471 | SetLastError(ERROR_INVALID_HANDLE_W);
|
---|
472 | return 0;
|
---|
473 | }
|
---|
474 |
|
---|
475 | dprintf(("%ls, %d, %d, 0x%08lx\n", lpString, uCount, nMaxExtent, dwFlags));
|
---|
476 |
|
---|
477 | dprintf(("lStructSize=%ld, lpOutString=%p, lpOrder=%p, lpDx=%p, lpCaretPos=%p, lpClass=%p, lpGlyphs=%p, nGlyphs=%u, nMaxFit=%d\n",
|
---|
478 | lpResults->lStructSize, lpResults->lpOutString, lpResults->lpOrder,
|
---|
479 | lpResults->lpDx, lpResults->lpCaretPos, lpResults->lpClass,
|
---|
480 | lpResults->lpGlyphs, lpResults->nGlyphs, lpResults->nMaxFit));
|
---|
481 |
|
---|
482 | if(dwFlags&(~0)) dprintf(("unsupported flags 0x%08lx\n", dwFlags));
|
---|
483 | if(lpResults->lpCaretPos) dprintf(("caret positions not implemented\n"));
|
---|
484 | if(lpResults->lpClass) dprintf(("classes not implemented\n"));
|
---|
485 |
|
---|
486 | nSet = (UINT)uCount;
|
---|
487 | if(nSet > lpResults->nGlyphs)
|
---|
488 | nSet = lpResults->nGlyphs;
|
---|
489 |
|
---|
490 | /* return number of initialized fields */
|
---|
491 | lpResults->nGlyphs = nSet;
|
---|
492 | lpResults->nMaxFit = nSet;
|
---|
493 |
|
---|
494 | /* Treat the case where no special handling was requested in a fastpath way */
|
---|
495 | /* copy will do if the GCP_REORDER flag is not set */
|
---|
496 | if(lpResults->lpOutString)
|
---|
497 | strncpyW( lpResults->lpOutString, lpString, nSet );
|
---|
498 |
|
---|
499 | if(lpResults->lpOrder)
|
---|
500 | for(i = 0; i < nSet; i++)
|
---|
501 | lpResults->lpOrder[i] = i;
|
---|
502 |
|
---|
503 | //fallback method
|
---|
504 |
|
---|
505 | /* FIXME: Will use the placement chars */
|
---|
506 | if (lpResults->lpDx)
|
---|
507 | {
|
---|
508 | Ft2GetStringWidthW(hdc, (LPWSTR)lpString, nSet, lpResults->lpDx);
|
---|
509 | }
|
---|
510 |
|
---|
511 | if(lpResults->lpGlyphs)
|
---|
512 | GetGlyphIndicesW(hdc, lpString, nSet, lpResults->lpGlyphs, 0);
|
---|
513 |
|
---|
514 | if (GetTextExtentPoint32W(hdc, lpString, uCount, &size))
|
---|
515 | ret = MAKELONG(size.cx, size.cy);
|
---|
516 | else ret = 0;
|
---|
517 |
|
---|
518 | return ret;
|
---|
519 | }
|
---|
520 | //******************************************************************************
|
---|
521 | //******************************************************************************
|
---|