Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for reading lib and glyphSet for a specified layer #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/UFOKit/PointPen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import Quartz
import os.log

public enum SegmentType: CustomStringConvertible {
Expand Down
18 changes: 14 additions & 4 deletions Sources/UFOKit/UFOReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import Foundation
public class UFOReader {
public let url: URL
public let metaInfo: MetaInfo
public let layerContents: [(String, String)]

public init(url: URL) throws {
self.url = url
metaInfo = try UFOReader.readMetaInfo(url: url)
layerContents = try UFOReader.readLayerContents(url: url)
}

class func readMetaInfo(url: URL) throws -> MetaInfo {
Expand Down Expand Up @@ -49,9 +51,9 @@ public class UFOReader {
return try decoder.decode([String: [String: Int]].self, from: kerningData)
}

public func readLib() throws -> Data {
public func readLib() throws -> NSMutableDictionary {
let libURL = url.appendingPathComponent(Filename.libFilename)
return try Data(contentsOf: libURL)
return NSMutableDictionary(contentsOf: libURL) ?? NSMutableDictionary()
}

public func readFeatures() throws -> String {
Expand All @@ -74,8 +76,16 @@ public class UFOReader {
return layerContents
}

public func glyphSet() throws -> GlyphSet {
let glyphDirURL = url.appendingPathComponent(DirectoryName.defaultGlyphsDirName)
public func glyphSet(layerName: String? = nil) throws -> GlyphSet {
var directory = DirectoryName.defaultGlyphsDirName
if layerName != nil {
for (name, layerDirectory) in layerContents {
if layerName == name {
directory = layerDirectory
}
}
}
let glyphDirURL = url.appendingPathComponent(directory)
return try GlyphSet(dirURL: glyphDirURL, ufoFormatVersion: metaInfo.formatVersion)
}

Expand Down