1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
15 #pragma implementation "bufferparams.h"
18 #include "bufferparams.h"
19 #include "tex-strings.h"
23 #include "support/lyxlib.h"
24 #include "support/lstrings.h"
26 BufferParams::BufferParams()
28 paragraph_separation = PARSEP_INDENT;
29 defskip = VSpace(VSpace::MEDSKIP);
30 quotes_language = InsetQuotes::EnglishQ;
31 quotes_times = InsetQuotes::DoubleQ;
33 // Initialize textclass to point to article. if `first' is
34 // true in the returned pair, then `second' is the textclass
35 // number; if it is false, second is 0. In both cases, second
37 textclass = textclasslist.NumberOfClass("article").second;
40 papersize = PAPER_DEFAULT;
41 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
42 paperpackage = PACKAGE_NONE;
43 orientation = ORIENTATION_PORTRAIT;
51 graphicsDriver = "default";
52 sides = LyXTextClass::OneSide;
54 pagestyle = "default";
55 for(int iter = 0; iter < 4; iter++) {
56 user_defined_bullets[iter] = temp_bullets[iter]
57 = ITEMIZE_DEFAULTS[iter];
63 void BufferParams::writeFile(ostream & os)
65 // The top of the file is written by the buffer.
66 // Prints out the buffer info into the .lyx file given by file
69 os << "\\textclass " << textclasslist.NameOfClass(textclass) << '\n';
71 // then the the preamble
72 if (!preamble.empty()) {
73 // remove '\n' from the end of preamble
74 preamble = strip(preamble, '\n');
75 os << "\\begin_preamble\n"
77 << "\n\\end_preamble\n";
81 if (!options.empty()) {
82 os << "\\options " << options << '\n';
85 /* then the text parameters */
86 os << "\\language " << language
87 << "\n\\inputencoding " << inputenc
88 << "\n\\fontscheme " << fonts
89 << "\n\\graphics " << graphicsDriver << '\n';
91 if (!float_placement.empty()) {
92 os << "\\float_placement " << float_placement << '\n';
94 os << "\\paperfontsize " << fontsize << '\n';
96 spacing.writeFile(os);
98 os << "\\papersize " << string_papersize[papersize2]
99 << "\n\\paperpackage " << string_paperpackages[paperpackage]
100 << "\n\\use_geometry " << use_geometry
101 << "\n\\use_amsmath " << use_amsmath
102 << "\n\\paperorientation " << string_orientation[orientation]
104 if (!paperwidth.empty())
105 os << "\\paperwidth "
106 << VSpace(paperwidth).asLyXCommand() << '\n';
107 if (!paperheight.empty())
108 os << "\\paperheight "
109 << VSpace(paperheight).asLyXCommand() << '\n';
110 if (!leftmargin.empty())
111 os << "\\leftmargin "
112 << VSpace(leftmargin).asLyXCommand() << '\n';
113 if (!topmargin.empty())
115 << VSpace(topmargin).asLyXCommand() << '\n';
116 if (!rightmargin.empty())
117 os << "\\rightmargin "
118 << VSpace(rightmargin).asLyXCommand() << '\n';
119 if (!bottommargin.empty())
120 os << "\\bottommargin "
121 << VSpace(bottommargin).asLyXCommand() << '\n';
122 if (!headheight.empty())
123 os << "\\headheight "
124 << VSpace(headheight).asLyXCommand() << '\n';
125 if (!headsep.empty())
127 << VSpace(headsep).asLyXCommand() << '\n';
128 if (!footskip.empty())
130 << VSpace(footskip).asLyXCommand() << '\n';
131 os << "\\secnumdepth " << secnumdepth
132 << "\n\\tocdepth " << tocdepth
133 << "\n\\paragraph_separation "
134 << string_paragraph_separation[paragraph_separation]
135 << "\n\\defskip " << defskip.asLyXCommand()
136 << "\n\\quotes_language "
137 << string_quotes_language[quotes_language] << '\n';
138 switch(quotes_times) {
139 // An output operator for insetquotes would be nice
140 case InsetQuotes::SingleQ:
141 os << "\\quotes_times 1\n"; break;
142 case InsetQuotes::DoubleQ:
143 os << "\\quotes_times 2\n"; break;
145 os << "\\papercolumns " << columns
146 << "\n\\papersides " << sides
147 << "\n\\paperpagestyle " << pagestyle << '\n';
148 for (int i = 0; i < 4; ++i) {
149 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
150 if (user_defined_bullets[i].getFont() != -1) {
151 os << "\\bullet " << i
153 << user_defined_bullets[i].getFont()
155 << user_defined_bullets[i].getCharacter()
157 << user_defined_bullets[i].getSize()
158 << "\n\\end_bullet\n";
161 os << "\\bulletLaTeX " << i
163 << user_defined_bullets[i].c_str()
164 << "\n\\end_bullet\n";
171 void BufferParams::useClassDefaults() {
172 LyXTextClass const & tclass = textclasslist.TextClass(textclass);
174 sides = tclass.sides();
175 columns = tclass.columns();
176 pagestyle = tclass.pagestyle();
177 options = tclass.options();
178 secnumdepth = tclass.secnumdepth();
179 tocdepth = tclass.tocdepth();
183 void BufferParams::readPreamble(LyXLex & lex)
185 if (lex.GetString() != "\\begin_preamble")
186 lyxerr << "Error (BufferParams::readPreamble):"
187 "consistency check failed." << endl;
189 preamble = lex.getLongString("\\end_preamble");
193 void BufferParams::readLanguage(LyXLex & lex)
195 if (!lex.next()) return;
197 string tmptok = lex.GetString();
200 // check if tmptok is part of tex_babel in tex-defs.h
202 test = tex_babel[n++];
204 if (test == tmptok) {
208 else if (test.empty()) {
209 lyxerr << "Warning: language `"
210 << tmptok << "' not recognized!\n"
211 << " Setting language to `default'."
213 language = "default";
220 void BufferParams::readGraphicsDriver(LyXLex & lex)
227 if (!lex.next()) return;
229 tmptok = lex.GetString();
230 // check if tmptok is part of tex_graphics in tex_defs.h
232 test = tex_graphics[n++];
234 if (test == tmptok) {
235 graphicsDriver = tmptok;
238 else if (test == "last_item") {
240 "Warning: graphics driver `$$Token' not recognized!\n"
241 " Setting graphics driver to `default'.\n");
242 graphicsDriver = "default";