From becf6c22eaf21be067b6467d465f3cdfcaecde4b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 16 Dec 2007 12:36:52 +0000 Subject: [PATCH] Added initilizers of variables to FreeTypeFont3D constructors. Removed unused FreeTypeFontBase class --- src/osgPlugins/freetype/FreeTypeFont3D.cpp | 13 +- src/osgPlugins/freetype/FreeTypeFontBase.cpp | 224 ------------------- src/osgPlugins/freetype/FreeTypeFontBase.h | 46 ---- 3 files changed, 11 insertions(+), 272 deletions(-) delete mode 100644 src/osgPlugins/freetype/FreeTypeFontBase.cpp delete mode 100644 src/osgPlugins/freetype/FreeTypeFontBase.h diff --git a/src/osgPlugins/freetype/FreeTypeFont3D.cpp b/src/osgPlugins/freetype/FreeTypeFont3D.cpp index 2a08c3c5d..6cba789ea 100644 --- a/src/osgPlugins/freetype/FreeTypeFont3D.cpp +++ b/src/osgPlugins/freetype/FreeTypeFont3D.cpp @@ -188,7 +188,11 @@ FreeTypeFont3D::FreeTypeFont3D(const std::string& filename, FT_Face face, unsign _filename(filename), _buffer(0), _face(face), - _flags(flags) + _flags(flags), + _scale(1.0), + _shiftY(0.0), + _shiftX(0.0), + _charScale(1.0) { init(); } @@ -197,13 +201,18 @@ FreeTypeFont3D::FreeTypeFont3D(FT_Byte* buffer, FT_Face face, unsigned int flags _filename(""), _buffer(buffer), _face(face), - _flags(flags) + _flags(flags), + _scale(1.0), + _shiftY(0.0), + _shiftX(0.0), + _charScale(1.0) { init(); } void FreeTypeFont3D::init() { + FT_Error _error = FT_Set_Pixel_Sizes(_face, 32, 32); if (_error) { diff --git a/src/osgPlugins/freetype/FreeTypeFontBase.cpp b/src/osgPlugins/freetype/FreeTypeFontBase.cpp deleted file mode 100644 index 25219e858..000000000 --- a/src/osgPlugins/freetype/FreeTypeFontBase.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield - * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * OpenSceneGraph Public License for more details. -*/ - -#include "FreeTypeFont.h" -#include "FreeTypeLibrary.h" - -#include -#include - -FreeTypeFont::FreeTypeFont(const std::string& filename, FT_Face face, unsigned int flags): - _filename(filename), - _buffer(0), - _face(face), - _flags(flags) -{ -} - -FreeTypeFont::FreeTypeFont(FT_Byte* buffer, FT_Face face, unsigned int flags): - _filename(""), - _buffer(buffer), - _face(face), - _flags(flags) -{ -} - -FreeTypeFont::~FreeTypeFont() -{ - if(_face) - { - FreeTypeLibrary* freeTypeLibrary = FreeTypeLibrary::instance(); - if (freeTypeLibrary) - { - // remove myself from the local registry to ensure that - // not dangling pointers remain - freeTypeLibrary->removeFontImplmentation(this); - - // free the freetype font face itself - FT_Done_Face(_face); - _face = 0; - - // release memory held for FT_Face to work - if (_buffer) - { - delete [] _buffer; - _buffer = 0; - } - } - } -} - -void FreeTypeFont::setFontResolution(unsigned int width, unsigned int height) -{ - int maxAxis = std::max(width, height); - int margin = _facade->getGlyphImageMargin() + (int)((float)maxAxis * _facade->getGlyphImageMarginRatio()); - - if (width+2*margin>_facade->getTextureWidthHint() || - width+2*margin>_facade->getTextureHeightHint()) - { - osg::notify(osg::WARN)<<"Warning: FreeTypeFont::setSize("<getTextureWidthHint()-2*margin; - height = _facade->getTextureHeightHint()-2*margin; - - osg::notify(osg::WARN)<<" sizes capped ("<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|_flags ); - if (error) - { - osg::notify(osg::WARN) << "FT_Load_Char(...) error 0x"<glyph; - - int pitch = glyphslot->bitmap.pitch; - unsigned char* buffer = glyphslot->bitmap.buffer; - - unsigned int sourceWidth = glyphslot->bitmap.width;; - unsigned int sourceHeight = glyphslot->bitmap.rows; - - unsigned int width = sourceWidth; - unsigned int height = sourceHeight; - - osg::ref_ptr glyph = new osgText::Font::Glyph; - - unsigned int dataSize = width*height; - unsigned char* data = new unsigned char[dataSize]; - - - // clear the image to zeros. - for(unsigned char* p=data;psetImage(width,height,1, - GL_ALPHA, - GL_ALPHA,GL_UNSIGNED_BYTE, - data, - osg::Image::USE_NEW_DELETE, - 1); - - glyph->setInternalTextureFormat(GL_ALPHA); - - // copy image across to osgText::Glyph image. - switch(glyphslot->bitmap.pixel_mode) - { - case FT_PIXEL_MODE_MONO: - for(int r=sourceHeight-1;r>=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; - } - - - FT_Glyph_Metrics* metrics = &(glyphslot->metrics); - - glyph->setHorizontalBearing(osg::Vec2((float)metrics->horiBearingX/64.0f,(float)(metrics->horiBearingY-metrics->height)/64.0f)); // bottom left. - glyph->setHorizontalAdvance((float)metrics->horiAdvance/64.0f); - glyph->setVerticalBearing(osg::Vec2((float)metrics->vertBearingX/64.0f,(float)(metrics->vertBearingY-metrics->height)/64.0f)); // top middle. - glyph->setVerticalAdvance((float)metrics->vertAdvance/64.0f); - - addGlyph(_facade->getFontWidth(),_facade->getFontHeight(),charcode,glyph.get()); - -// cout << " in getGlyph() implementation="< -#include FT_FREETYPE_H - -class FreeTypeFontBase : public osgText::Font::FontImplementation -{ -// declare the interface to a font. -public: - - FreeTypeFont(const std::string& filename, FT_Face face, unsigned int flags); - FreeTypeFont(FT_Byte* buffer, FT_Face face, unsigned int flags); - - virtual ~FreeTypeFont(); - - virtual std::string getFileName() const { return _filename; } - - virtual void setFontResolution(unsigned int width, unsigned int height); - - virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode, osgText::KerningType _kerningType); - - virtual bool hasVertical() const; - -protected: - - std::string _filename; - FT_Byte* _buffer; - FT_Face _face; - unsigned int _flags; -}; - -#endif