2007-09-20 23:29:20 +00:00
|
|
|
/**
|
|
|
|
* \file PDFoptions.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Pavel Sanda
|
2010-03-01 17:39:41 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
2007-09-20 23:29:20 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2007-09-21 09:49:50 +00:00
|
|
|
#include <config.h>
|
2007-09-20 23:29:20 +00:00
|
|
|
|
2007-09-21 01:51:08 +00:00
|
|
|
#include "PDFOptions.h"
|
2007-09-20 23:29:20 +00:00
|
|
|
|
2010-03-01 17:39:41 +00:00
|
|
|
#include "Encoding.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "Lexer.h"
|
|
|
|
|
2007-09-21 01:51:08 +00:00
|
|
|
#include "support/convert.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/lstrings.h"
|
2007-09-20 23:29:20 +00:00
|
|
|
|
2007-09-21 09:49:50 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2010-04-22 11:45:34 +00:00
|
|
|
#include <algorithm>
|
2007-09-20 23:29:20 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2007-09-20 23:29:20 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
namespace lyx {
|
2007-09-20 23:29:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
const string PDFOptions::pagemode_fullscreen("FullScreen");
|
|
|
|
|
|
|
|
bool PDFOptions::empty() const
|
|
|
|
{
|
2007-09-23 19:17:22 +00:00
|
|
|
PDFOptions x; //implicit hyperref settings
|
|
|
|
|
|
|
|
return author == x.author
|
|
|
|
&& title == x.title
|
|
|
|
&& subject == x.subject
|
|
|
|
&& keywords == x.keywords
|
|
|
|
&& pagemode == x.pagemode
|
|
|
|
&& quoted_options == x.quoted_options
|
|
|
|
&& bookmarks == x.bookmarks
|
|
|
|
&& bookmarksnumbered == x.bookmarksnumbered
|
|
|
|
&& bookmarksopen == x.bookmarksopen
|
|
|
|
&& bookmarksopenlevel == x.bookmarksopenlevel
|
|
|
|
&& breaklinks == x.breaklinks
|
|
|
|
&& pdfborder == x.pdfborder
|
|
|
|
&& colorlinks == x.colorlinks
|
|
|
|
&& backref == x.backref
|
2007-10-10 00:34:23 +00:00
|
|
|
&& pdfusetitle == x.pdfusetitle;
|
2007-09-20 23:29:20 +00:00
|
|
|
}
|
|
|
|
|
2008-01-19 11:17:12 +00:00
|
|
|
|
2007-09-20 23:29:20 +00:00
|
|
|
void PDFOptions::writeFile(ostream & os) const
|
|
|
|
{
|
2007-09-21 02:01:30 +00:00
|
|
|
os << "\\use_hyperref " << convert<string>(use_hyperref) << '\n';
|
2007-10-10 00:34:23 +00:00
|
|
|
if (!use_hyperref && empty())
|
2007-09-21 09:49:50 +00:00
|
|
|
return;
|
2007-09-21 02:01:30 +00:00
|
|
|
|
|
|
|
if (!title.empty() )
|
2007-09-21 09:49:50 +00:00
|
|
|
os << "\\pdf_title \"" << title << "\"\n";
|
2007-09-21 02:01:30 +00:00
|
|
|
if (!author.empty())
|
2007-09-21 09:49:50 +00:00
|
|
|
os << "\\pdf_author \"" << author << "\"\n";
|
2007-09-21 02:01:30 +00:00
|
|
|
if (!subject.empty())
|
2007-09-21 09:49:50 +00:00
|
|
|
os << "\\pdf_subject \"" << subject << "\"\n";
|
2007-09-21 02:01:30 +00:00
|
|
|
if (!keywords.empty())
|
2007-09-21 09:49:50 +00:00
|
|
|
os << "\\pdf_keywords \"" << keywords << "\"\n";
|
2007-09-21 02:01:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
os << "\\pdf_bookmarks " << convert<string>(bookmarks) << '\n';
|
|
|
|
os << "\\pdf_bookmarksnumbered " << convert<string>(bookmarksnumbered) << '\n';
|
|
|
|
os << "\\pdf_bookmarksopen " << convert<string>(bookmarksopen) << '\n';
|
2007-10-11 23:02:33 +00:00
|
|
|
os << "\\pdf_bookmarksopenlevel " << bookmarksopenlevel << '\n';
|
2007-09-21 02:01:30 +00:00
|
|
|
|
|
|
|
os << "\\pdf_breaklinks " << convert<string>(breaklinks) << '\n';
|
|
|
|
os << "\\pdf_pdfborder " << convert<string>(pdfborder) << '\n';
|
|
|
|
os << "\\pdf_colorlinks " << convert<string>(colorlinks) << '\n';
|
2008-10-13 16:01:02 +00:00
|
|
|
os << "\\pdf_backref " << backref << '\n';
|
2007-10-10 00:34:23 +00:00
|
|
|
os << "\\pdf_pdfusetitle " << convert<string>(pdfusetitle) << '\n';
|
2007-09-21 02:01:30 +00:00
|
|
|
|
|
|
|
if (!pagemode.empty())
|
2007-09-21 09:49:50 +00:00
|
|
|
os << "\\pdf_pagemode " << pagemode << '\n';
|
2007-09-21 02:01:30 +00:00
|
|
|
|
|
|
|
if (!quoted_options.empty())
|
2007-09-21 09:49:50 +00:00
|
|
|
os << "\\pdf_quoted_options \"" << quoted_options << "\"\n";
|
2007-09-20 23:29:20 +00:00
|
|
|
}
|
|
|
|
|
2008-01-19 11:17:12 +00:00
|
|
|
|
2011-02-13 21:41:44 +00:00
|
|
|
void PDFOptions::writeLaTeX(OutputParams & runparams, otexstream & os,
|
2010-03-01 17:39:41 +00:00
|
|
|
bool hyperref_already_provided) const
|
2007-09-20 23:29:20 +00:00
|
|
|
{
|
2010-03-01 17:39:41 +00:00
|
|
|
// FIXME Unicode
|
2007-09-21 02:01:30 +00:00
|
|
|
string opt;
|
2010-11-19 04:21:24 +00:00
|
|
|
string hyperset;
|
2007-09-21 02:01:30 +00:00
|
|
|
|
2007-10-03 18:58:02 +00:00
|
|
|
// since LyX uses unicode, also set the PDF strings to unicode strings with the
|
|
|
|
// hyperref option "unicode"
|
2010-11-19 04:21:24 +00:00
|
|
|
opt += "unicode=true,";
|
|
|
|
|
|
|
|
// only use the hyperref settings if hyperref is enabled by the user
|
|
|
|
// see bug #7052
|
2011-03-08 13:00:48 +00:00
|
|
|
if (use_hyperref) {
|
2010-11-19 04:21:24 +00:00
|
|
|
// try to extract author and title from document when none is
|
|
|
|
// explicitly given
|
|
|
|
if (pdfusetitle && title.empty() && author.empty())
|
|
|
|
opt += "pdfusetitle,";
|
|
|
|
opt += "\n ";
|
|
|
|
opt += "bookmarks=" + convert<string>(bookmarks) + ',';
|
|
|
|
if (bookmarks) {
|
|
|
|
opt += "bookmarksnumbered=" + convert<string>(bookmarksnumbered) + ',';
|
|
|
|
opt += "bookmarksopen=" + convert<string>(bookmarksopen) + ',';
|
|
|
|
if (bookmarksopen)
|
|
|
|
opt += "bookmarksopenlevel="
|
|
|
|
+ convert<string>(bookmarksopenlevel) + ',';
|
|
|
|
}
|
|
|
|
opt += "\n ";
|
|
|
|
opt += "breaklinks=" + convert<string>(breaklinks) + ',';
|
|
|
|
opt += "pdfborder={0 0 ";
|
|
|
|
opt += (pdfborder ? '0' : '1');
|
|
|
|
opt += "},";
|
|
|
|
opt += "backref=" + backref + ',';
|
|
|
|
opt += "colorlinks=" + convert<string>(colorlinks) + ',';
|
|
|
|
if (!pagemode.empty())
|
|
|
|
opt += "pdfpagemode=" + pagemode + ',';
|
|
|
|
|
|
|
|
// load the pdftitle etc. as hypersetup, otherwise you'll get
|
|
|
|
// LaTeX-errors when using non-latin characters
|
|
|
|
if (!title.empty())
|
|
|
|
hyperset += "pdftitle={" + title + "},";
|
|
|
|
if (!author.empty())
|
|
|
|
hyperset += "\n pdfauthor={" + author + "},";
|
|
|
|
if (!subject.empty())
|
|
|
|
hyperset += "\n pdfsubject={" + subject + "},";
|
|
|
|
if (!keywords.empty())
|
|
|
|
hyperset += "\n pdfkeywords={" + keywords + "},";
|
|
|
|
if (!quoted_options.empty()){
|
|
|
|
hyperset += "\n ";
|
|
|
|
hyperset += quoted_options;
|
|
|
|
}
|
|
|
|
hyperset = rtrim(hyperset,",");
|
2007-10-03 19:33:39 +00:00
|
|
|
}
|
2008-01-24 01:20:51 +00:00
|
|
|
|
2010-03-01 17:39:41 +00:00
|
|
|
// check if the hyperref settings use an encoding that exceeds
|
|
|
|
// ours. If so, we have to switch to utf8.
|
|
|
|
Encoding const * const enc = runparams.encoding;
|
|
|
|
docstring const hs = from_utf8(hyperset);
|
|
|
|
bool need_unicode = false;
|
|
|
|
if (enc) {
|
|
|
|
for (size_t n = 0; n < hs.size(); ++n) {
|
2012-03-25 13:36:00 +00:00
|
|
|
if (!enc->encodable(hs[n]))
|
2010-03-01 17:39:41 +00:00
|
|
|
need_unicode = true;
|
|
|
|
}
|
|
|
|
}
|
2008-01-24 01:20:51 +00:00
|
|
|
|
|
|
|
// use in \\usepackage parameter as not all options can be handled inside \\hypersetup
|
|
|
|
if (!hyperref_already_provided) {
|
2010-03-01 17:39:41 +00:00
|
|
|
opt = rtrim(opt, ",");
|
2008-01-24 01:20:51 +00:00
|
|
|
opt = "\\usepackage[" + opt + "]\n {hyperref}\n";
|
|
|
|
|
|
|
|
if (!hyperset.empty())
|
2010-03-01 17:39:41 +00:00
|
|
|
opt += "\\hypersetup{" + hyperset + "}\n";
|
2010-11-19 04:21:24 +00:00
|
|
|
} else {
|
2008-01-24 01:20:51 +00:00
|
|
|
// only in case hyperref is already loaded by the current text class
|
|
|
|
// try to put it into hyperset
|
|
|
|
//
|
2010-11-19 04:21:24 +00:00
|
|
|
// FIXME: rename in this case the PDF settings dialog checkbox
|
|
|
|
// label from "Use Hyperref" to "Customize Hyperref Settings"
|
|
|
|
// as discussd in bug #6293
|
2011-04-18 10:55:11 +00:00
|
|
|
opt = "\\hypersetup{" + rtrim(opt + hyperset, ",") + "}\n";
|
2010-11-19 04:21:24 +00:00
|
|
|
}
|
2010-03-01 17:39:41 +00:00
|
|
|
|
|
|
|
// hyperref expects utf8!
|
2010-11-29 09:03:55 +00:00
|
|
|
if (need_unicode && enc && enc->iconvName() != "UTF-8"
|
|
|
|
&&!runparams.isFullUnicode()) {
|
2010-03-01 17:39:41 +00:00
|
|
|
os << "\\inputencoding{utf8}\n"
|
|
|
|
<< setEncoding("UTF-8");
|
|
|
|
}
|
2011-03-08 13:15:26 +00:00
|
|
|
// If hyperref is loaded by the document class, we output
|
2011-04-18 10:55:11 +00:00
|
|
|
// \hypersetup \AtBeginDocument if hypersetup is not (yet)
|
|
|
|
// defined. In this case, the class loads hyperref late
|
|
|
|
// (see bug #7048).
|
|
|
|
if (hyperref_already_provided && !opt.empty()) {
|
|
|
|
os << "\\ifx\\hypersetup\\undefined\n"
|
|
|
|
<< " \\AtBeginDocument{%\n "
|
|
|
|
<< from_utf8(opt)
|
|
|
|
<< " }\n"
|
|
|
|
<< "\\else\n "
|
|
|
|
<< from_utf8(opt)
|
|
|
|
<< "\\fi\n";
|
|
|
|
} else
|
|
|
|
os << from_utf8(opt);
|
2010-11-19 04:21:24 +00:00
|
|
|
|
2010-11-29 09:03:55 +00:00
|
|
|
if (need_unicode && enc && enc->iconvName() != "UTF-8"
|
|
|
|
&&!runparams.isFullUnicode()) {
|
2010-03-01 17:39:41 +00:00
|
|
|
os << setEncoding(enc->iconvName())
|
|
|
|
<< "\\inputencoding{" << from_ascii(enc->latexName()) << "}\n";
|
|
|
|
}
|
2007-09-20 23:29:20 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 09:49:50 +00:00
|
|
|
|
2007-09-20 23:29:20 +00:00
|
|
|
string PDFOptions::readToken(Lexer &lex, string const & token)
|
|
|
|
{
|
2007-09-21 02:01:30 +00:00
|
|
|
if (token == "\\use_hyperref") {
|
2007-09-21 09:49:50 +00:00
|
|
|
lex >> use_hyperref;
|
2007-09-21 02:01:30 +00:00
|
|
|
} else if (token == "\\pdf_title") {
|
|
|
|
lex >> title;
|
|
|
|
} else if (token == "\\pdf_author") {
|
|
|
|
lex >> author;
|
|
|
|
} else if (token == "\\pdf_subject") {
|
|
|
|
lex >> subject;
|
|
|
|
} else if (token == "\\pdf_keywords") {
|
|
|
|
lex >> keywords;
|
|
|
|
} else if (token == "\\pdf_bookmarks") {
|
|
|
|
lex >> bookmarks;
|
|
|
|
} else if (token == "\\pdf_bookmarksnumbered") {
|
|
|
|
lex >> bookmarksnumbered;
|
|
|
|
} else if (token == "\\pdf_bookmarksopen") {
|
2007-09-22 11:39:19 +00:00
|
|
|
lex >> bookmarksopen;
|
2007-09-21 02:01:30 +00:00
|
|
|
} else if (token == "\\pdf_bookmarksopenlevel") {
|
|
|
|
lex >> bookmarksopenlevel;
|
|
|
|
} else if (token == "\\pdf_breaklinks") {
|
|
|
|
lex >> breaklinks;
|
|
|
|
} else if (token == "\\pdf_pdfborder") {
|
|
|
|
lex >> pdfborder;
|
|
|
|
} else if (token == "\\pdf_colorlinks") {
|
|
|
|
lex >> colorlinks;
|
|
|
|
} else if (token == "\\pdf_backref") {
|
|
|
|
lex >> backref;
|
2007-10-10 00:34:23 +00:00
|
|
|
} else if (token == "\\pdf_pdfusetitle") {
|
|
|
|
lex >> pdfusetitle;
|
2007-09-21 02:01:30 +00:00
|
|
|
} else if (token == "\\pdf_pagemode") {
|
|
|
|
lex >> pagemode;
|
|
|
|
} else if (token == "\\pdf_quoted_options") {
|
|
|
|
lex >> quoted_options;
|
|
|
|
} else {
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
return string();
|
2007-09-20 23:29:20 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 09:49:50 +00:00
|
|
|
|
2008-03-05 01:14:15 +00:00
|
|
|
// check the string from UI
|
|
|
|
string PDFOptions::quoted_options_check(string const str) const
|
2007-09-20 23:29:20 +00:00
|
|
|
{
|
2008-03-05 08:55:49 +00:00
|
|
|
return subst(str, "\n", "");
|
2007-09-20 23:29:20 +00:00
|
|
|
}
|
|
|
|
|
2008-01-19 11:17:12 +00:00
|
|
|
|
2007-10-10 00:34:23 +00:00
|
|
|
// set implicit settings for hyperref
|
2007-09-20 23:29:20 +00:00
|
|
|
void PDFOptions::clear()
|
|
|
|
{
|
2007-09-21 02:01:30 +00:00
|
|
|
use_hyperref = false;
|
|
|
|
title.clear();
|
|
|
|
author.clear();
|
|
|
|
subject.clear();
|
|
|
|
keywords.clear();
|
|
|
|
bookmarks = true;
|
|
|
|
bookmarksnumbered = false;
|
|
|
|
bookmarksopen = false;
|
2007-09-22 22:18:44 +00:00
|
|
|
bookmarksopenlevel = 1;
|
2007-09-21 02:01:30 +00:00
|
|
|
breaklinks = false;
|
|
|
|
pdfborder = false;
|
|
|
|
colorlinks = false;
|
2008-10-13 16:01:02 +00:00
|
|
|
backref = "false";
|
2007-09-21 02:01:30 +00:00
|
|
|
pagemode.clear();
|
|
|
|
quoted_options.clear();
|
2007-10-10 00:34:23 +00:00
|
|
|
pdfusetitle = true; //in contrast with hyperref
|
2007-09-20 23:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace lyx
|