Skip to content

Instantly share code, notes, and snippets.

@tolmasky
Created December 3, 2009 21:08
Show Gist options
  • Select an option

  • Save tolmasky/248522 to your computer and use it in GitHub Desktop.

Select an option

Save tolmasky/248522 to your computer and use it in GitHub Desktop.
void renderSubtreeToImage(ImageBuffer* image, RenderObject* item)
{
ASSERT(item);
ASSERT(image);
ASSERT(image->context());
RenderObject::PaintInfo info(image->context(), IntRect(), PaintPhaseForeground, 0, 0, 0);
// FIXME: isSVGContainer returns true for RenderSVGViewportContainer, so if this is ever
// called with one of those, we will read from the wrong offset in an object due to a bad cast.
RenderSVGContainer* svgContainer = 0;
if (item && item->isSVGContainer())
svgContainer = toRenderSVGContainer(item);
bool drawsContents = svgContainer ? svgContainer->drawsContents() : false;
if (svgContainer && !drawsContents)
svgContainer->setDrawsContents(true);
item->layoutIfNeeded();
item->paint(info, 0, 0);
if (svgContainer && !drawsContents)
svgContainer->setDrawsContents(false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment