NSTextView lineHeight多个绘图问题
通过设置文本视图中使用的 NSParagraphStyle 的 lineHeightMultiple,我在选择文本时得到了绘图伪影。这可以在 TextEdit 中重现。更具体地说:
- 在富文本模式下打开 TextEdit
- 选择 Courier 14 作为字体
- 将行高倍数设置为 1.4
- 插入一堆文本
- 用鼠标选择文本的一部分,直到顶部
- 开始减少选择(向下移动鼠标)
在某些行中,选区并未完全清除,留下了 1px 的水平伪影(参见屏幕截图)。使用不同的字体、字体大小作为 lineHeightMultiple 值(尽管不是全部)也会出现这种情况。
有没有人经历过这种情况或者知道为什么会发生这种情况?
谢谢,
鲁本
By setting the lineHeightMultiple of a NSParagraphStyle that is used in a text view I'm getting drawing artifacts when selecting text. This is reproducible in TextEdit. More specifically:
- Open TextEdit in rich text mode
- Pick Courier 14 as the font
- Set line height multiple to 1.4
- Insert a bunch of text
- Select a portion of text with the mouse until the top
- Start decreasing the selection (moving the mouse down)
In some lines, the selection is not totally cleared, leaving a 1px horizontal artifact behind (see screnshot). This also occurs with different fonts, font sizes as lineHeightMultiple values (although not all).
Has anyone experience this or has any idea why this is happening?
Thanks,
Rúben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过将段落样式添加到选定的文本属性并舍入行高,在自己的代码中解决了这个问题。
I fixed this in my own code by adding the paragraph style to the selected text attributes, and rounding the line height.
我对 NSTextAttachment 也有类似的问题,它的高度大于默认行距。我可以通过将这一行添加到我的 NSTextViewDelegate 来缓解它。
我还尝试在自定义 NSTextView 类中的 mouseDragged 期间创建更大的重绘区域,但不幸的是 NSTextView 处理此问题完全不同,因此 mouseDragged 永远不会被调用。
段落样式的技巧对我不起作用。
I had a similar issue with NSTextAttachment's which were having a height larger than the default line spacing. I was able to mitigate it by adding this line to my NSTextViewDelegate.
I also tried to create a larger redraw area during mouseDragged in my custom NSTextView class, but unfortunately NSTextView is handling this completely different, thus mouseDragged is never being invoked.
The trick with the paragraph style did not work for me.