]> git.saurik.com Git - wxWidgets.git/blob - src/mgl/fontmgr.cpp
Don't specialize std::numeric_limits<> for wxLongLong when using VC6.
[wxWidgets.git] / src / mgl / fontmgr.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mgl/fontmgr.cpp
3 // Purpose: font management for wxMGL
4 // Author: Vaclav Slavik
5 // Created: 2006-11-18
6 // RCS-ID: $Id$
7 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
8 // (c) 2006 REA Elektronik GmbH
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/log.h"
21 #endif
22
23 #include "wx/private/fontmgr.h"
24 #include "wx/sysopt.h"
25
26 #include <mgraph.h>
27
28 static int gs_antialiasingThreshold = -1;
29
30 // ============================================================================
31 // implementation
32 // ============================================================================
33
34 // ----------------------------------------------------------------------------
35 // wxFontInstance
36 // ----------------------------------------------------------------------------
37
38 wxFontInstance::wxFontInstance(float ptSize, bool aa, font_lib_t *fontLib)
39 : wxFontInstanceBase(ptSize, aa)
40 {
41 m_font = MGL_loadFontInstance(fontLib, ptSize, 0.0, 0.0, aa);
42
43 wxASSERT_MSG( m_font, wxT("cannot create font instance") );
44 }
45
46 wxFontInstance::~wxFontInstance()
47 {
48 if ( m_font )
49 MGL_unloadFontInstance(m_font);
50 }
51
52 // ----------------------------------------------------------------------------
53 // wxFontFace
54 // ----------------------------------------------------------------------------
55
56 void wxFontFace::Acquire()
57 {
58 wxFontFaceBase::Acquire();
59
60 if ( m_refCnt == 1 )
61 {
62 wxCHECK_RET( m_fontLib == NULL, wxT("font lib already created") );
63
64 wxLogTrace("mgl_font", "opening library '%s'", m_fileName.mb_str());
65 m_fontLib = MGL_openFontLib(m_fileName.fn_str());
66 }
67 }
68
69 void wxFontFace::Release()
70 {
71 wxFontFaceBase::Release();
72
73 if ( m_refCnt == 0 )
74 {
75 wxCHECK_RET( m_fontLib != NULL, wxT("font lib not created") );
76
77 wxLogTrace("mgl_font", "closing library '%s'", m_fileName.mb_str());
78 MGL_closeFontLib(m_fontLib);
79 m_fontLib = NULL;
80 }
81 }
82
83 wxFontInstance *wxFontFace::GetFontInstance(float ptSize, bool aa)
84 {
85 if ( gs_antialiasingThreshold == -1 )
86 {
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);
93 #endif
94 }
95
96 // Small characters don't look good when antialiased with the algorithm
97 // that FreeType uses (mere 2x2 supersampling), so let's 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 )
101 {
102 aa = false;
103 }
104
105 return wxFontFaceBase::GetFontInstance(ptSize, aa);
106 }
107
108 wxFontInstance *wxFontFace::CreateFontInstance(float ptSize, bool aa)
109 {
110 wxASSERT_MSG( m_fontLib, wxT("font library not loaded!") );
111
112 return new wxFontInstance(ptSize, aa, m_fontLib);
113 }
114
115 // ----------------------------------------------------------------------------
116 // wxFontBundle
117 // ----------------------------------------------------------------------------
118
119 wxFontBundle::wxFontBundle(const font_info_t *info)
120 : m_fontInfo(info)
121 {
122 if ( info->regularFace[0] != '\0' )
123 m_faces[FaceType_Regular] = new wxFontFace(info->regularFace);
124
125 if ( info->italicFace[0] != '\0' )
126 m_faces[FaceType_Italic] = new wxFontFace(info->italicFace);
127
128 if ( info->boldFace[0] != '\0' )
129 m_faces[FaceType_Bold] = new wxFontFace(info->boldFace);
130
131 if ( info->boldItalicFace[0] != '\0' )
132 m_faces[FaceType_BoldItalic] = new wxFontFace(info->boldItalicFace);
133
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);
137 }
138
139 wxString wxFontBundle::GetName() const
140 {
141 return wxString::FromAscii(m_fontInfo->familyName);
142 }
143
144 bool wxFontBundle::IsFixed() const
145 {
146 return m_fontInfo->isFixed;
147 }
148
149
150 // ----------------------------------------------------------------------------
151 // wxFontsManager
152 // ----------------------------------------------------------------------------
153
154 wxString wxFontsManager::GetDefaultFacename(wxFontFamily family) const
155 {
156 switch ( family )
157 {
158 case wxSCRIPT:
159 return wxT("Script");
160 case wxDECORATIVE:
161 return wxT("Charter");
162 case wxROMAN:
163 return wxT("Times");
164 case wxTELETYPE:
165 case wxMODERN:
166 return wxT("Courier");
167 case wxSWISS:
168 case wxDEFAULT:
169 default:
170 return wxT("Helvetica");
171 }
172 }
173
174 static ibool MGLAPI enum_callback(const font_info_t *info, void *cookie)
175 {
176 wxFontsManager *db = (wxFontsManager*)cookie;
177 db->AddBundle(new wxFontBundle(info));
178 return TRUE;
179 }
180
181 void wxFontsManager::AddAllFonts()
182 {
183 MGL_enumerateFonts(enum_callback, (void*)this);
184 }