home *** CD-ROM | disk | FTP | other *** search
- /*
- File: IntersectShapeAndBitmap.c
-
- Contains: QuickDraw GX to PostScript conversion code.
- File contains routine that does IntersectShape,
- allowing for Bitmap shapes as input
-
- Version: Technology: Quickdraw GX 1.1.x
-
- Copyright: © 1991-1997 by Apple Computer, Inc., all rights reserved.
- */
-
- #include <Types.h>
- #include <GXGraphics.h>
- #include "OffscreenLibrary.h"
-
- #if GENERATINGCFM
- #define _IntersectShapeAndBitmap IntersectShapeAndBitmap
- #endif
-
- /*******************************************
-
- Routine: IntersectShapeAndBitmap
-
- Routine is like intersect shape but works
- if one or both of the shapes is a bitmap.
-
- It differs from IntersectShape in that it
- is potentially distructive to the operand.
-
- This could be fixed, but unnecessary for the
- Imaging Engine's use.
-
- ********************************************/
- OSErr IntersectShapeAndBitmap(gxShape target, gxShape operand);
- OSErr IntersectShapeAndBitmap(gxShape target, gxShape operand)
- {
- gxShapeType targetType;
- gxShapeType operandType;
- offscreen theOffscreen;
- gxTransform oldTransform;
- gxTransform tempTransform;
- gxShape offscreenShape;
- gxBitmap offscreenBits;
- gxShape eraseShape;
- gxColor eraseColor;
- gxRectangle tempRect;
- gxShape targetBounds, operandBounds;
- gxPoint bitLocation;
-
- targetType = GXGetShapeType(target);
- operandType = GXGetShapeType(operand);
-
- if ( (targetType != gxBitmapType) && (operandType != gxBitmapType) ) {
-
- GXIntersectShape(target, operand);
-
- } else {
-
- if (operandType == gxBitmapType) { // swap em, we always want target to be the bitmap.
-
- gxShape swapShape = GXCopyToShape(nil, target);
-
- GXCopyToShape(target, operand);
- GXCopyToShape(operand, swapShape);
- GXDisposeShape(swapShape);
-
- }//end if
-
-
- /** Find the intersection of their bounding boxes, to minimize bitmap size **/
-
- targetBounds = GXNewRectangle(GXGetShapeBounds(target, 0, &tempRect));
- operandBounds = GXNewRectangle(GXGetShapeBounds(operand, 0, &tempRect));
- GXIntersectShape(targetBounds, operandBounds);
- GXGetShapeBounds(targetBounds, 0, &tempRect);
- GXDisposeShape(targetBounds);
- GXDisposeShape(operandBounds);
-
- /** Create an offscreen with the inersection rectangle **/
-
- GXGetBitmap(target, &offscreenBits, nil); // Use the target shape's bitmap as a template.
- offscreenBits.image = nil; // Make gx graphics allocate a new bit image.
-
- offscreenBits.width = tempRect.right - tempRect.left;
- offscreenBits.height = tempRect.bottom - tempRect.top;
- bitLocation.x = tempRect.left;
- bitLocation.y = tempRect.top;
- offscreenShape = GXNewBitmap(&offscreenBits, &bitLocation);
- CreateOffscreen(&theOffscreen, offscreenShape);
-
-
- /** Make sure the offscreen is clear **/
- eraseShape = GXNewShape(gxFullType);
- GXSetShapeViewPorts(eraseShape, 1, &(theOffscreen.port));
- eraseColor.space = gxGraySpace;
- eraseColor.profile = offscreenBits.profile; // make sure it is same profile
- eraseColor.element.gray = 0xFFFF;
- GXSetShapeColor(eraseShape, &eraseColor);
- GXDrawShape(eraseShape);
- GXDisposeShape(eraseShape);
-
-
- /** Intersect the two by drawing the oprand, clippped against target into a new offscreen **/
-
- oldTransform = GXCloneTransform(GXGetShapeTransform(operand)); // Save the operand's transform.
- tempTransform = GXNewTransform();
- GXSetTransformViewPorts(tempTransform, 1, &(theOffscreen.port)); // make it draw into offscreen.
- GXSetTransformClip(tempTransform, target); // make the clip the target bitmap.
- GXSetShapeTransform(operand, tempTransform);
- GXDisposeTransform(tempTransform); // shape owns it now.
-
- GXDrawShape(operand); // The offscreen now contains intersection shape which is a bitmap.
-
- GXSetShapeTransform(operand, oldTransform); // restore the original transoform.
- GXDisposeTransform(oldTransform);
-
- GXCopyToShape(target, offscreenShape); // Make the new shape the target.
-
- /** Clean up **/
-
- DisposeOffscreen(&theOffscreen);
- GXDisposeShape(offscreenShape);
-
-
- }//end if
-
- return(GXGetGraphicsError(nil));
-
- }//IntersectShapeAndBitmap
-