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.