简体   繁体   English

Pycairo vs. cairocffi vs. Qahirah

[英]Pycairo vs. cairocffi vs. Qahirah

I want to create and rasterize vector graphics in Python. I suspect that Pycairo or cairocffi (edit: or Qahirah ) are a great choice.我想在 Python 中创建和栅格化矢量图形。我怀疑Pycairocairocffi (编辑:或Qahirah )是一个不错的选择。 (If not, comments are welcome.) (如果没有,欢迎评论。)

What are the practical differences between the two?两者之间的实际区别是什么?

Specifically, the Pycairo documentation says:具体来说, Pycairo文档说:

If Pycairo is not what you need, have a look at cairocffi, which is an API compatible package using cffi or Qahirah, which is using ctypes and provides a more "pythonic" API with less focus on matching the cairo C API.如果 Pycairo 不是您所需要的,请查看 cairocffi,它是一个 API 兼容的 package 使用 cffi 或 Qahirah,它使用 ctypes 并提供更“pythonic”的 API,较少关注匹配 cairo C 8810338512

But this raises some questions: In what cases may Pycairo be "not what you need", whereas cairocffi is?但这提出了一些问题:在什么情况下 Pycairo 可能“不是你需要的”,而 cairocffi 是? In what way are cffi/Qahirah/ctypes better than whatever Pycairo does instead? cffi/Qahirah/ctypes 在哪些方面比 Pycairo 做的更好? In what ways is Pycairo not "pythonic"? Pycairo 在哪些方面不是“pythonic”? If cairocffi is better than Pycairo, why is Pycairo more popular, does it have advantages?如果cairocffi比Pycairo好,为什么Pycairo更受欢迎,它有优势吗?

Edit: A comma might be missing after "cffi" in the quote above.编辑:上面引用中的“cffi”后可能缺少逗号 In that case, it's not about "Pycairo vs. cairocffi", but about "Pycairo vs. cairocffi vs. Qahirah".在那种情况下,这不是关于“Pycairo vs. cairocffi”,而是关于“Pycairo vs. cairocffi vs. Qahirah”。

Mimicking the C API closely means that functions take simple arguments. As an example, the move_to function/method looks like this:紧密模仿 C API 意味着函数采用简单的 arguments。例如, move_to函数/方法如下所示:

ctx.move_to(x: float, y: float)→ None

If you want to use (x,y) points or vectors in your program, then at some point you might get annoyed that you need to write, say, move_to(P[0], P[1]) instead of just move_to(P) .如果你想在你的程序中使用 (x,y) 点或向量,那么在某些时候你可能会因为需要写move_to(P[0], P[1])而不仅仅是move_to(P)

In Qahirah you write this:在 Qahirah 你这样写:

p = Vector(x, y)
ctx.move_to(p)

or perhaps也许

ctx.move_to(Vector(x, y))

or even甚至

ctx.move_to((x, y))

You can think of the C API as a base level on top it is possible to build more convenient API.您可以将 C API 视为基础级别,可以构建更方便的 API。

As always, it is a trade-off.与往常一样,这是一种权衡。 Using a direct style C API might be faster (but not much).使用直接样式 C API 可能更快(但不是很多)。

More information can be found in the README for Qahirah:更多信息可以在 Qahirah 的自述文件中找到:

https://github.com/ldo/qahirah 

Then again - if you find a Cairo tutorial using C, it might be easier to use the direct style C API.话又说回来 - 如果你找到一个使用 C 的开罗教程,使用直接样式 C API 可能更容易。

Try them both and see what you like.两者都试一下,看看你喜欢什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM