2 * \file output_plaintext.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
13 #include "output_plaintext.h"
16 #include "bufferparams.h"
20 #include "outputparams.h"
21 #include "paragraph.h"
22 #include "ParagraphList_fwd.h"
23 #include "ParagraphParameters.h"
25 #include "support/gzstream.h"
26 #include "support/lstrings.h"
28 using lyx::support::ascii_lowercase;
29 using lyx::support::compare_ascii_no_case;
30 using lyx::support::compare_no_case;
31 using lyx::support::contains;
41 void writeFileAscii(Buffer const & buf,
43 OutputParams const & runparams)
46 if (!::openFileWrite(ofs, fname))
48 writeFileAscii(buf, ofs, runparams);
52 void writeFileAscii(Buffer const & buf, ostream & os,
53 OutputParams const & runparams)
55 ParagraphList const par = buf.paragraphs();
56 ParagraphList::const_iterator beg = par.begin();
57 ParagraphList::const_iterator end = par.end();
58 ParagraphList::const_iterator it = beg;
59 for (; it != end; ++it) {
60 asciiParagraph(buf, *it, os, runparams, it == beg);
68 pair<int, string> const addDepth(int depth, int ldepth)
72 d += (ldepth - depth) * 2;
73 return make_pair(d, string(d, ' '));
79 void asciiParagraph(Buffer const & buf,
80 Paragraph const & par,
82 OutputParams const & runparams,
86 Paragraph::depth_type ltype_depth = 0;
87 static bool ref_printed = false;
88 Paragraph::depth_type depth = par.params().depth();
90 // First write the layout
91 string const & tmp = par.layout()->name();
92 if (compare_no_case(tmp, "itemize") == 0) {
94 ltype_depth = depth + 1;
95 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
97 ltype_depth = depth + 1;
98 } else if (contains(ascii_lowercase(tmp), "ection")) {
100 ltype_depth = depth + 1;
101 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
103 ltype_depth = depth + 1;
104 } else if (compare_ascii_no_case(tmp, "description") == 0) {
106 ltype_depth = depth + 1;
107 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
110 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
118 /* maybe some vertical spaces */
120 /* the labelwidthstring used in lists */
124 /* some pagebreaks? */
128 /* what about the alignment */
130 // runparams.linelen <= 0 is special and means we don't have paragraph breaks
132 string::size_type currlinelen = 0;
135 if (runparams.linelen > 0)
138 os << string(depth * 2, ' ');
139 currlinelen += depth * 2;
142 // we should probably change to the paragraph language in the
143 // gettext here (if possible) so that strings are output in
144 // the correct language! (20012712 Jug)
148 case 4: // (Sub)Paragraph
149 case 5: // Description
153 if (runparams.linelen > 0) {
154 os << _("Abstract") << "\n\n";
157 string const abst = _("Abstract: ");
159 currlinelen += abst.length();
163 case 7: // Bibliography
165 if (runparams.linelen > 0) {
166 os << _("References") << "\n\n";
169 string const refs = _("References: ");
171 currlinelen += refs.length();
178 string const label = par.params().labelString();
180 currlinelen += label.length() + 1;
188 pair<int, string> p = addDepth(depth, ltype_depth);
190 currlinelen += p.first;
193 // this is to change the linebreak to do it by word a bit more
194 // intelligent hopefully! (only in the case where we have a
195 // max runparams.linelength!) (Jug)
199 for (pos_type i = 0; i < par.size(); ++i) {
200 char c = par.getUChar(buf.params(), i);
202 case Paragraph::META_INSET: {
203 InsetBase const * inset = par.getInset(i);
204 if (runparams.linelen > 0) {
206 currlinelen += word.length();
209 OutputParams rp = runparams;
210 rp.depth = par.params().depth();
211 if (inset->plaintext(buf, os, rp)) {
212 // to be sure it breaks paragraph
213 currlinelen += runparams.linelen;
219 if (runparams.linelen > 0 &&
220 currlinelen + word.length() > runparams.linelen - 10) {
222 pair<int, string> p = addDepth(depth, ltype_depth);
224 currlinelen = p.first;
227 currlinelen += word.length() + 1;
232 lyxerr[Debug::INFO] <<
233 "writeAsciiFile: NULL char in structure." << endl;
238 if (runparams.linelen > 0 &&
239 currlinelen + word.length() > runparams.linelen)
242 pair<int, string> p = addDepth(depth, ltype_depth);
244 currlinelen = p.first;