GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Tremollo/GraphicsRenderer: A drop-in UIGraphicsRenderer port -- CrossPlatform, Swift 3, Image & PDF

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

24 Commits
24 Commits

Folders and files

NameName
Last commit message
Last commit date
Example
Example
 
 
GraphicsRenderer/Classes
GraphicsRenderer/Classes
 
 
.gitignore
.gitignore
 
 
.swift-version
.swift-version
 
 
GraphicsRenderer.podspec
GraphicsRenderer.podspec
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
sample.png
sample.png
 
 

Repository files navigation

GraphicsRenderer

Version License Language Platform

Introduction

GraphicsRenderer is designed to a drop-in UIGraphicsRenderer port. For this reason, all function names are matched to make it easy to swap out a later date.

UIGraphicsRendererFormat > RendererFormat
UIGraphicsImageRendererFormat > ImageRendererFormat
UIGraphicsPDFRendererFormat > PDFRendererFormat

UIGraphicsRendererContext > RendererContext
UIGraphicsImageRendererContext > PDFRendererContext
UIGraphicsPDFRendererContext > PDFRendererContext

The classes you'll mostly work with though are:

UIGraphicsRenderer > Renderer
UIGraphicsImageRenderer > ImageRenderer
UIGraphicsPDFRenderer > PDFRenderer

GraphicsRenderer is also cross-platform with iOS and macOS demo projects included in the repo.

GraphicsRenderer matches the entire API currently available from UIGraphicsRenderer, however to make it work nicely with all platforms, it also includes some additional convenience's, like flipping the context.

GraphicsRenderer is also protocol based, which makes it more Swifty and allows for some nice generics driven integration as you can see in the performDrawing() example.

InkKit

I have another library called InkKit which now uses this library for its inner workings. For a LOT more drawing and layout convenience's -- checkout that library too.~~

Note: If you include InkKit in your project, you don't need to include this project too.

Example

There are 2 example projects included in the repo. One for iOS and another for OSX.

Simply select the appropriate scheme, build and run.

Lets start by creating a simple drawing function:

func performDrawing<Context: RendererContext>(context: Context) {
	let rect = context.format.bounds
    UIColor.white.setFill()
    context.fill(rect)
    
    UIColor.blue.setStroke()
    let frame = CGRect(x: 10, y: 10, width: 40, height: 40)
    context.stroke(frame)
    
    UIColor.red.setStroke()
    context.stroke(rect.insetBy(dx: 5, dy: 5))
}

Now lets create an image from this drawing:

let image = ImageRenderer(size: CGSize(width: 100, height: 100)).image { context in
	performDrawing()
}

Or perhaps you'd prefer a PDF?

let bounds = CGRect(x: 0, y: 0, width: 612, height: 792)
try? PDFRenderer(bounds: bounds).writePDF(to: url) { context in
    context.beginPage()
    performDrawing(context: context)
    context.beginPage()
    performDrawing(context: context)
}

Drawing

When working with PDFs you don't need to worry about creating the PDF, ending pages or even closing the PDF. This is all handled automatically for you.

The context returned to you inside the drawing block holds onto 2 key pieces of information. (Just like UIGraphicsRendererContext)

format -- Provides information about bounds, scale, etc.. cgContext -- The underlying CGContext

Final note, the stroke methods are optimized to work the same way as the Apple implementation, in that they automatically insetBy 0.5 for you. If you don't want this behavious automatically, simply use the usual methods available on CGContext.

e.g. cgContext.stroke(rect: myRect)

Requirements

The library has the following requirements:

  • Swift 3.0
  • iOS 8.0+
  • OSX 10.10+

Installation

GraphicsRenderer is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "GraphicsRenderer"

Author

Shaps Benkau, [email protected]

License

GraphicsRenderer is available under the MIT license. See the LICENSE file for more info.

About

A drop-in UIGraphicsRenderer port -- CrossPlatform, Swift 3, Image & PDF

Resources

Readme
MIT license
Activity
Custom properties

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.