1 // Created on: 2008-01-20
2 // Created by: Alexander A. BORODIN
3 // Copyright (c) 2008-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _Font_SystemFont_HeaderFile
17 #define _Font_SystemFont_HeaderFile
19 #include <Font_FontAspect.hxx>
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22 #include <Standard_Transient.hxx>
23 #include <TCollection_AsciiString.hxx>
25 //! This class stores information about the font, which is merely a file path and cached metadata about the font.
26 class Font_SystemFont : public Standard_Transient
28 DEFINE_STANDARD_RTTIEXT(Font_SystemFont, Standard_Transient)
31 //! Creates a new font object.
32 Standard_EXPORT Font_SystemFont (const TCollection_AsciiString& theFontName);
34 //! Returns font family name (lower-cased).
35 const TCollection_AsciiString& FontKey() const { return myFontKey; }
37 //! Returns font family name.
38 const TCollection_AsciiString& FontName() const { return myFontName; }
40 //! Returns font file path.
41 const TCollection_AsciiString& FontPath (Font_FontAspect theAspect) const
43 return myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular];
46 //! Sets font file path for specific aspect.
47 Standard_EXPORT void SetFontPath (Font_FontAspect theAspect,
48 const TCollection_AsciiString& thePath);
50 //! Returns TRUE if dedicated file for specified font aspect has been defined.
51 bool HasFontAspect (Font_FontAspect theAspect) const
53 return !myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular].IsEmpty();
56 //! Returns any defined font file path.
57 const TCollection_AsciiString& FontPathAny (Font_FontAspect theAspect) const
59 const TCollection_AsciiString& aPath = myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular];
64 else if (!myFilePaths[Font_FontAspect_Regular].IsEmpty())
66 return myFilePaths[Font_FontAspect_Regular];
68 for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
70 if (!myFilePaths[anAspectIter].IsEmpty())
72 return myFilePaths[anAspectIter];
75 return myFilePaths[Font_FontAspect_Regular];
78 //! Return true if the FontName, FontAspect and FontSize are the same.
79 Standard_EXPORT Standard_Boolean IsEqual (const Handle(Font_SystemFont)& theOtherFont) const;
81 //! Return TRUE if this is single-stroke (one-line) font, FALSE by default.
82 //! Such fonts define single-line glyphs instead of closed contours, so that they are rendered incorrectly by normal software.
83 Standard_Boolean IsSingleStrokeFont() const { return myIsSingleLine; }
85 //! Set if this font should be rendered as single-stroke (one-line).
86 void SetSingleStrokeFont (Standard_Boolean theIsSingleLine) { myIsSingleLine = theIsSingleLine; }
88 //! Format font description.
89 Standard_EXPORT TCollection_AsciiString ToString() const;
92 //! Computes a hash code for the system font, in the range [1, theUpperBound]. Based on Font Family, so that the whole
93 //! family with different aspects can be found within the same bucket of some map
94 //! @param theSystemFont the system font which hash code is to be computed
95 //! @param theUpperBound the upper bound of the range a computing hash code must be within
96 //! @return a computed hash code, in the range [1, theUpperBound]
97 static Standard_Integer HashCode (const Handle (Font_SystemFont) & theSystemFont, const Standard_Integer theUpperBound)
99 return ::HashCode (theSystemFont->FontKey(), theUpperBound);
102 //! Matching two instances, for Map interface.
103 static bool IsEqual (const Handle(Font_SystemFont)& theFont1,
104 const Handle(Font_SystemFont)& theFont2)
106 return theFont1->IsEqual (theFont2);
111 TCollection_AsciiString myFilePaths[Font_FontAspect_NB]; //!< paths to the font file
112 TCollection_AsciiString myFontKey; //!< font family name, lower cased
113 TCollection_AsciiString myFontName; //!< font family name
114 Standard_Boolean myIsSingleLine; //!< single stroke font flag, FALSE by default
118 DEFINE_STANDARD_HANDLE(Font_SystemFont, Standard_Transient)
120 #endif // _Font_SystemFont_HeaderFile