beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / luafontloader / fontforge / fontforge / uiinterface.h
blob81409b72499a78861bf52860665c9b82d90d9c36
1 /* Copyright (C) 2007,2008 by George Williams */
2 /*
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
13 * The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef _UIINTERFACE_H
28 #define _UIINTERFACE_H
29 # include "basics.h"
30 /* This encapsulates a set of callbacks and stubs. The callbacks get activated*/
31 /* when an event happens (a glyph in a font changes for example, then all */
32 /* charviews looking at it must be updated), and the stubs provide some simple*/
33 /* UI routines: Post an error, etc. */
35 /* ************************************************************************** */
36 /* Basic, low-level UI routines for events we discover deep inside script code*/
37 /* ************************************************************************** */
39 struct ui_interface {
40 /* The following is used to post a fontforge internal error */
41 /* currently it puts up a dlg displaying the error text */
42 void (*ierror)(const char *fmt,...);
44 /* The following is a simple dialog to alert the user that s/he has */
45 /* made an error. Currently it posts a modal dlg and waits for the */
46 /* user to dismiss it */
47 /* The title argument is the window's title. The error argument is the */
48 /* text of the message. It may contain printf formatting. It may contain */
49 /* newlines to force line breaks -- even if it doesn't contain new lines */
50 /* the routine will wrap the text if a line is too long */
51 void (*post_error)(const char *title,const char *error,...);
53 /* The following is used to post a warning message in such a way that it */
54 /* will not impede the user. Currently it creates a little window at the */
55 /* bottom right of the screen and writes successive messages there */
56 void (*logwarning)(const char *fmt,...);
58 /* The following is another way to post a warning message in such a way */
59 /* that it will not impede the user. Currently it pops up a little */
60 /* non-modal dlg which vanishes after a minute or two (or if the user */
61 /* dismisses it, of course */
62 void (*post_warning)(const char *title,const char *statement,...);
64 /* Occasionally we we be deep in a non-ui routine and we find we must ask */
65 /* the user a question. In this routine the choices are displayed as */
66 /* buttons, one button is the default, another is a cancel choice */
67 int (*ask)(const char *title, const char **answers,
68 int def, int cancel,const char *question,...);
70 /* Similar to the above, except here the choices are presented as a */
71 /* scrolled list. Return -1 if the user cancels */
72 int (*choose)(const char *title, const char **answers,
73 int def, int cancel,const char *question,...);
75 /* Multiple things can be selected, sel is an in/out parameter, one byte */
76 /* per entry in the choice array. 0=> not selected, 1=>selected */
77 int (*choose_multiple)(char *title, const char **choices,char *sel,
78 int cnt, char *buts[2], const char *question,...);
80 /* Here we want a string. We are passed a default answer (or NULL) */
81 /* The return is NULL on cancel, otherwise a string which must be freed */
82 char *(*ask_string)(const char *title,
83 const char *def,const char *question,...);
84 /* Same as above, except for entering a password */
85 char *(*ask_password)(const char *title,
86 const char *def,const char *question,...);
88 /* The next two routines are only used in the python interface to provide */
89 /* a python script running in ff a way to open a file */
90 /* Arguments are a window title for the dlg, a default file (or NULL), and */
91 /* an initial filter (unix wildcards) or NULL */
92 char *(*open_file)(const char *title, const char *defaultfile,
93 const char *initial_filter);
94 char *(*saveas_file)(const char *title, const char *defaultfile,
95 const char *initial_filter);
97 /* These routines are for a progress indicator */
98 void (*progress_start)(int delay, const char *title, const char *line1,
99 const char *line2, int tot, int stages);
100 void (*progress_end)(void);
101 void (*progress_show)(void);
102 void (*progress_enable_stop)(int);
103 int (*progress_next)(void);
104 int (*progress_next_stage)(void);
105 int (*progress_increment)(int);
106 void (*progress_change_line1)(const char *);
107 void (*progress_change_line2)(const char *);
108 void (*progress_pause)(void);
109 void (*progress_resume)(void);
110 void (*progress_change_stages)(int);
111 void (*progress_change_total)(int);
112 int (*progress_reset)(void);
114 void (*allow_events)(void);
116 /* These next few provide friendly names of various opentype tags */
117 /* The ui version will probably be translated, while the non-ui list */
118 /* will probably not. The distinction isn't necessary, but is present in ff*/
119 const char *(*strid)(int);
120 const char *(*mslang)(int);
122 /* pops up a dlg asking user whether to do remove overlap (and other stuff)*/
123 /* when loading an eps file with strokes, etc. */
124 int (*stroke_flags)(void);
126 extern struct ui_interface *ui_interface;
128 #define IError (ui_interface->ierror)
129 #define LogError (ui_interface->logwarning)
130 #define ff_post_notice (ui_interface->post_warning)
131 #define ff_post_error (ui_interface->post_error)
132 #define ff_ask (ui_interface->ask)
133 #define ff_choose (ui_interface->choose)
134 #define ff_choose_multiple (ui_interface->choose_multiple)
135 #define ff_ask_string (ui_interface->ask_string)
136 #define ff_ask_password (ui_interface->ask_password)
138 #define ff_open_filename (ui_interface->open_file)
139 #define ff_save_filename (ui_interface->saveas_file)
141 #define ff_progress_start_indicator (ui_interface->progress_start)
142 #define ff_progress_end_indicator (ui_interface->progress_end)
143 #define ff_progress_show (ui_interface->progress_show)
144 #define ff_progress_enable_stop (ui_interface->progress_enable_stop)
145 #define ff_progress_next (ui_interface->progress_next)
146 #define ff_progress_next_stage (ui_interface->progress_next_stage)
147 #define ff_progress_increment (ui_interface->progress_increment)
148 #define ff_progress_change_line1 (ui_interface->progress_change_line1)
149 #define ff_progress_change_line2 (ui_interface->progress_change_line2)
150 #define ff_progress_pause_timer (ui_interface->progress_pause)
151 #define ff_progress_resume_timer (ui_interface->progress_resume)
152 #define ff_progress_change_stages (ui_interface->progress_change_stages)
153 #define ff_progress_change_total (ui_interface->progress_change_total)
154 #define ff_progress_reset (ui_interface->progress_reset)
156 #define ff_progress_allow_events (ui_interface->allow_events)
158 #define TTFNameIds (ui_interface->strid)
159 #define MSLangString (ui_interface->mslang)
161 #define PsStrokeFlagsDlg (ui_interface->stroke_flags)
163 void FF_SetUiInterface(struct ui_interface *uii);
165 /* ************************************************************************** */
166 /* Preferences */
167 /* ************************************************************************** */
168 struct val;
170 struct prefs_interface {
171 void (*save_prefs)(int not_if_running_script);
172 void (*load_prefs)(void);
173 int (*get_prefs)(char *name,struct val *value);
174 int (*set_prefs)(char *name,struct val *val1, struct val *val2);
175 char *(*get_exe_share_dir)(void);
176 void (*init_prefs)(void);
178 extern struct prefs_interface *prefs_interface;
180 #define SavePrefs (prefs_interface->save_prefs)
181 #define LoadPrefs (prefs_interface->load_prefs)
182 #define GetPrefs (prefs_interface->get_prefs)
183 #define SetPrefs (prefs_interface->set_prefs)
184 #define getFontForgeShareDir (prefs_interface->get_exe_share_dir)
185 #define SetDefaults (prefs_interface->init_prefs)
187 void FF_SetPrefsInterface(struct prefs_interface *prefsi);
189 /* ************************************************************************** */
190 /* Updating glyph windows */
191 /* ************************************************************************** */
193 struct splinechar;
194 struct layer;
196 struct sc_interface {
197 /* Update all windows looking at this glyph */
198 void (*update_all)(struct splinechar *);
200 /* Background images or kerning info have changed for this glyph and */
201 /* all windows displaying them need to be refreshed */
202 void (*out_of_date_background)(struct splinechar *);
204 /* The name or code point or encoding of this glyph has changed */
205 /* update all window titles of any windows looking at us */
206 void (*refresh_titles)(struct splinechar *);
208 /* The hints of the glyph have changed */
209 void (*hints_changed)(struct splinechar *);
211 /* Mark the glyph as changed, and force an update */
212 void (*glyph_changed_update)(struct splinechar *,int layer);
214 /* As above, except this time the change might take the glyph back to */
215 /* an "unchanged" state (ie. an Undo) */
216 void (*glyph__changed_update)(struct splinechar *,int layer,int);
218 /* The glyph's instructions have changed, so any dlgs looking at */
219 /* our instructions need to be updated */
220 void (*instructions_changed)(struct splinechar *sc);
222 /* We are removing this glyph (or something like it), get rid of any */
223 /* glyph outline windows which display it */
224 void (*close_all_windows)(struct splinechar *);
226 /* Called when a multilayered glyph increases its layer count */
227 /* the charview needs to add more layers to its layer window, etc. */
228 void (*more_layers)(struct splinechar *, struct layer *);
230 extern struct sc_interface *sc_interface;
232 #define SCUpdateAll (sc_interface->update_all)
233 #define SCOutOfDateBackground (sc_interface->out_of_date_background)
234 #define SCRefreshTitles (sc_interface->refresh_titles)
235 #define SCHintsChanged (sc_interface->hints_changed)
236 #define _SCCharChangedUpdate (sc_interface->glyph__changed_update)
237 #define SCCharChangedUpdate (sc_interface->glyph_changed_update)
238 #define SCMarkInstrDlgAsChanged (sc_interface->instructions_changed)
239 #define SCCloseAllViews (sc_interface->close_all_windows)
240 #define SCMoreLayers (sc_interface->more_layers)
242 void FF_SetSCInterface(struct sc_interface *sci);
244 /* ************************************************************************** */
245 /* Updating glyph windows 2 */
246 /* ************************************************************************** */
248 struct charviewbase;
249 struct splinefont;
251 struct cv_interface {
252 /* Update all windows looking at what this char window looks at */
253 /* which might be a glyph, or perhaps the grid layer */
254 /* And mark as changed */
255 void (*glyph_changed_update)(struct charviewbase *);
256 void (*_glyph_changed_update)(struct charviewbase *, int);
258 /* A glyph's name has changed find all charviews with tabs with that name */
259 /* and update those tabs */
260 void (*glyph_name_change)(struct splinefont *sf, char *oldname, char *newname);
262 /* We've added a layer to a font */
263 void (*layer_palette_check)(struct splinefont *sf);
265 extern struct cv_interface *cv_interface;
267 #define CVCharChangedUpdate (cv_interface->glyph_changed_update)
268 #define _CVCharChangedUpdate (cv_interface->_glyph_changed_update)
269 #define CVGlyphRenameFixup (cv_interface->glyph_name_change)
270 #define CVLayerPaletteCheck (cv_interface->layer_palette_check)
272 void FF_SetCVInterface(struct cv_interface *cvi);
274 /* ************************************************************************** */
275 /* Updating bitmap windows */
276 /* ************************************************************************** */
278 struct bdfchar;
280 struct bc_interface {
281 /* Update all windows looking at this bitmap glyph */
282 /* And mark as changed */
283 void (*glyph_changed_update)(struct bdfchar *);
285 /* Force a refresh on all open bitmap windows of this glyph */
286 void (*refresh_all)(struct bdfchar *);
288 /* Destroy all open bitmap windows of this glyph */
289 void (*destroy_all)(struct bdfchar *);
291 extern struct bc_interface *bc_interface;
293 #define BCCharChangedUpdate (bc_interface->glyph_changed_update)
294 #define BCRefreshAll (bc_interface->refresh_all)
295 #define BCDestroyAll (bc_interface->destroy_all)
297 void FF_SetBCInterface(struct bc_interface *bci);
299 /* ************************************************************************** */
300 /* Access to metrics views */
301 /* ************************************************************************** */
303 struct metricsview;
304 struct splinefont;
306 struct mv_interface {
307 /* Number of glyphs displayed in the view */
308 int (*glyph_cnt)(struct metricsview *);
310 /* Access to the i'th member */
311 struct splinechar *(*get_glyph)(struct metricsview *,int);
313 /* Kerning information for this font has changed. Remetric the metric views*/
314 /* Now-a-days, call this when any kind of lookup information changes, not */
315 /* just kerning */
316 void (*rekern)(struct splinefont *);
318 /* Close any metrics views associated with this font */
319 void (*sf_close_metrics)(struct splinefont *sf);
321 extern struct mv_interface *mv_interface;
323 #define MVGlyphCount (mv_interface->glyph_cnt)
324 #define MVGlyphIndex (mv_interface->get_glyph)
325 #define MVReKernAll (mv_interface->rekern)
326 #define MVDestroyAll (mv_interface->sf_close_metrics)
328 void FF_SetMVInterface(struct mv_interface *mvi);
330 /* ************************************************************************** */
331 /* Access to font info */
332 /* ************************************************************************** */
333 struct otlookup;
335 struct fi_interface {
336 /* Insert a new lookup into the fontinfo lookup list */
337 void (*insert_lookup)(struct splinefont *, struct otlookup *);
339 /* Merge lookup in from another font */
340 void (*copy_into)(struct splinefont *, struct splinefont *,
341 struct otlookup *, struct otlookup *, int, struct otlookup *);
343 /* Removes any font info window for this font */
344 void (*destroy)(struct splinefont *);
346 extern struct fi_interface *fi_interface;
348 #define FISortInsertLookup (fi_interface->insert_lookup)
349 #define FIOTLookupCopyInto (fi_interface->copy_into)
350 #define FontInfo_Destroy (fi_interface->destroy)
352 void FF_SetFIInterface(struct fi_interface *fii);
354 /* ************************************************************************** */
355 /* Updating font windows */
356 /* ************************************************************************** */
358 struct fontviewbase;
359 struct bdffont;
361 struct fv_interface {
362 /* Create a new font view. Whatever that may entail */
363 struct fontviewbase *(*create)(struct splinefont *,int hide);
365 /* Create a new font view but without attaching it to a window */
366 struct fontviewbase *(*_create)(struct splinefont *);
368 /* Free a font view (we assume all windows have already been destroyed) */
369 void (*close)(struct fontviewbase *);
371 /* Free a font view (we assume all windows have already been destroyed) */
372 void (*free)(struct fontviewbase *);
374 /* Set the window title of this fontview */
375 void (*set_title)(struct fontviewbase *);
377 /* Set the window title of all fontviews associated with this font */
378 void (*set_titles)(struct splinefont *);
380 /* Refresh all displays of all fontviews associated with this font */
381 void (*refresh_all)(struct splinefont *);
383 /* Reformat this particular fontview (after encoding change, etc) */
384 void (*reformat_one)(struct fontviewbase *);
386 /* Reformat all fontviews associated with this font */
387 void (*reformat_all)(struct splinefont *);
389 /* The active layer has changed. Possibly because the old one was deleted */
390 void (*layer_changed)(struct fontviewbase *);
392 /* toggle the change indicator of this glyph in the font view */
393 void (*flag_glyph_changed)(struct splinechar *);
395 /* Retrieve the window's size in rows and columns */
396 int (*win_info)(struct fontviewbase *, int *cols, int *rows);
398 /* Is this font currently open? (It was open once, this check is to make */
399 /* sure the user hasn't closed it since they copied from it -- so we can */
400 /* follow references appropriately if the font we are pasting into doesn't*/
401 /* have the needed glyph */
402 int (*font_is_active)(struct splinefont *);
404 /* Sometimes we just need a fontview, any fontview as a last resort fallback*/
405 struct fontviewbase *(*first_font)(void);
407 /* Append this fontview to the list of them */
408 struct fontviewbase *(*append)(struct fontviewbase *);
410 /* Look through all loaded fontviews and see if any contains a font */
411 /* which lives in the given filename */
412 struct splinefont *(*font_of_filename)(const char *);
414 /* We've just added some extra encoding slots, which means we may need */
415 /* to increase the number of rows in the fontview display and perhaps */
416 /* adjust its scrollbar */
417 void (*extra_enc_slots)(struct fontviewbase *,int new_enc_max);
419 /* My fontviews contain a glyph cache (a BDFPieceMeal font) whenever */
420 /* more glyphs are added to the font, more bitmap glyph slots need to */
421 /* be added to the font cache */
422 void (*bigger_glyph_cache)(struct fontviewbase *,int new_glyph_cnt);
424 /* If we want to change the font displayed in a fontview */
425 void (*change_display_bitmap)(struct fontviewbase *, struct bdffont *);
427 /* We just deleted the active bitmap, so switch to a rasteriztion of the outlines */
428 void (*display_filled)(struct fontviewbase *);
430 /* When we revert a font we need to change the alegence of all outline */
431 /* glyph windows to the new value of the font */
432 void (*reattach_cvs)(struct splinefont *old, struct splinefont *new);
434 /* deselect any selected glyphs */
435 void (*deselect_all)(struct fontviewbase *);
437 /* Scroll (or whatever) the fontview so that the desired */
438 /* gid is displayed */
439 void (*display_gid)(struct fontviewbase *,int gid);
441 /* Scroll (or whatever) the fontview so that the desired */
442 /* encoding is displayed */
443 void (*display_enc)(struct fontviewbase *,int enc);
445 /* Scroll (or whatever) the fontview so that the desired */
446 /* glyph is displayed */
447 void (*select_gid)(struct fontviewbase *,int gid);
449 /* Close any open glyph instruction windows in the font */
450 int (*close_all_instrs)(struct splinefont *);
452 extern struct fv_interface *fv_interface;
454 #define FontViewCreate (fv_interface->create)
455 #define _FontViewCreate (fv_interface->_create)
456 #define FontViewClose (fv_interface->close)
457 #define FontViewFree (fv_interface->free)
458 #define FVSetTitle (fv_interface->set_title)
459 #define FVSetTitles (fv_interface->set_titles)
460 #define FVRefreshAll (fv_interface->refresh_all)
461 #define FontViewReformatOne (fv_interface->reformat_one)
462 #define FontViewReformatAll (fv_interface->reformat_all)
463 #define FontViewLayerChanged (fv_interface->layer_changed)
464 #define FVToggleCharChanged (fv_interface->flag_glyph_changed)
465 #define FVWinInfo (fv_interface->win_info)
466 #define SFIsActive (fv_interface->font_is_active)
467 #define FontViewFirst (fv_interface->first_font)
468 #define FVAppend (fv_interface->append)
469 #define FontWithThisFilename (fv_interface->font_of_filename)
470 #define FVAdjustScrollBarRows (fv_interface->extra_enc_slots)
471 #define FVBiggerGlyphCache (fv_interface->bigger_glyph_cache)
472 #define FVChangeDisplayBitmap (fv_interface->change_display_bitmap)
473 #define FVShowFilled (fv_interface->display_filled)
474 #define FVReattachCVs (fv_interface->reattach_cvs)
475 #define FVDisplayGID (fv_interface->display_gid)
476 #define FVDisplayEnc (fv_interface->display_enc)
477 #define FVChangeGID (fv_interface->select_gid)
478 #define SFCloseAllInstrs (fv_interface->close_all_instrs)
480 void FF_SetFVInterface(struct fv_interface *fvi);
482 /* ************************************************************************** */
483 /* Clibboard access (copy/paste) */
484 /* ************************************************************************** */
486 struct clip_interface {
487 /* Announce we own the clipboard selection */
488 void (*grab_clip)(void);
489 /* Either place data in the clipboard of a given type, or */
490 /* provide a routine to call which will give data on demand */
491 /* (and another routine to clean things up) */
492 void (*add_data_type)(const char *type, void *data, int cnt, int size,
493 void *(*gendata)(void *,int32 *len), void (*freedata)(void *));
494 /* Does the clipboard contain something of the given type? */
495 int (*clip_has_type)(const char *mimetype);
496 /* Ask for the clipboard, and waits (and returns) for the response */
497 void *(*request_clip)(const char *mimetype,int *len);
500 extern struct clip_interface *clip_interface;
502 #define ClipboardGrab (clip_interface->grab_clip)
503 #define ClipboardAddDataType (clip_interface->add_data_type)
504 #define ClipboardRequest (clip_interface->request_clip)
505 #define ClipboardHasType (clip_interface->clip_has_type)
507 void FF_SetClipInterface(struct clip_interface *clipi);
509 extern const char *NOUI_TTFNameIds(int id);
510 extern const char *NOUI_MSLangString(int language);
511 #endif