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.
13 #include "PDFOptions.h"
17 #include "support/convert.h"
18 #include "support/debug.h"
19 #include "support/lstrings.h"
25 using namespace lyx::support;
30 const string PDFOptions::pagemode_fullscreen("FullScreen");
32 bool PDFOptions::empty() const
34 PDFOptions x; //implicit hyperref settings
36 return author == x.author
38 && subject == x.subject
39 && keywords == x.keywords
40 && pagemode == x.pagemode
41 && quoted_options == x.quoted_options
42 && bookmarks == x.bookmarks
43 && bookmarksnumbered == x.bookmarksnumbered
44 && bookmarksopen == x.bookmarksopen
45 && bookmarksopenlevel == x.bookmarksopenlevel
46 && breaklinks == x.breaklinks
47 && pdfborder == x.pdfborder
48 && colorlinks == x.colorlinks
49 && backref == x.backref
50 && pagebackref == x.pagebackref
51 && pdfusetitle == x.pdfusetitle;
55 void PDFOptions::writeFile(ostream & os) const
57 os << "\\use_hyperref " << convert<string>(use_hyperref) << '\n';
58 if (!use_hyperref && empty())
62 os << "\\pdf_title \"" << title << "\"\n";
64 os << "\\pdf_author \"" << author << "\"\n";
66 os << "\\pdf_subject \"" << subject << "\"\n";
67 if (!keywords.empty())
68 os << "\\pdf_keywords \"" << keywords << "\"\n";
71 os << "\\pdf_bookmarks " << convert<string>(bookmarks) << '\n';
72 os << "\\pdf_bookmarksnumbered " << convert<string>(bookmarksnumbered) << '\n';
73 os << "\\pdf_bookmarksopen " << convert<string>(bookmarksopen) << '\n';
74 os << "\\pdf_bookmarksopenlevel " << bookmarksopenlevel << '\n';
76 os << "\\pdf_breaklinks " << convert<string>(breaklinks) << '\n';
77 os << "\\pdf_pdfborder " << convert<string>(pdfborder) << '\n';
78 os << "\\pdf_colorlinks " << convert<string>(colorlinks) << '\n';
79 os << "\\pdf_backref " << convert<string>(backref) << '\n';
80 os << "\\pdf_pagebackref " << convert<string>(pagebackref) << '\n';
81 os << "\\pdf_pdfusetitle " << convert<string>(pdfusetitle) << '\n';
83 if (!pagemode.empty())
84 os << "\\pdf_pagemode " << pagemode << '\n';
86 if (!quoted_options.empty())
87 os << "\\pdf_quoted_options \"" << quoted_options << "\"\n";
91 void PDFOptions::writeLaTeX(odocstream & os, bool hyperref_already_provided) const
95 // since LyX uses unicode, also set the PDF strings to unicode strings with the
96 // hyperref option "unicode"
97 opt += "unicode=true, ";
99 // try to extract author and title from document when none is
101 if (pdfusetitle && title.empty() && author.empty())
102 opt += "pdfusetitle,";
105 opt += "bookmarks=" + convert<string>(bookmarks) + ',';
107 opt += "bookmarksnumbered=" + convert<string>(bookmarksnumbered) + ',';
108 opt += "bookmarksopen=" + convert<string>(bookmarksopen) + ',';
110 opt += "bookmarksopenlevel=" + convert<string>(bookmarksopenlevel) + ',';
113 opt += "breaklinks=" + convert<string>(breaklinks) + ',';
115 opt += "pdfborder={0 0 " ;
116 opt += (pdfborder ?'0':'1');
119 opt += "backref=" + convert<string>(backref) + ',';
120 opt += "pagebackref=" + convert<string>(pagebackref) + ',';
122 opt += "colorlinks=" + convert<string>(colorlinks) + ',';
123 if (!pagemode.empty())
124 opt += "pdfpagemode=" + pagemode + ',';
128 // load the pdftitle etc. as hypersetup, otherwise you'll get
129 // LaTeX-errors when using non-latin characters
132 hyperset += "pdftitle={" + title + "},";
134 hyperset += "\n pdfauthor={" + author + "},";
135 if (!subject.empty())
136 hyperset += "\n pdfsubject={" + subject + "},";
137 if (!keywords.empty())
138 hyperset += "\n pdfkeywords={" + keywords + "},";
139 if (!quoted_options.empty()){
141 hyperset += quoted_options;
143 hyperset = rtrim(hyperset,",");
146 // use in \\usepackage parameter as not all options can be handled inside \\hypersetup
147 if (!hyperref_already_provided) {
148 opt = rtrim(opt,",");
149 opt = "\\usepackage[" + opt + "]\n {hyperref}\n";
151 if (!hyperset.empty())
152 opt += "\\hypersetup{" + hyperset + "}\n ";
154 // only in case hyperref is already loaded by the current text class
155 // try to put it into hyperset
157 // FIXME: this still does not fix the cases where hyperref is loaded
158 // and the option is active only when part of usepackage parameter
159 // (e.g. pdfusetitle).
161 opt = "\\hypersetup{" + opt + hyperset + "}\n ";
165 os << from_utf8(opt);
169 string PDFOptions::readToken(Lexer &lex, string const & token)
171 if (token == "\\use_hyperref") {
173 } else if (token == "\\pdf_title") {
175 } else if (token == "\\pdf_author") {
177 } else if (token == "\\pdf_subject") {
179 } else if (token == "\\pdf_keywords") {
181 } else if (token == "\\pdf_bookmarks") {
183 } else if (token == "\\pdf_bookmarksnumbered") {
184 lex >> bookmarksnumbered;
185 } else if (token == "\\pdf_bookmarksopen") {
186 lex >> bookmarksopen;
187 } else if (token == "\\pdf_bookmarksopenlevel") {
188 lex >> bookmarksopenlevel;
189 } else if (token == "\\pdf_breaklinks") {
191 } else if (token == "\\pdf_pdfborder") {
193 } else if (token == "\\pdf_colorlinks") {
195 } else if (token == "\\pdf_backref") {
197 } else if (token == "\\pdf_pagebackref") {
199 } else if (token == "\\pdf_pdfusetitle") {
201 } else if (token == "\\pdf_pagemode") {
203 } else if (token == "\\pdf_quoted_options") {
204 lex >> quoted_options;
212 // check the string from UI
213 string PDFOptions::quoted_options_check(string const str) const
215 return subst(str, "\n", "");
219 // set implicit settings for hyperref
220 void PDFOptions::clear()
222 use_hyperref = false;
228 bookmarksnumbered = false;
229 bookmarksopen = false;
230 bookmarksopenlevel = 1;
237 quoted_options.clear();
238 pdfusetitle = true; //in contrast with hyperref