]>
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"
23 #include "wx/private/fontmgr.h"
24 #include "wx/sysopt.h"
28 static int gs_antialiasingThreshold
= -1;
30 // ============================================================================
32 // ============================================================================
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 wxFontInstance::wxFontInstance(float ptSize
, bool aa
, font_lib_t
*fontLib
)
39 : wxFontInstanceBase(ptSize
, aa
)
41 m_font
= MGL_loadFontInstance(fontLib
, ptSize
, 0.0, 0.0, aa
);
43 wxASSERT_MSG( m_font
, wxT("cannot create font instance") );
46 wxFontInstance::~wxFontInstance()
49 MGL_unloadFontInstance(m_font
);
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 void wxFontFace::Acquire()
58 wxFontFaceBase::Acquire();
62 wxCHECK_RET( m_fontLib
== NULL
, wxT("font lib already created") );
64 wxLogTrace("mgl_font", "opening library '%s'", m_fileName
.mb_str());
65 m_fontLib
= MGL_openFontLib(m_fileName
.fn_str());
69 void wxFontFace::Release()
71 wxFontFaceBase::Release();
75 wxCHECK_RET( m_fontLib
!= NULL
, wxT("font lib not created") );
77 wxLogTrace("mgl_font", "closing library '%s'", m_fileName
.mb_str());
78 MGL_closeFontLib(m_fontLib
);
83 wxFontInstance
*wxFontFace::GetFontInstance(float ptSize
, bool aa
)
85 if ( gs_antialiasingThreshold
== -1 )
87 gs_antialiasingThreshold
= 10;
88 #if wxUSE_SYSTEM_OPTIONS
89 if ( wxSystemOptions::HasOption(wxT("mgl.aa-threshold")) )
90 gs_antialiasingThreshold
=
91 wxSystemOptions::GetOptionInt(wxT("mgl.aa-threshold"));
92 wxLogTrace("mgl_font", "AA threshold set to %i", gs_antialiasingThreshold
);
96 // Small characters don't look good when antialiased with the algorithm
97 // that FreeType uses (mere 2x2 supersampling), so lets disable AA
98 // completely for small fonts. Bitmap fonts are not antialiased either.
99 if ( ptSize
<= gs_antialiasingThreshold
||
100 m_fontLib
->fontLibType
== MGL_BITMAPFONT_LIB
)
105 return wxFontFaceBase::GetFontInstance(ptSize
, aa
);
108 wxFontInstance
*wxFontFace::CreateFontInstance(float ptSize
, bool aa
)
110 wxASSERT_MSG( m_fontLib
, wxT("font library not loaded!") );
112 return new wxFontInstance(ptSize
, aa
, m_fontLib
);
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
119 wxFontBundle::wxFontBundle(const font_info_t
*info
)
122 if ( info
->regularFace
[0] != '\0' )
123 m_faces
[FaceType_Regular
] = new wxFontFace(info
->regularFace
);
125 if ( info
->italicFace
[0] != '\0' )
126 m_faces
[FaceType_Italic
] = new wxFontFace(info
->italicFace
);
128 if ( info
->boldFace
[0] != '\0' )
129 m_faces
[FaceType_Bold
] = new wxFontFace(info
->boldFace
);
131 if ( info
->boldItalicFace
[0] != '\0' )
132 m_faces
[FaceType_BoldItalic
] = new wxFontFace(info
->boldItalicFace
);
134 wxLogTrace("mgl_font", "new family '%s' (r=%s, i=%s, b=%s, bi=%s)\n",
135 info
->familyName
, info
->regularFace
, info
->italicFace
,
136 info
->boldFace
, info
->boldItalicFace
);
139 wxString
wxFontBundle::GetName() const
141 return wxString::FromAscii(m_fontInfo
->familyName
);
144 bool wxFontBundle::IsFixed() const
146 return m_fontInfo
->isFixed
;
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
154 wxString
wxFontsManager::GetDefaultFacename(wxFontFamily family
) const
159 return wxT("Script");
161 return wxT("Charter");
166 return wxT("Courier");
170 return wxT("Helvetica");
174 static ibool MGLAPI
enum_callback(const font_info_t
*info
, void *cookie
)
176 wxFontsManager
*db
= (wxFontsManager
*)cookie
;
177 db
->AddBundle(new wxFontBundle(info
));
181 void wxFontsManager::AddAllFonts()
183 MGL_enumerateFonts(enum_callback
, (void*)this);