Skip to content

Commit

Permalink
Remove OpaquePointerProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Dec 14, 2024
1 parent 01cac13 commit 29eaa6a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 46 deletions.
10 changes: 6 additions & 4 deletions Sources/Cairo/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
import CCairo

/// Cairo Context
public final class Context: OpaquePointerOwner {
public final class Context {

// MARK: - Properties

public let surface: Surface

// MARK: - Internal Properties


internal let internalPointer: OpaquePointer

// MARK: - Initialization
Expand All @@ -41,6 +39,10 @@ public final class Context: OpaquePointerOwner {

// MARK: - Methods

public func withUnsafePointer<R, E>(_ body: (OpaquePointer) throws(E) -> R) throws(E) -> R where E: Error {
try body(internalPointer)
}

/// Makes a copy of the current state of the context and saves it on an internal stack of saved states.
/// When `restore()` is called, the context will be restored to the saved state.
/// Multiple calls to `save()` and `restore()` can be nested;
Expand Down
20 changes: 17 additions & 3 deletions Sources/Cairo/Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import CCairo
import CFontConfig
import CFreeType

public final class ScaledFont: OpaquePointerOwner {
public final class ScaledFont {

// MARK: - Properties

Expand Down Expand Up @@ -206,6 +206,10 @@ public final class ScaledFont: OpaquePointerOwner {

// MARK: - Methods

public func withUnsafePointer<R, E>(_ body: (OpaquePointer) throws(E) -> R) throws(E) -> R where E: Error {
try body(internalPointer)
}

public func advances(for glyphs: [FontIndex]) -> [Int] {

return self.lockFontFace { (fontFace) in
Expand Down Expand Up @@ -253,7 +257,7 @@ public typealias FontIndex = UInt16
/// The font's face.
///
/// - Note: Only compatible with FreeType and FontConfig.
public final class FontFace: OpaquePointerOwner {
public final class FontFace {

// MARK: - Properties

Expand Down Expand Up @@ -282,9 +286,15 @@ public final class FontFace: OpaquePointerOwner {
public var type: cairo_font_type_t {
cairo_font_face_get_type(internalPointer) // Never changes
}

// MARK: - Methods

public func withUnsafePointer<R, E>(_ body: (OpaquePointer) throws(E) -> R) throws(E) -> R where E: Error {
try body(internalPointer)
}
}

public final class FontOptions: OpaquePointerOwner {
public final class FontOptions {

// MARK: - Properties

Expand All @@ -310,6 +320,10 @@ public final class FontOptions: OpaquePointerOwner {

// MARK: - Methods

public func withUnsafePointer<R, E>(_ body: (OpaquePointer) throws(E) -> R) throws(E) -> R where E: Error {
try body(internalPointer)
}

public func merge(_ other: FontOptions) {

cairo_font_options_merge(internalPointer, other.internalPointer)
Expand Down
36 changes: 0 additions & 36 deletions Sources/Cairo/OpaquePointerProvider.swift

This file was deleted.

8 changes: 6 additions & 2 deletions Sources/Cairo/Pattern.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import CCairo
/// Represents a source when drawing onto a surface.
///
/// There are different subtypes of patterns, for different types of sources.
public final class Pattern: OpaquePointerOwner {
public final class Pattern {

// MARK: - Internal Properties
// MARK: - Properties

internal var internalPointer: OpaquePointer

Expand Down Expand Up @@ -105,6 +105,10 @@ public final class Pattern: OpaquePointerOwner {

// MARK: - Methods

public func withUnsafePointer<R, E>(_ body: (OpaquePointer) throws(E) -> R) throws(E) -> R where E: Error {
try body(internalPointer)
}

/// Adds an opaque color stop to a gradient pattern.
public func addColorStop(_ offset: Double, red: Double, green: Double, blue: Double) {

Expand Down
6 changes: 5 additions & 1 deletion Sources/Cairo/Surface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import CCairo

public class Surface: OpaquePointerOwner {
public class Surface {

// MARK: - Internal Properties

Expand Down Expand Up @@ -39,6 +39,10 @@ public class Surface: OpaquePointerOwner {

// MARK: - Methods

public func withUnsafePointer<R, E>(_ body: (OpaquePointer) throws(E) -> R) throws(E) -> R where E: Error {
try body(internalPointer)
}

/// Do any pending drawing for the surface and also restore any temporary
/// modifications cairo has made to the surface's state.
/// This function must be called before switching from drawing on the surface
Expand Down

0 comments on commit 29eaa6a

Please sign in to comment.