From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: YAMAMOTO Mitsuharu Newsgroups: gmane.emacs.devel Subject: Re: Drawing in images? Date: Fri, 28 Aug 2009 09:49:58 +0900 Organization: Faculty of Science, Chiba University Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Trace: ger.gmane.org 1251420661 13848 80.91.229.12 (28 Aug 2009 00:51:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 28 Aug 2009 00:51:01 +0000 (UTC) Cc: Emacs Development To: joakim@verona.se Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 28 02:50:53 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Mgpg4-0007om-Lz for ged-emacs-devel@m.gmane.org; Fri, 28 Aug 2009 02:50:52 +0200 Original-Received: from localhost ([127.0.0.1]:42368 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mgpg3-0005Km-Mi for ged-emacs-devel@m.gmane.org; Thu, 27 Aug 2009 20:50:51 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MgpfS-0004yo-F8 for emacs-devel@gnu.org; Thu, 27 Aug 2009 20:50:14 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MgpfN-0004wp-Dp for emacs-devel@gnu.org; Thu, 27 Aug 2009 20:50:13 -0400 Original-Received: from [199.232.76.173] (port=53619 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MgpfN-0004wl-5L for emacs-devel@gnu.org; Thu, 27 Aug 2009 20:50:09 -0400 Original-Received: from mx20.gnu.org ([199.232.41.8]:12520) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MgpfM-0004sB-53 for emacs-devel@gnu.org; Thu, 27 Aug 2009 20:50:08 -0400 Original-Received: from ntp.math.s.chiba-u.ac.jp ([133.82.132.2] helo=mathmail.math.s.chiba-u.ac.jp) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MgpfI-0002m1-Rx for emacs-devel@gnu.org; Thu, 27 Aug 2009 20:50:05 -0400 Original-Received: from church.math.s.chiba-u.ac.jp (church [133.82.132.36]) by mathmail.math.s.chiba-u.ac.jp (Postfix) with ESMTP id 1BBB9C0546; Fri, 28 Aug 2009 09:49:58 +0900 (JST) In-Reply-To: User-Agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (=?ISO-8859-4?Q?Shij=F2?=) APEL/10.6 Emacs/22.3 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI) X-Detected-Operating-System: by mx20.gnu.org: NetBSD 3.0 (DF) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:114711 Archived-At: >>>>> 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