Ignore:
Timestamp:
Nov 11, 1999, 2:16:40 PM (26 years ago)
Author:
sandervl
Message:

font changes + fixes

File:
1 edited

Legend:

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

    r1699 r1703  
    1 /* $Id: font.cpp,v 1.4 1999-11-10 23:30:45 phaller Exp $ */
     1/* $Id: font.cpp,v 1.5 1999-11-11 13:16:40 sandervl Exp $ */
    22
    33/*
     
    55 *
    66 * Copyright 1999 Edgar Buerkle (Edgar.Buerkle@gmx.ne)
    7  * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
     7 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
    88 * Copyright 1998 Patrick Haller
    99 *
    10  * TODO: EnumFontsA/W, EnumFontFamiliesExA/W + others
     10 * TODO: EnumFontsA/W, EnumFontFamiliesExA/W not complete
     11 *
     12 * Parts based on Wine code (991031)
     13 *
     14 * Copyright 1993 Alexandre Julliard
     15 *           1997 Alex Korobka
    1116 *
    1217 * Project Odin Software License can be found in LICENSE.TXT
     
    2429#include "misc.h"
    2530#include "unicode.h"
    26 #include <vmutex.h>
    2731#include <heapstring.h>
    2832#include <win\options.h>
     
    3236
    3337
    34 VMutex mutexProcWinA;
    35 VMutex mutexProcWinW;
    36 FONTENUMPROCA FontEnumProcWinA;
    37 FONTENUMPROCW FontEnumProcWinW;
    38 
     38typedef struct {
     39        DWORD userProc;
     40        DWORD userData;
     41        DWORD dwFlags;
     42} ENUMUSERDATA;
     43
     44/*
     45 *  For TranslateCharsetInfo
     46 */
     47#define FS(x) {{0,0,0,0},{0x1<<(x),0}}
     48#define MAXTCIINDEX 32
     49static CHARSETINFO FONT_tci[MAXTCIINDEX] = {
     50  /* ANSI */
     51  { ANSI_CHARSET, 1252, FS(0)},
     52  { EASTEUROPE_CHARSET, 1250, FS(1)},
     53  { RUSSIAN_CHARSET, 1251, FS(2)},
     54  { GREEK_CHARSET, 1253, FS(3)},
     55  { TURKISH_CHARSET, 1254, FS(4)},
     56  { HEBREW_CHARSET, 1255, FS(5)},
     57  { ARABIC_CHARSET, 1256, FS(6)},
     58  { BALTIC_CHARSET, 1257, FS(7)},
     59  /* reserved by ANSI */
     60  { DEFAULT_CHARSET, 0, FS(0)},
     61  { DEFAULT_CHARSET, 0, FS(0)},
     62  { DEFAULT_CHARSET, 0, FS(0)},
     63  { DEFAULT_CHARSET, 0, FS(0)},
     64  { DEFAULT_CHARSET, 0, FS(0)},
     65  { DEFAULT_CHARSET, 0, FS(0)},
     66  { DEFAULT_CHARSET, 0, FS(0)},
     67  { DEFAULT_CHARSET, 0, FS(0)},
     68  /* ANSI and OEM */
     69  { THAI_CHARSET,  874,  FS(16)},
     70  { SHIFTJIS_CHARSET, 932, FS(17)},
     71  { GB2312_CHARSET, 936, FS(18)},
     72  { HANGEUL_CHARSET, 949, FS(19)},
     73  { CHINESEBIG5_CHARSET, 950, FS(20)},
     74  { JOHAB_CHARSET, 1361, FS(21)},
     75  /* reserved for alternate ANSI and OEM */
     76  { DEFAULT_CHARSET, 0, FS(0)},
     77  { DEFAULT_CHARSET, 0, FS(0)},
     78  { DEFAULT_CHARSET, 0, FS(0)},
     79  { DEFAULT_CHARSET, 0, FS(0)},
     80  { DEFAULT_CHARSET, 0, FS(0)},
     81  { DEFAULT_CHARSET, 0, FS(0)},
     82  { DEFAULT_CHARSET, 0, FS(0)},
     83  { DEFAULT_CHARSET, 0, FS(0)},
     84  /* reserved for system */
     85  { DEFAULT_CHARSET, 0, FS(0)},
     86  { DEFAULT_CHARSET, 0, FS(0)},
     87};
    3988
    4089/*****************************************************************************
     
    204253  HFONT    hfont;
    205254
    206   //memcpy(&afont, lplf, ((int)&afont.lfFaceName - (int)&afont));
     255  //memcpy(&afont, lplf, ((ULONG)&afont.lfFaceName - (ULONG)&afont));
    207256  memcpy(&afont, lplf, sizeof(LOGFONTA));
    208257  memset(afont.lfFaceName, 0, LF_FACESIZE);
     
    214263//******************************************************************************
    215264int  EXPENTRY_O32 EnumFontProcA(LPENUMLOGFONTA lpLogFont, LPNEWTEXTMETRICA
    216                                 lpTextM, DWORD arg3, LPARAM arg4)
    217 {
    218   return FontEnumProcWinA(lpLogFont, lpTextM, arg3, arg4);
     265                                   lpTextM, DWORD arg3, LPARAM arg4)
     266{
     267 ENUMUSERDATA *lpEnumData = (ENUMUSERDATA *)arg4;
     268 FONTENUMPROCA proc = (FONTENUMPROCA)lpEnumData->userProc;
     269
     270  return proc(lpLogFont, lpTextM, arg3, lpEnumData->userData);
    219271}
    220272//******************************************************************************
    221273//******************************************************************************
    222274int  EXPENTRY_O32 EnumFontProcW(LPENUMLOGFONTA lpLogFont, LPNEWTEXTMETRICA lpTextM,
    223                                 DWORD arg3, LPARAM arg4)
    224 {
    225   ENUMLOGFONTW LogFont;
    226   int rc;
    227 
    228   memcpy(&LogFont, lpLogFont, ((int)&LogFont.elfLogFont.lfFaceName -
    229          (int)&LogFont));
     275                                   DWORD arg3, LPARAM arg4)
     276{
     277 ENUMUSERDATA *lpEnumData = (ENUMUSERDATA *)arg4;
     278 FONTENUMPROCW proc = (FONTENUMPROCW)lpEnumData->userProc;
     279 ENUMLOGFONTW LogFont;
     280 NEWTEXTMETRICW textM;
     281 int rc;
     282
     283  memcpy(&LogFont, lpLogFont, ((ULONG)&LogFont.elfLogFont.lfFaceName -
     284         (ULONG)&LogFont));
    230285  AsciiToUnicodeN(lpLogFont->elfLogFont.lfFaceName, LogFont.elfLogFont.lfFaceName, LF_FACESIZE-1);
    231286  AsciiToUnicodeN((char *) lpLogFont->elfFullName, LogFont.elfFullName, LF_FULLFACESIZE-1);
    232287  AsciiToUnicodeN((char *) lpLogFont->elfStyle, LogFont.elfStyle, LF_FACESIZE-1);
    233288
    234   rc = FontEnumProcWinW(&LogFont, (LPNEWTEXTMETRICW) lpTextM, arg3, arg4);
    235   return rc;
     289  textM.tmHeight = lpTextM->tmHeight;
     290  textM.tmAscent = lpTextM->tmAscent;
     291  textM.tmDescent = lpTextM->tmDescent;
     292  textM.tmInternalLeading = lpTextM->tmInternalLeading;
     293  textM.tmExternalLeading = lpTextM->tmExternalLeading;
     294  textM.tmAveCharWidth = lpTextM->tmAveCharWidth;
     295  textM.tmMaxCharWidth = lpTextM->tmMaxCharWidth;
     296  textM.tmWeight = lpTextM->tmWeight;
     297  textM.tmOverhang = lpTextM->tmOverhang;
     298  textM.tmDigitizedAspectX = lpTextM->tmDigitizedAspectX;
     299  textM.tmDigitizedAspectY = lpTextM->tmDigitizedAspectY;
     300  textM.tmFirstChar = lpTextM->tmFirstChar;
     301  textM.tmLastChar = lpTextM->tmLastChar;
     302  textM.tmDefaultChar = lpTextM->tmDefaultChar;
     303  textM.tmBreakChar = lpTextM->tmBreakChar;
     304  textM.tmItalic = lpTextM->tmItalic;
     305  textM.tmUnderlined = lpTextM->tmUnderlined;
     306  textM.tmStruckOut = lpTextM->tmStruckOut;
     307  textM.tmPitchAndFamily = lpTextM->tmPitchAndFamily;
     308  textM.tmCharSet = lpTextM->tmCharSet;
     309  textM.ntmFlags = 0;
     310  textM.ntmSizeEM = 0;
     311  textM.ntmCellHeight = 0;
     312  textM.ntmAvgWidth = 0;
     313
     314  return proc(&LogFont, &textM, arg3, lpEnumData->userData);
     315}
     316//******************************************************************************
     317//TODO: FontEnumdwFlagsEx, script, font signature & NEWTEXTMETRICEX (last part)
     318//******************************************************************************
     319int  EXPENTRY_O32 EnumFontProcExA(LPENUMLOGFONTA lpLogFont, LPNEWTEXTMETRICA
     320                                     lpTextM, DWORD arg3, LPARAM arg4)
     321{
     322 ENUMUSERDATA *lpEnumData = (ENUMUSERDATA *)arg4;
     323 FONTENUMPROCEXA proc = (FONTENUMPROCEXA)lpEnumData->userProc;
     324 ENUMLOGFONTEXA logFont;
     325 NEWTEXTMETRICEXA textM;
     326
     327  memcpy(&logFont, lpLogFont, sizeof(ENUMLOGFONTA));
     328  memset(logFont.elfScript, 0, sizeof(logFont.elfScript));
     329  memcpy(&textM.ntmetm, lpTextM, sizeof(textM.ntmetm));
     330  memset(&textM.ntmeFontSignature, 0, sizeof(textM.ntmeFontSignature));
     331
     332  return proc(&logFont, &textM, arg3, lpEnumData->userData);
     333}
     334//******************************************************************************
     335//TODO: FontEnumdwFlagsEx, script, font signature & NEWTEXTMETRICEX (last part)
     336//******************************************************************************
     337int EXPENTRY_O32 EnumFontProcExW(LPENUMLOGFONTA lpLogFont, LPNEWTEXTMETRICA lpTextM,
     338                                    DWORD arg3, LPARAM arg4)
     339{
     340 ENUMUSERDATA *lpEnumData = (ENUMUSERDATA *)arg4;
     341 FONTENUMPROCEXW proc = (FONTENUMPROCEXW)lpEnumData->userProc;
     342 ENUMLOGFONTEXW LogFont;
     343 NEWTEXTMETRICEXW textM;
     344 int rc;
     345
     346  memcpy(&LogFont, lpLogFont, ((ULONG)&LogFont.elfLogFont.lfFaceName - (ULONG)&LogFont));
     347  memset(LogFont.elfScript, 0, sizeof(LogFont.elfScript));
     348  AsciiToUnicodeN(lpLogFont->elfLogFont.lfFaceName, LogFont.elfLogFont.lfFaceName, LF_FACESIZE-1);
     349  AsciiToUnicodeN((char *) lpLogFont->elfFullName, LogFont.elfFullName, LF_FULLFACESIZE-1);
     350  AsciiToUnicodeN((char *) lpLogFont->elfStyle, LogFont.elfStyle, LF_FACESIZE-1);
     351
     352  textM.ntmetm.tmHeight = lpTextM->tmHeight;
     353  textM.ntmetm.tmAscent = lpTextM->tmAscent;
     354  textM.ntmetm.tmDescent = lpTextM->tmDescent;
     355  textM.ntmetm.tmInternalLeading = lpTextM->tmInternalLeading;
     356  textM.ntmetm.tmExternalLeading = lpTextM->tmExternalLeading;
     357  textM.ntmetm.tmAveCharWidth = lpTextM->tmAveCharWidth;
     358  textM.ntmetm.tmMaxCharWidth = lpTextM->tmMaxCharWidth;
     359  textM.ntmetm.tmWeight = lpTextM->tmWeight;
     360  textM.ntmetm.tmOverhang = lpTextM->tmOverhang;
     361  textM.ntmetm.tmDigitizedAspectX = lpTextM->tmDigitizedAspectX;
     362  textM.ntmetm.tmDigitizedAspectY = lpTextM->tmDigitizedAspectY;
     363  textM.ntmetm.tmFirstChar = lpTextM->tmFirstChar;
     364  textM.ntmetm.tmLastChar = lpTextM->tmLastChar;
     365  textM.ntmetm.tmDefaultChar = lpTextM->tmDefaultChar;
     366  textM.ntmetm.tmBreakChar = lpTextM->tmBreakChar;
     367  textM.ntmetm.tmItalic = lpTextM->tmItalic;
     368  textM.ntmetm.tmUnderlined = lpTextM->tmUnderlined;
     369  textM.ntmetm.tmStruckOut = lpTextM->tmStruckOut;
     370  textM.ntmetm.tmPitchAndFamily = lpTextM->tmPitchAndFamily;
     371  textM.ntmetm.tmCharSet = lpTextM->tmCharSet;
     372  textM.ntmetm.ntmFlags = 0;
     373  textM.ntmetm.ntmSizeEM = 0;
     374  textM.ntmetm.ntmCellHeight = 0;
     375  textM.ntmetm.ntmAvgWidth = 0;
     376  memset(&textM.ntmeFontSignature, 0, sizeof(textM.ntmeFontSignature));
     377
     378  return proc(&LogFont, &textM, arg3, lpEnumData->userData);
    236379}
    237380//******************************************************************************
     
    239382int WIN32API EnumFontsA( HDC arg1, LPCSTR arg2, FONTENUMPROCA arg3, LPARAM  arg4)
    240383{
    241     dprintf(("GDI32: OS2EnumFontsA"));
    242 //    return O32_EnumFonts(arg1, arg2, arg3, arg4);
    243     return 1;
    244 }
    245 //******************************************************************************
    246 //TODO: Callback
     384  return EnumFontFamiliesA(arg1, arg2, arg3, arg4);
     385}
     386//******************************************************************************
    247387//******************************************************************************
    248388int WIN32API EnumFontsW( HDC arg1, LPCWSTR arg2, FONTENUMPROCW arg3, LPARAM  arg4)
    249389{
    250     dprintf(("GDI32: OS2EnumFontsW - stub (1)"));
    251     // NOTE: This will not work as is (needs UNICODE support)
    252 //    return O32_EnumFonts(arg1, arg2, arg3, arg4);
    253     return 1;
     390  return EnumFontFamiliesW(arg1, arg2, arg3, arg4);
    254391}
    255392//******************************************************************************
     
    260397                               LPARAM       arg4)
    261398{
     399  ENUMUSERDATA enumData;
    262400  int rc;
    263401
    264   dprintf(("GDI32: OS2EnumFontFamiliesA "));
    265 
    266   mutexProcWinA.enter();
    267 
    268   FontEnumProcWinA = arg3;
    269 
    270   rc = O32_EnumFontFamilies(arg1, arg2, &EnumFontProcA, arg4);
    271 
    272   mutexProcWinA.leave();
     402  dprintf(("GDI32: EnumFontFamiliesA %s", arg2));
     403
     404  enumData.userProc = (DWORD)arg3;
     405  enumData.userData = arg4;
     406
     407  rc = O32_EnumFontFamilies(arg1, arg2, &EnumFontProcA, (LPARAM)&enumData);
     408
    273409  return rc;
    274410}
     
    280416                               LPARAM       arg4)
    281417{
     418  ENUMUSERDATA enumData;
    282419  int rc;
    283420  char *astring = UnicodeToAsciiString((LPWSTR)arg2);
    284421
    285   dprintf(("GDI32: OS2EnumFontFamiliesW "));
    286 
    287   mutexProcWinW.enter();
    288 
    289   FontEnumProcWinW = arg3;
    290 
    291   rc = O32_EnumFontFamilies(arg1, astring, &EnumFontProcW, arg4);
    292 
    293   mutexProcWinW.leave();
     422  dprintf(("GDI32: EnumFontFamiliesW %s", astring));
     423
     424  enumData.userProc = (DWORD)arg3;
     425  enumData.userData = arg4;
     426
     427  rc = O32_EnumFontFamilies(arg1, astring, &EnumFontProcW, (LPARAM)&enumData);
    294428
    295429  FreeAsciiString(astring);
     
    300434INT WIN32API EnumFontFamiliesExA( HDC arg1, LPLOGFONTA arg2, FONTENUMPROCEXA arg3, LPARAM  arg4, DWORD dwFlags)
    301435{
    302     dprintf(("GDI32: OS2EnumFontFamiliesExA, not implemented\n"));
    303     return 0;
     436  ENUMUSERDATA enumData;
     437  int rc;
     438
     439  dprintf(("GDI32: EnumFontFamiliesExA not complete %s", arg2->lfFaceName));
     440
     441  enumData.userProc = (DWORD)arg3;
     442  enumData.userData = arg4;
     443  enumData.dwFlags  = dwFlags;
     444
     445  rc = O32_EnumFontFamilies(arg1, arg2->lfFaceName, &EnumFontProcExA, (LPARAM)&enumData);
     446
     447  return rc;
    304448}
    305449//******************************************************************************
     
    307451INT WIN32API EnumFontFamiliesExW( HDC arg1, LPLOGFONTW arg2, FONTENUMPROCEXW arg3, LPARAM  arg4, DWORD dwFlags)
    308452{
    309     dprintf(("GDI32: OS2EnumFontFamiliesW, not implemented\n"));
    310     // NOTE: This will not work as is (needs UNICODE support)
    311     return 0;
     453  ENUMUSERDATA enumData;
     454  int rc;
     455  char *astring = UnicodeToAsciiString((LPWSTR)arg2->lfFaceName);
     456
     457  dprintf(("GDI32: EnumFontFamiliesExW not complete %s", astring));
     458
     459  enumData.userProc = (DWORD)arg3;
     460  enumData.userData = arg4;
     461  enumData.dwFlags  = dwFlags;
     462
     463  rc = O32_EnumFontFamilies(arg1, astring, &EnumFontProcExW, (LPARAM)&enumData);
     464
     465  FreeAsciiString(astring);
     466  return rc;
    312467}
    313468//******************************************************************************
     
    323478int WIN32API AddFontResourceA( LPCSTR arg1)
    324479{
    325     dprintf(("GDI32: OS2AddFontResourceA"));
     480    dprintf(("GDI32: AddFontResourceA"));
    326481    return O32_AddFontResource(arg1);
    327482}
     
    330485int WIN32API AddFontResourceW( LPCWSTR arg1)
    331486{
    332     dprintf(("GDI32: OS2AddFontResourceW STUB"));
     487    dprintf(("GDI32: AddFontResourceW STUB"));
    333488    // NOTE: This will not work as is (needs UNICODE support)
    334489//    return O32_AddFontResource(arg1);
     
    339494BOOL WIN32API RemoveFontResourceA( LPCSTR arg1)
    340495{
    341     dprintf(("GDI32: OS2RemoveFontResourceA %s\n", arg1));
     496    dprintf(("GDI32: RemoveFontResourceA %s\n", arg1));
    342497    return O32_RemoveFontResource(arg1);
    343498}
     
    349504 BOOL  rc;
    350505
    351     dprintf(("GDI32: OS2RemoveFontResourceW\n"));
     506    dprintf(("GDI32: RemoveFontResourceW\n"));
    352507    rc = O32_RemoveFontResource(astring);
    353508    FreeAsciiString(astring);
     
    436591  return (0);
    437592}
    438 //******************************************************************************
    439 //******************************************************************************
     593/*************************************************************************
     594 * TranslateCharsetInfo [GDI32.382]
     595 *
     596 * Fills a CHARSETINFO structure for a character set, code page, or
     597 * font. This allows making the correspondance between different labelings
     598 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
     599 * of the same encoding.
     600 *
     601 * Only one codepage will be set in lpCs->fs. If TCI_SRCFONTSIG is used,
     602 * only one codepage should be set in *lpSrc.
     603 *
     604 * RETURNS
     605 *   TRUE on success, FALSE on failure.
     606 *
     607 */
     608BOOL WIN32API TranslateCharsetInfo(
     609  LPDWORD lpSrc, /*
     610       if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
     611       if flags == TCI_SRCCHARSET: a character set value
     612       if flags == TCI_SRCCODEPAGE: a code page value
     613                 */
     614  LPCHARSETINFO lpCs, /* structure to receive charset information */
     615  DWORD flags /* determines interpretation of lpSrc */
     616) {
     617    int index = 0;
     618    switch (flags) {
     619    case TCI_SRCFONTSIG:
     620        while (!(*lpSrc>>index & 0x0001) && index<MAXTCIINDEX) index++;
     621      break;
     622    case TCI_SRCCODEPAGE:
     623      while ((UINT) (lpSrc) != FONT_tci[index].ciACP && index < MAXTCIINDEX) index++;
     624      break;
     625    case TCI_SRCCHARSET:
     626      while ((UINT) (lpSrc) != FONT_tci[index].ciCharset && index < MAXTCIINDEX) index++;
     627      break;
     628    default:
     629      return FALSE;
     630    }
     631    if (index >= MAXTCIINDEX || FONT_tci[index].ciCharset == DEFAULT_CHARSET) return FALSE;
     632    memcpy(lpCs, &FONT_tci[index], sizeof(CHARSETINFO));
     633    return TRUE;
     634}
     635//******************************************************************************
     636//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.