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 |
26 | class Font_SystemFont : public Standard_Transient |
42cf5bc1 |
27 | { |
e4f0cc46 |
28 | DEFINE_STANDARD_RTTIEXT(Font_SystemFont, Standard_Transient) |
42cf5bc1 |
29 | public: |
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 | |
9a90a452 |
46 | //! Returns font file path. |
47 | Standard_Integer FontFaceId (Font_FontAspect theAspect) const |
48 | { |
49 | return myFaceIds[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular]; |
50 | } |
51 | |
5b377041 |
52 | //! Sets font file path for specific aspect. |
53 | Standard_EXPORT void SetFontPath (Font_FontAspect theAspect, |
9a90a452 |
54 | const TCollection_AsciiString& thePath, |
55 | const Standard_Integer theFaceId = 0); |
5b377041 |
56 | |
57 | //! Returns TRUE if dedicated file for specified font aspect has been defined. |
58 | bool HasFontAspect (Font_FontAspect theAspect) const |
59 | { |
60 | return !myFilePaths[theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular].IsEmpty(); |
61 | } |
62 | |
63 | //! Returns any defined font file path. |
1bbd7c79 |
64 | const TCollection_AsciiString& FontPathAny (Font_FontAspect theAspect, |
9a90a452 |
65 | bool& theToSynthesizeItalic, |
66 | Standard_Integer& theFaceId) const |
5b377041 |
67 | { |
9a90a452 |
68 | const Font_FontAspect anAspect = theAspect != Font_FontAspect_UNDEFINED ? theAspect : Font_FontAspect_Regular; |
69 | const TCollection_AsciiString& aPath = myFilePaths[anAspect]; |
70 | theFaceId = myFaceIds[anAspect]; |
5b377041 |
71 | if (!aPath.IsEmpty()) |
72 | { |
73 | return aPath; |
74 | } |
1bbd7c79 |
75 | |
76 | if (theAspect == Font_FontAspect_Italic |
77 | || theAspect == Font_FontAspect_BoldItalic) |
78 | { |
79 | if (theAspect == Font_FontAspect_BoldItalic |
80 | && !myFilePaths[Font_FontAspect_Bold].IsEmpty()) |
81 | { |
82 | theToSynthesizeItalic = true; |
9a90a452 |
83 | theFaceId = myFaceIds[Font_FontAspect_Bold]; |
1bbd7c79 |
84 | return myFilePaths[Font_FontAspect_Bold]; |
85 | } |
86 | else if (!myFilePaths[Font_FontAspect_Regular].IsEmpty()) |
87 | { |
88 | theToSynthesizeItalic = true; |
9a90a452 |
89 | theFaceId = myFaceIds[Font_FontAspect_Regular]; |
1bbd7c79 |
90 | return myFilePaths[Font_FontAspect_Regular]; |
91 | } |
92 | } |
93 | |
94 | if (!myFilePaths[Font_FontAspect_Regular].IsEmpty()) |
5b377041 |
95 | { |
9a90a452 |
96 | theFaceId = myFaceIds[Font_FontAspect_Regular]; |
5b377041 |
97 | return myFilePaths[Font_FontAspect_Regular]; |
98 | } |
1bbd7c79 |
99 | |
5b377041 |
100 | for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter) |
101 | { |
102 | if (!myFilePaths[anAspectIter].IsEmpty()) |
103 | { |
9a90a452 |
104 | theFaceId = myFaceIds[anAspectIter]; |
5b377041 |
105 | return myFilePaths[anAspectIter]; |
106 | } |
107 | } |
9a90a452 |
108 | theFaceId = myFaceIds[Font_FontAspect_Regular]; |
5b377041 |
109 | return myFilePaths[Font_FontAspect_Regular]; |
110 | } |
e4f0cc46 |
111 | |
42cf5bc1 |
112 | //! Return true if the FontName, FontAspect and FontSize are the same. |
42cf5bc1 |
113 | Standard_EXPORT Standard_Boolean IsEqual (const Handle(Font_SystemFont)& theOtherFont) const; |
114 | |
e4f0cc46 |
115 | //! Return TRUE if this is single-stroke (one-line) font, FALSE by default. |
116 | //! Such fonts define single-line glyphs instead of closed contours, so that they are rendered incorrectly by normal software. |
117 | Standard_Boolean IsSingleStrokeFont() const { return myIsSingleLine; } |
42cf5bc1 |
118 | |
e4f0cc46 |
119 | //! Set if this font should be rendered as single-stroke (one-line). |
120 | void SetSingleStrokeFont (Standard_Boolean theIsSingleLine) { myIsSingleLine = theIsSingleLine; } |
42cf5bc1 |
121 | |
5b377041 |
122 | //! Format font description. |
123 | Standard_EXPORT TCollection_AsciiString ToString() const; |
124 | |
125 | public: |
2b2be3fb |
126 | //! Computes a hash code for the system font, in the range [1, theUpperBound]. Based on Font Family, so that the whole |
127 | //! family with different aspects can be found within the same bucket of some map |
128 | //! @param theSystemFont the system font which hash code is to be computed |
129 | //! @param theUpperBound the upper bound of the range a computing hash code must be within |
130 | //! @return a computed hash code, in the range [1, theUpperBound] |
131 | static Standard_Integer HashCode (const Handle (Font_SystemFont) & theSystemFont, const Standard_Integer theUpperBound) |
5b377041 |
132 | { |
2b2be3fb |
133 | return ::HashCode (theSystemFont->FontKey(), theUpperBound); |
5b377041 |
134 | } |
135 | |
136 | //! Matching two instances, for Map interface. |
137 | static bool IsEqual (const Handle(Font_SystemFont)& theFont1, |
138 | const Handle(Font_SystemFont)& theFont2) |
139 | { |
140 | return theFont1->IsEqual (theFont2); |
141 | } |
142 | |
42cf5bc1 |
143 | private: |
144 | |
5b377041 |
145 | TCollection_AsciiString myFilePaths[Font_FontAspect_NB]; //!< paths to the font file |
9a90a452 |
146 | Standard_Integer myFaceIds [Font_FontAspect_NB]; //!< face ids per font file |
5b377041 |
147 | TCollection_AsciiString myFontKey; //!< font family name, lower cased |
148 | TCollection_AsciiString myFontName; //!< font family name |
149 | Standard_Boolean myIsSingleLine; //!< single stroke font flag, FALSE by default |
42cf5bc1 |
150 | |
151 | }; |
152 | |
e4f0cc46 |
153 | DEFINE_STANDARD_HANDLE(Font_SystemFont, Standard_Transient) |
42cf5bc1 |
154 | |
155 | #endif // _Font_SystemFont_HeaderFile |