Debian Codegraph @

fontforgeexe/contextchain.c

raw symbols SCIP
1 /* Copyright (C) 2003-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
28 #include <fontforge-config.h>
29
30 #include "asmfpst.h"
31 #include "fontforgeui.h"
32 #include "gkeysym.h"
33 #include "lookups.h"
34 #include "splineutil.h"
35 #include "ustring.h"
36 #include "utype.h"
37
38 /* Currently uses class numbers rather than names!!!!!! */
39
40 /* ************************************************************************** */
41 /* ************************ Context/Chaining Dialog ************************* */
42 /* ************************************************************************** */
43 enum activewindow { aw_formats, aw_coverage, aw_grules, aw_glyphs,
44 aw_classrules, aw_classnumber,
45 aw_coverage_simple, aw_glyphs_simple, aw_classes_simple };
46 struct contextchaindlg {
47 struct gfi_data *gfi;
48 SplineFont *sf;
49 FPST *fpst;
50 unichar_t *newname;
51 int isnew;
52 GWindow gw;
53 GWindow formats, coverage, grules, glyphs, classrules, classnumber;
54 GWindow coverage_simple, glyphs_simple, classes_simple;
55 enum activewindow aw;
56 /* Wizard panes:
57 formats -- gives user a choice between by glyph/class/coverage table
58 Simple version:
59 glyphs_simple -- user picked glyph format, shows a matrix edit of glyph lists
60 and lookups.
61 classes_simple -- user picked class format. shows a matrix edit of class lists
62 with lookups. Also the three sets of classes_simple.
63 coverage_simple -- user picked coverage table format. shows a matrix edit with
64 a bunch of coverage tables and lookups/replacements.
65 [coverage_simple format only accepts 1 rule]
66 Complex version:
67 grules -- user picked glyph format, shows a list of glyph lists and with
68 lookups. Editing a glyph list takes us to the glyphs pane
69 classrules -- user picked class format. shows a list of class lists with
70 lookups. Also a tabbed widget showing the three sets of
71 classes.
72 coverage -- user picked coverage table format. shows a tabbed widget with
73 three lists of coverage tables. (for match also shows a
74 set of sequence #/lookup pairs.
75 [There is no coveragerules pane because coverage format
76 only accepts 1 rule]
77 glyphs -- from grules, user asked for a new rule. Shows tabbed widget
78 with three lists of glyphs (for match, also shows a set of
79 sequence #/lookups
80 classnumber - from class rules, tabbed pane describing one class based rule
81 */
82 int row_being_edited;
83 int subheightdiff, canceldrop;
84 int done;
85 int layer;
86 };
87
88 #define CID_OK 100
89 #define CID_Cancel 101
90 #define CID_Next 102
91 #define CID_Prev 103
92 #define CID_SubSize 104
93
94 #define CID_ByGlyph 200
95 #define CID_ByClass 201
96 #define CID_ByCoverage 202
97
98 #define CID_Simple 205
99 #define CID_Complex 206
100
101 /* There are more CIDs used in this file than those listed here */
102 /* The CIDs given here are for glyph lists (aw_glyphs & aw_grules) */
103 /* similar controls referring to coverage tables have 100 added to them */
104 /* The CIDs here are also for the "match" aspect of the tabsets */
105 /* those in backtrack get 20 added, those in lookahead get 40 */
106 #define CID_GList 305
107
108 #define CID_MatchType 1003
109 #define CID_Set 1004
110 #define CID_Select 1005
111 #define CID_GlyphList 1006
112 #define CID_Set2 1007
113 #define CID_Select2 1008
114 #define CID_RplList 1009
115 #define CID_LookupList 1010
116 #define CID_LNew 1011
117 #define CID_LEdit 1012
118 #define CID_LDelete 1013
119 #define CID_LUp 1014
120 #define CID_LDown 1015
121
122 #define CID_ClassNumbers 2000
123 #define CID_ClassList 2001
124 #define CID_ClassType 2002
125 #define CID_SameAsClasses 2003
126
127 /* And for the simple dlg... */
128
129 #define CID_GList_Simple 4000
130 #define CID_GNewSection 4001
131 #define CID_GAddLookup 4002
132
133 #define CID_CList_Simple (CID_GList_Simple+100)
134 #define CID_CNewSection (CID_GNewSection+100)
135 #define CID_CAddLookup (CID_GAddLookup+100)
136
137 #define CID_MatchClasses (CID_GList_Simple+300+0*20)
138 #define CID_BackClasses (CID_MatchClasses+1*20)
139 #define CID_ForeClasses (CID_MatchClasses+2*20)
140 #define CID_SameAsClasses_S (CID_MatchClasses+1) /* Not actually used itself */
141 #define CID_BackClassesSameAs_S (CID_SameAsClasses_S+1*20)
142 #define CID_ForeClassesSameAs_S (CID_SameAsClasses_S+2*20)
143
144 #define CID_ClassMatchType 4500
145
146 #define CID_Covers 4600
147
148 char *cu_copybetween(const unichar_t *start, const unichar_t *end) {
149 char *ret = malloc(end-start+1);
150 cu_strncpy(ret,start,end-start);
151 ret[end-start] = '\0';
152 return( ret );
153 }
154
155 static char *reversenames(char *str) {
156 char *ret;
157 char *rpt, *pt, *start, *spt;
158
159 if ( str==NULL )
160 return( NULL );
161
162 rpt = ret = malloc(strlen(str)+1);
163 *ret = '\0';
164 for ( pt=str+strlen(str); pt>str; pt=start ) {
165 for ( start = pt-1; start>=str && *start!=' '; --start );
166 for ( spt=start+1; spt<pt; )
167 *rpt++ = *spt++;
168 *rpt++ = ' ';
169 }
170 if ( rpt>ret )
171 rpt[-1] = '\0';
172 return( ret );
173 }
174
175 static char *rpl(const char *src, const char *find, const char *rpl) {
176 const char *pt, *start;
177 char *ret, *rpt;
178 int found_cnt=0;
179 int flen = strlen(find);
180
181 for ( pt=src; *pt; ) {
182 while ( isspace(*pt)) ++pt;
183 if ( *pt=='\0' )
184 break;
185 for ( start=pt; !isspace(*pt) && *pt!='\0'; ++pt );
186 if ( pt-start==flen && strncmp(find,start,flen)==0 )
187 ++found_cnt;
188 }
189 if ( found_cnt==0 )
190 return( copy(src));
191
192 rpt = ret = malloc(strlen(src)+found_cnt*(strlen(rpl)-flen)+1);
193 for ( pt=src; *pt; ) {
194 while ( isspace(*pt))
195 *rpt++ = *pt++;
196 if ( *pt=='\0' )
197 break;
198 for ( start=pt; !isspace(*pt) && *pt!='\0'; ++pt );
199 if ( pt-start==flen && strncmp(find,start,flen)==0 ) {
200 strcpy(rpt,rpl);
201 rpt += strlen(rpt);
202 } else {
203 strncpy(rpt,start,pt-start);
204 rpt += (pt-start);
205 }
206 }
207 *rpt = '\0';
208 return( ret );
209 }
210
211 static char *classnumbers(int cnt,uint16_t *classes, struct matrix_data *classnames, int rows, int cols) {
212 char buf[20];
213 int i, len;
214 char *pt, *ret;
215
216 len = 0;
217 for ( i=0; i<cnt; ++i ) {
218 if ( classnames[cols*classes[i]+0].u.md_str==NULL ) {
219 sprintf( buf, "%d ", classes[i]);
220 len += strlen(buf);
221 } else {
222 len += strlen(classnames[cols*classes[i]+0].u.md_str)+1;
223 }
224 }
225 ret = pt = malloc(len+3);
226 *pt = '\0'; /* In case it is empty */
227
228 for ( i=0; i<cnt; ++i ) {
229 if ( classnames[cols*classes[i]+0].u.md_str==NULL ) {
230 sprintf( pt, "%d ", classes[i]);
231 pt += strlen(pt);
232 } else {
233 strcpy(pt, classnames[cols*classes[i]+0].u.md_str);
234 pt += strlen(pt);
235 *pt++ = ' ';
236 }
237 }
238 if ( pt>ret && pt[-1]==' ' )
239 pt[-1] = '\0';
240 return( ret );
241 }
242
243 static char *rclassnumbers(int cnt,uint16_t *classes, struct matrix_data *classnames, int rows, int cols) {
244 char buf[20];
245 int i, len;
246 char *pt, *ret;
247
248 len = 0;
249 for ( i=0; i<cnt; ++i ) {
250 if ( classnames[cols*classes[i]+0].u.md_str==NULL ) {
251 sprintf( buf, "%d ", classes[i]);
252 len += strlen(buf);
253 } else {
254 len += strlen(classnames[cols*classes[i]+0].u.md_str)+1;
255 }
256 }
257 ret = pt = malloc(len+3);
258 *pt = '\0';
259 for ( i=cnt-1; i>=0; --i ) {
260 if ( classnames[cols*classes[i]+0].u.md_str==NULL ) {
261 sprintf( pt, "%d ", classes[i]);
262 pt += strlen(pt);
263 } else {
264 strcpy(pt, classnames[cols*classes[i]+0].u.md_str);
265 pt += strlen(pt);
266 *pt++ = ' ';
267 }
268 }
269 if ( pt>ret && pt[-1]==' ' )
270 pt[-1] = '\0';
271 return( ret );
272 }
273
274 static int CCD_GlyphNameCnt(const char *pt) {
275 int cnt = 0;
276
277 while ( *pt ) {
278 while ( isspace( *pt )) ++pt;
279 if ( *pt=='\0' )
280 return( cnt );
281 ++cnt;
282 while ( !isspace(*pt) && *pt!='\0' ) ++pt;
283 }
284 return( cnt );
285 }
286
287 static int seqlookuplen(struct fpst_rule *r) {
288 int i, len=0;
289 char buf[20];
290
291 len += 4; /* for the arrow, takes 3 bytes in utf8 */
292 for ( i=0; i<r->lookup_cnt; ++i ) {
293 sprintf( buf," %d \"\",", r->lookups[i].seq );
294 len += strlen(buf) + strlen( r->lookups[i].lookup->lookup_name );
295 }
296 return( len );
297 }
298
299 static char *addseqlookups(char *pt, struct fpst_rule *r) {
300 int i;
301
302 pt = utf8_idpb(pt, 0x21d2,0);
303 for ( i=0; i<r->lookup_cnt; ++i ) {
304 sprintf( pt," %d <%s>,", r->lookups[i].seq, r->lookups[i].lookup->lookup_name);
305 pt += strlen(pt);
306 }
307 if ( pt[-1]==',' ) --pt;
308 *pt = '\0';
309 return( pt );
310 }
311
312 static void parseseqlookups(SplineFont *sf, const char *solooks, struct fpst_rule *r) {
313 int cnt;
314 const char *pt;
315
316 for ( pt = solooks, cnt=0; *pt!='\0'; ) {
317 ++cnt;
318 while ( *pt!='<' && *pt!='\0' ) ++pt;
319 if ( *pt=='<' ) {
320 ++pt;
321 while ( *pt!='>' && *pt!='\0' ) ++pt;
322 if ( *pt=='>' ) ++pt;
323 }
324 if ( *pt==',' ) ++pt;
325 }
326 r->lookup_cnt = cnt;
327 r->lookups = calloc(cnt,sizeof(struct seqlookup));
328 cnt = 0;
329 pt = solooks;
330 for (;;) {
331 char *end;
332 r->lookups[cnt].seq = strtol(pt,&end,10);
333 for ( pt = end+1; isspace( *pt ); ++pt );
334 if ( *pt=='<' ) {
335 const char *eoname; char *temp;
336 ++pt;
337 for ( eoname = pt; *eoname!='\0' && *eoname!='>'; ++eoname );
338 temp = copyn(pt,eoname-pt);
339 r->lookups[cnt].lookup = SFFindLookup(sf,temp);
340 if ( r->lookups[cnt].lookup==NULL )
341 IError("No lookup in parseseqlookups");
342 free(temp);
343 pt = eoname;
344 if ( *pt=='>' ) ++pt;
345 } else
346 IError("No lookup in parseseqlookups");
347 ++cnt;
348 if ( *pt!=',' )
349 break;
350 ++pt;
351 }
352 }
353
354 static char *gruleitem(struct fpst_rule *r) {
355 char *ret, *pt;
356 int len;
357
358 len = (r->u.glyph.back==NULL ? 0 : strlen(r->u.glyph.back)) +
359 strlen(r->u.glyph.names) +
360 (r->u.glyph.fore==0 ? 0 : strlen(r->u.glyph.fore)) +
361 seqlookuplen(r);
362
363 ret = pt = malloc(len+8);
364 if ( r->u.glyph.back!=NULL && *r->u.glyph.back!='\0' ) {
365 char *temp = reversenames(r->u.glyph.back);
366 strcpy(pt,temp);
367 pt += strlen(temp);
368 free(temp);
369 *pt++ = ' ';
370 }
371 *pt++ = '|';
372 *pt++ = ' ';
373 strcpy(pt,r->u.glyph.names);
374 pt += strlen(r->u.glyph.names);
375 *pt++ = ' ';
376 *pt++ = '|';
377 *pt++ = ' ';
378 if ( r->u.glyph.fore!=NULL && *r->u.glyph.fore!='\0' ) {
379 strcpy(pt,r->u.glyph.fore);
380 pt += strlen(r->u.glyph.fore);
381 *pt++ = ' ';
382 }
383 pt = addseqlookups(pt, r);
384 return( ret );
385 }
386
387 static void gruleitem2rule(SplineFont *sf, const char *ruletext,struct fpst_rule *r) {
388 const char *pt, *pt2;
389 char *temp, *freeme;
390 int ch;
391
392 if ( ruletext==NULL )
393 return;
394 for ( pt=ruletext; *pt!='\0' && *pt!='|'; ++pt );
395 if ( *pt=='\0' )
396 return;
397 if ( pt>ruletext ) {
398 temp = GlyphNameListDeUnicode(freeme = copyn(ruletext,pt-1-ruletext));
399 r->u.glyph.back = reversenames(temp);
400 free(temp); free(freeme);
401 }
402 ruletext = pt+2;
403 for ( pt=ruletext; *pt!='\0' && *pt!='|'; ++pt );
404 if ( *pt=='\0' )
405 return;
406 r->u.glyph.names = GlyphNameListDeUnicode(freeme = copyn(ruletext,pt-1-ruletext));
407 free(freeme);
408 ruletext = pt+2;
409 for ( pt2=ruletext; (ch=utf8_ildb((const char **) &pt2))!='\0' && ch!=0x21d2; );
410 if ( ch=='\0' )
411 return;
412 if ( pt2!=ruletext ) {
413 r->u.glyph.fore = GlyphNameListDeUnicode(freeme = copyn(ruletext,pt2-3-ruletext));
414 free(freeme);
415 }
416 parseseqlookups(sf,pt2+2,r);
417 }
418
419 static char *classruleitem(struct fpst_rule *r,struct matrix_data **classes, int clen[3], int cols) {
420 char *ret, *pt;
421 int len, i, k;
422 char buf[20];
423
424 len = 0;
425 for ( i=0; i<3; ++i ) {
426 for ( k=0; k<(&r->u.fpc_class.ncnt)[i]; ++k ) {
427 int c = (&r->u.fpc_class.nclasses)[i][k];
428 if ( classes[i][cols*c+0].u.md_str!=NULL && *classes[i][cols*c+0].u.md_str!='\0' )
429 len += strlen(classes[i][cols*c+0].u.md_str)+1;
430 else {
431 sprintf( buf, "%d ", c);
432 len += strlen(buf);
433 }
434 }
435 }
436
437 ret = pt = malloc((len+8+seqlookuplen(r)) * sizeof(unichar_t));
438 for ( k=r->u.fpc_class.bcnt-1; k>=0; --k ) {
439 int c = r->u.fpc_class.bclasses[k];
440 if ( classes[1][cols*c+0].u.md_str!=NULL && *classes[1][cols*c+0].u.md_str!='\0' ) {
441 strcpy(pt,classes[1][cols*c+0].u.md_str);
442 pt += strlen( pt );
443 *pt++ = ' ';
444 } else {
445 sprintf( pt, "%d ", c);
446 pt += strlen(pt);
447 }
448 }
449 *pt++ = '|';
450 for ( k=0; k<r->u.fpc_class.ncnt; ++k ) {
451 int c = r->u.fpc_class.nclasses[k];
452 if ( classes[0][cols*c+0].u.md_str!=NULL && *classes[0][cols*c+0].u.md_str!='\0' ) {
453 strcpy(pt,classes[0][cols*c+0].u.md_str);
454 pt += strlen( pt );
455 *pt++ = ' ';
456 } else {
457 sprintf( pt, "%d ", c);
458 pt += strlen(pt);
459 }
460 }
461 if ( pt[-1]==' ' ) --pt;
462 *pt++ = '|';
463 for ( k=0; k<r->u.fpc_class.fcnt; ++k ) {
464 int c = r->u.fpc_class.fclasses[k];
465 if ( classes[2][cols*c+0].u.md_str!=NULL && *classes[2][cols*c+0].u.md_str!='\0' ) {
466 strcpy(pt,classes[2][cols*c+0].u.md_str);
467 pt += strlen( pt );
468 *pt++ = ' ';
469 } else {
470 sprintf( pt, "%d ", c);
471 pt += strlen(pt);
472 }
473 }
474
475 *pt++ = ' ';
476 pt = addseqlookups(pt, r);
477 return( ret );
478 }
479
480 static void classruleitem2rule(SplineFont *sf,const char *ruletext,struct fpst_rule *r,
481 struct matrix_data **classes, int clen[3], int cols) {
482 const char *pt, *start, *nstart; char *end;
483 int len, i, ch, k;
484
485 memset(r,0,sizeof(*r));
486
487 len = 0; i=1;
488 for ( pt=ruletext; *pt; ) {
489 ch = utf8_ildb((const char **) &pt);
490 while ( ch!='|' && ch!=0x21d2 && ch!='\0' ) {
491 while ( isspace(ch))
492 ch = utf8_ildb((const char **) &pt);
493 if ( ch=='|' || ch== 0x21d2 || ch=='\0' )
494 break;
495 ++len;
496 while ( !isspace(ch) && ch!='|' && ch!=0x21d2 && ch!='\0' )
497 ch = utf8_ildb((const char **) &pt);
498 }
499 (&r->u.fpc_class.ncnt)[i] = len;
500 (&r->u.fpc_class.nclasses)[i] = malloc(len*sizeof(uint16_t));
501 len = 0;
502 if ( ch=='\0' || ch==0x21d2 )
503 break;
504 if ( ch=='|' ) {
505 if ( i==1 ) i=0;
506 else if ( i==0 ) i=2;
507 }
508 }
509 len = 0; i=1;
510 for ( pt=ruletext; *pt; ) {
511 start = pt;
512 ch = utf8_ildb((const char **) &pt);
513 while ( ch!='|' && ch!=0x21d2 && ch!='\0' ) {
514 while ( isspace(ch)) {
515 start = pt;
516 ch = utf8_ildb((const char **) &pt);
517 }
518 if ( ch=='|' || ch== 0x21d2 || ch=='\0' )
519 break;
520 nstart = start;
521 while ( !isspace(ch) && ch!='|' && ch!=0x21d2 && ch!='\0' ) {
522 nstart = pt;
523 ch = utf8_ildb((const char **) &pt);
524 }
525 (&r->u.fpc_class.nclasses)[i][len] = strtol(start,&end,10);
526 if ( end<nstart ) { /* Not a number, must be a class name */
527 for ( k=0; k<clen[i]; ++k ) {
528 if ( classes[i][cols*k+0].u.md_str==NULL )
529 continue;
530 if ( strlen(classes[i][cols*k+0].u.md_str)==nstart-start &&
531 strncmp(classes[i][cols*k+0].u.md_str,start,nstart-start)==0 ) {
532 (&r->u.fpc_class.nclasses)[i][len] = k;
533 break;
534 }
535 }
536 }
537 start = nstart;
538 ++len;
539 }
540 len = 0;
541 if ( ch=='\0' || ch==0x21d2 )
542 break;
543 if ( ch=='|' ) {
544 if ( i==1 ) i=0;
545 else if ( i==0 ) i=2;
546 }
547 }
548 /* reverse the backtrack */
549 for ( i=0; i<r->u.fpc_class.bcnt/2; ++i ) {
550 int temp = r->u.fpc_class.bclasses[i];
551 r->u.fpc_class.bclasses[i] = r->u.fpc_class.bclasses[r->u.fpc_class.bcnt-1-i];
552 r->u.fpc_class.bclasses[r->u.fpc_class.bcnt-1-i] = temp;
553 }
554
555 if ( ch=='\0' || *pt=='\0' )
556 return;
557 parseseqlookups(sf,pt,r);
558 }
559
560 static void CCD_ParseLookupList(SplineFont *sf, struct fpst_rule *r,GGadget *list) {
561 int len, i;
562 struct matrix_data *classes = GMatrixEditGet(list,&len);
563
564 r->lookup_cnt = len;
565 r->lookups = malloc(len*sizeof(struct seqlookup));
566 for ( i=0; i<len; ++i ) {
567 r->lookups[i].seq = classes[2*i+1].u.md_ival;
568 r->lookups[i].lookup = (OTLookup *) classes[2*i+0].u.md_ival;
569 }
570 }
571
572 static void CCD_EnableNextPrev(struct contextchaindlg *ccd) {
573 /* Cancel is always enabled, Not so for OK or Next or Prev */
574 switch ( ccd->aw ) {
575 case aw_formats:
576 GGadgetSetEnabled(GWidgetGetControl(ccd->gw,CID_Prev),false);
577 GGadgetSetEnabled(GWidgetGetControl(ccd->gw,CID_Next),true);
578 GGadgetSetEnabled(GWidgetGetControl(ccd->gw,CID_OK),false);
579 break;
580 case aw_glyphs:
581 case aw_classnumber:
582 GGadgetSetEnabled(GWidgetGetControl(ccd->gw,CID_Prev),true);
583 GGadgetSetEnabled(GWidgetGetControl(ccd->gw,CID_Next),true);
584 GGadgetSetEnabled(GWidgetGetControl(ccd->gw,CID_OK),false);
585 break;
586 case aw_coverage:
587 case aw_grules:
588 case aw_classrules:
589 GGadgetSetEnabled(GWidgetGetControl(ccd->gw,CID_Prev),ccd->fpst->format!=pst_reversecoverage);
590 GGadgetSetEnabled(GWidgetGetControl(ccd->gw,CID_Next),false);
591 GGadgetSetEnabled(GWidgetGetControl(ccd->gw,CID_OK),true);
592 break;
593 case aw_glyphs_simple:
594 case aw_classes_simple:
595 case aw_coverage_simple:
596 GGadgetSetEnabled(GWidgetGetControl(ccd->gw,CID_Prev),ccd->fpst->type!=pst_reversesub);
597 GGadgetSetEnabled(GWidgetGetControl(ccd->gw,CID_Next),false);
598 GGadgetSetEnabled(GWidgetGetControl(ccd->gw,CID_OK),true);
599 break;
600 default:
601 IError("Can't get here");
602 break;
603 }
604 }
605
606 static int CCD_ReasonableClassNum(const unichar_t *umatch,GGadget *list,
607 struct fpst_rule *r, int which ) {
608 int cols, len;
609 struct matrix_data *classes;
610 char *match = u2utf8_copy(umatch);
611 char *pt, *start, *end;
612 int doit;
613 int any,val;
614
615 cols = GMatrixEditGetColCnt(list);
616 classes = GMatrixEditGet(list,&len);
617
618 for ( doit = 0; doit<2; ++doit ) {
619 any = 0;
620 for ( pt=match;; ) {
621 while ( *pt==' ' ) ++pt;
622 if ( *pt=='\0' )
623 break;
624 for ( start=pt; *pt!=' ' && *pt!='\0'; ++pt );
625 val = strtol(start,&end,10);
626 if ( *end!='\0' ) {
627 for ( val=len-1; val>=0; --val )
628 if ( classes[cols*val+0].u.md_str!=NULL &&
629 strlen(classes[cols*val+0].u.md_str)==pt-start &&
630 strncasecmp(start,classes[cols*val+0].u.md_str,pt-start)==0 )
631 break;
632 }
633 if ( val<0 || val>=len ) {
634 ff_post_error(_("Bad Class"),_("%.*s is not a valid class name (or number)"), pt-start, start);
635 return( false );
636 }
637 if ( doit )
638 (&r->u.fpc_class.nclasses)[which][any] = val;
639 ++any;
640 }
641 if ( !doit ) {
642 (&r->u.fpc_class.ncnt)[which] = any;
643 (&r->u.fpc_class.nclasses)[which] = malloc(any*sizeof(uint16_t));
644 }
645 }
646 return( true );
647 }
648
649 static int ClassNamePrep(struct contextchaindlg *ccd,struct matrix_data **classes,int clen[3]) {
650 int i;
651
652 for ( i=0; i<3; ++i ) {
653 if ( i==0 || !GGadgetIsChecked(GWidgetGetControl(ccd->gw,CID_SameAsClasses+i*20)) )
654 classes[i] = GMatrixEditGet(GWidgetGetControl(ccd->gw,CID_GList+300+i*20),&clen[i]);
655 else
656 classes[i] = GMatrixEditGet(GWidgetGetControl(ccd->gw,CID_GList+300),&clen[i]);
657 }
658 return( GMatrixEditGetColCnt(GWidgetGetControl(ccd->gw,CID_GList+300+0*20)) );
659 }
660
661 static void CCD_FinishRule(struct contextchaindlg *ccd) {
662 struct fpst_rule dummy;
663 GGadget *list;
664 int i,tot;
665 char *buts[3];
666 buts[0] = _("_Yes"); buts[1] = _("_No"); buts[2] = NULL;
667 struct matrix_data *md;
668 int len;
669 int clen[3], ccols;
670 struct matrix_data *classes[3];
671
672 if ( ccd->aw==aw_classnumber ) {
673 char *ret;
674 memset(&dummy,0,sizeof(dummy));
675 CCD_ParseLookupList(ccd->sf,&dummy,GWidgetGetControl(ccd->gw,CID_LookupList+500));
676 if ( dummy.lookup_cnt==0 ) {
677 int ans = gwwv_ask(_("No Sequence/Lookups"),
678 (const char **) buts,0,1,
679 _("There are no entries in the Sequence/Lookup List, was this intentional?"));
680 if ( ans==1 )
681 return;
682 }
683 ccols = ClassNamePrep(ccd,classes,clen);
684 if ( !CCD_ReasonableClassNum(
685 _GGadgetGetTitle(GWidgetGetControl(ccd->gw,CID_ClassNumbers)),
686 GWidgetGetControl(ccd->gw,CID_ClassList),
687 &dummy,0) ||
688 !CCD_ReasonableClassNum(
689 _GGadgetGetTitle(GWidgetGetControl(ccd->gw,CID_ClassNumbers+20)),
690 GWidgetGetControl(ccd->gw,CID_ClassList+20),
691 &dummy,1) ||
692 !CCD_ReasonableClassNum(
693 _GGadgetGetTitle(GWidgetGetControl(ccd->gw,CID_ClassNumbers+40)),
694 GWidgetGetControl(ccd->gw,CID_ClassList+40),
695 &dummy,2)) {
696 FPSTRuleContentsFree(&dummy,pst_class);
697 return;
698 }
699 /* reverse the backtrack */
700 for ( i=0; i<dummy.u.fpc_class.bcnt/2; ++i ) {
701 int temp = dummy.u.fpc_class.bclasses[i];
702 dummy.u.fpc_class.bclasses[i] = dummy.u.fpc_class.bclasses[dummy.u.fpc_class.bcnt-1-i];
703 dummy.u.fpc_class.bclasses[dummy.u.fpc_class.bcnt-1-i] = temp;
704 }
705 for ( i=0; i<dummy.lookup_cnt; ++i ) {
706 if ( dummy.lookups[i].seq >= dummy.u.fpc_class.ncnt ) {
707 ff_post_error(_("Bad Sequence/Lookup List"),_("Sequence number out of bounds, must be less than %d (number of classes in list above)"), dummy.u.fpc_class.ncnt );
708 return;
709 }
710 }
711 ret = classruleitem(&dummy,classes,clen,ccols);
712 FPSTRuleContentsFree(&dummy,pst_class);
713 list = GWidgetGetControl(ccd->gw,CID_GList+200);
714 md = GMatrixEditGet(list,&len);
715 free(md[ccd->row_being_edited].u.md_str);
716 md[ccd->row_being_edited].u.md_str = ret;
717 GMatrixEditSet(list,md,len,false);
718 ccd->aw = aw_classrules;
719 GDrawSetVisible(ccd->classnumber,false);
720 GDrawSetVisible(ccd->classrules,true);
721 } else if ( ccd->aw==aw_glyphs ) { /* It's from glyph list */
722 char *ret, *temp, *freeme;
723
724 memset(&dummy,0,sizeof(dummy));
725 CCD_ParseLookupList(ccd->sf,&dummy,GWidgetGetControl(ccd->gw,CID_LookupList));
726 if ( dummy.lookup_cnt==0 ) {
727 int ans = gwwv_ask(_("No Sequence/Lookups"),
728 (const char **) buts,0,1,
729 _("There are no entries in the Sequence/Lookup List, was this intentional?"));
730 if ( ans==1 )
731 return;
732 }
733 temp = GGadgetGetTitle8(GWidgetGetControl(ccd->gw,CID_GlyphList));
734 dummy.u.glyph.names = GlyphNameListDeUnicode(temp);
735 free(temp);
736 tot = CCD_GlyphNameCnt( temp = GGadgetGetTitle8(GWidgetGetControl(ccd->gw,CID_GlyphList)));
737 free(temp);
738 for ( i=0; i<dummy.lookup_cnt; ++i ) {
739 if ( dummy.lookups[i].seq >= tot ) {
740 ff_post_error(_("Bad Sequence/Lookup List"),_("Sequence number out of bounds, must be less than %d (number of glyphs, classes or coverage tables)"), tot );
741 return;
742 }
743 }
744 temp = GGadgetGetTitle8(GWidgetGetControl(ccd->gw,CID_GlyphList+20));
745 freeme = GlyphNameListDeUnicode(temp);
746 dummy.u.glyph.back = reversenames(freeme);
747 free(temp); free(freeme);
748 temp = GGadgetGetTitle8(GWidgetGetControl(ccd->gw,CID_GlyphList+40));
749 dummy.u.glyph.fore = GlyphNameListDeUnicode(temp);
750 free(temp);
751 ret = gruleitem(&dummy);
752 FPSTRuleContentsFree(&dummy,pst_glyphs);
753 list = GWidgetGetControl(ccd->gw,CID_GList+0);
754 md = GMatrixEditGet(list,&len);
755 free(md[ccd->row_being_edited].u.md_str);
756 md[ccd->row_being_edited].u.md_str = ret;
757 GMatrixEditSet(list,md,len,false);
758 ccd->aw = aw_grules;
759 GDrawSetVisible(ccd->glyphs,false);
760 GDrawSetVisible(ccd->grules,true);
761 } else {
762 IError("Bad format in CCD_FinishRule");
763 }
764 }
765
766 static int isEverythingElse(char *text) {
767 /* GT: The string "{Everything Else}" is used in the context of a list */
768 /* GT: of classes (a set of kerning classes) where class 0 designates the */
769 /* GT: default class containing all glyphs not specified in the other classes */
770 int ret = strcmp(text,_("{Everything Else}"));
771 return( ret==0 );
772 }
773
774 static char *CCD_PickGlyphsForClass(GGadget *g,int r, int c) {
775 struct contextchaindlg *ccd = GDrawGetUserData(GGadgetGetWindow(g));
776 int rows, cols = GMatrixEditGetColCnt(g);
777 struct matrix_data *classes = _GMatrixEditGet(g,&rows);
778 char *new = GlyphSetFromSelection(ccd->sf,ccd->layer,classes[r*cols+c].u.md_str);
779 return( new );
780 }
781
782 static void _CCD_FromSelection(struct contextchaindlg *ccd,int cid ) {
783 char *curval = GGadgetGetTitle8(GWidgetGetControl(ccd->gw,cid));
784 char *new = GlyphSetFromSelection(ccd->sf,ccd->layer,curval);
785
786 free(curval);
787 if ( new==NULL )
788 return;
789 GGadgetSetTitle8(GWidgetGetControl(ccd->gw,cid),new);
790 free(new);
791 }
792
793 static int CCD_FromSelection(GGadget *g, GEvent *e) {
794 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
795 struct contextchaindlg *ccd = GDrawGetUserData(GGadgetGetWindow(g));
796 int cid = (intptr_t) GGadgetGetUserData(g);
797
798 _CCD_FromSelection(ccd,cid);
799 }
800 return( true );
801 }
802
803 static struct matrix_data *MD2MD(struct matrix_data *md,int len) {
804 struct matrix_data *newmd = calloc(2*len,sizeof(struct matrix_data));
805 int i;
806
807 for ( i=0; i<len; ++i ) {
808 newmd[2*i+0].u.md_str = copy(md[3*i+0].u.md_str);
809 newmd[2*i+1].u.md_str = copy(md[3*i+1].u.md_str);
810 }
811 return( newmd );
812 }
813
814 static void CCD_NewGlyphRule(GGadget *glyphrules,int r,int c) {
815 struct contextchaindlg *ccd = GDrawGetUserData(GGadgetGetWindow(glyphrules));
816 int rows;
817 struct matrix_data *rulelist = GMatrixEditGet(glyphrules,&rows);
818 struct fpst_rule dummy;
819 GGadget *lookuplist = GWidgetGetControl(ccd->glyphs,CID_LookupList+0);
820 struct matrix_data *md;
821 char *temp2;
822 int j;
823
824 memset(&dummy,0,sizeof(dummy));
825 gruleitem2rule(ccd->sf,rulelist[r].u.md_str,&dummy);
826 GGadgetSetTitle8(GWidgetGetControl(ccd->gw,CID_GlyphList),dummy.u.glyph.names==NULL?"":dummy.u.glyph.names);
827 GGadgetSetTitle8(GWidgetGetControl(ccd->gw,CID_GlyphList+20),(temp2 = reversenames(dummy.u.glyph.back))==NULL ? "" : temp2);
828 free(temp2);
829 GGadgetSetTitle8(GWidgetGetControl(ccd->gw,CID_GlyphList+40),dummy.u.glyph.fore!=NULL?dummy.u.glyph.fore:"");
830
831 md = calloc(2*dummy.lookup_cnt,sizeof(struct matrix_data));
832 for ( j=0; j<dummy.lookup_cnt; ++j ) {
833 md[2*j+0].u.md_ival = (intptr_t) (void *) dummy.lookups[j].lookup;
834 md[2*j+1].u.md_ival = (intptr_t) dummy.lookups[j].seq;
835 }
836 GMatrixEditSet(lookuplist,md,dummy.lookup_cnt,false);
837 ccd->aw = aw_glyphs;
838 ccd->row_being_edited = r;
839 GDrawSetVisible(ccd->grules,false);
840 GDrawSetVisible(ccd->glyphs,true);
841 CCD_EnableNextPrev(ccd);
842 }
843
844 static char *_CCD_NewGlyphRule(GGadget *glyphrules,int r,int c) {
845 int rows;
846 struct matrix_data *rulelist = GMatrixEditGet(glyphrules,&rows);
847 CCD_NewGlyphRule(glyphrules,r,c);
848 return( copy( rulelist[r].u.md_str ) ); /* We change the display to get the new value, but we must return something... */
849 }
850
851 static void CCD_NewClassRule(GGadget *classrules,int r,int c) {
852 struct contextchaindlg *ccd = GDrawGetUserData(GGadgetGetWindow(classrules));
853 int rows;
854 struct matrix_data *rulelist = GMatrixEditGet(classrules,&rows);
855 struct fpst_rule dummy;
856 GGadget *lookuplist = GWidgetGetControl(ccd->classnumber,CID_LookupList+500);
857 struct matrix_data *md, *classes[3];
858 int len, clen[3], ccols;
859 int i,j;
860 char *temp;
861
862 ccols = ClassNamePrep(ccd,classes,clen);
863 memset(&dummy,0,sizeof(dummy));
864 classruleitem2rule(ccd->sf,rulelist[r].u.md_str,&dummy,classes,clen,ccols);
865 GGadgetSetTitle8(GWidgetGetControl(ccd->gw,CID_ClassNumbers),
866 (temp=classnumbers(dummy.u.fpc_class.ncnt,dummy.u.fpc_class.nclasses,classes[0],clen[0],ccols)));
867 free(temp);
868 GGadgetSetTitle8(GWidgetGetControl(ccd->gw,CID_ClassNumbers+20),
869 (temp=rclassnumbers(dummy.u.fpc_class.bcnt,dummy.u.fpc_class.bclasses,classes[1],clen[1],ccols)));
870 free(temp);
871 GGadgetSetTitle8(GWidgetGetControl(ccd->gw,CID_ClassNumbers+40),
872 (temp=classnumbers(dummy.u.fpc_class.fcnt,dummy.u.fpc_class.fclasses,classes[2],clen[2],ccols)));
873 free(temp);
874
875 md = calloc(2*dummy.lookup_cnt,sizeof(struct matrix_data));
876 for ( j=0; j<dummy.lookup_cnt; ++j ) {
877 md[2*j+0].u.md_ival = (intptr_t) (void *) dummy.lookups[j].lookup;
878 md[2*j+1].u.md_ival = (intptr_t) dummy.lookups[j].seq;
879 }
880 GMatrixEditSet(lookuplist,md,dummy.lookup_cnt,false);
881 FPSTRuleContentsFree(&dummy,pst_class);
882 GWidgetIndicateFocusGadget(GWidgetGetControl(ccd->gw,CID_ClassNumbers));
883 for ( i=0; i<3; ++i ) {
884 if ( i!=0 && GGadgetIsChecked(GWidgetGetControl(ccd->gw,CID_SameAsClasses+i*20)) )
885 md = GMatrixEditGet(GWidgetGetControl(ccd->gw,CID_GList+300),&len);
886 else
887 md = GMatrixEditGet(GWidgetGetControl(ccd->gw,CID_GList+300+i*20),&len);
888 GMatrixEditSet(GWidgetGetControl(ccd->gw,CID_ClassList+i*20),MD2MD(md,len),len,false);
889 }
890 ccd->aw = aw_classnumber;
891 ccd->row_being_edited = r;
892 GDrawSetVisible(ccd->classrules,false);
893 GDrawSetVisible(ccd->classnumber,true);
894 CCD_EnableNextPrev(ccd);
895 }
896
897 static char *_CCD_NewClassRule(GGadget *classrules,int r,int c) {
898 int rows;
899 struct matrix_data *rulelist = GMatrixEditGet(classrules,&rows);
900 CCD_NewClassRule(classrules,r,c);
901 return( copy( rulelist[r].u.md_str ) ); /* We change the display to get the new value, but we must return something... */
902 }
903
904 static int CCD_SameAsClasses(GGadget *g, GEvent *e) {
905 int ison = GGadgetIsChecked(g);
906 int cid = GGadgetGetCid(g);
907 struct contextchaindlg *ccd = GDrawGetUserData(GGadgetGetWindow(g));
908
909 if ( cid < CID_SameAsClasses_S ) {
910 int off = cid-CID_SameAsClasses;
911 GGadgetSetEnabled(GWidgetGetControl(ccd->gw,CID_GList+300+off),!ison);
912 return( true );
913 } else {
914 int off = cid-CID_SameAsClasses_S;
915 GGadgetSetEnabled(GWidgetGetControl(ccd->gw,CID_CList_Simple+off),!ison);
916 return( true );
917 }
918 }
919
920 static void CCD_ClassSelected(GGadget *g, int r, int c) {
921 struct contextchaindlg *ccd = GDrawGetUserData(GGadgetGetWindow(g));
922 int off = GGadgetGetCid(g)-CID_ClassList;
923 int rows, cols = GMatrixEditGetColCnt(g);
924 struct matrix_data *classes = GMatrixEditGet(g,&rows);
925 GGadget *tf = GWidgetGetControl(ccd->gw,CID_ClassNumbers+off);
926 char buf[20];
927 unichar_t ubuf[80];
928
929 if ( r<0 || r>=rows )
930 return;
931 if ( classes[cols*r+0].u.md_str == NULL || classes[cols*r+0].u.md_str[0]=='\0' ) {
932 sprintf( buf, " %d ", r );
933 uc_strcpy(ubuf,buf);
934 } else {
935 ubuf[0]=' ';
936 utf82u_strncpy(ubuf+1,classes[cols*r+0].u.md_str,sizeof(ubuf)/sizeof(ubuf[0])-2 );
937 ubuf[sizeof(ubuf)/sizeof(ubuf[0])-2] = '\0';
938 uc_strcat(ubuf," ");
939 }
940 GTextFieldReplace(tf,ubuf);
941 return;
942 }
943
944 static void CCD_Close(struct contextchaindlg *ccd) {
945 if ( ccd->isnew )
946 GFI_FinishContextNew(ccd->gfi,ccd->fpst,false);
947 ccd->done = true;
948 }
949
950 static char **CCD_ParseCoverageList(struct contextchaindlg *ccd,int cid,int *cnt) {
951 int i;
952 int _cnt;
953 struct matrix_data *covers = GMatrixEditGet(GWidgetGetControl(ccd->gw,cid),&_cnt);
954 char **ret;
955
956 *cnt = _cnt;
957 if ( _cnt==0 )
958 return( NULL );
959 ret = malloc(*cnt*sizeof(char *));
960 for ( i=0; i<_cnt; ++i )
961 ret[i] = GlyphNameListDeUnicode(covers[i].u.md_str);
962 return( ret );
963 }
964
965 static void CoverageReverse(char **bcovers,int bcnt) {
966 int i;
967 char *temp;
968
969 for ( i=0; i<bcnt/2; ++i ) {
970 temp = bcovers[i];
971 bcovers[i] = bcovers[bcnt-i-1];
972 bcovers[bcnt-i-1] = temp;
973 }
974 }
975
976 static void _CCD_Ok(struct contextchaindlg *ccd) {
977 FPST *fpst = ccd->fpst, *dummyfpst;
978 int len, i, k, had_class0, clen[3], ccols;
979 struct matrix_data *old, *classes[3], *classes_simple;
980 struct fpst_rule dummy;
981 char *msg;
982 int ans, cnt, cols, first, last, forward_start;
983 int iswarning;
984 char *temp;
985 int has[3];
986 char *buts[3];
987
988 buts[0] = _("_Yes"); buts[1] = _("_No"); buts[2] = NULL;
989
990 switch ( ccd->aw ) {
991 case aw_grules: {
992 old = GMatrixEditGet(GWidgetGetControl(ccd->gw,CID_GList),&len);
993 if ( len==0 ) {
994 ff_post_error(_("Missing rules"),_(" There must be at least one contextual rule"));
995 return;
996 }
997 FPSTRulesFree(fpst->rules,fpst->format,fpst->rule_cnt);
998 fpst->format = pst_glyphs;
999 fpst->rule_cnt = len;
1000 fpst->rules = calloc(len,sizeof(struct fpst_rule));
1001 for ( i=0; i<len; ++i )
1002 gruleitem2rule(ccd->sf,old[i].u.md_str,&fpst->rules[i]);
1003 } break;
1004 case aw_classrules: {
1005 old = GMatrixEditGet(GWidgetGetControl(ccd->gw,CID_GList+200),&len);
1006 if ( len==0 ) {
1007 ff_post_error(_("Missing rules"),_(" There must be at least one contextual rule"));
1008 return;
1009 }
1010 FPSTRulesFree(fpst->rules,fpst->format,fpst->rule_cnt);
1011 fpst->format = pst_class;
1012 fpst->rule_cnt = len;
1013 fpst->rules = calloc(len,sizeof(struct fpst_rule));
1014 fpst->nccnt = fpst->bccnt = fpst->fccnt = 0;
1015 fpst->nclass = fpst->bclass = fpst->fclass = NULL;
1016 has[1] = has[2] = false; has[0] = true;
1017 ccols = ClassNamePrep(ccd,classes,clen);
1018 for ( i=0; i<len; ++i ) {
1019 classruleitem2rule(ccd->sf,old[i].u.md_str,&fpst->rules[i],classes,clen,ccols);
1020 if ( fpst->rules[i].u.fpc_class.bcnt!=0 ) has[1] = true;
1021 if ( fpst->rules[i].u.fpc_class.fcnt!=0 ) has[2] = true;
1022 }
1023 for ( i=0; i<3; ++i ) {
1024 if ( i!=0 && !has[i] )
1025 continue;
1026 (&fpst->nccnt)[i] = clen[i];
1027 (&fpst->nclass)[i] = malloc(clen[i]*sizeof(char*));
1028 (&fpst->nclassnames)[i] = malloc(clen[i]*sizeof(char*));
1029 (&fpst->nclass)[i][0] = NULL;
1030 had_class0 = i==0 && !isEverythingElse(classes[i][0].u.md_str);
1031 for ( k=had_class0 ? 0 : 1 ; k<clen[i]; ++k )
1032 (&fpst->nclass)[i][k] = GlyphNameListDeUnicode(classes[i][ccols*k+1].u.md_str);
1033 for ( k=0; k<clen[i]; ++k )
1034 (&fpst->nclassnames)[i][k] = copy(classes[i][ccols*k+0].u.md_str);
1035 }
1036 } break;
1037 case aw_coverage:
1038 old = GMatrixEditGet(GWidgetGetControl(ccd->gw,CID_GList+100),&len);
1039 if ( len==0 ) {
1040 ff_post_error(_("Bad Coverage Table"),_("There must be at least one match coverage table"));
1041 return;
1042 }
1043 if ( fpst->format==pst_reversecoverage ) {
1044 if ( len!=1 ) {
1045 ff_post_error(_("Bad Coverage Table"),_("In a Reverse Chaining Substitution there must be exactly one coverage table to match"));
1046 return;
1047 }
1048 if ( CCD_GlyphNameCnt(old[0].u.md_str)!=CCD_GlyphNameCnt(
1049 temp=GGadgetGetTitle8(GWidgetGetControl(ccd->gw,CID_RplList+100))) ) {
1050 free(temp);
1051 ff_post_error(_("Replacement mismatch"),_("In a Reverse Chaining Substitution there must be exactly as many replacements as there are glyph names in the match coverage table"));
1052 return;
1053 }
1054 dummy.u.rcoverage.replacements = GlyphNameListDeUnicode(temp);
1055 free(temp);
1056 } else {
1057 CCD_ParseLookupList(ccd->sf,&dummy,GWidgetGetControl(ccd->gw,CID_LookupList+100));
1058 if ( dummy.lookup_cnt==0 ) {
1059 int ans = gwwv_ask(_("No Sequence/Lookups"),
1060 (const char **) buts,0,1,
1061 _("There are no entries in the Sequence/Lookup List, was this intentional?"));
1062 if ( ans==1 )
1063 return;
1064 }
1065 }
1066 FPSTRulesFree(fpst->rules,fpst->format,fpst->rule_cnt);
1067 fpst->format = fpst->type==pst_reversesub ? pst_reversecoverage : pst_coverage;
1068 fpst->rule_cnt = 1;
1069 fpst->rules = calloc(1,sizeof(struct fpst_rule));
1070 fpst->rules[0].u.coverage.ncovers = CCD_ParseCoverageList(ccd,CID_GList+100,&fpst->rules[0].u.coverage.ncnt);
1071 fpst->rules[0].u.coverage.bcovers = CCD_ParseCoverageList(ccd,CID_GList+100+20,&fpst->rules[0].u.coverage.bcnt);
1072 CoverageReverse(fpst->rules[0].u.coverage.bcovers,fpst->rules[0].u.coverage.bcnt);
1073 fpst->rules[0].u.coverage.fcovers = CCD_ParseCoverageList(ccd,CID_GList+100+40,&fpst->rules[0].u.coverage.fcnt);
1074 if ( fpst->format==pst_reversecoverage )
1075 fpst->rules[0].u.rcoverage.replacements = dummy.u.rcoverage.replacements;
1076 else {
1077 fpst->rules[0].lookup_cnt = dummy.lookup_cnt;
1078 fpst->rules[0].lookups = dummy.lookups;
1079 for ( i=0; i<dummy.lookup_cnt; ++i ) {
1080 if ( dummy.lookups[i].seq >= fpst->rules[0].u.coverage.ncnt ) {
1081 ff_post_error(_("Bad Sequence/Lookup List"),
1082 _("Sequence number out of bounds, must be less than %d (number of classes in list above)"),
1083 fpst->rules[0].u.coverage.ncnt );
1084 return;
1085 }
1086 }
1087 }
1088 break;
1089 case aw_classes_simple:
1090 case aw_glyphs_simple: {
1091 old = GMatrixEditGet(GWidgetGetControl(ccd->gw,ccd->aw==aw_glyphs_simple?CID_GList_Simple:CID_CList_Simple),&len);
1092 if ( len==0 ) {
1093 ff_post_error(_("Missing rules"),_(" There must be at least one contextual rule"));
1094 return;
1095 }
1096 dummyfpst = chunkalloc(sizeof(FPST));
1097 *dummyfpst = *fpst;
1098 dummyfpst->format = pst_glyphs;
1099 if ( ccd->aw==aw_classes_simple ) {
1100 dummyfpst->format = pst_class;
1101 for ( i=0; i<3; ++i ) { int clen;
1102 if ( i==0 || !GGadgetIsChecked(GWidgetGetControl(ccd->gw,CID_SameAsClasses_S+i*20)) )
1103 classes_simple = GMatrixEditGet(GWidgetGetControl(ccd->gw,CID_MatchClasses+i*20),&clen);
1104 else /* If SameAs the reparse the match classes_simple */
1105 classes_simple = GMatrixEditGet(GWidgetGetControl(ccd->gw,CID_MatchClasses),&clen);
1106 (&dummyfpst->nccnt)[i] = clen;
1107 if ( clen!=0 ) {
1108 (&dummyfpst->nclass)[i] = malloc(clen*sizeof(char*));
1109 (&dummyfpst->nclassnames)[i] = malloc(clen*sizeof(char*));
1110 (&dummyfpst->nclass)[i][0] = NULL;
1111 (&dummyfpst->nclassnames)[i][0] = NULL;
1112 had_class0 = i==0 && !isEverythingElse(classes_simple[3*0+1].u.md_str);
1113 if ( !had_class0 )
1114 (&dummyfpst->nclassnames)[i][0] = copy(classes_simple[3*0+0].u.md_str);
1115 for ( k=had_class0 ? 0 : 1 ; k<clen; ++k ) {
1116 (&dummyfpst->nclassnames)[i][k] = copy(classes_simple[3*k+0].u.md_str);
1117 (&dummyfpst->nclass)[i][k] = GlyphNameListDeUnicode(classes_simple[3*k+1].u.md_str);
1118 }
1119 }
1120 }
1121 } else {
1122 dummyfpst->nccnt = dummyfpst->bccnt = dummyfpst->fccnt = 0;
1123 dummyfpst->nclass = dummyfpst->bclass = dummyfpst->fclass = NULL;
1124 dummyfpst->nclassnames = dummyfpst->bclassnames = dummyfpst->fclassnames = NULL;
1125 }
1126 dummyfpst->rule_cnt = len;
1127 dummyfpst->rules = calloc(len,sizeof(struct fpst_rule));
1128 for ( i=0; i<len; ++i ) {
1129 char *temp = old[i].u.md_str;
1130 if ( ccd->aw==aw_glyphs_simple )
1131 temp = GlyphNameListDeUnicode(temp);
1132 msg = FPSTRule_From_Str(ccd->sf,dummyfpst,&dummyfpst->rules[i],temp,&iswarning);
1133 if ( temp!=old[i].u.md_str )
1134 free(temp);
1135 if ( msg!=NULL ) {
1136 if ( !iswarning ) {
1137 ff_post_error(_("Bad rule"), "%s", msg );
1138 free(msg);
1139 FPSTClassesFree(dummyfpst);
1140 FPSTRulesFree(dummyfpst->rules,dummyfpst->format,dummyfpst->rule_cnt);
1141 chunkfree(dummyfpst,sizeof(FPST));
1142 return;
1143 } else {
1144 ans = gwwv_ask(_("Warning"),
1145 (const char **) buts,0,1,
1146 _("%s\nProceed anyway?"), msg);
1147 free(msg);
1148 if ( ans==1 ) {
1149 FPSTClassesFree(dummyfpst);
1150 FPSTRulesFree(dummyfpst->rules,dummyfpst->format,dummyfpst->rule_cnt);
1151 chunkfree(dummyfpst,sizeof(FPST));
1152 return;
1153 }
1154 }
1155 }
1156 }
1157 FPSTRulesFree(fpst->rules,fpst->format,fpst->rule_cnt);
1158 fpst->format = dummyfpst->format;
1159 fpst->rule_cnt = dummyfpst->rule_cnt;
1160 fpst->rules = dummyfpst->rules;
1161 if ( fpst->format==pst_class ) {
1162 FPSTClassesFree(fpst);
1163 fpst->nccnt = dummyfpst->nccnt; fpst->bccnt = dummyfpst->bccnt; fpst->fccnt = dummyfpst->fccnt;
1164 fpst->nclass = dummyfpst->nclass; fpst->bclass = dummyfpst->bclass; fpst->fclass = dummyfpst->fclass;
1165 fpst->nclassnames = dummyfpst->nclassnames; fpst->bclassnames = dummyfpst->bclassnames; fpst->fclassnames = dummyfpst->fclassnames;
1166 }
1167 chunkfree(dummyfpst,sizeof(FPST));
1168 } break;
1169 case aw_coverage_simple:
1170 old = GMatrixEditGet(GWidgetGetControl(ccd->gw,CID_Covers),&len);
1171 cols = GMatrixEditGetColCnt(GWidgetGetControl(ccd->gw,CID_Covers));
1172 if ( len==0 ) {
1173 ff_post_error(_("Bad Coverage Table"),_("There must be at least one match coverage table"));
1174 return;
1175 }
1176 memset(&dummy,0,sizeof(dummy));
1177 if ( fpst->format==pst_reversecoverage ) {
1178 first = last = -1;
1179 for ( i=0; i<len; ++i ) {
1180 if ( old[cols*i+1].u.md_str!=NULL && *old[cols*i+1].u.md_str!='\0' ) {
1181 if ( first==-1 )
1182 first = last = i;
1183 else {
1184 ff_post_error(_("Bad Coverage Table"),_("In a Reverse Chaining Substitution there must be exactly one coverage table with replacements"));
1185 return;
1186 }
1187 /* There is only this one line of replacements to add. */
1188 dummy.u.rcoverage.replacements = GlyphNameListDeUnicode( old[cols*i+1].u.md_str );
1189 }
1190 }
1191 if ( first==-1 ) {
1192 ff_post_error(_("Bad Coverage Table"),_("In a Reverse Chaining Substitution there must be exactly one coverage table with replacements"));
1193 return;
1194 }
1195 if ( GlyphNameCnt(old[cols*first+0].u.md_str)!=GlyphNameCnt(old[cols*first+1].u.md_str) ) {
1196 ff_post_error(_("Replacement mismatch"),_("In a Reverse Chaining Substitution there must be exactly as many replacements as there are glyph names in the match coverage table"));
1197 return;
1198 }
1199 forward_start = last+1;
1200 } else {
1201 first = last = forward_start = -1;
1202 if ( fpst->type == pst_contextpos || fpst->type == pst_contextsub ) {
1203 first = 0;
1204 forward_start = len;
1205 /* No check here to see if any lookups invoked. It's only a warning */
1206 /* Do we need to add it???? */
1207 } else {
1208 for ( i=0; i<len; ++i ) {
1209 if ( old[cols*i+2].u.md_ival ) {
1210 if ( first==-1 )
1211 first = last = i;
1212 else if ( forward_start==-1 ) {
1213 if ( old[cols*i+1].u.md_addr!=NULL ) {
1214 ff_post_error(_("Bad Sections"),_("The sections specified do not make sense. All lookups must lie in the middle section."));
1215 return;
1216 }
1217 forward_start = i;
1218 } else {
1219 ff_post_error(_("Bad Sections"),_("The sections specified do not make sense. All lookups must lie in the middle section."));
1220 return;
1221 }
1222 } else if ( old[cols*i+1].u.md_addr!=NULL ) {
1223 if ( first==-1 )
1224 first = last = i;
1225 else if ( forward_start!=-1 ) {
1226 ff_post_error(_("Bad Sections"),_("The sections specified do not make sense. All lookups must lie in the middle section."));
1227 return;
1228 }
1229 }
1230 }
1231 if ( forward_start==-1 && last!=-1 )
1232 forward_start = last+1;
1233 if ( first==-1 ) {
1234 ans = gwwv_ask(_("Warning"),
1235 (const char **) buts,0,1,
1236 _("This rule activates no lookups.\nProceed anyway?"));
1237 if ( ans==1 )
1238 return;
1239 first = 0;
1240 forward_start = len;
1241 }
1242 }
1243 for ( i=first, cnt=0; i<forward_start; ++i )
1244 if ( old[cols*i+1].u.md_addr!=NULL )
1245 ++cnt;
1246 dummy.lookup_cnt = cnt;
1247 if ( cnt!=0 ) {
1248 dummy.lookups = calloc(cnt,sizeof(struct seqlookup));
1249 for ( i=first, cnt=0; i<forward_start; ++i ) {
1250 if ( old[cols*i+1].u.md_addr!=NULL ) {
1251 dummy.lookups[cnt].lookup = old[cols*i+1].u.md_addr;
1252 dummy.lookups[cnt].seq = i-first;
1253 ++cnt;
1254 }
1255 }
1256 }
1257 }
1258 dummy.u.coverage.bcnt = first;
1259 dummy.u.coverage.ncnt = forward_start-first;
1260 dummy.u.coverage.fcnt = len-forward_start;
1261 dummy.u.coverage.ncovers = malloc(dummy.u.coverage.ncnt*sizeof(char *));
1262 if ( dummy.u.coverage.bcnt!=0 )
1263 dummy.u.coverage.bcovers = malloc(dummy.u.coverage.bcnt*sizeof(char *));
1264 if ( dummy.u.coverage.fcnt!=0 )
1265 dummy.u.coverage.fcovers = malloc(dummy.u.coverage.fcnt*sizeof(char *));
1266 for ( i=0; i<first; ++i )
1267 dummy.u.coverage.bcovers[first-1-i] = GlyphNameListDeUnicode( old[cols*i+0].u.md_str );
1268 for ( i=0; i<dummy.u.coverage.ncnt; ++i )
1269 dummy.u.coverage.ncovers[i] = GlyphNameListDeUnicode( old[cols*(first+i)+0].u.md_str );
1270 for ( i=forward_start; i<len; ++i )
1271 dummy.u.coverage.fcovers[i-forward_start] = GlyphNameListDeUnicode( old[cols*i+0].u.md_str );
1272 FPSTClassesFree(fpst);
1273 FPSTRulesFree(fpst->rules,fpst->format,fpst->rule_cnt);
1274 fpst->format = fpst->type==pst_reversesub ? pst_reversecoverage : pst_coverage;
1275 fpst->rule_cnt = 1;
1276 fpst->rules = calloc(1,sizeof(struct fpst_rule));
1277 fpst->rules[0] = dummy;
1278 break;
1279 default:
1280 IError("The OK button should not be enabled here");
1281 return;
1282 }
1283 if ( ccd->isnew )
1284 GFI_FinishContextNew(ccd->gfi,ccd->fpst,true);
1285 ccd->done = true;
1286 }
1287
1288 static int CCD_OK(GGadget *g, GEvent *e) {
1289 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1290 struct contextchaindlg *ccd = GDrawGetUserData(GGadgetGetWindow(g));
1291 _CCD_Ok(ccd);
1292 }
1293 return( true );
1294 }
1295
1296 static int CCD_Cancel(GGadget *g, GEvent *e) {
1297 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1298 struct contextchaindlg *ccd = GDrawGetUserData(GGadgetGetWindow(g));
1299 CCD_Close(ccd);
1300 }
1301 return( true );
1302 }
1303
1304 static int CCD_Next(GGadget *g, GEvent *e) {
1305 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1306 struct contextchaindlg *ccd = GDrawGetUserData(GGadgetGetWindow(g));
1307 switch ( ccd->aw ) {
1308 case aw_formats:
1309 GDrawSetVisible(ccd->formats,false);
1310 if ( GGadgetIsChecked(GWidgetGetControl(ccd->gw,CID_Simple)) ) {
1311 if ( GGadgetIsChecked(GWidgetGetControl(ccd->gw,CID_ByGlyph)) ) {
1312 ccd->aw = aw_glyphs_simple;
1313 GDrawSetVisible(ccd->glyphs_simple,true);
1314 } else if ( GGadgetIsChecked(GWidgetGetControl(ccd->gw,CID_ByClass)) ) {
1315 ccd->aw = aw_classes_simple;
1316 GDrawSetVisible(ccd->classes_simple,true);
1317 } else {
1318 ccd->aw = aw_coverage_simple;
1319 GDrawSetVisible(ccd->coverage_simple,true);
1320 }
1321 } else {
1322 if ( GGadgetIsChecked(GWidgetGetControl(ccd->gw,CID_ByGlyph)) ) {
1323 ccd->aw = aw_grules;
1324 GDrawSetVisible(ccd->grules,true);
1325 } else if ( GGadgetIsChecked(GWidgetGetControl(ccd->gw,CID_ByClass)) ) {
1326 ccd->aw = aw_classrules;
1327 GDrawSetVisible(ccd->classrules,true);
1328 } else {
1329 ccd->aw = aw_coverage;
1330 GDrawSetVisible(ccd->coverage,true);
1331 }
1332 }
1333 break;
1334 case aw_glyphs:
1335 case aw_classnumber:
1336 CCD_FinishRule(ccd);
1337 break;
1338 default:
1339 IError("The next button should not be enabled here");
1340 break;
1341 }
1342 CCD_EnableNextPrev(ccd);
1343 }
1344 return( true );
1345 }
1346
1347 static int CCD_Prev(GGadget *g, GEvent *e) {
1348 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1349 struct contextchaindlg *ccd = GDrawGetUserData(GGadgetGetWindow(g));
1350 switch ( ccd->aw ) {
1351 case aw_formats:
1352 CCD_Cancel(g,e);
1353 break;
1354 case aw_glyphs:
1355 ccd->aw = aw_grules;
1356 GDrawSetVisible(ccd->glyphs,false);
1357 GDrawSetVisible(ccd->grules,true);
1358 break;
1359 case aw_classnumber:
1360 ccd->aw = aw_classrules;
1361 GDrawSetVisible(ccd->classnumber,false);
1362 GDrawSetVisible(ccd->classrules,true);
1363 break;
1364 case aw_coverage:
1365 case aw_classrules:
1366 case aw_grules:
1367 ccd->aw = aw_formats;
1368 GDrawSetVisible(ccd->coverage,false);
1369 GDrawSetVisible(ccd->classrules,false);
1370 GDrawSetVisible(ccd->grules,false);
1371 GDrawSetVisible(ccd->formats,true);
1372 break;
1373 case aw_coverage_simple:
1374 case aw_classes_simple:
1375 case aw_glyphs_simple:
1376 ccd->aw = aw_formats;
1377 GDrawSetVisible(ccd->coverage_simple,false);
1378 GDrawSetVisible(ccd->classes_simple,false);
1379 GDrawSetVisible(ccd->glyphs_simple,false);
1380 GDrawSetVisible(ccd->formats,true);
1381 break;
1382 default:
1383 IError("Can't get here");
1384 break;
1385 }
1386 CCD_EnableNextPrev(ccd);
1387 }
1388 return( true );
1389 }
1390
1391 static void CCD_SimulateDefaultButton( struct contextchaindlg *ccd ) {
1392 GEvent ev;
1393
1394 /* figure out what the default action should be */
1395 memset(&ev,0,sizeof(ev));
1396 ev.type = et_controlevent;
1397 ev.u.control.subtype = et_buttonactivate;
1398 if ( ccd->aw==aw_formats || ccd->aw == aw_glyphs ) {
1399 ev.u.control.g = GWidgetGetControl(ccd->gw,CID_Next);
1400 CCD_Next(ev.u.control.g,&ev);
1401 /* For the glyph list and the coverage list, the [Next] button is disabled */
1402 /* I think [OK] is probably inappropriate, so let's do either [New] or [Edit] */
1403 /* (which are what [Next] would logically do) depending on which of the two */
1404 /* is more appropriate */
1405 /* ev.u.control.g = GWidgetGetControl(ccd->gw,CID_OK); */
1406 /* CCD_OK(ev.u.control.g,&ev); */
1407 } else {
1408 }
1409 }
1410
1411 static int CCD_NewSection(GGadget *g, GEvent *e) {
1412 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1413 int off = GGadgetGetCid(g)-CID_GNewSection;
1414 GGadget *gme = GWidgetGetControl(GGadgetGetWindow(g),CID_GList_Simple+off);
1415 GGadget *tf = _GMatrixEditGetActiveTextField(gme);
1416 static const unichar_t section_mark[] = { ' ', '|', ' ', '\0' };
1417
1418 if ( tf!=NULL )
1419 GTextFieldReplace(tf,section_mark);
1420 }
1421 return( true );
1422 }
1423
1424 static int CCD_AddLookup(GGadget *g, GEvent *e) {
1425 if ( e->type==et_controlevent && e->u.control.subtype == et_listselected ) {
1426 int off = GGadgetGetCid(g)-CID_GAddLookup;
1427 GGadget *gme = GWidgetGetControl(GGadgetGetWindow(g),CID_GList_Simple+off);
1428 GGadget *tf = _GMatrixEditGetActiveTextField(gme);
1429 GTextInfo *lookup_ti = GGadgetGetListItemSelected(g);
1430 OTLookup *otl;
1431
1432 if ( tf!=NULL && lookup_ti!=NULL && lookup_ti->userdata!=NULL) {
1433 char *space;
1434 unichar_t *temp;
1435 otl = lookup_ti->userdata;
1436 space = malloc(strlen(otl->lookup_name)+8);
1437 sprintf( space, " @<%s> ", otl->lookup_name );
1438 temp = utf82u_copy(space);
1439 GTextFieldReplace(tf,temp);
1440 free(space);
1441 free(temp);
1442 }
1443 GGadgetSelectOneListItem(g,0);
1444 }
1445 return( true );
1446 }
1447
1448 static int subccd_e_h(GWindow gw, GEvent *event) {
1449 if ( event->type==et_char ) {
1450 if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) {
1451 help("ui/dialogs/contextchain.html", NULL);
1452 return( true );
1453 } else if ( GMenuIsCommand(event,H_("Quit|Ctl+Q") )) {
1454 MenuExit(NULL,NULL,NULL);
1455 return( true );
1456 } else if ( GMenuIsCommand(event,H_("Close|Ctl+Shft+Q") )) {
1457 CCD_Close(GDrawGetUserData(gw));
1458 return( true );
1459 } else if ( event->u.chr.chars[0]=='\r' ) {
1460 CCD_SimulateDefaultButton( (struct contextchaindlg *) GDrawGetUserData(gw));
1461 return( true );
1462 }
1463 return( false );
1464 }
1465 return( true );
1466 }
1467
1468 static int ccd_e_h(GWindow gw, GEvent *event) {
1469 if ( event->type==et_close ) {
1470 struct contextchaindlg *ccd = GDrawGetUserData(gw);
1471 CCD_Close(ccd);
1472 } else if ( event->type==et_destroy ) {
1473 struct contextchaindlg *ccd = GDrawGetUserData(gw);
1474 chunkfree(ccd,sizeof(struct contextchaindlg));
1475 } else if ( event->type==et_char ) {
1476 if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) {
1477 help("ui/dialogs/contextchain.html", NULL);
1478 return( true );
1479 } else if ( GMenuIsCommand(event,H_("Quit|Ctl+Q") )) {
1480 MenuExit(NULL,NULL,NULL);
1481 return( true );
1482 } else if ( GMenuIsCommand(event,H_("Close|Ctl+Shft+Q") )) {
1483 CCD_Close(GDrawGetUserData(gw));
1484 return( true );
1485 } else if ( event->u.chr.chars[0]=='\r' ) {
1486 CCD_SimulateDefaultButton( (struct contextchaindlg *) GDrawGetUserData(gw));
1487 return( true );
1488 }
1489 return( false );
1490 } else if ( event->type==et_resize ) {
1491 /* int blen = GDrawPointsToPixels(NULL,GIntGetResource(_NUM_Buttonsize)),*/
1492 GRect wsize;
1493 struct contextchaindlg *ccd = GDrawGetUserData(gw);
1494
1495 GGadgetGetSize(GWidgetGetControl(ccd->gw,CID_SubSize),&wsize);
1496
1497 GDrawResize(ccd->formats,wsize.width,wsize.height);
1498 GDrawResize(ccd->coverage,wsize.width,wsize.height);
1499 GDrawResize(ccd->grules,wsize.width,wsize.height);
1500 GDrawResize(ccd->glyphs,wsize.width,wsize.height);
1501 GDrawResize(ccd->classrules,wsize.width,wsize.height);
1502 GDrawResize(ccd->classnumber,wsize.width,wsize.height);
1503 GDrawResize(ccd->coverage_simple,wsize.width,wsize.height);
1504 GDrawResize(ccd->glyphs_simple,wsize.width,wsize.height);
1505 GDrawResize(ccd->classes_simple,wsize.width,wsize.height);
1506
1507 GDrawRequestExpose(ccd->gw,NULL,false);
1508 GDrawRequestExpose(ccd->aw==aw_formats ? ccd->formats :
1509 ccd->aw==aw_coverage ? ccd->coverage :
1510 ccd->aw==aw_grules ? ccd->grules :
1511 ccd->aw==aw_glyphs ? ccd->glyphs :
1512 ccd->aw==aw_classrules ? ccd->classrules :
1513 ccd->aw==aw_classnumber ? ccd->classnumber :
1514 ccd->aw==aw_coverage_simple ? ccd->coverage_simple :
1515 ccd->aw==aw_classes_simple ? ccd->classes_simple :
1516 ccd->glyphs_simple, NULL,false);
1517 }
1518 return( true );
1519 }
1520
1521 #define CCD_WIDTH 340
1522 #define CCD_HEIGHT 340
1523
1524 static unichar_t **CCD_GlyphListCompletion(GGadget *t,int from_tab) {
1525 struct contextchaindlg *ccd = GDrawGetUserData(GDrawGetParentWindow(GGadgetGetWindow(t)));
1526 SplineFont *sf = ccd->sf;
1527
1528 return( SFGlyphNameCompletion(sf,t,from_tab,true));
1529 }
1530
1531 static unichar_t **CCD_ClassListCompletion(GGadget *t,int from_tab) {
1532 struct contextchaindlg *ccd = GDrawGetUserData(GDrawGetParentWindow(GGadgetGetWindow(t)));
1533 unichar_t *pt, *spt, *basept, *wild; unichar_t **ret;
1534 int i, cnt, doit, match_len;
1535 int do_wildcards;
1536 int section;
1537 int namecnt;
1538 int cid;
1539 struct matrix_data *classnames;
1540
1541 section = 0;
1542
1543 pt = spt = basept = (unichar_t *) _GGadgetGetTitle(t);
1544 if ( pt==NULL || *pt=='\0' )
1545 return( NULL );
1546
1547 if ( ccd->fpst->type==pst_contextsub || ccd->fpst->type==pst_contextpos )
1548 section=1;
1549 else {
1550 for ( pt=basept; *pt ; ++pt )
1551 if ( *pt=='|' )
1552 ++section;
1553 if ( section>2 )
1554 section=2;
1555 }
1556 if ( section==0 && !GGadgetIsChecked(GWidgetGetControl(ccd->gw,CID_BackClassesSameAs_S)) )
1557 cid = CID_BackClasses;
1558 else if ( section==2 && !GGadgetIsChecked(GWidgetGetControl(ccd->gw,CID_ForeClassesSameAs_S)) )
1559 cid = CID_ForeClasses;
1560 else
1561 cid = CID_MatchClasses;
1562 classnames = GMatrixEditGet(GWidgetGetControl(ccd->gw,cid),&namecnt);
1563 if ( namecnt==0 ) /* No classes_simple specified yet, can't help */
1564 return( NULL );
1565
1566 if (( spt = u_strrchr(spt,' '))== NULL )
1567 spt = basept;
1568 else {
1569 pt = ++spt;
1570 if ( *pt=='\0' )
1571 return( NULL );
1572 }
1573 while ( *pt && *pt!='*' && *pt!='?' && *pt!='[' && *pt!='{' )
1574 ++pt;
1575 do_wildcards = *pt!='\0';
1576
1577 if ( do_wildcards && !from_tab )
1578 return( NULL );
1579
1580 wild = NULL;
1581 if ( do_wildcards ) {
1582 pt = spt;
1583 wild = malloc((u_strlen(spt)+2)*sizeof(unichar_t));
1584 u_strcpy(wild,pt);
1585 uc_strcat(wild,"*");
1586 }
1587
1588 match_len = u_strlen(spt);
1589 ret = NULL;
1590 for ( doit=0; doit<2; ++doit ) {
1591 cnt=0;
1592 for ( i=0; i<namecnt; ++i ) if ( classnames[3*i+0].u.md_str!=NULL ) {
1593 int matched;
1594 char *str = classnames[3*i+0].u.md_str;
1595 if ( do_wildcards ) {
1596 unichar_t *temp = utf82u_copy(str);
1597 matched = GGadgetWildMatch((unichar_t *) wild,temp,false);
1598 free(temp);
1599 } else
1600 matched = uc_strncmp(spt,str,match_len)==0;
1601 if ( matched ) {
1602 if ( doit ) {
1603 if ( spt==basept ) {
1604 ret[cnt] = utf82u_copy(str);
1605 } else {
1606 unichar_t *temp = malloc((spt-basept+strlen(str)+4)*sizeof(unichar_t));
1607 u_strncpy(temp,basept,spt-basept);
1608 utf82u_strcpy(temp+(spt-basept),str);
1609 ret[cnt] = temp;
1610 }
1611 }
1612 ++cnt;
1613 }
1614 }
1615 if ( doit )
1616 ret[cnt] = NULL;
1617 else if ( cnt==0 )
1618 break;
1619 else
1620 ret = malloc((cnt+1)*sizeof(unichar_t *));
1621 }
1622 free(wild);
1623 return( ret );
1624 }
1625
1626 static void CCD_FinishCoverageEdit(GGadget *g,int r, int c, int wasnew) {
1627 struct contextchaindlg *ccd = GDrawGetUserData(GGadgetGetWindow(g));
1628
1629 ME_SetCheckUnique(g, r, c, ccd->sf);
1630 }
1631
1632 static void CCD_FinishCoverageSimpleEdit(GGadget *g,int r, int c, int wasnew) {
1633 struct contextchaindlg *ccd = GDrawGetUserData(GGadgetGetWindow(g));
1634 int cols = GMatrixEditGetColCnt(g);
1635 int first, last, i;
1636 int rows;
1637 struct matrix_data *covers = _GMatrixEditGet(g,&rows);
1638
1639
1640 if ( c==0 )
1641 ME_SetCheckUnique(g, r, c, ccd->sf);
1642 else if ( c==1 && cols==2 ) { /* The replacement list in a reverse coverage_simple */
1643 ME_ListCheck(g, r, c, ccd->sf);
1644 } else if ( c==1 && cols==4 ) { /* The lookup in a coverage_simple line (not reverse coverage_simple) */
1645 if ( covers[cols*r+c].u.md_addr== (void *) (intptr_t) -1 ) {
1646 /* They asked to remove the lookup that was there */
1647 covers[cols*r+c].u.md_addr = NULL;
1648 } else if ( covers[cols*r+c].u.md_addr==NULL ) {
1649 /* The selected the "Add Lookup" item which should be a no-op */
1650 /* but actually sets the thing to 0 */
1651 covers[cols*r+c].u.md_addr = covers[cols*r+3].u.md_addr;
1652 }
1653 /* Save the new value somewhere safe */
1654 covers[cols*r+3].u.md_addr = covers[cols*r+c].u.md_addr;
1655 first = last = -1;
1656 for ( i=0; i<rows; ++i ) {
1657 if ( covers[cols*i+c].u.md_addr!=NULL ) {
1658 if ( first==-1 )
1659 first = i;
1660 last = i;
1661 }
1662 }
1663 if ( first!=-1 ) {
1664 /* there may not be a section break between first and last */
1665 for ( i=first; i<=last; ++i )
1666 covers[cols*i+2].u.md_ival = false;
1667 for ( i=0; i<first; ++i )
1668 if ( covers[cols*i+2].u.md_ival )
1669 break;
1670 if ( i==first )
1671 covers[cols*first+2].u.md_ival = true;
1672 for ( i=rows-1; i>last; --i )
1673 if ( covers[cols*i+2].u.md_ival )
1674 break;
1675 if ( i<=last && last+1<rows )
1676 covers[cols*(last+1)+2].u.md_ival = true;
1677 }
1678 GGadgetRedraw(g);
1679 } else if ( c==2 ) {
1680 first = last = -1;
1681 for ( i=0; i<rows; ++i ) {
1682 if ( covers[cols*i+1].u.md_addr!=NULL ) {
1683 if ( first==-1 )
1684 first = i;
1685 last = i;
1686 }
1687 }
1688 if ( covers[cols*i+2].u.md_ival ) {
1689 if ( r<=first ) {
1690 for ( i=0; i<=first; ++i ) if ( i!=r )
1691 covers[cols*i+2].u.md_ival = false;
1692 } else if ( r<=last ) {
1693 covers[cols*i+2].u.md_ival = false;
1694 GDrawBeep(NULL);
1695 } else {
1696 for ( i=last+1; i<=rows; ++i ) if ( i!=r )
1697 covers[cols*i+2].u.md_ival = false;
1698 }
1699 } else {
1700 for ( i=first; i>=0; --i )
1701 if ( covers[cols*i+2].u.md_ival )
1702 break;
1703 if ( i==0 )
1704 covers[cols*0+2].u.md_ival = true;
1705 }
1706 GGadgetRedraw(g);
1707 }
1708 }
1709
1710 static int WhichSections(struct contextchaindlg *ccd, GGadget *g) {
1711 int off = GGadgetGetCid(g)-CID_MatchClasses;
1712 int sections = 0;
1713
1714 if ( ccd->fpst->type==pst_contextpos || ccd->fpst->type==pst_contextsub )
1715 sections = 0x7; /* All sections */
1716 else if ( off==0 ) {
1717 sections = 0x2; /* Match */
1718 if ( GGadgetIsChecked(GWidgetGetControl(ccd->classes_simple,CID_SameAsClasses_S+20)))
1719 sections |= 0x1;
1720 if ( GGadgetIsChecked(GWidgetGetControl(ccd->classes_simple,CID_SameAsClasses_S+40)))
1721 sections |= 0x4;
1722 } else if ( off==20 )
1723 sections = 0x1; /* Backtracking */
1724 else
1725 sections = 0x4; /* Forward */
1726 return( sections );
1727 }
1728
1729 static void RenameClass(struct contextchaindlg *ccd,char *old,char *new,int sections) {
1730 /* A class has been renamed. We should fix up all class rules that use */
1731 /* the old name to use the new one. The name may only be valid in one */
1732 /* section of the rule (backtrack, match, or forward), or in all, or */
1733 /* in match and one of the other two */
1734 int rows, i;
1735 GGadget *gclassrules = GWidgetGetControl(ccd->classes_simple,CID_CList_Simple);
1736 struct matrix_data *classrules = GMatrixEditGet(gclassrules,&rows);
1737 int cols = GMatrixEditGetColCnt(gclassrules);
1738 char *pt, *last_name, *temp;
1739 int ch;
1740
1741 if ( sections==0x7 ) {
1742 /* name change applies through out rule, no need to search for sections */
1743 for ( i=0; i<rows; ++i ) {
1744 char *oldrule = classrules[cols*i+0].u.md_str;
1745 char *newrule = rpl(oldrule,old,new);
1746 free(oldrule);
1747 classrules[cols*i+0].u.md_str = newrule;
1748 }
1749 } else {
1750 for ( i=0; i<rows; ++i ) {
1751 char *end_back = NULL;
1752 char *end_match = NULL;
1753 char *oldrule = classrules[cols*i+0].u.md_str;
1754 char *newrule;
1755 for ( pt=last_name=oldrule; *pt; ) {
1756 while ( isspace(*pt)) ++pt;
1757 if ( *pt=='|' ) {
1758 if ( end_back == NULL )
1759 end_back = pt;
1760 else if ( end_match==NULL )
1761 end_match = pt;
1762 } else if ( end_back==NULL && ( *pt=='<' || *pt=='@' )) {
1763 end_back = last_name;
1764 } else
1765 last_name = pt;
1766 if ( *pt=='<' || *pt=='@' ) {
1767 while ( *pt!='>' && *pt!='\0' ) ++pt;
1768 if ( *pt=='>' ) ++pt;
1769 } else {
1770 while ( !isspace( *pt ) && *pt!='\0' )
1771 ++pt;
1772 }
1773 }
1774 if ( (sections==0x3 && end_match==NULL) ||
1775 (sections==0x6 && end_back==NULL) ||
1776 (sections==0x2 && end_match==NULL && end_back==NULL)) {
1777 newrule = rpl(oldrule,old,new);
1778 } else if ( sections==0x3 ) {
1779 ch = *end_match; *end_match='\0';
1780 temp = rpl(oldrule,old,new);
1781 *end_match = ch;
1782 newrule = strconcat(temp,end_match);
1783 free(temp);
1784 } else if ( sections==0x6 ) {
1785 temp = rpl(end_back,old,new);
1786 ch = *end_back; *end_back = '\0';
1787 newrule = strconcat(oldrule,temp);
1788 *end_back = ch;
1789 free(temp);
1790 } else if ( sections==0x1 ) {
1791 if ( end_back==NULL )
1792 newrule=NULL;
1793 else {
1794 ch = *end_back; *end_back = '\0';
1795 temp = rpl(oldrule,old,new);
1796 *end_back = ch;
1797 newrule = strconcat(temp,end_back);
1798 free(temp);
1799 }
1800 } else if ( sections==0x2 ) {
1801 if ( end_match==NULL ) {
1802 temp = rpl(end_back,old,new); /* end_back is not NULL, checked above */
1803 ch = *end_back; *end_back = '\0';
1804 newrule = strconcat(oldrule,temp);
1805 *end_back = ch;
1806 free(temp);
1807 } else if ( end_back==NULL ) {
1808 ch = *end_match; *end_match = '\0';
1809 temp = rpl(oldrule,old,new);
1810 *end_match = ch;
1811 newrule = strconcat(temp,end_match);
1812 free(temp);
1813 } else {
1814 ch = *end_match; *end_match = '\0';
1815 temp = rpl(end_back,old,new);
1816 *end_match = ch;
1817 ch = *end_back; *end_back = '\0';
1818 newrule = strconcat3(oldrule,temp,end_match);
1819 *end_back = ch;
1820 free(temp);
1821 }
1822 } else if ( sections==0x4 ) {
1823 if ( end_match==NULL )
1824 newrule=NULL;
1825 else {
1826 temp = rpl(end_match,old,new);
1827 ch = *end_match; *end_match = '\0';
1828 newrule = strconcat(oldrule,temp);
1829 *end_match = ch;
1830 free(temp);
1831 }
1832 } else
1833 newrule = NULL;
1834 if ( newrule!=NULL ) {
1835 free(oldrule);
1836 classrules[cols*i+0].u.md_str = newrule;
1837 }
1838 }
1839 }
1840 GGadgetRedraw(gclassrules);
1841 }
1842
1843 static void CCD_FinishClassEdit(GGadget *g,int r, int c, int wasnew) {
1844 struct contextchaindlg *ccd = GDrawGetUserData(GGadgetGetWindow(g));
1845
1846 if ( c==1 )
1847 ME_ClassCheckUnique(g, r, c, ccd->sf);
1848 else if ( c==0 ) {
1849 int rows, i;
1850 struct matrix_data *classes_simple = _GMatrixEditGet(g,&rows);
1851 char buffer[40], *end, *pt;
1852
1853 if ( strchr(classes_simple[3*r+0].u.md_str,' ')!=NULL ) {
1854 for ( pt=classes_simple[3*r+0].u.md_str; *pt; ++pt) {
1855 if ( isspace(*pt))
1856 *pt = '_';
1857 }
1858 GGadgetRedraw(g);
1859 ff_post_error(_("Bad class name"),_("No spaces allowed in class names."));
1860 }
1861 i = strtol(classes_simple[3*r+0].u.md_str,&end,10);
1862 if ( *end=='\0' && i!=r ) {
1863 sprintf( buffer,"%d",r );
1864 free( classes_simple[3*r+0].u.md_str );
1865 classes_simple[3*r+0].u.md_str = copy(buffer);
1866 GGadgetRedraw(g);
1867 ff_post_error(_("Bad class name"),_("If a class name is a number, it must be the index of the class in the array of classes_simple."));
1868 }
1869 for ( i=0; i<rows; ++i ) if ( i!=r ) {
1870 if ( strcmp(classes_simple[3*i+0].u.md_str,classes_simple[3*r+0].u.md_str) == 0 ) {
1871 sprintf( buffer,"%d",r );
1872 free( classes_simple[3*r+0].u.md_str );
1873 classes_simple[3*r+0].u.md_str = copy(buffer);
1874 GGadgetRedraw(g);
1875 ff_post_error(_("Bad class name"),_("The class name, %s, is already in use."), classes_simple[3*i+0].u.md_str);
1876 }
1877 }
1878 if ( strcmp(classes_simple[3*r+0].u.md_str,classes_simple[3*r+2].u.md_str)!=0 ) {
1879 RenameClass(ccd,classes_simple[3*r+2].u.md_str,classes_simple[3*r+0].u.md_str,WhichSections(ccd,g));
1880 free(classes_simple[3*r+2].u.md_str);
1881 classes_simple[3*r+2].u.md_str = copy(classes_simple[3*r+0].u.md_str);
1882 }
1883 }
1884 }
1885
1886 static void CCD_ClassGoing(GGadget *g,int r) {
1887 /* We are about to delete this row in the class dlg, so fix up all numeric */
1888 /* classes_simple after it */
1889 struct contextchaindlg *ccd = GDrawGetUserData(GGadgetGetWindow(g));
1890 int sections = WhichSections(ccd,g);
1891 int rows, i;
1892 struct matrix_data *classes_simple = _GMatrixEditGet(g,&rows);
1893 char buffer[20], *end;
1894
1895 for ( i=r+1; i<rows; ++i ) {
1896 strtol(classes_simple[3*i+0].u.md_str,&end,10);
1897 if ( *end=='\0' ) {
1898 sprintf(buffer,"%d",i-1);
1899 free(classes_simple[3*i+0].u.md_str);
1900 classes_simple[3*i+0].u.md_str = copy(buffer);
1901 RenameClass(ccd,classes_simple[3*i+2].u.md_str,buffer,sections);
1902 free(classes_simple[3*i+2].u.md_str);
1903 classes_simple[3*i+2].u.md_str = copy(buffer);
1904 }
1905 }
1906 }
1907
1908 static void CCD_InitClassRow(GGadget *g,int r) {
1909 char buffer[20];
1910 int rows;
1911 struct matrix_data *classes_simple = _GMatrixEditGet(g,&rows);
1912
1913 sprintf( buffer, "%d", r );
1914 classes_simple[3*r+0].u.md_str = copy(buffer);
1915 }
1916
1917 static int CCD_EnableDeleteClass(GGadget *g,int whichclass) {
1918 return( whichclass>0 );
1919 }
1920
1921 static enum gme_updown CCD_EnableUpDown(GGadget *g,int r) {
1922 int rows;
1923 enum gme_updown ret = 0;
1924
1925 (void) GMatrixEditGet(g,&rows);
1926 if ( r>=2 )
1927 ret = ud_up_enabled;
1928 if ( r>=1 && r<rows-1 )
1929 ret |= ud_down_enabled;
1930 return( ret );
1931 }
1932
1933 static GTextInfo section[] = {
1934 { (unichar_t *) N_("Section|Continue"), NULL, 0, 0, (void *) 0, NULL, 0, 0, 0, 0, 1, 0, 1, 0, 0, '\0'},
1935 { (unichar_t *) N_("Section|Start"), NULL, 0, 0, (void *) 1, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0'},
1936 GTEXTINFO_EMPTY
1937 };
1938 static struct col_init class_ci[] = {
1939 { me_string, NULL, NULL, NULL, N_("Class|Name") },
1940 { me_funcedit, CCD_PickGlyphsForClass, NULL, NULL, N_("Glyphs in the class") },
1941 { me_string, NULL, NULL, NULL, "Old Name (hidden)" },
1942 };
1943 static struct col_init classlist_ci[] = {
1944 { me_string, NULL, NULL, NULL, N_("Class|Name") },
1945 { me_string, NULL, NULL, NULL, N_("Glyphs in the class") },
1946 };
1947 static struct col_init coverage_ci[] = {
1948 { me_funcedit, CCD_PickGlyphsForClass, NULL, NULL, N_("Glyphs in the coverage tables") },
1949 };
1950 static struct col_init seqlookup_ci[] = {
1951 { me_enum, NULL, NULL, NULL, N_("Apply lookup") },
1952 { me_int, NULL, NULL, NULL, N_("at position") },
1953 };
1954 static struct col_init glyphrules_ci[] = {
1955 { me_onlyfuncedit, _CCD_NewGlyphRule, NULL, NULL, N_("Matching rules based on a list of glyphs") },
1956 };
1957 static struct col_init classrules_ci[] = {
1958 { me_onlyfuncedit, _CCD_NewClassRule, NULL, NULL, N_("Matching rules based on a list of classes") },
1959 };
1960 static struct col_init coveragesimple_ci[] = {
1961 { me_funcedit, CCD_PickGlyphsForClass, NULL, NULL, N_("Glyphs in the coverage tables") },
1962 { me_enum, NULL, NULL, NULL, N_("Apply lookup") },
1963 { me_enum, NULL, section, NULL, N_("Section")},
1964 { me_addr, NULL, section, NULL, "Old lookup, internal use only"},
1965 };
1966 static struct col_init rcoveragesimple_ci[] = {
1967 { me_funcedit, CCD_PickGlyphsForClass, NULL, NULL, N_("Glyphs in the coverage tables") },
1968 { me_funcedit, CCD_PickGlyphsForClass, NULL, NULL, N_("Replacement glyphs") },
1969 };
1970 static struct col_init glyph_ci[] = {
1971 { me_string, NULL, NULL, NULL, N_("Matching rules based on a list of glyphs") },
1972 };
1973 static struct col_init classsimple_ci[] = {
1974 { me_string, NULL, NULL, NULL, N_("Matching rules based on a list of classes") },
1975 };
1976
1977 /* The "simple" dialog has several problems:
1978 1. The order in which lookups are to be applied is lost, they will be
1979 applied in sequence order
1980 2. In coverage_simple classes_simple only one lookup may be applied for any given
1981 coverage_simple set.
1982 Adobe's feature files have these restrictions and more, so my hope is that
1983 they will not matter.
1984 If they do matter, then we fall back on the old, more complex (I think more
1985 complex anyway) format.
1986 */
1987 static int CanBeSimple(FPST *fpst) {
1988 int i, s, last_seq;
1989 for ( i=0; i<fpst->rule_cnt; ++i ) {
1990 struct fpst_rule *r = &fpst->rules[i];
1991
1992 last_seq = -1;
1993 for ( s=0; s<r->lookup_cnt; ++s ) {
1994 if ( last_seq>r->lookups[s].seq )
1995 return( false );
1996 else if ( last_seq==r->lookups[s].seq &&
1997 (fpst->format==pst_coverage || fpst->format==pst_reversecoverage))
1998 return( false );
1999 last_seq = r->lookups[s].seq;
2000 }
2001 }
2002 return( true );
2003 }
2004
2005 void ContextChainEdit(SplineFont *sf,FPST *fpst,
2006 struct gfi_data *gfi, unichar_t *newname,int layer) {
2007 struct contextchaindlg *ccd;
2008 int i,j,k;
2009 static char *titles[2][5] = {
2010 { N_("Edit Contextual Position"), N_("Edit Contextual Substitution"),
2011 N_("Edit Chaining Position"), N_("Edit Chaining Substitution"),
2012 N_("Edit Reverse Chaining Substitution"),
2013 },
2014 { N_("New Contextual Position"), N_("New Contextual Substitution"),
2015 N_("New Chaining Position"), N_("New Chaining Substitution"),
2016 N_("New Reverse Chaining Substitution")
2017 }};
2018 GRect pos, subpos;
2019 GWindow gw;
2020 GWindowAttrs wattrs;
2021 GTabInfo faspects[5];
2022 GGadgetCreateData glgcd[8], fgcd[3], ggcd[3][14], cgcd[3][18],
2023 clgcd[10], subboxes[3][5], topbox[3], classbox[2], extrabuttonsgcd[3];
2024 GTextInfo gllabel[8], flabel[3], glabel[3][14], clabel[3][18],
2025 cllabel[10], extrabuttonslab[3];
2026 GGadgetCreateData bgcd[6], rgcd[15], boxes[4], *barray[10], *hvarray[7][2];
2027 GGadgetCreateData *subvarray[3][10], *subvarray2[4], *subvarray3[4], *topvarray[8],
2028 *classv[4], *subvarray4[4], *barray2[6];
2029 GTextInfo blabel[5], rlabel[15];
2030 struct fpst_rule *r=NULL;
2031 FPST *tempfpst;
2032 struct matrixinit coverage_mi[3], class_mi[3], classlist_mi[3],
2033 gl_seqlookup_mi, cl_seqlookup_mi,
2034 co_seqlookup_mi, classrules_mi, glyphrules_mi,
2035 coveragesimple_mi, classsimple_mi, glyphs_mi;
2036 static int inited=false;
2037 int isgpos = ( fpst->type==pst_contextpos || fpst->type==pst_chainpos );
2038 struct matrix_data *md;
2039 GTextInfo *lookup_list, *addlookup_list, *addrmlookup_list;
2040 int use_simple = CanBeSimple(fpst);
2041 struct matrix_data *_classes[3]; int clen[3];
2042
2043 lookup_list = SFLookupArrayFromType(sf,isgpos?gpos_start:gsub_start);
2044 for ( i=0; lookup_list[i].text!=NULL; ++i ) {
2045 if (fpst!=NULL && lookup_list[i].userdata == fpst->subtable->lookup )
2046 lookup_list[i].disabled = true;
2047 lookup_list[i].selected = false;
2048 }
2049 addlookup_list = calloc(i+3,sizeof(GTextInfo));
2050 memcpy(addlookup_list+1,lookup_list,(i+1)*sizeof(GTextInfo));
2051 addrmlookup_list = calloc(i+3,sizeof(GTextInfo));
2052 memcpy(addrmlookup_list+2,lookup_list,(i+1)*sizeof(GTextInfo));
2053 addlookup_list[0].text = (unichar_t *) S_("Add Lookup");
2054 addlookup_list[0].text_is_1byte = true;
2055 addlookup_list[0].selected = true;
2056 addrmlookup_list[0].text = (unichar_t *) S_("Add Lookup");
2057 addrmlookup_list[0].text_is_1byte = true;
2058 addrmlookup_list[0].selected = true;
2059 addrmlookup_list[1].text = (unichar_t *) S_("Remove Lookup");
2060 addrmlookup_list[1].text_is_1byte = true;
2061 addrmlookup_list[1].selected = false;
2062 addrmlookup_list[1].userdata = (void *) (intptr_t) -1;
2063 coveragesimple_ci[1].enum_vals = addrmlookup_list;
2064 seqlookup_ci[0].enum_vals = lookup_list;
2065
2066 if ( !inited ) {
2067 inited = true;
2068 section[0].text = (unichar_t *) S_( (char *) section[0].text);
2069 section[1].text = (unichar_t *) S_( (char *) section[1].text);
2070 classlist_ci[0].title = class_ci[0].title = S_(class_ci[0].title);
2071 classlist_ci[1].title = class_ci[1].title = S_(class_ci[1].title);
2072 coverage_ci[0].title = S_(coverage_ci[0].title);
2073 seqlookup_ci[0].title = S_(seqlookup_ci[0].title);
2074 seqlookup_ci[1].title = S_(seqlookup_ci[1].title);
2075 glyphrules_ci[0].title = S_(glyphrules_ci[0].title);
2076 classrules_ci[0].title = S_(classrules_ci[0].title);
2077 coveragesimple_ci[0].title = S_(coveragesimple_ci[0].title);
2078 coveragesimple_ci[1].title = S_(coveragesimple_ci[1].title);
2079 coveragesimple_ci[2].title = S_(coveragesimple_ci[2].title);
2080 rcoveragesimple_ci[0].title = S_(rcoveragesimple_ci[0].title);
2081 rcoveragesimple_ci[1].title = S_(rcoveragesimple_ci[1].title);
2082 glyph_ci[0].title = S_(glyph_ci[0].title);
2083 }
2084
2085 ccd = chunkalloc(sizeof(struct contextchaindlg));
2086 ccd->gfi = gfi;
2087 ccd->sf = sf;
2088 ccd->fpst = fpst;
2089 ccd->newname = newname;
2090 ccd->isnew = newname!=NULL;
2091 ccd->layer = layer;
2092
2093 memset(&wattrs,0,sizeof(wattrs));
2094 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict;
2095 wattrs.event_masks = ~(1<<et_charup);
2096 wattrs.is_dlg = true;
2097 wattrs.restrict_input_to_me = false;
2098 wattrs.undercursor = 1;
2099 wattrs.cursor = ct_pointer;
2100 wattrs.utf8_window_title = _(titles[ccd->isnew][fpst->type-pst_contextpos]);
2101 pos.x = pos.y = 0;
2102 pos.width =GDrawPointsToPixels(NULL,GGadgetScale(CCD_WIDTH));
2103 pos.height = GDrawPointsToPixels(NULL,CCD_HEIGHT);
2104 ccd->gw = gw = GDrawCreateTopWindow(NULL,&pos,ccd_e_h,ccd,&wattrs);
2105
2106 subpos = pos;
2107 subpos.y = subpos.x = 4;
2108 subpos.width -= 8;
2109 ccd->subheightdiff = GDrawPointsToPixels(NULL,44)-8;
2110 subpos.height -= ccd->subheightdiff;
2111
2112
2113 memset(&blabel,0,sizeof(blabel));
2114 memset(&bgcd,0,sizeof(bgcd));
2115 memset(&boxes,0,sizeof(boxes));
2116
2117 ccd->canceldrop = GDrawPointsToPixels(NULL,30);
2118 bgcd[0].gd.pos = subpos;
2119 bgcd[0].gd.flags = gg_visible | gg_enabled | gg_pos_in_pixels;
2120 bgcd[0].gd.cid = CID_SubSize;
2121 bgcd[0].creator = GSpacerCreate;
2122 hvarray[0][0] = &bgcd[0]; hvarray[0][1] = NULL;
2123
2124 bgcd[1].gd.flags = gg_visible | gg_enabled;
2125 blabel[1].text = (unichar_t *) _("_OK");
2126 blabel[1].text_is_1byte = true;
2127 blabel[1].text_in_resource = true;
2128 bgcd[1].gd.label = &blabel[1];
2129 bgcd[1].gd.cid = CID_OK;
2130 bgcd[1].gd.handle_controlevent = CCD_OK;
2131 bgcd[1].creator = GButtonCreate;
2132 barray[0] = GCD_Glue; barray[1] = &bgcd[1];
2133
2134 bgcd[2].gd.flags = gg_visible;
2135 blabel[2].text = (unichar_t *) _("< _Prev");
2136 blabel[2].text_is_1byte = true;
2137 blabel[2].text_in_resource = true;
2138 bgcd[2].gd.label = &blabel[2];
2139 bgcd[2].gd.handle_controlevent = CCD_Prev;
2140 bgcd[2].gd.cid = CID_Prev;
2141 bgcd[2].creator = GButtonCreate;
2142 barray[2] = GCD_Glue; barray[3] = &bgcd[2];
2143
2144 bgcd[3].gd.flags = gg_visible;
2145 blabel[3].text = (unichar_t *) _("_Next >");
2146 blabel[3].text_is_1byte = true;
2147 blabel[3].text_in_resource = true;
2148 bgcd[3].gd.label = &blabel[3];
2149 bgcd[3].gd.handle_controlevent = CCD_Next;
2150 bgcd[3].gd.cid = CID_Next;
2151 bgcd[3].creator = GButtonCreate;
2152 barray[4] = GCD_Glue; barray[5] = &bgcd[3];
2153
2154 bgcd[4].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
2155 blabel[4].text = (unichar_t *) _("_Cancel");
2156 blabel[4].text_is_1byte = true;
2157 blabel[4].text_in_resource = true;
2158 bgcd[4].gd.label = &blabel[4];
2159 bgcd[4].gd.handle_controlevent = CCD_Cancel;
2160 bgcd[4].gd.cid = CID_Cancel;
2161 bgcd[4].creator = GButtonCreate;
2162 barray[6] = GCD_Glue; barray[7] = &bgcd[4]; barray[8] = GCD_Glue; barray[9] = NULL;
2163
2164 boxes[2].gd.flags = gg_enabled | gg_visible;
2165 boxes[2].gd.u.boxelements = barray;
2166 boxes[2].creator = GHBoxCreate;
2167 hvarray[1][0] = &boxes[2]; hvarray[1][1] = hvarray[2][0] = NULL;
2168
2169 boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2;
2170 boxes[0].gd.flags = gg_enabled | gg_visible;
2171 boxes[0].gd.u.boxelements = hvarray[0];
2172 boxes[0].creator = GHVGroupCreate;
2173
2174 if ( fpst->type == pst_reversesub ) {
2175 bgcd[2].gd.flags = bgcd[3].gd.flags = gg_visible;
2176 ccd->aw = use_simple ? aw_coverage_simple : aw_coverage;
2177 } else if ( ccd->isnew || fpst->rule_cnt==0) {
2178 fpst->format = pst_class;
2179 bgcd[1].gd.flags = gg_visible;
2180 bgcd[3].gd.flags = gg_visible | gg_enabled;
2181 ccd->aw = aw_formats;
2182 } else if ( fpst->format==pst_coverage ) {
2183 bgcd[2].gd.flags = gg_visible | gg_enabled;
2184 bgcd[3].gd.flags = gg_visible;
2185 ccd->aw = use_simple ? aw_coverage_simple : aw_coverage;
2186 /* different buttens are enabled from those of reversesub above */
2187 } else if ( fpst->format==pst_class ) {
2188 bgcd[2].gd.flags = gg_visible | gg_enabled;
2189 bgcd[3].gd.flags = gg_visible;
2190 ccd->aw = use_simple ? aw_classes_simple : aw_classrules;
2191 } else {
2192 bgcd[2].gd.flags = gg_visible | gg_enabled;
2193 bgcd[3].gd.flags = gg_visible;
2194 ccd->aw = use_simple ? aw_glyphs_simple : aw_grules;
2195 }
2196
2197 GGadgetsCreate(gw,boxes);
2198 GHVBoxSetExpandableRow(boxes[0].ret,0);
2199 GHVBoxSetExpandableCol(boxes[2].ret,gb_expandgluesame);
2200 /*GHVBoxFitWindow(boxes[0].ret);*/
2201
2202 wattrs.mask = wam_events;
2203 ccd->formats = GWidgetCreateSubWindow(ccd->gw,&subpos,subccd_e_h,ccd,&wattrs);
2204 memset(&rlabel,0,sizeof(rlabel));
2205 memset(&rgcd,0,sizeof(rgcd));
2206 memset(boxes,0,sizeof(boxes));
2207
2208 i = 0;
2209 rgcd[i].gd.pos.x = 5; rgcd[i].gd.pos.y = 5+i*13;
2210 rgcd[i].gd.flags = gg_visible | gg_enabled;
2211 rlabel[i].text = (unichar_t *) _(
2212 "OpenType Contextual or Chaining subtables may be in one\n"
2213 " of three formats. The context may be specified either\n"
2214 " as a string of specific glyphs, a string of glyph classes\n"
2215 " or a string of coverage tables\n"
2216 "In the first format you must specify a string of glyph-names\n"
2217 " In the second format you must specify a string of class names\n"
2218 " In the third format you must specify a string each element\n"
2219 " of which may contain several glyph-names\n"
2220 "For chaining subtables you may also specify backtrack and\n"
2221 " lookahead lists.");
2222 rlabel[i].text_is_1byte = true;
2223 rgcd[i].gd.label = &rlabel[i];
2224 rgcd[i++].creator = GLabelCreate;
2225 hvarray[0][0] = &rgcd[i-1]; hvarray[0][1] = NULL;
2226
2227 rgcd[i].gd.flags = gg_visible | gg_enabled | (fpst->format==pst_glyphs ? gg_cb_on : 0 );
2228 rlabel[i].text = (unichar_t *) _("By Glyphs");
2229 rlabel[i].text_is_1byte = true;
2230 rgcd[i].gd.label = &rlabel[i];
2231 rgcd[i].gd.cid = CID_ByGlyph;
2232 rgcd[i++].creator = GRadioCreate;
2233 barray[0] = GCD_HPad10; barray[1] = &rgcd[i-1];
2234
2235 rgcd[i].gd.pos.x = rgcd[i-1].gd.pos.x; rgcd[i].gd.pos.y = rgcd[i-1].gd.pos.y+16;
2236 rgcd[i].gd.flags = gg_visible | gg_enabled | (fpst->format==pst_class ? gg_cb_on : 0 );
2237 rlabel[i].text = (unichar_t *) _("By Classes");
2238 rlabel[i].text_is_1byte = true;
2239 rgcd[i].gd.label = &rlabel[i];
2240 rgcd[i].gd.cid = CID_ByClass;
2241 rgcd[i++].creator = GRadioCreate;
2242 barray[2] = &rgcd[i-1];
2243
2244 rgcd[i].gd.pos.x = rgcd[i-1].gd.pos.x; rgcd[i].gd.pos.y = rgcd[i-1].gd.pos.y+16;
2245 rgcd[i].gd.flags = gg_visible | gg_enabled | (fpst->format!=pst_glyphs && fpst->format!=pst_class ? gg_cb_on : 0 );
2246 rlabel[i].text = (unichar_t *) _("By Coverage");
2247 rlabel[i].text_is_1byte = true;
2248 rgcd[i].gd.label = &rlabel[i];
2249 rgcd[i].gd.cid = CID_ByCoverage;
2250 rgcd[i++].creator = GRadioCreate;
2251 barray[3] = &rgcd[i-1]; barray[4] = GCD_Glue; barray[5] = NULL;
2252
2253 boxes[2].gd.flags = gg_enabled|gg_visible;
2254 boxes[2].gd.u.boxelements = barray;
2255 boxes[2].creator = GHBoxCreate;
2256 hvarray[1][0] = &boxes[2]; hvarray[1][1] = NULL;
2257
2258 rgcd[i].gd.flags = gg_visible | gg_enabled;
2259 rlabel[i].text = (unichar_t *) _(
2260 "This dialog has two formats. A simpler one which\n"
2261 " hides some of the complexities of these rules,\n"
2262 " or a more complex form which gives you full control.");
2263 rlabel[i].text_is_1byte = true;
2264 rgcd[i].gd.label = &rlabel[i];
2265 rgcd[i++].creator = GLabelCreate;
2266 hvarray[2][0] = GCD_HPad10; hvarray[2][1] = NULL;
2267 hvarray[3][0] = &rgcd[i-1]; hvarray[3][1] = NULL;
2268
2269 rgcd[i].gd.pos.x = 5; rgcd[i].gd.pos.y = 5+i*13;
2270 rgcd[i].gd.flags = gg_visible | gg_enabled;
2271 rlabel[i].text = (unichar_t *) _( "Dialog Type:");
2272 rlabel[i].text_is_1byte = true;
2273 rgcd[i].gd.label = &rlabel[i];
2274 rgcd[i++].creator = GLabelCreate;
2275 barray2[0] = GCD_HPad10; barray2[1] = &rgcd[i-1];
2276
2277 rgcd[i].gd.pos.x = rgcd[i-1].gd.pos.x; rgcd[i].gd.pos.y = rgcd[i-1].gd.pos.y+16;
2278 rgcd[i].gd.flags = gg_visible | gg_enabled | (use_simple ? gg_cb_on : 0 );
2279 rlabel[i].text = (unichar_t *) _("Simple");
2280 rlabel[i].text_is_1byte = true;
2281 rgcd[i].gd.label = &rlabel[i];
2282 rgcd[i].gd.cid = CID_Simple;
2283 rgcd[i++].creator = GRadioCreate;
2284 barray2[2] = &rgcd[i-1];
2285
2286 rgcd[i].gd.pos.x = rgcd[i-1].gd.pos.x; rgcd[i].gd.pos.y = rgcd[i-1].gd.pos.y+16;
2287 rgcd[i].gd.flags = gg_visible | gg_enabled | (!use_simple ? gg_cb_on : 0 );
2288 rlabel[i].text = (unichar_t *) _("Complex");
2289 rlabel[i].text_is_1byte = true;
2290 rgcd[i].gd.label = &rlabel[i];
2291 rgcd[i].gd.cid = CID_Complex;
2292 rgcd[i++].creator = GRadioCreate;
2293 barray2[3] = &rgcd[i-1]; barray2[4] = GCD_Glue; barray2[5] = NULL;
2294
2295 boxes[3].gd.flags = gg_enabled|gg_visible;
2296 boxes[3].gd.u.boxelements = barray2;
2297 boxes[3].creator = GHBoxCreate;
2298 hvarray[4][0] = &boxes[3]; hvarray[4][1] = NULL;
2299 hvarray[5][0] = GCD_Glue; hvarray[5][1] = NULL; hvarray[6][0] = NULL;
2300
2301 boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2;
2302 boxes[0].gd.flags = gg_enabled|gg_visible;
2303 boxes[0].gd.u.boxelements = hvarray[0];
2304 boxes[0].creator = GHVGroupCreate;
2305
2306 GGadgetsCreate(ccd->formats,boxes);
2307 GHVBoxSetExpandableRow(boxes[0].ret,gb_expandglue);
2308 GHVBoxSetExpandableCol(boxes[2].ret,gb_expandgluesame);
2309 GHVBoxSetExpandableCol(boxes[3].ret,gb_expandglue);
2310
2311 /* Pane showing all rules from a glyph format, simple format */
2312 ccd->grules = GWidgetCreateSubWindow(ccd->gw,&subpos,subccd_e_h,ccd,&wattrs);
2313 memset(&gllabel,0,sizeof(gllabel));
2314 memset(&glgcd,0,sizeof(glgcd));
2315
2316 k = 0;
2317 memset(&glyphrules_mi,0,sizeof(glyphrules_mi));
2318 glyphrules_mi.col_cnt = 1;
2319 glyphrules_mi.col_init = glyphrules_ci;
2320 if ( fpst->format==pst_glyphs && fpst->rule_cnt>0 ) {
2321 glyphrules_mi.initial_row_cnt = fpst->rule_cnt;
2322 md = calloc(fpst->rule_cnt,sizeof(struct matrix_data));
2323 for ( j=0; j<fpst->rule_cnt; ++j ) {
2324 md[j+0].u.md_str = gruleitem(&fpst->rules[j]);
2325 }
2326 glyphrules_mi.matrix_data = md;
2327 } else {
2328 glyphrules_mi.initial_row_cnt = 0;
2329 glyphrules_mi.matrix_data = NULL;
2330 }
2331 glgcd[k].gd.flags = gg_visible | gg_enabled;
2332 glgcd[k].gd.cid = CID_GList+0;
2333 glgcd[k].gd.u.matrix = &glyphrules_mi;
2334 glgcd[k++].creator = GMatrixEditCreate;
2335 /* No need for a box, this widget fills the pane */
2336
2337 GGadgetsCreate(ccd->grules,glgcd);
2338 GMatrixEditSetUpDownVisible(GWidgetGetControl(ccd->grules,CID_GList+0),
2339 true);
2340 GMatrixEditSetOtherButtonEnable(GWidgetGetControl(ccd->grules,CID_GList+0),CCD_NewGlyphRule);
2341
2342 ccd->glyphs_simple = GWidgetCreateSubWindow(ccd->gw,&subpos,subccd_e_h,ccd,&wattrs);
2343 memset(&gllabel,0,sizeof(gllabel));
2344 memset(&glgcd,0,sizeof(glgcd));
2345
2346 k = 0;
2347 memset(&glyphs_mi,0,sizeof(glyphs_mi));
2348 glyphs_mi.col_cnt = 1;
2349 glyphs_mi.col_init = glyph_ci;
2350 if ( fpst->format==pst_glyphs && fpst->rule_cnt>0 ) {
2351 glyphs_mi.initial_row_cnt = fpst->rule_cnt;
2352 md = calloc(fpst->rule_cnt,sizeof(struct matrix_data));
2353 for ( j=0; j<fpst->rule_cnt; ++j ) {
2354 md[j+0].u.md_str = FPSTRule_To_Str(sf,fpst,&fpst->rules[j]);
2355 }
2356 glyphs_mi.matrix_data = md;
2357 } else {
2358 glyphs_mi.initial_row_cnt = 0;
2359 glyphs_mi.matrix_data = NULL;
2360 }
2361 glgcd[k].gd.flags = gg_visible | gg_enabled;
2362 glgcd[k].gd.cid = CID_GList_Simple;
2363 glgcd[k].gd.u.matrix = &glyphs_mi;
2364 glgcd[k++].creator = GMatrixEditCreate;
2365 /* No need for a box, this widget fills the pane */
2366
2367 GGadgetsCreate(ccd->glyphs_simple,glgcd);
2368 GMatrixEditSetUpDownVisible(GWidgetGetControl(ccd->glyphs_simple,CID_GList_Simple),
2369 true);
2370 GMatrixEditSetColumnCompletion(GWidgetGetControl(ccd->glyphs_simple,CID_GList_Simple),0,
2371 CCD_GlyphListCompletion);
2372
2373 memset(&extrabuttonslab,0,sizeof(extrabuttonslab));
2374 memset(&extrabuttonsgcd,0,sizeof(extrabuttonsgcd));
2375
2376 i=0;
2377 if ( fpst->type==pst_chainpos || fpst->type==pst_chainsub ) {
2378 extrabuttonsgcd[i].gd.flags = gg_visible | gg_enabled;
2379 extrabuttonslab[i].text = (unichar_t *) _("New Section");
2380 extrabuttonslab[i].text_is_1byte = true;
2381 extrabuttonsgcd[i].gd.label = &extrabuttonslab[i];
2382 extrabuttonsgcd[i].gd.cid = CID_GNewSection;
2383 extrabuttonsgcd[i].gd.handle_controlevent = CCD_NewSection;
2384 extrabuttonsgcd[i++].creator = GButtonCreate;
2385 }
2386 extrabuttonsgcd[i].gd.flags = gg_visible | gg_enabled;
2387 extrabuttonslab[i].text = (unichar_t *) _("Add Lookup");
2388 extrabuttonslab[i].text_is_1byte = true;
2389 extrabuttonsgcd[i].gd.u.list = addlookup_list;
2390 extrabuttonsgcd[i].gd.label = &extrabuttonslab[i];
2391 GDrawSetDefaultFont(ccd->glyphs_simple);
2392 extrabuttonsgcd[i].gd.pos.width = GDrawPixelsToPoints(ccd->glyphs_simple,
2393 GDrawGetText8Width(ccd->glyphs_simple,(char *)extrabuttonslab[i].text,-1))+50;
2394 extrabuttonsgcd[i].gd.cid = CID_GAddLookup;
2395 extrabuttonsgcd[i].gd.handle_controlevent = CCD_AddLookup;
2396 extrabuttonsgcd[i++].creator = GListButtonCreate;
2397 GMatrixEditAddButtons(GWidgetGetControl(ccd->glyphs_simple,CID_GList_Simple),extrabuttonsgcd);
2398
2399 /* Pane showing a single rule from a glyph format (not classes or coverage tables) */
2400 ccd->glyphs = GWidgetCreateSubWindow(ccd->gw,&subpos,subccd_e_h,ccd,&wattrs);
2401 memset(&ggcd,0,sizeof(ggcd));
2402 memset(&fgcd,0,sizeof(fgcd));
2403 memset(&glabel,0,sizeof(glabel));
2404 memset(&flabel,0,sizeof(flabel));
2405 memset(&faspects,0,sizeof(faspects));
2406 memset(&subboxes,0,sizeof(subboxes));
2407 memset(&topbox,0,sizeof(topbox));
2408 for ( i=0; i<3; ++i ) { /* Match, background foreground tabs */
2409 k=0;
2410 glabel[i][k].text = (unichar_t *) _("Set From Selection");
2411 glabel[i][k].text_is_1byte = true;
2412 ggcd[i][k].gd.label = &glabel[i][k];
2413 ggcd[i][k].gd.popup_msg = _("Set this glyph list from a selection.");
2414 ggcd[i][k].gd.flags = gg_visible | gg_enabled;
2415 ggcd[i][k].gd.handle_controlevent = CCD_FromSelection;
2416 ggcd[i][k].data=(void *)((intptr_t)CID_GlyphList+(0*100+i*20));
2417 ggcd[i][k++].creator = GButtonCreate;
2418 subvarray[i][0] = &ggcd[i][k-1];
2419
2420 ggcd[i][k].gd.flags = gg_visible | gg_enabled | gg_textarea_wrap;
2421 ggcd[i][k].gd.cid = CID_GlyphList+(0*100+i*20);
2422 ggcd[i][k].gd.u.completion = CCD_GlyphListCompletion;
2423 ggcd[i][k++].creator = GTextCompletionCreate;
2424 subvarray[i][1] = &ggcd[i][k-1];
2425
2426 if ( i==0 ) {
2427 glabel[i][k].text = (unichar_t *) _("An ordered list of lookups and positions");
2428 glabel[i][k].text_is_1byte = true;
2429 ggcd[i][k].gd.label = &glabel[i][k];
2430 ggcd[i][k].gd.flags = gg_visible | gg_enabled;
2431 ggcd[i][k++].creator = GLabelCreate;
2432 subvarray[i][2] = &ggcd[i][k-1];
2433
2434 memset(&gl_seqlookup_mi,0,sizeof(gl_seqlookup_mi));
2435 gl_seqlookup_mi.col_cnt = 2;
2436 gl_seqlookup_mi.col_init = seqlookup_ci;
2437 gl_seqlookup_mi.matrix_data = NULL;
2438 gl_seqlookup_mi.initial_row_cnt = 0;
2439
2440 ggcd[i][k].gd.flags = gg_visible | gg_enabled;
2441 ggcd[i][k].gd.cid = CID_LookupList+0;
2442 ggcd[i][k].gd.u.matrix = &gl_seqlookup_mi;
2443 ggcd[i][k++].creator = GMatrixEditCreate;
2444 subvarray[i][3] = &ggcd[i][k-1];
2445 } else
2446 subvarray[i][2] = subvarray[i][3] = GCD_Glue;
2447 subvarray[i][4] = NULL;
2448
2449 subboxes[i][0].gd.flags = gg_enabled|gg_visible;
2450 subboxes[i][0].gd.u.boxelements = subvarray[i];
2451 subboxes[i][0].creator = GVBoxCreate;
2452 }
2453
2454 j = 0;
2455
2456 faspects[j].text = (unichar_t *) _("Match");
2457 faspects[j].text_is_1byte = true;
2458 faspects[j].selected = true;
2459 faspects[j].gcd = subboxes[j]; ++j;
2460
2461 faspects[j].text = (unichar_t *) _("Backtrack");
2462 faspects[j].text_is_1byte = true;
2463 faspects[j].disabled = fpst->type==pst_contextpos || fpst->type==pst_contextsub;
2464 faspects[j].gcd = subboxes[j]; ++j;
2465
2466 faspects[j].text = (unichar_t *) _("Lookahead");
2467 faspects[j].text_is_1byte = true;
2468 faspects[j].disabled = fpst->type==pst_contextpos || fpst->type==pst_contextsub;
2469 faspects[j].gcd = subboxes[j]; ++j;
2470
2471 flabel[0].text = (unichar_t *) _("A list of glyphs:");
2472 flabel[0].text_is_1byte = true;
2473 fgcd[0].gd.label = &flabel[0];
2474 fgcd[0].gd.flags = gg_visible | gg_enabled;
2475 fgcd[0].creator = GLabelCreate;
2476 topvarray[0] = &fgcd[0];
2477
2478 fgcd[1].gd.u.tabs = faspects;
2479 fgcd[1].gd.flags = gg_visible | gg_enabled;
2480 fgcd[1].gd.cid = CID_MatchType;
2481 fgcd[1].creator = GTabSetCreate;
2482 topvarray[1] = &fgcd[1];
2483 topvarray[2] = NULL;
2484 topbox[0].gd.flags = gg_enabled|gg_visible;
2485 topbox[0].gd.u.boxelements = topvarray;
2486 topbox[0].creator = GVBoxCreate;
2487 GGadgetsCreate(ccd->glyphs,topbox);
2488
2489 GMatrixEditSetUpDownVisible(GWidgetGetControl(ccd->glyphs,CID_LookupList+0),
2490 true);
2491 GHVBoxSetExpandableRow(topbox[0].ret,1);
2492 GHVBoxSetExpandableRow(subboxes[0][0].ret,3);
2493 GHVBoxSetExpandableRow(subboxes[1][0].ret,gb_expandglue);
2494 GHVBoxSetExpandableRow(subboxes[2][0].ret,gb_expandglue);
2495
2496 /* Pane showing the single rule in a coverage table (complex) */
2497 ccd->coverage = GWidgetCreateSubWindow(ccd->gw,&subpos,subccd_e_h,ccd,&wattrs);
2498 memset(&clabel,0,sizeof(clabel));
2499 memset(&cgcd,0,sizeof(cgcd));
2500 memset(&subboxes,0,sizeof(subboxes));
2501 memset(&topbox,0,sizeof(topbox));
2502
2503 for ( i=0; i<3; ++i ) {
2504 k = 0;
2505 memset(&coverage_mi[i],0,sizeof(coverage_mi[i]));
2506 coverage_mi[i].col_cnt = 1;
2507 coverage_mi[i].col_init = coverage_ci;
2508 if (( fpst->format==pst_coverage || fpst->format==pst_reversecoverage )
2509 && fpst->rules!=NULL ) {
2510 int cnt = (&fpst->rules[0].u.coverage.ncnt)[i];
2511 char **names = (&fpst->rules[0].u.coverage.ncovers)[i];
2512 coverage_mi[i].initial_row_cnt = cnt;
2513 md = calloc(cnt,sizeof(struct matrix_data));
2514 for ( j=0; j<cnt; ++j ) {
2515 md[j].u.md_str = SFNameList2NameUni(sf,names[j]);
2516 }
2517 coverage_mi[i].matrix_data = md;
2518 } else {
2519 coverage_mi[i].initial_row_cnt = 0;
2520 coverage_mi[i].matrix_data = NULL;
2521 }
2522 coverage_mi[i].finishedit = CCD_FinishCoverageEdit;
2523 cgcd[i][k].gd.flags = gg_visible | gg_enabled;
2524 cgcd[i][k].gd.cid = CID_GList+100+i*20;
2525 cgcd[i][k].gd.u.matrix = &coverage_mi[i];
2526 cgcd[i][k++].creator = GMatrixEditCreate;
2527
2528 faspects[i].gcd = &cgcd[i][k-1];
2529
2530 if ( i==0 ) {
2531 if ( ccd->fpst->type!=pst_reversesub ) {
2532 clabel[i][k].text = (unichar_t *) _("An ordered list of lookups and positions");
2533 clabel[i][k].text_is_1byte = true;
2534 cgcd[i][k].gd.label = &clabel[i][k];
2535 cgcd[i][k].gd.flags = gg_visible | gg_enabled;
2536 cgcd[i][k++].creator = GLabelCreate;
2537 subvarray2[0] = &cgcd[i][k-1];
2538
2539 memset(&co_seqlookup_mi,0,sizeof(co_seqlookup_mi));
2540 co_seqlookup_mi.col_cnt = 2;
2541 co_seqlookup_mi.col_init = seqlookup_ci;
2542 if ( fpst->format==pst_coverage ) {
2543 r = &fpst->rules[0];
2544 co_seqlookup_mi.initial_row_cnt = r->lookup_cnt;
2545 md = calloc(2*r->lookup_cnt,sizeof(struct matrix_data));
2546 for ( j=0; j<r->lookup_cnt; ++j ) {
2547 md[2*j+0].u.md_ival = (intptr_t) (void *) r->lookups[j].lookup;
2548 md[2*j+1].u.md_ival = (intptr_t) r->lookups[j].seq;
2549 }
2550 co_seqlookup_mi.matrix_data = md;
2551 } else {
2552 co_seqlookup_mi.initial_row_cnt = 0;
2553 co_seqlookup_mi.matrix_data = NULL;
2554 }
2555 cgcd[i][k].gd.flags = gg_visible | gg_enabled;
2556 cgcd[i][k].gd.cid = CID_LookupList+100+(i*20);
2557 cgcd[i][k].gd.u.matrix = &co_seqlookup_mi;
2558 cgcd[i][k++].creator = GMatrixEditCreate;
2559 subvarray2[1] = &cgcd[i][k-1];
2560 subvarray2[2] = NULL;
2561
2562 subboxes[i][1].gd.flags = gg_enabled|gg_visible;
2563 subboxes[i][1].gd.u.boxelements = subvarray2;
2564 subboxes[i][1].creator = GVBoxCreate;
2565
2566 subvarray3[0] = &cgcd[i][0];
2567 subvarray3[1] = &subboxes[i][1];
2568 subvarray3[2] = NULL;
2569
2570 subboxes[i][2].gd.flags = gg_enabled|gg_visible;
2571 subboxes[i][2].gd.u.boxelements = subvarray3;
2572 subboxes[i][2].creator = GVBoxCreate;
2573 faspects[i].gcd = subboxes[i]+2;
2574 } else {
2575 r = NULL;
2576 if ( fpst->rule_cnt==1 ) r = &fpst->rules[0];
2577
2578 clabel[i][k].text = (unichar_t *) _("Replacements");
2579 clabel[i][k].text_is_1byte = true;
2580 cgcd[i][k].gd.label = &clabel[i][k];
2581 cgcd[i][k].gd.flags = gg_visible | gg_enabled;
2582 cgcd[i][k++].creator = GLabelCreate;
2583 subvarray2[0] = &cgcd[i][k-1];
2584
2585 clabel[i][k].text = (unichar_t *) _("Set From Selection");
2586 clabel[i][k].text_is_1byte = true;
2587 cgcd[i][k].gd.label = &clabel[i][k];
2588 cgcd[i][k].gd.popup_msg = _("Set this glyph list from a selection.");
2589 cgcd[i][k].gd.flags = gg_visible | gg_enabled;
2590 cgcd[i][k].gd.handle_controlevent = CCD_FromSelection;
2591 cgcd[i][k].data = (void *) (intptr_t) (CID_RplList+100);
2592 cgcd[i][k++].creator = GButtonCreate;
2593 subvarray2[1] = &cgcd[i][k-1];
2594 subvarray2[2] = GCD_Glue;
2595 subvarray2[3] = NULL;
2596
2597 subboxes[i][1].gd.flags = gg_enabled|gg_visible;
2598 subboxes[i][1].gd.u.boxelements = subvarray2;
2599 subboxes[i][1].creator = GHBoxCreate;
2600 subvarray3[0] = &subboxes[i][1];
2601
2602 if ( r!=NULL && r->u.rcoverage.replacements!=NULL ) {
2603 clabel[i][k].text = (unichar_t *) SFNameList2NameUni(sf,r->u.rcoverage.replacements);
2604 clabel[i][k].text_is_1byte = true;
2605 cgcd[i][k].gd.label = &clabel[i][k];
2606 }
2607 cgcd[i][k].gd.flags = gg_visible | gg_enabled;
2608 cgcd[i][k].gd.cid = CID_RplList+100;
2609 cgcd[i][k].gd.u.completion = CCD_GlyphListCompletion;
2610 cgcd[i][k++].creator = GTextCompletionCreate;
2611 subvarray3[1] = &cgcd[i][k-1];
2612 subvarray3[2] = GCD_Glue;
2613 subvarray3[3] = NULL;
2614
2615 subboxes[i][2].gd.flags = gg_enabled|gg_visible;
2616 subboxes[i][2].gd.u.boxelements = subvarray3;
2617 subboxes[i][2].creator = GVBoxCreate;
2618
2619 subvarray4[0] = &cgcd[i][0];
2620 subvarray4[1] = &subboxes[i][2];
2621 subvarray4[2] = NULL;
2622
2623 subboxes[i][3].gd.flags = gg_enabled|gg_visible;
2624 subboxes[i][3].gd.u.boxelements = subvarray4;
2625 subboxes[i][3].creator = GVBoxCreate;
2626 faspects[i].gcd = subboxes[i]+3;
2627 }
2628 }
2629 }
2630
2631 flabel[0].text = (unichar_t *) _("A coverage table:");
2632 flabel[0].text_is_1byte = true;
2633 fgcd[0].gd.label = &flabel[0];
2634 fgcd[0].gd.flags = gg_visible | gg_enabled;
2635 fgcd[0].creator = GLabelCreate;
2636 topvarray[0] = &fgcd[0];
2637
2638 fgcd[1].gd.u.tabs = faspects;
2639 fgcd[1].gd.flags = gg_visible | gg_enabled;
2640 fgcd[1].gd.cid = CID_MatchType+100;
2641 fgcd[1].creator = GTabSetCreate;
2642 topvarray[1] = &fgcd[1];
2643 topvarray[2] = NULL;
2644 topbox[0].gd.flags = gg_enabled|gg_visible;
2645 topbox[0].gd.u.boxelements = topvarray;
2646 topbox[0].creator = GVBoxCreate;
2647 GGadgetsCreate(ccd->coverage,topbox);
2648 for ( i=0; i<3; ++i ) {
2649 GMatrixEditSetUpDownVisible(GWidgetGetControl(ccd->coverage,CID_GList+100+i*20),
2650 true);
2651 GMatrixEditSetColumnCompletion(GWidgetGetControl(ccd->coverage,CID_GList+100+i*20),0,
2652 CCD_GlyphListCompletion);
2653 }
2654 if ( ccd->fpst->type!=pst_reversesub ) {
2655 GMatrixEditSetUpDownVisible(GWidgetGetControl(ccd->coverage,CID_LookupList+100+0),
2656 true);
2657 GHVBoxSetExpandableRow(subboxes[0][1].ret,1);
2658 } else {
2659 GHVBoxSetExpandableCol(subboxes[0][1].ret,gb_expandglue);
2660 GHVBoxSetExpandableRow(subboxes[0][2].ret,gb_expandglue);
2661 }
2662 GHVBoxSetExpandableRow(topbox[0].ret,1);
2663
2664 /* Pane showing the single rule in a coverage table (simple) */
2665 ccd->coverage_simple = GWidgetCreateSubWindow(ccd->gw,&subpos,subccd_e_h,ccd,&wattrs);
2666 memset(&clabel,0,sizeof(clabel));
2667 memset(&cgcd,0,sizeof(cgcd));
2668 memset(&subboxes,0,sizeof(subboxes));
2669 memset(&flabel,0,sizeof(flabel));
2670 memset(&fgcd,0,sizeof(fgcd));
2671 memset(&topbox,0,sizeof(topbox));
2672
2673 memset(&coveragesimple_mi,0,sizeof(coveragesimple_mi));
2674 coveragesimple_mi.col_cnt = 4;
2675 coveragesimple_mi.col_init = coveragesimple_ci;
2676 if ( fpst->format==pst_reversecoverage ) {
2677 coveragesimple_mi.col_cnt = 2;
2678 coveragesimple_mi.col_init = rcoveragesimple_ci;
2679 }
2680 if (( fpst->format==pst_coverage || fpst->format==pst_reversecoverage )
2681 && fpst->rules!=NULL ) {
2682 int cnt = fpst->rules[0].u.coverage.ncnt+fpst->rules[0].u.coverage.bcnt+fpst->rules[0].u.coverage.fcnt;
2683 coveragesimple_mi.initial_row_cnt = cnt;
2684 md = calloc(cnt*coveragesimple_mi.col_cnt,sizeof(struct matrix_data));
2685 for ( i=0,j=fpst->rules[0].u.coverage.bcnt-1; j>=0; --j, ++i )
2686 md[i*coveragesimple_mi.col_cnt].u.md_str = SFNameList2NameUni(sf,fpst->rules[0].u.coverage.bcovers[j]);
2687 for ( j=0; j<fpst->rules[0].u.coverage.ncnt; ++j, ++i ) {
2688 md[coveragesimple_mi.col_cnt*i+0].u.md_str = SFNameList2NameUni(sf,fpst->rules[0].u.coverage.ncovers[j]);
2689 if ( fpst->format==pst_reversecoverage )
2690 md[i*2+1].u.md_str = SFNameList2NameUni(sf,fpst->rules[0].u.rcoverage.replacements);
2691 else {
2692 md[4*i+2].u.md_ival = j==0;
2693 for ( k=0; k<fpst->rules[0].lookup_cnt; ++k ) {
2694 if ( fpst->rules[0].lookups[k].seq==j ) {
2695 md[4*i+1].u.md_addr = md[4*i+3].u.md_addr = fpst->rules[0].lookups[k].lookup;
2696 break;
2697 }
2698 }
2699 }
2700 }
2701 for ( j=0; j<fpst->rules[0].u.coverage.fcnt; ++j, ++i ) {
2702 md[coveragesimple_mi.col_cnt*i].u.md_str = SFNameList2NameUni(sf,fpst->rules[0].u.coverage.fcovers[j]);
2703 if ( fpst->format==pst_coverage )
2704 md[4*i+2].u.md_ival = j==0;
2705 }
2706 coveragesimple_mi.matrix_data = md;
2707 } else {
2708 coveragesimple_mi.initial_row_cnt = 0;
2709 coveragesimple_mi.matrix_data = NULL;
2710 }
2711 coveragesimple_mi.finishedit = CCD_FinishCoverageSimpleEdit;
2712
2713 flabel[0].text = (unichar_t *) _("A list of coverage tables:");
2714 flabel[0].text_is_1byte = true;
2715 fgcd[0].gd.label = &flabel[0];
2716 fgcd[0].gd.flags = gg_visible | gg_enabled;
2717 fgcd[0].creator = GLabelCreate;
2718 topvarray[0] = &fgcd[0];
2719
2720 fgcd[1].gd.flags = gg_visible | gg_enabled;
2721 fgcd[1].gd.cid = CID_Covers;
2722 fgcd[1].gd.u.matrix = &coveragesimple_mi;
2723 fgcd[1].creator = GMatrixEditCreate;
2724 topvarray[1] = &fgcd[1];
2725 topvarray[2] = NULL;
2726 topbox[0].gd.flags = gg_enabled|gg_visible;
2727 topbox[0].gd.u.boxelements = topvarray;
2728 topbox[0].creator = GVBoxCreate;
2729 GGadgetsCreate(ccd->coverage_simple,topbox);
2730 GMatrixEditSetUpDownVisible(GWidgetGetControl(ccd->coverage_simple,CID_Covers),
2731 true);
2732 GMatrixEditSetColumnCompletion(GWidgetGetControl(ccd->coverage_simple,CID_Covers),0,
2733 CCD_GlyphListCompletion);
2734 if ( fpst->type==pst_reversesub ) {
2735 GMatrixEditSetColumnCompletion(GWidgetGetControl(ccd->coverage_simple,CID_Covers),1,
2736 CCD_GlyphListCompletion);
2737 }
2738 GHVBoxSetExpandableRow(topbox[0].ret,1);
2739 if ( fpst->type == pst_contextpos || fpst->type == pst_contextsub )
2740 GMatrixEditShowColumn(GWidgetGetControl(ccd->coverage_simple,CID_Covers),2,false);
2741 if ( fpst->format!=pst_reversecoverage )
2742 GMatrixEditShowColumn(GWidgetGetControl(ccd->coverage_simple,CID_Covers),3,false);
2743
2744
2745 /* This pane displays a set of class rules, and below the three sets of classes for those rules */
2746 ccd->classrules = GWidgetCreateSubWindow(ccd->gw,&subpos,subccd_e_h,ccd,&wattrs);
2747 memset(&cllabel,0,sizeof(cllabel));
2748 memset(&clgcd,0,sizeof(clgcd));
2749 memset(&clabel,0,sizeof(clabel));
2750 memset(&cgcd,0,sizeof(cgcd));
2751 memset(&subboxes,0,sizeof(subboxes));
2752 memset(&topbox,0,sizeof(topbox));
2753 memset(&classbox,0,sizeof(classbox));
2754
2755 tempfpst = fpst;
2756 if ( fpst->format==pst_glyphs && fpst->rule_cnt>0 )
2757 tempfpst = FPSTGlyphToClass(fpst);
2758
2759 k=0;
2760
2761 memset(&classrules_mi,0,sizeof(classrules_mi));
2762 classrules_mi.col_cnt = 1;
2763 classrules_mi.col_init = classrules_ci;
2764 /* Further inits happen after we've set up the classnames */
2765 clgcd[k].gd.flags = gg_visible | gg_enabled;
2766 clgcd[k].gd.cid = CID_GList+200;
2767 clgcd[k].gd.u.matrix = &classrules_mi;
2768 clgcd[k++].creator = GMatrixEditCreate;
2769 classv[k-1] = &clgcd[k-1];
2770
2771 clgcd[k].gd.pos.width = CCD_WIDTH-23;
2772 clgcd[k].gd.flags = gg_visible | gg_enabled;
2773 clgcd[k++].creator = GLineCreate;
2774 classv[k-1] = &clgcd[k-1];
2775 classv[k] = NULL;
2776
2777 classbox[0].gd.flags = gg_enabled|gg_visible;
2778 classbox[0].gd.u.boxelements = classv;
2779 classbox[0].creator = GVBoxCreate;
2780 topvarray[0] = &classbox[0];
2781
2782 for ( i=0; i<3; ++i ) {
2783 int l=0, cc, j, sameas=0;
2784
2785 if ( i!=0 ) {
2786 if ( (&tempfpst->nccnt)[i] == tempfpst->nccnt ) {
2787 sameas = gg_cb_on;
2788 for ( j=1; j<(&tempfpst->nccnt)[i]; ++j ) {
2789 if ( strcmp((&tempfpst->nclass)[i][j],tempfpst->nclass[j])!=0 ) {
2790 sameas = 0;
2791 break;
2792 }
2793 }
2794 }
2795 clabel[i][l].text = (unichar_t *) _("Same as Match Classes");
2796 clabel[i][l].text_is_1byte = true;
2797 cgcd[i][l].gd.label = &clabel[i][l];
2798 cgcd[i][l].gd.handle_controlevent = CCD_SameAsClasses;
2799 cgcd[i][l].gd.flags = gg_visible | gg_enabled | sameas;
2800 cgcd[i][l].gd.cid = CID_SameAsClasses + i*20;
2801 cgcd[i][l++].creator = GCheckBoxCreate;
2802 subvarray[i][l-1] = &cgcd[i][l-1];
2803 }
2804
2805 memset(&class_mi[i],0,sizeof(class_mi[0]));
2806 class_mi[i].col_cnt = 3;
2807 class_mi[i].col_init = class_ci;
2808 {
2809 char **classes, **classnames;
2810 if ( tempfpst->format==pst_class ) {
2811 classes = (&tempfpst->nclass)[i];
2812 classnames = (&tempfpst->nclassnames)[i];
2813 } else {
2814 classes = NULL;
2815 classnames = NULL;
2816 }
2817 if ( classes==NULL )
2818 /* Make sure the class 0 is always present */
2819 cc=1;
2820 else
2821 cc = (&tempfpst->nccnt)[i];
2822 class_mi[i].initial_row_cnt = cc;
2823 md = calloc(3*cc+3,sizeof(struct matrix_data));
2824 md[0+0].u.md_str = copy(classnames==NULL || cc==0 || classnames[0]==NULL?S_("Glyphs|All_Others"):classnames[0]);
2825 md[3*0+1].u.md_str = copy(_("{Everything Else}"));
2826 md[3*0+1].frozen = true;
2827 md[0+2].u.md_str = copy(md[0+0].u.md_str);
2828 for ( j=1; j<cc; ++j ) {
2829 if ( classnames==NULL || classnames[j]==NULL ) {
2830 char buffer[12];
2831 sprintf( buffer,"%d",j );
2832 md[3*j+0].u.md_str = copy(buffer);
2833 } else
2834 md[3*j+0].u.md_str = copy(classnames[j]);
2835 md[3*j+1].u.md_str = SFNameList2NameUni(sf,classes[j]);
2836 md[3*j+2].u.md_str = copy(md[3*j+0].u.md_str);
2837 }
2838 class_mi[i].matrix_data = md;
2839
2840 clen[i] = cc;
2841 _classes[i] = md;
2842 }
2843 class_mi[i].initrow = CCD_InitClassRow;
2844 class_mi[i].finishedit = CCD_FinishClassEdit;
2845 class_mi[i].candelete = CCD_EnableDeleteClass;
2846
2847 if ( sameas )
2848 cgcd[i][l].gd.flags = gg_visible;
2849 else
2850 cgcd[i][l].gd.flags = gg_visible | gg_enabled;
2851 cgcd[i][l].gd.cid = CID_GList+300+i*20;
2852 cgcd[i][l].gd.u.matrix = &class_mi[i];
2853 cgcd[i][l++].creator = GMatrixEditCreate;
2854 subvarray[i][l-1] = &cgcd[i][l-1];
2855 subvarray[i][l] = NULL;
2856
2857 subboxes[i][0].gd.flags = gg_enabled|gg_visible;
2858 subboxes[i][0].gd.u.boxelements = subvarray[i];
2859 subboxes[i][0].creator = GVBoxCreate;
2860
2861 faspects[i].gcd = subboxes[i];
2862 }
2863 j=0;
2864 faspects[j++].text = (unichar_t *) _("Match Classes");
2865 faspects[j++].text = (unichar_t *) _("Back Classes");
2866 faspects[j++].text = (unichar_t *) _("Ahead Classes");
2867
2868 /* Finish initializing the list of class rules */
2869 if ( tempfpst->format==pst_class && tempfpst->rule_cnt>0 ) {
2870 classrules_mi.initial_row_cnt = tempfpst->rule_cnt;
2871 md = calloc(tempfpst->rule_cnt,sizeof(struct matrix_data));
2872 for ( j=0; j<tempfpst->rule_cnt; ++j ) {
2873 md[j+0].u.md_str = classruleitem(&tempfpst->rules[j],_classes,clen,3);
2874 }
2875 classrules_mi.matrix_data = md;
2876 } else {
2877 classrules_mi.initial_row_cnt = 0;
2878 classrules_mi.matrix_data = NULL;
2879 }
2880
2881 clgcd[k].gd.u.tabs = faspects;
2882 clgcd[k].gd.flags = gg_visible | gg_enabled;
2883 clgcd[k].gd.cid = CID_MatchType+300;
2884 clgcd[k].creator = GTabSetCreate;
2885 topvarray[1] = &clgcd[k]; topvarray[2] = NULL;
2886 topbox[0].gd.flags = gg_enabled|gg_visible;
2887 topbox[0].gd.u.boxelements = topvarray;
2888 topbox[0].creator = GVBoxCreate;
2889 GGadgetsCreate(ccd->classrules,topbox);
2890
2891 /* Top box should give it's size equally to its two components */
2892 GHVBoxSetExpandableRow(classbox[0].ret,0);
2893 GHVBoxSetExpandableRow(subboxes[0][0].ret,0);
2894 GHVBoxSetExpandableRow(subboxes[1][0].ret,1);
2895 GHVBoxSetExpandableRow(subboxes[2][0].ret,1);
2896 GMatrixEditSetColumnCompletion(GWidgetGetControl(ccd->classrules,CID_GList+300+0*20),0,CCD_GlyphListCompletion);
2897 GMatrixEditSetColumnCompletion(GWidgetGetControl(ccd->classrules,CID_GList+300+1*20),0,CCD_GlyphListCompletion);
2898 GMatrixEditSetColumnCompletion(GWidgetGetControl(ccd->classrules,CID_GList+300+2*20),0,CCD_GlyphListCompletion);
2899 GMatrixEditSetUpDownVisible(GWidgetGetControl(ccd->classrules,CID_GList+200), true);
2900 GMatrixEditSetOtherButtonEnable(GWidgetGetControl(ccd->classrules,CID_GList+200),CCD_NewClassRule);
2901 for ( i=0; i<3; ++i ) {
2902 GGadget *list = GWidgetGetControl(ccd->classrules,CID_GList+300+i*20);
2903 GMatrixEditShowColumn(list,2,false);
2904 GMatrixEditSetUpDownVisible(list, true);
2905 GMatrixEditSetCanUpDown(list, CCD_EnableUpDown);
2906 }
2907
2908 /* This pane displays a set of class rules, and below the three sets of classes_simple for those rules */
2909 ccd->classes_simple = GWidgetCreateSubWindow(ccd->gw,&subpos,subccd_e_h,ccd,&wattrs);
2910 memset(&cllabel,0,sizeof(cllabel));
2911 memset(&clgcd,0,sizeof(clgcd));
2912 memset(&clabel,0,sizeof(clabel));
2913 memset(&cgcd,0,sizeof(cgcd));
2914 memset(&subboxes,0,sizeof(subboxes));
2915 memset(&topbox,0,sizeof(topbox));
2916 memset(&classbox,0,sizeof(classbox));
2917 memset(&faspects,0,sizeof(faspects));
2918
2919 tempfpst = fpst;
2920 if ( fpst->format==pst_glyphs && fpst->rule_cnt>0 )
2921 tempfpst = FPSTGlyphToClass(fpst);
2922
2923 k=0;
2924
2925 memset(&classsimple_mi,0,sizeof(classsimple_mi));
2926 classsimple_mi.col_cnt = 1;
2927 classsimple_mi.col_init = classsimple_ci;
2928 if ( tempfpst->format==pst_class && tempfpst->rule_cnt>0 ) {
2929 classsimple_mi.initial_row_cnt = tempfpst->rule_cnt;
2930 md = calloc(tempfpst->rule_cnt,sizeof(struct matrix_data));
2931 for ( j=0; j<tempfpst->rule_cnt; ++j ) {
2932 md[j+0].u.md_str = FPSTRule_To_Str(sf,tempfpst,&tempfpst->rules[j]);
2933 }
2934 classsimple_mi.matrix_data = md;
2935 } else {
2936 classsimple_mi.initial_row_cnt = 0;
2937 classsimple_mi.matrix_data = NULL;
2938 }
2939 clgcd[k].gd.flags = gg_visible | gg_enabled;
2940 clgcd[k].gd.cid = CID_CList_Simple;
2941 clgcd[k].gd.u.matrix = &classsimple_mi;
2942 clgcd[k++].creator = GMatrixEditCreate;
2943 classv[k-1] = &clgcd[k-1];
2944
2945 clgcd[k].gd.pos.width = CCD_WIDTH-23;
2946 clgcd[k].gd.flags = gg_visible | gg_enabled;
2947 clgcd[k++].creator = GLineCreate;
2948 classv[k-1] = &clgcd[k-1];
2949 classv[k] = NULL;
2950
2951 classbox[0].gd.flags = gg_enabled|gg_visible;
2952 classbox[0].gd.u.boxelements = classv;
2953 classbox[0].creator = GVBoxCreate;
2954 topvarray[0] = &classbox[0];
2955
2956 for ( i=0; i<3; ++i ) {
2957 int l=0, cc, j, sameas=0;
2958
2959 if ( i!=0 ) {
2960 if ( (&tempfpst->nccnt)[i] == tempfpst->nccnt ) {
2961 sameas = gg_cb_on;
2962 for ( j=1; j<(&tempfpst->nccnt)[i]; ++j ) {
2963 if ( strcmp((&tempfpst->nclass)[i][j],tempfpst->nclass[j])!=0 ) {
2964 sameas = 0;
2965 break;
2966 }
2967 }
2968 }
2969 clabel[i][l].text = (unichar_t *) _("Same as Match Classes");
2970 clabel[i][l].text_is_1byte = true;
2971 cgcd[i][l].gd.label = &clabel[i][l];
2972 cgcd[i][l].gd.handle_controlevent = CCD_SameAsClasses;
2973 cgcd[i][l].gd.flags = gg_visible | gg_enabled | sameas;
2974 cgcd[i][l].gd.cid = CID_SameAsClasses_S + i*20;
2975 cgcd[i][l++].creator = GCheckBoxCreate;
2976 subvarray[i][l-1] = &cgcd[i][l-1];
2977 }
2978
2979 memset(&class_mi[i],0,sizeof(class_mi[0]));
2980 class_mi[i].col_cnt = 3;
2981 class_mi[i].col_init = class_ci;
2982 {
2983 char **classes, **classnames;
2984 if ( tempfpst->format==pst_class ) {
2985 classes = (&tempfpst->nclass)[i];
2986 classnames = (&tempfpst->nclassnames)[i];
2987 } else {
2988 classes = NULL;
2989 classnames = NULL;
2990 }
2991 if ( classes==NULL )
2992 /* Make sure the class 0 is always present */
2993 cc=1;
2994 else
2995 cc = (&tempfpst->nccnt)[i];
2996 class_mi[i].initial_row_cnt = cc;
2997 md = calloc(3*cc+3,sizeof(struct matrix_data));
2998 /* GT: This is the default class name for the class containing any glyphs_simple */
2999 /* GT: which aren't specified in other classes_simple. The class name may NOT */
3000 /* GT: contain spaces. Use an underscore or something similar instead */
3001 md[0+0].u.md_str = copy(classnames==NULL || cc==0 || classnames[0]==NULL?S_("Glyphs|All_Others"):classnames[0]);
3002 md[0+1].u.md_str = copy(_("{Everything Else}"));
3003 md[0+1].frozen = true;
3004 md[0+2].u.md_str = copy(md[0+0].u.md_str);
3005 for ( j=1; j<cc; ++j ) {
3006 if ( classnames==NULL || classnames[j]==NULL ) {
3007 char buffer[12];
3008 sprintf( buffer,"%d",j );
3009 md[3*j+0].u.md_str = copy(buffer);
3010 } else
3011 md[3*j+0].u.md_str = copy(classnames[j]);
3012 md[3*j+1].u.md_str = SFNameList2NameUni(sf,classes[j]);
3013 md[3*j+2].u.md_str = copy(md[3*j+0].u.md_str);
3014 }
3015 class_mi[i].matrix_data = md;
3016 }
3017 class_mi[i].initrow = CCD_InitClassRow;
3018 class_mi[i].finishedit = CCD_FinishClassEdit;
3019 class_mi[i].candelete = CCD_EnableDeleteClass;
3020
3021 if ( sameas )
3022 cgcd[i][l].gd.flags = gg_visible;
3023 else
3024 cgcd[i][l].gd.flags = gg_visible | gg_enabled;
3025 cgcd[i][l].gd.cid = CID_MatchClasses+i*20;
3026 cgcd[i][l].gd.u.matrix = &class_mi[i];
3027 cgcd[i][l++].creator = GMatrixEditCreate;
3028 subvarray[i][l-1] = &cgcd[i][l-1];
3029 subvarray[i][l] = NULL;
3030
3031 subboxes[i][0].gd.flags = gg_enabled|gg_visible;
3032 subboxes[i][0].gd.u.boxelements = subvarray[i];
3033 subboxes[i][0].creator = GVBoxCreate;
3034
3035 faspects[i].gcd = subboxes[i];
3036 faspects[i].text_is_1byte = true;
3037 }
3038 j=0;
3039 faspects[j++].text = (unichar_t *) _("Match Classes");
3040 faspects[j++].text = (unichar_t *) _("Back Classes");
3041 faspects[j++].text = (unichar_t *) _("Ahead Classes");
3042 if ( fpst->type == pst_contextpos || fpst->type == pst_contextsub )
3043 faspects[1].disabled = faspects[2].disabled = true;
3044
3045 clgcd[k].gd.u.tabs = faspects;
3046 clgcd[k].gd.flags = gg_visible | gg_enabled;
3047 clgcd[k].gd.cid = CID_ClassMatchType;
3048 clgcd[k].creator = GTabSetCreate;
3049 topvarray[1] = &clgcd[k]; topvarray[2] = NULL;
3050 topbox[0].gd.flags = gg_enabled|gg_visible;
3051 topbox[0].gd.u.boxelements = topvarray;
3052 topbox[0].creator = GVBoxCreate;
3053 GGadgetsCreate(ccd->classes_simple,topbox);
3054
3055 /* Top box should give it's size equally to its two components */
3056 GHVBoxSetExpandableRow(classbox[0].ret,0);
3057 GHVBoxSetExpandableRow(subboxes[0][0].ret,0);
3058 GHVBoxSetExpandableRow(subboxes[1][0].ret,1);
3059 GHVBoxSetExpandableRow(subboxes[2][0].ret,1);
3060 GMatrixEditSetColumnCompletion(GWidgetGetControl(ccd->classes_simple,CID_MatchClasses),1,CCD_GlyphListCompletion);
3061 GMatrixEditSetColumnCompletion(GWidgetGetControl(ccd->classes_simple,CID_BackClasses),1,CCD_GlyphListCompletion);
3062 GMatrixEditSetColumnCompletion(GWidgetGetControl(ccd->classes_simple,CID_ForeClasses),1,CCD_GlyphListCompletion);
3063 GMatrixEditSetColumnCompletion(GWidgetGetControl(ccd->classes_simple,CID_CList_Simple),0,
3064 CCD_ClassListCompletion);
3065 if ( fpst->type==pst_chainpos || fpst->type==pst_chainsub ) {
3066 extrabuttonsgcd[0].gd.cid = CID_CNewSection;
3067 extrabuttonsgcd[1].gd.cid = CID_CAddLookup;
3068 } else
3069 extrabuttonsgcd[0].gd.cid = CID_CAddLookup;
3070 GMatrixEditSetUpDownVisible(GWidgetGetControl(ccd->classes_simple,CID_CList_Simple), true);
3071 GMatrixEditAddButtons(GWidgetGetControl(ccd->classes_simple,CID_CList_Simple),extrabuttonsgcd);
3072 for ( i=0; i<3; ++i ) {
3073 GGadget *list = GWidgetGetControl(ccd->classes_simple,CID_MatchClasses+i*20);
3074 GMatrixEditShowColumn(list,2,false);
3075 GMatrixEditSetUpDownVisible(list, true);
3076 GMatrixEditSetCanUpDown(list, CCD_EnableUpDown);
3077 GMatrixEditSetBeforeDelete(list,CCD_ClassGoing);
3078 }
3079 if ( tempfpst!=fpst )
3080 FPSTFree(tempfpst);
3081
3082 /* This pane displays a tabbed set describing one rule in class format */
3083 ccd->classnumber = GWidgetCreateSubWindow(ccd->gw,&subpos,subccd_e_h,ccd,&wattrs);
3084 memset(&clabel,0,sizeof(clabel));
3085 memset(&cgcd,0,sizeof(cgcd));
3086 memset(&cllabel,0,sizeof(cllabel));
3087 memset(&clgcd,0,sizeof(clgcd));
3088
3089 for ( i=0; i<3; ++i ) {
3090 k=0;
3091
3092 clabel[i][k].text = (unichar_t *) _("List of class names");
3093 clabel[i][k].text_is_1byte = true;
3094 cgcd[i][k].gd.label = &clabel[i][k];
3095 cgcd[i][k].gd.flags = gg_visible | gg_enabled;
3096 cgcd[i][k++].creator = GLabelCreate;
3097 subvarray[i][k-1] = &cgcd[i][k-1];
3098
3099 cgcd[i][k].gd.flags = gg_visible | gg_enabled | gg_textarea_wrap;
3100 cgcd[i][k].gd.cid = CID_ClassNumbers+i*20;
3101 cgcd[i][k++].creator = GTextAreaCreate;
3102 subvarray[i][k-1] = &cgcd[i][k-1];
3103
3104 clabel[i][k].text = (unichar_t *) _("Classes");
3105 clabel[i][k].text_is_1byte = true;
3106 cgcd[i][k].gd.label = &clabel[i][k];
3107 cgcd[i][k].gd.flags = gg_visible | gg_enabled;
3108 cgcd[i][k++].creator = GLabelCreate;
3109 subvarray[i][k-1] = &cgcd[i][k-1];
3110
3111 memset(&classlist_mi[i],0,sizeof(classlist_mi[0]));
3112 classlist_mi[i].col_cnt = 2;
3113 classlist_mi[i].col_init = classlist_ci;
3114
3115 cgcd[i][k].gd.flags = gg_visible | gg_enabled | gg_textarea_wrap;
3116 cgcd[i][k].gd.cid = CID_ClassList+i*20;
3117 cgcd[i][k].gd.u.matrix = &classlist_mi[i];
3118 cgcd[i][k++].creator = GMatrixEditCreate;
3119 subvarray[i][k-1] = &cgcd[i][k-1];
3120 subvarray[i][k] = NULL;
3121
3122 subboxes[i][0].gd.flags = gg_enabled|gg_visible;
3123 subboxes[i][0].gd.u.boxelements = subvarray[i];
3124 subboxes[i][0].creator = GVBoxCreate;
3125
3126 faspects[i].gcd = subboxes[i];
3127
3128 if ( i==0 ) {
3129 clabel[i][k].text = (unichar_t *) _("An ordered list of lookups and positions");
3130 clabel[i][k].text_is_1byte = true;
3131 ggcd[i][k].gd.label = &clabel[i][k];
3132 ggcd[i][k].gd.flags = gg_visible | gg_enabled;
3133 ggcd[i][k++].creator = GLabelCreate;
3134 subvarray2[0] = &ggcd[i][k-1];
3135
3136 memset(&cl_seqlookup_mi,0,sizeof(cl_seqlookup_mi));
3137 cl_seqlookup_mi.col_cnt = 2;
3138 cl_seqlookup_mi.col_init = seqlookup_ci;
3139 cl_seqlookup_mi.matrix_data = NULL;
3140 cl_seqlookup_mi.initial_row_cnt = 0;
3141
3142 ggcd[i][k].gd.flags = gg_visible | gg_enabled;
3143 ggcd[i][k].gd.cid = CID_LookupList+500;
3144 ggcd[i][k].gd.u.matrix = &cl_seqlookup_mi;
3145 ggcd[i][k++].creator = GMatrixEditCreate;
3146 subvarray2[1] = &ggcd[i][k-1];
3147 subvarray2[2] = NULL;
3148
3149 subboxes[i][1].gd.flags = gg_enabled|gg_visible;
3150 subboxes[i][1].gd.u.boxelements = subvarray2;
3151 subboxes[i][1].creator = GVBoxCreate;
3152
3153 subvarray3[0] = &subboxes[i][0];
3154 subvarray3[1] = &subboxes[i][1];
3155 subvarray3[2] = NULL;
3156
3157 subboxes[i][2].gd.flags = gg_enabled|gg_visible;
3158 subboxes[i][2].gd.u.boxelements = subvarray3;
3159 subboxes[i][2].creator = GVBoxCreate;
3160 faspects[i].gcd = subboxes[i]+2;
3161 }
3162 }
3163
3164 j=0;
3165 faspects[j++].text = (unichar_t *) _("Match");
3166 faspects[j++].text = (unichar_t *) _("Backtrack");
3167 faspects[j++].text = (unichar_t *) _("Lookahead");
3168
3169 k=0;
3170 clgcd[k].gd.u.tabs = faspects;
3171 clgcd[k].gd.flags = gg_visible | gg_enabled;
3172 clgcd[k].gd.cid = CID_ClassType;
3173 clgcd[k].creator = GTabSetCreate;
3174 GGadgetsCreate(ccd->classnumber,clgcd);
3175 GHVBoxSetExpandableRow(subboxes[0][0].ret,3);
3176 GHVBoxSetExpandableRow(subboxes[1][0].ret,3);
3177 GHVBoxSetExpandableRow(subboxes[2][0].ret,3);
3178 GHVBoxSetExpandableRow(subboxes[0][1].ret,1);
3179
3180 GMatrixEditSetEditable(GWidgetGetControl(ccd->classnumber,CID_ClassList+0*20),false);
3181 GMatrixEditSetEditable(GWidgetGetControl(ccd->classnumber,CID_ClassList+1*20),false);
3182 GMatrixEditSetEditable(GWidgetGetControl(ccd->classnumber,CID_ClassList+2*20),false);
3183 GMatrixEditSetOtherButtonEnable(GWidgetGetControl(ccd->classnumber,CID_ClassList+0*20),CCD_ClassSelected);
3184 GMatrixEditSetOtherButtonEnable(GWidgetGetControl(ccd->classnumber,CID_ClassList+1*20),CCD_ClassSelected);
3185 GMatrixEditSetOtherButtonEnable(GWidgetGetControl(ccd->classnumber,CID_ClassList+2*20),CCD_ClassSelected);
3186
3187
3188 if ( ccd->aw == aw_formats )
3189 GDrawSetVisible(ccd->formats,true);
3190 else if ( use_simple ) {
3191 if ( ccd->aw == aw_glyphs_simple )
3192 GDrawSetVisible(ccd->glyphs_simple,true);
3193 else if ( ccd->aw == aw_classes_simple )
3194 GDrawSetVisible(ccd->classes_simple,true);
3195 else {
3196 GDrawSetVisible(ccd->coverage_simple,true);
3197 GDrawResize(ccd->gw,
3198 fpst->format==pst_reversecoverage?3*pos.width/2:2*pos.width,
3199 pos.height);
3200 }
3201 } else {
3202 if ( ccd->aw == aw_grules )
3203 GDrawSetVisible(ccd->grules,true);
3204 else if ( ccd->aw == aw_classrules )
3205 GDrawSetVisible(ccd->classrules,true);
3206 else
3207 GDrawSetVisible(ccd->coverage,true);
3208 }
3209
3210 GDrawSetVisible(gw,true);
3211 while ( !ccd->done )
3212 GDrawProcessOneEvent(NULL);
3213 GDrawDestroyWindow(ccd->gw);
3214
3215 GTextInfoListFree(lookup_list);
3216 seqlookup_ci[1].enum_vals = NULL;
3217
3218 /* ccd is freed by the event handler when we get a et_destroy event */
3219
3220 return;
3221 }