Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:30

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 about the font.
0026 class Font_SystemFont : public Standard_Transient
0027 {
0028   DEFINE_STANDARD_RTTIEXT(Font_SystemFont, Standard_Transient)
0029 public:
0030 
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 : Font_FontAspect_Regular];
0044   }
0045 
0046   //! Returns font file path.
0047   Standard_Integer FontFaceId (Font_FontAspect theAspect) const
0048   {
0049     return myFaceIds[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular];
0050   }
0051 
0052   //! Sets font file path for specific aspect.
0053   Standard_EXPORT void SetFontPath (Font_FontAspect theAspect,
0054                                     const TCollection_AsciiString& thePath,
0055                                     const Standard_Integer theFaceId = 0);
0056 
0057   //! Returns TRUE if dedicated file for specified font aspect has been defined.
0058   bool HasFontAspect (Font_FontAspect theAspect) const
0059   {
0060     return !myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular].IsEmpty();
0061   }
0062 
0063   //! Returns any defined font file path.
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   //! Return true if the FontName, FontAspect and FontSize are the same.
0113   Standard_EXPORT Standard_Boolean IsEqual (const Handle(Font_SystemFont)& theOtherFont) const;
0114 
0115   //! Return TRUE if this is single-stroke (one-line) font, FALSE by default.
0116   //! Such fonts define single-line glyphs instead of closed contours, so that they are rendered incorrectly by normal software.
0117   Standard_Boolean IsSingleStrokeFont() const { return myIsSingleLine; }
0118 
0119   //! Set if this font should be rendered as single-stroke (one-line).
0120   void SetSingleStrokeFont (Standard_Boolean theIsSingleLine) { myIsSingleLine = theIsSingleLine; }
0121 
0122   //! Format font description.
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]; //!< paths to the font file
0135   Standard_Integer        myFaceIds  [Font_FontAspect_NB]; //!< face ids per font file
0136   TCollection_AsciiString myFontKey;      //!< font family name, lower cased
0137   TCollection_AsciiString myFontName;     //!< font family name
0138   Standard_Boolean        myIsSingleLine; //!< single stroke font flag, FALSE by default
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 // _Font_SystemFont_HeaderFile