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 | |
23 | #include <OSD_SystemFont.ixx> |
24 | #include <OSD_Path.hxx> |
25 | #include <TCollection_HAsciiString.hxx> |
26 | |
27 | |
28 | OSD_SystemFont::OSD_SystemFont(): |
29 | MyFontName(), |
30 | MyFontAspect(OSD_FA_Undefined), |
31 | MyFaceSize(-1), |
32 | MyVerification(Standard_False) |
33 | { |
34 | } |
35 | |
36 | OSD_SystemFont::OSD_SystemFont( const Handle(TCollection_HAsciiString)& FontName, |
37 | const OSD_FontAspect FontAspect, |
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 | |
48 | OSD_SystemFont::OSD_SystemFont( const Handle(TCollection_HAsciiString)& XLFD, |
49 | const Handle(TCollection_HAsciiString)& FilePath) : |
50 | MyFilePath(FilePath), |
51 | MyFontAspect(OSD_FA_Undefined) |
52 | { |
53 | MyVerification = Standard_True; |
54 | if ( XLFD.IsNull() ) |
55 | { |
56 | MyVerification=Standard_False; |
57 | printf("NULL XLFD handler \n"); |
58 | } |
59 | if ( XLFD->IsEmpty() ) |
60 | { |
61 | MyVerification=Standard_False; |
62 | printf("EMPTY XLFD handler \n"); |
63 | } |
64 | |
65 | if(MyVerification) |
66 | { |
67 | MyFontName = XLFD->Token( "-", 2 ); |
68 | TCollection_AsciiString str( XLFD->ToCString() ); |
69 | |
70 | if ( str.Search( "-0-0-0-0-" ) >=0 ) |
71 | MyFaceSize = -1; |
72 | else |
73 | //TODO catch exeption |
74 | MyFaceSize = str.Token( "-", 7 ).RealValue(); |
75 | |
76 | //detect aspect |
77 | if ( str.Token("-", 3).IsEqual( "bold" ) ) |
78 | MyFontAspect = OSD_FA_Bold; |
79 | else if ( str.Token("-", 3).IsEqual( "medium" ) || |
80 | str.Token("-", 3).IsEqual( "normal" ) ) |
81 | MyFontAspect = OSD_FA_Regular; |
82 | |
83 | if ( MyFontAspect != OSD_FA_Undefined && |
84 | ( str.Token("-",4 ).IsEqual( "i" ) || str.Token("-",4 ).IsEqual( "o" ) ) ) |
85 | { |
86 | if ( MyFontAspect == OSD_FA_Bold ) |
87 | MyFontAspect = OSD_FA_BoldItalic; |
88 | else |
89 | MyFontAspect = OSD_FA_Italic; |
90 | } |
91 | } |
92 | } |
93 | |
94 | Standard_Boolean OSD_SystemFont::IsValid() const{ |
95 | if ( !MyVerification) |
96 | return Standard_False; |
97 | |
98 | if ( MyFontAspect == OSD_FA_Undefined ) |
99 | return Standard_False; |
100 | |
101 | if ( MyFontName->IsEmpty() || !MyFontName->IsAscii() ) |
102 | return Standard_False; |
103 | |
104 | OSD_Path path; |
105 | return path.IsValid( MyFilePath->String() ); |
106 | } |
107 | |
108 | Handle(TCollection_HAsciiString) OSD_SystemFont::FontPath() const{ |
109 | return MyFilePath; |
110 | } |
111 | |
112 | Handle(TCollection_HAsciiString) OSD_SystemFont::FontName() const{ |
113 | return MyFontName; |
114 | } |
115 | |
116 | OSD_FontAspect OSD_SystemFont::FontAspect() const{ |
117 | return MyFontAspect; |
118 | } |
119 | |
120 | Standard_Integer OSD_SystemFont::FontHeight() const { |
121 | return MyFaceSize; |
122 | } |