- UID
- 2546
- 积分
- 159
- 帖子
- 30
- 主题
- 5
- 论坛币
- 868
- 威望
- 0
- EP值
- 134
- MP值
- 0
- 阅读权限
- 50
- 注册时间
- 2015-5-9
- 在线时间
- 52 小时
- 最后登录
- 2024-10-20
|
本帖最后由 Seekladoom 于 2022-3-26 03:02 编辑
Source:
https://stackoverflow.com/questi ... -with-pygobject-api
I am porting a Python2 script that uses Pango for drawing text to a Cairo surface. It works fine using the old PyGtk API with the pangocairo package. My system (Debian Jesse) doesn't have Python3 packages for PyGtk and instead uses the newer Gtk+ libraries with the PyGObject API.
I want to create a pangocairo.CairoContext object but it seems to be missing in the new API. The PangoCairo package has a create_context() function but it generates a PangoContext object that doesn't have the methods I need.
So far I have this:
- import cairo
- from gi.repository import Pango
- from gi.repository import PangoCairo
- surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 8, 8)
- ctx = cairo.Context(surf)
- pctx = PangoCairo.create_context(ctx) # Creates a PangoContext
- pctx.set_antialias(cairo.ANTIALIAS_SUBPIXEL) # This fails
复制代码
The old Python2 code that works:
- import cairo
- import pango
- import pangocairo
- surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 8, 8)
- ctx = cairo.Context(surf)
- pctx = pangocairo.CairoContext(ctx)
- pctx.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
复制代码
Does anyone have a solution for this? Is there any good documentation on how PangoCairo should be used with the new API? |
|