Back to index

tetex-bin  3.0
Classes | Defines | Functions | Variables
download.c File Reference
#include "dvips.h"
#include "protos.h"

Go to the source code of this file.

Classes

struct  seenEncodings

Defines

#define DOWNLOAD_USING_PDFTEX
#define DVIPS
#define MAX_CHAR_CODE   256

Functions

void downchar P2C (chardesctype *, c, shalfword, cc)
void makepsname P2C (register char *, s, register int, n)
void lfontout P1C (int, n)
void download P2C (charusetype *, p, int, psfont)
static char ** getEncoding (char *encoding)
static void clearExtraGlyphList ()
static void addGlyph (char *glyphName)
void downpsfont P2C (charusetype *, p, charusetype *, all)
void dopsfont P1C (sectiontype *, fs)

Variables

char * nextstring
char * infont
FILEbitfile
fontdesctypecurfnt
long bytesleft
long mbytesleft
quarterwordraster
quarterwordmraster
Boolean compressed
Boolean partialdownload
double mag
int actualdpi
static unsigned char dummyend [8] = { 252 }
int prettycolumn
int quiet
Boolean disablecomments
real conv
static int lastccout
static char goodnames [] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
static struct seenEncodingsseenEncodings
static char * extraGlyphs = 0
static char * extraGlyphSpace = 0
static int extraGlyphSize = 0
static int glyphSizeUsed = 0

Class Documentation

struct seenEncodings

Definition at line 350 of file download.c.

Collaboration diagram for seenEncodings:
Class Members
char ** glyphs
char * name
struct seenEncodings * next

Define Documentation

Definition at line 8 of file download.c.

#define DVIPS

Definition at line 13 of file download.c.

#define MAX_CHAR_CODE   256

Definition at line 355 of file download.c.


Function Documentation

static void addGlyph ( char *  glyphName) [static]

Definition at line 408 of file download.c.

                                      {
   int len = strlen(glyphName) ;
   char *startOfAdd = 0 ;
   if (len + glyphSizeUsed + 3 > extraGlyphSize) {
      extraGlyphSize = 2 * (extraGlyphSize + len + 100) ;
      extraGlyphSpace = (char *) xrealloc(extraGlyphSpace, extraGlyphSize) ;
   }
   extraGlyphs = extraGlyphSpace ;
   if (glyphSizeUsed == 0) {
      startOfAdd = extraGlyphs + glyphSizeUsed ;
      extraGlyphs[glyphSizeUsed++] = '/' ; /* leading / */
   } else {
      startOfAdd = extraGlyphs + glyphSizeUsed - 1 ;
   }
   strcpy(extraGlyphs + glyphSizeUsed, glyphName) ;
   glyphSizeUsed += len ;
   extraGlyphs[glyphSizeUsed++] = '/' ;    /* trailing / */
   extraGlyphs[glyphSizeUsed] = 0 ;
   if (strstr(extraGlyphs, startOfAdd) != startOfAdd) { /* already there! */
      glyphSizeUsed = startOfAdd - extraGlyphs + 1 ; /* kill the second copy */
      extraGlyphs[glyphSizeUsed] = 0 ;
   }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void clearExtraGlyphList ( ) [static]

Definition at line 399 of file download.c.

                                  {
   glyphSizeUsed = 0 ;
   extraGlyphs = 0 ;
}

Here is the caller graph for this function:

static char** getEncoding ( char *  encoding) [static]

Definition at line 360 of file download.c.

                                          {
   struct seenEncodings *p = seenEncodings ;
   while (p != 0)
      if (strcmp(encoding, p->name) == 0)
         break ;
      else
         p = p->next ;
   if (p == 0) {
      int i ;
      p = (struct seenEncodings *)mymalloc(sizeof(struct seenEncodings)) ;
      p->next = seenEncodings ;
      seenEncodings = p ;
      p->name = xstrdup(encoding) ;
      p->glyphs = (char **)mymalloc((MAX_CHAR_CODE+1) * sizeof(char *)) ;
      for (i=0; i<MAX_CHAR_CODE; i++)
         p->glyphs[i] = ".notdef" ;
      load_enc(encoding, p->glyphs) ;
   }
   return p->glyphs ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void pk_put_count P1C ( int  ,
n   
)

Definition at line 197 of file download.c.

{
       char buf[10];
        char *b = buf ;
        *b++ = '/' ;
        makepsname(b, n) ;
       cmdout(buf);
}

Here is the call graph for this function:

void dopsfont P1C ( sectiontype ,
fs   
)

Definition at line 539 of file download.c.

{
    charusetype *cu ;

    cu = (charusetype *) (fs + 1) ;
#ifdef DOWNLOAD_USING_PDFTEX
    while (cu->fd) {
       if (cu->psfused)
          cu->fd->psflag = EXISTS ;
       downpsfont(cu++, (charusetype *)(fs + 1)) ;
    }
#else
    line = getmem(BUFSIZ);
    tmpline=line;
    while (cu->fd) {
       if (cu->psfused)
          cu->fd->psflag = EXISTS ;
       downpsfont(cu++, (charusetype *)(fs + 1)) ;
    }
    loadbase = ~FLG_LOAD_BASE;
    FirstCharB=UnDefineChars(FirstCharB);
    free(tmpline);
#endif
}

Here is the call graph for this function:

void downchar P2C ( chardesctype ,
c  ,
shalfword  ,
cc   
)

Definition at line 42 of file download.c.

{
   register long i, j ;
   register halfword cheight, cwidth ;
   register long k ;
   register quarterword *p ;
   register halfword cmd ;
   register shalfword xoff, yoff ;
   halfword wwidth = 0 ;
   register long len ;
   int smallchar ;

   p = c->packptr ;
   cmd = *p++ ;
   if (cmd & 4) {
      if ((cmd & 7) == 7) {
         cwidth = getlong(p) ;
         cheight = getlong(p + 4) ;
         xoff = getlong(p + 8) ;
         yoff = getlong(p + 12) ;
         p += 16 ;
      } else {
         cwidth = p[0] * 256 + p[1] ;
         cheight = p[2] * 256 + p[3] ;
         xoff = p[4] * 256 + p[5] ; /* N.B.: xoff, yoff are signed halfwords */
         yoff = p[6] * 256 + p[7] ;
         p += 8 ;
      }
   } else {
      cwidth = *p++ ;
      cheight = *p++ ;
      xoff = *p++ ;
      yoff = *p++ ;
      if (xoff > 127)
         xoff -= 256 ;
      if (yoff > 127)
         yoff -= 256 ;
   }
   if (c->flags & BIGCHAR)
      smallchar = 0 ;
   else
      smallchar = 5 ;
   if (compressed) {
      len = getlong(p) ;
      p += 4 ;
   } else {
      wwidth = (cwidth + 15) / 16 ;
      i = 2 * cheight * (long)wwidth ;
      if (i <= 0)
         i = 2 ;
      i += smallchar ;
      if (mbytesleft < i) {
         if (mbytesleft >= RASTERCHUNK)
            (void) free((char *) mraster) ;
         if (RASTERCHUNK > i) {
            mraster = (quarterword *)mymalloc((integer)RASTERCHUNK) ;
            mbytesleft = RASTERCHUNK ;
         } else {
            k = i + i / 4 ;
            mraster = (quarterword *)mymalloc((integer)k) ;
            mbytesleft = k ;
         }
      }
      k = i;
      while (k > 0)
         mraster[--k] = 0 ;
      unpack(p, (halfword *)mraster, cwidth, cheight, cmd) ;
      p = mraster ;
      len = i - smallchar ;
   }
   if (cheight == 0 || cwidth == 0 || len == 0) {
      cwidth = 1 ;
      cheight = 1 ;
      wwidth = 1 ;
      len = 2 ;
      if (compressed)
         p = dummyend ;  /* CMD(END); see repack.c */
      else
         mraster[0] = 0 ;
   }
   if (smallchar) {
      p[len] = cwidth ;
      p[len + 1] = cheight ;
      p[len + 2] = xoff + 128 ;
      p[len + 3] = yoff + 128 ;
      p[len + 4] = c->pixelwidth ;
   } else
/*
 *   Now we actually send out the data.
 */
      specialout('[') ;
   if (compressed) {
      specialout('<') ;
      mhexout(p, len + smallchar) ;
      specialout('>') ;
   } else {
      i = (cwidth + 7) / 8 ;
      if (i * cheight > 65520) {
         long bc = 0 ;
         specialout('<') ;
         for (j=0; j<cheight; j++) {
            if (bc + i > 65520) {
               specialout('>') ;
               specialout('<') ;
               bc = 0 ;
            }
            mhexout(p, i) ;
            bc += i ;
            p += 2*wwidth ;
         }
         specialout('>') ;
      } else {
         specialout('<') ;
         if (2 * wwidth == i)
            mhexout(p, ((long)cheight) * i + smallchar) ;
         else {
            for (j=0; j<cheight; j++) {
               mhexout(p, i) ;
               p += 2*wwidth ;
            }
            if (smallchar)
               mhexout(p, (long)smallchar) ;
         }
         specialout('>') ;
      }
   }
   if (smallchar == 0) {
      numout((integer)cwidth) ;
      numout((integer)cheight) ;
      numout((integer)xoff + 128) ; /* not all these casts needed. */
      numout((integer)yoff + 128) ;
      numout((integer)(c->pixelwidth)) ;
   }
   if (lastccout + 1 == cc) {
      cmdout("I") ;
   } else {
      numout((integer)cc) ;
      cmdout("D") ;
   }
   lastccout = cc ;
}

Here is the call graph for this function:

void makepsname P2C ( register char *  ,
s  ,
register  int,
n   
)

Definition at line 189 of file download.c.

{
   n-- ;
   *s++ = 'F' + n / (sizeof(goodnames)-1) ;
   *s++ = goodnames[n % (sizeof(goodnames)-1)] ;
   *s++ = 0 ;
}
void download P2C ( charusetype ,
p  ,
int  ,
psfont   
)

Definition at line 209 of file download.c.

{
   register int b, i ;
   register halfword bit ;
   register chardesctype *c ;
   int cc, maxcc = -1, numcc ;
   double fontscale ;
   char name[10] ;
   lastccout = -5 ;
   name[0] = '/' ;
   makepsname(name + 1, psfont) ;
   curfnt = p->fd ;
   curfnt->psname = psfont ;
   if (curfnt->resfont) {
      struct resfont *rf = curfnt->resfont ;
      int non_empty=0;
      for (b=0; b<16; b++)
        if(p->bitmap[b] !=0)
            non_empty =1;
      if(non_empty==0 && curfnt->codewidth==1)
        return;
      cmdout(name) ;
/* following code re-arranged - Rob Hutchings 1992Apr02 */
      c = curfnt->chardesc + 255 ;
      cc = 255 ;
      numcc = 0 ;
      i = 0 ;
      for (b=15; b>=0; b--) {
         for (bit=1; bit; bit<<=1) {
             if (p->bitmap[b] & bit) {
               if (i > 0) {
                  numout((integer)i) ;
                  specialout('[') ;
                  i = 0 ;
               }
               numout((integer)c->pixelwidth) ;
               c->flags |= EXISTS ;
               numcc++ ;
            } else {
               i++ ;
               c->flags &= ~EXISTS ;
            }
            c-- ;
            cc-- ;
         }
      }
      if (i > 0) {
         numout((integer)i) ;
         specialout('[') ;
      }
      specialout ('{') ;
      if (rf->specialinstructions)
         cmdout(rf->specialinstructions) ;
      specialout ('}') ;
      numout((integer)numcc) ;
      /*
       *   This code has been bogus for a long time.  The fix is
       *   straightforward.  The input, curfnt->scaledsize, is the
       *   desired size of the font in dvi units.  The output is the
       *   fontscale, which is the height of the font in output units
       *   which are simply pixels.  Thus, all we need to do is multiply
       *   by the default generic conv, which properly takes into
       *   account magnification, num/den, output resolution, and so on.
       *   Sorry this bug has been in here so long.   -tgr
       */
      fontscale = curfnt->scaledsize * conv ;
      (void)sprintf(nextstring, "%g", fontscale) ;
      cmdout(nextstring) ;
      (void)strcpy(nextstring, "/") ;
      (void)strcat(nextstring, rf->PSname) ;
      cmdout(nextstring) ;
/* end of changed section - Rob */
      cmdout("rf") ;
      rf->sent = 1 ;
      return ;
   }
/*
 *   Here we calculate the largest character actually used, and
 *   send it as a parameter to df.
 */
   cc = 0 ;
   numcc = 0 ;
   for (b=0; b<16; b++) {
      for (bit=32768; bit!=0; bit>>=1) {
         if (p->bitmap[b] & bit) {
            maxcc = cc ;
            numcc++ ;
         }
         cc++ ;
      }
   }
   if (numcc <= 0)
      return ;
   fontscale = ((double)(curfnt->scaledsize)) / 65536.0 ;
   fontscale *= (mag/1000.0) ;
   newline() ;
   fprintf(bitfile, "%%DVIPSBitmapFont: %s %s %g %d\n", name+1, curfnt->name,
                     fontscale, numcc) ;
   cmdout(name) ;
   numout((integer)numcc) ;
   numout((integer)maxcc + 1) ;
/*
 *   If we need to scale the font, we say so by using dfs
 *   instead of df, and we give it a scale factor.  We also
 *   scale the character widths; this is ugly, but scaling
 *   fonts is ugly, and this is the best we can probably do.
 */
   if (curfnt->dpi != curfnt->loadeddpi) {
      numout((integer)curfnt->dpi) ;
      numout((integer)curfnt->loadeddpi) ;
      if (curfnt->alreadyscaled == 0) {
         for (b=0, c=curfnt->chardesc; b<256; b++, c++)
            c->pixelwidth = (c->pixelwidth * 
      (long)curfnt->dpi * 2 + curfnt->loadeddpi) / (2 * curfnt->loadeddpi) ;
         curfnt->alreadyscaled = 1 ;
      }
      cmdout("dfs") ;
   } else
      cmdout("df") ;
   c = curfnt->chardesc ;
   cc = 0 ;
   for (b=0; b<16; b++) {
      for (bit=32768; bit; bit>>=1) {
         if (p->bitmap[b] & bit) {
            downchar(c, cc) ;
            c->flags |= EXISTS ;
         } else
            c->flags &= ~EXISTS ;
         c++ ;
         cc++ ;
      }
   }
   cmdout("E") ;
   newline() ;
   fprintf(bitfile, "%%EndDVIPSBitmapFont\n") ;
}

Here is the call graph for this function:

void downpsfont P2C ( charusetype ,
p  ,
charusetype ,
all   
)

Definition at line 436 of file download.c.

{
#ifdef DOWNLOAD_USING_PDFTEX
    static unsigned char grid[256];
#endif
    int GridCount ;
    register int b;
    register halfword bit ;
    register chardesctype *c ;
    struct resfont *rf ;
    int cc;

    curfnt = p->fd ;
    rf = curfnt->resfont ;
    if (rf == 0 || rf->Fontfile == NULL)
       return ;
    for (; all->fd; all++)
       if (all->fd->resfont &&
           strcmp(rf->PSname, all->fd->resfont->PSname) == 0)
          break ;
    if (all != p)
       return ;
    if (rf->sent == 2) /* sent as header, from a PS file */
       return ;
    if (all->fd == 0)
       error("! internal error in downpsfont") ;
    if (!partialdownload) {
        infont = all->fd->resfont->PSname ;
       copyfile(all->fd->resfont->Fontfile);
        infont = 0 ;
       return;
    }
    for (cc=0; cc<256; cc++)
       grid[cc] = 0 ;
#ifdef DOWNLOAD_USING_PDFTEX
    clearExtraGlyphList() ;
#endif
    for (; all->fd; all++) {
        if (all->fd->resfont == 0 ||
            strcmp(rf->PSname, all->fd->resfont->PSname))
           continue ;
        curfnt = all->fd ;
#ifdef DOWNLOAD_USING_PDFTEX
        if (curfnt->resfont->Vectfile) {
          char **glyphs = getEncoding(curfnt->resfont->Vectfile) ;
           c = curfnt->chardesc + 255 ;
           cc = 255 ;
           for (b=15; b>=0; b--) {
               for (bit=1; bit; bit<<=1) {
                   if (all->bitmap[b] & bit) {
                    addGlyph(glyphs[cc]) ;
                   }
                   c-- ;
                   cc-- ;
               }
            }
        } else {
#endif
           c = curfnt->chardesc + 255 ;
           cc = 255 ;
           for (b=15; b>=0; b--) {
               for (bit=1; bit; bit<<=1) {
                   if (all->bitmap[b] & bit) {
                       grid[cc]=1;
                   }
                   c-- ;
                   cc-- ;
               }
            }
#ifdef DOWNLOAD_USING_PDFTEX
        }
#endif
    }

    for (GridCount=0,cc=0; cc<256; cc++) {
/*      tmpgrid[cc]=grid[cc]; */
        if(grid[cc] ==1) {
            GridCount++;
        }
    }
    if(GridCount!=0 || extraGlyphs) {
        if (!quiet) {
           if (strlen(rf->Fontfile) + prettycolumn > STDOUTSIZE) {
              fprintf(stderr, "\n") ;
              prettycolumn = 0 ;
           }
           (void)fprintf(stderr, "<%s>", rf->Fontfile);
          prettycolumn += strlen(rf->Fontfile) + 2 ;
       }
        newline() ;
        if (! disablecomments)
           (void)fprintf(bitfile, "%%%%BeginFont: %s\n",  rf->PSname);
#ifdef DOWNLOAD_USING_PDFTEX
        if (!t1_subset_2(rf->Fontfile, grid, extraGlyphs))
#else
        if(FontPart(bitfile, rf->Fontfile, rf->Vectfile) < 0)
#endif
            exit(1);
        if (! disablecomments)
           (void)fprintf(bitfile, "%%%%EndFont \n");
   }
}

Here is the call graph for this function:


Variable Documentation

Definition at line 103 of file dvips.c.

Definition at line 93 of file dvips.c.

long bytesleft

Definition at line 112 of file dvips.c.

Definition at line 58 of file dvips.c.

Definition at line 97 of file dvips.c.

Definition at line 54 of file dvips.c.

Definition at line 173 of file dvips.c.

unsigned char dummyend[8] = { 252 } [static]

Definition at line 32 of file download.c.

char* extraGlyphs = 0 [static]

Definition at line 391 of file download.c.

int extraGlyphSize = 0 [static]

Definition at line 394 of file download.c.

char* extraGlyphSpace = 0 [static]

Definition at line 393 of file download.c.

int glyphSizeUsed = 0 [static]

Definition at line 395 of file download.c.

char goodnames[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" [static]

Definition at line 186 of file download.c.

char * infont

Definition at line 125 of file dvips.c.

int lastccout [static]

Definition at line 41 of file download.c.

double mag

Definition at line 598 of file dvi2xx.h.

long mbytesleft

Definition at line 320 of file repack.c.

Definition at line 321 of file repack.c.

char* nextstring

Definition at line 92 of file dvips.c.

Definition at line 56 of file dvips.c.

Definition at line 161 of file dvips.c.

Definition at line 158 of file dvips.c.

Definition at line 113 of file dvips.c.

struct seenEncodings * seenEncodings [static]