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
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Herbert Voß
|
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"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "InsetIterator.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"
|
2009-12-03 19:52:46 +00:00
|
|
|
#include "output_xhtml.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
|
|
|
|
2008-09-20 07:38:28 +00:00
|
|
|
#include <boost/tuple/tuple.hpp>
|
|
|
|
|
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
|
|
|
{
|
2010-11-23 16:07:42 +00:00
|
|
|
// Are we using latex or XeTeX/LuaTeX/pdflatex?
|
2009-04-11 13:00:10 +00:00
|
|
|
if (runparams.flavor == OutputParams::PDFLATEX
|
2010-11-23 16:07:42 +00:00
|
|
|
|| runparams.flavor == OutputParams::XETEX
|
|
|
|
|| runparams.flavor == OutputParams::LUATEX) {
|
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())
|
2013-03-21 19:13:02 +00:00
|
|
|
return "pdf6";
|
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
|
|
|
}
|
2009-10-25 01:48:14 +00:00
|
|
|
// for HTML, we leave the known formats and otherwise convert to png
|
|
|
|
if (runparams.flavor == OutputParams::HTML) {
|
2015-05-27 15:25:06 +00:00
|
|
|
Format const * const f = formats.getFormat(format);
|
|
|
|
// Convert vector graphics to svg
|
|
|
|
if (f && f->vectorFormat() && theConverters().isReachable(format, "svg"))
|
|
|
|
return "svg";
|
|
|
|
// Leave the known formats alone
|
2009-10-25 01:48:14 +00:00
|
|
|
if (format == "jpg" || format == "png" || format == "gif")
|
|
|
|
return format;
|
2015-05-27 15:25:06 +00:00
|
|
|
// Convert everything else to png
|
2009-10-25 01:48:14 +00:00
|
|
|
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))
|
2008-04-30 20:22:48 +00:00
|
|
|
lyxerr << "Unknown token, "
|
|
|
|
<< token
|
|
|
|
<< ", skipping."
|
|
|
|
<< endl;
|
2008-03-25 16:08:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-20 09:04:56 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetGraphics::InsetGraphics(Buffer * buf)
|
|
|
|
: Inset(buf), 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
|
|
|
{
|
|
|
|
}
|
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),
|
2008-09-19 21:18:18 +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);
|
2008-09-19 21:18:18 +00:00
|
|
|
delete graphic_;
|
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
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2008-04-27 16:20:12 +00:00
|
|
|
case LFUN_INSET_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);
|
2009-07-13 13:53:58 +00:00
|
|
|
editGraphics(p);
|
2004-04-13 10:36:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-03-07 18:44:57 +00:00
|
|
|
case LFUN_INSET_MODIFY: {
|
2014-02-05 22:59:39 +00:00
|
|
|
if (cmd.getArg(0) != "graphics") {
|
|
|
|
Inset::doDispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-03-07 18:44:57 +00:00
|
|
|
InsetGraphicsParams p;
|
2008-03-27 22:26:24 +00:00
|
|
|
string2params(to_utf8(cmd.argument()), buffer(), p);
|
2008-09-25 13:24:52 +00:00
|
|
|
if (p.filename.empty()) {
|
2010-07-08 20:04:35 +00:00
|
|
|
cur.noScreenUpdate();
|
2008-09-25 13:24:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-12-08 09:24:04 +00:00
|
|
|
cur.recordUndo();
|
2008-09-25 13:24:52 +00:00
|
|
|
setParams(p);
|
|
|
|
// if the inset is part of a graphics group, all the
|
|
|
|
// other members should be updated too.
|
|
|
|
if (!params_.groupId.empty())
|
2008-11-17 11:46:07 +00:00
|
|
|
graphics::unifyGraphicsGroups(buffer(),
|
2008-09-25 13:24:52 +00:00
|
|
|
to_utf8(cmd.argument()));
|
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-11-17 11:46:07 +00:00
|
|
|
cur.bv().updateDialog("graphics", params2string(params(), buffer()));
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-03-07 18:44:57 +00:00
|
|
|
|
2009-08-13 17:21:59 +00:00
|
|
|
case LFUN_GRAPHICS_RELOAD:
|
2009-12-05 02:56:19 +00:00
|
|
|
params_.filename.refresh();
|
2009-08-13 17:21:59 +00:00
|
|
|
graphic_->reload();
|
|
|
|
break;
|
|
|
|
|
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
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2005-04-22 08:57:22 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
2014-05-18 09:11:38 +00:00
|
|
|
if (cmd.getArg(0) != "graphics")
|
2014-02-05 22:59:39 +00:00
|
|
|
return Inset::getStatus(cur, cmd, flag);
|
2014-05-18 15:27:54 +00:00
|
|
|
// fall through
|
2014-02-05 22:59:39 +00:00
|
|
|
case LFUN_INSET_EDIT:
|
2005-04-22 08:57:22 +00:00
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2009-08-13 17:21:59 +00:00
|
|
|
case LFUN_GRAPHICS_RELOAD:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(true);
|
2005-04-22 08:57:22 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-10 00:20:12 +00:00
|
|
|
bool InsetGraphics::showInsetDialog(BufferView * bv) const
|
|
|
|
{
|
|
|
|
bv->showDialog("graphics", params2string(params(), bv->buffer()),
|
|
|
|
const_cast<InsetGraphics *>(this));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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";
|
Correctly load documents moved elsewhere after save.
It is now possible opening documents that where manually moved to a
different location after they were saved and still produce an output.
Indeed, (hopefully) all needed included files are now still found.
When the moved document is saved again, all paths are accordingly updated.
Of course, for this to work, a document has to be saved in Format 490,
at least.
As an example, after converting the user guide to the last format, it can
be copied anywhere and opened without the need of adapting the paths of
included files or moving them to a proper place.
There is one glitch I am aware of. When moving a child document (but not
the master) the path to the master is correctly updated but it won't be
recognized as such. This is because LyX checks that the parent actually
includes this document but, of course, being the parent document not
touched, it appears not including this child. Anyway, it will also occur
when saving the child to a different location and the user is warned
on the terminal about this fact when the moved child is loaded.
However, there is no problem when it is the master that has been moved.
2015-05-16 17:51:53 +00:00
|
|
|
readInsetGraphics(lex, buffer().originFilePath(), 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;
|
2015-07-18 15:02:54 +00:00
|
|
|
if (!params().bbox.empty())
|
|
|
|
options << "bb=" << params().bbox.xl.asLatexString() << ' '
|
|
|
|
<< params().bbox.yb.asLatexString() << ' '
|
|
|
|
<< params().bbox.xr.asLatexString() << ' '
|
|
|
|
<< params().bbox.yt.asLatexString() << ',';
|
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
|
2010-08-13 00:17:12 +00:00
|
|
|
case Length::PPH: // Percent of PaperHeight
|
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."),
|
2010-04-21 01:19:09 +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
|
|
|
{
|
2010-04-21 01:19:09 +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, "/"))
|
2012-10-08 19:26:17 +00:00
|
|
|
return make_pair(IDENTICAL_PATHS, FileName(file_in));
|
2004-05-05 15:37:36 +00:00
|
|
|
|
2010-04-21 01:19:22 +00:00
|
|
|
string mangled = file.mangledFileName();
|
2011-09-19 00:12:09 +00:00
|
|
|
if (formats.isZippedFile(file)) {
|
2004-05-05 15:37:36 +00:00
|
|
|
// We need to change _eps.gz to .eps.gz. The mangled name is
|
2010-04-21 01:19:22 +00:00
|
|
|
// still unique because of the counter in mangledFileName().
|
|
|
|
// We can't just call mangledFileName() with the zip
|
2004-05-05 15:37:36 +00:00
|
|
|
// extension removed, because base.eps and base.eps.gz may
|
|
|
|
// have different content but would get the same mangled
|
|
|
|
// name in this case.
|
2010-04-21 01:19:26 +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();
|
|
|
|
|
2010-04-21 01:19:09 +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
|
2010-04-21 01:19:20 +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
|
|
|
|
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())
|
2010-04-21 01:19:25 +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
|
|
|
|
2009-10-25 02:22:36 +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.
|
|
|
|
FileName temp_file;
|
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 ?
|
2010-04-21 01:19:25 +00:00
|
|
|
params().filename.outputFileName(masterBuffer->filePath()) :
|
2010-04-21 01:19:28 +00:00
|
|
|
onlyFileName(temp_file.absFileName());
|
2007-06-26 16:55:42 +00:00
|
|
|
|
2010-09-27 03:21:59 +00:00
|
|
|
if (runparams.nice) {
|
2010-09-27 02:39:22 +00:00
|
|
|
if (!isValidLaTeXFileName(output_file)) {
|
|
|
|
frontend::Alert::warning(_("Invalid filename"),
|
2010-09-27 03:21:59 +00:00
|
|
|
_("The following filename will cause troubles "
|
|
|
|
"when running the exported file through LaTeX: ") +
|
|
|
|
from_utf8(output_file));
|
2010-09-27 02:39:22 +00:00
|
|
|
}
|
|
|
|
// only show DVI-specific warning when export format is plain latex
|
|
|
|
if (!isValidDVIFileName(output_file)
|
|
|
|
&& runparams.flavor == OutputParams::LATEX) {
|
2010-09-27 03:21:59 +00:00
|
|
|
frontend::Alert::warning(_("Problematic filename for DVI"),
|
2010-09-27 02:39:22 +00:00
|
|
|
_("The following filename can cause troubles "
|
|
|
|
"when running the exported file through LaTeX "
|
|
|
|
"and opening the resulting DVI: ") +
|
|
|
|
from_utf8(output_file), true);
|
|
|
|
}
|
2007-06-26 16:55:42 +00:00
|
|
|
}
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName source_file = runparams.nice ? FileName(params().filename) : temp_file;
|
2010-09-27 02:39:22 +00:00
|
|
|
// determine the export format
|
2011-04-14 18:32:42 +00:00
|
|
|
string const tex_format = flavor2format(runparams.flavor);
|
2004-06-10 08:44:40 +00:00
|
|
|
|
2011-09-19 00:12:09 +00:00
|
|
|
if (formats.isZippedFile(params().filename)) {
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName const unzipped_temp_file =
|
2010-04-21 01:19:09 +00:00
|
|
|
FileName(unzippedFileName(temp_file.absFileName()));
|
2006-04-08 09:11:25 +00:00
|
|
|
output_file = unzippedFileName(output_file);
|
2010-04-21 01:19:09 +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) {
|
2009-10-25 02:22:36 +00:00
|
|
|
// source and destination formats are the same
|
2008-10-05 11:51:18 +00:00
|
|
|
if (!runparams.nice && !FileName(temp_file).hasExtension(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.
|
2008-04-30 20:22:48 +00:00
|
|
|
FileName const new_file =
|
2010-04-21 01:19:09 +00:00
|
|
|
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);
|
2008-04-30 20:22:48 +00:00
|
|
|
source_file =
|
2010-04-21 01:19:09 +00:00
|
|
|
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
|
|
|
|
2009-10-25 02:22:36 +00:00
|
|
|
// so the source and destination formats are different
|
2010-04-21 01:19:09 +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
|
|
|
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetGraphics::latex(otexstream & os,
|
|
|
|
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 = "
|
2010-04-21 01:19:09 +00:00
|
|
|
<< 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();
|
2011-11-27 20:12:32 +00:00
|
|
|
string message;
|
|
|
|
if (!file_exists) {
|
2015-07-18 15:02:54 +00:00
|
|
|
if (params().bbox.empty())
|
2011-11-27 20:12:32 +00:00
|
|
|
message = "bb = 0 0 200 100";
|
|
|
|
if (!params().draft) {
|
|
|
|
if (!message.empty())
|
|
|
|
message += ", ";
|
|
|
|
message += "draft";
|
|
|
|
}
|
|
|
|
if (!message.empty())
|
|
|
|
message += ", ";
|
|
|
|
message += "type=eps";
|
|
|
|
}
|
|
|
|
// If no existing file "filename" was found 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)
|
2011-09-15 01:07:49 +00:00
|
|
|
string file_path = prepareFile(runparams);
|
|
|
|
latex_str += file_path;
|
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);
|
2000-02-29 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
int InsetGraphics::plaintext(odocstringstream & os,
|
|
|
|
OutputParams const &, size_t) 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"),
|
2010-04-21 01:19:09 +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
|
|
|
|
2009-11-14 14:00:18 +00:00
|
|
|
string InsetGraphics::prepareHTMLFile(OutputParams const & runparams) const
|
|
|
|
{
|
|
|
|
// The following code depends on non-empty filenames
|
|
|
|
if (params().filename.empty())
|
|
|
|
return string();
|
|
|
|
|
2010-04-21 01:19:09 +00:00
|
|
|
string const orig_file = params().filename.absFileName();
|
2009-11-14 14:00:18 +00:00
|
|
|
|
|
|
|
// The master buffer. This is useful when there are multiple levels
|
|
|
|
// of include files
|
|
|
|
Buffer const * masterBuffer = buffer().masterBuffer();
|
|
|
|
|
|
|
|
if (!params().filename.isReadableFile())
|
|
|
|
return string();
|
|
|
|
|
|
|
|
// We place all temporary files in the master buffer's temp dir.
|
|
|
|
// This is possible because we use mangled file names.
|
|
|
|
// FIXME We may want to put these files in some special temporary
|
|
|
|
// directory.
|
|
|
|
string const temp_path = masterBuffer->temppath();
|
|
|
|
|
|
|
|
// Copy to temporary directory.
|
|
|
|
FileName temp_file;
|
|
|
|
GraphicsCopyStatus status;
|
|
|
|
boost::tie(status, temp_file) =
|
|
|
|
copyToDirIfNeeded(params().filename, temp_path);
|
|
|
|
|
|
|
|
if (status == FAILURE)
|
|
|
|
return string();
|
|
|
|
|
2010-04-21 01:19:28 +00:00
|
|
|
string output_file = onlyFileName(temp_file.absFileName());
|
2009-11-14 14:00:18 +00:00
|
|
|
|
|
|
|
string const from = formats.getFormatFromFile(temp_file);
|
|
|
|
if (from.empty())
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tCould not get file format.");
|
|
|
|
|
|
|
|
string const to = findTargetFormat(from, runparams);
|
|
|
|
string const ext = formats.extension(to);
|
|
|
|
LYXERR(Debug::GRAPHICS, "\t we have: from " << from << " to " << to);
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tthe orig file is: " << orig_file);
|
|
|
|
|
|
|
|
if (from == to) {
|
|
|
|
// source and destination formats are the same
|
|
|
|
runparams.exportdata->addExternalFile("xhtml", temp_file, output_file);
|
|
|
|
return output_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
// so the source and destination formats are different
|
2010-04-21 01:19:09 +00:00
|
|
|
FileName const to_file = FileName(changeExtension(temp_file.absFileName(), ext));
|
2009-11-14 14:00:18 +00:00
|
|
|
string const output_to_file = changeExtension(output_file, ext);
|
|
|
|
|
|
|
|
// Do we need to perform the conversion?
|
|
|
|
// Yes if to_file does not exist or if temp_file is newer than to_file
|
|
|
|
if (compare_timestamps(temp_file, to_file) < 0) {
|
|
|
|
// FIXME UNICODE
|
|
|
|
LYXERR(Debug::GRAPHICS,
|
|
|
|
to_utf8(bformat(_("No conversion of %1$s is needed after all"),
|
|
|
|
from_utf8(orig_file))));
|
|
|
|
runparams.exportdata->addExternalFile("xhtml", to_file, output_to_file);
|
|
|
|
return output_to_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
LYXERR(Debug::GRAPHICS,"\tThe original file is " << orig_file << "\n"
|
|
|
|
<< "\tA copy has been made and convert is to be called with:\n"
|
|
|
|
<< "\tfile to convert = " << temp_file << '\n'
|
|
|
|
<< "\t from " << from << " to " << to);
|
|
|
|
|
|
|
|
// FIXME (Abdel 12/08/06): Is there a need to show these errors?
|
|
|
|
ErrorList el;
|
|
|
|
bool const success =
|
|
|
|
theConverters().convert(&buffer(), temp_file, to_file, params().filename,
|
|
|
|
from, to, el, Converters::try_default | Converters::try_cache);
|
|
|
|
if (!success)
|
|
|
|
return string();
|
|
|
|
runparams.exportdata->addExternalFile("xhtml", to_file, output_to_file);
|
|
|
|
return output_to_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-03 19:52:46 +00:00
|
|
|
docstring InsetGraphics::xhtml(XHTMLStream & xs, OutputParams const & op) const
|
2009-11-14 14:00:18 +00:00
|
|
|
{
|
2009-12-03 19:52:46 +00:00
|
|
|
string const output_file = prepareHTMLFile(op);
|
2011-02-07 23:47:43 +00:00
|
|
|
|
2009-11-14 14:00:18 +00:00
|
|
|
if (output_file.empty()) {
|
2009-12-03 19:52:46 +00:00
|
|
|
LYXERR0("InsetGraphics::xhtml: Unable to prepare file `"
|
|
|
|
<< params().filename << "' for output. File missing?");
|
2010-04-21 01:19:09 +00:00
|
|
|
string const attr = "src='" + params().filename.absFileName()
|
2009-12-03 19:52:46 +00:00
|
|
|
+ "' alt='image: " + output_file + "'";
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << html::CompTag("img", attr);
|
2009-11-14 14:00:18 +00:00
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
2009-12-03 19:52:46 +00:00
|
|
|
// FIXME XHTML
|
2011-02-07 23:47:43 +00:00
|
|
|
// We aren't doing anything with the crop and rotate parameters, and it would
|
|
|
|
// really be better to do width and height conversion, rather than to output
|
|
|
|
// these parameters here.
|
|
|
|
string imgstyle;
|
|
|
|
if (!params().width.zero())
|
|
|
|
imgstyle += "width:" + params().width.asHTMLString() + ";";
|
|
|
|
if (!params().height.zero())
|
|
|
|
imgstyle += " height:" + params().height.asHTMLString() + ";";
|
|
|
|
if (!imgstyle.empty())
|
|
|
|
imgstyle = "style='" + imgstyle + "' ";
|
|
|
|
|
|
|
|
string const attr = imgstyle + "src='" + output_file + "' alt='image: "
|
2009-12-03 19:52:46 +00:00
|
|
|
+ output_file + "'";
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << html::CompTag("img", attr);
|
2009-11-14 14:00:18 +00:00
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
2010-04-21 01:19:09 +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) {
|
2011-10-31 20:27:21 +00:00
|
|
|
string const rel_file = params().filename.onlyFileNameWithoutExt();
|
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
|
|
|
|
|
|
|
|
2009-07-13 13:53:58 +00:00
|
|
|
void InsetGraphics::editGraphics(InsetGraphicsParams const & p) const
|
2004-04-13 10:36:09 +00:00
|
|
|
{
|
2009-07-13 13:53:58 +00:00
|
|
|
formats.edit(buffer(), p.filename,
|
2006-11-26 21:30:39 +00:00
|
|
|
formats.getFormatFromFile(p.filename));
|
2004-04-13 10:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 21:18:26 +00:00
|
|
|
void InsetGraphics::addToToc(DocIterator const & cpit, bool output_active) const
|
2008-03-11 10:27:33 +00:00
|
|
|
{
|
2008-05-05 06:56:43 +00:00
|
|
|
//FIXME UNICODE
|
|
|
|
docstring const str = from_utf8(params_.filename.onlyFileName());
|
2015-09-01 16:08:35 +00:00
|
|
|
buffer().tocBackend().toc("graphics")->push_back(TocItem(cpit, 0, str, output_active));
|
2008-03-11 10:27:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-29 14:48:55 +00:00
|
|
|
string InsetGraphics::contextMenuName() const
|
2008-03-24 04:27:43 +00:00
|
|
|
{
|
2011-10-29 14:48:55 +00:00
|
|
|
return "context-graphics";
|
2008-03-24 04:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2012-02-25 23:05:28 +00:00
|
|
|
|
|
|
|
docstring InsetGraphics::toolTip(BufferView const &, int, int) const
|
|
|
|
{
|
2012-02-26 23:09:25 +00:00
|
|
|
return from_utf8(params().filename.onlyFileName());
|
2012-02-25 23:05:28 +00:00
|
|
|
}
|
|
|
|
|
2008-05-27 12:06:34 +00:00
|
|
|
namespace graphics {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2008-06-18 18:27:45 +00:00
|
|
|
void getGraphicsGroups(Buffer const & b, set<string> & ids)
|
2008-05-06 21:13:09 +00:00
|
|
|
{
|
|
|
|
Inset & inset = b.inset();
|
|
|
|
InsetIterator it = inset_iterator_begin(inset);
|
|
|
|
InsetIterator const end = inset_iterator_end(inset);
|
|
|
|
for (; it != end; ++it)
|
|
|
|
if (it->lyxCode() == GRAPHICS_CODE) {
|
|
|
|
InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
|
|
|
|
InsetGraphicsParams inspar = ins.getParams();
|
2008-05-07 23:40:59 +00:00
|
|
|
if (!inspar.groupId.empty())
|
2008-05-06 21:13:09 +00:00
|
|
|
ids.insert(inspar.groupId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-17 08:02:52 +00:00
|
|
|
int countGroupMembers(Buffer const & b, string const & groupId)
|
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
if (groupId.empty())
|
|
|
|
return n;
|
|
|
|
Inset & inset = b.inset();
|
|
|
|
InsetIterator it = inset_iterator_begin(inset);
|
|
|
|
InsetIterator const end = inset_iterator_end(inset);
|
|
|
|
for (; it != end; ++it)
|
|
|
|
if (it->lyxCode() == GRAPHICS_CODE) {
|
|
|
|
InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
|
|
|
|
if (ins.getParams().groupId == groupId)
|
|
|
|
++n;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-18 18:27:45 +00:00
|
|
|
string getGroupParams(Buffer const & b, string const & groupId)
|
2008-05-06 21:13:09 +00:00
|
|
|
{
|
2008-05-07 23:40:59 +00:00
|
|
|
if (groupId.empty())
|
|
|
|
return string();
|
2008-05-06 21:13:09 +00:00
|
|
|
Inset & inset = b.inset();
|
|
|
|
InsetIterator it = inset_iterator_begin(inset);
|
|
|
|
InsetIterator const end = inset_iterator_end(inset);
|
|
|
|
for (; it != end; ++it)
|
|
|
|
if (it->lyxCode() == GRAPHICS_CODE) {
|
|
|
|
InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
|
|
|
|
InsetGraphicsParams inspar = ins.getParams();
|
|
|
|
if (inspar.groupId == groupId) {
|
|
|
|
InsetGraphicsParams tmp = inspar;
|
|
|
|
tmp.filename.erase();
|
2008-05-27 12:06:34 +00:00
|
|
|
return InsetGraphics::params2string(tmp, b);
|
2008-05-06 21:13:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
2008-05-07 14:44:58 +00:00
|
|
|
|
2008-09-17 14:54:37 +00:00
|
|
|
void unifyGraphicsGroups(Buffer & b, string const & argument)
|
2008-05-06 21:13:09 +00:00
|
|
|
{
|
2008-05-07 14:44:58 +00:00
|
|
|
InsetGraphicsParams params;
|
|
|
|
InsetGraphics::string2params(argument, b, params);
|
|
|
|
|
2008-09-17 14:54:37 +00:00
|
|
|
b.undo().beginUndoGroup();
|
2008-05-07 14:44:58 +00:00
|
|
|
Inset & inset = b.inset();
|
|
|
|
InsetIterator it = inset_iterator_begin(inset);
|
|
|
|
InsetIterator const end = inset_iterator_end(inset);
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (it->lyxCode() == GRAPHICS_CODE) {
|
|
|
|
InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
|
|
|
|
InsetGraphicsParams inspar = ins.getParams();
|
|
|
|
if (params.groupId == inspar.groupId) {
|
2012-07-15 16:16:09 +00:00
|
|
|
b.undo().recordUndo(CursorData(it));
|
2008-05-07 14:44:58 +00:00
|
|
|
params.filename = inspar.filename;
|
|
|
|
ins.setParams(params);
|
2008-05-06 21:13:09 +00:00
|
|
|
}
|
2008-05-07 14:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-17 14:54:37 +00:00
|
|
|
b.undo().endUndoGroup();
|
2008-05-06 21:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-27 12:06:34 +00:00
|
|
|
InsetGraphics * getCurrentGraphicsInset(Cursor const & cur)
|
2008-05-07 14:44:58 +00:00
|
|
|
{
|
|
|
|
Inset * instmp = &cur.inset();
|
2008-05-07 23:40:59 +00:00
|
|
|
if (instmp->lyxCode() != GRAPHICS_CODE)
|
|
|
|
instmp = cur.nextInset();
|
|
|
|
if (!instmp || instmp->lyxCode() != GRAPHICS_CODE)
|
|
|
|
return 0;
|
2008-05-07 14:44:58 +00:00
|
|
|
|
2008-05-07 23:40:59 +00:00
|
|
|
return static_cast<InsetGraphics *>(instmp);
|
2008-05-07 14:44:58 +00:00
|
|
|
}
|
|
|
|
|
2008-05-27 12:06:34 +00:00
|
|
|
} // namespace graphics
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|