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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
|
/* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.
Copyright (C) 2007-2014 by Jin-Hwan Cho and Shunsaku Hirata,
the dvipdfmx project team.
Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "system.h"
#include "numbers.h"
#include "error.h"
#include "mem.h"
#include "dpxfile.h"
/* pdfdev... */
#include "pdfdev.h"
#include "tfm.h"
#include "dvi.h"
#include "vf.h"
#include "dvipdfmx.h"
#include "dvicodes.h"
#define VF_ALLOC_SIZE 16u
#define VF_ID 202
#define FIX_WORD_BASE 1048576.0
#define TEXPT2PT (72.0/72.27)
#define FW2PT (TEXPT2PT/((double)(FIX_WORD_BASE)))
static unsigned char verbose = 0;
void vf_set_verbose(void)
{
if (verbose < 255) verbose++;
}
struct font_def {
signed long font_id /* id used internally in vf file */;
unsigned long checksum, size, design_size;
char *directory, *name;
int tfm_id; /* id returned by TFM module */
int dev_id; /* id returned by DEV module */
};
struct vf
{
char *tex_name;
spt_t ptsize;
unsigned long design_size; /* A fixword-pts quantity */
int num_dev_fonts, max_dev_fonts;
struct font_def *dev_fonts;
unsigned char **ch_pkt;
unsigned long *pkt_len;
unsigned num_chars;
};
struct vf *vf_fonts = NULL;
int num_vf_fonts = 0, max_vf_fonts = 0;
static int read_header(FILE *vf_file, int thisfont)
{
int i, result = 1, ch;
/* Check for usual signature */
if ((ch = get_unsigned_byte (vf_file)) == PRE &&
(ch = get_unsigned_byte (vf_file)) == VF_ID) {
/* If here, assume it's a legitimate vf file */
ch = get_unsigned_byte (vf_file);
/* skip comment */
for (i=0; i<ch; i++)
get_unsigned_byte (vf_file);
/* Skip checksum */
get_unsigned_quad(vf_file);
vf_fonts[thisfont].design_size =
get_unsigned_quad(vf_file);
} else { /* Try to fail gracefully and return an error to caller */
fprintf (stderr, "VF file may be corrupt\n");
result = 0;
}
return result;
}
static void resize_vf_fonts(int size)
{
int i;
if (size > max_vf_fonts) {
vf_fonts = RENEW (vf_fonts, size, struct vf);
for (i=max_vf_fonts; i<size; i++) {
vf_fonts[i].num_dev_fonts = 0;
vf_fonts[i].max_dev_fonts = 0;
vf_fonts[i].dev_fonts = NULL;
}
max_vf_fonts = size;
}
return;
}
static void resize_one_vf_font (struct vf *a_vf, unsigned size)
{
unsigned i;
if (size > (a_vf->num_chars)) {
size = MAX (size, a_vf->num_chars+256);
a_vf->ch_pkt = RENEW (a_vf->ch_pkt, size, unsigned char *);
a_vf->pkt_len = RENEW (a_vf->pkt_len, size, unsigned long);
for (i=a_vf->num_chars; i<size; i++) {
(a_vf->ch_pkt)[i] = NULL;
(a_vf->pkt_len)[i] = 0;
}
a_vf->num_chars = size;
}
}
static void read_a_char_def(FILE *vf_file, int thisfont, unsigned long pkt_len,
unsigned ch)
{
unsigned char *pkt;
#ifdef DEBUG
fprintf (stderr, "read_a_char_def: len=%ld, ch=%d\n", pkt_len, ch);
#endif
/* Resize and initialize character arrays if necessary */
if (ch >= vf_fonts[thisfont].num_chars) {
resize_one_vf_font (vf_fonts+thisfont, ch+1);
}
if (pkt_len > 0) {
pkt = NEW (pkt_len, unsigned char);
if (fread (pkt, 1, pkt_len, vf_file) != pkt_len)
ERROR ("VF file ended prematurely.");
(vf_fonts[thisfont].ch_pkt)[ch] = pkt;
}
(vf_fonts[thisfont].pkt_len)[ch] = pkt_len;
return;
}
static void read_a_font_def(FILE *vf_file, signed long font_id, int thisfont)
{
struct font_def *dev_font;
int dir_length, name_length;
#ifdef DEBUG
fprintf (stderr, "read_a_font_def: font_id = %ld\n", font_id);
#endif
if (vf_fonts[thisfont].num_dev_fonts >=
vf_fonts[thisfont].max_dev_fonts) {
vf_fonts[thisfont].max_dev_fonts += VF_ALLOC_SIZE;
vf_fonts[thisfont].dev_fonts = RENEW
(vf_fonts[thisfont].dev_fonts,
vf_fonts[thisfont].max_dev_fonts,
struct font_def);
}
dev_font = vf_fonts[thisfont].dev_fonts+
vf_fonts[thisfont].num_dev_fonts;
dev_font -> font_id = font_id;
dev_font -> checksum = get_unsigned_quad (vf_file);
dev_font -> size = get_unsigned_quad (vf_file);
dev_font -> design_size = get_unsigned_quad (vf_file);
dir_length = get_unsigned_byte (vf_file);
name_length = get_unsigned_byte (vf_file);
dev_font -> directory = NEW (dir_length+1, char);
dev_font -> name = NEW (name_length+1, char);
fread (dev_font -> directory, 1, dir_length, vf_file);
fread (dev_font -> name, 1, name_length, vf_file);
(dev_font -> directory)[dir_length] = 0;
(dev_font -> name)[name_length] = 0;
vf_fonts[thisfont].num_dev_fonts += 1;
dev_font->tfm_id = tfm_open (dev_font -> name, 1); /* must exist */
dev_font->dev_id =
dvi_locate_font (dev_font->name,
sqxfw (vf_fonts[thisfont].ptsize,
dev_font->size));
#ifdef DEBUG
fprintf (stderr, "[%s/%s]\n", dev_font -> directory, dev_font -> name);
#endif
return;
}
static void process_vf_file (FILE *vf_file, int thisfont)
{
int eof = 0, code;
unsigned long font_id;
while (!eof) {
code = get_unsigned_byte (vf_file);
switch (code) {
case FNT_DEF1:
font_id = get_unsigned_byte (vf_file);
read_a_font_def (vf_file, font_id, thisfont);
break;
case FNT_DEF2:
font_id = get_unsigned_pair (vf_file);
read_a_font_def (vf_file, font_id, thisfont);
break;
case FNT_DEF3:
font_id = get_unsigned_triple(vf_file);
read_a_font_def (vf_file, font_id, thisfont);
break;
case FNT_DEF4:
font_id = get_signed_quad(vf_file);
read_a_font_def (vf_file, font_id, thisfont);
break;
default:
if (code < 242) {
long ch;
/* For a short packet, code is the pkt_len */
ch = get_unsigned_byte (vf_file);
/* Skip over TFM width since we already know it */
get_unsigned_triple (vf_file);
read_a_char_def (vf_file, thisfont, code, ch);
break;
}
if (code == 242) {
unsigned long pkt_len, ch;
pkt_len = get_unsigned_quad(vf_file);
ch = get_unsigned_quad (vf_file);
/* Skip over TFM width since we already know it */
get_unsigned_quad (vf_file);
if (ch < (is_xetex ? 0x10000UL : 0x1000000UL))
read_a_char_def (vf_file, thisfont, pkt_len, ch);
else {
fprintf (stderr, "char=%ld\n", ch);
ERROR ("Long character (>%s bits) in VF file.\nI can't handle long characters!\n",
is_xetex ? "16" : "24");
}
break;
}
if (code == POST) {
eof = 1;
break;
}
fprintf (stderr, "Quitting on code=%d\n", code);
eof = 1;
break;
}
}
return;
}
/* Unfortunately, the following code isn't smart enough
to load the vf only once for multiple point sizes.
You will get a separate copy of each VF in memory (and a separate
opening and reading of the file) for
each point size. Since VFs are pretty small, I guess
this is tolerable for now. In any case,
the PDF file will never repeat a physical font name */
/* Note: This code needs to be able to recurse */
/* Global variables such as num_vf_fonts require careful attention */
int vf_locate_font (const char *tex_name, spt_t ptsize)
{
int thisfont = -1, i;
char *full_vf_file_name;
FILE *vf_file;
/* Has this name and ptsize already been loaded as a VF? */
for (i=0; i<num_vf_fonts; i++) {
if (!strcmp (vf_fonts[i].tex_name, tex_name) &&
vf_fonts[i].ptsize == ptsize)
break;
}
if (i != num_vf_fonts) {
thisfont = i;
} else {
/* It's hasn't already been loaded as a VF, so try to load it */
full_vf_file_name = kpse_find_file (tex_name,
kpse_vf_format,
1);
if (!full_vf_file_name) {
full_vf_file_name = kpse_find_file (tex_name,
kpse_ovf_format,
1);
}
if (full_vf_file_name &&
(vf_file = MFOPEN (full_vf_file_name, FOPEN_RBIN_MODE)) != NULL) {
if (verbose == 1)
fprintf (stderr, "(VF:%s", tex_name);
if (verbose > 1)
fprintf (stderr, "(VF:%s", full_vf_file_name);
if (num_vf_fonts >= max_vf_fonts) {
resize_vf_fonts (max_vf_fonts + VF_ALLOC_SIZE);
}
thisfont = num_vf_fonts++;
{ /* Initialize some pointers and such */
vf_fonts[thisfont].tex_name = NEW (strlen(tex_name)+1, char);
strcpy (vf_fonts[thisfont].tex_name, tex_name);
vf_fonts[thisfont].ptsize = ptsize;
vf_fonts[thisfont].num_chars = 0;
vf_fonts[thisfont].ch_pkt = NULL;
vf_fonts[thisfont].pkt_len = NULL;
}
read_header(vf_file, thisfont);
process_vf_file (vf_file, thisfont);
if (verbose)
fprintf (stderr, ")");
MFCLOSE (vf_file);
}
if (full_vf_file_name)
RELEASE(full_vf_file_name);
}
return thisfont;
}
#define next_byte() (*((*start)++))
static UNSIGNED_BYTE unsigned_byte (unsigned char **start, unsigned char *end)
{
UNSIGNED_BYTE byte = 0;
if (*start < end)
byte = next_byte();
else
ERROR ("Premature end of DVI byte stream in VF font\n");
return byte;
}
static SIGNED_BYTE signed_byte (unsigned char **start, unsigned char *end)
{
int byte = 0;
if (*start < end) {
byte = next_byte();
if (byte >= 0x80)
byte -= 0x100;
}
else
ERROR ("Premature end of DVI byte stream in VF font\n");
return (SIGNED_BYTE) byte;
}
static UNSIGNED_PAIR unsigned_pair (unsigned char **start, unsigned char *end)
{
int i;
UNSIGNED_BYTE byte;
UNSIGNED_PAIR pair = 0;
if (end-*start > 1) {
for (i=0; i<2; i++) {
byte = next_byte();
pair = pair*0x100u + byte;
}
}
else
ERROR ("Premature end of DVI byte stream in VF font\n");
return pair;
}
static SIGNED_PAIR signed_pair (unsigned char **start, unsigned char *end)
{
int i;
long pair = 0;
if (end - *start > 1) {
for (i=0; i<2; i++) {
pair = pair*0x100 + next_byte();
}
if (pair >= 0x8000) {
pair -= 0x10000l;
}
} else
ERROR ("Premature end of DVI byte stream in VF font\n");
return (SIGNED_PAIR) pair;
}
static UNSIGNED_TRIPLE unsigned_triple(unsigned char **start, unsigned
char *end)
{
int i;
long triple = 0;
if (end-*start > 2) {
for (i=0; i<3; i++) {
triple = triple*0x100u + next_byte();
}
} else
ERROR ("Premature end of DVI byte stream in VF font\n");
return (UNSIGNED_TRIPLE) triple;
}
static SIGNED_TRIPLE signed_triple(unsigned char **start, unsigned char *end)
{
int i;
long triple = 0;
if (end-*start > 2) {
for (i=0; i<3; i++) {
triple = triple*0x100 + next_byte();
}
if (triple >= 0x800000l)
triple -= 0x1000000l;
} else
ERROR ("Premature end of DVI byte stream in VF font\n");
return (SIGNED_TRIPLE) triple;
}
static SIGNED_QUAD signed_quad(unsigned char **start, unsigned char *end)
{
int byte, i;
long quad = 0;
/* Check sign on first byte before reading others */
if (end-*start > 3) {
byte = next_byte();
quad = byte;
if (quad >= 0x80)
quad = byte - 0x100;
for (i=0; i<3; i++) {
quad = quad*0x100 + next_byte();
}
} else
ERROR ("Premature end of DVI byte stream in VF font\n");
return (SIGNED_QUAD) quad;
}
static UNSIGNED_QUAD unsigned_quad(unsigned char **start, unsigned char *end)
{
int i;
unsigned long quad = 0;
if (end-*start > 3) {
for (i=0; i<4; i++) {
quad = quad*0x100u + next_byte();
}
} else
ERROR ("Premature end of DVI byte stream in VF font\n");
return (UNSIGNED_QUAD) quad;
}
static void vf_set (SIGNED_QUAD ch)
{
/* Defer to the dvi_set() defined in dvi.c */
dvi_set (ch);
return;
}
static void vf_set1(unsigned char **start, unsigned char *end)
{
vf_set (unsigned_byte(start, end));
return;
}
static void vf_set2(unsigned char **start, unsigned char *end)
{
vf_set (unsigned_pair(start, end));
return;
}
static void vf_set3(unsigned char **start, unsigned char *end)
{
vf_set (unsigned_triple(start, end));
return;
}
static void vf_putrule(unsigned char **start, unsigned char *end, spt_t ptsize)
{
SIGNED_QUAD width, height;
height = signed_quad (start, end);
width = signed_quad (start, end);
if (width > 0 && height > 0) {
dvi_rule (sqxfw(ptsize,width), sqxfw(ptsize, height));
}
return;
}
static void vf_setrule(unsigned char **start, unsigned char *end, spt_t ptsize)
{
SIGNED_QUAD width, height, s_width;
height = signed_quad (start, end);
width = signed_quad (start, end);
s_width = sqxfw(ptsize, width);
if (width > 0 && height > 0) {
dvi_rule (s_width, sqxfw(ptsize, height));
}
dvi_right (s_width);
return;
}
static void vf_put1(unsigned char **start, unsigned char *end)
{
dvi_put (unsigned_byte(start, end));
return;
}
static void vf_put2(unsigned char **start, unsigned char *end)
{
dvi_put (unsigned_pair(start, end));
return;
}
static void vf_put3(unsigned char **start, unsigned char *end)
{
dvi_put (unsigned_triple(start, end));
return;
}
static void vf_push(void)
{
dvi_push();
return;
}
static void vf_pop(void)
{
dvi_pop();
return;
}
static void vf_right (SIGNED_QUAD x, spt_t ptsize)
{
dvi_right ((SIGNED_QUAD) (sqxfw(ptsize, x)));
return;
}
static void vf_right1(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_right (signed_byte (start, end), ptsize);
return;
}
static void vf_right2(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_right (signed_pair (start, end), ptsize);
return;
}
static void vf_right3(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_right (signed_triple (start, end), ptsize);
return;
}
static void vf_right4(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_right (signed_quad (start, end), ptsize);
return;
}
static void vf_w0(void)
{
dvi_w0();
return;
}
static void vf_w (SIGNED_QUAD w, spt_t ptsize)
{
dvi_w ((SIGNED_QUAD) (sqxfw(ptsize, w)));
return;
}
static void vf_w1(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_w (signed_byte(start, end), ptsize);
return;
}
static void vf_w2(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_w (signed_pair(start, end), ptsize);
return;
}
static void vf_w3(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_w (signed_triple(start, end), ptsize);
return;
}
static void vf_w4(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_w (signed_quad(start, end), ptsize);
return;
}
static void vf_x0(void)
{
dvi_x0();
return;
}
static void vf_x (SIGNED_QUAD x, spt_t ptsize)
{
dvi_x ((SIGNED_QUAD) (sqxfw(ptsize, x)));
return;
}
static void vf_x1(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_x (signed_byte(start, end), ptsize);
return;
}
static void vf_x2(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_x (signed_pair(start, end), ptsize);
return;
}
static void vf_x3(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_x (signed_triple(start, end), ptsize);
return;
}
static void vf_x4(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_x (signed_quad(start, end), ptsize);
return;
}
static void vf_down (SIGNED_QUAD y, spt_t ptsize)
{
dvi_down ((SIGNED_QUAD) (sqxfw(ptsize, y)));
return;
}
static void vf_down1(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_down (signed_byte(start, end), ptsize);
return;
}
static void vf_down2(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_down (signed_pair(start, end), ptsize);
return;
}
static void vf_down3(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_down (signed_triple(start, end), ptsize);
return;
}
static void vf_down4(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_down (signed_quad(start, end), ptsize);
return;
}
static void vf_y0(void)
{
dvi_y0();
return;
}
static void vf_y (SIGNED_QUAD y, spt_t ptsize)
{
dvi_y ((SIGNED_QUAD) (sqxfw(ptsize, y)));
return;
}
static void vf_y1(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_y (signed_byte(start, end), ptsize);
return;
}
static void vf_y2(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_y (signed_pair(start, end), ptsize);
return;
}
static void vf_y3(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_y (signed_triple(start, end), ptsize);
return;
}
static void vf_y4(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_y (signed_quad(start, end), ptsize);
return;
}
static void vf_z0(void)
{
dvi_z0();
return;
}
static void vf_z (SIGNED_QUAD z, spt_t ptsize)
{
dvi_z ((SIGNED_QUAD) (sqxfw(ptsize, z)));
return;
}
static void vf_z1(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_z (signed_byte(start, end), ptsize);
return;
}
static void vf_z2(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_z (signed_pair(start, end), ptsize);
return;
}
static void vf_z3(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_z (signed_triple(start, end), ptsize);
return;
}
static void vf_z4(unsigned char **start, unsigned char *end, spt_t ptsize)
{
vf_z (signed_quad(start, end), ptsize);
return;
}
static void vf_fnt (SIGNED_QUAD font_id, unsigned long vf_font)
{
int i;
for (i=0; i<vf_fonts[vf_font].num_dev_fonts; i++) {
if (font_id == ((vf_fonts[vf_font].dev_fonts)[i]).font_id) {
break;
}
}
if (i < vf_fonts[vf_font].num_dev_fonts) { /* Font was found */
dvi_set_font ((vf_fonts[vf_font].dev_fonts[i]).dev_id);
} else {
fprintf (stderr, "Font_id: %ld not found in VF\n", font_id);
}
return;
}
static void vf_fnt1(unsigned char **start, unsigned char *end,
unsigned long vf_font)
{
vf_fnt (unsigned_byte(start, end), vf_font);
return;
}
static void vf_fnt2(unsigned char **start, unsigned char *end,
unsigned long vf_font)
{
vf_fnt (unsigned_pair(start, end), vf_font);
return;
}
static void vf_fnt3(unsigned char **start, unsigned char *end,
unsigned long vf_font)
{
vf_fnt (unsigned_triple(start, end), vf_font);
return;
}
static void vf_fnt4(unsigned char **start, unsigned char *end,
unsigned long vf_font)
{
vf_fnt (signed_quad(start, end), vf_font);
return;
}
/* identical to do_xxx in dvi.c */
static void vf_xxx (SIGNED_QUAD len, unsigned char **start, unsigned char *end)
{
Ubyte *buffer;
if (*start <= end - len) {
buffer = NEW(len+1, Ubyte);
memcpy(buffer, *start, len);
buffer[len] = '\0';
{
Ubyte *p = buffer;
while (p < buffer+len && *p == ' ') p++;
/*
* Warning message from virtual font.
*/
if (!memcmp((char *)p, "Warning:", 8)) {
if (verbose)
WARN("VF:%s", p+8);
} else {
dvi_do_special(buffer, len);
}
}
RELEASE(buffer);
} else {
ERROR ("Premature end of DVI byte stream in VF font.");
}
*start += len;
return;
}
static void vf_xxx1(unsigned char **start, unsigned char *end)
{
vf_xxx (unsigned_byte(start, end), start, end);
return;
}
static void vf_xxx2(unsigned char **start, unsigned char *end)
{
vf_xxx (unsigned_pair(start, end), start, end);
return;
}
static void vf_xxx3(unsigned char **start, unsigned char *end)
{
vf_xxx (unsigned_triple(start, end), start, end);
return;
}
static void vf_xxx4(unsigned char **start, unsigned char *end)
{
vf_xxx (unsigned_quad(start, end), start, end);
return;
}
static void vf_dir(unsigned char **start, unsigned char *end)
{
dvi_dir (unsigned_byte(start, end));
return;
}
void vf_set_char(SIGNED_QUAD ch, int vf_font)
{
unsigned char opcode;
unsigned char *start, *end;
spt_t ptsize;
int default_font = -1;
if (vf_font < num_vf_fonts) {
/* Initialize to the first font or -1 if undefined */
ptsize = vf_fonts[vf_font].ptsize;
if (vf_fonts[vf_font].num_dev_fonts > 0)
default_font = ((vf_fonts[vf_font].dev_fonts)[0]).dev_id;
dvi_vf_init (default_font);
if (ch >= vf_fonts[vf_font].num_chars ||
!(start = (vf_fonts[vf_font].ch_pkt)[ch])) {
fprintf (stderr, "\nchar=0x%lx(%ld)\n", ch, ch);
fprintf (stderr, "Tried to set a nonexistent character in a virtual font");
start = end = NULL;
} else {
end = start + (vf_fonts[vf_font].pkt_len)[ch];
}
while (start && start < end) {
opcode = *(start++);
#ifdef DEBUG
fprintf (stderr, "VF opcode: %d", opcode);
if (isprint (opcode)) fprintf (stderr, " (\'%c\')\n", opcode);
else fprintf (stderr, "\n");
#endif
switch (opcode)
{
case SET1:
vf_set1(&start, end);
break;
case SET2:
vf_set2(&start, end);
break;
case SET3:
if (!is_xetex) {
vf_set3(&start, end);
break;
}
case SET4:
ERROR ("Multibyte (>%s bits) character in VF packet.\nI can't handle this!",
is_xetex ? "16" : "24");
break;
case SET_RULE:
vf_setrule(&start, end, ptsize);
break;
case PUT1:
vf_put1(&start, end);
break;
case PUT2:
vf_put2(&start, end);
break;
case PUT3:
if (!is_xetex) {
vf_put3(&start, end);
break;
}
case PUT4:
ERROR ("Multibyte (>%s bits) character in VF packet.\nI can't handle this!",
is_xetex ? "16" : "24");
break;
case PUT_RULE:
vf_putrule(&start, end, ptsize);
break;
case NOP:
break;
case PUSH:
vf_push();
break;
case POP:
vf_pop();
break;
case RIGHT1:
vf_right1(&start, end, ptsize);
break;
case RIGHT2:
vf_right2(&start, end, ptsize);
break;
case RIGHT3:
vf_right3(&start, end, ptsize);
break;
case RIGHT4:
vf_right4(&start, end, ptsize);
break;
case W0:
vf_w0();
break;
case W1:
vf_w1(&start, end, ptsize);
break;
case W2:
vf_w2(&start, end, ptsize);
break;
case W3:
vf_w3(&start, end, ptsize);
break;
case W4:
vf_w4(&start, end, ptsize);
break;
case X0:
vf_x0();
break;
case X1:
vf_x1(&start, end, ptsize);
break;
case X2:
vf_x2(&start, end, ptsize);
break;
case X3:
vf_x3(&start, end, ptsize);
break;
case X4:
vf_x4(&start, end, ptsize);
break;
case DOWN1:
vf_down1(&start, end, ptsize);
break;
case DOWN2:
vf_down2(&start, end, ptsize);
break;
case DOWN3:
vf_down3(&start, end, ptsize);
break;
case DOWN4:
vf_down4(&start, end, ptsize);
break;
case Y0:
vf_y0();
break;
case Y1:
vf_y1(&start, end, ptsize);
break;
case Y2:
vf_y2(&start, end, ptsize);
break;
case Y3:
vf_y3(&start, end, ptsize);
break;
case Y4:
vf_y4(&start, end, ptsize);
break;
case Z0:
vf_z0();
break;
case Z1:
vf_z1(&start, end, ptsize);
break;
case Z2:
vf_z2(&start, end, ptsize);
break;
case Z3:
vf_z3(&start, end, ptsize);
break;
case Z4:
vf_z4(&start, end, ptsize);
break;
case FNT1:
vf_fnt1(&start, end, vf_font);
break;
case FNT2:
vf_fnt2(&start, end, vf_font);
break;
case FNT3:
vf_fnt3(&start, end, vf_font);
break;
case FNT4:
vf_fnt4(&start, end, vf_font);
break;
case XXX1:
vf_xxx1(&start, end);
break;
case XXX2:
vf_xxx2(&start, end);
break;
case XXX3:
vf_xxx3(&start, end);
break;
case XXX4:
vf_xxx4(&start, end);
break;
case PTEXDIR:
vf_dir(&start, end);
break;
default:
if (opcode <= SET_CHAR_127) {
vf_set (opcode);
} else if (opcode >= FNT_NUM_0 && opcode <= FNT_NUM_63) {
vf_fnt (opcode - FNT_NUM_0, vf_font);
} else {
fprintf (stderr, "Unexpected opcode: %d\n", opcode);
ERROR ("Unexpected opcode in vf file\n");
}
}
}
dvi_vf_finish();
} else {
fprintf (stderr, "vf_set_char: font: %d", vf_font);
ERROR ("Font not loaded\n");
}
return;
}
void vf_close_all_fonts(void)
{
unsigned long i;
int j;
struct font_def *one_font;
for (i=0; i<num_vf_fonts; i++) {
/* Release the packet for each character */
if (vf_fonts[i].ch_pkt) {
for (j=0; j<vf_fonts[i].num_chars; j++) {
if ((vf_fonts[i].ch_pkt)[j] != NULL)
RELEASE ((vf_fonts[i].ch_pkt)[j]);
}
RELEASE (vf_fonts[i].ch_pkt);
}
if (vf_fonts[i].pkt_len)
RELEASE (vf_fonts[i].pkt_len);
if (vf_fonts[i].tex_name)
RELEASE (vf_fonts[i].tex_name);
/* Release each font record */
for (j=0; j<vf_fonts[i].num_dev_fonts; j++) {
one_font = &(vf_fonts[i].dev_fonts)[j];
RELEASE (one_font -> directory);
RELEASE (one_font -> name);
}
if (vf_fonts[i].dev_fonts != NULL)
RELEASE (vf_fonts[i].dev_fonts);
}
if (vf_fonts != NULL)
RELEASE (vf_fonts);
return;
}
|