diff --git a/src/osgPlugins/freetype/FreeTypeFont.cpp b/src/osgPlugins/freetype/FreeTypeFont.cpp index afee9c914..dd36aa4fe 100644 --- a/src/osgPlugins/freetype/FreeTypeFont.cpp +++ b/src/osgPlugins/freetype/FreeTypeFont.cpp @@ -17,17 +17,19 @@ #include #include -FreeTypeFont::FreeTypeFont(const std::string& filename, FT_Face face): +FreeTypeFont::FreeTypeFont(const std::string& filename, FT_Face face, unsigned int flags): _filename(filename), _buffer(0), - _face(face) + _face(face), + _flags(flags) { } -FreeTypeFont::FreeTypeFont(FT_Byte* buffer, FT_Face face): +FreeTypeFont::FreeTypeFont(FT_Byte* buffer, FT_Face face, unsigned int flags): _filename(""), _buffer(buffer), - _face(face) + _face(face), + _flags(flags) { } @@ -105,7 +107,7 @@ osgText::Font::Glyph* FreeTypeFont::getGlyph(unsigned int charcode) } } - FT_Error error = FT_Load_Char( _face, charindex, FT_LOAD_RENDER|FT_LOAD_NO_BITMAP ); + FT_Error error = FT_Load_Char( _face, charindex, FT_LOAD_RENDER|FT_LOAD_NO_BITMAP|_flags ); if (error) { osg::notify(osg::WARN) << "FT_Load_Char(...) error "<setInternalTextureFormat(GL_ALPHA); // copy image across to osgText::Glyph image. - for(int r=sourceHeight-1;r>=0;--r) + switch(glyphslot->bitmap.pixel_mode) { - unsigned char* ptr = buffer+r*pitch; - for(unsigned int c=0;c=0;--r) + { + unsigned char* ptr = buffer+r*pitch; + for(unsigned int c=0;c> 3] & (1 << (~c & 7))) ? 255 : 0; + } + } + break; + + + case FT_PIXEL_MODE_GRAY: + for(int r=sourceHeight-1;r>=0;--r) + { + unsigned char* ptr = buffer+r*pitch; + for(unsigned int c=0;cbitmap.pixel_mode << std::endl; } diff --git a/src/osgPlugins/freetype/FreeTypeFont.h b/src/osgPlugins/freetype/FreeTypeFont.h index 3cd85ffeb..b6839e217 100644 --- a/src/osgPlugins/freetype/FreeTypeFont.h +++ b/src/osgPlugins/freetype/FreeTypeFont.h @@ -24,8 +24,8 @@ class FreeTypeFont : public osgText::Font::FontImplementation // declare the interface to a font. public: - FreeTypeFont(const std::string& filename, FT_Face face); - FreeTypeFont(FT_Byte* buffer, FT_Face face); + FreeTypeFont(const std::string& filename, FT_Face face, unsigned int flags); + FreeTypeFont(FT_Byte* buffer, FT_Face face, unsigned int flags); virtual ~FreeTypeFont(); @@ -44,7 +44,7 @@ protected: std::string _filename; FT_Byte* _buffer; FT_Face _face; - + unsigned int _flags; }; #endif diff --git a/src/osgPlugins/freetype/FreeTypeLibrary.cpp b/src/osgPlugins/freetype/FreeTypeLibrary.cpp index 45bb52563..924b649a4 100644 --- a/src/osgPlugins/freetype/FreeTypeLibrary.cpp +++ b/src/osgPlugins/freetype/FreeTypeLibrary.cpp @@ -56,7 +56,7 @@ FreeTypeLibrary* FreeTypeLibrary::instance() return s_library.get(); } -osgText::Font* FreeTypeLibrary::getFont(const std::string& fontfile,unsigned int index) +osgText::Font* FreeTypeLibrary::getFont(const std::string& fontfile,unsigned int index, unsigned int flags) { FT_Face face; /* handle to face object */ @@ -96,7 +96,7 @@ osgText::Font* FreeTypeLibrary::getFont(const std::string& fontfile,unsigned int // verifyCharacterMap(face); - FreeTypeFont* fontImp = new FreeTypeFont(fontfile,face); + FreeTypeFont* fontImp = new FreeTypeFont(fontfile,face,flags); osgText::Font* font = new osgText::Font(fontImp); _fontImplementationSet.insert(fontImp); @@ -105,7 +105,7 @@ osgText::Font* FreeTypeLibrary::getFont(const std::string& fontfile,unsigned int } -osgText::Font* FreeTypeLibrary::getFont(std::istream& fontstream, unsigned int index) +osgText::Font* FreeTypeLibrary::getFont(std::istream& fontstream, unsigned int index, unsigned int flags) { FT_Face face; /* handle to face object */ FT_Open_Args args; @@ -148,7 +148,7 @@ osgText::Font* FreeTypeLibrary::getFont(std::istream& fontstream, unsigned int i // verifyCharacterMap(face); - FreeTypeFont* fontImp = new FreeTypeFont(buffer,face); + FreeTypeFont* fontImp = new FreeTypeFont(buffer,face,flags); osgText::Font* font = new osgText::Font(fontImp); _fontImplementationSet.insert(fontImp); diff --git a/src/osgPlugins/freetype/FreeTypeLibrary.h b/src/osgPlugins/freetype/FreeTypeLibrary.h index 18b8b870e..cee9b0436 100644 --- a/src/osgPlugins/freetype/FreeTypeLibrary.h +++ b/src/osgPlugins/freetype/FreeTypeLibrary.h @@ -29,8 +29,8 @@ public: /** get the singleton instance.*/ static FreeTypeLibrary* instance(); - osgText::Font* getFont(const std::string& fontfile,unsigned int index=0); - osgText::Font* getFont(std::istream& fontstream, unsigned int index=0); + osgText::Font* getFont(const std::string& fontfile,unsigned int index=0, unsigned int flags=0); + osgText::Font* getFont(std::istream& fontstream, unsigned int index=0, unsigned int flags=0); void removeFontImplmentation(FreeTypeFont* fontImpl) { _fontImplementationSet.erase(fontImpl); } diff --git a/src/osgPlugins/freetype/ReaderWriterFreeType.cpp b/src/osgPlugins/freetype/ReaderWriterFreeType.cpp index 5b3b74d1f..b72f3165c 100644 --- a/src/osgPlugins/freetype/ReaderWriterFreeType.cpp +++ b/src/osgPlugins/freetype/ReaderWriterFreeType.cpp @@ -23,6 +23,17 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter osgDB::equalCaseInsensitive(extension,"fnt"); // Windows bitmap fonts } + static unsigned int getFlags(const osgDB::ReaderWriter::Options* options) + { + unsigned int flags = 0; + if (options && options->getOptionString().find("monochrome") != std::string::npos) + { + flags |= FT_LOAD_MONOCHROME; + } + + return flags; + } + virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); @@ -38,10 +49,10 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter return ReadResult::ERROR_IN_READING_FILE; } - return freeTypeLibrary->getFont(fileName,0); + return freeTypeLibrary->getFont(fileName,0,getFlags(options)); } - virtual ReadResult readObject(std::istream& stream, const osgDB::ReaderWriter::Options*) const + virtual ReadResult readObject(std::istream& stream, const osgDB::ReaderWriter::Options* options) const { FreeTypeLibrary* freeTypeLibrary = FreeTypeLibrary::instance(); if (!freeTypeLibrary) @@ -50,7 +61,7 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter return ReadResult::ERROR_IN_READING_FILE; } - return freeTypeLibrary->getFont(stream, 0); + return freeTypeLibrary->getFont(stream, 0, getFlags(options)); } };