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-21 09:49:50 +00:00
|
|
|
return author.empty()
|
|
|
|
&& title.empty()
|
|
|
|
&& subject.empty()
|
|
|
|
&& keywords.empty()
|
|
|
|
&& pagemode.empty()
|
|
|
|
&& bookmarksopenlevel.empty()
|
|
|
|
&& quoted_options.empty();
|
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';
|
|
|
|
if (bookmarksopenlevel.empty())
|
|
|
|
os << "\\pdf_bookmarksopenlevel \"" << bookmarksopenlevel << "\"\n";
|
|
|
|
|
|
|
|
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[";
|
|
|
|
if (!title.empty())
|
|
|
|
opt += "pdftitle={" + title + "},\n";
|
|
|
|
if (!author.empty())
|
|
|
|
opt += "pdfauthor={" + author + "},\n";
|
|
|
|
if (!subject.empty())
|
|
|
|
opt += "pdfsubject={" + subject + "},\n";
|
|
|
|
if (!keywords.empty())
|
|
|
|
opt += "pdfkeywords={" + keywords + "},\n";
|
|
|
|
|
|
|
|
opt += "bookmarks=" + convert<string>(bookmarks) + ',';
|
|
|
|
if (bookmarks) {
|
|
|
|
opt += "bookmarksnumbered=" + convert<string>(bookmarksnumbered) + ',';
|
|
|
|
opt += "bookmarksopen=" + convert<string>(bookmarksopen) + ',';
|
|
|
|
|
|
|
|
if (bookmarksopen && !bookmarksopenlevel.empty())
|
2007-09-21 23:55:24 +00:00
|
|
|
opt += "bookmarksopenlevel=" + bookmarksopenlevel + ',';
|
2007-09-21 02:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
opt += "breaklinks=" + convert<string>(breaklinks) + ',';
|
|
|
|
|
|
|
|
opt += "pdfborder={0 0 " ;
|
2007-09-21 23:55:24 +00:00
|
|
|
opt += (pdfborder ?'0':'1');
|
2007-09-21 02:01:30 +00:00
|
|
|
opt += "},\n";
|
|
|
|
|
|
|
|
opt += "colorlinks=" + convert<string>(colorlinks) + ',';
|
|
|
|
opt += "backref=" + convert<string>(backref) + ',';
|
|
|
|
opt += "pagebackref=" + convert<string>(pagebackref) + ',';
|
|
|
|
|
|
|
|
if (!pagemode.empty())
|
|
|
|
opt += "pdfpagemode=" + pagemode + ',';
|
|
|
|
opt += quoted_options_get();
|
|
|
|
|
|
|
|
opt = support::rtrim(opt,",");
|
|
|
|
opt += "]{hyperref}\n";
|
|
|
|
|
|
|
|
// 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") {
|
|
|
|
lex >> bookmarksopenlevel;
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
2007-09-21 09:49:50 +00:00
|
|
|
|
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;
|
|
|
|
bookmarksopenlevel.clear();
|
|
|
|
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
|