Exemple #1
0
	//-----------------------------------------------------------------------------
	static CGColorSpaceRef CreateMainDisplayColorSpace ()
	{
	#if TARGET_OS_IPHONE
		return CGColorSpaceCreateDeviceRGB ();

	#elif MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
		ColorSyncProfileRef csProfileRef = ColorSyncProfileCreateWithDisplayID (0);
		if (csProfileRef)
		{
			CGColorSpaceRef colorSpace = CGColorSpaceCreateWithPlatformColorSpace (csProfileRef);
			CFRelease (csProfileRef);
			return colorSpace;
		}
		return 0;
	#else
		CMProfileRef sysprof = NULL;

		// Get the Systems Profile for the main display
		if (CMGetSystemProfile (&sysprof) == noErr)
		{
			// Create a colorspace with the systems profile
			CGColorSpaceRef colorSpace = CGColorSpaceCreateWithPlatformColorSpace (sysprof);

			// Close the profile
			CMCloseProfile (sysprof);
			return colorSpace;
		}
		return 0;
	#endif
	}
Exemple #2
0
CGColorRef createCGColor(const Color& c)
{
    CGColorRef color = NULL;
    CMProfileRef prof = NULL;
    CMGetSystemProfile(&prof);

    RetainPtr<CGColorSpaceRef> rgbSpace(AdoptCF, CGColorSpaceCreateWithPlatformColorSpace(prof));

    if (rgbSpace) {
        CGFloat components[4] = { static_cast<CGFloat>(c.red()) / 255, static_cast<CGFloat>(c.green()) / 255,
                                  static_cast<CGFloat>(c.blue()) / 255, static_cast<CGFloat>(c.alpha()) / 255 };
        color = CGColorCreate(rgbSpace.get(), components);
    }

    CMCloseProfile(prof);

    return color;
}
Exemple #3
0
OSStatus DrawPage(PrintingLogicPtr printJob,CGContextRef printingContext)
{
    OSStatus status = noErr; 
    Rect	dstRect = { 0, 0, 0, 0 };
    Rect	srcRect = { 0, 0, 0, 0 };
	static CGColorSpaceRef colorspace = NULL;

	if (colorspace == NULL) {
			// Get the Systems Profile for the main display
		CMProfileRef sysprof = NULL;
		if (CMGetSystemProfile(&sysprof) == noErr) {
			// Create a colorspace with the systems profile
			colorspace = CGColorSpaceCreateWithPlatformColorSpace(sysprof);
			CMCloseProfile(sysprof);
		} else 
			colorspace = CGColorSpaceCreateDeviceRGB();
	}
    
		dstRect.top = printJob->offsetHeight;
        dstRect.left = printJob->offsetWidth;
        dstRect.right = printJob->width*printJob->scaleW + printJob->offsetWidth;
        dstRect.bottom = printJob->height*printJob->scaleH + printJob->offsetHeight;

	if (printJob->formBitMap != nil) {
    
        srcRect.right = printJob->width;
        srcRect.bottom = printJob->height;

        HLock((Handle)stPixMap);
        (*stPixMap)->baseAddr = (void *) printJob->formBitMap;
        (*stPixMap)->rowBytes = (((((printJob->width * printJob->depth) + 31) / 32) * 4) & 0x1FFF) | 0x8000;
        (*stPixMap)->bounds = srcRect;
        (*stPixMap)->pixelSize = printJob->depth;
    
        if (printJob->depth<=8) { 
            (*stPixMap)->cmpSize = printJob->depth;
            (*stPixMap)->cmpCount = 1;
        } else if (printJob->depth==16) {
            (*stPixMap)->cmpSize = 5;
            (*stPixMap)->cmpCount = 3;
        } else if (printJob->depth==32) {
            (*stPixMap)->cmpSize = 8;
            (*stPixMap)->cmpCount = 3;
        }

         
		{
            PixMapHandle thePix;
            int			pitch;
			CGDataProviderRef provider;			
			CGImageRef image;
			CGRect		clip;
			Ptr			baseAddr;
			
            if (printJob->depth == 32) {
				pitch =  (((((printJob->width * printJob->depth) + 31) / 32) * 4) & 0x1FFF);
				baseAddr =  (void *) printJob->formBitMap;
			} else {
				if (printJob->aGWorld == NULL)
					NewGWorld(&printJob->aGWorld, 32, &srcRect, stColorTable, NULL, keepLocal+useTempMem+pixelsLocked);
					
				thePix = GetGWorldPixMap (printJob->aGWorld);
				CopyBits((BitMap *) *stPixMap, (BitMap *) *thePix, &srcRect, &srcRect, srcCopy, NULL);
				
				pitch = GetPixRowBytes(thePix);
				baseAddr = GetPixBaseAddr(thePix);
			}
			
			provider = CGDataProviderCreateDirectAccess((void*)baseAddr, pitch * (srcRect.bottom-srcRect.top), &gProviderCallbacks);
			image = CGImageCreate( srcRect.right-srcRect.left, srcRect.bottom-srcRect.top, 8 /* bitsPerComponent */, 32 /* bitsPerPixel */, 
				pitch, colorspace, kCGImageAlphaNoneSkipFirst | (printJob->depth==32 ? kCGBitmapByteOrder32Host : 0), provider, NULL, 0, kCGRenderingIntentDefault);

			clip = CGRectMake(dstRect.left+(printJob->pageRect.left-printJob->paperRect.left),
				(printJob->paperRect.bottom-printJob->pageRect.bottom) + (printJob->pageRect.bottom - printJob->pageRect.top) - (dstRect.bottom-dstRect.top) - dstRect.top, 
				dstRect.right-dstRect.left, 
				dstRect.bottom-dstRect.top);
			
			CGContextDrawImage(printingContext, clip, image);
			CGContextFlush(printingContext);
			CGImageRelease(image);
			CGDataProviderRelease(provider);
       }
        HUnlock((Handle)stPixMap);
    }
	else {
	}
	
#if TARGET_API_MAC_CARBON	
     if (printJob->allowPostscript && printJob->postscriptLength > 0) {
	
		CGDataProviderRef provider,providerFakeImage;			
		CGImageRef image,imageFake;
		CGRect		clip;
		static long  dirt=0xBBBBBBBB;
		
		//PMPrinter  currentPrinter = NULL;
		//CFArrayRef mimeTypes;
		//status = PMSessionGetCurrentPrinter(printJob->printSession,&currentPrinter);
		//status = PMPrinterGetMimeTypes(currentPrinter,printJob->printSettings,&mimeTypes);
 		
		provider = CGDataProviderCreateDirectAccess((void*)printJob->postscript,printJob->postscriptLength, &gProviderCallbacks);
		providerFakeImage = CGDataProviderCreateDirectAccess((void*)&dirt,4, &gProviderCallbacks);
		
		//OK make fake image using tiny bit of data
		imageFake = CGImageCreate(1, 1, 8 /* bitsPerComponent */, 32 /* bitsPerPixel */, 4, colorspace, kCGImageAlphaNoneSkipFirst , providerFakeImage, NULL, 0, kCGRenderingIntentDefault);
		image = PMCGImageCreateWithEPSDataProvider(provider,imageFake);


		dstRect.top = 0;
		dstRect.left = 0;
		dstRect.bottom = CGImageGetHeight(image);
		dstRect.right = CGImageGetWidth(image);
		
		clip = CGRectMake(dstRect.left+(printJob->pageRect.left-printJob->paperRect.left),
			(printJob->paperRect.bottom-printJob->pageRect.bottom) + (printJob->pageRect.bottom - printJob->pageRect.top) - (dstRect.bottom-dstRect.top) - dstRect.top, 
			dstRect.right-dstRect.left, 
			dstRect.bottom-dstRect.top); 
			
		//PMPrinterPrintWithProvider
		
		CGContextDrawImage(printingContext, clip, image);
		CGContextFlush(printingContext);
		CGImageRelease(image);
		CGImageRelease(imageFake);
		CGDataProviderRelease(provider);
		CGDataProviderRelease(providerFakeImage);
    }   
#else
	return PrError();
#endif
		
    return status;
}	//	DrawPage