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.
|
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.
|
|
|
|
|
*/
|
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"
|
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"
|
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"
|
2008-03-11 10:27:33 +00:00
|
|
|
|
#include "TocBackend.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
2007-04-28 20:44:46 +00:00
|
|
|
|
#include "frontends/alert.h"
|
2008-03-27 22:26:24 +00:00
|
|
|
|
#include "frontends/Application.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
|
#include "support/convert.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
|
#include "support/debug.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
|
#include "support/docstream.h"
|
2008-01-05 05:28:39 +00:00
|
|
|
|
#include "support/ExceptionMessage.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
#include "support/filetools.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
|
#include "support/gettext.h"
|
2007-11-30 09:23:44 +00:00
|
|
|
|
#include "support/lyxlib.h"
|
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>
|
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
|
using namespace lyx::support;
|
2006-10-19 16:51:30 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2008-01-05 05:28:39 +00:00
|
|
|
|
namespace Alert = frontend::Alert;
|
|
|
|
|
|
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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "findTargetFormat: PDF mode");
|
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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "findTargetFormat: PostScript mode");
|
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
|
|
|
|
}
|
|
|
|
|
|
2008-03-25 16:08:39 +00:00
|
|
|
|
|
|
|
|
|
void readInsetGraphics(Lexer & lex, string const & bufpath,
|
|
|
|
|
InsetGraphicsParams & params)
|
|
|
|
|
{
|
|
|
|
|
bool finished = false;
|
|
|
|
|
|
|
|
|
|
while (lex.isOK() && !finished) {
|
|
|
|
|
lex.next();
|
|
|
|
|
|
|
|
|
|
string const token = lex.getString();
|
|
|
|
|
LYXERR(Debug::GRAPHICS, "Token: '" << token << '\'');
|
|
|
|
|
|
|
|
|
|
if (token.empty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (token == "\\end_inset") {
|
|
|
|
|
finished = true;
|
|
|
|
|
} else {
|
|
|
|
|
if (!params.Read(lex, token, bufpath))
|
|
|
|
|
lyxerr << "Unknown token, " << token << ", skipping."
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-20 09:04:56 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2008-03-25 16:08:39 +00:00
|
|
|
|
InsetGraphics::InsetGraphics(Buffer & buf)
|
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))
|
2008-03-25 16:08:39 +00:00
|
|
|
|
{
|
|
|
|
|
Inset::setBuffer(buf);
|
|
|
|
|
}
|
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()
|
|
|
|
|
{
|
2008-03-27 22:26:24 +00:00
|
|
|
|
hideDialogs("graphics", this);
|
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: {
|
2008-03-24 04:27:43 +00:00
|
|
|
|
InsetGraphicsParams p = params();
|
|
|
|
|
if (!cmd.argument().empty())
|
2008-03-27 22:26:24 +00:00
|
|
|
|
string2params(to_utf8(cmd.argument()), buffer(), p);
|
2008-03-23 14:26:13 +00:00
|
|
|
|
editGraphics(p, buffer());
|
2004-04-13 10:36:09 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-07 18:44:57 +00:00
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
|
InsetGraphicsParams p;
|
2008-03-27 22:26:24 +00:00
|
|
|
|
string2params(to_utf8(cmd.argument()), buffer(), p);
|
2008-03-13 16:49:04 +00:00
|
|
|
|
if (!p.filename.empty())
|
2003-06-03 15:10:14 +00:00
|
|
|
|
setParams(p);
|
2008-03-13 16:49:04 +00:00
|
|
|
|
else
|
2005-05-09 17:29:22 +00:00
|
|
|
|
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:
|
2008-03-27 22:26:24 +00:00
|
|
|
|
cur.bv().updateDialog("graphics", params2string(params(),
|
|
|
|
|
cur.bv().buffer()));
|
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:
|
2008-03-25 10:54:38 +00:00
|
|
|
|
if (!cur.selection() && cmd.button() == mouse_button::button1)
|
2008-03-27 22:26:24 +00:00
|
|
|
|
cur.bv().showDialog("graphics", params2string(params(),
|
|
|
|
|
cur.bv().buffer()), this);
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-11 08:20:13 +00:00
|
|
|
|
void InsetGraphics::edit(Cursor & cur, bool, EntryDirection)
|
2003-11-04 12:36:59 +00:00
|
|
|
|
{
|
2008-03-27 22:26:24 +00:00
|
|
|
|
cur.bv().showDialog("graphics", params2string(params(),
|
2008-04-20 03:08:11 +00:00
|
|
|
|
cur.bv().buffer()), this);
|
2003-11-04 12:36:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
|
void 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);
|
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
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
void InsetGraphics::write(ostream & os) const
|
2000-02-29 02:19:17 +00:00
|
|
|
|
{
|
2002-08-24 22:02:30 +00:00
|
|
|
|
os << "Graphics\n";
|
2008-02-27 20:43:16 +00:00
|
|
|
|
params().Write(os, buffer());
|
2000-02-29 02:19:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
void InsetGraphics::read(Lexer & lex)
|
2001-07-28 12:24:16 +00:00
|
|
|
|
{
|
2008-04-05 10:34:29 +00:00
|
|
|
|
lex.setContext("InsetGraphics::read");
|
|
|
|
|
//lex >> "Graphics";
|
|
|
|
|
readInsetGraphics(lex, buffer().filePath(), params_);
|
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
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
|
string 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
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
|
docstring 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
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
|
|
|
|
|
|
docstring 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
|
|
|
|
|
2007-11-01 22:17:22 +00:00
|
|
|
|
// FIXME: av: need to translate spec -> Docbook XSL spec
|
|
|
|
|
// (http://www.sagehill.net/docbookxsl/ImageSizing.html)
|
2004-09-29 15:25:54 +00:00
|
|
|
|
// 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 {
|
|
|
|
|
|
2007-10-20 10:51:13 +00:00
|
|
|
|
enum GraphicsCopyStatus {
|
2003-09-03 17:23:38 +00:00
|
|
|
|
SUCCESS,
|
|
|
|
|
FAILURE,
|
|
|
|
|
IDENTICAL_PATHS,
|
|
|
|
|
IDENTICAL_CONTENTS
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
pair<GraphicsCopyStatus, FileName> const
|
2006-11-26 21:30:39 +00:00
|
|
|
|
copyFileIfNeeded(FileName const & file_in, FileName const & file_out)
|
2003-09-03 17:23:38 +00:00
|
|
|
|
{
|
2007-12-02 11:55:25 +00:00
|
|
|
|
LYXERR(Debug::FILES, "Comparing " << file_in << " and " << file_out);
|
2007-11-30 09:23:44 +00:00
|
|
|
|
unsigned long const checksum_in = file_in.checksum();
|
|
|
|
|
unsigned long const checksum_out = file_out.checksum();
|
2003-09-03 17:23:38 +00:00
|
|
|
|
|
|
|
|
|
if (checksum_in == checksum_out)
|
|
|
|
|
// Nothing to do...
|
2007-12-12 19:28:07 +00:00
|
|
|
|
return make_pair(IDENTICAL_CONTENTS, file_out);
|
2003-09-03 17:23:38 +00:00
|
|
|
|
|
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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS,
|
2007-12-12 19:57:42 +00:00
|
|
|
|
to_utf8(bformat(_("Could not copy the file\n%1$s\n"
|
2006-09-11 08:54:10 +00:00
|
|
|
|
"into the temporary directory."),
|
2007-11-15 20:04:51 +00:00
|
|
|
|
from_utf8(file_in.absFilename()))));
|
2003-09-03 17:23:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-20 10:51:13 +00:00
|
|
|
|
GraphicsCopyStatus status = success ? SUCCESS : FAILURE;
|
2007-12-12 19:28:07 +00:00
|
|
|
|
return make_pair(status, file_out);
|
2003-09-03 17:23:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
pair<GraphicsCopyStatus, 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
|
|
|
|
{
|
2006-07-08 14:16:56 +00:00
|
|
|
|
string const file_in = file.absFilename();
|
2007-12-12 19:57:42 +00:00
|
|
|
|
string const only_path = onlyPath(file_in);
|
|
|
|
|
if (rtrim(onlyPath(file_in) , "/") == rtrim(dir, "/"))
|
2007-12-12 19:28:07 +00:00
|
|
|
|
return make_pair(IDENTICAL_PATHS, file_in);
|
2004-05-05 15:37:36 +00:00
|
|
|
|
|
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] = '.';
|
|
|
|
|
}
|
2007-12-12 19:57:42 +00:00
|
|
|
|
FileName const file_out(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.
|
2007-12-12 19:57:42 +00:00
|
|
|
|
string const latex_name = latex_path(file, 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;
|
2007-12-12 19:57:42 +00:00
|
|
|
|
return latex_path(removeExtension(file), PROTECT_EXTENSION, 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);
|
2007-12-12 19:57:42 +00:00
|
|
|
|
return latex_path(file, EXCLUDE_EXTENSION);
|
2003-09-03 17:23:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
string InsetGraphics::prepareFile(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();
|
|
|
|
|
|
2008-04-20 03:08:11 +00:00
|
|
|
|
string const orig_file = params().filename.absFilename();
|
2008-01-07 03:34:21 +00:00
|
|
|
|
// this is for dryrun and display purposes, do not use latexFilename
|
2008-02-27 20:43:16 +00:00
|
|
|
|
string const rel_file = params().filename.relFilename(buffer().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.
|
2008-04-20 03:08:11 +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
|
2008-02-27 20:43:16 +00:00
|
|
|
|
Buffer const * masterBuffer = buffer().masterBuffer();
|
2004-06-10 08:44:40 +00:00
|
|
|
|
|
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.
|
2007-11-25 11:18:16 +00:00
|
|
|
|
if (runparams.inComment || !params().filename.isReadableFile())
|
2007-10-20 10:03:45 +00:00
|
|
|
|
return params().filename.outputFilename(masterBuffer->filePath());
|
2005-02-22 16:57:36 +00:00
|
|
|
|
|
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.
|
2007-10-20 10:03:45 +00:00
|
|
|
|
string const temp_path = masterBuffer->temppath();
|
2004-03-25 10:12:44 +00:00
|
|
|
|
|
2007-10-20 10:51:13 +00:00
|
|
|
|
GraphicsCopyStatus status;
|
2004-05-05 15:37:36 +00:00
|
|
|
|
boost::tie(status, temp_file) =
|
2008-04-20 03:08:11 +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
|
|
|
|
|
2007-09-30 12:38:08 +00:00
|
|
|
|
// a relative filename should be relative to the master buffer.
|
2004-06-10 08:44:40 +00:00
|
|
|
|
// "nice" means that the buffer is exported to LaTeX format but not
|
2007-09-30 12:38:08 +00:00
|
|
|
|
// run through the LaTeX compiler.
|
|
|
|
|
string output_file = runparams.nice ?
|
2007-10-20 10:03:45 +00:00
|
|
|
|
params().filename.outputFilename(masterBuffer->filePath()) :
|
2007-09-30 12:38:08 +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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tpass zipped file to LaTeX.");
|
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
|
2007-12-12 19:57:42 +00:00
|
|
|
|
return latex_path(output_file, 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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\twas already unzipped to " << temp_file);
|
2004-05-05 15:37:36 +00:00
|
|
|
|
} else {
|
|
|
|
|
// unzipped_temp_file does not exist or is too old
|
|
|
|
|
temp_file = unzipFile(temp_file);
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tunzipped to " << temp_file);
|
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);
|
2007-11-15 20:04:51 +00:00
|
|
|
|
if (from.empty())
|
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tCould not get file format.");
|
|
|
|
|
|
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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\t we have: from " << from << " to " << to);
|
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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tthe orig file is: " << orig_file);
|
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));
|
2007-12-14 18:16:25 +00:00
|
|
|
|
if (temp_file.moveTo(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));
|
2007-11-15 20:04:51 +00:00
|
|
|
|
} else {
|
|
|
|
|
LYXERR(Debug::GRAPHICS, "Could not rename file `"
|
|
|
|
|
<< temp_file << "' to `" << new_file << "'.");
|
|
|
|
|
}
|
2006-05-22 09:15:33 +00:00
|
|
|
|
}
|
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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS,
|
|
|
|
|
to_utf8(bformat(_("No conversion of %1$s is needed after all"),
|
|
|
|
|
from_utf8(rel_file))));
|
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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS,"\tThe original file is " << orig_file << "\n"
|
2002-06-18 20:47:49 +00:00
|
|
|
|
<< "\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'
|
2007-11-15 20:04:51 +00:00
|
|
|
|
<< "\t from " << from << " to " << to);
|
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;
|
2008-02-27 20:43:16 +00:00
|
|
|
|
if (theConverters().convert(&buffer(), 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
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetGraphics::latex(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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "insetgraphics::latex: Filename = "
|
|
|
|
|
<< params().filename.absFilename());
|
2002-04-24 10:53:55 +00:00
|
|
|
|
|
2007-10-18 23:03:51 +00:00
|
|
|
|
bool const file_exists = !params().filename.empty()
|
2007-11-25 11:18:16 +00:00
|
|
|
|
&& params().filename.isReadableFile();
|
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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tMessage = \"" << message << '\"');
|
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;
|
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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tOpts = " << opts);
|
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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tBefore = " << before << "\n\tafter = " << after);
|
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)
|
2008-02-27 20:43:16 +00:00
|
|
|
|
latex_str += prepareFile(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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "InsetGraphics::latex outputting:\n" << latex_str);
|
2001-02-08 13:06:55 +00:00
|
|
|
|
// Return how many newlines we issued.
|
2007-12-12 19:28:07 +00:00
|
|
|
|
return int(count(latex_str.begin(), latex_str.end(),'\n'));
|
2000-02-29 02:19:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetGraphics::plaintext(odocstream & os, 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
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
docstring const str = bformat(buffer().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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
static 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
|
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
|
if (runparams.flavor != OutputParams::XML)
|
|
|
|
|
os << "<![ %output.print." << format
|
2007-12-12 19:28:07 +00:00
|
|
|
|
<< "; [" << endl;
|
2007-11-15 20:04:51 +00:00
|
|
|
|
|
|
|
|
|
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)
|
2007-12-12 19:28:07 +00:00
|
|
|
|
os << endl << "]]>" ;
|
2007-11-15 20:04:51 +00:00
|
|
|
|
|
|
|
|
|
return runparams.flavor == OutputParams::XML ? 0 : 2;
|
2004-10-21 22:55:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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/
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetGraphics::docbook(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.
|
2007-11-15 20:04:51 +00:00
|
|
|
|
if (runparams.flavor == OutputParams::XML)
|
2004-08-13 13:07:02 +00:00
|
|
|
|
runparams.exportdata->addExternalFile("docbook-xml",
|
2006-11-26 21:30:39 +00:00
|
|
|
|
params().filename);
|
2007-11-15 20:04:51 +00:00
|
|
|
|
else
|
2004-08-13 13:07:02 +00:00
|
|
|
|
runparams.exportdata->addExternalFile("docbook",
|
2006-11-26 21:30:39 +00:00
|
|
|
|
params().filename);
|
2007-11-15 20:04:51 +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) {
|
2007-10-20 10:03:45 +00:00
|
|
|
|
Buffer const * masterBuffer = features.buffer().masterBuffer();
|
|
|
|
|
string const rel_file = removeExtension(params().filename.relFilename(masterBuffer->filePath()));
|
2006-10-21 19:37:53 +00:00
|
|
|
|
if (contains(rel_file, "."))
|
2004-04-26 11:05:19 +00:00
|
|
|
|
features.require("lyxdot");
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-11 10:27:33 +00:00
|
|
|
|
void InsetGraphics::addToToc(ParConstIterator const & cpit) const
|
|
|
|
|
{
|
|
|
|
|
TocBackend & backend = buffer().tocBackend();
|
|
|
|
|
|
2008-04-20 03:08:11 +00:00
|
|
|
|
docstring const str = params_.filename.displayName();
|
2008-03-11 10:27:33 +00:00
|
|
|
|
backend.toc("graphics").push_back(TocItem(cpit, 0, str));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-24 04:27:43 +00:00
|
|
|
|
docstring InsetGraphics::contextMenu(BufferView const &, int, int) const
|
|
|
|
|
{
|
|
|
|
|
return from_ascii("context-graphics");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
|
void InsetGraphics::string2params(string const & in, Buffer const & buffer,
|
|
|
|
|
InsetGraphicsParams & params)
|
2003-03-07 18:44:57 +00:00
|
|
|
|
{
|
2003-04-24 20:02:49 +00:00
|
|
|
|
if (in.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
|
istringstream data(in);
|
2008-04-02 23:06:22 +00:00
|
|
|
|
Lexer lex;
|
2003-03-07 18:44:57 +00:00
|
|
|
|
lex.setStream(data);
|
2008-04-05 10:34:29 +00:00
|
|
|
|
lex.setContext("InsetGraphics::string2params");
|
|
|
|
|
lex >> "graphics";
|
2008-03-25 16:08:39 +00:00
|
|
|
|
params = InsetGraphicsParams();
|
|
|
|
|
readInsetGraphics(lex, buffer.filePath(), params);
|
2003-03-07 18:44:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
|
string InsetGraphics::params2string(InsetGraphicsParams const & params,
|
|
|
|
|
Buffer const & buffer)
|
2003-03-07 18:44:57 +00:00
|
|
|
|
{
|
|
|
|
|
ostringstream data;
|
2008-03-27 22:26:24 +00:00
|
|
|
|
data << "graphics" << ' ';
|
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
|