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.
12 #include "PDFOptions.h"
14 #include "support/convert.h"
18 #include "support/lstrings.h"
26 using std::ostringstream;
29 const string PDFOptions::pagemode_fullscreen("FullScreen");
31 bool PDFOptions::empty() const
39 bookmarksopenlevel.empty() &&
40 quoted_options.empty();
43 void PDFOptions::writeFile(ostream & os) const
45 os << "\\use_hyperref " << convert<string>(use_hyperref) << '\n';
46 os << "\\pdf_store_options " << convert<string>(store_options) << '\n';
47 if (!use_hyperref && !store_options) return;
50 os << "\\pdf_title \"" << title << "\"\n";
52 os << "\\pdf_author \"" << author << "\"\n";
54 os << "\\pdf_subject \"" << subject << "\"\n";
55 if (!keywords.empty())
56 os << "\\pdf_keywords \"" << keywords << "\"\n";
59 os << "\\pdf_bookmarks " << convert<string>(bookmarks) << '\n';
60 os << "\\pdf_bookmarksnumbered " << convert<string>(bookmarksnumbered) << '\n';
61 os << "\\pdf_bookmarksopen " << convert<string>(bookmarksopen) << '\n';
62 if (bookmarksopenlevel.empty())
63 os << "\\pdf_bookmarksopenlevel \"" << bookmarksopenlevel << "\"\n";
65 os << "\\pdf_breaklinks " << convert<string>(breaklinks) << '\n';
66 os << "\\pdf_pdfborder " << convert<string>(pdfborder) << '\n';
67 os << "\\pdf_colorlinks " << convert<string>(colorlinks) << '\n';
68 os << "\\pdf_backref " << convert<string>(backref) << '\n';
69 os << "\\pdf_pagebackref " << convert<string>(pagebackref) << '\n';
71 if (!pagemode.empty())
72 os << "\\pdf_pagemode " << pagemode << '\n';
74 if (!quoted_options.empty())
75 os << "\\pdf_quoted_options \"" << quoted_options << "\"\n";
79 void PDFOptions::writeLaTeX(odocstream &os) const
81 if (!use_hyperref) return ;
85 opt = "\\usepackage[";
87 opt += "pdftitle={" + title + "},\n";
89 opt += "pdfauthor={" + author + "},\n";
91 opt += "pdfsubject={" + subject + "},\n";
92 if (!keywords.empty())
93 opt += "pdfkeywords={" + keywords + "},\n";
95 opt += "bookmarks=" + convert<string>(bookmarks) + ',';
97 opt += "bookmarksnumbered=" +
98 convert<string>(bookmarksnumbered) + ',';
99 opt += "bookmarksopen=" +
100 convert<string>(bookmarksopen) + ',';
102 if (bookmarksopen && !bookmarksopenlevel.empty())
103 opt += "bookmarksopennumbered=" +
104 bookmarksopenlevel + ',';
107 opt += "breaklinks=" + convert<string>(breaklinks) + ',';
109 opt += "pdfborder={0 0 " ;
110 opt += (pdfborder ?'1':'0');
113 opt += "colorlinks=" + convert<string>(colorlinks) + ',';
114 opt += "backref=" + convert<string>(backref) + ',';
115 opt += "pagebackref=" + convert<string>(pagebackref) + ',';
117 if (!pagemode.empty())
118 opt += "pdfpagemode=" + pagemode + ',';
119 opt += quoted_options_get();
121 opt = support::rtrim(opt,",");
122 opt += "]{hyperref}\n";
125 os << from_utf8(opt);
128 string PDFOptions::readToken(Lexer &lex, string const & token)
130 if (token == "\\use_hyperref") {
132 } else if (token == "\\pdf_title") {
134 } else if (token == "\\pdf_author") {
136 } else if (token == "\\pdf_subject") {
138 } else if (token == "\\pdf_keywords") {
140 } else if (token == "\\pdf_bookmarks") {
142 } else if (token == "\\pdf_bookmarksnumbered") {
143 lex >> bookmarksnumbered;
144 } else if (token == "\\pdf_bookmarksopen") {
145 lex >> bookmarksopenlevel;
146 } else if (token == "\\pdf_bookmarksopenlevel") {
147 lex >> bookmarksopenlevel;
148 } else if (token == "\\pdf_breaklinks") {
150 } else if (token == "\\pdf_pdfborder") {
152 } else if (token == "\\pdf_colorlinks") {
154 } else if (token == "\\pdf_backref") {
156 } else if (token == "\\pdf_pagebackref") {
158 } else if (token == "\\pdf_pagemode") {
160 } else if (token == "\\pdf_quoted_options") {
161 lex >> quoted_options;
162 } else if (token == "\\pdf_store_options") {
163 lex >> store_options;
173 string PDFOptions::quoted_options_get() const
175 return quoted_options;
178 // Keep implicit hyperref settings
179 void PDFOptions::clear()
181 use_hyperref = false;
187 bookmarksnumbered = false;
188 bookmarksopen = false;
189 bookmarksopenlevel.clear();
196 quoted_options.clear();
197 store_options = false;