]> git.lyx.org Git - features.git/blob - src/PDFOptions.cpp
PDFOptions.cpp: clean up the appearance of the parameters in the LaTeX-output
[features.git] / src / PDFOptions.cpp
1 /**
2  * \file PDFoptions.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Pavel Sanda
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "PDFOptions.h"
14
15 #include "support/convert.h"
16 #include "support/lstrings.h"
17 #include "debug.h"
18 #include "Lexer.h"
19
20 #include <sstream>
21 #include <string>
22
23 namespace lyx {
24
25
26 using std::ostream;
27 using std::ostringstream;
28 using std::string;
29
30 const string PDFOptions::pagemode_fullscreen("FullScreen");
31
32 bool PDFOptions::empty() const
33 {
34         return author.empty()
35                 && title.empty()
36                 && subject.empty()
37                 && keywords.empty()
38                 && pagemode.empty()
39                 && bookmarksopenlevel.empty()
40                 && quoted_options.empty();
41 }
42
43 void PDFOptions::writeFile(ostream & os) const
44 {
45         os << "\\use_hyperref " << convert<string>(use_hyperref) << '\n';
46         os << "\\pdf_store_options " << convert<string>(store_options) << '\n';
47         if (!use_hyperref && !store_options)
48                 return;
49         
50         if (!title.empty() )
51                 os << "\\pdf_title \"" << title << "\"\n";
52         if (!author.empty())
53                 os << "\\pdf_author \"" << author << "\"\n";
54         if (!subject.empty())
55                 os << "\\pdf_subject \"" << subject << "\"\n";
56         if (!keywords.empty())
57                 os << "\\pdf_keywords \"" << keywords << "\"\n";
58         
59         
60         os << "\\pdf_bookmarks " << convert<string>(bookmarks) << '\n';
61         os << "\\pdf_bookmarksnumbered " << convert<string>(bookmarksnumbered) << '\n';
62         os << "\\pdf_bookmarksopen " << convert<string>(bookmarksopen) << '\n';
63         if (!bookmarksopenlevel.empty())
64                 os << "\\pdf_bookmarksopenlevel \"" << bookmarksopenlevel << "\"\n";
65         
66         os << "\\pdf_breaklinks "  << convert<string>(breaklinks)  << '\n';
67         os << "\\pdf_pdfborder "   << convert<string>(pdfborder)   << '\n';
68         os << "\\pdf_colorlinks "  << convert<string>(colorlinks)  << '\n';
69         os << "\\pdf_backref "     << convert<string>(backref)     << '\n';
70         os << "\\pdf_pagebackref " << convert<string>(pagebackref) << '\n';
71         
72         if (!pagemode.empty())
73                 os << "\\pdf_pagemode " << pagemode << '\n';
74         
75         if (!quoted_options.empty())
76                 os << "\\pdf_quoted_options \"" << quoted_options << "\"\n";
77 }
78
79 void PDFOptions::writeLaTeX(odocstringstream &os) const
80 {
81         if (!use_hyperref)
82                 return;
83         
84         string opt;
85         
86         opt = "\\usepackage[";
87         if (!title.empty())
88                 opt += "pdftitle={"   + title + "},\n ";
89         if (!author.empty())
90                 opt += "pdfauthor={"  + author + "},\n ";
91         if (!subject.empty())
92                 opt += "pdfsubject={" + subject + "},\n ";
93         if (!keywords.empty())
94                 opt += "pdfkeywords={" + keywords + "},\n ";
95         opt += "bookmarks=" + convert<string>(bookmarks) + ',';
96         if (bookmarks) {
97                 opt += "bookmarksnumbered=" + convert<string>(bookmarksnumbered) + ',';
98                 opt += "bookmarksopen=" + convert<string>(bookmarksopen) + ',';
99         
100                 if (bookmarksopen && !bookmarksopenlevel.empty())
101                         opt += "bookmarksopenlevel=" + bookmarksopenlevel + ',';
102         }
103         opt += "\n ";
104         opt += "breaklinks="     + convert<string>(breaklinks) + ',';
105
106         opt += "pdfborder={0 0 " ;
107         opt += (pdfborder ?'0':'1');
108         opt += "},";
109
110         opt += "backref="        + convert<string>(backref) + ',';
111         opt += "pagebackref="    + convert<string>(pagebackref) + ',';
112         opt += "\n ";
113         opt += "colorlinks="     + convert<string>(colorlinks) + ',';
114         if (!pagemode.empty())
115                 opt += "pdfpagemode=" + pagemode + ',';
116         opt += "\n ";
117         opt += quoted_options_get();
118         opt = support::rtrim(opt,",");
119         opt += "]\n {hyperref}\n";
120         
121         // FIXME UNICODE
122         os << from_utf8(opt);
123 }
124
125
126 string PDFOptions::readToken(Lexer &lex, string const & token)
127 {
128         if (token == "\\use_hyperref") {
129                 lex >> use_hyperref;
130         } else if (token == "\\pdf_title") {
131                 lex >> title;
132         } else if (token == "\\pdf_author") {
133                 lex >> author;
134         } else if (token == "\\pdf_subject") {
135                 lex >> subject;
136         } else if (token == "\\pdf_keywords") {
137                 lex >> keywords;
138         } else if (token == "\\pdf_bookmarks") {
139                 lex >> bookmarks;
140         } else if (token == "\\pdf_bookmarksnumbered") {
141                 lex >> bookmarksnumbered;
142         } else if (token == "\\pdf_bookmarksopen") {
143                 lex >> bookmarksopen;
144         } else if (token == "\\pdf_bookmarksopenlevel") {
145                 lex >> bookmarksopenlevel;
146         } else if (token == "\\pdf_breaklinks") {
147                 lex >> breaklinks;
148         } else if (token == "\\pdf_pdfborder") {
149                 lex >> pdfborder;
150         } else if (token == "\\pdf_colorlinks") {
151                 lex >> colorlinks;
152         } else if (token == "\\pdf_backref") {
153                 lex >> backref;
154         } else if (token == "\\pdf_pagebackref") {
155                 lex >> pagebackref;
156         } else if (token == "\\pdf_pagemode") {
157                 lex >> pagemode;
158         } else if (token == "\\pdf_quoted_options") {
159                 lex >> quoted_options;
160         } else if (token == "\\pdf_store_options") {
161                 lex >> store_options;
162         } else {
163                 return token;
164         }
165         return string();
166 }
167
168
169 //prepared for check
170 string PDFOptions::quoted_options_get() const
171 {
172         return quoted_options;
173 }
174
175
176 // Keep implicit hyperref settings
177 void PDFOptions::clear()
178 {
179         use_hyperref            = false;
180         title.clear();
181         author.clear();
182         subject.clear();
183         keywords.clear();
184         bookmarks               = true;
185         bookmarksnumbered       = false;
186         bookmarksopen           = false;
187         bookmarksopenlevel.clear();
188         breaklinks              = false;
189         pdfborder               = false;
190         colorlinks              = false;
191         backref                 = false;
192         pagebackref             = false;
193         pagemode.clear();
194         quoted_options.clear();
195         store_options           = false;
196 }
197
198 } // namespace lyx