]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetGraphics.cpp
Does not compile on older gcc.
[lyx.git] / src / insets / InsetGraphics.cpp
index 0daae4c9214b29d947f1d17f35af46e28f58e7d4..62efa84dc02978e1be91fcb6873c47ca05526bad 100644 (file)
@@ -67,6 +67,7 @@ TODO
 #include "MetricsInfo.h"
 #include "Mover.h"
 #include "OutputParams.h"
+#include "output_docbook.h"
 #include "output_xhtml.h"
 #include "xml.h"
 #include "texstream.h"
@@ -95,7 +96,6 @@ TODO
 
 #include <algorithm>
 #include <sstream>
-#include <tuple>
 
 using namespace std;
 using namespace lyx::support;
@@ -125,8 +125,9 @@ string findTargetFormat(string const & format, OutputParams const & runparams)
                // Convert everything else to png
                return "png";
        }
-       // for HTML, we leave the known formats and otherwise convert to png
-       if (runparams.flavor == OutputParams::HTML) {
+
+    // for HTML and DocBook, we leave the known formats and otherwise convert to png
+    if (runparams.flavor == OutputParams::HTML || runparams.flavor == OutputParams::DOCBOOK5) {
                Format const * const f = theFormats().getFormat(format);
                // Convert vector graphics to svg
                if (f && f->vectorFormat() && theConverters().isReachable(format, "svg"))
@@ -522,7 +523,6 @@ docstring InsetGraphics::createDocBookAttributes() const
                }
        }
 
-
        if (!params().special.empty())
                options << from_ascii(params().special) << " ";
 
@@ -575,7 +575,7 @@ copyToDirIfNeeded(DocFileName const & file, string const & dir)
        if (rtrim(only_path, "/") == rtrim(dir, "/"))
                return make_pair(IDENTICAL_PATHS, FileName(file_in));
 
-       string mangled = file.mangledFileName();
+       string mangled = file.mangledFileName(empty_string(), false, true);
        if (theFormats().isZippedFile(file)) {
                // We need to change _eps.gz to .eps.gz. The mangled name is
                // still unique because of the counter in mangledFileName().
@@ -935,62 +935,24 @@ int InsetGraphics::plaintext(odocstringstream & os,
 }
 
 
-static int writeImageObject(char const * format, odocstream & os,
-       OutputParams const & runparams, docstring const & graphic_label,
-       docstring const & attributes)
-{
-       if (runparams.flavor != OutputParams::DOCBOOK5)
-               os << "<![ %output.print." << format
-                  << "; [" << endl;
-
-       os <<"<imageobject><imagedata fileref=\"&"
-          << graphic_label
-          << ";."
-          << format
-          << "\" "
-          << attributes;
-
-       if (runparams.flavor == OutputParams::DOCBOOK5)
-               os <<  " role=\"" << format << "\"/>" ;
-       else
-               os << " format=\"" << format << "\">" ;
-
-       os << "</imageobject>";
-
-       if (runparams.flavor != OutputParams::DOCBOOK5)
-               os << endl << "]]>" ;
-
-       return runparams.flavor == OutputParams::DOCBOOK5 ? 0 : 2;
-}
-
-
 // For explanation on inserting graphics into DocBook checkout:
 // http://en.tldp.org/LDP/LDP-Author-Guide/html/inserting-pictures.html
 // See also the docbook guide at http://www.docbook.org/
-int InsetGraphics::docbook(odocstream & os,
-                          OutputParams const & runparams) const
+void InsetGraphics::docbook(XMLStream & xs, OutputParams const & runparams) const
 {
-       // In DocBook v5.0, the graphic tag will be eliminated from DocBook, will
-       // need to switch to MediaObject. However, for now this is sufficient and
-       // easier to use.
-       if (runparams.flavor == OutputParams::DOCBOOK5)
-               runparams.exportdata->addExternalFile("docbook-xml",
-                                                     params().filename);
-       else
-               runparams.exportdata->addExternalFile("docbook",
-                                                     params().filename);
-
-       os << "<inlinemediaobject>";
-
-       int r = 0;
-       docstring attributes = createDocBookAttributes();
-       r += writeImageObject("png", os, runparams, graphic_label, attributes);
-       r += writeImageObject("pdf", os, runparams, graphic_label, attributes);
-       r += writeImageObject("eps", os, runparams, graphic_label, attributes);
-       r += writeImageObject("bmp", os, runparams, graphic_label, attributes);
-
-       os << "</inlinemediaobject>";
-       return r;
+       string fn = params().filename.relFileName(runparams.export_folder);
+       string tag = runparams.docbook_in_float ? "mediaobject" : "inlinemediaobject";
+
+       xs << xml::StartTag(tag);
+       xs << xml::CR();
+       xs << xml::StartTag("imageobject");
+       xs << xml::CR();
+       xs << xml::CompTag("imagedata", "fileref=\"" + fn + "\" " + to_utf8(createDocBookAttributes()));
+       xs << xml::CR();
+       xs << xml::EndTag("imageobject");
+       xs << xml::CR();
+       xs << xml::EndTag(tag);
+       xs << xml::CR();
 }