Klaus Straubinger | 15 Dec 10:16
Picon

wrong font-size calculations in css.el and font.el

The function css-expand-length does not take the default character size
in pixels into account when calculating em and ex values. This results
typically in values very much too large.

I would like to suggest using something like the following in the
condition branch that deals with em and ex values:

    (round (font-spatial-to-canonical
            (concat (number-to-string
                     (* (string-to-number (match-string 1 spec))
                        (if height (frame-char-height) (frame-char-width))))
                    "px")))

I don't know if it is advisable to use font-spatial-to-canonical. But
it could be used in other places in this function too.

By the way, this function font-spatial-to-canonical has another bug:
Pixel values are calculated with

	(setq retval (* num (/ pix-width mm-width) (/ 25.4 72.0))))

instead of the correct

	(setq retval (* num (/ mm-width pix-width) (/ 72.0 25.4))))

i.e., exactly the other way round with respect to dividing and
multiplying.

--

-- 
Klaus Straubinger
(Continue reading)

Magnus Henoch | 15 Dec 16:24
Picon

Re: wrong font-size calculations in css.el and font.el

Klaus Straubinger <KSNetz <at> UseNet.ArcorNews.DE> writes:

> The function css-expand-length does not take the default character size
> in pixels into account when calculating em and ex values. This results
> typically in values very much too large.
>
> I would like to suggest using something like the following in the
> condition branch that deals with em and ex values:
>
>     (round (font-spatial-to-canonical
>             (concat (number-to-string
>                      (* (string-to-number (match-string 1 spec))
>                         (if height (frame-char-height) (frame-char-width))))
>                     "px")))
>
> I don't know if it is advisable to use font-spatial-to-canonical. But
> it could be used in other places in this function too.

This is not entirely correct, as these specifications are relative to
the font size of the enclosing element, not to the default font size.
However, this is good enough for now (until I find time to look at how
css.el handles inheritance), so I applied your change.

> By the way, this function font-spatial-to-canonical has another bug:
> Pixel values are calculated with
>
> 	(setq retval (* num (/ pix-width mm-width) (/ 25.4 72.0))))
>
> instead of the correct
>
(Continue reading)

Magnus Henoch | 10 Mar 03:24
Picon

Re: wrong font-size calculations in css.el and font.el

Klaus Straubinger <KSNetz <at> UseNet.ArcorNews.DE> writes:

> The function css-expand-length does not take the default character size
> in pixels into account when calculating em and ex values. This results
> typically in values very much too large.

I'm not quite sure about this anymore... It seems to me that
css-expand-length is supposed to return the number of character cells
needed to fill the given length (at least w3-display-handle-list-type
in w3-display.el assumes that; see the format string involving
"margin"), not the length in points; the previous version did the
former, but apparently (see <URL:http://article.gmane.org/gmane.emacs.
devel/67607>) this makes lists annoyingly wide.  What problem was this
change supposed to solve?

Magnus
Klaus Straubinger | 14 Mar 17:12
Picon

Re: wrong font-size calculations in css.el and font.el

Magnus Henoch wrote:

> Klaus Straubinger <KSNetz <at> UseNet.ArcorNews.DE> writes:

>> The function css-expand-length does not take the default character size
>> in pixels into account when calculating em and ex values. This results
>> typically in values very much too large.

> I'm not quite sure about this anymore... It seems to me that
> css-expand-length is supposed to return the number of character cells
> needed to fill the given length

Well, I only proposed a change to remove an inconsistency I observed.
The percentage case of the function obviously returns pixel values, by
multiplying with (frame-char-height) or (frame-char-width), respectively.

I now see that there still is an inconsistency because the last case
and my proposed correction use font-spatial-to-canonical which returns
points, not pixels. Of course, on many displays that is not much of a
difference so it went unnoticed.

> What problem was this change supposed to solve?

I saw extraordinarily large characters when a style sheet specified em
or ex values.

I would like to see the function css-expand-length brought to full
consistency, i.e., it should always return a number in the same unit
of measurement, and the callers of this function should be adapted to
work with that unit (I only thought of the font-size case, admittedly).
(Continue reading)


Gmane