2
0

Font.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  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: Font.c /main/11 1996/04/13 11:54:17 ageorge $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
  28. **
  29. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  30. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  31. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  32. ** (c) Copyright 1993, 1994 Novell, Inc.
  33. **
  34. ****************************************************************************
  35. ************************************<+>*************************************/
  36. /*
  37. * system includes
  38. */
  39. #include <stdlib.h>
  40. #include <X11/Xlib.h>
  41. #include <X11/Xlibint.h>
  42. #include <X11/Xresource.h>
  43. #include <Xm/Xm.h>
  44. /*
  45. * private includes
  46. */
  47. #include "DisplayAreaP.h"
  48. #include "FontI.h"
  49. #include "Lock.h"
  50. /*
  51. * private core engine
  52. */
  53. #include "StringFuncsI.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. static const char *FontResources[] =
  64. {
  65. /*! The serif proportional family */
  66. /*! medium upright */
  67. "*p.6.roman.medium.serif.*.ISO-8859-1: -dt-application-medium-r-normal-serif-*-80-*-*-p-*-iso8859-1",
  68. "*p.8.roman.medium.serif.*.ISO-8859-1: -dt-application-medium-r-normal-serif-*-100-*-*-p-*-iso8859-1",
  69. "*p.10.roman.medium.serif.*.ISO-8859-1: -dt-application-medium-r-normal-serif-*-120-*-*-p-*-iso8859-1",
  70. "*p.12.roman.medium.serif.*.ISO-8859-1: -dt-application-medium-r-normal-serif-*-140-*-*-p-*-iso8859-1",
  71. "*p.14.roman.medium.serif.*.ISO-8859-1: -dt-application-medium-r-normal-serif-*-180-*-*-p-*-iso8859-1",
  72. /*! bold upright */
  73. "*p.6.roman.bold.serif.*.ISO-8859-1: -dt-application-bold-r-normal-serif-*-80-*-*-p-*-iso8859-1",
  74. "*p.8.roman.bold.serif.*.ISO-8859-1: -dt-application-bold-r-normal-serif-*-100-*-*-p-*-iso8859-1",
  75. "*p.10.roman.bold.serif.*.ISO-8859-1: -dt-application-bold-r-normal-serif-*-120-*-*-p-*-iso8859-1",
  76. "*p.12.roman.bold.serif.*.ISO-8859-1: -dt-application-bold-r-normal-serif-*-140-*-*-p-*-iso8859-1",
  77. "*p.14.roman.bold.serif.*.ISO-8859-1: -dt-application-bold-r-normal-serif-*-180-*-*-p-*-iso8859-1",
  78. /*! medium italic */
  79. "*p.6.italic.medium.serif.*.ISO-8859-1: -dt-application-medium-i-normal-serif-*-80-*-*-p-*-iso8859-1",
  80. "*p.8.italic.medium.serif.*.ISO-8859-1: -dt-application-medium-i-normal-serif-*-100-*-*-p-*-iso8859-1",
  81. "*p.10.italic.medium.serif.*.ISO-8859-1: -dt-application-medium-i-normal-serif-*-120-*-*-p-*-iso8859-1",
  82. "*p.12.italic.medium.serif.*.ISO-8859-1: -dt-application-medium-i-normal-serif-*-140-*-*-p-*-iso8859-1",
  83. "*p.14.italic.medium.serif.*.ISO-8859-1: -dt-application-medium-i-normal-serif-*-180-*-*-p-*-iso8859-1",
  84. /*! bold italic */
  85. "*p.6.italic.bold.serif.*.ISO-8859-1: -dt-application-bold-i-normal-serif-*-80-*-*-p-*-iso8859-1",
  86. "*p.8.italic.bold.serif.*.ISO-8859-1: -dt-application-bold-i-normal-serif-*-100-*-*-p-*-iso8859-1",
  87. "*p.10.italic.bold.serif.*.ISO-8859-1: -dt-application-bold-i-normal-serif-*-120-*-*-p-*-iso8859-1",
  88. "*p.12.italic.bold.serif.*.ISO-8859-1: -dt-application-bold-i-normal-serif-*-140-*-*-p-*-iso8859-1",
  89. "*p.14.italic.bold.serif.*.ISO-8859-1: -dt-application-bold-i-normal-serif-*-180-*-*-p-*-iso8859-1",
  90. /*! The sans serif proportional family */
  91. /*! medium upright */
  92. "*p.6.roman.medium.sans_serif.*.ISO-8859-1: -dt-application-medium-r-normal-sans-*-80-*-*-p-*-iso8859-1",
  93. "*p.8.roman.medium.sans_serif.*.ISO-8859-1: -dt-application-medium-r-normal-sans-*-100-*-*-p-*-iso8859-1",
  94. "*p.10.roman.medium.sans_serif.*.ISO-8859-1: -dt-application-medium-r-normal-sans-*-120-*-*-p-*-iso8859-1",
  95. "*p.12.roman.medium.sans_serif.*.ISO-8859-1: -dt-application-medium-r-normal-sans-*-140-*-*-p-*-iso8859-1",
  96. "*p.14.roman.medium.sans_serif.*.ISO-8859-1: -dt-application-medium-r-normal-sans-*-180-*-*-p-*-iso8859-1",
  97. /*!bold upright */
  98. "*p.6.roman.bold.sans_serif.*.ISO-8859-1: -dt-application-bold-r-normal-sans-*-80-*-*-p-*-iso8859-1",
  99. "*p.8.roman.bold.sans_serif.*.ISO-8859-1: -dt-application-bold-r-normal-sans-*-100-*-*-p-*-iso8859-1",
  100. "*p.10.roman.bold.sans_serif.*.ISO-8859-1: -dt-application-bold-r-normal-sans-*-120-*-*-p-*-iso8859-1",
  101. "*p.12.roman.bold.sans_serif.*.ISO-8859-1: -dt-application-bold-r-normal-sans-*-140-*-*-p-*-iso8859-1",
  102. "*p.14.roman.bold.sans_serif.*.ISO-8859-1: -dt-application-bold-r-normal-sans-*-180-*-*-p-*-iso8859-1",
  103. /*! medium italic */
  104. "*p.6.italic.medium.sans_serif.*.ISO-8859-1: -dt-application-medium-i-normal-sans-*-80-*-*-p-*-iso8859-1",
  105. "*p.8.italic.medium.sans_serif.*.ISO-8859-1: -dt-application-medium-i-normal-sans-*-100-*-*-p-*-iso8859-1",
  106. "*p.10.italic.medium.sans_serif.*.ISO-8859-1: -dt-application-medium-i-normal-sans-*-120-*-*-p-*-iso8859-1",
  107. "*p.12.italic.medium.sans_serif.*.ISO-8859-1: -dt-application-medium-i-normal-sans-*-140-*-*-p-*-iso8859-1",
  108. "*p.14.italic.medium.sans_serif.*.ISO-8859-1: -dt-application-medium-i-normal-sans-*-180-*-*-p-*-iso8859-1",
  109. /*! bold italic */
  110. "*p.6.italic.bold.sans_serif.*.ISO-8859-1: -dt-application-bold-i-normal-sans-*-80-*-*-p-*-iso8859-1",
  111. "*p.8.italic.bold.sans_serif.*.ISO-8859-1: -dt-application-bold-i-normal-sans-*-100-*-*-p-*-iso8859-1",
  112. "*p.10.italic.bold.sans_serif.*.ISO-8859-1: -dt-application-bold-i-normal-sans-*-120-*-*-p-*-iso8859-1",
  113. "*p.12.italic.bold.sans_serif.*.ISO-8859-1: -dt-application-bold-i-normal-sans-*-140-*-*-p-*-iso8859-1",
  114. "*p.14.italic.bold.sans_serif.*.ISO-8859-1: -dt-application-bold-i-normal-sans-*-180-*-*-p-*-iso8859-1",
  115. /*! The monospace family - lump serif & sans serif together */
  116. /*! medium upright */
  117. "*m.6.roman.medium.*.*.ISO-8859-1: -dt-application-medium-r-normal-*-*-80-*-*-m-*-iso8859-1",
  118. "*m.8.roman.medium.*.*.ISO-8859-1: -dt-application-medium-r-normal-*-*-100-*-*-m-*-iso8859-1",
  119. "*m.10.roman.medium.*.*.ISO-8859-1: -dt-application-medium-r-normal-*-*-120-*-*-m-*-iso8859-1",
  120. "*m.12.roman.medium.*.*.ISO-8859-1: -dt-application-medium-r-normal-*-*-140-*-*-m-*-iso8859-1",
  121. "*m.14.roman.medium.*.*.ISO-8859-1: -dt-application-medium-r-normal-*-*-180-*-*-m-*-iso8859-1",
  122. /*! bold upright */
  123. "*m.6.roman.bold.*.*.ISO-8859-1: -dt-application-bold-r-normal-*-*-80-*-*-m-*-iso8859-1",
  124. "*m.8.roman.bold.*.*.ISO-8859-1: -dt-application-bold-r-normal-*-*-100-*-*-m-*-iso8859-1",
  125. "*m.10.roman.bold.*.*.ISO-8859-1: -dt-application-bold-r-normal-*-*-120-*-*-m-*-iso8859-1",
  126. "*m.12.roman.bold.*.*.ISO-8859-1: -dt-application-bold-r-normal-*-*-140-*-*-m-*-iso8859-1",
  127. "*m.14.roman.bold.*.*.ISO-8859-1: -dt-application-bold-r-normal-*-*-180-*-*-m-*-iso8859-1",
  128. /*! medium italic */
  129. "*m.6.italic.medium.*.*.ISO-8859-1: -dt-application-medium-i-normal-*-*-80-*-*-m-*-iso8859-1",
  130. "*m.8.italic.medium.*.*.ISO-8859-1: -dt-application-medium-i-normal-*-*-100-*-*-m-*-iso8859-1",
  131. "*m.10.italic.medium.*.*.ISO-8859-1: -dt-application-medium-i-normal-*-*-120-*-*-m-*-iso8859-1",
  132. "*m.12.italic.medium.*.*.ISO-8859-1: -dt-application-medium-i-normal-*-*-140-*-*-m-*-iso8859-1",
  133. "*m.14.italic.medium.*.*.ISO-8859-1: -dt-application-medium-i-normal-*-*-180-*-*-m-*-iso8859-1",
  134. /*! bold italic */
  135. "*m.6.italic.bold.*.*.ISO-8859-1: -dt-application-bold-i-normal-*-*-80-*-*-m-*-iso8859-1",
  136. "*m.8.italic.bold.*.*.ISO-8859-1: -dt-application-bold-i-normal-*-*-100-*-*-m-*-iso8859-1",
  137. "*m.10.italic.bold.*.*.ISO-8859-1: -dt-application-bold-i-normal-*-*-120-*-*-m-*-iso8859-1",
  138. "*m.12.italic.bold.*.*.ISO-8859-1: -dt-application-bold-i-normal-*-*-140-*-*-m-*-iso8859-1",
  139. "*m.14.italic.bold.*.*.ISO-8859-1: -dt-application-bold-i-normal-*-*-180-*-*-m-*-iso8859-1",
  140. /*! SYMBOL */
  141. "*6.*.*.*.*.DT-SYMBOL-1: -dt-application-medium-r-normal-*-*-80-*-*-*-*-dtsymbol-1",
  142. "*8.*.*.*.*.DT-SYMBOL-1: -dt-application-medium-r-normal-*-*-100-*-*-*-*-dtsymbol-1",
  143. "*10.*.*.*.*.DT-SYMBOL-1: -dt-application-medium-r-normal-*-*-120-*-*-*-*-dtsymbol-1",
  144. "*12.*.*.*.*.DT-SYMBOL-1: -dt-application-medium-r-normal-*-*-140-*-*-*-*-dtsymbol-1",
  145. "*14.*.*.*.*.DT-SYMBOL-1: -dt-application-medium-r-normal-*-*-180-*-*-*-*-dtsymbol-1",
  146. /* for ISO-8859-2 */
  147. "*.6.*.*.*.*.ISO-8859-2: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  148. "*.8.*.*.*.*.ISO-8859-2: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  149. "*.10.*.*.*.*.ISO-8859-2: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  150. "*.12.*.*.*.*.ISO-8859-2: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  151. "*.14.*.*.*.*.ISO-8859-2: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  152. /* for ISO-8859-5 */
  153. "*.6.*.*.*.*.ISO-8859-5: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  154. "*.8.*.*.*.*.ISO-8859-5: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  155. "*.10.*.*.*.*.ISO-8859-5: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  156. "*.12.*.*.*.*.ISO-8859-5: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  157. "*.14.*.*.*.*.ISO-8859-5: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  158. /* for ISO-8859-6 */
  159. "*.6.*.*.*.*.ISO-8859-6: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  160. "*.8.*.*.*.*.ISO-8859-6: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  161. "*.10.*.*.*.*.ISO-8859-6: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  162. "*.12.*.*.*.*.ISO-8859-6: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  163. "*.14.*.*.*.*.ISO-8859-6: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  164. /* for ISO-8859-7 */
  165. "*.6.*.*.*.*.ISO-8859-7: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  166. "*.8.*.*.*.*.ISO-8859-7: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  167. "*.10.*.*.*.*.ISO-8859-7: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  168. "*.12.*.*.*.*.ISO-8859-7: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  169. "*.14.*.*.*.*.ISO-8859-7: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  170. /* for ISO-8859-8 */
  171. "*.6.*.*.*.*.ISO-8859-8: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  172. "*.8.*.*.*.*.ISO-8859-8: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  173. "*.10.*.*.*.*.ISO-8859-8: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  174. "*.12.*.*.*.*.ISO-8859-8: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  175. "*.14.*.*.*.*.ISO-8859-8: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  176. /* for ISO-8859-9 */
  177. "*.6.*.*.*.*.ISO-8859-9: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  178. "*.8.*.*.*.*.ISO-8859-9: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  179. "*.10.*.*.*.*.ISO-8859-9: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  180. "*.12.*.*.*.*.ISO-8859-9: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  181. "*.14.*.*.*.*.ISO-8859-9: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  182. /* for EUC-KR */
  183. "*.6.*.*.*.*.EUC-KR: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  184. "*.8.*.*.*.*.EUC-KR: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  185. "*.10.*.*.*.*.EUC-KR: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  186. "*.12.*.*.*.*.EUC-KR: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  187. "*.14.*.*.*.*.EUC-KR: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  188. /* for EUC-JP */
  189. "*.6.*.*.*.*.EUC-JP: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  190. "*.8.*.*.*.*.EUC-JP: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  191. "*.10.*.*.*.*.EUC-JP: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  192. "*.12.*.*.*.*.EUC-JP: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  193. "*.14.*.*.*.*.EUC-JP: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  194. /* for EUC-TW */
  195. "*.6.*.*.*.*.EUC-TW: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  196. "*.8.*.*.*.*.EUC-TW: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  197. "*.10.*.*.*.*.EUC-TW: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  198. "*.12.*.*.*.*.EUC-TW: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  199. "*.14.*.*.*.*.EUC-TW: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  200. /* for EUC-CN */
  201. "*.6.*.*.*.*.EUC-CN: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  202. "*.8.*.*.*.*.EUC-CN: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  203. "*.10.*.*.*.*.EUC-CN: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  204. "*.12.*.*.*.*.EUC-CN: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  205. "*.14.*.*.*.*.EUC-CN: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  206. /* for IBM-437 */
  207. "*.6.*.*.*.*.IBM-437: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  208. "*.8.*.*.*.*.IBM-437: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  209. "*.10.*.*.*.*.IBM-437: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  210. "*.12.*.*.*.*.IBM-437: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  211. "*.14.*.*.*.*.IBM-437: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  212. /* for IBM-850 */
  213. "*.6.*.*.*.*.IBM-850: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  214. "*.8.*.*.*.*.IBM-850: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  215. "*.10.*.*.*.*.IBM-850: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  216. "*.12.*.*.*.*.IBM-850: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  217. "*.14.*.*.*.*.IBM-850: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  218. /* for IBM-856 */
  219. "*.6.*.*.*.*.IBM-856: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  220. "*.8.*.*.*.*.IBM-856: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  221. "*.10.*.*.*.*.IBM-856: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  222. "*.12.*.*.*.*.IBM-856: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  223. "*.14.*.*.*.*.IBM-856: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  224. /* for IBM-932 */
  225. "*.6.*.*.*.*.IBM-932: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  226. "*.8.*.*.*.*.IBM-932: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  227. "*.10.*.*.*.*.IBM-932: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  228. "*.12.*.*.*.*.IBM-932: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  229. "*.14.*.*.*.*.IBM-932: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  230. /* for IBM-1046 */
  231. "*.6.*.*.*.*.IBM-1046: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  232. "*.8.*.*.*.*.IBM-1046: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  233. "*.10.*.*.*.*.IBM-1046: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  234. "*.12.*.*.*.*.IBM-1046: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  235. "*.14.*.*.*.*.IBM-1046: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  236. /* for UTF-8 */
  237. "*.6.*.*.*.*.UTF-8: -dt-interface user-medium-r-normal-xs*-*-*-*-*-*-*-*-*:",
  238. "*.8.*.*.*.*.UTF-8: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*:",
  239. "*.10.*.*.*.*.UTF-8: -dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*:",
  240. "*.12.*.*.*.*.UTF-8: -dt-interface user-medium-r-normal-l*-*-*-*-*-*-*-*-*:",
  241. "*.14.*.*.*.*.UTF-8: -dt-interface user-medium-r-normal-xl*-*-*-*-*-*-*-*-*:",
  242. NULL,
  243. };
  244. #define GROW_SIZE 5
  245. static Boolean QuarksInited = FALSE;
  246. static XrmQuark StringFontQuark = 0;
  247. static XrmName DefaultFontQuarks[_DtHelpFontQuarkNumber];
  248. static XrmName CasualFontQuarks[_DtHelpFontQuarkNumber];
  249. static XrmBinding FontBindings[_DtHelpFontQuarkNumber] =
  250. { XrmBindLoosely, XrmBindLoosely, XrmBindLoosely, XrmBindLoosely,
  251. XrmBindLoosely, XrmBindLoosely, XrmBindLoosely };
  252. static DtHelpDAFSMetrics DefaultMetrics = { FALSE, { 0, 0 } };
  253. static DtHelpDAFontInfo DefFontInfo = { NULL, NULL, NULL, NULL, NULL,
  254. NULL, 0, NULL, 0, 0, 0, 0, 0};
  255. /******************************************************************************
  256. *
  257. * Semi Public variables.
  258. *
  259. *****************************************************************************/
  260. /******************************************************************************
  261. *
  262. * Private Functions
  263. *
  264. *****************************************************************************/
  265. /******************************************************************************
  266. * Function: SaveFontStruct (font_struct)
  267. *
  268. *****************************************************************************/
  269. static int
  270. SaveFontStruct (
  271. XFontStruct *font_struct,
  272. DtHelpDAFontInfo *font_info)
  273. {
  274. int fontIndex;
  275. fontIndex = font_info->struct_cnt++;
  276. if (font_info->struct_cnt >= font_info->max_structs)
  277. {
  278. font_info->max_structs += GROW_SIZE;
  279. if (font_info->font_structs != NULL)
  280. font_info->font_structs = (XFontStruct **) realloc (
  281. ((char *) font_info->font_structs),
  282. (sizeof (XFontStruct *) * font_info->max_structs));
  283. else
  284. font_info->font_structs = (XFontStruct **) malloc (
  285. sizeof (XFontStruct *) * font_info->max_structs);
  286. }
  287. font_info->font_structs[fontIndex] = font_struct;
  288. return (fontIndex);
  289. }
  290. /******************************************************************************
  291. * Function: SaveFontSet (font_set)
  292. *
  293. *****************************************************************************/
  294. static int
  295. SaveFontSet (
  296. XFontSet font_set,
  297. DtHelpDAFontInfo *font_info)
  298. {
  299. int fontIndex = 0;
  300. fontIndex = font_info->set_cnt++;
  301. if (font_info->set_cnt >= font_info->max_sets)
  302. {
  303. font_info->max_sets += GROW_SIZE;
  304. if (font_info->font_sets != NULL)
  305. {
  306. font_info->font_sets = (XFontSet *) realloc (
  307. ((char *) font_info->font_sets),
  308. (sizeof (XFontSet) * font_info->max_sets));
  309. font_info->fs_metrics = (DtHelpDAFSMetrics *) realloc (
  310. ((char *) font_info->fs_metrics),
  311. (sizeof (DtHelpDAFSMetrics) * font_info->max_sets));
  312. }
  313. else
  314. {
  315. font_info->font_sets = (XFontSet *) malloc (
  316. sizeof(XFontSet) * font_info->max_sets);
  317. font_info->fs_metrics = (DtHelpDAFSMetrics *) malloc (
  318. sizeof (DtHelpDAFSMetrics) * font_info->max_sets);
  319. }
  320. }
  321. font_info->font_sets[fontIndex] = font_set;
  322. font_info->fs_metrics[fontIndex] = DefaultMetrics;
  323. /*
  324. * want the font sets to go from -1 to -n because negative numbers
  325. * indicate a font set.
  326. */
  327. fontIndex++;
  328. return (-fontIndex);
  329. }
  330. /******************************************************************************
  331. * Function: LoadFont (char *font_string, int *ret_index)
  332. *
  333. *****************************************************************************/
  334. static short
  335. LoadFont (
  336. Display *dpy,
  337. DtHelpDAFontInfo *font_info,
  338. char *font_string,
  339. long *ret_index)
  340. {
  341. short found = False;
  342. short colon = False;
  343. int len;
  344. char *junk;
  345. char *strPtr;
  346. char **missingFontSet = NULL;
  347. XFontStruct *fontStruct = NULL;
  348. XFontSet fontSet;
  349. strPtr = font_string;
  350. /*
  351. * if working with one byte environment, do it the fast, cheap way.
  352. */
  353. if (MB_CUR_MAX == 1)
  354. {
  355. len = strlen(strPtr);
  356. if (len > 0)
  357. len--;
  358. while (len > 0 && strPtr[len] == ' ')
  359. len--;
  360. if (strPtr[len] == ':')
  361. {
  362. colon = True;
  363. junk = strPtr + len;
  364. }
  365. }
  366. else
  367. {
  368. /*
  369. * Multibyte environment, have to go through the characters one at
  370. * a time.
  371. */
  372. while (*strPtr != '\0')
  373. {
  374. /*
  375. * Process looking for a colon.
  376. */
  377. len = mblen(strPtr, MB_CUR_MAX);
  378. if (len == -1)
  379. len = 1;
  380. else if (len == 1 && *strPtr == ':')
  381. {
  382. colon = True;
  383. junk = strPtr;
  384. }
  385. else if (len != 1 || *strPtr != ' ')
  386. colon = False;
  387. strPtr += len;
  388. }
  389. }
  390. if (colon == False)
  391. {
  392. fontStruct = XLoadQueryFont (dpy, font_string);
  393. if (fontStruct != NULL)
  394. {
  395. *ret_index = SaveFontStruct (fontStruct, font_info);
  396. found = True;
  397. }
  398. }
  399. else
  400. {
  401. *junk = '\0';
  402. fontSet = XCreateFontSet (dpy, font_string, &missingFontSet,
  403. &len, NULL);
  404. if (fontSet != NULL)
  405. {
  406. /*
  407. * want the font sets to go from -1 to -n because 0 is
  408. * the default font.
  409. */
  410. *ret_index = SaveFontSet (fontSet, font_info);
  411. found = True;
  412. }
  413. if (len)
  414. XFreeStringList (missingFontSet);
  415. /*
  416. * restore colon
  417. */
  418. *junk = ':';
  419. }
  420. return found;
  421. }
  422. /******************************************************************************
  423. *
  424. * Semi Public Functions
  425. *
  426. *****************************************************************************/
  427. /******************************************************************************
  428. * Function: int __DtHelpFontIndexGet (Display dpy, XrmQuarkList xrm_list)
  429. *
  430. * Parameters: xrm_list Specifies the quark list for the font desired.
  431. *
  432. * Return Value: 0 if successful, -1 if using default font index.
  433. *
  434. * Purpose: Find the appropriate font to use for a quark set.
  435. *
  436. *****************************************************************************/
  437. int
  438. __DtHelpFontIndexGet (
  439. DtHelpDispAreaStruct *pDAS,
  440. XrmQuarkList xrm_list,
  441. long *ret_idx)
  442. {
  443. int result = -1;
  444. long fontIndex = pDAS->font_info.def_idx;
  445. XrmRepresentation retType;
  446. XrmValue retValue;
  447. char buffer[10];
  448. char *fontSpec;
  449. XrmName xrmList[3];
  450. DtHelpDAFontInfo *fontInfo = &(pDAS->font_info);
  451. Display *dpy = XtDisplay(pDAS->dispWid);
  452. /*
  453. * look in my font data base to see if I've already processed
  454. * this sequence of quarks.
  455. */
  456. if (XrmQGetResource (fontInfo->font_idx_db, xrm_list, xrm_list, &retType,
  457. &retValue))
  458. {
  459. fontIndex = *((int *)retValue.addr);
  460. result = 0;
  461. }
  462. else
  463. {
  464. /*
  465. * Check my parent's data base for an XLFD spec.
  466. */
  467. fontSpec = NULL;
  468. if (XrmQGetResource (XrmGetDatabase(dpy), xrm_list, xrm_list,
  469. &retType, &retValue))
  470. {
  471. fontSpec = ((char *) retValue.addr);
  472. if (LoadFont (dpy, fontInfo, fontSpec, &fontIndex))
  473. result = 0;
  474. }
  475. /*
  476. * If my parent didn't have anything, check my private database.
  477. */
  478. if (result != 0 &&
  479. XrmQGetResource (fontInfo->def_font_db, xrm_list, xrm_list,
  480. &retType, &retValue))
  481. {
  482. fontSpec = ((char *) retValue.addr);
  483. if (LoadFont (dpy, fontInfo, fontSpec, &fontIndex))
  484. result = 0;
  485. }
  486. /*
  487. * if unsuccessful on finding a font for this quark list.
  488. * save out using the default font
  489. */
  490. retValue.size = sizeof (int);
  491. retValue.addr = (XtPointer) &fontIndex;
  492. XrmQPutResource (&(fontInfo->font_idx_db),
  493. ((XrmBindingList) FontBindings),
  494. xrm_list, _DtHelpXrmInt, &retValue);
  495. /*
  496. * remember the character set for this font.
  497. */
  498. sprintf (buffer, "%ld", fontIndex);
  499. retValue.size = sizeof (XrmQuark);
  500. retValue.addr = (XtPointer) &xrm_list[_DT_HELP_FONT_CHAR_SET];
  501. xrmList[0] = XrmStringToQuark (buffer);
  502. xrmList[1] = XrmStringToQuark ("code_set");
  503. xrmList[2] = 0;
  504. XrmQPutResource (&(fontInfo->font_idx_db),
  505. ((XrmBindingList) FontBindings),
  506. xrmList, _DtHelpXrmQuark, &retValue);
  507. /*
  508. * remember the language for this font.
  509. */
  510. retValue.addr = (XtPointer) &xrm_list[_DT_HELP_FONT_LANG_TER];
  511. xrmList[1] = XrmStringToQuark ("language");
  512. XrmQPutResource (&(fontInfo->font_idx_db),
  513. ((XrmBindingList) FontBindings),
  514. xrmList, _DtHelpXrmQuark, &retValue);
  515. }
  516. *ret_idx = fontIndex;
  517. return result;
  518. }
  519. /******************************************************************************
  520. * Function: int __DtHelpFontCharSetQuarkGet (font_index, XrmQuark *ret_quark)
  521. *
  522. * Parameters: font_index Specifies the font in the font table.
  523. * ret_quark Returns the quark specifying the character
  524. * set of the font.
  525. *
  526. * Return Value: Returns 0 if successful, -1 if failed.
  527. *
  528. * Purpose: Gets the character set associated with a font.
  529. *
  530. *****************************************************************************/
  531. int
  532. __DtHelpFontCharSetQuarkGet (
  533. DtHelpDispAreaStruct *pDAS,
  534. long font_index,
  535. XrmQuark *ret_quark )
  536. {
  537. XrmRepresentation retType;
  538. XrmValue retValue;
  539. char buffer[10];
  540. XrmName xrmList[3];
  541. int result = 0;
  542. /*
  543. * quarkize the font index
  544. */
  545. sprintf (buffer, "%ld", font_index);
  546. xrmList[0] = XrmStringToQuark (buffer);
  547. xrmList[1] = XrmStringToQuark ("code_set");
  548. xrmList[2] = 0;
  549. /*
  550. * look in my font data base for the quark.
  551. */
  552. if (XrmQGetResource (pDAS->font_info.font_idx_db, xrmList, xrmList,
  553. &retType, &retValue))
  554. *ret_quark = *((XrmQuark *)retValue.addr);
  555. else
  556. result = -1;
  557. return result;
  558. }
  559. /******************************************************************************
  560. * Function: int __DtHelpFontLangQuarkGet (font_index, XrmQuark *ret_quark)
  561. *
  562. * Parameters: font_index Specifies the font in the font table.
  563. * ret_quark Returns the quark specifying the character
  564. * set of the font.
  565. *
  566. * Return Value: Returns 0 if successful, -1 if failed.
  567. *
  568. * Purpose: Gets the character set associated with a font.
  569. *
  570. *****************************************************************************/
  571. int
  572. __DtHelpFontLangQuarkGet (
  573. DtHelpDispAreaStruct *pDAS,
  574. long font_index,
  575. XrmQuark *ret_quark )
  576. {
  577. XrmRepresentation retType;
  578. XrmValue retValue;
  579. char buffer[10];
  580. XrmName xrmList[3];
  581. int result = 0;
  582. /*
  583. * quarkize the font index
  584. */
  585. sprintf (buffer, "%ld", font_index);
  586. xrmList[0] = XrmStringToQuark (buffer);
  587. xrmList[1] = XrmStringToQuark ("language");
  588. xrmList[2] = 0;
  589. /*
  590. * look in my font data base for the quark.
  591. */
  592. if (XrmQGetResource (pDAS->font_info.font_idx_db, xrmList, xrmList,
  593. &retType, &retValue))
  594. *ret_quark = *((XrmQuark *)retValue.addr);
  595. else
  596. result = -1;
  597. return result;
  598. }
  599. /******************************************************************************
  600. * Function: void _DtHelpCopyDefaultList (xrm_name)
  601. *
  602. * Parameters: xrm_name The quark list to fill out.
  603. *
  604. * Return Value: void
  605. *
  606. * Purpose: Initializes the font data base.
  607. *****************************************************************************/
  608. void
  609. _DtHelpCopyDefaultList (
  610. XrmName *xrm_list)
  611. {
  612. int n;
  613. for (n = 0; n < _DT_HELP_FONT_END + 1; n++)
  614. xrm_list[n] = DefaultFontQuarks[n];
  615. }
  616. /******************************************************************************
  617. * Function: void _DtHelpCopyCasualList (xrm_name)
  618. *
  619. * Parameters: xrm_name The quark list to fill out.
  620. *
  621. * Return Value: void
  622. *
  623. * Purpose:
  624. *****************************************************************************/
  625. void
  626. _DtHelpCopyCasualList (
  627. XrmName *xrm_list)
  628. {
  629. int n;
  630. for (n = 0; n < _DT_HELP_FONT_END + 1; n++)
  631. xrm_list[n] = CasualFontQuarks[n];
  632. }
  633. /******************************************************************************
  634. * Function: void _DtHelpGetStringQuarks (xrm_name)
  635. *
  636. * Parameters: xrm_name The quark list to fill out.
  637. *
  638. * Return Value: void
  639. *
  640. * Purpose: Initializes the font data base.
  641. *****************************************************************************/
  642. void
  643. _DtHelpGetStringQuarks (
  644. XrmName *xrm_list)
  645. {
  646. _DtHelpCopyDefaultList(xrm_list);
  647. xrm_list[_DT_HELP_FONT_CHAR_SET] = StringFontQuark;
  648. }
  649. /******************************************************************************
  650. * Function: void __DtHelpFontDatabaseInit (dpy, default_font, type, tmp)
  651. *
  652. * Parameters: dpy Specifies the connection to the display server.
  653. * default_font Specifies the base font.
  654. * type Specifies the type of font 'default_font' is.
  655. *
  656. * Return Value: void
  657. *
  658. * Purpose: Initializes the font data base.
  659. *
  660. *****************************************************************************/
  661. void
  662. __DtHelpFontDatabaseInit (
  663. DtHelpDispAreaStruct *pDAS,
  664. XtPointer string_font,
  665. XmFontType type,
  666. XFontStruct *user_font)
  667. {
  668. int n;
  669. int strIdx;
  670. int found = FALSE;
  671. Display *dpy = XtDisplay(pDAS->dispWid);
  672. DtHelpDAFontInfo *fontInfo = &(pDAS->font_info);
  673. XrmValue retValue;
  674. XrmRepresentation retType;
  675. XrmName xrmList[_DtHelpFontQuarkNumber];
  676. /*
  677. * build our default data base
  678. */
  679. *fontInfo = DefFontInfo;
  680. for (n = 0; FontResources[n]; n++)
  681. XrmPutLineResource (&(fontInfo->def_font_db), FontResources[n]);
  682. /*
  683. * build the default quark set.
  684. */
  685. _DtHelpProcessLock();
  686. if (QuarksInited == False)
  687. {
  688. StringFontQuark = XrmStringToQuark ("String");
  689. DefaultFontQuarks[_DT_HELP_FONT_SPACING] = XrmStringToQuark ("p");
  690. DefaultFontQuarks[_DT_HELP_FONT_SIZE] = XrmStringToQuark ("10");
  691. DefaultFontQuarks[_DT_HELP_FONT_ANGLE] = XrmStringToQuark ("roman");
  692. DefaultFontQuarks[_DT_HELP_FONT_WEIGHT] = XrmStringToQuark ("medium");
  693. DefaultFontQuarks[_DT_HELP_FONT_TYPE] =
  694. XrmStringToQuark ("sans_serif");
  695. DefaultFontQuarks[_DT_HELP_FONT_LANG_TER] = XrmStringToQuark ("C");
  696. DefaultFontQuarks[_DT_HELP_FONT_CHAR_SET] =
  697. XrmStringToQuark ("ISO-8859-1");
  698. DefaultFontQuarks[_DT_HELP_FONT_END] = 0;
  699. for (n = 0; n < _DT_HELP_FONT_END; ++n)
  700. CasualFontQuarks[n] = XrmStringToQuark("*");
  701. CasualFontQuarks[_DT_HELP_FONT_END] = 0;
  702. QuarksInited = True;
  703. }
  704. _DtHelpProcessUnlock();
  705. /*
  706. * if the string_font is null, used the default user's font for strings.
  707. */
  708. if (string_font == NULL)
  709. {
  710. /*
  711. * WARNING...what if the user_font is null? And what type is it?
  712. */
  713. string_font = (XtPointer) user_font;
  714. type = XmFONT_IS_FONT;
  715. }
  716. /*
  717. * save the string font in the lists
  718. */
  719. if (type == XmFONT_IS_FONTSET)
  720. strIdx = SaveFontSet ((XFontSet) string_font, fontInfo);
  721. else
  722. strIdx = SaveFontStruct ((XFontStruct *) string_font, fontInfo);
  723. /*
  724. * Save this idx font for ascii files and strings.
  725. */
  726. _DtHelpGetStringQuarks(xrmList);
  727. retValue.size = sizeof (int);
  728. retValue.addr = (XtPointer) &(strIdx);
  729. XrmQPutResource (&(fontInfo->font_idx_db), ((XrmBindingList) FontBindings),
  730. xrmList, _DtHelpXrmInt, &retValue);
  731. /*
  732. * try to get the default font for help information
  733. * from the parent's database.
  734. */
  735. if (XrmQGetResource (XrmGetDatabase(dpy), DefaultFontQuarks,
  736. DefaultFontQuarks, &retType, &retValue))
  737. found = LoadFont (dpy, fontInfo, ((char *) retValue.addr),
  738. &(fontInfo->def_idx));
  739. /*
  740. * If the XLFD font spec wasn't in the parent's database,
  741. * look at my private database.
  742. */
  743. if (found == False &&
  744. XrmQGetResource (fontInfo->def_font_db,
  745. DefaultFontQuarks, DefaultFontQuarks,
  746. &retType, &retValue))
  747. found = LoadFont (dpy, fontInfo, ((char *) retValue.addr),
  748. &(fontInfo->def_idx));
  749. /*
  750. * If still no luck, use the string font passed in.
  751. */
  752. if (found == False)
  753. fontInfo->def_idx = strIdx;
  754. /*
  755. * Remember we got this font for this quark string.
  756. */
  757. retValue.size = sizeof (int);
  758. retValue.addr = (XtPointer) &(fontInfo->def_idx);
  759. XrmQPutResource (&(fontInfo->font_idx_db), ((XrmBindingList) FontBindings),
  760. DefaultFontQuarks, _DtHelpXrmInt, &retValue);
  761. }
  762. /******************************************************************************
  763. * Function: XFontStruct *__DtHelpFontStructGet (long font_index );
  764. *
  765. * Parameters: font_index Specifies an index into the Font Structure
  766. * List.
  767. *
  768. * Return Value: Returns the font structure.
  769. *
  770. * Purpose:
  771. *
  772. *****************************************************************************/
  773. XFontStruct *
  774. __DtHelpFontStructGet (
  775. DtHelpDAFontInfo font_info,
  776. long font_index)
  777. {
  778. if (font_index > -1 && font_index < font_info.struct_cnt)
  779. return font_info.font_structs[font_index];
  780. return NULL;
  781. }
  782. /******************************************************************************
  783. * Function: XFontSet __DtHelpFontSetGet (long font_index);
  784. *
  785. * Parameters: font_index Specifies an index into the Font Set List.
  786. *
  787. * Return Value: Returns the font structure.
  788. *
  789. * Purpose:
  790. *
  791. *****************************************************************************/
  792. XFontSet
  793. __DtHelpFontSetGet (
  794. DtHelpDAFontInfo font_info,
  795. long font_index)
  796. {
  797. if (font_index < 0)
  798. {
  799. font_index = -font_index;
  800. font_index--;
  801. if (font_index < font_info.set_cnt)
  802. return font_info.font_sets[font_index];
  803. }
  804. return NULL;
  805. }
  806. /******************************************************************************
  807. * Function: long __DtHelpDefaultFontIndexGet ();
  808. *
  809. * Parameters:
  810. *
  811. * Return Value: Returns the index for the default font set/structure.
  812. *
  813. * Purpose:
  814. *
  815. *****************************************************************************/
  816. long
  817. __DtHelpDefaultFontIndexGet (
  818. DtHelpDispAreaStruct *pDAS)
  819. {
  820. return (pDAS->font_info.def_idx);
  821. }
  822. /******************************************************************************
  823. * Function: int __DtHelpFontMetrics (int font_index, int &ret_ascent,
  824. * &ret_descent);
  825. *
  826. * Parameters:
  827. *
  828. * Return Value: Returns the index for the default font set/structure.
  829. *
  830. * Purpose:
  831. *
  832. *****************************************************************************/
  833. void
  834. __DtHelpFontMetrics (
  835. DtHelpDAFontInfo font_info,
  836. long font_index,
  837. _DtCvUnit *ret_ascent,
  838. _DtCvUnit *ret_descent,
  839. _DtCvUnit *ret_char_width,
  840. _DtCvUnit *ret_super,
  841. _DtCvUnit *ret_sub)
  842. {
  843. XFontStruct **fontList;
  844. char **fontNames;
  845. int fontCount;
  846. _DtCvUnit maxAscent = -1;
  847. _DtCvUnit maxDescent = -1;
  848. _DtCvUnit maxCharW = -1;
  849. _DtCvUnit superOffset = 0;
  850. _DtCvUnit subOffset = 0;
  851. int i;
  852. if (font_index < 0)
  853. {
  854. font_index = -font_index;
  855. font_index--;
  856. if (font_index < font_info.set_cnt)
  857. {
  858. if (font_info.fs_metrics[font_index].inited == True)
  859. {
  860. maxAscent = font_info.fs_metrics[font_index].fm.ascent;
  861. maxDescent = font_info.fs_metrics[font_index].fm.descent;
  862. maxCharW = font_info.fs_metrics[font_index].fm.average_width;
  863. }
  864. else /* if (font_info.fs_metrics[font_index].inited == False) */
  865. {
  866. fontCount = XFontsOfFontSet(font_info.font_sets[font_index],
  867. &fontList, &fontNames);
  868. for (i = 0; i < fontCount; i++)
  869. {
  870. if (fontList[i]->ascent > maxAscent)
  871. maxAscent = fontList[i]->ascent;
  872. if (fontList[i]->descent > maxDescent)
  873. maxDescent = fontList[i]->descent;
  874. if (fontList[i]->max_bounds.width > maxCharW)
  875. maxCharW = fontList[i]->max_bounds.width;
  876. }
  877. font_info.fs_metrics[font_index].fm.ascent = maxAscent;
  878. font_info.fs_metrics[font_index].fm.descent = maxDescent;
  879. font_info.fs_metrics[font_index].fm.average_width = maxCharW;
  880. font_info.fs_metrics[font_index].inited = True;
  881. }
  882. }
  883. }
  884. else if (font_index < font_info.struct_cnt)
  885. {
  886. maxAscent = font_info.font_structs[font_index]->ascent;
  887. maxDescent = font_info.font_structs[font_index]->descent;
  888. maxCharW = font_info.font_structs[font_index]->max_bounds.width;
  889. }
  890. superOffset = (maxAscent * 40) / 100 + ((maxAscent % 40) > 19 ? 1 : 0);
  891. subOffset = superOffset;
  892. if (ret_ascent)
  893. *ret_ascent = maxAscent;
  894. if (ret_descent)
  895. *ret_descent = maxDescent;
  896. if (ret_char_width)
  897. *ret_char_width = maxCharW;
  898. if (ret_super)
  899. *ret_super = superOffset;
  900. if (ret_sub)
  901. *ret_sub = subOffset;
  902. }
  903. /******************************************************************************
  904. * Function: int _DtHelpGetExactFontIndex(Display dpy, char *xlfd_spec)
  905. *
  906. * Parameters:
  907. *
  908. * Return Value: 0 if successful, -1 if using default font index.
  909. *
  910. * Purpose: Try to load the specified font.
  911. *
  912. *****************************************************************************/
  913. int
  914. _DtHelpGetExactFontIndex (
  915. DtHelpDispAreaStruct *pDAS,
  916. const char *lang,
  917. const char *char_set,
  918. char *xlfd_spec,
  919. long *ret_idx)
  920. {
  921. int i = 0;
  922. int result = -1;
  923. long fontIndex = pDAS->font_info.def_idx;
  924. char **nameList;
  925. DtHelpDAFontInfo *fontInfo = &(pDAS->font_info);
  926. Display *dpy = XtDisplay(pDAS->dispWid);
  927. /*
  928. * look in my font data base to see if I've already processed
  929. * this xlfd_spec.
  930. */
  931. #ifndef REALLOC_INCR
  932. #define REALLOC_INCR 10
  933. #endif
  934. nameList = fontInfo->exact_fonts;
  935. if (NULL != nameList)
  936. {
  937. for (i = 0; NULL != *nameList && strcmp(*nameList, xlfd_spec); i++)
  938. nameList++;
  939. }
  940. if (NULL != nameList && NULL != *nameList)
  941. {
  942. fontIndex = fontInfo->exact_idx[i];
  943. result = 0;
  944. }
  945. else if (LoadFont(dpy, fontInfo, xlfd_spec, &fontIndex))
  946. {
  947. /*
  948. * make a copy of the font spec
  949. */
  950. xlfd_spec = strdup(xlfd_spec);
  951. if (NULL != xlfd_spec)
  952. {
  953. /*
  954. * now save it away for later tests.
  955. */
  956. fontInfo->exact_fonts = (char **) _DtHelpCeAddPtrToArray(
  957. (void **)fontInfo->exact_fonts,
  958. (void *) xlfd_spec);
  959. if (NULL != fontInfo->exact_fonts)
  960. {
  961. if (NULL == fontInfo->exact_idx)
  962. fontInfo->exact_idx = (int *) malloc(
  963. sizeof(int)*REALLOC_INCR);
  964. else if ((i + 1) % REALLOC_INCR == 0)
  965. fontInfo->exact_idx = (int *) realloc(fontInfo->exact_idx,
  966. sizeof(int) * (i + 1 + REALLOC_INCR));
  967. if (NULL != fontInfo->exact_idx)
  968. {
  969. char buffer[10];
  970. XrmValue retValue;
  971. XrmName xrmList[3];
  972. XrmQuark myQuark;
  973. fontInfo->exact_idx[i] = fontIndex;
  974. result = 0;
  975. /*
  976. * remember the character set for this font.
  977. */
  978. myQuark = XrmStringToQuark(char_set);
  979. sprintf (buffer, "%ld", fontIndex);
  980. retValue.size = sizeof (XrmQuark);
  981. retValue.addr = (XtPointer) &myQuark;
  982. xrmList[0] = XrmStringToQuark (buffer);
  983. xrmList[1] = XrmStringToQuark ("code_set");
  984. xrmList[2] = 0;
  985. XrmQPutResource (&(fontInfo->font_idx_db),
  986. ((XrmBindingList) FontBindings),
  987. xrmList, _DtHelpXrmQuark, &retValue);
  988. /*
  989. * remember the language for this font.
  990. */
  991. myQuark = XrmStringToQuark(lang);
  992. xrmList[1] = XrmStringToQuark ("language");
  993. XrmQPutResource (&(fontInfo->font_idx_db),
  994. ((XrmBindingList) FontBindings),
  995. xrmList, _DtHelpXrmQuark, &retValue);
  996. }
  997. }
  998. }
  999. }
  1000. *ret_idx = fontIndex;
  1001. return result;
  1002. }