Skip to content

Commit

Permalink
Finishing BLFont interface implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizZak committed May 22, 2019
1 parent de7c9b7 commit 92ef7ea
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
29 changes: 29 additions & 0 deletions Sources/SwiftBlend2D/BLArray.swift
Expand Up @@ -126,6 +126,23 @@ public final class BLArray<Element: BLArrayElement> {
}
}

extension BLArray: Sequence {
public __consuming func makeIterator() -> AnyIterator<Element> {
var index = 0

return AnyIterator {
if index >= self.count {
return nil
}
defer {
index += 1
}

return self[index]
}
}
}

/// A protocol that is used to parameterize `BLArray` instances.
public protocol BLArrayElement {
/// Returns a `BLImplType` for the array of elements corresponding to `Self`
Expand Down Expand Up @@ -218,3 +235,15 @@ extension UInt: BLArrayElement {
: UInt64.arrayImplementationType
}
}
extension BLFontFeature: BLArrayElement {
@inlinable
public static var arrayImplementationType: BLArrayType {
return BLArrayType(arrayType: .arrayOfStruct_8)
}
}
extension BLFontVariation: BLArrayElement {
@inlinable
public static var arrayImplementationType: BLArrayType {
return BLArrayType(arrayType: .arrayOfStruct_8)
}
}
2 changes: 1 addition & 1 deletion Sources/SwiftBlend2D/BLFile.swift
Expand Up @@ -3,7 +3,7 @@ import Foundation
#endif
import blend2d

/// A thin abstraction over a native OS file IO [C++ API].
/// A thin abstraction over a native OS file IO.
///
/// A thin wrapper around a native OS file support. The file handle is always
/// `intptr_t` and it refers to either a file descriptor on POSIX targets and
Expand Down
22 changes: 22 additions & 0 deletions Sources/SwiftBlend2D/BLFont.swift
Expand Up @@ -39,6 +39,28 @@ public class BLFont: BLBaseClass<BLFontCore> {
public var face: BLFontFace {
return BLFontFace(weakAssign: object.impl.pointee.face)
}

/// Gets font-features of the font.
public var features: [BLFontFeature] {
return Array(BLArray<BLFontFeature>(weakAssign: object.impl.pointee.features))
}
/// Gets font-variations used by this font.
public var variations: [BLFontVariation] {
return Array(BLArray<BLFontVariation>(weakAssign: object.impl.pointee.variations))
}

/// Gets the weight of the font.
public var weight: UInt16 {
return object.impl.pointee.weight
}
/// Gets the stretch of the font.
public var stretch: UInt8 {
return object.impl.pointee.stretch
}
/// Gets the style of the font.
public var style: UInt8 {
return object.impl.pointee.style
}

public init(fromFace face: BLFontFace, size: Float) {
super.init { pointer -> BLResult in
Expand Down
6 changes: 3 additions & 3 deletions Status.md
Expand Up @@ -8,8 +8,8 @@ This may change at any moment.
|-----|-----|-----|
`BLApproximationOptions` | ✅ Done | |
`BLArc` | ✅ Done | Arc specified as [cx, cy, rx, ry, start, sweep[ using double as a storage type |
`BLArray` | 🕒 Partial | Array container (template) [C++ API]|
`BLArrayView` | ℹ️ Not portable | `(Appears to be a C++-exclusive API)` |
`BLArray` | ✅ Done | Array container (template) [C++ API]|
`BLArrayView` | ✅ Done | |
`BLBox` | ✅ Done | Box specified as [x0, y0, x1, y1] using double as a storage type |
`BLBoxI` | ✅ Done | Box specified as [x0, y0, x1, y1] using int as a storage type |
`BLCircle` | ✅ Done | Circle specified as [cx, cy, r] using double as a storage type |
Expand All @@ -23,7 +23,7 @@ This may change at any moment.
`BLEllipse` | ✅ Done | Ellipse specified as [cx, cy, rx, ry] using double as a storage type |
`BLExternalImplPreface` | ℹ️ No work required | |
`BLFile` | ✅ Done | |
`BLFont` | 🕒 Partial | Font [C++ API]|
`BLFont` | ✅ Done | Font [C++ API]|
`BLFontData` | 🕒 Partial | Font data [C++ API] `(Missing Swift tests)` |
`BLFontDesignMetrics` | ℹ️ No work required | |
`BLFontFace` | 🕒 Partial | Font face [C++ API] `(Missing Swift tests)` |
Expand Down

0 comments on commit 92ef7ea

Please sign in to comment.