Ejemplo n.º 1
0
void CGContextDrawLayerInRect(CGContextRef context, CGRect rect, CGLayerRef layer)
{
	QPainter* painter = CGContextGetPainter(context);
	QTransform tf = painter->worldTransform();
	qreal sx, sy;
	CGSize origSize = CGLayerGetSize(layer);
	
	sx = CGRectGetWidth(rect) / origSize.width;
	sy = CGRectGetHeight(rect) / origSize.height;
	
	painter->scale(sx, sy);
	
	painter->drawPicture(QPointF(rect.origin.x / sx, rect.origin.y / sy), *layer->picture);
	
	painter->setWorldTransform(tf);
}
void doSimpleCGLayer(CGContextRef context)
{
    int i,j;
    CGSize s;
    // Create the layer.
    CGLayerRef layer = createCGLayerForDrawing(context);
    if(layer == NULL){
		fprintf(stderr, "Couldn't create layer!\n");
		return;
    }
    
    // Get the size of the layer created.
    s = CGLayerGetSize(layer);
    
    // Clip to a rect that corresponds to
    // a grid of 8x8 layer objects.
    CGContextClipToRect(context, CGRectMake(0, 0, 8*s.width, 8*s.height));
    
    // Paint 8 rows of layer objects.
    for(j = 0 ; j < 8 ; j++){
		CGContextSaveGState(context);
			// Paint 4 columns of layer objects, moving
			// across the drawing canvas by skipping a
			// square on the grid each time across.
			for(i = 0 ; i < 4 ; i++){
				// Draw the layer at the current origin.
				CGContextDrawLayerAtPoint(context, 
					CGPointZero, 
					layer);
				// Translate across two layer widths.
				CGContextTranslateCTM(context, 2*s.width, 0);
			}
		CGContextRestoreGState(context);
		// Translate to the left one layer width on
		// even loop counts and to the right one
		// layer width on odd loop counts. Each
		// time through the outer loop, translate up
		// one layer height.
		CGContextTranslateCTM(context, 
			(j % 2) ? s.width: -s.width, 
			s.height);
    }
    // Release the layer when done drawing with it.
    CGLayerRelease(layer);
}
void TilePDFWithCGLayer(CGContextRef context, CFURLRef url)
{
    // Again this should really be computed based on
    // the area intended to be tiled.
    float fillwidth = 612., fillheight = 792.;
    CGSize s;
    float tileX, tileY, tileOffsetX, tileOffsetY;
    float w, h;
    CGLayerRef layer = createLayerWithImageForContext(context, url);
    if(layer == NULL){
	    fprintf(stderr, "Couldn't create the layer!\n");
	    return;
    }
    
    // Compute the tile size and offset.
    s = CGLayerGetSize(layer);
    tileX = s.width;
    tileY = s.height;

#if DOSCALING
    // Space the tiles by the tile width and height
    // plus an extra 2 units in each dimension.
    tileOffsetX = 2. + tileX;
    tileOffsetY = 2. + tileY;
#else
	// Add 6 units to the offset in each direction
	// if there is no scaling of the source PDF document.
    tileOffsetX = 6. + tileX;
    tileOffsetY = 6. + tileY;
#endif

    // Now draw the contents of the layer to the context.
    // The layer is drawn at its true size (the size of
    // the tile) with its origin located at the corner
    // of each tile.
    for(h = 0; h < fillheight ; h += tileOffsetY)
		for(w = 0; w < fillwidth ; w += tileOffsetX){
			CGContextDrawLayerAtPoint(context, CGPointMake(w, h), layer);
		}
    
    // Release the layer when done drawing with it.
    CGLayerRelease(layer);
}
Ejemplo n.º 4
0
float CGLayerHeight_wrap(CGLayer* la) {
  return CGLayerGetSize(la).height;
}  
Ejemplo n.º 5
0
float CGLayerWidth_wrap(CGLayer* la) {
  return CGLayerGetSize(la).width;
}