Re: From Luca, Maths In AbiWord.

From: Luca Padovani <lpadovan_at_cs.unibo.it>
Date: Tue May 17 2005 - 10:00:17 CEST

On Tue, 2005-05-17 at 16:18 +1000, Martin Sevior wrote:
> renderer but is having trouble interfacing with our zooming code.

First of all a nice screenshot of what we've accomplished so far:

http://www.cs.unibo.it/~lpadovan/secret/Screenshot-1.png

(Martin: this looks much better than the one I sent you yesterday)

Let me add a little background. In short, it is fundamental to be able
to measure a glyph precisely, not just its width, but also its height
(the distance from the baseline to the highest "black" pixel in the
glyph) and its depth (the distance from the baseline to the lowest
"black" pixel in the glyph).

This is especially important for those math symbols that get built up
from smaller glyphs (like stretched parentheses or the square root
symbol) in which the glyphs are stacked together or combined in more or
less twisted ways.

The AbiWord graphics class allows one to retrieve the following
information for a character m_ch:

* width (graphics->measureUnRemappedChar(m_ch))
* font ascent (graphics->getFontAscent())
* font descent (graphics->getFontDescent()))

and these are, if I get the terminology right, in device units.

Ascent and descent can be thought of just a rough approximation for
m_ch's height and depth, and hence they result in suboptimal rendering
in most cases.

On the other side, the font class allows one to retrieve width, height
and depth for a glyph:

  f->glyphBox(m_ch, glyphRect);

however glyphRect.width, glyphRect.height, and glyphRect.depth are in
logical units.

At present, the hack for converting these logical units into device
units works as follows: we read the width of character in both logical
and device units:

  const float logicalWidth = f->measureUnremappedCharForCache(m_ch);
  const float deviceWidth = graphics->measureUnRemappedChar(m_ch);

and we multiply each entry in the glyphRect record by the ratio

  deviceWidth / logicalWidth

We're not happy with this approach because
1) it _looks_ dirty
2) it gives (slightly) different ratios depending on the character m_ch,
which is for me a sign that it _is_ dirty

Until a few days ago, I worked around (2) by asking logical and device
width of a common character (the blank), until I realized that some
fonts (in particular some of the fonts for math) don't have a glyph for
the blank and so the ratio becomes a useless NAN.

I'm sure somebody more expert than me on AbiWord's internal may provide
valuable comments.

Cheers,
--luca

Received on Tue May 17 10:01:14 2005

This archive was generated by hypermail 2.1.8 : Tue May 17 2005 - 10:01:15 CEST