在 gtk2hs 中使用 Gtk.Printing/cairo/pango 进行打印 - Haskell 中的打印操作
我目前正在尝试使用 Graphics.UI.Gtk.Printing、Cairo 和 Pango 在 Haskell 中使用 gtk(2hs) 打印文件或文本(到打印机,而不是终端等)。
代码如下:
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
由于我将 printOperationNPages
设置为 1,因此会打印一个空页。 问题是 cairo 没有画任何东西。我想我必须 将 cairoContext 与 pango 布局连接起来,正确的调用 showLayout
实际上是 pango_cairo_show_layout (cr,layout);
。
我已经在 gtk2hs [1] 的邮件列表上讨论了这个问题。
因此,如果有人有这方面的经验,请告诉我。我也将感谢其他更好的独立于平台的解决方案来在 haskell 中打印文件/文本。
对话链接: [1] http://sourceforge.net/mailarchive/message.php?msg_id=27662267< /a>
Hackage 中的 GTK(2hs): http://hackage.haskell.org/package/gtk-0.12.0
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 toshowLayout
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用
GtkPrintUnixDialog
来代替?使用起来更加简单。基本上,您创建了
GtkPrintUnixDialog
,创建了GtkPrintJob
。将打印设置为源文件(文本、pdf,随便你命名),然后打印出来。您也可以不显示该对话框,以便它使用系统上的默认打印设置。Have you tried to use
GtkPrintUnixDialog
instead?Much simpler to use. Basically you create the
GtkPrintUnixDialog
, Create aGtkPrintJob
. Set the print to to source file (text,pdf you name it) and then print it out. You can also not show the dialog so that it uses the default print settings on the system.