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
2 changes: 1 addition & 1 deletion Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 17 additions & 8 deletions Sources/OpenRenderBox/Path/ORBPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ public struct ORBPathLineShape: @unchecked Sendable {

public struct ORBPathStrokeStyle: @unchecked Sendable {
public var lineWidth: CGFloat
public var lineCap: Int32
public var lineJoin: Int32
public var lineCap: CGLineCap
public var lineJoin: CGLineJoin
public var miterLimit: CGFloat
public var dashPhase: CGFloat
public var dashCount: UInt64
public var dash: UnsafePointer<CGFloat>?

public init(
lineWidth: CGFloat,
lineCap: Int32,
lineJoin: Int32,
lineCap: CGLineCap,
lineJoin: CGLineJoin,
miterLimit: CGFloat,
dashPhase: CGFloat,
dashCount: UInt64,
Expand Down Expand Up @@ -662,7 +662,7 @@ extension ORBPath {
var shape = ORBPathShape(
rect: zeroRect, ellipse: zeroRect,
fixedRoundedRect: .init(transform: .identity, rect: .zero, cornerSize: .zero, style: .circular),
stroked: .init(path: self, style: .init(lineWidth: 0, lineCap: 0, lineJoin: 0, miterLimit: 0, dashPhase: 0, dashCount: 0, dash: nil))
stroked: .init(path: self, style: .init(lineWidth: 0, lineCap: .butt, lineJoin: .miter, miterLimit: 0, dashPhase: 0, dashCount: 0, dash: nil))
)
let type: ORBPathShapeType
var ownedChild: ORBPath?
Expand All @@ -687,9 +687,18 @@ extension ORBPath {
default:
type = .stroked
strokeDash = record.stroke?.dash ?? []
shape.stroked = .init(path: child, style: .init(lineWidth: record.values[0], lineCap: record.stroke?.lineCap ?? 0,
lineJoin: record.stroke?.lineJoin ?? 0, miterLimit: record.values[1], dashPhase: record.values[2],
dashCount: UInt64(strokeDash!.count), dash: nil))
shape.stroked = .init(
path: child,
style: .init(
lineWidth: record.values[0],
lineCap: CGLineCap(rawValue: record.stroke?.lineCap ?? 0) ?? .butt,
lineJoin: CGLineJoin(rawValue: record.stroke?.lineJoin ?? 0) ?? .miter,
miterLimit: record.values[1],
dashPhase: record.values[2],
dashCount: UInt64(strokeDash!.count),
dash: nil
)
)
}
} else if records.count == 1, let record = records.first {
switch record.element {
Expand Down
13 changes: 12 additions & 1 deletion Sources/OpenRenderBoxCxx/Path/ORBPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,18 @@ bool ORBPathApplyShape(
static const CGFloat emptyDash = 0;
size_t count = stroke.values ? stroke.count : 0;
auto *dash = count ? static_cast<const CGFloat *>(stroke.values) : &emptyDash;
shape.stroked = {nested, {values[0], stroke.cap, stroke.join, values[1], values[2], count, dash}};
shape.stroked = {
nested,
{
values[0],
static_cast<CGLineCap>(stroke.cap),
static_cast<CGLineJoin>(stroke.join),
values[1],
values[2],
count,
dash,
},
};
type = ORBPathShapeTypeStroked;
}
info->callback(info->info, type, &shape);
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenRenderBoxCxx/Path/ORBPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ typedef struct ORBPathLineShape {

typedef struct ORBPathStrokeStyle {
CGFloat lineWidth;
int32_t lineCap;
int32_t lineJoin;
CGLineCap lineCap;
CGLineJoin lineJoin;
CGFloat miterLimit;
CGFloat dashPhase;
uint64_t dashCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ struct PathOperationsTests {
let path = lhs.interpolated(to: rhs, fraction: 0.25)
lhs.release()
rhs.release()
struct Result { var width: CGFloat = 0; var cap: Int32 = -1; var dash: [CGFloat] = []; var child = ORBPath.empty }
struct Result { var width: CGFloat = 0; var cap: CGLineCap = .butt; var dash: [CGFloat] = []; var child = ORBPath.empty }
var result = Result()
#expect(path.applyShape(allowLine: true, info: &result) { info, type, shape in
if type == .stroked {
Expand All @@ -194,7 +194,7 @@ struct PathOperationsTests {
path.release()
defer { result.child.release() }
#expect(result.width == 1.5)
#expect(result.cap == 2)
#expect(result.cap == .square)
#expect(result.dash == [3, 5, 7])
#expect(result.child.boundingRect == CGRect(x: 1.5, y: 2.5, width: 15, height: 25))
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/OpenRenderBoxTests/Path/PortablePathTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ struct PortablePathTests {
let mixedStroke = lhs.interpolated(to: rhs, fraction: 0.25)
lhs.release()
rhs.release()
struct StrokeResult { var width: CGFloat = 0; var cap: Int32 = -1; var dash: [CGFloat] = []; var child = ORBPath.empty }
struct StrokeResult { var width: CGFloat = 0; var cap: CGLineCap = .butt; var dash: [CGFloat] = []; var child = ORBPath.empty }
var result = StrokeResult()
let strokeRecognized = withUnsafeMutablePointer(to: &result) { resultPtr in
mixedStroke.applyShape(allowLine: true, info: resultPtr) { info, type, shape in
Expand All @@ -390,7 +390,7 @@ struct PortablePathTests {
mixedStroke.release()
defer { result.child.release() }
#expect(result.width == 1.5)
#expect(result.cap == 2)
#expect(result.cap == .square)
#expect(result.dash == [3, 5, 7])
#expect(result.child.boundingRect == CGRect(x: 1.5, y: 2.5, width: 15, height: 25))

Expand Down
Loading