udcimp.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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: udcimp.c /main/4 1996/09/02 18:51:02 cde-fuj $ */
  24. /*
  25. * (c) Copyright 1995 FUJITSU LIMITED
  26. * This is source code modified by FUJITSU LIMITED under the Joint
  27. * Development Agreement for the CDEnext PST.
  28. * This is unpublished proprietary source code of FUJITSU LIMITED
  29. */
  30. #include "excutil.h"
  31. #include "FaLib.h"
  32. void addcharptn();
  33. void setcodelists();
  34. extern ListData *ld;
  35. extern int num_gr;
  36. extern FalGlyphRegion *gr;
  37. extern FalFontData fullFontData;
  38. void udcimp(Exc_data * ed)
  39. {
  40. ed->function = IMPORT;
  41. strcpy(ed->bdfmode,"r");
  42. getbdffn(ed);
  43. }
  44. int checkcode(int code)
  45. {
  46. int i, j;
  47. int code1, code2;
  48. for (i = 0; i < num_gr; i++) {
  49. code1 = smaller(gr[i].start, gr[i].end);
  50. code2 = bigger(gr[i].start, gr[i].end);
  51. if ((code >= code1) && (code <= code2)) { /*in udc area */
  52. for (j = 0; j < ld->existcode_num; j++) {
  53. if (code == ld->existcode[j])
  54. return (1); /* the font has same glyph index */
  55. }
  56. return (0);
  57. }
  58. }
  59. return (-1); /* out of udc area */
  60. }
  61. int checkcodes(int code_num, int * code_list)
  62. {
  63. int *codep;
  64. int i, ans;
  65. int exist = 0;
  66. codep = code_list;
  67. for (i = 0; i < code_num; i++) {
  68. ans = checkcode(*codep);
  69. if (ans == -1) {
  70. return (-1);
  71. } else if (ans == 1) {
  72. exist = 1;
  73. }
  74. codep++;
  75. }
  76. return (exist);
  77. }
  78. void getcharcd(Exc_data * ed)
  79. {
  80. int code_num;
  81. int *code_list;
  82. int i;
  83. char *msg;
  84. char *msg2;
  85. char *msg3;
  86. int ans, ans2;
  87. msg = GETMESSAGE(12, 2, "Glyph images in this BDF file can't be added to the font.");
  88. msg2 = GETMESSAGE(12, 4, "Failed to open the selected BDF font. You have no right to access for the font file, or the format of the file is not consistent.");
  89. msg3 = GETMESSAGE(12, 6, "There are one or more glyph images being overwritten. Overwrite?");
  90. i = ImpBDFCodeList(ed->bdffile, &code_num, &code_list);
  91. if (i != 0) { /* bad BDF format */
  92. AskUser(ed->toplevel, ed, msg2, &ans, "error");
  93. freeld(ld);
  94. excterminate(ed);
  95. }
  96. ans2 = checkcodes(code_num, code_list);
  97. if (ans2 == -1) { /* out of UDC code exists */
  98. AskUser(ed->toplevel, ed, msg, &ans, "error");
  99. freeld(ld);
  100. excterminate(ed);
  101. } else if (ans2 == 1) { /* font file has same glyph index */
  102. AskUser(ed->toplevel, ed, msg3, &ans, "warning");
  103. if (ans != 1) {
  104. freeld(ld);
  105. excterminate(ed);
  106. }
  107. }
  108. /* set twe codelists */
  109. setcodelists(ld, code_num, code_list);
  110. if (ImpBDFCodeListFree(&code_list) != 0) {
  111. fprintf(stderr,"error in ImpBDFCodeListFree\n");
  112. }
  113. /* add gryph images to font */
  114. addcharptn(ed);
  115. }
  116. void addcharptn(Exc_data * ed)
  117. {
  118. int i;
  119. int ans;
  120. char *msg;
  121. char *msg2;
  122. char *msg3;
  123. int mask;
  124. FalFontDataList *fulllist = NULL;
  125. FalFontID fontid;
  126. msg = GETMESSAGE(12, 8, "Failed to open the selected font. You have no right to access for the font file, or the format of the file is not consistent.");
  127. msg2 = GETMESSAGE(12, 10, "Glyph images in this BDF file can't be added to the font.");
  128. msg3 = GETMESSAGE(12, 12, "Failed in the registration of the font file.");
  129. mask = FAL_FONT_MASK_XLFDNAME | FAL_FONT_MASK_GLYPH_INDEX |
  130. FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UPDATE |
  131. FAL_FONT_MASK_UNDEFINED | FAL_FONT_MASK_CODE_SET;
  132. i = ImpBDFCheck(ed->bdffile, ed->fontfile);
  133. if (i != 0) {
  134. AskUser(ed->toplevel, ed, msg2, &ans, "error");
  135. excterminate(ed);
  136. }
  137. fontid = FalOpenSysFont(&fullFontData, mask, &fulllist);
  138. if (fontid == 0) {
  139. AskUser(ld->ed->toplevel, ld->ed, msg, &ans, "error");
  140. excterminate(ed);
  141. }
  142. i = 0;
  143. i = ImpBDFtoGpf(ed->bdffile, ed->fontfile,
  144. ed->code_num, ed->bdf_code_list);
  145. FalCloseFont( fontid );
  146. if (i != 0) {
  147. AskUser(ed->toplevel, ed, msg3, &ans, "error");
  148. }
  149. excterminate(ed);
  150. }
  151. void setcodelists(ListData *ld, int code_num, int *code_list)
  152. {
  153. int *c1, *c2;
  154. int i;
  155. Exc_data *ed;
  156. ld->ed->code_num = code_num;
  157. if ((c1 = (int *) calloc(code_num, sizeof(int))) == NULL) {
  158. ed = ld->ed;
  159. freeld(ld);
  160. excerror(ed, EXCERRMALLOC, "setcodelists", "exit");
  161. }
  162. ld->ed->bdf_code_list = c1;
  163. c2 = code_list;
  164. for (i = 0; i < code_num; i++)
  165. {
  166. *c1 = *c2;
  167. c1++;
  168. c2++;
  169. }
  170. if ((c1 = (int *) calloc(code_num, sizeof(int))) == NULL) {
  171. ed = ld->ed;
  172. freeld(ld);
  173. excerror(ed, EXCERRMALLOC, "setcodelists", "exit");
  174. }
  175. ld->ed->gpf_code_list = c1;
  176. c2 = code_list;
  177. for (i = 0; i < code_num; i++)
  178. {
  179. *c1 = *c2;
  180. c1++;
  181. c2++;
  182. }
  183. }