提问人:Rasto 提问时间:11/21/2014 最后编辑:Vadim KotovRasto 更新时间:4/10/2018 访问量:1543
获取除字母或数字以外的字符的 CGGlyphs 的边界矩形
Get bounding rectangle for CGGlyphs of Characters other then letters or numbers
问:
我正在寻找一种方法来记录字符的字形下降,如图所示:
该方法需要适用于任何给定字符(或至少所有常见的 Unicode 字符)。
这是我的实际方法(在 Swift 中,受到这个问题和这个问题的启发):
let char = "a"
let ctFont = CTFontCreateWithNameAndOptions("HelveticaNeue", 12, nil, nil)
var ctGlyph = CTFontGetGlyphWithName(ctFont, char)
let boundingBox = withUnsafePointer(&ctGlyph) { pointer -> CGRect in
return CTFontGetBoundingRectsForGlyphs(ctFont, CTFontOrientation.OrientationDefault, pointer, nil, 1)
}
那么我需要的下降就等于 .
这种方法适用于字母、数字和数字字符(有关图形表示,请参阅此答案)。-boundingBox.origin.y
问题是,对于字母或数字以外的所有内容(例如:),我得到相同的边界矩形:。这显然是不正确的。.,#')*
{x:0.612, y:0.012, w:4.908, h:8.532}
如何直接获取所有字符的下降的绑定矩形?
答: 暂无答案
评论
CTFontGetGlyphWithName()
.notdef
.notdef