cocoa graphics cursor advance

From: Tomas Frydrych <tomasfrydrych_at_yahoo.co.uk>
Date: Mon Sep 27 2004 - 21:18:35 CEST

This is to follow up on the discussion we have earlier today on IRC
regarding the cocoa caret getting gradually ahead of its character
position as it moves toward the right margin; we used to have this
same problem on win32, and summarising the issues should hopefully
help whoever will be fixing this.

The default mechanism for advancing the caret works like this:

We measure each individual character in a given font and size and
story these widths in a cache; when asked to measure text, we simply
lookup the widths for each char in a cache and add them up.

The problem was that on win32 widthof('xyz') != widthof(x) +
widthof(y) + widthof(z). Instead, the system drawing routines
position characters closer together (I think this has to do with
processing some of the more advanced info in the font tables, but
could be wrong).

In order to avoid the caret getting ahead of the text, there are two
options, both of which have been implemented on win32:

(1) -- force the system to draw so as to ensure widthof('xyz') ==
widthof(x) + widthof(y) + widthof(z). This method has been
implemented in the GR_Win32Graphics class; it simply involves passing
our character advances down to the OS drawing routines.

(2) -- use the system API to calculate width of runs and positioning
of caret. This method is implemented in the gr_Win32USPGraphics
class. This is slightly more involved, but by far preferable; not
only is the text spacing produced by the OS more visually pleasing to
that we produce through the default mechanism, but also using the
system caret positioning API allows us to handle complex scripts
correctly without any extra work.

Method 2 requires that the graphics class implements the virtual
methods XYToPosition(), positionToXY() and getTextWidth().

Tomas
Received on Mon Sep 27 21:18:08 2004

This archive was generated by hypermail 2.1.8 : Mon Sep 27 2004 - 21:18:11 CEST