Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtHelp / FontAttr.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: FontAttr.c /main/8 1996/01/29 12:19:57 cde-hp $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  **
27  **   File:     Font.c
28  **
29  **   Project:     Text Graphic Display Library
30  **
31  **   Description: Semi private format utility functions that do not
32  **                require the Display Area, Motif, Xt or X11.
33  **
34  **
35  **  (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
36  **
37  **  (c) Copyright 1993, 1994 Hewlett-Packard Company
38  **  (c) Copyright 1993, 1994 International Business Machines Corp.
39  **  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
40  **  (c) Copyright 1993, 1994 Novell, Inc.
41  **
42  **
43  ****************************************************************************
44  ************************************<+>*************************************/
45 /*
46  * system includes
47  */
48 #include <string.h>
49
50 /*
51  * private includes
52  */
53 #include "FontAttrI.h"
54
55 #ifdef NLS16
56 #endif
57
58 /********    Private Function Declarations    ********/
59 /********    End Public Function Declarations    ********/
60
61 /******************************************************************************
62  *
63  * Private variables and defines.
64  *
65  *****************************************************************************/
66 #ifndef NULL
67 #define NULL    0
68 #endif
69
70 static  _DtHelpFontHints        DefaultFontAttrs =
71   {
72         "C",
73         "ISO-8859-1",
74         10, 0,                          /* pointsz, setsize */
75           NULL,                                 /* color            */
76           NULL, NULL, NULL, NULL,               /* xlfd strings     */
77           NULL, NULL, NULL, NULL,               /* MS-Win strings   */
78         _DtHelpFontStyleSanSerif,
79         _DtHelpFontSpacingProp  ,
80         _DtHelpFontWeightMedium ,
81         _DtHelpFontSlantRoman   ,
82         _DtHelpFontSpecialNone  ,
83         NULL
84   };
85
86 /******************************************************************************
87  *
88  * Private Functions
89  *
90  *****************************************************************************/
91 static int
92 HintDuplicate(char **string)
93 {
94     if (NULL != *string)
95       {
96         *string = strdup(*string);
97         if (NULL == *string)
98             return -1;
99       }
100
101     return 0;
102 }
103
104 /******************************************************************************
105  *
106  * Semi Public Functions
107  *
108  *****************************************************************************/
109 /******************************************************************************
110  * Function:    void _DtHelpCeCopyDefFontAttrList (char **font_attr)
111  *
112  * Parameters:  font_attr       Specifies the font attribute list
113  *
114  * Return Value: void
115  *
116  * Purpose:     Initialize a font attribute list to the default.
117  *              Sets '_DtMB_LEN_MAX' to the default character size.
118  *
119  *****************************************************************************/
120 void
121 _DtHelpCeCopyDefFontAttrList (_DtHelpFontHints *font_attr )
122 {
123     *font_attr = DefaultFontAttrs;
124 }
125
126 /******************************************************************************
127  * Function:    void _DtHelpFreeFontHints (
128  *
129  * Parameters:  font_hints      Specifies the font hint structure
130  *
131  * Return Value: void
132  *
133  * Purpose:     frees the strings in the font structure.
134  *
135  *****************************************************************************/
136 void
137 _DtHelpFreeFontHints (_DtHelpFontHints *font_hints )
138 {
139     /*
140      * do the language and charset
141      */
142     if (NULL != font_hints->language)
143         free(font_hints->language);
144     if (NULL != font_hints->char_set)
145         free(font_hints->char_set);
146
147     /*
148      * do the color
149      */
150     if (NULL != font_hints->color)
151         free(font_hints->color);
152
153     /*
154      * do the xlfd fonts
155      */
156     if (NULL != font_hints->xlfd)
157         free(font_hints->xlfd);
158     if (NULL != font_hints->xlfdb)
159         free(font_hints->xlfdb);
160     if (NULL != font_hints->xlfdi)
161         free(font_hints->xlfdi);
162     if (NULL != font_hints->xlfdib)
163         free(font_hints->xlfdib);
164
165     /*
166      * do the ms-windows fonts
167      */
168     if (NULL != font_hints->typenam)
169         free(font_hints->typenam);
170     if (NULL != font_hints->typenamb)
171         free(font_hints->typenamb);
172     if (NULL != font_hints->typenami)
173         free(font_hints->typenami);
174     if (NULL != font_hints->typenamib)
175         free(font_hints->typenamib);
176 }
177
178 /******************************************************************************
179  * Function:    void _DtHelpDupFontHints (
180  *
181  * Parameters:  font_hints      Specifies the font hint structure
182  *
183  * Return Value: 0 for successful, -1 if failures.
184  *
185  * Purpose:     to the dup the strings in the font hint structure.
186  *
187  *****************************************************************************/
188 int
189 _DtHelpDupFontHints (_DtHelpFontHints *font_hints )
190 {
191     int result = 0;
192
193     /*
194      * do the language and charset
195      */
196     if (-1 == HintDuplicate(&(font_hints->language)))
197         result = -1;
198     if (-1 == HintDuplicate(&(font_hints->char_set)))
199         result = -1;
200
201     /*
202      * do the color
203      */
204     if (-1 == HintDuplicate(&(font_hints->color)))
205         result = -1;
206
207     /*
208      * do the xlfd fonts
209      */
210     if (-1 == HintDuplicate(&(font_hints->xlfd)))
211         result = -1;
212     if (-1 == HintDuplicate(&(font_hints->xlfdb)))
213         result = -1;
214     if (-1 == HintDuplicate(&(font_hints->xlfdi)))
215         result = -1;
216     if (-1 == HintDuplicate(&(font_hints->xlfdib)))
217         result = -1;
218
219     /*
220      * do the ms-windows fonts
221      */
222     if (-1 == HintDuplicate(&(font_hints->typenam)))
223         result = -1;
224     if (-1 == HintDuplicate(&(font_hints->typenamb)))
225         result = -1;
226     if (-1 == HintDuplicate(&(font_hints->typenami)))
227         result = -1;
228     if (-1 == HintDuplicate(&(font_hints->typenamib)))
229         result = -1;
230
231     if (-1 == result)
232         _DtHelpFreeFontHints(font_hints);
233
234     return result;
235 }