Debian Codegraph @

fontforgeexe/charinfo.c

raw symbols SCIP
1 /* -*- coding: utf-8 -*- */
2 /* Copyright (C) 2000-2012 by George Williams */
3 /*
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13
14 * The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <fontforge-config.h>
30
31 #include "autowidth2.h"
32 #include "cvundoes.h"
33 #include "fontforgeui.h"
34 #include "fvcomposite.h"
35 #include "fvfonts.h"
36 #include "gkeysym.h"
37 #include "gresedit.h"
38 #include "lookups.h"
39 #include "namelist.h"
40 #include "splinefill.h"
41 #include "splineutil.h"
42 #include "tottfgpos.h"
43 #include "ttf.h" /* For MAC_DELETED_GLYPH_NAME */
44 #include "ustring.h"
45 #include "utype.h"
46
47 #include <math.h>
48
49 extern int lookup_hideunused;
50
51 GResFont glyphinfo_font = GRESFONT_INIT("400 12pt " MONO_UI_FAMILIES);
52
53 static int last_gi_aspect = 0;
54
55 typedef struct charinfo {
56 CharView *cv;
57 EncMap *map;
58 SplineChar *sc, *cachedsc;
59 int def_layer;
60 SplineChar *oldsc; /* oldsc->charinfo will point to us. Used to keep track of that pointer */
61 int enc;
62 GWindow gw;
63 int done, first, changed;
64 struct lookup_subtable *old_sub;
65 int r,c;
66 int lc_seen, lc_aspect, vert_aspect;
67 Color last, real_last;
68 struct splinecharlist *changes;
69 int name_change, uni_change;
70 } CharInfo;
71
72 #define CI_Width 218
73 #define CI_Height 292
74
75 #define CID_UName 1001
76 #define CID_UValue 1002
77 #define CID_UChar 1003
78 #define CID_Cancel 1005
79 #define CID_ComponentMsg 1006
80 #define CID_Components 1007
81 #define CID_ComponentTextField 1008
82 #define CID_ComponentChangeMsg 1009
83 #define CID_ComponentDefaultCB 1010
84 #define CID_ComponentInterpMsg 1011
85 #define CID_Comment 1012
86 #define CID_Color 1013
87 #define CID_GClass 1014
88 #define CID_Tabs 1015
89
90 #define CID_TeX_Height 1016
91 #define CID_TeX_Depth 1017
92 #define CID_TeX_Italic 1018
93 #define CID_HorAccent 1019
94 /* Room for one more here, if we need it */
95 #define CID_TeX_HeightD 1020
96 #define CID_TeX_DepthD 1021
97 #define CID_TeX_ItalicD 1022
98 #define CID_HorAccentD 1023
99
100 #define CID_ItalicDevTab 1024
101 #define CID_AccentDevTab 1025
102
103 #define CID_IsExtended 1026
104 #define CID_DefLCCount 1040
105 #define CID_LCCount 1041
106 #define CID_LCCountLab 1042
107
108 #define CID_UnlinkRmOverlap 1045
109 #define CID_AltUni 1046
110
111 /* Offsets for repeated fields. add 100*index (index<=6) */
112 #define CID_List 1220
113 #define CID_New 1221
114 #define CID_Delete 1222
115 #define CID_Edit 1223
116
117 #define CID_PST 1111
118 #define CID_Tag 1112
119 #define CID_Contents 1113
120 #define CID_SelectResults 1114
121 #define CID_MergeResults 1115
122 #define CID_RestrictSelection 1116
123
124 /* Offsets for repeated fields. add 100*index (index<2) */ /* 0=>Vert, 1=>Hor */
125 #define CID_VariantList 2000
126 #define CID_ExtItalicCor 2001
127 #define CID_ExtItalicDev 2002
128 #define CID_ExtensionList 2003
129
130 #define CID_IsTileMargin 3001
131 #define CID_TileMargin 3002
132 #define CID_IsTileBBox 3003
133 #define CID_TileBBoxMinX 3004
134 #define CID_TileBBoxMinY 3005
135 #define CID_TileBBoxMaxX 3006
136 #define CID_TileBBoxMaxY 3007
137
138 #define SIM_DX 1
139 #define SIM_DY 3
140 #define SIM_DX_ADV 5
141 #define SIM_DY_ADV 7
142 #define PAIR_DX1 2
143 #define PAIR_DY1 4
144 #define PAIR_DX_ADV1 6
145 #define PAIR_DY_ADV1 8
146 #define PAIR_DX2 10
147 #define PAIR_DY2 12
148 #define PAIR_DX_ADV2 14
149 #define PAIR_DY_ADV2 16
150
151 static GTextInfo glyphclasses[] = {
152 { (unichar_t *) N_("Automatic"), NULL, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
153 { (unichar_t *) N_("No Class"), NULL, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
154 { (unichar_t *) N_("Base Glyph"), NULL, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
155 { (unichar_t *) N_("Base Lig"), NULL, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
156 { (unichar_t *) N_("Mark"), NULL, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
157 { (unichar_t *) N_("Component"), NULL, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
158 GTEXTINFO_EMPTY
159 };
160
161 #define CUSTOM_COLOR 9
162 #define COLOR_CHOOSE (-10)
163 static GTextInfo std_colors[] = {
164 { (unichar_t *) N_("Color|Choose..."), NULL, 0, 0, (void *) COLOR_CHOOSE, NULL, 0, 1, 0, 0, 0, 0, 1, 0, 0, '\0' },
165 { (unichar_t *) N_("Color|Default"), &def_image, 0, 0, (void *) COLOR_DEFAULT, NULL, 0, 1, 0, 0, 0, 0, 1, 0, 0, '\0' },
166 { NULL, &white_image, 0, 0, (void *) 0xffffff, NULL, 0, 1, 0, 0, 0, 0, 0, 0, 0, '\0' },
167 { NULL, &red_image, 0, 0, (void *) 0xff0000, NULL, 0, 1, 0, 0, 0, 0, 0, 0, 0, '\0' },
168 { NULL, &green_image, 0, 0, (void *) 0x00ff00, NULL, 0, 1, 0, 0, 0, 0, 0, 0, 0, '\0' },
169 { NULL, &blue_image, 0, 0, (void *) 0x0000ff, NULL, 0, 1, 0, 0, 0, 0, 0, 0, 0, '\0' },
170 { NULL, &yellow_image, 0, 0, (void *) 0xffff00, NULL, 0, 1, 0, 0, 0, 0, 0, 0, 0, '\0' },
171 { NULL, &cyan_image, 0, 0, (void *) 0x00ffff, NULL, 0, 1, 0, 0, 0, 0, 0, 0, 0, '\0' },
172 { NULL, &magenta_image, 0, 0, (void *) 0xff00ff, NULL, 0, 1, 0, 0, 0, 0, 0, 0, 0, '\0' },
173 { NULL, NULL, 0, 0, (void *) 0x000000, NULL, 0, 1, 0, 0, 0, 0, 0, 0, 0, '\0' },
174 GTEXTINFO_EMPTY
175 };
176
177 static char *newstrings[] = { N_("New Positioning"), N_("New Pair Position"),
178 N_("New Substitution Variant"),
179 N_("New Alternate List"), N_("New Multiple List"), N_("New Ligature"), NULL };
180
181 static unichar_t *CounterMaskLine(SplineChar *sc, HintMask *hm) {
182 unichar_t *textmask = NULL;
183 int j,k,len;
184 StemInfo *h;
185 char buffer[100];
186
187 for ( j=0; j<2; ++j ) {
188 len = 0;
189 for ( h=sc->hstem, k=0; h!=NULL && k<HntMax; h=h->next, ++k ) {
190 if ( (*hm)[k>>3]& (0x80>>(k&7)) ) {
191 sprintf( buffer, "H<%g,%g>, ",
192 rint(h->start*100)/100, rint(h->width*100)/100 );
193 if ( textmask!=NULL )
194 uc_strcpy(textmask+len,buffer);
195 len += strlen(buffer);
196 }
197 }
198 for ( h=sc->vstem; h!=NULL && k<HntMax; h=h->next, ++k ) {
199 if ( (*hm)[k>>3]& (0x80>>(k&7)) ) {
200 sprintf( buffer, "V<%g,%g>, ",
201 rint(h->start*100)/100, rint(h->width*100)/100 );
202 if ( textmask!=NULL )
203 uc_strcpy(textmask+len,buffer);
204 len += strlen(buffer);
205 }
206 }
207 if ( textmask==NULL ) {
208 textmask = malloc((len+1)*sizeof(unichar_t));
209 *textmask = '\0';
210 }
211 }
212 if ( len>1 && textmask[len-2]==',' )
213 textmask[len-2] = '\0';
214 return( textmask );
215 }
216
217 #define CID_HintMask 2020
218 #define HI_Width 200
219 #define HI_Height 260
220
221 struct hi_data {
222 int done, ok, empty;
223 GWindow gw;
224 HintMask *cur;
225 SplineChar *sc;
226 };
227
228 static int HI_Ok(GGadget *g, GEvent *e) {
229 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
230 struct hi_data *hi = GDrawGetUserData(GGadgetGetWindow(g));
231 int32_t i, len;
232 GTextInfo **ti = GGadgetGetList(GWidgetGetControl(hi->gw,CID_HintMask),&len);
233
234 for ( i=0; i<len; ++i )
235 if ( ti[i]->selected )
236 break;
237
238 memset(hi->cur,0,sizeof(HintMask));
239 if ( i==len ) {
240 hi->empty = true;
241 } else {
242 for ( i=0; i<len; ++i )
243 if ( ti[i]->selected )
244 (*hi->cur)[i>>3] |= (0x80>>(i&7));
245 }
246 PI_ShowHints(hi->sc,GWidgetGetControl(hi->gw,CID_HintMask),false);
247
248 hi->done = true;
249 hi->ok = true;
250 }
251 return( true );
252 }
253
254 static void HI_DoCancel(struct hi_data *hi) {
255 hi->done = true;
256 PI_ShowHints(hi->sc,GWidgetGetControl(hi->gw,CID_HintMask),false);
257 }
258
259 static int HI_HintSel(GGadget *g, GEvent *e) {
260 if ( e->type==et_controlevent && e->u.control.subtype == et_listselected ) {
261 struct hi_data *hi = GDrawGetUserData(GGadgetGetWindow(g));
262
263 PI_ShowHints(hi->sc,g,true);
264 /* Do I need to check for overlap here? */
265 }
266 return( true );
267 }
268
269 static int HI_Cancel(GGadget *g, GEvent *e) {
270 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
271 HI_DoCancel( GDrawGetUserData(GGadgetGetWindow(g)));
272 }
273 return( true );
274 }
275
276 static int hi_e_h(GWindow gw, GEvent *event) {
277 if ( event->type==et_close ) {
278 HI_DoCancel( GDrawGetUserData(gw));
279 } else if ( event->type==et_char ) {
280 if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) {
281 help("ui/dialogs/charinfo.html", "#charinfo-counters");
282 return( true );
283 }
284 return( false );
285 }
286 return( true );
287 }
288
289 static void CI_AskCounters(CharInfo *ci,HintMask *old) {
290 HintMask *cur = old != NULL ? old : chunkalloc(sizeof(HintMask));
291 struct hi_data hi;
292 GWindowAttrs wattrs;
293 GGadgetCreateData hgcd[5], *varray[11], *harray[8], boxes[3];
294 GTextInfo hlabel[5];
295 GGadget *list = GWidgetGetControl(ci->gw,CID_List+600);
296 int j,k;
297 GRect pos;
298
299 memset(&hi,0,sizeof(hi));
300 hi.cur = cur;
301 hi.sc = ci->sc;
302
303 memset(&wattrs,0,sizeof(wattrs));
304 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict;
305 wattrs.event_masks = ~(1<<et_charup);
306 wattrs.restrict_input_to_me = 1;
307 wattrs.undercursor = 1;
308 wattrs.cursor = ct_pointer;
309 wattrs.utf8_window_title = old==NULL?_("New Counter Mask"):_("Edit Counter Mask");
310 wattrs.is_dlg = true;
311 pos.width = GGadgetScale(GDrawPointsToPixels(NULL,HI_Width));
312 pos.height = GDrawPointsToPixels(NULL,HI_Height);
313 hi.gw = GDrawCreateTopWindow(NULL,&pos,hi_e_h,&hi,&wattrs);
314
315
316 memset(hgcd,0,sizeof(hgcd));
317 memset(boxes,0,sizeof(boxes));
318 memset(hlabel,0,sizeof(hlabel));
319
320 j=k=0;
321
322 hgcd[j].gd.pos.x = 20-3; hgcd[j].gd.pos.y = HI_Height-31-3;
323 hgcd[j].gd.pos.width = -1; hgcd[j].gd.pos.height = 0;
324 hgcd[j].gd.flags = gg_visible | gg_enabled;
325 hlabel[j].text = (unichar_t *) _("Select hints between which counters are formed");
326 hlabel[j].text_is_1byte = true;
327 hlabel[j].text_in_resource = true;
328 hgcd[j].gd.label = &hlabel[j];
329 varray[k++] = &hgcd[j]; varray[k++] = NULL;
330 hgcd[j++].creator = GLabelCreate;
331
332 hgcd[j].gd.pos.x = 5; hgcd[j].gd.pos.y = 5;
333 hgcd[j].gd.pos.width = HI_Width-10; hgcd[j].gd.pos.height = HI_Height-45;
334 hgcd[j].gd.flags = gg_visible | gg_enabled | gg_list_multiplesel;
335 hgcd[j].gd.cid = CID_HintMask;
336 hgcd[j].gd.u.list = SCHintList(ci->sc,old);
337 hgcd[j].gd.handle_controlevent = HI_HintSel;
338 varray[k++] = &hgcd[j]; varray[k++] = NULL;
339 varray[k++] = GCD_Glue; varray[k++] = NULL;
340 hgcd[j++].creator = GListCreate;
341
342 hgcd[j].gd.pos.x = 20-3; hgcd[j].gd.pos.y = HI_Height-31-3;
343 hgcd[j].gd.pos.width = -1; hgcd[j].gd.pos.height = 0;
344 hgcd[j].gd.flags = gg_visible | gg_enabled | gg_but_default;
345 hlabel[j].text = (unichar_t *) _("_OK");
346 hlabel[j].text_is_1byte = true;
347 hlabel[j].text_in_resource = true;
348 hgcd[j].gd.label = &hlabel[j];
349 hgcd[j].gd.handle_controlevent = HI_Ok;
350 harray[0] = GCD_Glue; harray[1] = &hgcd[j]; harray[2] = GCD_Glue; harray[3] = GCD_Glue;
351 hgcd[j++].creator = GButtonCreate;
352
353 hgcd[j].gd.pos.x = -20; hgcd[j].gd.pos.y = HI_Height-31;
354 hgcd[j].gd.pos.width = -1; hgcd[j].gd.pos.height = 0;
355 hgcd[j].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
356 hlabel[j].text = (unichar_t *) _("_Cancel");
357 hlabel[j].text_is_1byte = true;
358 hlabel[j].text_in_resource = true;
359 hgcd[j].gd.label = &hlabel[j];
360 hgcd[j].gd.handle_controlevent = HI_Cancel;
361 harray[4] = GCD_Glue; harray[5] = &hgcd[j]; harray[6] = GCD_Glue; harray[7] = NULL;
362 hgcd[j++].creator = GButtonCreate;
363
364 boxes[2].gd.flags = gg_enabled|gg_visible;
365 boxes[2].gd.u.boxelements = harray;
366 boxes[2].creator = GHBoxCreate;
367 varray[k++] = &boxes[2]; varray[k++] = NULL;
368 varray[k++] = GCD_Glue; varray[k++] = NULL;
369 varray[k] = NULL;
370
371 boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2;
372 boxes[0].gd.flags = gg_enabled|gg_visible;
373 boxes[0].gd.u.boxelements = varray;
374 boxes[0].creator = GHVGroupCreate;
375
376 GGadgetsCreate(hi.gw,boxes);
377 GHVBoxSetExpandableRow(boxes[0].ret,1);
378 GHVBoxSetExpandableCol(boxes[2].ret,gb_expandgluesame);
379 GHVBoxFitWindow(boxes[0].ret);
380 GTextInfoListFree(hgcd[0].gd.u.list);
381
382 PI_ShowHints(hi.sc,hgcd[0].ret,true);
383
384 GDrawSetVisible(hi.gw,true);
385 while ( !hi.done )
386 GDrawProcessOneEvent(NULL);
387 GDrawDestroyWindow(hi.gw);
388
389 if ( !hi.ok ) {
390 if ( old==NULL ) chunkfree(cur,sizeof(HintMask));
391 return; /* Cancelled */
392 } else if ( old==NULL && hi.empty ) {
393 if ( old==NULL ) chunkfree(cur,sizeof(HintMask));
394 return; /* Didn't add anything new */
395 } else if ( old==NULL ) {
396 GListAddStr(list,CounterMaskLine(hi.sc,cur),cur);
397 return;
398 } else if ( !hi.empty ) {
399 GListReplaceStr(list,GGadgetGetFirstListSelectedItem(list),
400 CounterMaskLine(hi.sc,cur),cur);
401 return;
402 } else {
403 GListDelSelected(list);
404 chunkfree(cur,sizeof(HintMask));
405 }
406 }
407
408 static int CI_NewCounter(GGadget *g, GEvent *e) {
409 CharInfo *ci;
410
411 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
412 ci = GDrawGetUserData(GGadgetGetWindow(g));
413 CI_AskCounters(ci,NULL);
414 }
415 return( true );
416 }
417
418 static int CI_EditCounter(GGadget *g, GEvent *e) {
419 GTextInfo *ti;
420 GGadget *list;
421 CharInfo *ci;
422
423 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
424 ci = GDrawGetUserData(GGadgetGetWindow(g));
425 list = GWidgetGetControl(GGadgetGetWindow(g),CID_List+6*100);
426 if ( (ti = GGadgetGetListItemSelected(list))==NULL )
427 return( true );
428 CI_AskCounters(ci,ti->userdata);
429 }
430 return( true );
431 }
432
433 static int CI_DeleteCounter(GGadget *g, GEvent *e) {
434 int32_t len; int i,j, offset;
435 GTextInfo **old, **new_;
436 GGadget *list;
437 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
438 offset = GGadgetGetCid(g)-CID_Delete;
439 list = GWidgetGetControl(GGadgetGetWindow(g),CID_List+offset);
440 old = GGadgetGetList(list,&len);
441 new_ = calloc(len+1,sizeof(GTextInfo *));
442 for ( i=j=0; i<len; ++i )
443 if ( !old[i]->selected ) {
444 new_[j] = (GTextInfo *) malloc(sizeof(GTextInfo));
445 *new_[j] = *old[i];
446 new_[j]->text = u_copy(new_[j]->text);
447 ++j;
448 }
449 new_[j] = (GTextInfo *) calloc(1,sizeof(GTextInfo));
450 if ( offset==600 ) {
451 for ( i=0; i<len; ++i ) if ( old[i]->selected )
452 chunkfree(old[i]->userdata,sizeof(HintMask));
453 }
454 GGadgetSetList(list,new_,false);
455 GGadgetSetEnabled(GWidgetGetControl(GGadgetGetWindow(g),CID_Delete+offset),false);
456 GGadgetSetEnabled(GWidgetGetControl(GGadgetGetWindow(g),CID_Edit+offset),false);
457 }
458 return( true );
459 }
460
461 static int CI_CounterSelChanged(GGadget *g, GEvent *e) {
462 if ( e->type==et_controlevent && e->u.control.subtype == et_listselected ) {
463 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
464 int sel = GGadgetGetFirstListSelectedItem(g);
465 int offset = GGadgetGetCid(g)-CID_List;
466 GGadgetSetEnabled(GWidgetGetControl(ci->gw,CID_Delete+offset),sel!=-1);
467 GGadgetSetEnabled(GWidgetGetControl(ci->gw,CID_Edit+offset),sel!=-1);
468 } else if ( e->type==et_controlevent && e->u.control.subtype == et_listdoubleclick ) {
469 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
470 int offset = GGadgetGetCid(g)-CID_List;
471 e->u.control.subtype = et_buttonactivate;
472 e->u.control.g = GWidgetGetControl(ci->gw,CID_Edit+offset);
473 CI_EditCounter(e->u.control.g,e);
474 }
475 return( true );
476 }
477
478 static int ParseUValue(GWindow gw, int cid, int minusoneok) {
479 const unichar_t *ret = _GGadgetGetTitle(GWidgetGetControl(gw,cid));
480 unichar_t *end;
481 int val;
482
483 if (( *ret=='U' || *ret=='u' ) && ret[1]=='+' )
484 val = u_strtoul(ret+2,&end,16);
485 else if ( *ret=='#' )
486 val = u_strtoul(ret+1,&end,16);
487 else
488 val = u_strtoul(ret,&end,16);
489 if ( val==-1 && minusoneok )
490 return( -1 );
491 if ( *end || val<0 || val>0x10ffff ) {
492 GGadgetProtest8( _("Unicode _Value:") );
493 return( -2 );
494 }
495 return( val );
496 }
497
498 static void SetNameFromUnicode(GWindow gw,int cid,int val) {
499 unichar_t *temp;
500 char buf[100];
501 CharInfo *ci = GDrawGetUserData(gw);
502
503 temp = utf82u_copy(StdGlyphName(buf,val,ci->sc->parent->uni_interp,ci->sc->parent->for_new_glyphs));
504 GGadgetSetTitle(GWidgetGetControl(gw,cid),temp);
505 free(temp);
506 }
507
508 void SCInsertPST(SplineChar *sc,PST *new_) {
509 new_->next = sc->possub;
510 sc->possub = new_;
511 }
512
513 static int CI_NameCheck(const unichar_t *name) {
514 bool questionable = false;
515 const char* error = SCNameCheck(name, &questionable);
516
517 if (error == NULL)
518 return true;
519
520 if (questionable) {
521 char *buts[3];
522 buts[0] = _("_Yes"); buts[1]=_("_No"); buts[2] = NULL;
523 return (gwwv_ask(_("Bad Name"),(const char **) buts,0,1,error) != 1);
524 }
525
526 ff_post_error(_("Bad Name"), error);
527 return false;
528 }
529
530 static void CI_ParseCounters(CharInfo *ci) {
531 int32_t i,len;
532 GTextInfo **ti = GGadgetGetList(GWidgetGetControl(ci->gw,CID_List+600),&len);
533 SplineChar *sc = ci->cachedsc;
534
535 free(sc->countermasks);
536
537 sc->countermask_cnt = len;
538 if ( len==0 )
539 sc->countermasks = NULL;
540 else {
541 sc->countermasks = malloc(len*sizeof(HintMask));
542 for ( i=0; i<len; ++i ) {
543 memcpy(sc->countermasks[i],ti[i]->userdata,sizeof(HintMask));
544 chunkfree(ti[i]->userdata,sizeof(HintMask));
545 ti[i]->userdata = NULL;
546 }
547 }
548 }
549
550 int DeviceTableOK(char *dvstr, int *_low, int *_high) {
551 char *pt, *end;
552 int low, high, pixel, cor;
553
554 low = high = -1;
555 if ( dvstr!=NULL ) {
556 while ( *dvstr==' ' ) ++dvstr;
557 for ( pt=dvstr; *pt; ) {
558 pixel = strtol(pt,&end,10);
559 if ( pixel<=0 || pt==end)
560 break;
561 pt = end;
562 if ( *pt==':' ) ++pt;
563 cor = strtol(pt,&end,10);
564 if ( pt==end || cor<-128 || cor>127 )
565 break;
566 pt = end;
567 while ( *pt==' ' ) ++pt;
568 if ( *pt==',' ) ++pt;
569 while ( *pt==' ' ) ++pt;
570 if ( low==-1 ) low = high = pixel;
571 else if ( pixel<low ) low = pixel;
572 else if ( pixel>high ) high = pixel;
573 }
574 if ( *pt != '\0' )
575 return( false );
576 }
577 *_low = low; *_high = high;
578 return( true );
579 }
580
581 DeviceTable *DeviceTableParse(DeviceTable *dv,char *dvstr) {
582 char *pt, *end;
583 int low, high, pixel, cor;
584
585 DeviceTableOK(dvstr,&low,&high);
586 if ( low==-1 ) {
587 if ( dv!=NULL ) {
588 free(dv->corrections);
589 memset(dv,0,sizeof(*dv));
590 }
591 return( dv );
592 }
593 if ( dv==NULL )
594 dv = chunkalloc(sizeof(DeviceTable));
595 else
596 free(dv->corrections);
597 dv->first_pixel_size = low;
598 dv->last_pixel_size = high;
599 dv->corrections = calloc(high-low+1,1);
600
601 for ( pt=dvstr; *pt; ) {
602 pixel = strtol(pt,&end,10);
603 if ( pixel<=0 || pt==end)
604 break;
605 pt = end;
606 if ( *pt==':' ) ++pt;
607 cor = strtol(pt,&end,10);
608 if ( pt==end || cor<-128 || cor>127 )
609 break;
610 pt = end;
611 while ( *pt==' ' ) ++pt;
612 if ( *pt==',' ) ++pt;
613 while ( *pt==' ' ) ++pt;
614 dv->corrections[pixel-low] = cor;
615 }
616 return( dv );
617 }
618
619 void VRDevTabParse(struct vr *vr,struct matrix_data *md) {
620 ValDevTab temp, *adjust;
621 int any = false;
622
623 if ( (adjust = vr->adjust)==NULL ) {
624 adjust = &temp;
625 memset(&temp,0,sizeof(temp));
626 }
627 any |= (DeviceTableParse(&adjust->xadjust,md[0].u.md_str)!=NULL);
628 any |= (DeviceTableParse(&adjust->yadjust,md[2].u.md_str)!=NULL);
629 any |= (DeviceTableParse(&adjust->xadv,md[4].u.md_str)!=NULL);
630 any |= (DeviceTableParse(&adjust->yadv,md[6].u.md_str)!=NULL);
631 if ( any && adjust==&temp ) {
632 vr->adjust = chunkalloc(sizeof(ValDevTab));
633 *vr->adjust = temp;
634 } else if ( !any && vr->adjust!=NULL ) {
635 ValDevFree(vr->adjust);
636 vr->adjust = NULL;
637 }
638 }
639
640 void DevTabToString(char **str,DeviceTable *adjust) {
641 char *pt;
642 int i;
643
644 if ( adjust==NULL || adjust->corrections==NULL ) {
645 *str = NULL;
646 return;
647 }
648 *str = pt = malloc(11*(adjust->last_pixel_size-adjust->first_pixel_size+1)+1);
649 for ( i=adjust->first_pixel_size; i<=adjust->last_pixel_size; ++i ) {
650 if ( adjust->corrections[i-adjust->first_pixel_size]!=0 )
651 sprintf( pt, "%d:%d, ", i, adjust->corrections[i-adjust->first_pixel_size]);
652 pt += strlen(pt);
653 }
654 if ( pt>*str && pt[-2] == ',' )
655 pt[-2] = '\0';
656 }
657
658 void ValDevTabToStrings(struct matrix_data *mds,int first_offset,ValDevTab *adjust) {
659 if ( adjust==NULL )
660 return;
661 DevTabToString(&mds[first_offset].u.md_str,&adjust->xadjust);
662 DevTabToString(&mds[first_offset+2].u.md_str,&adjust->yadjust);
663 DevTabToString(&mds[first_offset+4].u.md_str,&adjust->xadv);
664 DevTabToString(&mds[first_offset+6].u.md_str,&adjust->yadv);
665 }
666
667 void KpMDParse(SplineChar *sc,struct lookup_subtable *sub,
668 struct matrix_data *possub,int rows,int cols,int i) {
669 SplineChar *other;
670 PST *pst;
671 KernPair *kp;
672 int isv, iskpable, offset, newv;
673 char *dvstr;
674 char *pt, *start;
675 int ch;
676
677 for ( start=possub[cols*i+1].u.md_str; ; ) {
678 while ( *start==' ' ) ++start;
679 if ( *start=='\0' )
680 break;
681 for ( pt=start; *pt!='\0' && *pt!=' ' && *pt!='('; ++pt );
682 ch = *pt; *pt = '\0';
683 other = SFGetChar(sc->parent,-1,start);
684 for ( pst=sc->possub; pst!=NULL; pst=pst->next ) {
685 if ( pst->subtable == sub &&
686 strcmp(start,pst->u.pair.paired)==0 )
687 break;
688 }
689 kp = NULL;
690 if ( pst==NULL && other!=NULL ) {
691 for ( isv=0; isv<2; ++isv ) {
692 for ( kp = isv ? sc->vkerns : sc->kerns; kp!=NULL; kp=kp->next )
693 if ( kp->subtable==(void *) possub[cols*i+0].u.md_ival &&
694 kp->sc == other )
695 break;
696 if ( kp!=NULL )
697 break;
698 }
699 }
700 newv = false;
701 if ( other==NULL )
702 iskpable = false;
703 else if ( sub->vertical_kerning ) {
704 newv = true;
705 iskpable = possub[cols*i+PAIR_DX1].u.md_ival==0 &&
706 possub[cols*i+PAIR_DY1].u.md_ival==0 &&
707 possub[cols*i+PAIR_DX_ADV1].u.md_ival==0 &&
708 possub[cols*i+PAIR_DX2].u.md_ival==0 &&
709 possub[cols*i+PAIR_DY2].u.md_ival==0 &&
710 possub[cols*i+PAIR_DX_ADV2].u.md_ival==0 &&
711 possub[cols*i+PAIR_DY_ADV2].u.md_ival==0;
712 offset = possub[cols*i+PAIR_DY1].u.md_ival;
713 iskpable &= (possub[cols*i+PAIR_DX1+1].u.md_str==NULL || *possub[cols*i+PAIR_DX1+1].u.md_str==0 ) &&
714 (possub[cols*i+PAIR_DY1+1].u.md_str==0 || *possub[cols*i+PAIR_DY1+1].u.md_str==0 ) &&
715 (possub[cols*i+PAIR_DX_ADV1+1].u.md_str==0 || *possub[cols*i+PAIR_DX_ADV1+1].u.md_str==0 ) &&
716 (possub[cols*i+PAIR_DX2+1].u.md_str==0 || *possub[cols*i+PAIR_DX2+1].u.md_str==0 ) &&
717 (possub[cols*i+PAIR_DY2+1].u.md_str==0 || *possub[cols*i+PAIR_DY2+1].u.md_str==0 ) &&
718 (possub[cols*i+PAIR_DX_ADV2+1].u.md_str==0 || *possub[cols*i+PAIR_DX_ADV2+1].u.md_str==0 ) &&
719 (possub[cols*i+PAIR_DY_ADV2+1].u.md_str==0 || *possub[cols*i+PAIR_DY_ADV2+1].u.md_str==0 );
720 dvstr = possub[cols*i+PAIR_DY1+1].u.md_str;
721 } else if ( sub->lookup->lookup_flags & pst_r2l ) {
722 iskpable = possub[cols*i+PAIR_DX1].u.md_ival==0 &&
723 possub[cols*i+PAIR_DY1].u.md_ival==0 &&
724 possub[cols*i+PAIR_DX_ADV1].u.md_ival==0 &&
725 possub[cols*i+PAIR_DY_ADV1].u.md_ival==0 &&
726 possub[cols*i+PAIR_DX2].u.md_ival==0 &&
727 possub[cols*i+PAIR_DY2].u.md_ival==0 &&
728 possub[cols*i+PAIR_DY_ADV2].u.md_ival==0;
729 offset = possub[cols*i+PAIR_DX_ADV2].u.md_ival;
730 iskpable &= (possub[cols*i+PAIR_DX1+1].u.md_str==NULL || *possub[cols*i+PAIR_DX1+1].u.md_str==0 ) &&
731 (possub[cols*i+PAIR_DY1+1].u.md_str==0 || *possub[cols*i+PAIR_DY1+1].u.md_str==0 ) &&
732 (possub[cols*i+PAIR_DX_ADV1+1].u.md_str==0 || *possub[cols*i+PAIR_DX_ADV1+1].u.md_str==0 ) &&
733 (possub[cols*i+PAIR_DY_ADV1+1].u.md_str==0 || *possub[cols*i+PAIR_DY_ADV1+1].u.md_str==0 ) &&
734 (possub[cols*i+PAIR_DX2+1].u.md_str==0 || *possub[cols*i+PAIR_DX2+1].u.md_str==0 ) &&
735 (possub[cols*i+PAIR_DY2+1].u.md_str==0 || *possub[cols*i+PAIR_DY2+1].u.md_str==0 ) &&
736 (possub[cols*i+PAIR_DY_ADV2+1].u.md_str==0 || *possub[cols*i+PAIR_DY_ADV2+1].u.md_str==0 );
737 dvstr = possub[cols*i+PAIR_DX_ADV2+1].u.md_str;
738 } else {
739 iskpable = possub[cols*i+PAIR_DX1].u.md_ival==0 &&
740 possub[cols*i+PAIR_DY1].u.md_ival==0 &&
741 possub[cols*i+PAIR_DY_ADV1].u.md_ival==0 &&
742 possub[cols*i+PAIR_DX2].u.md_ival==0 &&
743 possub[cols*i+PAIR_DY2].u.md_ival==0 &&
744 possub[cols*i+PAIR_DX_ADV2].u.md_ival==0 &&
745 possub[cols*i+PAIR_DY_ADV2].u.md_ival==0;
746 offset = possub[cols*i+PAIR_DX_ADV1].u.md_ival;
747 iskpable &= (possub[cols*i+PAIR_DX1+1].u.md_str==NULL || *possub[cols*i+PAIR_DX1+1].u.md_str==0 ) &&
748 (possub[cols*i+PAIR_DY1+1].u.md_str==0 || *possub[cols*i+PAIR_DY1+1].u.md_str==0 ) &&
749 (possub[cols*i+PAIR_DY_ADV1+1].u.md_str==0 || *possub[cols*i+PAIR_DY_ADV1+1].u.md_str==0 ) &&
750 (possub[cols*i+PAIR_DX2+1].u.md_str==0 || *possub[cols*i+PAIR_DX2+1].u.md_str==0 ) &&
751 (possub[cols*i+PAIR_DY2+1].u.md_str==0 || *possub[cols*i+PAIR_DY2+1].u.md_str==0 ) &&
752 (possub[cols*i+PAIR_DX_ADV2+1].u.md_str==0 || *possub[cols*i+PAIR_DX_ADV2+1].u.md_str==0 ) &&
753 (possub[cols*i+PAIR_DY_ADV2+1].u.md_str==0 || *possub[cols*i+PAIR_DY_ADV2+1].u.md_str==0 );
754 dvstr = possub[cols*i+PAIR_DX_ADV1+1].u.md_str;
755 }
756 if ( iskpable ) {
757 if ( kp==NULL ) {
758 /* If there's a pst, ignore it, it will not get ticked and will*/
759 /* be freed later */
760 kp = chunkalloc(sizeof(KernPair));
761 kp->subtable = sub;
762 kp->sc = other;
763 if ( newv ) {
764 kp->next = sc->vkerns;
765 sc->vkerns = kp;
766 } else {
767 kp->next = sc->kerns;
768 sc->kerns = kp;
769 }
770 }
771 DeviceTableFree(kp->adjust);
772 kp->adjust = DeviceTableParse(NULL,dvstr);
773 kp->off = offset;
774 kp->kcid = true;
775 } else {
776 if ( pst == NULL ) {
777 /* If there's a kp, ignore it, it will not get ticked and will*/
778 /* be freed later */
779 pst = chunkalloc(sizeof(PST));
780 pst->type = pst_pair;
781 pst->subtable = sub;
782 pst->next = sc->possub;
783 sc->possub = pst;
784 pst->u.pair.vr = chunkalloc(sizeof(struct vr [2]));
785 pst->u.pair.paired = copy(start);
786 }
787 VRDevTabParse(&pst->u.pair.vr[0],&possub[cols*i+PAIR_DX1+1]);
788 VRDevTabParse(&pst->u.pair.vr[1],&possub[cols*i+PAIR_DX2]+1);
789 pst->u.pair.vr[0].xoff = possub[cols*i+PAIR_DX1].u.md_ival;
790 pst->u.pair.vr[0].yoff = possub[cols*i+PAIR_DY1].u.md_ival;
791 pst->u.pair.vr[0].h_adv_off = possub[cols*i+PAIR_DX_ADV1].u.md_ival;
792 pst->u.pair.vr[0].v_adv_off = possub[cols*i+PAIR_DY_ADV1].u.md_ival;
793 pst->u.pair.vr[1].xoff = possub[cols*i+PAIR_DX2].u.md_ival;
794 pst->u.pair.vr[1].yoff = possub[cols*i+PAIR_DY2].u.md_ival;
795 pst->u.pair.vr[1].h_adv_off = possub[cols*i+PAIR_DX_ADV2].u.md_ival;
796 pst->u.pair.vr[1].v_adv_off = possub[cols*i+PAIR_DY_ADV2].u.md_ival;
797 pst->ticked = true;
798 }
799 *pt = ch;
800 if ( ch=='(' ) {
801 while ( *pt!=')' && *pt!='\0' ) ++pt;
802 if ( *pt==')' ) ++pt;
803 }
804 start = pt;
805 }
806 }
807
808 static int CI_ProcessPosSubs(CharInfo *ci) {
809 /* Check for duplicate entries in kerning and ligatures. If we find any */
810 /* complain and return failure */
811 /* Check for various other errors */
812 /* Otherwise process */
813 SplineChar *sc = ci->cachedsc, *found;
814 int i,j, rows, cols, isv, pstt, ch;
815 char *pt;
816 struct matrix_data *possub;
817 char *buts[3];
818 KernPair *kp, *kpprev, *kpnext;
819 PST *pst, *pstprev, *pstnext, *lcpst=NULL;
820
821 possub = GMatrixEditGet(GWidgetGetControl(ci->gw,CID_List+(pst_ligature-1)*100), &rows );
822 cols = GMatrixEditGetColCnt(GWidgetGetControl(ci->gw,CID_List+(pst_ligature-1)*100) );
823 for ( i=0; i<rows; ++i ) {
824 for ( j=i+1; j<rows; ++j ) {
825 if ( possub[cols*i+0].u.md_ival == possub[cols*j+0].u.md_ival &&
826 strcmp(possub[cols*i+1].u.md_str,possub[cols*j+1].u.md_str)==0 ) {
827 ff_post_error( _("Duplicate Ligature"),_("There are two ligature entries with the same components (%.80s) in the same lookup subtable (%.30s)"),
828 possub[cols*j+1].u.md_str,
829 ((struct lookup_subtable *) possub[cols*i+0].u.md_ival)->subtable_name );
830 return( false );
831 }
832 }
833 }
834 possub = GMatrixEditGet(GWidgetGetControl(ci->gw,CID_List+(pst_pair-1)*100), &rows );
835 cols = GMatrixEditGetColCnt(GWidgetGetControl(ci->gw,CID_List+(pst_pair-1)*100));
836 for ( i=0; i<rows; ++i ) {
837 for ( j=i+1; j<rows; ++j ) {
838 if ( possub[cols*i+0].u.md_ival == possub[cols*j+0].u.md_ival &&
839 strcmp(possub[cols*i+1].u.md_str,possub[cols*j+1].u.md_str)==0 ) {
840 ff_post_error( _("Duplicate Kern data"),_("There are two kerning entries for the same glyph (%.80s) in the same lookup subtable (%.30s)"),
841 possub[cols*j+1].u.md_str,
842 ((struct lookup_subtable *) possub[cols*i+0].u.md_ival)->subtable_name );
843 return( false );
844 }
845 }
846 }
847
848 /* Check for badly specified device tables */
849 for ( pstt = pst_position; pstt<=pst_pair; ++pstt ) {
850 int startc = pstt==pst_position ? SIM_DX+1 : PAIR_DX1+1;
851 int low, high, c, r;
852 possub = GMatrixEditGet(GWidgetGetControl(ci->gw,CID_List+(pstt-1)*100), &rows );
853 cols = GMatrixEditGetColCnt(GWidgetGetControl(ci->gw,CID_List+(pstt-1)*100));
854 for ( r=0; r<rows; ++r ) {
855 for ( c=startc; c<cols; c+=2 ) {
856 if ( !DeviceTableOK(possub[r*cols+c].u.md_str,&low,&high) ) {
857 ff_post_error( _("Bad Device Table Adjustment"),_("A device table adjustment specified for %.80s is invalid"),
858 possub[cols*r+0].u.md_str );
859 return( true );
860 }
861 }
862 }
863 }
864
865 for ( pstt = pst_pair; pstt<=pst_ligature; ++pstt ) {
866 possub = GMatrixEditGet(GWidgetGetControl(ci->gw,CID_List+(pstt-1)*100), &rows );
867 cols = GMatrixEditGetColCnt(GWidgetGetControl(ci->gw,CID_List+(pstt-1)*100));
868 for ( i=0; i<rows; ++i ) {
869 char *start = possub[cols*i+1].u.md_str;
870 while ( *start== ' ' ) ++start;
871 if ( *start=='\0' ) {
872 ff_post_error( _("Missing glyph name"),_("You must specify a glyph name for subtable %s"),
873 ((struct lookup_subtable *) possub[cols*i+0].u.md_ival)->subtable_name );
874 return( false );
875 }
876 while ( *start ) {
877 for ( pt=start; *pt!='\0' && *pt!=' ' && *pt!='(' ; ++pt );
878 ch = *pt; *pt='\0';
879 found = SFGetChar(sc->parent,-1,start);
880 if ( found==NULL ) {
881 buts[0] = _("_Yes");
882 buts[1] = _("_Cancel");
883 buts[2] = NULL;
884 if ( gwwv_ask(_("Missing glyph"),(const char **) buts,0,1,_("In lookup subtable %.30s you refer to a glyph named %.80s, which is not in the font yet. Was this intentional?"),
885 ((struct lookup_subtable *) possub[cols*i+0].u.md_ival)->subtable_name,
886 start)==1 ) {
887 *pt = ch;
888 return( false );
889 }
890 } else if ( found==ci->sc && pstt!=pst_pair ) {
891 buts[0] = _("_Yes");
892 buts[1] = _("_Cancel");
893 buts[2] = NULL;
894 if ( gwwv_ask(_("Substitution generates itself"),(const char **) buts,0,1,_("In lookup subtable %.30s you replace a glyph with itself. Was this intentional?"),
895 ((struct lookup_subtable *) possub[cols*i+0].u.md_ival)->subtable_name)==1 ) {
896 *pt = ch;
897 return( false );
898 }
899 }
900 *pt = ch;
901 if ( ch=='(' ) {
902 while ( *pt!=')' && *pt!='\0' ) ++pt;
903 if ( *pt==')' ) ++pt;
904 }
905 while ( *pt== ' ' ) ++pt;
906 start = pt;
907 }
908 }
909 }
910
911 /* If we get this far, then we didn't find any errors */
912 for ( pst = sc->possub; pst!=NULL; pst=pst->next ) {
913 pst->ticked = false;
914 if ( pst->type==pst_lcaret )
915 lcpst = pst;
916 }
917
918 // There is no dialog datastructure for the ligature carets, so copy them here
919 // The entry will be modified in _CI_OK when needed
920 for ( pst = ci->sc->possub; pst!=NULL && pst->type!=pst_lcaret; pst=pst->next )
921 ;
922 if ( pst!=NULL ) {
923 if ( lcpst==NULL ) {
924 lcpst = chunkalloc(sizeof(PST));
925 lcpst->type = pst_lcaret;
926 lcpst->next = sc->possub;
927 sc->possub = lcpst;
928 }
929 if ( lcpst->u.lcaret.carets!=NULL )
930 free(lcpst->u.lcaret.carets);
931 lcpst->u.lcaret.cnt = pst->u.lcaret.cnt;
932 lcpst->u.lcaret.carets = malloc(pst->u.lcaret.cnt*sizeof(int16_t));
933 memcpy(lcpst->u.lcaret.carets,pst->u.lcaret.carets,pst->u.lcaret.cnt*sizeof(int16_t));
934 lcpst->ticked = true;
935 }
936
937 for ( isv=0; isv<2; ++isv )
938 for ( kp = isv ? sc->vkerns : sc->kerns; kp!=NULL; kp=kp->next )
939 kp->kcid = 0;
940
941 for ( pstt=pst_substitution; pstt<=pst_ligature; ++pstt ) {
942 possub = GMatrixEditGet(GWidgetGetControl(ci->gw,CID_List+(pstt-1)*100), &rows );
943 cols = GMatrixEditGetColCnt(GWidgetGetControl(ci->gw,CID_List+(pstt-1)*100) );
944 for ( i=0; i<rows; ++i ) {
945 for ( pst=sc->possub; pst!=NULL; pst=pst->next ) {
946 if ( pst->subtable == (void *) possub[cols*i+0].u.md_ival &&
947 !pst->ticked )
948 break;
949 }
950 if ( pst==NULL ) {
951 pst = chunkalloc(sizeof(PST));
952 pst->type = pstt;
953 pst->subtable = (void *) possub[cols*i+0].u.md_ival;
954 pst->next = sc->possub;
955 sc->possub = pst;
956 } else
957 free( pst->u.subs.variant );
958 pst->ticked = true;
959 pst->u.subs.variant = GlyphNameListDeUnicode( possub[cols*i+1].u.md_str );
960 if ( pstt==pst_ligature )
961 pst->u.lig.lig = sc;
962 }
963 }
964
965 possub = GMatrixEditGet(GWidgetGetControl(ci->gw,CID_List+(pst_position-1)*100), &rows );
966 cols = GMatrixEditGetColCnt(GWidgetGetControl(ci->gw,CID_List+(pst_position-1)*100));
967 for ( i=0; i<rows; ++i ) {
968 for ( pst=sc->possub; pst!=NULL; pst=pst->next ) {
969 if ( pst->subtable == (void *) possub[cols*i+0].u.md_ival &&
970 !pst->ticked )
971 break;
972 }
973 if ( pst==NULL ) {
974 pst = chunkalloc(sizeof(PST));
975 pst->type = pst_position;
976 pst->subtable = (void *) possub[cols*i+0].u.md_ival;
977 pst->next = sc->possub;
978 sc->possub = pst;
979 }
980 VRDevTabParse(&pst->u.pos,&possub[cols*i+SIM_DX+1]);
981 pst->u.pos.xoff = possub[cols*i+SIM_DX].u.md_ival;
982 pst->u.pos.yoff = possub[cols*i+SIM_DY].u.md_ival;
983 pst->u.pos.h_adv_off = possub[cols*i+SIM_DX_ADV].u.md_ival;
984 pst->u.pos.v_adv_off = possub[cols*i+SIM_DY_ADV].u.md_ival;
985 pst->ticked = true;
986 }
987
988 possub = GMatrixEditGet(GWidgetGetControl(ci->gw,CID_List+(pst_pair-1)*100), &rows );
989 cols = GMatrixEditGetColCnt(GWidgetGetControl(ci->gw,CID_List+(pst_pair-1)*100));
990 for ( i=0; i<rows; ++i ) {
991 struct lookup_subtable *sub = ((struct lookup_subtable *) possub[cols*i+0].u.md_ival);
992 KpMDParse(sc,sub,possub,rows,cols,i);
993 }
994
995 /* Now, free anything that did not get ticked */
996 for ( pstprev=NULL, pst = sc->possub; pst!=NULL; pst=pstnext ) {
997 pstnext = pst->next;
998 if ( pst->ticked )
999 pstprev = pst;
1000 else {
1001 if ( pstprev==NULL )
1002 sc->possub = pstnext;
1003 else
1004 pstprev->next = pstnext;
1005 pst->next = NULL;
1006 PSTFree(pst);
1007 }
1008 }
1009 for ( isv=0; isv<2; ++isv ) {
1010 for ( kpprev=NULL, kp = isv ? sc->vkerns : sc->kerns; kp!=NULL; kp=kpnext ) {
1011 kpnext = kp->next;
1012 if ( kp->kcid!=0 )
1013 kpprev = kp;
1014 else {
1015 if ( kpprev!=NULL )
1016 kpprev->next = kpnext;
1017 else if ( isv )
1018 sc->vkerns = kpnext;
1019 else
1020 sc->kerns = kpnext;
1021 kp->next = NULL;
1022 KernPairsFree(kp);
1023 }
1024 }
1025 }
1026 for ( isv=0; isv<2; ++isv )
1027 for ( kp = isv ? sc->vkerns : sc->kerns; kp!=NULL; kp=kp->next )
1028 kp->kcid = 0;
1029 return( true );
1030 }
1031
1032 static int gettex(GWindow gw,int cid,char *msg,int *err) {
1033 const unichar_t *ret = _GGadgetGetTitle(GWidgetGetControl(gw,cid));
1034
1035 if ( *ret=='\0' )
1036 return( TEX_UNDEF );
1037 return( GetInt8(gw,cid,msg,err));
1038 }
1039
1040 struct glyphvariants *GV_ParseConstruction(struct glyphvariants *gv,
1041 struct matrix_data *stuff, int rows, int cols) {
1042 int i;
1043
1044 if ( gv==NULL )
1045 gv = chunkalloc(sizeof(struct glyphvariants));
1046
1047 gv->part_cnt = rows;
1048 gv->parts = calloc(rows,sizeof(struct gv_part));
1049 for ( i=0; i<rows; ++i ) {
1050 gv->parts[i].component = copy(stuff[i*cols+0].u.md_str);
1051 gv->parts[i].is_extender = stuff[i*cols+1].u.md_ival;
1052 gv->parts[i].startConnectorLength = stuff[i*cols+2].u.md_ival;
1053 gv->parts[i].endConnectorLength = stuff[i*cols+3].u.md_ival;
1054 gv->parts[i].fullAdvance = stuff[i*cols+4].u.md_ival;
1055 }
1056 return( gv );
1057 }
1058
1059 static struct glyphvariants *CI_ParseVariants(struct glyphvariants *gv,
1060 CharInfo *ci, int is_horiz,
1061 char *italic_correction_devtab, int italic_correction,
1062 int only_parts) {
1063 char *variants = GGadgetGetTitle8(GWidgetGetControl(ci->gw,CID_VariantList+is_horiz*100));
1064 GGadget *construct = GWidgetGetControl(ci->gw,CID_ExtensionList+is_horiz*100);
1065 int rows, cols = GMatrixEditGetColCnt(construct);
1066 struct matrix_data *stuff = GMatrixEditGet(construct,&rows);
1067
1068 if ( (variants==NULL || variants[0]=='\0' || only_parts) && rows==0 ) {
1069 free(variants);
1070 GlyphVariantsFree(gv);
1071 return( NULL );
1072 }
1073 if ( gv==NULL )
1074 gv = chunkalloc(sizeof(struct glyphvariants));
1075 free(gv->variants); gv->variants = NULL;
1076 if ( only_parts ) {
1077 free(variants); variants = NULL;
1078 } else if ( variants!=NULL && *variants!='\0' )
1079 gv->variants = variants;
1080 else {
1081 gv->variants = NULL;
1082 free( variants);
1083 }
1084 if ( !only_parts ) {
1085 gv->italic_correction = italic_correction;
1086 gv->italic_adjusts = DeviceTableParse(gv->italic_adjusts,italic_correction_devtab);
1087 }
1088 gv = GV_ParseConstruction(gv,stuff,rows,cols);
1089 return( gv );
1090 }
1091
1092 static int CI_ValidateAltUnis(CharInfo *ci) {
1093 GGadget *au = GWidgetGetControl(ci->gw,CID_AltUni);
1094 int rows, cols = GMatrixEditGetColCnt(au);
1095 struct matrix_data *stuff = GMatrixEditGet(au,&rows);
1096 int i, asked = false;
1097
1098 for ( i=0; i<rows; ++i ) {
1099 int uni = stuff[i*cols+0].u.md_ival, vs = stuff[i*cols+1].u.md_ival;
1100 if ( uni<0 || uni>=unicode4_size ||
1101 vs<-1 || vs>=unicode4_size ) {
1102 ff_post_error(_("Unicode out of range"), _("Bad unicode value for an alternate unicode / variation selector"));
1103 return( false );
1104 }
1105 if ( (vs>=0x180B && vs<=0x180D) || /* Mongolian VS */
1106 (vs>=0xfe00 && vs<=0xfe0f) || /* First VS block */
1107 (vs>=0xE0100 && vs<=0xE01EF) ) { /* Second VS block */
1108 /* ok, that's a reasonable value */;
1109 } else if ( vs==0 || vs==-1 ) {
1110 /* That's ok too (means no selector, just an alternate encoding) */;
1111 } else if ( !asked ) {
1112 char *buts[3];
1113 buts[0] = _("_OK"); buts[1] = _("_Cancel"); buts[2]=NULL;
1114 if ( gwwv_ask(_("Unexpected Variation Selector"),(const char **) buts,0,1,
1115 _("Variation selectors are normally between\n"
1116 " U+180B and U+180D\n"
1117 " U+FE00 and U+FE0F\n"
1118 " U+E0100 and U+E01EF\n"
1119 "did you really intend to use U+%04X?"), vs)==1 )
1120 return( false );
1121 asked = true;
1122 }
1123 }
1124 return( true );
1125 }
1126
1127 static void CI_ParseAltUnis(CharInfo *ci) {
1128 GGadget *au = GWidgetGetControl(ci->gw,CID_AltUni);
1129 int rows, cols = GMatrixEditGetColCnt(au);
1130 struct matrix_data *stuff = GMatrixEditGet(au,&rows);
1131 int i;
1132 struct altuni *altuni, *last = NULL;
1133 SplineChar *sc = ci->cachedsc;
1134 int deenc = false;
1135 FontView *fvs;
1136 int oldcnt, newcnt;
1137
1138 oldcnt = 0;
1139 for ( altuni=sc->altuni ; altuni!=NULL; altuni = altuni->next )
1140 if ( altuni->vs==-1 && altuni->fid==0 )
1141 ++oldcnt;
1142
1143 newcnt = 0;
1144 for ( i=0; i<rows; ++i ) {
1145 int uni = stuff[i*cols+0].u.md_ival, vs = stuff[i*cols+1].u.md_ival;
1146 if ( vs!=0 )
1147 continue;
1148 ++newcnt;
1149 if ( uni==sc->unicodeenc )
1150 continue;
1151 for ( altuni=sc->altuni ; altuni!=NULL; altuni = altuni->next )
1152 if ( uni==altuni->unienc && altuni->vs==-1 && altuni->fid==0 )
1153 break;
1154 if ( altuni==NULL ) {
1155 deenc = true;
1156 break;
1157 }
1158 }
1159 if ( oldcnt!=newcnt || deenc ) {
1160 for ( fvs=(FontView *) sc->parent->fv; fvs!=NULL; fvs=(FontView *) fvs->b.nextsame ) {
1161 fvs->b.map->enc = &custom;
1162 FVSetTitle((FontViewBase *) fvs);
1163 }
1164 }
1165 AltUniFree(sc->altuni); sc->altuni = NULL;
1166 for ( i=0; i<rows; ++i ) {
1167 int uni = stuff[i*cols+0].u.md_ival, vs = stuff[i*cols+1].u.md_ival;
1168 altuni = chunkalloc(sizeof(struct altuni));
1169 altuni->unienc = uni;
1170 altuni->vs = vs==0 ? -1 : vs;
1171 altuni->fid = 0;
1172 if ( last == NULL )
1173 sc->altuni = altuni;
1174 else
1175 last->next = altuni;
1176 last = altuni;
1177 }
1178 }
1179
1180 static KernPair *CI_KPCopy(KernPair *kp) {
1181 KernPair *head=NULL, *last=NULL, *newkp;
1182
1183 while ( kp!=NULL ) {
1184 newkp = chunkalloc(sizeof(KernPair));
1185 *newkp = *kp;
1186 newkp->adjust = DeviceTableCopy(kp->adjust);
1187 newkp->next = NULL;
1188 if ( head==NULL )
1189 head = newkp;
1190 else
1191 last->next = newkp;
1192 last = newkp;
1193 kp = kp->next;
1194 }
1195 return( head );
1196 }
1197
1198 static PST *CI_PSTCopy(PST *pst) {
1199 PST *head=NULL, *last=NULL, *newpst;
1200
1201 while ( pst!=NULL ) {
1202 newpst = chunkalloc(sizeof(KernPair));
1203 *newpst = *pst;
1204 if ( newpst->type==pst_ligature ) {
1205 newpst->u.lig.components = copy(pst->u.lig.components);
1206 } else if ( newpst->type==pst_pair ) {
1207 newpst->u.pair.paired = copy(pst->u.pair.paired);
1208 newpst->u.pair.vr = chunkalloc(sizeof( struct vr [2]));
1209 memcpy(newpst->u.pair.vr,pst->u.pair.vr,sizeof(struct vr [2]));
1210 newpst->u.pair.vr[0].adjust = ValDevTabCopy(pst->u.pair.vr[0].adjust);
1211 newpst->u.pair.vr[1].adjust = ValDevTabCopy(pst->u.pair.vr[1].adjust);
1212 } else if ( newpst->type==pst_lcaret ) {
1213 newpst->u.lcaret.carets = malloc(pst->u.lcaret.cnt*sizeof(int16_t));
1214 memcpy(newpst->u.lcaret.carets,pst->u.lcaret.carets,pst->u.lcaret.cnt*sizeof(int16_t));
1215 } else if ( newpst->type==pst_substitution || newpst->type==pst_multiple || newpst->type==pst_alternate )
1216 newpst->u.subs.variant = copy(pst->u.subs.variant);
1217 newpst->next = NULL;
1218 if ( head==NULL )
1219 head = newpst;
1220 else
1221 last->next = newpst;
1222 last = newpst;
1223 pst = pst->next;
1224 }
1225 return( head );
1226 }
1227
1228 static SplineChar *CI_SCDuplicate(SplineChar *sc) {
1229 SplineChar *newsc; /* copy everything we care about in this dlg */
1230
1231 newsc = chunkalloc(sizeof(SplineChar));
1232 newsc->name = copy(sc->name);
1233 newsc->parent = sc->parent;
1234 newsc->unicodeenc = sc->unicodeenc;
1235 newsc->orig_pos = sc->orig_pos;
1236 newsc->comment = copy(sc->comment);
1237 newsc->user_decomp = u_copy(sc->user_decomp);
1238 newsc->unlink_rm_ovrlp_save_undo = sc->unlink_rm_ovrlp_save_undo;
1239 newsc->glyph_class = sc->glyph_class;
1240 newsc->color = sc->color;
1241 if ( sc->countermask_cnt!=0 ) {
1242 newsc->countermask_cnt = sc->countermask_cnt;
1243 newsc->countermasks = malloc(sc->countermask_cnt*sizeof(HintMask));
1244 memcpy(newsc->countermasks,sc->countermasks,sc->countermask_cnt*sizeof(HintMask));
1245 }
1246 newsc->tex_height = sc->tex_height;
1247 newsc->tex_depth = sc->tex_depth;
1248 newsc->italic_correction = sc->italic_correction;
1249 newsc->top_accent_horiz = sc->top_accent_horiz;
1250 newsc->is_extended_shape = sc->is_extended_shape;
1251 newsc->italic_adjusts = DeviceTableCopy(sc->italic_adjusts);
1252 newsc->top_accent_adjusts = DeviceTableCopy(sc->top_accent_adjusts);
1253 newsc->horiz_variants = GlyphVariantsCopy(sc->horiz_variants);
1254 newsc->vert_variants = GlyphVariantsCopy(sc->vert_variants);
1255 newsc->altuni = AltUniCopy(sc->altuni,NULL);
1256 newsc->lig_caret_cnt_fixed = sc->lig_caret_cnt_fixed;
1257 newsc->possub = CI_PSTCopy(sc->possub);
1258 newsc->kerns = CI_KPCopy(sc->kerns);
1259 newsc->vkerns = CI_KPCopy(sc->vkerns);
1260 newsc->tile_margin = sc->tile_margin;
1261 newsc->tile_bounds = sc->tile_bounds;
1262 return( newsc );
1263 }
1264
1265 static int CI_CheckMetaData(CharInfo *ci,SplineChar *oldsc,char *name,int unienc, char *comment) {
1266 SplineFont *sf = oldsc->parent;
1267 int i;
1268 int isnotdef, samename=false, sameuni=false;
1269 struct altuni *alt;
1270 SplineChar *newsc = ci->cachedsc;
1271 struct splinecharlist *scl, *baduniscl, *badnamescl;
1272 SplineChar *baduni, *badname;
1273
1274 for ( alt=oldsc->altuni; alt!=NULL && (alt->unienc!=unienc || alt->vs!=-1 || alt->fid!=0); alt=alt->next );
1275 if ( unienc==oldsc->unicodeenc || alt!=NULL )
1276 sameuni=true;
1277 samename = ( oldsc->name!=NULL && strcmp(name,oldsc->name)==0 );
1278
1279 isnotdef = strcmp(name,".notdef")==0;
1280 if (( !sameuni && unienc!=-1) || (!samename && !isnotdef) ) {
1281 baduniscl = badnamescl = NULL;
1282 baduni = badname = NULL;
1283 for ( i=0; i<sf->glyphcnt; ++i ) if ( sf->glyphs[i]!=NULL && sf->glyphs[i]!=ci->sc ) {
1284 if ( unienc!=-1 && sf->glyphs[i]->unicodeenc==unienc ) {
1285 for ( scl=ci->changes; scl!=NULL && scl->sc->orig_pos!=i; scl = scl->next );
1286 if ( scl==NULL ) {
1287 baduni = sf->glyphs[i];
1288 baduniscl = NULL;
1289 } else if ( scl->sc->unicodeenc==unienc ) {
1290 baduni = scl->sc;
1291 baduniscl = scl;
1292 }
1293 }
1294 if ( !isnotdef && strcmp(name,sf->glyphs[i]->name )==0 ) {
1295 for ( scl=ci->changes; scl!=NULL && scl->sc->orig_pos!=i; scl = scl->next );
1296 if ( scl==NULL ) {
1297 badname = sf->glyphs[i];
1298 badnamescl = NULL;
1299 } else if ( strcmp(scl->sc->name,name)==0 ) {
1300 badname = scl->sc;
1301 badnamescl = scl;
1302 }
1303 }
1304 }
1305 for ( scl=ci->changes; scl!=NULL ; scl = scl->next ) if ( scl->sc!=newsc ) {
1306 if ( unienc!=-1 && scl->sc->unicodeenc==unienc ) {
1307 baduni = scl->sc;
1308 baduniscl = scl;
1309 }
1310 if ( !isnotdef && strcmp(scl->sc->name,name)==0 ) {
1311 badname = scl->sc;
1312 badnamescl = scl;
1313 }
1314 }
1315 if ( baduni!=NULL || badname!=NULL ) {
1316 char *buts[3];
1317 buts[0] = _("_Yes"); buts[1]=_("_Cancel"); buts[2] = NULL;
1318 if ( badname==baduni ) {
1319 if ( ff_ask(_("Multiple"),(const char **) buts,0,1,_("There is already a glyph with this name and encoding,\nboth must be unique within a font,\ndo you want to swap them?"))==1 )
1320 return( false );
1321 /* If we're going to swap, then add the swapee to the list of */
1322 /* things that need changing */
1323 if ( baduniscl==NULL ) {
1324 baduni = CI_SCDuplicate(baduni);
1325 baduniscl = chunkalloc(sizeof(struct splinecharlist));
1326 baduniscl->sc = baduni;
1327 baduniscl->next = ci->changes;
1328 ci->changes = baduniscl;
1329 }
1330 baduni->unicodeenc = oldsc->unicodeenc;
1331 free(baduni->name); baduni->name = copy(oldsc->name);
1332 } else {
1333 if ( baduni!=NULL ) {
1334 if ( ff_ask(_("Multiple"),(const char **) buts,0,1,_("There is already a glyph with this encoding,\nwhich must be unique within a font,\ndo you want to swap the encodings of the two?"))==1 )
1335 return( false );
1336 if ( baduniscl==NULL ) {
1337 baduni = CI_SCDuplicate(baduni);
1338 baduniscl = chunkalloc(sizeof(struct splinecharlist));
1339 baduniscl->sc = baduni;
1340 baduniscl->next = ci->changes;
1341 ci->changes = baduniscl;
1342 }
1343 baduni->unicodeenc = oldsc->unicodeenc;
1344 }
1345 if ( badname!=NULL ) {
1346 if ( ff_ask(_("Multiple"),(const char **) buts,0,1,_("There is already a glyph with this name,\nwhich must be unique within a font,\ndo you want to swap the names of the two?"))==1 )
1347 return( false );
1348 if ( badnamescl==NULL ) {
1349 badname = CI_SCDuplicate(badname);
1350 badnamescl = chunkalloc(sizeof(struct splinecharlist));
1351 badnamescl->sc = badname;
1352 badnamescl->next = ci->changes;
1353 ci->changes = badnamescl;
1354 }
1355 free(badname->name); badname->name = copy(oldsc->name);
1356 }
1357 }
1358 }
1359 }
1360 if ( !samename )
1361 ci->name_change = true;
1362 if ( !sameuni )
1363 ci->uni_change = true;
1364 free( newsc->name ); free( newsc->comment );
1365 newsc->name = copy( name );
1366 newsc->unicodeenc = unienc;
1367 newsc->comment = copy( comment );
1368 return( true );
1369 }
1370
1371 static int _CI_OK(CharInfo *ci) {
1372 int val;
1373 int ret;
1374 char *name, *comment;
1375 const unichar_t *nm;
1376 int err = false;
1377 int tex_height, tex_depth, italic, topaccent;
1378 int hic, vic;
1379 int lc_cnt=-1;
1380 char *italicdevtab=NULL, *accentdevtab=NULL, *hicdt=NULL, *vicdt=NULL;
1381 int lig_caret_cnt_fixed=0;
1382 int low,high;
1383 real tile_margin=0;
1384 DBounds tileb;
1385 SplineChar *oldsc = ci->cachedsc==NULL ? ci->sc : ci->cachedsc;
1386
1387 if ( !CI_ValidateAltUnis(ci))
1388 return( false );
1389
1390 val = ParseUValue(ci->gw,CID_UValue,true);
1391 if ( val==-2 )
1392 return( false );
1393 tex_height = gettex(ci->gw,CID_TeX_Height,_("Height"),&err);
1394 tex_depth = gettex(ci->gw,CID_TeX_Depth ,_("Depth") ,&err);
1395 italic = gettex(ci->gw,CID_TeX_Italic,_("Italic Correction"),&err);
1396 topaccent = gettex(ci->gw,CID_HorAccent,_("Top Accent Horizontal Pos"),&err);
1397 if ( err )
1398 return( false );
1399 hic = GetInt8(ci->gw,CID_ExtItalicCor+1*100,_("Horizontal Extension Italic Correction"),&err);
1400 vic = GetInt8(ci->gw,CID_ExtItalicCor+0*100,_("Vertical Extension Italic Correction"),&err);
1401 if ( err )
1402 return( false );
1403
1404 memset(&tileb,0,sizeof(tileb));
1405 if ( ci->sc->parent->multilayer ) {
1406 if ( GGadgetIsChecked(GWidgetGetControl(ci->gw,CID_IsTileMargin)))
1407 tile_margin = GetReal8(ci->gw,CID_TileMargin,_("Tile Margin"),&err);
1408 else {
1409 tileb.minx = GetReal8(ci->gw,CID_TileBBoxMinX,_("Tile Min X"),&err);
1410 tileb.miny = GetReal8(ci->gw,CID_TileBBoxMinY,_("Tile Min Y"),&err);
1411 tileb.maxx = GetReal8(ci->gw,CID_TileBBoxMaxX,_("Tile Max X"),&err);
1412 tileb.maxy = GetReal8(ci->gw,CID_TileBBoxMaxY,_("Tile Max Y"),&err);
1413 }
1414 if ( err )
1415 return( false );
1416 }
1417
1418 lig_caret_cnt_fixed = !GGadgetIsChecked(GWidgetGetControl(ci->gw,CID_DefLCCount));
1419 if ( ci->lc_seen ) {
1420 lc_cnt = GetInt8(ci->gw,CID_LCCount,_("Ligature Caret Count"),&err);
1421 if ( err )
1422 return( false );
1423 if ( lc_cnt<0 || lc_cnt>100 ) {
1424 ff_post_error(_("Bad Lig. Caret Count"),_("Unreasonable ligature caret count"));
1425 return( false );
1426 }
1427 }
1428 nm = _GGadgetGetTitle(GWidgetGetControl(ci->gw,CID_UName));
1429 if ( !CI_NameCheck(nm) )
1430 return( false );
1431
1432 italicdevtab = GGadgetGetTitle8(GWidgetGetControl(ci->gw,CID_ItalicDevTab));
1433 accentdevtab = GGadgetGetTitle8(GWidgetGetControl(ci->gw,CID_AccentDevTab));
1434 hicdt = GGadgetGetTitle8(GWidgetGetControl(ci->gw,CID_ExtItalicDev+1*100));
1435 vicdt = GGadgetGetTitle8(GWidgetGetControl(ci->gw,CID_ExtItalicDev+0*100));
1436 if ( !DeviceTableOK(italicdevtab,&low,&high) || !DeviceTableOK(accentdevtab,&low,&high) ||
1437 !DeviceTableOK(hicdt,&low,&high) || !DeviceTableOK(vicdt,&low,&high)) {
1438 ff_post_error( _("Bad Device Table Adjustment"),_("A device table adjustment specified for the MATH table is invalid") );
1439 free( accentdevtab );
1440 free( italicdevtab );
1441 free(hicdt); free(vicdt);
1442 return( false );
1443 }
1444 if ( ci->cachedsc==NULL ) {
1445 struct splinecharlist *scl;
1446 ci->cachedsc = chunkalloc(sizeof(SplineChar));
1447 ci->cachedsc->orig_pos = ci->sc->orig_pos;
1448 ci->cachedsc->parent = ci->sc->parent;
1449 ci->cachedsc->user_decomp = u_copy(ci->sc->user_decomp);
1450 scl = chunkalloc(sizeof(struct splinecharlist));
1451 scl->sc = ci->cachedsc;
1452 scl->next = ci->changes;
1453 ci->changes = scl;
1454 }
1455 /* CI_ProcessPosSubs is the first thing which might change anything real */
1456 if ( !CI_ProcessPosSubs(ci)) {
1457 free( accentdevtab );
1458 free( italicdevtab );
1459 free(hicdt); free(vicdt);
1460 return( false );
1461 }
1462 name = u2utf8_copy( nm );
1463 comment = GGadgetGetTitle8(GWidgetGetControl(ci->gw,CID_Comment));
1464 if ( comment!=NULL && *comment=='\0' ) {
1465 free(comment);
1466 comment=NULL;
1467 }
1468 ret = CI_CheckMetaData(ci,oldsc,name,val,comment);
1469 free(name); free(comment);
1470 if ( !ret ) {
1471 free( accentdevtab );
1472 free( italicdevtab );
1473 free(hicdt); free(vicdt);
1474 return( false );
1475 }
1476 ci->cachedsc->unlink_rm_ovrlp_save_undo = GGadgetIsChecked(GWidgetGetControl(ci->gw,CID_UnlinkRmOverlap));
1477 ci->cachedsc->glyph_class = GGadgetGetFirstListSelectedItem(GWidgetGetControl(ci->gw,CID_GClass));
1478 val = GGadgetGetFirstListSelectedItem(GWidgetGetControl(ci->gw,CID_Color));
1479 if ( val!=-1 )
1480 ci->cachedsc->color = (intptr_t) (std_colors[val].userdata);
1481 CI_ParseCounters(ci);
1482 ci->cachedsc->tex_height = tex_height;
1483 ci->cachedsc->tex_depth = tex_depth;
1484 ci->cachedsc->italic_correction = italic;
1485 ci->cachedsc->top_accent_horiz = topaccent;
1486 ci->cachedsc->is_extended_shape = GGadgetIsChecked(GWidgetGetControl(ci->gw,CID_IsExtended));
1487 ci->cachedsc->italic_adjusts = DeviceTableParse(ci->cachedsc->italic_adjusts,italicdevtab);
1488 ci->cachedsc->top_accent_adjusts = DeviceTableParse(ci->cachedsc->top_accent_adjusts,accentdevtab);
1489 ci->cachedsc->horiz_variants = CI_ParseVariants(ci->cachedsc->horiz_variants,ci,1,hicdt,hic,false);
1490 ci->cachedsc->vert_variants = CI_ParseVariants(ci->cachedsc->vert_variants ,ci,0,vicdt,vic,false);
1491
1492 free( accentdevtab );
1493 free( italicdevtab );
1494 free(hicdt); free(vicdt);
1495
1496 CI_ParseAltUnis(ci);
1497
1498 if ( ci->lc_seen ) {
1499 PST *pst, *prev=NULL;
1500 int i;
1501 ci->cachedsc->lig_caret_cnt_fixed = lig_caret_cnt_fixed;
1502 for ( pst = ci->cachedsc->possub; pst!=NULL && pst->type!=pst_lcaret; pst=pst->next )
1503 prev = pst;
1504 if ( pst==NULL && lc_cnt==0 )
1505 /* Nothing to do */;
1506 else if ( pst!=NULL && lc_cnt==0 ) {
1507 if ( prev==NULL )
1508 ci->cachedsc->possub = pst->next;
1509 else
1510 prev->next = pst->next;
1511 pst->next = NULL;
1512 PSTFree(pst);
1513 } else {
1514 if ( pst==NULL ) {
1515 pst = chunkalloc(sizeof(PST));
1516 pst->type = pst_lcaret;
1517 pst->next = ci->sc->possub;
1518 ci->cachedsc->possub = pst;
1519 }
1520 if ( lc_cnt>pst->u.lcaret.cnt )
1521 pst->u.lcaret.carets = realloc(pst->u.lcaret.carets,lc_cnt*sizeof(int16_t));
1522 for ( i=pst->u.lcaret.cnt; i<lc_cnt; ++i )
1523 pst->u.lcaret.carets[i] = 0;
1524 pst->u.lcaret.cnt = lc_cnt;
1525 }
1526 }
1527
1528 ci->cachedsc->tile_margin = tile_margin;
1529 ci->cachedsc->tile_bounds = tileb;
1530
1531 return( ret );
1532 }
1533
1534 static void CI_ApplyAll(CharInfo *ci) {
1535 int refresh_fvdi = false;
1536 struct splinecharlist *scl;
1537 SplineChar *cached, *sc;
1538 SplineFont *sf = ci->sc->parent;
1539 FontView *fvs;
1540
1541 for ( scl = ci->changes; scl!=NULL; scl=scl->next ) {
1542 cached = scl->sc;
1543 sc = sf->glyphs[cached->orig_pos];
1544 SCPreserveState(sc,2);
1545 if ( strcmp(cached->name,sc->name)!=0 || cached->unicodeenc!=sc->unicodeenc )
1546 refresh_fvdi = 1;
1547 if ( sc->name==NULL || strcmp( sc->name,cached->name )!=0 ) {
1548 if ( sc->name!=NULL )
1549 SFGlyphRenameFixup(sf,sc->name,cached->name,false);
1550 free(sc->glif_name); sc->glif_name = NULL;
1551 free(sc->name); sc->name = copy(cached->name);
1552 sc->namechanged = true;
1553 GlyphHashFree(sf);
1554 }
1555 if ( sc->unicodeenc != cached->unicodeenc ) {
1556 struct splinecharlist *scl;
1557 int layer;
1558 RefChar *ref;
1559 struct altuni *alt;
1560
1561 /* All references need the new unicode value */
1562 for ( scl=sc->dependents; scl!=NULL; scl=scl->next ) {
1563 for ( layer=ly_back; layer<scl->sc->layer_cnt; ++layer )
1564 for ( ref = scl->sc->layers[layer].refs; ref!=NULL; ref=ref->next )
1565 if ( ref->sc==sc )
1566 ref->unicode_enc = cached->unicodeenc;
1567 }
1568 /* If the current unicode enc were in the list of alt unis */
1569 /* the user might have forgotten to remove it. So if s/he did */
1570 /* forget, swap the altuni value with the old value */
1571 for ( alt=cached->altuni; alt!=NULL && (alt->unienc!=cached->unicodeenc || alt->vs!=-1 || alt->fid!=0); alt=alt->next );
1572 if ( alt!=NULL ) /* alt->unienc==new value */
1573 alt->unienc = sc->unicodeenc;
1574 sc->unicodeenc = cached->unicodeenc;
1575 }
1576 free(sc->comment); sc->comment = copy(cached->comment);
1577 sc->unlink_rm_ovrlp_save_undo = cached->unlink_rm_ovrlp_save_undo;
1578 sc->glyph_class = cached->glyph_class;
1579 if ( sc->color != cached->color )
1580 refresh_fvdi = true;
1581 sc->color = cached->color;
1582 free(sc->countermasks);
1583 sc->countermask_cnt = cached->countermask_cnt;
1584 sc->countermasks = cached->countermasks;
1585 cached->countermasks = NULL; cached->countermask_cnt = 0;
1586 sc->tex_height = cached->tex_height;
1587 sc->tex_depth = cached->tex_depth;
1588 sc->italic_correction = cached->italic_correction;
1589 sc->top_accent_horiz = cached->top_accent_horiz;
1590 sc->is_extended_shape = cached->is_extended_shape;
1591 DeviceTableFree(sc->italic_adjusts);
1592 DeviceTableFree(sc->top_accent_adjusts);
1593 sc->italic_adjusts = cached->italic_adjusts;
1594 sc->top_accent_adjusts = cached->top_accent_adjusts;
1595 cached->italic_adjusts = cached->top_accent_adjusts = NULL;
1596 GlyphVariantsFree(sc->horiz_variants);
1597 GlyphVariantsFree(sc->vert_variants);
1598 sc->horiz_variants = cached->horiz_variants;
1599 sc->vert_variants = cached->vert_variants;
1600 cached->horiz_variants = cached->vert_variants = NULL;
1601 AltUniFree(sc->altuni);
1602 sc->altuni = cached->altuni;
1603 cached->altuni = NULL;
1604 sc->lig_caret_cnt_fixed = cached->lig_caret_cnt_fixed;
1605 PSTFree(sc->possub);
1606 sc->possub = cached->possub;
1607 cached->possub = NULL;
1608 KernPairsFree(sc->kerns); KernPairsFree(sc->vkerns);
1609 sc->kerns = cached->kerns; sc->vkerns = cached->vkerns;
1610 cached->kerns = cached->vkerns = NULL;
1611 sc->tile_margin = cached->tile_margin;
1612 sc->tile_bounds = cached->tile_bounds;
1613 if ( !sc->changed ) {
1614 sc->changed = true;
1615 refresh_fvdi = true;
1616 }
1617 SCRefreshTitles(sc);
1618 }
1619 if ( ci->name_change || ci->uni_change ) {
1620 for ( fvs=(FontView *) sf->fv; fvs!=NULL; fvs=(FontView *) fvs->b.nextsame ) {
1621 /* Postscript encodings are by name, others are by unicode */
1622 /* Hence slight differences in when we update the encoding */
1623 if ( (ci->name_change && fvs->b.map->enc->psnames!=NULL ) ||
1624 (ci->uni_change && fvs->b.map->enc->psnames==NULL )) {
1625 fvs->b.map->enc = &custom;
1626 FVSetTitle((FontViewBase *) fvs);
1627 refresh_fvdi = true;
1628 }
1629 }
1630 }
1631 if ( refresh_fvdi ) {
1632 for ( fvs=(FontView *) sf->fv; fvs!=NULL; fvs=(FontView *) fvs->b.nextsame ) {
1633 GDrawRequestExpose(fvs->gw,NULL,false); /* Redraw info area just in case this char is selected */
1634 GDrawRequestExpose(fvs->v,NULL,false); /* Redraw character area in case this char is on screen */
1635 }
1636 }
1637 if ( ci->changes )
1638 sf->changed = true;
1639 }
1640
1641 static void CI_Finish(CharInfo *ci) {
1642 struct splinecharlist *scl, *next;
1643
1644 for ( scl=ci->changes; scl!=NULL; scl=next ) {
1645 next = scl->next;
1646 SplineCharFree(scl->sc);
1647 chunkfree(scl,sizeof(*scl));
1648 }
1649 GDrawDestroyWindow(ci->gw);
1650 }
1651
1652 static int CI_OK(GGadget *g, GEvent *e) {
1653 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1654 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
1655 if ( _CI_OK(ci) ) {
1656 CI_ApplyAll(ci);
1657 CI_Finish(ci);
1658 }
1659 }
1660 return( true );
1661 }
1662
1663 static void CI_BoundsToMargin(CharInfo *ci) {
1664 int err=false;
1665 real margin = GetCalmReal8(ci->gw,CID_TileMargin,NULL,&err);
1666 DBounds b;
1667 char buffer[40];
1668
1669 if ( err )
1670 return;
1671 SplineCharFindBounds(ci->sc,&b);
1672 sprintf( buffer, "%g", (double)(b.minx-margin) );
1673 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_TileBBoxMinX),buffer);
1674 sprintf( buffer, "%g", (double)(b.miny-margin) );
1675 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_TileBBoxMinY),buffer);
1676 sprintf( buffer, "%g", (double)(b.maxx+margin) );
1677 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_TileBBoxMaxX),buffer);
1678 sprintf( buffer, "%g", (double)(b.maxy+margin) );
1679 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_TileBBoxMaxY),buffer);
1680 }
1681
1682 static int CI_TileMarginChange(GGadget *g, GEvent *e) {
1683 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
1684
1685 if ( e->type==et_controlevent && e->u.control.subtype == et_textfocuschanged &&
1686 e->u.control.u.tf_focus.gained_focus )
1687 GGadgetSetChecked(GWidgetGetControl(ci->gw,CID_IsTileMargin),true);
1688 else if ( e->type==et_controlevent && e->u.control.subtype == et_textchanged )
1689 CI_BoundsToMargin(ci);
1690 return( true );
1691 }
1692
1693 /* Generate default settings for the entries in ligature lookup */
1694 static char *LigDefaultStr(int uni, char *name, int alt_lig ) {
1695 const unichar_t *alt=NULL, *pt;
1696 char *components = NULL;
1697 int len;
1698 unichar_t hack[30], *upt;
1699 char buffer[80];
1700
1701 if ( uni==-1 )
1702 /* Nope */;
1703 else if ( isdecompositionnormative(uni) && (alt = unialt(uni))!=NULL ) {
1704 if ( alt[1]=='\0' )
1705 alt = NULL; /* Single replacements aren't ligatures */
1706 else if ( iscombining(alt[1]) && ( alt[2]=='\0' || iscombining(alt[2]))) {
1707 if ( alt_lig != -10 ) /* alt_lig = 10 => mac unicode decomp */
1708 alt = NULL; /* Otherwise, don't treat accented letters as ligatures */
1709 } else if (! isligvulgfrac((uint32_t)(uni)) &&
1710 uni!=0x152 && uni!=0x153 && /* oe ligature should not be standard */
1711 uni!=0x132 && uni!=0x133 && /* nor ij */
1712 (uni<0xfb2a || uni>0xfb4f) && /* Allow hebrew precomposed chars */
1713 uni!=0x215f && /* exclude 1/ */
1714 !((uni>=0x0958 && uni<=0x095f) || uni==0x929 || uni==0x931 || uni==0x934)) {
1715 alt = NULL;
1716 }
1717 }
1718 if ( alt==NULL ) {
1719 if ( name==NULL || alt_lig )
1720 return( NULL );
1721 else
1722 return( AdobeLigatureFormat(name));
1723 }
1724
1725 if ( uni==0xfb03 && alt_lig==1 )
1726 components = copy("ff i");
1727 else if ( uni==0xfb04 && alt_lig==1 )
1728 components = copy("ff l");
1729 else if ( alt!=NULL ) {
1730 if ( alt[1]==0x2044 && (alt[2]==0 || alt[3]==0) && alt_lig==1 ) {
1731 u_strcpy(hack,alt);
1732 hack[1] = '/';
1733 alt = hack;
1734 } else if ( alt_lig>0 )
1735 return( NULL );
1736
1737 if ( isarabisolated(uni) || isarabinitial(uni) || isarabmedial(uni) || isarabfinal(uni) ) {
1738 /* If it is arabic, then convert from the unformed version to the formed */
1739 if ( u_strlen(alt)<sizeof(hack)/sizeof(hack[0])-1 ) {
1740 u_strcpy(hack,alt);
1741 for ( upt=hack ; *upt ; ++upt ) {
1742 /* Make everything medial */
1743 if ( *upt>=0x600 && *upt<=0x6ff )
1744 *upt = arabicform(*upt)->medial;
1745 }
1746 if ( isarabisolated(uni) || isarabfinal(uni) ) {
1747 int len = upt-hack-1;
1748 if ( alt[len]>=0x600 && alt[len]<=0x6ff )
1749 hack[len] = arabicform(alt[len])->final;
1750 }
1751 if ( isarabisolated(uni) || isarabinitial(uni) ) {
1752 if ( alt[0]>=0x600 && alt[0]<=0x6ff )
1753 hack[0] = arabicform(alt[0])->initial;
1754 }
1755 alt = hack;
1756 }
1757 }
1758
1759 components=NULL;
1760 while ( 1 ) {
1761 len = 0;
1762 for ( pt=alt; *pt; ++pt ) {
1763 if ( components==NULL ) {
1764 len += strlen(StdGlyphName(buffer,*pt,ui_none,(NameList *)-1))+1;
1765 } else {
1766 const char *temp = StdGlyphName(buffer,*pt,ui_none,(NameList *)-1);
1767 strcpy(components+len,temp);
1768 len += strlen( temp );
1769 components[len++] = ' ';
1770 }
1771 }
1772 if ( components!=NULL )
1773 break;
1774 components = malloc(len+1);
1775 }
1776 components[len-1] = '\0';
1777 }
1778 return( components );
1779 }
1780
1781 char *AdobeLigatureFormat(char *name) {
1782 /* There are two formats for ligs: <glyph-name>_<glyph-name>{...} or */
1783 /* uni<code><code>{...} (only works for BMP) */
1784 /* I'm not checking to see if all the components are valid */
1785 char *components, *pt, buffer[12];
1786 const char *next;
1787 int len = strlen(name), uni;
1788
1789 if ( strncmp(name,"uni",3)==0 && (len-3)%4==0 && len>7 ) {
1790 pt = name+3;
1791 components = malloc(1); *components = '\0';
1792 while ( *pt ) {
1793 if ( sscanf(pt,"%4x", (unsigned *) &uni )==0 ) {
1794 free(components); components = NULL;
1795 break;
1796 }
1797 next = StdGlyphName(buffer,uni,ui_none,(NameList *)-1);
1798 components = realloc(components,strlen(components) + strlen(next) + 2);
1799 if ( *components!='\0' )
1800 strcat(components," ");
1801 strcat(components,next);
1802 pt += 4;
1803 }
1804 if ( components!=NULL )
1805 return( components );
1806 }
1807
1808 if ( strchr(name,'_')==NULL )
1809 return( NULL );
1810 pt = components = copy(name);
1811 while ( (pt = strchr(pt,'_'))!=NULL )
1812 *pt = ' ';
1813 return( components );
1814 }
1815
1816 /* TODO: see what can be brought-in from is_Ligature_data.h tables, but this */
1817 /* also appears to run various features beyond ligatures and fractions too. */
1818 uint32_t LigTagFromUnicode(int uni) {
1819 int tag = CHR('l','i','g','a'); /* standard */
1820
1821 if ( (uni>=0xbc && uni<=0xbe) || /* latin1 vulgar fractions */
1822 (uni>=0x2150 && uni<=0x215f) ||/* other vulgar fractions */
1823 (uni==0x2189) )
1824 tag = CHR('f','r','a','c'); /* Fraction */
1825 /* hebrew precomposed characters */
1826 else if ( uni>=0xfb2a && uni<=0xfb4e )
1827 tag = CHR('c','c','m','p');
1828 else if ( uni==0xfb4f )
1829 tag = CHR('h','l','i','g');
1830 /* armenian */
1831 else if ( uni>=0xfb13 && uni<=0xfb17 )
1832 tag = CHR('l','i','g','a');
1833 /* devanagari ligatures */
1834 else if ( (uni>=0x0958 && uni<=0x095f) || uni==0x931 || uni==0x934 || uni==0x929 )
1835 tag = CHR('n','u','k','t');
1836 else switch ( uni ) {
1837 case 0xfb05: /* long-s t */
1838 /* This should be 'liga' for long-s+t and 'hlig' for s+t */
1839 tag = CHR('l','i','g','a');
1840 break;
1841 case 0x00c6: case 0x00e6: /* ae, AE */
1842 case 0x0152: case 0x0153: /* oe, OE */
1843 case 0x0132: case 0x0133: /* ij, IJ */
1844 case 0xfb06: /* s t */
1845 tag = CHR('d','l','i','g');
1846 break;
1847 case 0xfefb: case 0xfefc: /* Lam & Alef, required ligs */
1848 tag = CHR('r','l','i','g');
1849 break;
1850 }
1851 return( tag );
1852 }
1853
1854 SplineChar *SuffixCheck(SplineChar *sc,char *suffix) {
1855 SplineChar *alt = NULL;
1856 SplineFont *sf = sc->parent;
1857 char namebuf[200];
1858
1859 if ( *suffix=='.' ) ++suffix;
1860 if ( sf->cidmaster!=NULL ) {
1861 sprintf( namebuf, "%.20s.%d.%.80s", sf->cidmaster->ordering, sc->orig_pos, suffix );
1862 alt = SFGetChar(sf,-1,namebuf);
1863 if ( alt==NULL ) {
1864 sprintf( namebuf, "cid-%d.%.80s", sc->orig_pos, suffix );
1865 alt = SFGetChar(sf,-1,namebuf);
1866 }
1867 }
1868 if ( alt==NULL && sc->unicodeenc!=-1 ) {
1869 sprintf( namebuf, "uni%04X.%.80s", sc->unicodeenc, suffix );
1870 alt = SFGetChar(sf,-1,namebuf);
1871 }
1872 if ( alt==NULL ) {
1873 sprintf( namebuf, "glyph%d.%.80s", sc->orig_pos, suffix );
1874 alt = SFGetChar(sf,-1,namebuf);
1875 }
1876 if ( alt==NULL ) {
1877 sprintf( namebuf, "%.80s.%.80s", sc->name, suffix );
1878 alt = SFGetChar(sf,-1,namebuf);
1879 }
1880 return( alt );
1881 }
1882
1883 static SplineChar *SuffixCheckCase(SplineChar *sc,char *suffix, int cvt2lc ) {
1884 SplineChar *alt = NULL;
1885 SplineFont *sf = sc->parent;
1886 char namebuf[100];
1887
1888 if ( *suffix=='.' ) ++suffix;
1889 if ( sf->cidmaster!=NULL )
1890 return( NULL );
1891
1892 /* Small cap characters are sometimes named "a.sc" */
1893 /* and sometimes "A.small" */
1894 /* So if I want a 'smcp' feature I must convert "a" to "A.small" */
1895 /* And if I want a 'c2sc' feature I must convert "A" to "a.sc" */
1896 if ( cvt2lc ) {
1897 if ( alt==NULL && isupper(sc->unicodeenc)) {
1898 sprintf( namebuf, "uni%04X.%s", tolower(sc->unicodeenc), suffix );
1899 alt = SFGetChar(sf,-1,namebuf);
1900 }
1901 if ( alt==NULL && isupper(*sc->name)) {
1902 sprintf( namebuf, "%c%s.%s", tolower(*sc->name), sc->name+1, suffix );
1903 alt = SFGetChar(sf,-1,namebuf);
1904 }
1905 } else {
1906 if ( alt==NULL && islower(sc->unicodeenc)) {
1907 sprintf( namebuf, "uni%04X.%s", toupper(sc->unicodeenc), suffix );
1908 alt = SFGetChar(sf,-1,namebuf);
1909 }
1910 if ( alt==NULL && islower(*sc->name)) {
1911 sprintf( namebuf, "%c%s.%s", toupper(*sc->name), sc->name+1, suffix );
1912 alt = SFGetChar(sf,-1,namebuf);
1913 }
1914 }
1915 return( alt );
1916 }
1917
1918 void SCLigCaretCheck(SplineChar *sc,int clean) {
1919 PST *pst, *carets=NULL, *prev_carets=NULL, *prev;
1920 int lig_comp_max=0, lc, i;
1921 char *pt;
1922 /* Check to see if this is a ligature character, and if so, does it have */
1923 /* a ligature caret structure. If a lig but no lig caret structure then */
1924 /* create a lig caret struct */
1925 /* This is not entirely sufficient. If we have an old type1 font with afm */
1926 /* file then there was no way of saying "ffi = f + f + i" instead you */
1927 /* said "ffi = ff + i" (only two component ligatures allowed). This means*/
1928 /* we'd get the wrong number of lcaret positions */
1929
1930 if ( sc->lig_caret_cnt_fixed )
1931 return;
1932
1933 for ( pst=sc->possub, prev=NULL; pst!=NULL; prev = pst, pst=pst->next ) {
1934 if ( pst->type == pst_lcaret ) {
1935 if ( carets!=NULL )
1936 IError("Too many ligature caret structures" );
1937 else {
1938 carets = pst;
1939 prev_carets = prev;
1940 }
1941 } else if ( pst->type==pst_ligature ) {
1942 for ( lc=0, pt=pst->u.lig.components; *pt; ++pt )
1943 if ( *pt==' ' ) ++lc;
1944 if ( lc>lig_comp_max )
1945 lig_comp_max = lc;
1946 }
1947 }
1948 if ( lig_comp_max == 0 ) {
1949 if ( clean && carets!=NULL ) {
1950 if ( prev_carets==NULL )
1951 sc->possub = carets->next;
1952 else
1953 prev_carets->next = carets->next;
1954 carets->next = NULL;
1955 PSTFree(carets);
1956 }
1957 return;
1958 }
1959 if ( carets==NULL ) {
1960 carets = chunkalloc(sizeof(PST));
1961 carets->type = pst_lcaret;
1962 carets->subtable = NULL; /* Not relevant here */
1963 carets->next = sc->possub;
1964 sc->possub = carets;
1965 }
1966 if ( carets->u.lcaret.cnt>=lig_comp_max ) {
1967 carets->u.lcaret.cnt = lig_comp_max;
1968 return;
1969 }
1970 if ( carets->u.lcaret.carets==NULL )
1971 carets->u.lcaret.carets = (int16_t *) calloc(lig_comp_max,sizeof(int16_t));
1972 else {
1973 carets->u.lcaret.carets = (int16_t *) realloc(carets->u.lcaret.carets,lig_comp_max*sizeof(int16_t));
1974 for ( i=carets->u.lcaret.cnt; i<lig_comp_max; ++i )
1975 carets->u.lcaret.carets[i] = 0;
1976 }
1977 carets->u.lcaret.cnt = lig_comp_max;
1978 }
1979
1980 static int CI_SName(GGadget *g, GEvent *e) { /* Set From Name */
1981 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1982 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
1983 const unichar_t *ret = _GGadgetGetTitle(GWidgetGetControl(ci->gw,CID_UName));
1984 int i;
1985 char buf[40], *ctemp; unichar_t ubuf[2], *temp;
1986 ctemp = u2utf8_copy(ret);
1987 i = UniFromName(ctemp,ui_none,&custom);
1988 free(ctemp);
1989 if ( i==-1 ) {
1990 /* Adobe says names like uni00410042 represent a ligature (A&B) */
1991 /* (that is "uni" followed by two (or more) 4-digit codes). */
1992 /* But that names outside of BMP should be uXXXX or uXXXXX or uXXXXXX */
1993 if ( ret[0]=='u' && ret[1]!='n' && u_strlen(ret)<=1+6 ) {
1994 unichar_t *end;
1995 i = u_strtol(ret+1,&end,16);
1996 if ( *end )
1997 i = -1;
1998 else /* Make sure it is properly capitalized */
1999 SetNameFromUnicode(ci->gw,CID_UName,i);
2000 }
2001 }
2002
2003 sprintf(buf,"U+%04x", i);
2004 temp = uc_copy(i==-1?"-1":buf);
2005 GGadgetSetTitle(GWidgetGetControl(ci->gw,CID_UValue),temp);
2006 free(temp);
2007
2008 ubuf[0] = i;
2009 if ( i==-1 || i>0xffff )
2010 ubuf[0] = '\0';
2011 ubuf[1] = '\0';
2012 GGadgetSetTitle(GWidgetGetControl(ci->gw,CID_UChar),ubuf);
2013 }
2014 return( true );
2015 }
2016
2017 static int CI_SValue(GGadget *g, GEvent *e) { /* Set From Value */
2018 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
2019 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
2020 unichar_t ubuf[2];
2021 int val;
2022
2023 val = ParseUValue(ci->gw,CID_UValue,false);
2024 if ( val<0 )
2025 return( true );
2026
2027 SetNameFromUnicode(ci->gw,CID_UName,val);
2028
2029 ubuf[0] = val;
2030 if ( val==-1 )
2031 ubuf[0] = '\0';
2032 ubuf[1] = '\0';
2033 GGadgetSetTitle(GWidgetGetControl(ci->gw,CID_UChar),ubuf);
2034 }
2035 return( true );
2036 }
2037
2038 GTextInfo *TIFromName(const char *name) {
2039 GTextInfo *ti = calloc(1,sizeof(GTextInfo));
2040 ti->text = utf82u_copy(name);
2041 ti->fg = COLOR_DEFAULT;
2042 ti->bg = COLOR_DEFAULT;
2043 return( ti );
2044 }
2045
2046 static void CI_SetNameList(CharInfo *ci,int val) {
2047 GGadget *g = GWidgetGetControl(ci->gw,CID_UName);
2048 int cnt;
2049
2050 if ( GGadgetGetUserData(g)==(void *) (intptr_t) val )
2051 return; /* Didn't change */
2052 {
2053 GTextInfo **list = NULL;
2054 char **names = AllGlyphNames(val,ci->sc->parent->for_new_glyphs,ci->sc);
2055
2056 for ( cnt=0; names[cnt]!=NULL; ++cnt );
2057 list = malloc((cnt+1)*sizeof(GTextInfo*));
2058 for ( cnt=0; names[cnt]!=NULL; ++cnt ) {
2059 list[cnt] = TIFromName(names[cnt]);
2060 free(names[cnt]);
2061 }
2062 free(names);
2063 list[cnt] = TIFromName(NULL);
2064 GGadgetSetList(g,list,true);
2065 }
2066 GGadgetSetUserData(g,(void *) (intptr_t) val);
2067 }
2068
2069 static int CI_UValChanged(GGadget *g, GEvent *e) {
2070 if ( e->type==et_controlevent && e->u.control.subtype == et_textchanged ) {
2071 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
2072 const unichar_t *ret = _GGadgetGetTitle(GWidgetGetControl(ci->gw,CID_UValue));
2073 unichar_t *end;
2074 int val;
2075
2076 if (( *ret=='U' || *ret=='u' ) && ret[1]=='+' )
2077 ret += 2;
2078 val = u_strtol(ret,&end,16);
2079 if ( *end=='\0' )
2080 CI_SetNameList(ci,val);
2081 }
2082 return( true );
2083 }
2084
2085 static int CI_CharChanged(GGadget *g, GEvent *e) {
2086 if ( e->type==et_controlevent && e->u.control.subtype == et_textchanged ) {
2087 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
2088 const unichar_t *ret = _GGadgetGetTitle(GWidgetGetControl(ci->gw,CID_UChar));
2089 int val = *ret;
2090 unichar_t *temp, ubuf[2]; char buf[10];
2091
2092 if ( ret[0]=='\0' )
2093 return( true );
2094 else if ( ret[1]!='\0' ) {
2095 ff_post_notice(_("Only a single character allowed"),_("Only a single character allowed"));
2096 ubuf[0] = ret[0];
2097 ubuf[1] = '\0';
2098 GGadgetSetTitle(GWidgetGetControl(ci->gw,CID_UChar),ubuf);
2099 return( true );
2100 }
2101
2102 SetNameFromUnicode(ci->gw,CID_UName,val);
2103 CI_SetNameList(ci,val);
2104
2105 sprintf(buf,"U+%04x", val);
2106 temp = uc_copy(buf);
2107 GGadgetSetTitle(GWidgetGetControl(ci->gw,CID_UValue),temp);
2108 free(temp);
2109 }
2110 return( true );
2111 }
2112
2113 static int CI_CommentChanged(GGadget *g, GEvent *e) {
2114 if ( e->type==et_controlevent && e->u.control.subtype == et_textchanged ) {
2115 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
2116 /* Let's give things with comments a white color. This may not be a good idea */
2117 if ( ci->first && ci->sc->color==COLOR_DEFAULT &&
2118 0==GGadgetGetFirstListSelectedItem(GWidgetGetControl(ci->gw,CID_Color)) )
2119 GGadgetSelectOneListItem(GWidgetGetControl(ci->gw,CID_Color),1);
2120 ci->first = false;
2121 }
2122 return( true );
2123 }
2124
2125 struct devtab_dlg {
2126 int done;
2127 GWindow gw;
2128 GGadget *gme;
2129 DeviceTable devtab;
2130 };
2131
2132 static struct col_init devtabci[] = {
2133 { me_int, NULL, NULL, NULL, N_("Pixel Size") },
2134 { me_int, NULL, NULL, NULL, N_("Correction") },
2135 COL_INIT_EMPTY
2136 };
2137
2138 static void DevTabMatrixInit(struct matrixinit *mi,char *dvstr) {
2139 struct matrix_data *md;
2140 int k, p, cnt;
2141 DeviceTable devtab;
2142
2143 memset(&devtab,0,sizeof(devtab));
2144 DeviceTableParse(&devtab,dvstr);
2145 cnt = 0;
2146 if ( devtab.corrections!=NULL ) {
2147 for ( k=devtab.first_pixel_size; k<=devtab.last_pixel_size; ++k )
2148 if ( devtab.corrections[k-devtab.first_pixel_size]!=0 )
2149 ++cnt;
2150 }
2151
2152 memset(mi,0,sizeof(*mi));
2153 mi->col_cnt = 2;
2154 mi->col_init = devtabci;
2155
2156 md = NULL;
2157 for ( k=0; k<2; ++k ) {
2158 cnt = 0;
2159 if ( devtab.corrections==NULL )
2160 /* Do Nothing */;
2161 else for ( p=devtab.first_pixel_size; p<=devtab.last_pixel_size; ++p ) {
2162 if ( devtab.corrections[p-devtab.first_pixel_size]!=0 ) {
2163 if ( k ) {
2164 md[2*cnt+0].u.md_ival = p;
2165 md[2*cnt+1].u.md_ival = devtab.corrections[p-devtab.first_pixel_size];
2166 }
2167 ++cnt;
2168 }
2169 }
2170 if ( md==NULL )
2171 md = calloc(2*(cnt+10),sizeof(struct matrix_data));
2172 }
2173 mi->matrix_data = md;
2174 mi->initial_row_cnt = cnt;
2175
2176 mi->initrow = NULL;
2177 mi->finishedit = NULL;
2178 mi->candelete = NULL;
2179 mi->popupmenu = NULL;
2180 mi->handle_key = NULL;
2181 mi->bigedittitle = NULL;
2182
2183 free( devtab.corrections );
2184 }
2185
2186 static int DevTabDlg_OK(GGadget *g, GEvent *e) {
2187
2188 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
2189 struct devtab_dlg *dvd = GDrawGetUserData(GGadgetGetWindow(g));
2190 int rows, i, low, high;
2191 struct matrix_data *corrections = GMatrixEditGet(dvd->gme, &rows);
2192
2193 low = high = -1;
2194 for ( i=0; i<rows; ++i ) {
2195 if ( corrections[2*i+1].u.md_ival<-128 || corrections[2*i+1].u.md_ival>127 ) {
2196 ff_post_error(_("Bad correction"),_("The correction on line %d is too big. It must be between -128 and 127"),
2197 i+1 );
2198 return(true);
2199 } else if ( corrections[2*i+0].u.md_ival<0 || corrections[2*i+0].u.md_ival>32767 ) {
2200 gwwv_post_error(_("Bad pixel size"),_("The pixel size on line %d is out of bounds."),
2201 i+1 );
2202 return(true);
2203 }
2204 if ( corrections[2*i+1].u.md_ival!=0 ) {
2205 if ( low==-1 )
2206 low = high = corrections[2*i+0].u.md_ival;
2207 else if ( corrections[2*i+0].u.md_ival<low )
2208 low = corrections[2*i+0].u.md_ival;
2209 else if ( corrections[2*i+0].u.md_ival>high )
2210 high = corrections[2*i+0].u.md_ival;
2211 }
2212 }
2213 memset(&dvd->devtab,0,sizeof(DeviceTable));
2214 if ( low!=-1 ) {
2215 dvd->devtab.first_pixel_size = low;
2216 dvd->devtab.last_pixel_size = high;
2217 dvd->devtab.corrections = calloc(high-low+1,1);
2218 for ( i=0; i<rows; ++i ) {
2219 if ( corrections[2*i+1].u.md_ival!=0 ) {
2220 dvd->devtab.corrections[ corrections[2*i+0].u.md_ival-low ] =
2221 corrections[2*i+1].u.md_ival;
2222 }
2223 }
2224 }
2225 dvd->done = 2;
2226 }
2227 return( true );
2228 }
2229
2230 static int DevTabDlg_Cancel(GGadget *g, GEvent *e) {
2231
2232 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
2233 struct devtab_dlg *dvd = GDrawGetUserData(GGadgetGetWindow(g));
2234 dvd->done = true;
2235 }
2236 return( true );
2237 }
2238
2239 static int devtabdlg_e_h(GWindow gw, GEvent *event) {
2240
2241 if ( event->type==et_close ) {
2242 struct devtab_dlg *dvd = GDrawGetUserData(gw);
2243 dvd->done = true;
2244 } else if ( event->type == et_char ) {
2245 return( false );
2246 }
2247
2248 return( true );
2249 }
2250
2251 char *DevTab_Dlg(GGadget *g, int r, int c) {
2252 int rows, k, j, cols = GMatrixEditGetColCnt(g);
2253 struct matrix_data *strings = GMatrixEditGet(g, &rows);
2254 char *dvstr = strings[cols*r+c].u.md_str;
2255 struct devtab_dlg dvd;
2256 GRect pos;
2257 GWindow gw;
2258 GWindowAttrs wattrs;
2259 GGadgetCreateData gcd[4], boxes[3];
2260 GGadgetCreateData *varray[6], *harray3[8];
2261 GTextInfo label[4];
2262 struct matrixinit mi;
2263
2264 memset(&dvd,0,sizeof(dvd));
2265
2266 memset(&wattrs,0,sizeof(wattrs));
2267 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict;
2268 wattrs.event_masks = ~(1<<et_charup);
2269 wattrs.is_dlg = true;
2270 wattrs.restrict_input_to_me = 1;
2271 wattrs.undercursor = 1;
2272 wattrs.cursor = ct_pointer;
2273 wattrs.utf8_window_title = _("Device Table Adjustments");
2274 pos.x = pos.y = 0;
2275 pos.width =GDrawPointsToPixels(NULL,GGadgetScale(268));
2276 pos.height = GDrawPointsToPixels(NULL,375);
2277 dvd.gw = gw = GDrawCreateTopWindow(NULL,&pos,devtabdlg_e_h,&dvd,&wattrs);
2278
2279 DevTabMatrixInit(&mi,dvstr);
2280
2281 memset(&gcd,0,sizeof(gcd));
2282 memset(&boxes,0,sizeof(boxes));
2283 memset(&label,0,sizeof(label));
2284 k=j=0;
2285 gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = gcd[1].gd.pos.y+14;
2286 gcd[k].gd.flags = gg_enabled | gg_visible;
2287 gcd[k].gd.u.matrix = &mi;
2288 gcd[k].gd.popup_msg = _(
2289 "At small pixel sizes (screen font sizes)\n"
2290 "the rounding errors that occur may be\n"
2291 "extremely ugly. A device table allows\n"
2292 "you to specify adjustments to the rounded\n"
2293 "Every pixel size my have its own adjustment.");
2294 gcd[k].creator = GMatrixEditCreate;
2295 varray[j++] = &gcd[k++]; varray[j++] = NULL;
2296
2297 gcd[k].gd.pos.x = 30-3;
2298 gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_default;
2299 label[k].text = (unichar_t *) _("_OK");
2300 label[k].text_is_1byte = true;
2301 label[k].text_in_resource = true;
2302 gcd[k].gd.label = &label[k];
2303 gcd[k].gd.handle_controlevent = DevTabDlg_OK;
2304 gcd[k++].creator = GButtonCreate;
2305
2306 gcd[k].gd.pos.x = -30;
2307 gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
2308 label[k].text = (unichar_t *) _("_Cancel");
2309 label[k].text_is_1byte = true;
2310 label[k].text_in_resource = true;
2311 gcd[k].gd.label = &label[k];
2312 gcd[k].gd.handle_controlevent = DevTabDlg_Cancel;
2313 gcd[k].gd.cid = CID_Cancel;
2314 gcd[k++].creator = GButtonCreate;
2315
2316 harray3[0] = harray3[2] = harray3[3] = harray3[4] = harray3[6] = GCD_Glue;
2317 harray3[7] = NULL;
2318 harray3[1] = &gcd[k-2]; harray3[5] = &gcd[k-1];
2319
2320 boxes[0].gd.flags = gg_enabled|gg_visible;
2321 boxes[0].gd.u.boxelements = harray3;
2322 boxes[0].creator = GHBoxCreate;
2323 varray[j++] = &boxes[0]; varray[j++] = NULL; varray[j] = NULL;
2324
2325 boxes[1].gd.pos.x = boxes[1].gd.pos.y = 2;
2326 boxes[1].gd.flags = gg_enabled|gg_visible;
2327 boxes[1].gd.u.boxelements = varray;
2328 boxes[1].creator = GHVGroupCreate;
2329
2330 GGadgetsCreate(gw,boxes+1);
2331
2332 free( mi.matrix_data );
2333
2334 dvd.gme = gcd[0].ret;
2335 GMatrixEditSetNewText(gcd[0].ret,S_("PixelSize|New"));
2336 GHVBoxSetExpandableRow(boxes[1].ret,1);
2337 GHVBoxSetExpandableCol(boxes[0].ret,gb_expandgluesame);
2338
2339 GHVBoxFitWindow(boxes[1].ret);
2340
2341 GDrawSetVisible(gw,true);
2342 while ( !dvd.done )
2343 GDrawProcessOneEvent(NULL);
2344 GDrawDestroyWindow(gw);
2345 if ( dvd.done==2 ) {
2346 char *ret;
2347 DevTabToString(&ret,&dvd.devtab);
2348 free(dvd.devtab.corrections);
2349 return( ret );
2350 } else
2351 return( copy(dvstr));
2352 }
2353
2354 static void finishedit(GGadget *g, int r, int c, int wasnew);
2355 static void kernfinishedit(GGadget *g, int r, int c, int wasnew);
2356 static void kerninit(GGadget *g, int r);
2357 static void enable_enum(GGadget *g, GMenuItem *mi, int r, int c);
2358
2359 static struct col_init simplesubsci[] = {
2360 { me_enum , NULL, NULL, enable_enum, N_("Subtable") },
2361 { me_string, NULL, NULL, NULL, N_("Replacement Glyph Name") },
2362 COL_INIT_EMPTY
2363 };
2364 static struct col_init ligatureci[] = {
2365 { me_enum , NULL, NULL, NULL, N_("Subtable") }, /* There can be multiple ligatures for a glyph */
2366 { me_string, NULL, NULL, NULL, N_("Source Glyph Names") },
2367 COL_INIT_EMPTY
2368 };
2369 static struct col_init altsubsci[] = {
2370 { me_enum , NULL, NULL, enable_enum, N_("Subtable") },
2371 { me_string, NULL, NULL, NULL, N_("Replacement Glyph Names") },
2372 COL_INIT_EMPTY
2373 };
2374 static struct col_init multsubsci[] = {
2375 { me_enum , NULL, NULL, enable_enum, N_("Subtable") },
2376 { me_string, NULL, NULL, NULL, N_("Replacement Glyph Names") },
2377 COL_INIT_EMPTY
2378 };
2379 static struct col_init simpleposci[] = {
2380 { me_enum , NULL, NULL, enable_enum, N_("Subtable") },
2381 { me_int, NULL, NULL, NULL, NU_("∆x") }, /* delta-x */
2382 /* GT: "Adjust" here means Device Table based pixel adjustments, an OpenType */
2383 /* GT: concept which allows small corrections for small pixel sizes where */
2384 /* GT: rounding errors (in kerning for example) may smush too glyphs together */
2385 /* GT: or space them too far apart. Generally not a problem for big pixelsizes*/
2386 { me_funcedit, DevTab_Dlg, NULL, NULL, N_("Adjust") },
2387 { me_int, NULL, NULL, NULL, NU_("∆y") }, /* delta-y */
2388 { me_funcedit, DevTab_Dlg, NULL, NULL, N_("Adjust") },
2389 { me_int, NULL, NULL, NULL, NU_("∆x_adv") }, /* delta-x-adv */
2390 { me_funcedit, DevTab_Dlg, NULL, NULL, N_("Adjust") },
2391 { me_int, NULL, NULL, NULL, NU_("∆y_adv") }, /* delta-y-adv */
2392 { me_funcedit, DevTab_Dlg, NULL, NULL, N_("Adjust") },
2393 COL_INIT_EMPTY
2394 };
2395 static struct col_init pairposci[] = {
2396 { me_enum , NULL, NULL, NULL, N_("Subtable") }, /* There can be multiple kern-pairs for a glyph */
2397 { me_string , DevTab_Dlg, NULL, NULL, N_("Second Glyph Name") },
2398 { me_int, NULL, NULL, NULL, NU_("∆x #1") }, /* delta-x */
2399 { me_funcedit, DevTab_Dlg, NULL, NULL, N_("Adjust") },
2400 { me_int, NULL, NULL, NULL, NU_("∆y #1") }, /* delta-y */
2401 { me_funcedit, DevTab_Dlg, NULL, NULL, N_("Adjust") },
2402 { me_int, NULL, NULL, NULL, NU_("∆x_adv #1") }, /* delta-x-adv */
2403 { me_funcedit, DevTab_Dlg, NULL, NULL, N_("Adjust") },
2404 { me_int, NULL, NULL, NULL, NU_("∆y_adv #1") }, /* delta-y-adv */
2405 { me_funcedit, DevTab_Dlg, NULL, NULL, N_("Adjust") },
2406 { me_int, NULL, NULL, NULL, NU_("∆x #2") }, /* delta-x */
2407 { me_funcedit, DevTab_Dlg, NULL, NULL, N_("Adjust") },
2408 { me_int, NULL, NULL, NULL, NU_("∆y #2") }, /* delta-y */
2409 { me_funcedit, DevTab_Dlg, NULL, NULL, N_("Adjust") },
2410 { me_int, NULL, NULL, NULL, NU_("∆x_adv #2") }, /* delta-x-adv */
2411 { me_funcedit, DevTab_Dlg, NULL, NULL, N_("Adjust") },
2412 { me_int, NULL, NULL, NULL, NU_("∆y_adv #2") }, /* delta-y-adv */
2413 { me_funcedit, DevTab_Dlg, NULL, NULL, N_("Adjust") },
2414 COL_INIT_EMPTY
2415 };
2416 static int pst2lookuptype[] = { ot_undef, gpos_single, gpos_pair, gsub_single,
2417 gsub_alternate, gsub_multiple, gsub_ligature, 0 };
2418 struct matrixinit mi[] = {
2419 { sizeof(simpleposci)/sizeof(struct col_init)-1, simpleposci, 0, NULL, NULL, NULL, finishedit, NULL, NULL, NULL },
2420 { sizeof(pairposci)/sizeof(struct col_init)-1, pairposci, 0, NULL, kerninit, NULL, kernfinishedit, NULL, NULL, NULL },
2421 { sizeof(simplesubsci)/sizeof(struct col_init)-1, simplesubsci, 0, NULL, NULL, NULL, finishedit, NULL, NULL, NULL },
2422 { sizeof(altsubsci)/sizeof(struct col_init)-1, altsubsci, 0, NULL, NULL, NULL, finishedit, NULL, NULL, NULL },
2423 { sizeof(multsubsci)/sizeof(struct col_init)-1, multsubsci, 0, NULL, NULL, NULL, finishedit, NULL, NULL, NULL },
2424 { sizeof(ligatureci)/sizeof(struct col_init)-1, ligatureci, 0, NULL, NULL, NULL, finishedit, NULL, NULL, NULL },
2425 MATRIXINIT_EMPTY
2426 };
2427
2428 static void enable_enum(GGadget *g, GMenuItem *mi, int r, int c) {
2429 int i,rows,j;
2430 struct matrix_data *possub;
2431 CharInfo *ci;
2432 int cols;
2433
2434 if ( c!=0 )
2435 return;
2436 ci = GDrawGetUserData(GGadgetGetWindow(g));
2437 possub = GMatrixEditGet(g, &rows);
2438 cols = GMatrixEditGetColCnt(g);
2439
2440 ci->old_sub = (void *) possub[r*cols+0].u.md_ival;
2441
2442 for ( i=0; mi[i].ti.text!=NULL || mi[i].ti.line; ++i ) {
2443 if ( mi[i].ti.line ) /* Lines, and the new entry always enabled */
2444 mi[i].ti.disabled = false;
2445 else if ( mi[i].ti.userdata == NULL )
2446 /* One of the lookup (rather than subtable) entries. leave disabled */;
2447 else if ( mi[i].ti.userdata == (void *) possub[r*cols+0].u.md_ival ) {
2448 mi[i].ti.selected = true; /* Current thing, they can keep on using it */
2449 mi[i].ti.disabled = false;
2450 } else {
2451 for ( j=0; j<rows; ++j )
2452 if ( mi[i].ti.userdata == (void *) possub[j*cols+0].u.md_ival ) {
2453 mi[i].ti.selected = false;
2454 mi[i].ti.disabled = true;
2455 break;
2456 }
2457 if ( j==rows ) { /* This subtable hasn't been used yet */
2458 mi[i].ti.disabled = false;
2459 }
2460 }
2461 }
2462 }
2463
2464 void SCSubtableDefaultSubsCheck(SplineChar *sc, struct lookup_subtable *sub,
2465 struct matrix_data *possub, int col_cnt, int r, int layer) {
2466 FeatureScriptLangList *fl;
2467 int lookup_type = sub->lookup->lookup_type;
2468 SplineChar *alt;
2469 char buffer[8];
2470 int i;
2471 static uint32_t form_tags[] = { CHR('i','n','i','t'), CHR('m','e','d','i'), CHR('f','i','n','a'), CHR('i','s','o','l'), 0 };
2472 real loff, roff;
2473
2474 if ( lookup_type == gsub_single && sub->suffix != NULL ) {
2475 alt = SuffixCheck(sc,sub->suffix);
2476 if ( alt!=NULL ) {
2477 possub[r*col_cnt+1].u.md_str = copy( alt->name );
2478 return;
2479 }
2480 }
2481
2482 for ( fl = sub->lookup->features; fl!=NULL; fl=fl->next ) {
2483 if ( lookup_type == gpos_single ) {
2484 /* These too features are designed to crop off the left and right */
2485 /* side bearings respectively */
2486 if ( fl->featuretag == CHR('l','f','b','d') ) {
2487 GuessOpticalOffset(sc,layer,&loff,&roff,0);
2488 /* Adjust horixontal positioning and horizontal advance by */
2489 /* the left side bearing */
2490 possub[r*col_cnt+SIM_DX].u.md_ival = -loff;
2491 possub[r*col_cnt+SIM_DX_ADV].u.md_ival = -loff;
2492 return;
2493 } else if ( fl->featuretag == CHR('r','t','b','d') ) {
2494 GuessOpticalOffset(sc,layer,&loff,&roff,0);
2495 /* Adjust horizontal advance by right side bearing */
2496 possub[r*col_cnt+SIM_DX_ADV].u.md_ival = -roff;
2497 return;
2498 }
2499 } else if ( lookup_type == gsub_single ) {
2500 alt = NULL;
2501 if ( fl->featuretag == CHR('s','m','c','p') ) {
2502 alt = SuffixCheck(sc,"sc");
2503 if ( alt==NULL )
2504 alt = SuffixCheckCase(sc,"small",false);
2505 } else if ( fl->featuretag == CHR('c','2','s','c') ) {
2506 alt = SuffixCheck(sc,"small");
2507 if ( alt==NULL )
2508 alt = SuffixCheckCase(sc,"sc",true);
2509 } else if ( fl->featuretag == CHR('r','t','l','a') ) {
2510 if ( tomirror(sc->unicodeenc)!=0 )
2511 alt = SFGetChar(sc->parent,tomirror(sc->unicodeenc),NULL);
2512 } else if ( sc->unicodeenc==0x3c3 && fl->featuretag==CHR('f','i','n','a') ) {
2513 /* Greek final sigma */
2514 alt = SFGetChar(sc->parent,0x3c2,NULL);
2515 }
2516 if ( alt==NULL ) {
2517 buffer[0] = fl->featuretag>>24;
2518 buffer[1] = fl->featuretag>>16;
2519 buffer[2] = fl->featuretag>>8;
2520 buffer[3] = fl->featuretag&0xff;
2521 buffer[4] = 0;
2522 alt = SuffixCheck(sc,buffer);
2523 }
2524 if ( alt==NULL && sc->unicodeenc>=0x600 && sc->unicodeenc<0x700 ) {
2525 /* Arabic forms */
2526 for ( i=0; form_tags[i]!=0; ++i ) if ( form_tags[i]==fl->featuretag ) {
2527 if ( (&(arabicform(sc->unicodeenc)->initial))[i]!=0 &&
2528 (&(arabicform(sc->unicodeenc)->initial))[i]!=sc->unicodeenc &&
2529 (alt = SFGetChar(sc->parent,(&(arabicform(sc->unicodeenc)->initial))[i],NULL))!=NULL )
2530 break;
2531 }
2532 }
2533 if ( alt!=NULL ) {
2534 possub[r*col_cnt+1].u.md_str = copy( alt->name );
2535 return;
2536 }
2537 } else if ( lookup_type == gsub_ligature ) {
2538 if ( fl->featuretag == LigTagFromUnicode(sc->unicodeenc) ) {
2539 int alt_index;
2540 for ( alt_index = 0; ; ++alt_index ) {
2541 char *components = LigDefaultStr(sc->unicodeenc,sc->name,alt_index);
2542 if ( components==NULL )
2543 break;
2544 for ( i=0; i<r; ++i ) {
2545 if ( possub[i*col_cnt+0].u.md_ival == (intptr_t) sub &&
2546 strcmp(possub[i*col_cnt+1].u.md_str,components)==0 )
2547 break;
2548 }
2549 if ( i==r ) {
2550 possub[r*col_cnt+1].u.md_str = components;
2551 return;
2552 }
2553 free( components );
2554 }
2555 }
2556 }
2557 }
2558 }
2559
2560 static void finishedit(GGadget *g, int r, int c, int wasnew) {
2561 int rows;
2562 struct matrix_data *possub;
2563 CharInfo *ci;
2564 int sel,cols;
2565 struct lookup_subtable *sub;
2566 struct subtable_data sd;
2567 GTextInfo *ti;
2568
2569 if ( c!=0 )
2570 return;
2571 ci = GDrawGetUserData(GGadgetGetWindow(g));
2572 sel = GTabSetGetSel(GWidgetGetControl(ci->gw,CID_Tabs))-2;
2573 possub = GMatrixEditGet(g, &rows);
2574 cols = GMatrixEditGetColCnt(g);
2575 if ( possub[r*cols+0].u.md_ival!=0 ) {
2576 if ( wasnew )
2577 SCSubtableDefaultSubsCheck(ci->sc,(struct lookup_subtable *) possub[r*cols+0].u.md_ival, possub,
2578 cols, r, ci->def_layer );
2579 return;
2580 }
2581 /* They asked to create a new subtable */
2582
2583 memset(&sd,0,sizeof(sd));
2584 sd.flags = sdf_dontedit;
2585 sub = SFNewLookupSubtableOfType(ci->sc->parent,pst2lookuptype[sel+1],&sd,ci->def_layer);
2586 if ( sub!=NULL ) {
2587 possub[r*cols+0].u.md_ival = (intptr_t) sub;
2588 ti = SFSubtableListOfType(ci->sc->parent, pst2lookuptype[sel+1], false, false);
2589 GMatrixEditSetColumnChoices(g,0,ti);
2590 GTextInfoListFree(ti);
2591 if ( wasnew && ci->cv!=NULL )
2592 SCSubtableDefaultSubsCheck(ci->sc,sub, possub, cols, r, CVLayer((CharViewBase *) (ci->cv)));
2593 } else if ( ci->old_sub!=NULL ) {
2594 /* Restore old value */
2595 possub[r*cols+0].u.md_ival = (intptr_t) ci->old_sub;
2596 } else {
2597 GMatrixEditDeleteRow(g,r);
2598 }
2599 ci->old_sub = NULL;
2600 GGadgetRedraw(g);
2601 }
2602
2603 static void kern_AddKP(void *data,SplineChar *left, SplineChar *right, int off) {
2604 int *kp_offset = data;
2605 *kp_offset = off;
2606 }
2607
2608 static void kernfinishedit(GGadget *g, int r, int c, int wasnew) {
2609 int rows;
2610 struct matrix_data *possub;
2611 CharInfo *ci;
2612 int cols;
2613 struct lookup_subtable *sub;
2614 SplineChar *lefts[2], *rights[2];
2615 int touch, separation, kp_offset=0;
2616 SplineChar *osc;
2617
2618 if ( c==1 ) {
2619 ci = GDrawGetUserData(GGadgetGetWindow(g));
2620 possub = GMatrixEditGet(g, &rows);
2621 cols = GMatrixEditGetColCnt(g);
2622 sub = (struct lookup_subtable *) possub[r*cols+0].u.md_ival;
2623 if ( possub[r*cols+PAIR_DX_ADV1].u.md_ival==0 &&
2624 possub[r*cols+1].u.md_str!=NULL &&
2625 (osc = SFGetChar(ci->sc->parent,-1,possub[r*cols+1].u.md_str))!=NULL ) {
2626 lefts[1] = rights[1] = NULL;
2627 if ( sub->lookup->lookup_flags & pst_r2l ) {
2628 lefts[0] = osc;
2629 rights[0] = ci->sc;
2630 } else {
2631 lefts[0] = ci->sc;
2632 rights[0] = osc;
2633 }
2634 touch = sub->kerning_by_touch;
2635 separation = sub->separation;
2636 if ( separation==0 && !touch )
2637 separation = 15*(osc->parent->ascent+osc->parent->descent)/100;
2638 AutoKern2(osc->parent,ci->def_layer,lefts,rights,sub,
2639 separation,0,touch,0,0, /* Don't bother with minkern or onlyCloser, they asked for this, they get it, whatever it may be */
2640 kern_AddKP,&kp_offset);
2641 possub[r*cols+PAIR_DX_ADV1].u.md_ival=kp_offset;
2642 }
2643 } else
2644 finishedit(g,r,c,wasnew);
2645 }
2646
2647 static int SubHasScript(uint32_t script,struct lookup_subtable *sub) {
2648 FeatureScriptLangList *f;
2649 struct scriptlanglist *s;
2650
2651 if ( sub==NULL )
2652 return(false);
2653 for ( f = sub->lookup->features; f!=NULL; f=f->next ) {
2654 for ( s=f->scripts; s!=NULL; s=s->next ) {
2655 if ( s->script == script )
2656 return( true );
2657 }
2658 }
2659 return( false );
2660 }
2661
2662 static void kerninit(GGadget *g, int r) {
2663 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
2664 GMenuItem *mi = GMatrixEditGetColumnChoices(g,0);
2665 int i,cols,rows;
2666 struct matrix_data *possub;
2667 uint32_t script;
2668
2669 possub = GMatrixEditGet(g, &rows);
2670 cols = GMatrixEditGetColCnt(g);
2671
2672 if ( r!=0 )
2673 possub[r*cols+0].u.md_ival = possub[(r-1)*cols+0].u.md_ival;
2674 else {
2675 script = SCScriptFromUnicode(ci->sc);
2676 for ( i=0; mi[i].ti.line || mi[i].ti.text!=NULL; ++i ) {
2677 if ( SubHasScript(script,(struct lookup_subtable *) mi[i].ti.userdata ) )
2678 break;
2679 }
2680 if ( mi[i].ti.line || mi[i].ti.text!=NULL )
2681 possub[r*cols+0].u.md_ival = (intptr_t) mi[i].ti.userdata;
2682 }
2683 }
2684
2685 static void CI_DoHideUnusedSingle(CharInfo *ci) {
2686 GGadget *pstk = GWidgetGetControl(ci->gw,CID_List+(pst_position-1)*100);
2687 int rows, cols = GMatrixEditGetColCnt(pstk);
2688 struct matrix_data *old = GMatrixEditGet(pstk,&rows);
2689 uint8_t cols_used[20];
2690 int r, col, tot;
2691
2692 if ( lookup_hideunused ) {
2693 memset(cols_used,0,sizeof(cols_used));
2694 for ( r=0; r<rows; ++r ) {
2695 for ( col=1; col<cols; col+=2 ) {
2696 if ( old[cols*r+col].u.md_ival!=0 )
2697 cols_used[col] = true;
2698 if ( old[cols*r+col+1].u.md_str!=NULL && *old[cols*r+col+1].u.md_str!='\0' )
2699 cols_used[col+1] = true;
2700 }
2701 }
2702 for ( col=1, tot=0; col<cols; ++col )
2703 tot += cols_used[col];
2704 /* If no columns used (no info yet, all info is to preempt a kernclass and sets to 0) */
2705 /* then show what we expect to be the default column for this kerning mode*/
2706 if ( tot==0 ) {
2707 if ( strstr(ci->sc->name,".vert")!=NULL || strstr(ci->sc->name,".vrt2")!=NULL )
2708 cols_used[SIM_DY] = true;
2709 else
2710 cols_used[SIM_DX] = true;
2711 }
2712 for ( col=1; col<cols; ++col )
2713 GMatrixEditShowColumn(pstk,col,cols_used[col]);
2714 } else {
2715 for ( col=1; col<cols; ++col )
2716 GMatrixEditShowColumn(pstk,col,true);
2717 }
2718 GWidgetToDesiredSize(ci->gw);
2719
2720 GGadgetRedraw(pstk);
2721 }
2722
2723 static void CI_DoHideUnusedPair(CharInfo *ci) {
2724 GGadget *pstk = GWidgetGetControl(ci->gw,CID_List+(pst_pair-1)*100);
2725 int rows, cols = GMatrixEditGetColCnt(pstk);
2726 struct matrix_data *old = GMatrixEditGet(pstk,&rows);
2727 uint8_t cols_used[20];
2728 int r, col, tot;
2729
2730 if ( lookup_hideunused ) {
2731 memset(cols_used,0,sizeof(cols_used));
2732 for ( r=0; r<rows; ++r ) {
2733 for ( col=2; col<cols; col+=2 ) {
2734 if ( old[cols*r+col].u.md_ival!=0 )
2735 cols_used[col] = true;
2736 if ( old[cols*r+col+1].u.md_str!=NULL && *old[cols*r+col+1].u.md_str!='\0' )
2737 cols_used[col+1] = true;
2738 }
2739 }
2740 for ( col=2, tot=0; col<cols; ++col )
2741 tot += cols_used[col];
2742 /* If no columns used (no info yet, all info is to preempt a kernclass and sets to 0) */
2743 /* then show what we expect to be the default column for this kerning mode*/
2744 if ( tot==0 ) {
2745 if ( strstr(ci->sc->name,".vert")!=NULL || strstr(ci->sc->name,".vrt2")!=NULL )
2746 cols_used[PAIR_DY_ADV1] = true;
2747 else if ( SCRightToLeft(ci->sc))
2748 cols_used[PAIR_DX_ADV2] = true;
2749 else
2750 cols_used[PAIR_DX_ADV1] = true;
2751 }
2752 for ( col=2; col<cols; ++col )
2753 GMatrixEditShowColumn(pstk,col,cols_used[col]);
2754 } else {
2755 for ( col=2; col<cols; ++col )
2756 GMatrixEditShowColumn(pstk,col,true);
2757 }
2758 GWidgetToDesiredSize(ci->gw);
2759
2760 GGadgetRedraw(pstk);
2761 }
2762
2763 static int CI_HideUnusedPair(GGadget *g, GEvent *e) {
2764 if ( e->type==et_controlevent && e->u.control.subtype == et_radiochanged ) {
2765 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
2766 lookup_hideunused = GGadgetIsChecked(g);
2767 CI_DoHideUnusedPair(ci);
2768 GGadgetRedraw(GWidgetGetControl(ci->gw,CID_List+(pst_pair-1)*100));
2769 }
2770 return( true );
2771 }
2772
2773 static int CI_HideUnusedSingle(GGadget *g, GEvent *e) {
2774 if ( e->type==et_controlevent && e->u.control.subtype == et_radiochanged ) {
2775 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
2776 lookup_hideunused = GGadgetIsChecked(g);
2777 CI_DoHideUnusedSingle(ci);
2778 GGadgetRedraw(GWidgetGetControl(ci->gw,CID_List+(pst_position-1)*100));
2779 }
2780 return( true );
2781 }
2782
2783 static void CI_FreeKernedImage(const void *_ci, GImage *img) {
2784 GImageDestroy(img);
2785 }
2786
2787 static const int kern_popup_size = 100;
2788
2789 static BDFChar *Rasterize(SplineChar *sc,int def_layer) {
2790 void *freetypecontext=NULL;
2791 BDFChar *ret;
2792
2793 freetypecontext = FreeTypeFontContext(sc->parent,sc,sc->parent->fv,def_layer);
2794 if ( freetypecontext!=NULL ) {
2795 ret = SplineCharFreeTypeRasterize(freetypecontext,sc->orig_pos,kern_popup_size,72,8);
2796 FreeTypeFreeContext(freetypecontext);
2797 } else
2798 ret = SplineCharAntiAlias(sc,def_layer,kern_popup_size,4);
2799 return( ret );
2800 }
2801
2802 static GImage *CI_GetKernedImage(const void *_ci) {
2803 CharInfo *ci = (CharInfo *) _ci;
2804 GGadget *pstk = GWidgetGetControl(ci->gw,CID_List+(pst_pair-1)*100);
2805 int rows, cols = GMatrixEditGetColCnt(pstk);
2806 struct matrix_data *old = GMatrixEditGet(pstk,&rows);
2807 SplineChar *othersc = SFGetChar(ci->sc->parent,-1, old[cols*ci->r+1].u.md_str);
2808 BDFChar *me, *other;
2809 double scale = kern_popup_size/(double) (ci->sc->parent->ascent+ci->sc->parent->descent);
2810 int kern;
2811 int width, height, miny, maxy, minx, maxx;
2812 GImage *img;
2813 struct _GImage *base;
2814 Color fg, bg;
2815 int l,clut_scale;
2816 int x,y, xoffset, yoffset, coff1, coff2;
2817 struct lookup_subtable *sub = (struct lookup_subtable *) (old[cols*ci->r+0].u.md_ival);
2818
2819 if ( othersc==NULL )
2820 return( NULL );
2821 me = Rasterize(ci->sc,ci->def_layer);
2822 other = Rasterize(othersc,ci->def_layer);
2823 if ( sub->vertical_kerning ) {
2824 int vwidth = rint(ci->sc->vwidth*scale);
2825 kern = rint( old[cols*ci->r+PAIR_DY_ADV1].u.md_ival*scale );
2826 miny = me->ymin + rint(old[cols*ci->r+PAIR_DY1].u.md_ival*scale);
2827 maxy = me->ymax + rint(old[cols*ci->r+PAIR_DY1].u.md_ival*scale);
2828 if ( miny > vwidth + kern + rint(old[cols*ci->r+PAIR_DY2].u.md_ival*scale) + other->ymin )
2829 miny = vwidth + kern + rint(old[cols*ci->r+PAIR_DY2].u.md_ival*scale) + other->ymin;
2830 if ( maxy < vwidth + kern + rint(old[cols*ci->r+PAIR_DY2].u.md_ival*scale) + other->ymax )
2831 maxy = vwidth + kern + rint(old[cols*ci->r+PAIR_DY2].u.md_ival*scale) + other->ymax;
2832 height = maxy - miny + 2;
2833 minx = me->xmin + rint(old[cols*ci->r+PAIR_DX1].u.md_ival*scale); maxx = me->xmax + rint(old[cols*ci->r+PAIR_DX1].u.md_ival*scale);
2834 if ( minx>other->xmin + rint(old[cols*ci->r+PAIR_DX2].u.md_ival*scale) ) minx = other->xmin+ rint(old[cols*ci->r+PAIR_DX2].u.md_ival*scale) ;
2835 if ( maxx<other->xmax + rint(old[cols*ci->r+PAIR_DX2].u.md_ival*scale) ) maxx = other->xmax+ rint(old[cols*ci->r+PAIR_DX2].u.md_ival*scale) ;
2836
2837 img = GImageCreate(it_index,maxx-minx+2,height);
2838 base = img->u.image;
2839 memset(base->data,'\0',base->bytes_per_line*base->height);
2840
2841 yoffset = 1 + maxy - vwidth - kern - rint(old[cols*ci->r+PAIR_DY1].u.md_ival*scale);
2842 xoffset = 1 - minx + rint(old[cols*ci->r+PAIR_DX1].u.md_ival*scale);
2843 for ( y=me->ymin; y<=me->ymax; ++y ) {
2844 for ( x=me->xmin; x<=me->xmax; ++x ) {
2845 base->data[(yoffset-y)*base->bytes_per_line + (x+xoffset)] =
2846 me->bitmap[(me->ymax-y)*me->bytes_per_line + (x-me->xmin)];
2847 }
2848 }
2849 yoffset = 1 + maxy - rint(old[cols*ci->r+PAIR_DY2].u.md_ival*scale);
2850 xoffset = 1 - minx + rint(old[cols*ci->r+PAIR_DX2].u.md_ival*scale);
2851 for ( y=other->ymin; y<=other->ymax; ++y ) {
2852 for ( x=other->xmin; x<=other->xmax; ++x ) {
2853 int n = other->bitmap[(other->ymax-y)*other->bytes_per_line + (x-other->xmin)];
2854 if ( n>base->data[(yoffset-y)*base->bytes_per_line + (x+xoffset)] )
2855 base->data[(yoffset-y)*base->bytes_per_line + (x+xoffset)] = n;
2856 }
2857 }
2858 } else {
2859 coff1 = coff2 = 0;
2860 if ( sub->lookup->lookup_flags & pst_r2l ) {
2861 BDFChar *temp = me;
2862 me = other;
2863 other = temp;
2864 coff1 = 8; coff2 = -8;
2865 }
2866 kern = rint( old[cols*ci->r+PAIR_DX_ADV1+coff1].u.md_ival*scale );
2867 minx = me->xmin + rint(old[cols*ci->r+PAIR_DX1+coff1].u.md_ival*scale);
2868 maxx = me->xmax + rint(old[cols*ci->r+PAIR_DX1+coff1].u.md_ival*scale);
2869 if ( minx > me->width + kern + rint(old[cols*ci->r+PAIR_DX2+coff2].u.md_ival*scale) + other->xmin )
2870 minx = me->width + kern + rint(old[cols*ci->r+PAIR_DX2+coff2].u.md_ival*scale) + other->xmin;
2871 if ( maxx < me->width + kern + rint(old[cols*ci->r+PAIR_DX2+coff2].u.md_ival*scale) + other->xmax )
2872 maxx = me->width + kern + rint(old[cols*ci->r+PAIR_DX2+coff2].u.md_ival*scale) + other->xmax;
2873 width = maxx - minx + 2;
2874 miny = me->ymin + rint(old[cols*ci->r+PAIR_DY1+coff1].u.md_ival*scale); maxy = me->ymax + rint(old[cols*ci->r+PAIR_DY1+coff1].u.md_ival*scale);
2875 if ( miny>other->ymin + rint(old[cols*ci->r+PAIR_DY2+coff2].u.md_ival*scale) ) miny = other->ymin+ rint(old[cols*ci->r+PAIR_DY2+coff2].u.md_ival*scale) ;
2876 if ( maxy<other->ymax + rint(old[cols*ci->r+PAIR_DY2+coff2].u.md_ival*scale) ) maxy = other->ymax+ rint(old[cols*ci->r+PAIR_DY2+coff2].u.md_ival*scale) ;
2877
2878 img = GImageCreate(it_index,width,maxy-miny+2);
2879 base = img->u.image;
2880 memset(base->data,'\0',base->bytes_per_line*base->height);
2881
2882 xoffset = rint(old[cols*ci->r+PAIR_DX1+coff1].u.md_ival*scale) + 1 - minx;
2883 yoffset = 1 + maxy - rint(old[cols*ci->r+PAIR_DY1+coff1].u.md_ival*scale);
2884 for ( y=me->ymin; y<=me->ymax; ++y ) {
2885 for ( x=me->xmin; x<=me->xmax; ++x ) {
2886 base->data[(yoffset-y)*base->bytes_per_line + (x+xoffset)] =
2887 me->bitmap[(me->ymax-y)*me->bytes_per_line + (x-me->xmin)];
2888 }
2889 }
2890 xoffset = 1 - minx + me->width + kern - rint(old[cols*ci->r+PAIR_DX2+coff2].u.md_ival*scale);
2891 yoffset = 1 + maxy - rint(old[cols*ci->r+PAIR_DY2+coff2].u.md_ival*scale);
2892 for ( y=other->ymin; y<=other->ymax; ++y ) {
2893 for ( x=other->xmin; x<=other->xmax; ++x ) {
2894 int n = other->bitmap[(other->ymax-y)*other->bytes_per_line + (x-other->xmin)];
2895 if ( n>base->data[(yoffset-y)*base->bytes_per_line + (x+xoffset)] )
2896 base->data[(yoffset-y)*base->bytes_per_line + (x+xoffset)] = n;
2897 }
2898 }
2899 }
2900 memset(base->clut,'\0',sizeof(*base->clut));
2901 bg = GDrawGetDefaultBackground(NULL);
2902 fg = GDrawGetDefaultForeground(NULL);
2903 clut_scale = me->depth == 8 ? 8 : 4;
2904 base->clut->clut_len = 1<<clut_scale;
2905 for ( l=0; l<(1<<clut_scale); ++l )
2906 base->clut->clut[l] =
2907 COLOR_CREATE(
2908 COLOR_RED(bg) + (l*(COLOR_RED(fg)-COLOR_RED(bg)))/((1<<clut_scale)-1),
2909 COLOR_GREEN(bg) + (l*(COLOR_GREEN(fg)-COLOR_GREEN(bg)))/((1<<clut_scale)-1),
2910 COLOR_BLUE(bg) + (l*(COLOR_BLUE(fg)-COLOR_BLUE(bg)))/((1<<clut_scale)-1) );
2911 BDFCharFree(me);
2912 BDFCharFree(other);
2913 return( img );
2914 }
2915
2916 /* Draws an image of a glyph with a vertical bar down the middle. */
2917 /* used to show italic correction position (we also dot in the width line) */
2918 /* and top accent horizontal position for the MATH table */
2919 GImage *SC_GetLinedImage(SplineChar *sc, int def_layer, int pos, int is_italic_cor) {
2920 BDFChar *me;
2921 double scale = kern_popup_size/(double) (sc->parent->ascent+sc->parent->descent);
2922 int miny, maxy, minx, maxx;
2923 GImage *img;
2924 struct _GImage *base;
2925 Color fg, bg;
2926 int l,clut_scale;
2927 int x,y, xoffset, yoffset;
2928 int pixel;
2929
2930 if ( is_italic_cor )
2931 pos += sc->width;
2932 pos = rint( pos*scale );
2933 if ( pos<-100 || pos>100 )
2934 return( NULL );
2935 me = Rasterize(sc,def_layer);
2936 if ( pos<me->xmin-10 || pos>me->xmax+30 ) {
2937 BDFCharFree(me);
2938 return( NULL );
2939 }
2940 if ( (minx=me->xmin)>0 ) minx = 0;
2941 if ( (maxx=me->xmax)<me->width ) maxx = me->width;
2942 if ( pos<minx ) minx = pos-2;
2943 if ( pos>maxx ) maxx = pos+2;
2944 miny = me->ymin - 4;
2945 maxy = me->ymax + 4;
2946
2947 pixel = me->depth == 8 ? 0xff : 0xf;
2948
2949 img = GImageCreate(it_index,maxx-minx+2,maxy-miny+2);
2950 base = img->u.image;
2951 memset(base->data,'\0',base->bytes_per_line*base->height);
2952
2953 xoffset = 1 - minx;
2954 yoffset = 1 + maxy;
2955 for ( y=me->ymin; y<=me->ymax; ++y ) {
2956 for ( x=me->xmin; x<=me->xmax; ++x ) {
2957 base->data[(yoffset-y)*base->bytes_per_line + (x+xoffset)] =
2958 me->bitmap[(me->ymax-y)*me->bytes_per_line + (x-me->xmin)];
2959 }
2960 }
2961 for ( y=miny; y<=maxy; ++y ) {
2962 base->data[(yoffset-y)*base->bytes_per_line + (pos+xoffset)] = pixel;
2963 if ( is_italic_cor && (y&1 ))
2964 base->data[(yoffset-y)*base->bytes_per_line + (me->width+xoffset)] = pixel;
2965 }
2966
2967 memset(base->clut,'\0',sizeof(*base->clut));
2968 bg = GDrawGetDefaultBackground(NULL);
2969 fg = GDrawGetDefaultForeground(NULL);
2970 clut_scale = me->depth == 8 ? 8 : 4;
2971 base->clut->clut_len = 1<<clut_scale;
2972 for ( l=0; l<(1<<clut_scale); ++l )
2973 base->clut->clut[l] =
2974 COLOR_CREATE(
2975 COLOR_RED(bg) + (l*(COLOR_RED(fg)-COLOR_RED(bg)))/((1<<clut_scale)-1),
2976 COLOR_GREEN(bg) + (l*(COLOR_GREEN(fg)-COLOR_GREEN(bg)))/((1<<clut_scale)-1),
2977 COLOR_BLUE(bg) + (l*(COLOR_BLUE(fg)-COLOR_BLUE(bg)))/((1<<clut_scale)-1) );
2978 BDFCharFree(me);
2979 return( img );
2980 }
2981
2982 // This defines the width of the arrow that gets drawn
2983 #define ICON_WIDTH 15
2984
2985 GImage *GV_GetConstructedImage(SplineChar *sc,int def_layer,struct glyphvariants *gv, int is_horiz) {
2986 SplineFont *sf = sc->parent;
2987 BDFChar *me, **others;
2988 double scale = kern_popup_size/(double) (sf->ascent+sf->descent);
2989 GImage *img;
2990 struct _GImage *base;
2991 Color fg, bg;
2992 int l,clut_scale;
2993 int x,y;
2994 int i,j;
2995
2996 if ( gv==NULL || gv->part_cnt==0 )
2997 return( NULL );
2998 me = Rasterize(sc,def_layer);
2999 others = malloc(gv->part_cnt*sizeof(BDFChar *));
3000 for ( i=0; i<gv->part_cnt; ++i ) {
3001 SplineChar *othersc = SFGetChar(sf,-1,gv->parts[i].component);
3002 if ( othersc==NULL ) {
3003 for ( j=0; j<i; ++j )
3004 BDFCharFree(others[j]);
3005 free(others);
3006 return( NULL );
3007 }
3008 others[i] = Rasterize(othersc,def_layer);
3009 }
3010 if ( is_horiz ) {
3011 int ymin, ymax;
3012 int width, xoff;
3013
3014 for ( i=1; i<gv->part_cnt; ++i ) { /* Normalize all but first. Makes construction easier */
3015 others[i]->xmax -= others[i]->xmin;
3016 others[i]->xmin = 0;
3017 }
3018 xoff = me->xmin<0 ? -me->xmin : 0;
3019 width = xoff + me->width + ICON_WIDTH;
3020 ymin = me->ymin; ymax = me->ymax;
3021 for ( i=0; i<gv->part_cnt; ++i ) {
3022 int overlap;
3023 if ( i==gv->part_cnt-1 )
3024 overlap=0;
3025 else {
3026 overlap = gv->parts[i].endConnectorLength>gv->parts[i+1].startConnectorLength ?
3027 gv->parts[i+1].startConnectorLength :
3028 gv->parts[i].endConnectorLength;
3029 overlap = rint( scale*overlap );
3030 }
3031 width += rint(gv->parts[i].fullAdvance*scale) - overlap + others[i]->xmin/* Only does anything if i==0, then it normalizes the rest to the same baseline */;
3032 if ( others[i]->ymin<ymin ) ymin = others[i]->ymin;
3033 if ( others[i]->ymax>ymax ) ymax = others[i]->ymax;
3034 }
3035 if ( ymax<=ICON_WIDTH ) ymax = ICON_WIDTH;
3036 if ( ymin>0 ) ymin = 0;
3037 img = GImageCreate(it_index,width+10,ymax-ymin+2);
3038 base = img->u.image;
3039 memset(base->data,'\0',base->bytes_per_line*base->height);
3040
3041 ++xoff; /* One pixel margin */
3042
3043 for ( y=me->ymin; y<=me->ymax; ++y ) {
3044 for ( x=me->xmin; x<=me->xmax; ++x ) {
3045 base->data[(1+ymax-y)*base->bytes_per_line + (x+xoff)] =
3046 me->bitmap[(me->ymax-y)*me->bytes_per_line + (x-me->xmin)];
3047 }
3048 }
3049 xoff += me->width;
3050 {
3051 int pixel = me->depth == 8 ? 0xff : 0xf;
3052 for ( j = -1; j<2; j+=2 ) {
3053 if ( me->ymax<-me->ymin )
3054 y = (me->ymax+me->ymin)/2;
3055 else
3056 y = 1+me->ymax/2;
3057 y = ymax-y + j*2;
3058 for ( x=1; x<ICON_WIDTH-5; ++x )
3059 base->data[y*base->bytes_per_line + (x+xoff)] = pixel;
3060 for ( x=ICON_WIDTH-8; x<ICON_WIDTH-1; ++x )
3061 base->data[(y+j*(ICON_WIDTH-4-x))*base->bytes_per_line + (x+xoff)] = pixel;
3062 }
3063 xoff += ICON_WIDTH;
3064 }
3065 for ( i=0; i<gv->part_cnt; ++i ) {
3066 int overlap;
3067 if ( i==gv->part_cnt-1 )
3068 overlap=0;
3069 else {
3070 overlap = gv->parts[i].endConnectorLength>gv->parts[i+1].startConnectorLength ?
3071 gv->parts[i+1].startConnectorLength :
3072 gv->parts[i].endConnectorLength;
3073 overlap = rint( scale*overlap );
3074 }
3075 for ( y=others[i]->ymin; y<=others[i]->ymax; ++y ) {
3076 for ( x=others[i]->xmin; x<=others[i]->xmax; ++x ) {
3077 int n = others[i]->bitmap[(others[i]->ymax-y)*others[i]->bytes_per_line + (x-others[i]->xmin)];
3078 if ( n>base->data[(ymax-y)*base->bytes_per_line + (x+xoff)] )
3079 base->data[(ymax-y)*base->bytes_per_line + (x+xoff)] = n;
3080 }
3081 }
3082 xoff += rint(gv->parts[i].fullAdvance*scale) - overlap + others[i]->xmin/* Only does anything if i==0, then it normalizes the rest to the same baseline */;
3083 }
3084 } else {
3085 int xmin, xmax, ymin, ymax;
3086 int yoff, xoff, width;
3087
3088 for ( i=1; i<gv->part_cnt; ++i ) { /* Normalize all but first. Makes construction easier */
3089 others[i]->ymax -= others[i]->ymin;
3090 others[i]->ymin = 0;
3091 }
3092
3093 xoff = me->xmin<0 ? -me->xmin : 0;
3094 width = xoff + me->width + ICON_WIDTH;
3095 ymin = me->ymin; ymax = me->ymax;
3096 xmin = xmax = 0;
3097 yoff = 0;
3098 for ( i=0; i<gv->part_cnt; ++i ) {
3099 int overlap;
3100 if ( i==gv->part_cnt-1 )
3101 overlap=0;
3102 else {
3103 overlap = gv->parts[i].endConnectorLength>gv->parts[i+1].startConnectorLength ?
3104 gv->parts[i+1].startConnectorLength :
3105 gv->parts[i].endConnectorLength;
3106 overlap = rint( scale*overlap );
3107 }
3108 if ( ymin>others[i]->ymin+yoff ) ymin = others[i]->ymin+yoff;
3109 if ( ymax<others[i]->ymax+yoff ) ymax = others[i]->ymax+yoff;
3110 yoff += rint(gv->parts[i].fullAdvance*scale) - overlap + others[i]->ymin/* Only does anything if i==0, then it normalizes the rest to the same baseline */;
3111 if ( others[i]->xmin<xmin ) xmin = others[i]->xmin;
3112 if ( others[i]->xmax>xmax ) xmax = others[i]->xmax;
3113 }
3114 if ( xmin<-width ) {
3115 xoff = -xmin-width;
3116 width = -xmin;
3117 }
3118 if ( xmax>0 )
3119 width += xmax;
3120 if ( ymax<=ICON_WIDTH ) ymax = ICON_WIDTH;
3121 if ( ymin>0 ) ymin = 0;
3122 img = GImageCreate(it_index,width+2,ymax-ymin+2);
3123 base = img->u.image;
3124 memset(base->data,'\0',base->bytes_per_line*base->height);
3125
3126 ++xoff; /* One pixel margin */
3127
3128 for ( y=me->ymin; y<=me->ymax; ++y ) {
3129 for ( x=me->xmin; x<=me->xmax; ++x ) {
3130 base->data[(1+ymax-y)*base->bytes_per_line + (x+xoff)] =
3131 me->bitmap[(me->ymax-y)*me->bytes_per_line + (x-me->xmin)];
3132 }
3133 }
3134 xoff += me->width;
3135 {
3136 int pixel = me->depth == 8 ? 0xff : 0xf;
3137 for ( j = -1; j<2; j+=2 ) {
3138 if ( me->ymax<-me->ymin )
3139 y = (me->ymax+me->ymin)/2;
3140 else
3141 y = 1+me->ymax/2;
3142 // Figure out the centerpoint of the arrow
3143 y = ymax - y;
3144 if (y > (ymax - ymin - ICON_WIDTH/2)) {
3145 // Too far down; shift up to make it fit
3146 y = ymax - ymin - ICON_WIDTH/2;
3147 }
3148 y += j*2;
3149 for ( x=1; x<ICON_WIDTH-5; ++x )
3150 base->data[y*base->bytes_per_line + (x+xoff)] = pixel;
3151 for ( x=ICON_WIDTH-8; x<ICON_WIDTH-1; ++x )
3152 base->data[(y+j*(ICON_WIDTH-4-x))*base->bytes_per_line + (x+xoff)] = pixel;
3153 }
3154 xoff += ICON_WIDTH;
3155 }
3156 yoff=0;
3157 for ( i=0; i<gv->part_cnt; ++i ) {
3158 int overlap;
3159 if ( i==gv->part_cnt-1 )
3160 overlap=0;
3161 else {
3162 overlap = gv->parts[i].endConnectorLength>gv->parts[i+1].startConnectorLength ?
3163 gv->parts[i+1].startConnectorLength :
3164 gv->parts[i].endConnectorLength;
3165 overlap = rint( scale*overlap );
3166 }
3167 for ( y=others[i]->ymin; y<=others[i]->ymax; ++y ) {
3168 for ( x=others[i]->xmin; x<=others[i]->xmax; ++x ) {
3169 int n = others[i]->bitmap[(others[i]->ymax-y)*others[i]->bytes_per_line + (x-others[i]->xmin)];
3170 if ( n>base->data[(ymax-y-yoff)*base->bytes_per_line + (x+xoff)] )
3171 base->data[(ymax-y-yoff)*base->bytes_per_line + (x+xoff)] = n;
3172 }
3173 }
3174 yoff += rint(gv->parts[i].fullAdvance*scale) - overlap + others[i]->ymin/* Only does anything if i==0, then it normalizes the rest to the same baseline */;
3175 }
3176 }
3177 for ( i=0; i<gv->part_cnt; ++i )
3178 BDFCharFree(others[i]);
3179 free(others);
3180
3181 memset(base->clut,'\0',sizeof(*base->clut));
3182 bg = GDrawGetDefaultBackground(NULL);
3183 fg = GDrawGetDefaultForeground(NULL);
3184 clut_scale = me->depth == 8 ? 8 : 4;
3185 BDFCharFree(me);
3186 base->clut->clut_len = 1<<clut_scale;
3187 for ( l=0; l<(1<<clut_scale); ++l )
3188 base->clut->clut[l] =
3189 COLOR_CREATE(
3190 COLOR_RED(bg) + (l*(COLOR_RED(fg)-COLOR_RED(bg)))/((1<<clut_scale)-1),
3191 COLOR_GREEN(bg) + (l*(COLOR_GREEN(fg)-COLOR_GREEN(bg)))/((1<<clut_scale)-1),
3192 COLOR_BLUE(bg) + (l*(COLOR_BLUE(fg)-COLOR_BLUE(bg)))/((1<<clut_scale)-1) );
3193 return( img );
3194 }
3195
3196 static GImage *CI_GetConstructedImage(const void *_ci) {
3197 CharInfo *ci = (CharInfo *) _ci;
3198 GImage *ret;
3199 int is_horiz = GTabSetGetSel(GWidgetGetControl(ci->gw,CID_Tabs))-ci->vert_aspect;
3200 struct glyphvariants *gv;
3201
3202 gv = CI_ParseVariants(NULL,ci,is_horiz,NULL,0,true);
3203
3204 ret = GV_GetConstructedImage(ci->sc,ci->def_layer,gv,is_horiz);
3205 GlyphVariantsFree(gv);
3206 return( ret );
3207 }
3208
3209 GImage *NameList_GetImage(SplineFont *sf,SplineChar *sc,int def_layer,
3210 char *namelist, int isliga ) {
3211 BDFChar *me, **extras;
3212 int width, xmin, xmax, ymin, ymax;
3213 GImage *img;
3214 struct _GImage *base;
3215 Color fg, bg;
3216 int l,clut_scale;
3217 int x,y;
3218 SplineChar *other;
3219 int extracnt;
3220 int i,j;
3221 char *subs = namelist, *pt, *start;
3222 int ch;
3223
3224 if ( sc==NULL || sf==NULL || namelist==NULL )
3225 return( NULL );
3226 me = Rasterize(sc,def_layer);
3227 ymin = me->ymin; ymax = me->ymax;
3228 xmin = me->xmin; xmax = me->xmax; width = me->width;
3229 extracnt = 0; extras = NULL;
3230
3231 for ( pt=subs; *pt ; ++extracnt ) {
3232 while ( *pt!=' ' && *pt!='\0' ) ++pt;
3233 if ( *pt==' ' )
3234 while ( *pt==' ' ) ++pt;
3235 }
3236 extras = malloc(extracnt*sizeof(BDFChar *));
3237 extracnt = 0;
3238 for ( pt=subs; *pt ; ) {
3239 start = pt;
3240 while ( *pt!=' ' && *pt!='\0' && *pt!='(' ) ++pt;
3241 ch = *pt; *pt = '\0';
3242 other = SFGetChar(sf,-1, start);
3243 *pt = ch;
3244 if ( ch=='(' ) {
3245 while ( *pt!=')' && *pt!='\0' ) ++pt;
3246 if ( *pt==')' ) ++pt;
3247 }
3248 if ( other!=NULL ) {
3249 if ( extracnt==0 ) width += ICON_WIDTH;
3250 extras[extracnt] = Rasterize(other,def_layer);
3251 if ( width+extras[extracnt]->xmin < xmin ) xmin = width+extras[extracnt]->xmin;
3252 if ( width+extras[extracnt]->xmax > xmax ) xmax = width+extras[extracnt]->xmax;
3253 if ( extras[extracnt]->ymin < ymin ) ymin = extras[extracnt]->ymin;
3254 if ( extras[extracnt]->ymax > ymax ) ymax = extras[extracnt]->ymax;
3255 width += extras[extracnt++]->width;
3256 }
3257 if ( *pt==' ' )
3258 while ( *pt==' ' ) ++pt;
3259 }
3260
3261 if ( ymax<=ICON_WIDTH ) ymax = ICON_WIDTH;
3262 if ( ymin>0 ) ymin = 0;
3263 if ( xmax<xmin ) {
3264 for ( i=0; i<extracnt; ++i )
3265 BDFCharFree(extras[i]);
3266 free(extras);
3267 return( NULL );
3268 }
3269
3270 if ( xmin>0 ) xmin = 0;
3271
3272 img = GImageCreate(it_index,xmax - xmin + 2,ymax-ymin+2);
3273 base = img->u.image;
3274 memset(base->data,'\0',base->bytes_per_line*base->height);
3275
3276 width = -xmin;
3277 ++width;
3278
3279 for ( y=me->ymin; y<=me->ymax; ++y ) {
3280 for ( x=me->xmin; x<=me->xmax; ++x ) {
3281 base->data[(1+ymax-y)*base->bytes_per_line + (x+width)] =
3282 me->bitmap[(me->ymax-y)*me->bytes_per_line + (x-me->xmin)];
3283 }
3284 }
3285 width += me->width;
3286 if ( extracnt!=0 ) {
3287 int pixel = me->depth == 8 ? 0xff : 0xf;
3288 if ( !isliga ) {
3289 for ( j = -1; j<2; j+=2 ) {
3290 if ( me->ymax<-me->ymin )
3291 y = (me->ymax+me->ymin)/2;
3292 else
3293 y = 1+me->ymax/2;
3294 // Figure out the centerpoint of the arrow
3295 y = ymax - y;
3296 if (y > (ymax - ymin - ICON_WIDTH/2)) {
3297 // Too far down; shift up to make it fit
3298 y = ymax - ymin - ICON_WIDTH/2;
3299 }
3300 // Draw the == part of the arrow
3301 y += j*2;
3302 for ( x=1; x<ICON_WIDTH-5; ++x )
3303 base->data[y*base->bytes_per_line + (x+width)] = pixel;
3304 // Draw the > part of the arrow
3305 for ( x=ICON_WIDTH-8; x<ICON_WIDTH-1; ++x )
3306 base->data[(y+j*(ICON_WIDTH-4-x))*base->bytes_per_line + (x+width)] = pixel;
3307 }
3308 } else if ( isliga>0 ) {
3309 for ( j = -1; j<2; j+=2 ) {
3310 y = 1+ymax/2 + j*2;
3311 // Draw the == part of the arrow
3312 for ( x=5; x<ICON_WIDTH-1; ++x )
3313 base->data[y*base->bytes_per_line + (x+width)] = pixel;
3314 // Draw the < part of the arrow
3315 for ( x=8; x>1 ; --x )
3316 base->data[(y+j*(x-3))*base->bytes_per_line + (x+width)] = pixel;
3317 }
3318 }
3319 width += ICON_WIDTH;
3320 for ( i=0; i<extracnt; ++i ) {
3321 BDFChar *other = extras[i];
3322 for ( y=other->ymin; y<=other->ymax; ++y ) {
3323 for ( x=other->xmin; x<=other->xmax; ++x ) {
3324 if ( other->bitmap[(other->ymax-y)*other->bytes_per_line + (x-other->xmin)] != 0 )
3325 base->data[(1+ymax-y)*base->bytes_per_line + (x+width)] =
3326 other->bitmap[(other->ymax-y)*other->bytes_per_line + (x-other->xmin)];
3327 }
3328 }
3329 width += other->width;
3330 }
3331 }
3332 memset(base->clut,'\0',sizeof(*base->clut));
3333 bg = GDrawGetDefaultBackground(NULL);
3334 fg = GDrawGetDefaultForeground(NULL);
3335 clut_scale = me->depth == 8 ? 8 : 4;
3336 base->clut->clut_len = 1<<clut_scale;
3337 for ( l=0; l<(1<<clut_scale); ++l )
3338 base->clut->clut[l] =
3339 COLOR_CREATE(
3340 COLOR_RED(bg) + (l*(COLOR_RED(fg)-COLOR_RED(bg)))/((1<<clut_scale)-1),
3341 COLOR_GREEN(bg) + (l*(COLOR_GREEN(fg)-COLOR_GREEN(bg)))/((1<<clut_scale)-1),
3342 COLOR_BLUE(bg) + (l*(COLOR_BLUE(fg)-COLOR_BLUE(bg)))/((1<<clut_scale)-1) );
3343 BDFCharFree(me);
3344 for ( i=0; i<extracnt; ++i )
3345 BDFCharFree(extras[i]);
3346 free(extras);
3347 return( img );
3348 }
3349
3350 GImage *PST_GetImage(GGadget *pstk,SplineFont *sf,int def_layer,
3351 struct lookup_subtable *sub,int popup_r, SplineChar *sc ) {
3352 int rows, cols = GMatrixEditGetColCnt(pstk);
3353 struct matrix_data *old = GMatrixEditGet(pstk,&rows);
3354
3355 if ( sc==NULL || sub==NULL )
3356 return( NULL );
3357 if ( sub->lookup->lookup_type<gsub_single || sub->lookup->lookup_type>gsub_ligature )
3358 return( NULL );
3359
3360 return( NameList_GetImage(sf,sc,def_layer,old[cols*popup_r+1].u.md_str,
3361 sub->lookup->lookup_type==gsub_ligature));
3362 }
3363
3364 static GImage *_CI_GetImage(const void *_ci) {
3365 CharInfo *ci = (CharInfo *) _ci;
3366 int offset = GTabSetGetSel(GWidgetGetControl(ci->gw,CID_Tabs))-2;
3367 GGadget *pstk = GWidgetGetControl(ci->gw,CID_List+offset*100);
3368 int rows, cols = GMatrixEditGetColCnt(pstk);
3369 struct matrix_data *old = GMatrixEditGet(pstk,&rows);
3370 struct lookup_subtable *sub = (struct lookup_subtable *) (old[cols*ci->r+0].u.md_ival);
3371
3372 if ( ci->r>=rows )
3373 return( NULL );
3374
3375 return( PST_GetImage(pstk,ci->sc->parent,ci->def_layer,sub,ci->r,ci->sc) );
3376 }
3377
3378 static void CI_KerningPopupPrepare(GGadget *g, int r, int c) {
3379 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
3380 int rows, cols = GMatrixEditGetColCnt(g);
3381 struct matrix_data *old = GMatrixEditGet(g,&rows);
3382
3383 if ( c<0 || c>=cols || r<0 || r>=rows || old[cols*r+1].u.md_str==NULL ||
3384 SFGetChar(ci->sc->parent,-1, old[cols*r+1].u.md_str)==NULL )
3385 return;
3386 ci->r = r; ci->c = c;
3387 GGadgetPreparePopupImage(GGadgetGetWindow(g),NULL,ci,CI_GetKernedImage,CI_FreeKernedImage);
3388 }
3389
3390 static void CI_SubsPopupPrepare(GGadget *g, int r, int c) {
3391 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
3392 int rows, cols = GMatrixEditGetColCnt(g);
3393
3394 (void) GMatrixEditGet(g,&rows);
3395 if ( c<0 || c>=cols || r<0 || r>=rows )
3396 return;
3397 ci->r = r; ci->c = c;
3398 GGadgetPreparePopupImage(GGadgetGetWindow(g),NULL,ci,_CI_GetImage,CI_FreeKernedImage);
3399 }
3400
3401 static void CI_ConstructionPopupPrepare(GGadget *g, int r, int c) {
3402 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
3403 int rows/*, cols = GMatrixEditGetColCnt(g)*/;
3404
3405 (void) GMatrixEditGet(g,&rows);
3406 if ( rows==0 )
3407 return;
3408 GGadgetPreparePopupImage(GGadgetGetWindow(g),NULL,ci,CI_GetConstructedImage,CI_FreeKernedImage);
3409 }
3410
3411 static unichar_t **CI_GlyphNameCompletion(GGadget *t,int from_tab) {
3412 CharInfo *ci = GDrawGetUserData(GDrawGetParentWindow(GGadgetGetWindow(t)));
3413 SplineFont *sf = ci->sc->parent;
3414
3415 return( SFGlyphNameCompletion(sf,t,from_tab,false));
3416 }
3417
3418 static unichar_t **CI_GlyphListCompletion(GGadget *t,int from_tab) {
3419 CharInfo *ci = GDrawGetUserData(GDrawGetParentWindow(GGadgetGetWindow(t)));
3420 SplineFont *sf = ci->sc->parent;
3421
3422 return( SFGlyphNameCompletion(sf,t,from_tab,true));
3423 }
3424
3425
3426 static void extpart_finishedit(GGadget *g, int r, int c, int wasnew) {
3427 int rows;
3428 struct matrix_data *possub;
3429 CharInfo *ci;
3430 int is_horiz,cols;
3431 DBounds b;
3432 double full_advance;
3433 SplineChar *sc;
3434
3435 if ( c!=0 )
3436 return;
3437 if ( !wasnew )
3438 return;
3439 /* If they added a new glyph to the sequence then set some defaults for it. */
3440 /* only the full advance has any likelihood of being correct */
3441 ci = GDrawGetUserData(GGadgetGetWindow(g));
3442 is_horiz = GTabSetGetSel(GWidgetGetControl(ci->gw,CID_Tabs))-ci->vert_aspect;
3443 possub = GMatrixEditGet(g, &rows);
3444 cols = GMatrixEditGetColCnt(g);
3445 if ( possub[r*cols+0].u.md_str==NULL )
3446 return;
3447 sc = SFGetChar(ci->sc->parent,-1,possub[r*cols+0].u.md_str);
3448 if ( sc==NULL )
3449 return;
3450 SplineCharFindBounds(sc,&b);
3451 if ( is_horiz )
3452 full_advance = b.maxx - b.minx;
3453 else
3454 full_advance = b.maxy - b.miny;
3455 possub[r*cols+2].u.md_ival = possub[r*cols+3].u.md_ival = rint(full_advance/3);
3456 possub[r*cols+4].u.md_ival = rint(full_advance);
3457 GGadgetRedraw(g);
3458 }
3459
3460 static GTextInfo truefalse[] = {
3461 { (unichar_t *) N_("false"), NULL, 0, 0, (void *) 0, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0'},
3462 { (unichar_t *) N_("true"), NULL, 0, 0, (void *) 1, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0'},
3463 GTEXTINFO_EMPTY
3464 };
3465
3466 static struct col_init extensionpart[] = {
3467 { me_string , NULL, NULL, NULL, N_("Glyph") },
3468 { me_enum, NULL, truefalse, NULL, N_("Extender") },
3469 /* GT: "Len" is an abbreviation for "Length" */
3470 { me_int, NULL, NULL, NULL, N_("StartLen") },
3471 { me_int, NULL, NULL, NULL, N_("EndLen") },
3472 { me_int, NULL, NULL, NULL, N_("FullLen") },
3473 COL_INIT_EMPTY
3474 };
3475 static struct matrixinit mi_extensionpart =
3476 { sizeof(extensionpart)/sizeof(struct col_init)-1, extensionpart, 0, NULL, NULL, NULL, extpart_finishedit, NULL, NULL, NULL };
3477
3478 static int isxheight(int uni) {
3479 if (!islower(uni))
3480 return( false );
3481
3482 if ( uni=='a' || uni=='c' || uni=='e' || uni=='i' || uni=='j' ||
3483 (uni>='m' && uni<='z') ||
3484 uni==0x131 || uni==0x237 || /* Ignore accented letters except the dotlessi/j */
3485 (uni>=0x250 && uni<0x253) || uni==0x254 || uni==0x255 ||
3486 (uni>=0x258 && uni<0x265) || uni==0x269 || uni==0x26A ||
3487 (uni>=0x26f && uni<=0x277) || uni==0x279 ||
3488 uni==0x3b1 || uni==0x3b3 || uni==0x3b5 || uni==0x3b7 ||
3489 uni==0x3b9 || uni==0x3ba || uni==0x3bc || uni==0x3bd ||
3490 (uni>=0x3bf && uni<=0x3c7) || uni==0x3c9 ||
3491 (uni>=0x400 && uni<=0x45f))
3492 return( true );
3493
3494 return( false );
3495 }
3496
3497 static int isbaseline(int uni) {
3498 /* Treat rounded letters as being on the base line */
3499 /* But don't bother including guys that normally are on the baseline */
3500
3501 if ( (uni>='a' && uni<'g') || uni=='h' || uni=='i' ||
3502 (uni>='k' && uni<='o') || (uni>='r' && uni<'y') || uni=='z' ||
3503 (uni>='A' && uni<='Z' ) ||
3504 uni==0x3b0 || uni==0x3b4 || uni==0x3b5 || (uni>=0x3b8 && uni<0x3bb) ||
3505 uni==0x3bd || uni==0x3bf || uni==0x3c0 || (uni>=0x3c2 && uni<0x3c6) ||
3506 uni==0x3c8 || uni==0x3c7 || uni==0x3c9 ||
3507 (uni>=0x391 && uni<0x3aa) ||
3508 (uni>=0x400 && uni<0x40f) || (uni>=0x410 && uni<=0x413) ||
3509 (uni>=0x415 && uni<0x425) || uni==0x427 || uni==0x428 ||
3510 (uni>=0x42a && uni<0x433) || (uni>=0x435 && uni<0x45e) )
3511 return( true );
3512
3513 return( false );
3514 }
3515
3516 static int TeX_Default(GGadget *g, GEvent *e) {
3517 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
3518 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
3519 int cid = GGadgetGetCid(g), mcid = 0;
3520 DBounds b;
3521 int value;
3522 SplineChar *basesc = NULL;
3523 SplineFont *sf = ci->sc->parent;
3524 int style;
3525 char buf[12];
3526
3527 basesc = ci->sc;
3528 /* Try to align the top of lowercase (xheight) letters all at the */
3529 /* same height. Ditto for uppercase & ascender letters */
3530 if ( cid==CID_TeX_HeightD && isxheight(ci->sc->unicodeenc) &&
3531 (basesc = SFGetChar(sf,'x',NULL))!=NULL )
3532 /* Done */;
3533 else if ( cid==CID_TeX_HeightD && islower(ci->sc->unicodeenc) &&
3534 (basesc = SFGetChar(sf,'l',NULL))!=NULL )
3535 /* Done */;
3536 else if ( cid==CID_TeX_HeightD && isupper(ci->sc->unicodeenc) &&
3537 (basesc = SFGetChar(sf,'I',NULL))!=NULL )
3538 /* Done */;
3539 else if ( cid==CID_TeX_DepthD && isbaseline(ci->sc->unicodeenc) &&
3540 (basesc = SFGetChar(sf,'I',NULL))!=NULL )
3541 /* Done */;
3542 else
3543 basesc = ci->sc;
3544
3545 SplineCharFindBounds(basesc,&b);
3546 style = MacStyleCode(sf,NULL);
3547
3548 if ( cid == CID_TeX_HeightD ) {
3549 mcid = CID_TeX_Height;
3550 if ( basesc!=ci->sc && basesc->tex_height!=TEX_UNDEF )
3551 value = basesc->tex_height;
3552 else
3553 value = rint(b.maxy);
3554 if ( value<0 ) value = 0;
3555 } else if ( cid == CID_TeX_DepthD ) {
3556 mcid = CID_TeX_Depth;
3557 if ( basesc!=ci->sc && basesc->tex_depth!=TEX_UNDEF )
3558 value = basesc->tex_depth;
3559 else {
3560 value = -rint(b.miny);
3561 if ( value<5 ) value = 0;
3562 }
3563 } else if ( cid == CID_HorAccentD ) {
3564 mcid = CID_HorAccent;
3565 double italic_off = (b.maxy-b.miny)*tan(-sf->italicangle);
3566 if ( b.maxx-b.minx-italic_off < 0 )
3567 value = rint(b.minx + (b.maxx-b.minx)/2);
3568 else
3569 value = rint(b.minx + italic_off + (b.maxx - b.minx - italic_off)/2);
3570 } else if ( cid == CID_TeX_ItalicD ) {
3571 mcid = CID_TeX_Italic;
3572 if ( (style&sf_italic) || sf->italicangle!=0 )
3573 value = rint((b.maxx-ci->sc->width) +
3574 (sf->ascent+sf->descent)/16.0);
3575 else
3576 value = 0;
3577 }
3578 if (mcid!=0) {
3579 sprintf( buf, "%d", value );
3580 GGadgetSetTitle8(GWidgetGetControl(ci->gw,mcid),buf);
3581 }
3582 }
3583 return( true );
3584 }
3585
3586 static int CI_SubSuperPositionings(GGadget *g, GEvent *e) {
3587 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
3588 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
3589 MathKernDialog(ci->sc,ci->def_layer);
3590 }
3591 return( true );
3592 }
3593
3594 static struct col_init altuniinfo[] = {
3595 { me_uhex , NULL, NULL, NULL, N_("Unicode") },
3596 { me_uhex, NULL, truefalse, NULL, N_("Variation Selector (or 0)") },
3597 COL_INIT_EMPTY
3598 };
3599 static struct matrixinit mi_altuniinfo =
3600 { sizeof(altuniinfo)/sizeof(struct col_init)-1, altuniinfo, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
3601
3602 static void CI_NoteAspect(CharInfo *ci) {
3603 int new_aspect = GTabSetGetSel(GWidgetGetControl(ci->gw,CID_Tabs));
3604 PST *pst;
3605 int cnt;
3606 char buf[20];
3607
3608 last_gi_aspect = new_aspect;
3609 if ( new_aspect == ci->lc_aspect && (!ci->lc_seen || GGadgetIsChecked(GWidgetGetControl(ci->gw,CID_DefLCCount)))) {
3610 ci->lc_seen = true;
3611 for ( pst=ci->sc->possub; pst!=NULL && pst->type!=pst_lcaret; pst=pst->next );
3612 if ( GGadgetIsChecked(GWidgetGetControl(ci->gw,CID_DefLCCount)) &&
3613 pst==NULL ) {
3614 int rows, cols, i;
3615 struct matrix_data *possub;
3616 /* Normally we look for ligatures in the possub list, but here*/
3617 /* we will examine the ligature pane itself to get the most */
3618 /* up to date info */
3619 possub = GMatrixEditGet(GWidgetGetControl(ci->gw,CID_List+(pst_ligature-1)*100), &rows );
3620 cols = GMatrixEditGetColCnt(GWidgetGetControl(ci->gw,CID_List+(pst_ligature-1)*100) );
3621 cnt = 0;
3622 for ( i=0; i<rows; ++i ) {
3623 char *pt = possub[cols*i+1].u.md_str;
3624 int comp = 0;
3625 while ( *pt!='\0' ) {
3626 while ( *pt==' ' ) ++pt;
3627 if ( *pt=='\0' )
3628 break;
3629 while ( *pt!=' ' && *pt!='\0' ) ++pt;
3630 ++comp;
3631 }
3632 if ( comp>cnt ) cnt = comp;
3633 }
3634 --cnt; /* We want one fewer caret than there are components -- carets go BETWEEN components */
3635 } else if ( pst!=NULL )
3636 cnt = pst->u.lcaret.cnt;
3637 else
3638 cnt = 0;
3639 if ( cnt<0 ) cnt = 0;
3640 sprintf( buf, "%d", cnt );
3641 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_LCCount),buf);
3642 }
3643 }
3644
3645 static int CI_AspectChange(GGadget *g, GEvent *e) {
3646 if ( e->type==et_controlevent && e->u.control.subtype == et_radiochanged ) {
3647 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
3648 CI_NoteAspect(ci);
3649 }
3650 return( true );
3651 }
3652
3653 static int CI_DefLCChange(GGadget *g, GEvent *e) {
3654 if ( e->type==et_controlevent && e->u.control.subtype == et_radiochanged ) {
3655 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
3656 int show = !GGadgetIsChecked(g);
3657 GGadgetSetEnabled(GWidgetGetControl(ci->gw,CID_LCCount),show);
3658 GGadgetSetEnabled(GWidgetGetControl(ci->gw,CID_LCCountLab),show);
3659 }
3660 return( true );
3661 }
3662
3663 // Turn the user's entered decomposition into the format returned by SFGetAlternate
3664 unichar_t* CI_ParseUserDecomposition(char* inp) {
3665 unsigned long len = strlen(inp);
3666 char* end;
3667 unichar_t* decomp = malloc((len+1)*sizeof(unichar_t));
3668
3669 int j = 0;
3670 for (unsigned long i = strtoul(inp, &end, 16); inp != end; i = strtoul(inp, &end, 16)) {
3671 inp = end;
3672 decomp[j] = i;
3673 j++;
3674 }
3675
3676 decomp[j] = '\0';
3677
3678 return decomp;
3679 }
3680
3681 char* CI_CreateInterpretedAsLabel(unichar_t* inp) {
3682 char* lblprefix = _("Interpreted as: ");
3683 char* lblerror = _("Error: wrong format");
3684 char* lblbuf;
3685
3686 // If I don't validate it, the string will become "(null)"
3687 bool valid = true;
3688 unichar_t* inp_ptr = inp;
3689 if (inp != NULL) {
3690 while (*inp_ptr != '\0') {
3691 if (*inp_ptr > 0x10FFFF) valid = false;
3692 inp_ptr++;
3693 }
3694 }
3695
3696 if (inp != NULL && inp[0] != 0 && valid) {
3697 char* inp_l = u2utf8_copy(inp);
3698 lblbuf = malloc(strlen(lblprefix)+strlen(inp_l)+1);
3699 sprintf(lblbuf, "%s%s", lblprefix, inp_l);
3700 free(inp_l);
3701 } else {
3702 lblbuf = copy(lblerror);
3703 }
3704
3705 return lblbuf;
3706 }
3707
3708 static int CI_CmpUseNonDefault(GGadget *g, GEvent *e) {
3709 int show = !GGadgetIsChecked(g);
3710 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
3711 GGadget* cotf = GWidgetGetControl(ci->gw,CID_ComponentTextField);
3712 GGadget* coim = GWidgetGetControl(ci->gw,CID_ComponentInterpMsg);
3713 GGadgetSetEnabled(cotf, show);
3714 if (ci->sc->user_decomp != NULL) free(ci->sc->user_decomp);
3715 if (!show) {
3716 ci->sc->user_decomp = NULL;
3717 GGadgetSetTitle8(coim, "");
3718 } else {
3719 unichar_t* ud = CI_ParseUserDecomposition(GGadgetGetTitle8(cotf));
3720 ci->sc->user_decomp = ud;
3721 char* lbl = CI_CreateInterpretedAsLabel(ci->sc->user_decomp);
3722 GGadgetSetTitle8(coim, lbl);
3723 free(lbl);
3724 }
3725
3726 return true;
3727 }
3728
3729 void GV_ToMD(GGadget *g, struct glyphvariants *gv) {
3730 int cols = GMatrixEditGetColCnt(g), j;
3731 struct matrix_data *mds;
3732 if ( gv==NULL ) {
3733 GMatrixEditSet(g, NULL,0,false);
3734 return;
3735 }
3736 mds = calloc(gv->part_cnt*cols,sizeof(struct matrix_data));
3737 for ( j=0; j<gv->part_cnt; ++j ) {
3738 mds[j*cols+0].u.md_str = copy(gv->parts[j].component);
3739 mds[j*cols+1].u.md_ival = gv->parts[j].is_extender;
3740 mds[j*cols+2].u.md_ival = gv->parts[j].startConnectorLength;
3741 mds[j*cols+3].u.md_ival = gv->parts[j].endConnectorLength;
3742 mds[j*cols+4].u.md_ival = gv->parts[j].fullAdvance;
3743 }
3744 GMatrixEditSet(g, mds,gv->part_cnt,false);
3745 }
3746
3747 static void GA_ToMD(GGadget *g, SplineChar *sc) {
3748 struct altuni *alt;
3749 int cols = GMatrixEditGetColCnt(g), cnt;
3750 struct matrix_data *mds;
3751 if ( sc->altuni==NULL ) {
3752 GMatrixEditSet(g, NULL,0,false);
3753 return;
3754 }
3755 for ( cnt=0, alt=sc->altuni; alt!=NULL; ++cnt, alt=alt->next );
3756 mds = calloc(cnt*cols,sizeof(struct matrix_data));
3757 for ( cnt=0, alt=sc->altuni; alt!=NULL; ++cnt, alt=alt->next ) {
3758 mds[cnt*cols+0].u.md_ival = alt->unienc;
3759 mds[cnt*cols+1].u.md_ival = alt->vs==-1? 0 : alt->vs;
3760 }
3761 GMatrixEditSet(g, mds,cnt,false);
3762 }
3763
3764 static void CI_SetColorList(CharInfo *ci,Color color) {
3765 int i;
3766 uint16_t junk;
3767
3768 std_colors[CUSTOM_COLOR].image = NULL;
3769 for ( i=0; std_colors[i].image!=NULL; ++i ) {
3770 if ( std_colors[i].userdata == (void *) (intptr_t) color )
3771 break;
3772 }
3773 if ( std_colors[i].image==NULL ) {
3774 std_colors[i].image = &customcolor_image;
3775 customcolor_image.u.image->clut->clut[1] = color;
3776 std_colors[i].userdata = (void *) (intptr_t) color;
3777 }
3778 GGadgetSetList(GWidgetGetControl(ci->gw,CID_Color), GTextInfoArrayFromList(std_colors,&junk), false);
3779 GGadgetSelectOneListItem(GWidgetGetControl(ci->gw,CID_Color),i);
3780 if ( color!=COLOR_DEFAULT )
3781 ci->last = color;
3782 ci->real_last = color;
3783 }
3784
3785 struct colcount { Color color; int cnt; };
3786 static int colcountorder(const void *op1, const void *op2) {
3787 const struct colcount *c1 = op1, *c2 = op2;
3788
3789 return( c2->cnt - c1->cnt ); /* Biggest first */
3790 }
3791
3792 struct hslrgb *SFFontCols(SplineFont *sf,struct hslrgb fontcols[6]) {
3793 int i, gid, cnt;
3794 struct colcount *colcount, stds[7];
3795 SplineChar *sc;
3796
3797 memset(stds,0,sizeof(stds));
3798 stds[0].color = 0xffffff;
3799 stds[1].color = 0xff0000;
3800 stds[2].color = 0x00ff00;
3801 stds[3].color = 0x0000ff;
3802 stds[4].color = 0xffff00;
3803 stds[5].color = 0x00ffff;
3804 stds[6].color = 0xff00ff;
3805 colcount = calloc(sf->glyphcnt,sizeof(struct colcount));
3806
3807 cnt = 0;
3808 for ( gid=0; gid<sf->glyphcnt; ++gid ) if ( (sc= sf->glyphs[gid])!=NULL ) {
3809 if ( sc->color==COLOR_DEFAULT )
3810 continue;
3811 for ( i=0; i<7 && sc->color!=stds[i].color; ++i );
3812 if ( i<7 ) {
3813 ++stds[i].cnt;
3814 continue;
3815 }
3816 for ( i=0; i<cnt && sc->color!=colcount[i].color; ++i );
3817 if ( i==cnt )
3818 colcount[cnt++].color = sc->color;
3819 ++colcount[i].cnt;
3820 }
3821
3822 if ( cnt<6 ) {
3823 for ( i=0; i<cnt; ++i )
3824 ++colcount[i].cnt;
3825 for ( i=0; i<7; ++i ) if ( stds[i].cnt!=0 ) {
3826 colcount[cnt].color = stds[i].color;
3827 colcount[cnt++].cnt = 1;
3828 }
3829 }
3830 qsort(colcount,cnt,sizeof(struct colcount),colcountorder);
3831
3832 memset(fontcols,0,6*sizeof(struct hslrgb));
3833 for ( i=0; i<6 && i<cnt; ++i ) {
3834 fontcols[i].rgb = true;
3835 fontcols[i].r = ((colcount[i].color>>16)&0xff)/255.0;
3836 fontcols[i].g = ((colcount[i].color>>8 )&0xff)/255.0;
3837 fontcols[i].b = ((colcount[i].color )&0xff)/255.0;
3838 }
3839 free(colcount);
3840 if ( cnt==0 )
3841 return( NULL );
3842
3843 return(fontcols);
3844 }
3845
3846 static int CI_PickColor(GGadget *g, GEvent *e) {
3847 if ( e->type==et_controlevent && e->u.control.subtype == et_listselected ) {
3848 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
3849 GTextInfo *ti = GGadgetGetListItemSelected(g);
3850 if ( ti==NULL )
3851 /* Can't happen */;
3852 else if ( ti->userdata == (void *) COLOR_CHOOSE ) {
3853 struct hslrgb col, font_cols[6];
3854 memset(&col,0,sizeof(col));
3855 col.rgb = true;
3856 col.r = ((ci->last>>16)&0xff)/255.;
3857 col.g = ((ci->last>>8 )&0xff)/255.;
3858 col.b = ((ci->last )&0xff)/255.;
3859 col = GWidgetColor(_("Pick a color"),&col,SFFontCols(ci->sc->parent,font_cols));
3860 if ( col.rgb ) {
3861 ci->last = (((int) rint(255.*col.r))<<16 ) |
3862 (((int) rint(255.*col.g))<<8 ) |
3863 (((int) rint(255.*col.b)) );
3864 CI_SetColorList(ci,ci->last);
3865 } else /* Cancelled */
3866 CI_SetColorList(ci,ci->real_last);
3867 } else {
3868 if ( (intptr_t) ti->userdata!=COLOR_DEFAULT )
3869 ci->last = (intptr_t) ti->userdata;
3870 ci->real_last = (intptr_t) ti->userdata;
3871 }
3872 }
3873 return( true );
3874 }
3875
3876 static int BytesNeeded(unichar_t in) {
3877 if (in <= 0xff) {
3878 return 1;
3879 } else if (in <= 0xffff) {
3880 return 2;
3881 } else if (in <= 0xffffff) {
3882 return 3;
3883 } else {
3884 return 4;
3885 }
3886 }
3887
3888 static void CIFillup(CharInfo *ci) {
3889 SplineChar *sc = ci->cachedsc!=NULL ? ci->cachedsc : ci->sc;
3890 SplineFont *sf = sc->parent;
3891 unichar_t *temp;
3892 char buffer[400];
3893 char buf[200];
3894 const unichar_t *bits, *bits2;
3895 const unichar_t *d_ptr = sc->user_decomp;
3896 int i,j,gid, isv;
3897 struct matrix_data *mds[pst_max];
3898 int cnts[pst_max];
3899 PST *pst;
3900 KernPair *kp;
3901 unichar_t ubuf[4];
3902 GTextInfo **ti;
3903 char *devtabstr;
3904
3905 sprintf(buf,_("Glyph Info for %.40s"),sc->name);
3906 GDrawSetWindowTitles8(ci->gw, buf, _("Glyph Info..."));
3907
3908 if ( ci->oldsc!=NULL && ci->oldsc->charinfo==ci )
3909 ci->oldsc->charinfo = NULL;
3910 ci->sc->charinfo = ci;
3911 ci->oldsc = ci->sc;
3912
3913 GGadgetSetEnabled(GWidgetGetControl(ci->gw,-1), ci->enc>0 &&
3914 ((gid=ci->map->map[ci->enc-1])==-1 ||
3915 sf->glyphs[gid]==NULL || sf->glyphs[gid]->charinfo==NULL ||
3916 gid==sc->orig_pos));
3917 GGadgetSetEnabled(GWidgetGetControl(ci->gw,1), ci->enc<ci->map->enccount-1 &&
3918 ((gid=ci->map->map[ci->enc+1])==-1 ||
3919 sf->glyphs[gid]==NULL || sf->glyphs[gid]->charinfo==NULL ||
3920 gid==sc->orig_pos));
3921
3922 temp = utf82u_copy(sc->name);
3923 GGadgetSetTitle(GWidgetGetControl(ci->gw,CID_UName),temp);
3924 free(temp);
3925 CI_SetNameList(ci,sc->unicodeenc);
3926
3927 sprintf(buffer,"U+%04x", sc->unicodeenc);
3928 temp = utf82u_copy(sc->unicodeenc==-1?"-1":buffer);
3929 GGadgetSetTitle(GWidgetGetControl(ci->gw,CID_UValue),temp);
3930 free(temp);
3931
3932 ubuf[0] = sc->unicodeenc;
3933 if ( sc->unicodeenc==-1 )
3934 ubuf[0] = '\0';
3935 ubuf[1] = '\0';
3936 GGadgetSetTitle(GWidgetGetControl(ci->gw,CID_UChar),ubuf);
3937
3938 memset(cnts,0,sizeof(cnts));
3939 for ( pst = sc->possub; pst!=NULL; pst=pst->next ) if ( pst->type!=pst_lcaret )
3940 ++cnts[pst->type];
3941 for ( isv=0; isv<2; ++isv ) {
3942 for ( kp=isv ? sc->vkerns : sc->kerns; kp!=NULL; kp=kp->next )
3943 ++cnts[pst_pair];
3944 }
3945 for ( i=pst_null+1; i<pst_max && i<pst_lcaret ; ++i )
3946 mds[i] = calloc((cnts[i]+1)*mi[i-1].col_cnt,sizeof(struct matrix_data));
3947 memset(cnts,0,sizeof(cnts));
3948 for ( pst = sc->possub; pst!=NULL; pst=pst->next ) if ( pst->type!=pst_lcaret ) {
3949 j = (cnts[pst->type]++ * mi[pst->type-1].col_cnt);
3950 mds[pst->type][j+0].u.md_ival = (intptr_t) pst->subtable;
3951 if ( pst->type==pst_position ) {
3952 mds[pst->type][j+SIM_DX].u.md_ival = pst->u.pos.xoff;
3953 mds[pst->type][j+SIM_DY].u.md_ival = pst->u.pos.yoff;
3954 mds[pst->type][j+SIM_DX_ADV].u.md_ival = pst->u.pos.h_adv_off;
3955 mds[pst->type][j+SIM_DY_ADV].u.md_ival = pst->u.pos.v_adv_off;
3956 ValDevTabToStrings(mds[pst_position],j+SIM_DX+1,pst->u.pos.adjust);
3957 } else if ( pst->type==pst_pair ) {
3958 mds[pst->type][j+1].u.md_str = copy(pst->u.pair.paired);
3959 mds[pst->type][j+PAIR_DX1].u.md_ival = pst->u.pair.vr[0].xoff;
3960 mds[pst->type][j+PAIR_DY1].u.md_ival = pst->u.pair.vr[0].yoff;
3961 mds[pst->type][j+PAIR_DX_ADV1].u.md_ival = pst->u.pair.vr[0].h_adv_off;
3962 mds[pst->type][j+PAIR_DY_ADV1].u.md_ival = pst->u.pair.vr[0].v_adv_off;
3963 mds[pst->type][j+PAIR_DX2].u.md_ival = pst->u.pair.vr[1].xoff;
3964 mds[pst->type][j+PAIR_DY2].u.md_ival = pst->u.pair.vr[1].yoff;
3965 mds[pst->type][j+PAIR_DX_ADV2].u.md_ival = pst->u.pair.vr[1].h_adv_off;
3966 mds[pst->type][j+PAIR_DY_ADV2].u.md_ival = pst->u.pair.vr[1].v_adv_off;
3967 ValDevTabToStrings(mds[pst_pair],j+PAIR_DX1+1,pst->u.pair.vr[0].adjust);
3968 ValDevTabToStrings(mds[pst_pair],j+PAIR_DX2+1,pst->u.pair.vr[1].adjust);
3969 } else {
3970 mds[pst->type][j+1].u.md_str = SFNameList2NameUni(sf,pst->u.subs.variant);
3971 }
3972 }
3973 for ( isv=0; isv<2; ++isv ) {
3974 for ( kp=isv ? sc->vkerns : sc->kerns; kp!=NULL; kp=kp->next ) {
3975 j = (cnts[pst_pair]++ * mi[pst_pair-1].col_cnt);
3976 mds[pst_pair][j+0].u.md_ival = (intptr_t) kp->subtable;
3977 mds[pst_pair][j+1].u.md_str = SCNameUniStr(kp->sc);
3978 if ( isv ) {
3979 mds[pst_pair][j+PAIR_DY_ADV1].u.md_ival = kp->off;
3980 DevTabToString(&mds[pst_pair][j+PAIR_DY_ADV1+1].u.md_str,kp->adjust);
3981 } else if ( kp->subtable->lookup->lookup_flags&pst_r2l ) {
3982 mds[pst_pair][j+PAIR_DX_ADV2].u.md_ival = kp->off;
3983 DevTabToString(&mds[pst_pair][j+PAIR_DX_ADV2+1].u.md_str,kp->adjust);
3984 } else {
3985 mds[pst_pair][j+PAIR_DX_ADV1].u.md_ival = kp->off;
3986 DevTabToString(&mds[pst_pair][j+PAIR_DX_ADV1+1].u.md_str,kp->adjust);
3987 }
3988 }
3989 }
3990 for ( i=pst_null+1; i<pst_lcaret /* == pst_max-1 */; ++i ) {
3991 GMatrixEditSet(GWidgetGetControl(ci->gw,CID_List+(i-1)*100),
3992 mds[i],cnts[i],false);
3993 }
3994 /* There's always a pane showing kerning data */
3995 CI_DoHideUnusedPair(ci);
3996 CI_DoHideUnusedSingle(ci);
3997
3998 GGadget *cotf = GWidgetGetControl(ci->gw,CID_ComponentTextField);
3999 GGadget *codcb = GWidgetGetControl(ci->gw,CID_ComponentDefaultCB);
4000 GGadget *coim = GWidgetGetControl(ci->gw,CID_ComponentInterpMsg);
4001 GGadget *cola = GWidgetGetControl(ci->gw,CID_ComponentChangeMsg);
4002
4003 bits = bits2 = SFGetAlternate(sc->parent,sc->unicodeenc,NULL,true);
4004 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_ComponentMsg),
4005 bits==NULL ? _("No components") :
4006 hascomposing(sc->parent,sc->unicodeenc,sc) ? _("Accented glyph composed of:") :
4007 _("Glyph composed of:"));
4008 if ( bits==NULL ) {
4009 ubuf[0] = '\0';
4010 GGadgetSetTitle(GWidgetGetControl(ci->gw,CID_Components),ubuf);
4011 GGadgetSetTitle(cotf,ubuf);
4012 } else {
4013 unichar_t *temp = malloc(18*u_strlen(bits)*sizeof(unichar_t));
4014 unichar_t *upt=temp;
4015 while ( *bits!='\0' ) {
4016 sprintf(buffer, "U+%04x (", *bits );
4017 uc_strcpy(upt,buffer);
4018 upt += u_strlen(upt);
4019 if (iscombining(*bits)) {
4020 *upt = 0x25CC; // DOTTED CIRCLE “◌”
4021 upt += 1;
4022 }
4023 *upt = *bits;
4024 upt += 1;
4025 sprintf(buffer, ") ");
4026 uc_strcpy(upt,buffer);
4027 upt += u_strlen(upt);
4028
4029 ++bits;
4030 }
4031 upt[-1] = '\0';
4032 GGadgetSetTitle(GWidgetGetControl(ci->gw,CID_Components),temp);
4033 free(temp);
4034 }
4035
4036 if (d_ptr == NULL) d_ptr = bits2;
4037
4038 int d_length = d_ptr ? u_strlen(d_ptr) : 0;
4039
4040 const int MAX_UNICHAR_T_BYTES = 4;
4041 char* codepoints_as_hex = malloc(((2 * MAX_UNICHAR_T_BYTES) * d_length) + d_length + 1);
4042 codepoints_as_hex[0] = '\0';
4043
4044 if (d_ptr == NULL) d_ptr = bits2;
4045
4046 while (d_ptr != NULL && *d_ptr != '\0') {
4047 switch (BytesNeeded(*d_ptr)) {
4048 case 1:
4049 sprintf(buffer, "%02x ", *d_ptr); break;
4050 case 2:
4051 sprintf(buffer, "%04x ", *d_ptr); break;
4052 case 3:
4053 sprintf(buffer, "%06x ", *d_ptr); break;
4054 default:
4055 sprintf(buffer, "%08x ", *d_ptr);
4056 }
4057 codepoints_as_hex = strcat(codepoints_as_hex, buffer);
4058 ++d_ptr;
4059 }
4060
4061 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_ComponentTextField),codepoints_as_hex);
4062 free(codepoints_as_hex);
4063
4064 if (!GGadgetIsEnabled(codcb)) GGadgetSetEnabled(codcb, true);
4065 char* lbl = CI_CreateInterpretedAsLabel(sc->user_decomp);
4066 if (sc->user_decomp != NULL) {
4067 GGadgetSetChecked(codcb, false);
4068 GGadgetSetEnabled(cotf, true);
4069 GGadgetSetEnabled(cola, true);
4070 GGadgetSetTitle8(coim,lbl);
4071 } else {
4072 GGadgetSetChecked(codcb, true);
4073 GGadgetSetEnabled(cotf, false);
4074 GGadgetSetEnabled(cola, false);
4075 GGadgetSetTitle8(coim,"");
4076 }
4077 free(lbl);
4078
4079 GGadgetSelectOneListItem(GWidgetGetControl(ci->gw,CID_Color),0);
4080
4081 GGadgetSetChecked(GWidgetGetControl(ci->gw,CID_UnlinkRmOverlap),sc->unlink_rm_ovrlp_save_undo);
4082
4083 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_Comment),
4084 sc->comment?sc->comment:"");
4085 GGadgetSelectOneListItem(GWidgetGetControl(ci->gw,CID_GClass),sc->glyph_class);
4086 CI_SetColorList(ci,sc->color);
4087 ci->first = sc->comment==NULL;
4088
4089 ti = malloc((sc->countermask_cnt+1)*sizeof(GTextInfo *));
4090 ti[sc->countermask_cnt] = calloc(1,sizeof(GTextInfo));
4091 for ( i=0; i<sc->countermask_cnt; ++i ) {
4092 ti[i] = calloc(1,sizeof(GTextInfo));
4093 ti[i]->text = CounterMaskLine(sc,&sc->countermasks[i]);
4094 ti[i]->fg = ti[i]->bg = COLOR_DEFAULT;
4095 ti[i]->userdata = chunkalloc(sizeof(HintMask));
4096 memcpy(ti[i]->userdata,sc->countermasks[i],sizeof(HintMask));
4097 }
4098 GGadgetSetList(GWidgetGetControl(ci->gw,CID_List+600),ti,false);
4099
4100 if ( sc->tex_height!=TEX_UNDEF )
4101 sprintf(buffer,"%d",sc->tex_height);
4102 else
4103 buffer[0] = '\0';
4104 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_TeX_Height),buffer);
4105
4106 if ( sc->tex_depth!=TEX_UNDEF )
4107 sprintf(buffer,"%d",sc->tex_depth);
4108 else
4109 buffer[0] = '\0';
4110 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_TeX_Depth),buffer);
4111
4112 if ( sc->italic_correction!=TEX_UNDEF )
4113 sprintf(buffer,"%d",sc->italic_correction);
4114 else
4115 buffer[0] = '\0';
4116 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_TeX_Italic),buffer);
4117 DevTabToString(&devtabstr,sc->italic_adjusts);
4118 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_ItalicDevTab),devtabstr==NULL?"":devtabstr);
4119 free(devtabstr);
4120
4121 if ( sc->top_accent_horiz!=TEX_UNDEF )
4122 sprintf(buffer,"%d",sc->top_accent_horiz);
4123 else
4124 buffer[0] = '\0';
4125 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_HorAccent),buffer);
4126 DevTabToString(&devtabstr,sc->top_accent_adjusts);
4127 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_AccentDevTab),devtabstr==NULL?"":devtabstr);
4128 free(devtabstr);
4129
4130 GGadgetSetChecked(GWidgetGetControl(ci->gw,CID_IsExtended),sc->is_extended_shape);
4131
4132 {
4133 GGadget *g = GWidgetGetControl(ci->gw,CID_VariantList+0*100);
4134 if ( sc->vert_variants==NULL || sc->vert_variants->variants==NULL )
4135 GGadgetSetTitle8(g,"");
4136 else
4137 GGadgetSetTitle8(g,sc->vert_variants->variants);
4138 sprintf(buffer,"%d",sc->vert_variants!=NULL?sc->vert_variants->italic_correction:0);
4139 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_ExtItalicCor+0*100),buffer);
4140 DevTabToString(&devtabstr,sc->vert_variants!=NULL?
4141 sc->vert_variants->italic_adjusts:
4142 NULL);
4143 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_ExtItalicDev+0*100),devtabstr==NULL?"":devtabstr);
4144 free(devtabstr);
4145
4146 g = GWidgetGetControl(ci->gw,CID_VariantList+1*100);
4147 if ( sc->horiz_variants==NULL || sc->horiz_variants->variants==NULL )
4148 GGadgetSetTitle8(g,"");
4149 else
4150 GGadgetSetTitle8(g,sc->horiz_variants->variants);
4151 sprintf(buffer,"%d",sc->horiz_variants!=NULL?sc->horiz_variants->italic_correction:0);
4152 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_ExtItalicCor+1*100),buffer);
4153 DevTabToString(&devtabstr,sc->horiz_variants!=NULL?
4154 sc->horiz_variants->italic_adjusts:
4155 NULL);
4156 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_ExtItalicDev+1*100),devtabstr==NULL?"":devtabstr);
4157 free(devtabstr);
4158 }
4159 for ( i=0; i<2; ++i ) {
4160 struct glyphvariants *gv = i ? sc->horiz_variants : sc->vert_variants ;
4161 GGadget *g = GWidgetGetControl(ci->gw,CID_ExtensionList+i*100);
4162 GV_ToMD(g, gv);
4163 }
4164 GA_ToMD(GWidgetGetControl(ci->gw,CID_AltUni), sc);
4165
4166 if ( ci->sc->parent->multilayer ) {
4167 int margined = sc->tile_margin!=0 || (sc->tile_bounds.minx==0 && sc->tile_bounds.maxx==0);
4168 char buffer[40];
4169
4170 GGadgetSetChecked(GWidgetGetControl(ci->gw,CID_IsTileMargin),margined);
4171 if ( margined ) {
4172 sprintf( buffer, "%g", (double) sc->tile_margin );
4173 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_TileMargin),buffer);
4174 CI_BoundsToMargin(ci);
4175 } else {
4176 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_TileMargin),"0");
4177 sprintf( buffer, "%g", (double) sc->tile_bounds.minx );
4178 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_TileBBoxMinX),buffer);
4179 sprintf( buffer, "%g", (double) sc->tile_bounds.miny );
4180 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_TileBBoxMinY),buffer);
4181 sprintf( buffer, "%g", (double) sc->tile_bounds.maxx );
4182 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_TileBBoxMaxX),buffer);
4183 sprintf( buffer, "%g", (double) sc->tile_bounds.maxy );
4184 GGadgetSetTitle8(GWidgetGetControl(ci->gw,CID_TileBBoxMaxY),buffer);
4185 }
4186 }
4187
4188 GGadgetSetChecked(GWidgetGetControl(ci->gw,CID_DefLCCount), !sc->lig_caret_cnt_fixed );
4189 GGadgetSetEnabled(GWidgetGetControl(ci->gw,CID_LCCountLab), sc->lig_caret_cnt_fixed );
4190 GGadgetSetEnabled(GWidgetGetControl(ci->gw,CID_LCCount), sc->lig_caret_cnt_fixed );
4191 ci->lc_seen = false;
4192 CI_NoteAspect(ci);
4193 }
4194
4195 static int CI_NextPrev(GGadget *g, GEvent *e) {
4196 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
4197 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
4198 int enc = ci->enc + GGadgetGetCid(g); /* cid is 1 for next, -1 for prev */
4199 SplineChar *new_;
4200 struct splinecharlist *scl;
4201
4202 if ( enc<0 || enc>=ci->map->enccount ) {
4203 GGadgetSetEnabled(g,false);
4204 return( true );
4205 }
4206 if ( !_CI_OK(ci))
4207 return( true );
4208 new_ = SFMakeChar(ci->sc->parent,ci->map,enc);
4209 if ( new_->charinfo!=NULL && new_->charinfo!=ci ) {
4210 GGadgetSetEnabled(g,false);
4211 return( true );
4212 }
4213 ci->sc = new_;
4214 ci->enc = enc;
4215 for ( scl=ci->changes; scl!=NULL && scl->sc->orig_pos!=new_->orig_pos;
4216 scl = scl->next );
4217 ci->cachedsc = scl==NULL ? NULL : scl->sc;
4218 CIFillup(ci);
4219 }
4220 return( true );
4221 }
4222
4223 static void CI_DoCancel(CharInfo *ci) {
4224 int32_t i,len;
4225 GTextInfo **ti = GGadgetGetList(GWidgetGetControl(ci->gw,CID_List+600),&len);
4226
4227 for ( i=0; i<len; ++i )
4228 chunkfree(ti[i]->userdata,sizeof(HintMask));
4229 CI_Finish(ci);
4230 }
4231
4232 static int CI_Cancel(GGadget *g, GEvent *e) {
4233 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
4234 CharInfo *ci = GDrawGetUserData(GGadgetGetWindow(g));
4235 CI_DoCancel(ci);
4236 }
4237 return( true );
4238 }
4239
4240 static int ci_e_h(GWindow gw, GEvent *event) {
4241 if ( event->type==et_close ) {
4242 CharInfo *ci = GDrawGetUserData(gw);
4243 CI_DoCancel(ci);
4244 } else if ( event->type==et_char ) {
4245 CharInfo *ci = GDrawGetUserData(gw);
4246 if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) {
4247 help("ui/dialogs/charinfo.html", NULL);
4248 return( true );
4249 } else if ( GMenuIsCommand(event,H_("Quit|Ctl+Q") )) {
4250 MenuExit(NULL,NULL,NULL);
4251 } else if ( GMenuIsCommand(event,H_("Close|Ctl+Shft+Q") )) {
4252 CI_DoCancel(ci);
4253 }
4254 return( false );
4255 } else if ( event->type == et_destroy ) {
4256 CharInfo *ci = GDrawGetUserData(gw);
4257 ci->sc->charinfo = NULL;
4258 free(ci);
4259 } else if ( event->type == et_map ) {
4260 /* Above palettes */
4261 GDrawRaise(gw);
4262 }
4263 return( true );
4264 }
4265
4266 void SCCharInfo(SplineChar *sc,int deflayer, EncMap *map,int enc) {
4267 CharInfo *ci;
4268 GRect pos;
4269 GWindowAttrs wattrs;
4270 GGadgetCreateData ugcd[14], cgcd[6], psgcd[7][7], cogcd[6], mgcd[9], tgcd[16];
4271 GGadgetCreateData lcgcd[4], vargcd[2][7];
4272 GTextInfo ulabel[14], clabel[6], pslabel[7][6], colabel[4], mlabel[9], tlabel[16];
4273 GTextInfo lclabel[4], varlabel[2][6];
4274 GGadgetCreateData mbox[4], *mvarray[7], *mharray1[7], *mharray2[8];
4275 GGadgetCreateData ubox[3], *uhvarray[29], *uharray[6];
4276 GGadgetCreateData cbox[3], *cvarray[5], *charray[4];
4277 GGadgetCreateData pstbox[7][4], *pstvarray[7][5], *pstharray1[7][8];
4278 GGadgetCreateData cobox[2], *covarray[8];
4279 GGadgetCreateData tbox[3], *thvarray[36], *tbarray[4];
4280 GGadgetCreateData lcbox[2], *lchvarray[4][4];
4281 GGadgetCreateData varbox[2][2], *varhvarray[2][5][4];
4282 GGadgetCreateData tilegcd[16], tilebox[4];
4283 GTextInfo tilelabel[16];
4284 GGadgetCreateData *tlvarray[6], *tlharray[4], *tlhvarray[4][5];
4285 int i;
4286 GTabInfo aspects[17];
4287 static GBox smallbox = { bt_raised, bs_rect, 2, 1, 0, 0, 0, 0, 0, 0, COLOR_DEFAULT, COLOR_DEFAULT, 0, 0, 0, 0, 0, 0, 0 };
4288 static int boxset=0;
4289
4290 CharInfoInit();
4291
4292 if ( sc->charinfo!=NULL ) {
4293 GDrawSetVisible(sc->charinfo->gw,true);
4294 GDrawRaise(sc->charinfo->gw);
4295 return;
4296 }
4297
4298 ci = calloc(1,sizeof(CharInfo));
4299 ci->sc = sc;
4300 ci->def_layer = deflayer;
4301 ci->done = false;
4302 ci->map = map;
4303 ci->last = 0xffffff;
4304 if ( enc==-1 )
4305 enc = map->backmap[sc->orig_pos];
4306 ci->enc = enc;
4307
4308 if ( !boxset ) {
4309 extern GBox _ggadget_Default_Box;
4310 GGadgetInit();
4311 smallbox = _ggadget_Default_Box;
4312 smallbox.padding = 1;
4313 boxset = 1;
4314 }
4315
4316 memset(&wattrs,0,sizeof(wattrs));
4317 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict;
4318 wattrs.event_masks = ~(1<<et_charup);
4319 wattrs.restrict_input_to_me = false;
4320 wattrs.undercursor = 1;
4321 wattrs.cursor = ct_pointer;
4322 wattrs.utf8_window_title = _("Glyph Info");
4323 wattrs.is_dlg = false;
4324 pos.x = pos.y = 0;
4325 pos.width = GGadgetScale(GDrawPointsToPixels(NULL,CI_Width+65));
4326 pos.height = GDrawPointsToPixels(NULL,CI_Height);
4327 ci->gw = GDrawCreateTopWindow(NULL,&pos,ci_e_h,ci,&wattrs);
4328
4329 memset(&ugcd,0,sizeof(ugcd));
4330 memset(&ubox,0,sizeof(ubox));
4331 memset(&ulabel,0,sizeof(ulabel));
4332
4333 ulabel[0].text = (unichar_t *) _("Gl_yph Name:");
4334 ulabel[0].text_is_1byte = true;
4335 ulabel[0].text_in_resource = true;
4336 ugcd[0].gd.label = &ulabel[0];
4337 ugcd[0].gd.pos.x = 5; ugcd[0].gd.pos.y = 5+4;
4338 ugcd[0].gd.flags = gg_enabled|gg_visible;
4339 ugcd[0].gd.mnemonic = 'y';
4340 ugcd[0].creator = GLabelCreate;
4341 uhvarray[0] = &ugcd[0];
4342
4343 ugcd[1].gd.pos.x = 85; ugcd[1].gd.pos.y = 5;
4344 ugcd[1].gd.flags = gg_enabled|gg_visible;
4345 ugcd[1].gd.mnemonic = 'y';
4346 ugcd[1].gd.cid = CID_UName;
4347 ugcd[1].creator = GListFieldCreate;
4348 ugcd[1].data = (void *) (-2);
4349 uhvarray[1] = &ugcd[1]; uhvarray[2] = NULL;
4350
4351 ulabel[2].text = (unichar_t *) _("Unicode _Value:");
4352 ulabel[2].text_in_resource = true;
4353 ulabel[2].text_is_1byte = true;
4354 ugcd[2].gd.label = &ulabel[2];
4355 ugcd[2].gd.pos.x = 5; ugcd[2].gd.pos.y = 31+4;
4356 ugcd[2].gd.flags = gg_enabled|gg_visible;
4357 ugcd[2].gd.mnemonic = 'V';
4358 ugcd[2].creator = GLabelCreate;
4359 uhvarray[3] = &ugcd[2];
4360
4361 ugcd[3].gd.pos.x = 85; ugcd[3].gd.pos.y = 31;
4362 ugcd[3].gd.flags = gg_enabled|gg_visible;
4363 ugcd[3].gd.mnemonic = 'V';
4364 ugcd[3].gd.cid = CID_UValue;
4365 ugcd[3].gd.handle_controlevent = CI_UValChanged;
4366 ugcd[3].creator = GTextFieldCreate;
4367 uhvarray[4] = &ugcd[3]; uhvarray[5] = NULL;
4368
4369 ulabel[4].text = (unichar_t *) _("Unicode C_har:");
4370 ulabel[4].text_in_resource = true;
4371 ulabel[4].text_is_1byte = true;
4372 ugcd[4].gd.label = &ulabel[4];
4373 ugcd[4].gd.pos.x = 5; ugcd[4].gd.pos.y = 57+4;
4374 ugcd[4].gd.flags = gg_enabled|gg_visible;
4375 ugcd[4].gd.mnemonic = 'h';
4376 ugcd[4].creator = GLabelCreate;
4377 uhvarray[6] = &ugcd[4];
4378
4379 ugcd[5].gd.pos.x = 85; ugcd[5].gd.pos.y = 57;
4380 ugcd[5].gd.flags = gg_enabled|gg_visible|gg_text_xim;
4381 ugcd[5].gd.mnemonic = 'h';
4382 ugcd[5].gd.cid = CID_UChar;
4383 ugcd[5].gd.handle_controlevent = CI_CharChanged;
4384 ugcd[5].creator = GTextFieldCreate;
4385 uhvarray[7] = &ugcd[5]; uhvarray[8] = NULL;
4386
4387 ugcd[6].gd.pos.x = 12; ugcd[6].gd.pos.y = 117;
4388 ugcd[6].gd.flags = gg_visible | gg_enabled;
4389 ulabel[6].text = (unichar_t *) _("Set From N_ame");
4390 ulabel[6].text_is_1byte = true;
4391 ulabel[6].text_in_resource = true;
4392 ugcd[6].gd.mnemonic = 'a';
4393 ugcd[6].gd.label = &ulabel[6];
4394 ugcd[6].gd.handle_controlevent = CI_SName;
4395 ugcd[6].creator = GButtonCreate;
4396 uharray[0] = GCD_Glue; uharray[1] = &ugcd[6];
4397
4398 ugcd[7].gd.pos.x = 107; ugcd[7].gd.pos.y = 117;
4399 ugcd[7].gd.flags = gg_visible | gg_enabled;
4400 ulabel[7].text = (unichar_t *) _("Set From Val_ue");
4401 ulabel[7].text_is_1byte = true;
4402 ulabel[7].text_in_resource = true;
4403 ugcd[7].gd.mnemonic = 'l';
4404 ugcd[7].gd.label = &ulabel[7];
4405 ugcd[7].gd.handle_controlevent = CI_SValue;
4406 ugcd[7].creator = GButtonCreate;
4407 uharray[2] = GCD_Glue; uharray[3] = &ugcd[7]; uharray[4] = GCD_Glue; uharray[5] = NULL;
4408
4409 ubox[2].gd.flags = gg_enabled|gg_visible;
4410 ubox[2].gd.u.boxelements = uharray;
4411 ubox[2].creator = GHBoxCreate;
4412 uhvarray[9] = &ubox[2]; uhvarray[10] = GCD_ColSpan; uhvarray[11] = NULL;
4413
4414 ugcd[8].gd.flags = gg_visible | gg_enabled;
4415 ulabel[8].text = (unichar_t *) _("Alternate Unicode Encodings / Variation Selectors");
4416 ulabel[8].text_is_1byte = true;
4417 ugcd[8].gd.label = &ulabel[8];
4418 ugcd[8].gd.popup_msg = _(
4419 "Some glyphs may be used for more than one\n"
4420 "unicode code point -- I don't recommend\n"
4421 "doing this, better to use a reference --\n"
4422 "but it is possible.\n"
4423 "The latin \"A\", the greek \"Alpha\" and the\n"
4424 "cyrillic \"A\" look very much the same.\n\n"
4425 "On the other hand certain Mongolian and CJK\n"
4426 "characters have multiple glyphs depending\n"
4427 "on a unicode Variation Selector.\n\n"
4428 "In the first case use a variation selector\n"
4429 "of 0, in the second use the appropriate\n"
4430 "codepoint.");
4431 ugcd[8].creator = GLabelCreate;
4432 uhvarray[12] = &ugcd[8]; uhvarray[13] = GCD_ColSpan; uhvarray[14] = NULL;
4433
4434 ugcd[9].gd.flags = gg_enabled|gg_visible;
4435 ugcd[9].gd.u.matrix = &mi_altuniinfo;
4436 ugcd[9].gd.cid = CID_AltUni;
4437 ugcd[9].gd.popup_msg = ugcd[8].gd.popup_msg;
4438 ugcd[9].creator = GMatrixEditCreate;
4439 uhvarray[15] = &ugcd[9]; uhvarray[16] = GCD_ColSpan; uhvarray[17] = NULL;
4440
4441 ugcd[10].gd.pos.x = 5; ugcd[10].gd.pos.y = 83+4;
4442 ugcd[10].gd.flags = gg_visible | gg_enabled;
4443 ulabel[10].text = (unichar_t *) _("OT _Glyph Class:");
4444 ulabel[10].text_is_1byte = true;
4445 ulabel[10].text_in_resource = true;
4446 ugcd[10].gd.label = &ulabel[10];
4447 ugcd[10].creator = GLabelCreate;
4448 uhvarray[18] = &ugcd[10];
4449
4450 ugcd[11].gd.pos.x = 85; ugcd[11].gd.pos.y = 83;
4451 ugcd[11].gd.flags = gg_visible | gg_enabled;
4452 ugcd[11].gd.cid = CID_GClass;
4453 ugcd[11].gd.u.list = glyphclasses;
4454 ugcd[11].creator = GListButtonCreate;
4455 uhvarray[19] = &ugcd[11]; uhvarray[20] = NULL;
4456
4457 ugcd[12].gd.flags = gg_visible | gg_enabled;
4458 ulabel[12].text = (unichar_t *) _("Mark for Unlink, Remove Overlap before Generating");
4459 ulabel[12].text_is_1byte = true;
4460 ulabel[12].text_in_resource = true;
4461 ugcd[12].gd.label = &ulabel[12];
4462 ugcd[12].gd.cid = CID_UnlinkRmOverlap;
4463 ugcd[12].gd.popup_msg = _("A few glyphs, like Aring, Ccedilla, Eogonek\nare composed of two overlapping references.\nOften it is desirable to retain the references\n(so that changes made to the base glyph are\nreflected in the composed glyph), but that\nmeans you are stuck with overlapping contours.\nThis flag means that just before generating\nthe font, FontForge will unlink the references\nand run remove overlap on them, while\n retaining the references in the SFD.");
4464 ugcd[12].creator = GCheckBoxCreate;
4465 uhvarray[21] = &ugcd[12]; uhvarray[22] = GCD_ColSpan; uhvarray[23] = NULL;
4466 uhvarray[24] = GCD_Glue; uhvarray[25] = GCD_Glue; uhvarray[26] = NULL;
4467 uhvarray[27] = NULL;
4468
4469 ubox[0].gd.flags = gg_enabled|gg_visible;
4470 ubox[0].gd.u.boxelements = uhvarray;
4471 ubox[0].creator = GHVBoxCreate;
4472
4473
4474 memset(&cgcd,0,sizeof(cgcd));
4475 memset(&cbox,0,sizeof(cbox));
4476 memset(&clabel,0,sizeof(clabel));
4477
4478 clabel[0].text = (unichar_t *) _("Comment");
4479 clabel[0].text_is_1byte = true;
4480 cgcd[0].gd.label = &clabel[0];
4481 cgcd[0].gd.pos.x = 5; cgcd[0].gd.pos.y = 5;
4482 cgcd[0].gd.flags = gg_enabled|gg_visible;
4483 cgcd[0].creator = GLabelCreate;
4484 cvarray[0] = &cgcd[0];
4485
4486 cgcd[1].gd.pos.x = 5; cgcd[1].gd.pos.y = cgcd[0].gd.pos.y+13;
4487 cgcd[1].gd.pos.height = 7*12+6;
4488 cgcd[1].gd.flags = gg_enabled|gg_visible|gg_textarea_wrap|gg_text_xim;
4489 cgcd[1].gd.cid = CID_Comment;
4490 cgcd[1].gd.handle_controlevent = CI_CommentChanged;
4491 cgcd[1].creator = GTextAreaCreate;
4492 cvarray[1] = &cgcd[1]; cvarray[2] = GCD_Glue;
4493
4494 clabel[2].text = (unichar_t *) _("Color:");
4495 clabel[2].text_is_1byte = true;
4496 cgcd[2].gd.label = &clabel[2];
4497 cgcd[2].gd.pos.x = 5; cgcd[2].gd.pos.y = cgcd[1].gd.pos.y+cgcd[1].gd.pos.height+5+6;
4498 cgcd[2].gd.flags = gg_enabled|gg_visible;
4499 cgcd[2].creator = GLabelCreate;
4500 charray[0] = &cgcd[2];
4501
4502 cgcd[3].gd.pos.x = cgcd[3].gd.pos.x; cgcd[3].gd.pos.y = cgcd[2].gd.pos.y-6;
4503 cgcd[3].gd.flags = gg_enabled|gg_visible;
4504 cgcd[3].gd.cid = CID_Color;
4505 cgcd[3].gd.handle_controlevent = CI_PickColor;
4506 std_colors[0].image = GGadgetImageCache("colorwheel.png");
4507 cgcd[3].gd.u.list = std_colors;
4508 cgcd[3].creator = GListButtonCreate;
4509 charray[1] = &cgcd[3]; charray[2] = GCD_Glue; charray[3] = NULL;
4510
4511 cbox[2].gd.flags = gg_enabled|gg_visible;
4512 cbox[2].gd.u.boxelements = charray;
4513 cbox[2].creator = GHBoxCreate;
4514 cvarray[3] = &cbox[2]; cvarray[4] = NULL;
4515
4516 cbox[0].gd.flags = gg_enabled|gg_visible;
4517 cbox[0].gd.u.boxelements = cvarray;
4518 cbox[0].creator = GVBoxCreate;
4519
4520 memset(&psgcd,0,sizeof(psgcd));
4521 memset(&pstbox,0,sizeof(pstbox));
4522 memset(&pslabel,0,sizeof(pslabel));
4523
4524 for ( i=0; i<6; ++i ) {
4525 psgcd[i][0].gd.pos.x = 5; psgcd[i][0].gd.pos.y = 5;
4526 psgcd[i][0].gd.flags = gg_visible | gg_enabled;
4527 psgcd[i][0].gd.cid = CID_List+i*100;
4528 psgcd[i][0].gd.u.matrix = &mi[i];
4529 mi[i].col_init[0].enum_vals = SFSubtableListOfType(sc->parent, pst2lookuptype[i+1], false, false);
4530 psgcd[i][0].creator = GMatrixEditCreate;
4531 }
4532 for ( i=pst_position; i<=pst_pair; ++i ) {
4533 pslabel[i-1][1].text = (unichar_t *) _("_Hide Unused Columns");
4534 pslabel[i-1][1].text_is_1byte = true;
4535 pslabel[i-1][1].text_in_resource = true;
4536 psgcd[i-1][1].gd.label = &pslabel[i-1][1];
4537 psgcd[i-1][1].gd.pos.x = 5; psgcd[i-1][1].gd.pos.y = 5+4;
4538 psgcd[i-1][1].gd.flags = lookup_hideunused ? (gg_enabled|gg_visible|gg_cb_on) : (gg_enabled|gg_visible);
4539 psgcd[i-1][1].gd.popup_msg = _("Don't display columns of 0s.\nThe OpenType lookup allows for up to 8 kinds\nof data, but almost all kerning lookups will use just one.\nOmitting the others makes the behavior clearer.");
4540 psgcd[i-1][1].gd.handle_controlevent = i==pst_position ? CI_HideUnusedSingle : CI_HideUnusedPair;
4541 psgcd[i-1][1].creator = GCheckBoxCreate;
4542 pstvarray[i-1][0] = &psgcd[i-1][0];
4543 pstvarray[i-1][1] = &psgcd[i-1][1];
4544 pstvarray[i-1][2] = NULL;
4545
4546 pstbox[i-1][0].gd.flags = gg_enabled|gg_visible;
4547 pstbox[i-1][0].gd.u.boxelements = pstvarray[i-1];
4548 pstbox[i-1][0].creator = GVBoxCreate;
4549 }
4550
4551 psgcd[6][0].gd.pos.x = 5; psgcd[6][0].gd.pos.y = 5;
4552 psgcd[6][0].gd.flags = gg_visible | gg_enabled;
4553 psgcd[6][0].gd.cid = CID_List+6*100;
4554 psgcd[6][0].gd.handle_controlevent = CI_CounterSelChanged;
4555 psgcd[6][0].gd.box = &smallbox;
4556 psgcd[6][0].creator = GListCreate;
4557 pstvarray[6][0] = &psgcd[6][0];
4558
4559 psgcd[6][1].gd.pos.x = 10; psgcd[6][1].gd.pos.y = psgcd[6][0].gd.pos.y+psgcd[6][0].gd.pos.height+4;
4560 psgcd[6][1].gd.flags = gg_visible | gg_enabled;
4561 pslabel[6][1].text = (unichar_t *) S_("CounterHint|_New...");
4562 pslabel[6][1].text_is_1byte = true;
4563 pslabel[6][1].text_in_resource = true;
4564 psgcd[6][1].gd.label = &pslabel[6][1];
4565 psgcd[6][1].gd.cid = CID_New+6*100;
4566 psgcd[6][1].gd.handle_controlevent = CI_NewCounter;
4567 psgcd[6][1].gd.box = &smallbox;
4568 psgcd[6][1].creator = GButtonCreate;
4569 pstharray1[6][0] = GCD_Glue; pstharray1[6][1] = &psgcd[6][1];
4570
4571 psgcd[6][2].gd.pos.x = 20+GIntGetResource(_NUM_Buttonsize)*100/GIntGetResource(_NUM_ScaleFactor); psgcd[6][2].gd.pos.y = psgcd[6][1].gd.pos.y;
4572 psgcd[6][2].gd.flags = gg_visible;
4573 pslabel[6][2].text = (unichar_t *) _("_Delete");
4574 pslabel[6][2].text_is_1byte = true;
4575 pslabel[6][2].text_in_resource = true;
4576 psgcd[6][2].gd.label = &pslabel[6][2];
4577 psgcd[6][2].gd.cid = CID_Delete+6*100;
4578 psgcd[6][2].gd.handle_controlevent = CI_DeleteCounter;
4579 psgcd[6][2].gd.box = &smallbox;
4580 psgcd[6][2].creator = GButtonCreate;
4581 pstharray1[6][2] = GCD_Glue; pstharray1[6][3] = &psgcd[6][2];
4582
4583 psgcd[6][3].gd.pos.x = -10; psgcd[6][3].gd.pos.y = psgcd[6][1].gd.pos.y;
4584 psgcd[6][3].gd.flags = gg_visible;
4585 pslabel[6][3].text = (unichar_t *) _("_Edit...");
4586 pslabel[6][3].text_is_1byte = true;
4587 pslabel[6][3].text_in_resource = true;
4588 psgcd[6][3].gd.label = &pslabel[6][3];
4589 psgcd[6][3].gd.cid = CID_Edit+6*100;
4590 psgcd[6][3].gd.handle_controlevent = CI_EditCounter;
4591 psgcd[6][3].gd.box = &smallbox;
4592 psgcd[6][3].creator = GButtonCreate;
4593 pstharray1[6][4] = GCD_Glue; pstharray1[6][5] = &psgcd[6][3]; pstharray1[6][6] = GCD_Glue; pstharray1[6][7] = NULL;
4594
4595 pstbox[6][2].gd.flags = gg_enabled|gg_visible;
4596 pstbox[6][2].gd.u.boxelements = pstharray1[6];
4597 pstbox[6][2].creator = GHBoxCreate;
4598 pstvarray[6][1] = &pstbox[6][2]; pstvarray[6][2] = NULL;
4599
4600 pstbox[6][0].gd.flags = gg_enabled|gg_visible;
4601 pstbox[6][0].gd.u.boxelements = pstvarray[6];
4602 pstbox[6][0].creator = GVBoxCreate;
4603 psgcd[6][4].gd.flags = psgcd[6][5].gd.flags = 0; /* No copy, paste for hint masks */
4604
4605 memset(&cogcd,0,sizeof(cogcd));
4606 memset(&cobox,0,sizeof(cobox));
4607 memset(&colabel,0,sizeof(colabel));
4608
4609 colabel[0].text = (unichar_t *) _("Accented glyph composed of:");
4610 colabel[0].text_is_1byte = true;
4611 cogcd[0].gd.label = &colabel[0];
4612 cogcd[0].gd.flags = gg_enabled|gg_visible;
4613 cogcd[0].gd.cid = CID_ComponentMsg;
4614 cogcd[0].creator = GLabelCreate;
4615
4616 cogcd[1].gd.flags = gg_enabled|gg_visible;
4617 cogcd[1].gd.cid = CID_Components;
4618 cogcd[1].creator = GLabelCreate;
4619
4620 colabel[1].text = (unichar_t *) _("\n\nIf the default decomposition is inappropriate for this font, you may choose your own.");
4621 colabel[1].text_is_1byte = true;
4622 cogcd[2].gd.label = &colabel[1];
4623 cogcd[2].gd.flags = gg_enabled|gg_visible;
4624 cogcd[2].gd.cid = CID_ComponentChangeMsg;
4625 cogcd[2].creator = GLabelCreate;
4626
4627 colabel[2].text = (unichar_t *) _("Use default?");
4628 colabel[2].text_is_1byte = true;
4629 cogcd[3].gd.flags = gg_enabled | gg_visible | gg_cb_on;
4630 cogcd[3].gd.cid = CID_ComponentDefaultCB;
4631 cogcd[3].gd.handle_controlevent = CI_CmpUseNonDefault;
4632 cogcd[3].gd.label = &colabel[2];
4633 cogcd[3].creator = GCheckBoxCreate;
4634
4635 cogcd[4].gd.flags = gg_visible;
4636 cogcd[4].gd.popup_msg = _("For example, to build this character from U+0061 (lowercase a) as the base and U+030C (combining caron), write:\n0061 030C");
4637 cogcd[4].gd.cid = CID_ComponentTextField;
4638 cogcd[4].gd.handle_controlevent = CI_CmpUseNonDefault;
4639 cogcd[4].gd.pos.x = 500; cogcd[4].gd.pos.y = 20;
4640 cogcd[4].creator = GTextFieldCreate;
4641
4642 cogcd[5].gd.flags = gg_enabled|gg_visible;
4643 cogcd[5].gd.cid = CID_ComponentInterpMsg;
4644 cogcd[5].creator = GLabelCreate;
4645
4646 covarray[0] = &cogcd[0]; covarray[1] = &cogcd[1]; covarray[2] = &cogcd[2]; covarray[3] = &cogcd[3]; covarray[4] = &cogcd[4]; covarray[5] = &cogcd[5]; covarray[6] = GCD_Glue; covarray[7] = NULL;
4647 cobox[0].gd.flags = gg_enabled|gg_visible;
4648 cobox[0].gd.u.boxelements = covarray;
4649 cobox[0].creator = GVBoxCreate;
4650
4651 memset(&tgcd,0,sizeof(tgcd));
4652 memset(&tbox,0,sizeof(tbox));
4653 memset(&tlabel,0,sizeof(tlabel));
4654
4655 tlabel[0].text = (unichar_t *) _("Height:");
4656 tlabel[0].text_is_1byte = true;
4657 tgcd[0].gd.label = &tlabel[0];
4658 tgcd[0].gd.pos.x = 5; tgcd[0].gd.pos.y = 5+4;
4659 tgcd[0].gd.flags = gg_enabled|gg_visible;
4660 tgcd[0].gd.popup_msg = _("The height and depth fields are the metrics fields used\nby TeX, they are corrected for optical distortion.\nSo 'x' and 'o' probably have the same height.");
4661 tgcd[0].creator = GLabelCreate;
4662 thvarray[0] = &tgcd[0];
4663
4664 tgcd[1].gd.pos.x = 85; tgcd[1].gd.pos.y = 5;
4665 tgcd[1].gd.pos.width = 60;
4666 tgcd[1].gd.flags = gg_enabled|gg_visible;
4667 tgcd[1].gd.cid = CID_TeX_Height;
4668 tgcd[1].creator = GTextFieldCreate;
4669 tgcd[1].gd.popup_msg = tgcd[0].gd.popup_msg;
4670 thvarray[1] = &tgcd[1];
4671
4672 tlabel[2].text = (unichar_t *) _("Guess");
4673 tlabel[2].text_is_1byte = true;
4674 tgcd[2].gd.label = &tlabel[2];
4675 tgcd[2].gd.flags = gg_enabled|gg_visible;
4676 tgcd[2].gd.cid = CID_TeX_HeightD;
4677 tgcd[2].gd.handle_controlevent = TeX_Default;
4678 tgcd[2].creator = GButtonCreate;
4679 tgcd[2].gd.popup_msg = tgcd[0].gd.popup_msg;
4680 thvarray[2] = &tgcd[2]; thvarray[3] = GCD_Glue; thvarray[4] = NULL;
4681
4682 tlabel[3].text = (unichar_t *) _("Depth:");
4683 tlabel[3].text_is_1byte = true;
4684 tgcd[3].gd.label = &tlabel[3];
4685 tgcd[3].gd.pos.x = 5; tgcd[3].gd.pos.y = 31+4;
4686 tgcd[3].gd.flags = gg_enabled|gg_visible;
4687 tgcd[3].gd.popup_msg = tgcd[0].gd.popup_msg;
4688 tgcd[3].creator = GLabelCreate;
4689 thvarray[5] = &tgcd[3];
4690
4691 tgcd[4].gd.pos.x = 85; tgcd[4].gd.pos.y = 31;
4692 tgcd[4].gd.pos.width = 60;
4693 tgcd[4].gd.flags = gg_enabled|gg_visible;
4694 tgcd[4].gd.cid = CID_TeX_Depth;
4695 tgcd[4].creator = GTextFieldCreate;
4696 tgcd[4].gd.popup_msg = tgcd[0].gd.popup_msg;
4697 thvarray[6] = &tgcd[4];
4698
4699 tlabel[5].text = (unichar_t *) _("Guess");
4700 tlabel[5].text_is_1byte = true;
4701 tgcd[5].gd.label = &tlabel[5];
4702 tgcd[5].gd.flags = gg_enabled|gg_visible;
4703 tgcd[5].gd.cid = CID_TeX_DepthD;
4704 tgcd[5].gd.handle_controlevent = TeX_Default;
4705 tgcd[5].creator = GButtonCreate;
4706 tgcd[5].gd.popup_msg = tgcd[0].gd.popup_msg;
4707 thvarray[7] = &tgcd[5]; thvarray[8] = GCD_Glue; thvarray[9] = NULL;
4708
4709 tlabel[6].text = (unichar_t *) _("Italic Correction:");
4710 tlabel[6].text_is_1byte = true;
4711 tgcd[6].gd.label = &tlabel[6];
4712 tgcd[6].gd.pos.x = 5; tgcd[6].gd.pos.y = 57+4;
4713 tgcd[6].gd.flags = gg_enabled|gg_visible;
4714 tgcd[6].creator = GLabelCreate;
4715 tgcd[6].gd.popup_msg = _("The Italic correction field is used by both TeX and the MS 'MATH'\ntable. It is used when joining slanted text (italic) to upright.\nIt is the amount of extra white space needed so the slanted text\nwill not run into the upright text.");
4716 thvarray[10] = &tgcd[6];
4717
4718 tgcd[7].gd.pos.x = 85; tgcd[7].gd.pos.y = 57;
4719 tgcd[7].gd.pos.width = 60;
4720 tgcd[7].gd.flags = gg_enabled|gg_visible;
4721 tgcd[7].gd.cid = CID_TeX_Italic;
4722 tgcd[7].creator = GTextFieldCreate;
4723 tgcd[7].gd.popup_msg = tgcd[6].gd.popup_msg;
4724 thvarray[11] = &tgcd[7];
4725
4726 tlabel[8].text = (unichar_t *) _("Guess");
4727 tlabel[8].text_is_1byte = true;
4728 tgcd[8].gd.label = &tlabel[8];
4729 tgcd[8].gd.flags = gg_enabled|gg_visible;
4730 tgcd[8].gd.cid = CID_TeX_ItalicD;
4731 tgcd[8].gd.handle_controlevent = TeX_Default;
4732 tgcd[8].creator = GButtonCreate;
4733 tgcd[8].gd.popup_msg = tgcd[6].gd.popup_msg;
4734 thvarray[12] = &tgcd[8];
4735
4736 tgcd[9].gd.flags = gg_enabled|gg_visible;
4737 tgcd[9].gd.cid = CID_ItalicDevTab;
4738 tgcd[9].creator = GTextFieldCreate;
4739 tgcd[9].gd.popup_msg = _("A device table for italic correction.\nExpects a comma separated list of <pixelsize>\":\"<adjustment>\nAs \"9:-1,12:1,13:1\"");
4740 thvarray[13] = &tgcd[9]; thvarray[14] = NULL;
4741
4742 tlabel[10].text = (unichar_t *) _("Top Accent Pos:");
4743 tlabel[10].text_is_1byte = true;
4744 tgcd[10].gd.label = &tlabel[10];
4745 tgcd[10].gd.pos.x = 5; tgcd[10].gd.pos.y = 57+4;
4746 tgcd[10].gd.flags = gg_enabled|gg_visible;
4747 tgcd[10].gd.popup_msg = tgcd[9].gd.popup_msg;
4748 tgcd[10].creator = GLabelCreate;
4749 tgcd[10].gd.popup_msg = _("In the MS 'MATH' table this value specifies where (horizontally)\nan accent should be placed above the glyph. Vertical placement\nis handled by other means");
4750 thvarray[15] = &tgcd[10];
4751
4752 tgcd[11].gd.pos.x = 85; tgcd[11].gd.pos.y = 57;
4753 tgcd[11].gd.pos.width = 60;
4754 tgcd[11].gd.flags = gg_enabled|gg_visible;
4755 tgcd[11].gd.cid = CID_HorAccent;
4756 tgcd[11].creator = GTextFieldCreate;
4757 tgcd[11].gd.popup_msg = tgcd[10].gd.popup_msg;
4758 thvarray[16] = &tgcd[11];
4759
4760 tlabel[12].text = (unichar_t *) _("Guess");
4761 tlabel[12].text_is_1byte = true;
4762 tgcd[12].gd.label = &tlabel[12];
4763 tgcd[12].gd.flags = gg_enabled|gg_visible;
4764 tgcd[12].gd.cid = CID_HorAccentD;
4765 tgcd[12].gd.handle_controlevent = TeX_Default;
4766 tgcd[12].creator = GButtonCreate;
4767 tgcd[12].gd.popup_msg = tgcd[10].gd.popup_msg;
4768 thvarray[17] = &tgcd[12];
4769
4770 tgcd[13].gd.flags = gg_enabled|gg_visible;
4771 tgcd[13].gd.cid = CID_AccentDevTab;
4772 tgcd[13].creator = GTextFieldCreate;
4773 tgcd[13].gd.popup_msg = _("A device table for horizontal accent positioning.\nExpects a comma separated list of <pixelsize>\":\"<adjustment>\nAs \"9:-1,12:1,13:1\"");
4774 thvarray[18] = &tgcd[13]; thvarray[19] = NULL;
4775
4776 tlabel[14].text = (unichar_t *) _("Is Extended Shape");
4777 tlabel[14].text_is_1byte = true;
4778 tgcd[14].gd.label = &tlabel[14];
4779 tgcd[14].gd.pos.x = 5; tgcd[14].gd.pos.y = 57+4;
4780 tgcd[14].gd.flags = gg_enabled|gg_visible;
4781 tgcd[14].gd.cid = CID_IsExtended;
4782 tgcd[14].creator = GCheckBoxCreate;
4783 tgcd[14].gd.popup_msg = _("Is this an extended shape (like a tall parenthesis)?\nExtended shapes need special attention for vertical\nsuperscript placement.");
4784 thvarray[20] = &tgcd[14];
4785 thvarray[21] = thvarray[22] = GCD_ColSpan; thvarray[23] = GCD_Glue; thvarray[24] = NULL;
4786
4787 tlabel[15].text = (unichar_t *) _("Math Kerning"); /* Graphical */
4788 tlabel[15].text_is_1byte = true;
4789 tgcd[15].gd.label = &tlabel[15];
4790 tgcd[15].gd.flags = gg_enabled|gg_visible;
4791 tgcd[15].gd.handle_controlevent = CI_SubSuperPositionings;
4792 tgcd[15].creator = GButtonCreate;
4793 tgcd[15].gd.popup_msg = _("Brings up a dialog which gives fine control over\nhorizontal positioning of subscripts and superscripts\ndepending on their vertical positioning.");
4794 tbarray[0] = GCD_Glue; tbarray[1] = &tgcd[15]; tbarray[2] = GCD_Glue; tbarray[3] = NULL;
4795
4796 tbox[2].gd.flags = gg_enabled|gg_visible;
4797 tbox[2].gd.u.boxelements = tbarray;
4798 tbox[2].creator = GHBoxCreate;
4799
4800 thvarray[25] = &tbox[2];
4801 thvarray[26] = thvarray[27] = thvarray[28] = GCD_ColSpan; thvarray[29] = NULL;
4802
4803 thvarray[30] = thvarray[31] = thvarray[32] = thvarray[33] = GCD_Glue; thvarray[34] = NULL;
4804 thvarray[35] = NULL;
4805
4806 tbox[0].gd.flags = gg_enabled|gg_visible;
4807 tbox[0].gd.u.boxelements = thvarray;
4808 tbox[0].creator = GHVBoxCreate;
4809
4810 memset(&lcgcd,0,sizeof(lcgcd));
4811 memset(&lcbox,0,sizeof(lcbox));
4812 memset(&lclabel,0,sizeof(lclabel));
4813
4814 lclabel[0].text = (unichar_t *) _("Default Ligature Caret Count");
4815 lclabel[0].text_is_1byte = true;
4816 lclabel[0].text_in_resource = true;
4817 lcgcd[0].gd.cid = CID_DefLCCount;
4818 lcgcd[0].gd.label = &lclabel[0];
4819 lcgcd[0].gd.flags = gg_enabled|gg_visible;
4820 lcgcd[0].gd.popup_msg = _("Ligature caret locations are used by a text editor\nwhen it needs to draw a text edit caret inside a\nligature. This means there should be a caret between\neach ligature component so if there are n components\nthere should be n-1 caret locations.\n You may adjust the caret locations themselves in the\noutline glyph view (drag them from to origin to the\nappropriate place)." );
4821 lcgcd[0].gd.handle_controlevent = CI_DefLCChange;
4822 lcgcd[0].creator = GCheckBoxCreate;
4823 lchvarray[0][0] = &lcgcd[0];
4824 lchvarray[0][1] = lchvarray[0][2] = GCD_Glue; lchvarray[0][3] = NULL;
4825
4826 lclabel[1].text = (unichar_t *) _("Ligature Caret Count:");
4827 lclabel[1].text_is_1byte = true;
4828 lclabel[1].text_in_resource = true;
4829 lcgcd[1].gd.label = &lclabel[1];
4830 lcgcd[1].gd.flags = gg_enabled|gg_visible;
4831 lcgcd[1].gd.cid = CID_LCCountLab;
4832 lcgcd[1].gd.popup_msg = _("Ligature caret locations are used by a text editor\nwhen it needs to draw a text edit caret inside a\nligature. This means there should be a caret between\neach ligature component so if there are n components\nthere should be n-1 caret locations.\n You may adjust the caret locations themselves in the\noutline glyph view (drag them from to origin to the\nappropriate place)." );
4833 lcgcd[1].creator = GLabelCreate;
4834 lchvarray[1][0] = &lcgcd[1];
4835
4836 lcgcd[2].gd.pos.width = 50;
4837 lcgcd[2].gd.flags = gg_enabled|gg_visible;
4838 lcgcd[2].gd.cid = CID_LCCount;
4839 lcgcd[2].gd.popup_msg = _("Ligature caret locations are used by a text editor\nwhen it needs to draw a text edit caret inside a\nligature. This means there should be a caret between\neach ligature component so if there are n components\nthere should be n-1 caret locations.\n You may adjust the caret locations themselves in the\noutline glyph view (drag them from to origin to the\nappropriate place)." );
4840 lcgcd[2].creator = GNumericFieldCreate;
4841 lchvarray[1][1] = &lcgcd[2]; lchvarray[1][2] = GCD_Glue; lchvarray[1][3] = NULL;
4842
4843 lchvarray[2][0] = lchvarray[2][1] = lchvarray[2][2] = GCD_Glue;
4844 lchvarray[2][3] = lchvarray[3][0] = NULL;
4845
4846 lcbox[0].gd.flags = gg_enabled|gg_visible;
4847 lcbox[0].gd.u.boxelements = lchvarray[0];
4848 lcbox[0].creator = GHVBoxCreate;
4849
4850 memset(&vargcd,0,sizeof(vargcd));
4851 memset(&varbox,0,sizeof(varbox));
4852 memset(&varlabel,0,sizeof(varlabel));
4853
4854 for ( i=0; i<2; ++i ) {
4855 varlabel[i][0].text = (unichar_t *) _("Variant Glyphs:");
4856 varlabel[i][0].text_is_1byte = true;
4857 vargcd[i][0].gd.label = &varlabel[i][0];
4858 vargcd[i][0].gd.pos.x = 5; vargcd[i][0].gd.pos.y = 57+4;
4859 vargcd[i][0].gd.flags = gg_enabled|gg_visible;
4860 vargcd[i][0].creator = GLabelCreate;
4861 vargcd[i][0].gd.popup_msg = _("A list of the names of pre defined glyphs which represent\nbigger versions of the current glyph.");
4862 varhvarray[i][0][0] = &vargcd[i][0];
4863
4864 vargcd[i][1].gd.flags = gg_enabled|gg_visible;
4865 vargcd[i][1].gd.cid = CID_VariantList+i*100;
4866 vargcd[i][1].creator = GTextCompletionCreate;
4867 vargcd[i][1].gd.popup_msg = vargcd[i][0].gd.popup_msg;
4868 varhvarray[i][0][1] = &vargcd[i][1]; varhvarray[i][0][2] = GCD_ColSpan; varhvarray[i][0][3] = NULL;
4869
4870 varlabel[i][2].text = (unichar_t *) _("Glyph Extension Components");
4871 varlabel[i][2].text_is_1byte = true;
4872 vargcd[i][2].gd.label = &varlabel[i][2];
4873 vargcd[i][2].gd.flags = gg_enabled|gg_visible;
4874 vargcd[i][2].creator = GLabelCreate;
4875 vargcd[i][2].gd.popup_msg = _("A really big version of this glyph may be made up of the\nfollowing component glyphs. They will be stacked either\nhorizontally or vertically. Glyphs marked as Extenders may\nbe removed or repeated (to make shorter or longer versions).\nThe StartLength is the length of the flat section at the\nstart of the glyph which may be overlapped with the previous\nglyph, while the EndLength is the similar region at the end\nof the glyph. The FullLength is the full length of the glyph." );
4876 varhvarray[i][1][0] = &vargcd[i][2];
4877 varhvarray[i][1][1] = varhvarray[i][1][2] = GCD_ColSpan; varhvarray[i][1][3] = NULL;
4878
4879 /* GT: "Cor" is an abbreviation for correction */
4880 varlabel[i][3].text = (unichar_t *) _("Italic Cor:");
4881 varlabel[i][3].text_is_1byte = true;
4882 vargcd[i][3].gd.label = &varlabel[i][3];
4883 vargcd[i][3].gd.flags = gg_enabled|gg_visible;
4884 vargcd[i][3].creator = GLabelCreate;
4885 vargcd[i][3].gd.popup_msg = _("The italic correction of the composed glyph. Should be independent of glyph size");
4886 varhvarray[i][2][0] = &vargcd[i][3];
4887
4888 vargcd[i][4].gd.flags = gg_enabled|gg_visible;
4889 vargcd[i][4].gd.pos.width = 60;
4890 vargcd[i][4].gd.cid = CID_ExtItalicCor+i*100;
4891 vargcd[i][4].creator = GTextFieldCreate;
4892 vargcd[i][4].gd.popup_msg = vargcd[i][3].gd.popup_msg;
4893 varhvarray[i][2][1] = &vargcd[i][4];
4894
4895 vargcd[i][5].gd.flags = gg_enabled|gg_visible;
4896 vargcd[i][5].gd.pos.width = 60;
4897 vargcd[i][5].gd.cid = CID_ExtItalicDev+i*100;
4898 vargcd[i][5].creator = GTextFieldCreate;
4899 vargcd[i][5].gd.popup_msg = vargcd[i][3].gd.popup_msg;
4900 varhvarray[i][2][2] = &vargcd[i][5];
4901 varhvarray[i][2][3] = NULL;
4902
4903 vargcd[i][6].gd.flags = gg_enabled|gg_visible;
4904 vargcd[i][6].gd.u.matrix = &mi_extensionpart;
4905 vargcd[i][6].gd.cid = CID_ExtensionList+i*100;
4906 vargcd[i][6].creator = GMatrixEditCreate;
4907 varhvarray[i][3][0] = &vargcd[i][6];
4908 varhvarray[i][3][1] = varhvarray[i][3][2] = GCD_ColSpan; varhvarray[i][3][3] = NULL;
4909
4910 varhvarray[i][4][0] = NULL;
4911
4912 varbox[i][0].gd.flags = gg_enabled|gg_visible;
4913 varbox[i][0].gd.u.boxelements = varhvarray[i][0];
4914 varbox[i][0].creator = GHVBoxCreate;
4915 }
4916
4917 memset(&tilegcd,0,sizeof(tilegcd));
4918 memset(&tilebox,0,sizeof(tilebox));
4919 memset(&tilelabel,0,sizeof(tilelabel));
4920
4921 i=0;
4922 tilelabel[i].text = (unichar_t *) _(
4923 "If this glyph is used as a pattern to tile\n"
4924 "some other glyph then it is useful to specify\n"
4925 "the amount of whitespace surrounding the tile.\n"
4926 "Either specify a margin to extend the bounding\n"
4927 "box of the contents, or specify the bounds\n"
4928 "explicitly.");
4929 tilelabel[i].text_is_1byte = true;
4930 tilelabel[i].text_in_resource = true;
4931 tilegcd[i].gd.label = &tilelabel[i];
4932 tilegcd[i].gd.flags = gg_enabled|gg_visible;
4933 tilegcd[i++].creator = GLabelCreate;
4934 tlvarray[0] = &tilegcd[i-1];
4935
4936 tilelabel[i].text = (unichar_t *) _("Tile Margin:");
4937 tilelabel[i].text_is_1byte = true;
4938 tilelabel[i].text_in_resource = true;
4939 tilegcd[i].gd.label = &tilelabel[i];
4940 tilegcd[i].gd.flags = gg_enabled|gg_visible;
4941 tilegcd[i].gd.cid = CID_IsTileMargin;
4942 tilegcd[i++].creator = GRadioCreate;
4943 tlharray[0] = &tilegcd[i-1];
4944
4945 tilegcd[i].gd.pos.width = 60;
4946 tilegcd[i].gd.flags = gg_enabled|gg_visible;
4947 tilegcd[i].gd.cid = CID_TileMargin;
4948 tilegcd[i].gd.handle_controlevent = CI_TileMarginChange;
4949 tilegcd[i++].creator = GTextFieldCreate;
4950 tlharray[1] = &tilegcd[i-1]; tlharray[2] = GCD_Glue; tlharray[3] = NULL;
4951
4952 tilebox[2].gd.flags = gg_enabled|gg_visible;
4953 tilebox[2].gd.u.boxelements = tlharray;
4954 tilebox[2].creator = GHBoxCreate;
4955 tlvarray[1] = &tilebox[2];
4956
4957 tilelabel[i].text = (unichar_t *) _("Tile Bounding Box:");
4958 tilelabel[i].text_is_1byte = true;
4959 tilelabel[i].text_in_resource = true;
4960 tilegcd[i].gd.label = &tilelabel[i];
4961 tilegcd[i].gd.flags = gg_enabled|gg_visible;
4962 tilegcd[i].gd.cid = CID_IsTileBBox;
4963 tilegcd[i++].creator = GRadioCreate;
4964 tlvarray[2] = &tilegcd[i-1];
4965
4966 tlhvarray[0][0] = GCD_Glue;
4967
4968 tilelabel[i].text = (unichar_t *) _(" X");
4969 tilelabel[i].text_is_1byte = true;
4970 tilegcd[i].gd.label = &tilelabel[i];
4971 tilegcd[i].gd.flags = gg_enabled|gg_visible;
4972 tilegcd[i++].creator = GLabelCreate;
4973 tlhvarray[0][1] = &tilegcd[i-1];
4974
4975 tilelabel[i].text = (unichar_t *) _(" Y");
4976 tilelabel[i].text_is_1byte = true;
4977 tilegcd[i].gd.label = &tilelabel[i];
4978 tilegcd[i].gd.flags = gg_enabled|gg_visible;
4979 tilegcd[i++].creator = GLabelCreate;
4980 tlhvarray[0][2] = &tilegcd[i-1]; tlhvarray[0][3] = GCD_Glue; tlhvarray[0][4] = NULL;
4981
4982 tilelabel[i].text = (unichar_t *) _("Min");
4983 tilelabel[i].text_is_1byte = true;
4984 tilegcd[i].gd.label = &tilelabel[i];
4985 tilegcd[i].gd.flags = gg_enabled|gg_visible;
4986 tilegcd[i++].creator = GLabelCreate;
4987 tlhvarray[1][0] = &tilegcd[i-1];
4988
4989 tilegcd[i].gd.flags = gg_enabled|gg_visible;
4990 tilegcd[i].gd.cid = CID_TileBBoxMinX;
4991 tilegcd[i++].creator = GTextFieldCreate;
4992 tlhvarray[1][1] = &tilegcd[i-1];
4993
4994 tilegcd[i].gd.flags = gg_enabled|gg_visible;
4995 tilegcd[i].gd.cid = CID_TileBBoxMinY;
4996 tilegcd[i++].creator = GTextFieldCreate;
4997 tlhvarray[1][2] = &tilegcd[i-1]; tlhvarray[1][3] = GCD_Glue; tlhvarray[1][4] = NULL;
4998
4999 tilelabel[i].text = (unichar_t *) _("Max");
5000 tilelabel[i].text_is_1byte = true;
5001 tilegcd[i].gd.label = &tilelabel[i];
5002 tilegcd[i].gd.flags = gg_enabled|gg_visible;
5003 tilegcd[i++].creator = GLabelCreate;
5004 tlhvarray[2][0] = &tilegcd[i-1];
5005
5006 tilegcd[i].gd.flags = gg_enabled|gg_visible;
5007 tilegcd[i].gd.cid = CID_TileBBoxMaxX;
5008 tilegcd[i++].creator = GTextFieldCreate;
5009 tlhvarray[2][1] = &tilegcd[i-1];
5010
5011 tilegcd[i].gd.flags = gg_enabled|gg_visible;
5012 tilegcd[i].gd.cid = CID_TileBBoxMaxY;
5013 tilegcd[i++].creator = GTextFieldCreate;
5014 tlhvarray[2][2] = &tilegcd[i-1]; tlhvarray[2][3] = GCD_Glue; tlhvarray[2][4] = NULL;
5015 tlhvarray[3][0] = NULL;
5016
5017 tilebox[3].gd.flags = gg_enabled|gg_visible;
5018 tilebox[3].gd.u.boxelements = tlhvarray[0];
5019 tilebox[3].creator = GHVBoxCreate;
5020 tlvarray[3] = &tilebox[3]; tlvarray[4] = GCD_Glue; tlvarray[5] = NULL;
5021
5022 tilebox[0].gd.flags = gg_enabled|gg_visible;
5023 tilebox[0].gd.u.boxelements = tlvarray;
5024 tilebox[0].creator = GVBoxCreate;
5025
5026 memset(&mgcd,0,sizeof(mgcd));
5027 memset(&mbox,0,sizeof(mbox));
5028 memset(&mlabel,0,sizeof(mlabel));
5029 memset(&aspects,'\0',sizeof(aspects));
5030
5031 i = 0;
5032 aspects[i].text = (unichar_t *) _("Unicode");
5033 aspects[i].text_is_1byte = true;
5034 aspects[i].selected = true;
5035 aspects[i++].gcd = ubox;
5036
5037 aspects[i].text = (unichar_t *) _("Comment");
5038 aspects[i].text_is_1byte = true;
5039 aspects[i++].gcd = cbox;
5040
5041 aspects[i].text = (unichar_t *) _("Positionings");
5042 aspects[i].text_is_1byte = true;
5043 aspects[i++].gcd = pstbox[pst_position-1];
5044
5045 aspects[i].text = (unichar_t *) _("Pairwise Pos");
5046 aspects[i].text_is_1byte = true;
5047 aspects[i++].gcd = pstbox[pst_pair-1];
5048
5049 aspects[i].text = (unichar_t *) _("Substitutions");
5050 aspects[i].text_is_1byte = true;
5051 aspects[i++].gcd = psgcd[2];
5052
5053 aspects[i].text = (unichar_t *) _("Alt Subs");
5054 aspects[i].text_is_1byte = true;
5055 aspects[i++].gcd = psgcd[3];
5056
5057 aspects[i].text = (unichar_t *) _("Mult Subs");
5058 aspects[i].text_is_1byte = true;
5059 aspects[i++].gcd = psgcd[4];
5060
5061 aspects[i].text = (unichar_t *) _("Ligatures");
5062 aspects[i].text_is_1byte = true;
5063 aspects[i++].gcd = psgcd[5];
5064
5065 ci->lc_aspect = i;
5066 aspects[i].text = (unichar_t *) _("Lig. Carets");
5067 aspects[i].text_is_1byte = true;
5068 aspects[i].nesting = 1;
5069 aspects[i++].gcd = lcbox;
5070
5071 aspects[i].text = (unichar_t *) _("Components");
5072 aspects[i].text_is_1byte = true;
5073 aspects[i++].gcd = cobox;
5074
5075 aspects[i].text = (unichar_t *) _("Counters");
5076 aspects[i].text_is_1byte = true;
5077 aspects[i++].gcd = pstbox[6];
5078
5079 aspects[i].text = (unichar_t *) U_("΀ΔΧ & Math"); /* TeX */
5080 aspects[i].text_is_1byte = true;
5081 aspects[i++].gcd = tbox;
5082
5083 ci->vert_aspect = i;
5084 /* GT: "Vert." is an abbreviation for Vertical */
5085 aspects[i].text = (unichar_t *) U_("Vert. Variants");
5086 aspects[i].text_is_1byte = true;
5087 aspects[i].nesting = 1;
5088 aspects[i++].gcd = varbox[0];
5089
5090 /* GT: "Horiz." is an abbreviation for Horizontal */
5091 aspects[i].text = (unichar_t *) U_("Horiz. Variants");
5092 aspects[i].text_is_1byte = true;
5093 aspects[i].nesting = 1;
5094 aspects[i++].gcd = varbox[1];
5095
5096 if ( sc->parent->multilayer ) {
5097 aspects[i].text = (unichar_t *) U_("Tile Size");
5098 aspects[i].text_is_1byte = true;
5099 aspects[i++].gcd = tilebox;
5100 }
5101
5102 if ( last_gi_aspect<i )
5103 aspects[last_gi_aspect].selected = true;
5104
5105 mgcd[0].gd.pos.x = 4; mgcd[0].gd.pos.y = 6;
5106 mgcd[0].gd.u.tabs = aspects;
5107 mgcd[0].gd.flags = gg_visible | gg_enabled | gg_tabset_vert;
5108 mgcd[0].gd.cid = CID_Tabs;
5109 mgcd[0].gd.handle_controlevent = CI_AspectChange;
5110 mgcd[0].creator = GTabSetCreate;
5111 mvarray[0] = &mgcd[0]; mvarray[1] = NULL;
5112
5113 mgcd[1].gd.pos.x = 40; mgcd[1].gd.pos.y = mgcd[0].gd.pos.y+mgcd[0].gd.pos.height+3;
5114 mgcd[1].gd.flags = gg_visible | gg_enabled ;
5115 mlabel[1].text = (unichar_t *) _("< _Prev");
5116 mlabel[1].text_is_1byte = true;
5117 mlabel[1].text_in_resource = true;
5118 mgcd[1].gd.mnemonic = 'P';
5119 mgcd[1].gd.label = &mlabel[1];
5120 mgcd[1].gd.handle_controlevent = CI_NextPrev;
5121 mgcd[1].gd.cid = -1;
5122 mharray1[0] = GCD_Glue; mharray1[1] = &mgcd[1]; mharray1[2] = GCD_Glue;
5123 mgcd[1].creator = GButtonCreate;
5124
5125 mgcd[2].gd.pos.x = -40; mgcd[2].gd.pos.y = mgcd[1].gd.pos.y;
5126 mgcd[2].gd.flags = gg_visible | gg_enabled ;
5127 mlabel[2].text = (unichar_t *) _("_Next >");
5128 mlabel[2].text_is_1byte = true;
5129 mlabel[2].text_in_resource = true;
5130 mgcd[2].gd.label = &mlabel[2];
5131 mgcd[2].gd.mnemonic = 'N';
5132 mgcd[2].gd.handle_controlevent = CI_NextPrev;
5133 mgcd[2].gd.cid = 1;
5134 mharray1[3] = GCD_Glue; mharray1[4] = &mgcd[2]; mharray1[5] = GCD_Glue; mharray1[6] = NULL;
5135 mgcd[2].creator = GButtonCreate;
5136
5137 mbox[2].gd.flags = gg_enabled|gg_visible;
5138 mbox[2].gd.u.boxelements = mharray1;
5139 mbox[2].creator = GHBoxCreate;
5140 mvarray[2] = &mbox[2]; mvarray[3] = NULL;
5141
5142 mgcd[3].gd.pos.x = 25-3; mgcd[3].gd.pos.y = CI_Height-31-3;
5143 mgcd[3].gd.flags = gg_visible | gg_enabled | gg_but_default;
5144 mlabel[3].text = (unichar_t *) _("_OK");
5145 mlabel[3].text_is_1byte = true;
5146 mlabel[3].text_in_resource = true;
5147 mgcd[3].gd.mnemonic = 'O';
5148 mgcd[3].gd.label = &mlabel[3];
5149 mgcd[3].gd.handle_controlevent = CI_OK;
5150 mharray2[0] = GCD_Glue; mharray2[1] = &mgcd[3]; mharray2[2] = GCD_Glue; mharray2[3] = GCD_Glue;
5151 mgcd[3].creator = GButtonCreate;
5152
5153 mgcd[4].gd.pos.x = -25; mgcd[4].gd.pos.y = mgcd[3].gd.pos.y+3;
5154 mgcd[4].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
5155 mlabel[4].text = (unichar_t *) _("_Cancel");
5156 mlabel[4].text_is_1byte = true;
5157 mlabel[4].text_in_resource = true;
5158 mgcd[4].gd.label = &mlabel[4];
5159 mgcd[4].gd.handle_controlevent = CI_Cancel;
5160 mgcd[4].gd.cid = CID_Cancel;
5161 mharray2[4] = GCD_Glue; mharray2[5] = &mgcd[4]; mharray2[6] = GCD_Glue; mharray2[7] = NULL;
5162 mgcd[4].creator = GButtonCreate;
5163
5164 mbox[3].gd.flags = gg_enabled|gg_visible;
5165 mbox[3].gd.u.boxelements = mharray2;
5166 mbox[3].creator = GHBoxCreate;
5167 mvarray[4] = &mbox[3]; mvarray[5] = NULL;
5168 mvarray[6] = NULL;
5169
5170 mbox[0].gd.pos.x = mbox[0].gd.pos.y = 2;
5171 mbox[0].gd.flags = gg_enabled|gg_visible;
5172 mbox[0].gd.u.boxelements = mvarray;
5173 mbox[0].creator = GHVGroupCreate;
5174
5175 GGadgetsCreate(ci->gw,mbox);
5176
5177 GHVBoxSetExpandableRow(mbox[0].ret,0);
5178 GHVBoxSetExpandableCol(mbox[2].ret,gb_expandgluesame);
5179 GHVBoxSetExpandableCol(mbox[3].ret,gb_expandgluesame);
5180
5181 GHVBoxSetExpandableRow(ubox[0].ret,gb_expandglue);
5182 GHVBoxSetExpandableCol(ubox[0].ret,1);
5183 GHVBoxSetExpandableCol(ubox[2].ret,gb_expandgluesame);
5184
5185 GHVBoxSetExpandableRow(cbox[0].ret,1);
5186 GHVBoxSetExpandableCol(cbox[2].ret,gb_expandglue);
5187
5188 for ( i=0; i<6; ++i ) {
5189 GGadget *g = GWidgetGetControl(ci->gw,CID_List+i*100);
5190 GMatrixEditSetNewText(g, newstrings[i]);
5191 if ( i==pst_substitution-1 || i==pst_pair-1 )
5192 GMatrixEditSetColumnCompletion(g,1,CI_GlyphNameCompletion);
5193 else if ( i==pst_alternate-1 || i==pst_multiple-1 ||
5194 i==pst_ligature-1)
5195 GMatrixEditSetColumnCompletion(g,1,CI_GlyphListCompletion);
5196 }
5197 GHVBoxSetExpandableRow(pstbox[pst_pair-1][0].ret,0);
5198 for ( i=0; i<6; ++i )
5199 GMatrixEditSetMouseMoveReporter(psgcd[i][0].ret,CI_SubsPopupPrepare);
5200 GMatrixEditSetMouseMoveReporter(psgcd[pst_pair-1][0].ret,CI_KerningPopupPrepare);
5201 for ( i=6; i<7; ++i ) {
5202 GHVBoxSetExpandableRow(pstbox[i][0].ret,0);
5203 GHVBoxSetExpandableCol(pstbox[i][2].ret,gb_expandgluesame);
5204 }
5205
5206 GHVBoxSetExpandableRow(cobox[0].ret,gb_expandglue);
5207 GHVBoxSetExpandableRow(tbox[0].ret,gb_expandglue);
5208 GHVBoxSetExpandableCol(tbox[0].ret,gb_expandglue);
5209 GHVBoxSetPadding(tbox[0].ret,6,4);
5210 GHVBoxSetExpandableCol(tbox[2].ret,gb_expandglue);
5211
5212 GHVBoxSetExpandableRow(lcbox[0].ret,gb_expandglue);
5213 GHVBoxSetExpandableCol(lcbox[0].ret,gb_expandglue);
5214
5215 GHVBoxSetExpandableRow(varbox[0][0].ret,3);
5216 GHVBoxSetExpandableRow(varbox[1][0].ret,3);
5217
5218 if ( sc->parent->multilayer ) {
5219 GHVBoxSetExpandableRow(tilebox[0].ret,gb_expandglue);
5220 GHVBoxSetExpandableCol(tilebox[2].ret,gb_expandglue);
5221 GHVBoxSetExpandableCol(tilebox[3].ret,gb_expandglue);
5222 }
5223
5224 GHVBoxFitWindow(mbox[0].ret);
5225
5226 for ( i=0; i<5; ++i )
5227 GGadgetSetFont(psgcd[i][0].ret,glyphinfo_font.fi);
5228 for ( i=0; i<2; ++i ) {
5229 GCompletionFieldSetCompletion(vargcd[i][1].ret,CI_GlyphNameCompletion);
5230 GCompletionFieldSetCompletionMode(vargcd[i][1].ret,true);
5231 GMatrixEditSetColumnCompletion(vargcd[i][6].ret,0,CI_GlyphNameCompletion);
5232 GMatrixEditSetMouseMoveReporter(vargcd[i][6].ret,CI_ConstructionPopupPrepare);
5233 }
5234
5235 CIFillup(ci);
5236
5237 GDrawSetVisible(ci->gw,true);
5238 }
5239
5240 void CharInfoDestroy(CharInfo *ci) {
5241 GDrawDestroyWindow(ci->gw);
5242 }
5243
5244 struct sel_dlg {
5245 int done;
5246 int ok;
5247 FontView *fv;
5248 };
5249
5250 int FVParseSelectByPST(FontView *fv,struct lookup_subtable *sub,
5251 int search_type) {
5252 int first;
5253
5254 first = FVBParseSelectByPST((FontViewBase *) fv,sub,search_type);
5255
5256 if ( first!=-1 )
5257 FVScrollToChar(fv,first);
5258 else if ( !no_windowing_ui )
5259 ff_post_notice(_("Select By ATT..."),_("No glyphs matched"));
5260 if ( !no_windowing_ui )
5261 GDrawRequestExpose(fv->v,NULL,false);
5262 return( true );
5263 }
5264
5265 static int SelectStuff(struct sel_dlg *sld,GWindow gw) {
5266 struct lookup_subtable *sub = GGadgetGetListItemSelected(GWidgetGetControl(gw,CID_PST))->userdata;
5267 int search_type = GGadgetIsChecked(GWidgetGetControl(gw,CID_SelectResults)) ? 1 :
5268 GGadgetIsChecked(GWidgetGetControl(gw,CID_MergeResults)) ? 2 :
5269 3;
5270 return( FVParseSelectByPST(sld->fv, sub, search_type));
5271 }
5272
5273 static int selpst_e_h(GWindow gw, GEvent *event) {
5274 struct sel_dlg *sld = GDrawGetUserData(gw);
5275
5276 if ( event->type==et_close ) {
5277 sld->done = true;
5278 sld->ok = false;
5279 } else if ( event->type==et_char ) {
5280 if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) {
5281 help("ui/dialogs/selectbyatt.html", NULL);
5282 return( true );
5283 }
5284 return( false );
5285 } else if ( event->type==et_controlevent && event->u.control.subtype == et_buttonactivate ) {
5286 sld->ok = GGadgetGetCid(event->u.control.g);
5287 if ( !sld->ok || SelectStuff(sld,gw))
5288 sld->done = true;
5289 }
5290 return( true );
5291 }
5292
5293 void FVSelectByPST(FontView *fv) {
5294 struct sel_dlg sld;
5295 GWindow gw;
5296 GRect pos;
5297 GWindowAttrs wattrs;
5298 GGadgetCreateData gcd[14];
5299 GTextInfo label[14];
5300 GGadgetCreateData *varray[20], *harray[8];
5301 int i,j,isgpos, cnt;
5302 OTLookup *otl;
5303 struct lookup_subtable *sub;
5304 GTextInfo *ti;
5305 SplineFont *sf = fv->b.sf;
5306
5307 if ( sf->cidmaster ) sf = sf->cidmaster;
5308 ti = NULL;
5309 for ( j=0; j<2; ++j ) {
5310 cnt = 0;
5311 for ( isgpos=0; isgpos<2; ++isgpos ) {
5312 for ( otl = isgpos ? sf->gpos_lookups : sf->gsub_lookups ; otl!=NULL; otl=otl->next ) {
5313 if ( otl->lookup_type== gsub_single ||
5314 otl->lookup_type== gsub_multiple ||
5315 otl->lookup_type== gsub_alternate ||
5316 otl->lookup_type== gsub_ligature ||
5317 otl->lookup_type== gpos_single ||
5318 otl->lookup_type== gpos_pair ||
5319 otl->lookup_type== gpos_cursive ||
5320 otl->lookup_type== gpos_mark2base ||
5321 otl->lookup_type== gpos_mark2ligature ||
5322 otl->lookup_type== gpos_mark2mark )
5323 for ( sub=otl->subtables; sub!=NULL; sub=sub->next )
5324 if ( sub->kc==NULL ) {
5325 if ( ti!=NULL ) {
5326 ti[cnt].text = (unichar_t *) copy(sub->subtable_name);
5327 ti[cnt].text_is_1byte = true;
5328 ti[cnt].userdata = sub;
5329 ti[cnt].selected = cnt==0;
5330 }
5331 ++cnt;
5332 }
5333 }
5334 }
5335 if ( cnt==0 ) {
5336 ff_post_notice(_("No Lookups"), _("No applicable lookup subtables"));
5337 return;
5338 }
5339 if ( ti==NULL )
5340 ti = calloc(cnt+1,sizeof(GTextInfo));
5341 }
5342
5343 CharInfoInit();
5344
5345 memset(&sld,0,sizeof(sld));
5346 sld.fv = fv;
5347 memset(&wattrs,0,sizeof(wattrs));
5348 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict;
5349 wattrs.event_masks = ~(1<<et_charup);
5350 wattrs.restrict_input_to_me = 1;
5351 wattrs.undercursor = 1;
5352 wattrs.cursor = ct_pointer;
5353 wattrs.utf8_window_title = _("Select By Lookup Subtable");
5354 wattrs.is_dlg = true;
5355 pos.x = pos.y = 0;
5356 pos.width = GGadgetScale(GDrawPointsToPixels(NULL,160));
5357 pos.height = GDrawPointsToPixels(NULL,204);
5358 gw = GDrawCreateTopWindow(NULL,&pos,selpst_e_h,&sld,&wattrs);
5359
5360 memset(&gcd,0,sizeof(gcd));
5361 memset(&label,0,sizeof(label));
5362
5363 i=j=0;
5364
5365 label[i].text = (unichar_t *) _("Select Glyphs in lookup subtable");
5366 label[i].text_is_1byte = true;
5367 gcd[i].gd.label = &label[i];
5368 gcd[i].gd.flags = gg_enabled|gg_visible;
5369 gcd[i++].creator = GLabelCreate;
5370 varray[j++] = &gcd[i-1]; varray[j++] = NULL;
5371
5372 gcd[i].gd.label = &ti[0];
5373 gcd[i].gd.pos.x = 10; gcd[i].gd.pos.y = 5+4;
5374 gcd[i].gd.flags = gg_enabled|gg_visible/*|gg_list_exactlyone*/;
5375 gcd[i].gd.u.list = ti;
5376 gcd[i].gd.cid = CID_PST;
5377 gcd[i++].creator = GListButtonCreate;
5378 varray[j++] = &gcd[i-1]; varray[j++] = NULL;
5379 varray[j++] = GCD_Glue; varray[j++] = NULL;
5380
5381 label[i].text = (unichar_t *) _("Select Results");
5382 label[i].text_is_1byte = true;
5383 gcd[i].gd.label = &label[i];
5384 gcd[i].gd.pos.x = 5; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y+26;
5385 gcd[i].gd.flags = gg_enabled|gg_visible|gg_cb_on;
5386 gcd[i].gd.popup_msg = _("Set the selection of the font view to the glyphs\nfound by this search");
5387 gcd[i].gd.cid = CID_SelectResults;
5388 gcd[i++].creator = GRadioCreate;
5389 varray[j++] = &gcd[i-1]; varray[j++] = NULL;
5390
5391 label[i].text = (unichar_t *) _("Merge Results");
5392 label[i].text_is_1byte = true;
5393 gcd[i].gd.label = &label[i];
5394 gcd[i].gd.pos.x = 5; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y+15;
5395 gcd[i].gd.flags = gg_enabled|gg_visible;
5396 gcd[i].gd.popup_msg = _("Expand the selection of the font view to include\nall the glyphs found by this search");
5397 gcd[i].gd.cid = CID_MergeResults;
5398 gcd[i++].creator = GRadioCreate;
5399 varray[j++] = &gcd[i-1]; varray[j++] = NULL;
5400
5401 label[i].text = (unichar_t *) _("Restrict Selection");
5402 label[i].text_is_1byte = true;
5403 gcd[i].gd.label = &label[i];
5404 gcd[i].gd.pos.x = 5; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y+15;
5405 gcd[i].gd.flags = gg_enabled|gg_visible;
5406 gcd[i].gd.popup_msg = _("Only search the selected glyphs, and unselect\nany characters which do not match this search");
5407 gcd[i].gd.cid = CID_RestrictSelection;
5408 gcd[i++].creator = GRadioCreate;
5409 varray[j++] = &gcd[i-1]; varray[j++] = NULL;
5410 varray[j++] = GCD_Glue; varray[j++] = NULL;
5411
5412 gcd[i].gd.pos.x = 15-3; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y+22;
5413 gcd[i].gd.flags = gg_visible | gg_enabled | gg_but_default;
5414 label[i].text = (unichar_t *) _("_OK");
5415 label[i].text_is_1byte = true;
5416 label[i].text_in_resource = true;
5417 gcd[i].gd.mnemonic = 'O';
5418 gcd[i].gd.label = &label[i];
5419 gcd[i].gd.cid = true;
5420 gcd[i++].creator = GButtonCreate;
5421 harray[0] = GCD_Glue; harray[1] = &gcd[i-1]; harray[2] = GCD_Glue;
5422
5423 gcd[i].gd.pos.x = -15; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y+3;
5424 gcd[i].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
5425 label[i].text = (unichar_t *) _("_Cancel");
5426 label[i].text_is_1byte = true;
5427 label[i].text_in_resource = true;
5428 gcd[i].gd.label = &label[i];
5429 gcd[i].gd.mnemonic = 'C';
5430 gcd[i].gd.cid = false;
5431 gcd[i++].creator = GButtonCreate;
5432 harray[3] = GCD_Glue; harray[4] = &gcd[i-1]; harray[5] = GCD_Glue;
5433 harray[6] = NULL;
5434
5435 gcd[i].gd.flags = gg_enabled|gg_visible;
5436 gcd[i].gd.u.boxelements = harray;
5437 gcd[i].creator = GHBoxCreate;
5438 varray[j++] = &gcd[i++]; varray[j++] = NULL; varray[j++] = NULL;
5439
5440 gcd[i].gd.pos.x = gcd[i].gd.pos.y = 2;
5441 gcd[i].gd.flags = gg_enabled|gg_visible;
5442 gcd[i].gd.u.boxelements = varray;
5443 gcd[i].creator = GHVGroupCreate;
5444
5445 GGadgetsCreate(gw,gcd+i);
5446 GTextInfoListFree(ti);
5447 GHVBoxSetExpandableRow(gcd[i].ret,gb_expandglue);
5448 GHVBoxSetExpandableCol(gcd[i-1].ret,gb_expandgluesame);
5449 GHVBoxFitWindow(gcd[i].ret);
5450
5451 GDrawSetVisible(gw,true);
5452 while ( !sld.done )
5453 GDrawProcessOneEvent(NULL);
5454 if ( sld.ok ) {
5455 }
5456 GDrawDestroyWindow(gw);
5457 }
5458
5459 void CharInfoInit(void) {
5460 static GTextInfo *lists[] = { glyphclasses, std_colors, truefalse, NULL };
5461 static int done = 0;
5462 int i, j;
5463 static char **cnames[] = { newstrings, NULL };
5464 static struct col_init *col_inits[] = { extensionpart, altuniinfo,
5465 devtabci,
5466 simplesubsci, ligatureci, altsubsci, multsubsci, simpleposci,
5467 pairposci, NULL };
5468
5469 if ( done )
5470 return;
5471 done = true;
5472 for ( i=0; lists[i]!=NULL; ++i )
5473 for ( j=0; lists[i][j].text!=NULL; ++j )
5474 lists[i][j].text = (unichar_t *) S_((char *) lists[i][j].text);
5475 for ( i=0; cnames[i]!=NULL; ++i )
5476 for ( j=0; cnames[i][j]!=NULL; ++j )
5477 cnames[i][j] = _(cnames[i][j]);
5478 for ( i=0; col_inits[i]!=NULL; ++i )
5479 for ( j=0; col_inits[i][j].title!=NULL; ++j )
5480 col_inits[i][j].title=_(col_inits[i][j].title);
5481 }