I'm trying to get CGPath from glyphs for all the fonts available on my iPad, in a few cases the Glyphs are not available for fonts such as "AcademyEngravedLetPlain" which looks like below:
My code:
let attributes = text.attributes(at: 0, effectiveRange: nil)
let font = attributes[.font] as! UIFont
//or you can use let font = UIFont(name: "AcademyEngravedLetPlain", size: 30)!
let unicodeScalarRange: ClosedRange<Unicode.Scalar> = "!" ... "~"
let unicodeScalarValueRange: ClosedRange<UInt32> = unicodeScalarRange.lowerBound.value ... unicodeScalarRange.upperBound.value
let unicodeScalarArray: [Unicode.Scalar] = unicodeScalarValueRange.compactMap(Unicode.Scalar.init)
var a: [UniChar] = unicodeScalarValueRange.map(UniChar.init)
var glyphs = [CGGlyph](repeatElement(0, count: a.count))
let gotGlyphs = CTFontGetGlyphsForCharacters(font, &a, &glyphs, a.count)
if gotGlyphs{
for g in glyphs {
if let cgpath = CTFontCreatePathForGlyph(font, g, nil) {
print("cgpath available")
}
}
}else{
print("Could not get glyphs for font characters!!! No cgpath")
}
How do I get the missing glyphs/paths of the fonts, I don't want to use the fallback font. what can be the solution?
