home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / OPCLIPST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  1.8 KB  |  67 lines

  1. /*
  2.     opclipst.c    11/2/88
  3.  
  4.     % Pixel coordinate whole-character string clipping functions.
  5.     Extracted from obox.c
  6.     by Ted.
  7.  
  8.     OWL 1.1
  9.     Copyright (c) 1988, by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14. */
  15.  
  16. #include "oakhead.h"
  17. /* -------------------------------------------------------------------------- */
  18.  
  19. int opbox_clipstring(clipboxp, xp, yp, slenp, font)
  20.     opbox *clipboxp;
  21.     opcoord *xp;
  22.     opcoord *yp;
  23.     int *slenp;
  24.     ofont_type font;
  25. /*
  26.     Clip a string of length 'slen' plotted in font 'font' into box scrbox.
  27.     Return a count of chars to be left off of the start of the string and
  28.     shorten slen to the appropriate number of characters. If no character of
  29.     the string is completely in the box, slen will be shortened to <=0;
  30.     Do not allow characters that are only partially in the box.
  31. */
  32. {
  33.     int delta;
  34.     opcoord xr;
  35.  
  36.     /* Clip left, right, top and bottom */
  37.     /* Quit if chars are completely out left or right */
  38.     /* Quit if chars are only partially in at top or bottom */
  39.     delta = 0;
  40.     xr = *xp + *slenp * ofont_GetWidth(font);
  41.     if  (xr <= clipboxp->xmin ||
  42.         *xp >= clipboxp->xmax ||
  43.         (opcoord)(*yp - ofont_GetHeight(font)) < clipboxp->ymin ||
  44.         *yp > clipboxp->ymax) {
  45.          *slenp = 0;
  46.     }
  47.     else {
  48.         /* Clip right; throw out last partial char */
  49.         if (xr > clipboxp->xmax) {
  50.             *slenp = (clipboxp->xmax - *xp) / ofont_GetWidth(font);
  51.         }
  52.         /* Clip left; throw out first partial char */
  53.         if (*xp < clipboxp->xmin) {
  54.             delta = (clipboxp->xmin - *xp + ofont_GetWidth(font) - 1) /
  55.                     ofont_GetWidth(font);
  56.             if (*slenp > delta) {
  57.                 *slenp -= delta;
  58.             }
  59.             else *slenp = 0;
  60.             *xp += delta * ofont_GetWidth(font);
  61.         }
  62.     }
  63.     return(delta);
  64. }
  65. /* -------------------------------------------------------------------------- */
  66.  
  67.