unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
To: joakim@verona.se
Cc: Emacs Development <emacs-devel@gnu.org>
Subject: Re: Drawing in images?
Date: Fri, 28 Aug 2009 09:49:58 +0900	[thread overview]
Message-ID: <wlr5uw92yx.wl%mituharu@math.s.chiba-u.ac.jp> (raw)
In-Reply-To: <m3skfffqnm.fsf@verona.se>

>>>>> On Wed, 26 Aug 2009 00:57:17 +0200, joakim@verona.se said:

> I would like to draw a bounding box inside an image displayed in
> emacs.  Do I:

>  a) use clever already existing way, unknown to me

Maybe existing image slicing and box drawing with face can be used for
some simple cases.

(defface inner-box '((t :box (:line-width -1))) "Simple box")

(defun insert-image-with-box (image x y w h)
  (let* ((image-size (image-size image t))
	 (image-width (car image-size))
	 (image-height (cdr image-size)))
    (if (or (<= w 0) (<= h 0) (< x 0) (< y 0)
	    (> (+ x w) image-width) (> (+ y h) image-height))
	(error "Box empty or not contained in the image")
      (when (> y 0)
	(insert-image image nil nil (list 0 0 image-width y))
	(insert (propertize "\n" 'line-height t)))
      (when (> x 0)
	(insert-image image nil nil (list 0 y x h)))
      (insert (propertize " " 'display `((slice ,x ,y ,w ,h) ,image)
			  'face 'inner-box))
      (when (< (+ x w) image-width)
	(insert-image image nil nil (list (+ x w) y (- image-width x w) h)))
      (insert (propertize "\n" 'line-height t))
      (when (< (+ y h) image-height)
	(insert-image image nil nil (list 0 (+ y h)
					  image-width (- image-height y h)))
	(insert (propertize "\n" 'line-height t))))))

;; Turn off font-lock-mode before you try this in *scratch*.
(insert-image-with-box (create-image "splash.png") 50 30 100 150)

				     YAMAMOTO Mitsuharu
				mituharu@math.s.chiba-u.ac.jp




  parent reply	other threads:[~2009-08-28  0:49 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-25 22:57 Drawing in images? joakim
2009-08-26  1:07 ` Stefan Monnier
2009-08-26  5:58   ` joakim
2009-08-26 14:45     ` Stefan Monnier
2009-08-26  9:05   ` Jason Rumney
2009-08-28  0:49 ` YAMAMOTO Mitsuharu [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-08-27  0:52 MON KEY
2009-08-27  6:31 ` joakim
2009-08-27 18:07   ` MON KEY
2009-08-27 19:05     ` joakim
2009-08-28 16:22       ` MON KEY
2009-08-27 22:21   ` Chong Yidong
2009-08-27 23:51     ` joakim
2009-09-16 19:04     ` joakim
2009-09-17 19:13       ` MON KEY
2009-09-17 21:04         ` Lennart Borgman
2009-09-17 21:08           ` Lennart Borgman
2009-09-17 23:00           ` Jason Rumney
2009-09-17 23:09             ` Lennart Borgman
2009-09-17 21:46         ` joakim
2009-09-17 22:09           ` Lennart Borgman
2009-09-17 22:46             ` Juanma Barranquero
2009-09-17 22:56               ` Lennart Borgman
2009-09-17 22:56         ` Jason Rumney
2009-09-17 22:59           ` Lennart Borgman
2009-09-29  0:31 MON KEY
2009-09-29  5:29 ` martin rudalics
2009-09-29 20:25   ` MON KEY

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=wlr5uw92yx.wl%mituharu@math.s.chiba-u.ac.jp \
    --to=mituharu@math.s.chiba-u.ac.jp \
    --cc=emacs-devel@gnu.org \
    --cc=joakim@verona.se \
    /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).