Debian Codegraph @

fontforgeexe/problems.cpp

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 <vector>
32 #include <assert.h>
33 #include <math.h>
34
35 extern "C" {
36 #include "fontforgeui.h"
37 #include "gkeysym.h"
38 #include "gresedit.h"
39 #include "gwidget.h"
40 }
41
42 #include "autohint.h"
43 #include "cvundoes.h"
44 #include "fvfonts.h"
45 #include "namelist.h"
46 #include "splineorder2.h"
47 #include "splineoverlap.h"
48 #include "splinesaveafm.h"
49 #include "splineutil.h"
50 #include "splineutil2.h"
51 #include "tottf.h"
52 #include "tottfgpos.h"
53 #include "ttf.h"
54 #include "ustring.h"
55 #include "gtk/find_problems_shim.hpp"
56
57 using ff::dlg::ProblemRecord;
58 using ff::dlg::ProblemTab;
59
60 /* ************************************************************************** */
61 /* ***************************** Problems Dialog **************************** */
62 /* ************************************************************************** */
63
64 GResFont validate_font = GRESFONT_INIT("400 11pt " SANS_UI_FAMILIES);
65
66 struct mgrpl {
67 char *search;
68 char *rpl; /* a rpl of "" means delete (NULL means not found) */
69 };
70
71 struct mlrpl {
72 uint32_t search;
73 uint32_t rpl;
74 };
75
76 struct problems {
77 FontView *fv;
78 CharView *cv;
79 SplineChar *sc;
80 SplineChar *msc;
81 int layer;
82 std::map<int, bool> selected_records;
83 std::map<int, ff::dlg::NumericalValue> record_values;
84 unsigned int explain: 1;
85 unsigned int doneexplain: 1;
86 unsigned int finish: 1;
87 unsigned int ignorethis: 1;
88 double near;
89 char *explaining;
90 double found, expected;
91 double xheight, caph, ascent, descent;
92 GWindow explainw;
93 GGadget *explaintext, *explainvals, *ignoregadg, *topbox;
94 SplineChar *lastcharopened;
95 CharView *cvopened;
96 char *badsubsname;
97 struct lookup_subtable *badsubs_lsubtable;
98 AnchorClass *missinganchor_class;
99 int rpl_cnt, rpl_max;
100 struct mgrpl *mg;
101 struct mlrpl *mlt;
102 char *glyphname;
103 int glyphenc;
104 EncMap *map;
105 };
106
107 static double near=3;
108
109 #define CID_Stop 2001
110 #define CID_Next 2002
111 #define CID_Fix 2003
112 #define CID_ClearAll 2004
113 #define CID_SetAll 2005
114
115 #define CID_OpenPaths 1001
116 #define CID_IntersectingPaths 1002
117 #define CID_PointsTooClose 1003
118 #define CID_XNear 1004
119 #define CID_YNear 1005
120 #define CID_YNearStd 1006
121 #define CID_HintNoPt 1007
122 #define CID_PtNearHint 1008
123 #define CID_HintWidthNear 1009
124 #define CID_LineStd 1014
125 #define CID_Direction 1015
126 #define CID_CpStd 1016
127 #define CID_CpOdd 1017
128 #define CID_CIDMultiple 1018
129 #define CID_CIDBlank 1019
130 #define CID_FlippedRefs 1020
131 #define CID_Bitmaps 1021
132 #define CID_AdvanceWidth 1022
133 #define CID_VAdvanceWidth 1024
134 #define CID_Stem3 1026
135 #define CID_ShowExactStem3 1027
136 #define CID_IrrelevantCP 1028
137 #define CID_BadSubs 1030
138 #define CID_MissingGlyph 1031
139 #define CID_MissingScriptInFeature 1032
140 #define CID_TooManyPoints 1033
141 #define CID_TooManyHints 1035
142 #define CID_TooDeepRefs 1037
143 #define CID_MultUni 1040
144 #define CID_MultName 1041
145 #define CID_PtMatchRefsOutOfDate 1042
146 #define CID_RefBadTransformTTF 1043
147 #define CID_RefBadTransformPS 1044
148 #define CID_MixedContoursRefs 1045
149 #define CID_MissingExtrema 1046
150 #define CID_UniNameMisMatch 1047
151 #define CID_BBYMax 1048
152 #define CID_BBYMin 1049
153 #define CID_BBXMax 1050
154 #define CID_BBXMin 1051
155 #define CID_NonIntegral 1056
156 #define CID_PointsTooFar 1057
157 #define CID_BitmapWidths 1058
158 #define CID_MissingAnchor 1059
159 #define CID_MultUseMyMetrics 1060
160 #define CID_OverlappedHints 1061
161
162
163 static void FixIt(struct problems *p) {
164 SplinePointList *spl;
165 SplinePoint *sp;
166 /*StemInfo *h;*/
167 RefChar *r;
168 int ncp_changed, pcp_changed;
169
170 if ( p->explaining==_("This reference has been flipped, so the paths in it are drawn backwards") ) {
171 for ( r=p->sc->layers[p->layer].refs; r!=NULL && !r->selected; r = r->next );
172 if ( r!=NULL ) {
173 SplineSet *ss, *spl;
174 SCPreserveLayer(p->sc,p->layer,false);
175 ss = p->sc->layers[p->layer].splines;
176 p->sc->layers[p->layer].splines = NULL;
177 SCRefToSplines(p->sc,r,p->layer);
178 for ( spl = p->sc->layers[p->layer].splines; spl!=NULL; spl=spl->next )
179 SplineSetReverse(spl);
180 if ( p->sc->layers[p->layer].splines!=NULL ) {
181 for ( spl = p->sc->layers[p->layer].splines; spl->next!=NULL; spl=spl->next );
182 spl->next = ss;
183 } else
184 p->sc->layers[p->layer].splines = ss;
185 SCCharChangedUpdate(p->sc,p->layer);
186 } else
187 IError("Could not find reference");
188 return;
189 } else if ( p->explaining==_("This glyph's advance width is different from the standard width") ) {
190 SCSynchronizeWidth(p->sc,std::get<int>(p->record_values[CID_AdvanceWidth]),p->sc->width,NULL);
191 return;
192 } else if ( p->explaining==_("This glyph's vertical advance is different from the standard width") ) {
193 p->sc->vwidth=std::get<int>(p->record_values[CID_VAdvanceWidth]);
194 return;
195 }
196
197 if ( p->explaining==_("This glyph is not mapped to any unicode code point, but its name should be.") ||
198 p->explaining==_("This glyph is mapped to a unicode code point which is different from its name.") ) {
199 char buf[100]; const char *newname;
200 SplineChar *foundsc;
201 newname = StdGlyphName(buf,p->sc->unicodeenc,p->sc->parent->uni_interp,p->sc->parent->for_new_glyphs);
202 foundsc = SFHashName(p->sc->parent,newname);
203 if ( foundsc==NULL ) {
204 free(p->sc->name);
205 p->sc->name = copy(newname);
206 } else {
207 ff_post_error(_("Can't fix"), _("The name FontForge would like to assign to this glyph, %.30s, is already used by a different glyph."),
208 newname );
209 }
210 return;
211 }
212
213 sp = NULL;
214 for ( spl=p->sc->layers[p->layer].splines; spl!=NULL; spl=spl->next ) {
215 for ( sp = spl->first; ; ) {
216 if ( sp->selected )
217 break;
218 if ( sp->next==NULL )
219 break;
220 sp = sp->next->to;
221 if ( sp==spl->first )
222 break;
223 }
224 if ( sp->selected )
225 break;
226 }
227 if ( sp==NULL ) {
228 IError("FixIt(): Nothing selected");
229 return;
230 }
231
232 /* I do not handle:
233 _("The two selected points are the endpoints of an open path")
234 _("The paths that make up this glyph intersect one another")
235 _("The selected points are too close to each other")
236 _("The selected line segment is near the italic angle"), _("The control point above the selected point is near the italic angle"), _("The control point below the selected point is near the italic angle"), _("The control point right of the selected point is near the italic angle"), _("The control point left of the selected point is near the italic angle")
237 _("The control point above the selected point is outside the spline segment"), _("The control point below the selected point is outside the spline segment"), _("The control point right of the selected point is outside the spline segment"), _("The control point left of the selected point is outside the spline segment")
238 _("This hint does not control any points")
239 _STR_ProbHint3*
240 _STR_ProbMultUni, STR_ProbMultName
241 */
242
243 SCPreserveLayer(p->sc,p->layer,false);
244 ncp_changed = pcp_changed = false;
245 if ( p->explaining==_("The x coord of the selected point is near the specified value") || p->explaining==_("The selected point is near a vertical stem hint")) {
246 sp->prevcp.x += p->expected-sp->me.x;
247 sp->nextcp.x += p->expected-sp->me.x;
248 sp->me.x = p->expected;
249 ncp_changed = pcp_changed = true;
250 } else if ( p->explaining==_("The selected point is not at integral coordinates") ||
251 p->explaining==_("The selected point does not have integral control points")) {
252 sp->me.x = rint(sp->me.x); sp->me.y = rint(sp->me.y);
253 sp->nextcp.x = rint(sp->nextcp.x); sp->nextcp.y = rint(sp->nextcp.y);
254 sp->prevcp.x = rint(sp->prevcp.x); sp->prevcp.y = rint(sp->prevcp.y);
255 ncp_changed = pcp_changed = true;
256 } else if ( p->explaining==_("The y coord of the selected point is near the specified value") || p->explaining==_("The selected point is near a horizontal stem hint") ||
257 p->explaining==_("The y coord of the selected point is near the baseline") || p->explaining==_("The y coord of the selected point is near the xheight") ||
258 p->explaining==_("The y coord of the selected point is near the cap height") || p->explaining==_("The y coord of the selected point is near the ascender height") ||
259 p->explaining==_("The y coord of the selected point is near the descender height") ) {
260 sp->prevcp.y += p->expected-sp->me.y;
261 sp->nextcp.y += p->expected-sp->me.y;
262 sp->me.y = p->expected;
263 ncp_changed = pcp_changed = true;
264 } else if ( p->explaining==_("The selected spline attains its extrema somewhere other than its endpoints") ) {
265 SplineCharAddExtrema(p->sc,p->sc->layers[p->layer].splines,
266 ae_between_selected,p->sc->parent->ascent+p->sc->parent->descent);
267 } else if ( p->explaining==_("The selected line segment is nearly horizontal") ) {
268 if ( sp->me.y!=p->found ) {
269 sp=sp->next->to;
270 if ( !sp->selected || sp->me.y!=p->found ) {
271 IError("Couldn't find line");
272 return;
273 }
274 }
275 sp->prevcp.y += p->expected-sp->me.y;
276 sp->nextcp.y += p->expected-sp->me.y;
277 sp->me.y = p->expected;
278 ncp_changed = pcp_changed = true;
279 } else if ( p->explaining==_("The control point above the selected point is nearly horizontal") || p->explaining==_("The control point below the selected point is nearly horizontal") ||
280 p->explaining==_("The control point right of the selected point is nearly horizontal") || p->explaining==_("The control point left of the selected point is nearly horizontal") ) {
281 BasePoint *tofix, *other;
282 if ( sp->nextcp.y==p->found ) {
283 tofix = &sp->nextcp;
284 other = &sp->prevcp;
285 } else {
286 tofix = &sp->prevcp;
287 other = &sp->nextcp;
288 }
289 if ( tofix->y!=p->found ) {
290 IError("Couldn't find control point");
291 return;
292 }
293 tofix->y = p->expected;
294 ncp_changed = pcp_changed = true;
295 if ( sp->pointtype==pt_curve || sp->pointtype==pt_hvcurve )
296 other->y = p->expected;
297 else {
298 sp->pointtype = pt_corner;
299 if ( other==&sp->nextcp )
300 ncp_changed = false;
301 else
302 pcp_changed = false;
303 }
304 } else if ( p->explaining==_("The selected line segment is nearly vertical") ) {
305 if ( sp->me.x!=p->found ) {
306 sp=sp->next->to;
307 if ( !sp->selected || sp->me.x!=p->found ) {
308 IError("Couldn't find line");
309 return;
310 }
311 }
312 sp->prevcp.x += p->expected-sp->me.x;
313 sp->nextcp.x += p->expected-sp->me.x;
314 sp->me.x = p->expected;
315 ncp_changed = pcp_changed = true;
316 } else if ( p->explaining==_("The control point above the selected point is nearly vertical") || p->explaining==_("The control point below the selected point is nearly vertical") ||
317 p->explaining==_("The control point right of the selected point is nearly vertical") || p->explaining==_("The control point left of the selected point is nearly vertical") ) {
318 BasePoint *tofix, *other;
319 if ( sp->nextcp.x==p->found ) {
320 tofix = &sp->nextcp;
321 other = &sp->prevcp;
322 } else {
323 tofix = &sp->prevcp;
324 other = &sp->nextcp;
325 }
326 if ( tofix->x!=p->found ) {
327 IError("Couldn't find control point");
328 return;
329 }
330 tofix->x = p->expected;
331 ncp_changed = pcp_changed = true;
332 if ( sp->pointtype==pt_curve || sp->pointtype==pt_hvcurve )
333 other->x = p->expected;
334 else {
335 sp->pointtype = pt_corner;
336 if ( other==&sp->nextcp )
337 ncp_changed = false;
338 else
339 pcp_changed = false;
340 }
341 } else if ( p->explaining==_("This path should have been drawn in a counter-clockwise direction") || p->explaining==_("This path should have been drawn in a clockwise direction") ) {
342 SplineSetReverse(spl);
343 } else if ( p->explaining==_("This glyph contains control points which are probably too close to the main points to alter the look of the spline") ) {
344 double irrelevantfactor = std::get<double>(p->record_values[CID_IrrelevantCP]) / 100.0;
345 if ( sp->next!=NULL ) {
346 double len = sqrt((sp->me.x-sp->next->to->me.x)*(sp->me.x-sp->next->to->me.x) +
347 (sp->me.y-sp->next->to->me.y)*(sp->me.y-sp->next->to->me.y));
348 double cplen = sqrt((sp->me.x-sp->nextcp.x)*(sp->me.x-sp->nextcp.x) +
349 (sp->me.y-sp->nextcp.y)*(sp->me.y-sp->nextcp.y));
350 if ( cplen!=0 && cplen<irrelevantfactor*len ) {
351 sp->nextcp = sp->me;
352 ncp_changed = true;
353 }
354 }
355 if ( sp->prev!=NULL ) {
356 double len = sqrt((sp->me.x-sp->prev->from->me.x)*(sp->me.x-sp->prev->from->me.x) +
357 (sp->me.y-sp->prev->from->me.y)*(sp->me.y-sp->prev->from->me.y));
358 double cplen = sqrt((sp->me.x-sp->prevcp.x)*(sp->me.x-sp->prevcp.x) +
359 (sp->me.y-sp->prevcp.y)*(sp->me.y-sp->prevcp.y));
360 if ( cplen!=0 && cplen<irrelevantfactor*len ) {
361 sp->prevcp = sp->me;
362 pcp_changed = true;
363 }
364 }
365 } else
366 IError("Did not fix: %d", p->explaining );
367 if ( p->sc->layers[p->layer].order2 ) {
368 if ( ncp_changed )
369 SplinePointNextCPChanged2(sp);
370 if ( pcp_changed )
371 SplinePointPrevCPChanged2(sp);
372 }
373 if ( sp->next!=NULL )
374 SplineRefigure(sp->next);
375 if ( sp->prev!=NULL )
376 SplineRefigure(sp->prev);
377 SCCharChangedUpdate(p->sc,p->layer);
378 }
379
380 static int explain_e_h(GWindow gw, GEvent *event) {
381 if ( event->type==et_close ) {
382 struct problems *p = (struct problems *) GDrawGetUserData(gw);
383 p->doneexplain = true;
384 } else if ( event->type==et_controlevent &&
385 event->u.control.subtype == et_buttonactivate ) {
386 struct problems *p = (struct problems *) GDrawGetUserData(gw);
387 if ( GGadgetGetCid(event->u.control.g)==CID_Stop )
388 p->finish = true;
389 else if ( GGadgetGetCid(event->u.control.g)==CID_Fix )
390 FixIt(p);
391 p->doneexplain = true;
392 } else if ( event->type==et_controlevent &&
393 event->u.control.subtype == et_radiochanged ) {
394 struct problems *p = (struct problems *) GDrawGetUserData(gw);
395 p->ignorethis = GGadgetIsChecked(event->u.control.g);
396 } else if ( event->type==et_char ) {
397 if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) {
398 help("ui/dialogs/problems.html", NULL);
399 return( true );
400 }
401 return( false );
402 }
403 return( true );
404 }
405
406 static void ExplainIt(struct problems *p, SplineChar *sc, char *explain,
407 real found, real expected ) {
408 GRect pos;
409 GWindowAttrs wattrs;
410 GGadgetCreateData gcd[9], boxes[3], *varray[10], *barray[14];
411 GTextInfo label[9];
412 char buf[200];
413 SplinePointList *spl; Spline *spline, *first;
414 int fixable;
415
416 if ( !p->explain || p->finish )
417 return;
418 if ( p->explainw==NULL ) {
419 memset(&wattrs,0,sizeof(wattrs));
420 wattrs.mask = (enum window_attr_mask)(wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor);
421 wattrs.event_masks = ~(1<<et_charup);
422 wattrs.undercursor = 1;
423 wattrs.cursor = ct_pointer;
424 wattrs.utf8_window_title = _("Problem explanation");
425 pos.x = pos.y = 0;
426 pos.width = GGadgetScale(GDrawPointsToPixels(NULL,400));
427 pos.height = GDrawPointsToPixels(NULL,86);
428 p->explainw = GDrawCreateTopWindow(NULL,&pos,explain_e_h,p,&wattrs);
429
430 memset(&label,0,sizeof(label));
431 memset(&gcd,0,sizeof(gcd));
432 memset(&boxes,0,sizeof(boxes));
433
434 label[0].text = (unichar_t *) explain;
435 label[0].text_is_1byte = true;
436 gcd[0].gd.label = &label[0];
437 gcd[0].gd.pos.x = 6; gcd[0].gd.pos.y = 6; gcd[0].gd.pos.width = 400-12;
438 gcd[0].gd.flags = (enum gg_flags) (gg_visible | gg_enabled);
439 gcd[0].creator = GLabelCreate;
440 varray[0] = &gcd[0]; varray[1] = NULL;
441
442 label[4].text = (unichar_t *) "";
443 label[4].text_is_1byte = true;
444 gcd[4].gd.label = &label[4];
445 gcd[4].gd.pos.x = 6; gcd[4].gd.pos.y = gcd[0].gd.pos.y+12; gcd[4].gd.pos.width = 400-12;
446 gcd[4].gd.flags = (enum gg_flags) (gg_visible | gg_enabled);
447 gcd[4].creator = GLabelCreate;
448 varray[2] = &gcd[4]; varray[3] = NULL;
449
450 label[5].text = (unichar_t *) _("Ignore this problem in the future");
451 label[5].text_is_1byte = true;
452 gcd[5].gd.label = &label[5];
453 gcd[5].gd.pos.x = 6; gcd[5].gd.pos.y = gcd[4].gd.pos.y+12;
454 gcd[5].gd.flags = (enum gg_flags) (gg_visible | gg_enabled);
455 gcd[5].creator = GCheckBoxCreate;
456 varray[4] = &gcd[5]; varray[5] = NULL;
457
458 gcd[1].gd.pos.x = 15-3; gcd[1].gd.pos.y = gcd[5].gd.pos.y+20;
459 gcd[1].gd.pos.width = -1; gcd[1].gd.pos.height = 0;
460 gcd[1].gd.flags = (enum gg_flags) (gg_visible | gg_enabled | gg_but_default);
461 label[1].text = (unichar_t *) _("_Next");
462 label[1].text_is_1byte = true;
463 label[1].text_in_resource = true;
464 gcd[1].gd.mnemonic = 'N';
465 gcd[1].gd.label = &label[1];
466 gcd[1].gd.cid = CID_Next;
467 gcd[1].creator = GButtonCreate;
468 barray[0] = GCD_Glue; barray[1] = &gcd[1]; barray[2] = GCD_Glue; barray[3] = GCD_Glue;
469
470 gcd[6].gd.pos.x = 200-30; gcd[6].gd.pos.y = gcd[2].gd.pos.y;
471 gcd[6].gd.pos.width = -1; gcd[6].gd.pos.height = 0;
472 gcd[6].gd.flags = /*gg_visible |*/ gg_enabled;
473 label[6].text = (unichar_t *) _("Fix");
474 label[6].text_is_1byte = true;
475 gcd[6].gd.mnemonic = 'F';
476 gcd[6].gd.label = &label[6];
477 gcd[6].gd.cid = CID_Fix;
478 gcd[6].creator = GButtonCreate;
479 barray[4] = GCD_Glue; barray[5] = GCD_Glue; barray[6] = &gcd[6]; barray[7] = GCD_Glue;
480
481 gcd[2].gd.pos.x = -15; gcd[2].gd.pos.y = gcd[1].gd.pos.y+3;
482 gcd[2].gd.pos.width = -1; gcd[2].gd.pos.height = 0;
483 gcd[2].gd.flags = (enum gg_flags) (gg_visible | gg_enabled | gg_but_cancel);
484 label[2].text = (unichar_t *) _("_Stop");
485 label[2].text_is_1byte = true;
486 label[2].text_in_resource = true;
487 gcd[2].gd.label = &label[2];
488 gcd[2].gd.mnemonic = 'S';
489 gcd[2].gd.cid = CID_Stop;
490 gcd[2].creator = GButtonCreate;
491 barray[8] = GCD_Glue; barray[9] = GCD_Glue; barray[10] = GCD_Glue;
492 barray[11] = &gcd[2]; barray[12] = GCD_Glue;
493 barray[13] = NULL;
494
495 boxes[2].gd.flags = (enum gg_flags) (gg_enabled|gg_visible);
496 boxes[2].gd.u.boxelements = barray;
497 boxes[2].creator = GHBoxCreate;
498 varray[6] = &boxes[2]; varray[7] = NULL; varray[8] = NULL;
499
500 boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2;
501 boxes[0].gd.flags = (enum gg_flags) (gg_enabled|gg_visible);
502 boxes[0].gd.u.boxelements = varray;
503 boxes[0].creator = GHVGroupCreate;
504
505 GGadgetsCreate(p->explainw,boxes);
506 GHVBoxSetExpandableCol(boxes[2].ret,gb_expandgluesame);
507 p->explaintext = gcd[0].ret;
508 p->explainvals = gcd[4].ret;
509 p->ignoregadg = gcd[5].ret;
510 p->topbox = boxes[0].ret;
511 } else
512 GGadgetSetTitle8(p->explaintext,explain);
513 p->explaining = explain;
514 fixable = /*explain==_("This glyph contains a horizontal hint near the specified width") || explain==_("This glyph contains a vertical hint near the specified width") ||*/
515 explain==_("This reference has been flipped, so the paths in it are drawn backwards") ||
516 explain==_("The x coord of the selected point is near the specified value") || explain==_("The selected point is near a vertical stem hint") ||
517 explain==_("The y coord of the selected point is near the specified value") || explain==_("The selected point is near a horizontal stem hint") ||
518 explain==_("This glyph contains control points which are probably too close to the main points to alter the look of the spline") ||
519 explain==_("The y coord of the selected point is near the baseline") || explain==_("The y coord of the selected point is near the xheight") ||
520 explain==_("The y coord of the selected point is near the cap height") || explain==_("The y coord of the selected point is near the ascender height") ||
521 explain==_("The y coord of the selected point is near the descender height") ||
522 explain==_("The selected line segment is nearly horizontal") || explain==_("The selected line segment is nearly vertical") ||
523 explain==_("The control point above the selected point is nearly horizontal") || explain==_("The control point below the selected point is nearly horizontal") ||
524 explain==_("The control point right of the selected point is nearly horizontal") || explain==_("The control point left of the selected point is nearly horizontal") ||
525 explain==_("The control point above the selected point is nearly vertical") || explain==_("The control point below the selected point is nearly vertical") ||
526 explain==_("The control point right of the selected point is nearly vertical") || explain==_("The control point left of the selected point is nearly vertical") ||
527 explain==_("This path should have been drawn in a counter-clockwise direction") || explain==_("This path should have been drawn in a clockwise direction") ||
528 explain==_("The selected spline attains its extrema somewhere other than its endpoints") ||
529 explain==_("This glyph's advance width is different from the standard width") ||
530 explain==_("This glyph's vertical advance is different from the standard width") ||
531 explain==_("This glyph is not mapped to any unicode code point, but its name should be.") ||
532 explain==_("The selected point is not at integral coordinates") ||
533 explain==_("The selected point does not have integral control points") ||
534 explain==_("This glyph is mapped to a unicode code point which is different from its name.");
535
536 GGadgetSetVisible(GWidgetGetControl(p->explainw,CID_Fix),fixable);
537
538 if ( explain==_("This glyph contains a substitution or ligature entry which refers to an empty char") ) {
539 snprintf(buf,sizeof(buf),
540 _("%2$.20s refers to an empty character \"%1$.20s\""), p->badsubsname,
541 p->badsubs_lsubtable->subtable_name );
542 } else if ( explain==_("This glyph contains anchor points from some, but not all anchor classes in a subtable") ) {
543 snprintf(buf,sizeof(buf),
544 _("There is no anchor for class %1$.30s in subtable %2$.30s"),
545 p->missinganchor_class->name,
546 p->missinganchor_class->subtable->subtable_name );
547 } else if ( explain==_("Two glyphs share the same unicode code point.\nChange the encoding to \"Glyph Order\" and use\nEdit->Select->Wildcard with the following code point") ) {
548 snprintf(buf,sizeof(buf), _("U+%04x"), sc->unicodeenc );
549 } else if ( explain==_("Two glyphs have the same name.\nChange the encoding to \"Glyph Order\" and use\nEdit->Select->Wildcard with the following name") ) {
550 snprintf(buf,sizeof(buf), _("%.40s"), sc->name );
551 } else if ( found==expected )
552 buf[0]='\0';
553 else {
554 sprintf(buf,_("Found %1$.4g, expected %2$.4g"), (double) found, (double) expected );
555 }
556 p->found = found; p->expected = expected;
557 GGadgetSetTitle8(p->explainvals,buf);
558 GGadgetSetChecked(p->ignoregadg,false);
559 GHVBoxFitWindow(p->topbox);
560
561 p->doneexplain = false;
562 p->ignorethis = false;
563
564 if ( sc!=p->lastcharopened || (CharView *) (sc->views)==NULL ) {
565 if ( CVValid(p->fv->b.sf,p->lastcharopened,p->cvopened) )
566 GDrawDestroyWindow(p->cvopened->gw);
567 p->cvopened = NULL;
568 if ( (CharView *) (sc->views)!=NULL )
569 GDrawRaise(((CharView *) (sc->views))->gw);
570 else
571 p->cvopened = CharViewCreate(sc,p->fv,-1);
572 GDrawSync(NULL);
573 GDrawProcessPendingEvents(NULL);
574 GDrawProcessPendingEvents(NULL);
575 p->lastcharopened = sc;
576 }
577 if ( explain==_("This glyph contains a substitution or ligature entry which refers to an empty char") ) {
578 SCCharInfo(sc,p->layer,p->fv->b.map,-1);
579 GDrawSync(NULL);
580 GDrawProcessPendingEvents(NULL);
581 GDrawProcessPendingEvents(NULL);
582 }
583
584 SCUpdateAll(sc); /* We almost certainly just selected something */
585
586 GDrawSetVisible(p->explainw,true);
587 GDrawRaise(p->explainw);
588
589 while ( !p->doneexplain )
590 GDrawProcessOneEvent(NULL);
591 /*GDrawSetVisible(p->explainw,false);*/ /* KDE gets unhappy about this and refuses to show the window later. I don't know why */
592
593 if ( CVValid(p->fv->b.sf,p->sc,p->cv) ) {
594 CVClearSel(p->cv);
595 } else {
596 for ( spl = p->sc->layers[p->layer].splines; spl!=NULL; spl = spl->next ) {
597 spl->first->selected = false;
598 first = NULL;
599 for ( spline = spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next ) {
600 spline->to->selected = false;
601 if ( first==NULL ) first = spline;
602 }
603 }
604 }
605 }
606
607 static void _ExplainIt(struct problems *p, int enc, char *explain,
608 real found, real expected ) {
609 ExplainIt(p,p->sc=SFMakeChar(p->fv->b.sf,p->fv->b.map,enc),explain,found,expected);
610 }
611
612 /* if they deleted a point or a splineset while we were explaining then we */
613 /* need to do some fix-ups. This routine detects a deletion and lets us know */
614 /* that more processing is needed */
615 static int missing(struct problems *p,SplineSet *test, SplinePoint *sp) {
616 SplinePointList *spl, *check;
617 SplinePoint *tsp;
618
619 if ( !p->explain )
620 return( false );
621
622 if ( CVValid(p->fv->b.sf,p->sc,p->cv) )
623 spl = p->cv->b.layerheads[p->cv->b.drawmode]->splines;
624 else
625 spl = p->sc->layers[p->layer].splines;
626 for ( check = spl; check!=test && check!=NULL; check = check->next );
627 if ( check==NULL )
628 return( true ); /* Deleted splineset */
629
630 if ( sp!=NULL ) {
631 for ( tsp=test->first; tsp!=sp ; ) {
632 if ( tsp->next==NULL )
633 return( true );
634 tsp = tsp->next->to;
635 if ( tsp==test->first )
636 return( true );
637 }
638 }
639 return( false );
640 }
641
642 static int missingspline(struct problems *p,SplineSet *test, Spline *spline) {
643 SplinePointList *spl, *check;
644 Spline *t, *first=NULL;
645
646 if ( !p->explain )
647 return( false );
648
649 if ( CVValid(p->fv->b.sf,p->sc,p->cv) )
650 spl = p->cv->b.layerheads[p->cv->b.drawmode]->splines;
651 else
652 spl = p->sc->layers[p->layer].splines;
653 for ( check = spl; check!=test && check!=NULL; check = check->next );
654 if ( check==NULL )
655 return( true ); /* Deleted splineset */
656
657 for ( t=test->first->next; t!=NULL && t!=first && t!=spline; t = t->to->next )
658 if ( first==NULL ) first = t;
659 return( t!=spline );
660 }
661
662 static int missinghint(StemInfo *base, StemInfo *findme) {
663
664 while ( base!=NULL && base!=findme )
665 base = base->next;
666 return( base==NULL );
667 }
668
669 static int missingschint(StemInfo *findme, SplineChar *sc) {
670 StemInfo *base;
671
672 for ( base = sc->hstem; base!=NULL; base=base->next )
673 if ( base==findme )
674 return( false ); /* Hasn't been deleted */
675 for ( base = sc->vstem; base!=NULL; base=base->next )
676 if ( base==findme )
677 return( false );
678
679 return( true );
680 }
681
682 static int HVITest(struct problems *p,BasePoint *to, BasePoint *from,
683 Spline *spline, int hasia, real ia) {
684 real yoff, xoff, angle;
685 int ishor=false, isvert=false, isital=false;
686 int isto;
687 int type;
688 BasePoint *base, *other;
689 static const char *hmsgs[5] = {
690 N_("The selected line segment is nearly horizontal"),
691 N_("The control point above the selected point is nearly horizontal"),
692 N_("The control point below the selected point is nearly horizontal"),
693 N_("The control point right of the selected point is nearly horizontal"),
694 N_("The control point left of the selected point is nearly horizontal")
695 };
696 static const char *vmsgs[5] = {
697 N_("The selected line segment is nearly vertical"),
698 N_("The control point above the selected point is nearly vertical"),
699 N_("The control point below the selected point is nearly vertical"),
700 N_("The control point right of the selected point is nearly vertical"),
701 N_("The control point left of the selected point is nearly vertical")
702 };
703 static const char *imsgs[5] = {
704 N_("The selected line segment is near the italic angle"),
705 N_("The control point above the selected point is near the italic angle"),
706 N_("The control point below the selected point is near the italic angle"),
707 N_("The control point right of the selected point is near the italic angle"),
708 N_("The control point left of the selected point is near the italic angle")
709 };
710
711 yoff = to->y-from->y;
712 xoff = to->x-from->x;
713 angle = atan2(yoff,xoff);
714 if ( angle<0 )
715 angle += FF_PI;
716 if ( angle<.1 || angle>FF_PI-.1 ) {
717 if ( yoff!=0 )
718 ishor = true;
719 } else if ( angle>1.5707963-.1 && angle<1.5707963+.1 ) {
720 if ( xoff!=0 )
721 isvert = true;
722 } else if ( hasia && angle>ia-.1 && angle<ia+.1 ) {
723 if ( angle<ia-.03 || angle>ia+.03 )
724 isital = true;
725 }
726 if ( ishor || isvert || isital ) {
727 isto = false;
728 if ( &spline->from->me==from || &spline->from->me==to )
729 spline->from->selected = true;
730 if ( &spline->to->me==from || &spline->to->me==to )
731 spline->to->selected = isto = true;
732 if ( from==&spline->from->me || from == &spline->to->me ) {
733 base = from; other = to;
734 } else {
735 base = to; other = from;
736 }
737 if ( &spline->from->me==from && &spline->to->me==to ) {
738 type = 0; /* Line */
739 if ( (ishor && xoff<0) || (isvert && yoff<0)) {
740 base = from;
741 other = to;
742 } else {
743 base = to;
744 other = from;
745 }
746 } else if ( fabs(yoff)>fabs(xoff) )
747 type = ((yoff>0) ^ isto)?1:2;
748 else
749 type = ((xoff>0) ^ isto)?3:4;
750 if ( ishor )
751 ExplainIt(p,p->sc,_(hmsgs[type]), other->y,base->y);
752 else if ( isvert )
753 ExplainIt(p,p->sc,_(vmsgs[type]), other->x,base->x);
754 else
755 ExplainIt(p,p->sc,_(imsgs[type]),0,0);
756 return( true );
757 }
758 return( false );
759 }
760
761 /* Is the control point outside of the spline segment when projected onto the */
762 /* vector between the end points of the spline segment? */
763 static int OddCPCheck(BasePoint *cp,BasePoint *base,BasePoint *v,
764 SplinePoint *sp, struct problems *p) {
765 real len = (cp->x-base->x)*v->x+ (cp->y-base->y)*v->y;
766 real xoff, yoff;
767 char *msg=NULL;
768
769 if ( len<0 || len>1 || (len==0 && &sp->me!=base) || (len==1 && &sp->me==base)) {
770 xoff = cp->x-sp->me.x; yoff = cp->y-sp->me.y;
771 if ( fabs(yoff)>fabs(xoff) )
772 msg = yoff>0?_("The control point above the selected point is outside the spline segment"):_("The control point below the selected point is outside the spline segment");
773 else
774 msg = xoff>0?_("The control point right of the selected point is outside the spline segment"):_("The control point left of the selected point is outside the spline segment");
775 sp->selected = true;
776 ExplainIt(p,p->sc,msg, 0,0);
777 return( true );
778 }
779 return( false );
780 }
781
782 static int Hint3Check(struct problems *p,StemInfo *h) {
783 StemInfo *h2, *h3;
784
785 /* Must be three hints to be interesting */
786 if ( h==NULL || (h2=h->next)==NULL || (h3=h2->next)==NULL )
787 return(false);
788 if ( h3->next!=NULL ) {
789 StemInfo *bad, *goods[3];
790 if ( h3->next->next!=NULL ) /* Don't try to find a subset with 5 */
791 return(false);
792 if ( h->width==h2->width || h->width==h3->width ) {
793 goods[0] = h;
794 if ( h->width==h2->width ) {
795 goods[1] = h2;
796 if ( h->width==h3->width && h->width!=h3->next->width ) {
797 goods[2] = h3;
798 bad = h3->next;
799 } else if ( h->width!=h3->width && h->width==h3->next->width ) {
800 goods[2] = h3->next;
801 bad = h3;
802 } else
803 return(false);
804 } else if ( h->width==h3->width && h->width==h3->next->width ) {
805 goods[1] = h3;
806 goods[2] = h3->next;
807 bad = h2;
808 } else
809 return(false);
810 } else if ( h2->width == h3->width && h2->width==h3->next->width ) {
811 bad = h;
812 goods[0] = h2; goods[1] = h3; goods[2] = h3->next;
813 } else
814 return(false);
815 if ( goods[2]->start-goods[1]->start == goods[1]->start-goods[0]->start ) {
816 bad->active = true;
817 ExplainIt(p,p->sc,_("This glyph has four hints, but if this one were omitted it would fit a stem3 hint"),0,0);
818 if ( !missinghint(p->sc->hstem,bad) || !missinghint(p->sc->vstem,bad))
819 bad->active = false;
820 if ( p->ignorethis )
821 p->selected_records[CID_Stem3] = false;
822 return( true );
823 }
824 return(false);
825 }
826
827 if ( h->width==h2->width && h->width==h3->width &&
828 h2->start-h->start == h3->start-h2->start ) {
829 if ( p->selected_records[CID_ShowExactStem3] ) {
830 ExplainIt(p,p->sc,_("This glyph can use a stem3 hint"),0,0);
831 if ( p->ignorethis )
832 p->selected_records[CID_ShowExactStem3] = false;
833 }
834 return( false ); /* It IS a stem3, so don't complain */
835 }
836
837 if ( h->width==h2->width && h->width==h3->width ) {
838 if ( h2->start-h->start+p->near > h3->start-h2->start &&
839 h2->start-h->start-p->near < h3->start-h2->start ) {
840 ExplainIt(p,p->sc,_("The counters between these hints are not the same size, bad for a stem3 hint"),0,0);
841 if ( p->ignorethis )
842 p->selected_records[CID_Stem3] = false;
843 return( true );
844 }
845 return( false );
846 }
847
848 if ( (h2->start-h->start+p->near > h3->start-h2->start &&
849 h2->start-h->start-p->near < h3->start-h2->start ) ||
850 (h2->start-h->start-h->width+p->near > h3->start-h2->start-h2->width &&
851 h2->start-h->start-h->width-p->near < h3->start-h2->start-h2->width )) {
852 if ( h->width==h2->width ) {
853 if ( h->width+p->near > h3->width && h->width-p->near < h3->width ) {
854 h3->active = true;
855 ExplainIt(p,p->sc,_("This hint has the wrong width for a stem3 hint"),0,0);
856 if ( !missinghint(p->sc->hstem,h3) || !missinghint(p->sc->vstem,h3))
857 h3->active = false;
858 if ( p->ignorethis )
859 p->selected_records[CID_Stem3] = false;
860 return( true );
861 } else
862 return( false );
863 }
864 if ( h->width==h3->width ) {
865 if ( h->width+p->near > h2->width && h->width-p->near < h2->width ) {
866 h2->active = true;
867 ExplainIt(p,p->sc,_("This hint has the wrong width for a stem3 hint"),0,0);
868 if ( !missinghint(p->sc->hstem,h2) || !missinghint(p->sc->vstem,h2))
869 h2->active = false;
870 if ( p->ignorethis )
871 p->selected_records[CID_Stem3] = false;
872 return( true );
873 } else
874 return( false );
875 }
876 if ( h2->width==h3->width ) {
877 if ( h2->width+p->near > h->width && h2->width-p->near < h->width ) {
878 h->active = true;
879 ExplainIt(p,p->sc,_("This hint has the wrong width for a stem3 hint"),0,0);
880 if ( !missinghint(p->sc->hstem,h) || !missinghint(p->sc->vstem,h))
881 h->active = false;
882 if ( p->ignorethis )
883 p->selected_records[CID_Stem3] = false;
884 return( true );
885 } else
886 return( false );
887 }
888 }
889 return( false );
890 }
891
892 static int probRefDepth(RefChar *r,int layer) {
893 RefChar *ref;
894 int cur, max=0;
895
896 for ( ref= r->sc->layers[layer].refs; ref!=NULL; ref=ref->next ) {
897 cur = probRefDepth(ref,layer);
898 if ( cur>max ) max = cur;
899 }
900 return( max+1 );
901 }
902
903 static int SCRefDepth(SplineChar *sc,int layer) {
904 RefChar *ref;
905 int cur, max=0;
906
907 for ( ref= sc->layers[layer].refs; ref!=NULL; ref=ref->next ) {
908 cur = probRefDepth(ref,layer);
909 if ( cur>max ) max = cur;
910 }
911 return( max );
912 }
913
914 static int SPLPointCnt(SplinePointList *spl) {
915 SplinePoint *sp;
916 int cnt=0;
917
918 for ( ; spl!=NULL; spl = spl->next ) {
919 for ( sp = spl->first; ; ) {
920 ++cnt;
921 if ( sp->prev!=NULL && !sp->prev->knownlinear ) {
922 if ( sp->prev->order2 )
923 ++cnt;
924 else
925 cnt += 2;
926 }
927 if ( sp->next==NULL )
928 break;
929 sp = sp->next->to;
930 if ( sp==spl->first )
931 break;
932 }
933 }
934 return( cnt );
935 }
936
937 static RefChar *FindRefOfSplineInLayer(Layer *layer,Spline *spline) {
938 RefChar *r;
939 SplineSet *ss;
940 Spline *s, *first;
941
942 for ( r=layer->refs; r!=NULL; r=r->next ) {
943 for ( ss=r->layers[0].splines; ss!=NULL; ss=ss->next ) {
944 first = NULL;
945 for ( s=ss->first->next ; s!=NULL && s!=first; s=s->to->next ) {
946 if ( first==NULL ) first = s;
947 if ( s==spline )
948 return( r );
949 }
950 }
951 }
952 return( NULL );
953 }
954
955 static void FigureStandardHeights(struct problems *p) {
956 BlueData bd;
957
958 QuickBlues(p->fv->b.sf,p->layer,&bd);
959 p->xheight = bd.xheight;
960 p->caph = bd.caph;
961 p->ascent = bd.ascent;
962 p->descent = bd.descent;
963 }
964
965 static int SCProblems(CharView *cv,SplineChar *sc,struct problems *p) {
966 SplineSet *spl, *test;
967 Spline *spline, *first;
968 Layer *cur;
969 SplinePoint *sp, *nsp;
970 int needsupdate=false, changed=false;
971 StemInfo *h;
972 RefChar *r1, *r2;
973 int uni;
974 DBounds bb;
975
976 restart:
977 if ( cv!=NULL ) {
978 needsupdate = CVClearSel(cv);
979 cur = cv->b.layerheads[cv->b.drawmode];
980 spl = cur->splines;
981 sc = cv->b.sc;
982 } else {
983 for ( spl = sc->layers[p->layer].splines; spl!=NULL; spl = spl->next ) {
984 if ( spl->first->selected ) { needsupdate = true; spl->first->selected = false; }
985 first = NULL;
986 for ( spline = spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next ) {
987 if ( spline->to->selected )
988 { needsupdate = true; spline->to->selected = false; }
989 if ( first==NULL ) first = spline;
990 }
991 }
992 cur = &sc->layers[p->layer];
993 spl = cur->splines;
994 }
995 p->sc = sc;
996 if (( p->selected_records[CID_PtNearHint] || p->selected_records[CID_HintWidthNear] || p->selected_records[CID_HintNoPt] ) &&
997 sc->changedsincelasthinted && !sc->manualhints )
998 SplineCharAutoHint(sc,p->layer,NULL);
999
1000 if ( p->selected_records[CID_OpenPaths] ) {
1001 for ( test=spl; test!=NULL && !p->finish; test=test->next ) {
1002 /* I'm also including in "open paths" the special case of a */
1003 /* singleton point with connects to itself */
1004 if ( test->first!=NULL && ( test->first->prev==NULL ||
1005 ( test->first->prev == test->first->next &&
1006 test->first->noprevcp && test->first->nonextcp))) {
1007 changed = true;
1008 test->first->selected = test->last->selected = true;
1009 ExplainIt(p,sc,_("The two selected points are the endpoints of an open path"),0,0);
1010 if ( p->ignorethis ) {
1011 p->selected_records[CID_OpenPaths] = false;
1012 break;
1013 }
1014 if ( missing(p,test,NULL))
1015 goto restart;
1016 }
1017 }
1018 }
1019
1020 if ( p->selected_records[CID_IntersectingPaths] && !p->finish ) {
1021 Spline *s, *s2;
1022 int found;
1023 spl = LayerAllSplines(cur);
1024 found = SplineSetIntersect(spl,&s,&s2);
1025 spl = LayerUnAllSplines(cur);
1026 if ( found ) {
1027 changed = true;
1028 if ( (r1 = FindRefOfSplineInLayer(cur,s))!=NULL )
1029 r1->selected = true;
1030 else {
1031 s->from->selected = true; s->to->selected = true;
1032 }
1033 if ( (r2 = FindRefOfSplineInLayer(cur,s2))!=NULL )
1034 r2->selected = true;
1035 else {
1036 s2->from->selected = true; s2->to->selected = true;
1037 }
1038 ExplainIt(p,sc,_("The paths that make up this glyph intersect one another"),0,0);
1039 if ( p->ignorethis ) {
1040 p->selected_records[CID_IntersectingPaths] = false;
1041 /* break; */
1042 }
1043 }
1044 }
1045
1046 if ( p->selected_records[CID_NonIntegral] && !p->finish ) {
1047 for ( test=spl; test!=NULL && !p->finish && p->selected_records[CID_NonIntegral]; test=test->next ) {
1048 sp = test->first;
1049 do {
1050 int interp = SPInterpolate(sp);
1051 int badme = interp
1052 ? (rint(2*sp->me.x)!=2*sp->me.x || rint(2*sp->me.y)!=2*sp->me.y)
1053 : (rint(sp->me.x)!=sp->me.x || rint(sp->me.y)!=sp->me.y);
1054 if ( badme ||
1055 rint(sp->nextcp.x)!=sp->nextcp.x || rint(sp->nextcp.y)!=sp->nextcp.y ||
1056 rint(sp->prevcp.x)!=sp->prevcp.x || rint(sp->prevcp.y)!=sp->prevcp.y ) {
1057 changed = true;
1058 sp->selected = true;
1059 if ( badme )
1060 ExplainIt(p,sc,_("The selected point is not at integral coordinates"),0,0);
1061 else
1062 ExplainIt(p,sc,_("The selected point does not have integral control points"),0,0);
1063 if ( p->ignorethis ) {
1064 p->selected_records[CID_NonIntegral] = false;
1065 break;
1066 }
1067 if ( missing(p,test,nsp))
1068 goto restart;
1069 }
1070 if ( sp->next==NULL )
1071 break;
1072 sp = sp->next->to;
1073 } while ( sp!=test->first && !p->finish );
1074 if ( !p->selected_records[CID_NonIntegral] )
1075 break;
1076 }
1077 }
1078
1079 if ( p->selected_records[CID_PointsTooFar] && !p->finish ) {
1080 SplinePoint *lastsp=NULL;
1081 BasePoint lastpt;
1082
1083 memset(&lastpt,0,sizeof(lastpt));
1084 for ( test=spl; test!=NULL && !p->finish && p->selected_records[CID_PointsTooFar]; test=test->next ) {
1085 sp = test->first;
1086 do {
1087 if ( BPTooFar(&lastpt,&sp->prevcp) ||
1088 BPTooFar(&sp->prevcp,&sp->me) ||
1089 BPTooFar(&sp->me,&sp->nextcp)) {
1090 changed = true;
1091 sp->selected = true;
1092 if ( lastsp==NULL ) {
1093 ExplainIt(p,sc,_("The selected point is too far from the origin"),0,0);
1094 } else {
1095 lastsp->selected = true;
1096 ExplainIt(p,sc,_("The selected points (or the intermediate control points) are too far apart"),0,0);
1097 }
1098 if ( p->ignorethis ) {
1099 p->selected_records[CID_PointsTooFar] = false;
1100 break;
1101 }
1102 if ( missing(p,test,sp))
1103 goto restart;
1104 }
1105 memcpy(&lastpt,&sp->nextcp,sizeof(lastpt));
1106 if ( sp->next==NULL )
1107 break;
1108 sp = sp->next->to;
1109 if ( sp==test->first ) {
1110 memcpy(&lastpt,&sp->me,sizeof(lastpt));
1111 break;
1112 }
1113 } while ( !p->finish );
1114 if ( !p->selected_records[CID_PointsTooFar] )
1115 break;
1116 }
1117 }
1118
1119 if ( p->selected_records[CID_PointsTooClose] && !p->finish ) {
1120 for ( test=spl; test!=NULL && !p->finish && p->selected_records[CID_PointsTooClose]; test=test->next ) {
1121 sp = test->first;
1122 do {
1123 if ( sp->next==NULL )
1124 break;
1125 nsp = sp->next->to;
1126 if ( (nsp->me.x-sp->me.x)*(nsp->me.x-sp->me.x) + (nsp->me.y-sp->me.y)*(nsp->me.y-sp->me.y) < 2*2 ) {
1127 changed = true;
1128 sp->selected = nsp->selected = true;
1129 ExplainIt(p,sc,_("The selected points are too close to each other"),0,0);
1130 if ( p->ignorethis ) {
1131 p->selected_records[CID_PointsTooClose] = false;
1132 break;
1133 }
1134 if ( missing(p,test,nsp))
1135 goto restart;
1136 }
1137 sp = nsp;
1138 } while ( sp!=test->first && !p->finish );
1139 if ( !p->selected_records[CID_PointsTooClose] )
1140 break;
1141 }
1142 }
1143
1144 if ( p->selected_records[CID_XNear] && !p->finish ) {
1145 double xval = std::get<double>(p->record_values[CID_XNear]);
1146 for ( test=spl; test!=NULL && !p->finish && p->selected_records[CID_XNear]; test=test->next ) {
1147 sp = test->first;
1148 do {
1149 if ( sp->me.x-xval<p->near && xval-sp->me.x<p->near &&
1150 sp->me.x!=xval ) {
1151 changed = true;
1152 sp->selected = true;
1153 ExplainIt(p,sc,_("The x coord of the selected point is near the specified value"),sp->me.x,xval);
1154 if ( p->ignorethis ) {
1155 p->selected_records[CID_XNear] = false;
1156 break;
1157 }
1158 if ( missing(p,test,sp))
1159 goto restart;
1160 }
1161 if ( sp->next==NULL )
1162 break;
1163 sp = sp->next->to;
1164 } while ( sp!=test->first && !p->finish );
1165 if ( !p->selected_records[CID_XNear] )
1166 break;
1167 }
1168 }
1169
1170 if ( p->selected_records[CID_YNear] && !p->finish ) {
1171 double yval = std::get<double>(p->record_values[CID_YNear]);
1172 for ( test=spl; test!=NULL && !p->finish && p->selected_records[CID_YNear]; test=test->next ) {
1173 sp = test->first;
1174 do {
1175 if ( sp->me.y-yval<p->near && yval-sp->me.y<p->near &&
1176 sp->me.y != yval ) {
1177 changed = true;
1178 sp->selected = true;
1179 ExplainIt(p,sc,_("The y coord of the selected point is near the specified value"),sp->me.y,yval);
1180 if ( p->ignorethis ) {
1181 p->selected_records[CID_YNear] = false;
1182 break;
1183 }
1184 if ( missing(p,test,sp))
1185 goto restart;
1186 }
1187 if ( sp->next==NULL )
1188 break;
1189 sp = sp->next->to;
1190 } while ( sp!=test->first && !p->finish );
1191 if ( !p->selected_records[CID_YNear] )
1192 break;
1193 }
1194 }
1195
1196 if ( p->selected_records[CID_YNearStd] && !p->finish ) {
1197 real expected;
1198 char *msg;
1199 FigureStandardHeights(p);
1200 for ( test=spl; test!=NULL && !p->finish && p->selected_records[CID_YNearStd]; test=test->next ) {
1201 sp = test->first;
1202 do {
1203 if (( sp->me.y-p->xheight<p->near && p->xheight-sp->me.y<p->near && sp->me.y!=p->xheight ) ||
1204 ( sp->me.y-p->caph<p->near && p->caph-sp->me.y<p->near && sp->me.y!=p->caph && sp->me.y!=p->ascent ) ||
1205 ( sp->me.y-p->ascent<p->near && p->ascent-sp->me.y<p->near && sp->me.y!=p->caph && sp->me.y!=p->ascent ) ||
1206 ( sp->me.y-p->descent<p->near && p->descent-sp->me.y<p->near && sp->me.y!=p->descent ) ||
1207 ( sp->me.y<p->near && -sp->me.y<p->near && sp->me.y!=0 ) ) {
1208 changed = true;
1209 sp->selected = true;
1210 if ( sp->me.y<p->near && -sp->me.y<p->near ) {
1211 msg = _("The y coord of the selected point is near the baseline");
1212 expected = 0;
1213 } else if ( sp->me.y-p->xheight<p->near && p->xheight-sp->me.y<p->near ) {
1214 msg = _("The y coord of the selected point is near the xheight");
1215 expected = p->xheight;
1216 } else if ( sp->me.y-p->caph<p->near && p->caph-sp->me.y<p->near ) {
1217 msg = _("The y coord of the selected point is near the cap height");
1218 expected = p->caph;
1219 } else if ( sp->me.y-p->ascent<p->near && p->ascent-sp->me.y<p->near ) {
1220 msg = _("The y coord of the selected point is near the ascender height");
1221 expected = p->ascent;
1222 } else {
1223 msg = _("The y coord of the selected point is near the descender height");
1224 expected = p->descent;
1225 }
1226 ExplainIt(p,sc,msg,sp->me.y,expected);
1227 if ( p->ignorethis ) {
1228 p->selected_records[CID_YNearStd] = false;
1229 break;
1230 }
1231 if ( missing(p,test,sp))
1232 goto restart;
1233 }
1234 if ( sp->next==NULL )
1235 break;
1236 sp = sp->next->to;
1237 } while ( sp!=test->first && !p->finish );
1238 if ( !p->selected_records[CID_YNearStd] )
1239 break;
1240 }
1241 }
1242
1243 if ( p->selected_records[CID_LineStd] && !p->finish ) {
1244 real ia = (90-p->fv->b.sf->italicangle)*(FF_PI/180);
1245 int hasia = p->fv->b.sf->italicangle!=0;
1246 for ( test=spl; test!=NULL && !p->finish && p->selected_records[CID_LineStd]; test = test->next ) {
1247 first = NULL;
1248 for ( spline = test->first->next; spline!=NULL && spline!=first && !p->finish; spline=spline->to->next ) {
1249 if ( spline->knownlinear ) {
1250 if ( HVITest(p,&spline->to->me,&spline->from->me,spline,
1251 hasia, ia)) {
1252 changed = true;
1253 if ( p->ignorethis ) {
1254 p->selected_records[CID_LineStd] = false;
1255 break;
1256 }
1257 if ( missingspline(p,test,spline))
1258 goto restart;
1259 }
1260 }
1261 if ( first==NULL ) first = spline;
1262 }
1263 if ( !p->selected_records[CID_LineStd] )
1264 break;
1265 }
1266 }
1267
1268 if ( p->selected_records[CID_CpStd] && !p->finish ) {
1269 real ia = (90-p->fv->b.sf->italicangle)*(FF_PI/180);
1270 int hasia = p->fv->b.sf->italicangle!=0;
1271 for ( test=spl; test!=NULL && !p->finish && p->selected_records[CID_CpStd]; test = test->next ) {
1272 first = NULL;
1273 for ( spline = test->first->next; spline!=NULL && spline!=first && !p->finish; spline=spline->to->next ) {
1274 if ( !spline->knownlinear ) {
1275 if ( !spline->from->nonextcp &&
1276 HVITest(p,&spline->from->nextcp,&spline->from->me,spline,
1277 hasia, ia)) {
1278 changed = true;
1279 if ( p->ignorethis ) {
1280 p->selected_records[CID_CpStd] = false;
1281 break;
1282 }
1283 if ( missingspline(p,test,spline))
1284 goto restart;
1285 }
1286 if ( !spline->to->noprevcp &&
1287 HVITest(p,&spline->to->me,&spline->to->prevcp,spline,
1288 hasia, ia)) {
1289 changed = true;
1290 if ( p->ignorethis ) {
1291 p->selected_records[CID_CpStd] = false;
1292 break;
1293 }
1294 if ( missingspline(p,test,spline))
1295 goto restart;
1296 }
1297 }
1298 if ( first==NULL ) first = spline;
1299 }
1300 if ( !p->selected_records[CID_CpStd] )
1301 break;
1302 }
1303 }
1304
1305 if ( p->selected_records[CID_CpOdd] && !p->finish ) {
1306 for ( test=spl; test!=NULL && !p->finish && p->selected_records[CID_CpOdd]; test = test->next ) {
1307 first = NULL;
1308 for ( spline = test->first->next; spline!=NULL && spline!=first && !p->finish; spline=spline->to->next ) {
1309 if ( !spline->knownlinear ) {
1310 BasePoint v; real len;
1311 v.x = spline->to->me.x-spline->from->me.x;
1312 v.y = spline->to->me.y-spline->from->me.y;
1313 len = /*sqrt*/(v.x*v.x+v.y*v.y);
1314 v.x /= len; v.y /= len;
1315 if ( !spline->from->nonextcp &&
1316 OddCPCheck(&spline->from->nextcp,&spline->from->me,&v,
1317 spline->from,p)) {
1318 changed = true;
1319 if ( p->ignorethis ) {
1320 p->selected_records[CID_CpOdd] = false;
1321 break;
1322 }
1323 if ( missingspline(p,test,spline))
1324 goto restart;
1325 }
1326 if ( !spline->to->noprevcp &&
1327 OddCPCheck(&spline->to->prevcp,&spline->from->me,&v,
1328 spline->to,p)) {
1329 changed = true;
1330 if ( p->ignorethis ) {
1331 p->selected_records[CID_CpOdd] = false;
1332 break;
1333 }
1334 if ( missingspline(p,test,spline))
1335 goto restart;
1336 }
1337 }
1338 if ( first==NULL ) first = spline;
1339 }
1340 if ( !p->selected_records[CID_CpOdd] )
1341 break;
1342 }
1343 }
1344
1345 if ( p->selected_records[CID_IrrelevantCP] && !p->finish ) {
1346 double irrelevantfactor = std::get<double>(p->record_values[CID_IrrelevantCP]) / 100.0;
1347 for ( test=spl; test!=NULL && !p->finish && p->selected_records[CID_IrrelevantCP]; test = test->next ) {
1348 for ( sp=test->first; !p->finish && p->selected_records[CID_IrrelevantCP]; ) {
1349 int either = false;
1350 if ( sp->prev!=NULL ) {
1351 double len = sqrt((sp->me.x-sp->prev->from->me.x)*(sp->me.x-sp->prev->from->me.x) +
1352 (sp->me.y-sp->prev->from->me.y)*(sp->me.y-sp->prev->from->me.y));
1353 double cplen = sqrt((sp->me.x-sp->prevcp.x)*(sp->me.x-sp->prevcp.x) +
1354 (sp->me.y-sp->prevcp.y)*(sp->me.y-sp->prevcp.y));
1355 if ( cplen!=0 && cplen<irrelevantfactor*len )
1356 either = true;
1357 }
1358 if ( sp->next!=NULL ) {
1359 double len = sqrt((sp->me.x-sp->next->to->me.x)*(sp->me.x-sp->next->to->me.x) +
1360 (sp->me.y-sp->next->to->me.y)*(sp->me.y-sp->next->to->me.y));
1361 double cplen = sqrt((sp->me.x-sp->nextcp.x)*(sp->me.x-sp->nextcp.x) +
1362 (sp->me.y-sp->nextcp.y)*(sp->me.y-sp->nextcp.y));
1363 if ( cplen!=0 && cplen<irrelevantfactor*len )
1364 either = true;
1365 }
1366 if ( either ) {
1367 sp->selected = true;
1368 ExplainIt(p,sc,_("This glyph contains control points which are probably too close to the main points to alter the look of the spline"),0,0);
1369 if ( p->ignorethis ) {
1370 p->selected_records[CID_IrrelevantCP] = false;
1371 break;
1372 }
1373 }
1374 if ( sp->next==NULL )
1375 break;
1376 sp = sp->next->to;
1377 if ( sp==test->first )
1378 break;
1379 }
1380 }
1381 }
1382
1383 if ( p->selected_records[CID_HintNoPt] && !p->finish ) {
1384 int anys, anye;
1385 restarthhint:
1386 for ( h=sc->hstem; h!=NULL ; h=h->next ) {
1387 anys = anye = false;
1388 for ( test=spl; test!=NULL && !p->finish && (!anys || !anye); test=test->next ) {
1389 sp = test->first;
1390 do {
1391 if (sp->me.y==h->start )
1392 anys = true;
1393 if (sp->me.y==h->start+h->width )
1394 anye = true;
1395 if ( sp->next==NULL )
1396 break;
1397 sp = sp->next->to;
1398 } while ( sp!=test->first && !p->finish );
1399 }
1400 if ( h->ghost && ( anys || anye ))
1401 /* Ghost hints only define one edge */;
1402 else if ( !anys || !anye ) {
1403 h->active = true;
1404 changed = true;
1405 ExplainIt(p,sc,_("This hint does not control any points"),0,0);
1406 if ( !missinghint(sc->hstem,h))
1407 h->active = false;
1408 if ( p->ignorethis ) {
1409 p->selected_records[CID_HintNoPt] = false;
1410 break;
1411 }
1412 if ( missinghint(sc->hstem,h))
1413 goto restarthhint;
1414 }
1415 }
1416 restartvhint:
1417 for ( h=sc->vstem; h!=NULL && p->selected_records[CID_HintNoPt] && !p->finish; h=h->next ) {
1418 anys = anye = false;
1419 for ( test=spl; test!=NULL && !p->finish && (!anys || !anye); test=test->next ) {
1420 sp = test->first;
1421 do {
1422 if (sp->me.x==h->start )
1423 anys = true;
1424 if (sp->me.x==h->start+h->width )
1425 anye = true;
1426 if ( sp->next==NULL )
1427 break;
1428 sp = sp->next->to;
1429 } while ( sp!=test->first && !p->finish );
1430 }
1431 if ( !anys || !anye ) {
1432 h->active = true;
1433 changed = true;
1434 ExplainIt(p,sc,_("This hint does not control any points"),0,0);
1435 if ( p->ignorethis ) {
1436 p->selected_records[CID_HintNoPt] = false;
1437 break;
1438 }
1439 if ( missinghint(sc->vstem,h))
1440 goto restartvhint;
1441 h->active = false;
1442 }
1443 }
1444 }
1445
1446 if ( p->selected_records[CID_PtNearHint] && !p->finish ) {
1447 real found, expected;
1448 h = NULL;
1449 for ( test=spl; test!=NULL && !p->finish && p->selected_records[CID_PtNearHint]; test=test->next ) {
1450 sp = test->first;
1451 do {
1452 int hs = false, vs = false;
1453 for ( h=sc->hstem; h!=NULL; h=h->next ) {
1454 if (( sp->me.y-h->start<p->near && h->start-sp->me.y<p->near &&
1455 sp->me.y!=h->start ) ||
1456 ( sp->me.y-h->start+h->width<p->near && h->start+h->width-sp->me.y<p->near &&
1457 sp->me.y!=h->start+h->width )) {
1458 found = sp->me.y;
1459 if ( sp->me.y-h->start<p->near && h->start-sp->me.y<p->near )
1460 expected = h->start;
1461 else
1462 expected = h->start+h->width;
1463 h->active = true;
1464 hs = true;
1465 break;
1466 }
1467 }
1468 if ( !hs ) {
1469 for ( h=sc->vstem; h!=NULL; h=h->next ) {
1470 if (( sp->me.x-h->start<p->near && h->start-sp->me.x<p->near &&
1471 sp->me.x!=h->start ) ||
1472 ( sp->me.x-h->start+h->width<p->near && h->start+h->width-sp->me.x<p->near &&
1473 sp->me.x!=h->start+h->width )) {
1474 found = sp->me.x;
1475 if ( sp->me.x-h->start<p->near && h->start-sp->me.x<p->near )
1476 expected = h->start;
1477 else
1478 expected = h->start+h->width;
1479 h->active = true;
1480 vs = true;
1481 break;
1482 }
1483 }
1484 }
1485 if ( hs || vs ) {
1486 changed = true;
1487 sp->selected = true;
1488 ExplainIt(p,sc,hs?_("The selected point is near a horizontal stem hint"):_("The selected point is near a vertical stem hint"),found,expected);
1489 if ( h!=NULL )
1490 h->active = false;
1491 if ( p->ignorethis ) {
1492 p->selected_records[CID_PtNearHint] = false;
1493 break;
1494 }
1495 if ( missing(p,test,sp))
1496 goto restart;
1497 }
1498 if ( sp->next==NULL )
1499 break;
1500 sp = sp->next->to;
1501 } while ( sp!=test->first && !p->finish );
1502 if ( !p->selected_records[CID_PtNearHint] )
1503 break;
1504 }
1505 }
1506
1507 if ( p->selected_records[CID_OverlappedHints] && !p->finish && !cur->order2 && spl!=NULL ) {
1508 int anyhm=0;
1509 for ( test=spl; test!=NULL && !p->finish && p->selected_records[CID_OverlappedHints]; test=test->next ) {
1510 sp = test->first;
1511 do {
1512 if ( sp->hintmask!=NULL ) {
1513 anyhm = true;
1514 h = SCHintOverlapInMask(sc,sp->hintmask);
1515 if ( h!=NULL ) {
1516 sp->selected = true;
1517 h->active = true;
1518 changed = true;
1519 ExplainIt(p,sc,_("The hint mask of the selected point contains overlapping hints"),0,0);
1520 if ( p->ignorethis )
1521 p->selected_records[CID_OverlappedHints] = false;
1522 if ( missing(p,test,sp))
1523 goto restart;
1524 if ( missingschint(h,sc))
1525 goto restart;
1526 h->active = false;
1527 sp->selected = false;
1528 if ( !p->selected_records[CID_OverlappedHints] )
1529 break;
1530 }
1531 }
1532 if ( sp->next==NULL )
1533 break;
1534 sp = sp->next->to;
1535 } while ( sp!=test->first && !p->finish );
1536 if ( !p->selected_records[CID_OverlappedHints] )
1537 break;
1538 }
1539 if ( p->selected_records[CID_OverlappedHints] && !anyhm ) {
1540 h = SCHintOverlapInMask(sc,NULL);
1541 if ( h!=NULL ) {
1542 h->active = true;
1543 changed = true;
1544 ExplainIt(p,sc,_("There are no hint masks in this layer but there are overlapping hints."),0,0);
1545 if ( missingschint(h,sc))
1546 goto restart;
1547 h->active = false;
1548 }
1549 }
1550 }
1551
1552 if ( p->selected_records[CID_HintWidthNear] && !p->finish ) {
1553 double widthval = std::get<double>(p->record_values[CID_HintWidthNear]);
1554 StemInfo *hs = NULL, *vs = NULL;
1555 for ( h=sc->hstem; h!=NULL; h=h->next ) {
1556 if ( h->width-widthval<p->near && widthval-h->width<p->near &&
1557 h->width!=widthval ) {
1558 h->active = true;
1559 hs = h;
1560 break;
1561 }
1562 }
1563 for ( h=sc->vstem; h!=NULL; h=h->next ) {
1564 if ( h->width-widthval<p->near && widthval-h->width<p->near &&
1565 h->width!=widthval ) {
1566 h->active = true;
1567 vs = h;
1568 break;
1569 }
1570 }
1571 if ( hs || vs ) {
1572 changed = true;
1573 ExplainIt(p,sc,hs?_("This glyph contains a horizontal hint near the specified width"):_("This glyph contains a vertical hint near the specified width"),
1574 hs?hs->width:vs->width,widthval);
1575 if ( hs!=NULL && !missinghint(sc->hstem,hs)) hs->active = false;
1576 if ( vs!=NULL && !missinghint(sc->vstem,vs)) vs->active = false;
1577 if ( p->ignorethis )
1578 p->selected_records[CID_HintWidthNear] = false;
1579 else if ( (hs!=NULL && missinghint(sc->hstem,hs)) &&
1580 ( vs!=NULL && missinghint(sc->vstem,vs)))
1581 goto restart;
1582 }
1583 }
1584
1585 if ( p->selected_records[CID_Stem3] && !p->finish )
1586 changed |= Hint3Check(p,sc->hstem);
1587 if ( p->selected_records[CID_Stem3] && !p->finish )
1588 changed |= Hint3Check(p,sc->vstem);
1589
1590 if ( p->selected_records[CID_Direction] && !p->finish ) {
1591 SplineSet **base, *ret, *ss;
1592 Spline *s, *s2;
1593 Layer *layer;
1594 int lastscan= -1;
1595 int self_intersects, dir;
1596
1597 if ( cv!=NULL )
1598 layer = cv->b.layerheads[cv->b.drawmode];
1599 else
1600 layer = &sc->layers[p->layer];
1601
1602 ss = LayerAllSplines(layer);
1603 self_intersects = SplineSetIntersect(ss,&s,&s2);
1604 LayerUnAllSplines(layer);
1605
1606 if ( self_intersects )
1607 ff_post_error(_("This glyph self-intersects"),_("This glyph self-intersects. Checking for correct direction is meaningless until that is fixed"));
1608 else {
1609 base = &layer->splines;
1610
1611 while ( !p->finish && (ret=SplineSetsDetectDir(base,&lastscan))!=NULL ) {
1612 sp = ret->first;
1613 changed = true;
1614 while ( 1 ) {
1615 sp->selected = true;
1616 if ( sp->next==NULL )
1617 break;
1618 sp = sp->next->to;
1619 if ( sp==ret->first )
1620 break;
1621 }
1622 dir = SplinePointListIsClockwise(ret);
1623 if ( dir==-1 )
1624 ExplainIt(p,sc,_("This path probably intersects itself (though I could not find that when\n I checked for intersections), look closely at the corners"),0,0);
1625 else if ( dir==1 )
1626 ExplainIt(p,sc,_("This path should have been drawn in a counter-clockwise direction"),0,0);
1627 else
1628 ExplainIt(p,sc,_("This path should have been drawn in a clockwise direction"),0,0);
1629 if ( p->ignorethis ) {
1630 p->selected_records[CID_Direction] = false;
1631 break;
1632 }
1633 }
1634 }
1635 }
1636
1637 if ( p->selected_records[CID_MissingExtrema] && !p->finish ) {
1638 SplineSet *ss;
1639 Spline *s, *first;
1640 double len2, bound2 = p->sc->parent->extrema_bound;
1641 double x,y;
1642 extended extrema[4];
1643
1644 if ( bound2<=0 )
1645 bound2 = (p->sc->parent->ascent + p->sc->parent->descent)/32.0;
1646
1647 bound2 *= bound2;
1648 ae_restart:
1649 for ( ss = sc->layers[p->layer].splines; ss!=NULL && !p->finish; ss=ss->next ) {
1650 ae2_restart:
1651 first = NULL;
1652 for ( s=ss->first->next ; s!=NULL && s!=first && !p->finish; s=s->to->next ) {
1653 if ( first==NULL )
1654 first = s;
1655 if ( s->acceptableextrema )
1656 continue; /* If marked as good, don't check it */
1657 /* rough approximation to spline's length */
1658 x = (s->to->me.x-s->from->me.x);
1659 y = (s->to->me.y-s->from->me.y);
1660 len2 = x*x + y*y;
1661 /* short splines (serifs) need not to have points at their extrema */
1662 /* But how do we define "short"? */
1663 if ( len2>bound2 && Spline2DFindExtrema(s,extrema)>0 ) {
1664 s->from->selected = true;
1665 s->to->selected = true;
1666 ExplainIt(p,sc,_("The selected spline attains its extrema somewhere other than its endpoints"),0,0);
1667 if ( !SSExistsInLayer(ss,sc->layers[p->layer].splines) )
1668 goto ae_restart;
1669 if ( !SplineExistsInSS(s,ss))
1670 goto ae2_restart;
1671 if ( !SplineExistsInSS(first,ss))
1672 first = s;
1673 if ( p->ignorethis ) {
1674 p->selected_records[CID_MissingExtrema] = false;
1675 break;
1676 }
1677 }
1678 }
1679 if ( !p->selected_records[CID_MissingExtrema] )
1680 break;
1681 }
1682 }
1683
1684 if ( p->selected_records[CID_FlippedRefs] && !p->finish && ( cv==NULL || cv->b.drawmode==dm_fore )) {
1685 RefChar *ref;
1686 for ( ref = sc->layers[p->layer].refs; ref!=NULL ; ref = ref->next )
1687 ref->selected = false;
1688 for ( ref = sc->layers[p->layer].refs; !p->finish && ref!=NULL ; ref = ref->next ) {
1689 if ( ref->transform[0]*ref->transform[3]<0 ||
1690 (ref->transform[0]==0 && ref->transform[1]*ref->transform[2]>0)) {
1691 changed = true;
1692 ref->selected = true;
1693 ExplainIt(p,sc,_("This reference has been flipped, so the paths in it are drawn backwards"),0,0);
1694 ref->selected = false;
1695 if ( p->ignorethis ) {
1696 p->selected_records[CID_FlippedRefs] = false;
1697 break;
1698 }
1699 }
1700 }
1701 }
1702
1703 if ( p->selected_records[CID_RefBadTransformTTF] && !p->finish ) {
1704 RefChar *ref;
1705 for ( ref = sc->layers[p->layer].refs; ref!=NULL ; ref = ref->next )
1706 ref->selected = false;
1707 for ( ref = sc->layers[p->layer].refs; !p->finish && ref!=NULL ; ref = ref->next ) {
1708 if ( ref->transform[0]>=2 || ref->transform[0]<-2 ||
1709 ref->transform[1]>=2 || ref->transform[1]<-2 ||
1710 ref->transform[2]>=2 || ref->transform[2]<-2 ||
1711 ref->transform[3]>=2 || ref->transform[3]<-2 ||
1712 rint(ref->transform[4])!=ref->transform[4] ||
1713 rint(ref->transform[5])!=ref->transform[5]) {
1714 changed = true;
1715 ref->selected = true;
1716 ExplainIt(p,sc,_("This reference has a transformation matrix which cannot be expressed in truetype.\nAll entries (except translation) must be between [-2.0,2.0).\nTranslation must be integral."),0,0);
1717 ref->selected = false;
1718 if ( p->ignorethis ) {
1719 p->selected_records[CID_RefBadTransformTTF] = false;
1720 break;
1721 }
1722 }
1723 }
1724 }
1725
1726 if ( p->selected_records[CID_MixedContoursRefs] && !p->finish ) {
1727 RefChar *ref;
1728 int hasref=0, hascontour = sc->layers[p->layer].splines!=NULL;
1729 for ( ref = sc->layers[p->layer].refs; ref!=NULL ; ref = ref->next ) {
1730 ref->selected = false;
1731 if ( ref->transform[0]>=2 || ref->transform[0]<-2 ||
1732 ref->transform[1]>=2 || ref->transform[1]<-2 ||
1733 ref->transform[2]>=2 || ref->transform[2]<-2 ||
1734 ref->transform[3]>=2 || ref->transform[3]<-2 )
1735 hascontour = true;
1736 else
1737 hasref = true;
1738 if ( hascontour && hasref ) {
1739 changed = true;
1740 ref->selected = true;
1741 ExplainIt(p,sc,_("This glyph contains both contours and references.\n(or contains a reference which has a bad transformation matrix and counts as a contour).\nThis cannot be expressed in the TrueType glyph format."),0,0);
1742 ref->selected = false;
1743 if ( p->ignorethis ) {
1744 p->selected_records[CID_MixedContoursRefs] = false;
1745 break;
1746 }
1747 }
1748 }
1749 }
1750
1751 if ( p->selected_records[CID_RefBadTransformPS] && !p->finish ) {
1752 RefChar *ref;
1753 for ( ref = sc->layers[p->layer].refs; ref!=NULL ; ref = ref->next )
1754 ref->selected = false;
1755 for ( ref = sc->layers[p->layer].refs; !p->finish && ref!=NULL ; ref = ref->next ) {
1756 if ( ref->transform[0]!=1.0 ||
1757 ref->transform[1]!=0 ||
1758 ref->transform[2]!=0 ||
1759 ref->transform[3]!= 1.0 ) {
1760 changed = true;
1761 ref->selected = true;
1762 ExplainIt(p,sc,_("This reference has a transformation matrix which cannot be expressed in Type1/2 fonts.\nNo scaling or rotation allowed."),0,0);
1763 ref->selected = false;
1764 if ( p->ignorethis ) {
1765 p->selected_records[CID_RefBadTransformPS] = false;
1766 break;
1767 }
1768 }
1769 }
1770 }
1771
1772 if ( p->selected_records[CID_MultUseMyMetrics] && !p->finish ) {
1773 RefChar *ref, *found;
1774 for ( ref = sc->layers[p->layer].refs; ref!=NULL ; ref = ref->next )
1775 ref->selected = false;
1776 found = NULL;
1777 for ( ref = sc->layers[p->layer].refs; !p->finish && ref!=NULL ; ref = ref->next ) {
1778 if ( ref->use_my_metrics ) {
1779 if ( found==NULL )
1780 found = ref;
1781 else {
1782 changed = true;
1783 ref->selected = true;
1784 found->selected = true;
1785 ExplainIt(p,sc,_("Both selected references have use-my-metrics set"),0,0);
1786 ref->selected = false;
1787 found->selected = false;
1788 if ( p->ignorethis ) {
1789 p->selected_records[CID_MultUseMyMetrics] = false;
1790 break;
1791 }
1792 }
1793 }
1794 }
1795 }
1796
1797 if ( p->selected_records[CID_PtMatchRefsOutOfDate] && !p->finish ) {
1798 RefChar *ref;
1799 for ( ref = sc->layers[p->layer].refs; ref!=NULL ; ref = ref->next )
1800 ref->selected = false;
1801 for ( ref = sc->layers[p->layer].refs; !p->finish && ref!=NULL ; ref = ref->next ) {
1802 if ( ref->point_match_out_of_date ) {
1803 changed = true;
1804 ref->selected = true;
1805 ExplainIt(p,sc,_("This reference uses point-matching but it refers to a glyph\n(or a previous reference refers to a glyph)\nwhose points have been renumbered."),0,0);
1806 ref->selected = false;
1807 if ( p->ignorethis ) {
1808 p->selected_records[CID_PtMatchRefsOutOfDate] = false;
1809 break;
1810 }
1811 }
1812 }
1813 }
1814
1815 if ( p->selected_records[CID_TooDeepRefs] && !p->finish ) {
1816 int refdepthmax = std::get<int>(p->record_values[CID_TooDeepRefs]);
1817 int cnt=SCRefDepth(sc,p->layer);
1818 if ( cnt>refdepthmax ) {
1819 changed = true;
1820 ExplainIt(p,sc,_("References are nested more deeply in this glyph than the maximum allowed"),cnt,refdepthmax);
1821 if ( p->ignorethis )
1822 p->selected_records[CID_TooDeepRefs] = false;
1823 }
1824 }
1825
1826 if ( p->selected_records[CID_TooManyPoints] && !p->finish ) {
1827 int pointsmax = std::get<int>(p->record_values[CID_TooManyPoints]);
1828 int cnt=0;
1829 RefChar *r;
1830 cnt = SPLPointCnt(sc->layers[p->layer].splines);
1831 for ( r=sc->layers[p->layer].refs; r!=NULL ; r=r->next )
1832 cnt += SPLPointCnt(r->layers[0].splines);
1833 if ( cnt>pointsmax ) {
1834 changed = true;
1835 ExplainIt(p,sc,_("There are more points in this glyph than the maximum allowed"),cnt,pointsmax);
1836 if ( p->ignorethis )
1837 p->selected_records[CID_TooManyPoints] = false;
1838 }
1839 }
1840
1841 if ( p->selected_records[CID_TooManyHints] && !p->finish ) {
1842 int hintsmax = std::get<int>(p->record_values[CID_TooManyHints]);
1843 int cnt=0;
1844 for ( h=sc->hstem; h!=NULL; h=h->next )
1845 ++cnt;
1846 for ( h=sc->vstem; h!=NULL; h=h->next )
1847 ++cnt;
1848 if ( cnt>hintsmax ) {
1849 changed = true;
1850 ExplainIt(p,sc,_("There are more hints in this glyph than the maximum allowed"),cnt,hintsmax);
1851 if ( p->ignorethis )
1852 p->selected_records[CID_TooManyHints] = false;
1853 }
1854 }
1855
1856 if ( p->selected_records[CID_Bitmaps] && !p->finish && SCWorthOutputting(sc)) {
1857 BDFFont *bdf;
1858
1859 for ( bdf=sc->parent->bitmaps; bdf!=NULL; bdf=bdf->next ) {
1860 if ( sc->orig_pos>=bdf->glyphcnt || bdf->glyphs[sc->orig_pos]==NULL ) {
1861 changed = true;
1862 ExplainIt(p,sc,_("This outline glyph is missing a bitmap version"),0,0);
1863 if ( p->ignorethis )
1864 p->selected_records[CID_Bitmaps] = false;
1865 break;
1866 }
1867 }
1868 }
1869
1870 if ( p->selected_records[CID_BitmapWidths] && !p->finish && SCWorthOutputting(sc)) {
1871 BDFFont *bdf;
1872 double em = (sc->parent->ascent+sc->parent->descent);
1873
1874 for ( bdf=sc->parent->bitmaps; bdf!=NULL; bdf=bdf->next ) {
1875 if ( sc->orig_pos<bdf->glyphcnt && bdf->glyphs[sc->orig_pos]!=NULL ) {
1876 BDFChar *bc = bdf->glyphs[sc->orig_pos];
1877 if ( bc->width!= (int) rint( (sc->width*bdf->pixelsize)/em ) ) {
1878 changed = true;
1879 ExplainIt(p,sc,_("This outline glyph's advance width is different from that of the bitmap's"),
1880 bc->width,rint( (sc->width*bdf->pixelsize)/em ));
1881 if ( p->ignorethis )
1882 p->selected_records[CID_BitmapWidths] = false;
1883 break;
1884 }
1885 }
1886 }
1887 }
1888
1889 if ( p->selected_records[CID_AdvanceWidth] && !p->finish && SCWorthOutputting(sc)) {
1890 int advancewidthval = std::get<int>(p->record_values[CID_AdvanceWidth]);
1891 if ( sc->width!=advancewidthval ) {
1892 changed = true;
1893 ExplainIt(p,sc,_("This glyph's advance width is different from the standard width"),sc->width,advancewidthval);
1894 if ( p->ignorethis )
1895 p->selected_records[CID_AdvanceWidth] = false;
1896 }
1897 }
1898
1899 if ( p->selected_records[CID_VAdvanceWidth] && p->fv->b.sf->hasvmetrics && !p->finish && SCWorthOutputting(sc)) {
1900 int vadvancewidthval = std::get<int>(p->record_values[CID_VAdvanceWidth]);
1901 if ( sc->vwidth!=vadvancewidthval ) {
1902 changed = true;
1903 ExplainIt(p,sc,_("This glyph's vertical advance is different from the standard width"),sc->vwidth,vadvancewidthval);
1904 if ( p->ignorethis )
1905 p->selected_records[CID_VAdvanceWidth] = false;
1906 }
1907 }
1908
1909 if ( (p->selected_records[CID_BBYMax] || p->selected_records[CID_BBXMax] || p->selected_records[CID_BBYMin] || p->selected_records[CID_BBXMin]) && !p->finish &&
1910 SCWorthOutputting(sc)) {
1911 int bbymax_val = std::get<int>(p->record_values[CID_BBYMax]);
1912 int bbymin_val = std::get<int>(p->record_values[CID_BBYMin]);
1913 int bbxmax_val = std::get<int>(p->record_values[CID_BBXMax]);
1914 int bbxmin_val = std::get<int>(p->record_values[CID_BBXMin]);
1915 SplineCharFindBounds(sc,&bb);
1916 if ( p->selected_records[CID_BBYMax] && bb.maxy > bbymax_val ) {
1917 changed = true;
1918 ExplainIt(p,sc,_("This glyph is taller than desired"),bb.maxy,bbymax_val);
1919 if ( p->ignorethis )
1920 p->selected_records[CID_BBYMax] = false;
1921 }
1922 if ( p->selected_records[CID_BBYMin] && bb.miny < bbymin_val ) {
1923 changed = true;
1924 ExplainIt(p,sc,_("This glyph extends further below the baseline than desired"),bb.miny,bbymin_val);
1925 if ( p->ignorethis )
1926 p->selected_records[CID_BBYMin] = false;
1927 }
1928 if ( p->selected_records[CID_BBXMax] && bb.maxx > bbxmax_val ) {
1929 changed = true;
1930 ExplainIt(p,sc,_("This glyph is wider than desired"),bb.maxx,bbxmax_val);
1931 if ( p->ignorethis )
1932 p->selected_records[CID_BBXMax] = false;
1933 }
1934 if ( p->selected_records[CID_BBXMin] && bb.minx < bbxmin_val ) {
1935 changed = true;
1936 ExplainIt(p,sc,_("This glyph extends left further than desired"),bb.minx,bbxmin_val);
1937 if ( p->ignorethis )
1938 p->selected_records[CID_BBXMin] = false;
1939 }
1940 }
1941
1942 if ( p->selected_records[CID_BadSubs] && !p->finish ) {
1943 PST *pst;
1944 char *pt, *end; int ch;
1945 for ( pst = sc->possub ; pst!=NULL; pst=pst->next ) {
1946 if ( pst->type==pst_substitution || pst->type==pst_alternate ||
1947 pst->type==pst_multiple || pst->type==pst_ligature ) {
1948 for ( pt=pst->u.subs.variant; *pt!='\0' ; pt=end ) {
1949 end = strchr(pt,' ');
1950 if ( end==NULL ) end=pt+strlen(pt);
1951 ch = *end;
1952 *end = '\0';
1953 if ( !SCWorthOutputting(SFGetChar(sc->parent,-1,pt)) ) {
1954 changed = true;
1955 p->badsubsname = copy(pt);
1956 *end = ch;
1957 p->badsubs_lsubtable = pst->subtable;
1958 ExplainIt(p,sc,_("This glyph contains a substitution or ligature entry which refers to an empty char"),0,0);
1959 free(p->badsubsname);
1960 if ( p->ignorethis )
1961 p->selected_records[CID_BadSubs] = false;
1962 } else
1963 *end = ch;
1964 while ( *end==' ' ) ++end;
1965 if ( !p->selected_records[CID_BadSubs] )
1966 break;
1967 }
1968 if ( !p->selected_records[CID_BadSubs] )
1969 break;
1970 }
1971 }
1972 }
1973
1974 if ( p->selected_records[CID_MissingAnchor] && !p->finish ) {
1975 for (;;) {
1976 p->missinganchor_class = SCValidateAnchors(sc);
1977 if ( p->missinganchor_class == NULL )
1978 break;
1979 ExplainIt(p,sc,_("This glyph contains anchor points from some, but not all anchor classes in a subtable"),0,0);
1980 if ( p->ignorethis )
1981 p->selected_records[CID_MissingAnchor] = false;
1982 break;
1983 }
1984 }
1985
1986 if ( p->selected_records[CID_MultUni] && !p->finish && sc->unicodeenc!=-1 ) {
1987 SplineFont *sf = sc->parent;
1988 int i;
1989 for ( i=0; i<sf->glyphcnt; ++i )
1990 if ( sf->glyphs[i]!=NULL && sf->glyphs[i]!=sc ) {
1991 if ( sf->glyphs[i]->unicodeenc == sc->unicodeenc ) {
1992 changed = true;
1993 p->glyphname = sf->glyphs[i]->name;
1994 ExplainIt(p,sc,_("Two glyphs share the same unicode code point.\nChange the encoding to \"Glyph Order\" and use\nEdit->Select->Wildcard with the following code point"),0,0);
1995 if ( p->ignorethis )
1996 p->selected_records[CID_MultUni] = false;
1997 }
1998 }
1999 }
2000
2001 if ( p->selected_records[CID_MultName] && !p->finish ) {
2002 SplineFont *sf = sc->parent;
2003 int i;
2004 for ( i=0; i<sf->glyphcnt; ++i )
2005 if ( sf->glyphs[i]!=NULL && sf->glyphs[i]!=sc ) {
2006 if ( strcmp(sf->glyphs[i]->name, sc->name)==0 ) {
2007 changed = true;
2008 p->glyphenc = i;
2009 ExplainIt(p,sc,_("Two glyphs have the same name.\nChange the encoding to \"Glyph Order\" and use\nEdit->Select->Wildcard with the following name"),0,0);
2010 if ( p->ignorethis )
2011 p->selected_records[CID_MultName] = false;
2012 }
2013 }
2014 }
2015
2016 if ( p->selected_records[CID_UniNameMisMatch] && !p->finish &&
2017 strcmp(sc->name,".notdef")!=0 &&
2018 strcmp(sc->name,".null")!=0 &&
2019 strcmp(sc->name,"nonmarkingreturn")!=0 &&
2020 (uni = UniFromName(sc->name,sc->parent->uni_interp,p->fv->b.map->enc))!= -1 &&
2021 sc->unicodeenc != uni ) {
2022 changed = true;
2023 p->glyphenc = sc->orig_pos;
2024 if ( sc->unicodeenc==-1 )
2025 ExplainIt(p,sc,_("This glyph is not mapped to any unicode code point, but its name should be."),0,0);
2026 else if ( strcmp(sc->name,"alefmaksurainitialarabic")==0 ||
2027 strcmp(sc->name,"alefmaksuramedialarabic")==0 )
2028 ExplainIt(p,sc,_("The use of names 'alefmaksurainitialarabic' and 'alefmaksuramedialarabic' is discouraged."),0,0);
2029 else
2030 ExplainIt(p,sc,_("This glyph is mapped to a unicode code point which is different from its name."),0,0);
2031 if ( p->ignorethis )
2032 p->selected_records[CID_UniNameMisMatch] = false;
2033 }
2034
2035
2036 if ( needsupdate || changed )
2037 SCUpdateAll(sc);
2038 return( changed );
2039 }
2040
2041 static int CIDCheck(struct problems *p,int cid) {
2042 int found = false;
2043 if (p->fv->b.cidmaster == NULL)
2044 return found;
2045
2046 if ( (p->selected_records[CID_CIDMultiple] || p->selected_records[CID_CIDBlank]) && !p->finish ) {
2047 SplineFont *csf = p->fv->b.cidmaster;
2048 int i, cnt;
2049 for ( i=cnt=0; i<csf->subfontcnt; ++i )
2050 if ( cid<csf->subfonts[i]->glyphcnt &&
2051 SCWorthOutputting(csf->subfonts[i]->glyphs[cid]) )
2052 ++cnt;
2053 if ( cnt>1 && p->selected_records[CID_CIDMultiple] ) {
2054 _ExplainIt(p,cid,_("This glyph is defined in more than one of the CID subfonts"),cnt,1);
2055 if ( p->ignorethis )
2056 p->selected_records[CID_CIDMultiple] = false;
2057 found = true;
2058 } else if ( cnt==0 && p->selected_records[CID_CIDBlank] ) {
2059 _ExplainIt(p,cid,_("This glyph is not defined in any of the CID subfonts"),0,0);
2060 if ( p->ignorethis )
2061 p->selected_records[CID_CIDBlank] = false;
2062 found = true;
2063 }
2064 }
2065 return( found );
2066 }
2067
2068 static char *missinglookup(struct problems *p,char *str) {
2069 int i;
2070
2071 for ( i=0; i<p->rpl_cnt; ++i )
2072 if ( strcmp(str,p->mg[i].search)==0 )
2073 return( p->mg[i].rpl );
2074
2075 return( NULL );
2076 }
2077
2078 static void mgreplace(char **base, char *str,char *end, const char *new_str, SplineChar *sc, PST *pst) {
2079 PST *p, *ps;
2080
2081 if ( new_str==NULL || *new_str=='\0' ) {
2082 if ( *base==str && *end=='\0' && sc!=NULL ) {
2083 /* We deleted the last name from the pst, it is meaningless, remove it */
2084 if ( sc->possub==pst )
2085 sc->possub = pst->next;
2086 else {
2087 for ( p = sc->possub, ps=p->next; ps!=NULL && ps!=pst; p=ps, ps=ps->next );
2088 if ( ps!=NULL )
2089 p->next = pst->next;
2090 }
2091 pst->next = NULL;
2092 PSTFree(pst);
2093 } else if ( *end=='\0' )
2094 *str = '\0';
2095 else
2096 strcpy(str,end+1); /* Skip the space */
2097 } else {
2098 char *res = (char *) malloc(strlen(*base)+strlen(new_str)-(end-str)+1);
2099 strncpy(res,*base,str-*base);
2100 strcpy(res+(str-*base),new_str);
2101 strcat(res,end);
2102 free(*base);
2103 *base = res;
2104 }
2105 }
2106
2107 static void ClearMissingState(struct problems *p) {
2108 int i;
2109
2110 if ( p->mg!=NULL ) {
2111 for ( i=0; i<p->rpl_cnt; ++i ) {
2112 free(p->mg[i].search);
2113 free(p->mg[i].rpl);
2114 }
2115 free(p->mg);
2116 } else
2117 free(p->mlt);
2118 p->mlt = NULL;
2119 p->mg = NULL;
2120 p->rpl_cnt = p->rpl_max = 0;
2121 }
2122
2123 enum missingglyph_type { mg_pst, mg_fpst, mg_kern, mg_vkern, mg_asm };
2124 struct mgask_data {
2125 GWindow gw;
2126 uint8_t done, skipped;
2127 uint32_t tag;
2128 char **_str, *start, *end;
2129 SplineChar *sc;
2130 PST *pst;
2131 struct problems *p;
2132 };
2133
2134 static void mark_to_replace(struct problems *p,struct mgask_data *d, const char *rpl) {
2135 int ch;
2136
2137 if ( p->rpl_cnt >= p->rpl_max ) {
2138 if ( p->rpl_max == 0 )
2139 p->mg = (struct mgrpl *) malloc((p->rpl_max = 30)*sizeof(struct mgrpl));
2140 else
2141 p->mg = (struct mgrpl *) realloc(p->mg,(p->rpl_max += 30)*sizeof(struct mgrpl));
2142 }
2143 ch = *d->end; *d->end = '\0';
2144 p->mg[p->rpl_cnt].search = copy( d->start );
2145 p->mg[p->rpl_cnt++].rpl = copy( rpl );
2146 *d->end = ch;
2147 }
2148
2149 #define CID_Always 1001
2150 #define CID_RplText 1002
2151 #define CID_Ignore 1003
2152 #define CID_Rpl 1004
2153 #define CID_Skip 1005
2154 #define CID_Delete 1006
2155
2156 static int MGA_RplChange(GGadget *g, GEvent *e) {
2157 if ( e->type==et_controlevent && e->u.control.subtype == et_textchanged ) {
2158 struct mgask_data *d = (struct mgask_data *) GDrawGetUserData(GGadgetGetWindow(g));
2159 const unichar_t *rpl = _GGadgetGetTitle(g);
2160 GGadgetSetEnabled(GWidgetGetControl(d->gw,CID_Rpl),*rpl!=0);
2161 }
2162 return( true );
2163 }
2164
2165 static int MGA_Rpl(GGadget *g, GEvent *e) {
2166 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
2167 struct mgask_data *d = (struct mgask_data *) GDrawGetUserData(GGadgetGetWindow(g));
2168 const unichar_t *_rpl = _GGadgetGetTitle(GWidgetGetControl(d->gw,CID_RplText));
2169 char *rpl = cu_copy(_rpl);
2170 if ( GGadgetIsChecked(GWidgetGetControl(d->gw,CID_Always)))
2171 mark_to_replace(d->p,d,rpl);
2172 mgreplace(d->_str,d->start,d->end,rpl,d->sc,d->pst);
2173 free(rpl);
2174 d->done = true;
2175 }
2176 return( true );
2177 }
2178
2179 static int MGA_Delete(GGadget *g, GEvent *e) {
2180 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
2181 struct mgask_data *d = (struct mgask_data *) GDrawGetUserData(GGadgetGetWindow(g));
2182 if ( GGadgetIsChecked(GWidgetGetControl(d->gw,CID_Always)))
2183 mark_to_replace(d->p,d,"");
2184 mgreplace(d->_str,d->start,d->end,"",d->sc,d->pst);
2185 d->done = true;
2186 }
2187 return( true );
2188 }
2189
2190 static int MGA_Skip(GGadget *g, GEvent *e) {
2191 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
2192 struct mgask_data *d = (struct mgask_data *) GDrawGetUserData(GGadgetGetWindow(g));
2193 d->done = d->skipped = true;
2194 }
2195 return( true );
2196 }
2197
2198 static int mgask_e_h(GWindow gw, GEvent *event) {
2199 if ( event->type==et_close ) {
2200 struct mgask_data *d = (struct mgask_data *) GDrawGetUserData(gw);
2201 d->done = d->skipped = true;
2202 } else if ( event->type==et_char ) {
2203 if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) {
2204 help("ui/dialogs/problems.html", NULL);
2205 return( true );
2206 }
2207 return( false );
2208 }
2209 return( true );
2210 }
2211
2212 static int mgAsk(struct problems *p,char **_str,char *str, char *end,uint32_t tag,
2213 SplineChar *sc,enum missingglyph_type which,void *data) {
2214 char buffer[200];
2215 static const char *pstnames[] = { "", N_("position"), N_("pair"), N_("substitution"),
2216 N_("alternate subs"), N_("multiple subs"), N_("ligature"), NULL };
2217 static const char *fpstnames[] = { N_("Contextual position"), N_("Contextual substitution"),
2218 N_("Chaining position"), N_("Chaining substitution"), N_("Reverse chaining subs"), NULL };
2219 static const char *asmnames[] = { N_("Indic reordering"), N_("Contextual substitution"),
2220 N_("Lig"), NULL, N_("Simple"), N_("Contextual insertion"), NULL, NULL, NULL,
2221 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2222 N_("Kerning"), NULL };
2223 PST *pst = (PST *) data;
2224 FPST *fpst = (FPST *) data;
2225 ASM *sm = (ASM *) data;
2226 KernClass *kc = (KernClass *) data;
2227 char end_ch;
2228 GRect pos;
2229 GWindow gw;
2230 GWindowAttrs wattrs;
2231 GGadgetCreateData gcd[12];
2232 GTextInfo label[12];
2233 struct mgask_data d;
2234 int blen = GIntGetResource(_NUM_Buttonsize), ptwidth;
2235 int k;
2236
2237 end_ch = *end; *end = '\0';
2238
2239 if ( which == mg_pst ) {
2240 snprintf(buffer,sizeof(buffer),
2241 _("Glyph %1$.50s with a %2$s from lookup subtable %3$.50s"),
2242 sc->name, _(pstnames[pst->type]),
2243 pst->subtable->subtable_name );
2244 } else if ( which == mg_fpst )
2245 snprintf(buffer,sizeof(buffer),
2246 _("%1$s from lookup subtable %2$.50s"),
2247 _(fpstnames[fpst->type-pst_contextpos]),
2248 fpst->subtable->subtable_name );
2249 else if ( which == mg_asm )
2250 snprintf(buffer,sizeof(buffer),
2251 _("%1$s from lookup subtable %2$.50s"),
2252 _(asmnames[sm->type]),
2253 sm->subtable->subtable_name );
2254 else
2255 snprintf(buffer,sizeof(buffer),
2256 _("%1$s from lookup subtable %2$.50s"),
2257 which==mg_kern ? _("Kerning Class"): _("Vertical Kerning Class"),
2258 kc->subtable->subtable_name );
2259
2260 memset(&d,'\0',sizeof(d));
2261 d._str = _str;
2262 d.start = str;
2263 d.end = end;
2264 d.sc = sc;
2265 d.pst = which==mg_pst ? (PST *) data : NULL;
2266 d.p = p;
2267 d.tag = tag;
2268
2269 memset(&wattrs,0,sizeof(wattrs));
2270 wattrs.mask = (enum window_attr_mask)(wam_events|wam_cursor|wam_utf8_wtitle|wam_centered|wam_restrict|wam_isdlg);
2271 wattrs.event_masks = ~(1<<et_charup);
2272 wattrs.is_dlg = 1;
2273 wattrs.restrict_input_to_me = 1;
2274 wattrs.centered = 1;
2275 wattrs.cursor = ct_pointer;
2276 wattrs.utf8_window_title = _("Check for missing glyph names");
2277 pos.x = pos.y = 0;
2278 ptwidth = 3*blen+GGadgetScale(80);
2279 pos.width =GDrawPointsToPixels(NULL,ptwidth);
2280 pos.height = GDrawPointsToPixels(NULL,180);
2281 d.gw = gw = GDrawCreateTopWindow(NULL,&pos,mgask_e_h,&d,&wattrs);
2282
2283 memset(&label,0,sizeof(label));
2284 memset(&gcd,0,sizeof(gcd));
2285
2286 k=0;
2287 label[k].text = (unichar_t *) buffer;
2288 label[k].text_is_1byte = true;
2289 gcd[k].gd.label = &label[k];
2290 gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = 6;
2291 gcd[k].gd.flags = (enum gg_flags) (gg_visible | gg_enabled);
2292 gcd[k++].creator = GLabelCreate;
2293
2294 label[k].text = (unichar_t *) _(" refers to a missing glyph");
2295 label[k].text_is_1byte = true;
2296 gcd[k].gd.label = &label[k];
2297 gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+13;
2298 gcd[k].gd.flags = (enum gg_flags) (gg_visible | gg_enabled);
2299 gcd[k++].creator = GLabelCreate;
2300
2301 label[k].text = (unichar_t *) str;
2302 label[k].text_is_1byte = true;
2303 gcd[k].gd.label = &label[k];
2304 gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+13;
2305 gcd[k].gd.flags = (enum gg_flags) (gg_visible | gg_enabled);
2306 gcd[k++].creator = GLabelCreate;
2307
2308 label[k].text = (unichar_t *) _("Replace With:");
2309 label[k].text_is_1byte = true;
2310 gcd[k].gd.label = &label[k];
2311 gcd[k].gd.pos.x = 5; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+16;
2312 gcd[k].gd.flags = (enum gg_flags) (gg_visible | gg_enabled);
2313 gcd[k++].creator = GLabelCreate;
2314
2315 gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+13; gcd[k].gd.pos.width = ptwidth-20;
2316 gcd[k].gd.flags = (enum gg_flags) (gg_visible | gg_enabled);
2317 gcd[k].gd.cid = CID_RplText;
2318 gcd[k].gd.handle_controlevent = MGA_RplChange;
2319 gcd[k++].creator = GTextFieldCreate;
2320
2321 gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+30;
2322 gcd[k].gd.flags = (enum gg_flags) (gg_visible | gg_enabled);
2323 label[k].text = (unichar_t *) _("Always");
2324 label[k].text_is_1byte = true;
2325 gcd[k].gd.label = &label[k];
2326 gcd[k].gd.cid = CID_Always;
2327 gcd[k++].creator = GCheckBoxCreate;
2328
2329 label[k].text = (unichar_t *) _("Ignore this problem in the future");
2330 label[k].text_is_1byte = true;
2331 gcd[k].gd.label = &label[k];
2332 gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+20;
2333 gcd[k].gd.flags = (enum gg_flags) (gg_visible | gg_enabled);
2334 gcd[k].gd.cid = CID_Ignore;
2335 gcd[k++].creator = GCheckBoxCreate;
2336
2337 gcd[k].gd.pos.x = 10-3; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+30 -3;
2338 gcd[k].gd.pos.width = -1;
2339 gcd[k].gd.flags = (enum gg_flags) (gg_visible | gg_but_default);
2340 label[k].text = (unichar_t *) _("Replace");
2341 label[k].text_is_1byte = true;
2342 gcd[k].gd.label = &label[k];
2343 gcd[k].gd.handle_controlevent = MGA_Rpl;
2344 gcd[k].gd.cid = CID_Rpl;
2345 gcd[k++].creator = GButtonCreate;
2346
2347 gcd[k].gd.pos.x = 10+blen+(ptwidth-3*blen-GGadgetScale(20))/2;
2348 gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+3;
2349 gcd[k].gd.pos.width = -1;
2350 gcd[k].gd.flags = (enum gg_flags) (gg_visible | gg_enabled);
2351 label[k].text = (unichar_t *) _("Remove");
2352 label[k].text_is_1byte = true;
2353 gcd[k].gd.label = &label[k];
2354 gcd[k].gd.handle_controlevent = MGA_Delete;
2355 gcd[k].gd.cid = CID_Delete;
2356 gcd[k++].creator = GButtonCreate;
2357
2358 gcd[k].gd.pos.x = -10; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y;
2359 gcd[k].gd.pos.width = -1;
2360 gcd[k].gd.flags = (enum gg_flags) (gg_visible | gg_enabled | gg_but_cancel);
2361 label[k].text = (unichar_t *) _("Skip");
2362 label[k].text_is_1byte = true;
2363 gcd[k].gd.label = &label[k];
2364 gcd[k].gd.handle_controlevent = MGA_Skip;
2365 gcd[k].gd.cid = CID_Skip;
2366 gcd[k++].creator = GButtonCreate;
2367
2368 gcd[k].gd.pos.x = 2; gcd[k].gd.pos.y = 2;
2369 gcd[k].gd.pos.width = pos.width-4; gcd[k].gd.pos.height = pos.height-4;
2370 gcd[k].gd.flags = (enum gg_flags) (gg_visible | gg_enabled | gg_pos_in_pixels);
2371 gcd[k++].creator = GGroupCreate;
2372
2373 GGadgetsCreate(gw,gcd);
2374 *end = end_ch;
2375 GDrawSetVisible(gw,true);
2376
2377 while ( !d.done )
2378 GDrawProcessOneEvent(NULL);
2379 if ( GGadgetIsChecked(GWidgetGetControl(gw,CID_Ignore)))
2380 p->selected_records[CID_MissingGlyph] = false;
2381 GDrawDestroyWindow(gw);
2382 return( !d.skipped );
2383 }
2384
2385 static int StrMissingGlyph(struct problems *p,char **_str,SplineChar *sc,enum missingglyph_type which, void *data) {
2386 char *end, ch, *str = *_str, *new_str;
2387 int off;
2388 int found = false;
2389 SplineFont *sf = p->fv!=NULL ? p->fv->b.sf : CVValid(p->fv->b.sf,p->sc,p->cv) ? p->cv->b.sc->parent : p->msc->parent;
2390 SplineChar *ssc;
2391 int changed=false;
2392
2393 if ( str==NULL )
2394 return( false );
2395
2396 while ( *str ) {
2397 if ( p->finish || !p->selected_records[CID_MissingGlyph] )
2398 break;
2399 while ( *str==' ' ) ++str;
2400 for ( end=str; *end!='\0' && *end!=' '; ++end );
2401 ch = *end; *end='\0';
2402 if ( strcmp(str,MAC_DELETED_GLYPH_NAME)==0 )
2403 ssc = (SplineChar *) 1;
2404 else
2405 ssc = SFGetChar(sf,-1,str);
2406 *end = ch;
2407 if ( ssc==NULL ) {
2408 off = end-*_str;
2409 if ( (new_str = missinglookup(p,str))!=NULL ) {
2410 mgreplace(_str, str,end, new_str, sc, which==mg_pst ? (PST*)data : NULL);
2411 changed = true;
2412 off += (strlen(new_str)-(end-str));
2413 } else {
2414 if ( mgAsk(p,_str,str,end,0,sc,which,data)) {
2415 changed = true;
2416 off = 0;
2417 }
2418 found = true;
2419 }
2420 if ( changed ) {
2421 PST *test;
2422 if ( which==mg_pst ) {
2423 for ( test = sc->possub; test!=NULL && test!=data; test=test->next );
2424 if ( test==NULL ) /* Entire pst was removed */
2425 return( true );
2426 *_str = test->u.subs.variant;
2427 }
2428 end = *_str+off;
2429 }
2430 }
2431 str = end;
2432 }
2433 return( found );
2434 }
2435
2436 static int SCMissingGlyph(struct problems *p,SplineChar *sc) {
2437 PST *pst, *next;
2438 int found = false;
2439
2440 if ( !p->selected_records[CID_MissingGlyph] || p->finish || sc==NULL )
2441 return( false );
2442
2443 for ( pst=sc->possub; pst!=NULL; pst=next ) {
2444 next = pst->next;
2445 switch ( pst->type ) {
2446 case pst_pair:
2447 found |= StrMissingGlyph(p,&pst->u.pair.paired,sc,mg_pst,pst);
2448 break;
2449 case pst_substitution:
2450 case pst_alternate:
2451 case pst_multiple:
2452 case pst_ligature:
2453 found |= StrMissingGlyph(p,&pst->u.subs.variant,sc,mg_pst,pst);
2454 break;
2455 }
2456 }
2457 return( found );
2458 }
2459
2460 static int KCMissingGlyph(struct problems *p,KernClass *kc,int isv) {
2461 int i;
2462 int found = false;
2463 enum missingglyph_type which = isv ? mg_vkern : mg_kern;
2464
2465 for ( i=0; i<kc->first_cnt; ++i ) if ( kc->firsts[i]!=NULL )
2466 found |= StrMissingGlyph(p,&kc->firsts[i],NULL,which,kc);
2467 for ( i=1; i<kc->second_cnt; ++i )
2468 found |= StrMissingGlyph(p,&kc->seconds[i],NULL,which,kc);
2469 return( found );
2470 }
2471
2472 static int FPSTMissingGlyph(struct problems *p,FPST *fpst) {
2473 int i,j;
2474 int found = false;
2475
2476 switch ( fpst->format ) {
2477 case pst_glyphs:
2478 for ( i=0; i<fpst->rule_cnt; ++i )
2479 for ( j=0; j<3; ++j )
2480 found |= StrMissingGlyph(p,&(&fpst->rules[i].u.glyph.names)[j],
2481 NULL,mg_fpst,fpst);
2482 break;
2483 case pst_class:
2484 for ( i=1; i<3; ++i )
2485 for ( j=0; j<(&fpst->nccnt)[i]; ++j )
2486 found |= StrMissingGlyph(p,&(&fpst->nclass)[i][j],NULL,mg_fpst,fpst);
2487 break;
2488 case pst_reversecoverage:
2489 found |= StrMissingGlyph(p,&fpst->rules[0].u.rcoverage.replacements,NULL,mg_fpst,fpst);
2490 /* fall through */;
2491 case pst_coverage:
2492 for ( i=1; i<3; ++i )
2493 for ( j=0; j<(&fpst->rules[0].u.coverage.ncnt)[i]; ++j )
2494 found |= StrMissingGlyph(p,&(&fpst->rules[0].u.coverage.ncovers)[i][j],NULL,mg_fpst,fpst);
2495 break;
2496 }
2497 return( found );
2498 }
2499
2500 static int ASMMissingGlyph(struct problems *p,ASM *sm) {
2501 int j;
2502 int found = false;
2503
2504 for ( j=4; j<sm->class_cnt; ++j )
2505 found |= StrMissingGlyph(p,&sm->classes[j],NULL,mg_asm,sm);
2506 return( found );
2507 }
2508
2509 static int LookupFeaturesMissScript(struct problems *p,OTLookup *otl,OTLookup *nested,
2510 uint32_t script, SplineFont *sf, char *glyph_name) {
2511 OTLookup *invokers, *any;
2512 struct lookup_subtable *subs;
2513 int i,l, ret;
2514 int found = false;
2515 FeatureScriptLangList *fsl;
2516 struct scriptlanglist *sl;
2517 char buffer[400];
2518 const char *buts[4];
2519
2520 if ( script==DEFAULT_SCRIPT )
2521 return( false );
2522
2523 if ( otl->features == NULL ) {
2524 /* No features invoke us, so presume that we are to be invoked by a */
2525 /* contextual lookup, and check its scripts rather than ours */
2526 if ( nested!=NULL ) {
2527 /* There is no need to have a nested contextual lookup */
2528 /* so we don't support them */
2529 return(false);
2530 }
2531 any = NULL;
2532 for ( invokers=otl->lookup_type>=gpos_start?sf->gpos_lookups:sf->gsub_lookups;
2533 invokers!=NULL ; invokers = invokers->next ) {
2534 for ( subs=invokers->subtables; subs!=NULL; subs=subs->next ) {
2535 if ( subs->fpst!=NULL ) {
2536 FPST *fpst = subs->fpst;
2537 for ( i=0; i<fpst->rule_cnt; ++i ) {
2538 struct fpst_rule *r = &fpst->rules[i];
2539 for ( l=0; l<r->lookup_cnt; ++l )
2540 if ( r->lookups[l].lookup == otl ) {
2541 found |= LookupFeaturesMissScript(p,invokers,otl,script,sf,glyph_name);
2542 any = invokers;
2543 }
2544 }
2545 }
2546 }
2547 }
2548 if ( any==NULL ) {
2549 /* No opentype contextual lookup uses this lookup with no features*/
2550 /* so it appears totally useless. But a mac feature might I guess*/
2551 /* so don't complain */
2552 }
2553 } else {
2554 for ( fsl = otl->features; fsl!=NULL; fsl=fsl->next ) {
2555 for ( sl=fsl->scripts; sl!=NULL; sl=sl->next ) {
2556 if ( sl->script==script )
2557 break;
2558 }
2559 if ( sl!=NULL )
2560 break;
2561 }
2562 if ( fsl==NULL ) {
2563 buffer[0]='\0';
2564 if ( nested!=NULL )
2565 snprintf(buffer,sizeof(buffer),
2566 _("The lookup %.30s which invokes lookup %.30s is active "
2567 "for glyph %.30s which has script '%c%c%c%c', yet this script does not "
2568 "appear in any of the features which apply the lookup.\n"
2569 "Would you like to add this script to one of those features?"),
2570 otl->lookup_name, nested->lookup_name,
2571 glyph_name,
2572 script>>24, script>>16, script>>8, script);
2573 else
2574 snprintf(buffer,sizeof(buffer),
2575 _("The lookup %.30s is active for glyph %.30s which has script "
2576 "'%c%c%c%c', yet this script does not appear in any of the features which "
2577 "apply the lookup.\n\n"
2578 "Would you like to add this script to one of those features?"),
2579 otl->lookup_name, glyph_name,
2580 script>>24, script>>16, script>>8, script);
2581 buts[0] = _("_OK"); buts[1] = _("_Skip"); buts[2]="_Ignore"; buts[3] = NULL;
2582 ret = ff_ask(_("Missing Script"),(const char **) buts,0,1,buffer);
2583 if ( ret==0 ) {
2584 sl = (struct scriptlanglist*)chunkalloc(sizeof(struct scriptlanglist));
2585 sl->script = script;
2586 sl->lang_cnt = 1;
2587 sl->langs[0] = DEFAULT_LANG;
2588 sl->next = otl->features->scripts;
2589 otl->features->scripts = sl;
2590 sf->changed = true;
2591 } else if ( ret==2 )
2592 p->selected_records[CID_MissingScriptInFeature] = false;
2593 return( true );
2594 }
2595 }
2596 return( found );
2597 }
2598
2599 static int SCMissingScriptFeat(struct problems *p,SplineFont *sf,SplineChar *sc) {
2600 PST *pst;
2601 int found = false;
2602 uint32_t script;
2603 AnchorPoint *ap;
2604
2605 if ( !p->selected_records[CID_MissingScriptInFeature] || p->finish || sc==NULL )
2606 return( false );
2607 script = SCScriptFromUnicode(sc);
2608
2609 for ( pst=sc->possub; pst!=NULL; pst=pst->next ) if ( pst->subtable!=NULL )
2610 found |= LookupFeaturesMissScript(p,pst->subtable->lookup,NULL,script,sf,sc->name);
2611 for ( ap=sc->anchor; ap!=NULL; ap=ap->next ) if ( ap->anchor->subtable!=NULL )
2612 found |= LookupFeaturesMissScript(p,ap->anchor->subtable->lookup,NULL,script,sf,sc->name);
2613
2614 return( found );
2615 }
2616
2617 static int StrMissingScript(struct problems *p,SplineFont *sf,OTLookup *otl,char *class_name) {
2618 char *pt, *start;
2619 int ch;
2620 SplineChar *sc;
2621 uint32_t script;
2622 int found = 0;
2623
2624 if ( class_name==NULL )
2625 return( false );
2626
2627 for ( pt=class_name; *pt && p->selected_records[CID_MissingScriptInFeature]; ) {
2628 while ( *pt==' ' ) ++pt;
2629 if ( *pt=='\0' )
2630 break;
2631 for ( start=pt; *pt && *pt!=' '; ++pt );
2632 ch = *pt; *pt='\0';
2633 sc = SFGetChar(sf,-1,start);
2634 *pt = ch;
2635 if ( sc!=NULL ) {
2636 script = SCScriptFromUnicode(sc);
2637 found |= LookupFeaturesMissScript(p,otl,NULL,script,sf,sc->name);
2638 }
2639 }
2640 return( found );
2641 }
2642
2643 static int KCMissingScriptFeat(struct problems *p,SplineFont *sf, KernClass *kc,int isv) {
2644 int i;
2645 int found = false;
2646 OTLookup *otl = kc->subtable->lookup;
2647
2648 for ( i=0; i<kc->first_cnt; ++i )
2649 found |= StrMissingScript(p,sf,otl,kc->firsts[i]);
2650 return( found );
2651 }
2652
2653 static int FPSTMissingScriptFeat(struct problems *p,SplineFont *sf,FPST *fpst) {
2654 int i,j;
2655 int found = false;
2656 OTLookup *otl = fpst->subtable->lookup;
2657
2658 switch ( fpst->format ) {
2659 case pst_glyphs:
2660 for ( i=0; i<fpst->rule_cnt; ++i )
2661 for ( j=0; j<3; ++j )
2662 found |= StrMissingScript(p,sf,otl,(&fpst->rules[i].u.glyph.names)[j]);
2663 break;
2664 case pst_class:
2665 for ( i=1; i<3; ++i )
2666 for ( j=0; j<(&fpst->nccnt)[i]; ++j )
2667 found |= StrMissingScript(p,sf,otl,(&fpst->nclass)[i][j]);
2668 break;
2669 case pst_reversecoverage:
2670 found |= StrMissingScript(p,sf,otl,fpst->rules[0].u.rcoverage.replacements);
2671 /* fall through */;
2672 case pst_coverage:
2673 for ( i=1; i<3; ++i )
2674 for ( j=0; j<(&fpst->rules[0].u.coverage.ncnt)[i]; ++j )
2675 found |= StrMissingScript(p,sf,otl,(&fpst->rules[0].u.coverage.ncovers)[i][j]);
2676 break;
2677 }
2678 return( found );
2679 }
2680
2681 static int CheckForATT(struct problems *p) {
2682 int found = false;
2683 int i,k;
2684 FPST *fpst;
2685 ASM *sm;
2686 KernClass *kc;
2687 SplineFont *_sf, *sf;
2688
2689 _sf = p->fv->b.sf;
2690 if ( _sf->cidmaster ) _sf = _sf->cidmaster;
2691
2692 if ( p->selected_records[CID_MissingGlyph] && !p->finish ) {
2693 if ( CVValid(p->fv->b.sf,p->sc,p->cv) )
2694 found = SCMissingGlyph(p,p->cv->b.sc);
2695 else if ( p->msc!=NULL )
2696 found = SCMissingGlyph(p,p->msc);
2697 else {
2698 k=0;
2699 do {
2700 if ( _sf->subfonts==NULL ) sf = _sf;
2701 else sf = _sf->subfonts[k++];
2702 for ( i=0; i<sf->glyphcnt && !p->finish; ++i ) if ( sf->glyphs[i]!=NULL )
2703 found |= SCMissingGlyph(p,sf->glyphs[i]);
2704 } while ( k<_sf->subfontcnt && !p->finish );
2705 for ( kc=_sf->kerns; kc!=NULL && !p->finish; kc=kc->next )
2706 found |= KCMissingGlyph(p,kc,false);
2707 for ( kc=_sf->vkerns; kc!=NULL && !p->finish; kc=kc->next )
2708 found |= KCMissingGlyph(p,kc,true);
2709 for ( fpst=_sf->possub; fpst!=NULL && !p->finish && p->selected_records[CID_MissingGlyph]; fpst=fpst->next )
2710 found |= FPSTMissingGlyph(p,fpst);
2711 for ( sm=_sf->sm; sm!=NULL && !p->finish && p->selected_records[CID_MissingGlyph]; sm=sm->next )
2712 found |= ASMMissingGlyph(p,sm);
2713 }
2714 ClearMissingState(p);
2715 }
2716
2717 if ( p->selected_records[CID_MissingScriptInFeature] && !p->finish ) {
2718 if ( CVValid(p->fv->b.sf,p->sc,p->cv) )
2719 found = SCMissingScriptFeat(p,_sf,p->cv->b.sc);
2720 else if ( p->msc!=NULL )
2721 found = SCMissingScriptFeat(p,_sf,p->msc);
2722 else {
2723 k=0;
2724 do {
2725 if ( _sf->subfonts==NULL ) sf = _sf;
2726 else sf = _sf->subfonts[k++];
2727 for ( i=0; i<sf->glyphcnt && !p->finish; ++i ) if ( sf->glyphs[i]!=NULL )
2728 found |= SCMissingScriptFeat(p,_sf,sf->glyphs[i]);
2729 } while ( k<_sf->subfontcnt && !p->finish );
2730 for ( kc=_sf->kerns; kc!=NULL && !p->finish; kc=kc->next )
2731 found |= KCMissingScriptFeat(p,_sf,kc,false);
2732 for ( kc=_sf->vkerns; kc!=NULL && !p->finish; kc=kc->next )
2733 found |= KCMissingScriptFeat(p,_sf,kc,true);
2734 for ( fpst=_sf->possub; fpst!=NULL && !p->finish && p->selected_records[CID_MissingGlyph]; fpst=fpst->next )
2735 found |= FPSTMissingScriptFeat(p,_sf,fpst);
2736 /* Apple's state machines don't have the concept of "script" */
2737 /* for their feature/settings */
2738 }
2739 }
2740
2741 return( found );
2742 }
2743
2744 static void DoProbs(struct problems *p) {
2745 int i, ret=false, gid;
2746 SplineChar *sc;
2747 BDFFont *bdf;
2748
2749 p->explain = true;
2750 ret = CheckForATT(p);
2751 if ( CVValid(p->fv->b.sf,p->sc,p->cv) ) {
2752 ret |= SCProblems(p->cv,NULL,p);
2753 ret |= CIDCheck(p,p->cv->b.sc->orig_pos);
2754 } else if ( p->msc!=NULL ) {
2755 ret |= SCProblems(NULL,p->msc,p);
2756 ret |= CIDCheck(p,p->msc->orig_pos);
2757 } else {
2758 for ( i=0; i<p->fv->b.map->enccount && !p->finish; ++i )
2759 if ( p->fv->b.selected[i] ) {
2760 sc = NULL;
2761 if ( (gid=p->fv->b.map->map[i])!=-1 && (sc = p->fv->b.sf->glyphs[gid])!=NULL ) {
2762 if ( SCProblems(NULL,sc,p)) {
2763 if ( sc!=p->lastcharopened ) {
2764 if ( (CharView *) (sc->views)!=NULL )
2765 GDrawRaise(((CharView *) (sc->views))->gw);
2766 else
2767 CharViewCreate(sc,p->fv,-1);
2768 p->lastcharopened = sc;
2769 }
2770 ret = true;
2771 }
2772 }
2773 if ( !p->finish && p->selected_records[CID_Bitmaps] && !SCWorthOutputting(sc)) {
2774 for ( bdf=p->fv->b.sf->bitmaps; bdf!=NULL; bdf=bdf->next )
2775 if ( i<bdf->glyphcnt && bdf->glyphs[i]!=NULL ) {
2776 sc = SFMakeChar(p->fv->b.sf,p->fv->b.map,i);
2777 ExplainIt(p,sc,_("This blank outline glyph has an unexpected bitmap version"),0,0);
2778 ret = true;
2779 }
2780 }
2781 ret |= CIDCheck(p,i);
2782 }
2783 }
2784 if ( !ret )
2785 ff_post_error(_("No problems found"),_("No problems found"));
2786 if ( p->explainw!=NULL )
2787 GDrawDestroyWindow(p->explainw);
2788 }
2789
2790 static void DummyFindProblems(CharView *cv) {
2791 struct problems p{};
2792
2793 p.fv = (FontView *) (cv->b.fv);
2794 p.cv=cv;
2795 p.layer = CVLayer((CharViewBase *) cv);
2796 p.map = cv->b.fv->map;
2797 p.lastcharopened = cv->b.sc;
2798
2799 p.selected_records[CID_OpenPaths] = true;
2800 p.selected_records[CID_IntersectingPaths] = true;
2801 p.selected_records[CID_Direction] = true;
2802 p.selected_records[CID_FlippedRefs] = true;
2803 p.selected_records[CID_MissingExtrema] = true;
2804 p.selected_records[CID_TooManyPoints] = true;
2805 p.selected_records[CID_TooManyHints] = true;
2806 p.selected_records[CID_PointsTooFar] = true;
2807 p.selected_records[CID_NonIntegral] = true;
2808 p.selected_records[CID_MissingAnchor] = true;
2809 p.selected_records[CID_OverlappedHints] = true;
2810
2811 DoProbs(&p);
2812 }
2813
2814 static int SFGetRepresentativeWidth(SplineFont* sf, bool vertical) {
2815 // Retrieve ideographic space character for vertical fonts.
2816 SplineChar* sc = SFGetChar(sf, vertical ? 0x3000 : ' ', NULL);
2817 if (SCWorthOutputting(sc)) {
2818 return vertical ? sc->vwidth : sc->width;
2819 }
2820
2821 // Try to find some non-trivial glyph
2822 for (int i = 0; i < sf->glyphcnt; ++i)
2823 if (SCWorthOutputting(sf->glyphs[i])) {
2824 int width = vertical ? sf->glyphs[i]->vwidth : sf->glyphs[i]->width;
2825 if (width != 0) return width;
2826 }
2827
2828 return 0;
2829 }
2830
2831 static std::vector<ProblemRecord> pr_points = {
2832 {CID_NonIntegral, N_("Non-_integral coordinates"),
2833 N_("The coordinates of all points and control points in truetype "
2834 "must be integers (if they are not integers then FontForge will "
2835 "round them when it outputs them, potentially causing havoc). "
2836 "Even in PostScript fonts it is generally a good idea to use "
2837 "integral values."),
2838 false},
2839 {CID_XNear, N_("_X nearÂč"),
2840 N_("Allows you to check that vertical stems in several characters start "
2841 "at the same location."),
2842 false, 0.0},
2843 {CID_YNear, N_("_Y nearÂč"),
2844 N_("Allows you to check that horizontal stems in several characters "
2845 "start at the same location."),
2846 false, 0.0},
2847 {CID_YNearStd, N_("Y nearÂč _standard heights"),
2848 N_("Allows you to find points which are slightly off from the baseline, "
2849 "xheight, cap height, ascender, descender heights."),
2850 false},
2851 {CID_CpStd, N_("_Control points near horizontal/vertical"),
2852 N_("Allows you to find control points which are almost, but not quite "
2853 "horizontal or vertical from their base point (or at the italic "
2854 "angle)."),
2855 false},
2856 {CID_CpOdd, N_("Control points _beyond spline"),
2857 N_("Allows you to find control points which when projected onto the line "
2858 "segment between the two end points lie outside of those end points"),
2859 false},
2860 {CID_IrrelevantCP,
2861 N_("Check for _irrelevant control points with factor (%)"),
2862 N_("Control points are irrelevant if they are too close to the main point "
2863 "to make a significant difference in the shape of the curve. The "
2864 "minimum relevant distance is computed as a factor of distance between "
2865 "the main points."),
2866 false, 0.5},
2867 {CID_PointsTooClose, N_("Poin_ts too close"),
2868 N_("If two adjacent points on the same path are less than a few emunits "
2869 "apart they will cause problems for some of FontForge's commands. "
2870 "PostScript shouldn't care though."),
2871 false},
2872 {CID_PointsTooFar, N_("_Points too far"),
2873 N_("Most font formats cannot specify adjacent points (or control "
2874 "points) which are more than 32767 em-units apart in either the x or "
2875 "y direction"),
2876 false}};
2877
2878 static std::vector<ProblemRecord> pr_paths = {
2879 {CID_OpenPaths, N_("O_pen paths"),
2880 N_("All paths should be closed loops, there "
2881 "should be no exposed endpoints"),
2882 false},
2883 {CID_IntersectingPaths, N_("Intersecting paths"),
2884 N_("No paths with within a glyph should intersect"), false},
2885 {CID_LineStd, N_("_Edges near horizontal/vertical"),
2886 N_("Allows you to find lines which are almost, but not quite horizontal "
2887 "or vertical (or at the italic angle)."),
2888 false},
2889 {CID_Direction, N_("Check _outermost paths clockwise"),
2890 N_("FontForge internally uses paths drawn in a clockwise direction. This "
2891 "lets you check that they are. Before doing this test insure that no "
2892 "paths self-intersect."),
2893 false},
2894 {CID_MissingExtrema, N_("Check _missing extrema"),
2895 N_("PostScript and TrueType require that when a path reaches its maximum "
2896 "or minimum position there must be a point at that location."),
2897 false},
2898 {CID_TooManyPoints, N_("_More points than:"),
2899 N_("The PostScript Language Reference Manual (Appendix B) says that an "
2900 "interpreter need not support paths with more than 1500 points. I "
2901 "think this count includes control points. From PostScript's point of "
2902 "view, all the contours in a character make up one path. "
2903 "Modern interpreters tend to support paths with more points than this "
2904 "limit. (Note a truetype font after conversion to PS will "
2905 "contain twice as many control points)"),
2906 false, 1500}};
2907
2908 static std::vector<ProblemRecord> pr_refs = {
2909 {CID_FlippedRefs, N_("Check _flipped references"),
2910 N_("PostScript and TrueType require that paths be drawn in a clockwise "
2911 "direction. If you have a reference that has been flipped then the "
2912 "paths in that reference will probably be counter-clockwise. You "
2913 "should unlink it and do Element->Correct direction on it."),
2914 false},
2915 {CID_RefBadTransformTTF,
2916 N_("References with bad TrueType transformation matrices"),
2917 N_("TrueType requires that all scaling and rotational entries in a "
2918 "transformation matrix be between -2 and 2"),
2919 false},
2920 {CID_MixedContoursRefs, N_("Mixed contours and references"),
2921 N_("TrueType glyphs can either contain references or contours. Not "
2922 "both."),
2923 false},
2924 {CID_RefBadTransformPS,
2925 N_("References with bad PostScript transformation matrices"),
2926 N_("Type1 and 2 fonts only support translation of references. The first "
2927 "four entries of the transformation matrix should be [1 0 0 1]."),
2928 false},
2929 {CID_TooDeepRefs, N_("References neste_d deeper than:"),
2930 N_("The Type 2 Charstring Reference (Appendix B) says that subroutines "
2931 "may not be nested more than 10 deep. Each nesting level for "
2932 "references requires one subroutine level, and hints may require "
2933 "another level."),
2934 false, 9},
2935 {CID_PtMatchRefsOutOfDate, N_("References with out of date point matching"),
2936 N_("If a glyph has been edited so that it has a different number of "
2937 "points now, then any references which use point matching and "
2938 "depended on that glyph's point count will be incorrect."),
2939 false},
2940 {CID_MultUseMyMetrics, N_("Multiple references with use-my-metrics"),
2941 N_("There may be at most one reference with the use-my-metrics bit set"),
2942 false}};
2943
2944 static std::vector<ProblemRecord> pr_hints = {
2945 {CID_HintNoPt, N_("_Hints controlling no points"),
2946 N_("Ghostview (perhaps other interpreters) has a problem when a hint "
2947 "exists without any points that lie on it."),
2948 false},
2949 {CID_PtNearHint, N_("_Points nearÂč hint edges"),
2950 N_("Often if a point is slightly off from a hint it is because a stem is "
2951 "made up of several segments, and one of them has the wrong width."),
2952 false},
2953 {CID_HintWidthNear, N_("Hint _width nearÂč"),
2954 N_("Allows you to check that stems have consistent widths.."), false,
2955 50.0},
2956 /* GT: The _3 is used to mark an accelerator */
2957 {CID_Stem3, N_("Almost stem_3 hint"),
2958 N_("This checks if the character almost, but not exactly, conforms to "
2959 "the requirements for a stem3 hint. That is, either vertically or "
2960 "horizontally, there must be exactly three hints, and they must have "
2961 "the same width and they must be evenly spaced."),
2962 false},
2963 {CID_ShowExactStem3,
2964 N_("_Show exact *stem3"),
2965 N_("Shows when this character is exactly a stem3 hint"),
2966 false,
2967 {},
2968 .parent_cid = CID_Stem3},
2969 {CID_TooManyHints, N_("_More hints than:"),
2970 N_("The Type 2 Charstring Reference (Appendix B) says that there may be "
2971 "at most 96 horizontal and vertical stem hints in a character."),
2972 false, 96},
2973 {CID_OverlappedHints, N_("_Overlapped hints"),
2974 N_("Either a glyph should have no overlapping hints, or a glyph with "
2975 "hint masks should have no overlapping hints within a hint mask."),
2976 false}};
2977
2978 static std::vector<ProblemRecord> pr_att = {
2979 {CID_MissingGlyph, N_("Check for missing _glyph names"),
2980 N_("Check whether a substitution, kerning class, etc. uses a glyph name "
2981 "which does not match any glyph in the font"),
2982 false},
2983 {CID_MissingScriptInFeature, N_("Check for missing _scripts in features"),
2984 N_("In every lookup that uses a glyph, check that at "
2985 "least one feature is active for the glyph's script."),
2986 false},
2987 {CID_BadSubs, N_("Check substitutions for empty chars"),
2988 N_("Check for characters which contain 'GSUB' entries which refer to "
2989 "empty characters"),
2990 false},
2991 {CID_MissingAnchor, N_("Check for incomplete mark to base subtables"),
2992 N_("The OpenType documentation suggests in a rather confusing way "
2993 "that if a base glyph (or base mark) contains an anchor point "
2994 "for one class in a lookup subtable, then it should contain "
2995 "anchors for all classes in the subtable"),
2996 false}};
2997
2998 static std::vector<ProblemRecord> pr_cid = {
2999 {CID_CIDMultiple, N_("Check for CIDs defined _twice"),
3000 N_("Check whether a CID is defined in more than one sub-font"), false},
3001 {CID_CIDBlank, N_("Check for _undefined CIDs"),
3002 N_("Check whether a CID is undefined in all sub-fonts"), false}};
3003
3004 static std::vector<ProblemRecord> pr_bb = {
3005 {CID_BBYMax, N_("Glyph bounding box above"),
3006 N_("Are there any glyph's whose bounding boxes extend above this number?"),
3007 false, 0},
3008 {CID_BBYMin, N_("Glyph bounding box below"),
3009 N_("Are there any glyph's whose bounding boxes extend below this number?"),
3010 false, 0},
3011 {CID_BBXMax, N_("Glyph bounding box right of"),
3012 N_("Are there any glyphs whose bounding boxes extend to the right of this "
3013 "number?"),
3014 false, 0},
3015 {CID_BBXMin, N_("Glyph bounding box left of"),
3016 N_("Are there any glyph's whose bounding boxes extend to the left of this "
3017 "number?"),
3018 false, 0},
3019 {CID_AdvanceWidth, N_("Check advance:"),
3020 N_("Check for characters whose advance width is not the displayed value."),
3021 false, 0},
3022 {CID_VAdvanceWidth, N_("Check vertical advance:"),
3023 N_("Check for characters whose vertical advance width is not the "
3024 "displayed value."),
3025 false, 0}};
3026
3027 static std::vector<ProblemRecord> pr_random = {
3028 {CID_Bitmaps, N_("Check missing _bitmaps"),
3029 N_("Are there any outline characters which don't have a bitmap version in "
3030 "one of the bitmap fonts? Conversely are there any bitmap characters "
3031 "without a corresponding outline character?"),
3032 false},
3033 {CID_BitmapWidths, N_("Bitmap/outline _advance mismatch"),
3034 N_("Are there any bitmap glyphs whose advance width is not is expected "
3035 "from scaling and rounding the outline's advance width?"),
3036 false},
3037 {CID_MultUni, N_("Check multiple Unicode"),
3038 N_("Check for multiple characters with the same Unicode code point"),
3039 false},
3040 {CID_MultName, N_("Check multiple names"),
3041 N_("Check for multiple characters with the same name"), false},
3042 {CID_UniNameMisMatch, N_("Check Unicode/name mismatch"),
3043 N_("Check for characters whose name maps to a unicode code point which "
3044 "does not map the character's assigned code point."),
3045 false}};
3046
3047 static std::vector<ProblemTab> pr_tabs = {
3048 {N_("Points"), pr_points}, {N_("Paths"), pr_paths},
3049 {N_("References"), pr_refs}, {N_("Hints"), pr_hints},
3050 {N_("ATT"), pr_att}, {N_("CID"), pr_cid},
3051 {N_("Bounding Box"), pr_bb}, {N_("Random"), pr_random}};
3052
3053 static void adjust_problem_records(FontView* fv,
3054 std::vector<ProblemTab>& problem_tabs) {
3055 static SplineFont* lastsf = NULL;
3056 static bool loc_initialized = false;
3057 SplineFont* sf = fv->b.sf;
3058
3059 if (lastsf != sf) {
3060 assert(problem_tabs[6].records[0].cid == CID_BBYMax);
3061 problem_tabs[6].records[0].value = sf->ascent;
3062
3063 assert(problem_tabs[6].records[1].cid == CID_BBYMin);
3064 problem_tabs[6].records[1].value = -sf->descent;
3065
3066 assert(problem_tabs[6].records[2].cid == CID_BBXMax);
3067 problem_tabs[6].records[2].value = sf->ascent + sf->descent;
3068
3069 assert(problem_tabs[6].records[4].cid == CID_AdvanceWidth);
3070 problem_tabs[6].records[4].value = SFGetRepresentativeWidth(sf, false);
3071
3072 assert(problem_tabs[6].records[5].cid == CID_VAdvanceWidth);
3073 problem_tabs[6].records[5].value = SFGetRepresentativeWidth(sf, true);
3074
3075 lastsf = sf;
3076 }
3077
3078 assert(problem_tabs[0].records[4].cid == CID_CpStd);
3079 problem_tabs[0].records[4].label =
3080 (sf->italicangle == 0
3081 ? _("_Control points near horizontal/vertical")
3082 : _("Control points near horizontal/vertical/italic"));
3083
3084 assert(problem_tabs[1].records[2].cid == CID_LineStd);
3085 problem_tabs[1].records[2].label =
3086 (sf->italicangle == 0 ? _("_Edges near horizontal/vertical")
3087 : _("Edges near horizontal/vertical/italic"));
3088
3089 assert(problem_tabs[5].records[0].cid == CID_CIDMultiple);
3090 problem_tabs[5].records[0].disabled = (fv->b.cidmaster == NULL);
3091
3092 assert(problem_tabs[5].records[1].cid == CID_CIDBlank);
3093 problem_tabs[5].records[1].disabled = (fv->b.cidmaster == NULL);
3094
3095 assert(problem_tabs[6].records[5].cid == CID_VAdvanceWidth);
3096 problem_tabs[6].records[5].disabled = (!sf->hasvmetrics);
3097 }
3098
3099 static void apply_dialog_results(const std::vector<ProblemTab>& problem_tabs,
3100 struct problems& p) {
3101 near = p.near;
3102
3103 for (const ProblemTab& tab : problem_tabs) {
3104 for (const ProblemRecord& rec : tab.records) {
3105 p.selected_records[rec.cid] = rec.active;
3106 if (!std::holds_alternative<std::monostate>(rec.value))
3107 p.record_values[rec.cid] = rec.value;
3108 }
3109 }
3110 }
3111
3112 void FindProblems(FontView *fv,CharView *cv, SplineChar *sc) {
3113 struct problems p{};
3114 bool do_apply = false;
3115
3116 if ( fv==NULL ) fv = (FontView *) (cv->b.fv);
3117 p.fv = fv; p.cv=cv; p.msc = sc;
3118 p.near = near;
3119 if ( cv!=NULL )
3120 p.lastcharopened = cv->b.sc;
3121 if ( fv!=NULL ) {
3122 p.map = fv->b.map;
3123 p.layer = fv->b.active_layer;
3124 } else if ( cv!=NULL ) {
3125 p.map = cv->b.fv->map;
3126 p.layer = CVLayer((CharViewBase *) cv);
3127 } else {
3128 p.map = sc->parent->fv->map;
3129 p.layer = sc->parent->fv->active_layer;
3130 }
3131
3132 adjust_problem_records(fv, pr_tabs);
3133
3134 GWindow parent = (cv != NULL) ? cv->gw : fv->gw;
3135 do_apply = find_problems_dialog(parent, pr_tabs, p.near);
3136
3137 if (do_apply) {
3138 apply_dialog_results(pr_tabs, p);
3139 DoProbs(&p);
3140 }
3141 }
3142
3143 /* ************************************************************************** */
3144 /* ***************************** Validation code **************************** */
3145 /* ************************************************************************** */
3146
3147 struct val_data {
3148 GWindow gw;
3149 GWindow v;
3150 GGadget *vsb;
3151 int lcnt;
3152 int loff_top;
3153 int vlcnt;
3154 SplineFont *sf;
3155 int cidmax;
3156 enum validation_state mask;
3157 int need_to_check_with_user_on_mask;
3158 int needs_blue;
3159 GTimer *recheck;
3160 int laststart;
3161 int finished_first_pass;
3162 int as,fh;
3163 GFont *font;
3164 SplineChar *sc; /* used by popup menu */
3165 int lastgid;
3166 CharView *lastcv;
3167 int layer;
3168 };
3169
3170 static const char *vserrornames[] = {
3171 N_("Open Contour"),
3172 N_("Self Intersecting"),
3173 N_("Wrong Direction"),
3174 N_("Flipped References"),
3175 N_("Missing Points at Extrema"),
3176 N_("Unknown glyph referenced in GSUB/GPOS/MATH"),
3177 N_("Too Many Points"),
3178 N_("Too Many Hints"),
3179 N_("Bad Glyph Name"),
3180 NULL, /* Maxp too many points */
3181 NULL, /* Maxp too many paths */
3182 NULL, /* Maxp too many component points */
3183 NULL, /* Maxp too many component paths */
3184 NULL, /* Maxp instructions too long */
3185 NULL, /* Maxp too many references */
3186 NULL, /* Maxp references too deep */
3187 NULL, /* prep or fpgm too long */
3188 N_("Distance between adjacent points is too big"),
3189 N_("Non-integral coordinates"),
3190 N_("Contains anchor points for some, but not all, classes in a subtable"),
3191 N_("There is another glyph in the font with this name"),
3192 N_("There is another glyph in the font with this unicode code point"),
3193 N_("Glyph contains overlapped hints (in the same hintmask)")
3194 };
3195
3196 static const char *privateerrornames[] = {
3197 N_("Odd number of elements in BlueValues/OtherBlues array."),
3198 N_("Elements in BlueValues/OtherBlues array are disordered."),
3199 N_("Too many elements in BlueValues/OtherBlues array."),
3200 N_("Elements in BlueValues/OtherBlues array are too close (Change BlueFuzz)."),
3201 N_("Elements in BlueValues/OtherBlues array are not integers."),
3202 N_("Alignment zone height in BlueValues/OtherBlues array is too big for BlueScale."),
3203 NULL,
3204 NULL,
3205 N_("Odd number of elements in FamilyBlues/FamilyOtherBlues array."),
3206 N_("Elements in FamilyBlues/FamilyOtherBlues array are disordered."),
3207 N_("Too many elements in FamilyBlues/FamilyOtherBlues array."),
3208 N_("Elements in FamilyBlues/FamilyOtherBlues array are too close (Change BlueFuzz)."),
3209 N_("Elements in FamilyBlues/FamilyOtherBlues array are not integers."),
3210 N_("Alignment zone height in FamilyBlues/FamilyOtherBlues array is too big for BlueScale."),
3211 NULL,
3212 NULL,
3213 N_("Missing BlueValues entry."),
3214 N_("Bad BlueFuzz entry."),
3215 N_("Bad BlueScale entry."),
3216 N_("Bad StdHW entry."),
3217 N_("Bad StdVW entry."),
3218 N_("Bad StemSnapH entry."),
3219 N_("Bad StemSnapV entry."),
3220 N_("StemSnapH does not contain StdHW value."),
3221 N_("StemSnapV does not contain StdVW value."),
3222 N_("Bad BlueShift entry."),
3223 NULL
3224 };
3225
3226 char *VSErrorsFromMask(int mask, int private_mask) {
3227 int bit, m;
3228 int len;
3229 char *ret;
3230
3231 len = 0;
3232 for ( m=0, bit=(vs_known<<1) ; bit<=vs_last; ++m, bit<<=1 )
3233 if ( (mask&bit) && vserrornames[m]!=NULL )
3234 len += strlen( _(vserrornames[m]))+2;
3235 if ( private_mask != 0 )
3236 len += strlen( _("Bad Private Dictionary")) +2;
3237 ret = (char *) malloc(len+1);
3238 len = 0;
3239 for ( m=0, bit=(vs_known<<1) ; bit<=vs_last; ++m, bit<<=1 )
3240 if ( (mask&bit) && vserrornames[m]!=NULL ) {
3241 ret[len++] =' ';
3242 strcpy(ret+len,_(vserrornames[m]));
3243 len += strlen( ret+len );
3244 ret[len++] ='\n';
3245 }
3246 if ( private_mask != 0 ) {
3247 ret[len++] =' ';
3248 strcpy(ret+len,_("Bad Private Dictionary"));
3249 len += strlen( ret+len );
3250 ret[len++] ='\n';
3251 }
3252 ret[len] = '\0';
3253 return( ret );
3254 }
3255
3256 static int VSModMask(SplineChar *sc, struct val_data *vw) {
3257 int vs = 0;
3258 if ( sc!=NULL ) {
3259 vs = sc->layers[vw->layer].validation_state;
3260 if ( sc->unlink_rm_ovrlp_save_undo )
3261 vs &= ~vs_selfintersects;
3262 /* if doing a truetype eval, then I'm told it's ok for references */
3263 /* to overlap. And if refs can overlap, then we can't figure out */
3264 /* direction properly */ /* I should really check that all the */
3265 /* refs have legal ttf transform matrices */
3266 if ( vw->mask==vs_maskttf &&
3267 sc->layers[vw->layer].splines==NULL &&
3268 sc->layers[vw->layer].refs!=NULL )
3269 vs &= ~(vs_selfintersects|vs_wrongdirection);
3270 }
3271 return( vs );
3272 }
3273
3274 static int VW_FindLine(struct val_data *vw,int line, int *skips) {
3275 int gid,k, cidmax = vw->cidmax;
3276 SplineFont *sf = vw->sf;
3277 SplineFont *sub;
3278 SplineChar *sc;
3279 int sofar, tot;
3280 int bit;
3281 int vs;
3282
3283 sofar = 0;
3284 for ( gid=0; gid<cidmax ; ++gid ) {
3285 if ( sf->subfontcnt==0 )
3286 sc = sf->glyphs[gid];
3287 else {
3288 for ( k=0; k<sf->subfontcnt; ++k ) {
3289 sub = sf->subfonts[k];
3290 if ( gid<sub->glyphcnt && (sc = sub->glyphs[gid])!=NULL )
3291 break;
3292 }
3293 }
3294 /* Ignore it if it has not been validated */
3295 /* Ignore it if it is good */
3296 vs = VSModMask(sc,vw);
3297 if ((vs&vs_known) && (vs&vw->mask)!=0 ) {
3298 tot = 1;
3299 if ( sc->vs_open )
3300 for ( bit=(vs_known<<1) ; bit<=vs_last; bit<<=1 )
3301 if ( (bit&vw->mask) && (vs&bit) )
3302 ++tot;
3303 if ( sofar+tot>line ) {
3304 *skips = line-sofar;
3305 return( gid );
3306 }
3307 sofar += tot;
3308 }
3309 }
3310
3311 vs = ValidatePrivate(sf);
3312 if ( !vw->needs_blue )
3313 vs &= ~pds_missingblue;
3314 if ( vs!=0 ) {
3315 tot = 1;
3316 for ( bit=1 ; bit!=0; bit<<=1 )
3317 if ( vs&bit )
3318 ++tot;
3319 if ( sofar+tot>line ) {
3320 *skips = line-sofar;
3321 return( -2 );
3322 }
3323 }
3324
3325 *skips = 0;
3326 return( -1 );
3327 }
3328
3329 static int VW_FindSC(struct val_data *vw,SplineChar *sought) {
3330 int gid,k, cidmax = vw->cidmax;
3331 SplineFont *sf = vw->sf;
3332 SplineFont *sub;
3333 SplineChar *sc;
3334 int sofar;
3335 int bit, vs;
3336
3337 sofar = 0;
3338 for ( gid=0; gid<cidmax ; ++gid ) {
3339 if ( sf->subfontcnt==0 )
3340 sc = sf->glyphs[gid];
3341 else {
3342 for ( k=0; k<sf->subfontcnt; ++k ) {
3343 sub = sf->subfonts[k];
3344 if ( gid<sub->glyphcnt && (sc = sub->glyphs[gid])!=NULL )
3345 break;
3346 }
3347 }
3348 /* Ignore it if it has not been validated */
3349 /* Ignore it if it is good */
3350 vs = VSModMask(sc,vw);
3351 if ((vs&vs_known) && (vs&vw->mask)!=0 ) {
3352 if ( sc==sought )
3353 return( sofar );
3354 ++sofar;
3355 if ( sc->vs_open )
3356 for ( bit=(vs_known<<1) ; bit<=vs_last; bit<<=1 )
3357 if ( (bit&vw->mask) && (vs&bit) )
3358 ++sofar;
3359 } else if ( sc==sought )
3360 return( -1 );
3361 }
3362 return( -1 );
3363 }
3364
3365 static int VW_VScroll(GGadget *g, GEvent *e) {
3366 struct val_data *vw = (struct val_data *) GDrawGetUserData(GGadgetGetWindow(g));
3367 int newpos = vw->loff_top;
3368
3369 switch( e->u.control.u.sb.type ) {
3370 case et_sb_top:
3371 newpos = 0;
3372 break;
3373 case et_sb_uppage:
3374 newpos -= 9*vw->vlcnt/10;
3375 break;
3376 case et_sb_up:
3377 newpos -= vw->vlcnt/15;
3378 break;
3379 case et_sb_down:
3380 newpos += vw->vlcnt/15;
3381 break;
3382 case et_sb_downpage:
3383 newpos += 9*vw->vlcnt/10;
3384 break;
3385 case et_sb_bottom:
3386 newpos = 0;
3387 break;
3388 case et_sb_thumb:
3389 case et_sb_thumbrelease:
3390 newpos = e->u.control.u.sb.pos;
3391 break;
3392 case et_sb_halfup:
3393 newpos -= vw->vlcnt/30;
3394 break;
3395 case et_sb_halfdown:
3396 newpos += vw->vlcnt/30;
3397 break;
3398 }
3399 if ( newpos + vw->vlcnt > vw->lcnt )
3400 newpos = vw->lcnt-vw->vlcnt;
3401 if ( newpos<0 )
3402 newpos = 0;
3403 if ( vw->loff_top!=newpos ) {
3404 vw->loff_top = newpos;
3405 GScrollBarSetPos(vw->vsb,newpos);
3406 GDrawRequestExpose(vw->v,NULL,false);
3407 }
3408 return( true );
3409 }
3410
3411 static void VW_SetSb(struct val_data *vw) {
3412 if ( vw->loff_top + vw->vlcnt > vw->lcnt )
3413 vw->loff_top = vw->lcnt-vw->vlcnt;
3414 if ( vw->loff_top<0 )
3415 vw->loff_top = 0;
3416 GScrollBarSetBounds(vw->vsb,0,vw->lcnt,vw->vlcnt);
3417 GScrollBarSetPos(vw->vsb,vw->loff_top);
3418 }
3419
3420 static void VW_Remetric(struct val_data *vw) {
3421 int gid,k, cidmax = vw->cidmax;
3422 SplineFont *sub, *sf = vw->sf;
3423 SplineChar *sc;
3424 int sofar, tot;
3425 int bit, vs;
3426
3427 sofar = 0;
3428 for ( gid=0; gid<cidmax ; ++gid ) {
3429 if ( sf->subfontcnt==0 )
3430 sc = sf->glyphs[gid];
3431 else {
3432 for ( k=0; k<sf->subfontcnt; ++k ) {
3433 sub = sf->subfonts[k];
3434 if ( gid<sub->glyphcnt && (sc = sub->glyphs[gid])!=NULL )
3435 break;
3436 }
3437 }
3438 /* Ignore it if it has not been validated */
3439 /* Ignore it if it is good */
3440 vs = VSModMask(sc,vw);
3441 if ((vs&vs_known) && (vs&vw->mask)!=0 ) {
3442 tot = 1;
3443 if ( sc->vs_open )
3444 for ( bit=(vs_known<<1) ; bit<=vs_last; bit<<=1 )
3445 if ( (bit&vw->mask) && (vs&bit) )
3446 ++tot;
3447 sofar += tot;
3448 }
3449 }
3450 vs = ValidatePrivate(sf);
3451 if ( !vw->needs_blue )
3452 vs &= ~pds_missingblue;
3453 if ( vs!=0 ) {
3454 tot = 1;
3455 for ( bit=1 ; bit!=0; bit<<=1 )
3456 if ( vs&bit )
3457 ++tot;
3458 sofar += tot;
3459 }
3460 if ( vw->lcnt!=sofar ) {
3461 vw->lcnt = sofar;
3462 VW_SetSb(vw);
3463 }
3464 GDrawRequestExpose(vw->v,NULL,false);
3465 }
3466
3467 static void VWMenuConnect(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3468 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3469 SplineChar *sc = vw->sc;
3470 int vs = sc->layers[vw->layer].validation_state;
3471 int changed = false;
3472 SplineSet *ss;
3473
3474 for ( ss=sc->layers[vw->layer].splines; ss!=NULL; ss=ss->next ) {
3475 if ( ss->first->prev==NULL && ss->first->next!=NULL ) {
3476 if ( !changed ) {
3477 SCPreserveLayer(sc,vw->layer,false);
3478 changed = true;
3479 }
3480 SplineMake(ss->last,ss->first,sc->layers[vw->layer].order2);
3481 ss->last = ss->first;
3482 }
3483 }
3484 if ( changed ) {
3485 SCCharChangedUpdate(sc,vw->layer);
3486 SCValidate(vw->sc,vw->layer,true);
3487 if ( vs != vw->sc->layers[vw->layer].validation_state )
3488 VW_Remetric(vw);
3489 }
3490 }
3491
3492 static void VWMenuInlineRefs(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3493 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3494 SplineChar *sc = vw->sc;
3495 int vs = sc->layers[vw->layer].validation_state;
3496 int changed = false;
3497 RefChar *ref, *refnext;
3498
3499 for ( ref= sc->layers[vw->layer].refs; ref!=NULL; ref=refnext ) {
3500 refnext = ref->next;
3501 if ( !changed )
3502 SCPreserveLayer(sc,vw->layer,false);
3503 changed = true;
3504 SCRefToSplines(sc,ref,vw->layer);
3505 }
3506 if ( changed ) {
3507 SCCharChangedUpdate(sc,vw->layer);
3508
3509 SCValidate(vw->sc,vw->layer,true);
3510 if ( vs != vw->sc->layers[vw->layer].validation_state )
3511 VW_Remetric(vw);
3512 }
3513 }
3514
3515 static void VWMenuOverlap(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3516 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3517 SplineChar *sc = vw->sc;
3518 int vs = sc->layers[vw->layer].validation_state;
3519
3520 if ( !SCRoundToCluster(sc,ly_all,false,.03,.12))
3521 SCPreserveLayer(sc,vw->layer,false);
3522 sc->layers[vw->layer].splines = SplineSetRemoveOverlap(sc,sc->layers[vw->layer].splines,over_remove);
3523 SCCharChangedUpdate(sc,vw->layer);
3524
3525 SCValidate(vw->sc,vw->layer,true);
3526 if ( vs != vw->sc->layers[vw->layer].validation_state )
3527 VW_Remetric(vw);
3528 }
3529
3530 static void VWMenuMark(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3531 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3532 SplineChar *sc = vw->sc;
3533
3534 sc->unlink_rm_ovrlp_save_undo = true;
3535
3536 VW_Remetric(vw);
3537 }
3538
3539 static void VWMenuInlineFlippedRefs(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3540 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3541 SplineChar *sc = vw->sc;
3542 int vs = sc->layers[vw->layer].validation_state;
3543 int changed = false;
3544 RefChar *ref, *refnext;
3545
3546 for ( ref= sc->layers[vw->layer].refs; ref!=NULL; ref=refnext ) {
3547 refnext = ref->next;
3548 if ( ref->transform[0]*ref->transform[3]<0 ||
3549 (ref->transform[0]==0 && ref->transform[1]*ref->transform[2]>0)) {
3550 if ( !changed )
3551 SCPreserveLayer(sc,vw->layer,false);
3552 changed = true;
3553 SCRefToSplines(sc,ref,vw->layer);
3554 }
3555 }
3556 if ( changed ) {
3557 SCCharChangedUpdate(sc,vw->layer);
3558
3559 SCValidate(vw->sc,vw->layer,true);
3560 if ( vs != vw->sc->layers[vw->layer].validation_state )
3561 VW_Remetric(vw);
3562 }
3563 }
3564
3565 static void VWMenuCorrectDir(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3566 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3567 SplineChar *sc = vw->sc;
3568 int vs = sc->layers[vw->layer].validation_state;
3569 int changed = false;
3570
3571 SCPreserveLayer(sc,vw->layer,false);
3572 sc->layers[vw->layer].splines = SplineSetsCorrect(sc->layers[vw->layer].splines,&changed);
3573 SCCharChangedUpdate(sc,vw->layer);
3574
3575 SCValidate(vw->sc,vw->layer,true);
3576 if ( vs != vw->sc->layers[vw->layer].validation_state )
3577 VW_Remetric(vw);
3578 }
3579
3580 static void VWMenuGoodExtrema(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3581 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3582 SplineFont *sf = vw->sf;
3583 int emsize = sf->ascent+sf->descent;
3584 SplineChar *sc = vw->sc;
3585 int vs = sc->layers[vw->layer].validation_state;
3586
3587 SCPreserveLayer(sc,vw->layer,false);
3588 SplineCharAddExtrema(sc,sc->layers[vw->layer].splines,ae_only_good,emsize);
3589 SCCharChangedUpdate(sc,vw->layer);
3590
3591 SCValidate(vw->sc,vw->layer,true);
3592 if ( vs != vw->sc->layers[vw->layer].validation_state )
3593 VW_Remetric(vw);
3594 }
3595
3596 static void VWMenuAllExtrema(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3597 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3598 SplineFont *sf = vw->sf;
3599 int emsize = sf->ascent+sf->descent;
3600 SplineChar *sc = vw->sc;
3601 int vs = sc->layers[vw->layer].validation_state;
3602
3603 SCPreserveLayer(sc,vw->layer,false);
3604 SplineCharAddExtrema(sc,sc->layers[vw->layer].splines,ae_all,emsize);
3605 SCCharChangedUpdate(sc,vw->layer);
3606
3607 SCValidate(vw->sc,vw->layer,true);
3608 if ( vs != vw->sc->layers[vw->layer].validation_state )
3609 VW_Remetric(vw);
3610 }
3611
3612 static void VWMenuSimplify(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3613 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3614 SplineChar *sc = vw->sc;
3615 int vs = sc->layers[vw->layer].validation_state;
3616 static struct simplifyinfo smpl = { sf_normal, 0.75, 0.05, 0, -1, 0, 0 };
3617
3618 SCPreserveLayer(sc,vw->layer,false);
3619 sc->layers[vw->layer].splines = SplineCharSimplify(sc,sc->layers[vw->layer].splines,&smpl);
3620 SCCharChangedUpdate(sc,vw->layer);
3621
3622 SCValidate(vw->sc,vw->layer,true);
3623 if ( vs != vw->sc->layers[vw->layer].validation_state )
3624 VW_Remetric(vw);
3625 }
3626
3627 static void VWMenuRevalidateAll(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3628 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3629 SplineChar *sc;
3630 int k, gid;
3631 SplineFont *sf;
3632
3633 k=0;
3634 do {
3635 sf = k<vw->sf->subfontcnt ? vw->sf->subfonts[k] : vw->sf;
3636 for ( gid=0; gid<sf->glyphcnt; ++gid ) if ( (sc=sf->glyphs[gid])!=NULL ) {
3637 sc->layers[vw->layer].validation_state = 0;
3638 sc->layers[vw->layer].old_vs = 2;
3639 }
3640 ++k;
3641 } while ( k<vw->sf->subfontcnt );
3642 VW_Remetric(vw);
3643 }
3644
3645 static void VWMenuRevalidate(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3646 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3647 int vs = vw->sc->layers[vw->layer].validation_state;
3648 SCValidate(vw->sc,vw->layer,true);
3649 if ( vs != vw->sc->layers[vw->layer].validation_state )
3650 VW_Remetric(vw);
3651 }
3652
3653 static void VWReuseCV(struct val_data *vw, SplineChar *sc) {
3654 int k;
3655 SplineChar *sctest;
3656 SplineFont *sf = vw->sf;
3657 CharView *cv;
3658
3659 /* See if the last cv we used is still open. This is a little complex as */
3660 /* we must make sure that the splinechar is still in the font, and then */
3661 /* that the cv is still attached to it */
3662 cv = NULL;
3663 if ( vw->lastgid!=-1 && vw->lastcv!=NULL ) {
3664 sctest = NULL;
3665 if ( sf->subfontcnt==0 ) {
3666 if ( vw->lastgid<sf->glyphcnt )
3667 sctest = sf->glyphs[vw->lastgid];
3668 } else {
3669 for ( k = 0; k<sf->subfontcnt; ++k )
3670 if ( vw->lastgid<sf->subfonts[k]->glyphcnt )
3671 if ( (sctest = sf->subfonts[k]->glyphs[vw->lastgid])!=NULL )
3672 break;
3673 }
3674 if ( sctest!=NULL )
3675 for ( cv=(CharView *) (sctest->views); cv!=NULL && cv!=vw->lastcv; cv=(CharView *) (cv->b.next) );
3676 }
3677 if ( cv==NULL )
3678 cv = CharViewCreate(sc,(FontView *) (vw->sf->fv),vw->sf->fv->map->backmap[sc->orig_pos]);
3679 else {
3680 CVChangeSC(cv,sc);
3681 GDrawSetVisible(cv->gw,true);
3682 GDrawRaise(cv->gw);
3683 }
3684 if ( CVLayer((CharViewBase *) cv)!=vw->layer )
3685 CVSetLayer(cv,vw->layer);
3686 vw->lastgid = sc->orig_pos;
3687 vw->lastcv = cv;
3688
3689 if ( sc->layers[vw->layer].validation_state & vs_maskfindproblems & vw->mask )
3690 DummyFindProblems(cv);
3691 }
3692
3693 static void VWMenuOpenGlyph(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3694 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3695 VWReuseCV(vw,vw->sc);
3696 }
3697
3698 static void VWMenuGotoGlyph(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3699 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3700 FontView *fv = (FontView *) (vw->sf->fv);
3701 int enc = GotoChar(vw->sf,fv->b.map,NULL);
3702 int gid, line;
3703 SplineChar *sc;
3704
3705 if ( enc==-1 )
3706 return;
3707 gid = fv->b.map->map[enc];
3708 if ( gid==-1 || (sc=vw->sf->glyphs[gid])==NULL ) {
3709 ff_post_error(_("Glyph not in font"), _("Glyph not in font"));
3710 return;
3711 } else if ( (SCValidate(sc,vw->layer,true)&vw->mask)==0 ) {
3712 ff_post_notice(_("Glyph Valid"), _("No problems detected in %s"),
3713 sc->name );
3714 return;
3715 }
3716
3717 line = VW_FindSC(vw,sc);
3718 if ( line==-1 )
3719 IError("Glyph doesn't exist?");
3720
3721 if ( line + vw->vlcnt > vw->lcnt )
3722 line = vw->lcnt-vw->vlcnt;
3723 if ( line<0 )
3724 line = 0;
3725 if ( vw->loff_top!=line ) {
3726 vw->loff_top = line;
3727 GScrollBarSetPos(vw->vsb,line);
3728 GDrawRequestExpose(vw->v,NULL,false);
3729 }
3730 }
3731
3732
3733 #define MID_SelectOpen 102
3734 #define MID_SelectRO 103
3735 #define MID_SelectDir 104
3736 #define MID_SelectExtr 105
3737 #define MID_SelectErrors 106
3738
3739 static void VWMenuSelect(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3740 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3741 FontView *fv = (FontView *) (vw->sf->fv);
3742 int mask = mi->mid == MID_SelectErrors ? vw->mask :
3743 mi->mid == MID_SelectOpen ? vs_opencontour :
3744 mi->mid == MID_SelectRO ? vs_selfintersects :
3745 mi->mid == MID_SelectDir ? vs_wrongdirection :
3746 mi->mid == MID_SelectExtr ? vs_missingextrema : 0;
3747 EncMap *map = fv->b.map;
3748 int i, gid;
3749 SplineChar *sc;
3750
3751 for ( i=0; i<map->enccount; ++i ) {
3752 fv->b.selected[i] = false;
3753 gid = map->map[i];
3754 if ( gid!=-1 && (sc=vw->sf->glyphs[gid])!=NULL &&
3755 (SCValidate(sc,vw->layer,true) & mask) )
3756 fv->b.selected[i] = true;
3757 }
3758 GDrawSetVisible(fv->gw,true);
3759 GDrawRaise(fv->gw);
3760 GDrawRequestExpose(fv->v,NULL,false);
3761 }
3762
3763 static GMenuItem vw_subselect[] = {
3764 { { (unichar_t *) N_("problselect|Errors"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, '\0', 0, NULL, NULL, VWMenuSelect, MID_SelectErrors },
3765 { { (unichar_t *) N_("problselect|Open Contours"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, '\0', 0, NULL, NULL, VWMenuSelect, MID_SelectOpen },
3766 { { (unichar_t *) N_("problselect|Bad Direction"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, '\0', 0, NULL, NULL, VWMenuSelect, MID_SelectDir },
3767 { { (unichar_t *) N_("problselect|Self Intersections"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, '\0', 0, NULL, NULL, VWMenuSelect, MID_SelectRO },
3768 { { (unichar_t *) N_("problselect|Missing Extrema"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, '\0', 0, NULL, NULL, VWMenuSelect, MID_SelectExtr },
3769 GMENUITEM_EMPTY
3770 };
3771
3772 static void VWMenuManyConnect(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3773 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3774 SplineChar *sc;
3775 int k, gid;
3776 SplineFont *sf;
3777
3778 k=0;
3779 do {
3780 sf = k<vw->sf->subfontcnt ? vw->sf->subfonts[k] : vw->sf;
3781 for ( gid=0; gid<sf->glyphcnt; ++gid ) if ( (sc=sf->glyphs[gid])!=NULL && (sc->layers[vw->layer].validation_state&vs_opencontour) ) {
3782 int vs = sc->layers[vw->layer].validation_state;
3783 int changed = false;
3784 SplineSet *ss;
3785
3786 for ( ss=sc->layers[vw->layer].splines; ss!=NULL; ss=ss->next ) {
3787 if ( ss->first->prev==NULL && ss->first->next!=NULL ) {
3788 if ( !changed ) {
3789 SCPreserveLayer(sc,vw->layer,false);
3790 changed = true;
3791 }
3792 SplineMake(ss->last,ss->first,sc->layers[vw->layer].order2);
3793 ss->last = ss->first;
3794 }
3795 }
3796 if ( changed ) {
3797 SCCharChangedUpdate(sc,vw->layer);
3798 SCValidate(vw->sc,vw->layer,true);
3799 if ( vs != vw->sc->layers[vw->layer].validation_state )
3800 VW_Remetric(vw);
3801 }
3802 }
3803 ++k;
3804 } while ( k<vw->sf->subfontcnt );
3805 }
3806
3807 static void VWMenuManyOverlap(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3808 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3809 SplineChar *sc;
3810 int k, gid;
3811 SplineFont *sf;
3812
3813 k=0;
3814 do {
3815 sf = k<vw->sf->subfontcnt ? vw->sf->subfonts[k] : vw->sf;
3816 for ( gid=0; gid<sf->glyphcnt; ++gid ) if ( (sc=sf->glyphs[gid])!=NULL && (sc->layers[vw->layer].validation_state&vs_selfintersects) ) {
3817 int vs = sc->layers[vw->layer].validation_state;
3818
3819 /* If it's only got references, I could inline them, since the */
3820 /* intersection would occur between two refs. But that seems */
3821 /* to extreme to do to an unsuspecting user */
3822 if ( !SCRoundToCluster(sc,ly_all,false,.03,.12))
3823 SCPreserveLayer(sc,vw->layer,false);
3824 sc->layers[vw->layer].splines = SplineSetRemoveOverlap(sc,sc->layers[vw->layer].splines,over_remove);
3825 SCCharChangedUpdate(sc,vw->layer);
3826 SCValidate(vw->sc,vw->layer,true);
3827 if ( vs != vw->sc->layers[vw->layer].validation_state )
3828 VW_Remetric(vw);
3829 }
3830 ++k;
3831 } while ( k<vw->sf->subfontcnt );
3832 }
3833
3834 static void VWMenuManyMark(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3835 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3836 SplineChar *sc;
3837 int k, gid;
3838 SplineFont *sf;
3839
3840 k=0;
3841 do {
3842 sf = k<vw->sf->subfontcnt ? vw->sf->subfonts[k] : vw->sf;
3843 for ( gid=0; gid<sf->glyphcnt; ++gid ) if ( (sc=sf->glyphs[gid])!=NULL &&
3844 (sc->layers[vw->layer].validation_state&vs_selfintersects) &&
3845 sc->layers[vw->layer].refs!=NULL &&
3846 sc->layers[vw->layer].refs->next!=NULL &&
3847 sc->layers[vw->layer].splines==NULL ) {
3848 sc->unlink_rm_ovrlp_save_undo = true;
3849 VW_Remetric(vw);
3850 }
3851 ++k;
3852 } while ( k<vw->sf->subfontcnt );
3853 }
3854
3855 static void VWMenuManyCorrectDir(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3856 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3857 SplineChar *sc;
3858 int k, gid;
3859 SplineFont *sf;
3860 RefChar *ref, *refnext;
3861 int changed;
3862
3863 k=0;
3864 do {
3865 sf = k<vw->sf->subfontcnt ? vw->sf->subfonts[k] : vw->sf;
3866 for ( gid=0; gid<sf->glyphcnt; ++gid ) if ( (sc=sf->glyphs[gid])!=NULL && (sc->layers[vw->layer].validation_state&vs_wrongdirection) ) {
3867 int vs = sc->layers[vw->layer].validation_state;
3868
3869 SCPreserveLayer(sc,vw->layer,false);
3870 /* But a flipped reference is just wrong so I have no compunctions*/
3871 /* about inlining it and then correcting its direction */
3872
3873 for ( ref= sc->layers[vw->layer].refs; ref!=NULL; ref=refnext ) {
3874 refnext = ref->next;
3875 if ( ref->transform[0]*ref->transform[3]<0 ||
3876 (ref->transform[0]==0 && ref->transform[1]*ref->transform[2]>0)) {
3877 SCRefToSplines(sc,ref,vw->layer);
3878 }
3879 }
3880 sc->layers[vw->layer].splines = SplineSetsCorrect(sc->layers[vw->layer].splines,&changed);
3881 SCCharChangedUpdate(sc,vw->layer);
3882 SCValidate(vw->sc,vw->layer,true);
3883 if ( vs != vw->sc->layers[vw->layer].validation_state )
3884 VW_Remetric(vw);
3885 }
3886 ++k;
3887 } while ( k<vw->sf->subfontcnt );
3888 }
3889
3890 static void VWMenuManyGoodExtrema(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3891 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3892 SplineChar *sc;
3893 int k, gid;
3894 SplineFont *sf = vw->sf;
3895 int emsize = sf->ascent+sf->descent;
3896
3897 k=0;
3898 do {
3899 sf = k<vw->sf->subfontcnt ? vw->sf->subfonts[k] : vw->sf;
3900 for ( gid=0; gid<sf->glyphcnt; ++gid ) if ( (sc=sf->glyphs[gid])!=NULL && (sc->layers[vw->layer].validation_state&vs_missingextrema) ) {
3901 int vs = sc->layers[vw->layer].validation_state;
3902
3903 SCPreserveLayer(sc,vw->layer,false);
3904 SplineCharAddExtrema(sc,sc->layers[vw->layer].splines,ae_only_good,emsize);
3905 SCCharChangedUpdate(sc,vw->layer);
3906 SCValidate(vw->sc,vw->layer,true);
3907 if ( vs != vw->sc->layers[vw->layer].validation_state )
3908 VW_Remetric(vw);
3909 }
3910 ++k;
3911 } while ( k<vw->sf->subfontcnt );
3912 }
3913
3914 static void VWMenuManyAllExtrema(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3915 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3916 SplineChar *sc;
3917 int k, gid;
3918 SplineFont *sf = vw->sf;
3919 int emsize = sf->ascent+sf->descent;
3920
3921 k=0;
3922 do {
3923 sf = k<vw->sf->subfontcnt ? vw->sf->subfonts[k] : vw->sf;
3924 for ( gid=0; gid<sf->glyphcnt; ++gid ) if ( (sc=sf->glyphs[gid])!=NULL && (sc->layers[vw->layer].validation_state&vs_missingextrema) ) {
3925 int vs = sc->layers[vw->layer].validation_state;
3926
3927 SCPreserveLayer(sc,vw->layer,false);
3928 SplineCharAddExtrema(sc,sc->layers[vw->layer].splines,ae_all,emsize);
3929 SCCharChangedUpdate(sc,vw->layer);
3930 SCValidate(vw->sc,vw->layer,true);
3931 if ( vs != vw->sc->layers[vw->layer].validation_state )
3932 VW_Remetric(vw);
3933 }
3934 ++k;
3935 } while ( k<vw->sf->subfontcnt );
3936 }
3937
3938 static void VWMenuManySimplify(GWindow gw,struct gmenuitem *mi,GEvent *e) {
3939 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
3940 SplineChar *sc;
3941 int k, gid;
3942 SplineFont *sf;
3943 static struct simplifyinfo smpl = { sf_normal, 0.75, 0.05, 0, -1, 0, 0 };
3944
3945 k=0;
3946 do {
3947 sf = k<vw->sf->subfontcnt ? vw->sf->subfonts[k] : vw->sf;
3948 for ( gid=0; gid<sf->glyphcnt; ++gid ) if ( (sc=sf->glyphs[gid])!=NULL && (sc->layers[vw->layer].validation_state&vs_toomanypoints) ) {
3949 int vs = sc->layers[vw->layer].validation_state;
3950
3951 SCPreserveLayer(sc,vw->layer,false);
3952 sc->layers[vw->layer].splines = SplineCharSimplify(sc,sc->layers[vw->layer].splines,&smpl);
3953 SCCharChangedUpdate(sc,vw->layer);
3954 SCValidate(vw->sc,vw->layer,true);
3955 if ( vs != vw->sc->layers[vw->layer].validation_state )
3956 VW_Remetric(vw);
3957 }
3958 ++k;
3959 } while ( k<vw->sf->subfontcnt );
3960 }
3961
3962 static GMenuItem vw_subfixup[] = {
3963 { { (unichar_t *) N_("problfixup|Open Contours"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, '\0', 0, NULL, NULL, VWMenuManyConnect, 0 },
3964 { { (unichar_t *) N_("problfixup|Self Intersections"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 0 }, '\0', 0, NULL, NULL, VWMenuManyOverlap, 0 },
3965 { { (unichar_t *) N_("problfixup|Mark for Overlap fix before Save"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 0 }, '\0', 0, NULL, NULL, VWMenuManyMark, 0 },
3966 { { (unichar_t *) N_("problfixup|Bad Directions"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 0 }, '\0', 0, NULL, NULL, VWMenuManyCorrectDir, 0 },
3967 { { (unichar_t *) N_("problfixup|Missing Extrema (cautiously)"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 0 }, '\0', 0, NULL, NULL, VWMenuManyGoodExtrema, 0 },
3968 { { (unichar_t *) N_("problfixup|Missing Extrema"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 0 }, '\0', 0, NULL, NULL, VWMenuManyAllExtrema, 0 },
3969 { { (unichar_t *) N_("problfixup|Too Many Points"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 0 }, '\0', 0, NULL, NULL, VWMenuManySimplify, 0 },
3970 GMENUITEM_EMPTY
3971 };
3972
3973 static GMenuItem vw_popuplist[] = {
3974 { { (unichar_t *) N_("Close Open Contours"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, '\0', 0, NULL, NULL, VWMenuConnect, 0 },
3975 { { (unichar_t *) N_("Inline All References"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 0 }, '\0', 0, NULL, NULL, VWMenuInlineRefs, 0 },
3976 { { (unichar_t *) N_("Remove Overlap"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 0 }, '\0', 0, NULL, NULL, VWMenuOverlap, 0 },
3977 { { (unichar_t *) N_("Mark for Overlap fix before Save"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 0 }, '\0', 0, NULL, NULL, VWMenuMark, 0 },
3978 { { (unichar_t *) N_("Inline Flipped References"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 0 }, '\0', 0, NULL, NULL, VWMenuInlineFlippedRefs, 0 },
3979 { { (unichar_t *) N_("Correct Direction"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 0 }, '\0', 0, NULL, NULL, VWMenuCorrectDir, 0 },
3980 { { (unichar_t *) N_("Add Good Extrema"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 0 }, '\0',0, NULL, NULL, VWMenuGoodExtrema, 0 },
3981 { { (unichar_t *) N_("Add All Extrema"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 0 }, '\0', 0, NULL, NULL, VWMenuAllExtrema, 0 },
3982 { { (unichar_t *) N_("Simplify"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 0 }, '\0', 0, NULL, NULL, VWMenuSimplify, 0 },
3983 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 1, 0, 0, 0, '\0' }, '\0', 0, NULL, NULL, NULL, 0 }, /* line */
3984 { { (unichar_t *) N_("Revalidate All"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, '\0', 0, NULL, NULL, VWMenuRevalidateAll, 0 },
3985 { { (unichar_t *) N_("Revalidate"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, '\0', 0, NULL, NULL, VWMenuRevalidate, 0 },
3986 { { (unichar_t *) N_("Open Glyph"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, '\0', 0, NULL, NULL, VWMenuOpenGlyph, 0 },
3987 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 1, 0, 0, 0, '\0' }, '\0', 0, NULL, NULL, NULL, 0 }, /* line */
3988 { { (unichar_t *) N_("Scroll To Glyph"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, '\0', 0, NULL, NULL, VWMenuGotoGlyph, 0 },
3989 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 1, 0, 0, 0, '\0' }, '\0', 0, NULL, NULL, NULL, 0 }, /* line */
3990 { { (unichar_t *) N_("Select Glyphs With"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, '\0', 0, vw_subselect, NULL, NULL, 0 },
3991 { { (unichar_t *) N_("Try To Fix Glyphs With"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, '\0', 0, vw_subfixup, NULL, NULL, 0 },
3992 GMENUITEM_EMPTY
3993 };
3994
3995 static void VWMouse(struct val_data *vw, GEvent *e) {
3996 int skips;
3997 int gid = VW_FindLine(vw,vw->loff_top + e->u.mouse.y/vw->fh, &skips);
3998 SplineChar *sc;
3999 int k=0;
4000
4001 if ( gid==-2 && e->u.mouse.clicks==2 && e->type==et_mouseup ) {
4002 FontInfo(vw->sf,vw->layer,4,false); /* Bring up the Private Dict */
4003 return;
4004 }
4005 if ( gid<0 )
4006 return;
4007 if ( vw->sf->subfontcnt==0 ) {
4008 if ( (sc = vw->sf->glyphs[gid])==NULL )
4009 return;
4010 } else {
4011 sc = NULL;
4012 for ( k=0; k<vw->sf->subfontcnt; ++k ) {
4013 if ( gid<vw->sf->subfonts[k]->glyphcnt &&
4014 (sc=vw->sf->subfonts[k]->glyphs[gid])!=NULL )
4015 break;
4016 }
4017 if ( sc==NULL )
4018 return;
4019 }
4020
4021 if ( e->u.mouse.clicks==2 && e->type==et_mouseup ) {
4022 VWReuseCV(vw,sc);
4023 } else if ( e->type==et_mouseup && e->u.mouse.x<10+vw->as && skips==0 ) {
4024 sc->vs_open = !sc->vs_open;
4025 VW_Remetric(vw);
4026 } else if ( e->type==et_mousedown && e->u.mouse.button==3 ) {
4027 static int initted = false;
4028 if ( !initted ) {
4029 int i;
4030 initted = true;
4031
4032 for ( i=0; vw_popuplist[i].ti.text!=NULL || vw_popuplist[i].ti.line; ++i )
4033 if ( vw_popuplist[i].ti.text!=NULL )
4034 vw_popuplist[i].ti.text = (unichar_t *) _( (char *)vw_popuplist[i].ti.text);
4035
4036 for (i=0; vw_subfixup[i].ti.text!=NULL || vw_subfixup[i].ti.line; ++i )
4037 if ( vw_subfixup[i].ti.text!=NULL )
4038 vw_subfixup[i].ti.text = (unichar_t *) S_( (char *)vw_subfixup[i].ti.text);
4039
4040 for (i=0; vw_subselect[i].ti.text!=NULL || vw_subselect[i].ti.line; ++i )
4041 if ( vw_subselect[i].ti.text!=NULL )
4042 vw_subselect[i].ti.text = (unichar_t *) S_( (char *)vw_subselect[i].ti.text);
4043 }
4044 vw_popuplist[0].ti.disabled = (sc->layers[vw->layer].validation_state&vs_opencontour)?0:1;
4045 vw_popuplist[1].ti.disabled = (SCValidate(sc,vw->layer,true)&vs_selfintersects)?0:1;
4046 vw_popuplist[2].ti.disabled = (SCValidate(sc,vw->layer,true)&vs_selfintersects)?0:1;
4047 vw_popuplist[3].ti.disabled = (SCValidate(sc,vw->layer,true)&vs_selfintersects) &&
4048 sc->layers[vw->layer].refs!=NULL?0:1;
4049 vw_popuplist[4].ti.disabled = (sc->layers[vw->layer].validation_state&vs_flippedreferences)?0:1;
4050 vw_popuplist[5].ti.disabled = (sc->layers[vw->layer].validation_state&vs_wrongdirection)?0:1;
4051 vw_popuplist[6].ti.disabled = (sc->layers[vw->layer].validation_state&vs_missingextrema)?0:1;
4052 vw_popuplist[7].ti.disabled = (sc->layers[vw->layer].validation_state&vs_missingextrema)?0:1;
4053 vw_popuplist[8].ti.disabled = (sc->layers[vw->layer].validation_state&vs_toomanypoints)?0:1;
4054 vw->sc = sc;
4055 GMenuCreatePopupMenu(vw->v,e, vw_popuplist);
4056 }
4057 }
4058
4059 static void VWDrawWindow(GWindow pixmap,struct val_data *vw, GEvent *e) {
4060 int gid,k, cidmax = vw->cidmax;
4061 SplineFont *sub, *sf=vw->sf;
4062 SplineChar *sc;
4063 int sofar;
4064 int bit, skips, vs, y, m;
4065 GRect old, r;
4066
4067 Color fg = GDrawGetDefaultForeground(NULL);
4068
4069 GDrawPushClip(pixmap,&e->u.expose.rect,&old);
4070 GDrawSetFont(pixmap,vw->font);
4071 gid = VW_FindLine(vw,vw->loff_top, &skips);
4072 if ( gid==-1 ) {
4073 GDrawDrawText8(pixmap,2,(vw->vlcnt-1)*vw->fh/2 + vw->as,
4074 vw->finished_first_pass ? _("Passed Validation") : _("Thinking..."),
4075 -1,fg );
4076 GDrawPopClip(pixmap,&old);
4077 return;
4078 }
4079
4080 y = vw->as - skips*vw->fh;
4081 sofar = -skips;
4082 r.width = r.height = vw->as;
4083 if ( gid!=-2 ) {
4084 for ( ; gid<cidmax && sofar<vw->vlcnt ; ++gid ) {
4085 if ( sf->subfontcnt==0 )
4086 sc = sf->glyphs[gid];
4087 else {
4088 for ( k=0; k<sf->subfontcnt; ++k ) {
4089 sub = sf->subfonts[k];
4090 if ( gid<sub->glyphcnt && (sc = sub->glyphs[gid])!=NULL )
4091 break;
4092 }
4093 }
4094 /* Ignore it if it has not been validated */
4095 /* Ignore it if it is good */
4096 vs = VSModMask(sc,vw);
4097 if ((vs&vs_known) && (vs&vw->mask)!=0 ) {
4098 r.x = 2; r.y = y-vw->as+1;
4099 GDrawDrawRect(pixmap,&r,fg);
4100 GDrawDrawLine(pixmap,r.x+2,r.y+vw->as/2,r.x+vw->as-2,r.y+vw->as/2,fg);
4101 if ( !sc->vs_open )
4102 GDrawDrawLine(pixmap,r.x+vw->as/2,r.y+2,r.x+vw->as/2,r.y+vw->as-2,fg);
4103 GDrawDrawText8(pixmap,r.x+r.width+2,y,sc->name,-1,fg);
4104 y += vw->fh;
4105 ++sofar;
4106 if ( sc->vs_open ) {
4107 for ( m=0, bit=(vs_known<<1) ; bit<=vs_last; ++m, bit<<=1 )
4108 if ( (bit&vw->mask) && (vs&bit) && vserrornames[m]!=NULL ) {
4109 GDrawDrawText8(pixmap,10+r.width+r.x,y,_(vserrornames[m]),-1,
4110 GDrawGetWarningForeground(NULL) );
4111 y += vw->fh;
4112 ++sofar;
4113 }
4114 }
4115 }
4116 }
4117 }
4118 if ( sofar<vw->vlcnt ) {
4119 vs = ValidatePrivate(sf);
4120 if ( !vw->needs_blue )
4121 vs &= ~pds_missingblue;
4122 if ( vs!=0 ) {
4123 /* GT: "Private" is a keyword (sort of) in PostScript. Perhaps it */
4124 /* GT: should remain untranslated? */
4125 GDrawDrawText8(pixmap,r.x+r.width+2,y,_("Private Dictionary"),-1,fg );
4126 y += vw->fh;
4127 for ( m=0, bit=1 ; bit!=0; ++m, bit<<=1 ) {
4128 if ( vs&bit ) {
4129 GDrawDrawText8(pixmap,10+r.width+r.x,y,_(privateerrornames[m]),-1,
4130 GDrawGetWarningForeground(NULL));
4131 y += vw->fh;
4132 }
4133 }
4134 }
4135 }
4136 GDrawPopClip(pixmap,&old);
4137 }
4138
4139 static int VWCheckup(struct val_data *vw) {
4140 /* Check some glyphs to see what their validation state is or if they have*/
4141 /* changed */
4142 int gid, k, cnt=0;
4143 int max;
4144 SplineFont *sf=vw->sf, *sub;
4145 int cntmax = vw->finished_first_pass ? 40 : 60;
4146 SplineChar *sc;
4147 int a_change = false;
4148 int firstv = true;
4149 char *buts[4];
4150
4151 if ( sf->subfontcnt==0 )
4152 max = vw->cidmax = sf->glyphcnt;
4153 else
4154 max = vw->cidmax;
4155
4156 for ( gid=vw->laststart; gid<max && cnt<cntmax && gid<vw->laststart+2000; ++gid ) {
4157 if ( sf->subfontcnt==0 )
4158 sc = sf->glyphs[gid];
4159 else {
4160 for ( k=0; k<sf->subfontcnt; ++k ) {
4161 sub = sf->subfonts[k];
4162 if ( gid<sub->glyphcnt && (sc = sub->glyphs[gid])!=NULL )
4163 break;
4164 }
4165 }
4166 if ( sc!=NULL && !(sc->layers[vw->layer].validation_state&vs_known)) {
4167 if ( firstv ) {
4168 GDrawSetCursor(vw->v,ct_watch);
4169 GDrawSync(NULL);
4170 firstv = false;
4171 }
4172 SCValidate(sc,vw->layer,true);
4173 ++cnt;
4174 }
4175 if ( sc!=NULL && vw->need_to_check_with_user_on_mask &&
4176 (sc->layers[vw->layer].validation_state&vs_nonintegral )) {
4177 vw->need_to_check_with_user_on_mask = false;
4178 buts[0] = _("Report as Error"); buts[1]=_("Ignore"); buts[2] = NULL;
4179 if ( ff_ask(_("Not sure if this is an error..."),(const char **) buts,0,1,
4180 _("This font contains non-integral coordinates. That's OK\n"
4181 "in PostScript and SVG but causes problems in TrueType.\n"
4182 "Should I consider that an error here?"))==0 ) {
4183 a_change = true;
4184 vw->mask = (enum validation_state) (vw->mask | vs_nonintegral);
4185 }
4186 }
4187 if ( sc!=NULL && sc->layers[vw->layer].validation_state!=sc->layers[vw->layer].old_vs ) {
4188 a_change = true;
4189 sc->layers[vw->layer].old_vs = sc->layers[vw->layer].validation_state;
4190 }
4191 }
4192 if ( gid<max )
4193 vw->laststart = gid;
4194 else {
4195 vw->laststart = 0;
4196 if ( !vw->finished_first_pass ) {
4197 vw->finished_first_pass = true;
4198 GDrawCancelTimer(vw->recheck);
4199 /* Check less frequently now we've completed a full scan */
4200 vw->recheck = GDrawRequestTimer(vw->v,3000,3000,NULL);
4201 }
4202 }
4203 if ( a_change )
4204 VW_Remetric(vw);
4205 if ( !firstv )
4206 GDrawSetCursor(vw->v,ct_mypointer);
4207 return( a_change );
4208 }
4209
4210 static int VW_OK(GGadget *g, GEvent *e) {
4211
4212 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
4213 struct val_data *vw = (struct val_data *) GDrawGetUserData(GGadgetGetWindow(g));
4214 GDrawDestroyWindow(vw->gw);
4215 }
4216 return( true );
4217 }
4218
4219 static int vwv_e_h(GWindow gw, GEvent *event) {
4220 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
4221
4222 switch ( event->type ) {
4223 case et_expose:
4224 if ( vw->recheck==NULL ) {
4225 vw->recheck = GDrawRequestTimer(vw->v,500,500,NULL);
4226 }
4227 VWDrawWindow(gw,vw,event);
4228 break;
4229 case et_mouseup:
4230 case et_mousedown:
4231 case et_mousemove:
4232 if (( event->type==et_mouseup || event->type==et_mousedown ) &&
4233 (event->u.mouse.button>=4 && event->u.mouse.button<=7) ) {
4234 return( GGadgetDispatchEvent(vw->vsb,event));
4235 }
4236 VWMouse(vw,event);
4237 break;
4238 case et_char:
4239 return( false );
4240 break;
4241 case et_resize: {
4242 int vlcnt = event->u.resize.size.height/vw->fh;
4243 vw->vlcnt = vlcnt;
4244 VW_SetSb(vw);
4245 GDrawRequestExpose(vw->v,NULL,false);
4246 } break;
4247 case et_timer:
4248 VWCheckup(vw);
4249 break;
4250 default: break;
4251 }
4252 return( true );
4253 }
4254
4255 static int vw_e_h(GWindow gw, GEvent *event) {
4256 struct val_data *vw = (struct val_data *) GDrawGetUserData(gw);
4257
4258 if ( event->type==et_close ) {
4259 GDrawDestroyWindow(gw);
4260 } else if ( event->type == et_char ) {
4261 return( false );
4262 } else if ( event->type == et_destroy ) {
4263 if ( vw->sf!=NULL )
4264 vw->sf->valwin = NULL;
4265 chunkfree(vw,sizeof(*vw));
4266 }
4267 return( true );
4268 }
4269
4270 void SFValidationWindow(SplineFont *sf,int layer,enum fontformat format) {
4271 GWindowAttrs wattrs;
4272 GRect pos;
4273 GWindow gw;
4274 GGadgetCreateData gcd[4], boxes[4], *harray[4], *butarray[8], *varray[3];
4275 GTextInfo label[4];
4276 struct val_data *valwin;
4277 char buffer[200];
4278 int k, gid;
4279 int cidmax;
4280 SplineFont *sub;
4281 SplineChar *sc;
4282 int as, ds, ld;
4283 int needs_blue;
4284 enum validation_state mask;
4285
4286 if ( sf->cidmaster )
4287 sf = sf->cidmaster;
4288 mask = VSMaskFromFormat(sf,layer,format);
4289 needs_blue = (mask==vs_maskps || mask==vs_maskcid);
4290
4291 if ( sf->valwin!=NULL ) {
4292 /* Don't need to force a revalidation because if the window exists */
4293 /* it's been doing that all by itself */
4294 if ( mask!=(sf->valwin->mask&~vs_nonintegral) ) {
4295 /* But if we go from postscript to truetype the types of errors */
4296 /* change, so what we display might be different */
4297 sf->valwin->mask = mask;
4298 sf->valwin->needs_blue = needs_blue;
4299 sf->valwin->layer = layer;
4300 VW_Remetric(sf->valwin);
4301 }
4302 GDrawSetVisible(sf->valwin->gw,true);
4303 GDrawRaise(sf->valwin->gw);
4304 return;
4305 }
4306
4307 if ( sf->subfontcnt!=0 ) {
4308 cidmax = 0;
4309 for ( k=0; k<sf->subfontcnt; ++k )
4310 if ( sf->subfonts[k]->glyphcnt > cidmax )
4311 cidmax = sf->subfonts[k]->glyphcnt;
4312 } else
4313 cidmax = sf->glyphcnt;
4314
4315 /* Init all glyphs as undrawn */
4316 for ( gid=0; gid<cidmax ; ++gid ) {
4317 if ( sf->subfontcnt==0 )
4318 sc = sf->glyphs[gid];
4319 else {
4320 for ( k=0; k<sf->subfontcnt; ++k ) {
4321 sub = sf->subfonts[k];
4322 if ( gid<sub->glyphcnt && (sc = sub->glyphs[gid])!=NULL )
4323 break;
4324 }
4325 }
4326 if ( sc!=NULL ) {
4327 sc->layers[layer].old_vs = 0;
4328 sc->vs_open = true; /* should this default to false? */
4329 }
4330 }
4331
4332 valwin = (struct val_data *)chunkalloc(sizeof(struct val_data));
4333 valwin->sf = sf;
4334 valwin->mask = mask;
4335 valwin->needs_blue = needs_blue;
4336 valwin->cidmax = cidmax;
4337 valwin->lastgid = -1;
4338 valwin->layer = layer;
4339 valwin->need_to_check_with_user_on_mask = (format==ff_none && !sf->layers[layer].order2 );
4340
4341 memset(&wattrs,0,sizeof(wattrs));
4342 wattrs.mask = (enum window_attr_mask)(wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg);
4343 wattrs.event_masks = -1;
4344 wattrs.cursor = ct_mypointer;
4345 sprintf( buffer, _("Validation of %.100s"), sf->fontname );
4346 wattrs.utf8_window_title = buffer;
4347 wattrs.is_dlg = true;
4348 wattrs.undercursor = 1;
4349 pos.x = pos.y = 0;
4350 pos.width = GDrawPointsToPixels(NULL,200);
4351 pos.height = GDrawPointsToPixels(NULL,300);
4352 valwin->gw = gw = GDrawCreateTopWindow(NULL,&pos,vw_e_h,valwin,&wattrs);
4353
4354 valwin->font = validate_font.fi;
4355 GDrawWindowFontMetrics(valwin->gw,valwin->font,&as,&ds,&ld);
4356 valwin->fh = as+ds;
4357 valwin->as = as;
4358
4359 memset(&label,0,sizeof(label));
4360 memset(&gcd,0,sizeof(gcd));
4361 memset(&boxes,0,sizeof(boxes));
4362
4363 k = 0;
4364 gcd[k].gd.flags = (enum gg_flags) (gg_visible | gg_enabled);
4365 gcd[k].gd.u.drawable_e_h = vwv_e_h;
4366 gcd[k++].creator = GDrawableCreate;
4367
4368 gcd[k].gd.flags = (enum gg_flags) (gg_visible | gg_enabled | gg_sb_vert);
4369 gcd[k].gd.handle_controlevent = VW_VScroll;
4370 gcd[k++].creator = GScrollBarCreate;
4371 harray[0] = &gcd[k-2]; harray[1] = &gcd[k-1]; harray[2] = NULL; harray[3] = NULL;
4372
4373 gcd[k].gd.flags = (enum gg_flags) (gg_visible | gg_enabled | gg_but_default);
4374 label[k].text = (unichar_t *) _("_OK");
4375 label[k].text_is_1byte = true;
4376 label[k].text_in_resource = true;
4377 gcd[k].gd.label = &label[k];
4378 gcd[k].gd.handle_controlevent = VW_OK;
4379 gcd[k++].creator = GButtonCreate;
4380 butarray[0] = GCD_Glue; butarray[1] = &gcd[k-1]; butarray[2] = GCD_Glue; butarray[3] = NULL;
4381
4382 boxes[2].gd.flags = (enum gg_flags) (gg_enabled|gg_visible);
4383 boxes[2].gd.u.boxelements = harray;
4384 boxes[2].creator = GHVGroupCreate;
4385
4386 boxes[3].gd.flags = (enum gg_flags) (gg_enabled|gg_visible);
4387 boxes[3].gd.u.boxelements = butarray;
4388 boxes[3].creator = GHBoxCreate;
4389 varray[0] = &boxes[2]; varray[1] = &boxes[3]; varray[2] = NULL;
4390
4391 boxes[0].gd.flags = (enum gg_flags) (gg_enabled|gg_visible);
4392 boxes[0].gd.u.boxelements = varray;
4393 boxes[0].creator = GVBoxCreate;
4394
4395 GGadgetsCreate(gw,boxes);
4396 valwin->vsb = gcd[1].ret;
4397 valwin->v = GDrawableGetWindow(gcd[0].ret);
4398 GHVBoxSetExpandableRow(boxes[0].ret,0);
4399 GHVBoxSetExpandableCol(boxes[2].ret,0);
4400 GHVBoxSetPadding(boxes[2].ret,0,0);
4401 GHVBoxSetExpandableCol(boxes[3].ret,gb_expandglue);
4402 GHVBoxFitWindow(boxes[0].ret);
4403
4404 GDrawSetVisible(gw,true);
4405 }
4406
4407 void ValidationDestroy(SplineFont *sf) {
4408 if ( sf->valwin!=NULL ) {
4409 sf->valwin->sf = NULL;
4410 GDrawDestroyWindow(sf->valwin->gw);
4411 sf->valwin = NULL;
4412 }
4413 }