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/font.cpp

    r10230 r10349  
    1 /* $Id: font.cpp,v 1.31 2003-08-13 09:11:42 sandervl Exp $ */
     1/* $Id: font.cpp,v 1.32 2003-12-01 13:27:37 sandervl Exp $ */
    22
    33/*
     
    145145                                  lpstrFaceTemp,
    146146                                  LF_FACESIZE);
     147}
     148/***********************************************************************
     149 *           FONT_mbtowc
     150 *
     151 * Returns a '\0' terminated Unicode translation of str using the
     152 * charset of the currently selected font in hdc.  If count is -1 then
     153 * str is assumed to be '\0' terminated, otherwise it contains the
     154 * number of bytes to convert.  If plenW is non-NULL, on return it
     155 * will point to the number of WCHARs (excluding the '\0') that have
     156 * been written.  If pCP is non-NULL, on return it will point to the
     157 * codepage used in the conversion (NB, this may be CP_SYMBOL so watch
     158 * out).  The caller should free the returned LPWSTR from the process
     159 * heap itself.
     160 */
     161LPWSTR FONT_mbtowc(HDC hdc, LPCSTR str, INT count, INT *plenW, UINT *pCP)
     162{
     163    UINT cp = CP_ACP;
     164    INT lenW, i;
     165    LPWSTR strW;
     166    CHARSETINFO csi;
     167    int charset = GetTextCharset(hdc);
     168
     169    /* Hmm, nicely designed api this one! */
     170    if(TranslateCharsetInfo((DWORD*)charset, &csi, TCI_SRCCHARSET))
     171        cp = csi.ciACP;
     172    else {
     173        switch(charset) {
     174        case OEM_CHARSET:
     175            cp = GetOEMCP();
     176            break;
     177        case DEFAULT_CHARSET:
     178            cp = GetACP();
     179            break;
     180
     181        case VISCII_CHARSET:
     182        case TCVN_CHARSET:
     183        case KOI8_CHARSET:
     184        case ISO3_CHARSET:
     185        case ISO4_CHARSET:
     186          /* FIXME: These have no place here, but because x11drv
     187             enumerates fonts with these (made up) charsets some apps
     188             might use them and then the FIXME below would become
     189             annoying.  Now we could pick the intended codepage for
     190             each of these, but since it's broken anyway we'll just
     191             use CP_ACP and hope it'll go away...
     192          */
     193            cp = CP_ACP;
     194            break;
     195
     196
     197        default:
     198            dprintf(("Can't find codepage for charset %d\n", charset));
     199            break;
     200        }
     201    }
     202
     203    dprintf(("cp == %d\n", cp));
     204
     205    if(count == -1) count = strlen(str);
     206    if(cp != CP_SYMBOL) {
     207        lenW = MultiByteToWideChar(cp, 0, str, count, NULL, 0);
     208        strW = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, (lenW + 1) * sizeof(WCHAR));
     209        MultiByteToWideChar(cp, 0, str, count, strW, lenW);
     210    } else {
     211        lenW = count;
     212        strW = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, (lenW + 1) * sizeof(WCHAR));
     213        for(i = 0; i < count; i++) strW[i] = (BYTE)str[i];
     214    }
     215    strW[lenW] = '\0';
     216    dprintf(("mapped %s -> %ls\n", str, strW));
     217    if(plenW) *plenW = lenW;
     218    if(pCP) *pCP = cp;
     219    return strW;
    147220}
    148221//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.