home *** CD-ROM | disk | FTP | other *** search
- /*
- opclipst.c 11/2/88
-
- % Pixel coordinate whole-character string clipping functions.
- Extracted from obox.c
- by Ted.
-
- OWL 1.1
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- */
-
- #include "oakhead.h"
- /* -------------------------------------------------------------------------- */
-
- int opbox_clipstring(clipboxp, xp, yp, slenp, font)
- opbox *clipboxp;
- opcoord *xp;
- opcoord *yp;
- int *slenp;
- ofont_type font;
- /*
- Clip a string of length 'slen' plotted in font 'font' into box scrbox.
- Return a count of chars to be left off of the start of the string and
- shorten slen to the appropriate number of characters. If no character of
- the string is completely in the box, slen will be shortened to <=0;
- Do not allow characters that are only partially in the box.
- */
- {
- int delta;
- opcoord xr;
-
- /* Clip left, right, top and bottom */
- /* Quit if chars are completely out left or right */
- /* Quit if chars are only partially in at top or bottom */
- delta = 0;
- xr = *xp + *slenp * ofont_GetWidth(font);
- if (xr <= clipboxp->xmin ||
- *xp >= clipboxp->xmax ||
- (opcoord)(*yp - ofont_GetHeight(font)) < clipboxp->ymin ||
- *yp > clipboxp->ymax) {
- *slenp = 0;
- }
- else {
- /* Clip right; throw out last partial char */
- if (xr > clipboxp->xmax) {
- *slenp = (clipboxp->xmax - *xp) / ofont_GetWidth(font);
- }
- /* Clip left; throw out first partial char */
- if (*xp < clipboxp->xmin) {
- delta = (clipboxp->xmin - *xp + ofont_GetWidth(font) - 1) /
- ofont_GetWidth(font);
- if (*slenp > delta) {
- *slenp -= delta;
- }
- else *slenp = 0;
- *xp += delta * ofont_GetWidth(font);
- }
- }
- return(delta);
- }
- /* -------------------------------------------------------------------------- */
-
-