[10373] | 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 | {
|
---|
[10400] | 43 | fFT2LIBIntegration = fEnabled;
|
---|
[10373] | 44 |
|
---|
| 45 | FT2Module.init();
|
---|
| 46 | }
|
---|
| 47 | //******************************************************************************
|
---|
| 48 | // Constructor
|
---|
| 49 | //******************************************************************************
|
---|
[21916] | 50 | CFT2Module::CFT2Module(const char* sModuleName): bEnabled(FALSE), hftModule(0), pfnGetGlyphIndices(NULL),
|
---|
[10373] | 51 | pfnFt2GetTextExtentW(NULL), pfnFt2EnableFontEngine(NULL),
|
---|
[10400] | 52 | pfnFt2GetGlyphOutline(NULL), pfnFt2CharStringPosAtA(NULL),
|
---|
[10373] | 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);
|
---|
[10400] | 73 | if (rc != 0)
|
---|
[10373] | 74 | dprintf(("Freetype2 library load error: return code = %u\n", rc));
|
---|
| 75 | else
|
---|
[10400] | 76 | bEnabled = TRUE;
|
---|
[10373] | 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 |
|
---|
[21304] | 98 | pfnGetGlyphIndices = (PFN_FT2GETGLYPHINDICES)QueryProcAddress("Ft2GetGlyphIndices");
|
---|
| 99 | if(!pfnGetGlyphIndices) dprintf(("Ft2GetGlyphIndices not found!!"));
|
---|
| 100 |
|
---|
[10373] | 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 |
|
---|
[21304] | 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 |
|
---|
[10373] | 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 |
|
---|
[21304] | 121 | pfnFt2GetCharacterPlacementW = (PFN_FT2GETCHARACTERPLACEMENTW)QueryProcAddress("Ft2GetCharacterPlacementW");
|
---|
| 122 | if(!pfnFt2GetCharacterPlacementW) dprintf(("pfnFt2GetCharacterPlacementW not found!!"));
|
---|
| 123 |
|
---|
[10373] | 124 | // Do not register functions for Mozilla plugins
|
---|
[10400] | 125 | if(IsDummyExeLoaded() == FALSE)
|
---|
[10373] | 126 | {
|
---|
| 127 | pfnFt2RegisterUconv = (PFN_FT2REGISTERUCONV)QueryProcAddress("Ft2RegisterUconv");
|
---|
[10400] | 128 | if(pfnFt2RegisterUconv)
|
---|
[10373] | 129 | pfnFt2RegisterUconv(WideCharToMultiByte, MultiByteToWideChar);
|
---|
| 130 | else dprintf(("Ft2QueryFontType not found!!"));
|
---|
| 131 | }
|
---|
| 132 | dprintf(("Freetype2 library enabled state %d",bEnabled));
|
---|
| 133 | }
|
---|
| 134 | return;
|
---|
| 135 |
|
---|
| 136 | failure:
|
---|
[10400] | 137 | if(pfnFt2RegisterUconv)
|
---|
[10373] | 138 | pfnFt2RegisterUconv(NULL, NULL);
|
---|
| 139 | if(pfnFt2EnableFontEngine)
|
---|
| 140 | pfnFt2EnableFontEngine(FALSE);
|
---|
| 141 |
|
---|
| 142 | pfnGetGlyphIndices = NULL;
|
---|
| 143 | pfnFt2GetTextExtentW = NULL;
|
---|
| 144 | pfnFt2EnableFontEngine = NULL;
|
---|
[10400] | 145 | pfnFt2GetGlyphOutline = NULL;
|
---|
| 146 | pfnFt2CharStringPosAtA = NULL;
|
---|
| 147 | pfnFt2CharStringPosAtW = NULL;
|
---|
[10373] | 148 | pfnFt2GetFontData = NULL;
|
---|
[10400] | 149 | pfnFt2RegisterUconv = NULL;
|
---|
[10373] | 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 | //******************************************************************************
|
---|
| 162 | CFT2Module::~CFT2Module()
|
---|
| 163 | {
|
---|
| 164 | if (hftModule)
|
---|
| 165 | DosFreeModule(hftModule);
|
---|
| 166 |
|
---|
| 167 | bEnabled = FALSE;
|
---|
| 168 | }
|
---|
| 169 | //******************************************************************************
|
---|
| 170 | //******************************************************************************
|
---|
| 171 | PFN CFT2Module::QueryProcAddress(int ordinal)
|
---|
| 172 | {
|
---|
| 173 | APIRET rc;
|
---|
| 174 | PFN ModuleAddr;
|
---|
| 175 |
|
---|
[10400] | 176 | rc = DosQueryProcAddr(hftModule, ordinal, NULL, &ModuleAddr);
|
---|
[10373] | 177 | if (rc != 0) {
|
---|
| 178 | dprintf(("FreeType2 QueryProcAddr error: return code = %u\n", rc));
|
---|
| 179 | return 0;
|
---|
| 180 | }
|
---|
| 181 | return ModuleAddr;
|
---|
| 182 | }
|
---|
| 183 | //******************************************************************************
|
---|
| 184 | //******************************************************************************
|
---|
[21916] | 185 | PFN CFT2Module::QueryProcAddress(const char * procname)
|
---|
[10373] | 186 | {
|
---|
| 187 | APIRET rc;
|
---|
| 188 | PFN ModuleAddr;
|
---|
| 189 |
|
---|
[10400] | 190 | rc = DosQueryProcAddr(hftModule, 0, procname, &ModuleAddr);
|
---|
[10373] | 191 | if (rc != 0) {
|
---|
| 192 | dprintf(("FreeType2 QueryProcAddr error: return code = %u\n", rc));
|
---|
| 193 | return 0;
|
---|
| 194 | }
|
---|
| 195 | return ModuleAddr;
|
---|
| 196 | }
|
---|
| 197 | //******************************************************************************
|
---|
| 198 | //******************************************************************************
|
---|
| 199 | DWORD CFT2Module::Ft2GetGlyphIndices(HPS hps, LPCWSTR str, int c, LPWORD pgi, DWORD fl)
|
---|
| 200 | {
|
---|
[21997] | 201 | DWORD ret;
|
---|
[21304] | 202 | USHORT sel;
|
---|
| 203 |
|
---|
[21997] | 204 | // All FreeType calls should be wrapped for saving FS
|
---|
[21304] | 205 | if(pfnGetGlyphIndices) {
|
---|
| 206 | sel = RestoreOS2FS();
|
---|
| 207 | ret = pfnGetGlyphIndices(hps, (WCHAR*)str, c, (ULONG*)pgi, fl);
|
---|
| 208 | SetFS(sel);
|
---|
[21997] | 209 | return ret;
|
---|
[21304] | 210 | }
|
---|
[10373] | 211 | //no fallback
|
---|
[10390] | 212 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED_W);
|
---|
[10373] | 213 | return GDI_ERROR;
|
---|
| 214 | }
|
---|
| 215 | //******************************************************************************
|
---|
| 216 | //******************************************************************************
|
---|
| 217 | DWORD CFT2Module::Ft2GetGlyphOutline(HPS hps, UINT glyph, UINT format, LPGLYPHMETRICS lpgm, DWORD buflen, LPVOID buf, const MAT2* lpmat)
|
---|
| 218 | {
|
---|
[21997] | 219 | DWORD ret;
|
---|
[21304] | 220 | USHORT sel;
|
---|
| 221 |
|
---|
[21997] | 222 | // All FreeType calls should be wrapped for saving FS
|
---|
[21304] | 223 | if (pfnFt2GetGlyphOutline)
|
---|
| 224 | {
|
---|
| 225 | sel = RestoreOS2FS();
|
---|
| 226 | ret = pfnFt2GetGlyphOutline (hps, glyph, format, lpgm, buflen, buf, lpmat);
|
---|
| 227 | SetFS(sel);
|
---|
[21997] | 228 | return ret;
|
---|
[21304] | 229 | }
|
---|
[21997] | 230 |
|
---|
[10373] | 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)
|
---|
[10400] | 239 | //
|
---|
[10373] | 240 | // The fallback case is not accurate!! (but the same as our old code)
|
---|
| 241 | //
|
---|
| 242 | //******************************************************************************
|
---|
[10390] | 243 | BOOL CFT2Module::Ft2GetTextExtentW(HPS hps, LONG lCount1,LPCWSTR pchString, PPOINTLOS2 pwidthHeight)
|
---|
[10373] | 244 | {
|
---|
[10390] | 245 | DWORD ret;
|
---|
| 246 | USHORT sel;
|
---|
| 247 | POINTLOS2 aptlPoints[TXTBOX_COUNT];
|
---|
[10373] | 248 |
|
---|
[10390] | 249 | // All FreeType calls should be wrapped for saving FS
|
---|
| 250 | if(pfnFt2GetTextExtentW)
|
---|
[10373] | 251 | {
|
---|
| 252 | sel = RestoreOS2FS();
|
---|
[10390] | 253 | ret = pfnFt2GetTextExtentW(hps, lCount1, pchString, TXTBOX_COUNT, aptlPoints);
|
---|
[10373] | 254 | SetFS(sel);
|
---|
| 255 | if(ret || (ret == FALSE && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
|
---|
| 256 | {
|
---|
[10390] | 257 | calcDimensions(aptlPoints, pwidthHeight);
|
---|
| 258 | return ret;
|
---|
| 259 | }
|
---|
[10373] | 260 | }
|
---|
| 261 | //else fall back to GPI
|
---|
[10390] | 262 | INT lenA;
|
---|
| 263 | LPSTR strA;
|
---|
| 264 | POINTLOS2 start = { 0, 0 };
|
---|
| 265 | PPOINTLOS2 pplos2;
|
---|
| 266 | INT cx;
|
---|
| 267 | INT cy;
|
---|
[10373] | 268 |
|
---|
| 269 | pDCData pHps = (pDCData)OSLibGpiQueryDCData(hps);
|
---|
| 270 |
|
---|
[10390] | 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 ));
|
---|
[10373] | 275 |
|
---|
[10390] | 276 | ret = OSLibGpiQueryCharStringPosAt( pHps, &start, 0, lenA, strA, NULL, pplos2 );
|
---|
[10400] | 277 | if( ret )
|
---|
| 278 | {
|
---|
| 279 | TEXTMETRICW tmW;
|
---|
[10390] | 280 |
|
---|
[10400] | 281 | cx = labs( pplos2[ lenA ].x - pplos2[ 0 ].x );
|
---|
| 282 | cy = labs( pplos2[ lenA ].y - pplos2[ 0 ].y );
|
---|
[10390] | 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 |
|
---|
[10400] | 295 | calcDimensions(aptlPoints, pwidthHeight);
|
---|
[10390] | 296 |
|
---|
[10402] | 297 | DecreaseLogCount();
|
---|
[10600] | 298 | if(GetTextMetricsW( hps, &tmW ) == TRUE)
|
---|
[10400] | 299 | {
|
---|
| 300 | pwidthHeight->y = tmW.tmHeight; // *Must* use the maximum height of the font
|
---|
| 301 | }
|
---|
[10390] | 302 | #ifdef DEBUG
|
---|
[10400] | 303 | else DebugInt3();
|
---|
[10390] | 304 | #endif
|
---|
[10402] | 305 | IncreaseLogCount();
|
---|
[10400] | 306 | }
|
---|
[10390] | 307 |
|
---|
| 308 | free( pplos2 );
|
---|
| 309 | free( strA );
|
---|
| 310 |
|
---|
[10373] | 311 | return ret;
|
---|
| 312 | }
|
---|
| 313 | //******************************************************************************
|
---|
| 314 | //******************************************************************************
|
---|
| 315 | BOOL CFT2Module::Ft2CharStringPosAtA(HPS hps,PPOINTLOS2 ptl,PRECTLOS2 rct,ULONG flOptions,LONG lCount,LPCSTR pchString,CONST INT *alAdx, DWORD fuWin32Options)
|
---|
| 316 | {
|
---|
[10400] | 317 | DWORD ret;
|
---|
[10373] | 318 | USHORT sel;
|
---|
| 319 |
|
---|
[21997] | 320 | // All FreeType calls should be wrapped for saving FS
|
---|
| 321 | if(pfnFt2CharStringPosAtA) {
|
---|
[10373] | 322 | sel = RestoreOS2FS();
|
---|
| 323 | ret = pfnFt2CharStringPosAtA(hps, ptl,rct,flOptions,lCount,pchString,alAdx, fuWin32Options);
|
---|
| 324 | SetFS(sel);
|
---|
| 325 | if(ret || (ret == FALSE && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
|
---|
[21997] | 326 | return ret;
|
---|
[10373] | 327 | }
|
---|
[21997] | 328 | //else fall back to GPI
|
---|
| 329 | //NOTE: We don't support fuWin32Options in the fallback case
|
---|
| 330 | pDCData pHps = (pDCData)OSLibGpiQueryDCData(hps);
|
---|
| 331 | return OSLibGpiCharStringPosAt(pHps,ptl,rct,flOptions,lCount,pchString,alAdx);
|
---|
[10373] | 332 | }
|
---|
| 333 | //******************************************************************************
|
---|
| 334 | //******************************************************************************
|
---|
| 335 | BOOL CFT2Module::Ft2CharStringPosAtW(HPS hps, PPOINTLOS2 ptl,PRECTLOS2 rct,ULONG flOptions,LONG lCount,LPCWSTR pchString,CONST INT *alAdx, DWORD fuWin32Options)
|
---|
| 336 | {
|
---|
[10400] | 337 | DWORD ret;
|
---|
[10373] | 338 | USHORT sel;
|
---|
| 339 |
|
---|
[21997] | 340 | // All FreeType calls should be wrapped for saving FS
|
---|
| 341 | if(pfnFt2CharStringPosAtW) {
|
---|
[10373] | 342 | sel = RestoreOS2FS();
|
---|
| 343 | ret = pfnFt2CharStringPosAtW(hps, ptl,rct,flOptions,lCount,pchString,alAdx, fuWin32Options);
|
---|
| 344 | SetFS(sel);
|
---|
| 345 | if(ret || (ret == FALSE && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
|
---|
[21997] | 346 | return ret;
|
---|
[10373] | 347 | }
|
---|
[21997] | 348 | //else fall back to GPI
|
---|
| 349 | //NOTE: We don't support fuWin32Options in the fallback case
|
---|
| 350 | int len;
|
---|
| 351 | LPSTR astring;
|
---|
| 352 | LPINT lpDx = NULL;
|
---|
[10373] | 353 |
|
---|
[21997] | 354 | pDCData pHps = (pDCData)OSLibGpiQueryDCData(hps);
|
---|
[10373] | 355 |
|
---|
[21997] | 356 | len = WideCharToMultiByte( CP_ACP, 0, pchString, lCount, 0, 0, NULL, NULL );
|
---|
| 357 | astring = (char *)malloc( len + 1 );
|
---|
| 358 | lstrcpynWtoA(astring, pchString, len + 1 );
|
---|
[10373] | 359 |
|
---|
[21997] | 360 | if( IsDBCSEnv() && alAdx )
|
---|
| 361 | {
|
---|
| 362 | int i, j;
|
---|
[10600] | 363 |
|
---|
[21997] | 364 | lpDx = ( LPINT )malloc( len * sizeof( INT ));
|
---|
| 365 | for( i = j = 0; i < len; i++, j++ )
|
---|
[10600] | 366 | {
|
---|
[21997] | 367 | lpDx[ i ] = alAdx[ j ];
|
---|
| 368 | if( IsDBCSLeadByte( astring[ i ]))
|
---|
| 369 | lpDx[ ++i ] = 0;
|
---|
[10600] | 370 | }
|
---|
| 371 |
|
---|
[21997] | 372 | alAdx = ( CONST INT * )lpDx;
|
---|
| 373 | }
|
---|
[10600] | 374 |
|
---|
[21997] | 375 | ret = OSLibGpiCharStringPosAt(pHps,ptl,rct,flOptions,len,astring,alAdx);
|
---|
[10600] | 376 |
|
---|
[21997] | 377 | if( lpDx )
|
---|
| 378 | free( lpDx );
|
---|
[10600] | 379 |
|
---|
[21997] | 380 | free(astring);
|
---|
[10600] | 381 |
|
---|
[10373] | 382 | return ret;
|
---|
| 383 | }
|
---|
| 384 | //******************************************************************************
|
---|
| 385 | //******************************************************************************
|
---|
| 386 | DWORD CFT2Module::Ft2GetFontData(HPS hps, DWORD dwTable, DWORD dwOffset,
|
---|
| 387 | LPVOID lpvBuffer, DWORD cbData)
|
---|
| 388 | {
|
---|
[21997] | 389 | DWORD ret;
|
---|
[21304] | 390 | USHORT sel;
|
---|
| 391 |
|
---|
[21997] | 392 | // All FreeType calls should be wrapped for saving FS
|
---|
[21304] | 393 | if(pfnFt2GetFontData) {
|
---|
| 394 | sel = RestoreOS2FS();
|
---|
| 395 | ret = pfnFt2GetFontData(hps, dwTable, dwOffset, lpvBuffer, cbData);
|
---|
| 396 | SetFS(sel);
|
---|
| 397 | if(ret || (ret == GDI_ERROR && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
|
---|
[21997] | 398 | return ret;
|
---|
[21304] | 399 | }
|
---|
[10373] | 400 | //no fallback
|
---|
| 401 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED_W);
|
---|
| 402 | return(GDI_ERROR);
|
---|
| 403 | }
|
---|
| 404 | //******************************************************************************
|
---|
[10400] | 405 | // Query the font type current selected into the presentation space, or,
|
---|
[10373] | 406 | // when hps == NULL, query the type of the font with the specified name
|
---|
| 407 | //******************************************************************************
|
---|
| 408 | DWORD CFT2Module::Ft2QueryFontType(HPS hps, LPCSTR lpszFontName)
|
---|
| 409 | {
|
---|
[10400] | 410 | DWORD ret;
|
---|
[10373] | 411 | USHORT sel;
|
---|
| 412 |
|
---|
[10400] | 413 | // All FreeType calls should be wrapped for saving FS
|
---|
[10373] | 414 | if(pfnFt2QueryFontType) {
|
---|
| 415 | sel = RestoreOS2FS();
|
---|
| 416 | ret = pfnFt2QueryFontType(hps, lpszFontName);
|
---|
| 417 | SetFS(sel);
|
---|
| 418 | if(ret || (ret == GDI_ERROR && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
|
---|
[10400] | 419 | return ret;
|
---|
[10373] | 420 | }
|
---|
| 421 | //no fallback
|
---|
| 422 | return FT2_FONTTYPE_UNKNOWN;
|
---|
| 423 | }
|
---|
| 424 | //******************************************************************************
|
---|
| 425 | //******************************************************************************
|
---|
| 426 | BOOL CFT2Module::Ft2GetStringWidthW(HDC hdc, LPWSTR lpszString, UINT cbString, PINT pWidthArray)
|
---|
| 427 | {
|
---|
[10400] | 428 | DWORD ret;
|
---|
[10373] | 429 | USHORT sel;
|
---|
| 430 | pDCData pHps;
|
---|
| 431 |
|
---|
| 432 | pHps = (pDCData)OSLibGpiQueryDCData(hdc);
|
---|
| 433 | if(pHps == NULL) {
|
---|
| 434 | DebugInt3();
|
---|
| 435 | SetLastError(ERROR_INVALID_HANDLE_W);
|
---|
| 436 | return 0;
|
---|
| 437 | }
|
---|
| 438 |
|
---|
[10400] | 439 | // All FreeType calls should be wrapped for saving FS
|
---|
[10373] | 440 | if(pfnFt2QueryStringWidthW) {
|
---|
| 441 | sel = RestoreOS2FS();
|
---|
| 442 | ret = pfnFt2QueryStringWidthW((HPS)hdc, lpszString, cbString, (LONG *)pWidthArray);
|
---|
| 443 | SetFS(sel);
|
---|
| 444 | if(ret || (ret == GDI_ERROR && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
|
---|
| 445 | {
|
---|
| 446 | if(pHps && pHps->isPrinter && pHps->hdc)
|
---|
| 447 | {//scale for printer dcs
|
---|
| 448 | LONG alArray[2];
|
---|
| 449 |
|
---|
| 450 | if(OSLibDevQueryCaps(pHps, OSLIB_CAPS_HORIZONTAL_RESOLUTION, 2, &alArray[0]) &&
|
---|
[10400] | 451 | alArray[0] != alArray[1])
|
---|
[10373] | 452 | {
|
---|
| 453 | dprintf(("Different hor/vert resolutions (%d,%d)", alArray[0], alArray[1]));
|
---|
| 454 | for (int i = 0; i < cbString; i++)
|
---|
| 455 | {
|
---|
| 456 | pWidthArray[i] = pWidthArray[i] * alArray[0] / alArray[1];
|
---|
| 457 | }
|
---|
| 458 | }
|
---|
| 459 | }
|
---|
[10400] | 460 | return ret;
|
---|
[10373] | 461 | }
|
---|
| 462 | }
|
---|
| 463 | //fallback method
|
---|
| 464 | int c, i;
|
---|
| 465 | for (i = 0; i < cbString; i++)
|
---|
| 466 | {
|
---|
| 467 | if (GetCharWidth32W(hdc, lpszString[i], lpszString[i], (LPINT)&c)) {
|
---|
| 468 | dprintf(("%c pWidthArray[%d] = %d", lpszString[i], i, c));
|
---|
| 469 | pWidthArray[i]= c;
|
---|
| 470 | }
|
---|
| 471 | else {
|
---|
| 472 | dprintf(("WARNING: GetCharWidth32W failed for %c!!!", lpszString[i]));
|
---|
| 473 | pWidthArray[i] = 0;
|
---|
| 474 | }
|
---|
| 475 | }
|
---|
| 476 | return TRUE;
|
---|
| 477 | }
|
---|
| 478 | /*****************************************************************************
|
---|
| 479 | * Name : DWORD GetCharacterPlacementW
|
---|
| 480 | * Purpose : The GetCharacterPlacementW function retrieves information about
|
---|
| 481 | * a character string, such as character widths, caret positioning,
|
---|
| 482 | * ordering within the string, and glyph rendering. The type of
|
---|
| 483 | * information returned depends on the dwFlags parameter and is
|
---|
| 484 | * based on the currently selected font in the given display context.
|
---|
| 485 | * The function copies the information to the specified GCP_RESULTSW
|
---|
| 486 | * structure or to one or more arrays specified by the structure.
|
---|
| 487 | * Parameters: HDC hdc handle to device context
|
---|
| 488 | * LPCSTR lpString pointer to string
|
---|
| 489 | * int nCount number of characters in string
|
---|
| 490 | * int nMaxExtent maximum extent for displayed string
|
---|
| 491 | * GCP_RESULTSW *lpResults pointer to buffer for placement result
|
---|
| 492 | * DWORD dwFlags placement flags
|
---|
| 493 | * Variables :
|
---|
| 494 | * Result :
|
---|
| 495 | * Remark :
|
---|
| 496 | * Status : Partly working
|
---|
| 497 | *
|
---|
| 498 | * Author : Borrowed Rewind Code
|
---|
| 499 | *****************************************************************************/
|
---|
| 500 | DWORD CFT2Module::Ft2GetCharacterPlacementW(HDC hdc,
|
---|
| 501 | LPCWSTR lpString,
|
---|
| 502 | int uCount,
|
---|
| 503 | int nMaxExtent,
|
---|
| 504 | GCP_RESULTSW *lpResults,
|
---|
| 505 | DWORD dwFlags)
|
---|
| 506 | {
|
---|
[10400] | 507 | DWORD ret;
|
---|
[10373] | 508 | USHORT sel;
|
---|
| 509 | SIZE size;
|
---|
| 510 | UINT i, nSet;
|
---|
| 511 | pDCData pHps;
|
---|
| 512 |
|
---|
| 513 | pHps = (pDCData)OSLibGpiQueryDCData(hdc);
|
---|
| 514 | if(pHps == NULL) {
|
---|
| 515 | DebugInt3();
|
---|
| 516 | SetLastError(ERROR_INVALID_HANDLE_W);
|
---|
| 517 | return 0;
|
---|
| 518 | }
|
---|
| 519 |
|
---|
| 520 | dprintf(("%ls, %d, %d, 0x%08lx\n", lpString, uCount, nMaxExtent, dwFlags));
|
---|
| 521 |
|
---|
| 522 | dprintf(("lStructSize=%ld, lpOutString=%p, lpOrder=%p, lpDx=%p, lpCaretPos=%p, lpClass=%p, lpGlyphs=%p, nGlyphs=%u, nMaxFit=%d\n",
|
---|
[10400] | 523 | lpResults->lStructSize, lpResults->lpOutString, lpResults->lpOrder,
|
---|
| 524 | lpResults->lpDx, lpResults->lpCaretPos, lpResults->lpClass,
|
---|
| 525 | lpResults->lpGlyphs, lpResults->nGlyphs, lpResults->nMaxFit));
|
---|
[10373] | 526 |
|
---|
| 527 | if(dwFlags&(~0)) dprintf(("unsupported flags 0x%08lx\n", dwFlags));
|
---|
[10400] | 528 | if(lpResults->lpCaretPos) dprintf(("caret positions not implemented\n"));
|
---|
| 529 | if(lpResults->lpClass) dprintf(("classes not implemented\n"));
|
---|
[10373] | 530 |
|
---|
| 531 | nSet = (UINT)uCount;
|
---|
| 532 | if(nSet > lpResults->nGlyphs)
|
---|
[10400] | 533 | nSet = lpResults->nGlyphs;
|
---|
[10373] | 534 |
|
---|
| 535 | /* return number of initialized fields */
|
---|
| 536 | lpResults->nGlyphs = nSet;
|
---|
| 537 | lpResults->nMaxFit = nSet;
|
---|
| 538 |
|
---|
| 539 | /* Treat the case where no special handling was requested in a fastpath way */
|
---|
| 540 | /* copy will do if the GCP_REORDER flag is not set */
|
---|
| 541 | if(lpResults->lpOutString)
|
---|
| 542 | strncpyW( lpResults->lpOutString, lpString, nSet );
|
---|
| 543 |
|
---|
| 544 | if(lpResults->lpOrder)
|
---|
| 545 | for(i = 0; i < nSet; i++)
|
---|
| 546 | lpResults->lpOrder[i] = i;
|
---|
| 547 |
|
---|
[21997] | 548 | // All FreeType calls should be wrapped for saving FS
|
---|
[21304] | 549 | if(pfnFt2GetCharacterPlacementW) {
|
---|
| 550 | sel = RestoreOS2FS();
|
---|
| 551 | ret = pfnFt2GetCharacterPlacementW((HPS)hdc, lpString, nSet, nMaxExtent, lpResults, dwFlags);
|
---|
| 552 | SetFS(sel);
|
---|
| 553 | if(ret || (ret == 0 && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
|
---|
| 554 | {
|
---|
| 555 | #ifdef DEBUG
|
---|
| 556 | if(ret && lpResults->lpDx) {
|
---|
| 557 | for (i = 0; i < nSet; i++)
|
---|
| 558 | {
|
---|
| 559 | dprintf(("%c pWidthArray[%d] = %d", lpString[i], i, lpResults->lpDx[i]));
|
---|
| 560 | }
|
---|
| 561 | }
|
---|
| 562 | #endif
|
---|
| 563 | if(pHps && pHps->isPrinter && pHps->hdc)
|
---|
| 564 | {//scale for printer dcs
|
---|
| 565 | LONG alArray[2];
|
---|
| 566 |
|
---|
| 567 | if(OSLibDevQueryCaps(pHps, OSLIB_CAPS_HORIZONTAL_RESOLUTION, 2, &alArray[0]) &&
|
---|
[21997] | 568 | alArray[0] != alArray[1])
|
---|
[21304] | 569 | {
|
---|
| 570 | dprintf(("Different hor/vert resolutions (%d,%d)", alArray[0], alArray[1]));
|
---|
| 571 | if(lpResults->lpDx) {
|
---|
| 572 | for (i = 0; i < nSet; i++)
|
---|
| 573 | {
|
---|
| 574 | lpResults->lpDx[i] = lpResults->lpDx[i] * alArray[0] / alArray[1];
|
---|
| 575 | }
|
---|
| 576 | }
|
---|
| 577 | ULONG x = (ret & 0xffff);
|
---|
| 578 | x = x * alArray[0] / alArray[1];
|
---|
| 579 | ret &= ~0xffff;
|
---|
| 580 | ret |= (x & 0xffff);
|
---|
| 581 | }
|
---|
| 582 | }
|
---|
[21997] | 583 | return ret;
|
---|
[21304] | 584 | }
|
---|
| 585 | }
|
---|
[10373] | 586 | //fallback method
|
---|
| 587 |
|
---|
| 588 | /* FIXME: Will use the placement chars */
|
---|
| 589 | if (lpResults->lpDx)
|
---|
| 590 | {
|
---|
| 591 | Ft2GetStringWidthW(hdc, (LPWSTR)lpString, nSet, lpResults->lpDx);
|
---|
| 592 | }
|
---|
| 593 |
|
---|
| 594 | if(lpResults->lpGlyphs)
|
---|
[10400] | 595 | GetGlyphIndicesW(hdc, lpString, nSet, lpResults->lpGlyphs, 0);
|
---|
[10373] | 596 |
|
---|
| 597 | if (GetTextExtentPoint32W(hdc, lpString, uCount, &size))
|
---|
| 598 | ret = MAKELONG(size.cx, size.cy);
|
---|
| 599 | else ret = 0;
|
---|
| 600 |
|
---|
| 601 | return ret;
|
---|
| 602 | }
|
---|
| 603 | //******************************************************************************
|
---|
| 604 | //******************************************************************************
|
---|