示例#1
0
def tilePDFDocument(context, offscreenType):
    url = GetURL(kCatPDF)

    if url is not None:
        if offscreenType == noOffScreen:
            BitmapContext.TilePDFNoBuffer(context, url)
        elif offscreenType == bitmapOffScreen:
            BitmapContext.TilePDFWithOffscreenBitmap(context, url)
        else:
            BitmapContext.TilePDFWithCGLayer(context, url)
示例#2
0
 def exportAsTIFF_(self, sender):
     url = getURLToExport("tif")
     if url is not None:
         exportInfo = Utilities.ExportInfo()
         self.setupExportInfo_(exportInfo)
         BitmapContext.MakeTIFFDocument(url, exportInfo)
示例#3
0
 def exportAsJPEG_(self, sender):
     url = getURLToExport("jpg")
     if url is not None:
         exportInfo = Utilities.ExportInfo()
         self.setupExportInfo_(exportInfo)
         BitmapContext.MakeJPEGDocument(url, exportInfo)
示例#4
0
def DispatchDrawing(context, drawingType):
    """ Drawing dispatcher """
    if drawingType == UIHandling.kHICommandSimpleRect:
            DrawingBasics.doSimpleRect(context)

    elif drawingType == UIHandling.kHICommandStrokedRect:
            DrawingBasics.doStrokedRect(context)
    
    elif drawingType == UIHandling.kHICommandStrokedAndFilledRect:
            DrawingBasics.doStrokedAndFilledRect(context)

    elif drawingType == UIHandling.kHICommandPathRects:
            DrawingBasics.doPathRects(context)
    
    elif drawingType == UIHandling.kHICommandAlphaRects:
            DrawingBasics.doAlphaRects(context)
    
    elif drawingType == UIHandling.kHICommandDashed:
            DrawingBasics.doDashedLines(context)
    
    elif drawingType == UIHandling.kHICommandSimpleClip:
            DrawingBasics.doClippedCircle(context)
    
    elif drawingType == UIHandling.kHICommandPDFDoc:
            callPDFDrawProc(context, DrawingBasics.doPDFDocument, kCatPDF)
        
    elif drawingType == UIHandling.kHICommandRotatedEllipses:
            CoordinateSystem.doRotatedEllipses(context)

    elif drawingType == UIHandling.kHICommandDrawSkewCoordinates:
            CoordinateSystem.drawSkewedCoordinateSystem(context)

    elif drawingType == UIHandling.kHICommandBezierEgg:
            PathDrawing.doEgg(context)

    elif drawingType == UIHandling.kHICommandRoundedRects:
            PathDrawing.doRoundedRects(context)

    elif drawingType == UIHandling.kHICommandStrokeWithCTM:
            PathDrawing.doStrokeWithCTM(context)

    elif drawingType == UIHandling.kHICommandRotatedEllipsesWithCGPath:
            PathDrawing.doRotatedEllipsesWithCGPath(context)

    elif drawingType == UIHandling.kHICommandPixelAligned:
            PathDrawing.doPixelAlignedFillAndStroke(context)

    elif drawingType == UIHandling.kHICommandDeviceFillAndStrokeColor:
            ColorAndGState.doColorSpaceFillAndStroke(context)

    elif drawingType == UIHandling.kHICommandCLUTDrawGraphics:
            ColorAndGState.doIndexedColorDrawGraphics(context)
            
    elif drawingType == UIHandling.kHICommandDrawWithGlobalAlpha:
            ColorAndGState.drawWithGlobalAlpha(context)

    elif drawingType == UIHandling.kHICommandDrawWithBlendMode:
            callPDFDrawProc(context, ColorAndGState.drawWithColorBlendMode, kPDFForBlendMode)

    elif drawingType == UIHandling.kHICommandDrawWithColorRefs:
            ColorAndGState.drawWithColorRefs(context)

    elif drawingType == UIHandling.kHICommandFunctionsHaveOwnGSave:
            ColorAndGState.doClippedEllipse(context)

    elif drawingType == UIHandling.kHICommandDrawJPEGImage:
            doDrawJPEGFile(context)

    elif drawingType == UIHandling.kHICommandColorImageFromFile:
            doRawImageFileWithURL(context)

    elif drawingType == UIHandling.kHICommandColorImageFromData:
            Images.doColorRampImage(context)

    elif drawingType == UIHandling.kHICommandColorImageFromCallbacks:
            doRawImageFileWithCallbacks(context)

    elif drawingType == UIHandling.kHICommandGrayRamp:
            Images.doGrayRamp(context)

    elif drawingType == UIHandling.kHICommandDrawWithCGImageSource:
            doDrawImageWithCGImageSource(context)

    elif drawingType == UIHandling.kHICommandDrawWithCGImageSourceIncremental:
            doIncrementalImage(context)

    elif drawingType == UIHandling.kHICommandDrawWithQuickTime:
            doQTImage(context)

    elif drawingType == UIHandling.kHICommandSubstituteImageProfile:
            doJPEGDocumentWithMultipleProfiles(context)

    elif drawingType == UIHandling.kHICommandDoSubImage:
            Images.doColorRampSubImage(context)

    elif drawingType == UIHandling.kHICommandExportWithQuickTime:
            Images.exportColorRampImageWithQT(context)

    elif drawingType == UIHandling.kHICommandMaskTurkeyImage:
            ImageMasking.doOneBitMaskImages(context)

    elif drawingType == UIHandling.kHICommandImageMaskedWithMask:
            doMaskImageWithMask(context)

    elif drawingType == UIHandling.kHICommandImageMaskedWithGrayImage:
            doMaskImageWithGrayImage(context)

    elif drawingType == UIHandling.kHICommandMaskImageWithColor:
            doImageMaskedWithColor(context)

    elif drawingType == UIHandling.kHICommandClipToMask:
            doClipMask(context)

    elif drawingType == UIHandling.kHICommandExportWithCGImageDestination:
            exportImageMaskedWithImage(context)

    elif drawingType == UIHandling.kHICommandSimpleCGLayer:
            BitmapContext.doSimpleCGLayer(context)

    elif drawingType == UIHandling.kHICommandAlphaOnlyContext:
            BitmapContext.doAlphaOnlyContext(context)

    elif drawingType == UIHandling.kHICommandDrawNoOffScreenImage:
            tilePDFDocument(context, noOffScreen)

    elif drawingType == UIHandling.kHICommandDrawOffScreenImage:
            tilePDFDocument(context, bitmapOffScreen)

    elif drawingType == UIHandling.kHICommandDrawWithLayer:
            tilePDFDocument(context, layerOffScreen)

    elif drawingType == UIHandling.kHICommandQuartzRomanText:
            QuartzTextDrawing.drawQuartzRomanText(context)

    elif drawingType == UIHandling.kHICommandQuartzTextModes:
            QuartzTextDrawing.drawQuartzTextWithTextModes(context)

    elif drawingType == UIHandling.kHICommandQuartzTextMatrix:
            QuartzTextDrawing.drawQuartzTextWithTextMatrix(context)

    elif drawingType == UIHandling.kHICommandSimplePattern:
            PatternDrawing.doRedBlackCheckerboard(context)

    elif drawingType == UIHandling.kHICommandPatternPhase:
            PatternDrawing.doPatternPhase(context)

    elif drawingType == UIHandling.kHICommandPatternMatrix:
            PatternDrawing.doPatternMatrix(context)

    elif drawingType == UIHandling.kHICommandUncoloredPattern:
            PatternDrawing.doStencilPattern(context)
            
    elif drawingType == UIHandling.kHICommandDrawWithPDFPattern:
            callPDFDrawProc(context, PatternDrawing.drawWithPDFPattern, kCatPDF)

    elif drawingType == UIHandling.kHICommandSimpleShadow:
            ShadowsAndTransparencyLayers.drawSimpleShadow(context)
        
    elif drawingType == UIHandling.kHICommandShadowScaling:
            ShadowsAndTransparencyLayers.doShadowScaling(context)
    
    elif drawingType == UIHandling.kHICommandShadowProblems:
            ShadowsAndTransparencyLayers.showComplexShadowIssues(context)

    elif drawingType == UIHandling.kHICommandComplexShadow:
            ShadowsAndTransparencyLayers.showComplexShadow(context)
    
    elif drawingType == UIHandling.kHICommandMultipleShapeComposite:
            ShadowsAndTransparencyLayers.doLayerCompositing(context)

    elif drawingType == UIHandling.kHICommandFillAndStrokeWithShadow:
            ShadowsAndTransparencyLayers.drawFillAndStrokeWithShadow(context)

    elif drawingType == UIHandling.kHICommandPDFDocumentShadow:
            callPDFDrawProc(context, ShadowsAndTransparencyLayers.shadowPDFDocument, kCatPDF)

    elif drawingType == UIHandling.kHICommandSimpleAxialShading:
            Shadings.doSimpleAxialShading(context)
            
    elif drawingType == UIHandling.kHICommandExampleAxialShadings:
            Shadings.doExampleAxialShading(context)

    elif drawingType == UIHandling.kHICommandSimpleRadialShading:
            Shadings.doSimpleRadialShading(context)

    elif drawingType == UIHandling.kHICommandExampleRadialShadings:
            Shadings.doExampleRadialShadings(context)

    elif drawingType == UIHandling.kHICommandEllipseShading:
            Shadings.doEllipseShading(context)

    elif drawingType == UIHandling.kHICommandDoCompatibleEPS:
            doCompatibleEPSDrawing(context)
示例#5
0
def createEPSPreviewImage(url):
    # The CGImage used as the preview needs to have the
    # same width and height as the EPS data it will
    # be associated with. This sample code doesn't attempt
    # to use any preview image associated with the EPS
    # data but instead simply draws a box of an appropriate
    # size. Your code would most likely create an image
    # that reflects a PICT or TIFF preview present in the
    # EPS data.
    result, path = Cocoa.CFURLGetFileSystemRepresentation(url, True, None, 1024)
    if not result:
        print("Couldn't get the path for EPS file!")
        return None

    path = path.rstrip(b"\0")

    epsRect = getEPSBBox(path)
    # Check whether the EPS bounding box is empty.
    if epsRect == Quartz.CGRectZero:
        print("Couldn't find BoundingBox comment!")
        return None

    wantDisplayColorSpace = False
    needsTransparentBitmap = True
    # Create a bitmap context to draw to in order to
    # create the preview image. Use the routine
    # createRGBBitmapContext from the earlier chapter.
    bitmapContext = BitmapContext.createRGBBitmapContext(
        epsRect.size.width,
        epsRect.size.height,
        wantDisplayColorSpace,
        needsTransparentBitmap,
    )
    if bitmapContext is None:
        print("Couldn't create bitmap context")
        return None

    epsRect.origin.x = epsRect.origin.y = 0
    # Draw the contents of the preview. The preview consists
    # of two lines and a stroke around the bounding box. One
    # of the two lines is drawn from the lower-left corner to
    # the upper-right corner of the bounding box and the other
    # line is from the lower-right corner to the upper-left
    # corner of the bounding box.
    Quartz.CGContextBeginPath(bitmapContext)
    Quartz.CGContextMoveToPoint(bitmapContext, 0, 0)
    Quartz.CGContextAddLineToPoint(
        bitmapContext, epsRect.size.width, epsRect.size.height
    )
    Quartz.CGContextMoveToPoint(bitmapContext, epsRect.size.width, 0)
    Quartz.CGContextAddLineToPoint(bitmapContext, 0, epsRect.size.height)
    Quartz.CGContextStrokePath(bitmapContext)
    # Stroke the bounding rectangle, inset so that the stroke is
    # completely contained in the EPS bounding rect.
    Quartz.CGContextStrokeRect(bitmapContext, Quartz.CGRectInset(epsRect, 0.5, 0.5))

    # Now create an image from the bitmap raster data. This image
    # has a data provider that releases the image raster data when
    # the image is released. Use the createImageFromBitmapContext
    # from Chapter 12. Calling createImageFromBitmapContext
    # gives up ownership of the raster data used by the context.
    epsPreviewImage = BitmapContext.createImageFromBitmapContext(bitmapContext)

    if epsPreviewImage is None:
        print("Couldn't create preview image!")
        return None

    return epsPreviewImage
示例#6
0
def createEPSPreviewImage(url):
    # The CGImage used as the preview needs to have the
    # same width and height as the EPS data it will
    # be associated with. This sample code doesn't attempt
    # to use any preview image associated with the EPS
    # data but instead simply draws a box of an appropriate
    # size. Your code would most likely create an image
    # that reflects a PICT or TIFF preview present in the
    # EPS data.
    result, path = CFURLGetFileSystemRepresentation(url, True, None, 1024)
    if not result:
        print >>sys.stderr, "Couldn't get the path for EPS file!"
        return None

    path = path.rstrip('\0')

    epsRect = getEPSBBox(path)
    # Check whether the EPS bounding box is empty.
    if epsRect == CGRectZero:
        print >>sys.stderr, "Couldn't find BoundingBox comment!"
        return None

    wantDisplayColorSpace = False
    needsTransparentBitmap = True
    # Create a bitmap context to draw to in order to
    # create the preview image. Use the routine
    # createRGBBitmapContext from the earlier chapter.
    bitmapContext = BitmapContext.createRGBBitmapContext(
                                    epsRect.size.width,
                                    epsRect.size.height,
                                    wantDisplayColorSpace,
                                    needsTransparentBitmap)
    if bitmapContext is None:
        print >>sys.stderr, "Couldn't create bitmap context"
        return None

    epsRect.origin.x = epsRect.origin.y = 0
    # Draw the contents of the preview. The preview consists
    # of two lines and a stroke around the bounding box. One
    # of the two lines is drawn from the lower-left corner to
    # the upper-right corner of the bounding box and the other
    # line is from the lower-right corner to the upper-left
    # corner of the bounding box.
    CGContextBeginPath(bitmapContext)
    CGContextMoveToPoint(bitmapContext, 0, 0)
    CGContextAddLineToPoint(bitmapContext, epsRect.size.width, epsRect.size.height)
    CGContextMoveToPoint(bitmapContext, epsRect.size.width, 0)
    CGContextAddLineToPoint(bitmapContext, 0, epsRect.size.height)
    CGContextStrokePath(bitmapContext)
    # Stroke the bounding rectangle, inset so that the stroke is
    # completely contained in the EPS bounding rect.
    CGContextStrokeRect(bitmapContext, CGRectInset(epsRect, 0.5, 0.5))

    # Now create an image from the bitmap raster data. This image
    # has a data provider that releases the image raster data when
    # the image is released. Use the createImageFromBitmapContext
    # from Chapter 12. Calling createImageFromBitmapContext
    # gives up ownership of the raster data used by the context.
    epsPreviewImage = BitmapContext.createImageFromBitmapContext(bitmapContext)

    if epsPreviewImage is None:
        print >>sys.stderr, "Couldn't create preview image!"
        return None

    return epsPreviewImage
示例#7
0
def DispatchDrawing(context, drawingType):
    """ Drawing dispatcher """
    if drawingType == UIHandling.kHICommandSimpleRect:
        DrawingBasics.doSimpleRect(context)

    elif drawingType == UIHandling.kHICommandStrokedRect:
        DrawingBasics.doStrokedRect(context)

    elif drawingType == UIHandling.kHICommandStrokedAndFilledRect:
        DrawingBasics.doStrokedAndFilledRect(context)

    elif drawingType == UIHandling.kHICommandPathRects:
        DrawingBasics.doPathRects(context)

    elif drawingType == UIHandling.kHICommandAlphaRects:
        DrawingBasics.doAlphaRects(context)

    elif drawingType == UIHandling.kHICommandDashed:
        DrawingBasics.doDashedLines(context)

    elif drawingType == UIHandling.kHICommandSimpleClip:
        DrawingBasics.doClippedCircle(context)

    elif drawingType == UIHandling.kHICommandPDFDoc:
        callPDFDrawProc(context, DrawingBasics.doPDFDocument, kCatPDF)

    elif drawingType == UIHandling.kHICommandRotatedEllipses:
        CoordinateSystem.doRotatedEllipses(context)

    elif drawingType == UIHandling.kHICommandDrawSkewCoordinates:
        CoordinateSystem.drawSkewedCoordinateSystem(context)

    elif drawingType == UIHandling.kHICommandBezierEgg:
        PathDrawing.doEgg(context)

    elif drawingType == UIHandling.kHICommandRoundedRects:
        PathDrawing.doRoundedRects(context)

    elif drawingType == UIHandling.kHICommandStrokeWithCTM:
        PathDrawing.doStrokeWithCTM(context)

    elif drawingType == UIHandling.kHICommandRotatedEllipsesWithCGPath:
        PathDrawing.doRotatedEllipsesWithCGPath(context)

    elif drawingType == UIHandling.kHICommandPixelAligned:
        PathDrawing.doPixelAlignedFillAndStroke(context)

    elif drawingType == UIHandling.kHICommandDeviceFillAndStrokeColor:
        ColorAndGState.doColorSpaceFillAndStroke(context)

    elif drawingType == UIHandling.kHICommandCLUTDrawGraphics:
        ColorAndGState.doIndexedColorDrawGraphics(context)

    elif drawingType == UIHandling.kHICommandDrawWithGlobalAlpha:
        ColorAndGState.drawWithGlobalAlpha(context)

    elif drawingType == UIHandling.kHICommandDrawWithBlendMode:
        callPDFDrawProc(context, ColorAndGState.drawWithColorBlendMode,
                        kPDFForBlendMode)

    elif drawingType == UIHandling.kHICommandDrawWithColorRefs:
        ColorAndGState.drawWithColorRefs(context)

    elif drawingType == UIHandling.kHICommandFunctionsHaveOwnGSave:
        ColorAndGState.doClippedEllipse(context)

    elif drawingType == UIHandling.kHICommandDrawJPEGImage:
        doDrawJPEGFile(context)

    elif drawingType == UIHandling.kHICommandColorImageFromFile:
        doRawImageFileWithURL(context)

    elif drawingType == UIHandling.kHICommandColorImageFromData:
        Images.doColorRampImage(context)

    elif drawingType == UIHandling.kHICommandColorImageFromCallbacks:
        doRawImageFileWithCallbacks(context)

    elif drawingType == UIHandling.kHICommandGrayRamp:
        Images.doGrayRamp(context)

    elif drawingType == UIHandling.kHICommandDrawWithCGImageSource:
        doDrawImageWithCGImageSource(context)

    elif drawingType == UIHandling.kHICommandDrawWithCGImageSourceIncremental:
        doIncrementalImage(context)

    elif drawingType == UIHandling.kHICommandDrawWithQuickTime:
        doQTImage(context)

    elif drawingType == UIHandling.kHICommandSubstituteImageProfile:
        doJPEGDocumentWithMultipleProfiles(context)

    elif drawingType == UIHandling.kHICommandDoSubImage:
        Images.doColorRampSubImage(context)

    elif drawingType == UIHandling.kHICommandExportWithQuickTime:
        Images.exportColorRampImageWithQT(context)

    elif drawingType == UIHandling.kHICommandMaskTurkeyImage:
        ImageMasking.doOneBitMaskImages(context)

    elif drawingType == UIHandling.kHICommandImageMaskedWithMask:
        doMaskImageWithMask(context)

    elif drawingType == UIHandling.kHICommandImageMaskedWithGrayImage:
        doMaskImageWithGrayImage(context)

    elif drawingType == UIHandling.kHICommandMaskImageWithColor:
        doImageMaskedWithColor(context)

    elif drawingType == UIHandling.kHICommandClipToMask:
        doClipMask(context)

    elif drawingType == UIHandling.kHICommandExportWithCGImageDestination:
        exportImageMaskedWithImage(context)

    elif drawingType == UIHandling.kHICommandSimpleCGLayer:
        BitmapContext.doSimpleCGLayer(context)

    elif drawingType == UIHandling.kHICommandAlphaOnlyContext:
        BitmapContext.doAlphaOnlyContext(context)

    elif drawingType == UIHandling.kHICommandDrawNoOffScreenImage:
        tilePDFDocument(context, noOffScreen)

    elif drawingType == UIHandling.kHICommandDrawOffScreenImage:
        tilePDFDocument(context, bitmapOffScreen)

    elif drawingType == UIHandling.kHICommandDrawWithLayer:
        tilePDFDocument(context, layerOffScreen)

    elif drawingType == UIHandling.kHICommandQuartzRomanText:
        QuartzTextDrawing.drawQuartzRomanText(context)

    elif drawingType == UIHandling.kHICommandQuartzTextModes:
        QuartzTextDrawing.drawQuartzTextWithTextModes(context)

    elif drawingType == UIHandling.kHICommandQuartzTextMatrix:
        QuartzTextDrawing.drawQuartzTextWithTextMatrix(context)

    elif drawingType == UIHandling.kHICommandSimplePattern:
        PatternDrawing.doRedBlackCheckerboard(context)

    elif drawingType == UIHandling.kHICommandPatternPhase:
        PatternDrawing.doPatternPhase(context)

    elif drawingType == UIHandling.kHICommandPatternMatrix:
        PatternDrawing.doPatternMatrix(context)

    elif drawingType == UIHandling.kHICommandUncoloredPattern:
        PatternDrawing.doStencilPattern(context)

    elif drawingType == UIHandling.kHICommandDrawWithPDFPattern:
        callPDFDrawProc(context, PatternDrawing.drawWithPDFPattern, kCatPDF)

    elif drawingType == UIHandling.kHICommandSimpleShadow:
        ShadowsAndTransparencyLayers.drawSimpleShadow(context)

    elif drawingType == UIHandling.kHICommandShadowScaling:
        ShadowsAndTransparencyLayers.doShadowScaling(context)

    elif drawingType == UIHandling.kHICommandShadowProblems:
        ShadowsAndTransparencyLayers.showComplexShadowIssues(context)

    elif drawingType == UIHandling.kHICommandComplexShadow:
        ShadowsAndTransparencyLayers.showComplexShadow(context)

    elif drawingType == UIHandling.kHICommandMultipleShapeComposite:
        ShadowsAndTransparencyLayers.doLayerCompositing(context)

    elif drawingType == UIHandling.kHICommandFillAndStrokeWithShadow:
        ShadowsAndTransparencyLayers.drawFillAndStrokeWithShadow(context)

    elif drawingType == UIHandling.kHICommandPDFDocumentShadow:
        callPDFDrawProc(context,
                        ShadowsAndTransparencyLayers.shadowPDFDocument,
                        kCatPDF)

    elif drawingType == UIHandling.kHICommandSimpleAxialShading:
        Shadings.doSimpleAxialShading(context)

    elif drawingType == UIHandling.kHICommandExampleAxialShadings:
        Shadings.doExampleAxialShading(context)

    elif drawingType == UIHandling.kHICommandSimpleRadialShading:
        Shadings.doSimpleRadialShading(context)

    elif drawingType == UIHandling.kHICommandExampleRadialShadings:
        Shadings.doExampleRadialShadings(context)

    elif drawingType == UIHandling.kHICommandEllipseShading:
        Shadings.doEllipseShading(context)

    elif drawingType == UIHandling.kHICommandDoCompatibleEPS:
        doCompatibleEPSDrawing(context)