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"
15 #include "support/convert.h"
16 #include "support/lstrings.h"
17 #include "support/debug.h"
24 using namespace lyx::support;
29 const string PDFOptions::pagemode_fullscreen("FullScreen");
31 bool PDFOptions::empty() const
33 PDFOptions x; //implicit hyperref settings
35 return author == x.author
37 && subject == x.subject
38 && keywords == x.keywords
39 && pagemode == x.pagemode
40 && quoted_options == x.quoted_options
41 && bookmarks == x.bookmarks
42 && bookmarksnumbered == x.bookmarksnumbered
43 && bookmarksopen == x.bookmarksopen
44 && bookmarksopenlevel == x.bookmarksopenlevel
45 && breaklinks == x.breaklinks
46 && pdfborder == x.pdfborder
47 && colorlinks == x.colorlinks
48 && backref == x.backref
49 && pagebackref == x.pagebackref
50 && pdfusetitle == x.pdfusetitle;
54 void PDFOptions::writeFile(ostream & os) const
56 os << "\\use_hyperref " << convert<string>(use_hyperref) << '\n';
57 if (!use_hyperref && empty())
61 os << "\\pdf_title \"" << title << "\"\n";
63 os << "\\pdf_author \"" << author << "\"\n";
65 os << "\\pdf_subject \"" << subject << "\"\n";
66 if (!keywords.empty())
67 os << "\\pdf_keywords \"" << keywords << "\"\n";
70 os << "\\pdf_bookmarks " << convert<string>(bookmarks) << '\n';
71 os << "\\pdf_bookmarksnumbered " << convert<string>(bookmarksnumbered) << '\n';
72 os << "\\pdf_bookmarksopen " << convert<string>(bookmarksopen) << '\n';
73 os << "\\pdf_bookmarksopenlevel " << bookmarksopenlevel << '\n';
75 os << "\\pdf_breaklinks " << convert<string>(breaklinks) << '\n';
76 os << "\\pdf_pdfborder " << convert<string>(pdfborder) << '\n';
77 os << "\\pdf_colorlinks " << convert<string>(colorlinks) << '\n';
78 os << "\\pdf_backref " << convert<string>(backref) << '\n';
79 os << "\\pdf_pagebackref " << convert<string>(pagebackref) << '\n';
80 os << "\\pdf_pdfusetitle " << convert<string>(pdfusetitle) << '\n';
82 if (!pagemode.empty())
83 os << "\\pdf_pagemode " << pagemode << '\n';
85 if (!quoted_options.empty())
86 os << "\\pdf_quoted_options \"" << quoted_options << "\"\n";
90 void PDFOptions::writeLaTeX(odocstream & os, bool hyperref_already_provided) const
94 // since LyX uses unicode, also set the PDF strings to unicode strings with the
95 // hyperref option "unicode"
96 opt += "unicode=true, ";
98 // try to extract author and title from document when none is
100 if (pdfusetitle && title.empty() && author.empty())
101 opt += "pdfusetitle,";
104 opt += "bookmarks=" + convert<string>(bookmarks) + ',';
106 opt += "bookmarksnumbered=" + convert<string>(bookmarksnumbered) + ',';
107 opt += "bookmarksopen=" + convert<string>(bookmarksopen) + ',';
109 opt += "bookmarksopenlevel=" + convert<string>(bookmarksopenlevel) + ',';
112 opt += "breaklinks=" + convert<string>(breaklinks) + ',';
114 opt += "pdfborder={0 0 " ;
115 opt += (pdfborder ?'0':'1');
118 opt += "backref=" + convert<string>(backref) + ',';
119 opt += "pagebackref=" + convert<string>(pagebackref) + ',';
121 opt += "colorlinks=" + convert<string>(colorlinks) + ',';
122 if (!pagemode.empty())
123 opt += "pdfpagemode=" + pagemode + ',';
127 // load the pdftitle etc. as hypersetup, otherwise you'll get
128 // LaTeX-errors when using non-latin characters
131 hyperset += "pdftitle={" + title + "},";
133 hyperset += "\n pdfauthor={" + author + "},";
134 if (!subject.empty())
135 hyperset += "\n pdfsubject={" + subject + "},";
136 if (!keywords.empty())
137 hyperset += "\n pdfkeywords={" + keywords + "},";
138 if (!quoted_options.empty()){
140 hyperset += quoted_options_get();
142 hyperset = rtrim(hyperset,",");
145 // use in \\usepackage parameter as not all options can be handled inside \\hypersetup
146 if (!hyperref_already_provided) {
147 opt = rtrim(opt,",");
148 opt = "\\usepackage[" + opt + "]\n {hyperref}\n";
150 if (!hyperset.empty())
151 opt += "\\hypersetup{" + hyperset + "}\n ";
153 // only in case hyperref is already loaded by the current text class
154 // try to put it into hyperset
156 // FIXME: this still does not fix the cases where hyperref is loaded
157 // and the option is active only when part of usepackage parameter
158 // (e.g. pdfusetitle).
160 opt = "\\hypersetup{" + opt + hyperset + "}\n ";
164 os << from_utf8(opt);
168 string PDFOptions::readToken(Lexer &lex, string const & token)
170 if (token == "\\use_hyperref") {
172 } else if (token == "\\pdf_title") {
174 } else if (token == "\\pdf_author") {
176 } else if (token == "\\pdf_subject") {
178 } else if (token == "\\pdf_keywords") {
180 } else if (token == "\\pdf_bookmarks") {
182 } else if (token == "\\pdf_bookmarksnumbered") {
183 lex >> bookmarksnumbered;
184 } else if (token == "\\pdf_bookmarksopen") {
185 lex >> bookmarksopen;
186 } else if (token == "\\pdf_bookmarksopenlevel") {
187 lex >> bookmarksopenlevel;
188 } else if (token == "\\pdf_breaklinks") {
190 } else if (token == "\\pdf_pdfborder") {
192 } else if (token == "\\pdf_colorlinks") {
194 } else if (token == "\\pdf_backref") {
196 } else if (token == "\\pdf_pagebackref") {
198 } else if (token == "\\pdf_pdfusetitle") {
200 } else if (token == "\\pdf_pagemode") {
202 } else if (token == "\\pdf_quoted_options") {
203 lex >> quoted_options;
211 // prepared for check
212 string PDFOptions::quoted_options_get() const
214 return quoted_options;
218 // set implicit settings for hyperref
219 void PDFOptions::clear()
221 use_hyperref = false;
227 bookmarksnumbered = false;
228 bookmarksopen = false;
229 bookmarksopenlevel = 1;
236 quoted_options.clear();
237 pdfusetitle = true; //in contrast with hyperref