]> git.lyx.org Git - lyx.git/blob - src/PDFOptions.cpp
94051b9fc11a122f9c595c09485baacf91ad54f7
[lyx.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
12 #include "config.h"
13
14 #include "PDFOptions.h"
15
16 #include <sstream>
17 #include <string>
18 #include "support/convert.h"
19 #include "support/lstrings.h"
20 #include "debug.h"
21 #include "Lexer.h"
22
23
24 namespace lyx {
25
26
27 using std::ostream;
28 using std::ostringstream;
29 using std::string;
30
31 const string PDFOptions::pagemode_fullscreen("FullScreen");
32
33 bool PDFOptions::empty() const
34 {
35         return
36                 author.empty()  &&
37                 title.empty()   &&
38                 subject.empty() &&
39                 keywords.empty()&&
40                 pagemode.empty()&&
41                 bookmarksopenlevel.empty() &&
42                 quoted_options.empty();
43 }
44
45 void PDFOptions::writeFile(ostream & os) const
46 {
47         os << "\\use_hyperref " << convert<string>(use_hyperref) << '\n';
48         os << "\\pdf_store_options " << convert<string>(store_options) << '\n';
49         if (!use_hyperref && !store_options) return;
50         
51         if (!title.empty() )
52         os << "\\pdf_title \"" << title << "\"\n";
53         if (!author.empty())
54         os << "\\pdf_author \"" << author << "\"\n";
55         if (!subject.empty())
56         os << "\\pdf_subject \"" << subject << "\"\n";
57         if (!keywords.empty())
58         os << "\\pdf_keywords \"" << keywords << "\"\n";
59         
60         
61         os << "\\pdf_bookmarks " << convert<string>(bookmarks) << '\n';
62         os << "\\pdf_bookmarksnumbered " << convert<string>(bookmarksnumbered) << '\n';
63         os << "\\pdf_bookmarksopen " << convert<string>(bookmarksopen) << '\n';
64         if (bookmarksopenlevel.empty())
65                 os << "\\pdf_bookmarksopenlevel \"" << bookmarksopenlevel << "\"\n";
66         
67         os << "\\pdf_breaklinks "  << convert<string>(breaklinks)  << '\n';
68         os << "\\pdf_pdfborder "   << convert<string>(pdfborder)   << '\n';
69         os << "\\pdf_colorlinks "  << convert<string>(colorlinks)  << '\n';
70         os << "\\pdf_backref "     << convert<string>(backref)     << '\n';
71         os << "\\pdf_pagebackref " << convert<string>(pagebackref) << '\n';
72         
73         if (!pagemode.empty())
74         os << "\\pdf_pagemode " << pagemode << '\n';
75         
76         if (!quoted_options.empty())
77         os << "\\pdf_quoted_options \"" << quoted_options << "\"\n";
78 }
79
80 void PDFOptions::writeLaTeX(odocstream &os) const
81 {
82         if (!use_hyperref) 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         
96         opt += "bookmarks=" + convert<string>(bookmarks) + ',';
97         if (bookmarks) {
98                 opt += "bookmarksnumbered=" + convert<string>(bookmarksnumbered) + ',';
99                 opt += "bookmarksopen=" + convert<string>(bookmarksopen) + ',';
100         
101                 if (bookmarksopen && !bookmarksopenlevel.empty())
102                         opt += "bookmarksopennumbered=" + bookmarksopenlevel + ',';
103         }
104         
105         opt += "breaklinks="     + convert<string>(breaklinks) + ',';
106         
107         opt += "pdfborder={0 0 " ;
108         opt += (pdfborder ?'1':'0');
109         opt += "},\n";
110         
111         opt += "colorlinks="     + convert<string>(colorlinks) + ',';
112         opt += "backref="        + convert<string>(backref) + ',';
113         opt += "pagebackref="    + convert<string>(pagebackref) + ',';
114         
115         if (!pagemode.empty())
116                 opt += "pdfpagemode=" + pagemode + ',';
117         opt += quoted_options_get();
118         
119         opt = support::rtrim(opt,",");
120         opt += "]{hyperref}\n";
121         
122         // FIXME UNICODE
123         os << from_utf8(opt);
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 >> bookmarksopenlevel;
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 //prepared for check
169 string PDFOptions::quoted_options_get() const
170 {
171         return quoted_options;
172 }
173
174 // Keep implicit hyperref settings
175 void PDFOptions::clear()
176 {
177         use_hyperref            = false;
178         title.clear();
179         author.clear();
180         subject.clear();
181         keywords.clear();
182         bookmarks               = true;
183         bookmarksnumbered       = false;
184         bookmarksopen           = false;
185         bookmarksopenlevel.clear();
186         breaklinks              = false;
187         pdfborder               = false;
188         colorlinks              = false;
189         backref                 = false;
190         pagebackref             = false;
191         pagemode.clear();
192         quoted_options.clear();
193         store_options           = false;
194
195 }
196
197 } // namespace lyx