home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / OPCLIPST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-28  |  1.8 KB  |  63 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.2
  9.     Copyright (c) 1988, by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      3/28/90 jmd    ansi-fied
  15. */
  16.  
  17. #include "oakhead.h"
  18. /* -------------------------------------------------------------------------- */
  19.  
  20. int opbox_clipstring(opbox *clipboxp, opcoord *xp, opcoord *yp, int *slenp, ofont_type font)
  21. /*
  22.     Clip a string of length 'slen' plotted in font 'font' into box scrbox.
  23.     Return a count of chars to be left off of the start of the string and
  24.     shorten slen to the appropriate number of characters. If no character of
  25.     the string is completely in the box, slen will be shortened to <=0;
  26.     Do not allow characters that are only partially in the box.
  27. */
  28. {
  29.     int delta;
  30.     opcoord xr;
  31.  
  32.     /* Clip left, right, top and bottom */
  33.     /* Quit if chars are completely out left or right */
  34.     /* Quit if chars are only partially in at top or bottom */
  35.     delta = 0;
  36.     xr = *xp + *slenp * ofont_GetWidth(font);
  37.     if  (xr <= clipboxp->xmin ||
  38.         *xp >= clipboxp->xmax ||
  39.         (opcoord)(*yp - ofont_GetHeight(font)) < clipboxp->ymin ||
  40.         *yp > clipboxp->ymax) {
  41.          *slenp = 0;
  42.     }
  43.     else {
  44.         /* Clip right; throw out last partial char */
  45.         if (xr > clipboxp->xmax) {
  46.             *slenp = (clipboxp->xmax - *xp) / ofont_GetWidth(font);
  47.         }
  48.         /* Clip left; throw out first partial char */
  49.         if (*xp < clipboxp->xmin) {
  50.             delta = (clipboxp->xmin - *xp + ofont_GetWidth(font) - 1) /
  51.                     ofont_GetWidth(font);
  52.             if (*slenp > delta) {
  53.                 *slenp -= delta;
  54.             }
  55.             else *slenp = 0;
  56.             *xp += delta * ofont_GetWidth(font);
  57.         }
  58.     }
  59.     return(delta);
  60. }
  61. /* -------------------------------------------------------------------------- */
  62.  
  63.