I have added the reading and writing of RTF, using the initWithRTF and RTFFromRange cocoa methods. These deal with NS/CFAttriibutedStrings, and back onto NS/CFData. The wrinkle is that NSColor has to be converted to CFColor as I covered before here.
The accompanying Unit Tests were quite simple, Create a CFAttributedstring, add attributes, write as a CFData, read back and compare. They should be equal.
The great thing about unit testing is that it throws up problems - though sometimes I prefer the older ostrich ways. I got the full twelve rounds on his one even the crash just after the test harness says everything is OK and tries to shut shop for the night. The crash turned out to to be an owner-count problem, once the owners drop below zero who owns what, and what is what, is a little ambiguous. I remember in my student days having this kind of ownership ambiguity with the bank - exactly whose money was I spending, and why did they get so upset.
Probably the most unexpected problem was in hindsight the most obvious. If you specify a color as say rgb(0.1, 0.2, 0.3) it comes back from RTF different. there are two parts to the problem. The first is color space (or profile). Colors went in as device color and came back as a NSCalibratedRGBColorSpace. Converting between color spaces (or profiles) changes color values. The other is that RTF stores color values as 0..255 - and of course naturally you loose precision.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment