Annotation of researchv10no/cmd/dimpress/rotate.c, revision 1.1.1.1

1.1       root        1: 
                      2: /*
                      3:  *
                      4:  * Things needed to rotate glyphs. Includes setting new reference point,
                      5:  * bitmap dimensions, and filling in the new bitmap.
                      6:  *
                      7:  */
                      8: 
                      9: 
                     10: #include <stdio.h>
                     11: 
                     12: #include "gen.h"                       /* a few general definitions */
                     13: #include "rast.h"                      /* for definition of Glyph */
                     14: #include "rotate.h"                    /* rotation macros */
                     15: 
                     16: 
                     17: /*
                     18:  *
                     19:  * These guys are used in the translation and rotation macros defined
                     20:  * in rotate.h.
                     21:  *
                     22:  */
                     23: 
                     24: 
                     25: int    cosine[ROT_COUNT] = {1, 0, -1, 0};
                     26: int    sine[ROT_COUNT] = {0, 1, 0, -1};
                     27: int    delta[ROT_COUNT] = {1, 0, 0, 0};
                     28: 
                     29: 
                     30: char   *bptr = NULL;                   /* last rotated bitmap */
                     31: 
                     32: 
                     33: /*****************************************************************************/
                     34: 
                     35: 
                     36: rotate(glyph, angle)
                     37: 
                     38: 
                     39:     Glyph      *glyph;                 /* rotate this glyph */
                     40:     int                angle;                  /* to this orientation */
                     41: 
                     42: 
                     43: {
                     44: 
                     45: 
                     46:     Glyph      oglyph;                 /* old glyph data */
                     47:     int                orwid;                  /* rows in the old bitmap */
                     48:     int                nrwid;                  /* same but for the new bitmap */
                     49:     int                mapsize;                /* byte size of the new map */
                     50:     int                i, j;                   /* coordinates in the old bitmap */
                     51:     int                x, y;                   /* same but in the new bitmap */
                     52: 
                     53: 
                     54: /*
                     55:  *
                     56:  * Called when we want to rotate glyph to an orientation of angle, where
                     57:  * angle should be 0, 1, 2, or 3. I decided against using a complete set
                     58:  * of raster files that had already been rotated in favor of doing the work
                     59:  * at run time. Really don't expect this stuff to be used that much and
                     60:  * we've already got too many raster files around.
                     61:  *
                     62:  */
                     63: 
                     64: 
                     65:     if ( angle == 0 ) return;          /* everything's already done */
                     66: 
                     67:     oglyph = *glyph;                   /* we'll need most of the old values */
                     68: 
                     69:     glyph->xref = NEWX(oglyph.xref, oglyph.yref, oglyph.height, oglyph.width, angle);
                     70:     glyph->yref = NEWY(oglyph.xref, oglyph.yref, oglyph.height, oglyph.width, angle);
                     71:     glyph->width = (angle % 2) ? oglyph.height : oglyph.width;
                     72:     glyph->height = (angle % 2) ? oglyph.width : oglyph.height;
                     73: 
                     74:     if ( bptr != NULL )
                     75:        free(bptr);
                     76: 
                     77:     mapsize = ((glyph->width + BYTE - 1) / BYTE) * glyph->height;
                     78:     if ( (bptr = (char *) calloc(mapsize, sizeof(char))) == NULL )
                     79:        error(FATAL, "can't get memory for bitmap");
                     80: 
                     81:     orwid = (oglyph.width + BYTE - 1) / BYTE;
                     82:     nrwid = (glyph->width + BYTE - 1) / BYTE;
                     83: 
                     84:     for ( j = 0; j < oglyph.height; j++ )
                     85:        for ( i = 0; i < oglyph.width; i++ )
                     86:            if ( checkbit(oglyph.bptr, orwid * j * BYTE + i) )  {
                     87:                x = NEWX(i, j, oglyph.height, oglyph.width, angle);
                     88:                y = NEWY(i, j, oglyph.height, oglyph.width, angle);
                     89:                setbit(bptr, nrwid * y * BYTE + x);
                     90:            }   /* End if */
                     91: 
                     92:     glyph->bptr = bptr;
                     93: 
                     94: }   /* End of rotate */
                     95: 
                     96: 
                     97: /*****************************************************************************/
                     98: 
                     99: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.