File indexing completed on 2025-01-18 10:03:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _Font_SystemFont_HeaderFile
0017 #define _Font_SystemFont_HeaderFile
0018
0019 #include <Font_FontAspect.hxx>
0020 #include <Standard.hxx>
0021 #include <NCollection_DefineAlloc.hxx>
0022 #include <Standard_Transient.hxx>
0023 #include <TCollection_AsciiString.hxx>
0024
0025
0026 class Font_SystemFont : public Standard_Transient
0027 {
0028 DEFINE_STANDARD_RTTIEXT(Font_SystemFont, Standard_Transient)
0029 public:
0030
0031
0032 Standard_EXPORT Font_SystemFont (const TCollection_AsciiString& theFontName);
0033
0034
0035 const TCollection_AsciiString& FontKey() const { return myFontKey; }
0036
0037
0038 const TCollection_AsciiString& FontName() const { return myFontName; }
0039
0040
0041 const TCollection_AsciiString& FontPath (Font_FontAspect theAspect) const
0042 {
0043 return myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular];
0044 }
0045
0046
0047 Standard_Integer FontFaceId (Font_FontAspect theAspect) const
0048 {
0049 return myFaceIds[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular];
0050 }
0051
0052
0053 Standard_EXPORT void SetFontPath (Font_FontAspect theAspect,
0054 const TCollection_AsciiString& thePath,
0055 const Standard_Integer theFaceId = 0);
0056
0057
0058 bool HasFontAspect (Font_FontAspect theAspect) const
0059 {
0060 return !myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular].IsEmpty();
0061 }
0062
0063
0064 const TCollection_AsciiString& FontPathAny (Font_FontAspect theAspect,
0065 bool& theToSynthesizeItalic,
0066 Standard_Integer& theFaceId) const
0067 {
0068 const Font_FontAspect anAspect = theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular;
0069 const TCollection_AsciiString& aPath = myFilePaths[anAspect];
0070 theFaceId = myFaceIds[anAspect];
0071 if (!aPath.IsEmpty())
0072 {
0073 return aPath;
0074 }
0075
0076 if (theAspect == Font_FontAspect_Italic
0077 || theAspect == Font_FontAspect_BoldItalic)
0078 {
0079 if (theAspect == Font_FontAspect_BoldItalic
0080 && !myFilePaths[Font_FontAspect_Bold].IsEmpty())
0081 {
0082 theToSynthesizeItalic = true;
0083 theFaceId = myFaceIds[Font_FontAspect_Bold];
0084 return myFilePaths[Font_FontAspect_Bold];
0085 }
0086 else if (!myFilePaths[Font_FontAspect_Regular].IsEmpty())
0087 {
0088 theToSynthesizeItalic = true;
0089 theFaceId = myFaceIds[Font_FontAspect_Regular];
0090 return myFilePaths[Font_FontAspect_Regular];
0091 }
0092 }
0093
0094 if (!myFilePaths[Font_FontAspect_Regular].IsEmpty())
0095 {
0096 theFaceId = myFaceIds[Font_FontAspect_Regular];
0097 return myFilePaths[Font_FontAspect_Regular];
0098 }
0099
0100 for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
0101 {
0102 if (!myFilePaths[anAspectIter].IsEmpty())
0103 {
0104 theFaceId = myFaceIds[anAspectIter];
0105 return myFilePaths[anAspectIter];
0106 }
0107 }
0108 theFaceId = myFaceIds[Font_FontAspect_Regular];
0109 return myFilePaths[Font_FontAspect_Regular];
0110 }
0111
0112
0113 Standard_EXPORT Standard_Boolean IsEqual (const Handle(Font_SystemFont)& theOtherFont) const;
0114
0115
0116
0117 Standard_Boolean IsSingleStrokeFont() const { return myIsSingleLine; }
0118
0119
0120 void SetSingleStrokeFont (Standard_Boolean theIsSingleLine) { myIsSingleLine = theIsSingleLine; }
0121
0122
0123 Standard_EXPORT TCollection_AsciiString ToString() const;
0124
0125 public:
0126
0127 bool operator==(const Font_SystemFont& theFont) const
0128 {
0129 return myFontKey.IsEqual(theFont.FontKey());
0130 }
0131
0132 private:
0133
0134 TCollection_AsciiString myFilePaths[Font_FontAspect_NB];
0135 Standard_Integer myFaceIds [Font_FontAspect_NB];
0136 TCollection_AsciiString myFontKey;
0137 TCollection_AsciiString myFontName;
0138 Standard_Boolean myIsSingleLine;
0139
0140 };
0141
0142 namespace std
0143 {
0144 template<>
0145 struct hash<Handle(Font_SystemFont)>
0146 {
0147 size_t operator()(const Handle (Font_SystemFont)& theLink) const noexcept
0148 {
0149 if (theLink.IsNull()) return 0;
0150 return std::hash<TCollection_AsciiString>{}(theLink->FontKey());
0151 }
0152 };
0153 };
0154
0155 DEFINE_STANDARD_HANDLE(Font_SystemFont, Standard_Transient)
0156
0157 #endif