]>
git.saurik.com Git - wxWidgets.git/blob - src/dfb/fontmgr.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/fontmgr.cpp
3 // Purpose: font management for wxDFB
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/fileconf.h"
20 #include "wx/filename.h"
22 #include "wx/private/fontmgr.h"
23 #include "wx/dfb/wrapdfb.h"
25 // ============================================================================
27 // ============================================================================
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 wxFontInstance::wxFontInstance(float ptSize
, bool aa
,
34 const wxString
& filename
)
35 : wxFontInstanceBase(ptSize
, aa
)
37 int scrSizePx
, scrSizeMM
;
38 wxDisplaySize(NULL
, &scrSizePx
);
39 wxDisplaySizeMM(NULL
, &scrSizeMM
);
40 double dpi
= (scrSizePx
/ (scrSizeMM
* mm2inches
));
41 // NB: DFB's fract_height value is 32bit integer with the last 6 bit
42 // representing fractional value, hence the multiplication by 64;
43 // 1pt=1/72inch, hence "/ 72"
44 int pixSize
= int(ptSize
* dpi
* 64 / 72);
46 DFBFontDescription desc
;
47 desc
.flags
= (DFBFontDescriptionFlags
)(
48 DFDESC_ATTRIBUTES
| DFDESC_FRACT_HEIGHT
);
49 desc
.attributes
= aa
? DFFA_NONE
: DFFA_MONOCHROME
;
50 desc
.fract_height
= pixSize
;
51 m_font
= wxIDirectFB::Get()->CreateFont(filename
.fn_str(), &desc
);
53 wxASSERT_MSG( m_font
, _T("cannot create font instance") );
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 wxFontInstance
*wxFontFace::CreateFontInstance(float ptSize
, bool aa
)
62 return new wxFontInstance(ptSize
, aa
, m_fileName
);
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 wxFontBundle::wxFontBundle(const wxString
& name
,
70 const wxString
& fileRegular
,
71 const wxString
& fileBold
,
72 const wxString
& fileItalic
,
73 const wxString
& fileBoldItalic
,
79 if ( !fileRegular
.empty() )
80 m_faces
[FaceType_Regular
] = new wxFontFace(fileRegular
);
81 if ( !fileItalic
.empty() )
82 m_faces
[FaceType_Italic
] = new wxFontFace(fileItalic
);
83 if ( !fileBold
.empty() )
84 m_faces
[FaceType_Bold
] = new wxFontFace(fileBold
);
85 if ( !fileBoldItalic
.empty() )
86 m_faces
[FaceType_BoldItalic
] = new wxFontFace(fileBoldItalic
);
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
94 The code below parses font configuration file ${WXDFB_FONTDIR}/FontsIndex.
95 By default, the directory is $prefix/share/wx/fonts, but can be ovewritten
96 by setting WXDFB_FONTDIR environment variable.
98 The file is standard wxFileConfig file text file. Each toplevel group
99 specifies one font bundle, font's name is the name of group. Group's entries
103 # font files (at least one of them must be present):
104 Regular=RegularFaceFile.ttf
105 Italic=ItalicFaceFile.ttf
106 Bold=BoldFaceFile.ttf
107 BoldItalic=BoldItalicFaceFile.ttf
108 # optional tag indicating this font is fixed-with (default is false):
111 Additionally, there may be DefaultXXX entries at the toplevel for every
112 family XXX and a Default entry that is shortcut for setting all families'
113 default, their value is name of the default font:
115 # optional tags indicating the default font for given family:
116 DefaultDecorative=Font Name
117 DefaultRoman=Font Name
118 DefaultScript=Font Name
119 DefaultSwiss=Font Name
120 DefaultModern=Font Name
121 DefaultTeletype=Font Name
122 # indicate the font that is default for all families (optional):
126 void wxFontsManager::AddAllFonts()
128 wxString dir
= _T(wxINSTALL_PREFIX
"/share/wx/fonts");
129 wxGetEnv(_T("WXDFB_FONTDIR"), &dir
);
131 wxString indexFile
= dir
+ _T("/FontsIndex");
133 if ( !wxFileName::FileExists(indexFile
) )
135 wxLogWarning(_("No fonts found in %s"), dir
.c_str());
139 wxLogTrace(_T("font"), _T("adding fonts from %s"), dir
.c_str());
141 wxFileConfig
cfg(wxEmptyString
, wxEmptyString
,
142 indexFile
, wxEmptyString
,
143 wxCONFIG_USE_LOCAL_FILE
);
147 for ( bool cont
= cfg
.GetFirstGroup(name
, i
);
149 cont
= cfg
.GetNextGroup(name
, i
) )
151 AddFont(dir
, name
, cfg
);
154 // set default fonts for families:
155 SetDefaultFonts(cfg
);
159 ReadFilePath(const wxString
& name
, const wxString
& dir
, wxFileConfig
& cfg
)
161 wxString p
= cfg
.Read(name
, wxEmptyString
);
163 if ( p
.empty() || wxFileName(p
).IsAbsolute() )
166 return dir
+ _T("/") + p
;
169 void wxFontsManager::AddFont(const wxString
& dir
,
170 const wxString
& name
,
173 wxLogTrace(_T("font"), _T("adding font '%s'"), name
.c_str());
175 wxConfigPathChanger
ch(&cfg
, wxString::Format(_T("/%s/"), name
.c_str()));
182 ReadFilePath(_T("Regular"), dir
, cfg
),
183 ReadFilePath(_T("Italic"), dir
, cfg
),
184 ReadFilePath(_T("Bold"), dir
, cfg
),
185 ReadFilePath(_T("BoldItalic"), dir
, cfg
),
186 cfg
.Read(_T("IsFixed"), (long)false)
191 void wxFontsManager::SetDefaultFonts(wxFileConfig
& cfg
)
195 if ( cfg
.Read(_T("Default"), &name
) )
197 m_defaultFacenames
[wxFONTFAMILY_DECORATIVE
] =
198 m_defaultFacenames
[wxFONTFAMILY_ROMAN
] =
199 m_defaultFacenames
[wxFONTFAMILY_SCRIPT
] =
200 m_defaultFacenames
[wxFONTFAMILY_SWISS
] =
201 m_defaultFacenames
[wxFONTFAMILY_MODERN
] =
202 m_defaultFacenames
[wxFONTFAMILY_TELETYPE
] = name
;
205 if ( cfg
.Read(_T("DefaultDecorative"), &name
) )
206 m_defaultFacenames
[wxFONTFAMILY_DECORATIVE
] = name
;
207 if ( cfg
.Read(_T("DefaultRoman"), &name
) )
208 m_defaultFacenames
[wxFONTFAMILY_ROMAN
] = name
;
209 if ( cfg
.Read(_T("DefaultScript"), &name
) )
210 m_defaultFacenames
[wxFONTFAMILY_SCRIPT
] = name
;
211 if ( cfg
.Read(_T("DefaultSwiss"), &name
) )
212 m_defaultFacenames
[wxFONTFAMILY_SWISS
] = name
;
213 if ( cfg
.Read(_T("DefaultModern"), &name
) )
214 m_defaultFacenames
[wxFONTFAMILY_MODERN
] = name
;
215 if ( cfg
.Read(_T("DefaultTeletype"), &name
) )
216 m_defaultFacenames
[wxFONTFAMILY_TELETYPE
] = name
;