Merge branch 'jmt/font' into next
This commit is contained in:
commit
bf4b263071
2 changed files with 39 additions and 18 deletions
src
|
@ -1109,7 +1109,12 @@ FGTextLayer::draw (osg::State& state)
|
||||||
transform();
|
transform();
|
||||||
|
|
||||||
FGFontCache *fc = globals->get_fontcache();
|
FGFontCache *fc = globals->get_fontcache();
|
||||||
text_renderer.setFont(fc->getTexFont(_font_name.c_str()));
|
fntFont* font = fc->getTexFont(_font_name.c_str());
|
||||||
|
if (!font) {
|
||||||
|
return; // don't crash on missing fonts
|
||||||
|
}
|
||||||
|
|
||||||
|
text_renderer.setFont(font);
|
||||||
|
|
||||||
text_renderer.setPointSize(_pointSize);
|
text_renderer.setPointSize(_pointSize);
|
||||||
text_renderer.begin();
|
text_renderer.begin();
|
||||||
|
@ -1170,6 +1175,11 @@ void
|
||||||
FGTextLayer::setFontName(const string &name)
|
FGTextLayer::setFontName(const string &name)
|
||||||
{
|
{
|
||||||
_font_name = name + ".txf";
|
_font_name = name + ".txf";
|
||||||
|
FGFontCache *fc = globals->get_fontcache();
|
||||||
|
fntFont* font = fc->getTexFont(_font_name.c_str());
|
||||||
|
if (!font) {
|
||||||
|
SG_LOG(SG_GENERAL, SG_WARN, "unable to find font:" << name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include <simgear/structure/exception.hxx>
|
#include <simgear/structure/exception.hxx>
|
||||||
#include <simgear/props/props_io.hxx>
|
#include <simgear/props/props_io.hxx>
|
||||||
|
|
||||||
|
#include <boost/algorithm/string/case_conv.hpp>
|
||||||
|
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
|
||||||
#include "menubar.hxx"
|
#include "menubar.hxx"
|
||||||
|
@ -468,24 +470,29 @@ inline bool FGFontCache::FntParamsLess::operator()(const FntParams& f1,
|
||||||
struct FGFontCache::fnt *
|
struct FGFontCache::fnt *
|
||||||
FGFontCache::getfnt(const char *name, float size, float slant)
|
FGFontCache::getfnt(const char *name, float size, float slant)
|
||||||
{
|
{
|
||||||
string fontName(name);
|
string fontName = boost::to_lower_copy(string(name));
|
||||||
FntParams fntParams(fontName, size, slant);
|
FntParams fntParams(fontName, size, slant);
|
||||||
PuFontMap::iterator i = _puFonts.find(fntParams);
|
PuFontMap::iterator i = _puFonts.find(fntParams);
|
||||||
if (i != _puFonts.end())
|
if (i != _puFonts.end()) {
|
||||||
|
// found in the puFonts map, all done
|
||||||
return i->second;
|
return i->second;
|
||||||
|
}
|
||||||
|
|
||||||
// fntTexFont s are all preloaded into the _texFonts map
|
// fntTexFont s are all preloaded into the _texFonts map
|
||||||
TexFontMap::iterator texi = _texFonts.find(fontName);
|
TexFontMap::iterator texi = _texFonts.find(fontName);
|
||||||
fntTexFont* texfont = 0;
|
fntTexFont* texfont = NULL;
|
||||||
puFont* pufont = 0;
|
puFont* pufont = NULL;
|
||||||
if (texi != _texFonts.end()) {
|
if (texi != _texFonts.end()) {
|
||||||
texfont = texi->second;
|
texfont = texi->second;
|
||||||
} else {
|
} else {
|
||||||
|
// check the built-in PUI fonts (in guifonts array)
|
||||||
const GuiFont* guifont = std::find_if(&guifonts[0], guifontsEnd,
|
const GuiFont* guifont = std::find_if(&guifonts[0], guifontsEnd,
|
||||||
GuiFont::Predicate(name));
|
GuiFont::Predicate(name));
|
||||||
if (guifont != guifontsEnd) {
|
if (guifont != guifontsEnd) {
|
||||||
pufont = guifont->font;
|
pufont = guifont->font;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fnt* f = new fnt;
|
fnt* f = new fnt;
|
||||||
if (pufont) {
|
if (pufont) {
|
||||||
f->pufont = pufont;
|
f->pufont = pufont;
|
||||||
|
@ -527,16 +534,18 @@ FGFontCache::get(SGPropertyNode *node)
|
||||||
|
|
||||||
void FGFontCache::init()
|
void FGFontCache::init()
|
||||||
{
|
{
|
||||||
if (!_initialized) {
|
if (_initialized) {
|
||||||
char *envp = ::getenv("FG_FONTS");
|
return;
|
||||||
if (envp != NULL) {
|
|
||||||
_path.set(envp);
|
|
||||||
} else {
|
|
||||||
_path.set(globals->get_fg_root());
|
|
||||||
_path.append("Fonts");
|
|
||||||
}
|
|
||||||
_initialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *envp = ::getenv("FG_FONTS");
|
||||||
|
if (envp != NULL) {
|
||||||
|
_path.set(envp);
|
||||||
|
} else {
|
||||||
|
_path.set(globals->get_fg_root());
|
||||||
|
_path.append("Fonts");
|
||||||
|
}
|
||||||
|
_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SGPath
|
SGPath
|
||||||
|
@ -552,7 +561,7 @@ FGFontCache::getfntpath(const char *name)
|
||||||
|
|
||||||
path = SGPath(_path);
|
path = SGPath(_path);
|
||||||
path.append("Helvetica.txf");
|
path.append("Helvetica.txf");
|
||||||
|
SG_LOG(SG_GENERAL, SG_WARN, "Unknown font name '" << name << "', defaulting to Helvetica");
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,9 +578,11 @@ bool FGFontCache::initializeFonts()
|
||||||
path.append(dirEntry->d_name);
|
path.append(dirEntry->d_name);
|
||||||
if (path.extension() == fontext) {
|
if (path.extension() == fontext) {
|
||||||
fntTexFont* f = new fntTexFont;
|
fntTexFont* f = new fntTexFont;
|
||||||
if (f->load((char *)path.c_str()))
|
if (f->load((char *)path.c_str())) {
|
||||||
_texFonts[string(dirEntry->d_name)] = f;
|
// convert font names in the map to lowercase for matching
|
||||||
else
|
string fontName = boost::to_lower_copy(string(dirEntry->d_name));
|
||||||
|
_texFonts[fontName] = f;
|
||||||
|
} else
|
||||||
delete f;
|
delete f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue