Back to index

tetex-bin  3.0
Classes | Defines | Functions | Variables
color.c File Reference
#include "dvips.h"
#include <stdio.h>
#include "protos.h"

Go to the source code of this file.

Classes

struct  colorpage

Defines

#define COLORHASH   (89)
#define MAXCOLORLEN   (120) /* maximum color length for background */
#define INITCOLORLEN   (3000) /* initial stack size in chars */
#define DEFAULTCOLOR   "Black"

Functions

void colorcmdout P1C (char *, s)
void initcolor ()
void background P1C (char *, bkgrnd)
void pushcolor P2C (char *, p, Boolean, outtops)
void popcolor P1C (Boolean, outtops)
void resetcolorstack P2C (char *, p, int, outtops)
void bopcolor P1C (int, outtops)

Variables

integer pagenum
FILEdvifile
static struct colorpagecolorhash [COLORHASH]
static char * cstack
static char * csp
static char * cend
static char * bg

Class Documentation

struct colorpage

Definition at line 37 of file color.c.

Collaboration diagram for colorpage:
Class Members
char * bg
integer boploc
char colordat
struct colorpage * next

Define Documentation

#define COLORHASH   (89)

Definition at line 28 of file color.c.

#define DEFAULTCOLOR   "Black"

Definition at line 79 of file color.c.

#define INITCOLORLEN   (3000) /* initial stack size in chars */

Definition at line 30 of file color.c.

#define MAXCOLORLEN   (120) /* maximum color length for background */

Definition at line 29 of file color.c.


Function Documentation

Definition at line 80 of file color.c.

                 {
   int i ;
   struct colorpage *p, *q ;

   for (i=0; i<COLORHASH; i++) {
      for (p=colorhash[i]; p; p = q) {
         q = p->next ;
         free(p) ;
      }
      colorhash[i] = 0 ;
   }
   cstack = (char *)mymalloc(INITCOLORLEN) ;
   strcpy(cstack, "\n") ;
   strcat(cstack, DEFAULTCOLOR) ;
   csp = cstack + strlen(cstack) ;
   cend = cstack + INITCOLORLEN - 3 ; /* for conservativeness */
   bg = 0 ;
}

Here is the call graph for this function:

void colorcmdout P1C ( char *  ,
s   
)

Definition at line 51 of file color.c.

{
   char *p ;
   char tempword[100] ;

   while (*s && *s <= ' ')
      s++ ;
   if (*s == '"') {
      cmdout(s+1) ;
      return ;
   }
   for (p=s; *p && *p > ' '; p++) ;
   for (; *p && *p <= ' '; p++) ;
   if (*p == 0) {
      cmdout(s) ;
      return ;
   }
   cmdout(p) ;
   strcpy(tempword, "TeXcolor") ;
   for (p=tempword + strlen(tempword); *s && *s > ' '; p++, s++)
      *p = *s ;
   *p = 0 ;
   cmdout(tempword) ;
   return ;
}

Here is the call graph for this function:

void background P1C ( char *  ,
bkgrnd   
)

Definition at line 104 of file color.c.

{
   if (bkgrnd && *bkgrnd) {
      if (strlen(bkgrnd) > MAXCOLORLEN)
         error(" color name too long; ignored") ;
      else
         strcpy(bg, bkgrnd) ;
   }
}

Here is the call graph for this function:

void popcolor P1C ( Boolean  ,
outtops   
)

Definition at line 140 of file color.c.

{
   char *p = csp - 1 ;

   while (p >= cstack && *p != '\n')
      p-- ;
   if (p == cstack)
      return ;  /* We don't pop the last color as that is global */
   *p = 0 ;
   csp = p ;
   for (p--; p >= cstack && *p != '\n'; p--) ;
   p++ ;
   if ( outtops ) {
      colorcmdout(p) ;
   }
}
void bopcolor P1C ( int  ,
outtops   
)

Definition at line 196 of file color.c.

{
   integer pageloc = ftell(dvifile) ;
   int h = pageloc % COLORHASH ;
   struct colorpage *p = colorhash[h] ;

   while (p) {
      if (p->boploc == pageloc)
         break ;
      else
         p = p->next ;
   }
   if (p) {
      strcpy(cstack, p->colordat) ;
      csp = cstack + strlen(cstack) ;
      bg = p->bg ;
      if (outtops && strcmp(bg, "White")!=0 && bg[0]) {
         cmdout("gsave") ;
         colorcmdout(bg) ;
         cmdout("clippath fill grestore") ;
      }
   } else {
      p = (struct colorpage *)mymalloc((integer)
                  (strlen(cstack) + sizeof(struct colorpage) + MAXCOLORLEN)) ;
      p->next = colorhash[h] ;
      p->boploc = pageloc ;
      strcpy(p->colordat, cstack) ;
      p->bg = p->colordat + strlen(cstack) + 1 ;
      if (bg)
         strcpy(p->bg, bg) ;
      else
         *(p->bg) = 0 ;
      bg = p->bg ;
      colorhash[h] = p ;
   }
   if (outtops) {
      char *pp = csp - 1 ;
      while (pp >= cstack && *pp != '\n')
         pp-- ;
      pp++ ;
      if (strcmp(pp, DEFAULTCOLOR)!=0) {
         colorcmdout(pp) ;
      }
   }
}

Here is the call graph for this function:

void pushcolor P2C ( char *  ,
p  ,
Boolean  ,
outtops   
)

Definition at line 118 of file color.c.

{
   while (strlen(p) + csp > cend) {
      int newlen = 3 * (cend - cstack) ;
      char *newcs = (char *)mymalloc(newlen) ;
      strcpy(newcs, cstack) ;
      csp = newcs + (csp - cstack) ;
      cend = newcs + newlen - 3 ;
      cstack = newcs ;
   }
   *csp++ = '\n' ;
   strcpy(csp, p) ;
   csp += strlen(p) ;
   if (outtops) {
      colorcmdout(p) ;
   }
}

Here is the call graph for this function:

void resetcolorstack P2C ( char *  ,
p  ,
int  ,
outtops   
)

Definition at line 161 of file color.c.

{
   char *q = csp - 1 ;

   while (q > cstack && *q != '\n')
      q-- ;
   if (q > cstack && outtops == 0) {
#ifdef SHORTINT
     (void)fprintf(stderr, "You've mistakenly made a global color change ") ;
     (void)fprintf(stderr, "to %s within nested colors\n", p) ;
     (void)fprintf(stderr, "on page %ld. Will try to recover.\n", pagenum) ;
#else   /* ~SHORTINT */
     (void)fprintf(stderr, "You've mistakenly made a global color change ") ;
     (void)fprintf(stderr, "to %s within nested colors\n", p) ;
     (void)fprintf(stderr, "on page %d. Will try to recover.\n", pagenum) ;
#endif  /* ~SHORTINT */
   }
   csp = cstack ;
   *csp = 0 ;
   pushcolor(p, outtops) ;
}

Here is the call graph for this function:


Variable Documentation

char * bg [static]

Definition at line 43 of file color.c.

char * cend [static]

Definition at line 43 of file color.c.

struct colorpage * colorhash[COLORHASH] [static]
char * csp [static]

Definition at line 43 of file color.c.

char* cstack [static]

Definition at line 43 of file color.c.

Definition at line 93 of file dvips.c.

Definition at line 111 of file dvips.c.