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 //! Returns font file path.
47 Standard_Integer FontFaceId (Font_FontAspect theAspect) const
49 return myFaceIds[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular];
52 //! Sets font file path for specific aspect.
53 Standard_EXPORT void SetFontPath (Font_FontAspect theAspect,
54 const TCollection_AsciiString& thePath,
55 const Standard_Integer theFaceId = 0);
57 //! Returns TRUE if dedicated file for specified font aspect has been defined.
58 bool HasFontAspect (Font_FontAspect theAspect) const
60 return !myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular].IsEmpty();
63 //! Returns any defined font file path.
64 const TCollection_AsciiString& FontPathAny (Font_FontAspect theAspect,
65 bool& theToSynthesizeItalic,
66 Standard_Integer& theFaceId) const
68 const Font_FontAspect anAspect = theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular;
69 const TCollection_AsciiString& aPath = myFilePaths[anAspect];
70 theFaceId = myFaceIds[anAspect];
76 if (theAspect == Font_FontAspect_Italic
77 || theAspect == Font_FontAspect_BoldItalic)
79 if (theAspect == Font_FontAspect_BoldItalic
80 && !myFilePaths[Font_FontAspect_Bold].IsEmpty())
82 theToSynthesizeItalic = true;
83 theFaceId = myFaceIds[Font_FontAspect_Bold];
84 return myFilePaths[Font_FontAspect_Bold];
86 else if (!myFilePaths[Font_FontAspect_Regular].IsEmpty())
88 theToSynthesizeItalic = true;
89 theFaceId = myFaceIds[Font_FontAspect_Regular];
90 return myFilePaths[Font_FontAspect_Regular];
94 if (!myFilePaths[Font_FontAspect_Regular].IsEmpty())
96 theFaceId = myFaceIds[Font_FontAspect_Regular];
97 return myFilePaths[Font_FontAspect_Regular];
100 for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
102 if (!myFilePaths[anAspectIter].IsEmpty())
104 theFaceId = myFaceIds[anAspectIter];
105 return myFilePaths[anAspectIter];
108 theFaceId = myFaceIds[Font_FontAspect_Regular];
109 return myFilePaths[Font_FontAspect_Regular];
112 //! Return true if the FontName, FontAspect and FontSize are the same.
113 Standard_EXPORT Standard_Boolean IsEqual (const Handle(Font_SystemFont)& theOtherFont) const;
115 //! Return TRUE if this is single-stroke (one-line) font, FALSE by default.
116 //! Such fonts define single-line glyphs instead of closed contours, so that they are rendered incorrectly by normal software.
117 Standard_Boolean IsSingleStrokeFont() const { return myIsSingleLine; }
119 //! Set if this font should be rendered as single-stroke (one-line).
120 void SetSingleStrokeFont (Standard_Boolean theIsSingleLine) { myIsSingleLine = theIsSingleLine; }
122 //! Format font description.
123 Standard_EXPORT TCollection_AsciiString ToString() const;
126 //! Computes a hash code for the system font, in the range [1, theUpperBound]. Based on Font Family, so that the whole
127 //! family with different aspects can be found within the same bucket of some map
128 //! @param theSystemFont the system font which hash code is to be computed
129 //! @param theUpperBound the upper bound of the range a computing hash code must be within
130 //! @return a computed hash code, in the range [1, theUpperBound]
131 static Standard_Integer HashCode (const Handle (Font_SystemFont) & theSystemFont, const Standard_Integer theUpperBound)
133 return ::HashCode (theSystemFont->FontKey(), theUpperBound);
136 //! Matching two instances, for Map interface.
137 static bool IsEqual (const Handle(Font_SystemFont)& theFont1,
138 const Handle(Font_SystemFont)& theFont2)
140 return theFont1->IsEqual (theFont2);
145 TCollection_AsciiString myFilePaths[Font_FontAspect_NB]; //!< paths to the font file
146 Standard_Integer myFaceIds [Font_FontAspect_NB]; //!< face ids per font file
147 TCollection_AsciiString myFontKey; //!< font family name, lower cased
148 TCollection_AsciiString myFontName; //!< font family name
149 Standard_Boolean myIsSingleLine; //!< single stroke font flag, FALSE by default
153 DEFINE_STANDARD_HANDLE(Font_SystemFont, Standard_Transient)
155 #endif // _Font_SystemFont_HeaderFile