"Leave the graphics context in any state" 的含义

Meaning of "Leave the graphics context in any state"

我使用 "Core Text" 函数 CTLineDraw。但看起来它对 CGContextRef 有一些副作用:填充矩形在 CTLineDraw 之后对于相同的上下文不再起作用(但在我注释掉 CTLineDraw 调用之前或之前起作用)。

根据 CTLineDraw 和 "Core Text" 文档中的一些其他函数:

This call can leave the graphics context in any state and does not flush the context after the draw operation.

我认为这可能是相关的。但是这句话到底是什么意思呢?我应该保存和恢复上下文状态的内容(这有帮助)?

是的,你应该在最后一个之后 save the state before the first call to CTLineDraw you’re doing and restore it。文档中那一行的意思是 Core Text 在内部设置状态的各个位来完成你要求它做的文本绘制,并且之后不会自动将它们设置回来。