All Projects → shaps80 → Graphicsrenderer

shaps80 / Graphicsrenderer

Licence: mit
A drop-in UIGraphicsRenderer port -- CrossPlatform, Swift 4, Image & PDF

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Graphicsrenderer

Flycube
Graphics API wrapper is written in C++ on top of Directx 12 and Vulkan. Provides main features including ray tracing.
Stars: ✭ 78 (-8.24%)
Mutual labels:  graphics, rendering, renderer
Svglib
Read SVG files and convert them to other formats.
Stars: ✭ 139 (+63.53%)
Mutual labels:  graphics, rendering, pdf
Perfect Freehand
Draw perfect pressure-sensitive freehand strokes.
Stars: ✭ 999 (+1075.29%)
Mutual labels:  graphics, drawing
Shaderworkshop
Interactive GLSL fragment shaders editor made with Qt
Stars: ✭ 43 (-49.41%)
Mutual labels:  graphics, rendering
React Pdf
📄 Create PDF files using React
Stars: ✭ 10,153 (+11844.71%)
Mutual labels:  renderer, pdf
Rendy
State of the art "build your own engine" kit powered by gfx-hal
Stars: ✭ 750 (+782.35%)
Mutual labels:  graphics, renderer
Opengraphic
Graphic Engine & Game Engine lists
Stars: ✭ 772 (+808.24%)
Mutual labels:  graphics, rendering
Openframeworks
openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
Stars: ✭ 8,652 (+10078.82%)
Mutual labels:  graphics, osx
Rs pbrt
Rust crate to implement a counterpart to the PBRT book's (3rd edition) C++ code. See also https://www.rs-pbrt.org/about ...
Stars: ✭ 619 (+628.24%)
Mutual labels:  graphics, rendering
Maker.js
📐⚙ 2D vector line drawing and shape modeling for CNC and laser cutters.
Stars: ✭ 1,185 (+1294.12%)
Mutual labels:  drawing, pdf
Real Time Rendering 3rd Cn Summary Ebook
📘 电子书 -《Real-Time Rendering 3rd》提炼总结 | 全书共9万7千余字。你可以把它看做中文通俗版的《Real-Time Rendering 3rd》,也可以把它看做《Real-Time Rendering 3rd》的解读版与配套学习伴侣,或者《Real-Time Rendering 4th》的前置阅读材料。
Stars: ✭ 1,159 (+1263.53%)
Mutual labels:  rendering, pdf
Trace Of Radiance
An educational raytracer
Stars: ✭ 77 (-9.41%)
Mutual labels:  rendering, renderer
Macaw
Powerful and easy-to-use vector graphics Swift library with SVG support
Stars: ✭ 5,756 (+6671.76%)
Mutual labels:  graphics, drawing
Fauxgl
Software-only 3D renderer written in Go.
Stars: ✭ 658 (+674.12%)
Mutual labels:  graphics, rendering
Pixi.js
The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.
Stars: ✭ 34,982 (+41055.29%)
Mutual labels:  rendering, renderer
Raymarching Workshop
An Introduction to Raymarching
Stars: ✭ 657 (+672.94%)
Mutual labels:  graphics, rendering
Atrament.js
A small JS library for beautiful drawing and handwriting on the HTML Canvas.
Stars: ✭ 1,045 (+1129.41%)
Mutual labels:  graphics, drawing
Gpu Gems Book Source Code
💿 CD Content ( Source Code ) Collection of Book <GPU Gems > 1~ 3 | 《GPU精粹》 1~ 3 随书CD(源代码)珍藏
Stars: ✭ 567 (+567.06%)
Mutual labels:  graphics, rendering
Ascii art
Real-Time ASCII Art Rendering Library
Stars: ✭ 599 (+604.71%)
Mutual labels:  graphics, rendering
Graphics Algorithm
3D图形学算法Code。包括软渲染、光线追踪、PBR等等~
Stars: ✭ 67 (-21.18%)
Mutual labels:  graphics, renderer

GraphicsRenderer

Carthage compatible Version License Language Platform

Installation

Cocoapods

pod "GraphicsRenderer", "1.3.0"

Carthage

github "shaps80/GraphicsRenderer" ~> 1.2.1

Swift 3

pod "GraphicsRenderer", "1.1.0"

Swift 2.3

pod "GraphicsRenderer", "1.0.0"

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 > ImageRendererContext
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 4.0
  • iOS 8.0+
  • OSX 10.10+

Author

Shaps Benkau, [email protected]

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].