<?xml version="1.0" encoding="ISO-8859-1"?>
<configuration name="Image Demo"
  xmlns="http://www.xmlmind.com/xmleditor/schema/configuration"
  xmlns:cfg="http://www.xmlmind.com/xmleditor/schema/configuration"
  xmlns:imgd="http://www.xmlmind.com/xmleditor/schema/imagedemo"
  xmlns:svg="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink">

  <detect>
    <rootElementNamespace>http://www.xmlmind.com/xmleditor/schema/imagedemo</rootElementNamespace>
  </detect>

  <schema>
    <location>http://www.xmlmind.com/xmleditor/schema/imagedemo
              imagedemo.xsd</location>
  </schema>

  <css location="imagedemo.css" name="Image Demo" />

  <template location="template.xml" name="Template" />

  <saveOptions favorInteroperability="false" />

  <documentResources>
    <resource path="//imgd:image_au/@location" />
    <resource path="//imgd:image_eu" />
    <resource path="//svg:svg//@xlink:href" />
  </documentResources>

  <command name="imgd.editMenu">
    <macro>
      <choice>
        <sequence>
          <match context="$selectedElement" pattern="imgd:image_ab" />
          <command name="imgd.imageABMenu" />
        </sequence>
        <sequence>
          <match context="$selectedElement" pattern="imgd:image_eb" />
          <command name="imgd.imageEBMenu" />
        </sequence>
        <sequence>
          <match context="$selectedElement" pattern="svg:svg" />
          <command name="imgd.svgMenu" />
        </sequence>
        
        <command name="editMenu" />
      </choice>
    </macro>
  </command>

  <command name="imgd.imageABMenu">
    <menu>
      <item label="Save Embedded Image As..." 
	    command="extractObject" parameter="data" />

      <editMenu />
    </menu>
  </command>

  <command name="imgd.imageEBMenu">
    <menu>
      <item label="Save Embedded Image As..." 
	    command="extractObject" />

      <editMenu />
    </menu>
  </command>

  <command name="imgd.svgMenu">
    <menu>
      <item label="Save SVG Graphics As..." 
	    command="extractObject" />

      <editMenu />
    </menu>
  </command>

  <binding>
    <mousePressed button="3"/>
    <command name="imgd.editMenu" />
  </binding>

<!-- On Mac, uncomment this ==========
  <binding>
    <mousePressed button="1" modifiers="ctrl" />
    <command name="imgd.editMenu" />
  </binding>
-->

  <!-- A placeholder for embedded SVG graphics -->

  <elementTemplate name="simple" selectable="override">
    <svg:svg xmlns="" height="101" viewBox="0 0 101 101" width="101">
      <svg:text font-family="sans-serif" font-size="12pt" font-style="italic"
		font-weight="bold" stroke="gray" x="5" y="20">SVG</svg:text>
      <svg:rect stroke-width="1" stroke="gray" fill="none"
                x="0" y="0" width="100" height="100" rx="10" ry="10" />
    </svg:svg>
  </elementTemplate>

  <!-- =================================================================== -->

  <command name="imgd.toHTML">
    <process>
      <mkdir dir="resources" />
      <mkdir dir="raw" />
      <copyDocument to="__doc.xml">
	<extract xpath="//imgd:image_ab/@data|//imgd:image_eb" toDir="raw">
	  <processingInstruction target="extracted" 
                                 data="resources/{$url.rootName}.png" />
	</extract>
	<extract xpath="//imgd:*/svg:svg" toDir="raw">
	  <processingInstruction target="extracted" 
                                 data="resources/{$url.rootName}.png" />
	</extract>

	<!-- ..................................................................
	  If your Web browser supports SVG, comment out the above <extract>
          directive and replace it by the following <extract> directive.

	    <extract xpath="//imgd:*/svg:svg" toDir="resources">
	      <processingInstruction target="extracted"
				     data="resources/{$url.name}" />
	    </extract>
	.................................................................. -->

        <resources match="(https|http|ftp)://.*" />
        <resources match=".+\.(png|jpg|jpeg|gif)" 
                   copyTo="resources" />
        <resources match="(?:.+/)?(.+)\.(\w+)"
                   copyTo="raw" referenceAs="resources/$1.png" />
        <resources match=".+" 
                   copyTo="resources" />
      </copyDocument>

      <convertImage from="raw" to="resources" format="png" />

      <mkdir dir="xslt_graphics" />
      <copyProcessResources resources="xslt_graphics/*" to="xslt_graphics" />

      <transform stylesheet="html.xslt" 
                 file="__doc.xml" to="__doc.html"/>
 
      <upload base="%0">
        <copyFile file="__doc.html" to="%0" />
        <copyFiles files="resources/*" toDir="resources" />
        <copyFiles files="xslt_graphics/*" toDir="xslt_graphics" />
      </upload>
    </process>
  </command>

  <command name="imgd.convertToHTML">
    <macro>
      <sequence>
	<command name="selectConvertedFile"
                 parameter="saveFileURLWithExtension=html" />
	<command name="imgd.toHTML" parameter='"%_"' />
      </sequence>
    </macro>
  </command>

  <!-- =================================================================== -->

  <command name="imgd.toRTF">
    <process>
      <mkdir dir="resources" />
      <mkdir dir="raw" />
      <copyDocument to="__doc.xml">
	<extract xpath="//imgd:image_ab/@data|//imgd:image_eb" toDir="raw">
	  <processingInstruction target="extracted" 
                                 data="resources/{$url.rootName}.png" />
	</extract>
	<extract xpath="//imgd:*/svg:svg" toDir="raw">
	  <processingInstruction target="extracted" 
                                 data="resources/{$url.rootName}.png" />
	</extract>

        <resources match="(https|http|ftp)://.*" />
        <resources match=".+\.(png|jpg|jpeg|gif)" 
                   copyTo="resources" />
        <resources match="(?:.+/)?(.+)\.(\w+)"
                   copyTo="raw" referenceAs="resources/$1.png" />
        <resources match=".+"
                   copyTo="resources" />
      </copyDocument>

      <convertImage from="raw" to="resources" format="png" />

      <mkdir dir="xslt_graphics" />
      <copyProcessResources resources="xslt_graphics/*" to="xslt_graphics" />

      <transform stylesheet="fo.xslt" 
                 file="__doc.xml" to="__doc.fo" />

      <processFO processor="XFC" file="__doc.fo" to="__doc.%0">
        <parameter name="outputFormat">%0</parameter>
        <parameter name="outputEncoding">%1</parameter>
        <parameter name="imageResolution">96</parameter>
        <parameter name="prescaleImages">true</parameter>
      </processFO>

      <upload base="%2">
        <copyFile file="__doc.%0" to="%2" />
      </upload>
    </process>
  </command>

  <command name="imgd.convertToRTF">
    <macro>
      <sequence>
	<command name="selectConvertedFile"
                 parameter="saveFileURLWithExtension=%2" />
	<command name="imgd.toRTF" parameter='"%0" "%1" "%_"' />
      </sequence>
    </macro>
  </command>

  <!-- =================================================================== -->

  <command name="imgd.toPS">
    <process>
      <mkdir dir="resources" />
      <mkdir dir="raw" />
      <copyDocument to="__doc.xml">
	<extract xpath="//imgd:image_ab/@data|//imgd:image_eb" toDir="raw">
	  <processingInstruction target="extracted" 
                                 data="resources/{$url.rootName}.png" />
	</extract>

        <resources match="(https|http|ftp)://.*" />

        <!-- referenceAs=absolute_URL is used as a workaround for 
             FOP ``really strange'' image managment. 
	     (This is harmless for XEP.) -->

        <resources match="(?:.+/)?(.+)\.(png|jpg|jpeg|gif|svg|svgz%1)" 
                   copyTo="resources" referenceAs="%w/resources/$1.$2" />
        <resources match="(?:.+/)?(.+)\.(\w+)"
                   copyTo="raw" referenceAs="%w/resources/$1.png" />
        <resources match="(?:.+/)?(.+)" 
	           copyTo="resources" referenceAs="%w/resources/$1" />
      </copyDocument>

      <convertImage from="raw" to="resources" format="png" />

      <mkdir dir="xslt_graphics" />
      <copyProcessResources resources="xslt_graphics/*" to="xslt_graphics" />

      <transform stylesheet="fo.xslt" 
                 file="__doc.xml" to="__doc.fo" />

      <processFO processor="XEP" file="__doc.fo" to="__doc.%0">
        <parameter name="OUTPUT_FORMAT">%0</parameter>
        <parameter name="PS.LANGUAGE_LEVEL">2</parameter>

	<!-- If XEP plug-in has not been installed, try FOP plug-in. -->
	<processFO processor="FOP" file="__doc.fo" to="__doc.%0">
	  <parameter name="renderer">%0</parameter>
	</processFO>
      </processFO>
    </process>
  </command>

  <command name="imgd.toPSFile">
    <process>
      <subProcess name="imgd.toPS" parameter='"%0" "%1"' />

      <upload base="%2">
        <copyFile file="__doc.%0" to="%2" />
      </upload>
    </process>
  </command>

  <command name="imgd.convertToPS">
    <macro>
      <sequence>
	<command name="selectConvertedFile"
                 parameter="saveFileURLWithExtension=%0" />
	<command name="imgd.toPSFile" parameter='"%0" "%1" "%_"' />
      </sequence>
    </macro>
  </command>

  <!-- =================================================================== -->

  <command name="imgd.toPSPrinter">
    <process>
      <subProcess name="imgd.toPS" parameter='"%0" "%1"' />

      <print file="__doc.%0" printer="%2" />
    </process>
  </command>

  <command name="imgd.printPS">
    <macro>
      <sequence>
	<command name="selectPrinter" parameter="%0" />
	<command name="imgd.toPSPrinter" parameter='"%0" "%1" "%_"' />
      </sequence>
    </macro>
  </command>

  <!-- =================================================================== -->

  <menu label="Image_Demo">
    <item label="Convert to _HTML..."
	  command="imgd.convertToHTML" />
    <item label="Convert to _RTF..."
	  command="imgd.convertToRTF" parameter='rtf Cp1252 rtf' />
    <item label="Convert to _WordprocessingML (MS-Word 2003)..."
	  command="imgd.convertToRTF" parameter='wml UTF-8 wml' />
    <item label="Convert to _OpenDocument (OpenOffice.org 2)..."
	  command="imgd.convertToRTF" parameter='odt UTF-8 odt' />
    <item label="Print Post_Script..."
	  command="imgd.printPS" parameter='ps |eps|ps' />
    <item label="Convert to _PDF..."
	  command="imgd.convertToPS" parameter='pdf |pdf' />
  </menu>

</configuration>
