Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-04 08:32:04

0001 // Created on: 2008-01-20
0002 // Created by: Alexander A. BORODIN
0003 // Copyright (c) 2008-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
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 //! This class stores information about the font, which is merely a file path and cached metadata
0026 //! about the font.
0027 class Font_SystemFont : public Standard_Transient
0028 {
0029   DEFINE_STANDARD_RTTIEXT(Font_SystemFont, Standard_Transient)
0030 public:
0031   //! Creates a new font object.
0032   Standard_EXPORT Font_SystemFont(const TCollection_AsciiString& theFontName);
0033 
0034   //! Returns font family name (lower-cased).
0035   const TCollection_AsciiString& FontKey() const { return myFontKey; }
0036 
0037   //! Returns font family name.
0038   const TCollection_AsciiString& FontName() const { return myFontName; }
0039 
0040   //! Returns font file path.
0041   const TCollection_AsciiString& FontPath(Font_FontAspect theAspect) const
0042   {
0043     return myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect
0044                                                               : Font_FontAspect_Regular];
0045   }
0046 
0047   //! Returns font file path.
0048   Standard_Integer FontFaceId(Font_FontAspect theAspect) const
0049   {
0050     return myFaceIds[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular];
0051   }
0052 
0053   //! Sets font file path for specific aspect.
0054   Standard_EXPORT void SetFontPath(Font_FontAspect                theAspect,
0055                                    const TCollection_AsciiString& thePath,
0056                                    const Standard_Integer         theFaceId = 0);
0057 
0058   //! Returns TRUE if dedicated file for specified font aspect has been defined.
0059   bool HasFontAspect(Font_FontAspect theAspect) const
0060   {
0061     return !myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect
0062                                                                : Font_FontAspect_Regular]
0063               .IsEmpty();
0064   }
0065 
0066   //! Returns any defined font file path.
0067   const TCollection_AsciiString& FontPathAny(Font_FontAspect   theAspect,
0068                                              bool&             theToSynthesizeItalic,
0069                                              Standard_Integer& theFaceId) const
0070   {
0071     const Font_FontAspect anAspect =
0072       theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular;
0073     const TCollection_AsciiString& aPath = myFilePaths[anAspect];
0074     theFaceId                            = myFaceIds[anAspect];
0075     if (!aPath.IsEmpty())
0076     {
0077       return aPath;
0078     }
0079 
0080     if (theAspect == Font_FontAspect_Italic || theAspect == Font_FontAspect_BoldItalic)
0081     {
0082       if (theAspect == Font_FontAspect_BoldItalic && !myFilePaths[Font_FontAspect_Bold].IsEmpty())
0083       {
0084         theToSynthesizeItalic = true;
0085         theFaceId             = myFaceIds[Font_FontAspect_Bold];
0086         return myFilePaths[Font_FontAspect_Bold];
0087       }
0088       else if (!myFilePaths[Font_FontAspect_Regular].IsEmpty())
0089       {
0090         theToSynthesizeItalic = true;
0091         theFaceId             = myFaceIds[Font_FontAspect_Regular];
0092         return myFilePaths[Font_FontAspect_Regular];
0093       }
0094     }
0095 
0096     if (!myFilePaths[Font_FontAspect_Regular].IsEmpty())
0097     {
0098       theFaceId = myFaceIds[Font_FontAspect_Regular];
0099       return myFilePaths[Font_FontAspect_Regular];
0100     }
0101 
0102     for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
0103     {
0104       if (!myFilePaths[anAspectIter].IsEmpty())
0105       {
0106         theFaceId = myFaceIds[anAspectIter];
0107         return myFilePaths[anAspectIter];
0108       }
0109     }
0110     theFaceId = myFaceIds[Font_FontAspect_Regular];
0111     return myFilePaths[Font_FontAspect_Regular];
0112   }
0113 
0114   //! Return true if the FontName, FontAspect and FontSize are the same.
0115   Standard_EXPORT Standard_Boolean IsEqual(const Handle(Font_SystemFont)& theOtherFont) const;
0116 
0117   //! Return TRUE if this is single-stroke (one-line) font, FALSE by default.
0118   //! Such fonts define single-line glyphs instead of closed contours, so that they are rendered
0119   //! incorrectly by normal software.
0120   Standard_Boolean IsSingleStrokeFont() const { return myIsSingleLine; }
0121 
0122   //! Set if this font should be rendered as single-stroke (one-line).
0123   void SetSingleStrokeFont(Standard_Boolean theIsSingleLine) { myIsSingleLine = theIsSingleLine; }
0124 
0125   //! Format font description.
0126   Standard_EXPORT TCollection_AsciiString ToString() const;
0127 
0128 public:
0129   bool operator==(const Font_SystemFont& theFont) const
0130   {
0131     return myFontKey.IsEqual(theFont.FontKey());
0132   }
0133 
0134 private:
0135   TCollection_AsciiString myFilePaths[Font_FontAspect_NB]; //!< paths to the font file
0136   Standard_Integer        myFaceIds[Font_FontAspect_NB];   //!< face ids per font file
0137   TCollection_AsciiString myFontKey;                       //!< font family name, lower cased
0138   TCollection_AsciiString myFontName;                      //!< font family name
0139   Standard_Boolean        myIsSingleLine; //!< single stroke font flag, FALSE by default
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())
0150       return 0;
0151     return std::hash<TCollection_AsciiString>{}(theLink->FontKey());
0152   }
0153 };
0154 }; // namespace std
0155 
0156 DEFINE_STANDARD_HANDLE(Font_SystemFont, Standard_Transient)
0157 
0158 #endif // _Font_SystemFont_HeaderFile