[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/svg-lib 04fdd1a 08/32: Added svg-lib-concat function fo
From: |
ELPA Syncer |
Subject: |
[elpa] externals/svg-lib 04fdd1a 08/32: Added svg-lib-concat function for org-mode demo |
Date: |
Mon, 27 Sep 2021 16:57:46 -0400 (EDT) |
branch: externals/svg-lib
commit 04fdd1a49910d5a38f59328c951f200bfdff159d
Author: Nicolas P. Rougier <Nicolas.Rougier@inria.fr>
Commit: Nicolas P. Rougier <Nicolas.Rougier@inria.fr>
Added svg-lib-concat function for org-mode demo
---
README.org | 3 ++-
svg-lib-demo.org | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
svg-lib.el | 40 ++++++++++++++++++++++++++++++++++
3 files changed, 107 insertions(+), 1 deletion(-)
diff --git a/README.org b/README.org
index fc8478c..ac6cb9a 100644
--- a/README.org
+++ b/README.org
@@ -6,8 +6,9 @@ namely tags, progress bars and icons. Each object is guaranteed
to fit
nicely in a text buffer ensuring width is an integer multiple of
charater width.
-
*** Usage example
+[[file:screenshot-2.png]]
+
[[file:screenshot.png]]
diff --git a/svg-lib-demo.org b/svg-lib-demo.org
new file mode 100644
index 0000000..0019c54
--- /dev/null
+++ b/svg-lib-demo.org
@@ -0,0 +1,65 @@
+
+* Code
+#+begin_src lisp
+(require 'svg-lib)
+
+(defvar svg-font-lock-keywords
+ `(("TODO"
+ (0 (list 'face nil 'display (svg-font-lock-todo))))
+ ("DONE"
+ (0 (list 'face nil 'display (svg-font-lock-done))))
+ ("\\[\\([0-9]\\{1,3\\}\\)%\\]"
+ (0 (list 'face nil 'display (svg-font-lock-progress_percent (match-string
1)))))
+ ("\\[\\([0-9]+/[0-9]+\\)\\]"
+ (0 (list 'face nil 'display (svg-font-lock-progress_count (match-string
1)))))))
+
+(defun svg-font-lock-todo ()
+ (svg-lib-tag "TODO" nil :margin 0
+ :font-family "Roboto Mono" :font-weight 500
+ :foreground "#FFFFFF" :background "#673AB7"))
+
+(defun svg-font-lock-done ()
+ (svg-lib-tag "DONE" nil :margin 0
+ :font-family "Roboto Mono" :font-weight 400
+ :foreground "#B0BEC5" :background "white"))
+
+(defun svg-font-lock-progress_percent (value)
+ (svg-image (svg-lib-concat
+ (svg-lib-progress (/ (string-to-number value) 100.0)
+ nil :margin 0 :stroke 2 :radius 3 :padding 2
:width 12)
+ (svg-lib-tag (concat value "%")
+ nil :stroke 0 :margin 0)) :ascent 'center))
+
+(defun svg-font-lock-progress_count (value)
+ (let* ((seq (mapcar #'string-to-number (split-string value "/")))
+ (count (float (car seq)))
+ (total (float (cadr seq))))
+ (svg-image (svg-lib-concat
+ (svg-lib-progress (/ count total)
+ nil :stroke 2 :radius 3 :padding 2 :width 12)
+ (svg-lib-tag value
+ nil :stroke 0 :margin 0)) :ascent 'center)))
+
+;; Activate
+(push 'display font-lock-extra-managed-props)
+(font-lock-add-keywords nil svg-font-lock-keywords)
+(font-lock-flush (point-min) (point-max))
+
+;; Deactivate
+;; (font-lock-remove-keywords nil svg-font-lock-keywords)
+;; (font-lock-flush (point-min) (point-max))
+
+#+end_src
+
+
+* Progress count: [1/3]
+
+ - [X] DONE Sub-task 1
+ - [ ] TODO Sub-task 2
+ - [ ] TODO Sub-task 5
+
+* Progress percent: [100%]
+
+ - [X] DONE Sub-task 1
+ - [X] DONE Sub-task 2
+ - [X] TODO Sub-task 3
diff --git a/svg-lib.el b/svg-lib.el
index 93ff745..5ee0bba 100644
--- a/svg-lib.el
+++ b/svg-lib.el
@@ -68,6 +68,9 @@
;;; Code:
(require 'svg)
+(require 'xml)
+(require 'cl-lib)
+
(defgroup svg-lib nil
"SVG tags, bars & icons."
@@ -482,5 +485,42 @@ and style elements ARGS."
+(defun svg-lib-concat (svg-image-1 svg-image-2)
+ "Concatenate two svg images horizontally."
+
+ (let* ((svg (car (with-temp-buffer
+ (insert (plist-get (cdr svg-image-1) :data))
+ (xml-parse-region (point-min) (point-max)))))
+ (attrs (xml-node-attributes svg))
+ (width-1 (string-to-number (cdr (assq 'width attrs))))
+ (height-1 (string-to-number (cdr (assq 'height attrs))))
+ (children-1 (xml-node-children svg))
+
+ (svg (car (with-temp-buffer
+ (insert (plist-get (cdr svg-image-2) :data))
+ (xml-parse-region (point-min) (point-max)))))
+ (attrs (xml-node-attributes svg))
+ (width-2 (string-to-number (cdr (assq 'width attrs))))
+ (height-2 (string-to-number (cdr (assq 'height attrs))))
+ (children-2 (xml-node-children svg))
+
+ (width (+ width-1 width-2))
+ (height (max height-1 height-2))
+ (transform (format "translate(%f,0)" width-1))
+ (svg (svg-create width height)))
+
+ (dolist (child children-1)
+ (dom-append-child svg child))
+
+ (dolist (child children-2)
+ (if (not (stringp child))
+ (dom-set-attribute child 'transform transform))
+ (dom-append-child svg child))
+ svg))
+
(provide 'svg-lib)
;;; svg-lib.el ends here
+
+
+
+
- [elpa] externals/svg-lib e2d2d68 10/32: Better screenshot, (continued)
- [elpa] externals/svg-lib e2d2d68 10/32: Better screenshot, ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib 952016b 11/32: Fix tasks status, ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib ebde091 22/32: Added progress pies, ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib b67b120 30/32: Cosmetic changes, ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib 90bb561 18/32: Added tag example, ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib 0ce0302 19/32: Merge remote-tracking branch 'origin/master', ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib 83834c6 20/32: Fix usage example in comment., ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib 6876d54 26/32: Fix `font-info` query format., ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib 2cab1a0 29/32: Merge remote-tracking branch 'origin/master', ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib f9e1bbb 32/32: Fix some warnings, ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib 04fdd1a 08/32: Added svg-lib-concat function for org-mode demo,
ELPA Syncer <=
- [elpa] externals/svg-lib d9a49ac 14/32: Delete the redundant url checking, ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib 6ceae83 16/32: Change `svg-lib-icons-dir` default value, ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib f775af4 21/32: Merge pull request #5 from 404cn/master, ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib 8427772 23/32: Merge remote-tracking branch 'origin/master', ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib 5c206f3 24/32: Remove hard coded image scaling factor, ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib f0b2136 25/32: Merge pull request #7 from HyunggyuJang/remove-hard-image-scale, ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib e0423a2 27/32: Merge pull request #8 from HyunggyuJang/fix-font-info-query-format, ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib 11bc5dc 28/32: Make stroke to be fully contained inside the svg, ELPA Syncer, 2021/09/27
- [elpa] externals/svg-lib 5cb5865 31/32: Bug fix, ELPA Syncer, 2021/09/27