17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
237c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.1	*/
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  *
307c478bd9Sstevel@tonic-gate  * Definitions used by the troff post-processor for PostScript printers.
317c478bd9Sstevel@tonic-gate  *
327c478bd9Sstevel@tonic-gate  * DEVNAME should be the name of a device whose font files accurately describe
337c478bd9Sstevel@tonic-gate  * what's available on the target printer. It's a string that's combined with
347c478bd9Sstevel@tonic-gate  * "/usr/lib/font/dev" to locate the final font directory. It can be changed
357c478bd9Sstevel@tonic-gate  * using the -T option, but you may end up getting garbage - the character code
367c478bd9Sstevel@tonic-gate  * field must agree with PostScript's character encoding scheme for each font and
377c478bd9Sstevel@tonic-gate  * troff's one or two character font names must be mapped into the appropriate
387c478bd9Sstevel@tonic-gate  * PostScript font names (typically in the prologue)
397c478bd9Sstevel@tonic-gate  *
407c478bd9Sstevel@tonic-gate  *
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	DEVNAME		"post"		/* name of the target printer */
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  *
477c478bd9Sstevel@tonic-gate  * NFONT is the most font positions we'll allow. It's set ridiculously high for no
487c478bd9Sstevel@tonic-gate  * good reason.
497c478bd9Sstevel@tonic-gate  *
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #define NFONT		60		/* max number of font positions */
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  *
567c478bd9Sstevel@tonic-gate  * SLOP controls how much horizontal positioning error we'll accept and primarily
577c478bd9Sstevel@tonic-gate  * helps when we're emulating another device. It's used when we output characters
587c478bd9Sstevel@tonic-gate  * in oput() to check if troff and the printer have gotten too far out of sync.
597c478bd9Sstevel@tonic-gate  * Given in units of points and can be changed using the -S option. Converted to
607c478bd9Sstevel@tonic-gate  * machine units in t_init() after the resolution is known.
617c478bd9Sstevel@tonic-gate  *
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #define SLOP		.2		/* horizontal error - in points */
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  *
687c478bd9Sstevel@tonic-gate  * Fonts are assigned unique internal numbers (positive integers) in their ASCII
697c478bd9Sstevel@tonic-gate  * font files. MAXINTERNAL is the largest internal font number that lets the host
707c478bd9Sstevel@tonic-gate  * resident and DOCUMENTFONTS stuff work. Used to allocate space for an array that
717c478bd9Sstevel@tonic-gate  * keeps track of what fonts we've seen and perhaps downloaded - could be better!
727c478bd9Sstevel@tonic-gate  *
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #define MAXINTERNAL	256
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  *
797c478bd9Sstevel@tonic-gate  * Several different text line encoding schemes are supported. Print time should
807c478bd9Sstevel@tonic-gate  * decrease as the value assigned to encoding (in dpost.c) increases, although the
817c478bd9Sstevel@tonic-gate  * only encoding that's well tested is the lowest level one, which produces output
827c478bd9Sstevel@tonic-gate  * essentially identical to the original version of dpost. Setting DFLTENCODING to
837c478bd9Sstevel@tonic-gate  * 0 will give you the most stable (but slowest) encoding. The encoding scheme can
847c478bd9Sstevel@tonic-gate  * also be set on the command line using the -e option. Faster methods are based
857c478bd9Sstevel@tonic-gate  * on widthshow and may not place words exactly where troff wanted, but errors will
867c478bd9Sstevel@tonic-gate  * usually not be noticeable.
877c478bd9Sstevel@tonic-gate  *
887c478bd9Sstevel@tonic-gate  */
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #define MAXENCODING	3
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate #ifndef DFLTENCODING
937c478bd9Sstevel@tonic-gate #define DFLTENCODING	0
947c478bd9Sstevel@tonic-gate #endif
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  *
987c478bd9Sstevel@tonic-gate  * The encoding scheme controls how lines of text are output. In the lower level
997c478bd9Sstevel@tonic-gate  * schemes words and horizontal positions are put on the stack as they're read and
1007c478bd9Sstevel@tonic-gate  * when they're printed it's done in reverse order - the first string printed is
1017c478bd9Sstevel@tonic-gate  * the one on top of the stack and it's the last one on the line. Faster methods
1027c478bd9Sstevel@tonic-gate  * may be forced to reverse the order of strings on the stack, making the top one
1037c478bd9Sstevel@tonic-gate  * the first string on the line. STRINGSPACE sets the size of a character array
1047c478bd9Sstevel@tonic-gate  * that's used to save the strings that make up  a line of text so they can be
1057c478bd9Sstevel@tonic-gate  * output in reverse order or perhaps combined in groups for widthshow.
1067c478bd9Sstevel@tonic-gate  *
1077c478bd9Sstevel@tonic-gate  * MAXSTACK controls how far we let PostScript's operand stack grow and determines
1087c478bd9Sstevel@tonic-gate  * the number of strings we'll save before printing all or part of a line of text.
1097c478bd9Sstevel@tonic-gate  * The internal limit in PostScript printers built by Adobe is 500, so MAXSTACK
1107c478bd9Sstevel@tonic-gate  * should never be bigger than about 240!
1117c478bd9Sstevel@tonic-gate  *
1127c478bd9Sstevel@tonic-gate  * Line is a structure used to keep track of the words (or rather strings) on the
1137c478bd9Sstevel@tonic-gate  * current line that have been read but not printed. dx is the width troff wants
1147c478bd9Sstevel@tonic-gate  * to use for a space in the current string. start is where the string began, width
1157c478bd9Sstevel@tonic-gate  * is the total width of the string, and spaces is the number of space characters
1167c478bd9Sstevel@tonic-gate  * in the current string. *str points to the start of the string in the strings[]
1177c478bd9Sstevel@tonic-gate  * array. The Line structure is only used in the higher level encoding schemes.
118*55fea89dSDan Cross  *
1197c478bd9Sstevel@tonic-gate  */
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate #define	MAXSTACK	50		/* most strings we'll save at once */
1227c478bd9Sstevel@tonic-gate #define	STRINGSPACE	2000		/* bytes available for string storage */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate typedef struct {
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 	char	*str;			/* where the string is stored */
1277c478bd9Sstevel@tonic-gate 	int	dx;			/* width of a space */
1287c478bd9Sstevel@tonic-gate 	int	spaces;			/* number of space characters */
1297c478bd9Sstevel@tonic-gate 	int	start;			/* horizontal starting position */
1307c478bd9Sstevel@tonic-gate 	int	width;			/* and its total width */
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate } Line;
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate  *
1367c478bd9Sstevel@tonic-gate  * Simple stuff used to map unrecognized font names into something reasonable. The
1377c478bd9Sstevel@tonic-gate  * mapping array is initialized using FONTMAP and used in loadfont() whenever the
1387c478bd9Sstevel@tonic-gate  * job tries to use a font that we don't recognize. Normally only needed when we're
1397c478bd9Sstevel@tonic-gate  * emulating another device.
1407c478bd9Sstevel@tonic-gate  *
1417c478bd9Sstevel@tonic-gate  */
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate typedef struct {
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	char	*name;			/* font name we're looking for */
1467c478bd9Sstevel@tonic-gate 	char	*use;			/* and this is what we should use */
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate } Fontmap;
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate #define	FONTMAP								\
1517c478bd9Sstevel@tonic-gate 									\
1527c478bd9Sstevel@tonic-gate 	{								\
1537c478bd9Sstevel@tonic-gate 	    "G", "H",							\
1547c478bd9Sstevel@tonic-gate 	    "LO", "S",							\
1557c478bd9Sstevel@tonic-gate 	    "S2", "S",							\
1567c478bd9Sstevel@tonic-gate 	    "GI", "HI",							\
1577c478bd9Sstevel@tonic-gate 	    "HM", "H",							\
1587c478bd9Sstevel@tonic-gate 	    "HK", "H",							\
1597c478bd9Sstevel@tonic-gate 	    "HL", "H",							\
1607c478bd9Sstevel@tonic-gate 	    "PA", "R",							\
1617c478bd9Sstevel@tonic-gate 	    "PI", "I",							\
1627c478bd9Sstevel@tonic-gate 	    "PB", "B",							\
1637c478bd9Sstevel@tonic-gate 	    "PX", "BI",							\
1647c478bd9Sstevel@tonic-gate 	    NULL, NULL,							\
1657c478bd9Sstevel@tonic-gate 	}
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate  *
1697c478bd9Sstevel@tonic-gate  * The Fontmap stuff isn't quite enough if we expect to do a good job emulating
1707c478bd9Sstevel@tonic-gate  * other devices. A recognized font in *realdev's tables may be have a different
1717c478bd9Sstevel@tonic-gate  * name in *devname's tables, and using the *realdev font may not be the best
1727c478bd9Sstevel@tonic-gate  * choice. The fix is to use an optional lookup table for *devname that's used to
1737c478bd9Sstevel@tonic-gate  * map font names into something else before anything else is done. The table we
1747c478bd9Sstevel@tonic-gate  * use is /usr/lib/font/dev*realdev/fontmaps/devname and if it exists getdevmap()
1757c478bd9Sstevel@tonic-gate  * uses the file to fill in a Devfontmap array. Then whenever an "x font pos name"
1767c478bd9Sstevel@tonic-gate  * command is read mapdevfont() uses the lookup table to map name into something
1777c478bd9Sstevel@tonic-gate  * else before loadfont() is called.
1787c478bd9Sstevel@tonic-gate  *
1797c478bd9Sstevel@tonic-gate  */
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate typedef struct {
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	char	name[3];		/* map this font name */
1847c478bd9Sstevel@tonic-gate 	char	use[3];			/* into this one */
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate } Devfontmap;
187*55fea89dSDan Cross 
1887c478bd9Sstevel@tonic-gate /*
1897c478bd9Sstevel@tonic-gate  *
1907c478bd9Sstevel@tonic-gate  * Some of the non-integer valued functions in dpost.c.
1917c478bd9Sstevel@tonic-gate  *
1927c478bd9Sstevel@tonic-gate  */
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate char	*mapfont();
1957c478bd9Sstevel@tonic-gate char	*mapdevfont();
1967c478bd9Sstevel@tonic-gate 
197