{"id":16482767,"url":"https://github.com/shaps80/graphicsrenderer","last_synced_at":"2025-03-16T18:31:42.227Z","repository":{"id":56912955,"uuid":"69885169","full_name":"shaps80/GraphicsRenderer","owner":"shaps80","description":"A drop-in UIGraphicsRenderer port -- CrossPlatform, Swift 4, Image \u0026 PDF","archived":false,"fork":false,"pushed_at":"2020-08-25T19:28:23.000Z","size":239,"stargazers_count":111,"open_issues_count":0,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T09:35:07.167Z","etag":null,"topics":["drawing","graphics","osx","pdf","renderer","rendering"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shaps80.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-03T15:42:20.000Z","updated_at":"2025-01-08T22:20:27.000Z","dependencies_parsed_at":"2022-08-21T03:20:33.479Z","dependency_job_id":null,"html_url":"https://github.com/shaps80/GraphicsRenderer","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FGraphicsRenderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FGraphicsRenderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FGraphicsRenderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FGraphicsRenderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shaps80","download_url":"https://codeload.github.com/shaps80/GraphicsRenderer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243826783,"owners_count":20354220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["drawing","graphics","osx","pdf","renderer","rendering"],"created_at":"2024-10-11T13:11:56.200Z","updated_at":"2025-03-16T18:31:41.003Z","avatar_url":"https://github.com/shaps80.png","language":"Swift","readme":"# GraphicsRenderer\n\n[![Carthage compatible](https://img.shields.io/badge/Carthage-✓-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Version](https://img.shields.io/cocoapods/v/GraphicsRenderer.svg?style=flat)](http://cocoapods.org/pods/GraphicsRenderer)\n[![License](https://img.shields.io/cocoapods/l/GraphicsRenderer.svg?style=flat)](http://cocoapods.org/pods/GraphicsRenderer)\n[![Language](https://img.shields.io/badge/language-swift_3.0-ff69b4.svg)](http://cocoadocs.org/docsets/GraphicsRenderer)\n[![Platform](https://img.shields.io/cocoapods/p/GraphicsRenderer.svg?style=flat)](http://cocoapods.org/pods/GraphicsRenderer)\n\n## Installation\n\n**Cocoapods**\n\n```ruby\npod \"GraphicsRenderer\", \"1.3.0\"\n```\n\n**Carthage**\n\n```ruby\ngithub \"shaps80/GraphicsRenderer\" ~\u003e 1.2.1\n```\n\n### Swift 3\n```ruby\npod \"GraphicsRenderer\", \"1.1.0\"\n```\n\n### Swift 2.3\n```ruby\npod \"GraphicsRenderer\", \"1.0.0\"\n```\n\n## Introduction\n\n\u003cimg src=\"sample.png\" /\u003e\n\nGraphicsRenderer 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.\n\n```swift\nUIGraphicsRendererFormat \u003e RendererFormat\nUIGraphicsImageRendererFormat \u003e ImageRendererFormat\nUIGraphicsPDFRendererFormat \u003e PDFRendererFormat\n\nUIGraphicsRendererContext \u003e RendererContext\nUIGraphicsImageRendererContext \u003e ImageRendererContext\nUIGraphicsPDFRendererContext \u003e PDFRendererContext\n```\n\nThe classes you'll mostly work with though are:\n\n```swift\nUIGraphicsRenderer \u003e Renderer\nUIGraphicsImageRenderer \u003e ImageRenderer\nUIGraphicsPDFRenderer \u003e PDFRenderer\n```\n\nGraphicsRenderer is also cross-platform with iOS and macOS demo projects included in the repo.\n\nGraphicsRenderer 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`. \n\nGraphicsRenderer 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.\n\n## InkKit\n\nI have another library called \u003ca href=\"http://github.com/shaps80/InkKit\"\u003eInkKit\u003c/a\u003e which now uses this library for its inner workings. For a LOT more drawing and layout convenience's -- checkout that library too.~~\n\nNote: If you include InkKit in your project, you don't need to include this project too.\n\n## Example\n\nThere are 2 example projects included in the repo. One for iOS and another for OSX.\n\nSimply select the appropriate scheme, build and run.\n\nLets start by creating a simple drawing function:\n\n```swift\nfunc performDrawing\u003cContext: RendererContext\u003e(context: Context) {\n\tlet rect = context.format.bounds\n    UIColor.white.setFill()\n    context.fill(rect)\n    \n    UIColor.blue.setStroke()\n    let frame = CGRect(x: 10, y: 10, width: 40, height: 40)\n    context.stroke(frame)\n    \n    UIColor.red.setStroke()\n    context.stroke(rect.insetBy(dx: 5, dy: 5))\n}\n```\n\nNow lets create an image from this drawing:\n\n```swift\nlet image = ImageRenderer(size: CGSize(width: 100, height: 100)).image { context in\n\tperformDrawing()\n}\n```\n\nOr perhaps you'd prefer a PDF?\n\n```swift\nlet bounds = CGRect(x: 0, y: 0, width: 612, height: 792)\ntry? PDFRenderer(bounds: bounds).writePDF(to: url) { context in\n    context.beginPage()\n    performDrawing(context: context)\n    context.beginPage()\n    performDrawing(context: context)\n}\n```\n\n## Drawing\n\nWhen 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.\n\nThe `context` returned to you inside the drawing block holds onto 2 key pieces of information. (Just like `UIGraphicsRendererContext`)\n\n`format` -- Provides information about bounds, scale, etc..\n`cgContext` --  The underlying `CGContext`\n\nFinal 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`. \n\ne.g. `cgContext.stroke(rect: myRect)`\n\n## Requirements\n\nThe library has the following requirements:\n\n* Swift 4.0\n* iOS 8.0+\n* OSX 10.10+\n\n## Author\n\nShaps Benkau, shapsuk@me.com\n\n## License\n\nGraphicsRenderer is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaps80%2Fgraphicsrenderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshaps80%2Fgraphicsrenderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaps80%2Fgraphicsrenderer/lists"}