d12frosted / homebrew-emacs-plus

Emacs Plus formulae for the Homebrew package manager
MIT License
2.35k stars 181 forks source link

SVG rendering issues #620

Closed whodevil closed 11 months ago

whodevil commented 1 year ago

installed with

brew install emacs-plus --with-dragon-icon --with-mailutils --with-xwidgets --with-imagemagick

I was previously using the emacs-mac cask in homebrew, but someone told me to take a look at this formula in the #emacs libera channel. I like the extra features of this build, but I can't get svg to render correctly in notmuch

What it looks like in my install with emacs-plus Screenshot 2023-09-29 at 6 08 20 PM

What it is supposed to look like:

Screenshot 2023-09-29 at 5 57 50 PM
d12frosted commented 1 year ago

Hey @whodevil

To my knowledge, SVG support in GNU Emacs is not as good as in emacs-mac (which uses a completely different 'renderer'). And in general, rendering works differently between these two.

That being said, it's not completely impossible. For example, I have the following buffer:

image

It is based on (a slightly modified version of) https://github.com/rougier/svg-lib. Nicolas P. Rougier is known for building Emacs UIs with lots of fancy icons/SVGs.

It's hard to tell what's wrong without knowing how exactly you draw these images.

whodevil commented 1 year ago

I have something that looks like this in my config.

(after! notmuch
  (setq notmuch-tag-formats
        '(("attachment" (propertize tag 'display `(image :type svg 
                                                         :ascent center 
                                                         :mask heuristic 
                                                         :file "~/.config/doom/icons/attachment.svg")))))

Does this help? Based on your screenshot it seems like I should be able to get this working. I've been using this build of emacs and I really like it, so I want to try to make it work. Any other suggestions would be really appreciated!

d12frosted commented 1 year ago

@whodevil Yeah, it should be working. But keep in mind that it doesn't work when font-lock-mode is enabled. You can test it like this:

  1. Open a scratch buffer.
  2. Disable font-lock-mode (probably by just M-x font-lock-mode until it says the mode is disabled).
  3. M-: (insert-image (image :type svg ...)) <ret>

You should see the image. If you enable font-lock-mode, the image becomes broken. Disabling font-lock-mode again doesn't restore the image.

While writing this I asked myself. Why does font-lock-mode break rendering of svg images? And I don't have answer yet. 😿 if someone knows - please let me know!

d12frosted commented 1 year ago

Oh lol. I asked ChatGPT this question and here is the answer:


SVG images are typically not displayed in Emacs buffers when font-lock-mode is enabled because Emacs uses a different rendering mechanism for text and for images. font-lock-mode is a mode in Emacs that provides syntax highlighting for code and text files. When this mode is enabled, Emacs focuses on rendering and highlighting text, and it may not have built-in support for rendering complex graphics formats like SVG.

Emacs can display images in certain formats, such as PNG, JPEG, and GIF, by using external programs like ImageMagick or by utilizing native Emacs libraries. However, SVG is a vector graphics format, and rendering SVG images directly within an Emacs buffer is a more complex task. Emacs may not have native support for rendering SVG images because of the complexity of SVG and the fact that SVG images can contain scripting and interactive elements, which would require a full-fledged SVG rendering engine.

To display SVG images in Emacs, you might need to use external tools or libraries. One common approach is to use the "image+" package, which provides enhanced image support for Emacs and can handle various image formats, including SVG. You can configure it to display SVG images using external tools like ImageMagick's convert command. Here's an example of how you can set up image+ to display SVG images:

(require 'image+)

(setq image+--imagemagick-types '(svg))
(setq image+-display-image-externally-alist
      '((svg . (image+-display-imagemagick-externally))))

(add-hook 'image-mode-hook 'image+-setup)

This configuration tells Emacs to use ImageMagick to display SVG images when you open them in image-mode. Keep in mind that you'll need to have ImageMagick installed for this to work.

Please note that Emacs configurations and package availability may change over time, so it's a good idea to check the latest documentation and package availability for your specific Emacs setup.


That kind of makes sense. And I believe emacs-mac supports SVG images without any user-level hacks because they have a very different renderer, which is cool.

whodevil commented 11 months ago

ChatGPT is making my life easier, the other day I had it get me 80% the way there on a weechat plugin.

I think I'll poke at your suggestions for a little this coming weekend. For now I've moved my tagging over to using nerd font glyphs, and it works fine with this build. emacs-mac doesn't support xwidgets-webkit, at least not in a way I could figure out, and I'm really enjoying elfeed-webkit, so I don't really see myself wanting to go back to life without it hahaha.

Thanks!