]> git.lyx.org Git - lyx.git/blob - src/bufferparams.C
Dekels tabular/textinset patches
[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 using std::ostream;
29 using std::endl;
30
31 BufferParams::BufferParams()
32 {
33         paragraph_separation = PARSEP_INDENT;
34         defskip = VSpace(VSpace::MEDSKIP); 
35         quotes_language = InsetQuotes::EnglishQ;
36         quotes_times = InsetQuotes::DoubleQ;
37         fontsize = "default";
38         // Initialize textclass to point to article. if `first' is
39         // true in the returned pair, then `second' is the textclass
40         // number; if it is false, second is 0. In both cases, second
41         // is what we want.
42         textclass = textclasslist.NumberOfClass("article").second;
43
44         /*  PaperLayout */
45         papersize = PAPER_DEFAULT;
46         papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
47         paperpackage = PACKAGE_NONE;
48         orientation = ORIENTATION_PORTRAIT;
49         use_geometry = false;
50         use_amsmath = false;
51         secnumdepth = 3;
52         tocdepth = 3;
53         language = default_language;
54         fonts = "default";
55         inputenc = "auto";
56         graphicsDriver = "default";
57         sides = LyXTextClass::OneSide;
58         columns = 1;
59         pagestyle = "default";
60         for (int iter = 0; iter < 4; ++iter) {
61                 user_defined_bullets[iter] = temp_bullets[iter] 
62                                            = ITEMIZE_DEFAULTS[iter];
63         }
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 const 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->lang()
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].getText()
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 const tmptok = lex.GetString();
202
203         // check if tmptok is part of tex_babel in tex-defs.h
204         language = languages.getLanguage(tmptok);
205         if (!language) {
206                 // Language tmptok was not found
207                 language = default_language;
208                 lyxerr << "Warning: Setting language `"
209                        << tmptok << "' to `" << language->lang()
210                        << "'." << endl;
211         }
212 }
213
214
215 void BufferParams::readGraphicsDriver(LyXLex & lex)
216 {
217         if (!lex.next()) return;
218         
219         string const tmptok = lex.GetString();
220         // check if tmptok is part of tex_graphics in tex_defs.h
221         int n = 0;
222         while (true) {
223                 string const test = tex_graphics[n++];
224                 
225                 if (test == tmptok) {    
226                         graphicsDriver = tmptok;
227                         break;
228                 } else if (test == "last_item") {
229                         lex.printError(
230                                 "Warning: graphics driver `$$Token' not recognized!\n"
231                                 "         Setting graphics driver to `default'.\n");
232                         graphicsDriver = "default";
233                         break;
234                 }      
235         }
236 }