1 /* Copyright (C) 2000-2008 by George Williams */
2 /*
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are met:
5 
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer.
8 
9  * Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12 
13  * The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15 
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 #include "pfaedit.h"
28 #include "plugins.h"
29 #include <charset.h>
30 #include <gfile.h>
31 #include <ustring.h>
32 
33 #include <sys/types.h>
34 #include <dirent.h>
35 #include <locale.h>
36 #include <time.h>
37 #include <sys/time.h>
38 #include <stdlib.h>
39 
40 #include "ttf.h"
41 
42 #if HAVE_LANGINFO_H
43 # include <langinfo.h>
44 #endif
45 
46 static char *othersubrsfile = NULL;
47 
48 extern int adjustwidth;
49 extern int adjustlbearing;
50 extern Encoding *default_encoding;
51 extern int autohint_before_rasterize;
52 extern int autohint_before_generate;
53 extern int accent_offset;
54 extern int GraveAcuteCenterBottom;
55 extern int PreferSpacingAccents;
56 extern int CharCenterHighest;
57 extern int recognizePUA;
58 extern int snaptoint;
59 extern float joinsnap;
60 extern char *BDFFoundry;
61 extern char *TTFFoundry;
62 extern char *xuid;
63 extern char *SaveTablesPref;
64 extern int maxundoes;			/* in cvundoes */
65 extern int prefer_cjk_encodings;	/* in parsettf */
66 extern int onlycopydisplayed, copymetadata, copyttfinstr;
67 extern int oldformatstate;		/* in savefontdlg.c */
68 extern int oldbitmapstate;		/* in savefontdlg.c */
69 extern int old_ttf_flags;		/* in savefontdlg.c */
70 extern int old_ps_flags;		/* in savefontdlg.c */
71 extern int old_otf_flags;		/* in savefontdlg.c */
72 extern int preferpotrace;		/* in autotrace.c */
73 extern int autotrace_ask;		/* in autotrace.c */
74 extern int mf_ask;			/* in autotrace.c */
75 extern int mf_clearbackgrounds;		/* in autotrace.c */
76 extern int mf_showerrors;		/* in autotrace.c */
77 extern char *mf_args;			/* in autotrace.c */
78 extern int coverageformatsallowed;	/* in tottfgpos.c */
79 extern int hint_diagonal_ends;		/* in stemdb.c */
80 extern int hint_diagonal_intersections;	/* in stemdb.c */
81 extern int hint_bounding_boxes;		/* in stemdb.c */
82 extern int detect_diagonal_stems;	/* in stemdb.c */
83 extern int new_em_size;				/* in splineutil2.c */
84 extern int new_fonts_are_order2;		/* in splineutil2.c */
85 extern int loaded_fonts_same_as_new;		/* in splineutil2.c */
86 extern int use_second_indic_scripts;		/* in tottfgpos.c */
87 extern int allow_utf8_glyphnames;		/* in charinfo.c */
88 extern int ask_user_for_cmap;			/* in parsettf.c */
89 extern NameList *force_names_when_opening;
90 extern NameList *force_names_when_saving;
91 extern NameList *namelist_for_new_fonts;
92 extern int default_fv_row_count;		/* in splineutil2.c */
93 extern int default_fv_col_count;		/* in splineutil2.c */
94 extern int use_freetype_to_rasterize_fv;	/* in bitmapchar.c */
95 
96 /* UI preferences which we don't use, but will preserve to so we can read/write */
97 /*  UI preference files without loss of data */
98 static char *xdefs_filename;
99 static char *helpdir=NULL;				/* in uiutil.c */
100 static int splash=1;
101 static int cv_auto_goto=1;
102 static int OpenCharsInNewWindow=1;
103 static float arrowAmount=1;
104 static float arrowAccelFactor=10;
105 static float snapdistance=3.5;
106 static int stop_at_join=0;
107 static int updateflex=0;				/* in charview.c */
108 static int ask_user_for_resolution=1;
109 static int default_fv_showhmetrics=0;	/* in fontview */
110 static int default_fv_showvmetrics=0;	/* in fontview */
111 static int default_fv_glyphlabel=0;	/* in fontview */
112 static int save_to_dir=0;			/* in fontview, use sfdir rather than sfd */
113 static int palettes_docked=1;		/* in cvpalettes */
114 static int cvvisible[2]={1,1}, bvvisible[3]={1,1,1};	/* in cvpalettes.c */
115 static int infowindowdistance=10;		/* in cvruler.c */
116 static int loacal_markextrema, loacal_markpoi, loacal_showrulers,
117     loacal_showcpinfo, loacal_showsidebearings, loacal_showpoints,
118     loacal_showfilled, loacal_showtabs, loacal_showrefnames;
119 static int oldsystem=100;
120 static char *oflib_username;
121 static char *oflib_password;
122 static int rectelipse=0, polystar=0, regular_star=0;	/* from cvpalettes.c */
123 static int center_out[2]={0,0};			/* from cvpalettes.c */
124 static float rr_radius=0;				/* from cvpalettes.c */
125 static int ps_pointcnt=5;				/* from cvpalettes.c */
126 static float star_percent=100;			/* from cvpalettes.c */
127 static int debug_wins=0;			/* in cvdebug.c */
128 static int gridfit_dpi=100, gridfit_depth=1;	/* in cvgridfit.c */
129 static float gridfit_pointsizex=12;		/* in cvgridfit.c */
130 static float gridfit_pointsizey=12;		/* in cvgridfit.c */
131 static int  gridfit_x_sameas_y=true;		/* in cvgridfit.c */
132 static int default_font_filter_index=0;
133 static int ItalicConstrained = true;
134 extern int clear_tt_instructions_when_needed;	/* cvundoes.c */
135 static int default_cv_width;			/* in charview.c */
136 static int default_cv_height;			/* in charview.c */
137 static int mv_width;				/* in metricsview.c */
138 static int mv_height;				/* in metricsview.c */
139 static int bv_width;				/* in bitmapview.c */
140 static int bv_height;				/* in bitmapview.c */
141 static int mvshowgrid;				/* in metricsview.c */
142 static int old_validate = true;
143 static int old_fontlog = false;
144 static int home_char = 'A';
145 static int compact_font_on_open=0;
146 static int oflib_automagic_preview;		/* from oflib.c */
147 static int aa_pixelsize;			/* from anchorsaway.c */
148 
149 static int gfc_showhidden, gfc_dirplace;
150 static char *gfc_bookmarks=NULL;
151 static char *pixmapdir=NULL;
152 
153 enum pref_types { pr_int, pr_real, pr_bool, pr_enum, pr_encoding, pr_string,
154 	pr_file, pr_namelist, pr_unicode };
155 
156 int unused = 0;
157 char *unused_string = NULL;
158 
159 static struct prefs_list {
160     char *name;
161     	/* In the prefs file the untranslated name will always be used, but */
162 	/* in the UI that name may be translated. */
163     enum pref_types type;
164     void *val;
165     void *(*get)(void);
166     void (*set)(void *);
167     char mn;
168     struct enums *enums;
169     unsigned int dontdisplay: 1;
170     char *popup;
171 } core_list[] = {
172 	{ 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.") },
173 	{ N_("AutoHint"), pr_bool, &unused, NULL, NULL, 'A', NULL, 0, N_("AutoHint before rasterizing") },
174 	{ N_("NewCharset"), pr_encoding, &default_encoding, NULL, NULL, 'N', NULL, 0, N_("Default encoding for\nnew fonts") },
175 	{ 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.") },
176 	{ 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).") },
177 	{ N_("FreeTypeInFontView"), pr_bool, &unused, 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.") },
178 	{ 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).") },
179 	{ 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.") },
180 	{ 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.") },
181 	{ 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.") },
182 	{ 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.") },
183 	{ 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.") },
184 	{ 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") },
185 	{ 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).") },
186 	{ N_("UndoDepth"), pr_int, &maxundoes, NULL, NULL, '\0', NULL, 0, N_("The maximum number of Undoes/Redoes stored in a glyph") },
187 	{ 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.") },
188 	{ 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.") },
189 	{ 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 disasterous 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!") },
190 	{ N_("CopyTTFInstrs"), pr_bool, &copyttfinstr, NULL, NULL, '\0', NULL, 0, N_("When copying glyphs from the font view, also copy the\nglyphs' metadata (name, encoding, comment, etc).") },
191 	{ 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") },
192 	{ 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.") },
193 	{ 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?") },
194 	{ 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.") },
195 	{ N_("PreferPotrace"), pr_bool, &unused, 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.") },
196 	{ N_("AutotraceArgs"), pr_string, &unused_string, NULL, NULL, '\0', NULL, 0, N_("Extra arguments for configuring the autotrace program\n(either autotrace or potrace)") },
197 	{ N_("AutotraceAsk"), pr_bool, &unused, NULL, NULL, '\0', NULL, 0, N_("Ask the user for autotrace arguments each time autotrace is invoked") },
198 	{ N_("MfArgs"), pr_string, &unused_string, NULL, NULL, '\0', NULL, 0, N_("Commands to pass to mf (metafont) program, the filename will follow these") },
199 	{ N_("MfAsk"), pr_bool, &unused, NULL, NULL, '\0', NULL, 0, N_("Ask the user for mf commands each time mf is invoked") },
200 	{ N_("MfClearBg"), pr_bool, &unused, 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") },
201 	{ N_("MfShowErr"), pr_bool, &unused, 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.") },
202 	{ N_("FoundryName"), pr_string, &unused_string, NULL, NULL, 'F', NULL, 0, N_("Name used for foundry field in bdf\nfont generation") },
203 	{ 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") },
204 	{ 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.") },
205 	{ 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.") },
206 	{ 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." ) },
207 	{ N_("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.") },
208 	{ 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.") },
209 	{ N_("HintForGen"), pr_bool, &autohint_before_generate, NULL, NULL, 'H', NULL, 0, N_("AutoHint changed glyphs before generating a font") },
210 	{ 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.") },
211 	{ 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.") },
212 	{ 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.") },
213 	{ 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.") },
214 	{ 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).") },
215 	{ "AntiAlias", pr_bool, &default_fv_antialias, NULL, NULL, '\0', NULL, 1, NULL },
216 	{ "DefaultFVSize", pr_int, &default_fv_font_size, NULL, NULL, 'S', NULL, 1, NULL },
217 	{ "DefaultFVRowCount", pr_int, &default_fv_row_count, NULL, NULL, 'S', NULL, 1, NULL },
218 	{ "DefaultFVColCount", pr_int, &default_fv_col_count, NULL, NULL, 'S', NULL, 1, NULL },
219 	{ "OnlyCopyDisplayed", pr_bool, &onlycopydisplayed, NULL, NULL, '\0', NULL, 1, NULL },
220 	{ "DefaultOutputFormat", pr_int, &unused, NULL, NULL, '\0', NULL, 1, NULL },
221 	{ "DefaultBitmapFormat", pr_int, &unused, NULL, NULL, '\0', NULL, 1, NULL },
222 	{ "SaveValidate", pr_int, &old_validate, NULL, NULL, '\0', NULL, 1, NULL },
223 	{ "SaveFontLogAsk", pr_int, &old_fontlog, NULL, NULL, '\0', NULL, 1, NULL },
224 	{ "DefaultTTFflags", pr_int, &unused, NULL, NULL, '\0', NULL, 1, NULL },
225 	{ "DefaultPSflags", pr_int, &unused, NULL, NULL, '\0', NULL, 1, NULL },
226 	{ "DefaultOTFflags", pr_int, &unused, NULL, NULL, '\0', NULL, 1, NULL },
227 	{ "PageWidth", pr_int, &unused, NULL, NULL, '\0', NULL, 1, NULL },
228 	{ "PageHeight", pr_int, &unused, NULL, NULL, '\0', NULL, 1, NULL },
229 	{ "PrintType", pr_int, &unused, NULL, NULL, '\0', NULL, 1, NULL },
230 	{ "PrintCommand", pr_string, &unused_string, NULL, NULL, '\0', NULL, 1, NULL },
231 	{ "PageLazyPrinter", pr_string, &unused_string, NULL, NULL, '\0', NULL, 1, NULL },
232 	{ "CoverageFormatsAllowed", pr_int, &coverageformatsallowed, NULL, NULL, '\0', NULL, 1, NULL },
233 	{ "ForceNamesWhenOpening", pr_namelist, &force_names_when_opening, NULL, NULL, '\0', NULL, 1, NULL },
234 	{ "ForceNamesWhenSaving", pr_namelist, &force_names_when_saving, NULL, NULL, '\0', NULL, 1, NULL },
235 	{ NULL, 0, NULL, NULL, NULL, 0, NULL, 0, NULL },
236 },
237    extras[] = {
238 	{ N_("ResourceFile"), pr_file, &xdefs_filename, NULL, NULL, 'R', NULL, 0, N_("When FontForge starts up, it loads display related resources from a\nproperty on the screen. Sometimes it is useful to be able to store\nthese resources in a file. These resources are only read at start\nup, so changing this has no effect until the next time you start\nFontForge.") },
239 	{ N_("HelpDir"), pr_file, &helpdir, NULL, NULL, 'H', NULL, 0, N_("The directory on your local system in which FontForge will search for help\nfiles.  If a file is not found there, then FontForge will look for it on the net.") },
240 	{ N_("SplashScreen"), pr_bool, &splash, NULL, NULL, 'S', NULL, 0, N_("Show splash screen on start-up") },
241 	{ 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") },
242 	{ 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.") },
243 	{ 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") },
244 	{ N_("ArrowAccelFactor"), pr_real, &arrowAccelFactor, NULL, NULL, '\0', NULL, 0, N_("Holding down the Alt (or Meta) key will speed up arrow key motion by this factor") },
245 	{ 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.") },
246 	{ 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.") },
247 	{ N_("UpdateFlex"), pr_bool, &updateflex, NULL, NULL, '\0', NULL, 0, N_("Figure out flex hints after every change") },
248 	{ 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.") },
249 	{ "DefaultFVShowHmetrics", pr_int, &default_fv_showhmetrics, NULL, NULL, '\0', NULL, 1, NULL  },
250 	{ "DefaultFVShowVmetrics", pr_int, &default_fv_showvmetrics, NULL, NULL, '\0', NULL, 1, NULL  },
251 	{ "DefaultFVGlyphLabel", pr_int, &default_fv_glyphlabel, NULL, NULL, 'S', NULL, 1, NULL  },
252 	{ "SaveToDir", pr_int, &save_to_dir, NULL, NULL, 'S', NULL, 1, NULL  },
253 	{ "PalettesDocked", pr_bool, &palettes_docked, NULL, NULL, '\0', NULL, 1, NULL  },
254 	{ "CVVisible0", pr_bool, &cvvisible[0], NULL, NULL, '\0', NULL, 1, NULL  },
255 	{ "CVVisible1", pr_bool, &cvvisible[1], NULL, NULL, '\0', NULL, 1, NULL  },
256 	{ "BVVisible0", pr_bool, &bvvisible[0], NULL, NULL, '\0', NULL, 1, NULL  },
257 	{ "BVVisible1", pr_bool, &bvvisible[1], NULL, NULL, '\0', NULL, 1, NULL  },
258 	{ "BVVisible2", pr_bool, &bvvisible[2], NULL, NULL, '\0', NULL, 1, NULL  },
259 	{ "InfoWindowDistance", pr_int, &infowindowdistance, NULL, NULL, '\0', NULL, 1, NULL  },
260 	{ "MarkExtrema", pr_int, &loacal_markextrema, NULL, NULL, '\0', NULL, 1, NULL  },
261 	{ "MarkPointsOfInflect", pr_int, &loacal_markpoi, NULL, NULL, '\0', NULL, 1, NULL  },
262 	{ "ShowRulers", pr_bool, &loacal_showrulers, NULL, NULL, '\0', NULL, 1, N_("Display rulers in the Outline Glyph View") },
263 	{ "ShowCPInfo", pr_int, &loacal_showcpinfo, NULL, NULL, '\0', NULL, 1, NULL  },
264 	{ "ShowSideBearings", pr_int, &loacal_showsidebearings, NULL, NULL, '\0', NULL, 1, NULL  },
265 	{ "ShowRefNames", pr_int, &loacal_showrefnames, NULL, NULL, '\0', NULL, 1, NULL  },
266 	{ "ShowPoints", pr_bool, &loacal_showpoints, NULL, NULL, '\0', NULL, 1, NULL  },
267 	{ "ShowFilled", pr_int, &loacal_showfilled, NULL, NULL, '\0', NULL, 1, NULL  },
268 	{ "ShowTabs", pr_int, &loacal_showtabs, NULL, NULL, '\0', NULL, 1, NULL  },
269 	{ "DefaultScreenDpiSystem", pr_int, &oldsystem, NULL, NULL, '\0', NULL, 1, NULL  },
270 	{ "OFLibUsername", pr_string, &oflib_username, NULL, NULL, '\0', NULL, 1, NULL  },
271 	{ "OFLibPassword", pr_string, &oflib_password, NULL, NULL, '\0', NULL, 1, NULL  },
272 	{ "RegularStar", pr_bool, &regular_star, NULL, NULL, '\0', NULL, 1, NULL  },
273 	{ "PolyStar", pr_bool, &polystar, NULL, NULL, '\0', NULL, 1, NULL  },
274 	{ "RectEllipse", pr_bool, &rectelipse, NULL, NULL, '\0', NULL, 1, NULL  },
275 	{ "RectCenterOut", pr_bool, &center_out[0], NULL, NULL, '\0', NULL, 1, NULL  },
276 	{ "EllipseCenterOut", pr_bool, &center_out[1], NULL, NULL, '\0', NULL, 1, NULL  },
277 	{ "PolyStartPointCnt", pr_int, &ps_pointcnt, NULL, NULL, '\0', NULL, 1, NULL  },
278 	{ "RoundRectRadius", pr_real, &rr_radius, NULL, NULL, '\0', NULL, 1, NULL  },
279 	{ "StarPercent", pr_real, &star_percent, NULL, NULL, '\0', NULL, 1, NULL  },
280 	{ "DebugWins", pr_int, &debug_wins, NULL, NULL, '\0', NULL, 1, NULL  },
281 	{ "GridFitDpi", pr_int, &gridfit_dpi, NULL, NULL, '\0', NULL, 1, NULL  },
282 	{ "GridFitDepth", pr_int, &gridfit_depth, NULL, NULL, '\0', NULL, 1, NULL  },
283 	{ "GridFitPointSize", pr_real, &gridfit_pointsizey, NULL, NULL, '\0', NULL, 1, NULL  },
284 	{ "GridFitPointSizeX", pr_real, &gridfit_pointsizex, NULL, NULL, '\0', NULL, 1, NULL  },
285 	{ "GridFitSameAs", pr_int, &gridfit_x_sameas_y, NULL, NULL, '\0', NULL, 1, NULL  },
286 	{ "MVShowGrid", pr_int, &mvshowgrid, NULL, NULL, '\0', NULL, 1, NULL  },
287 	{ "DefaultFontFilterIndex", pr_int, &default_font_filter_index, NULL, NULL, '\0', NULL, 1, NULL  },
288 	{ "SeekChar", pr_unicode, &home_char, NULL, NULL, '\0', NULL, 1, NULL  },
289 	{ "CompactOnOpen", pr_bool, &compact_font_on_open, NULL, NULL, '\0', NULL, 1, NULL  },
290 	{ "PixmapDir", pr_file, &pixmapdir, NULL, NULL, 'R', NULL, 0, NULL },
291 	{ "DefaultCVWidth", pr_int, &default_cv_width, NULL, NULL, '\0', NULL, 1, NULL  },
292 	{ "DefaultCVHeight", pr_int, &default_cv_height, NULL, NULL, '\0', NULL, 1, NULL  },
293 	{ "FCShowHidden", pr_bool, &gfc_showhidden, NULL, NULL, '\0', NULL, 1, NULL  },
294 	{ "FCDirPlacement", pr_int, &gfc_dirplace, NULL, NULL, '\0', NULL, 1, NULL  },
295 	{ "FCBookmarks", pr_string, &gfc_bookmarks, NULL, NULL, '\0', NULL, 1, NULL  },
296 	{ "OFLibAutomagicPreview", pr_int, &oflib_automagic_preview, NULL, NULL, '\0', NULL, 1, NULL  },
297 	{ "DefaultMVWidth", pr_int, &mv_width, NULL, NULL, '\0', NULL, 1, NULL  },
298 	{ "DefaultMVHeight", pr_int, &mv_height, NULL, NULL, '\0', NULL, 1, NULL  },
299 	{ "DefaultBVWidth", pr_int, &bv_width, NULL, NULL, '\0', NULL, 1, NULL  },
300 	{ "DefaultBVHeight", pr_int, &bv_height, NULL, NULL, '\0', NULL, 1, NULL  },
301 	{ "AnchorControlPixelSize", pr_int, &aa_pixelsize, NULL, NULL, '\0', NULL, 1, NULL  },
302 	{ NULL, 0, NULL, NULL, NULL, 0, NULL, 0, NULL },
303 },
304  *prefs_list[] = { core_list, extras, NULL };
305 
NOUI_GetPrefs(char * name,Val * val)306 static int NOUI_GetPrefs(char *name,Val *val) {
307     int i,j;
308 
309     for ( i=0; prefs_list[i]!=NULL; ++i ) for ( j=0; prefs_list[i][j].name!=NULL; ++j ) {
310 	if ( strcmp(prefs_list[i][j].name,name)==0 ) {
311 	    struct prefs_list *pf = &prefs_list[i][j];
312 	    if ( pf->type == pr_bool || pf->type == pr_int || pf->type == pr_unicode ) {
313 		val->type = v_int;
314 		val->u.ival = *((int *) (pf->val));
315 	    } else if ( pf->type == pr_string || pf->type == pr_file ) {
316 		val->type = v_str;
317 		val->u.sval = copy( *((char **) (pf->val)));
318 	    } else if ( pf->type == pr_encoding ) {
319 		val->type = v_str;
320 		if ( *((NameList **) (pf->val))==NULL )
321 		    val->u.sval = copy( "NULL" );
322 		else
323 		    val->u.sval = copy( (*((Encoding **) (pf->val)))->enc_name );
324 	    } else if ( pf->type == pr_namelist ) {
325 		val->type = v_str;
326 		val->u.sval = copy( (*((NameList **) (pf->val)))->title );
327 	    } else if ( pf->type == pr_real ) {
328 		val->type = v_real;
329 		val->u.fval = *((float *) (pf->val));
330 	    } else
331 return( false );
332 
333 return( true );
334 	}
335     }
336 return( false );
337 }
338 
NOUI_SetPrefs(char * name,Val * val1,Val * val2)339 static int NOUI_SetPrefs(char *name,Val *val1, Val *val2) {
340     int i,j;
341 
342     for ( i=0; prefs_list[i]!=NULL; ++i ) for ( j=0; prefs_list[i][j].name!=NULL; ++j ) {
343 	if ( strcmp(prefs_list[i][j].name,name)==0 ) {
344 	    struct prefs_list *pf = &prefs_list[i][j];
345 	    if ( pf->type == pr_bool || pf->type == pr_int || pf->type == pr_unicode ) {
346 		if ( (val1->type!=v_int && val1->type!=v_unicode) || val2!=NULL )
347 return( -1 );
348 		*((int *) (pf->val)) = val1->u.ival;
349 	    } else if ( pf->type == pr_real ) {
350 		if ( val1->type==v_real && val2==NULL )
351 		    *((float *) (pf->val)) = val1->u.fval;
352 		else if ( val1->type!=v_int || (val2!=NULL && val2->type!=v_int ))
353 return( -1 );
354 		else
355 		    *((float *) (pf->val)) = (val2==NULL ? val1->u.ival : val1->u.ival / (double) val2->u.ival);
356 	    } else if ( pf->type == pr_string || pf->type == pr_file ) {
357 		if ( val1->type!=v_str || val2!=NULL )
358 return( -1 );
359 		if ( pf->set ) {
360 		    pf->set( val1->u.sval );
361 		} else {
362 		    free( *((char **) (pf->val)));
363 		    *((char **) (pf->val)) = copy( val1->u.sval );
364 		}
365 	    } else if ( pf->type == pr_encoding ) {
366 		if ( val2!=NULL )
367 return( -1 );
368 		else if ( val1->type==v_str && pf->val == &default_encoding) {
369 		    Encoding *enc = FindOrMakeEncoding(val1->u.sval);
370 		    if ( enc==NULL )
371 return( -1 );
372 		    *((Encoding **) (pf->val)) = enc;
373 		} else
374 return( -1 );
375 	    } else if ( pf->type == pr_namelist ) {
376 		if ( val2!=NULL )
377 return( -1 );
378 		else if ( val1->type==v_str ) {
379 		    NameList *nl = NameListByName(val1->u.sval);
380 		    if ( strcmp(val1->u.sval,"NULL")==0 && pf->val != &namelist_for_new_fonts )
381 			nl = NULL;
382 		    else if ( nl==NULL )
383 return( -1 );
384 		    *((NameList **) (pf->val)) = nl;
385 		} else
386 return( -1 );
387 	    } else
388 return( false );
389 
390 	    SavePrefs(true);
391 return( true );
392 	}
393     }
394 return( false );
395 }
396 
NOUI_getFontForgeShareDir(void)397 static char *NOUI_getFontForgeShareDir(void) {
398 #if defined(SHAREDIR)
399 return( SHAREDIR "/fontforge" );
400 #elif defined(PREFIX)
401 return( PREFIX "/share/fontforge" );
402 #else
403 return( NULL );
404 #endif
405 }
406 
DefaultXUID(void)407 static void DefaultXUID(void) {
408     /* Adobe has assigned PfaEdit a base XUID of 1021. Each new user is going */
409     /*  to get a couple of random numbers appended to that, hoping that will */
410     /*  make for a fairly safe system. */
411     /* FontForge will use the same scheme */
412     int r1, r2;
413     char buffer[50];
414     struct timeval tv;
415 
416     gettimeofday(&tv,NULL);
417     srand(tv.tv_usec);
418     do {
419 	r1 = rand()&0x3ff;
420     } while ( r1==0 );		/* I reserve "0" for me! */
421     gettimeofday(&tv,NULL);
422     r2 = rand();
423     sprintf( buffer, "1021 %d %d", r1, r2 );
424     free(xuid);
425     xuid = copy(buffer);
426 }
427 
NOUI_SetDefaults(void)428 static void NOUI_SetDefaults(void) {
429     DefaultXUID();
430 }
431 
NOUI_LoadPrefs(void)432 static void NOUI_LoadPrefs(void) {
433 }
434 
NOUI_SavePrefs(int not_if_script)435 static void NOUI_SavePrefs(int not_if_script) {
436   (void)not_if_script;
437 }
438 
439 static struct prefs_interface prefsnoui = {
440     NOUI_SavePrefs,
441     NOUI_LoadPrefs,
442     NOUI_GetPrefs,
443     NOUI_SetPrefs,
444     NOUI_getFontForgeShareDir,
445     NOUI_SetDefaults
446 };
447 
448 struct prefs_interface *prefs_interface = &prefsnoui;
449 
FF_SetPrefsInterface(struct prefs_interface * prefsi)450 void FF_SetPrefsInterface(struct prefs_interface *prefsi) {
451     prefs_interface = prefsi;
452 }
453