-
Notifications
You must be signed in to change notification settings - Fork 3
/
fnt.c
4038 lines (3572 loc) · 109 KB
/
fnt.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
/*
File: fnt.c
Copyright: © 1987-1990, 1992 by Apple Computer, Inc., all rights reserved.
Change History (most recent first):
<25> 7/20/92 DTY Revert fnt_IP back to 7.0 code.
<24> 7/23/91 RB Bumped version number returned by GetInfo to 4 for 6.1J TT. Make
it 5 for Kirin 1. Make it 6 for CubeE.
<23> 5/7/91 RB Cancelled bugfix made in <18>. When freedom and projection
vectors are orthogonal, the projection vector is set to the
freedom vector. However, fonts have already been shipped that
rely on this bad behavior, so we're stuck with it. Echh!!
<22> 4/26/91 RB Add DEBUG assertion checks for jump instructions.
<21> 4/25/91 RB no changes
<20> 4/11/91 RB Change to New Mnemonics for OPCodes
<19> 4/10/91 RB Finish obsoleting AA and SANGW
<18> 4/9/91 RB Change orthogonal freedom and projection vector fix so
that cosine of angle is pinned at 1/16 rather than set to 1.0.
<17> 4/9/91 RB Fix IP when original range is 0.
<16> 4/5/91 RB Bugfix to fnt_Normalize; check for 0 length;
if so, set vector to x axis.
<15> 3/25/91 RB Change Kanji Adjust Instruction
<13> 3/7/91 RB *********** POST 7.0 ****************
- Add Adjust Instruction for Kanji.
**************************************
<14> 3/11/91 RB Make AA and SANGW obsolete.
<12> 2/15/91 RB MR, #82806: Bump version number returned by GETINFO instruction
so 7.0 TT (version 2) can be distinguished from 6.0 TT (version
1).
<11> 2/11/91 RB MR, CL,CC,#82409: Add initials to previous change. Also
rearrange order to be more like original.
<10> 2/8/91 RB Fix instructions MIRP and MSIRP to correctly move point in
twilight zone.
<9> 12/20/90 RB Add mr initials to previous change comment. [mr]
<8> 12/20/90 RB Fix bug in INSTCTRL so unselected flags are not changed.[mr]
<7> 12/5/90 MR Change RAW to use the phantom points.
<6> 11/27/90 MR Fix bogus debugging in Check_ElementPtr. [rb]
<5> 11/16/90 MR More debugging code [rb]
<4> 11/9/90 MR Fix non-portable C (dup, depth, pushsomestuff) [rb]
<3> 11/5/90 MR Use proper types in fnt_Normalize, change globalGS.ppemDot6 to
globalGS.fpem. Make instrPtrs all uint8*. Removed conditional
code for long vectors. [rb]
<2> 10/20/90 MR Restore changes since project died. Converting to 2.14 vectors,
smart math routines. [rb]
<24> 8/16/90 RB Fix IP to use oo domain
<22> 8/11/90 MR Add Print debugging function
<21> 8/10/90 MR Make SFVTL check like SPVTL does
<20> 8/1/90 MR remove call to fnt_NextPt1 macro in fnt_SHC
<19> 7/26/90 MR Fix bug in SHC
<18> 7/19/90 dba get rid of C warnings
<17> 7/18/90 MR What else, more Ansi-C fixes
<16> 7/13/90 MR Added runtime range checking, various ansi-fixes
<15> 7/2/90 RB combine variables into parameter block.
<12> 6/26/90 RB bugfix in divide instruction
<11> 6/21/90 RB bugfix in scantype
<10> 6/12/90 RB add scantype instruction, add selector variable to getinfo
instruction
<9> 6/11/90 CL Using the debug call.
<8> 6/4/90 MR Remove MVT
<7> 6/3/90 RB no change
<6> 5/8/90 RB revert to version 4
<5> 5/4/90 RB mrr-more optimization, errorchecking
<4> 5/3/90 RB more optimization. decreased code size.
<4> 5/2/90 MR mrr - added support for IDEF mrr - combined multiple small
instructions into switchs e.g. BinaryOperands, UnaryOperand,
etc. (to save space) mrr - added twilightzone support to fnt_WC,
added fnt_ROTATE, fnt_MAX and fnt_MIN. Max and Min are in
fnt_BinaryOperand. Optimized various functions for size.
Optimized loops in push statements and alignrp for speed.
gs->loop now is base-0. so gs->loop == 4 means do it 5 times.
<3> 3/20/90 MR Added support for multiple preprograms. This touched function
calls, definitions. Fractional ppem (called ppemDot6 in globalGS
Add new instructions ELSE, JMPR Experimenting with RMVT, WMVT
Removed lots of the MR_MAC #ifdefs, GOSLOW, Added MFPPEM, MFPS
as experiments (fractional versions) Added high precision
multiply and divide for MUL and DIV Changed fnt_MD to use oox
instead of ox when it can (more precise) fnt_Init: Initialize
instruction jump table with *p++ instead of p[index] Changed
fnt_AngleInfo into fnt_FractPoint and int16 for speed and to
maintain long alignment Switch to Loop in PUSHB and PUSHW for
size reduction Speed up GetCVTScale to avoid FracMul(1.0,
transScale) (sampo)
<2> 2/27/90 CL Added DSPVTL[] instruction. Dropout control scanconverter and
SCANCTRL[] instruction. BugFix in SFVTL[], and SFVTOPV[].
Fixed bug in fnt_ODD[] and fnt_EVEN[]. Fixed bug in
fnt_Normalize
<3.4> 11/16/89 CEL Added new functions fnt_FLIPPT, fnt_FLIPRGON and fnt_FLIPRGOFF.
<3.3> 11/15/89 CEL Put function array check in ifndef so printer folks could
exclude the check.
<3.2> 11/14/89 CEL Fixed two small bugs/feature in RTHG, and RUTG. Added SROUND &
S45ROUND.
<3.1> 9/27/89 CEL GetSingleWidth slow was set to incorrect value. Changed rounding
routines, so that the sign flip check only apply if the input
value is nonzero.
<3.0> 8/28/89 sjk Cleanup and one transformation bugfix
<2.3> 8/14/89 sjk 1 point contours now OK
<2.2> 8/8/89 sjk Now allow the system to muck with high bytes of addresses
<2.1> 8/8/89 sjk Improved encryption handling
<2.0> 8/2/89 sjk Just fixed EASE comment
<1.8> 8/1/89 sjk Added in composites and encryption. Plus other enhancements…
<1.7> 6/13/89 sjk fixed broken delta instruction
<1.6> 6/13/89 SJK Comment
<1.5> 6/2/89 CEL 16.16 scaling of metrics, minimum recommended ppem, point size 0
bug, correct transformed integralized ppem behavior, pretty much
so
<1.4> 5/26/89 CEL EASE messed up on “c” comments
<•1.3> 5/26/89 CEL Integrated the new Font Scaler 1.0 into Spline Fonts
To Do:
<24> Added string debug support. NewFDebugstr.
rwb 4/24/90 - changed scanctrl instruction to take 16 bit argument
*/
/******* MIKE PLEASE FIX up these comments so they fit in the header above with the same
FORMAT!!!
*/
/*
* File: fnt.c
*
* This module contains the interpreter that executes font instructions
*
* The BASS Project Interpreter and Font Instruction Set sub ERS contains
* relevant information.
*
* © Apple Computer Inc. 1987, 1988, 1989, 1990.
*
* History:
* Work on this module began in the fall of 1987
*
* Written June 23, 1988 by Sampo Kaasila
*
* Rewritten October 18, 1988 by Sampo Kaasila. Added a jump table instead of the switch statement.
* Also added CALL(), LOOPCALL(), FDEF(), ENDF(), and replaced WX(),WY(), RX(), RY(), MD()
* with new WC(), RC(), MD(). Reimplemented IUP(). Also optimized the code somewhat.
* Cast code into a more digestable form using a local and global graphics state.
*
* December 20, 1988. Added DELTA(), SDB(), SDS(), and deleted ONTON(), and ONTOFF(). ---Sampo.
*
* January 17, 1989 Added DEBUG(), RAW(), RLSB(), WLSB(), ALIGNPTS(), SANGW(), AA().
* Brought up this module to an alpha ready state. ---Sampo
*
* January 31, 1989 Added RDTG(), and RUTG().
*
* Feb 16, 1989 Completed final bug fixes for the alpha release.
*
* March 21, 1989 Fixed a small Twilight Zone bug in MIAP(), MSIRP(), and MIRP().
*
* March 28, 1989 Took away the need and reason for directional switches in the control value table.
* However, this forced a modification of all the code that reads or writes to the control
* value table and the single width. Also WCVT was replaced by WCVTFOL, WCVTFOD, and
* WCVTFCVT. ---Sampo
*
* April 17, 1989 Modified RPV(), RFV(), WPV(), WFV() to work with an x & y pair instead of just x. --- Sampo
*
* April 25, 1989 Fixed bugs in CEILING(), RUTG(), FDEF(), and IF(). Made MPPEM() a function of
* the projection vector. ---Sampo
*
* June 7, 1989 Made ALIGNRP() dependent on the loop variable, and also made it blissfully
* ignorant of the twilight zone.
* Also, added ROFF(), removed WCVTFCVT(), renamed WCVTFOL() to WCVT(), made MIRP() and
* MDRP() compensate for the engine even when there is no rounding. --- Sampo
*
* June 8, 1989 Made DELTA() dependent on the Transformation. ---Sampo
*
* June 19, 1989 Added JROF() and JROT(). ---Sampo
*
* July 14, 1989 Forced a pretty tame behaviour when abs((projection vector) * (freedoom vector)) < 1/16.
* The old behaviour was to grossly blow up the outline. This situation may happen for low pointsizes
* when the character is severly distorted due to the gridfitting ---Sampo
*
* July 17, 1989 Prevented the rounding routines from changing the sign of a quantity due to the engine compensation. ---Sampo
*
* July 19, 1989 Increased nummerical precision of fnt_MovePoint by 8 times. ---Sampo
*
* July 28, 1989 Introduced 5 more Delta instructions. (Now 3 are for points and 3 for the cvt.) ---Sampo
*
* Aug 24, 1989 fixed fnt_GetCVTEntrySlow and fnt_GetSingleWidthSlow bug ---Sampo
*
* Sep 26, 1989 changed rounding routines, so that the sign flip check only apply if the input value is nonzero. ---Sampo
*
* Oct 26, 1989 Fixed small bugs/features in fnt_RoundUpToGrid() and fnt_RoundToHalfGrid. Added SROUND() and S45ROUND(). ---Sampo
*
* Oct 31, 1989 Fixed transformation bug in fnt_MPPEM, fnt_DeltaEngine, fnt_GetCvtEntrySlow, fnt_GetSingleWidthSlow. ---Sampo
*
* Nov 3, 1989 Added FLIPPT(), FLIPRGON(), FLIPRGOFF(). ---Sampo
*
* Nov 16, 1989 Merged back in lost Nov 3 changes.---Sampo
*
* Dec 2, 1989 Added READMETRICS() aand WRITEMETRICS(). --- Sampo
*
* Jan 8, 1990 Added SDPVTL(). --- Sampo
*
* Jan 8, 1990 Eliminated bug in SFVTPV[] ( old bug ) and SFVTL[] (showed up because of SDPVTL[]). --- Sampo
*
* Jan 9, 1990 Added the SCANCTRL[] instruction. --- Sampo
*
* Jan 24, 1990 Fixed bug in fnt_ODD and fnt_EVEN. ---Sampo
*
* Jan 28, 1990 Fixed bug in fnt_Normalize. --- Sampo
*
* 2/9/90 mrr ReFixed Normalize bug, added ELSE and JMPR. Added pgmList[] to globalGS
in preparation for 3 preprograms. affected CALL, LOOPCALL, FDEF
* 2/21/90 mrr Added RMVT, WMVT.
* 3/7/90 mrr put in high precision versions of MUL and DIV.
*/
#include <setjmp.h>
/** FontScaler’s Includes **/
#include "FSCdefs.h"
#include "FontMath.h"
#include "sc.h"
#include "fnt.h"
#include "FSError.h"
/****** Macros *******/
#define POP( p ) ( *(--p) )
#define PUSH( p, x ) ( *(p)++ = (x) )
#define BADCOMPILER
#ifdef BADCOMPILER
#define BOOLEANPUSH( p, x ) PUSH( p, ((x) ? 1 : 0) ) /* MPW 3.0 */
#else
#define BOOLEANPUSH( p, x ) PUSH( p, x )
#endif
#define MAX(a,b) ((a) > (b) ? (a) : (b))
/* <24> Cal added printing debug support for developer init */
#ifdef DEBUG
/* FDebugStrNew routines CKL 6/25/1991 */
/* reverse string s in place <24> */
void reverse (char *s);
void reverse (char *s)
{
char c;
int i, j;
j=0;
while (s[j] != 0) ++j; /* find length of string */
for (i=0, j = j-1; i<j; i++, j--)
{
c = s[i];
s[i] = s[j];
s[j] = c;
}
}
/* convert n to characters in s <24> */
char *itoa (int n, char *s);
char *itoa (int n, char *s)
{
int i, sign;
if ((sign = n) <0)
{
n=-n;
}
i=0;
do
{
s[i++] = n%10+'0';
} while ((n/=10)>0);
if (sign<0)
{
s[i++] = '-';
}
s[i] = 0;
reverse(s) ;
return (s) ;
}
/* concatenate two strings <24> */
void catstrings (char *str1, char* str2);
void catstrings (char *str1, char* str2)
{
while (*str1 != 0) ++str1; /* find end of str1 */
while ((*str1++ = *str2++) != 0); /* copy str2 */
}
/* make c string into pascal string - rwb <24> */
void c2pas (char *str );
void c2pas (char *str )
{
int i;
int j = 0;
while (str[j] != 0) ++j; /* find end of str */
for( i = j; i>0; --i) str[i] = str[i-1];
str[0] = j;
}
void FDebugStrNew(char *str1, int n);
void FDebugStrNew(char *str1, int n)
{
char str0[80], str2[10];
str0[0] = 0;
catstrings (str0, str1);
itoa(n,str2); /* convert index to ASCII value */
catstrings (str0, str2) ; /* concatenate the two strings */
c2pas( str0);
DebugStr(str0);
}
void CHECK_RANGE(int32 n, int32 min, int32 max);
void CHECK_RANGE(int32 n, int32 min, int32 max)
{
if (n > max || n < min)
Debugger();
}
void CHECK_RANGE2(int32 n, int32 min, int32 max, fnt_GlobalGraphicStateType* gs);
void CHECK_RANGE2(int32 n, int32 min, int32 max, fnt_GlobalGraphicStateType* gs)
{
if (n > max || n < min)
FDebugStrNew("glyph id = ", gs->glyphIndex);
//FDebugStr("glyph id = 0x%x",gs->glyphIndex);
}
void CHECK_ASSERTION( int expression );
void CHECK_ASSERTION( int expression )
{
if (!expression)
Debugger();
}
void CHECK_CVT(fnt_LocalGraphicStateType* gs, int cvt);
void CHECK_CVT(fnt_LocalGraphicStateType* gs, int cvt)
{
CHECK_RANGE(cvt, 0, gs->globalGS->cvtCount-1);
}
void CHECK_CVT2(fnt_LocalGraphicStateType* gs, int cvt);
void CHECK_CVT2(fnt_LocalGraphicStateType* gs, int cvt)
{
CHECK_RANGE2(cvt, 0, gs->globalGS->cvtCount-1, gs->globalGS);
}
void CHECK_FDEF(fnt_LocalGraphicStateType* gs, int fdef);
void CHECK_FDEF(fnt_LocalGraphicStateType* gs, int fdef)
{
CHECK_RANGE(fdef, 0, gs->globalGS->maxp->maxFunctionDefs-1);
}
void CHECK_PROGRAM(int pgmIndex);
void CHECK_PROGRAM(int pgmIndex)
{
CHECK_RANGE(pgmIndex, 0, MAXPREPROGRAMS-1);
}
void CHECK_ELEMENT(fnt_LocalGraphicStateType* gs, int elem);
void CHECK_ELEMENT(fnt_LocalGraphicStateType* gs, int elem)
{
CHECK_RANGE(elem, 0, gs->globalGS->maxp->maxElements-1);
}
void CHECK_ELEMENTPTR(fnt_LocalGraphicStateType* gs, fnt_ElementType* elem);
void CHECK_ELEMENTPTR(fnt_LocalGraphicStateType* gs, fnt_ElementType* elem)
{
if (elem == &gs->elements[1])
{
int maxctrs, maxpts;
maxctrs = MAX(gs->globalGS->maxp->maxContours, gs->globalGS->maxp->maxCompositeContours);
maxpts = MAX(gs->globalGS->maxp->maxPoints, gs->globalGS->maxp->maxCompositePoints);
CHECK_RANGE(elem->nc, 1, maxctrs);
CHECK_RANGE(elem->ep[elem->nc-1], 0, maxpts-1);
}
else if (elem != &gs->elements[0])
{
Debugger();
}
}
void CHECK_STORAGE(fnt_LocalGraphicStateType* gs, int index);
void CHECK_STORAGE(fnt_LocalGraphicStateType* gs, int index)
{
CHECK_RANGE(index, 0, gs->globalGS->maxp->maxStorage-1);
}
void CHECK_STACK(fnt_LocalGraphicStateType* gs);
void CHECK_STACK(fnt_LocalGraphicStateType* gs)
{
CHECK_RANGE(gs->stackPointer - gs->globalGS->stackBase, 0, gs->globalGS->maxp->maxStackElements-1);
}
void CHECK_POINT(fnt_LocalGraphicStateType* gs, fnt_ElementType* elem, int pt);
void CHECK_POINT(fnt_LocalGraphicStateType* gs, fnt_ElementType* elem, int pt)
{
CHECK_ELEMENTPTR(gs, elem);
if (gs->elements == elem)
CHECK_RANGE(pt, 0, gs->globalGS->maxp->maxTwilightPoints - 1);
else
CHECK_RANGE(pt, 0, elem->ep[elem->nc-1] + 2); /* phantom points */
}
void CHECK_CONTOUR(fnt_LocalGraphicStateType* gs, fnt_ElementType* elem, int ctr);
void CHECK_CONTOUR(fnt_LocalGraphicStateType* gs, fnt_ElementType* elem, int ctr)
{
CHECK_ELEMENTPTR(gs, elem);
CHECK_RANGE(ctr, 0, elem->nc - 1);
}
#define CHECK_POP(gs, s) POP(s)
#define CHECK_PUSH(gs, s, v) PUSH(s, v)
#else
#define CHECK_RANGE(a,b,c)
#define CHECK_RANGE2(a,b,c)
#define CHECK_ASSERTION(a)
#define CHECK_CVT(a,b)
#define CHECK_CVT2(a,b)
#define CHECK_POINT(a,b,c)
#define CHECK_CONTOUR(a,b,c)
#define CHECK_FDEF(a,b)
#define CHECK_PROGRAM(a)
#define CHECK_ELEMENT(a,b)
#define CHECK_ELEMENTPTR(a,b)
#define CHECK_STORAGE(a,b)
#define CHECK_STACK(a)
#define CHECK_POP(gs, s) POP(s)
#define CHECK_PUSH(gs, s, v) PUSH(s, v)
#endif
#define GETBYTE(ptr) ( (uint8)*ptr++ )
#define MABS(x) ( (x) < 0 ? (-(x)) : (x) )
#define BIT0( t ) ( (t) & 0x01 )
#define BIT1( t ) ( (t) & 0x02 )
#define BIT2( t ) ( (t) & 0x04 )
#define BIT3( t ) ( (t) & 0x08 )
#define BIT4( t ) ( (t) & 0x10 )
#define BIT5( t ) ( (t) & 0x20 )
#define BIT6( t ) ( (t) & 0x40 )
#define BIT7( t ) ( (t) & 0x80 )
/******** 12 BinaryOperators **********/
#define LT_CODE 0x50
#define LTEQ_CODE 0x51
#define GT_CODE 0x52
#define GTEQ_CODE 0x53
#define EQ_CODE 0x54
#define NEQ_CODE 0x55
#define AND_CODE 0x5A
#define OR_CODE 0x5B
#define ADD_CODE 0x60
#define SUB_CODE 0x61
#define DIV_CODE 0x62
#define MUL_CODE 0x63
#define MAX_CODE 0x8b
#define MIN_CODE 0x8c
/******** 9 UnaryOperators **********/
#define ODD_CODE 0x56
#define EVEN_CODE 0x57
#define NOT_CODE 0x5C
#define ABS_CODE 0x64
#define NEG_CODE 0x65
#define FLOOR_CODE 0x66
#define CEILING_CODE 0x67
/******** 6 RoundState Codes **********/
#define RTG_CODE 0x18
#define RTHG_CODE 0x19
#define RTDG_CODE 0x3D
#define ROFF_CODE 0x7A
#define RUTG_CODE 0x7C
#define RDTG_CODE 0x7D
/****** LocalGS Codes *********/
#define POP_CODE 0x21
#define SRP0_CODE 0x10
#define SRP1_CODE 0x11
#define SRP2_CODE 0x12
#define SLOOP_CODE 0x17
#define LMD_CODE 0x1A
/****** Element Codes *********/
#define SCE0_CODE 0x13
#define SCE1_CODE 0x14
#define SCE2_CODE 0x15
#define SCES_CODE 0x16
/****** Control Codes *********/
#define IF_CODE 0x58
#define ELSE_CODE 0x1B
#define EIF_CODE 0x59
#define ENDF_CODE 0x2d
#define MD_CODE 0x49
/* flags for UTP, IUP, MovePoint */
#define XMOVED 0x01
#define YMOVED 0x02
#ifdef SEGMENT_LINK
#pragma segment FNT_C
#endif
/* <13> defines for kanji adjust from here*/
#define ADJUSTBASE 0x8F /* <15> base opcode for adjust instruction */
#define PIXEL 64
#define LG2PIXEL 6
#define HALF (PIXEL >> 1)
#define HALFM (HALF-1)
#define HALFP (HALF+1)
#define floor( x ) ((x) & ~0x3F )
typedef int pixel;
typedef int subPixel;
typedef short index;
/* <13> defines for kanji adjust to here */
/* Private function prototypes */
void fnt_Panic(fnt_LocalGraphicStateType *gs, int error);
void fnt_IllegalInstruction(fnt_LocalGraphicStateType *gs);
void fnt_Normalize(F26Dot6 x, F26Dot6 y, VECTOR*);
void fnt_MovePoint(fnt_LocalGraphicStateType *gs, fnt_ElementType *element, ArrayIndex point, F26Dot6 delta);
void fnt_XMovePoint(fnt_LocalGraphicStateType *, fnt_ElementType *element, ArrayIndex point, F26Dot6 delta) ;
void fnt_YMovePoint(fnt_LocalGraphicStateType *, fnt_ElementType *element, ArrayIndex point, F26Dot6 delta) ;
F26Dot6 fnt_Project(fnt_LocalGraphicStateType *gs, F26Dot6 x, F26Dot6 y);
F26Dot6 fnt_OldProject(fnt_LocalGraphicStateType *gs, F26Dot6 x, F26Dot6 y);
F26Dot6 fnt_XProject(fnt_LocalGraphicStateType *gs, F26Dot6 x, F26Dot6 y);
F26Dot6 fnt_YProject(fnt_LocalGraphicStateType *gs, F26Dot6 x, F26Dot6 y);
Fixed fnt_GetCVTScale(fnt_LocalGraphicStateType *gs);
F26Dot6 fnt_GetCVTEntryFast(fnt_LocalGraphicStateType *gs, ArrayIndex n);
F26Dot6 fnt_GetCVTEntrySlow(fnt_LocalGraphicStateType *gs, ArrayIndex n);
F26Dot6 fnt_GetSingleWidthFast(fnt_LocalGraphicStateType *gs);
F26Dot6 fnt_GetSingleWidthSlow(fnt_LocalGraphicStateType *gs);
void fnt_ChangeCvt(fnt_LocalGraphicStateType *gs, fnt_ElementType *element, ArrayIndex number, F26Dot6 delta);
void fnt_InnerTraceExecute(fnt_LocalGraphicStateType *gs, uint8 *ptr, uint8 *eptr);
void fnt_InnerExecute(fnt_LocalGraphicStateType *gs, uint8 *ptr, uint8 *eptr);
void fnt_Check_PF_Proj(fnt_LocalGraphicStateType *gs);
void fnt_ComputeAndCheck_PF_Proj(fnt_LocalGraphicStateType *gs);
Fract fnt_QuickDist(Fract dx, Fract dy);
void fnt_SetRoundValues(fnt_LocalGraphicStateType *gs, int arg1, int normalRound);
F26Dot6 fnt_CheckSingleWidth(F26Dot6 value, fnt_LocalGraphicStateType *gs);
fnt_instrDef* fnt_FindIDef(fnt_LocalGraphicStateType* gs, uint8 opCode);
void fnt_DeltaEngine(fnt_LocalGraphicStateType *gs, FntMoveFunc doIt, int16 base, int16 shift);
void fnt_DefaultJumpTable( voidFunc* function );
/* Actual instructions for the jump table */
void fnt_SVTCA_0(fnt_LocalGraphicStateType *gs);
void fnt_SVTCA_1(fnt_LocalGraphicStateType *gs);
void fnt_SPVTCA(fnt_LocalGraphicStateType *gs);
void fnt_SFVTCA(fnt_LocalGraphicStateType *gs);
void fnt_SPVTL(fnt_LocalGraphicStateType *gs);
void fnt_SDPVTL(fnt_LocalGraphicStateType *gs);
void fnt_SFVTL(fnt_LocalGraphicStateType *gs);
void fnt_SPVFS(fnt_LocalGraphicStateType *gs);
void fnt_SFVFS(fnt_LocalGraphicStateType *gs);
void fnt_GPV(fnt_LocalGraphicStateType *gs);
void fnt_GFV(fnt_LocalGraphicStateType *gs);
void fnt_SFVTPV(fnt_LocalGraphicStateType *gs);
void fnt_ISECT(fnt_LocalGraphicStateType *gs);
void fnt_SetLocalGraphicState(fnt_LocalGraphicStateType *gs);
void fnt_SetElementPtr(fnt_LocalGraphicStateType *gs);
void fnt_SetRoundState(fnt_LocalGraphicStateType *gs);
void fnt_SROUND(fnt_LocalGraphicStateType *gs);
void fnt_S45ROUND(fnt_LocalGraphicStateType *gs);
void fnt_SMD(fnt_LocalGraphicStateType *gs);
void fnt_RAW(fnt_LocalGraphicStateType *gs);
void fnt_WLSB(fnt_LocalGraphicStateType *gs);
void fnt_SCVTCI(fnt_LocalGraphicStateType *gs);
void fnt_SSWCI(fnt_LocalGraphicStateType *gs);
void fnt_SSW(fnt_LocalGraphicStateType *gs);
void fnt_DUP(fnt_LocalGraphicStateType *gs);
void fnt_POP(fnt_LocalGraphicStateType *gs);
void fnt_CLEAR(fnt_LocalGraphicStateType *gs);
void fnt_SWAP(fnt_LocalGraphicStateType *gs);
void fnt_DEPTH(fnt_LocalGraphicStateType *gs);
void fnt_CINDEX(fnt_LocalGraphicStateType *gs);
void fnt_MINDEX(fnt_LocalGraphicStateType *gs);
void fnt_ROLL( fnt_LocalGraphicStateType* gs );
void fnt_MDAP(fnt_LocalGraphicStateType *gs);
void fnt_MIAP(fnt_LocalGraphicStateType *gs);
void fnt_IUP(fnt_LocalGraphicStateType *gs);
void fnt_SHP(fnt_LocalGraphicStateType *gs);
void fnt_SHC(fnt_LocalGraphicStateType *gs);
void fnt_SHZ(fnt_LocalGraphicStateType *gs);
void fnt_SHPIX(fnt_LocalGraphicStateType *gs);
void fnt_IP(fnt_LocalGraphicStateType *gs);
void fnt_MSIRP(fnt_LocalGraphicStateType *gs);
void fnt_ALIGNRP(fnt_LocalGraphicStateType *gs);
void fnt_ALIGNPTS(fnt_LocalGraphicStateType *gs);
void fnt_SANGW(fnt_LocalGraphicStateType *gs);
void fnt_FLIPPT(fnt_LocalGraphicStateType *gs);
void fnt_FLIPRGON(fnt_LocalGraphicStateType *gs);
void fnt_FLIPRGOFF(fnt_LocalGraphicStateType *gs);
void fnt_SCANCTRL(fnt_LocalGraphicStateType *gs);
void fnt_SCANTYPE(fnt_LocalGraphicStateType *gs);
void fnt_INSTCTRL(fnt_LocalGraphicStateType *gs);
void fnt_AA(fnt_LocalGraphicStateType *gs);
void fnt_NPUSHB(fnt_LocalGraphicStateType *gs);
void fnt_NPUSHW(fnt_LocalGraphicStateType *gs);
void fnt_WS(fnt_LocalGraphicStateType *gs);
void fnt_RS(fnt_LocalGraphicStateType *gs);
void fnt_WCVTP(fnt_LocalGraphicStateType *gs);
void fnt_WCVTF(fnt_LocalGraphicStateType *gs);
void fnt_RCVT(fnt_LocalGraphicStateType *gs);
void fnt_GC(fnt_LocalGraphicStateType *gs);
void fnt_SCFS(fnt_LocalGraphicStateType *gs);
void fnt_MD(fnt_LocalGraphicStateType *gs);
void fnt_MPPEM(fnt_LocalGraphicStateType *gs);
void fnt_MPS(fnt_LocalGraphicStateType *gs);
void fnt_GETINFO(fnt_LocalGraphicStateType* gs);
void fnt_FLIPON(fnt_LocalGraphicStateType *gs);
void fnt_FLIPOFF(fnt_LocalGraphicStateType *gs);
#ifndef NOT_ON_THE_MAC
#ifdef DEBUG
void fnt_DDT(int8 c, int32 n);
#endif
#endif
void fnt_DEBUG(fnt_LocalGraphicStateType *gs);
void fnt_SkipPushCrap(fnt_LocalGraphicStateType *gs);
void fnt_IF(fnt_LocalGraphicStateType *gs);
void fnt_ELSE( fnt_LocalGraphicStateType* gs );
void fnt_EIF(fnt_LocalGraphicStateType *gs);
void fnt_JMPR( fnt_LocalGraphicStateType* gs );
void fnt_JROT(fnt_LocalGraphicStateType *gs);
void fnt_JROF(fnt_LocalGraphicStateType *gs);
void fnt_BinaryOperand(fnt_LocalGraphicStateType*);
void fnt_UnaryOperand(fnt_LocalGraphicStateType*);
void fnt_ROUND(fnt_LocalGraphicStateType *gs);
void fnt_NROUND(fnt_LocalGraphicStateType *gs);
void fnt_PUSHB(fnt_LocalGraphicStateType *gs);
void fnt_PUSHW(fnt_LocalGraphicStateType *gs);
void fnt_MDRP(fnt_LocalGraphicStateType *gs);
void fnt_MIRP(fnt_LocalGraphicStateType *gs);
void fnt_CALL(fnt_LocalGraphicStateType *gs);
void fnt_FDEF(fnt_LocalGraphicStateType *gs);
void fnt_LOOPCALL(fnt_LocalGraphicStateType *gs);
void fnt_IDefPatch( fnt_LocalGraphicStateType* gs );
void fnt_IDEF( fnt_LocalGraphicStateType* gs );
void fnt_UTP(fnt_LocalGraphicStateType *gs);
void fnt_SDB(fnt_LocalGraphicStateType *gs);
void fnt_SDS(fnt_LocalGraphicStateType *gs);
void fnt_DELTAP1(fnt_LocalGraphicStateType *gs);
void fnt_DELTAP2(fnt_LocalGraphicStateType *gs);
void fnt_DELTAP3(fnt_LocalGraphicStateType *gs);
void fnt_DELTAC1(fnt_LocalGraphicStateType *gs);
void fnt_DELTAC2(fnt_LocalGraphicStateType *gs);
void fnt_DELTAC3(fnt_LocalGraphicStateType *gs);
void fnt_ADJUST( fnt_LocalGraphicStateType *gs ); /* <13> */
/*
* We exit through here, when we detect serious errors.
*/
void fnt_Panic( fnt_LocalGraphicStateType* gs, int error )
{
longjmp( gs->env, error ); /* Do a gracefull recovery */
}
/***************************/
#define fnt_NextPt1( pt, elem, ctr ) ( (pt) == elem->ep[(ctr)] ? elem->sp[(ctr)] : (pt)+1 )
/*
* Illegal instruction panic
*/
static void fnt_IllegalInstruction(register fnt_LocalGraphicStateType *gs)
{
fnt_Panic( gs, UNDEFINED_INSTRUCTION_ERR );
}
#define bitcount(a, count) \
{ \
count = 0; \
while (a) \
{ \
a >>= 1; \
count++; \
} \
}
static void fnt_Normalize(F26Dot6 x, F26Dot6 y, VECTOR* v)
{
Fract x1, y1;
/*
* Since x and y are 26.6, and currently that means they are really 16.6,
* when treated as Fract, they are 0.[8]22, so shift up to 0.30 for accuracy
*/
CHECK_RANGE(x, -32768L << 6, 32767L << 6);
CHECK_RANGE(y, -32768L << 6, 32767L << 6);
{
int shift, count;
F26Dot6 xx = x;
F26Dot6 yy = y;
if (xx < 0) xx = -xx;
if (yy < 0) yy = -yy;
if (xx < yy) xx = yy;
/*
* 0.5 <= max(x,y) < 1
*/
bitcount(xx, count);
shift = 8 * sizeof(Fract) - 2 - count;
x1 = (Fract) x << shift;
y1 = (Fract) y << shift;
}
{
Fract length;
if (length = FracSqrt( FracMul( x1, x1 ) + FracMul( y1, y1 ) )) /*<16>*/
{
v->x = FIXROUND( FracDiv( x1, length ) );
v->y = FIXROUND( FracDiv( y1, length ) );
}
else
/* length is 0 set up the projection vector along the x axis <16>*/
{
v->x = ONEVECTOR;
v->y = 0;
}
}
}
/******************** BEGIN Rounding Routines ***************************/
/*
* Internal rounding routine
*/
F26Dot6 fnt_RoundToDoubleGrid(register F26Dot6 xin, F26Dot6 engine, fnt_LocalGraphicStateType* gs)
{
#pragma unused(gs)
register F26Dot6 x = xin;
if ( x >= 0 ) {
x += engine;
x += fnt_pixelSize/4;
x &= ~(fnt_pixelSize/2-1);
} else {
x = -x;
x += engine;
x += fnt_pixelSize/4;
x &= ~(fnt_pixelSize/2-1);
x = -x;
}
if ( ((int32)(xin ^ x)) < 0 && xin ) {
x = 0; /* The sign flipped, make zero */
}
return x;
}
/*
* Internal rounding routine
*/
F26Dot6 fnt_RoundDownToGrid(register F26Dot6 xin, F26Dot6 engine, fnt_LocalGraphicStateType* gs)
{
#pragma unused(gs)
register F26Dot6 x = xin;
if ( x >= 0 ) {
x += engine;
x &= ~(fnt_pixelSize-1);
} else {
x = -x;
x += engine;
x &= ~(fnt_pixelSize-1);
x = -x;
}
if ( ((int32)(xin ^ x)) < 0 && xin ) {
x = 0; /* The sign flipped, make zero */
}
return x;
}
/*
* Internal rounding routine
*/
F26Dot6 fnt_RoundUpToGrid(register F26Dot6 xin, F26Dot6 engine, fnt_LocalGraphicStateType* gs)
{
#pragma unused(gs)
register F26Dot6 x = xin;
if ( x >= 0 ) {
x += engine;
x += fnt_pixelSize - 1;
x &= ~(fnt_pixelSize-1);
} else {
x = -x;
x += engine;
x += fnt_pixelSize - 1;
x &= ~(fnt_pixelSize-1);
x = -x;
}
if ( ((int32)(xin ^ x)) < 0 && xin ) {
x = 0; /* The sign flipped, make zero */
}
return x;
}
/*
* Internal rounding routine
*/
F26Dot6 fnt_RoundToGrid(register F26Dot6 xin, F26Dot6 engine, fnt_LocalGraphicStateType* gs)
{
#pragma unused(gs)
register F26Dot6 x = xin;
if ( x >= 0 ) {
x += engine;
x += fnt_pixelSize/2;
x &= ~(fnt_pixelSize-1);
} else {
x = -x;
x += engine;
x += fnt_pixelSize/2;
x &= ~(fnt_pixelSize-1);
x = -x;
}
if ( ((int32)(xin ^ x)) < 0 && xin ) {
x = 0; /* The sign flipped, make zero */
}
return x;
}
/*
* Internal rounding routine
*/
F26Dot6 fnt_RoundToHalfGrid(register F26Dot6 xin, F26Dot6 engine, fnt_LocalGraphicStateType* gs)
{
#pragma unused(gs)
register F26Dot6 x = xin;
if ( x >= 0 ) {
x += engine;
x &= ~(fnt_pixelSize-1);
x += fnt_pixelSize/2;
} else {
x = -x;
x += engine;
x &= ~(fnt_pixelSize-1);
x += fnt_pixelSize/2;
x = -x;
}
if ( ((int32)(xin ^ x)) < 0 && xin ) {
x = xin > 0 ? fnt_pixelSize/2 : -fnt_pixelSize/2; /* The sign flipped, make equal to smallest valid value */
}
return x;
}
/*
* Internal rounding routine
*/
F26Dot6 fnt_RoundOff(register F26Dot6 xin, F26Dot6 engine, fnt_LocalGraphicStateType* gs)
{
#pragma unused(gs)
register F26Dot6 x = xin;
if ( x >= 0 ) {
x += engine;
} else {
x -= engine;
}
if ( ((int32)(xin ^ x)) < 0 && xin) {
x = 0; /* The sign flipped, make zero */
}
return x;
}
/*
* Internal rounding routine
*/
F26Dot6 fnt_SuperRound(register F26Dot6 xin, F26Dot6 engine, register fnt_LocalGraphicStateType *gs)
{
register F26Dot6 x = xin;
register fnt_ParameterBlock *pb = &gs->globalGS->localParBlock;
if ( x >= 0 ) {
x += engine;
x += pb->threshold - pb->phase;
x &= pb->periodMask;
x += pb->phase;
} else {
x = -x;
x += engine;
x += pb->threshold - pb->phase;
x &= pb->periodMask;
x += pb->phase;
x = -x;
}
if ( ((int32)(xin ^ x)) < 0 && xin ) {
x = xin > 0 ? pb->phase : -pb->phase; /* The sign flipped, make equal to smallest phase */
}
return x;
}
/*
* Internal rounding routine
*/
F26Dot6 fnt_Super45Round(register F26Dot6 xin, F26Dot6 engine, register fnt_LocalGraphicStateType *gs)
{
register F26Dot6 x = xin;
register fnt_ParameterBlock *pb = &gs->globalGS->localParBlock;
if ( x >= 0 ) {
x += engine;
x += pb->threshold - pb->phase;
x = FracDiv( x, pb->period45 );
x &= ~(fnt_pixelSize-1);
x = FracMul( x, pb->period45 );
x += pb->phase;
} else {
x = -x;
x += engine;
x += pb->threshold - pb->phase;
x = FracDiv( x, pb->period45 );
x &= ~(fnt_pixelSize-1);
x = FracMul( x, pb->period45 );
x += pb->phase;
x = -x;
}
if ( ((int32)(xin ^ x)) < 0 && xin ) {
x = xin > 0 ? pb->phase : -pb->phase; /* The sign flipped, make equal to smallest phase */
}
return x;
}
/******************** END Rounding Routines ***************************/
/* 3-versions ************************************************************************/
/*
* Moves the point in element by delta (measured against the projection vector)
* along the freedom vector.
*/
static void fnt_MovePoint(register fnt_LocalGraphicStateType *gs,
register fnt_ElementType *element,
register ArrayIndex point,
register F26Dot6 delta)
{
register VECTORTYPE pfProj = gs->pfProj;
register VECTORTYPE fx = gs->free.x;
register VECTORTYPE fy = gs->free.y;
CHECK_POINT( gs, element, point );
if ( pfProj != ONEVECTOR )
{
if ( fx ) {
element->x[point] += VECTORMULDIV( delta, fx, pfProj );
element->f[point] |= XMOVED;
}
if ( fy ) {
element->y[point] += VECTORMULDIV( delta, fy, pfProj );
element->f[point] |= YMOVED;
}
}
else
{
if ( fx ) {
element->x[point] += VECTORMUL( delta, fx );
element->f[point] |= XMOVED;
}
if ( fy ) {
element->y[point] += VECTORMUL( delta, fy );
element->f[point] |= YMOVED;
}
}
}
/*
* For use when the projection and freedom vectors coincide along the x-axis.
*/
static void fnt_XMovePoint( fnt_LocalGraphicStateType* gs, fnt_ElementType* element, ArrayIndex point, register F26Dot6 delta )
{
#ifndef DEBUG
#pragma unused(gs)
#endif
CHECK_POINT( gs, element, point );
element->x[point] += delta;
element->f[point] |= XMOVED;
}
/*
* For use when the projection and freedom vectors coincide along the y-axis.
*/
static void fnt_YMovePoint( fnt_LocalGraphicStateType* gs, register fnt_ElementType *element, ArrayIndex point, F26Dot6 delta )
{
#ifndef DEBUG
#pragma unused(gs)
#endif
CHECK_POINT( gs, element, point );
element->y[point] += delta;
element->f[point] |= YMOVED;
}
/*
* projects x and y into the projection vector.
*/
static F26Dot6 fnt_Project(fnt_LocalGraphicStateType* gs, F26Dot6 x, F26Dot6 y)
{
return( VECTORMUL( x, gs->proj.x ) + VECTORMUL( y, gs->proj.y ) );
}
/*
* projects x and y into the old projection vector.