Debian Codegraph @

fontforgeexe/cvhints.c

raw symbols SCIP
1 /* Copyright (C) 2000-2012 by George Williams */
2 /*
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
8
9 * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12
13 * The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <fontforge-config.h>
29
30 #include "autohint.h"
31 #include "cvundoes.h"
32 #include "fontforgeui.h"
33 #include "ustring.h"
34
35 #include <math.h>
36
37 #define CID_Base 1001
38 #define CID_Width 1002
39 #define CID_Label 1003
40 #define CID_HStem 1004
41 #define CID_VStem 1005
42 #define CID_Next 1006
43 #define CID_Prev 1007
44 #define CID_Remove 1008
45 #define CID_Add 1009
46 #define CID_Overlap 1010
47 #define CID_Count 1011
48 #define CID_MovePoints 1012
49 #define CID_RegenHM 1013
50 #define CID_TopBox 1014
51
52 typedef struct reviewhintdata {
53 unsigned int done: 1;
54 unsigned int ishstem: 1;
55 unsigned int oldmanual: 1;
56 unsigned int undocreated: 1;
57 unsigned int changed: 1;
58 CharView *cv;
59 GWindow gw;
60 StemInfo *active;
61 StemInfo *lastactive;
62 StemInfo *oldh, *oldv;
63 } ReviewHintData;
64
65 static void RH_SetNextPrev(ReviewHintData *hd) {
66 if ( hd->active==NULL ) {
67 GGadgetSetEnabled(GWidgetGetControl(hd->gw,CID_Next),false);
68 GGadgetSetEnabled(GWidgetGetControl(hd->gw,CID_Prev),false);
69 GGadgetSetEnabled(GWidgetGetControl(hd->gw,CID_Remove),false);
70 GGadgetSetEnabled(GWidgetGetControl(hd->gw,CID_Base),false);
71 GGadgetSetEnabled(GWidgetGetControl(hd->gw,CID_Width),false);
72 } else {
73 GGadgetSetEnabled(GWidgetGetControl(hd->gw,CID_Remove),true);
74 GGadgetSetEnabled(GWidgetGetControl(hd->gw,CID_Base),true);
75 GGadgetSetEnabled(GWidgetGetControl(hd->gw,CID_Width),true);
76 GGadgetSetEnabled(GWidgetGetControl(hd->gw,CID_Next),hd->active->next!=NULL);
77 if ( hd->ishstem )
78 GGadgetSetEnabled(GWidgetGetControl(hd->gw,CID_Prev),hd->active!=hd->cv->b.sc->hstem);
79 else
80 GGadgetSetEnabled(GWidgetGetControl(hd->gw,CID_Prev),hd->active!=hd->cv->b.sc->vstem);
81 }
82 GDrawRequestExpose(hd->gw,NULL,false);
83 }
84
85 static void RH_SetupHint(ReviewHintData *hd) {
86 char buffer[20]; unichar_t ubuf[20];
87 static unichar_t nullstr[] = {'\0'};
88 StemInfo *h;
89 int pos,cnt;
90
91 if ( hd->lastactive!=NULL )
92 hd->lastactive->active = false;
93
94 pos = cnt = 0;
95 for ( h=hd->ishstem ? hd->cv->b.sc->hstem : hd->cv->b.sc->vstem; h!=NULL; h=h->next ) {
96 ++cnt;
97 if ( h==hd->active ) pos=cnt;
98 }
99 sprintf( buffer,"%d/%d", pos, cnt );
100 if ( cnt==3 ) {
101 StemInfo *h2, *h3;
102 h = hd->ishstem ? hd->cv->b.sc->hstem : hd->cv->b.sc->vstem;
103 h2 = h->next; h3 = h2->next;
104 if ( h->width == h2->width && h2->width==h3->width &&
105 h2->start-h->start == h3->start-h2->start )
106 strcat( buffer, hd->ishstem ? " hstem3" : " vstem3" );
107 }
108 uc_strcpy(ubuf,buffer);
109 GGadgetSetTitle(GWidgetGetControl(hd->gw,CID_Count),ubuf);
110
111 if ( hd->active==NULL ) {
112 GGadgetSetTitle(GWidgetGetControl(hd->gw,CID_Base),nullstr);
113 GGadgetSetTitle(GWidgetGetControl(hd->gw,CID_Width),nullstr);
114 GGadgetSetVisible(GWidgetGetControl(hd->gw,CID_Overlap),false);
115 } else {
116 hd->active->active = true;
117 sprintf( buffer,"%g", (double) (!hd->active->ghost ? hd->active->start : hd->active->start+hd->active->width) );
118 uc_strcpy(ubuf,buffer);
119 GGadgetSetTitle(GWidgetGetControl(hd->gw,CID_Base),ubuf);
120 GTextFieldShow(GWidgetGetControl(hd->gw,CID_Base),0);
121 sprintf( buffer,"%g", (double) (!hd->active->ghost ? hd->active->width : -hd->active->width) );
122 uc_strcpy(ubuf,buffer);
123 GGadgetSetTitle(GWidgetGetControl(hd->gw,CID_Width),ubuf);
124 GTextFieldShow(GWidgetGetControl(hd->gw,CID_Width),0);
125 GGadgetSetVisible(GWidgetGetControl(hd->gw,CID_Overlap),hd->active->hasconflicts);
126 }
127 if ( hd->lastactive!=hd->active ) {
128 hd->lastactive = hd->active;
129 SCUpdateAll(hd->cv->b.sc); /* Changing the active Hint means we should redraw everything */
130 }
131 RH_SetNextPrev(hd);
132 }
133
134 static int OnHint(StemInfo *hint,real major,real minor) {
135 HintInstance *hi;
136
137 if ( true /*hint->hasconflicts*/ ) {
138 for ( hi=hint->where; hi!=NULL; hi=hi->next ) {
139 if ( minor>=hi->begin && minor<=hi->end )
140 break;
141 }
142 if ( hi==NULL )
143 return( 0 );
144 /* Ok, it's active */
145 }
146 if ( major==hint->start )
147 return( 1 );
148 else if ( major==hint->start+hint->width )
149 return( 2 );
150
151 return( 0 );
152 }
153
154 static void RH_MovePoints(ReviewHintData *hd,StemInfo *active,int start,int width) {
155 SplineChar *sc = hd->cv->b.sc;
156 SplineSet *spl;
157 SplinePoint *sp;
158 int which;
159 int layer = CVLayer( (CharViewBase *) (hd->cv));
160
161 if ( !hd->undocreated ) {
162 SCPreserveLayer(sc,layer,true);
163 hd->undocreated = true;
164 }
165
166 for ( spl=sc->layers[layer].splines; spl!=NULL; spl=spl->next ) {
167 for ( sp = spl->first ; ; ) {
168 if ( hd->ishstem ) {
169 switch ((which = OnHint(active,sp->me.y,sp->me.x)) ) {
170 case 1:
171 sp->nextcp.y += start-sp->me.y;
172 sp->prevcp.y += start-sp->me.y;
173 sp->me.y = start;
174 break;
175 case 2:
176 sp->nextcp.y += start+width-sp->me.y;
177 sp->prevcp.y += start+width-sp->me.y;
178 sp->me.y = start+width;
179 break;
180 case 0:
181 /* Not on hint */;
182 break;
183 }
184 } else {
185 switch ( (which = OnHint(active,sp->me.x,sp->me.y)) ) {
186 case 1:
187 sp->nextcp.x += start-sp->me.x;
188 sp->prevcp.x += start-sp->me.x;
189 sp->me.x = start;
190 break;
191 case 2:
192 sp->nextcp.x += start+width-sp->me.x;
193 sp->prevcp.x += start+width-sp->me.x;
194 sp->me.x = start+width;
195 break;
196 case 0:
197 /* Not on hint */;
198 break;
199 }
200 }
201 if ( which ) {
202 if ( sp->prev )
203 SplineRefigure(sp->prev);
204 if ( sp->next )
205 SplineRefigure(sp->next);
206 }
207 if ( sp->next==NULL )
208 break;
209 sp = sp->next->to;
210 if ( sp== spl->first )
211 break;
212 }
213 }
214 }
215
216 static int RH_TextChanged(GGadget *g, GEvent *e) {
217 int wasconflict;
218 if ( e->type==et_controlevent && e->u.control.subtype == et_textchanged ) {
219 ReviewHintData *hd = GDrawGetUserData(GGadgetGetWindow(g));
220 if ( hd->active!=NULL ) {
221 int cid = GGadgetGetCid(g);
222 int err=0;
223 real start = GetCalmReal8(hd->gw,CID_Base,_("Base:"),&err);
224 real width = GetCalmReal8(hd->gw,CID_Width,_("Size:"),&err);
225 if ( err )
226 return( true );
227 if ( GGadgetIsChecked(GWidgetGetControl(GGadgetGetWindow(g),CID_MovePoints)) ) {
228 if ( width<0 )
229 RH_MovePoints(hd,hd->active,start+width,-width);
230 else
231 RH_MovePoints(hd,hd->active,start,width);
232 }
233 if ( cid==CID_Base )
234 hd->active->start = start;
235 else
236 hd->active->width = width;
237 if ( width<0 ) {
238 hd->active->ghost = true;
239 hd->active->width = -width;
240 hd->active->start = start+width;
241 } else
242 hd->active->ghost = false;
243 wasconflict = hd->active->hasconflicts;
244 if ( hd->ishstem )
245 hd->cv->b.sc->hconflicts = StemListAnyConflicts(hd->cv->b.sc->hstem);
246 else
247 hd->cv->b.sc->vconflicts = StemListAnyConflicts(hd->cv->b.sc->vstem);
248 hd->cv->b.sc->manualhints = true;
249 hd->changed = true;
250 if ( wasconflict!=hd->active->hasconflicts ) {
251 GGadgetSetVisible(GWidgetGetControl(hd->gw,CID_Overlap),hd->active->hasconflicts);
252 if ( hd->active->hasconflicts )
253 GHVBoxFitWindow(GWidgetGetControl(hd->gw,CID_TopBox));
254 }
255 SCUpdateAll(hd->cv->b.sc);
256 }
257 }
258 return( true );
259 }
260
261 static void Do_OKRegen(ReviewHintData *hd) {
262 SplineChar *sc = hd->cv->b.sc;
263 StemInfo *curh = sc->hstem, *curv = sc->vstem;
264 int do_regen = GGadgetIsChecked(GWidgetGetControl(hd->gw,CID_RegenHM));
265
266 /* We go backwards here, but not for long. The point is to go back to */
267 /* the original hint state so we can preserve it, now that we know we*/
268 /* are going to modify it */
269 sc->hstem = hd->oldh; sc->vstem = hd->oldv;
270 SCPreserveHints(sc,CVLayer((CharViewBase *) hd->cv));
271 sc->hstem = curh; sc->vstem = curv;
272
273 StemInfosFree(hd->oldh);
274 StemInfosFree(hd->oldv);
275 if ( hd->lastactive!=NULL )
276 hd->lastactive->active = false;
277 if ( hd->changed ) {
278 SCClearHintMasks(hd->cv->b.sc,CVLayer((CharViewBase *) (hd->cv)),true);
279 if ( do_regen )
280 SCFigureHintMasks(hd->cv->b.sc,CVLayer((CharViewBase *) (hd->cv)));
281 }
282 /* Everything else got done as we went along... */
283 SCUpdateAll(hd->cv->b.sc);
284 SCHintsChanged(hd->cv->b.sc);
285 hd->done = true;
286 }
287
288 static int RH_OK(GGadget *g, GEvent *e) {
289 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
290 ReviewHintData *hd = GDrawGetUserData(GGadgetGetWindow(g));
291 Do_OKRegen(hd);
292 }
293 return( true );
294 }
295
296 static void DoCancel(ReviewHintData *hd) {
297 StemInfosFree(hd->cv->b.sc->hstem);
298 StemInfosFree(hd->cv->b.sc->vstem);
299 hd->cv->b.sc->hstem = hd->oldh;
300 hd->cv->b.sc->vstem = hd->oldv;
301 hd->cv->b.sc->hconflicts = StemListAnyConflicts(hd->cv->b.sc->hstem);
302 hd->cv->b.sc->vconflicts = StemListAnyConflicts(hd->cv->b.sc->vstem);
303 hd->cv->b.sc->manualhints = hd->oldmanual;
304 if ( hd->undocreated )
305 SCDoUndo(hd->cv->b.sc,ly_fore);
306 SCUpdateAll(hd->cv->b.sc);
307 hd->done = true;
308 }
309
310 static int RH_Cancel(GGadget *g, GEvent *e) {
311 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
312 DoCancel( GDrawGetUserData(GGadgetGetWindow(g)));
313 }
314 return( true );
315 }
316
317 static int RH_Remove(GGadget *g, GEvent *e) {
318 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
319 ReviewHintData *hd = GDrawGetUserData(GGadgetGetWindow(g));
320 StemInfo *prev;
321 if ( hd->active==NULL )
322 return( true ); /* Eh? */
323 if ( hd->active==hd->cv->b.sc->hstem ) {
324 hd->cv->b.sc->hstem = hd->active->next;
325 prev = hd->cv->b.sc->hstem;
326 } else if ( hd->active==hd->cv->b.sc->vstem ) {
327 hd->cv->b.sc->vstem = hd->active->next;
328 prev = hd->cv->b.sc->vstem;
329 } else {
330 prev = hd->ishstem ? hd->cv->b.sc->hstem : hd->cv->b.sc->vstem;
331 for ( ; prev->next!=hd->active && prev->next!=NULL; prev = prev->next );
332 prev->next = hd->active->next;
333 }
334 if ( hd->ishstem )
335 hd->cv->b.sc->hconflicts = StemListAnyConflicts(hd->cv->b.sc->hstem);
336 else
337 hd->cv->b.sc->vconflicts = StemListAnyConflicts(hd->cv->b.sc->vstem);
338 hd->cv->b.sc->manualhints = true;
339 hd->changed = true;
340 StemInfoFree( hd->active );
341 hd->active = prev;
342 RH_SetupHint(hd);
343 /*SCUpdateAll(hd->cv->b.sc);*/ /* Done in RH_SetupHint now */
344 }
345 return( true );
346 }
347
348 static int RH_Add(GGadget *g, GEvent *e) {
349 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
350 ReviewHintData *hd = GDrawGetUserData(GGadgetGetWindow(g));
351 CVCreateHint(hd->cv,hd->ishstem,false);
352 hd->active = hd->ishstem ? hd->cv->b.sc->hstem : hd->cv->b.sc->vstem;
353 RH_SetupHint(hd);
354 }
355 return( true );
356 }
357
358 static int RH_NextPrev(GGadget *g, GEvent *e) {
359 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
360 ReviewHintData *hd = GDrawGetUserData(GGadgetGetWindow(g));
361 StemInfo *prev;
362 if ( GGadgetGetCid(g)==CID_Next ) {
363 if ( hd->active->next !=NULL )
364 hd->active = hd->active->next;
365 } else {
366 prev = hd->ishstem ? hd->cv->b.sc->hstem : hd->cv->b.sc->vstem;
367 for ( ; prev->next!=hd->active && prev->next!=NULL; prev = prev->next );
368 hd->active = prev;
369 }
370 RH_SetupHint(hd);
371 }
372 return( true );
373 }
374
375 static int RH_HVStem(GGadget *g, GEvent *e) {
376 if ( e->type==et_controlevent && e->u.control.subtype == et_radiochanged ) {
377 ReviewHintData *hd = GDrawGetUserData(GGadgetGetWindow(g));
378 hd->ishstem = GGadgetIsChecked(GWidgetGetControl(GGadgetGetWindow(g),CID_HStem));
379 hd->active = hd->ishstem ? hd->cv->b.sc->hstem : hd->cv->b.sc->vstem;
380 RH_SetupHint(hd);
381 }
382 return( true );
383 }
384
385 static int rh_e_h(GWindow gw, GEvent *event) {
386 if ( event->type==et_close ) {
387 DoCancel( GDrawGetUserData(gw));
388 } else if ( event->type == et_char ) {
389 return( false );
390 } else if ( event->type == et_map ) {
391 /* Above palettes */
392 GDrawRaise(gw);
393 }
394 return( true );
395 }
396
397 void CVReviewHints(CharView *cv) {
398 GRect pos;
399 GWindow gw;
400 GWindowAttrs wattrs;
401 GGadgetCreateData gcd[18], *harray1[6], *harray2[6], *harray3[6], *harray4[6],
402 *varray[7][2], boxes[8], *barray[6][6];
403 GTextInfo label[18];
404 static ReviewHintData hd;
405 int k;
406
407 hd.done = false;
408 hd.cv = cv;
409
410 if ( hd.gw==NULL ) {
411 memset(&wattrs,0,sizeof(wattrs));
412 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict;
413 wattrs.event_masks = ~(1<<et_charup);
414 wattrs.restrict_input_to_me = 1;
415 wattrs.undercursor = 1;
416 wattrs.cursor = ct_pointer;
417 wattrs.utf8_window_title = _("Review Hints");
418 wattrs.is_dlg = true;
419 pos.x = pos.y = 0;
420 pos.width = GGadgetScale(GDrawPointsToPixels(NULL,170));
421 pos.height = GDrawPointsToPixels(NULL,178);
422 hd.gw = gw = GDrawCreateTopWindow(NULL,&pos,rh_e_h,&hd,&wattrs);
423
424 memset(&label,0,sizeof(label));
425 memset(&gcd,0,sizeof(gcd));
426 memset(&boxes,0,sizeof(boxes));
427
428 k=0;
429
430 label[k].text = (unichar_t *) _("_HStem");
431 label[k].text_is_1byte = true;
432 label[k].text_in_resource = true;
433 gcd[k].gd.label = &label[k];
434 gcd[k].gd.flags = gg_enabled|gg_visible|gg_cb_on;
435 gcd[k].gd.cid = CID_HStem;
436 gcd[k].gd.handle_controlevent = RH_HVStem;
437 gcd[k].creator = GRadioCreate;
438 harray2[0] = &gcd[k++];
439
440 label[k].text = (unichar_t *) _("_VStem");
441 label[k].text_is_1byte = true;
442 label[k].text_in_resource = true;
443 gcd[k].gd.label = &label[k];
444 gcd[k].gd.flags = gg_enabled|gg_visible;
445 gcd[k].gd.cid = CID_VStem;
446 gcd[k].gd.handle_controlevent = RH_HVStem;
447 gcd[k].creator = GRadioCreate;
448 harray2[1] = &gcd[k++];
449
450 label[k].text = (unichar_t *) "999/999 hstem3";
451 label[k].text_is_1byte = true;
452 gcd[k].gd.label = &label[k];
453 gcd[k].gd.flags = gg_enabled|gg_visible;
454 gcd[k].gd.cid = CID_Count;
455 gcd[k].creator = GLabelCreate;
456 harray2[2] = GCD_HPad10; harray2[3] = &gcd[k++]; harray2[4] = GCD_Glue; harray2[5] = NULL;
457
458 label[k].text = (unichar_t *) _("_Move Points");
459 label[k].text_is_1byte = true;
460 label[k].text_in_resource = true;
461 gcd[k].gd.label = &label[k];
462 gcd[k].gd.flags = gg_enabled|gg_visible;
463 gcd[k].gd.cid = CID_MovePoints;
464 gcd[k].gd.popup_msg = _("When the hint's position is changed\nadjust the position of any points\nwhich lie on that hint");
465 gcd[k].creator = GCheckBoxCreate;
466 harray3[0] = &gcd[k++]; harray3[1] = GCD_Glue; harray3[2] = NULL;
467
468 label[k].text = (unichar_t *) _("_Base:");
469 label[k].text_is_1byte = true;
470 label[k].text_in_resource = true;
471 gcd[k].gd.label = &label[k];
472 gcd[k].gd.pos.x = 5; gcd[k].gd.pos.y = 14+17+5+3;
473 gcd[k].gd.flags = gg_enabled|gg_visible;
474 gcd[k].creator = GLabelCreate;
475 harray1[0] = &gcd[k++];
476
477 gcd[k].gd.pos.width = 40;
478 gcd[k].gd.flags = gg_enabled|gg_visible;
479 gcd[k].gd.cid = CID_Base;
480 gcd[k].gd.handle_controlevent = RH_TextChanged;
481 gcd[k].creator = GTextFieldCreate;
482 harray1[1] = &gcd[k++];
483
484 label[k].text = (unichar_t *) _("_Size:");
485 label[k].text_is_1byte = true;
486 label[k].text_in_resource = true;
487 gcd[k].gd.label = &label[k];
488 gcd[k].gd.flags = gg_enabled|gg_visible;
489 gcd[k].creator = GLabelCreate;
490 harray1[2] = &gcd[k++];
491
492 gcd[k].gd.pos.width = 40;
493 gcd[k].gd.flags = gg_enabled|gg_visible;
494 gcd[k].gd.cid = CID_Width;
495 gcd[k].gd.handle_controlevent = RH_TextChanged;
496 gcd[k].creator = GTextFieldCreate;
497 harray1[3] = &gcd[k++]; harray1[4] = GCD_Glue; harray1[5] = NULL;
498
499 gcd[k].gd.flags = gg_visible | gg_enabled;
500 label[k].text = (unichar_t *) "Overlaps another hint";
501 label[k].text_is_1byte = true;
502 label[k].fg = 0xff0000; label[k].bg = COLOR_DEFAULT; /* Doesn't work, needs to be in box */
503 gcd[k].gd.label = &label[k];
504 gcd[k].gd.cid = CID_Overlap;
505 gcd[k].creator = GLabelCreate;
506 harray4[0] = GCD_Glue; harray4[1] = &gcd[k++]; harray4[2] = GCD_Glue; harray4[3] = NULL;
507
508
509 gcd[k].gd.flags = gg_visible | gg_enabled;
510 label[k].text = (unichar_t *) _("Cr_eate");
511 label[k].text_is_1byte = true;
512 label[k].text_in_resource = true;
513 gcd[k].gd.label = &label[k];
514 gcd[k].gd.cid = CID_Add;
515 gcd[k].gd.handle_controlevent = RH_Add;
516 gcd[k].creator = GButtonCreate;
517 barray[0][0] = GCD_Glue; barray[0][1] = &gcd[k++]; barray[0][2] = GCD_Glue;
518
519 gcd[k].gd.flags = gg_visible | gg_enabled;
520 label[k].text = (unichar_t *) _("Re_move");
521 label[k].text_is_1byte = true;
522 label[k].text_in_resource = true;
523 gcd[k].gd.label = &label[k];
524 gcd[k].gd.cid = CID_Remove;
525 gcd[k].gd.handle_controlevent = RH_Remove;
526 gcd[k].creator = GButtonCreate;
527 barray[0][3] = &gcd[k++]; barray[0][4] = GCD_Glue; barray[0][5] = NULL;
528
529 gcd[k].gd.pos.width = 170-10;
530 gcd[k].gd.flags = gg_enabled|gg_visible;
531 gcd[k].creator = GLineCreate;
532 barray[1][0] = GCD_Glue; barray[1][1] = &gcd[k++]; barray[1][2] = barray[1][3] = GCD_ColSpan; barray[1][4] = GCD_Glue; barray[1][5] = NULL;
533
534 gcd[k].gd.flags = gg_visible | gg_enabled;
535 label[k].text = (unichar_t *) _("< _Prev");
536 label[k].text_is_1byte = true;
537 label[k].text_in_resource = true;
538 gcd[k].gd.label = &label[k];
539 gcd[k].gd.cid = CID_Prev;
540 gcd[k].gd.popup_msg = _("Previous Hint.");
541 gcd[k].gd.handle_controlevent = RH_NextPrev;
542 gcd[k].creator = GButtonCreate;
543 barray[2][0] = GCD_Glue; barray[2][1] = &gcd[k++]; barray[2][2] = GCD_Glue;
544
545 gcd[k].gd.flags = gg_visible | gg_enabled;
546 label[k].text = (unichar_t *) _("_Next >");
547 label[k].text_is_1byte = true;
548 label[k].text_in_resource = true;
549 gcd[k].gd.label = &label[k];
550 gcd[k].gd.cid = CID_Next;
551 gcd[k].gd.popup_msg = _("Next Hint.");
552 gcd[k].gd.handle_controlevent = RH_NextPrev;
553 gcd[k].creator = GButtonCreate;
554 barray[2][3] = &gcd[k++]; barray[2][4] = GCD_Glue; barray[2][5] = NULL;
555
556 label[k].text = (unichar_t *) _("Regenerate Hint Substitution Points");
557 label[k].text_is_1byte = true;
558 label[k].text_in_resource = true;
559 gcd[k].gd.label = &label[k];
560 gcd[k].gd.flags = gg_enabled|gg_visible|gg_cb_on;
561 gcd[k].gd.cid = CID_RegenHM;
562 gcd[k].gd.popup_msg = _("If you have made any changes to the hints,\nthen in addition to changing the glyph's hints\nrefigure it's hint masks and substitution points.");
563 gcd[k].creator = GCheckBoxCreate;
564 barray[3][0] = &gcd[k++]; barray[3][1] = barray[3][2] = barray[3][3] = barray[3][4] = GCD_ColSpan; barray[3][5] = NULL;
565
566 gcd[k].gd.flags = gg_visible | gg_enabled;
567 label[k].text = (unichar_t *) _("_OK");
568 label[k].text_is_1byte = true;
569 label[k].text_in_resource = true;
570 gcd[k].gd.label = &label[k];
571 gcd[k].gd.handle_controlevent = RH_OK;
572 gcd[k].creator = GButtonCreate;
573 barray[4][0] = GCD_Glue; barray[4][1] = &gcd[k++]; barray[4][2] = GCD_Glue;
574
575 gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
576 label[k].text = (unichar_t *) _("_Cancel");
577 label[k].text_is_1byte = true;
578 label[k].text_in_resource = true;
579 gcd[k].gd.label = &label[k];
580 gcd[k].gd.handle_controlevent = RH_Cancel;
581 gcd[k].creator = GButtonCreate;
582 barray[4][3] = &gcd[k++]; barray[4][4] = GCD_Glue; barray[4][5] = NULL;
583 barray[5][0] = NULL;
584
585 boxes[2].gd.flags = gg_enabled|gg_visible;
586 boxes[2].gd.u.boxelements = harray2;
587 boxes[2].creator = GHBoxCreate;
588
589 boxes[3].gd.flags = gg_enabled|gg_visible;
590 boxes[3].gd.u.boxelements = harray3;
591 boxes[3].creator = GHBoxCreate;
592
593 boxes[4].gd.flags = gg_enabled|gg_visible;
594 boxes[4].gd.u.boxelements = harray1;
595 boxes[4].creator = GHBoxCreate;
596
597 boxes[5].gd.flags = gg_enabled|gg_visible;
598 boxes[5].gd.u.boxelements = harray4;
599 boxes[5].creator = GHBoxCreate;
600
601 boxes[6].gd.flags = gg_enabled|gg_visible;
602 boxes[6].gd.u.boxelements = barray[0];
603 boxes[6].creator = GHVBoxCreate;
604
605 varray[0][0] = &boxes[2]; varray[0][1] = NULL;
606 varray[1][0] = &boxes[3]; varray[1][1] = NULL;
607 varray[2][0] = &boxes[4]; varray[2][1] = NULL;
608 varray[3][0] = &boxes[5]; varray[3][1] = NULL;
609 varray[4][0] = &boxes[6]; varray[4][1] = NULL;
610 varray[5][0] = NULL;
611
612 boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2;
613 boxes[0].gd.flags = gg_enabled|gg_visible;
614 boxes[0].gd.u.boxelements = varray[0];
615 boxes[0].gd.cid = CID_TopBox;
616 boxes[0].creator = GHVGroupCreate;
617
618
619 GGadgetsCreate(gw,boxes);
620
621 GHVBoxSetExpandableRow(boxes[0].ret,3);
622 GHVBoxSetExpandableCol(boxes[2].ret,gb_expandglue);
623 GHVBoxSetExpandableCol(boxes[3].ret,gb_expandglue);
624 GHVBoxSetExpandableCol(boxes[4].ret,gb_expandglue);
625 GHVBoxSetExpandableCol(boxes[5].ret,gb_expandglue);
626 GHVBoxSetExpandableCol(boxes[6].ret,gb_expandglue);
627 GHVBoxFitWindow(boxes[0].ret);
628 } else {
629 gw = hd.gw;
630 GDrawSetTransientFor(gw,(GWindow) -1);
631 }
632 if ( cv->b.sc->hstem==NULL && cv->b.sc->vstem==NULL )
633 hd.active = NULL;
634 else if ( cv->b.sc->hstem!=NULL && cv->b.sc->vstem!=NULL ) {
635 if ( GGadgetIsChecked(GWidgetGetControl(gw,CID_HStem)))
636 hd.active = cv->b.sc->hstem;
637 else
638 hd.active = cv->b.sc->vstem;
639 } else if ( cv->b.sc->hstem!=NULL ) {
640 GGadgetSetChecked(GWidgetGetControl(gw,CID_HStem),true);
641 hd.active = cv->b.sc->hstem;
642 } else {
643 GGadgetSetChecked(GWidgetGetControl(gw,CID_VStem),true);
644 hd.active = cv->b.sc->vstem;
645 }
646 hd.ishstem = (hd.active==cv->b.sc->hstem);
647 hd.oldh = StemInfoCopy(cv->b.sc->hstem);
648 hd.oldv = StemInfoCopy(cv->b.sc->vstem);
649 hd.oldmanual = cv->b.sc->manualhints;
650 hd.changed = false;
651 RH_SetupHint(&hd);
652 if ( hd.active!=NULL ) {
653 GWidgetIndicateFocusGadget(GWidgetGetControl(gw,CID_Base));
654 GTextFieldSelect(GWidgetGetControl(gw,CID_Base),0,-1);
655 }
656
657 GDrawSetVisible(gw,true);
658 while ( !hd.done )
659 GDrawProcessOneEvent(NULL);
660 GDrawSetVisible(gw,false);
661 }
662
663 typedef struct createhintdata {
664 unsigned int done: 1;
665 unsigned int ishstem: 1;
666 unsigned int preservehints: 1;
667 CharView *cv;
668 GWindow gw;
669 } CreateHintData;
670
671 static int CH_OK(GGadget *g, GEvent *e) {
672 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
673 CreateHintData *hd = GDrawGetUserData(GGadgetGetWindow(g));
674 real base, width;
675 int err = 0;
676 StemInfo *h;
677 int layer = CVLayer((CharViewBase *) hd->cv);
678
679 base = GetReal8(hd->gw,CID_Base,_("Base:"),&err);
680 width = GetReal8(hd->gw,CID_Width,_("Size:"),&err);
681 if ( err )
682 return(true);
683 if ( hd->preservehints ) {
684 SCPreserveHints(hd->cv->b.sc,layer);
685 SCHintsChanged(hd->cv->b.sc);
686 }
687 h = chunkalloc(sizeof(StemInfo));
688 if ( width==-21 || width==-20 ) {
689 base += width;
690 width = -width;
691 h->ghost = true;
692 }
693 h->start = base;
694 h->width = width;
695 if ( hd->ishstem ) {
696 SCGuessHHintInstancesAndAdd(hd->cv->b.sc,layer,h,0x80000000,0x80000000);
697 hd->cv->b.sc->hconflicts = StemListAnyConflicts(hd->cv->b.sc->hstem);
698 } else {
699 SCGuessVHintInstancesAndAdd(hd->cv->b.sc,layer,h,0x80000000,0x80000000);
700 hd->cv->b.sc->vconflicts = StemListAnyConflicts(hd->cv->b.sc->vstem);
701 }
702 hd->cv->b.sc->manualhints = true;
703 if ( h!=NULL && hd->cv->b.sc->parent->mm==NULL )
704 SCModifyHintMasksAdd(hd->cv->b.sc,layer,h);
705 else
706 SCClearHintMasks(hd->cv->b.sc,layer,true);
707 SCUpdateAll(hd->cv->b.sc);
708 hd->done = true;
709 }
710 return( true );
711 }
712
713 static int CH_Cancel(GGadget *g, GEvent *e) {
714 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
715 CreateHintData *hd = GDrawGetUserData(GGadgetGetWindow(g));
716 hd->done = true;
717 }
718 return( true );
719 }
720
721 static int chd_e_h(GWindow gw, GEvent *event) {
722 if ( event->type==et_close ) {
723 CreateHintData *hd = GDrawGetUserData(gw);
724 hd->done = true;
725 } else if ( event->type == et_char ) {
726 return( false );
727 } else if ( event->type == et_map ) {
728 /* Above palettes */
729 GDrawRaise(gw);
730 }
731 return( true );
732 }
733
734 void CVCreateHint(CharView *cv,int ishstem,int preservehints) {
735 GRect pos;
736 GWindow gw;
737 GWindowAttrs wattrs;
738 GGadgetCreateData gcd[9], *harray1[4], *harray2[9], *barray[7], *varray[5][2], boxes[5];
739 GTextInfo label[9];
740 static CreateHintData chd;
741 char buffer[20]; unichar_t ubuf[20];
742
743 chd.done = false;
744 chd.ishstem = ishstem;
745 chd.preservehints = preservehints;
746 chd.cv = cv;
747
748 if ( chd.gw==NULL ) {
749 memset(&wattrs,0,sizeof(wattrs));
750 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict;
751 wattrs.event_masks = ~(1<<et_charup);
752 wattrs.restrict_input_to_me = 1;
753 wattrs.undercursor = 1;
754 wattrs.cursor = ct_pointer;
755 wattrs.utf8_window_title = _("Create Hint");
756 wattrs.is_dlg = true;
757 pos.x = pos.y = 0;
758 pos.width = GGadgetScale(GDrawPointsToPixels(NULL,170));
759 pos.height = GDrawPointsToPixels(NULL,90);
760 chd.gw = gw = GDrawCreateTopWindow(NULL,&pos,chd_e_h,&chd,&wattrs);
761
762 memset(&label,0,sizeof(label));
763 memset(&gcd,0,sizeof(gcd));
764 memset(&boxes,0,sizeof(boxes));
765
766 label[0].text = (unichar_t *) _("_Base:");
767 label[0].text_is_1byte = true;
768 label[0].text_in_resource = true;
769 gcd[0].gd.label = &label[0];
770 gcd[0].gd.pos.x = 5; gcd[0].gd.pos.y = 17+5+6;
771 gcd[0].gd.flags = gg_enabled|gg_visible;
772 gcd[0].creator = GLabelCreate;
773 harray2[0] = GCD_Glue; harray2[1] = &gcd[0];
774
775 sprintf( buffer, "%g", (double) (ishstem ? cv->p.cy : cv->p.cx) );
776 label[1].text = (unichar_t *) buffer;
777 label[1].text_is_1byte = true;
778 gcd[1].gd.label = &label[1];
779 gcd[1].gd.pos.x = 37; gcd[1].gd.pos.y = 17+5; gcd[1].gd.pos.width = 40;
780 gcd[1].gd.flags = gg_enabled|gg_visible;
781 gcd[1].gd.cid = CID_Base;
782 gcd[1].creator = GTextFieldCreate;
783 harray2[2] = &gcd[1];
784
785 label[2].text = (unichar_t *) _("_Size:");
786 label[2].text_is_1byte = true;
787 label[2].text_in_resource = true;
788 gcd[2].gd.label = &label[2];
789 gcd[2].gd.pos.x = 90; gcd[2].gd.pos.y = 17+5+6;
790 gcd[2].gd.flags = gg_enabled|gg_visible;
791 gcd[2].creator = GLabelCreate;
792 harray2[3] = GCD_Glue; harray2[4] = &gcd[2];
793
794 label[3].text = (unichar_t *) "60";
795 label[3].text_is_1byte = true;
796 gcd[3].gd.label = &label[3];
797 gcd[3].gd.pos.x = 120; gcd[3].gd.pos.y = 17+5; gcd[3].gd.pos.width = 40;
798 gcd[3].gd.flags = gg_enabled|gg_visible;
799 gcd[3].gd.cid = CID_Width;
800 gcd[3].creator = GTextFieldCreate;
801 harray2[5] = &gcd[3]; harray2[6] = GCD_Glue; harray2[7] = NULL;
802
803 gcd[4].gd.pos.x = 20-3; gcd[4].gd.pos.y = 17+37;
804 gcd[4].gd.pos.width = -1; gcd[4].gd.pos.height = 0;
805 gcd[4].gd.flags = gg_visible | gg_enabled | gg_but_default;
806 label[4].text = (unichar_t *) _("_OK");
807 label[4].text_is_1byte = true;
808 label[4].text_in_resource = true;
809 gcd[4].gd.mnemonic = 'O';
810 gcd[4].gd.label = &label[4];
811 gcd[4].gd.handle_controlevent = CH_OK;
812 gcd[4].creator = GButtonCreate;
813 barray[0] = GCD_Glue; barray[1] = &gcd[4]; barray[2] = GCD_Glue;
814
815 gcd[5].gd.pos.x = -20; gcd[5].gd.pos.y = 17+37+3;
816 gcd[5].gd.pos.width = -1; gcd[5].gd.pos.height = 0;
817 gcd[5].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
818 label[5].text = (unichar_t *) _("_Cancel");
819 label[5].text_is_1byte = true;
820 label[5].text_in_resource = true;
821 gcd[5].gd.label = &label[5];
822 gcd[5].gd.mnemonic = 'C';
823 gcd[5].gd.handle_controlevent = CH_Cancel;
824 gcd[5].creator = GButtonCreate;
825 barray[3] = GCD_Glue; barray[4] = &gcd[5]; barray[5] = GCD_Glue; barray[6] = NULL;
826
827 label[6].text = (unichar_t *) _("Create Horizontal Stem Hint"); /* Initialize to bigger size */
828 label[6].text_is_1byte = true;
829 gcd[6].gd.label = &label[6];
830 gcd[6].gd.pos.x = 17; gcd[6].gd.pos.y = 5;
831 gcd[6].gd.flags = gg_enabled|gg_visible;
832 gcd[6].gd.cid = CID_Label;
833 gcd[6].creator = GLabelCreate;
834 harray1[0] = GCD_Glue; harray1[1] = &gcd[6]; harray1[2] = GCD_Glue; harray1[3] = NULL;
835
836 gcd[7].gd.pos.x = 5; gcd[7].gd.pos.y = 17+31;
837 gcd[7].gd.pos.width = 170-10;
838 gcd[7].gd.flags = gg_enabled|gg_visible;
839 gcd[7].creator = GLineCreate;
840
841 boxes[2].gd.flags = gg_enabled|gg_visible;
842 boxes[2].gd.u.boxelements = harray1;
843 boxes[2].creator = GHBoxCreate;
844
845 boxes[3].gd.flags = gg_enabled|gg_visible;
846 boxes[3].gd.u.boxelements = harray2;
847 boxes[3].creator = GHBoxCreate;
848
849 boxes[4].gd.flags = gg_enabled|gg_visible;
850 boxes[4].gd.u.boxelements = barray;
851 boxes[4].creator = GHBoxCreate;
852
853 varray[0][0] = &boxes[2]; varray[0][1] = NULL;
854 varray[1][0] = &boxes[3]; varray[1][1] = NULL;
855 varray[2][0] = &gcd[7]; varray[2][1] = NULL;
856 varray[3][0] = &boxes[4]; varray[3][1] = NULL;
857 varray[4][0] = NULL;
858
859 boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2;
860 boxes[0].gd.flags = gg_enabled|gg_visible;
861 boxes[0].gd.u.boxelements = varray[0];
862 boxes[0].creator = GHVGroupCreate;
863
864
865 GGadgetsCreate(gw,boxes);
866 GHVBoxSetExpandableCol(boxes[2].ret,gb_expandglue);
867 GHVBoxSetExpandableCol(boxes[3].ret,gb_expandglue);
868 GHVBoxSetExpandableCol(boxes[4].ret,gb_expandgluesame);
869 GHVBoxFitWindow(boxes[0].ret);
870 } else {
871 gw = chd.gw;
872 sprintf( buffer, "%g", (double) (ishstem ? cv->p.cy : cv->p.cx) );
873 uc_strcpy(ubuf,buffer);
874 GGadgetSetTitle(GWidgetGetControl(gw,CID_Base),ubuf);
875 GDrawSetTransientFor(gw,(GWindow) -1);
876 }
877 GGadgetSetTitle8(GWidgetGetControl(gw,CID_Label),
878 ishstem ? _("Create Horizontal Stem Hint") :
879 _("Create Vertical Stem Hint"));
880 GWidgetIndicateFocusGadget(GWidgetGetControl(gw,CID_Base));
881 GTextFieldSelect(GWidgetGetControl(gw,CID_Base),0,-1);
882
883 GDrawSetVisible(gw,true);
884 while ( !chd.done )
885 GDrawProcessOneEvent(NULL);
886 GDrawSetVisible(gw,false);
887 }
888
889 void SCRemoveSelectedMinimumDistances(SplineChar *sc,int inx) {
890 /* Remove any minimum distance where at least one of the two points is */
891 /* selected */
892 MinimumDistance *md, *prev, *next;
893 SplineSet *ss;
894 SplinePoint *sp;
895
896 prev = NULL;
897 for ( md = sc->md; md!=NULL; md = next ) {
898 next = md->next;
899 if ( (inx==2 || inx==md->x) &&
900 ((md->sp1!=NULL && md->sp1->selected) ||
901 (md->sp2!=NULL && md->sp2->selected))) {
902 if ( prev==NULL )
903 sc->md = next;
904 else
905 prev->next = next;
906 chunkfree(md,sizeof(MinimumDistance));
907 } else
908 prev = md;
909 }
910
911 for ( ss=sc->layers[ly_fore].splines; ss!=NULL; ss=ss->next ) {
912 for ( sp=ss->first; ; ) {
913 if ( sp->selected ) {
914 if ( inx==2 ) sp->roundx = sp->roundy = false;
915 else if ( inx==1 ) sp->roundx = false;
916 else sp->roundy = false;
917 }
918 if ( sp->next==NULL )
919 break;
920 sp = sp->next->to;
921 if ( sp==ss->first )
922 break;
923 }
924 }
925 }