Hi,
I am getting my hands on cairo for the first time. Rendering quality
is good but api is pretty ugly.
Any way, Here I am trying to render a text and saving as bitmap. The
text is not getting rendered on the bitmap.
You may need to delay creating the context (or recreate it) until after the bitmap has been selected into the DC. The DC won't be fully valid until it has a bitmap selected into it, so ContextFromDC may be failing. Also, you may want to try using show_text instead of text_path.
···
On 12/14/09 6:19 AM, King wrote:
Hi,
I am getting my hands on cairo for the first time. Rendering quality
is good but api is pretty ugly.
Any way, Here I am trying to render a text and saving as bitmap. The
text is not getting rendered on the bitmap.
BTW, you may want to look at wx.lib.graphics. It is a wx.GraphcsContext-like (IOW, mostly compatible) implantation done in Python code that uses Cairo on all the platforms. The main thing that it does for you is allowing you to avoid the ugly cairo API, but still be able to use the same backend on all platforms. You can still use Cairo APIs if needed.
In some simple benchmarks I did a while back it's lots faster than wx.GraphicsContext on Windows since it is not using GDI+. On GTK and Mac it's a little slower than wx.GraphicsContext, but not by very much.
···
On 12/14/09 6:19 AM, King wrote:
Hi,
I am getting my hands on cairo for the first time. Rendering quality
is good but api is pretty ugly.
In some simple benchmarks I did a while back it's lots faster than
wx.GraphicsContext on Windows since it is not using GDI+. On GTK and
Mac it's a little slower than wx.GraphicsContext, but not by very much.
The application I am writing is heavily used wxGraphicContext. The
simple reason
is rendering quality offered by it compare to other DCs. Although
cairo rendering
is much better but I am a bit unaware how perfectly cairo+wxPython are
glued on Linux and Mac.
There are some simple tests in the sandbox folder in the source repository. See the test_cairoContext*.py files in wxTrac has been migrated to GitHub Issues - wxWidgets. There is also a test_cairo.py script there that tests using the basic Cairo APIs from wxPython.
DrawText should be drawing the text in anti-alias mode, or at least with the same anti-alias setting that it is using for everything else. See the attached screenshot of part of one of the samples I pointed you to yesterday, along with a zoom in on the text. If you're not getting the same results then something is wrong.
Although it's rendering the text but not at correct position and does
not render
as per the font that has been assigned earlier using SetFont method.
See the implementation of DrawText for what has to be done to apply the font and to offset the text origin correctly. You have the source code, use it.