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"
27 using std::ostringstream;
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 ;
53 void PDFOptions::writeFile(ostream & os) const
55 os << "\\use_hyperref " << convert<string>(use_hyperref) << '\n';
56 os << "\\pdf_store_options " << convert<string>(store_options) << '\n';
57 if (!use_hyperref && !store_options)
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';
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(odocstringstream &os) const
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 (title.empty() && author.empty())
103 opt += "pdfusetitle,\n ";
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 = support::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 = support::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_pagemode") {
186 } else if (token == "\\pdf_quoted_options") {
187 lex >> quoted_options;
188 } else if (token == "\\pdf_store_options") {
189 lex >> store_options;
198 string PDFOptions::quoted_options_get() const
200 return quoted_options;
203 // Keep implicit hyperref settings
204 void PDFOptions::clear()
206 use_hyperref = false;
212 bookmarksnumbered = false;
213 bookmarksopen = false;
214 bookmarksopenlevel = 1;
221 quoted_options.clear();
222 store_options = false;