-
Notifications
You must be signed in to change notification settings - Fork 3
/
guifile.c
3009 lines (2519 loc) · 90.7 KB
/
guifile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2008 Department of Mathematical Sciences, New Mexico State University
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* DEPARTMENT OF MATHEMATICAL SCIENCES OR NEW MEXICO STATE UNIVERSITY BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "gbdfed.h"
#include "labcon.h"
#ifdef HAVE_XLIB
#include <gdk/gdkx.h>
#endif
/*
* These are formats that can appear in the editor for importing/loading and
* exporting fonts.
*/
#define BDF_FORMAT 1
#define CONSOLE_FORMAT 2
#define PKGF_FORMAT 3
#define FNT_FORMAT 4
#define HBF_FORMAT 5
#define OTF_FORMAT 6
#define HEX_FORMAT 7
#define PSF_FORMAT 8
#define PSFUNI_FORMAT 9
/*
* An array of filters used for the open/import and save dialogs.
*/
static GtkFileFilter *filename_filters[10];
/*
* This variable is used to track whether the save dialog has been closed
* so the guifile_save_as_wait() routine knows when to return to the main
* application.
*/
static gboolean save_dialog_done;
#ifdef HAVE_FREETYPE
#include FT_GLYPH_H
#include FT_SFNT_NAMES_H
#include FT_TRUETYPE_TABLES_H
/*
* Globals used for FreeType.
*/
static FT_Library library;
static FT_Face face;
/*
* Globals used for importing OpenType fonts.
*/
static gboolean ftinit = FALSE;
static gboolean otf_collection;
static gboolean otf_face_open;
static gint otf_select_done = 0;
static gchar *otf_fullpath;
/*
* These are the widgets that will be needed for importing OpenType fonts.
*/
static GtkWidget *otf_dialog;
static GtkWidget *otf_faces;
static GtkWidget *otf_platforms;
static GtkWidget *otf_encodings;
static GtkWidget *otf_point_size;
static GtkWidget *otf_hres;
static GtkWidget *otf_vres;
/*
* List of platform IDs seen that is used when platforms are selected
* from OpenType fonts.
*/
static gint16 platforms[32];
static gint nplatforms;
/*
* List of encoding IDs seen that is used when encodings are selected
* from OpenType fonts.
*/
static gint16 encodings[34];
static gint nencodings;
/*
* Variables to hold the selected platform and encoding ID's.
*/
static gint16 otf_pid_pos;
static gint16 otf_eid_pos;
#endif /* HAVE_FREETYPE */
#ifdef HAVE_XLIB
/*
* These are for importing fonts from the X server.
*/
#define _XSRV_MAX_FONTS 32767
#define _XSRV_DEFAULT_FILTER "-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
static GtkWidget *xsrv_dialog;
static GtkWidget *xsrv_filter_text;
static GtkWidget *xsrv_selection_text;
static GtkWidget *xsrv_font_list;
static GtkWidget *xsrv_import;
/*
* Because the grab dialog is shared amongst the editors, this tracks which
* editor has control of the font list.
*/
static guint xsrv_active_editor;
#endif /* HAVE_XLIB */
/*
* Widgets for dealing with exporting PSF fonts.
*/
static GtkWidget *psf_export_frame;
static GtkWidget *psf_export_options;
/*
* Widgets for selecting fonts from a Windows font archive.
*/
static GtkWidget *fnt_dialog;
static GtkWidget *fnt_font_list;
static GtkWidget *fnt_load_button;
/*
* This is a list of Windows fonts that have been selected. It assumes that
* the font file will never contain more than 32 fonts.
*/
static gint fnt_selected[32];
static gint fnt_selected_count;
/*
* A structure used to pass data to the load and cancel callbacks when dealing
* with FON/FNT fonts.
*/
typedef struct {
gchar *file;
gchar *dir;
gchar *dot;
bdffnt_font_t font;
} _bdffnt_callback_data_t;
/*
* This is used in a couple of cases to point at the active editor.
*/
static gbdfed_editor_t *active_editor;
static void
make_file_chooser_filters(void)
{
int i;
if (filename_filters[0] != NULL)
return;
filename_filters[BDF_FORMAT] = gtk_file_filter_new();
gtk_file_filter_add_pattern(filename_filters[BDF_FORMAT],
"*.[Bb][Dd][Ff]");
filename_filters[CONSOLE_FORMAT] = gtk_file_filter_new();
gtk_file_filter_add_pattern(filename_filters[CONSOLE_FORMAT], "*");
filename_filters[PKGF_FORMAT] = gtk_file_filter_new();
gtk_file_filter_add_pattern(filename_filters[PKGF_FORMAT],
"*[PpGg][KkFf]");
filename_filters[FNT_FORMAT] = gtk_file_filter_new();
gtk_file_filter_add_pattern(filename_filters[FNT_FORMAT],
"*.[FfEeDd][OoNnXxLl][NnTtEeLl]");
filename_filters[HEX_FORMAT] = gtk_file_filter_new();
gtk_file_filter_add_pattern(filename_filters[HEX_FORMAT],
"*.[Hh][Ee][Xx]");
filename_filters[PSF_FORMAT] = gtk_file_filter_new();
gtk_file_filter_add_pattern(filename_filters[PSF_FORMAT],
"*.[Ps][Ss][Ff]*");
/*
* This one is basically for exporting unimap files that belong to PSF
* fonts.
*/
filename_filters[PSFUNI_FORMAT] = gtk_file_filter_new();
gtk_file_filter_add_pattern(filename_filters[PSFUNI_FORMAT],
"*.[Uu][Nn][Ii]");
#ifdef HAVE_HBF
filename_filters[HBF_FORMAT] = gtk_file_filter_new();
gtk_file_filter_add_pattern(filename_filters[HBF_FORMAT],
"*.[Hh][Bb][Ff]");
#endif
#ifdef HAVE_FREETYPE
filename_filters[OTF_FORMAT] = gtk_file_filter_new();
gtk_file_filter_add_pattern(filename_filters[OTF_FORMAT],
"*.[OoTt][Tt][FfCcEe]");
#endif /* HAVE_FREETYPE */
filename_filters[0] = (GtkFileFilter *) 1;
/*
* Add a reference to all the filters so they don't cause a delayed crash
* when popping up the import dialog multiple times.
*/
for (i = 1; i < 10; i++) {
if (filename_filters[i] != NULL)
g_object_ref(filename_filters[i]);
}
}
static gboolean
export_font(gchar *filename, gbdfed_editor_t *ed, gboolean copy_filename)
{
FILE *out;
bdf_font_t *font;
gboolean local_font = FALSE;
bdf_property_t vanity;
FontgridSelectionInfo sinfo;
font = fontgrid_get_font(FONTGRID(ed->fgrid));
/*
* First, attempt to make a backup if they are specified.
*/
if (options.backups) {
out = fopen(filename, "rb");
if (out != 0) {
fclose(out);
/*
* Attempt to make a backup.
*/
sprintf(buffer2, "%s.bak", filename);
/*
* %PLATFORM_CHECK%
*
* Don't return here because we want to save the font even if a
* backup can't be made.
*/
if (rename(filename, buffer2))
guiutil_error_message(ed->shell,
"Backups: Unable to make a backup.");
}
}
/*
* Try to open the file for writing. Only PSF needs binary.
*/
out = (ed->export_format != PSF_FORMAT) ?
fopen(filename, "w") : fopen(filename, "wb");
if (out == 0) {
if (ed->export_format == BDF_FORMAT)
sprintf(buffer2, "Save Font: Unable to write to %s.", filename);
else
sprintf(buffer2, "Export Font: Unable to write to %s.", filename);
guiutil_error_message(ed->shell, buffer2);
return FALSE;
}
switch (ed->export_format) {
case BDF_FORMAT:
if (!font) {
/*
* We need to create a font with the default options so it
* can be written out as a skeleton.
*/
font = bdf_new_font("unnamed",
options.font_opts.point_size,
options.font_opts.resolution_x,
options.font_opts.resolution_y,
options.font_opts.font_spacing,
options.font_opts.bits_per_pixel);
local_font = TRUE;
}
/*
* Add a custom property if the font has been
*/
if (font->modified || local_font == TRUE) {
sprintf(buffer2, "Edited with gbdfed %s.", GBDFED_VERSION);
vanity.name = "_GBDFED_INFO";
vanity.format = BDF_ATOM;
vanity.value.atom = buffer2;
bdf_add_font_property(font, &vanity);
}
bdf_save_font(out, font, &options.font_opts, 0, 0);
if (local_font == TRUE)
bdf_free_font(font);
break;
case HEX_FORMAT:
bdf_export_hex(out, font, &options.font_opts, 0, 0);
break;
case PSF_FORMAT:
sinfo.start = sinfo.end = 0;
(void) fontgrid_has_selection(FONTGRID(ed->fgrid), &sinfo);
if (sinfo.start == sinfo.end) {
sinfo.start = font->glyphs[0].encoding;
sinfo.end = font->glyphs[font->glyphs_used - 1].encoding;
}
switch (bdf_export_psf(out, font, &options.font_opts,
sinfo.start, sinfo.end)) {
case BDF_OK:
buffer1[0] = 0;
break;
case BDF_BAD_RANGE:
sprintf(buffer1, "Export PSF: Invalid range %d-%d.\n",
sinfo.start, sinfo.end);
break;
case BDF_PSF_CORRUPT_UTF8:
strcpy(buffer1,
"Export PSF: Bad UTF-8 encountered in the mappings.");
break;
}
if (buffer1[0] != 0)
/*
* Something went wrong during the PSF export.
*/
guiutil_error_message(ed->shell, buffer1);
}
fclose(out);
/*
* The rest of this only applies to BDF fonts and not PSF or HEX fonts.
* PSF and HEX fonts have their own extensions in the save dialog, but
* that does not affect the actual file name in the editor.
*/
if (ed->export_format == BDF_FORMAT) {
/*
* Copy the path and filename into the editor if specified.
*/
if (copy_filename) {
if (ed->path)
g_free(ed->path);
if (ed->file)
g_free(ed->file);
ed->path = ed->file = 0;
ed->file = g_path_get_basename(filename);
ed->path = g_path_get_dirname(filename);
}
/*
* Mark the font as being unmodified.
*/
fontgrid_set_font_modified(FONTGRID(ed->fgrid), FALSE);
/*
* Update the window title accordingly.
*/
if (ed->file)
sprintf(buffer1, "%s - %s", g_get_prgname(), ed->file);
else
sprintf(buffer1, "%s - (unnamed%d)", g_get_prgname(), ed->id);
gtk_window_set_title(GTK_WINDOW(ed->shell), buffer1);
/*
* Since the font was saved as BDF, it is no longer marked as being
* imported.
*/
ed->imported = FALSE;
}
return TRUE;
}
static void
really_save_font(guint ed_id)
{
gbdfed_editor_t *ed = editors + ed_id;
gchar *fname;
FILE *have;
#if (GTK_MAJOR_VERSION >= 2 && GTK_MINOR_VERSION >= 10)
GtkRecentManager *recent;
#endif
fname = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(ed->save_dialog));
have = fopen(fname, "rb");
if (have != 0) {
fclose(have);
/*
* Check to see if the user wishes to overwrite the existing font.
*/
sprintf(buffer2, "Save Font: %s exists.\nDo you wish to overwrite?",
fname);
if (guiutil_yes_or_no(ed->shell, buffer2, TRUE) == FALSE) {
g_free(fname);
return;
}
}
/*
* If the write was successful, hide the dialog.
*/
if (export_font(fname, ed, TRUE)) {
save_dialog_done = TRUE;
gtk_widget_hide(ed->save_dialog);
#if (GTK_MAJOR_VERSION >= 2 && GTK_MINOR_VERSION >= 10)
recent = gtk_recent_manager_get_default();
sprintf(buffer1, "file://%s", fname);
if (gtk_recent_manager_has_item(recent,
(const gchar *) buffer1) == FALSE)
gtk_recent_manager_add_item(recent,
(const gchar *) buffer1);
#endif
}
g_free(fname);
}
/*
* This callback routine handles errors and updating the progress bar if
* one is being used.
*/
static void
handle_import_messages(bdf_callback_struct_t *call_data, void *client_data)
{
if (call_data->reason == BDF_ERROR) {
sprintf(buffer1, "Import Font:%d: error: See the font messages.",
call_data->errlineno);
guiutil_error_message(GTK_WIDGET(client_data), buffer1);
}
}
/**************************************************************************
*
* BDF section.
*
**************************************************************************/
static void
load_bdf_font(gbdfed_editor_t *ed, const gchar *fullpath, const gchar *dir,
const gchar *file)
{
FILE *in;
bdf_font_t *font;
/*
* Check to see if the file can be opened.
*/
if ((in = fopen(fullpath, "rb")) == 0) {
sprintf(buffer1, "Import Font: Unable to open %s.", file);
guiutil_error_message(ed->shell, buffer1);
return;
}
guiutil_busy_cursor(ed->shell, TRUE);
if (ed->open_dialog != NULL)
guiutil_busy_cursor(ed->open_dialog, TRUE);
font = bdf_load_font(in, &options.font_opts,
handle_import_messages, (void *) ed->shell);
guiutil_busy_cursor(ed->shell, FALSE);
if (ed->open_dialog != NULL)
guiutil_busy_cursor(ed->open_dialog, FALSE);
if (font == 0) {
fclose(in);
sprintf(buffer1, "Import Font: Unable to load %s.", file);
guiutil_error_message(ed->shell, buffer1);
return;
}
fclose(in);
if (ed->open_dialog != NULL)
gtk_widget_hide(ed->open_dialog);
/*
* Delete the file and path names so they can be updated.
*/
if (ed->file != 0)
g_free(ed->file);
if (ed->path != 0)
g_free(ed->path);
ed->file = ed->path = 0;
ed->file = strdup(file);
ed->path = strdup(dir);
/*
* Update the window title.
*/
if (font->modified)
sprintf(buffer1, "%s - %s [modified]", g_get_prgname(), ed->file);
else
sprintf(buffer1, "%s - %s", g_get_prgname(), ed->file);
gtk_window_set_title(GTK_WINDOW(ed->shell), buffer1);
/*
* Tell the glyphtest widget to remove references to the current font if
* it has any, and redraw.
*/
if (glyphtest != 0)
glyphtest_remove_font(GLYPHTEST(glyphtest),
fontgrid_get_font(FONTGRID(ed->fgrid)));
fontgrid_set_font(FONTGRID(ed->fgrid), font, -1);
/*
* Finally, update the font name field.
*/
gtk_entry_set_text(GTK_ENTRY(ed->fontname),
fontgrid_get_font_name(FONTGRID(ed->fgrid)));
/*
* Make sure the imported flag is cleared in this case.
*/
ed->imported = FALSE;
}
/**************************************************************************
*
* Console section.
*
**************************************************************************/
static void
load_console_font(gbdfed_editor_t *ed, gchar *fullpath, gchar *dot,
gchar *dir, gchar *file)
{
FILE *in;
gbdfed_editor_t *ep;
gint i, j, nfonts, len;
gchar *np;
bdf_font_t *fonts[3];
/*
* Check to see if the file can be opened.
*/
if ((in = fopen(fullpath, "rb")) == 0) {
sprintf(buffer1, "Import Font: Unable to open %s.", fullpath);
guiutil_error_message(ed->shell, buffer1);
return;
}
guiutil_busy_cursor(ed->shell, TRUE);
guiutil_busy_cursor(ed->open_dialog, TRUE);
i = bdf_load_console_font(in, &options.font_opts, 0, 0, fonts, &nfonts);
guiutil_busy_cursor(ed->shell, FALSE);
guiutil_busy_cursor(ed->open_dialog, FALSE);
fclose(in);
if (i != BDF_OK) {
/*
* Free up any font structures that happened to be loaded.
*/
for (j = 0; j < nfonts; j++)
bdf_free_font(fonts[j]);
sprintf(buffer1, "Import Font: %s not a console font.", fullpath);
guiutil_error_message(ed->shell, buffer1);
return;
}
gtk_widget_hide(ed->open_dialog);
/*
* Handle creation of the editors. In the case of some console fonts,
* there are three different sizes contained in the font.
*/
for (i = 0; i < nfonts; i++) {
if (i)
ep = editors + gbdfed_make_editor(0, FALSE);
else {
ep = ed;
/*
* Erase the existing file and directory name in the "root"
* editor.
*/
if (ep->file)
g_free(ep->file);
if (ep->path)
g_free(ep->path);
ep->file = ep->path = 0;
/*
* Tell the glyphtest widget to remove references to the current
* font, if it has any, and redraw.
*/
if (glyphtest != 0)
glyphtest_remove_font(GLYPHTEST(glyphtest),
fontgrid_get_font(FONTGRID(ep->fgrid)));
}
/*
* Make an XLFD name for the font using the filename. Run through the
* file name and change all occurences of '-' to '_' to avoid problems
* with '-' being the XLFD field separator.
*/
for (j = 0, np = file; np < dot; np++, j++)
buffer2[j] = (*np != '-') ? *np : '_';
buffer2[j] = 0;
fonts[i]->name =
bdf_make_xlfd_name(fonts[i], "Unknown", buffer2);
bdf_update_properties_from_name(fonts[i]);
len = (gint) (dot - file);
/*
* Create the default name for the font file.
*/
if (nfonts == 3) {
switch (i) {
case 0:
sprintf(buffer1, "%.*s-16.bdf", len, file);
break;
case 1:
sprintf(buffer1, "%.*s-14.bdf", len, file);
break;
case 2:
sprintf(buffer1, "%.*s-08.bdf", len, file);
break;
}
} else
sprintf(buffer1, "%.*s.bdf", len, file);
/*
* Set the filename for the editor.
*/
ep->file = strdup(buffer1);
ep->path = strdup(dir);
/*
* Set the new editor title.
*/
sprintf(buffer1, "%s - %s [modified]", g_get_prgname(), ep->file);
gtk_window_set_title(GTK_WINDOW(ep->shell), buffer1);
/*
* Change the font in the editor.
*/
fontgrid_set_font(FONTGRID(ep->fgrid), fonts[i], -1);
/*
* Indicate the font was imported.
*/
ed->imported = TRUE;
/*
* Update the XLFD name.
*/
gtk_entry_set_text(GTK_ENTRY(ep->fontname),
fontgrid_get_font_name(FONTGRID(ep->fgrid)));
}
}
/**************************************************************************
*
* PK/GF section.
*
**************************************************************************/
static void
load_pkgf_font(gbdfed_editor_t *ed, gchar *fullpath, gchar *dot,
gchar *dir, gchar *file)
{
FILE *in;
gint i;
gchar *np;
bdf_font_t *font;
/*
* Check to see if the file can be opened.
*/
if ((in = fopen(fullpath, "rb")) == 0) {
sprintf(buffer1, "Import Font: Unable to open %s.", file);
guiutil_error_message(ed->shell, buffer1);
return;
}
guiutil_busy_cursor(ed->shell, TRUE);
guiutil_busy_cursor(ed->open_dialog, TRUE);
i = bdf_load_mf_font(in, &options.font_opts, 0, 0, &font);
guiutil_busy_cursor(ed->shell, FALSE);
guiutil_busy_cursor(ed->open_dialog, FALSE);
fclose(in);
if (i != BDF_OK) {
sprintf(buffer1, "Import Font: %s not a PK or GF font.", fullpath);
guiutil_error_message(ed->shell, buffer1);
return;
}
gtk_widget_hide(ed->open_dialog);
/*
* Make an XLFD name for the font using the filename. Run through the
* file name and change all occurences of '-' to '_' to avoid problems
* with '-' being the XLFD field separator.
*/
for (i = 0, np = file; np < dot; np++, i++)
buffer2[i] = (*np != '-') ? *np : '_';
buffer2[i] = 0;
font->name = bdf_make_xlfd_name(font, "Unknown", buffer2);
bdf_update_properties_from_name(font);
/*
* Now set up a file name.
*/
sprintf(buffer1, "%.*s.bdf", (int) (dot - file), file);
/*
* Delete the file and path names so they can be updated.
*/
if (ed->file != 0)
g_free(ed->file);
if (ed->path != 0)
g_free(ed->path);
ed->file = strdup(buffer1);
ed->path = strdup(dir);
/*
* Update the window title.
*/
sprintf(buffer1, "%s - %s [modified]", g_get_prgname(), ed->file);
gtk_window_set_title(GTK_WINDOW(ed->shell), buffer1);
/*
* Tell the glyphtest widget to remove references to the current font if
* it has any, and redraw.
*/
if (glyphtest != 0)
glyphtest_remove_font(GLYPHTEST(glyphtest),
fontgrid_get_font(FONTGRID(ed->fgrid)));
fontgrid_set_font(FONTGRID(ed->fgrid), font, -1);
/*
* Indicate the font was imported.
*/
ed->imported = TRUE;
/*
* Finally, update the font name field.
*/
gtk_entry_set_text(GTK_ENTRY(ed->fontname),
fontgrid_get_font_name(FONTGRID(ed->fgrid)));
}
/**************************************************************************
*
* FNT section.
*
**************************************************************************/
/*
* Toggles the "Ok" button on or off depending if there was a selection or
* not.
*/
static void
fnt_check_load_button(GtkWidget *w, gpointer data)
{
GtkTreeSelection *sel = GTK_TREE_SELECTION(data);
if (gtk_tree_selection_count_selected_rows(sel) == 0)
gtk_widget_set_sensitive(fnt_load_button, FALSE);
else
gtk_widget_set_sensitive(fnt_load_button, TRUE);
}
static void
fnt_unselect_all(GtkWidget *w, gpointer data)
{
GtkTreeSelection *sel = GTK_TREE_SELECTION(data);
gtk_tree_selection_unselect_all(sel);
/*
* Disable the Ok button since everything is unselected.
*/
gtk_widget_set_sensitive(fnt_load_button, FALSE);
}
static void
fnt_select_all(GtkWidget *w, gpointer data)
{
GtkTreeSelection *sel = GTK_TREE_SELECTION(data);
gtk_tree_selection_select_all(sel);
/*
* Enable the Ok button since everything is unselected.
*/
gtk_widget_set_sensitive(fnt_load_button, TRUE);
}
static void
fnt_foreach_selected(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
gpointer data)
{
gint *id;
id = gtk_tree_path_get_indices(path);
fnt_selected[fnt_selected_count++] = *id;
}
static void
fnt_load_selected_fonts(GtkWidget *w, gpointer data)
{
gbdfed_editor_t *ep, *ed = editors + GPOINTER_TO_UINT(data);
GtkTreeSelection *sel =
gtk_tree_view_get_selection(GTK_TREE_VIEW(fnt_font_list));
gint i, nfonts;
gboolean loaded;
bdf_font_t **fonts;
_bdffnt_callback_data_t *cdata;
fnt_selected_count = 0;
if ((cdata = g_object_get_data(G_OBJECT(w),
"bdffnt_callback_data")) == NULL) {
/*
* Big problem. Should never happen.
*/
guiutil_error_message(editors[0].shell,
"BIG PROBLEM PASSING OPEN FON/FNT FONT!!!!");
return;
}
/*
* This collects all the selected indices from the list and puts them in
* the global fnt_selected array.
*/
gtk_tree_selection_selected_foreach(sel, fnt_foreach_selected, NULL);
/*
* CHANGE - maybe.
*/
if (fnt_selected_count == 0)
return;
/*
* Hide the dialog that allowed selection of the fonts in the file.
*/
gtk_widget_hide(fnt_dialog);
guiutil_busy_cursor(ed->shell, TRUE);
guiutil_busy_cursor(ed->open_dialog, TRUE);
fonts = (bdf_font_t **)
g_malloc(sizeof(bdf_font_t *) * fnt_selected_count);
for (loaded = TRUE, nfonts = 0;
nfonts < fnt_selected_count && loaded == TRUE;
nfonts++) {
/*
* If the current font can't be loaded, then assume the rest are
* not available either.
*/
if (bdffnt_load_font(cdata->font, fnt_selected[nfonts],
0, 0, &fonts[nfonts]) != 0) {
/*
* It is easier to get the font name from the font than it is
* from the list store.
*/
(void) bdffnt_get_facename(cdata->font, fnt_selected[nfonts], 0,
(unsigned char *) buffer1);
sprintf(buffer2, "Import Font: Unable to load %s from %s.",
buffer1, cdata->file);
guiutil_error_message(ed->shell, buffer2);
guiutil_busy_cursor(ed->shell, FALSE);
guiutil_busy_cursor(ed->open_dialog, FALSE);
loaded = FALSE;
}
}
guiutil_busy_cursor(ed->shell, FALSE);
guiutil_busy_cursor(ed->open_dialog, FALSE);
/*
* If no fonts were loaded, then simply return with the open dialog still
* up, giving the user a chance to load another font.
*/
if (nfonts == 0) {
g_free(fonts);
return;
}
/*
* Hide the open dialog.
*/
gtk_widget_hide(ed->open_dialog);
/*
* Create the editors for the fonts that did get loaded.
*/
for (i = 0; i < nfonts; i++) {
if (i)
ep = editors + gbdfed_make_editor(0, FALSE);
else {
ep = ed;
/*
* Erase the existing file and directory name in the "root"
* editor.
*/
if (ep->file)
g_free(ep->file);
if (ep->path)
g_free(ep->path);
ep->file = ep->path = 0;
/*
* Tell the glyphtest widget to remove references to the current
* font, if it has any, and redraw.
*/
if (glyphtest != 0)
glyphtest_remove_font(GLYPHTEST(glyphtest),
fontgrid_get_font(FONTGRID(ep->fgrid)));
}
/*
* Make the BDF file name for the font.
*/
sprintf(buffer1, "%.*s%d.bdf", (int) (cdata->dot - cdata->file),
cdata->file, fonts[i]->point_size);
ep->file = strdup(buffer1);
ep->path = strdup(cdata->dir);
/*
* Set the new editor title.
*/
sprintf(buffer1, "%s - %s [modified]", g_get_prgname(), ep->file);
gtk_window_set_title(GTK_WINDOW(ep->shell), buffer1);
/*
* Change the font in the editor.
*/
fontgrid_set_font(FONTGRID(ep->fgrid), fonts[i], -1);
/*
* Indicate the font was imported.
*/
ep->imported = TRUE;
/*
* Update the XLFD name.
*/
gtk_entry_set_text(GTK_ENTRY(ep->fontname),
fontgrid_get_font_name(FONTGRID(ep->fgrid)));
}
g_free(cdata->file);
g_free(cdata->dir);
bdffnt_close_font(cdata->font);
g_free(fonts);
}
static void
fnt_cancel(GtkWidget *w, gpointer data)
{
_bdffnt_callback_data_t *cdata;
/*
* If the load callback stole the data already, this will be NULL.
*/
if ((cdata = g_object_get_data(G_OBJECT(w),
"bdffnt_callback_data")) == NULL) {
/*
* Big problem. Should never happen.