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_FontMgr_HeaderFile
0017 #define _Font_FontMgr_HeaderFile
0018
0019 #include <Standard.hxx>
0020 #include <Standard_Transient.hxx>
0021 #include <Font_NListOfSystemFont.hxx>
0022 #include <Font_StrictLevel.hxx>
0023 #include <Font_UnicodeSubset.hxx>
0024 #include <NCollection_DataMap.hxx>
0025 #include <NCollection_IndexedMap.hxx>
0026 #include <NCollection_Shared.hxx>
0027 #include <TColStd_SequenceOfHAsciiString.hxx>
0028
0029 class TCollection_HAsciiString;
0030 class NCollection_Buffer;
0031
0032 DEFINE_STANDARD_HANDLE(Font_FontMgr, Standard_Transient)
0033
0034
0035 class Font_FontMgr : public Standard_Transient
0036 {
0037 DEFINE_STANDARD_RTTIEXT(Font_FontMgr, Standard_Transient)
0038 public:
0039
0040
0041 Standard_EXPORT static Handle(Font_FontMgr) GetInstance();
0042
0043
0044 static const char* FontAspectToString (Font_FontAspect theAspect)
0045 {
0046 switch (theAspect)
0047 {
0048 case Font_FontAspect_UNDEFINED: return "undefined";
0049 case Font_FontAspect_Regular: return "regular";
0050 case Font_FontAspect_Bold: return "bold";
0051 case Font_FontAspect_Italic: return "italic";
0052 case Font_FontAspect_BoldItalic: return "bold-italic";
0053 }
0054 return "invalid";
0055 }
0056
0057
0058 Standard_EXPORT static Standard_Boolean& ToUseUnicodeSubsetFallback();
0059
0060 public:
0061
0062
0063 void AvailableFonts (Font_NListOfSystemFont& theList) const
0064 {
0065 for (Font_FontMap::Iterator aFontIter (myFontMap); aFontIter.More(); aFontIter.Next())
0066 {
0067 theList.Append (aFontIter.Value());
0068 }
0069 }
0070
0071
0072 Font_NListOfSystemFont GetAvailableFonts() const
0073 {
0074 Font_NListOfSystemFont aList;
0075 AvailableFonts (aList);
0076 return aList;
0077 }
0078
0079
0080 Standard_EXPORT void GetAvailableFontsNames (TColStd_SequenceOfHAsciiString& theFontsNames) const;
0081
0082
0083
0084
0085
0086 Standard_EXPORT Handle(Font_SystemFont) GetFont (const Handle(TCollection_HAsciiString)& theFontName, const Font_FontAspect theFontAspect, const Standard_Integer theFontSize) const;
0087
0088
0089
0090 Standard_EXPORT Handle(Font_SystemFont) GetFont (const TCollection_AsciiString& theFontName) const;
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102 Standard_EXPORT Handle(Font_SystemFont) FindFont (const TCollection_AsciiString& theFontName,
0103 Font_StrictLevel theStrictLevel,
0104 Font_FontAspect& theFontAspect,
0105 Standard_Boolean theDoFailMsg = Standard_True) const;
0106
0107
0108 Handle(Font_SystemFont) FindFont (const TCollection_AsciiString& theFontName,
0109 Font_FontAspect& theFontAspect) const
0110 {
0111 return FindFont (theFontName, Font_StrictLevel_Any, theFontAspect);
0112 }
0113
0114
0115
0116
0117
0118 Standard_EXPORT Handle(Font_SystemFont) FindFallbackFont (Font_UnicodeSubset theSubset,
0119 Font_FontAspect theFontAspect) const;
0120
0121
0122 Standard_EXPORT Standard_Boolean CheckFont (NCollection_Sequence<Handle(Font_SystemFont)>& theFonts,
0123 const TCollection_AsciiString& theFontPath) const;
0124
0125
0126 Standard_EXPORT Handle(Font_SystemFont) CheckFont (const Standard_CString theFontPath) const;
0127
0128
0129
0130
0131 Standard_EXPORT Standard_Boolean RegisterFont (const Handle(Font_SystemFont)& theFont,
0132 const Standard_Boolean theToOverride);
0133
0134
0135 Standard_Boolean RegisterFonts (const NCollection_Sequence<Handle(Font_SystemFont)>& theFonts,
0136 const Standard_Boolean theToOverride)
0137 {
0138 Standard_Boolean isRegistered = Standard_False;
0139 for (NCollection_Sequence<Handle(Font_SystemFont)>::Iterator aFontIter (theFonts); aFontIter.More(); aFontIter.Next())
0140 {
0141 isRegistered = RegisterFont (aFontIter.Value(), theToOverride) || isRegistered;
0142 }
0143 return isRegistered;
0144 }
0145
0146 public:
0147
0148
0149 Standard_Boolean ToTraceAliases() const { return myToTraceAliases; }
0150
0151
0152
0153 void SetTraceAliases (Standard_Boolean theToTrace) { myToTraceAliases = theToTrace; }
0154
0155
0156
0157 Standard_EXPORT void GetAllAliases (TColStd_SequenceOfHAsciiString& theAliases) const;
0158
0159
0160
0161
0162 Standard_EXPORT void GetFontAliases (TColStd_SequenceOfHAsciiString& theFontNames,
0163 const TCollection_AsciiString& theAliasName) const;
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179 Standard_EXPORT bool AddFontAlias (const TCollection_AsciiString& theAliasName,
0180 const TCollection_AsciiString& theFontName);
0181
0182
0183
0184
0185
0186
0187
0188 Standard_EXPORT bool RemoveFontAlias (const TCollection_AsciiString& theAliasName,
0189 const TCollection_AsciiString& theFontName);
0190
0191 public:
0192
0193
0194 Standard_EXPORT void InitFontDataBase();
0195
0196
0197 Standard_EXPORT void ClearFontDataBase();
0198
0199
0200
0201
0202
0203 Standard_EXPORT static Handle(NCollection_Buffer) EmbedFallbackFont();
0204
0205 private:
0206
0207
0208 Standard_EXPORT Font_FontMgr();
0209
0210 private:
0211
0212 struct FontHasher
0213 {
0214 size_t operator()(const Handle(Font_SystemFont)& theFont) const noexcept
0215 {
0216 return std::hash<TCollection_AsciiString>{}(theFont->FontKey());
0217 }
0218
0219 bool operator()(const Handle(Font_SystemFont)& theFont1,
0220 const Handle(Font_SystemFont)& theFont2) const
0221 {
0222 return theFont1->IsEqual(theFont2);
0223 }
0224 };
0225
0226
0227 class Font_FontMap : public NCollection_IndexedMap<Handle(Font_SystemFont), FontHasher>
0228 {
0229 public:
0230
0231 Font_FontMap() {}
0232
0233
0234
0235
0236 Handle(Font_SystemFont) Find (const TCollection_AsciiString& theFontName) const;
0237 };
0238
0239
0240 struct Font_FontAlias
0241 {
0242 TCollection_AsciiString FontName;
0243 Font_FontAspect FontAspect;
0244
0245 Font_FontAlias (const TCollection_AsciiString& theFontName, Font_FontAspect theFontAspect = Font_FontAspect_UNDEFINED) : FontName (theFontName), FontAspect (theFontAspect) {}
0246 Font_FontAlias() : FontAspect (Font_FontAspect_UNDEFINED) {}
0247 };
0248
0249
0250 typedef NCollection_Shared< NCollection_Sequence<Font_FontAlias> > Font_FontAliasSequence;
0251
0252
0253 void addFontAlias (const TCollection_AsciiString& theAliasName,
0254 const Handle(Font_FontAliasSequence)& theAliases,
0255 Font_FontAspect theAspect = Font_FontAspect_UNDEFINED);
0256
0257 private:
0258
0259 Font_FontMap myFontMap;
0260 NCollection_DataMap<TCollection_AsciiString, Handle(Font_FontAliasSequence)> myFontAliases;
0261 Handle(Font_FontAliasSequence) myFallbackAlias;
0262 Standard_Boolean myToTraceAliases;
0263
0264 };
0265
0266 #endif