unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Anand Tamariya <atamariya@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Alexander Adolf <alexander.adolf@condition-alpha.com>,
	Emacs Devel <emacs-devel@gnu.org>
Subject: Re: SVG hack for display engine
Date: Thu, 18 Nov 2021 05:17:47 +0530	[thread overview]
Message-ID: <CADm7Y4nj_Nx2tSG7q+5V9FhCKxQ4=2e585ncPff5Mq6ammf4YA@mail.gmail.com> (raw)
In-Reply-To: <83mtm2zyf6.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 3511 bytes --]

> Please describe the intended use of these APIs and the hook to provide
> the display feature(s) you have in mind, and how will that work in
> concert with the display engine.  I don't think I have a clear picture
> of that yet.
>
> Also, please describe what happens with use of these APIs when just a
> small part of the Emacs display needs to be redrawn.
>
> Maybe a demo ( https://youtu.be/1343m3LY4mo ) will help you visualize my
suggestion. In the video, an event loop is started in the scratch buffer.
All the edit operations update text and text property in a temporary
buffer, say a.txt. Based on this information, in-memory SVG DOM is updated.
Ultimately, the display engine updates the view with this SVG image. In
cases like this, the mode can have full control over the display if so
desired.

Since you have a problem accessing my repo, I've added the code of a
function I call in my event loop at the end of this mail.

With a tighter integration, Emacs would define a new data structure {svg,
x, y, w, h} and two new variables with this type - new_svg and prev_svg.
Then the sequence of operations would be:
- Display engine refreshes the view bitmap with current logic - full or
partial refresh as the case may be.
- If it's a graphical display
- prev_svg = new_svg
- Run display-svg-hook. The registered user function will call (svg-render)
function passing required information. This API sets the value in new_svg.
- If the bounding box of new_svg < the bounding box of prev_svg, display
engine refreshes the area of prev_svg in the view bitmap.
- Generate a bitmap for new_svg and superimpose it on the view bitmap.
- Display the view bitmap to the user.

Hope this helps.

(defun formula-canvas-mode (key svg)
  (let* ((func (lookup-key global-map (vector key)))
         (i 0)
         (size 20)
         mkey win
         text x y id point pos start end opts)
    ;; (message "Before: %s %s" key func)
    (unless func
      (setq mkey (lookup-key local-function-key-map (vector key))
            func (lookup-key global-map mkey)))
    ;; (message "After: %s %s" key func)

    (with-current-buffer (get-buffer-create "a.txt")
      (when func
        (condition-case var
            (if (eq func 'self-insert-command)
                (funcall func 1 key)
              (funcall func 1))
          (error (message (format "Error: %s" (car var)))))

        (save-excursion
          (setq win (get-buffer-window))
          (goto-char (window-start win))
          ;; Need to keep popup at the end
          ;; (setq svg (subseq svg 0 2))
          (dom-remove-node svg (car (dom-by-id svg "_popup")))
          (while (< (point) (window-end win))
            (setq start (point)
                  end (progn (end-of-line) (point))
                  text (buffer-substring start end)
                  id (number-to-string i)
                  x 0
                  y (* (1+ i) size))
            (setq i (1+ i))
            (forward-line)
            ;; Text
            (svg-text svg text :id id :x x :y y :xml:space "preserve")))

        ;; Cursor
        (setq pos (posn-col-row (posn-at-point (point) win))
              point (* 4 (car pos))
              y (* size (cdr pos)))
        (svg-rectangle svg point y 5 size
                       :id "_cursor" :fill "black" :opacity "0.4")
        ;; Popup
        (setq opts '("a" "b" "c" ))
        (if opts
            (formula-canvas-popup svg point (+ y size) opts))
        (svg-possibly-update-image svg)
        )
      )))

[-- Attachment #2: Type: text/html, Size: 4744 bytes --]

  reply	other threads:[~2021-11-17 23:47 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-15  2:39 SVG hack for display engine Anand Tamariya
2021-11-15 12:45 ` Eli Zaretskii
2021-11-15 13:27   ` Anand Tamariya
2021-11-15 14:02     ` Eli Zaretskii
2021-11-16  3:01       ` Anand Tamariya
2021-11-16  3:28         ` Po Lu
2021-11-16 12:56           ` Eli Zaretskii
2021-11-16 13:02             ` Po Lu
2021-11-16 12:55         ` Eli Zaretskii
2021-11-16 14:08           ` Alexander Adolf
2021-11-16 14:16             ` Eli Zaretskii
2021-11-16 14:22               ` Alexander Adolf
2021-11-17  4:33               ` Anand Tamariya
2021-11-17  4:46                 ` Po Lu
2021-11-26  1:33                   ` Gerry Agbobada
2021-11-17 13:47                 ` Eli Zaretskii
2021-11-17 23:47                   ` Anand Tamariya [this message]
2021-11-18  8:16                     ` Eli Zaretskii
2021-11-18 10:13                       ` Anand Tamariya
2021-11-18 11:21                         ` Eli Zaretskii
2021-11-18 13:29                           ` Anand Tamariya
2021-11-18 14:52                             ` Eli Zaretskii
2021-11-19  1:32                               ` Anand Tamariya
2021-11-19  7:07                                 ` Eli Zaretskii
2021-11-20 19:44                                 ` Alan Third
2021-11-22  2:48                                   ` Anand Tamariya
2021-11-22 10:59                                     ` Alan Third

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADm7Y4nj_Nx2tSG7q+5V9FhCKxQ4=2e585ncPff5Mq6ammf4YA@mail.gmail.com' \
    --to=atamariya@gmail.com \
    --cc=alexander.adolf@condition-alpha.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).