Debian Codegraph @

fontforgeexe/prefs.c

raw symbols SCIP
1 /* -*- coding: utf-8 -*- */
2 /* Copyright (C) 2000-2012 by George Williams */
3 /*
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13
14 * The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <fontforge-config.h>
30
31 #include "autotrace.h"
32 #include "encoding.h"
33 #include "ffglib.h"
34 #include "fontforgeui.h"
35 #include "gfile.h"
36 #include "gkeysym.h"
37 #include "gresedit.h"
38 #include "groups.h"
39 #include "macenc.h"
40 #include "namelist.h"
41 #include "plugin.h"
42 #include "othersubrs.h"
43 #include "prefs.h"
44 #include "sfd.h"
45 #include "splineutil.h"
46 #include "ttf.h"
47 #include "ustring.h"
48 #include "gtk/simple_dialogs.hpp"
49 #include "shapers/shaper_shim.hpp"
50
51 #include <assert.h>
52 #include <dirent.h>
53 #include <locale.h>
54 #include <stdlib.h>
55 #include <sys/time.h>
56 #include <sys/types.h>
57 #include <time.h>
58
59 #define RAD2DEG (180/FF_PI)
60
61 static void change_res_filename(const char *newname);
62 GResFont prefs_monofont = GRESFONT_INIT("400 12pt " MONO_UI_FAMILIES);
63
64 extern int splash;
65 extern int adjustwidth;
66 extern int adjustlbearing;
67 extern Encoding *default_encoding;
68 extern int autohint_before_generate;
69 extern int use_freetype_to_rasterize_fv;
70 extern int use_freetype_with_aa_fill_cv;
71 extern int OpenCharsInNewWindow;
72 extern int ItalicConstrained;
73 extern int accent_offset;
74 extern int GraveAcuteCenterBottom;
75 extern int PreferSpacingAccents;
76 extern int CharCenterHighest;
77 extern int ask_user_for_resolution;
78 #ifndef _NO_LIBPNG
79 extern int WritePNGInSFD;
80 #endif
81 extern int stop_at_join;
82 extern int recognizePUA;
83 extern float arrowAmount;
84 extern float arrowAccelFactor;
85 extern float snapdistance;
86 extern float snapdistancemeasuretool;
87 extern int measuretoolshowhorizontolvertical;
88 extern int snaptoint;
89 extern float joinsnap;
90 extern char *BDFFoundry;
91 extern char *TTFFoundry;
92 extern char *xuid;
93 extern char *SaveTablesPref;
94 /*struct cvshows CVShows = { 1, 1, 1, 1, 1, 0, 1 };*/ /* in charview */
95 /* int default_fv_font_size = 24; */ /* in fontview */
96 /* int default_fv_antialias = false */ /* in fontview */
97 /* int default_fv_bbsized = false */ /* in fontview */
98 extern int default_fv_row_count; /* in fontview */
99 extern int default_fv_col_count; /* in fontview */
100 extern int default_fv_showhmetrics; /* in fontview */
101 extern int default_fv_showvmetrics; /* in fontview */
102 extern int default_fv_glyphlabel; /* in fontview */
103 extern int save_to_dir; /* in fontview, use sfdir rather than sfd */
104 extern int palettes_docked; /* in cvpalettes */
105 extern int cvvisible[2], bvvisible[3]; /* in cvpalettes.c */
106 extern int maxundoes; /* in cvundoes */
107 extern int pref_mv_shift_and_arrow_skip; /* in metricsview.c */
108 extern int pref_mv_control_shift_and_arrow_skip; /* in metricsview.c */
109 extern int mv_type; /* in metricsview.c */
110 extern int prefer_cjk_encodings; /* in parsettf */
111 extern int onlycopydisplayed, copymetadata, copyttfinstr;
112 extern struct cvshows CVShows;
113 extern int infowindowdistance; /* in cvruler.c */
114 extern int oldformatstate; /* in savefontdlg.c */
115 extern int oldbitmapstate; /* in savefontdlg.c */
116 static int old_ttf_flags=0, old_otf_flags=0;
117 extern int old_sfnt_flags; /* in savefont.c */
118 extern int old_ps_flags; /* in savefont.c */
119 extern int old_validate; /* in savefontdlg.c */
120 extern int old_fontlog; /* in savefontdlg.c */
121 extern int preferpotrace; /* in autotrace.c */
122 extern int autotrace_ask; /* in autotrace.c */
123 extern int mf_ask; /* in autotrace.c */
124 extern int mf_clearbackgrounds; /* in autotrace.c */
125 extern int mf_showerrors; /* in autotrace.c */
126 extern char *mf_args; /* in autotrace.c */
127 static int glyph_2_name_map=0; /* was in tottf.c, now a flag in savefont options dlg */
128 extern int coverageformatsallowed; /* in tottfgpos.c */
129 extern int debug_wins; /* in cvdebug.c */
130 extern int gridfit_dpi, gridfit_depth; /* in cvgridfit.c */
131 extern float gridfit_pointsizey; /* in cvgridfit.c */
132 extern float gridfit_pointsizex; /* in cvgridfit.c */
133 extern int gridfit_x_sameas_y; /* in cvgridfit.c */
134 extern int hint_diagonal_ends; /* in stemdb.c */
135 extern int hint_diagonal_intersections; /* in stemdb.c */
136 extern int hint_bounding_boxes; /* in stemdb.c */
137 extern int detect_diagonal_stems; /* in stemdb.c */
138 extern float stem_slope_error; /* in stemdb.c */
139 extern float stub_slope_error; /* in stemdb.c */
140 extern int instruct_diagonal_stems; /* in nowakowskittfinstr.c */
141 extern int instruct_serif_stems; /* in nowakowskittfinstr.c */
142 extern int instruct_ball_terminals; /* in nowakowskittfinstr.c */
143 extern int interpolate_strong; /* in nowakowskittfinstr.c */
144 extern int control_counters; /* in nowakowskittfinstr.c */
145 extern unichar_t *script_menu_names[SCRIPT_MENU_MAX];
146 extern char *script_filenames[SCRIPT_MENU_MAX];
147 static char *xdefs_filename;
148 extern int new_em_size; /* in splineutil2.c */
149 extern int new_fonts_are_order2; /* in splineutil2.c */
150 extern int loaded_fonts_same_as_new; /* in splineutil2.c */
151 extern int use_second_indic_scripts; /* in tottfgpos.c */
152 static char *othersubrsfile = NULL;
153 extern MacFeat *default_mac_feature_map, /* from macenc.c */
154 *user_mac_feature_map;
155 extern int updateflex; /* in charview.c */
156 extern int default_autokern_dlg; /* in lookupui.c */
157 extern int allow_utf8_glyphnames; /* in lookupui.c */
158 extern int add_char_to_name_list; /* in charinfo.c */
159 extern int clear_tt_instructions_when_needed; /* in cvundoes.c */
160 extern int export_clipboard; /* in cvundoes.c */
161 extern int cv_width; /* in charview.c */
162 extern int cv_height; /* in charview.c */
163 extern int cv_show_fill_with_space; /* in charview.c */
164 extern int interpCPsOnMotion; /* in charview.c */
165 extern int DrawOpenPathsWithHighlight; /* in charview.c */
166 extern float prefs_cvEditHandleSize; /* in charview.c */
167 extern int prefs_cvInactiveHandleAlpha; /* in charview.c */
168 extern int mv_width; /* in metricsview.c */
169 extern int mv_height; /* in metricsview.c */
170 extern int fvmv_selectmax; /* in metricsview.c */
171 extern int bv_width; /* in bitmapview.c */
172 extern int bv_height; /* in bitmapview.c */
173 extern int ask_user_for_cmap; /* in parsettf.c */
174 extern int mvshowgrid; /* in metricsview.c */
175
176 extern int rectelipse, polystar, regular_star; /* from cvpalettes.c */
177 extern int center_out[2]; /* from cvpalettes.c */
178 extern float rr_radius; /* from cvpalettes.c */
179 extern int ps_pointcnt; /* from cvpalettes.c */
180 extern float star_percent; /* from cvpalettes.c */
181 extern int home_char; /* from fontview.c */
182 extern int compact_font_on_open; /* from fontview.c */
183 extern int aa_pixelsize; /* from anchorsaway.c */
184 extern enum cvtools cv_b1_tool, cv_cb1_tool, cv_b2_tool, cv_cb2_tool; /* cvpalettes.c */
185 extern int show_kerning_pane_in_class; /* kernclass.c */
186 extern int AutoSaveFrequency; /* autosave.c */
187 extern int UndoRedoLimitToSave; /* sfd.c */
188 extern int UndoRedoLimitToLoad; /* sfd.c */
189 extern int prefRevisionsToRetain; /* sfd.c */
190 extern int SaveEditorState; /* sfd.c */
191 extern int prefs_cv_show_control_points_always_initially; /* from charview.c */
192 extern int prefs_create_dragging_comparison_outline; /* from charview.c */
193 extern int prefs_cv_outline_thickness; /* from charview.c */
194
195 extern float OpenTypeLoadHintEqualityTolerance; /* autohint.c */
196 extern float GenerateHintWidthEqualityTolerance; /* splinesave.c */
197 extern int warn_script_unsaved; /* fontview.c */
198 extern NameList *force_names_when_opening;
199 extern NameList *force_names_when_saving;
200 extern NameList *namelist_for_new_fonts;
201
202 extern int default_font_filter_index;
203 extern struct openfilefilters *user_font_filters;
204 static int alwaysgenapple=false, alwaysgenopentype=false;
205
206 static int gfc_showhidden, gfc_dirplace;
207 static char *gfc_bookmarks=NULL;
208
209 static int pointless;
210
211 /* These first three must match the values in macenc.c */
212 #define CID_Features 101
213 #define CID_FeatureDel 103
214 #define CID_FeatureEdit 105
215
216 #define CID_Mapping 102
217 #define CID_MappingDel 104
218 #define CID_MappingEdit 106
219
220 #define CID_ScriptMNameBase 200
221 #define CID_ScriptMFileBase (200+SCRIPT_MENU_MAX)
222 #define CID_ScriptMBrowseBase (200+2*SCRIPT_MENU_MAX)
223
224 #define CID_PrefsBase 1000
225 #define CID_PrefsOffset 100
226 #define CID_PrefsBrowseOffset (CID_PrefsOffset/2)
227
228 //////////////////////////////////
229 // The _oldval_ are used to cache the setting when the prefs window
230 // is created so that a redraw can be performed only when the
231 // value has changed.
232 float prefs_oldval_cvEditHandleSize = 0;
233 int prefs_oldval_cvInactiveHandleAlpha = 0;
234
235 /* ************************************************************************** */
236 /* ***************************** mac data ***************************** */
237 /* ************************************************************************** */
238
239 extern struct macsettingname macfeat_otftag[], *user_macfeat_otftag;
240
241 static void UserSettingsFree(void) {
242
243 free( user_macfeat_otftag );
244 user_macfeat_otftag = NULL;
245 }
246
247 static int UserSettingsDiffer(void) {
248 int i,j;
249
250 if ( user_macfeat_otftag==NULL )
251 return( false );
252
253 for ( i=0; user_macfeat_otftag[i].otf_tag!=0; ++i );
254 for ( j=0; macfeat_otftag[j].otf_tag!=0; ++j );
255 if ( i!=j )
256 return( true );
257 for ( i=0; user_macfeat_otftag[i].otf_tag!=0; ++i ) {
258 for ( j=0; macfeat_otftag[j].otf_tag!=0; ++j ) {
259 if ( macfeat_otftag[j].mac_feature_type ==
260 user_macfeat_otftag[i].mac_feature_type &&
261 macfeat_otftag[j].mac_feature_setting ==
262 user_macfeat_otftag[i].mac_feature_setting &&
263 macfeat_otftag[j].otf_tag ==
264 user_macfeat_otftag[i].otf_tag )
265 break;
266 }
267 if ( macfeat_otftag[j].otf_tag==0 )
268 return( true );
269 }
270 return( false );
271 }
272
273 /**************************************************************************** */
274
275
276 /* don't use mnemonics 'C' or 'O' (Cancel & OK) */
277 enum pref_types { pr_int, pr_real, pr_bool, pr_encoding, pr_string,
278 pr_file, pr_namelist, pr_unicode, pr_angle, pr_shaper };
279 struct enums { char *name; int value; };
280
281 struct enums fvsize_enums[] = { {NULL, 0} };
282
283 #define PREFS_LIST_EMPTY { NULL, 0, NULL, NULL, NULL, '\0', NULL, 0, NULL }
284 static struct prefs_list {
285 char *name;
286 /* In the prefs file the untranslated name will always be used, but */
287 /* in the UI that name may be translated. */
288 enum pref_types type;
289 void *val;
290 void *(*get)(void);
291 void (*set)(void *);
292 char mn;
293 struct enums *enums;
294 unsigned int dontdisplay: 1;
295 char *popup;
296 } general_list[] = {
297 /* GT: The following strings have no spaces and an odd capitalization */
298 /* GT: this is because these strings are used in two different ways, one */
299 /* GT: translated (which the user sees, and should probably have added spaces,*/
300 /* GT: and one untranslated which needs the current odd format */
301 { N_("ResourceFile"), pr_file, &xdefs_filename, NULL, NULL, 'R', NULL, 0, N_("When FontForge starts up, it loads the user interface theme from\nthis file. Any changes will only take effect the next time you start FontForge.") },
302 { N_("OtherSubrsFile"), pr_file, &othersubrsfile, NULL, NULL, 'O', NULL, 0, N_("If you wish to replace Adobe's OtherSubrs array (for Type1 fonts)\nwith an array of your own, set this to point to a file containing\na list of up to 14 PostScript subroutines. Each subroutine must\nbe preceded by a line starting with '%%%%' (any text before the\nfirst '%%%%' line will be treated as an initial copyright notice).\nThe first three subroutines are for flex hints, the next for hint\nsubstitution (this MUST be present), the 14th (or 13 as the\nnumbering actually starts with 0) is for counter hints.\nThe subroutines should not be enclosed in a [ ] pair.") },
303 { N_("FreeTypeInFontView"), pr_bool, &use_freetype_to_rasterize_fv, NULL, NULL, 'O', NULL, 0, N_("Use the FreeType rasterizer (when available)\nto rasterize glyphs in the font view.\nThis generally results in better quality.") },
304 { N_("FreeTypeAAFillInOutlineView"), pr_bool, &use_freetype_with_aa_fill_cv, NULL, NULL, 'O', NULL, 0, N_("When filling using freetype in the outline view,\nhave freetype render the glyph antialiased.") },
305 { N_("SplashScreen"), pr_bool, &splash, NULL, NULL, 'S', NULL, 0, N_("Show splash screen on start-up") },
306 { N_("ExportClipboard"), pr_bool, &export_clipboard, NULL, NULL, '\0', NULL, 0, N_( "If you are running an X11 clipboard manager you might want\nto turn this off. FF can put things into its internal clipboard\nwhich it cannot export to X11 (things like copying more than\none glyph in the fontview). If you have a clipboard manager\nrunning it will force these to be exported with consequent\nloss of data.") },
307 { N_("AutoSaveFrequency"), pr_int, &AutoSaveFrequency, NULL, NULL, '\0', NULL, 0, N_( "The number of seconds between autosaves. If you set this to 0 there will be no autosaves.") },
308 { N_("RevisionsToRetain"), pr_int, &prefRevisionsToRetain, NULL, NULL, '\0', NULL, 0, N_( "When Saving, keep this number of previous versions of the file. file.sfd-01 will be the last saved file, file.sfd-02 will be the file saved before that, and so on. If you set this to 0 then no revisions will be retained.") },
309 { N_("UndoRedoLimitToSave"), pr_int, &UndoRedoLimitToSave, NULL, NULL, '\0', NULL, 0, N_( "The number of undo and redo operations which will be saved in sfd files.\nIf you set this to 0 undo/redo information is not saved to sfd files.\nIf set to -1 then all available undo/redo information is saved without limit.") },
310 { N_("SaveEditorState"), pr_bool, &SaveEditorState, NULL, NULL, '\0', NULL, 0, N_( "When saving, keep editor state like window size and position, selected points and references, and open glyphs.") },
311 { N_("WarnScriptUnsaved"), pr_bool, &warn_script_unsaved, NULL, NULL, '\0', NULL, 0, N_( "Whether or not to warn you if you have an unsaved script in the «Execute Script» dialog.") },
312 #ifndef _NO_PYTHON
313 { N_("UsePlugins"), pr_bool, &use_plugins, NULL, NULL, '\0', NULL, 0, N_( "Whether or not to try to discover and import Python plugins.") },
314 #endif
315 { N_("DefaultShaper"), pr_shaper, NULL, (void * (*)(void))get_default_shaper, (void (*)(void *))set_default_shaper, '\0', NULL, 0, N_( "The default shaper for MetricsView.") },
316 PREFS_LIST_EMPTY
317 },
318 new_list[] = {
319 { N_("NewCharset"), pr_encoding, &default_encoding, NULL, NULL, 'N', NULL, 0, N_("Default encoding for\nnew fonts") },
320 { N_("NewEmSize"), pr_int, &new_em_size, NULL, NULL, 'S', NULL, 0, N_("The default size of the Em-Square in a newly created font.") },
321 { N_("NewFontsQuadratic"), pr_bool, &new_fonts_are_order2, NULL, NULL, 'Q', NULL, 0, N_("Whether new fonts should contain splines of quadratic (truetype)\nor cubic (postscript & opentype).") },
322 { N_("LoadedFontsAsNew"), pr_bool, &loaded_fonts_same_as_new, NULL, NULL, 'L', NULL, 0, N_("Whether fonts loaded from the disk should retain their splines\nwith the original order (quadratic or cubic), or whether the\nsplines should be converted to the default order for new fonts\n(see NewFontsQuadratic).") },
323 PREFS_LIST_EMPTY
324 },
325 open_list[] = {
326 { N_("PreferCJKEncodings"), pr_bool, &prefer_cjk_encodings, NULL, NULL, 'C', NULL, 0, N_("When loading a truetype or opentype font which has both a unicode\nand a CJK encoding table, use this flag to specify which\nshould be loaded for the font.") },
327 { N_("AskUserForCMap"), pr_bool, &ask_user_for_cmap, NULL, NULL, 'O', NULL, 0, N_("When loading a font in sfnt format (TrueType, OpenType, etc.),\nask the user to specify which cmap to use initially.") },
328 { N_("PreserveTables"), pr_string, &SaveTablesPref, NULL, NULL, 'P', NULL, 0, N_("Enter a list of 4 letter table tags, separated by commas.\nFontForge will make a binary copy of these tables when it\nloads a True/OpenType font, and will output them (unchanged)\nwhen it generates the font. Do not include table tags which\nFontForge thinks it understands.") },
329 { N_("SeekCharacter"), pr_unicode, &home_char, NULL, NULL, '\0', NULL, 0, N_("When fontforge opens a (non-sfd) font it will try to display this unicode character in the fontview.")},
330 { N_("CompactOnOpen"), pr_bool, &compact_font_on_open, NULL, NULL, 'O', NULL, 0, N_("When a font is opened, should it be made compact?")},
331 { N_("UndoRedoLimitToLoad"), pr_int, &UndoRedoLimitToLoad, NULL, NULL, '\0', NULL, 0, N_( "The number of undo and redo operations to load from sfd files.\nWith this option you can disregard undo information while loading SFD files.\nIf set to 0 then no undo/redo information is loaded.\nIf set to -1 then all available undo/redo information is loaded without limit.") },
332 { N_("OpenTypeLoadHintEqualityTolerance"), pr_real, &OpenTypeLoadHintEqualityTolerance, NULL, NULL, '\0', NULL, 0, N_( "When importing an OpenType font, for the purposes of hinting spline points might not exactly match boundaries. For example, a point might be -0.0002 instead of exactly 0\nThis setting gives the user some control over this allowing a small tolerance value to be fed into the OpenType loading code.\nComparisons are then not performed for raw equality but for equality within tolerance (e.g., values within the range -0.0002 to 0.0002 will be considered equal to 0 when figuring out hints).") },
333 PREFS_LIST_EMPTY
334 },
335 navigation_list[] = {
336 { N_("GlyphAutoGoto"), pr_bool, &cv_auto_goto, NULL, NULL, '\0', NULL, 0, N_("Typing a normal character in the glyph view window changes the window to look at that character.\nEnabling GlyphAutoGoto will disable the shortcut where holding just the ` key will enable Preview mode as long as the key is held.") },
337 { N_("OpenCharsInNewWindow"), pr_bool, &OpenCharsInNewWindow, NULL, NULL, '\0', NULL, 0, N_("When double clicking on a character in the font view\nopen that character in a new window, otherwise\nreuse an existing one.") },
338 { N_("FontViewMetricsViewSelectMax"), pr_int, &fvmv_selectmax, NULL, NULL, '\0', NULL, 0, N_("When characters are selected in the FontView, how many should be put into the MetricsView if you open one? Negative values mean there's no limit, which should be used sparingly.") },
339 PREFS_LIST_EMPTY
340 },
341 editing_list[] = {
342 { N_("ItalicConstrained"), pr_bool, &ItalicConstrained, NULL, NULL, '\0', NULL, 0, N_("In the Outline View, the Shift key constrains motion to be parallel to the ItalicAngle rather than constraining it to be vertical.") },
343 { N_("InterpolateCPsOnMotion"), pr_bool, &interpCPsOnMotion, NULL, NULL, '\0', NULL, 0, N_("When moving one end point of a spline but not the other\ninterpolate the control points between the two.") },
344 { N_("SnapDistance"), pr_real, &snapdistance, NULL, NULL, '\0', NULL, 0, N_("When the mouse pointer is within this many pixels\nof one of the various interesting features (baseline,\nwidth, grid splines, etc.) the pointer will snap\nto that feature.") },
345 { N_("SnapDistanceMeasureTool"), pr_real, &snapdistancemeasuretool, NULL, NULL, '\0', NULL, 0, N_("When the measure tool is active and when the mouse pointer is within this many pixels\nof one of the various interesting features (baseline,\nwidth, grid splines, etc.) the pointer will snap\nto that feature.") },
346 { N_("SnapToInt"), pr_bool, &snaptoint, NULL, NULL, '\0', NULL, 0, N_("When the user clicks in the editing window, round the location to the nearest integers.") },
347 { N_("StopAtJoin"), pr_bool, &stop_at_join, NULL, NULL, '\0', NULL, 0, N_("When dragging points in the outline view a join may occur\n(two open contours may connect at their endpoints). When\nthis is On a join will cause FontForge to stop moving the\nselection (as if the user had released the mouse button).\nThis is handy if your fingers are inclined to wiggle a bit.") },
348 { N_("JoinSnap"), pr_real, &joinsnap, NULL, NULL, '\0', NULL, 0, N_("The Edit->Join command will join points which are this close together\nA value of 0 means they must be coincident") },
349 { N_("CopyMetaData"), pr_bool, &copymetadata, NULL, NULL, '\0', NULL, 0, N_("When copying glyphs from the font view, also copy the\nglyphs' metadata (name, encoding, comment, etc).") },
350 { N_("UndoDepth"), pr_int, &maxundoes, NULL, NULL, '\0', NULL, 0, N_("The maximum number of Undoes/Redoes stored in a glyph. Use -1 for infinite Undoes\n(but watch RAM consumption and use the Edit menu's Remove Undoes as needed)") },
351 { N_("UpdateFlex"), pr_bool, &updateflex, NULL, NULL, '\0', NULL, 0, N_("Figure out flex hints after every change") },
352 { N_("AutoKernDialog"), pr_bool, &default_autokern_dlg, NULL, NULL, '\0', NULL, 0, N_("Open AutoKern dialog for new kerning subtables") },
353 { N_("MetricsShiftSkip"), pr_int, &pref_mv_shift_and_arrow_skip, NULL, NULL, '\0', NULL, 0, N_("Number of units to increment/decrement a table value by in the metrics window when shift is held") },
354 { N_("MetricsControlShiftSkip"), pr_int, &pref_mv_control_shift_and_arrow_skip, NULL, NULL, '\0', NULL, 0, N_("Number of units to increment/decrement a table value by in the metrics window when both control and shift is held") },
355 PREFS_LIST_EMPTY
356 },
357 editing_interface_list[] = {
358 { N_("ArrowMoveSize"), pr_real, &arrowAmount, NULL, NULL, '\0', NULL, 0, N_("The number of em-units by which an arrow key will move a selected point") },
359 { N_("ArrowAccelFactor"), pr_real, &arrowAccelFactor, NULL, NULL, '\0', NULL, 0, N_("Holding down the Shift key will speed up arrow key motion by this factor") },
360 { N_("DrawOpenPathsWithHighlight"), pr_bool, &DrawOpenPathsWithHighlight, NULL, NULL, '\0', NULL, 0, N_("Open paths should be drawn in a special highlight color to make them more apparent.") },
361 { N_("MeasureToolShowHorizontalVertical"), pr_bool, &measuretoolshowhorizontolvertical, NULL, NULL, '\0', NULL, 0, N_("Have the measure tool show horizontal and vertical distances on the canvas.") },
362 { N_("EditHandleSize"), pr_real, &prefs_cvEditHandleSize, NULL, NULL, '\0', NULL, 0, N_("The size of the handles showing control points and other interesting points in the glyph editor (default is 5).") },
363 { N_("InactiveHandleAlpha"), pr_int, &prefs_cvInactiveHandleAlpha, NULL, NULL, '\0', NULL, 0, N_("Inactive handles in the glyph editor will be drawn with this alpha value (range: 0-255 default is 255).") },
364 { N_("ShowControlPointsAlways"), pr_bool, &prefs_cv_show_control_points_always_initially, NULL, NULL, '\0', NULL, 0, N_("Always show the control points when editing a glyph.\nThis can be turned off in the menu View/Show, this setting will effect if control points are shown initially.\nChange requires a restart of fontforge.") },
365 { N_("ShowFillWithSpace"), pr_bool, &cv_show_fill_with_space, NULL, NULL, '\0', NULL, 0, N_("Also enable preview mode when the space bar is pressed.") },
366 { N_("OutlineThickness"), pr_int, &prefs_cv_outline_thickness, NULL, NULL, '\0', NULL, 0, N_("Setting above 1 will cause a thick outline to be drawn for glyph paths\n which is only extended inwards from the edge of the glyph.\n See also the ForegroundThickOutlineColor Resource for the color of this outline.") },
367 PREFS_LIST_EMPTY
368 },
369 sync_list[] = {
370 { N_("AutoWidthSync"), pr_bool, &adjustwidth, NULL, NULL, '\0', NULL, 0, N_("Changing the width of a glyph\nchanges the widths of all accented\nglyphs based on it.") },
371 { N_("AutoLBearingSync"), pr_bool, &adjustlbearing, NULL, NULL, '\0', NULL, 0, N_("Changing the left side bearing\nof a glyph adjusts the lbearing\nof other references in all accented\nglyphs based on it.") },
372 PREFS_LIST_EMPTY
373 },
374 tt_list[] = {
375 { N_("ClearInstrsBigChanges"), pr_bool, &clear_tt_instructions_when_needed, NULL, NULL, 'C', NULL, 0, N_("Instructions in a TrueType font refer to\npoints by number, so if you edit a glyph\nin such a way that some points have different\nnumbers (add points, remove them, etc.) then\nthe instructions will be applied to the wrong\npoints with disastrous results.\n Normally FontForge will remove the instructions\nif it detects that the points have been renumbered\nin order to avoid the above problem. You may turn\nthis behavior off -- but be careful!") },
376 { N_("CopyTTFInstrs"), pr_bool, &copyttfinstr, NULL, NULL, '\0', NULL, 0, N_("When copying glyphs from the font view, also copy the\nglyphs' truetype instructions.") },
377 PREFS_LIST_EMPTY
378 },
379 accent_list[] = {
380 { N_("AccentOffsetPercent"), pr_int, &accent_offset, NULL, NULL, '\0', NULL, 0, N_("The percentage of an em by which an accent is offset from its base glyph in Build Accent") },
381 { N_("AccentCenterLowest"), pr_bool, &GraveAcuteCenterBottom, NULL, NULL, '\0', NULL, 0, N_("When placing grave and acute accents above letters, should\nFontForge center them based on their full width, or\nshould it just center based on the lowest point\nof the accent.") },
382 { N_("CharCenterHighest"), pr_bool, &CharCenterHighest, NULL, NULL, '\0', NULL, 0, N_("When centering an accent over a glyph, should the accent\nbe centered on the highest point(s) of the glyph,\nor the middle of the glyph?") },
383 { N_("PreferSpacingAccents"), pr_bool, &PreferSpacingAccents, NULL, NULL, '\0', NULL, 0, N_("Use spacing accents (Unicode: 02C0-02FF) rather than\ncombining accents (Unicode: 0300-036F) when\nbuilding accented glyphs.") },
384 PREFS_LIST_EMPTY
385 },
386 args_list[] = {
387 { N_("PreferPotrace"), pr_bool, &preferpotrace, NULL, NULL, '\0', NULL, 0, N_("FontForge supports two different helper applications to do autotracing\n autotrace and potrace\nIf your system only has one it will use that one, if you have both\nuse this option to tell FontForge which to pick.") },
388 { N_("AutotraceArgs"), pr_string, NULL, GetAutoTraceArgs, SetAutoTraceArgs, '\0', NULL, 0, N_("Extra arguments for configuring the autotrace program\n(either autotrace or potrace)") },
389 { N_("AutotraceAsk"), pr_bool, &autotrace_ask, NULL, NULL, '\0', NULL, 0, N_("Ask the user for autotrace arguments each time autotrace is invoked") },
390 { N_("MfArgs"), pr_string, &mf_args, NULL, NULL, '\0', NULL, 0, N_("Commands to pass to mf (metafont) program, the filename will follow these") },
391 { N_("MfAsk"), pr_bool, &mf_ask, NULL, NULL, '\0', NULL, 0, N_("Ask the user for mf commands each time mf is invoked") },
392 { N_("MfClearBg"), pr_bool, &mf_clearbackgrounds, NULL, NULL, '\0', NULL, 0, N_("FontForge loads large images into the background of each glyph\nprior to autotracing them. You may retain those\nimages to look at after mf processing is complete, or\nremove them to save space") },
393 { N_("MfShowErr"), pr_bool, &mf_showerrors, NULL, NULL, '\0', NULL, 0, N_("MetaFont (mf) generates lots of verbiage to stdout.\nMost of the time I find it an annoyance but it is\nimportant to see if something goes wrong.") },
394 PREFS_LIST_EMPTY
395 },
396 fontinfo_list[] = {
397 { N_("FoundryName"), pr_string, &BDFFoundry, NULL, NULL, 'F', NULL, 0, N_("Name used for foundry field in bdf\nfont generation") },
398 { N_("TTFFoundry"), pr_string, &TTFFoundry, NULL, NULL, 'T', NULL, 0, N_("Name used for Vendor ID field in\nttf (OS/2 table) font generation.\nMust be no more than 4 characters") },
399 { N_("NewFontNameList"), pr_namelist, &namelist_for_new_fonts, NULL, NULL, '\0', NULL, 0, N_("FontForge will use this namelist when assigning\nglyph names to code points in a new font.") },
400 { N_("RecognizePUANames"), pr_bool, &recognizePUA, NULL, NULL, 'U', NULL, 0, N_("Once upon a time, Adobe assigned PUA (public use area) encodings\nfor many stylistic variants of characters (small caps, old style\nnumerals, etc.). Adobe no longer believes this to be a good idea,\nand recommends that these encodings be ignored.\n\n The assignments were originally made because most applications\ncould not handle OpenType features for accessing variants. Adobe\nnow believes that all apps that matter can now do so. Applications\nlike Word and OpenOffice still can't handle these features, so\n fontforge's default behavior is to ignore Adobe's current\nrecommendations.\n\nNote: This does not affect figuring out unicode from the font's encoding,\nit just controls determining unicode from a name.") },
401 { N_("UnicodeGlyphNames"), pr_bool, &allow_utf8_glyphnames, NULL, NULL, 'O', NULL, 0, N_("Allow the full unicode character set in glyph names.\nThis does not conform to adobe's glyph name standard.\nSuch names should be for internal use only and\nshould NOT end up in production fonts." ) },
402 { N_("AddCharToNameList"), pr_bool, &add_char_to_name_list, NULL, NULL, 'O', NULL, 0, N_( "When displaying a list of glyph names\n(or sometimes just a single glyph name)\nFontForge will add the unicode character\nthe name refers to in parenthesis after\nthe name. It does this because some names\nare obscure.\nSome people would prefer not to see this,\nso this preference item lets you turn off\n this behavior" ) },
403 PREFS_LIST_EMPTY
404 },
405 generate_list[] = {
406 { N_("AskBDFResolution"), pr_bool, &ask_user_for_resolution, NULL, NULL, 'B', NULL, 0, N_("When generating a set of BDF fonts ask the user\nto specify the screen resolution of the fonts\notherwise FontForge will guess depending on the pixel size.") },
407 { N_("AutoHint"), pr_bool, &autohint_before_generate, NULL, NULL, 'H', NULL, 0, N_("AutoHint changed glyphs before generating a font") },
408 #ifndef _NO_LIBPNG
409 { N_("WritePNGInSFD"), pr_bool, &WritePNGInSFD, NULL, NULL, 'B', NULL, 0, N_("If your SFD contains images, write them as PNG; this results in smaller SFDs; but was not supported in FontForge versions compiled before July 2019, so older FontForge versions cannot read them.") },
410 #endif
411
412 { N_("GenerateHintWidthEqualityTolerance"), pr_real, &GenerateHintWidthEqualityTolerance, NULL, NULL, '\0', NULL, 0, N_( "When generating a font, ignore slight rounding errors for hints that should be at the top or bottom of the glyph. For example, you might like to set this to 0.02 so that 19.999 will be considered 20. But only for the hint width value.") },
413
414 PREFS_LIST_EMPTY
415 },
416 hints_list[] = {
417 { N_("StandardSlopeError"), pr_angle, &stem_slope_error, NULL, NULL, '\0', NULL, 0, N_("The maximum slope difference which still allows to consider two points \"parallel\".\nEnlarge this to make the autohinter more tolerable to small deviations from straight lines when detecting stem edges.") },
418 { N_("SerifSlopeError"), pr_angle, &stub_slope_error, NULL, NULL, '\0', NULL, 0, N_("Same as above, but for terminals of small features (e. g. serifs), which can deviate more significantly from the horizontal or vertical direction.") },
419 { N_("HintBoundingBoxes"), pr_bool, &hint_bounding_boxes, NULL, NULL, '\0', NULL, 0, N_("FontForge will place vertical or horizontal hints to describe the bounding boxes of suitable glyphs.") },
420 { N_("HintDiagonalEnds"), pr_bool, &hint_diagonal_ends, NULL, NULL, '\0', NULL, 0, N_("FontForge will place vertical or horizontal hints at the ends of diagonal stems.") },
421 { N_("HintDiagonalInter"), pr_bool, &hint_diagonal_intersections, NULL, NULL, '\0', NULL, 0, N_("FontForge will place vertical or horizontal hints at the intersections of diagonal stems.") },
422 { N_("DetectDiagonalStems"), pr_bool, &detect_diagonal_stems, NULL, NULL, '\0', NULL, 0, N_("FontForge will generate diagonal stem hints, which then can be used by the AutoInstr command.") },
423 PREFS_LIST_EMPTY
424 },
425 instrs_list[] = {
426 { N_("InstructDiagonalStems"), pr_bool, &instruct_diagonal_stems, NULL, NULL, '\0', NULL, 0, N_("Generate instructions for diagonal stem hints.") },
427 { N_("InstructSerifs"), pr_bool, &instruct_serif_stems, NULL, NULL, '\0', NULL, 0, N_("Try to detect serifs and other elements protruding from base stems and generate instructions for them.") },
428 { N_("InstructBallTerminals"), pr_bool, &instruct_ball_terminals, NULL, NULL, '\0', NULL, 0, N_("Generate instructions for ball terminals.") },
429 { N_("InterpolateStrongPoints"), pr_bool, &interpolate_strong, NULL, NULL, '\0', NULL, 0, N_("Interpolate between stem edges some important points, not affected by other instructions.") },
430 { N_("CounterControl"), pr_bool, &control_counters, NULL, NULL, '\0', NULL, 0, N_("Make sure similar or equal counters remain the same in gridfitted outlines.\nEnabling this option may result in glyph advance widths being\ninconsistently scaled at some PPEMs.") },
431 PREFS_LIST_EMPTY
432 },
433 opentype_list[] = {
434 { N_("UseNewIndicScripts"), pr_bool, &use_second_indic_scripts, NULL, NULL, 'C', NULL, 0, N_("MS has changed (in August 2006) the inner workings of their Indic shaping\nengine, and to disambiguate this change has created a parallel set of script\ntags (generally ending in '2') for Indic writing systems. If you are working\nwith the new system set this flag, if you are working with the old unset it.\n(if you aren't doing Indic work, this flag is irrelevant).") },
435 PREFS_LIST_EMPTY
436 },
437 /* These are hidden, so will never appear in preference ui, hence, no "N_(" */
438 /* They are controlled elsewhere AntiAlias is a menu item in the font window's View menu */
439 /* etc. */
440 hidden_list[] = {
441 { "AntiAlias", pr_bool, &default_fv_antialias, NULL, NULL, '\0', NULL, 1, NULL },
442 { "DefaultFVShowHmetrics", pr_int, &default_fv_showhmetrics, NULL, NULL, '\0', NULL, 1, NULL },
443 { "DefaultFVShowVmetrics", pr_int, &default_fv_showvmetrics, NULL, NULL, '\0', NULL, 1, NULL },
444 { "DefaultFVSize", pr_int, &default_fv_font_size, NULL, NULL, 'S', NULL, 1, NULL },
445 { "DefaultFVRowCount", pr_int, &default_fv_row_count, NULL, NULL, 'S', NULL, 1, NULL },
446 { "DefaultFVColCount", pr_int, &default_fv_col_count, NULL, NULL, 'S', NULL, 1, NULL },
447 { "DefaultFVGlyphLabel", pr_int, &default_fv_glyphlabel, NULL, NULL, 'S', NULL, 1, NULL },
448 { "SaveToDir", pr_int, &save_to_dir, NULL, NULL, 'S', NULL, 1, NULL },
449 { "OnlyCopyDisplayed", pr_bool, &onlycopydisplayed, NULL, NULL, '\0', NULL, 1, NULL },
450 { "PalettesDocked", pr_bool, &palettes_docked, NULL, NULL, '\0', NULL, 1, NULL },
451 { "DefaultCVWidth", pr_int, &cv_width, NULL, NULL, '\0', NULL, 1, NULL },
452 { "DefaultCVHeight", pr_int, &cv_height, NULL, NULL, '\0', NULL, 1, NULL },
453 { "CVVisible0", pr_bool, &cvvisible[0], NULL, NULL, '\0', NULL, 1, NULL },
454 { "CVVisible1", pr_bool, &cvvisible[1], NULL, NULL, '\0', NULL, 1, NULL },
455 { "BVVisible0", pr_bool, &bvvisible[0], NULL, NULL, '\0', NULL, 1, NULL },
456 { "BVVisible1", pr_bool, &bvvisible[1], NULL, NULL, '\0', NULL, 1, NULL },
457 { "BVVisible2", pr_bool, &bvvisible[2], NULL, NULL, '\0', NULL, 1, NULL },
458 { "MarkExtrema", pr_int, &CVShows.markextrema, NULL, NULL, '\0', NULL, 1, NULL },
459 { "MarkPointsOfInflect", pr_int, &CVShows.markpoi, NULL, NULL, '\0', NULL, 1, NULL },
460 { "ShowRulers", pr_bool, &CVShows.showrulers, NULL, NULL, '\0', NULL, 1, N_("Display rulers in the Outline Glyph View") },
461 { "ShowCPInfo", pr_int, &CVShows.showcpinfo, NULL, NULL, '\0', NULL, 1, NULL },
462 { "CreateDraggingComparisonOutline", pr_int, &prefs_create_dragging_comparison_outline, NULL, NULL, '\0', NULL, 1, NULL },
463 { "InfoWindowDistance", pr_int, &infowindowdistance, NULL, NULL, '\0', NULL, 1, NULL },
464 { "ShowSideBearings", pr_int, &CVShows.showsidebearings, NULL, NULL, '\0', NULL, 1, NULL },
465 { "ShowRefNames", pr_int, &CVShows.showrefnames, NULL, NULL, '\0', NULL, 1, NULL },
466 { "ShowPoints", pr_bool, &CVShows.showpoints, NULL, NULL, '\0', NULL, 1, NULL },
467 { "ShowFilled", pr_int, &CVShows.showfilled, NULL, NULL, '\0', NULL, 1, NULL },
468 { "ShowTabs", pr_int, &CVShows.showtabs, NULL, NULL, '\0', NULL, 1, NULL },
469 { "SnapOutlines", pr_int, &CVShows.snapoutlines, NULL, NULL, '\0', NULL, 1, NULL },
470 { "ShowAlmostHVLines", pr_bool, &CVShows.showalmosthvlines, NULL, NULL, '\0', NULL, 1, NULL },
471 { "ShowAlmostHVCurves", pr_bool, &CVShows.showalmosthvcurves, NULL, NULL, '\0', NULL, 1, NULL },
472 { "AlmostHVBound", pr_int, &CVShows.hvoffset, NULL, NULL, '\0', NULL, 1, NULL },
473 { "CheckSelfIntersects", pr_bool, &CVShows.checkselfintersects, NULL, NULL, '\0', NULL, 1, NULL },
474 { "ShowDebugChanges", pr_bool, &CVShows.showdebugchanges, NULL, NULL, '\0', NULL, 1, NULL },
475 { "DefaultOutputFormat", pr_int, &oldformatstate, NULL, NULL, '\0', NULL, 1, NULL },
476 { "DefaultBitmapFormat", pr_int, &oldbitmapstate, NULL, NULL, '\0', NULL, 1, NULL },
477 { "SaveValidate", pr_int, &old_validate, NULL, NULL, '\0', NULL, 1, NULL },
478 { "SaveFontLogAsk", pr_int, &old_fontlog, NULL, NULL, '\0', NULL, 1, NULL },
479 { "DefaultSFNTflags", pr_int, &old_sfnt_flags, NULL, NULL, '\0', NULL, 1, NULL },
480 { "DefaultPSflags", pr_int, &old_ps_flags, NULL, NULL, '\0', NULL, 1, NULL },
481 { "PageWidth", pr_int, &pagewidth, NULL, NULL, '\0', NULL, 1, NULL },
482 { "PageHeight", pr_int, &pageheight, NULL, NULL, '\0', NULL, 1, NULL },
483 { "PrintType", pr_int, &printtype, NULL, NULL, '\0', NULL, 1, NULL },
484 { "PrintCommand", pr_string, &printcommand, NULL, NULL, '\0', NULL, 1, NULL },
485 { "PageLazyPrinter", pr_string, &printlazyprinter, NULL, NULL, '\0', NULL, 1, NULL },
486 { "RegularStar", pr_bool, &regular_star, NULL, NULL, '\0', NULL, 1, NULL },
487 { "PolyStar", pr_bool, &polystar, NULL, NULL, '\0', NULL, 1, NULL },
488 { "RectEllipse", pr_bool, &rectelipse, NULL, NULL, '\0', NULL, 1, NULL },
489 { "RectCenterOut", pr_bool, &center_out[0], NULL, NULL, '\0', NULL, 1, NULL },
490 { "EllipseCenterOut", pr_bool, &center_out[1], NULL, NULL, '\0', NULL, 1, NULL },
491 { "PolyStartPointCnt", pr_int, &ps_pointcnt, NULL, NULL, '\0', NULL, 1, NULL },
492 { "RoundRectRadius", pr_real, &rr_radius, NULL, NULL, '\0', NULL, 1, NULL },
493 { "StarPercent", pr_real, &star_percent, NULL, NULL, '\0', NULL, 1, NULL },
494 { "CoverageFormatsAllowed", pr_int, &coverageformatsallowed, NULL, NULL, '\0', NULL, 1, NULL },
495 { "DebugWins", pr_int, &debug_wins, NULL, NULL, '\0', NULL, 1, NULL },
496 { "GridFitDpi", pr_int, &gridfit_dpi, NULL, NULL, '\0', NULL, 1, NULL },
497 { "GridFitDepth", pr_int, &gridfit_depth, NULL, NULL, '\0', NULL, 1, NULL },
498 { "GridFitPointSize", pr_real, &gridfit_pointsizey, NULL, NULL, '\0', NULL, 1, NULL },
499 { "GridFitPointSizeX", pr_real, &gridfit_pointsizex, NULL, NULL, '\0', NULL, 1, NULL },
500 { "GridFitSameAs", pr_int, &gridfit_x_sameas_y, NULL, NULL, '\0', NULL, 1, NULL },
501 { "MVShowGrid", pr_int, &mvshowgrid, NULL, NULL, '\0', NULL, 1, NULL },
502 { "ForceNamesWhenOpening", pr_namelist, &force_names_when_opening, NULL, NULL, '\0', NULL, 1, NULL },
503 { "ForceNamesWhenSaving", pr_namelist, &force_names_when_saving, NULL, NULL, '\0', NULL, 1, NULL },
504 { "DefaultFontFilterIndex", pr_int, &default_font_filter_index, NULL, NULL, '\0', NULL, 1, NULL },
505 { "FCShowHidden", pr_bool, &gfc_showhidden, NULL, NULL, '\0', NULL, 1, NULL },
506 { "FCDirPlacement", pr_int, &gfc_dirplace, NULL, NULL, '\0', NULL, 1, NULL },
507 { "FCBookmarks", pr_string, &gfc_bookmarks, NULL, NULL, '\0', NULL, 1, NULL },
508 { "DefaultMVType", pr_int, &mv_type, NULL, NULL, '\0', NULL, 1, NULL },
509 { "DefaultMVWidth", pr_int, &mv_width, NULL, NULL, '\0', NULL, 1, NULL },
510 { "DefaultMVHeight", pr_int, &mv_height, NULL, NULL, '\0', NULL, 1, NULL },
511 { "DefaultBVWidth", pr_int, &bv_width, NULL, NULL, '\0', NULL, 1, NULL },
512 { "DefaultBVHeight", pr_int, &bv_height, NULL, NULL, '\0', NULL, 1, NULL },
513 { "AnchorControlPixelSize", pr_int, &aa_pixelsize, NULL, NULL, '\0', NULL, 1, NULL },
514 { "CV_B1Tool", pr_int, (int *) &cv_b1_tool, NULL, NULL, '\0', NULL, 1, NULL },
515 { "CV_CB1Tool", pr_int, (int *) &cv_cb1_tool, NULL, NULL, '\0', NULL, 1, NULL },
516 { "CV_B2Tool", pr_int, (int *) &cv_b2_tool, NULL, NULL, '\0', NULL, 1, NULL },
517 { "CV_CB2Tool", pr_int, (int *) &cv_cb2_tool, NULL, NULL, '\0', NULL, 1, NULL },
518 { "XUID-Base", pr_string, &xuid, NULL, NULL, 'X', NULL, 0, N_("If specified this should be a space separated list of integers each\nless than 16777216 which uniquely identify your organization\nFontForge will generate a random number for the final component.") }, /* Obsolete */
519 { "ShowKerningPane", pr_int, (int *) &show_kerning_pane_in_class, NULL, NULL, '\0', NULL, 1, NULL },
520 #ifndef _NO_PYTHON
521 { "PluginStartupMode", pr_string, NULL, &GetPluginStartupMode, &SetPluginStartupMode, '\0', NULL, 1, NULL },
522 #endif
523 PREFS_LIST_EMPTY
524 },
525 oldnames[] = {
526 { "DumpGlyphMap", pr_bool, &glyph_2_name_map, NULL, NULL, '\0', NULL, 0, N_("When generating a truetype or opentype font it is occasionally\nuseful to know the mapping between truetype glyph ids and\nglyph names. Setting this option will cause FontForge to\nproduce a file (with extension .g2n) containing those data.") },
527 { "DefaultTTFApple", pr_int, &pointless, NULL, NULL, '\0', NULL, 1, NULL },
528 { "AcuteCenterBottom", pr_bool, &GraveAcuteCenterBottom, NULL, NULL, '\0', NULL, 1, N_("When placing grave and acute accents above letters, should\nFontForge center them based on their full width, or\nshould it just center based on the lowest point\nof the accent.") },
529 { "AlwaysGenApple", pr_bool, &alwaysgenapple, NULL, NULL, 'A', NULL, 0, N_("Apple and MS/Adobe differ about the format of truetype and opentype files.\nThis controls the default setting of the Apple checkbox in the\nFile->Generate Font dialog.\nThe main differences are:\n Bitmap data are stored in different tables\n Scaled composite glyphs are treated differently\n Use of GSUB rather than morx(t)/feat\n Use of GPOS rather than kern/opbd\n Use of GDEF rather than lcar/prop\nIf both this and OpenType are set, both formats are generated") },
530 { "AlwaysGenOpenType", pr_bool, &alwaysgenopentype, NULL, NULL, 'O', NULL, 0, N_("Apple and MS/Adobe differ about the format of truetype and opentype files.\nThis controls the default setting of the OpenType checkbox in the\nFile->Generate Font dialog.\nThe main differences are:\n Bitmap data are stored in different tables\n Scaled composite glyphs are treated differently\n Use of GSUB rather than morx(t)/feat\n Use of GPOS rather than kern/opbd\n Use of GDEF rather than lcar/prop\nIf both this and Apple are set, both formats are generated") },
531 { "DefaultTTFflags", pr_int, &old_ttf_flags, NULL, NULL, '\0', NULL, 1, NULL },
532 { "DefaultOTFflags", pr_int, &old_otf_flags, NULL, NULL, '\0', NULL, 1, NULL },
533 PREFS_LIST_EMPTY
534 },
535 *prefs_list[] = { general_list, new_list, open_list, navigation_list, sync_list, editing_list, editing_interface_list, accent_list, args_list, fontinfo_list, generate_list, tt_list, opentype_list, hints_list, instrs_list,
536 hidden_list, NULL },
537 *load_prefs_list[] = { general_list, new_list, open_list, navigation_list, sync_list, editing_list, editing_interface_list, accent_list, args_list, fontinfo_list, generate_list, tt_list, opentype_list, hints_list, instrs_list,
538 hidden_list, oldnames, NULL };
539
540 struct visible_prefs_list { char *tab_name; int nest; struct prefs_list *pl; } visible_prefs_list[] = {
541 { N_("Generic"), 0, general_list},
542 { N_("New Font"), 0, new_list},
543 { N_("Open Font"), 0, open_list},
544 { N_("Navigation"), 0, navigation_list},
545 { N_("Editing"), 0, editing_list},
546 { N_("Interface"), 1, editing_interface_list},
547 { N_("Synchronize"), 1, sync_list},
548 { N_("TT"), 1, tt_list},
549 { N_("Accents"), 1, accent_list},
550 { N_("Apps"), 1, args_list},
551 { N_("Font Info"), 0, fontinfo_list},
552 { N_("Generate"), 0, generate_list},
553 { N_("PS Hints"), 1, hints_list},
554 { N_("TT Instrs"), 1, instrs_list},
555 { N_("OpenType"), 1, opentype_list},
556 { NULL, 0, NULL }
557 };
558
559 static void FileChooserPrefsChanged(void *pointless) {
560 SavePrefs(true);
561 }
562
563 static void ProcessFileChooserPrefs(void) {
564 unichar_t **b;
565 int i;
566 #if _WIN32
567 char *userProfile = getenv("USERPROFILE");
568 unichar_t *u_userProfile = userProfile ? utf82u_copy(userProfile) : NULL;
569 u_GFileNormalizePath(u_userProfile);
570 #endif
571
572 GFileChooserSetShowHidden(gfc_showhidden);
573 GFileChooserSetDirectoryPlacement(gfc_dirplace);
574 if ( gfc_bookmarks==NULL ) {
575 b = malloc(8*sizeof(unichar_t *));
576 i = 0;
577 #ifdef __Mac
578 b[i++] = uc_copy("~/Library/Fonts/");
579 b[i++] = uc_copy("/Library/Fonts/");
580 b[i++] = uc_copy("/System/Library/Fonts/");
581 #elif _WIN32
582 b[i++] = uc_copy("C:/Windows/Fonts/");
583 if (u_userProfile != NULL) {
584 unichar_t *fontsPath = uc_copy("/AppData/Local/Microsoft/Windows/Fonts/");
585 b[i++] = u_concat(u_userProfile, fontsPath);
586 free(fontsPath);
587 free(u_userProfile);
588 }
589 #else /* Linux, Unix */
590 b[i++] = uc_copy("/usr/share/fonts/");
591 b[i++] = uc_copy("/usr/share/X11/fonts/");
592 b[i++] = uc_copy("~/.local/share/fonts/");
593 b[i++] = uc_copy("~/.fonts/");
594 #endif
595 b[i++] = NULL;
596 GFileChooserSetBookmarks(b);
597 } else {
598 char *pt, *start;
599 start = gfc_bookmarks;
600 for ( i=0; ; ++i ) {
601 pt = strchr(start,';');
602 if ( pt==NULL )
603 break;
604 start = pt+1;
605 }
606 start = gfc_bookmarks;
607 b = malloc((i+2)*sizeof(unichar_t *));
608 for ( i=0; ; ++i ) {
609 pt = strchr(start,';');
610 if ( pt!=NULL )
611 *pt = '\0';
612 b[i] = utf82u_copy(start);
613 if ( pt==NULL )
614 break;
615 *pt = ';';
616 start = pt+1;
617 }
618 b[i+1] = NULL;
619 GFileChooserSetBookmarks(b);
620 }
621 GFileChooserSetPrefsChangedCallback(NULL,FileChooserPrefsChanged);
622 }
623
624 static void GetFileChooserPrefs(void) {
625 unichar_t **foo;
626
627 gfc_showhidden = GFileChooserGetShowHidden();
628 gfc_dirplace = GFileChooserGetDirectoryPlacement();
629 foo = GFileChooserGetBookmarks();
630 free(gfc_bookmarks);
631 if ( foo==NULL || foo[0]==NULL )
632 gfc_bookmarks = NULL;
633 else {
634 int i,len=0;
635 for ( i=0; foo[i]!=NULL; ++i )
636 len += 4*u_strlen(foo[i])+1;
637 gfc_bookmarks = malloc(len+10);
638 len = 0;
639 for ( i=0; foo[i]!=NULL; ++i ) {
640 u2utf8_strcpy(gfc_bookmarks+len,foo[i]);
641 len += strlen(gfc_bookmarks+len);
642 gfc_bookmarks[len++] = ';';
643 }
644 if ( len>0 )
645 gfc_bookmarks[len-1] = '\0';
646 else {
647 free(gfc_bookmarks);
648 gfc_bookmarks = NULL;
649 }
650 }
651 }
652
653 #define TOPICS (sizeof(visible_prefs_list)/sizeof(visible_prefs_list[0])-1)
654
655 static int PrefsUI_GetPrefs(char *name,Val *val) {
656 int i,j;
657
658 /* Support for obsolete preferences */
659 alwaysgenapple=(old_sfnt_flags&ttf_flag_applemode)?1:0;
660 alwaysgenopentype=(old_sfnt_flags&ttf_flag_otmode)?1:0;
661
662 for ( i=0; prefs_list[i]!=NULL; ++i ) for ( j=0; prefs_list[i][j].name!=NULL; ++j ) {
663 if ( strcmp(prefs_list[i][j].name,name)==0 ) {
664 struct prefs_list *pf = &prefs_list[i][j];
665 if ( pf->type == pr_bool || pf->type == pr_int || pf->type == pr_unicode ) {
666 val->type = v_int;
667 val->u.ival = *((int *) (pf->val));
668 } else if ( pf->type == pr_string || pf->type == pr_file || pf->type == pr_shaper) {
669 val->type = v_str;
670
671 char *tmpstr = pf->val ? *((char **) (pf->val)) : (char *) (pf->get)();
672 val->u.sval = copy( tmpstr ? tmpstr : "" );
673
674 if( ! pf->val )
675 free( tmpstr );
676 } else if ( pf->type == pr_encoding ) {
677 val->type = v_str;
678 if ( *((NameList **) (pf->val))==NULL )
679 val->u.sval = copy( "NULL" );
680 else
681 val->u.sval = copy( (*((Encoding **) (pf->val)))->enc_name );
682 } else if ( pf->type == pr_namelist ) {
683 val->type = v_str;
684 val->u.sval = copy( (*((NameList **) (pf->val)))->title );
685 } else if ( pf->type == pr_real || pf->type == pr_angle ) {
686 val->type = v_real;
687 val->u.fval = *((float *) (pf->val));
688 if ( pf->type == pr_angle )
689 val->u.fval *= RAD2DEG;
690 } else
691 return( false );
692
693 return( true );
694 }
695 }
696 return( false );
697 }
698
699 static void CheckObsoletePrefs(void) {
700 if ( alwaysgenapple==false ) {
701 old_sfnt_flags &= ~ttf_flag_applemode;
702 } else if ( alwaysgenapple==true ) {
703 old_sfnt_flags |= ttf_flag_applemode;
704 }
705 if ( alwaysgenopentype==false ) {
706 old_sfnt_flags &= ~ttf_flag_otmode;
707 } else if ( alwaysgenopentype==true ) {
708 old_sfnt_flags |= ttf_flag_otmode;
709 }
710 if ( old_ttf_flags!=0 )
711 old_sfnt_flags = old_ttf_flags | old_otf_flags;
712 }
713
714 static int PrefsUI_SetPrefs(char *name,Val *val1, Val *val2) {
715 int i,j;
716
717 /* Support for obsolete preferences */
718 alwaysgenapple=-1; alwaysgenopentype=-1;
719
720 for ( i=0; prefs_list[i]!=NULL; ++i ) for ( j=0; prefs_list[i][j].name!=NULL; ++j ) {
721 if ( strcmp(prefs_list[i][j].name,name)==0 ) {
722 struct prefs_list *pf = &prefs_list[i][j];
723 if ( pf->type == pr_bool || pf->type == pr_int || pf->type == pr_unicode ) {
724 if ( (val1->type!=v_int && val1->type!=v_unicode) || val2!=NULL )
725 return( -1 );
726 *((int *) (pf->val)) = val1->u.ival;
727 } else if ( pf->type == pr_real || pf->type == pr_angle ) {
728 if ( val1->type==v_real && val2==NULL )
729 *((float *) (pf->val)) = val1->u.fval;
730 else if ( val1->type!=v_int || (val2!=NULL && val2->type!=v_int ))
731 return( -1 );
732 else
733 *((float *) (pf->val)) = (val2==NULL ? val1->u.ival : val1->u.ival / (double) val2->u.ival);
734 if ( pf->type == pr_angle )
735 *((float *) (pf->val)) /= RAD2DEG;
736 } else if ( pf->type == pr_string || pf->type == pr_file || pf->type == pr_shaper) {
737 if ( val1->type!=v_str || val2!=NULL )
738 return( -1 );
739 if ( pf->set ) {
740 pf->set( val1->u.sval );
741 } else {
742 free( *((char **) (pf->val)));
743 *((char **) (pf->val)) = copy( val1->u.sval );
744 }
745 } else if ( pf->type == pr_encoding ) {
746 if ( val2!=NULL )
747 return( -1 );
748 else if ( val1->type==v_str && pf->val == &default_encoding) {
749 Encoding *enc = FindOrMakeEncoding(val1->u.sval);
750 if ( enc==NULL )
751 return( -1 );
752 *((Encoding **) (pf->val)) = enc;
753 } else
754 return( -1 );
755 } else if ( pf->type == pr_namelist ) {
756 if ( val2!=NULL )
757 return( -1 );
758 else if ( val1->type==v_str ) {
759 NameList *nl = NameListByName(val1->u.sval);
760 if ( strcmp(val1->u.sval,"NULL")==0 && pf->val != &namelist_for_new_fonts )
761 nl = NULL;
762 else if ( nl==NULL )
763 return( -1 );
764 *((NameList **) (pf->val)) = nl;
765 } else
766 return( -1 );
767 } else
768 return( false );
769
770 CheckObsoletePrefs();
771 SavePrefs(true);
772 return( true );
773 }
774 }
775 return( false );
776 }
777
778 static char *getPfaEditPrefs(void) {
779 static char *prefs=NULL;
780 char buffer[1025];
781 char *ffdir;
782
783 if ( prefs!=NULL )
784 return prefs;
785 ffdir = getFontForgeUserDir(Config);
786 if ( ffdir==NULL )
787 return NULL;
788 sprintf(buffer,"%s/prefs", ffdir);
789 free(ffdir);
790 prefs = copy(buffer);
791 return prefs;
792 }
793
794 static const char *PrefsUI_getFontForgeShareDir(void) {
795 return getShareDir();
796 }
797
798 static void DefaultEncoding(void) {
799 const char* charset = NULL;
800 bool is_utf8 = g_get_charset(&charset);
801
802 if (!SetupUCharMap(FindUnicharName(), charset, is_utf8)) {
803 fprintf(stderr, "Failed to set up unichar<->system local encoding, assuming utf-8 and trying again...\n");
804 if (!SetupUCharMap(FindUnicharName(), "UTF-8", true)) {
805 fprintf(stderr, "Failed to set up unichar<->utf-8 encoding.");
806 assert(false);
807 }
808 }
809 }
810
811 static void DefaultXUID(void) {
812 /* Adobe has assigned PfaEdit a base XUID of 1021. Each new user is going */
813 /* to get a couple of random numbers appended to that, hoping that will */
814 /* make for a fairly safe system. */
815 /* FontForge will use the same scheme */
816 int r1, r2;
817 char buffer[50];
818 struct timeval tv;
819
820 gettimeofday(&tv,NULL);
821 srand(tv.tv_usec);
822 do {
823 r1 = rand()&0x3ff;
824 } while ( r1==0 ); /* I reserve "0" for me! */
825 gettimeofday(&tv,NULL);
826 g_random_set_seed(tv.tv_usec+1);
827 r2 = g_random_int();
828 sprintf( buffer, "1021 %d %d", r1, r2 );
829 if (xuid != NULL) free(xuid);
830 xuid = copy(buffer);
831 }
832
833 static void PrefsUI_SetDefaults(void) {
834 DefaultXUID();
835 DefaultEncoding();
836 }
837
838 static void ParseMacMapping(char *pt,struct macsettingname *ms) {
839 char *end;
840
841 ms->mac_feature_type = strtol(pt,&end,10);
842 if ( *end==',' ) ++end;
843 ms->mac_feature_setting = strtol(end,&end,10);
844 if ( *end==' ' ) ++end;
845 ms->otf_tag =
846 ((end[0]&0xff)<<24) |
847 ((end[1]&0xff)<<16) |
848 ((end[2]&0xff)<<8) |
849 (end[3]&0xff);
850 }
851
852 static void ParseNewMacFeature(FILE *p,char *line) {
853 fseek(p,-(strlen(line)-strlen("MacFeat:")),SEEK_CUR);
854 line[strlen("MacFeat:")] ='\0';
855 default_mac_feature_map = SFDParseMacFeatures(p,line);
856 fseek(p,-strlen(line),SEEK_CUR);
857 if ( user_mac_feature_map!=NULL )
858 MacFeatListFree(user_mac_feature_map);
859 user_mac_feature_map = default_mac_feature_map;
860 }
861
862 static void PrefsUI_LoadPrefs_FromFile( char* filename )
863 {
864 FILE *p;
865 char line[1100];
866 int i, j, ri=0, mn=0, ms=0, fn=0, ff=0, filt_max=0;
867 int msp=0, msc=0;
868 char *pt;
869 struct prefs_list *pl;
870
871 if ( filename!=NULL && (p=fopen(filename,"r"))!=NULL ) {
872 while ( fgets(line,sizeof(line),p)!=NULL ) {
873 if ( *line=='#' )
874 continue;
875 pt = strchr(line,':');
876 if ( pt==NULL )
877 continue;
878 for ( j=0; load_prefs_list[j]!=NULL; ++j ) {
879 for ( i=0; load_prefs_list[j][i].name!=NULL; ++i )
880 if ( strncmp(line,load_prefs_list[j][i].name,pt-line)==0 )
881 break;
882 if ( load_prefs_list[j][i].name!=NULL )
883 break;
884 }
885 pl = NULL;
886 if ( load_prefs_list[j]!=NULL )
887 pl = &load_prefs_list[j][i];
888 for ( ++pt; *pt=='\t'; ++pt );
889 if ( line[strlen(line)-1]=='\n' )
890 line[strlen(line)-1] = '\0';
891 if ( line[strlen(line)-1]=='\r' )
892 line[strlen(line)-1] = '\0';
893 if ( pl==NULL ) {
894 if ( strncmp(line,"Recent:",strlen("Recent:"))==0 && ri<RECENT_MAX )
895 RecentFiles[ri++] = copy(pt);
896 else if ( strncmp(line,"MenuScript:",strlen("MenuScript:"))==0 && ms<SCRIPT_MENU_MAX )
897 script_filenames[ms++] = copy(pt);
898 else if ( strncmp(line,"MenuName:",strlen("MenuName:"))==0 && mn<SCRIPT_MENU_MAX )
899 script_menu_names[mn++] = utf82u_copy(pt);
900 else if ( strncmp(line,"FontFilterName:",strlen("FontFilterName:"))==0 ) {
901 if ( fn>=filt_max )
902 user_font_filters = realloc(user_font_filters,((filt_max+=10)+1)*sizeof( struct openfilefilters));
903 user_font_filters[fn].filter = NULL;
904 user_font_filters[fn++].name = copy(pt);
905 user_font_filters[fn].name = NULL;
906 } else if ( strncmp(line,"FontFilter:",strlen("FontFilter:"))==0 ) {
907 if ( ff<filt_max )
908 user_font_filters[ff++].filter = copy(pt);
909 } else if ( strncmp(line,"MacMapCnt:",strlen("MacSetCnt:"))==0 ) {
910 sscanf( pt, "%d", &msc );
911 msp = 0;
912 user_macfeat_otftag = calloc(msc+1,sizeof(struct macsettingname));
913 } else if ( strncmp(line,"MacMapping:",strlen("MacMapping:"))==0 && msp<msc ) {
914 ParseMacMapping(pt,&user_macfeat_otftag[msp++]);
915 } else if ( strncmp(line,"MacFeat:",strlen("MacFeat:"))==0 ) {
916 ParseNewMacFeature(p,line);
917 }
918 continue;
919 }
920 switch ( pl->type ) {
921 case pr_encoding:
922 { Encoding *enc = FindOrMakeEncoding(pt);
923 if ( enc==NULL )
924 enc = FindOrMakeEncoding("ISO8859-1");
925 if ( enc==NULL )
926 enc = &custom;
927 *((Encoding **) (pl->val)) = enc;
928 }
929 break;
930 case pr_namelist:
931 { NameList *nl = NameListByName(pt);
932 if ( strcmp(pt,"NULL")==0 && pl->val != &namelist_for_new_fonts )
933 *((NameList **) (pl->val)) = NULL;
934 else if ( nl!=NULL )
935 *((NameList **) (pl->val)) = nl;
936 }
937 break;
938 case pr_bool: case pr_int:
939 sscanf( pt, "%d", (int *) pl->val );
940 break;
941 case pr_unicode:
942 if ( sscanf( pt, "U+%x", (int *) pl->val )!=1 )
943 if ( sscanf( pt, "u+%x", (int *) pl->val )!=1 )
944 sscanf( pt, "%x", (int *) pl->val );
945 break;
946 case pr_real: case pr_angle:
947 { char *end;
948 *((float *) pl->val) = strtod(pt,&end);
949 if (( *end==',' || *end=='.' ) ) {
950 *end = (*end=='.')?',':'.';
951 *((float *) pl->val) = strtod(pt,NULL);
952 }
953 }
954 if ( pl->type == pr_angle )
955 *(float *) pl->val /= RAD2DEG;
956 break;
957 case pr_string: case pr_file: case pr_shaper:
958 if ( *pt=='\0' ) pt=NULL;
959 if ( pl->val!=NULL )
960 *((char **) (pl->val)) = copy(pt);
961 else
962 (pl->set)(copy(pt));
963 break;
964 }
965 }
966 fclose(p);
967 }
968 }
969
970 void Prefs_LoadDefaultPreferences( void )
971 {
972 char filename[PATH_MAX+1];
973 const char* sharedir = getShareDir();
974
975 snprintf(filename,PATH_MAX,"%s/prefs", sharedir );
976 PrefsUI_LoadPrefs_FromFile( filename );
977 }
978
979
980 static void PrefsUI_LoadPrefs(void)
981 {
982 char *prefs = getPfaEditPrefs();
983 FILE *p;
984 char line[1100], path[PATH_MAX];
985 int i, j, ri=0, mn=0, ms=0, fn=0, ff=0, filt_max=0;
986 int msp=0, msc=0;
987 char *pt, *real_xdefs_filename = NULL;
988 struct prefs_list *pl;
989
990 LoadPfaEditEncodings();
991 LoadGroupList();
992
993 if ( prefs!=NULL && (p=fopen(prefs,"r"))!=NULL ) {
994 while ( fgets(line,sizeof(line),p)!=NULL ) {
995 if ( *line=='#' )
996 continue;
997 pt = strchr(line,':');
998 if ( pt==NULL )
999 continue;
1000 for ( j=0; load_prefs_list[j]!=NULL; ++j ) {
1001 for ( i=0; load_prefs_list[j][i].name!=NULL; ++i )
1002 if ( strncmp(line,load_prefs_list[j][i].name,pt-line)==0 )
1003 break;
1004 if ( load_prefs_list[j][i].name!=NULL )
1005 break;
1006 }
1007 pl = NULL;
1008 if ( load_prefs_list[j]!=NULL )
1009 pl = &load_prefs_list[j][i];
1010 for ( ++pt; *pt=='\t'; ++pt );
1011 if ( line[strlen(line)-1]=='\n' )
1012 line[strlen(line)-1] = '\0';
1013 if ( line[strlen(line)-1]=='\r' )
1014 line[strlen(line)-1] = '\0';
1015 if ( pl==NULL ) {
1016 if ( strncmp(line,"Recent:",strlen("Recent:"))==0 && ri<RECENT_MAX )
1017 RecentFiles[ri++] = copy(pt);
1018 else if ( strncmp(line,"MenuScript:",strlen("MenuScript:"))==0 && ms<SCRIPT_MENU_MAX )
1019 script_filenames[ms++] = copy(pt);
1020 else if ( strncmp(line,"MenuName:",strlen("MenuName:"))==0 && mn<SCRIPT_MENU_MAX )
1021 script_menu_names[mn++] = utf82u_copy(pt);
1022 else if ( strncmp(line,"FontFilterName:",strlen("FontFilterName:"))==0 ) {
1023 if ( fn>=filt_max )
1024 user_font_filters = realloc(user_font_filters,((filt_max+=10)+1)*sizeof( struct openfilefilters));
1025 user_font_filters[fn].filter = NULL;
1026 user_font_filters[fn++].name = copy(pt);
1027 user_font_filters[fn].name = NULL;
1028 } else if ( strncmp(line,"FontFilter:",strlen("FontFilter:"))==0 ) {
1029 if ( ff<filt_max )
1030 user_font_filters[ff++].filter = copy(pt);
1031 } else if ( strncmp(line,"MacMapCnt:",strlen("MacSetCnt:"))==0 ) {
1032 sscanf( pt, "%d", &msc );
1033 msp = 0;
1034 user_macfeat_otftag = calloc(msc+1,sizeof(struct macsettingname));
1035 } else if ( strncmp(line,"MacMapping:",strlen("MacMapping:"))==0 && msp<msc ) {
1036 ParseMacMapping(pt,&user_macfeat_otftag[msp++]);
1037 } else if ( strncmp(line,"MacFeat:",strlen("MacFeat:"))==0 ) {
1038 ParseNewMacFeature(p,line);
1039 }
1040 continue;
1041 }
1042 switch ( pl->type ) {
1043 case pr_encoding:
1044 { Encoding *enc = FindOrMakeEncoding(pt);
1045 if ( enc==NULL )
1046 enc = FindOrMakeEncoding("ISO8859-1");
1047 if ( enc==NULL )
1048 enc = &custom;
1049 *((Encoding **) (pl->val)) = enc;
1050 }
1051 break;
1052 case pr_namelist:
1053 { NameList *nl = NameListByName(pt);
1054 if ( strcmp(pt,"NULL")==0 && pl->val != &namelist_for_new_fonts )
1055 *((NameList **) (pl->val)) = NULL;
1056 else if ( nl!=NULL )
1057 *((NameList **) (pl->val)) = nl;
1058 }
1059 break;
1060 case pr_bool: case pr_int:
1061 sscanf( pt, "%d", (int *) pl->val );
1062 break;
1063 case pr_unicode:
1064 if ( sscanf( pt, "U+%x", (int *) pl->val )!=1 )
1065 if ( sscanf( pt, "u+%x", (int *) pl->val )!=1 )
1066 sscanf( pt, "%x", (int *) pl->val );
1067 break;
1068 case pr_real: case pr_angle:
1069 { char *end;
1070 *((float *) pl->val) = strtod(pt,&end);
1071 if (( *end==',' || *end=='.' ) ) {
1072 *end = (*end=='.')?',':'.';
1073 *((float *) pl->val) = strtod(pt,NULL);
1074 }
1075 }
1076 if ( pl->type == pr_angle )
1077 *(float *) pl->val /= RAD2DEG;
1078 break;
1079 case pr_string: case pr_file: case pr_shaper:
1080 if ( *pt=='\0' ) pt=NULL;
1081 if ( pl->val!=NULL )
1082 *((char **) (pl->val)) = copy(pt);
1083 else
1084 (pl->set)(copy(pt));
1085 break;
1086 }
1087 }
1088 fclose(p);
1089 }
1090
1091 //
1092 // If the user has no theme set, then use the default
1093 //
1094 real_xdefs_filename = xdefs_filename;
1095 if ( !real_xdefs_filename )
1096 {
1097 // fprintf(stderr,"no xdefs_filename!\n");
1098 // if (!quiet) {
1099 // fprintf(stderr,"TESTING: getPixmapDir:%s\n", getPixmapDir() );
1100 // fprintf(stderr,"TESTING: getShareDir:%s\n", getShareDir() );
1101 // }
1102 snprintf(path, PATH_MAX, "%s/%s", getPixmapDir(), "resources" );
1103 // if (!quiet)
1104 // fprintf(stderr,"trying default theme:%s\n", path );
1105 real_xdefs_filename = path;
1106 }
1107 GResourceAddResourceFile(real_xdefs_filename,GResourceProgramName,true);
1108
1109 if ( othersubrsfile!=NULL && ReadOtherSubrsFile(othersubrsfile)<=0 )
1110 fprintf( stderr, "Failed to read OtherSubrs from %s\n", othersubrsfile );
1111
1112 if ( glyph_2_name_map )
1113 old_sfnt_flags |= ttf_flag_glyphmap;
1114 LoadNamelistDir(NULL);
1115 ProcessFileChooserPrefs();
1116 }
1117
1118 static void PrefsUI_SavePrefs(int not_if_script) {
1119 char *prefs = getPfaEditPrefs();
1120 FILE *p;
1121 int i, j;
1122 char *temp;
1123 struct prefs_list *pl;
1124 extern int running_script;
1125
1126 if ( prefs==NULL )
1127 return;
1128 if ( not_if_script && running_script )
1129 return;
1130
1131 if ( (p=fopen(prefs,"w"))==NULL )
1132 return;
1133
1134 GetFileChooserPrefs();
1135
1136 for ( j=0; prefs_list[j]!=NULL; ++j ) for ( i=0; prefs_list[j][i].name!=NULL; ++i ) {
1137 pl = &prefs_list[j][i];
1138 switch ( pl->type ) {
1139 case pr_encoding:
1140 fprintf( p, "%s:\t%s\n", pl->name, (*((Encoding **) (pl->val)))->enc_name );
1141 break;
1142 case pr_namelist:
1143 fprintf( p, "%s:\t%s\n", pl->name, *((NameList **) (pl->val))==NULL ? "NULL" :
1144 (*((NameList **) (pl->val)))->title );
1145 break;
1146 case pr_bool: case pr_int:
1147 fprintf( p, "%s:\t%d\n", pl->name, *(int *) (pl->val) );
1148 break;
1149 case pr_unicode:
1150 fprintf( p, "%s:\tU+%04x\n", pl->name, *(int *) (pl->val) );
1151 break;
1152 case pr_real:
1153 fprintf( p, "%s:\t%g\n", pl->name, (double) *(float *) (pl->val) );
1154 break;
1155 case pr_string: case pr_file:
1156 if ( (pl->val)!=NULL )
1157 temp = *(char **) (pl->val);
1158 else
1159 temp = (char *) (pl->get());
1160 if ( temp!=NULL )
1161 fprintf( p, "%s:\t%s\n", pl->name, temp );
1162 if ( (pl->val)==NULL )
1163 free(temp);
1164 break;
1165 case pr_shaper:
1166 temp = (char *) (pl->get());
1167 if ( temp!=NULL )
1168 fprintf( p, "%s:\t%s\n", pl->name, temp );
1169 break;
1170 case pr_angle:
1171 fprintf( p, "%s:\t%g\n", pl->name, ((double) *(float *) pl->val) * RAD2DEG );
1172 break;
1173 }
1174 }
1175
1176 for ( i=0; i<RECENT_MAX && RecentFiles[i]!=NULL; ++i )
1177 fprintf( p, "Recent:\t%s\n", RecentFiles[i]);
1178 for ( i=0; i<SCRIPT_MENU_MAX && script_filenames[i]!=NULL; ++i ) {
1179 fprintf( p, "MenuScript:\t%s\n", script_filenames[i]);
1180 fprintf( p, "MenuName:\t%s\n", temp = u2utf8_copy(script_menu_names[i]));
1181 free(temp);
1182 }
1183 if ( user_font_filters!=NULL ) {
1184 for ( i=0; user_font_filters[i].name!=NULL; ++i ) {
1185 fprintf( p, "FontFilterName:\t%s\n", user_font_filters[i].name);
1186 fprintf( p, "FontFilter:\t%s\n", user_font_filters[i].filter);
1187 }
1188 }
1189 if ( user_macfeat_otftag!=NULL && UserSettingsDiffer()) {
1190 for ( i=0; user_macfeat_otftag[i].otf_tag!=0; ++i );
1191 fprintf( p, "MacMapCnt: %d\n", i );
1192 for ( i=0; user_macfeat_otftag[i].otf_tag!=0; ++i ) {
1193 fprintf( p, "MacMapping: %d,%d %c%c%c%c\n",
1194 user_macfeat_otftag[i].mac_feature_type,
1195 user_macfeat_otftag[i].mac_feature_setting,
1196 (int) (user_macfeat_otftag[i].otf_tag>>24),
1197 (int) ((user_macfeat_otftag[i].otf_tag>>16)&0xff),
1198 (int) ((user_macfeat_otftag[i].otf_tag>>8)&0xff),
1199 (int) (user_macfeat_otftag[i].otf_tag&0xff) );
1200 }
1201 }
1202
1203 if ( UserFeaturesDiffer())
1204 SFDDumpMacFeat(p,default_mac_feature_map);
1205
1206 fclose(p);
1207 }
1208
1209 struct pref_data {
1210 int done;
1211 struct prefs_list* plist;
1212 };
1213
1214 static int Prefs_ScriptBrowse(GGadget *g, GEvent *e) {
1215 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1216 GWindow gw = GGadgetGetWindow(g);
1217 GGadget *tf = GWidgetGetControl(gw,GGadgetGetCid(g)-SCRIPT_MENU_MAX);
1218 char *cur = GGadgetGetTitle8(tf); char *ret;
1219
1220 if ( *cur=='\0' ) cur=NULL;
1221 ret = gwwv_open_filename(_("Call Script"), cur, "*.pe", NULL);
1222 free(cur);
1223 if ( ret==NULL )
1224 return(true);
1225 GGadgetSetTitle8(tf,ret);
1226 free(ret);
1227 }
1228 return( true );
1229 }
1230
1231 static int Prefs_BrowseFile(GGadget *g, GEvent *e) {
1232 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1233 GWindow gw = GGadgetGetWindow(g);
1234 GGadget *tf = GWidgetGetControl(gw,GGadgetGetCid(g)-CID_PrefsBrowseOffset);
1235 char *cur = GGadgetGetTitle8(tf); char *ret;
1236 struct prefs_list *pl = GGadgetGetUserData(tf);
1237
1238 ret = gwwv_open_filename(pl->name, *cur=='\0'? NULL : cur, NULL, NULL);
1239 free(cur);
1240 if ( ret==NULL )
1241 return(true);
1242 GGadgetSetTitle8(tf,ret);
1243 free(ret);
1244 }
1245 return( true );
1246 }
1247
1248 static GTextInfo *Pref_MappingList(int use_user) {
1249 struct macsettingname *msn = use_user && user_macfeat_otftag!=NULL ?
1250 user_macfeat_otftag :
1251 macfeat_otftag;
1252 GTextInfo *ti;
1253 int i;
1254 char buf[60];
1255
1256 for ( i=0; msn[i].otf_tag!=0; ++i );
1257 ti = calloc(i+1,sizeof( GTextInfo ));
1258
1259 for ( i=0; msn[i].otf_tag!=0; ++i ) {
1260 sprintf(buf,"%3d,%2d %c%c%c%c",
1261 msn[i].mac_feature_type, msn[i].mac_feature_setting,
1262 (int) (msn[i].otf_tag>>24), (int) ((msn[i].otf_tag>>16)&0xff), (int) ((msn[i].otf_tag>>8)&0xff), (int) (msn[i].otf_tag&0xff) );
1263 ti[i].text = uc_copy(buf);
1264 }
1265 return( ti );
1266 }
1267
1268 void GListAddStr(GGadget *list,unichar_t *str, void *ud) {
1269 int32_t i,len;
1270 GTextInfo **ti = GGadgetGetList(list,&len);
1271 GTextInfo **replace = malloc((len+2)*sizeof(GTextInfo *));
1272
1273 replace[len+1] = calloc(1,sizeof(GTextInfo));
1274 for ( i=0; i<len; ++i ) {
1275 replace[i] = malloc(sizeof(GTextInfo));
1276 *replace[i] = *ti[i];
1277 replace[i]->text = u_copy(ti[i]->text);
1278 }
1279 replace[i] = calloc(1,sizeof(GTextInfo));
1280 replace[i]->fg = replace[i]->bg = COLOR_DEFAULT;
1281 replace[i]->text = str;
1282 replace[i]->userdata = ud;
1283 GGadgetSetList(list,replace,false);
1284 }
1285
1286 void GListReplaceStr(GGadget *list,int index, unichar_t *str, void *ud) {
1287 int32_t i,len;
1288 GTextInfo **ti = GGadgetGetList(list,&len);
1289 GTextInfo **replace = malloc((len+2)*sizeof(GTextInfo *));
1290
1291 for ( i=0; i<len; ++i ) {
1292 replace[i] = malloc(sizeof(GTextInfo));
1293 *replace[i] = *ti[i];
1294 if ( i!=index )
1295 replace[i]->text = u_copy(ti[i]->text);
1296 }
1297 replace[i] = calloc(1,sizeof(GTextInfo));
1298 replace[index]->text = str;
1299 replace[index]->userdata = ud;
1300 GGadgetSetList(list,replace,false);
1301 }
1302
1303 struct setdata {
1304 GWindow gw;
1305 GGadget *list;
1306 GGadget *flist;
1307 GGadget *feature;
1308 GGadget *set_code;
1309 GGadget *otf;
1310 GGadget *ok;
1311 GGadget *cancel;
1312 int index;
1313 int done;
1314 unichar_t *ret;
1315 };
1316
1317 static int set_e_h(GWindow gw, GEvent *event) {
1318 struct setdata *sd = GDrawGetUserData(gw);
1319 int i;
1320 int32_t len;
1321 GTextInfo **ti;
1322 const unichar_t *ret1; unichar_t *end;
1323 int on, feat, val1, val2;
1324 unichar_t ubuf[4];
1325 char buf[40];
1326
1327 if ( event->type==et_close ) {
1328 sd->done = true;
1329 } else if ( event->type==et_char ) {
1330 if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) {
1331 help("ui/dialogs/prefs.html", "#prefs-features");
1332 return( true );
1333 }
1334 return( false );
1335 } else if ( event->type==et_controlevent && event->u.control.subtype == et_buttonactivate ) {
1336 if ( event->u.control.g == sd->cancel ) {
1337 sd->done = true;
1338 } else if ( event->u.control.g == sd->ok ) {
1339 ret1 = _GGadgetGetTitle(sd->set_code);
1340 on = u_strtol(ret1,&end,10);
1341 if ( *end!='\0' ) {
1342 ff_post_error(_("Bad Number"),_("Bad Number"));
1343 return( true );
1344 }
1345 ret1 = _GGadgetGetTitle(sd->feature);
1346 feat = u_strtol(ret1,&end,10);
1347 if ( *end!='\0' && *end!=' ' ) {
1348 ff_post_error(_("Bad Number"),_("Bad Number"));
1349 return( true );
1350 }
1351 ti = GGadgetGetList(sd->list,&len);
1352 for ( i=0; i<len; ++i ) if ( i!=sd->index ) {
1353 val1 = u_strtol(ti[i]->text,&end,10);
1354 val2 = u_strtol(end+1,NULL,10);
1355 if ( val1==feat && val2==on ) {
1356 static char *buts[3];
1357 buts[0] = _("_Yes");
1358 buts[1] = _("_No");
1359 buts[2] = NULL;
1360 if ( gwwv_ask(_("This feature, setting combination is already used"),(const char **) buts,0,1,
1361 _("This feature, setting combination is already used\nDo you really wish to reuse it?"))==1 )
1362 return( true );
1363 }
1364 }
1365
1366 ret1 = _GGadgetGetTitle(sd->otf);
1367 if ( (ubuf[0] = ret1[0])==0 )
1368 ubuf[0] = ubuf[1] = ubuf[2] = ubuf[3] = ' ';
1369 else if ( (ubuf[1] = ret1[1])==0 )
1370 ubuf[1] = ubuf[2] = ubuf[3] = ' ';
1371 else if ( (ubuf[2] = ret1[2])==0 )
1372 ubuf[2] = ubuf[3] = ' ';
1373 else if ( (ubuf[3] = ret1[3])==0 )
1374 ubuf[3] = ' ';
1375 len = u_strlen(ret1);
1376 if ( len<2 || len>4 || ubuf[0]>=0x7f || ubuf[1]>=0x7f || ubuf[2]>=0x7f || ubuf[3]>=0x7f ) {
1377 ff_post_error(_("Tag too long"),_("Feature tags must be exactly 4 ASCII characters"));
1378 return( true );
1379 }
1380 sprintf(buf,"%3d,%2d %c%c%c%c",
1381 feat, on,
1382 ubuf[0], ubuf[1], ubuf[2], ubuf[3]);
1383 sd->done = true;
1384 sd->ret = uc_copy(buf);
1385 }
1386 }
1387 return( true );
1388 }
1389
1390 static unichar_t *AskSetting(struct macsettingname *temp,GGadget *list, int index,GGadget *flist) {
1391 GRect pos;
1392 GWindow gw;
1393 GWindowAttrs wattrs;
1394 GGadgetCreateData gcd[17];
1395 GTextInfo label[17];
1396 struct setdata sd;
1397 char buf[20];
1398 unichar_t ubuf3[6];
1399 int32_t len, i;
1400 GTextInfo **ti;
1401
1402 memset(&sd,0,sizeof(sd));
1403 sd.list = list;
1404 sd.flist = flist;
1405 sd.index = index;
1406
1407 memset(&wattrs,0,sizeof(wattrs));
1408 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_restrict|wam_isdlg;
1409 wattrs.event_masks = ~(1<<et_charup);
1410 wattrs.restrict_input_to_me = 1;
1411 wattrs.is_dlg = 1;
1412 wattrs.undercursor = 1;
1413 wattrs.cursor = ct_pointer;
1414 wattrs.utf8_window_title = _("Mapping");
1415 pos.x = pos.y = 0;
1416 pos.width = GGadgetScale(GDrawPointsToPixels(NULL,240));
1417 pos.height = GDrawPointsToPixels(NULL,120);
1418 gw = GDrawCreateTopWindow(NULL,&pos,set_e_h,&sd,&wattrs);
1419 sd.gw = gw;
1420
1421 memset(gcd,0,sizeof(gcd));
1422 memset(label,0,sizeof(label));
1423
1424 label[0].text = (unichar_t *) _("_Feature:");
1425 label[0].text_is_1byte = true;
1426 label[0].text_in_resource = true;
1427 gcd[0].gd.label = &label[0];
1428 gcd[0].gd.pos.x = 5; gcd[0].gd.pos.y = 5+4;
1429 gcd[0].gd.flags = gg_enabled|gg_visible;
1430 gcd[0].creator = GLabelCreate;
1431
1432 gcd[1].gd.pos.x = 50; gcd[1].gd.pos.y = 5; gcd[1].gd.pos.width = 170;
1433 gcd[1].gd.flags = gg_enabled|gg_visible;
1434 gcd[1].creator = GListButtonCreate;
1435
1436 label[2].text = (unichar_t *) _("Setting");
1437 label[2].text_is_1byte = true;
1438 gcd[2].gd.label = &label[2];
1439 gcd[2].gd.pos.x = 5; gcd[2].gd.pos.y = gcd[0].gd.pos.y+26;
1440 gcd[2].gd.flags = gg_enabled|gg_visible;
1441 gcd[2].creator = GLabelCreate;
1442
1443 sprintf( buf, "%d", temp->mac_feature_setting );
1444 label[3].text = (unichar_t *) buf;
1445 label[3].text_is_1byte = true;
1446 gcd[3].gd.label = &label[3];
1447 gcd[3].gd.pos.x = gcd[1].gd.pos.x; gcd[3].gd.pos.y = gcd[2].gd.pos.y-4; gcd[3].gd.pos.width = 50;
1448 gcd[3].gd.flags = gg_enabled|gg_visible;
1449 gcd[3].creator = GTextFieldCreate;
1450
1451 label[4].text = (unichar_t *) _("_Tag:");
1452 label[4].text_is_1byte = true;
1453 label[4].text_in_resource = true;
1454 gcd[4].gd.label = &label[4];
1455 gcd[4].gd.pos.x = 5; gcd[4].gd.pos.y = gcd[3].gd.pos.y+26;
1456 gcd[4].gd.flags = gg_enabled|gg_visible;
1457 gcd[4].creator = GLabelCreate;
1458
1459 ubuf3[0] = temp->otf_tag>>24; ubuf3[1] = (temp->otf_tag>>16)&0xff; ubuf3[2] = (temp->otf_tag>>8)&0xff; ubuf3[3] = temp->otf_tag&0xff; ubuf3[4] = 0;
1460 label[5].text = ubuf3;
1461 gcd[5].gd.label = &label[5];
1462 gcd[5].gd.pos.x = gcd[3].gd.pos.x; gcd[5].gd.pos.y = gcd[4].gd.pos.y-4; gcd[5].gd.pos.width = 50;
1463 gcd[5].gd.flags = gg_enabled|gg_visible;
1464 /*gcd[5].gd.u.list = tags;*/
1465 gcd[5].creator = GTextFieldCreate;
1466
1467 gcd[6].gd.pos.x = 13-3; gcd[6].gd.pos.y = gcd[5].gd.pos.y+30;
1468 gcd[6].gd.pos.width = -1; gcd[6].gd.pos.height = 0;
1469 gcd[6].gd.flags = gg_visible | gg_enabled | gg_but_default;
1470 label[6].text = (unichar_t *) _("_OK");
1471 label[6].text_is_1byte = true;
1472 label[6].text_in_resource = true;
1473 gcd[6].gd.label = &label[6];
1474 /*gcd[6].gd.handle_controlevent = Prefs_Ok;*/
1475 gcd[6].creator = GButtonCreate;
1476
1477 gcd[7].gd.pos.x = -13; gcd[7].gd.pos.y = gcd[7-1].gd.pos.y+3;
1478 gcd[7].gd.pos.width = -1; gcd[7].gd.pos.height = 0;
1479 gcd[7].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
1480 label[7].text = (unichar_t *) _("_Cancel");
1481 label[7].text_is_1byte = true;
1482 label[7].text_in_resource = true;
1483 gcd[7].gd.label = &label[7];
1484 gcd[7].creator = GButtonCreate;
1485
1486 GGadgetsCreate(gw,gcd);
1487 sd.feature = gcd[1].ret;
1488 sd.set_code = gcd[3].ret;
1489 sd.otf = gcd[5].ret;
1490 sd.ok = gcd[6].ret;
1491 sd.cancel = gcd[7].ret;
1492
1493 ti = GGadgetGetList(flist,&len);
1494 GGadgetSetList(sd.feature,ti,true);
1495 for ( i=0; i<len; ++i ) {
1496 int val = u_strtol(ti[i]->text,NULL,10);
1497 if ( val==temp->mac_feature_type ) {
1498 GGadgetSetTitle(sd.feature,ti[i]->text);
1499 break;
1500 }
1501 }
1502
1503 GDrawSetVisible(gw,true);
1504 GWidgetIndicateFocusGadget(gcd[1].ret);
1505 while ( !sd.done )
1506 GDrawProcessOneEvent(NULL);
1507 GDrawDestroyWindow(gw);
1508
1509 return( sd.ret );
1510 }
1511
1512 static void ChangeSetting(GGadget *list,int index,GGadget *flist) {
1513 struct macsettingname temp;
1514 int32_t len;
1515 GTextInfo **ti = GGadgetGetList(list,&len);
1516 char *str;
1517 unichar_t *ustr;
1518
1519 str = cu_copy(ti[index]->text);
1520 ParseMacMapping(str,&temp);
1521 free(str);
1522 if ( (ustr=AskSetting(&temp,list,index,flist))==NULL )
1523 return;
1524 GListReplaceStr(list,index,ustr,NULL);
1525 }
1526
1527 static int Pref_NewMapping(GGadget *g, GEvent *e) {
1528 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1529 GWindow gw = GGadgetGetWindow(g);
1530 GGadget *list = GWidgetGetControl(gw,CID_Mapping);
1531 GGadget *flist = GWidgetGetControl(GDrawGetParentWindow(gw),CID_Features);
1532 struct macsettingname temp;
1533 unichar_t *str;
1534
1535 memset(&temp,0,sizeof(temp));
1536 temp.mac_feature_type = -1;
1537 if ( (str=AskSetting(&temp,list,-1,flist))==NULL )
1538 return( true );
1539 GListAddStr(list,str,NULL);
1540 /*free(str);*/
1541 }
1542 return( true );
1543 }
1544
1545 static int Pref_DelMapping(GGadget *g, GEvent *e) {
1546 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1547 GWindow gw = GGadgetGetWindow(g);
1548 GListDelSelected(GWidgetGetControl(gw,CID_Mapping));
1549 GGadgetSetEnabled(GWidgetGetControl(gw,CID_MappingDel),false);
1550 GGadgetSetEnabled(GWidgetGetControl(gw,CID_MappingEdit),false);
1551 }
1552 return( true );
1553 }
1554
1555 static int Pref_EditMapping(GGadget *g, GEvent *e) {
1556 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1557 GWindow gw = GDrawGetParentWindow(GGadgetGetWindow(g));
1558 GGadget *list = GWidgetGetControl(gw,CID_Mapping);
1559 GGadget *flist = GWidgetGetControl(gw,CID_Features);
1560 ChangeSetting(list,GGadgetGetFirstListSelectedItem(list),flist);
1561 }
1562 return( true );
1563 }
1564
1565 static int Pref_MappingSel(GGadget *g, GEvent *e) {
1566 if ( e->type==et_controlevent && e->u.control.subtype == et_listselected ) {
1567 int32_t len;
1568 GTextInfo **ti = GGadgetGetList(g,&len);
1569 GWindow gw = GGadgetGetWindow(g);
1570 int i, sel_cnt=0;
1571 for ( i=0; i<len; ++i )
1572 if ( ti[i]->selected ) ++sel_cnt;
1573 GGadgetSetEnabled(GWidgetGetControl(gw,CID_MappingDel),sel_cnt!=0);
1574 GGadgetSetEnabled(GWidgetGetControl(gw,CID_MappingEdit),sel_cnt==1);
1575 } else if ( e->type==et_controlevent && e->u.control.subtype == et_listdoubleclick ) {
1576 GGadget *flist = GWidgetGetControl( GDrawGetParentWindow(GGadgetGetWindow(g)),CID_Features);
1577 ChangeSetting(g,e->u.control.u.list.changed_index!=-1?e->u.control.u.list.changed_index:
1578 GGadgetGetFirstListSelectedItem(g),flist);
1579 }
1580 return( true );
1581 }
1582
1583 static int Pref_DefaultMapping(GGadget *g, GEvent *e) {
1584 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1585 GGadget *list = GWidgetGetControl(GGadgetGetWindow(g),CID_Mapping);
1586 GTextInfo *ti, **arr;
1587 uint16_t cnt;
1588
1589 ti = Pref_MappingList(false);
1590 arr = GTextInfoArrayFromList(ti,&cnt);
1591 GGadgetSetList(list,arr,false);
1592 GTextInfoListFree(ti);
1593 }
1594 return( true );
1595 }
1596
1597 static int Prefs_Ok(GGadget *g, GEvent *e) {
1598 int i, j, mi;
1599 int err=0;
1600 struct pref_data *p;
1601 GWindow gw;
1602 const unichar_t *ret;
1603 const unichar_t *names[SCRIPT_MENU_MAX], *scripts[SCRIPT_MENU_MAX];
1604 struct prefs_list *pl;
1605 GTextInfo **list;
1606 int32_t len;
1607 char *buf, *str;
1608 real dangle;
1609
1610 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1611 gw = GGadgetGetWindow(g);
1612 p = GDrawGetUserData(gw);
1613 for ( i=0; i<SCRIPT_MENU_MAX; ++i ) {
1614 names[i] = _GGadgetGetTitle(GWidgetGetControl(gw,CID_ScriptMNameBase+i));
1615 scripts[i] = _GGadgetGetTitle(GWidgetGetControl(gw,CID_ScriptMFileBase+i));
1616 if ( *names[i]=='\0' ) names[i] = NULL;
1617 if ( *scripts[i]=='\0' ) scripts[i] = NULL;
1618 if ( scripts[i]==NULL && names[i]!=NULL ) {
1619 ff_post_error(_("Menu name with no associated script"),_("Menu name with no associated script"));
1620 return( true );
1621 } else if ( scripts[i]!=NULL && names[i]==NULL ) {
1622 ff_post_error(_("Script with no associated menu name"),_("Script with no associated menu name"));
1623 return( true );
1624 }
1625 }
1626 for ( i=mi=0; i<SCRIPT_MENU_MAX; ++i ) {
1627 if ( names[i]!=NULL ) {
1628 names[mi] = names[i];
1629 scripts[mi] = scripts[i];
1630 ++mi;
1631 }
1632 }
1633 for ( j=0; visible_prefs_list[j].tab_name!=0; ++j ) for ( i=0; visible_prefs_list[j].pl[i].name!=NULL; ++i ) {
1634 pl = &visible_prefs_list[j].pl[i];
1635 /* before assigning values, check for any errors */
1636 /* if any errors, then NO values should be assigned, in case they cancel */
1637 if ( pl->dontdisplay )
1638 continue;
1639 if ( pl->type==pr_int ) {
1640 GetInt8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
1641 } else if ( pl->type==pr_real ) {
1642 GetReal8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
1643 } else if ( pl->type==pr_angle ) {
1644 dangle = GetReal8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
1645 if ( dangle > 90 || dangle < 0 ) {
1646 GGadgetProtest8(pl->name);
1647 err = true;
1648 }
1649 } else if ( pl->type==pr_unicode ) {
1650 GetUnicodeChar8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
1651 }
1652 }
1653 if ( err )
1654 return( true );
1655
1656 for ( j=0; visible_prefs_list[j].tab_name!=0; ++j ) for ( i=0; visible_prefs_list[j].pl[i].name!=NULL; ++i ) {
1657 pl = &visible_prefs_list[j].pl[i];
1658 if ( pl->dontdisplay )
1659 continue;
1660 switch( pl->type ) {
1661 case pr_int:
1662 *((int *) (pl->val)) = GetInt8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
1663 break;
1664 case pr_unicode:
1665 *((int *) (pl->val)) = GetUnicodeChar8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
1666 break;
1667 case pr_bool:
1668 *((int *) (pl->val)) = GGadgetIsChecked(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
1669 break;
1670 case pr_real:
1671 *((float *) (pl->val)) = GetReal8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
1672 break;
1673 case pr_encoding:
1674 { Encoding *e;
1675 e = ParseEncodingNameFromList(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
1676 if ( e!=NULL )
1677 *((Encoding **) (pl->val)) = e;
1678 }
1679 break;
1680 case pr_namelist:
1681 { NameList *nl;
1682 GTextInfo *ti = GGadgetGetListItemSelected(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
1683 if ( ti!=NULL ) {
1684 char *name = u2utf8_copy(ti->text);
1685 nl = NameListByName(name);
1686 free(name);
1687 if ( nl!=NULL && nl->uses_unicode && !allow_utf8_glyphnames)
1688 ff_post_error(_("Namelist contains non-ASCII names"),_("Glyph names should be limited to characters in the ASCII character set, but there are names in this namelist which use characters outside that range."));
1689 else if ( nl!=NULL )
1690 *((NameList **) (pl->val)) = nl;
1691 }
1692 }
1693 break;
1694 case pr_shaper:
1695 { GTextInfo *ti = GGadgetGetListItemSelected(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
1696 if ( ti!=NULL ) {
1697 char *name = ti->userdata;
1698 (pl->set)(name);
1699 }
1700 }
1701 break;
1702 case pr_string: case pr_file:
1703 ret = _GGadgetGetTitle(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
1704 if ( pl->val!=NULL ) {
1705 free( *((char **) (pl->val)) );
1706 *((char **) (pl->val)) = NULL;
1707 if ( ret!=NULL && *ret!='\0' )
1708 *((char **) (pl->val)) = /* u2def_*/ cu_copy(ret);
1709 } else {
1710 char *cret = cu_copy(ret);
1711 (pl->set)(cret);
1712 free(cret);
1713 }
1714 break;
1715 case pr_angle:
1716 *((float *) (pl->val)) = GetReal8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err)/RAD2DEG;
1717 break;
1718 }
1719 }
1720 for ( i=0; i<SCRIPT_MENU_MAX; ++i ) {
1721 free(script_menu_names[i]); script_menu_names[i] = NULL;
1722 free(script_filenames[i]); script_filenames[i] = NULL;
1723 }
1724 for ( i=0; i<mi; ++i ) {
1725 script_menu_names[i] = u_copy(names[i]);
1726 script_filenames[i] = u2def_copy(scripts[i]);
1727 }
1728
1729 list = GGadgetGetList(GWidgetGetControl(gw,CID_Mapping),&len);
1730 UserSettingsFree();
1731 user_macfeat_otftag = malloc((len+1)*sizeof(struct macsettingname));
1732 user_macfeat_otftag[len].otf_tag = 0;
1733
1734 for ( i=0; i<len; ++i ) {
1735 buf = u2utf8_copy(list[i]->text);
1736 str = Utf8ToMacStr(buf, 0, 0); // sm_roman/english
1737 ParseMacMapping(str,&user_macfeat_otftag[i]);
1738 free(str);
1739 free(buf);
1740 }
1741
1742 Prefs_ReplaceMacFeatures(GWidgetGetControl(gw,CID_Features));
1743
1744 if ( xuid!=NULL ) {
1745 char *pt;
1746 for ( pt=xuid; *pt==' ' ; ++pt );
1747 if ( *pt=='[' ) { /* People who know PS well, might want to put brackets around the xuid base array, but I don't want them */
1748 pt = copy(pt+1);
1749 if (xuid != NULL) free( xuid );
1750 xuid = pt;
1751 }
1752 for ( pt=xuid+strlen(xuid)-1; pt>xuid && *pt==' '; --pt );
1753 if ( pt >= xuid && *pt==']' ) *pt = '\0';
1754 }
1755
1756 p->done = true;
1757 PrefsUI_SavePrefs(true);
1758 if ( maxundoes==0 ) { FontView *fv;
1759 for ( fv=fv_list ; fv!=NULL; fv=(FontView *) (fv->b.next) )
1760 SFRemoveUndoes(fv->b.sf,NULL,NULL);
1761 }
1762 if ( othersubrsfile!=NULL && ReadOtherSubrsFile(othersubrsfile)<=0 )
1763 fprintf( stderr, "Failed to read OtherSubrs from %s\n", othersubrsfile );
1764
1765 int force_redraw_charviews = 0;
1766 if( prefs_oldval_cvEditHandleSize != prefs_cvEditHandleSize )
1767 force_redraw_charviews = 1;
1768 if( prefs_oldval_cvInactiveHandleAlpha != prefs_cvInactiveHandleAlpha )
1769 force_redraw_charviews = 1;
1770
1771
1772 if( force_redraw_charviews )
1773 {
1774 FontView *fv;
1775 for ( fv=fv_list ; fv!=NULL; fv=(FontView *) (fv->b.next) )
1776 {
1777 FVRedrawAllCharViews( fv );
1778 }
1779 }
1780 }
1781 return( true );
1782 }
1783
1784 static int Prefs_Cancel(GGadget *g, GEvent *e) {
1785 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1786 struct pref_data *p = GDrawGetUserData(GGadgetGetWindow(g));
1787 MacFeatListFree(GGadgetGetUserData((GWidgetGetControl(
1788 GGadgetGetWindow(g),CID_Features))));
1789 p->done = true;
1790 }
1791 return( true );
1792 }
1793
1794 static int e_h(GWindow gw, GEvent *event) {
1795 if ( event->type==et_close ) {
1796 struct pref_data *p = GDrawGetUserData(gw);
1797 p->done = true;
1798 if(GWidgetGetControl(gw,CID_Features)) {
1799 MacFeatListFree(GGadgetGetUserData((GWidgetGetControl(gw,CID_Features))));
1800 }
1801 } else if ( event->type==et_char ) {
1802 if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) {
1803 help("ui/dialogs/prefs.html", NULL);
1804 return( true );
1805 }
1806 return( false );
1807 }
1808 return( true );
1809 }
1810
1811 static void PrefsInit(void) {
1812 static int done = false;
1813 int i;
1814
1815 if ( done )
1816 return;
1817 done = true;
1818 for ( i=0; visible_prefs_list[i].tab_name!=NULL; ++i )
1819 visible_prefs_list[i].tab_name = _(visible_prefs_list[i].tab_name);
1820 }
1821
1822 void DoPrefs(void) {
1823 GRect pos;
1824 GWindow gw;
1825 GWindowAttrs wattrs;
1826 GGadgetCreateData *pgcd, gcd[5], sgcd[45], mgcd[3], mfgcd[9], msgcd[9];
1827 GGadgetCreateData mfboxes[3], *mfarray[14];
1828 GGadgetCreateData mpboxes[3], *mparray[14];
1829 GGadgetCreateData sboxes[2], *sarray[50];
1830 GGadgetCreateData mboxes[3], *varray[5], *harray[8];
1831 GTextInfo *plabel, **list, label[5], slabel[45], *plabels[TOPICS+5], mflabels[9], mslabels[9];
1832 GTabInfo aspects[TOPICS+5], subaspects[3];
1833 GGadgetCreateData **hvarray, boxes[2*TOPICS];
1834 struct pref_data p;
1835 int i, gc, sgc, j, k, line, line_max, y, y2, ii, si;
1836 int32_t llen;
1837 char buf[20];
1838 int gcnt[20];
1839 static unichar_t nullstr[] = { 0 };
1840 struct prefs_list *pl;
1841 char *tempstr;
1842
1843 PrefsInit();
1844
1845 MfArgsInit();
1846 for ( k=line_max=0; visible_prefs_list[k].tab_name!=0; ++k ) {
1847 for ( i=line=gcnt[k]=0; visible_prefs_list[k].pl[i].name!=NULL; ++i ) {
1848 if ( visible_prefs_list[k].pl[i].dontdisplay )
1849 continue;
1850 gcnt[k] += 2;
1851 if ( visible_prefs_list[k].pl[i].type==pr_bool ) ++gcnt[k];
1852 else if ( visible_prefs_list[k].pl[i].type==pr_file ) ++gcnt[k];
1853 else if ( visible_prefs_list[k].pl[i].type==pr_angle ) ++gcnt[k];
1854 ++line;
1855 }
1856 if ( visible_prefs_list[k].pl == args_list ) {
1857 gcnt[k] += 6;
1858 line += 6;
1859 }
1860 if ( line>line_max ) line_max = line;
1861 }
1862
1863 prefs_oldval_cvEditHandleSize = prefs_cvEditHandleSize;
1864 prefs_oldval_cvInactiveHandleAlpha = prefs_cvInactiveHandleAlpha;
1865
1866 memset(&p,'\0',sizeof(p));
1867 memset(&wattrs,0,sizeof(wattrs));
1868 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_restrict|wam_isdlg;
1869 wattrs.event_masks = ~(1<<et_charup);
1870 wattrs.restrict_input_to_me = 1;
1871 wattrs.is_dlg = 1;
1872 wattrs.undercursor = 1;
1873 wattrs.cursor = ct_pointer;
1874 wattrs.utf8_window_title = _("Preferences");
1875 pos.x = pos.y = 0;
1876 pos.width = GGadgetScale(GDrawPointsToPixels(NULL,350));
1877 pos.height = GDrawPointsToPixels(NULL,line_max*26+69);
1878 gw = GDrawCreateTopWindow(NULL,&pos,e_h,&p,&wattrs);
1879
1880 memset(sgcd,0,sizeof(sgcd));
1881 memset(slabel,0,sizeof(slabel));
1882 memset(&mfgcd,0,sizeof(mfgcd));
1883 memset(&msgcd,0,sizeof(msgcd));
1884 memset(&mflabels,0,sizeof(mflabels));
1885 memset(&mslabels,0,sizeof(mslabels));
1886 memset(&mfboxes,0,sizeof(mfboxes));
1887 memset(&mpboxes,0,sizeof(mpboxes));
1888 memset(&sboxes,0,sizeof(sboxes));
1889 memset(&boxes,0,sizeof(boxes));
1890
1891 GCDFillMacFeat(mfgcd,mflabels,250,default_mac_feature_map, true, mfboxes, mfarray);
1892
1893 sgc = 0;
1894
1895 msgcd[sgc].gd.pos.x = 6; msgcd[sgc].gd.pos.y = 6;
1896 msgcd[sgc].gd.pos.width = 250; msgcd[sgc].gd.pos.height = 16*12+10;
1897 msgcd[sgc].gd.flags = gg_visible | gg_enabled | gg_list_alphabetic | gg_list_multiplesel;
1898 msgcd[sgc].gd.cid = CID_Mapping;
1899 msgcd[sgc].gd.u.list = Pref_MappingList(true);
1900 msgcd[sgc].gd.handle_controlevent = Pref_MappingSel;
1901 msgcd[sgc++].creator = GListCreate;
1902 mparray[0] = &msgcd[sgc-1];
1903
1904 msgcd[sgc].gd.pos.x = 6; msgcd[sgc].gd.pos.y = msgcd[sgc-1].gd.pos.y+msgcd[sgc-1].gd.pos.height+10;
1905 msgcd[sgc].gd.flags = gg_visible | gg_enabled;
1906 mslabels[sgc].text = (unichar_t *) S_("MacMap|_New...");
1907 mslabels[sgc].text_is_1byte = true;
1908 mslabels[sgc].text_in_resource = true;
1909 msgcd[sgc].gd.label = &mslabels[sgc];
1910 msgcd[sgc].gd.handle_controlevent = Pref_NewMapping;
1911 msgcd[sgc++].creator = GButtonCreate;
1912 mparray[4] = GCD_Glue; mparray[5] = &msgcd[sgc-1];
1913
1914 msgcd[sgc].gd.pos.x = msgcd[sgc-1].gd.pos.x+10+GIntGetResource(_NUM_Buttonsize)*100/GIntGetResource(_NUM_ScaleFactor);
1915 msgcd[sgc].gd.pos.y = msgcd[sgc-1].gd.pos.y;
1916 msgcd[sgc].gd.flags = gg_visible ;
1917 mslabels[sgc].text = (unichar_t *) _("_Delete");
1918 mslabels[sgc].text_is_1byte = true;
1919 mslabels[sgc].text_in_resource = true;
1920 msgcd[sgc].gd.label = &mslabels[sgc];
1921 msgcd[sgc].gd.cid = CID_MappingDel;
1922 msgcd[sgc].gd.handle_controlevent = Pref_DelMapping;
1923 msgcd[sgc++].creator = GButtonCreate;
1924 mparray[5] = GCD_Glue; mparray[6] = &msgcd[sgc-1];
1925
1926 msgcd[sgc].gd.pos.x = msgcd[sgc-1].gd.pos.x+10+GIntGetResource(_NUM_Buttonsize)*100/GIntGetResource(_NUM_ScaleFactor);
1927 msgcd[sgc].gd.pos.y = msgcd[sgc-1].gd.pos.y;
1928 msgcd[sgc].gd.flags = gg_visible ;
1929 mslabels[sgc].text = (unichar_t *) _("_Edit...");
1930 mslabels[sgc].text_is_1byte = true;
1931 mslabels[sgc].text_in_resource = true;
1932 msgcd[sgc].gd.label = &mslabels[sgc];
1933 msgcd[sgc].gd.cid = CID_MappingEdit;
1934 msgcd[sgc].gd.handle_controlevent = Pref_EditMapping;
1935 msgcd[sgc++].creator = GButtonCreate;
1936 mparray[7] = GCD_Glue; mparray[8] = &msgcd[sgc-1];
1937
1938 msgcd[sgc].gd.pos.x = msgcd[sgc-1].gd.pos.x+10+GIntGetResource(_NUM_Buttonsize)*100/GIntGetResource(_NUM_ScaleFactor);
1939 msgcd[sgc].gd.pos.y = msgcd[sgc-1].gd.pos.y;
1940 msgcd[sgc].gd.flags = gg_visible | gg_enabled;
1941 mslabels[sgc].text = (unichar_t *) S_("MacMapping|Default");
1942 mslabels[sgc].text_is_1byte = true;
1943 mslabels[sgc].text_in_resource = true;
1944 msgcd[sgc].gd.label = &mslabels[sgc];
1945 msgcd[sgc].gd.handle_controlevent = Pref_DefaultMapping;
1946 msgcd[sgc++].creator = GButtonCreate;
1947 mparray[9] = GCD_Glue; mparray[10] = &msgcd[sgc-1];
1948 mparray[11] = GCD_Glue; mparray[12] = NULL;
1949
1950 mpboxes[2].gd.flags = gg_enabled|gg_visible;
1951 mpboxes[2].gd.u.boxelements = mparray+4;
1952 mpboxes[2].creator = GHBoxCreate;
1953 mparray[1] = GCD_Glue;
1954 mparray[2] = &mpboxes[2];
1955 mparray[3] = NULL;
1956
1957 mpboxes[0].gd.flags = gg_enabled|gg_visible;
1958 mpboxes[0].gd.u.boxelements = mparray;
1959 mpboxes[0].creator = GVBoxCreate;
1960
1961 sgc = 0;
1962 y2=5;
1963 si = 0;
1964
1965 slabel[sgc].text = (unichar_t *) _("Menu Name");
1966 slabel[sgc].text_is_1byte = true;
1967 sgcd[sgc].gd.label = &slabel[sgc];
1968 sgcd[sgc].gd.popup_msg = _("You may create a script menu containing up to 10 frequently used scripts.\nEach entry in the menu needs both a name to display in the menu and\na script file to execute. The menu name may contain any unicode characters.\nThe button labeled \"...\" will allow you to browse for a script file.");
1969 sgcd[sgc].gd.pos.x = 8;
1970 sgcd[sgc].gd.pos.y = y2;
1971 sgcd[sgc].gd.flags = gg_visible | gg_enabled;
1972 sgcd[sgc++].creator = GLabelCreate;
1973 sarray[si++] = &sgcd[sgc-1];
1974
1975 slabel[sgc].text = (unichar_t *) _("Script File");
1976 slabel[sgc].text_is_1byte = true;
1977 sgcd[sgc].gd.label = &slabel[sgc];
1978 sgcd[sgc].gd.popup_msg = _("You may create a script menu containing up to 10 frequently used scripts\nEach entry in the menu needs both a name to display in the menu and\na script file to execute. The menu name may contain any unicode characters.\nThe button labeled \"...\" will allow you to browse for a script file.");
1979 sgcd[sgc].gd.pos.x = 110;
1980 sgcd[sgc].gd.pos.y = y2;
1981 sgcd[sgc].gd.flags = gg_visible | gg_enabled;
1982 sgcd[sgc++].creator = GLabelCreate;
1983 sarray[si++] = &sgcd[sgc-1];
1984 sarray[si++] = GCD_Glue;
1985 sarray[si++] = NULL;
1986
1987 y2 += 14;
1988
1989 for ( i=0; i<SCRIPT_MENU_MAX; ++i ) {
1990 sgcd[sgc].gd.pos.x = 8; sgcd[sgc].gd.pos.y = y2;
1991 sgcd[sgc].gd.flags = gg_visible | gg_enabled | gg_text_xim;
1992 slabel[sgc].text = script_menu_names[i]==NULL?nullstr:script_menu_names[i];
1993 sgcd[sgc].gd.label = &slabel[sgc];
1994 sgcd[sgc].gd.cid = i+CID_ScriptMNameBase;
1995 sgcd[sgc++].creator = GTextFieldCreate;
1996 sarray[si++] = &sgcd[sgc-1];
1997
1998 sgcd[sgc].gd.pos.x = 110; sgcd[sgc].gd.pos.y = y2;
1999 sgcd[sgc].gd.flags = gg_visible | gg_enabled;
2000 slabel[sgc].text = (unichar_t *) (script_filenames[i]==NULL?"":script_filenames[i]);
2001 slabel[sgc].text_is_1byte = true;
2002 sgcd[sgc].gd.label = &slabel[sgc];
2003 sgcd[sgc].gd.cid = i+CID_ScriptMFileBase;
2004 sgcd[sgc++].creator = GTextFieldCreate;
2005 sarray[si++] = &sgcd[sgc-1];
2006
2007 sgcd[sgc].gd.pos.x = 210; sgcd[sgc].gd.pos.y = y2;
2008 sgcd[sgc].gd.flags = gg_visible | gg_enabled;
2009 slabel[sgc].text = (unichar_t *) _("...");
2010 slabel[sgc].text_is_1byte = true;
2011 sgcd[sgc].gd.label = &slabel[sgc];
2012 sgcd[sgc].gd.cid = i+CID_ScriptMBrowseBase;
2013 sgcd[sgc].gd.handle_controlevent = Prefs_ScriptBrowse;
2014 sgcd[sgc++].creator = GButtonCreate;
2015 sarray[si++] = &sgcd[sgc-1];
2016 sarray[si++] = NULL;
2017
2018 y2 += 26;
2019 }
2020 sarray[si++] = GCD_Glue; sarray[si++] = GCD_Glue; sarray[si++] = GCD_Glue;
2021 sarray[si++] = NULL;
2022 sarray[si++] = NULL;
2023
2024 sboxes[0].gd.flags = gg_enabled|gg_visible;
2025 sboxes[0].gd.u.boxelements = sarray;
2026 sboxes[0].creator = GHVBoxCreate;
2027
2028 memset(&mgcd,0,sizeof(mgcd));
2029 memset(&mgcd,0,sizeof(mgcd));
2030 memset(&subaspects,'\0',sizeof(subaspects));
2031 memset(&label,0,sizeof(label));
2032 memset(&gcd,0,sizeof(gcd));
2033 memset(&aspects,'\0',sizeof(aspects));
2034 aspects[0].selected = true;
2035
2036 for ( k=0; visible_prefs_list[k].tab_name!=0; ++k ) {
2037 pgcd = calloc(gcnt[k]+4,sizeof(GGadgetCreateData));
2038 plabel = calloc(gcnt[k]+4,sizeof(GTextInfo));
2039 hvarray = calloc((gcnt[k]+6)*5+2,sizeof(GGadgetCreateData *));
2040
2041 aspects[k].text = (unichar_t *) visible_prefs_list[k].tab_name;
2042 aspects[k].text_is_1byte = true;
2043 aspects[k].gcd = &boxes[2*k];
2044 aspects[k].nesting = visible_prefs_list[k].nest;
2045 plabels[k] = plabel;
2046
2047 gc = si = 0;
2048 for ( i=line=0, y=5; visible_prefs_list[k].pl[i].name!=NULL; ++i ) {
2049 pl = &visible_prefs_list[k].pl[i];
2050 if ( pl->dontdisplay )
2051 continue;
2052 plabel[gc].text = (unichar_t *) _(pl->name);
2053 plabel[gc].text_is_1byte = true;
2054 pgcd[gc].gd.label = &plabel[gc];
2055 pgcd[gc].gd.mnemonic = '\0';
2056 pgcd[gc].gd.popup_msg = _(pl->popup);
2057 pgcd[gc].gd.pos.x = 8;
2058 pgcd[gc].gd.pos.y = y + 6;
2059 pgcd[gc].gd.flags = gg_visible | gg_enabled;
2060 pgcd[gc++].creator = GLabelCreate;
2061 hvarray[si++] = &pgcd[gc-1];
2062
2063 plabel[gc].text_is_1byte = true;
2064 pgcd[gc].gd.label = &plabel[gc];
2065 pgcd[gc].gd.mnemonic = '\0';
2066 pgcd[gc].gd.popup_msg = _(pl->popup);
2067 pgcd[gc].gd.pos.x = 110;
2068 pgcd[gc].gd.pos.y = y;
2069 pgcd[gc].gd.flags = gg_visible | gg_enabled;
2070 pgcd[gc].data = pl;
2071 pgcd[gc].gd.cid = k*CID_PrefsOffset+CID_PrefsBase+i;
2072 switch ( pl->type ) {
2073 case pr_bool:
2074 plabel[gc].text = (unichar_t *) _("On");
2075 pgcd[gc].gd.pos.y += 3;
2076 pgcd[gc++].creator = GRadioCreate;
2077 hvarray[si++] = &pgcd[gc-1];
2078 pgcd[gc] = pgcd[gc-1];
2079 pgcd[gc].gd.pos.x += 50;
2080 pgcd[gc].gd.cid = 0;
2081 pgcd[gc].gd.label = &plabel[gc];
2082 plabel[gc].text = (unichar_t *) _("Off");
2083 plabel[gc].text_is_1byte = true;
2084 hvarray[si++] = &pgcd[gc];
2085 hvarray[si++] = GCD_Glue;
2086 if ( *((int *) pl->val))
2087 pgcd[gc-1].gd.flags |= gg_cb_on;
2088 else
2089 pgcd[gc].gd.flags |= gg_cb_on;
2090 ++gc;
2091 y += 22;
2092 break;
2093 case pr_int:
2094 sprintf(buf,"%d", *((int *) pl->val));
2095 plabel[gc].text = (unichar_t *) copy( buf );
2096 pgcd[gc++].creator = GTextFieldCreate;
2097 hvarray[si++] = &pgcd[gc-1];
2098 hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
2099 y += 26;
2100 break;
2101 case pr_unicode:
2102 /*sprintf(buf,"U+%04x", *((int *) pl->val));*/
2103 { char *pt; pt=buf; pt=utf8_idpb(pt,*((int *)pl->val),UTF8IDPB_NOZERO); *pt='\0'; }
2104 plabel[gc].text = (unichar_t *) copy( buf );
2105 pgcd[gc++].creator = GTextFieldCreate;
2106 hvarray[si++] = &pgcd[gc-1];
2107 hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
2108 y += 26;
2109 break;
2110 case pr_real:
2111 sprintf(buf,"%g", *((float *) pl->val));
2112 plabel[gc].text = (unichar_t *) copy( buf );
2113 pgcd[gc++].creator = GTextFieldCreate;
2114 hvarray[si++] = &pgcd[gc-1];
2115 hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
2116 y += 26;
2117 break;
2118 case pr_encoding:
2119 pgcd[gc].gd.u.list = GetEncodingTypes();
2120 pgcd[gc].gd.label = EncodingTypesFindEnc(pgcd[gc].gd.u.list,
2121 *(Encoding **) pl->val);
2122 for ( ii=0; pgcd[gc].gd.u.list[ii].text!=NULL ||pgcd[gc].gd.u.list[ii].line; ++ii )
2123 if ( pgcd[gc].gd.u.list[ii].userdata!=NULL &&
2124 (strcmp(pgcd[gc].gd.u.list[ii].userdata,"Compacted")==0 ||
2125 strcmp(pgcd[gc].gd.u.list[ii].userdata,"Original")==0 ))
2126 pgcd[gc].gd.u.list[ii].disabled = true;
2127 pgcd[gc].creator = GListFieldCreate;
2128 pgcd[gc].gd.pos.width = 160;
2129 if ( pgcd[gc].gd.label==NULL ) pgcd[gc].gd.label = &encodingtypes[0];
2130 ++gc;
2131 hvarray[si++] = &pgcd[gc-1];
2132 hvarray[si++] = GCD_ColSpan; hvarray[si++] = GCD_ColSpan;
2133 y += 28;
2134 break;
2135 case pr_namelist:
2136 { char **nlnames = AllNamelistNames();
2137 int cnt;
2138 GTextInfo *namelistnames;
2139 for ( cnt=0; nlnames[cnt]!=NULL; ++cnt);
2140 namelistnames = calloc(cnt+1,sizeof(GTextInfo));
2141 for ( cnt=0; nlnames[cnt]!=NULL; ++cnt) {
2142 namelistnames[cnt].text = (unichar_t *) nlnames[cnt];
2143 namelistnames[cnt].text_is_1byte = true;
2144 if ( strcmp(_((*(NameList **) (pl->val))->title),nlnames[cnt])==0 ) {
2145 namelistnames[cnt].selected = true;
2146 pgcd[gc].gd.label = &namelistnames[cnt];
2147 }
2148 }
2149 pgcd[gc].gd.u.list = namelistnames;
2150 pgcd[gc].creator = GListButtonCreate;
2151 pgcd[gc].gd.pos.width = 160;
2152 ++gc;
2153 hvarray[si++] = &pgcd[gc-1];
2154 hvarray[si++] = GCD_ColSpan; hvarray[si++] = GCD_ColSpan;
2155 y += 28;
2156 } break;
2157 case pr_shaper:
2158 {
2159 int default_idx = 0;
2160 pgcd[gc].gd.u.list = GetShaperList(&default_idx);
2161 pgcd[gc].gd.label = pgcd[gc].gd.u.list + default_idx;
2162 pgcd[gc].creator = GListFieldCreate;
2163 pgcd[gc].gd.pos.width = 160;
2164 ++gc;
2165 hvarray[si++] = &pgcd[gc-1];
2166 hvarray[si++] = GCD_ColSpan; hvarray[si++] = GCD_ColSpan;
2167 y += 28;
2168 }
2169 break;
2170 case pr_string: case pr_file:
2171 if ( pl->set==SetAutoTraceArgs || ((char **) pl->val)==&mf_args )
2172 pgcd[gc].gd.pos.width = 160;
2173 if ( pl->val!=NULL )
2174 tempstr = *((char **) (pl->val));
2175 else
2176 tempstr = (char *) ((pl->get)());
2177 if ( tempstr!=NULL )
2178 plabel[gc].text = /* def2u_*/ uc_copy( tempstr );
2179 else if ( ((char **) pl->val)==&BDFFoundry )
2180 plabel[gc].text = /* def2u_*/ uc_copy( "FontForge" );
2181 else
2182 plabel[gc].text = /* def2u_*/ uc_copy( "" );
2183 plabel[gc].text_is_1byte = false;
2184 pgcd[gc++].creator = GTextFieldCreate;
2185 hvarray[si++] = &pgcd[gc-1];
2186 if ( pl->type==pr_file ) {
2187 pgcd[gc] = pgcd[gc-1];
2188 pgcd[gc-1].gd.pos.width = 140;
2189 hvarray[si++] = GCD_ColSpan;
2190 pgcd[gc].gd.pos.x += 145;
2191 pgcd[gc].gd.cid += CID_PrefsBrowseOffset;
2192 pgcd[gc].gd.label = &plabel[gc];
2193 plabel[gc].text = (unichar_t *) "...";
2194 plabel[gc].text_is_1byte = true;
2195 pgcd[gc].gd.handle_controlevent = Prefs_BrowseFile;
2196 pgcd[gc++].creator = GButtonCreate;
2197 hvarray[si++] = &pgcd[gc-1];
2198 } else if ( pl->set==SetAutoTraceArgs || ((char **) pl->val)==&mf_args ) {
2199 hvarray[si++] = GCD_ColSpan;
2200 hvarray[si++] = GCD_Glue;
2201 } else {
2202 hvarray[si++] = GCD_Glue;
2203 hvarray[si++] = GCD_Glue;
2204 }
2205 y += 26;
2206 if ( pl->val==NULL )
2207 free(tempstr);
2208 break;
2209 case pr_angle:
2210 sprintf(buf,"%g", *((float *) pl->val) * RAD2DEG);
2211 plabel[gc].text = (unichar_t *) copy( buf );
2212 pgcd[gc++].creator = GTextFieldCreate;
2213 hvarray[si++] = &pgcd[gc-1];
2214 plabel[gc].text = (unichar_t *) U_("°");
2215 plabel[gc].text_is_1byte = true;
2216 pgcd[gc].gd.label = &plabel[gc];
2217 pgcd[gc].gd.pos.x = pgcd[gc-1].gd.pos.x+gcd[gc-1].gd.pos.width+2; pgcd[gc].gd.pos.y = pgcd[gc-1].gd.pos.y;
2218 pgcd[gc].gd.flags = gg_enabled|gg_visible;
2219 pgcd[gc++].creator = GLabelCreate;
2220 hvarray[si++] = &pgcd[gc-1];
2221 hvarray[si++] = GCD_Glue;
2222 y += 26;
2223 break;
2224 }
2225 ++line;
2226 hvarray[si++] = NULL;
2227 }
2228 if ( visible_prefs_list[k].pl == args_list ) {
2229 static char *text[] = {
2230 /* GT: See the long comment at "Property|New" */
2231 /* GT: This and the next few strings show a limitation of my widget set which */
2232 /* GT: cannot handle multi-line text labels. These strings should be concatenated */
2233 /* GT: (after striping off "Prefs_App|") together, translated, and then broken up */
2234 /* GT: to fit the dialog. There is an extra blank line, not used in English, */
2235 /* GT: into which your text may extend if needed. */
2236 N_("Prefs_App|Normally FontForge will find applications by searching for"),
2237 N_("Prefs_App|them in your PATH environment variable, if you want"),
2238 N_("Prefs_App|to alter that behavior you may set an environment"),
2239 N_("Prefs_App|variable giving the full path spec of the application."),
2240 N_("Prefs_App|FontForge recognizes BROWSER, MF and AUTOTRACE."),
2241 N_("Prefs_App| "), /* A blank line */
2242 NULL };
2243 y += 8;
2244 for ( i=0; text[i]!=0; ++i ) {
2245 plabel[gc].text = (unichar_t *) S_(text[i]);
2246 plabel[gc].text_is_1byte = true;
2247 pgcd[gc].gd.label = &plabel[gc];
2248 pgcd[gc].gd.pos.x = 8;
2249 pgcd[gc].gd.pos.y = y;
2250 pgcd[gc].gd.flags = gg_visible | gg_enabled;
2251 pgcd[gc++].creator = GLabelCreate;
2252 hvarray[si++] = &pgcd[gc-1];
2253 hvarray[si++] = GCD_ColSpan; hvarray[si++] = GCD_ColSpan;
2254 hvarray[si++] = NULL;
2255 y += 12;
2256 }
2257 }
2258 if ( y>y2 ) y2 = y;
2259 hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
2260 hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
2261 hvarray[si++] = NULL;
2262 hvarray[si++] = NULL;
2263 boxes[2*k].gd.flags = gg_enabled|gg_visible;
2264 boxes[2*k].gd.u.boxelements = hvarray;
2265 boxes[2*k].creator = GHVBoxCreate;
2266 }
2267
2268 aspects[k].text = (unichar_t *) _("Script Menu");
2269 aspects[k].text_is_1byte = true;
2270 aspects[k++].gcd = sboxes;
2271
2272 subaspects[0].text = (unichar_t *) _("Features");
2273 subaspects[0].text_is_1byte = true;
2274 subaspects[0].gcd = mfboxes;
2275
2276 subaspects[1].text = (unichar_t *) _("Mapping");
2277 subaspects[1].text_is_1byte = true;
2278 subaspects[1].gcd = mpboxes;
2279
2280 mgcd[0].gd.pos.x = 4; gcd[0].gd.pos.y = 6;
2281 mgcd[0].gd.pos.width = GDrawPixelsToPoints(NULL,pos.width)-20;
2282 mgcd[0].gd.pos.height = y2;
2283 mgcd[0].gd.u.tabs = subaspects;
2284 mgcd[0].gd.flags = gg_visible | gg_enabled;
2285 mgcd[0].creator = GTabSetCreate;
2286
2287 aspects[k].text = (unichar_t *) _("Mac");
2288 aspects[k].text_is_1byte = true;
2289 aspects[k++].gcd = mgcd;
2290
2291 gc = 0;
2292
2293 gcd[gc].gd.pos.x = gcd[gc].gd.pos.y = 2;
2294 gcd[gc].gd.pos.width = pos.width-4; gcd[gc].gd.pos.height = pos.height-2;
2295 gcd[gc].gd.flags = gg_enabled | gg_visible | gg_pos_in_pixels;
2296 gcd[gc++].creator = GGroupCreate;
2297
2298 gcd[gc].gd.pos.x = 4; gcd[gc].gd.pos.y = 6;
2299 gcd[gc].gd.pos.width = GDrawPixelsToPoints(NULL,pos.width)-8;
2300 gcd[gc].gd.pos.height = y2+20+18+4;
2301 gcd[gc].gd.u.tabs = aspects;
2302 gcd[gc].gd.flags = gg_visible | gg_enabled | gg_tabset_vert;
2303 gcd[gc++].creator = GTabSetCreate;
2304 varray[0] = &gcd[gc-1]; varray[1] = NULL;
2305
2306 y = gcd[gc-1].gd.pos.y+gcd[gc-1].gd.pos.height;
2307
2308 gcd[gc].gd.pos.x = 30-3; gcd[gc].gd.pos.y = y+5-3;
2309 gcd[gc].gd.pos.width = -1; gcd[gc].gd.pos.height = 0;
2310 gcd[gc].gd.flags = gg_visible | gg_enabled | gg_but_default;
2311 label[gc].text = (unichar_t *) _("_OK");
2312 label[gc].text_is_1byte = true;
2313 label[gc].text_in_resource = true;
2314 gcd[gc].gd.mnemonic = 'O';
2315 gcd[gc].gd.label = &label[gc];
2316 gcd[gc].gd.handle_controlevent = Prefs_Ok;
2317 gcd[gc++].creator = GButtonCreate;
2318 harray[0] = GCD_Glue; harray[1] = &gcd[gc-1]; harray[2] = GCD_Glue; harray[3] = GCD_Glue;
2319
2320 gcd[gc].gd.pos.x = -30; gcd[gc].gd.pos.y = gcd[gc-1].gd.pos.y+3;
2321 gcd[gc].gd.pos.width = -1; gcd[gc].gd.pos.height = 0;
2322 gcd[gc].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
2323 label[gc].text = (unichar_t *) _("_Cancel");
2324 label[gc].text_is_1byte = true;
2325 label[gc].text_in_resource = true;
2326 gcd[gc].gd.label = &label[gc];
2327 gcd[gc].gd.mnemonic = 'C';
2328 gcd[gc].gd.handle_controlevent = Prefs_Cancel;
2329 gcd[gc++].creator = GButtonCreate;
2330 harray[4] = GCD_Glue; harray[5] = &gcd[gc-1]; harray[6] = GCD_Glue; harray[7] = NULL;
2331
2332 memset(mboxes,0,sizeof(mboxes));
2333 mboxes[2].gd.flags = gg_enabled|gg_visible;
2334 mboxes[2].gd.u.boxelements = harray;
2335 mboxes[2].creator = GHBoxCreate;
2336 varray[2] = &mboxes[2];
2337 varray[3] = NULL;
2338 varray[4] = NULL;
2339
2340 mboxes[0].gd.pos.x = mboxes[0].gd.pos.y = 2;
2341 mboxes[0].gd.flags = gg_enabled|gg_visible;
2342 mboxes[0].gd.u.boxelements = varray;
2343 mboxes[0].creator = GHVGroupCreate;
2344
2345 y = GDrawPointsToPixels(NULL,y+37);
2346 gcd[0].gd.pos.height = y-4;
2347
2348 GGadgetsCreate(gw,mboxes);
2349 GTextInfoListFree(mfgcd[0].gd.u.list);
2350 GTextInfoListFree(msgcd[0].gd.u.list);
2351
2352 GHVBoxSetExpandableRow(mboxes[0].ret,0);
2353 GHVBoxSetExpandableCol(mboxes[2].ret,gb_expandgluesame);
2354 GHVBoxSetExpandableRow(mfboxes[0].ret,0);
2355 GHVBoxSetExpandableCol(mfboxes[2].ret,gb_expandgluesame);
2356 GHVBoxSetExpandableRow(mpboxes[0].ret,0);
2357 GHVBoxSetExpandableCol(mpboxes[2].ret,gb_expandgluesame);
2358 GHVBoxSetExpandableRow(sboxes[0].ret,gb_expandglue);
2359 for ( k=0; k<TOPICS; ++k )
2360 GHVBoxSetExpandableRow(boxes[2*k].ret,gb_expandglue);
2361
2362 GGadgetSetFont(mfgcd[0].ret,prefs_monofont.fi);
2363 GGadgetSetFont(msgcd[0].ret,prefs_monofont.fi);
2364 GHVBoxFitWindow(mboxes[0].ret);
2365
2366 for ( k=0; visible_prefs_list[k].tab_name!=0; ++k ) for ( gc=0,i=0; visible_prefs_list[k].pl[i].name!=NULL; ++i ) {
2367 GGadgetCreateData *gcd = aspects[k].gcd[0].gd.u.boxelements[0];
2368 pl = &visible_prefs_list[k].pl[i];
2369 if ( pl->dontdisplay )
2370 continue;
2371 switch ( pl->type ) {
2372 case pr_bool:
2373 ++gc;
2374 break;
2375 case pr_encoding: {
2376 GGadget *g = gcd[gc+1].ret;
2377 list = GGadgetGetList(g,&llen);
2378 for ( j=0; j<llen ; ++j ) {
2379 if ( list[j]->text!=NULL &&
2380 (void *) (intptr_t) ( *((int *) pl->val)) == list[j]->userdata )
2381 list[j]->selected = true;
2382 else
2383 list[j]->selected = false;
2384 }
2385 if ( gcd[gc+1].gd.u.list!=encodingtypes )
2386 GTextInfoListFree(gcd[gc+1].gd.u.list);
2387 } break;
2388 case pr_namelist:
2389 free(gcd[gc+1].gd.u.list);
2390 break;
2391 case pr_string: case pr_file: case pr_int: case pr_real: case pr_unicode: case pr_angle: case pr_shaper:
2392 free(plabels[k][gc+1].text);
2393 if ( pl->type==pr_file || pl->type==pr_angle )
2394 ++gc;
2395 break;
2396 }
2397 gc += 2;
2398 }
2399
2400 for ( k=0; visible_prefs_list[k].tab_name!=0; ++k ) {
2401 free(aspects[k].gcd->gd.u.boxelements[0]);
2402 free(aspects[k].gcd->gd.u.boxelements);
2403 free(plabels[k]);
2404 }
2405
2406 GDrawSetVisible(gw,true);
2407 while ( !p.done )
2408 GDrawProcessOneEvent(NULL);
2409 GDrawDestroyWindow(gw);
2410 }
2411
2412 void RecentFilesRemember(char *filename) {
2413 int i,j;
2414
2415 for ( i=0; i<RECENT_MAX && RecentFiles[i]!=NULL; ++i )
2416 if ( strcmp(RecentFiles[i],filename)==0 )
2417 break;
2418
2419 if ( i<RECENT_MAX && RecentFiles[i]!=NULL ) {
2420 if ( i!=0 ) {
2421 filename = RecentFiles[i];
2422 for ( j=i; j>0; --j )
2423 RecentFiles[j] = RecentFiles[j-1];
2424 RecentFiles[0] = filename;
2425 }
2426 } else {
2427 if ( RecentFiles[RECENT_MAX-1]!=NULL )
2428 free( RecentFiles[RECENT_MAX-1]);
2429 for ( i=RECENT_MAX-1; i>0; --i )
2430 RecentFiles[i] = RecentFiles[i-1];
2431 RecentFiles[0] = copy(filename);
2432 }
2433
2434 PrefsUI_SavePrefs(true);
2435 }
2436
2437 void LastFonts_Save(void) {
2438 FontView *fv, *next;
2439 char buffer[1024];
2440 char *ffdir = getFontForgeUserDir(Config);
2441 FILE *preserve = NULL;
2442
2443 if ( ffdir ) {
2444 sprintf(buffer, "%s/FontsOpenAtLastQuit", ffdir);
2445 preserve = fopen(buffer,"w");
2446 free(ffdir);
2447 }
2448
2449 for ( fv = fv_list; fv!=NULL; fv = next ) {
2450 next = (FontView *) (fv->b.next);
2451 if ( preserve ) {
2452 SplineFont *sf = fv->b.cidmaster?fv->b.cidmaster:fv->b.sf;
2453 fprintf(preserve, "%s\n", sf->filename?sf->filename:sf->origname);
2454 }
2455 }
2456
2457 if ( preserve )
2458 fclose(preserve);
2459 }
2460
2461 struct prefs_interface gdraw_prefs_interface = {
2462 PrefsUI_SavePrefs,
2463 PrefsUI_LoadPrefs,
2464 PrefsUI_GetPrefs,
2465 PrefsUI_SetPrefs,
2466 PrefsUI_getFontForgeShareDir,
2467 PrefsUI_SetDefaults
2468 };
2469
2470 static void change_res_filename(const char *newname) {
2471 free(xdefs_filename);
2472 xdefs_filename = copy( newname );
2473 SavePrefs(true);
2474 }
2475
2476 void DoXRes(void) {
2477 extern GResInfo view_ri;
2478
2479 MVColInit();
2480 CVColInit();
2481 BVColInit();
2482 GResEdit(&view_ri,xdefs_filename,change_res_filename);
2483
2484 // Trigger GTK StyleProvider update
2485 update_appearance();
2486 }
2487
2488 struct prefs_list pointer_dialog_list[] = {
2489 { N_("ArrowMoveSize"), pr_real, &arrowAmount, NULL, NULL, '\0', NULL, 0, N_("The number of em-units by which an arrow key will move a selected point") },
2490 { N_("ArrowAccelFactor"), pr_real, &arrowAccelFactor, NULL, NULL, '\0', NULL, 0, N_("Holding down the Shift key will speed up arrow key motion by this factor") },
2491 { N_("InterpolateCPsOnMotion"), pr_bool, &interpCPsOnMotion, NULL, NULL, '\0', NULL, 0, N_("When moving one end point of a spline but not the other\ninterpolate the control points between the two.") },
2492 PREFS_LIST_EMPTY
2493 };
2494
2495 struct prefs_list ruler_dialog_list[] = {
2496 { N_("SnapDistanceMeasureTool"), pr_real, &snapdistancemeasuretool, NULL, NULL, '\0', NULL, 0, N_("When the measure tool is active and when the mouse pointer is within this many pixels\nof one of the various interesting features (baseline,\nwidth, grid splines, etc.) the pointer will snap\nto that feature.") },
2497 { N_("MeasureToolShowHorizontalVertical"), pr_bool, &measuretoolshowhorizontolvertical, NULL, NULL, '\0', NULL, 0, N_("Have the measure tool show horizontal and vertical distances on the canvas.") },
2498 PREFS_LIST_EMPTY
2499 };
2500
2501 static int PrefsSubSet_Ok(GGadget *g, GEvent *e) {
2502 GWindow gw = GGadgetGetWindow(g);
2503 struct pref_data *p = GDrawGetUserData(GGadgetGetWindow(g));
2504 struct prefs_list* plist = p->plist;
2505 struct prefs_list* pl = plist;
2506 int i=0,j=0;
2507 int err=0;
2508 const unichar_t *ret;
2509
2510 p->done = true;
2511
2512 for ( i=0, pl=plist; pl->name; ++i, ++pl ) {
2513 switch( pl->type ) {
2514 case pr_int:
2515 *((int *) (pl->val)) = GetInt8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
2516 break;
2517 case pr_unicode:
2518 *((int *) (pl->val)) = GetUnicodeChar8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
2519 break;
2520 case pr_bool:
2521 *((int *) (pl->val)) = GGadgetIsChecked(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
2522 break;
2523 case pr_real:
2524 *((float *) (pl->val)) = GetReal8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
2525 break;
2526 case pr_encoding:
2527 { Encoding *e;
2528 e = ParseEncodingNameFromList(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
2529 if ( e!=NULL )
2530 *((Encoding **) (pl->val)) = e;
2531 }
2532 break;
2533 case pr_namelist:
2534 { NameList *nl;
2535 GTextInfo *ti = GGadgetGetListItemSelected(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
2536 if ( ti!=NULL ) {
2537 char *name = u2utf8_copy(ti->text);
2538 nl = NameListByName(name);
2539 free(name);
2540 if ( nl!=NULL && nl->uses_unicode && !allow_utf8_glyphnames)
2541 ff_post_error(_("Namelist contains non-ASCII names"),_("Glyph names should be limited to characters in the ASCII character set, but there are names in this namelist which use characters outside that range."));
2542 else if ( nl!=NULL )
2543 *((NameList **) (pl->val)) = nl;
2544 }
2545 }
2546 break;
2547 case pr_string: case pr_file:
2548 ret = _GGadgetGetTitle(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
2549 if ( pl->val!=NULL ) {
2550 free( *((char **) (pl->val)) );
2551 *((char **) (pl->val)) = NULL;
2552 if ( ret!=NULL && *ret!='\0' )
2553 *((char **) (pl->val)) = /* u2def_*/ cu_copy(ret);
2554 } else {
2555 char *cret = cu_copy(ret);
2556 (pl->set)(cret);
2557 free(cret);
2558 }
2559 break;
2560 case pr_angle:
2561 *((float *) (pl->val)) = GetReal8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err)/RAD2DEG;
2562 break;
2563 case pr_shaper:
2564 ff_post_error(_("Preferences"),
2565 _("Shaper preference is not implemented in contextual preferences"));
2566 break;
2567 }
2568 }
2569
2570 return( true );
2571 }
2572
2573 static void PrefsSubSetDlg(CharView *cv,char* windowTitle,struct prefs_list* plist) {
2574 struct prefs_list* pl = plist;
2575 GRect pos;
2576 GWindow gw;
2577 GWindowAttrs wattrs;
2578 GGadgetCreateData *pgcd, gcd[20], sgcd[45], mgcd[3], mfgcd[9], msgcd[9];
2579 GGadgetCreateData mfboxes[3], *mfarray[14];
2580 GGadgetCreateData mpboxes[3];
2581 GGadgetCreateData sboxes[2];
2582 GGadgetCreateData mboxes[3], mboxes2[5], *varray[5], *harray[8];
2583 GTextInfo *plabel, label[20], slabel[45], mflabels[9], mslabels[9];
2584 GTabInfo aspects[TOPICS+5], subaspects[3];
2585 GGadgetCreateData **hvarray, boxes[2*TOPICS];
2586 struct pref_data p;
2587 int line_max = 3;
2588 int i = 0, gc = 0, ii, y=0, si=0, k=0;
2589 char buf[20];
2590 char *tempstr;
2591
2592 PrefsInit();
2593 MfArgsInit();
2594
2595 line_max=0;
2596 for ( i=0, pl=plist; pl->name; ++i, ++pl ) {
2597 ++line_max;
2598 }
2599
2600 int itemCount = 100;
2601 pgcd = calloc(itemCount,sizeof(GGadgetCreateData));
2602 plabel = calloc(itemCount,sizeof(GTextInfo));
2603 hvarray = calloc((itemCount)*5,sizeof(GGadgetCreateData *));
2604 memset(&p,'\0',sizeof(p));
2605 memset(&wattrs,0,sizeof(wattrs));
2606 memset(sgcd,0,sizeof(sgcd));
2607 memset(slabel,0,sizeof(slabel));
2608 memset(&mfgcd,0,sizeof(mfgcd));
2609 memset(&msgcd,0,sizeof(msgcd));
2610 memset(&mflabels,0,sizeof(mflabels));
2611 memset(&mslabels,0,sizeof(mslabels));
2612 memset(&mfboxes,0,sizeof(mfboxes));
2613 memset(&mpboxes,0,sizeof(mpboxes));
2614 memset(&sboxes,0,sizeof(sboxes));
2615 memset(&boxes,0,sizeof(boxes));
2616 memset(&mgcd,0,sizeof(mgcd));
2617 memset(&mgcd,0,sizeof(mgcd));
2618 memset(&subaspects,'\0',sizeof(subaspects));
2619 memset(&label,0,sizeof(label));
2620 memset(&gcd,0,sizeof(gcd));
2621 memset(&aspects,'\0',sizeof(aspects));
2622 GCDFillMacFeat(mfgcd,mflabels,250,default_mac_feature_map, true, mfboxes, mfarray);
2623
2624 p.plist = plist;
2625 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_restrict|wam_isdlg;
2626 wattrs.event_masks = ~(1<<et_charup);
2627 wattrs.restrict_input_to_me = 1;
2628 wattrs.is_dlg = 1;
2629 wattrs.undercursor = 1;
2630 wattrs.cursor = ct_pointer;
2631 wattrs.utf8_window_title = windowTitle;
2632 pos.x = pos.y = 0;
2633 pos.width = GGadgetScale(GDrawPointsToPixels(NULL,340));
2634 pos.height = GDrawPointsToPixels(NULL,line_max*26+25);
2635 gw = GDrawCreateTopWindow(NULL,&pos,e_h,&p,&wattrs);
2636
2637
2638
2639 for ( i=0, pl=plist; pl->name; ++i, ++pl ) {
2640
2641 plabel[gc].text = (unichar_t *) _(pl->name);
2642 plabel[gc].text_is_1byte = true;
2643 pgcd[gc].gd.label = &plabel[gc];
2644 pgcd[gc].gd.mnemonic = '\0';
2645 pgcd[gc].gd.popup_msg = 0;//_(pl->popup);
2646 pgcd[gc].gd.pos.x = 8;
2647 pgcd[gc].gd.pos.y = y + 6;
2648 pgcd[gc].gd.flags = gg_visible | gg_enabled;
2649 pgcd[gc++].creator = GLabelCreate;
2650 hvarray[si++] = &pgcd[gc-1];
2651
2652 plabel[gc].text_is_1byte = true;
2653 pgcd[gc].gd.label = &plabel[gc];
2654 pgcd[gc].gd.mnemonic = '\0';
2655 pgcd[gc].gd.popup_msg = 0;//_(pl->popup);
2656 pgcd[gc].gd.pos.x = 110;
2657 pgcd[gc].gd.pos.y = y;
2658 pgcd[gc].gd.flags = gg_visible | gg_enabled;
2659 pgcd[gc].data = pl;
2660 pgcd[gc].gd.cid = k*CID_PrefsOffset+CID_PrefsBase+i;
2661 switch ( pl->type ) {
2662 case pr_bool:
2663 plabel[gc].text = (unichar_t *) _("On");
2664 pgcd[gc].gd.pos.y += 3;
2665 pgcd[gc++].creator = GRadioCreate;
2666 hvarray[si++] = &pgcd[gc-1];
2667 pgcd[gc] = pgcd[gc-1];
2668 pgcd[gc].gd.pos.x += 50;
2669 pgcd[gc].gd.cid = 0;
2670 pgcd[gc].gd.label = &plabel[gc];
2671 plabel[gc].text = (unichar_t *) _("Off");
2672 plabel[gc].text_is_1byte = true;
2673 hvarray[si++] = &pgcd[gc];
2674 hvarray[si++] = GCD_Glue;
2675 if ( *((int *) pl->val))
2676 pgcd[gc-1].gd.flags |= gg_cb_on;
2677 else
2678 pgcd[gc].gd.flags |= gg_cb_on;
2679 ++gc;
2680 y += 22;
2681 break;
2682 case pr_int:
2683 sprintf(buf,"%d", *((int *) pl->val));
2684 plabel[gc].text = (unichar_t *) copy( buf );
2685 pgcd[gc++].creator = GTextFieldCreate;
2686 hvarray[si++] = &pgcd[gc-1];
2687 hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
2688 y += 26;
2689 break;
2690 case pr_unicode:
2691 /*sprintf(buf,"U+%04x", *((int *) pl->val));*/
2692 { char *pt; pt=buf; pt=utf8_idpb(pt,*((int *)pl->val),UTF8IDPB_NOZERO); *pt='\0'; }
2693 plabel[gc].text = (unichar_t *) copy( buf );
2694 pgcd[gc++].creator = GTextFieldCreate;
2695 hvarray[si++] = &pgcd[gc-1];
2696 hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
2697 y += 26;
2698 break;
2699 case pr_real:
2700 sprintf(buf,"%g", *((float *) pl->val));
2701 plabel[gc].text = (unichar_t *) copy( buf );
2702 pgcd[gc++].creator = GTextFieldCreate;
2703 hvarray[si++] = &pgcd[gc-1];
2704 hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
2705 y += 26;
2706 break;
2707 case pr_encoding:
2708 pgcd[gc].gd.u.list = GetEncodingTypes();
2709 pgcd[gc].gd.label = EncodingTypesFindEnc(pgcd[gc].gd.u.list,
2710 *(Encoding **) pl->val);
2711 for ( ii=0; pgcd[gc].gd.u.list[ii].text!=NULL ||pgcd[gc].gd.u.list[ii].line; ++ii )
2712 if ( pgcd[gc].gd.u.list[ii].userdata!=NULL &&
2713 (strcmp(pgcd[gc].gd.u.list[ii].userdata,"Compacted")==0 ||
2714 strcmp(pgcd[gc].gd.u.list[ii].userdata,"Original")==0 ))
2715 pgcd[gc].gd.u.list[ii].disabled = true;
2716 pgcd[gc].creator = GListFieldCreate;
2717 pgcd[gc].gd.pos.width = 160;
2718 if ( pgcd[gc].gd.label==NULL ) pgcd[gc].gd.label = &encodingtypes[0];
2719 ++gc;
2720 hvarray[si++] = &pgcd[gc-1];
2721 hvarray[si++] = GCD_ColSpan; hvarray[si++] = GCD_ColSpan;
2722 y += 28;
2723 break;
2724 case pr_namelist:
2725 { char **nlnames = AllNamelistNames();
2726 int cnt;
2727 GTextInfo *namelistnames;
2728 for ( cnt=0; nlnames[cnt]!=NULL; ++cnt);
2729 namelistnames = calloc(cnt+1,sizeof(GTextInfo));
2730 for ( cnt=0; nlnames[cnt]!=NULL; ++cnt) {
2731 namelistnames[cnt].text = (unichar_t *) nlnames[cnt];
2732 namelistnames[cnt].text_is_1byte = true;
2733 if ( strcmp(_((*(NameList **) (pl->val))->title),nlnames[cnt])==0 ) {
2734 namelistnames[cnt].selected = true;
2735 pgcd[gc].gd.label = &namelistnames[cnt];
2736 }
2737 }
2738 pgcd[gc].gd.u.list = namelistnames;
2739 pgcd[gc].creator = GListButtonCreate;
2740 pgcd[gc].gd.pos.width = 160;
2741 ++gc;
2742 hvarray[si++] = &pgcd[gc-1];
2743 hvarray[si++] = GCD_ColSpan; hvarray[si++] = GCD_ColSpan;
2744 y += 28;
2745 } break;
2746 case pr_string: case pr_file:
2747 if ( pl->set==SetAutoTraceArgs || ((char **) pl->val)==&mf_args )
2748 pgcd[gc].gd.pos.width = 160;
2749 if ( pl->val!=NULL )
2750 tempstr = *((char **) (pl->val));
2751 else
2752 tempstr = (char *) ((pl->get)());
2753 if ( tempstr!=NULL )
2754 plabel[gc].text = /* def2u_*/ uc_copy( tempstr );
2755 else if ( ((char **) pl->val)==&BDFFoundry )
2756 plabel[gc].text = /* def2u_*/ uc_copy( "FontForge" );
2757 else
2758 plabel[gc].text = /* def2u_*/ uc_copy( "" );
2759 plabel[gc].text_is_1byte = false;
2760 pgcd[gc++].creator = GTextFieldCreate;
2761 hvarray[si++] = &pgcd[gc-1];
2762 if ( pl->type==pr_file ) {
2763 pgcd[gc] = pgcd[gc-1];
2764 pgcd[gc-1].gd.pos.width = 140;
2765 hvarray[si++] = GCD_ColSpan;
2766 pgcd[gc].gd.pos.x += 145;
2767 pgcd[gc].gd.cid += CID_PrefsBrowseOffset;
2768 pgcd[gc].gd.label = &plabel[gc];
2769 plabel[gc].text = (unichar_t *) "...";
2770 plabel[gc].text_is_1byte = true;
2771 pgcd[gc].gd.handle_controlevent = Prefs_BrowseFile;
2772 pgcd[gc++].creator = GButtonCreate;
2773 hvarray[si++] = &pgcd[gc-1];
2774 } else if ( pl->set==SetAutoTraceArgs || ((char **) pl->val)==&mf_args ) {
2775 hvarray[si++] = GCD_ColSpan;
2776 hvarray[si++] = GCD_Glue;
2777 } else {
2778 hvarray[si++] = GCD_Glue;
2779 hvarray[si++] = GCD_Glue;
2780 }
2781 y += 26;
2782 if ( pl->val==NULL )
2783 free(tempstr);
2784 break;
2785 case pr_angle:
2786 sprintf(buf,"%g", *((float *) pl->val) * RAD2DEG);
2787 plabel[gc].text = (unichar_t *) copy( buf );
2788 pgcd[gc++].creator = GTextFieldCreate;
2789 hvarray[si++] = &pgcd[gc-1];
2790 plabel[gc].text = (unichar_t *) U_("°");
2791 plabel[gc].text_is_1byte = true;
2792 pgcd[gc].gd.label = &plabel[gc];
2793 pgcd[gc].gd.pos.x = pgcd[gc-1].gd.pos.x+gcd[gc-1].gd.pos.width+2; pgcd[gc].gd.pos.y = pgcd[gc-1].gd.pos.y;
2794 pgcd[gc].gd.flags = gg_enabled|gg_visible;
2795 pgcd[gc++].creator = GLabelCreate;
2796 hvarray[si++] = &pgcd[gc-1];
2797 hvarray[si++] = GCD_Glue;
2798 y += 26;
2799 break;
2800 case pr_shaper:
2801 ff_post_error(_("Preferences"),
2802 _("Shaper preference is not implemented in contextual preferences"));
2803 break;
2804 }
2805 hvarray[si++] = NULL;
2806
2807 }
2808
2809 harray[4] = 0;
2810 harray[5] = 0;
2811 harray[6] = 0;
2812 harray[7] = 0;
2813
2814 gcd[gc].gd.pos.x = 30-3;
2815 gcd[gc].gd.pos.y = y+5-3;
2816 gcd[gc].gd.pos.width = -1;
2817 gcd[gc].gd.pos.height = 0;
2818 gcd[gc].gd.flags = gg_visible | gg_enabled | gg_but_default;
2819 label[gc].text = (unichar_t *) _("_OK");
2820 label[gc].text_is_1byte = true;
2821 label[gc].text_in_resource = true;
2822 gcd[gc].gd.mnemonic = 'O';
2823 gcd[gc].gd.label = &label[gc];
2824 gcd[gc].gd.handle_controlevent = PrefsSubSet_Ok;
2825 gcd[gc++].creator = GButtonCreate;
2826 harray[0] = GCD_Glue; harray[1] = &gcd[gc-1]; harray[2] = GCD_Glue; harray[3] = GCD_Glue;
2827
2828
2829 memset(mboxes,0,sizeof(mboxes));
2830 memset(mboxes2,0,sizeof(mboxes2));
2831
2832 mboxes[2].gd.pos.x = 2;
2833 mboxes[2].gd.pos.y = 20;
2834 mboxes[2].gd.flags = gg_enabled|gg_visible;
2835 mboxes[2].gd.u.boxelements = harray;
2836 mboxes[2].creator = GHBoxCreate;
2837
2838 mboxes[0].gd.pos.x = mboxes[0].gd.pos.y = 2;
2839 mboxes[0].gd.flags = gg_enabled|gg_visible;
2840 mboxes[0].gd.u.boxelements = hvarray;
2841 mboxes[0].creator = GHVGroupCreate;
2842
2843 varray[0] = &mboxes[0];
2844 varray[1] = &mboxes[2];
2845 varray[2] = 0;
2846 varray[3] = 0;
2847 varray[4] = 0;
2848
2849 /* varray[0] = &mboxes[2]; */
2850 /* varray[1] = 0;//&mboxes[2]; */
2851 /* varray[2] = 0; */
2852 /* varray[3] = 0; */
2853 /* varray[4] = 0; */
2854
2855 mboxes2[0].gd.pos.x = 4;
2856 mboxes2[0].gd.pos.y = 4;
2857 mboxes2[0].gd.flags = gg_enabled|gg_visible;
2858 mboxes2[0].gd.u.boxelements = varray;
2859 mboxes2[0].creator = GVBoxCreate;
2860
2861 GGadgetsCreate(gw,mboxes2);
2862
2863
2864 GDrawSetVisible(gw,true);
2865 while ( !p.done )
2866 GDrawProcessOneEvent(NULL);
2867 GDrawDestroyWindow(gw);
2868 }
2869
2870
2871 void PointerDlg(CharView *cv) {
2872 PrefsSubSetDlg( cv, _("Arrow Options"), pointer_dialog_list );
2873 }
2874
2875 void RulerDlg(CharView *cv) {
2876 PrefsSubSetDlg( cv, _("Ruler Options"), ruler_dialog_list );
2877 }
2878