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
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
|
/* $XConsortium: type1.c,v 1.5 91/10/10 11:20:06 rws Exp $ */
/* Copyright International Business Machines, Corp. 1991
* All Rights Reserved
* Copyright Lexmark International, Inc. 1991
* All Rights Reserved
* Portions Copyright (c) 1990 Adobe Systems Incorporated.
* All Rights Reserved
*
* License to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of IBM or Lexmark or Adobe
* not be used in advertising or publicity pertaining to distribution of
* the software without specific, written prior permission.
*
* IBM, LEXMARK, AND ADOBE PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY
* WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
* LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. THE
* ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING
* ANY DUTY TO SUPPORT OR MAINTAIN, BELONGS TO THE LICENSEE. SHOULD ANY
* PORTION OF THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM,
* LEXMARK, OR ADOBE) ASSUMES THE ENTIRE COST OF ALL SERVICING, REPAIR AND
* CORRECTION. IN NO EVENT SHALL IBM, LEXMARK, OR ADOBE BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*********************************************************************/
/* */
/* Type 1 module - Converting fonts in Adobe Type 1 Font Format */
/* to scaled and hinted paths for rasterization. */
/* Files: type1.c, type1.h, and blues.h. */
/* */
/* Authors: Sten F. Andler, IBM Almaden Research Center */
/* (Type 1 interpreter, stem & flex hints) */
/* */
/* Patrick A. Casey, Lexmark International, Inc. */
/* (Font level hints & stem hints) */
/* */
/*********************************************************************/
/******************/
/* Include Files: */
/******************/
#include "types.h"
#include <stdio.h> /* a system-dependent include, usually */
#include "objects.h"
#include "spaces.h"
#include "paths.h"
#include "fonts.h" /* understands about TEXTTYPEs */
#include "pictures.h" /* understands about handles */
typedef struct xobject xobject;
#include "util.h" /* PostScript objects */
#include "blues.h" /* Blues structure for font-level hints */
/**********************************/
/* Type1 Constants and Structures */
/**********************************/
#define MAXSTACK 24 /* Adobe Type1 limit */
#define MAXCALLSTACK 10 /* Adobe Type1 limit */
#define MAXPSFAKESTACK 32 /* Max depth of fake PostScript stack (local) */
#define MAXSTRLEN 512 /* Max length of a Type 1 string (local) */
#define MAXLABEL 256 /* Maximum number of new hints */
#define MAXSTEMS 128 /* Maximum number of VSTEM and HSTEM hints */
#define EPS 0.001 /* Small number for comparisons */
/************************************/
/* Adobe Type 1 CharString commands */
/************************************/
#define HSTEM 1
#define VSTEM 3
#define VMOVETO 4
#define RLINETO 5
#define HLINETO 6
#define VLINETO 7
#define RRCURVETO 8
#define CLOSEPATH 9
#define CALLSUBR 10
#define RETURN 11
#define ESCAPE 12
#define HSBW 13
#define ENDCHAR 14
#define RMOVETO 21
#define HMOVETO 22
#define VHCURVETO 30
#define HVCURVETO 31
/*******************************************/
/* Adobe Type 1 CharString Escape commands */
/*******************************************/
#define DOTSECTION 0
#define VSTEM3 1
#define HSTEM3 2
#define SEAC 6
#define SBW 7
#define DIV 12
#define CALLOTHERSUBR 16
#define POP 17
#define SETCURRENTPOINT 33
/*****************/
/* Useful macros */
/*****************/
static DOUBLE tmpx; /* Store macro argument in tmpx to avoid re-evaluation */
static LONG tmpi; /* Store converted value in tmpi to avoid re-evaluation */
#define FABS(x) (((tmpx = (x)) < 0.0) ? -tmpx : tmpx)
#define CEIL(x) (((tmpi = (LONG) (tmpx = (x))) < tmpx) ? ++tmpi : tmpi)
#define FLOOR(x) (((tmpi = (LONG) (tmpx = (x))) > tmpx) ? --tmpi : tmpi)
#define ROUND(x) FLOOR((x) + 0.5)
#define ODD(x) (((int)(x)) & 01)
int currentchar = -1; /* for error reporting */
#define CC IfTrace1(TRUE, "'%03o ", currentchar)
#define Error {errflag = TRUE; return;}
#define Error0(errmsg) { CC; IfTrace0(TRUE, errmsg); Error;}
#define Error1(errmsg,arg) { CC; IfTrace1(TRUE, errmsg, arg); Error;}
/********************/
/* global variables */
/********************/
struct stem { /* representation of a STEM hint */
int vertical; /* TRUE if vertical, FALSE otherwise */
DOUBLE x, dx; /* interval of vertical stem */
DOUBLE y, dy; /* interval of horizontal stem */
struct segment *lbhint, *lbrevhint; /* left or bottom hint adjustment */
struct segment *rthint, *rtrevhint; /* right or top hint adjustment */
};
extern struct XYspace *IDENTITY;
static DOUBLE escapementX, escapementY;
static DOUBLE sidebearingX, sidebearingY;
static DOUBLE accentoffsetX, accentoffsetY;
static struct segment *path;
static int errflag;
/*************************************************/
/* Global variables to hold Type1Char parameters */
/*************************************************/
static char *Environment;
static struct XYspace *CharSpace;
static psobj *CharStringP, *SubrsP, *OtherSubrsP;
static int *ModeP;
/************************/
/* Forward declarations */
/************************/
#ifdef WIN32
/* Unfortunately, there is such a function in the Win32 API */
#define Escape Type1Escape
#endif
#ifdef KPATHSEA
static void ComputeAlignmentZones P1H(void);
static void InitStems P1H(void);
static void FinitStems P1H(void);
static void ComputeStem P1H(int stemno);
static struct segment *Applyhint P3H(struct segment *p,int stemnumber,int half);
static struct segment *Applyrevhint P3H(struct segment *p,int stemnumber,int half);
static struct segment *FindStems P4H(DOUBLE x,DOUBLE y,DOUBLE dx,DOUBLE dy);
static void ClearStack P1H(void);
static void Push P1H(DOUBLE Num);
static void ClearCallStack P1H(void);
static void PushCall P3H(psobj *CurrStrP,int CurrIndex,unsigned short CurrKey);
static void PopCall P3H(psobj **CurrStrPP ,int *CurrIndexP,unsigned short *CurrKeyP);
static void ClearPSFakeStack P1H(void);
static void PSFakePush P1H(DOUBLE Num);
static DOUBLE PSFakePop P1H(void);
static struct segment *CenterStem P2H(DOUBLE edge1,DOUBLE edge2);
static unsigned char Decrypt P1H(unsigned char cipher);
static int DoRead P1H(int *CodeP);
static void StartDecrypt P1H(void);
static void Decode P1H(int Code);
static void DoCommand P1H(int Code);
static void Escape P1H(int Code);
static void HStem P2H(DOUBLE y,DOUBLE dy);
static void VStem P2H(DOUBLE x,DOUBLE dx);
static void RLineTo P2H(DOUBLE dx,DOUBLE dy);
static void RRCurveTo P6H(DOUBLE dx1,DOUBLE dy1,DOUBLE dx2,DOUBLE dy2,DOUBLE dx3,DOUBLE dy3);
static void DoClosePath P1H(void);
static void CallSubr P1H(int subrno);
static void Return P1H(void);
static void EndChar P1H(void);
static void RMoveTo P2H(DOUBLE dx,DOUBLE dy);
static void DotSection P1H(void);
static void Seac P5H(DOUBLE asb,DOUBLE adx,DOUBLE ady,unsigned char bchar,unsigned char achar);
static void Sbw P4H(DOUBLE sbx,DOUBLE sby,DOUBLE wx,DOUBLE wy);
static DOUBLE Div P2H(DOUBLE num1,DOUBLE num2);
static void FlxProc AA((DOUBLE c1x2,DOUBLE c1y2,DOUBLE c3x0,DOUBLE c3y0,DOUBLE c3x1,DOUBLE c3y1,DOUBLE c3x2,DOUBLE c3y2,DOUBLE c4x0,DOUBLE c4y0,DOUBLE c4x1,DOUBLE c4y1,DOUBLE c4x2,DOUBLE c4y2,DOUBLE epY,DOUBLE epX,int idmin));
static void FlxProc1 P1H(void);
static void FlxProc2 P1H(void);
static void HintReplace P1H(void);
static void CallOtherSubr P1H(int othersubrno);
static void SetCurrentPoint P2H(DOUBLE x,DOUBLE y);
extern struct xobject *Type1Char AA((char *env,struct XYspace *S,psobj *charstrP,psobj *subrsP,psobj *osubrsP,struct blues_struct *bluesP,int *modeP));
#else
static DOUBLE Div();
static DOUBLE PSFakePop();
static DoCommand();
static Escape();
static HStem();
static VStem();
static RLineTo();
static RRCurveTo();
static DoClosePath();
static CallSubr();
static Return();
static EndChar();
static RMoveTo();
static DotSection();
static Seac();
static Sbw();
static CallOtherSubr();
static SetCurrentPoint();
#endif
/*****************************************/
/* statics for Flex procedures (FlxProc) */
/*****************************************/
static struct segment *FlxOldPath; /* save path before Flex feature */
/******************************************************/
/* statics for Font level hints (Blues) (see blues.h) */
/******************************************************/
static struct blues_struct *blues; /* the blues structure */
static struct alignmentzone alignmentzones[MAXALIGNMENTZONES];
int numalignmentzones; /* total number of alignment zones */
/****************************************************************/
/* Subroutines for the Font level hints (Alignment zones, etc.) */
/****************************************************************/
/******************************************/
/* Fill in the alignment zone structures. */
/******************************************/
static void ComputeAlignmentZones()
{
int i;
DOUBLE dummy, bluezonepixels, familyzonepixels;
struct segment *p;
numalignmentzones = 0; /* initialize total # of zones */
/* do the BlueValues zones */
for (i = 0; i < blues->numBlueValues; i +=2, ++numalignmentzones) {
/* the 0th & 1st numbers in BlueValues are for a bottom zone */
/* the rest are topzones */
if (i == 0) /* bottom zone */
alignmentzones[numalignmentzones].topzone = FALSE;
else /* top zone */
alignmentzones[numalignmentzones].topzone = TRUE;
if (i < blues->numFamilyBlues) { /* we must consider FamilyBlues */
p = ILoc(CharSpace,0,blues->BlueValues[i] - blues->BlueValues[i+1]);
QueryLoc(p, IDENTITY, &dummy, &bluezonepixels);
Destroy(p);
p = ILoc(CharSpace,0,blues->FamilyBlues[i]-blues->FamilyBlues[i+1]);
QueryLoc(p, IDENTITY, &dummy, &familyzonepixels);
Destroy(p);
/* is the difference in size of the zones less than 1 pixel? */
if (FABS(bluezonepixels - familyzonepixels) < 1.0) {
/* use the Family zones */
alignmentzones[numalignmentzones].bottomy =
blues->FamilyBlues[i];
alignmentzones[numalignmentzones].topy =
blues->FamilyBlues[i+1];
continue;
}
}
/* use this font's Blue zones */
alignmentzones[numalignmentzones].bottomy = blues->BlueValues[i];
alignmentzones[numalignmentzones].topy = blues->BlueValues[i+1];
}
/* do the OtherBlues zones */
for (i = 0; i < blues->numOtherBlues; i +=2, ++numalignmentzones) {
/* all of the OtherBlues zones are bottom zones */
alignmentzones[numalignmentzones].topzone = FALSE;
if (i < blues->numFamilyOtherBlues) {/* consider FamilyOtherBlues */
p = ILoc(CharSpace,0,blues->OtherBlues[i] - blues->OtherBlues[i+1]);
QueryLoc(p, IDENTITY, &dummy, &bluezonepixels);
Destroy(p);
p = ILoc(CharSpace,0,blues->FamilyOtherBlues[i] -
blues->FamilyOtherBlues[i+1]);
QueryLoc(p, IDENTITY, &dummy, &familyzonepixels);
Destroy(p);
/* is the difference in size of the zones less than 1 pixel? */
if (FABS(bluezonepixels - familyzonepixels) < 1.0) {
/* use the Family zones */
alignmentzones[numalignmentzones].bottomy =
blues->FamilyOtherBlues[i];
alignmentzones[numalignmentzones].topy =
blues->FamilyOtherBlues[i+1];
continue;
}
}
/* use this font's Blue zones (as opposed to the Family Blues */
alignmentzones[numalignmentzones].bottomy = blues->OtherBlues[i];
alignmentzones[numalignmentzones].topy = blues->OtherBlues[i+1];
}
}
/**********************************************************************/
/* Subroutines and statics for handling of the VSTEM and HSTEM hints. */
/**********************************************************************/
int InDotSection; /* DotSection flag */
struct stem stems[MAXSTEMS]; /* All STEM hints */
int numstems; /* Number of STEM hints */
int currstartstem; /* The current starting stem. */
int oldvert, oldhor; /* Remember hint in effect */
int oldhorhalf, oldverthalf; /* Remember which half of the stem */
DOUBLE wsoffsetX, wsoffsetY; /* White space offset - for VSTEM3,HSTEM3 */
int wsset; /* Flag for whether we've set wsoffsetX,Y */
static void InitStems() /* Initialize the STEM hint data structures */
{
InDotSection = FALSE;
currstartstem = numstems = 0;
oldvert = oldhor = -1;
}
static void FinitStems() /* Terminate the STEM hint data structures */
{
int i;
for (i = 0; i < numstems; i++) {
Destroy(stems[i].lbhint);
Destroy(stems[i].lbrevhint);
Destroy(stems[i].rthint);
Destroy(stems[i].rtrevhint);
}
}
/*******************************************************************/
/* Compute the dislocation that a stemhint should cause for points */
/* inside the stem. */
/*******************************************************************/
static void ComputeStem(stemno)
int stemno;
{
int verticalondevice, idealwidth;
DOUBLE stemstart, stemwidth;
struct segment *p;
int i;
DOUBLE stembottom, stemtop, flatposition;
DOUBLE Xpixels, Ypixels;
DOUBLE unitpixels, onepixel;
int suppressovershoot, enforceovershoot;
DOUBLE stemshift, flatpospixels, overshoot;
DOUBLE widthdiff; /* Number of character space units to adjust width */
DOUBLE lbhintvalue, rthintvalue;
DOUBLE cxx, cyx, cxy, cyy; /* Transformation matrix */
int rotated; /* TRUE if character is on the side, FALSE if upright */
/************************************************/
/* DETERMINE ORIENTATION OF CHARACTER ON DEVICE */
/************************************************/
QuerySpace(CharSpace, &cxx, &cyx, &cxy, &cyy); /* Transformation matrix */
if (FABS(cxx) < 0.00001 || FABS(cyy) < 0.00001)
rotated = TRUE; /* Char is on side (90 or 270 degrees), possibly oblique. */
else if (FABS(cyx) < 0.00001 || FABS(cxy) < 0.00001)
rotated = FALSE; /* Char is upright (0 or 180 degrees), possibly oblique. */
else {
stems[stemno].lbhint = NULL; /* Char is at non-axial angle, ignore hints. */
stems[stemno].lbrevhint = NULL;
stems[stemno].rthint = NULL;
stems[stemno].rtrevhint = NULL;
return;
}
/* Determine orientation of stem */
if (stems[stemno].vertical) {
verticalondevice = !rotated;
stemstart = stems[stemno].x;
stemwidth = stems[stemno].dx;
} else {
verticalondevice = rotated;
stemstart = stems[stemno].y;
stemwidth = stems[stemno].dy;
}
/* Determine how many pixels (non-negative) correspond to 1 character space
unit (unitpixels), and how many character space units (non-negative)
correspond to one pixel (onepixel). */
if (stems[stemno].vertical)
p = ILoc(CharSpace, 1, 0);
else
p = ILoc(CharSpace, 0, 1);
QueryLoc(p, IDENTITY, &Xpixels, &Ypixels);
Destroy(p);
if (verticalondevice)
unitpixels = FABS(Xpixels);
else
unitpixels = FABS(Ypixels);
onepixel = 1.0 / unitpixels;
/**********************/
/* ADJUST STEM WIDTHS */
/**********************/
widthdiff = 0.0;
/* Find standard stem with smallest width difference from this stem */
if (stems[stemno].vertical) { /* vertical stem */
if (blues->StdVW != 0) /* there is an entry for StdVW */
widthdiff = blues->StdVW - stemwidth;
for (i = 0; i < blues->numStemSnapV; ++i) { /* now look at StemSnapV */
if (blues->StemSnapV[i] - stemwidth < widthdiff)
/* this standard width is the best match so far for this stem */
widthdiff = blues->StemSnapV[i] - stemwidth;
}
} else { /* horizontal stem */
if (blues->StdHW != 0) /* there is an entry for StdHW */
widthdiff = blues->StdHW - stemwidth;
for (i = 0; i < blues->numStemSnapH; ++i) { /* now look at StemSnapH */
if (blues->StemSnapH[i] - stemwidth < widthdiff)
/* this standard width is the best match so far for this stem */
widthdiff = blues->StemSnapH[i] - stemwidth;
}
}
/* Only expand or contract stems if they differ by less than 1 pixel from
the closest standard width, otherwise make the width difference = 0. */
if (FABS(widthdiff) > onepixel)
widthdiff = 0.0;
/* Expand or contract stem to the nearest integral number of pixels. */
idealwidth = ROUND((stemwidth + widthdiff) * unitpixels);
/* Ensure that all stems are at least one pixel wide. */
if (idealwidth == 0)
idealwidth = 1;
/* Apply ForceBold to vertical stems. */
if (blues->ForceBold && stems[stemno].vertical)
/* Force this vertical stem to be at least DEFAULTBOLDSTEMWIDTH wide. */
if (idealwidth < DEFAULTBOLDSTEMWIDTH)
idealwidth = DEFAULTBOLDSTEMWIDTH;
/* Now compute the number of character space units necessary */
widthdiff = idealwidth * onepixel - stemwidth;
/*********************************************************************/
/* ALIGNMENT ZONES AND OVERSHOOT SUPPRESSION - HORIZONTAL STEMS ONLY */
/*********************************************************************/
stemshift = 0.0;
if (!stems[stemno].vertical) {
/* Get bottom and top boundaries of the stem. */
stembottom = stemstart;
stemtop = stemstart + stemwidth;
/* Find out if this stem intersects an alignment zone (the BlueFuzz */
/* entry in the Private dictionary specifies the number of character */
/* units to extend (in both directions) the effect of an alignment */
/* zone on a horizontal stem. The default value of BlueFuzz is 1. */
for (i = 0; i < numalignmentzones; ++i) {
if (alignmentzones[i].topzone) {
if (stemtop >= alignmentzones[i].bottomy &&
stemtop <= alignmentzones[i].topy + blues->BlueFuzz) {
break; /* We found a top-zone */
}
} else {
if (stembottom <= alignmentzones[i].topy &&
stembottom >= alignmentzones[i].bottomy - blues->BlueFuzz) {
break; /* We found a bottom-zone */
}
}
}
if (i < numalignmentzones) { /* We found an intersecting zone (number i). */
suppressovershoot = FALSE;
enforceovershoot = FALSE;
/* When 1 character space unit is rendered smaller than BlueScale
device units (pixels), we must SUPPRESS overshoots. Otherwise,
if the top (or bottom) of this stem is more than BlueShift character
space units away from the flat position, we must ENFORCE overshoot. */
if (unitpixels < blues->BlueScale)
suppressovershoot = TRUE;
else
if (alignmentzones[i].topzone)
if (stemtop >= alignmentzones[i].bottomy + blues->BlueShift)
enforceovershoot = TRUE;
else
if (stembottom <= alignmentzones[i].topy - blues->BlueShift)
enforceovershoot = TRUE;
/*************************************************/
/* ALIGN THE FLAT POSITION OF THE ALIGNMENT ZONE */
/*************************************************/
/* Compute the position of the alignment zone's flat position in
device space and the amount of shift needed to align it on a
pixel boundary. Move all stems this amount. */
if (alignmentzones[i].topzone)
flatposition = alignmentzones[i].bottomy;
else
flatposition = alignmentzones[i].topy;
/* Find the flat position in pixels */
flatpospixels = flatposition * unitpixels;
/* Find the stem shift necessary to align the flat
position on a pixel boundary, and use this shift for all stems */
stemshift = (ROUND(flatpospixels) - flatpospixels) * onepixel;
/************************************************/
/* HANDLE OVERSHOOT ENFORCEMENT AND SUPPRESSION */
/************************************************/
/* Compute overshoot amount (non-negative) */
if (alignmentzones[i].topzone)
overshoot = stemtop - flatposition;
else
overshoot = flatposition - stembottom;
if (overshoot > 0.0) {
/* ENFORCE overshoot by shifting the entire stem (if necessary) so that
it falls at least one pixel beyond the flat position. */
if (enforceovershoot)
if (overshoot < onepixel)
if (alignmentzones[i].topzone)
stemshift += onepixel - overshoot;
else
stemshift -= onepixel - overshoot;
/* SUPPRESS overshoot by aligning the stem to the alignment zone's
flat position. */
if (suppressovershoot)
if (alignmentzones[i].topzone)
stemshift -= overshoot;
else
stemshift += overshoot;
}
/************************************************************/
/* COMPUTE HINT VALUES FOR EACH SIDE OF THE HORIZONTAL STEM */
/************************************************************/
/* If the stem was aligned by a topzone, we expand or contract the stem
only at the bottom - since the stem top was aligned by the zone.
If the stem was aligned by a bottomzone, we expand or contract the stem
only at the top - since the stem bottom was aligned by the zone. */
if (alignmentzones[i].topzone) {
lbhintvalue = stemshift - widthdiff; /* bottom */
rthintvalue = stemshift; /* top */
} else {
lbhintvalue = stemshift; /* bottom */
rthintvalue = stemshift + widthdiff; /* top */
}
stems[stemno].lbhint = (struct segment *)Permanent(Loc(CharSpace, 0.0, lbhintvalue));
stems[stemno].lbrevhint = (struct segment *)Permanent(Loc(CharSpace, 0.0, -lbhintvalue));
stems[stemno].rthint = (struct segment *)Permanent(Loc(CharSpace, 0.0, rthintvalue));
stems[stemno].rtrevhint = (struct segment *)Permanent(Loc(CharSpace, 0.0, -rthintvalue));
return;
} /* endif (i < numalignmentzones) */
/* We didn't find any alignment zones intersecting this stem, so
proceed with normal stem alignment below. */
} /* endif (!stems[stemno].vertical) */
/* Align stem with pixel boundaries on device */
stemstart = stemstart - widthdiff / 2;
stemshift = ROUND(stemstart * unitpixels) * onepixel - stemstart;
/* Adjust the boundaries of the stem */
lbhintvalue = stemshift - widthdiff / 2; /* left or bottom */
rthintvalue = stemshift + widthdiff / 2; /* right or top */
if (stems[stemno].vertical) {
stems[stemno].lbhint = (struct segment *)Permanent(Loc(CharSpace, lbhintvalue, 0.0));
stems[stemno].lbrevhint = (struct segment *)Permanent(Loc(CharSpace, -lbhintvalue, 0.0));
stems[stemno].rthint = (struct segment *)Permanent(Loc(CharSpace, rthintvalue, 0.0));
stems[stemno].rtrevhint = (struct segment *)Permanent(Loc(CharSpace, -rthintvalue, 0.0));
} else {
stems[stemno].lbhint = (struct segment *)Permanent(Loc(CharSpace, 0.0, lbhintvalue));
stems[stemno].lbrevhint = (struct segment *)Permanent(Loc(CharSpace, 0.0, -lbhintvalue));
stems[stemno].rthint = (struct segment *)Permanent(Loc(CharSpace, 0.0, rthintvalue));
stems[stemno].rtrevhint = (struct segment *)Permanent(Loc(CharSpace, 0.0, -rthintvalue));
}
}
#define LEFT 1
#define RIGHT 2
#define BOTTOM 3
#define TOP 4
/*********************************************************************/
/* Adjust a point using the given stem hint. Use the left/bottom */
/* hint value or the right/top hint value depending on where the */
/* point lies in the stem. */
/*********************************************************************/
static struct segment *Applyhint(p, stemnumber, half)
struct segment *p;
int stemnumber, half;
{
if (half == LEFT || half == BOTTOM)
return Join(p, stems[stemnumber].lbhint); /* left or bottom hint */
else
return Join(p, stems[stemnumber].rthint); /* right or top hint */
}
/*********************************************************************/
/* Adjust a point using the given reverse hint. Use the left/bottom */
/* hint value or the right/top hint value depending on where the */
/* point lies in the stem. */
/*********************************************************************/
static struct segment *Applyrevhint(p, stemnumber, half)
struct segment *p;
int stemnumber, half;
{
if (half == LEFT || half == BOTTOM)
return Join(p, stems[stemnumber].lbrevhint); /* left or bottom hint */
else
return Join(p, stems[stemnumber].rtrevhint); /* right or top hint */
}
/***********************************************************************/
/* Find the vertical and horizontal stems that the current point */
/* (x, y) may be involved in. At most one horizontal and one vertical */
/* stem can apply to a single point, since there are no overlaps */
/* allowed. */
/* The actual hintvalue is returned as a location. */
/* Hints are ignored inside a DotSection. */
/***********************************************************************/
static struct segment *FindStems(x, y, dx, dy)
DOUBLE x, y, dx, dy;
{
int i;
int newvert, newhor;
struct segment *p;
int newhorhalf, newverthalf;
if (InDotSection) return(NULL);
newvert = newhor = -1;
newhorhalf = newverthalf = -1;
for (i = currstartstem; i < numstems; i++) {
if (stems[i].vertical) { /* VSTEM hint */
if ((x >= stems[i].x - EPS) &&
(x <= stems[i].x+stems[i].dx + EPS)) {
newvert = i;
if (dy != 0.0) {
if (dy < 0) newverthalf = LEFT;
else newverthalf = RIGHT;
} else {
if (x < stems[i].x+stems[i].dx / 2) newverthalf = LEFT;
else newverthalf = RIGHT;
}
}
} else { /* HSTEM hint */
if ((y >= stems[i].y - EPS) &&
(y <= stems[i].y+stems[i].dy + EPS)) {
newhor = i;
if (dx != 0.0) {
if (dx < 0) newhorhalf = TOP;
else newhorhalf = BOTTOM;
} else {
if (y < stems[i].y+stems[i].dy / 2) newhorhalf = BOTTOM;
else newhorhalf = TOP;
}
}
}
}
p = NULL;
if (newvert == -1 && oldvert == -1) ; /* Outside of any hints */
else if (newvert == oldvert &&
newverthalf == oldverthalf); /* No hint change */
else if (oldvert == -1) { /* New vertical hint in effect */
p = Applyhint(p, newvert, newverthalf);
} else if (newvert == -1) { /* Old vertical hint no longer in effect */
p = Applyrevhint(p, oldvert, oldverthalf);
} else { /* New vertical hint in effect, old hint no longer in effect */
p = Applyrevhint(p, oldvert, oldverthalf);
p = Applyhint(p, newvert, newverthalf);
}
if (newhor == -1 && oldhor == -1) ; /* Outside of any hints */
else if (newhor == oldhor &&
newhorhalf == oldhorhalf) ; /* No hint change */
else if (oldhor == -1) { /* New horizontal hint in effect */
p = Applyhint(p, newhor, newhorhalf);
} else if (newhor == -1) { /* Old horizontal hint no longer in effect */
p = Applyrevhint(p, oldhor, oldhorhalf);
}
else { /* New horizontal hint in effect, old hint no longer in effect */
p = Applyrevhint(p, oldhor, oldhorhalf);
p = Applyhint(p, newhor, newhorhalf);
}
oldvert = newvert; oldverthalf = newverthalf;
oldhor = newhor; oldhorhalf = newhorhalf;
return p;
}
/******************************************************/
/* Subroutines and statics for the Type1Char routines */
/******************************************************/
static int strindex; /* index into PostScript string being interpreted */
static DOUBLE currx, curry; /* accumulated x and y values for hints */
struct callstackentry {
psobj *currstrP; /* current CharStringP */
int currindex; /* current strindex */
unsigned short currkey; /* current decryption key */
};
static DOUBLE Stack[MAXSTACK];
static int Top;
static struct callstackentry CallStack[MAXCALLSTACK];
static int CallTop;
static DOUBLE PSFakeStack[MAXPSFAKESTACK];
static int PSFakeTop;
static void ClearStack()
{
Top = -1;
}
static void Push(Num)
DOUBLE Num;
{
if (++Top < MAXSTACK) Stack[Top] = Num;
else Error0("Push: Stack full\n");
}
static void ClearCallStack()
{
CallTop = -1;
}
static void PushCall(psobj *CurrStrP, int CurrIndex, unsigned short CurrKey)
{
if (++CallTop < MAXCALLSTACK) {
CallStack[CallTop].currstrP = CurrStrP; /* save CharString pointer */
CallStack[CallTop].currindex = CurrIndex; /* save CharString index */
CallStack[CallTop].currkey = CurrKey; /* save decryption key */
}
else Error0("PushCall: Stack full\n");
}
static void PopCall(CurrStrPP, CurrIndexP, CurrKeyP)
psobj **CurrStrPP;
int *CurrIndexP;
unsigned short *CurrKeyP;
{
if (CallTop >= 0) {
*CurrStrPP = CallStack[CallTop].currstrP; /* restore CharString pointer */
*CurrIndexP = CallStack[CallTop].currindex; /* restore CharString index */
*CurrKeyP = CallStack[CallTop--].currkey; /* restore decryption key */
}
else Error0("PopCall: Stack empty\n");
}
static void ClearPSFakeStack()
{
PSFakeTop = -1;
}
/* PSFakePush: Pushes a number onto the fake PostScript stack */
static void PSFakePush(Num)
DOUBLE Num;
{
if (++PSFakeTop < MAXPSFAKESTACK) PSFakeStack[PSFakeTop] = Num;
else Error0("PSFakePush: Stack full\n");
}
/* PSFakePop: Removes a number from the top of the fake PostScript stack */
static DOUBLE PSFakePop ()
{
if (PSFakeTop >= 0) return(PSFakeStack[PSFakeTop--]);
else Error0("PSFakePop : Stack empty\n");
/*NOTREACHED*/
}
/***********************************************************************/
/* Center a stem on the pixel grid -- used by HStem3 and VStem3 */
/***********************************************************************/
static struct segment *CenterStem(edge1, edge2)
DOUBLE edge1;
DOUBLE edge2;
{
int idealwidth, verticalondevice;
DOUBLE leftx, lefty, rightx, righty, center, width;
DOUBLE widthx, widthy;
DOUBLE shift, shiftx, shifty;
DOUBLE Xpixels, Ypixels;
struct segment *p;
p = Loc(CharSpace, edge1, 0.0);
QueryLoc(p, IDENTITY, &leftx, &lefty);
p = Join(p, Loc(CharSpace, edge2, 0.0));
QueryLoc(p, IDENTITY, &rightx, &righty);
Destroy(p);
widthx = FABS(rightx - leftx);
widthy = FABS(righty - lefty);
if (widthy <= EPS) { /* verticalondevice hint */
verticalondevice = TRUE;
center = (rightx + leftx) / 2.0;
width = widthx;
}
else if (widthx <= EPS) { /* horizontal hint */
verticalondevice = FALSE;
center = (righty + lefty) / 2.0;
width = widthy;
}
else { /* neither horizontal nor verticalondevice and not oblique */
return (NULL);
}
idealwidth = ROUND(width);
if (idealwidth == 0) idealwidth = 1;
if (ODD(idealwidth)) { /* is ideal width odd? */
/* center stem over pixel */
shift = FLOOR(center) + 0.5 - center;
}
else {
/* align stem on pixel boundary */
shift = ROUND(center) - center;
}
if (verticalondevice) {
shiftx = shift;
shifty = 0.0;
} else {
shifty = shift;
shiftx = 0.0;
}
p = Loc(IDENTITY, shiftx, shifty);
QueryLoc(p, CharSpace, &Xpixels, &Ypixels);
wsoffsetX = Xpixels; wsoffsetY = Ypixels;
currx += wsoffsetX; curry += wsoffsetY;
return (p);
}
/*-----------------------------------------------------------------------
Decrypt - From Adobe Type 1 book page 63, with some modifications
-----------------------------------------------------------------------*/
#define KEY 4330 /* Initial key (seed) for CharStrings decryption */
#define C1 52845 /* Multiplier for pseudo-random number generator */
#define C2 22719 /* Constant for pseudo-random number generator */
static unsigned short r; /* Pseudo-random sequence of keys */
static unsigned char Decrypt(unsigned char cipher)
{
unsigned char plain;
plain = cipher ^ (r >> 8);
r = (cipher + r) * C1 + C2;
return plain;
}
/* Get the next byte from the codestring being interpreted */
static int DoRead(CodeP)
int *CodeP;
{
if (strindex >= CharStringP->len) return(FALSE); /* end of string */
*CodeP = Decrypt((unsigned char) CharStringP->data.stringP[strindex++]);
return(TRUE);
}
/* Strip blues->lenIV bytes from CharString and update encryption key */
/* (the lenIV entry in the Private dictionary specifies the number of */
/* random bytes at the beginning of each CharString; default is 4) */
static void StartDecrypt()
{
int Code;
r = KEY; /* Initial key (seed) for CharStrings decryption */
for (strindex = 0; strindex < blues->lenIV;)
if (!DoRead(&Code)) /* Read a byte and update decryption key */
Error0("StartDecrypt: Premature end of CharString\n");
}
static void Decode(Code)
int Code;
{
int Code1, Code2, Code3, Code4;
if (Code <= 31) /* Code is [0,31] */
DoCommand(Code);
else if (Code <= 246) /* Code is [32,246] */
Push((DOUBLE)(Code - 139));
else if (Code <= 250) { /* Code is [247,250] */
if (!DoRead(&Code2)) goto ended;
Push((DOUBLE)(((Code - 247) << 8) + Code2 + 108));
}
else if (Code <= 254) { /* Code is [251,254] */
if (!DoRead(&Code2)) goto ended;
Push((DOUBLE)( -((Code - 251) << 8) - Code2 - 108));
}
else { /* Code is 255 */
if (!DoRead(&Code1)) goto ended;
if (!DoRead(&Code2)) goto ended;
if (!DoRead(&Code3)) goto ended;
if (!DoRead(&Code4)) goto ended;
Push((DOUBLE)((((((Code1<<8) + Code2)<<8) + Code3)<<8) + Code4));
}
return;
ended: Error0("Decode: Premature end of Type 1 CharString");
}
/* Interpret a command code */
static void DoCommand(Code)
int Code;
{
switch(Code) {
case HSTEM: /* |- y dy HSTEM |- */
/* Vertical range of a horizontal stem zone */
if (Top < 1) Error0("DoCommand: Stack low\n");
HStem(Stack[0], Stack[1]);
ClearStack();
break;
case VSTEM: /* |- x dx VSTEM |- */
/* Horizontal range of a vertical stem zone */
if (Top < 1) Error0("DoCommand: Stack low\n");
VStem(Stack[0], Stack[1]);
ClearStack();
break;
case VMOVETO: /* |- dy VMOVETO |- */
/* Vertical MOVETO, equivalent to 0 dy RMOVETO */
if (Top < 0) Error0("DoCommand: Stack low\n");
RMoveTo(0.0, Stack[0]);
ClearStack();
break;
case RLINETO: /* |- dx dy RLINETO |- */
/* Like RLINETO in PostScript */
if (Top < 1) Error0("DoCommand: Stack low\n");
RLineTo(Stack[0], Stack[1]);
ClearStack();
break;
case HLINETO: /* |- dx HLINETO |- */
/* Horizontal LINETO, equivalent to dx 0 RLINETO */
if (Top < 0) Error0("DoCommand: Stack low\n");
RLineTo(Stack[0], 0.0);
ClearStack();
break;
case VLINETO: /* |- dy VLINETO |- */
/* Vertical LINETO, equivalent to 0 dy RLINETO */
if (Top < 0) Error0("DoCommand: Stack low\n");
RLineTo(0.0, Stack[0]);
ClearStack();
break;
case RRCURVETO:
/* |- dx1 dy1 dx2 dy2 dx3 dy3 RRCURVETO |- */
/* Relative RCURVETO, equivalent to dx1 dy1 */
/* (dx1+dx2) (dy1+dy2) (dx1+dx2+dx3) */
/* (dy1+dy2+dy3) RCURVETO in PostScript */
if (Top < 5) Error0("DoCommand: Stack low\n");
RRCurveTo(Stack[0], Stack[1], Stack[2], Stack[3],
Stack[4], Stack[5]);
ClearStack();
break;
case CLOSEPATH: /* - CLOSEPATH |- */
/* Closes a subpath without repositioning the */
/* current point */
DoClosePath();
ClearStack();
break;
case CALLSUBR: /* subr# CALLSUBR - */
/* Calls a CharString subroutine with index */
/* subr# from the Subrs array */
if (Top < 0) Error0("DoCommand: Stack low\n");
CallSubr((int)Stack[Top--]);
break;
case RETURN: /* - RETURN - */
/* Returns from a Subrs array CharString */
/* subroutine called with CALLSUBR */
Return();
break;
case ESCAPE: /* ESCAPE to two-byte command code */
if (!DoRead(&Code)) Error0("DoCommand: ESCAPE is last byte\n");
Escape(Code);
break;
case HSBW: /* |- sbx wx HSBW |- */
/* Set the left sidebearing point to (sbx,0), */
/* set the character width vector to (wx,0). */
/* Equivalent to sbx 0 wx 0 SBW. Space */
/* character should have sbx = 0 */
if (Top < 1) Error0("DoCommand: Stack low\n");
Sbw(Stack[0], 0.0, Stack[1], 0.0);
ClearStack();
break;
case ENDCHAR: /* - ENDCHAR |- */
/* Finishes a CharString outline */
EndChar();
ClearStack();
break;
case RMOVETO: /* |- dx dy RMOVETO |- */
/* Behaves like RMOVETO in PostScript */
if (Top < 1) Error0("DoCommand: Stack low\n");
RMoveTo(Stack[0], Stack[1]);
ClearStack();
break;
case HMOVETO: /* |- dx HMOVETO |- */
/* Horizontal MOVETO. Equivalent to dx 0 RMOVETO */
if (Top < 0) Error0("DoCommand: Stack low\n");
RMoveTo(Stack[0], 0.0);
ClearStack();
break;
case VHCURVETO: /* |- dy1 dx2 dy2 dx3 VHCURVETO |- */
/* Vertical-Horizontal CURVETO, equivalent to */
/* 0 dy1 dx2 dy2 dx3 0 RRCURVETO */
if (Top < 3) Error0("DoCommand: Stack low\n");
RRCurveTo(0.0, Stack[0], Stack[1], Stack[2],
Stack[3], 0.0);
ClearStack();
break;
case HVCURVETO: /* |- dx1 dx2 dy2 dy3 HVCURVETO |- */
/* Horizontal-Vertical CURVETO, equivalent to */
/* dx1 0 dx2 dy2 0 dy3 RRCURVETO */
if (Top < 3) Error0("DoCommand: Stack low\n");
RRCurveTo(Stack[0], 0.0, Stack[1], Stack[2], 0.0, Stack[3]);
ClearStack();
break;
default: /* Unassigned command code */
ClearStack();
Error1("DoCommand: Unassigned code %d\n", Code);
}
}
static void Escape(Code)
int Code;
{
int i, Num;
struct segment *p;
switch(Code) {
case DOTSECTION: /* - DOTSECTION |- */
/* Brackets an outline section for the dots in */
/* letters such as "i", "j", and "!". */
DotSection();
ClearStack();
break;
case VSTEM3: /* |- x0 dx0 x1 dx1 x2 dx2 VSTEM3 |- */
/* Declares the horizontal ranges of three */
/* vertical stem zones between x0 and x0+dx0, */
/* x1 and x1+dx1, and x2 and x2+dx2. */
if (Top < 5) Error0("DoCommand: Stack low\n");
if (!wsset && ProcessHints) {
/* Shift the whole character so that the middle stem is centered. */
p = CenterStem(Stack[2] + sidebearingX, Stack[3]);
path = Join(path, p);
wsset = 1;
}
VStem(Stack[0], Stack[1]);
VStem(Stack[2], Stack[3]);
VStem(Stack[4], Stack[5]);
ClearStack();
break;
case HSTEM3: /* |- y0 dy0 y1 dy1 y2 dy2 HSTEM3 |- */
/* Declares the vertical ranges of three hori- */
/* zontal stem zones between y0 and y0+dy0, */
/* y1 and y1+dy1, and y2 and y2+dy2. */
if (Top < 5) Error0("DoCommand: Stack low\n");
HStem(Stack[0], Stack[1]);
HStem(Stack[2], Stack[3]);
HStem(Stack[4], Stack[5]);
ClearStack();
break;
case SEAC: /* |- asb adx ady bchar achar SEAC |- */
/* Standard Encoding Accented Character. */
if (Top < 4) Error0("DoCommand: Stack low\n");
Seac(Stack[0], Stack[1], Stack[2],
(unsigned char) Stack[3],
(unsigned char) Stack[4]);
ClearStack();
break;
case SBW: /* |- sbx sby wx wy SBW |- */
/* Set the left sidebearing point to (sbx,sby), */
/* set the character width vector to (wx,wy). */
if (Top < 3) Error0("DoCommand: Stack low\n");
Sbw(Stack[0], Stack[1], Stack[2], Stack[3]);
ClearStack();
break;
case DIV: /* num1 num2 DIV quotient */
/* Behaves like DIV in the PostScript language */
if (Top < 1) Error0("DoCommand: Stack low\n");
Stack[Top-1] = Div(Stack[Top-1], Stack[Top]);
Top--;
break;
case CALLOTHERSUBR:
/* arg1 ... argn n othersubr# CALLOTHERSUBR - */
/* Make calls on the PostScript interpreter */
if (Top < 1) Error0("DoCommand: Stack low\n");
Num = Stack[Top-1];
if (Top < Num+1) Error0("DoCommand: Stack low\n");
for (i = 0; i < Num; i++) PSFakePush(Stack[Top - i - 2]);
Top -= Num + 2;
CallOtherSubr((int)Stack[Top + Num + 2]);
break;
case POP: /* - POP number */
/* Removes a number from the top of the */
/* PostScript interpreter stack and pushes it */
/* onto the Type 1 BuildChar operand stack */
Push(PSFakePop());
break;
case SETCURRENTPOINT: /* |- x y SETCURRENTPOINT |- */
/* Sets the current point to (x,y) in absolute */
/* character space coordinates without per- */
/* forming a CharString MOVETO command */
if (Top < 1) Error0("DoCommand: Stack low\n");
SetCurrentPoint(Stack[0], Stack[1]);
ClearStack();
break;
default: /* Unassigned escape code command */
ClearStack();
Error1("Escape: Unassigned code %d\n", Code);
}
}
/* |- y dy HSTEM |- */
/* Declares the vertical range of a horizontal stem zone */
/* between coordinates y and y + dy */
/* y is relative to the left sidebearing point */
static void HStem(y, dy)
DOUBLE y, dy;
{
IfTrace2((FontDebug), "Hstem %f %f\n", &y, &dy);
if (ProcessHints) {
if (numstems >= MAXSTEMS) Error0("HStem: Too many hints\n");
if (dy < 0.0) {y += dy; dy = -dy;}
stems[numstems].vertical = FALSE;
stems[numstems].x = 0.0;
stems[numstems].y = sidebearingY + y + wsoffsetY;
stems[numstems].dx = 0.0;
stems[numstems].dy = dy;
ComputeStem(numstems);
numstems++;
}
}
/* |- x dx VSTEM |- */
/* Declares the horizontal range of a vertical stem zone */
/* between coordinates x and x + dx */
/* x is relative to the left sidebearing point */
static void VStem(x, dx)
DOUBLE x, dx;
{
IfTrace2((FontDebug), "Vstem %f %f\n", &x, &dx);
if (ProcessHints) {
if (numstems >= MAXSTEMS) Error0("VStem: Too many hints\n");
if (dx < 0.0) {x += dx; dx = -dx;}
stems[numstems].vertical = TRUE;
stems[numstems].x = sidebearingX + x + wsoffsetX;
stems[numstems].y = 0.0;
stems[numstems].dx = dx;
stems[numstems].dy = 0.0;
ComputeStem(numstems);
numstems++;
}
}
/* |- dx dy RLINETO |- */
/* Behaves like RLINETO in PostScript */
static void RLineTo(dx, dy)
DOUBLE dx, dy;
{
struct segment *B;
IfTrace2((FontDebug), "RLineTo %f %f\n", &dx, &dy);
B = Loc(CharSpace, dx, dy);
if (ProcessHints) {
currx += dx;
curry += dy;
/* B = Join(B, FindStems(currx, curry)); */
B = Join(B, FindStems(currx, curry, dx, dy));
}
path = Join(path, Line(B));
}
/* |- dx1 dy1 dx2 dy2 dx3 dy3 RRCURVETO |- */
/* Relative RCURVETO, equivalent to dx1 dy1 */
/* (dx1+dx2) (dy1+dy2) (dx1+dx2+dx3) */
/* (dy1+dy2+dy3) RCURVETO in PostScript */
static void RRCurveTo(dx1, dy1, dx2, dy2, dx3, dy3)
DOUBLE dx1, dy1, dx2, dy2, dx3, dy3;
{
struct segment *B, *C, *D;
IfTrace4((FontDebug), "RRCurveTo %f %f %f %f ", &dx1, &dy1, &dx2, &dy2);
IfTrace2((FontDebug), "%f %f\n", &dx3, &dy3);
B = Loc(CharSpace, dx1, dy1);
C = Loc(CharSpace, dx2, dy2);
D = Loc(CharSpace, dx3, dy3);
if (ProcessHints) {
/* For a Bezier curve, we apply the full hint value to
the Bezier C point (and thereby D point). */
currx += dx1 + dx2 + dx3;
curry += dy1 + dy2 + dy3;
/* C = Join(C, FindStems(currx, curry)); */
C = Join(C, FindStems(currx, curry, dx3, dy3));
}
/* Since XIMAGER is not completely relative, */
/* we need to add up the delta values */
C = Join(C, Dup(B));
D = Join(D, Dup(C));
path = Join(path, Bezier(B, C, D));
}
/* - CLOSEPATH |- */
/* Closes a subpath WITHOUT repositioning the */
/* current point */
static void DoClosePath()
{
struct segment *CurrentPoint;
IfTrace0((FontDebug), "DoClosePath\n");
CurrentPoint = Phantom(path);
path = ClosePath(path);
path = Join(Snap(path), CurrentPoint);
}
/* subr# CALLSUBR - */
/* Calls a CharString subroutine with index */
/* subr# from the Subrs array */
static void CallSubr(subrno)
int subrno;
{
IfTrace1((FontDebug), "CallSubr %d\n", subrno);
if ((subrno < 0) || (subrno >= SubrsP->len))
Error0("CallSubr: subrno out of range\n");
PushCall(CharStringP, strindex, r);
CharStringP = &SubrsP->data.arrayP[subrno];
StartDecrypt();
}
/* - RETURN - */
/* Returns from a Subrs array CharString */
/* subroutine called with CALLSUBR */
static void Return()
{
IfTrace0((FontDebug), "Return\n");
PopCall(&CharStringP, &strindex, &r);
}
/* - ENDCHAR |- */
/* Finishes a CharString outline */
/* Executes SETCHACHEDEVICE using a bounding box */
/* it computes directly from the character outline */
/* and using the width information acquired from a previous */
/* HSBW or SBW. It then calls a special version of FILL */
/* or STROKE depending on the value of PaintType in the */
/* font dictionary */
static void EndChar()
{
IfTrace0((FontDebug), "EndChar\n");
/* There is no need to compute and set bounding box for
the cache, since XIMAGER does that on the fly. */
/* Perform a Closepath just in case the command was left out */
path = ClosePath(path);
/* Set character width */
path = Join(Snap(path), Loc(CharSpace, escapementX, escapementY));
}
/* |- dx dy RMOVETO |- */
/* Behaves like RMOVETO in PostScript */
static void RMoveTo(dx,dy)
DOUBLE dx,dy;
{
struct segment *B;
IfTrace2((FontDebug), "RMoveTo %f %f\n", &dx, &dy);
B = Loc(CharSpace, dx, dy);
if (ProcessHints) {
currx += dx;
curry += dy;
/* B = Join(B, FindStems(currx, curry)); */
B = Join(B, FindStems(currx, curry, 0.0, 0.0));
}
path = Join(path, B);
}
/* - DOTSECTION |- */
/* Brackets an outline section for the dots in */
/* letters such as "i", "j", and "!". */
static void DotSection()
{
IfTrace0((FontDebug), "DotSection\n");
InDotSection = !InDotSection;
}
/* |- asb adx ady bchar achar SEAC |- */
/* Standard Encoding Accented Character. */
static void Seac(DOUBLE asb, DOUBLE adx, DOUBLE ady,
unsigned char bchar, unsigned char achar)
{
int Code;
struct segment *mypath;
IfTrace4((FontDebug), "SEAC %f %f %f %d ", &asb, &adx, &ady, bchar);
IfTrace1((FontDebug), "%d\n", achar);
/* Move adx - asb, ady over and up from base char's sbpoint. */
/* (We use adx - asb to counteract the accents sb shift.) */
/* The variables accentoffsetX/Y modify sidebearingX/Y in Sbw(). */
/* Note that these incorporate the base character's sidebearing shift by */
/* using the current sidebearingX, Y values. */
accentoffsetX = sidebearingX + adx - asb;
accentoffsetY = sidebearingY + ady;
/* Set path = NULL to avoid complaints from Sbw(). */
path = NULL;
/* Go find the CharString for the accent's code via an upcall */
CharStringP = GetType1CharString(Environment, achar);
if (CharStringP == NULL) {
Error1("Invalid accent ('%03o) in SEAC\n", achar);
return;
}
StartDecrypt();
ClearStack();
ClearPSFakeStack();
ClearCallStack();
for (;;) {
if (!DoRead(&Code)) break;
Decode(Code);
if (errflag) return;
}
/* Copy snapped path to mypath and set path to NULL as above. */
mypath = Snap(path);
path = NULL;
/* We must reset these to null now. */
accentoffsetX = accentoffsetY = 0;
/* go find the CharString for the base char's code via an upcall */
CharStringP = GetType1CharString(Environment, bchar);
StartDecrypt();
ClearStack();
ClearPSFakeStack();
ClearCallStack();
FinitStems();
InitStems();
for (;;) {
if (!DoRead(&Code)) break;
Decode(Code);
if (errflag) return;
}
path = Join(mypath, path);
}
/* |- sbx sby wx wy SBW |- */
/* Set the left sidebearing point to (sbx,sby), */
/* set the character width vector to (wx,wy). */
static void Sbw(sbx, sby, wx, wy)
DOUBLE sbx, sby, wx, wy;
{
IfTrace4((FontDebug), "SBW %f %f %f %f\n", &sbx, &sby, &wx, &wy);
escapementX = wx; /* Character width vector */
escapementY = wy;
/* Sidebearing values are sbx, sby args, plus accent offset from Seac(). */
sidebearingX = sbx + accentoffsetX;
sidebearingY = sby + accentoffsetY;
path = Join(path, Loc(CharSpace, sidebearingX, sidebearingY));
if (ProcessHints) {currx = sidebearingX; curry = sidebearingY;}
}
/* num1 num2 DIV quotient */
/* Behaves like DIV in the PostScript language */
static DOUBLE Div(num1, num2)
DOUBLE num1, num2;
{
IfTrace2((FontDebug), "Div %f %f\n", &num1, &num2);
return(num1 / num2);
}
/*
The following four subroutines (FlxProc, FlxProc1, FlxProc2, and
HintReplace) are C versions of the OtherSubrs Programs, which were
were published in the Adobe Type 1 Font Format book.
The Flex outline fragment is described by
c1: (x0, y0) = c3: (x0, yshrink(y0)) or (xshrink(x0), y0)
" (x1, y1) = " (x1, yshrink(y1)) or (xshrink(x1), y1)
" (x2, y2) - reference point
c2: (x0, y0) = c4: (x0, yshrink(y0)) or (xshrink(x0), y0)
" (x1, y1) = " (x1, yshrink(y1)) or (xshrink(x1), y1)
" (x2, y2) = " (x2, y2), rightmost endpoint
c3: (x0, y0) - control point, 1st Bezier curve
" (x1, y1) - control point, -"-
" (x2, y2) - end point, -"-
c4: (x0, y0) - control point, 2nd Bezier curve
" (x1, y1) - control point, -"-
" (x2, y2) - end point, -"-
ep: (epY, epX) - final endpoint (should be same as c4: (x2, y2))
idmin - minimum Flex height (1/100 pixel) at which to render curves
*/
#define dtransform(dxusr,dyusr,dxdev,dydev) { \
register struct segment *point = Loc(CharSpace, dxusr, dyusr); \
QueryLoc(point, IDENTITY, dxdev, dydev); \
Destroy(point); \
}
#define itransform(xdev,ydev,xusr,yusr) { \
register struct segment *point = Loc(IDENTITY, xdev, ydev); \
QueryLoc(point, CharSpace, xusr, yusr); \
Destroy(point); \
}
#define transform(xusr,yusr,xdev,ydev) dtransform(xusr,yusr,xdev,ydev)
#define PaintType (0)
#define lineto(x,y) { \
struct segment *CurrentPoint; \
DOUBLE CurrentX, CurrentY; \
CurrentPoint = Phantom(path); \
QueryLoc(CurrentPoint, CharSpace, &CurrentX, &CurrentY); \
Destroy(CurrentPoint); \
RLineTo(x - CurrentX, y - CurrentY); \
}
#define curveto(x0,y0,x1,y1,x2,y2) { \
struct segment *CurrentPoint; \
DOUBLE CurrentX, CurrentY; \
CurrentPoint = Phantom(path); \
QueryLoc(CurrentPoint, CharSpace, &CurrentX, &CurrentY); \
Destroy(CurrentPoint); \
RRCurveTo(x0 - CurrentX, y0 - CurrentY, x1 - x0, y1 - y0, x2 - x1, y2 - y1); \
}
#define xshrink(x) ((x - c4x2) * shrink +c4x2)
#define yshrink(y) ((y - c4y2) * shrink +c4y2)
#define PickCoords(flag) \
if (flag) { /* Pick "shrunk" coordinates */ \
x0 = c1x0; y0 = c1y0; \
x1 = c1x1; y1 = c1y1; \
x2 = c1x2; y2 = c1y2; \
x3 = c2x0; y3 = c2y0; \
x4 = c2x1; y4 = c2y1; \
x5 = c2x2; y5 = c2y2; \
} else { /* Pick original coordinates */ \
x0 = c3x0; y0 = c3y0; \
x1 = c3x1; y1 = c3y1; \
x2 = c3x2; y2 = c3y2; \
x3 = c4x0; y3 = c4y0; \
x4 = c4x1; y4 = c4y1; \
x5 = c4x2; y5 = c4y2; \
}
/* FlxProc() = OtherSubrs[0]; Main part of Flex */
/* Calling sequence: 'idmin epX epY 3 0 callothersubr' */
/* Computes Flex values, and renders the Flex path, */
/* and returns (leaves) ending coordinates on stack */
static void FlxProc(c1x2, c1y2, c3x0, c3y0, c3x1, c3y1, c3x2, c3y2,
c4x0, c4y0, c4x1, c4y1, c4x2, c4y2, epY, epX, idmin)
DOUBLE c1x2, c1y2;
DOUBLE c3x0, c3y0, c3x1, c3y1, c3x2, c3y2;
DOUBLE c4x0, c4y0, c4x1, c4y1, c4x2, c4y2;
DOUBLE epX, epY;
int idmin;
{
DOUBLE dmin;
DOUBLE c1x0, c1y0, c1x1, c1y1;
DOUBLE c2x0, c2y0, c2x1, c2y1, c2x2, c2y2;
char yflag;
DOUBLE x0, y0, x1, y1, x2, y2, x3, y3, x4, y4, x5, y5;
DOUBLE cxx, cyx, cxy, cyy; /* Transformation matrix */
int flipXY;
DOUBLE x, y;
DOUBLE erosion = 1; /* Device parameter */
/* Erosion may have different value specified in 'internaldict' */
DOUBLE shrink;
DOUBLE dX, dY;
char erode;
DOUBLE eShift;
DOUBLE cx, cy;
DOUBLE ex, ey;
Destroy(path);
path = FlxOldPath; /* Restore previous path (stored in FlxProc1) */
if (ProcessHints) {
dmin = ABS(idmin) / 100.0; /* Minimum Flex height in pixels */
c2x2 = c4x2; c2y2 = c4y2; /* Point c2 = c4 */
yflag = FABS(c1y2 - c3y2) > FABS(c1x2 - c3x2); /* Flex horizontal? */
QuerySpace(CharSpace, &cxx, &cyx, &cxy, &cyy); /* Transformation matrix */
if (FABS(cxx) < 0.00001 || FABS(cyy) < 0.00001)
flipXY = -1; /* Char on side */
else if (FABS(cyx) < 0.00001 || FABS(cxy) < 0.00001)
flipXY = 1; /* Char upright */
else
flipXY = 0; /* Char at angle */
if (yflag) { /* Flex horizontal */
if (flipXY == 0 || c3y2 == c4y2) { /* Char at angle or Flex height = 0 */
PickCoords(FALSE); /* Pick original control points */
} else {
shrink = FABS((c1y2 - c4y2) / (c3y2 - c4y2)); /* Slope */
c1x0 = c3x0; c1y0 = yshrink(c3y0);
c1x1 = c3x1; c1y1 = yshrink(c3y1);
c2x0 = c4x0; c2y0 = yshrink(c4y0);
c2x1 = c4x1; c2y1 = yshrink(c4y1);
dtransform(0.0, ROUND(c3y2-c1y2), &x, &y); /* Flex height in pixels */
dY = FABS((flipXY == 1) ? y : x);
PickCoords(dY < dmin); /* If Flex small, pick 'shrunk' control points */
if (FABS(y2 - c1y2) > 0.001) { /* Flex 'non-zero'? */
transform(c1x2, c1y2, &x, &y);
if (flipXY == 1) {
cx = x; cy = y;
} else {
cx = y; cy = x;
}
dtransform(0.0, ROUND(y2-c1y2), &x, &y);
dY = (flipXY == 1) ? y : x;
if (ROUND(dY) != 0)
dY = ROUND(dY);
else
dY = (dY < 0) ? -1 : 1;
erode = PaintType != 2 && erosion >= 0.5;
if (erode)
cy -= 0.5;
ey = cy + dY;
ey = CEIL(ey) - ey + FLOOR(ey);
if (erode)
ey += 0.5;
if (flipXY == 1) {
itransform(cx, ey, &x, &y);
} else {
itransform(ey, cx, &x, &y);
}
eShift = y - y2;
y1 += eShift;
y2 += eShift;
y3 += eShift;
}
}
} else { /* Flex vertical */
if (flipXY == 0 || c3x2 == c4x2) { /* Char at angle or Flex height = 0 */
PickCoords(FALSE); /* Pick original control points */
} else {
shrink = FABS((c1x2 - c4x2) / (c3x2 - c4x2)); /* Slope */
c1x0 = xshrink(c3x0); c1y0 = c3y0;
c1x1 = xshrink(c3x1); c1y1 = c3y1;
c2x0 = xshrink(c4x0); c2y0 = c4y0;
c2x1 = xshrink(c4x1); c2y1 = c4y1;
dtransform(ROUND(c3x2 - c1x2), 0.0, &x, &y); /* Flex height in pixels */
dX = FABS((flipXY == -1) ? y : x);
PickCoords(dX < dmin); /* If Flex small, pick 'shrunk' control points */
if (FABS(x2 - c1x2) > 0.001) {
transform(c1x2, c1y2, &x, &y);
if (flipXY == -1) {
cx = y; cy = x;
} else {
cx = x; cy = y;
}
dtransform(ROUND(x2-c1x2), 0.0, &x, &y);
dX = (flipXY == -1) ? y : x;
if (ROUND(dX) != 0)
dX = ROUND(dX);
else
dX = (dX < 0) ? -1 : 1;
erode = PaintType != 2 && erosion >= 0.5;
if (erode)
cx -= 0.5;
ex = cx + dX;
ex = CEIL(ex) - ex + FLOOR(ex);
if (erode)
ex += 0.5;
if (flipXY == -1) {
itransform(cy, ex, &x, &y);
} else {
itransform(ex, cy, &x, &y);
}
eShift = x - x2;
x1 += eShift;
x2 += eShift;
x3 += eShift;
}
}
}
if (x2 == x5 || y2 == y5) {
lineto(x5, y5);
} else {
curveto(x0, y0, x1, y1, x2, y2);
curveto(x3, y3, x4, y4, x5, y5);
}
} else { /* ProcessHints is off */
PickCoords(FALSE); /* Pick original control points */
curveto(x0, y0, x1, y1, x2, y2);
curveto(x3, y3, x4, y4, x5, y5);
}
PSFakePush(epY);
PSFakePush(epX);
}
/* FlxProc1() = OtherSubrs[1]; Part of Flex */
/* Calling sequence: '0 1 callothersubr' */
/* Saves and clears path, then restores currentpoint */
static void FlxProc1()
{
struct segment *CurrentPoint;
CurrentPoint = Phantom(path);
FlxOldPath = path;
path = CurrentPoint;
}
/* FlxProc2() = OtherSubrs[2]; Part of Flex */
/* Calling sequence: '0 2 callothersubr' */
/* Returns currentpoint on stack */
static void FlxProc2()
{
struct segment *CurrentPoint;
DOUBLE CurrentX, CurrentY;
CurrentPoint = Phantom(path);
QueryLoc(CurrentPoint, CharSpace, &CurrentX, &CurrentY);
Destroy(CurrentPoint);
/* Push CurrentPoint on fake PostScript stack */
PSFakePush(CurrentX);
PSFakePush(CurrentY);
}
/* HintReplace() = OtherSubrs[3]; Hint Replacement */
/* Calling sequence: 'subr# 1 3 callothersubr pop callsubr' */
/* Reinitializes stem hint structure */
static void HintReplace()
{
/* Effectively retire the current stems, but keep them around for */
/* revhint use in case we are in a stem when we replace hints. */
currstartstem = numstems;
/* 'subr#' is left on PostScript stack (for 'pop callsubr') */
}
/* arg1 ... argn n othersubr# CALLOTHERSUBR - */
/* Make calls on the PostScript interpreter (or call equivalent C code) */
/* NOTE: The n arguments have been pushed on the fake PostScript stack */
static void CallOtherSubr(othersubrno)
int othersubrno;
{
IfTrace1((FontDebug), "CallOtherSubr %d\n", othersubrno);
switch(othersubrno) {
case 0: /* OtherSubrs[0]; Main part of Flex */
if (PSFakeTop < 16) Error0("CallOtherSubr: PSFakeStack low");
ClearPSFakeStack();
FlxProc(
PSFakeStack[0], PSFakeStack[1], PSFakeStack[2], PSFakeStack[3],
PSFakeStack[4], PSFakeStack[5], PSFakeStack[6], PSFakeStack[7],
PSFakeStack[8], PSFakeStack[9], PSFakeStack[10], PSFakeStack[11],
PSFakeStack[12], PSFakeStack[13], PSFakeStack[14], PSFakeStack[15],
(int) PSFakeStack[16]
);
break;
case 1: /* OtherSubrs[1]; Part of Flex */
FlxProc1();
break;
case 2: /* OtherSubrs[2]; Part of Flex */
FlxProc2();
break;
case 3: /* OtherSubrs[3]; Hint Replacement */
HintReplace();
break;
default: { /* call OtherSubrs[4] or higher if PostScript is present */
}
}
}
/* |- x y SETCURRENTPOINT |- */
/* Sets the current point to (x,y) in absolute */
/* character space coordinates without per- */
/* forming a CharString MOVETO command */
static void SetCurrentPoint(x, y)
DOUBLE x, y;
{
IfTrace2((FontDebug), "SetCurrentPoint %f %f\n", &x, &y);
currx = x;
curry = y;
}
/* The Type1Char routine for use by PostScript. */
/************************************************/
struct xobject *Type1Char(env, S, charstrP, subrsP, osubrsP, bluesP, modeP)
char *env;
struct XYspace *S;
psobj *charstrP;
psobj *subrsP;
psobj *osubrsP;
struct blues_struct *bluesP; /* FontID's ptr to the blues struct */
int *modeP;
{
int Code;
path = NULL;
errflag = FALSE;
/* Make parameters available to all Type1 routines */
Environment = env;
CharSpace = S; /* used when creating path elements */
CharStringP = charstrP;
SubrsP = subrsP;
OtherSubrsP = osubrsP;
ModeP = modeP;
blues = bluesP;
/* compute the alignment zones */
ComputeAlignmentZones();
StartDecrypt();
ClearStack();
ClearPSFakeStack();
ClearCallStack();
InitStems();
currx = curry = 0;
escapementX = escapementY = 0;
sidebearingX = sidebearingY = 0;
accentoffsetX = accentoffsetY = 0;
wsoffsetX = wsoffsetY = 0; /* No shift to preserve whitspace. */
wsset = 0; /* wsoffsetX,Y haven't been set yet. */
for (;;) {
if (!DoRead(&Code)) break;
Decode(Code);
if (errflag) break;
}
FinitStems();
/* Clean up if an error has occurred */
if (errflag) {
if (path != NULL) {
Destroy(path); /* Reclaim storage */
path = NULL; /* Indicate that character could not be built */
}
}
return((struct xobject *) path);
}
|