static bool monochromeMediaFeatureEval(CSSValueImpl* value, RenderStyle*, KHTMLPart* part, MediaFeaturePrefix op) { KHTMLPart* rootPart = part; while (rootPart->parentPart()) rootPart = rootPart->parentPart(); DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; int depth = 0; if (printing) { if (pd->numColors() < 2) depth = 1; // assume printer is either b&w or color. } else { int sn = QApplication::desktop()->screenNumber( rootPart->view() ); if (QApplication::desktop()->screen(sn)->depth() == 1) depth = 1; else if (QColormap::instance(sn).mode() == QColormap::Gray) depth = QApplication::desktop()->screen(sn)->depth(); } if (value) { float number = 0; return numberValue(value, number) && compareValue(depth, static_cast<int>(number), op); } return depth; }
static bool orientationMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part, MediaFeaturePrefix /*op*/) { if (value) { CSSPrimitiveValueImpl *pv = static_cast<CSSPrimitiveValueImpl *>(value); if (!value->isPrimitiveValue() || pv->primitiveType() != CSSPrimitiveValue::CSS_IDENT || (pv->getIdent() != CSS_VAL_PORTRAIT && pv->getIdent() != CSS_VAL_LANDSCAPE)) { return false; } KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; if (printing) { if (pd->width() > pd->height()) { return (pv->getIdent() == CSS_VAL_LANDSCAPE); } } else { if (part->view()->visibleWidth() > part->view()->visibleHeight()) { return (pv->getIdent() == CSS_VAL_LANDSCAPE); } } return (pv->getIdent() == CSS_VAL_PORTRAIT); } return false; }
/*! Returns a QImage pointer which represents the actual buffer the \a widget is drawn into or 0 if this is unavailable. You must call beginPaint() before you call this function and the returned pointer is only valid until endPaint() is called. */ QImage* QWindowSurface::buffer(const QWidget *widget) { if (widget->window() != window()) return 0; QPaintDevice *pdev = paintDevice(); if (!pdev || pdev->devType() != QInternal::Image) return 0; const QPoint off = offset(widget); QImage *img = static_cast<QImage*>(pdev); QRect rect(off, widget->size()); rect &= QRect(QPoint(), img->size()); if (rect.isEmpty()) return 0; img = new QImage(img->scanLine(rect.y()) + rect.x() * img->depth() / 8, rect.width(), rect.height(), img->bytesPerLine(), img->format()); d_ptr->bufferImages.append(img); return img; }
static bool aspect_ratioMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part, MediaFeaturePrefix op) { if (value) { KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; QSize vs; int h = 0, v = 0; if (printing) { vs = QSize(pd->width(), pd->height()); } else { vs = QSize(part->view()->visibleWidth(), part->view()->visibleHeight()); } if (parseAspectRatio(value, h, v)) { return v != 0 && compareValue(vs.width() * v, vs.height() * h, op); } return false; } // ({,min-,max-}aspect-ratio) // assume if we have a viewport, its aspect ratio is non-zero return true; }
static bool device_aspect_ratioMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part, MediaFeaturePrefix op) { if (value) { KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; QRect sg; int h = 0, v = 0; if (printing) { sg = QRect(0, 0, pd->width(), pd->height()); } else { sg = QApplication::desktop()->screen(QApplication::desktop()->screenNumber(rootPart->view()))->rect(); } if (parseAspectRatio(value, h, v)) { return v != 0 && compareValue(sg.width() * v, sg.height() * h, op); } return false; } // ({,min-,max-}device-aspect-ratio) // assume if we have a device, its aspect ratio is non-zero return true; }
static bool colorMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part, MediaFeaturePrefix op) { KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; int bitsPerComponent = 0; if (printing) { if (pd->colorCount() > 2) { bitsPerComponent = pd->depth() / 3; } // assume printer is either b&w or color. } else { int sn = QApplication::desktop()->screenNumber(rootPart->view()); if (QColormap::instance(sn).mode() != QColormap::Gray) { bitsPerComponent = QApplication::desktop()->screen(sn)->depth() / 3; } } if (value && bitsPerComponent) { float number = 0; return numberValue(value, number) && compareValue(bitsPerComponent, static_cast<int>(number), op); } return bitsPerComponent; }
static bool color_indexMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part, MediaFeaturePrefix op) { KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; unsigned int numColors = 0; if (printing) { numColors = pd->colorCount(); } else { int sn = QApplication::desktop()->screenNumber(rootPart->view()); numColors = QApplication::desktop()->screen(sn)->colorCount(); } if (numColors == INT_MAX) { numColors = UINT_MAX; } if (value) { float number = 0; return numberValue(value, number) && compareValue(numColors, static_cast<unsigned int>(number), op); } return numColors; }
static cairo_image_surface_t * _cairo_qt_surface_map_to_image (void *abstract_surface, const cairo_rectangle_int_t *extents) { cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; QImage *qimg = NULL; D(fprintf(stderr, "q[%p] acquire_dest_image\n", abstract_surface)); if (qs->image_equiv) return _cairo_image_surface_map_to_image (qs->image_equiv, extents); QPoint offset; if (qs->pixmap) { qimg = new QImage(qs->pixmap->toImage()); } else { // Try to figure out what kind of QPaintDevice we have, and // how we can grab an image from it QPaintDevice *pd = qs->p->device(); if (!pd) return (cairo_image_surface_t *) _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); QPaintDevice *rpd = QPainter::redirected(pd, &offset); if (rpd) pd = rpd; if (pd->devType() == QInternal::Image) { qimg = new QImage(((QImage*) pd)->copy()); } else if (pd->devType() == QInternal::Pixmap) { qimg = new QImage(((QPixmap*) pd)->toImage()); } else if (pd->devType() == QInternal::Widget) { qimg = new QImage(QPixmap::grabWindow(((QWidget*)pd)->winId()).toImage()); } } return (cairo_image_surface_t *) map_qimage_to_image (qimg, extents); }
void StylePainterQStyle::init(GraphicsContext* context, QStyle* themeStyle) { painter = static_cast<QPainter*>(context->platformContext()); widget = 0; QPaintDevice* dev = 0; if (painter) dev = painter->device(); if (dev && dev->devType() == QInternal::Widget) widget = static_cast<QWidget*>(dev); style = themeStyle; StylePainter::init(context); }
StylePainter::StylePainter(const RenderObject::PaintInfo& paintInfo) { painter = (paintInfo.context ? static_cast<QPainter*>(paintInfo.context->platformContext()) : 0); widget = 0; QPaintDevice* dev = 0; if (painter) dev = painter->device(); if (dev && dev->devType() == QInternal::Widget) widget = static_cast<QWidget*>(dev); style = (widget ? widget->style() : QApplication::style()); if (painter) { // the styles often assume being called with a pristine painter where no brush is set, // so reset it manually oldBrush = painter->brush(); painter->setBrush(Qt::NoBrush); } }
void CarioQImageMainWindow::on_create_image_by_xlib_button_clicked() { int height = ui->label->height(); int width = ui->label->width(); QPixmap *pixmap = new QPixmap(width, height); QPainter painter(pixmap); QPaintDevice *pd = painter.device(); if(pd->devType() == QInternal::Pixmap) { QPixmap *pixmap_inner = (QPixmap*) pd; Drawable d = (Drawable) pixmap_inner->handle(); QX11Info xinfo = pixmap_inner->x11Info(); int width = pixmap_inner->width(); int height = pixmap_inner->height(); cairo_surface_t * pCairoSurface = cairo_xlib_surface_create_with_xrender_format (xinfo.display(), d, ScreenOfDisplay(xinfo.display(), xinfo.screen()), XRenderFindVisualFormat (xinfo.display(), (Visual*) xinfo.visual()), width, height); cairo_t* pCairoContext = cairo_create(pCairoSurface); cairo_surface_destroy(pCairoSurface); if(pCairoContext) { cairo_set_source_rgb (pCairoContext, 0.627, 0, 0); cairo_set_font_size (pCairoContext, 24.0); cairo_move_to (pCairoContext, 10.0, 34.0); cairo_show_text (pCairoContext, "Hello, world\nUsing Image X11 Surface"); cairo_destroy(pCairoContext); } } ui->label->setPixmap(*pixmap); }
static bool heightMediaFeatureEval(CSSValueImpl* value, RenderStyle* style, KHTMLPart* part, MediaFeaturePrefix op) { KHTMLPart* rootPart = part; while (rootPart->parentPart()) rootPart = rootPart->parentPart(); DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; int height; if (printing) height = pd->height(); else { height = part->view()->visibleHeight(); doc = static_cast<DOM::DocumentImpl*>(part->document().handle()); } int logicalDpiY = doc->logicalDpiY(); if (value) return value->isPrimitiveValue() && compareValue(height, static_cast<CSSPrimitiveValueImpl*>(value)->computeLength(style, logicalDpiY), op); return height > 0; }
static bool device_widthMediaFeatureEval(CSSValueImpl* value, RenderStyle* style, KHTMLPart* part, MediaFeaturePrefix op) { if (value) { KHTMLPart* rootPart = part; while (rootPart->parentPart()) rootPart = rootPart->parentPart(); DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; int width; if (printing) width = pd->width(); else { width = QApplication::desktop()->screen(QApplication::desktop()->screenNumber( rootPart->view() ))->rect().width(); doc = static_cast<DOM::DocumentImpl*>(part->document().handle()); } int logicalDpiY = doc->logicalDpiY(); return value->isPrimitiveValue() && compareValue(width, static_cast<CSSPrimitiveValueImpl*>(value)->computeLength(style,logicalDpiY), op); } // ({,min-,max-}device-width) // assume if we have a device, assume non-zero return true; }
StylePainter::StylePainter(const RenderObject::PaintInfo& paintInfo) { painter = (paintInfo.context ? static_cast<QPainter*>(paintInfo.context->platformContext()) : 0); widget = 0; QPaintDevice* dev = 0; if (painter) dev = painter->device(); if (dev && dev->devType() == QInternal::Widget) widget = static_cast<QWidget*>(dev); style = (widget ? widget->style() : QApplication::style()); if (painter) { // the styles often assume being called with a pristine painter where no brush is set, // so reset it manually oldBrush = painter->brush(); painter->setBrush(Qt::NoBrush); // painting the widget with anti-aliasing will make it blurry // disable it here and restore it later oldAntialiasing = painter->testRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing, false); } }
void StylePainter::init(GraphicsContext* context, QStyle* themeStyle) { painter = static_cast<QPainter*>(context->platformContext()); widget = 0; QPaintDevice* dev = 0; if (painter) dev = painter->device(); if (dev && dev->devType() == QInternal::Widget) widget = static_cast<QWidget*>(dev); style = themeStyle; if (painter) { // the styles often assume being called with a pristine painter where no brush is set, // so reset it manually oldBrush = painter->brush(); painter->setBrush(Qt::NoBrush); // painting the widget with anti-aliasing will make it blurry // disable it here and restore it later oldAntialiasing = painter->testRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing, false); } }
static bool widthMediaFeatureEval(CSSValueImpl *value, RenderStyle *style, KHTMLPart *part, MediaFeaturePrefix op) { KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; int width; if (printing) { width = pd->width(); } else { width = part->view()->visibleWidth(); doc = static_cast<DOM::DocumentImpl *>(part->document().handle()); } int logicalDpiY = doc->logicalDpiY(); if (value) { return value->isPrimitiveValue() && compareValue(width, static_cast<CSSPrimitiveValueImpl *>(value)->computeLength(style, style, logicalDpiY), op); } return width > 0; }
void PluginView::paint(GraphicsContext* context, const IntRect& rect) { if (!m_isStarted) { paintMissingPluginIcon(context, rect); return; } if (context->paintingDisabled()) return; setNPWindowIfNeeded(); if (m_isWindowed || !m_drawable) return; const bool syncX = m_pluginDisplay && m_pluginDisplay != QX11Info::display(); QPainter* painter = context->platformContext(); IntRect exposedRect(rect); exposedRect.intersect(frameRect()); exposedRect.move(-frameRect().x(), -frameRect().y()); QPixmap qtDrawable = QPixmap::fromX11Pixmap(m_drawable, QPixmap::ExplicitlyShared); const int drawableDepth = ((NPSetWindowCallbackStruct*)m_npWindow.ws_info)->depth; ASSERT(drawableDepth == qtDrawable.depth()); // When printing, Qt uses a QPicture to capture the output in preview mode. The // QPicture holds a reference to the X Pixmap. As a result, the print preview would // update itself when the X Pixmap changes. To prevent this, we create a copy. if (m_element->document()->printing()) qtDrawable = qtDrawable.copy(); if (m_isTransparent && drawableDepth != 32) { // Attempt content propagation for drawable with no alpha by copying over from the backing store QPoint offset; QPaintDevice* backingStoreDevice = QPainter::redirected(painter->device(), &offset); offset = -offset; // negating the offset gives us the offset of the view within the backing store pixmap const bool hasValidBackingStore = backingStoreDevice && backingStoreDevice->devType() == QInternal::Pixmap; QPixmap* backingStorePixmap = static_cast<QPixmap*>(backingStoreDevice); // We cannot grab contents from the backing store when painting on QGraphicsView items // (because backing store contents are already transformed). What we really mean to do // here is to check if we are painting on QWebView, but let's be a little permissive :) QWebPageClient* client = m_parentFrame->view()->hostWindow()->platformPageClient(); const bool backingStoreHasUntransformedContents = client && qobject_cast<QWidget*>(client->pluginParent()); if (hasValidBackingStore && backingStorePixmap->depth() == drawableDepth && backingStoreHasUntransformedContents) { GC gc = XDefaultGC(QX11Info::display(), QX11Info::appScreen()); XCopyArea(QX11Info::display(), backingStorePixmap->handle(), m_drawable, gc, offset.x() + m_windowRect.x() + exposedRect.x(), offset.y() + m_windowRect.y() + exposedRect.y(), exposedRect.width(), exposedRect.height(), exposedRect.x(), exposedRect.y()); } else { // no backing store, clean the pixmap because the plugin thinks its transparent QPainter painter(&qtDrawable); painter.fillRect(exposedRect, Qt::white); } if (syncX) QApplication::syncX(); } XEvent xevent; memset(&xevent, 0, sizeof(XEvent)); XGraphicsExposeEvent& exposeEvent = xevent.xgraphicsexpose; exposeEvent.type = GraphicsExpose; exposeEvent.display = QX11Info::display(); exposeEvent.drawable = qtDrawable.handle(); exposeEvent.x = exposedRect.x(); exposeEvent.y = exposedRect.y(); exposeEvent.width = exposedRect.x() + exposedRect.width(); // flash bug? it thinks width is the right in transparent mode exposeEvent.height = exposedRect.y() + exposedRect.height(); // flash bug? it thinks height is the bottom in transparent mode dispatchNPEvent(xevent); if (syncX) XSync(m_pluginDisplay, False); // sync changes by plugin painter->drawPixmap(QPoint(frameRect().x() + exposedRect.x(), frameRect().y() + exposedRect.y()), qtDrawable, exposedRect); }
void Style::drawTabBar(const QStyleOption *option, QPainter *painter, const QWidget *widget) const { ASSURE_OPTION(tbb, TabBarBase); if (!config.invert.headers) { if (tbb->selectedTabRect.isEmpty()) return; // only paint tab shapes if HAVE_OPTION(tbb2, TabBarBaseV2) { if (tbb2->documentMode) { return; // useless and adds confliciting horizintal lines } } SAVE_PAINTER(Pen|Alias); painter->setRenderHint(QPainter::Antialiasing, false); painter->setPen(QPen(FRAME_COLOR, FRAME_STROKE_WIDTH)); switch (tbb->shape) { case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: painter->drawLine(RECT.x(), RECT.bottom(), tbb->selectedTabRect.x(), RECT.bottom()); painter->drawLine(tbb->selectedTabRect.right(), RECT.bottom(), RECT.right(), RECT.bottom()); break; case QTabBar::RoundedSouth: case QTabBar::TriangularSouth: painter->drawLine(RECT.x(), RECT.top(), tbb->selectedTabRect.x(), RECT.top()); painter->drawLine(tbb->selectedTabRect.right(), RECT.top(), RECT.right(), RECT.top()); break; case QTabBar::RoundedEast: case QTabBar::TriangularEast: painter->drawLine(RECT.x(), RECT.y(), RECT.x(), tbb->selectedTabRect.y()); painter->drawLine(RECT.x(), tbb->selectedTabRect.bottom(), RECT.x(), RECT.bottom()); break; case QTabBar::RoundedWest: case QTabBar::TriangularWest: painter->drawLine(RECT.right(), RECT.y(), RECT.right(), tbb->selectedTabRect.y()); painter->drawLine(RECT.right(), tbb->selectedTabRect.bottom(), RECT.right(), RECT.bottom()); break; } RESTORE_PAINTER return; } QWidget *win = 0; if (widget) { if (widget->parentWidget() && qobject_cast<QTabWidget*>(widget->parentWidget())) { if (widget->parentWidget()->style() == this) { return; // otherwise it's a proxystyle like on konqueror / kdevelop... } } else if (qobject_cast<const QTabBar*>(widget) || (appType == KDevelop && widget->inherits("QLabel"))) { return; // usually we alter the paintevent by eventfiltering } win = widget->window(); } else { if (painter->device()->devType() == QInternal::Widget) widget = static_cast<QWidget*>(painter->device()); else { QPaintDevice *dev = QPainter::redirected(painter->device()); if (dev && dev->devType() == QInternal::Widget) widget = static_cast<QWidget*>(dev); } if ( widget ) win = widget->window(); } QRect winRect; if (win) { winRect = win->rect(); winRect.moveTopLeft(widget->mapFrom(win, winRect.topLeft())); } // else // winRect = tbb->tabBarRect; // we set this from the eventfilter QEvent::Paint SAVE_PAINTER(Pen|Brush|Alias); painter->setBrush(PAL.color(QPalette::Active, QPalette::WindowText)); painter->setPen(Qt::NoPen); // TODO: half rounded rect? if (RECT.x() == winRect.x() || RECT.y() == winRect.y() || RECT.right() == winRect.right() || RECT.bottom() == winRect.bottom()) { painter->setRenderHint(QPainter::Antialiasing, false); painter->drawRect(RECT); } else { painter->setRenderHint(QPainter::Antialiasing, true); const int rnd = qMin(config.frame.roundness, verticalTabs(tbb->shape) ? RECT.width()/2 : RECT.height()/2); painter->drawRoundedRect(RECT, rnd, rnd); } RESTORE_PAINTER }
void WindowSurfaceImpl::updateSurfaceData() { // If painting is active, i.e. beginPaint has been called // surface data is not updated if(mPaintingStarted) { return; } QWindowSurface* surface = mMainSurface.widget->windowSurface(); // If window surface is null it means that the widget has been // sent to background and widget's window surface has been deleted, // in such case create own QImage as local surface in order to support // rendering in background if(surface == NULL) { // check if we already have local surface with valid size if(!isLocalSurfaceValid()) { // incase we have invalid surface delete the current one // and create new if(mMainSurface.localSurfaceInUse) { deleteLocalSurface(); } createLocalSurface(); // set info mMainSurface.qSurface = NULL; mMainSurface.device = mMainSurface.localSurface; mMainSurface.type = WsTypeQtImage; mMainSurface.localSurfaceInUse = true; return; } else { // We have valid local surface so make sure its active and return mMainSurface.localSurfaceInUse = true; return; } } else { // We got Qt's window surface, so in case we had local surface in use // delete it as it's not used anymore if(mMainSurface.localSurfaceInUse) { // in case we have needed the local surface as temp // buffer for a client, it is not deleted as we most likely // will need it again. In any case the local surface // stops to be the main surface and is atleast demoted to // temp surface. if(!mPreserveLocalSurface) { deleteLocalSurface(); } } } // We got window surface so extract information QPaintDevice* device = surface->paintDevice(); QPaintEngine* engine = NULL; // If the device is active it means that some painter is attached to the widget, // if not then we attach our own painter to do the job if(device->paintingActive()) { engine = device->paintEngine(); } else { mPainter.begin(device); engine = mPainter.paintEngine(); } // determine the surface type based on the engine used // as Qt does not provide exact info of the surface type switch (engine->type()) { case QPaintEngine::OpenVG: // surface is EGL window surface mMainSurface.type = WsTypeEglSurface; break; case QPaintEngine::Raster: mMainSurface.type = WsTypeSymbianBitmap; if(device->devType() == QInternal::Pixmap) { QPixmap* pixmap = static_cast<QPixmap*>(device); mMainSurface.symbianBitmap = pixmap->toSymbianCFbsBitmap(); } else { throw GfxException(EGfxErrorIllegalArgument, "Unsupported device type"); } break; default: throw GfxException(EGfxErrorIllegalArgument, "Unsupported widget window surface type"); } // release painter if its active if(mPainter.isActive()) { mPainter.end(); } mMainSurface.qSurface = surface; mMainSurface.device = device; mMainSurface.localSurfaceInUse = false; }
static cairo_status_t _cairo_qt_surface_acquire_dest_image (void *abstract_surface, cairo_rectangle_int_t *interest_rect, cairo_image_surface_t **image_out, cairo_rectangle_int_t *image_rect, void **image_extra) { cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; QImage *qimg = NULL; D(fprintf(stderr, "q[%p] acquire_dest_image\n", abstract_surface)); *image_extra = NULL; if (qs->image_equiv) { *image_out = (cairo_image_surface_t*) cairo_surface_reference (qs->image_equiv); image_rect->x = qs->window.x(); image_rect->y = qs->window.y(); image_rect->width = qs->window.width(); image_rect->height = qs->window.height(); return CAIRO_STATUS_SUCCESS; } QPoint offset; if (qs->pixmap) { qimg = new QImage(qs->pixmap->toImage()); } else { // Try to figure out what kind of QPaintDevice we have, and // how we can grab an image from it QPaintDevice *pd = qs->p->device(); if (!pd) return _cairo_error (CAIRO_STATUS_NO_MEMORY); QPaintDevice *rpd = QPainter::redirected(pd, &offset); if (rpd) pd = rpd; if (pd->devType() == QInternal::Image) { qimg = new QImage(((QImage*) pd)->copy()); } else if (pd->devType() == QInternal::Pixmap) { qimg = new QImage(((QPixmap*) pd)->toImage()); } else if (pd->devType() == QInternal::Widget) { qimg = new QImage(QPixmap::grabWindow(((QWidget*)pd)->winId()).toImage()); } } if (qimg == NULL) return _cairo_error (CAIRO_STATUS_NO_MEMORY); *image_out = (cairo_image_surface_t*) cairo_image_surface_create_for_data (qimg->bits(), _cairo_format_from_qimage_format (qimg->format()), qimg->width(), qimg->height(), qimg->bytesPerLine()); *image_extra = qimg; image_rect->x = qs->window.x() + offset.x(); image_rect->y = qs->window.y() + offset.y(); image_rect->width = qs->window.width() - offset.x(); image_rect->height = qs->window.height() - offset.y(); return CAIRO_STATUS_SUCCESS; }