compface.el 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ;;; compface.el --- functions for converting X-Face headers
  2. ;; Copyright (C) 2002-2012 Free Software Foundation, Inc.
  3. ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
  4. ;; Keywords: news
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;; Code:
  18. ;;;###
  19. (defun uncompface (face)
  20. "Convert FACE to pbm.
  21. Requires the external programs `uncompface', and `icontopbm'. On a
  22. GNU/Linux system these might be in packages with names like `compface'
  23. or `faces-xface' and `netpbm' or `libgr-progs', for instance."
  24. (with-temp-buffer
  25. (unless (featurep 'xemacs) (set-buffer-multibyte nil))
  26. (insert face)
  27. (let ((coding-system-for-read 'raw-text)
  28. ;; At least "icontopbm" doesn't work with Windows because
  29. ;; the line-break code is converted into CRLF by default.
  30. (coding-system-for-write 'binary))
  31. (and (eq 0 (apply 'call-process-region (point-min) (point-max)
  32. "uncompface"
  33. 'delete '(t nil) nil))
  34. (progn
  35. (goto-char (point-min))
  36. (insert "/* Format_version=1, Width=48, Height=48, Depth=1,\
  37. Valid_bits_per_item=16 */\n")
  38. ;; I just can't get "icontopbm" to work correctly on its
  39. ;; own in XEmacs. And Emacs doesn't understand un-raw pbm
  40. ;; files.
  41. (if (not (featurep 'xemacs))
  42. (eq 0 (call-process-region (point-min) (point-max)
  43. "icontopbm"
  44. 'delete '(t nil)))
  45. (shell-command-on-region (point-min) (point-max)
  46. "icontopbm | pnmnoraw"
  47. (current-buffer) t)
  48. t))
  49. (buffer-string)))))
  50. (provide 'compface)
  51. ;;; compface.el ends here