Last active
December 14, 2017 05:28
-
-
Save amake/f2928229f1fc9170672a3ed811db20ca to your computer and use it in GitHub Desktop.
Dump glyph names on iOS in order to test availability (Swift 3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Make a dummy application and run this in e.g. UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:) | |
*/ | |
let filemanager = FileManager.default | |
let docsdir = filemanager.urls(for: .documentDirectory, in: .userDomainMask).first! | |
try! filemanager.createDirectory(at: docsdir, withIntermediateDirectories: true, attributes: nil) | |
let outfile = docsdir.appendingPathComponent("glyphtest.txt") | |
filemanager.createFile(atPath: outfile.path, contents: nil, attributes: nil) | |
let handle = try! FileHandle(forWritingTo: outfile) | |
handle.truncateFile(atOffset: 0) | |
let layoutmanager = NSLayoutManager() | |
for c in 0...0x10ffff { | |
if c >= 0xd800 && c <= 0xdfff { | |
continue | |
} | |
var line: String | |
if let scalar = UnicodeScalar(c) { | |
let string = String(Character(scalar)) | |
let text = NSTextStorage(attributedString: NSAttributedString(string: string)) | |
text.addLayoutManager(layoutmanager) | |
let glyph = layoutmanager.cgGlyph(at: 0) | |
let attr = text.attribute(NSFontAttributeName, at: 0, longestEffectiveRange: nil, in: NSMakeRange(0, 1)) | |
if let font = attr as? UIFont { | |
if let cgfnt = CGFont(font.fontName as CFString) { | |
if let name = cgfnt.name(for: glyph) { | |
//print(name) | |
line = String(format:"U+%06x %@\n", c, name as String) | |
} else { | |
line = String(format:"U+%06x (failed to get glyph name)\n", c) | |
} | |
} else { | |
line = String(format:"U+%06x (failed to get CGFont)\n", c) | |
} | |
} else { | |
line = String(format:"U+%06x (failed to get font)\n", c) | |
} | |
} else { | |
line = String(format:"U+%06x (failed to get Unicode scalar)\n") | |
} | |
let data = line.data(using: String.Encoding.utf8, allowLossyConversion: false)! | |
handle.write(data) | |
} | |
handle.closeFile() | |
print(outfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lastresorttemplate
)The only difference between the simulator and a real iPhone running 9.3.1 was some glyph names:
(<: simulator; >: iPhone)