Exemple #1
0
//-----------------------------------------------------------------------------
void CGDrawContext::init ()
{
	CGContextSaveGState (cgContext);
	CGContextSetShouldAntialias (cgContext, false);
	CGContextSetFillColorSpace (cgContext, GetCGColorSpace ());
	CGContextSetStrokeColorSpace (cgContext, GetCGColorSpace ()); 
	CGContextSaveGState (cgContext);
	CGAffineTransform cgCTM = CGAffineTransformMake (1.0, 0.0, 0.0, -1.0, 0.0, 0.0);
	CGContextSetTextMatrix (cgContext, cgCTM);

	CDrawContext::init ();
}
Exemple #2
0
//-----------------------------------------------------------------------------
CGContextRef CGBitmap::createCGContext ()
{
	CGContextRef context = 0;
	if (bits == 0)
	{
		allocBits ();
		if (imageSource)
			getCGImage ();
		if (image)
		{
			context = createCGContext ();
			if (context)
			{
				CGContextScaleCTM (context, 1, -1);
				CGContextDrawImage (context, CGRectMake (0, -size.y, size.x, size.y), image);
				CGContextScaleCTM (context, 1, -1);
				return context;
			}
		}
	}
	if (bits)
	{
		CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big;
		context = CGBitmapContextCreate (bits,
						size.x,
						size.y,
						8,
						getBytesPerRow (),
						GetCGColorSpace (),
						bitmapInfo);
		CGContextTranslateCTM (context, 0, (CGFloat)size.y);
		CGContextScaleCTM (context, 1, -1);
	}
	return context;
}
Exemple #3
0
//-----------------------------------------------------------------------------
CGImageRef CGBitmap::getCGImage ()
{
	if (image == 0 && imageSource)
	{
		const void* keys[] = {kCGImageSourceShouldCache, kCGImageSourceShouldPreferRGB32};
		const void* values[] = {kCFBooleanTrue, kCFBooleanTrue};
		CFDictionaryRef options = CFDictionaryCreate (NULL, keys, values, 2, NULL, NULL);
		image = CGImageSourceCreateImageAtIndex (imageSource, 0, options);
		CFRelease (imageSource);
		CFRelease (options);
		imageSource = 0;
	}
	if ((dirty || image == 0) && bits)
	{
		freeCGImage ();

		size_t rowBytes = getBytesPerRow ();
		size_t byteCount = rowBytes * size.y;
		size_t bitDepth = 32;

		CGDataProviderRef provider = CGDataProviderCreateWithData (NULL, bits, byteCount, NULL);
		CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big;
		image = CGImageCreate (size.x, size.y, 8, bitDepth, rowBytes, GetCGColorSpace (), bitmapInfo, provider, NULL, false, kCGRenderingIntentDefault);
		CGDataProviderRelease (provider);
		dirty = false;
	}
	return image;
}
Exemple #4
0
//-----------------------------------------------------------------------------
void CGDrawContext::init ()
{
    CGContextSaveGState (cgContext);
    CGContextSetAllowsAntialiasing (cgContext, true);
    CGContextSetAllowsFontSmoothing (cgContext, true);
    CGContextSetAllowsFontSubpixelPositioning (cgContext, true);
    CGContextSetAllowsFontSubpixelQuantization (cgContext, true);
    CGContextSetShouldAntialias (cgContext, false);
    CGContextSetFillColorSpace (cgContext, GetCGColorSpace ());
    CGContextSetStrokeColorSpace (cgContext, GetCGColorSpace ());
    CGContextSaveGState (cgContext);
    CGAffineTransform cgCTM = CGAffineTransformMake (1.0, 0.0, 0.0, -1.0, 0.0, 0.0);
    CGContextSetTextMatrix (cgContext, cgCTM);

    CDrawContext::init ();
}
Exemple #5
0
//-----------------------------------------------------------------------------
CGColorRef getCGColor (const CColor& color)
{
	CGColorMap& colorMap = getColorMap ();
	CGColorMap::const_iterator it = colorMap.find (color);
	if (it != colorMap.end ())
	{
		CGColorRef result = it->second;
		return result;
	}
	const CGFloat components[] = {
		static_cast<CGFloat> (color.red / 255.),
		static_cast<CGFloat> (color.green / 255.),
		static_cast<CGFloat> (color.blue / 255.),
		static_cast<CGFloat> (color.alpha / 255.)
	};
	CGColorRef result = CGColorCreate (GetCGColorSpace (), components);
	colorMap.insert (std::make_pair (color, result));
	return result;
}