1: /* $Header: text.c,v 10.3 86/02/01 15:47:40 tony Rel $ */
   2: /* text.c	Prints a line of text
   3:  *
   4:  *	PrintText	Prints text with source font
   5:  *	PrintTextMask	Prints text with mask font
   6:  *	CopyText	Copy text to bitmap
   7:  *	TextWidth	Returns width of a piece of text in a font
   8:  *	CharWidth	Returns width of a character in a font
   9:  *
  10:  */
  11: 
  12: /****************************************************************************
  13:  *									    *
  14:  *  Copyright (c) 1983, 1984 by						    *
  15:  *  DIGITAL EQUIPMENT CORPORATION, Maynard, Massachusetts.		    *
  16:  *  All rights reserved.						    *
  17:  * 									    *
  18:  *  This software is furnished on an as-is basis and may be used and copied *
  19:  *  only with inclusion of the above copyright notice. This software or any *
  20:  *  other copies thereof may be provided or otherwise made available to     *
  21:  *  others only for non-commercial purposes.  No title to or ownership of   *
  22:  *  the software is hereby transferred.					    *
  23:  * 									    *
  24:  *  The information in this software is  subject to change without notice   *
  25:  *  and  should  not  be  construed as  a commitment by DIGITAL EQUIPMENT   *
  26:  *  CORPORATION.							    *
  27:  * 									    *
  28:  *  DIGITAL assumes no responsibility for the use  or  reliability of its   *
  29:  *  software on equipment which is not supplied by DIGITAL.		    *
  30:  * 									    *
  31:  *									    *
  32:  ****************************************************************************/
  33: 
  34: #include "vs100.h"
  35: 
  36: extern BitMap screen;
  37: extern int VSReloc;
  38: extern char FBMap[];
  39: extern char SSMap[];
  40: 
  41: char *AllocateCopy(), *AllocateSpace();
  42: 
  43: PrintText (string, strlen, font, fore, back, charpad, spacepad, dstx, dsty,
  44:        clips, clipcount, func, zmask)
  45:     char *string;
  46:     FONT *font;
  47:     int strlen, fore, back, charpad, spacepad, dstx, dsty;
  48:     CLIP *clips;
  49:     int clipcount, zmask;
  50:     register int func;
  51: {
  52:     register PrintTextPacket *ptp;
  53: #define h ((PacketHeader *) ptp->ptp_head)
  54: #define dest ((BitMap *) ptp->ptp_destImage)
  55: #define destOff ((Point *) ptp->ptp_initialOffset.literal)
  56: #define txt ((TextString *) ptp->ptp_text)
  57: #define control ((ControlString *) ptp->ptp_control)
  58: #define clip ((RectangleList *) ptp->ptp_clipping.rectList)
  59: 
  60:     if (!(zmask & 1)) {
  61:         DeallocateSpace ();
  62:         return;
  63:     }
  64:     if ((string = (caddr_t) AllocateCopy(string, strlen)) == NULL ||
  65:         (ptp = (PrintTextPacket *) AllocateSpace (sizeof (PrintTextPacket))) == NULL)
  66:         return;
  67: 
  68:     if (fore & 1)
  69:         func += 0x20;
  70:     if (back & 1)
  71:         func += 0x10;
  72:     func = FBMap[func];
  73:     h->ph_textMod.m_source = 1; /* Source font */
  74:     h->ph_textMod.m_mask = 0;   /* No mask font */
  75:     h->ph_textMod.m_dest = 0;   /* Dest off. literal */
  76:     h->ph_textMod.m_map = MAPTYPE(func);
  77:     h->ph_textMod.m_textSize = 0;   /* 8 bit characters */
  78:     h->ph_textMod.m_control = 0;    /* No control string */
  79:     h->ph_opcode = PRINT_TEXT;
  80:     *(long *) h->ph_next = NULL;
  81:     *(caddr_t *) ptp->ptp_source.font = FDATA(font)->remote->vsPtr;
  82: 
  83:     *dest = screen;
  84:     destOff->p_x = dstx;
  85:     destOff->p_y = dsty;
  86: 
  87:     *(short *) ptp->ptp_map.literal = MAPLIT(func);
  88: 
  89:     if (clipcount == 1) {
  90:         h->ph_textMod.m_clipping = 1;
  91:         *(CLIP *) ptp->ptp_clipping.litRect = *clips;
  92:     } else {
  93:         h->ph_textMod.m_clipping = 2;
  94:         *(caddr_t *) clip->r_first = (caddr_t) clips + VSReloc;
  95:         clip->r_count = clipcount;
  96:     }
  97: 
  98:     *(caddr_t *) txt->t_first = (caddr_t) string + VSReloc;
  99:     txt->t_count = strlen;
 100: 
 101:     *(short **) control->c_first = NULL;
 102:     control->c_count = 0;
 103:     ptp->ptp_charPad = charpad;
 104:     ptp->ptp_spacePad = spacepad;
 105: 
 106:     WritePacket ((caddr_t) ptp);
 107: #undef h
 108: #undef dest
 109: #undef destOff
 110: #undef txt
 111: #undef control
 112: #undef clip
 113: }
 114: 
 115: PrintTextMask (string, strlen, font, srcpix, charpad, spacepad, dstx, dsty,
 116:            clips, clipcount, func, zmask)
 117:     char *string;
 118:     FONT *font;
 119:     int strlen, srcpix, charpad, spacepad, dstx, dsty;
 120:     CLIP *clips;
 121:     int clipcount, zmask;
 122:     register int func;
 123: {
 124:     register PrintTextPacket *ptp;
 125: #define h ((PacketHeader *) ptp->ptp_head)
 126: #define dest ((BitMap *) ptp->ptp_destImage)
 127: #define destOff ((Point *) ptp->ptp_initialOffset.literal)
 128: #define txt ((TextString *) ptp->ptp_text)
 129: #define control ((ControlString *) ptp->ptp_control)
 130: #define clip ((RectangleList *) ptp->ptp_clipping.rectList)
 131: 
 132:     if (!(zmask & 1)) {
 133:         DeallocateSpace ();
 134:         return;
 135:     }
 136:     if ((string = (caddr_t) AllocateCopy(string, strlen)) == NULL ||
 137:         (ptp = (PrintTextPacket *) AllocateSpace (sizeof (PrintTextPacket))) == NULL)
 138:         return;
 139: 
 140:     func = SSMap[func];
 141:     h->ph_textMod.m_source = 0; /* Constant */
 142:     h->ph_textMod.m_mask = 1;   /* Mask font */
 143:     h->ph_textMod.m_dest = 0;   /* Dest off. literal */
 144:     h->ph_textMod.m_map = MAPTYPE(func);
 145:     h->ph_textMod.m_textSize = 0;   /* 8 bit characters */
 146:     h->ph_textMod.m_control = 0;    /* No control string */
 147:     h->ph_opcode = PRINT_TEXT;
 148:     *(long *) h->ph_next = NULL;
 149:     ptp->ptp_source.const = srcpix & 1;
 150: 
 151:     *(caddr_t *) ptp->ptp_mask = FDATA(font)->remote->vsPtr;
 152: 
 153:     *dest = screen;
 154:     destOff->p_x = dstx;
 155:     destOff->p_y = dsty;
 156: 
 157:     *(short *) ptp->ptp_map.literal = MAPLIT(func);
 158: 
 159:     if (clipcount == 1) {
 160:         h->ph_textMod.m_clipping = 1;
 161:         *(CLIP *) ptp->ptp_clipping.litRect = *clips;
 162:     } else {
 163:         h->ph_textMod.m_clipping = 2;
 164:         *(caddr_t *) clip->r_first = (caddr_t) clips + VSReloc;
 165:         clip->r_count = clipcount;
 166:     }
 167: 
 168:     *(caddr_t *) txt->t_first = (caddr_t) string + VSReloc;
 169:     txt->t_count = strlen;
 170: 
 171:     *(short **) control->c_first = NULL;
 172:     control->c_count = 0;
 173:     ptp->ptp_charPad = charpad;
 174:     ptp->ptp_spacePad = spacepad;
 175: 
 176:     WritePacket ((caddr_t) ptp);
 177: #undef h
 178: #undef dest
 179: #undef destOff
 180: #undef txt
 181: #undef control
 182: #undef clip
 183: }
 184: 
 185: CopyText (string, strlen, font, bm)
 186:     char *string;
 187:     int strlen;
 188:     FONT *font;
 189:     BITMAP *bm;
 190: {
 191:     register PrintTextPacket *ptp;
 192: #define h ((PacketHeader *) ptp->ptp_head)
 193: #define dst ((SubBitmap *) ptp->ptp_destImage)
 194: #define txt ((TextString *) ptp->ptp_text)
 195: #define control ((ControlString *) ptp->ptp_control)
 196: 
 197:     if ((string = (caddr_t) AllocateCopy(string, strlen)) == NULL ||
 198:         (ptp = (PrintTextPacket *) AllocateSpace (sizeof (PrintTextPacket))) == NULL)
 199:         return;
 200: 
 201:     h->ph_textMod.m_source = 1; /* Source font */
 202:     h->ph_textMod.m_mask = 0;   /* No mask font */
 203:     h->ph_textMod.m_dest = 0;   /* Dest off. literal */
 204:     h->ph_textMod.m_map = 0;
 205:     h->ph_textMod.m_textSize = 0;   /* 8 bit characters */
 206:     h->ph_textMod.m_control = 0;    /* No control string */
 207:     h->ph_opcode = PRINT_TEXT;
 208:     *(long *) h->ph_next = NULL;
 209:     *(caddr_t *) ptp->ptp_source.font = FDATA(font)->remote->vsPtr;
 210: 
 211:     *(caddr_t *)dst->sb_address = BDATA(bm)->vsPtr;
 212:     dst->sb_height = bm->height;
 213:     dst->sb_width = bm->width;
 214:     dst->sb_bitsPerPixel = 1;
 215:     dst->sb_x = dst->sb_y = 0;
 216: 
 217:     *(short *) ptp->ptp_map.literal = 0;
 218: 
 219:     h->ph_textMod.m_clipping = 0;
 220: 
 221:     *(caddr_t *) txt->t_first = (caddr_t) string + VSReloc;
 222:     txt->t_count = strlen;
 223: 
 224:     *(short **) control->c_first = NULL;
 225:     control->c_count = 0;
 226:     ptp->ptp_charPad = 0;
 227:     ptp->ptp_spacePad = 0;
 228: 
 229:     WritePacket ((caddr_t) ptp);
 230: #undef h
 231: #undef dst
 232: #undef txt
 233: #undef control
 234: }
 235: 
 236: /* Returns the width of a string in a font */
 237: 
 238: int TextWidth (string, strlen, spacepad, font)
 239:     char *string;
 240:     register int strlen;
 241:     int spacepad;
 242:     register FONT *font;
 243: {
 244:     register u_char *strptr = (u_char *) string;
 245:     short c;
 246:     register short *widths;
 247:     int width = 0;
 248: 
 249:     if (font->fixed) {
 250:         width = strlen * font->avg_width;
 251:         if (spacepad) {
 252:         while (--strlen >= 0)
 253:             if (*strptr++ == font->space)
 254:                 width += spacepad;
 255:         }
 256:     } else {
 257:         widths = FDATA(font)->widths;
 258:         while (--strlen >= 0) {
 259:         c = *strptr++;
 260:         if (c >= font->first && c <= font->last) {
 261:             if (c == font->space)
 262:                 width += spacepad;
 263:             width += widths[c - font->first];
 264:         }
 265:         }
 266:     }
 267: 
 268:     return (width);
 269: }
 270: 
 271: /* Returns width of a character in a font. */
 272: 
 273: int CharWidth(c, font)
 274:     register unsigned int c;
 275:     register FONT *font;
 276: {
 277: 
 278:     if (c < font->first || c > font->last)
 279:         return (0);
 280:     else if (font->fixed)
 281:         return (font->avg_width);
 282:     else
 283:         return (FDATA(font)->widths[c - font->first]);
 284: }

Defined functions

CharWidth defined in line 273; never used
CopyText defined in line 185; used 1 times
PrintText defined in line 43; never used
PrintTextMask defined in line 115; never used
TextWidth defined in line 238; never used

Defined macros

clip defined in line 130; used 6 times
control defined in line 195; used 9 times
dest defined in line 126; used 4 times
destOff defined in line 127; used 6 times
dst defined in line 193; used 7 times
h defined in line 192; used 32 times
txt defined in line 194; used 9 times
Last modified: 1986-02-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1548
Valid CSS Valid XHTML 1.0 Strict