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

  1. /*
  2.     opclipso.c    11/2/88
  3.  
  4.     % Pixel coordinate partial-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_clipstrout(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 even partially in the box, slen will be shortened to <=0;
  30.     Allow characters that are only partially in the box. For windows to work
  31.     using this function, the character plotter must be able to use a clipbox.
  32. */
  33. {
  34.     int delta;
  35.     opcoord xr;
  36.  
  37.     /* Clip left, right, top and bottom */
  38.     /* Quit if chars are completely out left or right */
  39.     /* Quit if chars are completely out top or bottom */
  40.     delta = 0;
  41.     xr = *xp + *slenp * ofont_GetWidth(font);
  42.     if  (xr <= clipboxp->xmin ||
  43.         *xp >= clipboxp->xmax ||
  44.         *yp <= clipboxp->ymin ||
  45.         (opcoord)(*yp - ofont_GetHeight(font)) >= clipboxp->ymax) {
  46.          *slenp = 0;
  47.     }
  48.     else {
  49.         /* Clip right; keep last partial char */
  50.         if ((opcoord)(xr - ofont_GetWidth(font)) >= clipboxp->xmax) {
  51.             *slenp = (clipboxp->xmax - *xp + ofont_GetWidth(font) - 1) /
  52.                         ofont_GetWidth(font);
  53.         }
  54.         /* Clip left; keep first partial char */
  55.         if ((opcoord)(*xp + ofont_GetWidth(font)) <= clipboxp->xmin) {
  56.             delta = (clipboxp->xmin - *xp) / ofont_GetWidth(font);
  57.             *slenp -= delta;
  58.             *xp += delta * ofont_GetWidth(font);
  59.         }
  60.         else delta = 0;
  61.     }
  62.     return(delta);
  63. }
  64. /* -------------------------------------------------------------------------- */
  65.  
  66.