NSTextView->;cacheDisplay会丢失一些下划线,但不会丢失其他下划线

NSTextView->;cacheDisplay会丢失一些下划线,但不会丢失其他下划线,nstextview,nsbitmapimagerep,Nstextview,Nsbitmapimagerep,在我的应用程序中,我的下划线有一个奇怪的问题。我没有任何其他字体相关属性(大小、样式、粗体等)的问题,只有下划线 我在NSTextView(视图)中有文本数据。课文中的每一处下划线都是正确的 我使用的代码如下: dataPointers?[0] = UnsafeMutablePointer<UInt8>.allocate(capacity: totalBytes) cachedBMs[appDel.nextFrameIndex] = NSBitmapI

在我的应用程序中,我的下划线有一个奇怪的问题。我没有任何其他字体相关属性(大小、样式、粗体等)的问题,只有下划线

我在NSTextView(视图)中有文本数据。课文中的每一处下划线都是正确的

我使用的代码如下:

        dataPointers?[0] = UnsafeMutablePointer<UInt8>.allocate(capacity: totalBytes)
        cachedBMs[appDel.nextFrameIndex] = NSBitmapImageRep(bitmapDataPlanes: dataPointers, pixelsWide: Int(viewFrame.size.width * 2), pixelsHigh: Int(viewFrame.size.height * 2), bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false, colorSpaceName: NSCalibratedRGBColorSpace, bytesPerRow: Int(bytesPerRow), bitsPerPixel: 32)
        cachedBMs[appDel.nextFrameIndex]?.size = NSSize(width: viewFrame.size.width, height: viewFrame.size.height)
        cachedBMsDataPointer[appDel.nextFrameIndex] = dataPointers?[0]
        cachedBMsSize[appDel.nextFrameIndex] = totalBytes

        if let bitmap = cachedBMs[appDel.nextFrameIndex]
        {
        theView = NSKeyedUnarchiver.unarchiveObject(with: NSKeyedArchiver.archivedData(withRootObject: originalView))!
            theView.cacheDisplay(in: viewFrame, to: bitmap)
            cachedBMsDataPointer[appDel.nextFrameIndex] = bitmap.bitmapData
        }
dataPointers?[0]=UnsafeMutablePointer.allocate(容量:totalBytes)
CachedDBMS[appDel.nextFrameIndex]=NSBitmapImageRep(bitmapDataPlanes:dataPointers,pixelsWide:Int(viewFrame.size.width*2),pixelsHigh:Int(viewFrame.size.height*2),bitsPerSample:8,samplesPerPixel:4,hasAlpha:true,isPlanar:false,colorSpaceName:NSCalibratedRGBColorSpace,bytesPerRow:Int(bytesPerRow),bitsPerPixel:32)
cachedBMs[appDel.nextFrameIndex]?.size=NSSize(宽度:viewFrame.size.width,高度:viewFrame.size.height)
CachedDBMSDataPointer[appDel.nextFrameIndex]=数据指针?[0]
cachedbmsize[appDel.nextFrameIndex]=totalBytes
如果let bitmap=cachedBMs[appDel.nextFrameIndex]
{
视图=NSKeyedArchiver.unarchiveObject(带:NSKeyedArchiver.ArchiveData(带根对象:originalView))!
cacheDisplay(在:viewFrame中,到:位图)
cachedBMsDataPointer[appDel.nextFrameIndex]=位图.bitmapData
}
然后,我使用位图缓冲区为OpenGL创建一些纹理(我知道,我应该使用Metal,我很快就会使用),并将它们渲染到另一个窗口。并非所有下划线都可见。文件开头的那个不见了。文件末尾的那些是正确的

文本可以很长,5000多行。如果我从文件中间删除一块文本,文件开头的下划线将正确显示在OpenGL视图中。这就是为什么我要在操作之前克隆NSTextView,否则会花费很长时间,从而干扰用户在窗口中编辑NSTextView

我已经一个接一个地浏览了属性,它们每次都是相同的,无论是在文件的开头和结尾,还是在我的OpenGL窗口中下划线可见和不可见的情况下

如上所述,所有其他文本属性都是正确的


文本源可以是RTF文件,也可以是从另一个应用程序粘贴的,或者是直接键入到NSTextView中的。无论来源如何,行为都是相同的。

如何添加属性,是否使用TextKit?