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