FontAttr.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 libraries 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. #include <stdlib.h>
  50. /*
  51. * private includes
  52. */
  53. #include "FontAttrI.h"
  54. #ifdef NLS16
  55. #endif
  56. /******** Private Function Declarations ********/
  57. /******** End Public Function Declarations ********/
  58. /******************************************************************************
  59. *
  60. * Private variables and defines.
  61. *
  62. *****************************************************************************/
  63. #ifndef NULL
  64. #define NULL 0
  65. #endif
  66. static _DtHelpFontHints DefaultFontAttrs =
  67. {
  68. "C",
  69. "ISO-8859-1",
  70. 10, 0, /* pointsz, setsize */
  71. NULL, /* color */
  72. NULL, NULL, NULL, NULL, /* xlfd strings */
  73. NULL, NULL, NULL, NULL, /* MS-Win strings */
  74. _DtHelpFontStyleSanSerif,
  75. _DtHelpFontSpacingProp ,
  76. _DtHelpFontWeightMedium ,
  77. _DtHelpFontSlantRoman ,
  78. _DtHelpFontSpecialNone ,
  79. NULL
  80. };
  81. /******************************************************************************
  82. *
  83. * Private Functions
  84. *
  85. *****************************************************************************/
  86. static int
  87. HintDuplicate(char **string)
  88. {
  89. if (NULL != *string)
  90. {
  91. *string = strdup(*string);
  92. if (NULL == *string)
  93. return -1;
  94. }
  95. return 0;
  96. }
  97. /******************************************************************************
  98. *
  99. * Semi Public Functions
  100. *
  101. *****************************************************************************/
  102. /******************************************************************************
  103. * Function: void _DtHelpCeCopyDefFontAttrList (char **font_attr)
  104. *
  105. * Parameters: font_attr Specifies the font attribute list
  106. *
  107. * Return Value: void
  108. *
  109. * Purpose: Initialize a font attribute list to the default.
  110. * Sets '_DtMB_LEN_MAX' to the default character size.
  111. *
  112. *****************************************************************************/
  113. void
  114. _DtHelpCeCopyDefFontAttrList (_DtHelpFontHints *font_attr )
  115. {
  116. *font_attr = DefaultFontAttrs;
  117. }
  118. /******************************************************************************
  119. * Function: void _DtHelpFreeFontHints (
  120. *
  121. * Parameters: font_hints Specifies the font hint structure
  122. *
  123. * Return Value: void
  124. *
  125. * Purpose: frees the strings in the font structure.
  126. *
  127. *****************************************************************************/
  128. void
  129. _DtHelpFreeFontHints (_DtHelpFontHints *font_hints )
  130. {
  131. /*
  132. * do the language and charset
  133. */
  134. if (NULL != font_hints->language)
  135. free(font_hints->language);
  136. if (NULL != font_hints->char_set)
  137. free(font_hints->char_set);
  138. /*
  139. * do the color
  140. */
  141. if (NULL != font_hints->color)
  142. free(font_hints->color);
  143. /*
  144. * do the xlfd fonts
  145. */
  146. if (NULL != font_hints->xlfd)
  147. free(font_hints->xlfd);
  148. if (NULL != font_hints->xlfdb)
  149. free(font_hints->xlfdb);
  150. if (NULL != font_hints->xlfdi)
  151. free(font_hints->xlfdi);
  152. if (NULL != font_hints->xlfdib)
  153. free(font_hints->xlfdib);
  154. /*
  155. * do the ms-windows fonts
  156. */
  157. if (NULL != font_hints->typenam)
  158. free(font_hints->typenam);
  159. if (NULL != font_hints->typenamb)
  160. free(font_hints->typenamb);
  161. if (NULL != font_hints->typenami)
  162. free(font_hints->typenami);
  163. if (NULL != font_hints->typenamib)
  164. free(font_hints->typenamib);
  165. }
  166. /******************************************************************************
  167. * Function: void _DtHelpDupFontHints (
  168. *
  169. * Parameters: font_hints Specifies the font hint structure
  170. *
  171. * Return Value: 0 for successful, -1 if failures.
  172. *
  173. * Purpose: to the dup the strings in the font hint structure.
  174. *
  175. *****************************************************************************/
  176. int
  177. _DtHelpDupFontHints (_DtHelpFontHints *font_hints )
  178. {
  179. int result = 0;
  180. /*
  181. * do the language and charset
  182. */
  183. if (-1 == HintDuplicate(&(font_hints->language)))
  184. result = -1;
  185. if (-1 == HintDuplicate(&(font_hints->char_set)))
  186. result = -1;
  187. /*
  188. * do the color
  189. */
  190. if (-1 == HintDuplicate(&(font_hints->color)))
  191. result = -1;
  192. /*
  193. * do the xlfd fonts
  194. */
  195. if (-1 == HintDuplicate(&(font_hints->xlfd)))
  196. result = -1;
  197. if (-1 == HintDuplicate(&(font_hints->xlfdb)))
  198. result = -1;
  199. if (-1 == HintDuplicate(&(font_hints->xlfdi)))
  200. result = -1;
  201. if (-1 == HintDuplicate(&(font_hints->xlfdib)))
  202. result = -1;
  203. /*
  204. * do the ms-windows fonts
  205. */
  206. if (-1 == HintDuplicate(&(font_hints->typenam)))
  207. result = -1;
  208. if (-1 == HintDuplicate(&(font_hints->typenamb)))
  209. result = -1;
  210. if (-1 == HintDuplicate(&(font_hints->typenami)))
  211. result = -1;
  212. if (-1 == HintDuplicate(&(font_hints->typenamib)))
  213. result = -1;
  214. if (-1 == result)
  215. _DtHelpFreeFontHints(font_hints);
  216. return result;
  217. }