LCOV - code coverage report
Current view: top level - fontforgeexe - prefs.c (source / functions) Hit Total Coverage
Test: FontForge coverage report 2017-08-04 01:21:11+02:00 (commit d35f7e4107a9e1db65cce47c468fcc914cecb8fd) Lines: 137 1728 7.9 %
Date: 2017-08-04 Functions: 14 46 30.4 %

          Line data    Source code
       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             : #include "autotrace.h"
      29             : #include "encoding.h"
      30             : #include "fontforgeui.h"
      31             : #include "groups.h"
      32             : #include "macenc.h"
      33             : #include "namelist.h"
      34             : #include "othersubrs.h"
      35             : #include "plugins.h"
      36             : #include "sfd.h"
      37             : #include "splineutil.h"
      38             : #include <charset.h>
      39             : #include <gfile.h>
      40             : #include <gresource.h>
      41             : #include <gresedit.h>
      42             : #include <ustring.h>
      43             : #include <gkeysym.h>
      44             : 
      45             : #include <sys/types.h>
      46             : #include <dirent.h>
      47             : #include <locale.h>
      48             : #include <time.h>
      49             : #include <sys/time.h>
      50             : #include <stdlib.h>
      51             : 
      52             : #include "ttf.h"
      53             : 
      54             : #if HAVE_LANGINFO_H
      55             : # include <langinfo.h>
      56             : #endif
      57             : 
      58             : #define GTimer GTimer_GTK
      59             : #include <glib.h>
      60             : #undef GTimer
      61             : 
      62             : #include "collabclient.h"
      63             : 
      64             : #define RAD2DEG (180/3.1415926535897932)
      65             : 
      66             : static void change_res_filename(const char *newname);
      67             : 
      68             : #include "gutils/prefs.h"
      69             : 
      70             : extern int splash;
      71             : extern int adjustwidth;
      72             : extern int adjustlbearing;
      73             : extern Encoding *default_encoding;
      74             : extern int autohint_before_generate;
      75             : extern int use_freetype_to_rasterize_fv;
      76             : extern int use_freetype_with_aa_fill_cv;
      77             : extern int OpenCharsInNewWindow;
      78             : extern int ItalicConstrained;
      79             : extern int accent_offset;
      80             : extern int GraveAcuteCenterBottom;
      81             : extern int PreferSpacingAccents;
      82             : extern int CharCenterHighest;
      83             : extern int ask_user_for_resolution;
      84             : extern int stop_at_join;
      85             : extern int recognizePUA;
      86             : extern float arrowAmount;
      87             : extern float arrowAccelFactor;
      88             : extern float snapdistance;
      89             : extern float snapdistancemeasuretool;
      90             : extern int measuretoolshowhorizontolvertical;
      91             : extern int xorrubberlines;
      92             : extern int snaptoint;
      93             : extern float joinsnap;
      94             : extern char *BDFFoundry;
      95             : extern char *TTFFoundry;
      96             : extern char *xuid;
      97             : extern char *SaveTablesPref;
      98             : /*struct cvshows CVShows = { 1, 1, 1, 1, 1, 0, 1 };*/ /* in charview */
      99             : /* int default_fv_font_size = 24; */    /* in fontview */
     100             : /* int default_fv_antialias = false */  /* in fontview */
     101             : /* int default_fv_bbsized = false */    /* in fontview */
     102             : extern int default_fv_row_count;        /* in fontview */
     103             : extern int default_fv_col_count;        /* in fontview */
     104             : extern int default_fv_showhmetrics;     /* in fontview */
     105             : extern int default_fv_showvmetrics;     /* in fontview */
     106             : extern int default_fv_glyphlabel;       /* in fontview */
     107             : extern int save_to_dir;                 /* in fontview, use sfdir rather than sfd */
     108             : extern int palettes_docked;             /* in cvpalettes */
     109             : extern int cvvisible[2], bvvisible[3];  /* in cvpalettes.c */
     110             : extern int maxundoes;                   /* in cvundoes */
     111             : extern int pref_mv_shift_and_arrow_skip;         /* in metricsview.c */
     112             : extern int pref_mv_control_shift_and_arrow_skip; /* in metricsview.c */
     113             : extern int mv_type;                              /* in metricsview.c */
     114             : extern int prefer_cjk_encodings;        /* in parsettf */
     115             : extern int onlycopydisplayed, copymetadata, copyttfinstr;
     116             : extern struct cvshows CVShows;
     117             : extern int infowindowdistance;          /* in cvruler.c */
     118             : extern int oldformatstate;              /* in savefontdlg.c */
     119             : extern int oldbitmapstate;              /* in savefontdlg.c */
     120             : static int old_ttf_flags=0, old_otf_flags=0;
     121             : extern int old_sfnt_flags;              /* in savefont.c */
     122             : extern int old_ps_flags;                /* in savefont.c */
     123             : extern int old_validate;                /* in savefontdlg.c */
     124             : extern int old_fontlog;                 /* in savefontdlg.c */
     125             : extern int oldsystem;                   /* in bitmapdlg.c */
     126             : extern int preferpotrace;               /* in autotrace.c */
     127             : extern int autotrace_ask;               /* in autotrace.c */
     128             : extern int mf_ask;                      /* in autotrace.c */
     129             : extern int mf_clearbackgrounds;         /* in autotrace.c */
     130             : extern int mf_showerrors;               /* in autotrace.c */
     131             : extern char *mf_args;                   /* in autotrace.c */
     132             : static int glyph_2_name_map=0;          /* was in tottf.c, now a flag in savefont options dlg */
     133             : extern int coverageformatsallowed;      /* in tottfgpos.c */
     134             : extern int debug_wins;                  /* in cvdebug.c */
     135             : extern int gridfit_dpi, gridfit_depth;  /* in cvgridfit.c */
     136             : extern float gridfit_pointsizey;        /* in cvgridfit.c */
     137             : extern float gridfit_pointsizex;        /* in cvgridfit.c */
     138             : extern int gridfit_x_sameas_y;          /* in cvgridfit.c */
     139             : extern int hint_diagonal_ends;          /* in stemdb.c */
     140             : extern int hint_diagonal_intersections; /* in stemdb.c */
     141             : extern int hint_bounding_boxes;         /* in stemdb.c */
     142             : extern int detect_diagonal_stems;       /* in stemdb.c */
     143             : extern float stem_slope_error;          /* in stemdb.c */
     144             : extern float stub_slope_error;          /* in stemdb.c */
     145             : extern int instruct_diagonal_stems;     /* in nowakowskittfinstr.c */
     146             : extern int instruct_serif_stems;                /* in nowakowskittfinstr.c */
     147             : extern int instruct_ball_terminals;     /* in nowakowskittfinstr.c */
     148             : extern int interpolate_strong;          /* in nowakowskittfinstr.c */
     149             : extern int control_counters;            /* in nowakowskittfinstr.c */
     150             : extern unichar_t *script_menu_names[SCRIPT_MENU_MAX];
     151             : extern char *script_filenames[SCRIPT_MENU_MAX];
     152             : static char *xdefs_filename;
     153             : extern int new_em_size;                         /* in splineutil2.c */
     154             : extern int new_fonts_are_order2;                /* in splineutil2.c */
     155             : extern int loaded_fonts_same_as_new;            /* in splineutil2.c */
     156             : extern int use_second_indic_scripts;            /* in tottfgpos.c */
     157             : static char *othersubrsfile = NULL;
     158             : extern MacFeat *default_mac_feature_map,        /* from macenc.c */
     159             :                 *user_mac_feature_map;
     160             : extern int updateflex;                          /* in charview.c */
     161             : extern int default_autokern_dlg;                /* in lookupui.c */
     162             : extern int allow_utf8_glyphnames;               /* in lookupui.c */
     163             : extern int add_char_to_name_list;               /* in charinfo.c */
     164             : extern int clear_tt_instructions_when_needed;   /* in cvundoes.c */
     165             : extern int export_clipboard;                    /* in cvundoes.c */
     166             : extern int cv_width;                    /* in charview.c */
     167             : extern int cv_height;                   /* in charview.c */
     168             : extern int cv_show_fill_with_space; /* in charview.c */
     169             : extern int interpCPsOnMotion;                   /* in charview.c */
     170             : extern int DrawOpenPathsWithHighlight;          /* in charview.c */
     171             : extern float prefs_cvEditHandleSize;            /* in charview.c */
     172             : extern int prefs_cvInactiveHandleAlpha;         /* in charview.c */
     173             : extern int mv_width;                            /* in metricsview.c */
     174             : extern int mv_height;                           /* in metricsview.c */
     175             : extern int bv_width;                            /* in bitmapview.c */
     176             : extern int bv_height;                           /* in bitmapview.c */
     177             : extern int ask_user_for_cmap;                   /* in parsettf.c */
     178             : extern int mvshowgrid;                          /* in metricsview.c */
     179             : 
     180             : extern int rectelipse, polystar, regular_star;  /* from cvpalettes.c */
     181             : extern int center_out[2];                       /* from cvpalettes.c */
     182             : extern float rr_radius;                         /* from cvpalettes.c */
     183             : extern int ps_pointcnt;                         /* from cvpalettes.c */
     184             : extern float star_percent;                      /* from cvpalettes.c */
     185             : extern int home_char;                           /* from fontview.c */
     186             : extern int compact_font_on_open;                /* from fontview.c */
     187             : extern int aa_pixelsize;                        /* from anchorsaway.c */
     188             : extern enum cvtools cv_b1_tool, cv_cb1_tool, cv_b2_tool, cv_cb2_tool; /* cvpalettes.c */
     189             : extern int show_kerning_pane_in_class;          /* kernclass.c */
     190             : extern int AutoSaveFrequency;                   /* autosave.c */
     191             : extern int UndoRedoLimitToSave;  /* sfd.c */
     192             : extern int UndoRedoLimitToLoad;  /* sfd.c */
     193             : extern int prefRevisionsToRetain; /* sfd.c */
     194             : extern int prefs_cv_show_control_points_always_initially; /* from charview.c */
     195             : extern int prefs_create_dragging_comparison_outline;      /* from charview.c */
     196             : extern int prefs_cv_outline_thickness; /* from charview.c */
     197             : 
     198             : extern char *pref_collab_last_server_connected_to; /* in collabclient.c */
     199             : 
     200             : extern float OpenTypeLoadHintEqualityTolerance;  /* autohint.c */
     201             : extern float GenerateHintWidthEqualityTolerance; /* splinesave.c */
     202             : extern NameList *force_names_when_opening;
     203             : extern NameList *force_names_when_saving;
     204             : extern NameList *namelist_for_new_fonts;
     205             : 
     206             : extern int default_font_filter_index;
     207             : extern struct openfilefilters *user_font_filters;
     208             : static int alwaysgenapple=false, alwaysgenopentype=false;
     209             : 
     210             : static int gfc_showhidden, gfc_dirplace;
     211             : static char *gfc_bookmarks=NULL;
     212             : 
     213             : static int prefs_usecairo = true;
     214             : 
     215             : static int pointless;
     216             : 
     217             :     /* These first three must match the values in macenc.c */
     218             : #define CID_Features    101
     219             : #define CID_FeatureDel  103
     220             : #define CID_FeatureEdit 105
     221             : 
     222             : #define CID_Mapping     102
     223             : #define CID_MappingDel  104
     224             : #define CID_MappingEdit 106
     225             : 
     226             : #define CID_ScriptMNameBase     200
     227             : #define CID_ScriptMFileBase     (200+SCRIPT_MENU_MAX)
     228             : #define CID_ScriptMBrowseBase   (200+2*SCRIPT_MENU_MAX)
     229             : 
     230             : #define CID_PrefsBase   1000
     231             : #define CID_PrefsOffset 100
     232             : #define CID_PrefsBrowseOffset   (CID_PrefsOffset/2)
     233             : 
     234             : //////////////////////////////////
     235             : // The _oldval_ are used to cache the setting when the prefs window
     236             : // is created so that a redraw can be performed only when the
     237             : // value has changed.
     238             : float prefs_oldval_cvEditHandleSize = 0;
     239             : int   prefs_oldval_cvInactiveHandleAlpha = 0;
     240             : 
     241             : /* ************************************************************************** */
     242             : /* *****************************    mac data    ***************************** */
     243             : /* ************************************************************************** */
     244             : 
     245             : extern struct macsettingname macfeat_otftag[], *user_macfeat_otftag;
     246             : 
     247           0 : static void UserSettingsFree(void) {
     248             : 
     249           0 :     free( user_macfeat_otftag );
     250           0 :     user_macfeat_otftag = NULL;
     251           0 : }
     252             : 
     253           0 : static int UserSettingsDiffer(void) {
     254             :     int i,j;
     255             : 
     256           0 :     if ( user_macfeat_otftag==NULL )
     257           0 : return( false );
     258             : 
     259           0 :     for ( i=0; user_macfeat_otftag[i].otf_tag!=0; ++i );
     260           0 :     for ( j=0; macfeat_otftag[j].otf_tag!=0; ++j );
     261           0 :     if ( i!=j )
     262           0 : return( true );
     263           0 :     for ( i=0; user_macfeat_otftag[i].otf_tag!=0; ++i ) {
     264           0 :         for ( j=0; macfeat_otftag[j].otf_tag!=0; ++j ) {
     265           0 :             if ( macfeat_otftag[j].mac_feature_type ==
     266           0 :                     user_macfeat_otftag[i].mac_feature_type &&
     267           0 :                     macfeat_otftag[j].mac_feature_setting ==
     268           0 :                     user_macfeat_otftag[i].mac_feature_setting &&
     269           0 :                     macfeat_otftag[j].otf_tag ==
     270           0 :                     user_macfeat_otftag[i].otf_tag )
     271           0 :         break;
     272             :         }
     273           0 :         if ( macfeat_otftag[j].otf_tag==0 )
     274           0 : return( true );
     275             :     }
     276           0 : return( false );
     277             : }
     278             : 
     279             : /**************************************************************************** */
     280             : 
     281             : 
     282             : /* don't use mnemonics 'C' or 'O' (Cancel & OK) */
     283             : enum pref_types { pr_int, pr_real, pr_bool, pr_enum, pr_encoding, pr_string,
     284             :         pr_file, pr_namelist, pr_unicode, pr_angle };
     285             : struct enums { char *name; int value; };
     286             : 
     287             : struct enums fvsize_enums[] = { {NULL, 0} };
     288             : 
     289             : #define PREFS_LIST_EMPTY { NULL, 0, NULL, NULL, NULL, '\0', NULL, 0, NULL }
     290             : static struct prefs_list {
     291             :     char *name;
     292             :         /* In the prefs file the untranslated name will always be used, but */
     293             :         /* in the UI that name may be translated. */
     294             :     enum pref_types type;
     295             :     void *val;
     296             :     void *(*get)(void);
     297             :     void (*set)(void *);
     298             :     char mn;
     299             :     struct enums *enums;
     300             :     unsigned int dontdisplay: 1;
     301             :     char *popup;
     302             : } general_list[] = {
     303             : /* GT: The following strings have no spaces and an odd capitalization */
     304             : /* GT: this is because these strings are used in two different ways, one */
     305             : /* GT: translated (which the user sees, and should probably have added spaces,*/
     306             : /* GT: and one untranslated which needs the current odd format */
     307             :         { 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.") },
     308             :         { 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.") },
     309             :         { 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.") },
     310             :         { 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.") },
     311             :         { N_("SplashScreen"), pr_bool, &splash, NULL, NULL, 'S', NULL, 0, N_("Show splash screen on start-up") },
     312             : #ifndef _NO_LIBCAIRO
     313             :         { N_("UseCairoDrawing"), pr_bool, &prefs_usecairo, NULL, NULL, '\0', NULL, 0, N_("Use the cairo library for drawing (if available)\nThis makes for prettier (anti-aliased) but slower drawing\nThis applies to any windows created AFTER this is set.\nAlready existing windows will continue as they are.") },
     314             : #endif
     315             :         { 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.") },
     316             :         { 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.") },
     317             :         { 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.") },
     318             :         { 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.") },
     319             :         PREFS_LIST_EMPTY
     320             : },
     321             :   new_list[] = {
     322             :         { N_("NewCharset"), pr_encoding, &default_encoding, NULL, NULL, 'N', NULL, 0, N_("Default encoding for\nnew fonts") },
     323             :         { 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.") },
     324             :         { 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).") },
     325             :         { 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).") },
     326             :         PREFS_LIST_EMPTY
     327             : },
     328             :   open_list[] = {
     329             :         { 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.") },
     330             :         { 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.") },
     331             :         { 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.") },
     332             :         { 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.")},
     333             :         { N_("CompactOnOpen"), pr_bool, &compact_font_on_open, NULL, NULL, 'O', NULL, 0, N_("When a font is opened, should it be made compact?")},
     334             :         { 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.") },
     335             :         { 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).") },
     336             :         PREFS_LIST_EMPTY
     337             : },
     338             :   navigation_list[] = {
     339             :         { 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.") },
     340             :         { 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.") },
     341             :         PREFS_LIST_EMPTY
     342             : },
     343             :   editing_list[] = {
     344             :         { 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.") },
     345             :         { 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.") },
     346             :         { 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.") },
     347             :         { 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.") },
     348             :         { 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.") },
     349             :         { 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.") },
     350             :         { 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") },
     351             :         { 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).") },
     352             :         { 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)") },
     353             :         { N_("UpdateFlex"), pr_bool, &updateflex, NULL, NULL, '\0', NULL, 0, N_("Figure out flex hints after every change") },
     354             :         { N_("AutoKernDialog"), pr_bool, &default_autokern_dlg, NULL, NULL, '\0', NULL, 0, N_("Open AutoKern dialog for new kerning subtables") },
     355             :         { 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") },
     356             :         { 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") },
     357             :         PREFS_LIST_EMPTY
     358             : },
     359             :   editing_interface_list[] = {
     360             :         { 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") },
     361             :         { 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") },
     362             :         { 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.") },
     363             :         { N_("MeasureToolShowHorizontalVertical"), pr_bool, &measuretoolshowhorizontolvertical, NULL, NULL, '\0', NULL, 0, N_("Have the measure tool show horizontal and vertical distances on the canvas.") },
     364             :         { N_("XORRubberLines"), pr_bool, &xorrubberlines, NULL, NULL, '\0', NULL, 0, N_("Use XOR based rubber lines.") },
     365             :         { 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).") },
     366             :         { 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).") },
     367             :         { 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.") },
     368             :         { 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.") },
     369             :         { 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.") },
     370             :         PREFS_LIST_EMPTY
     371             : },
     372             :   sync_list[] = {
     373             :         { 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.") },
     374             :         { 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.") },
     375             :         PREFS_LIST_EMPTY
     376             : },
     377             :  tt_list[] = {
     378             :         { 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!") },
     379             :         { N_("CopyTTFInstrs"), pr_bool, &copyttfinstr, NULL, NULL, '\0', NULL, 0, N_("When copying glyphs from the font view, also copy the\nglyphs' truetype instructions.") },
     380             :         PREFS_LIST_EMPTY
     381             : },
     382             :   accent_list[] = {
     383             :         { 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") },
     384             :         { 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.") },
     385             :         { 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?") },
     386             :         { 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.") },
     387             :         PREFS_LIST_EMPTY
     388             : },
     389             :  args_list[] = {
     390             :         { 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.") },
     391             :         { N_("AutotraceArgs"), pr_string, NULL, GetAutoTraceArgs, SetAutoTraceArgs, '\0', NULL, 0, N_("Extra arguments for configuring the autotrace program\n(either autotrace or potrace)") },
     392             :         { N_("AutotraceAsk"), pr_bool, &autotrace_ask, NULL, NULL, '\0', NULL, 0, N_("Ask the user for autotrace arguments each time autotrace is invoked") },
     393             :         { N_("MfArgs"), pr_string, &mf_args, NULL, NULL, '\0', NULL, 0, N_("Commands to pass to mf (metafont) program, the filename will follow these") },
     394             :         { N_("MfAsk"), pr_bool, &mf_ask, NULL, NULL, '\0', NULL, 0, N_("Ask the user for mf commands each time mf is invoked") },
     395             :         { 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") },
     396             :         { 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.") },
     397             :         PREFS_LIST_EMPTY
     398             : },
     399             :  fontinfo_list[] = {
     400             :         { N_("FoundryName"), pr_string, &BDFFoundry, NULL, NULL, 'F', NULL, 0, N_("Name used for foundry field in bdf\nfont generation") },
     401             :         { 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") },
     402             :         { 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.") },
     403             :         { 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.") },
     404             :         { 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." ) },
     405             :         { 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" ) },
     406             :         PREFS_LIST_EMPTY
     407             : },
     408             :  generate_list[] = {
     409             :         { 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.") },
     410             :         { N_("AutoHint"), pr_bool, &autohint_before_generate, NULL, NULL, 'H', NULL, 0, N_("AutoHint changed glyphs before generating a font") },
     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             : #ifdef BUILD_COLLAB
     438             :  collab_list[] = {
     439             :         { N_("SessionJoinTimeout"), pr_int, &pref_collab_sessionJoinTimeoutMS, NULL, NULL, 'C', NULL, 0, N_("The number of milliseconds to wait for a connection to the collaboration server to happen. FontForge may be unresponsive during this session connection time. (default 1000 which is 1 second)") },
     440             :         { N_("RoundTripMessageMaxTime"), pr_int, &pref_collab_roundTripTimerMS, NULL, NULL, 'C', NULL, 0, N_("The number of milliseconds that are allowed to pass between sending an update to the server and hearing it sent back as a message to all clients. The FontForge user interface may be unresponsive during this time. A change requires a restart of FontForge. (default 2000 which is 2 seconds)") },
     441             :         PREFS_LIST_EMPTY
     442             : },
     443             : #endif
     444             : /* These are hidden, so will never appear in preference ui, hence, no "N_(" */
     445             : /*  They are controled elsewhere AntiAlias is a menu item in the font window's View menu */
     446             : /*  etc. */
     447             :  hidden_list[] = {
     448             :         { "AntiAlias", pr_bool, &default_fv_antialias, NULL, NULL, '\0', NULL, 1, NULL },
     449             :         { "DefaultFVShowHmetrics", pr_int, &default_fv_showhmetrics, NULL, NULL, '\0', NULL, 1, NULL },
     450             :         { "DefaultFVShowVmetrics", pr_int, &default_fv_showvmetrics, NULL, NULL, '\0', NULL, 1, NULL },
     451             :         { "DefaultFVSize", pr_int, &default_fv_font_size, NULL, NULL, 'S', NULL, 1, NULL },
     452             :         { "DefaultFVRowCount", pr_int, &default_fv_row_count, NULL, NULL, 'S', NULL, 1, NULL },
     453             :         { "DefaultFVColCount", pr_int, &default_fv_col_count, NULL, NULL, 'S', NULL, 1, NULL },
     454             :         { "DefaultFVGlyphLabel", pr_int, &default_fv_glyphlabel, NULL, NULL, 'S', NULL, 1, NULL },
     455             :         { "SaveToDir", pr_int, &save_to_dir, NULL, NULL, 'S', NULL, 1, NULL },
     456             :         { "OnlyCopyDisplayed", pr_bool, &onlycopydisplayed, NULL, NULL, '\0', NULL, 1, NULL },
     457             :         { "PalettesDocked", pr_bool, &palettes_docked, NULL, NULL, '\0', NULL, 1, NULL },
     458             :         { "DefaultCVWidth", pr_int, &cv_width, NULL, NULL, '\0', NULL, 1, NULL },
     459             :         { "DefaultCVHeight", pr_int, &cv_height, NULL, NULL, '\0', NULL, 1, NULL },
     460             :         { "CVVisible0", pr_bool, &cvvisible[0], NULL, NULL, '\0', NULL, 1, NULL },
     461             :         { "CVVisible1", pr_bool, &cvvisible[1], NULL, NULL, '\0', NULL, 1, NULL },
     462             :         { "BVVisible0", pr_bool, &bvvisible[0], NULL, NULL, '\0', NULL, 1, NULL },
     463             :         { "BVVisible1", pr_bool, &bvvisible[1], NULL, NULL, '\0', NULL, 1, NULL },
     464             :         { "BVVisible2", pr_bool, &bvvisible[2], NULL, NULL, '\0', NULL, 1, NULL },
     465             :         { "MarkExtrema", pr_int, &CVShows.markextrema, NULL, NULL, '\0', NULL, 1, NULL },
     466             :         { "MarkPointsOfInflect", pr_int, &CVShows.markpoi, NULL, NULL, '\0', NULL, 1, NULL },
     467             :         { "ShowRulers", pr_bool, &CVShows.showrulers, NULL, NULL, '\0', NULL, 1, N_("Display rulers in the Outline Glyph View") },
     468             :         { "ShowCPInfo", pr_int, &CVShows.showcpinfo, NULL, NULL, '\0', NULL, 1, NULL },
     469             :         { "CreateDraggingComparisonOutline", pr_int, &prefs_create_dragging_comparison_outline, NULL, NULL, '\0', NULL, 1, NULL },
     470             :         { "InfoWindowDistance", pr_int, &infowindowdistance, NULL, NULL, '\0', NULL, 1, NULL },
     471             :         { "ShowSideBearings", pr_int, &CVShows.showsidebearings, NULL, NULL, '\0', NULL, 1, NULL },
     472             :         { "ShowRefNames", pr_int, &CVShows.showrefnames, NULL, NULL, '\0', NULL, 1, NULL },
     473             :         { "ShowPoints", pr_bool, &CVShows.showpoints, NULL, NULL, '\0', NULL, 1, NULL },
     474             :         { "ShowFilled", pr_int, &CVShows.showfilled, NULL, NULL, '\0', NULL, 1, NULL },
     475             :         { "ShowTabs", pr_int, &CVShows.showtabs, NULL, NULL, '\0', NULL, 1, NULL },
     476             :         { "SnapOutlines", pr_int, &CVShows.snapoutlines, NULL, NULL, '\0', NULL, 1, NULL },
     477             :         { "ShowAlmostHVLines", pr_bool, &CVShows.showalmosthvlines, NULL, NULL, '\0', NULL, 1, NULL },
     478             :         { "ShowAlmostHVCurves", pr_bool, &CVShows.showalmosthvcurves, NULL, NULL, '\0', NULL, 1, NULL },
     479             :         { "AlmostHVBound", pr_int, &CVShows.hvoffset, NULL, NULL, '\0', NULL, 1, NULL },
     480             :         { "CheckSelfIntersects", pr_bool, &CVShows.checkselfintersects, NULL, NULL, '\0', NULL, 1, NULL },
     481             :         { "ShowDebugChanges", pr_bool, &CVShows.showdebugchanges, NULL, NULL, '\0', NULL, 1, NULL },
     482             :         { "DefaultScreenDpiSystem", pr_int, &oldsystem, NULL, NULL, '\0', NULL, 1, NULL },
     483             :         { "DefaultOutputFormat", pr_int, &oldformatstate, NULL, NULL, '\0', NULL, 1, NULL },
     484             :         { "DefaultBitmapFormat", pr_int, &oldbitmapstate, NULL, NULL, '\0', NULL, 1, NULL },
     485             :         { "SaveValidate", pr_int, &old_validate, NULL, NULL, '\0', NULL, 1, NULL },
     486             :         { "SaveFontLogAsk", pr_int, &old_fontlog, NULL, NULL, '\0', NULL, 1, NULL },
     487             :         { "DefaultSFNTflags", pr_int, &old_sfnt_flags, NULL, NULL, '\0', NULL, 1, NULL },
     488             :         { "DefaultPSflags", pr_int, &old_ps_flags, NULL, NULL, '\0', NULL, 1, NULL },
     489             :         { "PageWidth", pr_int, &pagewidth, NULL, NULL, '\0', NULL, 1, NULL },
     490             :         { "PageHeight", pr_int, &pageheight, NULL, NULL, '\0', NULL, 1, NULL },
     491             :         { "PrintType", pr_int, &printtype, NULL, NULL, '\0', NULL, 1, NULL },
     492             :         { "PrintCommand", pr_string, &printcommand, NULL, NULL, '\0', NULL, 1, NULL },
     493             :         { "PageLazyPrinter", pr_string, &printlazyprinter, NULL, NULL, '\0', NULL, 1, NULL },
     494             :         { "RegularStar", pr_bool, &regular_star, NULL, NULL, '\0', NULL, 1, NULL },
     495             :         { "PolyStar", pr_bool, &polystar, NULL, NULL, '\0', NULL, 1, NULL },
     496             :         { "RectEllipse", pr_bool, &rectelipse, NULL, NULL, '\0', NULL, 1, NULL },
     497             :         { "RectCenterOut", pr_bool, &center_out[0], NULL, NULL, '\0', NULL, 1, NULL },
     498             :         { "EllipseCenterOut", pr_bool, &center_out[1], NULL, NULL, '\0', NULL, 1, NULL },
     499             :         { "PolyStartPointCnt", pr_int, &ps_pointcnt, NULL, NULL, '\0', NULL, 1, NULL },
     500             :         { "RoundRectRadius", pr_real, &rr_radius, NULL, NULL, '\0', NULL, 1, NULL },
     501             :         { "StarPercent", pr_real, &star_percent, NULL, NULL, '\0', NULL, 1, NULL },
     502             :         { "CoverageFormatsAllowed", pr_int, &coverageformatsallowed, NULL, NULL, '\0', NULL, 1, NULL },
     503             :         { "DebugWins", pr_int, &debug_wins, NULL, NULL, '\0', NULL, 1, NULL },
     504             :         { "GridFitDpi", pr_int, &gridfit_dpi, NULL, NULL, '\0', NULL, 1, NULL },
     505             :         { "GridFitDepth", pr_int, &gridfit_depth, NULL, NULL, '\0', NULL, 1, NULL },
     506             :         { "GridFitPointSize", pr_real, &gridfit_pointsizey, NULL, NULL, '\0', NULL, 1, NULL },
     507             :         { "GridFitPointSizeX", pr_real, &gridfit_pointsizex, NULL, NULL, '\0', NULL, 1, NULL },
     508             :         { "GridFitSameAs", pr_int, &gridfit_x_sameas_y, NULL, NULL, '\0', NULL, 1, NULL },
     509             :         { "MVShowGrid", pr_int, &mvshowgrid, NULL, NULL, '\0', NULL, 1, NULL },
     510             :         { "ForceNamesWhenOpening", pr_namelist, &force_names_when_opening, NULL, NULL, '\0', NULL, 1, NULL },
     511             :         { "ForceNamesWhenSaving", pr_namelist, &force_names_when_saving, NULL, NULL, '\0', NULL, 1, NULL },
     512             :         { "DefaultFontFilterIndex", pr_int, &default_font_filter_index, NULL, NULL, '\0', NULL, 1, NULL },
     513             :         { "FCShowHidden", pr_bool, &gfc_showhidden, NULL, NULL, '\0', NULL, 1, NULL },
     514             :         { "FCDirPlacement", pr_int, &gfc_dirplace, NULL, NULL, '\0', NULL, 1, NULL },
     515             :         { "FCBookmarks", pr_string, &gfc_bookmarks, NULL, NULL, '\0', NULL, 1, NULL },
     516             :         { "DefaultMVType",   pr_int, &mv_type, NULL, NULL, '\0', NULL, 1, NULL },
     517             :         { "DefaultMVWidth",  pr_int, &mv_width, NULL, NULL, '\0', NULL, 1, NULL },
     518             :         { "DefaultMVHeight", pr_int, &mv_height, NULL, NULL, '\0', NULL, 1, NULL },
     519             :         { "DefaultBVWidth", pr_int, &bv_width, NULL, NULL, '\0', NULL, 1, NULL },
     520             :         { "DefaultBVHeight", pr_int, &bv_height, NULL, NULL, '\0', NULL, 1, NULL },
     521             :         { "AnchorControlPixelSize", pr_int, &aa_pixelsize, NULL, NULL, '\0', NULL, 1, NULL },
     522             :         { "CollabLastServerConnectedTo", pr_string, &pref_collab_last_server_connected_to, NULL, NULL, '\0', NULL, 1, NULL },
     523             : #ifdef _NO_LIBCAIRO
     524             :         { "UseCairoDrawing", pr_bool, &prefs_usecairo, NULL, NULL, '\0', NULL, 0, N_("Use the cairo library for drawing (if available)\nThis makes for prettier (anti-aliased) but slower drawing\nThis applies to any windows created AFTER this is set.\nAlready existing windows will continue as they are.") },
     525             : #endif
     526             :         { "CV_B1Tool", pr_int, (int *) &cv_b1_tool, NULL, NULL, '\0', NULL, 1, NULL },
     527             :         { "CV_CB1Tool", pr_int, (int *) &cv_cb1_tool, NULL, NULL, '\0', NULL, 1, NULL },
     528             :         { "CV_B2Tool", pr_int, (int *) &cv_b2_tool, NULL, NULL, '\0', NULL, 1, NULL },
     529             :         { "CV_CB2Tool", pr_int, (int *) &cv_cb2_tool, NULL, NULL, '\0', NULL, 1, NULL },
     530             :         { "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 */
     531             :         { "ShowKerningPane", pr_int, (int *) &show_kerning_pane_in_class, NULL, NULL, '\0', NULL, 1, NULL },
     532             :         PREFS_LIST_EMPTY
     533             : },
     534             :  oldnames[] = {
     535             :         { "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.") },
     536             :         { "DefaultTTFApple", pr_int, &pointless, NULL, NULL, '\0', NULL, 1, NULL },
     537             :         { "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.") },
     538             :         { "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") },
     539             :         { "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") },
     540             :         { "DefaultTTFflags", pr_int, &old_ttf_flags, NULL, NULL, '\0', NULL, 1, NULL },
     541             :         { "DefaultOTFflags", pr_int, &old_otf_flags, NULL, NULL, '\0', NULL, 1, NULL },
     542             :         PREFS_LIST_EMPTY
     543             : },
     544             :  *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,
     545             :  #ifdef BUILD_COLLAB
     546             :  collab_list,
     547             :  #endif
     548             :  hidden_list, NULL },
     549             :  *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,
     550             :  #ifdef BUILD_COLLAB
     551             :  collab_list,
     552             :  #endif
     553             :  hidden_list, oldnames, NULL };
     554             : 
     555             : struct visible_prefs_list { char *tab_name; int nest; struct prefs_list *pl; } visible_prefs_list[] = {
     556             :     { N_("Generic"), 0, general_list},
     557             :     { N_("New Font"), 0, new_list},
     558             :     { N_("Open Font"), 0, open_list},
     559             :     { N_("Navigation"), 0, navigation_list},
     560             :     { N_("Editing"), 0, editing_list},
     561             :     { N_("Interface"), 1, editing_interface_list},
     562             :     { N_("Synchronize"), 1, sync_list},
     563             :     { N_("TT"), 1, tt_list},
     564             :     { N_("Accents"), 1, accent_list},
     565             :     { N_("Apps"), 1, args_list},
     566             :     { N_("Font Info"), 0, fontinfo_list},
     567             :     { N_("Generate"), 0, generate_list},
     568             :     { N_("PS Hints"), 1, hints_list},
     569             :     { N_("TT Instrs"), 1, instrs_list},
     570             :     { N_("OpenType"), 1, opentype_list},
     571             : #ifdef BUILD_COLLAB
     572             :     { N_("Collaboration"), 0, collab_list},
     573             : #endif
     574             :     { NULL, 0, NULL }
     575             : };
     576             : 
     577           0 : static void FileChooserPrefsChanged(void *pointless) {
     578           0 :     SavePrefs(true);
     579           0 : }
     580             : 
     581           1 : static void ProcessFileChooserPrefs(void) {
     582             :     unichar_t **b;
     583             :     int i;
     584             : 
     585           1 :     GFileChooserSetShowHidden(gfc_showhidden);
     586           1 :     GFileChooserSetDirectoryPlacement(gfc_dirplace);
     587           1 :     if ( gfc_bookmarks==NULL ) {
     588           1 :         b = malloc(8*sizeof(unichar_t *));
     589           1 :         i = 0;
     590             : #ifdef __Mac
     591             :         b[i++] = uc_copy("~/Library/Fonts/");
     592             : #endif
     593           1 :         b[i++] = uc_copy("~/fonts");
     594             : #ifdef __Mac
     595             :         b[i++] = uc_copy("/Library/Fonts/");
     596             :         b[i++] = uc_copy("/System/Library/Fonts/");
     597             : #endif
     598             : #if __CygWin
     599             :         b[i++] = uc_copy("/cygdrive/c/Windows/Fonts/");
     600             : #endif
     601           1 :         b[i++] = uc_copy("/usr/X11R6/lib/X11/fonts/");
     602             : #ifndef __CygWin                /* I'm not releasing ftp support on cygwin */
     603           1 :         b[i++] = uc_copy("ftp://ctan.org/pub/tex-archive/fonts/");
     604             : #endif
     605           1 :         b[i++] = NULL;
     606           1 :         GFileChooserSetBookmarks(b);
     607             :     } else {
     608             :         char *pt, *start;
     609           0 :         start = gfc_bookmarks;
     610           0 :         for ( i=0; ; ++i ) {
     611           0 :             pt = strchr(start,';');
     612           0 :             if ( pt==NULL )
     613           0 :         break;
     614           0 :             start = pt+1;
     615           0 :         }
     616           0 :         start = gfc_bookmarks;
     617           0 :         b = malloc((i+2)*sizeof(unichar_t *));
     618           0 :         for ( i=0; ; ++i ) {
     619           0 :             pt = strchr(start,';');
     620           0 :             if ( pt!=NULL )
     621           0 :                 *pt = '\0';
     622           0 :             b[i] = utf82u_copy(start);
     623           0 :             if ( pt==NULL )
     624           0 :         break;
     625           0 :             *pt = ';';
     626           0 :             start = pt+1;
     627           0 :         }
     628           0 :         b[i+1] = NULL;
     629           0 :         GFileChooserSetBookmarks(b);
     630             :     }
     631           1 :     GFileChooserSetPrefsChangedCallback(NULL,FileChooserPrefsChanged);
     632           1 : }
     633             : 
     634           0 : static void GetFileChooserPrefs(void) {
     635             :     unichar_t **foo;
     636             : 
     637           0 :     gfc_showhidden = GFileChooserGetShowHidden();
     638           0 :     gfc_dirplace = GFileChooserGetDirectoryPlacement();
     639           0 :     foo = GFileChooserGetBookmarks();
     640           0 :     free(gfc_bookmarks);
     641           0 :     if ( foo==NULL || foo[0]==NULL )
     642           0 :         gfc_bookmarks = NULL;
     643             :     else {
     644           0 :         int i,len=0;
     645           0 :         for ( i=0; foo[i]!=NULL; ++i )
     646           0 :             len += 4*u_strlen(foo[i])+1;
     647           0 :         gfc_bookmarks = malloc(len+10);
     648           0 :         len = 0;
     649           0 :         for ( i=0; foo[i]!=NULL; ++i ) {
     650           0 :             u2utf8_strcpy(gfc_bookmarks+len,foo[i]);
     651           0 :             len += strlen(gfc_bookmarks+len);
     652           0 :             gfc_bookmarks[len++] = ';';
     653             :         }
     654           0 :         if ( len>0 )
     655           0 :             gfc_bookmarks[len-1] = '\0';
     656             :         else {
     657           0 :             free(gfc_bookmarks);
     658           0 :             gfc_bookmarks = NULL;
     659             :         }
     660             :     }
     661           0 : }
     662             : 
     663             : #define TOPICS  (sizeof(visible_prefs_list)/sizeof(visible_prefs_list[0])-1)
     664             : 
     665           1 : static int PrefsUI_GetPrefs(char *name,Val *val) {
     666             :     int i,j;
     667             : 
     668             :     /* Support for obsolete preferences */
     669           1 :     alwaysgenapple=(old_sfnt_flags&ttf_flag_applemode)?1:0;
     670           1 :     alwaysgenopentype=(old_sfnt_flags&ttf_flag_otmode)?1:0;
     671             : 
     672          77 :     for ( i=0; prefs_list[i]!=NULL; ++i ) for ( j=0; prefs_list[i][j].name!=NULL; ++j ) {
     673          77 :         if ( strcmp(prefs_list[i][j].name,name)==0 ) {
     674           1 :             struct prefs_list *pf = &prefs_list[i][j];
     675           1 :             if ( pf->type == pr_bool || pf->type == pr_int || pf->type == pr_unicode ) {
     676           1 :                 val->type = v_int;
     677           1 :                 val->u.ival = *((int *) (pf->val));
     678           0 :             } else if ( pf->type == pr_string || pf->type == pr_file ) {
     679           0 :                 val->type = v_str;
     680             : 
     681           0 :                 char *tmpstr = pf->val ? *((char **) (pf->val)) : (char *) (pf->get)();
     682           0 :                 val->u.sval = copy( tmpstr ? tmpstr : "" );
     683             : 
     684           0 :                 if( ! pf->val )
     685           0 :                     free( tmpstr );
     686           0 :             } else if ( pf->type == pr_encoding ) {
     687           0 :                 val->type = v_str;
     688           0 :                 if ( *((NameList **) (pf->val))==NULL )
     689           0 :                     val->u.sval = copy( "NULL" );
     690             :                 else
     691           0 :                     val->u.sval = copy( (*((Encoding **) (pf->val)))->enc_name );
     692           0 :             } else if ( pf->type == pr_namelist ) {
     693           0 :                 val->type = v_str;
     694           0 :                 val->u.sval = copy( (*((NameList **) (pf->val)))->title );
     695           0 :             } else if ( pf->type == pr_real || pf->type == pr_angle ) {
     696           0 :                 val->type = v_real;
     697           0 :                 val->u.fval = *((float *) (pf->val));
     698           0 :                 if ( pf->type == pr_angle )
     699           0 :                     val->u.fval *= RAD2DEG;
     700             :             } else
     701           0 : return( false );
     702             : 
     703           1 : return( true );
     704             :         }
     705             :     }
     706           0 : return( false );
     707             : }
     708             : 
     709           3 : static void CheckObsoletePrefs(void) {
     710           3 :     if ( alwaysgenapple==false ) {
     711           0 :         old_sfnt_flags &= ~ttf_flag_applemode;
     712           3 :     } else if ( alwaysgenapple==true ) {
     713           0 :         old_sfnt_flags |= ttf_flag_applemode;
     714             :     }
     715           3 :     if ( alwaysgenopentype==false ) {
     716           0 :         old_sfnt_flags &= ~ttf_flag_otmode;
     717           3 :     } else if ( alwaysgenopentype==true ) {
     718           0 :         old_sfnt_flags |= ttf_flag_otmode;
     719             :     }
     720           3 :     if ( old_ttf_flags!=0 )
     721           0 :         old_sfnt_flags = old_ttf_flags | old_otf_flags;
     722           3 : }
     723             : 
     724           3 : static int PrefsUI_SetPrefs(char *name,Val *val1, Val *val2) {
     725             :     int i,j;
     726             : 
     727             :     /* Support for obsolete preferences */
     728           3 :     alwaysgenapple=-1; alwaysgenopentype=-1;
     729             : 
     730         231 :     for ( i=0; prefs_list[i]!=NULL; ++i ) for ( j=0; prefs_list[i][j].name!=NULL; ++j ) {
     731         231 :         if ( strcmp(prefs_list[i][j].name,name)==0 ) {
     732           3 :             struct prefs_list *pf = &prefs_list[i][j];
     733           3 :             if ( pf->type == pr_bool || pf->type == pr_int || pf->type == pr_unicode ) {
     734           3 :                 if ( (val1->type!=v_int && val1->type!=v_unicode) || val2!=NULL )
     735           0 : return( -1 );
     736           3 :                 *((int *) (pf->val)) = val1->u.ival;
     737           0 :             } else if ( pf->type == pr_real || pf->type == pr_angle ) {
     738           0 :                 if ( val1->type==v_real && val2==NULL )
     739           0 :                     *((float *) (pf->val)) = val1->u.fval;
     740           0 :                 else if ( val1->type!=v_int || (val2!=NULL && val2->type!=v_int ))
     741           0 : return( -1 );
     742             :                 else
     743           0 :                     *((float *) (pf->val)) = (val2==NULL ? val1->u.ival : val1->u.ival / (double) val2->u.ival);
     744           0 :                 if ( pf->type == pr_angle )
     745           0 :                     *((float *) (pf->val)) /= RAD2DEG;
     746           0 :             } else if ( pf->type == pr_string || pf->type == pr_file ) {
     747           0 :                 if ( val1->type!=v_str || val2!=NULL )
     748           0 : return( -1 );
     749           0 :                 if ( pf->set ) {
     750           0 :                     pf->set( val1->u.sval );
     751             :                 } else {
     752           0 :                     free( *((char **) (pf->val)));
     753           0 :                     *((char **) (pf->val)) = copy( val1->u.sval );
     754             :                 }
     755           0 :             } else if ( pf->type == pr_encoding ) {
     756           0 :                 if ( val2!=NULL )
     757           0 : return( -1 );
     758           0 :                 else if ( val1->type==v_str && pf->val == &default_encoding) {
     759           0 :                     Encoding *enc = FindOrMakeEncoding(val1->u.sval);
     760           0 :                     if ( enc==NULL )
     761           0 : return( -1 );
     762           0 :                     *((Encoding **) (pf->val)) = enc;
     763             :                 } else
     764           0 : return( -1 );
     765           0 :             } else if ( pf->type == pr_namelist ) {
     766           0 :                 if ( val2!=NULL )
     767           0 : return( -1 );
     768           0 :                 else if ( val1->type==v_str ) {
     769           0 :                     NameList *nl = NameListByName(val1->u.sval);
     770           0 :                     if ( strcmp(val1->u.sval,"NULL")==0 && pf->val != &namelist_for_new_fonts )
     771           0 :                         nl = NULL;
     772           0 :                     else if ( nl==NULL )
     773           0 : return( -1 );
     774           0 :                     *((NameList **) (pf->val)) = nl;
     775             :                 } else
     776           0 : return( -1 );
     777             :             } else
     778           0 : return( false );
     779             : 
     780           3 :             CheckObsoletePrefs();
     781           3 :             SavePrefs(true);
     782           3 : return( true );
     783             :         }
     784             :     }
     785           0 : return( false );
     786             : }
     787             : 
     788          36 : static char *getPfaEditPrefs(void) {
     789             :     static char *prefs=NULL;
     790             :     char buffer[1025];
     791             :     char *ffdir;
     792             : 
     793          36 :     if ( prefs!=NULL )
     794          21 :         return prefs;
     795          15 :     ffdir = getFontForgeUserDir(Config);
     796          15 :     if ( ffdir==NULL )
     797           0 :         return NULL;
     798          15 :     sprintf(buffer,"%s/prefs", ffdir);
     799          15 :     free(ffdir);
     800          15 :     prefs = copy(buffer);
     801          15 :     return prefs;
     802             : }
     803             : 
     804          15 : static char *PrefsUI_getFontForgeShareDir(void) {
     805             :     static char *sharedir=NULL;
     806             :     static int set=false;
     807             :     char *pt;
     808             :     int len;
     809             : 
     810          15 :     if ( set )
     811           2 : return( sharedir );
     812             : 
     813          13 :     set = true;
     814             : 
     815             : #if defined(__MINGW32__)
     816             : 
     817             :     len = strlen(GResourceProgramDir) + strlen("/share/fontforge") +1;
     818             :     sharedir = malloc(len);
     819             :     strcpy(sharedir, GResourceProgramDir);
     820             :     strcat(sharedir, "/share/fontforge");
     821             :     return sharedir;
     822             : 
     823             : #else
     824             : 
     825          13 :     pt = strstr(GResourceProgramDir,"/bin");
     826          13 :     if ( pt==NULL ) {
     827             : #if defined(SHAREDIR)
     828          13 :         sharedir = copy(SHAREDIR "/fontforge" );
     829          13 : return( sharedir );
     830             : #elif defined(PREFIX)
     831             :         sharedir = copy( PREFIX "/share/fontforge" );
     832             : return( sharedir );
     833             : #else
     834             : return( NULL );
     835             : #endif
     836             :     }
     837           0 :     len = (pt-GResourceProgramDir)+strlen("/share/fontforge")+1;
     838           0 :     sharedir = malloc(len);
     839           0 :     strncpy(sharedir,GResourceProgramDir,pt-GResourceProgramDir);
     840           0 :     strcpy(sharedir+(pt-GResourceProgramDir),"/share/fontforge");
     841           0 : return( sharedir );
     842             : 
     843             : #endif
     844             : }
     845             : 
     846             : #  include <charset.h>            /* we still need the charsets & encoding to set local_encoding */
     847          80 : static int encmatch(const char *enc,int subok) {
     848             :     static struct { char *name; int enc; } encs[] = {
     849             :         { "US-ASCII", e_usascii },
     850             :         { "ASCII", e_usascii },
     851             :         { "ISO646-NO", e_iso646_no },
     852             :         { "ISO646-SE", e_iso646_se },
     853             :         { "LATIN10", e_iso8859_16 },
     854             :         { "LATIN1", e_iso8859_1 },
     855             :         { "ISO-8859-1", e_iso8859_1 },
     856             :         { "ISO-8859-2", e_iso8859_2 },
     857             :         { "ISO-8859-3", e_iso8859_3 },
     858             :         { "ISO-8859-4", e_iso8859_4 },
     859             :         { "ISO-8859-5", e_iso8859_4 },
     860             :         { "ISO-8859-6", e_iso8859_4 },
     861             :         { "ISO-8859-7", e_iso8859_4 },
     862             :         { "ISO-8859-8", e_iso8859_4 },
     863             :         { "ISO-8859-9", e_iso8859_4 },
     864             :         { "ISO-8859-10", e_iso8859_10 },
     865             :         { "ISO-8859-11", e_iso8859_11 },
     866             :         { "ISO-8859-13", e_iso8859_13 },
     867             :         { "ISO-8859-14", e_iso8859_14 },
     868             :         { "ISO-8859-15", e_iso8859_15 },
     869             :         { "ISO-8859-16", e_iso8859_16 },
     870             :         { "ISO_8859-1", e_iso8859_1 },
     871             :         { "ISO_8859-2", e_iso8859_2 },
     872             :         { "ISO_8859-3", e_iso8859_3 },
     873             :         { "ISO_8859-4", e_iso8859_4 },
     874             :         { "ISO_8859-5", e_iso8859_4 },
     875             :         { "ISO_8859-6", e_iso8859_4 },
     876             :         { "ISO_8859-7", e_iso8859_4 },
     877             :         { "ISO_8859-8", e_iso8859_4 },
     878             :         { "ISO_8859-9", e_iso8859_4 },
     879             :         { "ISO_8859-10", e_iso8859_10 },
     880             :         { "ISO_8859-11", e_iso8859_11 },
     881             :         { "ISO_8859-13", e_iso8859_13 },
     882             :         { "ISO_8859-14", e_iso8859_14 },
     883             :         { "ISO_8859-15", e_iso8859_15 },
     884             :         { "ISO_8859-16", e_iso8859_16 },
     885             :         { "ISO8859-1", e_iso8859_1 },
     886             :         { "ISO8859-2", e_iso8859_2 },
     887             :         { "ISO8859-3", e_iso8859_3 },
     888             :         { "ISO8859-4", e_iso8859_4 },
     889             :         { "ISO8859-5", e_iso8859_4 },
     890             :         { "ISO8859-6", e_iso8859_4 },
     891             :         { "ISO8859-7", e_iso8859_4 },
     892             :         { "ISO8859-8", e_iso8859_4 },
     893             :         { "ISO8859-9", e_iso8859_4 },
     894             :         { "ISO8859-10", e_iso8859_10 },
     895             :         { "ISO8859-11", e_iso8859_11 },
     896             :         { "ISO8859-13", e_iso8859_13 },
     897             :         { "ISO8859-14", e_iso8859_14 },
     898             :         { "ISO8859-15", e_iso8859_15 },
     899             :         { "ISO8859-16", e_iso8859_16 },
     900             :         { "ISO88591", e_iso8859_1 },
     901             :         { "ISO88592", e_iso8859_2 },
     902             :         { "ISO88593", e_iso8859_3 },
     903             :         { "ISO88594", e_iso8859_4 },
     904             :         { "ISO88595", e_iso8859_4 },
     905             :         { "ISO88596", e_iso8859_4 },
     906             :         { "ISO88597", e_iso8859_4 },
     907             :         { "ISO88598", e_iso8859_4 },
     908             :         { "ISO88599", e_iso8859_4 },
     909             :         { "ISO885910", e_iso8859_10 },
     910             :         { "ISO885911", e_iso8859_11 },
     911             :         { "ISO885913", e_iso8859_13 },
     912             :         { "ISO885914", e_iso8859_14 },
     913             :         { "ISO885915", e_iso8859_15 },
     914             :         { "ISO885916", e_iso8859_16 },
     915             :         { "8859_1", e_iso8859_1 },
     916             :         { "8859_2", e_iso8859_2 },
     917             :         { "8859_3", e_iso8859_3 },
     918             :         { "8859_4", e_iso8859_4 },
     919             :         { "8859_5", e_iso8859_4 },
     920             :         { "8859_6", e_iso8859_4 },
     921             :         { "8859_7", e_iso8859_4 },
     922             :         { "8859_8", e_iso8859_4 },
     923             :         { "8859_9", e_iso8859_4 },
     924             :         { "8859_10", e_iso8859_10 },
     925             :         { "8859_11", e_iso8859_11 },
     926             :         { "8859_13", e_iso8859_13 },
     927             :         { "8859_14", e_iso8859_14 },
     928             :         { "8859_15", e_iso8859_15 },
     929             :         { "8859_16", e_iso8859_16 },
     930             :         { "KOI8-R", e_koi8_r },
     931             :         { "KOI8R", e_koi8_r },
     932             :         { "WINDOWS-1252", e_win },
     933             :         { "CP1252", e_win },
     934             :         { "Big5", e_big5 },
     935             :         { "Big-5", e_big5 },
     936             :         { "BigFive", e_big5 },
     937             :         { "Big-Five", e_big5 },
     938             :         { "Big5HKSCS", e_big5hkscs },
     939             :         { "Big5-HKSCS", e_big5hkscs },
     940             :         { "UTF-8", e_utf8 },
     941             :         { "ISO-10646/UTF-8", e_utf8 },
     942             :         { "ISO_10646/UTF-8", e_utf8 },
     943             :         { "UCS2", e_unicode },
     944             :         { "UCS-2", e_unicode },
     945             :         { "UCS-2-INTERNAL", e_unicode },
     946             :         { "ISO-10646", e_unicode },
     947             :         { "ISO_10646", e_unicode },
     948             :         /* { "eucJP", e_euc }, */
     949             :         /* { "EUC-JP", e_euc }, */
     950             :         /* { "ujis", ??? }, */
     951             :         /* { "EUC-KR", e_euckorean }, */
     952             :         { NULL, 0 }
     953             :     };
     954             : 
     955             :     int i;
     956             :     char buffer[80];
     957             : #if HAVE_ICONV
     958             :     static char *last_complaint;
     959             : 
     960             :     iconv_t test;
     961          80 :     free(iconv_local_encoding_name);
     962          80 :     iconv_local_encoding_name= NULL;
     963             : #endif
     964             : 
     965          80 :     if ( strchr(enc,'@')!=NULL && strlen(enc)<sizeof(buffer)-1 ) {
     966           0 :         strcpy(buffer,enc);
     967           0 :         *strchr(buffer,'@') = '\0';
     968           0 :         enc = buffer;
     969             :     }
     970             : 
     971        8000 :     for ( i=0; encs[i].name!=NULL; ++i )
     972        7920 :         if ( strmatch(enc,encs[i].name)==0 )
     973           0 : return( encs[i].enc );
     974             : 
     975          80 :     if ( subok ) {
     976           0 :         for ( i=0; encs[i].name!=NULL; ++i )
     977           0 :             if ( strstrmatch(enc,encs[i].name)!=NULL )
     978           0 : return( encs[i].enc );
     979             : 
     980             : #if HAVE_ICONV
     981             :         /* I only try to use iconv if the encoding doesn't match one I support*/
     982             :         /*  loading iconv unicode data takes a while */
     983           0 :         test = iconv_open(enc,FindUnicharName());
     984           0 :         if ( test==(iconv_t) (-1) || test==NULL ) {
     985           0 :             if ( last_complaint==NULL || strcmp(last_complaint,enc)!=0 ) {
     986           0 :                 fprintf( stderr, "Neither FontForge nor iconv() supports your encoding (%s) we will pretend\n you asked for latin1 instead.\n", enc );
     987           0 :                 free( last_complaint );
     988           0 :                 last_complaint = copy(enc);
     989             :             }
     990             :         } else {
     991           0 :             if ( last_complaint==NULL || strcmp(last_complaint,enc)!=0 ) {
     992           0 :                 fprintf( stderr, "FontForge does not support your encoding (%s), it will try to use iconv()\n or it will pretend the local encoding is latin1\n", enc );
     993           0 :                 free( last_complaint );
     994           0 :                 last_complaint = copy(enc);
     995             :             }
     996           0 :             iconv_local_encoding_name= copy(enc);
     997           0 :             iconv_close(test);
     998             :         }
     999             : #else
    1000             :         fprintf( stderr, "FontForge does not support your encoding (%s), it will pretend the local encoding is latin1\n", enc );
    1001             : #endif
    1002             : 
    1003           0 : return( e_iso8859_1 );
    1004             :     }
    1005          80 : return( e_unknown );
    1006             : }
    1007             : 
    1008          40 : static int DefaultEncoding(void) {
    1009             :     const char *loc;
    1010             :     int enc;
    1011             : 
    1012             : #if HAVE_LANGINFO_H
    1013          40 :     loc = nl_langinfo(CODESET);
    1014          40 :     enc = encmatch(loc,false);
    1015          40 :     if ( enc!=e_unknown )
    1016           0 : return( enc );
    1017             : #endif
    1018          40 :     loc = getenv("LC_ALL");
    1019          40 :     if ( loc==NULL ) loc = getenv("LC_CTYPE");
    1020             :     /*if ( loc==NULL ) loc = getenv("LC_MESSAGES");*/
    1021          40 :     if ( loc==NULL ) loc = getenv("LANG");
    1022             : 
    1023          40 :     if ( loc==NULL )
    1024           0 : return( e_iso8859_1 );
    1025             : 
    1026          40 :     enc = encmatch(loc,false);
    1027          40 :     if ( enc==e_unknown ) {
    1028          40 :         loc = strrchr(loc,'.');
    1029          40 :         if ( loc==NULL )
    1030          40 : return( e_iso8859_1 );
    1031           0 :         enc = encmatch(loc+1,true);
    1032             :     }
    1033           0 :     if ( enc==e_unknown )
    1034           0 : return( e_iso8859_1 );
    1035             : 
    1036           0 : return( enc );
    1037             : }
    1038             : 
    1039          40 : static void DefaultXUID(void) {
    1040             :     /* Adobe has assigned PfaEdit a base XUID of 1021. Each new user is going */
    1041             :     /*  to get a couple of random numbers appended to that, hoping that will */
    1042             :     /*  make for a fairly safe system. */
    1043             :     /* FontForge will use the same scheme */
    1044             :     int r1, r2;
    1045             :     char buffer[50];
    1046             :     struct timeval tv;
    1047             : 
    1048          40 :     gettimeofday(&tv,NULL);
    1049          40 :     srand(tv.tv_usec);
    1050             :     do {
    1051          40 :         r1 = rand()&0x3ff;
    1052          40 :     } while ( r1==0 );          /* I reserve "0" for me! */
    1053          40 :     gettimeofday(&tv,NULL);
    1054          40 :     g_random_set_seed(tv.tv_usec+1);
    1055          40 :     r2 = g_random_int();
    1056          40 :     sprintf( buffer, "1021 %d %d", r1, r2 );
    1057          40 :     if (xuid != NULL) free(xuid);
    1058          40 :     xuid = copy(buffer);
    1059          40 : }
    1060             : 
    1061          40 : static void PrefsUI_SetDefaults(void) {
    1062             : 
    1063          40 :     DefaultXUID();
    1064          40 :     local_encoding = DefaultEncoding();
    1065          40 : }
    1066             : 
    1067           0 : static void ParseMacMapping(char *pt,struct macsettingname *ms) {
    1068             :     char *end;
    1069             : 
    1070           0 :     ms->mac_feature_type = strtol(pt,&end,10);
    1071           0 :     if ( *end==',' ) ++end;
    1072           0 :     ms->mac_feature_setting = strtol(end,&end,10);
    1073           0 :     if ( *end==' ' ) ++end;
    1074           0 :     ms->otf_tag =
    1075           0 :         ((end[0]&0xff)<<24) |
    1076           0 :         ((end[1]&0xff)<<16) |
    1077           0 :         ((end[2]&0xff)<<8) |
    1078           0 :         (end[3]&0xff);
    1079           0 : }
    1080             : 
    1081           0 : static void ParseNewMacFeature(FILE *p,char *line) {
    1082           0 :     fseek(p,-(strlen(line)-strlen("MacFeat:")),SEEK_CUR);
    1083           0 :     line[strlen("MacFeat:")] ='\0';
    1084           0 :     default_mac_feature_map = SFDParseMacFeatures(p,line);
    1085           0 :     fseek(p,-strlen(line),SEEK_CUR);
    1086           0 :     if ( user_mac_feature_map!=NULL )
    1087           0 :         MacFeatListFree(user_mac_feature_map);
    1088           0 :     user_mac_feature_map = default_mac_feature_map;
    1089           0 : }
    1090             : 
    1091          40 : static void PrefsUI_LoadPrefs_FromFile( char* filename )
    1092             : {
    1093             :     FILE *p;
    1094             :     char line[1100];
    1095          40 :     int i, j, ri=0, mn=0, ms=0, fn=0, ff=0, filt_max=0;
    1096          40 :     int msp=0, msc=0;
    1097             :     char *pt;
    1098             :     struct prefs_list *pl;
    1099             : 
    1100          40 :     if ( filename!=NULL && (p=fopen(filename,"r"))!=NULL ) {
    1101           0 :         while ( fgets(line,sizeof(line),p)!=NULL ) {
    1102           0 :             if ( *line=='#' )
    1103           0 :         continue;
    1104           0 :             pt = strchr(line,':');
    1105           0 :             if ( pt==NULL )
    1106           0 :         continue;
    1107           0 :             for ( j=0; load_prefs_list[j]!=NULL; ++j ) {
    1108           0 :                 for ( i=0; load_prefs_list[j][i].name!=NULL; ++i )
    1109           0 :                     if ( strncmp(line,load_prefs_list[j][i].name,pt-line)==0 )
    1110           0 :                 break;
    1111           0 :                 if ( load_prefs_list[j][i].name!=NULL )
    1112           0 :             break;
    1113             :             }
    1114           0 :             pl = NULL;
    1115           0 :             if ( load_prefs_list[j]!=NULL )
    1116           0 :                 pl = &load_prefs_list[j][i];
    1117           0 :             for ( ++pt; *pt=='\t'; ++pt );
    1118           0 :             if ( line[strlen(line)-1]=='\n' )
    1119           0 :                 line[strlen(line)-1] = '\0';
    1120           0 :             if ( line[strlen(line)-1]=='\r' )
    1121           0 :                 line[strlen(line)-1] = '\0';
    1122           0 :             if ( pl==NULL ) {
    1123           0 :                 if ( strncmp(line,"Recent:",strlen("Recent:"))==0 && ri<RECENT_MAX )
    1124           0 :                     RecentFiles[ri++] = copy(pt);
    1125           0 :                 else if ( strncmp(line,"MenuScript:",strlen("MenuScript:"))==0 && ms<SCRIPT_MENU_MAX )
    1126           0 :                     script_filenames[ms++] = copy(pt);
    1127           0 :                 else if ( strncmp(line,"MenuName:",strlen("MenuName:"))==0 && mn<SCRIPT_MENU_MAX )
    1128           0 :                     script_menu_names[mn++] = utf82u_copy(pt);
    1129           0 :                 else if ( strncmp(line,"FontFilterName:",strlen("FontFilterName:"))==0 ) {
    1130           0 :                     if ( fn>=filt_max )
    1131           0 :                         user_font_filters = realloc(user_font_filters,((filt_max+=10)+1)*sizeof( struct openfilefilters));
    1132           0 :                     user_font_filters[fn].filter = NULL;
    1133           0 :                     user_font_filters[fn++].name = copy(pt);
    1134           0 :                     user_font_filters[fn].name = NULL;
    1135           0 :                 } else if ( strncmp(line,"FontFilter:",strlen("FontFilter:"))==0 ) {
    1136           0 :                     if ( ff<filt_max )
    1137           0 :                         user_font_filters[ff++].filter = copy(pt);
    1138           0 :                 } else if ( strncmp(line,"MacMapCnt:",strlen("MacSetCnt:"))==0 ) {
    1139           0 :                     sscanf( pt, "%d", &msc );
    1140           0 :                     msp = 0;
    1141           0 :                     user_macfeat_otftag = calloc(msc+1,sizeof(struct macsettingname));
    1142           0 :                 } else if ( strncmp(line,"MacMapping:",strlen("MacMapping:"))==0 && msp<msc ) {
    1143           0 :                     ParseMacMapping(pt,&user_macfeat_otftag[msp++]);
    1144           0 :                 } else if ( strncmp(line,"MacFeat:",strlen("MacFeat:"))==0 ) {
    1145           0 :                     ParseNewMacFeature(p,line);
    1146             :                 }
    1147           0 :         continue;
    1148             :             }
    1149           0 :             switch ( pl->type ) {
    1150             :               case pr_encoding:
    1151           0 :                 { Encoding *enc = FindOrMakeEncoding(pt);
    1152           0 :                     if ( enc==NULL )
    1153           0 :                         enc = FindOrMakeEncoding("ISO8859-1");
    1154           0 :                     if ( enc==NULL )
    1155           0 :                         enc = &custom;
    1156           0 :                     *((Encoding **) (pl->val)) = enc;
    1157             :                 }
    1158           0 :               break;
    1159             :               case pr_namelist:
    1160           0 :                 { NameList *nl = NameListByName(pt);
    1161           0 :                     if ( strcmp(pt,"NULL")==0 && pl->val != &namelist_for_new_fonts )
    1162           0 :                         *((NameList **) (pl->val)) = NULL;
    1163           0 :                     else if ( nl!=NULL )
    1164           0 :                         *((NameList **) (pl->val)) = nl;
    1165             :                 }
    1166           0 :               break;
    1167             :               case pr_bool: case pr_int:
    1168           0 :                 sscanf( pt, "%d", (int *) pl->val );
    1169           0 :               break;
    1170             :               case pr_unicode:
    1171           0 :                 if ( sscanf( pt, "U+%x", (int *) pl->val )!=1 )
    1172           0 :                     if ( sscanf( pt, "u+%x", (int *) pl->val )!=1 )
    1173           0 :                         sscanf( pt, "%x", (int *) pl->val );
    1174           0 :               break;
    1175             :               case pr_real: case pr_angle:
    1176             :                 { char *end;
    1177           0 :                     *((float *) pl->val) = strtod(pt,&end);
    1178           0 :                     if (( *end==',' || *end=='.' ) ) {
    1179           0 :                         *end = (*end=='.')?',':'.';
    1180           0 :                         *((float *) pl->val) = strtod(pt,NULL);
    1181             :                     }
    1182             :                 }
    1183           0 :                 if ( pl->type == pr_angle )
    1184           0 :                     *(float *) pl->val /= RAD2DEG;
    1185           0 :               break;
    1186             :               case pr_string: case pr_file:
    1187           0 :                 if ( *pt=='\0' ) pt=NULL;
    1188           0 :                 if ( pl->val!=NULL )
    1189           0 :                     *((char **) (pl->val)) = copy(pt);
    1190             :                 else
    1191           0 :                     (pl->set)(copy(pt));
    1192           0 :               break;
    1193             :             }
    1194             :         }
    1195           0 :         fclose(p);
    1196             :     }
    1197          40 : }
    1198             : 
    1199          40 : void Prefs_LoadDefaultPreferences( void )
    1200             : {
    1201             :     char filename[PATH_MAX+1];
    1202          40 :     char* sharedir = getShareDir();
    1203             : 
    1204          40 :     snprintf(filename,PATH_MAX,"%s/prefs", sharedir );
    1205          40 :     PrefsUI_LoadPrefs_FromFile( filename );
    1206          40 : }
    1207             : 
    1208             : 
    1209           1 : static void PrefsUI_LoadPrefs(void)
    1210             : {
    1211           1 :     char *prefs = getPfaEditPrefs();
    1212             :     FILE *p;
    1213             :     char line[1100], path[PATH_MAX];
    1214           1 :     int i, j, ri=0, mn=0, ms=0, fn=0, ff=0, filt_max=0;
    1215           1 :     int msp=0, msc=0;
    1216           1 :     char *pt, *real_xdefs_filename = NULL;
    1217             :     struct prefs_list *pl;
    1218             : 
    1219           1 :     LoadPluginDir(NULL);
    1220           1 :     LoadPfaEditEncodings();
    1221           1 :     LoadGroupList();
    1222             : 
    1223           1 :     if ( prefs!=NULL && (p=fopen(prefs,"r"))!=NULL ) {
    1224           0 :         while ( fgets(line,sizeof(line),p)!=NULL ) {
    1225           0 :             if ( *line=='#' )
    1226           0 :         continue;
    1227           0 :             pt = strchr(line,':');
    1228           0 :             if ( pt==NULL )
    1229           0 :         continue;
    1230           0 :             for ( j=0; load_prefs_list[j]!=NULL; ++j ) {
    1231           0 :                 for ( i=0; load_prefs_list[j][i].name!=NULL; ++i )
    1232           0 :                     if ( strncmp(line,load_prefs_list[j][i].name,pt-line)==0 )
    1233           0 :                 break;
    1234           0 :                 if ( load_prefs_list[j][i].name!=NULL )
    1235           0 :             break;
    1236             :             }
    1237           0 :             pl = NULL;
    1238           0 :             if ( load_prefs_list[j]!=NULL )
    1239           0 :                 pl = &load_prefs_list[j][i];
    1240           0 :             for ( ++pt; *pt=='\t'; ++pt );
    1241           0 :             if ( line[strlen(line)-1]=='\n' )
    1242           0 :                 line[strlen(line)-1] = '\0';
    1243           0 :             if ( line[strlen(line)-1]=='\r' )
    1244           0 :                 line[strlen(line)-1] = '\0';
    1245           0 :             if ( pl==NULL ) {
    1246           0 :                 if ( strncmp(line,"Recent:",strlen("Recent:"))==0 && ri<RECENT_MAX )
    1247           0 :                     RecentFiles[ri++] = copy(pt);
    1248           0 :                 else if ( strncmp(line,"MenuScript:",strlen("MenuScript:"))==0 && ms<SCRIPT_MENU_MAX )
    1249           0 :                     script_filenames[ms++] = copy(pt);
    1250           0 :                 else if ( strncmp(line,"MenuName:",strlen("MenuName:"))==0 && mn<SCRIPT_MENU_MAX )
    1251           0 :                     script_menu_names[mn++] = utf82u_copy(pt);
    1252           0 :                 else if ( strncmp(line,"FontFilterName:",strlen("FontFilterName:"))==0 ) {
    1253           0 :                     if ( fn>=filt_max )
    1254           0 :                         user_font_filters = realloc(user_font_filters,((filt_max+=10)+1)*sizeof( struct openfilefilters));
    1255           0 :                     user_font_filters[fn].filter = NULL;
    1256           0 :                     user_font_filters[fn++].name = copy(pt);
    1257           0 :                     user_font_filters[fn].name = NULL;
    1258           0 :                 } else if ( strncmp(line,"FontFilter:",strlen("FontFilter:"))==0 ) {
    1259           0 :                     if ( ff<filt_max )
    1260           0 :                         user_font_filters[ff++].filter = copy(pt);
    1261           0 :                 } else if ( strncmp(line,"MacMapCnt:",strlen("MacSetCnt:"))==0 ) {
    1262           0 :                     sscanf( pt, "%d", &msc );
    1263           0 :                     msp = 0;
    1264           0 :                     user_macfeat_otftag = calloc(msc+1,sizeof(struct macsettingname));
    1265           0 :                 } else if ( strncmp(line,"MacMapping:",strlen("MacMapping:"))==0 && msp<msc ) {
    1266           0 :                     ParseMacMapping(pt,&user_macfeat_otftag[msp++]);
    1267           0 :                 } else if ( strncmp(line,"MacFeat:",strlen("MacFeat:"))==0 ) {
    1268           0 :                     ParseNewMacFeature(p,line);
    1269             :                 }
    1270           0 :         continue;
    1271             :             }
    1272           0 :             switch ( pl->type ) {
    1273             :               case pr_encoding:
    1274           0 :                 { Encoding *enc = FindOrMakeEncoding(pt);
    1275           0 :                     if ( enc==NULL )
    1276           0 :                         enc = FindOrMakeEncoding("ISO8859-1");
    1277           0 :                     if ( enc==NULL )
    1278           0 :                         enc = &custom;
    1279           0 :                     *((Encoding **) (pl->val)) = enc;
    1280             :                 }
    1281           0 :               break;
    1282             :               case pr_namelist:
    1283           0 :                 { NameList *nl = NameListByName(pt);
    1284           0 :                     if ( strcmp(pt,"NULL")==0 && pl->val != &namelist_for_new_fonts )
    1285           0 :                         *((NameList **) (pl->val)) = NULL;
    1286           0 :                     else if ( nl!=NULL )
    1287           0 :                         *((NameList **) (pl->val)) = nl;
    1288             :                 }
    1289           0 :               break;
    1290             :               case pr_bool: case pr_int:
    1291           0 :                 sscanf( pt, "%d", (int *) pl->val );
    1292           0 :               break;
    1293             :               case pr_unicode:
    1294           0 :                 if ( sscanf( pt, "U+%x", (int *) pl->val )!=1 )
    1295           0 :                     if ( sscanf( pt, "u+%x", (int *) pl->val )!=1 )
    1296           0 :                         sscanf( pt, "%x", (int *) pl->val );
    1297           0 :               break;
    1298             :               case pr_real: case pr_angle:
    1299             :                 { char *end;
    1300           0 :                     *((float *) pl->val) = strtod(pt,&end);
    1301           0 :                     if (( *end==',' || *end=='.' ) ) {
    1302           0 :                         *end = (*end=='.')?',':'.';
    1303           0 :                         *((float *) pl->val) = strtod(pt,NULL);
    1304             :                     }
    1305             :                 }
    1306           0 :                 if ( pl->type == pr_angle )
    1307           0 :                     *(float *) pl->val /= RAD2DEG;
    1308           0 :               break;
    1309             :               case pr_string: case pr_file:
    1310           0 :                 if ( *pt=='\0' ) pt=NULL;
    1311           0 :                 if ( pl->val!=NULL )
    1312           0 :                     *((char **) (pl->val)) = copy(pt);
    1313             :                 else
    1314           0 :                     (pl->set)(copy(pt));
    1315           0 :               break;
    1316             :             }
    1317             :         }
    1318           0 :         fclose(p);
    1319             :     }
    1320             : 
    1321             :     //
    1322             :     // If the user has no theme set, then use the default
    1323             :     //
    1324           1 :     real_xdefs_filename = xdefs_filename;
    1325           1 :     if ( !real_xdefs_filename )
    1326             :     {
    1327           1 :         fprintf(stderr,"no xdefs_filename!\n");
    1328           1 :         if (!quiet) {
    1329           1 :             fprintf(stderr,"TESTING: getPixmapDir:%s\n", getPixmapDir() );
    1330           1 :             fprintf(stderr,"TESTING: getShareDir:%s\n", getShareDir() );
    1331           1 :             fprintf(stderr,"TESTING: GResourceProgramDir:%s\n", GResourceProgramDir );
    1332             :         }
    1333           1 :         snprintf(path, PATH_MAX, "%s/%s", getPixmapDir(), "resources" );
    1334           1 :         if (!quiet)
    1335           1 :             fprintf(stderr,"trying default theme:%s\n", path );
    1336           1 :         real_xdefs_filename = path;
    1337             :     }
    1338           1 :     GResourceAddResourceFile(real_xdefs_filename,GResourceProgramName,true);
    1339             : 
    1340           1 :     if ( othersubrsfile!=NULL && ReadOtherSubrsFile(othersubrsfile)<=0 )
    1341           0 :         fprintf( stderr, "Failed to read OtherSubrs from %s\n", othersubrsfile );
    1342             : 
    1343           1 :     if ( glyph_2_name_map )
    1344           0 :         old_sfnt_flags |= ttf_flag_glyphmap;
    1345           1 :     LoadNamelistDir(NULL);
    1346           1 :     ProcessFileChooserPrefs();
    1347           1 :     GDrawEnableCairo( prefs_usecairo );
    1348           1 : }
    1349             : 
    1350          35 : static void PrefsUI_SavePrefs(int not_if_script) {
    1351          35 :     char *prefs = getPfaEditPrefs();
    1352             :     FILE *p;
    1353             :     int i, j;
    1354             :     char *temp;
    1355             :     struct prefs_list *pl;
    1356             :     extern int running_script;
    1357             : 
    1358          35 :     if ( prefs==NULL )
    1359           0 : return;
    1360          35 :     if ( not_if_script && running_script )
    1361          35 : return;
    1362             : 
    1363           0 :     if ( (p=fopen(prefs,"w"))==NULL )
    1364           0 : return;
    1365             : 
    1366           0 :     GetFileChooserPrefs();
    1367             : 
    1368           0 :     for ( j=0; prefs_list[j]!=NULL; ++j ) for ( i=0; prefs_list[j][i].name!=NULL; ++i ) {
    1369           0 :         pl = &prefs_list[j][i];
    1370           0 :         switch ( pl->type ) {
    1371             :           case pr_encoding:
    1372           0 :             fprintf( p, "%s:\t%s\n", pl->name, (*((Encoding **) (pl->val)))->enc_name );
    1373           0 :           break;
    1374             :           case pr_namelist:
    1375           0 :             fprintf( p, "%s:\t%s\n", pl->name, *((NameList **) (pl->val))==NULL ? "NULL" :
    1376           0 :                     (*((NameList **) (pl->val)))->title );
    1377           0 :           break;
    1378             :           case pr_bool: case pr_int:
    1379           0 :             fprintf( p, "%s:\t%d\n", pl->name, *(int *) (pl->val) );
    1380           0 :           break;
    1381             :           case pr_unicode:
    1382           0 :             fprintf( p, "%s:\tU+%04x\n", pl->name, *(int *) (pl->val) );
    1383           0 :           break;
    1384             :           case pr_real:
    1385           0 :             fprintf( p, "%s:\t%g\n", pl->name, (double) *(float *) (pl->val) );
    1386           0 :           break;
    1387             :           case pr_string: case pr_file:
    1388           0 :             if ( (pl->val)!=NULL )
    1389           0 :                 temp = *(char **) (pl->val);
    1390             :             else
    1391           0 :                 temp = (char *) (pl->get());
    1392           0 :             if ( temp!=NULL )
    1393           0 :                 fprintf( p, "%s:\t%s\n", pl->name, temp );
    1394           0 :             if ( (pl->val)==NULL )
    1395           0 :                 free(temp);
    1396           0 :           break;
    1397             :           case pr_angle:
    1398           0 :             fprintf( p, "%s:\t%g\n", pl->name, ((double) *(float *) pl->val) * RAD2DEG );
    1399           0 :           break;
    1400             :         }
    1401             :     }
    1402             : 
    1403           0 :     for ( i=0; i<RECENT_MAX && RecentFiles[i]!=NULL; ++i )
    1404           0 :         fprintf( p, "Recent:\t%s\n", RecentFiles[i]);
    1405           0 :     for ( i=0; i<SCRIPT_MENU_MAX && script_filenames[i]!=NULL; ++i ) {
    1406           0 :         fprintf( p, "MenuScript:\t%s\n", script_filenames[i]);
    1407           0 :         fprintf( p, "MenuName:\t%s\n", temp = u2utf8_copy(script_menu_names[i]));
    1408           0 :         free(temp);
    1409             :     }
    1410           0 :     if ( user_font_filters!=NULL ) {
    1411           0 :         for ( i=0; user_font_filters[i].name!=NULL; ++i ) {
    1412           0 :             fprintf( p, "FontFilterName:\t%s\n", user_font_filters[i].name);
    1413           0 :             fprintf( p, "FontFilter:\t%s\n", user_font_filters[i].filter);
    1414             :         }
    1415             :     }
    1416           0 :     if ( user_macfeat_otftag!=NULL && UserSettingsDiffer()) {
    1417           0 :         for ( i=0; user_macfeat_otftag[i].otf_tag!=0; ++i );
    1418           0 :         fprintf( p, "MacMapCnt: %d\n", i );
    1419           0 :         for ( i=0; user_macfeat_otftag[i].otf_tag!=0; ++i ) {
    1420           0 :             fprintf( p, "MacMapping: %d,%d %c%c%c%c\n",
    1421           0 :                     user_macfeat_otftag[i].mac_feature_type,
    1422           0 :                     user_macfeat_otftag[i].mac_feature_setting,
    1423           0 :                         (int) (user_macfeat_otftag[i].otf_tag>>24),
    1424           0 :                         (int) ((user_macfeat_otftag[i].otf_tag>>16)&0xff),
    1425           0 :                         (int) ((user_macfeat_otftag[i].otf_tag>>8)&0xff),
    1426           0 :                         (int) (user_macfeat_otftag[i].otf_tag&0xff) );
    1427             :         }
    1428             :     }
    1429             : 
    1430           0 :     if ( UserFeaturesDiffer())
    1431           0 :         SFDDumpMacFeat(p,default_mac_feature_map);
    1432             : 
    1433           0 :     fclose(p);
    1434             : }
    1435             : 
    1436             : struct pref_data {
    1437             :     int done;
    1438             :     struct prefs_list* plist;
    1439             : };
    1440             : 
    1441           0 : static int Prefs_ScriptBrowse(GGadget *g, GEvent *e) {
    1442           0 :     if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
    1443           0 :         GWindow gw = GGadgetGetWindow(g);
    1444           0 :         GGadget *tf = GWidgetGetControl(gw,GGadgetGetCid(g)-SCRIPT_MENU_MAX);
    1445           0 :         char *cur = GGadgetGetTitle8(tf); char *ret;
    1446             : 
    1447           0 :         if ( *cur=='\0' ) cur=NULL;
    1448           0 :         ret = gwwv_open_filename(_("Call Script"), cur, "*.pe", NULL);
    1449           0 :         free(cur);
    1450           0 :         if ( ret==NULL )
    1451           0 : return(true);
    1452           0 :         GGadgetSetTitle8(tf,ret);
    1453           0 :         free(ret);
    1454             :     }
    1455           0 : return( true );
    1456             : }
    1457             : 
    1458           0 : static int Prefs_BrowseFile(GGadget *g, GEvent *e) {
    1459           0 :     if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
    1460           0 :         GWindow gw = GGadgetGetWindow(g);
    1461           0 :         GGadget *tf = GWidgetGetControl(gw,GGadgetGetCid(g)-CID_PrefsBrowseOffset);
    1462           0 :         char *cur = GGadgetGetTitle8(tf); char *ret;
    1463           0 :         struct prefs_list *pl = GGadgetGetUserData(tf);
    1464             : 
    1465           0 :         ret = gwwv_open_filename(pl->name, *cur=='\0'? NULL : cur, NULL, NULL);
    1466           0 :         free(cur);
    1467           0 :         if ( ret==NULL )
    1468           0 : return(true);
    1469           0 :         GGadgetSetTitle8(tf,ret);
    1470           0 :         free(ret);
    1471             :     }
    1472           0 : return( true );
    1473             : }
    1474             : 
    1475           0 : static GTextInfo *Pref_MappingList(int use_user) {
    1476           0 :     struct macsettingname *msn = use_user && user_macfeat_otftag!=NULL ?
    1477           0 :             user_macfeat_otftag :
    1478             :             macfeat_otftag;
    1479             :     GTextInfo *ti;
    1480             :     int i;
    1481             :     char buf[60];
    1482             : 
    1483           0 :     for ( i=0; msn[i].otf_tag!=0; ++i );
    1484           0 :     ti = calloc(i+1,sizeof( GTextInfo ));
    1485             : 
    1486           0 :     for ( i=0; msn[i].otf_tag!=0; ++i ) {
    1487           0 :         sprintf(buf,"%3d,%2d %c%c%c%c",
    1488           0 :             msn[i].mac_feature_type, msn[i].mac_feature_setting,
    1489           0 :             (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) );
    1490           0 :         ti[i].text = uc_copy(buf);
    1491             :     }
    1492           0 : return( ti );
    1493             : }
    1494             : 
    1495           0 : void GListAddStr(GGadget *list,unichar_t *str, void *ud) {
    1496             :     int32 i,len;
    1497           0 :     GTextInfo **ti = GGadgetGetList(list,&len);
    1498           0 :     GTextInfo **replace = malloc((len+2)*sizeof(GTextInfo *));
    1499             : 
    1500           0 :     replace[len+1] = calloc(1,sizeof(GTextInfo));
    1501           0 :     for ( i=0; i<len; ++i ) {
    1502           0 :         replace[i] = malloc(sizeof(GTextInfo));
    1503           0 :         *replace[i] = *ti[i];
    1504           0 :         replace[i]->text = u_copy(ti[i]->text);
    1505             :     }
    1506           0 :     replace[i] = calloc(1,sizeof(GTextInfo));
    1507           0 :     replace[i]->fg = replace[i]->bg = COLOR_DEFAULT;
    1508           0 :     replace[i]->text = str;
    1509           0 :     replace[i]->userdata = ud;
    1510           0 :     GGadgetSetList(list,replace,false);
    1511           0 : }
    1512             : 
    1513           0 : void GListReplaceStr(GGadget *list,int index, unichar_t *str, void *ud) {
    1514             :     int32 i,len;
    1515           0 :     GTextInfo **ti = GGadgetGetList(list,&len);
    1516           0 :     GTextInfo **replace = malloc((len+2)*sizeof(GTextInfo *));
    1517             : 
    1518           0 :     for ( i=0; i<len; ++i ) {
    1519           0 :         replace[i] = malloc(sizeof(GTextInfo));
    1520           0 :         *replace[i] = *ti[i];
    1521           0 :         if ( i!=index )
    1522           0 :             replace[i]->text = u_copy(ti[i]->text);
    1523             :     }
    1524           0 :     replace[i] = calloc(1,sizeof(GTextInfo));
    1525           0 :     replace[index]->text = str;
    1526           0 :     replace[index]->userdata = ud;
    1527           0 :     GGadgetSetList(list,replace,false);
    1528           0 : }
    1529             : 
    1530             : struct setdata {
    1531             :     GWindow gw;
    1532             :     GGadget *list;
    1533             :     GGadget *flist;
    1534             :     GGadget *feature;
    1535             :     GGadget *set_code;
    1536             :     GGadget *otf;
    1537             :     GGadget *ok;
    1538             :     GGadget *cancel;
    1539             :     int index;
    1540             :     int done;
    1541             :     unichar_t *ret;
    1542             : };
    1543             : 
    1544           0 : static int set_e_h(GWindow gw, GEvent *event) {
    1545           0 :     struct setdata *sd = GDrawGetUserData(gw);
    1546             :     int i;
    1547             :     int32 len;
    1548             :     GTextInfo **ti;
    1549             :     const unichar_t *ret1; unichar_t *end;
    1550             :     int on, feat, val1, val2;
    1551             :     unichar_t ubuf[4];
    1552             :     char buf[40];
    1553             : 
    1554           0 :     if ( event->type==et_close ) {
    1555           0 :         sd->done = true;
    1556           0 :     } else if ( event->type==et_char ) {
    1557           0 :         if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) {
    1558           0 :             help("prefs.html#Features");
    1559           0 : return( true );
    1560             :         }
    1561           0 : return( false );
    1562           0 :     } else if ( event->type==et_controlevent && event->u.control.subtype == et_buttonactivate ) {
    1563           0 :         if ( event->u.control.g == sd->cancel ) {
    1564           0 :             sd->done = true;
    1565           0 :         } else if ( event->u.control.g == sd->ok ) {
    1566           0 :             ret1 = _GGadgetGetTitle(sd->set_code);
    1567           0 :             on = u_strtol(ret1,&end,10);
    1568           0 :             if ( *end!='\0' ) {
    1569           0 :                 ff_post_error(_("Bad Number"),_("Bad Number"));
    1570           0 : return( true );
    1571             :             }
    1572           0 :             ret1 = _GGadgetGetTitle(sd->feature);
    1573           0 :             feat = u_strtol(ret1,&end,10);
    1574           0 :             if ( *end!='\0' && *end!=' ' ) {
    1575           0 :                 ff_post_error(_("Bad Number"),_("Bad Number"));
    1576           0 : return( true );
    1577             :             }
    1578           0 :             ti = GGadgetGetList(sd->list,&len);
    1579           0 :             for ( i=0; i<len; ++i ) if ( i!=sd->index ) {
    1580           0 :                 val1 = u_strtol(ti[i]->text,&end,10);
    1581           0 :                 val2 = u_strtol(end+1,NULL,10);
    1582           0 :                 if ( val1==feat && val2==on ) {
    1583             :                     static char *buts[3];
    1584           0 :                     buts[0] = _("_Yes");
    1585           0 :                     buts[1] = _("_No");
    1586           0 :                     buts[2] = NULL;
    1587           0 :                     if ( gwwv_ask(_("This feature, setting combination is already used"),(const char **) buts,0,1,
    1588           0 :                             _("This feature, setting combination is already used\nDo you really wish to reuse it?"))==1 )
    1589           0 : return( true );
    1590             :                 }
    1591             :             }
    1592             : 
    1593           0 :             ret1 = _GGadgetGetTitle(sd->otf);
    1594           0 :             if ( (ubuf[0] = ret1[0])==0 )
    1595           0 :                 ubuf[0] = ubuf[1] = ubuf[2] = ubuf[3] = ' ';
    1596           0 :             else if ( (ubuf[1] = ret1[1])==0 )
    1597           0 :                 ubuf[1] = ubuf[2] = ubuf[3] = ' ';
    1598           0 :             else if ( (ubuf[2] = ret1[2])==0 )
    1599           0 :                 ubuf[2] = ubuf[3] = ' ';
    1600           0 :             else if ( (ubuf[3] = ret1[3])==0 )
    1601           0 :                 ubuf[3] = ' ';
    1602           0 :             len = u_strlen(ret1);
    1603           0 :             if ( len<2 || len>4 || ubuf[0]>=0x7f || ubuf[1]>=0x7f || ubuf[2]>=0x7f || ubuf[3]>=0x7f ) {
    1604           0 :                 ff_post_error(_("Tag too long"),_("Feature tags must be exactly 4 ASCII characters"));
    1605           0 : return( true );
    1606             :             }
    1607           0 :             sprintf(buf,"%3d,%2d %c%c%c%c",
    1608             :                     feat, on,
    1609             :                     ubuf[0], ubuf[1], ubuf[2], ubuf[3]);
    1610           0 :             sd->done = true;
    1611           0 :             sd->ret = uc_copy(buf);
    1612             :         }
    1613             :     }
    1614           0 : return( true );
    1615             : }
    1616             : 
    1617           0 : static unichar_t *AskSetting(struct macsettingname *temp,GGadget *list, int index,GGadget *flist) {
    1618             :     GRect pos;
    1619             :     GWindow gw;
    1620             :     GWindowAttrs wattrs;
    1621             :     GGadgetCreateData gcd[17];
    1622             :     GTextInfo label[17];
    1623             :     struct setdata sd;
    1624             :     char buf[20];
    1625             :     unichar_t ubuf3[6];
    1626             :     int32 len, i;
    1627             :     GTextInfo **ti;
    1628             : 
    1629           0 :     memset(&sd,0,sizeof(sd));
    1630           0 :     sd.list = list;
    1631           0 :     sd.flist = flist;
    1632           0 :     sd.index = index;
    1633             : 
    1634           0 :     memset(&wattrs,0,sizeof(wattrs));
    1635           0 :     wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_restrict|wam_isdlg;
    1636           0 :     wattrs.event_masks = ~(1<<et_charup);
    1637           0 :     wattrs.restrict_input_to_me = 1;
    1638           0 :     wattrs.is_dlg = 1;
    1639           0 :     wattrs.undercursor = 1;
    1640           0 :     wattrs.cursor = ct_pointer;
    1641           0 :     wattrs.utf8_window_title = _("Mapping");
    1642           0 :     pos.x = pos.y = 0;
    1643           0 :     pos.width = GGadgetScale(GDrawPointsToPixels(NULL,240));
    1644           0 :     pos.height = GDrawPointsToPixels(NULL,120);
    1645           0 :     gw = GDrawCreateTopWindow(NULL,&pos,set_e_h,&sd,&wattrs);
    1646           0 :     sd.gw = gw;
    1647             : 
    1648           0 :     memset(gcd,0,sizeof(gcd));
    1649           0 :     memset(label,0,sizeof(label));
    1650             : 
    1651           0 :     label[0].text = (unichar_t *) _("_Feature:");
    1652           0 :     label[0].text_is_1byte = true;
    1653           0 :     label[0].text_in_resource = true;
    1654           0 :     gcd[0].gd.label = &label[0];
    1655           0 :     gcd[0].gd.pos.x = 5; gcd[0].gd.pos.y = 5+4;
    1656           0 :     gcd[0].gd.flags = gg_enabled|gg_visible;
    1657           0 :     gcd[0].creator = GLabelCreate;
    1658             : 
    1659           0 :     gcd[1].gd.pos.x = 50; gcd[1].gd.pos.y = 5; gcd[1].gd.pos.width = 170;
    1660           0 :     gcd[1].gd.flags = gg_enabled|gg_visible;
    1661           0 :     gcd[1].creator = GListButtonCreate;
    1662             : 
    1663           0 :     label[2].text = (unichar_t *) _("Setting");
    1664           0 :     label[2].text_is_1byte = true;
    1665           0 :     gcd[2].gd.label = &label[2];
    1666           0 :     gcd[2].gd.pos.x = 5; gcd[2].gd.pos.y = gcd[0].gd.pos.y+26;
    1667           0 :     gcd[2].gd.flags = gg_enabled|gg_visible;
    1668           0 :     gcd[2].creator = GLabelCreate;
    1669             : 
    1670           0 :     sprintf( buf, "%d", temp->mac_feature_setting );
    1671           0 :     label[3].text = (unichar_t *) buf;
    1672           0 :     label[3].text_is_1byte = true;
    1673           0 :     gcd[3].gd.label = &label[3];
    1674           0 :     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;
    1675           0 :     gcd[3].gd.flags = gg_enabled|gg_visible;
    1676           0 :     gcd[3].creator = GTextFieldCreate;
    1677             : 
    1678           0 :     label[4].text = (unichar_t *) _("_Tag:");
    1679           0 :     label[4].text_is_1byte = true;
    1680           0 :     label[4].text_in_resource = true;
    1681           0 :     gcd[4].gd.label = &label[4];
    1682           0 :     gcd[4].gd.pos.x = 5; gcd[4].gd.pos.y = gcd[3].gd.pos.y+26;
    1683           0 :     gcd[4].gd.flags = gg_enabled|gg_visible;
    1684           0 :     gcd[4].creator = GLabelCreate;
    1685             : 
    1686           0 :     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;
    1687           0 :     label[5].text = ubuf3;
    1688           0 :     gcd[5].gd.label = &label[5];
    1689           0 :     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;
    1690           0 :     gcd[5].gd.flags = gg_enabled|gg_visible;
    1691             :     /*gcd[5].gd.u.list = tags;*/
    1692           0 :     gcd[5].creator = GTextFieldCreate;
    1693             : 
    1694           0 :     gcd[6].gd.pos.x = 13-3; gcd[6].gd.pos.y = gcd[5].gd.pos.y+30;
    1695           0 :     gcd[6].gd.pos.width = -1; gcd[6].gd.pos.height = 0;
    1696           0 :     gcd[6].gd.flags = gg_visible | gg_enabled | gg_but_default;
    1697           0 :     label[6].text = (unichar_t *) _("_OK");
    1698           0 :     label[6].text_is_1byte = true;
    1699           0 :     label[6].text_in_resource = true;
    1700           0 :     gcd[6].gd.label = &label[6];
    1701             :     /*gcd[6].gd.handle_controlevent = Prefs_Ok;*/
    1702           0 :     gcd[6].creator = GButtonCreate;
    1703             : 
    1704           0 :     gcd[7].gd.pos.x = -13; gcd[7].gd.pos.y = gcd[7-1].gd.pos.y+3;
    1705           0 :     gcd[7].gd.pos.width = -1; gcd[7].gd.pos.height = 0;
    1706           0 :     gcd[7].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
    1707           0 :     label[7].text = (unichar_t *) _("_Cancel");
    1708           0 :     label[7].text_is_1byte = true;
    1709           0 :     label[7].text_in_resource = true;
    1710           0 :     gcd[7].gd.label = &label[7];
    1711           0 :     gcd[7].creator = GButtonCreate;
    1712             : 
    1713           0 :     GGadgetsCreate(gw,gcd);
    1714           0 :     sd.feature = gcd[1].ret;
    1715           0 :     sd.set_code = gcd[3].ret;
    1716           0 :     sd.otf = gcd[5].ret;
    1717           0 :     sd.ok = gcd[6].ret;
    1718           0 :     sd.cancel = gcd[7].ret;
    1719             : 
    1720           0 :     ti = GGadgetGetList(flist,&len);
    1721           0 :     GGadgetSetList(sd.feature,ti,true);
    1722           0 :     for ( i=0; i<len; ++i ) {
    1723           0 :         int val = u_strtol(ti[i]->text,NULL,10);
    1724           0 :         if ( val==temp->mac_feature_type ) {
    1725           0 :             GGadgetSetTitle(sd.feature,ti[i]->text);
    1726           0 :     break;
    1727             :         }
    1728             :     }
    1729             : 
    1730           0 :     GDrawSetVisible(gw,true);
    1731           0 :     GWidgetIndicateFocusGadget(gcd[1].ret);
    1732           0 :     while ( !sd.done )
    1733           0 :         GDrawProcessOneEvent(NULL);
    1734           0 :     GDrawDestroyWindow(gw);
    1735             : 
    1736           0 : return( sd.ret );
    1737             : }
    1738             : 
    1739           0 : static void ChangeSetting(GGadget *list,int index,GGadget *flist) {
    1740             :     struct macsettingname temp;
    1741             :     int32 len;
    1742           0 :     GTextInfo **ti = GGadgetGetList(list,&len);
    1743             :     char *str;
    1744             :     unichar_t *ustr;
    1745             : 
    1746           0 :     str = cu_copy(ti[index]->text);
    1747           0 :     ParseMacMapping(str,&temp);
    1748           0 :     free(str);
    1749           0 :     if ( (ustr=AskSetting(&temp,list,index,flist))==NULL )
    1750           0 : return;
    1751           0 :     GListReplaceStr(list,index,ustr,NULL);
    1752             : }
    1753             : 
    1754           0 : static int Pref_NewMapping(GGadget *g, GEvent *e) {
    1755           0 :     if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
    1756           0 :         GWindow gw = GGadgetGetWindow(g);
    1757           0 :         GGadget *list = GWidgetGetControl(gw,CID_Mapping);
    1758           0 :         GGadget *flist = GWidgetGetControl(GDrawGetParentWindow(gw),CID_Features);
    1759             :         struct macsettingname temp;
    1760             :         unichar_t *str;
    1761             : 
    1762           0 :         memset(&temp,0,sizeof(temp));
    1763           0 :         temp.mac_feature_type = -1;
    1764           0 :         if ( (str=AskSetting(&temp,list,-1,flist))==NULL )
    1765           0 : return( true );
    1766           0 :         GListAddStr(list,str,NULL);
    1767             :         /*free(str);*/
    1768             :     }
    1769           0 : return( true );
    1770             : }
    1771             : 
    1772           0 : static int Pref_DelMapping(GGadget *g, GEvent *e) {
    1773           0 :     if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
    1774           0 :         GWindow gw = GGadgetGetWindow(g);
    1775           0 :         GListDelSelected(GWidgetGetControl(gw,CID_Mapping));
    1776           0 :         GGadgetSetEnabled(GWidgetGetControl(gw,CID_MappingDel),false);
    1777           0 :         GGadgetSetEnabled(GWidgetGetControl(gw,CID_MappingEdit),false);
    1778             :     }
    1779           0 : return( true );
    1780             : }
    1781             : 
    1782           0 : static int Pref_EditMapping(GGadget *g, GEvent *e) {
    1783           0 :     if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
    1784           0 :         GWindow gw = GDrawGetParentWindow(GGadgetGetWindow(g));
    1785           0 :         GGadget *list = GWidgetGetControl(gw,CID_Mapping);
    1786           0 :         GGadget *flist = GWidgetGetControl(gw,CID_Features);
    1787           0 :         ChangeSetting(list,GGadgetGetFirstListSelectedItem(list),flist);
    1788             :     }
    1789           0 : return( true );
    1790             : }
    1791             : 
    1792           0 : static int Pref_MappingSel(GGadget *g, GEvent *e) {
    1793           0 :     if ( e->type==et_controlevent && e->u.control.subtype == et_listselected ) {
    1794             :         int32 len;
    1795           0 :         GTextInfo **ti = GGadgetGetList(g,&len);
    1796           0 :         GWindow gw = GGadgetGetWindow(g);
    1797           0 :         int i, sel_cnt=0;
    1798           0 :         for ( i=0; i<len; ++i )
    1799           0 :             if ( ti[i]->selected ) ++sel_cnt;
    1800           0 :         GGadgetSetEnabled(GWidgetGetControl(gw,CID_MappingDel),sel_cnt!=0);
    1801           0 :         GGadgetSetEnabled(GWidgetGetControl(gw,CID_MappingEdit),sel_cnt==1);
    1802           0 :     } else if ( e->type==et_controlevent && e->u.control.subtype == et_listdoubleclick ) {
    1803           0 :         GGadget *flist = GWidgetGetControl( GDrawGetParentWindow(GGadgetGetWindow(g)),CID_Features);
    1804           0 :         ChangeSetting(g,e->u.control.u.list.changed_index!=-1?e->u.control.u.list.changed_index:
    1805             :                 GGadgetGetFirstListSelectedItem(g),flist);
    1806             :     }
    1807           0 : return( true );
    1808             : }
    1809             : 
    1810           0 : static int Pref_DefaultMapping(GGadget *g, GEvent *e) {
    1811           0 :     if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
    1812           0 :         GGadget *list = GWidgetGetControl(GGadgetGetWindow(g),CID_Mapping);
    1813             :         GTextInfo *ti, **arr;
    1814             :         uint16 cnt;
    1815             : 
    1816           0 :         ti = Pref_MappingList(false);
    1817           0 :         arr = GTextInfoArrayFromList(ti,&cnt);
    1818           0 :         GGadgetSetList(list,arr,false);
    1819           0 :         GTextInfoListFree(ti);
    1820             :     }
    1821           0 : return( true );
    1822             : }
    1823             : 
    1824           0 : static int Prefs_Ok(GGadget *g, GEvent *e) {
    1825             :     int i, j, mi;
    1826           0 :     int err=0, enc;
    1827             :     struct pref_data *p;
    1828             :     GWindow gw;
    1829             :     const unichar_t *ret;
    1830             :     const unichar_t *names[SCRIPT_MENU_MAX], *scripts[SCRIPT_MENU_MAX];
    1831             :     struct prefs_list *pl;
    1832             :     GTextInfo **list;
    1833             :     int32 len;
    1834             :     int maxl, t;
    1835             :     char *str;
    1836             :     real dangle;
    1837             : 
    1838           0 :     if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
    1839           0 :         gw = GGadgetGetWindow(g);
    1840           0 :         p = GDrawGetUserData(gw);
    1841           0 :         for ( i=0; i<SCRIPT_MENU_MAX; ++i ) {
    1842           0 :             names[i] = _GGadgetGetTitle(GWidgetGetControl(gw,CID_ScriptMNameBase+i));
    1843           0 :             scripts[i] = _GGadgetGetTitle(GWidgetGetControl(gw,CID_ScriptMFileBase+i));
    1844           0 :             if ( *names[i]=='\0' ) names[i] = NULL;
    1845           0 :             if ( *scripts[i]=='\0' ) scripts[i] = NULL;
    1846           0 :             if ( scripts[i]==NULL && names[i]!=NULL ) {
    1847           0 :                 ff_post_error(_("Menu name with no associated script"),_("Menu name with no associated script"));
    1848           0 : return( true );
    1849           0 :             } else if ( scripts[i]!=NULL && names[i]==NULL ) {
    1850           0 :                 ff_post_error(_("Script with no associated menu name"),_("Script with no associated menu name"));
    1851           0 : return( true );
    1852             :             }
    1853             :         }
    1854           0 :         for ( i=mi=0; i<SCRIPT_MENU_MAX; ++i ) {
    1855           0 :             if ( names[i]!=NULL ) {
    1856           0 :                 names[mi] = names[i];
    1857           0 :                 scripts[mi] = scripts[i];
    1858           0 :                 ++mi;
    1859             :             }
    1860             :         }
    1861           0 :         for ( j=0; visible_prefs_list[j].tab_name!=0; ++j ) for ( i=0; visible_prefs_list[j].pl[i].name!=NULL; ++i ) {
    1862           0 :             pl = &visible_prefs_list[j].pl[i];
    1863             :             /* before assigning values, check for any errors */
    1864             :             /* if any errors, then NO values should be assigned, in case they cancel */
    1865           0 :             if ( pl->dontdisplay )
    1866           0 :         continue;
    1867           0 :             if ( pl->type==pr_int ) {
    1868           0 :                 GetInt8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
    1869           0 :             } else if ( pl->type==pr_real ) {
    1870           0 :                 GetReal8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
    1871           0 :             } else if ( pl->type==pr_angle ) {
    1872           0 :                 dangle = GetReal8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
    1873           0 :                 if ( dangle > 90 || dangle < 0 ) {
    1874           0 :                     GGadgetProtest8(pl->name);
    1875           0 :                     err = true;
    1876             :                 }
    1877           0 :             } else if ( pl->type==pr_unicode ) {
    1878           0 :                 GetUnicodeChar8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
    1879             :             }
    1880             :         }
    1881           0 :         if ( err )
    1882           0 : return( true );
    1883             : 
    1884           0 :         for ( j=0; visible_prefs_list[j].tab_name!=0; ++j ) for ( i=0; visible_prefs_list[j].pl[i].name!=NULL; ++i ) {
    1885           0 :             pl = &visible_prefs_list[j].pl[i];
    1886           0 :             if ( pl->dontdisplay )
    1887           0 :         continue;
    1888           0 :             switch( pl->type ) {
    1889             :               case pr_int:
    1890           0 :                 *((int *) (pl->val)) = GetInt8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
    1891           0 :               break;
    1892             :               case pr_unicode:
    1893           0 :                 *((int *) (pl->val)) = GetUnicodeChar8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
    1894           0 :               break;
    1895             :               case pr_bool:
    1896           0 :                 *((int *) (pl->val)) = GGadgetIsChecked(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
    1897           0 :               break;
    1898             :               case pr_real:
    1899           0 :                 *((float *) (pl->val)) = GetReal8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
    1900           0 :               break;
    1901             :               case pr_encoding:
    1902             :                 { Encoding *e;
    1903           0 :                     e = ParseEncodingNameFromList(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
    1904           0 :                     if ( e!=NULL )
    1905           0 :                         *((Encoding **) (pl->val)) = e;
    1906           0 :                     enc = 1;    /* So gcc doesn't complain about unused. It is unused, but why add the ifdef and make the code even messier? Sigh. icc complains anyway */
    1907             :                 }
    1908           0 :               break;
    1909             :               case pr_namelist:
    1910             :                 { NameList *nl;
    1911           0 :                   GTextInfo *ti = GGadgetGetListItemSelected(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
    1912           0 :                   if ( ti!=NULL ) {
    1913           0 :                         char *name = u2utf8_copy(ti->text);
    1914           0 :                         nl = NameListByName(name);
    1915           0 :                         free(name);
    1916           0 :                         if ( nl!=NULL && nl->uses_unicode && !allow_utf8_glyphnames)
    1917           0 :                             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."));
    1918           0 :                         else if ( nl!=NULL )
    1919           0 :                             *((NameList **) (pl->val)) = nl;
    1920             :                     }
    1921             :                 }
    1922           0 :               break;
    1923             :               case pr_string: case pr_file:
    1924           0 :                 ret = _GGadgetGetTitle(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
    1925           0 :                 if ( pl->val!=NULL ) {
    1926           0 :                     free( *((char **) (pl->val)) );
    1927           0 :                     *((char **) (pl->val)) = NULL;
    1928           0 :                     if ( ret!=NULL && *ret!='\0' )
    1929           0 :                         *((char **) (pl->val)) = /* u2def_*/ cu_copy(ret);
    1930             :                 } else {
    1931           0 :                     char *cret = cu_copy(ret);
    1932           0 :                     (pl->set)(cret);
    1933           0 :                     free(cret);
    1934             :                 }
    1935           0 :               break;
    1936             :               case pr_angle:
    1937           0 :                 *((float *) (pl->val)) = GetReal8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err)/RAD2DEG;
    1938           0 :               break;
    1939             :             }
    1940             :         }
    1941           0 :         for ( i=0; i<SCRIPT_MENU_MAX; ++i ) {
    1942           0 :             free(script_menu_names[i]); script_menu_names[i] = NULL;
    1943           0 :             free(script_filenames[i]); script_filenames[i] = NULL;
    1944             :         }
    1945           0 :         for ( i=0; i<mi; ++i ) {
    1946           0 :             script_menu_names[i] = u_copy(names[i]);
    1947           0 :             script_filenames[i] = u2def_copy(scripts[i]);
    1948             :         }
    1949             : 
    1950           0 :         list = GGadgetGetList(GWidgetGetControl(gw,CID_Mapping),&len);
    1951           0 :         UserSettingsFree();
    1952           0 :         user_macfeat_otftag = malloc((len+1)*sizeof(struct macsettingname));
    1953           0 :         user_macfeat_otftag[len].otf_tag = 0;
    1954           0 :         maxl = 0;
    1955           0 :         for ( i=0; i<len; ++i ) {
    1956           0 :             t = u_strlen(list[i]->text);
    1957           0 :             if ( t>maxl ) maxl = t;
    1958             :         }
    1959           0 :         str = malloc(maxl+3);
    1960           0 :         for ( i=0; i<len; ++i ) {
    1961           0 :             u2encoding_strncpy(str,list[i]->text,maxl+1,e_mac);
    1962           0 :             ParseMacMapping(str,&user_macfeat_otftag[i]);
    1963             :         }
    1964           0 :         free(str);
    1965             : 
    1966           0 :         Prefs_ReplaceMacFeatures(GWidgetGetControl(gw,CID_Features));
    1967             : 
    1968           0 :         if ( xuid!=NULL ) {
    1969             :             char *pt;
    1970           0 :             for ( pt=xuid; *pt==' ' ; ++pt );
    1971           0 :             if ( *pt=='[' ) {   /* People who know PS well, might want to put brackets arround the xuid base array, but I don't want them */
    1972           0 :                 pt = copy(pt+1);
    1973           0 :                 if (xuid != NULL) free( xuid );
    1974           0 :                 xuid = pt;
    1975             :             }
    1976           0 :             for ( pt=xuid+strlen(xuid)-1; pt>xuid && *pt==' '; --pt );
    1977           0 :             if ( pt >= xuid && *pt==']' ) *pt = '\0';
    1978             :         }
    1979             : 
    1980           0 :         p->done = true;
    1981           0 :         PrefsUI_SavePrefs(true);
    1982           0 :         if ( maxundoes==0 ) { FontView *fv;
    1983           0 :             for ( fv=fv_list ; fv!=NULL; fv=(FontView *) (fv->b.next) )
    1984           0 :                 SFRemoveUndoes(fv->b.sf,NULL,NULL);
    1985             :         }
    1986           0 :         if ( othersubrsfile!=NULL && ReadOtherSubrsFile(othersubrsfile)<=0 )
    1987           0 :             fprintf( stderr, "Failed to read OtherSubrs from %s\n", othersubrsfile );
    1988           0 :         GDrawEnableCairo(prefs_usecairo);
    1989             : 
    1990           0 :         int force_redraw_charviews = 0;
    1991           0 :         if( prefs_oldval_cvEditHandleSize != prefs_cvEditHandleSize )
    1992           0 :             force_redraw_charviews = 1;
    1993           0 :         if( prefs_oldval_cvInactiveHandleAlpha != prefs_cvInactiveHandleAlpha )
    1994           0 :             force_redraw_charviews = 1;
    1995             : 
    1996             : 
    1997           0 :         if( force_redraw_charviews )
    1998             :         {
    1999             :             FontView *fv;
    2000           0 :             for ( fv=fv_list ; fv!=NULL; fv=(FontView *) (fv->b.next) )
    2001             :             {
    2002           0 :                 FVRedrawAllCharViews( fv );
    2003             :             }
    2004             :         }
    2005             :     }
    2006           0 : return( true );
    2007             : }
    2008             : 
    2009           0 : static int Prefs_Cancel(GGadget *g, GEvent *e) {
    2010           0 :     if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
    2011           0 :         struct pref_data *p = GDrawGetUserData(GGadgetGetWindow(g));
    2012           0 :         MacFeatListFree(GGadgetGetUserData((GWidgetGetControl(
    2013             :                 GGadgetGetWindow(g),CID_Features))));
    2014           0 :         p->done = true;
    2015             :     }
    2016           0 : return( true );
    2017             : }
    2018             : 
    2019           0 : static int e_h(GWindow gw, GEvent *event) {
    2020           0 :     if ( event->type==et_close ) {
    2021           0 :         struct pref_data *p = GDrawGetUserData(gw);
    2022           0 :         p->done = true;
    2023           0 :         if(GWidgetGetControl(gw,CID_Features)) {
    2024           0 :             MacFeatListFree(GGadgetGetUserData((GWidgetGetControl(gw,CID_Features))));
    2025             :         }
    2026           0 :     } else if ( event->type==et_char ) {
    2027           0 :         if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) {
    2028           0 :             help("prefs.html");
    2029           0 : return( true );
    2030             :         }
    2031           0 : return( false );
    2032             :     }
    2033           0 : return( true );
    2034             : }
    2035             : 
    2036           0 : static void PrefsInit(void) {
    2037             :     static int done = false;
    2038             :     int i;
    2039             : 
    2040           0 :     if ( done )
    2041           0 : return;
    2042           0 :     done = true;
    2043           0 :     for ( i=0; visible_prefs_list[i].tab_name!=NULL; ++i )
    2044           0 :         visible_prefs_list[i].tab_name = _(visible_prefs_list[i].tab_name);
    2045             : }
    2046             : 
    2047           0 : void DoPrefs(void) {
    2048             :     GRect pos;
    2049             :     GWindow gw;
    2050             :     GWindowAttrs wattrs;
    2051             :     GGadgetCreateData *pgcd, gcd[5], sgcd[45], mgcd[3], mfgcd[9], msgcd[9];
    2052             :     GGadgetCreateData mfboxes[3], *mfarray[14];
    2053             :     GGadgetCreateData mpboxes[3], *mparray[14];
    2054             :     GGadgetCreateData sboxes[2], *sarray[50];
    2055             :     GGadgetCreateData mboxes[3], *varray[5], *harray[8];
    2056             :     GTextInfo *plabel, **list, label[5], slabel[45], *plabels[TOPICS+5], mflabels[9], mslabels[9];
    2057             :     GTabInfo aspects[TOPICS+5], subaspects[3];
    2058             :     GGadgetCreateData **hvarray, boxes[2*TOPICS];
    2059             :     struct pref_data p;
    2060             :     int i, gc, sgc, j, k, line, line_max, y, y2, ii, si;
    2061             :     int32 llen;
    2062             :     char buf[20];
    2063             :     int gcnt[20];
    2064             :     static unichar_t nullstr[] = { 0 };
    2065             :     struct prefs_list *pl;
    2066             :     char *tempstr;
    2067             :     FontRequest rq;
    2068             :     GFont *font;
    2069             : 
    2070           0 :     PrefsInit();
    2071             : 
    2072           0 :     MfArgsInit();
    2073           0 :     for ( k=line_max=0; visible_prefs_list[k].tab_name!=0; ++k ) {
    2074           0 :         for ( i=line=gcnt[k]=0; visible_prefs_list[k].pl[i].name!=NULL; ++i ) {
    2075           0 :             if ( visible_prefs_list[k].pl[i].dontdisplay )
    2076           0 :         continue;
    2077           0 :             gcnt[k] += 2;
    2078           0 :             if ( visible_prefs_list[k].pl[i].type==pr_bool ) ++gcnt[k];
    2079           0 :             else if ( visible_prefs_list[k].pl[i].type==pr_file ) ++gcnt[k];
    2080           0 :             else if ( visible_prefs_list[k].pl[i].type==pr_angle ) ++gcnt[k];
    2081           0 :             ++line;
    2082             :         }
    2083           0 :         if ( visible_prefs_list[k].pl == args_list ) {
    2084           0 :             gcnt[k] += 6;
    2085           0 :             line += 6;
    2086             :         }
    2087           0 :         if ( line>line_max ) line_max = line;
    2088             :     }
    2089             : 
    2090           0 :     prefs_oldval_cvEditHandleSize = prefs_cvEditHandleSize;
    2091           0 :     prefs_oldval_cvInactiveHandleAlpha = prefs_cvInactiveHandleAlpha;
    2092             : 
    2093           0 :     memset(&p,'\0',sizeof(p));
    2094           0 :     memset(&wattrs,0,sizeof(wattrs));
    2095           0 :     wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_restrict|wam_isdlg;
    2096           0 :     wattrs.event_masks = ~(1<<et_charup);
    2097           0 :     wattrs.restrict_input_to_me = 1;
    2098           0 :     wattrs.is_dlg = 1;
    2099           0 :     wattrs.undercursor = 1;
    2100           0 :     wattrs.cursor = ct_pointer;
    2101           0 :     wattrs.utf8_window_title = _("Preferences");
    2102           0 :     pos.x = pos.y = 0;
    2103           0 :     pos.width = GGadgetScale(GDrawPointsToPixels(NULL,350));
    2104           0 :     pos.height = GDrawPointsToPixels(NULL,line_max*26+69);
    2105           0 :     gw = GDrawCreateTopWindow(NULL,&pos,e_h,&p,&wattrs);
    2106             : 
    2107           0 :     memset(sgcd,0,sizeof(sgcd));
    2108           0 :     memset(slabel,0,sizeof(slabel));
    2109           0 :     memset(&mfgcd,0,sizeof(mfgcd));
    2110           0 :     memset(&msgcd,0,sizeof(msgcd));
    2111           0 :     memset(&mflabels,0,sizeof(mflabels));
    2112           0 :     memset(&mslabels,0,sizeof(mslabels));
    2113           0 :     memset(&mfboxes,0,sizeof(mfboxes));
    2114           0 :     memset(&mpboxes,0,sizeof(mpboxes));
    2115           0 :     memset(&sboxes,0,sizeof(sboxes));
    2116           0 :     memset(&boxes,0,sizeof(boxes));
    2117             : 
    2118           0 :     GCDFillMacFeat(mfgcd,mflabels,250,default_mac_feature_map, true, mfboxes, mfarray);
    2119             : 
    2120           0 :     sgc = 0;
    2121             : 
    2122           0 :     msgcd[sgc].gd.pos.x = 6; msgcd[sgc].gd.pos.y = 6;
    2123           0 :     msgcd[sgc].gd.pos.width = 250; msgcd[sgc].gd.pos.height = 16*12+10;
    2124           0 :     msgcd[sgc].gd.flags = gg_visible | gg_enabled | gg_list_alphabetic | gg_list_multiplesel;
    2125           0 :     msgcd[sgc].gd.cid = CID_Mapping;
    2126           0 :     msgcd[sgc].gd.u.list = Pref_MappingList(true);
    2127           0 :     msgcd[sgc].gd.handle_controlevent = Pref_MappingSel;
    2128           0 :     msgcd[sgc++].creator = GListCreate;
    2129           0 :     mparray[0] = &msgcd[sgc-1];
    2130             : 
    2131           0 :     msgcd[sgc].gd.pos.x = 6; msgcd[sgc].gd.pos.y = msgcd[sgc-1].gd.pos.y+msgcd[sgc-1].gd.pos.height+10;
    2132           0 :     msgcd[sgc].gd.flags = gg_visible | gg_enabled;
    2133           0 :     mslabels[sgc].text = (unichar_t *) S_("MacMap|_New...");
    2134           0 :     mslabels[sgc].text_is_1byte = true;
    2135           0 :     mslabels[sgc].text_in_resource = true;
    2136           0 :     msgcd[sgc].gd.label = &mslabels[sgc];
    2137           0 :     msgcd[sgc].gd.handle_controlevent = Pref_NewMapping;
    2138           0 :     msgcd[sgc++].creator = GButtonCreate;
    2139           0 :     mparray[4] = GCD_Glue; mparray[5] = &msgcd[sgc-1];
    2140             : 
    2141           0 :     msgcd[sgc].gd.pos.x = msgcd[sgc-1].gd.pos.x+10+GIntGetResource(_NUM_Buttonsize)*100/GIntGetResource(_NUM_ScaleFactor);
    2142           0 :     msgcd[sgc].gd.pos.y = msgcd[sgc-1].gd.pos.y;
    2143           0 :     msgcd[sgc].gd.flags = gg_visible ;
    2144           0 :     mslabels[sgc].text = (unichar_t *) _("_Delete");
    2145           0 :     mslabels[sgc].text_is_1byte = true;
    2146           0 :     mslabels[sgc].text_in_resource = true;
    2147           0 :     msgcd[sgc].gd.label = &mslabels[sgc];
    2148           0 :     msgcd[sgc].gd.cid = CID_MappingDel;
    2149           0 :     msgcd[sgc].gd.handle_controlevent = Pref_DelMapping;
    2150           0 :     msgcd[sgc++].creator = GButtonCreate;
    2151           0 :     mparray[5] = GCD_Glue; mparray[6] = &msgcd[sgc-1];
    2152             : 
    2153           0 :     msgcd[sgc].gd.pos.x = msgcd[sgc-1].gd.pos.x+10+GIntGetResource(_NUM_Buttonsize)*100/GIntGetResource(_NUM_ScaleFactor);
    2154           0 :     msgcd[sgc].gd.pos.y = msgcd[sgc-1].gd.pos.y;
    2155           0 :     msgcd[sgc].gd.flags = gg_visible ;
    2156           0 :     mslabels[sgc].text = (unichar_t *) _("_Edit...");
    2157           0 :     mslabels[sgc].text_is_1byte = true;
    2158           0 :     mslabels[sgc].text_in_resource = true;
    2159           0 :     msgcd[sgc].gd.label = &mslabels[sgc];
    2160           0 :     msgcd[sgc].gd.cid = CID_MappingEdit;
    2161           0 :     msgcd[sgc].gd.handle_controlevent = Pref_EditMapping;
    2162           0 :     msgcd[sgc++].creator = GButtonCreate;
    2163           0 :     mparray[7] = GCD_Glue; mparray[8] = &msgcd[sgc-1];
    2164             : 
    2165           0 :     msgcd[sgc].gd.pos.x = msgcd[sgc-1].gd.pos.x+10+GIntGetResource(_NUM_Buttonsize)*100/GIntGetResource(_NUM_ScaleFactor);
    2166           0 :     msgcd[sgc].gd.pos.y = msgcd[sgc-1].gd.pos.y;
    2167           0 :     msgcd[sgc].gd.flags = gg_visible | gg_enabled;
    2168           0 :     mslabels[sgc].text = (unichar_t *) S_("MacMapping|Default");
    2169           0 :     mslabels[sgc].text_is_1byte = true;
    2170           0 :     mslabels[sgc].text_in_resource = true;
    2171           0 :     msgcd[sgc].gd.label = &mslabels[sgc];
    2172           0 :     msgcd[sgc].gd.handle_controlevent = Pref_DefaultMapping;
    2173           0 :     msgcd[sgc++].creator = GButtonCreate;
    2174           0 :     mparray[9] = GCD_Glue; mparray[10] = &msgcd[sgc-1];
    2175           0 :     mparray[11] = GCD_Glue; mparray[12] = NULL;
    2176             : 
    2177           0 :     mpboxes[2].gd.flags = gg_enabled|gg_visible;
    2178           0 :     mpboxes[2].gd.u.boxelements = mparray+4;
    2179           0 :     mpboxes[2].creator = GHBoxCreate;
    2180           0 :     mparray[1] = GCD_Glue;
    2181           0 :     mparray[2] = &mpboxes[2];
    2182           0 :     mparray[3] = NULL;
    2183             : 
    2184           0 :     mpboxes[0].gd.flags = gg_enabled|gg_visible;
    2185           0 :     mpboxes[0].gd.u.boxelements = mparray;
    2186           0 :     mpboxes[0].creator = GVBoxCreate;
    2187             : 
    2188           0 :     sgc = 0;
    2189           0 :     y2=5;
    2190           0 :     si = 0;
    2191             : 
    2192           0 :     slabel[sgc].text = (unichar_t *) _("Menu Name");
    2193           0 :     slabel[sgc].text_is_1byte = true;
    2194           0 :     sgcd[sgc].gd.label = &slabel[sgc];
    2195           0 :     sgcd[sgc].gd.popup_msg = (unichar_t *) _("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.");
    2196           0 :     sgcd[sgc].gd.pos.x = 8;
    2197           0 :     sgcd[sgc].gd.pos.y = y2;
    2198           0 :     sgcd[sgc].gd.flags = gg_visible | gg_enabled | gg_utf8_popup;
    2199           0 :     sgcd[sgc++].creator = GLabelCreate;
    2200           0 :     sarray[si++] = &sgcd[sgc-1];
    2201             : 
    2202           0 :     slabel[sgc].text = (unichar_t *) _("Script File");
    2203           0 :     slabel[sgc].text_is_1byte = true;
    2204           0 :     sgcd[sgc].gd.label = &slabel[sgc];
    2205           0 :     sgcd[sgc].gd.popup_msg = (unichar_t *) _("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.");
    2206           0 :     sgcd[sgc].gd.pos.x = 110;
    2207           0 :     sgcd[sgc].gd.pos.y = y2;
    2208           0 :     sgcd[sgc].gd.flags = gg_visible | gg_enabled | gg_utf8_popup;
    2209           0 :     sgcd[sgc++].creator = GLabelCreate;
    2210           0 :     sarray[si++] = &sgcd[sgc-1];
    2211           0 :     sarray[si++] = GCD_Glue;
    2212           0 :     sarray[si++] = NULL;
    2213             : 
    2214           0 :     y2 += 14;
    2215             : 
    2216           0 :     for ( i=0; i<SCRIPT_MENU_MAX; ++i ) {
    2217           0 :         sgcd[sgc].gd.pos.x = 8; sgcd[sgc].gd.pos.y = y2;
    2218           0 :         sgcd[sgc].gd.flags = gg_visible | gg_enabled | gg_text_xim;
    2219           0 :         slabel[sgc].text = script_menu_names[i]==NULL?nullstr:script_menu_names[i];
    2220           0 :         sgcd[sgc].gd.label = &slabel[sgc];
    2221           0 :         sgcd[sgc].gd.cid = i+CID_ScriptMNameBase;
    2222           0 :         sgcd[sgc++].creator = GTextFieldCreate;
    2223           0 :         sarray[si++] = &sgcd[sgc-1];
    2224             : 
    2225           0 :         sgcd[sgc].gd.pos.x = 110; sgcd[sgc].gd.pos.y = y2;
    2226           0 :         sgcd[sgc].gd.flags = gg_visible | gg_enabled;
    2227           0 :         slabel[sgc].text = (unichar_t *) (script_filenames[i]==NULL?"":script_filenames[i]);
    2228           0 :         slabel[sgc].text_is_1byte = true;
    2229           0 :         sgcd[sgc].gd.label = &slabel[sgc];
    2230           0 :         sgcd[sgc].gd.cid = i+CID_ScriptMFileBase;
    2231           0 :         sgcd[sgc++].creator = GTextFieldCreate;
    2232           0 :         sarray[si++] = &sgcd[sgc-1];
    2233             : 
    2234           0 :         sgcd[sgc].gd.pos.x = 210; sgcd[sgc].gd.pos.y = y2;
    2235           0 :         sgcd[sgc].gd.flags = gg_visible | gg_enabled;
    2236           0 :         slabel[sgc].text = (unichar_t *) _("...");
    2237           0 :         slabel[sgc].text_is_1byte = true;
    2238           0 :         sgcd[sgc].gd.label = &slabel[sgc];
    2239           0 :         sgcd[sgc].gd.cid = i+CID_ScriptMBrowseBase;
    2240           0 :         sgcd[sgc].gd.handle_controlevent = Prefs_ScriptBrowse;
    2241           0 :         sgcd[sgc++].creator = GButtonCreate;
    2242           0 :         sarray[si++] = &sgcd[sgc-1];
    2243           0 :         sarray[si++] = NULL;
    2244             : 
    2245           0 :         y2 += 26;
    2246             :     }
    2247           0 :     sarray[si++] = GCD_Glue; sarray[si++] = GCD_Glue; sarray[si++] = GCD_Glue;
    2248           0 :     sarray[si++] = NULL;
    2249           0 :     sarray[si++] = NULL;
    2250             : 
    2251           0 :     sboxes[0].gd.flags = gg_enabled|gg_visible;
    2252           0 :     sboxes[0].gd.u.boxelements = sarray;
    2253           0 :     sboxes[0].creator = GHVBoxCreate;
    2254             : 
    2255           0 :     memset(&mgcd,0,sizeof(mgcd));
    2256           0 :     memset(&mgcd,0,sizeof(mgcd));
    2257           0 :     memset(&subaspects,'\0',sizeof(subaspects));
    2258           0 :     memset(&label,0,sizeof(label));
    2259           0 :     memset(&gcd,0,sizeof(gcd));
    2260           0 :     memset(&aspects,'\0',sizeof(aspects));
    2261           0 :     aspects[0].selected = true;
    2262             : 
    2263           0 :     for ( k=0; visible_prefs_list[k].tab_name!=0; ++k ) {
    2264           0 :         pgcd = calloc(gcnt[k]+4,sizeof(GGadgetCreateData));
    2265           0 :         plabel = calloc(gcnt[k]+4,sizeof(GTextInfo));
    2266           0 :         hvarray = calloc((gcnt[k]+6)*5+2,sizeof(GGadgetCreateData *));
    2267             : 
    2268           0 :         aspects[k].text = (unichar_t *) visible_prefs_list[k].tab_name;
    2269           0 :         aspects[k].text_is_1byte = true;
    2270           0 :         aspects[k].gcd = &boxes[2*k];
    2271           0 :         aspects[k].nesting = visible_prefs_list[k].nest;
    2272           0 :         plabels[k] = plabel;
    2273             : 
    2274           0 :         gc = si = 0;
    2275           0 :         for ( i=line=0, y=5; visible_prefs_list[k].pl[i].name!=NULL; ++i ) {
    2276           0 :             pl = &visible_prefs_list[k].pl[i];
    2277           0 :             if ( pl->dontdisplay )
    2278           0 :         continue;
    2279           0 :             plabel[gc].text = (unichar_t *) _(pl->name);
    2280           0 :             plabel[gc].text_is_1byte = true;
    2281           0 :             pgcd[gc].gd.label = &plabel[gc];
    2282           0 :             pgcd[gc].gd.mnemonic = '\0';
    2283           0 :             pgcd[gc].gd.popup_msg = (unichar_t *) _(pl->popup);
    2284           0 :             pgcd[gc].gd.pos.x = 8;
    2285           0 :             pgcd[gc].gd.pos.y = y + 6;
    2286           0 :             pgcd[gc].gd.flags = gg_visible | gg_enabled | gg_utf8_popup;
    2287           0 :             pgcd[gc++].creator = GLabelCreate;
    2288           0 :             hvarray[si++] = &pgcd[gc-1];
    2289             : 
    2290           0 :             plabel[gc].text_is_1byte = true;
    2291           0 :             pgcd[gc].gd.label = &plabel[gc];
    2292           0 :             pgcd[gc].gd.mnemonic = '\0';
    2293           0 :             pgcd[gc].gd.popup_msg = (unichar_t *) _(pl->popup);
    2294           0 :             pgcd[gc].gd.pos.x = 110;
    2295           0 :             pgcd[gc].gd.pos.y = y;
    2296           0 :             pgcd[gc].gd.flags = gg_visible | gg_enabled | gg_utf8_popup;
    2297           0 :             pgcd[gc].data = pl;
    2298           0 :             pgcd[gc].gd.cid = k*CID_PrefsOffset+CID_PrefsBase+i;
    2299           0 :             switch ( pl->type ) {
    2300             :               case pr_bool:
    2301           0 :                 plabel[gc].text = (unichar_t *) _("On");
    2302           0 :                 pgcd[gc].gd.pos.y += 3;
    2303           0 :                 pgcd[gc++].creator = GRadioCreate;
    2304           0 :                 hvarray[si++] = &pgcd[gc-1];
    2305           0 :                 pgcd[gc] = pgcd[gc-1];
    2306           0 :                 pgcd[gc].gd.pos.x += 50;
    2307           0 :                 pgcd[gc].gd.cid = 0;
    2308           0 :                 pgcd[gc].gd.label = &plabel[gc];
    2309           0 :                 plabel[gc].text = (unichar_t *) _("Off");
    2310           0 :                 plabel[gc].text_is_1byte = true;
    2311           0 :                 hvarray[si++] = &pgcd[gc];
    2312           0 :                 hvarray[si++] = GCD_Glue;
    2313           0 :                 if ( *((int *) pl->val))
    2314           0 :                     pgcd[gc-1].gd.flags |= gg_cb_on;
    2315             :                 else
    2316           0 :                     pgcd[gc].gd.flags |= gg_cb_on;
    2317           0 :                 ++gc;
    2318           0 :                 y += 22;
    2319           0 :               break;
    2320             :               case pr_int:
    2321           0 :                 sprintf(buf,"%d", *((int *) pl->val));
    2322           0 :                 plabel[gc].text = (unichar_t *) copy( buf );
    2323           0 :                 pgcd[gc++].creator = GTextFieldCreate;
    2324           0 :                 hvarray[si++] = &pgcd[gc-1];
    2325           0 :                 hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
    2326           0 :                 y += 26;
    2327           0 :               break;
    2328             :               case pr_unicode:
    2329             :                 /*sprintf(buf,"U+%04x", *((int *) pl->val));*/
    2330           0 :                 { char *pt; pt=buf; pt=utf8_idpb(pt,*((int *)pl->val),UTF8IDPB_NOZERO); *pt='\0'; }
    2331           0 :                 plabel[gc].text = (unichar_t *) copy( buf );
    2332           0 :                 pgcd[gc++].creator = GTextFieldCreate;
    2333           0 :                 hvarray[si++] = &pgcd[gc-1];
    2334           0 :                 hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
    2335           0 :                 y += 26;
    2336           0 :               break;
    2337             :               case pr_real:
    2338           0 :                 sprintf(buf,"%g", *((float *) pl->val));
    2339           0 :                 plabel[gc].text = (unichar_t *) copy( buf );
    2340           0 :                 pgcd[gc++].creator = GTextFieldCreate;
    2341           0 :                 hvarray[si++] = &pgcd[gc-1];
    2342           0 :                 hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
    2343           0 :                 y += 26;
    2344           0 :               break;
    2345             :               case pr_encoding:
    2346           0 :                 pgcd[gc].gd.u.list = GetEncodingTypes();
    2347           0 :                 pgcd[gc].gd.label = EncodingTypesFindEnc(pgcd[gc].gd.u.list,
    2348           0 :                         *(Encoding **) pl->val);
    2349           0 :                 for ( ii=0; pgcd[gc].gd.u.list[ii].text!=NULL ||pgcd[gc].gd.u.list[ii].line; ++ii )
    2350           0 :                     if ( pgcd[gc].gd.u.list[ii].userdata!=NULL &&
    2351           0 :                             (strcmp(pgcd[gc].gd.u.list[ii].userdata,"Compacted")==0 ||
    2352           0 :                              strcmp(pgcd[gc].gd.u.list[ii].userdata,"Original")==0 ))
    2353           0 :                         pgcd[gc].gd.u.list[ii].disabled = true;
    2354           0 :                 pgcd[gc].creator = GListFieldCreate;
    2355           0 :                 pgcd[gc].gd.pos.width = 160;
    2356           0 :                 if ( pgcd[gc].gd.label==NULL ) pgcd[gc].gd.label = &encodingtypes[0];
    2357           0 :                 ++gc;
    2358           0 :                 hvarray[si++] = &pgcd[gc-1];
    2359           0 :                 hvarray[si++] = GCD_ColSpan; hvarray[si++] = GCD_ColSpan;
    2360           0 :                 y += 28;
    2361           0 :               break;
    2362             :               case pr_namelist:
    2363           0 :                 { char **nlnames = AllNamelistNames();
    2364             :                 int cnt;
    2365             :                 GTextInfo *namelistnames;
    2366           0 :                 for ( cnt=0; nlnames[cnt]!=NULL; ++cnt);
    2367           0 :                 namelistnames = calloc(cnt+1,sizeof(GTextInfo));
    2368           0 :                 for ( cnt=0; nlnames[cnt]!=NULL; ++cnt) {
    2369           0 :                     namelistnames[cnt].text = (unichar_t *) nlnames[cnt];
    2370           0 :                     namelistnames[cnt].text_is_1byte = true;
    2371           0 :                     if ( strcmp(_((*(NameList **) (pl->val))->title),nlnames[cnt])==0 ) {
    2372           0 :                         namelistnames[cnt].selected = true;
    2373           0 :                         pgcd[gc].gd.label = &namelistnames[cnt];
    2374             :                     }
    2375             :                 }
    2376           0 :                 pgcd[gc].gd.u.list = namelistnames;
    2377           0 :                 pgcd[gc].creator = GListButtonCreate;
    2378           0 :                 pgcd[gc].gd.pos.width = 160;
    2379           0 :                 ++gc;
    2380           0 :                 hvarray[si++] = &pgcd[gc-1];
    2381           0 :                 hvarray[si++] = GCD_ColSpan; hvarray[si++] = GCD_ColSpan;
    2382           0 :                 y += 28;
    2383           0 :               } break;
    2384             :               case pr_string: case pr_file:
    2385           0 :                 if ( pl->set==SetAutoTraceArgs || ((char **) pl->val)==&mf_args )
    2386           0 :                     pgcd[gc].gd.pos.width = 160;
    2387           0 :                 if ( pl->val!=NULL )
    2388           0 :                     tempstr = *((char **) (pl->val));
    2389             :                 else
    2390           0 :                     tempstr = (char *) ((pl->get)());
    2391           0 :                 if ( tempstr!=NULL )
    2392           0 :                     plabel[gc].text = /* def2u_*/ uc_copy( tempstr );
    2393           0 :                 else if ( ((char **) pl->val)==&BDFFoundry )
    2394           0 :                     plabel[gc].text = /* def2u_*/ uc_copy( "FontForge" );
    2395             :                 else
    2396           0 :                     plabel[gc].text = /* def2u_*/ uc_copy( "" );
    2397           0 :                 plabel[gc].text_is_1byte = false;
    2398           0 :                 pgcd[gc++].creator = GTextFieldCreate;
    2399           0 :                 hvarray[si++] = &pgcd[gc-1];
    2400           0 :                 if ( pl->type==pr_file ) {
    2401           0 :                     pgcd[gc] = pgcd[gc-1];
    2402           0 :                     pgcd[gc-1].gd.pos.width = 140;
    2403           0 :                     hvarray[si++] = GCD_ColSpan;
    2404           0 :                     pgcd[gc].gd.pos.x += 145;
    2405           0 :                     pgcd[gc].gd.cid += CID_PrefsBrowseOffset;
    2406           0 :                     pgcd[gc].gd.label = &plabel[gc];
    2407           0 :                     plabel[gc].text = (unichar_t *) "...";
    2408           0 :                     plabel[gc].text_is_1byte = true;
    2409           0 :                     pgcd[gc].gd.handle_controlevent = Prefs_BrowseFile;
    2410           0 :                     pgcd[gc++].creator = GButtonCreate;
    2411           0 :                     hvarray[si++] = &pgcd[gc-1];
    2412           0 :                 } else if ( pl->set==SetAutoTraceArgs || ((char **) pl->val)==&mf_args ) {
    2413           0 :                     hvarray[si++] = GCD_ColSpan;
    2414           0 :                     hvarray[si++] = GCD_Glue;
    2415             :                 } else {
    2416           0 :                     hvarray[si++] = GCD_Glue;
    2417           0 :                     hvarray[si++] = GCD_Glue;
    2418             :                 }
    2419           0 :                 y += 26;
    2420           0 :                 if ( pl->val==NULL )
    2421           0 :                     free(tempstr);
    2422           0 :               break;
    2423             :               case pr_angle:
    2424           0 :                 sprintf(buf,"%g", *((float *) pl->val) * RAD2DEG);
    2425           0 :                 plabel[gc].text = (unichar_t *) copy( buf );
    2426           0 :                 pgcd[gc++].creator = GTextFieldCreate;
    2427           0 :                 hvarray[si++] = &pgcd[gc-1];
    2428           0 :                 plabel[gc].text = (unichar_t *) U_("°");
    2429           0 :                 plabel[gc].text_is_1byte = true;
    2430           0 :                 pgcd[gc].gd.label = &plabel[gc];
    2431           0 :                 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;
    2432           0 :                 pgcd[gc].gd.flags = gg_enabled|gg_visible;
    2433           0 :                 pgcd[gc++].creator = GLabelCreate;
    2434           0 :                 hvarray[si++] = &pgcd[gc-1];
    2435           0 :                 hvarray[si++] = GCD_Glue;
    2436           0 :                 y += 26;
    2437           0 :               break;
    2438             :             }
    2439           0 :             ++line;
    2440           0 :             hvarray[si++] = NULL;
    2441             :         }
    2442           0 :         if ( visible_prefs_list[k].pl == args_list ) {
    2443             :             static char *text[] = {
    2444             : /* GT: See the long comment at "Property|New" */
    2445             : /* GT: This and the next few strings show a limitation of my widget set which */
    2446             : /* GT: cannot handle multi-line text labels. These strings should be concatenated */
    2447             : /* GT: (after striping off "Prefs_App|") together, translated, and then broken up */
    2448             : /* GT: to fit the dialog. There is an extra blank line, not used in English, */
    2449             : /* GT: into which your text may extend if needed. */
    2450             :                 N_("Prefs_App|Normally FontForge will find applications by searching for"),
    2451             :                 N_("Prefs_App|them in your PATH environment variable, if you want"),
    2452             :                 N_("Prefs_App|to alter that behavior you may set an environment"),
    2453             :                 N_("Prefs_App|variable giving the full path spec of the application."),
    2454             :                 N_("Prefs_App|FontForge recognizes BROWSER, MF and AUTOTRACE."),
    2455             :                 N_("Prefs_App| "), /* A blank line */
    2456             :                 NULL };
    2457           0 :             y += 8;
    2458           0 :             for ( i=0; text[i]!=0; ++i ) {
    2459           0 :                 plabel[gc].text = (unichar_t *) S_(text[i]);
    2460           0 :                 plabel[gc].text_is_1byte = true;
    2461           0 :                 pgcd[gc].gd.label = &plabel[gc];
    2462           0 :                 pgcd[gc].gd.pos.x = 8;
    2463           0 :                 pgcd[gc].gd.pos.y = y;
    2464           0 :                 pgcd[gc].gd.flags = gg_visible | gg_enabled;
    2465           0 :                 pgcd[gc++].creator = GLabelCreate;
    2466           0 :                 hvarray[si++] = &pgcd[gc-1];
    2467           0 :                 hvarray[si++] = GCD_ColSpan; hvarray[si++] = GCD_ColSpan;
    2468           0 :                 hvarray[si++] = NULL;
    2469           0 :                 y += 12;
    2470             :             }
    2471             :         }
    2472           0 :         if ( y>y2 ) y2 = y;
    2473           0 :         hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
    2474           0 :         hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
    2475           0 :         hvarray[si++] = NULL;
    2476           0 :         hvarray[si++] = NULL;
    2477           0 :         boxes[2*k].gd.flags = gg_enabled|gg_visible;
    2478           0 :         boxes[2*k].gd.u.boxelements = hvarray;
    2479           0 :         boxes[2*k].creator = GHVBoxCreate;
    2480             :     }
    2481             : 
    2482           0 :     aspects[k].text = (unichar_t *) _("Script Menu");
    2483           0 :     aspects[k].text_is_1byte = true;
    2484           0 :     aspects[k++].gcd = sboxes;
    2485             : 
    2486           0 :     subaspects[0].text = (unichar_t *) _("Features");
    2487           0 :     subaspects[0].text_is_1byte = true;
    2488           0 :     subaspects[0].gcd = mfboxes;
    2489             : 
    2490           0 :     subaspects[1].text = (unichar_t *) _("Mapping");
    2491           0 :     subaspects[1].text_is_1byte = true;
    2492           0 :     subaspects[1].gcd = mpboxes;
    2493             : 
    2494           0 :     mgcd[0].gd.pos.x = 4; gcd[0].gd.pos.y = 6;
    2495           0 :     mgcd[0].gd.pos.width = GDrawPixelsToPoints(NULL,pos.width)-20;
    2496           0 :     mgcd[0].gd.pos.height = y2;
    2497           0 :     mgcd[0].gd.u.tabs = subaspects;
    2498           0 :     mgcd[0].gd.flags = gg_visible | gg_enabled;
    2499           0 :     mgcd[0].creator = GTabSetCreate;
    2500             : 
    2501           0 :     aspects[k].text = (unichar_t *) _("Mac");
    2502           0 :     aspects[k].text_is_1byte = true;
    2503           0 :     aspects[k++].gcd = mgcd;
    2504             : 
    2505           0 :     gc = 0;
    2506             : 
    2507           0 :     gcd[gc].gd.pos.x = gcd[gc].gd.pos.y = 2;
    2508           0 :     gcd[gc].gd.pos.width = pos.width-4; gcd[gc].gd.pos.height = pos.height-2;
    2509           0 :     gcd[gc].gd.flags = gg_enabled | gg_visible | gg_pos_in_pixels;
    2510           0 :     gcd[gc++].creator = GGroupCreate;
    2511             : 
    2512           0 :     gcd[gc].gd.pos.x = 4; gcd[gc].gd.pos.y = 6;
    2513           0 :     gcd[gc].gd.pos.width = GDrawPixelsToPoints(NULL,pos.width)-8;
    2514           0 :     gcd[gc].gd.pos.height = y2+20+18+4;
    2515           0 :     gcd[gc].gd.u.tabs = aspects;
    2516           0 :     gcd[gc].gd.flags = gg_visible | gg_enabled | gg_tabset_vert;
    2517           0 :     gcd[gc++].creator = GTabSetCreate;
    2518           0 :     varray[0] = &gcd[gc-1]; varray[1] = NULL;
    2519             : 
    2520           0 :     y = gcd[gc-1].gd.pos.y+gcd[gc-1].gd.pos.height;
    2521             : 
    2522           0 :     gcd[gc].gd.pos.x = 30-3; gcd[gc].gd.pos.y = y+5-3;
    2523           0 :     gcd[gc].gd.pos.width = -1; gcd[gc].gd.pos.height = 0;
    2524           0 :     gcd[gc].gd.flags = gg_visible | gg_enabled | gg_but_default;
    2525           0 :     label[gc].text = (unichar_t *) _("_OK");
    2526           0 :     label[gc].text_is_1byte = true;
    2527           0 :     label[gc].text_in_resource = true;
    2528           0 :     gcd[gc].gd.mnemonic = 'O';
    2529           0 :     gcd[gc].gd.label = &label[gc];
    2530           0 :     gcd[gc].gd.handle_controlevent = Prefs_Ok;
    2531           0 :     gcd[gc++].creator = GButtonCreate;
    2532           0 :     harray[0] = GCD_Glue; harray[1] = &gcd[gc-1]; harray[2] = GCD_Glue; harray[3] = GCD_Glue;
    2533             : 
    2534           0 :     gcd[gc].gd.pos.x = -30; gcd[gc].gd.pos.y = gcd[gc-1].gd.pos.y+3;
    2535           0 :     gcd[gc].gd.pos.width = -1; gcd[gc].gd.pos.height = 0;
    2536           0 :     gcd[gc].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
    2537           0 :     label[gc].text = (unichar_t *) _("_Cancel");
    2538           0 :     label[gc].text_is_1byte = true;
    2539           0 :     label[gc].text_in_resource = true;
    2540           0 :     gcd[gc].gd.label = &label[gc];
    2541           0 :     gcd[gc].gd.mnemonic = 'C';
    2542           0 :     gcd[gc].gd.handle_controlevent = Prefs_Cancel;
    2543           0 :     gcd[gc++].creator = GButtonCreate;
    2544           0 :     harray[4] = GCD_Glue; harray[5] = &gcd[gc-1]; harray[6] = GCD_Glue; harray[7] = NULL;
    2545             : 
    2546           0 :     memset(mboxes,0,sizeof(mboxes));
    2547           0 :     mboxes[2].gd.flags = gg_enabled|gg_visible;
    2548           0 :     mboxes[2].gd.u.boxelements = harray;
    2549           0 :     mboxes[2].creator = GHBoxCreate;
    2550           0 :     varray[2] = &mboxes[2];
    2551           0 :     varray[3] = NULL;
    2552           0 :     varray[4] = NULL;
    2553             : 
    2554           0 :     mboxes[0].gd.pos.x = mboxes[0].gd.pos.y = 2;
    2555           0 :     mboxes[0].gd.flags = gg_enabled|gg_visible;
    2556           0 :     mboxes[0].gd.u.boxelements = varray;
    2557           0 :     mboxes[0].creator = GHVGroupCreate;
    2558             : 
    2559           0 :     y = GDrawPointsToPixels(NULL,y+37);
    2560           0 :     gcd[0].gd.pos.height = y-4;
    2561             : 
    2562           0 :     GGadgetsCreate(gw,mboxes);
    2563           0 :     GTextInfoListFree(mfgcd[0].gd.u.list);
    2564           0 :     GTextInfoListFree(msgcd[0].gd.u.list);
    2565             : 
    2566           0 :     GHVBoxSetExpandableRow(mboxes[0].ret,0);
    2567           0 :     GHVBoxSetExpandableCol(mboxes[2].ret,gb_expandgluesame);
    2568           0 :     GHVBoxSetExpandableRow(mfboxes[0].ret,0);
    2569           0 :     GHVBoxSetExpandableCol(mfboxes[2].ret,gb_expandgluesame);
    2570           0 :     GHVBoxSetExpandableRow(mpboxes[0].ret,0);
    2571           0 :     GHVBoxSetExpandableCol(mpboxes[2].ret,gb_expandgluesame);
    2572           0 :     GHVBoxSetExpandableRow(sboxes[0].ret,gb_expandglue);
    2573           0 :     for ( k=0; k<TOPICS; ++k )
    2574           0 :         GHVBoxSetExpandableRow(boxes[2*k].ret,gb_expandglue);
    2575             : 
    2576           0 :     memset(&rq,0,sizeof(rq));
    2577           0 :     rq.utf8_family_name = MONO_UI_FAMILIES;
    2578           0 :     rq.point_size = 12;
    2579           0 :     rq.weight = 400;
    2580           0 :     font = GDrawInstanciateFont(gw,&rq);
    2581           0 :     GGadgetSetFont(mfgcd[0].ret,font);
    2582           0 :     GGadgetSetFont(msgcd[0].ret,font);
    2583           0 :     GHVBoxFitWindow(mboxes[0].ret);
    2584             : 
    2585           0 :     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 ) {
    2586           0 :         GGadgetCreateData *gcd = aspects[k].gcd[0].gd.u.boxelements[0];
    2587           0 :         pl = &visible_prefs_list[k].pl[i];
    2588           0 :         if ( pl->dontdisplay )
    2589           0 :     continue;
    2590           0 :         switch ( pl->type ) {
    2591             :           case pr_bool:
    2592           0 :             ++gc;
    2593           0 :           break;
    2594             :           case pr_encoding: {
    2595           0 :             GGadget *g = gcd[gc+1].ret;
    2596           0 :             list = GGadgetGetList(g,&llen);
    2597           0 :             for ( j=0; j<llen ; ++j ) {
    2598           0 :                 if ( list[j]->text!=NULL &&
    2599           0 :                         (void *) (intpt) ( *((int *) pl->val)) == list[j]->userdata )
    2600           0 :                     list[j]->selected = true;
    2601             :                 else
    2602           0 :                     list[j]->selected = false;
    2603             :             }
    2604           0 :             if ( gcd[gc+1].gd.u.list!=encodingtypes )
    2605           0 :                 GTextInfoListFree(gcd[gc+1].gd.u.list);
    2606           0 :           } break;
    2607             :           case pr_namelist:
    2608           0 :             free(gcd[gc+1].gd.u.list);
    2609           0 :           break;
    2610             :           case pr_string: case pr_file: case pr_int: case pr_real: case pr_unicode: case pr_angle:
    2611           0 :             free(plabels[k][gc+1].text);
    2612           0 :             if ( pl->type==pr_file || pl->type==pr_angle )
    2613           0 :                 ++gc;
    2614           0 :           break;
    2615             :         }
    2616           0 :         gc += 2;
    2617             :     }
    2618             : 
    2619           0 :     for ( k=0; visible_prefs_list[k].tab_name!=0; ++k ) {
    2620           0 :         free(aspects[k].gcd->gd.u.boxelements[0]);
    2621           0 :         free(aspects[k].gcd->gd.u.boxelements);
    2622           0 :         free(plabels[k]);
    2623             :     }
    2624             : 
    2625           0 :     GWidgetHidePalettes();
    2626           0 :     GDrawSetVisible(gw,true);
    2627           0 :     while ( !p.done )
    2628           0 :         GDrawProcessOneEvent(NULL);
    2629           0 :     GDrawDestroyWindow(gw);
    2630           0 : }
    2631             : 
    2632           0 : void RecentFilesRemember(char *filename) {
    2633             :     int i,j;
    2634             : 
    2635           0 :     for ( i=0; i<RECENT_MAX && RecentFiles[i]!=NULL; ++i )
    2636           0 :         if ( strcmp(RecentFiles[i],filename)==0 )
    2637           0 :     break;
    2638             : 
    2639           0 :     if ( i<RECENT_MAX && RecentFiles[i]!=NULL ) {
    2640           0 :         if ( i!=0 ) {
    2641           0 :             filename = RecentFiles[i];
    2642           0 :             for ( j=i; j>0; --j )
    2643           0 :                 RecentFiles[j] = RecentFiles[j-1];
    2644           0 :             RecentFiles[0] = filename;
    2645             :         }
    2646             :     } else {
    2647           0 :         if ( RecentFiles[RECENT_MAX-1]!=NULL )
    2648           0 :             free( RecentFiles[RECENT_MAX-1]);
    2649           0 :         for ( i=RECENT_MAX-1; i>0; --i )
    2650           0 :             RecentFiles[i] = RecentFiles[i-1];
    2651           0 :         RecentFiles[0] = copy(filename);
    2652             :     }
    2653             : 
    2654           0 :     PrefsUI_SavePrefs(true);
    2655           0 : }
    2656             : 
    2657           0 : void LastFonts_Save(void) {
    2658             :     FontView *fv, *next;
    2659             :     char buffer[1024];
    2660           0 :     char *ffdir = getFontForgeUserDir(Config);
    2661           0 :     FILE *preserve = NULL;
    2662             : 
    2663           0 :     if ( ffdir ) {
    2664           0 :         sprintf(buffer, "%s/FontsOpenAtLastQuit", ffdir);
    2665           0 :         preserve = fopen(buffer,"w");
    2666           0 :         free(ffdir);
    2667             :     }
    2668             : 
    2669           0 :     for ( fv = fv_list; fv!=NULL; fv = next ) {
    2670           0 :         next = (FontView *) (fv->b.next);
    2671           0 :         if ( preserve ) {
    2672           0 :             SplineFont *sf = fv->b.cidmaster?fv->b.cidmaster:fv->b.sf;
    2673           0 :             fprintf(preserve, "%s\n", sf->filename?sf->filename:sf->origname);
    2674             :         }
    2675             :     }
    2676             : 
    2677           0 :     if ( preserve )
    2678           0 :         fclose(preserve);
    2679           0 : }
    2680             : 
    2681             : struct prefs_interface gdraw_prefs_interface = {
    2682             :     PrefsUI_SavePrefs,
    2683             :     PrefsUI_LoadPrefs,
    2684             :     PrefsUI_GetPrefs,
    2685             :     PrefsUI_SetPrefs,
    2686             :     PrefsUI_getFontForgeShareDir,
    2687             :     PrefsUI_SetDefaults
    2688             : };
    2689             : 
    2690           0 : static void change_res_filename(const char *newname) {
    2691           0 :     free(xdefs_filename);
    2692           0 :     xdefs_filename = copy( newname );
    2693           0 :     SavePrefs(true);
    2694           0 : }
    2695             : 
    2696           0 : void DoXRes(void) {
    2697             :     extern GResInfo fontview_ri;
    2698             : 
    2699           0 :     MVColInit();
    2700           0 :     CVColInit();
    2701           0 :     GResEdit(&fontview_ri,xdefs_filename,change_res_filename);
    2702           0 : }
    2703             : 
    2704             : struct prefs_list pointer_dialog_list[] = {
    2705             :     { 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") },
    2706             :     { 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") },
    2707             :     { 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.") },
    2708             :     PREFS_LIST_EMPTY
    2709             : };
    2710             : 
    2711             : struct prefs_list ruler_dialog_list[] = {
    2712             :         { 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.") },
    2713             :         { N_("MeasureToolShowHorizontalVertical"), pr_bool, &measuretoolshowhorizontolvertical, NULL, NULL, '\0', NULL, 0, N_("Have the measure tool show horizontal and vertical distances on the canvas.") },
    2714             :     PREFS_LIST_EMPTY
    2715             : };
    2716             : 
    2717           0 : static int PrefsSubSet_Ok(GGadget *g, GEvent *e) {
    2718           0 :     GWindow gw = GGadgetGetWindow(g);
    2719           0 :     struct pref_data *p = GDrawGetUserData(GGadgetGetWindow(g));
    2720           0 :     struct prefs_list* plist = p->plist;
    2721           0 :     struct prefs_list* pl = plist;
    2722           0 :     int i=0,j=0;
    2723           0 :     int err=0, enc;
    2724             :     const unichar_t *ret;
    2725             : 
    2726           0 :     p->done = true;
    2727             : 
    2728           0 :     for ( i=0, pl=plist; pl->name; ++i, ++pl ) {
    2729           0 :         switch( pl->type ) {
    2730             :         case pr_int:
    2731           0 :             *((int *) (pl->val)) = GetInt8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
    2732           0 :             break;
    2733             :         case pr_unicode:
    2734           0 :             *((int *) (pl->val)) = GetUnicodeChar8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
    2735           0 :             break;
    2736             :         case pr_bool:
    2737           0 :             *((int *) (pl->val)) = GGadgetIsChecked(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
    2738           0 :             break;
    2739             :         case pr_real:
    2740           0 :             *((float *) (pl->val)) = GetReal8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err);
    2741           0 :             break;
    2742             :         case pr_encoding:
    2743             :         { Encoding *e;
    2744           0 :                 e = ParseEncodingNameFromList(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
    2745           0 :                 if ( e!=NULL )
    2746           0 :                     *((Encoding **) (pl->val)) = e;
    2747           0 :                 enc = 1;        /* So gcc doesn't complain about unused. It is unused, but why add the ifdef and make the code even messier? Sigh. icc complains anyway */
    2748             :         }
    2749           0 :         break;
    2750             :         case pr_namelist:
    2751             :         { NameList *nl;
    2752           0 :             GTextInfo *ti = GGadgetGetListItemSelected(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
    2753           0 :             if ( ti!=NULL ) {
    2754           0 :                 char *name = u2utf8_copy(ti->text);
    2755           0 :                 nl = NameListByName(name);
    2756           0 :                 free(name);
    2757           0 :                 if ( nl!=NULL && nl->uses_unicode && !allow_utf8_glyphnames)
    2758           0 :                     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."));
    2759           0 :                 else if ( nl!=NULL )
    2760           0 :                     *((NameList **) (pl->val)) = nl;
    2761             :             }
    2762             :         }
    2763           0 :         break;
    2764             :         case pr_string: case pr_file:
    2765           0 :             ret = _GGadgetGetTitle(GWidgetGetControl(gw,j*CID_PrefsOffset+CID_PrefsBase+i));
    2766           0 :             if ( pl->val!=NULL ) {
    2767           0 :                 free( *((char **) (pl->val)) );
    2768           0 :                 *((char **) (pl->val)) = NULL;
    2769           0 :                 if ( ret!=NULL && *ret!='\0' )
    2770           0 :                     *((char **) (pl->val)) = /* u2def_*/ cu_copy(ret);
    2771             :             } else {
    2772           0 :                 char *cret = cu_copy(ret);
    2773           0 :                 (pl->set)(cret);
    2774           0 :                 free(cret);
    2775             :             }
    2776           0 :             break;
    2777             :         case pr_angle:
    2778           0 :             *((float *) (pl->val)) = GetReal8(gw,j*CID_PrefsOffset+CID_PrefsBase+i,pl->name,&err)/RAD2DEG;
    2779           0 :             break;
    2780             :         }
    2781             :     }
    2782             : 
    2783           0 :     return( true );
    2784             : }
    2785             : 
    2786           0 : static void PrefsSubSetDlg(CharView *cv,char* windowTitle,struct prefs_list* plist) {
    2787           0 :     struct prefs_list* pl = plist;
    2788             :     GRect pos;
    2789             :     GWindow gw;
    2790             :     GWindowAttrs wattrs;
    2791             :     GGadgetCreateData *pgcd, gcd[20], sgcd[45], mgcd[3], mfgcd[9], msgcd[9];
    2792             :     GGadgetCreateData mfboxes[3], *mfarray[14];
    2793             :     GGadgetCreateData mpboxes[3];
    2794             :     GGadgetCreateData sboxes[2];
    2795             :     GGadgetCreateData mboxes[3], mboxes2[5], *varray[5], *harray[8];
    2796             :     GTextInfo *plabel, label[20], slabel[45], mflabels[9], mslabels[9];
    2797             :     GTabInfo aspects[TOPICS+5], subaspects[3];
    2798             :     GGadgetCreateData **hvarray, boxes[2*TOPICS];
    2799             :     struct pref_data p;
    2800           0 :     int line = 0,line_max = 3;
    2801           0 :     int i = 0, gc = 0, ii, y=0, si=0, k=0;
    2802             :     char buf[20];
    2803             :     char *tempstr;
    2804             : 
    2805           0 :     PrefsInit();
    2806           0 :     MfArgsInit();
    2807             : 
    2808           0 :     line_max=0;
    2809           0 :     for ( i=0, pl=plist; pl->name; ++i, ++pl ) {
    2810           0 :             ++line_max;
    2811             :     }
    2812             : 
    2813           0 :     int itemCount = 100;
    2814           0 :     pgcd = calloc(itemCount,sizeof(GGadgetCreateData));
    2815           0 :     plabel = calloc(itemCount,sizeof(GTextInfo));
    2816           0 :     hvarray = calloc((itemCount)*5,sizeof(GGadgetCreateData *));
    2817           0 :     memset(&p,'\0',sizeof(p));
    2818           0 :     memset(&wattrs,0,sizeof(wattrs));
    2819           0 :     memset(sgcd,0,sizeof(sgcd));
    2820           0 :     memset(slabel,0,sizeof(slabel));
    2821           0 :     memset(&mfgcd,0,sizeof(mfgcd));
    2822           0 :     memset(&msgcd,0,sizeof(msgcd));
    2823           0 :     memset(&mflabels,0,sizeof(mflabels));
    2824           0 :     memset(&mslabels,0,sizeof(mslabels));
    2825           0 :     memset(&mfboxes,0,sizeof(mfboxes));
    2826           0 :     memset(&mpboxes,0,sizeof(mpboxes));
    2827           0 :     memset(&sboxes,0,sizeof(sboxes));
    2828           0 :     memset(&boxes,0,sizeof(boxes));
    2829           0 :     memset(&mgcd,0,sizeof(mgcd));
    2830           0 :     memset(&mgcd,0,sizeof(mgcd));
    2831           0 :     memset(&subaspects,'\0',sizeof(subaspects));
    2832           0 :     memset(&label,0,sizeof(label));
    2833           0 :     memset(&gcd,0,sizeof(gcd));
    2834           0 :     memset(&aspects,'\0',sizeof(aspects));
    2835           0 :     GCDFillMacFeat(mfgcd,mflabels,250,default_mac_feature_map, true, mfboxes, mfarray);
    2836             : 
    2837           0 :     p.plist = plist;
    2838           0 :     wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_restrict|wam_isdlg;
    2839           0 :     wattrs.event_masks = ~(1<<et_charup);
    2840           0 :     wattrs.restrict_input_to_me = 1;
    2841           0 :     wattrs.is_dlg = 1;
    2842           0 :     wattrs.undercursor = 1;
    2843           0 :     wattrs.cursor = ct_pointer;
    2844           0 :     wattrs.utf8_window_title = windowTitle;
    2845           0 :     pos.x = pos.y = 0;
    2846           0 :     pos.width = GGadgetScale(GDrawPointsToPixels(NULL,340));
    2847           0 :     pos.height = GDrawPointsToPixels(NULL,line_max*26+25);
    2848           0 :     gw = GDrawCreateTopWindow(NULL,&pos,e_h,&p,&wattrs);
    2849             : 
    2850             : 
    2851             : 
    2852           0 :     for ( i=0, pl=plist; pl->name; ++i, ++pl ) {
    2853             : 
    2854           0 :             plabel[gc].text = (unichar_t *) _(pl->name);
    2855           0 :             plabel[gc].text_is_1byte = true;
    2856           0 :             pgcd[gc].gd.label = &plabel[gc];
    2857           0 :             pgcd[gc].gd.mnemonic = '\0';
    2858           0 :             pgcd[gc].gd.popup_msg = (unichar_t *) 0;//_(pl->popup);
    2859           0 :             pgcd[gc].gd.pos.x = 8;
    2860           0 :             pgcd[gc].gd.pos.y = y + 6;
    2861           0 :             pgcd[gc].gd.flags = gg_visible | gg_enabled | gg_utf8_popup;
    2862           0 :             pgcd[gc++].creator = GLabelCreate;
    2863           0 :             hvarray[si++] = &pgcd[gc-1];
    2864             : 
    2865           0 :             plabel[gc].text_is_1byte = true;
    2866           0 :             pgcd[gc].gd.label = &plabel[gc];
    2867           0 :             pgcd[gc].gd.mnemonic = '\0';
    2868           0 :             pgcd[gc].gd.popup_msg = (unichar_t *) 0;//_(pl->popup);
    2869           0 :             pgcd[gc].gd.pos.x = 110;
    2870           0 :             pgcd[gc].gd.pos.y = y;
    2871           0 :             pgcd[gc].gd.flags = gg_visible | gg_enabled | gg_utf8_popup;
    2872           0 :             pgcd[gc].data = pl;
    2873           0 :             pgcd[gc].gd.cid = k*CID_PrefsOffset+CID_PrefsBase+i;
    2874           0 :             switch ( pl->type ) {
    2875             :               case pr_bool:
    2876           0 :                 plabel[gc].text = (unichar_t *) _("On");
    2877           0 :                 pgcd[gc].gd.pos.y += 3;
    2878           0 :                 pgcd[gc++].creator = GRadioCreate;
    2879           0 :                 hvarray[si++] = &pgcd[gc-1];
    2880           0 :                 pgcd[gc] = pgcd[gc-1];
    2881           0 :                 pgcd[gc].gd.pos.x += 50;
    2882           0 :                 pgcd[gc].gd.cid = 0;
    2883           0 :                 pgcd[gc].gd.label = &plabel[gc];
    2884           0 :                 plabel[gc].text = (unichar_t *) _("Off");
    2885           0 :                 plabel[gc].text_is_1byte = true;
    2886           0 :                 hvarray[si++] = &pgcd[gc];
    2887           0 :                 hvarray[si++] = GCD_Glue;
    2888           0 :                 if ( *((int *) pl->val))
    2889           0 :                     pgcd[gc-1].gd.flags |= gg_cb_on;
    2890             :                 else
    2891           0 :                     pgcd[gc].gd.flags |= gg_cb_on;
    2892           0 :                 ++gc;
    2893           0 :                 y += 22;
    2894           0 :               break;
    2895             :               case pr_int:
    2896           0 :                 sprintf(buf,"%d", *((int *) pl->val));
    2897           0 :                 plabel[gc].text = (unichar_t *) copy( buf );
    2898           0 :                 pgcd[gc++].creator = GTextFieldCreate;
    2899           0 :                 hvarray[si++] = &pgcd[gc-1];
    2900           0 :                 hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
    2901           0 :                 y += 26;
    2902           0 :               break;
    2903             :               case pr_unicode:
    2904             :                 /*sprintf(buf,"U+%04x", *((int *) pl->val));*/
    2905           0 :                 { char *pt; pt=buf; pt=utf8_idpb(pt,*((int *)pl->val),UTF8IDPB_NOZERO); *pt='\0'; }
    2906           0 :                 plabel[gc].text = (unichar_t *) copy( buf );
    2907           0 :                 pgcd[gc++].creator = GTextFieldCreate;
    2908           0 :                 hvarray[si++] = &pgcd[gc-1];
    2909           0 :                 hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
    2910           0 :                 y += 26;
    2911           0 :               break;
    2912             :               case pr_real:
    2913           0 :                 sprintf(buf,"%g", *((float *) pl->val));
    2914           0 :                 plabel[gc].text = (unichar_t *) copy( buf );
    2915           0 :                 pgcd[gc++].creator = GTextFieldCreate;
    2916           0 :                 hvarray[si++] = &pgcd[gc-1];
    2917           0 :                 hvarray[si++] = GCD_Glue; hvarray[si++] = GCD_Glue;
    2918           0 :                 y += 26;
    2919           0 :               break;
    2920             :               case pr_encoding:
    2921           0 :                 pgcd[gc].gd.u.list = GetEncodingTypes();
    2922           0 :                 pgcd[gc].gd.label = EncodingTypesFindEnc(pgcd[gc].gd.u.list,
    2923           0 :                         *(Encoding **) pl->val);
    2924           0 :                 for ( ii=0; pgcd[gc].gd.u.list[ii].text!=NULL ||pgcd[gc].gd.u.list[ii].line; ++ii )
    2925           0 :                     if ( pgcd[gc].gd.u.list[ii].userdata!=NULL &&
    2926           0 :                             (strcmp(pgcd[gc].gd.u.list[ii].userdata,"Compacted")==0 ||
    2927           0 :                              strcmp(pgcd[gc].gd.u.list[ii].userdata,"Original")==0 ))
    2928           0 :                         pgcd[gc].gd.u.list[ii].disabled = true;
    2929           0 :                 pgcd[gc].creator = GListFieldCreate;
    2930           0 :                 pgcd[gc].gd.pos.width = 160;
    2931           0 :                 if ( pgcd[gc].gd.label==NULL ) pgcd[gc].gd.label = &encodingtypes[0];
    2932           0 :                 ++gc;
    2933           0 :                 hvarray[si++] = &pgcd[gc-1];
    2934           0 :                 hvarray[si++] = GCD_ColSpan; hvarray[si++] = GCD_ColSpan;
    2935           0 :                 y += 28;
    2936           0 :               break;
    2937             :               case pr_namelist:
    2938           0 :                 { char **nlnames = AllNamelistNames();
    2939             :                 int cnt;
    2940             :                 GTextInfo *namelistnames;
    2941           0 :                 for ( cnt=0; nlnames[cnt]!=NULL; ++cnt);
    2942           0 :                 namelistnames = calloc(cnt+1,sizeof(GTextInfo));
    2943           0 :                 for ( cnt=0; nlnames[cnt]!=NULL; ++cnt) {
    2944           0 :                     namelistnames[cnt].text = (unichar_t *) nlnames[cnt];
    2945           0 :                     namelistnames[cnt].text_is_1byte = true;
    2946           0 :                     if ( strcmp(_((*(NameList **) (pl->val))->title),nlnames[cnt])==0 ) {
    2947           0 :                         namelistnames[cnt].selected = true;
    2948           0 :                         pgcd[gc].gd.label = &namelistnames[cnt];
    2949             :                     }
    2950             :                 }
    2951           0 :                 pgcd[gc].gd.u.list = namelistnames;
    2952           0 :                 pgcd[gc].creator = GListButtonCreate;
    2953           0 :                 pgcd[gc].gd.pos.width = 160;
    2954           0 :                 ++gc;
    2955           0 :                 hvarray[si++] = &pgcd[gc-1];
    2956           0 :                 hvarray[si++] = GCD_ColSpan; hvarray[si++] = GCD_ColSpan;
    2957           0 :                 y += 28;
    2958           0 :               } break;
    2959             :               case pr_string: case pr_file:
    2960           0 :                 if ( pl->set==SetAutoTraceArgs || ((char **) pl->val)==&mf_args )
    2961           0 :                     pgcd[gc].gd.pos.width = 160;
    2962           0 :                 if ( pl->val!=NULL )
    2963           0 :                     tempstr = *((char **) (pl->val));
    2964             :                 else
    2965           0 :                     tempstr = (char *) ((pl->get)());
    2966           0 :                 if ( tempstr!=NULL )
    2967           0 :                     plabel[gc].text = /* def2u_*/ uc_copy( tempstr );
    2968           0 :                 else if ( ((char **) pl->val)==&BDFFoundry )
    2969           0 :                     plabel[gc].text = /* def2u_*/ uc_copy( "FontForge" );
    2970             :                 else
    2971           0 :                     plabel[gc].text = /* def2u_*/ uc_copy( "" );
    2972           0 :                 plabel[gc].text_is_1byte = false;
    2973           0 :                 pgcd[gc++].creator = GTextFieldCreate;
    2974           0 :                 hvarray[si++] = &pgcd[gc-1];
    2975           0 :                 if ( pl->type==pr_file ) {
    2976           0 :                     pgcd[gc] = pgcd[gc-1];
    2977           0 :                     pgcd[gc-1].gd.pos.width = 140;
    2978           0 :                     hvarray[si++] = GCD_ColSpan;
    2979           0 :                     pgcd[gc].gd.pos.x += 145;
    2980           0 :                     pgcd[gc].gd.cid += CID_PrefsBrowseOffset;
    2981           0 :                     pgcd[gc].gd.label = &plabel[gc];
    2982           0 :                     plabel[gc].text = (unichar_t *) "...";
    2983           0 :                     plabel[gc].text_is_1byte = true;
    2984           0 :                     pgcd[gc].gd.handle_controlevent = Prefs_BrowseFile;
    2985           0 :                     pgcd[gc++].creator = GButtonCreate;
    2986           0 :                     hvarray[si++] = &pgcd[gc-1];
    2987           0 :                 } else if ( pl->set==SetAutoTraceArgs || ((char **) pl->val)==&mf_args ) {
    2988           0 :                     hvarray[si++] = GCD_ColSpan;
    2989           0 :                     hvarray[si++] = GCD_Glue;
    2990             :                 } else {
    2991           0 :                     hvarray[si++] = GCD_Glue;
    2992           0 :                     hvarray[si++] = GCD_Glue;
    2993             :                 }
    2994           0 :                 y += 26;
    2995           0 :                 if ( pl->val==NULL )
    2996           0 :                     free(tempstr);
    2997           0 :               break;
    2998             :               case pr_angle:
    2999           0 :                 sprintf(buf,"%g", *((float *) pl->val) * RAD2DEG);
    3000           0 :                 plabel[gc].text = (unichar_t *) copy( buf );
    3001           0 :                 pgcd[gc++].creator = GTextFieldCreate;
    3002           0 :                 hvarray[si++] = &pgcd[gc-1];
    3003           0 :                 plabel[gc].text = (unichar_t *) U_("°");
    3004           0 :                 plabel[gc].text_is_1byte = true;
    3005           0 :                 pgcd[gc].gd.label = &plabel[gc];
    3006           0 :                 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;
    3007           0 :                 pgcd[gc].gd.flags = gg_enabled|gg_visible;
    3008           0 :                 pgcd[gc++].creator = GLabelCreate;
    3009           0 :                 hvarray[si++] = &pgcd[gc-1];
    3010           0 :                 hvarray[si++] = GCD_Glue;
    3011           0 :                 y += 26;
    3012           0 :               break;
    3013             :             }
    3014           0 :             ++line;
    3015           0 :             hvarray[si++] = NULL;
    3016             : 
    3017             :     }
    3018             : 
    3019           0 :     harray[4] = 0;
    3020           0 :     harray[5] = 0;
    3021           0 :     harray[6] = 0;
    3022           0 :     harray[7] = 0;
    3023             : 
    3024           0 :     gcd[gc].gd.pos.x = 30-3;
    3025           0 :     gcd[gc].gd.pos.y = y+5-3;
    3026           0 :     gcd[gc].gd.pos.width = -1;
    3027           0 :     gcd[gc].gd.pos.height = 0;
    3028           0 :     gcd[gc].gd.flags = gg_visible | gg_enabled | gg_but_default;
    3029           0 :     label[gc].text = (unichar_t *) _("_OK");
    3030           0 :     label[gc].text_is_1byte = true;
    3031           0 :     label[gc].text_in_resource = true;
    3032           0 :     gcd[gc].gd.mnemonic = 'O';
    3033           0 :     gcd[gc].gd.label = &label[gc];
    3034           0 :     gcd[gc].gd.handle_controlevent = PrefsSubSet_Ok;
    3035           0 :     gcd[gc++].creator = GButtonCreate;
    3036           0 :     harray[0] = GCD_Glue; harray[1] = &gcd[gc-1]; harray[2] = GCD_Glue; harray[3] = GCD_Glue;
    3037             : 
    3038             : 
    3039           0 :     memset(mboxes,0,sizeof(mboxes));
    3040           0 :     memset(mboxes2,0,sizeof(mboxes2));
    3041             : 
    3042           0 :     mboxes[2].gd.pos.x = 2;
    3043           0 :     mboxes[2].gd.pos.y = 20;
    3044           0 :     mboxes[2].gd.flags = gg_enabled|gg_visible;
    3045           0 :     mboxes[2].gd.u.boxelements = harray;
    3046           0 :     mboxes[2].creator = GHBoxCreate;
    3047             : 
    3048           0 :     mboxes[0].gd.pos.x = mboxes[0].gd.pos.y = 2;
    3049           0 :     mboxes[0].gd.flags = gg_enabled|gg_visible;
    3050           0 :     mboxes[0].gd.u.boxelements = hvarray;
    3051           0 :     mboxes[0].creator = GHVGroupCreate;
    3052             : 
    3053           0 :     varray[0] = &mboxes[0];
    3054           0 :     varray[1] = &mboxes[2];
    3055           0 :     varray[2] = 0;
    3056           0 :     varray[3] = 0;
    3057           0 :     varray[4] = 0;
    3058             : 
    3059             :     /* varray[0] = &mboxes[2]; */
    3060             :     /* varray[1] = 0;//&mboxes[2]; */
    3061             :     /* varray[2] = 0; */
    3062             :     /* varray[3] = 0; */
    3063             :     /* varray[4] = 0; */
    3064             : 
    3065           0 :     mboxes2[0].gd.pos.x = 4;
    3066           0 :     mboxes2[0].gd.pos.y = 4;
    3067           0 :     mboxes2[0].gd.flags = gg_enabled|gg_visible;
    3068           0 :     mboxes2[0].gd.u.boxelements = varray;
    3069           0 :     mboxes2[0].creator = GVBoxCreate;
    3070             : 
    3071           0 :     GGadgetsCreate(gw,mboxes2);
    3072             : 
    3073             : 
    3074           0 :     GDrawSetVisible(gw,true);
    3075           0 :     while ( !p.done )
    3076           0 :         GDrawProcessOneEvent(NULL);
    3077           0 :     GDrawDestroyWindow(gw);
    3078           0 : }
    3079             : 
    3080             : 
    3081           0 : void PointerDlg(CharView *cv) {
    3082           0 :     PrefsSubSetDlg( cv, _("Arrow Options"), pointer_dialog_list );
    3083           0 : }
    3084             : 
    3085           0 : void RulerDlg(CharView *cv) {
    3086           0 :     PrefsSubSetDlg( cv, _("Ruler Options"), ruler_dialog_list );
    3087           0 : }
    3088             : 

Generated by: LCOV version 1.10