Debian Codegraph @

fontforgeexe/bdfinfo.c

raw symbols SCIP
1 /* -*- coding: utf-8 -*- */
2 /* Copyright (C) 2000-2012 by George Williams */
3 /*
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13
14 * The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <fontforge-config.h>
30
31 /* Routines to handle bdf properties, and a dialog to set them */
32 #include "bitmapchar.h"
33 #include "fontforgeui.h"
34 #include "gkeysym.h"
35 #include "gresedit.h"
36 #include "splinefill.h"
37 #include "splinefont.h"
38 #include "ustring.h"
39 #include "utype.h"
40
41 #include <math.h>
42 #include <string.h>
43
44 extern GBox _ggadget_Default_Box;
45 #define ACTIVE_BORDER (_ggadget_Default_Box.active_border)
46 #define MAIN_FOREGROUND (_ggadget_Default_Box.main_foreground)
47 extern Color showatt_selcol; // Yes this is cheating
48 extern Color fi_originlinescol; // So is this
49 extern Color kernclass_classfgcol; // and this
50
51 GResFont bdfprop_font = GRESFONT_INIT("400 10pt " SANS_UI_FAMILIES);
52
53 struct bdf_dlg_font {
54 int old_prop_cnt;
55 BDFProperties *old_props;
56 BDFFont *bdf;
57 int top_prop; /* for the scrollbar */
58 int sel_prop;
59 };
60
61 struct bdf_dlg {
62 int fcnt;
63 struct bdf_dlg_font *fonts;
64 struct bdf_dlg_font *cur;
65 EncMap *map;
66 SplineFont *sf;
67 GWindow gw, v;
68 GGadget *vsb;
69 GGadget *tf;
70 GFont *font;
71 int value_x;
72 int vheight;
73 int vwidth;
74 int height,width;
75 int fh, as;
76 int done;
77 int active;
78 int press_pos;
79 };
80
81 extern struct std_bdf_props StandardProps[];
82
83 static int NumericKey(char *key) {
84 int i;
85
86 for ( i=0; StandardProps[i].name!=NULL; ++i )
87 if ( strcmp(key,StandardProps[i].name)==0 )
88 return(( StandardProps[i].type&~prt_property)==prt_uint || ( StandardProps[i].type&~prt_property)==prt_int );
89
90 return( false );
91 }
92
93 static int KnownProp(char *keyword) { /* We can generate default values for these */
94 int i;
95
96 for ( i=0; StandardProps[i].name!=NULL; ++i )
97 if ( strcmp(keyword,StandardProps[i].name)==0 )
98 return( StandardProps[i].defaultable );
99
100 return( false );
101 }
102
103 static int KeyType(char *keyword) {
104 int i;
105
106 for ( i=0; StandardProps[i].name!=NULL; ++i )
107 if ( strcmp(keyword,StandardProps[i].name)==0 )
108 return( StandardProps[i].type );
109
110 return( -1 );
111 }
112
113 static int UnknownKey(char *keyword) {
114 int i;
115
116 for ( i=0; StandardProps[i].name!=NULL; ++i )
117 if ( strcmp(keyword,StandardProps[i].name)==0 )
118 return( false );
119
120 return( true );
121 }
122
123 /* ************************************************************************** */
124 /* ************ Dialog **************** */
125 /* ************************************************************************** */
126
127 #define CID_Delete 1001
128 #define CID_DefAll 1002
129 #define CID_DefCur 1003
130 #define CID_Up 1004
131 #define CID_Down 1005
132
133 #define CID_OK 1010
134 #define CID_Cancel 1011
135
136 static void BdfP_RefigureScrollbar(struct bdf_dlg *bd) {
137 struct bdf_dlg_font *cur = bd->cur;
138 int lines = bd->vheight/(bd->fh+1);
139
140 /* allow for one extra line which will display "New" */
141 GScrollBarSetBounds(bd->vsb,0,cur->bdf->prop_cnt+1,lines);
142 if ( cur->top_prop+lines>cur->bdf->prop_cnt+1 )
143 cur->top_prop = cur->bdf->prop_cnt+1-lines;
144 if ( cur->top_prop < 0 )
145 cur->top_prop = 0;
146 GScrollBarSetPos(bd->vsb,cur->top_prop);
147 }
148
149 static void BdfP_EnableButtons(struct bdf_dlg *bd) {
150 struct bdf_dlg_font *cur = bd->cur;
151
152 if ( cur->sel_prop<0 || cur->sel_prop>=cur->bdf->prop_cnt ) {
153 GGadgetSetEnabled(GWidgetGetControl(bd->gw,CID_Delete),false);
154 GGadgetSetEnabled(GWidgetGetControl(bd->gw,CID_DefCur),false);
155 GGadgetSetEnabled(GWidgetGetControl(bd->gw,CID_Up),false);
156 GGadgetSetEnabled(GWidgetGetControl(bd->gw,CID_Down),false);
157 } else {
158 GGadgetSetEnabled(GWidgetGetControl(bd->gw,CID_Delete),true);
159 GGadgetSetEnabled(GWidgetGetControl(bd->gw,CID_DefCur),KnownProp(cur->bdf->props[cur->sel_prop].name));
160 GGadgetSetEnabled(GWidgetGetControl(bd->gw,CID_Up),cur->sel_prop>0);
161 GGadgetSetEnabled(GWidgetGetControl(bd->gw,CID_Down),cur->sel_prop<cur->bdf->prop_cnt-1);
162 }
163 }
164
165 static void BdfP_HideTextField(struct bdf_dlg *bd) {
166 if ( bd->active ) {
167 bd->active = false;
168 GGadgetSetVisible(bd->tf,false);
169 }
170 }
171
172 static int BdfP_FinishTextField(struct bdf_dlg *bd) {
173 if ( bd->active ) {
174 char *text = GGadgetGetTitle8(bd->tf);
175 char *pt, *end;
176 int val;
177 struct bdf_dlg_font *cur = bd->cur;
178 BDFFont *bdf = cur->bdf;
179
180 for ( pt=text; *pt; ++pt )
181 if ( *pt&0x80 ) {
182 ff_post_error(_("Not ASCII"),_("All characters in the value must be in ASCII"));
183 free(text);
184 return( false );
185 }
186 val = strtol(text,&end,10);
187 if ( NumericKey(bdf->props[cur->sel_prop].name) ) {
188 if ( *end!='\0' ) {
189 ff_post_error(_("Bad Number"),_("Must be a number"));
190 free(text);
191 return( false );
192 }
193 }
194 if ( (bdf->props[cur->sel_prop].type&~prt_property)==prt_string ||
195 (bdf->props[cur->sel_prop].type&~prt_property)==prt_atom )
196 free(bdf->props[cur->sel_prop].u.str);
197 if ( UnknownKey(bdf->props[cur->sel_prop].name) ) {
198 if ( *end!='\0' ) {
199 bdf->props[cur->sel_prop].type = prt_string | prt_property;
200 bdf->props[cur->sel_prop].u.str = copy(text);
201 } else {
202 if ( bdf->props[cur->sel_prop].type != (prt_uint | prt_property ))
203 bdf->props[cur->sel_prop].type = prt_int | prt_property;
204 bdf->props[cur->sel_prop].u.val = val;
205 }
206 } else if ( NumericKey(bdf->props[cur->sel_prop].name) ) {
207 bdf->props[cur->sel_prop].type = KeyType(bdf->props[cur->sel_prop].name);
208 bdf->props[cur->sel_prop].u.val = val;
209 } else {
210 bdf->props[cur->sel_prop].type = KeyType(bdf->props[cur->sel_prop].name);
211 bdf->props[cur->sel_prop].u.str = copy(text);
212 }
213 free(text);
214 bd->active = false;
215 GGadgetSetVisible(bd->tf,false);
216 }
217 return( true );
218 }
219
220 static int BdfP_DefaultAll(GGadget *g, GEvent *e) {
221 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
222 struct bdf_dlg *bd = GDrawGetUserData(GGadgetGetWindow(g));
223 int res = BdfPropHasInt(bd->cur->bdf,"RESOLUTION_Y",-1);
224 if ( res!=-1 )
225 bd->cur->bdf->res = res;
226 BdfP_HideTextField(bd);
227 BDFPropsFree(bd->cur->bdf);
228 bd->cur->bdf->prop_cnt = bd->cur->bdf->prop_max = 0;
229 bd->cur->bdf->props = NULL;
230 BDFDefaultProps(bd->cur->bdf, bd->map, -1);
231 bd->cur->top_prop = 0; bd->cur->sel_prop = -1;
232 BdfP_RefigureScrollbar(bd);
233 BdfP_EnableButtons(bd);
234 GDrawRequestExpose(bd->v,NULL,false);
235 }
236 return( true );
237 }
238
239 static void _BdfP_DefaultCurrent(struct bdf_dlg *bd) {
240 struct bdf_dlg_font *cur = bd->cur;
241 BDFFont *bdf = cur->bdf;
242 if ( cur->sel_prop<0 || cur->sel_prop>=bdf->prop_cnt )
243 return;
244 BdfP_HideTextField(bd);
245 if ( strcmp(bdf->props[cur->sel_prop].name,"FONT")==0 ) {
246 Default_XLFD(bdf,bd->map,-1);
247 } else if ( strcmp(bdf->props[cur->sel_prop].name,"COMMENT")==0 )
248 return;
249 else
250 Default_Properties(bdf,bd->map,bdf->props[cur->sel_prop].name);
251 GDrawRequestExpose(bd->v,NULL,false);
252 return;
253 }
254
255 static int BdfP_DefaultCurrent(GGadget *g, GEvent *e) {
256 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
257 struct bdf_dlg *bd = GDrawGetUserData(GGadgetGetWindow(g));
258 _BdfP_DefaultCurrent(bd);
259 }
260 return( true );
261 }
262
263 static int BdfP_DeleteCurrent(GGadget *g, GEvent *e) {
264 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
265 struct bdf_dlg *bd = GDrawGetUserData(GGadgetGetWindow(g));
266 struct bdf_dlg_font *cur = bd->cur;
267 BDFFont *bdf = cur->bdf;
268 int i;
269 if ( cur->sel_prop<0 || cur->sel_prop>=bdf->prop_cnt )
270 return( true );
271 BdfP_HideTextField(bd);
272 if ( (bdf->props[cur->sel_prop].type&~prt_property)==prt_string ||
273 (bdf->props[cur->sel_prop].type&~prt_property)==prt_atom )
274 free(bdf->props[cur->sel_prop].u.str);
275 free(bdf->props[cur->sel_prop].name);
276 --bdf->prop_cnt;
277 for ( i=cur->sel_prop; i<bdf->prop_cnt; ++i )
278 bdf->props[i] = bdf->props[i+1];
279 if ( cur->sel_prop >= bdf->prop_cnt )
280 --cur->sel_prop;
281 BdfP_RefigureScrollbar(bd);
282 BdfP_EnableButtons(bd);
283 GDrawRequestExpose(bd->v,NULL,false);
284 }
285 return( true );
286 }
287
288 static void _BdfP_Up(struct bdf_dlg *bd) {
289 struct bdf_dlg_font *cur = bd->cur;
290 BDFFont *bdf = cur->bdf;
291 GRect r;
292 BDFProperties prop;
293 if ( cur->sel_prop<1 || cur->sel_prop>=bdf->prop_cnt )
294 return;
295 prop = bdf->props[cur->sel_prop];
296 bdf->props[cur->sel_prop] = bdf->props[cur->sel_prop-1];
297 bdf->props[cur->sel_prop-1] = prop;
298 --cur->sel_prop;
299 GGadgetGetSize(bd->tf,&r);
300 GGadgetMove(bd->tf,r.x,r.y-(bd->fh+1));
301 BdfP_EnableButtons(bd);
302 GDrawRequestExpose(bd->v,NULL,false);
303 }
304
305 static int BdfP_Up(GGadget *g, GEvent *e) {
306 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
307 _BdfP_Up( GDrawGetUserData(GGadgetGetWindow(g)));
308 }
309 return( true );
310 }
311
312 static void _BdfP_Down(struct bdf_dlg *bd) {
313 struct bdf_dlg_font *cur = bd->cur;
314 BDFFont *bdf = cur->bdf;
315 GRect r;
316 BDFProperties prop;
317 if ( cur->sel_prop<0 || cur->sel_prop>=bdf->prop_cnt-1 )
318 return;
319 prop = bdf->props[cur->sel_prop];
320 bdf->props[cur->sel_prop] = bdf->props[cur->sel_prop+1];
321 bdf->props[cur->sel_prop+1] = prop;
322 ++cur->sel_prop;
323 GGadgetGetSize(bd->tf,&r);
324 GGadgetMove(bd->tf,r.x,r.y+(bd->fh+1));
325 BdfP_EnableButtons(bd);
326 GDrawRequestExpose(bd->v,NULL,false);
327 return;
328 }
329
330 static int BdfP_Down(GGadget *g, GEvent *e) {
331 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
332 _BdfP_Down((struct bdf_dlg *) GDrawGetUserData(GGadgetGetWindow(g)));
333 }
334 return( true );
335 }
336
337 static int BdfP_ChangeBDF(GGadget *g, GEvent *e) {
338 if ( e->type==et_controlevent && e->u.control.subtype == et_listselected ) {
339 struct bdf_dlg *bd = GDrawGetUserData(GGadgetGetWindow(g));
340 int sel = GGadgetGetFirstListSelectedItem(g);
341 if ( sel<0 || sel>=bd->fcnt )
342 return( true );
343 if ( !BdfP_FinishTextField(bd)) {
344 sel = bd->cur-bd->fonts;
345 GGadgetSelectListItem(g,sel,true);
346 return( true );
347 }
348 bd->cur = &bd->fonts[sel];
349 BdfP_RefigureScrollbar(bd);
350 BdfP_EnableButtons(bd);
351 GDrawRequestExpose(bd->v,NULL,false);
352 }
353 return( true );
354 }
355
356 static void BdfP_DoCancel(struct bdf_dlg *bd) {
357 int i;
358 for ( i=0; i<bd->fcnt; ++i ) {
359 BDFFont *bdf = bd->fonts[i].bdf;
360 BDFPropsFree(bdf);
361 bdf->props = bd->fonts[i].old_props;
362 bdf->prop_cnt = bd->fonts[i].old_prop_cnt;
363 }
364 free(bd->fonts);
365 bd->done = true;
366 }
367
368 static int BdfP_Cancel(GGadget *g, GEvent *e) {
369 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
370 struct bdf_dlg *bd = GDrawGetUserData(GGadgetGetWindow(g));
371 BdfP_DoCancel(bd);
372 }
373 return( true );
374 }
375
376 static int BdfP_OK(GGadget *g, GEvent *e) {
377 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
378 struct bdf_dlg *bd = GDrawGetUserData(GGadgetGetWindow(g));
379 int i;
380 struct xlfd_components components;
381 const char *xlfd;
382
383 if ( !BdfP_FinishTextField(bd))
384 return( true );
385 for ( i=0; i<bd->fcnt; ++i ) {
386 BDFFont *bdf = bd->fonts[i].bdf;
387 BDFProperties *temp = bdf->props;
388 int pc = bdf->prop_cnt;
389 bdf->props = bd->fonts[i].old_props;
390 bdf->prop_cnt = bd->fonts[i].old_prop_cnt;
391 BDFPropsFree(bdf);
392 bdf->props = temp;
393 bdf->prop_cnt = pc;
394
395 xlfd = BdfPropHasString(bdf,"FONT",NULL);
396 if ( xlfd!=NULL )
397 XLFD_GetComponents(xlfd,&components);
398 else
399 XLFD_CreateComponents(bdf,bd->map, -1, &components);
400 bdf->res = components.res_y;
401 }
402 free(bd->fonts);
403 bd->sf->changed = true;
404 bd->done = true;
405 }
406 return( true );
407 }
408
409 static void BdfP_VScroll(struct bdf_dlg *bd,struct sbevent *sb) {
410 int newpos = bd->cur->top_prop;
411 int page = bd->vheight/(bd->fh+1);
412
413 switch( sb->type ) {
414 case et_sb_top:
415 newpos = 0;
416 break;
417 case et_sb_uppage:
418 newpos -= 9*page/10;
419 break;
420 case et_sb_up:
421 newpos--;
422 break;
423 case et_sb_down:
424 newpos++;
425 break;
426 case et_sb_downpage:
427 newpos += 9*page/10;
428 break;
429 case et_sb_bottom:
430 newpos = bd->cur->bdf->prop_cnt+1;
431 break;
432 case et_sb_thumb:
433 case et_sb_thumbrelease:
434 newpos = sb->pos;
435 break;
436 case et_sb_halfup: case et_sb_halfdown: break;
437 }
438 if ( newpos + page > bd->cur->bdf->prop_cnt+1 )
439 newpos = bd->cur->bdf->prop_cnt+1 - page;
440 if ( newpos<0 )
441 newpos = 0;
442 if ( newpos!=bd->cur->top_prop ) {
443 int diff = (newpos-bd->cur->top_prop)*(bd->fh+1);
444 GRect r;
445 bd->cur->top_prop = newpos;
446 GScrollBarSetPos(bd->vsb,newpos);
447 GGadgetGetSize(bd->tf,&r);
448 GGadgetMove(bd->tf,r.x,r.y+diff);
449 r.x = 0; r.y = 0; r.width = bd->vwidth; r.height = (bd->vheight/(bd->fh+1))*(bd->fh+1);
450 GDrawScroll(bd->v,&r,0,diff);
451 }
452 }
453
454 static int _BdfP_VScroll(GGadget *g, GEvent *e) {
455 if ( e->type==et_controlevent && e->u.control.subtype == et_scrollbarchange ) {
456 struct bdf_dlg *bd = (struct bdf_dlg *) GDrawGetUserData(GGadgetGetWindow(g));
457 BdfP_VScroll(bd,&e->u.control.u.sb);
458 }
459 return( true );
460 }
461
462 static void BdfP_Resize(struct bdf_dlg *bd) {
463 extern int _GScrollBar_Width;
464 int sbwidth = GDrawPointsToPixels(bd->gw,_GScrollBar_Width);
465 GRect size, pos;
466 static int cids[] = { CID_Delete, CID_DefAll, CID_DefCur, CID_Up,
467 CID_Down, CID_OK, CID_Cancel, 0 };
468 int i;
469
470 GDrawGetSize(bd->gw,&size);
471 GDrawGetSize(bd->v,&pos);
472 if ( size.width!=bd->width || size.height!=bd->height ) {
473 int yoff = size.height-bd->height;
474 int xoff = size.width-bd->width;
475 bd->width = size.width; bd->height = size.height;
476 bd->vwidth += xoff; bd->vheight += yoff;
477 GDrawResize(bd->v,bd->vwidth,bd->vheight);
478
479 GGadgetMove(bd->vsb,size.width-sbwidth,pos.y-1);
480 GGadgetResize(bd->vsb,sbwidth,bd->vheight+2);
481
482 GGadgetGetSize(bd->tf,&pos);
483 GGadgetResize(bd->tf,pos.width+xoff,pos.height);
484
485 for ( i=0; cids[i]!=0; ++i ) {
486 GGadgetGetSize(GWidgetGetControl(bd->gw,cids[i]),&pos);
487 GGadgetMove(GWidgetGetControl(bd->gw,cids[i]),pos.x,pos.y+yoff);
488 }
489 }
490 BdfP_RefigureScrollbar(bd);
491 GDrawRequestExpose(bd->v,NULL,false);
492 GDrawRequestExpose(bd->gw,NULL,true);
493 }
494
495 static void BdfP_Expose(struct bdf_dlg *bd, GWindow pixmap) {
496 struct bdf_dlg_font *cur = bd->cur;
497 BDFFont *bdf = cur->bdf;
498 int i;
499 int page = bd->vheight/(bd->fh+1);
500 GRect clip, old, r;
501 char buffer[40];
502 extern GBox _ggadget_Default_Box;
503
504 GDrawSetFont(pixmap,bd->font);
505 clip.x = 4; clip.width = bd->value_x-4-2; clip.height = bd->fh;
506 for ( i=0; i<page && i+cur->top_prop<bdf->prop_cnt; ++i ) {
507 int sel = i+cur->top_prop==cur->sel_prop;
508 clip.y = i*(bd->fh+1);
509 if ( sel ) {
510 r.x = 0; r.width = bd->width;
511 r.y = clip.y; r.height = clip.height;
512 GDrawFillRect(pixmap,&r,ACTIVE_BORDER);
513 }
514 GDrawPushClip(pixmap,&clip,&old);
515 GDrawDrawText8(pixmap,4,i*(bd->fh+1)+bd->as,bdf->props[i+cur->top_prop].name,-1,MAIN_FOREGROUND);
516 GDrawPopClip(pixmap,&old);
517 switch ( bdf->props[i+cur->top_prop].type&~prt_property ) {
518 case prt_string: case prt_atom:
519 GDrawDrawText8(pixmap,bd->value_x+2,i*(bd->fh+1)+bd->as,bdf->props[i+cur->top_prop].u.str,-1,MAIN_FOREGROUND);
520 break;
521 case prt_int:
522 sprintf( buffer, "%d", bdf->props[i+cur->top_prop].u.val );
523 GDrawDrawText8(pixmap,bd->value_x+2,i*(bd->fh+1)+bd->as,buffer,-1,MAIN_FOREGROUND);
524 break;
525 case prt_uint:
526 sprintf( buffer, "%u", (unsigned) bdf->props[i+cur->top_prop].u.val );
527 GDrawDrawText8(pixmap,bd->value_x+2,i*(bd->fh+1)+bd->as,buffer,-1,MAIN_FOREGROUND);
528 break;
529 }
530 GDrawDrawLine(pixmap,0,i*(bd->fh+1)+bd->fh,bd->vwidth,i*(bd->fh+1)+bd->fh,fi_originlinescol);
531 }
532 if ( i<page ) {
533 /* GT: I am told that the use of "|" to provide contextual information in a */
534 /* GT: gettext string is non-standard. However it is documented in section */
535 /* GT: 10.2.6 of http://www.gnu.org/software/gettext/manual/html_mono/gettext.html */
536 /* GT: */
537 /* GT: Anyway here the word "Property" is used to provide context for "New..." and */
538 /* GT: the translator should only translate "New...". This is necessary because in */
539 /* GT: French (or any language where adjectives agree in gender/number with their */
540 /* GT: nouns) there are several different forms of "New" and the one chose depends */
541 /* GT: on the noun in question. */
542 /* GT: A french translation might be either msgstr "Nouveau..." or msgstr "Nouvelle..." */
543 /* GT: */
544 /* GT: I expect there are more cases where one english word needs to be translated */
545 /* GT: by several different words in different languages (in Japanese a different */
546 /* GT: word is used for the latin script and the latin language) and that you, as */
547 /* GT: a translator may need to ask me to disambiguate more strings. Please do so: */
548 /* GT: <[email protected]> */
549 GDrawDrawText8(pixmap,4,i*(bd->fh+1)+bd->as,S_("Property|New..."),-1,showatt_selcol);
550 GDrawDrawLine(pixmap,0,i*(bd->fh+1)+bd->fh,bd->vwidth,i*(bd->fh+1)+bd->fh, _ggadget_Default_Box.border_darker);
551 }
552 GDrawDrawLine(pixmap,bd->value_x,0,bd->value_x,bd->vheight, _ggadget_Default_Box.border_darker);
553 }
554
555 static void BdfP_Invoked(GWindow v, GMenuItem *mi, GEvent *e) {
556 struct bdf_dlg *bd = (struct bdf_dlg *) GDrawGetUserData(v);
557 BDFFont *bdf = bd->cur->bdf;
558 char *prop_name = cu_copy(mi->ti.text);
559 int sel = bd->cur->sel_prop;
560 int i;
561
562 if ( sel>=bdf->prop_cnt ) {
563 /* Create a new one */
564 if ( bdf->prop_cnt>=bdf->prop_max )
565 bdf->props = realloc(bdf->props,(bdf->prop_max+=10)*sizeof(BDFProperties));
566 sel = bd->cur->sel_prop = bdf->prop_cnt++;
567 bdf->props[sel].name = prop_name;
568 for ( i=0; StandardProps[i].name!=NULL; ++i )
569 if ( strcmp(prop_name,StandardProps[i].name)==0 )
570 break;
571 if ( StandardProps[i].name!=NULL ) {
572 bdf->props[sel].type = StandardProps[i].type;
573 if ( (bdf->props[sel].type&~prt_property)==prt_string ||
574 (bdf->props[sel].type&~prt_property)==prt_atom)
575 bdf->props[sel].u.str = NULL;
576 else
577 bdf->props[sel].u.val = 0;
578 if ( StandardProps[i].defaultable )
579 _BdfP_DefaultCurrent(bd);
580 else if ( (bdf->props[sel].type&~prt_property)==prt_string ||
581 (bdf->props[sel].type&~prt_property)==prt_atom)
582 bdf->props[sel].u.str = copy("");
583 } else {
584 bdf->props[sel].type = prt_property|prt_string;
585 bdf->props[sel].u.str = copy("");
586 }
587 } else {
588 free(bdf->props[sel].name);
589 bdf->props[sel].name = prop_name;
590 }
591 GDrawRequestExpose(bd->v,NULL,false);
592 }
593
594 static void BdfP_PopupMenuProps(struct bdf_dlg *bd, GEvent *e) {
595 GMenuItem *mi;
596 int i;
597
598 for ( i=0 ; StandardProps[i].name!=NULL; ++i );
599 mi = calloc(i+3,sizeof(GMenuItem));
600 mi[0].ti.text = (unichar_t *) _("No Change");
601 mi[0].ti.text_is_1byte = true;
602 mi[0].ti.fg = COLOR_DEFAULT;
603 mi[0].ti.bg = COLOR_DEFAULT;
604
605 mi[1].ti.line = true;
606 mi[1].ti.fg = COLOR_DEFAULT;
607 mi[1].ti.bg = COLOR_DEFAULT;
608
609 for ( i=0 ; StandardProps[i].name!=NULL; ++i ) {
610 mi[i+2].ti.text = (unichar_t *) StandardProps[i].name; /* These do not translate!!! */
611 mi[i+2].ti.text_is_1byte = true;
612 mi[i+2].ti.fg = COLOR_DEFAULT;
613 mi[i+2].ti.bg = COLOR_DEFAULT;
614 mi[i+2].invoke = BdfP_Invoked;
615 }
616
617 GMenuCreatePopupMenu(bd->v,e,mi);
618 free(mi);
619 }
620
621 static void BdfP_Mouse(struct bdf_dlg *bd, GEvent *e) {
622 int line = e->u.mouse.y/(bd->fh+1) + bd->cur->top_prop;
623
624 if ( line<0 || line>bd->cur->bdf->prop_cnt )
625 return; /* "New" happens when line==bd->cur->bdf->prop_cnt */
626 if ( e->type == et_mousedown ) {
627 if ( !BdfP_FinishTextField(bd) ) {
628 bd->press_pos = -1;
629 return;
630 }
631 if ( e->u.mouse.x>=4 && e->u.mouse.x<= bd->value_x ) {
632 bd->cur->sel_prop = line;
633 BdfP_PopupMenuProps(bd,e);
634 BdfP_EnableButtons(bd);
635 } else if ( line>=bd->cur->bdf->prop_cnt )
636 return;
637 else {
638 bd->press_pos = line;
639 bd->cur->sel_prop = -1;
640 GDrawRequestExpose(bd->v,NULL,false );
641 }
642 } else if ( e->type == et_mouseup ) {
643 int pos = bd->press_pos;
644 bd->press_pos = -1;
645 if ( line>=bd->cur->bdf->prop_cnt || line!=pos )
646 return;
647 if ( bd->active ) /* Should never happen */
648 return;
649 bd->cur->sel_prop = line;
650 if ( e->u.mouse.x > bd->value_x ) {
651 BDFFont *bdf = bd->cur->bdf;
652 GGadgetMove(bd->tf,bd->value_x+2,(line-bd->cur->top_prop)*(bd->fh+1));
653 if ( (bdf->props[line].type&~prt_property) == prt_int ||
654 (bdf->props[line].type&~prt_property) == prt_uint ) {
655 char buffer[40];
656 sprintf( buffer,"%d",bdf->props[line].u.val );
657 GGadgetSetTitle8(bd->tf,buffer);
658 } else
659 GGadgetSetTitle8(bd->tf,bdf->props[line].u.str );
660 GGadgetSetVisible(bd->tf,true);
661 bd->active = true;
662 }
663 GDrawRequestExpose(bd->v,NULL,false );
664 }
665 }
666
667 static int BdfP_Char(struct bdf_dlg *bd, GEvent *e) {
668 if ( bd->active || bd->cur->sel_prop==-1 )
669 return( false );
670 switch ( e->u.chr.keysym ) {
671 case GK_Up: case GK_KP_Up:
672 _BdfP_Up(bd);
673 return( true );
674 case GK_Down: case GK_KP_Down:
675 _BdfP_Down(bd);
676 return( true );
677 default:
678 return( false );
679 }
680 }
681
682 static int bdfpv_e_h(GWindow gw, GEvent *event) {
683 struct bdf_dlg *bd = GDrawGetUserData(gw);
684 if ( event->type==et_expose ) {
685 BdfP_Expose(bd,gw);
686 } else if ( event->type == et_char ) {
687 return( BdfP_Char(bd,event));
688 } else if ( event->type == et_mousedown || event->type == et_mouseup || event->type==et_mousemove ) {
689 BdfP_Mouse(bd,event);
690 if ( event->type == et_mouseup )
691 BdfP_EnableButtons(bd);
692 }
693 return( true );
694 }
695
696 static int bdfp_e_h(GWindow gw, GEvent *event) {
697 struct bdf_dlg *bd = GDrawGetUserData(gw);
698 if ( event->type==et_close ) {
699 BdfP_DoCancel(bd);
700 } else if ( event->type == et_expose ) {
701 GRect r;
702 GDrawGetSize(bd->v,&r);
703 GDrawDrawLine(gw,0,r.y-1,bd->width,r.y-1,fi_originlinescol);
704 GDrawDrawLine(gw,0,r.y+r.height,bd->width,r.y+r.height,fi_originlinescol);
705 } else if ( event->type == et_char ) {
706 return( BdfP_Char(bd,event));
707 } else if ( event->type == et_resize ) {
708 BdfP_Resize(bd);
709 }
710 return( true );
711 }
712
713 void SFBdfProperties(SplineFont *sf, EncMap *map, BDFFont *thisone) {
714 struct bdf_dlg bd;
715 int i;
716 BDFFont *bdf;
717 GTextInfo *ti;
718 char buffer[40];
719 char title[130];
720 GRect pos, subpos;
721 GWindow gw;
722 GWindowAttrs wattrs;
723 GGadgetCreateData gcd[10];
724 GTextInfo label[9];
725 extern int _GScrollBar_Width;
726 int sbwidth;
727 static GBox small = GBOX_EMPTY;
728 GGadgetData gd;
729 /* I don't use a MatrixEdit here because I want to be able to display */
730 /* non-standard properties. And a MatrixEdit can only display things in */
731 /* its pull-down list */
732
733 memset(&bd,0,sizeof(bd));
734 bd.map = map;
735 bd.sf = sf;
736 for ( bdf = sf->bitmaps, i=0; bdf!=NULL; bdf=bdf->next, ++i );
737 if ( i==0 )
738 return;
739 bd.fcnt = i;
740 bd.fonts = calloc(i,sizeof(struct bdf_dlg_font));
741 bd.cur = &bd.fonts[0];
742 for ( bdf = sf->bitmaps, i=0; bdf!=NULL; bdf=bdf->next, ++i ) {
743 bd.fonts[i].bdf = bdf;
744 bd.fonts[i].old_prop_cnt = bdf->prop_cnt;
745 bd.fonts[i].old_props = BdfPropsCopy(bdf->props,bdf->prop_cnt);
746 bd.fonts[i].sel_prop = -1;
747 bdf->prop_max = bdf->prop_cnt;
748 if ( bdf==thisone )
749 bd.cur = &bd.fonts[i];
750 }
751
752 ti = calloc((i+1),sizeof(GTextInfo));
753 for ( bdf = sf->bitmaps, i=0; bdf!=NULL; bdf=bdf->next, ++i ) {
754 if ( bdf->clut==NULL )
755 sprintf( buffer, "%d", bdf->pixelsize );
756 else
757 sprintf( buffer, "%d@%d", bdf->pixelsize, BDFDepth(bdf));
758 ti[i].text = (unichar_t *) copy(buffer);
759 ti[i].text_is_1byte = true;
760 }
761 ti[bd.cur-bd.fonts].selected = true;
762
763 memset(&wattrs,0,sizeof(wattrs));
764 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict;
765 wattrs.event_masks = ~(1<<et_charup);
766 wattrs.is_dlg = true;
767 wattrs.restrict_input_to_me = 1;
768 wattrs.undercursor = 1;
769 wattrs.cursor = ct_pointer;
770 snprintf(title,sizeof(title),_("Strike Information for %.90s"),
771 sf->fontname);
772 wattrs.utf8_window_title = title;
773 pos.x = pos.y = 0;
774 pos.width = GDrawPointsToPixels(NULL,GGadgetScale(268));
775 pos.height = GDrawPointsToPixels(NULL,375);
776 bd.gw = gw = GDrawCreateTopWindow(NULL,&pos,bdfp_e_h,&bd,&wattrs);
777
778 /* TODO(iorsh): Show read-only BDF properties which are not stored in
779 BDFFont::props, e.g. "FONT_ASCENT", "FONT_DESCENT". */
780 sbwidth = GDrawPointsToPixels(bd.gw,_GScrollBar_Width);
781 subpos.x = 0; subpos.y = GDrawPointsToPixels(NULL,28);
782 subpos.width = pos.width-sbwidth;
783 subpos.height = pos.height - subpos.y - GDrawPointsToPixels(NULL,70);
784 wattrs.mask = wam_events;
785 bd.v = GWidgetCreateSubWindow(gw,&subpos,bdfpv_e_h,&bd,&wattrs);
786 bd.vwidth = subpos.width; bd.vheight = subpos.height;
787 bd.width = pos.width; bd.height = pos.height;
788 bd.value_x = GDrawPointsToPixels(bd.gw,135);
789
790 bd.font = bdfprop_font.fi;
791 {
792 int as, ds, ld;
793 GDrawWindowFontMetrics(gw,bd.font,&as,&ds,&ld);
794 bd.as = as; bd.fh = as+ds;
795 }
796
797 memset(gcd,0,sizeof(gcd));
798 memset(label,0,sizeof(label));
799
800 i=0;
801 gcd[i].gd.pos.x = 10; gcd[i].gd.pos.y = 3;
802 gcd[i].gd.flags = gg_visible | gg_enabled;
803 gcd[i].gd.u.list = ti;
804 gcd[i].gd.handle_controlevent = BdfP_ChangeBDF;
805 gcd[i++].creator = GListButtonCreate;
806
807 gcd[i].gd.pos.x = bd.vwidth; gcd[i].gd.pos.y = subpos.y-1;
808 gcd[i].gd.pos.width = sbwidth; gcd[i].gd.pos.height = subpos.height+2;
809 gcd[i].gd.flags = gg_visible | gg_enabled | gg_sb_vert | gg_pos_in_pixels;
810 gcd[i].gd.handle_controlevent = _BdfP_VScroll;
811 gcd[i++].creator = GScrollBarCreate;
812
813 label[i].text = (unichar_t *) _("Delete");
814 label[i].text_is_1byte = true;
815 gcd[i].gd.label = &label[i];
816 gcd[i].gd.pos.x = 4; gcd[i].gd.pos.y = GDrawPixelsToPoints(gw,subpos.y+subpos.height)+6;
817 gcd[i].gd.flags = gg_visible | gg_enabled ;
818 gcd[i].gd.handle_controlevent = BdfP_DeleteCurrent;
819 gcd[i].gd.cid = CID_Delete;
820 gcd[i++].creator = GButtonCreate;
821
822 label[i].text = (unichar_t *) _("Default All");
823 label[i].text_is_1byte = true;
824 gcd[i].gd.label = &label[i];
825 gcd[i].gd.pos.x = 80; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y;
826 gcd[i].gd.flags = gg_visible | gg_enabled ;
827 gcd[i].gd.handle_controlevent = BdfP_DefaultAll;
828 gcd[i].gd.cid = CID_DefAll;
829 gcd[i++].creator = GButtonCreate;
830
831 label[i].text = (unichar_t *) _("Default This");
832 label[i].text_is_1byte = true;
833 gcd[i].gd.label = &label[i];
834 gcd[i].gd.pos.y = gcd[i-1].gd.pos.y;
835 gcd[i].gd.flags = gg_visible | gg_enabled ;
836 gcd[i].gd.handle_controlevent = BdfP_DefaultCurrent;
837 gcd[i].gd.cid = CID_DefCur;
838 gcd[i++].creator = GButtonCreate;
839
840 /* I want the 2 pronged arrow, but gdraw can't find a nice one */
841 /* label[i].text = (unichar_t *) "⇑"; *//* Up Arrow */
842 label[i].text = (unichar_t *) "↑"; /* Up Arrow */
843 label[i].text_is_1byte = true;
844 gcd[i].gd.label = &label[i];
845 gcd[i].gd.pos.y = gcd[i-1].gd.pos.y;
846 gcd[i].gd.flags = gg_visible | gg_enabled ;
847 gcd[i].gd.handle_controlevent = BdfP_Up;
848 gcd[i].gd.cid = CID_Up;
849 gcd[i++].creator = GButtonCreate;
850
851 /* I want the 2 pronged arrow, but gdraw can't find a nice one */
852 /* label[i].text = (unichar_t *) "⇓"; *//* Down Arrow */
853 label[i].text = (unichar_t *) "↓"; /* Down Arrow */
854 label[i].text_is_1byte = true;
855 gcd[i].gd.label = &label[i];
856 gcd[i].gd.pos.y = gcd[i-1].gd.pos.y;
857 gcd[i].gd.flags = gg_visible | gg_enabled ;
858 gcd[i].gd.handle_controlevent = BdfP_Down;
859 gcd[i].gd.cid = CID_Down;
860 gcd[i++].creator = GButtonCreate;
861
862
863 gcd[i].gd.pos.x = 30-3; gcd[i].gd.pos.y = GDrawPixelsToPoints(NULL,pos.height)-32-3;
864 gcd[i].gd.pos.width = -1; gcd[i].gd.pos.height = 0;
865 gcd[i].gd.flags = gg_visible | gg_enabled | gg_but_default;
866 label[i].text = (unichar_t *) _("_OK");
867 label[i].text_is_1byte = true;
868 label[i].text_in_resource = true;
869 gcd[i].gd.label = &label[i];
870 gcd[i].gd.handle_controlevent = BdfP_OK;
871 gcd[i].gd.cid = CID_OK;
872 gcd[i++].creator = GButtonCreate;
873
874 gcd[i].gd.pos.x = -30; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y+3;
875 gcd[i].gd.pos.width = -1; gcd[i].gd.pos.height = 0;
876 gcd[i].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
877 label[i].text = (unichar_t *) _("_Cancel");
878 label[i].text_is_1byte = true;
879 label[i].text_in_resource = true;
880 gcd[i].gd.label = &label[i];
881 gcd[i].gd.handle_controlevent = BdfP_Cancel;
882 gcd[i].gd.cid = CID_Cancel;
883 gcd[i++].creator = GButtonCreate;
884
885 GGadgetsCreate(gw,gcd);
886 GTextInfoListFree(gcd[0].gd.u.list);
887 bd.vsb = gcd[1].ret;
888
889 small.main_background = small.main_foreground = COLOR_DEFAULT;
890 small.main_foreground = kernclass_classfgcol;
891 memset(&gd,'\0',sizeof(gd));
892 memset(&label[0],'\0',sizeof(label[0]));
893
894 label[0].text = (unichar_t *) "\0\0\0\0";
895 label[0].font = bd.font;
896 gd.pos.height = bd.fh;
897 gd.pos.width = bd.vwidth-bd.value_x;
898 gd.label = &label[0];
899 gd.box = &small;
900 gd.flags = gg_enabled | gg_pos_in_pixels | gg_dontcopybox | gg_text_xim;
901 bd.tf = GTextFieldCreate(bd.v,&gd,&bd);
902
903 bd.press_pos = -1;
904 BdfP_EnableButtons(&bd);
905 BdfP_RefigureScrollbar(&bd);
906
907 GDrawSetVisible(bd.v,true);
908 GDrawSetVisible(gw,true);
909 while ( !bd.done )
910 GDrawProcessOneEvent(NULL);
911 GDrawDestroyWindow(gw);
912 }