]> git.lyx.org Git - lyx.git/blob - src/bufferparams.C
Added html export for LinuxDoc and DocBook. LinuxDoc import now available in file...
[lyx.git] / src / bufferparams.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *       
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2000 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12 #include <cstdlib>
13
14 #ifdef __GNUG__
15 #pragma implementation "bufferparams.h"
16 #endif
17
18 #include "bufferparams.h"
19 #include "tex-strings.h"
20 #include "layout.h"
21 #include "vspace.h"
22 #include "debug.h"
23 #include "support/lyxlib.h"
24 #include "support/lstrings.h"
25 #include "lyxrc.h"
26 #include "language.h"
27
28
29 BufferParams::BufferParams()
30 {
31         paragraph_separation = PARSEP_INDENT;
32         defskip = VSpace(VSpace::MEDSKIP); 
33         quotes_language = InsetQuotes::EnglishQ;
34         quotes_times = InsetQuotes::DoubleQ;
35         fontsize = "default";
36         // Initialize textclass to point to article. if `first' is
37         // true in the returned pair, then `second' is the textclass
38         // number; if it is false, second is 0. In both cases, second
39         // is what we want.
40         textclass = textclasslist.NumberOfClass("article").second;
41
42         /*  PaperLayout */
43         papersize = PAPER_DEFAULT;
44         papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
45         paperpackage = PACKAGE_NONE;
46         orientation = ORIENTATION_PORTRAIT;
47         use_geometry = false;
48         use_amsmath = false;
49         secnumdepth = 3;
50         tocdepth = 3;
51         language = "default";
52         language_info = default_language;
53         fonts = "default";
54         inputenc = "latin1";
55         graphicsDriver = "default";
56         sides = LyXTextClass::OneSide;
57         columns = 1;
58         pagestyle = "default";
59         for(int iter = 0; iter < 4; ++iter) {
60                 user_defined_bullets[iter] = temp_bullets[iter] 
61                                            = ITEMIZE_DEFAULTS[iter];
62         }
63         allowAccents = false;
64 }
65
66
67 void BufferParams::writeFile(ostream & os) const
68 {
69         // The top of the file is written by the buffer.
70         // Prints out the buffer info into the .lyx file given by file
71
72         // the textclass
73         os << "\\textclass " << textclasslist.NameOfClass(textclass) << '\n';
74         
75         // then the the preamble
76         if (!preamble.empty()) {
77                 // remove '\n' from the end of preamble
78                 string tmppreamble = strip(preamble, '\n');
79                 os << "\\begin_preamble\n"
80                    << tmppreamble
81                    << "\n\\end_preamble\n";
82         }
83       
84         /* the options */ 
85         if (!options.empty()) {
86                 os << "\\options " << options << '\n';
87         }
88    
89         /* then the text parameters */
90         os << "\\language " << language
91            << "\n\\inputencoding " << inputenc
92            << "\n\\fontscheme " << fonts
93            << "\n\\graphics " << graphicsDriver << '\n';
94
95         if (!float_placement.empty()) {
96                 os << "\\float_placement " << float_placement << '\n';
97         }
98         os << "\\paperfontsize " << fontsize << '\n';
99
100         spacing.writeFile(os);
101
102         os << "\\papersize " << string_papersize[papersize2]
103            << "\n\\paperpackage " << string_paperpackages[paperpackage]
104            << "\n\\use_geometry " << use_geometry
105            << "\n\\use_amsmath " << use_amsmath
106            << "\n\\paperorientation " << string_orientation[orientation]
107            << '\n';
108         if (!paperwidth.empty())
109                 os << "\\paperwidth "
110                    << VSpace(paperwidth).asLyXCommand() << '\n';
111         if (!paperheight.empty())
112                 os << "\\paperheight "
113                    << VSpace(paperheight).asLyXCommand() << '\n';
114         if (!leftmargin.empty())
115                 os << "\\leftmargin "
116                    << VSpace(leftmargin).asLyXCommand() << '\n';
117         if (!topmargin.empty())
118                 os << "\\topmargin "
119                    << VSpace(topmargin).asLyXCommand() << '\n';
120         if (!rightmargin.empty())
121                 os << "\\rightmargin "
122                    << VSpace(rightmargin).asLyXCommand() << '\n';
123         if (!bottommargin.empty())
124                 os << "\\bottommargin "
125                    << VSpace(bottommargin).asLyXCommand() << '\n';
126         if (!headheight.empty())
127                 os << "\\headheight "
128                    << VSpace(headheight).asLyXCommand() << '\n';
129         if (!headsep.empty())
130                 os << "\\headsep "
131                    << VSpace(headsep).asLyXCommand() << '\n';
132         if (!footskip.empty())
133                 os << "\\footskip "
134                    << VSpace(footskip).asLyXCommand() << '\n';
135         os << "\\secnumdepth " << secnumdepth
136            << "\n\\tocdepth " << tocdepth
137            << "\n\\paragraph_separation "
138            << string_paragraph_separation[paragraph_separation]
139            << "\n\\defskip " << defskip.asLyXCommand()
140            << "\n\\quotes_language "
141            << string_quotes_language[quotes_language] << '\n';
142         switch(quotes_times) {
143                 // An output operator for insetquotes would be nice
144         case InsetQuotes::SingleQ:
145                 os << "\\quotes_times 1\n"; break;
146         case InsetQuotes::DoubleQ: 
147                 os << "\\quotes_times 2\n"; break;
148         }
149         os << "\\papercolumns " << columns
150            << "\n\\papersides " << sides
151            << "\n\\paperpagestyle " << pagestyle << '\n';
152         for (int i = 0; i < 4; ++i) {
153                 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
154                         if (user_defined_bullets[i].getFont() != -1) {
155                                 os << "\\bullet " << i
156                                    << "\n\t"
157                                    << user_defined_bullets[i].getFont()
158                                    << "\n\t"
159                                    << user_defined_bullets[i].getCharacter()
160                                    << "\n\t"
161                                    << user_defined_bullets[i].getSize()
162                                    << "\n\\end_bullet\n";
163                         }
164                         else {
165                                 os << "\\bulletLaTeX " << i
166                                    << "\n\t"
167                                    << user_defined_bullets[i].c_str()
168                                    << "\n\\end_bullet\n";
169                         }
170                 }
171         }
172 }
173
174
175 void BufferParams::useClassDefaults() {
176         LyXTextClass const & tclass = textclasslist.TextClass(textclass);
177
178         sides = tclass.sides();
179         columns = tclass.columns();
180         pagestyle = tclass.pagestyle();
181         options = tclass.options();
182         secnumdepth = tclass.secnumdepth();
183         tocdepth = tclass.tocdepth();
184 }
185
186
187 void BufferParams::readPreamble(LyXLex & lex)
188 {
189         if (lex.GetString() != "\\begin_preamble")
190                 lyxerr << "Error (BufferParams::readPreamble):"
191                         "consistency check failed." << endl;
192
193         preamble = lex.getLongString("\\end_preamble");
194 }
195
196
197 void BufferParams::readLanguage(LyXLex & lex)
198 {
199         if (!lex.next()) return;
200         
201         string tmptok = lex.GetString();
202
203         // check if tmptok is part of tex_babel in tex-defs.h
204         Languages::iterator lit = languages.find(tmptok);
205         if (lit != languages.end()) {
206                 // found it
207                 language = tmptok;
208                 language_info = &(*lit).second;
209         } else {
210                 // not found
211                 language = "default";
212                 language_info = default_language;
213                 if (tmptok != "default") {
214                         lyxerr << "Warning: language `"
215                                << tmptok << "' not recognized!\n"
216                                << "         Setting language to `default'."
217                                << endl;
218                 }
219         }
220 }
221
222
223 void BufferParams::readGraphicsDriver(LyXLex & lex)
224 {
225         string tmptok;
226         string test;
227         int n = 0;
228         
229         
230         if (!lex.next()) return;
231         
232         tmptok = lex.GetString();
233         // check if tmptok is part of tex_graphics in tex_defs.h
234         while (true) {
235                 test = tex_graphics[n++];
236                 
237                 if (test == tmptok) {    
238                         graphicsDriver = tmptok;
239                         break;
240                 }      
241                 else if (test == "last_item") {
242                         lex.printError(
243                                 "Warning: graphics driver `$$Token' not recognized!\n"
244                                 "         Setting graphics driver to `default'.\n");
245                         graphicsDriver = "default";
246                         break;
247                 }      
248         }
249 }