/** Read a font from specified file. The filename may contain a path.
* It will search for the font file in the following places in this order:
* - In the current directory
* - All paths defined in OSG_FILE_PATH or OSGFILEPATH environment variable
* - Filename with path stripped: In the current directory
* - Filename with path stripped: All paths defined in OSG_FILE_PATH or OSGFILEPATH
*
* Then the file will be searched in OS specific directories in the following order:
* - Again in the current directory
* - Windows: In C:/winnt/fonts
* - Windows: In C:/windows/fonts
* - Windows: In the fonts directory of the windows install directory
* - Other OS: In /usr/share/fonts/ttf
* - Other OS: In /usr/share/fonts/ttf/western
* - Other OS: In /usr/share/fonts/ttf/decoratives
*
* If the given file could not be found, the path part will be stripped and
* the file will be searched again in the OS specific directories.
*/
extern OSGTEXT_EXPORT Font* readFontFile(const std::string& filename, const osgDB::Options* userOptions = 0);
void Registry::initDataFilePathList()
{
FilePathList filepath;
//
// set up data file paths
//
char *ptr;
if( (ptr = getenv( "OSG_FILE_PATH" )) )
{
//OSG_NOTIFY(DEBUG_INFO) << "OSG_FILE_PATH("<
convertStringPathIntoFilePathList(ptr, filepath);
}
else if( (ptr = getenv( "OSGFILEPATH" )) )
{
//OSG_NOTIFY(DEBUG_INFO) << "OSGFILEPATH("<
convertStringPathIntoFilePathList(ptr, filepath);
}
osgDB::appendPlatformSpecificResourceFilePaths(filepath);
setDataFilePathList(filepath);
}
安装包指定目录下加载osg字体
当前工作目录的说明
若没有显示调用SetCurrentDirectory或C语言中的chdir,则默认的工作目录会取决于用户启动进程的方式:快捷图标启动,当前工作目录就为其属性中的起始位置;直接双击EXE启动,当前工作目录则为EXE所在目录。
方案1
显示设置好当前工作目录,将字体放于此目录下
方案2
显示设置好当前工作目录,并在当前工作目录中创建fonts文件夹(windows下大小写不区分),将字体放于此目录下
方案3
在加载字体前,在进程环境变量OSG_FILE_PATH中追加自定义的目录,如d:\myAppData,然后将字体放于此目录下
方案4
在加载字体前,在进程环境变量OSG_FILE_PATH中追加自定义的目录,如d:\myAppData,然后在此目录下新建文件夹fonts(windows下大小写不区分),并将字体放于此目录下