Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_size():
pixbuf_obj, format_name = pixbuf.decode_to_pixbuf(PNG_BYTES, 10, 10)
assert format_name == 'png'
surface = pixbuf.pixbuf_to_cairo_png(pixbuf_obj)
assert surface.get_width() == 10
assert surface.get_height() == 10
assert surface.get_format() == constants.FORMAT_ARGB32
def test_png():
pixbuf_obj, format_name = pixbuf.decode_to_pixbuf(JPEG_BYTES)
assert format_name == 'jpeg'
assert_decoded(pixbuf.pixbuf_to_cairo_slices(pixbuf_obj),
constants.FORMAT_RGB24, b'\xff\x00\x80\xff')
**Note**: this unsafely inteprets an integer as a pointer.
Make sure it actually points to a valid DC!
:type hdc: int
*New in cairocffi 0.6*
"""
def __init__(self, hdc):
pointer = cairo.cairo_win32_printing_surface_create(
ffi.cast('void*', hdc))
Surface.__init__(self, pointer)
SURFACE_TYPE_TO_CLASS = {
constants.SURFACE_TYPE_IMAGE: ImageSurface,
constants.SURFACE_TYPE_PDF: PDFSurface,
constants.SURFACE_TYPE_SVG: SVGSurface,
constants.SURFACE_TYPE_RECORDING: RecordingSurface,
constants.SURFACE_TYPE_WIN32: Win32Surface,
constants.SURFACE_TYPE_WIN32_PRINTING: Win32PrintingSurface
}
*New in cairocffi 0.6*
"""
def __init__(self, hdc):
pointer = cairo.cairo_win32_printing_surface_create(
ffi.cast('void*', hdc))
Surface.__init__(self, pointer)
SURFACE_TYPE_TO_CLASS = {
constants.SURFACE_TYPE_IMAGE: ImageSurface,
constants.SURFACE_TYPE_PDF: PDFSurface,
constants.SURFACE_TYPE_SVG: SVGSurface,
constants.SURFACE_TYPE_RECORDING: RecordingSurface,
constants.SURFACE_TYPE_WIN32: Win32Surface,
constants.SURFACE_TYPE_WIN32_PRINTING: Win32PrintingSurface
}
def __init__(self, family='', slant=constants.FONT_SLANT_NORMAL,
weight=constants.FONT_WEIGHT_NORMAL):
FontFace.__init__(self, cairo.cairo_toy_font_face_create(
_encode_string(family), slant, weight))
def _check_status(status):
"""Take a cairo status code and raise an exception if/as appropriate."""
if status != constants.STATUS_SUCCESS:
exception = STATUS_TO_EXCEPTION.get(status, CairoError)
status_name = ffi.string(ffi.cast("cairo_status_t", status))
message = 'cairo returned %s: %s' % (
status_name, ffi.string(cairo.cairo_status_to_string(status)))
raise exception(message, status)
def pixbuf_to_cairo_gdk(pixbuf):
"""Convert from PixBuf to ImageSurface, using GDK.
This method is fastest but GDK is not always available.
"""
dummy_context = Context(ImageSurface(constants.FORMAT_ARGB32, 1, 1))
gdk.gdk_cairo_set_source_pixbuf(
dummy_context._pointer, pixbuf._pointer, 0, 0)
return dummy_context.get_source().get_surface()
def __init__(self, family='', slant=constants.FONT_SLANT_NORMAL,
weight=constants.FONT_WEIGHT_NORMAL):
FontFace.__init__(self, cairo.cairo_toy_font_face_create(
_encode_string(family), slant, weight))
as obtained from :func:`win32gui.CreateDC`.
**Note**: this unsafely inteprets an integer as a pointer.
Make sure it actually points to a valid DC!
:type hdc: int
*New in cairocffi 0.6*
"""
def __init__(self, hdc):
pointer = cairo.cairo_win32_printing_surface_create(
ffi.cast('void*', hdc))
Surface.__init__(self, pointer)
SURFACE_TYPE_TO_CLASS = {
constants.SURFACE_TYPE_IMAGE: ImageSurface,
constants.SURFACE_TYPE_PDF: PDFSurface,
constants.SURFACE_TYPE_SVG: SVGSurface,
constants.SURFACE_TYPE_RECORDING: RecordingSurface,
constants.SURFACE_TYPE_WIN32: Win32Surface,
constants.SURFACE_TYPE_WIN32_PRINTING: Win32PrintingSurface
}
:type hdc: int
*New in cairocffi 0.6*
"""
def __init__(self, hdc):
pointer = cairo.cairo_win32_printing_surface_create(
ffi.cast('void*', hdc))
Surface.__init__(self, pointer)
SURFACE_TYPE_TO_CLASS = {
constants.SURFACE_TYPE_IMAGE: ImageSurface,
constants.SURFACE_TYPE_PDF: PDFSurface,
constants.SURFACE_TYPE_SVG: SVGSurface,
constants.SURFACE_TYPE_RECORDING: RecordingSurface,
constants.SURFACE_TYPE_WIN32: Win32Surface,
constants.SURFACE_TYPE_WIN32_PRINTING: Win32PrintingSurface
}