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