diff --git a/include/osgText/Glyph b/include/osgText/Glyph index 6bee19e7c..cff491d08 100644 --- a/include/osgText/Glyph +++ b/include/osgText/Glyph @@ -49,6 +49,12 @@ public: unsigned int getGlyphCode() const { return _glyphCode; } + void setWidth(float width) { _width = width; } + float getWidth() const { return _width; } + + void setHeight(float height) { _height = height; } + float getHeight() const { return _height; } + void setHorizontalBearing(const osg::Vec2& bearing); const osg::Vec2& getHorizontalBearing() const; @@ -84,6 +90,9 @@ protected: Font* _font; unsigned int _glyphCode; + float _width; + float _height; + osg::Vec2 _horizontalBearing; float _horizontalAdvance; @@ -159,6 +168,12 @@ public: unsigned int getGlyphCode() const { return _glyphCode; } + void setWidth(float width) { _width = width; } + float getWidth() const { return _width; } + + void setHeight(float height) { _height = height; } + float getHeight() const { return _height; } + void setHorizontalBearing(const osg::Vec2& bearing) { _horizontalBearing=bearing; } const osg::Vec2 & getHorizontalBearing() const { return _horizontalBearing; } @@ -187,18 +202,6 @@ public: osg::Geometry::PrimitiveSetList & getRawFacePrimitiveSetList() { return _rawFacePrimitiveSetList; } const osg::Geometry::PrimitiveSetList & getRawFacePrimitiveSetList() const { return _rawFacePrimitiveSetList; } - - float getHorizontalWidth() const { return (-_horizontalBearing.x() + _horizontalAdvance); } - float getHorizontalHeight() const { return (-_horizontalBearing.y() + _bb.yMax()); } - float getVerticalWidth() const { return (-_verticalBearing.x() + _bb.xMax()); } - float getVerticalHeight() const { return (-_verticalBearing.y() + _verticalAdvance); } - - void setWidth(float width) { _width = width; } - float getWidth() const { return _width; } - - void setHeight(float height) { _height = height; } - float getHeight() const { return _height; } - GlyphGeometry* getGlyphGeometry(const Style* style); protected: @@ -208,6 +211,9 @@ protected: Font* _font; unsigned int _glyphCode; + float _width; + float _height; + osg::Vec2 _horizontalBearing; float _horizontalAdvance; @@ -217,8 +223,6 @@ protected: osg::BoundingBox _bb; // osg::Vec2 _advance; - float _width; - float _height; osg::ref_ptr _rawVertexArray; osg::Geometry::PrimitiveSetList _rawFacePrimitiveSetList; diff --git a/include/osgText/Text b/include/osgText/Text index 1f29019b7..15b1c2f1a 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -37,6 +37,15 @@ public: virtual const char* className() const { return "Text"; } virtual const char* libraryName() const { return "osgText"; } + virtual void setFont(Font* font=0) { setFont(osg::ref_ptr(font)); }; + + /** Set the Font to use to render the text.*/ + virtual void setFont(osg::ref_ptr font); + + /** Set the font, loaded from the specified front file, to use to render the text, + * setFont("") sets the use of the default font. + * See the osgText::readFontFile function for how the font file will be located. */ + virtual void setFont(const std::string& fontfile) { TextBase::setFont(fontfile); } /** * Turns off writing to the depth buffer when rendering text. This only affects text diff --git a/include/osgText/TextBase b/include/osgText/TextBase index 3e4ad6566..b063c5129 100644 --- a/include/osgText/TextBase +++ b/include/osgText/TextBase @@ -41,15 +41,15 @@ public: /** Set the Font to use to render the text. * setFont(0) sets the use of the default font.*/ - inline void setFont(Font* font=0) { setFont(osg::ref_ptr(font)); }; + virtual void setFont(Font* font=0) { setFont(osg::ref_ptr(font)); }; /** Set the Font to use to render the text.*/ - void setFont(osg::ref_ptr font); + virtual void setFont(osg::ref_ptr font); /** Set the font, loaded from the specified front file, to use to render the text, * setFont("") sets the use of the default font. * See the osgText::readFontFile function for how the font file will be located. */ - void setFont(const std::string& fontfile); + virtual void setFont(const std::string& fontfile); /** Get the font. Return 0 if default is being used.*/ const Font* getFont() const { return _font.get(); } diff --git a/src/osgPlugins/freetype/FreeTypeFont.cpp b/src/osgPlugins/freetype/FreeTypeFont.cpp index d903c8a2d..23b3c7d8f 100644 --- a/src/osgPlugins/freetype/FreeTypeFont.cpp +++ b/src/osgPlugins/freetype/FreeTypeFont.cpp @@ -205,8 +205,7 @@ FreeTypeFont::FreeTypeFont(const std::string& filename, FT_Face face, unsigned i _filename(filename), _buffer(0), _face(face), - _flags(flags), - _freetype_scale(1.0f) + _flags(flags) { init(); } @@ -216,8 +215,7 @@ FreeTypeFont::FreeTypeFont(FT_Byte* buffer, FT_Face face, unsigned int flags): _filename(""), _buffer(buffer), _face(face), - _flags(flags), - _freetype_scale(1.0f) + _flags(flags) { init(); } @@ -250,60 +248,14 @@ FreeTypeFont::~FreeTypeFont() void FreeTypeFont::init() { FT_Error _error; -#if 0 _error = FT_Set_Pixel_Sizes(_face, 32, 32); if (_error) { OSG_NOTICE << "FreeTypeFont3D: set pixel sizes failed ..." << std::endl; return; } -#endif - FT_Set_Char_Size( _face, 64*64, 64*64, 600, 600); - - int glyphIndex = FT_Get_Char_Index( _face, 'M' ); - _error = FT_Load_Glyph( _face, glyphIndex, FT_LOAD_DEFAULT ); - if (_error) - { - OSG_NOTICE << "FreeTypeFont3D: initial glyph load failed ..." << std::endl; - return; - } - - if (_face->glyph->format != FT_GLYPH_FORMAT_OUTLINE) - { - OSG_NOTICE << "FreeTypeFont3D: not a vector font" << std::endl; - return; - } - - { - FreeType::Char3DInfo char3d(10); - - FT_Outline outline = _face->glyph->outline; - FT_Outline_Funcs funcs; - funcs.conic_to = (FT_Outline_ConicToFunc)&FreeType::conicTo; - funcs.line_to = (FT_Outline_LineToFunc)&FreeType::lineTo; - funcs.cubic_to = (FT_Outline_CubicToFunc)&FreeType::cubicTo; - funcs.move_to = (FT_Outline_MoveToFunc)&FreeType::moveTo; - funcs.shift = 0; - funcs.delta = 0; - _error = FT_Outline_Decompose(&outline,&funcs,&char3d); - if (_error) - { - OSG_NOTICE << "FreeTypeFont3D: - outline decompose failed ..." << std::endl; - return; - } - - FT_BBox bb; - FT_Outline_Get_BBox(&outline,&bb); - - long ymin = ft_floor( bb.yMin ); - long ymax = ft_ceiling( bb.yMax ); - double height = double(ymax - ymin)/64.0; - - // long xmin = ft_floor( bb.xMin ); - // long xmax = ft_ceiling( bb.xMax ); - // double width = (xmax - xmin)/64.0; - _freetype_scale = 1.0f/height; - } + _currentRes.first = 32; + _currentRes.second = 32; } void FreeTypeFont::setFontResolution(const osgText::FontResolution& fontSize) @@ -347,6 +299,8 @@ osgText::Glyph* FreeTypeFont::getGlyph(const osgText::FontResolution& fontRes, u setFontResolution(fontRes); + float coord_scale = 1.0f/(float(_currentRes.second)*64.0f); + // // 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 @@ -432,17 +386,23 @@ osgText::Glyph* FreeTypeFont::getGlyph(const osgText::FontResolution& fontRes, u FT_Glyph_Metrics* metrics = &(_face->glyph->metrics); -#if 0 - float coord_scale = _freetype_scale/64.0f; -#else - float coord_scale = 1.0f/64.0f; -#endif - + glyph->setWidth((float)metrics->width * coord_scale); + glyph->setHeight((float)metrics->height * coord_scale); glyph->setHorizontalBearing(osg::Vec2((float)metrics->horiBearingX * coord_scale,(float)(metrics->horiBearingY-metrics->height) * coord_scale)); // bottom left. glyph->setHorizontalAdvance((float)metrics->horiAdvance * coord_scale); glyph->setVerticalBearing(osg::Vec2((float)metrics->vertBearingX * coord_scale,(float)(metrics->vertBearingY-metrics->height) * coord_scale)); // top middle. glyph->setVerticalAdvance((float)metrics->vertAdvance * coord_scale); +#if 0 + OSG_NOTICE<<"getGlyph("<