-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgbdfed.c
2504 lines (2170 loc) · 84.7 KB
/
gbdfed.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"
/**************************************************************************
*
* Application globals.
*
**************************************************************************/
gchar buffer1[BUFSIZ];
gchar buffer2[BUFSIZ];
gbdfed_options_t options;
/*
* The list of editors that exist.
*/
gbdfed_editor_t *editors;
guint num_editors;
/**************************************************************************
*
* Forward declarations and local variables.
*
**************************************************************************/
/*
* These are formats that can appear in the editor for importing/loading and
* exporting fonts.
*/
#define XMBDFED_BDF_FORMAT 1
#define XMBDFED_CONSOLE_FORMAT 2
#define XMBDFED_PKGF_FORMAT 3
#define XMBDFED_FNT_FORMAT 4
#define XMBDFED_HBF_FORMAT 5
#define XMBDFED_TTF_FORMAT 6
#define XMBDFED_PSF_FORMAT 7
#define XMBDFED_HEX_FORMAT 8
/**************************************************************************
*
* Application icons.
*
**************************************************************************/
static const gchar *gbdfed_16x16[] = {
/* width height num_colors chars_per_pixel */
" 16 16 5 1",
/* colors */
". c #dcdcdc",
"# c #ff0000",
"a c #ffffff",
"b c #000000",
"c c #b2c0dc",
/* pixels */
"..#.............",
"a.#.a.a.a.a.a.a.",
"..#.............",
"a.#bbba.a.a.a.b.",
"..#.bbb......b..",
"a.#.abbba.a.b.a.",
"..#...bbb..b....",
"a.#.a.abb.b.a.a.",
"..#....b.bb.....",
"a.#.a.b.abbba.a.",
"..#..b....bbb...",
"a.#.b.a.a.abbba.",
"..#b........bbb.",
"################",
"..#.............",
"c.#.c.c.c.c.c.c."
};
static const gchar *gbdfed_32x32[] = {
/* width height num_colors chars_per_pixel */
" 32 32 4 1",
/* colors */
". c #d9d9d9",
"# c #ffffff",
"a c #ff0000",
"b c #000000",
/* pixels */
".##a##.##.##.##.##.##.##.##.##.#",
".##a##.##.##.##.##.##.##.##.##.#",
"...a............................",
".##a##.##.##.##.##.##.##.##.##.#",
".##a##.##.##.##.##.##.##.##.##.#",
"...a............................",
".##abb.bb.bb.##.##.##.##.##.bb.#",
".##abb.bb.bb.##.##.##.##.##.bb.#",
"...a............................",
".##a##.bb.bb.bb.##.##.##.bb.##.#",
".##a##.bb.bb.bb.##.##.##.bb.##.#",
"...a............................",
".##a##.##.bb.bb.bb.##.bb.##.##.#",
".##a##.##.bb.bb.bb.##.bb.##.##.#",
"...a............................",
".##a##.##.##.bb.##.bb.##.##.##.#",
".##a##.##.##.bb.##.bb.##.##.##.#",
"...a............................",
".##a##.##.bb.##.bb.bb.bb.##.##.#",
".##a##.##.bb.##.bb.bb.bb.##.##.#",
"...a............................",
".##a##.bb.##.##.##.bb.bb.bb.##.#",
".##a##.bb.##.##.##.bb.bb.bb.##.#",
"...a............................",
".##abb.##.##.##.##.##.bb.bb.bb.#",
".##abb.##.##.##.##.##.bb.bb.bb.#",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
".##a##.##.##.##.##.##.##.##.##.#",
".##a##.##.##.##.##.##.##.##.##.#",
"...a............................",
".##a##.##.##.##.##.##.##.##.##.#",
".##a##.##.##.##.##.##.##.##.##.#"
};
static const gchar *gbdfed_48x48[] = {
/* width height num_colors chars_per_pixel */
" 48 48 4 1",
/* colors */
". c #dcdcdc",
"# c #ff0000",
"a c #ffffff",
"b c #000000",
/* pixels */
"....#...........................................",
".aaa#aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa",
".aaa#aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa",
".aaa#aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa..aa.aaa.aaa",
"....#...........................................",
".aaa#bbb.bbb.bbb.aaa.aaa.aaa.aaa.aaa.aaa.aaa.bbb",
".aaa#bbb.bbb.bbb.aaa.aaa.aaa.aaa.aaa.aaa.aaa.bbb",
".aaa#bbb.bbb.bbb.aaa.aaa.aaa.aaa.aaa.aaa.aaa.bbb",
"....#...........................................",
".aaa#aaa.bbb.bbb.bbb.aaa.aaa.aaa.aaa.aaa.bbb.aaa",
".aaa#aaa.bbb.bbb.bbb.aaa.aaa.aaa.aaa.aaa.bbb.aaa",
".aaa#aaa.bbb.bbb.bbb.aaa.aaa.aaa.aaa.aaa.bbb.aaa",
"....#...........................................",
".aaa#aaa.aaa.bbb.bbb.bbb.aaa.aaa.aaa.bbb.aaa.aaa",
".aaa#aaa.aaa.bbb.bbb.bbb.aaa.aaa.aaa.bbb.aaa.aaa",
".aaa#aaa.aaa.bbb.bbb.bbb.aaa.aaa.aaa.bbb.aaa.aaa",
"....#...........................................",
".aaa#aaa.aaa.aaa.bbb.bbb.bbb.aaa.bbb.aaa.aaa.aaa",
".aaa#aaa.aaa.aaa.bbb.bbb.bbb.aaa.bbb.aaa.aaa.aaa",
".aaa#aaa.aaa.aaa.bbb.bbb.bbb.aaa.bbb.aaa.aaa.aaa",
"....#...........................................",
".aaa#aaa.aaa.aaa.aaa.bbb.aaa.bbb.aaa.aaa.aaa.aaa",
".aaa#aaa.aaa.aaa.aaa.bbb.aaa.bbb.aaa.aaa.aaa.aaa",
".aaa#aaa.aaa.aaa.aaa.bbb.aaa.bbb.aaa.aaa.aaa.aaa",
"....#...........................................",
".aaa#aaa.aaa.aaa.bbb.aaa.bbb.bbb.bbb.aaa.aaa.aaa",
".aaa#aaa.aaa.aaa.bbb.aaa.bbb.bbb.bbb.aaa.aaa.aaa",
".aaa#aaa.aaa.aaa.bbb.aaa.bbb.bbb.bbb.aaa.aaa.aaa",
"....#...........................................",
".aaa#aaa.aaa.bbb.aaa.aaa.aaa.bbb.bbb.bbb.aaa.aaa",
".aaa#aaa.aaa.bbb.aaa.aaa.aaa.bbb.bbb.bbb.aaa.aaa",
".aaa#aaa.aaa.bbb.aaa.aaa.aaa.bbb.bbb.bbb.aaa.aaa",
"....#...........................................",
".aaa#aaa.bbb.aaa.aaa.aaa.aaa.aaa.bbb.bbb.bbb.aaa",
".aaa#aaa.bbb.aaa.aaa.aaa.aaa.aaa.bbb.bbb.bbb.aaa",
".aaa#aaa.bbb.aaa.aaa.aaa.aaa.aaa.bbb.bbb.bbb.aaa",
"....#...........................................",
".aaa#bbb.aaa.aaa.aaa.aaa.aaa.aaa.aaa.bbb.bbb.bbb",
".aaa#bbb.aaa.aaa.aaa.aaa.aaa.aaa.aaa.bbb.bbb.bbb",
".aaa#bbb.aaa.aaa.aaa.aaa.aaa.aaa.aaa.bbb.bbb.bbb",
"################################################",
".aaa#aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa",
".aaa#aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa",
".aaa#aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa",
"....#...........................................",
".aaa#aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa",
".aaa#aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa",
".aaa#aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa.aaa"
};
static gboolean icons_set = FALSE;
/**************************************************************************
*
* GTK signal handlers.
*
**************************************************************************/
static gboolean
quit_application(GtkWidget *w, GdkEvent *ev, gpointer data)
{
guint i, modified;
for (i = modified = 0; i < num_editors; i++) {
if (fontgrid_get_font_modified(FONTGRID(editors[i].fgrid)))
modified++;
}
if (modified) {
if (modified == 1)
sprintf(buffer1, "Save Font: One font was modified. Save?");
else
sprintf(buffer1, "Save Font: %d fonts were modified. Save?",
modified);
if (guiutil_yes_or_no(editors[0].shell, buffer1, TRUE)) {
/*
* Go through each editor and ask if the font should be saved if
* it has been modified.
*/
for (i = 0; i < num_editors; i++) {
if (fontgrid_get_font_modified(FONTGRID(editors[i].fgrid))) {
/*
* Ask if this font should be saved.
*/
if (editors[i].file)
sprintf(buffer1, "Save Font: Save %s?", editors[i].file);
else
sprintf(buffer1, "Save Font: Save unnamed%d.bdf?", i);
/*
* Always ask this question using the shell window of the
* first editor so the dialog box doesn't move around.
*/
if (guiutil_yes_or_no(editors[0].shell, buffer1, TRUE))
guifile_save_as_wait(w, GUINT_TO_POINTER(i));
}
}
}
}
/*
* Ask if the user really wants to exit if their preferences specify this
* question should be asked.
*/
if (options.really_exit &&
!guiutil_yes_or_no(editors[0].shell, "Really Quit?", TRUE))
return TRUE;
/*
* Call all the cleanup routines in case something really needs to be
* deallocated.
*/
guigedit_cleanup();
guiedit_preference_cleanup();
guiutil_cursor_cleanup();
guihelp_cleanup();
bdf_cleanup();
gtk_main_quit();
exit(0);
}
static void
show_editor(GtkWidget *w, gpointer data)
{
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(data);
/*
* Nothing seems to force the original window to the top of the stack
* on the screen, but this supposedly does everything necessary.
*/
gtk_widget_show_all(ed->shell);
gtk_window_present(GTK_WINDOW(ed->shell));
}
static void
goto_other_page(GtkWidget *w, gpointer editor)
{
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(editor);
gint32 opage;
FontgridPageInfo pi;
fontgrid_get_page_info(FONTGRID(ed->fgrid), &pi);
if (!pi.unencoded_page) {
opage = ed->last_pageno;
ed->last_pageno = pi.current_page;
} else {
opage = ed->last_upageno;
ed->last_upageno = pi.current_page;
}
if (opage != -1 && opage != pi.current_page)
fontgrid_goto_page(FONTGRID(ed->fgrid), opage);
}
static void
toggle_encoding_view(GtkWidget *w, gpointer editor)
{
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(editor);
gchar *label;
GtkLabel *lw;
if (fontgrid_viewing_unencoded(FONTGRID(ed->fgrid)))
label = "Unencoded";
else
label = "Encoded";
lw = GTK_LABEL(gtk_bin_get_child(GTK_BIN(ed->view_unencoded)));
gtk_label_set_text(lw, label);
fontgrid_switch_encoding_view(FONTGRID(ed->fgrid));
}
static void
toggle_view_orientation(GtkWidget *w, gpointer editor)
{
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(editor);
gchar *label;
GtkLabel *lw;
if (fontgrid_get_orientation(FONTGRID(ed->fgrid)) ==
GTK_ORIENTATION_VERTICAL) {
fontgrid_set_orientation(FONTGRID(ed->fgrid),
GTK_ORIENTATION_HORIZONTAL);
label = "Vertical View";
} else {
fontgrid_set_orientation(FONTGRID(ed->fgrid),
GTK_ORIENTATION_VERTICAL);
label = "Horizontal View";
}
lw = GTK_LABEL(gtk_bin_get_child(GTK_BIN(ed->view_unencoded)));
gtk_label_set_text(lw, label);
}
static void
set_code_base(GtkWidget *w, gpointer editor)
{
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(editor);
gint base;
if (w == ed->view_oct)
base = 8;
else if (w == ed->view_dec)
base = 10;
else
base = 16;
fontgrid_set_code_base(FONTGRID(ed->fgrid), base);
/*
* Make sure the font info editor is updated when the code base
* changes.
*/
guiedit_update_code_base(ed);
guigedit_set_code_base(base);
}
static void
page_change(GtkWidget *w, gpointer pinfo, gpointer editor)
{
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(editor);
FontgridPageInfo *pi = (FontgridPageInfo *) pinfo;
gchar *label;
GtkLabel *lw;
if (pi->previous_page < 0) {
gtk_widget_set_sensitive(ed->prev, FALSE);
gtk_widget_set_sensitive(ed->first, FALSE);
} else {
gtk_widget_set_sensitive(ed->prev, TRUE);
gtk_widget_set_sensitive(ed->first, TRUE);
}
if (pi->next_page < 0) {
gtk_widget_set_sensitive(ed->next, FALSE);
gtk_widget_set_sensitive(ed->last, FALSE);
} else {
gtk_widget_set_sensitive(ed->next, TRUE);
gtk_widget_set_sensitive(ed->last, TRUE);
}
/*
* Update the page number field with the current page.
*/
sprintf(buffer1, "%d", pi->current_page);
gtk_entry_set_text(GTK_ENTRY(ed->pageno), buffer1);
gtk_editable_set_position(GTK_EDITABLE(ed->pageno), -1);
/*
* Finally, modify the label on the Encoded/Unencoded view menu item.
*/
label = (pi->unencoded_page) ? "Encoded" : "Unencoded";
lw = GTK_LABEL(gtk_bin_get_child(GTK_BIN(ed->view_unencoded)));
gtk_label_set_text(lw, label);
}
static void
first_page(GtkWidget *w, gpointer editor)
{
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(editor);
fontgrid_goto_first_page(FONTGRID(ed->fgrid));
/*
* Force the focus back to the Fontgrid.
*/
gtk_widget_grab_focus(ed->fgrid);
}
static void
previous_page(GtkWidget *w, gpointer editor)
{
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(editor);
fontgrid_goto_previous_page(FONTGRID(ed->fgrid));
/*
* Force the focus back to the Fontgrid.
*/
gtk_widget_grab_focus(ed->fgrid);
}
static void
next_page(GtkWidget *w, gpointer editor)
{
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(editor);
fontgrid_goto_next_page(FONTGRID(ed->fgrid));
/*
* Force the focus back to the Fontgrid.
*/
gtk_widget_grab_focus(ed->fgrid);
}
static void
last_page(GtkWidget *w, gpointer editor)
{
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(editor);
fontgrid_goto_last_page(FONTGRID(ed->fgrid));
/*
* Force the focus back to the Fontgrid.
*/
gtk_widget_grab_focus(ed->fgrid);
}
static void
goto_page_or_code(GtkWidget *w, gpointer editor)
{
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(editor);
const gchar *text;
gint32 code;
FontgridPageInfo pi;
fontgrid_get_page_info(FONTGRID(ed->fgrid), &pi);
if (!pi.unencoded_page)
ed->last_pageno = pi.current_page;
else
ed->last_upageno = pi.current_page;
if (w == ed->pageno) {
text = gtk_entry_get_text(GTK_ENTRY(ed->pageno));
fontgrid_goto_page(FONTGRID(ed->fgrid),
_bdf_atol((char *) text, 0, 10));
} else {
text = gtk_entry_get_text(GTK_ENTRY(ed->charno));
code = _bdf_atol((char *) text, 0,
fontgrid_get_code_base(FONTGRID(ed->fgrid)));
fontgrid_goto_code(FONTGRID(ed->fgrid), code);
}
}
static void
update_selection_info(GtkWidget *w, gpointer sinfo, gpointer editor)
{
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(editor);
FontgridSelectionInfo *si = (FontgridSelectionInfo *) sinfo;
short as, ds, rt, lt;
gint32 start, end;
guint b1 = 0, b2 = 0, b3, b4;
as = ds = rt = lt = 0;
if (si->start == si->end) {
if (si->num_glyphs != 0 && si->glyphs != 0) {
b1 = (si->start >> 8) & 0xff;
b2 = si->start & 0xff;
as = si->glyphs->bbx.ascent;
ds = si->glyphs->bbx.descent;
lt = si->glyphs->bbx.x_offset;
rt = si->glyphs->bbx.width + lt;
if (si->glyphs->name != 0)
(void) strcpy(buffer1, si->glyphs->name);
else
sprintf(buffer1, "char%d", si->glyphs->encoding);
/*
* If the glyph test dialog is active, send it the glyph if this
* is an end selection event.
*/
if (si->reason == FONTGRID_END_SELECTION && glyphtest != 0)
glyphtest_add_glyph(GLYPHTEST(glyphtest),
fontgrid_get_font(FONTGRID(ed->fgrid)),
si->glyphs);
} else
sprintf(buffer1, "char%d", si->start);
switch (si->base) {
case 8:
sprintf(buffer2, "\"%s\" %o (%o, %o)", buffer1,
si->start, b1, b2);
break;
case 10:
sprintf(buffer2, "\"%s\" %d (%d, %d)", buffer1,
si->start, b1, b2);
break;
case 16:
sprintf(buffer2, "\"%s\" %04X (%02X, %02X)", buffer1,
si->start, b1, b2);
break;
}
} else {
/*
* A range of glyphs has been selected.
*/
if (si->end < si->start) {
start = si->end;
end = si->start;
} else {
start = si->start;
end = si->end;
}
b1 = (start >> 8) & 0xff;
b2 = start & 0xff;
b3 = (end >> 8) & 0xff;
b4 = end & 0xff;
switch (si->base) {
case 8:
sprintf(buffer2, "Selection %o (%o, %o) - %o (%o, %o)",
start, b1, b2, end, b3, b4);
break;
case 10:
sprintf(buffer2, "Selection %d (%d, %d) - %d (%d, %d)",
start, b1, b2, end, b3, b4);
break;
case 16:
sprintf(buffer2, "Selection %04X (%02X, %02X) - %04X (%02X, %02X)",
start, b1, b2, end, b3, b4);
break;
}
}
/*
* Update the glyph info label.
*/
gtk_label_set_text(GTK_LABEL(ed->charinfo), buffer2);
/*
* Update the metrics label.
*/
sprintf(buffer1, "ascent %hd descent %hd right %hd left %hd",
as, ds, rt, lt);
gtk_label_set_text(GTK_LABEL(ed->metrics), buffer1);
switch (si->reason) {
case FONTGRID_START_SELECTION:
break;
case FONTGRID_EXTEND_SELECTION:
break;
case FONTGRID_END_SELECTION:
break;
case FONTGRID_ACTIVATE:
guigedit_edit_glyph(ed, si);
break;
case FONTGRID_BASE_CHANGE:
break;
}
}
static void
handle_modified_signal(GtkWidget *w, gpointer minfo, gpointer editor)
{
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(editor);
gchar *prgname = g_get_prgname();
FontgridModificationInfo *mi;
mi = (FontgridModificationInfo *) minfo;
/*
* Check to see what change was made so updates can be handled
* appropriately.
*/
if (mi->reason == FONTGRID_NAME_MODIFIED)
gtk_entry_set_text(GTK_ENTRY(ed->fontname), mi->name);
else if (mi->reason == FONTGRID_PROPERTIES_MODIFIED)
/*
* Make sure the font info editing dialog knows that the list of
* font properties changed.
*/
guiedit_update_font_properties(ed);
else if (mi->reason == FONTGRID_GLYPHS_DELETED ||
mi->reason == FONTGRID_GLYPHS_PASTED)
guiedit_update_font_details(ed);
else if ((mi->reason == FONTGRID_DEVICE_WIDTH_MODIFIED ||
mi->reason == FONTGRID_GLYPHS_MODIFIED) && glyphtest != 0)
/*
* Update the glyph test widget with the new device width.
*/
glyphtest_update_device_width(GLYPHTEST(glyphtest),
fontgrid_get_font(FONTGRID(ed->fgrid)));
/*
* Update the title.
*/
if (ed->file == 0)
sprintf(buffer1, "%s - (unnamed%d) [modified]", prgname, ed->id);
else
sprintf(buffer1, "%s - %s [modified]", prgname, ed->file);
gtk_window_set_title(GTK_WINDOW(ed->shell), buffer1);
}
static void
view_font_messages(GtkWidget *w, gpointer editor)
{
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(editor);
GtkWidget *dialog, *frame, *button, *label, *vbox, *sw;
GtkTextBuffer *text;
gchar *msgs;
if (ed->messages_dialog == 0) {
/*
* Special case of no messages and the menu item hasn't been
* checked for sensitivity yet.
*/
if (fontgrid_get_font_messages(FONTGRID(ed->fgrid)) == 0)
return;
dialog = ed->messages_dialog = gtk_dialog_new();
(void) g_signal_connect(G_OBJECT(dialog), "delete_event",
G_CALLBACK(gtk_widget_hide), 0);
frame = gtk_frame_new(0);
label = ed->messages_label = gtk_label_new("");
gtk_container_add(GTK_CONTAINER(frame), label);
vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
sw = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
GTK_POLICY_NEVER,
GTK_POLICY_ALWAYS);
gtk_box_pack_start(GTK_BOX(vbox), sw, FALSE, FALSE, 0);
/*
* Add the text widget.
*/
text = gtk_text_buffer_new(NULL);
ed->messages_text = gtk_text_view_new_with_buffer(text);
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(ed->messages_text),
FALSE);
gtk_widget_set_size_request(ed->messages_text, 500, 200);
gtk_text_view_set_editable(GTK_TEXT_VIEW(ed->messages_text), FALSE);
gtk_container_add(GTK_CONTAINER(sw), ed->messages_text);
button = gtk_button_new_with_label("Close");
(void) g_signal_connect_object(G_OBJECT(button), "clicked",
G_CALLBACK(gtk_widget_hide),
(gpointer) dialog,
G_CONNECT_SWAPPED);
gtk_container_add(GTK_CONTAINER(gtk_dialog_get_action_area(GTK_DIALOG(dialog))),
button);
gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(ed->messages_dialog)));
gtk_widget_show_all(gtk_dialog_get_action_area(GTK_DIALOG(ed->messages_dialog)));
} else
text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ed->messages_text));
/*
* Update the label with the font name in case it changed since the last
* time the messages were shown.
*/
if (ed->file != 0)
sprintf(buffer1, "%s: Messages", ed->file);
else
sprintf(buffer1, "unnamed%d.bdf: Messages", ed->id);
gtk_label_set_text(GTK_LABEL(ed->messages_label), buffer1);
/*
* Now change the text itself.
*/
if ((msgs = fontgrid_get_font_messages(FONTGRID(ed->fgrid))) == 0)
msgs = "";
gtk_text_buffer_set_text(text, msgs, -1);
guiutil_show_dialog_centered(ed->messages_dialog, ed->shell);
}
/**************************************************************************
*
* Menu construction.
*
**************************************************************************/
static GtkWidget *
make_accel_menu_item(GtkWidget *menu, const gchar *text, const gchar *accel,
GtkAccelGroup *ag)
{
GtkWidget *mi;
guint key;
GdkModifierType mods;
mi = gtk_menu_item_new_with_mnemonic(text);
gtk_accelerator_parse(accel, &key, &mods);
gtk_widget_add_accelerator(mi, "activate", ag, key, mods,
GTK_ACCEL_VISIBLE|GTK_ACCEL_LOCKED);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
return mi;
}
/*
* Handle all the menu checking needed to enable or disable menu items on
* all the menus.
*/
static gint
menu_popup(GtkWidget *w, GdkEvent *event, gpointer data)
{
gbdfed_editor_t *ed;
bdf_font_t *font;
GtkWidget *mitem;
GList *kids, *label;
gboolean flag;
guint i;
/*
* Get a pointer to the editor.
*/
ed = editors + GPOINTER_TO_UINT(data);
font = fontgrid_get_font(FONTGRID(ed->fgrid));
if (event->type == GDK_MAP) {
if (w == ed->file_menu) {
if (font && font->modified)
gtk_widget_set_sensitive(ed->file_save, TRUE);
else
gtk_widget_set_sensitive(ed->file_save, FALSE);
if (font && font->glyphs_used > 0)
gtk_widget_set_sensitive(ed->file_export, TRUE);
else
gtk_widget_set_sensitive(ed->file_export, FALSE);
} else if (w == ed->edit_menu) {
/*
* If the fontgrid clipboard is empty, then disable the paste,
* overlay, and insert menu options.
*/
flag = fontgrid_clipboard_empty(FONTGRID(ed->fgrid)) ?
FALSE : TRUE;
gtk_widget_set_sensitive(ed->edit_paste, flag);
gtk_widget_set_sensitive(ed->edit_overlay, flag);
gtk_widget_set_sensitive(ed->edit_insert, flag);
/*
* If there is no selection, disable the cut and copy menu
* options.
*/
flag = fontgrid_has_selection(FONTGRID(ed->fgrid), 0) ?
TRUE : FALSE;
gtk_widget_set_sensitive(ed->edit_cut, flag);
gtk_widget_set_sensitive(ed->edit_copy, flag);
flag = (font && font->glyphs_used > 0) ? TRUE : FALSE;
/*
* Disable glyph rename when viewing unecoded glyphs because their
* encoding values are not actual.
*/
if (fontgrid_viewing_unencoded(FONTGRID(ed->fgrid)) || !flag)
gtk_widget_set_sensitive(ed->edit_rename_glyphs, FALSE);
else
gtk_widget_set_sensitive(ed->edit_rename_glyphs, TRUE);
gtk_widget_set_sensitive(ed->edit_test_glyphs, flag);
} else if (w == ed->edit_rename_menu) {
if (options.adobe_name_file != 0)
gtk_widget_set_sensitive(ed->edit_adobe_names, TRUE);
else
gtk_widget_set_sensitive(ed->edit_adobe_names, FALSE);
if (options.unicode_name_file != 0)
gtk_widget_set_sensitive(ed->edit_unicode_names, TRUE);
else
gtk_widget_set_sensitive(ed->edit_unicode_names, FALSE);
} else if (w == ed->name_submenu) {
flag = (!font || bdf_has_xlfd_name(font)) ? FALSE : TRUE;
gtk_widget_set_sensitive(ed->edit_make_xlfd, flag);
} else if (w == ed->view_menu) {
if (fontgrid_get_font_messages(FONTGRID(ed->fgrid)))
gtk_widget_set_sensitive(ed->view_messages, TRUE);
else
gtk_widget_set_sensitive(ed->view_messages, FALSE);
} else if (w == ed->win_menu) {
/*
* Go through and update the file names that might have changed
* since the last time this menu popped up.
*/
for (i = 0, kids = gtk_container_get_children(GTK_CONTAINER(w)); kids != 0;
kids = kids->next, i++) {
if (editors[i].file == 0)
sprintf(buffer1, "(unnamed%d)", i);
else
strcpy(buffer1, editors[i].file);
label = gtk_container_get_children(GTK_CONTAINER(kids->data));
gtk_label_set_text(GTK_LABEL(label->data), buffer1);
}
/*
* Add any new editors that were created since the last time this
* menu was shown.
*/
for (; i < num_editors; i++) {
if (editors[i].file == 0)
sprintf(buffer1, "(unnamed%d)", editors[i].id);
else
strcpy(buffer1, editors[i].file);
mitem = gtk_menu_item_new_with_label(buffer1);
(void) g_signal_connect(G_OBJECT(mitem), "activate",
G_CALLBACK(show_editor),
GUINT_TO_POINTER(i));
gtk_menu_shell_append(GTK_MENU_SHELL(ed->win_menu), mitem);
gtk_widget_show(mitem);
}
/*
* Disable the item for this editor.
*/
gtk_widget_set_sensitive(ed->win_menu_item, FALSE);
}
} else if (event->type == GDK_UNMAP) {
/*
* Enable everything again, so it doesn't get forgotten.
*/
gtk_widget_set_sensitive(ed->file_save, TRUE);
gtk_widget_set_sensitive(ed->file_export, TRUE);
gtk_widget_set_sensitive(ed->edit_paste, TRUE);
gtk_widget_set_sensitive(ed->edit_overlay, TRUE);
gtk_widget_set_sensitive(ed->edit_insert, TRUE);
gtk_widget_set_sensitive(ed->edit_cut, TRUE);
gtk_widget_set_sensitive(ed->edit_copy, TRUE);
gtk_widget_set_sensitive(ed->edit_rename_glyphs, TRUE);
gtk_widget_set_sensitive(ed->edit_adobe_names, TRUE);
gtk_widget_set_sensitive(ed->edit_unicode_names, TRUE);
gtk_widget_set_sensitive(ed->edit_test_glyphs, TRUE);
gtk_widget_set_sensitive(ed->edit_make_xlfd, TRUE);
gtk_widget_set_sensitive(ed->win_menu_item, TRUE);
gtk_widget_set_sensitive(ed->view_messages, TRUE);
}
return FALSE;
}
#if (GTK_MAJOR_VERSION >= 2 && GTK_MINOR_VERSION >= 10)
static void
open_recent_font(GtkWidget *w, gpointer data)
{
gchar *p, *uri = gtk_recent_chooser_get_current_uri(GTK_RECENT_CHOOSER(w));
gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(data);
if (uri == NULL)
return;
/*
* Skip the URI prefix to get to the path. The URI's are strictly local
* at the moment.
*/
for (p = uri; *p && *p != ':'; p++);
if (*p != ':')
return;
p++;
if (*p == '/' && *(p + 1) == '/')
p += 2;
guifile_load_bdf_font(ed, (const gchar *) p);
g_free(uri);
}
static GtkWidget *
make_recent_menu(guint ed_id)
{
GtkWidget *menu;
GtkRecentFilter *filter;
GtkRecentManager *manager;
manager = gtk_recent_manager_get_default();
menu = gtk_recent_chooser_menu_new_for_manager(manager);
gtk_recent_chooser_set_limit(GTK_RECENT_CHOOSER(menu), 10);
gtk_recent_chooser_set_sort_type(GTK_RECENT_CHOOSER(menu),
GTK_RECENT_SORT_MRU);
gtk_recent_chooser_set_show_tips(GTK_RECENT_CHOOSER(menu), TRUE);
gtk_recent_chooser_menu_set_show_numbers(GTK_RECENT_CHOOSER_MENU(menu),
TRUE);
gtk_recent_chooser_set_local_only(GTK_RECENT_CHOOSER(menu), TRUE);
filter = gtk_recent_filter_new();
gtk_recent_filter_add_pattern(filter, "*.[Bb][Dd][Ff]");
gtk_recent_chooser_set_filter(GTK_RECENT_CHOOSER(menu), filter);
(void) g_signal_connect(G_OBJECT(menu), "item_activated",
G_CALLBACK(open_recent_font),
GUINT_TO_POINTER(ed_id));
return menu;
}
#endif
static GtkWidget *
make_file_menu(gbdfed_editor_t *ed, GtkWidget *menubar)
{
GtkWidget *file, *menu, *submenu, *mitem, *sep;
/*
* Create the File menu.
*/
file = gtk_menu_item_new_with_mnemonic("_File");
ed->file_menu = menu = gtk_menu_new();
(void) g_signal_connect(G_OBJECT(menu), "map_event",
G_CALLBACK(menu_popup),
GUINT_TO_POINTER(ed->id));
mitem = make_accel_menu_item(menu, "_New", "<Control>N", ed->ag);
(void) g_signal_connect(G_OBJECT(mitem), "activate",
G_CALLBACK(guifile_new_editor), 0);
mitem = make_accel_menu_item(menu, "_Open", "<Control>O", ed->ag);
(void) g_signal_connect(G_OBJECT(mitem), "activate",
G_CALLBACK(guifile_import_bdf_font),
GUINT_TO_POINTER(ed->id));
ed->file_save = make_accel_menu_item(menu, "_Save", "<Control>S", ed->ag);
(void) g_signal_connect(G_OBJECT(ed->file_save), "activate",
G_CALLBACK(guifile_save),
GUINT_TO_POINTER(ed->id));
mitem = make_accel_menu_item(menu, "Save _As...", "<Control>W", ed->ag);
(void) g_signal_connect(G_OBJECT(mitem), "activate",
G_CALLBACK(guifile_save_as),
GUINT_TO_POINTER(ed->id));
/*
* Separator.
*/
sep = gtk_menu_item_new();
gtk_widget_set_sensitive(sep, FALSE);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), sep);
/*
* Create the Import and Export menu items with their submenus.
*/
mitem = gtk_menu_item_new_with_mnemonic("_Import");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), mitem);
submenu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(mitem), submenu);
mitem = make_accel_menu_item(submenu, "_PK/GF Font", "<Control>K", ed->ag);
(void) g_signal_connect(G_OBJECT(mitem), "activate",
G_CALLBACK(guifile_import_pkgf_font),
GUINT_TO_POINTER(ed->id));
mitem = make_accel_menu_item(submenu, "_Console Font", "<Control>L",
ed->ag);
(void) g_signal_connect(G_OBJECT(mitem), "activate",
G_CALLBACK(guifile_import_console_font),
GUINT_TO_POINTER(ed->id));
#ifdef HAVE_HBF
mitem = make_accel_menu_item(submenu, "_HBF Font", "<Control>H",
ed->ag);
(void) g_signal_connect(G_OBJECT(mitem), "activate",
G_CALLBACK(guifile_import_hbf_font),
GUINT_TO_POINTER(ed->id));
#endif
mitem = make_accel_menu_item(submenu, "_Windows Font", "<Control>B",
ed->ag);
(void) g_signal_connect(G_OBJECT(mitem), "activate",