Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pocketsvg/PocketSVG into ci-for-m…
Browse files Browse the repository at this point in the history
…acos13
  • Loading branch information
arielelkin committed Sep 13, 2024
2 parents 20056c1 + 13bc881 commit e6cd59d
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 170 deletions.
7 changes: 3 additions & 4 deletions Demos/Demo-iOS/Demo-iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@

import UIKit

@UIApplicationMain
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
let rootViewController = UINavigationController(rootViewController: MainViewController())
window?.rootViewController = rootViewController
window?.makeKeyAndVisible()

return true
}
}
13 changes: 4 additions & 9 deletions Demos/Demo-iOS/Demo-iOS/GrayscaleTigerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
* file that was distributed with this source code.
*/

import UIKit
import PocketSVG
import UIKit

class GrayscaleTigerViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -22,17 +21,14 @@ class GrayscaleTigerViewController: UIViewController {
let tigerLayer = CALayer()

for (index, path) in paths.enumerated() {

let shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath

if index%2 == 0 {
if index % 2 == 0 {
shapeLayer.fillColor = UIColor.black.cgColor
}
else if index%3 == 0 {
} else if index % 3 == 0 {
shapeLayer.fillColor = UIColor.darkGray.cgColor
}
else {
} else {
shapeLayer.fillColor = UIColor.gray.cgColor
}

Expand All @@ -46,4 +42,3 @@ class GrayscaleTigerViewController: UIViewController {
view.layer.addSublayer(tigerLayer)
}
}

30 changes: 14 additions & 16 deletions Demos/Demo-iOS/Demo-iOS/IcelandicViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,27 @@
* file that was distributed with this source code.
*/

import UIKit
import PocketSVG
import UIKit

class IcelandicViewController: UIViewController {

let icelandicView = UIView()

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white

let svgURL = Bundle.main.url(forResource: "iceland", withExtension: "svg")!
let paths = SVGBezierPath.pathsFromSVG(at: svgURL)

for (index, path) in paths.enumerated() {

// assign different colours to different shapes:
let shapeLayer = CAShapeLayer()
shapeLayer.fillColor = UIColor(hue: CGFloat(index)/CGFloat(paths.count), saturation: 1, brightness: 1, alpha: 1).cgColor
shapeLayer.strokeColor = UIColor(white: 1-CGFloat(index)/CGFloat(paths.count), alpha: 1).cgColor
shapeLayer.fillColor = UIColor(hue: CGFloat(index) / CGFloat(paths.count), saturation: 1, brightness: 1, alpha: 1).cgColor
shapeLayer.strokeColor = UIColor(white: 1 - CGFloat(index) / CGFloat(paths.count), alpha: 1).cgColor
shapeLayer.path = path.cgPath
icelandicView.layer.addSublayer(shapeLayer)

// animate stroke width:
let animation = CABasicAnimation(keyPath: "lineWidth")
animation.toValue = 4
Expand All @@ -40,26 +38,26 @@ class IcelandicViewController: UIViewController {
animation.isRemovedOnCompletion = false
shapeLayer.add(animation, forKey: animation.keyPath)
}

let r = SVGBoundingRectForPaths(paths)
icelandicView.frame = r

let scrollview = UIScrollView(frame: view.bounds)
scrollview.maximumZoomScale = 5.0
scrollview.minimumZoomScale = 0.5

scrollview.contentSize = r.size

scrollview.delegate = self

scrollview.addSubview(icelandicView)

view.addSubview(scrollview)
}
}

extension IcelandicViewController: UIScrollViewDelegate {
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return icelandicView
func viewForZooming(in _: UIScrollView) -> UIView? {
icelandicView
}
}
64 changes: 30 additions & 34 deletions Demos/Demo-iOS/Demo-iOS/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import UIKit

class MainViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
title = "PocketSVG Demo"
Expand All @@ -22,20 +21,22 @@ class MainViewController: UIViewController {
view.addSubview(tableView)
}
}

enum Section: Int {
case simple
case complex

var title: String {
switch self {
case .simple:
return "Simple"
"Simple"
case .complex:
return "Complex"
"Complex"
}
}

static var count: Int {
return 2
2
}
}

Expand All @@ -48,40 +49,40 @@ enum SimpleRow: Int {
case tiger

static var count: Int {
return 4
4
}

var svgURL: URL {
switch self {
case .circle:
return Bundle.main.url(forResource: "circle", withExtension: "svg")!
Bundle.main.url(forResource: "circle", withExtension: "svg")!
case .curve:
return Bundle.main.url(forResource: "curve", withExtension: "svg")!
Bundle.main.url(forResource: "curve", withExtension: "svg")!
case .lines:
return Bundle.main.url(forResource: "lines", withExtension: "svg")!
Bundle.main.url(forResource: "lines", withExtension: "svg")!
case .attribute_inheritance:
return Bundle.main.url(forResource: "attribute_inheritance", withExtension: "svg")!
Bundle.main.url(forResource: "attribute_inheritance", withExtension: "svg")!
case .iceland:
return Bundle.main.url(forResource: "iceland", withExtension: "svg")!
Bundle.main.url(forResource: "iceland", withExtension: "svg")!
case .tiger:
return Bundle.main.url(forResource: "tiger", withExtension: "svg")!
Bundle.main.url(forResource: "tiger", withExtension: "svg")!
}
}

var title: String {
switch self {
case .circle:
return "Circle"
"Circle"
case .curve:
return "Curve"
"Curve"
case .lines:
return "Lines"
"Lines"
case .attribute_inheritance:
return "Attribute Inheritance"
"Attribute Inheritance"
case .iceland:
return "Iceland"
"Iceland"
case .tiger:
return "Tiger"
"Tiger"
}
}
}
Expand All @@ -92,23 +93,22 @@ enum ComplexRow: Int {
case grayscaleTiger

static var count: Int {
return 3
3
}

var title: String {
switch self {
case .rectangle:
return "Rectangle"
"Rectangle"
case .icelandic:
return "Icelandic"
"Icelandic"
case .grayscaleTiger:
return "Grayscale Tiger"
"Grayscale Tiger"
}
}
}

extension MainViewController: UITableViewDataSource {

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "identifier", for: indexPath)

Expand All @@ -125,11 +125,11 @@ extension MainViewController: UITableViewDataSource {
return cell
}

func numberOfSections(in tableView: UITableView) -> Int {
return Section.count
func numberOfSections(in _: UITableView) -> Int {
Section.count
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
let sectionEnum = Section(rawValue: section)!
switch sectionEnum {
case .simple:
Expand All @@ -139,20 +139,17 @@ extension MainViewController: UITableViewDataSource {
}
}

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
func tableView(_: UITableView, titleForHeaderInSection section: Int) -> String? {
let sectionEnum = Section(rawValue: section)!
return sectionEnum.title
}
}

extension MainViewController: UITableViewDelegate {

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

let section = Section(rawValue: indexPath.section)!

switch section {

case .simple:
let row = SimpleRow(rawValue: indexPath.row)!
let svgURL = row.svgURL
Expand All @@ -161,14 +158,13 @@ extension MainViewController: UITableViewDelegate {

case .complex:
let row = ComplexRow(rawValue: indexPath.row)!
let vc: UIViewController
switch row {
let vc: UIViewController = switch row {
case .rectangle:
vc = RectangleViewController()
RectangleViewController()
case .icelandic:
vc = IcelandicViewController()
IcelandicViewController()
case .grayscaleTiger:
vc = GrayscaleTigerViewController()
GrayscaleTigerViewController()
}
navigationController?.pushViewController(vc, animated: true)
}
Expand Down
7 changes: 3 additions & 4 deletions Demos/Demo-iOS/Demo-iOS/RectangleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
* file that was distributed with this source code.
*/

import UIKit
import PocketSVG
import UIKit

class RectangleViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .white

let svgURL = Bundle.main.url(forResource: "rectangle", withExtension: "svg")!

let svgImageView = SVGImageView.init(contentsOf: svgURL)
let svgImageView = SVGImageView(contentsOf: svgURL)

// The original SVG's stroke color is yellow, but we'll make it red:
svgImageView.strokeColor = .red

//The original SVG's fill is transparent but we'll make it blue:
// The original SVG's fill is transparent but we'll make it blue:
svgImageView.fillColor = .blue

svgImageView.frame = view.bounds
Expand Down
12 changes: 6 additions & 6 deletions Demos/Demo-iOS/Demo-iOS/SimpleDetailViewController.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
//
// DetailViewController.swift
// SimpleDetailViewController.swift
// Demo-iOS
//
// Created by Ariel Elkin on 04/04/2018.
// Copyright © 2018 PocketSVG. All rights reserved.
//

import UIKit
import PocketSVG
import UIKit

class SimpleDetailViewController: UIViewController {

init(svgURL: URL) {
super.init(nibName: nil, bundle: nil)

view.backgroundColor = .white

let svgImageView = SVGImageView.init(contentsOf: svgURL)
let svgImageView = SVGImageView(contentsOf: svgURL)
svgImageView.contentMode = .scaleAspectFit

view.addSubview(svgImageView)
Expand All @@ -26,11 +25,12 @@ class SimpleDetailViewController: UIViewController {
svgImageView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -12),
svgImageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 12),
svgImageView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -12),
]
]
)
}

required init?(coder aDecoder: NSCoder) {
@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
4 changes: 2 additions & 2 deletions Demos/Demo-macOS/Demo-macOS/MacDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import Cocoa
import PocketSVG

@NSApplicationMain
@main
class AppDelegate: NSObject, NSApplicationDelegate {}

class DemoController: NSViewController {
override func loadView() {
let url = Bundle.main.url(forResource: "iceland", withExtension: "svg")!
let j = SVGImageView.init(contentsOf: url)
let j = SVGImageView(contentsOf: url)
print(j.viewBox == .null)
view = j

Expand Down
Loading

0 comments on commit e6cd59d

Please sign in to comment.