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
51 && 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";
89 void PDFOptions::writeLaTeX(odocstringstream &os) const
96 opt = "\\usepackage[";
97 // since LyX uses unicode, also set the PDF strings to unicode strings with the
98 // hyperref option "unicode"
99 opt += "unicode=true, ";
101 // try to extract author and title from document when none is
103 if (pdfusetitle && title.empty() && author.empty())
104 opt += "pdfusetitle,";
107 opt += "bookmarks=" + convert<string>(bookmarks) + ',';
109 opt += "bookmarksnumbered=" + convert<string>(bookmarksnumbered) + ',';
110 opt += "bookmarksopen=" + convert<string>(bookmarksopen) + ',';
112 opt += "bookmarksopenlevel=" + convert<string>(bookmarksopenlevel) + ',';
115 opt += "breaklinks=" + convert<string>(breaklinks) + ',';
117 opt += "pdfborder={0 0 " ;
118 opt += (pdfborder ?'0':'1');
121 opt += "backref=" + convert<string>(backref) + ',';
122 opt += "pagebackref=" + convert<string>(pagebackref) + ',';
124 opt += "colorlinks=" + convert<string>(colorlinks) + ',';
125 if (!pagemode.empty())
126 opt += "pdfpagemode=" + pagemode + ',';
128 opt = support::rtrim(opt,",");
129 opt += "]\n {hyperref}\n";
131 // load the pdftitle etc. as hypersetup, otherwise you'll get
132 // LaTeX-errors when using non-latin characters
135 hyperset += "pdftitle={" + title + "},";
137 hyperset += "\n pdfauthor={" + author + "},";
138 if (!subject.empty())
139 hyperset += "\n pdfsubject={" + subject + "},";
140 if (!keywords.empty())
141 hyperset += "\n pdfkeywords={" + keywords + "},";
142 if (!quoted_options.empty()){
144 hyperset += quoted_options_get();
146 hyperset = support::rtrim(hyperset,",");
147 if (!hyperset.empty())
148 opt += "\\hypersetup{" + hyperset + "}\n ";
151 os << from_utf8(opt);
155 string PDFOptions::readToken(Lexer &lex, string const & token)
157 if (token == "\\use_hyperref") {
159 } else if (token == "\\pdf_title") {
161 } else if (token == "\\pdf_author") {
163 } else if (token == "\\pdf_subject") {
165 } else if (token == "\\pdf_keywords") {
167 } else if (token == "\\pdf_bookmarks") {
169 } else if (token == "\\pdf_bookmarksnumbered") {
170 lex >> bookmarksnumbered;
171 } else if (token == "\\pdf_bookmarksopen") {
172 lex >> bookmarksopen;
173 } else if (token == "\\pdf_bookmarksopenlevel") {
174 lex >> bookmarksopenlevel;
175 } else if (token == "\\pdf_breaklinks") {
177 } else if (token == "\\pdf_pdfborder") {
179 } else if (token == "\\pdf_colorlinks") {
181 } else if (token == "\\pdf_backref") {
183 } else if (token == "\\pdf_pagebackref") {
185 } else if (token == "\\pdf_pdfusetitle") {
187 } else if (token == "\\pdf_pagemode") {
189 } else if (token == "\\pdf_quoted_options") {
190 lex >> quoted_options;
191 } else if (token == "\\pdf_store_options") {
192 //leftover from previous option; intended for later removal
200 // prepared for check
201 string PDFOptions::quoted_options_get() const
203 return quoted_options;
206 // set implicit settings for hyperref
207 void PDFOptions::clear()
209 use_hyperref = false;
215 bookmarksnumbered = false;
216 bookmarksopen = false;
217 bookmarksopenlevel = 1;
224 quoted_options.clear();
225 pdfusetitle = true; //in contrast with hyperref