xlfdutil.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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: xlfdutil.c /main/2 1996/10/14 14:45:50 barstow $ */
  24. /*
  25. * All Rights Reserved, Copyright (c) FUJITSU LIMITED 1995
  26. *
  27. * This is unpublished proprietary source code of FUJITSU LIMITED
  28. *
  29. * Authors: Seiya Miyazaki FUJITSU LIMITED
  30. * Hiroyuki Chiba Fujitsu Basic Software Corporation
  31. *
  32. */
  33. #include <string.h>
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <Dt/MsgCatP.h>
  37. #include <Xm/Xm.h>
  38. #include <Xm/Form.h>
  39. #include <Xm/PushB.h>
  40. #include <Xm/Text.h>
  41. #include <Xm/TextF.h>
  42. #include <Xm/Label.h>
  43. #include <Xm/SeparatoG.h>
  44. #include <Xm/List.h>
  45. #include <Xm/ToggleB.h>
  46. #include <Xm/MessageB.h>
  47. #include "FaLib.h"
  48. #include "falxlfd.h"
  49. #include "selectxlfd.h"
  50. #ifdef DEBUG
  51. #undef Dprintf
  52. #define Dprintf fprintf
  53. #else
  54. #define Dprintf
  55. #endif /* DEBUG */
  56. /*
  57. * parameters
  58. */
  59. static char* skipSpace() ;
  60. extern FalFontDataList *font_L ;
  61. extern FalxFontDataBuff KeyBuff ;
  62. extern FalxCodeList *CodeList ;
  63. extern FalxStyleList *StyleList ;
  64. extern FalxSizeList *SizeList ;
  65. extern int SelectedOffset ;
  66. extern int getmask ;
  67. extern char *fullPathName ;
  68. extern Widget toplevel ;
  69. extern Widget
  70. xlfdWform, cpyWform,
  71. slctBLabel[BUTTONITEMS],slctBText[BUTTONITEMS], slctButton[BUTTONITEMS],
  72. listPop[BUTTONITEMS], listW[BUTTONITEMS],
  73. errorMD, msgBox ;
  74. /****************************************************************
  75. * functions for get font infomation
  76. ****************************************************************/
  77. int
  78. GetXLFDInfomations()
  79. {
  80. Dprintf( stdout, "GetXLFDInfomations()\n" ) ;
  81. /* initialize */
  82. getmask = 0 ;
  83. SelectedOffset = 0 ;
  84. fullPathName = NULL ;
  85. FalxInitDataBuff( &KeyBuff ) ;
  86. /* get UDC informations */
  87. if( FalxGetFontList( &font_L, XtDisplayOfObject( toplevel ) ) ){
  88. Dprintf( stderr, "GetXLFDInfomations() : FalxGetFontList() error.\n" ) ;
  89. return(-1);
  90. }
  91. /* create code area list */
  92. if( FalxCreateCodeList( &CodeList, font_L ) ){
  93. Dprintf( stderr, "\nGetXLFDInfomations() : FalxCreateCodeList() error.\n" ) ;
  94. return(-1);
  95. }
  96. /* create style list */
  97. if( FalxCreateStyleList( &StyleList, font_L ) ){
  98. Dprintf( stderr, "\nGetXLFDInfomations() : FalxCreateStyleList() error.\n" ) ;
  99. return(-1);
  100. }
  101. /* create size list */
  102. if( FalxCreateSizeList( &SizeList, font_L ) ){
  103. Dprintf( stderr, "\nGetXLFDInfomations() : FalxCreateSizeList() error.\n" ) ;
  104. return(-1);
  105. }
  106. return(0) ;
  107. }
  108. int
  109. GetItemsToDisplay( int num, int *itemcnt, XmString **xms_list )
  110. {
  111. int i, j, cnt ;
  112. char *sp ,string[256], buf[256] ;
  113. Arg args[1];
  114. int length, maxlength ;
  115. FalxXlfdList *xlist ;
  116. int tmp_cnt ;
  117. char **tmp_dlist, *str ;
  118. XmString *xms ;
  119. int rlen ;
  120. int rtn ;
  121. switch( num ){
  122. case 0 : /* XLFD */
  123. /* set key data */
  124. for( i=1; i<BUTTONITEMS; i++ ){
  125. if( (str = XmTextGetString( slctBText[i] )) == NULL ){
  126. exit(-1) ;
  127. }
  128. if( *str == ' ' || *str == NULL ) continue ;
  129. if( SetKeyBuff( i, str ) ){
  130. exit(-1) ;
  131. }
  132. }
  133. rtn = FalxGetXlfdList( &xlist, font_L, &KeyBuff, getmask ) ;
  134. if( rtn ) return( rtn ) ;
  135. tmp_cnt = xlist->num ;
  136. tmp_dlist = xlist->list ;
  137. break ;
  138. case 1 : /* code area */
  139. tmp_cnt = CodeList->num ;
  140. tmp_dlist = (char **)malloc( sizeof(char *) * tmp_cnt ) ;
  141. if( tmp_dlist == NULL ) return(-1) ;
  142. for( i=0; i<tmp_cnt; i++ ){
  143. sp = string ;
  144. rlen = sprintf( sp, "CS:%d ", (CodeList->dlist[i]->fontset) ) ;
  145. sp += rlen ;
  146. for( j=0; j<CodeList->dlist[i]->code_area_num; j++ ){
  147. rlen = sprintf( sp, "%x - %x ",
  148. CodeList->dlist[i]->alist[j]->udc_start,
  149. CodeList->dlist[i]->alist[j]->udc_end ) ;
  150. sp += rlen ;
  151. }
  152. if( (tmp_dlist[i] = strdup( string )) == NULL ){
  153. return(-1) ;
  154. }
  155. }
  156. break ;
  157. case 2 : /* style */
  158. tmp_cnt = StyleList->num ;
  159. tmp_dlist = (char **)malloc( sizeof(char *) * tmp_cnt ) ;
  160. for( i=0; i<tmp_cnt; i++ ){
  161. if( (tmp_dlist[i] = strdup( StyleList->list[i] )) == NULL ){
  162. return(-1) ;
  163. }
  164. }
  165. break ;
  166. case 3 : /* size */
  167. tmp_cnt = SizeList->num ;
  168. tmp_dlist = (char **)malloc( sizeof(char *) * tmp_cnt ) ;
  169. for( i=0; i<tmp_cnt; i++ ){
  170. sprintf( string, "%d ", SizeList->list[i] ) ;
  171. if( (tmp_dlist[i] = strdup( string )) == NULL ){
  172. return(-1) ;
  173. }
  174. }
  175. break ;
  176. default : /* error */
  177. return(-1) ;
  178. }
  179. if( (xms = (XmString *)calloc( tmp_cnt, sizeof(XmString) )) == NULL ){
  180. return( -1 ) ;
  181. }
  182. /*
  183. * set list for display
  184. */
  185. maxlength = 0 ;
  186. for ( i=0; i<tmp_cnt; i++ ){
  187. xms[i] = XmStringCreateLocalized( tmp_dlist[i] );
  188. }
  189. /*
  190. * free allocated memory
  191. */
  192. switch( num ){
  193. case 0 : /* XLFD */
  194. FalxFreeXlfdList( xlist ) ;
  195. break ;
  196. case 1 : /* code area */
  197. case 2 : /* style */
  198. case 3 : /* size */
  199. for( i=0; i<tmp_cnt; i++ ){
  200. free( tmp_dlist[i] ) ;
  201. }
  202. free( tmp_dlist ) ;
  203. break ;
  204. default : /* error */
  205. return(-1) ;
  206. }
  207. *itemcnt = tmp_cnt ;
  208. *xms_list = xms ;
  209. return(0) ;
  210. }
  211. static char*
  212. skipSpace( char *str, int skipcnt )
  213. {
  214. int i, spacecnt ;
  215. char *sp ;
  216. int len ;
  217. if( *str == NULL ) return( NULL ) ;
  218. len = strlen( str ) ;
  219. sp = str ;
  220. for( i=0,spacecnt=0; i<len-1; i++, sp++ ) {
  221. if( *sp == NULL ) return( NULL ) ;
  222. if( *sp == ' ' ) spacecnt++ ;
  223. if( spacecnt == skipcnt ) break ;
  224. }
  225. sp++ ;
  226. return( sp ) ;
  227. }
  228. int
  229. SetKeyBuff( int num, char *str )
  230. {
  231. int i, j ;
  232. int cdset, start, end ;
  233. FalxUdcArea *tmp_list ;
  234. char hyp, *sp ;
  235. switch( num ){
  236. case 0 : /* XLFD */
  237. KeyBuff.FontData.xlfdname = str ;
  238. break ;
  239. case 1 : /* code area */
  240. getmask |= FAL_FONT_MASK_CODE_SET ;
  241. if( KeyBuff.FileData.list != NULL ){
  242. free( KeyBuff.FileData.list ) ;
  243. }
  244. KeyBuff.FileData.list = NULL ;
  245. tmp_list = NULL ;
  246. sp = str ;
  247. if( sscanf( sp, "CS:%d ", &cdset ) != 1 ){
  248. return(-1) ;
  249. }
  250. if( (sp = skipSpace( sp, 1 )) == NULL ) return( -1 ) ;
  251. num = 0 ;
  252. KeyBuff.FontData.cd_set = cdset ;
  253. while( sscanf( sp, "%x %c %x ", &start, &hyp, &end ) == 3 ){
  254. if( hyp != '-' ) break ;
  255. if( tmp_list == NULL ){
  256. tmp_list = (FalxUdcArea *)malloc( sizeof(FalxUdcArea) ) ;
  257. }else{
  258. tmp_list = (FalxUdcArea *)realloc( KeyBuff.FileData.list,
  259. sizeof(FalxUdcArea) * (num+1) ) ;
  260. }
  261. if( tmp_list == NULL ) return(-1) ;
  262. tmp_list[num].udc_start = (int)start ;
  263. tmp_list[num].udc_end = (int)end ;
  264. num ++ ;
  265. if( (sp = skipSpace( sp, 3 )) == NULL ) break ;
  266. }
  267. if( num == 0 ) return(-1) ;
  268. KeyBuff.FileData.code_area_num = num ;
  269. KeyBuff.FileData.list = tmp_list ;
  270. break ;
  271. case 2 : /* style */
  272. getmask |= FAL_FONT_MASK_STYLE_NAME ;
  273. KeyBuff.FontData.style.name = str ;
  274. break ;
  275. case 3 : /* size */
  276. getmask |= FAL_FONT_MASK_LETTER_W ;
  277. getmask |= FAL_FONT_MASK_LETTER_H ;
  278. KeyBuff.FontData.letter.w = atoi( str ) ;
  279. KeyBuff.FontData.letter.h = atoi( str ) ;
  280. break ;
  281. default :
  282. return(-1) ;
  283. }
  284. return(0);
  285. }