]> git.lyx.org Git - lyx.git/blob - src/bufferparams.C
More ascii-export fixes and when making copy of single tabular cells now the
[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-2001 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         // Initialize textclass to point to article. if `first' is
33         // true in the returned pair, then `second' is the textclass
34         // number; if it is false, second is 0. In both cases, second
35         // is what we want.
36         : textclass(textclasslist.NumberOfClass("article").second)
37 {
38         paragraph_separation = PARSEP_INDENT;
39         defskip = VSpace(VSpace::MEDSKIP); 
40         quotes_language = InsetQuotes::EnglishQ;
41         quotes_times = InsetQuotes::DoubleQ;
42         fontsize = "default";
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         use_natbib = false;
52         use_numerical_citations = false;
53         secnumdepth = 3;
54         tocdepth = 3;
55         language = default_language;
56         fonts = "default";
57         inputenc = "auto";
58         graphicsDriver = "default";
59         sides = LyXTextClass::OneSide;
60         columns = 1;
61         pagestyle = "default";
62         for (int iter = 0; iter < 4; ++iter) {
63                 user_defined_bullets[iter] = ITEMIZE_DEFAULTS[iter];
64                 temp_bullets[iter] = ITEMIZE_DEFAULTS[iter];
65         }
66 }
67
68
69 void BufferParams::writeFile(ostream & os) const
70 {
71         // The top of the file is written by the buffer.
72         // Prints out the buffer info into the .lyx file given by file
73
74         // the textclass
75         os << "\\textclass " << textclasslist.NameOfClass(textclass) << '\n';
76         
77         // then the the preamble
78         if (!preamble.empty()) {
79                 // remove '\n' from the end of preamble
80                 string const tmppreamble = strip(preamble, '\n');
81                 os << "\\begin_preamble\n"
82                    << tmppreamble
83                    << "\n\\end_preamble\n";
84         }
85       
86         /* the options */ 
87         if (!options.empty()) {
88                 os << "\\options " << options << '\n';
89         }
90    
91         /* then the text parameters */
92         if (language != ignore_language)
93                 os << "\\language " << language->lang() << '\n';
94         os << "\\inputencoding " << inputenc
95            << "\n\\fontscheme " << fonts
96            << "\n\\graphics " << graphicsDriver << '\n';
97
98         if (!float_placement.empty()) {
99                 os << "\\float_placement " << float_placement << '\n';
100         }
101         os << "\\paperfontsize " << fontsize << '\n';
102
103         spacing.writeFile(os);
104
105         os << "\\papersize " << string_papersize[papersize2]
106            << "\n\\paperpackage " << string_paperpackages[paperpackage]
107            << "\n\\use_geometry " << use_geometry
108            << "\n\\use_amsmath " << use_amsmath
109            << "\n\\use_natbib " << use_natbib
110            << "\n\\use_numerical_citations " << use_numerical_citations
111            << "\n\\paperorientation " << string_orientation[orientation]
112            << '\n';
113         if (!paperwidth.empty())
114                 os << "\\paperwidth "
115                    << VSpace(paperwidth).asLyXCommand() << '\n';
116         if (!paperheight.empty())
117                 os << "\\paperheight "
118                    << VSpace(paperheight).asLyXCommand() << '\n';
119         if (!leftmargin.empty())
120                 os << "\\leftmargin "
121                    << VSpace(leftmargin).asLyXCommand() << '\n';
122         if (!topmargin.empty())
123                 os << "\\topmargin "
124                    << VSpace(topmargin).asLyXCommand() << '\n';
125         if (!rightmargin.empty())
126                 os << "\\rightmargin "
127                    << VSpace(rightmargin).asLyXCommand() << '\n';
128         if (!bottommargin.empty())
129                 os << "\\bottommargin "
130                    << VSpace(bottommargin).asLyXCommand() << '\n';
131         if (!headheight.empty())
132                 os << "\\headheight "
133                    << VSpace(headheight).asLyXCommand() << '\n';
134         if (!headsep.empty())
135                 os << "\\headsep "
136                    << VSpace(headsep).asLyXCommand() << '\n';
137         if (!footskip.empty())
138                 os << "\\footskip "
139                    << VSpace(footskip).asLyXCommand() << '\n';
140         os << "\\secnumdepth " << secnumdepth
141            << "\n\\tocdepth " << tocdepth
142            << "\n\\paragraph_separation "
143            << string_paragraph_separation[paragraph_separation]
144            << "\n\\defskip " << defskip.asLyXCommand()
145            << "\n\\quotes_language "
146            << string_quotes_language[quotes_language] << '\n';
147         switch (quotes_times) {
148                 // An output operator for insetquotes would be nice
149         case InsetQuotes::SingleQ:
150                 os << "\\quotes_times 1\n"; break;
151         case InsetQuotes::DoubleQ: 
152                 os << "\\quotes_times 2\n"; break;
153         }
154         os << "\\papercolumns " << columns
155            << "\n\\papersides " << sides
156            << "\n\\paperpagestyle " << pagestyle << '\n';
157         for (int i = 0; i < 4; ++i) {
158                 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
159                         if (user_defined_bullets[i].getFont() != -1) {
160                                 os << "\\bullet " << i
161                                    << "\n\t"
162                                    << user_defined_bullets[i].getFont()
163                                    << "\n\t"
164                                    << user_defined_bullets[i].getCharacter()
165                                    << "\n\t"
166                                    << user_defined_bullets[i].getSize()
167                                    << "\n\\end_bullet\n";
168                         }
169                         else {
170                                 os << "\\bulletLaTeX " << i
171                                    << "\n\t"
172                                    << user_defined_bullets[i].getText()
173                                    << "\n\\end_bullet\n";
174                         }
175                 }
176         }
177 }
178
179
180 void BufferParams::setPaperStuff()
181 {
182         papersize = PAPER_DEFAULT;
183         char const c1 = paperpackage;
184         if (c1 == PACKAGE_NONE) {
185                 char const c2 = papersize2;
186                 if (c2 == VM_PAPER_USLETTER)
187                         papersize = PAPER_USLETTER;
188                 else if (c2 == VM_PAPER_USLEGAL)
189                         papersize = PAPER_LEGALPAPER;
190                 else if (c2 == VM_PAPER_USEXECUTIVE)
191                         papersize = PAPER_EXECUTIVEPAPER;
192                 else if (c2 == VM_PAPER_A3)
193                         papersize = PAPER_A3PAPER;
194                 else if (c2 == VM_PAPER_A4)
195                         papersize = PAPER_A4PAPER;
196                 else if (c2 == VM_PAPER_A5)
197                         papersize = PAPER_A5PAPER;
198                 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
199                          (c2 == VM_PAPER_B5))
200                         papersize = PAPER_B5PAPER;
201         } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
202                    (c1 == PACKAGE_WIDEMARGINSA4))
203                 papersize = PAPER_A4PAPER;
204 }
205
206
207 void BufferParams::useClassDefaults()
208 {
209         LyXTextClass const & tclass = textclasslist.TextClass(textclass);
210
211         sides = tclass.sides();
212         columns = tclass.columns();
213         pagestyle = tclass.pagestyle();
214         options = tclass.options();
215         secnumdepth = tclass.secnumdepth();
216         tocdepth = tclass.tocdepth();
217 }
218
219
220 bool BufferParams::hasClassDefaults() const
221 {
222         LyXTextClass const & tclass = textclasslist.TextClass(textclass);
223         
224         return (sides == tclass.sides()
225                 && columns == tclass.columns()
226                 && pagestyle == tclass.pagestyle()
227                 && options == tclass.options()
228                 && secnumdepth == tclass.secnumdepth()
229                 && tocdepth == tclass.tocdepth());
230 }
231
232
233 void BufferParams::readPreamble(LyXLex & lex)
234 {
235         if (lex.getString() != "\\begin_preamble")
236                 lyxerr << "Error (BufferParams::readPreamble):"
237                         "consistency check failed." << endl;
238
239         preamble = lex.getLongString("\\end_preamble");
240 }
241
242
243 void BufferParams::readLanguage(LyXLex & lex)
244 {
245         if (!lex.next()) return;
246         
247         string const tmptok = lex.getString();
248
249         // check if tmptok is part of tex_babel in tex-defs.h
250         language = languages.getLanguage(tmptok);
251         if (!language) {
252                 // Language tmptok was not found
253                 language = default_language;
254                 lyxerr << "Warning: Setting language `"
255                        << tmptok << "' to `" << language->lang()
256                        << "'." << endl;
257         }
258 }
259
260
261 void BufferParams::readGraphicsDriver(LyXLex & lex)
262 {
263         if (!lex.next()) return;
264         
265         string const tmptok = lex.getString();
266         // check if tmptok is part of tex_graphics in tex_defs.h
267         int n = 0;
268         while (true) {
269                 string const test = tex_graphics[n++];
270                 
271                 if (test == tmptok) {    
272                         graphicsDriver = tmptok;
273                         break;
274                 } else if (test == "last_item") {
275                         lex.printError(
276                                 "Warning: graphics driver `$$Token' not recognized!\n"
277                                 "         Setting graphics driver to `default'.\n");
278                         graphicsDriver = "default";
279                         break;
280                 }      
281         }
282 }