unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: joakim@verona.se
To: Chong Yidong <cyd@stupidchicken.com>
Cc: MON KEY <monkey@sandpframing.com>, emacs-devel@gnu.org
Subject: Re: Drawing in images?
Date: Wed, 16 Sep 2009 21:04:14 +0200	[thread overview]
Message-ID: <m3iqfiemoh.fsf@verona.se> (raw)
In-Reply-To: <87bpm028zk.fsf@stupidchicken.com> (Chong Yidong's message of "Thu, 27 Aug 2009 18:21:51 -0400")

[-- Attachment #1: Type: text/plain, Size: 729 bytes --]

Chong Yidong <cyd@stupidchicken.com> 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.




[-- Attachment #2: dragbox-test.el --]
[-- Type: text/plain, Size: 3164 bytes --]



(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)))

                      


[-- Attachment #3: Type: text/plain, Size: 20 bytes --]



-- 
Joakim Verona

  parent reply	other threads:[~2009-09-16 19:04 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-27  0:52 Drawing in images? 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 [this message]
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
  -- strict thread matches above, loose matches on Subject: below --
2009-09-29  0:31 MON KEY
2009-09-29  5:29 ` martin rudalics
2009-09-29 20:25   ` MON KEY
2009-08-25 22:57 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

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=m3iqfiemoh.fsf@verona.se \
    --to=joakim@verona.se \
    --cc=cyd@stupidchicken.com \
    --cc=emacs-devel@gnu.org \
    --cc=monkey@sandpframing.com \
    /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).