Skip to content

Instantly share code, notes, and snippets.

@amake
Last active December 14, 2017 05:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amake/f2928229f1fc9170672a3ed811db20ca to your computer and use it in GitHub Desktop.
Save amake/f2928229f1fc9170672a3ed811db20ca to your computer and use it in GitHub Desktop.
Dump glyph names on iOS in order to test availability (Swift 3)
/*
* 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)
@amake
Copy link
Author

amake commented May 31, 2016

The only difference between the simulator and a real iPhone running 9.3.1 was some glyph names:

61704c61704
< U+00f907 cid65535

---
> U+00f907 uni9F9C.3946
129163c129163
< U+02008a cid65535

---
> U+02008a uniD840DC8A.14108
130578c130578
< U+020611 cid65535

---
> U+020611 uniD841DE11.14294
132000c132000
< U+020b9f cid65535

---
> U+020b9f uniD842DF9F.13803
132718c132718
< U+020e6d cid65535

---
> U+020e6d uniD843DE6D.17380
133943c133943
< U+021336 cid65535

---
> U+021336 uniD844DF36.17437
140867c140867
< U+022e42 cid65535

---
> U+022e42 uniD84BDE42.20124
142285c142285
< U+0233cc cid65535

---
> U+0233cc uniD87EDCDB.14140
142335c142335
< U+0233fe cid65535

---
> U+0233fe uniD84CDFFE.15422
142683c142683
< U+02355a cid65535

---
> U+02355a uniD84DDD5A.17815
143168c143168
< U+02373f cid65535

---
> U+02373f uniD84DDF3F.16914
144639c144639
< U+023cfe cid65535

---
> U+023cfe uniD84FDCFE.13904
144705c144705
< U+023d40 cid65535

---
> U+023d40 uniD84FDD40.17942
146159c146159
< U+0242ee cid65535

---
> U+0242ee uniD850DEEE.14282
149966c149966
< U+0251cd cid65535

---
> U+0251cd uniD854DDCD.18193
152013c152013
< U+0259cc cid65535

---
> U+0259cc uniD856DDCC.20112
153305c153305
< U+025ed8 cid65535

---
> U+025ed8 uniD857DED8.18325
154219c154219
< U+02626a cid65535

---
> U+02626a uni7F51.14189
154445c154445
< U+02634c cid65535

---
> U+02634c uniD858DF4C.20311
154627c154627
< U+026402 cid65535

---
> U+026402 uniD859DC02.18398
155986c155986
< U+026951 cid65535

---
> U+026951 uni2EBD.13646
157966c157966
< U+02710d cid65535

---
> U+02710d uniD85CDD0D.18571
160389c160389
< U+027a84 cid65535

---
> U+027a84 uniD85EDE84.18684
164170c164170
< U+028949 cid65535

---
> U+028949 uniD862DD49.18811
164394c164394
< U+028a29 cid65535

---
> U+028a29 uniD862DE29.18844
165431c165431
< U+028e36 cid65535

---
> U+028e36 uniD863DE36.18890
170675c170675
< U+02a2b2 cid65535

---
> U+02a2b2 uniD868DEB2.20072
192679c192679
< U+02f8a6 cid65535

---
> U+02f8a6 uniD87EDCA6.20064

(<: simulator; >: iPhone)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment