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