Saturday, June 23, 2007

CoreData and transient properties

If you are interested in transient properties with CoreData you should read this article written by Jakob Stoklund Olesen.

Tuesday, May 22, 2007

DeviceN & Separation color space

Though cocoa is able to display PDFs that contain colors of DeviceN or separation color spaces you cannot create those spaces programatically.
That means, you cannot create instances of colors using DeviceN or separation color spaces. And finally there is a lack of support for other color related stuff like 'overprint black' and others we'd need to create professional PDFs.
Remember that all this depends on underlying Quartz graphics engine.
So new color features first have to be added to Quartz before propagated to Cocoa.

BUT: Take a look at spot color picker for OSX.
It manages to add spot colors to documents of any app that supports OSX color picker.
So how is this possible?!
Hint: This color picker lists instances of NSColor of a dummy gray color space marked by a special ICC profile containing the needed additional information about the spot color. Then it hooks into the PDF/PS generation process and appends additional objects to the generated PDF using the data taken from the ICC profile. This hook only works with spot color picker installed.
So if you hand over a document with spot colors to someone who hasn't installed spot picker you won't get the correct results when printing it to PDF.
This is the most intelligent Cocoa/Quartz hack I have ever seen. Cool stuff.

Sunday, May 20, 2007

NSKeyedArchiver is wasting memory

If your program has to handle a large amount of data, remember that NSKeyedArchiver's
-archiveRootObject:toFile: first encodes your document into an instance of NSData and then stores content data to disk using -writeToFile:options:error:.
For reference see according documentation of -archiveRootObject:toFile:.
That means saving a 2GB document to disk may consume n GB of RAM (2GB document + n GB as encoded data in an instance of NSData :-)
Memory consumption of course depends on output format you set to the archiver.

NSKeyedUnarchiver behaves similar:
First the data will be read from disk into an instance of NSData and then it will be decoded from there.

I really miss a direct to disk variant of coding/encoding.
I did not digged deeply into CoreData in combination with SQLite. Maybe this is something worth to take at look at, as theoretically SQLite should never need to have the whole graph in memory. But for an existing project (or if your project should be downward compatible to Panther) it's hard to accept.

Tuesday, April 17, 2007

Justified text alignment

If you set alignment constant NSJustifiedTextAlignment to an instance of NSParagraphStyle that has been applied to a text storage, you will be annoyed by two problems:

At first the justification algorithm of ATSUI, that is used for text layout in COCOA, is stretching words. So 'Test' becomes 'T e s t', which even gets worse with wider line fragment rects the word has to be formatted in.
I do not know much about classic typesetting in the US. At least for european layouters this is not acceptable. When ATSUI performs text justification it should be able to stretch spaces only.

Secondly text justification not always gives correct results.
See my Movie I filed to Apple in 2006 (Problem ID: 4748128).
It shows a line being formatted incorrectly when changing width of text container in TextEdit.

Monday, April 16, 2007

Text hyphenation in general

Another bad thing you should know about hyphenation: OSX only supports english hyphenation rules. It does not matter which language you select for your programs or finder.
There is no replacement for OSX hyphenation system yet, as cocoa developers did not implement a generalized concept for hyphenation rule handling yet.
You'll find english hyphenation dictionary on your HD at:
System/Library/Frameworks/AppKit.framework/Versions/C/Resources/English-Hyphenation.txt
The exception dictionary can be found at the same location (English-HyphenationExc.txt)

Inconsequently spell checking is not limited to english language.

Soft hyphens

Unfortunately Tiger does not handle soft hyphens (U+00AD) correctly. After inserting a soft hyphen it stays visible even if text is not wrapped at soft hyphen's position.
As far as I remember soft hyphens did work in Panther. So I filed a bug report (ID: 4633376) in summer 2006.
This bug really is a major problem. It simply makes professional text layout impossible.
Just try it out using TextEdit. Just insert a soft hyphen using character palette.

Update: This bug has been resolved in Leopard.

Saturday, April 14, 2007

NSTextView transformations

Ever needed a transformed (e.g. rotated) Text editing? Ever wondered why most Cocoa applications do not support transformed text editing?

Remember that as a subclass of NSView, NSTextView inherits its -setFrameRotation: accessor method from NSView.

First of all I miss a -setFrameTransform: method, that would allow free transformation to be applied to instances of NSView. But there is the rotation feature only for now.
But even this is not working correctly.

As text caret (the text cursor) and red markers for misspelled words are drawn in base coo system (the coo system of the window the view belongs to) the rotated results are quite funny:
All the text is formatted and drawn correctly. Even the selected and marked text ranges are drawn correctly. But blinking text caret and misspelled words markers get drawn unrotated.

So right now transformed text editing is impossible to achieve without writing your own text editor.

Friday, April 13, 2007

CMYK and Grayscale graphics contexts

You may think that Cocoa fully supports RGB, CMYK and Greyscale pixel formats. In fact it doesn't.
OK, you are able to load and display various file and pixel formats.
But if you'd plan to write a pixel format converter, you will find out that Quartz does not support CMYK+Alpha and Grayscale+Alpha in bitmap graphics contexts. This is documented correctly. See "Supported Pixel Formats" for details.
That means a pixel format conversion by drawing a RGB+A image into a CMYK+A image context is simply impossible. You'd have to do it by hand.

These unsupported pixel formats also cause another gap:
You cannot create a CMYK+A or Grayscale+A bitmap context to draw objects directly to it.

I filed an enhancement request to apple in August 2005 ( Problem ID: 4225167).

The Beginning

Working on iCalamus for about four years now, I decided to start a blog about all the major caveats I came across along the road. Be prepared to hear about strange bugs that Apple did not resolved so far (Tiger 10.4.9), missing functionality and other issues you will encounter when diving deeply into cocoa framework.
Don't get me wrong, I still like cocoa a lot. I just try to do some informal job here.