0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / Font / Font_SystemFont.hxx
CommitLineData
42cf5bc1 1// Created on: 2008-01-20
2// Created by: Alexander A. BORODIN
3// Copyright (c) 2008-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
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.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#ifndef _Font_SystemFont_HeaderFile
17#define _Font_SystemFont_HeaderFile
18
5b377041 19#include <Font_FontAspect.hxx>
42cf5bc1 20#include <Standard.hxx>
1103eb60 21#include <NCollection_DefineAlloc.hxx>
25e59720 22#include <Standard_Transient.hxx>
5b377041 23#include <TCollection_AsciiString.hxx>
42cf5bc1 24
e4f0cc46 25//! This class stores information about the font, which is merely a file path and cached metadata about the font.
25e59720 26class Font_SystemFont : public Standard_Transient
42cf5bc1 27{
e4f0cc46 28 DEFINE_STANDARD_RTTIEXT(Font_SystemFont, Standard_Transient)
42cf5bc1 29public:
30
e4f0cc46 31 //! Creates a new font object.
5b377041 32 Standard_EXPORT Font_SystemFont (const TCollection_AsciiString& theFontName);
e4f0cc46 33
5b377041 34 //! Returns font family name (lower-cased).
35 const TCollection_AsciiString& FontKey() const { return myFontKey; }
e4f0cc46 36
37 //! Returns font family name.
5b377041 38 const TCollection_AsciiString& FontName() const { return myFontName; }
42cf5bc1 39
e4f0cc46 40 //! Returns font file path.
5b377041 41 const TCollection_AsciiString& FontPath (Font_FontAspect theAspect) const
42 {
43 return myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular];
44 }
45
9a90a452 46 //! Returns font file path.
47 Standard_Integer FontFaceId (Font_FontAspect theAspect) const
48 {
49 return myFaceIds[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular];
50 }
51
5b377041 52 //! Sets font file path for specific aspect.
53 Standard_EXPORT void SetFontPath (Font_FontAspect theAspect,
9a90a452 54 const TCollection_AsciiString& thePath,
55 const Standard_Integer theFaceId = 0);
5b377041 56
57 //! Returns TRUE if dedicated file for specified font aspect has been defined.
58 bool HasFontAspect (Font_FontAspect theAspect) const
59 {
60 return !myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular].IsEmpty();
61 }
62
63 //! Returns any defined font file path.
1bbd7c79 64 const TCollection_AsciiString& FontPathAny (Font_FontAspect theAspect,
9a90a452 65 bool& theToSynthesizeItalic,
66 Standard_Integer& theFaceId) const
5b377041 67 {
9a90a452 68 const Font_FontAspect anAspect = theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular;
69 const TCollection_AsciiString& aPath = myFilePaths[anAspect];
70 theFaceId = myFaceIds[anAspect];
5b377041 71 if (!aPath.IsEmpty())
72 {
73 return aPath;
74 }
1bbd7c79 75
76 if (theAspect == Font_FontAspect_Italic
77 || theAspect == Font_FontAspect_BoldItalic)
78 {
79 if (theAspect == Font_FontAspect_BoldItalic
80 && !myFilePaths[Font_FontAspect_Bold].IsEmpty())
81 {
82 theToSynthesizeItalic = true;
9a90a452 83 theFaceId = myFaceIds[Font_FontAspect_Bold];
1bbd7c79 84 return myFilePaths[Font_FontAspect_Bold];
85 }
86 else if (!myFilePaths[Font_FontAspect_Regular].IsEmpty())
87 {
88 theToSynthesizeItalic = true;
9a90a452 89 theFaceId = myFaceIds[Font_FontAspect_Regular];
1bbd7c79 90 return myFilePaths[Font_FontAspect_Regular];
91 }
92 }
93
94 if (!myFilePaths[Font_FontAspect_Regular].IsEmpty())
5b377041 95 {
9a90a452 96 theFaceId = myFaceIds[Font_FontAspect_Regular];
5b377041 97 return myFilePaths[Font_FontAspect_Regular];
98 }
1bbd7c79 99
5b377041 100 for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
101 {
102 if (!myFilePaths[anAspectIter].IsEmpty())
103 {
9a90a452 104 theFaceId = myFaceIds[anAspectIter];
5b377041 105 return myFilePaths[anAspectIter];
106 }
107 }
9a90a452 108 theFaceId = myFaceIds[Font_FontAspect_Regular];
5b377041 109 return myFilePaths[Font_FontAspect_Regular];
110 }
e4f0cc46 111
42cf5bc1 112 //! Return true if the FontName, FontAspect and FontSize are the same.
42cf5bc1 113 Standard_EXPORT Standard_Boolean IsEqual (const Handle(Font_SystemFont)& theOtherFont) const;
114
e4f0cc46 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; }
42cf5bc1 118
e4f0cc46 119 //! Set if this font should be rendered as single-stroke (one-line).
120 void SetSingleStrokeFont (Standard_Boolean theIsSingleLine) { myIsSingleLine = theIsSingleLine; }
42cf5bc1 121
5b377041 122 //! Format font description.
123 Standard_EXPORT TCollection_AsciiString ToString() const;
124
125public:
5b377041 126
1103eb60 127 bool operator==(const Font_SystemFont& theFont) const
5b377041 128 {
1103eb60 129 return myFontKey.IsEqual(theFont.FontKey());
5b377041 130 }
131
42cf5bc1 132private:
133
5b377041 134 TCollection_AsciiString myFilePaths[Font_FontAspect_NB]; //!< paths to the font file
9a90a452 135 Standard_Integer myFaceIds [Font_FontAspect_NB]; //!< face ids per font file
5b377041 136 TCollection_AsciiString myFontKey; //!< font family name, lower cased
137 TCollection_AsciiString myFontName; //!< font family name
138 Standard_Boolean myIsSingleLine; //!< single stroke font flag, FALSE by default
42cf5bc1 139
140};
141
1103eb60 142namespace std
143{
144 template<>
145 struct hash<Handle(Font_SystemFont)>
146 {
147 size_t operator()(const Handle (Font_SystemFont)& theLink) const noexcept
148 {
149 if (theLink.IsNull()) return 0;
150 return std::hash<TCollection_AsciiString>{}(theLink->FontKey());
151 }
152 };
153};
154
e4f0cc46 155DEFINE_STANDARD_HANDLE(Font_SystemFont, Standard_Transient)
42cf5bc1 156
157#endif // _Font_SystemFont_HeaderFile