| 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 |
|
|---|
| 319 | pDCData pHps = (pDCData)OSLibGpiQueryDCData(hps);
|
|---|
| 320 |
|
|---|
| 321 | len = WideCharToMultiByte( CP_ACP, 0, pchString, lCount, 0, 0, NULL, NULL );
|
|---|
| 322 | astring = (char *)malloc( len + 1 );
|
|---|
| 323 | lstrcpynWtoA(astring, pchString, len + 1 );
|
|---|
| 324 |
|
|---|
| 325 | ret = OSLibGpiCharStringPosAt(pHps,ptl,rct,flOptions,len,astring,alAdx);
|
|---|
| 326 | free(astring);
|
|---|
| 327 | return ret;
|
|---|
| 328 | }
|
|---|
| 329 | //******************************************************************************
|
|---|
| 330 | //******************************************************************************
|
|---|
| 331 | DWORD CFT2Module::Ft2GetFontData(HPS hps, DWORD dwTable, DWORD dwOffset,
|
|---|
| 332 | LPVOID lpvBuffer, DWORD cbData)
|
|---|
| 333 | {
|
|---|
| 334 | //no fallback
|
|---|
| 335 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED_W);
|
|---|
| 336 | return(GDI_ERROR);
|
|---|
| 337 | }
|
|---|
| 338 | //******************************************************************************
|
|---|
| 339 | // Query the font type current selected into the presentation space, or,
|
|---|
| 340 | // when hps == NULL, query the type of the font with the specified name
|
|---|
| 341 | //******************************************************************************
|
|---|
| 342 | DWORD CFT2Module::Ft2QueryFontType(HPS hps, LPCSTR lpszFontName)
|
|---|
| 343 | {
|
|---|
| 344 | DWORD ret;
|
|---|
| 345 | USHORT sel;
|
|---|
| 346 |
|
|---|
| 347 | // All FreeType calls should be wrapped for saving FS
|
|---|
| 348 | if(pfnFt2QueryFontType) {
|
|---|
| 349 | sel = RestoreOS2FS();
|
|---|
| 350 | ret = pfnFt2QueryFontType(hps, lpszFontName);
|
|---|
| 351 | SetFS(sel);
|
|---|
| 352 | if(ret || (ret == GDI_ERROR && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
|
|---|
| 353 | return ret;
|
|---|
| 354 | }
|
|---|
| 355 | //no fallback
|
|---|
| 356 | return FT2_FONTTYPE_UNKNOWN;
|
|---|
| 357 | }
|
|---|
| 358 | //******************************************************************************
|
|---|
| 359 | //******************************************************************************
|
|---|
| 360 | BOOL CFT2Module::Ft2GetStringWidthW(HDC hdc, LPWSTR lpszString, UINT cbString, PINT pWidthArray)
|
|---|
| 361 | {
|
|---|
| 362 | DWORD ret;
|
|---|
| 363 | USHORT sel;
|
|---|
| 364 | pDCData pHps;
|
|---|
| 365 |
|
|---|
| 366 | pHps = (pDCData)OSLibGpiQueryDCData(hdc);
|
|---|
| 367 | if(pHps == NULL) {
|
|---|
| 368 | DebugInt3();
|
|---|
| 369 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 370 | return 0;
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | // All FreeType calls should be wrapped for saving FS
|
|---|
| 374 | if(pfnFt2QueryStringWidthW) {
|
|---|
| 375 | sel = RestoreOS2FS();
|
|---|
| 376 | ret = pfnFt2QueryStringWidthW((HPS)hdc, lpszString, cbString, (LONG *)pWidthArray);
|
|---|
| 377 | SetFS(sel);
|
|---|
| 378 | if(ret || (ret == GDI_ERROR && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
|
|---|
| 379 | {
|
|---|
| 380 | if(pHps && pHps->isPrinter && pHps->hdc)
|
|---|
| 381 | {//scale for printer dcs
|
|---|
| 382 | LONG alArray[2];
|
|---|
| 383 |
|
|---|
| 384 | if(OSLibDevQueryCaps(pHps, OSLIB_CAPS_HORIZONTAL_RESOLUTION, 2, &alArray[0]) &&
|
|---|
| 385 | alArray[0] != alArray[1])
|
|---|
| 386 | {
|
|---|
| 387 | dprintf(("Different hor/vert resolutions (%d,%d)", alArray[0], alArray[1]));
|
|---|
| 388 | for (int i = 0; i < cbString; i++)
|
|---|
| 389 | {
|
|---|
| 390 | pWidthArray[i] = pWidthArray[i] * alArray[0] / alArray[1];
|
|---|
| 391 | }
|
|---|
| 392 | }
|
|---|
| 393 | }
|
|---|
| 394 | return ret;
|
|---|
| 395 | }
|
|---|
| 396 | }
|
|---|
| 397 | //fallback method
|
|---|
| 398 | int c, i;
|
|---|
| 399 | for (i = 0; i < cbString; i++)
|
|---|
| 400 | {
|
|---|
| 401 | if (GetCharWidth32W(hdc, lpszString[i], lpszString[i], (LPINT)&c)) {
|
|---|
| 402 | dprintf(("%c pWidthArray[%d] = %d", lpszString[i], i, c));
|
|---|
| 403 | pWidthArray[i]= c;
|
|---|
| 404 | }
|
|---|
| 405 | else {
|
|---|
| 406 | dprintf(("WARNING: GetCharWidth32W failed for %c!!!", lpszString[i]));
|
|---|
| 407 | pWidthArray[i] = 0;
|
|---|
| 408 | }
|
|---|
| 409 | }
|
|---|
| 410 | return TRUE;
|
|---|
| 411 | }
|
|---|
| 412 | /*****************************************************************************
|
|---|
| 413 | * Name : DWORD GetCharacterPlacementW
|
|---|
| 414 | * Purpose : The GetCharacterPlacementW function retrieves information about
|
|---|
| 415 | * a character string, such as character widths, caret positioning,
|
|---|
| 416 | * ordering within the string, and glyph rendering. The type of
|
|---|
| 417 | * information returned depends on the dwFlags parameter and is
|
|---|
| 418 | * based on the currently selected font in the given display context.
|
|---|
| 419 | * The function copies the information to the specified GCP_RESULTSW
|
|---|
| 420 | * structure or to one or more arrays specified by the structure.
|
|---|
| 421 | * Parameters: HDC hdc handle to device context
|
|---|
| 422 | * LPCSTR lpString pointer to string
|
|---|
| 423 | * int nCount number of characters in string
|
|---|
| 424 | * int nMaxExtent maximum extent for displayed string
|
|---|
| 425 | * GCP_RESULTSW *lpResults pointer to buffer for placement result
|
|---|
| 426 | * DWORD dwFlags placement flags
|
|---|
| 427 | * Variables :
|
|---|
| 428 | * Result :
|
|---|
| 429 | * Remark :
|
|---|
| 430 | * Status : Partly working
|
|---|
| 431 | *
|
|---|
| 432 | * Author : Borrowed Rewind Code
|
|---|
| 433 | *****************************************************************************/
|
|---|
| 434 | DWORD CFT2Module::Ft2GetCharacterPlacementW(HDC hdc,
|
|---|
| 435 | LPCWSTR lpString,
|
|---|
| 436 | int uCount,
|
|---|
| 437 | int nMaxExtent,
|
|---|
| 438 | GCP_RESULTSW *lpResults,
|
|---|
| 439 | DWORD dwFlags)
|
|---|
| 440 | {
|
|---|
| 441 | DWORD ret;
|
|---|
| 442 | USHORT sel;
|
|---|
| 443 | SIZE size;
|
|---|
| 444 | UINT i, nSet;
|
|---|
| 445 | pDCData pHps;
|
|---|
| 446 |
|
|---|
| 447 | pHps = (pDCData)OSLibGpiQueryDCData(hdc);
|
|---|
| 448 | if(pHps == NULL) {
|
|---|
| 449 | DebugInt3();
|
|---|
| 450 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 451 | return 0;
|
|---|
| 452 | }
|
|---|
| 453 |
|
|---|
| 454 | dprintf(("%ls, %d, %d, 0x%08lx\n", lpString, uCount, nMaxExtent, dwFlags));
|
|---|
| 455 |
|
|---|
| 456 | dprintf(("lStructSize=%ld, lpOutString=%p, lpOrder=%p, lpDx=%p, lpCaretPos=%p, lpClass=%p, lpGlyphs=%p, nGlyphs=%u, nMaxFit=%d\n",
|
|---|
| 457 | lpResults->lStructSize, lpResults->lpOutString, lpResults->lpOrder,
|
|---|
| 458 | lpResults->lpDx, lpResults->lpCaretPos, lpResults->lpClass,
|
|---|
| 459 | lpResults->lpGlyphs, lpResults->nGlyphs, lpResults->nMaxFit));
|
|---|
| 460 |
|
|---|
| 461 | if(dwFlags&(~0)) dprintf(("unsupported flags 0x%08lx\n", dwFlags));
|
|---|
| 462 | if(lpResults->lpCaretPos) dprintf(("caret positions not implemented\n"));
|
|---|
| 463 | if(lpResults->lpClass) dprintf(("classes not implemented\n"));
|
|---|
| 464 |
|
|---|
| 465 | nSet = (UINT)uCount;
|
|---|
| 466 | if(nSet > lpResults->nGlyphs)
|
|---|
| 467 | nSet = lpResults->nGlyphs;
|
|---|
| 468 |
|
|---|
| 469 | /* return number of initialized fields */
|
|---|
| 470 | lpResults->nGlyphs = nSet;
|
|---|
| 471 | lpResults->nMaxFit = nSet;
|
|---|
| 472 |
|
|---|
| 473 | /* Treat the case where no special handling was requested in a fastpath way */
|
|---|
| 474 | /* copy will do if the GCP_REORDER flag is not set */
|
|---|
| 475 | if(lpResults->lpOutString)
|
|---|
| 476 | strncpyW( lpResults->lpOutString, lpString, nSet );
|
|---|
| 477 |
|
|---|
| 478 | if(lpResults->lpOrder)
|
|---|
| 479 | for(i = 0; i < nSet; i++)
|
|---|
| 480 | lpResults->lpOrder[i] = i;
|
|---|
| 481 |
|
|---|
| 482 | //fallback method
|
|---|
| 483 |
|
|---|
| 484 | /* FIXME: Will use the placement chars */
|
|---|
| 485 | if (lpResults->lpDx)
|
|---|
| 486 | {
|
|---|
| 487 | Ft2GetStringWidthW(hdc, (LPWSTR)lpString, nSet, lpResults->lpDx);
|
|---|
| 488 | }
|
|---|
| 489 |
|
|---|
| 490 | if(lpResults->lpGlyphs)
|
|---|
| 491 | GetGlyphIndicesW(hdc, lpString, nSet, lpResults->lpGlyphs, 0);
|
|---|
| 492 |
|
|---|
| 493 | if (GetTextExtentPoint32W(hdc, lpString, uCount, &size))
|
|---|
| 494 | ret = MAKELONG(size.cx, size.cy);
|
|---|
| 495 | else ret = 0;
|
|---|
| 496 |
|
|---|
| 497 | return ret;
|
|---|
| 498 | }
|
|---|
| 499 | //******************************************************************************
|
|---|
| 500 | //******************************************************************************
|
|---|