]> git.lyx.org Git - lyx.git/blob - src/PDFOptions.cpp
* BufferView::updateMetrics(): split up the method in two for the SinglePar case.
[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 #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         PDFOptions x; //implicit hyperref settings
35
36         return  author == x.author
37                 && title == x.title
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 }
52
53 void PDFOptions::writeFile(ostream & os) const
54 {
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)
58                 return;
59         
60         if (!title.empty() )
61                 os << "\\pdf_title \"" << title << "\"\n";
62         if (!author.empty())
63                 os << "\\pdf_author \"" << author << "\"\n";
64         if (!subject.empty())
65                 os << "\\pdf_subject \"" << subject << "\"\n";
66         if (!keywords.empty())
67                 os << "\\pdf_keywords \"" << keywords << "\"\n";
68         
69         
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";
74         
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         
81         if (!pagemode.empty())
82                 os << "\\pdf_pagemode " << pagemode << '\n';
83         
84         if (!quoted_options.empty())
85                 os << "\\pdf_quoted_options \"" << quoted_options << "\"\n";
86 }
87
88 void PDFOptions::writeLaTeX(odocstringstream &os) const
89 {
90         if (!use_hyperref)
91                 return;
92         
93         string opt;
94         
95         opt = "\\usepackage[";
96         if (!title.empty())
97                 opt += "pdftitle={"   + title + "},\n ";
98         if (!author.empty())
99                 opt += "pdfauthor={"  + author + "},\n ";
100         if (!subject.empty())
101                 opt += "pdfsubject={" + subject + "},\n ";
102         if (!keywords.empty())
103                 opt += "pdfkeywords={" + keywords + "},\n ";
104         opt += "bookmarks=" + convert<string>(bookmarks) + ',';
105         if (bookmarks) {
106                 opt += "bookmarksnumbered=" + convert<string>(bookmarksnumbered) + ',';
107                 opt += "bookmarksopen=" + convert<string>(bookmarksopen) + ',';
108         
109                 if (bookmarksopen)
110                         opt += "bookmarksopenlevel=" + convert<string>(bookmarksopenlevel) + ',';
111         }
112         opt += "\n ";
113         opt += "breaklinks="     + convert<string>(breaklinks) + ',';
114
115         opt += "pdfborder={0 0 " ;
116         opt += (pdfborder ?'0':'1');
117         opt += "},";
118
119         opt += "backref="        + convert<string>(backref) + ',';
120         opt += "pagebackref="    + convert<string>(pagebackref) + ',';
121         opt += "\n ";
122         opt += "colorlinks="     + convert<string>(colorlinks) + ',';
123         if (!pagemode.empty())
124                 opt += "pdfpagemode=" + pagemode + ',';
125         if (!quoted_options.empty()){
126                 opt += "\n ";
127                 opt += quoted_options_get();
128         }
129         opt = support::rtrim(opt,",");
130         opt += "]\n {hyperref}\n";
131         
132         // FIXME UNICODE
133         os << from_utf8(opt);
134 }
135
136
137 string PDFOptions::readToken(Lexer &lex, string const & token)
138 {
139         if (token == "\\use_hyperref") {
140                 lex >> use_hyperref;
141         } else if (token == "\\pdf_title") {
142                 lex >> title;
143         } else if (token == "\\pdf_author") {
144                 lex >> author;
145         } else if (token == "\\pdf_subject") {
146                 lex >> subject;
147         } else if (token == "\\pdf_keywords") {
148                 lex >> keywords;
149         } else if (token == "\\pdf_bookmarks") {
150                 lex >> bookmarks;
151         } else if (token == "\\pdf_bookmarksnumbered") {
152                 lex >> bookmarksnumbered;
153         } else if (token == "\\pdf_bookmarksopen") {
154                 lex >> bookmarksopen;
155         } else if (token == "\\pdf_bookmarksopenlevel") {
156                 lex >> bookmarksopenlevel;
157         } else if (token == "\\pdf_breaklinks") {
158                 lex >> breaklinks;
159         } else if (token == "\\pdf_pdfborder") {
160                 lex >> pdfborder;
161         } else if (token == "\\pdf_colorlinks") {
162                 lex >> colorlinks;
163         } else if (token == "\\pdf_backref") {
164                 lex >> backref;
165         } else if (token == "\\pdf_pagebackref") {
166                 lex >> pagebackref;
167         } else if (token == "\\pdf_pagemode") {
168                 lex >> pagemode;
169         } else if (token == "\\pdf_quoted_options") {
170                 lex >> quoted_options;
171         } else if (token == "\\pdf_store_options") {
172                 lex >> store_options;
173         } else {
174                 return token;
175         }
176         return string();
177 }
178
179
180 //prepared for check
181 string PDFOptions::quoted_options_get() const
182 {
183         return quoted_options;
184 }
185
186 // Keep implicit hyperref settings
187 void PDFOptions::clear()
188 {
189         use_hyperref            = false;
190         title.clear();
191         author.clear();
192         subject.clear();
193         keywords.clear();
194         bookmarks               = true;
195         bookmarksnumbered       = false;
196         bookmarksopen           = false;
197         bookmarksopenlevel      = 1;
198         breaklinks              = false;
199         pdfborder               = false;
200         colorlinks              = false;
201         backref                 = false;
202         pagebackref             = false;
203         pagemode.clear();
204         quoted_options.clear();
205         store_options           = false;
206 }
207
208 } // namespace lyx