From Gordon Tomlinson, "I have attached the 3 files we had to change to fix a proble we were seeing with using Symbol Fonts

// GT: fix for symbol fonts (i.e. the Webdings font) as the wrong character are being
// returned, for symbol fonts in windows (FT_ENCONDING_MS_SYMBOL in freetype) the correct
// values are from 0xF000 to 0xF0FF not from 0x000 to 0x00FF (0 to 255) as you would expect.
// becuase Microsoft uses a private field for its symbol fonts ........
 "
This commit is contained in:
Robert Osfield
2007-02-05 11:48:02 +00:00
parent 3c5c4ae242
commit 246b28e752
3 changed files with 58 additions and 7 deletions

View File

@@ -38,7 +38,7 @@ FreeTypeFont::~FreeTypeFont()
FreeTypeLibrary* freeTypeLibrary = FreeTypeLibrary::instance();
if (freeTypeLibrary)
{
// remove myself from the local regsitry to ensure that
// remove myself from the local registry to ensure that
// not dangling pointers remain
freeTypeLibrary->removeFontImplmentation(this);
@@ -69,9 +69,9 @@ void FreeTypeFont::setFontResolution(unsigned int width, unsigned int height)
osg::notify(osg::WARN)<<" sizes capped ("<<width<<","<<height<<") to fit int current glyph texture size."<<std::endl;
}
FT_Error error = FT_Set_Pixel_Sizes( _face, /* handle to face object */
width, /* pixel_width */
height ); /* pixel_height */
FT_Error error = FT_Set_Pixel_Sizes( _face, /* handle to face object */
width, /* pixel_width */
height ); /* pixel_height */
if (error)
{
@@ -87,7 +87,22 @@ void FreeTypeFont::setFontResolution(unsigned int width, unsigned int height)
osgText::Font::Glyph* FreeTypeFont::getGlyph(unsigned int charcode)
{
FT_Error error = FT_Load_Char( _face, charcode, FT_LOAD_RENDER|FT_LOAD_NO_BITMAP );
//
// GT: fix for symbol fonts (i.e. the Webdings font) as the wrong character are being
// returned, for symbol fonts in windows (FT_ENCONDING_MS_SYMBOL in freetype) the correct
// values are from 0xF000 to 0xF0FF not from 0x000 to 0x00FF (0 to 255) as you would expect.
// Microsoft uses a private field for its symbol fonts
//
unsigned int charindex = charcode;
if (_face->charmap != NULL)
{
if (_face->charmap->encoding == FT_ENCODING_MS_SYMBOL)
{
charindex |= 0xF000;
}
}
FT_Error error = FT_Load_Char( _face, charindex, FT_LOAD_RENDER|FT_LOAD_NO_BITMAP );
if (error)
{
osg::notify(osg::WARN) << "FT_Load_Char(...) error "<<error<<std::endl;

View File

@@ -13,13 +13,15 @@
#include "FreeTypeLibrary.h"
#include <osg/Notify>
#include <ft2build.h>
#include FT_TRUETYPE_IDS_H
FreeTypeLibrary::FreeTypeLibrary()
{
FT_Error error = FT_Init_FreeType( &_ftlibrary );
if (error)
{
osg::notify(osg::WARN)<<"Warning: an error occured during FT_Init_FreeType(..) initialisation .. "<<std::endl;
osg::notify(osg::WARN)<<"Warning: an error occurred during FT_Init_FreeType(..) initialisation .. "<<std::endl;
}
}
@@ -29,7 +31,7 @@ FreeTypeLibrary::~FreeTypeLibrary()
// need to remove the implementations from the Fonts here
// just in case the Fonts continue to have external references
// to them, otherwise they will try to point to an object thats
// definiation has been unloaded along with the unload of the FreeType
// definition has been unloaded along with the unload of the FreeType
// plugin.
while(!_fontImplementationSet.empty())
{
@@ -66,6 +68,11 @@ osgText::Font* FreeTypeLibrary::getFont(const std::string& fontfile,unsigned int
return 0;
}
//
// GT: Fix to handle symbol fonts in MS Windows
//
verifyCharacterMap(face);
FreeTypeFont* fontImp = new FreeTypeFont(fontfile,face);
osgText::Font* font = new osgText::Font(fontImp);
@@ -113,6 +120,11 @@ osgText::Font* FreeTypeLibrary::getFont(std::istream& fontstream, unsigned int i
return 0;
}
//
// GT: Fix to handle symbol fonts in MS Windows
//
verifyCharacterMap(face);
FreeTypeFont* fontImp = new FreeTypeFont(buffer,face);
osgText::Font* font = new osgText::Font(fontImp);
@@ -120,3 +132,24 @@ osgText::Font* FreeTypeLibrary::getFont(std::istream& fontstream, unsigned int i
return font;
}
void FreeTypeLibrary::verifyCharacterMap(FT_Face face)
{
//
// GT: Verify the correct character mapping for MS windows
// as symbol fonts were being returned incorrectly
//
FT_CharMap charmap;
if (face->charmap == NULL)
{
for (int n = 0; n < face->num_charmaps; n++)
{
charmap = face->charmaps[n];
if (charmap->platform_id == TT_PLATFORM_MICROSOFT)
{
FT_Set_Charmap(face, charmap);
break;
}
}
}
}

View File

@@ -36,6 +36,9 @@ public:
protected:
/** Verify the correct character mapping for MS windows */
void verifyCharacterMap(FT_Face face);
/** protected constructor to ensure the only way to create the
* library is via the singleton instance method.*/
FreeTypeLibrary();