// Created on: 2013-01-29
// Created by: Kirill GAVRILOV
-// Copyright (c) 2013 OPEN CASCADE SAS
+// Copyright (c) 2013-2014 OPEN CASCADE SAS
//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
#ifndef _OpenGl_Font_H__
#define _OpenGl_Font_H__
#include <OpenGl_Texture.hxx>
#include <OpenGl_Vec.hxx>
-#include <Font_FTFont.hxx>
+#include <Font_Rect.hxx>
#include <NCollection_DataMap.hxx>
#include <NCollection_Vector.hxx>
#include <TCollection_AsciiString.hxx>
+class Font_FTFont;
+
//! Texture font.
class OpenGl_Font : public OpenGl_Resource
{
//! Simple structure stores tile rectangle.
struct Tile
{
- Font_FTFont::Rect uv; //!< UV coordinates in texture
- Font_FTFont::Rect px; //!< pixel displacement coordinates
- GLuint texture; //!< GL texture ID
+ Font_Rect uv; //!< UV coordinates in texture
+ Font_Rect px; //!< pixel displacement coordinates
+ GLuint texture; //!< GL texture ID
};
struct RectI
Standard_EXPORT virtual ~OpenGl_Font();
//! Destroy object - will release GPU memory if any
- Standard_EXPORT virtual void Release (const OpenGl_Context* theCtx);
+ Standard_EXPORT virtual void Release (OpenGl_Context* theCtx) Standard_OVERRIDE;
+
+ //! Returns estimated GPU memory usage.
+ Standard_EXPORT virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE;
//! @return key of shared resource
inline const TCollection_AsciiString& ResourceKey() const
//! FreeType font instance should be already initialized!
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theCtx);
- //! Compute advance to the next character with kerning applied when applicable.
- //! Assuming text rendered horizontally.
- inline float AdvanceX (const Standard_Utf32Char theUChar,
- const Standard_Utf32Char theUCharNext)
- {
- return myFont->AdvanceX (theUChar, theUCharNext);
- }
-
//! @return vertical distance from the horizontal baseline to the highest character coordinate
inline float Ascender() const
{
return myDescender;
}
- //! @return default line spacing (the baseline-to-baseline distance)
- inline float LineSpacing() const
- {
- return myLineSpacing;
- }
-
- //! Compute glyph rectangle at specified pen position (on baseline)
- //! and render it to texture if not already.
+ //! Render glyph to texture if not already.
//! @param theCtx active context
//! @param theUChar unicode symbol to render
- //! @param theUCharNext next symbol to compute advance with kerning when available
//! @param theGlyph computed glyph position rectangle, texture ID and UV coordinates
- //! @param thePen pen position on baseline to place new glyph
- Standard_EXPORT void RenderGlyph (const Handle(OpenGl_Context)& theCtx,
+ Standard_EXPORT bool RenderGlyph (const Handle(OpenGl_Context)& theCtx,
const Standard_Utf32Char theUChar,
- const Standard_Utf32Char theUCharNext,
- Tile& theGlyph,
- OpenGl_Vec2& thePen);
+ Tile& theGlyph);
protected:
Handle(Font_FTFont) myFont; //!< FreeType font instance
Standard_ShortReal myAscender; //!< ascender provided my FT font
Standard_ShortReal myDescender; //!< descender provided my FT font
- Standard_ShortReal myLineSpacing; //!< line spacing provided my FT font
- Standard_Integer myTileSizeX; //!< tile width
Standard_Integer myTileSizeY; //!< tile height
Standard_Integer myLastTileId; //!< id of last tile
RectI myLastTilePx;
public:
- DEFINE_STANDARD_RTTI(OpenGl_Font) // Type definition
+ DEFINE_STANDARD_RTTIEXT(OpenGl_Font,OpenGl_Resource) // Type definition
};