diff --git a/Sources/UFOKit/PointPen.swift b/Sources/UFOKit/PointPen.swift index 9dc513f..fdc546b 100644 --- a/Sources/UFOKit/PointPen.swift +++ b/Sources/UFOKit/PointPen.swift @@ -7,6 +7,7 @@ // import Foundation +import Quartz import os.log public enum SegmentType: CustomStringConvertible { diff --git a/Sources/UFOKit/UFOReader.swift b/Sources/UFOKit/UFOReader.swift index f87c999..4d1610c 100644 --- a/Sources/UFOKit/UFOReader.swift +++ b/Sources/UFOKit/UFOReader.swift @@ -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 { @@ -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 { @@ -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) }