]> git.lyx.org Git - lyx.git/blob - src/bufferparams.C
f45a5b2ca1bdffdb888ec33fd371ec36fb394ff6
[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";
54         language_info = default_language;
55         fonts = "default";
56         inputenc = "latin1";
57         graphicsDriver = "default";
58         sides = LyXTextClass::OneSide;
59         columns = 1;
60         pagestyle = "default";
61         for(int iter = 0; iter < 4; ++iter) {
62                 user_defined_bullets[iter] = temp_bullets[iter] 
63                                            = ITEMIZE_DEFAULTS[iter];
64         }
65         allowAccents = false;
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 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         os << "\\language " << language
93            << "\n\\inputencoding " << inputenc
94            << "\n\\fontscheme " << fonts
95            << "\n\\graphics " << graphicsDriver << '\n';
96
97         if (!float_placement.empty()) {
98                 os << "\\float_placement " << float_placement << '\n';
99         }
100         os << "\\paperfontsize " << fontsize << '\n';
101
102         spacing.writeFile(os);
103
104         os << "\\papersize " << string_papersize[papersize2]
105            << "\n\\paperpackage " << string_paperpackages[paperpackage]
106            << "\n\\use_geometry " << use_geometry
107            << "\n\\use_amsmath " << use_amsmath
108            << "\n\\paperorientation " << string_orientation[orientation]
109            << '\n';
110         if (!paperwidth.empty())
111                 os << "\\paperwidth "
112                    << VSpace(paperwidth).asLyXCommand() << '\n';
113         if (!paperheight.empty())
114                 os << "\\paperheight "
115                    << VSpace(paperheight).asLyXCommand() << '\n';
116         if (!leftmargin.empty())
117                 os << "\\leftmargin "
118                    << VSpace(leftmargin).asLyXCommand() << '\n';
119         if (!topmargin.empty())
120                 os << "\\topmargin "
121                    << VSpace(topmargin).asLyXCommand() << '\n';
122         if (!rightmargin.empty())
123                 os << "\\rightmargin "
124                    << VSpace(rightmargin).asLyXCommand() << '\n';
125         if (!bottommargin.empty())
126                 os << "\\bottommargin "
127                    << VSpace(bottommargin).asLyXCommand() << '\n';
128         if (!headheight.empty())
129                 os << "\\headheight "
130                    << VSpace(headheight).asLyXCommand() << '\n';
131         if (!headsep.empty())
132                 os << "\\headsep "
133                    << VSpace(headsep).asLyXCommand() << '\n';
134         if (!footskip.empty())
135                 os << "\\footskip "
136                    << VSpace(footskip).asLyXCommand() << '\n';
137         os << "\\secnumdepth " << secnumdepth
138            << "\n\\tocdepth " << tocdepth
139            << "\n\\paragraph_separation "
140            << string_paragraph_separation[paragraph_separation]
141            << "\n\\defskip " << defskip.asLyXCommand()
142            << "\n\\quotes_language "
143            << string_quotes_language[quotes_language] << '\n';
144         switch(quotes_times) {
145                 // An output operator for insetquotes would be nice
146         case InsetQuotes::SingleQ:
147                 os << "\\quotes_times 1\n"; break;
148         case InsetQuotes::DoubleQ: 
149                 os << "\\quotes_times 2\n"; break;
150         }
151         os << "\\papercolumns " << columns
152            << "\n\\papersides " << sides
153            << "\n\\paperpagestyle " << pagestyle << '\n';
154         for (int i = 0; i < 4; ++i) {
155                 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
156                         if (user_defined_bullets[i].getFont() != -1) {
157                                 os << "\\bullet " << i
158                                    << "\n\t"
159                                    << user_defined_bullets[i].getFont()
160                                    << "\n\t"
161                                    << user_defined_bullets[i].getCharacter()
162                                    << "\n\t"
163                                    << user_defined_bullets[i].getSize()
164                                    << "\n\\end_bullet\n";
165                         }
166                         else {
167                                 os << "\\bulletLaTeX " << i
168                                    << "\n\t"
169                                    << user_defined_bullets[i].c_str()
170                                    << "\n\\end_bullet\n";
171                         }
172                 }
173         }
174 }
175
176
177 void BufferParams::useClassDefaults() {
178         LyXTextClass const & tclass = textclasslist.TextClass(textclass);
179
180         sides = tclass.sides();
181         columns = tclass.columns();
182         pagestyle = tclass.pagestyle();
183         options = tclass.options();
184         secnumdepth = tclass.secnumdepth();
185         tocdepth = tclass.tocdepth();
186 }
187
188
189 void BufferParams::readPreamble(LyXLex & lex)
190 {
191         if (lex.GetString() != "\\begin_preamble")
192                 lyxerr << "Error (BufferParams::readPreamble):"
193                         "consistency check failed." << endl;
194
195         preamble = lex.getLongString("\\end_preamble");
196 }
197
198
199 void BufferParams::readLanguage(LyXLex & lex)
200 {
201         if (!lex.next()) return;
202         
203         string tmptok = lex.GetString();
204
205         // check if tmptok is part of tex_babel in tex-defs.h
206         Languages::iterator lit = languages.find(tmptok);
207         if (lit != languages.end()) {
208                 // found it
209                 language = tmptok;
210                 language_info = &(*lit).second;
211         } else {
212                 // not found
213                 language = "default";
214                 language_info = default_language;
215                 if (tmptok != "default") {
216                         lyxerr << "Warning: language `"
217                                << tmptok << "' not recognized!\n"
218                                << "         Setting language to `default'."
219                                << endl;
220                 }
221         }
222 }
223
224
225 void BufferParams::readGraphicsDriver(LyXLex & lex)
226 {
227         string tmptok;
228         string test;
229         int n = 0;
230         
231         
232         if (!lex.next()) return;
233         
234         tmptok = lex.GetString();
235         // check if tmptok is part of tex_graphics in tex_defs.h
236         while (true) {
237                 test = tex_graphics[n++];
238                 
239                 if (test == tmptok) {    
240                         graphicsDriver = tmptok;
241                         break;
242                 }      
243                 else if (test == "last_item") {
244                         lex.printError(
245                                 "Warning: graphics driver `$$Token' not recognized!\n"
246                                 "         Setting graphics driver to `default'.\n");
247                         graphicsDriver = "default";
248                         break;
249                 }      
250         }
251 }