b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
7fd59977 |
19 | |
20 | #include <Xw_FontMap.ixx> |
21 | #include <Aspect_TypeOfFont.hxx> |
22 | #include <Aspect_FontStyle.hxx> |
23 | #include <Standard_ShortReal.hxx> |
24 | |
25 | // Routines C a declarer en extern |
26 | //extern "C" { |
27 | #include <Xw_Cextern.hxx> |
28 | //} |
29 | |
30 | //-Static data definitions |
31 | |
32 | static char *ErrorMessag ; |
33 | static int ErrorNumber ; |
34 | static int ErrorGravity ; |
35 | static XW_STATUS status ; |
36 | |
37 | Xw_FontMap::Xw_FontMap () { |
38 | } |
39 | |
40 | Xw_FontMap::Xw_FontMap (const Standard_CString Connexion) { |
41 | |
42 | MyExtendedDisplay = Xw_open_display((Standard_PCharacter)Connexion) ; |
43 | |
44 | if( !MyExtendedDisplay ) { |
45 | ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ; |
46 | if( ErrorGravity ) |
47 | Aspect_FontMapDefinitionError::Raise (ErrorMessag) ; |
48 | else Xw_print_error() ; |
49 | } |
50 | |
51 | MyExtendedFontMap = Xw_def_fontmap(MyExtendedDisplay,(int)0) ; |
52 | |
53 | if( !Xw_isdefine_fontmap(MyExtendedFontMap) ) { |
54 | ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ; |
55 | if( ErrorGravity ) |
56 | Aspect_FontMapDefinitionError::Raise (ErrorMessag) ; |
57 | else Xw_print_error() ; |
58 | } |
59 | } |
60 | |
61 | void Xw_FontMap::SetEntry (const Aspect_FontMapEntry& Entry) { |
62 | Aspect_FontStyle style = Entry.Type() ; |
63 | int ffont = (int) Entry.Index() ; |
64 | Standard_CString value = style.FullName() ; |
65 | float csize = TOMILLIMETER(style.Size()) ; |
66 | |
67 | if( ffont ) { /* Don't modify Index 0,Default font */ |
68 | status = Xw_def_font(MyExtendedFontMap,ffont,csize,(char*)value); |
69 | |
70 | if( !status ) { |
71 | ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ; |
72 | if( ErrorGravity > 2 ) |
73 | Aspect_BadAccess::Raise (ErrorMessag) ; |
74 | else Xw_print_error() ; |
75 | } |
76 | } |
77 | |
78 | } |
79 | |
80 | void Xw_FontMap::SetEntries (const Handle(Aspect_FontMap)& Fontmap) { |
81 | Standard_Integer size = Fontmap->Size() ; |
82 | Standard_Integer i ; |
83 | |
84 | if( !Xw_isdefine_fontmap(MyExtendedFontMap) ) { |
85 | ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ; |
86 | if( ErrorGravity > 2 ) |
87 | Aspect_FontMapDefinitionError::Raise (ErrorMessag) ; |
88 | else Xw_print_error() ; |
89 | } |
90 | |
91 | for( i=1 ; i<=size ; i++ ) { |
92 | SetEntry(Fontmap->Entry(i)) ; |
93 | } |
94 | } |
95 | |
96 | void Xw_FontMap::Destroy() { |
97 | |
98 | if( MyExtendedFontMap ) { |
99 | Xw_close_fontmap(MyExtendedFontMap) ; |
100 | MyExtendedFontMap = NULL ; |
101 | } |
102 | } |
103 | |
104 | Standard_Integer Xw_FontMap::FreeFonts( ) const { |
105 | Standard_Integer nfont ; |
106 | int mfont,ufont,dfont,ffont ; |
107 | |
108 | status = Xw_get_fontmap_info(MyExtendedFontMap, |
109 | &mfont,&ufont,&dfont,&ffont) ; |
110 | |
111 | if( !status ) { |
112 | ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ; |
113 | if( ErrorGravity > 2 ) |
114 | Aspect_BadAccess::Raise (ErrorMessag) ; |
115 | else Xw_print_error() ; |
116 | } |
117 | |
118 | nfont = ufont - dfont ; |
119 | |
120 | return (nfont) ; |
121 | } |
122 | |
123 | Standard_Address Xw_FontMap::ExtendedFontMap () const { |
124 | |
125 | return (MyExtendedFontMap); |
126 | |
127 | } |