From b20bd31dd44ad5df79a50c82aebc77d8b8132d19 Mon Sep 17 00:00:00 2001 From: Sacha Chua Date: Wed, 2 Nov 2022 13:05:40 -0400 Subject: Use SVGs for overlays --- emacsconf-stream.el | 95 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 38 deletions(-) (limited to 'emacsconf-stream.el') diff --git a/emacsconf-stream.el b/emacsconf-stream.el index 755d565..19fe049 100644 --- a/emacsconf-stream.el +++ b/emacsconf-stream.el @@ -39,14 +39,25 @@ Files should be in YEAR/video-slug--main.webm and video-slug--main.vtt.") (defvar emacsconf-stream-bottom-limit 80 "Number of characters for bottom text.") -(defun emacsconf-stream-write-news (track message) +(defun emacsconf-stream-set-news (track message) (interactive (list (emacsconf-complete-track) (read-string "Message: "))) - (with-temp-file (expand-file-name "news.txt" (concat (emacsconf-stream-track-login track) "~")) - (insert message))) + (let* ((home (concat (emacsconf-stream-track-login track) "~")) + (default-directory home) + (filename (expand-file-name "other.svg" home)) + (dom (xml-parse-file filename))) + (emacsconf-stream-svg-set-text dom "news" message) + (with-temp-file filename (dom-print dom t)) + (with-temp-file (expand-file-name "video.svg" home) + (emacsconf-stream-svg-set-text dom "bottom" "") + (dom-print dom t)) + ;; (shell-command "inkscape --export-type=png --export-dpi=96 --export-background-opacity=0 video.svg") + ;; (shell-command "inkscape --export-type=png --export-dpi=96 --export-background-opacity=0 other.svg") + )) (defun emacsconf-stream-broadcast (message) (interactive (list (read-string "Message: "))) - (mapc (lambda (track) (emacsconf-stream-write-news track message)) emacsconf-tracks)) + (mapc (lambda (track) (emacsconf-stream-set-news track message)) + emacsconf-tracks)) (defun emacsconf-stream-clear-talk-info (track) (interactive (list (emacsconf-complete-track))) @@ -55,60 +66,68 @@ Files should be in YEAR/video-slug--main.webm and video-slug--main.vtt.") (defun emacsconf-stream-clear-track (track) (interactive (list (emacsconf-complete-track))) (emacsconf-stream-set-talk-info-from-strings track "" "") - (emacsconf-stream-write-news track "")) + (emacsconf-stream-set-news track "")) (defun emacsconf-stream-clear-all () (interactive) (mapc #'emacsconf-stream-clear-track emacsconf-tracks)) +(defun emacsconf-stream-svg-set-text (dom id text) + "Update DOM to set the tspan in the element with ID to TEXT. +If the element doesn't have a tspan child, use the element itself." + (setq text (svg--encode-text text)) + (let ((node (or (dom-child-by-tag + (car (dom-by-id dom id)) + 'tspan) + (dom-by-id dom id)))) + (cond + ((null node)) ; skip + ((and (string= text "") + (= (length node) 2))) ; already nothing, skip + ((string= text "") + (setf (elt node 2) "")) + ((= (length node) 2) + (nconc node (list text))) + (t (setf (elt node 2) text))))) + (defun emacsconf-stream-set-talk-info-from-strings (track url bottom) (interactive (list (emacsconf-complete-track) (read-string "URL: ") (read-string "Bottom: "))) (let* ((home (concat (emacsconf-stream-track-login track) "~")) - (default-directory home)) - (with-temp-file (expand-file-name "url.txt" home) - (insert url)) - (with-temp-file (expand-file-name "bottom.txt" home) - (insert bottom)) + (default-directory home) + (filename (expand-file-name "other.svg" home)) + (dom (xml-parse-file filename))) + (emacsconf-stream-svg-set-text dom "bottom" bottom) + (emacsconf-stream-svg-set-text dom "url" url) + (with-temp-file filename (dom-print dom t)) (with-temp-file (expand-file-name "video.svg" home) - (insert - (emacsconf-replace-plist-in-string - (list - :news - (with-temp-buffer - (insert-file-contents (expand-file-name "news.txt" home)) - (buffer-string)) - :url - url - :bottom - bottom) - (with-temp-buffer - (insert-file-contents (expand-file-name "roles/obs/video.svg" emacsconf-ansible-directory)) - (buffer-string))))) - (shell-command "inkscape --export-type=png --export-dpi=96 --export-background-opacity=0 video.svg"))) + (emacsconf-stream-svg-set-text dom "bottom" "") + (dom-print dom t)) + ;; (shell-command "inkscape --export-type=png --export-dpi=96 --export-background-opacity=0 video.svg") + ;; (shell-command "inkscape --export-type=png --export-dpi=96 --export-background-opacity=0 other.svg") + )) (defun emacsconf-stream-set-talk-info (talk) (interactive (list (emacsconf-complete-talk-info))) (emacsconf-stream-set-talk-info-from-strings (emacsconf-get-track talk) (concat (replace-regexp-in-string "^.*//" "" emacsconf-base-url) - (plist-get talk :url)) - (concat (cond - ((or (null (plist-get talk :pronouns)) (string= (plist-get talk :pronouns) "nil")) - (plist-get talk :speakers)) - ((string-match ", " (plist-get talk :pronouns)) - (plist-get talk :pronouns)) - (t (format "%s (%s)" - (plist-get talk :speakers) - (plist-get talk :pronouns)))) - "\n" + (plist-get talk :url) (cond ((string-match "live" (plist-get talk :q-and-a)) - "Q&A: live - see talk page for URL") + " - Q&A: live (see talk page for URL)") ((string-match "irc" (plist-get talk :q-and-a)) - (format "Q&A: IRC (#%s) - speaker nick: %s" + (format " - Q&A: IRC (#%s) - speaker nick: %s" (plist-get track :channel) (plist-get talk :irc))) - (t ""))))) + (t ""))) + (cond + ((or (null (plist-get talk :pronouns)) (string= (plist-get talk :pronouns) "nil")) + (plist-get talk :speakers)) + ((string-match ", " (plist-get talk :pronouns)) + (plist-get talk :pronouns)) + (t (format "%s (%s)" + (plist-get talk :speakers) + (plist-get talk :pronouns)))))) (defun emacsconf-stream-update-talk-info-org-after-todo-state-change () "Update talk info." -- cgit v1.2.3