I am currently trying to print files or text (to a printer, not to a terminal etc.) in Haskell with gtk(2hs) using Graphics.UI.Gtk.Printing
, Cairo and Pango.
Code is the following:
op <- printOperationNew
on op printOptBeginPrint $ \context -> do
set op [ printOperationNPages := 1]
return ()
on op printOptDrawPage $ \context pages - do
let text = "Hello World"
putStrLn $ "Printing :" ++ text
--cairo
cairoContext<- printContextGetCairoContext context
--pango
layout<- printContextCreatePangoLayout context
layoutSetText layout text
let _ = do
--inside the Render Monad
showLayout layout
return ()
return ()
result <- printOperationRun op PrintOperationActionPrintDialog window
This prints an empty page since I set the printOperationNPages
to 1.
The problem is that cairo does not draw anything. I suppose I have to
connect the cairoContext
with the pango layout, the proper call to
showLayout
would actually be pango_cairo_show_layout (cr, layout);
.
I already discussed this problem on the mailing list for gtk2hs [1].
So if anybody has experience with this, please let me know. I would also be grateful for other - preferable platform-independent - solutions to printing files/text in haskell.
Link to conversation: [1] http://sourceforge.net/mailarchive/message.php?msg_id=27662267
GTK(2hs) in Hackage: http://hackage.haskell.org/package/gtk-0.12.0