emacs-devel
[Top][All Lists]
Advanced

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

Re: ELPA: New package: svg-lib


From: Nicolas P. Rougier (inria)
Subject: Re: ELPA: New package: svg-lib
Date: Mon, 27 Sep 2021 20:03:12 +0200
User-agent: mu4e 1.6.6; emacs 27.2


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)))

#+END_SRC

Nicolas

Alan Third <alan@idiocy.org> writes:

On Mon, Sep 27, 2021 at 03:49:16PM +0200, Nicolas P. Rougier (inria) wrote:

Note that there is still a pending bug with text size for some users (see https://github.com/rougier/svg-tag-mode/pull/14. This is a different project
but the problem is the same). Any help appreciated.

Hi Nicolas,

I had my own go at matching SVG images and Emacs's text rendering at
one time and my code is here:

    https://gist.github.com/alanthird/7b86dc66df1ed3b9006bcd3fddd7350f

I was really just messing about, though, so it's probably not much
use.

Reading through that bug report I'm not 100% sure what is going on, but I do suspect there may be some confusion as the behaviour of SVG
rendering has changed between Emacs 27 and Emacs 28.

For the most part Emacs 28 _should_ do the right thing. i.e. 1em
matches the exact font size used at the insertion point and the
default font family should also match the font at the insertion point. Emacs 28 also adds the ability to set image sizes with '(1 . em), to make it easier to make images scale with the font (we're using that to
display checkboxes in customize, and so on).

It also should set the DPI accurately so that 1cm == 1 real world cm, except possibly on Macs where Apple's recommended DPI behaviour is...

Strange.

Unfortunately I guess you still have to support Emacs 27 (and below?)
so perhaps none of that really helps you.

When generating images I'd suggest always setting the image scale to 1, as that avoids any strange resizing behaviour that may be caused by the image creation code attempting to rescale images to match the font
size.

Finally we have a bug open about screen DPIs (bug#49937) although it
probably has nothing to do with the problems you're seeing.




reply via email to

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