1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/os2/font.cpp 
   3 // Purpose:     wxFont class 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  15 // ============================================================================ 
  17 // ============================================================================ 
  19 // ---------------------------------------------------------------------------- 
  21 // ---------------------------------------------------------------------------- 
  33 #include "wx/os2/private.h" 
  35 #include "wx/fontutil.h" 
  36 #include "wx/fontmap.h" 
  37 #include "wx/encinfo.h" 
  39 #include "wx/tokenzr.h" 
  43 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
) 
  45 // ---------------------------------------------------------------------------- 
  46 // wxFontRefData - the internal description of the font 
  47 // ---------------------------------------------------------------------------- 
  49 class WXDLLEXPORT wxFontRefData
: public wxGDIRefData
 
  54         Init(-1, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
, false, 
  55              wxEmptyString
, wxFONTENCODING_DEFAULT
); 
  58     wxFontRefData( int             nSize
 
  63                   ,const wxString
& sFaceName
 
  64                   ,wxFontEncoding  vEncoding
 
  77     wxFontRefData( const wxNativeFontInfo
& rInfo
 
  88     wxFontRefData(const wxFontRefData
& rData
) 
  90         Init( rData
.m_nPointSize
 
  98         m_nFontId 
= rData
.m_nFontId
; 
 101     virtual ~wxFontRefData(); 
 106     bool Alloc(wxFont
* pFont
); 
 110     // All wxFont accessors 
 112     inline int GetPointSize(void) const 
 115         // We don't use the actual native font point size since it is 
 116         // the chosen physical font, which is usually only and approximation 
 117         // of the desired outline font.  The actual displayable point size 
 118         // is the one stored in the refData 
 123     inline int GetFamily(void) const 
 128     inline int GetStyle(void) const 
 130         return m_bNativeFontInfoOk 
? m_vNativeFontInfo
.GetStyle() 
 134     inline int GetWeight(void) const 
 136         return m_bNativeFontInfoOk 
? m_vNativeFontInfo
.GetWeight() 
 140     inline bool GetUnderlined(void) const 
 142         return m_bNativeFontInfoOk 
? m_vNativeFontInfo
.GetUnderlined() 
 146     inline wxString 
GetFaceName(void) const 
 150         if (m_bNativeFontInfoOk
) 
 151             sFaceName 
= m_vNativeFontInfo
.GetFaceName(); 
 153             sFaceName 
= m_sFaceName
; 
 158     inline wxFontEncoding 
GetEncoding(void) const 
 160         return m_bNativeFontInfoOk 
? m_vNativeFontInfo
.GetEncoding() 
 164     inline WXHFONT      
GetHFONT(void) const { return m_hFont
; } 
 165     inline HPS          
GetPS(void) const { return m_hPS
; } 
 166     inline PFONTMETRICS 
GetFM(void) const { return m_pFM
; } 
 167     inline int          GetNumFonts(void) const { return m_nNumFonts
; } 
 170     inline void SetPointSize(int nPointSize
) 
 172         if (m_bNativeFontInfoOk
) 
 173             m_vNativeFontInfo
.SetPointSize(nPointSize
); 
 175             m_nPointSize 
= nPointSize
; 
 178     inline void SetFamily(int nFamily
) 
 183     inline void SetStyle(int nStyle
) 
 185         if (m_bNativeFontInfoOk
) 
 186             m_vNativeFontInfo
.SetStyle((wxFontStyle
)nStyle
); 
 191     inline void SetWeight(int nWeight
) 
 193         if (m_bNativeFontInfoOk
) 
 194             m_vNativeFontInfo
.SetWeight((wxFontWeight
)nWeight
); 
 199     inline bool SetFaceName(const wxString
& sFaceName
) 
 201         if (m_bNativeFontInfoOk
) 
 202             return m_vNativeFontInfo
.SetFaceName(sFaceName
); 
 204             m_sFaceName 
= sFaceName
; 
 208     inline void SetUnderlined(bool bUnderlined
) 
 210         if (m_bNativeFontInfoOk
) 
 211             m_vNativeFontInfo
.SetUnderlined(bUnderlined
); 
 213             m_bUnderlined 
= bUnderlined
; 
 216     inline void SetEncoding(wxFontEncoding vEncoding
) 
 218         if (m_bNativeFontInfoOk
) 
 219             m_vNativeFontInfo
.SetEncoding(vEncoding
); 
 221             m_vEncoding 
= vEncoding
; 
 224     inline void SetPS(HPS hPS
) 
 229     inline void SetFM(PFONTMETRICS pFM
) 
 234     inline void SetNumFonts(int nNumFonts
) 
 236         m_nNumFonts 
= nNumFonts
; 
 240     // Native font info tests 
 242     bool HasNativeFontInfo() const { return m_bNativeFontInfoOk
; } 
 244     const wxNativeFontInfo
& GetNativeFontInfo() const 
 245         { return m_vNativeFontInfo
; } 
 249     // Common part of all ctors 
 256               ,const wxString
& rsFaceName
 
 257               ,wxFontEncoding  vEncoding
 
 260     void Init( const wxNativeFontInfo
& rInfo
 
 265     // If true, the pointer to the actual font is temporary and SHOULD NOT BE 
 266     // DELETED by destructor 
 272     // Font characterstics 
 279     wxString                        m_sFaceName
; 
 280     wxFontEncoding                  m_vEncoding
; 
 286     wxNativeFontInfo                m_vNativeFontInfo
; 
 287     bool                            m_bNativeFontInfoOk
; 
 290     // Some PM specific stuff 
 292     PFONTMETRICS                    m_pFM
;         // array of FONTMETRICS structs 
 293     int                             m_nNumFonts
;   // number of fonts in array 
 294     HPS                             m_hPS
;         // PS handle this font belongs to 
 295     FATTRS                          m_vFattrs
;     // Current fattrs struct 
 296     FACENAMEDESC                    m_vFname
;      // Current facename struct 
 297     bool                            m_bInternalPS
; // Internally generated PS? 
 298 }; // end of CLASS wxFontRefData 
 300 #define M_FONTDATA ((wxFontRefData*)m_refData) 
 302 // ============================================================================ 
 304 // ============================================================================ 
 306 // ---------------------------------------------------------------------------- 
 308 // ---------------------------------------------------------------------------- 
 310 void wxFontRefData::Init( 
 316 , const wxString
&                   rsFaceName
 
 317 , wxFontEncoding                    vEncoding
 
 321     m_nPointSize  
= nPointSize
; 
 325     m_bUnderlined 
= bUnderlined
; 
 326     m_sFaceName   
= rsFaceName
; 
 327     m_vEncoding   
= vEncoding
; 
 330     m_bNativeFontInfoOk 
= false; 
 333     m_bTemporary  
= false; 
 334     m_pFM         
= (PFONTMETRICS
)NULL
; 
 337 } // end of wxFontRefData::Init 
 339 void wxFontRefData::Init( 
 340   const wxNativeFontInfo
&           rInfo
 
 341 , WXHFONT                           hFont 
//this is the FontId -- functions as the hFont for OS/2 
 342 , WXHANDLE                          hPS   
// Presentation Space we are using 
 346     // hFont may be zero, or it be passed in case we really want to 
 347     // use the exact font created in the underlying system 
 348     // (for example where we can't guarantee conversion from HFONT 
 349     // to LOGFONT back to HFONT) 
 352     m_nFontId 
= (int)hFont
; 
 354     m_bNativeFontInfoOk 
= true; 
 355     m_vNativeFontInfo 
= rInfo
; 
 357     if (hPS 
== NULLHANDLE
) 
 359         m_hPS 
= ::WinGetPS(HWND_DESKTOP
); 
 360         m_bInternalPS 
= true; 
 366     m_bTemporary  
= false; 
 367     m_pFM         
= (PFONTMETRICS
)NULL
; 
 369 } // end of wxFontRefData::Init 
 371 wxFontRefData::~wxFontRefData() 
 376 bool wxFontRefData::Alloc( wxFont
* pFont 
) 
 384     if (!m_bNativeFontInfoOk
) 
 386         wxFillLogFont( &m_vNativeFontInfo
.fa
 
 387                       ,&m_vNativeFontInfo
.fn
 
 394         m_bNativeFontInfoOk 
= true; 
 405     if((lRc 
= ::GpiCreateLogFont( m_hPS
 
 408                                  ,&m_vNativeFontInfo
.fa
 
 411        m_hFont 
= (WXHFONT
)flId
; 
 416         vError 
= ::WinGetLastError(vHabmain
); 
 417         sError 
= wxPMErrorToStr(vError
); 
 418         wxLogLastError(wxT("CreateFont")); 
 421     ::GpiSetCharSet(m_hPS
, flId
); // sets font for presentation space 
 422     ::GpiQueryFontMetrics(m_hPS
, sizeof(FONTMETRICS
), &m_vNativeFontInfo
.fm
); 
 425     // Set refData members with the results 
 427     memcpy(&m_vFattrs
, &m_vNativeFontInfo
.fa
, sizeof(m_vFattrs
)); 
 428     memcpy(&m_vFname
, &m_vNativeFontInfo
.fn
, sizeof(m_vFname
)); 
 430     // Going to leave the point size alone.  Mostly we use outline fonts 
 431     // that can be set to any point size inside of Presentation Parameters, 
 432     // regardless of whether or not the actual font is registered in the system. 
 433     // The GpiCreateLogFont will do enough by selecting the right family, 
 436     if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "Times New Roman") == 0) 
 438     else if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "Times New Roman MT 30") == 0) 
 440     else if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "@Times New Roman MT 30") == 0) 
 442     else if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "Tms Rmn") == 0) 
 444     else if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "WarpSans") == 0) 
 445         m_nFamily 
= wxDECORATIVE
; 
 446     else if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "Helvetica") == 0) 
 448     else if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "Helv") == 0) 
 450     else if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "Script") == 0) 
 451         m_nFamily 
= wxSCRIPT
; 
 452     else if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "Courier New") == 0) 
 453         m_nFamily 
= wxTELETYPE
; 
 454     else if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "Courier") == 0) 
 455         m_nFamily 
= wxTELETYPE
; 
 456     else if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "System Monospaced") == 0) 
 457         m_nFamily 
= wxTELETYPE
; 
 458     else if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "System VIO") == 0) 
 459         m_nFamily 
= wxMODERN
; 
 460     else if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "System Proportional") == 0) 
 461         m_nFamily 
= wxMODERN
; 
 462     else if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "Arial") == 0) 
 464     else if (strcmp(m_vNativeFontInfo
.fm
.szFamilyname
, "Swiss") == 0) 
 469     if (m_vNativeFontInfo
.fa
.fsSelection 
& FATTR_SEL_ITALIC
) 
 470         m_nStyle 
= wxFONTSTYLE_ITALIC
; 
 472         m_nStyle 
= wxFONTSTYLE_NORMAL
; 
 473     switch(m_vNativeFontInfo
.fn
.usWeightClass
) 
 475         case FWEIGHT_DONT_CARE
: 
 476             m_nWeight 
= wxFONTWEIGHT_NORMAL
; 
 480             m_nWeight 
= wxFONTWEIGHT_NORMAL
; 
 484             m_nWeight 
= wxFONTWEIGHT_LIGHT
; 
 488             m_nWeight 
= wxFONTWEIGHT_BOLD
; 
 491         case FWEIGHT_ULTRA_BOLD
: 
 492             m_nWeight 
= wxFONTWEIGHT_MAX
; 
 496             m_nWeight 
= wxFONTWEIGHT_NORMAL
; 
 498     m_bUnderlined 
= ((m_vNativeFontInfo
.fa
.fsSelection 
& FATTR_SEL_UNDERSCORE
) != 0); 
 499     m_sFaceName 
= (wxChar
*)m_vNativeFontInfo
.fa
.szFacename
; 
 500     m_vEncoding 
= wxGetFontEncFromCharSet(m_vNativeFontInfo
.fa
.usCodePage
); 
 503     // We don't actuall keep the font around if using a temporary PS 
 508             ::GpiDeleteSetId( m_hPS
 
 512         ::WinReleasePS(m_hPS
); 
 516         // Select the font into the Presentation space 
 518         ::GpiSetCharSet(m_hPS
, flId
); // sets font for presentation space 
 520 } // end of wxFontRefData::Alloc 
 522 void wxFontRefData::Free() 
 526     m_pFM 
= (PFONTMETRICS
)NULL
; 
 530         ::GpiDeleteSetId(m_hPS
, 1L); /* delete the logical font          */ 
 535         ::WinReleasePS(m_hPS
); 
 537 } // end of wxFontRefData::Free 
 539 // ---------------------------------------------------------------------------- 
 541 // ---------------------------------------------------------------------------- 
 543 void wxNativeFontInfo::Init() 
 545     memset(&fa
, '\0', sizeof(FATTRS
)); 
 546 } // end of wxNativeFontInfo::Init 
 548 int wxNativeFontInfo::GetPointSize() const 
 551 } // end of wxNativeFontInfo::GetPointSize 
 553 wxFontStyle 
wxNativeFontInfo::GetStyle() const 
 555     return fa
.fsSelection 
& FATTR_SEL_ITALIC 
? wxFONTSTYLE_ITALIC 
: wxFONTSTYLE_NORMAL
; 
 556 } // end of wxNativeFontInfo::GetStyle 
 558 wxFontWeight 
wxNativeFontInfo::GetWeight() const 
 560     switch(fn
.usWeightClass
) 
 562         case FWEIGHT_DONT_CARE
: 
 563             return wxFONTWEIGHT_NORMAL
; 
 566             return wxFONTWEIGHT_NORMAL
; 
 569             return wxFONTWEIGHT_LIGHT
; 
 572             return wxFONTWEIGHT_BOLD
; 
 574         case FWEIGHT_ULTRA_BOLD
: 
 575             return wxFONTWEIGHT_MAX
; 
 577     return wxFONTWEIGHT_NORMAL
; 
 578 } // end of wxNativeFontInfo::GetWeight 
 580 bool wxNativeFontInfo::GetUnderlined() const 
 582     return ((fa
.fsSelection 
& FATTR_SEL_UNDERSCORE
) != 0); 
 583 } // end of wxNativeFontInfo::GetUnderlined 
 585 wxString 
wxNativeFontInfo::GetFaceName() const 
 587     return (wxChar
*)fm
.szFacename
; 
 588 } // end of wxNativeFontInfo::GetFaceName 
 590 wxFontFamily 
wxNativeFontInfo::GetFamily() const 
 595     // Extract family from facename 
 597     if (strcmp(fm
.szFamilyname
, "Times New Roman") == 0) 
 599     else if (strcmp(fm
.szFamilyname
, "Times New Roman MT 30") == 0) 
 601     else if (strcmp(fm
.szFamilyname
, "@Times New Roman MT 30") == 0) 
 603     else if (strcmp(fm
.szFamilyname
, "Tms Rmn") == 0) 
 605     else if (strcmp(fm
.szFamilyname
, "WarpSans") == 0) 
 606         nFamily 
= wxDECORATIVE
; 
 607     else if (strcmp(fm
.szFamilyname
, "Helvetica") == 0) 
 609     else if (strcmp(fm
.szFamilyname
, "Helv") == 0) 
 611     else if (strcmp(fm
.szFamilyname
, "Script") == 0) 
 613     else if (strcmp(fm
.szFamilyname
, "Courier New") == 0) 
 614         nFamily 
= wxTELETYPE
; 
 615     else if (strcmp(fm
.szFamilyname
, "Courier") == 0) 
 616         nFamily 
= wxTELETYPE
; 
 617     else if (strcmp(fm
.szFamilyname
, "System Monospaced") == 0) 
 618         nFamily 
= wxTELETYPE
; 
 619     else if (strcmp(fm
.szFamilyname
, "System VIO") == 0) 
 621     else if (strcmp(fm
.szFamilyname
, "System Proportional") == 0) 
 623     else if (strcmp(fm
.szFamilyname
, "Arial") == 0) 
 625     else if (strcmp(fm
.szFamilyname
, "Swiss") == 0) 
 629     return (wxFontFamily
)nFamily
; 
 630 } // end of wxNativeFontInfo::GetFamily 
 632 wxFontEncoding 
wxNativeFontInfo::GetEncoding() const 
 634     return wxGetFontEncFromCharSet(fa
.usCodePage
); 
 635 } // end of wxNativeFontInfo::GetEncoding 
 637 void wxNativeFontInfo::SetPointSize( 
 641     fm
.lEmHeight 
= (LONG
)nPointsize
; 
 642 } // end of wxNativeFontInfo::SetPointSize 
 644 void wxNativeFontInfo::SetStyle( 
 651             wxFAIL_MSG( _T("unknown font style") ); 
 654         case wxFONTSTYLE_NORMAL
: 
 657         case wxFONTSTYLE_ITALIC
: 
 658         case wxFONTSTYLE_SLANT
: 
 659             fa
.fsSelection 
|= FATTR_SEL_ITALIC
; 
 662 } // end of wxNativeFontInfo::SetStyle 
 664 void wxNativeFontInfo::SetWeight( 
 671             wxFAIL_MSG( _T("unknown font weight") ); 
 674         case wxFONTWEIGHT_NORMAL
: 
 675             fn
.usWeightClass 
= FWEIGHT_NORMAL
; 
 678         case wxFONTWEIGHT_LIGHT
: 
 679             fn
.usWeightClass 
= FWEIGHT_LIGHT
; 
 682         case wxFONTWEIGHT_BOLD
: 
 683             fn
.usWeightClass 
= FWEIGHT_BOLD
; 
 686 } // end of wxNativeFontInfo::SetWeight 
 688 void wxNativeFontInfo::SetUnderlined( 
 693         fa
.fsSelection 
|= FATTR_SEL_UNDERSCORE
; 
 694 } // end of wxNativeFontInfo::SetUnderlined 
 696 bool wxNativeFontInfo::SetFaceName( 
 697   const wxString
&                   sFacename
 
 700     wxStrncpy((wxChar
*)fa
.szFacename
, sFacename
, WXSIZEOF(fa
.szFacename
)); 
 702 } // end of wxNativeFontInfo::SetFaceName 
 704 void wxNativeFontInfo::SetFamily( 
 713             sFacename 
= wxT("Tms Rmn"); 
 717             sFacename 
= wxT("WarpSans"); 
 721             sFacename 
= wxT("Tms Rmn"); 
 725             sFacename 
= wxT("Courier") ; 
 729             sFacename 
= wxT("System VIO") ; 
 733             sFacename 
= wxT("Helv") ; 
 738             sFacename 
= wxT("System VIO") ; 
 741     if (!wxStrlen((wxChar
*)fa
.szFacename
) ) 
 743         SetFaceName(sFacename
); 
 745 } // end of wxNativeFontInfo::SetFamily 
 747 void wxNativeFontInfo::SetEncoding( wxFontEncoding eEncoding 
) 
 749     wxNativeEncodingInfo            vInfo
; 
 751     if ( !wxGetNativeFontEncoding( eEncoding
 
 755         if (wxFontMapper::Get()->GetAltForEncoding( eEncoding
 
 759             if (!vInfo
.facename
.empty()) 
 762                 // If we have this encoding only in some particular facename, use 
 763                 // the facename - it is better to show the correct characters in a 
 764                 // wrong facename than unreadable text in a correct one 
 766                 SetFaceName(vInfo
.facename
); 
 771             // unsupported encoding, replace with the default 
 775     fa
.usCodePage 
= (USHORT
)vInfo
.charset
; 
 776 } // end of wxNativeFontInfo::SetFaceName 
 778 bool wxNativeFontInfo::FromString( const wxString
& rsStr 
) 
 782     wxStringTokenizer               
vTokenizer(rsStr
, _T(";")); 
 787     wxString                        sToken 
= vTokenizer
.GetNextToken(); 
 789     if (sToken 
!= _T('0')) 
 792     sToken 
= vTokenizer
.GetNextToken(); 
 793     if (!sToken
.ToLong(&lVal
)) 
 797     sToken 
= vTokenizer
.GetNextToken(); 
 798     if (!sToken
.ToLong(&lVal
)) 
 800     fa
.lAveCharWidth 
= lVal
; 
 802     sToken 
= vTokenizer
.GetNextToken(); 
 803     if (!sToken
.ToLong(&lVal
)) 
 805     fa
.fsSelection 
= (USHORT
)lVal
; 
 807     sToken 
= vTokenizer
.GetNextToken(); 
 808     if (!sToken
.ToLong(&lVal
)) 
 810     fa
.fsType 
= (USHORT
)lVal
; 
 812     sToken 
= vTokenizer
.GetNextToken(); 
 813     if (!sToken
.ToLong(&lVal
)) 
 815     fa
.fsFontUse 
= (USHORT
)lVal
; 
 817     sToken 
= vTokenizer
.GetNextToken(); 
 818     if (!sToken
.ToLong(&lVal
)) 
 820     fa
.idRegistry 
= (USHORT
)lVal
; 
 822     sToken 
= vTokenizer
.GetNextToken(); 
 823     if (!sToken
.ToLong(&lVal
)) 
 825     fa
.usCodePage 
= (USHORT
)lVal
; 
 827     sToken 
= vTokenizer
.GetNextToken(); 
 828     if (!sToken
.ToLong(&lVal
)) 
 832     sToken 
= vTokenizer
.GetNextToken(); 
 833     if (!sToken
.ToLong(&lVal
)) 
 835     fn
.usWeightClass 
= (USHORT
)lVal
; 
 837     sToken 
= vTokenizer
.GetNextToken(); 
 840     wxStrcpy((wxChar
*)fa
.szFacename
, sToken
.c_str()); 
 842 } // end of wxNativeFontInfo::FromString 
 844 wxString 
wxNativeFontInfo::ToString() const 
 848     sStr
.Printf(_T("%d;%ld;%ld;%ld;%d;%d;%d;%d;%d;%ld;%d;%s"), 
 849                 0, // version, in case we want to change the format later 
 860                 (char *)fa
.szFacename
); 
 862 } // end of wxNativeFontInfo::ToString 
 864 // ---------------------------------------------------------------------------- 
 866 // ---------------------------------------------------------------------------- 
 868 bool wxFont::Create( const wxNativeFontInfo
& rInfo
, 
 872     m_refData 
= new wxFontRefData( rInfo
 
 877 } // end of wxFont::Create 
 880   const wxString
&                   rsFontdesc
 
 883     wxNativeFontInfo                vInfo
; 
 885     if (vInfo
.FromString(rsFontdesc
)) 
 887 } // end of wxFont::wxFont 
 889 // ---------------------------------------------------------------------------- 
 890 // Constructor for a font. Note that the real construction is done 
 891 // in wxDC::SetFont, when information is available about scaling etc. 
 892 // ---------------------------------------------------------------------------- 
 893 bool wxFont::Create( int             nPointSize
, 
 898                      const wxString
& rsFaceName
, 
 899                      wxFontEncoding  vEncoding 
) 
 904     // wxDEFAULT is a valid value for the font size too so we must treat it 
 905     // specially here (otherwise the size would be 70 == wxDEFAULT value) 
 907     if (nPointSize 
== wxDEFAULT
) 
 909         nPointSize 
= wxNORMAL_FONT
->GetPointSize(); 
 911     m_refData 
= new wxFontRefData( nPointSize
 
 921 } // end of wxFont::Create 
 925 } // end of wxFont::~wxFont 
 927 // ---------------------------------------------------------------------------- 
 928 // real implementation 
 929 // Boris' Kovalenko comments: 
 930 //   Because OS/2 fonts are associated with PS we can not create the font 
 931 //   here, but we may check that font definition is true 
 932 // ---------------------------------------------------------------------------- 
 934 bool wxFont::RealizeResource() 
 936     if ( GetResourceHandle() ) 
 940     return M_FONTDATA
->Alloc(this); 
 941 } // end of wxFont::RealizeResource 
 943 bool wxFont::FreeResource( bool WXUNUSED(bForce
) ) 
 945     if (GetResourceHandle()) 
 951 } // end of wxFont::FreeResource 
 953 WXHANDLE 
wxFont::GetResourceHandle() const 
 956 } // end of wxFont::GetResourceHandle 
 958 WXHFONT 
wxFont::GetHFONT() const 
 960     return M_FONTDATA 
? M_FONTDATA
->GetHFONT() : 0; 
 961 } // end of wxFont::GetHFONT 
 963 bool wxFont::IsFree() const 
 965     return M_FONTDATA 
&& (M_FONTDATA
->GetHFONT() == 0); 
 966 } // end of wxFont::IsFree 
 968 void wxFont::Unshare() 
 970     // Don't change shared data 
 973         m_refData 
= new wxFontRefData(); 
 977         wxFontRefData
* ref 
= new wxFontRefData(*M_FONTDATA
); 
 981 } // end of wxFont::Unshare 
 983 // ---------------------------------------------------------------------------- 
 984 // change font attribute: we recreate font when doing it 
 985 // ---------------------------------------------------------------------------- 
 987 void wxFont::SetPointSize( 
 993     M_FONTDATA
->SetPointSize(nPointSize
); 
 996 } // end of wxFont::SetPointSize 
 998 void wxFont::SetFamily( 
1004     M_FONTDATA
->SetFamily(nFamily
); 
1007 } // end of wxFont::SetFamily 
1009 void wxFont::SetStyle( 
1015     M_FONTDATA
->SetStyle(nStyle
); 
1018 } // end of wxFont::SetStyle 
1020 void wxFont::SetWeight( 
1026     M_FONTDATA
->SetWeight(nWeight
); 
1029 } // end of wxFont::SetWeight 
1031 bool wxFont::SetFaceName( 
1032   const wxString
&                   rsFaceName
 
1037     bool refdataok 
= M_FONTDATA
->SetFaceName(rsFaceName
); 
1041     return refdataok 
&& wxFontBase::SetFaceName(rsFaceName
); 
1042 } // end of wxFont::SetFaceName 
1044 void wxFont::SetUnderlined( 
1050     M_FONTDATA
->SetUnderlined(bUnderlined
); 
1053 } // end of wxFont::SetUnderlined 
1055 void wxFont::SetEncoding( 
1056   wxFontEncoding                    vEncoding
 
1061     M_FONTDATA
->SetEncoding(vEncoding
); 
1064 } // end of wxFont::SetEncoding 
1066 void wxFont::DoSetNativeFontInfo( 
1067   const wxNativeFontInfo
&           rInfo
 
1074     *M_FONTDATA 
= wxFontRefData(rInfo
); 
1079 // ---------------------------------------------------------------------------- 
1081 // ---------------------------------------------------------------------------- 
1083 int wxFont::GetPointSize() const 
1085     wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); 
1087     return M_FONTDATA
->GetPointSize(); 
1088 } // end of wxFont::GetPointSize 
1090 int wxFont::GetFamily() const 
1092     wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); 
1094     return M_FONTDATA
->GetFamily(); 
1095 } // end of wxFont::GetFamily 
1097 int wxFont::GetStyle() const 
1099     wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); 
1101     return M_FONTDATA
->GetStyle(); 
1102 } // end of wxFont::GetStyle 
1104 int wxFont::GetWeight() const 
1106     wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); 
1108     return M_FONTDATA
->GetWeight(); 
1111 bool wxFont::GetUnderlined() const 
1113     wxCHECK_MSG( Ok(), false, wxT("invalid font") ); 
1115     return M_FONTDATA
->GetUnderlined(); 
1116 } // end of wxFont::GetUnderlined 
1118 wxString 
wxFont::GetFaceName() const 
1120     wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") ); 
1122     return M_FONTDATA
->GetFaceName(); 
1123 } // end of wxFont::GetFaceName 
1125 wxFontEncoding 
wxFont::GetEncoding() const 
1127     wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") ); 
1129     return M_FONTDATA
->GetEncoding(); 
1130 } // end of wxFont::GetEncoding 
1132 const wxNativeFontInfo
* wxFont::GetNativeFontInfo() const 
1134     return M_FONTDATA
->HasNativeFontInfo() ? &(M_FONTDATA
->GetNativeFontInfo()) 
1136 } // end of wxFont::GetNativeFontInfo 
1139 // Internal use only method to set the FONTMETRICS array 
1141 void wxFont::SetFM( PFONTMETRICS pFM
, int nNumFonts 
) 
1143     M_FONTDATA
->SetFM(pFM
); 
1144     M_FONTDATA
->SetNumFonts(nNumFonts
); 
1145 } // end of wxFont::SetFM 
1148 void wxFont::SetPS( HPS hPS 
) 
1152     M_FONTDATA
->SetPS(hPS
); 
1155 } // end of wxFont::SetPS