1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        msw/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 // ---------------------------------------------------------------------------- 
  21     #pragma implementation "fontenum.h" 
  24 // For compilers that support precompilation, includes "wx.h". 
  25 #include "wx/wxprec.h" 
  33 #include "wx/fontenum.h" 
  34 #include "wx/fontmap.h" 
  35 #include "wx/encinfo.h" 
  37 #include "wx/os2/private.h" 
  39 // ---------------------------------------------------------------------------- 
  41 // ---------------------------------------------------------------------------- 
  43 class wxFontEnumeratorHelper
 
  46     wxFontEnumeratorHelper(wxFontEnumerator 
*fontEnum
); 
  48     // control what exactly are we enumerating 
  49     bool SetEncoding(wxFontEncoding encoding
); 
  50     void SetFixedOnly(bool fixedOnly
) 
  51         { m_fixedOnly 
= fixedOnly
; } 
  53     // call to start enumeration 
  56     // called by our font enumeration proc 
  57     bool OnFont(/*const LPLOGFONT lf, const LPTEXTMETRIC tm*/) const; 
  60     // the object we forward calls to OnFont() to 
  61     wxFontEnumerator 
*m_fontEnum
; 
  63     // if != -1, enum only fonts which have this encoding 
  66     // if not empty, enum only the fonts with this facename 
  69     // if TRUE, enum only fixed fonts 
  73 // ---------------------------------------------------------------------------- 
  75 // ---------------------------------------------------------------------------- 
  79 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm, 
  80                                   DWORD dwStyle, LONG lParam); 
  83 // ============================================================================ 
  85 // ============================================================================ 
  87 // ---------------------------------------------------------------------------- 
  88 // wxFontEnumeratorHelper 
  89 // ---------------------------------------------------------------------------- 
  91 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator 
*fontEnum
) 
  93     m_fontEnum 
= fontEnum
; 
  98 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
) 
 100     wxNativeEncodingInfo info
; 
 101     if ( !wxGetNativeFontEncoding(encoding
, &info
) ) 
 103         if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) ) 
 105             // no such encodings at all 
 109     m_charset 
= info
.charset
; 
 110     m_facename 
= info
.facename
; 
 115 #define wxFONTENUMPROC FONTENUMPROC 
 117 void wxFontEnumeratorHelper::DoEnumerate() 
 121     HDC hDC = ::GetDC(NULL); 
 125     lf.lfCharSet = m_charset; 
 126     wxStrncpy(lf.lfFaceName, m_facename, WXSIZEOF(lf.lfFaceName)); 
 127     lf.lfPitchAndFamily = 0; 
 128     ::EnumFontFamiliesEx(hDC, &lf, (wxFONTENUMPROC)wxFontEnumeratorProc, 
 131     ::EnumFonts(hDC, (LPTSTR)NULL, (FONTENUMPROC)wxFontEnumeratorProc, 
 140     ::ReleaseDC(NULL, hDC); 
 144 bool wxFontEnumeratorHelper::OnFont(/*const LPLOGFONT lf, 
 145                                       const LPTEXTMETRIC tm */) const 
 151         // check that it's a fixed pitch font (there is *no* error here, the 
 152         // flag name is misleading!) 
 153         if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH ) 
 155             // not a fixed pitch font 
 160     if ( m_charset != -1 ) 
 162         // check that we have the right encoding 
 163         if ( lf->lfCharSet != m_charset ) 
 169     return m_fontEnum->OnFacename(lf->lfFaceName); 
 174 // ---------------------------------------------------------------------------- 
 176 // ---------------------------------------------------------------------------- 
 178 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
, 
 181     wxFontEnumeratorHelper 
fe(this); 
 182     if ( fe
.SetEncoding(encoding
) ) 
 184         fe
.SetFixedOnly(fixedWidthOnly
); 
 188     // else: no such fonts, unknown encoding 
 193 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
) 
 195     wxFAIL_MSG(wxT("TODO")); 
 200 // ---------------------------------------------------------------------------- 
 202 // ---------------------------------------------------------------------------- 
 206 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm, 
 207                                   DWORD dwStyle, LONG lParam) 
 209     // Get rid of any fonts that we don't want... 
 210     if ( dwStyle != TRUETYPE_FONTTYPE ) 
 212         // continue enumeration 
 216     wxFontEnumeratorHelper *fontEnum = (wxFontEnumeratorHelper *)lParam; 
 218     return fontEnum->OnFont(lplf, lptm); 
 222 #endif // wxUSE_FONTMAP