1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 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"
31 BufferParams::BufferParams()
33 paragraph_separation = PARSEP_INDENT;
34 defskip = VSpace(VSpace::MEDSKIP);
35 quotes_language = InsetQuotes::EnglishQ;
36 quotes_times = InsetQuotes::DoubleQ;
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
42 textclass = textclasslist.NumberOfClass("article").second;
45 papersize = PAPER_DEFAULT;
46 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
47 paperpackage = PACKAGE_NONE;
48 orientation = ORIENTATION_PORTRAIT;
53 language = default_language;
56 graphicsDriver = "default";
57 sides = LyXTextClass::OneSide;
59 pagestyle = "default";
60 for(int iter = 0; iter < 4; ++iter) {
61 user_defined_bullets[iter] = temp_bullets[iter]
62 = ITEMIZE_DEFAULTS[iter];
67 void BufferParams::writeFile(ostream & os) const
69 // The top of the file is written by the buffer.
70 // Prints out the buffer info into the .lyx file given by file
73 os << "\\textclass " << textclasslist.NameOfClass(textclass) << '\n';
75 // then the the preamble
76 if (!preamble.empty()) {
77 // remove '\n' from the end of preamble
78 string tmppreamble = strip(preamble, '\n');
79 os << "\\begin_preamble\n"
81 << "\n\\end_preamble\n";
85 if (!options.empty()) {
86 os << "\\options " << options << '\n';
89 /* then the text parameters */
90 os << "\\language " << language->lang()
91 << "\n\\inputencoding " << inputenc
92 << "\n\\fontscheme " << fonts
93 << "\n\\graphics " << graphicsDriver << '\n';
95 if (!float_placement.empty()) {
96 os << "\\float_placement " << float_placement << '\n';
98 os << "\\paperfontsize " << fontsize << '\n';
100 spacing.writeFile(os);
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]
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())
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())
131 << VSpace(headsep).asLyXCommand() << '\n';
132 if (!footskip.empty())
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;
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
157 << user_defined_bullets[i].getFont()
159 << user_defined_bullets[i].getCharacter()
161 << user_defined_bullets[i].getSize()
162 << "\n\\end_bullet\n";
165 os << "\\bulletLaTeX " << i
167 << user_defined_bullets[i].getText()
168 << "\n\\end_bullet\n";
175 void BufferParams::useClassDefaults() {
176 LyXTextClass const & tclass = textclasslist.TextClass(textclass);
178 sides = tclass.sides();
179 columns = tclass.columns();
180 pagestyle = tclass.pagestyle();
181 options = tclass.options();
182 secnumdepth = tclass.secnumdepth();
183 tocdepth = tclass.tocdepth();
187 void BufferParams::readPreamble(LyXLex & lex)
189 if (lex.GetString() != "\\begin_preamble")
190 lyxerr << "Error (BufferParams::readPreamble):"
191 "consistency check failed." << endl;
193 preamble = lex.getLongString("\\end_preamble");
197 void BufferParams::readLanguage(LyXLex & lex)
199 if (!lex.next()) return;
201 string tmptok = lex.GetString();
203 // check if tmptok is part of tex_babel in tex-defs.h
204 language = languages.getLanguage(tmptok);
206 // Language tmptok was not found
207 language = default_language;
208 lyxerr << "Warning: language `"
209 << tmptok << "' not recognized!\n"
210 << " Setting language to `" << language->lang()
216 void BufferParams::readGraphicsDriver(LyXLex & lex)
223 if (!lex.next()) return;
225 tmptok = lex.GetString();
226 // check if tmptok is part of tex_graphics in tex_defs.h
228 test = tex_graphics[n++];
230 if (test == tmptok) {
231 graphicsDriver = tmptok;
234 else if (test == "last_item") {
236 "Warning: graphics driver `$$Token' not recognized!\n"
237 " Setting graphics driver to `default'.\n");
238 graphicsDriver = "default";