From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: joakim@verona.se Newsgroups: gmane.emacs.devel Subject: Re: Drawing in images? Date: Wed, 16 Sep 2009 21:04:14 +0200 Message-ID: References: <87bpm028zk.fsf@stupidchicken.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1253127881 1936 80.91.229.12 (16 Sep 2009 19:04:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 16 Sep 2009 19:04:41 +0000 (UTC) Cc: MON KEY , emacs-devel@gnu.org To: Chong Yidong Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Sep 16 21:04:32 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 1Mnznr-00017S-Nq for ged-emacs-devel@m.gmane.org; Wed, 16 Sep 2009 21:04:32 +0200 Original-Received: from localhost ([127.0.0.1]:54580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mnznr-0006Z9-9w for ged-emacs-devel@m.gmane.org; Wed, 16 Sep 2009 15:04:31 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mnzno-0006Yx-2J for emacs-devel@gnu.org; Wed, 16 Sep 2009 15:04:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mnznj-0006Ya-BR for emacs-devel@gnu.org; Wed, 16 Sep 2009 15:04:27 -0400 Original-Received: from [199.232.76.173] (port=55033 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mnznj-0006YX-7v for emacs-devel@gnu.org; Wed, 16 Sep 2009 15:04:23 -0400 Original-Received: from proxy3.bredband.net ([195.54.101.73]:56033) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mnzni-0004bM-Ht for emacs-devel@gnu.org; Wed, 16 Sep 2009 15:04:22 -0400 Original-Received: from iph1.telenor.se (195.54.127.132) by proxy3.bredband.net (7.3.140.3) id 49F597CD038E1E86 for emacs-devel@gnu.org; Wed, 16 Sep 2009 21:04:19 +0200 X-SMTPAUTH-B2: joakvero X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgRjALvTsEpT44qWPGdsb2JhbACbFAEBAQE3xDyEFwWBWA X-IronPort-AV: E=Sophos;i="4.44,399,1249250400"; d="el'?scan'208";a="44436041" Original-Received: from ua-83-227-138-150.cust.bredbandsbolaget.se (HELO exodia) ([83.227.138.150]) by iph1.telenor.se with ESMTP; 16 Sep 2009 21:04:18 +0200 Original-Received: from localhost.localdomain (DIR-655.lan [192.168.200.113]) (authenticated bits=0) by exodia (8.14.3/8.14.3) with ESMTP id n8GJ4E4o027362 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 16 Sep 2009 21:04:15 +0200 In-Reply-To: <87bpm028zk.fsf@stupidchicken.com> (Chong Yidong's message of "Thu, 27 Aug 2009 18:21:51 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. 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:115396 Archived-At: --=-=-= Chong Yidong writes: > joakim@verona.se writes: > >> This should be possible by drawing a SVG image on top of another >> image. The SVG image is XML which can be generated in a buffer within >> Emacs. > > If I understand you, you're suggesting to generate an SVG image that > contains a bitmap (the underlying image), plus a rectangle (or whatever > else), correct? This approach has the great advantage that it can be > implemented entirely in Lisp. Anyone want to give it a shot? Here's an attempt. Its hardly industrial strength, but seems to work. Test with m-x dragbox-start, enter an image file name compatible with svg, I tried png. Then set the corner coords for the box with LMB and RMB. --=-=-= Content-Disposition: inline; filename=dragbox-test.el (setq dragbox-image-url "") (setq dragbox-image-width 744) (setq dragbox-image-height 1052) (setq dragbox-x1y1 '(0 . 0)) (setq dragbox-x2y2 '(100 . 100)) (defun dragbox-start (image-file) "start here" (interactive "fimage file:") (get-buffer-create "*dragbox*") (switch-to-buffer "*dragbox*") (setq dragbox-image-url (concat "file://" (expand-file-name image-file))) (dragbox-update-box-from-state)) (defun dragbox-make-svg-data (x y width height image-url) `((svg ((xmlns:dc . "http://purl.org/dc/elements/1.1/") (xmlns:cc . "http://creativecommons.org/ns#") (xmlns:rdf . "http://www.w3.org/1999/02/22-rdf-syntax-ns#") (xmlns:svg . "http://www.w3.org/2000/svg") (xmlns:xlink . "http://www.w3.org/1999/xlink") (xmlns . "http://www.w3.org/2000/svg") (width . ,(number-to-string dragbox-image-width)) (height . ,(number-to-string dragbox-image-height)) (id . "svg2")) (g ((id . "layer1")) (rect ((style . "fill:#cfcfcf;fill-opacity:1") (width . ,(number-to-string dragbox-image-width)) (height . ,(number-to-string dragbox-image-height)) (x . "0") (y . "0"))) (image ((y . "0") (x . "0") (width . ,(number-to-string dragbox-image-width)) (height . ,(number-to-string dragbox-image-height)) (xlink:href . ,image-url) )) (rect ((style . "color:#000000;fill:#000000;fill-opacity:0.5;fill-rule:nonzero;stroke:#000000;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;stroke-opacity:0.5") (id . "dragbox") (width . , (number-to-string width) ) (height . ,(number-to-string height)) (x . ,(number-to-string x)) (y . ,(number-to-string y)))) )))) (defun dragbox-lmb-click-handler () (interactive) (setq dragbox-x1y1 (dragbox-extract-event-coords last-input-event)) (dragbox-update-box-from-state) ) (defun dragbox-rmb-click-handler () (interactive) (setq dragbox-x2y2 (dragbox-extract-event-coords last-input-event)) (dragbox-update-box-from-state) ) (defun dragbox-extract-event-coords (event) (caddr(cadr last-input-event)) ) (define-key image-mode-map [down-mouse-1] 'dragbox-lmb-click-handler) (define-key image-mode-map [down-mouse-2] 'dragbox-rmb-click-handler) (defun dragbox-update-box (x y width height) (fundamental-mode) (erase-buffer) (xml-print (dragbox-make-svg-data x y width height dragbox-image-url)) (image-mode) ) (defun dragbox-update-box-from-state () (let* ((x1 (car dragbox-x1y1)) (y1 (cdr dragbox-x1y1)) (x2 (car dragbox-x2y2)) (y2 (cdr dragbox-x2y2)) (w (- x2 x1)) (h (- y2 y1))) (message "(%d %d) (%d %d) w:%d h:%d" x1 y1 x2 y2 w h) (dragbox-update-box x1 y1 w h))) --=-=-= -- Joakim Verona --=-=-=--