Пример #1
0
def createSequentialAccessDPForURL(url):
    success, pathString = Cocoa.CFURLGetFileSystemRepresentation(url, True, None, 1024)
    pathString = pathString.rstrip(b"\0")
    if not success:
        print("Couldn't get the path name C string!")
        return None

    fp = open(pathString, "rb")
    if fp is None:
        print("Couldn't open path to file %s!" % (pathString,))
        return None

    imageDataInfoP = MyImageDataInfo()
    imageDataInfoP.fp = fp

    provider = Quartz.CGDataProviderCreate(
        imageDataInfoP,
        (
            getBytesSequentialAccessDP,
            skipBytesSequentialAccessDP,
            rewindSequentialAccessDP,
            releaseSequentialAccessDP,
        ),
    )
    if provider is None:
        print("Couldn't create data provider!")
        # Release the info data and cleanup.
        releaseSequentialAccessDP(imageDataInfoP)
        return None

    return provider
Пример #2
0
def createMyIncrementalDataFromURL(url, myDataP):
    myDataP.data = None
    myDataP.dataSize = 0
    myDataP.repCount = 0

    success, pathString = Cocoa.CFURLGetFileSystemRepresentation(
        url, True, None, 1024)
    pathString = pathString.rstrip(b"\0")

    if success and len(pathString):
        fp = open(pathString, "rb")
        myDataP.data = fp.read()
        fp.close()
        myDataP.dataSize = len(myDataP.data)

    if myDataP.dataSize > 0:
        myDataP.chunkSize = myDataP.dataSize / 10  # 10 chunks
Пример #3
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