CGFont and CTFont functionality in portable Swift

2020-05-08 07:35发布

问题:

Swift on macOS, the import Foundation statement is sufficient to link with CGFont, CTFont and related functions.

import Foundation

public struct FontMetric {

    let cgFont: CGFont
    private let ctFont: CTFont
    // ... 

However, for Swift on Ubuntu, the CGFont, CTFont and related functions cause "undeclared type" errors:

FontMetric.swift:21:17: error: use of undeclared type 'CGFont'
    let cgFont: CGFont
                ^~~~~~
FontMetric.swift:24:25: error: use of undeclared type 'CTFont'
    private let ctFont: CTFont
                        ^~~~~~

Is there a way to either install the CoreGraphics/CoreText libraries on other (non-Apple) platforms like Ubuntu?

Alternately, is there some portable open-source swift-compatible (e.g. C) library that offers functionality similar to CGFont and CTFont?


Answers like coregraphics on gnustep ubuntu would indicate that CoreGraphics is not in GNUStep.