Swiftpack.co -  fwcd/swift-graphics as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
fwcd/swift-graphics
Cross-platform 2D graphics library for Swift
.package(url: "https://github.com/fwcd/swift-graphics.git", from: "v1.1.0")

Swift Graphics

Linux

Cross-platform 2D drawing library for Swift based on Cairo.

Example

// Create a new image and a graphics context
let image = try Image(width: 300, height: 300)
let graphics = CairoGraphics(fromImage: image)

// Draw some shapes
graphics.draw(LineSegment(fromX: 20, y: 20, toX: 50, y: 30))
graphics.draw(Rectangle(fromX: 80, y: 90, width: 10, height: 40, color: Colors.yellow))
graphics.draw(Text("Test", at: Vec2(x: 0, y: 15)))
graphics.draw(Ellipse(centerX: 150, y: 80, radius: 40))

// Encode the image to a byte buffer
let data = try image.pngEncoded()

System Dependencies

  • Swift 5.2+

Linux

  • sudo apt-get install libcairo2-dev
    • If Swift cannot find the Freetype headers despite libfreetype6-dev being installed, you may need to add symlinks:
      • mkdir /usr/include/freetype2/freetype
      • ln -s /usr/include/freetype2/freetype.h /usr/include/freetype2/freetype/freetype.h
      • ln -s /usr/include/freetype2/tttables.h /usr/include/freetype2/freetype/tttables.h
    • Note that you might need to apt-get install clang separately on a Raspberry Pi

macOS

  • brew install cairo

Building

swift build

Testing

swift test

GitHub

link
Stars: 7
Last commit: 6 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Version 1.1.0
6 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API