Let's say I'm porting some application to Mac OS X and in some cases it renders text and caret using Xor operation under other platform. Research has shown that XOR operation is not supported by Quartz drawing functions. Am I correct? And what alternative can be used to port such pieces of code to Mac OS X?
Note that XOR is a bitmap operation (and binary, really, hence only defined for b/w) so it is only defined when drawing one bitmap over another. Quartz provides a wide variety of bitmap blend modes, including Difference (kCGBlendModeDifference
) and Exclusion (kCGBlendModeExclusion
) which are both exactly XOR for b/w values - so, yes, Quartz does support XOR.
The way you can do this in practice is to get an image of your caret (white caret on black background) and draw it using either of the above blend modes (see CGContextSetBlendMode
). If you meant to draw the text using XOR as well, then you draw it into an image context (again, white on black) and then apply the image context with the blend mode to your target.