[cairo] Re: Cairo font size should be in units

Bill Spitzak spitzak at d2.com
Tue Sep 28 16:09:02 PDT 2004


On Tuesday 28 September 2004 01:15 pm, graydon hoare wrote:
> On Tue, 28 Sep 2004 11:11:30 -0700, Bill Spitzak <spitzak at d2.com> wrote:
> > My only concern here is to avoid some problems with some other API's. I
> > am quite tired of API's where fonts are measured in a different transform
> > (usually called "points") than every other graphic.
>
> well, we've discussed this somewhat on IRC, and I certainly accept what
> you're saying. it may well make sense to do as you say -- it is only a
> couple lines of code to change either way -- but I'd like to clarify that
> this is not actually a cut-and-dried issues as you suggest:
>
>   - the line spacing is only one metric of a font.

Sorry if it was misleading by mentioning line spacing all the time. What I 
absolutly require is that all metricies including line spacing of a font are 
fixed given a set of controls used to select that font. It cannot depend on 
any uncontrollable factor such as a "DPI" that I cannot directly set with a 
Cairo API.

Now my proposal will certainly be taken advantage of by programs that realize 
they can guess the line spacing without selecting the font and asking about 
it. Whether these programs are doing the right thing or not is a seperate 
question, the ability to do this is not my purpose. What I want is to get the 
same line spacing for the same font and arguments on all output devices and 
at all CTM's.

>   - the correct way to do layout is to pick an EM size which is somewhat
> near the ballpark you want, and ask for metrics.

My problem is that under the proposed DPI system, "the ballpark" requires me 
to query what the DPI is so that I can figure out a number of points. I see 
this as a total waste of time.

>     deciding on a layout metric a priori and then telling the graphics
> toolkit to "make the font suit that size" is imo the wrong way to design
> it; it can't even be guaranteed to *work* for anything other than EM size.

Yes, a GUI that scales to match the user-selected font size is a good thing. 
However this is completely irrelevant to whether selecting a font size is in 
"points" or "pixels".

>   - many APIs start with points. many naive programmers sitting down to
> work with cairo will want to speak in terms of points.

I think this is completly false and a bogus argument.

If this was true then shapes and line thicknesses and dash lengths would also 
be specified in points. Obviously they are not, and nobody is suggesting they 
be.

People "think in points" because of GUI's that present "points" and they have 
learned that "12" is "about the right size". In fact, ask people how big the 
cursor is in pixels, and they will consistently underestimate by 3/4 because 
they are comparing it to the text, so it is pretty obvioius that people think 
the font size is measured in pixels, not points.

I can tell you that as a "naive programmer" I certainly DO NOT expect the 
units used to measure fonts to be anything different than the units used to 
measure everything else I'm drawing. The entire reason for me arguing to 
measure things in pixels is precisely because this *IS* what a naive 
programmer expects!

> > Also it is important (and I think everybody agrees) that Cairo scales
> > should not cause the glyph metricies to change, although the glyphs
> > themselves can change shape a bit due to hinting. Otherwise it is
> > impossible to reproduce a graphic at different sizes, for instance a
> > simple right-justify will no longer produce a straight right edge.
>
> I don't understand this paragraph. do you mean:

>    - changing cairo's CTM should not cause a glyph's metrics to change?

YES

>    - changing cairo's CTM should not cause such metrics to change in a
>      way other than multiplying each metric by the CTM?

Glyph metricies must be reported in the CTM input space, so certainly 
changing the CTM should not do any such multplication.

>    - changing cairo's CTM should not cause a font's matrix to change?

Yes, the "font matrix" does not change. Glyphs change because they are drawn 
using the concatenation of the font and CTM matricies.

>    - changing cairo's font matrix should not cause a glyph's metrics to
> change?

No, changing the font matrix should certainly change the metrics. In general 
if the font matrix is scaled up by 2, metricies all scale up by approximately 
2 (though maybe not exactly that as the font matrix is allowed to 
differentiate between sizes in fonts that draw different shapes at different 
point sizes).

> but as you (and carl, and others) have argued, maybe a "1 user unit EM
> square" makes more sense as an initial font size than a "(1 point * CTM) EM
> square". it only takes a moment to change. I have tried it both ways and it
> works. the practical difference is that fonts are 0.75x smaller or larger
> (this 72/96 ratio) given the same client code. I'm open to either approach.

Absolutley this sounds like what I want.

The scale can be handled easily by very high-level code. If you read a "point 
size" from some configuration file, it is pretty easy to multiply by 4/3 
before passing it to Cairo.



More information about the cairo mailing list