Open jojo05 opened 10 years ago
There is certainly a way, but I am not familiar enough with the API to know the best way to do it. Would you be interested in submitting a patch for this?
/cc @bryansum
On Apr 21, 2014, at 7:51, jojo05 notifications@github.com wrote:
Is it possible to fix the rendering width ? I found it tries to render the pages in the minimum width, rather than a fixed width. thanks
— Reply to this email directly or view it on GitHub.
The underlying API is here: http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-get-snapshot
There doesn't seem to be an explicit option for setting width / height. It does seem, however, that we could try and resize the window directly via GTK commands (see the comment in his file: http://www.opensource.apple.com/source/WebKit2/WebKit2-7536.26.14/UIProcess/API/gtk/WebKitWindowProperties.cpp).
just seen a nice example here: https://github.com/conformal/gotk3
package main import ( "github.com/conformal/gotk3/gtk" "log" ) func main() { // Initialize GTK without parsing any command line arguments. gtk.Init(nil) // Create a new toplevel window, set its title, and connect it to the // "destroy" signal to exit the GTK main loop when it is destroyed. win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL) if err != nil { log.Fatal("Unable to create window:", err) } win.SetTitle("Simple Example") win.Connect("destroy", func() { gtk.MainQuit() }) // Create a new label widget to show in the window. l, err := gtk.LabelNew("Hello, gotk3!") if err != nil { log.Fatal("Unable to create label:", err) } // Add the label to the window. win.Add(l) // Set the default window size. win.SetDefaultSize(800, 600) // Recursively show all widgets contained in this window. win.ShowAll() // Begin executing the GTK main loop. This blocks until // gtk.MainQuit() is run. gtk.Main() }
Thats a great example but it can be a bit confusing for those who aren't familiar with GDK or GTK. For anyone that doesn't want to delve into the large API's of those projects this is what you have to do for setting the size of the go-webkit "browser".
//gtk initialization
gtk.Init(nil)
//starting gtk window
win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
if err != nil {
log.Fatal("Unable to create window:", err)
}
win.Connect("destroy", func() {
gtk.MainQuit()
})
// Set the size of the gtk window we will be rendering go-webkit in.
win.SetDefaultSize(1280, 1200)
// make a new go-webkit widget
webView := webkit2.NewWebView()
defer webView.Destroy()
//add the go-webkit widget to the gtk window
win.Add(webView)
//OPTIONAL: set the size of the go-webkit widget within that window, otherwise it will default to the dimensions specified with win.SetDefaultSize
//webView.SetSizeRequest(1280,1200)
// Recursively show all widgets contained the window. this will force the window to apply the sizes we defined above
win.ShowAll()
// continue on with a go-webkit instance rendering at 1280x1200
Oh using this should allow for full use of: http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WebKitSnapshotRegion
allowing for only the region visible in the window to be used for the snapshot
I'll be submitting a PR for this soon edit: https://github.com/sourcegraph/go-webkit2/pull/24
Is it possible to fix the rendering width ? I found it tries to render the pages in the minimum width, rather than a fixed width. thanks