X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cc096b11ea824104eff93744eb7ef7072510e5ac..f0eebb39bc6bb54441e695b3c1b1e0bea6ab5c01:/src/dfb/fontmgr.cpp?ds=sidebyside diff --git a/src/dfb/fontmgr.cpp b/src/dfb/fontmgr.cpp index 1bc84cac58..3913b995f8 100644 --- a/src/dfb/fontmgr.cpp +++ b/src/dfb/fontmgr.cpp @@ -37,6 +37,11 @@ // wxFontInstance // ---------------------------------------------------------------------------- +// This is a fake "filename" for DirectFB's builtin font (which isn't loaded +// from a file); we can't use empty string, because that's already used for +// "this face is not available" by wxFontsManagerBase +#define BUILTIN_DFB_FONT_FILENAME "/dev/null" + wxFontInstance::wxFontInstance(float ptSize, bool aa, const wxString& filename) : wxFontInstanceBase(ptSize, aa) @@ -55,9 +60,13 @@ wxFontInstance::wxFontInstance(float ptSize, bool aa, DFDESC_ATTRIBUTES | DFDESC_FRACT_HEIGHT); desc.attributes = aa ? DFFA_NONE : DFFA_MONOCHROME; desc.fract_height = pixSize; - m_font = wxIDirectFB::Get()->CreateFont(filename.fn_str(), &desc); - wxASSERT_MSG( m_font, _T("cannot create font instance") ); + if ( filename == BUILTIN_DFB_FONT_FILENAME ) + m_font = wxIDirectFB::Get()->CreateFont(NULL, &desc); + else + m_font = wxIDirectFB::Get()->CreateFont(filename.fn_str(), &desc); + + wxASSERT_MSG( m_font, "cannot create font instance" ); } // ---------------------------------------------------------------------------- @@ -136,7 +145,7 @@ wxFontBundle::wxFontBundle(const wxString& name, void wxFontsManager::AddAllFonts() { wxString path; - if ( !wxGetEnv(_T("WXDFB_FONTPATH"), &path) ) + if ( !wxGetEnv("WXDFB_FONTPATH", &path) ) path = _T(wxINSTALL_PREFIX "/share/wx/fonts"); wxStringTokenizer tkn(path, wxPATH_SEP); @@ -146,12 +155,12 @@ void wxFontsManager::AddAllFonts() if ( !wxDir::Exists(dir) ) { - wxLogTrace(_T("font"), _T("font directory %s doesn't exist"), dir); + wxLogDebug("font directory %s doesn't exist", dir); continue; } wxArrayString indexFiles; - if ( !wxDir::GetAllFiles(dir, &indexFiles, _T("FontsIndex")) ) + if ( !wxDir::GetAllFiles(dir, &indexFiles, "FontsIndex") ) continue; for ( wxArrayString::const_iterator i = indexFiles.begin(); @@ -163,8 +172,23 @@ void wxFontsManager::AddAllFonts() if ( GetBundles().empty() ) { - // wxDFB is unusable without fonts, so terminate the app - wxLogFatalError(_("No fonts found in %s."), path.c_str()); + // We can fall back to the builtin default font if no other fonts are + // defined: + wxLogTrace("font", + _("no fonts found in %s, using builtin font"), path); + + AddBundle + ( + new wxFontBundle + ( + _("Default font"), + BUILTIN_DFB_FONT_FILENAME, + wxEmptyString, + wxEmptyString, + wxEmptyString, + false // IsFixed + ) + ); } } @@ -180,7 +204,7 @@ void wxFontsManager::AddFontsFromDir(const wxString& indexFile) return; } - wxLogTrace(_T("font"), _T("adding fonts from %s"), dir.c_str()); + wxLogTrace("font", "adding fonts from %s", dir.c_str()); wxFileConfig cfg(wxEmptyString, wxEmptyString, indexFile, wxEmptyString, @@ -207,27 +231,27 @@ ReadFilePath(const wxString& name, const wxString& dir, wxFileConfig& cfg) if ( p.empty() || wxFileName(p).IsAbsolute() ) return p; - return dir + _T("/") + p; + return dir + "/" + p; } void wxFontsManager::AddFont(const wxString& dir, const wxString& name, wxFileConfig& cfg) { - wxLogTrace(_T("font"), _T("adding font '%s'"), name.c_str()); + wxLogTrace("font", "adding font '%s'", name.c_str()); - wxConfigPathChanger ch(&cfg, wxString::Format(_T("/%s/"), name.c_str())); + wxConfigPathChanger ch(&cfg, wxString::Format("/%s/", name.c_str())); AddBundle ( new wxFontBundle ( name, - ReadFilePath(_T("Regular"), dir, cfg), - ReadFilePath(_T("Italic"), dir, cfg), - ReadFilePath(_T("Bold"), dir, cfg), - ReadFilePath(_T("BoldItalic"), dir, cfg), - cfg.Read(_T("IsFixed"), (long)false) + ReadFilePath("Regular", dir, cfg), + ReadFilePath("Italic", dir, cfg), + ReadFilePath("Bold", dir, cfg), + ReadFilePath("BoldItalic", dir, cfg), + cfg.Read("IsFixed", (long)false) ) ); } @@ -236,7 +260,7 @@ void wxFontsManager::SetDefaultFonts(wxFileConfig& cfg) { wxString name; - if ( cfg.Read(_T("Default"), &name) ) + if ( cfg.Read("Default", &name) ) { m_defaultFacenames[wxFONTFAMILY_DECORATIVE] = m_defaultFacenames[wxFONTFAMILY_ROMAN] = @@ -246,16 +270,16 @@ void wxFontsManager::SetDefaultFonts(wxFileConfig& cfg) m_defaultFacenames[wxFONTFAMILY_TELETYPE] = name; } - if ( cfg.Read(_T("DefaultDecorative"), &name) ) + if ( cfg.Read("DefaultDecorative", &name) ) m_defaultFacenames[wxFONTFAMILY_DECORATIVE] = name; - if ( cfg.Read(_T("DefaultRoman"), &name) ) + if ( cfg.Read("DefaultRoman", &name) ) m_defaultFacenames[wxFONTFAMILY_ROMAN] = name; - if ( cfg.Read(_T("DefaultScript"), &name) ) + if ( cfg.Read("DefaultScript", &name) ) m_defaultFacenames[wxFONTFAMILY_SCRIPT] = name; - if ( cfg.Read(_T("DefaultSwiss"), &name) ) + if ( cfg.Read("DefaultSwiss", &name) ) m_defaultFacenames[wxFONTFAMILY_SWISS] = name; - if ( cfg.Read(_T("DefaultModern"), &name) ) + if ( cfg.Read("DefaultModern", &name) ) m_defaultFacenames[wxFONTFAMILY_MODERN] = name; - if ( cfg.Read(_T("DefaultTeletype"), &name) ) + if ( cfg.Read("DefaultTeletype", &name) ) m_defaultFacenames[wxFONTFAMILY_TELETYPE] = name; }