From f3929078fe10e19173abaf1a8842176a3b9cf79a Mon Sep 17 00:00:00 2001 From: Frederik Berlaen Date: Fri, 13 Dec 2024 19:05:08 +0100 Subject: [PATCH 1/3] Add support to read a glypyhset for a layer --- Sources/UFOKit/PointPen.swift | 1 + Sources/UFOKit/UFOReader.swift | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) 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..0891ef6 100644 --- a/Sources/UFOKit/UFOReader.swift +++ b/Sources/UFOKit/UFOReader.swift @@ -74,8 +74,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) } From 5c1fa1805503c7f619ff1ac2941fca16d19d0a30 Mon Sep 17 00:00:00 2001 From: Frederik Berlaen Date: Fri, 13 Dec 2024 19:05:25 +0100 Subject: [PATCH 2/3] add support to read lib to a dictionary --- Sources/UFOKit/UFOReader.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/UFOKit/UFOReader.swift b/Sources/UFOKit/UFOReader.swift index 0891ef6..6943ba4 100644 --- a/Sources/UFOKit/UFOReader.swift +++ b/Sources/UFOKit/UFOReader.swift @@ -49,9 +49,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 { From fd0d8818bec07cb8074f7bdfda560a19ec1ceb01 Mon Sep 17 00:00:00 2001 From: Frederik Berlaen Date: Fri, 13 Dec 2024 19:05:48 +0100 Subject: [PATCH 3/3] read layer contents during init --- Sources/UFOKit/UFOReader.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/UFOKit/UFOReader.swift b/Sources/UFOKit/UFOReader.swift index 6943ba4..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 {