Line data Source code
1 : /* Copyright (C) 2000-2012 by George Williams */
2 : /*
3 : * Redistribution and use in source and binary forms, with or without
4 : * modification, are permitted provided that the following conditions are met:
5 :
6 : * Redistributions of source code must retain the above copyright notice, this
7 : * list of conditions and the following disclaimer.
8 :
9 : * Redistributions in binary form must reproduce the above copyright notice,
10 : * this list of conditions and the following disclaimer in the documentation
11 : * and/or other materials provided with the distribution.
12 :
13 : * The name of the author may not be used to endorse or promote products
14 : * derived from this software without specific prior written permission.
15 :
16 : * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 : * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 : * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 : * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 : * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 : * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 : * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 : * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 : * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 : * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 : */
27 : #include "bvedit.h"
28 : #include "cvimages.h"
29 : #include "cvundoes.h"
30 : #include "fontforgeui.h"
31 : #include "fvimportbdf.h"
32 : #include "spiro.h"
33 : #include "splinefill.h"
34 : #include <math.h>
35 : #include <sys/types.h>
36 : #include <dirent.h>
37 : #include "sd.h"
38 : #include <gkeysym.h>
39 : #include <ustring.h>
40 : #include <utype.h>
41 :
42 0 : static void ImportPS(CharView *cv,char *path) {
43 0 : FILE *ps = fopen(path,"r");
44 :
45 0 : if ( ps==NULL )
46 0 : return;
47 0 : SCImportPSFile(cv->b.sc,CVLayer((CharViewBase *) cv),ps,false,-1);
48 0 : fclose(ps);
49 : }
50 :
51 0 : static void ImportPDF(CharView *cv,char *path) {
52 0 : FILE *pdf = fopen(path,"r");
53 :
54 0 : if ( pdf==NULL )
55 0 : return;
56 0 : SCImportPDFFile(cv->b.sc,CVLayer((CharViewBase *) cv),pdf,false,-1);
57 0 : fclose(pdf);
58 : }
59 :
60 0 : static void ImportPlate(CharView *cv,char *path) {
61 0 : FILE *plate = fopen(path,"r");
62 :
63 0 : if ( plate==NULL )
64 0 : return;
65 0 : SCImportPlateFile(cv->b.sc,CVLayer((CharViewBase *) cv),plate,false);
66 0 : fclose(plate);
67 : }
68 :
69 0 : static void ImportSVG(CharView *cv,char *path) {
70 0 : SCImportSVG(cv->b.sc,CVLayer((CharViewBase *) cv),path,NULL,0,false);
71 0 : }
72 :
73 0 : static void ImportGlif(CharView *cv,char *path) {
74 0 : SCImportGlif(cv->b.sc,CVLayer((CharViewBase *) cv),path,NULL,0,false);
75 0 : }
76 :
77 0 : static void ImportFig(CharView *cv,char *path) {
78 0 : SCImportFig(cv->b.sc,CVLayer((CharViewBase *) cv),path,false);
79 0 : }
80 :
81 0 : static void ImportImage(CharView *cv,char *path) {
82 : GImage *image;
83 : int layer;
84 :
85 0 : image = GImageRead(path);
86 0 : if ( image==NULL ) {
87 0 : ff_post_error(_("Bad image file"),_("Bad image file: %.100s"), path);
88 0 : return;
89 : }
90 0 : layer = ly_back;
91 0 : if ( cv->b.drawmode!=dm_grid ) {
92 0 : if ( cv->b.sc->parent->multilayer )
93 0 : layer = cv->b.drawmode-dm_back + ly_back;
94 0 : else if ( cv->b.layerheads[cv->b.drawmode]->background )
95 0 : layer = CVLayer( (CharViewBase *) cv);
96 : }
97 0 : SCAddScaleImage(cv->b.sc,image,false,layer);
98 : }
99 :
100 0 : static int BVImportImage(BitmapView *bv,char *path) {
101 : GImage *image;
102 : struct _GImage *base;
103 : int tot;
104 : uint8 *pt, *end;
105 0 : BDFChar *bc = bv->bc;
106 : int i, j;
107 :
108 0 : image = GImageRead(path);
109 0 : if ( image==NULL ) {
110 0 : ff_post_error(_("Bad image file"),_("Bad image file: %.100s"), path);
111 0 : return(false);
112 : }
113 0 : base = image->list_len==0?image->u.image:image->u.images[0];
114 0 : BCPreserveState(bc);
115 0 : BCFlattenFloat(bc);
116 0 : free(bc->bitmap);
117 0 : bc->xmin = bc->ymin = 0;
118 0 : bc->xmax = base->width-1; bc->ymax = base->height-1;
119 0 : if ( !bc->byte_data && base->image_type==it_mono ) {
120 0 : bc->bitmap = base->data;
121 0 : bc->bytes_per_line = base->bytes_per_line;
122 :
123 : /* Sigh. Bitmaps use a different defn of set than images do. make it consistant */
124 0 : tot = bc->bytes_per_line*(bc->ymax-bc->ymin+1);
125 0 : for ( pt = bc->bitmap, end = pt+tot; pt<end; *pt++ ^= 0xff );
126 :
127 0 : base->data = NULL;
128 0 : } else if ( base->image_type==it_mono /* && byte_data */) {
129 0 : int set = (1<<BDFDepth(bv->bdf))-1;
130 0 : bc->bytes_per_line = base->width;
131 0 : bc->bitmap = calloc(base->height,base->width);
132 0 : for ( i=0; i<base->height; ++i ) for ( j=0; j<base->width; ++j ) {
133 0 : if ( !(base->data[i*base->bytes_per_line+(j>>3)]&(0x80>>(j&7))) )
134 0 : bc->bitmap[i*bc->bytes_per_line+j] = set;
135 : }
136 0 : } else if ( !bc->byte_data && base->image_type==it_true ) {
137 0 : bc->bytes_per_line = (base->width>>3)+1;
138 0 : bc->bitmap = calloc(base->height,bc->bytes_per_line);
139 0 : for ( i=0; i<base->height; ++i ) for ( j=0; j<base->width; ++j ) {
140 0 : int col = ((Color *) (base->data+i*base->bytes_per_line))[j];
141 0 : col = (3*COLOR_RED(col)+6*COLOR_GREEN(col)+COLOR_BLUE(col));
142 0 : if ( col<=5*256 )
143 0 : bc->bitmap[i*bc->bytes_per_line+(j>>3)] |= (0x80>>(j&7));
144 : }
145 0 : } else if ( /* byte_data && */ base->image_type==it_true ) {
146 0 : int div = 255/((1<<BDFDepth(bv->bdf))-1);
147 0 : bc->bytes_per_line = base->width;
148 0 : bc->bitmap = calloc(base->height,base->width);
149 0 : for ( i=0; i<base->height; ++i ) for ( j=0; j<base->width; ++j ) {
150 0 : int col = ((Color *) (base->data+i*base->bytes_per_line))[j];
151 0 : col = 255-(3*COLOR_RED(col)+6*COLOR_GREEN(col)+COLOR_BLUE(col)+5)/10;
152 0 : bc->bitmap[i*bc->bytes_per_line+j] = col/div;
153 : }
154 0 : } else if ( bc->byte_data /* && indexed */ ) {
155 0 : int div = 255/((1<<BDFDepth(bv->bdf))-1);
156 0 : bc->bitmap = base->data;
157 0 : bc->bytes_per_line = base->bytes_per_line;
158 0 : for ( i=0; i<base->height; ++i ) for ( j=0; j<base->width; ++j ) {
159 0 : int col = base->clut->clut[base->data[i*base->bytes_per_line+j]];
160 0 : col = 255-(3*COLOR_RED(col)+6*COLOR_GREEN(col)+COLOR_BLUE(col)+5)/10;
161 0 : base->data[i*base->bytes_per_line+j] = col/div;
162 : }
163 0 : base->data = NULL;
164 : } else /* if ( mono && indexed ) */ {
165 0 : bc->bytes_per_line = (base->width>>3)+1;
166 0 : bc->bitmap = calloc(base->height,bc->bytes_per_line);
167 0 : for ( i=0; i<base->height; ++i ) for ( j=0; j<base->width; ++j ) {
168 0 : int col = base->clut->clut[base->data[i*base->bytes_per_line+j]];
169 0 : col = (3*COLOR_RED(col)+6*COLOR_GREEN(col)+COLOR_BLUE(col));
170 0 : if ( col<=5*256 )
171 0 : bc->bitmap[i*bc->bytes_per_line+(j>>3)] |= (0x80>>(j&7));
172 : }
173 : }
174 0 : GImageDestroy(image);
175 0 : if ( bc->sc!=NULL )
176 0 : bc->sc->widthset = true;
177 0 : BCCharChangedUpdate(bc);
178 0 : return( true );
179 : }
180 :
181 :
182 : static unichar_t wildimg[] = { '*', '.', '{',
183 : #ifndef _NO_LIBUNGIF
184 : 'g','i','f',',',
185 : #endif
186 : #ifndef _NO_LIBPNG
187 : 'p','n','g',',',
188 : #endif
189 : #ifndef _NO_LIBTIFF
190 : 't','i','f','f',',',
191 : 't','i','f',',',
192 : #endif
193 : #ifndef _NO_LIBJPEG
194 : 'j','p','e','g',',',
195 : 'j','p','g',',',
196 : #endif
197 : 'x','p','m',',', 'x','b','m',',', 'b','m','p', '}', '\0' };
198 : static unichar_t wildtemplate[] = { '{','u','n','i',',','u',',','c','i','d',',','e','n','c','}','[','0','-','9','a','-','f','A','-','F',']','*', '.', '{',
199 : #ifndef _NO_LIBUNGIF
200 : 'g','i','f',',',
201 : #endif
202 : #ifndef _NO_LIBPNG
203 : 'p','n','g',',',
204 : #endif
205 : #ifndef _NO_LIBTIFF
206 : 't','i','f','f',',',
207 : 't','i','f',',',
208 : #endif
209 : 'x','p','m',',', 'x','b','m',',', 'b','m','p', '}', '\0' };
210 : /* Hmm. Mac seems to use the extension 'art' for eps files sometimes */
211 : static unichar_t wildepstemplate[] = { '{','u','n','i',',','u',',','c','i','d',',','e','n','c','}','[','0','-','9','a','-','f','A','-','F',']','*', '.', '{', 'p','s',',', 'e','p','s',',','a','r','t','}', 0 };
212 : static unichar_t wildpdftemplate[] = { '{','u','n','i',',','u',',','c','i','d',',','e','n','c','}','[','0','-','9','a','-','f','A','-','F',']','*', '.', 'p', 'd','f', 0 };
213 : static unichar_t wildsvgtemplate[] = { '{','u','n','i',',','u',',','c','i','d',',','e','n','c','}','[','0','-','9','a','-','f','A','-','F',']','*', '.', 's', 'v','g', 0 };
214 : static unichar_t wildgliftemplate[] = { '{','u','n','i',',','u',',','c','i','d',',','e','n','c','}','[','0','-','9','a','-','f','A','-','F',']','*', '.', 'g', 'l','i','f', 0 };
215 : static unichar_t wildplatetemplate[] = { '{','u','n','i',',','u',',','c','i','d',',','e','n','c','}','[','0','-','9','a','-','f','A','-','F',']','*', '.', 'p','l','a','t','e', 0 };
216 : static unichar_t wildps[] = { '*', '.', '{', 'p','s',',', 'e','p','s',',', 'a','r','t','}', '\0' };
217 : static unichar_t wildpdf[] = { '*', '.', 'p','d','f', '\0' };
218 : static unichar_t wildsvg[] = { '*', '.', 's','v','g', '\0' };
219 : static unichar_t wildplate[] = { '*', '.', 'p','l','a','t','e', '\0' };
220 : static unichar_t wildglif[] = { '*', '.', 'g','l','i','f', '\0' };
221 : static unichar_t wildfig[] = { '*', '.', '{', 'f','i','g',',','x','f','i','g','}', '\0' };
222 : static unichar_t wildbdf[] = { '*', '.', 'b', 'd','{', 'f', ',','f','.','g','z',',','f','.','Z',',','f','.','b','z','2','}', '\0' };
223 : static unichar_t wildpcf[] = { '*', '.', 'p', '{', 'c',',','m','}','{', 'f', ',','f','.','g','z',',','f','.','Z',',','f','.','b','z','2','}', '\0' };
224 : static unichar_t wildttf[] = { '*', '.', '{', 't', 't','f',',','o','t','f',',','o','t','b',',','t','t','c','}', '\0' };
225 : static unichar_t wildpk[] = { '*', '{', 'p', 'k', ',', 'g', 'f', '}', '\0' }; /* pk fonts can have names like cmr10.300pk, not a normal extension */
226 : static unichar_t wildmac[] = { '*', '{', 'b', 'i', 'n', ',', 'h', 'q', 'x', ',', 'd','f','o','n','t', '}', '\0' };
227 : static unichar_t wildwin[] = { '*', '{', 'f', 'o', 'n', ',', 'f', 'n', 't', '}', '\0' };
228 : static unichar_t wildpalm[] = { '*', 'p', 'd', 'b', '\0' };
229 : static unichar_t *wildchr[] = { wildimg, wildps, wildpdf,
230 : wildsvg,
231 : wildglif,
232 : wildplate,
233 : wildfig };
234 : static unichar_t *wildfnt[] = { wildbdf, wildttf, wildpk, wildpcf, wildmac,
235 : wildwin, wildpalm,
236 : wildimg, wildtemplate, wildps, wildepstemplate,
237 : wildpdf, wildpdftemplate,
238 : wildplate, wildplatetemplate,
239 : wildsvg, wildsvgtemplate,
240 : wildglif, wildgliftemplate,
241 : wildfig
242 : };
243 :
244 : #define PSSF_Width 220
245 : #define PSSF_Height 165
246 :
247 0 : static int PSSF_OK(GGadget *g, GEvent *e) {
248 0 : if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate )
249 0 : *(int *) GDrawGetUserData(GGadgetGetWindow(g)) = true;
250 0 : return( true );
251 : }
252 :
253 0 : static int psstrokeflags_e_h(GWindow gw, GEvent *event) {
254 0 : if ( event->type==et_close ) {
255 0 : *(int *) GDrawGetUserData(gw) = true;
256 0 : } else if ( event->type == et_char ) {
257 0 : if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) {
258 0 : help("filemenu.html#type3-import");
259 0 : return( true );
260 : }
261 0 : return( false );
262 : }
263 0 : return( true );
264 : }
265 :
266 1 : enum psstrokeflags Ps_StrokeFlagsDlg(void) {
267 : static enum psstrokeflags oldflags = sf_correctdir/*|sf_removeoverlap|sf_handle_eraser*/;
268 : GRect pos;
269 : GWindow gw;
270 : GWindowAttrs wattrs;
271 : GGadgetCreateData gcd[11], boxes[4], *hvarray[7][2], *barray[10];
272 : GTextInfo label[11];
273 1 : int done = false;
274 : int k, he_k, cd_k;
275 :
276 1 : if ( no_windowing_ui )
277 1 : return( oldflags );
278 :
279 0 : memset(&wattrs,0,sizeof(wattrs));
280 0 : wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict;
281 0 : wattrs.event_masks = ~(1<<et_charup);
282 0 : wattrs.restrict_input_to_me = 1;
283 0 : wattrs.undercursor = 1;
284 0 : wattrs.cursor = ct_pointer;
285 0 : wattrs.utf8_window_title = _("PS Interpretion");
286 0 : wattrs.is_dlg = true;
287 0 : pos.x = pos.y = 0;
288 0 : pos.width = GGadgetScale(GDrawPointsToPixels(NULL,PSSF_Width));
289 0 : pos.height = GDrawPointsToPixels(NULL,PSSF_Height);
290 0 : gw = GDrawCreateTopWindow(NULL,&pos,psstrokeflags_e_h,&done,&wattrs);
291 :
292 0 : memset(&label,0,sizeof(label));
293 0 : memset(&gcd,0,sizeof(gcd));
294 0 : memset(&boxes,0,sizeof(boxes));
295 :
296 0 : k = 0;
297 : /* GT: The following strings should be concatenated together, the result */
298 : /* GT: translated, and then broken into lines by hand. I'm sure it would */
299 : /* GT: be better to specify this all as one string, but my widgets won't support */
300 : /* GT: that */
301 0 : label[k].text = (unichar_t *) _("FontForge has some bugs in its remove overlap\n"
302 : "function which may cause you problems, so\n"
303 : "I give you the option of turning it off.\n"
304 : "Leave it on if possible though, it is useful.");
305 0 : label[k].text_is_1byte = true;
306 0 : gcd[k].gd.label = &label[k];
307 0 : gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = 6;
308 0 : gcd[k].gd.flags = gg_enabled | gg_visible;
309 0 : gcd[k++].creator = GLabelCreate;
310 0 : hvarray[0][0] = &gcd[k-1]; hvarray[0][1] = NULL;
311 :
312 0 : cd_k = k;
313 0 : label[k].text = (unichar_t *) _("_Correct Direction");
314 0 : label[k].text_is_1byte = true;
315 0 : label[k].text_in_resource = true;
316 0 : gcd[k].gd.label = &label[k];
317 0 : gcd[k].gd.pos.x = gcd[k-1].gd.pos.x; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+15;
318 0 : gcd[k].gd.flags = gg_enabled | gg_visible | (oldflags&sf_correctdir?gg_cb_on:0);
319 0 : gcd[k++].creator = GCheckBoxCreate;
320 0 : hvarray[1][0] = &gcd[k-1]; hvarray[1][1] = NULL;
321 :
322 0 : he_k = k;
323 0 : label[k].text = (unichar_t *) _("Handle Erasers");
324 0 : label[k].text_is_1byte = true;
325 0 : gcd[k].gd.label = &label[k];
326 0 : gcd[k].gd.pos.x = gcd[k-1].gd.pos.x; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+15;
327 0 : gcd[k].gd.flags = gg_enabled | gg_visible | gg_utf8_popup |
328 0 : (oldflags&sf_handle_eraser?gg_cb_on:0);
329 0 : gcd[k].gd.popup_msg = (unichar_t *) _("Certain programs use pens with white ink as erasers\nIf you select (blacken) this checkbox, FontForge will\nattempt to simulate that.");
330 0 : gcd[k++].creator = GCheckBoxCreate;
331 0 : hvarray[2][0] = &gcd[k-1]; hvarray[2][1] = NULL;
332 0 : hvarray[3][0] = GCD_Glue; hvarray[3][1] = NULL;
333 :
334 0 : gcd[k].gd.pos.x = (PSSF_Width-GIntGetResource(_NUM_Buttonsize))/2; gcd[k].gd.pos.y = PSSF_Height-34;
335 0 : gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_default;
336 0 : label[k].text = (unichar_t *) _("_OK");
337 0 : label[k].text_is_1byte = true;
338 0 : label[k].text_in_resource = true;
339 0 : gcd[k].gd.label = &label[k];
340 0 : gcd[k].gd.handle_controlevent = PSSF_OK;
341 0 : gcd[k++].creator = GButtonCreate;
342 0 : barray[0] = GCD_Glue; barray[1] = &gcd[k-1]; barray[2] = GCD_Glue; barray[3] = NULL;
343 :
344 0 : boxes[2].gd.flags = gg_enabled | gg_visible;
345 0 : boxes[2].gd.u.boxelements = barray;
346 0 : boxes[2].creator = GHBoxCreate;
347 0 : hvarray[4][0] = &boxes[2]; hvarray[4][1] = NULL;
348 0 : hvarray[5][0] = NULL;
349 :
350 0 : boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2;
351 0 : boxes[0].gd.flags = gg_enabled | gg_visible;
352 0 : boxes[0].gd.u.boxelements = hvarray[0];
353 0 : boxes[0].creator = GHVGroupCreate;
354 :
355 0 : GGadgetsCreate(gw,boxes);
356 0 : GHVBoxSetExpandableRow(boxes[0].ret,gb_expandglue);
357 0 : GHVBoxSetExpandableCol(boxes[2].ret,gb_expandgluesame);
358 0 : GHVBoxFitWindow(boxes[0].ret);
359 :
360 0 : GDrawSetVisible(gw,true);
361 :
362 0 : while ( !done )
363 0 : GDrawProcessOneEvent(NULL);
364 :
365 : /* This dlg can't be cancelled */
366 0 : oldflags = 0;
367 0 : if ( GGadgetIsChecked(gcd[cd_k].ret) )
368 0 : oldflags |= sf_correctdir;
369 0 : if ( GGadgetIsChecked(gcd[he_k].ret) )
370 0 : oldflags |= sf_handle_eraser;
371 0 : GDrawDestroyWindow(gw);
372 0 : return( oldflags );
373 : }
374 :
375 : /****************************** Import picker *********************************/
376 :
377 : static int last_format, flast_format;
378 : struct gfc_data {
379 : int done;
380 : int ret;
381 : GGadget *gfc;
382 : GGadget *format;
383 : GGadget *background;
384 : CharView *cv;
385 : BitmapView *bv;
386 : FontView *fv;
387 : };
388 :
389 : static GTextInfo formats[] = {
390 : { (unichar_t *) N_("Image"), NULL, 0, 0, (void *) fv_image, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
391 : { (unichar_t *) N_("EPS"), NULL, 0, 0, (void *) fv_eps, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
392 : { (unichar_t *) N_("PDF page graphics"), NULL, 0, 0, (void *) fv_pdf, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
393 : { (unichar_t *) N_("SVG"), NULL, 0, 0, (void *) fv_svg, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
394 : { (unichar_t *) N_("Glif"), NULL, 0, 0, (void *) fv_glif, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
395 : { (unichar_t *) N_("Raph's plate files"), NULL, 0, 0, (void *) fv_plate, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
396 : { (unichar_t *) N_("XFig"), NULL, 0, 0, (void *) fv_fig, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
397 : GTEXTINFO_EMPTY
398 : };
399 :
400 : static GTextInfo fvformats[] = {
401 : { (unichar_t *) N_("BDF"), NULL, 0, 0, (void *) fv_bdf, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, '\0' },
402 : { (unichar_t *) N_("TTF"), NULL, 0, 0, (void *) fv_ttf, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
403 : { (unichar_t *) NU_("ΤεΧ Bitmap Fonts"), NULL, 0, 0, (void *) fv_pk, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
404 : { (unichar_t *) N_("PCF (pmf)"), NULL, 0, 0, (void *) fv_pcf, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
405 : { (unichar_t *) N_("Mac Bitmap"), NULL, 0, 0, (void *) fv_mac, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
406 : { (unichar_t *) N_("Win FON"), NULL, 0, 0, (void *) fv_win, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
407 : { (unichar_t *) N_("palm"), NULL, 0, 0, (void *) fv_palm, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
408 : { (unichar_t *) N_("Image"), NULL, 0, 0, (void *) fv_image, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
409 : { (unichar_t *) N_("Image Template"), NULL, 0, 0, (void *) fv_imgtemplate, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
410 : { (unichar_t *) N_("EPS"), NULL, 0, 0, (void *) fv_eps, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
411 : { (unichar_t *) N_("EPS Template"), NULL, 0, 0, (void *) fv_epstemplate, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
412 : { (unichar_t *) N_("PDF page graphics"), NULL, 0, 0, (void *) fv_pdf, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
413 : { (unichar_t *) N_("SVG"), NULL, 0, 0, (void *) fv_svg, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
414 : { (unichar_t *) N_("SVG Template"), NULL, 0, 0, (void *) fv_svgtemplate, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
415 : { (unichar_t *) N_("Glif"), NULL, 0, 0, (void *) fv_glif, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
416 : { (unichar_t *) N_("Glif Template"), NULL, 0, 0, (void *) fv_gliftemplate, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
417 : GTEXTINFO_EMPTY
418 : };
419 :
420 0 : static int GFD_ImportOk(GGadget *g, GEvent *e) {
421 0 : if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
422 0 : struct gfc_data *d = GDrawGetUserData(GGadgetGetWindow(g));
423 0 : unichar_t *ret = GGadgetGetTitle(d->gfc);
424 0 : char *temp = u2def_copy(ret);
425 0 : int pos = GGadgetGetFirstListSelectedItem(d->format);
426 0 : int format = (intpt) (GGadgetGetListItemSelected(d->format)->userdata);
427 : GGadget *tf;
428 :
429 0 : GFileChooserGetChildren(d->gfc,NULL,NULL,&tf);
430 0 : if ( *_GGadgetGetTitle(tf)=='\0' )
431 0 : return( true );
432 0 : GDrawSetCursor(GGadgetGetWindow(g),ct_watch);
433 0 : if ( d->fv!=NULL )
434 0 : flast_format = pos;
435 : else
436 0 : last_format = pos;
437 0 : free(ret);
438 0 : if ( d->fv!=NULL ) {
439 0 : int toback = GGadgetIsChecked(d->background);
440 0 : if ( toback && strchr(temp,';')!=NULL && format<3 )
441 0 : ff_post_error(_("Only One Font"),_("Only one font may be imported into the background"));
442 0 : else if ( format==fv_bdf )
443 0 : d->done = FVImportBDF((FontViewBase *) d->fv,temp,false, toback);
444 0 : else if ( format==fv_ttf )
445 0 : d->done = FVImportMult((FontViewBase *) d->fv,temp,toback,bf_ttf);
446 0 : else if ( format==fv_pk ) /* pk */
447 0 : d->done = FVImportBDF((FontViewBase *) d->fv,temp,true, toback);
448 0 : else if ( format==fv_pcf ) /* pcf */
449 0 : d->done = FVImportBDF((FontViewBase *) d->fv,temp,2, toback);
450 0 : else if ( format==fv_mac )
451 0 : d->done = FVImportMult((FontViewBase *) d->fv,temp,toback,bf_nfntmacbin);
452 0 : else if ( format==fv_win )
453 0 : d->done = FVImportMult((FontViewBase *) d->fv,temp,toback,bf_fon);
454 0 : else if ( format==fv_palm )
455 0 : d->done = FVImportMult((FontViewBase *) d->fv,temp,toback,bf_palm);
456 0 : else if ( format==fv_image )
457 0 : d->done = FVImportImages((FontViewBase *) d->fv,temp,format,toback,-1);
458 0 : else if ( format==fv_imgtemplate )
459 0 : d->done = FVImportImageTemplate((FontViewBase *) d->fv,temp,format,toback,-1);
460 0 : else if ( format==fv_eps )
461 0 : d->done = FVImportImages((FontViewBase *) d->fv,temp,format,toback,-1);
462 0 : else if ( format==fv_epstemplate )
463 0 : d->done = FVImportImageTemplate((FontViewBase *) d->fv,temp,format,toback,-1);
464 0 : else if ( format==fv_pdf )
465 0 : d->done = FVImportImages((FontViewBase *) d->fv,temp,format,toback,-1);
466 0 : else if ( format==fv_pdftemplate )
467 0 : d->done = FVImportImageTemplate((FontViewBase *) d->fv,temp,format,toback,-1);
468 0 : else if ( format==fv_svg )
469 0 : d->done = FVImportImages((FontViewBase *) d->fv,temp,format,toback,-1);
470 0 : else if ( format==fv_svgtemplate )
471 0 : d->done = FVImportImageTemplate((FontViewBase *) d->fv,temp,format,toback,-1);
472 0 : else if ( format==fv_glif )
473 0 : d->done = FVImportImages((FontViewBase *) d->fv,temp,format,toback,-1);
474 0 : else if ( format==fv_gliftemplate )
475 0 : d->done = FVImportImageTemplate((FontViewBase *) d->fv,temp,format,toback,-1);
476 0 : else if ( format>=fv_pythonbase )
477 0 : d->done = FVImportImages((FontViewBase *) d->fv,temp,format,toback,-1);
478 0 : } else if ( d->bv!=NULL )
479 0 : d->done = BVImportImage(d->bv,temp);
480 : else {
481 0 : d->done = true;
482 0 : if ( format==fv_image )
483 0 : ImportImage(d->cv,temp);
484 0 : else if ( format==fv_eps )
485 0 : ImportPS(d->cv,temp);
486 0 : else if ( format==fv_pdf )
487 0 : ImportPDF(d->cv,temp);
488 0 : else if ( format==fv_plate )
489 0 : ImportPlate(d->cv,temp);
490 0 : else if ( format==fv_svg )
491 0 : ImportSVG(d->cv,temp);
492 0 : else if ( format==fv_glif )
493 0 : ImportGlif(d->cv,temp);
494 0 : else if ( format==fv_fig )
495 0 : ImportFig(d->cv,temp);
496 : #ifndef _NO_PYTHON
497 0 : else if ( format>=fv_pythonbase )
498 0 : PyFF_SCImport(d->cv->b.sc,format-fv_pythonbase,temp,
499 0 : CVLayer((CharViewBase *) d->cv), false);
500 : #endif
501 : }
502 0 : free(temp);
503 0 : GDrawSetCursor(GGadgetGetWindow(g),ct_pointer);
504 : }
505 0 : return( true );
506 : }
507 :
508 0 : static int GFD_Cancel(GGadget *g, GEvent *e) {
509 0 : if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
510 0 : struct gfc_data *d = GDrawGetUserData(GGadgetGetWindow(g));
511 0 : d->done = true;
512 0 : d->ret = false;
513 : }
514 0 : return( true );
515 : }
516 :
517 0 : static int GFD_Format(GGadget *g, GEvent *e) {
518 0 : if ( e->type==et_controlevent && e->u.control.subtype == et_listselected ) {
519 0 : struct gfc_data *d = GDrawGetUserData(GGadgetGetWindow(g));
520 0 : int format = (intpt) (GGadgetGetListItemSelected(d->format)->userdata);
521 0 : if ( format<fv_pythonbase )
522 0 : GFileChooserSetFilterText(d->gfc,wildfnt[format]);
523 : #ifndef _NO_PYTHON
524 : else {
525 : char *text;
526 0 : char *ae = py_ie[format-fv_pythonbase].all_extensions;
527 : unichar_t *utext;
528 0 : text = malloc(strlen(ae)+10);
529 0 : if ( strchr(ae,','))
530 0 : sprintf( text, "*.{%s}", ae );
531 : else
532 0 : sprintf( text, "*.%s", ae );
533 0 : utext = utf82u_copy(text);
534 0 : GFileChooserSetFilterText(d->gfc,utext);
535 0 : free(text); free(utext);
536 : }
537 : #endif
538 0 : GFileChooserRefreshList(d->gfc);
539 0 : if ( d->fv!=NULL ) {
540 0 : if ( format==fv_bdf || format==fv_ttf || format==fv_pcf ||
541 0 : format==fv_mac || format==fv_win ) {
542 0 : GGadgetSetChecked(d->background,false);
543 0 : GGadgetSetEnabled(d->background,true);
544 0 : } else if ( format==fv_pk ) {
545 0 : GGadgetSetChecked(d->background,true);
546 0 : GGadgetSetEnabled(d->background,true);
547 0 : } else if ( format==fv_eps || format==fv_epstemplate ||
548 0 : format==fv_pdf || format==fv_pdftemplate ||
549 0 : format==fv_svg || format==fv_svgtemplate ||
550 0 : format==fv_glif || format==fv_gliftemplate ||
551 : format>=fv_pythonbase ) {
552 0 : GGadgetSetChecked(d->background,false);
553 0 : GGadgetSetEnabled(d->background,true);
554 : } else { /* Images */
555 0 : GGadgetSetChecked(d->background,true);
556 0 : GGadgetSetEnabled(d->background,true);
557 : }
558 : }
559 : }
560 0 : return( true );
561 : }
562 :
563 0 : static int e_h(GWindow gw, GEvent *event) {
564 0 : if ( event->type==et_close ) {
565 0 : struct gfc_data *d = GDrawGetUserData(gw);
566 0 : d->done = true;
567 0 : d->ret = false;
568 0 : } else if ( event->type == et_char ) {
569 0 : return( false );
570 0 : } else if ( event->type==et_map ) {
571 0 : GDrawRaise(gw);
572 0 : } else if ( event->type == et_mousemove ||
573 0 : (event->type==et_mousedown && event->u.mouse.button==3 )) {
574 0 : struct gfc_data *d = GDrawGetUserData(gw);
575 0 : GFileChooserPopupCheck(d->gfc,event);
576 0 : } else if (( event->type==et_mouseup || event->type==et_mousedown ) &&
577 0 : (event->u.mouse.button>=4 && event->u.mouse.button<=7) ) {
578 0 : struct gfc_data *d = GDrawGetUserData(gw);
579 0 : return( GGadgetDispatchEvent((GGadget *) (d->gfc),event));
580 : }
581 0 : return( true );
582 : }
583 :
584 0 : static void _Import(CharView *cv,BitmapView *bv,FontView *fv) {
585 : GRect pos;
586 : GWindow gw;
587 : GWindowAttrs wattrs;
588 : GGadgetCreateData gcd[9], boxes[4], *varray[9], *harray[5], *buttons[10];
589 : GTextInfo label[9];
590 : struct gfc_data d;
591 : int i, format;
592 0 : int bs = GIntGetResource(_NUM_Buttonsize), bsbigger, totwid, scalewid;
593 : static int done= false;
594 : GTextInfo *cur_formats, *base;
595 :
596 0 : if ( !done ) {
597 0 : for ( i=0; formats[i].text!=NULL; ++i )
598 0 : formats[i].text = (unichar_t *) _((char *) formats[i].text);
599 0 : for ( i=0; fvformats[i].text!=NULL; ++i )
600 0 : fvformats[i].text = (unichar_t *) _((char *) fvformats[i].text);
601 0 : done = true;
602 : }
603 0 : base = cur_formats = fv==NULL?formats:fvformats;
604 : #ifndef _NO_PYTHON
605 0 : if ( py_ie!=NULL ) {
606 : int cnt, extras;
607 0 : for ( cnt=0; base[cnt].text!=NULL; ++cnt );
608 0 : for ( i=extras=0; py_ie[i].name!=NULL; ++i )
609 0 : if ( py_ie[i].import!=NULL )
610 0 : ++extras;
611 0 : if ( extras!=0 ) {
612 0 : cur_formats = calloc(extras+cnt+1,sizeof(GTextInfo));
613 0 : for ( cnt=0; base[cnt].text!=NULL; ++cnt ) {
614 0 : cur_formats[cnt] = base[cnt];
615 0 : cur_formats[cnt].text = (unichar_t *) copy( (char *) base[cnt].text );
616 : }
617 0 : for ( i=extras=0; py_ie[i].name!=NULL; ++i ) {
618 0 : if ( py_ie[i].import!=NULL ) {
619 0 : cur_formats[cnt+extras].text = (unichar_t *) copy(py_ie[i].name);
620 0 : cur_formats[cnt+extras].text_is_1byte = true;
621 0 : cur_formats[cnt+extras].userdata = (void *) (intpt) (fv_pythonbase+i);
622 0 : ++extras;
623 : }
624 : }
625 : }
626 : }
627 : #endif
628 0 : if ( !hasspiro()) {
629 0 : for ( i=0; cur_formats[i].text!=NULL; ++i )
630 0 : if ( ((intpt) cur_formats[i].userdata)==fv_plate ||
631 0 : ((intpt) cur_formats[i].userdata)==fv_platetemplate )
632 0 : cur_formats[i].disabled = true;
633 : }
634 :
635 0 : memset(&wattrs,0,sizeof(wattrs));
636 0 : wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_restrict|wam_isdlg;
637 0 : wattrs.event_masks = ~(1<<et_charup);
638 0 : wattrs.restrict_input_to_me = 1;
639 0 : wattrs.is_dlg = 1;
640 0 : wattrs.undercursor = 1;
641 0 : wattrs.cursor = ct_pointer;
642 0 : wattrs.utf8_window_title = _("Import");
643 0 : pos.x = pos.y = 0;
644 0 : totwid = 223;
645 0 : if ( fv!=NULL ) totwid += 60;
646 0 : scalewid = GGadgetScale(totwid);
647 0 : bsbigger = 3*bs+4*14>scalewid; scalewid = bsbigger?3*bs+4*12:scalewid;
648 0 : pos.width = GDrawPointsToPixels(NULL,scalewid);
649 0 : pos.height = GDrawPointsToPixels(NULL,255);
650 0 : gw = GDrawCreateTopWindow(NULL,&pos,e_h,&d,&wattrs);
651 :
652 0 : memset(&label,0,sizeof(label));
653 0 : memset(&gcd,0,sizeof(gcd));
654 0 : memset(&boxes,0,sizeof(boxes));
655 0 : gcd[0].gd.pos.x = 12; gcd[0].gd.pos.y = 6; gcd[0].gd.pos.width = totwid-24; gcd[0].gd.pos.height = 182;
656 0 : gcd[0].gd.flags = gg_visible | gg_enabled;
657 0 : if ( fv!=NULL )
658 0 : gcd[0].gd.flags |= gg_file_multiple;
659 0 : gcd[0].creator = GFileChooserCreate;
660 0 : varray[0] = &gcd[0]; varray[1] = NULL;
661 :
662 0 : gcd[1].gd.pos.x = 12; gcd[1].gd.pos.y = 224-3; gcd[1].gd.pos.width = -1; gcd[1].gd.pos.height = 0;
663 0 : gcd[1].gd.flags = gg_visible | gg_enabled | gg_but_default;
664 0 : label[1].text = (unichar_t *) _("_Import");
665 0 : label[1].text_is_1byte = true;
666 0 : label[1].text_in_resource = true;
667 0 : gcd[1].gd.label = &label[1];
668 0 : gcd[1].gd.handle_controlevent = GFD_ImportOk;
669 0 : gcd[1].creator = GButtonCreate;
670 0 : buttons[0] = GCD_Glue; buttons[1] = &gcd[1]; buttons[2] = GCD_Glue;
671 :
672 0 : gcd[2].gd.pos.x = (totwid-bs)*100/GIntGetResource(_NUM_ScaleFactor)/2; gcd[2].gd.pos.y = 224; gcd[2].gd.pos.width = -1; gcd[2].gd.pos.height = 0;
673 0 : gcd[2].gd.flags = gg_visible | gg_enabled;
674 0 : label[2].text = (unichar_t *) _("_Filter");
675 0 : label[2].text_is_1byte = true;
676 0 : label[2].text_in_resource = true;
677 0 : gcd[2].gd.mnemonic = 'F';
678 0 : gcd[2].gd.label = &label[2];
679 0 : gcd[2].gd.handle_controlevent = GFileChooserFilterEh;
680 0 : gcd[2].creator = GButtonCreate;
681 0 : buttons[3] = GCD_Glue; buttons[4] = &gcd[2]; buttons[5] = GCD_Glue;
682 :
683 0 : gcd[3].gd.pos.x = -gcd[1].gd.pos.x; gcd[3].gd.pos.y = 224; gcd[3].gd.pos.width = -1; gcd[3].gd.pos.height = 0;
684 0 : gcd[3].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
685 0 : label[3].text = (unichar_t *) _("_Cancel");
686 0 : label[3].text_is_1byte = true;
687 0 : label[3].text_in_resource = true;
688 0 : gcd[3].gd.label = &label[3];
689 0 : gcd[3].gd.handle_controlevent = GFD_Cancel;
690 0 : gcd[3].creator = GButtonCreate;
691 0 : buttons[6] = GCD_Glue; buttons[7] = &gcd[3]; buttons[8] = GCD_Glue;
692 0 : buttons[9] = NULL;
693 :
694 0 : gcd[4].gd.pos.x = 12; gcd[4].gd.pos.y = 200; gcd[4].gd.pos.width = 0; gcd[4].gd.pos.height = 0;
695 0 : gcd[4].gd.flags = gg_visible | gg_enabled;
696 0 : label[4].text = (unichar_t *) _("Format:");
697 0 : label[4].text_is_1byte = true;
698 0 : gcd[4].gd.label = &label[4];
699 0 : gcd[4].creator = GLabelCreate;
700 0 : harray[0] = &gcd[4];
701 :
702 0 : gcd[5].gd.pos.x = 55; gcd[5].gd.pos.y = 194;
703 0 : gcd[5].gd.flags = gg_visible | gg_enabled ;
704 0 : if ( bv!=NULL ) {
705 0 : gcd[5].gd.flags = gg_visible ; /* No postscript in bitmap mode */
706 0 : last_format=0;
707 : }
708 0 : format = fv==NULL?last_format:flast_format;
709 0 : gcd[5].gd.u.list = cur_formats;
710 0 : gcd[5].gd.label = &gcd[5].gd.u.list[format];
711 0 : gcd[5].gd.handle_controlevent = GFD_Format;
712 0 : gcd[5].creator = GListButtonCreate;
713 0 : for ( i=0; i<sizeof(formats)/sizeof(formats[0]); ++i )
714 0 : gcd[5].gd.u.list[i].selected = false;
715 0 : gcd[5].gd.u.list[format].selected = true;
716 0 : harray[1] = &gcd[5];
717 :
718 0 : if ( fv!=NULL ) {
719 0 : gcd[6].gd.pos.x = 185; gcd[6].gd.pos.y = gcd[5].gd.pos.y+4;
720 0 : gcd[6].gd.flags = gg_visible | gg_enabled ;
721 0 : if ( format==fv_pk || format==fv_image || format==fv_imgtemplate )
722 0 : gcd[6].gd.flags = gg_visible | gg_enabled | gg_cb_on;
723 0 : label[6].text = (unichar_t *) _("As Background");
724 0 : label[6].text_is_1byte = true;
725 0 : gcd[6].gd.label = &label[6];
726 0 : gcd[6].creator = GCheckBoxCreate;
727 0 : harray[2] = &gcd[6]; harray[3] = GCD_Glue; harray[4] = NULL;
728 : } else {
729 0 : harray[2] = GCD_Glue; harray[3] = NULL;
730 : }
731 :
732 0 : boxes[2].gd.flags = gg_enabled|gg_visible;
733 0 : boxes[2].gd.u.boxelements = harray;
734 0 : boxes[2].creator = GHBoxCreate;
735 0 : varray[2] = &boxes[2]; varray[3] = NULL;
736 :
737 0 : boxes[3].gd.flags = gg_enabled|gg_visible;
738 0 : boxes[3].gd.u.boxelements = buttons;
739 0 : boxes[3].creator = GHBoxCreate;
740 0 : varray[4] = GCD_Glue; varray[5] = NULL;
741 0 : varray[6] = &boxes[3]; varray[7] = NULL;
742 0 : varray[8] = NULL;
743 :
744 0 : boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2;
745 0 : boxes[0].gd.flags = gg_enabled|gg_visible;
746 0 : boxes[0].gd.u.boxelements = varray;
747 0 : boxes[0].creator = GHVGroupCreate;
748 :
749 0 : GGadgetsCreate(gw,boxes);
750 0 : GHVBoxSetExpandableRow(boxes[0].ret,gb_expandglue);
751 0 : GHVBoxSetExpandableCol(boxes[3].ret,gb_expandgluesame);
752 0 : GHVBoxSetExpandableCol(boxes[2].ret,gb_expandglue);
753 0 : GGadgetSetUserData(gcd[2].ret,gcd[0].ret);
754 :
755 0 : GFileChooserConnectButtons(gcd[0].ret,gcd[1].ret,gcd[2].ret);
756 0 : GFileChooserSetFilterText(gcd[0].ret,fv!=NULL?wildfnt[format]:wildchr[format]);
757 0 : GFileChooserRefreshList(gcd[0].ret);
758 0 : GHVBoxFitWindow(boxes[0].ret);
759 :
760 0 : memset(&d,'\0',sizeof(d));
761 0 : d.cv = cv;
762 0 : d.fv = fv;
763 0 : d.bv = bv;
764 0 : d.gfc = gcd[0].ret;
765 0 : d.format = gcd[5].ret;
766 0 : if ( fv!=NULL )
767 0 : d.background = gcd[6].ret;
768 :
769 0 : if ( cur_formats!=formats && cur_formats!=fvformats )
770 0 : GTextInfoListFree(cur_formats);
771 :
772 0 : GWidgetHidePalettes();
773 0 : GDrawSetVisible(gw,true);
774 0 : while ( !d.done )
775 0 : GDrawProcessOneEvent(NULL);
776 0 : GDrawDestroyWindow(gw);
777 0 : }
778 :
779 0 : void CVImport(CharView *cv) {
780 0 : _Import(cv,NULL,NULL);
781 0 : }
782 :
783 0 : void BVImport(BitmapView *bv) {
784 0 : _Import(NULL,bv,NULL);
785 0 : }
786 :
787 0 : void FVImport(FontView *fv) {
788 0 : _Import(NULL,NULL,fv);
789 0 : }
|