Swiftpack.co - krzyzanowskim/CoreTextSwift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by krzyzanowskim.
krzyzanowskim/CoreTextSwift 0.0.2
CoreText Swift bindings
⭐️ 146
🕓 1 year ago
iOS macOS
.package(url: "https://github.com/krzyzanowskim/CoreTextSwift.git", from: "0.0.2")

CoreTextSwift

Swifty CoreText API.

CoreText is C API. This library is a set of wrappers and extensions that makes it convenient to work with Swift.

Example

Draw line in currect graphics context

guard let ctx = UIGraphicsGetCurrentContext() else {
  return
}

let attributedString = NSAttributedString(string: "abcdefgh")
ctx.draw(attributedString.line())

Use Glyph Run

let attributedString = NSAttributedString(string: "abcdefgh")

for run in attributedString.line().glyphRuns() {
  let font = run.font
  for glyph in run.glyphs() {
    let glyphPath = font.path(for: glyph)
  }
}

Draw Glyph Run to CGContext

guard let ctx = UIGraphicsGetCurrentContext() else {
  return
}

for run in attributedString.line().glyphRuns() {
  run.draw(in: ctx)
}

GitHub

link
Stars: 146
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1 year ago

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