Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 15 additions & 7 deletions cocoa/src/toga_cocoa/libs/core_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CGAffineTransform(Structure):
core_graphics.CGPathAddArc.restype = c_void_p
core_graphics.CGPathAddArc.argtypes = [
CGMutablePathRef,
CGAffineTransform,
POINTER(CGAffineTransform),
CGFloat,
CGFloat,
CGFloat,
Expand All @@ -86,7 +86,7 @@ class CGAffineTransform(Structure):
core_graphics.CGPathAddCurveToPoint.restype = c_void_p
core_graphics.CGPathAddCurveToPoint.argtypes = [
CGMutablePathRef,
CGAffineTransform,
POINTER(CGAffineTransform),
CGFloat,
CGFloat,
CGFloat,
Expand All @@ -97,34 +97,42 @@ class CGAffineTransform(Structure):
core_graphics.CGPathAddLineToPoint.restype = c_void_p
core_graphics.CGPathAddLineToPoint.argtypes = [
CGMutablePathRef,
CGAffineTransform,
POINTER(CGAffineTransform),
CGFloat,
CGFloat,
]
core_graphics.CGPathAddQuadCurveToPoint.restype = c_void_p
core_graphics.CGPathAddQuadCurveToPoint.argtypes = [
CGMutablePathRef,
CGAffineTransform,
POINTER(CGAffineTransform),
CGFloat,
CGFloat,
CGFloat,
CGFloat,
]
core_graphics.CGPathAddRect.restype = c_void_p
core_graphics.CGPathAddRect.argtypes = [CGMutablePathRef, CGAffineTransform, CGRect]
core_graphics.CGPathAddRect.argtypes = [
CGMutablePathRef,
POINTER(CGAffineTransform),
CGRect,
]
core_graphics.CGPathCloseSubpath.restype = c_void_p
core_graphics.CGPathCloseSubpath.argtypes = [c_void_p]
core_graphics.CGPathIsEmpty.restype = c_bool
core_graphics.CGPathIsEmpty.argtypes = [CGMutablePathRef]
core_graphics.CGPathMoveToPoint.restype = c_void_p
core_graphics.CGPathMoveToPoint.argtypes = [
CGMutablePathRef,
CGAffineTransform,
POINTER(CGAffineTransform),
CGFloat,
CGFloat,
]
core_graphics.CGPathAddPath.restype = c_void_p
core_graphics.CGPathAddPath.argtypes = [CGMutablePathRef, CGAffineTransform, CGPathRef]
core_graphics.CGPathAddPath.argtypes = [
CGMutablePathRef,
POINTER(CGAffineTransform),
CGPathRef,
]

######################################################################
# CGImage.h
Expand Down
40 changes: 14 additions & 26 deletions cocoa/src/toga_cocoa/widgets/canvas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import platform
from collections.abc import Sequence
from copy import copy
from dataclasses import dataclass
Expand Down Expand Up @@ -51,9 +50,7 @@ def add_path(self, path, transform=None):
transform = IDENTITY
else:
transform = core_graphics.CGAffineTransformMake(*transform)
# adding empty path segfaults on intel
if not path.is_empty():
core_graphics.CGPathAddPath(self.native, transform, path.native)
core_graphics.CGPathAddPath(self.native, transform, path.native)

def close_path(self):
core_graphics.CGPathCloseSubpath(self.native)
Expand Down Expand Up @@ -107,28 +104,19 @@ def ellipse(
endangle,
counterclockwise,
):
if (
counterclockwise and platform.machine() == "x86_64"
): # pragma: no-cover-if-arm
# Persistent segfaults in CGPathAddArc with counterclockwise True on intel
# skip for now
return
else: # pragma: no-cover-if-x86
transform = core_graphics.CGAffineTransformMake(1, 0, 0, 1, x, y)
transform = core_graphics.CGAffineTransformRotate(transform, rotation)
transform = core_graphics.CGAffineTransformScale(
transform, radiusx, radiusy
)
core_graphics.CGPathAddArc(
self.native,
transform,
0,
0,
1.0,
startangle,
endangle,
int(counterclockwise),
)
transform = core_graphics.CGAffineTransformMake(1, 0, 0, 1, x, y)
transform = core_graphics.CGAffineTransformRotate(transform, rotation)
transform = core_graphics.CGAffineTransformScale(transform, radiusx, radiusy)
core_graphics.CGPathAddArc(
self.native,
transform,
0,
0,
1.0,
startangle,
endangle,
int(counterclockwise),
)

def rect(self, x, y, width, height):
rectangle = CGRectMake(x, y, width, height)
Expand Down
22 changes: 15 additions & 7 deletions iOS/src/toga_iOS/libs/core_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CGAffineTransform(Structure):
core_graphics.CGPathAddArc.restype = c_void_p
core_graphics.CGPathAddArc.argtypes = [
CGMutablePathRef,
CGAffineTransform,
POINTER(CGAffineTransform),
CGFloat,
CGFloat,
CGFloat,
Expand All @@ -86,7 +86,7 @@ class CGAffineTransform(Structure):
core_graphics.CGPathAddCurveToPoint.restype = c_void_p
core_graphics.CGPathAddCurveToPoint.argtypes = [
CGMutablePathRef,
CGAffineTransform,
POINTER(CGAffineTransform),
CGFloat,
CGFloat,
CGFloat,
Expand All @@ -97,34 +97,42 @@ class CGAffineTransform(Structure):
core_graphics.CGPathAddLineToPoint.restype = c_void_p
core_graphics.CGPathAddLineToPoint.argtypes = [
CGMutablePathRef,
CGAffineTransform,
POINTER(CGAffineTransform),
CGFloat,
CGFloat,
]
core_graphics.CGPathAddQuadCurveToPoint.restype = c_void_p
core_graphics.CGPathAddQuadCurveToPoint.argtypes = [
CGMutablePathRef,
CGAffineTransform,
POINTER(CGAffineTransform),
CGFloat,
CGFloat,
CGFloat,
CGFloat,
]
core_graphics.CGPathAddRect.restype = c_void_p
core_graphics.CGPathAddRect.argtypes = [CGMutablePathRef, CGAffineTransform, CGRect]
core_graphics.CGPathAddRect.argtypes = [
CGMutablePathRef,
POINTER(CGAffineTransform),
CGRect,
]
core_graphics.CGPathCloseSubpath.restype = c_void_p
core_graphics.CGPathCloseSubpath.argtypes = [c_void_p]
core_graphics.CGPathIsEmpty.restype = c_bool
core_graphics.CGPathIsEmpty.argtypes = [CGMutablePathRef]
core_graphics.CGPathMoveToPoint.restype = c_void_p
core_graphics.CGPathMoveToPoint.argtypes = [
CGMutablePathRef,
CGAffineTransform,
POINTER(CGAffineTransform),
CGFloat,
CGFloat,
]
core_graphics.CGPathAddPath.restype = c_void_p
core_graphics.CGPathAddPath.argtypes = [CGMutablePathRef, CGAffineTransform, CGPathRef]
core_graphics.CGPathAddPath.argtypes = [
CGMutablePathRef,
POINTER(CGAffineTransform),
CGPathRef,
]

######################################################################
# CGImage.h
Expand Down
5 changes: 0 additions & 5 deletions testbed/tests/widgets/canvas/test_canvas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import math
import os
import platform
from itertools import chain
from math import pi, radians, tan
from unittest.mock import call
Expand Down Expand Up @@ -995,10 +994,6 @@ async def test_draw_image_in_rect(canvas, probe):
assert_reference(probe, "draw_image_in_rect", threshold=0.05)


@pytest.mark.xfail(
condition=platform.system() == "Darwin" and platform.machine() == "x86_64",
reason="Calls to CGPathAddArc with counterclockwise True segfaults on Mac Intel",
)
async def test_path_object(canvas, probe):
path = Path2D()

Expand Down
Loading