#include "Converter.h"
#include "Cursor.h"
#include "DispatchResult.h"
+#include "Encoding.h"
#include "ErrorList.h"
#include "Exporter.h"
#include "Format.h"
#include "MetricsInfo.h"
#include "Mover.h"
#include "OutputParams.h"
+#include "output_docbook.h"
#include "output_xhtml.h"
-#include "sgml.h"
+#include "xml.h"
#include "texstream.h"
#include "TocBackend.h"
#include <algorithm>
#include <sstream>
-#include <tuple>
using namespace std;
using namespace lyx::support;
namespace {
/// Find the most suitable image format for images in \p format
-/// Note that \p format may be unknown (i. e. an empty string)
+/// Note that \p format may be unknown (i.e. an empty string)
string findTargetFormat(string const & format, OutputParams const & runparams)
{
// Are we latexing to DVI or PDF?
// 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"))
InsetGraphics::InsetGraphics(Buffer * buf)
- : Inset(buf), graphic_label(sgml::uniqueID(from_ascii("graph"))),
+ : Inset(buf), graphic_label(xml::uniqueID(from_ascii("graph"))),
graphic_(new RenderGraphic(this))
{
}
InsetGraphics::InsetGraphics(InsetGraphics const & ig)
: Inset(ig),
- graphic_label(sgml::uniqueID(from_ascii("graph"))),
+ graphic_label(xml::uniqueID(from_ascii("graph"))),
graphic_(new RenderGraphic(*ig.graphic_, this))
{
setParams(ig.params());
if (!params().width.zero())
size << "width=" << params().width.asLatexString() << ',';
if (!params().height.zero())
- size << "height=" << params().height.asLatexString() << ',';
+ size << "totalheight=" << params().height.asLatexString() << ',';
if (params().keepAspectRatio)
size << "keepaspectratio,";
}
// Calculate the options part of the command, we must do it to a string
// stream since we copied the code from createLatexParams() ;-)
- // FIXME: av: need to translate spec -> Docbook XSL spec
- // (http://www.sagehill.net/docbookxsl/ImageSizing.html)
- // Right now it only works with my version of db2latex :-)
-
odocstringstream options;
double const scl = convert<double>(params().scale);
if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
}
}
-
if (!params().special.empty())
options << from_ascii(params().special) << " ";
{
// No conversion is needed. LaTeX can handle the graphic file as is.
// This is true even if the orig_file is compressed.
- string const to_format = theFormats().getFormat(to)->extension();
+ Format const * f = theFormats().getFormat(to);
+ if (!f)
+ return latex_path(file, EXCLUDE_EXTENSION);
+ string const to_format = f->extension();
string const file_format = getExtension(file);
// for latex .ps == .eps
if (to_format == file_format ||
string before;
string after;
- if (runparams.moving_arg)
- before += "\\protect";
-
- // We never use the starred form, we use the "clip" option instead.
- before += "\\includegraphics";
-
// Write the options if there are any.
bool const ps = runparams.flavor == OutputParams::LATEX
|| runparams.flavor == OutputParams::DVILUATEX;
string const opts = createLatexOptions(ps);
LYXERR(Debug::GRAPHICS, "\tOpts = " << opts);
+ if (contains(opts, '=') && contains(runparams.active_chars, '=')) {
+ // We have a language that makes = active. Deactivate locally
+ // for keyval option parsing (#2005).
+ before = "\\begingroup\\catcode`\\=12";
+ after = "\\endgroup ";
+ }
+
+ if (runparams.moving_arg)
+ before += "\\protect";
+
+ // We never use the starred form, we use the "clip" option instead.
+ before += "\\includegraphics";
+
if (!opts.empty() && !message.empty())
before += ('[' + opts + ',' + message + ']');
else if (!opts.empty() || !message.empty())
// Convert the file if necessary.
// Remove the extension so LaTeX will use whatever is appropriate
// (when there are several versions in different formats)
- string file_path = prepareFile(runparams);
- latex_str += file_path;
+ docstring file_path = from_utf8(prepareFile(runparams));
+ // we can only output characters covered by the current
+ // encoding!
+ docstring uncodable;
+ docstring encodable_file_path;
+ for (size_type i = 0 ; i < file_path.size() ; ++i) {
+ char_type c = file_path[i];
+ try {
+ if (runparams.encoding->encodable(c))
+ encodable_file_path += c;
+ else if (runparams.dryrun) {
+ encodable_file_path += "<" + _("LyX Warning: ")
+ + _("uncodable character") + " '";
+ encodable_file_path += docstring(1, c);
+ encodable_file_path += "'>";
+ } else
+ uncodable += c;
+ } catch (EncodingException & /* e */) {
+ if (runparams.dryrun) {
+ encodable_file_path += "<" + _("LyX Warning: ")
+ + _("uncodable character") + " '";
+ encodable_file_path += docstring(1, c);
+ encodable_file_path += "'>";
+ } else
+ uncodable += c;
+ }
+ }
+ if (!uncodable.empty() && !runparams.silent) {
+ // issue a warning about omitted characters
+ // FIXME: should be passed to the error dialog
+ frontend::Alert::warning(_("Uncodable character in file path"),
+ bformat(_("The following characters in one of the graphic paths are\n"
+ "not representable in the current encoding and have been omitted: %1$s.\n"
+ "You need to adapt either the encoding or the path."),
+ uncodable));
+ }
+ latex_str += to_utf8(encodable_file_path);
latex_str += '}' + after;
// FIXME UNICODE
os << from_utf8(latex_str);
}
-static int writeImageObject(char const * format, odocstream & os,
- OutputParams const & runparams, docstring const & graphic_label,
- docstring const & attributes)
-{
- if (runparams.flavor != OutputParams::XML)
- os << "<![ %output.print." << format
- << "; [" << endl;
-
- os <<"<imageobject><imagedata fileref=\"&"
- << graphic_label
- << ";."
- << format
- << "\" "
- << attributes;
-
- if (runparams.flavor == OutputParams::XML)
- os << " role=\"" << format << "\"/>" ;
- else
- os << " format=\"" << format << "\">" ;
-
- os << "</imageobject>";
-
- if (runparams.flavor != OutputParams::XML)
- os << endl << "]]>" ;
-
- return runparams.flavor == OutputParams::XML ? 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::XML)
- 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();
}
}
-docstring InsetGraphics::xhtml(XHTMLStream & xs, OutputParams const & op) const
+docstring InsetGraphics::xhtml(XMLStream & xs, OutputParams const & op) const
{
string const output_file = op.dryrun ? string() : prepareHTMLFile(op);
<< params().filename << "' for output. File missing?");
string const attr = "src='" + params().filename.absFileName()
+ "' alt='image: " + output_file + "'";
- xs << html::CompTag("img", attr);
+ xs << xml::CompTag("img", attr);
return docstring();
}
string const attr = imgstyle + "src='" + output_file + "' alt='image: "
+ output_file + "'";
- xs << html::CompTag("img", attr);
+ xs << xml::CompTag("img", attr);
return docstring();
}
if (contains(rel_file, "."))
features.require("lyxdot");
}
+ if (features.inDeletedInset()) {
+ features.require("tikz");
+ features.require("ct-tikz-object-sout");
+ }
}