Changeset 20936


Ignore:
Timestamp:
Jan 15, 2004, 12:18:58 PM (21 years ago)
Author:
sandervl
Message:

KOM: Cleanup of text functions

Location:
tags/trunk/src/gdi32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified tags/trunk/src/gdi32/ft2supp.cpp

    r20927 r20936  
    4141void WIN32API SetFreeTypeIntegration(BOOL fEnabled)
    4242{
    43     fFT2LIBIntegration = fEnabled;   
     43    fFT2LIBIntegration = fEnabled;
    4444
    4545    FT2Module.init();
     
    4848// Constructor
    4949//******************************************************************************
    50 CFT2Module::CFT2Module(char* sModuleName): bEnabled(FALSE), hftModule(0), pfnGetGlyphIndices(NULL), 
     50CFT2Module::CFT2Module(char* sModuleName): bEnabled(FALSE), hftModule(0), pfnGetGlyphIndices(NULL),
    5151                pfnFt2GetTextExtentW(NULL), pfnFt2EnableFontEngine(NULL),
    52                 pfnFt2GetGlyphOutline(NULL), pfnFt2CharStringPosAtA(NULL), 
     52                pfnFt2GetGlyphOutline(NULL), pfnFt2CharStringPosAtA(NULL),
    5353                pfnFt2CharStringPosAtW(NULL), pfnFt2GetFontData(NULL),
    5454                pfnFt2RegisterUconv(NULL), pfnFt2QueryStringWidthW(NULL),
     
    7171
    7272    rc = DosLoadModule((PSZ)Loaderror, sizeof(Loaderror), pszModuleName, &hftModule);
    73     if (rc != 0) 
     73    if (rc != 0)
    7474        dprintf(("Freetype2 library load error: return code = %u\n", rc));
    7575    else
    76        bEnabled = TRUE;   
     76       bEnabled = TRUE;
    7777
    7878    if(bEnabled) {
     
    111111
    112112       // Do not register functions for Mozilla plugins
    113        if(IsDummyExeLoaded() == FALSE) 
     113       if(IsDummyExeLoaded() == FALSE)
    114114       {
    115115           pfnFt2RegisterUconv = (PFN_FT2REGISTERUCONV)QueryProcAddress("Ft2RegisterUconv");
    116            if(pfnFt2RegisterUconv) 
     116           if(pfnFt2RegisterUconv)
    117117                pfnFt2RegisterUconv(WideCharToMultiByte, MultiByteToWideChar);
    118118           else dprintf(("Ft2QueryFontType not found!!"));
     
    123123
    124124failure:
    125     if(pfnFt2RegisterUconv) 
     125    if(pfnFt2RegisterUconv)
    126126        pfnFt2RegisterUconv(NULL, NULL);
    127127    if(pfnFt2EnableFontEngine)
     
    131131    pfnFt2GetTextExtentW   = NULL;
    132132    pfnFt2EnableFontEngine = NULL;
    133     pfnFt2GetGlyphOutline  = NULL; 
    134     pfnFt2CharStringPosAtA = NULL; 
    135     pfnFt2CharStringPosAtW = NULL; 
     133    pfnFt2GetGlyphOutline  = NULL;
     134    pfnFt2CharStringPosAtA = NULL;
     135    pfnFt2CharStringPosAtW = NULL;
    136136    pfnFt2GetFontData      = NULL;
    137     pfnFt2RegisterUconv    = NULL; 
     137    pfnFt2RegisterUconv    = NULL;
    138138    pfnFt2QueryStringWidthW= NULL;
    139139    pfnFt2GetVersion       = NULL;
     
    162162    PFN ModuleAddr;
    163163
    164     rc = DosQueryProcAddr(hftModule, ordinal, NULL, &ModuleAddr); 
     164    rc = DosQueryProcAddr(hftModule, ordinal, NULL, &ModuleAddr);
    165165    if (rc != 0) {
    166166        dprintf(("FreeType2 QueryProcAddr error: return code = %u\n", rc));
     
    176176    PFN ModuleAddr;
    177177
    178     rc = DosQueryProcAddr(hftModule, 0, procname, &ModuleAddr); 
     178    rc = DosQueryProcAddr(hftModule, 0, procname, &ModuleAddr);
    179179    if (rc != 0) {
    180180        dprintf(("FreeType2 QueryProcAddr error: return code = %u\n", rc));
     
    203203// This is basically the same as Ft2QueryTextBoxW, but it behaves as the Win32
    204204// API GetTextExtent (which ignores character attributes and underhang/overhang)
    205 // 
     205//
    206206// The fallback case is not accurate!! (but the same as our old code)
    207207//
     
    242242
    243243    ret = OSLibGpiQueryCharStringPosAt( pHps, &start, 0, lenA, strA, NULL, pplos2 );
    244 
    245     cx = labs( pplos2[ lenA ].x - pplos2[ 0 ].x );
    246     cy = labs( pplos2[ lenA ].y - pplos2[ 0 ].y );
    247 
    248244    if( ret )
    249245    {
     246        TEXTMETRICW tmW;
     247
     248        cx = labs( pplos2[ lenA ].x - pplos2[ 0 ].x );
     249        cy = labs( pplos2[ lenA ].y - pplos2[ 0 ].y );
     250
    250251        aptlPoints[ TXTBOX_BOTTOMLEFT ].x = 0;
    251252        aptlPoints[ TXTBOX_BOTTOMLEFT ].y = 0;
     
    258259        aptlPoints[ TXTBOX_CONCAT ].x = cx;
    259260        aptlPoints[ TXTBOX_CONCAT ].y = cy;
    260     }
    261 
    262     calcDimensions(aptlPoints, pwidthHeight);
    263 
    264     TEXTMETRICW tmW;
    265     if(GetTextMetricsW( hps, &tmW ) == TRUE)
    266     {
    267         pwidthHeight->y = tmW.tmHeight;    // *Must* use the maximum height of the font
    268     }
     261
     262        calcDimensions(aptlPoints, pwidthHeight);
     263
     264        if(GetTextMetricsW( hps, &tmW ) == TRUE)
     265        {
     266            pwidthHeight->y = tmW.tmHeight;    // *Must* use the maximum height of the font
     267        }
    269268#ifdef DEBUG
    270     else DebugInt3();
     269        else DebugInt3();
    271270#endif
     271    }
    272272
    273273    free( pplos2 );
     
    280280BOOL CFT2Module::Ft2CharStringPosAtA(HPS hps,PPOINTLOS2 ptl,PRECTLOS2 rct,ULONG flOptions,LONG lCount,LPCSTR pchString,CONST INT *alAdx, DWORD fuWin32Options)
    281281{
    282     DWORD  ret; 
     282    DWORD  ret;
    283283    USHORT sel;
    284284
    285     // All FreeType calls should be wrapped for saving FS 
     285    // All FreeType calls should be wrapped for saving FS
    286286    if(pfnFt2CharStringPosAtA) {
    287287        sel  = RestoreOS2FS();
     
    289289        SetFS(sel);
    290290        if(ret || (ret == FALSE && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
    291             return ret; 
     291            return ret;
    292292    }
    293293    //else fall back to GPI
     
    300300BOOL CFT2Module::Ft2CharStringPosAtW(HPS hps, PPOINTLOS2 ptl,PRECTLOS2 rct,ULONG flOptions,LONG lCount,LPCWSTR pchString,CONST INT *alAdx, DWORD fuWin32Options)
    301301{
    302     DWORD  ret; 
     302    DWORD  ret;
    303303    USHORT sel;
    304304
    305     // All FreeType calls should be wrapped for saving FS 
     305    // All FreeType calls should be wrapped for saving FS
    306306    if(pfnFt2CharStringPosAtW) {
    307307        sel  = RestoreOS2FS();
     
    309309        SetFS(sel);
    310310        if(ret || (ret == FALSE && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
    311             return ret; 
     311            return ret;
    312312    }
    313313    //else fall back to GPI
     
    336336}
    337337//******************************************************************************
    338 // Query the font type current selected into the presentation space, or, 
     338// Query the font type current selected into the presentation space, or,
    339339// when hps == NULL, query the type of the font with the specified name
    340340//******************************************************************************
    341341DWORD CFT2Module::Ft2QueryFontType(HPS hps, LPCSTR lpszFontName)
    342342{
    343     DWORD  ret; 
     343    DWORD  ret;
    344344    USHORT sel;
    345345
    346     // All FreeType calls should be wrapped for saving FS 
     346    // All FreeType calls should be wrapped for saving FS
    347347    if(pfnFt2QueryFontType) {
    348348        sel  = RestoreOS2FS();
     
    350350        SetFS(sel);
    351351        if(ret || (ret == GDI_ERROR && ERRORIDERROR(WinGetLastError(0)) != PMERR_FUNCTION_NOT_SUPPORTED))
    352             return ret; 
     352            return ret;
    353353    }
    354354    //no fallback
     
    359359BOOL CFT2Module::Ft2GetStringWidthW(HDC hdc, LPWSTR lpszString, UINT cbString, PINT pWidthArray)
    360360{
    361     DWORD  ret; 
     361    DWORD  ret;
    362362    USHORT sel;
    363363    pDCData pHps;
     
    370370    }
    371371
    372     // All FreeType calls should be wrapped for saving FS 
     372    // All FreeType calls should be wrapped for saving FS
    373373    if(pfnFt2QueryStringWidthW) {
    374374        sel  = RestoreOS2FS();
     
    382382
    383383               if(OSLibDevQueryCaps(pHps, OSLIB_CAPS_HORIZONTAL_RESOLUTION, 2, &alArray[0]) &&
    384                   alArray[0] != alArray[1]) 
     384                  alArray[0] != alArray[1])
    385385               {
    386386                   dprintf(("Different hor/vert resolutions (%d,%d)", alArray[0], alArray[1]));
     
    391391                }
    392392            }
    393             return ret; 
     393            return ret;
    394394        }
    395395    }
     
    438438                                            DWORD         dwFlags)
    439439{
    440     DWORD  ret; 
     440    DWORD  ret;
    441441    USHORT sel;
    442442    SIZE   size;
     
    454454
    455455    dprintf(("lStructSize=%ld, lpOutString=%p, lpOrder=%p, lpDx=%p, lpCaretPos=%p, lpClass=%p, lpGlyphs=%p, nGlyphs=%u, nMaxFit=%d\n",
    456             lpResults->lStructSize, lpResults->lpOutString, lpResults->lpOrder,
    457             lpResults->lpDx, lpResults->lpCaretPos, lpResults->lpClass,
    458             lpResults->lpGlyphs, lpResults->nGlyphs, lpResults->nMaxFit));
     456        lpResults->lStructSize, lpResults->lpOutString, lpResults->lpOrder,
     457        lpResults->lpDx, lpResults->lpCaretPos, lpResults->lpClass,
     458        lpResults->lpGlyphs, lpResults->nGlyphs, lpResults->nMaxFit));
    459459
    460460    if(dwFlags&(~0))            dprintf(("unsupported flags 0x%08lx\n", dwFlags));
    461     if(lpResults->lpCaretPos)   dprintf(("caret positions not implemented\n"));
    462     if(lpResults->lpClass)      dprintf(("classes not implemented\n"));
     461    if(lpResults->lpCaretPos)   dprintf(("caret positions not implemented\n"));
     462    if(lpResults->lpClass)  dprintf(("classes not implemented\n"));
    463463
    464464    nSet = (UINT)uCount;
    465465    if(nSet > lpResults->nGlyphs)
    466         nSet = lpResults->nGlyphs;
     466    nSet = lpResults->nGlyphs;
    467467
    468468    /* return number of initialized fields */
     
    488488
    489489    if(lpResults->lpGlyphs)
    490         GetGlyphIndicesW(hdc, lpString, nSet, lpResults->lpGlyphs, 0);
     490    GetGlyphIndicesW(hdc, lpString, nSet, lpResults->lpGlyphs, 0);
    491491
    492492    if (GetTextExtentPoint32W(hdc, lpString, uCount, &size))
  • TabularUnified tags/trunk/src/gdi32/text.cpp

    r20928 r20936  
    1 /* $Id: text.cpp,v 1.42 2004-01-14 16:53:25 sandervl Exp $ */
     1/* $Id: text.cpp,v 1.43 2004-01-15 11:18:58 sandervl Exp $ */
    22
    33/*
     
    543543    return GetTextExtentPointW(hdc, lpsz, cbString, lpSize);
    544544}
     545
     546typedef BOOL ( WIN32API *PFN_GETTEXTEXTENTPOINT32 )( HDC, PVOID, INT, LPSIZE );
     547
     548BOOL InternalGetTextExtentExPointAW(HDC hdc,
     549                                    PVOID   str,
     550                                    INT     count,
     551                                    INT     maxExt,
     552                                    LPINT   lpnFit,
     553                                    LPINT   alpDx,
     554                                    LPSIZE  size,
     555                                    BOOL    fUnicode)
     556{
     557    int i, nFit;
     558    SIZE tSize;
     559    BOOL ret = FALSE;
     560
     561    PFN_GETTEXTEXTENTPOINT32 pfnGetTextExtentPoint32;
     562
     563    if( fUnicode )
     564        pfnGetTextExtentPoint32 = ( PFN_GETTEXTEXTENTPOINT32 )GetTextExtentPoint32W;
     565    else
     566        pfnGetTextExtentPoint32 = ( PFN_GETTEXTEXTENTPOINT32 )GetTextExtentPoint32A;
     567
     568    size->cx = size->cy = nFit = i = 0;
     569
     570    if( lpnFit || alpDx )
     571    {
     572        for( i = 1; i <= count; i++ )
     573        {
     574            if( !pfnGetTextExtentPoint32( hdc, str, i, &tSize )) goto done;
     575
     576            if( lpnFit && ( maxExt < tSize.cx ))
     577                break;
     578
     579            if( alpDx )
     580                alpDx[ nFit ] = tSize.cx;
     581
     582            nFit++;
     583        }
     584    }
     585
     586    if(( count > 0 ) && ( i >= count ))
     587    {
     588        size->cx = tSize.cx;
     589        size->cy = tSize.cy; // The height of a font is constant.
     590    }
     591    else if( !pfnGetTextExtentPoint32( hdc, str, count, size )) goto done;
     592
     593    if(lpnFit) *lpnFit = nFit;
     594    ret = TRUE;
     595
     596    dprintf(("returning %d %ld x %ld\n",nFit,size->cx,size->cy));
     597
     598done:
     599    return ret;
     600}
     601
    545602//******************************************************************************
    546603//******************************************************************************
     
    553610                                    LPSIZE  size)
    554611{
    555     BOOL ret;
    556     INT wlen;
    557     LPWSTR p;
    558     INT nFit;
    559     TEXTMETRICA tmA;
    560     CHAR brokenDBCS = 0;
    561 
    562     if( IsDBCSEnv())
    563     {
    564         brokenDBCS = getBrokenDBCS( str, count );
    565 
    566         GetTextMetricsA( hdc, &tmA );
    567     }
    568 
    569     if( brokenDBCS )
    570        count--;
    571 
    572     p = FONT_mbtowc( hdc, str, count, &wlen, NULL);
    573     ret = GetTextExtentExPointW( hdc, p, wlen, maxExt, &nFit, alpDx, size);
    574     nFit = WideCharToMultiByte(CP_ACP,0,p,nFit,NULL,0,NULL,NULL);
    575     if( IsDBCSEnv() && alpDx ) // index of alpDx between ansi and wide may not match in DBCS !!!
    576     {
    577         LPINT alpDxNew = ( LPINT )HeapAlloc( GetProcessHeap(), 0, sizeof( alpDx[ 0 ] ) * ( nFit + 1 ));
    578         INT prevDx;
    579         int i, j;
    580 
    581         for( i = j = 0; i < nFit; i++, j++ )
    582         {
    583             if( IsDBCSLeadByte( str[ i ]))
    584             {
    585                 prevDx = ( i > 0 ) ? alpDxNew[ i - 1 ] : 0;
    586                 alpDxNew[ i++ ] = prevDx + tmA.tmAveCharWidth;
    587                 if( i >= nFit )
    588                     break;
    589             }
    590             alpDxNew[ i ] = alpDx[ j ];
    591         }
    592 
    593         if(( nFit < count ) && IsDBCSLeadByte( str[ nFit ]))
    594         {
    595             prevDx = ( nFit > 0 ) ? alpDxNew[ nFit - 1 ] : 0;
    596             if( maxExt >= prevDx + tmA.tmAveCharWidth )
    597                 alpDxNew[ nFit++ ] = prevDx + tmA.tmAveCharWidth;
    598         }
    599 
    600         memcpy( alpDx, alpDxNew, sizeof( alpDx[ 0 ] ) * nFit );
    601 
    602         HeapFree( GetProcessHeap(), 0, alpDxNew );
    603     }
    604 
    605     // for broken DBCS. correct for FIXED WIDTH, not approx. for VARIABLE WIDTH
    606     if( brokenDBCS )
    607     {
    608        size->cx += tmA.tmAveCharWidth;
    609        if( count == 0 )
    610           size->cy = tmA.tmHeight;
    611 
    612        if(( maxExt > size->cx ) && ( nFit <= count )) // decreaed count by 1 above
    613        {
    614           if( alpDx )
    615             alpDx[ nFit ] = size->cx;
    616 
    617           nFit++;
    618        }
    619     }
    620 
    621     if (lpnFit) *lpnFit = nFit;
    622 
    623     HeapFree( GetProcessHeap(), 0, p );
    624     return ret;
     612    return InternalGetTextExtentExPointAW( hdc, ( PVOID )str, count, maxExt, lpnFit, alpDx, size, FALSE );
    625613}
    626614//******************************************************************************
     
    634622                                    LPSIZE  size)
    635623{
    636     int i, nFit, extent;
    637     SIZE tSize;
    638     BOOL ret = FALSE;
    639 
    640     size->cx = size->cy = nFit = extent = 0;
    641 
    642     for( i = 1; i <= count; i++ )
    643     {
    644         if( !GetTextExtentPoint32W( hdc, str, i, &tSize )) goto done;
    645 
    646         if( maxExt < tSize.cx )
    647             break;
    648 
    649         if( alpDx )
    650             alpDx[ nFit ] = tSize.cx;
    651 
    652         nFit++;
    653     }
    654 
    655     if( i >= count )
    656         size->cx = tSize.cx;
    657     else if( !GetTextExtentPoint32W( hdc, str, count, size )) goto done;
    658 
    659     size->cy = tSize.cy; // The height of a font is constant.
    660 
    661     if(lpnFit) *lpnFit = nFit;
    662     ret = TRUE;
    663 
    664     dprintf(("returning %d %ld x %ld\n",nFit,size->cx,size->cy));
    665 
    666 done:
    667     return ret;
     624    return InternalGetTextExtentExPointAW( hdc, ( PVOID )str, count, maxExt, lpnFit, alpDx, size, TRUE );
    668625}
    669626//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.