Exemple #1
0
def doAlphaOnlyContext(context):
    # This code is going to capture the alpha coverage
    # of the drawing done by the doAlphaRects routine.
    # The value passed here as the width and height is
    # the size of the bounding rectangle of that drawing.
    width = 520
    height = 400
    alphaContext = createAlphaOnlyContext(width, height)
    if context is None:
        print("Couldn't create the alpha-only context!")
        return

    # Draw the content to the alpha-only context, capturing
    # the alpha coverage. The doAlphaRects routine paints
    # a series of translucent red rectangles.
    DrawingBasics.doAlphaRects(alphaContext)

    # Finished drawing to the context and now the raster contains
    # the alpha data captured from the drawing. Create
    # the mask from the data in the context.
    mask = createMaskFromAlphaOnlyContext(alphaContext)
    # This code is now finshed with the context so it can
    # release it.
    del alphaContext

    if mask is None:
        return

    # Set the fill color space.
    Quartz.CGContextSetFillColorSpace(
        context, Utilities.getTheCalibratedRGBColorSpace()
    )
    opaqueBlue = (0.11, 0.208, 0.451, 1.0)
    # Set the painting color to opaque blue.
    Quartz.CGContextSetFillColor(context, opaqueBlue)
    # Draw the mask, painting the mask with blue. This colorizes
    # the image to blue and it is as if we painted the
    # alpha rects with blue instead of red.
    Quartz.CGContextDrawImage(context, Quartz.CGRectMake(0, 0, width, height), mask)
Exemple #2
0
def doAlphaOnlyContext(context):
    # This code is going to capture the alpha coverage
    # of the drawing done by the doAlphaRects routine.
    # The value passed here as the width and height is
    # the size of the bounding rectangle of that drawing.
    width = 520
    height = 400
    alphaContext = createAlphaOnlyContext(width, height);
    if context is None:
        print >>sys.stderr, "Couldn't create the alpha-only context!"
        return

    # Draw the content to the alpha-only context, capturing
    # the alpha coverage. The doAlphaRects routine paints
    # a series of translucent red rectangles.
    DrawingBasics.doAlphaRects(alphaContext)

    # Finished drawing to the context and now the raster contains
    # the alpha data captured from the drawing. Create
    # the mask from the data in the context.
    mask = createMaskFromAlphaOnlyContext(alphaContext);
    # This code is now finshed with the context so it can
    # release it.
    del alphaContext
    
    if mask is None:
        return

    # Set the fill color space.
    CGContextSetFillColorSpace(context, Utilities.getTheCalibratedRGBColorSpace());
    opaqueBlue = ( 0.11, 0.208, 0.451, 1.0 )
    # Set the painting color to opaque blue.
    CGContextSetFillColor(context, opaqueBlue);
    # Draw the mask, painting the mask with blue. This colorizes
    # the image to blue and it is as if we painted the
    # alpha rects with blue instead of red.
    CGContextDrawImage(context, CGRectMake(0, 0, width, height), mask);
Exemple #3
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)
Exemple #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)