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 */
22*f928ce67Sceastha /*
23*f928ce67Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24*f928ce67Sceastha * Use is subject to license terms.
25*f928ce67Sceastha */
26*f928ce67Sceastha
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate *
327c478bd9Sstevel@tonic-gate * Routines that handle color requests passed through as device control commands
337c478bd9Sstevel@tonic-gate * in the form "x X SetColor:red". The following PostScript procedures are needed:
347c478bd9Sstevel@tonic-gate *
357c478bd9Sstevel@tonic-gate * setcolor
367c478bd9Sstevel@tonic-gate *
377c478bd9Sstevel@tonic-gate * mark /color setcolor mark
387c478bd9Sstevel@tonic-gate * mark /color1 /color2 setcolor mark
397c478bd9Sstevel@tonic-gate *
407c478bd9Sstevel@tonic-gate * Called whenever we want to change PostScript's current color graphics
417c478bd9Sstevel@tonic-gate * state parameter. One or two color arguments can be given. In each case
427c478bd9Sstevel@tonic-gate * the colors are looked up in the PostScript colordict dictionary that's
437c478bd9Sstevel@tonic-gate * defined in *colorfile. Two named colors implies reverse video printing
447c478bd9Sstevel@tonic-gate * with the background given in /color2 and the text printed in /color1.
457c478bd9Sstevel@tonic-gate * Unknown colors are mapped into defaults - black for a single color and
467c478bd9Sstevel@tonic-gate * white on black for reverse video.
477c478bd9Sstevel@tonic-gate *
487c478bd9Sstevel@tonic-gate * drawrvbox
497c478bd9Sstevel@tonic-gate *
507c478bd9Sstevel@tonic-gate * leftx rightx drawrvbox -
517c478bd9Sstevel@tonic-gate *
527c478bd9Sstevel@tonic-gate * Fills a box that extends from leftx to rightx with the background color
537c478bd9Sstevel@tonic-gate * that was requested when setcolor set things up for reverse video mode.
547c478bd9Sstevel@tonic-gate * The vertical extent of the box is determined using FontBBox just before
557c478bd9Sstevel@tonic-gate * the first string is printed, and the height remains in effect until
567c478bd9Sstevel@tonic-gate * there's an explicit color change. In otherwords font or size changes
577c478bd9Sstevel@tonic-gate * won't always produce correct result in reverse video mode.
587c478bd9Sstevel@tonic-gate *
597c478bd9Sstevel@tonic-gate * setdecoding
607c478bd9Sstevel@tonic-gate *
617c478bd9Sstevel@tonic-gate * num setdecoding -
627c478bd9Sstevel@tonic-gate *
637c478bd9Sstevel@tonic-gate * Selects the text decoding procedure (ie. what's assigned to PostScript
647c478bd9Sstevel@tonic-gate * procedure t) from the decodingdefs array defined in the prologue. num
657c478bd9Sstevel@tonic-gate * should be the value assigned to variable encoding (in dpost) and will
667c478bd9Sstevel@tonic-gate * remain constant throughout a job, unless special features, like reverse
677c478bd9Sstevel@tonic-gate * video printing, are requested. The text encoding scheme can be set on
687c478bd9Sstevel@tonic-gate * the command line using the -e option. Print time and the size of the
697c478bd9Sstevel@tonic-gate * output file will usually decrease as the value assigned to encoding
707c478bd9Sstevel@tonic-gate * increases.
717c478bd9Sstevel@tonic-gate *
727c478bd9Sstevel@tonic-gate *
737c478bd9Sstevel@tonic-gate * The recognized collection of "x X SetColor:" commands are:
747c478bd9Sstevel@tonic-gate *
757c478bd9Sstevel@tonic-gate * x X SetColor: selects black
767c478bd9Sstevel@tonic-gate * x X SetColor:color selects color
777c478bd9Sstevel@tonic-gate * x X SetColor:color1 on color2 reverse video
787c478bd9Sstevel@tonic-gate * x X SetColor:color1 color2 reverse video again
797c478bd9Sstevel@tonic-gate * x X SetColor:num1 num2 num3 rgb explicit rgb color request
807c478bd9Sstevel@tonic-gate * x X SetColor:num1 num2 num3 hsb explicit hsb color request
817c478bd9Sstevel@tonic-gate *
827c478bd9Sstevel@tonic-gate * In the last three examples num1, num2, and num3 should be numbers between 0 and
837c478bd9Sstevel@tonic-gate * 1 inclusive and are passed on as aguments to the approrpriate PostScript color
847c478bd9Sstevel@tonic-gate * command (eg. setrgbcolor). Unknown color names (ie. the ones that setcolor
857c478bd9Sstevel@tonic-gate * doesn't find in colordict) are mapped into defaults. For one color the default
867c478bd9Sstevel@tonic-gate * is black, while for reverse video it's white text on a black background.
877c478bd9Sstevel@tonic-gate *
887c478bd9Sstevel@tonic-gate * dpost makes sure the current color is maintained across page boundaries, which
897c478bd9Sstevel@tonic-gate * may not be what you want if you're using a macro package like mm that puts out
907c478bd9Sstevel@tonic-gate * page footers and headers. Adding a color request to troff and keeping track of
917c478bd9Sstevel@tonic-gate * the color in each environment may be the best solution.
927c478bd9Sstevel@tonic-gate *
937c478bd9Sstevel@tonic-gate * To get reverse video printing follow the "x X SetColor:" command with two or
947c478bd9Sstevel@tonic-gate * three arguments. "x X SetColor:white on black" or "x X SetColor:white black"
957c478bd9Sstevel@tonic-gate * both produce white text on a black background. Any two colors named in colordict
967c478bd9Sstevel@tonic-gate * (in file *colorfile) can be chosen so "x X SetColor:yellow on blue" also works.
977c478bd9Sstevel@tonic-gate * Each reverse video mode request selects the vertical extent of the background
987c478bd9Sstevel@tonic-gate * box based on the font and size in use just before the first string is printed.
997c478bd9Sstevel@tonic-gate * Font and/or size changes aren't guaranteed to work properly in reverse video
1007c478bd9Sstevel@tonic-gate * printing.
1017c478bd9Sstevel@tonic-gate *
1027c478bd9Sstevel@tonic-gate */
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate #include <stdio.h>
1067c478bd9Sstevel@tonic-gate #include <ctype.h>
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate #include "gen.h" /* general purpose definitions */
1097c478bd9Sstevel@tonic-gate #include "ext.h" /* external variable definitions */
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate #define DEFAULTCOLOR "black"
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate char color[50] = DEFAULTCOLOR; /* current color */
1157c478bd9Sstevel@tonic-gate int gotcolor = FALSE; /* TRUE after *colorfile is downloaded */
1167c478bd9Sstevel@tonic-gate int wantcolor = FALSE; /* TRUE if we really ask for a color */
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate /*
1207c478bd9Sstevel@tonic-gate *
1217c478bd9Sstevel@tonic-gate * All these should be defined in dpost.c.
1227c478bd9Sstevel@tonic-gate *
1237c478bd9Sstevel@tonic-gate */
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate extern int lastend;
1277c478bd9Sstevel@tonic-gate extern int encoding;
1287c478bd9Sstevel@tonic-gate extern int maxencoding;
1297c478bd9Sstevel@tonic-gate extern int realencoding;
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate extern char *colorfile;
1327c478bd9Sstevel@tonic-gate extern FILE *tf;
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate /*****************************************************************************/
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate
138*f928ce67Sceastha void
getcolor(void)139*f928ce67Sceastha getcolor(void)
1407c478bd9Sstevel@tonic-gate {
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate *
1447c478bd9Sstevel@tonic-gate * Responsible for making sure the PostScript color procedures are downloaded from
1457c478bd9Sstevel@tonic-gate * *colorfile. Done at most once per job, and only if the job really uses color.
1467c478bd9Sstevel@tonic-gate * For now I've decided not to quit if we can't read the color file.
1477c478bd9Sstevel@tonic-gate *
1487c478bd9Sstevel@tonic-gate */
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate if ( gotcolor == FALSE && access(colorfile, 04) == 0 )
1527c478bd9Sstevel@tonic-gate doglobal(colorfile);
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate if ( tf == stdout )
1557c478bd9Sstevel@tonic-gate gotcolor = TRUE;
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate } /* End of getcolor */
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate /*****************************************************************************/
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate
163*f928ce67Sceastha void
newcolor(char * name)164*f928ce67Sceastha newcolor(char *name)
165*f928ce67Sceastha /* of the color */
1667c478bd9Sstevel@tonic-gate {
1677c478bd9Sstevel@tonic-gate char *p; /* next character in *name */
1687c478bd9Sstevel@tonic-gate int i; /* goes in color[i] */
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate *
1727c478bd9Sstevel@tonic-gate * Converts *name to lower case and saves the result in color[] for use as the
1737c478bd9Sstevel@tonic-gate * current color. The first time something other than DEFAULTCOLOR is requested
1747c478bd9Sstevel@tonic-gate * sets wantcolor to TRUE. Characters are converted to lower case as they're put
1757c478bd9Sstevel@tonic-gate * in color[] and we quit when we find a newline or get to the end of *name. The
1767c478bd9Sstevel@tonic-gate * isupper() test is for Berkley systems.
1777c478bd9Sstevel@tonic-gate *
1787c478bd9Sstevel@tonic-gate */
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate for ( p = name; *p && (*p == ' ' || *p == ':'); p++ ) ;
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate for ( i = 0; i < sizeof(color) - 1 && *p != '\n' && *p; i++, p++ )
1847c478bd9Sstevel@tonic-gate if ( isupper(*p) )
1857c478bd9Sstevel@tonic-gate color[i] = tolower(*p);
1867c478bd9Sstevel@tonic-gate else color[i] = *p;
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate if ( i == 0 )
1897c478bd9Sstevel@tonic-gate strcpy(color, DEFAULTCOLOR);
1907c478bd9Sstevel@tonic-gate else color[i] = '\0';
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate if ( strcmp(color, DEFAULTCOLOR) != 0 )
1937c478bd9Sstevel@tonic-gate wantcolor = TRUE;
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate } /* End of newcolor */
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate /*****************************************************************************/
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate
201*f928ce67Sceastha void
setcolor(void)202*f928ce67Sceastha setcolor(void)
2037c478bd9Sstevel@tonic-gate {
2047c478bd9Sstevel@tonic-gate int newencoding; /* text encoding scheme that's needed */
2057c478bd9Sstevel@tonic-gate char *p; /* for converting what's in color[] */
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate *
2097c478bd9Sstevel@tonic-gate * Sets the color being used by the printer to whatever's stored as the current
2107c478bd9Sstevel@tonic-gate * color (ie. the string in color[]). wantcolor is only set to TRUE if we've been
2117c478bd9Sstevel@tonic-gate * through newcolor() and asked for something other than DEFAULTCOLOR (probably
2127c478bd9Sstevel@tonic-gate * black). While in reverse video mode encoding gets set to maxencoding + 1 in
2137c478bd9Sstevel@tonic-gate * dpost and 0 on the printer. Didn't see much point in trying to extend reverse
2147c478bd9Sstevel@tonic-gate * video to all the different encoding schemes. realencoding is restored when we
2157c478bd9Sstevel@tonic-gate * leave reverse video mode.
2167c478bd9Sstevel@tonic-gate *
2177c478bd9Sstevel@tonic-gate */
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate if ( wantcolor == TRUE ) {
2217c478bd9Sstevel@tonic-gate endtext();
2227c478bd9Sstevel@tonic-gate getcolor();
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate lastend = -1;
2257c478bd9Sstevel@tonic-gate newencoding = realencoding;
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate if ( islower(color[0]) == 0 ) /* explicit rgb or hsb request */
2287c478bd9Sstevel@tonic-gate fprintf(tf, "%s\n", color);
2297c478bd9Sstevel@tonic-gate else {
2307c478bd9Sstevel@tonic-gate putc('/', tf);
2317c478bd9Sstevel@tonic-gate for ( p = color; *p && *p != ' '; p++ )
2327c478bd9Sstevel@tonic-gate putc(*p, tf);
2337c478bd9Sstevel@tonic-gate for ( ; *p && *p == ' '; p++ ) ;
2347c478bd9Sstevel@tonic-gate if ( strncmp(p, "on ", 3) == 0 ) p += 3;
2357c478bd9Sstevel@tonic-gate if ( *p != '\0' ) {
2367c478bd9Sstevel@tonic-gate fprintf(tf, " /%s", p);
2377c478bd9Sstevel@tonic-gate newencoding = maxencoding + 1;
2387c478bd9Sstevel@tonic-gate } /* End if */
2397c478bd9Sstevel@tonic-gate fprintf(tf, " setcolor\n");
2407c478bd9Sstevel@tonic-gate } /* End else */
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate if ( newencoding != encoding ) {
2437c478bd9Sstevel@tonic-gate encoding = newencoding;
2447c478bd9Sstevel@tonic-gate fprintf(tf, "%d setdecoding\n", encoding);
2457c478bd9Sstevel@tonic-gate resetpos();
2467c478bd9Sstevel@tonic-gate } /* End if */
2477c478bd9Sstevel@tonic-gate } /* End if */
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate } /* End of setcolor */
250