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;
53 void PDFOptions::writeFile(ostream & os) const
55 os << "\\use_hyperref " << convert<string>(use_hyperref) << '\n';
56 if (!use_hyperref && empty())
60 os << "\\pdf_title \"" << title << "\"\n";
62 os << "\\pdf_author \"" << author << "\"\n";
64 os << "\\pdf_subject \"" << subject << "\"\n";
65 if (!keywords.empty())
66 os << "\\pdf_keywords \"" << keywords << "\"\n";
69 os << "\\pdf_bookmarks " << convert<string>(bookmarks) << '\n';
70 os << "\\pdf_bookmarksnumbered " << convert<string>(bookmarksnumbered) << '\n';
71 os << "\\pdf_bookmarksopen " << convert<string>(bookmarksopen) << '\n';
72 os << "\\pdf_bookmarksopenlevel " << bookmarksopenlevel << '\n';
74 os << "\\pdf_breaklinks " << convert<string>(breaklinks) << '\n';
75 os << "\\pdf_pdfborder " << convert<string>(pdfborder) << '\n';
76 os << "\\pdf_colorlinks " << convert<string>(colorlinks) << '\n';
77 os << "\\pdf_backref " << convert<string>(backref) << '\n';
78 os << "\\pdf_pagebackref " << convert<string>(pagebackref) << '\n';
79 os << "\\pdf_pdfusetitle " << convert<string>(pdfusetitle) << '\n';
81 if (!pagemode.empty())
82 os << "\\pdf_pagemode " << pagemode << '\n';
84 if (!quoted_options.empty())
85 os << "\\pdf_quoted_options \"" << quoted_options << "\"\n";
88 void PDFOptions::writeLaTeX(odocstream & os, bool hyper_required) const
90 if (!use_hyperref && !hyper_required)
95 opt = "\\usepackage[";
96 // since LyX uses unicode, also set the PDF strings to unicode strings with the
97 // hyperref option "unicode"
98 opt += "unicode=true, ";
100 // try to extract author and title from document when none is
102 if (pdfusetitle && title.empty() && author.empty())
103 opt += "pdfusetitle,";
106 opt += "bookmarks=" + convert<string>(bookmarks) + ',';
108 opt += "bookmarksnumbered=" + convert<string>(bookmarksnumbered) + ',';
109 opt += "bookmarksopen=" + convert<string>(bookmarksopen) + ',';
111 opt += "bookmarksopenlevel=" + convert<string>(bookmarksopenlevel) + ',';
114 opt += "breaklinks=" + convert<string>(breaklinks) + ',';
116 opt += "pdfborder={0 0 " ;
117 opt += (pdfborder ?'0':'1');
120 opt += "backref=" + convert<string>(backref) + ',';
121 opt += "pagebackref=" + convert<string>(pagebackref) + ',';
123 opt += "colorlinks=" + convert<string>(colorlinks) + ',';
124 if (!pagemode.empty())
125 opt += "pdfpagemode=" + pagemode + ',';
127 opt = rtrim(opt,",");
128 opt += "]\n {hyperref}\n";
130 // load the pdftitle etc. as hypersetup, otherwise you'll get
131 // LaTeX-errors when using non-latin characters
134 hyperset += "pdftitle={" + title + "},";
136 hyperset += "\n pdfauthor={" + author + "},";
137 if (!subject.empty())
138 hyperset += "\n pdfsubject={" + subject + "},";
139 if (!keywords.empty())
140 hyperset += "\n pdfkeywords={" + keywords + "},";
141 if (!quoted_options.empty()){
143 hyperset += quoted_options_get();
145 hyperset = rtrim(hyperset,",");
146 if (!hyperset.empty())
147 opt += "\\hypersetup{" + hyperset + "}\n ";
150 os << from_utf8(opt);
154 string PDFOptions::readToken(Lexer &lex, string const & token)
156 if (token == "\\use_hyperref") {
158 } else if (token == "\\pdf_title") {
160 } else if (token == "\\pdf_author") {
162 } else if (token == "\\pdf_subject") {
164 } else if (token == "\\pdf_keywords") {
166 } else if (token == "\\pdf_bookmarks") {
168 } else if (token == "\\pdf_bookmarksnumbered") {
169 lex >> bookmarksnumbered;
170 } else if (token == "\\pdf_bookmarksopen") {
171 lex >> bookmarksopen;
172 } else if (token == "\\pdf_bookmarksopenlevel") {
173 lex >> bookmarksopenlevel;
174 } else if (token == "\\pdf_breaklinks") {
176 } else if (token == "\\pdf_pdfborder") {
178 } else if (token == "\\pdf_colorlinks") {
180 } else if (token == "\\pdf_backref") {
182 } else if (token == "\\pdf_pagebackref") {
184 } else if (token == "\\pdf_pdfusetitle") {
186 } else if (token == "\\pdf_pagemode") {
188 } else if (token == "\\pdf_quoted_options") {
189 lex >> quoted_options;
197 // prepared for check
198 string PDFOptions::quoted_options_get() const
200 return quoted_options;
203 // set implicit settings for hyperref
204 void PDFOptions::clear()
206 use_hyperref = false;
212 bookmarksnumbered = false;
213 bookmarksopen = false;
214 bookmarksopenlevel = 1;
221 quoted_options.clear();
222 pdfusetitle = true; //in contrast with hyperref