Hi!

On Thu, Sep 15, 2011 at 06:58:47PM +1000, Lex Trotman wrote:
> > Is asciidoc's graphviz filter support imagemap feature of graphviz?
> >    http://www.graphviz.org/doc/info/output.html#d:imap
> No.
> 
> You could maybe extend the graphviz filter to generate the map
> contents and include them.

Yeah, I did that, and it works for me (patch attached).
Tested in Opera and Firefox in Linux, both with and without data-uri.

Probably this can be done with less copy&paste, without tying it to
xhtml11's variant of imageblock, but I didn't know asciidoc conf files
good enough for this. :(


P.S. I probably hit the bug. In this snippet:
    {set2:quot:\"}
    {sys:sed "s/<map[^>]*>/<map id={quot}cmapx-{cmapx-id}{quot} …
I had to define {quot} and use it instead of \" because while this works:
    {sys:sed "s/<map[^>]*>/<map id=\"cmapx-{cmapx-id} …
this one doesn't work:
    {sys:sed "s/<map[^>]*>/<map id=\"cmapx-{cmapx-id}\" …
because it looks like this:
    {attribute}\
somehow processed similar to escaping attribute, like this:
    \{attribute}

-- 
                        WBR, Alex.

-- 
You received this message because you are subscribed to the Google Groups 
"asciidoc" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/asciidoc?hl=en.

diff -uNr /usr/share/asciidoc/filters/graphviz/graphviz2png.py ./graphviz2png.py
--- /usr/share/asciidoc/filters/graphviz/graphviz2png.py	2011-09-17 02:25:31.000000000 +0300
+++ ./graphviz2png.py	2011-09-17 21:02:11.000000000 +0300
@@ -129,8 +129,8 @@
         saved_cwd = os.getcwd()
         os.chdir(outdir)
         try:
-            cmd = '%s -T%s "%s" > "%s"' % (
-                  self.options.layout, self.options.format, infile, outfile)
+            cmd = '%s -Tcmapx -o"%s".map -T%s -o"%s" "%s"' % (
+                  self.options.layout, outfile, self.options.format, outfile, infile)
             self.systemcmd(cmd)
         finally:
             os.chdir(saved_cwd)
diff -uNr /usr/share/asciidoc/filters/graphviz/graphviz-filter.conf ./graphviz-filter.conf
--- /usr/share/asciidoc/filters/graphviz/graphviz-filter.conf	2011-09-17 02:25:31.000000000 +0300
+++ ./graphviz-filter.conf	2011-09-17 22:29:30.000000000 +0300
@@ -14,7 +14,29 @@
 template::[graphviz-filter-style]
 
 [graphviz-block]
-template::[filter-image-blockmacro]
+# Synthesize missing target attribute for filter generated file names.
+# The tag split | ensures missing target file names are auto-generated
+# before the filter is executed, the remainder (the [image-blockmacro])
+# is excuted after the filter to ensure data URI encoding comes after
+# the image is created.
+{target%}{counter2:target-number}
+{target%}{set2:target:{docname}__{target-number}.png}
+{set2:cmapx-id:1}
+{set2:quot:\"}
+|
+<div class="imageblock{style? {style}}{role? {role}}"{id? id="{id}"}{align? style="text-align:{align};"}{float? style="float:{float};"}>
+<div class="content">
+<a class="image" href="{link}">
+{data-uri%}<img usemap="#cmapx-{counter:cmapx-id}" src="{imagesdir=}{imagesdir?/}{target}" alt="{alt={target}}"{width? width="{width}"}{height? height="{height}"} />
+{data-uri#}<img usemap="#cmapx-{counter:cmapx-id}" alt="{alt={target}}"{width? width="{width}"}{height? height="{height}"} src="data:image/{eval:os.path.splitext(r'{target}')[1][1:]};base64,
+{data-uri#}{sys:python -uc "import base64,sys; base64.encode(sys.stdin,sys.stdout)" < "{eval:os.path.join(r"{indir={outdir}}",r"{imagesdir=}",r"{target}")}" />
+{sys:sed "s/<map[^>]*>/<map id={quot}cmapx-{cmapx-id}{quot} name={quot}cmapx-{cmapx-id}{quot}>/;s/\\\\[nlr]/  /g" "{eval:os.path.join(r"{indir={outdir}}",r"{imagesdir=}",r"{target}")}.map"}
+{sys:rm "{eval:os.path.join(r"{indir={outdir}}",r"{imagesdir=}",r"{target}")}.map"}
+{link#}</a>
+</div>
+<div class="title">{caption={figure-caption} {counter:figure-number}. }{title}</div>
+</div>
+
 
 # EXPERIMENTAL: xhtml11 backend SVG image block.
 ifdef::basebackend-xhtml11[]

Reply via email to