3
현재 잘 작동하는 글리프의 논리적 NSView 위치를 가져 오는 데 다음 코드를 사용하고 있습니다. 그러나 속도가 약간 느려지고 위치가 문자 커닝 지점과 기준선에 정확하게 있지 않습니다. 글리프 자체를 하나씩 반복하고 직사각형을 직접 작성하는 것이 모두 필요한 경우가 될 수 있습니다.NSTextView에서 문자의 픽셀 위치는 어떻게 찾습니까?
이 코드 (기능)는 이제 더 효율적으로 또는 올바르게 수행 될 수 있는지보고 싶습니다.
// lastRange is any valid, bounds checked character range in an NSTextView
NSLayoutManager *layoutManager = [self layoutManager];
NSRect paragraphRect = [layoutManager boundingRectForGlyphRange:lastRange inTextContainer:[self textContainer]];
// Draw a gradient around the range.
NSGradient * gradient = [self indicatorGradient];
CGContextRef myContext = [[NSGraphicsContext currentContext] graphicsPort];
CGContextSetBlendMode(myContext , kCGBlendModeMultiply);
[gradient drawInRect:paragraphRect angle:90];