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
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2007-09-21 01:51:08 +00:00
|
|
|
#include "support/convert.h"
|
2007-09-20 23:29:20 +00:00
|
|
|
#include "support/lstrings.h"
|
2007-09-21 01:51:08 +00:00
|
|
|
#include "debug.h"
|
2007-09-20 23:29:20 +00:00
|
|
|
#include "Lexer.h"
|
|
|
|
|
2007-09-21 09:49:50 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2007-09-20 23:29:20 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
|
|
using std::ostream;
|
|
|
|
using std::ostringstream;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
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
|
|
|
|
&& pagebackref == x.pagebackref ;
|
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';
|
|
|
|
os << "\\pdf_store_options " << convert<string>(store_options) << '\n';
|
2007-09-21 09:49:50 +00:00
|
|
|
if (!use_hyperref && !store_options)
|
|
|
|
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-09-22 22:18:44 +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';
|
|
|
|
os << "\\pdf_backref " << convert<string>(backref) << '\n';
|
|
|
|
os << "\\pdf_pagebackref " << convert<string>(pagebackref) << '\n';
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-09-21 02:10:50 +00:00
|
|
|
void PDFOptions::writeLaTeX(odocstringstream &os) const
|
2007-09-20 23:29:20 +00:00
|
|
|
{
|
2007-09-21 09:49:50 +00:00
|
|
|
if (!use_hyperref)
|
|
|
|
return;
|
2007-09-21 02:01:30 +00:00
|
|
|
|
|
|
|
string opt;
|
|
|
|
|
|
|
|
opt = "\\usepackage[";
|
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"
|
2007-10-03 19:33:39 +00:00
|
|
|
opt += "unicode=true, ";
|
|
|
|
|
2007-10-03 18:58:02 +00:00
|
|
|
// try to extract author and title from document when none is
|
|
|
|
// explicitely given
|
|
|
|
if (title.empty() && author.empty())
|
|
|
|
opt += "pdfusetitle,\n ";
|
2007-10-03 19:33:39 +00:00
|
|
|
else
|
|
|
|
opt += "\n ";
|
2007-09-21 02:01:30 +00:00
|
|
|
opt += "bookmarks=" + convert<string>(bookmarks) + ',';
|
|
|
|
if (bookmarks) {
|
|
|
|
opt += "bookmarksnumbered=" + convert<string>(bookmarksnumbered) + ',';
|
|
|
|
opt += "bookmarksopen=" + convert<string>(bookmarksopen) + ',';
|
2007-09-22 22:18:44 +00:00
|
|
|
if (bookmarksopen)
|
|
|
|
opt += "bookmarksopenlevel=" + convert<string>(bookmarksopenlevel) + ',';
|
2007-09-21 02:01:30 +00:00
|
|
|
}
|
2007-09-22 12:53:22 +00:00
|
|
|
opt += "\n ";
|
2007-09-21 02:01:30 +00:00
|
|
|
opt += "breaklinks=" + convert<string>(breaklinks) + ',';
|
2007-09-22 12:53:22 +00:00
|
|
|
|
2007-09-21 02:01:30 +00:00
|
|
|
opt += "pdfborder={0 0 " ;
|
2007-09-21 23:55:24 +00:00
|
|
|
opt += (pdfborder ?'0':'1');
|
2007-09-22 12:53:22 +00:00
|
|
|
opt += "},";
|
|
|
|
|
2007-09-21 02:01:30 +00:00
|
|
|
opt += "backref=" + convert<string>(backref) + ',';
|
|
|
|
opt += "pagebackref=" + convert<string>(pagebackref) + ',';
|
2007-09-22 12:53:22 +00:00
|
|
|
opt += "\n ";
|
|
|
|
opt += "colorlinks=" + convert<string>(colorlinks) + ',';
|
2007-09-21 02:01:30 +00:00
|
|
|
if (!pagemode.empty())
|
|
|
|
opt += "pdfpagemode=" + pagemode + ',';
|
2007-10-03 19:33:39 +00:00
|
|
|
|
2007-09-21 02:01:30 +00:00
|
|
|
opt = support::rtrim(opt,",");
|
2007-09-22 12:53:22 +00:00
|
|
|
opt += "]\n {hyperref}\n";
|
2007-10-03 19:33:39 +00:00
|
|
|
|
|
|
|
// load the pdftitle etc. as hypersetup, otherwise you'll get
|
|
|
|
// LaTeX-errors when using non-latin characters
|
|
|
|
string hyperset;
|
|
|
|
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_get();
|
|
|
|
}
|
|
|
|
hyperset = support::rtrim(hyperset,",");
|
|
|
|
if (!hyperset.empty())
|
|
|
|
opt += "\\hypersetup{" + hyperset + "}\n ";
|
2007-09-21 02:01:30 +00:00
|
|
|
|
|
|
|
// FIXME UNICODE
|
|
|
|
os << from_utf8(opt);
|
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;
|
|
|
|
} else if (token == "\\pdf_pagebackref") {
|
|
|
|
lex >> pagebackref;
|
|
|
|
} else if (token == "\\pdf_pagemode") {
|
|
|
|
lex >> pagemode;
|
|
|
|
} else if (token == "\\pdf_quoted_options") {
|
|
|
|
lex >> quoted_options;
|
|
|
|
} else if (token == "\\pdf_store_options") {
|
|
|
|
lex >> store_options;
|
|
|
|
} else {
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
return string();
|
2007-09-20 23:29:20 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 09:49:50 +00:00
|
|
|
|
2007-09-20 23:29:20 +00:00
|
|
|
//prepared for check
|
|
|
|
string PDFOptions::quoted_options_get() const
|
|
|
|
{
|
2007-09-21 02:01:30 +00:00
|
|
|
return quoted_options;
|
2007-09-20 23:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Keep implicit hyperref settings
|
|
|
|
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;
|
|
|
|
backref = false;
|
|
|
|
pagebackref = false;
|
|
|
|
pagemode.clear();
|
|
|
|
quoted_options.clear();
|
|
|
|
store_options = false;
|
2007-09-20 23:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace lyx
|