-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong sizes on high resolution screens #12
Comments
Thanks for the report. For the weird calling for high resolution, do you know if this is related to the difference between actual scrren resolution vs system resolution? Also, on your screenshot, what is the font size of text? |
Just added |
I don't know. I am using the monitors native resolution.
I already tried that. It doesn't seem to do anything. The only documentation I could find about this is in
(list (window-font-width)
(window-font-height))
=> (13 27) |
Could you evaluate
Replacing the font-family and font size with yours. After evaluating the SVG and type "A" just next to the svg image in order to compare SVG text size vs emacs text size? |
How does one determine the font size? |
Anyway, I think the value is 16, because I have set |
The size is expressed in 1/10th of point hence 158 is 16. If you can't seen the letter, you can |
I've figured it out but it will be a few days until I get around to a pull-request. |
If I can contribute to this: I seem to be seeing the same problem on a high-resolution screen, with X set to 144 DPI. Using the test code above, I need to bump the font-size up to 19 to look approximately the same size as a normally-typed I also note that if I omit the font-size line in the code above, then it does draw as the correct size. |
You mean |
Yessir |
Hi, Just tried on windows 10. My screen is hidpi and I can barely see the text within the box |
We're trying to debug it. Can you try code at #14 (comment) (and post in the same thread)? |
Sorry for late answer. Can you try to remove the |
Also, can you have a look at #14 (comment) (maybe best to continue discussion on this PR actually) |
Here, I did some test (I didn't look at the PR yet). (save-excursion
(forward-paragraph)
(progn ;; Delete til end of file
(delete-region (point) (point-max)))
(cl-loop
for font-family in (list "Roboto Mono Emacs Regular" "Roboto Mono" (face-attribute 'default :family)) do
(cl-loop
for font-size in (list 14 (face-attribute 'default :height)) do
(let* ((canvas-scale 8.0)
(w (* canvas-scale (window-font-width)))
(h (* canvas-scale (window-font-height)))
(svg (svg-create w h)))
(svg-rectangle svg 0 0 w h :stroke "black" :fill "none")
(svg-text svg "A"
:x 0
:y (- h 4)
:font-family "Roboto Mono Emacs Regular"
:font-size font-size
:fill "black")
(insert "\n")
(insert "A")
(insert-image (svg-image svg :scale 1 :ascent 'center))
(insert-image (svg-image svg :ascent 'center))
(insert "\t" font-family " - " (format "%s" font-size))))))
(face-attribute 'default :family) ;; => "Courier New"
(face-attribute 'default :height) ;; => 98 |
Ok, @rougier I took a look at the comment you linked and I added the code next to what I tried, it work very well: The whole shebang(save-excursion
(forward-paragraph)
(progn ;; Delete til end of file
(delete-region (point) (point-max)))
(cl-loop
for font-family in (list ;; "Roboto Mono Emacs Regular"
"Roboto Mono"
(face-attribute 'default :family))
do
(cl-loop
for font-size in (list 14
(face-attribute 'default :height)
(elt (query-font (font-at (point-min))) 3))
do
(let* ((canvas-scale (+ 0.5 (/ font-size 14)))
(w (* canvas-scale (window-font-width)))
(h (* canvas-scale (window-font-height)))
(svg (svg-create w h)))
(svg-rectangle svg 0 0 w h :stroke "black" :fill "none")
(svg-text svg "A"
:x 0
:y (- h 4)
:font-family "Roboto Mono Emacs Regular"
:font-size font-size
:fill "black")
(insert "\n")
(insert "A")
(insert-image (svg-image svg :scale 1 :ascent 'center))
(insert-image (svg-image svg :ascent 'center))
(insert "\t" font-family " - " (format "%s" font-size) " ")
(let* ((text "Hello guys!")
(font (query-font (font-at (point-min))))
(font-size (elt font 2))
(family (face-attribute 'default :family))
(descent (elt font 4))
(ascent (elt font 5))
(svg-height (+ ascent descent))
(char-width (elt font 7))
(svg-width (* char-width (length text)))
(svg (svg-create svg-width svg-height)))
(svg-rectangle svg 0 0 svg-width svg-height :stroke "black" :fill "none")
(svg-text svg text
:fill "red"
:stroke-width 0
:font-family family
:font-weight "300"
:font-size font-size
:x 0
:y descent)
(insert-image (svg-image svg :ascent 'center)))
))))
(face-attribute 'default :family) ;; => "Courier New"
(face-attribute 'default :height) ;; => 98
(font-at (point)) ;; => #<font-object "-outline-Fira Mono-normal-normal-normal-mono-13-*-*-*-c-*-iso8859-1"> |
Thanks for these tests. The last version seems better but the baseline seems a bit off. |
Hello, I come back to this thread because I still have this issue. My configuration is emacs Here is an org file without ``svg-tag-mode` : Then The svg are sensibly bigger than the text. I digged a little in Because images are svg, I am quite convinced that there should exist an easy way to rescale images. For example, if you are a I would love to use Regards EDIT : it happens only with a hidpi screen with a zoom applied. With another screen, svg sizes are correct |
Any hints ? |
Where does the zoom comes from exactly ? From outside emacs? |
Yes, this is a zoom applied by windows 11. By tweaking some parameters in This issue definitely comes from the screen zoom. With another computer (same emacs config) and another screen, which does not need zooming, the text and its svg counter part are equivalent in size and appearance. I do not remember the tweaks but I will let you know as soon as I have time. Regards |
It might be possible to retrieve the magnification factor from inside emacs but I'm not sure how. Maybe through DPI computation. See also https://emacs.stackexchange.com/questions/28390/quickly-adjusting-text-to-dpi-changes |
Yes, but then, how to use it ? as an argument to I will try do debug that soon. Regards |
Not sure how to use it, but most probably you can use the zoom factor for char-height and char-width. |
Hi, I was able to correct my issue by manually modifying the This is only a workaround. I plan to uncomment the Regards |
Yes, but the idea is to have all of these calculations to be automated. It seems to be a reccuring problem though. Each time we solve one case, a new one pops out... Best would be to understand the origin of the problem or to find a parameter we could use. |
I finally got it working by modifying the (defun svg-lib-tag (label &optional style &rest args)
"Create an image displaying LABEL in a rounded box using given STYLE
and style elements ARGS."
(let* ((default svg-lib-style-default)
(style (if style (apply #'svg-lib-style nil style) default))
(style (if args (apply #'svg-lib-style style args) style))
(foreground (plist-get style :foreground))
(background (plist-get style :background))
(crop-left (plist-get style :crop-left))
(crop-right (plist-get style :crop-right))
(alignment (plist-get style :alignment))
(stroke (plist-get style :stroke))
(width (plist-get style :width))
(height (plist-get style :height))
(radius (plist-get style :radius))
;; (scale (plist-get style :scale))
(margin (plist-get style :margin))
(padding (plist-get style :padding))
(font-size (plist-get style :font-size))
(font-family (plist-get style :font-family))
(font-weight (plist-get style :font-weight))
(txt-char-width (plist-get style :txt-char-width))
(txt-char-height (plist-get style :txt-char-height))
(txt-char-height (if line-spacing
(+ txt-char-height line-spacing)
txt-char-height))
(font-info (font-info (format "%s-%d" font-family font-size)))
(font-size (aref font-info 2)) ;; redefine font-size
(ascent (aref font-info 8))
(tag-char-width (aref font-info 11))
;; (tag-char-height (aref font-info 3))
(tag-width (* width (* (+ (length label) padding) txt-char-width)))
(tag-height (* txt-char-height height))
(svg-width (+ tag-width (* margin txt-char-width width)))
(svg-height tag-height)
(tag-x (* (- svg-width tag-width) alignment))
(text-x (+ tag-x (/ (- tag-width (* (length label) tag-char-width)) 2)))
(text-y ascent)
(tag-x (if crop-left (- tag-x txt-char-width) tag-x))
(tag-width (if crop-left (+ tag-width txt-char-width) tag-width))
(text-x (if crop-left (- text-x (/ stroke 2)) text-x))
(tag-width (if crop-right (+ tag-width txt-char-width) tag-width))
(text-x (if crop-right (+ text-x (/ stroke 2)) text-x))
(svg (svg-create svg-width svg-height)))
(if (>= stroke 0.25)
(svg-rectangle svg tag-x 0 tag-width tag-height
:fill foreground :rx radius))
(svg-rectangle svg (+ tag-x (/ stroke 2.0)) (/ stroke 2.0)
(- tag-width stroke) (- tag-height stroke)
:fill background :rx (- radius (/ stroke 2.0)))
(svg-text svg label
:font-family font-family :font-weight font-weight :font-size font-size
:fill foreground :x text-x :y text-y)
(svg-lib--image svg :ascent 'center))) where I introduced I also uncommented the Then, to get a svg with correct size appearance, I have to call (svg-lib-tag "TODO" nil :height 0.5 :width 0.5 :font-size 8 Regards |
The |
Hi, just a small comment to say that the solution described by @deb75 did not to work for me as is. Instead I tweaked (in a very hackish way I am sure) The code
This worked for me. And yes the 0.3 in the code is due to the zoom of my hidpi screen. I am on linux and I use roughly a x3 zoom. |
Thanks for the report. Do you know of a way to get that factor from inside emacs? |
I didn't, but from one of the previous discussion there is this https://emacs.stackexchange.com/a/44930/37788 and using the The real dpi (which represents the screen zoom from what I understand) is set to 288 for me using |
But what is the relation with the 0.3 scaling you're using ? Is there a default dpi somewhere that we need to take into account? |
By default Xorg set dpi to 96 (ref https://wiki.archlinux.org/title/xorg#Display_size_and_DPI) , so my 288 / 96 gives me the x3 zoom. I don't know how windows does it, I also don't know about Wayland. |
Can you check if changing the OS dpi make your formula consistent? |
Thanks. Can you post here the function to get the scale such I can test it on my setup? |
Yes, here it is, with the result from my high dpi computer
|
And I get (defun org--get-display-dpi ()
"Get the DPI of the display.
The function assumes that the display has the same pixel width in
the horizontal and vertical directions."
(if (display-graphic-p)
(round (/ (display-pixel-height)
(/ (display-mm-height) 25.4)))
(error "Attempt to calculate the dpi of a non-graphic display"))) |
For me, the
which results in 3 for me (this is in fact more precise than the dpi function proposed before). |
We thus need to find what is the equivalent of this 96 dpi default for all systems. |
I am guessing you are on Mac OS since according to Wikipedia Mac OS default to 72 dpi which should explain the value you gave above. Wikipedia also says that Windows default to 96 (same as Linux). Maybe detecting the OS would be sufficient ? Plus a user override in case it fails. |
Even with 72, the scale is wrong in my case. |
The math seems to be off on high resolution screens, 3840x2160 in my case. I believe I have also tried this on a 2560x1440 screen without any issues, but it has been a while since I had that hooked up, so I am not quite sure anymore.
Emacs does some weird calling for high resolutions. Again, I don't remember any details but for my
moody
package I got thecreate-image
to stop calling by some unknown number by telling it to scale by 1 instead, using(create-image ... :scale 1)
.Note that it's not just the font size that is off, there also appear some pixels to be missing at the bottom of images.
The text was updated successfully, but these errors were encountered: