#include "frontends/alert.h"
#include "support/convert.h"
+#include "support/docstream.h"
#include "support/filetools.h"
#include "support/lyxlib.h" // sum
#include "support/lstrings.h"
using support::FileName;
using support::float_equal;
using support::getExtension;
-using support::isFileReadable;
using support::isValidLaTeXFilename;
using support::latex_path;
using support::onlyFilename;
{
// Are we using latex or pdflatex?
if (runparams.flavor == OutputParams::PDFLATEX) {
- LYXERR(Debug::GRAPHICS) << "findTargetFormat: PDF mode" << endl;
+ LYXERR(Debug::GRAPHICS, "findTargetFormat: PDF mode");
Format const * const f = formats.getFormat(format);
// Convert vector graphics to pdf
if (f && f->vectorFormat())
return "png";
}
// If it's postscript, we always do eps.
- LYXERR(Debug::GRAPHICS) << "findTargetFormat: PostScript mode" << endl;
+ LYXERR(Debug::GRAPHICS, "findTargetFormat: PostScript mode");
if (format != "ps")
// any other than ps is changed to eps
return "eps";
{
BOOST_ASSERT(buf.embeddedFiles().enabled());
params_.filename = file;
- LYXERR(Debug::FILES) << "Update InsetGraphic with File "
+ LYXERR(Debug::FILES, "Update InsetGraphic with File "
<< params_.filename.toFilesystemEncoding()
- << ", embedding status: "
- << params_.filename.embedded() << std::endl;
+ << ", embedding status: " << params_.filename.embedded());
}
}
-bool InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
+void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
{
graphic_->metrics(mi, dim);
- bool const changed = dim_ != dim;
- dim_ = dim;
- return changed;
}
if (token == "Graphics")
readInsetGraphics(lex, buf.filePath());
else
- LYXERR(Debug::GRAPHICS) << "Not a Graphics inset!" << endl;
+ LYXERR(Debug::GRAPHICS, "Not a Graphics inset!");
// InsetGraphics is read, with filename in params_. We do not know if this file actually
// exists or is embedded so we need to get the 'availableFile' from buf.embeddedFiles()
lex.next();
string const token = lex.getString();
- LYXERR(Debug::GRAPHICS) << "Token: '" << token << '\''
- << endl;
+ LYXERR(Debug::GRAPHICS, "Token: '" << token << '\'');
- if (token.empty()) {
+ if (token.empty())
continue;
- } else if (token == "\\end_inset") {
+
+ if (token == "\\end_inset") {
finished = true;
} else {
if (!params_.Read(lex, token, bufpath))
// 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)
+ // 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;
namespace {
-enum CopyStatus {
+enum GraphicsCopyStatus {
SUCCESS,
FAILURE,
IDENTICAL_PATHS,
};
-std::pair<CopyStatus, FileName> const
+std::pair<GraphicsCopyStatus, FileName> const
copyFileIfNeeded(FileName const & file_in, FileName const & file_out)
{
unsigned long const checksum_in = support::sum(file_in);
bool const success = mover.copy(file_in, file_out);
if (!success) {
// FIXME UNICODE
- LYXERR(Debug::GRAPHICS)
- << to_utf8(support::bformat(_("Could not copy the file\n%1$s\n"
+ LYXERR(Debug::GRAPHICS,
+ to_utf8(support::bformat(_("Could not copy the file\n%1$s\n"
"into the temporary directory."),
- from_utf8(file_in.absFilename())))
- << std::endl;
+ from_utf8(file_in.absFilename()))));
}
- CopyStatus status = success ? SUCCESS : FAILURE;
+ GraphicsCopyStatus status = success ? SUCCESS : FAILURE;
return std::make_pair(status, file_out);
}
-std::pair<CopyStatus, FileName> const
+std::pair<GraphicsCopyStatus, FileName> const
copyToDirIfNeeded(DocFileName const & file, string const & dir)
{
using support::rtrim;
// The master buffer. This is useful when there are multiple levels
// of include files
- Buffer const * m_buffer = buf.getMasterBuffer();
+ Buffer const * masterBuffer = buf.masterBuffer();
// Return the output name if we are inside a comment or the file does
// not exist.
// We are not going to change the extension or using the name of the
// temporary file, the code is already complicated enough.
- if (runparams.inComment || !isFileReadable(params().filename))
- return params().filename.outputFilename(m_buffer->filePath());
+ if (runparams.inComment || !params().filename.isFileReadable())
+ return params().filename.outputFilename(masterBuffer->filePath());
// We place all temporary files in the master buffer's temp dir.
// This is possible because we use mangled file names.
// This is necessary for DVI export.
- string const temp_path = m_buffer->temppath();
+ string const temp_path = masterBuffer->temppath();
- CopyStatus status;
+ GraphicsCopyStatus status;
boost::tie(status, temp_file) =
copyToDirIfNeeded(params().filename, temp_path);
if (status == FAILURE)
return orig_file;
- // a relative filename should be relative to the master
- // buffer.
+ // a relative filename should be relative to the master buffer.
// "nice" means that the buffer is exported to LaTeX format but not
- // run through the LaTeX compiler.
- string output_file = support::os::external_path(runparams.nice ?
- params().filename.outputFilename(m_buffer->filePath()) :
- onlyFilename(temp_file.absFilename()));
+ // run through the LaTeX compiler.
+ string output_file = runparams.nice ?
+ params().filename.outputFilename(masterBuffer->filePath()) :
+ onlyFilename(temp_file.absFilename());
if (runparams.nice && !isValidLaTeXFilename(output_file)) {
frontend::Alert::warning(_("Invalid filename"),
// this file, but we can't check, because that would
// mean to unzip the file and thereby making the
// noUnzip parameter meaningless.
- LYXERR(Debug::GRAPHICS)
- << "\tpass zipped file to LaTeX.\n";
+ LYXERR(Debug::GRAPHICS, "\tpass zipped file to LaTeX.");
FileName const bb_orig_file = FileName(changeExtension(orig_file, "bb"));
if (runparams.nice) {
// temp_file has been unzipped already and
// orig_file has not changed in the meantime.
temp_file = unzipped_temp_file;
- LYXERR(Debug::GRAPHICS)
- << "\twas already unzipped to " << temp_file
- << endl;
+ LYXERR(Debug::GRAPHICS, "\twas already unzipped to " << temp_file);
} else {
// unzipped_temp_file does not exist or is too old
temp_file = unzipFile(temp_file);
- LYXERR(Debug::GRAPHICS)
- << "\tunzipped to " << temp_file << endl;
+ LYXERR(Debug::GRAPHICS, "\tunzipped to " << temp_file);
}
}
string const from = formats.getFormatFromFile(temp_file);
- if (from.empty()) {
- LYXERR(Debug::GRAPHICS)
- << "\tCould not get file format." << endl;
- }
+ if (from.empty())
+ LYXERR(Debug::GRAPHICS, "\tCould not get file format.");
+
string const to = findTargetFormat(from, runparams);
string const ext = formats.extension(to);
- LYXERR(Debug::GRAPHICS)
- << "\t we have: from " << from << " to " << to << '\n';
+ LYXERR(Debug::GRAPHICS, "\t we have: from " << from << " to " << to);
// We're going to be running the exported buffer through the LaTeX
// compiler, so must ensure that LaTeX can cope with the graphics
// file format.
- LYXERR(Debug::GRAPHICS)
- << "\tthe orig file is: " << orig_file << endl;
+ LYXERR(Debug::GRAPHICS, "\tthe orig file is: " << orig_file);
if (from == to) {
if (!runparams.nice && getExtension(temp_file.absFilename()) != ext) {
temp_file = new_file;
output_file = changeExtension(output_file, ext);
source_file = FileName(changeExtension(source_file.absFilename(), ext));
- } else
- LYXERR(Debug::GRAPHICS)
- << "Could not rename file `"
- << temp_file << "' to `" << new_file
- << "'." << endl;
+ } else {
+ LYXERR(Debug::GRAPHICS, "Could not rename file `"
+ << temp_file << "' to `" << new_file << "'.");
+ }
}
// The extension of temp_file might be != ext!
runparams.exportdata->addExternalFile(tex_format, source_file,
// Yes if to_file does not exist or if temp_file is newer than to_file
if (compare_timestamps(temp_file, to_file) < 0) {
// FIXME UNICODE
- LYXERR(Debug::GRAPHICS)
- << to_utf8(bformat(_("No conversion of %1$s is needed after all"),
- from_utf8(rel_file)))
- << std::endl;
+ LYXERR(Debug::GRAPHICS,
+ to_utf8(bformat(_("No conversion of %1$s is needed after all"),
+ from_utf8(rel_file))));
runparams.exportdata->addExternalFile(tex_format, to_file,
output_to_file);
runparams.exportdata->addExternalFile("dvi", to_file,
return stripExtensionIfPossible(output_to_file, runparams.nice);
}
- LYXERR(Debug::GRAPHICS)
- << "\tThe original file is " << orig_file << "\n"
+ LYXERR(Debug::GRAPHICS,"\tThe original file is " << orig_file << "\n"
<< "\tA copy has been made and convert is to be called with:\n"
<< "\tfile to convert = " << temp_file << '\n'
- << "\t from " << from << " to " << to << '\n';
+ << "\t from " << from << " to " << to);
// FIXME (Abdel 12/08/06): Is there a need to show these errors?
ErrorList el;
{
// If there is no file specified or not existing,
// just output a message about it in the latex output.
- LYXERR(Debug::GRAPHICS)
- << "insetgraphics::latex: Filename = "
- << params().filename.absFilename() << endl;
+ LYXERR(Debug::GRAPHICS, "insetgraphics::latex: Filename = "
+ << params().filename.absFilename());
string const relative_file =
params().filename.relFilename(buf.filePath());
- bool const file_exists = !params().filename.empty() &&
- isFileReadable(params().filename);
+ bool const file_exists = !params().filename.empty()
+ && params().filename.isFileReadable();
string const message = file_exists ?
string() : string("bb = 0 0 200 100, draft, type=eps");
// if !message.empty() then there was no existing file
// "filename" found. In this case LaTeX
// draws only a rectangle with the above bb and the
// not found filename in it.
- LYXERR(Debug::GRAPHICS)
- << "\tMessage = \"" << message << '\"' << endl;
+ LYXERR(Debug::GRAPHICS, "\tMessage = \"" << message << '\"');
// These variables collect all the latex code that should be before and
// after the actual includegraphics command.
// Write the options if there are any.
string const opts = createLatexOptions();
- LYXERR(Debug::GRAPHICS) << "\tOpts = " << opts << endl;
+ LYXERR(Debug::GRAPHICS, "\tOpts = " << opts);
if (!opts.empty() && !message.empty())
before += ('[' + opts + ',' + message + ']');
else if (!opts.empty() || !message.empty())
before += ('[' + opts + message + ']');
- LYXERR(Debug::GRAPHICS)
- << "\tBefore = " << before
- << "\n\tafter = " << after << endl;
+ LYXERR(Debug::GRAPHICS, "\tBefore = " << before << "\n\tafter = " << after);
string latex_str = before + '{';
// Convert the file if necessary.
// FIXME UNICODE
os << from_utf8(latex_str);
- LYXERR(Debug::GRAPHICS) << "InsetGraphics::latex outputting:\n"
- << latex_str << endl;
+ LYXERR(Debug::GRAPHICS, "InsetGraphics::latex outputting:\n" << latex_str);
// Return how many newlines we issued.
return int(std::count(latex_str.begin(), latex_str.end(),'\n'));
}
}
-namespace {
-
-int writeImageObject(char const * format,
- odocstream & os,
- OutputParams const & runparams,
- docstring const & graphic_label,
- docstring const & attributes)
+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
- << "; ["
- << std::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 << std::endl << "]]>" ;
- }
- return runparams.flavor == OutputParams::XML ? 0 : 2;
-}
-// end anonymous namespace
+ if (runparams.flavor != OutputParams::XML)
+ os << "<![ %output.print." << format
+ << "; [" << std::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 << std::endl << "]]>" ;
+
+ return runparams.flavor == OutputParams::XML ? 0 : 2;
}
// 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) {
+ if (runparams.flavor == OutputParams::XML)
runparams.exportdata->addExternalFile("docbook-xml",
params().filename);
- } else {
+ else
runparams.exportdata->addExternalFile("docbook",
params().filename);
- }
+
os << "<inlinemediaobject>";
int r = 0;
features.require("graphicx");
if (features.runparams().nice) {
- Buffer const * m_buffer = features.buffer().getMasterBuffer();
- string const rel_file = removeExtension(params().filename.relFilename(m_buffer->filePath()));
+ Buffer const * masterBuffer = features.buffer().masterBuffer();
+ string const rel_file = removeExtension(params().filename.relFilename(masterBuffer->filePath()));
if (contains(rel_file, "."))
features.require("lyxdot");
}