]>
git.saurik.com Git - wxWidgets.git/blob - src/mgl/fontmgr.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mgl/fontmgr.cpp
3 // Purpose: font management for wxMGL
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
8 // (c) 2006 REA Elektronik GmbH
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/private/fontmgr.h"
20 #include "wx/sysopt.h"
24 static int gs_antialiasingThreshold
= -1;
26 // ============================================================================
28 // ============================================================================
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 wxFontInstance::wxFontInstance(float ptSize
, bool aa
, font_lib_t
*fontLib
)
35 : wxFontInstanceBase(ptSize
, aa
)
37 m_font
= MGL_loadFontInstance(fontLib
, ptSize
, 0.0, 0.0, aa
);
39 wxASSERT_MSG( m_font
, _T("cannot create font instance") );
42 wxFontInstance::~wxFontInstance()
45 MGL_unloadFontInstance(m_font
);
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 void wxFontFace::Acquire()
54 wxFontFaceBase::Acquire();
58 wxCHECK_RET( m_fontLib
== NULL
, _T("font lib already created") );
60 wxLogTrace("mgl_font", "opening library '%s'", m_fileName
.mb_str());
61 m_fontLib
= MGL_openFontLib(m_fileName
.fn_str());
65 void wxFontFace::Release()
67 wxFontFaceBase::Release();
71 wxCHECK_RET( m_fontLib
!= NULL
, _T("font lib not created") );
73 wxLogTrace("mgl_font", "closing library '%s'", m_fileName
.mb_str());
74 MGL_closeFontLib(m_fontLib
);
79 wxFontInstance
*wxFontFace::GetFontInstance(float ptSize
, bool aa
)
81 if ( gs_antialiasingThreshold
== -1 )
83 gs_antialiasingThreshold
= 10;
84 #if wxUSE_SYSTEM_OPTIONS
85 if ( wxSystemOptions::HasOption(wxT("mgl.aa-threshold")) )
86 gs_antialiasingThreshold
=
87 wxSystemOptions::GetOptionInt(wxT("mgl.aa-threshold"));
88 wxLogTrace("mgl_font", "AA threshold set to %i", gs_antialiasingThreshold
);
92 // Small characters don't look good when antialiased with the algorithm
93 // that FreeType uses (mere 2x2 supersampling), so lets disable AA
94 // completely for small fonts. Bitmap fonts are not antialiased either.
95 if ( ptSize
<= gs_antialiasingThreshold
||
96 m_fontLib
->fontLibType
== MGL_BITMAPFONT_LIB
)
101 return wxFontFaceBase::GetFontInstance(ptSize
, aa
);
104 wxFontInstance
*wxFontFace::CreateFontInstance(float ptSize
, bool aa
)
106 wxASSERT_MSG( m_fontLib
, _T("font library not loaded!") );
108 return new wxFontInstance(ptSize
, aa
, m_fontLib
);
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
115 wxFontBundle::wxFontBundle(const font_info_t
*info
)
118 if ( info
->regularFace
[0] != '\0' )
119 m_faces
[FaceType_Regular
] = new wxFontFace(info
->regularFace
);
121 if ( info
->italicFace
[0] != '\0' )
122 m_faces
[FaceType_Italic
] = new wxFontFace(info
->italicFace
);
124 if ( info
->boldFace
[0] != '\0' )
125 m_faces
[FaceType_Bold
] = new wxFontFace(info
->boldFace
);
127 if ( info
->boldItalicFace
[0] != '\0' )
128 m_faces
[FaceType_BoldItalic
] = new wxFontFace(info
->boldItalicFace
);
130 wxLogTrace("mgl_font", "new family '%s' (r=%s, i=%s, b=%s, bi=%s)\n",
131 info
->familyName
, info
->regularFace
, info
->italicFace
,
132 info
->boldFace
, info
->boldItalicFace
);
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
139 wxString
wxFontsManager::GetDefaultFacename(wxFontFamily family
) const
146 return _T("Charter");
151 return _T("Courier");
155 return wxT("Helvetica");
159 static ibool MGLAPI
enum_callback(const font_info_t
*info
, void *cookie
)
161 wxFontsManager
*db
= (wxFontsManager
*)cookie
;
162 db
->AddBundle(new wxFontBundle(info
));
166 void wxFontsManager::AddAllFonts()
168 MGL_enumerateFonts(enum_callback
, (void*)this);