2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
|
* \file InsetGraphics.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-01-29 09:26:24 +00:00
|
|
|
|
* \author Baruch Even
|
2003-09-07 01:45:40 +00:00
|
|
|
|
* \author Herbert Vo<EFBFBD>
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*/
|
2000-02-29 02:19:17 +00:00
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
|
/*
|
2002-07-18 14:01:42 +00:00
|
|
|
|
TODO
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2002-03-18 17:37:08 +00:00
|
|
|
|
* What advanced features the users want to do?
|
|
|
|
|
Implement them in a non latex dependent way, but a logical way.
|
|
|
|
|
LyX should translate it to latex or any other fitting format.
|
2000-07-31 12:30:10 +00:00
|
|
|
|
* Add a way to roll the image file into the file format.
|
2001-02-08 13:06:55 +00:00
|
|
|
|
* When loading, if the image is not found in the expected place, try
|
2002-03-18 17:37:08 +00:00
|
|
|
|
to find it in the clipart, or in the same directory with the image.
|
|
|
|
|
* The image choosing dialog could show thumbnails of the image formats
|
|
|
|
|
it knows of, thus selection based on the image instead of based on
|
|
|
|
|
filename.
|
|
|
|
|
* Add support for the 'picins' package.
|
|
|
|
|
* Add support for the 'picinpar' package.
|
|
|
|
|
* Improve support for 'subfigure' - Allow to set the various options
|
|
|
|
|
that are possible.
|
|
|
|
|
*/
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
|
|
/* NOTES:
|
|
|
|
|
* Fileformat:
|
|
|
|
|
* The filename is kept in the lyx file in a relative way, so as to allow
|
|
|
|
|
* moving the document file and its images with no problem.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2000-07-31 12:30:10 +00:00
|
|
|
|
*
|
|
|
|
|
* Conversions:
|
2001-07-29 06:04:20 +00:00
|
|
|
|
* Postscript output means EPS figures.
|
|
|
|
|
*
|
|
|
|
|
* PDF output is best done with PDF figures if it's a direct conversion
|
|
|
|
|
* or PNG figures otherwise.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
* Image format
|
|
|
|
|
* from to
|
|
|
|
|
* EPS epstopdf
|
|
|
|
|
* PS ps2pdf
|
|
|
|
|
* JPG/PNG direct
|
|
|
|
|
* PDF direct
|
|
|
|
|
* others PNG
|
2000-07-31 12:30:10 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
#include <config.h>
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "insets/InsetGraphics.h"
|
|
|
|
|
#include "insets/RenderGraphic.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
2000-06-21 15:07:57 +00:00
|
|
|
|
#include "BufferView.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Converter.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
|
#include "Cursor.h"
|
2000-07-31 12:30:10 +00:00
|
|
|
|
#include "debug.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "DispatchResult.h"
|
2007-06-15 13:13:49 +00:00
|
|
|
|
#include "ErrorList.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Exporter.h"
|
|
|
|
|
#include "Format.h"
|
|
|
|
|
#include "FuncRequest.h"
|
2005-04-22 08:57:22 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "gettext.h"
|
2002-02-27 09:59:52 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-28 12:58:49 +00:00
|
|
|
|
#include "Length.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "MetricsInfo.h"
|
|
|
|
|
#include "Mover.h"
|
|
|
|
|
#include "OutputParams.h"
|
2004-10-29 23:08:04 +00:00
|
|
|
|
#include "sgml.h"
|
2007-08-30 20:46:42 +00:00
|
|
|
|
#include "EmbeddedFiles.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
2007-04-28 20:44:46 +00:00
|
|
|
|
#include "frontends/alert.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
|
#include "support/convert.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
#include "support/filetools.h"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
#include "support/lyxlib.h" // sum
|
2004-12-28 11:23:05 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "support/os.h"
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
|
#include "support/Systemcall.h"
|
2000-03-09 23:58:55 +00:00
|
|
|
|
|
2002-06-25 15:59:10 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
2003-09-03 17:23:38 +00:00
|
|
|
|
#include <boost/tuple/tuple.hpp>
|
2002-06-25 15:59:10 +00:00
|
|
|
|
|
2007-08-12 08:57:17 +00:00
|
|
|
|
#include <algorithm>
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::bformat;
|
|
|
|
|
using support::changeExtension;
|
|
|
|
|
using support::compare_timestamps;
|
|
|
|
|
using support::contains;
|
2006-11-18 12:49:47 +00:00
|
|
|
|
using support::DocFileName;
|
2006-11-26 21:30:39 +00:00
|
|
|
|
using support::FileName;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::float_equal;
|
|
|
|
|
using support::getExtension;
|
|
|
|
|
using support::isFileReadable;
|
2007-06-26 16:55:42 +00:00
|
|
|
|
using support::isValidLaTeXFilename;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::latex_path;
|
|
|
|
|
using support::onlyFilename;
|
|
|
|
|
using support::removeExtension;
|
|
|
|
|
using support::rtrim;
|
|
|
|
|
using support::subst;
|
2007-06-25 13:49:51 +00:00
|
|
|
|
using support::suffixIs;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::Systemcall;
|
|
|
|
|
using support::unzipFile;
|
|
|
|
|
using support::unzippedFileName;
|
2003-09-16 11:03:20 +00:00
|
|
|
|
|
2001-07-28 12:24:16 +00:00
|
|
|
|
using std::endl;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::ostream;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
2000-03-09 23:58:55 +00:00
|
|
|
|
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2006-01-19 21:18:25 +00:00
|
|
|
|
/// Find the most suitable image format for images in \p format
|
|
|
|
|
/// Note that \p format may be unknown (i. e. an empty string)
|
2004-10-29 15:47:55 +00:00
|
|
|
|
string findTargetFormat(string const & format, OutputParams const & runparams)
|
2002-11-04 02:12:42 +00:00
|
|
|
|
{
|
2004-10-29 15:47:55 +00:00
|
|
|
|
// Are we using latex or pdflatex?
|
2003-11-05 12:06:20 +00:00
|
|
|
|
if (runparams.flavor == OutputParams::PDFLATEX) {
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS) << "findTargetFormat: PDF mode" << endl;
|
2006-10-03 08:34:59 +00:00
|
|
|
|
Format const * const f = formats.getFormat(format);
|
|
|
|
|
// Convert vector graphics to pdf
|
|
|
|
|
if (f && f->vectorFormat())
|
2002-11-04 02:12:42 +00:00
|
|
|
|
return "pdf";
|
2004-10-29 15:47:55 +00:00
|
|
|
|
// pdflatex can use jpeg, png and pdf directly
|
2006-10-03 08:34:59 +00:00
|
|
|
|
if (format == "jpg")
|
2004-10-29 15:47:55 +00:00
|
|
|
|
return format;
|
|
|
|
|
// Convert everything else to png
|
|
|
|
|
return "png";
|
2002-11-04 02:12:42 +00:00
|
|
|
|
}
|
|
|
|
|
// If it's postscript, we always do eps.
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS) << "findTargetFormat: PostScript mode" << endl;
|
2004-10-29 15:47:55 +00:00
|
|
|
|
if (format != "ps")
|
|
|
|
|
// any other than ps is changed to eps
|
|
|
|
|
return "eps";
|
|
|
|
|
// let ps untouched
|
|
|
|
|
return format;
|
2002-02-20 09:04:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2000-03-09 23:58:55 +00:00
|
|
|
|
InsetGraphics::InsetGraphics()
|
2006-10-22 11:00:04 +00:00
|
|
|
|
: graphic_label(sgml::uniqueID(from_ascii("graph"))),
|
2004-04-13 17:25:23 +00:00
|
|
|
|
graphic_(new RenderGraphic(this))
|
|
|
|
|
{}
|
2000-02-29 02:19:17 +00:00
|
|
|
|
|
2001-05-08 10:50:09 +00:00
|
|
|
|
|
2003-06-03 15:10:14 +00:00
|
|
|
|
InsetGraphics::InsetGraphics(InsetGraphics const & ig)
|
2007-04-29 13:39:47 +00:00
|
|
|
|
: Inset(ig),
|
2003-06-03 17:49:09 +00:00
|
|
|
|
boost::signals::trackable(),
|
2006-10-22 11:00:04 +00:00
|
|
|
|
graphic_label(sgml::uniqueID(from_ascii("graph"))),
|
2004-04-13 17:25:23 +00:00
|
|
|
|
graphic_(new RenderGraphic(*ig.graphic_, this))
|
2001-07-14 20:11:35 +00:00
|
|
|
|
{
|
2003-06-03 15:10:14 +00:00
|
|
|
|
setParams(ig.params());
|
2001-07-14 20:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetGraphics::clone() const
|
2003-02-26 16:05:35 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return new InsetGraphics(*this);
|
2003-02-26 16:05:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
|
InsetGraphics::~InsetGraphics()
|
|
|
|
|
{
|
2003-06-03 17:49:09 +00:00
|
|
|
|
InsetGraphicsMailer(*this).hideDialog();
|
2003-03-07 18:44:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2003-03-07 18:44:57 +00:00
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
2004-10-05 10:11:42 +00:00
|
|
|
|
case LFUN_GRAPHICS_EDIT: {
|
2007-08-21 13:03:55 +00:00
|
|
|
|
Buffer const & buffer = cur.bv().buffer();
|
2004-04-13 10:36:09 +00:00
|
|
|
|
InsetGraphicsParams p;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer, p);
|
2004-04-13 10:36:09 +00:00
|
|
|
|
editGraphics(p, buffer);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-07 18:44:57 +00:00
|
|
|
|
case LFUN_INSET_MODIFY: {
|
2004-04-08 15:03:33 +00:00
|
|
|
|
Buffer const & buffer = cur.buffer();
|
2003-03-07 18:44:57 +00:00
|
|
|
|
InsetGraphicsParams p;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer, p);
|
2005-05-09 17:29:22 +00:00
|
|
|
|
if (!p.filename.empty())
|
2003-06-03 15:10:14 +00:00
|
|
|
|
setParams(p);
|
2005-05-09 17:29:22 +00:00
|
|
|
|
else
|
|
|
|
|
cur.noUpdate();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-03-07 18:44:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
InsetGraphicsMailer(*this).updateDialog(&cur.bv());
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-03-07 18:44:57 +00:00
|
|
|
|
|
2003-03-09 09:38:47 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
2007-05-23 10:35:57 +00:00
|
|
|
|
if (!cur.selection())
|
|
|
|
|
InsetGraphicsMailer(*this).showDialog(&cur.bv());
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-03-09 09:38:47 +00:00
|
|
|
|
|
2003-03-07 18:44:57 +00:00
|
|
|
|
default:
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-03-07 18:44:57 +00:00
|
|
|
|
}
|
2000-07-31 12:30:10 +00:00
|
|
|
|
}
|
2000-02-29 02:19:17 +00:00
|
|
|
|
|
2001-05-08 10:50:09 +00:00
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2005-04-22 08:57:22 +00:00
|
|
|
|
FuncStatus & flag) const
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
case LFUN_GRAPHICS_EDIT:
|
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
|
flag.enabled(true);
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
default:
|
2007-04-29 13:39:47 +00:00
|
|
|
|
return Inset::getStatus(cur, cmd, flag);
|
2005-04-22 08:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-09 07:07:13 +00:00
|
|
|
|
void InsetGraphics::registerEmbeddedFiles(Buffer const &,
|
|
|
|
|
EmbeddedFiles & files) const
|
2007-08-30 20:46:42 +00:00
|
|
|
|
{
|
|
|
|
|
files.registerFile(params().filename.absFilename(),
|
2007-09-09 07:07:13 +00:00
|
|
|
|
false, this);
|
2007-08-30 20:46:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetGraphics::edit(Cursor & cur, bool)
|
2003-11-04 12:36:59 +00:00
|
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
|
InsetGraphicsMailer(*this).showDialog(&cur.bv());
|
2003-11-04 12:36:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
|
2000-02-29 02:19:17 +00:00
|
|
|
|
{
|
2003-06-03 17:49:09 +00:00
|
|
|
|
graphic_->metrics(mi, dim);
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool const changed = dim_ != dim;
|
2003-07-18 07:47:07 +00:00
|
|
|
|
dim_ = dim;
|
2006-11-28 15:15:49 +00:00
|
|
|
|
return changed;
|
2003-03-07 18:44:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
|
void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
|
2000-02-29 02:19:17 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2003-06-03 17:49:09 +00:00
|
|
|
|
graphic_->draw(pi, x, y);
|
2000-02-29 02:19:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset::EDITABLE InsetGraphics::editable() const
|
2000-02-29 02:19:17 +00:00
|
|
|
|
{
|
2000-03-08 13:52:57 +00:00
|
|
|
|
return IS_EDITABLE;
|
2000-02-29 02:19:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetGraphics::write(Buffer const & buf, ostream & os) const
|
2000-02-29 02:19:17 +00:00
|
|
|
|
{
|
2002-08-24 22:02:30 +00:00
|
|
|
|
os << "Graphics\n";
|
2007-09-05 17:50:07 +00:00
|
|
|
|
params().Write(os, buf);
|
2000-02-29 02:19:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
void InsetGraphics::read(Buffer const & buf, Lexer & lex)
|
2001-07-28 12:24:16 +00:00
|
|
|
|
{
|
2001-08-06 19:13:25 +00:00
|
|
|
|
string const token = lex.getString();
|
2001-07-28 12:24:16 +00:00
|
|
|
|
|
2001-07-29 06:04:20 +00:00
|
|
|
|
if (token == "Graphics")
|
2003-08-28 07:41:31 +00:00
|
|
|
|
readInsetGraphics(lex, buf.filePath());
|
2001-07-28 12:24:16 +00:00
|
|
|
|
else
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS) << "Not a Graphics inset!" << endl;
|
2001-07-28 12:24:16 +00:00
|
|
|
|
|
2007-09-05 17:50:07 +00:00
|
|
|
|
// 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()
|
|
|
|
|
EmbeddedFiles::EmbeddedFileList::const_iterator it = buf.embeddedFiles().find(params_.filename.toFilesystemEncoding());
|
|
|
|
|
if (it != buf.embeddedFiles().end())
|
|
|
|
|
// using available file, embedded or external, depending on file availability and
|
|
|
|
|
// embedding status.
|
|
|
|
|
params_.filename = DocFileName(it->availableFile(&buf));
|
2003-06-03 17:49:09 +00:00
|
|
|
|
graphic_->update(params().as_grfxParams());
|
2001-07-28 12:24:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-25 11:04:34 +00:00
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
void InsetGraphics::readInsetGraphics(Lexer & lex, string const & bufpath)
|
2000-02-29 02:19:17 +00:00
|
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
|
bool finished = false;
|
|
|
|
|
|
2001-08-06 19:13:25 +00:00
|
|
|
|
while (lex.isOK() && !finished) {
|
2000-08-14 09:44:53 +00:00
|
|
|
|
lex.next();
|
|
|
|
|
|
2001-08-06 19:13:25 +00:00
|
|
|
|
string const token = lex.getString();
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS) << "Token: '" << token << '\''
|
2003-08-02 11:30:30 +00:00
|
|
|
|
<< endl;
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
|
|
if (token.empty()) {
|
|
|
|
|
continue;
|
|
|
|
|
} else if (token == "\\end_inset") {
|
|
|
|
|
finished = true;
|
2004-02-25 12:00:53 +00:00
|
|
|
|
} else {
|
2003-06-03 15:10:14 +00:00
|
|
|
|
if (!params_.Read(lex, token, bufpath))
|
2002-03-21 17:09:55 +00:00
|
|
|
|
lyxerr << "Unknown token, " << token << ", skipping."
|
2002-02-27 09:59:52 +00:00
|
|
|
|
<< std::endl;
|
2000-08-14 09:44:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-07-28 12:24:16 +00:00
|
|
|
|
}
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
|
|
2002-01-29 09:26:24 +00:00
|
|
|
|
string const InsetGraphics::createLatexOptions() const
|
2001-02-08 13:06:55 +00:00
|
|
|
|
{
|
|
|
|
|
// Calculate the options part of the command, we must do it to a string
|
|
|
|
|
// stream since we might have a trailing comma that we would like to remove
|
|
|
|
|
// before writing it to the output stream.
|
2001-07-13 14:03:48 +00:00
|
|
|
|
ostringstream options;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
if (!params().bb.empty())
|
2005-02-08 17:15:17 +00:00
|
|
|
|
options << "bb=" << rtrim(params().bb) << ',';
|
2002-02-27 09:59:52 +00:00
|
|
|
|
if (params().draft)
|
2005-02-08 17:15:17 +00:00
|
|
|
|
options << "draft,";
|
2002-02-27 09:59:52 +00:00
|
|
|
|
if (params().clip)
|
2005-02-08 17:15:17 +00:00
|
|
|
|
options << "clip,";
|
2007-06-25 13:49:51 +00:00
|
|
|
|
ostringstream size;
|
2005-01-27 21:05:44 +00:00
|
|
|
|
double const scl = convert<double>(params().scale);
|
2005-01-04 10:59:49 +00:00
|
|
|
|
if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
|
|
|
|
|
if (!float_equal(scl, 100.0, 0.05))
|
2007-06-25 13:49:51 +00:00
|
|
|
|
size << "scale=" << scl / 100.0 << ',';
|
2002-08-24 22:02:30 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (!params().width.zero())
|
2007-06-25 13:49:51 +00:00
|
|
|
|
size << "width=" << params().width.asLatexString() << ',';
|
2002-08-24 22:02:30 +00:00
|
|
|
|
if (!params().height.zero())
|
2007-06-25 13:49:51 +00:00
|
|
|
|
size << "height=" << params().height.asLatexString() << ',';
|
2002-08-24 22:02:30 +00:00
|
|
|
|
if (params().keepAspectRatio)
|
2007-06-25 13:49:51 +00:00
|
|
|
|
size << "keepaspectratio,";
|
2002-01-29 09:26:24 +00:00
|
|
|
|
}
|
2007-06-25 13:49:51 +00:00
|
|
|
|
if (params().scaleBeforeRotation && !size.str().empty())
|
|
|
|
|
options << size.str();
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
|
|
|
|
// Make sure rotation angle is not very close to zero;
|
|
|
|
|
// a float can be effectively zero but not exactly zero.
|
2005-01-12 10:30:46 +00:00
|
|
|
|
if (!params().rotateAngle.empty()
|
2005-01-27 21:05:44 +00:00
|
|
|
|
&& !float_equal(convert<double>(params().rotateAngle), 0.0, 0.001)) {
|
2005-02-08 17:15:17 +00:00
|
|
|
|
options << "angle=" << params().rotateAngle << ',';
|
2002-02-27 09:59:52 +00:00
|
|
|
|
if (!params().rotateOrigin.empty()) {
|
2005-02-08 17:15:17 +00:00
|
|
|
|
options << "origin=" << params().rotateOrigin[0];
|
2002-02-27 09:59:52 +00:00
|
|
|
|
if (contains(params().rotateOrigin,"Top"))
|
2002-01-29 09:26:24 +00:00
|
|
|
|
options << 't';
|
2002-02-27 09:59:52 +00:00
|
|
|
|
else if (contains(params().rotateOrigin,"Bottom"))
|
2002-01-29 09:26:24 +00:00
|
|
|
|
options << 'b';
|
2002-02-27 09:59:52 +00:00
|
|
|
|
else if (contains(params().rotateOrigin,"Baseline"))
|
2002-01-29 09:26:24 +00:00
|
|
|
|
options << 'B';
|
2005-02-08 17:15:17 +00:00
|
|
|
|
options << ',';
|
2002-01-29 09:26:24 +00:00
|
|
|
|
}
|
2001-02-08 13:06:55 +00:00
|
|
|
|
}
|
2007-06-25 13:49:51 +00:00
|
|
|
|
if (!params().scaleBeforeRotation && !size.str().empty())
|
|
|
|
|
options << size.str();
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
|
if (!params().special.empty())
|
2005-02-08 17:15:17 +00:00
|
|
|
|
options << params().special << ',';
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
|
string opts = options.str();
|
2005-02-08 17:15:17 +00:00
|
|
|
|
// delete last ','
|
2007-06-25 13:49:51 +00:00
|
|
|
|
if (suffixIs(opts, ','))
|
|
|
|
|
opts = opts.substr(0, opts.size() - 1);
|
|
|
|
|
|
|
|
|
|
return opts;
|
2001-07-29 06:04:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
|
docstring const InsetGraphics::toDocbookLength(Length const & len) const
|
2004-10-04 13:56:04 +00:00
|
|
|
|
{
|
2006-10-21 19:40:29 +00:00
|
|
|
|
odocstringstream result;
|
2004-10-21 22:55:04 +00:00
|
|
|
|
switch (len.unit()) {
|
2007-04-28 12:58:49 +00:00
|
|
|
|
case Length::SP: // Scaled point (65536sp = 1pt) TeX's smallest unit.
|
2004-10-05 10:11:42 +00:00
|
|
|
|
result << len.value() * 65536.0 * 72 / 72.27 << "pt";
|
2004-10-04 13:56:04 +00:00
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
|
case Length::PT: // Point = 1/72.27in = 0.351mm
|
2004-10-05 10:11:42 +00:00
|
|
|
|
result << len.value() * 72 / 72.27 << "pt";
|
2004-10-04 13:56:04 +00:00
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
|
case Length::BP: // Big point (72bp = 1in), also PostScript point
|
2004-10-04 13:56:04 +00:00
|
|
|
|
result << len.value() << "pt";
|
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
|
case Length::DD: // Didot point = 1/72 of a French inch, = 0.376mm
|
2004-10-04 13:56:04 +00:00
|
|
|
|
result << len.value() * 0.376 << "mm";
|
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
|
case Length::MM: // Millimeter = 2.845pt
|
2004-10-04 13:56:04 +00:00
|
|
|
|
result << len.value() << "mm";
|
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
|
case Length::PC: // Pica = 12pt = 4.218mm
|
2004-10-04 13:56:04 +00:00
|
|
|
|
result << len.value() << "pc";
|
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
|
case Length::CC: // Cicero = 12dd = 4.531mm
|
2004-10-04 13:56:04 +00:00
|
|
|
|
result << len.value() * 4.531 << "mm";
|
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
|
case Length::CM: // Centimeter = 10mm = 2.371pc
|
2004-10-04 13:56:04 +00:00
|
|
|
|
result << len.value() << "cm";
|
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
|
case Length::IN: // Inch = 25.4mm = 72.27pt = 6.022pc
|
2004-10-04 13:56:04 +00:00
|
|
|
|
result << len.value() << "in";
|
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
|
case Length::EX: // Height of a small "x" for the current font.
|
2004-10-04 13:56:04 +00:00
|
|
|
|
// Obviously we have to compromise here. Any better ratio than 1.5 ?
|
|
|
|
|
result << len.value() / 1.5 << "em";
|
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
|
case Length::EM: // Width of capital "M" in current font.
|
2004-10-04 13:56:04 +00:00
|
|
|
|
result << len.value() << "em";
|
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
|
case Length::MU: // Math unit (18mu = 1em) for positioning in math mode
|
2004-10-04 13:56:04 +00:00
|
|
|
|
result << len.value() * 18 << "em";
|
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
|
case Length::PTW: // Percent of TextWidth
|
|
|
|
|
case Length::PCW: // Percent of ColumnWidth
|
|
|
|
|
case Length::PPW: // Percent of PageWidth
|
|
|
|
|
case Length::PLW: // Percent of LineWidth
|
|
|
|
|
case Length::PTH: // Percent of TextHeight
|
|
|
|
|
case Length::PPH: // Percent of Paper
|
2004-10-05 10:11:42 +00:00
|
|
|
|
// Sigh, this will go wrong.
|
2004-10-04 13:56:04 +00:00
|
|
|
|
result << len.value() << "%";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2006-10-21 19:40:29 +00:00
|
|
|
|
result << len.asDocstring();
|
2004-10-04 13:56:04 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return result.str();
|
|
|
|
|
}
|
2004-10-05 10:11:42 +00:00
|
|
|
|
|
2006-10-21 19:40:29 +00:00
|
|
|
|
docstring const InsetGraphics::createDocBookAttributes() const
|
2004-09-29 15:25:54 +00:00
|
|
|
|
{
|
|
|
|
|
// Calculate the options part of the command, we must do it to a string
|
2004-10-04 13:56:04 +00:00
|
|
|
|
// stream since we copied the code from createLatexParams() ;-)
|
2004-09-29 15:25:54 +00:00
|
|
|
|
|
|
|
|
|
// 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 :-)
|
|
|
|
|
|
2006-10-21 19:40:29 +00:00
|
|
|
|
odocstringstream options;
|
2005-01-27 21:05:44 +00:00
|
|
|
|
double const scl = convert<double>(params().scale);
|
2005-01-04 10:59:49 +00:00
|
|
|
|
if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
|
|
|
|
|
if (!float_equal(scl, 100.0, 0.05))
|
2005-01-12 10:30:46 +00:00
|
|
|
|
options << " scale=\""
|
2005-01-04 10:59:49 +00:00
|
|
|
|
<< static_cast<int>( (scl) + 0.5 )
|
2004-09-29 15:25:54 +00:00
|
|
|
|
<< "\" ";
|
|
|
|
|
} else {
|
2004-10-21 22:55:04 +00:00
|
|
|
|
if (!params().width.zero()) {
|
2004-10-04 13:56:04 +00:00
|
|
|
|
options << " width=\"" << toDocbookLength(params().width) << "\" ";
|
|
|
|
|
}
|
2004-10-21 22:55:04 +00:00
|
|
|
|
if (!params().height.zero()) {
|
2004-10-04 13:56:04 +00:00
|
|
|
|
options << " depth=\"" << toDocbookLength(params().height) << "\" ";
|
|
|
|
|
}
|
2004-10-21 22:55:04 +00:00
|
|
|
|
if (params().keepAspectRatio) {
|
2004-10-04 13:56:04 +00:00
|
|
|
|
// This will be irrelevant unless both width and height are set
|
|
|
|
|
options << "scalefit=\"1\" ";
|
|
|
|
|
}
|
2004-09-29 15:25:54 +00:00
|
|
|
|
}
|
2004-10-05 10:11:42 +00:00
|
|
|
|
|
2004-09-29 15:25:54 +00:00
|
|
|
|
|
|
|
|
|
if (!params().special.empty())
|
2006-10-21 19:40:29 +00:00
|
|
|
|
options << from_ascii(params().special) << " ";
|
2004-09-29 15:25:54 +00:00
|
|
|
|
|
|
|
|
|
// trailing blanks are ok ...
|
2006-10-21 19:40:29 +00:00
|
|
|
|
return options.str();
|
2004-09-29 15:25:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-03 17:23:38 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
enum CopyStatus {
|
|
|
|
|
SUCCESS,
|
|
|
|
|
FAILURE,
|
|
|
|
|
IDENTICAL_PATHS,
|
|
|
|
|
IDENTICAL_CONTENTS
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
std::pair<CopyStatus, FileName> const
|
|
|
|
|
copyFileIfNeeded(FileName const & file_in, FileName const & file_out)
|
2003-09-03 17:23:38 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned long const checksum_in = support::sum(file_in);
|
|
|
|
|
unsigned long const checksum_out = support::sum(file_out);
|
|
|
|
|
|
|
|
|
|
if (checksum_in == checksum_out)
|
|
|
|
|
// Nothing to do...
|
|
|
|
|
return std::make_pair(IDENTICAL_CONTENTS, file_out);
|
|
|
|
|
|
2007-01-18 08:42:53 +00:00
|
|
|
|
Mover const & mover = getMover(formats.getFormatFromFile(file_in));
|
2004-10-26 18:39:13 +00:00
|
|
|
|
bool const success = mover.copy(file_in, file_out);
|
2003-09-03 17:23:38 +00:00
|
|
|
|
if (!success) {
|
2006-09-09 15:27:44 +00:00
|
|
|
|
// FIXME UNICODE
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS)
|
2006-10-21 00:16:43 +00:00
|
|
|
|
<< to_utf8(support::bformat(_("Could not copy the file\n%1$s\n"
|
2006-09-11 08:54:10 +00:00
|
|
|
|
"into the temporary directory."),
|
2006-11-26 21:30:39 +00:00
|
|
|
|
from_utf8(file_in.absFilename())))
|
2003-09-03 17:23:38 +00:00
|
|
|
|
<< std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CopyStatus status = success ? SUCCESS : FAILURE;
|
|
|
|
|
return std::make_pair(status, file_out);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
std::pair<CopyStatus, FileName> const
|
2006-11-18 12:49:47 +00:00
|
|
|
|
copyToDirIfNeeded(DocFileName const & file, string const & dir)
|
2004-05-05 15:37:36 +00:00
|
|
|
|
{
|
|
|
|
|
using support::rtrim;
|
|
|
|
|
|
2006-07-08 14:16:56 +00:00
|
|
|
|
string const file_in = file.absFilename();
|
2006-04-08 22:31:11 +00:00
|
|
|
|
string const only_path = support::onlyPath(file_in);
|
|
|
|
|
if (rtrim(support::onlyPath(file_in) , "/") == rtrim(dir, "/"))
|
2004-05-05 15:37:36 +00:00
|
|
|
|
return std::make_pair(IDENTICAL_PATHS, file_in);
|
|
|
|
|
|
2006-07-08 14:16:56 +00:00
|
|
|
|
string mangled = file.mangledFilename();
|
|
|
|
|
if (file.isZipped()) {
|
2004-05-05 15:37:36 +00:00
|
|
|
|
// We need to change _eps.gz to .eps.gz. The mangled name is
|
|
|
|
|
// still unique because of the counter in mangledFilename().
|
|
|
|
|
// We can't just call mangledFilename() with the zip
|
|
|
|
|
// extension removed, because base.eps and base.eps.gz may
|
|
|
|
|
// have different content but would get the same mangled
|
|
|
|
|
// name in this case.
|
2006-07-08 14:16:56 +00:00
|
|
|
|
string const base = removeExtension(file.unzippedFilename());
|
2004-05-05 15:37:36 +00:00
|
|
|
|
string::size_type const ext_len = file_in.length() - base.length();
|
|
|
|
|
mangled[mangled.length() - ext_len] = '.';
|
|
|
|
|
}
|
2006-12-27 10:56:11 +00:00
|
|
|
|
FileName const file_out(support::makeAbsPath(mangled, dir));
|
2004-05-05 15:37:36 +00:00
|
|
|
|
|
2006-12-27 10:56:11 +00:00
|
|
|
|
return copyFileIfNeeded(file, file_out);
|
2004-05-05 15:37:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-02-08 21:14:40 +00:00
|
|
|
|
string const stripExtensionIfPossible(string const & file, bool nice)
|
2004-06-10 08:44:40 +00:00
|
|
|
|
{
|
2007-02-08 21:14:40 +00:00
|
|
|
|
// Remove the extension so the LaTeX compiler will use whatever
|
|
|
|
|
// is appropriate (when there are several versions in different
|
|
|
|
|
// formats).
|
|
|
|
|
// Do this only if we are not exporting for internal usage, because
|
|
|
|
|
// pdflatex prefers png over pdf and it would pick up the png images
|
|
|
|
|
// that we generate for preview.
|
2004-06-10 08:44:40 +00:00
|
|
|
|
// This works only if the filename contains no dots besides
|
|
|
|
|
// the just removed one. We can fool here by replacing all
|
|
|
|
|
// dots with a macro whose definition is just a dot ;-)
|
2005-06-20 14:11:11 +00:00
|
|
|
|
// The automatic format selection does not work if the file
|
|
|
|
|
// name is escaped.
|
2005-07-10 09:31:27 +00:00
|
|
|
|
string const latex_name = latex_path(file,
|
2006-10-21 00:16:43 +00:00
|
|
|
|
support::EXCLUDE_EXTENSION);
|
2007-02-08 21:14:40 +00:00
|
|
|
|
if (!nice || contains(latex_name, '"'))
|
2005-06-20 14:11:11 +00:00
|
|
|
|
return latex_name;
|
2006-04-01 10:49:58 +00:00
|
|
|
|
return latex_path(removeExtension(file),
|
2006-10-21 00:16:43 +00:00
|
|
|
|
support::PROTECT_EXTENSION,
|
|
|
|
|
support::ESCAPE_DOTS);
|
2004-06-10 08:44:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-02-08 21:14:40 +00:00
|
|
|
|
string const stripExtensionIfPossible(string const & file, string const & to, bool nice)
|
2003-09-03 17:23:38 +00:00
|
|
|
|
{
|
|
|
|
|
// No conversion is needed. LaTeX can handle the graphic file as is.
|
|
|
|
|
// This is true even if the orig_file is compressed.
|
2004-06-10 08:44:40 +00:00
|
|
|
|
string const to_format = formats.getFormat(to)->extension();
|
2006-04-08 22:31:11 +00:00
|
|
|
|
string const file_format = getExtension(file);
|
2004-06-10 08:44:40 +00:00
|
|
|
|
// for latex .ps == .eps
|
|
|
|
|
if (to_format == file_format ||
|
|
|
|
|
(to_format == "eps" && file_format == "ps") ||
|
|
|
|
|
(to_format == "ps" && file_format == "eps"))
|
2007-02-08 21:14:40 +00:00
|
|
|
|
return stripExtensionIfPossible(file, nice);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
return latex_path(file, support::EXCLUDE_EXTENSION);
|
2003-09-03 17:23:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
string const InsetGraphics::prepareFile(Buffer const & buf,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2001-02-08 13:06:55 +00:00
|
|
|
|
{
|
2005-02-22 16:57:36 +00:00
|
|
|
|
// The following code depends on non-empty filenames
|
|
|
|
|
if (params().filename.empty())
|
|
|
|
|
return string();
|
|
|
|
|
|
2004-06-10 08:44:40 +00:00
|
|
|
|
string const orig_file = params().filename.absFilename();
|
2003-08-28 07:41:31 +00:00
|
|
|
|
string const rel_file = params().filename.relFilename(buf.filePath());
|
2003-06-03 15:10:14 +00:00
|
|
|
|
|
2006-09-09 15:27:44 +00:00
|
|
|
|
// previewing source code, no file copying or file format conversion
|
view-source feature, from Bo Peng <ben.bob@gmail.com>
* src/buffer.h buffer.C - getSourceCode()
* src/lyxfunc.C - open view-source dialog
* src/text3.C - change LFUN_MOUSE_RELEASE
* src/output_linuxdoc.C, src/output_docbook.C, src/output_latex.C
- intercept output
* src/outputparams.h, outputparams.C - add par_begin, par_end, dryrun
* src/insets/insetgraphics.C - add dryrun mode of file conversion
* lib/ui/stdmenus.ui - add view-source menu item under view
* Add view-source dialog, add
src/frontends/qt2/QViewSourceDialog.h, QViewSource.C, QViewSource.h, QViewSourceDialog.C
src/frontends/qt2/ui/QViewSourceDialogBase.ui
src/frontends/controllers/ControlViewSource.h ControlViewSource.C
modify
src/frontends/qt2/Makefile.dialogs, Makefile.am, Dialogs.C,
src/frontends/controllers/Makefile.am, po.POTFILES.in
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13610 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-09 02:48:54 +00:00
|
|
|
|
if (runparams.dryrun)
|
2007-02-08 21:14:40 +00:00
|
|
|
|
return stripExtensionIfPossible(rel_file, runparams.nice);
|
view-source feature, from Bo Peng <ben.bob@gmail.com>
* src/buffer.h buffer.C - getSourceCode()
* src/lyxfunc.C - open view-source dialog
* src/text3.C - change LFUN_MOUSE_RELEASE
* src/output_linuxdoc.C, src/output_docbook.C, src/output_latex.C
- intercept output
* src/outputparams.h, outputparams.C - add par_begin, par_end, dryrun
* src/insets/insetgraphics.C - add dryrun mode of file conversion
* lib/ui/stdmenus.ui - add view-source menu item under view
* Add view-source dialog, add
src/frontends/qt2/QViewSourceDialog.h, QViewSource.C, QViewSource.h, QViewSourceDialog.C
src/frontends/qt2/ui/QViewSourceDialogBase.ui
src/frontends/controllers/ControlViewSource.h ControlViewSource.C
modify
src/frontends/qt2/Makefile.dialogs, Makefile.am, Dialogs.C,
src/frontends/controllers/Makefile.am, po.POTFILES.in
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13610 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-09 02:48:54 +00:00
|
|
|
|
|
2002-07-18 14:01:42 +00:00
|
|
|
|
// temp_file will contain the file for LaTeX to act on if, for example,
|
|
|
|
|
// we move it to a temp dir or uncompress it.
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName temp_file = params().filename;
|
2002-07-18 14:01:42 +00:00
|
|
|
|
|
2004-06-10 08:44:40 +00:00
|
|
|
|
// The master buffer. This is useful when there are multiple levels
|
|
|
|
|
// of include files
|
|
|
|
|
Buffer const * m_buffer = buf.getMasterBuffer();
|
|
|
|
|
|
2006-01-09 21:00:24 +00:00
|
|
|
|
// Return the output name if we are inside a comment or the file does
|
|
|
|
|
// not exist.
|
2005-02-22 16:57:36 +00:00
|
|
|
|
// We are not going to change the extension or using the name of the
|
|
|
|
|
// temporary file, the code is already complicated enough.
|
2006-11-26 21:30:39 +00:00
|
|
|
|
if (runparams.inComment || !isFileReadable(params().filename))
|
2005-02-22 16:57:36 +00:00
|
|
|
|
return params().filename.outputFilename(m_buffer->filePath());
|
|
|
|
|
|
2004-03-25 10:12:44 +00:00
|
|
|
|
// 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.
|
2004-06-10 08:44:40 +00:00
|
|
|
|
string const temp_path = m_buffer->temppath();
|
2004-03-25 10:12:44 +00:00
|
|
|
|
|
2004-05-05 15:37:36 +00:00
|
|
|
|
CopyStatus status;
|
|
|
|
|
boost::tie(status, temp_file) =
|
2006-07-08 14:16:56 +00:00
|
|
|
|
copyToDirIfNeeded(params().filename, temp_path);
|
2003-09-03 17:23:38 +00:00
|
|
|
|
|
2004-05-05 15:37:36 +00:00
|
|
|
|
if (status == FAILURE)
|
|
|
|
|
return orig_file;
|
2003-09-03 17:23:38 +00:00
|
|
|
|
|
2004-06-10 08:44:40 +00:00
|
|
|
|
// 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.
|
2006-10-21 00:16:43 +00:00
|
|
|
|
string output_file = support::os::external_path(runparams.nice ?
|
2004-06-10 08:44:40 +00:00
|
|
|
|
params().filename.outputFilename(m_buffer->filePath()) :
|
2006-11-26 21:30:39 +00:00
|
|
|
|
onlyFilename(temp_file.absFilename()));
|
2007-06-26 16:55:42 +00:00
|
|
|
|
|
|
|
|
|
if (runparams.nice && !isValidLaTeXFilename(output_file)) {
|
|
|
|
|
frontend::Alert::warning(_("Invalid filename"),
|
|
|
|
|
_("The following filename is likely to cause trouble "
|
|
|
|
|
"when running the exported file through LaTeX: ") +
|
|
|
|
|
from_utf8(output_file));
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName source_file = runparams.nice ? FileName(params().filename) : temp_file;
|
2006-03-28 18:49:46 +00:00
|
|
|
|
string const tex_format = (runparams.flavor == OutputParams::LATEX) ?
|
|
|
|
|
"latex" : "pdflatex";
|
2004-06-10 08:44:40 +00:00
|
|
|
|
|
2006-07-08 14:16:56 +00:00
|
|
|
|
// If the file is compressed and we have specified that it
|
|
|
|
|
// should not be uncompressed, then just return its name and
|
|
|
|
|
// let LaTeX do the rest!
|
|
|
|
|
if (params().filename.isZipped()) {
|
2004-05-05 15:37:36 +00:00
|
|
|
|
if (params().noUnzip) {
|
2004-06-18 06:47:19 +00:00
|
|
|
|
// We don't know whether latex can actually handle
|
2004-06-01 13:39:33 +00:00
|
|
|
|
// this file, but we can't check, because that would
|
|
|
|
|
// mean to unzip the file and thereby making the
|
|
|
|
|
// noUnzip parameter meaningless.
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS)
|
2004-05-05 15:37:36 +00:00
|
|
|
|
<< "\tpass zipped file to LaTeX.\n";
|
2004-06-10 08:44:40 +00:00
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName const bb_orig_file = FileName(changeExtension(orig_file, "bb"));
|
2004-06-10 08:44:40 +00:00
|
|
|
|
if (runparams.nice) {
|
2006-03-28 18:49:46 +00:00
|
|
|
|
runparams.exportdata->addExternalFile(tex_format,
|
2004-06-10 08:44:40 +00:00
|
|
|
|
bb_orig_file,
|
2006-04-08 22:31:11 +00:00
|
|
|
|
changeExtension(output_file, "bb"));
|
2004-06-10 08:44:40 +00:00
|
|
|
|
} else {
|
|
|
|
|
// LaTeX needs the bounding box file in the
|
|
|
|
|
// tmp dir
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName bb_file = FileName(changeExtension(temp_file.absFilename(), "bb"));
|
2004-06-10 08:44:40 +00:00
|
|
|
|
boost::tie(status, bb_file) =
|
|
|
|
|
copyFileIfNeeded(bb_orig_file, bb_file);
|
|
|
|
|
if (status == FAILURE)
|
|
|
|
|
return orig_file;
|
2006-03-28 18:49:46 +00:00
|
|
|
|
runparams.exportdata->addExternalFile(tex_format,
|
2004-06-10 08:44:40 +00:00
|
|
|
|
bb_file);
|
|
|
|
|
}
|
2006-03-28 18:49:46 +00:00
|
|
|
|
runparams.exportdata->addExternalFile(tex_format,
|
2004-06-10 08:44:40 +00:00
|
|
|
|
source_file, output_file);
|
|
|
|
|
runparams.exportdata->addExternalFile("dvi",
|
|
|
|
|
source_file, output_file);
|
|
|
|
|
// We can't strip the extension, because we don't know
|
|
|
|
|
// the unzipped file format
|
2005-07-10 09:31:27 +00:00
|
|
|
|
return latex_path(output_file,
|
2006-10-21 00:16:43 +00:00
|
|
|
|
support::EXCLUDE_EXTENSION);
|
2004-05-05 15:37:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName const unzipped_temp_file =
|
|
|
|
|
FileName(unzippedFileName(temp_file.absFilename()));
|
2006-04-08 09:11:25 +00:00
|
|
|
|
output_file = unzippedFileName(output_file);
|
2006-11-26 21:30:39 +00:00
|
|
|
|
source_file = FileName(unzippedFileName(source_file.absFilename()));
|
2004-05-05 15:37:36 +00:00
|
|
|
|
if (compare_timestamps(unzipped_temp_file, temp_file) > 0) {
|
|
|
|
|
// temp_file has been unzipped already and
|
|
|
|
|
// orig_file has not changed in the meantime.
|
|
|
|
|
temp_file = unzipped_temp_file;
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS)
|
2004-05-05 15:37:36 +00:00
|
|
|
|
<< "\twas already unzipped to " << temp_file
|
|
|
|
|
<< endl;
|
|
|
|
|
} else {
|
|
|
|
|
// unzipped_temp_file does not exist or is too old
|
|
|
|
|
temp_file = unzipFile(temp_file);
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS)
|
2004-05-05 15:37:36 +00:00
|
|
|
|
<< "\tunzipped to " << temp_file << endl;
|
2003-09-03 17:23:38 +00:00
|
|
|
|
}
|
2002-06-18 20:47:49 +00:00
|
|
|
|
}
|
2003-09-09 17:25:35 +00:00
|
|
|
|
|
2004-11-09 19:08:34 +00:00
|
|
|
|
string const from = formats.getFormatFromFile(temp_file);
|
|
|
|
|
if (from.empty()) {
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS)
|
2004-11-09 19:08:34 +00:00
|
|
|
|
<< "\tCould not get file format." << endl;
|
|
|
|
|
}
|
2003-05-22 18:59:10 +00:00
|
|
|
|
string const to = findTargetFormat(from, runparams);
|
2004-10-29 15:47:55 +00:00
|
|
|
|
string const ext = formats.extension(to);
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS)
|
2002-07-18 14:01:42 +00:00
|
|
|
|
<< "\t we have: from " << from << " to " << to << '\n';
|
2002-04-24 10:53:55 +00:00
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS)
|
2003-06-03 15:10:14 +00:00
|
|
|
|
<< "\tthe orig file is: " << orig_file << endl;
|
2002-06-18 20:47:49 +00:00
|
|
|
|
|
2004-06-01 13:39:33 +00:00
|
|
|
|
if (from == to) {
|
2006-11-26 21:30:39 +00:00
|
|
|
|
if (!runparams.nice && getExtension(temp_file.absFilename()) != ext) {
|
2006-05-22 09:15:33 +00:00
|
|
|
|
// The LaTeX compiler will not be able to determine
|
|
|
|
|
// the file format from the extension, so we must
|
|
|
|
|
// change it.
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName const new_file = FileName(changeExtension(temp_file.absFilename(), ext));
|
2006-10-21 00:16:43 +00:00
|
|
|
|
if (support::rename(temp_file, new_file)) {
|
2006-05-22 09:15:33 +00:00
|
|
|
|
temp_file = new_file;
|
|
|
|
|
output_file = changeExtension(output_file, ext);
|
2006-11-26 21:30:39 +00:00
|
|
|
|
source_file = FileName(changeExtension(source_file.absFilename(), ext));
|
2006-05-22 09:15:33 +00:00
|
|
|
|
} else
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS)
|
2006-05-22 09:15:33 +00:00
|
|
|
|
<< "Could not rename file `"
|
|
|
|
|
<< temp_file << "' to `" << new_file
|
|
|
|
|
<< "'." << endl;
|
|
|
|
|
}
|
2004-10-29 15:47:55 +00:00
|
|
|
|
// The extension of temp_file might be != ext!
|
2006-03-28 18:49:46 +00:00
|
|
|
|
runparams.exportdata->addExternalFile(tex_format, source_file,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
output_file);
|
2004-06-10 08:44:40 +00:00
|
|
|
|
runparams.exportdata->addExternalFile("dvi", source_file,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
output_file);
|
2007-02-08 21:14:40 +00:00
|
|
|
|
return stripExtensionIfPossible(output_file, to, runparams.nice);
|
2004-06-01 13:39:33 +00:00
|
|
|
|
}
|
2003-09-03 17:23:38 +00:00
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName const to_file = FileName(changeExtension(temp_file.absFilename(), ext));
|
2006-04-08 22:31:11 +00:00
|
|
|
|
string const output_to_file = changeExtension(output_file, ext);
|
2003-09-03 17:23:38 +00:00
|
|
|
|
|
|
|
|
|
// Do we need to perform the conversion?
|
|
|
|
|
// Yes if to_file does not exist or if temp_file is newer than to_file
|
2004-06-22 15:26:55 +00:00
|
|
|
|
if (compare_timestamps(temp_file, to_file) < 0) {
|
2006-09-09 15:27:44 +00:00
|
|
|
|
// FIXME UNICODE
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS)
|
2006-10-21 00:16:43 +00:00
|
|
|
|
<< to_utf8(bformat(_("No conversion of %1$s is needed after all"),
|
|
|
|
|
from_utf8(rel_file)))
|
2003-09-03 17:23:38 +00:00
|
|
|
|
<< std::endl;
|
2006-03-28 18:49:46 +00:00
|
|
|
|
runparams.exportdata->addExternalFile(tex_format, to_file,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
output_to_file);
|
2004-06-10 08:44:40 +00:00
|
|
|
|
runparams.exportdata->addExternalFile("dvi", to_file,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
output_to_file);
|
2007-02-08 21:14:40 +00:00
|
|
|
|
return stripExtensionIfPossible(output_to_file, runparams.nice);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
}
|
2003-03-03 15:59:08 +00:00
|
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS)
|
2002-06-18 20:47:49 +00:00
|
|
|
|
<< "\tThe original file is " << orig_file << "\n"
|
|
|
|
|
<< "\tA copy has been made and convert is to be called with:\n"
|
2002-04-24 10:53:55 +00:00
|
|
|
|
<< "\tfile to convert = " << temp_file << '\n'
|
|
|
|
|
<< "\t from " << from << " to " << to << '\n';
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2006-08-13 16:16:43 +00:00
|
|
|
|
// FIXME (Abdel 12/08/06): Is there a need to show these errors?
|
|
|
|
|
ErrorList el;
|
2007-01-17 13:18:16 +00:00
|
|
|
|
if (theConverters().convert(&buf, temp_file, to_file, params().filename,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
from, to, el,
|
|
|
|
|
Converters::try_default | Converters::try_cache)) {
|
2006-03-28 18:49:46 +00:00
|
|
|
|
runparams.exportdata->addExternalFile(tex_format,
|
2005-01-14 08:52:35 +00:00
|
|
|
|
to_file, output_to_file);
|
|
|
|
|
runparams.exportdata->addExternalFile("dvi",
|
|
|
|
|
to_file, output_to_file);
|
2002-06-18 20:47:49 +00:00
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2007-02-08 21:14:40 +00:00
|
|
|
|
return stripExtensionIfPossible(output_to_file, runparams.nice);
|
2001-02-08 13:06:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-05-08 10:50:09 +00:00
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetGraphics::latex(Buffer const & buf, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2000-02-29 02:19:17 +00:00
|
|
|
|
{
|
2002-04-06 13:05:46 +00:00
|
|
|
|
// If there is no file specified or not existing,
|
2002-04-02 12:48:41 +00:00
|
|
|
|
// just output a message about it in the latex output.
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS)
|
2002-04-29 09:24:19 +00:00
|
|
|
|
<< "insetgraphics::latex: Filename = "
|
2003-07-22 20:42:40 +00:00
|
|
|
|
<< params().filename.absFilename() << endl;
|
2002-04-24 10:53:55 +00:00
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
string const relative_file =
|
2003-08-28 07:41:31 +00:00
|
|
|
|
params().filename.relFilename(buf.filePath());
|
2003-06-03 15:10:14 +00:00
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
bool const file_exists = !params().filename.empty() &&
|
2007-05-28 22:27:45 +00:00
|
|
|
|
isFileReadable(params().filename);
|
2002-05-21 23:50:36 +00:00
|
|
|
|
string const message = file_exists ?
|
2002-09-09 09:49:47 +00:00
|
|
|
|
string() : string("bb = 0 0 200 100, draft, type=eps");
|
2004-06-10 08:44:40 +00:00
|
|
|
|
// if !message.empty() then there was no existing file
|
2004-04-29 09:24:29 +00:00
|
|
|
|
// "filename" found. In this case LaTeX
|
2002-04-29 09:24:19 +00:00
|
|
|
|
// draws only a rectangle with the above bb and the
|
|
|
|
|
// not found filename in it.
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS)
|
2002-06-18 20:47:49 +00:00
|
|
|
|
<< "\tMessage = \"" << message << '\"' << endl;
|
2002-03-26 18:08:07 +00:00
|
|
|
|
|
2002-02-13 18:53:36 +00:00
|
|
|
|
// These variables collect all the latex code that should be before and
|
2001-02-08 13:06:55 +00:00
|
|
|
|
// after the actual includegraphics command.
|
|
|
|
|
string before;
|
|
|
|
|
string after;
|
2000-08-14 09:44:53 +00:00
|
|
|
|
// Do we want subcaptions?
|
2002-02-27 09:59:52 +00:00
|
|
|
|
if (params().subcaption) {
|
2006-03-24 13:45:33 +00:00
|
|
|
|
if (runparams.moving_arg)
|
|
|
|
|
before += "\\protect";
|
2002-02-27 09:59:52 +00:00
|
|
|
|
before += "\\subfigure[" + params().subcaptionText + "]{";
|
2002-02-13 18:53:36 +00:00
|
|
|
|
after = '}';
|
2000-08-14 09:44:53 +00:00
|
|
|
|
}
|
2006-03-24 13:45:33 +00:00
|
|
|
|
|
|
|
|
|
if (runparams.moving_arg)
|
|
|
|
|
before += "\\protect";
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2001-02-08 13:06:55 +00:00
|
|
|
|
// We never use the starred form, we use the "clip" option instead.
|
2002-02-13 18:53:36 +00:00
|
|
|
|
before += "\\includegraphics";
|
2002-04-02 12:48:41 +00:00
|
|
|
|
|
2001-02-08 13:06:55 +00:00
|
|
|
|
// Write the options if there are any.
|
|
|
|
|
string const opts = createLatexOptions();
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS) << "\tOpts = " << opts << endl;
|
2002-04-24 10:53:55 +00:00
|
|
|
|
|
2002-04-02 12:48:41 +00:00
|
|
|
|
if (!opts.empty() && !message.empty())
|
2005-02-08 17:15:17 +00:00
|
|
|
|
before += ('[' + opts + ',' + message + ']');
|
2002-09-09 09:49:47 +00:00
|
|
|
|
else if (!opts.empty() || !message.empty())
|
2005-02-08 17:15:17 +00:00
|
|
|
|
before += ('[' + opts + message + ']');
|
2002-04-24 10:53:55 +00:00
|
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS)
|
2002-06-18 20:47:49 +00:00
|
|
|
|
<< "\tBefore = " << before
|
|
|
|
|
<< "\n\tafter = " << after << endl;
|
2002-04-02 12:48:41 +00:00
|
|
|
|
|
2004-03-25 10:12:44 +00:00
|
|
|
|
string latex_str = before + '{';
|
2005-02-22 16:57:36 +00:00
|
|
|
|
// Convert the file if necessary.
|
|
|
|
|
// Remove the extension so LaTeX will use whatever is appropriate
|
|
|
|
|
// (when there are several versions in different formats)
|
2005-06-20 14:11:11 +00:00
|
|
|
|
latex_str += prepareFile(buf, runparams);
|
2004-03-25 10:12:44 +00:00
|
|
|
|
latex_str += '}' + after;
|
2006-10-19 16:51:30 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
os << from_utf8(latex_str);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS) << "InsetGraphics::latex outputting:\n"
|
2003-06-07 17:45:43 +00:00
|
|
|
|
<< latex_str << endl;
|
2001-02-08 13:06:55 +00:00
|
|
|
|
// Return how many newlines we issued.
|
2007-08-12 08:57:17 +00:00
|
|
|
|
return int(std::count(latex_str.begin(), latex_str.end(),'\n'));
|
2000-02-29 02:19:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-05-01 08:26:40 +00:00
|
|
|
|
int InsetGraphics::plaintext(Buffer const & buf, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const &) const
|
2000-04-24 20:58:23 +00:00
|
|
|
|
{
|
2001-02-08 13:06:55 +00:00
|
|
|
|
// No graphics in ascii output. Possible to use gifscii to convert
|
|
|
|
|
// images to ascii approximation.
|
|
|
|
|
// 1. Convert file to ascii using gifscii
|
|
|
|
|
// 2. Read ascii output file and add it to the output stream.
|
2002-01-31 14:20:09 +00:00
|
|
|
|
// at least we send the filename
|
2006-09-09 15:27:44 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-11 19:40:50 +00:00
|
|
|
|
// FIXME: We have no idea what the encoding of the filename is
|
2007-02-17 11:30:58 +00:00
|
|
|
|
|
2007-05-01 08:26:40 +00:00
|
|
|
|
docstring const str = bformat(buf.B_("Graphics file: %1$s"),
|
2007-05-28 22:27:45 +00:00
|
|
|
|
from_utf8(params().filename.absFilename()));
|
2007-02-17 11:30:58 +00:00
|
|
|
|
os << '<' << str << '>';
|
|
|
|
|
|
|
|
|
|
return 2 + str.size();
|
2000-04-24 20:58:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-10-21 22:55:04 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2007-08-10 20:14:54 +00:00
|
|
|
|
int writeImageObject(char const * format,
|
|
|
|
|
odocstream & os,
|
|
|
|
|
OutputParams const & runparams,
|
|
|
|
|
docstring const & graphic_label,
|
|
|
|
|
docstring const & attributes)
|
2004-10-21 22:55:04 +00:00
|
|
|
|
{
|
|
|
|
|
if (runparams.flavor != OutputParams::XML) {
|
2006-10-19 21:00:33 +00:00
|
|
|
|
os << "<![ %output.print."
|
2007-05-28 22:27:45 +00:00
|
|
|
|
<< format
|
|
|
|
|
<< "; ["
|
|
|
|
|
<< std::endl;
|
2004-10-21 22:55:04 +00:00
|
|
|
|
}
|
2004-10-26 18:39:13 +00:00
|
|
|
|
os <<"<imageobject><imagedata fileref=\"&"
|
2006-10-21 19:40:29 +00:00
|
|
|
|
<< graphic_label
|
2007-05-28 22:27:45 +00:00
|
|
|
|
<< ";."
|
|
|
|
|
<< format
|
|
|
|
|
<< "\" "
|
|
|
|
|
<< attributes;
|
2004-10-21 22:55:04 +00:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-02-08 13:06:55 +00:00
|
|
|
|
// For explanation on inserting graphics into DocBook checkout:
|
2004-06-01 13:39:33 +00:00
|
|
|
|
// http://en.tldp.org/LDP/LDP-Author-Guide/html/inserting-pictures.html
|
2001-02-08 13:06:55 +00:00
|
|
|
|
// See also the docbook guide at http://www.docbook.org/
|
2006-10-19 21:00:33 +00:00
|
|
|
|
int InsetGraphics::docbook(Buffer const &, odocstream & os,
|
2004-06-01 13:39:33 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
2002-03-21 17:09:55 +00:00
|
|
|
|
// 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
|
2001-02-08 13:06:55 +00:00
|
|
|
|
// easier to use.
|
2004-08-13 13:07:02 +00:00
|
|
|
|
if (runparams.flavor == OutputParams::XML) {
|
|
|
|
|
runparams.exportdata->addExternalFile("docbook-xml",
|
2006-11-26 21:30:39 +00:00
|
|
|
|
params().filename);
|
2004-08-13 13:07:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
runparams.exportdata->addExternalFile("docbook",
|
2006-11-26 21:30:39 +00:00
|
|
|
|
params().filename);
|
2004-08-13 13:07:02 +00:00
|
|
|
|
}
|
2004-10-21 22:55:04 +00:00
|
|
|
|
os << "<inlinemediaobject>";
|
2004-10-26 18:39:13 +00:00
|
|
|
|
|
2004-10-21 22:55:04 +00:00
|
|
|
|
int r = 0;
|
2006-10-21 19:40:29 +00:00
|
|
|
|
docstring attributes = createDocBookAttributes();
|
2004-10-21 22:55:04 +00:00
|
|
|
|
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);
|
2004-10-26 18:39:13 +00:00
|
|
|
|
|
2004-10-21 22:55:04 +00:00
|
|
|
|
os << "</inlinemediaobject>";
|
|
|
|
|
return r;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetGraphics::validate(LaTeXFeatures & features) const
|
2000-02-29 02:19:17 +00:00
|
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
|
// If we have no image, we should not require anything.
|
2002-02-27 09:59:52 +00:00
|
|
|
|
if (params().filename.empty())
|
2003-02-26 16:05:35 +00:00
|
|
|
|
return;
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
2003-07-22 20:42:40 +00:00
|
|
|
|
features.includeFile(graphic_label,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
removeExtension(params().filename.absFilename()));
|
2002-02-20 09:04:56 +00:00
|
|
|
|
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("graphicx");
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
2006-03-28 18:49:46 +00:00
|
|
|
|
if (features.runparams().nice) {
|
2004-04-26 11:05:19 +00:00
|
|
|
|
Buffer const * m_buffer = features.buffer().getMasterBuffer();
|
2006-10-21 19:37:53 +00:00
|
|
|
|
string const rel_file = removeExtension(params().filename.relFilename(m_buffer->filePath()));
|
|
|
|
|
if (contains(rel_file, "."))
|
2004-04-26 11:05:19 +00:00
|
|
|
|
features.require("lyxdot");
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
|
if (params().subcaption)
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("subfigure");
|
2000-02-29 02:19:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-05-08 10:50:09 +00:00
|
|
|
|
|
2003-06-03 15:10:14 +00:00
|
|
|
|
bool InsetGraphics::setParams(InsetGraphicsParams const & p)
|
2000-02-29 02:19:17 +00:00
|
|
|
|
{
|
2000-08-08 09:18:39 +00:00
|
|
|
|
// If nothing is changed, just return and say so.
|
2003-02-26 16:05:35 +00:00
|
|
|
|
if (params() == p && !p.filename.empty())
|
2000-08-14 09:44:53 +00:00
|
|
|
|
return false;
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
|
// Copy the new parameters.
|
2002-02-27 09:59:52 +00:00
|
|
|
|
params_ = p;
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
// Update the display using the new parameters.
|
|
|
|
|
graphic_->update(params().as_grfxParams());
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
|
|
// We have changed data, report it.
|
|
|
|
|
return true;
|
2000-02-29 02:19:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-05-08 10:50:09 +00:00
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
|
InsetGraphicsParams const & InsetGraphics::params() const
|
2000-07-31 12:30:10 +00:00
|
|
|
|
{
|
2002-02-27 09:59:52 +00:00
|
|
|
|
return params_;
|
2000-07-31 12:30:10 +00:00
|
|
|
|
}
|
2003-03-07 18:44:57 +00:00
|
|
|
|
|
|
|
|
|
|
2004-11-09 19:08:34 +00:00
|
|
|
|
void InsetGraphics::editGraphics(InsetGraphicsParams const & p,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
Buffer const & buffer) const
|
2004-04-13 10:36:09 +00:00
|
|
|
|
{
|
2006-11-26 21:30:39 +00:00
|
|
|
|
formats.edit(buffer, p.filename,
|
|
|
|
|
formats.getFormatFromFile(p.filename));
|
2004-04-13 10:36:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-07 18:44:57 +00:00
|
|
|
|
string const InsetGraphicsMailer::name_("graphics");
|
|
|
|
|
|
|
|
|
|
InsetGraphicsMailer::InsetGraphicsMailer(InsetGraphics & inset)
|
|
|
|
|
: inset_(inset)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-07-23 09:54:21 +00:00
|
|
|
|
string const InsetGraphicsMailer::inset2string(Buffer const & buffer) const
|
2003-03-07 18:44:57 +00:00
|
|
|
|
{
|
2003-07-23 09:54:21 +00:00
|
|
|
|
return params2string(inset_.params(), buffer);
|
2003-03-07 18:44:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetGraphicsMailer::string2params(string const & in,
|
2003-07-23 09:54:21 +00:00
|
|
|
|
Buffer const & buffer,
|
2003-07-25 17:11:25 +00:00
|
|
|
|
InsetGraphicsParams & params)
|
2003-03-07 18:44:57 +00:00
|
|
|
|
{
|
|
|
|
|
params = InsetGraphicsParams();
|
2003-04-24 20:02:49 +00:00
|
|
|
|
if (in.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
|
istringstream data(in);
|
2007-04-26 11:30:54 +00:00
|
|
|
|
Lexer lex(0,0);
|
2003-03-07 18:44:57 +00:00
|
|
|
|
lex.setStream(data);
|
|
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
|
string name;
|
|
|
|
|
lex >> name;
|
|
|
|
|
if (!lex || name != name_)
|
|
|
|
|
return print_mailer_error("InsetGraphicsMailer", in, 1, name_);
|
2003-03-07 18:44:57 +00:00
|
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
|
InsetGraphics inset;
|
|
|
|
|
inset.readInsetGraphics(lex, buffer.filePath());
|
|
|
|
|
params = inset.params();
|
2003-03-07 18:44:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const
|
2003-07-21 21:51:17 +00:00
|
|
|
|
InsetGraphicsMailer::params2string(InsetGraphicsParams const & params,
|
2003-07-23 09:54:21 +00:00
|
|
|
|
Buffer const & buffer)
|
2003-03-07 18:44:57 +00:00
|
|
|
|
{
|
|
|
|
|
ostringstream data;
|
|
|
|
|
data << name_ << ' ';
|
2007-09-05 17:50:07 +00:00
|
|
|
|
params.Write(data, buffer);
|
2003-03-07 18:44:57 +00:00
|
|
|
|
data << "\\end_inset\n";
|
2003-09-15 11:00:00 +00:00
|
|
|
|
return data.str();
|
2003-03-07 18:44:57 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|