Debian Codegraph @

fontforgeexe/charview.c

raw symbols SCIP
1 /* Copyright (C) 2000-2012 by George Williams */
2 /*
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
8
9 * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12
13 * The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <fontforge-config.h>
29
30 #include "autohint.h"
31 #include "autosave.h"
32 #include "autotrace.h"
33 #include "autowidth.h"
34 #include "charview_private.h"
35 #include "cvruler.h"
36 #include "cvundoes.h"
37 #include "dlist.h"
38 #include "dumppfa.h"
39 #include "encoding.h"
40 #include "ffglib.h"
41 #include "fontforgeui.h"
42 #include "fvcomposite.h"
43 #include "fvfonts.h"
44 #include "gkeysym.h"
45 #include "gresedit.h"
46 #include "hotkeys.h"
47 #include "lookups.h"
48 #include "mm.h"
49 #include "namelist.h"
50 #include "prefs.h"
51 #include "sfd.h"
52 #include "spiro.h"
53 #include "splinefill.h"
54 #include "splineorder2.h"
55 #include "splineoverlap.h"
56 #include "splinesaveafm.h"
57 #include "splineutil.h"
58 #include "splineutil2.h"
59 #include "ustring.h"
60 #include "utype.h"
61 #include "wordlistparser.h"
62
63 #include "cv_mids.h"
64
65 #include <locale.h>
66 #include <math.h>
67
68 #ifdef HAVE_IEEEFP_H
69 # include <ieeefp.h> /* Solaris defines isnan in ieeefp rather than math.h */
70 #endif
71
72 /* Barry wants to be able to redefine menu bindings only in the charview (I think) */
73 /* the menu parser will first check for something like "CV*Open|Ctl+O", and */
74 /* if that fails will strip off "CV*" and check for "Open|Ctl+O" */
75 #undef H_
76 #define H_(str) ("CV*" str)
77
78 extern void UndoesFreeButRetainFirstN( Undoes** undopp, int retainAmount );
79 static void CVMoveInWordListByOffset( CharView* cv, int offset );
80 extern void CVDebugFree( DebugView *dv );
81
82 extern int _GScrollBar_Width;
83
84 int additionalCharsToShowLimit = 50;
85
86 int ItalicConstrained=true;
87 float arrowAmount=1;
88 float arrowAccelFactor=10.;
89 float snapdistance=3.5;
90 float snapdistancemeasuretool=3.5;
91 int updateflex = false;
92 extern int clear_tt_instructions_when_needed;
93 int use_freetype_with_aa_fill_cv = 1;
94 int interpCPsOnMotion=false;
95 int DrawOpenPathsWithHighlight = 1;
96 #define default_cv_width 540
97 #define default_cv_height 540
98 int cv_width = default_cv_width;
99 int cv_height = default_cv_height;
100 int cv_show_fill_with_space = 1;
101
102 #define prefs_cvEditHandleSize_default 5.0
103 float prefs_cvEditHandleSize = prefs_cvEditHandleSize_default;
104
105 int prefs_cvInactiveHandleAlpha = 255;
106
107 int prefs_cv_show_control_points_always_initially = 0;
108 int prefs_create_dragging_comparison_outline = 0;
109
110 extern struct lconv localeinfo;
111 extern char *coord_sep;
112 struct cvshows CVShows = {
113 1, /* show foreground */
114 1, /* show background */
115 1, /* show grid plane */
116 1, /* show horizontal hints */
117 1, /* show vertical hints */
118 1, /* show diagonal hints */
119 1, /* show points */
120 0, /* show filled */
121 1, /* show rulers */
122 1, /* show points which are to be rounded to the ttf grid and aren't on hints */
123 1, /* show x minimum distances */
124 1, /* show y minimum distances */
125 1, /* show horizontal metrics */
126 1, /* show vertical metrics */
127 0, /* mark extrema */
128 0, /* show points of inflection */
129 1, /* show blue values */
130 1, /* show family blues too */
131 1, /* show anchor points */
132 0, /* show control point info when moving them */
133 1, /* show tabs containing names of former glyphs */
134 1, /* show side bearings */
135 1, /* show the names of references */
136 1, /* snap outlines to pixel grid */
137 0, /* show lines which are almost, but not exactly horizontal or vertical */
138 0, /* show curves which are almost, but not exactly horizontal or vertical at the end-points */
139 3, /* number of em-units a coord difference must be less than to qualify for almost hv */
140 1, /* Check for self-intersections in the element view */
141 1 /* In tt debugging, mark changed rasters differently */
142 };
143 struct cvshows CVShowsPrevewToggleSavedState;
144
145 #define CID_Base 1001
146 #define CID_getValueFromUser CID_Base + 1
147
148 static Color pointcol = 0xff0000;
149 static Color firstpointcol = 0x707000;
150 static Color selectedpointcol = 0xc8c800;
151 static int selectedpointwidth = 2;
152 static Color extremepointcol = 0xc00080;
153 static Color pointofinflectioncol = 0x008080;
154 static Color almosthvcol = 0x00ff80;
155 Color nextcpcol = 0x007090;
156 Color prevcpcol = 0xcc00cc;
157 static Color selectedcpcol = 0xffffff;
158 static Color coordcol = 0x808080;
159 static Color ascentdescentcol = 0xff808080;
160 Color widthcol = 0x000000;
161 static Color widthselcol = 0x00ff00;
162 static Color lbearingselcol = 0x00ff00;
163 static Color widthgridfitcol = 0x009800;
164 static Color lcaretcol = 0x909040;
165 static Color rastercol = 0xffa0a0a0; /* Translucent */
166 static Color rasternewcol = 0xff909090;
167 static Color rasteroldcol = 0xffc0c0c0;
168 static Color rastergridcol = 0xffb0b0ff;
169 static Color rasterdarkcol = 0xff606060;
170 static Color deltagridcol = 0xcc0000;
171 static Color italiccoordcol = 0x909090;
172 static Color metricslabelcol = 0x000000;
173 static Color hintlabelcol = 0x00cccc;
174 static Color bluevalstipplecol = 0x808080ff; /* Translucent */
175 static Color fambluestipplecol = 0x80ff7070; /* Translucent */
176 static Color mdhintcol = 0x80e04040; /* Translucent */
177 static Color dhintcol = 0x80d0a0a0; /* Translucent */
178 static Color hhintcol = 0x80a0d0a0; /* Translucent */
179 static Color vhintcol = 0x80c0c0ff; /* Translucent */
180 static Color hflexhintcol = 0x00ff00;
181 static Color vflexhintcol = 0x00ff00;
182 static Color conflicthintcol = 0x00ffff;
183 static Color hhintactivecol = 0x00a000;
184 static Color vhintactivecol = 0x0000ff;
185 static Color anchorcol = 0x0040ff;
186 static Color anchoredoutlinecol = 0x0040ff;
187 static Color templateoutlinecol = 0x009800;
188 static Color oldoutlinecol = 0x008000;
189 static Color transformorigincol = 0x000000;
190 static Color guideoutlinecol = 0x808080;
191 static Color guidedragcol = 0x000000;
192 static Color gridfitoutlinecol = 0x009800;
193 static Color backoutlinecol = 0x009800;
194 static Color foreoutlinecol = 0x000000;
195 static Color clippathcol = 0x0000ff;
196 static Color openpathcol = 0x40660000;
197 static Color backimagecol = 0x707070;
198 static Color fillcol = 0x80707070; /* Translucent */
199 static Color tracecol = 0x008000;
200 static Color rulerbigtickcol = 0x008000;
201 static Color previewfillcol = 0x0f0f0f;
202 static Color DraggingComparisonOutlineColor = 0x8800BB00;
203 static Color DraggingComparisonAlphaChannelOverride = 0x88000000;
204 static Color foreoutthicklinecol = 0x20707070;
205 static Color backoutthicklinecol = 0x20707070;
206 static Color rulercurtickcol = 0xff0000;
207 Color cvpalettefgcol = 0x000000;
208 Color cvpalettebgcol = 0xf5fffa;
209 Color cvpaletteactborcol;
210 int cvbutton3d = 1;
211 Color cvbutton3dedgelightcol = 0xe0e0e0;
212 Color cvbutton3dedgedarkcol = 0x707070;
213 static GResFont cv_labelfont = GRESFONT_INIT("400 10pt " SANS_UI_FAMILIES);
214 static GResFont cv_iconfont = GRESFONT_INIT("400 24pt " SERIF_UI_FAMILIES);
215 GResFont cv_pointnumberfont = GRESFONT_INIT("400 10px " SANS_UI_FAMILIES);
216 GResFont cv_rulerfont = GRESFONT_INIT("400 10px " SANS_UI_FAMILIES);
217 extern GResFont cv_measuretoolfont;
218 extern GResFont layerspalette_font;
219 extern GResFont toolspalette_font;
220
221
222 int prefs_cv_outline_thickness = 1;
223
224 // Format is 0x AA RR GG BB.
225
226 static int CV_OnCharSelectorTextChanged( GGadget *g, GEvent *e );
227 static void CVHScrollSetPos( CharView *cv, int newpos );
228
229 static void CVClear(GWindow,GMenuItem *mi, GEvent *);
230 static void CVMouseMove(CharView *cv, GEvent *event );
231 static void CVMouseUp(CharView *cv, GEvent *event );
232 static void CVHScroll(CharView *cv,struct sbevent *sb);
233 static void CVVScroll(CharView *cv,struct sbevent *sb);
234 /*static void CVElide(GWindow gw,struct gmenuitem *mi,GEvent *e);*/
235 static void CVMenuSimplify(GWindow gw,struct gmenuitem *mi,GEvent *e);
236 static void CVMenuSimplifyMore(GWindow gw,struct gmenuitem *mi,GEvent *e);
237 static void CVPreviewModeSet(GWindow gw, int checked);
238 static void CVExposeRulers(CharView *cv, GWindow pixmap);
239 static void CVDrawGuideLine(CharView *cv, int guide_pos);
240
241 static int cvcolsinited = false;
242
243 static struct resed charviewpoints_re[] = {
244 { N_("Point Color"), "PointColor", rt_color, &pointcol, N_("The color of an on-curve point"), NULL, { 0 }, 0, 0 },
245 { N_("First Point Color"), "FirstPointColor", rt_color, &firstpointcol, N_("The color of the point which is the start of a contour"), NULL, { 0 }, 0, 0 },
246 { N_("Selected Point Color"), "SelectedPointColor", rt_color, &selectedpointcol, N_("The color of a selected point"), NULL, { 0 }, 0, 0 },
247 { N_("Selected Point Width"), "SelectedPointWidth", rt_int, &selectedpointwidth, N_("The width of the line used to draw selected points"), NULL, { 0 }, 0, 0 },
248 { N_("Extrema Point Color"), "ExtremePointColor", rt_color, &extremepointcol, N_("The color used to draw points at extrema (if that mode is active)"), NULL, { 0 }, 0, 0 },
249 { N_("Point of Inflection Color"), "PointOfInflectionColor", rt_color, &pointofinflectioncol, N_("The color used to draw points of inflection (if that mode is active)"), NULL, { 0 }, 0, 0 },
250 { N_("Almost H/V Color"), "AlmostHVColor", rt_color, &almosthvcol, N_("The color used to draw markers for splines which are almost, but not quite horizontal or vertical at their end-points"), NULL, { 0 }, 0, 0 },
251 { N_("Next CP Color"), "NextCPColor", rt_color, &nextcpcol, N_("The color used to draw the \"next\" control point of an on-curve point"), NULL, { 0 }, 0, 0 },
252 { N_("Prev CP Color"), "PrevCPColor", rt_color, &prevcpcol, N_("The color used to draw the \"previous\" control point of an on-curve point"), NULL, { 0 }, 0, 0 },
253 { N_("Selected CP Color"), "SelectedCPColor", rt_color, &selectedcpcol, N_("The color used to draw a selected control point of an on-curve point"), NULL, { 0 }, 0, 0 },
254 { N_("Anchor Color"), "AnchorColor", rt_color, &anchorcol, N_("The color of anchor stars"), NULL, { 0 }, 0, 0 },
255 { N_("LabelFont"), "LabelFont", rt_font, &cv_labelfont, N_("Used for point and contour names, anchor point names, etc."), NULL, { 0 }, 0, 0 },
256 { N_("IconFont"), "IconFont", rt_font, &cv_iconfont, N_("Used for window decoration icon when there is no existing spline or reference"), NULL, { 0 }, 0, 0 },
257 { N_("PointNumberFont"), "PointNumberFont", rt_font, &cv_pointnumberfont, N_("Used for point numbers, hints, etc."), NULL, { 0 }, 0, 0 },
258 RESED_EMPTY
259 };
260
261 static struct resed charviewlinesfills_re[] = {
262 { N_("Active Layer Color"), "ForegroundOutlineColor", rt_color, &foreoutlinecol, N_("The color of outlines in the active layer"), NULL, { 0 }, 0, 0 },
263 { N_("Active Thick Layer Color"), "ForegroundThickOutlineColor", rt_coloralpha, &foreoutthicklinecol, N_("The color of thick outlines in the active layer"), NULL, { 0 }, 0, 0 },
264 { N_("Fill Color"), "FillColor", rt_coloralpha, &fillcol, N_("The color used to fill the outline if that mode is active"), NULL, { 0 }, 0, 0 },
265 { N_("Preview Fill Color"), "PreviewFillColor", rt_coloralpha, &previewfillcol, N_("The color used to fill the outline when in preview mode"), NULL, { 0 }, 0, 0 },
266 { N_("Open Path Color"), "OpenPathColor", rt_coloralpha, &openpathcol, N_("The color of the open path"), NULL, { 0 }, 0, 0 },
267 { N_("Clip Path Color"), "ClipPathColor", rt_color, &clippathcol, N_("The color of the clip path"), NULL, { 0 }, 0, 0 },
268 { N_("Inactive Layer Color"), "BackgroundOutlineColor", rt_color, &backoutlinecol, N_("The color of outlines in inactive layers"), NULL, { 0 }, 0, 0 },
269 { N_("Inactive Thick Layer Color"), "BackgroundThickOutlineColor", rt_coloralpha, &backoutthicklinecol, N_("The color of thick outlines in inactive layers"), NULL, { 0 }, 0, 0 },
270 { N_("Width Color"), "WidthColor", rt_color, &widthcol, N_("The color of the line marking the advance width"), NULL, { 0 }, 0, 0 },
271 { N_("Selected Width Color"), "WidthSelColor", rt_color, &widthselcol, N_("The color of the line marking the advance width when it is selected"), NULL, { 0 }, 0, 0 },
272 { N_("Selected LBearing Color"), "LBearingSelColor", rt_color, &lbearingselcol, N_("The color of the line marking the left bearing when it is selected"), NULL, { 0 }, 0, 0 },
273 { N_("Ligature Caret Color"), "LigatureCaretColor", rt_color, &lcaretcol, N_("The color of the line(s) marking ligature carets"), NULL, { 0 }, 0, 0 },
274 { N_("Anchored Line Color"), "AnchoredOutlineColor", rt_color, &anchoredoutlinecol, N_("The color of another glyph drawn in the current view to show where it would be placed by an anchor lookup"), NULL, { 0 }, 0, 0 },
275 { N_("Coordinate Line Color"), "CoordinateLineColor", rt_color, &coordcol, N_("Color of the x=0 and y=0 lines"), NULL, { 0 }, 0, 0 },
276 { N_("Ascent/Descent Color"), "AscentDescentColor", rt_coloralpha, &ascentdescentcol, N_("Color of the ascent and descent lines"), NULL, { 0 }, 0, 0 },
277 { N_("Italic Coord. Color"), "ItalicCoordColor", rt_color, &italiccoordcol, NULL, NULL, { 0 }, 0, 0 },
278 { N_("Metrics Label Color"), "MetricsLabelColor", rt_color, &metricslabelcol, NULL, NULL, { 0 }, 0, 0 },
279 { N_("Template Outline Color"), "TemplateOutlineColor", rt_color, &templateoutlinecol, NULL, NULL, { 0 }, 0, 0 },
280 { N_("Ruler Big Tick Color"), "RulerBigTickColor", rt_color, &rulerbigtickcol, N_("The color used to draw the large tick marks in rulers."), NULL, { 0 }, 0, 0 },
281 { N_("Ruler Current Tick Color"), "RulerCurrentTickColor", rt_color, &rulercurtickcol, N_("The color used to draw a vertical and a horizontal tick corresponding to the mouse position."), NULL, { 0 }, 0, 0 },
282 { N_("Ruler Font"), "Ruler Font", rt_font, &cv_rulerfont, N_("Used for ruler numbers and other ruler notations."), NULL, { 0 }, 0, 0 },
283 { N_("Guide Layer Color"), "GuideOutlineColor", rt_color, &guideoutlinecol, NULL, NULL, { 0 }, 0, 0 },
284 { N_("Guide Drag Color"), "GuideDragColor", rt_color, &guidedragcol, N_("The color used to display a new guide line dragged from the ruler."), NULL, { 0 }, 0, 0 },
285 RESED_EMPTY
286 };
287
288 static struct resed charviewtools_re[] = {
289 { N_("Trace Color"), "TraceColor", rt_color, &tracecol, NULL, NULL, { 0 }, 0, 0 },
290 { N_("Old Outline Color"), "OldOutlineColor", rt_color, &oldoutlinecol, NULL, NULL, { 0 }, 0, 0 },
291 { N_("Transform Original Color"), "TransformOriginColor", rt_color, &transformorigincol, NULL, NULL, { 0 }, 0, 0 },
292 { N_("Dragging Comparison Outline Color"), "DraggingComparisonOutlineColor", rt_coloralpha, &DraggingComparisonOutlineColor, N_("The color used to draw the outline of the old spline when you are interactively modifying a glyph"), NULL, { 0 }, 0, 0 },
293 { N_("Dragging Comparison Alpha Channel"), "DraggingComparisonAlphaChannelOverride", rt_coloralpha, &DraggingComparisonAlphaChannelOverride, N_("Only the alpha value is used and if non zero it will set the alpha channel for the control points, bezier information and other non spline indicators for the Dragging Comparison Outline spline"), NULL, { 0 }, 0, 0 },
294 { N_("Measure Tool Line Color"), "MeasureToolLineColor", rt_color, &measuretoollinecol, N_("The color used to draw the measure tool line."), NULL, { 0 }, 0, 0 },
295 { N_("Measure Tool Point Color"), "MeasureToolPointColor", rt_color, &measuretoolpointcol, N_("The color used to draw the measure tool points."), NULL, { 0 }, 0, 0 },
296 { N_("Measure Tool Point Snapped Color"), "MeasureToolPointSnappedColor", rt_color, &measuretoolpointsnappedcol, N_("The color used to draw the measure tool points when snapped."), NULL, { 0 }, 0, 0 },
297 { N_("Measure Tool Canvas Number Color"), "MeasureToolCanvasNumbersColor", rt_color, &measuretoolcanvasnumberscol, N_("The color used to draw the measure tool numbers on the canvas."), NULL, { 0 }, 0, 0 },
298 { N_("Measure Tool Canvas Number Snapped Color"), "MeasureToolCanvasNumbersSnappedColor", rt_color, &measuretoolcanvasnumberssnappedcol, N_("The color used to draw the measure tool numbers on the canvas when snapped."), NULL, { 0 }, 0, 0 },
299 { N_("Measure Tool Windows Foreground Color"), "MeasureToolWindowForeground", rt_color, &measuretoolwindowforegroundcol, N_("The measure tool window foreground color."), NULL, { 0 }, 0, 0 },
300 { N_("Measure Tool Windows Background Color"), "MeasureToolWindowBackground", rt_color, &measuretoolwindowbackgroundcol, N_("The measure tool window background color."), NULL, { 0 }, 0, 0 },
301 { N_("MeasureToolFont"), "MeasureToolFont", rt_font, &cv_measuretoolfont, NULL, NULL, { 0 }, 0, 0 },
302 RESED_EMPTY
303 };
304
305 static struct resed charviewhints_re[] = {
306 { N_("Blue Values Color"), "BlueValuesStippledColor", rt_coloralpha, &bluevalstipplecol, N_("The color used to mark blue zones in the blue values entry of the private dictionary"), NULL, { 0 }, 0, 0 },
307 { N_("Family Blue Color"), "FamilyBlueStippledColor", rt_coloralpha, &fambluestipplecol, N_("The color used to mark blue zones in the family blues entry of the private dictionary"), NULL, { 0 }, 0, 0 },
308 { N_("Minimum Distance Hint Color"), "MDHintColor", rt_coloralpha, &mdhintcol, N_("The color used to draw minimum distance hints"), NULL, { 0 }, 0, 0 },
309 { N_("Hint Label Color"), "HintLabelColor", rt_color, &hintlabelcol,NULL, NULL, { 0 }, 0, 0 },
310 { N_("Diagonal Hint Color"), "DHintColor", rt_coloralpha, &dhintcol, N_("The color used to draw diagonal hints"), NULL, { 0 }, 0, 0 },
311 { N_("Horiz. Hint Color"), "HHintColor", rt_coloralpha, &hhintcol, N_("The color used to draw horizontal hints"), NULL, { 0 }, 0, 0 },
312 { N_("Vert. Hint Color"), "VHintColor", rt_coloralpha, &vhintcol, N_("The color used to draw vertical hints"), NULL, { 0 }, 0, 0 },
313 { N_("HFlex Hint Color"), "HFlexHintColor", rt_color, &hflexhintcol, NULL, NULL, { 0 }, 0, 0 },
314 { N_("VFlex Hint Color"), "VFlexHintColor", rt_color, &vflexhintcol, NULL, NULL, { 0 }, 0, 0 },
315 { N_("Conflict Hint Color"), "ConflictHintColor", rt_color, &conflicthintcol, N_("The color used to draw a hint which conflicts with another"), NULL, { 0 }, 0, 0 },
316 { N_("HHint Active Color"), "HHintActiveColor", rt_color, &hhintactivecol, N_("The color used to draw the active horizontal hint which the Review Hints dialog is examining"), NULL, { 0 }, 0, 0 },
317 { N_("VHint Active Color"), "VHintActiveColor", rt_color, &vhintactivecol, N_("The color used to draw the active vertical hint which the Review Hints dialog is examining"), NULL, { 0 }, 0, 0 },
318 { N_("Delta Grid Color"), "DeltaGridColor", rt_color, &deltagridcol, N_("Indicates a notable grid pixel when suggesting deltas."), NULL, { 0 }, 0, 0 },
319 RESED_EMPTY
320 };
321
322 static struct resed charviewraster_re[] = {
323 { N_("Grid Fit Color"), "GridFitOutlineColor", rt_color, &gridfitoutlinecol, N_("The color of grid-fit outlines"), NULL, { 0 }, 0, 0 },
324 { N_("Grid Fit Width Color"), "GridFitWidthColor", rt_color, &widthgridfitcol, N_("The color of the line marking the grid-fit advance width"), NULL, { 0 }, 0, 0 },
325 { N_("Raster Color"), "RasterColor", rt_coloralpha, &rastercol, N_("The color of grid-fit (and other) raster blocks"), NULL, { 0 }, 0, 0 },
326 { N_("Raster New Color"), "RasterNewColor", rt_coloralpha, &rasternewcol, N_("The color of raster blocks which have just been turned on (in the debugger when an instruction moves a point)"), NULL, { 0 }, 0, 0 },
327 { N_("Raster Old Color"), "RasterOldColor", rt_coloralpha, &rasteroldcol, N_("The color of raster blocks which have just been turned off (in the debugger when an instruction moves a point)"), NULL, { 0 }, 0, 0 },
328 { N_("Raster Grid Color"), "RasterGridColor", rt_coloralpha, &rastergridcol, NULL, NULL, { 0 }, 0, 0 },
329 { N_("Raster Dark Color"), "RasterDarkColor", rt_coloralpha, &rasterdarkcol, N_("When debugging in grey-scale this is the color of a raster block which is fully covered."), NULL, { 0 }, 0, 0 },
330 { N_("Background Image Color"), "BackgroundImageColor", rt_coloralpha, &backimagecol, N_("The color used to draw bitmap (single bit) images which do not specify a clut"), NULL, { 0 }, 0, 0 },
331 RESED_EMPTY
332 };
333
334 static struct resed cvpalettes_re[] = {
335 { N_("Palette Foreground Color"), "CVPaletteForegroundColor", rt_color, &cvpalettefgcol, N_("When buttons are 3D, the light edge color"), NULL, { 0 }, 0, 0 },
336 { N_("Palette Background Color"), "CVPaletteBackgroundColor", rt_color, &cvpalettebgcol, N_("When buttons are 3D, the light edge color"), NULL, { 0 }, 0, 0 },
337 { N_("3D Light Edge Color"), "Button3DEdgeLightColor", rt_color, &cvbutton3dedgelightcol, N_("When buttons are 3D, the light edge color"), NULL, { 0 }, 0, 0 },
338 { N_("3D Dark Edge Color"), "Button3DEdgeDarkColor", rt_color, &cvbutton3dedgedarkcol, N_("When buttons are 3D, the dark edge color"), NULL, { 0 }, 0, 0 },
339 { N_("3D Buttons"), "Button3d", rt_bool, &cvbutton3d, N_("Whether buttons on the CharView pallettes have a 3D appearance"), NULL, { 0 }, 0, 0 },
340 {N_("LayersPalette.Font"), "LayersPalette.Font", rt_font, &layerspalette_font, N_("Font used in the outline view layers palette"), NULL, { 0 }, 0, 0 },
341 {N_("ToolsPalette.Font"), "ToolsPalette.Font", rt_font, &toolspalette_font, N_("Font used in the outline view tools palette"), NULL, { 0 }, 0, 0 },
342 RESED_EMPTY
343 };
344
345 /* return 1 if anything changed */
346 static void update_spacebar_hand_tool(CharView *cv) {
347 if ( GDrawKeyState(cv->v, ' ') ) {
348 if ( !cv->spacebar_hold && !cv_auto_goto ) {
349 cv->spacebar_hold = 1;
350 cv->b1_tool_old = cv->b1_tool;
351 cv->b1_tool = cvt_hand;
352 cv->active_tool = cvt_hand;
353 CVMouseDownHand(cv);
354 CVPreviewModeSet(cv->gw, cv_show_fill_with_space);
355 }
356 } else {
357 if ( cv->spacebar_hold ) {
358 cv->spacebar_hold = 0;
359 cv->b1_tool = cv->b1_tool_old;
360 cv->active_tool = cvt_none;
361 cv->b1_tool_old = cvt_none;
362 CVPreviewModeSet(cv->gw, false);
363 }
364 }
365 }
366
367
368 int CVInSpiro( CharView *cv )
369 {
370 int inspiro = 0;
371 int canspiro = hasspiro();
372 if( cv )
373 inspiro = canspiro && cv->b.sc->inspiro;
374 return inspiro;
375 }
376
377 /**
378 * Returns the number of points which are currently selected in this
379 * charview. Handy for menus and the like which might like to grey out
380 * if there are <2, or <3 points actively selected.
381 */
382 int CVCountSelectedPoints(CharView *cv) {
383 SplinePointList *spl;
384 Spline *spline, *first;
385 int ret = 0;
386
387 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
388 first = NULL;
389 for ( spline = spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next ) {
390 if( spline == spl->first->next ) {
391 if ( spline->from->selected ) {
392 ret++;
393 }
394 }
395 if ( spline->to->selected ) {
396 if( spline->to != spl->first->next->from )
397 ret++;
398 }
399 if ( first==NULL ) {
400 first = spline;
401 }
402 }
403 }
404 return ret;
405 }
406
407
408
409 /* floor(pt) would _not_ be more correct, as we want
410 * shapes not to cross axes multiple times while scaling.
411 */
412 static double rpt(CharView *cv, double pt) {
413 return cv && cv->snapoutlines ? rint(pt) : pt;
414 }
415
416 extern GResInfo charviewpoints_ri, charviewlinesfills_ri, charviewtools_ri;
417 extern GResInfo charviewhints_ri, charviewraster_ri, cvpalettes_ri;
418 void CVColInit( void ) {
419 if ( cvcolsinited )
420 return;
421 GResEditDoInit(&charviewpoints_ri);
422 GResEditDoInit(&charviewlinesfills_ri);
423 GResEditDoInit(&charviewtools_ri);
424 GResEditDoInit(&charviewhints_ri);
425 GResEditDoInit(&charviewraster_ri);
426 GResEditDoInit(&cvpalettes_ri);
427 cvcolsinited = true;
428 }
429
430 GDevEventMask input_em[] = {
431 /* Event masks for wacom devices */
432 /* negative utility in opening Mouse1 */
433 /* No point in distinguishing cursor from core mouse */
434 { (1<<et_mousemove)|(1<<et_mousedown)|(1<<et_mouseup)|(1<<et_char), "stylus" },
435 { (1<<et_mousemove)|(1<<et_mousedown)|(1<<et_mouseup), "eraser" },
436 { 0, NULL }
437 };
438 const int input_em_cnt = sizeof(input_em)/sizeof(input_em[0])-1;
439
440 /* Positions on the info line */
441 #define RPT_BASE 5 /* Place to draw the pointer icon */
442 #define RPT_DATA 13 /* x,y text after above */
443 #define SPT_BASE 83 /* Place to draw selected pt icon */
444 #define SPT_DATA 97 /* Any text for it */
445 #define SOF_BASE 157 /* Place to draw selection to pointer icon */
446 #define SOF_DATA 179 /* Any text for it */
447 #define SDS_BASE 259 /* Place to draw distance icon */
448 #define SDS_DATA 281 /* Any text for it */
449 #define SAN_BASE 331 /* Place to draw angle icon */
450 #define SAN_DATA 353 /* Any text for it */
451 #define MAG_BASE 383 /* Place to draw magnification icon */
452 #define MAG_DATA 394 /* Any text for it */
453 #define LAYER_DATA 454 /* Text to show the current layer */
454 #define CODERANGE_DATA 574 /* Text to show the current code range (if the debugger be active) */
455 #define FLAGS_DATA 724 /* Text to show the current drawmode flags */
456
457 CharViewTab* CVGetActiveTab(CharView *cv) {
458 if (cv->tabs == NULL) {
459 // This happens when used by the bitmap view, which doesn't support tabs
460 return &cv->cvtabs[0];
461 }
462 int tab = GTabSetGetSel(cv->tabs);
463 return &cv->cvtabs[tab];
464 }
465
466 void CVDrawRubberRect(GWindow pixmap, CharView *cv) {
467 GRect r;
468 CharViewTab *tab = CVGetActiveTab(cv);
469 if ( !cv->p.rubberbanding )
470 return;
471 r.x = tab->xoff + rint(cv->p.cx*tab->scale);
472 r.y = -tab->yoff + cv->height - rint(cv->p.cy*tab->scale);
473 r.width = rint( (cv->p.ex-cv->p.cx)*tab->scale);
474 r.height = -rint( (cv->p.ey-cv->p.cy)*tab->scale);
475 if ( r.width<0 ) {
476 r.x += r.width;
477 r.width = -r.width;
478 }
479 if ( r.height<0 ) {
480 r.y += r.height;
481 r.height = -r.height;
482 }
483 GDrawSetDashedLine(pixmap,2,2,0);
484 GDrawSetLineWidth(pixmap,0);
485 GDrawDrawRect(pixmap,&r,oldoutlinecol);
486 GDrawSetDashedLine(pixmap,0,0,0);
487 }
488
489 static void CVDrawRubberLine(GWindow pixmap, CharView *cv) {
490 int x,y, xend,yend;
491 CharViewTab* tab = CVGetActiveTab(cv);
492 Color col = cv->active_tool==cvt_ruler ? measuretoollinecol : oldoutlinecol;
493 if ( !cv->p.rubberlining )
494 return;
495 x = tab->xoff + rint(cv->p.cx*tab->scale);
496 y = -tab->yoff + cv->height - rint(cv->p.cy*tab->scale);
497 xend = tab->xoff + rint(cv->info.x*tab->scale);
498 yend = -tab->yoff + cv->height - rint(cv->info.y*tab->scale);
499 GDrawSetLineWidth(pixmap,0);
500 GDrawDrawLine(pixmap,x,y,xend,yend,col);
501 }
502
503 static void CVDrawBB(CharView *cv, GWindow pixmap, DBounds *bb) {
504 GRect r;
505 CharViewTab* tab = CVGetActiveTab(cv);
506 int off = tab->xoff+cv->height-tab->yoff;
507
508 r.x = tab->xoff + rint(bb->minx*tab->scale);
509 r.y = -tab->yoff + cv->height - rint(bb->maxy*tab->scale);
510 r.width = rint((bb->maxx-bb->minx)*tab->scale);
511 r.height = rint((bb->maxy-bb->miny)*tab->scale);
512 GDrawSetDashedLine(pixmap,1,1,off);
513 GDrawDrawRect(pixmap,&r,GDrawGetDefaultForeground(NULL));
514 GDrawSetDashedLine(pixmap,0,0,0);
515 }
516
517 /* Draws tangent-style arrows using specified hv/diag arrow sizes */
518 static void DrawTangentPointSized(GWindow pixmap, int x, int y,
519 BasePoint *unit, int outline, Color col,
520 float hv_size, float diag_size) {
521 int dir;
522 const int gp_sz = 4;
523 GPoint gp[5];
524
525 dir = 0;
526 if ( unit->x!=0 || unit->y!=0 ) {
527 float dx = unit->x, dy = unit->y;
528 if ( dx<0 ) dx= -dx;
529 if ( dy<0 ) dy= -dy;
530 if ( dx>2*dy ) {
531 if ( unit->x>0 ) dir = 0 /* right */;
532 else dir = 1 /* left */;
533 } else if ( dy>2*dx ) {
534 if ( unit->y>0 ) dir = 2 /* up */;
535 else dir = 3 /* down */;
536 } else {
537 if ( unit->y>0 && unit->x>0 ) dir=4;
538 else if ( unit->x>0 ) dir=5;
539 else if ( unit->y>0 ) dir=7;
540 else dir = 6;
541 }
542 }
543
544 float sizedelta = hv_size; // horizontal/vertical arrow size
545
546 if( prefs_cvEditHandleSize > prefs_cvEditHandleSize_default )
547 sizedelta *= prefs_cvEditHandleSize / prefs_cvEditHandleSize_default;
548
549 if ( dir==1 /* left */ || dir==0 /* right */) {
550 gp[0].y = y; gp[0].x = (dir==0)?x+sizedelta:x-sizedelta;
551 gp[1].y = y-sizedelta; gp[1].x = x;
552 gp[2].y = y+sizedelta; gp[2].x = x;
553 } else if ( dir==2 /* up */ || dir==3 /* down */ ) {
554 gp[0].x = x; gp[0].y = dir==2?y-sizedelta:y+sizedelta; /* remember screen coordinates are backwards in y from character coords */
555 gp[1].x = x-sizedelta; gp[1].y = y;
556 gp[2].x = x+sizedelta; gp[2].y = y;
557 } else {
558 /* at a 45 angle, a value of 4 looks too small. I probably want 4*1.414 */
559 sizedelta = diag_size; // diagonal arrow size
560 if( prefs_cvEditHandleSize > prefs_cvEditHandleSize_default )
561 sizedelta *= prefs_cvEditHandleSize / prefs_cvEditHandleSize_default;
562 int xdiff = unit->x > 0 ? sizedelta : -1*sizedelta;
563 int ydiff = unit->y > 0 ? -1*sizedelta : sizedelta;
564
565 gp[0].x = x+xdiff/2; gp[0].y = y+ydiff/2;
566 gp[1].x = gp[0].x-xdiff; gp[1].y = gp[0].y;
567 gp[2].x = gp[0].x; gp[2].y = gp[0].y-ydiff;
568 }
569 gp[3] = gp[0];
570 if ( outline )
571 GDrawDrawPoly(pixmap,gp,gp_sz,col);
572 else
573 GDrawFillPoly(pixmap,gp,4,col);
574 }
575
576 // Draws directional arrows for tangent points
577 static void DrawTangentPoint(GWindow pixmap, int x, int y,
578 BasePoint *unit, int outline, Color col) {
579 const int hv_arrow_size = 4;
580 const int diag_arrow_size = 5;
581
582 DrawTangentPointSized(pixmap, x, y, unit, outline, col,
583 hv_arrow_size, diag_arrow_size);
584 }
585
586 /* Convert scale box handle into a fixed arrow direction for drawing */
587 static void CVScaleHandleDirection(enum expandedge edge, BasePoint *unit) {
588 unit->x = edge==ee_nw || edge==ee_sw || edge==ee_left ? -1 :
589 edge==ee_ne || edge==ee_se || edge==ee_right ? 1 : 0;
590 unit->y = edge==ee_sw || edge==ee_se || edge==ee_down ? -1 :
591 edge==ee_nw || edge==ee_ne || edge==ee_up ? 1 : 0;
592 }
593
594 /* Draw scale tool's selection bounds and draggable edge/corner handles */
595 static void CVDrawScaleSelectionBox(CharView *cv, GWindow pixmap) {
596 static enum expandedge edges[] = { ee_nw, ee_up, ee_ne, ee_right, ee_se, ee_down, ee_sw, ee_left };
597 CharViewTab* tab = CVGetActiveTab(cv);
598 DBounds bb;
599 const int scale_handle_hv_arrow_size = 6; // a little larger than tangent arrows
600 const int scale_handle_diag_arrow_size = 8;
601 int i;
602
603 if ( !CVScaleSelectionBounds(cv,&bb) )
604 return;
605 CVDrawBB(cv,pixmap,&bb);
606 for ( i=0; i<sizeof(edges)/sizeof(edges[0]); ++i ) {
607 BasePoint pt, unit;
608 int x, y;
609
610 CVScaleHandlePoint(&bb, edges[i], &pt);
611 CVScaleHandleDirection(edges[i], &unit);
612 x = tab->xoff + rint(pt.x*tab->scale);
613 y = -tab->yoff + cv->height - rint(pt.y*tab->scale);
614 DrawTangentPointSized(pixmap, x, y, &unit, false, GDrawGetDefaultForeground(NULL),
615 scale_handle_hv_arrow_size, scale_handle_diag_arrow_size);
616 }
617 }
618
619 static GRect* DrawPoint_SetupRectForSize( GRect* r, int cx, int cy, float sz )
620 {
621 float sizedelta = sz;
622 if( prefs_cvEditHandleSize > prefs_cvEditHandleSize_default )
623 sizedelta *= prefs_cvEditHandleSize / prefs_cvEditHandleSize_default;
624
625 r->x = cx - sizedelta;
626 r->y = cy - sizedelta;
627 r->width = 1 + sizedelta * 2;
628 r->height = 1 + sizedelta * 2;
629 return r;
630 }
631
632
633 static Color MaybeMaskColorToAlphaChannelOverride( Color c, Color AlphaChannelOverride )
634 {
635 if( AlphaChannelOverride )
636 {
637 c &= 0x00FFFFFF;
638 c |= (AlphaChannelOverride & 0xFF000000);
639 }
640 return c;
641 }
642
643 /*
644 * Format the given real value to .001 precision, discarding trailing
645 * zeroes, and the decimal point if not needed.
646 */
647 static int FmtReal(char *buf, int buflen, real r)
648 {
649 if (buf && buflen > 0) {
650 int ct;
651
652 if ((ct = snprintf(buf, buflen, "%.3f", r)) >= buflen)
653 ct = buflen-1;
654
655 if (strchr(buf, '.')) {
656 while (buf[ct-1] == '0') {
657 --ct;
658 }
659 if (buf[ct-1] == '.') {
660 --ct;
661 }
662 buf[ct] = '\0';
663 }
664 return ct;
665 }
666 return -1;
667 }
668
669 /*
670 * Write the given spline point's coordinates in the form (xxx,yyy)
671 * into the buffer provided, rounding fractions to the nearest .001
672 * and discarding trailing zeroes.
673 */
674 static int SplinePointCoords(char *buf, int buflen, SplinePoint *sp)
675 {
676 if (buf && buflen > 0) {
677 int ct = 0, clen;
678
679 /* 4 chars for parens, comma and trailing NUL, then divide what
680 remains between the two coords */
681 clen = (buflen - 4) / 2;
682 if (clen > 0) {
683 buf[ct++] = '(';
684 ct += FmtReal(buf+ct, clen, sp->me.x);
685 buf[ct++] = ',';
686 ct += FmtReal(buf+ct, clen, sp->me.y);
687 buf[ct++] = ')';
688 }
689 buf[ct] = '\0';
690
691 return ct;
692 }
693 return -1;
694 }
695
696 static void DrawPoint( CharView *cv, GWindow pixmap, SplinePoint *sp,
697 SplineSet *spl, int onlynumber, int truetype_markup,
698 Color AlphaChannelOverride )
699 {
700 GRect r;
701 int x, y, cx, cy;
702 CharViewTab* tab = CVGetActiveTab(cv);
703 Color col = sp==spl->first ? firstpointcol : pointcol;
704 int pnum;
705 char buf[16];
706 int isfake;
707
708 if ( cv->markextrema && SpIsExtremum(sp) && sp!=spl->first )
709 col = extremepointcol;
710 if ( sp->selected )
711 col = selectedpointcol;
712 else {
713 col = col&0x00ffffff;
714 col |= prefs_cvInactiveHandleAlpha << 24;
715 }
716
717 col = MaybeMaskColorToAlphaChannelOverride( col, AlphaChannelOverride );
718 Color subcolmasked;
719 Color nextcpcolmasked = MaybeMaskColorToAlphaChannelOverride( nextcpcol, AlphaChannelOverride );
720 Color prevcpcolmasked = MaybeMaskColorToAlphaChannelOverride( prevcpcol, AlphaChannelOverride );
721 Color selectedpointcolmasked = MaybeMaskColorToAlphaChannelOverride( selectedpointcol, AlphaChannelOverride );
722 Color selectedcpcolmasked = MaybeMaskColorToAlphaChannelOverride( selectedcpcol, AlphaChannelOverride );
723
724 x = tab->xoff + rint(sp->me.x*tab->scale);
725 y = -tab->yoff + cv->height - rint(sp->me.y*tab->scale);
726 if ( x<-4000 || y<-4000 || x>cv->width+4000 || y>=cv->height+4000 )
727 return;
728
729 /* draw the control points if it's selected */
730 if ( sp->selected
731 || cv->showpointnumbers
732 || cv->alwaysshowcontrolpoints
733 || cv->show_ft_results
734 || cv->dv )
735 {
736 if ( !sp->nonextcp ) {
737 cx = tab->xoff + rint(sp->nextcp.x*tab->scale);
738 cy = -tab->yoff + cv->height - rint(sp->nextcp.y*tab->scale);
739 if ( cx<-100 ) { /* Clip */
740 cy = cx==x ? x : (cy-y) * (double)(-100-x)/(cx-x) + y;
741 cx = -100;
742 } else if ( cx>cv->width+100 ) {
743 cy = cx==x ? x : (cy-y) * (double)(cv->width+100-x)/(cx-x) + y;
744 cx = cv->width+100;
745 }
746 if ( cy<-100 ) {
747 cx = cy==y ? y : (cx-x) * (double)(-100-y)/(cy-y) + x;
748 cy = -100;
749 } else if ( cy>cv->height+100 ) {
750 cx = cy==y ? y : (cx-x) * (double)(cv->height+100-y)/(cy-y) + x;
751 cy = cv->height+100;
752 }
753 subcolmasked = nextcpcolmasked;
754
755 //
756 // If the next BCP is selected we should decorate the
757 // drawing to let the user know that. The primary (last)
758 // selected BCP is drawn with a backing rectangle of size
759 // 3, the secondary BCP (2nd, 3rd, 4th last selected BCP)
760 // are drawn with slightly smaller highlights.
761 //
762 if( !onlynumber && SPIsNextCPSelected( sp, cv ))
763 {
764 float sz = 2;
765 if( SPIsNextCPSelectedSingle( sp, cv ))
766 sz *= 1.5;
767
768 DrawPoint_SetupRectForSize( &r, cx, cy, sz );
769 GDrawFillRect(pixmap,&r, nextcpcol);
770 subcolmasked = selectedcpcolmasked;
771 }
772 else if ( truetype_markup )
773 {
774 if ( sp->flexy ) {
775 /* cp is about to be moved (or changed in some other way) */
776 DrawPoint_SetupRectForSize( &r, cx, cy, 3 );
777 GDrawFillRect(pixmap,&r, selectedpointcol);
778 }
779 if ( sp->flexx ) {
780 /* cp is a reference point */
781 DrawPoint_SetupRectForSize( &r, cx, cy, 5 );
782 GDrawDrawElipse(pixmap,&r,selectedpointcol );
783 }
784 }
785 if ( !onlynumber )
786 {
787 float sizedelta = 3;
788 if( prefs_cvEditHandleSize > prefs_cvEditHandleSize_default )
789 sizedelta *= prefs_cvEditHandleSize / prefs_cvEditHandleSize_default;
790 GDrawDrawLine(pixmap,x,y,cx,cy, nextcpcolmasked );
791 GDrawDrawLine(pixmap,cx-sizedelta,cy-sizedelta,cx+sizedelta,cy+sizedelta,subcolmasked);
792 GDrawDrawLine(pixmap,cx+sizedelta,cy-sizedelta,cx-sizedelta,cy+sizedelta,subcolmasked);
793 }
794 if ( cv->showpointnumbers || cv->show_ft_results || cv->dv ) {
795 pnum = sp->nextcpindex;
796 if ( pnum!=0xffff && pnum!=0xfffe ) {
797 if (cv->showpointnumbers == 2)
798 SplinePointCoords( buf, sizeof(buf), sp);
799 else
800 sprintf( buf,"%d", pnum );
801 GDrawDrawText8(pixmap,cx,cy-6,buf,-1,nextcpcol);
802 }
803 }
804 }
805 if ( !sp->noprevcp ) {
806 cx = tab->xoff + rint(sp->prevcp.x*tab->scale);
807 cy = -tab->yoff + cv->height - rint(sp->prevcp.y*tab->scale);
808 if ( cx<-100 ) { /* Clip */
809 cy = cx==x ? x : (cy-y) * (double)(-100-x)/(cx-x) + y;
810 cx = -100;
811 } else if ( cx>cv->width+100 ) {
812 cy = cx==x ? x : (cy-y) * (double)(cv->width+100-x)/(cx-x) + y;
813 cx = cv->width+100;
814 }
815 if ( cy<-100 ) {
816 cx = cy==y ? y : (cx-x) * (double)(-100-y)/(cy-y) + x;
817 cy = -100;
818 } else if ( cy>cv->height+100 ) {
819 cx = cy==y ? y : (cx-x) * (double)(cv->height+100-y)/(cy-y) + x;
820 cy = cv->height+100;
821 }
822 subcolmasked = prevcpcolmasked;
823 if( !onlynumber && SPIsPrevCPSelected( sp, cv ))
824 {
825 float sz = 2;
826 if( SPIsPrevCPSelectedSingle( sp, cv ))
827 sz *= 1.5;
828 DrawPoint_SetupRectForSize( &r, cx, cy, sz );
829 GDrawFillRect(pixmap,&r, prevcpcol);
830 subcolmasked = selectedcpcolmasked;
831 }
832 if ( !onlynumber ) {
833 float sizedelta = 3;
834 if( prefs_cvEditHandleSize > prefs_cvEditHandleSize_default )
835 sizedelta *= prefs_cvEditHandleSize / prefs_cvEditHandleSize_default;
836 GDrawDrawLine(pixmap,x,y,cx,cy, prevcpcolmasked);
837 GDrawDrawLine(pixmap,cx-sizedelta,cy-sizedelta,cx+sizedelta,cy+sizedelta,subcolmasked);
838 GDrawDrawLine(pixmap,cx+sizedelta,cy-sizedelta,cx-sizedelta,cy+sizedelta,subcolmasked);
839 }
840 }
841 }
842
843 if ( x<-4 || y<-4 || x>cv->width+4 || y>=cv->height+4 )
844 return;
845 r.x = x-2;
846 r.y = y-2;
847 r.width = r.height = 0;
848 r.width += prefs_cvEditHandleSize;
849 r.height += prefs_cvEditHandleSize;
850 if ( sp->selected )
851 GDrawSetLineWidth(pixmap,selectedpointwidth);
852 isfake = false;
853 if ( cv->b.layerheads[cv->b.drawmode]->order2 &&
854 cv->b.layerheads[cv->b.drawmode]->refs==NULL )
855 {
856 int mightbe_fake = SPInterpolate(sp);
857 if ( !mightbe_fake && sp->ttfindex==0xffff )
858 sp->ttfindex = 0xfffe; /* if we have no instructions we won't call instrcheck and won't notice when a point stops being fake */
859 else if ( mightbe_fake )
860 sp->ttfindex = 0xffff;
861 isfake = sp->ttfindex==0xffff;
862 }
863 if ( onlynumber )
864 {
865 /* Draw Nothing */;
866 }
867 else if ( sp->pointtype==pt_curve )
868 {
869 r.width +=2; r.height += 2;
870 r.x = x - r.width / 2;
871 r.y = y - r.height / 2;
872 if ( sp->selected || isfake )
873 GDrawDrawElipse(pixmap,&r,col);
874 else
875 GDrawFillElipse(pixmap,&r,col);
876 }
877 else if ( sp->pointtype==pt_corner )
878 {
879 r.x = x - r.width / 2;
880 r.y = y - r.height / 2;
881 if ( sp->selected || isfake )
882 GDrawDrawRect(pixmap,&r,col);
883 else
884 GDrawFillRect(pixmap,&r,col);
885 }
886 else if ( sp->pointtype==pt_hvcurve )
887 {
888 const int gp_sz = 5;
889 GPoint gp[5];
890
891 float sizedelta = 3;
892 float offsetdelta = 0; // 4 * tab->scale;
893 if( prefs_cvEditHandleSize > prefs_cvEditHandleSize_default )
894 {
895 sizedelta *= prefs_cvEditHandleSize / prefs_cvEditHandleSize_default;
896 offsetdelta *= prefs_cvEditHandleSize / prefs_cvEditHandleSize_default;
897 }
898
899 float basex = r.x + 3 + offsetdelta;
900 float basey = r.y + 3 + offsetdelta;
901 gp[0].x = basex - sizedelta; gp[0].y = basey + 0;
902 gp[1].x = basex + 0; gp[1].y = basey + sizedelta;
903 gp[2].x = basex + sizedelta; gp[2].y = basey + 0;
904 gp[3].x = basex + 0; gp[3].y = basey - sizedelta;
905 gp[4] = gp[0];
906
907 if ( sp->selected || isfake )
908 GDrawDrawPoly(pixmap,gp,gp_sz,col);
909 else
910 GDrawFillPoly(pixmap,gp,gp_sz,col);
911 }
912 else
913 {
914 BasePoint *cp=NULL;
915 BasePoint unit;
916
917 if ( !sp->nonextcp )
918 cp = &sp->nextcp;
919 else if ( !sp->noprevcp )
920 cp = &sp->prevcp;
921 memset(&unit,0,sizeof(unit));
922 if ( cp!=NULL ) {
923 unit.x = cp->x-sp->me.x; unit.y = cp->y-sp->me.y;
924 }
925 DrawTangentPoint(pixmap, x, y, &unit, sp->selected || isfake, col);
926 }
927 GDrawSetLineWidth(pixmap,0);
928 if ( (cv->showpointnumbers || cv->show_ft_results || cv->dv )
929 && sp->ttfindex!=0xffff )
930 {
931 if ( sp->ttfindex==0xfffe )
932 strcpy(buf,"??");
933 else if (cv->showpointnumbers == 2)
934 SplinePointCoords(buf, sizeof(buf), sp);
935 else
936 sprintf( buf,"%d", sp->ttfindex );
937 GDrawDrawText8(pixmap,x,y-6,buf,-1,col);
938 }
939 if ( truetype_markup && sp->roundx ) {
940 r.x = x-5; r.y = y-5;
941 r.width = r.height = 11;
942 GDrawDrawElipse(pixmap,&r,selectedpointcolmasked);
943 } else if ( !onlynumber && !truetype_markup ) {
944 if ((( sp->roundx || sp->roundy ) &&
945 (((cv->showrounds&1) && tab->scale>=.3) || (cv->showrounds&2))) ||
946 (sp->watched && cv->dv!=NULL) ||
947 sp->hintmask!=NULL ) {
948 r.x = x-5; r.y = y-5;
949 r.width = r.height = 11;
950 GDrawDrawElipse(pixmap,&r,col);
951 }
952 if (( sp->flexx && cv->showhhints ) || (sp->flexy && cv->showvhints)) {
953 r.x = x-5; r.y = y-5;
954 r.width = r.height = 11;
955 GDrawDrawElipse(pixmap,&r,
956 MaybeMaskColorToAlphaChannelOverride( sp->flexx ? hflexhintcol : vflexhintcol,
957 AlphaChannelOverride ));
958 }
959 }
960 }
961
962 static void DrawSpiroPoint( CharView *cv, GWindow pixmap, spiro_cp *cp,
963 SplineSet *spl, int cp_i, Color AlphaChannelOverride )
964 {
965 CharViewTab* tab = CVGetActiveTab(cv);
966 GRect r;
967 int x, y;
968 Color col = cp==&spl->spiros[0] ? firstpointcol : pointcol;
969 char ty = cp->ty&0x7f;
970 int selected = SPIRO_SELECTED(cp);
971 GPoint gp[5];
972
973 if ( selected )
974 col = selectedpointcol;
975
976 if( !selected )
977 {
978 col = col & 0x00ffffff;
979 col |= prefs_cvInactiveHandleAlpha << 24;
980 }
981
982 col = MaybeMaskColorToAlphaChannelOverride( col, AlphaChannelOverride );
983
984
985 x = tab->xoff + rint(cp->x*tab->scale);
986 y = -tab->yoff + cv->height - rint(cp->y*tab->scale);
987 if ( x<-4 || y<-4 || x>cv->width+4 || y>=cv->height+4 )
988 return;
989
990 DrawPoint_SetupRectForSize( &r, x, y, 2 );
991 /* r.x = x-2; */
992 /* r.y = y-2; */
993 /* r.width = r.height = 5; */
994 if ( selected )
995 GDrawSetLineWidth(pixmap,selectedpointwidth);
996
997 float sizedelta = 3;
998 if( prefs_cvEditHandleSize > prefs_cvEditHandleSize_default )
999 sizedelta *= prefs_cvEditHandleSize / prefs_cvEditHandleSize_default;
1000
1001 if ( ty == SPIRO_RIGHT ) {
1002 GDrawSetLineWidth(pixmap,2);
1003 gp[0].x = x-sizedelta; gp[0].y = y-sizedelta;
1004 gp[1].x = x; gp[1].y = y-sizedelta;
1005 gp[2].x = x; gp[2].y = y+sizedelta;
1006 gp[3].x = x-sizedelta; gp[3].y = y+sizedelta;
1007 GDrawDrawPoly(pixmap,gp,4,col);
1008 } else if ( ty == SPIRO_LEFT ) {
1009 GDrawSetLineWidth(pixmap,2);
1010 gp[0].x = x+sizedelta; gp[0].y = y-sizedelta;
1011 gp[1].x = x; gp[1].y = y-sizedelta;
1012 gp[2].x = x; gp[2].y = y+sizedelta;
1013 gp[3].x = x+sizedelta; gp[3].y = y+sizedelta;
1014 GDrawDrawPoly(pixmap,gp,4,col);
1015 } else if ( ty == SPIRO_G2 ) {
1016 GPoint gp[5];
1017
1018 float sizedelta = 3;
1019 float offsetdelta = 1;
1020 if( prefs_cvEditHandleSize > prefs_cvEditHandleSize_default )
1021 {
1022 sizedelta *= prefs_cvEditHandleSize / prefs_cvEditHandleSize_default;
1023 offsetdelta *= prefs_cvEditHandleSize / prefs_cvEditHandleSize_default;
1024 }
1025
1026 float basex = r.x + 1 + offsetdelta;
1027 float basey = r.y + 1 + offsetdelta;
1028 gp[0].x = basex - sizedelta; gp[0].y = basey + 0;
1029 gp[1].x = basex + 0; gp[1].y = basey + sizedelta;
1030 gp[2].x = basex + sizedelta; gp[2].y = basey + 0;
1031 gp[3].x = basex + 0; gp[3].y = basey - sizedelta;
1032 gp[4] = gp[0];
1033 if ( selected )
1034 GDrawDrawPoly(pixmap,gp,5,col);
1035 else
1036 GDrawFillPoly(pixmap,gp,5,col);
1037 } else if ( ty==SPIRO_CORNER ) {
1038 if ( selected )
1039 GDrawDrawRect(pixmap,&r,col);
1040 else
1041 GDrawFillRect(pixmap,&r,col);
1042 } else {
1043 --r.x; --r.y; r.width +=2; r.height += 2;
1044 if ( selected )
1045 GDrawDrawElipse(pixmap,&r,col);
1046 else
1047 GDrawFillElipse(pixmap,&r,col);
1048 }
1049 GDrawSetLineWidth(pixmap,0);
1050 }
1051
1052 static void DrawLine(CharView *cv, GWindow pixmap,
1053 real x1, real y1, real x2, real y2, Color fg) {
1054 CharViewTab* tab = CVGetActiveTab(cv);
1055 int ix1 = tab->xoff + rint(x1*tab->scale);
1056 int iy1 = -tab->yoff + cv->height - rint(y1*tab->scale);
1057 int ix2 = tab->xoff + rint(x2*tab->scale);
1058 int iy2 = -tab->yoff + cv->height - rint(y2*tab->scale);
1059 if ( iy1==iy2 ) {
1060 if ( iy1<0 || iy1>cv->height )
1061 return;
1062 if ( ix1<0 ) ix1 = 0;
1063 if ( ix2>cv->width ) ix2 = cv->width;
1064 } else if ( ix1==ix2 ) {
1065 if ( ix1<0 || ix1>cv->width )
1066 return;
1067 if ( iy1<0 ) iy1 = 0;
1068 if ( iy2<0 ) iy2 = 0;
1069 if ( iy1>cv->height ) iy1 = cv->height;
1070 if ( iy2>cv->height ) iy2 = cv->height;
1071 }
1072 GDrawDrawLine(pixmap, ix1,iy1, ix2,iy2, fg );
1073 }
1074
1075 static void DrawDirection(CharView *cv,GWindow pixmap, SplinePoint *sp) {
1076 BasePoint dir, *other;
1077 double len;
1078 CharViewTab* tab = CVGetActiveTab(cv);
1079 int x,y,xe,ye;
1080 SplinePoint *test;
1081
1082 if ( sp->next==NULL )
1083 return;
1084
1085 x = tab->xoff + rint(sp->me.x*tab->scale);
1086 y = -tab->yoff + cv->height - rint(sp->me.y*tab->scale);
1087 if ( x<0 || y<0 || x>cv->width || y>cv->width )
1088 return;
1089
1090 /* Werner complained when the first point and the second point were at */
1091 /* the same location... */ /* Damn. They weren't at the same location */
1092 /* the were off by a rounding error. I'm not going to fix for that */
1093 for ( test=sp; ; ) {
1094 if ( test->me.x!=sp->me.x || test->me.y!=sp->me.y ) {
1095 other = &test->me;
1096 break;
1097 } else if ( !test->nonextcp ) {
1098 other = &test->nextcp;
1099 break;
1100 }
1101 if ( test->next==NULL )
1102 return;
1103 test = test->next->to;
1104 if ( test==sp )
1105 return;
1106 }
1107
1108 dir.x = other->x-sp->me.x;
1109 dir.y = sp->me.y-other->y; /* screen coordinates are the mirror of user coords */
1110 len = sqrt(dir.x*dir.x + dir.y*dir.y);
1111 dir.x /= len; dir.y /= len;
1112
1113 x += rint(5*dir.y);
1114 y -= rint(5*dir.x);
1115 xe = x + rint(7*dir.x);
1116 ye = y + rint(7*dir.y);
1117 GDrawDrawLine(pixmap,x,y,xe,ye,firstpointcol);
1118 GDrawDrawLine(pixmap,xe,ye,xe+rint(2*(dir.y-dir.x)),ye+rint(2*(-dir.y-dir.x)), firstpointcol);
1119 GDrawDrawLine(pixmap,xe,ye,xe+rint(2*(-dir.y-dir.x)),ye+rint(2*(dir.x-dir.y)), firstpointcol);
1120 }
1121
1122 static void CVMarkInterestingLocations(CharView *cv, GWindow pixmap,
1123 SplinePointList *spl) {
1124 Spline *s, *first;
1125 extended interesting[6];
1126 CharViewTab* tab = CVGetActiveTab(cv);
1127 int i, ecnt, cnt;
1128 GRect r;
1129
1130 for ( s=spl->first->next, first=NULL; s!=NULL && s!=first; s=s->to->next ) {
1131 if ( first==NULL ) first = s;
1132 cnt = ecnt = 0;
1133 if ( cv->markextrema )
1134 ecnt = cnt = Spline2DFindExtrema(s,interesting);
1135
1136 if ( cv->markpoi ) {
1137 cnt += Spline2DFindPointsOfInflection(s,interesting+cnt);
1138 }
1139 r.width = r.height = 9;
1140 for ( i=0; i<cnt; ++i ) if ( interesting[i]>0 && interesting[i]<1.0 ) {
1141 Color col = i<ecnt ? extremepointcol : pointofinflectioncol;
1142 double x = ((s->splines[0].a*interesting[i]+s->splines[0].b)*interesting[i]+s->splines[0].c)*interesting[i]+s->splines[0].d;
1143 double y = ((s->splines[1].a*interesting[i]+s->splines[1].b)*interesting[i]+s->splines[1].c)*interesting[i]+s->splines[1].d;
1144 double sx = tab->xoff + rint(x*tab->scale);
1145 double sy = -tab->yoff + cv->height - rint(y*tab->scale);
1146 if ( sx<-5 || sy<-5 || sx>10000 || sy>10000 )
1147 continue;
1148 GDrawDrawLine(pixmap,sx-4,sy,sx+4,sy, col);
1149 GDrawDrawLine(pixmap,sx,sy-4,sx,sy+4, col);
1150 r.x = sx-4; r.y = sy-4;
1151 GDrawDrawElipse(pixmap,&r,col);
1152 }
1153 }
1154 }
1155
1156 static void CVMarkAlmostHV(CharView *cv, GWindow pixmap,
1157 SplinePointList *spl) {
1158 Spline *s, *first;
1159 double dx, dy;
1160 int x1,x2,y1,y2;
1161 CharViewTab* tab = CVGetActiveTab(cv);
1162
1163 for ( s=spl->first->next, first=NULL; s!=NULL && s!=first; s=s->to->next ) {
1164 if ( first==NULL ) first = s;
1165
1166 if ( s->islinear ) {
1167 if ( !cv->showalmosthvlines )
1168 continue;
1169 if ( (dx = s->from->me.x - s->to->me.x)<0 ) dx = -dx;
1170 if ( (dy = s->from->me.y - s->to->me.y)<0 ) dy = -dy;
1171 if ( dx<=cv->hvoffset && dy<=cv->hvoffset )
1172 continue;
1173 if ( dx==0 || dy==0 )
1174 continue;
1175 if ( dx<cv->hvoffset || dy<cv->hvoffset ) {
1176 x1 = tab->xoff + rint(s->from->me.x*tab->scale);
1177 y1 = -tab->yoff + cv->height - rint(s->from->me.y*tab->scale);
1178 x2 = tab->xoff + rint(s->to->me.x*tab->scale);
1179 y2 = -tab->yoff + cv->height - rint(s->to->me.y*tab->scale);
1180 GDrawDrawLine(pixmap,x1,y1,x2,y2,almosthvcol);
1181 }
1182 } else {
1183 if ( !cv->showalmosthvcurves )
1184 continue;
1185 if ( (dx = s->from->me.x - s->from->nextcp.x)<0 ) dx = -dx;
1186 if ( (dy = s->from->me.y - s->from->nextcp.y)<0 ) dy = -dy;
1187 if ( dx<=cv->hvoffset && dy<=cv->hvoffset )
1188 /* Ignore */;
1189 else if ( dx==0 || dy==0 )
1190 /* It's right */;
1191 else if ( dx<cv->hvoffset || dy<cv->hvoffset ) {
1192 x2 = x1 = tab->xoff + rint(s->from->me.x*tab->scale);
1193 y2 = y1 = -tab->yoff + cv->height - rint(s->from->me.y*tab->scale);
1194 if ( dx<cv->hvoffset ) {
1195 if ( s->from->me.y<s->from->nextcp.y )
1196 y2 += 15;
1197 else
1198 y2 -= 15;
1199 } else {
1200 if ( s->from->me.x<s->from->nextcp.x )
1201 x2 += 15;
1202 else
1203 x2 -= 15;
1204 }
1205 GDrawDrawLine(pixmap,x1,y1,x2,y2,almosthvcol);
1206 }
1207
1208 if ( (dx = s->to->me.x - s->to->prevcp.x)<0 ) dx = -dx;
1209 if ( (dy = s->to->me.y - s->to->prevcp.y)<0 ) dy = -dy;
1210 if ( dx<=cv->hvoffset && dy<=cv->hvoffset )
1211 /* Ignore */;
1212 else if ( dx==0 || dy==0 )
1213 /* It's right */;
1214 else if ( dx<cv->hvoffset || dy<cv->hvoffset ) {
1215 x2 = x1 = tab->xoff + rint(s->to->me.x*tab->scale);
1216 y2 = y1 = -tab->yoff + cv->height - rint(s->to->me.y*tab->scale);
1217 if ( dx<cv->hvoffset ) {
1218 if ( s->to->me.y<s->to->prevcp.y )
1219 y2 += 15;
1220 else
1221 y2 -= 15;
1222 } else {
1223 if ( s->to->me.x<s->to->prevcp.x )
1224 x2 += 15;
1225 else
1226 x2 -= 15;
1227 }
1228 GDrawDrawLine(pixmap,x1,y1,x2,y2,almosthvcol);
1229 }
1230 }
1231 }
1232 }
1233
1234 static void CVDrawPointName(CharView *cv, GWindow pixmap, SplinePoint *sp, Color fg)
1235 {
1236 CharViewTab* tab = CVGetActiveTab(cv);
1237 if (sp->name && *sp->name) {
1238 int32_t theight;
1239
1240 GDrawSetFont(pixmap, cv->normal);
1241 theight = GDrawGetText8Height(pixmap, sp->name, -1);
1242 GDrawDrawText8(pixmap,
1243 tab->xoff + rint(sp->me.x*tab->scale),
1244 cv->height-tab->yoff - rint(sp->me.y*tab->scale) + theight + 3,
1245 sp->name,-1,fg);
1246 GDrawSetFont(pixmap,cv->small); /* For point numbers */
1247 }
1248 }
1249
1250 static void CVDrawContourName(CharView *cv, GWindow pixmap, SplinePointList *ss,
1251 Color fg ) {
1252 SplinePoint *sp, *topright;
1253 GPoint tr;
1254 CharViewTab* tab = CVGetActiveTab(cv);
1255
1256 /* Find the top right point of the contour. This is where we will put the */
1257 /* label */
1258 for ( sp = topright = ss->first; ; ) {
1259 if ( sp->me.y>topright->me.y || (sp->me.y==topright->me.y && sp->me.x>topright->me.x) )
1260 topright = sp;
1261 if ( sp->next==NULL )
1262 break;
1263 sp = sp->next->to;
1264 if ( sp==ss->first )
1265 break;
1266 }
1267 tr.x = tab->xoff + rint(topright->me.x*tab->scale);
1268 tr.y = cv->height-tab->yoff - rint(topright->me.y*tab->scale);
1269
1270 /* If the top edge of the contour is off the bottom of the screen */
1271 /* then the contour won't show */
1272 if ( tr.y>cv->height )
1273 return;
1274
1275 GDrawSetFont(pixmap,cv->normal);
1276
1277 if ( ss->first->prev==NULL && ss->first->next!=NULL &&
1278 ss->first->next->to->next==NULL && ss->first->next->knownlinear &&
1279 (tr.y < cv->nfh || tr.x>cv->width-cv->nfh) ) {
1280 /* It's a simple line */
1281 /* A special case because: It's common, and it's important to get it */
1282 /* right and label lines even if the point to which we'd normally */
1283 /* attach a label is offscreen */
1284 SplinePoint *sp1 = ss->first, *sp2 = ss->first->next->to;
1285 double dx, dy, slope, off, yinter, xinter;
1286
1287 if ( (dx = sp1->me.x-sp2->me.x)<0 ) dx = -dx;
1288 if ( (dy = sp1->me.y-sp2->me.y)<0 ) dy = -dy;
1289 if ( dx==0 ) {
1290 /* Vertical line */
1291 tr.y = cv->nfh;
1292 tr.x += 2;
1293 } else if ( dy==0 ) {
1294 /* Horizontal line */
1295 tr.x = cv->width - cv->nfh - GDrawGetText8Width(pixmap,ss->contour_name,-1);
1296 } else {
1297 /* y = slope*x + off; */
1298 slope = (sp1->me.y-sp2->me.y)/(sp1->me.x-sp2->me.x);
1299 off = sp1->me.y - slope*sp1->me.x;
1300 /* Now translate to screen coords */
1301 off = (cv->height-tab->yoff)+slope*tab->xoff - tab->scale*off;
1302 slope = -slope;
1303 xinter = (0-off)/slope;
1304 yinter = slope*cv->width + off;
1305 if ( xinter>0 && xinter<cv->width ) {
1306 tr.x = xinter+2;
1307 tr.y = cv->nfh;
1308 } else if ( yinter>0 && yinter<cv->height ) {
1309 tr.x = cv->width - cv->nfh - GDrawGetText8Width(pixmap,ss->contour_name,-1);
1310 tr.y = yinter;
1311 }
1312 }
1313 } else {
1314 tr.y -= cv->nfh/2;
1315 tr.x -= GDrawGetText8Width(pixmap,ss->contour_name,-1)/2;
1316 }
1317
1318 GDrawDrawText8(pixmap,tr.x,tr.y,ss->contour_name,-1,fg);
1319 GDrawSetFont(pixmap,cv->small); /* For point numbers */
1320 }
1321
1322 void CVDrawSplineSet(CharView *cv, GWindow pixmap, SplinePointList *set,
1323 Color fg, int dopoints, DRect *clip ) {
1324 CVDrawSplineSetSpecialized( cv, pixmap, set, fg, dopoints, clip,
1325 sfm_stroke, 0 );
1326 }
1327
1328
1329 void CVDrawSplinePointList(CharView *cv, GWindow pixmap, SplinePointList *set, Color fg,
1330 enum outlinesfm_flags strokeFillMode, float xoff, float yoff, real scale)
1331 {
1332 SplinePointList *spl;
1333 int height = 0;
1334 for (spl = set; spl != NULL; spl = spl->next)
1335 {
1336 Color fc = spl->is_clip_path ? clippathcol : fg;
1337 /**
1338 * Only make the outline red if this is not a grid layer
1339 * and we want to highlight open paths
1340 * and the activelayer is sane
1341 * and the activelayer contains the given splinepointlist
1342 * and the path is open
1343 */
1344 if (cv)
1345 {
1346 int activelayer = CVLayer(&cv->b);
1347 height = cv->height;
1348 if (cv->b.drawmode != dm_grid && DrawOpenPathsWithHighlight &&
1349 activelayer < cv->b.sc->layer_cnt && activelayer >= 0 &&
1350 SplinePointListContains(cv->b.sc->layers[activelayer].splines, spl) && spl->first &&
1351 spl->first->prev == NULL)
1352 {
1353 if (GDrawGetLineWidth(pixmap) <= 1)
1354 fc = openpathcol | 0xff000000;
1355 else
1356 fc = openpathcol;
1357 }
1358 }
1359
1360 Spline *first, *spline;
1361 double x, y, cx1, cy1, cx2, cy2, dx, dy;
1362 GDrawPathStartSubNew(pixmap);
1363 x = rpt(cv, xoff + spl->first->me.x * scale);
1364 y = rpt(cv, yoff + height - spl->first->me.y * scale);
1365 GDrawPathMoveTo(pixmap, x + .5, y + .5);
1366 for (spline = spl->first->next, first = NULL; spline != first && spline != NULL;
1367 spline = spline->to->next)
1368 {
1369 x = rpt(cv, xoff + spline->to->me.x * scale);
1370 y = rpt(cv, yoff + height - spline->to->me.y * scale);
1371 if (spline->knownlinear)
1372 GDrawPathLineTo(pixmap, x + .5, y + .5);
1373 else if (spline->order2)
1374 {
1375 dx = rint(spline->from->me.x * scale) - spline->from->me.x * scale;
1376 dy = rint(spline->from->me.y * scale) - spline->from->me.y * scale;
1377 cx1 = spline->from->me.x + spline->splines[0].c / 3;
1378 cy1 = spline->from->me.y + spline->splines[1].c / 3;
1379 cx2 = cx1 + (spline->splines[0].b + spline->splines[0].c) / 3;
1380 cy2 = cy1 + (spline->splines[1].b + spline->splines[1].c) / 3;
1381 cx1 = xoff + cx1 * scale + dx;
1382 cy1 = yoff + height - cy1 * scale - dy;
1383 dx = rint(spline->to->me.x * scale) - spline->to->me.x * scale;
1384 dy = rint(spline->to->me.y * scale) - spline->to->me.y * scale;
1385 cx2 = xoff + cx2 * scale + dx;
1386 cy2 = yoff + height - cy2 * scale - dy;
1387 GDrawPathCurveTo(pixmap, cx1 + .5, cy1 + .5, cx2 + .5, cy2 + .5, x + .5,
1388 y + .5);
1389 }
1390 else
1391 {
1392 dx = rint(spline->from->me.x * scale) - spline->from->me.x * scale;
1393 dy = rint(spline->from->me.y * scale) - spline->from->me.y * scale;
1394 cx1 = xoff + spline->from->nextcp.x * scale + dx;
1395 cy1 = yoff + height - spline->from->nextcp.y * scale - dy;
1396 dx = rint(spline->to->me.x * scale) - spline->to->me.x * scale;
1397 dy = rint(spline->to->me.y * scale) - spline->to->me.y * scale;
1398 cx2 = xoff + spline->to->prevcp.x * scale + dx;
1399 cy2 = yoff + height - spline->to->prevcp.y * scale - dy;
1400 GDrawPathCurveTo(pixmap, cx1 + .5, cy1 + .5, cx2 + .5, cy2 + .5, x + .5,
1401 y + .5);
1402 }
1403 if (first == NULL)
1404 first = spline;
1405 }
1406 if (spline != NULL)
1407 GDrawPathClose(pixmap);
1408
1409 switch (strokeFillMode)
1410 {
1411 case sfm_stroke_trans:
1412 GDrawPathStroke(pixmap, fc);
1413 break;
1414 case sfm_stroke:
1415 GDrawPathStroke(pixmap, fc | 0xff000000);
1416 break;
1417 case sfm_clip:
1418 case sfm_fill:
1419 case sfm_nothing:
1420 break;
1421 }
1422 }
1423 }
1424
1425 void CVDrawSplineSetOutlineOnly(CharView *cv, GWindow pixmap, SplinePointList *set,
1426 Color fg, int dopoints, DRect *clip, enum outlinesfm_flags strokeFillMode ) {
1427 CharViewTab* tab = CVGetActiveTab(cv);
1428
1429 if( strokeFillMode == sfm_fill ) {
1430 GDrawFillRuleSetWinding(pixmap);
1431 }
1432
1433 CVDrawSplinePointList(cv, pixmap, set, fg, strokeFillMode, tab->xoff, -tab->yoff, tab->scale);
1434
1435 if (strokeFillMode == sfm_clip) {
1436 // Really only cairo_clip needs to be called
1437 // But then I'd have to change the GDraw interface, ew...
1438 GDrawClipPreserve( pixmap );
1439 GDrawPathStartNew( pixmap );
1440 } else if (strokeFillMode == sfm_fill) {
1441 if ( cv->inPreviewMode )
1442 GDrawPathFill(pixmap, previewfillcol|0xff000000);
1443 else
1444 GDrawPathFill(pixmap, fillcol);
1445 }
1446 }
1447
1448
1449
1450 void CVDrawSplineSetSpecialized( CharView *cv, GWindow pixmap, SplinePointList *set,
1451 Color fg, int dopoints, DRect *clip,
1452 enum outlinesfm_flags strokeFillMode,
1453 Color AlphaChannelOverride )
1454 {
1455 Spline *spline, *first;
1456 SplinePointList *spl;
1457 int truetype_markup = set==cv->b.gridfit && cv->dv!=NULL;
1458 CharViewTab* tab = CVGetActiveTab(cv);
1459
1460 if ( cv->inactive )
1461 dopoints = false;
1462
1463 if( strokeFillMode == sfm_fill ) {
1464 CVDrawSplineSetOutlineOnly( cv, pixmap, set,
1465 fg, dopoints, clip, strokeFillMode );
1466 }
1467
1468 GDrawSetFont(pixmap,cv->small); /* For point numbers */
1469 for ( spl = set; spl!=NULL; spl = spl->next ) {
1470 if ( spl->contour_name!=NULL )
1471 CVDrawContourName(cv,pixmap,spl,fg);
1472 if ( dopoints>0 || (dopoints==-1 && cv->showpointnumbers) ) {
1473 first = NULL;
1474 if ( dopoints>0 )
1475 DrawDirection(cv,pixmap,spl->first);
1476 if ( cv->b.sc->inspiro && hasspiro()) {
1477 if ( dopoints>=0 ) {
1478 int i;
1479 if ( spl->spiros==NULL ) {
1480 spl->spiros = SplineSet2SpiroCP(spl,&spl->spiro_cnt);
1481 spl->spiro_max = spl->spiro_cnt;
1482 }
1483 for ( i=0; i<spl->spiro_cnt-1; ++i )
1484 DrawSpiroPoint(cv,pixmap,&spl->spiros[i],spl,i, AlphaChannelOverride );
1485 }
1486 } else {
1487 for ( spline = spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next ) {
1488 DrawPoint(cv,pixmap,spline->from,spl,dopoints<0,truetype_markup, AlphaChannelOverride );
1489 CVDrawPointName(cv,pixmap,spline->from,fg);
1490 if ( first==NULL ) first = spline;
1491 }
1492 if ( spline==NULL ) {
1493 DrawPoint(cv,pixmap,spl->last,spl,dopoints<0,truetype_markup, AlphaChannelOverride );
1494 CVDrawPointName(cv,pixmap,spl->last,fg);
1495 }
1496 }
1497 }
1498 }
1499
1500 if( strokeFillMode != sfm_nothing ) {
1501 /*
1502 * If we were filling, we have to stroke the outline again to properly show
1503 * clip path splines which will possibly have a different stroke color
1504 */
1505 Color thinfgcolor = fg;
1506 enum outlinesfm_flags fgstrokeFillMode = sfm_stroke;
1507 if( strokeFillMode==sfm_stroke_trans )
1508 fgstrokeFillMode = sfm_stroke_trans;
1509 if( cv->showfilled ) {
1510 if (cv->inPreviewMode)
1511 thinfgcolor = (thinfgcolor | 0x01000000) & 0x01ffffff;
1512 fgstrokeFillMode = sfm_stroke_trans;
1513 }
1514 CVDrawSplineSetOutlineOnly( cv, pixmap, set,
1515 thinfgcolor, dopoints, clip,
1516 fgstrokeFillMode );
1517
1518 if( prefs_cv_outline_thickness > 1 )
1519 {
1520 // we only draw the inner half, so we double the user's expected
1521 // thickness here.
1522 int strokeWidth = prefs_cv_outline_thickness * 2 * tab->scale;
1523 Color strokefg = foreoutthicklinecol;
1524
1525 if( cv->showfilled && cv->inPreviewMode ) {
1526 strokefg = (strokefg | 0x01000000) & 0x01ffffff;
1527 }
1528
1529 int16_t oldwidth = GDrawGetLineWidth( pixmap );
1530 GDrawSetLineWidth( pixmap, strokeWidth );
1531 GDrawPushClipOnly( pixmap );
1532
1533 CVDrawSplineSetOutlineOnly( cv, pixmap, set,
1534 strokefg, dopoints, clip,
1535 sfm_clip );
1536 CVDrawSplineSetOutlineOnly( cv, pixmap, set,
1537 strokefg, dopoints, clip,
1538 sfm_stroke_trans );
1539
1540 GDrawPopClip( pixmap, NULL );
1541 GDrawSetLineWidth( pixmap, oldwidth );
1542 }
1543 }
1544
1545 for ( spl = set; spl!=NULL; spl = spl->next ) {
1546 if (( cv->markextrema || cv->markpoi ) && dopoints && !cv->b.sc->inspiro )
1547 CVMarkInterestingLocations(cv,pixmap,spl);
1548 if ( (cv->showalmosthvlines || cv->showalmosthvcurves ) && dopoints )
1549 CVMarkAlmostHV(cv,pixmap,spl);
1550 }
1551 }
1552
1553 static void CVDrawLayerSplineSet(CharView *cv, GWindow pixmap, Layer *layer,
1554 Color fg, int dopoints, DRect *clip, enum outlinesfm_flags strokeFillMode ) {
1555 CharViewTab* tab = CVGetActiveTab(cv);
1556 int active = cv->b.layerheads[cv->b.drawmode]==layer;
1557 int ml = cv->b.sc->parent->multilayer;
1558
1559 if ( ml && layer->dostroke ) {
1560 if ( layer->stroke_pen.brush.col!=COLOR_INHERITED &&
1561 layer->stroke_pen.brush.col!=view_bgcol )
1562 fg = layer->stroke_pen.brush.col;
1563 }
1564 if ( ml && layer->dofill ) {
1565 if ( layer->fill_brush.col!=COLOR_INHERITED &&
1566 layer->fill_brush.col!=view_bgcol )
1567 fg = layer->fill_brush.col;
1568 }
1569
1570 if ( ml && !active && layer!=&cv->b.sc->layers[ly_back] )
1571 GDrawSetDashedLine(pixmap,5,5,tab->xoff+cv->height-tab->yoff);
1572
1573 CVDrawSplineSetSpecialized( cv, pixmap, layer->splines,
1574 fg, dopoints && active, clip,
1575 strokeFillMode, 0 );
1576
1577 if ( ml && !active && layer!=&cv->b.sc->layers[ly_back] )
1578 GDrawSetDashedLine(pixmap,0,0,0);
1579 }
1580
1581 static void CVDrawTemplates(CharView *cv,GWindow pixmap,SplineChar *template,DRect *clip) {
1582 RefChar *r;
1583
1584 CVDrawSplineSet(cv,pixmap,template->layers[ly_fore].splines,templateoutlinecol,false,clip);
1585 for ( r=template->layers[ly_fore].refs; r!=NULL; r=r->next )
1586 CVDrawSplineSet(cv,pixmap,r->layers[0].splines,templateoutlinecol,false,clip);
1587 }
1588
1589 static void CVShowDHintInstance(CharView *cv, GWindow pixmap, BasePoint *bp) {
1590 IPoint ip[40], ip2[40];
1591 GPoint clipped[13];
1592 int i,j, tot,last;
1593 CharViewTab* tab = CVGetActiveTab(cv);
1594
1595 ip[0].x = tab->xoff + rint( bp[0].x*tab->scale );
1596 ip[0].y = -tab->yoff + cv->height - rint( bp[0].y*tab->scale );
1597 ip[1].x = tab->xoff + rint(bp[1].x*tab->scale);
1598 ip[1].y = -tab->yoff + cv->height - rint( bp[1].y*tab->scale );
1599 ip[2].x = tab->xoff + rint( bp[2].x*tab->scale );
1600 ip[2].y = -tab->yoff + cv->height - rint( bp[2].y*tab->scale );
1601 ip[3].x = tab->xoff + rint( bp[3].x*tab->scale );
1602 ip[3].y = -tab->yoff + cv->height - rint( bp[3].y*tab->scale );
1603
1604 if (( ip[0].x<0 && ip[1].x<0 && ip[2].x<0 && ip[3].x<0 ) ||
1605 ( ip[0].x>=cv->width && ip[1].x>=cv->width && ip[2].x>=cv->width && ip[3].x>=cv->width ) ||
1606 ( ip[0].y<0 && ip[1].y<0 && ip[2].y<0 && ip[3].y<0 ) ||
1607 ( ip[0].y>=cv->height && ip[1].y>=cv->height && ip[2].y>=cv->height && ip[3].y>=cv->height ))
1608 return; /* Offscreen */
1609
1610 /* clip to left edge */
1611 tot = 4;
1612 for ( i=j=0; i<tot; ++i ) {
1613 last = i==0?tot-1:i-1;
1614 if ( ip[i].x>=0 && ip[last].x>=0) {
1615 ip2[j++] = ip[i];
1616 } else if ( ip[i].x<0 && ip[last].x<0 ) {
1617 if ( j==0 || ip2[j-1].x!=0 || ip2[j-1].y!=ip[i].y ) {
1618 ip2[j].x = 0;
1619 ip2[j++].y = ip[i].y;
1620 }
1621 } else {
1622 ip2[j].x = 0;
1623 ip2[j++].y = ip[last].y - ip[last].x * ((real) (ip[i].y-ip[last].y))/(ip[i].x-ip[last].x);
1624 if ( ip[i].x>0 )
1625 ip2[j++] = ip[i];
1626 else {
1627 ip2[j].x = 0;
1628 ip2[j++].y = ip[i].y;
1629 }
1630 }
1631 }
1632 /* clip to right edge */
1633 tot = j;
1634 for ( i=j=0; i<tot; ++i ) {
1635 last = i==0?tot-1:i-1;
1636 if ( ip2[i].x<cv->width && ip2[last].x<cv->width ) {
1637 ip[j++] = ip2[i];
1638 } else if ( ip2[i].x>=cv->width && ip2[last].x>=cv->width ) {
1639 if ( j==0 || ip[j-1].x!=cv->width-1 || ip[j-1].y!=ip2[i].y ) {
1640 ip[j].x = cv->width-1;
1641 ip[j++].y = ip2[i].y;
1642 }
1643 } else {
1644 ip[j].x = cv->width-1;
1645 ip[j++].y = ip2[last].y + (cv->width-1- ip2[last].x) * ((real) (ip2[i].y-ip2[last].y))/(ip2[i].x-ip2[last].x);
1646 if ( ip2[i].x<cv->width )
1647 ip[j++] = ip2[i];
1648 else {
1649 ip[j].x = cv->width-1;
1650 ip[j++].y = ip2[i].y;
1651 }
1652 }
1653 }
1654 /* clip to bottom edge */
1655 tot = j;
1656 for ( i=j=0; i<tot; ++i ) {
1657 last = i==0?tot-1:i-1;
1658 if ( ip[i].y>=0 && ip[last].y>=0) {
1659 ip2[j++] = ip[i];
1660 } else if ( ip[i].y<0 && ip[last].y<0 ) {
1661 ip2[j].y = 0;
1662 ip2[j++].x = ip[i].x;
1663 } else {
1664 ip2[j].y = 0;
1665 ip2[j++].x = ip[last].x - ip[last].y * ((real) (ip[i].x-ip[last].x))/(ip[i].y-ip[last].y);
1666 if ( ip[i].y>0 )
1667 ip2[j++] = ip[i];
1668 else {
1669 ip2[j].y = 0;
1670 ip2[j++].x = ip[i].x;
1671 }
1672 }
1673 }
1674 /* clip to top edge */
1675 tot = j;
1676 for ( i=j=0; i<tot; ++i ) {
1677 last = i==0?tot-1:i-1;
1678 if ( ip2[i].y<cv->height && ip2[last].y<cv->height ) {
1679 ip[j++] = ip2[i];
1680 } else if ( ip2[i].y>=cv->height && ip2[last].y>=cv->height ) {
1681 ip[j].y = cv->height-1;
1682 ip[j++].x = ip2[i].x;
1683 } else {
1684 ip[j].y = cv->height-1;
1685 ip[j++].x = ip2[last].x + (cv->height-1- ip2[last].y) * ((real) (ip2[i].x-ip2[last].x))/(ip2[i].y-ip2[last].y);
1686 if ( ip2[i].y<cv->height )
1687 ip[j++] = ip2[i];
1688 else {
1689 ip[j].y = cv->height-1;
1690 ip[j++].x = ip2[i].x;
1691 }
1692 }
1693 }
1694
1695 tot=j;
1696 clipped[0].x = ip[0].x; clipped[0].y = ip[0].y;
1697 for ( i=j=1; i<tot; ++i ) {
1698 if ( ip[i].x!=ip[i-1].x || ip[i].y!=ip[i-1].y ) {
1699 clipped[j].x = ip[i].x; clipped[j++].y = ip[i].y;
1700 }
1701 }
1702 clipped[j++] = clipped[0];
1703 GDrawFillPoly(pixmap,clipped,j,dhintcol);
1704 }
1705
1706 static void CVShowDHint ( CharView *cv, GWindow pixmap, DStemInfo *dstem ) {
1707 BasePoint bp[4];
1708 HintInstance *hi;
1709 double roff;
1710
1711 roff = ( dstem->right.x - dstem->left.x ) * dstem->unit.x +
1712 ( dstem->right.y - dstem->left.y ) * dstem->unit.y;
1713
1714 for ( hi=dstem->where; hi!=NULL; hi=hi->next ) {
1715 bp[0].x = dstem->left.x + dstem->unit.x * hi->begin;
1716 bp[0].y = dstem->left.y + dstem->unit.y * hi->begin;
1717 bp[1].x = dstem->right.x + dstem->unit.x * ( hi->begin - roff );
1718 bp[1].y = dstem->right.y + dstem->unit.y * ( hi->begin - roff );
1719 bp[2].x = dstem->right.x + dstem->unit.x * ( hi->end - roff );
1720 bp[2].y = dstem->right.y + dstem->unit.y * ( hi->end - roff );
1721 bp[3].x = dstem->left.x + dstem->unit.x * hi->end;
1722 bp[3].y = dstem->left.y + dstem->unit.y * hi->end;
1723 CVShowDHintInstance( cv, pixmap, bp );
1724 }
1725 }
1726
1727 static void CVShowMinimumDistance(CharView *cv, GWindow pixmap,MinimumDistance *md) {
1728 CharViewTab* tab = CVGetActiveTab(cv);
1729 int x1,y1, x2,y2;
1730 int xa, ya;
1731 int off = tab->xoff+cv->height-tab->yoff;
1732
1733 if (( md->x && !cv->showmdx ) || (!md->x && !cv->showmdy))
1734 return;
1735 if ( md->sp1==NULL && md->sp2==NULL )
1736 return;
1737 if ( md->sp1!=NULL ) {
1738 x1 = tab->xoff + rint( md->sp1->me.x*tab->scale );
1739 y1 = -tab->yoff + cv->height - rint(md->sp1->me.y*tab->scale);
1740 } else {
1741 x1 = tab->xoff + rint( cv->b.sc->width*tab->scale );
1742 y1 = 0x80000000;
1743 }
1744 if ( md->sp2!=NULL ) {
1745 x2 = tab->xoff + rint( md->sp2->me.x*tab->scale );
1746 y2 = -tab->yoff + cv->height - rint(md->sp2->me.y*tab->scale);
1747 } else {
1748 x2 = tab->xoff + rint( cv->b.sc->width*tab->scale );
1749 y2 = y1-8;
1750 }
1751 if ( y1==0x80000000 )
1752 y1 = y2-8;
1753 if ( md->x ) {
1754 ya = (y1+y2)/2;
1755 GDrawDrawArrow(pixmap, x1,ya, x2,ya, 2, mdhintcol);
1756 GDrawSetDashedLine(pixmap,5,5,off);
1757 GDrawDrawLine(pixmap, x1,ya, x1,y1, mdhintcol);
1758 GDrawDrawLine(pixmap, x2,ya, x2,y2, mdhintcol);
1759 } else {
1760 xa = (x1+x2)/2;
1761 GDrawDrawArrow(pixmap, xa,y1, xa,y2, 2, mdhintcol);
1762 GDrawSetDashedLine(pixmap,5,5,off);
1763 GDrawDrawLine(pixmap, xa,y1, x1,y1, mdhintcol);
1764 GDrawDrawLine(pixmap, xa,y2, x2,y2, mdhintcol);
1765 }
1766 GDrawSetDashedLine(pixmap,0,0,0);
1767 }
1768
1769 static void dtos(char *buf,real val) {
1770 char *pt;
1771
1772 sprintf( buf,"%.1f", (double) val);
1773 pt = buf+strlen(buf);
1774 if ( pt[-1]=='0' && pt[-2]=='.' ) pt[-2] = '\0';
1775 }
1776
1777 static void CVDrawBlues(CharView *cv,GWindow pixmap,char *bluevals,char *others,
1778 Color col) {
1779 double blues[24];
1780 char *pt, *end;
1781 int i=0, bcnt=0;
1782 GRect r;
1783 char buf[20];
1784 int len,len2;
1785 CharViewTab* tab = CVGetActiveTab(cv);
1786
1787 if ( bluevals!=NULL ) {
1788 for ( pt = bluevals; isspace( *pt ) || *pt=='['; ++pt);
1789 while ( i<14 && *pt!='\0' && *pt!=']' ) {
1790 blues[i] = g_ascii_strtod(pt,&end);
1791 if ( pt==end )
1792 break;
1793 ++i;
1794 pt = end;
1795 while ( isspace( *pt )) ++pt;
1796 }
1797 if ( i&1 ) --i;
1798 }
1799 if ( others!=NULL ) {
1800 for ( pt = others; isspace( *pt ) || *pt=='['; ++pt);
1801 while ( i<24 && *pt!='\0' && *pt!=']' ) {
1802 blues[i] = g_ascii_strtod(pt,&end);
1803 if ( pt==end )
1804 break;
1805 ++i;
1806 pt = end;
1807 while ( isspace( *pt )) ++pt;
1808 }
1809 if ( i&1 ) --i;
1810 }
1811 bcnt = i;
1812 if ( i==0 )
1813 return;
1814
1815 r.x = 0; r.width = cv->width;
1816 for ( i=0; i<bcnt; i += 2 ) {
1817 int first, other;
1818 first = -tab->yoff + cv->height - rint(blues[i]*tab->scale);
1819 other = -tab->yoff + cv->height - rint(blues[i+1]*tab->scale);
1820 r.y = first;
1821 if ( ( r.y<0 && other<0 ) || (r.y>cv->height && other>cv->height))
1822 continue;
1823 if ( r.y<0 ) r.y = 0;
1824 else if ( r.y>cv->height ) r.y = cv->height;
1825 if ( other<0 ) other = 0;
1826 else if ( other>cv->height ) other = cv->height;
1827 if ( other<r.y ) {
1828 r.height = r.y-other;
1829 r.y = other;
1830 } else
1831 r.height = other-r.y;
1832 if ( r.height==0 ) r.height = 1; /* show something */
1833 GDrawSetStippled(pixmap,2, 0,0);
1834 GDrawFillRect(pixmap,&r,col);
1835 GDrawSetStippled(pixmap,0, 0,0);
1836
1837 if ( first>-20 && first<cv->height+20 ) {
1838 dtos( buf, blues[i]);
1839 len = GDrawGetText8Width(pixmap,buf,-1);
1840 GDrawDrawText8(pixmap,cv->width-len-5,first-3,buf,-1,hintlabelcol);
1841 } else
1842 len = 0;
1843 if ( other>-20 && other<cv->height+20 ) {
1844 dtos( buf, blues[i+1]-blues[i]);
1845 len2 = GDrawGetText8Width(pixmap,buf,-1);
1846 GDrawDrawText8(pixmap,cv->width-len-5-len2-5,other+cv->sas-3,buf,-1,hintlabelcol);
1847 }
1848 }
1849 }
1850
1851 static void CVShowHints(CharView *cv, GWindow pixmap) {
1852 StemInfo *hint;
1853 GRect r;
1854 HintInstance *hi;
1855 int end;
1856 Color col;
1857 DStemInfo *dstem;
1858 MinimumDistance *md;
1859 char *blues, *others;
1860 struct psdict *private = cv->b.sc->parent->private_dict;
1861 char buf[20];
1862 int len, len2;
1863 SplinePoint *sp;
1864 SplineSet *spl;
1865 CharViewTab* tab = CVGetActiveTab(cv);
1866
1867 GDrawSetFont(pixmap,cv->small);
1868 blues = PSDictHasEntry(private,"BlueValues"); others = PSDictHasEntry(private,"OtherBlues");
1869 if ( cv->showblues && (blues!=NULL || others!=NULL))
1870 CVDrawBlues(cv,pixmap,blues,others,bluevalstipplecol);
1871 blues = PSDictHasEntry(private,"FamilyBlues"); others = PSDictHasEntry(private,"FamilyOtherBlues");
1872 if ( cv->showfamilyblues && (blues!=NULL || others!=NULL))
1873 CVDrawBlues(cv,pixmap,blues,others,fambluestipplecol);
1874
1875 if ( cv->showdhints ) for ( dstem = cv->b.sc->dstem; dstem!=NULL; dstem = dstem->next ) {
1876 CVShowDHint(cv,pixmap,dstem);
1877 }
1878
1879 if ( cv->showhhints && cv->b.sc->hstem!=NULL ) {
1880 GDrawSetDashedLine(pixmap,5,5,tab->xoff);
1881 for ( hint = cv->b.sc->hstem; hint!=NULL; hint = hint->next ) {
1882 if ( hint->width<0 ) {
1883 r.y = -tab->yoff + cv->height - rint(hint->start*tab->scale);
1884 r.height = rint(-hint->width*tab->scale)+1;
1885 } else {
1886 r.y = -tab->yoff + cv->height - rint((hint->start+hint->width)*tab->scale);
1887 r.height = rint(hint->width*tab->scale)+1;
1888 }
1889 col = hint->active ? hhintactivecol : hhintcol;
1890 /* XRectangles are shorts! */
1891 if ( r.y<32767 && r.y+r.height>-32768 ) {
1892 if ( r.y<-32768 ) {
1893 r.height -= (-32768-r.y);
1894 r.y = -32768;
1895 }
1896 if ( r.y+r.height>32767 )
1897 r.height = 32767-r.y;
1898 for ( hi=hint->where; hi!=NULL; hi=hi->next ) {
1899 r.x = tab->xoff + rint(hi->begin*tab->scale);
1900 end = tab->xoff + rint(hi->end*tab->scale);
1901 if ( end>=0 && r.x<=cv->width ) {
1902 r.width = end-r.x+1;
1903 GDrawFillRect(pixmap,&r,col);
1904 }
1905 }
1906 }
1907 col = (!hint->active && hint->hasconflicts) ? conflicthintcol : col;
1908 if ( r.y>=0 && r.y<=cv->height )
1909 GDrawDrawLine(pixmap,0,r.y,cv->width,r.y,col);
1910 if ( r.y+r.height>=0 && r.y+r.height<=cv->width )
1911 GDrawDrawLine(pixmap,0,r.y+r.height-1,cv->width,r.y+r.height-1,col);
1912
1913 r.y = -tab->yoff + cv->height - rint(hint->start*tab->scale);
1914 r.y += ( hint->width>0 ) ? -3 : cv->sas+3;
1915 if ( r.y>-20 && r.y<cv->height+20 ) {
1916 dtos( buf, hint->start);
1917 len = GDrawGetText8Width(pixmap,buf,-1);
1918 GDrawDrawText8(pixmap,cv->width-len-5,r.y,buf,-1,hintlabelcol);
1919 } else
1920 len = 0;
1921 r.y = -tab->yoff + cv->height - rint((hint->start+hint->width)*tab->scale);
1922 r.y += ( hint->width>0 ) ? cv->sas+3 : -3;
1923 if ( r.y>-20 && r.y<cv->height+20 ) {
1924 if ( hint->ghost ) {
1925 buf[0] = 'G';
1926 buf[1] = ' ';
1927 dtos(buf+2, hint->width);
1928 } else
1929 dtos( buf, hint->width);
1930 len2 = GDrawGetText8Width(pixmap,buf,-1);
1931 GDrawDrawText8(pixmap,cv->width-len-5-len2-5,r.y,buf,-1,hintlabelcol);
1932 }
1933 }
1934 }
1935 if ( cv->showvhints && cv->b.sc->vstem!=NULL ) {
1936 GDrawSetDashedLine(pixmap,5,5,cv->height-tab->yoff);
1937 for ( hint = cv->b.sc->vstem; hint!=NULL; hint = hint->next ) {
1938 if ( hint->width<0 ) {
1939 r.x = tab->xoff + rint( (hint->start+hint->width)*tab->scale );
1940 r.width = rint(-hint->width*tab->scale)+1;
1941 } else {
1942 r.x = tab->xoff + rint(hint->start*tab->scale);
1943 r.width = rint(hint->width*tab->scale)+1;
1944 }
1945 col = hint->active ? vhintactivecol : vhintcol;
1946 if ( r.x<32767 && r.x+r.width>-32768 ) {
1947 if ( r.x<-32768 ) {
1948 r.width -= (-32768-r.x);
1949 r.x = -32768;
1950 }
1951 if ( r.x+r.width>32767 )
1952 r.width = 32767-r.x;
1953 for ( hi=hint->where; hi!=NULL; hi=hi->next ) {
1954 r.y = -tab->yoff + cv->height - rint(hi->end*tab->scale);
1955 end = -tab->yoff + cv->height - rint(hi->begin*tab->scale);
1956 if ( end>=0 && r.y<=cv->height ) {
1957 r.height = end-r.y+1;
1958 GDrawFillRect(pixmap,&r,col);
1959 }
1960 }
1961 }
1962 col = (!hint->active && hint->hasconflicts) ? conflicthintcol : col;
1963 if ( r.x>=0 && r.x<=cv->width )
1964 GDrawDrawLine(pixmap,r.x,0,r.x,cv->height,col);
1965 if ( r.x+r.width>=0 && r.x+r.width<=cv->width )
1966 GDrawDrawLine(pixmap,r.x+r.width-1,0,r.x+r.width-1,cv->height,col);
1967
1968 r.x = tab->xoff + rint(hint->start*tab->scale);
1969 if ( r.x>-60 && r.x<cv->width+20 ) {
1970 dtos( buf, hint->start);
1971 len = GDrawGetText8Width(pixmap,buf,-1);
1972 r.x += ( hint->width>0 ) ? 3 : -len-3;
1973 GDrawDrawText8(pixmap,r.x,cv->sas+3,buf,-1,hintlabelcol);
1974 }
1975 r.x = tab->xoff + rint((hint->start+hint->width)*tab->scale);
1976 if ( r.x>-60 && r.x<cv->width+20 ) {
1977 if ( hint->ghost ) {
1978 buf[0] = 'G';
1979 buf[1] = ' ';
1980 dtos(buf+2, hint->width);
1981 } else
1982 dtos( buf, hint->width);
1983 len = GDrawGetText8Width(pixmap,buf,-1);
1984 r.x += ( hint->width>0 ) ? -len-3 : 3;
1985 GDrawDrawText8(pixmap,r.x,cv->sas+cv->sfh+3,buf,-1,hintlabelcol);
1986 }
1987 }
1988 }
1989 GDrawSetDashedLine(pixmap,0,0,0);
1990
1991 for ( md=cv->b.sc->md; md!=NULL; md=md->next )
1992 CVShowMinimumDistance(cv, pixmap,md);
1993
1994 if ( cv->showvhints || cv->showhhints ) {
1995 for ( spl=cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl=spl->next ) {
1996 if ( spl->first->prev!=NULL ) for ( sp=spl->first ; ; ) {
1997 if ( cv->showhhints && sp->flexx ) {
1998 double x,y,end;
1999 x = tab->xoff + rint(sp->me.x*tab->scale);
2000 y = -tab->yoff + cv->height - rint(sp->me.y*tab->scale);
2001 end = tab->xoff + rint(sp->next->to->me.x*tab->scale);
2002 if ( x>-4096 && x<32767 && y>-4096 && y<32767 ) {
2003 GDrawDrawLine(pixmap,x,y,end,y,hflexhintcol);
2004 }
2005 }
2006 if ( cv->showvhints && sp->flexy ) {
2007 double x,y,end;
2008 x = tab->xoff + rint(sp->me.x*tab->scale);
2009 y = -tab->yoff + cv->height - rint(sp->me.y*tab->scale);
2010 end = -tab->yoff + cv->height - rint(sp->next->to->me.y*tab->scale);
2011 if ( x>-4096 && x<32767 && y>-4096 && y<32767 ) {
2012 GDrawDrawLine(pixmap,x,y,x,end,vflexhintcol);
2013 }
2014 }
2015 if ( sp->next==NULL ) /* This can happen if we get an internal error inside of RemoveOverlap when the pointlist is not in good shape */
2016 break;
2017 sp = sp->next->to;
2018 if ( sp==spl->first )
2019 break;
2020 }
2021 }
2022 }
2023 }
2024
2025 static void CVDrawRefName(CharView *cv,GWindow pixmap,RefChar *ref,int fg) {
2026 CharViewTab* tab = CVGetActiveTab(cv);
2027 int x,y, len;
2028 GRect size;
2029
2030 x = tab->xoff + rint(ref->top.x*tab->scale);
2031 y = -tab->yoff + cv->height - rint(ref->top.y*tab->scale);
2032 y -= 5;
2033 if ( x<-400 || y<-40 || x>cv->width+400 || y>cv->height )
2034 return;
2035
2036 GDrawLayoutInit(pixmap,ref->sc->name,-1,cv->small);
2037 GDrawLayoutExtents(pixmap,&size);
2038 GDrawLayoutDraw(pixmap,x-size.width/2,y,fg);
2039 len = size.width;
2040 if ( ref->use_my_metrics )
2041 GDrawDrawImage(pixmap,&GIcon_lock,NULL,x+len+3,y-cv->sas);
2042 }
2043
2044 void DrawAnchorPoint(GWindow pixmap,int x, int y,int selected) {
2045 GPoint gp[9];
2046 Color col = anchorcol;
2047
2048 gp[0].x = x-1; gp[0].y = y-1;
2049 gp[1].x = x; gp[1].y = y-6;
2050 gp[2].x = x+1; gp[2].y = y-1;
2051 gp[3].x = x+6; gp[3].y = y;
2052 gp[4].x = x+1; gp[4].y = y+1;
2053 gp[5].x = x; gp[5].y = y+6;
2054 gp[6].x = x-1; gp[6].y = y+1;
2055 gp[7].x = x-6; gp[7].y = y;
2056 gp[8] = gp[0];
2057 if ( selected )
2058 GDrawDrawPoly(pixmap,gp,9,col);
2059 else
2060 GDrawFillPoly(pixmap,gp,9,col);
2061 }
2062
2063 static void CVDrawAnchorPoints(CharView *cv,GWindow pixmap) {
2064 CharViewTab* tab = CVGetActiveTab(cv);
2065 int x,y, len, sel;
2066 Color col = anchorcol;
2067 AnchorPoint *ap;
2068 char *name, ubuf[50];
2069 GRect r;
2070
2071 if ( cv->b.drawmode!=dm_fore || cv->b.sc->anchor==NULL || !cv->showanchor )
2072 return;
2073 GDrawSetFont(pixmap,cv->normal);
2074
2075 for ( sel=0; sel<2; ++sel ) {
2076 for ( ap = cv->b.sc->anchor; ap!=NULL; ap=ap->next ) if ( ap->selected==sel ) {
2077 x = tab->xoff + rint(ap->me.x*tab->scale);
2078 y = -tab->yoff + cv->height - rint(ap->me.y*tab->scale);
2079 if ( x<-400 || y<-40 || x>cv->width+400 || y>cv->height )
2080 continue;
2081
2082 DrawAnchorPoint(pixmap,x,y,ap->selected);
2083 ubuf[30]=0;
2084 if ( ap->anchor->type==act_mkmk ) {
2085 cc_strncpy(ubuf,ap->anchor->name,30);
2086 strcat(ubuf," ");
2087 strcat(ubuf,ap->type==at_basemark ? _("Base") : _("Mark") );
2088 name = ubuf;
2089 } else if ( ap->type==at_basechar || ap->type==at_mark || ap->type==at_basemark ) {
2090 name = ap->anchor->name;
2091 } else if ( ap->type==at_centry || ap->type==at_cexit ) {
2092 cc_strncpy(ubuf,ap->anchor->name,30);
2093 strcat(ubuf,ap->type==at_centry ? _("Entry") : _("Exit") );
2094 name = ubuf;
2095 } else if ( ap->type==at_baselig ) {
2096 cc_strncpy(ubuf,ap->anchor->name,30);
2097 sprintf(ubuf+strlen(ubuf),"#%d", ap->lig_index);
2098 name = ubuf;
2099 } else
2100 name = NULL; /* Should never happen */
2101
2102 GRect size;
2103 GDrawLayoutInit(pixmap,name,-1,NULL);
2104 GDrawLayoutExtents(pixmap,&size);
2105 len = size.width;
2106
2107 r.x = x-len/2; r.width = len;
2108 r.y = y+7; r.height = cv->nfh;
2109 GDrawFillRect(pixmap,&r,view_bgcol );
2110 GDrawLayoutDraw(pixmap,x-len/2,y+7+cv->nas,col);
2111 }
2112 }
2113 }
2114
2115 static void DrawImageList(CharView *cv,GWindow pixmap,ImageList *backimages) {
2116 CharViewTab* tab = CVGetActiveTab(cv);
2117
2118 while ( backimages!=NULL ) {
2119 struct _GImage *base = backimages->image->list_len==0?
2120 backimages->image->u.image:backimages->image->u.images[0];
2121
2122 GDrawDrawImageMagnified(pixmap, backimages->image, NULL,
2123 (int) (tab->xoff + rint(backimages->xoff * tab->scale)),
2124 (int) (-tab->yoff + cv->height - rint(backimages->yoff*tab->scale)),
2125 (int) rint((base->width*backimages->xscale*tab->scale)),
2126 (int) rint((base->height*backimages->yscale*tab->scale)));
2127 backimages = backimages->next;
2128 }
2129 }
2130
2131 static void DrawSelImageList(CharView *cv,GWindow pixmap,ImageList *images) {
2132 while ( images!=NULL ) {
2133 if ( images->selected )
2134 CVDrawBB(cv,pixmap,&images->bb);
2135 images = images->next;
2136 }
2137 }
2138
2139 static void DrawOldState(CharView *cv, GWindow pixmap, Undoes *undo, DRect *clip) {
2140 RefChar *refs;
2141
2142 if ( undo==NULL )
2143 return;
2144
2145 CVDrawSplineSet(cv,pixmap,undo->u.state.splines,oldoutlinecol,false,clip);
2146 for ( refs=undo->u.state.refs; refs!=NULL; refs=refs->next )
2147 if ( refs->layers[0].splines!=NULL )
2148 CVDrawSplineSet(cv,pixmap,refs->layers[0].splines,oldoutlinecol,false,clip);
2149 /* Don't do images... */
2150 }
2151
2152 static void DrawTransOrigin(CharView *cv, GWindow pixmap) {
2153 CharViewTab* tab = CVGetActiveTab(cv);
2154 real originx = cv->active_tool==cvt_scale ? cv->expandorigin.x : cv->p.cx;
2155 real originy = cv->active_tool==cvt_scale ? cv->expandorigin.y : cv->p.cy;
2156 int x = rint(originx*tab->scale) + tab->xoff;
2157 int y = cv->height-tab->yoff-rint(originy*tab->scale);
2158
2159 GDrawDrawLine(pixmap,x-4,y,x+4,y,transformorigincol);
2160 GDrawDrawLine(pixmap,x,y-4,x,y+4,transformorigincol);
2161 }
2162
2163 static void DrawVLine(CharView *cv,GWindow pixmap,real pos,Color fg, int flags,
2164 GImage *lock, char *name) {
2165 CharViewTab* tab = CVGetActiveTab(cv);
2166 char buf[20];
2167 int x = tab->xoff + rint(pos*tab->scale);
2168 DrawLine(cv,pixmap,pos,-32768,pos,32767,fg);
2169 if ( x>-400 && x<cv->width+400 ) {
2170 if ( flags&1 ) {
2171 dtos( buf, pos);
2172 GDrawSetFont(pixmap,cv->small);
2173 GDrawDrawText8(pixmap,x+5,cv->sas+3,buf,-1,metricslabelcol);
2174 if ( lock!=NULL )
2175 GDrawDrawImage(pixmap,lock,NULL,x+5,3+cv->sfh);
2176 }
2177 if ( name!=NULL )
2178 GDrawDrawText8(pixmap,x+5,cv->sas+cv->sfh*(1+lock!=NULL)+3,name,-1,metricslabelcol);
2179 }
2180 if ( ItalicConstrained && cv->b.sc->parent->italicangle!=0 ) {
2181 double t = tan(-cv->b.sc->parent->italicangle*FF_PI/180.);
2182 int xoff = rint(8096*t);
2183 DrawLine(cv,pixmap,pos-xoff,-8096,pos+xoff,8096,italiccoordcol);
2184 }
2185 }
2186
2187 static void DrawMMGhosts(CharView *cv,GWindow pixmap,DRect *clip) {
2188 /* In an MM font, draw any selected alternate versions of the current char */
2189 MMSet *mm = cv->b.sc->parent->mm;
2190 int j;
2191 SplineFont *sub;
2192 SplineChar *sc;
2193 RefChar *rf;
2194
2195 if ( mm==NULL )
2196 return;
2197 for ( j = 0; j<mm->instance_count+1; ++j ) {
2198 if ( j==0 )
2199 sub = mm->normal;
2200 else
2201 sub = mm->instances[j-1];
2202 sc = NULL;
2203 if ( cv->b.sc->parent!=sub && (cv->mmvisible & (1<<j)) &&
2204 cv->b.sc->orig_pos<sub->glyphcnt )
2205 sc = sub->glyphs[cv->b.sc->orig_pos];
2206 if ( sc!=NULL ) {
2207 for ( rf=sc->layers[ly_fore].refs; rf!=NULL; rf = rf->next )
2208 CVDrawSplineSet(cv,pixmap,rf->layers[0].splines,backoutlinecol,false,clip);
2209 CVDrawSplineSet(cv,pixmap,sc->layers[ly_fore].splines,backoutlinecol,false,clip);
2210 }
2211 }
2212 }
2213
2214 static void CVDrawGridRaster(CharView *cv, GWindow pixmap, DRect *clip ) {
2215 CharViewTab* tab = CVGetActiveTab(cv);
2216 if ( cv->showgrids ) {
2217 /* Draw ppem grid, and the raster for truetype debugging, grid fit */
2218 GRect pixel;
2219 real ygrid_spacing = (cv->b.sc->parent->ascent+cv->b.sc->parent->descent) / (real) cv->ft_ppemy;
2220 real xgrid_spacing = (cv->b.sc->parent->ascent+cv->b.sc->parent->descent) / (real) cv->ft_ppemx;
2221 int max,jmax,ii,i,jj,j;
2222 int minx, maxx, miny, maxy, r,or=0;
2223 Color clut[256];
2224
2225 pixel.width = xgrid_spacing*tab->scale+1;
2226 pixel.height = ygrid_spacing*tab->scale+1;
2227 if ( cv->raster!=NULL ) {
2228 if ( cv->raster->num_greys>2 ) {
2229 int rb, gb, bb, rd, gd, bd;
2230 clut[0] = view_bgcol ;
2231 rb = COLOR_RED(clut[0]); gb = COLOR_GREEN(clut[0]); bb = COLOR_BLUE(clut[0]);
2232 rd = COLOR_RED(rasterdarkcol)-rb;
2233 gd = COLOR_GREEN(rasterdarkcol)-gb;
2234 bd = COLOR_BLUE(rasterdarkcol)-bb;
2235 for ( i=1; i<256; ++i ) {
2236 clut[i] = ( (rb +rd*(i)/0xff)<<16 ) |
2237 ( (gb+gd*(i)/0xff)<<8 ) |
2238 ( (bb+bd*(i)/0xff) );
2239 }
2240 }
2241 minx = cv->raster->lb; maxx = minx+cv->raster->cols;
2242 maxy = cv->raster->as; miny = maxy-cv->raster->rows;
2243 if ( cv->oldraster!=NULL ) {
2244 if ( cv->oldraster->lb<minx ) minx = cv->oldraster->lb;
2245 if ( cv->oldraster->lb+cv->oldraster->cols>maxx ) maxx = cv->oldraster->lb+cv->oldraster->cols;
2246 if ( cv->oldraster->as>maxy ) maxy = cv->oldraster->as;
2247 if ( cv->oldraster->as-cv->oldraster->rows<miny ) miny = cv->oldraster->as-cv->oldraster->rows;
2248 }
2249 for ( ii=maxy; ii>miny; --ii ) {
2250 for ( jj=minx; jj<maxx; ++jj ) {
2251 i = cv->raster->as-ii; j = jj-cv->raster->lb;
2252 if ( i<0 || i>=cv->raster->rows || j<0 || j>=cv->raster->cols )
2253 r = 0;
2254 else if ( cv->raster->num_greys<=2 )
2255 r = cv->raster->bitmap[i*cv->raster->bytes_per_row+(j>>3)] & (1<<(7-(j&7)));
2256 else
2257 r = cv->raster->bitmap[i*cv->raster->bytes_per_row+j];
2258 if ( cv->oldraster==NULL || cv->oldraster->num_greys!=cv->raster->num_greys)
2259 or = r;
2260 else {
2261 i = cv->oldraster->as-ii; j = jj-cv->oldraster->lb;
2262 if ( i<0 || i>=cv->oldraster->rows || j<0 || j>=cv->oldraster->cols )
2263 or = 0;
2264 else if ( cv->oldraster->num_greys<=2 )
2265 or = cv->oldraster->bitmap[i*cv->oldraster->bytes_per_row+(j>>3)] & (1<<(7-(j&7)));
2266 else
2267 or = cv->oldraster->bitmap[i*cv->oldraster->bytes_per_row+j];
2268 }
2269 if ( r || ( or && cv->showdebugchanges)) {
2270 pixel.x = jj*xgrid_spacing*tab->scale + tab->xoff+1;
2271 pixel.y = cv->height-tab->yoff - rint(ii*ygrid_spacing*tab->scale);
2272 if ( cv->showdebugchanges ) {
2273 if ( cv->raster->num_greys<=2 )
2274 GDrawFillRect(pixmap,&pixel,(r && or) ? rastercol : r ? rasternewcol : rasteroldcol );
2275 else
2276 GDrawFillRect(pixmap,&pixel,(r-or>-16 && r-or<16) ? clut[r] : (clut[r]&0x00ff00) );
2277 } else {
2278 if ( cv->raster->num_greys<=2 )
2279 GDrawFillRect(pixmap,&pixel, rastercol );
2280 else
2281 GDrawFillRect(pixmap,&pixel, clut[r] );
2282 }
2283 }
2284 }
2285 }
2286 }
2287
2288 for ( i = floor( clip->x/xgrid_spacing ), max = ceil((clip->x+clip->width)/xgrid_spacing);
2289 i<=max; ++i )
2290 DrawLine(cv,pixmap,i*xgrid_spacing,-32768,i*xgrid_spacing,32767,i==0?coordcol:rastergridcol);
2291 for ( i = floor( clip->y/ygrid_spacing ), max = ceil((clip->y+clip->height)/ygrid_spacing);
2292 i<=max; ++i )
2293 DrawLine(cv,pixmap,-32768,i*ygrid_spacing,32767,i*ygrid_spacing,i==0?coordcol:rastergridcol);
2294 if ( xgrid_spacing*tab->scale>=7 && ygrid_spacing*tab->scale>=7) {
2295 for ( i = floor( clip->x/xgrid_spacing ), max = ceil((clip->x+clip->width)/xgrid_spacing);
2296 i<=max; ++i )
2297 for ( j = floor( clip->y/ygrid_spacing ), jmax = ceil((clip->y+clip->height)/ygrid_spacing);
2298 j<=jmax; ++j ) {
2299 int x = (i+.5)*xgrid_spacing*tab->scale + tab->xoff;
2300 int y = cv->height-tab->yoff - rint((j+.5)*ygrid_spacing*tab->scale);
2301 GDrawDrawLine(pixmap,x-2,y,x+2,y,rastergridcol);
2302 GDrawDrawLine(pixmap,x,y-2,x,y+2,rastergridcol);
2303 }
2304 }
2305 if ( cv->qg!=NULL ) {
2306 pixel.x = cv->note_x*xgrid_spacing*tab->scale + tab->xoff;
2307 pixel.y = cv->height-tab->yoff - rint(cv->note_y*ygrid_spacing*tab->scale)
2308 - pixel.height;
2309 if ( pixel.height>=20 )
2310 GDrawSetLineWidth(pixmap,3);
2311 else if ( pixel.height>10 )
2312 GDrawSetLineWidth(pixmap,2);
2313 GDrawDrawRect(pixmap,&pixel,deltagridcol);
2314 GDrawSetLineWidth(pixmap,0);
2315 {
2316 int x = (cv->note_x+.5)*xgrid_spacing*tab->scale + tab->xoff;
2317 int y = cv->height-tab->yoff - rint((cv->note_y+.5)*ygrid_spacing*tab->scale);
2318 GDrawDrawLine(pixmap,x-2,y,x+2,y,deltagridcol);
2319 GDrawDrawLine(pixmap,x,y-2,x,y+2,deltagridcol);
2320 }
2321 }
2322 }
2323 if ( cv->showback[0]&1 ) {
2324 CVDrawSplineSet(cv,pixmap,cv->b.gridfit,gridfitoutlinecol,
2325 cv->showpoints,clip);
2326 }
2327 }
2328
2329 static int APinSC(AnchorPoint *ap,SplineChar *sc) {
2330 /* Anchor points can be deleted ... */
2331 AnchorPoint *test;
2332
2333 for ( test=sc->anchor; test!=NULL && test!=ap; test = test->next );
2334 return( test==ap );
2335 }
2336
2337 static void DrawAPMatch(CharView *cv,GWindow pixmap,DRect *clip) {
2338 SplineChar *sc = cv->b.sc, *apsc = cv->apsc;
2339 SplineFont *sf = sc->parent;
2340 real trans[6];
2341 SplineSet *head, *tail, *temp;
2342 RefChar *ref;
2343 int layer = CVLayer((CharViewBase *) cv);
2344
2345 if ( cv->b.drawmode==dm_grid )
2346 return;
2347
2348 /* The other glyph might have been removed from the font */
2349 /* Either anchor might have been deleted. Be prepared for that to happen */
2350 if ( (apsc->orig_pos>=sf->glyphcnt || apsc->orig_pos<0) ||
2351 sf->glyphs[apsc->orig_pos]!=apsc ||
2352 !APinSC(cv->apmine,sc) || !APinSC(cv->apmatch,apsc)) {
2353 cv->apmine = cv->apmatch = NULL;
2354 cv->apsc =NULL;
2355 return;
2356 }
2357
2358 /* Ok this isn't very accurate, but we are going to use the current glyph's*/
2359 /* coordinate system (because we're showing the current glyph), we should */
2360 /* always use the base character's coordinates, but that would screw up */
2361 /* editing of the current glyph if it happened to be the mark */
2362 trans[0] = trans[3] = 1;
2363 trans[1] = trans[2] = 0;
2364 trans[4] = cv->apmine->me.x - cv->apmatch->me.x;
2365 trans[5] = cv->apmine->me.y - cv->apmatch->me.y;
2366
2367 head = tail = SplinePointListCopy(apsc->layers[layer].splines);
2368 for ( ref = apsc->layers[layer].refs; ref!=NULL; ref = ref->next ) {
2369 temp = SplinePointListCopy(ref->layers[0].splines);
2370 if ( head!=NULL ) {
2371 for ( ; tail->next!=NULL; tail = tail->next );
2372 tail->next = temp;
2373 } else
2374 head = tail = temp;
2375 }
2376 head = SplinePointListTransform(head,trans,tpt_AllPoints);
2377 CVDrawSplineSet(cv,pixmap,head,anchoredoutlinecol,
2378 false,clip);
2379 SplinePointListsFree(head);
2380 if ( cv->apmine->type==at_mark || cv->apmine->type==at_centry ) {
2381 DrawVLine(cv,pixmap,trans[4],anchoredoutlinecol,false,NULL,NULL);
2382 DrawLine(cv,pixmap,-8096,trans[5],8096,trans[5],anchoredoutlinecol);
2383 }
2384 }
2385
2386 static void DrawPLine(CharView *cv,GWindow pixmap,int x1, int y1, int x2, int y2,Color col) {
2387
2388 if ( x1==x2 || y1==y2 ) {
2389 if ( x1<0 ) x1=0;
2390 else if ( x1>cv->width ) x1 = cv->width;
2391 if ( x2<0 ) x2=0;
2392 else if ( x2>cv->width ) x2 = cv->width;
2393 if ( y1<0 ) y1=0;
2394 else if ( y1>cv->height ) y1 = cv->height;
2395 if ( y2<0 ) y2=0;
2396 else if ( y2>cv->height ) y2 = cv->height;
2397 } else if ( y1<-1000 || y2<-1000 || x1<-1000 || x2<-1000 ||
2398 y1>cv->height+1000 || y2>cv->height+1000 ||
2399 x1>cv->width+1000 || x2>cv->width+1000 )
2400 return;
2401 GDrawDrawLine(pixmap,x1,y1,x2,y2,col);
2402 }
2403
2404 static void FindQuickBounds(SplineSet *ss,BasePoint **bounds) {
2405 SplinePoint *sp;
2406
2407 for ( ; ss!=NULL; ss=ss->next ) {
2408 sp = ss->first;
2409 if ( sp->next==NULL || sp->next->to==sp ) /* Ignore contours with one point. Often tt points for moving references or anchors */
2410 continue;
2411 for (;;) {
2412 if ( bounds[0]==NULL )
2413 bounds[0] = bounds[1] = bounds[2] = bounds[3] = &sp->me;
2414 else {
2415 if ( sp->me.x<bounds[0]->x ) bounds[0] = &sp->me;
2416 if ( sp->me.x>bounds[1]->x ) bounds[1] = &sp->me;
2417 if ( sp->me.y<bounds[2]->y ) bounds[2] = &sp->me;
2418 if ( sp->me.y>bounds[3]->y ) bounds[3] = &sp->me;
2419 }
2420 if ( sp->next==NULL )
2421 break;
2422 sp = sp->next->to;
2423 if ( sp==ss->first )
2424 break;
2425 }
2426 }
2427 }
2428
2429 static void SSFindItalicBounds(SplineSet *ss,double t,SplinePoint **left, SplinePoint **right) {
2430 SplinePoint *sp;
2431
2432 if ( t==0 )
2433 return;
2434
2435 for ( ; ss!=NULL; ss=ss->next ) {
2436 sp = ss->first;
2437 if ( sp->next==NULL || sp->next->to==sp ) /* Ignore contours with one point. Often tt points for moving references or anchors */
2438 continue;
2439 for (;;) {
2440 if ( *left==NULL )
2441 *left = *right = sp;
2442 else {
2443 double xoff = sp->me.y*t;
2444 if ( sp->me.x-xoff < (*left)->me.x - (*left)->me.y*t ) *left = sp;
2445 if ( sp->me.x-xoff > (*right)->me.x - (*right)->me.y*t ) *right = sp;
2446 }
2447 if ( sp->next==NULL )
2448 break;
2449 sp = sp->next->to;
2450 if ( sp==ss->first )
2451 break;
2452 }
2453 }
2454 }
2455
2456 static void CVSideBearings(GWindow pixmap, CharView *cv) {
2457 CharViewTab* tab = CVGetActiveTab(cv);
2458 SplineChar *sc = cv->b.sc;
2459 RefChar *ref;
2460 BasePoint *bounds[4];
2461 int layer,last, first,l;
2462 int x,y, x2, y2;
2463 char buf[20];
2464
2465 memset(bounds,0,sizeof(bounds));
2466 if ( sc->parent->multilayer ) {
2467 last = sc->layer_cnt-1;
2468 first = ly_fore;
2469 } else {
2470 first = last = CVLayer( (CharViewBase *) cv);
2471 if ( first==ly_grid )
2472 first = last = ly_fore;
2473 }
2474 for ( layer = first ; layer<=last; ++layer ) {
2475 FindQuickBounds(sc->layers[layer].splines,bounds);
2476 for ( ref=sc->layers[layer].refs; ref!=NULL; ref=ref->next )
2477 for ( l=0; l<ref->layer_cnt; ++l )
2478 FindQuickBounds(ref->layers[l].splines,bounds);
2479 }
2480
2481 if ( bounds[0]==NULL )
2482 return; /* no points. no side bearings */
2483
2484 GDrawSetFont(pixmap,cv->small);
2485 if ( cv->showhmetrics ) {
2486 if ( bounds[0]->x!=0 ) {
2487 x = rint(bounds[0]->x*tab->scale) + tab->xoff;
2488 y = cv->height-tab->yoff-rint(bounds[0]->y*tab->scale);
2489 DrawPLine(cv,pixmap,tab->xoff,y,x,y,metricslabelcol);
2490 /* arrow heads */
2491 DrawPLine(cv,pixmap,tab->xoff,y,tab->xoff+4,y+4,metricslabelcol);
2492 DrawPLine(cv,pixmap,tab->xoff,y,tab->xoff+4,y-4,metricslabelcol);
2493 DrawPLine(cv,pixmap,x,y,x-4,y-4,metricslabelcol);
2494 DrawPLine(cv,pixmap,x,y,x-4,y+4,metricslabelcol);
2495 dtos( buf, bounds[0]->x);
2496 x = tab->xoff + (x-tab->xoff-GDrawGetText8Width(pixmap,buf,-1))/2;
2497 GDrawDrawText8(pixmap,x,y-4,buf,-1,metricslabelcol);
2498 }
2499
2500 if ( sc->width != bounds[1]->x ) {
2501 x = rint(bounds[1]->x*tab->scale) + tab->xoff;
2502 y = cv->height-tab->yoff-rint(bounds[1]->y*tab->scale);
2503 x2 = rint(sc->width*tab->scale) + tab->xoff;
2504 DrawPLine(cv,pixmap,x,y,x2,y,metricslabelcol);
2505 /* arrow heads */
2506 DrawPLine(cv,pixmap,x,y,x+4,y+4,metricslabelcol);
2507 DrawPLine(cv,pixmap,x,y,x+4,y-4,metricslabelcol);
2508 DrawPLine(cv,pixmap,x2,y,x2-4,y-4,metricslabelcol);
2509 DrawPLine(cv,pixmap,x2,y,x2-4,y+4,metricslabelcol);
2510 dtos( buf, sc->width-bounds[1]->x);
2511 x = x + (x2-x-GDrawGetText8Width(pixmap,buf,-1))/2;
2512 GDrawDrawText8(pixmap,x,y-4,buf,-1,metricslabelcol);
2513 }
2514 if ( ItalicConstrained && cv->b.sc->parent->italicangle!=0 ) {
2515 double t = tan(-cv->b.sc->parent->italicangle*FF_PI/180.);
2516 if ( t!=0 ) {
2517 SplinePoint *leftmost=NULL, *rightmost=NULL;
2518 for ( layer=first; layer<=last; ++layer ) {
2519 SSFindItalicBounds(sc->layers[layer].splines,t,&leftmost,&rightmost);
2520 for ( ref=sc->layers[layer].refs; ref!=NULL; ref=ref->next )
2521 for ( l=0; l<ref->layer_cnt; ++l )
2522 SSFindItalicBounds(ref->layers[l].splines,t,&leftmost,&rightmost);
2523 }
2524 if ( leftmost!=NULL ) {
2525 x = rint(leftmost->me.y*t*tab->scale) + tab->xoff;
2526 x2 = rint(leftmost->me.x*tab->scale) + tab->xoff;
2527 y = cv->height-tab->yoff-rint(leftmost->me.y*tab->scale);
2528 DrawPLine(cv,pixmap,x,y,x2,y,italiccoordcol);
2529 /* arrow heads */
2530 DrawPLine(cv,pixmap,x,y,x+4,y+4,italiccoordcol);
2531 DrawPLine(cv,pixmap,x,y,x+4,y-4,italiccoordcol);
2532 DrawPLine(cv,pixmap,x2,y,x2-4,y-4,italiccoordcol);
2533 DrawPLine(cv,pixmap,x2,y,x2-4,y+4,italiccoordcol);
2534 dtos( buf, leftmost->me.x-leftmost->me.y*t);
2535 x = x + (x2-x-GDrawGetText8Width(pixmap,buf,-1))/2;
2536 GDrawDrawText8(pixmap,x,y+12,buf,-1,italiccoordcol);
2537 }
2538 if ( rightmost!=NULL ) {
2539 x = rint(rightmost->me.x*tab->scale) + tab->xoff;
2540 y = cv->height-tab->yoff-rint(rightmost->me.y*tab->scale);
2541 x2 = rint((sc->width + rightmost->me.y*t)*tab->scale) + tab->xoff;
2542 DrawPLine(cv,pixmap,x,y,x2,y,italiccoordcol);
2543 /* arrow heads */
2544 DrawPLine(cv,pixmap,x,y,x+4,y+4,italiccoordcol);
2545 DrawPLine(cv,pixmap,x,y,x+4,y-4,italiccoordcol);
2546 DrawPLine(cv,pixmap,x2,y,x2-4,y-4,italiccoordcol);
2547 DrawPLine(cv,pixmap,x2,y,x2-4,y+4,italiccoordcol);
2548 dtos( buf, sc->width+rightmost->me.y*t-rightmost->me.x);
2549 x = x + (x2-x-GDrawGetText8Width(pixmap,buf,-1))/2;
2550 GDrawDrawText8(pixmap,x,y+12,buf,-1,italiccoordcol);
2551 }
2552 }
2553 }
2554 }
2555
2556 if ( cv->showvmetrics ) {
2557 x = rint(bounds[2]->x*tab->scale) + tab->xoff;
2558 y = cv->height-tab->yoff-rint(bounds[2]->y*tab->scale);
2559 y2 = cv->height-tab->yoff-rint(-sc->parent->descent*tab->scale);
2560 DrawPLine(cv,pixmap,x,y,x,y2,metricslabelcol);
2561 /* arrow heads */
2562 DrawPLine(cv,pixmap,x,y,x-4,y+4,metricslabelcol);
2563 DrawPLine(cv,pixmap,x,y,x+4,y+4,metricslabelcol);
2564 DrawPLine(cv,pixmap,x,y2,x+4,y2-4,metricslabelcol);
2565 DrawPLine(cv,pixmap,x,y2,x-4,y2-4,metricslabelcol);
2566 dtos( buf, bounds[2]->y+sc->parent->descent);
2567 y = y - (y-y2-cv->sfh)/2;
2568 GDrawDrawText8(pixmap,x+4,y,buf,-1,metricslabelcol);
2569
2570 x = rint(bounds[3]->x*tab->scale) + tab->xoff;
2571 y = cv->height-tab->yoff-rint(bounds[3]->y*tab->scale);
2572 y2 = cv->height-tab->yoff-rint(sc->parent->ascent*tab->scale);
2573 DrawPLine(cv,pixmap,x,y,x,y2,metricslabelcol);
2574 /* arrow heads */
2575 DrawPLine(cv,pixmap,x,y,x-4,y-4,metricslabelcol);
2576 DrawPLine(cv,pixmap,x,y,x+4,y-4,metricslabelcol);
2577 DrawPLine(cv,pixmap,x,y2,x+4,y2+4,metricslabelcol);
2578 DrawPLine(cv,pixmap,x,y2,x-4,y2+4,metricslabelcol);
2579 dtos( buf, sc->parent->ascent-bounds[3]->y);
2580 x = x + (x2-x-GDrawGetText8Width(pixmap,buf,-1))/2;
2581 GDrawDrawText8(pixmap,x,y-4,buf,-1,metricslabelcol);
2582 }
2583 }
2584
2585 static int CVExposeGlyphFill(CharView *cv, GWindow pixmap, GEvent *event, DRect* clip ) {
2586 int layer, cvlayer = CVLayer((CharViewBase *) cv);
2587 int filled = 0;
2588
2589 if( cv->showfilled ) {
2590 layer = cvlayer;
2591 if ( layer>=0 ) {
2592 CVDrawLayerSplineSet(cv,pixmap,&cv->b.sc->layers[layer],foreoutlinecol,
2593 cv->showpoints, clip, sfm_fill );
2594 filled = 1;
2595 }
2596 }
2597 return(filled);
2598 }
2599
2600 static void CVExposeReferences( CharView *cv, GWindow pixmap, SplineChar* sc, int layer, DRect* clip )
2601 {
2602 RefChar *rf = 0;
2603 int rlayer = 0;
2604
2605 for ( rf = sc->layers[layer].refs; rf!=NULL; rf = rf->next )
2606 {
2607 if ( cv->showrefnames )
2608 CVDrawRefName(cv,pixmap,rf,0);
2609 enum outlinesfm_flags refsfm = sfm_stroke;
2610 if( cv->showfilled ) {
2611 refsfm = sfm_fill;
2612 }
2613
2614 for ( rlayer=0; rlayer<rf->layer_cnt; ++rlayer )
2615 CVDrawSplineSetSpecialized(cv,pixmap,rf->layers[rlayer].splines,foreoutlinecol,-1,clip, refsfm, 0);
2616 if ( rf->selected && cv->b.layerheads[cv->b.drawmode]==&sc->layers[layer])
2617 CVDrawBB(cv,pixmap,&rf->bb);
2618 }
2619 }
2620
2621
2622 static void CVExpose(CharView *cv, GWindow pixmap, GEvent *event ) {
2623 CharViewTab* tab = CVGetActiveTab(cv);
2624 SplineFont *sf = cv->b.sc->parent;
2625 RefChar *rf;
2626 GRect old;
2627 DRect clip;
2628 char buf[20];
2629 PST *pst;
2630 int i, layer, rlayer, cvlayer = CVLayer((CharViewBase *) cv);
2631 enum outlinesfm_flags strokeFillMode = sfm_stroke;
2632 int GlyphHasBeenFilled = 0;
2633
2634 GDrawPushClip(pixmap,&event->u.expose.rect,&old);
2635
2636 if( cv->showfilled ) {
2637 strokeFillMode = sfm_fill;
2638 }
2639
2640 clip.width = event->u.expose.rect.width/tab->scale;
2641 clip.height = event->u.expose.rect.height/tab->scale;
2642 clip.x = (event->u.expose.rect.x-tab->xoff)/tab->scale;
2643 clip.y = (cv->height-event->u.expose.rect.y-event->u.expose.rect.height-tab->yoff)/tab->scale;
2644
2645 GDrawSetFont(pixmap,cv->small);
2646 GDrawSetLineWidth(pixmap,0);
2647
2648 if ( !cv->show_ft_results && cv->dv==NULL ) {
2649
2650 for ( layer = ly_back; layer<cv->b.sc->layer_cnt; ++layer ) if ( cv->b.sc->layers[layer].images!=NULL ) {
2651 if (( sf->multilayer && ((( cv->showback[0]&1 || cvlayer==layer) && layer==ly_back ) ||
2652 ((cv->showfore || cvlayer==layer) && layer>ly_back)) ) ||
2653 ( !sf->multilayer && (((cv->showfore && cvlayer==layer) && layer==ly_fore) ||
2654 (((cv->showback[layer>>5]&(1<<(layer&31))) || cvlayer==layer) && layer!=ly_fore))) ) {
2655 /* This really should be after the grids, but then it would completely*/
2656 /* hide them. */
2657 DrawImageList(cv,pixmap,cv->b.sc->layers[layer].images);
2658 }
2659 }
2660 if ( cv->showhhints || cv->showvhints || cv->showdhints || cv->showblues || cv->showfamilyblues)
2661 CVShowHints(cv,pixmap);
2662 if ( cv->showgrids || cv->b.drawmode==dm_grid ) {
2663 CVDrawSplineSet(cv,pixmap,cv->b.fv->sf->grid.splines,guideoutlinecol,
2664 cv->showpoints && cv->b.drawmode==dm_grid,&clip);
2665 }
2666 if ( cv->showhmetrics ) {
2667 Color lbcolor = (!cv->inactive && cv->lbearingsel) ? lbearingselcol : coordcol;
2668 DrawVLine(cv,pixmap,0,lbcolor,false,NULL,NULL);
2669 DrawLine(cv,pixmap,-8096,0,8096,0,coordcol);
2670 DrawLine(cv,pixmap,-8096,sf->ascent,8096,sf->ascent,ascentdescentcol);
2671 DrawLine(cv,pixmap,-8096,-sf->descent,8096,-sf->descent,ascentdescentcol);
2672 }
2673 if ( cv->showvmetrics ) {
2674 /*DrawLine(cv,pixmap,(sf->ascent+sf->descent)/2,-8096,(sf->ascent+sf->descent)/2,8096,coordcol);
2675 DrawLine(cv,pixmap,-8096,sf->vertical_origin,8096,sf->vertical_origin,coordcol);*/
2676 }
2677
2678 DrawSelImageList(cv,pixmap,cv->b.layerheads[cv->b.drawmode]->images);
2679
2680 /* Wrong order, I know. But it is useful to have the background */
2681 /* visible on top of the fill... */
2682 GlyphHasBeenFilled = CVExposeGlyphFill(cv, pixmap, event, &clip );
2683 } else {
2684 /* Draw FreeType Results */
2685 CVDrawGridRaster(cv,pixmap,&clip);
2686 }
2687
2688 if ( cv->b.layerheads[cv->b.drawmode]->undoes!=NULL &&
2689 cv->b.layerheads[cv->b.drawmode]->undoes->undotype==ut_tstate )
2690 DrawOldState(cv,pixmap,cv->b.layerheads[cv->b.drawmode]->undoes, &clip);
2691
2692 if ( cv->showfore )
2693 cv->showback[0] |= (1<<ly_fore);
2694 else
2695 cv->showback[0] &= ~(1<<ly_fore);
2696
2697 for ( layer=ly_back; layer<cv->b.sc->layer_cnt; ++layer ) if ( layer!=cvlayer ) {
2698 if ( cv->showback[layer>>5]&(1<<(layer&31)) ) {
2699 /* Used to draw the image list here, but that's too slow. Optimization*/
2700 /* is to draw to pixmap, dump pixmap a bit earlier */
2701 /* Then when we moved the fill image around, we had to deal with the */
2702 /* images before the fill... */
2703 int activelayer = CVLayer(&cv->b);
2704
2705 enum outlinesfm_flags strokeFillMode = sfm_stroke;
2706 if( cv->inPreviewMode )
2707 strokeFillMode = sfm_nothing;
2708 if( layer == activelayer && layer >= ly_back )
2709 strokeFillMode = sfm_fill;
2710
2711 CVDrawLayerSplineSet(cv,pixmap,&cv->b.sc->layers[layer],
2712 !sf->multilayer || layer==ly_back ? backoutlinecol : foreoutlinecol,
2713 false,&clip,strokeFillMode);
2714 for ( rf=cv->b.sc->layers[layer].refs; rf!=NULL; rf = rf->next ) {
2715 if ( /* cv->b.drawmode==dm_back &&*/ cv->showrefnames )
2716 CVDrawRefName(cv,pixmap,rf,0);
2717 for ( rlayer=0; rlayer<rf->layer_cnt; ++rlayer )
2718 CVDrawSplineSet(cv,pixmap,rf->layers[rlayer].splines, backoutlinecol,false,&clip);
2719 if ( rf->selected && cv->b.layerheads[cv->b.drawmode]==&cv->b.sc->layers[layer])
2720 CVDrawBB(cv,pixmap,&rf->bb);
2721 }
2722 }
2723 }
2724 if ( cv->mmvisible!=0 )
2725 DrawMMGhosts(cv,pixmap,&clip);
2726 if ( cv->template1!=NULL )
2727 CVDrawTemplates(cv,pixmap,cv->template1,&clip);
2728 if ( cv->template2!=NULL )
2729 CVDrawTemplates(cv,pixmap,cv->template2,&clip);
2730
2731 /* Draw the active layer last so its splines are on top. */
2732 /* Note that we don't check whether the layer is visible or not, we always*/
2733 /* draw the current layer -- unless they've turned on grid fit. Then they*/
2734 /* might want to hide the active layer. */
2735 layer = cvlayer;
2736
2737
2738 /*
2739 * If we have a pretransform_spl and the user wants to see it then show it to them
2740 */
2741 if(cv->p.pretransform_spl) {
2742 CVDrawSplineSetSpecialized(cv, pixmap, cv->p.pretransform_spl,
2743 DraggingComparisonOutlineColor, 1, &clip, sfm_stroke_trans,
2744 DraggingComparisonAlphaChannelOverride);
2745 }
2746
2747 /* The call to CVExposeGlyphFill() above will have rendered a filled glyph already. */
2748 /* We draw the outline only at this stage so as to have it layered */
2749 /* over the control points if they are currently visible. */
2750 /* CVDrawLayerSplineSet() will draw both the control points, and the font outline over those */
2751 /* NB:
2752 * Drawing the stroked outline may also use the color
2753 * clippathcol for some splines, so we can't really avoid a
2754 * restroke unless we are sure
2755 * FOR-ALL(splines):spl->is_clip_path==0 */
2756 if( cv->showfilled ) {
2757 strokeFillMode = sfm_stroke;
2758 }
2759 if( GlyphHasBeenFilled ) {
2760 strokeFillMode = sfm_stroke_trans;
2761 }
2762
2763 if ( layer<0 ) /* Guide lines are special */
2764 CVDrawLayerSplineSet( cv,pixmap,cv->b.layerheads[cv->b.drawmode],foreoutlinecol,
2765 cv->showpoints ,&clip, strokeFillMode );
2766 else if ( (cv->showback[layer>>5]&(1<<(layer&31))) ||
2767 (!cv->show_ft_results && cv->dv==NULL ))
2768 {
2769 CVExposeReferences( cv, pixmap, cv->b.sc, layer, &clip );
2770 }
2771 if ( layer>=0 )
2772 {
2773 if( cv->dv && !(cv->showback[layer>>5]&(1<<(layer&31))))
2774 {
2775 // MIQ 2013 feb: issue/168
2776 // turn off the glyph outline if we are in debug mode and
2777 // the layer is not visible
2778 }
2779 else
2780 {
2781 CVDrawLayerSplineSet( cv,pixmap,&cv->b.sc->layers[layer],foreoutlinecol,
2782 cv->showpoints ,&clip, strokeFillMode );
2783
2784
2785 int showpoints = 0;
2786 enum outlinesfm_flags sm = sfm_stroke;
2787 if( cv->inPreviewMode ) {
2788 sm = sfm_fill;
2789 }
2790
2791 int ridx = cv->additionalCharsToShowActiveIndex+1;
2792 // TRACE("expose(b) additionalCharsToShowActiveIndex:%d\n", cv->additionalCharsToShowActiveIndex );
2793 if( cv->additionalCharsToShow[ ridx ] )
2794 {
2795 int i = 1;
2796 int originalxoff = tab->xoff;
2797 int offset = tab->scale * cv->b.sc->width;
2798 for( i=ridx; i < additionalCharsToShowLimit; i++ )
2799 {
2800 // TRACE("expose(right) loop:%d\n", i );
2801 SplineChar* xc = cv->additionalCharsToShow[i];
2802 if( !xc )
2803 break;
2804
2805 tab->xoff += offset;
2806 CVExposeReferences( cv, pixmap, xc, layer, &clip );
2807 CVDrawLayerSplineSet( cv, pixmap, &xc->layers[layer], foreoutlinecol,
2808 showpoints ,&clip, sm );
2809 offset = tab->scale * xc->width;
2810 }
2811 tab->xoff = originalxoff;
2812 }
2813
2814
2815
2816 if( cv->additionalCharsToShowActiveIndex > 0 )
2817 {
2818 int i = 1;
2819 int originalxoff = tab->xoff;
2820 int offset = 0;
2821
2822 for( i=cv->additionalCharsToShowActiveIndex-1; i >= 0; i-- )
2823 {
2824 // TRACE("expose(left) loop:%d\n", i );
2825 SplineChar* xc = cv->additionalCharsToShow[i];
2826 if( !xc )
2827 break;
2828
2829 offset = tab->scale * xc->width;
2830 tab->xoff -= offset;
2831 CVExposeReferences( cv, pixmap, xc, layer, &clip );
2832 CVDrawLayerSplineSet( cv, pixmap, &xc->layers[layer], foreoutlinecol,
2833 showpoints ,&clip, sm );
2834 }
2835 tab->xoff = originalxoff;
2836 }
2837
2838 // TRACE("expose(e) ridx:%d\n", ridx );
2839
2840 }
2841 }
2842
2843
2844 if ( cv->freehand.current_trace )
2845 CVDrawSplineSet( cv,pixmap,cv->freehand.current_trace,tracecol,
2846 false,&clip);
2847
2848 if ( cv->showhmetrics && (cv->b.container==NULL || cv->b.container->funcs->type==cvc_mathkern) ) {
2849 RefChar *lock = HasUseMyMetrics(cv->b.sc,cvlayer);
2850 if ( lock!=NULL ) cv->b.sc->width = lock->sc->width;
2851 DrawVLine(cv,pixmap,cv->b.sc->width,(!cv->inactive && cv->widthsel)?widthselcol:widthcol,true,
2852 lock!=NULL ? &GIcon_lock : NULL, NULL);
2853 if ( cv->b.sc->italic_correction!=TEX_UNDEF && cv->b.sc->italic_correction!=0 ) {
2854 GDrawSetDashedLine(pixmap,2,2,0);
2855 DrawVLine(cv,pixmap,cv->b.sc->width+cv->b.sc->italic_correction,(!cv->inactive && cv->icsel)?widthselcol:widthcol,
2856 /* GT: Italic Correction */
2857 false, NULL,_("ItalicCor."));
2858 GDrawSetDashedLine(pixmap,0,0,0);
2859 }
2860 }
2861 if ( cv->showhmetrics && cv->b.container==NULL ) {
2862 for ( pst=cv->b.sc->possub; pst!=NULL && pst->type!=pst_lcaret; pst=pst->next );
2863 if ( pst!=NULL ) {
2864 for ( i=0; i<pst->u.lcaret.cnt; ++i )
2865 DrawVLine(cv,pixmap,pst->u.lcaret.carets[i],lcaretcol,true,NULL,_("Lig.Caret"));
2866 }
2867 if ( cv->show_ft_results || cv->dv!=NULL )
2868 DrawVLine(cv,pixmap,cv->b.ft_gridfitwidth,widthgridfitcol,true,NULL,NULL);
2869 if ( cv->b.sc->top_accent_horiz!=TEX_UNDEF )
2870 DrawVLine(cv,pixmap,cv->b.sc->top_accent_horiz,(!cv->inactive && cv->tah_sel)?widthselcol:anchorcol,true,
2871 NULL,_("TopAccent"));
2872 }
2873 if ( cv->showvmetrics ) {
2874 int vertical_height = -cv->b.sc->vwidth + cv->b.sc->parent->ascent;
2875 int len, y = -tab->yoff + cv->height - rint(vertical_height*tab->scale);
2876 DrawLine(cv,pixmap,-32768,vertical_height,32767,vertical_height,
2877 (!cv->inactive && cv->vwidthsel)?widthselcol:widthcol);
2878 if ( y>-40 && y<cv->height+40 ) {
2879 dtos( buf, cv->b.sc->vwidth);
2880 GDrawSetFont(pixmap,cv->small);
2881 len = GDrawGetText8Width(pixmap,buf,-1);
2882 GDrawDrawText8(pixmap,cv->width-len-5,y,buf,-1,metricslabelcol);
2883 }
2884 }
2885 if ( cv->showsidebearings && cv->showfore &&
2886 (cv->showvmetrics || cv->showhmetrics))
2887 CVSideBearings(pixmap,cv);
2888
2889 /* Show scale handles while scale tool selected or actively dragging */
2890 if ( cv->showing_tool==cvt_scale || cv->active_tool==cvt_scale || cv->b1_tool==cvt_scale )
2891 CVDrawScaleSelectionBox(cv,pixmap);
2892
2893 if ((( cv->active_tool >= cvt_scale && cv->active_tool <= cvt_perspective ) ||
2894 cv->active_shape!=NULL ) &&
2895 cv->p.pressed )
2896 DrawTransOrigin(cv,pixmap);
2897 if ( cv->dv==NULL || (cv->showback[ly_fore>>5]&(1<<(ly_fore&31))) )
2898 CVDrawAnchorPoints(cv,pixmap);
2899 if ( cv->apmine!=NULL )
2900 DrawAPMatch(cv,pixmap,&clip);
2901
2902 if ( cv->p.rubberbanding || cv->p.rubberlining ) {
2903 if ( cv->p.rubberbanding )
2904 CVDrawRubberRect(pixmap,cv);
2905 if ( cv->p.rubberlining )
2906 CVDrawRubberLine(pixmap,cv);
2907 }
2908 CVRulerExpose(pixmap,cv);
2909
2910 if (cv->guide_pos != -1) {
2911 CVDrawGuideLine(cv, cv->guide_pos);
2912 }
2913
2914 GDrawPopClip(pixmap,&old);
2915 }
2916
2917 static void SC_UpdateAll(SplineChar *sc) {
2918 CharView *cv;
2919 struct splinecharlist *dlist;
2920 MetricsView *mv;
2921 FontView *fv;
2922
2923 for ( cv=(CharView *) (sc->views); cv!=NULL; cv=(CharView *) (cv->b.next) )
2924 GDrawRequestExpose(cv->v,NULL,false);
2925 for ( dlist=sc->dependents; dlist!=NULL; dlist=dlist->next )
2926 SCUpdateAll(dlist->sc);
2927 if ( sc->parent!=NULL ) {
2928 for ( fv = (FontView *) (sc->parent->fv); fv!=NULL; fv=(FontView *) (fv->b.nextsame) )
2929 FVRegenChar(fv,sc);
2930 for ( mv = sc->parent->metrics; mv!=NULL; mv=mv->next )
2931 MVRegenChar(mv,sc);
2932 }
2933 }
2934
2935 static void FVRedrawAllCharViewsSF(SplineFont *sf)
2936 {
2937 int i;
2938 CharView *cv;
2939
2940 for ( i=0; i<sf->glyphcnt; ++i ) if ( sf->glyphs[i]!=NULL )
2941 for ( cv = (CharView *) (sf->glyphs[i]->views); cv!=NULL; cv=(CharView *) (cv->b.next) )
2942 GDrawRequestExpose(cv->v,NULL,false);
2943 }
2944
2945 void FVRedrawAllCharViews(FontView *fv)
2946 {
2947 FVRedrawAllCharViewsSF( fv->b.sf );
2948 }
2949
2950 static void SCRegenDependents(SplineChar *sc, int layer) {
2951 struct splinecharlist *dlist;
2952 FontView *fv;
2953 int first, last;
2954
2955 first = last = layer;
2956 if ( layer==ly_all ) {
2957 first = 0; last = sc->layer_cnt-1;
2958 }
2959 for ( layer = first; layer<=last; ++layer ) {
2960 for ( fv = (FontView *) (sc->parent->fv); fv!=NULL; fv=(FontView *) (fv->b.nextsame) ) {
2961 if ( fv->sv!=NULL && layer<=ly_fore ) {
2962 SCReinstanciateRef(&fv->sv->sd.sc_srch,sc,layer);
2963 SCReinstanciateRef(&fv->sv->sd.sc_rpl,sc,layer);
2964 }
2965 }
2966
2967 for ( dlist=sc->dependents; dlist!=NULL; dlist=dlist->next ) {
2968 SCReinstanciateRef(dlist->sc,sc,layer);
2969 SCRegenDependents(dlist->sc,layer);
2970 }
2971 }
2972 }
2973
2974 static void CVUpdateInfo(CharView *cv, GEvent *event) {
2975 CharViewTab* tab = CVGetActiveTab(cv);
2976
2977 cv->info_within = true;
2978 cv->e.x = event->u.mouse.x; cv->e.y = event->u.mouse.y;
2979 cv->info.x = (event->u.mouse.x-tab->xoff)/tab->scale;
2980 cv->info.y = (cv->height-event->u.mouse.y-tab->yoff)/tab->scale;
2981 CVInfoDraw(cv,cv->gw);
2982 }
2983
2984 static void CVNewScale(CharView *cv) {
2985 CharViewTab* tab = CVGetActiveTab(cv);
2986 GEvent e;
2987
2988 GScrollBarSetBounds(cv->vsb,-20000*tab->scale,8000*tab->scale,cv->height);
2989 GScrollBarSetBounds(cv->hsb,-8000*tab->scale,32000*tab->scale,cv->width);
2990 GScrollBarSetPos(cv->vsb,tab->yoff-cv->height);
2991 GScrollBarSetPos(cv->hsb,-tab->xoff);
2992
2993 GDrawRequestExpose(cv->v,NULL,false);
2994 if ( cv->showrulers )
2995 GDrawRequestExpose(cv->gw,NULL,false);
2996 GDrawGetPointerPosition(cv->v,&e);
2997 CVRulerLingerMove(cv);
2998 CVUpdateInfo(cv,&e);
2999 }
3000
3001 static void _CVFit(CharView *cv,DBounds *b, int integral) {
3002 CharViewTab* tab = CVGetActiveTab(cv);
3003 real left, right, top, bottom, hsc, wsc;
3004 extern int palettes_docked;
3005 int offset = palettes_docked ? 90 : 0;
3006 int em = cv->b.sc->parent->ascent + cv->b.sc->parent->descent;
3007 int hsmall = true;
3008
3009 if ( offset>cv->width ) offset = 0;
3010
3011 bottom = b->miny;
3012 top = b->maxy;
3013 left = b->minx;
3014 right = b->maxx;
3015
3016 if ( top<bottom ) IError("Bottom bigger than top!");
3017 if ( right<left ) IError("Left bigger than right!");
3018 top -= bottom;
3019 right -= left;
3020 if ( top==0 ) top = em;
3021 if ( right==0 ) right = em;
3022 wsc = (cv->width-offset) / right;
3023 hsc = cv->height / top;
3024 if ( wsc<hsc ) { hsc = wsc; hsmall = false ; }
3025
3026 tab->scale = hsc;
3027 if ( integral ) {
3028 if ( tab->scale > 1.0 ) {
3029 tab->scale = floor(tab->scale);
3030 } else {
3031 tab->scale = 1/ceil(1/tab->scale);
3032 }
3033 } else {
3034 if ( tab->scale > 1.0 ) {
3035 tab->scale = floor(2*tab->scale)/2;
3036 } else {
3037 tab->scale = 2/ceil(2/tab->scale);
3038 }
3039 }
3040
3041 /* Center glyph horizontally */
3042 tab->xoff = ( (cv->width-offset) - (right*tab->scale) )/2 + offset - b->minx*tab->scale;
3043 if ( hsmall )
3044 tab->yoff = -bottom*tab->scale;
3045 else
3046 tab->yoff = -(bottom+top/2)*tab->scale + cv->height/2;
3047
3048 CVNewScale(cv);
3049 }
3050
3051 static void CVFit(CharView *cv) {
3052 DBounds b;
3053 double center;
3054
3055 SplineCharFindBounds(cv->b.sc,&b);
3056 if ( b.miny==0 && b.maxy==0 ) {
3057 b.maxy =cv->b.sc->parent->ascent;
3058 b.miny = -cv->b.sc->parent->descent;
3059 }
3060 /* FF used to normalize bounding boxes making maxx positive. But this */
3061 /* may result into an incorrect positioning for combining marks, which */
3062 /* usually have both bearings negative. So keep negative values as they are. */
3063 /* As for the Y axis, we only ensure the minimum value doesn't exceed zero, */
3064 /* so that the baseline is always visible. */
3065
3066 if ( b.miny>0 ) b.miny = 0;
3067
3068 /* Now give some extra space around the interesting stuff */
3069 center = (b.maxx+b.minx)/2;
3070 b.minx = center - (center - b.minx)*1.2;
3071 b.maxx = center + (b.maxx - center)*1.2;
3072 center = (b.maxy+b.miny)/2;
3073 b.miny = center - (center - b.miny)*1.2;
3074 b.maxy = center + (b.maxy - center)*1.2;
3075
3076 _CVFit(cv,&b,true);
3077 }
3078
3079 void CVUnlinkView(CharView *cv ) {
3080 CharView *test;
3081
3082 if ( cv->b.sc->views == (CharViewBase *) cv ) {
3083 cv->b.sc->views = cv->b.next;
3084 } else {
3085 for ( test=(CharView *) (cv->b.sc->views);
3086 test->b.next!=(CharViewBase *) cv && test->b.next!=NULL;
3087 test=(CharView *) (test->b.next) );
3088 if ( test->b.next==(CharViewBase *) cv )
3089 test->b.next = cv->b.next;
3090 }
3091 }
3092
3093 static GWindow CharIcon(CharView *cv, FontView *fv) {
3094 SplineChar *sc = cv->b.sc;
3095 BDFFont *bdf, *bdf2;
3096 BDFChar *bdfc;
3097 GWindow icon = cv->icon;
3098 GRect r;
3099
3100 r.x = r.y = 0; r.width = r.height = fv->cbw-1;
3101 if ( icon == NULL )
3102 cv->icon = icon = GDrawCreatePixmap(NULL,NULL,r.width,r.width);
3103 GDrawFillRect(icon,&r,0x0); /* for some reason icons seem to be color reversed by my defn */
3104
3105 bdf = NULL; bdfc = NULL;
3106 if ( sc->layers[ly_fore].refs!=NULL || sc->layers[ly_fore].splines!=NULL ) {
3107 bdf = fv->show;
3108 if ( sc->orig_pos>=bdf->glyphcnt || bdf->glyphs[sc->orig_pos]==NULL )
3109 bdf = fv->filled;
3110 if ( sc->orig_pos>=bdf->glyphcnt || bdf->glyphs[sc->orig_pos]==NULL ) {
3111 bdf2 = NULL; bdfc = NULL;
3112 for ( bdf=fv->b.sf->bitmaps; bdf!=NULL && bdf->pixelsize<24 ; bdf=bdf->next )
3113 bdf2 = bdf;
3114 if ( bdf2!=NULL && bdf!=NULL ) {
3115 if ( 24-bdf2->pixelsize < bdf->pixelsize-24 )
3116 bdf = bdf2;
3117 } else if ( bdf==NULL )
3118 bdf = bdf2;
3119 }
3120 if ( bdf!=NULL && sc->orig_pos<bdf->glyphcnt )
3121 bdfc = bdf->glyphs[sc->orig_pos];
3122 }
3123
3124 // Leaving the hard-coded colors here because this stuff is window-system
3125 // dependent and not necessarily user-configurable (although it might or
3126 // might not be appropriate to make them theme-configurable)
3127 if ( bdfc!=NULL ) {
3128 GClut clut;
3129 struct _GImage base;
3130 GImage gi;
3131 /* if not empty, use the font's own shape, otherwise use a standard */
3132 /* font */
3133 memset(&gi,'\0',sizeof(gi));
3134 memset(&base,'\0',sizeof(base));
3135 memset(&clut,'\0',sizeof(clut));
3136 gi.u.image = &base;
3137 base.trans = -1;
3138 base.clut = &clut;
3139 if ( bdfc->byte_data ) { int i;
3140 base.image_type = it_index;
3141 clut.clut_len = bdf->clut->clut_len;
3142 for ( i=0; i<clut.clut_len; ++i ) {
3143 int v = 255-i*255/(clut.clut_len-1);
3144 clut.clut[i] = COLOR_CREATE(v,v,v);
3145 }
3146 clut.trans_index = -1;
3147 } else {
3148 base.image_type = it_mono;
3149 clut.clut_len = 2;
3150 clut.clut[1] = 0xffffff;
3151 }
3152 base.data = bdfc->bitmap;
3153 base.bytes_per_line = bdfc->bytes_per_line;
3154 base.width = bdfc->xmax-bdfc->xmin+1;
3155 base.height = bdfc->ymax-bdfc->ymin+1;
3156 GDrawDrawImage(icon,&gi,NULL,(r.width-base.width)/2,(r.height-base.height)/2);
3157 } else if ( sc->unicodeenc!=-1 ) {
3158 if ( cv_iconfont.fi==NULL )
3159 GResEditDoInit(&charviewpoints_ri);
3160 unichar_t text[2];
3161 int as, ds, ld, width;
3162 GDrawSetFont(icon,cv_iconfont.fi);
3163 text[0] = sc->unicodeenc; text[1] = 0;
3164 GDrawWindowFontMetrics(icon,cv_iconfont.fi,&as,&ds,&ld);
3165 width = GDrawGetTextWidth(icon,text,1);
3166 GDrawDrawText(icon,(r.width-width)/2,(r.height-as-ds)/2+as,text,1,0xffffff);
3167 }
3168 return( icon );
3169 }
3170
3171 static int CVCurEnc(CharView *cv)
3172 {
3173 return( ((FontView *) (cv->b.fv))->b.map->backmap[cv->b.sc->orig_pos] );
3174 }
3175
3176 static char *CVMakeTitles(CharView *cv,char *buf,size_t len) {
3177 char *title;
3178 SplineChar *sc = cv->b.sc;
3179 SplineFont *sf = sc->parent;
3180 char *uniname;
3181 size_t used;
3182
3183 /* GT: This is the title for a window showing an outline character */
3184 /* GT: It will look something like: */
3185 /* GT: exclam at 33 from Arial */
3186 /* GT: $1 is the name of the glyph */
3187 /* GT: $2 is the glyph's encoding */
3188 /* GT: $3 is the font name */
3189 /* GT: $4 is the changed flag ('*' for the changed items)*/
3190 used = snprintf(buf,len,_("%1$.80s at %2$d from %3$.90s%4$s"),
3191 sc->name, CVCurEnc(cv), sf->fontname,
3192 sc->changed ? "*" : "");
3193 title = copy(buf);
3194
3195 if (used < len) {
3196 /* Enhance 'buf' description with Nameslist.txt unicode name definition */
3197 if ( (uniname=uniname_name(sc->unicodeenc))!=NULL ) {
3198 used += snprintf(buf+used, len-used, " %s", uniname);
3199 free(uniname);
3200 }
3201 }
3202
3203 if (used < len && ( cv->show_ft_results || cv->dv )) {
3204 snprintf(buf+used, len-used, " (%gpt, %ddpi)", (double) cv->ft_pointsizey, cv->ft_dpi );
3205 }
3206
3207 return( title );
3208 }
3209
3210 static void SC_RefreshTitles(SplineChar *sc) {
3211 /* Called if the user changes the unicode encoding or the character name */
3212 CharView *cv;
3213 char buf[300], *title;
3214
3215 if ( (CharView *) (sc->views)==NULL )
3216 return;
3217 for ( cv = (CharView *) (sc->views); cv!=NULL; cv=(CharView *) (cv->b.next) ) {
3218 title = CVMakeTitles(cv,buf,sizeof(buf));
3219 /* Could be different if one window is debugging and one is not */
3220 GDrawSetWindowTitles8(cv->gw,buf,title);
3221 free(title);
3222 }
3223 }
3224
3225 static void CVChangeTabsVisibility(CharView *cv,int makevisible) {
3226 GRect gsize, pos, sbsize;
3227
3228 if ( cv->tabs==NULL || GGadgetIsVisible(cv->tabs)==makevisible )
3229 return;
3230 GGadgetGetSize(cv->tabs,&gsize);
3231 GGadgetGetSize(cv->vsb,&sbsize);
3232 if ( makevisible ) {
3233 cv->mbh += gsize.height;
3234 cv->height -= gsize.height;
3235 GGadgetMove(cv->vsb,sbsize.x,sbsize.y+gsize.height);
3236 GGadgetResize(cv->vsb,sbsize.width,sbsize.height-gsize.height);
3237 GGadgetMoveAddToY( cv->charselector, gsize.height );
3238 GGadgetMoveAddToY( cv->charselectorNext, gsize.height );
3239 GGadgetMoveAddToY( cv->charselectorPrev, gsize.height );
3240 } else {
3241 cv->mbh -= gsize.height;
3242 cv->height += gsize.height;
3243 GGadgetMove(cv->vsb,sbsize.x,sbsize.y-gsize.height);
3244 GGadgetResize(cv->vsb,sbsize.width,sbsize.height+gsize.height);
3245 GGadgetMoveAddToY( cv->charselector, -1*gsize.height );
3246 GGadgetMoveAddToY( cv->charselectorNext, -1*gsize.height );
3247 GGadgetMoveAddToY( cv->charselectorPrev, -1*gsize.height );
3248 }
3249 GGadgetSetVisible(cv->tabs,makevisible);
3250 pos.x = 0; pos.y = cv->mbh+cv->charselectorh+cv->infoh;
3251 pos.width = cv->width; pos.height = cv->height;
3252 if ( cv->showrulers ) {
3253 pos.x += cv->rulerh;
3254 pos.y += cv->rulerh;
3255 }
3256 GDrawMoveResize(cv->v,pos.x,pos.y,pos.width,pos.height);
3257 GDrawSync(NULL);
3258 GDrawRequestExpose(cv->v,NULL,false);
3259 GDrawRequestExpose(cv->gw,NULL,false);
3260 }
3261
3262 static void CVCheckPoints(CharView *cv) {
3263 if ( !SCPointsNumberedProperly(cv->b.sc,CVLayer((CharViewBase *) cv)) && cv->b.sc->ttf_instrs_len!=0 ) {
3264 char *buts[3];
3265 int answer;
3266 buts[0] = _("_Yes");
3267 buts[1] = _("_No");
3268 buts[2] = NULL;
3269 answer = ff_ask(_("Bad Point Numbering"),(const char **) buts,0,1,_("The points in %s are not numbered properly. This means that any instructions will probably move the wrong points and do the wrong thing.\nWould you like me to remove the instructions?"),cv->b.sc->name);
3270 if ( answer==0 ) {
3271 free(cv->b.sc->ttf_instrs); cv->b.sc->ttf_instrs = NULL;
3272 cv->b.sc->ttf_instrs_len = 0;
3273 }
3274 }
3275 }
3276
3277 static void CVChangeSC_storeTab( CharView *cv, int tabnumber )
3278 {
3279 TRACE("CVChangeSC_storeTab() %d\n", tabnumber );
3280 if( tabnumber < charview_cvtabssz )
3281 {
3282 CharViewTab* t = &cv->cvtabs[tabnumber];
3283 strncpy( t->charselected,
3284 GGadgetGetTitle8(cv->charselector),
3285 charviewtab_charselectedsz );
3286 }
3287 }
3288
3289 static void CVChangeSC_fetchTab( CharView *cv, int tabnumber )
3290 {
3291 if( tabnumber < charview_cvtabssz )
3292 {
3293 CharViewTab* t = &cv->cvtabs[tabnumber];
3294 GGadgetSetTitle8(cv->charselector, t->charselected );
3295 }
3296 }
3297
3298 static void CVSetCharSelectorValueFromSC( CharView *cv, SplineChar *sc )
3299 {
3300 const char* title = Wordlist_getSCName( sc );
3301 GGadgetSetTitle8(cv->charselector, title);
3302 }
3303
3304 // See comment in gtabset.c (fn GTabSetRemoveTabByPos)
3305 static void CVMenuCloseTab(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e));
3306 static void CVTabSetRemoveSync(GWindow gw, int pos) {
3307 CharView* cv = (CharView*) GDrawGetUserData(gw);
3308 // There's no other good way to pass an "argument" to this function as its definition
3309 // is required to be a certain way. The user_data of the GWindow is already our CharView
3310 // so we can't use that.
3311 cv->ctpos = pos;
3312 CVMenuCloseTab(gw, NULL, NULL);
3313 }
3314
3315 static void CVTabSetSwapSync(GWindow gw, int pos_a, int pos_b) {
3316 CharView* cv = (CharView*) GDrawGetUserData(gw);
3317 CharViewTab tempt = cv->cvtabs[pos_a];
3318 char* fnt = cv->former_names[pos_a];
3319
3320 cv->cvtabs[pos_a] = cv->cvtabs[pos_b];
3321 cv->former_names[pos_a] = cv->former_names[pos_b];
3322 cv->cvtabs[pos_b] = tempt;
3323 cv->former_names[pos_b] = fnt;
3324
3325 int sel = GTabSetGetSel(cv->tabs);
3326 if (pos_a == sel)
3327 cv->oldtabnum = pos_b;
3328 if (pos_b == sel)
3329 cv->oldtabnum = pos_a;
3330 }
3331
3332 void CVChangeSC( CharView *cv, SplineChar *sc )
3333 {
3334 char *title;
3335 char buf[300];
3336 extern int updateflex;
3337 int i;
3338 int old_layer = CVLayer((CharViewBase *) cv), blayer;
3339 int was_fitted = cv->dv==NULL && cv->b.gridfit!=NULL;
3340
3341 if ( old_layer>=sc->layer_cnt )
3342 old_layer = ly_fore; /* Can happen in type3 fonts where each glyph has a different layer cnt */
3343
3344 memset( cv->additionalCharsToShow, 0, sizeof(SplineChar*) * additionalCharsToShowLimit );
3345 cv->additionalCharsToShowActiveIndex = 0;
3346 cv->additionalCharsToShow[0] = sc;
3347
3348 CVDebugFree(cv->dv);
3349
3350 if ( cv->expandedge != ee_none ) {
3351 GDrawSetCursor(cv->v,ct_mypointer);
3352 cv->expandedge = ee_none;
3353 }
3354
3355 SplinePointListsFree(cv->b.gridfit); cv->b.gridfit = NULL;
3356 FreeType_FreeRaster(cv->oldraster); cv->oldraster = NULL;
3357 FreeType_FreeRaster(cv->raster); cv->raster = NULL;
3358
3359 SCLigCaretCheck(sc,false);
3360
3361 CVUnlinkView(cv);
3362 cv->p.nextcp = cv->p.prevcp = cv->widthsel = cv->vwidthsel = false;
3363 if ( (CharView *) (sc->views)==NULL && updateflex )
3364 SplineCharIsFlexible(sc,old_layer!=ly_grid ? old_layer : ly_fore );
3365 cv->b.sc = sc;
3366 cv->b.next = sc->views;
3367 sc->views = &cv->b;
3368 cv->enc = ( ((FontView *) (cv->b.fv))->b.map->backmap[cv->b.sc->orig_pos] );
3369 cv->b.layerheads[dm_fore] = &sc->layers[ly_fore];
3370 blayer = old_layer;
3371 if ( old_layer==ly_grid || old_layer==ly_fore ||
3372 sc->parent->multilayer || old_layer>=sc->layer_cnt )
3373 blayer = ly_back;
3374 cv->b.layerheads[dm_back] = &sc->layers[blayer];
3375 cv->b.layerheads[dm_grid] = &sc->parent->grid;
3376 cv->p.sp = cv->lastselpt = NULL;
3377 cv->p.spiro = cv->lastselcp = NULL;
3378 cv->apmine = cv->apmatch = NULL; cv->apsc = NULL;
3379 cv->template1 = cv->template2 = NULL;
3380 #if HANYANG
3381 if ( cv->b.sc->parent->rules!=NULL && cv->b.sc->compositionunit )
3382 Disp_DefaultTemplate(cv);
3383 #endif
3384 if ( cv->b.layerheads[cv->b.drawmode]->order2 )
3385 CVCheckPoints(cv);
3386 if ( cv->showpointnumbers || cv->show_ft_results )
3387 SCNumberPoints(sc,old_layer);
3388 if ( cv->show_ft_results )
3389 CVGridFitChar(cv);
3390
3391 CVNewScale(cv);
3392
3393 CharIcon(cv,(FontView *) (cv->b.fv));
3394 title = CVMakeTitles(cv,buf,sizeof(buf));
3395 GDrawSetWindowTitles8(cv->gw,buf,title);
3396 CVInfoDraw(cv,cv->gw);
3397 free(title);
3398 _CVPaletteActivate(cv,true,false);
3399
3400 if ( cv->tabs!=NULL ) {
3401 for ( i=0; i<cv->former_cnt; ++i )
3402 if ( strcmp(cv->former_names[i],sc->name)==0 )
3403 break;
3404 if ( i!=cv->former_cnt && cv->showtabs )
3405 {
3406 CVChangeSC_storeTab( cv, cv->oldtabnum );
3407 CVChangeSC_fetchTab( cv, i );
3408 cv->oldtabnum = i;
3409 GTabSetSetSel(cv->tabs,i);
3410 }
3411 else
3412 {
3413 // Only need to store here, as we are about to make a new tab.
3414 CVChangeSC_storeTab( cv, cv->oldtabnum );
3415 cv->oldtabnum = 0;
3416 // have to shuffle the cvtabs along to be in sync with cv->tabs
3417 {
3418 int i = 0;
3419 for( i=charview_cvtabssz-1; i > 0; i-- )
3420 {
3421 cv->cvtabs[i] = cv->cvtabs[i-1];
3422 }
3423 }
3424 CVSetCharSelectorValueFromSC( cv, sc );
3425
3426 if ( cv->former_cnt==CV_TABMAX )
3427 free(cv->former_names[CV_TABMAX-1]);
3428 for ( i=cv->former_cnt<CV_TABMAX?cv->former_cnt-1:CV_TABMAX-2; i>=0; --i )
3429 cv->former_names[i+1] = cv->former_names[i];
3430 cv->former_names[0] = copy(sc->name);
3431 if ( cv->former_cnt<CV_TABMAX )
3432 ++cv->former_cnt;
3433 for ( i=0; i<cv->former_cnt; ++i )
3434 {
3435 if( i < charview_cvtabssz )
3436 {
3437 CharViewTab* t = &cv->cvtabs[i];
3438 GTabSetChangeTabName(cv->tabs, t->charselected, i);
3439 }
3440 }
3441
3442 GTabSetRemetric(cv->tabs);
3443 GTabSetSetSel(cv->tabs,0); /* This does a redraw */
3444 if ( !GGadgetIsVisible(cv->tabs) && cv->showtabs )
3445 CVChangeTabsVisibility(cv,true);
3446 }
3447 }
3448 if( !strcmp(GGadgetGetTitle8(cv->charselector),""))
3449 CVSetCharSelectorValueFromSC( cv, sc );
3450
3451 if ( sc->inspiro && !hasspiro() && !sc->parent->complained_about_spiros ) {
3452 sc->parent->complained_about_spiros = true;
3453 #ifdef _NO_LIBSPIRO
3454 ff_post_error(_("You may not use spiros"),_("This glyph should display spiro points, but unfortunately this version of fontforge was not linked with the spiro library, so only normal bezier points will be displayed."));
3455 #else
3456 ff_post_error(_("You may not use spiros"),_("This glyph should display spiro points, but unfortunately FontForge was unable to load libspiro, spiros are not available for use, and normal bezier points will be displayed instead."));
3457 #endif
3458 }
3459
3460 if ( was_fitted )
3461 CVGridFitChar(cv);
3462
3463 // Force any extra chars to be setup and drawn
3464 GEvent e;
3465 e.type=et_controlevent;
3466 e.u.control.subtype = et_textchanged;
3467 e.u.control.u.tf_changed.from_pulldown = 0;
3468 CV_OnCharSelectorTextChanged( cv->charselector, &e );
3469 }
3470
3471 static void CVChangeChar(CharView *cv, int i )
3472 {
3473 SplineChar *sc;
3474 SplineFont *sf = cv->b.sc->parent;
3475 EncMap *map = ((FontView *) (cv->b.fv))->b.map;
3476 int gid = i<0 || i>= map->enccount ? -2 : map->map[i];
3477
3478 if ( sf->cidmaster!=NULL && !map->enc->is_compact ) {
3479 SplineFont *cidmaster = sf->cidmaster;
3480 int k;
3481 for ( k=0; k<cidmaster->subfontcnt; ++k ) {
3482 SplineFont *sf = cidmaster->subfonts[k];
3483 if ( i<sf->glyphcnt && sf->glyphs[i]!=NULL )
3484 break;
3485 }
3486 if ( k!=cidmaster->subfontcnt ) {
3487 if ( cidmaster->subfonts[k] != sf ) {
3488 sf = cidmaster->subfonts[k];
3489 gid = ( i>=sf->glyphcnt ) ? -2 : i;
3490 /* can't create a new glyph this way */
3491 }
3492 }
3493 }
3494 if ( gid == -2 )
3495 return;
3496 if ( gid==-1 || (sc = sf->glyphs[gid])==NULL ) {
3497 sc = SFMakeChar(sf,map,i);
3498 sc->inspiro = cv->b.sc->inspiro && hasspiro();
3499 }
3500
3501 if ( sc==NULL || (cv->b.sc == sc && cv->enc==i ))
3502 return;
3503 cv->map_of_enc = map;
3504 cv->enc = i;
3505 CVChangeSC(cv,sc);
3506 }
3507
3508 /*
3509 * Unused
3510 static void CVSwitchToTab(CharView *cv,int tnum ) {
3511 if( tnum >= cv->former_cnt )
3512 return;
3513
3514 SplineFont *sf = cv->b.fv->sf;
3515 char* n = cv->former_names[tnum];
3516 int unienc = UniFromName(n,sf->uni_interp,cv->b.fv->map->enc);
3517 CVChangeChar(cv,unienc);
3518 }
3519
3520 static void CVMenuShowTab(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
3521 CharView *cv = (CharView *) GDrawGetUserData(gw);
3522 CVSwitchToTab(cv,mi->mid);
3523 }
3524 */
3525
3526 static int CVChangeToFormer( GGadget *g, GEvent *e) {
3527 if ( e->type==et_controlevent && e->u.control.subtype == et_radiochanged ) {
3528 CharView *cv = GDrawGetUserData(GGadgetGetWindow(g));
3529 int new_aspect = GTabSetGetSel(g);
3530 SplineFont *sf = cv->b.sc->parent;
3531 int gid;
3532
3533 for ( gid=sf->glyphcnt-1; gid>=0; --gid )
3534 if ( sf->glyphs[gid]!=NULL &&
3535 strcmp(sf->glyphs[gid]->name,cv->former_names[new_aspect])==0 )
3536 break;
3537 if ( gid<0 ) {
3538 /* They changed the name? See if we can get a unicode value from it */
3539 int unienc = UniFromName(cv->former_names[new_aspect],sf->uni_interp,cv->b.fv->map->enc);
3540 if ( unienc>=0 ) {
3541 gid = SFFindGID(sf,unienc,cv->former_names[new_aspect]);
3542 if ( gid>=0 ) {
3543 free(cv->former_names[new_aspect]);
3544 cv->former_names[new_aspect] = copy(sf->glyphs[gid]->name);
3545 }
3546 }
3547 }
3548 if ( gid<0 )
3549 return( true );
3550 CVChangeSC(cv,sf->glyphs[gid]);
3551 TRACE("CVChangeToFormer: Changed SC to %s (GID %d)\n", sf->glyphs[gid]->name, gid);
3552 cv->enc = ((FontView *) (cv->b.fv))->b.map->backmap[cv->b.sc->orig_pos];
3553 }
3554 return( true );
3555 }
3556
3557 static void CVFakeMove(CharView *cv, GEvent *event) {
3558 GEvent e;
3559
3560 memset(&e,0,sizeof(e));
3561 e.type = et_mousemove;
3562 e.w = cv->v;
3563 if ( event->w!=cv->v ) {
3564 GPoint p;
3565 p.x = event->u.chr.x; p.y = event->u.chr.y;
3566 GDrawTranslateCoordinates(event->w,cv->v,&p);
3567 event->u.chr.x = p.x; event->u.chr.y = p.y;
3568 }
3569 e.u.mouse.state = TrueCharState(event);
3570 e.u.mouse.x = event->u.chr.x;
3571 e.u.mouse.y = event->u.chr.y;
3572 e.u.mouse.device = NULL;
3573 CVMouseMove(cv,&e);
3574 }
3575
3576 static void CVDoFindInFontView(CharView *cv) {
3577 FVChangeChar((FontView *) (cv->b.fv),CVCurEnc(cv));
3578 GDrawSetVisible(((FontView *) (cv->b.fv))->gw,true);
3579 GDrawRaise(((FontView *) (cv->b.fv))->gw);
3580 }
3581
3582 static uint16_t HaveModifiers = 0;
3583 static uint16_t PressingTilde = 0;
3584 static uint16_t PrevCharEventWasCharUpOnControl = 0;
3585
3586
3587 static void CVCharUp(CharView *cv, GEvent *event ) {
3588
3589 if ( !event->u.chr.autorepeat && !HaveModifiers && event->u.chr.keysym==' ' ) {
3590 update_spacebar_hand_tool(cv);
3591 }
3592
3593 int oldactiveModifierControl = cv->activeModifierControl;
3594 int oldactiveModifierAlt = cv->activeModifierAlt;
3595 cv->activeModifierControl = cv->activeModifierControl && !( event->u.chr.keysym == GK_Control_L || event->u.chr.keysym == GK_Control_R
3596 || event->u.chr.keysym == GK_Meta_L || event->u.chr.keysym == GK_Meta_R );
3597 cv->activeModifierAlt = cv->activeModifierAlt && !( event->u.chr.keysym == GK_Alt_L || event->u.chr.keysym == GK_Alt_R
3598 || event->u.chr.keysym == GK_Mode_switch );
3599 // helps with keys on the mac
3600 if( (event->u.chr.state&ksm_meta) )
3601 cv->activeModifierAlt = 0;
3602 if( oldactiveModifierControl != cv->activeModifierControl
3603 || oldactiveModifierAlt != cv->activeModifierAlt )
3604 {
3605 CVInfoDraw(cv,cv->gw);
3606 }
3607
3608
3609
3610 // TRACE("CVCharUp() ag:%d key:%d\n", cv_auto_goto, event->u.chr.keysym );
3611 if( !cv_auto_goto )
3612 {
3613 bool isImmediateKeyTogglePreview = isImmediateKey( cv->gw, "TogglePreview", event ) != NULL;
3614 if( isImmediateKeyTogglePreview ) {
3615 PressingTilde = 1;
3616 }
3617
3618 if( PrevCharEventWasCharUpOnControl && isImmediateKeyTogglePreview )
3619 {
3620 HaveModifiers = 0;
3621 PrevCharEventWasCharUpOnControl = 0;
3622 return;
3623 }
3624 PrevCharEventWasCharUpOnControl = 0;
3625
3626 if( !event->u.chr.autorepeat
3627 && (event->u.chr.keysym == GK_Control_L
3628 || event->u.chr.keysym == GK_Control_R ))
3629 {
3630 PrevCharEventWasCharUpOnControl = 1;
3631 if( !PressingTilde ) {
3632 HaveModifiers = 0;
3633 }
3634 }
3635
3636 if ( !event->u.chr.autorepeat && !HaveModifiers && isImmediateKeyTogglePreview ) {
3637 PressingTilde = 0;
3638 CVPreviewModeSet( cv->gw, false );
3639 return;
3640 }
3641
3642 if ( !event->u.chr.autorepeat && isImmediateKeyTogglePreview ) {
3643 PressingTilde = 0;
3644 }
3645 if ( event->u.chr.autorepeat && HaveModifiers && isImmediateKeyTogglePreview ) {
3646 return;
3647 }
3648 }
3649
3650
3651 if( event->u.chr.keysym == GK_Escape )
3652 {
3653 TRACE("escape char.......!\n");
3654 GGadget *active = GWindowGetFocusGadgetOfWindow(cv->gw);
3655 if( active == cv->charselector )
3656 {
3657 TRACE("was on charselector\n");
3658 GWidgetIndicateFocusGadget( cv->hsb );
3659 }
3660 else if ( cv->charselector != NULL )
3661 {
3662 TRACE("was on NOT charselector\n");
3663 GWidgetIndicateFocusGadget( cv->charselector );
3664 }
3665 }
3666
3667
3668 #if _ModKeysAutoRepeat
3669 /* Under cygwin these keys auto repeat, they don't under normal X */
3670 if ( event->u.chr.keysym == GK_Shift_L || event->u.chr.keysym == GK_Shift_R ||
3671 event->u.chr.keysym == GK_Control_L || event->u.chr.keysym == GK_Control_R ||
3672 event->u.chr.keysym == GK_Meta_L || event->u.chr.keysym == GK_Meta_R ||
3673 event->u.chr.keysym == GK_Alt_L || event->u.chr.keysym == GK_Alt_R ||
3674 event->u.chr.keysym == GK_Super_L || event->u.chr.keysym == GK_Super_R ||
3675 event->u.chr.keysym == GK_Hyper_L || event->u.chr.keysym == GK_Hyper_R ) {
3676 if ( cv->autorpt!=NULL ) {
3677 GDrawCancelTimer(cv->autorpt);
3678 CVToolsSetCursor(cv,cv->oldstate,NULL);
3679 }
3680 cv->keysym = event->u.chr.keysym;
3681 cv->oldkeyx = event->u.chr.x;
3682 cv->oldkeyy = event->u.chr.y;
3683 cv->oldkeyw = event->w;
3684 cv->oldstate = TrueCharState(event);
3685 cv->autorpt = GDrawRequestTimer(cv->v,100,0,NULL);
3686 } else {
3687 if ( cv->autorpt!=NULL ) {
3688 GDrawCancelTimer(cv->autorpt); cv->autorpt=NULL;
3689 CVToolsSetCursor(cv,cv->oldstate,NULL);
3690 }
3691 CVToolsSetCursor(cv,TrueCharState(event),NULL);
3692 }
3693 #else
3694 CVToolsSetCursor(cv,TrueCharState(event),NULL);
3695 if ( event->u.chr.keysym == GK_Shift_L || event->u.chr.keysym == GK_Shift_R ||
3696 event->u.chr.keysym == GK_Alt_L || event->u.chr.keysym == GK_Alt_R ||
3697 event->u.chr.keysym == GK_Meta_L || event->u.chr.keysym == GK_Meta_R )
3698 CVFakeMove(cv, event);
3699 #endif
3700 }
3701
3702 void CVInfoDrawText(CharView *cv, GWindow pixmap ) {
3703 CharViewTab* tab = CVGetActiveTab(cv);
3704 GRect r;
3705 Color bg = GDrawGetDefaultBackground(GDrawGetDisplayOfWindow(pixmap));
3706 Color fg = GDrawGetDefaultForeground(GDrawGetDisplayOfWindow(pixmap));
3707 const int buffersz = 150;
3708 char buffer[buffersz+1];
3709 int ybase = cv->mbh+cv->charselectorh+(cv->infoh-cv->sfh)/2+cv->sas;
3710 real xdiff, ydiff;
3711 SplinePoint *sp, dummy;
3712 spiro_cp *cp;
3713
3714 GDrawSetFont(pixmap,cv->small);
3715 r.x = RPT_DATA; r.width = SPT_BASE-RPT_DATA;
3716 r.y = cv->mbh+cv->charselectorh; r.height = cv->infoh-1;
3717 GDrawFillRect(pixmap,&r,bg);
3718 r.x = SPT_DATA; r.width = SOF_BASE-SPT_DATA;
3719 GDrawFillRect(pixmap,&r,bg);
3720 r.x = SOF_DATA; r.width = SDS_BASE-SOF_DATA;
3721 GDrawFillRect(pixmap,&r,bg);
3722 r.x = SDS_DATA; r.width = SAN_BASE-SDS_DATA;
3723 GDrawFillRect(pixmap,&r,bg);
3724 r.x = SAN_DATA; r.width = MAG_BASE-SAN_DATA;
3725 GDrawFillRect(pixmap,&r,bg);
3726 r.x = MAG_DATA; r.width = LAYER_DATA-MAG_DATA;
3727 GDrawFillRect(pixmap,&r,bg);
3728 r.x = LAYER_DATA; r.width = CODERANGE_DATA-LAYER_DATA;
3729 GDrawFillRect(pixmap,&r,bg);
3730 r.x = CODERANGE_DATA; r.width = FLAGS_DATA-CODERANGE_DATA;
3731 GDrawFillRect(pixmap,&r,bg);
3732 r.x = FLAGS_DATA; r.width = 200;
3733 GDrawFillRect(pixmap,&r,bg);
3734
3735 if ( cv->info_within ) {
3736 if ( cv->info.x>=1000 || cv->info.x<=-1000 || cv->info.y>=1000 || cv->info.y<=-1000 )
3737 sprintf(buffer,"%d%s%d", (int) cv->info.x, coord_sep, (int) cv->info.y );
3738 else
3739 sprintf(buffer,"%.4g%s%.4g", (double) cv->info.x, coord_sep, (double) cv->info.y );
3740 buffer[11] = '\0';
3741 GDrawDrawText8(pixmap,RPT_DATA,ybase,buffer,-1,fg);
3742 }
3743 if ( tab->scale>=.25 )
3744 sprintf( buffer, "%d%%", (int) (100*tab->scale));
3745 else
3746 sprintf( buffer, "%.3g%%", (double) (100*tab->scale));
3747 GDrawDrawText8(pixmap,MAG_DATA,ybase,buffer,-1,fg);
3748
3749 const int layernamesz = 100;
3750 char layername[layernamesz+1];
3751 strncpy(layername,_("Guide"),layernamesz);
3752 if(cv->b.drawmode!=dm_grid) {
3753 int idx = CVLayer((CharViewBase *) cv);
3754 if(idx >= 0 && idx < cv->b.sc->parent->layer_cnt) {
3755 strncpy(layername,cv->b.sc->parent->layers[idx].name,layernamesz);
3756 }
3757 }
3758 snprintf( buffer, buffersz, _("Active Layer: %s (%s)"),
3759 layername,
3760 /* GT: Guide layer, make it short */
3761 ( cv->b.drawmode==dm_grid ? _("Guide") :
3762 /* GT: Background, make it short */
3763 cv->b.layerheads[cv->b.drawmode]->background ? _("Back") :
3764 /* GT: Foreground, make it short */
3765 _("Fore") )
3766 );
3767 GDrawDrawText8(pixmap,LAYER_DATA,ybase,buffer,-1,fg);
3768 GDrawDrawText8(pixmap,LAYER_DATA,ybase,buffer,-1,fg);
3769
3770 if ( cv->coderange==cr_none )
3771 {
3772 snprintf( buffer, buffersz, _("Modes: "));
3773 if( CVShouldInterpolateCPsOnMotion(cv) )
3774 strcat( buffer, "Interpolate" );
3775 GDrawDrawText8(pixmap,FLAGS_DATA,ybase,buffer,-1,fg);
3776 }
3777
3778
3779 if ( cv->coderange!=cr_none ) {
3780 GDrawDrawText8(pixmap,CODERANGE_DATA,ybase,
3781 cv->coderange==cr_fpgm ? _("'fpgm'") :
3782 cv->coderange==cr_prep ? _("'prep'") : _("Glyph"),
3783 -1,fg);
3784 GDrawDrawText8(pixmap,CODERANGE_DATA+40,ybase,
3785 FreeTypeStringVersion(), -1,fg);
3786 }
3787 sp = NULL; cp = NULL;
3788 if ( cv->b.sc->inspiro && hasspiro())
3789 cp = cv->p.spiro!=NULL ? cv->p.spiro : cv->lastselcp;
3790 else
3791 sp = cv->p.sp!=NULL ? cv->p.sp : cv->lastselpt;
3792 if ( sp==NULL && cp==NULL )
3793 if ( cv->active_tool==cvt_rect || cv->active_tool==cvt_elipse ||
3794 cv->active_tool==cvt_poly || cv->active_tool==cvt_star ||
3795 cv->active_tool==cvt_scale || cv->active_tool==cvt_skew ||
3796 cv->active_tool==cvt_rotate || cv->active_tool==cvt_flip ) {
3797 dummy.me.x = cv->p.cx; dummy.me.y = cv->p.cy;
3798 sp = &dummy;
3799 }
3800 if ( sp || cp ) {
3801 real selx, sely;
3802 if ( sp ) {
3803 if ( cv->pressed && sp==cv->p.sp ) {
3804 selx = cv->p.constrain.x;
3805 sely = cv->p.constrain.y;
3806 } else {
3807 selx = sp->me.x;
3808 sely = sp->me.y;
3809 }
3810 } else {
3811 selx = cp->x;
3812 sely = cp->y;
3813 }
3814 xdiff=cv->info.x-selx;
3815 ydiff = cv->info.y-sely;
3816
3817 if ( selx>=1000 || selx<=-1000 || sely>=1000 || sely<=-1000 )
3818 sprintf(buffer,"%d%s%d", (int) selx, coord_sep, (int) sely );
3819 else
3820 sprintf(buffer,"%.4g%s%.4g", (double) selx, coord_sep, (double) sely );
3821 buffer[11] = '\0';
3822 GDrawDrawText8(pixmap,SPT_DATA,ybase,buffer,-1,fg);
3823 } else if ( cv->widthsel && cv->info_within ) {
3824 xdiff = cv->info.x-cv->p.cx;
3825 ydiff = 0;
3826 } else if ( cv->p.rubberbanding && cv->info_within ) {
3827 xdiff=cv->info.x-cv->p.cx;
3828 ydiff = cv->info.y-cv->p.cy;
3829 } else
3830 return;
3831 if ( !cv->info_within )
3832 return;
3833
3834 if ( cv->active_tool==cvt_scale ) {
3835 xdiff = cv->expandwidth==0 ? 100.0 : 100.0*(cv->info.x-cv->expandorigin.x)/cv->expandwidth;
3836 ydiff = cv->expandheight==0 ? 100.0 : 100.0*(cv->info.y-cv->expandorigin.y)/cv->expandheight;
3837 if ( xdiff>=100 || xdiff<=-100 || ydiff>=100 || ydiff<=-100 )
3838 sprintf(buffer,"%d%%%s%d%%", (int) xdiff, coord_sep, (int) ydiff );
3839 else
3840 sprintf(buffer,"%.3g%%%s%.3g%%", (double) xdiff, coord_sep, (double) ydiff );
3841 } else if ( xdiff>=1000 || xdiff<=-1000 || ydiff>=1000 || ydiff<=-1000 )
3842 sprintf(buffer,"%d%s%d", (int) xdiff, coord_sep, (int) ydiff );
3843 else
3844 sprintf(buffer,"%.4g%s%.4g", (double) xdiff, coord_sep, (double) ydiff );
3845 buffer[11] = '\0';
3846 GDrawDrawText8(pixmap,SOF_DATA,ybase,buffer,-1,fg);
3847
3848 sprintf( buffer, "%.1f", sqrt(xdiff*xdiff+ydiff*ydiff));
3849 GDrawDrawText8(pixmap,SDS_DATA,ybase,buffer,-1,fg);
3850
3851 /* Utf-8 for degree sign */
3852 sprintf( buffer, "%d\302\260", (int) rint(180*atan2(ydiff,xdiff)/FF_PI));
3853 GDrawDrawText8(pixmap,SAN_DATA,ybase,buffer,-1,fg);
3854 }
3855
3856 static void CVInfoDrawRulers(CharView *cv, GWindow pixmap ) {
3857 // Check if we have any rulers to draw over
3858 if (cv->hruler == NULL || cv->vruler == NULL) {
3859 return;
3860 }
3861
3862 int rstart = cv->mbh+cv->charselectorh+cv->infoh;
3863 GRect rh, rv, oldrh, oldrv;
3864 rh.y = rstart; rh.height = cv->rulerh; rh.x = cv->rulerh; rh.width = cv->width;
3865 rv.x = 0; rv.width = cv->rulerh; rv.y = rstart + cv->rulerh; rv.height = cv->height;
3866
3867 GDrawSetLineWidth(pixmap,0);
3868 // Draw the new rulers
3869 GDrawPushClip(pixmap, &rh, &oldrh);
3870 rh.x = cv->olde.x; rh.y = 0; rh.width = 1;
3871 GDrawDrawPixmap(pixmap, cv->hruler, &rh, cv->rulerh + cv->olde.x, rstart);
3872 GDrawDrawLine(pixmap,cv->e.x+cv->rulerh,rstart,cv->e.x+cv->rulerh,rstart+cv->rulerh,rulercurtickcol);
3873 GDrawPopClip(pixmap, &oldrh);
3874
3875 GDrawPushClip(pixmap, &rv, &oldrv);
3876 rv.x = 0; rv.y = cv->olde.y; rv.height = 1;
3877 GDrawDrawPixmap(pixmap, cv->vruler, &rv, 0, cv->rulerh + rstart + cv->olde.y);
3878 GDrawDrawLine(pixmap,0,cv->e.y+rstart+cv->rulerh,cv->rulerh,cv->e.y+rstart+cv->rulerh,rulercurtickcol);
3879 GDrawPopClip(pixmap, &oldrv);
3880
3881 cv->olde = cv->e;
3882 }
3883
3884 void CVInfoDraw(CharView *cv, GWindow pixmap ) {
3885 GRect r;
3886 r.x = 0;
3887 r.y = cv->mbh+cv->charselectorh;
3888 r.width = cv->width;
3889 r.height = cv->infoh-1;
3890 GDrawRequestExpose(pixmap, &r, false);
3891 if (cv->showrulers) {
3892 int rstart = cv->mbh+cv->charselectorh+cv->infoh;
3893 r.x = cv->rulerh;
3894 r.y = rstart;
3895 r.height = cv->rulerh;
3896 r.width = cv->width;
3897 GDrawRequestExpose(pixmap, &r, false);
3898
3899 r.x = 0;
3900 r.y = rstart + cv->rulerh;
3901 r.width = cv->rulerh;
3902 r.height = cv->height;
3903 GDrawRequestExpose(pixmap, &r, false);
3904 }
3905 }
3906
3907 static void CVCrossing(CharView *cv, GEvent *event ) {
3908 CharViewTab* tab = CVGetActiveTab(cv);
3909 CVToolsSetCursor(cv,event->u.mouse.state,event->u.mouse.device);
3910 cv->info_within = event->u.crossing.entered;
3911 cv->info.x = (event->u.crossing.x-tab->xoff)/tab->scale;
3912 cv->info.y = (cv->height-event->u.crossing.y-tab->yoff)/tab->scale;
3913 CVInfoDraw(cv,cv->gw);
3914 CPEndInfo(cv);
3915 }
3916
3917 static int CheckSpiroPoint(FindSel *fs, spiro_cp *cp, SplineSet *spl,int index) {
3918
3919 if ( fs->xl<=cp->x && fs->xh>=cp->x &&
3920 fs->yl<=cp->y && fs->yh >= cp->y ) {
3921 fs->p->spiro = cp;
3922 fs->p->spline = NULL;
3923 fs->p->anysel = true;
3924 fs->p->spl = spl;
3925 fs->p->spiro_index = index;
3926 return( true );
3927 }
3928 return( false );
3929 }
3930
3931 static int CheckPoint(FindSel *fs, SplinePoint *sp, SplineSet *spl) {
3932
3933 if ( fs->xl<=sp->me.x && fs->xh>=sp->me.x &&
3934 fs->yl<=sp->me.y && fs->yh >= sp->me.y ) {
3935 fs->p->sp = sp;
3936 fs->p->spline = NULL;
3937 fs->p->anysel = true;
3938 fs->p->spl = spl;
3939 if ( !fs->seek_controls )
3940 return( true );
3941 }
3942 if ( (sp->selected && fs->select_controls)
3943 || fs->all_controls
3944 || fs->alwaysshowcontrolpoints )
3945 {
3946 int seln=false, selp=false;
3947 if ( fs->c_xl<=sp->nextcp.x && fs->c_xh>=sp->nextcp.x &&
3948 fs->c_yl<=sp->nextcp.y && fs->c_yh >= sp->nextcp.y )
3949 seln = true;
3950 if ( fs->c_xl<=sp->prevcp.x && fs->c_xh>=sp->prevcp.x &&
3951 fs->c_yl<=sp->prevcp.y && fs->c_yh >= sp->prevcp.y )
3952 selp = true;
3953 if ( seln && selp ) {
3954 /* Select the one with a spline attached. */
3955 if ( sp->prev!=NULL && sp->next==NULL )
3956 seln = false;
3957 }
3958 if ( seln ) {
3959 fs->p->sp = sp;
3960 fs->p->spline = NULL;
3961 fs->p->spl = spl;
3962 fs->p->nextcp = true;
3963 fs->p->anysel = true;
3964 fs->p->cp = sp->nextcp;
3965 if ( sp->nonextcp && (sp->pointtype==pt_curve || sp->pointtype==pt_hvcurve)) {
3966 fs->p->cp.x = sp->me.x + (sp->me.x-sp->prevcp.x);
3967 fs->p->cp.y = sp->me.y + (sp->me.y-sp->prevcp.y);
3968 }
3969 sp->selected = true;
3970 sp->nextcpselected = true;
3971 return( true );
3972 } else if ( selp ) {
3973 fs->p->sp = sp;
3974 fs->p->spline = NULL;
3975 fs->p->spl = spl;
3976 fs->p->prevcp = true;
3977 fs->p->anysel = true;
3978 fs->p->cp = sp->prevcp;
3979 if ( sp->noprevcp && (sp->pointtype==pt_curve || sp->pointtype==pt_hvcurve)) {
3980 fs->p->cp.x = sp->me.x + (sp->me.x-sp->nextcp.x);
3981 fs->p->cp.y = sp->me.y + (sp->me.y-sp->nextcp.y);
3982 }
3983 sp->selected = true;
3984 sp->prevcpselected = true;
3985 return( true );
3986 }
3987 }
3988 return( false );
3989 }
3990
3991 static int CheckSpline(FindSel *fs, Spline *spline, SplineSet *spl) {
3992
3993 /* Anything else is better than a spline */
3994 if ( fs->p->anysel )
3995 return( false );
3996
3997 if ( NearSpline(fs,spline)) {
3998 fs->p->spline = spline;
3999 fs->p->spl = spl;
4000 fs->p->anysel = true;
4001 fs->p->spiro_index = SplineT2SpiroIndex(spline,fs->p->t,spl);
4002 return( false /*true*/ ); /* Check if there's a point where we are first */
4003 /* if there is use it, if not (because anysel is true) we'll fall back */
4004 /* here */
4005 }
4006
4007 return( false );
4008 }
4009
4010 static int InImage( FindSel *fs, ImageList *img) {
4011 int x,y;
4012
4013 x = floor((fs->p->cx-img->xoff)/img->xscale);
4014 y = floor((img->yoff-fs->p->cy)/img->yscale);
4015 if ( x<0 || y<0 || x>=GImageGetWidth(img->image) || y>=GImageGetHeight(img->image))
4016 return ( false );
4017 if ( GImageGetPixelRGBA(img->image,x,y)<0x80000000 ) /* Transparent(ish) */
4018 return( false );
4019
4020 return( true );
4021 }
4022
4023 static int InSplineSet( FindSel *fs, SplinePointList *set,int inspiro) {
4024 SplinePointList *spl;
4025 Spline *spline, *first;
4026 int i;
4027
4028 for ( spl = set; spl!=NULL; spl = spl->next ) {
4029 if ( inspiro ) {
4030 for ( i=0; i<spl->spiro_cnt-1; ++i )
4031 if ( CheckSpiroPoint(fs,&spl->spiros[i],spl,i))
4032 return( true );
4033 first = NULL;
4034 for ( spline = spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next ) {
4035 if ( CheckSpline(fs,spline,spl), fs->p->anysel )
4036 return( true );
4037 if ( first==NULL ) first = spline;
4038 }
4039 } else {
4040 if ( CheckPoint(fs,spl->first,spl) && ( !fs->seek_controls || fs->p->nextcp || fs->p->prevcp )) {
4041 return( true );
4042 }
4043 first = NULL;
4044 for ( spline = spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next ) {
4045 if ( (CheckPoint(fs,spline->to,spl) && ( !fs->seek_controls || fs->p->nextcp || fs->p->prevcp )) ||
4046 ( CheckSpline(fs,spline,spl) && !fs->seek_controls )) {
4047 return( true );
4048 }
4049 if ( first==NULL ) first = spline;
4050 }
4051 }
4052 }
4053 return( fs->p->anysel );
4054 }
4055
4056 static int NearSplineSetPoints( FindSel *fs, SplinePointList *set,int inspiro) {
4057 SplinePointList *spl;
4058 Spline *spline, *first;
4059 int i;
4060
4061 for ( spl = set; spl!=NULL; spl = spl->next ) {
4062 if ( inspiro ) {
4063 for ( i=0; i<spl->spiro_cnt; ++i )
4064 if ( CheckSpiroPoint(fs,&spl->spiros[i],spl,i))
4065 return( true );
4066 } else {
4067 if ( CheckPoint(fs,spl->first,spl)) {
4068 return( true );
4069 }
4070 first = NULL;
4071 for ( spline = spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next ) {
4072 if ( CheckPoint(fs,spline->to,spl) ) {
4073 return( true );
4074 }
4075 if ( first==NULL ) first = spline;
4076 }
4077 }
4078 }
4079 return( fs->p->anysel );
4080 }
4081
4082 static int16_t MouseToCX( CharView *cv, int16_t mx )
4083 {
4084 CharViewTab* tab = CVGetActiveTab(cv);
4085 return( mx - tab->xoff ) / tab->scale;
4086 }
4087
4088
4089 static void SetFS( FindSel *fs, PressedOn *p, CharView *cv, GEvent *event) {
4090 CharViewTab* tab = CVGetActiveTab(cv);
4091 extern int snaptoint;
4092
4093 memset(p,'\0',sizeof(PressedOn));
4094 p->pressed = true;
4095
4096 memset(fs,'\0',sizeof(*fs));
4097 fs->p = p;
4098 p->x = event->u.mouse.x;
4099 p->y = event->u.mouse.y;
4100 p->cx = (event->u.mouse.x-tab->xoff)/tab->scale;
4101 p->cy = (cv->height-event->u.mouse.y-tab->yoff)/tab->scale;
4102
4103 fs->fudge = (cv->active_tool==cvt_ruler ? snapdistancemeasuretool : snapdistance)/tab->scale;
4104
4105 /* If they have really large control points then expand
4106 * the selection range to allow them to still click on the
4107 * very edge of the control point to select it.
4108 */
4109 if( prefs_cvEditHandleSize > prefs_cvEditHandleSize_default )
4110 {
4111 float delta = (prefs_cvEditHandleSize - prefs_cvEditHandleSize_default) / tab->scale;
4112 delta *= 1.5;
4113 fs->fudge += delta;
4114 }
4115
4116 fs->c_xl = fs->xl = p->cx - fs->fudge;
4117 fs->c_xh = fs->xh = p->cx + fs->fudge;
4118 fs->c_yl = fs->yl = p->cy - fs->fudge;
4119 fs->c_yh = fs->yh = p->cy + fs->fudge;
4120 if ( snaptoint ) {
4121 p->cx = rint(p->cx);
4122 p->cy = rint(p->cy);
4123 if ( fs->xl>p->cx - fs->fudge )
4124 fs->xl = p->cx - fs->fudge;
4125 if ( fs->xh < p->cx + fs->fudge )
4126 fs->xh = p->cx + fs->fudge;
4127 if ( fs->yl>p->cy - fs->fudge )
4128 fs->yl = p->cy - fs->fudge;
4129 if ( fs->yh < p->cy + fs->fudge )
4130 fs->yh = p->cy + fs->fudge;
4131 }
4132 }
4133
4134 int CVMouseAtSpline(CharView *cv,GEvent *event) {
4135 FindSel fs;
4136 int pressed = cv->p.pressed;
4137
4138 SetFS(&fs,&cv->p,cv,event);
4139 cv->p.pressed = pressed;
4140 return( InSplineSet(&fs,cv->b.layerheads[cv->b.drawmode]->splines,cv->b.sc->inspiro && hasspiro()));
4141 }
4142
4143 static GEvent *CVConstrainedMouseDown(CharView *cv,GEvent *event, GEvent *fake) {
4144 CharViewTab* tab = CVGetActiveTab(cv);
4145 SplinePoint *base;
4146 spiro_cp *basecp;
4147 int basex, basey, dx, dy;
4148 double basetruex, basetruey;
4149 int sign;
4150
4151 if ( !CVAnySelPoint(cv,&base,&basecp))
4152 return( event );
4153
4154 if ( base!=NULL ) {
4155 basetruex = base->me.x;
4156 basetruey = base->me.y;
4157 } else {
4158 basetruex = basecp->x;
4159 basetruey = basecp->y;
4160 }
4161 basex = tab->xoff + rint(basetruex*tab->scale);
4162 basey = -tab->yoff + cv->height - rint(basetruey*tab->scale);
4163
4164 dx= event->u.mouse.x-basex, dy = event->u.mouse.y-basey;
4165 sign = dx*dy<0?-1:1;
4166
4167 fake->u.mouse = event->u.mouse;
4168 if ( dx<0 ) dx = -dx; if ( dy<0 ) dy = -dy;
4169 if ( dy >= 2*dx ) {
4170 cv->p.x = fake->u.mouse.x = basex;
4171 cv->p.cx = basetruex ;
4172 if ( !(event->u.mouse.state&ksm_meta) &&
4173 ItalicConstrained && cv->b.sc->parent->italicangle!=0 ) {
4174 double off = tan(cv->b.sc->parent->italicangle*FF_PI/180)*
4175 (cv->p.cy-basetruey);
4176 double aoff = off<0 ? -off : off;
4177 if ( dx>=aoff*tab->scale/2 && (event->u.mouse.x-basex<0)!=(off<0) ) {
4178 cv->p.cx -= off;
4179 cv->p.x = fake->u.mouse.x = tab->xoff + rint(cv->p.cx*tab->scale);
4180 }
4181 }
4182 } else if ( dx >= 2*dy ) {
4183 fake->u.mouse.y = basey;
4184 cv->p.cy = basetruey;
4185 } else if ( dx > dy ) {
4186 fake->u.mouse.x = basex + sign * (event->u.mouse.y-cv->p.y);
4187 cv->p.cx = basetruex - sign * (cv->p.cy-basetruey);
4188 } else {
4189 fake->u.mouse.y = basey + sign * (event->u.mouse.x-cv->p.x);
4190 cv->p.cy = basetruey - sign * (cv->p.cx-basetruex);
4191 }
4192
4193 return( fake );
4194 }
4195
4196 static void CVSetConstrainPoint(CharView *cv, GEvent *event) {
4197 SplineSet *sel;
4198
4199 if ( (sel = CVAnySelPointList(cv))!=NULL ) {
4200 if ( sel->first->selected ) cv->p.constrain = sel->first->me;
4201 else cv->p.constrain = sel->last->me;
4202 } else if ( cv->p.sp!=NULL ) {
4203 cv->p.constrain = cv->p.sp->me;
4204 } else {
4205 cv->p.constrain.x = cv->info.x;
4206 cv->p.constrain.y = cv->info.y;
4207 }
4208 }
4209
4210 static void CVDoSnaps(CharView *cv, FindSel *fs) {
4211 PressedOn *p = fs->p;
4212
4213 if ( cv->b.drawmode!=dm_grid && cv->b.layerheads[dm_grid]->splines!=NULL ) {
4214 PressedOn temp;
4215 int oldseek = fs->seek_controls;
4216 temp = *p;
4217 fs->p = &temp;
4218 fs->seek_controls = false;
4219 if ( InSplineSet( fs, cv->b.layerheads[dm_grid]->splines,cv->b.sc->inspiro && hasspiro())) {
4220 if ( temp.spline!=NULL ) {
4221 p->cx = ((temp.spline->splines[0].a*temp.t+
4222 temp.spline->splines[0].b)*temp.t+
4223 temp.spline->splines[0].c)*temp.t+
4224 temp.spline->splines[0].d;
4225 p->cy = ((temp.spline->splines[1].a*temp.t+
4226 temp.spline->splines[1].b)*temp.t+
4227 temp.spline->splines[1].c)*temp.t+
4228 temp.spline->splines[1].d;
4229 } else if ( temp.sp!=NULL ) {
4230 p->cx = temp.sp->me.x;
4231 p->cy = temp.sp->me.y;
4232 }
4233 }
4234 fs->p = p;
4235 fs->seek_controls = oldseek;
4236 }
4237 if ( p->cx>-fs->fudge && p->cx<fs->fudge )
4238 p->cx = 0;
4239 else if ( p->cx>cv->b.sc->width-fs->fudge && p->cx<cv->b.sc->width+fs->fudge &&
4240 !cv->widthsel)
4241 p->cx = cv->b.sc->width;
4242 else if ( cv->widthsel && p!=&cv->p &&
4243 p->cx>cv->oldwidth-fs->fudge && p->cx<cv->oldwidth+fs->fudge )
4244 p->cx = cv->oldwidth;
4245 if ( p->cy>-fs->fudge && p->cy<fs->fudge )
4246 p->cy = 0;
4247 }
4248
4249 static int _CVTestSelectFromEvent(CharView *cv,FindSel *fs) {
4250 PressedOn temp;
4251 ImageList *img;
4252 int found;
4253
4254 found = InSplineSet(fs,cv->b.layerheads[cv->b.drawmode]->splines,cv->b.sc->inspiro && hasspiro());
4255
4256 if ( !found ) {
4257 RefChar *rf;
4258 temp = cv->p;
4259 fs->p = &temp;
4260 fs->seek_controls = false;
4261 for ( rf=cv->b.layerheads[cv->b.drawmode]->refs; rf!=NULL; rf = rf->next ) {
4262 if ( InSplineSet(fs,rf->layers[0].splines,cv->b.sc->inspiro && hasspiro())) {
4263 cv->p.ref = rf;
4264 cv->p.anysel = true;
4265 break;
4266 }
4267 }
4268 if ( cv->b.drawmode==dm_fore && ( cv->showanchor && !cv->p.anysel )) {
4269 AnchorPoint *ap, *found=NULL;
4270 /* I do this pecular search because: */
4271 /* 1) I expect there to be lots of times we get multiple */
4272 /* anchors at the same location */
4273 /* 2) The anchor points are drawn so that the bottommost */
4274 /* is displayed */
4275 for ( ap=cv->b.sc->anchor; ap!=NULL; ap=ap->next )
4276 if ( fs->xl<=ap->me.x && fs->xh>=ap->me.x &&
4277 fs->yl<=ap->me.y && fs->yh >= ap->me.y )
4278 found = ap;
4279 if ( found!=NULL ) {
4280 cv->p.ap = found;
4281 cv->p.anysel = true;
4282 }
4283 }
4284 for ( img = cv->b.layerheads[cv->b.drawmode]->images; img!=NULL; img=img->next ) {
4285 if ( InImage(fs,img)) {
4286 cv->p.img = img;
4287 cv->p.anysel = true;
4288 break;
4289 }
4290 }
4291 }
4292 return( cv->p.anysel );
4293 }
4294
4295 int CVTestSelectFromEvent(CharView *cv,GEvent *event) {
4296 FindSel fs;
4297
4298 SetFS(&fs,&cv->p,cv,event);
4299 return( _CVTestSelectFromEvent(cv,&fs));
4300 }
4301
4302 /**
4303 * A cache for the selected spline point or spiro control point
4304 */
4305 typedef struct lastselectedpoint
4306 {
4307 SplinePoint *lastselpt;
4308 spiro_cp *lastselcp;
4309 } lastSelectedPoint;
4310
4311 static void CVMaybeCreateDraggingComparisonOutline( CharView* cv )
4312 {
4313 if (!prefs_create_dragging_comparison_outline)
4314 return;
4315 if (!cv)
4316 return;
4317 if (cv->p.pretransform_spl) {
4318 SplinePointListFree(cv->p.pretransform_spl);
4319 cv->p.pretransform_spl = NULL;
4320 }
4321
4322 Layer* l = cv->b.layerheads[cv->b.drawmode];
4323 if (!l || !l->splines)
4324 return;
4325
4326 if (cv->p.anysel) {
4327 SplinePointList *cur = NULL;
4328 for (SplinePointList *spl = l->splines; spl; spl = spl->next) {
4329 if (SplinePointListCheckSelected1(spl, cv->b.sc->inspiro && hasspiro(), NULL, false)) {
4330 if (cur == NULL) {
4331 cv->p.pretransform_spl = cur = SplinePointListCopy1(spl);
4332 } else {
4333 cur->next = SplinePointListCopy1(spl);
4334 cur = cur->next;
4335 }
4336 }
4337 }
4338 }
4339 }
4340
4341 static void CVSwitchActiveSC( CharView *cv, SplineChar* sc, int idx )
4342 {
4343 CharViewTab* tab = CVGetActiveTab(cv);
4344 int i=0;
4345 FontViewBase *fv = cv->b.fv;
4346 char buf[300];
4347
4348 TRACE("CVSwitchActiveSC() idx:%d active:%d\n", idx, cv->additionalCharsToShowActiveIndex );
4349 if( !sc )
4350 {
4351 sc = cv->additionalCharsToShow[i];
4352 if( !sc )
4353 return;
4354 }
4355 else
4356 {
4357 // test for setting something twice
4358 if( !idx && cv->additionalCharsToShowActiveIndex == idx )
4359 {
4360 if( cv->additionalCharsToShow[i] == sc )
4361 return;
4362 }
4363 }
4364
4365 cv->changedActiveGlyph = 1;
4366 TRACE("CVSwitchActiveSC(b) activeidx:%d newidx:%d\n", cv->additionalCharsToShowActiveIndex, idx );
4367 for( i=0; i < additionalCharsToShowLimit; i++ )
4368 if( cv->additionalCharsToShow[i] )
4369 TRACE("CVSwitchActiveSC(b) toshow.. i:%d char:%s\n", i, cv->additionalCharsToShow[i]
4370 ? cv->additionalCharsToShow[i]->name : "N/A" );
4371
4372
4373 //
4374 // Work out how far we should scroll the panel to keep
4375 // the display from jumping around. First look right then
4376 // check left.
4377 int scroll_offset = 0;
4378 if( idx > cv->additionalCharsToShowActiveIndex )
4379 {
4380 SplineChar* xc = 0;
4381 int i = 0;
4382 scroll_offset = cv->b.sc->width;
4383 int ridx = cv->additionalCharsToShowActiveIndex+1;
4384 for( i=ridx; i < idx; i++ )
4385 {
4386 if((xc = cv->additionalCharsToShow[i]))
4387 scroll_offset += xc->width;
4388 }
4389 }
4390 if( idx < cv->additionalCharsToShowActiveIndex )
4391 {
4392 SplineChar* xc = 0;
4393 int i = 0;
4394 scroll_offset = 0;
4395 int ridx = cv->additionalCharsToShowActiveIndex-1;
4396 for( i=ridx; i >= idx; i-- )
4397 {
4398 if((xc = cv->additionalCharsToShow[i]))
4399 scroll_offset -= xc->width;
4400 }
4401 }
4402
4403
4404
4405
4406
4407 CVUnlinkView( cv );
4408 cv->b.sc = sc;
4409 cv->b.next = sc->views;
4410 cv->b.layerheads[dm_fore] = &sc->layers[ly_fore];
4411 cv->b.layerheads[dm_back] = &sc->layers[ly_back];
4412 cv->b.layerheads[dm_grid] = &fv->sf->grid;
4413 if ( !sc->parent->multilayer && fv->active_layer!=ly_fore ) {
4414 cv->b.layerheads[dm_back] = &sc->layers[fv->active_layer];
4415 cv->b.drawmode = dm_back;
4416 }
4417 CharIcon(cv,(FontView *) (cv->b.fv));
4418 char* title = CVMakeTitles(cv,buf,sizeof(buf));
4419 GDrawSetWindowTitles8(cv->gw,buf,title);
4420 CVInfoDraw(cv,cv->gw);
4421 free(title);
4422 _CVPaletteActivate(cv,true,false);
4423
4424 TRACE("CVSwitchActiveSC() idx:%d\n", idx );
4425
4426 cv->additionalCharsToShowActiveIndex = idx;
4427
4428 // update the select[i]on in the input text to reflect
4429 // the users currently selected char.
4430 {
4431 SplineFont* sf = cv->b.sc->parent;
4432 EncMap *map = ((FontView *) (cv->b.fv))->b.map;
4433 unichar_t *srctxt = GGadgetGetTitle( cv->charselector );
4434 int endsWithSlash = u_endswith( srctxt, c_to_u("/"));
4435
4436 unichar_t* p = 0;
4437 p = Wordlist_selectionClear( sf, map, srctxt );
4438 p = Wordlist_selectionAdd( sf, map, p, idx );
4439 if( endsWithSlash )
4440 uc_strcat( p, "/" );
4441
4442 // only update when the selection has changed.
4443 // updating this string is a non reversible operation if the
4444 // user is part way through typing some text.
4445 if( !Wordlist_selectionsEqual( srctxt, p ))
4446 {
4447 GGadgetSetTitle( cv->charselector, p );
4448 }
4449 }
4450
4451
4452 cv->b.next = sc->views;
4453 sc->views = &cv->b;
4454
4455 // Move the scrollbar so that it appears the selection
4456 // box has moved rather than all the characters.
4457 if( scroll_offset )
4458 CVHScrollSetPos( cv, tab->xoff + scroll_offset * tab->scale );
4459
4460 // if ( CVClearSel(cv))
4461 // SCUpdateAll(cv->b.sc);
4462
4463 }
4464
4465 static void CVMouseDown(CharView *cv, GEvent *event ) {
4466 FindSel fs;
4467 GEvent fake;
4468 lastSelectedPoint lastSel;
4469 memset( &lastSel, 0, sizeof(lastSelectedPoint));
4470
4471 if ( event->u.mouse.button==2 && event->u.mouse.device!=NULL &&
4472 strcmp(event->u.mouse.device,"stylus")==0 )
4473 return; /* I treat this more like a modifier key change than a button press */
4474
4475 if ( cv->expandedge != ee_none )
4476 GDrawSetCursor(cv->v,ct_mypointer);
4477 if ( event->u.mouse.button==3 )
4478 {
4479 /* context menu */
4480 CVToolsPopup(cv,event);
4481 return;
4482 }
4483
4484 TRACE("tool:%d pointer:%d ctl:%d alt:%d\n",
4485 cv->showing_tool,
4486 (cv->showing_tool == cvt_pointer),
4487 cv->activeModifierControl, cv->activeModifierAlt );
4488
4489 int8_t override_showing_tool = cvt_none;
4490 int8_t old_showing_tool = cv->showing_tool;
4491 if( cv->showing_tool == cvt_pointer
4492 && cv->activeModifierControl
4493 && cv->activeModifierAlt )
4494 {
4495 FindSel fs;
4496 SetFS(&fs,&cv->p,cv,event);
4497 int found = InSplineSet( &fs, cv->b.layerheads[cv->b.drawmode]->splines,
4498 cv->b.sc->inspiro && hasspiro());
4499 TRACE("in spline set:%d cv->p.sp:%p\n", found, cv->p.sp );
4500
4501 //
4502 // Only overwrite to create a point if the user has clicked a spline.
4503 //
4504 if( found && !cv->p.sp )
4505 override_showing_tool = cvt_curve;
4506 }
4507
4508 if( cv->charselector && cv->charselector == GWindowGetFocusGadgetOfWindow(cv->gw))
4509 GWindowClearFocusGadgetOfWindow(cv->gw);
4510
4511 update_spacebar_hand_tool(cv);
4512
4513 CVToolsSetCursor(cv,event->u.mouse.state|(1<<(7+event->u.mouse.button)), event->u.mouse.device );
4514 if( override_showing_tool != cvt_none )
4515 cv->showing_tool = override_showing_tool;
4516 cv->active_tool = cv->showing_tool;
4517 cv->needsrasterize = false;
4518 cv->recentchange = false;
4519
4520
4521 SetFS(&fs,&cv->p,cv,event);
4522 if ( event->u.mouse.state&ksm_shift )
4523 event = CVConstrainedMouseDown(cv,event,&fake);
4524
4525 if ( cv->active_tool == cvt_pointer ) {
4526 fs.select_controls = true;
4527 if ( event->u.mouse.state&ksm_meta ) {
4528 fs.seek_controls = true;
4529 /* Allow more slop looking for control points if they asked for them */
4530 fs.c_xl -= fs.fudge; fs.c_xh += fs.fudge;
4531 fs.c_yl -= fs.fudge; fs.c_yh += fs.fudge;
4532 }
4533 if ( cv->showpointnumbers && cv->b.layerheads[cv->b.drawmode]->order2 )
4534 fs.all_controls = true;
4535 fs.alwaysshowcontrolpoints = cv->alwaysshowcontrolpoints;
4536 lastSel.lastselpt = cv->lastselpt;
4537 lastSel.lastselcp = cv->lastselcp;
4538 cv->lastselpt = NULL;
4539 cv->lastselcp = NULL;
4540 _CVTestSelectFromEvent(cv,&fs);
4541 fs.p = &cv->p;
4542
4543 // TRACE("cvmousedown tab->xoff:%d\n", tab->xoff );
4544 // TRACE("cvmousedown x:%d y:%d\n", event->u.mouse.x, event->u.mouse.y );
4545
4546 if( !cv->p.anysel && cv->b.drawmode != dm_grid )
4547 {
4548 // If we are in left-right arrow cursor mode to move
4549 // those bearings then don't even think about changing
4550 // the char right now.
4551 if( !CVNearRBearingLine( cv, cv->p.cx, fs.fudge )
4552 && !CVNearLBearingLine( cv, cv->p.cx, fs.fudge ))
4553 {
4554 int i=0;
4555 FindSel fsadjusted = fs;
4556 fsadjusted.c_xl -= 2*fsadjusted.fudge;
4557 fsadjusted.c_xh += 2*fsadjusted.fudge;
4558 fsadjusted.xl -= 2*fsadjusted.fudge;
4559 fsadjusted.xh += 2*fsadjusted.fudge;
4560 SplineChar* xc = 0;
4561 int xcidx = -1;
4562 int borderFudge = 20;
4563
4564 {
4565 int offset = cv->b.sc->width;
4566 int cumulativeLeftSideBearing = 0;
4567 // TRACE("first offset:%d original cx:%f \n", offset, fsadjusted.p->cx );
4568 int ridx = cv->additionalCharsToShowActiveIndex+1;
4569 for( i=ridx; i < additionalCharsToShowLimit; i++ )
4570 {
4571 if( i == cv->additionalCharsToShowActiveIndex )
4572 continue;
4573 xc = cv->additionalCharsToShow[i];
4574 if( !xc )
4575 break;
4576 int OffsetForDoingCharNextToActive = 0;
4577 if( i == ridx )
4578 {
4579 OffsetForDoingCharNextToActive = borderFudge;
4580 }
4581
4582
4583 cumulativeLeftSideBearing += offset;
4584 /* TRACE("1 adj. x:%f %f\n",fsadjusted.xl,fsadjusted.xh); */
4585 /* TRACE("1 adj.cx:%f %f\n",fsadjusted.c_xl,fsadjusted.c_xh); */
4586 /* TRACE("1 p. cx:%f %f\n",fsadjusted.p->cx,fsadjusted.p->cy ); */
4587 /* fsadjusted.c_xl -= offset; */
4588 /* fsadjusted.c_xh -= offset; */
4589 /* fsadjusted.xl -= offset; */
4590 /* fsadjusted.xh -= offset; */
4591 /* TRACE("2 adj. x:%f %f\n",fsadjusted.xl,fsadjusted.xh); */
4592 /* TRACE("2 adj.cx:%f %f\n",fsadjusted.c_xl,fsadjusted.c_xh); */
4593 /* TRACE("2 p. cx:%f %f\n",fsadjusted.p->cx,fsadjusted.p->cy ); */
4594 /* int found = InSplineSet( &fsadjusted, */
4595 /* xc->layers[cv->b.drawmode-1].splines, */
4596 /* xc->inspiro && hasspiro()); */
4597 TRACE("A:%d\n", cumulativeLeftSideBearing );
4598 TRACE("B:%f\n", fsadjusted.p->cx );
4599 TRACE("C:%d\n", cumulativeLeftSideBearing+xc->width );
4600 int found = IS_IN_ORDER3(
4601 cumulativeLeftSideBearing + OffsetForDoingCharNextToActive,
4602 fsadjusted.p->cx,
4603 cumulativeLeftSideBearing+xc->width );
4604 TRACE("CVMOUSEDOWN i:%d found:%d\n", i, found );
4605 if( found )
4606 {
4607 TRACE("FOUND FOUND FOUND FOUND FOUND FOUND FOUND \n");
4608
4609 xcidx = i;
4610 // CVChangeSC(cv,xc);
4611 break;
4612 }
4613
4614 offset = xc->width;
4615 }
4616 }
4617
4618 fsadjusted = fs;
4619 fsadjusted.c_xl -= 2*fsadjusted.fudge;
4620 fsadjusted.c_xh += 2*fsadjusted.fudge;
4621 fsadjusted.xl -= 2*fsadjusted.fudge;
4622 fsadjusted.xh += 2*fsadjusted.fudge;
4623
4624 if( !xc && cv->additionalCharsToShowActiveIndex > 0 )
4625 {
4626 xc = cv->additionalCharsToShow[cv->additionalCharsToShowActiveIndex-1];
4627 int cumulativeLeftSideBearing = 0;
4628 // TRACE("first offset:%d original cx:%f \n", offset, fsadjusted.p->cx );
4629 int lidx = cv->additionalCharsToShowActiveIndex-1;
4630 for( i=lidx; i>=0; i-- )
4631 {
4632 if( i == cv->additionalCharsToShowActiveIndex )
4633 continue;
4634 xc = cv->additionalCharsToShow[i];
4635 if( !xc )
4636 break;
4637 cumulativeLeftSideBearing -= xc->width;
4638 int OffsetForDoingCharNextToActive = 0;
4639 if( i == lidx )
4640 {
4641 OffsetForDoingCharNextToActive = borderFudge;
4642 }
4643
4644 /* TRACE("1 adj. x:%f %f\n",fsadjusted.xl,fsadjusted.xh); */
4645 /* TRACE("1 adj.cx:%f %f\n",fsadjusted.c_xl,fsadjusted.c_xh); */
4646 /* TRACE("1 p. cx:%f %f\n",fsadjusted.p->cx,fsadjusted.p->cy ); */
4647 /* fsadjusted.c_xl += offset; */
4648 /* fsadjusted.c_xh += offset; */
4649 /* fsadjusted.xl += offset; */
4650 /* fsadjusted.xh += offset; */
4651 /* TRACE("2 adj. x:%f %f\n",fsadjusted.xl,fsadjusted.xh); */
4652 /* TRACE("2 adj.cx:%f %f\n",fsadjusted.c_xl,fsadjusted.c_xh); */
4653 /* TRACE("2 p. cx:%f %f\n",fsadjusted.p->cx,fsadjusted.p->cy ); */
4654 /* int found = InSplineSet( &fsadjusted, */
4655 /* xc->layers[cv->b.drawmode-1].splines, */
4656 /* xc->inspiro && hasspiro()); */
4657 TRACE("A:%d\n", cumulativeLeftSideBearing );
4658 TRACE("B:%f\n", fsadjusted.p->cx );
4659 TRACE("C:%d\n", cumulativeLeftSideBearing+xc->width );
4660 int found = IS_IN_ORDER3(
4661 cumulativeLeftSideBearing,
4662 fsadjusted.p->cx,
4663 cumulativeLeftSideBearing + xc->width - OffsetForDoingCharNextToActive );
4664
4665 TRACE("cvmousedown i:%d found:%d\n", i, found );
4666 if( found )
4667 {
4668 TRACE("FOUND FOUND FOUND FOUND FOUND FOUND FOUND i:%d\n", i);
4669 xcidx = i;
4670 break;
4671 }
4672
4673 }
4674 }
4675
4676 TRACE("have xc:%p xcidx:%d\n", xc, xcidx );
4677 TRACE(" idx:%d active:%d\n", xcidx, cv->additionalCharsToShowActiveIndex );
4678 if( xc && xcidx >= 0 )
4679 {
4680 CVSwitchActiveSC( cv, xc, xcidx );
4681 GDrawRequestExpose(cv->v,NULL,false);
4682 return;
4683 }
4684 }
4685 }
4686
4687
4688
4689 } else if ( cv->active_tool == cvt_curve || cv->active_tool == cvt_corner ||
4690 cv->active_tool == cvt_tangent || cv->active_tool == cvt_hvcurve ||
4691 cv->active_tool == cvt_pen || cv->active_tool == cvt_ruler )
4692 {
4693 /* Snap to points and splines */
4694 InSplineSet(&fs,cv->b.layerheads[cv->b.drawmode]->splines,cv->b.sc->inspiro && hasspiro());
4695 if ( fs.p->sp==NULL && fs.p->spline==NULL )
4696 CVDoSnaps(cv,&fs);
4697 } else if ( cv->active_tool==cvt_scale ) {
4698 /* Ignore scale-tool clicks that miss the bounding box handles. */
4699 if ( !CVScaleHandlePress(cv, CVSCALE_HANDLE_FUDGE/CVGetActiveTab(cv)->scale) ) {
4700 cv->p.pressed = false;
4701 cv->active_tool = cvt_none;
4702 cv->showing_tool = old_showing_tool;
4703 return;
4704 }
4705 } else {
4706 /* Other transform tools still snap to points. */
4707 NearSplineSetPoints(&fs,cv->b.layerheads[cv->b.drawmode]->splines,cv->b.sc->inspiro && hasspiro());
4708 if ( fs.p->sp==NULL && fs.p->spline==NULL )
4709 CVDoSnaps(cv,&fs);
4710 }
4711
4712 cv->e.x = event->u.mouse.x; cv->e.y = event->u.mouse.y;
4713 if ( cv->p.sp!=NULL ) {
4714 BasePoint *p;
4715 if ( cv->p.nextcp )
4716 p = &cv->p.sp->nextcp;
4717 else if ( cv->p.prevcp )
4718 p = &cv->p.sp->prevcp;
4719 else
4720 p = &cv->p.sp->me;
4721 cv->info.x = p->x;
4722 cv->info.y = p->y;
4723 cv->p.cx = p->x; cv->p.cy = p->y;
4724 } else if ( cv->p.spiro!=NULL ) {
4725 cv->info.x = cv->p.spiro->x;
4726 cv->info.y = cv->p.spiro->y;
4727 cv->p.cx = cv->p.spiro->x; cv->p.cy = cv->p.spiro->y;
4728 } else {
4729 cv->info.x = cv->p.cx;
4730 cv->info.y = cv->p.cy;
4731 }
4732 cv->info_within = true;
4733 CVInfoDraw(cv,cv->gw);
4734 CVSetConstrainPoint(cv,event);
4735
4736 switch ( cv->active_tool ) {
4737 case cvt_pointer:
4738 CVMouseDownPointer(cv, &fs, event);
4739 CVMaybeCreateDraggingComparisonOutline( cv );
4740 cv->lastselpt = fs.p->sp;
4741 cv->lastselcp = fs.p->spiro;
4742 break;
4743 case cvt_magnify: case cvt_minify:
4744 //When scroll zooming, the old showing tool is the normal pointer.
4745 old_showing_tool = cv->active_tool;
4746 break;
4747 case cvt_hand:
4748 CVMouseDownHand(cv);
4749 break;
4750 case cvt_freehand:
4751 CVMouseDownFreeHand(cv,event);
4752 break;
4753 case cvt_curve: case cvt_corner: case cvt_tangent: case cvt_pen:
4754 case cvt_hvcurve:
4755 CVMouseDownPoint(cv,event);
4756 break;
4757 case cvt_ruler:
4758 CVMouseDownRuler(cv,event);
4759 break;
4760 case cvt_rotate: case cvt_flip: case cvt_scale: case cvt_skew:
4761 case cvt_3d_rotate: case cvt_perspective:
4762 CVMouseDownTransform(cv);
4763 break;
4764 case cvt_knife:
4765 CVMouseDownKnife(cv);
4766 break;
4767 case cvt_rect: case cvt_elipse: case cvt_poly: case cvt_star:
4768 CVMouseDownShape(cv,event);
4769 break;
4770 }
4771 cv->showing_tool = old_showing_tool;
4772 }
4773
4774 static void _SCHintsChanged(SplineChar *sc) {
4775 struct splinecharlist *dlist;
4776
4777 if ( !sc->changedsincelasthinted ) {
4778 sc->changedsincelasthinted = true;
4779 FVMarkHintsOutOfDate(sc);
4780 }
4781
4782 for ( dlist=sc->dependents; dlist!=NULL; dlist=dlist->next )
4783 _SCHintsChanged(dlist->sc);
4784 }
4785
4786 static void SC_HintsChanged(SplineChar *sc) {
4787 struct splinecharlist *dlist;
4788 int was = sc->changedsincelasthinted;
4789
4790 if ( sc->parent->onlybitmaps || sc->parent->multilayer || sc->parent->strokedfont )
4791 return;
4792 sc->changedsincelasthinted = false; /* We just applied a hinting change */
4793 if ( !sc->changed ) {
4794 sc->changed = true;
4795 FVToggleCharChanged(sc);
4796 SCRefreshTitles(sc);
4797 if ( !sc->parent->changed ) {
4798 sc->parent->changed = true;
4799 FVSetTitles(sc->parent);
4800 }
4801 }
4802 for ( dlist=sc->dependents; dlist!=NULL; dlist=dlist->next )
4803 _SCHintsChanged(dlist->sc);
4804 if ( was ) {
4805 FontView *fvs;
4806 for ( fvs = (FontView *) (sc->parent->fv); fvs!=NULL; fvs=(FontView *) (fvs->b.nextsame) )
4807 GDrawRequestExpose(fvs->v,NULL,false);
4808 }
4809 }
4810
4811 void CVSetCharChanged(CharView *cv,int changed) {
4812 SplineFont *sf = cv->b.fv->sf;
4813 SplineChar *sc = cv->b.sc;
4814 int oldchanged = sf->changed;
4815 /* A changed argument of 2 means the outline didn't change, but something */
4816 /* else (width, anchorpoint) did */
4817 int cvlayer = CVLayer((CharViewBase *) cv);
4818
4819 if ( changed )
4820 SFSetModTime(sf);
4821 if ( cv->b.drawmode==dm_grid ) {
4822 if ( changed ) {
4823 sf->changed = true;
4824 if ( sf->cidmaster!=NULL )
4825 sf->cidmaster->changed = true;
4826 }
4827 } else {
4828 if ( cv->b.drawmode==dm_fore && changed==1 ) {
4829 sf->onlybitmaps = false;
4830 }
4831 SCTickValidationState(cv->b.sc,cvlayer);
4832 if ( (sc->changed==0) != (changed==0) ) {
4833 sc->changed = (changed!=0);
4834 FVToggleCharChanged(sc);
4835 SCRefreshTitles(sc);
4836 if ( changed ) {
4837 sf->changed = true;
4838 if ( sf->cidmaster!=NULL )
4839 sf->cidmaster->changed = true;
4840 }
4841 }
4842 if ( changed==1 ) {
4843 instrcheck(sc,cvlayer);
4844 /*SCDeGridFit(sc);*/
4845 if ( sc->parent->onlybitmaps )
4846 /* Do nothing */;
4847 else if ( sc->parent->multilayer || sc->parent->strokedfont || sc->layers[cvlayer].order2 )
4848 sc->changed_since_search = true;
4849 else if ( cv->b.drawmode==dm_fore ) {
4850 sc->changed_since_search = true;
4851 _SCHintsChanged(cv->b.sc);
4852 }
4853 sc->changed_since_autosave = true;
4854 sf->changed_since_autosave = true;
4855 sf->changed_since_xuidchanged = true;
4856 if ( sf->cidmaster!=NULL ) {
4857 sf->cidmaster->changed_since_autosave = true;
4858 sf->cidmaster->changed_since_xuidchanged = true;
4859 }
4860 }
4861 if ( cv->b.drawmode!=dm_grid ) {
4862 cv->needsrasterize = true;
4863 }
4864 }
4865 cv->recentchange = true;
4866 if ( !oldchanged )
4867 FVSetTitles(sf);
4868 }
4869
4870 void SCClearSelPt(SplineChar *sc) {
4871 CharView *cv;
4872
4873 for ( cv=(CharView *) (sc->views); cv!=NULL; cv=(CharView *) (cv->b.next) ) {
4874 cv->lastselpt = cv->p.sp = NULL;
4875 cv->p.spiro = cv->lastselcp = NULL;
4876 }
4877 }
4878
4879 static void _SC_CharChangedUpdate(SplineChar *sc,int layer,int changed) {
4880 SplineFont *sf = sc->parent;
4881 extern int updateflex;
4882 /* layer might be ly_none or ly_all */
4883
4884 if ( layer>=sc->layer_cnt ) {
4885 IError( "Bad layer in _SC_CharChangedUpdate");
4886 layer = ly_fore;
4887 }
4888 if ( layer>=0 && !sc->layers[layer].background )
4889 TTFPointMatches(sc,layer,true);
4890 if ( changed != -1 ) {
4891 sc->changed_since_autosave = true;
4892 SFSetModTime(sf);
4893 if ( (sc->changed==0) != (changed==0) ) {
4894 sc->changed = (changed!=0);
4895 if ( changed && layer>=ly_fore && (sc->layers[layer].splines!=NULL || sc->layers[layer].refs!=NULL))
4896 sc->parent->onlybitmaps = false;
4897 FVToggleCharChanged(sc);
4898 SCRefreshTitles(sc);
4899 }
4900 if ( !sf->changed ) {
4901 sf->changed = true;
4902 if ( sf->cidmaster )
4903 sf->cidmaster->changed = true;
4904 FVSetTitles(sf);
4905 }
4906 if ( changed && layer>=0 && !sc->layers[layer].background && sc->layers[layer].order2 ) {
4907 instrcheck(sc,layer);
4908 SCReGridFit(sc,layer);
4909 }
4910 if ( !sc->parent->onlybitmaps && !sc->parent->multilayer &&
4911 changed==1 && !sc->parent->strokedfont &&
4912 layer>=0 &&
4913 !sc->layers[layer].background && !sc->layers[layer].order2 )
4914 _SCHintsChanged(sc);
4915 sc->changed_since_search = true;
4916 sf->changed = true;
4917 sf->changed_since_autosave = true;
4918 sf->changed_since_xuidchanged = true;
4919 if ( layer>=0 )
4920 SCTickValidationState(sc,layer);
4921 }
4922 if ( sf->cidmaster!=NULL )
4923 sf->cidmaster->changed = sf->cidmaster->changed_since_autosave =
4924 sf->cidmaster->changed_since_xuidchanged = true;
4925 SCRegenDependents(sc,ly_all); /* All chars linked to this one need to get the new splines */
4926 if ( updateflex && (CharView *) (sc->views)!=NULL && layer>=ly_fore )
4927 SplineCharIsFlexible(sc,layer);
4928 SCUpdateAll(sc);
4929 SCLayersChange(sc);
4930 }
4931
4932 static void SC_CharChangedUpdate(SplineChar *sc,int layer) {
4933 _SC_CharChangedUpdate(sc,layer,true);
4934 }
4935
4936 static void _CV_CharChangedUpdate(CharView *cv,int changed) {
4937 extern int updateflex;
4938 FontView *fv;
4939 int cvlayer = CVLayer((CharViewBase *) cv);
4940
4941 CVSetCharChanged(cv,changed);
4942 CVLayerChange(cv);
4943 if ( cv->needsrasterize ) {
4944 TTFPointMatches(cv->b.sc,cvlayer,true); /* Must precede regen dependents, as this can change references */
4945 SCRegenDependents(cv->b.sc,cvlayer); /* All chars linked to this one need to get the new splines */
4946 if ( cv->b.layerheads[cv->b.drawmode]->order2 )
4947 SCReGridFit(cv->b.sc,cvlayer);
4948 if ( updateflex && cvlayer!=ly_grid && !cv->b.layerheads[cv->b.drawmode]->background )
4949 SplineCharIsFlexible(cv->b.sc,cvlayer);
4950 SCUpdateAll(cv->b.sc);
4951 for ( fv = (FontView *) (cv->b.sc->parent->fv); fv!=NULL; fv=(FontView *) (fv->b.nextsame) )
4952 FVRegenChar(fv,cv->b.sc);
4953 cv->needsrasterize = false;
4954 } else if ( cv->b.drawmode!=dm_grid ) {
4955 /* If we changed the background then only views of this character */
4956 /* need to know about it. No dependents needed, but why write */
4957 /* another routine for a rare case... */
4958 SCUpdateAll(cv->b.sc);
4959 } else /* if ( cv->b.drawmode==dm_grid )*/ {
4960 /* If we changed the grid then any character needs to know it */
4961 FVRedrawAllCharViewsSF(cv->b.sc->parent);
4962 }
4963 if ( cv->showpointnumbers || cv->show_ft_results )
4964 SCNumberPoints(cv->b.sc, cvlayer);
4965 cv->recentchange = false;
4966 cv->p.sp = NULL; /* Might have been deleted */
4967 }
4968
4969 static void CV_CharChangedUpdate(CharView *cv) {
4970 _CV_CharChangedUpdate(cv,true);
4971 }
4972
4973 static void CVMouseMove(CharView *cv, GEvent *event ) {
4974 CharViewTab* tab = CVGetActiveTab(cv);
4975 real cx, cy;
4976 PressedOn p;
4977 FindSel fs;
4978 GEvent fake;
4979 int stop_motion = false;
4980 int has_spiro = hasspiro();
4981
4982 /* Debug wacom !!!! */
4983 /* TRACE( "dev=%s (%d,%d) 0x%x\n", event->u.mouse.device!=NULL?event->u.mouse.device:"<None>", */
4984 /* event->u.mouse.x, event->u.mouse.y, event->u.mouse.state); */
4985
4986 if ( event->u.mouse.device!=NULL )
4987 CVToolsSetCursor(cv,event->u.mouse.state,event->u.mouse.device);
4988
4989 if ( !cv->p.pressed ) {
4990 CVUpdateInfo(cv, event);
4991 if ( cv->showing_tool==cvt_pointer || cv->showing_tool==cvt_scale || cv->b1_tool==cvt_scale ) {
4992 /* Pointer and scale tools both use resize cursors over draggable handles */
4993 CVCheckResizeCursors(cv);
4994 if ( cv->showing_tool==cvt_pointer && cv->dv!=NULL )
4995 CVDebugPointPopup(cv);
4996 } else if ( cv->showing_tool == cvt_ruler )
4997 CVMouseMoveRuler(cv,event);
4998 return;
4999 }
5000
5001 //GDrawRequestExpose(cv->v,NULL,false); /* TBD, hack to clear ruler */
5002
5003 SetFS(&fs,&p,cv,event);
5004 if ( cv->active_tool == cvt_freehand )
5005 /* freehand does its own kind of constraining */;
5006 else if ( (event->u.mouse.state&ksm_shift) &&
5007 !cv->p.rubberbanding &&
5008 cv->active_tool!=cvt_scale) {
5009 /* Constrained */
5010
5011 fake.u.mouse = event->u.mouse;
5012 if ( ((event->u.mouse.state&ksm_meta) ||
5013 (!cv->cntrldown && (event->u.mouse.state&ksm_control))) &&
5014 (cv->p.nextcp || cv->p.prevcp)) {
5015 real dot = (cv->p.cp.x-cv->p.constrain.x)*(p.cx-cv->p.constrain.x) +
5016 (cv->p.cp.y-cv->p.constrain.y)*(p.cy-cv->p.constrain.y);
5017 real len = (cv->p.cp.x-cv->p.constrain.x)*(cv->p.cp.x-cv->p.constrain.x)+
5018 (cv->p.cp.y-cv->p.constrain.y)*(cv->p.cp.y-cv->p.constrain.y);
5019 if ( len!=0 ) {
5020 dot /= len;
5021 /* constrain control point to same angle with respect to base point*/
5022 if ( dot<0 ) dot = 0;
5023 p.cx = cv->p.constrain.x + dot*(cv->p.cp.x-cv->p.constrain.x);
5024 p.cy = cv->p.constrain.y + dot*(cv->p.cp.y-cv->p.constrain.y);
5025 p.x = fake.u.mouse.x = tab->xoff + rint(p.cx*tab->scale);
5026 p.y = fake.u.mouse.y = -tab->yoff + cv->height - rint(p.cy*tab->scale);
5027 }
5028 } else {
5029 /* Constrain mouse to hor/vert/45 from base point */
5030 int basex = cv->active_tool!=cvt_hand ? tab->xoff + rint(cv->p.constrain.x*tab->scale) : cv->p.x;
5031 int basey = cv->active_tool!=cvt_hand ?-tab->yoff + cv->height - rint(cv->p.constrain.y*tab->scale) : cv->p.y;
5032 int dx= event->u.mouse.x-basex, dy = event->u.mouse.y-basey;
5033 int sign = dx*dy<0?-1:1;
5034 double aspect = 1.0;
5035
5036 if ( dx<0 ) dx = -dx; if ( dy<0 ) dy = -dy;
5037 if ( cv->p.img!=NULL && cv->p.img->bb.minx!=cv->p.img->bb.maxx )
5038 aspect = (cv->p.img->bb.maxy - cv->p.img->bb.miny) / (cv->p.img->bb.maxx - cv->p.img->bb.minx);
5039 else if ( cv->p.ref!=NULL && cv->p.ref->bb.minx!=cv->p.ref->bb.maxx )
5040 aspect = (cv->p.ref->bb.maxy - cv->p.ref->bb.miny) / (cv->p.ref->bb.maxx - cv->p.ref->bb.minx);
5041 if ( dy >= 2*dx ) {
5042 p.x = fake.u.mouse.x = basex;
5043 p.cx = cv->p.constrain.x;
5044 if ( ItalicConstrained && cv->b.sc->parent->italicangle!=0 ) {
5045 double off = tan(cv->b.sc->parent->italicangle*FF_PI/180)*
5046 (p.cy-cv->p.constrain.y);
5047 double aoff = off<0 ? -off : off;
5048 if ( dx>=aoff*tab->scale/2 && (event->u.mouse.x-basex<0)!=(off<0) ) {
5049 p.cx -= off;
5050 p.x = fake.u.mouse.x = tab->xoff + rint(p.cx*tab->scale);
5051 }
5052 }
5053 } else if ( dx >= 2*dy ) {
5054 p.y = fake.u.mouse.y = basey;
5055 p.cy = cv->p.constrain.y;
5056 } else if ( dx > dy ) {
5057 p.x = fake.u.mouse.x = basex + sign * (event->u.mouse.y-basey)/aspect;
5058 p.cx = cv->p.constrain.x - sign * (p.cy-cv->p.constrain.y)/aspect;
5059 } else {
5060 p.y = fake.u.mouse.y = basey + sign * (event->u.mouse.x-basex)*aspect;
5061 p.cy = cv->p.constrain.y - sign * (p.cx-cv->p.constrain.x)*aspect;
5062 }
5063 }
5064 event = &fake;
5065 }
5066
5067 /* If we've changed the character (recentchange is true) we want to */
5068 /* snap to the original location, otherwise we'll keep snapping to the */
5069 /* current point as it moves across the screen (jerkily) */
5070 if ( cv->active_tool == cvt_hand || cv->active_tool == cvt_freehand )
5071 /* Don't snap to points */;
5072 else if ( !cv->joinvalid ||
5073 ((!cv->b.sc->inspiro || has_spiro) && !CheckPoint(&fs,&cv->joinpos,NULL)) ||
5074 ( cv->b.sc->inspiro && has_spiro && !CheckSpiroPoint(&fs,&cv->joincp,NULL,0))) {
5075 SplinePointList *spl;
5076 spl = cv->b.layerheads[cv->b.drawmode]->splines;
5077 if ( cv->recentchange && cv->active_tool==cvt_pointer &&
5078 cv->b.layerheads[cv->b.drawmode]->undoes!=NULL &&
5079 (cv->b.layerheads[cv->b.drawmode]->undoes->undotype==ut_state ||
5080 cv->b.layerheads[cv->b.drawmode]->undoes->undotype==ut_tstate ))
5081 spl = cv->b.layerheads[cv->b.drawmode]->undoes->u.state.splines;
5082 if ( cv->active_tool != cvt_knife && cv->active_tool != cvt_ruler ) {
5083 if ( cv->active_tool == cvt_pointer && ( cv->p.nextcp || cv->p.prevcp ))
5084 fs.select_controls = true;
5085 NearSplineSetPoints(&fs,spl,cv->b.sc->inspiro && has_spiro);
5086 } else
5087 InSplineSet(&fs,spl,cv->b.sc->inspiro && has_spiro);
5088 }
5089 /* p.sp and cv->p.sp may correspond to different undo states, thus being */
5090 /* different objects even while describing essentially the same point. */
5091 /* So compare point coordinates rather than the points themselves */
5092 if ( (cv->p.nextcp || cv->p.prevcp) && p.nextcp &&
5093 p.sp!=NULL && cv->p.sp != NULL &&
5094 p.sp->me.x == cv->p.sp->me.x && p.sp->me.y == cv->p.sp->me.y ) {
5095 /* If either control point selected, then snap to it or its brother */
5096 /* when close */
5097 p.cx = p.sp->nextcp.x;
5098 p.cy = p.sp->nextcp.y;
5099 } else if (( cv->p.nextcp || cv->p.prevcp) && p.prevcp &&
5100 p.sp!=NULL && cv->p.sp != NULL &&
5101 p.sp->me.x == cv->p.sp->me.x && p.sp->me.y == cv->p.sp->me.y ) {
5102 p.cx = p.sp->prevcp.x;
5103 p.cy = p.sp->prevcp.y;
5104 } else if ( p.sp!=NULL && p.sp!=cv->active_sp ) { /* Snap to points */
5105 p.cx = p.sp->me.x;
5106 p.cy = p.sp->me.y;
5107 } else if ( p.spiro!=NULL && p.spiro!=cv->active_cp ) {
5108 p.cx = p.spiro->x;
5109 p.cy = p.spiro->y;
5110 } else {
5111 // Require some movement before snapping objects with the pointer tool
5112 if ( !RealNear(cv->info.x,cv->p.cx) || !RealNear(cv->info.y,cv->p.cy) )
5113 CVDoSnaps(cv,&fs);
5114 }
5115 cx = (p.cx -cv->p.cx) / tab->scale;
5116 cy = (p.cy - cv->p.cy) / tab->scale;
5117 if ( cx<0 ) cx = -cx;
5118 if ( cy<0 ) cy = -cy;
5119
5120 /* If they haven't moved far from the start point, then snap to it */
5121 if ( cx+cy < 4 ) {
5122 p.x = cv->p.x; p.y = cv->p.y;
5123 }
5124
5125 cv->info.x = p.cx; cv->info.y = p.cy;
5126 cv->info_sp = p.sp;
5127 cv->info_spline = p.spline;
5128 cv->info_t = p.t;
5129 cv->e.x = event->u.mouse.x; cv->e.y = event->u.mouse.y;
5130 CVInfoDraw(cv,cv->gw);
5131
5132 switch ( cv->active_tool ) {
5133 case cvt_pointer:
5134 stop_motion = CVMouseMovePointer(cv,event);
5135 break;
5136 case cvt_magnify: case cvt_minify:
5137 if ( !cv->p.rubberbanding ) {
5138 cv->p.ex = cv->p.cx;
5139 cv->p.ey = cv->p.cy;
5140 }
5141 cv->p.ex = cv->info.x;
5142 cv->p.ey = cv->info.y;
5143 cv->p.rubberbanding = true;
5144 GDrawRequestExpose(cv->v, NULL, false);
5145 break;
5146 case cvt_hand:
5147 CVMouseMoveHand(cv,event);
5148 break;
5149 case cvt_freehand:
5150 CVMouseMoveFreeHand(cv,event);
5151 break;
5152 case cvt_curve: case cvt_corner: case cvt_tangent: case cvt_hvcurve:
5153 CVMouseMovePoint(cv,&p);
5154 break;
5155 case cvt_pen:
5156 CVMouseMovePen(cv,&p,event);
5157 break;
5158 case cvt_ruler:
5159 CVMouseMoveRuler(cv,event);
5160 break;
5161 case cvt_rotate: case cvt_flip: case cvt_scale: case cvt_skew:
5162 case cvt_3d_rotate: case cvt_perspective:
5163 CVMouseMoveTransform(cv);
5164 break;
5165 case cvt_knife:
5166 CVMouseMoveKnife(cv,&p);
5167 break;
5168 case cvt_rect: case cvt_elipse: case cvt_poly: case cvt_star:
5169 CVMouseMoveShape(cv);
5170 break;
5171 }
5172 if ( stop_motion ) {
5173 event->type = et_mouseup;
5174 CVMouseUp(cv,event);
5175 }
5176 }
5177
5178 static void CVMagnify(CharView *cv, real midx, real midy, int bigger, int LockPosition) {
5179 CharViewTab* tab = CVGetActiveTab(cv);
5180 static float scales[] = { 1, 2, 3, 4, 6, 8, 11, 16, 23, 32, 45, 64, 90, 128, 181, 256, 512, 1024, 0 };
5181 float oldscale;
5182 int i, j;
5183
5184 oldscale = tab->scale;
5185
5186 if ( bigger!=0 ) {
5187 if ( tab->scale>=1 ) {
5188 for ( i=0; scales[i]!=0 && tab->scale>scales[i]; ++i );
5189 if ( scales[i]==0 ) i=j= i-1;
5190 else if ( RealNear(scales[i],tab->scale) ) j=i;
5191 else if ( i!=0 && RealNear(scales[i-1],tab->scale) ) j= --i; /* Round errors! */
5192 else j = i-1;
5193 } else { real sinv = 1/tab->scale; int t;
5194 for ( i=0; scales[i]!=0 && sinv>scales[i]; ++i );
5195 if ( scales[i]==0 ) i=j= i-1;
5196 else if ( RealNear(scales[i],sinv) ) j=i;
5197 else if ( i!=0 && RealNear(scales[i-1],sinv) ) j= --i; /* Round errors! */
5198 else j = i-1;
5199 t = j;
5200 j = -i; i = -t;
5201 }
5202 if ( bigger==1 ) {
5203 if ( i==j ) ++i;
5204 if ( i>0 && scales[i]==0 ) --i;
5205 if ( i>=0 )
5206 tab->scale = scales[i];
5207 else
5208 tab->scale = 1/scales[-i];
5209 } else {
5210 if ( i==j ) --j;
5211 if ( j<0 && scales[-j]==0 ) ++j;
5212 if ( j>=0 )
5213 tab->scale = scales[j];
5214 else
5215 tab->scale = 1/scales[-j];
5216 }
5217 }
5218
5219 if (LockPosition) {
5220 float mousex = rint(midx * oldscale + tab->xoff);
5221 float mousey = rint(midy * oldscale + tab->yoff - cv->height);
5222 tab->xoff = mousex - midx*tab->scale;
5223 tab->yoff = mousey - midy*tab->scale + cv->height;
5224 }
5225 else {
5226 tab->xoff = -(rint(midx*tab->scale) - cv->width/2);
5227 tab->yoff = -(rint(midy*tab->scale) - cv->height/2);
5228 }
5229
5230 CVNewScale(cv);
5231 }
5232
5233 static void CVMouseUp(CharView *cv, GEvent *event ) {
5234 CharViewTab* tab = CVGetActiveTab(cv);
5235
5236 CVMouseMove(cv,event);
5237 if ( cv->pressed!=NULL ) {
5238 GDrawCancelTimer(cv->pressed);
5239 cv->pressed = NULL;
5240 }
5241 cv->p.pressed = false;
5242 SplinePointListFree(cv->p.pretransform_spl);
5243 cv->p.pretransform_spl = NULL;
5244 update_spacebar_hand_tool(cv);
5245
5246 if ( cv->p.rubberbanding ) {
5247 cv->p.rubberbanding = false;
5248 } else if ( cv->p.rubberlining ) {
5249 cv->p.rubberlining = false;
5250 }
5251
5252 // This is needed to allow characters to the left of the
5253 // active one to be picked with the mouse,
5254 // but outright it does mess with keyboard input changing BCP
5255 // so we only do it for mouse up to the left of the left side
5256 // bearing, because that click can not currently activate any BCP
5257 if ( cv->active_tool == cvt_pointer &&
5258 MouseToCX( cv, event->u.mouse.x ) < -2 )
5259 {
5260 // Since we allow clicking anywhere now, instead of having
5261 // to check if you clicked on a spline of a prev char,
5262 // then we don't need this. It also causes an issue with the arrow
5263 // keys moving a BCP on a spline left of the lbearing line.
5264 // (comment included just in case this click on spline feature is desired in the future)
5265 /* FindSel fs; */
5266 /* SetFS(&fs,&cv->p,cv,event); */
5267 /* _CVTestSelectFromEvent(cv,&fs); */
5268 /* fs.p = &cv->p; */
5269 }
5270
5271
5272 switch ( cv->active_tool ) {
5273 case cvt_pointer:
5274 CVMouseUpPointer(cv);
5275 break;
5276 case cvt_ruler:
5277 CVMouseUpRuler(cv,event);
5278 break;
5279 case cvt_hand:
5280 CVMouseUpHand(cv);
5281 break;
5282 case cvt_freehand:
5283 CVMouseUpFreeHand(cv,event);
5284 break;
5285 case cvt_curve: case cvt_corner: case cvt_tangent: case cvt_hvcurve:
5286 case cvt_pen:
5287 CVMouseUpPoint(cv,event);
5288 CVGridHandlePossibleFitChar( cv );
5289 break;
5290 case cvt_magnify: case cvt_minify:
5291 if ( cv->p.x>=event->u.mouse.x-6 && cv->p.x<=event->u.mouse.x+6 &&
5292 cv->p.y>=event->u.mouse.y-6 && cv->p.y<=event->u.mouse.y+6 ) {
5293 real cx, cy;
5294 cx = (event->u.mouse.x-tab->xoff)/tab->scale;
5295 cy = (cv->height-event->u.mouse.y-tab->yoff)/tab->scale ;
5296 CVMagnify(cv,cx,cy,cv->active_tool==cvt_minify?-1:1,event->u.mouse.button>3);
5297 } else {
5298 DBounds b;
5299 double oldscale = tab->scale;
5300 if ( cv->p.cx>cv->info.x ) {
5301 b.minx = cv->info.x;
5302 b.maxx = cv->p.cx;
5303 } else {
5304 b.minx = cv->p.cx;
5305 b.maxx = cv->info.x;
5306 }
5307 if ( cv->p.cy>cv->info.y ) {
5308 b.miny = cv->info.y;
5309 b.maxy = cv->p.cy;
5310 } else {
5311 b.miny = cv->p.cy;
5312 b.maxy = cv->info.y;
5313 }
5314 _CVFit(cv,&b,false);
5315 if ( oldscale==tab->scale ) {
5316 tab->scale += .5;
5317 CVNewScale(cv);
5318 }
5319 }
5320 break;
5321 case cvt_rotate: case cvt_flip: case cvt_scale: case cvt_skew:
5322 case cvt_3d_rotate: case cvt_perspective:
5323 CVMouseUpTransform(cv);
5324 break;
5325 case cvt_knife:
5326 CVMouseUpKnife(cv,event);
5327 break;
5328 case cvt_rect: case cvt_elipse: case cvt_poly: case cvt_star:
5329 CVMouseUpShape(cv);
5330 CVGridHandlePossibleFitChar( cv );
5331 break;
5332 }
5333 cv->active_tool = cvt_none;
5334 CVToolsSetCursor(cv,event->u.mouse.state&~(1<<(7+event->u.mouse.button)),event->u.mouse.device); /* X still has the buttons set in the state, even though we just released them. I don't want em */
5335 /* CharChangedUpdate is a rather blunt tool. When moving anchor points with */
5336 /* the mouse we need finer control than it provides */
5337 /* If recentchange is set then change should also be set, don't think we */
5338 /* need the full form of this call */
5339 if ( cv->needsrasterize || cv->recentchange )
5340 _CV_CharChangedUpdate(cv,2);
5341
5342 dlist_foreach( &cv->pointInfoDialogs, (dlist_foreach_func_type)PIChangePoint );
5343 }
5344
5345 static void CVTimer(CharView *cv,GEvent *event) {
5346 CharViewTab* tab = CVGetActiveTab(cv);
5347
5348 if ( event->u.timer.timer==cv->pressed ) {
5349 GEvent e;
5350 GDrawGetPointerPosition(cv->v,&e);
5351 if ( e.u.mouse.x<0 || e.u.mouse.y<0 ||
5352 e.u.mouse.x>=cv->width || e.u.mouse.y >= cv->height ) {
5353 real dx = 0, dy = 0;
5354 if ( e.u.mouse.x<0 )
5355 dx = cv->width/8;
5356 else if ( e.u.mouse.x>=cv->width )
5357 dx = -cv->width/8;
5358 if ( e.u.mouse.y<0 )
5359 dy = -cv->height/8;
5360 else if ( e.u.mouse.y>=cv->height )
5361 dy = cv->height/8;
5362 tab->xoff += dx; tab->yoff += dy;
5363 if ( dy!=0 )
5364 GScrollBarSetPos(cv->vsb,tab->yoff-cv->height);
5365 if ( dx!=0 )
5366 GScrollBarSetPos(cv->hsb,-tab->xoff);
5367 GDrawRequestExpose(cv->v,NULL,false);
5368 }
5369 #if _ModKeysAutoRepeat
5370 /* Under cygwin the modifier keys auto repeat, they don't under normal X */
5371 } else if ( cv->autorpt==event->u.timer.timer ) {
5372 cv->autorpt = NULL;
5373 CVToolsSetCursor(cv,cv->oldstate,NULL);
5374 if ( cv->keysym == GK_Shift_L || cv->keysym == GK_Shift_R ||
5375 cv->keysym == GK_Alt_L || cv->keysym == GK_Alt_R ||
5376 cv->keysym == GK_Meta_L || cv->keysym == GK_Meta_R ) {
5377 GEvent e;
5378 e.w = cv->oldkeyw;
5379 e.u.chr.keysym = cv->keysym;
5380 e.u.chr.x = cv->oldkeyx;
5381 e.u.chr.y = cv->oldkeyy;
5382 CVFakeMove(cv,&e);
5383 }
5384 #endif
5385 }
5386 }
5387
5388 static void CVDrop(CharView *cv,GEvent *event) {
5389 /* We should get a list of character names. Add each as a RefChar */
5390 int32_t len;
5391 int ch, first = true;
5392 char *start, *pt, *cnames;
5393 SplineChar *rsc;
5394 RefChar *new;
5395 int layer = CVLayer((CharViewBase *) cv);
5396
5397 if ( cv->b.drawmode==dm_grid ) {
5398 ff_post_error(_("Not Guides"),_("References may not be dragged into the guidelines layer"));
5399 return;
5400 }
5401 if ( !GDrawSelectionHasType(cv->gw,sn_drag_and_drop,"STRING"))
5402 return;
5403 cnames = GDrawRequestSelection(cv->gw,sn_drag_and_drop,"STRING",&len);
5404 if ( cnames==NULL )
5405 return;
5406
5407 start = cnames;
5408 while ( *start ) {
5409 while ( *start==' ' ) ++start;
5410 if ( *start=='\0' )
5411 break;
5412 for ( pt=start; *pt && *pt!=' '; ++pt );
5413 ch = *pt; *pt = '\0';
5414 if ( (rsc=SFGetChar(cv->b.sc->parent,-1,start))!=NULL && rsc!=cv->b.sc ) {
5415 if ( first ) {
5416 CVPreserveState(&cv->b);
5417 first =false;
5418 }
5419 new = RefCharCreate();
5420 new->transform[0] = new->transform[3] = 1.0;
5421 new->layers[0].splines = NULL;
5422 new->sc = rsc;
5423 new->next = cv->b.sc->layers[layer].refs;
5424 cv->b.sc->layers[layer].refs = new;
5425 SCReinstanciateRefChar(cv->b.sc,new,layer);
5426 SCMakeDependent(cv->b.sc,rsc);
5427 }
5428 *pt = ch;
5429 start = pt;
5430 }
5431
5432 free(cnames);
5433 CVCharChangedUpdate(&cv->b);
5434 }
5435
5436 static int v_e_h(GWindow gw, GEvent *event) {
5437 CharView *cv = (CharView *) GDrawGetUserData(gw);
5438
5439 GGadgetPopupExternalEvent(event);
5440 if (( event->type==et_mouseup || event->type==et_mousedown ) &&
5441 (event->u.mouse.button>=4 && event->u.mouse.button<=7 ) ) {
5442 if ( !(event->u.mouse.state&(ksm_control)) ) /* bind control to magnify/minify */
5443 {
5444 int ish = event->u.mouse.button>5;
5445 if ( event->u.mouse.state&ksm_shift ) ish = !ish;
5446 if ( ish ) /* bind shift to vertical scrolling */
5447 return( GGadgetDispatchEvent(cv->hsb,event));
5448 else
5449 return( GGadgetDispatchEvent(cv->vsb,event));
5450 }
5451 }
5452
5453 switch ( event->type ) {
5454 case et_expose:
5455 GDrawSetLineWidth(gw,0);
5456 CVExpose(cv,gw,event);
5457 break;
5458 case et_crossing:
5459 CVCrossing(cv,event);
5460 break;
5461 case et_mousedown:
5462 CVPaletteActivate(cv);
5463 if ( cv->gic!=NULL )
5464 GDrawSetGIC(gw,cv->gic,0,20);
5465 if ( cv->inactive )
5466 (cv->b.container->funcs->activateMe)(cv->b.container,&cv->b);
5467 CVMouseDown(cv,event);
5468 break;
5469 case et_mousemove:
5470 if ( cv->p.pressed || cv->spacebar_hold)
5471 GDrawSkipMouseMoveEvents(cv->v,event);
5472 CVMouseMove(cv,event);
5473 break;
5474 case et_mouseup:
5475 CVMouseUp(cv,event);
5476 break;
5477 case et_char:
5478 if ( cv->b.container!=NULL )
5479 (cv->b.container->funcs->charEvent)(cv->b.container,event);
5480 else
5481 CVChar(cv,event);
5482 break;
5483 case et_charup:
5484 CVCharUp(cv,event);
5485 break;
5486 case et_timer:
5487 CVTimer(cv,event);
5488 break;
5489 case et_drop:
5490 CVDrop(cv,event);
5491 break;
5492 case et_focus:
5493 if ( event->u.focus.gained_focus ) {
5494 if ( cv->gic!=NULL )
5495 GDrawSetGIC(gw,cv->gic,0,20);
5496 }
5497 break;
5498 default: break;
5499 }
5500 return( true );
5501 }
5502
5503 static void CVDrawNum(CharView *UNUSED(cv),GWindow pixmap,int x, int y, char *format,real val, int align) {
5504 char buffer[40];
5505 int len;
5506
5507 if ( val==0 ) val=0; /* avoid -0 */
5508 sprintf(buffer,format,(double)val); /* formats are given as for doubles */
5509 if ( align!=0 ) {
5510 len = GDrawGetText8Width(pixmap,buffer,-1);
5511 if ( align==1 )
5512 x-=len/2;
5513 else
5514 x-=len;
5515 }
5516 GDrawDrawText8(pixmap,x,y,buffer,-1,GDrawGetDefaultForeground(NULL));
5517 }
5518
5519 static void CVDrawVNum(CharView *cv,GWindow pixmap,int x, int y, char *format,real val, int align) {
5520 char buffer[40], *pt;
5521 int len;
5522
5523 if ( val==0 ) val=0; /* avoid -0 */
5524 sprintf(buffer,format,(double)val); /* formats are given as for doubles */
5525 if ( align!=0 ) {
5526 len = strlen(buffer)*cv->sfh;
5527 if ( align==1 )
5528 y-=len/2;
5529 else
5530 y-=len;
5531 }
5532 for ( pt=buffer; *pt; ++pt ) {
5533 GDrawDrawText8(pixmap,x,y,pt,1,GDrawGetDefaultForeground(NULL));
5534 y += cv->sdh;
5535 }
5536 }
5537
5538
5539 static void CVExposeRulers(CharView *cv, GWindow pixmap ) {
5540 CharViewTab* tab = CVGetActiveTab(cv);
5541 real xmin, xmax, ymin, ymax;
5542 real onehundred, pos;
5543 real units, littleunits;
5544 int ybase = cv->mbh+cv->charselectorh+cv->infoh;
5545 int x,y;
5546 GRect rect;
5547 Color def_fg = GDrawGetDefaultForeground(NULL);
5548
5549 xmin = -tab->xoff/tab->scale;
5550 xmax = (cv->width-tab->xoff)/tab->scale;
5551 ymin = -tab->yoff/tab->scale;
5552 ymax = (cv->height-tab->yoff)/tab->scale;
5553 onehundred = 100/tab->scale;
5554
5555 if ( onehundred<5 ) {
5556 units = 1; littleunits=0;
5557 } else if ( onehundred<10 ) {
5558 units = 5; littleunits=1;
5559 } else if ( onehundred<50 ) {
5560 units = 10; littleunits=2;
5561 } else if ( onehundred<100 ) {
5562 units = 25; littleunits=5;
5563 } else if ( onehundred<500/2 ) {
5564 units = 100; littleunits=20;
5565 } else if ( onehundred<1000/2 ) {
5566 // The next numbers (1000 and up) take more space to display, so Frank has adjusted the thresholds.
5567 units = 250; littleunits=50;
5568 } else if ( onehundred<5000/2 ) {
5569 units = 1000; littleunits=200;
5570 } else if ( onehundred<10000/2 ) {
5571 units = 2500; littleunits=500;
5572 } else if ( onehundred<50000/2 ) {
5573 units = 10000; littleunits=2000;
5574 } else {
5575 for ( units=1 ; units<onehundred*2; units *= 10 );
5576 units/=10; littleunits = units/5;
5577 }
5578
5579 // Create the pixmaps
5580 if (cv->hruler != NULL) {
5581 GDrawGetSize(cv->hruler, &rect);
5582 if (rect.width != cv->width || rect.height != cv->rulerh) {
5583 GDrawDestroyWindow(cv->hruler);
5584 cv->hruler = NULL;
5585 }
5586 }
5587 if (cv->vruler != NULL) {
5588 GDrawGetSize(cv->vruler, &rect);
5589 if (rect.height != cv->height || rect.width != cv->rulerh) {
5590 GDrawDestroyWindow(cv->vruler);
5591 cv->vruler = NULL;
5592 }
5593 }
5594 if (cv->hruler == NULL) {
5595 cv->hruler = GDrawCreatePixmap(GDrawGetDisplayOfWindow(cv->v), cv->v, cv->width, cv->rulerh);
5596 }
5597 if (cv->vruler == NULL) {
5598 cv->vruler = GDrawCreatePixmap(GDrawGetDisplayOfWindow(cv->v), cv->v, cv->rulerh, cv->height);
5599 }
5600
5601 // Set background
5602 rect.x = 0; rect.width = cv->width; rect.y = 0; rect.height = cv->rulerh;
5603 GDrawFillRect(cv->hruler, &rect, GDrawGetDefaultBackground(NULL));
5604 rect.width = cv->rulerh; rect.height = cv->height;
5605 GDrawFillRect(cv->vruler, &rect, GDrawGetDefaultBackground(NULL));
5606
5607 // Draw bottom line of rulers
5608 GDrawSetLineWidth(cv->hruler, 0);
5609 GDrawSetLineWidth(cv->vruler, 0);
5610 GDrawDrawLine(cv->hruler, 0, cv->rulerh - 1, cv->width, cv->rulerh - 1, def_fg);
5611 GDrawDrawLine(cv->vruler, cv->rulerh - 1, 0, cv->rulerh - 1, cv->height, def_fg);
5612
5613 // Draw the ticks
5614 GDrawSetFont(cv->hruler, cv->small);
5615 GDrawSetFont(cv->vruler, cv->small);
5616 if ( xmax-xmin<1 && cv->width>100 ) {
5617 CVDrawNum(cv,cv->hruler,0,cv->sas,"%.3f",xmin,0);
5618 CVDrawNum(cv,cv->hruler,cv->width,cv->sas,"%.3f",xmax,2);
5619 }
5620
5621 if ( ymax-ymin<1 && cv->height>100 ) {
5622 CVDrawVNum(cv,cv->vruler,1,cv->height+cv->sas,"%.3f",ymin,0);
5623 CVDrawVNum(cv,cv->vruler,1,cv->sas,"%.3f",ymax,2);
5624 }
5625 if ( fabs(xmin/units) < 1e5 && fabs(ymin/units)<1e5 && fabs(xmax/units)<1e5 && fabs(ymax/units)<1e5 ) {
5626 if ( littleunits!=0 ) {
5627 for ( pos=littleunits*ceil(xmin/littleunits); pos<xmax; pos += littleunits ) {
5628 x = tab->xoff + rint(pos*tab->scale);
5629 GDrawDrawLine(cv->hruler,x,cv->rulerh-4,x,cv->rulerh, def_fg);
5630 }
5631 for ( pos=littleunits*ceil(ymin/littleunits); pos<ymax; pos += littleunits ) {
5632 y = -tab->yoff + cv->height - rint(pos*tab->scale);
5633 GDrawDrawLine(cv->vruler,cv->rulerh-4,y,cv->rulerh,y, def_fg);
5634 }
5635 }
5636 for ( pos=units*ceil(xmin/units); pos<xmax; pos += units ) {
5637 x = tab->xoff + rint(pos*tab->scale);
5638 GDrawDrawLine(cv->hruler,x,0,x,cv->rulerh, rulerbigtickcol);
5639 CVDrawNum(cv,cv->hruler,x+15,cv->sas,"%g",pos,1);
5640 }
5641 for ( pos=units*ceil(ymin/units); pos<ymax; pos += units ) {
5642 y = -tab->yoff + cv->height - rint(pos*tab->scale);
5643 GDrawDrawLine(cv->vruler,0,y,cv->rulerh,y, rulerbigtickcol);
5644 CVDrawVNum(cv,cv->vruler,1,y+cv->sas+20,"%g",pos,1);
5645 }
5646 }
5647
5648 // Draw the pixmaps to screen
5649 GDrawDrawPixmap(pixmap, cv->vruler, &rect, 0, cv->rulerh + ybase);
5650 rect.width = cv->width; rect.height = cv->rulerh;
5651 GDrawDrawPixmap(pixmap, cv->hruler, &rect, cv->rulerh, ybase);
5652 }
5653
5654 static void InfoExpose(CharView *cv, GWindow pixmap, GEvent *expose) {
5655 GRect old1, old2;
5656 Color def_fg = GDrawGetDefaultForeground(NULL);
5657
5658 if ( expose->u.expose.rect.y + expose->u.expose.rect.height < cv->mbh ||
5659 (!cv->showrulers && expose->u.expose.rect.y >= cv->mbh+cv->charselectorh+cv->infoh ))
5660 return;
5661
5662 GDrawPushClip(pixmap,&expose->u.expose.rect,&old1);
5663 GDrawSetLineWidth(pixmap,0);
5664 if ( expose->u.expose.rect.y< cv->mbh+cv->charselectorh+cv->infoh ) {
5665 GDrawPushClip(pixmap,&expose->u.expose.rect,&old2);
5666
5667 GDrawDrawLine(pixmap,0,cv->mbh+cv->charselectorh+cv->infoh-1,8096,cv->mbh+cv->charselectorh+cv->infoh-1,def_fg);
5668 GDrawDrawImage(pixmap,&GIcon_rightpointer,NULL,RPT_BASE,cv->mbh+cv->charselectorh+2);
5669 GDrawDrawImage(pixmap,&GIcon_selectedpoint,NULL,SPT_BASE,cv->mbh+cv->charselectorh+2);
5670 GDrawDrawImage(pixmap,&GIcon_sel2ptr,NULL,SOF_BASE,cv->mbh+cv->charselectorh+2);
5671 GDrawDrawImage(pixmap,&GIcon_distance,NULL,SDS_BASE,cv->mbh+cv->charselectorh+2);
5672 GDrawDrawImage(pixmap,&GIcon_angle,NULL,SAN_BASE,cv->mbh+cv->charselectorh+2);
5673 GDrawDrawImage(pixmap,&GIcon_mag,NULL,MAG_BASE,cv->mbh+cv->charselectorh+2);
5674 CVInfoDrawText(cv,pixmap);
5675 GDrawPopClip(pixmap,&old2);
5676 }
5677 if ( cv->showrulers ) {
5678 CVExposeRulers(cv,pixmap);
5679 cv->olde.x = -1;
5680 CVInfoDrawRulers(cv,pixmap);
5681 }
5682 GDrawPopClip(pixmap,&old1);
5683 }
5684
5685 void CVResize(CharView *cv ) {
5686 int sbsize = GDrawPointsToPixels(cv->gw,_GScrollBar_Width);
5687 GRect size;
5688 GDrawGetSize(cv->gw,&size);
5689 {
5690 int newwidth = size.width-sbsize,
5691 newheight = size.height-sbsize - cv->mbh-cv->charselectorh-cv->infoh;
5692 int sbwidth = newwidth, sbheight = newheight;
5693
5694 if ( cv->dv!=NULL ) {
5695 newwidth -= cv->dv->dwidth;
5696 sbwidth -= cv->dv->dwidth;
5697 }
5698 if ( newwidth<30 || newheight<50 ) {
5699 if ( newwidth<30 )
5700 newwidth = 30+sbsize+(cv->dv!=NULL ? cv->dv->dwidth : 0);
5701 if ( newheight<50 )
5702 newheight = 50+sbsize+cv->mbh+cv->charselectorh+cv->infoh;
5703 GDrawResize(cv->gw,newwidth,newheight);
5704 return;
5705 }
5706
5707 if ( cv->dv!=NULL ) {
5708 int dvheight = size.height-(cv->mbh+cv->charselectorh+cv->infoh);
5709 GDrawMove(cv->dv->dv,size.width-cv->dv->dwidth,cv->mbh+cv->charselectorh+cv->infoh);
5710 GDrawResize(cv->dv->dv,cv->dv->dwidth,dvheight);
5711 GDrawResize(cv->dv->ii.v,cv->dv->dwidth-sbsize,dvheight-cv->dv->toph);
5712 GGadgetResize(cv->dv->ii.vsb,sbsize,dvheight-cv->dv->toph);
5713 cv->dv->ii.vheight = dvheight-cv->dv->toph;
5714 GDrawRequestExpose(cv->dv->dv,NULL,false);
5715 GDrawRequestExpose(cv->dv->ii.v,NULL,false);
5716 GScrollBarSetBounds(cv->dv->ii.vsb,0,cv->dv->ii.lheight+1,
5717 cv->dv->ii.vheight/cv->dv->ii.fh);
5718 }
5719
5720 if (cv->charselector != NULL && cv->charselectorPrev != NULL && cv->charselectorNext != NULL) {
5721 GRect charselector_size;
5722 GRect charselectorNext_size;
5723 GRect charselectorPrev_size;
5724 GGadgetGetSize(cv->charselector, &charselector_size);
5725 GGadgetGetSize(cv->charselectorPrev, &charselectorPrev_size);
5726 GGadgetGetSize(cv->charselectorNext, &charselectorNext_size);
5727 int new_charselector_width = newwidth + sbsize - ( 4 * charselector_size.x ) - charselectorNext_size.width - charselectorPrev_size.width;
5728 int new_charselectorPrev_x = newwidth + sbsize - ( 2 * charselector_size.x ) - charselectorNext_size.width - charselectorPrev_size.width;
5729 int new_charselectorNext_x = newwidth + sbsize - ( 1 * charselector_size.x ) - charselectorNext_size.width;
5730 GGadgetResize(cv->charselector, new_charselector_width, charselector_size.height);
5731 GGadgetMove(cv->charselectorPrev, new_charselectorPrev_x, charselectorPrev_size.y);
5732 GGadgetMove(cv->charselectorNext, new_charselectorNext_x, charselectorNext_size.y);
5733 charselector_size.x = 0; charselector_size.y = cv->mbh; charselector_size.width = newwidth + sbsize; charselector_size.height = cv->charselectorh;
5734 GDrawRequestExpose(cv->gw, &charselector_size, false);
5735 }
5736
5737 if ( cv->showrulers ) {
5738 newheight -= cv->rulerh;
5739 newwidth -= cv->rulerh;
5740 }
5741
5742 if ( newwidth == cv->width && newheight == cv->height )
5743 return;
5744
5745 /* MenuBar takes care of itself */
5746 GDrawResize(cv->v,newwidth,newheight);
5747 GGadgetMove(cv->vsb,sbwidth, cv->mbh+cv->charselectorh+cv->infoh);
5748 GGadgetResize(cv->vsb,sbsize,sbheight);
5749 GGadgetMove(cv->hsb,0,size.height-sbsize);
5750 GGadgetResize(cv->hsb,sbwidth,sbsize);
5751 cv->width = newwidth; cv->height = newheight;
5752 /*CVFit(cv);*/ CVNewScale(cv);
5753 CVPalettesRaise(cv);
5754 if ( cv->b.container == NULL && ( cv_width!=size.width || cv_height!=size.height )) {
5755 cv_width = size.width;
5756 cv_height = size.height;
5757 SavePrefs(true);
5758 }
5759 }
5760 }
5761
5762 static void CVHScrollSetPos( CharView *cv, int newpos )
5763 {
5764 CharViewTab* tab = CVGetActiveTab(cv);
5765 TRACE("CVHScrollSetPos(1) cvxoff:%f newpos:%d\n", tab->xoff, newpos );
5766 if ( newpos<-(32000*tab->scale-cv->width) )
5767 newpos = -(32000*tab->scale-cv->width);
5768 if ( newpos>8000*tab->scale ) newpos = 8000*tab->scale;
5769 TRACE("CVHScrollSetPos(2) cvxoff:%f newpos:%d\n", tab->xoff, newpos );
5770 if ( newpos!=tab->xoff ) {
5771 int diff = newpos-tab->xoff;
5772 tab->xoff = newpos;
5773 GScrollBarSetPos(cv->hsb,-newpos);
5774 GDrawScroll(cv->v,NULL,diff,0);
5775 CVRulerLingerMove(cv);
5776 if (( cv->showhhints && cv->b.sc->hstem!=NULL ) || cv->showblues || cv->showvmetrics ) {
5777 GRect r;
5778 r.y = 0; r.height = cv->height;
5779 r.width = 6*cv->sfh+10;
5780 if ( diff>0 )
5781 r.x = cv->width-r.width;
5782 else
5783 r.x = cv->width+diff-r.width;
5784 GDrawRequestExpose(cv->v,&r,false);
5785 }
5786 if ( cv->showrulers ) {
5787 GRect r;
5788 r.y = cv->infoh+cv->mbh+cv->charselectorh; r.height = cv->rulerh; r.x = 0; r.width = cv->rulerh+cv->width;
5789 GDrawRequestExpose(cv->gw,&r,false);
5790 }
5791 }
5792 }
5793
5794 static void CVHScroll(CharView *cv, struct sbevent *sb) {
5795 CharViewTab* tab = CVGetActiveTab(cv);
5796 int newpos = tab->xoff;
5797
5798 switch( sb->type ) {
5799 case et_sb_top:
5800 newpos = 0;
5801 break;
5802 case et_sb_uppage:
5803 newpos += 9*cv->width/10;
5804 break;
5805 case et_sb_up:
5806 newpos += cv->width/15;
5807 break;
5808 case et_sb_down:
5809 newpos -= cv->width/15;
5810 break;
5811 case et_sb_downpage:
5812 newpos -= 9*cv->width/10;
5813 break;
5814 case et_sb_bottom:
5815 newpos = 0;
5816 break;
5817 case et_sb_thumb:
5818 case et_sb_thumbrelease:
5819 newpos = -sb->pos;
5820 break;
5821 case et_sb_halfup:
5822 newpos += cv->width/30;
5823 break;
5824 case et_sb_halfdown:
5825 newpos -= cv->width/30;
5826 break;
5827 }
5828
5829 CVHScrollSetPos( cv, newpos );
5830 }
5831
5832 static void CVVScroll(CharView *cv, struct sbevent *sb) {
5833 CharViewTab* tab = CVGetActiveTab(cv);
5834 int newpos = tab->yoff;
5835
5836 switch( sb->type ) {
5837 case et_sb_top:
5838 newpos = 0;
5839 break;
5840 case et_sb_uppage:
5841 newpos -= 9*cv->height/10;
5842 break;
5843 case et_sb_up:
5844 newpos -= cv->height/15;
5845 break;
5846 case et_sb_down:
5847 newpos += cv->height/15;
5848 break;
5849 case et_sb_downpage:
5850 newpos += 9*cv->height/10;
5851 break;
5852 case et_sb_bottom:
5853 newpos = 0;
5854 break;
5855 case et_sb_thumb:
5856 case et_sb_thumbrelease:
5857 newpos = sb->pos+cv->height;
5858 break;
5859 case et_sb_halfup:
5860 newpos -= cv->height/30;
5861 break;
5862 case et_sb_halfdown:
5863 newpos += cv->height/30;
5864 break;
5865 }
5866 if ( newpos<-(20000*tab->scale-cv->height) )
5867 newpos = -(20000*tab->scale-cv->height);
5868 if ( newpos>8000*tab->scale ) newpos = 8000*tab->scale;
5869 if ( newpos!=tab->yoff ) {
5870 int diff = newpos-tab->yoff;
5871 tab->yoff = newpos;
5872 GScrollBarSetPos(cv->vsb,newpos-cv->height);
5873 GDrawScroll(cv->v,NULL,0,diff);
5874 CVRulerLingerMove(cv);
5875 if (( cv->showvhints && cv->b.sc->vstem!=NULL) || cv->showhmetrics ) {
5876 GRect r;
5877 RefChar *lock = HasUseMyMetrics(cv->b.sc,CVLayer((CharViewBase *) cv));
5878 r.x = 0; r.width = cv->width;
5879 r.height = 2*cv->sfh+6;
5880 if ( lock!=NULL )
5881 r.height = cv->sfh+3+GImageGetHeight(&GIcon_lock);
5882 if ( diff>0 )
5883 r.y = 0;
5884 else
5885 r.y = -diff;
5886 GDrawRequestExpose(cv->v,&r,false);
5887 }
5888 if ( cv->showrulers ) {
5889 GRect r;
5890 r.x = 0; r.width = cv->rulerh; r.y = cv->infoh+cv->charselectorh+cv->mbh; r.height = cv->rulerh+cv->height;
5891 GDrawRequestExpose(cv->gw,&r,false);
5892 }
5893 }
5894 }
5895
5896 void LogoExpose(GWindow pixmap,GEvent *event, GRect *r,enum drawmode dm) {
5897 int sbsize = GDrawPointsToPixels(pixmap,_GScrollBar_Width);
5898 GRect old;
5899
5900 r->width = r->height = sbsize;
5901 if ( event->u.expose.rect.x+event->u.expose.rect.width >= r->x &&
5902 event->u.expose.rect.y+event->u.expose.rect.height >= r->y ) {
5903 /* Put something into the little box where the two scroll bars meet */
5904 int xoff, yoff;
5905 GImage *which = (dm==dm_fore) ? &GIcon_FontForgeLogo :
5906 (dm==dm_back) ? &GIcon_FontForgeBack :
5907 &GIcon_FontForgeGuide;
5908 struct _GImage *base = which->u.image;
5909 xoff = (sbsize-base->width);
5910 yoff = (sbsize-base->height);
5911 GDrawPushClip(pixmap,r,&old);
5912 GDrawDrawImage(pixmap,which,NULL,
5913 r->x+(xoff-xoff/2),r->y+(yoff-yoff/2));
5914 GDrawPopClip(pixmap,&old);
5915 /*GDrawDrawLine(pixmap,r->x+sbsize-1,r->y,r->x+sbsize-1,r->y+sbsize,0x000000);*/
5916 }
5917 }
5918
5919 static void CVLogoExpose(CharView *cv,GWindow pixmap,GEvent *event) {
5920 int rh = cv->showrulers ? cv->rulerh : 0;
5921 GRect r;
5922
5923 r.x = cv->width+rh;
5924 r.y = cv->height+cv->mbh+cv->charselectorh+cv->infoh+rh;
5925 LogoExpose(pixmap,event,&r,cv->b.drawmode==dm_grid? dm_grid :
5926 cv->b.layerheads[cv->b.drawmode]->background ? dm_back : dm_fore );
5927 }
5928
5929 static void CVDrawGuideLine(CharView *cv, int guide_pos) {
5930 GWindow pixmap = cv->v;
5931
5932 if ( guide_pos<0 )
5933 return;
5934 GDrawSetDashedLine(pixmap,2,2,0);
5935 GDrawSetLineWidth(pixmap,0);
5936
5937 if ( cv->ruler_pressedv ) {
5938 GDrawDrawLine(pixmap,guide_pos,0,guide_pos,cv->height,guidedragcol);
5939 } else {
5940 GDrawDrawLine(pixmap,0,guide_pos,cv->width,guide_pos,guidedragcol);
5941 }
5942 GDrawSetDashedLine(pixmap,0,0,0);
5943 }
5944
5945 static void CVAddGuide(CharView *cv,int is_v,int guide_pos) {
5946 CharViewTab* tab = CVGetActiveTab(cv);
5947 SplinePoint *sp1, *sp2;
5948 SplineSet *ss;
5949 SplineFont *sf = cv->b.sc->parent;
5950 int emsize = sf->ascent+sf->descent;
5951
5952 if ( is_v ) {
5953 /* Create a vertical guide line */
5954 double x = (guide_pos-tab->xoff)/tab->scale;
5955 sp1 = SplinePointCreate(x,sf->ascent+emsize/2);
5956 sp2 = SplinePointCreate(x,-sf->descent-emsize/2);
5957 } else {
5958 double y = (cv->height-guide_pos-tab->yoff)/tab->scale;
5959 sp1 = SplinePointCreate(-emsize,y);
5960 sp2 = SplinePointCreate(2*emsize,y);
5961 }
5962 SplineMake(sp1,sp2,sf->grid.order2);
5963 ss = chunkalloc(sizeof(SplineSet));
5964 ss->first = sp1; ss->last = sp2;
5965 ss->next = sf->grid.splines;
5966 sf->grid.splines = ss;
5967 ss->contour_name = gwwv_ask_string(_("Name this contour"),NULL,
5968 _("Name this guideline or cancel to create it without a name"));
5969 if ( ss->contour_name!=NULL && *ss->contour_name=='\0' ) {
5970 free(ss->contour_name);
5971 ss->contour_name = NULL;
5972 }
5973
5974 FVRedrawAllCharViewsSF(sf);
5975 if ( !sf->changed ) {
5976 sf->changed = true;
5977 FVSetTitles(sf);
5978 }
5979 }
5980
5981 static int cv_e_h(GWindow gw, GEvent *event) {
5982 CharView *cv = (CharView *) GDrawGetUserData(gw);
5983
5984 if (( event->type==et_mouseup || event->type==et_mousedown ) &&
5985 (event->u.mouse.button>=4 && event->u.mouse.button<=7) ) {
5986 int ish = event->u.mouse.button>5;
5987 if ( event->u.mouse.state&ksm_shift ) ish = !ish;
5988 if ( ish ) /* bind shift to vertical scrolling */
5989 return( GGadgetDispatchEvent(cv->hsb,event));
5990 else
5991 return( GGadgetDispatchEvent(cv->vsb,event));
5992 }
5993
5994 switch ( event->type ) {
5995 case et_selclear:
5996 ClipboardClear();
5997 break;
5998 case et_expose:
5999 GDrawSetLineWidth(gw,0);
6000 InfoExpose(cv,gw,event);
6001 CVLogoExpose(cv,gw,event);
6002 break;
6003 case et_char:
6004 if ( cv->b.container!=NULL )
6005 (cv->b.container->funcs->charEvent)(cv->b.container,event);
6006 else
6007 CVChar(cv,event);
6008 break;
6009 case et_charup:
6010 CVCharUp(cv,event);
6011 break;
6012 case et_resize:
6013 if ( event->u.resize.sized )
6014 CVResize(cv);
6015 break;
6016 case et_controlevent:
6017 switch ( event->u.control.subtype ) {
6018 case et_scrollbarchange:
6019 if ( event->u.control.g == cv->hsb )
6020 CVHScroll(cv,&event->u.control.u.sb);
6021 else
6022 CVVScroll(cv,&event->u.control.u.sb);
6023 break;
6024 default: break;
6025 }
6026 break;
6027 case et_map:
6028 if ( event->u.map.is_visible )
6029 CVPaletteActivate(cv);
6030 else
6031 CVPalettesHideIfMine(cv);
6032 break;
6033 case et_destroy:
6034 CVUnlinkView(cv);
6035 CVPalettesHideIfMine(cv);
6036 if ( cv->icon!=NULL ) {
6037 GDrawDestroyWindow(cv->icon);
6038 cv->icon = NULL;
6039 }
6040 if (cv->hruler != NULL) {
6041 GDrawDestroyWindow(cv->hruler);
6042 cv->hruler = NULL;
6043 }
6044 if (cv->vruler != NULL) {
6045 GDrawDestroyWindow(cv->vruler);
6046 cv->vruler = NULL;
6047 }
6048 CharViewFree(cv);
6049 break;
6050 case et_close:
6051 dlist_foreach( &cv->pointInfoDialogs, PI_Destroy );
6052 GDrawDestroyWindow(gw);
6053 break;
6054 case et_mouseup: case et_mousedown:
6055 GGadgetEndPopup();
6056 CVPaletteActivate(cv);
6057 if ( cv->inactive )
6058 (cv->b.container->funcs->activateMe)(cv->b.container,&cv->b);
6059 if ( cv->showrulers ) {
6060 int is_h = event->u.mouse.y>cv->mbh+cv->charselectorh+cv->infoh && event->u.mouse.y<cv->mbh+cv->charselectorh+cv->infoh+cv->rulerh;
6061 int is_v = event->u.mouse.x<cv->rulerh;
6062 if ( cv->gwgic!=NULL && event->type==et_mousedown)
6063 GDrawSetGIC(gw,cv->gwgic,0,20);
6064 if ( event->type == et_mousedown ) {
6065 if ( is_h && is_v )
6066 /* Ambiguous, ignore */;
6067 else if ( is_h ) {
6068 cv->ruler_pressed = true;
6069 cv->ruler_pressedv = false;
6070 GDrawSetCursor(cv->v,ct_updown);
6071 GDrawSetCursor(cv->gw,ct_updown);
6072 } else if ( is_v ) {
6073 cv->ruler_pressed = true;
6074 cv->ruler_pressedv = true;
6075 GDrawSetCursor(cv->v,ct_leftright);
6076 GDrawSetCursor(cv->gw,ct_leftright);
6077 }
6078 cv->guide_pos = -1;
6079 } else if ( event->type==et_mouseup && cv->ruler_pressed ) {
6080 cv->guide_pos = -1;
6081 cv->showing_tool = cvt_none;
6082 CVToolsSetCursor(cv,event->u.mouse.state&~(1<<(7+event->u.mouse.button)),event->u.mouse.device); /* X still has the buttons set in the state, even though we just released them. I don't want em */
6083 GDrawSetCursor(cv->gw,ct_mypointer);
6084 cv->ruler_pressed = false;
6085 if ( is_h || is_v )
6086 /* Do Nothing */;
6087 else if ( cv->ruler_pressedv )
6088 CVAddGuide(cv,true,event->u.mouse.x-cv->rulerh);
6089 else
6090 CVAddGuide(cv,false,event->u.mouse.y-(cv->mbh+cv->charselectorh+cv->infoh+cv->rulerh));
6091 }
6092 }
6093 break;
6094 case et_mousemove:
6095 if ( cv->ruler_pressed ) {
6096 CharViewTab* tab = CVGetActiveTab(cv);
6097 cv->e.x = event->u.mouse.x - cv->rulerh;
6098 cv->e.y = event->u.mouse.y-(cv->mbh+cv->charselectorh+cv->infoh+cv->rulerh);
6099 cv->info.x = (cv->e.x-tab->xoff)/tab->scale;
6100 cv->info.y = (cv->height-cv->e.y-tab->yoff)/tab->scale;
6101 if ( cv->ruler_pressedv )
6102 cv->guide_pos = cv->e.x;
6103 else
6104 cv->guide_pos = cv->e.y;
6105 GDrawRequestExpose(cv->v,NULL,false);
6106 CVInfoDraw(cv,cv->gw);
6107 }
6108 else if ( event->u.mouse.y > cv->mbh )
6109 {
6110 if( GGadgetContainsEventLocation( cv->charselectorPrev, event ))
6111 {
6112 GGadgetPreparePopup(cv->gw,c_to_u("Show the previous word in the current word list\n"
6113 "Select the menu File / Load Word List... to load a wordlist."));
6114 }
6115 else if( GGadgetContainsEventLocation( cv->charselectorNext, event ))
6116 {
6117 GGadgetPreparePopup(cv->gw,c_to_u("Show the next word in the current word list\n"
6118 "Select the menu File / Load Word List... to load a wordlist."));
6119 }
6120 else if( GGadgetContainsEventLocation( cv->charselector, event ))
6121 {
6122 GGadgetPreparePopup(cv->gw,c_to_u("This is a word list that you can step through to quickly see your glyphs in context\n"
6123 "Select the menu File / Load Word List... to load a wordlist."));
6124 }
6125 else
6126 {
6127 int enc = CVCurEnc(cv);
6128 SCPreparePopup(cv->gw,cv->b.sc,cv->b.fv->map->remap,enc,
6129 UniFromEnc(enc,cv->b.fv->map->enc));
6130 }
6131 }
6132 break;
6133 case et_drop:
6134 CVDrop(cv,event);
6135 break;
6136 case et_focus:
6137 if ( event->u.focus.gained_focus ) {
6138 if ( cv->gic!=NULL )
6139 GDrawSetGIC(gw,cv->gic,0,20);
6140
6141 // X11 on Windows is broken, non-active windows
6142 // receive this event on mouseover
6143 CVPaletteActivate(cv);
6144 }
6145 break;
6146 default: break;
6147 }
6148 return( true );
6149 }
6150
6151
6152 static void CVMenuClose(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6153 CharView *cv = (CharView *) GDrawGetUserData(gw);
6154 if ( cv->b.container )
6155 (cv->b.container->funcs->doClose)(cv->b.container);
6156 else
6157 GDrawDestroyWindow(gw);
6158 }
6159
6160 // This can be triggered two ways: by the "X" buttons on tabs, and regularly in the menu.
6161 static void CVMenuCloseTab(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6162 CharView *cv = (CharView *) GDrawGetUserData(gw);
6163 int pos, i;
6164
6165 if ( cv->b.container || cv->tabs==NULL || cv->former_cnt<=1 )
6166 return;
6167 pos = cv->ctpos == -1 ? GTabSetGetSel(cv->tabs) : cv->ctpos;
6168 free(cv->former_names[pos]);
6169 for ( i=pos+1; i<cv->former_cnt; ++i ) {
6170 cv->former_names[i-1] = cv->former_names[i];
6171 cv->cvtabs[i-1] = cv->cvtabs[i];
6172 }
6173 --cv->former_cnt;
6174 if (cv->ctpos==-1){
6175 GTabSetRemoveTabByPos(cv->tabs,pos); /* This should send an event that the selection has changed */
6176 }
6177 GTabSetRemetric(cv->tabs);
6178 if (GTabSetGetSel(cv->tabs) >= pos) {
6179 CVChangeSC_fetchTab(cv, pos);
6180 // Otherwise subsequent calls to CVChangeSC_storeTab which use this value will be off by one
6181 cv->oldtabnum = pos;
6182 }
6183 if (GTabSetGetTabCount(cv->tabs)<=1) CVChangeTabsVisibility(cv,false);
6184 // Reset this argument so in case it's called by the menu the right tab will be removed.
6185 cv->ctpos = -1;
6186 }
6187
6188 static void CVMenuOpen(GWindow gw, struct gmenuitem *mi, GEvent *g) {
6189 CharView *d = (CharView*)GDrawGetUserData(gw);
6190 FontView *fv = NULL;
6191 if (d) {
6192 fv = (FontView*)d->b.fv;
6193 }
6194 _FVMenuOpen(fv);
6195 }
6196
6197 static void CVMenuOpenBitmap(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6198 CharView *cv = (CharView *) GDrawGetUserData(gw);
6199 if ( cv->b.fv->sf->bitmaps==NULL )
6200 return;
6201 BitmapViewCreatePick(CVCurEnc(cv),(FontView *) (cv->b.fv));
6202 }
6203
6204 static void CVMenuOpenMetrics(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6205 CharView *cv = (CharView *) GDrawGetUserData(gw);
6206 MetricsViewCreate((FontView *) (cv->b.fv),cv->b.sc,NULL);
6207 }
6208
6209 static void CVMenuSave(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6210 CharView *cv = (CharView *) GDrawGetUserData(gw);
6211 _FVMenuSave((FontView *) (cv->b.fv));
6212 }
6213
6214 static void CVMenuSaveAs(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6215 CharView *cv = (CharView *) GDrawGetUserData(gw);
6216 _FVMenuSaveAs((FontView *) (cv->b.fv));
6217 }
6218
6219 static void CVMenuGenerate(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6220 CharView *cv = (CharView *) GDrawGetUserData(gw);
6221 FontViewBase *fv = cv->b.fv;
6222 SFGenerateFont(cv->b.sc->parent,CVLayer((CharViewBase *) cv),false,fv->normal==NULL?fv->map:fv->normal);
6223 }
6224
6225 static void CVMenuGenerateFamily(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6226 CharView *cv = (CharView *) GDrawGetUserData(gw);
6227 _FVMenuGenerate((FontView *) (cv->b.fv),gf_macfamily);
6228 }
6229
6230 static void CVMenuGenerateTTC(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6231 CharView *cv = (CharView *) GDrawGetUserData(gw);
6232 _FVMenuGenerate((FontView *) (cv->b.fv),gf_ttc);
6233 }
6234
6235 static void CVMenuExport(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6236 CharView *cv = (CharView *) GDrawGetUserData(gw);
6237 CVExport(cv);
6238 }
6239
6240 static void CVInkscapeAdjust(CharView *cv) {
6241 CharViewTab* tab = CVGetActiveTab(cv);
6242 /* Inkscape considers different coordinates useful. That is to say, */
6243 /* Inkscape views the world as a blank sheet of paper and often */
6244 /* put things outside the [0,1000] range (especially in Y) that */
6245 /* FF uses. So after doing a Paste, or Import or something similar */
6246 /* check and see if the image is completely out of view, and if so */
6247 /* then adjust the view field */
6248 DBounds b;
6249 int layer = CVLayer((CharViewBase *) cv);
6250
6251 if (layer != ly_grid) SplineCharLayerQuickBounds(cv->b.sc,layer,&b);
6252 else {
6253 b.minx = b.miny = 1e10;
6254 b.maxx = b.maxy = -1e10;
6255 SplineSetQuickBounds(cv->b.sc->parent->grid.splines,&b);
6256 }
6257
6258 b.minx *= tab->scale; b.maxx *= tab->scale;
6259 b.miny *= tab->scale; b.maxy *= tab->scale;
6260
6261 if ( b.minx + tab->xoff < 0 || b.miny + tab->yoff < 0 ||
6262 b.maxx + tab->xoff > cv->width || b.maxy + tab->yoff > cv->height )
6263 CVFit(cv);
6264 }
6265
6266 static void CVMenuImport(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6267 CharView *cv = (CharView *) GDrawGetUserData(gw);
6268 CVImport(cv);
6269 CVInkscapeAdjust(cv);
6270 }
6271
6272 static void CVMenuRevert(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6273 CharView *cv = (CharView *) GDrawGetUserData(gw);
6274 FVDelay((FontView *) (cv->b.fv),(void (*)(FontView *)) FVRevert);
6275 /* The revert command can potentially */
6276 /* destroy our window (if the char weren't in the */
6277 /* old font). If that happens before the menu finishes */
6278 /* we get a crash. So delay till after the menu completes */
6279 }
6280
6281 static void CVMenuRevertGlyph(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6282 CharView *cv = (CharView *) GDrawGetUserData(gw);
6283 SplineChar *sc, temp;
6284 Undoes **undoes;
6285 int layer, lc;
6286 CharView *cvs;
6287 int mylayer = CVLayer((CharViewBase *) cv);
6288
6289 if ( cv->b.sc->parent->filename==NULL || cv->b.sc->namechanged || cv->b.sc->parent->mm!=NULL )
6290 return;
6291 if ( cv->b.sc->parent->sfd_version<2 )
6292 ff_post_error(_("Old sfd file"),_("This font comes from an old format sfd file. Not all aspects of it can be reverted successfully."));
6293
6294 sc = SFDReadOneChar(cv->b.sc->parent,cv->b.sc->name);
6295 if ( sc==NULL ) {
6296 ff_post_error(_("Can't Find Glyph"),_("The glyph, %.80s, can't be found in the sfd file"),cv->b.sc->name);
6297 cv->b.sc->namechanged = true;
6298 } else {
6299 SCPreserveState(cv->b.sc,true);
6300 SCPreserveBackground(cv->b.sc);
6301 temp = *cv->b.sc;
6302 cv->b.sc->dependents = NULL;
6303 lc = cv->b.sc->layer_cnt;
6304 undoes = malloc(lc*sizeof(Undoes *));
6305 for ( layer=0; layer<lc; ++layer ) {
6306 undoes[layer] = cv->b.sc->layers[layer].undoes;
6307 cv->b.sc->layers[layer].undoes = NULL;
6308 }
6309 SplineCharFreeContents(cv->b.sc);
6310 *cv->b.sc = *sc;
6311 chunkfree(sc,sizeof(SplineChar));
6312 cv->b.sc->parent = temp.parent;
6313 cv->b.sc->dependents = temp.dependents;
6314 for ( layer = 0; layer<lc && layer<cv->b.sc->layer_cnt; ++layer )
6315 cv->b.sc->layers[layer].undoes = undoes[layer];
6316 for ( ; layer<lc; ++layer )
6317 UndoesFree(undoes[layer]);
6318 free(undoes);
6319 cv->b.sc->views = temp.views;
6320 /* cv->b.sc->changed = temp.changed; */
6321 for ( cvs=(CharView *) (cv->b.sc->views); cvs!=NULL; cvs=(CharView *) (cvs->b.next) ) {
6322 cvs->b.layerheads[dm_back] = &cv->b.sc->layers[ly_back];
6323 cvs->b.layerheads[dm_fore] = &cv->b.sc->layers[ly_fore];
6324 if ( cv->b.sc->parent->multilayer ) {
6325 if ( mylayer!=ly_back )
6326 cvs->b.layerheads[dm_fore] = &cv->b.sc->layers[mylayer];
6327 } else {
6328 if ( mylayer!=ly_fore )
6329 cvs->b.layerheads[dm_back] = &cv->b.sc->layers[mylayer];
6330 }
6331 }
6332 RevertedGlyphReferenceFixup(cv->b.sc, temp.parent);
6333 _CV_CharChangedUpdate(cv,false);
6334 }
6335 }
6336
6337 static void CVAddWordList(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e))
6338 {
6339 CharView *cv = (CharView *) GDrawGetUserData(gw);
6340 WordlistLoadToGTextInfo( cv->charselector, &cv->charselectoridx );
6341 }
6342
6343 static void CVMenuPrint(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6344 CharView *cv = (CharView *) GDrawGetUserData(gw);
6345
6346 PrintFFDlg(NULL,cv->b.sc,NULL);
6347 }
6348
6349 #if !defined(_NO_PYTHON)
6350 static void CVMenuExecute(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6351 CharView *cv = (CharView *) GDrawGetUserData(gw);
6352 ScriptDlg((FontView *) (cv->b.fv),cv);
6353 }
6354 #endif /* !_NO_PYTHON */
6355
6356 static void fllistcheck(GWindow gw, struct gmenuitem *mi,GEvent *UNUSED(e)) {
6357 CharView *cv = (CharView *) GDrawGetUserData(gw);
6358 FontView *fvs;
6359
6360 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
6361 switch ( mi->mid ) {
6362 case CV_MID_Open: case CV_MID_New:
6363 mi->ti.disabled = cv->b.container!=NULL && !(cv->b.container->funcs->canOpen)(cv->b.container);
6364 break;
6365 case CV_MID_GenerateTTC:
6366 for ( fvs=fv_list; fvs!=NULL; fvs=(FontView *) (fvs->b.next) ) {
6367 if ( fvs!=(FontView *) cv->b.fv )
6368 break;
6369 }
6370 mi->ti.disabled = fvs==NULL || cv->b.container!=NULL;
6371 break;
6372 case CV_MID_Revert:
6373 mi->ti.disabled = cv->b.fv->sf->origname==NULL || cv->b.fv->sf->isnew || cv->b.container;
6374 break;
6375 case CV_MID_RevertGlyph:
6376 mi->ti.disabled = cv->b.fv->sf->filename==NULL ||
6377 cv->b.fv->sf->sfd_version<2 ||
6378 cv->b.sc->namechanged ||
6379 cv->b.fv->sf->mm!=NULL ||
6380 cv->b.container;
6381 break;
6382 case CV_MID_Recent:
6383 mi->ti.disabled = !RecentFilesAny() ||
6384 (cv->b.container!=NULL && !(cv->b.container->funcs->canOpen)(cv->b.container));
6385 break;
6386 case CV_MID_Close: case CV_MID_Quit:
6387 mi->ti.disabled = false;
6388 break;
6389 case CV_MID_CloseTab:
6390 mi->ti.disabled = cv->tabs==NULL || cv->former_cnt<=1;
6391 break;
6392 default:
6393 mi->ti.disabled = cv->b.container!=NULL;
6394 break;
6395 }
6396 }
6397 }
6398
6399 static void CVMenuFontInfo(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6400 CharView *cv = (CharView *) GDrawGetUserData(gw);
6401 FontInfo(cv->b.sc->parent,CVLayer((CharViewBase *) cv),-1,false);
6402 }
6403
6404 static void CVMenuFindProblems(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6405 CharView *cv = (CharView *) GDrawGetUserData(gw);
6406 FindProblems(NULL,cv,NULL);
6407 }
6408
6409 static void CVMenuEmbolden(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6410 CharView *cv = (CharView *) GDrawGetUserData(gw);
6411 EmboldenDlg(NULL,cv);
6412 }
6413
6414 static void CVMenuItalic(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6415 CharView *cv = (CharView *) GDrawGetUserData(gw);
6416 ItalicDlg(NULL,cv);
6417 }
6418
6419 static void CVMenuOblique(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6420 CharView *cv = (CharView *) GDrawGetUserData(gw);
6421 ObliqueDlg(NULL,cv);
6422 }
6423
6424 static void CVMenuCondense(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6425 CharView *cv = (CharView *) GDrawGetUserData(gw);
6426 CondenseExtendDlg(NULL,cv);
6427 }
6428
6429 static void CVMenuChangeXHeight(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6430 CharView *cv = (CharView *) GDrawGetUserData(gw);
6431 ChangeXHeightDlg(NULL,cv);
6432 }
6433
6434 static void CVMenuChangeGlyph(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6435 CharView *cv = (CharView *) GDrawGetUserData(gw);
6436 GlyphChangeDlg(NULL,cv,gc_generic);
6437 }
6438
6439 static void CVMenuInline(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6440 CharView *cv = (CharView *) GDrawGetUserData(gw);
6441 OutlineDlg(NULL,cv,NULL,true);
6442 }
6443
6444 static void CVMenuOutline(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6445 CharView *cv = (CharView *) GDrawGetUserData(gw);
6446 OutlineDlg(NULL,cv,NULL,false);
6447 }
6448
6449 static void CVMenuShadow(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6450 CharView *cv = (CharView *) GDrawGetUserData(gw);
6451 ShadowDlg(NULL,cv,NULL,false);
6452 }
6453
6454 static void CVMenuWireframe(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6455 CharView *cv = (CharView *) GDrawGetUserData(gw);
6456 ShadowDlg(NULL,cv,NULL,true);
6457 }
6458
6459 static void _CVMenuScale(CharView *cv, int mid) {
6460 CharViewTab* tab = CVGetActiveTab(cv);
6461 if ( mid == CV_MID_Fit ) {
6462 CVFit(cv);
6463 } else {
6464 BasePoint c;
6465 c.x = (cv->width/2-tab->xoff)/tab->scale;
6466 c.y = (cv->height/2-tab->yoff)/tab->scale;
6467 if ( CVAnySel(cv,NULL,NULL,NULL,NULL))
6468 CVFindCenter(cv,&c,false);
6469 CVMagnify(cv,c.x,c.y, mid==CV_MID_ZoomOut?-1:1,0);
6470 }
6471 }
6472
6473 static void CVMenuScale(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
6474 CharView *cv = (CharView *) GDrawGetUserData(gw);
6475 _CVMenuScale(cv,mi->mid);
6476 }
6477
6478 static void CVMenuShowHide(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6479 CharView *cv = (CharView *) GDrawGetUserData(gw);
6480 CVShows.showpoints = cv->showpoints = !cv->showpoints;
6481 GDrawRequestExpose(cv->v,NULL,false);
6482 }
6483
6484 static void CVMenuShowHideControlPoints(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6485 CharView *cv = (CharView *) GDrawGetUserData(gw);
6486 CVShows.alwaysshowcontrolpoints = cv->alwaysshowcontrolpoints = !cv->alwaysshowcontrolpoints;
6487 GDrawRequestExpose(cv->v,NULL,false);
6488 }
6489
6490 static void CVMenuNumberPoints(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
6491 CharView *cv = (CharView *) GDrawGetUserData(gw);
6492
6493 switch ( mi->mid ) {
6494 case CV_MID_PtsNone:
6495 cv->showpointnumbers = 0;
6496 break;
6497 case CV_MID_PtsTrue:
6498 cv->showpointnumbers = 1;
6499 CVCheckPoints(cv);
6500 break;
6501 case CV_MID_PtsPost:
6502 cv->showpointnumbers = 1;
6503 cv->b.sc->numberpointsbackards = true;
6504 break;
6505 case CV_MID_PtsSVG:
6506 cv->showpointnumbers = 1;
6507 cv->b.sc->numberpointsbackards = false;
6508 break;
6509 case CV_MID_PtsPos:
6510 cv->showpointnumbers = 2;
6511 break;
6512 }
6513 SCNumberPoints(cv->b.sc,CVLayer((CharViewBase *) cv));
6514 SCUpdateAll(cv->b.sc);
6515 }
6516
6517 static void CVMenuMarkExtrema(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6518 CharView *cv = (CharView *) GDrawGetUserData(gw);
6519
6520 CVShows.markextrema = cv->markextrema = !cv->markextrema;
6521 SavePrefs(true);
6522 GDrawRequestExpose(cv->v,NULL,false);
6523 }
6524
6525 static void CVMenuMarkPointsOfInflection(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6526 CharView *cv = (CharView *) GDrawGetUserData(gw);
6527
6528 CVShows.markpoi = cv->markpoi = !cv->markpoi;
6529 SavePrefs(true);
6530 GDrawRequestExpose(cv->v,NULL,false);
6531 }
6532
6533 static void CVMenuShowAlmostHV(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6534 CharView *cv = (CharView *) GDrawGetUserData(gw);
6535
6536 CVShows.showalmosthvlines = cv->showalmosthvlines = !cv->showalmosthvlines;
6537 SavePrefs(true);
6538 GDrawRequestExpose(cv->v,NULL,false);
6539 }
6540
6541 static void CVMenuShowAlmostHVCurves(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6542 CharView *cv = (CharView *) GDrawGetUserData(gw);
6543
6544 CVShows.showalmosthvcurves = cv->showalmosthvcurves = !cv->showalmosthvcurves;
6545 SavePrefs(true);
6546 GDrawRequestExpose(cv->v,NULL,false);
6547 }
6548
6549 static void CVMenuDefineAlmost(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6550 CharView *cv = (CharView *) GDrawGetUserData(gw);
6551 char buf[20], *end;
6552 int val;
6553 char *ret;
6554
6555 sprintf(buf,"%d",cv->hvoffset );
6556
6557 ret = gwwv_ask_string(_("Define \"Almost Horizontal\""),buf,
6558 _("A line is \"almost\" horizontal (or vertical)\nif the coordinates are within this many em-units"));
6559 if ( ret==NULL )
6560 return;
6561 val = strtol(ret,&end,10);
6562 if ( val>100 || val<=0 || *end!='\0' ) {
6563 free(ret);
6564 ff_post_error(_("Bad number"),_("Bad number"));
6565 } else {
6566 free(ret);
6567 CVShows.hvoffset = cv->hvoffset = val;
6568 SavePrefs(true);
6569 GDrawRequestExpose(cv->v,NULL,false);
6570 }
6571 }
6572
6573 static void CVMenuShowCPInfo(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6574 CharView *cv = (CharView *) GDrawGetUserData(gw);
6575
6576 CVShows.showcpinfo = cv->showcpinfo = !cv->showcpinfo;
6577 SavePrefs(true);
6578 /* Nothing to update, only show this stuff in the user is moving a cp */
6579 /* which s/he is currently not, s/he is manipulating the menu */
6580 }
6581
6582 static void CVMenuShowTabs(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6583 CharView *cv = (CharView *) GDrawGetUserData(gw);
6584
6585 CVShows.showtabs = cv->showtabs = !cv->showtabs;
6586 CVChangeTabsVisibility(cv,cv->showtabs);
6587 SavePrefs(true);
6588 }
6589
6590 static void CVMenuShowSideBearings(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6591 CharView *cv = (CharView *) GDrawGetUserData(gw);
6592
6593 CVShows.showsidebearings = cv->showsidebearings = !cv->showsidebearings;
6594 SavePrefs(true);
6595 GDrawRequestExpose(cv->v,NULL,false);
6596 }
6597
6598 static void CVMenuShowRefNames(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6599 CharView *cv = (CharView *) GDrawGetUserData(gw);
6600
6601 CVShows.showrefnames = cv->showrefnames = !cv->showrefnames;
6602 SavePrefs(true);
6603 GDrawRequestExpose(cv->v,NULL,false);
6604 }
6605
6606 static void CVMenuSnapOutlines(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6607 CharView *cv = (CharView *) GDrawGetUserData(gw);
6608
6609 CVShows.snapoutlines = cv->snapoutlines = !cv->snapoutlines;
6610 SavePrefs(true);
6611 GDrawRequestExpose(cv->v,NULL,false);
6612 }
6613
6614 static void CVMenuShowHints(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
6615 CharView *cv = (CharView *) GDrawGetUserData(gw);
6616
6617 switch ( mi->mid ) {
6618 case CV_MID_ShowHHints:
6619 CVShows.showhhints = cv->showhhints = !cv->showhhints;
6620 break;
6621 case CV_MID_ShowVHints:
6622 CVShows.showvhints = cv->showvhints = !cv->showvhints;
6623 break;
6624 case CV_MID_ShowDHints:
6625 CVShows.showdhints = cv->showdhints = !cv->showdhints;
6626 break;
6627 case CV_MID_ShowBlueValues:
6628 CVShows.showblues = cv->showblues = !cv->showblues;
6629 break;
6630 case CV_MID_ShowFamilyBlues:
6631 CVShows.showfamilyblues = cv->showfamilyblues = !cv->showfamilyblues;
6632 break;
6633 case CV_MID_ShowAnchors:
6634 CVShows.showanchor = cv->showanchor = !cv->showanchor;
6635 break;
6636 case CV_MID_ShowHMetrics:
6637 CVShows.showhmetrics = cv->showhmetrics = !cv->showhmetrics;
6638 break;
6639 case CV_MID_ShowVMetrics:
6640 CVShows.showvmetrics = cv->showvmetrics = !cv->showvmetrics;
6641 break;
6642 case CV_MID_ShowDebugChanges:
6643 CVShows.showdebugchanges = cv->showdebugchanges = !cv->showdebugchanges;
6644 break;
6645 default:
6646 IError("Unexpected call to CVMenuShowHints");
6647 break;
6648 }
6649 SavePrefs(true);
6650 GDrawRequestExpose(cv->v,NULL,false);
6651 /* !!!! In this interim version we should request an expose on cvlayers */
6652 /* but that's private to cvpalettes, and later we won't need to */
6653 }
6654
6655 static void _CVMenuShowHideRulers(CharView *cv) {
6656 GRect pos;
6657
6658 CVShows.showrulers = cv->showrulers = !cv->showrulers;
6659 pos.y = cv->mbh+cv->charselectorh+cv->infoh;
6660 pos.x = 0;
6661 if ( cv->showrulers ) {
6662 cv->height -= cv->rulerh;
6663 cv->width -= cv->rulerh;
6664 pos.y += cv->rulerh;
6665 pos.x += cv->rulerh;
6666 } else {
6667 cv->height += cv->rulerh;
6668 cv->width += cv->rulerh;
6669 }
6670 pos.width = cv->width; pos.height = cv->height;
6671 GDrawMoveResize(cv->v,pos.x,pos.y,pos.width,pos.height);
6672 GDrawSync(NULL);
6673 GDrawRequestExpose(cv->v,NULL,false);
6674 SavePrefs(true);
6675 }
6676
6677 static void CVMenuShowHideRulers(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6678 CharView *cv = (CharView *) GDrawGetUserData(gw);
6679 _CVMenuShowHideRulers(cv);
6680 }
6681
6682 static void CVMenuFill(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6683 CharView *cv = (CharView *) GDrawGetUserData(gw);
6684
6685 CVShows.showfilled = cv->showfilled = !cv->showfilled;
6686 GDrawRequestExpose(cv->v,NULL,false);
6687 }
6688
6689 static struct cvshows* cvshowsCopyTo( struct cvshows* dst, CharView* src )
6690 {
6691 dst->showfore = src->showfore;
6692 dst->showgrids = src->showgrids;
6693 dst->showhhints = src->showhhints;
6694 dst->showvhints = src->showvhints;
6695 dst->showdhints = src->showdhints;
6696 dst->showpoints = src->showpoints;
6697 dst->alwaysshowcontrolpoints = src->alwaysshowcontrolpoints;
6698 dst->showfilled = src->showfilled;
6699 dst->showrulers = src->showrulers;
6700 dst->showrounds = src->showrounds;
6701 dst->showmdx = src->showmdx;
6702 dst->showmdy = src->showmdy;
6703 dst->showhmetrics = src->showhmetrics;
6704 dst->showvmetrics = src->showvmetrics;
6705 dst->markextrema = src->markextrema;
6706 dst->markpoi = src->markpoi;
6707 dst->showblues = src->showblues;
6708 dst->showfamilyblues = src->showfamilyblues;
6709 dst->showanchor = src->showanchor;
6710 dst->showcpinfo = src->showcpinfo;
6711 dst->showtabs = src->showtabs;
6712 dst->showsidebearings = src->showsidebearings;
6713 dst->showrefnames = src->showrefnames;
6714 dst->snapoutlines = src->snapoutlines;
6715 dst->showalmosthvlines = src->showalmosthvlines;
6716 dst->showalmosthvcurves = src->showalmosthvcurves;
6717 dst->hvoffset = src->hvoffset;
6718 dst->checkselfintersects = src->checkselfintersects;
6719 dst->showdebugchanges = src->showdebugchanges;
6720 return dst;
6721 }
6722
6723 static CharView* cvshowsCopyFrom( CharView* dst, struct cvshows* src )
6724 {
6725 dst->showfore = src->showfore;
6726 dst->showgrids = src->showgrids;
6727 dst->showhhints = src->showhhints;
6728 dst->showvhints = src->showvhints;
6729 dst->showdhints = src->showdhints;
6730 dst->showpoints = src->showpoints;
6731 dst->alwaysshowcontrolpoints = src->alwaysshowcontrolpoints;
6732 dst->showfilled = src->showfilled;
6733 dst->showrulers = src->showrulers;
6734 dst->showrounds = src->showrounds;
6735 dst->showmdx = src->showmdx;
6736 dst->showmdy = src->showmdy;
6737 dst->showhmetrics = src->showhmetrics;
6738 dst->showvmetrics = src->showvmetrics;
6739 dst->markextrema = src->markextrema;
6740 dst->markpoi = src->markpoi;
6741 dst->showblues = src->showblues;
6742 dst->showfamilyblues = src->showfamilyblues;
6743 dst->showanchor = src->showanchor;
6744 dst->showcpinfo = src->showcpinfo;
6745 dst->showtabs = src->showtabs;
6746 dst->showsidebearings = src->showsidebearings;
6747 dst->showrefnames = src->showrefnames;
6748 dst->snapoutlines = src->snapoutlines;
6749 dst->showalmosthvlines = src->showalmosthvlines;
6750 dst->showalmosthvcurves = src->showalmosthvcurves;
6751 dst->hvoffset = src->hvoffset;
6752 dst->checkselfintersects = src->checkselfintersects;
6753 dst->showdebugchanges = src->showdebugchanges;
6754 return dst;
6755 }
6756
6757 static void CVPreviewModeSet(GWindow gw, int checked ) {
6758 CharView *cv = (CharView *) GDrawGetUserData(gw);
6759 if( checked == cv->inPreviewMode )
6760 return;
6761
6762 cv->inPreviewMode = checked;
6763 if( checked ) {
6764 cvshowsCopyTo( &CVShowsPrevewToggleSavedState, cv );
6765 cv->showfore = 1;
6766 cv->showgrids = 0;
6767 cv->showhhints = 0;
6768 cv->showvhints = 0;
6769 cv->showdhints = 0;
6770 cv->showpoints = 0;
6771 cv->alwaysshowcontrolpoints = 0;
6772 cv->showfilled = 1;
6773 cv->showrounds = 0;
6774 cv->showanchor = 0;
6775 cv->showrefnames = 0;
6776 cv->showhmetrics = 0;
6777 cv->showvmetrics = 0;
6778 } else {
6779 cvshowsCopyFrom( cv, &CVShowsPrevewToggleSavedState );
6780 }
6781 GDrawRequestExpose(cv->v,NULL,false);
6782 }
6783
6784 static void CVMenuPreview(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
6785 int checked = mi->ti.checked;
6786
6787 #if 0
6788 // This has the effect of breaking the button since cv_auto_goto and HaveModifiers tend to be false.
6789 // The purpose of these checks is unclear.
6790 if( !cv_auto_goto ) {
6791 if( !HaveModifiers )
6792 return;
6793 }
6794 #endif // 0
6795
6796 CVPreviewModeSet(gw, checked);
6797 }
6798
6799 static void CVMenuDraggingComparisonOutline(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e))
6800 {
6801 CharView *cv = (CharView *) GDrawGetUserData(gw);
6802
6803 int checked = mi->ti.checked;
6804 SplinePointListFree(cv->p.pretransform_spl);
6805 cv->p.pretransform_spl = NULL;
6806 prefs_create_dragging_comparison_outline = checked;
6807 SavePrefs(true);
6808 }
6809
6810
6811 static void CVMenuShowGridFit(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6812 CharView *cv = (CharView *) GDrawGetUserData(gw);
6813
6814 if ( !hasFreeType() || cv->dv!=NULL )
6815 return;
6816 cv->show_ft_results_live_update = 0;
6817 CVFtPpemDlg(cv,false);
6818 }
6819
6820 static void CVMenuShowGridFitLiveUpdate(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6821 CharView *cv = (CharView *) GDrawGetUserData(gw);
6822
6823 if ( !hasFreeType() || cv->dv!=NULL )
6824 return;
6825 cv->show_ft_results_live_update = 1;
6826 CVFtPpemDlg(cv,false);
6827 }
6828
6829 static void CVMenuChangePointSize(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
6830 CharView *cv = (CharView *) GDrawGetUserData(gw);
6831
6832 if ( !hasFreeType() || cv->dv!=NULL || !cv->show_ft_results )
6833 return;
6834
6835 if ( mi->mid==CV_MID_GridFitOff ) {
6836 cv->show_ft_results = false;
6837 cv->show_ft_results_live_update = false;
6838
6839 SplinePointListsFree(cv->b.gridfit); cv->b.gridfit = NULL;
6840 FreeType_FreeRaster(cv->raster); cv->raster = NULL;
6841 GDrawRequestExpose(cv->v,NULL,false);
6842 } else {
6843 if ( mi->mid==CV_MID_Bigger ) {
6844 ++cv->ft_pointsizex;
6845 ++cv->ft_pointsizey;
6846 } else if ( mi->mid==CV_MID_Smaller ) {
6847 if ( cv->ft_pointsizex>1 )
6848 --cv->ft_pointsizex;
6849 if ( cv->ft_pointsizey>1 )
6850 --cv->ft_pointsizey;
6851 }
6852
6853 if ( mi->mid==CV_MID_GridFitAA )
6854 cv->ft_depth = cv->ft_depth==8 ? 1 : 8;
6855 cv->ft_ppemx = rint(cv->ft_pointsizex*cv->ft_dpi/72.0);
6856 cv->ft_ppemy = rint(cv->ft_pointsizey*cv->ft_dpi/72.0);
6857 CVGridFitChar(cv);
6858 }
6859 SCRefreshTitles(cv->b.sc);
6860 }
6861
6862 static void CVMenuEditInstrs(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6863 CharView *cv = (CharView *) GDrawGetUserData(gw);
6864 SCEditInstructions(cv->b.sc);
6865 }
6866
6867 static void CVMenuDebug(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6868 CharView *cv = (CharView *) GDrawGetUserData(gw);
6869
6870 if ( !hasFreeTypeDebugger())
6871 return;
6872 CVFtPpemDlg(cv,true);
6873 }
6874
6875 static void CVMenuDeltas(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6876 CharView *cv = (CharView *) GDrawGetUserData(gw);
6877
6878 if ( !hasFreeTypeDebugger())
6879 return;
6880 DeltaSuggestionDlg(NULL,cv);
6881 }
6882
6883 static void CVMenuClearInstrs(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6884 CharView *cv = (CharView *) GDrawGetUserData(gw);
6885
6886 if ( cv->b.sc->ttf_instrs_len!=0 ) {
6887 free(cv->b.sc->ttf_instrs);
6888 cv->b.sc->ttf_instrs = NULL;
6889 cv->b.sc->ttf_instrs_len = 0;
6890 cv->b.sc->instructions_out_of_date = false;
6891 SCCharChangedUpdate(cv->b.sc,ly_none);
6892 SCMarkInstrDlgAsChanged(cv->b.sc);
6893 cv->b.sc->complained_about_ptnums = false; /* Should be after CharChanged */
6894 }
6895 }
6896
6897 static void CVMenuKernPairs(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6898 CharView *cv = (CharView *) GDrawGetUserData(gw);
6899 SFShowKernPairs(cv->b.sc->parent,cv->b.sc,NULL,CVLayer((CharViewBase *) cv));
6900 }
6901
6902 static void CVMenuLigatures(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6903 CharView *cv = (CharView *) GDrawGetUserData(gw);
6904 SFShowLigatures(cv->b.fv->sf,cv->b.sc);
6905 }
6906
6907 static void CVMenuAnchorPairs(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6908 CharView *cv = (CharView *) GDrawGetUserData(gw);
6909 SFShowKernPairs(cv->b.sc->parent,cv->b.sc,(AnchorClass *) (-1),CVLayer((CharViewBase *) cv));
6910 }
6911
6912 static void CVMenuAPDetach(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
6913 CharView *cv = (CharView *) GDrawGetUserData(gw);
6914 cv->apmine = cv->apmatch = NULL;
6915 cv->apsc = NULL;
6916 GDrawRequestExpose(cv->v,NULL,false);
6917 }
6918
6919 static void CVMenuAPAttachSC(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
6920 CharView *cv = (CharView *) GDrawGetUserData(gw);
6921 enum anchor_type type;
6922 AnchorPoint *ap;
6923 AnchorClass *ac;
6924
6925 for ( ap = cv->b.sc->anchor; ap!=NULL && !ap->selected; ap=ap->next );
6926 if ( ap==NULL )
6927 ap = cv->b.sc->anchor;
6928 if ( ap==NULL )
6929 return;
6930 type = ap->type;
6931 cv->apmine = ap;
6932 ac = ap->anchor;
6933 cv->apsc = mi->ti.userdata;
6934 for ( ap = cv->apsc->anchor; ap!=NULL ; ap=ap->next ) {
6935 if ( ap->anchor==ac &&
6936 ((type==at_centry && ap->type==at_cexit) ||
6937 (type==at_cexit && ap->type==at_centry) ||
6938 (type==at_mark && ap->type!=at_mark) ||
6939 ((type==at_basechar || type==at_baselig || type==at_basemark) && ap->type==at_mark)) )
6940 break;
6941 }
6942 cv->apmatch = ap;
6943 GDrawRequestExpose(cv->v,NULL,false);
6944 }
6945
6946 static SplineChar **GlyphsMatchingAP(SplineFont *sf, AnchorPoint *ap) {
6947 SplineChar *sc;
6948 AnchorClass *ac = ap->anchor;
6949 enum anchor_type type = ap->type;
6950 int i, k, gcnt;
6951 SplineChar **glyphs;
6952
6953 glyphs = NULL;
6954 for ( k=0; k<2; ++k ) {
6955 gcnt = 0;
6956 for ( i=0; i<sf->glyphcnt; ++i ) if ( (sc=sf->glyphs[i])!=NULL ) {
6957 for ( ap = sc->anchor; ap!=NULL; ap=ap->next ) {
6958 if ( ap->anchor == ac &&
6959 ((type==at_centry && ap->type==at_cexit) ||
6960 (type==at_cexit && ap->type==at_centry) ||
6961 (type==at_mark && ap->type!=at_mark) ||
6962 ((type==at_basechar || type==at_baselig || type==at_basemark) && ap->type==at_mark)) )
6963 break;
6964 }
6965 if ( ap!=NULL ) {
6966 if ( k )
6967 glyphs[gcnt] = sc;
6968 ++gcnt;
6969 }
6970 }
6971 if ( !k ) {
6972 if ( gcnt==0 )
6973 return( NULL );
6974 glyphs = malloc((gcnt+1)*sizeof(SplineChar *));
6975 } else
6976 glyphs[gcnt] = NULL;
6977 }
6978 return( glyphs );
6979 }
6980
6981 static void _CVMenuChangeChar(CharView *cv, int mid) {
6982 SplineFont *sf = cv->b.sc->parent;
6983 int pos = -1;
6984 int gid;
6985 EncMap *map = cv->b.fv->map;
6986 Encoding *enc = map->enc;
6987
6988 if ( cv->b.container!=NULL ) {
6989 if ( cv->b.container->funcs->doNavigate!=NULL && mid != CV_MID_Former)
6990 (cv->b.container->funcs->doNavigate)(cv->b.container,
6991 mid==CV_MID_Next ? nt_next :
6992 mid==CV_MID_Prev ? nt_prev :
6993 mid==CV_MID_NextDef ? nt_next :
6994 /* mid==CV_MID_PrevDef ?*/ nt_prev);
6995 return;
6996 }
6997
6998 int curenc = CVCurEnc(cv);
6999
7000 if( cv->charselector )
7001 {
7002 char* txt = GGadgetGetTitle8( cv->charselector );
7003 if( txt && strlen(txt) > 1 )
7004 {
7005 int offset = 1;
7006 if ( mid == CV_MID_Prev )
7007 offset = -1;
7008
7009 unichar_t *txtu = GGadgetGetTitle( cv->charselector );
7010 unichar_t* r = Wordlist_advanceSelectedCharsBy( cv->b.sc->parent,
7011 ((FontView *) (cv->b.fv))->b.map,
7012 txtu, offset );
7013 free( txtu );
7014
7015 GGadgetSetTitle( cv->charselector, r );
7016 // Force any extra chars to be setup and drawn
7017 GEvent e;
7018 e.type=et_controlevent;
7019 e.u.control.subtype = et_textchanged;
7020 e.u.control.u.tf_changed.from_pulldown = 0;
7021 CV_OnCharSelectorTextChanged( cv->charselector, &e );
7022 return;
7023 }
7024 }
7025
7026 if ( mid == CV_MID_Next ) {
7027 pos = curenc+1;
7028 } else if ( mid == CV_MID_Prev ) {
7029 pos = curenc-1;
7030 } else if ( mid == CV_MID_NextDef ) {
7031 for ( pos = CVCurEnc(cv)+1; pos<map->enccount &&
7032 ((gid=map->map[pos])==-1 || !SCWorthOutputting(sf->glyphs[gid])); ++pos );
7033 if ( pos>=map->enccount ) {
7034 if ( enc->is_tradchinese ) {
7035 if ( strstrmatch(enc->enc_name,"hkscs")!=NULL ) {
7036 if ( CVCurEnc(cv)<0x8140 )
7037 pos = 0x8140;
7038 } else {
7039 if ( CVCurEnc(cv)<0xa140 )
7040 pos = 0xa140;
7041 }
7042 } else if ( CVCurEnc(cv)<0x8431 && strstrmatch(enc->enc_name,"johab")!=NULL )
7043 pos = 0x8431;
7044 else if ( CVCurEnc(cv)<0xa1a1 && strstrmatch(enc->iconv_name?enc->iconv_name:enc->enc_name,"EUC")!=NULL )
7045 pos = 0xa1a1;
7046 else if ( CVCurEnc(cv)<0x8140 && strstrmatch(enc->enc_name,"sjis")!=NULL )
7047 pos = 0x8140;
7048 else if ( CVCurEnc(cv)<0xe040 && strstrmatch(enc->enc_name,"sjis")!=NULL )
7049 pos = 0xe040;
7050 if ( pos>=map->enccount )
7051 return;
7052 }
7053 } else if ( mid == CV_MID_PrevDef ) {
7054 for ( pos = CVCurEnc(cv)-1; pos>=0 &&
7055 ((gid=map->map[pos])==-1 || !SCWorthOutputting(sf->glyphs[gid])); --pos );
7056 if ( pos<0 )
7057 return;
7058 } else if ( mid == CV_MID_Former ) {
7059 if ( cv->former_cnt<=1 )
7060 return;
7061 for ( gid=sf->glyphcnt-1; gid>=0; --gid )
7062 if ( sf->glyphs[gid]!=NULL &&
7063 strcmp(sf->glyphs[gid]->name,cv->former_names[1])==0 )
7064 break;
7065 if ( gid<0 )
7066 return;
7067 pos = map->backmap[gid];
7068 }
7069 /* Werner doesn't think it should wrap */
7070 if ( pos<0 ) /* pos = map->enccount-1; */
7071 return;
7072 else if ( pos>= map->enccount ) /* pos = 0; */
7073 return;
7074
7075 if ( pos>=0 && pos<map->enccount )
7076 CVChangeChar(cv,pos);
7077 }
7078
7079
7080 static void CVMenuChangeChar(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
7081 CharView *cv = (CharView *) GDrawGetUserData(gw);
7082 _CVMenuChangeChar(cv,mi->mid);
7083 }
7084
7085 static int CVMoveToNextInWordList(GGadget *g, GEvent *e)
7086 {
7087 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
7088 CharView *cv = GDrawGetUserData(GGadgetGetWindow(g));
7089 CVMoveInWordListByOffset( cv, 1 );
7090 }
7091 return 1;
7092 }
7093 static int CVMoveToPrevInWordList(GGadget *g, GEvent *e)
7094 {
7095 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
7096 CharView *cv = GDrawGetUserData(GGadgetGetWindow(g));
7097 CVMoveInWordListByOffset( cv, -1 );
7098 }
7099 return 1;
7100 }
7101
7102 /**
7103 * If the prev/next BCP is selected than add those to the hash table
7104 * at "ret".
7105 */
7106 static void getSelectedControlPointsVisitor(SplinePoint* splfirst, Spline* s, SplinePoint* sp, void* udata )
7107 {
7108 GHashTable* ret = (GHashTable*)udata;
7109 if( sp->nextcpselected )
7110 g_hash_table_insert( ret, sp, 0 );
7111 if( sp->prevcpselected )
7112 g_hash_table_insert( ret, sp, 0 );
7113 }
7114 static void getAllControlPointsVisitor(SplinePoint* splfirst, Spline* s, SplinePoint* sp, void* udata )
7115 {
7116 GHashTable* ret = (GHashTable*)udata;
7117 g_hash_table_insert( ret, sp, 0 );
7118 g_hash_table_insert( ret, sp, 0 );
7119 }
7120
7121 /**
7122 * Get a hash table with all the selected BCP in it.
7123 *
7124 * The caller must call g_hash_table_destroy() on the return value.
7125 */
7126 static GHashTable* getSelectedControlPoints( CharView *cv, PressedOn *p )
7127 {
7128 Layer* l = cv->b.layerheads[cv->b.drawmode];
7129 if( !l || !l->splines )
7130 return 0;
7131
7132 GHashTable* ret = g_hash_table_new( g_direct_hash, g_direct_equal );
7133 SplinePointList* spl = l->splines;
7134 for( ; spl; spl = spl->next )
7135 {
7136 SPLFirstVisitPoints( spl->first, getSelectedControlPointsVisitor, ret );
7137 }
7138
7139 return ret;
7140 }
7141 static GHashTable* getAllControlPoints( CharView *cv, PressedOn *p )
7142 {
7143 Layer* l = cv->b.layerheads[cv->b.drawmode];
7144 if( !l || !l->splines )
7145 return 0;
7146
7147 GHashTable* ret = g_hash_table_new( g_direct_hash, g_direct_equal );
7148 SplinePointList* spl = l->splines;
7149 for( ; spl; spl = spl->next )
7150 {
7151 SPLFirstVisitPoints( spl->first, getAllControlPointsVisitor, ret );
7152 }
7153 return ret;
7154 }
7155
7156 void FE_touchControlPoint( void* key,
7157 void* value,
7158 SplinePoint* sp,
7159 BasePoint *which,
7160 bool isnext,
7161 void* udata )
7162 {
7163 TRACE("FE_touchControlPoint() which:%p\n", which );
7164 SPTouchControl( sp, which, (int)(intptr_t)udata );
7165 }
7166
7167 void FE_unselectBCP( void* key,
7168 void* value,
7169 SplinePoint* sp,
7170 BasePoint *which,
7171 bool isnext,
7172 void* udata )
7173 {
7174 sp->nextcpselected = 0;
7175 sp->prevcpselected = 0;
7176 }
7177
7178 void FE_adjustBCPByDelta( void* key,
7179 void* value,
7180 SplinePoint* sp,
7181 BasePoint *which,
7182 bool isnext,
7183 void* udata )
7184 {
7185 FE_adjustBCPByDeltaData* data = (FE_adjustBCPByDeltaData*)udata;
7186 CharView *cv = data->cv;
7187
7188 TRACE("FE_adjustBCPByDelta %p %d\n", which, isnext );
7189 BasePoint to;
7190 to.x = which->x + data->dx;
7191 to.y = which->y + data->dy;
7192 SPAdjustControl(sp,which,&to,cv->b.layerheads[cv->b.drawmode]->order2);
7193 CVSetCharChanged(cv,true);
7194 }
7195
7196 void FE_adjustBCPByDeltaWhilePreservingBCPAngle( void* key,
7197 void* value,
7198 SplinePoint* sp,
7199 BasePoint *which,
7200 bool isnext,
7201 void* udata )
7202 {
7203 FE_adjustBCPByDeltaData* data = (FE_adjustBCPByDeltaData*)udata;
7204 CharView *cv = data->cv;
7205
7206 // TRACE("FE_adjustBCPByDeltaWhilePreservingBCPAngle which:%p data:%p isnext:%d\n", which, data, isnext );
7207 // TRACE("FE_adjustBCPByDeltaWhilePreservingBCPAngle delta %f %f\n", data->dx, data->dy );
7208 BasePoint to;
7209 to.x = which->x + data->dx;
7210 to.y = which->y + data->dy;
7211
7212 // work out near and far BCP for this movement
7213 BasePoint* near = &sp->nextcp;
7214 BasePoint* far = &sp->prevcp;
7215 if( !isnext )
7216 {
7217 near = &sp->prevcp;
7218 far = &sp->nextcp;
7219 }
7220
7221 real dx = near->x - far->x;
7222 if( !fabs(dx) )
7223 {
7224 // flatline protection
7225 to.x = which->x + data->dx;
7226 to.y = which->y + data->dy;
7227 }
7228 else
7229 {
7230 // we have a workable gradient
7231 real m = (near->y - far->y) / dx;
7232
7233 // should we lean to x or y for the change?
7234 // all this is based on m = y2-y1/x2-x1
7235 // we use m from near and far and extrapolate to the new location
7236 // based on either x or y and calculate the other ordinate from the
7237 // gradiant function above.
7238 if( fabs(m) < 1.0 )
7239 {
7240 real datadx = data->dx;
7241 if( data->keyboarddx && !datadx )
7242 {
7243 datadx = data->dy;
7244 if( m < 0 )
7245 datadx *= -1;
7246 }
7247
7248 real dx = near->x - far->x;
7249 real m = (near->y - far->y) / dx;
7250 to.x = which->x + datadx;
7251 to.y = m * (to.x - near->x) + near->y;
7252 }
7253 else
7254 {
7255 real datady = data->dy;
7256 if( data->keyboarddx && !datady )
7257 {
7258 datady = data->dx;
7259 if( m < 0 )
7260 datady *= -1;
7261 }
7262 real dx = near->x - far->x;
7263 real m = (near->y - far->y) / dx;
7264 to.y = which->y + datady;
7265 to.x = (to.y - near->y + m*near->x) / m;
7266 }
7267 }
7268
7269 // move the point and update
7270 SPAdjustControl(sp,which,&to,cv->b.layerheads[cv->b.drawmode]->order2);
7271 CVSetCharChanged(cv,true);
7272 }
7273
7274 /**
7275 * Container for arguments to FE_visitSelectedControlPoints.
7276 */
7277 typedef struct visitSelectedControlPoints_CallbackDataS
7278 {
7279 int count; // number of times visitor is called.
7280 int sel;
7281 visitSelectedControlPointsVisitor func; // Visitor function to delegate to
7282 gpointer udata; // user data to use when calling above func()
7283
7284 } visitSelectedControlPoints_CallbackData;
7285
7286 /**
7287 * Visitor function: calls a delegate visitor function for any prev
7288 * and next BCP which are selected for each spline point. This is a
7289 * handy visitor when your BCP handling code for the most part doesn't
7290 * care if it will operate on the next or prev BCP, ie your visitor
7291 * simply wants to visit all the selected BCP.
7292 */
7293 static void FE_visitSelectedControlPoints( gpointer key,
7294 gpointer value,
7295 gpointer udata )
7296 {
7297 visitSelectedControlPoints_CallbackData* d = (visitSelectedControlPoints_CallbackData*)udata;
7298 SplinePoint* sp = (SplinePoint*)key;
7299
7300 d->count++;
7301 if( sp->nextcpselected )
7302 {
7303 BasePoint *which = &sp->nextcp;
7304 d->func( key, value, sp, which, true, d->udata );
7305 }
7306 if( sp->prevcpselected )
7307 {
7308 BasePoint *which = &sp->prevcp;
7309 d->func( key, value, sp, which, false, d->udata );
7310 }
7311 }
7312 static void FE_visitAllControlPoints( gpointer key,
7313 gpointer value,
7314 gpointer udata )
7315 {
7316 visitSelectedControlPoints_CallbackData* d = (visitSelectedControlPoints_CallbackData*)udata;
7317 SplinePoint* sp = (SplinePoint*)key;
7318
7319 d->count++;
7320 {
7321 BasePoint *which = &sp->nextcp;
7322 d->func( key, value, sp, which, true, d->udata );
7323 }
7324 {
7325 BasePoint *which = &sp->prevcp;
7326 d->func( key, value, sp, which, false, d->udata );
7327 }
7328 }
7329 static void FE_visitAdjacentToSelectedControlPoints( gpointer key,
7330 gpointer value,
7331 gpointer udata )
7332 {
7333 visitSelectedControlPoints_CallbackData* d = (visitSelectedControlPoints_CallbackData*)udata;
7334 SplinePoint* sp = (SplinePoint*)key;
7335
7336 if( sp->selected )
7337 return;
7338
7339 d->count++;
7340 if( sp->prev && sp->prev->from && sp->prev->from->selected )
7341 {
7342 d->func( key, value, sp, &sp->nextcp, true, d->udata );
7343 d->func( key, value, sp, &sp->prevcp, true, d->udata );
7344 }
7345 if( sp->next && sp->next->to && sp->next->to->selected )
7346 {
7347 d->func( key, value, sp, &sp->nextcp, true, d->udata );
7348 d->func( key, value, sp, &sp->prevcp, true, d->udata );
7349 }
7350 }
7351
7352 void visitSelectedControlPoints( GHashTable *col, visitSelectedControlPointsVisitor f, gpointer udata )
7353 {
7354 visitSelectedControlPoints_CallbackData d;
7355 d.func = f;
7356 d.udata = udata;
7357 d.count = 0;
7358 g_hash_table_foreach( col, FE_visitSelectedControlPoints, &d );
7359 }
7360
7361 void visitAllControlPoints( GHashTable *col, visitSelectedControlPointsVisitor f, gpointer udata )
7362 {
7363 visitSelectedControlPoints_CallbackData d;
7364 d.func = f;
7365 d.udata = udata;
7366 d.count = 0;
7367 g_hash_table_foreach( col, FE_visitAllControlPoints, &d );
7368 }
7369 static void visitAdjacentToSelectedControlPoints( GHashTable *col, visitSelectedControlPointsVisitor f, gpointer udata )
7370 {
7371 visitSelectedControlPoints_CallbackData d;
7372 d.func = f;
7373 d.udata = udata;
7374 d.count = 0;
7375 g_hash_table_foreach( col, FE_visitAdjacentToSelectedControlPoints, &d );
7376 }
7377
7378 void CVFindAndVisitSelectedControlPoints( CharView *cv, bool preserveState,
7379 visitSelectedControlPointsVisitor f, void* udata )
7380 {
7381 // TRACE("CVFindAndVisitSelectedControlPoints(top) cv->p.sp:%p\n", cv->p.sp );
7382 GHashTable* col = getSelectedControlPoints( cv, &cv->p );
7383 if(!col)
7384 return;
7385
7386 if( g_hash_table_size( col ) )
7387 {
7388 if( preserveState )
7389 CVPreserveState(&cv->b);
7390 visitSelectedControlPoints( col, f, udata );
7391 }
7392 g_hash_table_destroy(col);
7393 }
7394
7395 void CVVisitAllControlPoints( CharView *cv, bool preserveState,
7396 visitSelectedControlPointsVisitor f, void* udata )
7397 {
7398 TRACE("CVVisitAllControlPoints(top) cv->p.spl:%p cv->p.sp:%p\n", cv->p.spl, cv->p.sp );
7399 if( !cv->p.spl || !cv->p.sp )
7400 return;
7401
7402 GHashTable* col = getAllControlPoints( cv, &cv->p );
7403 if( g_hash_table_size( col ) )
7404 {
7405 if( preserveState )
7406 CVPreserveState(&cv->b);
7407 visitAllControlPoints( col, f, udata );
7408 }
7409 g_hash_table_destroy(col);
7410 }
7411
7412 void CVVisitAdjacentToSelectedControlPoints( CharView *cv, bool preserveState,
7413 visitSelectedControlPointsVisitor f, void* udata )
7414 {
7415 // TRACE("CVVisitAdjacentToSelectedControlPoints(top) cv->p.sp:%p\n", cv->p.sp );
7416 if( !cv->p.spl || !cv->p.sp )
7417 return;
7418
7419 GHashTable* col = getAllControlPoints( cv, &cv->p );
7420 if( !col )
7421 return;
7422
7423 if( g_hash_table_size( col ) )
7424 {
7425 if( preserveState )
7426 CVPreserveState(&cv->b);
7427 visitAdjacentToSelectedControlPoints( col, f, udata );
7428 }
7429 g_hash_table_destroy(col);
7430 }
7431
7432
7433
7434 void CVChar(CharView *cv, GEvent *event ) {
7435 extern float arrowAmount, arrowAccelFactor;
7436 extern int navigation_mask;
7437
7438 if( !cv_auto_goto )
7439 {
7440 if( event->u.chr.keysym == GK_Control_L
7441 || event->u.chr.keysym == GK_Control_R )
7442 {
7443 HaveModifiers = 1;
7444 }
7445 bool isImmediateKeyTogglePreview = isImmediateKey( cv->gw, "TogglePreview", event ) != NULL;
7446
7447 if( !HaveModifiers && isImmediateKeyTogglePreview ) {
7448 PressingTilde = 1;
7449 CVPreviewModeSet( cv->gw, true );
7450 return;
7451 }
7452 }
7453
7454 /* TRACE("GK_Control_L:%d\n", ( event->u.chr.keysym == GK_Control_L )); */
7455 /* TRACE("GK_Meta_L:%d\n", ( event->u.chr.keysym == GK_Meta_L )); */
7456
7457 int oldactiveModifierControl = cv->activeModifierControl;
7458 int oldactiveModifierAlt = cv->activeModifierAlt;
7459 cv->activeModifierControl |= ( event->u.chr.keysym == GK_Control_L || event->u.chr.keysym == GK_Control_R
7460 || event->u.chr.keysym == GK_Meta_L || event->u.chr.keysym == GK_Meta_R );
7461 cv->activeModifierAlt |= ( event->u.chr.keysym == GK_Alt_L || event->u.chr.keysym == GK_Alt_R
7462 || event->u.chr.keysym == GK_Mode_switch );
7463
7464 if( oldactiveModifierControl != cv->activeModifierControl
7465 || oldactiveModifierAlt != cv->activeModifierAlt )
7466 {
7467 CVInfoDraw(cv,cv->gw);
7468 }
7469
7470
7471 #if _ModKeysAutoRepeat
7472 /* Under cygwin these keys auto repeat, they don't under normal X */
7473 if ( cv->autorpt!=NULL ) {
7474 GDrawCancelTimer(cv->autorpt); cv->autorpt = NULL;
7475 if ( cv->keysym == event->u.chr.keysym ) /* It's an autorepeat, ignore it */
7476 return;
7477 CVToolsSetCursor(cv,cv->oldstate,NULL);
7478 }
7479 #endif
7480
7481 #if MyMemory
7482 if ( event->u.chr.keysym == GK_F2 ) {
7483 fprintf( stderr, "Malloc debug on\n" );
7484 __malloc_debug(5);
7485 } else if ( event->u.chr.keysym == GK_F3 ) {
7486 fprintf( stderr, "Malloc debug off\n" );
7487 __malloc_debug(0);
7488 }
7489 #endif
7490
7491 if ( !HaveModifiers && event->u.chr.keysym==' ' && cv->spacebar_hold==0 ) {
7492 cv->p.x = event->u.mouse.x;
7493 cv->p.y = event->u.mouse.y;
7494 update_spacebar_hand_tool(cv);
7495 }
7496
7497 CVPaletteActivate(cv);
7498 CVToolsSetCursor(cv,TrueCharState(event),NULL);
7499
7500
7501 /* The window check is to prevent infinite loops since DVChar can */
7502 /* call CVChar too */
7503 if ( cv->dv!=NULL && (event->w==cv->gw || event->w==cv->v) && DVChar(cv->dv,event))
7504 {
7505 /* All Done */;
7506 }
7507 else if ( event->u.chr.keysym=='s' &&
7508 (event->u.chr.state&ksm_control) &&
7509 (event->u.chr.state&ksm_meta) )
7510 MenuSaveAll(NULL,NULL,NULL);
7511 else if ( event->u.chr.keysym=='q' &&
7512 (event->u.chr.state&ksm_control) &&
7513 (event->u.chr.state&ksm_meta) )
7514 MenuExit(NULL,NULL,NULL);
7515 else if ( event->u.chr.keysym == GK_Shift_L || event->u.chr.keysym == GK_Shift_R ||
7516 event->u.chr.keysym == GK_Alt_L || event->u.chr.keysym == GK_Alt_R ||
7517 event->u.chr.keysym == GK_Meta_L || event->u.chr.keysym == GK_Meta_R ) {
7518 CVFakeMove(cv, event);
7519 } else if (( event->u.chr.keysym == GK_Tab || event->u.chr.keysym == GK_BackTab) &&
7520 (event->u.chr.state&ksm_control) && cv->showtabs && cv->former_cnt>1 ) {
7521 GGadgetDispatchEvent(cv->tabs,event);
7522 } else if ( (event->u.chr.state&ksm_meta) &&
7523 !(event->u.chr.state&(ksm_control|ksm_shift)) &&
7524 event->u.chr.chars[0]!='\0' ) {
7525 CVPaletteMnemonicCheck(event);
7526 } else if ( !(event->u.chr.state&(ksm_control|ksm_meta)) &&
7527 event->u.chr.keysym == GK_BackSpace ) {
7528 /* Menu does delete */
7529 CVClear(cv->gw,NULL,NULL);
7530 } else if ( event->u.chr.keysym == GK_Help ) {
7531 MenuHelp(NULL,NULL,NULL); /* Menu does F1 */
7532 } else if ( event->u.chr.keysym=='<' && (event->u.chr.state&ksm_control) ) {
7533 /* European keyboards do not need shift to get < */
7534 CVDoFindInFontView(cv);
7535 } else if ( (event->u.chr.keysym=='[' || event->u.chr.keysym==']') &&
7536 (event->u.chr.state&ksm_control) ) {
7537 /* European keyboards need a funky modifier to get [] */
7538 _CVMenuChangeChar(cv,event->u.chr.keysym=='[' ? CV_MID_Prev : CV_MID_Next );
7539 } else if ( (event->u.chr.keysym=='{' || event->u.chr.keysym=='}') &&
7540 (event->u.chr.state&ksm_control) ) {
7541 /* European keyboards need a funky modifier to get {} */
7542 _CVMenuChangeChar(cv,event->u.chr.keysym=='{' ? CV_MID_PrevDef : CV_MID_NextDef );
7543 } else if ( event->u.chr.keysym=='\\' && (event->u.chr.state&ksm_control) ) {
7544 /* European keyboards need a funky modifier to get \ */
7545 CVDoTransform(cv,cvt_none);
7546 } else if ( (event->u.chr.keysym=='F' || event->u.chr.keysym=='B') &&
7547 !(event->u.chr.state&(ksm_control|ksm_meta)) ) {
7548 CVLSelectLayer(cv, event->u.chr.keysym=='F' ? 1 : 0);
7549 } else if ( (event->u.chr.state&ksm_control) && (event->u.chr.keysym=='-' || event->u.chr.keysym==0xffad/*XK_KP_Subtract*/) ){
7550 _CVMenuScale(cv, CV_MID_ZoomOut);
7551 } else if ( (event->u.chr.state&ksm_control) && (event->u.chr.keysym=='=' || event->u.chr.keysym==0xffab/*XK_KP_Add*/) ){
7552 _CVMenuScale(cv, CV_MID_ZoomIn);
7553 }
7554 else if ( event->u.chr.keysym == GK_Left ||
7555 event->u.chr.keysym == GK_Up ||
7556 event->u.chr.keysym == GK_Right ||
7557 event->u.chr.keysym == GK_Down ||
7558 event->u.chr.keysym == GK_KP_Left ||
7559 event->u.chr.keysym == GK_KP_Up ||
7560 event->u.chr.keysym == GK_KP_Right ||
7561 event->u.chr.keysym == GK_KP_Down )
7562 {
7563 TRACE("key left/right/up/down...\n");
7564
7565 GGadget *active = GWindowGetFocusGadgetOfWindow(cv->gw);
7566 if( active == cv->charselector )
7567 {
7568 if ( event->u.chr.keysym == GK_Left ||event->u.chr.keysym == GK_Right )
7569 {
7570 TRACE("left/right on the charselector!\n");
7571 }
7572 int dir = ( event->u.chr.keysym == GK_Up || event->u.chr.keysym==GK_KP_Up ) ? -1 : 1;
7573 Wordlist_MoveByOffset( cv->charselector, &cv->charselectoridx, dir );
7574
7575 return;
7576 }
7577
7578
7579 real dx=0, dy=0; int anya;
7580 switch ( event->u.chr.keysym ) {
7581 case GK_Left: case GK_KP_Left:
7582 dx = -1;
7583 break;
7584 case GK_Right: case GK_KP_Right:
7585 dx = 1;
7586 break;
7587 case GK_Up: case GK_KP_Up:
7588 dy = 1;
7589 break;
7590 case GK_Down: case GK_KP_Down:
7591 dy = -1;
7592 break;
7593 }
7594 if ( event->u.chr.state & (ksm_control|ksm_capslock) ) {
7595 struct sbevent sb;
7596 sb.type = dy>0 || dx<0 ? et_sb_halfup : et_sb_halfdown;
7597 if ( dx==0 )
7598 CVVScroll(cv,&sb);
7599 else
7600 CVHScroll(cv,&sb);
7601 }
7602 else
7603 {
7604 // TRACE("cvchar( moving points? ) shift:%d\n", ( event->u.chr.state & (ksm_shift) ));
7605 FE_adjustBCPByDeltaData d;
7606 memset( &d, 0, sizeof(FE_adjustBCPByDeltaData));
7607 visitSelectedControlPointsVisitor func = FE_adjustBCPByDelta;
7608 if ( event->u.chr.state & ksm_meta )
7609 {
7610 // move the bcp 1 unit in the direction it already has
7611 func = FE_adjustBCPByDeltaWhilePreservingBCPAngle;
7612 // allow that func to work it's magic on any gradient
7613 d.keyboarddx = 1;
7614 }
7615 /* if ( event->u.chr.state & (ksm_shift) ) */
7616 /* dx -= dy*tan((cv->b.sc->parent->italicangle)*(FF_PI/180) ); */
7617 if ( event->u.chr.state & (ksm_shift) )
7618 {
7619 dx *= arrowAccelFactor; dy *= arrowAccelFactor;
7620 }
7621
7622 if (( cv->p.sp!=NULL || cv->lastselpt!=NULL ) &&
7623 (cv->p.nextcp || cv->p.prevcp) )
7624 {
7625 // This code moves 1 or more BCP
7626
7627 SplinePoint *old = cv->p.sp;
7628 d.cv = cv;
7629 d.dx = dx * arrowAmount;
7630 d.dy = dy * arrowAmount;
7631 CVFindAndVisitSelectedControlPoints( cv, true,
7632 func, &d );
7633 cv->p.sp = old;
7634 SCUpdateAll(cv->b.sc);
7635
7636 }
7637 else if ( CVAnySel(cv,NULL,NULL,NULL,&anya) || cv->widthsel || cv->vwidthsel )
7638 {
7639 CVPreserveState(&cv->b);
7640 CVMoveSelection(cv,dx*arrowAmount,dy*arrowAmount, event->u.chr.state);
7641 if ( cv->widthsel )
7642 SCSynchronizeWidth(cv->b.sc,cv->b.sc->width,cv->b.sc->width-dx,NULL);
7643 _CV_CharChangedUpdate(cv,2);
7644 CVInfoDraw(cv,cv->gw);
7645 }
7646 CVGridHandlePossibleFitChar( cv );
7647 }
7648 } else if ( event->u.chr.keysym == GK_Page_Up ||
7649 event->u.chr.keysym == GK_KP_Page_Up ||
7650 event->u.chr.keysym == GK_Prior ||
7651 event->u.chr.keysym == GK_Page_Down ||
7652 event->u.chr.keysym == GK_KP_Page_Down ||
7653 event->u.chr.keysym == GK_Next ) {
7654 /* Um... how do we scroll horizontally??? */
7655 struct sbevent sb;
7656 sb.type = et_sb_uppage;
7657 if ( event->u.chr.keysym == GK_Page_Down ||
7658 event->u.chr.keysym == GK_KP_Page_Down ||
7659 event->u.chr.keysym == GK_Next )
7660 sb.type = et_sb_downpage;
7661 CVVScroll(cv,&sb);
7662 } else if ( event->u.chr.keysym == GK_Home ) {
7663 CVFit(cv);
7664 } else if ( event->u.chr.keysym==' ' && cv->spacebar_hold ){
7665 } else if ( (event->u.chr.state&((GMenuMask()|navigation_mask)&~(ksm_shift|ksm_capslock)))==navigation_mask &&
7666 event->type == et_char &&
7667 event->u.chr.keysym!=0 &&
7668 (event->u.chr.keysym<GK_Special /*|| event->u.chr.keysym>=0x10000*/)) {
7669 SplineFont *sf = cv->b.sc->parent;
7670 int i;
7671 EncMap *map = cv->b.fv->map;
7672 extern int cv_auto_goto;
7673 if ( cv_auto_goto ) {
7674 i = SFFindSlot(sf,map,event->u.chr.keysym,NULL);
7675 if ( i!=-1 )
7676 CVChangeChar(cv,i);
7677 }
7678 }
7679 }
7680
7681 void CVShowPoint(CharView *cv, BasePoint *me) {
7682 CharViewTab* tab = CVGetActiveTab(cv);
7683 int x, y;
7684 int fudge = 30;
7685
7686 if ( cv->width<60 )
7687 fudge = cv->width/3;
7688 if ( cv->height<60 && fudge>cv->height/3 )
7689 fudge = cv->height/3;
7690
7691 /* Make sure the point is visible and has some context around it */
7692 x = tab->xoff + rint(me->x*tab->scale);
7693 y = -tab->yoff + cv->height - rint(me->y*tab->scale);
7694 if ( x<fudge || y<fudge || x>cv->width-fudge || y>cv->height-fudge )
7695 CVMagnify(cv,me->x,me->y,0,0);
7696 }
7697
7698 static void CVSelectContours(CharView *cv) {
7699 SplineSet *spl;
7700 SplinePoint *sp;
7701 int sel;
7702 int i;
7703
7704 for ( spl=cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl=spl->next ) {
7705 sel = false;
7706 if ( cv->b.sc->inspiro && hasspiro()) {
7707 for ( i=0; i<spl->spiro_cnt-1; ++i ) {
7708 if ( SPIRO_SELECTED(&spl->spiros[i]) ) {
7709 sel = true;
7710 break;
7711 }
7712 }
7713 if ( sel ) {
7714 for ( i=0; i<spl->spiro_cnt-1; ++i )
7715 SPIRO_SELECT(&spl->spiros[i]);
7716 }
7717 } else {
7718 for ( sp=spl->first ; ; ) {
7719 if ( sp->selected ) {
7720 sel = true;
7721 break;
7722 }
7723 if ( sp->next==NULL )
7724 break;
7725 sp = sp->next->to;
7726 if ( sp==spl->first )
7727 break;
7728 }
7729 if ( sel ) {
7730 for ( sp=spl->first ; ; ) {
7731 sp->selected = true;
7732 if ( sp->next==NULL )
7733 break;
7734 sp = sp->next->to;
7735 if ( sp==spl->first )
7736 break;
7737 }
7738 }
7739 }
7740 }
7741 SCUpdateAll(cv->b.sc);
7742 }
7743
7744 static void CVMenuSelectContours(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
7745 CharView *cv = (CharView *) GDrawGetUserData(gw);
7746 CVSelectContours(cv);
7747 }
7748
7749 static void CVMenuSelectPointAt(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
7750 CharView *cv = (CharView *) GDrawGetUserData(gw);
7751 CVSelectPointAt(cv);
7752 }
7753
7754 static void CVNextPrevSpiroPt(CharView *cv, struct gmenuitem *mi) {
7755 CharViewTab* tab = CVGetActiveTab(cv);
7756 RefChar *r; ImageList *il;
7757 SplineSet *spl, *ss;
7758 SplinePoint *junk;
7759 int x, y;
7760 spiro_cp *selcp = NULL, *other;
7761 int index;
7762
7763 if ( mi->mid == CV_MID_FirstPt ) {
7764 if ( cv->b.layerheads[cv->b.drawmode]->splines==NULL )
7765 return;
7766 CVClearSel(cv);
7767 other = &cv->b.layerheads[cv->b.drawmode]->splines->spiros[0];
7768 } else {
7769 if ( !CVOneThingSel(cv,&junk,&spl,&r,&il,NULL,&selcp) || spl==NULL )
7770 return;
7771 other = selcp;
7772 if ( spl==NULL )
7773 return;
7774 index = selcp - spl->spiros;
7775 if ( mi->mid == CV_MID_NextPt ) {
7776 if ( index!=spl->spiro_cnt-2 )
7777 other = &spl->spiros[index+1];
7778 else {
7779 if ( spl->next == NULL )
7780 spl = cv->b.layerheads[cv->b.drawmode]->splines;
7781 else
7782 spl = spl->next;
7783 other = &spl->spiros[0];
7784 }
7785 } else if ( mi->mid == CV_MID_PrevPt ) {
7786 if ( index!=0 ) {
7787 other = &spl->spiros[index-1];
7788 } else {
7789 if ( spl==cv->b.layerheads[cv->b.drawmode]->splines ) {
7790 for ( ss = cv->b.layerheads[cv->b.drawmode]->splines; ss->next!=NULL; ss=ss->next );
7791 } else {
7792 for ( ss = cv->b.layerheads[cv->b.drawmode]->splines; ss->next!=spl; ss=ss->next );
7793 }
7794 spl = ss;
7795 other = &ss->spiros[ss->spiro_cnt-2];
7796 }
7797 } else if ( mi->mid == CV_MID_FirstPtNextCont ) {
7798 if ( spl->next!=NULL )
7799 other = &spl->next->spiros[0];
7800 else
7801 other = NULL;
7802 }
7803 }
7804 if ( selcp!=NULL )
7805 SPIRO_DESELECT(selcp);
7806 if ( other!=NULL )
7807 SPIRO_SELECT(other);
7808 cv->p.sp = NULL;
7809 cv->lastselpt = NULL;
7810 cv->lastselcp = other;
7811
7812 /* Make sure the point is visible and has some context around it */
7813 if ( other!=NULL ) {
7814 x = tab->xoff + rint(other->x*tab->scale);
7815 y = -tab->yoff + cv->height - rint(other->y*tab->scale);
7816 if ( x<40 || y<40 || x>cv->width-40 || y>cv->height-40 )
7817 CVMagnify(cv,other->x,other->y,0,0);
7818 }
7819
7820 CVInfoDraw(cv,cv->gw);
7821 SCUpdateAll(cv->b.sc);
7822 }
7823
7824 static void CVNextPrevPt(CharView *cv, struct gmenuitem *mi) {
7825 CharViewTab* tab = CVGetActiveTab(cv);
7826 SplinePoint *selpt=NULL, *other;
7827 RefChar *r; ImageList *il;
7828 SplineSet *spl, *ss;
7829 int x, y;
7830 spiro_cp *junk;
7831
7832 if ( cv->b.sc->inspiro && hasspiro()) {
7833 CVNextPrevSpiroPt(cv,mi);
7834 return;
7835 }
7836
7837 if ( mi->mid == CV_MID_FirstPt ) {
7838 if ( cv->b.layerheads[cv->b.drawmode]->splines==NULL )
7839 return;
7840 other = (cv->b.layerheads[cv->b.drawmode]->splines)->first;
7841 CVClearSel(cv);
7842 } else {
7843 if ( !CVOneThingSel(cv,&selpt,&spl,&r,&il,NULL,&junk) || spl==NULL )
7844 return;
7845 other = selpt;
7846 if ( spl==NULL )
7847 return;
7848 else if ( mi->mid == CV_MID_NextPt ) {
7849 if ( other->next!=NULL && other->next->to!=spl->first )
7850 other = other->next->to;
7851 else {
7852 if ( spl->next == NULL )
7853 spl = cv->b.layerheads[cv->b.drawmode]->splines;
7854 else
7855 spl = spl->next;
7856 other = spl->first;
7857 }
7858 } else if ( mi->mid == CV_MID_PrevPt ) {
7859 if ( other!=spl->first ) {
7860 other = other->prev->from;
7861 } else {
7862 if ( spl==cv->b.layerheads[cv->b.drawmode]->splines ) {
7863 for ( ss = cv->b.layerheads[cv->b.drawmode]->splines; ss->next!=NULL; ss=ss->next );
7864 } else {
7865 for ( ss = cv->b.layerheads[cv->b.drawmode]->splines; ss->next!=spl; ss=ss->next );
7866 }
7867 spl = ss;
7868 other = ss->last;
7869 if ( spl->last==spl->first && spl->last->prev!=NULL )
7870 other = other->prev->from;
7871 }
7872 } else if ( mi->mid == CV_MID_FirstPtNextCont ) {
7873 if ( spl->next!=NULL )
7874 other = spl->next->first;
7875 else
7876 other = NULL;
7877 }
7878 }
7879 if ( selpt!=NULL )
7880 selpt->selected = false;
7881 if ( other!=NULL )
7882 other->selected = true;
7883 cv->p.sp = NULL;
7884 cv->lastselpt = other;
7885 cv->p.spiro = cv->lastselcp = NULL;
7886
7887 /* Make sure the point is visible and has some context around it */
7888 if ( other!=NULL ) {
7889 x = tab->xoff + rint(other->me.x*tab->scale);
7890 y = -tab->yoff + cv->height - rint(other->me.y*tab->scale);
7891 if ( x<40 || y<40 || x>cv->width-40 || y>cv->height-40 )
7892 CVMagnify(cv,other->me.x,other->me.y,0,0);
7893 }
7894
7895 CVInfoDraw(cv,cv->gw);
7896 SCUpdateAll(cv->b.sc);
7897 }
7898
7899 static void CVMenuNextPrevPt(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
7900 CharView *cv = (CharView *) GDrawGetUserData(gw);
7901 CVNextPrevPt(cv, mi);
7902 }
7903
7904 static void CVNextPrevCPt(CharView *cv, struct gmenuitem *mi) {
7905 SplinePoint *selpt=NULL;
7906 RefChar *r; ImageList *il;
7907 SplineSet *spl;
7908 spiro_cp *junk;
7909
7910 if ( !CVOneThingSel(cv,&selpt,&spl,&r,&il,NULL,&junk))
7911 return;
7912 if ( selpt==NULL )
7913 return;
7914 cv->p.nextcp = mi->mid==CV_MID_NextCP;
7915 cv->p.prevcp = mi->mid==CV_MID_PrevCP;
7916 SCUpdateAll(cv->b.sc);
7917 }
7918
7919 static void CVMenuNextPrevCPt(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
7920 CharView *cv = (CharView *) GDrawGetUserData(gw);
7921 CVNextPrevCPt(cv, mi);
7922 }
7923
7924 static void CVMenuGotoChar(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
7925 CharView *cv = (CharView *) GDrawGetUserData(gw);
7926 int pos;
7927
7928 if ( cv->b.container ) {
7929 (cv->b.container->funcs->doNavigate)(cv->b.container,nt_goto);
7930 return;
7931 }
7932
7933 pos = GotoChar(cv->b.fv->sf,cv->b.fv->map,NULL);
7934 if ( pos!=-1 )
7935 CVChangeChar(cv,pos);
7936 }
7937
7938 static void CVMenuFindInFontView(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
7939 CharView *cv = (CharView *) GDrawGetUserData(gw);
7940 CVDoFindInFontView(cv);
7941 }
7942
7943 static void CVMenuPalettesDock(GWindow UNUSED(gw), struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
7944 PalettesChangeDocking();
7945 }
7946
7947 static void CVMenuPaletteShow(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
7948 CharView *cv = (CharView *) GDrawGetUserData(gw);
7949 CVPaletteSetVisible(cv, mi->mid==CV_MID_Tools, !CVPaletteIsVisible(cv, mi->mid==CV_MID_Tools));
7950 }
7951
7952 static void cv_pllistcheck(CharView *cv, struct gmenuitem *mi) {
7953 extern int palettes_docked;
7954
7955 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
7956 switch ( mi->mid ) {
7957 case CV_MID_Tools:
7958 mi->ti.checked = CVPaletteIsVisible(cv,1);
7959 break;
7960 case CV_MID_Layers:
7961 mi->ti.checked = CVPaletteIsVisible(cv,0);
7962 break;
7963 case CV_MID_DockPalettes:
7964 mi->ti.checked = palettes_docked;
7965 break;
7966 }
7967 }
7968 }
7969
7970 static void pllistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
7971 CharView *cv = (CharView *) GDrawGetUserData(gw);
7972 cv_pllistcheck(cv, mi);
7973 }
7974
7975 /*
7976 * Unused
7977 static void tablistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
7978 GDrawGetUserData(gw);
7979 }
7980 */
7981
7982 static void CVUndo(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
7983 CharView *cv = (CharView *) GDrawGetUserData(gw);
7984
7985 CVDoUndo(&cv->b);
7986 cv->lastselpt = NULL;
7987 }
7988
7989 static void CVRedo(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
7990 CharView *cv = (CharView *) GDrawGetUserData(gw);
7991
7992 CVDoRedo(&cv->b);
7993 cv->lastselpt = NULL;
7994 }
7995
7996 static void _CVCopy(CharView *cv) {
7997 int desel = false, anya;
7998
7999 /* If nothing is selected, copy everything. Do that by temporarily selecting everything */
8000 if ( !CVAnySel(cv,NULL,NULL,NULL,&anya))
8001 if ( !(desel = CVSetSel(cv,-1)))
8002 return;
8003 CopySelected(&cv->b,cv->showanchor);
8004 if ( desel )
8005 CVClearSel(cv);
8006 }
8007
8008 static void CVCopy(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8009 CharView *cv = (CharView *) GDrawGetUserData(gw);
8010 _CVCopy(cv);
8011 }
8012
8013 static void CVCopyLookupData(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8014 CharView *cv = (CharView *) GDrawGetUserData(gw);
8015 SCCopyLookupData(cv->b.sc);
8016 }
8017
8018 static void CVCopyRef(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8019 CharView *cv = (CharView *) GDrawGetUserData(gw);
8020 CopyReference(cv->b.sc);
8021 }
8022
8023 static void CVMenuCopyGridFit(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8024 CharView *cv = (CharView *) GDrawGetUserData(gw);
8025 CVCopyGridFit(&cv->b);
8026 }
8027
8028 static void CVCopyWidth(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
8029 CharView *cv = (CharView *) GDrawGetUserData(gw);
8030 if ( mi->mid==CV_MID_CopyVWidth && !cv->b.sc->parent->hasvmetrics )
8031 return;
8032 CopyWidth(&cv->b,mi->mid==CV_MID_CopyWidth?ut_width:
8033 mi->mid==CV_MID_CopyVWidth?ut_vwidth:
8034 mi->mid==CV_MID_CopyLBearing?ut_lbearing:
8035 ut_rbearing);
8036 }
8037
8038 static void CVDoClear(CharView *cv) {
8039 ImageList *prev, *imgs, *next;
8040 RefChar *refs, *rnext;
8041 int layer = CVLayer((CharViewBase *) cv);
8042 int anyimages;
8043
8044 CVPreserveState(&cv->b);
8045 if ( cv->b.drawmode==dm_fore )
8046 SCRemoveSelectedMinimumDistances(cv->b.sc,2);
8047 cv->b.layerheads[cv->b.drawmode]->splines = SplinePointListRemoveSelected(cv->b.sc,
8048 cv->b.layerheads[cv->b.drawmode]->splines);
8049 for ( refs=cv->b.layerheads[cv->b.drawmode]->refs; refs!=NULL; refs = rnext ) {
8050 rnext = refs->next;
8051 if ( refs->selected )
8052 SCRemoveDependent(cv->b.sc,refs,layer);
8053 }
8054 if ( cv->b.drawmode==dm_fore ) {
8055 AnchorPoint *ap, *aprev=NULL, *anext;
8056 if ( cv->showanchor ) for ( ap=cv->b.sc->anchor; ap!=NULL; ap=anext ) {
8057 anext = ap->next;
8058 if ( ap->selected ) {
8059 if ( aprev!=NULL )
8060 aprev->next = anext;
8061 else
8062 cv->b.sc->anchor = anext;
8063 ap->next = NULL;
8064 AnchorPointsFree(ap);
8065 } else
8066 aprev = ap;
8067 }
8068 }
8069 anyimages = false;
8070 for ( prev = NULL, imgs=cv->b.layerheads[cv->b.drawmode]->images; imgs!=NULL; imgs = next ) {
8071 next = imgs->next;
8072 if ( !imgs->selected )
8073 prev = imgs;
8074 else {
8075 if ( prev==NULL )
8076 cv->b.layerheads[cv->b.drawmode]->images = next;
8077 else
8078 prev->next = next;
8079 chunkfree(imgs,sizeof(ImageList));
8080 /* garbage collection of images????!!!! */
8081 anyimages = true;
8082 }
8083 }
8084 if ( anyimages )
8085 if ( cv->lastselpt!=NULL || cv->p.sp!=NULL || cv->p.spiro!=NULL || cv->lastselcp!=NULL ) {
8086 cv->lastselpt = NULL; cv->p.sp = NULL;
8087 cv->p.spiro = cv->lastselcp = NULL;
8088 CVInfoDraw(cv,cv->gw);
8089 }
8090 }
8091
8092 static void CVClear(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8093 CharView *cv = (CharView *) GDrawGetUserData(gw);
8094 int anyanchor;
8095
8096 if ( !CVAnySel(cv,NULL,NULL,NULL,&anyanchor))
8097 return;
8098 CVDoClear(cv);
8099 CVGridHandlePossibleFitChar( cv );
8100 CVCharChangedUpdate(&cv->b);
8101 }
8102
8103 static void CVClearBackground(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8104 CharView *cv = (CharView *) GDrawGetUserData(gw);
8105 SCClearBackground(cv->b.sc);
8106 }
8107
8108 static void _CVPaste(CharView *cv) {
8109 enum undotype ut = CopyUndoType();
8110 int was_empty = cv->b.drawmode==dm_fore && cv->b.sc->hstem==NULL && cv->b.sc->vstem==NULL && cv->b.layerheads[cv->b.drawmode]->splines==NULL && cv->b.layerheads[cv->b.drawmode]->refs==NULL;
8111 if ( ut!=ut_lbearing ) /* The lbearing code does this itself */
8112 CVPreserveStateHints(&cv->b);
8113 if ( ut!=ut_width && ut!=ut_vwidth && ut!=ut_lbearing && ut!=ut_rbearing && ut!=ut_possub )
8114 CVClearSel(cv);
8115 PasteToCV(&cv->b);
8116 cv->lastselpt = NULL;
8117 CVCharChangedUpdate(&cv->b);
8118 if ( was_empty && (cv->b.sc->hstem != NULL || cv->b.sc->vstem!=NULL ))
8119 cv->b.sc->changedsincelasthinted = false;
8120 }
8121
8122 static void CVPaste(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8123 CharView *cv = (CharView *) GDrawGetUserData(gw);
8124 _CVPaste(cv);
8125 // Before July 2019, all pastes would reset the view such that all splines
8126 // were visible. This is wrong in most cases, e.g. tracing many letters
8127 // from one manuscript page, or copying and pasting parts of a glyph.
8128 //
8129 // A more complete fix would be to make it so only selected points were put
8130 // into view, but it was deemed not worth it at the time, and this comment
8131 // was left instead. See Github issue №3783 and PR №3813 for more details.
8132 // CVInkscapeAdjust(cv);
8133 }
8134
8135 static void _CVMerge(CharView *cv, int elide) {
8136 int anyp = 0;
8137
8138 if ( !CVAnySel(cv,&anyp,NULL,NULL,NULL) || !anyp)
8139 return;
8140 CVPreserveState(&cv->b);
8141 SplineCharMerge(cv->b.sc,&cv->b.layerheads[cv->b.drawmode]->splines,!elide);
8142 SCClearSelPt(cv->b.sc);
8143 CVCharChangedUpdate(&cv->b);
8144 }
8145
8146 void CVMerge(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8147 CharView *cv = (CharView *) GDrawGetUserData(gw);
8148 _CVMerge(cv,false);
8149 }
8150
8151 static void _CVMergeToLine(CharView *cv, int elide) {
8152 int anyp = 0;
8153
8154 if ( !CVAnySel(cv,&anyp,NULL,NULL,NULL) || !anyp)
8155 return;
8156 CVPreserveState(&cv->b);
8157 SplineCharMerge(cv->b.sc,&cv->b.layerheads[cv->b.drawmode]->splines,!elide);
8158
8159 // Select the other side of the new curve
8160 if (!CVInSpiro(cv)) {
8161 GList_Glib* gl = CVGetSelectedPoints( cv );
8162 if( g_list_first(gl) )
8163 SPSelectPrevPoint( (SplinePoint*)g_list_first(gl)->data, 1 );
8164 g_list_free( gl );
8165 }
8166
8167 // And make the curve between the two active points a line
8168 _CVMenuMakeLine( (CharViewBase*) cv, 0, 0 );
8169 SCClearSelPt(cv->b.sc);
8170 CVCharChangedUpdate(&cv->b);
8171 }
8172
8173 void CVMergeToLine(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8174 CharView *cv = (CharView *) GDrawGetUserData(gw);
8175 _CVMergeToLine(cv,false);
8176
8177 }
8178
8179 static void _CVJoin(CharView *cv) {
8180 CharViewTab* tab = CVGetActiveTab(cv);
8181 int anyp = 0, changed;
8182 extern float joinsnap;
8183
8184 CVAnySel(cv,&anyp,NULL,NULL,NULL);
8185 CVPreserveState(&cv->b);
8186 cv->b.layerheads[cv->b.drawmode]->splines = SplineSetJoin(cv->b.layerheads[cv->b.drawmode]->splines,!anyp,joinsnap/tab->scale,&changed,true);
8187 if ( changed )
8188 CVCharChangedUpdate(&cv->b);
8189 }
8190
8191 static void CVJoin(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8192 CharView *cv = (CharView *) GDrawGetUserData(gw);
8193 _CVJoin(cv);
8194 }
8195
8196 static void _CVCut(CharView *cv) {
8197 int anya;
8198
8199 if ( !CVAnySel(cv,NULL,NULL,NULL,&anya))
8200 return;
8201 _CVCopy(cv);
8202 CVDoClear(cv);
8203 CVCharChangedUpdate(&cv->b);
8204 }
8205
8206 static void CVCut(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8207 CharView *cv = (CharView *) GDrawGetUserData(gw);
8208 _CVCut(cv);
8209 }
8210
8211 static void CVCopyFgBg(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8212 CharView *cv = (CharView *) GDrawGetUserData(gw);
8213
8214 if ( cv->b.sc->layers[ly_fore].splines==NULL )
8215 return;
8216 SCCopyLayerToLayer(cv->b.sc,ly_fore,ly_back,false);
8217 }
8218
8219 static void CVMenuCopyL2L(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8220 CharView *cv = (CharView *) GDrawGetUserData(gw);
8221 CVCopyLayerToLayer(cv);
8222 }
8223
8224 static void CVMenuCompareL2L(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8225 CharView *cv = (CharView *) GDrawGetUserData(gw);
8226 CVCompareLayerToLayer(cv);
8227 }
8228
8229 static void CVSelectAll(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
8230 CharView *cv = (CharView *) GDrawGetUserData(gw);
8231 int mask = -1;
8232
8233 if ( mi->mid==CV_MID_SelectAllPoints )
8234 mask = 1;
8235 else if ( mi->mid==CV_MID_SelectAnchors )
8236 mask = 2;
8237 else if ( mi->mid==CV_MID_SelAll ) {
8238 mask = 1;
8239 if (cv->b.drawmode==dm_fore) mask+=2;
8240 /* TODO! Should we also check if this is the right foreground layer? */
8241 }
8242
8243 if ( CVSetSel(cv,mask))
8244 SCUpdateAll(cv->b.sc);
8245 }
8246
8247 static void CVSelectOpenContours(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8248 CharView *cv = (CharView *) GDrawGetUserData(gw);
8249 SplineSet *ss;
8250 int i;
8251 SplinePoint *sp;
8252 int changed = CVClearSel(cv);
8253
8254 for ( ss=cv->b.layerheads[cv->b.drawmode]->splines; ss!=NULL; ss=ss->next ) {
8255 if ( ss->first->prev==NULL ) {
8256 changed = true;
8257 if ( cv->b.sc->inspiro && hasspiro()) {
8258 for ( i=0; i<ss->spiro_cnt; ++i )
8259 SPIRO_SELECT(&ss->spiros[i]);
8260 } else {
8261 for ( sp=ss->first ;; ) {
8262 sp->selected = true;
8263 if ( sp->next==NULL )
8264 break;
8265 sp = sp->next->to;
8266 }
8267 }
8268 }
8269 }
8270 if ( changed )
8271 SCUpdateAll(cv->b.sc);
8272 }
8273
8274 static void CVSelectNone(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8275 CharView *cv = (CharView *) GDrawGetUserData(gw);
8276 if ( CVClearSel(cv))
8277 SCUpdateAll(cv->b.sc);
8278 }
8279
8280 static void CVSelectInvert(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8281 CharView *cv = (CharView *) GDrawGetUserData(gw);
8282 CVInvertSel(cv);
8283 SCUpdateAll(cv->b.sc);
8284 }
8285
8286 static void CVSelectWidth(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8287 CharView *cv = (CharView *) GDrawGetUserData(gw);
8288 if ( HasUseMyMetrics(cv->b.sc,CVLayer((CharViewBase *) cv))!=NULL )
8289 return;
8290 cv->widthsel = !cv->widthsel;
8291 cv->oldwidth = cv->b.sc->width;
8292 SCUpdateAll(cv->b.sc);
8293 }
8294
8295 static void CVSelectVWidth(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8296 CharView *cv = (CharView *) GDrawGetUserData(gw);
8297 if ( !cv->showvmetrics || !cv->b.sc->parent->hasvmetrics )
8298 return;
8299 if ( HasUseMyMetrics(cv->b.sc,CVLayer((CharViewBase *) cv))!=NULL )
8300 return;
8301 cv->vwidthsel = !cv->widthsel;
8302 cv->oldvwidth = cv->b.sc->vwidth;
8303 SCUpdateAll(cv->b.sc);
8304 }
8305
8306 static void CVSelectHM(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8307 CharView *cv = (CharView *) GDrawGetUserData(gw);
8308 SplinePoint *sp; SplineSet *spl; RefChar *r; ImageList *im;
8309 spiro_cp *junk;
8310 int exactlyone = CVOneThingSel(cv,&sp,&spl,&r,&im,NULL,&junk);
8311
8312 if ( !exactlyone || sp==NULL || sp->hintmask == NULL || spl==NULL )
8313 return;
8314 while ( sp!=NULL ) {
8315 if ( sp->prev==NULL )
8316 break;
8317 sp = sp->prev->from;
8318 if ( sp == spl->first )
8319 break;
8320 if ( sp->hintmask!=NULL )
8321 goto done;
8322 sp->selected = true;
8323 }
8324 for ( spl = spl->next; spl!=NULL; spl = spl->next ) {
8325 for ( sp=spl->first; sp!=NULL; ) {
8326 if ( sp->hintmask!=NULL )
8327 goto done;
8328 sp->selected = true;
8329 if ( sp->prev==NULL )
8330 break;
8331 sp = sp->prev->from;
8332 if ( sp == spl->first )
8333 break;
8334 }
8335 }
8336 done:
8337 SCUpdateAll(cv->b.sc);
8338 }
8339
8340 static void _CVUnlinkRef(CharView *cv) {
8341 int anyrefs=0;
8342 RefChar *rf, *next;
8343
8344 if ( cv->b.layerheads[cv->b.drawmode]->refs!=NULL ) {
8345 CVPreserveState(&cv->b);
8346 for ( rf=cv->b.layerheads[cv->b.drawmode]->refs; rf!=NULL && !anyrefs; rf=rf->next )
8347 if ( rf->selected ) anyrefs = true;
8348 for ( rf=cv->b.layerheads[cv->b.drawmode]->refs; rf!=NULL ; rf=next ) {
8349 next = rf->next;
8350 if ( rf->selected || !anyrefs) {
8351 SCRefToSplines(cv->b.sc,rf,CVLayer((CharViewBase *) cv));
8352 }
8353 }
8354 CVSetCharChanged(cv,true);
8355 SCUpdateAll(cv->b.sc);
8356 /* Don't need to update dependencies, their splines won't have changed*/
8357 }
8358 }
8359
8360 static void CVUnlinkRef(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8361 CharView *cv = (CharView *) GDrawGetUserData(gw);
8362 _CVUnlinkRef(cv);
8363 }
8364
8365 typedef struct getValueDialogData
8366 {
8367 int done;
8368 int cancelled;
8369 CharView *cv;
8370 GWindow gw;
8371 char* ret;
8372 GTextInfo label;
8373 } GetValueDialogData;
8374
8375 static int getValueDialogData_e_h(GWindow gw, GEvent *event) {
8376 if ( event->type==et_close ) {
8377 GetValueDialogData *hd = GDrawGetUserData(gw);
8378 hd->done = true;
8379 } else if ( event->type == et_char ) {
8380 return( false );
8381 } else if ( event->type == et_map ) {
8382 /* Above palettes */
8383 GDrawRaise(gw);
8384 }
8385 return( true );
8386 }
8387
8388 static int getValueFromUser_OK(GGadget *g, GEvent *e)
8389 {
8390 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
8391 GetValueDialogData *hd = GDrawGetUserData(GGadgetGetWindow(g));
8392 strcpy( hd->ret, u_to_c(hd->label.text));
8393 strcpy( hd->ret, GGadgetGetTitle8(GWidgetGetControl(hd->gw,CID_getValueFromUser)));
8394 hd->done = true;
8395 }
8396 return( true );
8397 }
8398
8399 static int getValueFromUser_Cancel(GGadget *g, GEvent *e) {
8400 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
8401 GetValueDialogData *hd = GDrawGetUserData(GGadgetGetWindow(g));
8402 hd->cancelled = true;
8403 hd->done = true;
8404 }
8405 return( true );
8406 }
8407
8408 static char* getValueFromUser( CharView *cv, const char* windowTitle, const char* msg, const char* defaultValue )
8409 {
8410 const int retsz = 4096;
8411 static char ret[4097];
8412 static GetValueDialogData DATA;
8413 GRect pos;
8414 GWindow gw;
8415 GWindowAttrs wattrs;
8416 GGadgetCreateData gcd[9], *harray1[4], *harray2[9], *barray[7], *varray[5][2], boxes[5];
8417 GTextInfo label[9];
8418
8419 DATA.cancelled = false;
8420 DATA.done = false;
8421 DATA.cv = cv;
8422 DATA.ret = ret;
8423 ret[0] = '\0';
8424
8425 if ( DATA.gw==NULL ) {
8426 memset(&wattrs,0,sizeof(wattrs));
8427 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict;
8428 wattrs.event_masks = ~(1<<et_charup);
8429 wattrs.restrict_input_to_me = 1;
8430 wattrs.undercursor = 1;
8431 wattrs.cursor = ct_pointer;
8432 wattrs.utf8_window_title = windowTitle;
8433 wattrs.is_dlg = true;
8434 pos.x = pos.y = 0;
8435 pos.width = GGadgetScale(GDrawPointsToPixels(NULL,170));
8436 pos.height = GDrawPointsToPixels(NULL,90);
8437 DATA.gw = gw = GDrawCreateTopWindow(NULL,&pos,getValueDialogData_e_h,&DATA,&wattrs);
8438
8439 memset(&label,0,sizeof(label));
8440 memset(&gcd, 0,sizeof(gcd));
8441 memset(&boxes,0,sizeof(boxes));
8442
8443 label[0].text = (unichar_t *) msg;
8444 label[0].text_is_1byte = true;
8445 label[0].text_in_resource = true;
8446 gcd[0].gd.label = &label[0];
8447 gcd[0].gd.pos.x = 5;
8448 gcd[0].gd.pos.y = 5;
8449 gcd[0].gd.flags = gg_enabled|gg_visible;
8450 gcd[0].creator = GLabelCreate;
8451 harray1[0] = GCD_Glue;
8452 harray1[1] = &gcd[0];
8453 harray1[2] = 0;
8454
8455 label[1].text = (unichar_t *) defaultValue;
8456 label[1].text_is_1byte = true;
8457 DATA.label = label[1];
8458 gcd[1].gd.label = &label[1];
8459 gcd[1].gd.pos.x = 5;
8460 gcd[1].gd.pos.y = 17+5;
8461 gcd[1].gd.pos.width = 40;
8462 gcd[1].gd.flags = gg_enabled|gg_visible;
8463 gcd[1].gd.cid = CID_getValueFromUser;
8464 gcd[1].creator = GTextFieldCreate;
8465 harray2[0] = &gcd[1];
8466 harray2[1] = 0;
8467
8468 int idx = 2;
8469 gcd[idx].gd.pos.x = 20-3;
8470 gcd[idx].gd.pos.y = 17+37;
8471 gcd[idx].gd.pos.width = -1;
8472 gcd[idx].gd.pos.height = 0;
8473 gcd[idx].gd.flags = gg_visible | gg_enabled | gg_but_default;
8474 label[idx].text = (unichar_t *) _("_OK");
8475 label[idx].text_is_1byte = true;
8476 label[idx].text_in_resource = true;
8477 gcd[idx].gd.mnemonic = 'O';
8478 gcd[idx].gd.label = &label[idx];
8479 gcd[idx].gd.handle_controlevent = getValueFromUser_OK;
8480 gcd[idx].creator = GButtonCreate;
8481 barray[0] = GCD_Glue;
8482 barray[1] = &gcd[idx];
8483 barray[2] = GCD_Glue;
8484
8485 ++idx;
8486 gcd[idx].gd.pos.x = -20;
8487 gcd[idx].gd.pos.y = 17+37+3;
8488 gcd[idx].gd.pos.width = -1;
8489 gcd[idx].gd.pos.height = 0;
8490 gcd[idx].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
8491 label[idx].text = (unichar_t *) _("_Cancel");
8492 label[idx].text_is_1byte = true;
8493 label[idx].text_in_resource = true;
8494 gcd[idx].gd.label = &label[idx];
8495 gcd[idx].gd.mnemonic = 'C';
8496 gcd[idx].gd.handle_controlevent = getValueFromUser_Cancel;
8497 gcd[idx].creator = GButtonCreate;
8498 barray[3] = GCD_Glue;
8499 barray[4] = &gcd[idx];
8500 barray[5] = GCD_Glue;
8501 barray[6] = NULL;
8502
8503 gcd[7].gd.pos.x = 5;
8504 gcd[7].gd.pos.y = 17+31;
8505 gcd[7].gd.pos.width = 170-10;
8506 gcd[7].gd.flags = gg_enabled|gg_visible;
8507 gcd[7].creator = GLineCreate;
8508
8509 boxes[2].gd.flags = gg_enabled|gg_visible;
8510 boxes[2].gd.u.boxelements = harray1;
8511 boxes[2].creator = GHBoxCreate;
8512
8513 boxes[3].gd.flags = gg_enabled|gg_visible;
8514 boxes[3].gd.u.boxelements = harray2;
8515 boxes[3].creator = GHBoxCreate;
8516
8517 boxes[4].gd.flags = gg_enabled|gg_visible;
8518 boxes[4].gd.u.boxelements = barray;
8519 boxes[4].creator = GHBoxCreate;
8520
8521 varray[0][0] = &boxes[2]; varray[0][1] = NULL;
8522 varray[1][0] = &boxes[3]; varray[1][1] = NULL;
8523 varray[2][0] = &gcd[7]; varray[2][1] = NULL;
8524 varray[3][0] = &boxes[4]; varray[3][1] = NULL;
8525 varray[4][0] = NULL;
8526
8527 boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2;
8528 boxes[0].gd.flags = gg_enabled|gg_visible;
8529 boxes[0].gd.u.boxelements = varray[0];
8530 boxes[0].creator = GHVGroupCreate;
8531
8532 GGadgetsCreate(gw,boxes);
8533 GHVBoxSetExpandableCol(boxes[2].ret,gb_expandglue);
8534 GHVBoxSetExpandableCol(boxes[3].ret,gb_expandglue);
8535 GHVBoxSetExpandableCol(boxes[4].ret,gb_expandgluesame);
8536 GHVBoxFitWindow(boxes[0].ret);
8537 } else {
8538 gw = DATA.gw;
8539 snprintf( ret, retsz, "%s", defaultValue );
8540 GGadgetSetTitle8(GWidgetGetControl(gw,CID_getValueFromUser),ret);
8541 GDrawSetTransientFor(gw,(GWindow) -1);
8542 }
8543
8544 GWidgetIndicateFocusGadget(GWidgetGetControl(gw,CID_getValueFromUser));
8545 GTextFieldSelect(GWidgetGetControl(gw,CID_getValueFromUser),0,-1);
8546
8547 GDrawSetVisible(gw,true);
8548 while ( !DATA.done )
8549 GDrawProcessOneEvent(NULL);
8550 GDrawSetVisible(gw,false);
8551
8552 if( DATA.cancelled )
8553 return 0;
8554 return ret;
8555 }
8556
8557
8558
8559 static void CVRemoveUndoes(GWindow gw,struct gmenuitem *mi,GEvent *e)
8560 {
8561 CharView *cv = (CharView *) GDrawGetUserData(gw);
8562 static int lastValue = 10;
8563 int v = toint(getValueFromUser( cv,
8564 _("Trimming Undo Information"),
8565 _("How many most-recent Undos should be kept?"),
8566 tostr(lastValue)));
8567 lastValue = v;
8568 UndoesFreeButRetainFirstN(&cv->b.layerheads[cv->b.drawmode]->undoes,v);
8569 UndoesFreeButRetainFirstN(&cv->b.layerheads[cv->b.drawmode]->redoes,v);
8570 }
8571
8572
8573 /* We can only paste if there's something in the copy buffer */
8574 /* we can only copy if there's something selected to copy */
8575 /* figure out what things are possible from the edit menu before the user */
8576 /* pulls it down */
8577 static void cv_edlistcheck(CharView *cv, struct gmenuitem *mi) {
8578 int anypoints, anyrefs, anyimages, anyanchor;
8579
8580 CVAnySel(cv,&anypoints,&anyrefs,&anyimages,&anyanchor);
8581
8582 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
8583 switch ( mi->mid ) {
8584 case CV_MID_Join:
8585 mi->ti.disabled = cv->b.layerheads[cv->b.drawmode]->splines==NULL;
8586 break;
8587 case CV_MID_Merge:
8588 mi->ti.disabled = !anypoints;
8589 break;
8590 case CV_MID_MergeToLine:
8591 mi->ti.disabled = !anypoints;
8592 break;
8593 case CV_MID_Clear: case CV_MID_Cut: /*case CV_MID_Copy:*/
8594 /* If nothing is selected, copy copies everything */
8595 /* In spiro mode copy will copy all contours with at least (spiro) one point selected */
8596 mi->ti.disabled = !anypoints && !anyrefs && !anyimages && !anyanchor;
8597 break;
8598 case CV_MID_CopyLBearing: case CV_MID_CopyRBearing:
8599 mi->ti.disabled = cv->b.drawmode!=dm_fore ||
8600 (cv->b.layerheads[cv->b.drawmode]->splines==NULL && cv->b.layerheads[cv->b.drawmode]->refs==NULL);
8601 break;
8602 case CV_MID_CopyFgToBg:
8603 mi->ti.disabled = cv->b.sc->layers[ly_fore].splines==NULL;
8604 break;
8605 case CV_MID_CopyGridFit:
8606 mi->ti.disabled = cv->b.gridfit==NULL;
8607 break;
8608 case CV_MID_Paste:
8609 mi->ti.disabled = !CopyContainsSomething() && !SCClipboardHasPasteableContents();
8610 break;
8611 case CV_MID_Undo:
8612 mi->ti.disabled = cv->b.layerheads[cv->b.drawmode]->undoes==NULL;
8613 break;
8614 case CV_MID_Redo:
8615 mi->ti.disabled = cv->b.layerheads[cv->b.drawmode]->redoes==NULL;
8616 break;
8617 case CV_MID_RemoveUndoes:
8618 mi->ti.disabled = cv->b.layerheads[cv->b.drawmode]->undoes==NULL && cv->b.layerheads[cv->b.drawmode]->redoes==NULL;
8619 break;
8620 case CV_MID_CopyRef:
8621 mi->ti.disabled = cv->b.drawmode!=dm_fore || cv->b.container!=NULL;
8622 break;
8623 case CV_MID_CopyLookupData:
8624 mi->ti.disabled = (cv->b.sc->possub==NULL && cv->b.sc->kerns==NULL && cv->b.sc->vkerns==NULL) ||
8625 cv->b.container!=NULL;
8626 break;
8627 case CV_MID_UnlinkRef:
8628 mi->ti.disabled = cv->b.layerheads[cv->b.drawmode]->refs==NULL;
8629 break;
8630 }
8631 }
8632 }
8633
8634 static void edlistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
8635 CharView *cv = (CharView *) GDrawGetUserData(gw);
8636 cv_edlistcheck(cv, mi);
8637 }
8638
8639 static void CVMenuAcceptableExtrema(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8640 CharView *cv = (CharView *) GDrawGetUserData(gw);
8641 SplineSet *ss;
8642 Spline *s, *first;
8643
8644 for ( ss = cv->b.layerheads[cv->b.drawmode]->splines; ss!=NULL ; ss = ss->next ) {
8645 first = NULL;
8646 for ( s=ss->first->next; s!=NULL && s!=first; s = s->to->next ) {
8647 if ( first == NULL )
8648 first = s;
8649 if ( s->from->selected && s->to->selected )
8650 s->acceptableextrema = !s->acceptableextrema;
8651 }
8652 }
8653 }
8654
8655 static void _CVMenuPointType(CharView *cv, struct gmenuitem *mi) {
8656 int pointtype = mi->mid==CV_MID_Corner?pt_corner:mi->mid==CV_MID_Tangent?pt_tangent:
8657 mi->mid==CV_MID_Curve?pt_curve:pt_hvcurve;
8658 SplinePointList *spl;
8659 Spline *spline, *first;
8660
8661 CVPreserveState(&cv->b); /* We should only get here if there's a selection */
8662 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL ; spl = spl->next ) {
8663 first = NULL;
8664 if ( spl->first->selected ) {
8665 if ( spl->first->pointtype!=pointtype )
8666 SPChangePointType(spl->first,pointtype);
8667 }
8668 for ( spline=spl->first->next; spline!=NULL && spline!=first ; spline = spline->to->next ) {
8669 if ( spline->to->selected ) {
8670 if ( spline->to->pointtype!=pointtype )
8671 SPChangePointType(spline->to,pointtype);
8672 }
8673 if ( first == NULL ) first = spline;
8674 }
8675 }
8676 CVCharChangedUpdate(&cv->b);
8677 }
8678
8679 static void _CVMenuSpiroPointType(CharView *cv, struct gmenuitem *mi) {
8680 int pointtype = mi->mid==CV_MID_SpiroCorner?SPIRO_CORNER:
8681 mi->mid==CV_MID_SpiroG4?SPIRO_G4:
8682 mi->mid==CV_MID_SpiroG2?SPIRO_G2:
8683 mi->mid==CV_MID_SpiroLeft?SPIRO_LEFT:SPIRO_RIGHT;
8684 SplinePointList *spl;
8685 int i, changes;
8686
8687 CVPreserveState(&cv->b); /* We should only get here if there's a selection */
8688 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL ; spl = spl->next ) {
8689 changes = false;
8690 for ( i=0; i<spl->spiro_cnt-1; ++i ) {
8691 if ( SPIRO_SELECTED(&spl->spiros[i]) ) {
8692 if ( (spl->spiros[i].ty&0x7f)!=SPIRO_OPEN_CONTOUR ) {
8693 spl->spiros[i].ty = pointtype|0x80;
8694 changes = true;
8695 }
8696 }
8697 }
8698 if ( changes )
8699 SSRegenerateFromSpiros(spl);
8700 }
8701 CVCharChangedUpdate(&cv->b);
8702 }
8703
8704
8705 void CVMenuPointType(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
8706 CharView *cv = (CharView *) GDrawGetUserData(gw);
8707 if ( cv->b.sc->inspiro && hasspiro())
8708 _CVMenuSpiroPointType(cv, mi);
8709 else
8710 _CVMenuPointType(cv, mi);
8711 }
8712
8713 static void _CVMenuImplicit(CharView *cv, struct gmenuitem *mi) {
8714 SplinePointList *spl;
8715 Spline *spline, *first;
8716 int dontinterpolate = mi->mid==CV_MID_NoImplicitPt;
8717
8718 if ( !cv->b.layerheads[cv->b.drawmode]->order2 )
8719 return;
8720 CVPreserveState(&cv->b); /* We should only get here if there's a selection */
8721 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL ; spl = spl->next ) {
8722 first = NULL;
8723 if ( spl->first->selected ) {
8724 spl->first->dontinterpolate = dontinterpolate;
8725 }
8726 for ( spline=spl->first->next; spline!=NULL && spline!=first ; spline = spline->to->next ) {
8727 if ( spline->to->selected ) {
8728 spline->to->dontinterpolate = dontinterpolate;
8729 }
8730 if ( first == NULL ) first = spline;
8731 }
8732 }
8733 CVCharChangedUpdate(&cv->b);
8734 }
8735
8736 static void CVMenuImplicit(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
8737 CharView *cv = (CharView *) GDrawGetUserData(gw);
8738 _CVMenuImplicit(cv, mi);
8739 }
8740
8741 static GMenuItem2 spiroptlist[], ptlist[];
8742 static void cv_ptlistcheck(CharView *cv, struct gmenuitem *mi) {
8743 int type = -2, cnt=0, ccp_cnt=0, spline_selected=0;
8744 int spirotype = -2, opencnt=0, spirocnt=0;
8745 SplinePointList *spl, *sel=NULL, *onlysel=NULL;
8746 Spline *spline, *first;
8747 SplinePoint *selpt=NULL;
8748 int notimplicit = -1;
8749 int acceptable = -1;
8750 uint16_t junk;
8751 int i;
8752
8753 if ( cv->showing_spiro_pt_menu != (cv->b.sc->inspiro && hasspiro())) {
8754 GMenuItemArrayFree(mi->sub);
8755 mi->sub = GMenuItem2ArrayCopy(cv->b.sc->inspiro && hasspiro()?spiroptlist:ptlist,&junk);
8756 cv->showing_spiro_pt_menu = cv->b.sc->inspiro && hasspiro();
8757 }
8758 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
8759 first = NULL;
8760 if ( spl->first->selected ) {
8761 sel = spl;
8762 if ( onlysel==NULL || onlysel==spl ) onlysel = spl; else onlysel = (SplineSet *) (-1);
8763 selpt = spl->first; ++cnt;
8764 if ( type==-2 ) type = spl->first->pointtype;
8765 else if ( type!=spl->first->pointtype ) type = -1;
8766 if ( !spl->first->nonextcp && !spl->first->noprevcp && spl->first->prev!=NULL )
8767 ++ccp_cnt;
8768 if ( notimplicit==-1 ) notimplicit = spl->first->dontinterpolate;
8769 else if ( notimplicit!=spl->first->dontinterpolate ) notimplicit = -2;
8770 }
8771 for ( spline=spl->first->next; spline!=NULL && spline!=first; spline = spline->to->next ) {
8772 /* On a closed contour the walk returns to spl->first, already handled
8773 in the preamble above, so skip it here. (spline_selected below still
8774 counts the wrap spline.) */
8775 if ( spline->to->selected && spline->to!=spl->first ) {
8776 if ( type==-2 ) type = spline->to->pointtype;
8777 else if ( type!=spline->to->pointtype ) type = -1;
8778 selpt = spline->to;
8779 if ( onlysel==NULL || onlysel==spl ) onlysel = spl; else onlysel = (SplineSet *) (-1);
8780 sel = spl; ++cnt;
8781 if ( !spline->to->nonextcp && !spline->to->noprevcp && spline->to->next!=NULL )
8782 ++ccp_cnt;
8783 if ( notimplicit==-1 ) notimplicit = spline->to->dontinterpolate;
8784 else if ( notimplicit!=spline->to->dontinterpolate ) notimplicit = -2;
8785 }
8786 if ( spline->to->selected && spline->from->selected ) {
8787 ++spline_selected;
8788 if ( acceptable==-1 )
8789 acceptable = spline->acceptableextrema;
8790 else if ( acceptable!=spline->acceptableextrema )
8791 acceptable = -2;
8792 }
8793 if ( first == NULL ) first = spline;
8794 }
8795 for ( i=0; i<spl->spiro_cnt-1; ++i ) {
8796 if ( SPIRO_SELECTED(&spl->spiros[i])) {
8797 int ty = spl->spiros[i].ty&0x7f;
8798 ++spirocnt;
8799 if ( ty==SPIRO_OPEN_CONTOUR )
8800 ++opencnt;
8801 else if ( spirotype==-2 )
8802 spirotype = ty;
8803 else if ( spirotype!=ty )
8804 spirotype = -1;
8805 if ( onlysel==NULL || onlysel==spl ) onlysel = spl; else onlysel = (SplineSet *) (-1);
8806 }
8807 }
8808 }
8809
8810 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
8811 switch ( mi->mid ) {
8812 case CV_MID_Corner:
8813 mi->ti.disabled = type==-2;
8814 mi->ti.checked = type==pt_corner;
8815 break;
8816 case CV_MID_Tangent:
8817 mi->ti.disabled = type==-2;
8818 mi->ti.checked = type==pt_tangent;
8819 break;
8820 case CV_MID_Curve:
8821 mi->ti.disabled = type==-2;
8822 mi->ti.checked = type==pt_curve;
8823 break;
8824 case CV_MID_HVCurve:
8825 mi->ti.disabled = type==-2;
8826 mi->ti.checked = type==pt_hvcurve;
8827 break;
8828 case CV_MID_SpiroG4:
8829 mi->ti.disabled = spirotype==-2;
8830 mi->ti.checked = spirotype==SPIRO_G4;
8831 break;
8832 case CV_MID_SpiroG2:
8833 mi->ti.disabled = spirotype==-2;
8834 mi->ti.checked = spirotype==SPIRO_G2;
8835 break;
8836 case CV_MID_SpiroCorner:
8837 mi->ti.disabled = spirotype==-2;
8838 mi->ti.checked = spirotype==SPIRO_CORNER;
8839 break;
8840 case CV_MID_SpiroLeft:
8841 mi->ti.disabled = spirotype==-2;
8842 mi->ti.checked = spirotype==SPIRO_LEFT;
8843 break;
8844 case CV_MID_SpiroRight:
8845 mi->ti.disabled = spirotype==-2;
8846 mi->ti.checked = spirotype==SPIRO_RIGHT;
8847 break;
8848 case CV_MID_MakeFirst:
8849 mi->ti.disabled = cnt!=1 || sel->first->prev==NULL || sel->first==selpt;
8850 break;
8851 case CV_MID_SpiroMakeFirst:
8852 mi->ti.disabled = opencnt!=0 || spirocnt!=1;
8853 break;
8854 case CV_MID_MakeLine: case CV_MID_MakeArc:
8855 mi->ti.disabled = cnt<2;
8856 break;
8857 case CV_MID_AcceptableExtrema:
8858 mi->ti.disabled = acceptable<0;
8859 mi->ti.checked = acceptable==1;
8860 break;
8861 case CV_MID_NamePoint:
8862 mi->ti.disabled = onlysel==NULL || onlysel == (SplineSet *) -1;
8863 break;
8864 case CV_MID_NameContour:
8865 mi->ti.disabled = onlysel==NULL || onlysel == (SplineSet *) -1;
8866 break;
8867 case CV_MID_ClipPath:
8868 mi->ti.disabled = !cv->b.sc->parent->multilayer;
8869 break;
8870 case CV_MID_InsertPtOnSplineAt:
8871 mi->ti.disabled = spline_selected!=1;
8872 break;
8873 case CV_MID_CenterCP:
8874 mi->ti.disabled = ccp_cnt==0;
8875 break;
8876 case CV_MID_ImplicitPt:
8877 mi->ti.disabled = !cv->b.layerheads[cv->b.drawmode]->order2;
8878 mi->ti.checked = notimplicit==0;
8879 break;
8880 case CV_MID_NoImplicitPt:
8881 mi->ti.disabled = !cv->b.layerheads[cv->b.drawmode]->order2;
8882 mi->ti.checked = notimplicit==1;
8883 break;
8884 case CV_MID_AddAnchor:
8885 mi->ti.disabled = cv->b.container!=NULL;
8886 break;
8887 }
8888 }
8889 }
8890
8891 static void ptlistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
8892 CharView *cv = (CharView *) GDrawGetUserData(gw);
8893 cv_ptlistcheck(cv, mi);
8894 }
8895
8896 static void _CVMenuDir(CharView *cv, struct gmenuitem *mi) {
8897 int splinepoints, dir;
8898 SplinePointList *spl;
8899 Spline *spline, *first;
8900 int needsrefresh = false;
8901
8902 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
8903 first = NULL;
8904 splinepoints = 0;
8905 if ( cv->b.sc->inspiro && hasspiro()) {
8906 int i;
8907 for ( i=0; i<spl->spiro_cnt-1; ++i )
8908 if ( SPIRO_SELECTED(&spl->spiros[i])) {
8909 splinepoints = true;
8910 break;
8911 }
8912 } else {
8913 if ( spl->first->selected ) splinepoints = true;
8914 for ( spline=spl->first->next; spline!=NULL && spline!=first && !splinepoints; spline = spline->to->next ) {
8915 if ( spline->to->selected ) splinepoints = true;
8916 if ( first == NULL ) first = spline;
8917 }
8918 }
8919 if ( splinepoints && spl->first->prev!=NULL ) {
8920 dir = SplinePointListIsClockwise(spl);
8921 if ( (mi->mid==CV_MID_Clockwise && dir==0) || (mi->mid==CV_MID_Counter && dir==1)) {
8922 if ( !needsrefresh )
8923 CVPreserveState(&cv->b);
8924 SplineSetReverse(spl);
8925 needsrefresh = true;
8926 }
8927 }
8928 }
8929 if ( needsrefresh )
8930 CVCharChangedUpdate(&cv->b);
8931 }
8932
8933 static void CVMenuDir(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
8934 CharView *cv = (CharView *) GDrawGetUserData(gw);
8935 _CVMenuDir(cv, mi);
8936 }
8937
8938 static void CVMenuCheckSelf(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8939 CharView *cv = (CharView *) GDrawGetUserData(gw);
8940 CVShows.checkselfintersects = cv->checkselfintersects = !cv->checkselfintersects;
8941 }
8942
8943 static void CVMenuGlyphSelfIntersects(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
8944 CharView *cv = (CharView *) GDrawGetUserData(gw);
8945 Spline *s=NULL, *s2=NULL;
8946 SplineSet *ss;
8947 DBounds b;
8948 double off;
8949
8950 ss = LayerAllSplines(cv->b.layerheads[cv->b.drawmode]);
8951 SplineSetIntersect(ss,&s,&s2);
8952 LayerUnAllSplines(cv->b.layerheads[cv->b.drawmode]);
8953
8954 if ( s!=NULL || s2!=NULL ) {
8955 memset(&b,0,sizeof(b));
8956 CVClearSel(cv);
8957 if ( s!=NULL ) {
8958 b.minx = b.maxx = s->from->me.x;
8959 b.miny = b.maxy = s->from->me.y;
8960 } else if ( s2!=NULL ) {
8961 b.minx = b.maxx = s2->from->me.x;
8962 b.miny = b.maxy = s2->from->me.y;
8963 }
8964 if ( s!=NULL ) {
8965 s->from->selected = s->to->selected = true;
8966 if ( s->to->me.x>b.maxx ) b.maxx = s->to->me.x;
8967 if ( s->to->me.x<b.minx ) b.minx = s->to->me.x;
8968 if ( s->to->me.y>b.maxy ) b.maxy = s->to->me.y;
8969 if ( s->to->me.y<b.miny ) b.miny = s->to->me.y;
8970 }
8971 if ( s2!=NULL ) {
8972 s2->from->selected = s2->to->selected = true;
8973 if ( s2->from->me.x>b.maxx ) b.maxx = s2->from->me.x;
8974 if ( s2->from->me.x<b.minx ) b.minx = s2->from->me.x;
8975 if ( s2->from->me.y>b.maxy ) b.maxy = s2->from->me.y;
8976 if ( s2->from->me.y<b.miny ) b.miny = s2->from->me.y;
8977 if ( s2->to->me.x>b.maxx ) b.maxx = s2->to->me.x;
8978 if ( s2->to->me.x<b.minx ) b.minx = s2->to->me.x;
8979 if ( s2->to->me.y>b.maxy ) b.maxy = s2->to->me.y;
8980 if ( s2->to->me.y<b.miny ) b.miny = s2->to->me.y;
8981 }
8982 off = (b.maxx-b.minx)/10;
8983 if ( off==0 ) off = 1;
8984 b.minx -= off; b.maxx += off;
8985 off = (b.maxy-b.miny)/10;
8986 if ( off==0 ) off = 1;
8987 b.miny -= off; b.maxy += off;
8988 _CVFit(cv,&b,false);
8989 } else
8990 ff_post_notice(_("No Intersections"),_("No Intersections"));
8991 }
8992
8993 static int getorigin(void *d,BasePoint *base,int index) {
8994 CharView *cv = (CharView *) d;
8995
8996 base->x = base->y = 0;
8997 switch ( index ) {
8998 case 0: /* Character origin */
8999 /* all done */
9000 break;
9001 case 1: /* Center of selection */
9002 CVFindCenter(cv,base,!CVAnySel(cv,NULL,NULL,NULL,NULL));
9003 break;
9004 case 2: /* last press */
9005 base->x = cv->p.cx;
9006 base->y = cv->p.cy;
9007 /* I don't have any way of telling if a press has happened. if one */
9008 /* hasn't they'll just get a 0,0 origin. oh well */
9009 break;
9010 default:
9011 return( false );
9012 }
9013 return( true );
9014 }
9015
9016 static void TransRef(RefChar *ref,real transform[6], enum fvtrans_flags flags) {
9017 int j;
9018 real t[6];
9019
9020 for ( j=0; j<ref->layer_cnt; ++j )
9021 SplinePointListTransform(ref->layers[j].splines,transform,tpt_AllPoints);
9022 t[0] = ref->transform[0]*transform[0] +
9023 ref->transform[1]*transform[2];
9024 t[1] = ref->transform[0]*transform[1] +
9025 ref->transform[1]*transform[3];
9026 t[2] = ref->transform[2]*transform[0] +
9027 ref->transform[3]*transform[2];
9028 t[3] = ref->transform[2]*transform[1] +
9029 ref->transform[3]*transform[3];
9030 t[4] = ref->transform[4]*transform[0] +
9031 ref->transform[5]*transform[2] +
9032 transform[4];
9033 t[5] = ref->transform[4]*transform[1] +
9034 ref->transform[5]*transform[3] +
9035 transform[5];
9036 if ( flags&fvt_round_to_int ) {
9037 t[4] = rint( t[4] );
9038 t[5] = rint( t[5] );
9039 }
9040 memcpy(ref->transform,t,sizeof(t));
9041 RefCharFindBounds(ref);
9042 }
9043
9044 void CVTransFuncLayer(CharView *cv,Layer *ly,real transform[6], enum fvtrans_flags flags)
9045 {
9046 int anysel = cv->p.transany;
9047 RefChar *refs;
9048 ImageList *img;
9049 AnchorPoint *ap;
9050 KernPair *kp;
9051 PST *pst;
9052 int l, cvlayer;
9053 enum transformPointMask tpmask = 0;
9054
9055 if ( cv->b.sc->inspiro && hasspiro() )
9056 SplinePointListSpiroTransform(ly->splines,transform,!anysel);
9057 else
9058 {
9059 if( cv->active_tool==cvt_scale )
9060 tpmask |= tpmask_operateOnSelectedBCP;
9061
9062 SplinePointListTransformExtended(
9063 ly->splines, transform,
9064 !anysel?tpt_AllPoints: interpCPsOnMotion?tpt_OnlySelectedInterpCPs:tpt_OnlySelected,
9065 tpmask );
9066 }
9067
9068 if ( flags&fvt_round_to_int )
9069 SplineSetsRound2Int(ly->splines,1.0,cv->b.sc->inspiro && hasspiro(),!anysel);
9070 if ( ly->images!=NULL ) {
9071 ImageListTransform(ly->images,transform,!anysel);
9072 }
9073 for ( refs = ly->refs; refs!=NULL; refs=refs->next )
9074 if ( refs->selected || !anysel )
9075 TransRef(refs,transform,flags);
9076 if ( cv->showanchor ) {
9077 for ( ap=cv->b.sc->anchor; ap!=NULL; ap=ap->next ) if ( ap->selected || !anysel )
9078 ApTransform(ap,transform);
9079 }
9080 if ( !anysel ) {
9081 if ( flags & fvt_scalepstpos ) {
9082 for ( kp=cv->b.sc->kerns; kp!=NULL; kp=kp->next )
9083 kp->off = rint(kp->off*transform[0]);
9084 for ( kp=cv->b.sc->vkerns; kp!=NULL; kp=kp->next )
9085 kp->off = rint(kp->off*transform[3]);
9086 for ( pst = cv->b.sc->possub; pst!=NULL; pst=pst->next ) {
9087 if ( pst->type == pst_position )
9088 VrTrans(&pst->u.pos,transform);
9089 else if ( pst->type==pst_pair ) {
9090 VrTrans(&pst->u.pair.vr[0],transform);
9091 VrTrans(&pst->u.pair.vr[1],transform);
9092 }
9093 }
9094 }
9095 if ( transform[1]==0 && transform[2]==0 ) {
9096 TransHints(cv->b.sc->hstem,transform[3],transform[5],transform[0],transform[4],flags&fvt_round_to_int);
9097 TransHints(cv->b.sc->vstem,transform[0],transform[4],transform[3],transform[5],flags&fvt_round_to_int);
9098 TransDStemHints(cv->b.sc->dstem,transform[0],transform[4],transform[3],transform[5],flags&fvt_round_to_int);
9099 }
9100 if ( transform[0]==1 && transform[3]==1 && transform[1]==0 &&
9101 transform[2]==0 && transform[5]==0 &&
9102 transform[4]!=0 && CVAllSelected(cv) &&
9103 cv->b.sc->unicodeenc!=-1 && isalpha(cv->b.sc->unicodeenc)) {
9104 SCUndoSetLBearingChange(cv->b.sc,(int) rint(transform[4]));
9105 SCSynchronizeLBearing(cv->b.sc,transform[4],CVLayer((CharViewBase *) cv));
9106 }
9107 }
9108 if ( !(flags&fvt_dontmovewidth) && (cv->widthsel || !anysel))
9109 if ( transform[0]>0 && transform[3]>0 && transform[1]==0 &&
9110 transform[2]==0 && transform[4]!=0 )
9111 SCSynchronizeWidth(cv->b.sc,cv->b.sc->width*transform[0]+transform[4],cv->b.sc->width,NULL);
9112 if ( !(flags&fvt_dontmovewidth) && (cv->vwidthsel || !anysel))
9113 if ( transform[0]==1 && transform[3]==1 && transform[1]==0 &&
9114 transform[2]==0 && transform[5]!=0 )
9115 cv->b.sc->vwidth+=transform[5];
9116 if ( (flags&fvt_alllayers) && !anysel ) {
9117 /* SCPreserveBackground(cv->b.sc); */ /* done by caller */
9118 cvlayer = CVLayer( (CharViewBase *) cv );
9119 for ( l=0; l<cv->b.sc->layer_cnt; ++l ) if ( l!=cvlayer ) {
9120 for ( img = cv->b.sc->layers[l].images; img!=NULL; img=img->next )
9121 BackgroundImageTransform(cv->b.sc, img, transform);
9122 SplinePointListTransform(cv->b.sc->layers[l].splines,
9123 transform,tpt_AllPoints);
9124 for ( refs=cv->b.sc->layers[l].refs; refs!=NULL; refs=refs->next )
9125 TransRef(refs,transform,flags);
9126 }
9127 }
9128 }
9129
9130 void CVTransFunc(CharView *cv,real transform[6], enum fvtrans_flags flags)
9131 {
9132 Layer *ly = cv->b.layerheads[cv->b.drawmode];
9133 CVTransFuncLayer( cv, ly, transform, flags );
9134 }
9135
9136 void CVTransFuncAllLayers(CharView *cv,real transform[6], enum fvtrans_flags flags)
9137 {
9138 int idx;
9139 for( idx = 0; idx < cv->b.sc->layer_cnt; ++idx )
9140 {
9141 Layer *ly = &cv->b.sc->layers[ idx ];
9142 CVTransFuncLayer( cv, ly, transform, flags );
9143 }
9144 }
9145
9146 static void transfunc(void *d,real transform[6],int otype,BVTFunc *bvts,
9147 enum fvtrans_flags flags) {
9148 CharView *cv = (CharView *) d;
9149 int anya, l, cvlayer = CVLayer((CharViewBase *) cv);
9150
9151 if ( cv->b.layerheads[cv->b.drawmode]->undoes!=NULL &&
9152 cv->b.layerheads[cv->b.drawmode]->undoes->undotype==ut_tstate )
9153 {
9154 CVDoUndo(&cv->b);
9155 }
9156
9157 if ( flags&fvt_revert )
9158 return;
9159
9160 cv->p.transany = CVAnySel(cv,NULL,NULL,NULL,&anya);
9161 if ( flags&fvt_justapply )
9162 CVPreserveTState(cv);
9163 else {
9164 CVPreserveStateHints(&cv->b);
9165 if ( flags&fvt_alllayers )
9166 for ( l=0; l<cv->b.sc->layer_cnt; ++l ) if ( l!=cvlayer )
9167 SCPreserveLayer(cv->b.sc,l,false);
9168 }
9169
9170 CVPreserveMaybeState( cv, flags&fvt_justapply );
9171 CVTransFunc(cv,transform,flags);
9172 CVCharChangedUpdate(&cv->b);
9173 }
9174
9175 void CVDoTransform(CharView *cv, enum cvtools cvt ) {
9176 int anysel = CVAnySel(cv,NULL,NULL,NULL,NULL);
9177 TransformDlgCreate(cv,transfunc,getorigin,!anysel?(tdf_enableback|tdf_addapply):tdf_addapply,
9178 cvt);
9179 }
9180
9181 static void CVMenuTransform(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9182 CharView *cv = (CharView *) GDrawGetUserData(gw);
9183 CVDoTransform(cv,cvt_none);
9184 }
9185
9186 static void CVMenuPOV(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9187 CharView *cv = (CharView *) GDrawGetUserData(gw);
9188 struct pov_data pov_data;
9189 if ( PointOfViewDlg(&pov_data,cv->b.sc->parent,true)==-1 )
9190 return;
9191 CVPointOfView(cv,&pov_data);
9192 }
9193
9194 static void CVMenuNLTransform(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9195 CharView *cv = (CharView *) GDrawGetUserData(gw);
9196 cv->lastselpt = NULL; cv->lastselcp = NULL;
9197 NonLinearDlg(NULL,cv);
9198 }
9199
9200 void CVMenuConstrain(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
9201 CharView *cv = (CharView *) GDrawGetUserData(gw);
9202 CVConstrainSelection( cv,
9203 mi->mid==CV_MID_Average ? constrainSelection_AveragePoints :
9204 mi->mid==CV_MID_SpacePts ? constrainSelection_SpacePoints :
9205 constrainSelection_SpaceSelectedRegions );
9206 }
9207
9208 static void CVMenuMakeParallel(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9209 CharView *cv = (CharView *) GDrawGetUserData(gw);
9210 CVMakeParallel(cv);
9211 }
9212
9213 static void _CVMenuRound2Int(CharView *cv, double factor) {
9214 int anysel = CVAnySel(cv,NULL,NULL,NULL,NULL);
9215 RefChar *r;
9216 AnchorPoint *ap;
9217
9218 CVPreserveState(&cv->b);
9219 SplineSetsRound2Int(cv->b.layerheads[cv->b.drawmode]->splines,factor,
9220 cv->b.sc->inspiro && hasspiro(), anysel);
9221 for ( r=cv->b.layerheads[cv->b.drawmode]->refs; r!=NULL; r=r->next ) {
9222 if ( r->selected || !anysel ) {
9223 r->transform[4] = rint(r->transform[4]*factor)/factor;
9224 r->transform[5] = rint(r->transform[5]*factor)/factor;
9225 }
9226 }
9227 if ( cv->b.drawmode==dm_fore ) {
9228 for ( ap=cv->b.sc->anchor; ap!=NULL; ap=ap->next ) {
9229 if ( ap->selected || !anysel ) {
9230 ap->me.x = rint(ap->me.x*factor)/factor;
9231 ap->me.y = rint(ap->me.y*factor)/factor;
9232 }
9233 }
9234 }
9235 CVCharChangedUpdate(&cv->b);
9236 }
9237
9238 static void CVMenuRound2Int(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9239 CharView *cv = (CharView *) GDrawGetUserData(gw);
9240 _CVMenuRound2Int(cv,1.0);
9241 }
9242
9243 static void CVMenuRound2Hundredths(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9244 CharView *cv = (CharView *) GDrawGetUserData(gw);
9245 _CVMenuRound2Int(cv,100.0);
9246 }
9247
9248 static void CVMenuCluster(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9249 CharView *cv = (CharView *) GDrawGetUserData(gw);
9250 int layer = cv->b.drawmode == dm_grid ? ly_grid :
9251 cv->b.drawmode == dm_back ? ly_back
9252 : cv->b.layerheads[dm_fore] - cv->b.sc->layers;
9253 SCRoundToCluster(cv->b.sc,layer,true,.1,.5);
9254 }
9255
9256 static void CVMenuStroke(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9257 CharView *cv = (CharView *) GDrawGetUserData(gw);
9258 CVStroke(cv);
9259 }
9260
9261 #ifdef FONTFORGE_CONFIG_TILEPATH
9262 static void CVMenuTilePath(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9263 CharView *cv = (CharView *) GDrawGetUserData(gw);
9264 CVTile(cv);
9265 }
9266
9267 static void CVMenuPatternTile(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9268 CharView *cv = (CharView *) GDrawGetUserData(gw);
9269 CVPatternTile(cv);
9270 }
9271 #endif
9272
9273 static void _CVMenuOverlap(CharView *cv,enum overlap_type ot) {
9274 /* We know it's more likely that we'll find a problem in the overlap code */
9275 /* than anywhere else, so let's save the current state against a crash */
9276
9277 DoAutoSaves();
9278 CVPreserveState(&cv->b);
9279
9280 if ( cv->b.drawmode==dm_fore ) {
9281 MinimumDistancesFree(cv->b.sc->md);
9282 cv->b.sc->md = NULL;
9283 }
9284 cv->b.layerheads[cv->b.drawmode]->splines = SplineSetRemoveOverlap(cv->b.sc,cv->b.layerheads[cv->b.drawmode]->splines,ot);
9285 // Check for removal of last selected points.
9286 if ( cv->b.sc->inspiro && hasspiro()) {
9287 // Detection is not implemented for Spiro, so just clear them.
9288 // TODO: Detect point survival in Spiro mode.
9289 cv->p.sp = cv->lastselpt = NULL;
9290 cv->p.spiro = cv->lastselcp = NULL;
9291 } else {
9292 // Check whether the last selected point is still in the spline set.
9293 // If not, remove the reference to it.
9294 if (cv->lastselpt != NULL &&
9295 !SplinePointListContainsPoint(cv->b.layerheads[cv->b.drawmode]->splines, cv->lastselpt))
9296 cv->p.sp = cv->lastselpt = NULL;
9297 cv->p.spiro = cv->lastselcp = NULL;
9298 }
9299 CVCharChangedUpdate(&cv->b);
9300 }
9301
9302 static void CVMenuOverlap(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
9303 CharView *cv = (CharView *) GDrawGetUserData(gw);
9304 int anysel;
9305
9306 (void) CVAnySel(cv,&anysel,NULL,NULL,NULL);
9307 _CVMenuOverlap(cv,mi->mid==CV_MID_RmOverlap ? (anysel ? over_rmselected: over_remove) :
9308 mi->mid==CV_MID_Intersection ? (anysel ? over_intersel : over_intersect ) :
9309 mi->mid==CV_MID_Exclude ? over_exclude :
9310 (anysel ? over_fisel : over_findinter));
9311 }
9312
9313 static void CVMenuOrder(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
9314 CharView *cv = (CharView *) GDrawGetUserData(gw);
9315 SplinePointList *spl;
9316 RefChar *r;
9317 ImageList *im;
9318 int exactlyone = CVOneContourSel(cv,&spl,&r,&im);
9319
9320 if ( !exactlyone )
9321 return;
9322
9323 CVPreserveState(&cv->b);
9324 if ( spl!=NULL ) {
9325 SplinePointList *p, *pp, *t;
9326 p = pp = NULL;
9327 for ( t=cv->b.layerheads[cv->b.drawmode]->splines; t!=NULL && t!=spl; t=t->next ) {
9328 pp = p; p = t;
9329 }
9330 switch ( mi->mid ) {
9331 case CV_MID_First:
9332 if ( p!=NULL ) {
9333 p->next = spl->next;
9334 spl->next = cv->b.layerheads[cv->b.drawmode]->splines;
9335 cv->b.layerheads[cv->b.drawmode]->splines = spl;
9336 }
9337 break;
9338 case CV_MID_Earlier:
9339 if ( p!=NULL ) {
9340 p->next = spl->next;
9341 spl->next = p;
9342 if ( pp==NULL ) {
9343 cv->b.layerheads[cv->b.drawmode]->splines = spl;
9344 } else {
9345 pp->next = spl;
9346 }
9347 }
9348 break;
9349 case CV_MID_Last:
9350 if ( spl->next!=NULL ) {
9351 for ( t=cv->b.layerheads[cv->b.drawmode]->splines; t->next!=NULL; t=t->next );
9352 t->next = spl;
9353 if ( p==NULL )
9354 cv->b.layerheads[cv->b.drawmode]->splines = spl->next;
9355 else
9356 p->next = spl->next;
9357 spl->next = NULL;
9358 }
9359 break;
9360 case CV_MID_Later:
9361 if ( spl->next!=NULL ) {
9362 t = spl->next;
9363 spl->next = t->next;
9364 t->next = spl;
9365 if ( p==NULL )
9366 cv->b.layerheads[cv->b.drawmode]->splines = t;
9367 else
9368 p->next = t;
9369 }
9370 break;
9371 }
9372 } else if ( r!=NULL ) {
9373 RefChar *p, *pp, *t;
9374 p = pp = NULL;
9375 for ( t=cv->b.layerheads[cv->b.drawmode]->refs; t!=NULL && t!=r; t=t->next ) {
9376 pp = p; p = t;
9377 }
9378 switch ( mi->mid ) {
9379 case CV_MID_First:
9380 if ( p!=NULL ) {
9381 p->next = r->next;
9382 r->next = cv->b.layerheads[cv->b.drawmode]->refs;
9383 cv->b.layerheads[cv->b.drawmode]->refs = r;
9384 }
9385 break;
9386 case CV_MID_Earlier:
9387 if ( p!=NULL ) {
9388 p->next = r->next;
9389 r->next = p;
9390 if ( pp==NULL ) {
9391 cv->b.layerheads[cv->b.drawmode]->refs = r;
9392 } else {
9393 pp->next = r;
9394 }
9395 }
9396 break;
9397 case CV_MID_Last:
9398 if ( r->next!=NULL ) {
9399 for ( t=cv->b.layerheads[cv->b.drawmode]->refs; t->next!=NULL; t=t->next );
9400 t->next = r;
9401 if ( p==NULL )
9402 cv->b.layerheads[cv->b.drawmode]->refs = r->next;
9403 else
9404 p->next = r->next;
9405 r->next = NULL;
9406 }
9407 break;
9408 case CV_MID_Later:
9409 if ( r->next!=NULL ) {
9410 t = r->next;
9411 r->next = t->next;
9412 t->next = r;
9413 if ( p==NULL )
9414 cv->b.layerheads[cv->b.drawmode]->refs = t;
9415 else
9416 p->next = t;
9417 }
9418 break;
9419 }
9420 } else if ( im!=NULL ) {
9421 ImageList *p, *pp, *t;
9422 p = pp = NULL;
9423 for ( t=cv->b.layerheads[cv->b.drawmode]->images; t!=NULL && t!=im; t=t->next ) {
9424 pp = p; p = t;
9425 }
9426 switch ( mi->mid ) {
9427 case CV_MID_First:
9428 if ( p!=NULL ) {
9429 p->next = im->next;
9430 im->next = cv->b.layerheads[cv->b.drawmode]->images;
9431 cv->b.layerheads[cv->b.drawmode]->images = im;
9432 }
9433 break;
9434 case CV_MID_Earlier:
9435 if ( p!=NULL ) {
9436 p->next = im->next;
9437 im->next = p;
9438 if ( pp==NULL ) {
9439 cv->b.layerheads[cv->b.drawmode]->images = im;
9440 } else {
9441 pp->next = im;
9442 }
9443 }
9444 break;
9445 case CV_MID_Last:
9446 if ( im->next!=NULL ) {
9447 for ( t=cv->b.layerheads[cv->b.drawmode]->images; t->next!=NULL; t=t->next );
9448 t->next = im;
9449 if ( p==NULL )
9450 cv->b.layerheads[cv->b.drawmode]->images = im->next;
9451 else
9452 p->next = im->next;
9453 im->next = NULL;
9454 }
9455 break;
9456 case CV_MID_Later:
9457 if ( im->next!=NULL ) {
9458 t = im->next;
9459 im->next = t->next;
9460 t->next = im;
9461 if ( p==NULL )
9462 cv->b.layerheads[cv->b.drawmode]->images = t;
9463 else
9464 p->next = t;
9465 }
9466 break;
9467 }
9468 }
9469 CVCharChangedUpdate(&cv->b);
9470 }
9471
9472 static void _CVMenuAddExtrema(CharView *cv) {
9473 int anysel;
9474 SplineFont *sf = cv->b.sc->parent;
9475
9476 (void) CVAnySel(cv,&anysel,NULL,NULL,NULL);
9477 CVPreserveState(&cv->b);
9478 SplineCharAddExtrema(cv->b.sc,cv->b.layerheads[cv->b.drawmode]->splines,
9479 anysel?ae_between_selected:ae_only_good,sf->ascent+sf->descent);
9480 CVCharChangedUpdate(&cv->b);
9481 }
9482
9483 static void CVMenuAddExtrema(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9484 CharView *cv = (CharView *) GDrawGetUserData(gw);
9485 _CVMenuAddExtrema(cv);
9486 }
9487
9488 static void _CVMenuAction(GWindow gw, void (*func)(SplineChar*, SplineSet*, int)) {
9489 CharView *cv = (CharView *) GDrawGetUserData(gw);
9490 int anysel = CVAnySel(cv,NULL,NULL,NULL,NULL);
9491 CVPreserveState(&cv->b);
9492 func(cv->b.sc,cv->b.layerheads[cv->b.drawmode]->splines,anysel);
9493 CVCharChangedUpdate(&cv->b);
9494 }
9495
9496 static void CVMenuAddInflections(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9497 _CVMenuAction(gw,&SplineCharAddInflections);
9498 }
9499
9500 static void CVMenuBalance(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9501 _CVMenuAction(gw,&SplineCharBalance);
9502 }
9503
9504 static void CVMenuHarmonize(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9505 _CVMenuAction(gw,&SplineCharHarmonize);
9506 }
9507
9508 static void CVSimplify(CharView *cv,int type) {
9509 static struct simplifyinfo smpls[] = {
9510 { sf_normal, 0, 0, 0, 0, 0, 0 },
9511 { sf_normal,.75,.05,0,-1, 0, 0 },
9512 { sf_normal,.75,.05,0,-1, 0, 0 }};
9513 struct simplifyinfo *smpl = &smpls[type+1];
9514
9515 if ( smpl->linelenmax==-1 || (type==0 && !smpl->set_as_default)) {
9516 smpl->err = (cv->b.sc->parent->ascent+cv->b.sc->parent->descent)/1000.;
9517 smpl->linelenmax = (cv->b.sc->parent->ascent+cv->b.sc->parent->descent)/100.;
9518 }
9519
9520 if ( type==1 ) {
9521 if ( !SimplifyDlg(cv->b.sc->parent,smpl))
9522 return;
9523 if ( smpl->set_as_default )
9524 smpls[1] = *smpl;
9525 }
9526
9527 CVPreserveState(&cv->b);
9528 smpl->check_selected_contours = true;
9529 cv->b.layerheads[cv->b.drawmode]->splines = SplineCharSimplify(cv->b.sc,cv->b.layerheads[cv->b.drawmode]->splines,
9530 smpl);
9531 CVCharChangedUpdate(&cv->b);
9532 }
9533
9534 static void CVMenuSimplify(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9535 CharView *cv = (CharView *) GDrawGetUserData(gw);
9536 CVSimplify(cv,0);
9537 }
9538
9539 static void CVMenuSimplifyMore(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9540 CharView *cv = (CharView *) GDrawGetUserData(gw);
9541 CVSimplify(cv,1);
9542 }
9543
9544 static void CVMenuCleanupGlyph(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9545 CharView *cv = (CharView *) GDrawGetUserData(gw);
9546 CVSimplify(cv,-1);
9547 }
9548
9549 static int SPLSelected(SplineSet *ss) {
9550 SplinePoint *sp;
9551
9552 for ( sp=ss->first ;; ) {
9553 if ( sp->selected )
9554 return( true );
9555 if ( sp->next==NULL )
9556 return( false );
9557 sp = sp->next->to;
9558 if ( sp==ss->first )
9559 return( false );
9560 }
9561 }
9562
9563 static void CVCanonicalStart(CharView *cv) {
9564 SplineSet *ss;
9565 int changed = 0;
9566
9567 for ( ss = cv->b.layerheads[cv->b.drawmode]->splines; ss!=NULL; ss=ss->next )
9568 if ( ss->first==ss->last && SPLSelected(ss)) {
9569 SPLStartToLeftmost(cv->b.sc,ss,&changed);
9570 /* The above clears the spiros if needed */
9571 }
9572 }
9573
9574 static void CVMenuCanonicalStart(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9575 CharView *cv = (CharView *) GDrawGetUserData(gw);
9576 CVCanonicalStart(cv);
9577 }
9578
9579 static void CVCanonicalContour(CharView *cv) {
9580 CanonicalContours(cv->b.sc,CVLayer((CharViewBase *) cv));
9581 }
9582
9583 static void CVMenuCanonicalContours(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9584 CharView *cv = (CharView *) GDrawGetUserData(gw);
9585 CVCanonicalContour(cv);
9586 }
9587
9588 static void _CVMenuMakeFirst(CharView *cv) {
9589 SplinePoint *selpt = NULL;
9590 int anypoints = 0, splinepoints;
9591 SplinePointList *spl, *sel;
9592 Spline *spline, *first;
9593
9594 sel = NULL;
9595 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
9596 first = NULL;
9597 splinepoints = 0;
9598 if ( spl->first->selected ) { splinepoints = 1; sel = spl; selpt=spl->first; }
9599 for ( spline=spl->first->next; spline!=NULL && spline!=first && !splinepoints; spline = spline->to->next ) {
9600 if ( spline->to->selected ) { ++splinepoints; sel = spl; selpt=spline->to; }
9601 if ( first == NULL ) first = spline;
9602 }
9603 anypoints += splinepoints;
9604 }
9605
9606 if ( anypoints!=1 || sel->first->prev==NULL || sel->first==selpt )
9607 return;
9608
9609 CVPreserveState(&cv->b);
9610 sel->first = sel->last = selpt;
9611 CVCharChangedUpdate(&cv->b);
9612 }
9613
9614 static void CVMenuMakeFirst(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9615 CharView *cv = (CharView *) GDrawGetUserData(gw);
9616 _CVMenuMakeFirst(cv);
9617 }
9618
9619 static void _CVMenuSpiroMakeFirst(CharView *cv) {
9620 int anypoints = 0, which;
9621 SplinePointList *spl, *sel;
9622 int i;
9623 spiro_cp *newspiros;
9624
9625 sel = NULL;
9626 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
9627 for ( i=0; i<spl->spiro_cnt-1; ++i ) {
9628 if ( SPIRO_SELECTED(&spl->spiros[i])) {
9629 if ( SPIRO_SPL_OPEN(spl))
9630 return;
9631 ++anypoints;
9632 sel = spl;
9633 which = i;
9634 }
9635 }
9636 }
9637
9638 if ( anypoints!=1 || sel==NULL )
9639 return;
9640
9641 CVPreserveState(&cv->b);
9642 newspiros = malloc((sel->spiro_max+1)*sizeof(spiro_cp));
9643 memcpy(newspiros,sel->spiros+which,(sel->spiro_cnt-1-which)*sizeof(spiro_cp));
9644 memcpy(newspiros+(sel->spiro_cnt-1-which),sel->spiros,which*sizeof(spiro_cp));
9645 memcpy(newspiros+sel->spiro_cnt-1,sel->spiros+sel->spiro_cnt-1,sizeof(spiro_cp));
9646 free(sel->spiros);
9647 sel->spiros = newspiros;
9648 SSRegenerateFromSpiros(sel);
9649 CVCharChangedUpdate(&cv->b);
9650 }
9651
9652 static void CVMenuSpiroMakeFirst(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9653 CharView *cv = (CharView *) GDrawGetUserData(gw);
9654 _CVMenuSpiroMakeFirst(cv);
9655 }
9656
9657 static void CVMenuMakeLine(GWindow gw, struct gmenuitem *mi, GEvent *e) {
9658 CharView *cv = (CharView *) GDrawGetUserData(gw);
9659 _CVMenuMakeLine((CharViewBase *) cv,mi->mid==CV_MID_MakeArc, e!=NULL && (e->u.mouse.state&ksm_meta));
9660 }
9661
9662 void _CVMenuNamePoint(CharView *cv, SplinePoint *sp) {
9663 char *ret, *name, *oldname;
9664
9665 oldname = (sp->name && *sp->name) ? sp->name : NULL;
9666 ret = gwwv_ask_string(_("Name this point"), oldname,
9667 _("Please name this point"));
9668 if ( ret!=NULL ) {
9669 name = *ret ? ret : NULL;
9670 if (name != oldname || (name && oldname && strcmp(name,oldname))) {
9671 sp->name = name;
9672 CVCharChangedUpdate(&cv->b);
9673 }
9674 if (name != ret) { free(ret); ret = NULL; }
9675 if (name != oldname) { free(oldname); oldname = NULL; }
9676 }
9677 }
9678
9679 static void CVMenuNamePoint(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9680 CharView *cv = (CharView *) GDrawGetUserData(gw);
9681 SplinePointList *spl;
9682 SplinePoint *sp;
9683 RefChar *r;
9684 ImageList *il;
9685 spiro_cp *junk;
9686
9687 if ( CVOneThingSel( cv, &sp, &spl, &r, &il, NULL, &junk ) && sp) {
9688 _CVMenuNamePoint(cv, sp);
9689 }
9690 }
9691
9692 void _CVMenuNameContour(CharView *cv) {
9693 SplinePointList *spl, *onlysel = NULL;
9694 SplinePoint *sp;
9695 char *ret;
9696 int i;
9697
9698 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
9699 if ( !cv->b.sc->inspiro || !hasspiro()) {
9700 for ( sp=spl->first; ; ) {
9701 if ( sp->selected ) {
9702 if ( onlysel==NULL )
9703 onlysel = spl;
9704 else if ( onlysel!=spl )
9705 return;
9706 }
9707 if ( sp->next==NULL )
9708 break;
9709 sp = sp->next->to;
9710 if ( sp==spl->first )
9711 break;
9712 }
9713 } else {
9714 for ( i=0; i<spl->spiro_cnt; ++i ) {
9715 if ( SPIRO_SELECTED(&spl->spiros[i])) {
9716 if ( onlysel==NULL )
9717 onlysel = spl;
9718 else if ( onlysel!=spl )
9719 return;
9720 }
9721 }
9722 }
9723 }
9724
9725 if ( onlysel!=NULL ) {
9726 ret = gwwv_ask_string(_("Name this contour"),onlysel->contour_name,
9727 _("Please name this contour"));
9728 if ( ret!=NULL ) {
9729 free(onlysel->contour_name);
9730 if ( *ret!='\0' )
9731 onlysel->contour_name = ret;
9732 else {
9733 onlysel->contour_name = NULL;
9734 free(ret);
9735 }
9736 CVCharChangedUpdate(&cv->b);
9737 }
9738 }
9739 }
9740
9741 static void CVMenuNameContour(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9742 CharView *cv = (CharView *) GDrawGetUserData(gw);
9743 _CVMenuNameContour(cv);
9744 }
9745
9746 struct insertonsplineat {
9747 int done;
9748 GWindow gw;
9749 Spline *s;
9750 CharView *cv;
9751 };
9752
9753 #define CID_X 1001
9754 #define CID_Y 1002
9755 #define CID_XR 1003
9756 #define CID_YR 1004
9757
9758 static int IOSA_OK(GGadget *g, GEvent *e) {
9759
9760 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
9761 int err = false;
9762 struct insertonsplineat *iosa = GDrawGetUserData(GGadgetGetWindow(g));
9763 double val;
9764 extended ts[3];
9765 int which;
9766 SplinePoint *sp;
9767
9768 if ( GGadgetIsChecked(GWidgetGetControl(iosa->gw,CID_XR)) ) {
9769 val = GetReal8(iosa->gw,CID_X,"X",&err);
9770 which = 0;
9771 } else {
9772 val = GetReal8(iosa->gw,CID_Y,"Y",&err);
9773 which = 1;
9774 }
9775 if ( err )
9776 return(true);
9777 if ( CubicSolve(&iosa->s->splines[which],val,ts)==0 ) {
9778 ff_post_error(_("Out of Range"),_("The spline does not reach %g"), (double) val );
9779 return( true );
9780 }
9781 iosa->done = true;
9782 CVPreserveState(&iosa->cv->b);
9783 for (;;) {
9784 sp = SplineBisect(iosa->s,ts[0]);
9785 SplinePointCategorize(sp);
9786 if ( which==0 ) {
9787 double off = val-sp->me.x;
9788 sp->me.x = val; sp->nextcp.x += off; sp->prevcp.x += off;
9789 } else {
9790 double off = val-sp->me.y;
9791 sp->me.y = val; sp->nextcp.y += off; sp->prevcp.y += off;
9792 }
9793 SplineRefigure(sp->prev); SplineRefigure(sp->next);
9794 if ( ts[1]==-1 ) {
9795 CVCharChangedUpdate(&iosa->cv->b);
9796 return( true );
9797 }
9798 iosa->s = sp->next;
9799 if ( CubicSolve(&iosa->s->splines[which],val,ts)==0 ) {
9800 /* Odd. We found one earlier */
9801 CVCharChangedUpdate(&iosa->cv->b);
9802 return( true );
9803 }
9804 }
9805 }
9806 return( true );
9807 }
9808
9809 static int IOSA_Cancel(GGadget *g, GEvent *e) {
9810 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
9811 struct insertonsplineat *iosa = GDrawGetUserData(GGadgetGetWindow(g));
9812 iosa->done = true;
9813 }
9814 return( true );
9815 }
9816
9817 static int IOSA_FocusChange(GGadget *g, GEvent *e) {
9818 if ( e->type==et_controlevent && e->u.control.subtype == et_textfocuschanged ) {
9819 struct insertonsplineat *iosa = GDrawGetUserData(GGadgetGetWindow(g));
9820 int cid = (intptr_t) GGadgetGetUserData(g);
9821 GGadgetSetChecked(GWidgetGetControl(iosa->gw,cid),true);
9822 }
9823 return( true );
9824 }
9825
9826 static int IOSA_RadioChange(GGadget *g, GEvent *e) {
9827 if ( e->type==et_controlevent && e->u.control.subtype == et_radiochanged ) {
9828 struct insertonsplineat *iosa = GDrawGetUserData(GGadgetGetWindow(g));
9829 int cid = (intptr_t) GGadgetGetUserData(g);
9830 GWidgetIndicateFocusGadget(GWidgetGetControl(iosa->gw,cid));
9831 GTextFieldSelect(GWidgetGetControl(iosa->gw,cid),0,-1);
9832 }
9833 return( true );
9834 }
9835
9836 static int iosa_e_h(GWindow gw, GEvent *event) {
9837 if ( event->type==et_close ) {
9838 struct insertonsplineat *iosa = GDrawGetUserData(gw);
9839 iosa->done = true;
9840 } else if ( event->type == et_char ) {
9841 return( false );
9842 } else if ( event->type == et_map ) {
9843 /* Above palettes */
9844 GDrawRaise(gw);
9845 }
9846 return( true );
9847 }
9848
9849 void _CVMenuInsertPt(CharView *cv) {
9850 SplineSet *spl;
9851 Spline *s, *found=NULL, *first;
9852 struct insertonsplineat iosa;
9853 GRect pos;
9854 GWindowAttrs wattrs;
9855 GGadgetCreateData gcd[11], boxes[2], topbox[2], *hvs[13], *varray[8], *buttons[6];
9856 GTextInfo label[11];
9857
9858 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
9859 first = NULL;
9860 for ( s=spl->first->next; s!=NULL && s!=first ; s = s->to->next ) {
9861 if ( first==NULL ) first=s;
9862 if ( s->from->selected && s->to->selected ) {
9863 if ( found!=NULL )
9864 return; /* Can only work with one spline */
9865 found = s;
9866 }
9867 }
9868 }
9869 if ( found==NULL )
9870 return; /* Need a spline */
9871
9872 memset(&iosa,0,sizeof(iosa));
9873 iosa.s = found;
9874 iosa.cv = cv;
9875 memset(&wattrs,0,sizeof(wattrs));
9876 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict;
9877 wattrs.event_masks = ~(1<<et_charup);
9878 wattrs.restrict_input_to_me = 1;
9879 wattrs.undercursor = 1;
9880 wattrs.cursor = ct_pointer;
9881 wattrs.utf8_window_title = _("Insert a point on the given spline at either...");
9882 wattrs.is_dlg = true;
9883 pos.x = pos.y = 0;
9884 pos.width = GGadgetScale(GDrawPointsToPixels(NULL,210));
9885 pos.height = GDrawPointsToPixels(NULL,120);
9886 iosa.gw = GDrawCreateTopWindow(NULL,&pos,iosa_e_h,&iosa,&wattrs);
9887
9888 memset(&label,0,sizeof(label));
9889 memset(&gcd,0,sizeof(gcd));
9890
9891 label[0].text = (unichar_t *) _("_X:");
9892 label[0].text_is_1byte = true;
9893 label[0].text_in_resource = true;
9894 gcd[0].gd.label = &label[0];
9895 gcd[0].gd.pos.x = 5; gcd[0].gd.pos.y = 5;
9896 gcd[0].gd.flags = gg_enabled|gg_visible|gg_cb_on;
9897 gcd[0].gd.cid = CID_XR;
9898 gcd[0].gd.handle_controlevent = IOSA_RadioChange;
9899 gcd[0].data = (void *) CID_X;
9900 gcd[0].creator = GRadioCreate;
9901
9902 label[1].text = (unichar_t *) _("_Y:");
9903 label[1].text_is_1byte = true;
9904 label[1].text_in_resource = true;
9905 gcd[1].gd.label = &label[1];
9906 gcd[1].gd.pos.x = 5; gcd[1].gd.pos.y = 32;
9907 gcd[1].gd.flags = gg_enabled|gg_visible|gg_rad_continueold ;
9908 gcd[1].gd.cid = CID_YR;
9909 gcd[1].gd.handle_controlevent = IOSA_RadioChange;
9910 gcd[1].data = (void *) CID_Y;
9911 gcd[1].creator = GRadioCreate;
9912
9913 gcd[2].gd.pos.x = 131; gcd[2].gd.pos.y = 5; gcd[2].gd.pos.width = 60;
9914 gcd[2].gd.flags = gg_enabled|gg_visible;
9915 gcd[2].gd.cid = CID_X;
9916 gcd[2].gd.handle_controlevent = IOSA_FocusChange;
9917 gcd[2].data = (void *) CID_XR;
9918 gcd[2].creator = GTextFieldCreate;
9919
9920 gcd[3].gd.pos.x = 131; gcd[3].gd.pos.y = 32; gcd[3].gd.pos.width = 60;
9921 gcd[3].gd.flags = gg_enabled|gg_visible;
9922 gcd[3].gd.cid = CID_Y;
9923 gcd[3].gd.handle_controlevent = IOSA_FocusChange;
9924 gcd[3].data = (void *) CID_YR;
9925 gcd[3].creator = GTextFieldCreate;
9926
9927 gcd[4].gd.pos.x = 20-3; gcd[4].gd.pos.y = 120-32-3;
9928 gcd[4].gd.pos.width = -1; gcd[4].gd.pos.height = 0;
9929 gcd[4].gd.flags = gg_visible | gg_enabled | gg_but_default;
9930 label[4].text = (unichar_t *) _("_OK");
9931 label[4].text_is_1byte = true;
9932 label[4].text_in_resource = true;
9933 gcd[4].gd.mnemonic = 'O';
9934 gcd[4].gd.label = &label[4];
9935 gcd[4].gd.handle_controlevent = IOSA_OK;
9936 gcd[4].creator = GButtonCreate;
9937
9938 gcd[5].gd.pos.x = -20; gcd[5].gd.pos.y = 120-32;
9939 gcd[5].gd.pos.width = -1; gcd[5].gd.pos.height = 0;
9940 gcd[5].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
9941 label[5].text = (unichar_t *) _("_Cancel");
9942 label[5].text_is_1byte = true;
9943 label[5].text_in_resource = true;
9944 gcd[5].gd.label = &label[5];
9945 gcd[5].gd.mnemonic = 'C';
9946 gcd[5].gd.handle_controlevent = IOSA_Cancel;
9947 gcd[5].creator = GButtonCreate;
9948
9949 hvs[0] = &gcd[0]; hvs[1] = &gcd[2]; hvs[2] = NULL;
9950 hvs[3] = &gcd[1]; hvs[4] = &gcd[3]; hvs[5] = NULL;
9951 hvs[6] = NULL;
9952
9953 buttons[0] = buttons[2] = buttons[4] = GCD_Glue; buttons[5] = NULL;
9954 buttons[1] = &gcd[4]; buttons[3] = &gcd[5];
9955
9956 varray[0] = &boxes[1]; varray[1] = NULL;
9957 varray[2] = GCD_Glue; varray[3] = NULL;
9958 varray[4] = &boxes[0]; varray[5] = NULL;
9959 varray[6] = NULL;
9960
9961 memset(boxes,0,sizeof(boxes));
9962 boxes[0].gd.flags = gg_enabled|gg_visible;
9963 boxes[0].gd.u.boxelements = buttons;
9964 boxes[0].creator = GHBoxCreate;
9965
9966 boxes[1].gd.flags = gg_enabled|gg_visible;
9967 boxes[1].gd.u.boxelements = hvs;
9968 boxes[1].creator = GHVBoxCreate;
9969
9970 memset(topbox,0,sizeof(topbox));
9971 topbox[0].gd.pos.x = topbox[0].gd.pos.y = 2;
9972 topbox[0].gd.pos.width = pos.width-4; topbox[0].gd.pos.height = pos.height-4;
9973 topbox[0].gd.flags = gg_enabled|gg_visible;
9974 topbox[0].gd.u.boxelements = varray;
9975 topbox[0].creator = GHVGroupCreate;
9976
9977
9978 GGadgetsCreate(iosa.gw,topbox);
9979 GHVBoxSetExpandableRow(topbox[0].ret,1);
9980 GHVBoxSetExpandableCol(boxes[0].ret,gb_expandgluesame);
9981 GHVBoxSetExpandableCol(boxes[1].ret,1);
9982 GWidgetIndicateFocusGadget(GWidgetGetControl(iosa.gw,CID_X));
9983 GTextFieldSelect(GWidgetGetControl(iosa.gw,CID_X),0,-1);
9984 GHVBoxFitWindow(topbox[0].ret);
9985
9986 GDrawSetVisible(iosa.gw,true);
9987 while ( !iosa.done )
9988 GDrawProcessOneEvent(NULL);
9989 GDrawDestroyWindow(iosa.gw);
9990 }
9991
9992 static void CVMenuInsertPt(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
9993 CharView *cv = (CharView *) GDrawGetUserData(gw);
9994 _CVMenuInsertPt(cv);
9995 }
9996
9997 static void _CVCenterCP(CharView *cv) {
9998 SplinePointList *spl;
9999 SplinePoint *sp;
10000 int changed = false;
10001 enum movething { mt_pt, mt_ncp, mt_pcp } movething = mt_pt;
10002
10003 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
10004 for ( sp=spl->first; ; ) {
10005 if ( sp->selected && sp->prev!=NULL && sp->next!=NULL &&
10006 !sp->noprevcp && !sp->nonextcp ) {
10007 if ( sp->me.x != (sp->nextcp.x+sp->prevcp.x)/2 ||
10008 sp->me.y != (sp->nextcp.y+sp->prevcp.y)/2 ) {
10009 if ( !changed ) {
10010 CVPreserveState(&cv->b);
10011 changed = true;
10012 }
10013 switch ( movething ) {
10014 case mt_pt:
10015 sp->me.x = (sp->nextcp.x+sp->prevcp.x)/2;
10016 sp->me.y = (sp->nextcp.y+sp->prevcp.y)/2;
10017 SplineRefigure(sp->prev);
10018 SplineRefigure(sp->next);
10019 break;
10020 case mt_ncp:
10021 sp->nextcp.x = sp->me.x - (sp->prevcp.x-sp->me.x);
10022 sp->nextcp.y = sp->me.y - (sp->prevcp.y-sp->me.y);
10023 if ( sp->next->order2 ) {
10024 sp->next->to->prevcp = sp->nextcp;
10025 sp->next->to->noprevcp = false;
10026 }
10027 SplineRefigure(sp->prev);
10028 SplineRefigureFixup(sp->next);
10029 break;
10030 case mt_pcp:
10031 sp->prevcp.x = sp->me.x - (sp->nextcp.x-sp->me.x);
10032 sp->prevcp.y = sp->me.y - (sp->nextcp.y-sp->me.y);
10033 if ( sp->prev->order2 ) {
10034 sp->prev->from->nextcp = sp->prevcp;
10035 sp->prev->from->nonextcp = false;
10036 }
10037 SplineRefigureFixup(sp->prev);
10038 SplineRefigure(sp->next);
10039 break;
10040 }
10041 }
10042 }
10043 if ( sp->next==NULL )
10044 break;
10045 sp = sp->next->to;
10046 if ( sp==spl->first )
10047 break;
10048 }
10049 }
10050
10051 if ( changed )
10052 CVCharChangedUpdate(&cv->b);
10053 }
10054
10055 static void CVMenuCenterCP(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10056 CharView *cv = (CharView *) GDrawGetUserData(gw);
10057 _CVCenterCP(cv);
10058 }
10059
10060 void CVMakeClipPath(CharView *cv) {
10061 SplineSet *ss;
10062 SplinePoint *sp;
10063 int sel;
10064 int changed=false;
10065
10066 for ( ss=cv->b.layerheads[cv->b.drawmode]->splines; ss!=NULL; ss=ss->next ) {
10067 sel = false;
10068 for ( sp=ss->first; ; ) {
10069 if ( sp->selected ) {
10070 sel = true;
10071 break;
10072 }
10073 if ( sp->next==NULL )
10074 break;
10075 sp = sp->next->to;
10076 if ( sp==ss->first )
10077 break;
10078 }
10079 if ( sel!=ss->is_clip_path ) {
10080 if ( !changed )
10081 CVPreserveState((CharViewBase *) cv);
10082 changed = true;
10083 ss->is_clip_path = sel;
10084 }
10085 }
10086 if ( changed )
10087 CVCharChangedUpdate((CharViewBase *) cv);
10088 }
10089
10090 static void CVMenuClipPath(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10091 CharView *cv = (CharView *) GDrawGetUserData(gw);
10092 CVMakeClipPath(cv);
10093 }
10094
10095 void CVAddAnchor(CharView *cv) {
10096 int waslig;
10097
10098 if ( AnchorClassUnused(cv->b.sc,&waslig)==NULL ) {
10099 SplineFont *sf = cv->b.sc->parent;
10100 char *name = gwwv_ask_string(_("Anchor Class Name"),"",_("Please enter the name of a Anchor point class to create"));
10101 if ( name==NULL )
10102 return;
10103 SFFindOrAddAnchorClass(sf,name,NULL);
10104 free(name);
10105 if ( AnchorClassUnused(cv->b.sc,&waslig)==NULL )
10106 return;
10107 }
10108 ApGetInfo(cv,NULL);
10109 }
10110
10111 static void CVMenuAddAnchor(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10112 CharView *cv = (CharView *) GDrawGetUserData(gw);
10113 CVAddAnchor(cv);
10114 }
10115
10116 static void CVMenuAutotrace(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *e) {
10117 CharView *cv = (CharView *) GDrawGetUserData(gw);
10118 GCursor ct;
10119
10120 ct = GDrawGetCursor(cv->v);
10121 GDrawSetCursor(cv->v,ct_watch);
10122 ff_progress_allow_events();
10123 SCAutoTrace(cv->b.sc,CVLayer((CharViewBase *) cv),e!=NULL && (e->u.mouse.state&ksm_shift));
10124 GDrawSetCursor(cv->v,ct);
10125 }
10126
10127 static void CVMenuBuildAccent(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10128 CharView *cv = (CharView *) GDrawGetUserData(gw);
10129 extern int onlycopydisplayed;
10130 int layer = CVLayer((CharViewBase *) cv);
10131
10132 if ( SFIsRotatable(cv->b.fv->sf,cv->b.sc))
10133 /* It's ok */;
10134 else if ( !SFIsSomethingBuildable(cv->b.fv->sf,cv->b.sc,layer,true) )
10135 return;
10136 SCBuildComposit(cv->b.fv->sf,cv->b.sc,layer,NULL,onlycopydisplayed,true);
10137 }
10138
10139 static void CVMenuBuildComposite(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10140 CharView *cv = (CharView *) GDrawGetUserData(gw);
10141 extern int onlycopydisplayed;
10142 int layer = CVLayer((CharViewBase *) cv);
10143
10144 if ( SFIsRotatable(cv->b.fv->sf,cv->b.sc))
10145 /* It's ok */;
10146 else if ( !SFIsCompositBuildable(cv->b.fv->sf,cv->b.sc->unicodeenc,cv->b.sc,layer) )
10147 return;
10148 SCBuildComposit(cv->b.fv->sf,cv->b.sc,layer,NULL,onlycopydisplayed,false);
10149 }
10150
10151 static void CVMenuReverseDir(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10152 CharView *cv = (CharView *) GDrawGetUserData(gw);
10153 int changed=false;
10154 SplineSet *ss;
10155
10156 for ( ss = cv->b.layerheads[cv->b.drawmode]->splines; ss!=NULL; ss=ss->next )
10157 if ( PointListIsSelected(ss)) {
10158 if ( !changed ) {
10159 CVPreserveState(&cv->b);
10160 cv->lastselpt = NULL; cv->lastselcp = NULL;
10161 changed = true;
10162 }
10163 SplineSetReverse(ss);
10164 }
10165
10166 if ( changed )
10167 CVCharChangedUpdate(&cv->b);
10168 }
10169
10170 static void CVMenuCorrectDir(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10171 CharView *cv = (CharView *) GDrawGetUserData(gw);
10172 int changed=false, refchanged=false;
10173 RefChar *ref;
10174 int asked=-1;
10175 int layer = CVLayer( (CharViewBase *) cv);
10176
10177 for ( ref=cv->b.sc->layers[layer].refs; ref!=NULL; ref=ref->next ) {
10178 if ( ref->transform[0]*ref->transform[3]<0 ||
10179 (ref->transform[0]==0 && ref->transform[1]*ref->transform[2]>0)) {
10180 if ( asked==-1 ) {
10181 char *buts[4];
10182 buts[0] = _("_Unlink");
10183 buts[1] = _("_No");
10184 buts[2] = _("_Cancel");
10185 buts[3] = NULL;
10186 asked = gwwv_ask(_("Flipped Reference"),(const char **) buts,0,2,_("%.50s contains a flipped reference. This cannot be corrected as is. Would you like me to unlink it and then correct it?"), cv->b.sc->name );
10187 if ( asked==2 )
10188 return;
10189 else if ( asked==1 )
10190 break;
10191 }
10192 if ( asked==0 ) {
10193 if ( !refchanged ) {
10194 refchanged = true;
10195 CVPreserveState(&cv->b);
10196 }
10197 SCRefToSplines(cv->b.sc,ref,layer);
10198 }
10199 }
10200 }
10201
10202 if ( !refchanged )
10203 CVPreserveState(&cv->b);
10204
10205 cv->b.layerheads[cv->b.drawmode]->splines = SplineSetsCorrect(cv->b.layerheads[cv->b.drawmode]->splines,&changed);
10206 if ( changed || refchanged )
10207 CVCharChangedUpdate(&cv->b);
10208 }
10209
10210 static void CVMenuInsertText(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10211 CharView *cv = (CharView *) GDrawGetUserData(gw);
10212 InsertTextDlg(cv);
10213 }
10214
10215 static void CVMenuGetInfo(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10216 CharView *cv = (CharView *) GDrawGetUserData(gw);
10217 CVGetInfo(cv);
10218 }
10219
10220 static void CVMenuCharInfo(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10221 CharView *cv = (CharView *) GDrawGetUserData(gw);
10222 SCCharInfo(cv->b.sc,CVLayer((CharViewBase *) cv),cv->b.fv->map,CVCurEnc(cv));
10223 }
10224
10225 static void CVMenuShowDependentRefs(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10226 CharView *cv = (CharView *) GDrawGetUserData(gw);
10227 SCRefBy(cv->b.sc);
10228 }
10229
10230 static void CVMenuShowDependentSubs(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10231 CharView *cv = (CharView *) GDrawGetUserData(gw);
10232 SCSubBy(cv->b.sc);
10233 }
10234
10235 static void CVMenuBitmaps(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
10236 CharView *cv = (CharView *) GDrawGetUserData(gw);
10237 BitmapDlg(cv->b.fv,gw,cv->b.sc,mi->mid==CV_MID_RemoveBitmaps?-1: (mi->mid==CV_MID_AvailBitmaps) );
10238 }
10239
10240 static void cv_allistcheck(CharView *cv, struct gmenuitem *mi) {
10241 int selpoints = 0;
10242 SplinePointList *spl;
10243 SplinePoint *sp=NULL;
10244
10245 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
10246 sp=spl->first;
10247 while ( 1 ) {
10248 if ( sp->selected )
10249 ++selpoints;
10250 if ( sp->next==NULL )
10251 break;
10252 sp = sp->next->to;
10253 if ( sp==spl->first )
10254 break;
10255 }
10256 }
10257
10258 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
10259 switch ( mi->mid ) {
10260 case CV_MID_Average:
10261 mi->ti.disabled = selpoints<2;
10262 break;
10263 case CV_MID_SpacePts:
10264 mi->ti.disabled = ((selpoints<3) && (selpoints!=1));
10265 break;
10266 case CV_MID_SpaceRegion:
10267 mi->ti.disabled = selpoints<3;
10268 break;
10269 case CV_MID_MakeParallel:
10270 mi->ti.disabled = selpoints!=4;
10271 break;
10272 }
10273 }
10274 }
10275
10276 static void allistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
10277 CharView *cv = (CharView *) GDrawGetUserData(gw);
10278 cv_allistcheck(cv, mi);
10279 }
10280
10281 static void cv_balistcheck(CharView *cv, struct gmenuitem *mi) {
10282 int layer = CVLayer((CharViewBase *) cv);
10283
10284 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
10285 switch ( mi->mid ) {
10286 case CV_MID_BuildAccent:
10287 mi->ti.disabled = !SFIsSomethingBuildable(cv->b.fv->sf,cv->b.sc,layer,true);
10288 break;
10289 case CV_MID_BuildComposite:
10290 mi->ti.disabled = !SFIsSomethingBuildable(cv->b.fv->sf,cv->b.sc,layer,false);
10291 break;
10292 }
10293 }
10294 }
10295
10296 static void balistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
10297 CharView *cv = (CharView *) GDrawGetUserData(gw);
10298 cv_balistcheck(cv, mi);
10299 }
10300
10301 static void delistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
10302 CharView *cv = (CharView *) GDrawGetUserData(gw);
10303
10304 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
10305 switch ( mi->mid ) {
10306 case CV_MID_ShowDependentRefs:
10307 mi->ti.disabled = cv->b.sc->dependents==NULL;
10308 break;
10309 case CV_MID_ShowDependentSubs:
10310 mi->ti.disabled = !SCUsedBySubs(cv->b.sc);
10311 break;
10312 }
10313 }
10314 }
10315
10316 static void rndlistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
10317 CharView *cv = (CharView *) GDrawGetUserData(gw);
10318
10319 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
10320 switch ( mi->mid ) {
10321 case CV_MID_RoundToCluster:
10322 mi->ti.disabled = cv->b.sc->inspiro && hasspiro();
10323 break;
10324 }
10325 }
10326 }
10327
10328 static void cv_ellistcheck(CharView *cv, struct gmenuitem *mi) {
10329 int anypoints = 0, splinepoints, dir = -2;
10330 int self_intersects=-2;
10331 SplinePointList *spl;
10332 Spline *spline, *first;
10333 AnchorPoint *ap;
10334 spiro_cp *cp;
10335 int i;
10336
10337 #ifdef FONTFORGE_CONFIG_TILEPATH
10338 int badsel = false;
10339 RefChar *ref;
10340 ImageList *il;
10341
10342 for ( ref=cv->b.layerheads[cv->b.drawmode]->refs; ref!=NULL; ref=ref->next )
10343 if ( ref->selected )
10344 badsel = true;
10345
10346 for ( il=cv->b.layerheads[cv->b.drawmode]->images; il!=NULL; il=il->next )
10347 if ( il->selected )
10348 badsel = true;
10349 #endif
10350
10351 if ( cv->checkselfintersects ) {
10352 Spline *s, *s2;
10353 SplineSet *ss;
10354 ss = LayerAllSplines(cv->b.layerheads[cv->b.drawmode]);
10355 self_intersects = SplineSetIntersect(ss,&s,&s2);
10356 LayerUnAllSplines(cv->b.layerheads[cv->b.drawmode]);
10357 }
10358
10359 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
10360 first = NULL;
10361 splinepoints = 0;
10362 if ( cv->b.sc->inspiro && hasspiro()) {
10363 for ( i=0; i<spl->spiro_cnt-1; ++i ) {
10364 if ( SPIRO_SELECTED(&spl->spiros[i])) {
10365 splinepoints = 1;
10366 break;
10367 }
10368 }
10369 } else {
10370 if ( spl->first->selected ) { splinepoints = 1; }
10371 for ( spline=spl->first->next; spline!=NULL && spline!=first && !splinepoints; spline = spline->to->next ) {
10372 if ( spline->to->selected ) { ++splinepoints; }
10373 if ( first == NULL ) first = spline;
10374 }
10375 }
10376 if ( splinepoints ) {
10377 anypoints += splinepoints;
10378 if ( dir==-1 )
10379 /* Do nothing */;
10380 else if ( spl->first!=spl->last || spl->first->next==NULL ) {
10381 if ( dir==-2 || dir==2 )
10382 dir = 2; /* Not a closed path, no direction */
10383 else
10384 dir = -1;
10385 } else if ( dir==-2 )
10386 dir = SplinePointListIsClockwise(spl);
10387 if ( dir==-1 )
10388 self_intersects = 1; /* Sometimes the clockwise test finds intersections the main routine can't */
10389 else {
10390 int subdir = SplinePointListIsClockwise(spl);
10391 if ( subdir==-1 )
10392 self_intersects = 1;
10393 if ( subdir!=dir )
10394 dir = -1;
10395 }
10396 }
10397 }
10398
10399 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
10400 switch ( mi->mid ) {
10401 case CV_MID_FontInfo: case CV_MID_CharInfo: case CV_MID_ShowDependentRefs:
10402 case CV_MID_FindProblems:
10403 case CV_MID_AvailBitmaps:
10404 mi->ti.disabled = cv->b.container!=NULL;
10405 break;
10406 case CV_MID_GetInfo:
10407 {
10408 SplinePoint *sp; SplineSet *spl; RefChar *ref; ImageList *img;
10409 mi->ti.disabled = !CVOneThingSel(cv,&sp,&spl,&ref,&img,&ap,&cp);
10410 }
10411 break;
10412 case CV_MID_CheckSelf:
10413 mi->ti.checked = cv->checkselfintersects;
10414 break;
10415 case CV_MID_GlyphSelfIntersects:
10416 mi->ti.disabled = !cv->checkselfintersects;
10417 mi->ti.checked = self_intersects==1;
10418 break;
10419 case CV_MID_Clockwise:
10420 mi->ti.disabled = !anypoints || dir==2 || dir<0;
10421 mi->ti.checked = dir==1;
10422 break;
10423 case CV_MID_Counter:
10424 mi->ti.disabled = !anypoints || dir==2 || dir<0;
10425 mi->ti.checked = dir==0;
10426 break;
10427 case CV_MID_Correct:
10428 mi->ti.disabled = (cv->b.layerheads[cv->b.drawmode]->splines==NULL && cv->b.layerheads[cv->b.drawmode]->refs==NULL) ||
10429 dir==2 || self_intersects==1;
10430 break;
10431 case CV_MID_ReverseDir:
10432 mi->ti.disabled = !anypoints;
10433 break;
10434 case CV_MID_Stroke:
10435 case CV_MID_RmOverlap:
10436 case CV_MID_Styles:
10437 mi->ti.disabled = cv->b.layerheads[cv->b.drawmode]->splines==NULL ||
10438 cv->b.container!=NULL;
10439 break;
10440 #ifdef FONTFORGE_CONFIG_TILEPATH
10441 case CV_MID_TilePath:
10442 mi->ti.disabled = badsel;
10443 break;
10444 #endif
10445 case CV_MID_RegenBitmaps: case CV_MID_RemoveBitmaps:
10446 mi->ti.disabled = cv->b.fv->sf->bitmaps==NULL;
10447 break;
10448 case CV_MID_AddExtrema: case CV_MID_AddInflections: case CV_MID_Harmonize:
10449 mi->ti.disabled = cv->b.layerheads[cv->b.drawmode]->splines==NULL || (cv->b.sc->inspiro && hasspiro());
10450 /* Like Simplify, always available, but may not do anything if */
10451 /* all extrema have points. I'm not going to check for that, too hard */
10452 break;
10453 case CV_MID_Balance:
10454 mi->ti.disabled = cv->b.layerheads[cv->b.drawmode]->splines==NULL || (cv->b.sc->inspiro && hasspiro())
10455 || cv->b.layerheads[cv->b.drawmode]->order2;
10456 break;
10457 case CV_MID_Simplify:
10458 mi->ti.disabled = cv->b.layerheads[cv->b.drawmode]->splines==NULL || (cv->b.sc->inspiro && hasspiro());
10459 /* Simplify is always available (it may not do anything though) */
10460 /* well, ok. Disable it if there is absolutely nothing to work on */
10461 break;
10462 case CV_MID_BuildAccent:
10463 mi->ti.disabled = !SFIsSomethingBuildable(cv->b.fv->sf,cv->b.sc,
10464 CVLayer((CharViewBase *) cv),false);
10465 break;
10466 case CV_MID_Autotrace:
10467 mi->ti.disabled = FindAutoTraceName()==NULL || cv->b.sc->layers[ly_back].images==NULL;
10468 break;
10469 case CV_MID_Align:
10470 mi->ti.disabled = cv->b.sc->inspiro && hasspiro();
10471 break;
10472 }
10473 }
10474 }
10475
10476 static void ellistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
10477 CharView *cv = (CharView *) GDrawGetUserData(gw);
10478 cv_ellistcheck(cv, mi);
10479 }
10480
10481 static void CVMenuAutoHint(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10482 CharView *cv = (CharView *) GDrawGetUserData(gw);
10483 /*int removeOverlap = e==NULL || !(e->u.mouse.state&ksm_shift);*/
10484 int was = cv->b.sc->changedsincelasthinted;
10485
10486 /* Hint undoes are done in _SplineCharAutoHint */
10487 cv->b.sc->manualhints = false;
10488 SplineCharAutoHint(cv->b.sc,CVLayer((CharViewBase *) cv),NULL);
10489 SCUpdateAll(cv->b.sc);
10490 if ( was ) {
10491 FontView *fvs;
10492 for ( fvs=(FontView *) (cv->b.fv); fvs!=NULL; fvs=(FontView *) (fvs->b.nextsame) )
10493 GDrawRequestExpose(fvs->v,NULL,false); /* Clear any changedsincelasthinted marks */
10494 }
10495 }
10496
10497 static void CVMenuAutoHintSubs(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10498 CharView *cv = (CharView *) GDrawGetUserData(gw);
10499 SCFigureHintMasks(cv->b.sc,CVLayer((CharViewBase *) cv));
10500 SCUpdateAll(cv->b.sc);
10501 }
10502
10503 static void CVMenuAutoCounter(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10504 CharView *cv = (CharView *) GDrawGetUserData(gw);
10505 SCFigureCounterMasks(cv->b.sc);
10506 }
10507
10508 static void CVMenuDontAutoHint(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10509 CharView *cv = (CharView *) GDrawGetUserData(gw);
10510 cv->b.sc->manualhints = !cv->b.sc->manualhints;
10511 }
10512
10513 static void CVMenuNowakAutoInstr(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10514 CharView *cv = (CharView *) GDrawGetUserData(gw);
10515 SplineChar *sc = cv->b.sc;
10516 GlobalInstrCt gic;
10517
10518 if ( cv->b.layerheads[cv->b.drawmode]->splines!=NULL && sc->hstem==NULL && sc->vstem==NULL
10519 && sc->dstem==NULL && !no_windowing_ui )
10520 ff_post_notice(_("Things could be better..."), _("Glyph, %s, has no hints. FontForge will not produce many instructions."),
10521 sc->name );
10522
10523 InitGlobalInstrCt(&gic, sc->parent, CVLayer((CharViewBase *) cv), NULL);
10524 NowakowskiSCAutoInstr(&gic, sc);
10525 FreeGlobalInstrCt(&gic);
10526 SCUpdateAll(sc);
10527 }
10528
10529 static void CVMenuClearHints(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
10530 CharView *cv = (CharView *) GDrawGetUserData(gw);
10531
10532 SCPreserveHints(cv->b.sc,CVLayer((CharViewBase *) cv));
10533 SCHintsChanged(cv->b.sc);
10534 if ( mi->mid==CV_MID_ClearHStem ) {
10535 StemInfosFree(cv->b.sc->hstem);
10536 cv->b.sc->hstem = NULL;
10537 cv->b.sc->hconflicts = false;
10538 } else if ( mi->mid==CV_MID_ClearVStem ) {
10539 StemInfosFree(cv->b.sc->vstem);
10540 cv->b.sc->vstem = NULL;
10541 cv->b.sc->vconflicts = false;
10542 } else if ( mi->mid==CV_MID_ClearDStem ) {
10543 DStemInfosFree(cv->b.sc->dstem);
10544 cv->b.sc->dstem = NULL;
10545 }
10546 cv->b.sc->manualhints = true;
10547
10548 if ( mi->mid != CV_MID_ClearDStem ) {
10549 SCClearHintMasks(cv->b.sc,CVLayer((CharViewBase *) cv),true);
10550 }
10551 SCUpdateAll(cv->b.sc);
10552 }
10553
10554 /* This is an improved version of the older CVTwoForePointsSelected function. */
10555 /* Unlike the former, it doesn't just check if there are exactly two points */
10556 /* selected, but rather returns the number of selected points (whatever this */
10557 /* number can be) and puts references to those points into an array. It is up */
10558 /* to the calling code to see if the returned result is satisfiable (there */
10559 /* should be exactly two points selected for specifying a vertical or */
10560 /* horizontal stem and four points for a diagonal stem). */
10561 static int CVNumForePointsSelected(CharView *cv, BasePoint **bp) {
10562 SplineSet *spl;
10563 SplinePoint *test, *first;
10564 BasePoint *bps[5];
10565 int i, cnt;
10566
10567 if ( cv->b.drawmode!=dm_fore )
10568 return( 0 ) ;
10569 cnt = 0;
10570 for ( spl = cv->b.sc->layers[ly_fore].splines; spl!=NULL; spl = spl->next ) {
10571 first = NULL;
10572 for ( test = spl->first; test!=first; test = test->next->to ) {
10573 if ( test->selected ) {
10574 bps[cnt++] = &(test->me);
10575 if ( cnt>4 )
10576 return( 0 );
10577 }
10578 if ( first == NULL ) first = test;
10579 if ( test->next==NULL )
10580 break;
10581 }
10582 }
10583 for (i=0; i<cnt; i++) {
10584 bp[i] = bps[i];
10585 }
10586 return( cnt );
10587 }
10588
10589 static void CVMenuAddHint(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
10590 CharView *cv = (CharView *) GDrawGetUserData(gw);
10591 BasePoint *bp[4], unit;
10592 StemInfo *h=NULL;
10593 DStemInfo *d;
10594 int num;
10595 int layer = CVLayer((CharViewBase *) cv);
10596
10597 num = CVNumForePointsSelected( cv,bp );
10598
10599 /* We need exactly 2 points to specify a horizontal or vertical stem */
10600 /* and exactly 4 points to specify a diagonal stem */
10601 if ( !(num == 2 && mi->mid != CV_MID_AddDHint) &&
10602 !(num == 4 && mi->mid == CV_MID_AddDHint))
10603 return;
10604
10605 SCPreserveHints(cv->b.sc,CVLayer((CharViewBase *) cv));
10606 SCHintsChanged(cv->b.sc);
10607 if ( mi->mid==CV_MID_AddHHint ) {
10608 if ( bp[0]->y==bp[1]->y )
10609 return;
10610 h = chunkalloc(sizeof(StemInfo));
10611 if ( bp[1]->y>bp[0]->y ) {
10612 h->start = bp[0]->y;
10613 h->width = bp[1]->y-bp[0]->y;
10614 } else {
10615 h->start = bp[1]->y;
10616 h->width = bp[0]->y-bp[1]->y;
10617 }
10618 SCGuessHHintInstancesAndAdd(cv->b.sc,layer,h,bp[0]->x,bp[1]->x);
10619 cv->b.sc->hconflicts = StemListAnyConflicts(cv->b.sc->hstem);
10620 } else if ( mi->mid==CV_MID_AddVHint ) {
10621 if ( bp[0]->x==bp[1]->x )
10622 return;
10623 h = chunkalloc(sizeof(StemInfo));
10624 if ( bp[1]->x>bp[0]->x ) {
10625 h->start = bp[0]->x;
10626 h->width = bp[1]->x-bp[0]->x;
10627 } else {
10628 h->start = bp[1]->x;
10629 h->width = bp[0]->x-bp[1]->x;
10630 }
10631 SCGuessVHintInstancesAndAdd(cv->b.sc,layer,h,bp[0]->y,bp[1]->y);
10632 cv->b.sc->vconflicts = StemListAnyConflicts(cv->b.sc->vstem);
10633 } else {
10634 if ( !PointsDiagonalable( cv->b.sc->parent,bp,&unit ))
10635 return;
10636 /* No additional tests, as the points should have already been */
10637 /* reordered by PointsDiagonalable */
10638 d = chunkalloc(sizeof(DStemInfo));
10639 d->where = NULL;
10640 d->left = *bp[0];
10641 d->right = *bp[1];
10642 d->unit = unit;
10643 SCGuessDHintInstances( cv->b.sc,layer,d );
10644 if ( d->where == NULL )
10645 DStemInfoFree( d );
10646 else
10647 MergeDStemInfo( cv->b.sc->parent,&cv->b.sc->dstem,d );
10648 }
10649 cv->b.sc->manualhints = true;
10650
10651 /* Hint Masks are not relevant for diagonal stems, so modifying */
10652 /* diagonal stems should not affect them */
10653 if ( (mi->mid==CV_MID_AddVHint) || (mi->mid==CV_MID_AddHHint) ) {
10654 if ( h!=NULL && cv->b.sc->parent->mm==NULL )
10655 SCModifyHintMasksAdd(cv->b.sc,layer,h);
10656 else
10657 SCClearHintMasks(cv->b.sc,layer,true);
10658 }
10659 SCUpdateAll(cv->b.sc);
10660 }
10661
10662 static void CVMenuCreateHint(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
10663 CharView *cv = (CharView *) GDrawGetUserData(gw);
10664 CVCreateHint(cv,mi->mid==CV_MID_CreateHHint,true);
10665 }
10666
10667 static void CVMenuReviewHints(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
10668 CharView *cv = (CharView *) GDrawGetUserData(gw);
10669
10670 if ( cv->b.sc->hstem==NULL && cv->b.sc->vstem==NULL )
10671 return;
10672 CVReviewHints(cv);
10673 }
10674
10675 static void htlistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
10676 CharView *cv = (CharView *) GDrawGetUserData(gw);
10677 int cvlayer = CVLayer((CharViewBase *) cv);
10678 BasePoint *bp[4], unit;
10679 int multilayer = cv->b.sc->parent->multilayer;
10680 int i=0, num = 0;
10681
10682 for (i=0; i<4; i++) {bp[i]=NULL;}
10683
10684 num = CVNumForePointsSelected(cv,bp);
10685
10686 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
10687 switch ( mi->mid ) {
10688 case CV_MID_AutoHint:
10689 mi->ti.disabled = cvlayer == ly_grid || multilayer;
10690 break;
10691 case CV_MID_HintSubsPt:
10692 mi->ti.disabled = multilayer ||
10693 cv->b.layerheads[cv->b.drawmode]->order2 ||
10694 cvlayer == ly_grid;
10695 break;
10696 case CV_MID_AutoCounter:
10697 mi->ti.disabled = multilayer;
10698 break;
10699 case CV_MID_DontAutoHint:
10700 mi->ti.disabled = cv->b.layerheads[cv->b.drawmode]->order2 || multilayer;
10701 mi->ti.checked = cv->b.sc->manualhints;
10702 break;
10703 case CV_MID_AutoInstr:
10704 case CV_MID_EditInstructions:
10705 mi->ti.disabled = multilayer ||
10706 !cv->b.layerheads[cv->b.drawmode]->order2 ||
10707 cvlayer == ly_grid;
10708 break;
10709 case CV_MID_Debug:
10710 mi->ti.disabled = multilayer ||
10711 !cv->b.layerheads[cv->b.drawmode]->order2 ||
10712 !hasFreeTypeDebugger();
10713 break;
10714 case CV_MID_Deltas:
10715 mi->ti.disabled = multilayer ||
10716 !cv->b.layerheads[cv->b.drawmode]->order2 ||
10717 !hasFreeTypeDebugger();
10718 break;
10719 case CV_MID_ClearHStem:
10720 case CV_MID_ClearVStem:
10721 case CV_MID_ClearDStem:
10722 mi->ti.disabled = cvlayer == ly_grid;
10723 break;
10724 case CV_MID_ClearInstr:
10725 mi->ti.disabled = cv->b.sc->ttf_instrs_len==0;
10726 break;
10727 case CV_MID_AddHHint:
10728 mi->ti.disabled = num != 2 || bp[1]->y==bp[0]->y || multilayer;
10729 break;
10730 case CV_MID_AddVHint:
10731 mi->ti.disabled = num != 2 || bp[1]->x==bp[0]->x || multilayer;
10732 break;
10733 case CV_MID_AddDHint:
10734 mi->ti.disabled = num != 4 || !PointsDiagonalable( cv->b.sc->parent,bp,&unit ) || multilayer;
10735 break;
10736 case CV_MID_CreateHHint:
10737 case CV_MID_CreateVHint:
10738 mi->ti.disabled = cvlayer == ly_grid;
10739 break;
10740 case CV_MID_ReviewHints:
10741 mi->ti.disabled = (cv->b.sc->hstem==NULL && cv->b.sc->vstem==NULL ) || multilayer;
10742 break;
10743 }
10744 }
10745 }
10746
10747 static void mtlistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
10748 CharView *cv = (CharView *) GDrawGetUserData(gw);
10749 RefChar *r = HasUseMyMetrics(cv->b.sc,CVLayer((CharViewBase *) cv));
10750
10751 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
10752 switch ( mi->mid ) {
10753 case CV_MID_RemoveKerns:
10754 mi->ti.disabled = cv->b.sc->kerns==NULL;
10755 break;
10756 case CV_MID_RemoveVKerns:
10757 mi->ti.disabled = cv->b.sc->vkerns==NULL;
10758 break;
10759 case CV_MID_SetVWidth:
10760 mi->ti.disabled = !cv->b.sc->parent->hasvmetrics || r!=NULL;
10761 break;
10762 case CV_MID_AnchorsAway:
10763 mi->ti.disabled = cv->b.sc->anchor==NULL;
10764 break;
10765 case CV_MID_SetWidth: case CV_MID_SetLBearing: case CV_MID_SetRBearing: case CV_MID_SetBearings:
10766 mi->ti.disabled = r!=NULL;
10767 break;
10768 }
10769 }
10770 }
10771
10772 static void cv_sllistcheck(CharView *cv, struct gmenuitem *mi) {
10773 SplinePoint *sp; SplineSet *spl; RefChar *r; ImageList *im;
10774 spiro_cp *scp;
10775 SplineSet *test;
10776 int exactlyone = CVOneThingSel(cv,&sp,&spl,&r,&im,NULL,&scp);
10777
10778 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
10779 switch ( mi->mid ) {
10780 case CV_MID_NextCP: case CV_MID_PrevCP:
10781 mi->ti.disabled = !exactlyone || sp==NULL || (cv->b.sc->inspiro && hasspiro());
10782 break;
10783 case CV_MID_NextPt: case CV_MID_PrevPt:
10784 case CV_MID_FirstPtNextCont:
10785 mi->ti.disabled = !exactlyone || (sp==NULL && scp==NULL);
10786 break;
10787 case CV_MID_FirstPt: case CV_MID_SelPointAt:
10788 mi->ti.disabled = cv->b.layerheads[cv->b.drawmode]->splines==NULL;
10789 break;
10790 case CV_MID_Contours:
10791 mi->ti.disabled = !CVAnySelPoints(cv);
10792 break;
10793 case CV_MID_SelectOpenContours:
10794 mi->ti.disabled = true;
10795 for ( test=cv->b.layerheads[cv->b.drawmode]->splines; test!=NULL; test=test->next ) {
10796 if ( test->first->prev==NULL ) {
10797 mi->ti.disabled = false;
10798 break;
10799 }
10800 }
10801 break;
10802 case CV_MID_SelectWidth:
10803 mi->ti.disabled = !cv->showhmetrics;
10804 if ( HasUseMyMetrics(cv->b.sc,CVLayer((CharViewBase *) cv))!=NULL )
10805 mi->ti.disabled = true;
10806 if ( !mi->ti.disabled ) {
10807 free(mi->ti.text);
10808 mi->ti.text = utf82u_copy(cv->widthsel?_("Deselect Width"):_("Width"));
10809 }
10810 break;
10811 case CV_MID_SelectVWidth:
10812 mi->ti.disabled = !cv->showvmetrics || !cv->b.sc->parent->hasvmetrics;
10813 if ( HasUseMyMetrics(cv->b.sc,CVLayer((CharViewBase *) cv))!=NULL )
10814 mi->ti.disabled = true;
10815 if ( !mi->ti.disabled ) {
10816 free(mi->ti.text);
10817 mi->ti.text = utf82u_copy(cv->vwidthsel?_("Deselect VWidth"):_("VWidth"));
10818 }
10819 break;
10820 case CV_MID_SelectHM:
10821 mi->ti.disabled = !exactlyone || sp==NULL || sp->hintmask==NULL;
10822 break;
10823 }
10824 }
10825 }
10826
10827 static void sllistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
10828 CharView *cv = (CharView *) GDrawGetUserData(gw);
10829 cv_sllistcheck(cv, mi);
10830 }
10831
10832 static void cv_cblistcheck(CharView *cv, struct gmenuitem *mi) {
10833 int i;
10834 KernPair *kp;
10835 SplineChar *sc = cv->b.sc;
10836 SplineFont *sf = sc->parent;
10837 PST *pst;
10838 char *name;
10839
10840 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
10841 switch ( mi->mid ) {
10842 case CV_MID_AnchorPairs:
10843 mi->ti.disabled = sc->anchor==NULL;
10844 break;
10845 case CV_MID_AnchorControl:
10846 mi->ti.disabled = sc->anchor==NULL;
10847 break;
10848 case CV_MID_AnchorGlyph:
10849 if ( cv->apmine!=NULL )
10850 mi->ti.disabled = false;
10851 else
10852 mi->ti.disabled = sc->anchor==NULL;
10853 break;
10854 case CV_MID_KernPairs:
10855 mi->ti.disabled = sc->kerns==NULL;
10856 if ( sc->kerns==NULL ) {
10857 for ( i=0; i<sf->glyphcnt; ++i ) if ( sf->glyphs[i]!=NULL ) {
10858 for ( kp = sf->glyphs[i]->kerns; kp!=NULL; kp=kp->next ) {
10859 if ( kp->sc == sc ) {
10860 mi->ti.disabled = false;
10861 goto out;
10862 }
10863 }
10864 }
10865 out:;
10866 }
10867 break;
10868 case CV_MID_Ligatures:
10869 name = sc->name;
10870 for ( i=0; i<sf->glyphcnt; ++i ) if ( sf->glyphs[i]!=NULL ) {
10871 for ( pst=sf->glyphs[i]->possub; pst!=NULL; pst=pst->next ) {
10872 if ( pst->type==pst_ligature &&
10873 PSTContains(pst->u.lig.components,name)) {
10874 mi->ti.disabled = false;
10875 goto break_out_2;
10876 }
10877 }
10878 }
10879 mi->ti.disabled = true;
10880 break_out_2:;
10881 break;
10882 }
10883 }
10884 }
10885
10886 static void cv_nplistcheck(CharView *cv, struct gmenuitem *mi) {
10887 SplineChar *sc = cv->b.sc;
10888 int order2 = cv->b.layerheads[cv->b.drawmode]->order2;
10889 int is_grid_layer = cv->b.drawmode == dm_grid;
10890
10891 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
10892 switch ( mi->mid ) {
10893 case CV_MID_PtsNone:
10894 mi->ti.disabled = !order2 || is_grid_layer;
10895 mi->ti.checked = (cv->showpointnumbers == 0);
10896 break;
10897 case CV_MID_PtsTrue:
10898 mi->ti.disabled = !order2 || is_grid_layer;
10899 mi->ti.checked = cv->showpointnumbers && order2;
10900 break;
10901 case CV_MID_PtsPost:
10902 mi->ti.disabled = order2 || is_grid_layer;
10903 mi->ti.checked = cv->showpointnumbers && !order2 && sc->numberpointsbackards;
10904 break;
10905 case CV_MID_PtsSVG:
10906 mi->ti.disabled = order2 || is_grid_layer;
10907 mi->ti.checked = cv->showpointnumbers && !order2 && !sc->numberpointsbackards;
10908 break;
10909 case CV_MID_PtsPos:
10910 mi->ti.disabled = is_grid_layer;
10911 mi->ti.checked = (cv->showpointnumbers == 2);
10912 }
10913 }
10914 }
10915
10916 static void gflistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
10917 CharView *cv = (CharView *) GDrawGetUserData(gw);
10918
10919 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
10920 switch ( mi->mid ) {
10921 case CV_MID_ShowGridFit:
10922 mi->ti.disabled = !hasFreeType() || cv->dv!=NULL;
10923 mi->ti.checked = cv->show_ft_results;
10924 break;
10925 case CV_MID_ShowGridFitLiveUpdate:
10926 mi->ti.disabled = !hasFreeType() || cv->dv!=NULL;
10927 mi->ti.checked = cv->show_ft_results_live_update;
10928 break;
10929 case CV_MID_Bigger:
10930 mi->ti.disabled = !cv->show_ft_results;
10931 break;
10932 case CV_MID_Smaller:
10933 mi->ti.disabled = !cv->show_ft_results || cv->ft_pointsizex<2 || cv->ft_pointsizey<2;
10934 break;
10935 case CV_MID_GridFitAA:
10936 mi->ti.disabled = !cv->show_ft_results;
10937 mi->ti.checked = cv->ft_depth==8;
10938 break;
10939 case CV_MID_GridFitOff:
10940 mi->ti.disabled = !cv->show_ft_results;
10941 break;
10942 }
10943 }
10944 }
10945
10946 static void swlistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
10947 CharView *cv = (CharView *) GDrawGetUserData(gw);
10948 SplineFont *sf = cv->b.sc->parent;
10949
10950 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
10951 switch ( mi->mid ) {
10952 case CV_MID_MarkExtrema:
10953 mi->ti.checked = cv->markextrema;
10954 mi->ti.disabled = cv->b.sc->inspiro && hasspiro();
10955 break;
10956 case CV_MID_MarkPointsOfInflection:
10957 mi->ti.checked = cv->markpoi;
10958 mi->ti.disabled = cv->b.sc->inspiro && hasspiro();
10959 break;
10960 case CV_MID_ShowAlmostHV:
10961 mi->ti.checked = cv->showalmosthvlines;
10962 break;
10963 case CV_MID_ShowAlmostHVCurves:
10964 mi->ti.checked = cv->showalmosthvcurves;
10965 break;
10966 case CV_MID_DefineAlmost:
10967 mi->ti.disabled = !cv->showalmosthvlines && !cv->showalmosthvcurves;
10968 break;
10969 case CV_MID_ShowCPInfo:
10970 mi->ti.checked = cv->showcpinfo;
10971 break;
10972 case CV_MID_DraggingComparisonOutline:
10973 mi->ti.checked = prefs_create_dragging_comparison_outline;
10974 break;
10975 case CV_MID_ShowSideBearings:
10976 mi->ti.checked = cv->showsidebearings;
10977 break;
10978 case CV_MID_ShowRefNames:
10979 mi->ti.checked = cv->showrefnames;
10980 break;
10981 case CV_MID_ShowTabs:
10982 mi->ti.checked = cv->showtabs;
10983 mi->ti.disabled = cv->former_cnt<=1;
10984 break;
10985 case CV_MID_HidePoints:
10986 mi->ti.checked = cv->showpoints;
10987 break;
10988 case CV_MID_HideControlPoints:
10989 mi->ti.checked = cv->alwaysshowcontrolpoints;
10990 break;
10991 case CV_MID_HideRulers:
10992 mi->ti.checked = cv->showrulers;
10993 break;
10994 case CV_MID_Fill:
10995 mi->ti.checked = cv->showfilled;
10996 break;
10997 case CV_MID_ShowHHints:
10998 mi->ti.checked = cv->showhhints;
10999 mi->ti.disabled = sf->multilayer;
11000 break;
11001 case CV_MID_ShowVHints:
11002 mi->ti.checked = cv->showvhints;
11003 mi->ti.disabled = sf->multilayer;
11004 break;
11005 case CV_MID_ShowDHints:
11006 mi->ti.checked = cv->showdhints;
11007 mi->ti.disabled = sf->multilayer;
11008 break;
11009 case CV_MID_ShowBlueValues:
11010 mi->ti.checked = cv->showblues;
11011 mi->ti.disabled = sf->multilayer;
11012 break;
11013 case CV_MID_ShowFamilyBlues:
11014 mi->ti.checked = cv->showfamilyblues;
11015 mi->ti.disabled = sf->multilayer;
11016 break;
11017 case CV_MID_ShowAnchors:
11018 mi->ti.checked = cv->showanchor;
11019 mi->ti.disabled = sf->multilayer;
11020 break;
11021 case CV_MID_ShowHMetrics:
11022 mi->ti.checked = cv->showhmetrics;
11023 break;
11024 case CV_MID_ShowVMetrics:
11025 mi->ti.checked = cv->showvmetrics;
11026 mi->ti.disabled = !sf->hasvmetrics;
11027 break;
11028 case CV_MID_ShowDebugChanges:
11029 mi->ti.checked = cv->showdebugchanges;
11030 break;
11031 case CV_MID_SnapOutlines:
11032 mi->ti.checked = cv->snapoutlines;
11033 mi->ti.disabled = false;
11034 break;
11035 }
11036 }
11037 }
11038
11039 static void cv_vwlistcheck(CharView *cv, struct gmenuitem *mi) {
11040 int pos, gid;
11041 SplineFont *sf = cv->b.sc->parent;
11042 EncMap *map = cv->b.fv->map;
11043
11044 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
11045 switch ( mi->mid ) {
11046 case CV_MID_NextDef:
11047 if ( cv->b.container==NULL ) {
11048 for ( pos = CVCurEnc(cv)+1; pos<map->enccount && ((gid=map->map[pos])==-1 || !SCWorthOutputting(sf->glyphs[gid])); ++pos );
11049 mi->ti.disabled = pos==map->enccount;
11050 } else
11051 mi->ti.disabled = !(cv->b.container->funcs->canNavigate)(cv->b.container,nt_nextdef);
11052 break;
11053 case CV_MID_PrevDef:
11054 if ( cv->b.container==NULL ) {
11055 for ( pos = CVCurEnc(cv)-1; pos>=0 && ((gid=map->map[pos])==-1 || !SCWorthOutputting(sf->glyphs[gid])); --pos );
11056 mi->ti.disabled = pos<0 || cv->b.container!=NULL;
11057 } else
11058 mi->ti.disabled = !(cv->b.container->funcs->canNavigate)(cv->b.container,nt_nextdef);
11059 break;
11060 case CV_MID_Next:
11061 mi->ti.disabled = cv->b.container==NULL ? CVCurEnc(cv)==map->enccount-1 : !(cv->b.container->funcs->canNavigate)(cv->b.container,nt_nextdef);
11062 break;
11063 case CV_MID_Prev:
11064 mi->ti.disabled = cv->b.container==NULL ? CVCurEnc(cv)==0 : !(cv->b.container->funcs->canNavigate)(cv->b.container,nt_nextdef);
11065 break;
11066 case CV_MID_Former:
11067 if ( cv->former_cnt<=1 )
11068 pos = -1;
11069 else for ( pos = sf->glyphcnt-1; pos>=0 ; --pos )
11070 if ( sf->glyphs[pos]!=NULL && strcmp(sf->glyphs[pos]->name,cv->former_names[1])==0 )
11071 break;
11072 mi->ti.disabled = pos==-1 || cv->b.container!=NULL;
11073 break;
11074 case CV_MID_Goto:
11075 mi->ti.disabled = cv->b.container!=NULL && !(cv->b.container->funcs->canNavigate)(cv->b.container,nt_goto);
11076 break;
11077 case CV_MID_FindInFontView:
11078 mi->ti.disabled = cv->b.container!=NULL;
11079 break;
11080 #if HANYANG
11081 case CV_MID_DisplayCompositions:
11082 mi->ti.disabled = !cv->b.sc->compositionunit || cv->b.sc->parent->rules==NULL;
11083 break;
11084 #endif
11085 }
11086 }
11087 }
11088
11089 static void cblistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11090 CharView *cv = (CharView *) GDrawGetUserData(gw);
11091 cv_cblistcheck(cv, mi);
11092 }
11093
11094 static void nplistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11095 CharView *cv = (CharView *) GDrawGetUserData(gw);
11096 cv_nplistcheck(cv, mi);
11097 }
11098
11099 static void vwlistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11100 CharView *cv = (CharView *) GDrawGetUserData(gw);
11101 cv_vwlistcheck(cv, mi);
11102 }
11103
11104 static void CVMenuCenter(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11105 CharView *cv = (CharView *) GDrawGetUserData(gw);
11106 DBounds bb;
11107 real transform[6];
11108 int drawmode = cv->b.drawmode;
11109
11110 cv->b.drawmode = dm_fore;
11111
11112 memset(transform,0,sizeof(transform));
11113 transform[0] = transform[3] = 1.0;
11114 transform[1] = transform[2] = transform[5] = 0.0;
11115 if ( cv->b.sc->parent->italicangle==0 )
11116 SplineCharFindBounds(cv->b.sc,&bb);
11117 else {
11118 SplineSet *base, *temp;
11119 base = LayerAllSplines(cv->b.layerheads[cv->b.drawmode]);
11120 transform[2] = tan( cv->b.sc->parent->italicangle * FF_PI/180.0 );
11121 temp = SplinePointListTransform(SplinePointListCopy(base),transform,tpt_AllPoints);
11122 transform[2] = 0;
11123 LayerUnAllSplines(cv->b.layerheads[cv->b.drawmode]);
11124 SplineSetFindBounds(temp,&bb);
11125 SplinePointListsFree(temp);
11126 }
11127
11128 if ( mi->mid==CV_MID_Center )
11129 transform[4] = (cv->b.sc->width-(bb.maxx-bb.minx))/2 - bb.minx;
11130 else
11131 transform[4] = (cv->b.sc->width-(bb.maxx-bb.minx))/3 - bb.minx;
11132 if ( transform[4]!=0 ) {
11133 cv->p.transany = false;
11134 CVPreserveState(&cv->b);
11135 CVTransFuncAllLayers(cv, transform, fvt_dontmovewidth );
11136 CVCharChangedUpdate(&cv->b);
11137 }
11138 cv->b.drawmode = drawmode;
11139 }
11140
11141 static void CVMenuSetWidth(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11142 CharView *cv = (CharView *) GDrawGetUserData(gw);
11143
11144 if ( mi->mid == CV_MID_SetVWidth && !cv->b.sc->parent->hasvmetrics )
11145 return;
11146 CVSetWidth(cv,mi->mid==CV_MID_SetWidth?wt_width:
11147 mi->mid==CV_MID_SetLBearing?wt_lbearing:
11148 mi->mid==CV_MID_SetRBearing?wt_rbearing:
11149 mi->mid==CV_MID_SetBearings?wt_bearings:
11150 wt_vwidth);
11151 }
11152
11153 static void CVMenuRemoveKern(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
11154 CharView *cv = (CharView *) GDrawGetUserData(gw);
11155 SCRemoveKern(cv->b.sc);
11156 }
11157
11158 static void CVMenuRemoveVKern(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
11159 CharView *cv = (CharView *) GDrawGetUserData(gw);
11160 SCRemoveVKern(cv->b.sc);
11161 }
11162
11163 static void CVMenuKPCloseup(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
11164 CharView *cv = (CharView *) GDrawGetUserData(gw);
11165 KernPairD(cv->b.sc->parent,cv->b.sc,NULL,CVLayer((CharViewBase *) cv),false);
11166 }
11167
11168 static void CVMenuAnchorsAway(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11169 CharView *cv = (CharView *) GDrawGetUserData(gw);
11170 AnchorPoint *ap;
11171
11172 ap = mi->ti.userdata;
11173 if ( ap==NULL )
11174 for ( ap = cv->b.sc->anchor; ap!=NULL && !ap->selected; ap = ap->next );
11175 if ( ap==NULL ) ap= cv->b.sc->anchor;
11176 if ( ap==NULL )
11177 return;
11178
11179 GDrawSetCursor(cv->v,ct_watch);
11180 GDrawSync(NULL);
11181 GDrawProcessPendingEvents(NULL);
11182 AnchorControl(cv->b.sc,ap,CVLayer((CharViewBase *) cv));
11183 GDrawSetCursor(cv->v,ct_pointer);
11184 }
11185
11186 static GMenuItem2 wnmenu[] = {
11187 { { (unichar_t *) N_("New O_utline Window"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 1, 0, 0, 0, 0, 0, 1, 1, 0, 'u' }, H_("New Outline Window|No Shortcut"), NULL, NULL, /* No function, never avail */NULL, 0 },
11188 { { (unichar_t *) N_("New _Bitmap Window"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'B' }, H_("New Bitmap Window|No Shortcut"), NULL, NULL, CVMenuOpenBitmap, CV_MID_OpenBitmap },
11189 { { (unichar_t *) N_("New _Metrics Window"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("New Metrics Window|No Shortcut"), NULL, NULL, CVMenuOpenMetrics, 0 },
11190 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11191 { { (unichar_t *) N_("Warnings"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Warnings|No Shortcut"), NULL, NULL, _MenuWarnings, CV_MID_Warnings },
11192 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11193 GMENUITEM2_EMPTY
11194 };
11195
11196 static void CVWindowMenuBuild(GWindow gw, struct gmenuitem *mi, GEvent *e) {
11197 CharView *cv = (CharView *) GDrawGetUserData(gw);
11198 struct gmenuitem *wmi;
11199
11200 WindowMenuBuild(gw,mi,e);
11201 for ( wmi = mi->sub; wmi->ti.text!=NULL || wmi->ti.line ; ++wmi ) {
11202 switch ( wmi->mid ) {
11203 case CV_MID_OpenBitmap:
11204 wmi->ti.disabled = cv->b.sc->parent->bitmaps==NULL;
11205 break;
11206 case CV_MID_Warnings:
11207 wmi->ti.disabled = ErrorWindowExists();
11208 break;
11209 }
11210 }
11211 if ( cv->b.container!=NULL ) {
11212 int canopen = (cv->b.container->funcs->canOpen)(cv->b.container);
11213 if ( !canopen ) {
11214 for ( wmi = mi->sub; wmi->ti.text!=NULL || wmi->ti.line ; ++wmi ) {
11215 wmi->ti.disabled = true;
11216 }
11217 }
11218 }
11219 }
11220
11221 static GMenuItem2 dummyitem[] = {
11222 { { (unichar_t *) N_("Font|_New"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'N' }, NULL, NULL, NULL, NULL, 0 },
11223 GMENUITEM2_EMPTY
11224 };
11225 static GMenuItem2 fllist[] = {
11226 { { (unichar_t *) N_("Font|_New"), (GImage *) "filenew.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'N' }, H_("New|No Shortcut"), NULL, NULL, MenuNew, CV_MID_New },
11227 { { (unichar_t *) N_("_Open"), (GImage *) "fileopen.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'O' }, H_("Open|No Shortcut"), NULL, NULL, CVMenuOpen, CV_MID_Open },
11228 { { (unichar_t *) N_("Recen_t"), (GImage *) "filerecent.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 't' }, NULL, dummyitem, MenuRecentBuild, NULL, CV_MID_Recent },
11229 { { (unichar_t *) N_("_Close"), (GImage *) "fileclose.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'C' }, H_("Close|No Shortcut"), NULL, NULL, CVMenuClose, CV_MID_Close },
11230 { { (unichar_t *) N_("C_lose Tab"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'C' }, H_("Close Tab|No Shortcut"), NULL, NULL, CVMenuCloseTab, CV_MID_CloseTab },
11231 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11232 { { (unichar_t *) N_("_Save"), (GImage *) "filesave.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'S' }, H_("Save|No Shortcut"), NULL, NULL, CVMenuSave, 0 },
11233 { { (unichar_t *) N_("S_ave as..."), (GImage *) "filesaveas.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'a' }, H_("Save as...|No Shortcut"), NULL, NULL, CVMenuSaveAs, 0 },
11234 { { (unichar_t *) N_("_Generate Fonts..."), (GImage *) "filegenerate.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'G' }, H_("Generate Fonts...|No Shortcut"), NULL, NULL, CVMenuGenerate, 0 },
11235 { { (unichar_t *) N_("Generate Mac _Family..."), (GImage *) "filegeneratefamily.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("Generate Mac Family...|No Shortcut"), NULL, NULL, CVMenuGenerateFamily, 0 },
11236 { { (unichar_t *) N_("Generate TTC..."), (GImage *) "filegeneratefamily.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("Generate TTC...|No Shortcut"), NULL, NULL, CVMenuGenerateTTC, CV_MID_GenerateTTC },
11237 { { (unichar_t *) N_("E_xport..."), (GImage *) "fileexport.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 't' }, H_("Export...|No Shortcut"), NULL, NULL, CVMenuExport, 0 },
11238 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11239 { { (unichar_t *) N_("_Import..."), (GImage *) "fileimport.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'I' }, H_("Import...|No Shortcut"), NULL, NULL, CVMenuImport, 0 },
11240 { { (unichar_t *) N_("_Revert File"), (GImage *) "filerevert.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'R' }, H_("Revert File|No Shortcut"), NULL, NULL, CVMenuRevert, CV_MID_Revert },
11241 { { (unichar_t *) N_("Revert Gl_yph"), (GImage *) "filerevertglyph.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'R' }, H_("Revert Glyph|No Shortcut"), NULL, NULL, CVMenuRevertGlyph, CV_MID_RevertGlyph },
11242 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11243 { { (unichar_t *) N_("Load Word List..."), (GImage *) 0, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Load Word List...|No Shortcut"), NULL, NULL, CVAddWordList, 0 },
11244 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11245 { { (unichar_t *) N_("_Print..."), (GImage *) "fileprint.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Print...|No Shortcut"), NULL, NULL, CVMenuPrint, 0 },
11246 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11247 #if !defined(_NO_PYTHON)
11248 { { (unichar_t *) N_("E_xecute Script..."), (GImage *) "python.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'x' }, H_("Execute Script...|No Shortcut"), NULL, NULL, CVMenuExecute, 0 },
11249 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11250 #endif
11251 { { (unichar_t *) N_("Pr_eferences..."), (GImage *) "fileprefs.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'e' }, H_("Preferences...|No Shortcut"), NULL, NULL, MenuPrefs, 0 },
11252 { { (unichar_t *) N_("Appea_rance Editor..."), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'e' }, H_("Appearance Editor...|No Shortcut"), NULL, NULL, MenuXRes, 0 },
11253 #if !defined(_NO_PYTHON)
11254 { { (unichar_t *) N_("Config_ure Plugins..."), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'u' }, H_("Configure Plugins...|No Shortcut"), NULL, NULL, MenuPlug, 0 },
11255 #endif
11256 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11257 { { (unichar_t *) N_("_Quit"), (GImage *) "filequit.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'Q' }, H_("Quit|No Shortcut"), NULL, NULL, MenuExit, CV_MID_Quit },
11258 GMENUITEM2_EMPTY
11259 };
11260
11261 static GMenuItem2 sllist[] = {
11262 { { (unichar_t *) N_("Select _All"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'A' }, H_("Select All|No Shortcut"), NULL, NULL, CVSelectAll, CV_MID_SelAll },
11263 { { (unichar_t *) N_("_Invert Selection"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'I' }, H_("Invert Selection|No Shortcut"), NULL, NULL, CVSelectInvert, CV_MID_SelInvert },
11264 { { (unichar_t *) N_("_Deselect All"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'o' }, H_("Deselect All|Escape"), NULL, NULL, CVSelectNone, CV_MID_SelNone },
11265 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11266 { { (unichar_t *) N_("_First Point"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("First Point|No Shortcut"), NULL, NULL, CVMenuNextPrevPt, CV_MID_FirstPt },
11267 { { (unichar_t *) N_("First P_oint, Next Contour"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("First Point, Next Contour|No Shortcut"), NULL, NULL, CVMenuNextPrevPt, CV_MID_FirstPtNextCont },
11268 { { (unichar_t *) N_("_Next Point"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'N' }, H_("Next Point|No Shortcut"), NULL, NULL, CVMenuNextPrevPt, CV_MID_NextPt },
11269 { { (unichar_t *) N_("_Prev Point"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Prev Point|No Shortcut"), NULL, NULL, CVMenuNextPrevPt, CV_MID_PrevPt },
11270 { { (unichar_t *) N_("Ne_xt Control Point"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'x' }, H_("Next Control Point|No Shortcut"), NULL, NULL, CVMenuNextPrevCPt, CV_MID_NextCP },
11271 { { (unichar_t *) N_("P_rev Control Point"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'r' }, H_("Prev Control Point|No Shortcut"), NULL, NULL, CVMenuNextPrevCPt, CV_MID_PrevCP },
11272 { { (unichar_t *) N_("Points on Selected _Contours"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'r' }, H_("Points on Selected Contours|No Shortcut"), NULL, NULL, CVMenuSelectContours, CV_MID_Contours },
11273 { { (unichar_t *) N_("Point A_t"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'r' }, H_("Point At|No Shortcut"), NULL, NULL, CVMenuSelectPointAt, CV_MID_SelPointAt },
11274 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11275 { { (unichar_t *) N_("Select All _Points & Refs"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Select All Points & Refs|No Shortcut"), NULL, NULL, CVSelectAll, CV_MID_SelectAllPoints },
11276 { { (unichar_t *) N_("Select Open Contours"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Select Open Contours|No Shortcut"), NULL, NULL, CVSelectOpenContours, CV_MID_SelectOpenContours },
11277 { { (unichar_t *) N_("Select Anc_hors"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'c' }, H_("Select Anchors|No Shortcut"), NULL, NULL, CVSelectAll, CV_MID_SelectAnchors },
11278 { { (unichar_t *) N_("_Width"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, '\0' }, H_("Width|No Shortcut"), NULL, NULL, CVSelectWidth, CV_MID_SelectWidth },
11279 { { (unichar_t *) N_("_VWidth"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, '\0' }, H_("VWidth|No Shortcut"), NULL, NULL, CVSelectVWidth, CV_MID_SelectVWidth },
11280 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11281 { { (unichar_t *) N_("Select Points Affected by HM"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'V' }, H_("Select Points Affected by HM|No Shortcut"), NULL, NULL, CVSelectHM, CV_MID_SelectHM },
11282 GMENUITEM2_EMPTY
11283 };
11284
11285 static GMenuItem2 edlist[] = {
11286 { { (unichar_t *) N_("_Undo"), (GImage *) "editundo.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'U' }, H_("Undo|No Shortcut"), NULL, NULL, CVUndo, CV_MID_Undo },
11287 { { (unichar_t *) N_("_Redo"), (GImage *) "editredo.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'R' }, H_("Redo|No Shortcut"), NULL, NULL, CVRedo, CV_MID_Redo },
11288 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11289 { { (unichar_t *) N_("Cu_t"), (GImage *) "editcut.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 't' }, H_("Cut|No Shortcut"), NULL, NULL, CVCut, CV_MID_Cut },
11290 { { (unichar_t *) N_("_Copy"), (GImage *) "editcopy.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'C' }, H_("Copy|No Shortcut"), NULL, NULL, CVCopy, CV_MID_Copy },
11291 { { (unichar_t *) N_("C_opy Reference"), (GImage *) "editcopyref.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'o' }, H_("Copy Reference|No Shortcut"), NULL, NULL, CVCopyRef, CV_MID_CopyRef },
11292 { { (unichar_t *) N_("Copy Loo_kup Data"), (GImage *) "editcopylookupdata.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'o' }, H_("Copy Lookup Data|No Shortcut"), NULL, NULL, CVCopyLookupData, CV_MID_CopyLookupData },
11293 { { (unichar_t *) N_("Copy _Width"), (GImage *) "editcopywidth.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'W' }, H_("Copy Width|No Shortcut"), NULL, NULL, CVCopyWidth, CV_MID_CopyWidth },
11294 { { (unichar_t *) N_("Co_py LBearing"), (GImage *) "editcopylbearing.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'p' }, H_("Copy LBearing|No Shortcut"), NULL, NULL, CVCopyWidth, CV_MID_CopyLBearing },
11295 { { (unichar_t *) N_("Copy RBearin_g"), (GImage *) "editcopyrbearing.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'g' }, H_("Copy RBearing|No Shortcut"), NULL, NULL, CVCopyWidth, CV_MID_CopyRBearing },
11296 { { (unichar_t *) N_("_Paste"), (GImage *) "editpaste.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Paste|No Shortcut"), NULL, NULL, CVPaste, CV_MID_Paste },
11297 { { (unichar_t *) N_("C_hop"), (GImage *) "editclear.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'h' }, H_("Chop|Delete"), NULL, NULL, CVClear, CV_MID_Clear },
11298 { { (unichar_t *) N_("Clear _Background"), (GImage *) "editclearback.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'B' }, H_("Clear Background|No Shortcut"), NULL, NULL, CVClearBackground, 0 },
11299 { { (unichar_t *) N_("points|_Merge"), (GImage *) "editmerge.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Merge|No Shortcut"), NULL, NULL, CVMerge, CV_MID_Merge },
11300 { { (unichar_t *) N_("points|Merge to Line"), (GImage *) "editmergetoline.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Merge to Line|No Shortcut"), NULL, NULL, CVMergeToLine, CV_MID_MergeToLine },
11301 /*{ { (unichar_t *) N_("_Elide"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Elide|No Shortcut"), NULL, NULL, CVElide, CV_MID_Elide },*/
11302 { { (unichar_t *) N_("_Join"), (GImage *) "editjoin.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'J' }, H_("Join|No Shortcut"), NULL, NULL, CVJoin, CV_MID_Join },
11303 { { (unichar_t *) N_("Copy _Fg To Bg"), (GImage *) "editcopyfg2bg.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("Copy Fg To Bg|No Shortcut"), NULL, NULL, CVCopyFgBg, CV_MID_CopyFgToBg },
11304 { { (unichar_t *) N_("Cop_y Layer To Layer..."), (GImage *) "editcopylayer2layer.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("Copy Layer To Layer...|No Shortcut"), NULL, NULL, CVMenuCopyL2L, CV_MID_CopyBgToFg },
11305 { { (unichar_t *) N_("Copy Gri_d Fit"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, '\0' }, H_("Copy Grid Fit|No Shortcut"), NULL, NULL, CVMenuCopyGridFit, CV_MID_CopyGridFit },
11306 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11307 { { (unichar_t *) N_("_Select"), (GImage *) "editselect.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'S' }, H_("Select|No Shortcut"), sllist, sllistcheck, NULL, 0 },
11308 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11309 { { (unichar_t *) N_("U_nlink Reference"), (GImage *) "editunlink.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'U' }, H_("Unlink Reference|No Shortcut"), NULL, NULL, CVUnlinkRef, CV_MID_UnlinkRef },
11310 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11311 { { (unichar_t *) N_("Remo_ve Undoes..."), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'e' }, H_("Remove Undoes...|No Shortcut"), NULL, NULL, CVRemoveUndoes, CV_MID_RemoveUndoes },
11312 GMENUITEM2_EMPTY
11313 };
11314
11315 static GMenuItem2 ptlist[] = {
11316 { { (unichar_t *) N_("_Curve"), (GImage *) "pointscurve.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'C' }, H_("Curve|No Shortcut"), NULL, NULL, CVMenuPointType, CV_MID_Curve },
11317 { { (unichar_t *) N_("_HVCurve"), (GImage *) "pointshvcurve.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'o' }, H_("HVCurve|No Shortcut"), NULL, NULL, CVMenuPointType, CV_MID_HVCurve },
11318 { { (unichar_t *) N_("C_orner"), (GImage *) "pointscorner.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'o' }, H_("Corner|No Shortcut"), NULL, NULL, CVMenuPointType, CV_MID_Corner },
11319 { { (unichar_t *) N_("_Tangent"), (GImage *) "pointstangent.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Tangent|No Shortcut"), NULL, NULL, CVMenuPointType, CV_MID_Tangent },
11320 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11321 /* GT: Make this (selected) point the first point in the glyph */
11322 { { (unichar_t *) N_("_Make First"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Make First|No Shortcut"), NULL, NULL, CVMenuMakeFirst, CV_MID_MakeFirst },
11323 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11324 { { (unichar_t *) N_("Can Be _Interpolated"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Can Be Interpolated|No Shortcut"), NULL, NULL, CVMenuImplicit, CV_MID_ImplicitPt },
11325 { { (unichar_t *) N_("Can't _Be Interpolated"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Can't Be Interpolated|No Shortcut"), NULL, NULL, CVMenuImplicit, CV_MID_NoImplicitPt },
11326 { { (unichar_t *) N_("Center Bet_ween Control Points"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Center Between Control Points|No Shortcut"), NULL, NULL, CVMenuCenterCP, CV_MID_CenterCP },
11327 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11328 { { (unichar_t *) N_("_Add Anchor"), (GImage *) "pointsaddanchor.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'A' }, H_("Add Anchor|No Shortcut"), NULL, NULL, CVMenuAddAnchor, CV_MID_AddAnchor },
11329 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11330 { { (unichar_t *) N_("Acceptable _Extrema"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'C' }, H_("Acceptable Extrema|No Shortcut"), NULL, NULL, CVMenuAcceptableExtrema, CV_MID_AcceptableExtrema },
11331 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11332 { { (unichar_t *) N_("Make _Line"), (GImage *) "pointsmakeline.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Make Line|No Shortcut"), NULL, NULL, CVMenuMakeLine, CV_MID_MakeLine },
11333 { { (unichar_t *) N_("Ma_ke Arc"), (GImage *) "pointsmakearc.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Make Arc|No Shortcut"), NULL, NULL, CVMenuMakeLine, CV_MID_MakeArc },
11334 { { (unichar_t *) N_("Inse_rt Point On Spline At..."), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Insert Point On Spline At...|No Shortcut"), NULL, NULL, CVMenuInsertPt, CV_MID_InsertPtOnSplineAt },
11335 { { (unichar_t *) N_("_Name Point"), (GImage *) "pointsnamepoint.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Name Point|No Shortcut"), NULL, NULL, CVMenuNamePoint, CV_MID_NamePoint },
11336 { { (unichar_t *) N_("_Name Contour"), (GImage *) "pointsnamecontour.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Name Contour|No Shortcut"), NULL, NULL, CVMenuNameContour, CV_MID_NameContour },
11337 { { (unichar_t *) N_("Make Clip _Path"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Make Clip Path|No Shortcut"), NULL, NULL, CVMenuClipPath, CV_MID_ClipPath },
11338 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11339 { { (unichar_t *) N_("Tool_s"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Tools|No Shortcut"), cvtoollist, cvtoollist_check, NULL, CV_MID_Tools },
11340 GMENUITEM2_EMPTY
11341 };
11342
11343 static GMenuItem2 spiroptlist[] = {
11344 { { (unichar_t *) N_("G4 _Curve"), (GImage *) "pointscurve.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'C' }, H_("G4 Curve|No Shortcut"), NULL, NULL, CVMenuPointType, CV_MID_SpiroG4 },
11345 { { (unichar_t *) N_("_G2 Curve"), (GImage *) "pointsG2curve.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'o' }, H_("G2 Curve|No Shortcut"), NULL, NULL, CVMenuPointType, CV_MID_SpiroG2 },
11346 { { (unichar_t *) N_("C_orner"), (GImage *) "pointscorner.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'o' }, H_("Corner|No Shortcut"), NULL, NULL, CVMenuPointType, CV_MID_SpiroCorner },
11347 { { (unichar_t *) N_("_Left Constraint"), (GImage *) "pointsspiroprev.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Left Constraint|No Shortcut"), NULL, NULL, CVMenuPointType, CV_MID_SpiroLeft },
11348 { { (unichar_t *) N_("_Right Constraint"), (GImage *) "pointsspironext.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Right Constraint|No Shortcut"), NULL, NULL, CVMenuPointType, CV_MID_SpiroRight },
11349 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11350 /* GT: Make this (selected) point the first point in the glyph */
11351 { { (unichar_t *) N_("_Make First"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Make First|No Shortcut"), NULL, NULL, CVMenuSpiroMakeFirst, CV_MID_SpiroMakeFirst },
11352 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11353 { { (unichar_t *) N_("_Add Anchor"), (GImage *) "pointsaddanchor.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'A' }, H_("Add Anchor|No Shortcut"), NULL, NULL, CVMenuAddAnchor, CV_MID_AddAnchor },
11354 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11355 { { (unichar_t *) N_("_Name Point"), (GImage *) "pointsnamepoint.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Name Point|No Shortcut"), NULL, NULL, CVMenuNamePoint, CV_MID_NamePoint },
11356 { { (unichar_t *) N_("_Name Contour"), (GImage *) "pointsnamecontour.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Name Contour|No Shortcut"), NULL, NULL, CVMenuNameContour, CV_MID_NameContour },
11357 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11358 { { (unichar_t *) N_("Tool_s"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, NULL, cvspirotoollist, cvtoollist_check, NULL, CV_MID_Tools },
11359 GMENUITEM2_EMPTY
11360 };
11361
11362 static GMenuItem2 allist[] = {
11363 /* GT: Align these points to their average position */
11364 { { (unichar_t *) N_("_Align Points"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'A' }, H_("Align Points|No Shortcut"), NULL, NULL, CVMenuConstrain, CV_MID_Average },
11365 { { (unichar_t *) N_("_Space Points"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'S' }, H_("Space Points|No Shortcut"), NULL, NULL, CVMenuConstrain, CV_MID_SpacePts },
11366 { { (unichar_t *) N_("Space _Regions..."), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'R' }, H_("Space Regions...|No Shortcut"), NULL, NULL, CVMenuConstrain, CV_MID_SpaceRegion },
11367 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11368 { { (unichar_t *) N_("Make _Parallel..."), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Make Parallel...|No Shortcut"), NULL, NULL, CVMenuMakeParallel, CV_MID_MakeParallel },
11369 GMENUITEM2_EMPTY
11370 };
11371
11372 static GMenuItem2 smlist[] = {
11373 { { (unichar_t *) N_("_Simplify"), (GImage *) "elementsimplify.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'S' }, H_("Simplify|No Shortcut"), NULL, NULL, CVMenuSimplify, CV_MID_Simplify },
11374 { { (unichar_t *) N_("Simplify More..."), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Simplify More...|No Shortcut"), NULL, NULL, CVMenuSimplifyMore, CV_MID_SimplifyMore },
11375 { { (unichar_t *) N_("Clea_nup Glyph"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'n' }, H_("Cleanup Glyph|No Shortcut"), NULL, NULL, CVMenuCleanupGlyph, CV_MID_CleanupGlyph },
11376 { { (unichar_t *) N_("Canonical Start _Point"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'n' }, H_("Canonical Start Point|No Shortcut"), NULL, NULL, CVMenuCanonicalStart, CV_MID_CanonicalStart },
11377 { { (unichar_t *) N_("Canonical _Contours"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'n' }, H_("Canonical Contours|No Shortcut"), NULL, NULL, CVMenuCanonicalContours, CV_MID_CanonicalContours },
11378 GMENUITEM2_EMPTY
11379 };
11380
11381 static void smlistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11382 CharView *cv = (CharView *) GDrawGetUserData(gw);
11383
11384 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
11385 switch ( mi->mid ) {
11386 case CV_MID_Simplify:
11387 case CV_MID_CleanupGlyph:
11388 case CV_MID_SimplifyMore:
11389 mi->ti.disabled = cv->b.layerheads[cv->b.drawmode]->splines==NULL;
11390 break;
11391 case CV_MID_CanonicalStart:
11392 mi->ti.disabled = cv->b.layerheads[cv->b.drawmode]->splines==NULL ||
11393 (cv->b.sc->inspiro && hasspiro());
11394 break;
11395 case CV_MID_CanonicalContours:
11396 mi->ti.disabled = cv->b.layerheads[cv->b.drawmode]->splines==NULL ||
11397 cv->b.layerheads[cv->b.drawmode]->splines->next==NULL ||
11398 cv->b.drawmode!=dm_fore;
11399 break;
11400 }
11401 }
11402 }
11403
11404 static GMenuItem2 orlist[] = {
11405 { { (unichar_t *) N_("_First"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'S' }, H_("First|No Shortcut"), NULL, NULL, CVMenuOrder, CV_MID_First },
11406 { { (unichar_t *) N_("_Earlier"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Earlier|No Shortcut"), NULL, NULL, CVMenuOrder, CV_MID_Earlier },
11407 { { (unichar_t *) N_("L_ater"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'n' }, H_("Later|No Shortcut"), NULL, NULL, CVMenuOrder, CV_MID_Later },
11408 { { (unichar_t *) N_("_Last"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'n' }, H_("Last|No Shortcut"), NULL, NULL, CVMenuOrder, CV_MID_Last },
11409 GMENUITEM2_EMPTY
11410 };
11411
11412 static void orlistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11413 CharView *cv = (CharView *) GDrawGetUserData(gw);
11414 SplinePointList *spl;
11415 RefChar *r;
11416 ImageList *im;
11417 int exactlyone = CVOneContourSel(cv,&spl,&r,&im);
11418 int isfirst, islast;
11419
11420 isfirst = islast = false;
11421 if ( spl!=NULL ) {
11422 isfirst = cv->b.layerheads[cv->b.drawmode]->splines==spl;
11423 islast = spl->next==NULL;
11424 } else if ( r!=NULL ) {
11425 isfirst = cv->b.layerheads[cv->b.drawmode]->refs==r;
11426 islast = r->next==NULL;
11427 } else if ( im!=NULL ) {
11428 isfirst = cv->b.layerheads[cv->b.drawmode]->images==im;
11429 islast = im->next==NULL;
11430 }
11431
11432 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
11433 switch ( mi->mid ) {
11434 case CV_MID_First:
11435 case CV_MID_Earlier:
11436 mi->ti.disabled = !exactlyone || isfirst;
11437 break;
11438 case CV_MID_Last:
11439 case CV_MID_Later:
11440 mi->ti.disabled = !exactlyone || islast;
11441 break;
11442 }
11443 }
11444 }
11445
11446 static GMenuItem2 rmlist[] = {
11447 { { (unichar_t *) N_("_Remove Overlap"), (GImage *) "overlaprm.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 'R' }, H_("Remove Overlap|No Shortcut"), NULL, NULL, CVMenuOverlap, CV_MID_RmOverlap },
11448 { { (unichar_t *) N_("_Intersect"), (GImage *) "overlapintersection.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 'I' }, H_("Intersect|No Shortcut"), NULL, NULL, CVMenuOverlap, CV_MID_Intersection },
11449 { { (unichar_t *) N_("_Exclude"), (GImage *) "overlapexclude.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 'E' }, H_("Exclude|No Shortcut"), NULL, NULL, CVMenuOverlap, CV_MID_Exclude },
11450 { { (unichar_t *) N_("_Find Intersections"), (GImage *) "overlapfindinter.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("Find Intersections|No Shortcut"), NULL, NULL, CVMenuOverlap, CV_MID_FindInter },
11451 GMENUITEM2_EMPTY
11452 };
11453
11454 static GMenuItem2 eflist[] = {
11455 { { (unichar_t *) N_("Change _Weight..."), (GImage *) "styleschangeweight.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Change Weight...|No Shortcut"), NULL, NULL, CVMenuEmbolden, CV_MID_Embolden },
11456 { { (unichar_t *) N_("_Italic..."), (GImage *) "stylesitalic.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, '\0' }, H_("Italic...|No Shortcut"), NULL, NULL, CVMenuItalic, CV_MID_Italic },
11457 { { (unichar_t *) N_("Obli_que..."), (GImage *) "stylesoblique.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Oblique...|No Shortcut"), NULL, NULL, CVMenuOblique, 0 },
11458 { { (unichar_t *) N_("_Condense/Extend..."), (GImage *) "stylesextendcondense.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Condense/Extend...|No Shortcut"), NULL, NULL, CVMenuCondense, CV_MID_Condense },
11459 { { (unichar_t *) N_("Change _X-Height..."), (GImage *) "styleschangexheight.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, '\0' }, H_("Change X-Height...|No Shortcut"), NULL, NULL, CVMenuChangeXHeight, CV_MID_ChangeXHeight },
11460 { { (unichar_t *) N_("Change _Glyph..."), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, '\0' }, H_("Change Glyph...|No Shortcut"), NULL, NULL, CVMenuChangeGlyph, CV_MID_ChangeGlyph },
11461 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11462 { { (unichar_t *) N_("In_line..."), (GImage *) "stylesinline.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 'O' }, H_("Inline...|No Shortcut"), NULL, NULL, CVMenuInline, 0 },
11463 { { (unichar_t *) N_("_Outline..."), (GImage *) "stylesoutline.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 'I' }, H_("Outline...|No Shortcut"), NULL, NULL, CVMenuOutline, 0 },
11464 { { (unichar_t *) N_("S_hadow..."), (GImage *) "stylesshadow.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 'S' }, H_("Shadow...|No Shortcut"), NULL, NULL, CVMenuShadow, 0 },
11465 { { (unichar_t *) N_("_Wireframe..."), (GImage *) "styleswireframe.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, true, 0, 0, 0, 0, 1, 1, 0, 'W' }, H_("Wireframe...|No Shortcut"), NULL, NULL, CVMenuWireframe, 0 },
11466 GMENUITEM2_EMPTY
11467 };
11468
11469 static GMenuItem2 balist[] = {
11470 { { (unichar_t *) N_("_Build Accented Glyph"), (GImage *) "elementbuildaccent.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'u' }, H_("Build Accented Glyph|No Shortcut"), NULL, NULL, CVMenuBuildAccent, CV_MID_BuildAccent },
11471 { { (unichar_t *) N_("Build _Composite Glyph"), (GImage *) "elementbuildcomposite.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'B' }, H_("Build Composite Glyph|No Shortcut"), NULL, NULL, CVMenuBuildComposite, CV_MID_BuildComposite },
11472 GMENUITEM2_EMPTY
11473 };
11474
11475 static GMenuItem2 delist[] = {
11476 { { (unichar_t *) N_("_References..."), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'u' }, H_("References...|No Shortcut"), NULL, NULL, CVMenuShowDependentRefs, CV_MID_ShowDependentRefs },
11477 { { (unichar_t *) N_("_Substitutions..."), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'B' }, H_("Substitutions...|No Shortcut"), NULL, NULL, CVMenuShowDependentSubs, CV_MID_ShowDependentSubs },
11478 GMENUITEM2_EMPTY
11479 };
11480
11481 static GMenuItem2 trlist[] = {
11482 { { (unichar_t *) N_("_Transform..."), (GImage *) "elementtransform.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'T' }, H_("Transform...|No Shortcut"), NULL, NULL, CVMenuTransform, 0 },
11483 { { (unichar_t *) N_("_Point of View Projection..."), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'T' }, H_("Point of View Projection...|No Shortcut"), NULL, NULL, CVMenuPOV, 0 },
11484 { { (unichar_t *) N_("_Non Linear Transform..."), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'T' }, H_("Non Linear Transform...|No Shortcut"), NULL, NULL, CVMenuNLTransform, 0 },
11485 GMENUITEM2_EMPTY
11486 };
11487
11488 static GMenuItem2 rndlist[] = {
11489 { { (unichar_t *) N_("To _Int"), (GImage *) "elementround.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'I' }, H_("To Int|No Shortcut"), NULL, NULL, CVMenuRound2Int, CV_MID_Round },
11490 { { (unichar_t *) N_("To _Hundredths"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'I' }, H_("To Hundredths|No Shortcut"), NULL, NULL, CVMenuRound2Hundredths, 0 },
11491 { { (unichar_t *) N_("_Cluster"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'I' }, H_("Cluster|No Shortcut"), NULL, NULL, CVMenuCluster, CV_MID_RoundToCluster },
11492 GMENUITEM2_EMPTY
11493 };
11494
11495 static GMenuItem2 ellist[] = {
11496 { { (unichar_t *) N_("_Font Info..."), (GImage *) "elementfontinfo.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("Font Info...|No Shortcut"), NULL, NULL, CVMenuFontInfo, CV_MID_FontInfo },
11497 { { (unichar_t *) N_("_Glyph Info..."), (GImage *) "elementglyphinfo.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'I' }, H_("Glyph Info...|No Shortcut"), NULL, NULL, CVMenuCharInfo, CV_MID_CharInfo },
11498 { { (unichar_t *) N_("Get _Info..."), (GImage *) "elementgetinfo.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'I' }, H_("Get Info...|No Shortcut"), NULL, NULL, CVMenuGetInfo, CV_MID_GetInfo },
11499 { { (unichar_t *) N_("S_how Dependent"), (GImage *) "elementshowdep.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'D' }, H_("Show Dependent|No Shortcut"), delist, delistcheck, NULL, CV_MID_ShowDependentRefs },
11500 { { (unichar_t *) N_("Find Proble_ms..."), (GImage *) "elementfindprobs.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'o' }, H_("Find Problems...|No Shortcut"), NULL, NULL, CVMenuFindProblems, CV_MID_FindProblems },
11501 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11502 { { (unichar_t *) N_("Bitm_ap strikes Available..."), (GImage *) "elementbitmapsavail.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'A' }, H_("Bitmap strikes Available...|No Shortcut"), NULL, NULL, CVMenuBitmaps, CV_MID_AvailBitmaps },
11503 { { (unichar_t *) N_("Regenerate _Bitmap Glyphs..."), (GImage *) "elementregenbitmaps.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'B' }, H_("Regenerate Bitmap Glyphs...|No Shortcut"), NULL, NULL, CVMenuBitmaps, CV_MID_RegenBitmaps },
11504 { { (unichar_t *) N_("Remove Bitmap Glyphs..."), (GImage *) "elementremovebitmaps.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, '\0' }, H_("Remove Bitmap Glyphs...|No Shortcut"), NULL, NULL, CVMenuBitmaps, CV_MID_RemoveBitmaps },
11505 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11506 { { (unichar_t *) N_("St_yles"), (GImage *) "elementstyles.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, '\0' }, H_("Styles|No Shortcut"), eflist, NULL, NULL, CV_MID_Styles },
11507 { { (unichar_t *) N_("_Transformations"), (GImage *) "elementtransform.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'T' }, H_("Transformations|No Shortcut"), trlist, NULL, NULL, 0 },
11508 { { (unichar_t *) N_("_Expand Stroke..."), (GImage *) "elementexpandstroke.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'E' }, H_("Expand Stroke...|No Shortcut"), NULL, NULL, CVMenuStroke, CV_MID_Stroke },
11509 #ifdef FONTFORGE_CONFIG_TILEPATH
11510 { { (unichar_t *) N_("Tile _Path..."), (GImage *) "elementtilepath.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Tile Path...|No Shortcut"), NULL, NULL, CVMenuTilePath, CV_MID_TilePath },
11511 { { (unichar_t *) N_("Tile Pattern..."), (GImage *) "elementtilepattern.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, '\0' }, H_("Tile Pattern...|No Shortcut"), NULL, NULL, CVMenuPatternTile, 0 },
11512 #endif
11513 { { (unichar_t *) N_("O_verlap"), (GImage *) "overlaprm.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'v' }, H_("Overlap|No Shortcut"), rmlist, NULL, NULL, CV_MID_RmOverlap },
11514 { { (unichar_t *) N_("_Simplify"), (GImage *) "elementsimplify.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'S' }, H_("Simplify|No Shortcut"), smlist, smlistcheck, NULL, CV_MID_Simplify },
11515 { { (unichar_t *) N_("Add E_xtrema"), (GImage *) "elementaddextrema.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'x' }, H_("Add Extrema|No Shortcut"), NULL, NULL, CVMenuAddExtrema, CV_MID_AddExtrema },
11516 { { (unichar_t *) N_("Add Points Of I_nflection"), (GImage *) "elementaddinflections.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'n' }, H_("Add Points Of Inflection|No Shortcut"), NULL, NULL, CVMenuAddInflections, CV_MID_AddInflections },
11517 { { (unichar_t *) N_("_Balance"), (GImage *) "elementbalance.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'b' }, H_("Balance|No Shortcut"), NULL, NULL, CVMenuBalance, CV_MID_Balance },
11518 { { (unichar_t *) N_("Harmoni_ze"), (GImage *) "elementharmonize.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'z' }, H_("Harmonize|No Shortcut"), NULL, NULL, CVMenuHarmonize, CV_MID_Harmonize },
11519 { { (unichar_t *) N_("Autot_race"), (GImage *) "elementautotrace.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'r' }, H_("Autotrace|No Shortcut"), NULL, NULL, CVMenuAutotrace, CV_MID_Autotrace },
11520 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11521 { { (unichar_t *) N_("A_lign"), (GImage *) "elementalign.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'l' }, H_("Align|No Shortcut"), allist, allistcheck, NULL, CV_MID_Align },
11522 { { (unichar_t *) N_("Roun_d"), (GImage *) "elementround.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'I' }, H_("Round|No Shortcut"), rndlist, rndlistcheck, NULL, CV_MID_Round },
11523 { { (unichar_t *) N_("_Order"), (GImage *) "elementorder.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, '\0' }, H_("Order|No Shortcut"), orlist, orlistcheck, NULL, 0 },
11524 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11525 { { (unichar_t *) N_("Check Self-Intersection"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'o' }, H_("Check Self-Intersection|No Shortcut"), NULL, NULL, CVMenuCheckSelf, CV_MID_CheckSelf },
11526 { { (unichar_t *) N_("Glyph Self-Intersects"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'o' }, H_("Glyph Self-Intersects|No Shortcut"), NULL, NULL, CVMenuGlyphSelfIntersects, CV_MID_GlyphSelfIntersects },
11527 { { (unichar_t *) N_("Cloc_kwise"), (GImage *) "elementclockwise.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'o' }, H_("Clockwise|No Shortcut"), NULL, NULL, CVMenuDir, CV_MID_Clockwise },
11528 { { (unichar_t *) N_("Cou_nter Clockwise"), (GImage *) "elementanticlock.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'n' }, H_("Counter Clockwise|No Shortcut"), NULL, NULL, CVMenuDir, CV_MID_Counter },
11529 { { (unichar_t *) N_("_Correct Direction"), (GImage *) "elementcorrectdir.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'D' }, H_("Correct Direction|No Shortcut"), NULL, NULL, CVMenuCorrectDir, CV_MID_Correct },
11530 { { (unichar_t *) N_("Reverse Direction"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'D' }, H_("Reverse Direction|No Shortcut"), NULL, NULL, CVMenuReverseDir, CV_MID_ReverseDir },
11531 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11532 { { (unichar_t *) N_("Insert Text Outlines..."), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'D' }, H_("Insert Text Outlines...|No Shortcut"), NULL, NULL, CVMenuInsertText, CV_MID_InsertText },
11533 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11534 { { (unichar_t *) N_("B_uild"), (GImage *) "elementbuildaccent.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'u' }, H_("Build|No Shortcut"), balist, balistcheck, NULL, CV_MID_BuildAccent },
11535 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11536 { { (unichar_t *) N_("Compare Layers..."), (GImage *) "elementcomparelayers.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'u' }, H_("Compare Layers...|No Shortcut"), NULL, NULL, CVMenuCompareL2L, 0 },
11537 GMENUITEM2_EMPTY
11538 };
11539
11540 static GMenuItem2 htlist[] = {
11541 { { (unichar_t *) N_("Auto_Hint"), (GImage *) "hintsautohint.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'H' }, H_("AutoHint|No Shortcut"), NULL, NULL, CVMenuAutoHint, CV_MID_AutoHint },
11542 { { (unichar_t *) N_("Hint _Substitution Pts"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'H' }, H_("Hint Substitution Pts|No Shortcut"), NULL, NULL, CVMenuAutoHintSubs, CV_MID_HintSubsPt },
11543 { { (unichar_t *) N_("Auto _Counter Hint"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'H' }, H_("Auto Counter Hint|No Shortcut"), NULL, NULL, CVMenuAutoCounter, CV_MID_AutoCounter },
11544 { { (unichar_t *) N_("_Don't AutoHint"), (GImage *) "hintsdontautohint.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'H' }, H_("Don't AutoHint|No Shortcut"), NULL, NULL, CVMenuDontAutoHint, CV_MID_DontAutoHint },
11545 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11546 { { (unichar_t *) N_("Auto_Instr"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'T' }, H_("AutoInstr|No Shortcut"), NULL, NULL, CVMenuNowakAutoInstr, CV_MID_AutoInstr },
11547 { { (unichar_t *) N_("_Edit Instructions..."), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'l' }, H_("Edit Instructions...|No Shortcut"), NULL, NULL, CVMenuEditInstrs, CV_MID_EditInstructions },
11548 { { (unichar_t *) N_("_Debug..."), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'l' }, H_("Debug...|No Shortcut"), NULL, NULL, CVMenuDebug, CV_MID_Debug },
11549 { { (unichar_t *) N_("S_uggest Deltas..."), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'l' }, H_("Suggest Deltas...|No Shortcut"), NULL, NULL, CVMenuDeltas, CV_MID_Deltas },
11550 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11551 { { (unichar_t *) N_("_Clear HStem"), (GImage *) "hintsclearhstems.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'C' }, H_("Clear HStem|No Shortcut"), NULL, NULL, CVMenuClearHints, CV_MID_ClearHStem },
11552 { { (unichar_t *) N_("Clear _VStem"), (GImage *) "hintsclearvstems.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'V' }, H_("Clear VStem|No Shortcut"), NULL, NULL, CVMenuClearHints, CV_MID_ClearVStem },
11553 { { (unichar_t *) N_("Clear DStem"), (GImage *) "hintscleardstems.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'V' }, H_("Clear DStem|No Shortcut"), NULL, NULL, CVMenuClearHints, CV_MID_ClearDStem },
11554 { { (unichar_t *) N_("Clear Instructions"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, '\0' }, H_("Clear Instructions|No Shortcut"), NULL, NULL, CVMenuClearInstrs, CV_MID_ClearInstr },
11555 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11556 { { (unichar_t *) N_("_Add HHint"), (GImage *) "hintsaddhstem.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'A' }, H_("Add HHint|No Shortcut"), NULL, NULL, CVMenuAddHint, CV_MID_AddHHint },
11557 { { (unichar_t *) N_("Add VHi_nt"), (GImage *) "hintsaddvstem.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 's' }, H_("Add VHint|No Shortcut"), NULL, NULL, CVMenuAddHint, CV_MID_AddVHint },
11558 { { (unichar_t *) N_("Add DHint"), (GImage *) "hintsadddstem.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 't' }, H_("Add DHint|No Shortcut"), NULL, NULL, CVMenuAddHint, CV_MID_AddDHint },
11559 { { (unichar_t *) N_("Crea_te HHint..."), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'r' }, H_("Create HHint...|No Shortcut"), NULL, NULL, CVMenuCreateHint, CV_MID_CreateHHint },
11560 { { (unichar_t *) N_("Cr_eate VHint..."), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'e' }, H_("Create VHint...|No Shortcut"), NULL, NULL, CVMenuCreateHint, CV_MID_CreateVHint },
11561 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11562 { { (unichar_t *) N_("_Review Hints..."), (GImage *) "hintsreviewhints.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'R' }, H_("Review Hints...|No Shortcut"), NULL, NULL, CVMenuReviewHints, CV_MID_ReviewHints },
11563 GMENUITEM2_EMPTY
11564 };
11565
11566 static GMenuItem2 ap2list[] = {
11567 GMENUITEM2_EMPTY
11568 };
11569
11570 static void ap2listbuild(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11571 CharView *cv = (CharView *) GDrawGetUserData(gw);
11572 char buf[300];
11573 GMenuItem *sub;
11574 int k, cnt;
11575 AnchorPoint *ap;
11576
11577 if ( mi->sub!=NULL ) {
11578 GMenuItemArrayFree(mi->sub);
11579 mi->sub = NULL;
11580 }
11581
11582 for ( k=0; k<2; ++k ) {
11583 cnt = 0;
11584 for ( ap=cv->b.sc->anchor; ap!=NULL; ap=ap->next ) {
11585 if ( k ) {
11586 if ( ap->type==at_baselig )
11587 /* GT: In the next few lines the "%s" is the name of an anchor class, and the */
11588 /* GT: rest of the string identifies the type of the anchor */
11589 snprintf(buf,sizeof(buf), _("%s at ligature pos %d"), ap->anchor->name, ap->lig_index );
11590 else
11591 snprintf(buf,sizeof(buf),
11592 ap->type==at_cexit ? _("%s exit"):
11593 ap->type==at_centry ? _("%s entry"):
11594 ap->type==at_mark ? _("%s mark"):
11595 _("%s base"),ap->anchor->name );
11596 sub[cnt].ti.text = utf82u_copy(buf);
11597 sub[cnt].ti.userdata = ap;
11598 sub[cnt].ti.bg = sub[cnt].ti.fg = COLOR_DEFAULT;
11599 sub[cnt].invoke = CVMenuAnchorsAway;
11600 }
11601 ++cnt;
11602 }
11603 if ( !k )
11604 sub = calloc(cnt+1,sizeof(GMenuItem));
11605 }
11606 mi->sub = sub;
11607 }
11608
11609 static void CVMenuKernByClasses(GWindow gw,struct gmenuitem *mi,GEvent *e) {
11610 CharView *cv = (CharView *) GDrawGetUserData(gw);
11611 MetricsView *mv = 0;
11612 SplineFont *sf = cv->b.sc->parent;
11613 int cvlayer = CVLayer((CharViewBase *) cv);
11614 ShowKernClasses(sf, mv, cvlayer, false);
11615 }
11616
11617 static void CVMenuVKernByClasses(GWindow gw,struct gmenuitem *mi,GEvent *e) {
11618 CharView *cv = (CharView *) GDrawGetUserData(gw);
11619 MetricsView *mv = 0;
11620 SplineFont *sf = cv->b.sc->parent;
11621 int cvlayer = CVLayer((CharViewBase *) cv);
11622 ShowKernClasses(sf, mv, cvlayer, true);
11623 }
11624
11625 static void CVMenuVKernFromHKern(GWindow gw,struct gmenuitem *mi,GEvent *e) {
11626 CharView *cv = (CharView *) GDrawGetUserData(gw);
11627 FVVKernFromHKern((FontViewBase *) cv->b.fv);
11628 }
11629
11630 static GMenuItem2 mtlist[] = {
11631 { { (unichar_t *) N_("New _Metrics Window"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("New Metrics Window|No Shortcut"), NULL, NULL, CVMenuOpenMetrics, 0 },
11632 GMENUITEM2_LINE,
11633 { { (unichar_t *) N_("_Center in Width"), (GImage *) "metricscenter.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'C' }, H_("Center in Width|No Shortcut"), NULL, NULL, CVMenuCenter, CV_MID_Center },
11634 { { (unichar_t *) N_("_Thirds in Width"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'T' }, H_("Thirds in Width|No Shortcut"), NULL, NULL, CVMenuCenter, CV_MID_Thirds },
11635 { { (unichar_t *) N_("Set _Width..."), (GImage *) "metricssetwidth.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'W' }, H_("Set Width...|No Shortcut"), NULL, NULL, CVMenuSetWidth, CV_MID_SetWidth },
11636 { { (unichar_t *) N_("Set _LBearing..."), (GImage *) "metricssetlbearing.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'L' }, H_("Set LBearing...|No Shortcut"), NULL, NULL, CVMenuSetWidth, CV_MID_SetLBearing },
11637 { { (unichar_t *) N_("Set _RBearing..."), (GImage *) "metricssetrbearing.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'R' }, H_("Set RBearing...|No Shortcut"), NULL, NULL, CVMenuSetWidth, CV_MID_SetRBearing },
11638 { { (unichar_t *) N_("Set Both Bearings..."), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'R' }, H_("Set Both Bearings...|No Shortcut"), NULL, NULL, CVMenuSetWidth, CV_MID_SetBearings },
11639 GMENUITEM2_LINE,
11640 { { (unichar_t *) N_("Set _Vertical Advance..."), (GImage *) "metricssetvwidth.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'V' }, H_("Set Vertical Advance...|No Shortcut"), NULL, NULL, CVMenuSetWidth, CV_MID_SetVWidth },
11641 GMENUITEM2_LINE,
11642 { { (unichar_t *) N_("Ker_n By Classes..."), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'T' }, H_("Kern By Classes...|No Shortcut"), NULL, NULL, CVMenuKernByClasses, 0 },
11643 { { (unichar_t *) N_("VKern By Classes..."), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'T' }, H_("VKern By Classes...|No Shortcut"), NULL, NULL, CVMenuVKernByClasses, CV_MID_VKernClass },
11644 { { (unichar_t *) N_("VKern From HKern"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'T' }, H_("VKern From HKern|No Shortcut"), NULL, NULL, CVMenuVKernFromHKern, CV_MID_VKernFromHKern },
11645 { { (unichar_t *) N_("Remove Kern _Pairs"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Remove Kern Pairs|No Shortcut"), NULL, NULL, CVMenuRemoveKern, CV_MID_RemoveKerns },
11646 { { (unichar_t *) N_("Remove VKern Pairs"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Remove VKern Pairs|No Shortcut"), NULL, NULL, CVMenuRemoveVKern, CV_MID_RemoveVKerns },
11647 { { (unichar_t *) N_("Kern Pair Closeup..."), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Kern Pair Closeup...|No Shortcut"), NULL, NULL, CVMenuKPCloseup, CV_MID_KPCloseup },
11648 GMENUITEM2_EMPTY
11649 };
11650
11651 static GMenuItem2 pllist[] = {
11652 { { (unichar_t *) N_("_Tools"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Tools|No Shortcut"), NULL, NULL, CVMenuPaletteShow, CV_MID_Tools },
11653 { { (unichar_t *) N_("_Layers"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'L' }, H_("Layers|No Shortcut"), NULL, NULL, CVMenuPaletteShow, CV_MID_Layers },
11654 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11655 { { (unichar_t *) N_("_Docked Palettes"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'D' }, H_("Docked Palettes|No Shortcut"), NULL, NULL, CVMenuPalettesDock, CV_MID_DockPalettes },
11656 GMENUITEM2_EMPTY
11657 };
11658
11659 static GMenuItem2 aplist[] = {
11660 { { (unichar_t *) N_("_Detach"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'K' }, H_("Detach|No Shortcut"), NULL, NULL, CVMenuAPDetach, 0 },
11661 GMENUITEM2_EMPTY
11662 };
11663
11664 static void aplistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11665 CharView *cv = (CharView *) GDrawGetUserData(gw);
11666 SplineChar *sc = cv->b.sc, **glyphs;
11667 SplineFont *sf = sc->parent;
11668 AnchorPoint *ap, *found;
11669 GMenuItem2 *mit;
11670 int cnt;
11671
11672 found = NULL;
11673 for ( ap=sc->anchor; ap!=NULL; ap=ap->next ) {
11674 if ( ap->selected ) {
11675 if ( found==NULL )
11676 found = ap;
11677 else {
11678 /* Can't deal with two selected anchors */
11679 found = NULL;
11680 break;
11681 }
11682 }
11683 }
11684
11685 GMenuItemArrayFree(mi->sub);
11686 if ( found==NULL )
11687 glyphs = NULL;
11688 else
11689 glyphs = GlyphsMatchingAP(sf,found);
11690 if ( glyphs==NULL ) {
11691 mi->sub = GMenuItem2ArrayCopy(aplist,NULL);
11692 mi->sub->ti.disabled = (cv->apmine==NULL);
11693 return;
11694 }
11695
11696 for ( cnt = 0; glyphs[cnt]!=NULL; ++cnt );
11697 mit = calloc(cnt+2,sizeof(GMenuItem2));
11698 mit[0] = aplist[0];
11699 mit[0].ti.text = (unichar_t *) copy( (char *) mit[0].ti.text );
11700 mit[0].ti.disabled = (cv->apmine==NULL);
11701 for ( cnt = 0; glyphs[cnt]!=NULL; ++cnt ) {
11702 mit[cnt+1].ti.text = (unichar_t *) copy(glyphs[cnt]->name);
11703 mit[cnt+1].ti.text_is_1byte = true;
11704 mit[cnt+1].ti.fg = mit[cnt+1].ti.bg = COLOR_DEFAULT;
11705 mit[cnt+1].ti.userdata = glyphs[cnt];
11706 mit[cnt+1].invoke = CVMenuAPAttachSC;
11707 if ( glyphs[cnt]==cv->apsc )
11708 mit[cnt+1].ti.checked = mit[cnt+1].ti.checkable = true;
11709 }
11710 free(glyphs);
11711 mi->sub = GMenuItem2ArrayCopy(mit,NULL);
11712 GMenuItem2ArrayFree(mit);
11713 }
11714
11715 static void CVMoveInWordListByOffset( CharView* cv, int offset )
11716 {
11717 Wordlist_MoveByOffset( cv->charselector, &cv->charselectoridx, offset );
11718 }
11719
11720 static void CVMenuNextLineInWordList(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11721 CharView* cv = (CharView*) GDrawGetUserData(gw);
11722 CVMoveInWordListByOffset( cv, 1 );
11723 }
11724 static void CVMenuPrevLineInWordList(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11725 CharView* cv = (CharView*) GDrawGetUserData(gw);
11726 CVMoveInWordListByOffset( cv, -1 );
11727 }
11728
11729 static GMenuItem2 cblist[] = {
11730 { { (unichar_t *) N_("_Kern Pairs"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'K' }, H_("Kern Pairs|No Shortcut"), NULL, NULL, CVMenuKernPairs, CV_MID_KernPairs },
11731 { { (unichar_t *) N_("_Anchored Pairs"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'A' }, H_("Anchored Pairs|No Shortcut"), NULL, NULL, CVMenuAnchorPairs, CV_MID_AnchorPairs },
11732 { { (unichar_t *) N_("_Anchor Control..."), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'V' }, H_("Anchor Control...|No Shortcut"), ap2list, ap2listbuild, NULL, CV_MID_AnchorControl },
11733 { { (unichar_t *) N_("Anchor _Glyph at Point"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'A' }, H_("Anchor Glyph at Point|No Shortcut"), aplist, aplistcheck, NULL, CV_MID_AnchorGlyph },
11734 { { (unichar_t *) N_("_Ligatures"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'L' }, H_("Ligatures|No Shortcut"), NULL, NULL, CVMenuLigatures, CV_MID_Ligatures },
11735 GMENUITEM2_EMPTY
11736 };
11737
11738 static GMenuItem2 nplist[] = {
11739 { { (unichar_t *) N_("PointNumbers|_None"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'K' }, H_("None|No Shortcut"), NULL, NULL, CVMenuNumberPoints, CV_MID_PtsNone },
11740 { { (unichar_t *) N_("_TrueType"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'A' }, H_("TrueType|No Shortcut"), NULL, NULL, CVMenuNumberPoints, CV_MID_PtsTrue },
11741 { { (unichar_t *) NU_("_PostScriptÂź"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'L' }, H_("PostScript|No Shortcut"), NULL, NULL, CVMenuNumberPoints, CV_MID_PtsPost },
11742 { { (unichar_t *) N_("_SVG"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'L' }, H_("SVG|No Shortcut"), NULL, NULL, CVMenuNumberPoints, CV_MID_PtsSVG },
11743 { { (unichar_t *) N_("P_ositions"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'L' }, H_("Positions|No Shortcut"), NULL, NULL, CVMenuNumberPoints, CV_MID_PtsPos },
11744 GMENUITEM2_EMPTY
11745 };
11746
11747 static GMenuItem2 gflist[] = {
11748 { { (unichar_t *) N_("Show _Grid Fit..."), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'l' }, H_("Show Grid Fit...|No Shortcut"), NULL, NULL, CVMenuShowGridFit, CV_MID_ShowGridFit },
11749 { { (unichar_t *) N_("Show _Grid Fit (Live Update)..."), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'l' }, H_("Show Grid Fit (Live Update)...|No Shortcut"), NULL, NULL, CVMenuShowGridFitLiveUpdate, CV_MID_ShowGridFitLiveUpdate },
11750 { { (unichar_t *) N_("_Bigger Point Size"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'B' }, H_("Bigger Point Size|No Shortcut"), NULL, NULL, CVMenuChangePointSize, CV_MID_Bigger },
11751 { { (unichar_t *) N_("_Smaller Point Size"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'S' }, H_("Smaller Point Size|No Shortcut"), NULL, NULL, CVMenuChangePointSize, CV_MID_Smaller },
11752 { { (unichar_t *) N_("_Anti Alias"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'L' }, H_("Anti Alias|No Shortcut"), NULL, NULL, CVMenuChangePointSize, CV_MID_GridFitAA },
11753 { { (unichar_t *) N_("_Off"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'S' }, H_("Off|No Shortcut"), NULL, NULL, CVMenuChangePointSize, CV_MID_GridFitOff },
11754 GMENUITEM2_EMPTY
11755 };
11756
11757 static GMenuItem2 swlist[] = {
11758 { { (unichar_t *) N_("_Points"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'o' }, H_("Points|No Shortcut"), NULL, NULL, CVMenuShowHide, CV_MID_HidePoints },
11759 { { (unichar_t *) N_("Control Points (Always_)"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, ')' }, H_("Control Points (Always)|No Shortcut"), NULL, NULL, CVMenuShowHideControlPoints, CV_MID_HideControlPoints },
11760 { { (unichar_t *) N_("_Control Point Info"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'M' }, H_("Control Point Info|No Shortcut"), NULL, NULL, CVMenuShowCPInfo, CV_MID_ShowCPInfo },
11761 { { (unichar_t *) N_("_Extrema"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'M' }, H_("Extrema|No Shortcut"), NULL, NULL, CVMenuMarkExtrema, CV_MID_MarkExtrema },
11762 { { (unichar_t *) N_("Points of _Inflection"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'M' }, H_("Points of Inflection|No Shortcut"), NULL, NULL, CVMenuMarkPointsOfInflection, CV_MID_MarkPointsOfInflection },
11763 { { (unichar_t *) N_("Almost Horizontal/Vertical Lines"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'M' }, H_("Almost Horizontal/Vertical Lines|No Shortcut"), NULL, NULL, CVMenuShowAlmostHV, CV_MID_ShowAlmostHV },
11764 { { (unichar_t *) N_("Almost Horizontal/Vertical Curves"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'M' }, H_("Almost Horizontal/Vertical Curves|No Shortcut"), NULL, NULL, CVMenuShowAlmostHVCurves, CV_MID_ShowAlmostHVCurves },
11765 { { (unichar_t *) N_("(Define \"Almost\")"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("(Define \"Almost\")|No Shortcut"), NULL, NULL, CVMenuDefineAlmost, CV_MID_DefineAlmost },
11766 { { (unichar_t *) N_("_Side Bearings"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'M' }, H_("Side Bearings|No Shortcut"), NULL, NULL, CVMenuShowSideBearings, CV_MID_ShowSideBearings },
11767 { { (unichar_t *) N_("Reference Names"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'M' }, H_("Reference Names|No Shortcut"), NULL, NULL, CVMenuShowRefNames, CV_MID_ShowRefNames },
11768 { { (unichar_t *) N_("_Fill"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'l' }, H_("Fill|No Shortcut"), NULL, NULL, CVMenuFill, CV_MID_Fill },
11769 { { (unichar_t *) N_("Previe_w"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'l' }, H_("Preview|No Shortcut"), NULL, NULL, CVMenuPreview, CV_MID_Preview },
11770 { { (unichar_t *) N_("Dragging Comparison Outline"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'l' }, H_("Dragging Comparison Outline|No Shortcut"), NULL, NULL, CVMenuDraggingComparisonOutline, CV_MID_DraggingComparisonOutline },
11771 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11772 { { (unichar_t *) N_("Pale_ttes"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Palettes|No Shortcut"), pllist, pllistcheck, NULL, 0 },
11773 { { (unichar_t *) N_("_Glyph Tabs"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'R' }, H_("Glyph Tabs|No Shortcut"), NULL, NULL, CVMenuShowTabs, CV_MID_ShowTabs },
11774 { { (unichar_t *) N_("_Rulers"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'R' }, H_("Rulers|No Shortcut"), NULL, NULL, CVMenuShowHideRulers, CV_MID_HideRulers },
11775 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11776 { { (unichar_t *) N_("_Horizontal Hints"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'R' }, H_("Horizontal Hints|No Shortcut"), NULL, NULL, CVMenuShowHints, CV_MID_ShowHHints },
11777 { { (unichar_t *) N_("_Vertical Hints"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'R' }, H_("Vertical Hints|No Shortcut"), NULL, NULL, CVMenuShowHints, CV_MID_ShowVHints },
11778 { { (unichar_t *) N_("_Diagonal Hints"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'R' }, H_("Diagonal Hints|No Shortcut"), NULL, NULL, CVMenuShowHints, CV_MID_ShowDHints },
11779 /* GT: You might not want to translate this, it's a keyword in PostScript font files */
11780 { { (unichar_t *) N_("_BlueValues"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'R' }, H_("BlueValues|No Shortcut"), NULL, NULL, CVMenuShowHints, CV_MID_ShowBlueValues },
11781 /* GT: You might not want to translate this, it's a keyword in PostScript font files */
11782 { { (unichar_t *) N_("FamilyBl_ues"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'R' }, H_("FamilyBlues|No Shortcut"), NULL, NULL, CVMenuShowHints, CV_MID_ShowFamilyBlues },
11783 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11784 { { (unichar_t *) N_("_Anchors"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'R' }, H_("Anchors|No Shortcut"), NULL, NULL, CVMenuShowHints, CV_MID_ShowAnchors },
11785 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11786 { { (unichar_t *) N_("Debug Raster Cha_nges"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'R' }, H_("Debug Raster Changes|No Shortcut"), NULL, NULL, CVMenuShowHints, CV_MID_ShowDebugChanges },
11787 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11788 { { (unichar_t *) N_("Hori_zontal Metric Lines"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'R' }, H_("Horizontal Metric Lines|No Shortcut"), NULL, NULL, CVMenuShowHints, CV_MID_ShowHMetrics },
11789 { { (unichar_t *) N_("Vertical _Metric Lines"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'R' }, H_("Vertical Metric Lines|No Shortcut"), NULL, NULL, CVMenuShowHints, CV_MID_ShowVMetrics },
11790 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11791 { { (unichar_t *) N_("Snap Outlines to Pi_xel Grid"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'R' }, H_("Snap Outlines to Pixel Grid|No Shortcut"), NULL, NULL, CVMenuSnapOutlines, CV_MID_SnapOutlines },
11792 GMENUITEM2_EMPTY
11793 };
11794
11795 static GMenuItem2 vwlist[] = {
11796 { { (unichar_t *) N_("_Fit"), (GImage *) "viewfit.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("Fit|No Shortcut"), NULL, NULL, CVMenuScale, CV_MID_Fit },
11797 { { (unichar_t *) N_("Z_oom out"), (GImage *) "viewzoomout.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'o' }, H_("Zoom out|No Shortcut"), NULL, NULL, CVMenuScale, CV_MID_ZoomOut },
11798 { { (unichar_t *) N_("Zoom _in"), (GImage *) "viewzoomin.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'i' }, H_("Zoom in|No Shortcut"), NULL, NULL, CVMenuScale, CV_MID_ZoomIn },
11799 #if HANYANG
11800 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11801 { { (unichar_t *) N_("_Display Compositions..."), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'i' }, H_("Display Compositions...|No Shortcut"), NULL, NULL, CVDisplayCompositions, CV_MID_DisplayCompositions },
11802 #endif
11803 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11804 { { (unichar_t *) N_("_Next Glyph"), (GImage *) "viewnext.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'N' }, H_("Next Glyph|No Shortcut"), NULL, NULL, CVMenuChangeChar, CV_MID_Next },
11805 { { (unichar_t *) N_("_Prev Glyph"), (GImage *) "viewprev.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Prev Glyph|No Shortcut"), NULL, NULL, CVMenuChangeChar, CV_MID_Prev },
11806 { { (unichar_t *) N_("Next _Defined Glyph"), (GImage *) "viewnextdef.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'D' }, H_("Next Defined Glyph|No Shortcut"), NULL, NULL, CVMenuChangeChar, CV_MID_NextDef },
11807 { { (unichar_t *) N_("Prev Defined Gl_yph"), (GImage *) "viewprevdef.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'a' }, H_("Prev Defined Glyph|No Shortcut"), NULL, NULL, CVMenuChangeChar, CV_MID_PrevDef },
11808 { { (unichar_t *) N_("Form_er Glyph"), (GImage *) "viewformer.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'a' }, H_("Former Glyph|No Shortcut"), NULL, NULL, CVMenuChangeChar, CV_MID_Former },
11809 { { (unichar_t *) N_("_Goto"), (GImage *) "viewgoto.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'G' }, H_("Goto|No Shortcut"), NULL, NULL, CVMenuGotoChar, CV_MID_Goto },
11810 { { (unichar_t *) N_("Find In Font _View"), (GImage *) "viewfindinfont.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'V' }, H_("Find In Font View|No Shortcut"), NULL, NULL, CVMenuFindInFontView, CV_MID_FindInFontView },
11811 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11812 { { (unichar_t *) N_("N_umber Points"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'o' }, H_("Number Points|No Shortcut"), nplist, nplistcheck, NULL, 0 },
11813 { { (unichar_t *) N_("Grid Fi_t"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'l' }, H_("Grid Fit|No Shortcut"), gflist, gflistcheck, NULL, CV_MID_ShowGridFit },
11814 { { (unichar_t *) N_("Sho_w"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'l' }, H_("Show|No Shortcut"), swlist, swlistcheck, NULL, 0 },
11815 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11816 { { (unichar_t *) N_("Com_binations"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'b' }, H_("Combinations|No Shortcut"), cblist, cblistcheck, NULL, 0 },
11817 GMENUITEM2_LINE,
11818 { { (unichar_t *) N_("Next _Line in Word List"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'L' }, H_("Next Line in Word List|No Shortcut"), NULL, NULL, CVMenuNextLineInWordList, CV_MID_NextLineInWordList },
11819 { { (unichar_t *) N_("Previous Line in _Word List"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'W' }, H_("Previous Line in Word List|No Shortcut"), NULL, NULL, CVMenuPrevLineInWordList, CV_MID_PrevLineInWordList },
11820 GMENUITEM2_EMPTY
11821 };
11822
11823 static void CVMenuShowMMMask(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11824 CharView *cv = (CharView *) GDrawGetUserData(gw);
11825 uint32_t changemask = (uint32_t) (intptr_t) mi->ti.userdata;
11826 /* Change which mms get displayed in the "background" */
11827
11828 if ( mi->mid==CV_MID_MMAll ) {
11829 if ( (cv->mmvisible&changemask)==changemask ) cv->mmvisible = 0;
11830 else cv->mmvisible = changemask;
11831 } else if ( mi->mid == CV_MID_MMNone ) {
11832 if ( cv->mmvisible==0 ) cv->mmvisible = (1<<(cv->b.sc->parent->mm->instance_count+1))-1;
11833 else cv->mmvisible = 0;
11834 } else
11835 cv->mmvisible ^= changemask;
11836 GDrawRequestExpose(cv->v,NULL,false);
11837 }
11838
11839 static GMenuItem2 mvlist[] = {
11840 { { (unichar_t *) N_("SubFonts|_All"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, (void *) 0xffffffff, NULL, 0, 0, 1, 0, 0, 0, 1, 1, 0, '\0' }, H_("All|No Shortcut"), NULL, NULL, CVMenuShowMMMask, CV_MID_MMAll },
11841 { { (unichar_t *) N_("SubFonts|_None"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, (void *) 0, NULL, 0, 0, 1, 0, 0, 0, 1, 1, 0, '\0' }, H_("None|No Shortcut"), NULL, NULL, CVMenuShowMMMask, CV_MID_MMNone },
11842 GMENUITEM2_EMPTY
11843 };
11844
11845 static void mvlistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11846 CharView *cv = (CharView *) GDrawGetUserData(gw);
11847 int i, base, j;
11848 MMSet *mm = cv->b.sc->parent->mm;
11849 uint32_t submask;
11850 SplineFont *sub;
11851 GMenuItem2 *mml;
11852
11853 base = 3;
11854 if ( mm==NULL )
11855 mml = mvlist;
11856 else {
11857 mml = calloc(base+mm->instance_count+2,sizeof(GMenuItem2));
11858 memcpy(mml,mvlist,sizeof(mvlist));
11859 mml[base-1].ti.fg = mml[base-1].ti.bg = COLOR_DEFAULT;
11860 mml[base-1].ti.line = true;
11861 submask = 0;
11862 for ( j = 0, i=base; j<mm->instance_count+1; ++i, ++j ) {
11863 if ( j==0 )
11864 sub = mm->normal;
11865 else
11866 sub = mm->instances[j-1];
11867 mml[i].ti.text = uc_copy(sub->fontname);
11868 mml[i].ti.checkable = true;
11869 mml[i].ti.checked = (cv->mmvisible & (1<<j))?1:0;
11870 mml[i].ti.userdata = (void *) (intptr_t) (1<<j);
11871 mml[i].invoke = CVMenuShowMMMask;
11872 mml[i].ti.fg = mml[i].ti.bg = COLOR_DEFAULT;
11873 if ( sub==cv->b.sc->parent )
11874 submask = (1<<j);
11875 }
11876 /* All */
11877 mml[0].ti.userdata = (void *) (intptr_t) ((1<<j)-1);
11878 mml[0].ti.checked = (cv->mmvisible == (uint32_t) (intptr_t) mml[0].ti.userdata);
11879 /* None */
11880 mml[1].ti.checked = (cv->mmvisible == 0 || cv->mmvisible == submask);
11881 }
11882 GMenuItemArrayFree(mi->sub);
11883 mi->sub = GMenuItem2ArrayCopy(mml,NULL);
11884 if ( mml!=mvlist ) {
11885 for ( i=base; mml[i].ti.text!=NULL; ++i )
11886 free( mml[i].ti.text);
11887 free(mml);
11888 }
11889 }
11890
11891 static void CVMenuReblend(GWindow gw, struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
11892 CharView *cv = (CharView *) GDrawGetUserData(gw);
11893 char *err;
11894 MMSet *mm = cv->b.sc->parent->mm;
11895
11896 if ( mm==NULL || mm->apple || cv->b.sc->parent!=mm->normal )
11897 return;
11898 err = MMBlendChar(mm,cv->b.sc->orig_pos);
11899 if ( mm->normal->glyphs[cv->b.sc->orig_pos]!=NULL )
11900 _SCCharChangedUpdate(mm->normal->glyphs[cv->b.sc->orig_pos],CVLayer((CharViewBase *)cv->b.sc),-1);
11901 if ( err!=0 )
11902 ff_post_error(_("Bad Multiple Master Font"),err);
11903 }
11904
11905 static GMenuItem2 mmlist[] = {
11906 /* GT: Here (and following) MM means "MultiMaster" */
11907 { { (unichar_t *) N_("MM _Reblend"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, '\0' }, H_("MM Reblend|No Shortcut"), NULL, NULL, CVMenuReblend, CV_MID_MMReblend },
11908 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
11909 { { (unichar_t *) N_("_View"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, '\0' }, NULL, mvlist, mvlistcheck, NULL, 0 },
11910 GMENUITEM2_EMPTY
11911 };
11912
11913 static void CVMenuShowSubChar(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11914 CharView *cv = (CharView *) GDrawGetUserData(gw);
11915 SplineFont *new = mi->ti.userdata;
11916 /* Change to the same char in a different instance font of the mm */
11917
11918 CVChangeSC(cv,SFMakeChar(new,cv->b.fv->map,CVCurEnc(cv)));
11919 cv->b.layerheads[dm_grid] = &new->grid;
11920 }
11921
11922 static void mmlistcheck(GWindow gw, struct gmenuitem *mi, GEvent *UNUSED(e)) {
11923 CharView *cv = (CharView *) GDrawGetUserData(gw);
11924 int i, base, j;
11925 MMSet *mm = cv->b.sc->parent->mm;
11926 SplineFont *sub;
11927 GMenuItem2 *mml;
11928
11929 base = sizeof(mmlist)/sizeof(mmlist[0]);
11930 if ( mm==NULL )
11931 mml = mmlist;
11932 else {
11933 mml = calloc(base+mm->instance_count+2,sizeof(GMenuItem2));
11934 memcpy(mml,mmlist,sizeof(mmlist));
11935 mml[base-1].ti.fg = mml[base-1].ti.bg = COLOR_DEFAULT;
11936 mml[base-1].ti.line = true;
11937 for ( j = 0, i=base; j<mm->instance_count+1; ++i, ++j ) {
11938 if ( j==0 )
11939 sub = mm->normal;
11940 else
11941 sub = mm->instances[j-1];
11942 mml[i].ti.text = uc_copy(sub->fontname);
11943 mml[i].ti.checkable = true;
11944 mml[i].ti.checked = sub==cv->b.sc->parent;
11945 mml[i].ti.userdata = sub;
11946 mml[i].invoke = CVMenuShowSubChar;
11947 mml[i].ti.fg = mml[i].ti.bg = COLOR_DEFAULT;
11948 }
11949 }
11950 mml[0].ti.disabled = (mm==NULL || cv->b.sc->parent!=mm->normal || mm->apple);
11951 GMenuItemArrayFree(mi->sub);
11952 mi->sub = GMenuItem2ArrayCopy(mml,NULL);
11953 if ( mml!=mmlist ) {
11954 for ( i=base; mml[i].ti.text!=NULL; ++i )
11955 free( mml[i].ti.text);
11956 free(mml);
11957 }
11958 }
11959
11960 static void CVMenuContextualHelp(GWindow UNUSED(gw), struct gmenuitem *UNUSED(mi), GEvent *UNUSED(e)) {
11961 help("ui/mainviews/charview.html", NULL);
11962 }
11963
11964 static GMenuItem2 mblist[] = {
11965 { { (unichar_t *) N_("_File"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("File|No Shortcut"), fllist, fllistcheck, NULL, 0 },
11966 { { (unichar_t *) N_("_Edit"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'E' }, H_("Edit|No Shortcut"), edlist, edlistcheck, NULL, 0 },
11967 { { (unichar_t *) N_("_Point"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Point|No Shortcut"), ptlist, ptlistcheck, NULL, 0 },
11968 { { (unichar_t *) N_("E_lement"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'l' }, H_("Element|No Shortcut"), ellist, ellistcheck, NULL, 0 },
11969 #ifndef _NO_PYTHON
11970 { { (unichar_t *) N_("_Tools"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'l' }, H_("Tools|No Shortcut"), NULL, cvpy_tllistcheck, NULL, 0 },
11971 #endif
11972 { { (unichar_t *) N_("H_ints"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'H' }, H_("Hints|No Shortcut"), htlist, htlistcheck, NULL, 0 },
11973 { { (unichar_t *) N_("_View"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'V' }, H_("View|No Shortcut"), vwlist, vwlistcheck, NULL, 0 },
11974 { { (unichar_t *) N_("_Metrics"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Metrics|No Shortcut"), mtlist, mtlistcheck, NULL, 0 },
11975 /* GT: Here (and following) MM means "MultiMaster" */
11976 { { (unichar_t *) N_("MM"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, '\0' }, H_("MM|No Shortcut"), mmlist, mmlistcheck, NULL, 0 },
11977 { { (unichar_t *) N_("_Window"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'W' }, H_("Window|No Shortcut"), wnmenu, CVWindowMenuBuild, NULL, 0 },
11978 { { (unichar_t *) N_("_Help"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'H' }, H_("Help|No Shortcut"), helplist, NULL, NULL, 0 },
11979 GMENUITEM2_EMPTY
11980 };
11981
11982 static GMenuItem2 mblist_nomm[] = {
11983 { { (unichar_t *) N_("_File"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("File|No Shortcut"), fllist, fllistcheck, NULL, 0 },
11984 { { (unichar_t *) N_("_Edit"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'E' }, H_("Edit|No Shortcut"), edlist, edlistcheck, NULL, 0 },
11985 { { (unichar_t *) N_("_Point"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Point|No Shortcut"), ptlist, ptlistcheck, NULL, 0 },
11986 { { (unichar_t *) N_("E_lement"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'l' }, H_("Element|No Shortcut"), ellist, ellistcheck, NULL, 0 },
11987 #ifndef _NO_PYTHON
11988 { { (unichar_t *) N_("_Tools"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 1, 0, 0, 0, 0, 0, 1, 1, 0, 'l' }, H_("Tools|No Shortcut"), NULL, cvpy_tllistcheck, NULL, 0 },
11989 #endif
11990 { { (unichar_t *) N_("H_ints"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'H' }, H_("Hints|No Shortcut"), htlist, htlistcheck, NULL, 0 },
11991 { { (unichar_t *) N_("_View"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'V' }, H_("View|No Shortcut"), vwlist, vwlistcheck, NULL, 0 },
11992 { { (unichar_t *) N_("_Metrics"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Metrics|No Shortcut"), mtlist, mtlistcheck, NULL, 0 },
11993 { { (unichar_t *) N_("_Window"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'W' }, H_("Window|No Shortcut"), wnmenu, CVWindowMenuBuild, NULL, 0 },
11994 { { (unichar_t *) N_("_Help"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'H' }, H_("Help|No Shortcut"), helplist, NULL, NULL, 0 },
11995 GMENUITEM2_EMPTY
11996 };
11997
11998 static void _CharViewCreate(CharView *cv, SplineChar *sc, FontView *fv,int enc,int show) {
11999 CharViewTab* tab = CVGetActiveTab(cv);
12000 GRect pos;
12001 GWindowAttrs wattrs;
12002 GGadgetData gd;
12003 int sbsize;
12004 int as, ds, ld;
12005 extern int updateflex;
12006 GTextBounds textbounds;
12007 /* extern int cv_auto_goto; */
12008 extern enum cvtools cv_b1_tool, cv_cb1_tool, cv_b2_tool, cv_cb2_tool;
12009
12010 CVColInit();
12011
12012 static int firstCharView = 1;
12013 if( firstCharView )
12014 {
12015 firstCharView = 0;
12016 CVShows.alwaysshowcontrolpoints = prefs_cv_show_control_points_always_initially;
12017 }
12018
12019 cv->b.sc = sc;
12020 tab->scale = .5;
12021 tab->xoff = tab->yoff = 20;
12022 cv->b.next = sc->views;
12023 sc->views = &cv->b;
12024 cv->b.fv = &fv->b;
12025 cv->map_of_enc = fv->b.map;
12026 cv->enc = enc;
12027 cv->p.pretransform_spl = NULL;
12028 cv->b.drawmode = dm_fore;
12029
12030 memset(cv->showback,-1,sizeof(cv->showback));
12031 if ( !CVShows.showback )
12032 cv->showback[0] &= ~1;
12033 cv->showfore = CVShows.showfore;
12034 cv->showgrids = CVShows.showgrids;
12035 cv->showhhints = CVShows.showhhints;
12036 cv->showvhints = CVShows.showvhints;
12037 cv->showdhints = CVShows.showdhints;
12038 cv->showpoints = CVShows.showpoints;
12039 cv->alwaysshowcontrolpoints = CVShows.alwaysshowcontrolpoints;
12040 cv->showrulers = CVShows.showrulers;
12041 cv->showfilled = CVShows.showfilled;
12042 cv->showrounds = CVShows.showrounds;
12043 cv->showmdx = CVShows.showmdx;
12044 cv->showmdy = CVShows.showmdy;
12045 cv->showhmetrics = CVShows.showhmetrics;
12046 cv->showvmetrics = sc->parent->hasvmetrics ? CVShows.showvmetrics : 0;
12047 cv->markextrema = CVShows.markextrema;
12048 cv->showsidebearings = CVShows.showsidebearings;
12049 cv->showrefnames = CVShows.showrefnames;
12050 cv->snapoutlines = CVShows.snapoutlines;
12051 cv->markpoi = CVShows.markpoi;
12052 cv->showalmosthvlines = CVShows.showalmosthvlines;
12053 cv->showalmosthvcurves = CVShows.showalmosthvcurves;
12054 cv->hvoffset = CVShows.hvoffset;
12055 cv->showblues = CVShows.showblues;
12056 cv->showfamilyblues = CVShows.showfamilyblues;
12057 cv->showanchor = CVShows.showanchor;
12058 cv->showcpinfo = CVShows.showcpinfo;
12059 cv->showtabs = CVShows.showtabs;
12060 cv->inPreviewMode = 0;
12061 cv->checkselfintersects = CVShows.checkselfintersects;
12062
12063 cv->showdebugchanges = CVShows.showdebugchanges;
12064
12065 cv->infoh = 13;
12066 #if defined(__MINGW32__)||defined(__CYGWIN__)
12067 cv->infoh = 26;
12068 #endif
12069 cv->rulerh = 16;
12070
12071 GDrawGetSize(cv->gw,&pos);
12072 memset(&gd,0,sizeof(gd));
12073 gd.pos.y = cv->mbh+cv->charselectorh+cv->infoh;
12074 gd.pos.width = sbsize = GDrawPointsToPixels(cv->gw,_GScrollBar_Width);
12075 gd.pos.height = pos.height-cv->mbh-cv->charselectorh-cv->infoh - sbsize;
12076 gd.pos.x = pos.width-sbsize;
12077 gd.flags = gg_visible|gg_enabled|gg_pos_in_pixels|gg_sb_vert;
12078 cv->vsb = GScrollBarCreate(cv->gw,&gd,cv);
12079
12080 gd.pos.y = pos.height-sbsize; gd.pos.height = sbsize;
12081 gd.pos.width = pos.width - sbsize;
12082 gd.pos.x = 0;
12083 gd.flags = gg_visible|gg_enabled|gg_pos_in_pixels|gg_text_xim;
12084 cv->hsb = GScrollBarCreate(cv->gw,&gd,cv);
12085
12086 GDrawGetSize(cv->gw,&pos);
12087 pos.y = cv->mbh+cv->charselectorh+cv->infoh; pos.height -= cv->mbh + cv->charselectorh + sbsize + cv->infoh;
12088 pos.x = 0; pos.width -= sbsize;
12089 if ( cv->showrulers ) {
12090 pos.y += cv->rulerh; pos.height -= cv->rulerh;
12091 pos.x += cv->rulerh; pos.width -= cv->rulerh;
12092 }
12093 memset(&wattrs,0,sizeof(wattrs));
12094 wattrs.mask = wam_events|wam_cursor|wam_backcol;
12095 wattrs.background_color = view_bgcol;
12096 wattrs.event_masks = -1;
12097 wattrs.cursor = ct_mypointer;
12098 cv->v = GWidgetCreateSubWindow(cv->gw,&pos,v_e_h,cv,&wattrs);
12099 GDrawSetWindowTypeName(cv->v, "CharView");
12100
12101 if ( GDrawRequestDeviceEvents(cv->v,input_em_cnt,input_em)>0 ) {
12102 /* Success! They've got a wacom tablet */
12103 }
12104
12105 cv->small = cv_pointnumberfont.fi;
12106 GDrawWindowFontMetrics(cv->gw,cv->small,&as,&ds,&ld);
12107 cv->sfh = as+ds; cv->sas = as;
12108 GDrawSetFont(cv->gw,cv->small);
12109 GDrawGetText8Bounds(cv->gw,"0123456789",10,&textbounds);
12110 cv->sdh = textbounds.as+textbounds.ds+1;
12111 cv->normal = cv_labelfont.fi;
12112 GDrawWindowFontMetrics(cv->gw,cv->normal,&as,&ds,&ld);
12113 cv->nfh = as+ds; cv->nas = as;
12114
12115 cv->height = pos.height; cv->width = pos.width;
12116 cv->b1_tool = cv_b1_tool; cv->cb1_tool = cv_cb1_tool;
12117 cv->b1_tool_old = cv->b1_tool;
12118 cv->b2_tool = cv_b2_tool; cv->cb2_tool = cv_cb2_tool;
12119 cv->s1_tool = cvt_freehand; cv->s2_tool = cvt_pen;
12120 cv->er_tool = cvt_knife;
12121 cv->showing_tool = cvt_pointer;
12122 cv->pressed_tool = cv->pressed_display = cv->active_tool = cvt_none;
12123 cv->spacebar_hold = 0;
12124 cv->b.layerheads[dm_fore] = &sc->layers[ly_fore];
12125 cv->b.layerheads[dm_back] = &sc->layers[ly_back];
12126 cv->b.layerheads[dm_grid] = &fv->b.sf->grid;
12127 if ( !sc->parent->multilayer && fv->b.active_layer!=ly_fore ) {
12128 cv->b.layerheads[dm_back] = &sc->layers[fv->b.active_layer];
12129 cv->b.drawmode = dm_back;
12130 }
12131
12132 #if HANYANG
12133 if ( sc->parent->rules!=NULL && sc->compositionunit )
12134 Disp_DefaultTemplate(cv);
12135 #endif
12136
12137 cv->olde.x = -1;
12138
12139 cv->ft_dpi = 72; cv->ft_pointsizex = cv->ft_pointsizey = 12.0;
12140 cv->ft_ppemx = cv->ft_ppemy = 12;
12141
12142 /*cv->tools = CVMakeTools(cv);*/
12143 /*cv->layers = CVMakeLayers(cv);*/
12144
12145 CVFit(cv);
12146 GDrawSetVisible(cv->v,true);
12147 GWindowClearFocusGadgetOfWindow(cv->v);
12148
12149 /*if ( cv_auto_goto )*/ /* Chinese input method steals hot key key-strokes */
12150 /* But if we don't do this, then people can't type menu short-cuts */
12151 cv->gic = GDrawCreateInputContext(cv->v,gic_root|gic_orlesser);
12152 GDrawSetGIC(cv->v,cv->gic,0,20);
12153 cv->gwgic = GDrawCreateInputContext(cv->gw,gic_root|gic_orlesser);
12154 GDrawSetGIC(cv->gw,cv->gwgic,0,20);
12155 if( show )
12156 {
12157 GDrawSetVisible(cv->gw,true);
12158 }
12159
12160 if ( (CharView *) (sc->views)==NULL && updateflex )
12161 SplineCharIsFlexible(sc,CVLayer((CharViewBase *) cv));
12162 if ( sc->inspiro && !hasspiro() && !sc->parent->complained_about_spiros ) {
12163 sc->parent->complained_about_spiros = true;
12164 #ifdef _NO_LIBSPIRO
12165 ff_post_error(_("You may not use spiros"),_("This glyph should display spiro points, but unfortunately this version of fontforge was not linked with the spiro library, so only normal bezier points will be displayed."));
12166 #else
12167 ff_post_error(_("You may not use spiros"),_("This glyph should display spiro points, but unfortunately FontForge was unable to load libspiro, spiros are not available for use, and normal bezier points will be displayed instead."));
12168 #endif
12169 }
12170
12171 }
12172
12173 void DefaultY(GRect *pos) {
12174 static int nexty=0;
12175 GRect size;
12176
12177 GDrawGetSize(GDrawGetRoot(NULL),&size);
12178 if ( nexty!=0 ) {
12179 FontView *fv;
12180 int any=0, i;
12181 BDFFont *bdf;
12182 /* are there any open cv/bv windows? */
12183 for ( fv = fv_list; fv!=NULL && !any; fv = (FontView *) (fv->b.next) ) {
12184 for ( i=0; i<fv->b.sf->glyphcnt; ++i ) if ( fv->b.sf->glyphs[i]!=NULL ) {
12185 if ( fv->b.sf->glyphs[i]->views!=NULL ) {
12186 any = true;
12187 break;
12188 }
12189 }
12190 for ( bdf = fv->b.sf->bitmaps; bdf!=NULL && !any; bdf=bdf->next ) {
12191 for ( i=0; i<bdf->glyphcnt; ++i ) if ( bdf->glyphs[i]!=NULL ) {
12192 if ( bdf->glyphs[i]->views!=NULL ) {
12193 any = true;
12194 break;
12195 }
12196 }
12197 }
12198 }
12199 if ( !any ) nexty = 0;
12200 }
12201 pos->y = nexty;
12202 nexty += 200;
12203 if ( nexty+pos->height > size.height )
12204 nexty = 0;
12205 }
12206
12207 static void CharViewInit(void);
12208
12209 static int CV_OnCharSelectorTextChanged( GGadget *g, GEvent *e )
12210 {
12211 CharView* cv = GGadgetGetUserData(g);
12212 CharViewTab* tab = CVGetActiveTab(cv);
12213 SplineChar *sc = cv->b.sc;
12214 SplineFont* sf = sc->parent;
12215
12216 if ( e->type==et_controlevent && e->u.control.subtype == et_textchanged )
12217 {
12218 int pos = e->u.control.u.tf_changed.from_pulldown;
12219
12220 if ( pos!=-1 )
12221 {
12222 int32_t len;
12223 GTextInfo **ti = GGadgetGetList(g,&len);
12224 GTextInfo *cur = ti[pos];
12225 int type = (intptr_t) cur->userdata;
12226 if ( type < 0 )
12227 {
12228 TRACE("load wordlist...! pos:%d\n",pos);
12229
12230 WordlistLoadToGTextInfo( cv->charselector, &cv->charselectoridx );
12231 return 0;
12232 }
12233 }
12234
12235 cv->charselectoridx = pos;
12236 char* txt = GGadgetGetTitle8( cv->charselector );
12237 TRACE("char selector @%d changed to:%s\n", pos, txt );
12238 {
12239 int tabnum = GTabSetGetSel(cv->tabs);
12240 CharViewTab* t = &cv->cvtabs[tabnum];
12241 strncpy( t->tablabeltxt, txt, charviewtab_charselectedsz );
12242 TRACE("tab num: %d set to %s\n", tabnum, t->tablabeltxt);
12243 GTabSetChangeTabName(cv->tabs,t->tablabeltxt,tabnum);
12244 GTabSetRemetric(cv->tabs);
12245 GTabSetSetSel(cv->tabs,tabnum); /* This does a redraw */
12246 }
12247
12248 memset( cv->additionalCharsToShow, 0, sizeof(SplineChar*) * additionalCharsToShowLimit );
12249 cv->additionalCharsToShowActiveIndex = 0;
12250 cv->additionalCharsToShow[0] = cv->b.sc;
12251
12252 int hadSelection = 0;
12253 if( txt[0] == '\0' )
12254 {
12255 CVSetCharSelectorValueFromSC( cv, cv->b.sc );
12256 }
12257 else if( strlen(txt) > 1 )
12258 {
12259 int i=0;
12260 unichar_t *ret = GGadgetGetTitle( cv->charselector );
12261 WordListLine wll = WordlistEscapedInputStringToParsedData( sf, ret );
12262 WordListLine pt = wll;
12263 WordListLine ept = WordListLine_end(wll);
12264 WordListLine tpt = 0;
12265 for ( tpt=pt; tpt<ept; ++tpt )
12266 {
12267 if( tpt == pt )
12268 {
12269 // your own char at the leading of the text
12270 cv->additionalCharsToShow[i] = tpt->sc;
12271 i++;
12272 continue;
12273 }
12274
12275 cv->additionalCharsToShow[i] = tpt->sc;
12276
12277 i++;
12278 if( i >= additionalCharsToShowLimit )
12279 break;
12280 }
12281 free(ret);
12282
12283 if( wll->sc )
12284 {
12285 if( wll->isSelected )
12286 {
12287 // first char selected, nothing to do!
12288 }
12289 else
12290 {
12291 while( wll->sc && !(wll->isSelected))
12292 wll++;
12293 if( wll->sc && wll->isSelected )
12294 {
12295 SplineChar* xc = wll->sc;
12296 if( xc )
12297 {
12298 TRACE("selected v:%d xc:%s\n", wll->currentGlyphIndex, xc->name );
12299 int xoff = tab->xoff;
12300 CVSwitchActiveSC( cv, xc, wll->currentGlyphIndex );
12301 CVHScrollSetPos( cv, xoff );
12302 hadSelection = 1;
12303 }
12304
12305 }
12306 }
12307 }
12308 }
12309 free(txt);
12310
12311 int i=0;
12312 for( i=0; cv->additionalCharsToShow[i]; i++ )
12313 {
12314 TRACE("i:%d %p .. ", i, cv->additionalCharsToShow[i] );
12315 TRACE(" %s\n", cv->additionalCharsToShow[i]->name );
12316 }
12317
12318 if( !hadSelection )
12319 CVSwitchActiveSC( cv, 0, 0 );
12320 GDrawRequestExpose(cv->v,NULL,false);
12321 }
12322 return( true );
12323 }
12324
12325 GTextInfo cv_charselector_init[] = {
12326 { (unichar_t *) "", NULL, 0, 0, NULL, NULL, 0, 0, 0, 0, 1, 0, 1, 0, 0, '\0'},
12327 { NULL, NULL, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 1, 0, 0, 0, '\0'},
12328 { (unichar_t *) N_("Load Word List..."), NULL, 0, 0, (void *) -1, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0'},
12329 // { (unichar_t *) N_("Load Glyph Name List..."), NULL, 0, 0, (void *) -2, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0'},
12330 GTEXTINFO_EMPTY
12331 };
12332
12333 CharView *CharViewCreateExtended(SplineChar *sc, FontView *fv,int enc, int show )
12334 {
12335 CharView *cv = calloc(1,sizeof(CharView));
12336 GWindowAttrs wattrs;
12337 GRect pos, zoom;
12338 GWindow gw;
12339 GGadgetData gd;
12340 GTabInfo aspects[2];
12341 GRect gsize;
12342 char buf[300];
12343 GTextInfo label[9];
12344
12345 CharViewInit();
12346
12347 cv->b.sc = sc;
12348 cv->b.fv = &fv->b;
12349 cv->enc = enc;
12350 cv->map_of_enc = fv->b.map; /* I know this is done again in _CharViewCreate, but it needs to be done before creating the title */
12351
12352 cv->infoh = 13;
12353 #if defined(__MINGW32__)||defined(__CYGWIN__)
12354 cv->infoh = 26;
12355 #endif
12356 cv->rulerh = 16;
12357
12358 cv->ctpos = -1;
12359
12360
12361 SCLigCaretCheck(sc,false);
12362
12363 memset(&wattrs,0,sizeof(wattrs));
12364 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_utf8_ititle;
12365 wattrs.event_masks = -1;
12366 wattrs.cursor = ct_mypointer;
12367 wattrs.utf8_icon_title = (const char*)CVMakeTitles(cv,buf,sizeof(buf));
12368 wattrs.utf8_window_title = buf;
12369 wattrs.icon = CharIcon(cv, fv);
12370 if ( wattrs.icon )
12371 wattrs.mask |= wam_icon;
12372 pos.x = GGadgetScale(104)+6;
12373 pos.width = (cv_width > 0) ? cv_width : default_cv_width;
12374 pos.height = (cv_height > 0) ? cv_height : default_cv_height;
12375 DefaultY(&pos);
12376
12377 cv->gw = gw = GDrawCreateTopWindow(NULL,&pos,cv_e_h,cv,&wattrs);
12378 free( (unichar_t *) wattrs.icon_title );
12379 free((char*)wattrs.utf8_icon_title);
12380 GDrawSetWindowTypeName(cv->gw, "CharView");
12381
12382 // FIXME: cant do this until gw is shown?
12383 GTextBounds textbounds;
12384 GDrawGetText8Bounds(cv->gw,"0123456789hl",10,&textbounds);
12385 TRACE("XXXXXX as:%d ds:%d\n", textbounds.as, textbounds.ds );
12386 cv->charselectorh = textbounds.as+textbounds.ds+1;
12387 TRACE("XXXXXX h:%d\n", GDrawGetText8Height( cv->gw, "0123456AZgplh", 10));
12388 cv->charselectorh = 35;
12389
12390
12391 GDrawGetSize(GDrawGetRoot(screen_display),&zoom);
12392 zoom.x = CVPalettesWidth(); zoom.width -= zoom.x-10;
12393 zoom.height -= 30; /* Room for title bar & such */
12394 GDrawSetZoom(gw,&zoom,-1);
12395
12396 memset(&gd,0,sizeof(gd));
12397 gd.flags = gg_visible | gg_enabled;
12398 helplist[0].invoke = CVMenuContextualHelp;
12399 gd.u.menu2 = sc->parent->mm==NULL ? mblist_nomm : mblist;
12400 cv->mb = GMenu2BarCreate( gw, &gd, NULL);
12401 GGadgetGetSize(cv->mb,&gsize);
12402 cv->mbh = gsize.height;
12403
12404 // TRACE("pos.x:%d pos.y:%d pos.w:%d pos.h:%d\n", pos.x, pos.y, pos.width, pos.height );
12405 GDrawGetSize(cv->gw,&pos);
12406 memset(&gd,0,sizeof(gd));
12407 // gd.pos.x = pos.x;
12408 gd.pos.x = 3;
12409 gd.pos.y = cv->mbh+2;
12410 gd.pos.height = cv->charselectorh-4;
12411 gd.pos.width = cv_width / 2;
12412 gd.flags = gg_visible|gg_enabled|gg_pos_in_pixels|gg_text_xim;
12413 gd.handle_controlevent = CV_OnCharSelectorTextChanged;
12414 gd.u.list = cv_charselector_init;
12415 cv->charselector = GListFieldCreate(cv->gw,&gd,cv);
12416 CVSetCharSelectorValueFromSC( cv, sc );
12417 GGadgetSetSkipUnQualifiedHotkeyProcessing( cv->charselector, 1 );
12418
12419 // Up and Down buttons for moving through the word list.
12420 {
12421 GGadgetData xgd = gd;
12422 gd.pos.width += 2 * xgd.pos.height + 4;
12423 memset(label, '\0', sizeof(GTextInfo));
12424 xgd.pos.x += xgd.pos.width + 2;
12425 xgd.pos.width = xgd.pos.height;
12426 xgd.flags = gg_visible|gg_enabled|gg_pos_in_pixels;
12427 xgd.handle_controlevent = CVMoveToPrevInWordList;
12428 xgd.label = &label[0];
12429 label[0].text = (unichar_t *) "⇞";
12430 label[0].text_is_1byte = true;
12431 cv->charselectorPrev = GButtonCreate(cv->gw,&xgd,cv);
12432 memset(label, '\0', sizeof(GTextInfo));
12433 xgd.pos.x += xgd.pos.width + 2;
12434 xgd.pos.width = xgd.pos.height;
12435 xgd.flags = gg_visible|gg_enabled|gg_pos_in_pixels;
12436 xgd.handle_controlevent = CVMoveToNextInWordList;
12437 xgd.label = &label[0];
12438 label[0].text = (unichar_t *) "⇟";
12439 label[0].text_is_1byte = true;
12440 cv->charselectorNext = GButtonCreate(cv->gw,&xgd,cv);
12441 }
12442
12443
12444 memset(aspects,0,sizeof(aspects));
12445 aspects[0].text = (unichar_t *) sc->name;
12446 aspects[0].text_is_1byte = true;
12447 /* NOT visible until we add a second glyph to the stack */
12448 gd.flags = gg_enabled|gg_tabset_nowindow|gg_tabset_scroll|gg_pos_in_pixels;
12449 gd.u.menu = NULL;
12450 gd.u.tabs = aspects;
12451 gd.pos.x = 0;
12452 gd.pos.y = cv->mbh;
12453 gd.handle_controlevent = CVChangeToFormer;
12454 cv->tabs = GTabSetCreate( gw, &gd, NULL );
12455 cv->former_cnt = 1;
12456 cv->former_names[0] = copy(sc->name);
12457 GTabSetSetClosable(cv->tabs, true);
12458 GTabSetSetMovable(cv->tabs, true);
12459 GTabSetSetRemoveSync(cv->tabs, CVTabSetRemoveSync);
12460 GTabSetSetSwapSync(cv->tabs, CVTabSetSwapSync);
12461 GGadgetTakesKeyboard(cv->tabs,false);
12462
12463 _CharViewCreate( cv, sc, fv, enc, show );
12464 // Frank wants to avoid needing to implement scaling twice.
12465 CVResize(cv);
12466
12467 return( cv );
12468 }
12469
12470 CharView *CharViewCreate(SplineChar *sc, FontView *fv,int enc)
12471 {
12472 return CharViewCreateExtended( sc, fv, enc, 1 );
12473 }
12474
12475 void CharViewFree(CharView *cv) {
12476 int i;
12477
12478 if ( cv->qg != NULL )
12479 QGRmCharView(cv->qg,cv);
12480 if ( cv->ruler_w ) {
12481 GDrawDestroyWindow(cv->ruler_w);
12482 cv->ruler_w = NULL;
12483 }
12484 if ( cv->ruler_linger_w ) {
12485 GDrawDestroyWindow(cv->ruler_linger_w);
12486 cv->ruler_linger_w = NULL;
12487 }
12488 #if HANYANG
12489 if ( cv->jamodisplay!=NULL )
12490 Disp_DoFinish(cv->jamodisplay,true);
12491 #endif
12492
12493 CVDebugFree(cv->dv);
12494
12495 SplinePointListsFree(cv->b.gridfit);
12496 FreeType_FreeRaster(cv->oldraster);
12497 FreeType_FreeRaster(cv->raster);
12498
12499 CVDebugFree(cv->dv);
12500
12501 for ( i=0; i<cv->former_cnt; ++i )
12502 free(cv->former_names[i]);
12503
12504 free(cv->ruler_intersections);
12505 free(cv);
12506 }
12507
12508 int CVValid(SplineFont *sf, SplineChar *sc, CharView *cv) {
12509 /* A charview may have been closed. A splinechar may have been removed */
12510 /* from a font */
12511 CharView *test;
12512
12513 if ( cv==NULL )
12514 return( false );
12515 if ( cv->b.sc!=sc || sc->parent!=sf )
12516 return( false );
12517 if ( sc->orig_pos<0 || sc->orig_pos>sf->glyphcnt )
12518 return( false );
12519 if ( sf->glyphs[sc->orig_pos]!=sc )
12520 return( false );
12521 for ( test=(CharView *) (sc->views); test!=NULL; test=(CharView *) (test->b.next) )
12522 if ( test==cv )
12523 return( true );
12524
12525 return( false );
12526 }
12527
12528 static int charview_ready = false;
12529
12530 static void CharViewFinish() {
12531 // The memory leak is limited and reachable.
12532 if ( !charview_ready ) return;
12533 charview_ready = false;
12534 mb2FreeGetText(mblist);
12535 mb2FreeGetText(spiroptlist);
12536 int i;
12537 for ( i=0; mblist_nomm[i].ti.text!=NULL; ++i ) {
12538 free(mblist_nomm[i].ti.text_untranslated); mblist_nomm[i].ti.text_untranslated = NULL;
12539 }
12540 }
12541
12542 void CharViewFinishNonStatic() {
12543 CharViewFinish();
12544 }
12545
12546 #ifndef _NO_PYTHON
12547 void CVSetToolsSubmenu(GMenuItem2 *py_menu) {
12548 mblist[4].ti.disabled = mblist_nomm[4].ti.disabled = (py_menu == NULL);
12549 mblist[4].sub = mblist_nomm[4].sub = py_menu;
12550 }
12551 static GMenuItem2 *CVGetToolsSubmenu(void) {
12552 return mblist[4].sub;
12553 }
12554 #endif
12555
12556 static void CharViewInit(void) {
12557 int i;
12558 // static int done = false; // superseded by charview_ready.
12559
12560 if ( charview_ready )
12561 return;
12562 charview_ready = true;
12563 // TRACE("CharViewInit(top) mblist[0].text before translation: %s\n", mblist[0].ti.text );
12564
12565 // The tools menu handles its own translation. I would rather do this by testing
12566 // whether ti.text_untranslated is already null but there are hundreds of missing
12567 // initializers for that field in the menu layout code.
12568 #ifndef _NO_PYTHON
12569 GMenuItem2 *t = CVGetToolsSubmenu();
12570 CVSetToolsSubmenu(NULL);
12571 #endif
12572 mb2DoGetText(mblist);
12573 #ifndef _NO_PYTHON
12574 CVSetToolsSubmenu(t);
12575 #endif
12576
12577 // TRACE("CharViewInit(2) mblist[0].text after translation: %s\n", u_to_c(mblist[0].ti.text) );
12578 // TRACE("CharViewInit(2) mblist[0].text_untranslated notrans: %s\n", mblist[0].ti.text_untranslated );
12579
12580 mb2DoGetText(spiroptlist);
12581 for ( i=0; mblist_nomm[i].ti.text!=NULL; ++i )
12582 {
12583 // Note that because we are doing this ourself we have to set
12584 // the text_untranslated ourself too.
12585 if( mblist_nomm[i].shortcut )
12586 mblist_nomm[i].ti.text_untranslated = copy(mblist_nomm[i].shortcut);
12587 else
12588 mblist_nomm[i].ti.text_untranslated = copy((char*)mblist_nomm[i].ti.text);
12589
12590 mblist_nomm[i].ti.text = (unichar_t *) _((char *) mblist_nomm[i].ti.text);
12591 }
12592 atexit(&CharViewFinishNonStatic);
12593 }
12594
12595 static int nested_cv_e_h(GWindow gw, GEvent *event) {
12596 CharView *cv = (CharView *) GDrawGetUserData(gw);
12597
12598 switch ( event->type ) {
12599 case et_expose:
12600 InfoExpose(cv,gw,event);
12601 CVLogoExpose(cv,gw,event);
12602 break;
12603 case et_char:
12604 (cv->b.container->funcs->charEvent)(cv->b.container,event);
12605 break;
12606 case et_charup:
12607 CVCharUp(cv,event);
12608 break;
12609 case et_controlevent:
12610 switch ( event->u.control.subtype ) {
12611 case et_scrollbarchange:
12612 if ( event->u.control.g == cv->hsb )
12613 CVHScroll(cv,&event->u.control.u.sb);
12614 else
12615 CVVScroll(cv,&event->u.control.u.sb);
12616 break;
12617 default: break;
12618 }
12619 break;
12620 case et_map:
12621 if ( event->u.map.is_visible )
12622 CVPaletteActivate(cv);
12623 else
12624 CVPalettesHideIfMine(cv);
12625 break;
12626 case et_resize:
12627 if ( event->u.resize.sized )
12628 CVResize(cv);
12629 break;
12630 case et_mouseup: case et_mousedown:
12631 GGadgetEndPopup();
12632 CVPaletteActivate(cv);
12633 break;
12634 default: break;
12635 }
12636 return( true );
12637 }
12638
12639 void SVCharViewInits(SearchView *sv) {
12640 GGadgetData gd;
12641 GWindowAttrs wattrs;
12642 GRect pos, gsize;
12643
12644 CharViewInit();
12645
12646 memset(&gd,0,sizeof(gd));
12647 gd.flags = gg_visible | gg_enabled;
12648 helplist[0].invoke = CVMenuContextualHelp;
12649 gd.u.menu2 = mblist_nomm;
12650 sv->mb = GMenu2BarCreate( sv->gw, &gd, NULL);
12651 GGadgetGetSize(sv->mb,&gsize);
12652 sv->mbh = gsize.height;
12653
12654 pos.y = sv->mbh+sv->fh+10; pos.height = 220;
12655 pos.width = pos.height; pos.x = 10+pos.width+20; /* Do replace first so palettes appear properly */
12656 sv->rpl_x = pos.x; sv->cv_y = pos.y;
12657 sv->cv_height = pos.height; sv->cv_width = pos.width;
12658 memset(&wattrs,0,sizeof(wattrs));
12659 wattrs.mask = wam_events|wam_cursor;
12660 wattrs.event_masks = -1;
12661 wattrs.cursor = ct_mypointer;
12662 sv->cv_rpl.gw = GWidgetCreateSubWindow(sv->gw,&pos,nested_cv_e_h,&sv->cv_rpl,&wattrs);
12663 _CharViewCreate(&sv->cv_rpl, &sv->sd.sc_rpl, &sv->dummy_fv, 1, 1);
12664
12665 pos.x = 10;
12666 sv->cv_srch.gw = GWidgetCreateSubWindow(sv->gw,&pos,nested_cv_e_h,&sv->cv_srch,&wattrs);
12667 _CharViewCreate(&sv->cv_srch, &sv->sd.sc_srch, &sv->dummy_fv, 0, 1);
12668 }
12669
12670 /* Same for the MATH Kern dlg */
12671
12672 void MKDCharViewInits(MathKernDlg *mkd) {
12673 GGadgetData gd;
12674 GWindowAttrs wattrs;
12675 GRect pos, gsize;
12676 int i;
12677
12678 CharViewInit();
12679
12680 memset(&gd,0,sizeof(gd));
12681 gd.flags = gg_visible | gg_enabled;
12682 helplist[0].invoke = CVMenuContextualHelp;
12683 gd.u.menu2 = mblist_nomm;
12684 mkd->mb = GMenu2BarCreate( mkd->gw, &gd, NULL);
12685 GGadgetGetSize(mkd->mb,&gsize);
12686 mkd->mbh = gsize.height;
12687
12688 mkd->mid_space = 20;
12689 for ( i=3; i>=0; --i ) { /* Create backwards so palettes get set in topright (last created) */
12690 pos.y = mkd->fh+10; pos.height = 220; /* Size doesn't matter, adjusted later */
12691 pos.width = pos.height; pos.x = 10+i*(pos.width+20);
12692 mkd->cv_y = pos.y;
12693 mkd->cv_height = pos.height; mkd->cv_width = pos.width;
12694 memset(&wattrs,0,sizeof(wattrs));
12695 wattrs.mask = wam_events|wam_cursor;
12696 wattrs.event_masks = -1;
12697 wattrs.cursor = ct_mypointer;
12698 (&mkd->cv_topright)[i].gw = GWidgetCreateSubWindow(mkd->cvparent_w,&pos,nested_cv_e_h,(&mkd->cv_topright)+i,&wattrs);
12699 _CharViewCreate((&mkd->cv_topright)+i, (&mkd->sc_topright)+i, &mkd->dummy_fv, i, 1);
12700 }
12701 }
12702
12703 /* Same for the Tile Path dlg */
12704
12705 #ifdef FONTFORGE_CONFIG_TILEPATH
12706
12707 void TPDCharViewInits(TilePathDlg *tpd, int cid) {
12708 GGadgetData gd;
12709 GWindowAttrs wattrs;
12710 GRect pos, gsize;
12711 int i;
12712
12713 CharViewInit();
12714
12715 memset(&gd,0,sizeof(gd));
12716 gd.flags = gg_visible | gg_enabled;
12717 helplist[0].invoke = CVMenuContextualHelp;
12718 gd.u.menu2 = mblist_nomm;
12719 tpd->mb = GMenu2BarCreate( tpd->gw, &gd, NULL);
12720 GGadgetGetSize(tpd->mb,&gsize);
12721 tpd->mbh = gsize.height;
12722
12723 tpd->mid_space = 20;
12724 for ( i=3; i>=0; --i ) { /* Create backwards so palettes get set in topright (last created) */
12725 pos.y = 0; pos.height = 220; /* Size doesn't matter, adjusted later */
12726 pos.width = pos.height; pos.x = 0;
12727 tpd->cv_y = pos.y;
12728 tpd->cv_height = pos.height; tpd->cv_width = pos.width;
12729 memset(&wattrs,0,sizeof(wattrs));
12730 wattrs.mask = wam_events|wam_cursor;
12731 wattrs.event_masks = -1;
12732 wattrs.cursor = ct_mypointer;
12733 (&tpd->cv_first)[i].gw = GWidgetCreateSubWindow(GDrawableGetWindow(GWidgetGetControl(tpd->gw,cid+i)),
12734 &pos,nested_cv_e_h,(&tpd->cv_first)+i,&wattrs);
12735 _CharViewCreate((&tpd->cv_first)+i, (&tpd->sc_first)+i, &tpd->dummy_fv, i, 1 );
12736 }
12737 }
12738
12739 void PTDCharViewInits(TilePathDlg *tpd, int cid) {
12740 GGadgetData gd;
12741 GWindowAttrs wattrs;
12742 GRect pos, gsize;
12743
12744 CharViewInit();
12745
12746 memset(&gd,0,sizeof(gd));
12747 gd.flags = gg_visible | gg_enabled;
12748 helplist[0].invoke = CVMenuContextualHelp;
12749 gd.u.menu2 = mblist_nomm;
12750 tpd->mb = GMenu2BarCreate( tpd->gw, &gd, NULL);
12751 GGadgetGetSize(tpd->mb,&gsize);
12752 tpd->mbh = gsize.height;
12753
12754 tpd->mid_space = 20;
12755 {
12756 pos.y = 0; pos.height = 220; /* Size doesn't matter, adjusted later */
12757 pos.width = pos.height; pos.x = 0;
12758 tpd->cv_y = pos.y;
12759 tpd->cv_height = pos.height; tpd->cv_width = pos.width;
12760 memset(&wattrs,0,sizeof(wattrs));
12761 wattrs.mask = wam_events|wam_cursor;
12762 wattrs.event_masks = -1;
12763 wattrs.cursor = ct_mypointer;
12764 tpd->cv_first.gw = GWidgetCreateSubWindow(GDrawableGetWindow(GWidgetGetControl(tpd->gw,cid)),
12765 &pos,nested_cv_e_h,&tpd->cv_first,&wattrs);
12766 _CharViewCreate(&tpd->cv_first, &tpd->sc_first, &tpd->dummy_fv, 0, 1 );
12767 }
12768 }
12769 #endif /* TilePath */
12770
12771 void GDDCharViewInits(GradientDlg *gdd, int cid) {
12772 GGadgetData gd;
12773 GWindowAttrs wattrs;
12774 GRect pos, gsize;
12775
12776 CharViewInit();
12777
12778 memset(&gd,0,sizeof(gd));
12779 gd.flags = gg_visible | gg_enabled;
12780 helplist[0].invoke = CVMenuContextualHelp;
12781 gd.u.menu2 = mblist_nomm;
12782 gdd->mb = GMenu2BarCreate( gdd->gw, &gd, NULL);
12783 GGadgetGetSize(gdd->mb,&gsize);
12784 gdd->mbh = gsize.height;
12785
12786 memset(&wattrs,0,sizeof(wattrs));
12787 wattrs.mask = wam_events|wam_cursor;
12788 wattrs.event_masks = -1;
12789 wattrs.cursor = ct_mypointer;
12790
12791 pos.y = 1; pos.height = 220;
12792 pos.width = pos.height; pos.x = 0;
12793 gdd->cv_grad.gw = GWidgetCreateSubWindow(
12794 GDrawableGetWindow(GWidgetGetControl(gdd->gw,cid)),
12795 &pos,nested_cv_e_h,&gdd->cv_grad,&wattrs);
12796 _CharViewCreate(&gdd->cv_grad, &gdd->sc_grad, &gdd->dummy_fv, 0, 1 );
12797 }
12798
12799 void StrokeCharViewInits(StrokeDlg *sd, int cid) {
12800 GGadgetData gd;
12801 GWindowAttrs wattrs;
12802 GRect pos, gsize;
12803
12804 CharViewInit();
12805
12806 memset(&gd,0,sizeof(gd));
12807 gd.flags = gg_visible | gg_enabled;
12808 helplist[0].invoke = CVMenuContextualHelp;
12809 gd.u.menu2 = mblist_nomm;
12810 sd->mb = GMenu2BarCreate( sd->gw, &gd, NULL);
12811 GGadgetGetSize(sd->mb,&gsize);
12812 sd->mbh = gsize.height;
12813
12814 memset(&wattrs,0,sizeof(wattrs));
12815 wattrs.mask = wam_events|wam_cursor;
12816 wattrs.event_masks = -1;
12817 wattrs.cursor = ct_mypointer;
12818
12819 pos.y = 1; pos.height = 220;
12820 pos.width = pos.height; pos.x = 0;
12821 sd->cv_stroke.gw = GWidgetCreateSubWindow(
12822 GDrawableGetWindow(GWidgetGetControl(sd->gw,cid)),
12823 &pos,nested_cv_e_h,&sd->cv_stroke,&wattrs);
12824 _CharViewCreate(&sd->cv_stroke, &sd->sc_stroke, &sd->dummy_fv, 0, 1 );
12825 }
12826
12827 static void SC_CloseAllWindows(SplineChar *sc) {
12828 CharViewBase *cv, *next;
12829 BitmapView *bv, *bvnext;
12830 BDFFont *bdf;
12831 BDFChar *bfc;
12832 FontView *fvs;
12833
12834 if ( sc->views ) {
12835 for ( cv = sc->views; cv!=NULL; cv=next ) {
12836 next = cv->next;
12837 GDrawDestroyWindow(((CharView *) cv)->gw);
12838 }
12839 GDrawSync(NULL);
12840 GDrawProcessPendingEvents(NULL);
12841 GDrawSync(NULL);
12842 GDrawProcessPendingEvents(NULL);
12843 }
12844
12845 for ( bdf=sc->parent->bitmaps; bdf!=NULL; bdf = bdf->next ) {
12846 if ( sc->orig_pos<bdf->glyphcnt && (bfc = bdf->glyphs[sc->orig_pos])!= NULL ) {
12847 if ( bfc->views!=NULL ) {
12848 for ( bv= bfc->views; bv!=NULL; bv=bvnext ) {
12849 bvnext = bv->next;
12850 GDrawDestroyWindow(bv->gw);
12851 }
12852 GDrawSync(NULL);
12853 GDrawProcessPendingEvents(NULL);
12854 GDrawSync(NULL);
12855 GDrawProcessPendingEvents(NULL);
12856 }
12857 }
12858 }
12859
12860 /* Turn any searcher references to this glyph into inline copies of it */
12861 for ( fvs=(FontView *) sc->parent->fv; fvs!=NULL; fvs=(FontView *) fvs->b.nextsame ) {
12862 if ( fvs->sv!=NULL ) {
12863 RefChar *rf, *rnext;
12864 for ( rf = fvs->sv->sd.sc_srch.layers[ly_fore].refs; rf!=NULL; rf=rnext ) {
12865 rnext = rf->next;
12866 if ( rf->sc==sc )
12867 SCRefToSplines(&fvs->sv->sd.sc_srch,rf,ly_fore);
12868 }
12869 for ( rf = fvs->sv->sd.sc_rpl.layers[ly_fore].refs; rf!=NULL; rf=rnext ) {
12870 rnext = rf->next;
12871 if ( rf->sc==sc )
12872 SCRefToSplines(&fvs->sv->sd.sc_rpl,rf,ly_fore);
12873 }
12874 }
12875 }
12876 }
12877
12878 struct sc_interface gdraw_sc_interface = {
12879 SC_UpdateAll,
12880 SC_RefreshTitles,
12881 SC_HintsChanged,
12882 SC_CharChangedUpdate,
12883 _SC_CharChangedUpdate,
12884 SC_MarkInstrDlgAsChanged,
12885 SC_CloseAllWindows,
12886 SC_MoreLayers
12887 };
12888
12889 static void UI_CVGlyphRenameFixup(SplineFont *sf, const char *oldname, const char *newname) {
12890 int gid, i;
12891 SplineChar *sc;
12892 CharView *cv;
12893
12894 if ( no_windowing_ui )
12895 return;
12896
12897 for ( gid=0; gid<sf->glyphcnt; ++gid ) if ( (sc=sf->glyphs[gid])!=NULL) {
12898 for ( cv=(CharView *) (sc->views); cv!=NULL; cv = (CharView *) (cv->b.next)) {
12899 for ( i=0; i<cv->former_cnt; ++i ) if ( strcmp(oldname,cv->former_names[i])==0 ) {
12900 free( cv->former_names[i] );
12901 cv->former_names[i] = copy( newname );
12902 if ( cv->tabs!=NULL ) {
12903 GTabSetChangeTabName(cv->tabs,newname,i);
12904 GTabSetRemetric(cv->tabs);
12905 GGadgetRedraw(cv->tabs);
12906 }
12907 }
12908 }
12909 }
12910 }
12911
12912 struct cv_interface gdraw_cv_interface = {
12913 (void (*)(CharViewBase *)) CV_CharChangedUpdate,
12914 (void (*)(CharViewBase *,int)) _CV_CharChangedUpdate,
12915 UI_CVGlyphRenameFixup,
12916 CV_LayerPaletteCheck
12917 };
12918
12919
12920 int CVPalettesRIInit(GResInfo *ri) {
12921 extern GBox _ggadget_Default_Box;
12922 extern GResInfo ggadget_ri;
12923 if ( ri->is_initialized )
12924 return false;
12925 GResEditDoInit(&ggadget_ri);
12926 cvpalettefgcol = GDrawGetDefaultForeground(NULL);
12927 cvpalettebgcol = GDrawGetDefaultBackground(NULL);
12928 cvpaletteactborcol = _ggadget_Default_Box.active_border;
12929 return _GResEditInitialize(ri);
12930 }
12931
12932 extern GResInfo bitmapview_ri;
12933 GResInfo cvpalettes_ri = {
12934 &bitmapview_ri, NULL,NULL, NULL,
12935 NULL,
12936 NULL,
12937 NULL,
12938 cvpalettes_re,
12939 N_("Palettes"),
12940 N_("Colors, etc. of the Outline, Bitmap, and Layer palettes"),
12941 "CharView",
12942 "fontforge",
12943 false,
12944 false,
12945 0,
12946 GBOX_EMPTY,
12947 GBOX_EMPTY,
12948 NULL,
12949 CVPalettesRIInit,
12950 NULL
12951 };
12952 GResInfo charviewraster_ri = {
12953 &cvpalettes_ri, NULL,NULL, NULL,
12954 NULL,
12955 NULL,
12956 NULL,
12957 charviewraster_re,
12958 N_("Outline Raster"),
12959 N_("Colors related to images and font rasterizing"),
12960 "CharView",
12961 "fontforge",
12962 false,
12963 false,
12964 0,
12965 GBOX_EMPTY,
12966 GBOX_EMPTY,
12967 NULL,
12968 NULL,
12969 NULL
12970 };
12971 GResInfo charviewhints_ri = {
12972 &charviewraster_ri, NULL,NULL, NULL,
12973 NULL,
12974 NULL,
12975 NULL,
12976 charviewhints_re,
12977 N_("Outline Hints"),
12978 N_("Colors related to CFF/PostScript hints"),
12979 "CharView",
12980 "fontforge",
12981 false,
12982 false,
12983 0,
12984 GBOX_EMPTY,
12985 GBOX_EMPTY,
12986 NULL,
12987 NULL,
12988 NULL
12989 };
12990 GResInfo charviewtools_ri = {
12991 &charviewhints_ri, NULL,NULL, NULL,
12992 NULL,
12993 NULL,
12994 NULL,
12995 charviewtools_re,
12996 N_("Outline Tools"),
12997 N_("Colors, etc. related to tool use in outline window"),
12998 "CharView",
12999 "fontforge",
13000 false,
13001 false,
13002 0,
13003 GBOX_EMPTY,
13004 GBOX_EMPTY,
13005 NULL,
13006 NULL,
13007 NULL
13008 };
13009 GResInfo charviewlinesfills_ri = {
13010 &charviewtools_ri, NULL,NULL, NULL,
13011 NULL,
13012 NULL,
13013 NULL,
13014 charviewlinesfills_re,
13015 N_("Outline Lines/Fills"),
13016 N_("Colors of lines and fills in outline window"),
13017 "CharView",
13018 "fontforge",
13019 false,
13020 false,
13021 0,
13022 GBOX_EMPTY,
13023 GBOX_EMPTY,
13024 NULL,
13025 NULL,
13026 NULL
13027 };
13028 GResInfo charviewpoints_ri = {
13029 &charviewlinesfills_ri, NULL,NULL, NULL,
13030 NULL,
13031 NULL,
13032 NULL,
13033 charviewpoints_re,
13034 N_("Outline Points"),
13035 N_("Colors, etc of points in glyph outline window"),
13036 "CharView",
13037 "fontforge",
13038 false,
13039 false,
13040 0,
13041 GBOX_EMPTY,
13042 GBOX_EMPTY,
13043 NULL,
13044 NULL,
13045 NULL
13046 };
13047
13048
13049 void SPSelectNextPoint( SplinePoint *sp, int state )
13050 {
13051 if( !sp )
13052 return;
13053 if( !sp->next )
13054 return;
13055 if( !sp->next->to )
13056 return;
13057 sp->next->to->selected = state;
13058 }
13059
13060 void SPSelectPrevPoint( SplinePoint *sp, int state )
13061 {
13062 if( !sp )
13063 return;
13064 if( !sp->prev )
13065 return;
13066 if( !sp->prev->from )
13067 return;
13068 sp->prev->from->selected = state;
13069 }
13070
13071
13072
13073 bool SPIsNextCPSelectedSingle( SplinePoint *sp, CharView *cv )
13074 {
13075 if( cv )
13076 {
13077 int iscurrent = sp == (cv->p.sp!=NULL?cv->p.sp:cv->lastselpt);
13078 if( iscurrent && cv->p.nextcp )
13079 return true;
13080 }
13081 return false;
13082 }
13083
13084
13085 bool SPIsNextCPSelected( SplinePoint *sp, CharView *cv )
13086 {
13087 if( SPIsNextCPSelectedSingle( sp, cv ))
13088 return true;
13089 return sp->nextcpselected;
13090 }
13091
13092 bool SPIsPrevCPSelectedSingle( SplinePoint *sp, CharView *cv )
13093 {
13094 if( cv )
13095 {
13096 int iscurrent = sp == (cv->p.sp!=NULL?cv->p.sp:cv->lastselpt);
13097 if( iscurrent && cv->p.prevcp )
13098 return true;
13099 }
13100 return false;
13101 }
13102
13103 bool SPIsPrevCPSelected( SplinePoint *sp, CharView *cv )
13104 {
13105 if( SPIsPrevCPSelectedSingle( sp, cv ))
13106 {
13107 return true;
13108 }
13109 return sp->prevcpselected;
13110 }
13111
13112 bool CVShouldInterpolateCPsOnMotion( CharView* cv )
13113 {
13114 bool ret = interpCPsOnMotion;
13115
13116 if( cv->activeModifierControl && cv->activeModifierAlt )
13117 ret = !ret;
13118
13119 return ret;
13120 }
13121