b311480e |
1 | // Created on: 2008-01-20 |
2 | // Created by: Alexander A. BORODIN |
3 | // Copyright (c) 2008-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | |
7fd59977 |
21 | // Updated: |
22 | |
eeaaaefb |
23 | #include <Font_SystemFont.ixx> |
7fd59977 |
24 | #include <OSD_Path.hxx> |
25 | #include <TCollection_HAsciiString.hxx> |
26 | |
27 | |
eeaaaefb |
28 | Font_SystemFont::Font_SystemFont(): |
7fd59977 |
29 | MyFontName(), |
eeaaaefb |
30 | MyFontAspect(Font_FA_Undefined), |
7fd59977 |
31 | MyFaceSize(-1), |
32 | MyVerification(Standard_False) |
33 | { |
34 | } |
35 | |
eeaaaefb |
36 | Font_SystemFont::Font_SystemFont( const Handle(TCollection_HAsciiString)& FontName, |
37 | const Font_FontAspect FontAspect, |
7fd59977 |
38 | const Handle(TCollection_HAsciiString)& FilePath ): |
39 | MyFontName(FontName), |
40 | MyFontAspect(FontAspect), |
41 | MyFilePath(FilePath), |
42 | MyFaceSize(-1), |
43 | MyVerification(Standard_True) |
44 | { |
45 | |
46 | } |
47 | |
aff395a3 |
48 | Font_SystemFont::Font_SystemFont (const Handle(TCollection_HAsciiString)& theXLFD, |
49 | const Handle(TCollection_HAsciiString)& theFilePath) : |
50 | MyFilePath(theFilePath), |
51 | MyFontAspect(Font_FA_Regular) |
7fd59977 |
52 | { |
53 | MyVerification = Standard_True; |
aff395a3 |
54 | if (theXLFD.IsNull()) |
7fd59977 |
55 | { |
aff395a3 |
56 | MyVerification = Standard_False; // empty font description handler |
7fd59977 |
57 | } |
aff395a3 |
58 | if (theXLFD->IsEmpty()) |
7fd59977 |
59 | { |
aff395a3 |
60 | MyVerification = Standard_False; // empty font description |
7fd59977 |
61 | } |
62 | |
aff395a3 |
63 | if (MyVerification) |
7fd59977 |
64 | { |
aff395a3 |
65 | MyFontName = theXLFD->Token ("-", 2); |
66 | TCollection_AsciiString aXLFD (theXLFD->ToCString()); |
7fd59977 |
67 | |
aff395a3 |
68 | // Getting font size for fixed size fonts |
69 | if (aXLFD.Search ("-0-0-0-0-") >= 0) |
70 | MyFaceSize = -1; // Scalable font |
7fd59977 |
71 | else |
72 | //TODO catch exeption |
aff395a3 |
73 | MyFaceSize = aXLFD.Token ("-", 7).IntegerValue(); |
7fd59977 |
74 | |
aff395a3 |
75 | // Detect font aspect |
76 | if (aXLFD.Token ("-", 3).IsEqual ("bold") && |
77 | (aXLFD.Token ("-", 4).IsEqual ("i") || aXLFD.Token ("-", 4).IsEqual ("o"))) |
78 | { |
79 | MyFontAspect = Font_FA_BoldItalic; |
80 | } |
81 | else if (aXLFD.Token ("-", 3).IsEqual ("bold")) |
82 | { |
eeaaaefb |
83 | MyFontAspect = Font_FA_Bold; |
aff395a3 |
84 | } |
85 | else if (aXLFD.Token ("-", 4).IsEqual ("i") || aXLFD.Token ("-", 4).IsEqual ("o")) |
7fd59977 |
86 | { |
aff395a3 |
87 | MyFontAspect = Font_FA_Italic; |
7fd59977 |
88 | } |
89 | } |
90 | } |
91 | |
eeaaaefb |
92 | Standard_Boolean Font_SystemFont::IsValid() const{ |
7fd59977 |
93 | if ( !MyVerification) |
94 | return Standard_False; |
95 | |
eeaaaefb |
96 | if ( MyFontAspect == Font_FA_Undefined ) |
7fd59977 |
97 | return Standard_False; |
98 | |
99 | if ( MyFontName->IsEmpty() || !MyFontName->IsAscii() ) |
100 | return Standard_False; |
101 | |
102 | OSD_Path path; |
103 | return path.IsValid( MyFilePath->String() ); |
104 | } |
105 | |
eeaaaefb |
106 | Handle(TCollection_HAsciiString) Font_SystemFont::FontPath() const{ |
7fd59977 |
107 | return MyFilePath; |
108 | } |
109 | |
eeaaaefb |
110 | Handle(TCollection_HAsciiString) Font_SystemFont::FontName() const{ |
7fd59977 |
111 | return MyFontName; |
112 | } |
113 | |
eeaaaefb |
114 | Font_FontAspect Font_SystemFont::FontAspect() const{ |
7fd59977 |
115 | return MyFontAspect; |
116 | } |
117 | |
eeaaaefb |
118 | Standard_Integer Font_SystemFont::FontHeight() const { |
7fd59977 |
119 | return MyFaceSize; |
120 | } |
aff395a3 |
121 | |
122 | Standard_Boolean Font_SystemFont::IsEqual(const Handle(Font_SystemFont)& theOtherFont) const |
123 | { |
124 | if (!MyFontName->IsSameString (theOtherFont->FontName(), Standard_False)) |
125 | { |
126 | return Standard_False; |
127 | } |
128 | |
129 | if (MyFontAspect != theOtherFont->FontAspect()) |
130 | { |
131 | return Standard_False; |
132 | } |
133 | |
134 | if (MyFaceSize != theOtherFont->FontHeight()) |
135 | { |
136 | return Standard_False; |
137 | } |
138 | |
139 | return Standard_True; |
140 | } |