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_FTFont_HeaderFile
0017 #define Font_FTFont_HeaderFile
0018
0019 #include <Font_FontAspect.hxx>
0020 #include <Font_Hinting.hxx>
0021 #include <Font_Rect.hxx>
0022 #include <Font_StrictLevel.hxx>
0023 #include <Font_UnicodeSubset.hxx>
0024 #include <Graphic3d_HorizontalTextAlignment.hxx>
0025 #include <Graphic3d_VerticalTextAlignment.hxx>
0026 #include <Image_PixMap.hxx>
0027 #include <NCollection_String.hxx>
0028 #include <TCollection_AsciiString.hxx>
0029
0030
0031 typedef struct FT_FaceRec_* FT_Face;
0032 typedef struct FT_Vector_ FT_Vector;
0033 typedef struct FT_Outline_ FT_Outline;
0034 class Font_FTLibrary;
0035
0036
0037 struct Font_FTFontParams
0038 {
0039 unsigned int PointSize;
0040 unsigned int Resolution;
0041 Font_Hinting FontHinting;
0042
0043
0044 bool ToSynthesizeItalic;
0045 bool IsSingleStrokeFont;
0046
0047
0048 Font_FTFontParams()
0049 : PointSize (0), Resolution (72u),
0050 FontHinting (Font_Hinting_Off),
0051 ToSynthesizeItalic (false),
0052 IsSingleStrokeFont (false) {}
0053
0054
0055 Font_FTFontParams (unsigned int thePointSize,
0056 unsigned int theResolution)
0057 : PointSize (thePointSize), Resolution (theResolution),
0058 FontHinting (Font_Hinting_Off),
0059 ToSynthesizeItalic (false),
0060 IsSingleStrokeFont (false) {}
0061 };
0062
0063 DEFINE_STANDARD_HANDLE(Font_FTFont, Standard_Transient)
0064
0065
0066
0067
0068 class Font_FTFont : public Standard_Transient
0069 {
0070 DEFINE_STANDARD_RTTIEXT(Font_FTFont, Standard_Transient)
0071 public:
0072
0073
0074
0075
0076
0077
0078
0079 Standard_EXPORT static Handle(Font_FTFont) FindAndCreate (const TCollection_AsciiString& theFontName,
0080 const Font_FontAspect theFontAspect,
0081 const Font_FTFontParams& theParams,
0082 const Font_StrictLevel theStrictLevel = Font_StrictLevel_Any);
0083
0084
0085 static bool IsCharFromCJK (Standard_Utf32Char theUChar)
0086 {
0087 return (theUChar >= 0x03400 && theUChar <= 0x04DFF)
0088 || (theUChar >= 0x04E00 && theUChar <= 0x09FFF)
0089 || (theUChar >= 0x0F900 && theUChar <= 0x0FAFF)
0090 || (theUChar >= 0x20000 && theUChar <= 0x2A6DF)
0091 || (theUChar >= 0x2F800 && theUChar <= 0x2FA1F)
0092
0093 || IsCharFromHiragana (theUChar)
0094 || IsCharFromKatakana (theUChar);
0095 }
0096
0097
0098 static bool IsCharFromHiragana (Standard_Utf32Char theUChar)
0099 {
0100 return (theUChar >= 0x03040 && theUChar <= 0x0309F);
0101 }
0102
0103
0104 static bool IsCharFromKatakana (Standard_Utf32Char theUChar)
0105 {
0106 return (theUChar >= 0x030A0 && theUChar <= 0x030FF);
0107 }
0108
0109
0110 static bool IsCharFromKorean (Standard_Utf32Char theUChar)
0111 {
0112 return (theUChar >= 0x01100 && theUChar <= 0x011FF)
0113 || (theUChar >= 0x03130 && theUChar <= 0x0318F)
0114 || (theUChar >= 0x0AC00 && theUChar <= 0x0D7A3);
0115 }
0116
0117
0118 static bool IsCharFromArabic (Standard_Utf32Char theUChar)
0119 {
0120 return (theUChar >= 0x00600 && theUChar <= 0x006FF);
0121 }
0122
0123
0124 static bool IsCharRightToLeft (Standard_Utf32Char theUChar)
0125 {
0126 return IsCharFromArabic(theUChar);
0127 }
0128
0129
0130 static Font_UnicodeSubset CharSubset (Standard_Utf32Char theUChar)
0131 {
0132 if (IsCharFromCJK (theUChar))
0133 {
0134 return Font_UnicodeSubset_CJK;
0135 }
0136 else if (IsCharFromKorean (theUChar))
0137 {
0138 return Font_UnicodeSubset_Korean;
0139 }
0140 else if (IsCharFromArabic (theUChar))
0141 {
0142 return Font_UnicodeSubset_Arabic;
0143 }
0144 return Font_UnicodeSubset_Western;
0145 }
0146
0147 public:
0148
0149
0150 Standard_EXPORT Font_FTFont (const Handle(Font_FTLibrary)& theFTLib = Handle(Font_FTLibrary)());
0151
0152
0153 Standard_EXPORT virtual ~Font_FTFont();
0154
0155
0156 inline bool IsValid() const
0157 {
0158 return myFTFace != NULL;
0159 }
0160
0161
0162 inline const Image_PixMap& GlyphImage() const
0163 {
0164 return myGlyphImg;
0165 }
0166
0167
0168
0169
0170
0171
0172 bool Init (const TCollection_AsciiString& theFontPath,
0173 const Font_FTFontParams& theParams,
0174 const Standard_Integer theFaceId = 0)
0175 {
0176 return Init (Handle(NCollection_Buffer)(), theFontPath, theParams, theFaceId);
0177 }
0178
0179
0180
0181
0182
0183
0184
0185
0186 Standard_EXPORT bool Init (const Handle(NCollection_Buffer)& theData,
0187 const TCollection_AsciiString& theFileName,
0188 const Font_FTFontParams& theParams,
0189 const Standard_Integer theFaceId = 0);
0190
0191
0192
0193
0194
0195
0196
0197 Standard_EXPORT bool FindAndInit (const TCollection_AsciiString& theFontName,
0198 Font_FontAspect theFontAspect,
0199 const Font_FTFontParams& theParams,
0200 Font_StrictLevel theStrictLevel = Font_StrictLevel_Any);
0201
0202
0203
0204 Standard_Boolean ToUseUnicodeSubsetFallback() const { return myToUseUnicodeSubsetFallback; }
0205
0206
0207 void SetUseUnicodeSubsetFallback (Standard_Boolean theToFallback) { myToUseUnicodeSubsetFallback = theToFallback; }
0208
0209
0210
0211 bool IsSingleStrokeFont() const { return myFontParams.IsSingleStrokeFont; }
0212
0213
0214 void SetSingleStrokeFont (bool theIsSingleLine) { myFontParams.IsSingleStrokeFont = theIsSingleLine; }
0215
0216
0217 bool ToSynthesizeItalic() const { return myFontParams.ToSynthesizeItalic; }
0218
0219
0220 Standard_EXPORT virtual void Release();
0221
0222
0223 Standard_EXPORT bool RenderGlyph (const Standard_Utf32Char theChar);
0224
0225
0226 Standard_EXPORT unsigned int GlyphMaxSizeX (bool theToIncludeFallback = false) const;
0227
0228
0229 Standard_EXPORT unsigned int GlyphMaxSizeY (bool theToIncludeFallback = false) const;
0230
0231
0232 Standard_EXPORT float Ascender() const;
0233
0234
0235 Standard_EXPORT float Descender() const;
0236
0237
0238 Standard_EXPORT float LineSpacing() const;
0239
0240
0241 unsigned int PointSize() const
0242 {
0243 return myFontParams.PointSize;
0244 }
0245
0246
0247 float WidthScaling() const
0248 {
0249 return myWidthScaling;
0250 }
0251
0252
0253
0254 void SetWidthScaling (const float theScaleFactor)
0255 {
0256 myWidthScaling = theScaleFactor;
0257 }
0258
0259
0260 Standard_EXPORT bool HasSymbol (Standard_Utf32Char theUChar) const;
0261
0262
0263
0264
0265 Standard_EXPORT float AdvanceX (Standard_Utf32Char theUCharNext) const;
0266
0267
0268
0269
0270
0271 Standard_EXPORT float AdvanceX (Standard_Utf32Char theUChar,
0272 Standard_Utf32Char theUCharNext);
0273
0274
0275
0276
0277 Standard_EXPORT float AdvanceY (Standard_Utf32Char theUCharNext) const;
0278
0279
0280
0281
0282
0283 Standard_EXPORT float AdvanceY (Standard_Utf32Char theUChar,
0284 Standard_Utf32Char theUCharNext);
0285
0286
0287
0288 Standard_EXPORT Standard_Integer GlyphsNumber (bool theToIncludeFallback = false) const;
0289
0290
0291 Standard_EXPORT void GlyphRect (Font_Rect& theRect) const;
0292
0293
0294
0295
0296 Standard_EXPORT Font_Rect BoundingBox (const NCollection_String& theString,
0297 const Graphic3d_HorizontalTextAlignment theAlignX,
0298 const Graphic3d_VerticalTextAlignment theAlignY);
0299
0300 public:
0301
0302
0303
0304
0305
0306 Standard_EXPORT const FT_Outline* renderGlyphOutline(const Standard_Utf32Char theChar);
0307
0308 public:
0309
0310
0311
0312
0313
0314
0315 Standard_DEPRECATED ("Deprecated method, Font_FTFontParams should be used for passing parameters")
0316 bool Init (const NCollection_String& theFontPath,
0317 unsigned int thePointSize,
0318 unsigned int theResolution)
0319 {
0320 Font_FTFontParams aParams;
0321 aParams.PointSize = thePointSize;
0322 aParams.Resolution = theResolution;
0323 return Init (theFontPath.ToCString(), aParams, 0);
0324 }
0325
0326
0327
0328
0329
0330
0331
0332 Standard_DEPRECATED ("Deprecated method, Font_FTFontParams should be used for passing parameters")
0333 bool Init (const NCollection_String& theFontName,
0334 Font_FontAspect theFontAspect,
0335 unsigned int thePointSize,
0336 unsigned int theResolution)
0337 {
0338 Font_FTFontParams aParams;
0339 aParams.PointSize = thePointSize;
0340 aParams.Resolution = theResolution;
0341 return FindAndInit (theFontName.ToCString(), theFontAspect, aParams);
0342 }
0343
0344 protected:
0345
0346
0347 template <typename theInput_t>
0348 int32_t toFTPoints (const theInput_t thePointSize) const
0349 {
0350 return (int32_t)thePointSize * 64;
0351 }
0352
0353
0354 template <typename theReturn_t, typename theFTUnits_t>
0355 inline theReturn_t fromFTPoints (const theFTUnits_t theFTUnits) const
0356 {
0357 return (theReturn_t)theFTUnits / 64.0f;
0358 }
0359
0360 protected:
0361
0362
0363 Standard_EXPORT bool loadGlyph (const Standard_Utf32Char theUChar);
0364
0365
0366 Standard_EXPORT bool getKerning (FT_Vector& theKern,
0367 Standard_Utf32Char theUCharCurr,
0368 Standard_Utf32Char theUCharNext) const;
0369
0370
0371 Standard_EXPORT bool findAndInitFallback (Font_UnicodeSubset theSubset);
0372
0373
0374 void setLoadFlag (int32_t theFlag, bool theToEnable)
0375 {
0376 if (theToEnable)
0377 {
0378 myLoadFlags |= theFlag;
0379 }
0380 else
0381 {
0382 myLoadFlags &= ~theFlag;
0383 }
0384 }
0385
0386 protected:
0387
0388 Handle(Font_FTLibrary) myFTLib;
0389 Handle(NCollection_Buffer) myBuffer;
0390 Handle(Font_FTFont) myFallbackFaces[Font_UnicodeSubset_NB];
0391 FT_Face myFTFace;
0392 FT_Face myActiveFTFace;
0393 TCollection_AsciiString myFontPath;
0394 Font_FTFontParams myFontParams;
0395 Font_FontAspect myFontAspect;
0396 float myWidthScaling;
0397 int32_t myLoadFlags;
0398
0399 Image_PixMap myGlyphImg;
0400 Standard_Utf32Char myUChar;
0401 Standard_Boolean myToUseUnicodeSubsetFallback;
0402
0403 };
0404
0405 #endif