b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | |
19 | #include <Xw_Extension.h> |
20 | |
b311480e |
21 | /* ifdef then trace on */ |
7fd59977 |
22 | #ifdef TRACE |
23 | #define TRACE_DEF_FONTMAP |
24 | #endif |
25 | |
26 | /* |
27 | XW_EXT_FONTMAP* Xw_def_fontmap(adisplay,nfont): |
28 | XW_EXT_DISPLAY *adisplay Extended Display structure |
29 | |
30 | int nfont Number of font cells to be allocated |
31 | |
32 | Create a fontmap extension |
33 | allocate the font cells in the fontmap as if possible |
34 | depending of the MAXFONT define . |
35 | |
36 | Returns Fontmap extension address if successuful |
37 | or NULL if ERROR |
38 | |
39 | STATUS = Xw_close_fontmap(afontmap) |
40 | XW_EXT_FONTMAP* afontmap Extended fontmap |
41 | |
42 | |
43 | Destroy The Extended TypeMap |
44 | |
45 | Returns ERROR if Bad Extended TypeMap Address |
46 | SUCCESS if successfull |
47 | |
48 | */ |
49 | |
50 | #ifdef XW_PROTOTYPE |
51 | void* Xw_def_fontmap (void* adisplay,int nfont) |
52 | #else |
53 | void* Xw_def_fontmap (adisplay,nfont) |
54 | void *adisplay ; |
55 | int nfont ; |
56 | #endif /*XW_PROTOTYPE*/ |
57 | { |
58 | XW_EXT_DISPLAY *pdisplay = (XW_EXT_DISPLAY*)adisplay ; |
59 | XW_EXT_FONTMAP *pfontmap = NULL ; |
60 | XFontStruct *dfstruct ; |
61 | XGCValues values ; |
62 | GC gc ; |
63 | //int i,font,psize ; |
64 | int i,psize ; |
65 | char *dfstring = NULL ; |
66 | |
67 | if( !Xw_isdefine_display(pdisplay) ) { |
68 | /*ERROR*Bad EXT_DISPLAY Address*/ |
69 | Xw_set_error(96,"Xw_def_fontmap",pdisplay) ; |
70 | return (NULL) ; |
71 | } |
72 | |
73 | gc = DefaultGCOfScreen(_DSCREEN) ; |
74 | XGetGCValues(_DDISPLAY,gc,GCFont,&values) ; |
75 | dfstruct = XQueryFont(_DDISPLAY,XGContextFromGC(gc)) ; |
76 | for( i=0 ; i<dfstruct->n_properties ; i++ ) { |
77 | if( dfstruct->properties[i].name == XA_FONT ) { |
78 | dfstring = XGetAtomName(_DDISPLAY,dfstruct->properties[i].card32) ; |
79 | break ; |
80 | } |
81 | } |
82 | |
83 | |
84 | if( !(pfontmap = Xw_add_fontmap_structure(sizeof(XW_EXT_FONTMAP))) ) |
85 | return (NULL) ; |
86 | |
87 | if( nfont <= 0 ) nfont = MAXFONT ; |
88 | |
89 | |
90 | pfontmap->connexion = pdisplay ; |
91 | pfontmap->maxfont = min(nfont,MAXFONT) ; |
92 | pfontmap->gnames[0] = (char*) "Defaultfont"; |
93 | pfontmap->snames[0] = dfstring ; |
94 | pfontmap->fonts[0] = dfstruct ; |
95 | pfontmap->fonts[0]->fid = values.font ; |
96 | |
97 | psize = (pfontmap->fonts[0])->max_bounds.ascent + |
98 | (pfontmap->fonts[0])->max_bounds.descent ; |
99 | |
100 | pfontmap->gsizes[0] = (float)psize*HeightMMOfScreen(_DSCREEN)/ |
101 | (float)HeightOfScreen(_DSCREEN) ; |
102 | pfontmap->fsizes[0] = pfontmap->gsizes[0]; |
103 | pfontmap->fratios[0] = 0.; |
104 | pfontmap->ssizex[0] = pfontmap->ssizey[0] = pfontmap->fsizes[0] ; |
105 | pfontmap->gslants[0] = pfontmap->sslants[0] = 0. ; |
106 | |
107 | #ifdef TRACE_DEF_FONTMAP |
108 | if( Xw_get_trace() ) { |
109 | printf(" %lx = Xw_def_fontmap(%lx,%d)\n", (long ) pfontmap,(long ) adisplay,nfont) ; |
110 | } |
111 | #endif |
112 | |
113 | return (pfontmap); |
114 | } |
115 | |
116 | static XW_EXT_FONTMAP *PfontmapList =NULL ; |
117 | |
118 | #ifdef XW_PROTOTYPE |
119 | XW_EXT_FONTMAP* Xw_add_fontmap_structure(int size) |
120 | #else |
121 | XW_EXT_FONTMAP* Xw_add_fontmap_structure(size) |
122 | int size ; |
123 | #endif /*XW_PROTOTYPE*/ |
124 | /* |
125 | Create and Insert one Extended fontmap structure in the |
126 | EXtended fontmap List |
127 | |
128 | returns Extended fontmap address if successful |
129 | or NULL if Bad Allocation |
130 | */ |
131 | { |
132 | XW_EXT_FONTMAP *pfontmap = (XW_EXT_FONTMAP*) Xw_malloc(size) ; |
133 | int i ; |
134 | |
135 | if( pfontmap ) { |
136 | pfontmap->type = FONTMAP_TYPE ; |
137 | pfontmap->link = PfontmapList ; |
138 | PfontmapList = pfontmap ; |
139 | pfontmap->connexion = NULL ; |
140 | pfontmap->maxfont = 0 ; |
141 | pfontmap->maxwindow = 0 ; |
142 | for( i=0 ; i<MAXFONT ; i++ ) { |
143 | pfontmap->gnames[i] = NULL ; |
144 | pfontmap->snames[i] = NULL ; |
145 | pfontmap->fonts[i] = NULL ; |
146 | pfontmap->gsizes[i] = 0. ; |
147 | pfontmap->fsizes[i] = 0. ; |
148 | pfontmap->ssizex[i] = 0. ; |
149 | pfontmap->ssizey[i] = 0. ; |
150 | pfontmap->gslants[i] = 0. ; |
151 | pfontmap->sslants[i] = 0. ; |
152 | pfontmap->fratios[i] = 0. ; |
153 | } |
154 | } else { |
155 | /*EXT_FONTMAP allocation failed*/ |
156 | Xw_set_error(9,"Xw_add_fontmap_structure",NULL) ; |
157 | } |
158 | |
159 | return (pfontmap) ; |
160 | } |
161 | |
162 | #ifdef XW_PROTOTYPE |
163 | XW_STATUS Xw_close_fontmap(void* afontmap) |
164 | #else |
165 | XW_STATUS Xw_close_fontmap(afontmap) |
166 | void* afontmap ; |
167 | #endif /*XW_PROTOTYPE*/ |
168 | { |
169 | XW_EXT_FONTMAP* pfontmap = (XW_EXT_FONTMAP*) afontmap ; |
170 | XW_STATUS status ; |
171 | |
172 | if( !Xw_isdefine_fontmap(pfontmap) ) { |
173 | /*Bad EXT_FONTMAP Address*/ |
174 | Xw_set_error(51,"Xw_close_fontmap",pfontmap) ; |
175 | return (XW_ERROR) ; |
176 | } |
177 | |
178 | status = Xw_del_fontmap_structure(pfontmap) ; |
179 | |
180 | #ifdef TRACE_DEF_FONTMAP |
181 | if( Xw_get_trace() ) { |
182 | printf(" %d = Xw_close_fontmap(%lx)\n",status,(long ) pfontmap) ; |
183 | } |
184 | #endif |
185 | |
186 | return (status) ; |
187 | } |
188 | |
189 | #ifdef XW_PROTOTYPE |
190 | XW_STATUS Xw_del_fontmap_structure(XW_EXT_FONTMAP* afontmap) |
191 | #else |
192 | XW_STATUS Xw_del_fontmap_structure(afontmap) |
193 | XW_EXT_FONTMAP *afontmap; |
194 | #endif /*XW_PROTOTYPE*/ |
195 | /* |
196 | Remove the Extended fontmap address from the Extended List |
197 | |
198 | returns ERROR if the fontmap address is not Found in the list |
199 | returns SUCCESS if successful |
200 | */ |
201 | { |
202 | XW_EXT_FONTMAP *pfontmap = PfontmapList ; |
203 | int i ; |
204 | |
205 | if( !afontmap ) return (XW_ERROR) ; |
206 | |
207 | if( afontmap->maxwindow ) { |
208 | return (XW_ERROR) ; |
209 | } else { |
210 | for( i=1 ; i<MAXFONT ; i++) { |
211 | if( afontmap->fonts[i] ) { |
212 | if( afontmap->gnames[i] ) Xw_free(afontmap->gnames[i]) ; |
213 | if( afontmap->snames[i] ) Xw_free(afontmap->snames[i]) ; |
214 | if( afontmap->fonts[i]->fid != afontmap->fonts[0]->fid ) |
215 | XFreeFont(_FDISPLAY,afontmap->fonts[i]) ; |
216 | } |
217 | } |
218 | |
219 | if( afontmap == pfontmap ) { |
220 | PfontmapList = (XW_EXT_FONTMAP*) afontmap->link ; |
221 | } else { |
222 | for( ; pfontmap ; pfontmap = (XW_EXT_FONTMAP*) pfontmap->link ) { |
223 | if( pfontmap->link == afontmap ) { |
224 | pfontmap->link = afontmap->link ; |
225 | break ; |
226 | } |
227 | } |
228 | } |
229 | Xw_free(afontmap) ; |
230 | } |
231 | return (XW_SUCCESS) ; |
232 | } |