3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
14 #include "PDFOptions.h"
18 #include "support/convert.h"
19 #include "support/lstrings.h"
28 using std::ostringstream;
31 const string PDFOptions::pagemode_fullscreen("FullScreen");
33 bool PDFOptions::empty() const
41 bookmarksopenlevel.empty() &&
42 quoted_options.empty();
45 void PDFOptions::writeFile(ostream & os) const
47 os << "\\use_hyperref " << convert<string>(use_hyperref) << '\n';
48 os << "\\pdf_store_options " << convert<string>(store_options) << '\n';
49 if (!use_hyperref && !store_options) return;
52 os << "\\pdf_title \"" << title << "\"\n";
54 os << "\\pdf_author \"" << author << "\"\n";
56 os << "\\pdf_subject \"" << subject << "\"\n";
57 if (!keywords.empty())
58 os << "\\pdf_keywords \"" << keywords << "\"\n";
61 os << "\\pdf_bookmarks " << convert<string>(bookmarks) << '\n';
62 os << "\\pdf_bookmarksnumbered " << convert<string>(bookmarksnumbered) << '\n';
63 os << "\\pdf_bookmarksopen " << convert<string>(bookmarksopen) << '\n';
64 if (bookmarksopenlevel.empty())
65 os << "\\pdf_bookmarksopenlevel \"" << bookmarksopenlevel << "\"\n";
67 os << "\\pdf_breaklinks " << convert<string>(breaklinks) << '\n';
68 os << "\\pdf_pdfborder " << convert<string>(pdfborder) << '\n';
69 os << "\\pdf_colorlinks " << convert<string>(colorlinks) << '\n';
70 os << "\\pdf_backref " << convert<string>(backref) << '\n';
71 os << "\\pdf_pagebackref " << convert<string>(pagebackref) << '\n';
73 if (!pagemode.empty())
74 os << "\\pdf_pagemode " << pagemode << '\n';
76 if (!quoted_options.empty())
77 os << "\\pdf_quoted_options \"" << quoted_options << "\"\n";
80 void PDFOptions::writeLaTeX(odocstream &os) const
82 if (!use_hyperref) return ;
86 opt = "\\usepackage[";
88 opt += "pdftitle={" + title + "},\n";
90 opt += "pdfauthor={" + author + "},\n";
92 opt += "pdfsubject={" + subject + "},\n";
93 if (!keywords.empty())
94 opt += "pdfkeywords={" + keywords + "},\n";
96 opt += "bookmarks=" + convert<string>(bookmarks) + ',';
98 opt += "bookmarksnumbered=" + convert<string>(bookmarksnumbered) + ',';
99 opt += "bookmarksopen=" + convert<string>(bookmarksopen) + ',';
101 if (bookmarksopen && !bookmarksopenlevel.empty())
102 opt += "bookmarksopennumbered=" + bookmarksopenlevel + ',';
105 opt += "breaklinks=" + convert<string>(breaklinks) + ',';
107 opt += "pdfborder={0 0 " ;
108 opt += (pdfborder ?'1':'0');
111 opt += "colorlinks=" + convert<string>(colorlinks) + ',';
112 opt += "backref=" + convert<string>(backref) + ',';
113 opt += "pagebackref=" + convert<string>(pagebackref) + ',';
115 if (!pagemode.empty())
116 opt += "pdfpagemode=" + pagemode + ',';
117 opt += quoted_options_get();
119 opt = support::rtrim(opt,",");
120 opt += "]{hyperref}\n";
123 os << from_utf8(opt);
126 string PDFOptions::readToken(Lexer &lex, string const & token)
128 if (token == "\\use_hyperref") {
130 } else if (token == "\\pdf_title") {
132 } else if (token == "\\pdf_author") {
134 } else if (token == "\\pdf_subject") {
136 } else if (token == "\\pdf_keywords") {
138 } else if (token == "\\pdf_bookmarks") {
140 } else if (token == "\\pdf_bookmarksnumbered") {
141 lex >> bookmarksnumbered;
142 } else if (token == "\\pdf_bookmarksopen") {
143 lex >> bookmarksopenlevel;
144 } else if (token == "\\pdf_bookmarksopenlevel") {
145 lex >> bookmarksopenlevel;
146 } else if (token == "\\pdf_breaklinks") {
148 } else if (token == "\\pdf_pdfborder") {
150 } else if (token == "\\pdf_colorlinks") {
152 } else if (token == "\\pdf_backref") {
154 } else if (token == "\\pdf_pagebackref") {
156 } else if (token == "\\pdf_pagemode") {
158 } else if (token == "\\pdf_quoted_options") {
159 lex >> quoted_options;
160 } else if (token == "\\pdf_store_options") {
161 lex >> store_options;
169 string PDFOptions::quoted_options_get() const
171 return quoted_options;
174 // Keep implicit hyperref settings
175 void PDFOptions::clear()
177 use_hyperref = false;
183 bookmarksnumbered = false;
184 bookmarksopen = false;
185 bookmarksopenlevel.clear();
192 quoted_options.clear();
193 store_options = false;