diff --git a/src/FTContour.cpp b/src/FTContour.cpp old mode 100644 new mode 100755 index cef1f3b..6b92812 --- a/src/FTContour.cpp +++ b/src/FTContour.cpp @@ -33,6 +33,9 @@ static const unsigned int BEZIER_STEPS = 5; +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif void FTContour::AddPoint(FTPoint point) { diff --git a/src/FTFace.h b/src/FTFace.h old mode 100644 new mode 100755 index 0e903b5..4a35f5a --- a/src/FTFace.h +++ b/src/FTFace.h @@ -141,6 +141,24 @@ class FTFace */ FT_Error Error() const { return err; } + //TECGRAF + const char* GetFamilyName () const + { + return (*ftFace)->family_name; + } + + //TECGRAF + bool IsBold () const + { + return (*ftFace)->style_flags & FT_STYLE_FLAG_BOLD; + } + + //TECGRAF + bool IsItalic () const + { + return (*ftFace)->style_flags & FT_STYLE_FLAG_ITALIC; + } + private: /** * The Freetype face diff --git a/src/FTFont/FTFont.cpp b/src/FTFont/FTFont.cpp old mode 100644 new mode 100755 index a7206fb..8e1d85d --- a/src/FTFont/FTFont.cpp +++ b/src/FTFont/FTFont.cpp @@ -1,552 +1,645 @@ -/* - * FTGL - OpenGL font library - * - * Copyright (c) 2001-2004 Henry Maddocks - * Copyright (c) 2008 Sam Hocevar - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include "config.h" - -#include "FTInternals.h" -#include "FTUnicode.h" - -#include "FTFontImpl.h" - -#include "FTBitmapFontImpl.h" -#include "FTExtrudeFontImpl.h" -#include "FTOutlineFontImpl.h" -#include "FTPixmapFontImpl.h" -#include "FTPolygonFontImpl.h" -#include "FTTextureFontImpl.h" - -#include "FTGlyphContainer.h" -#include "FTFace.h" - - -// -// FTFont -// - - -FTFont::FTFont(char const *fontFilePath) -{ - impl = new FTFontImpl(this, fontFilePath); -} - - -FTFont::FTFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes) -{ - impl = new FTFontImpl(this, pBufferBytes, bufferSizeInBytes); -} - - -FTFont::FTFont(FTFontImpl *pImpl) -{ - impl = pImpl; -} - - -FTFont::~FTFont() -{ - delete impl; -} - - -bool FTFont::Attach(const char* fontFilePath) -{ - return impl->Attach(fontFilePath); -} - - -bool FTFont::Attach(const unsigned char *pBufferBytes, size_t bufferSizeInBytes) -{ - return impl->Attach(pBufferBytes, bufferSizeInBytes); -} - - -bool FTFont::FaceSize(const unsigned int size, const unsigned int res) -{ - return impl->FaceSize(size, res); -} - - -unsigned int FTFont::FaceSize() const -{ - return impl->FaceSize(); -} - - -void FTFont::Depth(float depth) -{ - return impl->Depth(depth); -} - - -void FTFont::Outset(float outset) -{ - return impl->Outset(outset); -} - - -void FTFont::Outset(float front, float back) -{ - return impl->Outset(front, back); -} - - -void FTFont::GlyphLoadFlags(FT_Int flags) -{ - return impl->GlyphLoadFlags(flags); -} - - -bool FTFont::CharMap(FT_Encoding encoding) -{ - return impl->CharMap(encoding); -} - - -unsigned int FTFont::CharMapCount() const -{ - return impl->CharMapCount(); -} - - -FT_Encoding* FTFont::CharMapList() -{ - return impl->CharMapList(); -} - - -void FTFont::UseDisplayList(bool useList) -{ - return impl->UseDisplayList(useList); -} - - -float FTFont::Ascender() const -{ - return impl->Ascender(); -} - - -float FTFont::Descender() const -{ - return impl->Descender(); -} - - -float FTFont::LineHeight() const -{ - return impl->LineHeight(); -} - - -FTPoint FTFont::Render(const char * string, const int len, - FTPoint position, FTPoint spacing, int renderMode) -{ - return impl->Render(string, len, position, spacing, renderMode); -} - - -FTPoint FTFont::Render(const wchar_t * string, const int len, - FTPoint position, FTPoint spacing, int renderMode) -{ - return impl->Render(string, len, position, spacing, renderMode); -} - - -float FTFont::Advance(const char * string, const int len, FTPoint spacing) -{ - return impl->Advance(string, len, spacing); -} - - -float FTFont::Advance(const wchar_t * string, const int len, FTPoint spacing) -{ - return impl->Advance(string, len, spacing); -} - - -FTBBox FTFont::BBox(const char *string, const int len, - FTPoint position, FTPoint spacing) -{ - return impl->BBox(string, len, position, spacing); -} - - -FTBBox FTFont::BBox(const wchar_t *string, const int len, - FTPoint position, FTPoint spacing) -{ - return impl->BBox(string, len, position, spacing); -} - - -FT_Error FTFont::Error() const -{ - return impl->err; -} - - -// -// FTFontImpl -// - - -FTFontImpl::FTFontImpl(FTFont *ftFont, char const *fontFilePath) : - face(fontFilePath), - useDisplayLists(true), - load_flags(FT_LOAD_DEFAULT), - intf(ftFont), - glyphList(0) -{ - err = face.Error(); - if(err == 0) - { - glyphList = new FTGlyphContainer(&face); - } -} - - -FTFontImpl::FTFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes, - size_t bufferSizeInBytes) : - face(pBufferBytes, bufferSizeInBytes), - useDisplayLists(true), - load_flags(FT_LOAD_DEFAULT), - intf(ftFont), - glyphList(0) -{ - err = face.Error(); - if(err == 0) - { - glyphList = new FTGlyphContainer(&face); - } -} - - -FTFontImpl::~FTFontImpl() -{ - if(glyphList) - { - delete glyphList; - } -} - - -bool FTFontImpl::Attach(const char* fontFilePath) -{ - if(!face.Attach(fontFilePath)) - { - err = face.Error(); - return false; - } - - err = 0; - return true; -} - - -bool FTFontImpl::Attach(const unsigned char *pBufferBytes, - size_t bufferSizeInBytes) -{ - if(!face.Attach(pBufferBytes, bufferSizeInBytes)) - { - err = face.Error(); - return false; - } - - err = 0; - return true; -} - - -bool FTFontImpl::FaceSize(const unsigned int size, const unsigned int res) -{ - if(glyphList != NULL) - { - delete glyphList; - glyphList = NULL; - } - - charSize = face.Size(size, res); - err = face.Error(); - - if(err != 0) - { - return false; - } - - glyphList = new FTGlyphContainer(&face); - return true; -} - - -unsigned int FTFontImpl::FaceSize() const -{ - return charSize.CharSize(); -} - - -void FTFontImpl::Depth(float depth) -{ - ; -} - - -void FTFontImpl::Outset(float outset) -{ - ; -} - - -void FTFontImpl::Outset(float front, float back) -{ - ; -} - - -void FTFontImpl::GlyphLoadFlags(FT_Int flags) -{ - load_flags = flags; -} - - -bool FTFontImpl::CharMap(FT_Encoding encoding) -{ - bool result = glyphList->CharMap(encoding); - err = glyphList->Error(); - return result; -} - - -unsigned int FTFontImpl::CharMapCount() const -{ - return face.CharMapCount(); -} - - -FT_Encoding* FTFontImpl::CharMapList() -{ - return face.CharMapList(); -} - - -void FTFontImpl::UseDisplayList(bool useList) -{ - useDisplayLists = useList; -} - - -float FTFontImpl::Ascender() const -{ - return charSize.Ascender(); -} - - -float FTFontImpl::Descender() const -{ - return charSize.Descender(); -} - - -float FTFontImpl::LineHeight() const -{ - return charSize.Height(); -} - - -template -inline FTBBox FTFontImpl::BBoxI(const T* string, const int len, - FTPoint position, FTPoint spacing) -{ - FTBBox totalBBox; - - /* Only compute the bounds if string is non-empty. */ - if(string && ('\0' != string[0])) - { - // for multibyte - we can't rely on sizeof(T) == character - FTUnicodeStringItr ustr(string); - unsigned int thisChar = *ustr++; - unsigned int nextChar = *ustr; - - if(CheckGlyph(thisChar)) - { - totalBBox = glyphList->BBox(thisChar); - totalBBox += position; - - position += FTPoint(glyphList->Advance(thisChar, nextChar), 0.0); - } - - /* Expand totalBox by each glyph in string */ - for(int i = 1; (len < 0 && *ustr) || (len >= 0 && i < len); i++) - { - thisChar = *ustr++; - nextChar = *ustr; - - if(CheckGlyph(thisChar)) - { - position += spacing; - - FTBBox tempBBox = glyphList->BBox(thisChar); - tempBBox += position; - totalBBox |= tempBBox; - - position += FTPoint(glyphList->Advance(thisChar, nextChar), - 0.0); - } - } - } - - return totalBBox; -} - - -FTBBox FTFontImpl::BBox(const char *string, const int len, - FTPoint position, FTPoint spacing) -{ - /* The chars need to be unsigned because they are cast to int later */ - return BBoxI((const unsigned char *)string, len, position, spacing); -} - - -FTBBox FTFontImpl::BBox(const wchar_t *string, const int len, - FTPoint position, FTPoint spacing) -{ - return BBoxI(string, len, position, spacing); -} - - -template -inline float FTFontImpl::AdvanceI(const T* string, const int len, - FTPoint spacing) -{ - float advance = 0.0f; - FTUnicodeStringItr ustr(string); - - for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++) - { - unsigned int thisChar = *ustr++; - unsigned int nextChar = *ustr; - - if(CheckGlyph(thisChar)) - { - advance += glyphList->Advance(thisChar, nextChar); - } - - if(nextChar) - { - advance += spacing.Xf(); - } - } - - return advance; -} - - -float FTFontImpl::Advance(const char* string, const int len, FTPoint spacing) -{ - /* The chars need to be unsigned because they are cast to int later */ - return AdvanceI((const unsigned char *)string, len, spacing); -} - - -float FTFontImpl::Advance(const wchar_t* string, const int len, FTPoint spacing) -{ - return AdvanceI(string, len, spacing); -} - - -template -inline FTPoint FTFontImpl::RenderI(const T* string, const int len, - FTPoint position, FTPoint spacing, - int renderMode) -{ - // for multibyte - we can't rely on sizeof(T) == character - FTUnicodeStringItr ustr(string); - - for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++) - { - unsigned int thisChar = *ustr++; - unsigned int nextChar = *ustr; - - if(CheckGlyph(thisChar)) - { - position += glyphList->Render(thisChar, nextChar, - position, renderMode); - } - - if(nextChar) - { - position += spacing; - } - } - - return position; -} - - -FTPoint FTFontImpl::Render(const char * string, const int len, - FTPoint position, FTPoint spacing, int renderMode) -{ - return RenderI((const unsigned char *)string, - len, position, spacing, renderMode); -} - - -FTPoint FTFontImpl::Render(const wchar_t * string, const int len, - FTPoint position, FTPoint spacing, int renderMode) -{ - return RenderI(string, len, position, spacing, renderMode); -} - - -bool FTFontImpl::CheckGlyph(const unsigned int characterCode) -{ - if(glyphList->Glyph(characterCode)) - { - return true; - } - - unsigned int glyphIndex = glyphList->FontIndex(characterCode); - FT_GlyphSlot ftSlot = face.Glyph(glyphIndex, load_flags); - if(!ftSlot) - { - err = face.Error(); - return false; - } - - FTGlyph* tempGlyph = intf->MakeGlyph(ftSlot); - if(!tempGlyph) - { - if(0 == err) - { - err = 0x13; - } - - return false; - } - - glyphList->Add(tempGlyph, characterCode); - - return true; -} - +/* + * FTGL - OpenGL font library + * + * Copyright (c) 2001-2004 Henry Maddocks + * Copyright (c) 2008 Sam Hocevar + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "config.h" + +#include "FTInternals.h" +#include "FTUnicode.h" + +#include "FTFontImpl.h" + +#include "FTBitmapFontImpl.h" +#include "FTExtrudeFontImpl.h" +#include "FTOutlineFontImpl.h" +#include "FTPixmapFontImpl.h" +#include "FTPolygonFontImpl.h" +#include "FTTextureFontImpl.h" + +#include "FTGlyphContainer.h" +#include "FTFace.h" + + +// +// FTFont +// + + +FTFont::FTFont(char const *fontFilePath) +{ + impl = new FTFontImpl(this, fontFilePath); +} + + +FTFont::FTFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes) +{ + impl = new FTFontImpl(this, pBufferBytes, bufferSizeInBytes); +} + + +FTFont::FTFont(FTFontImpl *pImpl) +{ + impl = pImpl; +} + + +FTFont::~FTFont() +{ + delete impl; +} + + +bool FTFont::Attach(const char* fontFilePath) +{ + return impl->Attach(fontFilePath); +} + + +bool FTFont::Attach(const unsigned char *pBufferBytes, size_t bufferSizeInBytes) +{ + return impl->Attach(pBufferBytes, bufferSizeInBytes); +} + + +bool FTFont::FaceSize(const unsigned int size, const unsigned int res) +{ + return impl->FaceSize(size, res); +} + + +unsigned int FTFont::FaceSize() const +{ + return impl->FaceSize(); +} + + +void FTFont::Depth(float depth) +{ + return impl->Depth(depth); +} + + +void FTFont::Outset(float outset) +{ + return impl->Outset(outset); +} + + +void FTFont::Outset(float front, float back) +{ + return impl->Outset(front, back); +} + + +void FTFont::GlyphLoadFlags(FT_Int flags) +{ + return impl->GlyphLoadFlags(flags); +} + + +bool FTFont::CharMap(FT_Encoding encoding) +{ + return impl->CharMap(encoding); +} + + +unsigned int FTFont::CharMapCount() const +{ + return impl->CharMapCount(); +} + + +FT_Encoding* FTFont::CharMapList() +{ + return impl->CharMapList(); +} + + +void FTFont::UseDisplayList(bool useList) +{ + return impl->UseDisplayList(useList); +} + +//TECGRAF +bool FTFont::SetEncoding (FT_Encoding e) +{ + return impl->SetEncoding(e); +} + +//TECGRAF +void FTFont::SetEnableBlend(bool enable) +{ + impl->SetEnableBlend(enable); +} + +//TECGRAF +void FTFont::SetNearestFilter(bool enable) +{ + impl->SetNearestFilter(enable); +} + +float FTFont::Ascender() const +{ + return impl->Ascender(); +} + + +float FTFont::Descender() const +{ + return impl->Descender(); +} + + +float FTFont::LineHeight() const +{ + return impl->LineHeight(); +} + + +//TECGRAF +float FTFont::MaxWidth() const +{ + return impl->MaxWidth(); +} + + +FTPoint FTFont::Render(const char * string, const int len, + FTPoint position, FTPoint spacing, int renderMode) +{ + return impl->Render(string, len, position, spacing, renderMode); +} + + +FTPoint FTFont::Render(const wchar_t * string, const int len, + FTPoint position, FTPoint spacing, int renderMode) +{ + return impl->Render(string, len, position, spacing, renderMode); +} + + +float FTFont::Advance(const char * string, const int len, FTPoint spacing) +{ + return impl->Advance(string, len, spacing); +} + + +float FTFont::Advance(const wchar_t * string, const int len, FTPoint spacing) +{ + return impl->Advance(string, len, spacing); +} + + +FTBBox FTFont::BBox(const char *string, const int len, + FTPoint position, FTPoint spacing) +{ + return impl->BBox(string, len, position, spacing); +} + + +FTBBox FTFont::BBox(const wchar_t *string, const int len, + FTPoint position, FTPoint spacing) +{ + return impl->BBox(string, len, position, spacing); +} + +FT_Error FTFont::Error() const +{ + return impl->err; +} + +//TECGRAF +const char* FTFont::GetFamilyName () const +{ + return impl->GetFamilyName(); +} + +//TECGRAF +bool FTFont::IsBold () const +{ + return impl->IsBold(); +} + +//TECGRAF +bool FTFont::IsItalic () const +{ + return impl->IsItalic(); +} + +// +// FTFontImpl +// + + +FTFontImpl::FTFontImpl(FTFont *ftFont, char const *fontFilePath) : + face(fontFilePath), + useDisplayLists(true), + load_flags(FT_LOAD_DEFAULT), + intf(ftFont), + glyphList(0), + useBlending(false), + useNearest(false) +{ + err = face.Error(); + if(err == 0) + { + glyphList = new FTGlyphContainer(&face); + } +} + + +FTFontImpl::FTFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes, + size_t bufferSizeInBytes) : + face(pBufferBytes, bufferSizeInBytes), + useDisplayLists(true), + load_flags(FT_LOAD_DEFAULT), + intf(ftFont), + glyphList(0) +{ + err = face.Error(); + if(err == 0) + { + glyphList = new FTGlyphContainer(&face); + } +} + + +FTFontImpl::~FTFontImpl() +{ + if(glyphList) + { + delete glyphList; + } +} + + +bool FTFontImpl::Attach(const char* fontFilePath) +{ + if(!face.Attach(fontFilePath)) + { + err = face.Error(); + return false; + } + + err = 0; + return true; +} + + +bool FTFontImpl::Attach(const unsigned char *pBufferBytes, + size_t bufferSizeInBytes) +{ + if(!face.Attach(pBufferBytes, bufferSizeInBytes)) + { + err = face.Error(); + return false; + } + + err = 0; + return true; +} + + +bool FTFontImpl::FaceSize(const unsigned int size, const unsigned int res) +{ + if(glyphList != NULL) + { + delete glyphList; + glyphList = NULL; + } + + charSize = face.Size(size, res); + err = face.Error(); + + if(err != 0) + { + return false; + } + + glyphList = new FTGlyphContainer(&face); + return true; +} + + +unsigned int FTFontImpl::FaceSize() const +{ + return charSize.CharSize(); +} + + +void FTFontImpl::Depth(float depth) +{ + ; +} + + +void FTFontImpl::Outset(float outset) +{ + ; +} + + +void FTFontImpl::Outset(float front, float back) +{ + ; +} + + +void FTFontImpl::GlyphLoadFlags(FT_Int flags) +{ + load_flags = flags; +} + + +bool FTFontImpl::CharMap(FT_Encoding encoding) +{ + bool result = glyphList->CharMap(encoding); + err = glyphList->Error(); + return result; +} + + +unsigned int FTFontImpl::CharMapCount() const +{ + return face.CharMapCount(); +} + + +FT_Encoding* FTFontImpl::CharMapList() +{ + return face.CharMapList(); +} + + +void FTFontImpl::UseDisplayList(bool useList) +{ + useDisplayLists = useList; +} + +//TECGRAF +bool FTFontImpl::SetEncoding (FT_Encoding e) +{ + return glyphList->CharMap(e); +} + +//TECGRAF +void FTFontImpl::SetEnableBlend(bool enable) +{ + useBlending = enable; +} + +void FTFontImpl::SetNearestFilter(bool enable) +{ + useNearest = enable; +} + + +float FTFontImpl::Ascender() const +{ + return charSize.Ascender(); +} + + +float FTFontImpl::Descender() const +{ + return charSize.Descender(); +} + + +float FTFontImpl::LineHeight() const +{ + return charSize.Height(); +} + + +//TECGRAF +float FTFontImpl::MaxWidth() const +{ + return charSize.Width(); +} + + +template +inline FTBBox FTFontImpl::BBoxI(const T* string, const int len, + FTPoint position, FTPoint spacing) +{ + FTBBox totalBBox; + + /* Only compute the bounds if string is non-empty. */ + if(string && ('\0' != string[0])) + { + // for multibyte - we can't rely on sizeof(T) == character + FTUnicodeStringItr ustr(string); + unsigned int thisChar = *ustr++; + unsigned int nextChar = *ustr; + + if(CheckGlyph(thisChar)) + { + totalBBox = glyphList->BBox(thisChar); + totalBBox += position; + + position += FTPoint(glyphList->Advance(thisChar, nextChar), 0.0); + } + + /* Expand totalBox by each glyph in string */ + for(int i = 1; (len < 0 && *ustr) || (len >= 0 && i < len); i++) + { + thisChar = *ustr++; + nextChar = *ustr; + + if(CheckGlyph(thisChar)) + { + position += spacing; + + FTBBox tempBBox = glyphList->BBox(thisChar); + tempBBox += position; + totalBBox |= tempBBox; + + position += FTPoint(glyphList->Advance(thisChar, nextChar), + 0.0); + } + } + } + + return totalBBox; +} + + +FTBBox FTFontImpl::BBox(const char *string, const int len, + FTPoint position, FTPoint spacing) +{ + /* The chars need to be unsigned because they are cast to int later */ + return BBoxI((const unsigned char *)string, len, position, spacing); +} + + +FTBBox FTFontImpl::BBox(const wchar_t *string, const int len, + FTPoint position, FTPoint spacing) +{ + return BBoxI(string, len, position, spacing); +} + + +template +inline float FTFontImpl::AdvanceI(const T* string, const int len, + FTPoint spacing) +{ + float advance = 0.0f; + FTUnicodeStringItr ustr(string); + + for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++) + { + unsigned int thisChar = *ustr++; + unsigned int nextChar = *ustr; + + if(CheckGlyph(thisChar)) + { + advance += glyphList->Advance(thisChar, nextChar); + } + + if(nextChar) + { + advance += spacing.Xf(); + } + } + + return advance; +} + + +float FTFontImpl::Advance(const char* string, const int len, FTPoint spacing) +{ + /* The chars need to be unsigned because they are cast to int later */ + return AdvanceI((const unsigned char *)string, len, spacing); +} + + +float FTFontImpl::Advance(const wchar_t* string, const int len, FTPoint spacing) +{ + return AdvanceI(string, len, spacing); +} + + +template +inline FTPoint FTFontImpl::RenderI(const T* string, const int len, + FTPoint position, FTPoint spacing, + int renderMode) +{ + // for multibyte - we can't rely on sizeof(T) == character + FTUnicodeStringItr ustr(string); + + for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++) + { + unsigned int thisChar = *ustr++; + unsigned int nextChar = *ustr; + + if(CheckGlyph(thisChar)) + { + position += glyphList->Render(thisChar, nextChar, + position, renderMode); + } + + if(nextChar) + { + position += spacing; + } + } + + return position; +} + + +FTPoint FTFontImpl::Render(const char * string, const int len, + FTPoint position, FTPoint spacing, int renderMode) +{ + return RenderI((const unsigned char *)string, + len, position, spacing, renderMode); +} + + +FTPoint FTFontImpl::Render(const wchar_t * string, const int len, + FTPoint position, FTPoint spacing, int renderMode) +{ + return RenderI(string, len, position, spacing, renderMode); +} + + +bool FTFontImpl::CheckGlyph(const unsigned int characterCode) +{ + if(glyphList->Glyph(characterCode)) + { + return true; + } + + unsigned int glyphIndex = glyphList->FontIndex(characterCode); + FT_GlyphSlot ftSlot = face.Glyph(glyphIndex, load_flags); + if(!ftSlot) + { + err = face.Error(); + return false; + } + + // TECGRAF + if (load_flags == FT_LOAD_DEFAULT && + ftSlot->format == FT_GLYPH_FORMAT_BITMAP && + ftSlot->bitmap.num_grays == 0) + { + /* workaround for ClearType fonts */ + load_flags |= FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; + ftSlot = face.Glyph(glyphIndex, load_flags); + } + + FTGlyph* tempGlyph = intf->MakeGlyph(ftSlot); + if(!tempGlyph) + { + if(0 == err) + { + err = 0x13; + } + + return false; + } + + glyphList->Add(tempGlyph, characterCode); + + return true; +} + +//TECGRAF +const char* FTFontImpl::GetFamilyName () const +{ + return face.GetFamilyName(); +} + +//TECGRAF +bool FTFontImpl::IsBold () const +{ + return face.IsBold(); +} + +//TECGRAF +bool FTFontImpl::IsItalic () const +{ + return face.IsItalic(); +} diff --git a/src/FTFont/FTFontGlue.cpp b/src/FTFont/FTFontGlue.cpp old mode 100644 new mode 100755 index b23e787..7ec5082 --- a/src/FTFont/FTFontGlue.cpp +++ b/src/FTFont/FTFontGlue.cpp @@ -180,6 +180,9 @@ C_FUN(void, ftglSetFontOutset, (FTGLfont *f, float front, float back), C_FUN(void, ftglSetFontDisplayList, (FTGLfont *f, int l), return, UseDisplayList, (l != 0)); +C_FUN(void, ftglSetNearestFilter, (FTGLfont *f, int l), + return, SetNearestFilter, (l != 0)); + // float FTFont::Ascender() const; C_FUN(float, ftglGetFontAscender, (FTGLfont *f), return 0.f, Ascender, ()); @@ -189,6 +192,10 @@ C_FUN(float, ftglGetFontDescender, (FTGLfont *f), return 0.f, Descender, ()); // float FTFont::LineHeight() const; C_FUN(float, ftglGetFontLineHeight, (FTGLfont *f), return 0.f, LineHeight, ()); +//TECGRAF +// float FTFont::MaxWidth() const; +C_FUN(float, ftglGetFontMaxWidth, (FTGLfont *f), return 0.f, MaxWidth, ()); + // void FTFont::BBox(const char* string, float& llx, float& lly, float& llz, // float& urx, float& ury, float& urz); extern "C++" { diff --git a/src/FTFont/FTFontImpl.h b/src/FTFont/FTFontImpl.h old mode 100644 new mode 100755 index 36c3bf8..0904721 --- a/src/FTFont/FTFontImpl.h +++ b/src/FTFont/FTFontImpl.h @@ -1,162 +1,193 @@ -/* - * FTGL - OpenGL font library - * - * Copyright (c) 2001-2004 Henry Maddocks - * Copyright (c) 2008 Sam Hocevar - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef __FTFontImpl__ -#define __FTFontImpl__ - -#include "FTGL/ftgl.h" - -#include "FTFace.h" - -class FTGlyphContainer; -class FTGlyph; - -class FTFontImpl -{ - friend class FTFont; - - protected: - FTFontImpl(FTFont *ftFont, char const *fontFilePath); - - FTFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes, - size_t bufferSizeInBytes); - - virtual ~FTFontImpl(); - - virtual bool Attach(const char* fontFilePath); - - virtual bool Attach(const unsigned char *pBufferBytes, - size_t bufferSizeInBytes); - - virtual void GlyphLoadFlags(FT_Int flags); - - virtual bool CharMap(FT_Encoding encoding); - - virtual unsigned int CharMapCount() const; - - virtual FT_Encoding* CharMapList(); - - virtual void UseDisplayList(bool useList); - - virtual float Ascender() const; - - virtual float Descender() const; - - virtual float LineHeight() const; - - virtual bool FaceSize(const unsigned int size, - const unsigned int res); - - virtual unsigned int FaceSize() const; - - virtual void Depth(float depth); - - virtual void Outset(float outset); - - virtual void Outset(float front, float back); - - virtual FTBBox BBox(const char *s, const int len, FTPoint, FTPoint); - - virtual FTBBox BBox(const wchar_t *s, const int len, FTPoint, FTPoint); - - virtual float Advance(const char *s, const int len, FTPoint); - - virtual float Advance(const wchar_t *s, const int len, FTPoint); - - virtual FTPoint Render(const char *s, const int len, - FTPoint, FTPoint, int); - - virtual FTPoint Render(const wchar_t *s, const int len, - FTPoint, FTPoint, int); - - /** - * Current face object - */ - FTFace face; - - /** - * Current size object - */ - FTSize charSize; - - /** - * Flag to enable or disable the use of Display Lists inside FTGL - * true turns ON display lists. - * false turns OFF display lists. - */ - bool useDisplayLists; - - /** - * The default glyph loading flags. - */ - FT_Int load_flags; - - /** - * Current error code. Zero means no error. - */ - FT_Error err; - - private: - /** - * A link back to the interface of which we are the implementation. - */ - FTFont *intf; - - /** - * Check that the glyph at chr exist. If not load it. - * - * @param chr character index - * @return true if the glyph can be created. - */ - bool CheckGlyph(const unsigned int chr); - - /** - * An object that holds a list of glyphs - */ - FTGlyphContainer* glyphList; - - /** - * Current pen or cursor position; - */ - FTPoint pen; - - /* Internal generic BBox() implementation */ - template - inline FTBBox BBoxI(const T *s, const int len, - FTPoint position, FTPoint spacing); - - /* Internal generic Advance() implementation */ - template - inline float AdvanceI(const T *s, const int len, FTPoint spacing); - - /* Internal generic Render() implementation */ - template - inline FTPoint RenderI(const T *s, const int len, - FTPoint position, FTPoint spacing, int mode); -}; - -#endif // __FTFontImpl__ - +/* + * FTGL - OpenGL font library + * + * Copyright (c) 2001-2004 Henry Maddocks + * Copyright (c) 2008 Sam Hocevar + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __FTFontImpl__ +#define __FTFontImpl__ + +#include "FTGL/ftgl.h" + +#include "FTFace.h" + +class FTGlyphContainer; +class FTGlyph; + +class FTFontImpl +{ + friend class FTFont; + + protected: + FTFontImpl(FTFont *ftFont, char const *fontFilePath); + + FTFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes, + size_t bufferSizeInBytes); + + virtual ~FTFontImpl(); + + virtual bool Attach(const char* fontFilePath); + + virtual bool Attach(const unsigned char *pBufferBytes, + size_t bufferSizeInBytes); + + virtual void GlyphLoadFlags(FT_Int flags); + + virtual bool CharMap(FT_Encoding encoding); + + virtual unsigned int CharMapCount() const; + + virtual FT_Encoding* CharMapList(); + + virtual void UseDisplayList(bool useList); + + //TECGRAF + virtual bool SetEncoding (FT_Encoding e); + + //TECGRAF + virtual void SetEnableBlend(bool enable); + + //TECGRAF + virtual void SetNearestFilter(bool enable); + + virtual float Ascender() const; + + virtual float Descender() const; + + virtual float LineHeight() const; + + //TECGRAF + virtual float MaxWidth() const; + + virtual bool FaceSize(const unsigned int size, + const unsigned int res); + + virtual unsigned int FaceSize() const; + + virtual void Depth(float depth); + + virtual void Outset(float outset); + + virtual void Outset(float front, float back); + + virtual FTBBox BBox(const char *s, const int len, FTPoint, FTPoint); + + virtual FTBBox BBox(const wchar_t *s, const int len, FTPoint, FTPoint); + + virtual float Advance(const char *s, const int len, FTPoint); + + virtual float Advance(const wchar_t *s, const int len, FTPoint); + + virtual FTPoint Render(const char *s, const int len, + FTPoint, FTPoint, int); + + virtual FTPoint Render(const wchar_t *s, const int len, + FTPoint, FTPoint, int); + + //TECGRAF + const char* GetFamilyName () const; + bool IsBold () const; + bool IsItalic () const; + + /** + * Current face object + */ + FTFace face; + + /** + * Current size object + */ + FTSize charSize; + + /** + * Flag to enable or disable the use of Display Lists inside FTGL + * true turns ON display lists. + * false turns OFF display lists. + */ + bool useDisplayLists; + + /** TECGRAF + * Flag to enable or disable the use of blending inside FTGL + * true turns ON blending. + * false turns OFF blending. + */ + bool useBlending; + + /** TECGRAF + * Flag to enable or disable the use of nearest texture filter inside FTGL + * true turns ON nearest. + * false turns OFF nearest (linear, the default). + */ + bool useNearest; + + /** + * The default glyph loading flags. + */ + FT_Int load_flags; + + /** + * Current error code. Zero means no error. + */ + FT_Error err; + + private: + /** + * A link back to the interface of which we are the implementation. + */ + FTFont *intf; + + /** + * Check that the glyph at chr exist. If not load it. + * + * @param chr character index + * @return true if the glyph can be created. + */ + bool CheckGlyph(const unsigned int chr); + + /** + * An object that holds a list of glyphs + */ + FTGlyphContainer* glyphList; + + /** + * Current pen or cursor position; + */ + FTPoint pen; + + /* Internal generic BBox() implementation */ + template + inline FTBBox BBoxI(const T *s, const int len, + FTPoint position, FTPoint spacing); + + /* Internal generic Advance() implementation */ + template + inline float AdvanceI(const T *s, const int len, FTPoint spacing); + + /* Internal generic Render() implementation */ + template + inline FTPoint RenderI(const T *s, const int len, + FTPoint position, FTPoint spacing, int mode); +}; + +#endif // __FTFontImpl__ + diff --git a/src/FTFont/FTPixmapFont.cpp b/src/FTFont/FTPixmapFont.cpp old mode 100644 new mode 100755 index 5638ac8..98aad01 --- a/src/FTFont/FTPixmapFont.cpp +++ b/src/FTFont/FTPixmapFont.cpp @@ -66,7 +66,7 @@ FTGlyph* FTPixmapFont::MakeGlyph(FT_GlyphSlot ftGlyph) FTPixmapFontImpl::FTPixmapFontImpl(FTFont *ftFont, const char* fontFilePath) : FTFontImpl(ftFont, fontFilePath) { - load_flags = FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; + load_flags = FT_LOAD_DEFAULT; //TECGRAF - was FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; } @@ -75,7 +75,7 @@ FTPixmapFontImpl::FTPixmapFontImpl(FTFont *ftFont, size_t bufferSizeInBytes) : FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes) { - load_flags = FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; + load_flags = FT_LOAD_DEFAULT; //TECGRAF - was FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; } @@ -90,9 +90,13 @@ inline FTPoint FTPixmapFontImpl::RenderI(const T* string, const int len, // Protect glPixelStorei() calls (made by FTPixmapGlyphImpl::RenderImpl). glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + //TECGRAF + if (useBlending) + { + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + } glDisable(GL_TEXTURE_2D); @@ -129,3 +133,4 @@ FTPoint FTPixmapFontImpl::Render(const wchar_t * string, const int len, return RenderI(string, len, position, spacing, renderMode); } + diff --git a/src/FTFont/FTTextureFont.cpp b/src/FTFont/FTTextureFont.cpp old mode 100644 new mode 100755 index 4e385ea..a114041 --- a/src/FTFont/FTTextureFont.cpp +++ b/src/FTFont/FTTextureFont.cpp @@ -99,7 +99,7 @@ FTTextureFontImpl::FTTextureFontImpl(FTFont *ftFont, const char* fontFilePath) xOffset(0), yOffset(0) { - load_flags = FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; + load_flags = FT_LOAD_DEFAULT; //TECGRAF - was FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; remGlyphs = numGlyphs = face.GlyphCount(); } @@ -117,7 +117,7 @@ FTTextureFontImpl::FTTextureFontImpl(FTFont *ftFont, xOffset(0), yOffset(0) { - load_flags = FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; + load_flags = FT_LOAD_DEFAULT; //TECGRAF - was FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; remGlyphs = numGlyphs = face.GlyphCount(); } @@ -241,6 +241,11 @@ inline FTPoint FTTextureFontImpl::RenderI(const T* string, const int len, FTTextureGlyphImpl::ResetActiveTexture(); + // TECGRAF renderMode here is always RENDER_ALL, + // so we use it to control texture filter + if (useNearest) + renderMode |= 0x10000; + FTPoint tmp = FTFontImpl::Render(string, len, position, spacing, renderMode); diff --git a/src/FTGL/FTFont.h b/src/FTGL/FTFont.h old mode 100644 new mode 100755 index 0799fff..c3793d8 --- a/src/FTGL/FTFont.h +++ b/src/FTGL/FTFont.h @@ -1,584 +1,631 @@ -/* - * FTGL - OpenGL font library - * - * Copyright (c) 2001-2004 Henry Maddocks - * Copyright (c) 2008 Sam Hocevar - * Copyright (c) 2008 Sean Morrison - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef __ftgl__ -# warning This header is deprecated. Please use from now. -# include -#endif - -#ifndef __FTFont__ -#define __FTFont__ - -#ifdef __cplusplus - -class FTFontImpl; - -/** - * FTFont is the public interface for the FTGL library. - * - * Specific font classes are derived from this class. It uses the helper - * classes FTFace and FTSize to access the Freetype library. This class - * is abstract and deriving classes must implement the protected - * MakeGlyph function to create glyphs of the - * appropriate type. - * - * It is good practice after using these functions to test the error - * code returned. FT_Error Error(). Check the freetype file - * fterrdef.h for error definitions. - * - * @see FTFace - * @see FTSize - */ -class FTGL_EXPORT FTFont -{ - protected: - /** - * Open and read a font file. Sets Error flag. - * - * @param fontFilePath font file path. - */ - FTFont(char const *fontFilePath); - - /** - * Open and read a font from a buffer in memory. Sets Error flag. - * The buffer is owned by the client and is NOT copied by FTGL. The - * pointer must be valid while using FTGL. - * - * @param pBufferBytes the in-memory buffer - * @param bufferSizeInBytes the length of the buffer in bytes - */ - FTFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes); - - private: - /* Allow our internal subclasses to access the private constructor */ - friend class FTBitmapFont; - friend class FTBufferFont; - friend class FTExtrudeFont; - friend class FTOutlineFont; - friend class FTPixmapFont; - friend class FTPolygonFont; - friend class FTTextureFont; - - /** - * Internal FTGL FTFont constructor. For private use only. - * - * @param pImpl Internal implementation object. Will be destroyed - * upon FTFont deletion. - */ - FTFont(FTFontImpl *pImpl); - - public: - virtual ~FTFont(); - - /** - * Attach auxilliary file to font e.g font metrics. - * - * Note: not all font formats implement this function. - * - * @param fontFilePath auxilliary font file path. - * @return true if file has been attached - * successfully. - */ - virtual bool Attach(const char* fontFilePath); - - /** - * Attach auxilliary data to font e.g font metrics, from memory. - * - * Note: not all font formats implement this function. - * - * @param pBufferBytes the in-memory buffer. - * @param bufferSizeInBytes the length of the buffer in bytes. - * @return true if file has been attached - * successfully. - */ - virtual bool Attach(const unsigned char *pBufferBytes, - size_t bufferSizeInBytes); - - /** - * Set the glyph loading flags. By default, fonts use the most - * sensible flags when loading a font's glyph using FT_Load_Glyph(). - * This function allows to override the default flags. - * - * @param flags The glyph loading flags. - */ - virtual void GlyphLoadFlags(FT_Int flags); - - /** - * Set the character map for the face. - * - * @param encoding Freetype enumerate for char map code. - * @return true if charmap was valid and - * set correctly. - */ - virtual bool CharMap(FT_Encoding encoding); - - /** - * Get the number of character maps in this face. - * - * @return character map count. - */ - virtual unsigned int CharMapCount() const; - - /** - * Get a list of character maps in this face. - * - * @return pointer to the first encoding. - */ - virtual FT_Encoding* CharMapList(); - - /** - * Set the char size for the current face. - * - * @param size the face size in points (1/72 inch) - * @param res the resolution of the target device. - * @return true if size was set correctly - */ - virtual bool FaceSize(const unsigned int size, - const unsigned int res = 72); - - /** - * Get the current face size in points (1/72 inch). - * - * @return face size - */ - virtual unsigned int FaceSize() const; - - /** - * Set the extrusion distance for the font. Only implemented by - * FTExtrudeFont - * - * @param depth The extrusion distance. - */ - virtual void Depth(float depth); - - /** - * Set the outset distance for the font. Only implemented by - * FTOutlineFont, FTPolygonFont and FTExtrudeFont - * - * @param outset The outset distance. - */ - virtual void Outset(float outset); - - /** - * Set the front and back outset distances for the font. Only - * implemented by FTExtrudeFont - * - * @param front The front outset distance. - * @param back The back outset distance. - */ - virtual void Outset(float front, float back); - - /** - * Enable or disable the use of Display Lists inside FTGL - * - * @param useList true turns ON display lists. - * false turns OFF display lists. - */ - virtual void UseDisplayList(bool useList); - - /** - * Get the global ascender height for the face. - * - * @return Ascender height - */ - virtual float Ascender() const; - - /** - * Gets the global descender height for the face. - * - * @return Descender height - */ - virtual float Descender() const; - - /** - * Gets the line spacing for the font. - * - * @return Line height - */ - virtual float LineHeight() const; - - /** - * Get the bounding box for a string. - * - * @param string A char buffer. - * @param len The length of the string. If < 0 then all characters - * will be checked until a null character is encountered - * (optional). - * @param position The pen position of the first character (optional). - * @param spacing A displacement vector to add after each character - * has been checked (optional). - * @return The corresponding bounding box. - */ - virtual FTBBox BBox(const char *string, const int len = -1, - FTPoint position = FTPoint(), - FTPoint spacing = FTPoint()); - - /** - * Get the bounding box for a string (deprecated). - * - * @param string A char buffer. - * @param llx Lower left near x coordinate. - * @param lly Lower left near y coordinate. - * @param llz Lower left near z coordinate. - * @param urx Upper right far x coordinate. - * @param ury Upper right far y coordinate. - * @param urz Upper right far z coordinate. - */ - void BBox(const char* string, float& llx, float& lly, float& llz, - float& urx, float& ury, float& urz) - { - FTBBox b = BBox(string); - llx = b.Lower().Xf(); lly = b.Lower().Yf(); llz = b.Lower().Zf(); - urx = b.Upper().Xf(); ury = b.Upper().Yf(); urz = b.Upper().Zf(); - } - - /** - * Get the bounding box for a string. - * - * @param string A wchar_t buffer. - * @param len The length of the string. If < 0 then all characters - * will be checked until a null character is encountered - * (optional). - * @param position The pen position of the first character (optional). - * @param spacing A displacement vector to add after each character - * has been checked (optional). - * @return The corresponding bounding box. - */ - virtual FTBBox BBox(const wchar_t *string, const int len = -1, - FTPoint position = FTPoint(), - FTPoint spacing = FTPoint()); - - /** - * Get the bounding box for a string (deprecated). - * - * @param string A wchar_t buffer. - * @param llx Lower left near x coordinate. - * @param lly Lower left near y coordinate. - * @param llz Lower left near z coordinate. - * @param urx Upper right far x coordinate. - * @param ury Upper right far y coordinate. - * @param urz Upper right far z coordinate. - */ - void BBox(const wchar_t* string, float& llx, float& lly, float& llz, - float& urx, float& ury, float& urz) - { - FTBBox b = BBox(string); - llx = b.Lower().Xf(); lly = b.Lower().Yf(); llz = b.Lower().Zf(); - urx = b.Upper().Xf(); ury = b.Upper().Yf(); urz = b.Upper().Zf(); - } - - /** - * Get the advance for a string. - * - * @param string 'C' style string to be checked. - * @param len The length of the string. If < 0 then all characters - * will be checked until a null character is encountered - * (optional). - * @param spacing A displacement vector to add after each character - * has been checked (optional). - * @return The string's advance width. - */ - virtual float Advance(const char* string, const int len = -1, - FTPoint spacing = FTPoint()); - - /** - * Get the advance for a string. - * - * @param string A wchar_t string - * @param len The length of the string. If < 0 then all characters - * will be checked until a null character is encountered - * (optional). - * @param spacing A displacement vector to add after each character - * has been checked (optional). - * @return The string's advance width. - */ - virtual float Advance(const wchar_t* string, const int len = -1, - FTPoint spacing = FTPoint()); - - /** - * Render a string of characters. - * - * @param string 'C' style string to be output. - * @param len The length of the string. If < 0 then all characters - * will be displayed until a null character is encountered - * (optional). - * @param position The pen position of the first character (optional). - * @param spacing A displacement vector to add after each character - * has been displayed (optional). - * @param renderMode Render mode to use for display (optional). - * @return The new pen position after the last character was output. - */ - virtual FTPoint Render(const char* string, const int len = -1, - FTPoint position = FTPoint(), - FTPoint spacing = FTPoint(), - int renderMode = FTGL::RENDER_ALL); - - /** - * Render a string of characters - * - * @param string wchar_t string to be output. - * @param len The length of the string. If < 0 then all characters - * will be displayed until a null character is encountered - * (optional). - * @param position The pen position of the first character (optional). - * @param spacing A displacement vector to add after each character - * has been displayed (optional). - * @param renderMode Render mode to use for display (optional). - * @return The new pen position after the last character was output. - */ - virtual FTPoint Render(const wchar_t *string, const int len = -1, - FTPoint position = FTPoint(), - FTPoint spacing = FTPoint(), - int renderMode = FTGL::RENDER_ALL); - - /** - * Queries the Font for errors. - * - * @return The current error code. - */ - virtual FT_Error Error() const; - - protected: - /* Allow impl to access MakeGlyph */ - friend class FTFontImpl; - - /** - * Construct a glyph of the correct type. - * - * Clients must override the function and return their specialised - * FTGlyph. - * - * @param slot A FreeType glyph slot. - * @return An FT****Glyph or null on failure. - */ - virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot) = 0; - - private: - /** - * Internal FTGL FTFont implementation object. For private use only. - */ - FTFontImpl *impl; -}; - -#endif //__cplusplus - -FTGL_BEGIN_C_DECLS - -/** - * FTGLfont is the public interface for the FTGL library. - * - * It is good practice after using these functions to test the error - * code returned. FT_Error Error(). Check the freetype file - * fterrdef.h for error definitions. - */ -struct _FTGLFont; -typedef struct _FTGLfont FTGLfont; - -/** - * Create a custom FTGL font object. - * - * @param fontFilePath The font file name. - * @param data A pointer to private data that will be passed to callbacks. - * @param makeglyphCallback A glyph-making callback function. - * @return An FTGLfont* object. - */ -FTGL_EXPORT FTGLfont *ftglCreateCustomFont(char const *fontFilePath, - void *data, - FTGLglyph * (*makeglyphCallback) (FT_GlyphSlot, void *)); - -/** - * Destroy an FTGL font object. - * - * @param font An FTGLfont* object. - */ -FTGL_EXPORT void ftglDestroyFont(FTGLfont* font); - -/** - * Attach auxilliary file to font e.g. font metrics. - * - * Note: not all font formats implement this function. - * - * @param font An FTGLfont* object. - * @param path Auxilliary font file path. - * @return 1 if file has been attached successfully. - */ -FTGL_EXPORT int ftglAttachFile(FTGLfont* font, const char* path); - -/** - * Attach auxilliary data to font, e.g. font metrics, from memory. - * - * Note: not all font formats implement this function. - * - * @param font An FTGLfont* object. - * @param data The in-memory buffer. - * @param size The length of the buffer in bytes. - * @return 1 if file has been attached successfully. - */ -FTGL_EXPORT int ftglAttachData(FTGLfont* font, const unsigned char * data, - size_t size); - -/** - * Set the character map for the face. - * - * @param font An FTGLfont* object. - * @param encoding Freetype enumerate for char map code. - * @return 1 if charmap was valid and set correctly. - */ -FTGL_EXPORT int ftglSetFontCharMap(FTGLfont* font, FT_Encoding encoding); - -/** - * Get the number of character maps in this face. - * - * @param font An FTGLfont* object. - * @return character map count. - */ -FTGL_EXPORT unsigned int ftglGetFontCharMapCount(FTGLfont* font); - -/** - * Get a list of character maps in this face. - * - * @param font An FTGLfont* object. - * @return pointer to the first encoding. - */ -FTGL_EXPORT FT_Encoding* ftglGetFontCharMapList(FTGLfont* font); - -/** - * Set the char size for the current face. - * - * @param font An FTGLfont* object. - * @param size The face size in points (1/72 inch). - * @param res The resolution of the target device, or 0 to use the default - * value of 72. - * @return 1 if size was set correctly. - */ -FTGL_EXPORT int ftglSetFontFaceSize(FTGLfont* font, unsigned int size, - unsigned int res); - -/** - * Get the current face size in points (1/72 inch). - * - * @param font An FTGLfont* object. - * @return face size - */ -FTGL_EXPORT unsigned int ftglGetFontFaceSize(FTGLfont* font); - -/** - * Set the extrusion distance for the font. Only implemented by - * FTExtrudeFont. - * - * @param font An FTGLfont* object. - * @param depth The extrusion distance. - */ -FTGL_EXPORT void ftglSetFontDepth(FTGLfont* font, float depth); - -/** - * Set the outset distance for the font. Only FTOutlineFont, FTPolygonFont - * and FTExtrudeFont implement front outset. Only FTExtrudeFont implements - * back outset. - * - * @param font An FTGLfont* object. - * @param front The front outset distance. - * @param back The back outset distance. - */ -FTGL_EXPORT void ftglSetFontOutset(FTGLfont* font, float front, float back); - -/** - * Enable or disable the use of Display Lists inside FTGL. - * - * @param font An FTGLfont* object. - * @param useList 1 turns ON display lists. - * 0 turns OFF display lists. - */ -FTGL_EXPORT void ftglSetFontDisplayList(FTGLfont* font, int useList); - -/** - * Get the global ascender height for the face. - * - * @param font An FTGLfont* object. - * @return Ascender height - */ -FTGL_EXPORT float ftglGetFontAscender(FTGLfont* font); - -/** - * Gets the global descender height for the face. - * - * @param font An FTGLfont* object. - * @return Descender height - */ -FTGL_EXPORT float ftglGetFontDescender(FTGLfont* font); - -/** - * Gets the line spacing for the font. - * - * @param font An FTGLfont* object. - * @return Line height - */ -FTGL_EXPORT float ftglGetFontLineHeight(FTGLfont* font); - -/** - * Get the bounding box for a string. - * - * @param font An FTGLfont* object. - * @param string A char buffer - * @param len The length of the string. If < 0 then all characters will be - * checked until a null character is encountered (optional). - * @param bounds An array of 6 float values where the bounding box's lower - * left near and upper right far 3D coordinates will be stored. - */ -FTGL_EXPORT void ftglGetFontBBox(FTGLfont* font, const char *string, - int len, float bounds[6]); - -/** - * Get the advance width for a string. - * - * @param font An FTGLfont* object. - * @param string A char string. - * @return Advance width - */ -FTGL_EXPORT float ftglGetFontAdvance(FTGLfont* font, const char *string); - -/** - * Render a string of characters. - * - * @param font An FTGLfont* object. - * @param string Char string to be output. - * @param mode Render mode to display. - */ -FTGL_EXPORT void ftglRenderFont(FTGLfont* font, const char *string, int mode); - -/** - * Query a font for errors. - * - * @param font An FTGLfont* object. - * @return The current error code. - */ -FTGL_EXPORT FT_Error ftglGetFontError(FTGLfont* font); - -FTGL_END_C_DECLS - -#endif // __FTFont__ - +/* + * FTGL - OpenGL font library + * + * Copyright (c) 2001-2004 Henry Maddocks + * Copyright (c) 2008 Sam Hocevar + * Copyright (c) 2008 Sean Morrison + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __ftgl__ +# warning This header is deprecated. Please use from now. +# include +#endif + +#ifndef __FTFont__ +#define __FTFont__ + +#ifdef __cplusplus + +class FTFontImpl; + +/** + * FTFont is the public interface for the FTGL library. + * + * Specific font classes are derived from this class. It uses the helper + * classes FTFace and FTSize to access the Freetype library. This class + * is abstract and deriving classes must implement the protected + * MakeGlyph function to create glyphs of the + * appropriate type. + * + * It is good practice after using these functions to test the error + * code returned. FT_Error Error(). Check the freetype file + * fterrdef.h for error definitions. + * + * @see FTFace + * @see FTSize + */ +class FTGL_EXPORT FTFont +{ + protected: + /** + * Open and read a font file. Sets Error flag. + * + * @param fontFilePath font file path. + */ + FTFont(char const *fontFilePath); + + /** + * Open and read a font from a buffer in memory. Sets Error flag. + * The buffer is owned by the client and is NOT copied by FTGL. The + * pointer must be valid while using FTGL. + * + * @param pBufferBytes the in-memory buffer + * @param bufferSizeInBytes the length of the buffer in bytes + */ + FTFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes); + + private: + /* Allow our internal subclasses to access the private constructor */ + friend class FTBitmapFont; + friend class FTBufferFont; + friend class FTExtrudeFont; + friend class FTOutlineFont; + friend class FTPixmapFont; + friend class FTPolygonFont; + friend class FTTextureFont; + + /** + * Internal FTGL FTFont constructor. For private use only. + * + * @param pImpl Internal implementation object. Will be destroyed + * upon FTFont deletion. + */ + FTFont(FTFontImpl *pImpl); + + public: + virtual ~FTFont(); + + /** + * Attach auxilliary file to font e.g font metrics. + * + * Note: not all font formats implement this function. + * + * @param fontFilePath auxilliary font file path. + * @return true if file has been attached + * successfully. + */ + virtual bool Attach(const char* fontFilePath); + + /** + * Attach auxilliary data to font e.g font metrics, from memory. + * + * Note: not all font formats implement this function. + * + * @param pBufferBytes the in-memory buffer. + * @param bufferSizeInBytes the length of the buffer in bytes. + * @return true if file has been attached + * successfully. + */ + virtual bool Attach(const unsigned char *pBufferBytes, + size_t bufferSizeInBytes); + + /** + * Set the glyph loading flags. By default, fonts use the most + * sensible flags when loading a font's glyph using FT_Load_Glyph(). + * This function allows to override the default flags. + * + * @param flags The glyph loading flags. + */ + virtual void GlyphLoadFlags(FT_Int flags); + + /** + * Set the character map for the face. + * + * @param encoding Freetype enumerate for char map code. + * @return true if charmap was valid and + * set correctly. + */ + virtual bool CharMap(FT_Encoding encoding); + + /** + * Get the number of character maps in this face. + * + * @return character map count. + */ + virtual unsigned int CharMapCount() const; + + /** + * Get a list of character maps in this face. + * + * @return pointer to the first encoding. + */ + virtual FT_Encoding* CharMapList(); + + /** + * Set the char size for the current face. + * + * @param size the face size in points (1/72 inch) + * @param res the resolution of the target device. + * @return true if size was set correctly + */ + virtual bool FaceSize(const unsigned int size, + const unsigned int res = 72); + + /** + * Get the current face size in points (1/72 inch). + * + * @return face size + */ + virtual unsigned int FaceSize() const; + + /** + * Set the extrusion distance for the font. Only implemented by + * FTExtrudeFont + * + * @param depth The extrusion distance. + */ + virtual void Depth(float depth); + + /** + * Set the outset distance for the font. Only implemented by + * FTOutlineFont, FTPolygonFont and FTExtrudeFont + * + * @param outset The outset distance. + */ + virtual void Outset(float outset); + + /** + * Set the front and back outset distances for the font. Only + * implemented by FTExtrudeFont + * + * @param front The front outset distance. + * @param back The back outset distance. + */ + virtual void Outset(float front, float back); + + /** + * Enable or disable the use of Display Lists inside FTGL + * + * @param useList true turns ON display lists. + * false turns OFF display lists. + */ + virtual void UseDisplayList(bool useList); + + /** TECGRAF + * Sets the CharMap encoding for spcific character in string. + * + * @param e CharMap encoding + * @return bool If encoding was valid for current font. + */ + virtual bool SetEncoding (FT_Encoding e); + + /** TECGRAF + * Enable or disable the use of blending + * + * @param useBlend true turns ON blending. + * false turns OFF blending (default). + */ + virtual void SetEnableBlend(bool enable); + + /** TECGRAF + * Enable or disable the use of the nearest filter in texture + * + * @param useBlend true turns ON nearest. + * false turns OFF nearest (default). + */ + virtual void SetNearestFilter(bool enable); + + /** + * Get the global ascender height for the face. + * + * @return Ascender height + */ + virtual float Ascender() const; + + /** + * Gets the global descender height for the face. + * + * @return Descender height + */ + virtual float Descender() const; + + /** + * Gets the line spacing for the font. + * + * @return Line height + */ + virtual float LineHeight() const; + + /** TECGRAF + * Gets the maximum character width for the font. + * + * @return Maximum width + */ + virtual float MaxWidth() const; + + /** + * Get the bounding box for a string. + * + * @param string A char buffer. + * @param len The length of the string. If < 0 then all characters + * will be checked until a null character is encountered + * (optional). + * @param position The pen position of the first character (optional). + * @param spacing A displacement vector to add after each character + * has been checked (optional). + * @return The corresponding bounding box. + */ + virtual FTBBox BBox(const char *string, const int len = -1, + FTPoint position = FTPoint(), + FTPoint spacing = FTPoint()); + + /** + * Get the bounding box for a string (deprecated). + * + * @param string A char buffer. + * @param llx Lower left near x coordinate. + * @param lly Lower left near y coordinate. + * @param llz Lower left near z coordinate. + * @param urx Upper right far x coordinate. + * @param ury Upper right far y coordinate. + * @param urz Upper right far z coordinate. + */ + void BBox(const char* string, float& llx, float& lly, float& llz, + float& urx, float& ury, float& urz) + { + FTBBox b = BBox(string); + llx = b.Lower().Xf(); lly = b.Lower().Yf(); llz = b.Lower().Zf(); + urx = b.Upper().Xf(); ury = b.Upper().Yf(); urz = b.Upper().Zf(); + } + + /** + * Get the bounding box for a string. + * + * @param string A wchar_t buffer. + * @param len The length of the string. If < 0 then all characters + * will be checked until a null character is encountered + * (optional). + * @param position The pen position of the first character (optional). + * @param spacing A displacement vector to add after each character + * has been checked (optional). + * @return The corresponding bounding box. + */ + virtual FTBBox BBox(const wchar_t *string, const int len = -1, + FTPoint position = FTPoint(), + FTPoint spacing = FTPoint()); + + /** + * Get the bounding box for a string (deprecated). + * + * @param string A wchar_t buffer. + * @param llx Lower left near x coordinate. + * @param lly Lower left near y coordinate. + * @param llz Lower left near z coordinate. + * @param urx Upper right far x coordinate. + * @param ury Upper right far y coordinate. + * @param urz Upper right far z coordinate. + */ + void BBox(const wchar_t* string, float& llx, float& lly, float& llz, + float& urx, float& ury, float& urz) + { + FTBBox b = BBox(string); + llx = b.Lower().Xf(); lly = b.Lower().Yf(); llz = b.Lower().Zf(); + urx = b.Upper().Xf(); ury = b.Upper().Yf(); urz = b.Upper().Zf(); + } + + /** + * Get the advance for a string. + * + * @param string 'C' style string to be checked. + * @param len The length of the string. If < 0 then all characters + * will be checked until a null character is encountered + * (optional). + * @param spacing A displacement vector to add after each character + * has been checked (optional). + * @return The string's advance width. + */ + virtual float Advance(const char* string, const int len = -1, + FTPoint spacing = FTPoint()); + + /** + * Get the advance for a string. + * + * @param string A wchar_t string + * @param len The length of the string. If < 0 then all characters + * will be checked until a null character is encountered + * (optional). + * @param spacing A displacement vector to add after each character + * has been checked (optional). + * @return The string's advance width. + */ + virtual float Advance(const wchar_t* string, const int len = -1, + FTPoint spacing = FTPoint()); + + /** + * Render a string of characters. + * + * @param string 'C' style string to be output. + * @param len The length of the string. If < 0 then all characters + * will be displayed until a null character is encountered + * (optional). + * @param position The pen position of the first character (optional). + * @param spacing A displacement vector to add after each character + * has been displayed (optional). + * @param renderMode Render mode to use for display (optional). + * @return The new pen position after the last character was output. + */ + virtual FTPoint Render(const char* string, const int len = -1, + FTPoint position = FTPoint(), + FTPoint spacing = FTPoint(), + int renderMode = FTGL::RENDER_ALL); + + /** + * Render a string of characters + * + * @param string wchar_t string to be output. + * @param len The length of the string. If < 0 then all characters + * will be displayed until a null character is encountered + * (optional). + * @param position The pen position of the first character (optional). + * @param spacing A displacement vector to add after each character + * has been displayed (optional). + * @param renderMode Render mode to use for display (optional). + * @return The new pen position after the last character was output. + */ + virtual FTPoint Render(const wchar_t *string, const int len = -1, + FTPoint position = FTPoint(), + FTPoint spacing = FTPoint(), + int renderMode = FTGL::RENDER_ALL); + + /** + * Queries the Font for errors. + * + * @return The current error code. + */ + virtual FT_Error Error() const; + + //TECGRAF + const char* GetFamilyName () const; + bool IsBold () const; + bool IsItalic () const; + protected: + /* Allow impl to access MakeGlyph */ + friend class FTFontImpl; + + /** + * Construct a glyph of the correct type. + * + * Clients must override the function and return their specialised + * FTGlyph. + * + * @param slot A FreeType glyph slot. + * @return An FT****Glyph or null on failure. + */ + virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot) = 0; + + private: + /** + * Internal FTGL FTFont implementation object. For private use only. + */ + FTFontImpl *impl; +}; + +#endif //__cplusplus + +FTGL_BEGIN_C_DECLS + +/** + * FTGLfont is the public interface for the FTGL library. + * + * It is good practice after using these functions to test the error + * code returned. FT_Error Error(). Check the freetype file + * fterrdef.h for error definitions. + */ +struct _FTGLFont; +typedef struct _FTGLfont FTGLfont; + +/** + * Create a custom FTGL font object. + * + * @param fontFilePath The font file name. + * @param data A pointer to private data that will be passed to callbacks. + * @param makeglyphCallback A glyph-making callback function. + * @return An FTGLfont* object. + */ +FTGL_EXPORT FTGLfont *ftglCreateCustomFont(char const *fontFilePath, + void *data, + FTGLglyph * (*makeglyphCallback) (FT_GlyphSlot, void *)); + +/** + * Destroy an FTGL font object. + * + * @param font An FTGLfont* object. + */ +FTGL_EXPORT void ftglDestroyFont(FTGLfont* font); + +/** + * Attach auxilliary file to font e.g. font metrics. + * + * Note: not all font formats implement this function. + * + * @param font An FTGLfont* object. + * @param path Auxilliary font file path. + * @return 1 if file has been attached successfully. + */ +FTGL_EXPORT int ftglAttachFile(FTGLfont* font, const char* path); + +/** + * Attach auxilliary data to font, e.g. font metrics, from memory. + * + * Note: not all font formats implement this function. + * + * @param font An FTGLfont* object. + * @param data The in-memory buffer. + * @param size The length of the buffer in bytes. + * @return 1 if file has been attached successfully. + */ +FTGL_EXPORT int ftglAttachData(FTGLfont* font, const unsigned char * data, + size_t size); + +/** + * Set the character map for the face. + * + * @param font An FTGLfont* object. + * @param encoding Freetype enumerate for char map code. + * @return 1 if charmap was valid and set correctly. + */ +FTGL_EXPORT int ftglSetFontCharMap(FTGLfont* font, FT_Encoding encoding); + +/** + * Get the number of character maps in this face. + * + * @param font An FTGLfont* object. + * @return character map count. + */ +FTGL_EXPORT unsigned int ftglGetFontCharMapCount(FTGLfont* font); + +/** + * Get a list of character maps in this face. + * + * @param font An FTGLfont* object. + * @return pointer to the first encoding. + */ +FTGL_EXPORT FT_Encoding* ftglGetFontCharMapList(FTGLfont* font); + +/** + * Set the char size for the current face. + * + * @param font An FTGLfont* object. + * @param size The face size in points (1/72 inch). + * @param res The resolution of the target device, or 0 to use the default + * value of 72. + * @return 1 if size was set correctly. + */ +FTGL_EXPORT int ftglSetFontFaceSize(FTGLfont* font, unsigned int size, + unsigned int res); + +/** + * Get the current face size in points (1/72 inch). + * + * @param font An FTGLfont* object. + * @return face size + */ +FTGL_EXPORT unsigned int ftglGetFontFaceSize(FTGLfont* font); + +/** + * Set the extrusion distance for the font. Only implemented by + * FTExtrudeFont. + * + * @param font An FTGLfont* object. + * @param depth The extrusion distance. + */ +FTGL_EXPORT void ftglSetFontDepth(FTGLfont* font, float depth); + +/** + * Set the outset distance for the font. Only FTOutlineFont, FTPolygonFont + * and FTExtrudeFont implement front outset. Only FTExtrudeFont implements + * back outset. + * + * @param font An FTGLfont* object. + * @param front The front outset distance. + * @param back The back outset distance. + */ +FTGL_EXPORT void ftglSetFontOutset(FTGLfont* font, float front, float back); + +/** + * Enable or disable the use of Display Lists inside FTGL. + * + * @param font An FTGLfont* object. + * @param useList 1 turns ON display lists. + * 0 turns OFF display lists. + */ +FTGL_EXPORT void ftglSetFontDisplayList(FTGLfont* font, int useList); + +/** + * Get the global ascender height for the face. + * + * @param font An FTGLfont* object. + * @return Ascender height + */ +FTGL_EXPORT float ftglGetFontAscender(FTGLfont* font); + +/** + * Gets the global descender height for the face. + * + * @param font An FTGLfont* object. + * @return Descender height + */ +FTGL_EXPORT float ftglGetFontDescender(FTGLfont* font); + +/** + * Gets the line spacing for the font. + * + * @param font An FTGLfont* object. + * @return Line height + */ +FTGL_EXPORT float ftglGetFontLineHeight(FTGLfont* font); + +/** TECGRAF +* Gets the maximum character width for the font. +* +* @param font An FTGLfont* object. +* @return Maximum width +*/ +FTGL_EXPORT float ftglGetFontMaxWidth(FTGLfont* font); + +/** + * Get the bounding box for a string. + * + * @param font An FTGLfont* object. + * @param string A char buffer + * @param len The length of the string. If < 0 then all characters will be + * checked until a null character is encountered (optional). + * @param bounds An array of 6 float values where the bounding box's lower + * left near and upper right far 3D coordinates will be stored. + */ +FTGL_EXPORT void ftglGetFontBBox(FTGLfont* font, const char *string, + int len, float bounds[6]); + +/** + * Get the advance width for a string. + * + * @param font An FTGLfont* object. + * @param string A char string. + * @return Advance width + */ +FTGL_EXPORT float ftglGetFontAdvance(FTGLfont* font, const char *string); + +/** + * Render a string of characters. + * + * @param font An FTGLfont* object. + * @param string Char string to be output. + * @param mode Render mode to display. + */ +FTGL_EXPORT void ftglRenderFont(FTGLfont* font, const char *string, int mode); + +/** + * Query a font for errors. + * + * @param font An FTGLfont* object. + * @return The current error code. + */ +FTGL_EXPORT FT_Error ftglGetFontError(FTGLfont* font); + +//TECGRAF +FTGL_EXPORT void ftglSetNearestFilter(FTGLfont* font, int useNearest); + + +FTGL_END_C_DECLS + +#endif // __FTFont__ + diff --git a/src/FTGlyph/FTTextureGlyph.cpp b/src/FTGlyph/FTTextureGlyph.cpp old mode 100644 new mode 100755 index a9cf2e8..3f9280c --- a/src/FTGlyph/FTTextureGlyph.cpp +++ b/src/FTGlyph/FTTextureGlyph.cpp @@ -129,6 +129,18 @@ const FTPoint& FTTextureGlyphImpl::RenderImpl(const FTPoint& pen, { glBindTexture(GL_TEXTURE_2D, (GLuint)glTextureID); activeTextureID = glTextureID; + + //TECGRAF + if (renderMode <= FTGL::RENDER_ALL) // default + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + } + else + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + } } dx = floor(pen.Xf() + corner.Xf()); diff --git a/src/FTSize.cpp b/src/FTSize.cpp old mode 100644 new mode 100755 index 49f1596..7a088ea --- a/src/FTSize.cpp +++ b/src/FTSize.cpp @@ -46,7 +46,10 @@ bool FTSize::CharSize(FT_Face* face, unsigned int pointSize, unsigned int xRes, { if(size != pointSize || xResolution != xRes || yResolution != yRes) { - err = FT_Set_Char_Size(*face, 0L, pointSize * 64, xResolution, yResolution); + //TECGRAF + // fixed resolution parameter, was xResolution, yResolution + // note: char_height is 1/64th of points + err = FT_Set_Char_Size(*face, 0L, pointSize * 64, xRes, yRes); if(!err) { @@ -87,11 +90,14 @@ float FTSize::Height() const return 0.0f; } - if(FT_IS_SCALABLE((*ftFace))) - { - return ((*ftFace)->bbox.yMax - (*ftFace)->bbox.yMin) * ((float)ftSize->metrics.y_ppem / (float)(*ftFace)->units_per_EM); - } - else + //TECGRAF + // Commented to ensure compatibility with FreeType usage, + // and better results for regular size computation. + //if(FT_IS_SCALABLE((*ftFace))) + //{ + // return ((*ftFace)->bbox.yMax - (*ftFace)->bbox.yMin) * ((float)ftSize->metrics.y_ppem / (float)(*ftFace)->units_per_EM); + //} + //else { return static_cast(ftSize->metrics.height) / 64.0f; } @@ -105,11 +111,14 @@ float FTSize::Width() const return 0.0f; } - if(FT_IS_SCALABLE((*ftFace))) - { - return ((*ftFace)->bbox.xMax - (*ftFace)->bbox.xMin) * (static_cast(ftSize->metrics.x_ppem) / static_cast((*ftFace)->units_per_EM)); - } - else + //TECGRAF + // Commented to ensure compatibility with FreeType usage, + // and better results for regular size computation. + //if(FT_IS_SCALABLE((*ftFace))) + //{ + // return ((*ftFace)->bbox.xMax - (*ftFace)->bbox.xMin) * (static_cast(ftSize->metrics.x_ppem) / static_cast((*ftFace)->units_per_EM)); + //} + //else { return static_cast(ftSize->metrics.max_advance) / 64.0f; } diff --git a/src/FTVectoriser.cpp b/src/FTVectoriser.cpp old mode 100644 new mode 100755 index ea5c571..3ac0840 --- a/src/FTVectoriser.cpp +++ b/src/FTVectoriser.cpp @@ -36,7 +36,7 @@ #if defined __APPLE_CC__ && __APPLE_CC__ < 5465 typedef GLvoid (*GLUTesselatorFunction) (...); -#elif defined WIN32 && !defined __CYGWIN__ +#elif (defined WIN32 && !defined __CYGWIN__) || (defined __CYGWIN__ && defined USE_OPENGL32) typedef GLvoid (CALLBACK *GLUTesselatorFunction) (); #else typedef GLvoid (*GLUTesselatorFunction) ();