[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] elpa-admin 38b62c5795: * elpa-admin.el (elpaa--string-width): Han
From: |
Stephen Leake |
Subject: |
[elpa] elpa-admin 38b62c5795: * elpa-admin.el (elpaa--string-width): Handle ImageMagick >=7.1.0 |
Date: |
Fri, 4 Nov 2022 12:41:12 -0400 (EDT) |
branch: elpa-admin
commit 38b62c5795cbd807bcad37fd22fb1d1acd79c554
Author: Stephen Leake <stephen_leake@stephe-leake.org>
Commit: Stephen Leake <stephen_leake@stephe-leake.org>
* elpa-admin.el (elpaa--string-width): Handle ImageMagick >=7.1.0
---
elpa-admin.el | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/elpa-admin.el b/elpa-admin.el
index 496b6c8ba0..f4f8809b1d 100644
--- a/elpa-admin.el
+++ b/elpa-admin.el
@@ -884,22 +884,25 @@ SPECS is the list of package specifications."
(defun elpaa--string-width (str)
"Determine string width in pixels of STR."
(with-temp-buffer
- ;; Current (2021) ImageMagick recommends using the "magick"
- ;; driver, rather than "convert" directly, but Debian doesn't
- ;; provide it yet.
- (elpaa--call (current-buffer)
- "convert" "-debug" "annotate" "xc:" "-font" "DejaVu-Sans"
- "-pointsize" "110" "-annotate" "0" str "null:")
- (goto-char (point-min))
- (if (not (re-search-forward "Metrics:.*?width: \\([0-9]+\\)"))
- (error "Could not determine string width")
- (let ((width (string-to-number (match-string 1))))
- ;; This test aims to catch the case where the font is missing,
- ;; but it seems it only works in some cases :-(
- (if (and (> (string-width str) 0) (not (> width 0)))
- (progn (message "convert:\n%s" (buffer-string))
- (error "Could not determine string width"))
- width)))))
+ ;; ImageMagick 7.1.0 or later requires using the "magick" driver,
+ ;; rather than "convert" directly, but Debian doesn't provide it
+ ;; yet (2021).
+ (let ((args
+ (append (list (current-buffer))
+ (if (executable-find "magick") '("magick" "convert")
'("convert"))
+ (list "-debug" "annotate" "xc:" "-font" "DejaVu-Sans"
+ "-pointsize" "110" "-annotate" "0" str "null:"))))
+ (apply #'elpaa--call args)
+ (goto-char (point-min))
+ (if (not (re-search-forward "Metrics:.*?width: \\([0-9]+\\)"))
+ (error "Could not determine string width")
+ (let ((width (string-to-number (match-string 1))))
+ ;; This test aims to catch the case where the font is missing,
+ ;; but it seems it only works in some cases :-(
+ (if (and (> (string-width str) 0) (not (> width 0)))
+ (progn (message "convert:\n%s" (buffer-string))
+ (error "Could not determine string width"))
+ width))))))
(defun elpaa--make-badge (file left right)
"Make badge svg FILE with LEFT and RIGHT string."
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] elpa-admin 38b62c5795: * elpa-admin.el (elpaa--string-width): Handle ImageMagick >=7.1.0,
Stephen Leake <=