GPrintDC::GPrintDC(void *Handle, const char *PrintJobName, const char *PrinterName) : GScreenDC((GPrintDcParams*)Handle) { d = new GPrintDCPrivate; d->PrintJobName = PrintJobName; d->PrinterName = PrinterName; GPrintDcParams *Params = (GPrintDcParams*)Handle; if (Params) { int x = Params->Page.right - Params->Page.left; int y = Params->Page.bottom - Params->Page.top; d->Dpi.x = Params->Dpi.hRes; d->Dpi.y = Params->Dpi.vRes; #if 0 d->x = x * d->Dpi.x; d->y = y * d->Dpi.y; #else d->x = x; d->y = y; #endif d->Ctx = Params->Ctx; // Invert the co-ordinate space so 0,0 is the top left corner. CGContextTranslateCTM(d->Ctx, 0, y); CGContextScaleCTM(d->Ctx, 1.0, -1.0); } }
wxBitmap wxScreenDCImpl::DoGetAsBitmap(const wxRect *subrect) const { CGRect srcRect = CGRectMake(0, 0, m_width, m_height); if (subrect) { srcRect.origin.x = subrect->GetX(); srcRect.origin.y = subrect->GetY(); srcRect.size.width = subrect->GetWidth(); srcRect.size.height = subrect->GetHeight(); } wxBitmap bmp = wxBitmap(srcRect.size.width, srcRect.size.height, 32); #if wxOSX_USE_IPHONE #else CGContextRef context = (CGContextRef)bmp.GetHBITMAP(); CGContextSaveGState(context); CGContextTranslateCTM( context, 0, m_height ); CGContextScaleCTM( context, 1, -1 ); if ( subrect ) srcRect = CGRectOffset( srcRect, -subrect->x, -subrect->y ) ; CGImageRef image = grabViaOpenGL(kCGNullDirectDisplay, srcRect); wxASSERT_MSG(image, wxT("wxScreenDC::GetAsBitmap - unable to get screenshot.")); CGContextDrawImage(context, srcRect, image); CGContextRestoreGState(context); #endif return bmp; }
static CGContextRef CGContextWithHDC(HDC hdc, bool hasAlpha) { HBITMAP bitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP)); DIBPixelData pixelData(bitmap); // FIXME: We can get here because we asked for a bitmap that is too big // when we have a tiled layer and we're compositing. In that case // bmBitsPixel will be 0. This seems to be benign, so for now we will // exit gracefully and look at it later: // https://bugs.webkit.org/show_bug.cgi?id=52041 // ASSERT(bitmapBits.bitsPerPixel() == 32); if (pixelData.bitsPerPixel() != 32) return 0; CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Little | (hasAlpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst); CGContextRef context = CGBitmapContextCreate(pixelData.buffer(), pixelData.size().width(), pixelData.size().height(), 8, pixelData.bytesPerRow(), deviceRGBColorSpaceRef(), bitmapInfo); // Flip coords CGContextTranslateCTM(context, 0, pixelData.size().height()); CGContextScaleCTM(context, 1, -1); // Put the HDC In advanced mode so it will honor affine transforms. SetGraphicsMode(hdc, GM_ADVANCED); return context; }
static void paintRepaintRectOverlay(CGContextRef context, WKImageRef image, WKArrayRef repaintRects) { WKSize imageSize = WKImageGetSize(image); CGContextSaveGState(context); // Using a transparency layer is easier than futzing with clipping. CGContextBeginTransparencyLayer(context, 0); // Flip the context. CGContextScaleCTM(context, 1, -1); CGContextTranslateCTM(context, 0, -imageSize.height); CGContextSetRGBFillColor(context, 0, 0, 0, static_cast<CGFloat>(0.66)); CGContextFillRect(context, CGRectMake(0, 0, imageSize.width, imageSize.height)); // Clear the repaint rects. size_t count = WKArrayGetSize(repaintRects); for (size_t i = 0; i < count; ++i) { WKRect rect = WKRectGetValue(static_cast<WKRectRef>(WKArrayGetItemAtIndex(repaintRects, i))); CGRect cgRect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); CGContextClearRect(context, cgRect); } CGContextEndTransparencyLayer(context); CGContextRestoreGState(context); }
wxBitmap wxScreenDCImpl::DoGetAsBitmap(const wxRect *subrect) const { wxRect rect = subrect ? *subrect : wxRect(0, 0, m_width, m_height); wxBitmap bmp(rect.GetSize(), 32); #if !wxOSX_USE_IPHONE CGRect srcRect = CGRectMake(rect.x, rect.y, rect.width, rect.height); CGContextRef context = (CGContextRef)bmp.GetHBITMAP(); CGContextSaveGState(context); CGContextTranslateCTM( context, 0, m_height ); CGContextScaleCTM( context, 1, -1 ); if ( subrect ) srcRect = CGRectOffset( srcRect, -subrect->x, -subrect->y ) ; CGImageRef image = grabViaOpenGL(kCGNullDirectDisplay, srcRect); wxASSERT_MSG(image, wxT("wxScreenDC::GetAsBitmap - unable to get screenshot.")); CGContextDrawImage(context, srcRect, image); CGImageRelease(image); CGContextRestoreGState(context); #else // TODO implement using UIGetScreenImage, CGImageCreateWithImageInRect, CGContextDrawImage #endif return bmp; }
wxMetafileRefData::wxMetafileRefData( int width, int height) { Init(); m_width = width; m_height = height; CGRect r = CGRectMake( 0 , 0 , width , height ); CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0); m_data.reset(data); CGDataConsumerRef dataConsumer = wxMacCGDataConsumerCreateWithCFData(data); m_context = CGPDFContextCreate( dataConsumer, (width != 0 && height != 0) ? &r : NULL , NULL ); CGDataConsumerRelease( dataConsumer ); if ( m_context ) { CGPDFContextBeginPage(m_context, NULL); CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace(); CGContextSetFillColorSpace( m_context, genericColorSpace ); CGContextSetStrokeColorSpace( m_context, genericColorSpace ); CGContextTranslateCTM( m_context , 0 , height ) ; CGContextScaleCTM( m_context , 1 , -1 ) ; } }
void GraphicsContext::translate(float x, float y) { if (paintingDisabled()) return; CGContextTranslateCTM(platformContext(), x, y); m_data->translate(x, y); }
wxWindowDCImpl::wxWindowDCImpl( wxDC *owner, wxWindow *window ) : wxGCDCImpl( owner ) { m_window = window; m_ok = true ; m_window->GetSize( &m_width , &m_height); if ( !m_window->IsShownOnScreen() ) m_width = m_height = 0; CGContextRef cg = (CGContextRef) window->MacGetCGContextRef(); m_release = false; if ( cg == NULL ) { SetGraphicsContext( wxGraphicsContext::Create( window ) ) ; } else { CGContextSaveGState( cg ); m_release = true ; // make sure the context is having its origin at the wx-window coordinates of the // view (read at the top of window.cpp about the differences) if ( window->MacGetLeftBorderSize() != 0 || window->MacGetTopBorderSize() != 0 ) CGContextTranslateCTM( cg , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ); SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) ); } DoSetClippingRegion( 0 , 0 , m_width , m_height ) ; SetBackground(wxBrush(window->GetBackgroundColour(),wxSOLID)); SetFont( window->GetFont() ) ; }
//----------------------------------------------------------------------------- void CGDrawContext::lineTo (const CPoint& point) { CGContextRef context = beginCGContext (true, currentState.drawMode.integralMode ()); if (context) { applyLineStyle (context); if ((((int32_t)currentState.frameWidth) % 2)) CGContextTranslateCTM (context, 0.5f, -0.5f); CGContextBeginPath (context); if (currentState.drawMode.integralMode ()) { CGContextMoveToPoint (context, round (currentState.penLoc.h), round (currentState.penLoc.v)); CGContextAddLineToPoint (context, round (point.h), round (point.v)); } else { CGContextMoveToPoint (context, currentState.penLoc.h, currentState.penLoc.v); CGContextAddLineToPoint (context, point.h, point.v); } CGContextDrawPath (context, kCGPathStroke); releaseCGContext (context); } currentState.penLoc = point; }
//----------------------------------------------------------------------------- void CGDrawContext::drawLines (const LineList& lines) { if (lines.size () == 0) return; CGContextRef context = beginCGContext (true, getDrawMode ().integralMode ()); if (context) { applyLineStyle (context); CGPoint* cgPoints = new CGPoint[lines.size () * 2]; uint32_t index = 0; VSTGUI_RANGE_BASED_FOR_LOOP(LineList, lines, LinePair, line) cgPoints[index] = CGPointFromCPoint (line.first); cgPoints[index+1] = CGPointFromCPoint (line.second); if (getDrawMode ().integralMode ()) { cgPoints[index] = pixelAlligned (cgPoints[index]); cgPoints[index+1] = pixelAlligned (cgPoints[index+1]); } index += 2; VSTGUI_RANGE_BASED_FOR_LOOP_END if (getDrawMode ().integralMode ()) { int32_t frameWidth = static_cast<int32_t> (currentState.frameWidth); if (frameWidth % 2) CGContextTranslateCTM (context, 0.5, 0.5); } CGContextStrokeLineSegments (context, cgPoints, lines.size () * 2); delete [] cgPoints; releaseCGContext (context); } }
static OSStatus HandleViewEvent( EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData ) { #pragma unused( inHandlerCallRef ) OSStatus err = eventNotHandledErr; DrawContextStruct *context = inUserData; verify_noerr( GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(CGContextRef), NULL, &context->cgContext) ); HIViewGetBounds(context->viewRef, &context->bounds); CGContextTranslateCTM(context->cgContext, 0, context->bounds.size.height); CGContextScaleCTM(context->cgContext, 1.0, -1.0); switch ( GetEventKind( inEvent ) ) { case kEventControlDraw: { // redraw the context DrawWindow( context->windowRef ); break; } default: break; }; return err; }
//----------------------------------------------------------------------------- void CGDrawContext::drawLine (const LinePair& line) { CGContextRef context = beginCGContext (true, getDrawMode ().integralMode ()); if (context) { applyLineStyle (context); CGContextBeginPath (context); CGPoint first = CGPointFromCPoint (line.first); CGPoint second = CGPointFromCPoint (line.second); if (getDrawMode ().integralMode ()) { first = pixelAlligned (first); second = pixelAlligned (second); int32_t frameWidth = static_cast<int32_t> (currentState.frameWidth); if (frameWidth % 2) CGContextTranslateCTM (context, 0.5, 0.5); } CGContextMoveToPoint (context, first.x, first.y); CGContextAddLineToPoint (context, second.x, second.y); CGContextDrawPath (context, kCGPathStroke); releaseCGContext (context); } }
void drawSkewedCoordinateSystem(CGContextRef context) { // alpha is 22.5 degrees and beta is 15 degrees. float alpha = M_PI/8, beta = M_PI/12; CGAffineTransform skew; // Create a rectangle that is 72 units on a side // with its origin at (0,0). CGRect r = CGRectMake(0, 0, 72, 72); CGContextTranslateCTM(context, 144, 144); // Draw the coordinate axes untransformed. drawCoordinateAxes(context); // Fill the rectangle. CGContextFillRect(context, r); // Create an affine transform that skews the coordinate system, // skewing the x-axis by alpha radians and the y-axis by beta radians. skew = CGAffineTransformMake(1, tan(alpha), tan(beta), 1, 0, 0); // Apply that transform to the context coordinate system. CGContextConcatCTM(context, skew); // Set the fill and stroke color to a dark blue. CGContextSetRGBStrokeColor(context, 0.11, 0.208, 0.451, 1); CGContextSetRGBFillColor(context, 0.11, 0.208, 0.451, 1); // Draw the coordinate axes again, now transformed. drawCoordinateAxes(context); // Set the fill color again but with a partially transparent alpha. CGContextSetRGBFillColor(context, 0.11, 0.208, 0.451, 0.7); // Fill the rectangle in the transformed coordinate system. CGContextFillRect(context, r); }
static double Quartz_StrWidth(char *str, R_GE_gcontext *gc, NewDevDesc *dd) { QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific; CGPoint position; CGContextSaveGState( GetContext(xd) ); CGContextTranslateCTM( GetContext(xd), 0, 0 ); CGContextScaleCTM( GetContext(xd), -1, 1); CGContextRotateCTM( GetContext(xd), -1.0 * 3.1416); CGContextSetTextDrawingMode( GetContext(xd), kCGTextInvisible ); Quartz_SetFont(gc->fontfamily, gc->fontface, gc->cex, gc->ps, dd); CGContextShowTextAtPoint( GetContext(xd), 0, 0, str, strlen(str) ); position = CGContextGetTextPosition( GetContext(xd) ); CGContextRestoreGState( GetContext(xd) ); return(position.x); }
bool wxMetaFile::Play(wxDC *dc) { if (!m_refData) return false; if (!dc->Ok() ) return false; { #if wxMAC_USE_CORE_GRAPHICS QDPictRef cgPictRef = M_METAFILEDATA->m_qdPictRef ; CGContextRef cg = ((wxMacCGContext*)(dc->GetGraphicContext()))->GetNativeContext() ; CGRect bounds = QDPictGetBounds( cgPictRef ) ; CGContextSaveGState(cg); CGContextTranslateCTM(cg, 0 , bounds.size.width ); CGContextScaleCTM(cg, 1, -1); QDPictDrawToCGContext( cg , bounds , cgPictRef ) ; CGContextRestoreGState( cg ) ; #else PicHandle pict = (PicHandle) GetHMETAFILE() ; wxMacPortSetter helper( dc ) ; DrawPicture( pict , &(**pict).picFrame ) ; #endif } return true; }
//----------------------------------------------------------------------------- void CGDrawContext::drawLines (const CPoint* points, const int32_t& numLines) { CGContextRef context = beginCGContext (true, currentState.drawMode.integralMode ()); if (context) { applyLineStyle (context); if ((((int32_t)currentState.frameWidth) % 2)) CGContextTranslateCTM (context, 0.5f, -0.5f); CGPoint* cgPoints = new CGPoint[numLines*2]; for (int32_t i = 0; i < numLines * 2; i += 2) { if (currentState.drawMode.integralMode ()) { cgPoints[i].x = round (points[i].x); cgPoints[i+1].x = round (points[i+1].x); cgPoints[i].y = round (points[i].y); cgPoints[i+1].y = round (points[i+1].y); } else { cgPoints[i].x = points[i].x; cgPoints[i+1].x = points[i+1].x; cgPoints[i].y = points[i].y; cgPoints[i+1].y = points[i+1].y; } } CGContextStrokeLineSegments (context, cgPoints, numLines*2); delete [] cgPoints; releaseCGContext (context); } }
static void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth, float ovalHeight) { float fw, fh; // If either ovalWidth or ovalHeight is 0, draw a regular rectangle. if (ovalWidth == 0 || ovalHeight == 0) { CGContextAddRect(context, rect); }else{ CGContextSaveGState(context); // Translate to lower-left corner of rectangle. CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect)); // Scale by the oval width and height so that // each rounded corner is 0.5 units in radius. CGContextScaleCTM(context, ovalWidth, ovalHeight); // Unscale the rectangle width by the amount of the X scaling. fw = CGRectGetWidth(rect) / ovalWidth; // Unscale the rectangle height by the amount of the Y scaling. fh = CGRectGetHeight(rect) / ovalHeight; // Start at the right edge of the rect, at the midpoint in Y. CGContextMoveToPoint(context, fw, fh/2); // Segment 1 CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 0.5); // Segment 2 CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 0.5); // Segment 3 CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 0.5); // Segment 4 CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 0.5); // Closing the path adds the last segment. CGContextClosePath(context); CGContextRestoreGState(context); } }
//----------------------------------------------------------------------------- void CGDrawContext::drawRect (const CRect &rect, const CDrawStyle drawStyle) { CGContextRef context = beginCGContext (true, currentState.drawMode.integralMode ()); if (context) { CGPathDrawingMode m; switch (drawStyle) { case kDrawFilled : m = kCGPathFill; break; case kDrawFilledAndStroked : m = kCGPathFillStroke; break; default : m = kCGPathStroke; break; } applyLineStyle (context); CGRect r; if (currentState.drawMode.integralMode ()) { r = CGRectMake (round (rect.left), round (rect.top + 1), round (rect.width () - 1), round (rect.height () - 1)); } else { r = CGRectMake (rect.left, rect.top + 1, rect.width () - 1, rect.height () - 1); } if ((((int32_t)currentState.frameWidth) % 2)) CGContextTranslateCTM (context, 0.5f, -0.5f); CGContextBeginPath (context); CGContextAddRect (context, r); CGContextDrawPath (context, m); releaseCGContext (context); } }
QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool /* isTextBuffer */, QWidget *widget) : image(width, height, format) { uint cgflags = kCGImageAlphaNoneSkipFirst; switch (format) { case QImage::Format_ARGB32: cgflags = kCGImageAlphaFirst; break; case QImage::Format_ARGB32_Premultiplied: case QImage::Format_ARGB8565_Premultiplied: case QImage::Format_ARGB6666_Premultiplied: case QImage::Format_ARGB8555_Premultiplied: case QImage::Format_ARGB4444_Premultiplied: cgflags = kCGImageAlphaPremultipliedFirst; break; default: break; } #ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version cgflags |= kCGBitmapByteOrder32Host; #endif cg = CGBitmapContextCreate(image.bits(), width, height, 8, image.bytesPerLine(), QCoreGraphicsPaintEngine::macDisplayColorSpace(widget), cgflags); CGContextTranslateCTM(cg, 0, height); CGContextScaleCTM(cg, 1, -1); Q_ASSERT(image.paintEngine()->type() == QPaintEngine::Raster); static_cast<QRasterPaintEngine *>(image.paintEngine())->setCGContext(cg); }
bool GiCanvasIosImpl::createBufferBitmap(float width, float height, float scale) { width *= scale; // 点数宽度转为像素宽度 height *= scale; if (width < 4 || height < 4 || width > 2049 || height > 2049) { return false; } CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); _buffctx = CGBitmapContextCreate(NULL, width, height, 8, width * 4, colorSpace, kCGImageAlphaPremultipliedLast); CGColorSpaceRelease(colorSpace); CGContextClearRect(_buffctx, CGRectMake(0, 0, width, height)); // 坐标系改为Y朝下,原点在左上角,这样除了放大倍数为1外,其余就与 _context 坐标系一致 //if (_buffctx && _context) { CGContextTranslateCTM(_buffctx, 0, height); CGContextScaleCTM(_buffctx, scale, - scale); //} //else if (_buffctx) { // CGContextScaleCTM(_buffctx, scale, scale); //} return !!_buffctx; }
//----------------------------------------------------------------------------- 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, static_cast<CGFloat> (-size.y), static_cast<CGFloat> (size.x), static_cast<CGFloat> (size.y)), image); CGContextScaleCTM (context, 1, -1); return context; } } } if (bits) { CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big; context = CGBitmapContextCreate (bits, static_cast<size_t> (size.x), static_cast<size_t> (size.y), 8, getBytesPerRow (), GetCGColorSpace (), bitmapInfo); CGContextTranslateCTM (context, 0, (CGFloat)size.y); CGContextScaleCTM (context, 1, -1); } return context; }
static void AddRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth, float ovalHeight) { float fw, fh; if (ovalWidth == 0 || ovalHeight == 0) { CGContextAddRect(context, rect); return; } CGContextSaveGState(context); CGContextTranslateCTM (context, CGRectGetMinX(rect), CGRectGetMinY(rect)); CGContextScaleCTM (context, ovalWidth, ovalHeight); fw = CGRectGetWidth (rect) / ovalWidth; fh = CGRectGetHeight (rect) / ovalHeight; CGContextMoveToPoint(context, fw, fh / 2); CGContextAddArcToPoint(context, fw, fh, fw / 2, fh, 1); CGContextAddArcToPoint(context, 0, fh, 0, fh / 2, 1); CGContextAddArcToPoint(context, 0, 0, fw / 2, 0, 1); CGContextAddArcToPoint(context, fw, 0, fw, fh / 2, 1); CGContextClosePath(context); CGContextRestoreGState(context); }
void ImageBuffer::clip(GraphicsContext* context, const FloatRect& rect) const { CGContextRef platformContext = context->platformContext(); RetainPtr<CGImageRef> image; if (!m_accelerateRendering) image.adoptCF(cgImage(m_size, m_data)); #if USE(IOSURFACE_CANVAS_BACKING_STORE) else image.adoptCF(wkIOSurfaceContextCreateImage(platformContext)); #endif CGContextTranslateCTM(platformContext, rect.x(), rect.y() + rect.height()); CGContextScaleCTM(platformContext, 1, -1); CGContextClipToMask(platformContext, FloatRect(FloatPoint(), rect.size()), image.get()); CGContextScaleCTM(platformContext, 1, -1); CGContextTranslateCTM(platformContext, -rect.x(), -rect.y() - rect.height()); }
void SkOSWindow::doPaint(void* ctx) { #if 0 this->update(NULL); const SkBitmap& bm = this->getBitmap(); CGImageRef img = SkCreateCGImageRef(bm); if (img) { CGRect r = CGRectMake(0, 0, bm.width(), bm.height()); CGContextRef cg = reinterpret_cast<CGContextRef>(ctx); CGContextSaveGState(cg); CGContextTranslateCTM(cg, 0, r.size.height); CGContextScaleCTM(cg, 1, -1); CGContextDrawImage(cg, r, img); CGContextRestoreGState(cg); CGImageRelease(img); } #endif }
void GraphicsContext::translate(float x, float y) { if (paintingDisabled()) return; CGContextTranslateCTM(platformContext(), x, y); m_data->translate(x, y); m_data->m_userToDeviceTransformKnownToBeIdentity = false; }
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 WKCACFLayer::display(PlatformGraphicsContext* context) { if (!m_owner) return; CGContextSaveGState(context); CGRect layerBounds = bounds(); if (m_owner->contentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesTopDown) { CGContextScaleCTM(context, 1, -1); CGContextTranslateCTM(context, 0, -layerBounds.size.height); } if (m_owner->client()) { GraphicsContext graphicsContext(context); // It's important to get the clip from the context, because it may be significantly // smaller than the layer bounds (e.g. tiled layers) CGRect clipBounds = CGContextGetClipBoundingBox(context); IntRect clip(enclosingIntRect(clipBounds)); m_owner->paintGraphicsLayerContents(graphicsContext, clip); } #ifndef NDEBUG else { ASSERT_NOT_REACHED(); // FIXME: ideally we'd avoid calling -setNeedsDisplay on a layer that is a plain color, // so CA never makes backing store for it (which is what -setNeedsDisplay will do above). CGContextSetRGBFillColor(context, 0.0f, 1.0f, 0.0f, 1.0f); CGContextFillRect(context, layerBounds); } #endif if (m_owner->showRepaintCounter()) { char text[16]; // that's a lot of repaints _snprintf(text, sizeof(text), "%d", m_owner->incrementRepaintCount()); CGContextSaveGState(context); CGContextSetRGBFillColor(context, 1.0f, 0.0f, 0.0f, 0.8f); CGRect aBounds = layerBounds; aBounds.size.width = 10 + 12 * strlen(text); aBounds.size.height = 25; CGContextFillRect(context, aBounds); CGContextSetRGBFillColor(context, 0.0f, 0.0f, 0.0f, 1.0f); CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0f, -1.0f)); CGContextSelectFont(context, "Helvetica", 25, kCGEncodingMacRoman); CGContextShowTextAtPoint(context, aBounds.origin.x + 3.0f, aBounds.origin.y + 20.0f, text, strlen(text)); CGContextRestoreGState(context); } CGContextRestoreGState(context); }
static void drawPatternCallback(void* info, CGContextRef context) { CGImageRef image = (CGImageRef)info; CGFloat height = CGImageGetHeight(image); #if PLATFORM(IOS) CGContextScaleCTM(context, 1, -1); CGContextTranslateCTM(context, 0, -height); #endif CGContextDrawImage(context, GraphicsContext(context).roundToDevicePixels(FloatRect(0, 0, CGImageGetWidth(image), height)), image); }
DISABLED_DRAW_TEST_F(CGContext, ShadowWithRotatedCTM, WhiteBackgroundTest) { CGContextRef context = GetDrawingContext(); CGRect bounds = GetDrawingBounds(); CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0); CGContextSetLineWidth(context, 5); CGContextSetShadow(context, CGSize{ 10.f, 10.f }, 1.0); CGPoint center = _CGRectGetCenter(bounds); CGRect rect = _CGRectCenteredOnPoint({ 150, 150 }, center); CGPoint rectCenter = _CGRectGetCenter(rect); CGContextTranslateCTM(context, rectCenter.x, rectCenter.y); CGContextRotateCTM(context, 15.f * M_PI / 180.f); CGContextTranslateCTM(context, -rectCenter.x, -rectCenter.y); CGContextStrokeRect(context, rect); }
// On Mac, must redraw borders yourself: void QuartzWindow::adjust_after_resize() { if (myContext) { CGAffineTransform x = CGContextGetCTM(myContext); CGContextScaleCTM(myContext, 1.0 / x.a, 1.0 / x.d); CGContextTranslateCTM(myContext, -x.tx, -x.ty); setupCTM(); } if (TheSpy != NULL) TheSpy->adjust_after_resize(); // might be the spy }