Debian Codegraph @

lib/database/src/so/nodes/SoFontStyle.c++

raw symbols SCIP
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * Copyright (C) 1995-96 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | SoFontStyle implementation.
44 |
45 | Author(s) : Chris Marrin
46 |
47 ______________ S I L I C O N G R A P H I C S I N C . ____________
48 _______________________________________________________________________
49 */
50
51 #include <assert.h>
52
53 #include <Inventor/actions/SoAction.h>
54 #include <Inventor/actions/SoCallbackAction.h>
55 #include <Inventor/actions/SoGLRenderAction.h>
56 #include <Inventor/actions/SoGetBoundingBoxAction.h>
57 #include <Inventor/actions/SoPickAction.h>
58 #include <Inventor/elements/SoFontNameElement.h>
59 #include <Inventor/elements/SoFontSizeElement.h>
60 #include <Inventor/elements/SoOverrideElement.h>
61 #include <Inventor/nodes/SoFontStyle.h>
62
63 SO_NODE_SOURCE(SoFontStyle);
64
65 const char *SoFontStyle::fontList[][4] =
66 {
67 { "Utopia-Regular", "Utopia-Bold",
68 "Utopia-Italic", "Utopia-BoldItalic" },
69 { "Helvetica", "Helvetica-Bold",
70 "Helvetica-Oblique", "Helvetica-BoldOblique" },
71 { "Courier", "Courier-Bold",
72 "Courier-Oblique", "Courier-BoldOblique" },
73 };
74
75 ////////////////////////////////////////////////////////////////////////
76 //
77 // Constructor
78 //
79 SoFontStyle::SoFontStyle()
80 //
81 ////////////////////////////////////////////////////////////////////////
82 {
83 SO_NODE_CONSTRUCTOR(SoFontStyle);
84 SO_NODE_ADD_FIELD(family, (SERIF));
85 SO_NODE_ADD_FIELD(style, (NONE));
86
87 // Set up static info for enumerated type field
88 SO_NODE_DEFINE_ENUM_VALUE(Family, SERIF);
89 SO_NODE_DEFINE_ENUM_VALUE(Family, SANS);
90 SO_NODE_DEFINE_ENUM_VALUE(Family, TYPEWRITER);
91
92 SO_NODE_DEFINE_ENUM_VALUE(Style, NONE);
93 SO_NODE_DEFINE_ENUM_VALUE(Style, BOLD);
94 SO_NODE_DEFINE_ENUM_VALUE(Style, ITALIC);
95
96 // Set up info in enumerated type field
97 SO_NODE_SET_SF_ENUM_TYPE(family, Family);
98 SO_NODE_SET_SF_ENUM_TYPE(style, Style);
99
100 isBuiltIn = TRUE;
101 }
102
103 ////////////////////////////////////////////////////////////////////////
104 //
105 // Destructor
106 //
107 SoFontStyle::~SoFontStyle()
108 //
109 ////////////////////////////////////////////////////////////////////////
110 {
111 }
112
113 ////////////////////////////////////////////////////////////////////////
114 //
115 // Description:
116 // Gets the font name based on the family and style
117 //
118 // Use: protected
119
120 SbString
121 SoFontStyle::getFontName()
122 //
123 ////////////////////////////////////////////////////////////////////////
124 {
125 int f = family.getValue();
126 int s = style.getValue();
127
128 if (family.isIgnored()) f = SERIF;
129 if (style.isIgnored()) s = NONE;
130
131 if (f < 0 || f > 2) f = 0;
132 if (s < 0 || s > 3) s = 0;
133
134 return fontList[f][s];
135 }
136
137 ////////////////////////////////////////////////////////////////////////
138 //
139 // Description:
140 // Handles actions
141 //
142 // Use: extender
143
144 void
145 SoFontStyle::doAction(SoAction *action)
146 //
147 ////////////////////////////////////////////////////////////////////////
148 {
149 SoState *state = action->getState();
150
151 // set font to the given font style
152 if ((!family.isIgnored() || !style.isIgnored())
153 && !SoOverrideElement::getFontNameOverride(state)
154 ) {
155
156 SbString font = getFontName();
157
158 if (isOverride()) {
159 SoOverrideElement::setFontNameOverride(state, this, TRUE);
160 }
161 SoFontNameElement::set(state, this, font.getString());
162 }
163
164 if (! size.isIgnored()
165 && ! SoOverrideElement::getFontSizeOverride(state)
166 ) {
167 if (isOverride()) {
168 SoOverrideElement::setFontSizeOverride(state, this, TRUE);
169 }
170 SoFontSizeElement::set(state, this, size.getValue());
171 }
172 }
173
174 ////////////////////////////////////////////////////////////////////////
175 //
176 // Description:
177 // Does callback action thing.
178 //
179 // Use: extender
180
181 void
182 SoFontStyle::callback(SoCallbackAction *action)
183 //
184 ////////////////////////////////////////////////////////////////////////
185 {
186 SoFontStyle::doAction(action);
187 }
188
189 ////////////////////////////////////////////////////////////////////////
190 //
191 // Description:
192 // Does GL render action.
193 //
194 // Use: extender
195
196 void
197 SoFontStyle::GLRender(SoGLRenderAction *action)
198 //
199 ////////////////////////////////////////////////////////////////////////
200 {
201 SoFontStyle::doAction(action);
202 }
203
204 ////////////////////////////////////////////////////////////////////////
205 //
206 // Description:
207 // Does pick action...
208 //
209 // Use: extender
210
211 void
212 SoFontStyle::pick(SoPickAction *action)
213 //
214 ////////////////////////////////////////////////////////////////////////
215 {
216 SoFontStyle::doAction(action);
217 }
218
219 ////////////////////////////////////////////////////////////////////////
220 //
221 // Description:
222 // Does get bounding box action...
223 //
224 // Use: extender
225
226 void
227 SoFontStyle::getBoundingBox(SoGetBoundingBoxAction *action)
228 //
229 ////////////////////////////////////////////////////////////////////////
230 {
231 SoFontStyle::doAction(action);
232 }