0030439: Visualization - extend fonts search within Font_FontMgr::FindFont() on Linux
[occt.git] / src / Font / Font_SystemFont.hxx
CommitLineData
42cf5bc1 1// Created on: 2008-01-20
2// Created by: Alexander A. BORODIN
3// Copyright (c) 2008-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#ifndef _Font_SystemFont_HeaderFile
17#define _Font_SystemFont_HeaderFile
18
5b377041 19#include <Font_FontAspect.hxx>
42cf5bc1 20#include <Standard.hxx>
21#include <Standard_Type.hxx>
25e59720 22#include <Standard_Transient.hxx>
5b377041 23#include <TCollection_AsciiString.hxx>
42cf5bc1 24
e4f0cc46 25//! This class stores information about the font, which is merely a file path and cached metadata about the font.
25e59720 26class Font_SystemFont : public Standard_Transient
42cf5bc1 27{
e4f0cc46 28 DEFINE_STANDARD_RTTIEXT(Font_SystemFont, Standard_Transient)
42cf5bc1 29public:
30
e4f0cc46 31 //! Creates a new font object.
5b377041 32 Standard_EXPORT Font_SystemFont (const TCollection_AsciiString& theFontName);
e4f0cc46 33
5b377041 34 //! Returns font family name (lower-cased).
35 const TCollection_AsciiString& FontKey() const { return myFontKey; }
e4f0cc46 36
37 //! Returns font family name.
5b377041 38 const TCollection_AsciiString& FontName() const { return myFontName; }
42cf5bc1 39
e4f0cc46 40 //! Returns font file path.
5b377041 41 const TCollection_AsciiString& FontPath (Font_FontAspect theAspect) const
42 {
43 return myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular];
44 }
45
46 //! Sets font file path for specific aspect.
47 Standard_EXPORT void SetFontPath (Font_FontAspect theAspect,
48 const TCollection_AsciiString& thePath);
49
50 //! Returns TRUE if dedicated file for specified font aspect has been defined.
51 bool HasFontAspect (Font_FontAspect theAspect) const
52 {
53 return !myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular].IsEmpty();
54 }
55
56 //! Returns any defined font file path.
57 const TCollection_AsciiString& FontPathAny (Font_FontAspect theAspect) const
58 {
59 const TCollection_AsciiString& aPath = myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular];
60 if (!aPath.IsEmpty())
61 {
62 return aPath;
63 }
64 else if (!myFilePaths[Font_FontAspect_Regular].IsEmpty())
65 {
66 return myFilePaths[Font_FontAspect_Regular];
67 }
68 for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
69 {
70 if (!myFilePaths[anAspectIter].IsEmpty())
71 {
72 return myFilePaths[anAspectIter];
73 }
74 }
75 return myFilePaths[Font_FontAspect_Regular];
76 }
e4f0cc46 77
42cf5bc1 78 //! Return true if the FontName, FontAspect and FontSize are the same.
42cf5bc1 79 Standard_EXPORT Standard_Boolean IsEqual (const Handle(Font_SystemFont)& theOtherFont) const;
80
e4f0cc46 81 //! Return TRUE if this is single-stroke (one-line) font, FALSE by default.
82 //! Such fonts define single-line glyphs instead of closed contours, so that they are rendered incorrectly by normal software.
83 Standard_Boolean IsSingleStrokeFont() const { return myIsSingleLine; }
42cf5bc1 84
e4f0cc46 85 //! Set if this font should be rendered as single-stroke (one-line).
86 void SetSingleStrokeFont (Standard_Boolean theIsSingleLine) { myIsSingleLine = theIsSingleLine; }
42cf5bc1 87
5b377041 88 //! Format font description.
89 Standard_EXPORT TCollection_AsciiString ToString() const;
90
91public:
92
93 //! Hash value, for Map interface.
94 //! Based on Font Family, so that the whole family with different aspects can be found within the same bucket.
95 static Standard_Integer HashCode (const Handle(Font_SystemFont)& theFont,
96 const Standard_Integer theUpper)
97 {
98 return ::HashCode (theFont->FontKey(), theUpper);
99 }
100
101 //! Matching two instances, for Map interface.
102 static bool IsEqual (const Handle(Font_SystemFont)& theFont1,
103 const Handle(Font_SystemFont)& theFont2)
104 {
105 return theFont1->IsEqual (theFont2);
106 }
107
42cf5bc1 108private:
109
5b377041 110 TCollection_AsciiString myFilePaths[Font_FontAspect_NB]; //!< paths to the font file
111 TCollection_AsciiString myFontKey; //!< font family name, lower cased
112 TCollection_AsciiString myFontName; //!< font family name
113 Standard_Boolean myIsSingleLine; //!< single stroke font flag, FALSE by default
42cf5bc1 114
115};
116
e4f0cc46 117DEFINE_STANDARD_HANDLE(Font_SystemFont, Standard_Transient)
42cf5bc1 118
119#endif // _Font_SystemFont_HeaderFile