Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api mode cffi compile #230

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
__pycache__
_cairocffi*.o
_cairocffi*.so
_cairocffi*.c
_cairocffi*.py
_cairocffi_pixbuf*.o
_cairocffi_pixbuf*.so
_cairocffi_pixbuf*.c
_cairocffi_pixbuf*.py
_cairocffi_xcb*.o
_cairocffi_xcb*.so
_cairocffi_xcb*.c
_cairocffi_xcb*.py
cairocffi/_ffi*.py
*.egg
*.egg-info
Expand Down
32 changes: 26 additions & 6 deletions cairocffi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,32 @@
from ctypes.util import find_library

from . import constants
from .ffi import ffi

VERSION = __version__ = '1.7.1'

VERSION = __version__ = '1.7.2'
# supported version of cairo, used to be pycairo version too:
version = '1.17.2'
version_info = (1, 17, 2)


# Attempt api mode, then precompiled abi mode, then import time abi
cffi_mode = "(unknown)"
try:
# Note in ABI mode lib is already available, no dlopen() needed
from ._cairocffi import ffi, lib as cairo
cffi_mode = "api"
except ImportError:
try:
# Note in ABI mode lib will be missing
from ._cairocffi import ffi
cffi_mode = "abi_precompiled"
except ImportError:
# Fall back to importing and parsing cffi defs
from .ffi_build import ffi_for_mode
ffi = ffi_for_mode("abi")
cffi_mode = "abi"


# Python 3.8 no longer searches for DLLs in PATH, so we can add everything in
# CAIROCFFI_DLL_DIRECTORIES manually. Note that unlike PATH, add_dll_directory
# has no defined order, so if there are two cairo DLLs in PATH we might get a
Expand Down Expand Up @@ -57,10 +75,12 @@ def dlopen(ffi, library_names, filenames):
raise OSError(error_message) # pragma: no cover


cairo = dlopen(
ffi, ('cairo-2', 'cairo', 'libcairo-2'),
('libcairo.so.2', 'libcairo.2.dylib', 'libcairo-2.dll'))

# Fall back to non api mode, inline at load time
# this would only happen if the precompiled cairocffi was missing
if cffi_mode != "api":
cairo = dlopen( # noqa
ffi, ('cairo-2', 'cairo', 'libcairo-2'),
('libcairo.so.2', 'libcairo.2.dylib', 'libcairo-2.dll'))

class _keepref(object): # noqa: N801
"""Function wrapper that keeps a reference to another object."""
Expand Down
22 changes: 13 additions & 9 deletions cairocffi/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,12 @@
typedef enum _cairo_antialias {
CAIRO_ANTIALIAS_DEFAULT,


CAIRO_ANTIALIAS_NONE,
CAIRO_ANTIALIAS_GRAY,
CAIRO_ANTIALIAS_SUBPIXEL,


CAIRO_ANTIALIAS_FAST,
CAIRO_ANTIALIAS_GOOD,
CAIRO_ANTIALIAS_BEST
Expand Down Expand Up @@ -1827,9 +1827,9 @@
typedef struct _cairo_region cairo_region_t;

typedef enum _cairo_region_overlap {
CAIRO_REGION_OVERLAP_IN,
CAIRO_REGION_OVERLAP_OUT,
CAIRO_REGION_OVERLAP_PART
CAIRO_REGION_OVERLAP_IN,
CAIRO_REGION_OVERLAP_OUT,
CAIRO_REGION_OVERLAP_PART
} cairo_region_overlap_t;

cairo_region_t *
Expand Down Expand Up @@ -2085,11 +2085,12 @@
cairo_svg_unit_t
cairo_svg_surface_get_document_unit (cairo_surface_t *surface);

"""

_CAIRO_WIN32_HEADERS = r"""
typedef void* HDC;
typedef void* HFONT;
typedef void LOGFONTW;


cairo_surface_t *
cairo_win32_surface_create (HDC hdc);
Expand Down Expand Up @@ -2133,6 +2134,7 @@

void
cairo_win32_scaled_font_done_font (cairo_scaled_font_t *scaled_font);
:w

double
cairo_win32_scaled_font_get_metrics_factor (cairo_scaled_font_t *scaled_font);
Expand All @@ -2144,12 +2146,13 @@
void
cairo_win32_scaled_font_get_device_to_logical (cairo_scaled_font_t *scaled_font,
cairo_matrix_t *device_to_logical);
"""


_CAIRO_QUARTZ_HEADERS = r"""
typedef void* CGContextRef;
typedef void* CGFontRef;
typedef void* ATSUFontID;
typedef unsigned int ATSUFontID;


cairo_surface_t *
cairo_quartz_surface_create (cairo_format_t format,
Expand Down Expand Up @@ -2227,3 +2230,4 @@
cairo_xcb_device_debug_get_precision (cairo_device_t *device);

"""

90 changes: 0 additions & 90 deletions cairocffi/ffi.py

This file was deleted.

Loading