Exemplo n.º 1
0
static void initializeSupportedImageMIMETypesForEncoding()
{
    supportedImageMIMETypesForEncoding = new HashSet<String>;

#if PLATFORM(CG)
#if PLATFORM(MAC)
    RetainPtr<CFArrayRef> supportedTypes(AdoptCF, CGImageDestinationCopyTypeIdentifiers());
    CFIndex count = CFArrayGetCount(supportedTypes.get());
    for (CFIndex i = 0; i < count; i++) {
        RetainPtr<CFStringRef> supportedType(AdoptCF, reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(supportedTypes.get(), i)));
        String mimeType = MIMETypeForImageSourceType(supportedType.get());
        if (!mimeType.isEmpty())
            supportedImageMIMETypesForEncoding->add(mimeType);
    }
#else
    // FIXME: Add Windows support for all the supported UTI's when a way to convert from MIMEType to UTI reliably is found.
    // For now, only support PNG, JPEG and GIF.  See <rdar://problem/6095286>.
    supportedImageMIMETypesForEncoding->add("image/png");
    supportedImageMIMETypesForEncoding->add("image/jpeg");
    supportedImageMIMETypesForEncoding->add("image/gif");
#endif
#elif PLATFORM(QT)
    QList<QByteArray> formats = QImageWriter::supportedImageFormats();
    for (int i = 0; i < formats.size(); ++i) {
        String mimeType = MIMETypeRegistry::getMIMETypeForExtension(formats.at(i).constData());
        supportedImageMIMETypesForEncoding->add(mimeType);
    }

    supportedImageMIMETypesForEncoding->remove("application/octet-stream");
#elif PLATFORM(CAIRO)
    supportedImageMIMETypesForEncoding->add("image/png");
#endif
}
Exemplo n.º 2
0
static void initializeSupportedImageMIMETypesForEncoding()
{
    supportedImageMIMETypesForEncoding = new HashSet<String>;

#if PLATFORM(CG)
#if PLATFORM(MAC)
    RetainPtr<CFArrayRef> supportedTypes(AdoptCF, CGImageDestinationCopyTypeIdentifiers());
    CFIndex count = CFArrayGetCount(supportedTypes.get());
    for (CFIndex i = 0; i < count; i++) {
        RetainPtr<CFStringRef> supportedType(AdoptCF, reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(supportedTypes.get(), i)));
        String mimeType = getMIMETypeForUTI(supportedType.get());
        if (!mimeType.isEmpty())
            supportedImageMIMETypesForEncoding->add(mimeType);
    }
#else
    // FIXME: Add Windows support for all the supported UTI's when a way to convert from MIMEType to UTI reliably is found.
    // For now, only support PNG, the minimum that the spec requires.
    supportedImageMIMETypesForEncoding->add("image/png");
#endif
#elif PLATFORM(QT)
    QList<QByteArray> formats = QImageWriter::supportedImageFormats();
    for (size_t i = 0; i < formats.size(); ++i) {
        String mimeType = MIMETypeRegistry::getMIMETypeForExtension(formats.at(i).constData());
        supportedImageMIMETypesForEncoding->add(mimeType);
    }
#endif
}
Exemplo n.º 3
0
static void initializeSupportedImageMIMETypesForEncoding()
{
    supportedImageMIMETypesForEncoding = new HashSet<String>;

#if USE(CG)
#if PLATFORM(MAC)
    RetainPtr<CFArrayRef> supportedTypes = adoptCF(CGImageDestinationCopyTypeIdentifiers());
    CFIndex count = CFArrayGetCount(supportedTypes.get());
    for (CFIndex i = 0; i < count; i++) {
        CFStringRef supportedType = reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(supportedTypes.get(), i));
        String mimeType = MIMETypeForImageSourceType(supportedType);
        if (!mimeType.isEmpty())
            supportedImageMIMETypesForEncoding->add(mimeType);
    }
#else
    // FIXME: Add Windows support for all the supported UTI's when a way to convert from MIMEType to UTI reliably is found.
    // For now, only support PNG, JPEG and GIF.  See <rdar://problem/6095286>.
    supportedImageMIMETypesForEncoding->add("image/png");
    supportedImageMIMETypesForEncoding->add("image/jpeg");
    supportedImageMIMETypesForEncoding->add("image/gif");
#endif
#elif PLATFORM(GTK)
    supportedImageMIMETypesForEncoding->add("image/png");
    supportedImageMIMETypesForEncoding->add("image/jpeg");
    supportedImageMIMETypesForEncoding->add("image/tiff");
    supportedImageMIMETypesForEncoding->add("image/bmp");
    supportedImageMIMETypesForEncoding->add("image/ico");
#elif USE(CAIRO)
    supportedImageMIMETypesForEncoding->add("image/png");
#elif PLATFORM(BLACKBERRY)
    supportedImageMIMETypesForEncoding->add("image/png");
    supportedImageMIMETypesForEncoding->add("image/jpeg");
#endif
}
Exemplo n.º 4
0
QuartzDesc_t QuartzBitmap_DeviceCreate(void *dd, QuartzFunctions_t *fn, QuartzParameters_t *par)
{
    /* In the case of a zero length string we default to PNG presently. This
       should probably be an option somewhere. */
    double *dpi = par->dpi;
    double width = par->width, height = par->height;
    const char *type = par->type;
    double mydpi[2] = { 72.0, 72.0 }; /* fall-back to 72dpi if none was specified */
    QuartzDesc_t ret = NULL;
    if (!qf) qf = fn;
    if(!type || strlen(type) == 0) type = "public.png";
    if (!dpi) dpi=mydpi;

#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
    /* We'll gladly support any image destination type */
    CFArrayRef  types = CGImageDestinationCopyTypeIdentifiers();
    CFStringRef mine  = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8*) type, strlen(type), kCFStringEncodingUTF8, FALSE);
    if(CFArrayContainsValue(types,CFRangeMake(0, CFArrayGetCount(types)), mine)) {
        size_t w = (size_t) (dpi[0] * width);
        size_t h = (size_t) (dpi[1] * height);
        size_t rb= (w*8*4+7)/8; /* Bytes per row */
        size_t s = h*rb;
        /* QuartzDesc_t qd; */
        /* Allocate sufficient space */
	/* FIXME: check allocations */
        QuartzBitmapDevice *dev = malloc(sizeof(QuartzBitmapDevice)+s);
        dev->length = (unsigned int) s;
        dev->uti  = type ? strdup(type) : NULL;
        dev->path = par->file ? strdup(par->file) : NULL;
        dev->page = 0;
        memset(dev->data, 0, s);
        dev->bitmap = CGBitmapContextCreate(dev->data, w, h, 8, rb,
					    CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB),
					    kCGImageAlphaPremultipliedLast);
	/* bitmaps use flipped coordinates (top-left is the origin), so we need to pre-set CTM. */
	CGContextTranslateCTM(dev->bitmap, 0.0, height * dpi[1]);
	CGContextScaleCTM(dev->bitmap, 1.0, -1.0);
	QuartzBackend_t qdef = {
	    sizeof(qdef), width, height, dpi[0]/72.0 , dpi[1]/72.0, par->pointsize,
	    par->bg, par->canvas, par->flags | QDFLAG_RASTERIZED,
	    dev,
	    QuartzBitmap_GetCGContext,
	    NULL,	/* locate */
	    QuartzBitmap_Close,
	    QuartzBitmap_NewPage,
	    NULL,	/* state */
	    NULL,	/* par */
	    NULL,       /* sync */
	    NULL,       /* cap */
	};


	if (!(ret = qf->Create(dd, &qdef)))
            QuartzBitmap_Close(NULL, dev);
        else {
	    /* since this device is non-resizable we set the size right away (as opposed to on-display) */
	    qf->SetSize(ret, width, height);
	    /* tell Quartz to prepare our new context */
            qf->ResetContext(ret);
        }
    }
    CFRelease(mine);
    CFRelease(types);
#endif
    return ret;
}