1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/os2/fontenum.cpp 
   3 // Purpose:     wxFontEnumerator class for Windows 
   4 // Author:      Julian Smart 
   5 // Modified by: David Webster to add support for font encodings 
   8 // Copyright:   (c) Julian Smart 
   9 // Licence:     wxWindows licence 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  20 // For compilers that support precompilation, includes "wx.h". 
  21 #include "wx/wxprec.h" 
  25 #include "wx/fontenum.h" 
  31 #include "wx/fontmap.h" 
  32 #include "wx/encinfo.h" 
  34 #include "wx/os2/private.h" 
  36 // ---------------------------------------------------------------------------- 
  38 // ---------------------------------------------------------------------------- 
  40 class wxFontEnumeratorHelper
 
  43     wxFontEnumeratorHelper(wxFontEnumerator 
*fontEnum
); 
  45     // control what exactly are we enumerating 
  46     bool SetEncoding(wxFontEncoding encoding
); 
  47     void SetFixedOnly(bool fixedOnly
) 
  48         { m_fixedOnly 
= fixedOnly
; } 
  50     // call to start enumeration 
  53     // called by our font enumeration proc 
  54     bool OnFont(/*const LPLOGFONT lf, const LPTEXTMETRIC tm*/) const; 
  57     // the object we forward calls to OnFont() to 
  58     wxFontEnumerator 
*m_fontEnum
; 
  60     // if != -1, enum only fonts which have this encoding 
  63     // if not empty, enum only the fonts with this facename 
  66     // if true, enum only fixed fonts 
  70 // ---------------------------------------------------------------------------- 
  72 // ---------------------------------------------------------------------------- 
  76 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm, 
  77                                   DWORD dwStyle, LONG lParam); 
  80 // ============================================================================ 
  82 // ============================================================================ 
  84 // ---------------------------------------------------------------------------- 
  85 // wxFontEnumeratorHelper 
  86 // ---------------------------------------------------------------------------- 
  88 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator 
*fontEnum
) 
  90     m_fontEnum 
= fontEnum
; 
  95 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
) 
  97     wxNativeEncodingInfo info
; 
  98     if ( !wxGetNativeFontEncoding(encoding
, &info
) ) 
 100         if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) ) 
 102             // no such encodings at all 
 106     m_charset 
= info
.charset
; 
 107     m_facename 
= info
.facename
; 
 112 #define wxFONTENUMPROC FONTENUMPROC 
 114 void wxFontEnumeratorHelper::DoEnumerate() 
 118     HDC hDC = ::GetDC(NULL); 
 122     lf.lfCharSet = m_charset; 
 123     wxStrlcpy(lf.lfFaceName, m_facename, WXSIZEOF(lf.lfFaceName)); 
 124     lf.lfPitchAndFamily = 0; 
 125     ::EnumFontFamiliesEx(hDC, &lf, (wxFONTENUMPROC)wxFontEnumeratorProc, 
 128     ::EnumFonts(hDC, (LPTSTR)NULL, (FONTENUMPROC)wxFontEnumeratorProc, 
 137     ::ReleaseDC(NULL, hDC); 
 141 bool wxFontEnumeratorHelper::OnFont(/*const LPLOGFONT lf, 
 142                                       const LPTEXTMETRIC tm */) const 
 148         // check that it's a fixed pitch font (there is *no* error here, the 
 149         // flag name is misleading!) 
 150         if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH ) 
 152             // not a fixed pitch font 
 157     if ( m_charset != -1 ) 
 159         // check that we have the right encoding 
 160         if ( lf->lfCharSet != m_charset ) 
 166     return m_fontEnum->OnFacename(lf->lfFaceName); 
 171 // ---------------------------------------------------------------------------- 
 173 // ---------------------------------------------------------------------------- 
 175 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
, 
 178     wxFontEnumeratorHelper 
fe(this); 
 179     if ( fe
.SetEncoding(encoding
) ) 
 181         fe
.SetFixedOnly(fixedWidthOnly
); 
 185     // else: no such fonts, unknown encoding 
 190 bool wxFontEnumerator::EnumerateEncodings(const wxString
& WXUNUSED(family
)) 
 192     wxFAIL_MSG(wxT("TODO")); 
 197 // ---------------------------------------------------------------------------- 
 199 // ---------------------------------------------------------------------------- 
 203 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm, 
 204                                   DWORD dwStyle, LONG lParam) 
 206     // Get rid of any fonts that we don't want... 
 207     if ( dwStyle != TRUETYPE_FONTTYPE ) 
 209         // continue enumeration 
 213     wxFontEnumeratorHelper *fontEnum = (wxFontEnumeratorHelper *)lParam; 
 215     return fontEnum->OnFont(lplf, lptm); 
 219 #endif // wxUSE_FONTMAP