4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
43 * width functions, sizes and fonts
51 /* fitab[f][c] is 0 if c is not on font f */
52 /* if it's non-zero, c is in fontab[f] at position
55 extern struct Font
*fontbase
[NFONT
+1];
56 extern char *codetab
[NFONT
+1];
88 else if (iscontrol(i
))
96 if (sfbits(j
) == oldbits
) {
101 if (widcache
[i
-32].fontpts
== (xfont
<<8) + xpts
&& !setwdf
)
102 k
= widcache
[i
-32].width
;
115 * clear width cache-- s means just space
123 widcache
[0].fontpts
= 0;
126 for (i
=0; i
<NWIDCACHE
; i
++)
127 widcache
[i
].fontpts
= 0;
142 if (i
>= nchtab
+ 128-32) {
143 j
= abscw(i
+ 32 - (nchtab
+128));
146 if (i
== 0) { /* a blank */
147 k
= (fontab
[xfont
][0] * spacesz
+ 6) / 12;
148 /* this nonsense because .ss cmd uses 1/36 em as its units */
149 /* and default is 12 */
152 if ((j
= fitab
[xfont
][i
] & BYTEMASK
) == 0) { /* it's not on current font */
153 /* search through search list of xfont
154 * to see what font it ought to be on.
155 * searches S, then remaining fonts in wraparound order.
160 for (ii
=smnt
, jj
=0; jj
< nfonts
; jj
++, ii
=ii
% nfonts
+ 1) {
161 j
= fitab
[ii
][i
] & BYTEMASK
;
168 numtab
[CT
].val
|= kerntab
[ii
][j
];
173 k
= fontab
[xfont
][0]; /* leave a space-size space */
179 numtab
[CT
].val
|= kerntab
[xfont
][j
];
184 if (cs
= cstab
[xfont
]) {
186 if (ccs
= ccstab
[xfont
])
190 cs
= (cs
* EMPTS(x
)) / 36;
192 k
= ((k
&BYTEMASK
) * xpts
+ (Unitwidth
/ 2)) / Unitwidth
;
194 widcache
[i
].fontpts
= 0;
196 widcache
[i
].fontpts
= (xfont
<<8) + xpts
;
197 widcache
[i
].width
= k
;
200 /* Unitwidth is Units/Point, where
201 * Units is the fundamental digitization
202 * of the character set widths, and
203 * Point is the number of goobies in a point
204 * e.g., for cat, Units=36, Point=6, so Unitwidth=36/6=6
205 * In effect, it's the size at which the widths
206 * translate directly into units.
211 abscw(n
) /* return index of abs char n in fontab[], etc. */
214 ncf
= fontbase
[xfont
]->nwfont
& BYTEMASK
;
215 for (i
= 0; i
< ncf
; i
++)
216 if (codetab
[xfont
][i
] == n
)
264 if ((*s
++ = getach()) == 0 || (*s
++ = getach()) == 0)
267 for (j
= 0; j
< nchtab
; j
++)
268 if (strcmp(&chname
[chtab
[j
]], temp
) == 0)
269 return(j
+ 128 | chbits
);
273 tchar
setabs() /* set absolute char from \C'...' */
284 return n
+ nchtab
+ 128;
295 if ((k
= i
- '0') >= 0 && k
<= nfonts
&& k
< smnt
)
297 for (k
= 0; fontlab
[k
] != i
; k
++)
313 i
= inumb(&apts
); /* this is a disaster for fractional point sizes */
330 * in olden times, it used to ignore changes to 0 or negative.
331 * this is meant to allow the requested size to be anything,
332 * in particular so eqn can generate lots of \s-3's and still
333 * get back by matching \s+3's.
354 for (j
=k
=0 ; pstab
[j
] != 0 ; j
++)
355 if (abs(pstab
[j
]-i
) < abs(pstab
[k
]-i
))
368 for (j
= 0; i
> (k
= pstab
[j
]); j
++)
374 setsbits(chbits
, ++j
);
375 setfbits(chbits
, font
);
376 sps
= width(' ' | chbits
);
388 if (ischar(i
) && isdigit(i
)) { /* \sd or \sdd */
390 if (i
== 0) /* \s0 */
392 else if (i
<= 3 && ischar(j
= cbits(ch
= getch())) &&
393 isdigit(j
)) { /* \sdd */
394 j
= 10 * i
+ j
- '0';
398 } else if (i
== '(') { /* \s(dd */
399 j
= cbits(getch()) - '0';
400 j
= 10 * j
+ cbits(getch()) - '0';
401 if (j
== 0) /* \s(00 */
403 } else if (i
== '+' || i
== '-') { /* \s+, \s- */
405 if (ischar(j
) && isdigit(j
)) { /* \s+d, \s-d */
407 } else if (j
== '(') { /* \s+(dd, \s-(dd */
408 j
= cbits(getch()) - '0';
409 j
= 10 * j
+ cbits(getch()) - '0';
421 tchar
setht() /* set character height from \H'...' */
429 if (n
== 0 || nonumb
)
430 n
= apts
; /* does this work? */
437 tchar
setslant() /* set slant from \S'...' */
475 if (!i
|| i
== 'P') {
479 if (i
== 'S' || i
== '0')
481 if ((j
= findft(i
)) == -1)
482 if ((j
= setfp(0, i
, 0)) == -1) /* try to put it in position 0 */
499 int savhp
, savapts
, savapts1
, savfont
, savfont1
, savpts
, savpts1
;
501 base
= numtab
[ST
].val
= wid
= numtab
[CT
].val
= 0;
502 if (ismot(i
= getch()))
505 savhp
= numtab
[HP
].val
;
514 while (cbits(i
= getch()) != delim
&& !nlflg
) {
520 } else if (isvmot(i
)) {
528 if (base
< numtab
[SB
].val
)
529 numtab
[SB
].val
= base
;
530 if ((k
= base
+ emsz
) > numtab
[ST
].val
)
533 setn1(wid
, 0, (tchar
) 0);
534 numtab
[HP
].val
= savhp
;
569 getch(); /*eat delim*/
573 i
= makem(quant(n
, j
));
623 if ((lf
= fontbase
[fbits(i
)]->ligfont
) == 0) /* font lacks ligatures */
626 if (cbits(j
) == 'i' && (lf
& LFI
))
628 else if (cbits(j
) == 'l' && (lf
& LFL
))
630 else if (cbits(j
) == 'f' && (lf
& LFF
)) {
631 if ((lf
& (LFFI
|LFFL
)) && lg
!= 2) {
633 if (cbits(k
)=='i' && (lf
&LFFI
))
635 else if (cbits(k
)=='l' && (lf
&LFFL
))
647 return(i
& SFMASK
| j
);
671 if ((i
= cbits(getch()) - '0') <= 0 || i
> nfonts
)
672 errprint(gettext("fp: bad font position %d"), i
);
673 else if (skip() || !(j
= getrq()))
674 errprint(gettext("fp: no font name"));
675 else if (skip() || !getname())
677 else /* 3rd argument = filename */
684 setfp(pos
, f
, truename
) /* mount font f at position pos[0...nfonts] */
690 char longname
[NS
], shortname
[20];
695 strcpy(shortname
, truename
);
697 shortname
[0] = f
& BYTEMASK
;
698 shortname
[1] = f
>> BYTE
;
701 sprintf(longname
, "%s/dev%s/%s.out", fontfile
, devname
, shortname
);
702 if ((k
= open(longname
, 0)) < 0) {
703 errprint(gettext("Can't open %s"), longname
);
706 n
= fontbase
[pos
]->nwfont
& BYTEMASK
;
707 read(k
, (char *) fontbase
[pos
], 3*n
+ nchtab
+ 128 - 32 + sizeof(struct Font
));
708 kerntab
[pos
] = (char *) fontab
[pos
] + (fontbase
[pos
]->nwfont
& BYTEMASK
);
709 /* have to reset the fitab pointer because the width may be different */
710 fitab
[pos
] = (char *) fontab
[pos
] + 3 * (fontbase
[pos
]->nwfont
& BYTEMASK
);
711 if ((fontbase
[pos
]->nwfont
& BYTEMASK
) > n
) {
712 errprint(gettext("Font %s too big for position %d"), shortname
,
716 fontbase
[pos
]->nwfont
= n
; /* so can load a larger one again later */
722 if ((fontlab
[pos
] = f
) == 'S')
724 bdtab
[pos
] = cstab
[pos
] = ccstab
[pos
] = 0;
725 /* if there is a directory, no place to store its name. */
726 /* if position isn't zero, no place to store its value. */
727 /* only time a FONTPOS is pushed back is if it's a */
728 /* standard font on position 0 (i.e., mounted implicitly. */
729 /* there's a bug here: if there are several input lines */
730 /* that look like .ft XX in short successtion, the output */
731 /* will all be in the last one because the "x font ..." */
732 /* comes out too soon. pushing back FONTPOS doesn't work */
733 /* with .ft commands because input is flushed after .xx cmds */
734 ptfpcmd(pos
, shortname
);
736 ch
= (tchar
) FONTPOS
| (tchar
) f
<< 16;
748 if (!(i
= getrq()) || (i
= findft(i
)) < 0)
757 ccstab
[i
] = findps(j
);
774 if (skip() || !(i
= getrq()) || (j
= findft(i
)) == -1) {
805 dfact
= INCH
; /* default scaling is points! */
830 sps
= width(' ' | chbits
);
840 /* stores \x'...' into
841 * two successive tchars.
842 * the first contains HX, the second the value,
843 * encoded as a vertical motion.
844 * decoding is done in n2.c by pchar().
850 i
= quant(atoi(), VERT
);
854 *pbp
++ = MOT
| VMOT
| i
;
856 *pbp
++ = MOT
| VMOT
| NMOT
| -i
;