Ignore:
Timestamp:
Dec 1, 2003, 2:27:39 PM (22 years ago)
Author:
sandervl
Message:

Updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gdi32/text.cpp

    r10163 r10349  
    1 /* $Id: text.cpp,v 1.34 2003-07-14 13:43:15 sandervl Exp $ */
     1/* $Id: text.cpp,v 1.35 2003-12-01 13:27:39 sandervl Exp $ */
    22
    33/*
     
    2121#include <dcdata.h>
    2222#include <unicode.h>
     23#include "font.h"
    2324
    2425#define DBG_LOCALLOG    DBG_text
     
    386387                                  LPSIZE lpsSize)
    387388{
    388 #if 1
    389    dprintf(("GDI32: GetTextExtentPointA %x %.*s %d", hdc, cbString, lpsz, cbString));
    390 
    391    if(lpsz == NULL || cbString < 0 || lpsSize == NULL)
    392    {
    393       dprintf(("!WARNING!: GDI32: GetTextExtentPointA invalid parameter!"));
    394       SetLastError(ERROR_INVALID_PARAMETER);
    395       return FALSE;
    396    }
    397 
    398    lpsSize->cx = 0;
    399    lpsSize->cy = 0;
    400 
    401    // Verified with NT4, SP6
    402    if(cbString == 0)
    403    {
    404       dprintf(("GDI32: GetTextExtentPointA cbString == 0"));
    405       SetLastError(ERROR_SUCCESS);
    406       return TRUE;
    407    }
    408 
    409    //SvL: This works better than the code below. Can been seen clearly
    410    //     in the Settings dialog box of VirtualPC. Strings are clipped.
    411    //     (e.g.: Hard Disk 1 -> Hard Disk)
    412    BOOL rc = O32_GetTextExtentPoint(hdc, lpsz, cbString, lpsSize);
    413    if(rc) {
    414       dprintf(("GDI32: GetTextExtentPointA returned (%d,%d)", lpsSize->cx, lpsSize->cy));
    415       SetLastError(ERROR_SUCCESS);
    416       return TRUE;
    417    }
    418    return FALSE;
    419 #else
     389   BOOL ret = FALSE;
     390   INT  wlen;
     391   LPWSTR p = FONT_mbtowc(hdc, lpsz, cbString, &wlen, NULL);
     392   if (p) {
     393       ret = GetTextExtentPointW( hdc, p, wlen, lpsSize );
     394       HeapFree( GetProcessHeap(), 0, p );
     395   }
     396   else DebugInt3();
     397   return ret;
     398}
     399//******************************************************************************
     400//******************************************************************************
     401BOOL WIN32API GetTextExtentPointW(HDC    hdc,
     402                                  LPCWSTR lpString,
     403                                  int    cbString,
     404                                  PSIZE  lpSize)
     405{
    420406   BOOL       rc;
    421407   POINTLOS2  pts[TXTBOXOS_COUNT];
     
    423409   pDCData    pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
    424410
    425    dprintf(("GDI32: GetTextExtentPointA %s\n", lpsz));
     411   dprintf(("GDI32: GetTextExtentPointW %ls", lpString));
    426412   if(pHps == NULL)
    427413   {
     
    430416   }
    431417
    432    if(lpsz == NULL || cbString < 0 || lpsSize == NULL)
     418   if(lpString == NULL || cbString < 0 || lpSize == NULL)
    433419   {
    434420      SetLastError(ERROR_INVALID_PARAMETER);
     
    436422   }
    437423
    438    lpsSize->cx = 0;
    439    lpsSize->cy = 0;
     424   lpSize->cx = 0;
     425   lpSize->cy = 0;
    440426
    441427   // Verified with NT4, SP6
     
    451437
    452438      dprintf(("WARNING: string longer than 512 chars; splitting up"));
    453       lpsSize->cx = 0;
    454       lpsSize->cy = 0;
     439      lpSize->cx = 0;
     440      lpSize->cy = 0;
    455441      while(cbString) {
    456442         cbStringNew = min(500, cbString);
    457          rc = GetTextExtentPointA(hdc, lpsz, cbStringNew, &newSize);
     443         rc = GetTextExtentPointW(hdc, lpString, cbStringNew, &newSize);
    458444         if(rc == FALSE) {
    459445             return FALSE;
    460446         }
    461          lpsSize->cx += newSize.cx;
    462          lpsSize->cy  = max(newSize.cy, lpsSize->cy);
    463          lpsz     += cbStringNew;
     447         lpSize->cx += newSize.cx;
     448         lpSize->cy  = max(newSize.cy, lpSize->cy);
     449         lpString     += cbStringNew;
    464450         cbString -= cbStringNew;
    465451      }
     
    467453   }
    468454
    469    rc = OSLibGpiQueryTextBox(pHps, cbString, lpsz, TXTBOXOS_COUNT, pts);
     455   int   len;
     456   LPSTR astring;
     457
     458   len = WideCharToMultiByte( CP_ACP, 0, lpString, cbString, 0, 0, NULL, NULL );
     459   astring = (char *)malloc( len + 1 );
     460   lstrcpynWtoA(astring, lpString, len + 1 );
     461
     462   BOOL ret = OSLibGpiQueryTextBox(pHps, cbString, astring, TXTBOXOS_COUNT, pts);
     463   free(astring);
     464
    470465   if(rc == FALSE)
    471466   {
     
    474469   }
    475470   calcDimensions(pts, &widthHeight);
    476    lpsSize->cx = widthHeight.x;
    477    lpsSize->cy = widthHeight.y;
     471   lpSize->cx = widthHeight.x;
     472   lpSize->cy = widthHeight.y;
    478473
    479474   if(pHps && pHps->isPrinter && pHps->hdc)
     
    482477
    483478       if (OSLibDevQueryCaps(pHps, OSLIB_CAPS_HORIZONTAL_RESOLUTION, 2, &alArray[0]))
    484          lpsSize->cx = lpsSize->cx * alArray[0] / alArray[1];
    485    }
    486 
    487    dprintf(("GDI32: GetTextExtentPointA %x %s %d returned %d (%d,%d)", hdc, lpsz, cbString, rc, lpsSize->cx, lpsSize->cy));
     479         lpSize->cx = lpSize->cx * alArray[0] / alArray[1];
     480   }
     481
     482   dprintf(("GDI32: GetTextExtentPointW %x %ls %d returned %d (%d,%d)", hdc, lpString, cbString, rc, lpSize->cx, lpSize->cy));
    488483   SetLastError(ERROR_SUCCESS);
    489484   return TRUE;
    490 #endif
    491 }
    492 //******************************************************************************
    493 //******************************************************************************
    494 BOOL WIN32API GetTextExtentPointW(HDC    hdc,
    495                                   LPCWSTR lpString,
    496                                   int    cbString,
    497                                   PSIZE  lpSize)
    498 {
    499   char *astring;
    500   int  len;
    501   BOOL rc;
    502 
    503    if(lpString == NULL || cbString < 0 || lpSize == NULL)
    504    {
    505       dprintf(("!WARNING!: GDI32: GetTextExtentPointW invalid parameter!"));
    506       SetLastError(ERROR_INVALID_PARAMETER);
    507       return FALSE;
    508    }
    509 
    510    lpSize->cx = 0;
    511    lpSize->cy = 0;
    512 
    513    // Verified with NT4, SP6
    514    if(cbString == 0)
    515    {
    516       dprintf(("GDI32: GetTextExtentPointW cbString == 0"));
    517       SetLastError(ERROR_SUCCESS);
    518       return TRUE;
    519    }
    520 
    521    dprintf(("GDI32: GetTextExtentPointW %x %.*ls %d %x", hdc, cbString, lpString, cbString, lpSize));
    522 
    523    len = WideCharToMultiByte( CP_ACP, 0, lpString, cbString, 0, 0, NULL, NULL );
    524    astring = (char *)malloc( len + 1 );
    525    UnicodeToAsciiN(lpString, astring, len + 1 );
    526    rc = GetTextExtentPointA(hdc, astring,
    527                             len, lpSize);
    528 
    529    free(astring);
    530    return(rc);
    531485}
    532486//******************************************************************************
     
    544498//******************************************************************************
    545499//******************************************************************************
     500BOOL WIN32API GetTextExtentExPointA(HDC hdc,
     501                                    LPCSTR  str,
     502                                    int     count,
     503                                    int     maxExt,
     504                                    LPINT   lpnFit,
     505                                    LPINT   alpDx,
     506                                    LPSIZE  size)
     507{
     508    BOOL ret;
     509    INT wlen;
     510    LPWSTR p = FONT_mbtowc( hdc, str, count, &wlen, NULL);
     511    ret = GetTextExtentExPointW( hdc, p, wlen, maxExt, lpnFit, alpDx, size);
     512    if (lpnFit) *lpnFit = WideCharToMultiByte(CP_ACP,0,p,*lpnFit,NULL,0,NULL,NULL);
     513    HeapFree( GetProcessHeap(), 0, p );
     514    return ret;
     515}
     516//******************************************************************************
     517//******************************************************************************
     518BOOL WIN32API GetTextExtentExPointW(HDC hdc,
     519                                    LPCWSTR str,
     520                                    int     count,
     521                                    int     maxExt,
     522                                    LPINT   lpnFit,
     523                                    LPINT   alpDx,
     524                                    LPSIZE  size)
     525{
     526    int index, nFit, extent;
     527    SIZE tSize;
     528    BOOL ret = FALSE;
     529
     530    size->cx = size->cy = nFit = extent = 0;
     531    for(index = 0; index < count; index++)
     532    {
     533        if(!GetTextExtentPoint32W( hdc, str, 1, &tSize )) goto done;
     534        /* GetTextExtentPoint includes intercharacter spacing. */
     535        /* FIXME - justification needs doing yet.  Remember that the base
     536         * data will not be in logical coordinates.
     537         */
     538        extent += tSize.cx;
     539        if( !lpnFit || extent <= maxExt )
     540        /* It is allowed to be equal. */
     541        {
     542            nFit++;
     543            if( alpDx ) alpDx[index] = extent;
     544        }
     545        if( tSize.cy > size->cy ) size->cy = tSize.cy;
     546        str++;
     547    }
     548    size->cx = extent;
     549    if(lpnFit) *lpnFit = nFit;
     550    ret = TRUE;
     551
     552    dprintf(("returning %d %ld x %ld\n",nFit,size->cx,size->cy));
     553
     554done:
     555    return ret;
     556}
     557//******************************************************************************
     558//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.