Commit Graph

48 Commits

Author SHA1 Message Date
Christoph Reiter a10af0bb9f travis-ci: add Python 3.7, drop 3.3 2018-07-07 16:33:50 +02:00
Christoph Reiter c04e32eb07 surface: override the __exit__() handle for mapped images
With the context manager support for surfaces this also has started to
work for mapped images but finishing a mapped one is undefined.

Add a new __exit__() which unmaps the image instead and makes this valid:

with surface.map_to_image(None) as image:
    pass
2018-03-27 20:59:39 +02:00
Christoph Reiter 5d2fe236ee Fix a leak when a mapped surface gets GCed instead of unmapped
missing unref of the base surface
2018-03-27 19:35:59 +02:00
Christoph Reiter 6d3b0addb2 Make cairo.Surface and cairo.Device context managers. Fixes #103
calls finish() in __exit__()
2018-03-27 16:51:07 +02:00
Christoph Reiter 6e14bbf621 setup.py: get rid of config.h
Just pass the macros at compile time.
2018-01-21 22:05:11 +01:00
Christoph Reiter 074f0b24b8 enums: Don't assume enums are int when parsing Python args.
Instead cast the parsed int explicitly to the enum type which
might be unsigned.

Still not perfect, as the enum type can be smaller, but I don't
think any compiler does that.
2017-11-07 23:01:36 +01:00
Christoph Reiter 9bc5fb7ba1 Try using more warning flags when testing and fail for warnings under msvc
We can't check if the compiler supports the flags, so enable
them only when PYCAIRO_WARN is defined in the environment.
2017-09-16 17:06:40 +02:00
Christoph Reiter a999325825 compiler warning 2017-08-18 22:38:18 +02:00
Christoph Reiter 9b2d4d2a3a fspaths: improve error messages for methods taking filenames or file objects
First decide on the input type and only parse once instead of parsing
multiple times and throwing away the filename parsing errors.
2017-08-18 22:33:31 +02:00
Christoph Reiter e4fc9db660 Add support for all fspaths 2017-08-18 16:27:37 +02:00
Christoph Reiter 52d85932e1 surface: some cleanup 2017-08-16 18:31:22 +02:00
Christoph Reiter 23933c3658 Add cairo.Rectangle. Fixes #54 2017-07-22 21:42:44 +02:00
Christoph Reiter df880d58f5 docs: Move the C API documentation from the source code into the docs. Fixes #58
Also add some more info regarding ownership transfer and error handling.
2017-07-19 11:27:33 +02:00
Christoph Reiter 65aea3dfdc Surface.get_device() fix missing ref. Fixes #57 2017-07-14 13:19:54 +02:00
Christoph Reiter b780969870 Implement richcompare for Surface and Path. See #52
So that two instances wrapping the same object compare equally.
2017-07-14 09:21:29 +02:00
Christoph Reiter 96a2a26f10 Add Surface.map_to_image() and Surface.unmap_image(). Fixes #51
This keeps the same API as cairo but adds some additional checks
to prevent crashes. Those cases still are undefined but at least
you get some error messages.

* It adds a new ImageSurface subtype so we can do some type checking.
* It swaps the underlying image surface to a dummy finished one
  when it gets unmapped so that operations after unmap
  on the wrapper don't crash.
* It checks if the source surface is correct when unmapping.
2017-07-13 16:38:19 +02:00
Christoph Reiter 4b8aba8a97 Add TeeSurface 2017-07-11 20:20:15 +02:00
Christoph Reiter 065a7a7aed set_device_scale: do some extra validation before passing things to cairo since that can crash. Fixes #50 2017-07-11 08:34:08 +02:00
Christoph Reiter c8713e8132 Add cairo.ScriptSurface. Fixes #17 2017-07-10 10:10:56 +02:00
Christoph Reiter 0240732fce Add cairo.Device() class and Surface.get_device()
This only adds new Python API an no C API for now.
2017-07-07 09:45:09 +02:00
Sander Sweers 498dc027a0 Add device scaling functions
These were added for HiDPI displays in cairo 1.14.
2017-07-01 12:18:44 +02:00
Christoph Reiter 4ab80df68d bufferproxy: properly pass flags to PyBuffer_FillInfo; also expose the readonly flag 2017-05-31 21:44:44 +02:00
Christoph Reiter 07ee64b3fb Fix leak when using ImageSurface.get_data() with Python 3. Fixes #41
Turns out the buffer/memoryview API can only be used in implementations
of the buffer protocol of some object and the current approach
worked by accident and for some unknown reason leaked the exporter as
well.

This creates a new Python class implementing the buffer interface,
which takes the buffer information and is only used to keep the
image surface alive and to hand out memory views.

In case the last view dies, the proxy will die and unref the image
surface.
2017-05-31 21:35:42 +02:00
Christoph Reiter 66534d99ea Change all functions returning enum values to return instances of the new enum types
This includes cairo.Error.status, which is now a cairo.Status
2017-05-02 13:32:45 +02:00
Christoph Reiter 4fee87d3e2 imagesurface: Implement bf_getcharbuffer interface
This should make PyObject_AsCharBuffer work which for example pygame uses.
2017-05-01 15:23:43 +02:00
Christoph Reiter 2a58f46754 imagesurface: Fix signature for PyBufferProcs functions
They should all be using Py_ssize_t and not int
2017-05-01 15:23:43 +02:00
Christoph Reiter 457652f0d8 SVGSurface: Add version API
This adds:

* cairo.SVG_VERSION_1_1 and cairo.SVG_VERSION_1_2
* cairo.SVGSurface.restrict_to_version()
* cairo.SVGSurface.get_versions()
* cairo.SVGSurface.version_to_string()
2017-04-18 00:14:40 +02:00
Christoph Reiter 62b9ca315b Add RecordingSurface.get_extents() 2017-04-18 00:12:59 +02:00
Christoph Reiter 7934a0e384 Add PSSurface.get_levels() and PSSurface.level_to_string()
level_to_string() already existed under ps_level_to_string() but the
naming is inconsistend with similar functions.
This just adds another alias and adds a note in the docs.
2017-04-16 17:15:24 +02:00
Christoph Reiter 29c0f0e3f6 Add Surface.has_show_text_glyphs() 2017-04-16 16:57:36 +02:00
Christoph Reiter 91961c6004 Always expose XCBSurface.set_size()
It doesn't require xpyb to work, so there is no reason to hide it.
2017-04-16 16:45:08 +02:00
Christoph Reiter 2544535c7c PDFSurface: Add version API
This adds:

* cairo.PDF_VERSION_1_4 and cairo.PDF_VERSION_1_5
* cairo.PDFSurface.restrict_to_version()
* cairo.PDFSurface.get_versions()
* cairo.PDFSurface.version_to_string()
2017-04-16 16:20:17 +02:00
Christoph Reiter a196d9c3dc Add Surface.create_similar_image() 2017-04-16 16:14:37 +02:00
Christoph Reiter 9d97f834c0 Add Surface.create_for_rectangle() 2017-04-16 15:41:34 +02:00
Christoph Reiter be23eb87cf surface: Tie lifetime of surface base objects to the surface, not the wrapper. Fixes #11
In case the cairo.Surface got deallocated it took the base object with it, but the surface
could still be referenced from some other place like a cairo.Context/SurfacePattern.
In case the referencing object would then try to use the surface things crash.

Tie the lifetime to the actual object instead using the user_data API.
2017-04-16 13:02:30 +02:00
Christoph Reiter 0170e90026 surface: Add mime data support. Fixes #7
Add Surface.set_mime_data(), Surface.get_mime_data(),
Surface.supports_mime_type(), HAS_MIME_SURFACE, MIME_TYPE_*.

set_mime_data() takes a buffer and keeps it alive.
get_mime_data() tries to return the same object.
2017-04-16 10:56:42 +02:00
Christoph Reiter eeea4de31f cairo.Error: add a status attribute; add CairoError alias
This extends the cairo.Error exception type to have a status attribute
containing the cairo_status_t constants. This is what cairocffi
implements and will also make testing for specific error cases easier.

Also adds an cairo.CairoError alias to be compatible with the default
cairocffi naming.

Switch some functions which raise cairo.Error on programming errors
to ValueError, so we have a valid status value in all cases.
2017-04-16 10:47:34 +02:00
Christoph Reiter 1579d7cb0b Use c90 and enforce it on travis. Fixes #5 2017-04-14 08:54:06 +02:00
Christoph Reiter 6b956ad986 Re-add support for RecordingSurface
This time without breaking ABI
2017-04-12 15:32:53 +02:00
Christoph Reiter 55259f63c5 Revert "Add support for RecordingSurface, using patch (modified) from bug #36854. Add docs and tests for RecordingSurface. Adding the RecordingSurface to the pycairo API breaks ABI compatibility with previous pycairo versions."
This reverts commit c4df9b51c8.

I didn't notice that pyc2cairo master also broke ABI :(
2017-04-12 15:14:10 +02:00
Christoph Reiter 52c270b0a1 Revert "Remove xpyb support."
This reverts commit e00cd9d634.

Fedora builds pycairo with xpyb and has some packages depending on it.
So we have to keep it and figure out how to build it.
2017-04-09 16:13:01 +02:00
Christoph Reiter a44bcccb42 surface: Fix handle value truncation on win64
HDC is a pointer which doesn't fit int on amd64,
so use PyLong_AsVoidPtr instead.
2017-04-09 15:21:04 +02:00
Christoph Reiter e00cd9d634 Remove xpyb support.
It's Python 2 only and was never enabled for py2/3 on debian/ubuntu
so this should not change much.

Handle instantiating of XCBSurface like is currently done for
XlibSurface. Getting an instance through the C-API still works.

If support gets added back we should look into xcffib, which is
what cairocffi uses. It also has the advandage that we don't
have to link against it and can use it at runtime.
2017-04-09 11:09:47 +02:00
Christoph Reiter 062f75a75c python3: Expose cairo.Error and fix raising it
Instead of using the global error object look up the module+state
and fetch the error object from there.
2017-04-08 20:40:54 +02:00
Christoph Reiter a158d9a658 image surface: Implement get_data() and create_for_data() for Python 3
get_data() returns a memoryview object (using bytes) on Python 3
create_for_data() uses the old deprecated code paths.
2017-04-08 20:40:37 +02:00
Christoph Reiter bb8981799c PDFSurface/PSSurface: properly clear exceptions if the write func raises an exception 2017-04-08 14:38:39 +02:00
Christoph Reiter 727470e8a1 Port to Python 3 2017-04-07 11:15:35 +02:00
Christoph Reiter 7630f6d7d0 Rename src->cairo, doc->docs, test->tests 2017-04-07 09:45:40 +02:00