[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ELPA: New package: svg-lib

From: Alan Third
Subject: Re: ELPA: New package: svg-lib
Date: Mon, 27 Sep 2021 21:19:42 +0100

On Mon, Sep 27, 2021 at 08:03:12PM +0200, Nicolas P. Rougier (inria) wrote:
> Thanks for the information and the code. I did not know about the difference
> between Emacs 27 and 28. I did not have a change to test 28.
> My problem can be tested with the code below. The goal is to output an "A"
> using SVG and compare it to a regular "A". Ideally, they would need to be
> the same with very minor differences (due to different aliasing). But for
> some users and for unknown reason, the svg text size is plainly wrong.
> Can you confirm this code works as expected with emacs 28 ?
> #+BEGIN_SRC emacs-lisp
> ;; To adapt font weight:
> ;; '((thin       . 100) (ultralight . 200) (light      . 300)
> ;;   (regular    . 400) (medium     . 500) (semibold   . 600)
> ;;   (bold       . 700) (extrabold  . 800) (black      . 900))))
> (let* ((w           (window-font-width))
>       (h           (window-font-height))
>       (font        (query-font (font-at (point-min))))
>       (font-family (face-attribute 'default :family))
>       (font-size   (elt font 2))
>       (descent     (elt font 4))
>       (svg (svg-create w h)))
>  ;; (svg-rectangle svg 0 0 w h :stroke "black" :fill "none")
>  (svg-text svg "A"
>            :x           0
>            :y           descent
>            :font-family font-family            :font-weight 300
>            :font-size   font-size
>            :fill        (face-attribute 'default :foreground))
>  (insert-image (svg-image svg :ascent 'center)))

It's very close. It looks almost completely identical under GNUstep,
but under GTK it looks like the SVG text is sometimes about one pixel
taller, which makes it look slightly different at the default size
(14, I think?) but at larger sizes it looks near identical.

I suspect the difference I'm seeing is simply down to different font
rendering backends.

I'm not using hi-dpi, but even setting GDK_SCALE=2 doesn't make any

FWIW, I believe that librsvg defaults to 96dpi, however I'm not sure
that it always did, I've a feeling it used to use something different,
so different versions of librsvg may use different default DPIs. Only
Emacs 28 explicitly sets a DPI, so Emacs 27 will use whatever is
default for librsvg.

I ended up using pixels for font sizes rather than trying to get point
sizes to match up. When I DID try to use point sizes, on macOS I had
to multiply every size by something like 72/96. That calculation would
vary with OS and GUI toolkit, and possibly monitor size too.

Alan Third

reply via email to

[Prev in Thread] Current Thread [Next in Thread]