<?xml version="1.0"?>
<!-- This file is part of the DITA Open Toolkit project hosted on 
  Sourceforge.net. See the accompanying license.txt file for 
  applicable licenses.-->
<!-- (c) Copyright IBM Corp. 2011 All Rights Reserved. -->
<project name="org.dita.pdf2.fop">

  <property name="fop.home" value="${dita.plugin.org.dita.pdf2.dir}/fop"/>

  <!--Added by William on 2009-11-23 for bug:2893745 start -->
  <condition property="hasFopLib">
    <available classname="org.apache.fop.tools.anttasks.Fop">
      <classpath id="project.classpath">
        <fileset dir="${fop.home}">
          <include name="build/fop.jar"/>
          <include name="lib/*.jar"/>
          <include name="build/fop-hyph.jar"/>
        </fileset>
      </classpath>
    </available>
  </condition>
  <!--Added by William on 2009-11-23 for bug:2893745 end -->

  <!--Added by William on 2009-11-23 for bug:2893745 start -->
  <target name="checkFOPLib">
    <dita-ot-fail id="DOTA010E">
      <condition>
        <and>
          <not><isset property="hasFopLib"/></not>
        </and>
      </condition>
    </dita-ot-fail>
  </target>
  <!--Added by William on 2009-11-23 for bug:2893745 end -->

  <target name="transform.fo2pdf.fop.test-use">
    <condition property="use.fop.pdf.formatter">
      <equals arg1="${pdf.formatter}" arg2="fop"/>
    </condition>
  </target>

  <target name="transform.fo2pdf.fop.init" if="use.fop.pdf.formatter">
    <condition property="use.fop.pdf.formatter">
      <equals arg1="${pdf.formatter}" arg2="fop"/>
    </condition>
    
    <!-- default output format -->
    <condition property="fop.formatter.output-format" value="application/pdf">
      <not><isset property="fop.formatter.output-format"/></not>
    </condition>
    <!-- output file extension -->
    <condition property="xsl.formatter.ext" value=".mif">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="application/mif"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".pcl">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="application/x-pcl"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".pcl">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="application/vnd.hp-PCL"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".png">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="image/png"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".ps">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="application/postscript"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".mda">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="application/x-afp"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".mda">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="application/vnd.ibm.modcap"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".svg">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="image/svg+xml"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".rtf">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="text/richtext"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".rtf">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="text/rtf"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".rtf">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="application/rtf"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".tif">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="image/tiff "/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".gif">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="image/gif"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".txt">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="text/plain"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".AT.xml">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="application/X-fop-areatree"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".pdf">
      <and>
        <equals arg1="${fop.formatter.output-format}" arg2="application/pdf"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
  </target>

  <!--Run FOP-->
  <target name="transform.fo2pdf.fop" depends="transform.fo2pdf.fop.test-use, transform.fo2pdf.fop.init" if="use.fop.pdf.formatter">
    <!--Check fop lib-->
    <antcall target="checkFOPLib"/>
    <taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop">
      <classpath>
        <fileset dir="${fop.home}/lib">
          <include name="*.jar"/>
        </fileset>
        <fileset dir="${fop.home}/build">
          <include name="fop.jar"/>
          <include name="fop-hyph.jar"/>
        </fileset>
      </classpath>
    </taskdef>
    
    <condition property="outputFile" value="${dita.map.output.dir}/${outputFile.base}${xsl.formatter.ext}">
      <not><isset property="outputFile"/></not>
    </condition>
    
    <fop format="${fop.formatter.output-format}" fofile="${dita.map.output.dir}/topic.fo" basedir="${dita.map.output.dir}"
         outfile="${outputFile}" messagelevel="info" relativebase="true" force="true"
         userconfig="${fop.home}/conf/fop.xconf"/>
  </target>

</project>
