I can get the size the page wants to be via CEF.  But resizing the WebView to 
that size in order to get the full bitmap, as you noted, changes some layouts 
and thus gives a different bitmap.  Using an excessively long size doesn't 
solve these problems though, they're almost all still present.  Media queries 
will potentially be broken, pages that grow width-wise rather than height-wise 
are screwed, and then there's the problem with a page like:

<body height='100%'>
<div height='100%'>
More content
</div>
<div height='10px'>
More content
</div>
</body>

With an arbitrarily long height for the initial setting, you'll still miss the 
last 10px always just as you will if you start with a smaller size, check the 
page for its natural height, and resize the view causing the page to re-layout 
and the natural size to be 10px larger.

Now, WebKit doesn't have to paint the stuff offscreen, but given a starting 
viewport size clearly it has to lay it out fully (so that it knows the real 
size of the page).  So where is that and how do I get that and turn it into a 
bitmap?

From: Nick Guenther [mailto:[email protected]]
Sent: Wednesday, July 13, 2011 4:28 PM
To: Matthew Johnson; [email protected]
Subject: RE: Rendering HTML page to bitmap


As I understand it, rendering *only* happens within a View. Webkit is meant for 
speed, it's not like it's going to render things that aren't going to be seen. 
On Windows the only place the bitmap of the webpage gets created is during a 
WM_PAINT or WM_PRINT (I know, I had to hook in that code before an svn revision 
added what I'd added), except for then the bitmap doesn't exist, so the only 
way to render all the contents, not just those within the viewport, is to 
render everything within the viewport. You'll have to create your view with a 
fixed width and an excessively long height, tell it to render, and hope for the 
best.

I've written the same thing on Windows and we ended up discovering (in a moment 
of duh) that pages will react badly to being resized after the fact so there 
are two reasons to pick your rendering size at the outset. I originally wanted 
to load a page and then ask webkit what its size should be, but there is no 
reasonable way to snag that because some pages are designed for fixed layouts 
and others are designed for fluidity and there really isn't much you can do 
except pick a size and run with it.

QtWebKit allows asking for the natural size of a webpage but WebKit2 doesn't 
yet unfortunately. Does CEF? If it does then you can just that information to 
clip the bitmap once it's done rendering.

-Nick Guenther
DossierView.com

From: [email protected] 
[mailto:[email protected]] On Behalf Of Matthew Johnson
Sent: Wednesday, July 13, 2011 5:17 PM
To: [email protected]
Subject: [webkit-help] Rendering HTML page to bitmap

I'd like to be able to render the full contents of a page to a bitmap, not just 
the contents within the viewport.  Is this possible?

I have been using chromiumembedded framework (CEF) to deal with WebKit and get 
the bitmap (CefBrowser::GetImage), but I can either get an bitmap of the 
viewport area only or resize the WebView and then get a bitmap of the full page 
contents.  The latter results in changes to the web page layout on many pages 
due to a different viewport size after the resize.

Using the WebKit APIs is there a way to get a bitmap of the full contents of a 
web page - at a given point in time - without resorting to resizing the WebView?

Ideally, I could capture the full WebView in a single bitmap.  But I could 
resort to scrolling around the page and tiling the respective bitmaps together 
if I can prevent it from performing any layout on the page while doing so.

Anybody have any good ways to tackle this?

Thanks,
Matt
_______________________________________________
webkit-help mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-help

Reply via email to