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 "ParagraphParameters.h"
24 #include "support/gzstream.h"
25 #include "support/lstrings.h"
30 using lyx::support::ascii_lowercase;
31 using lyx::support::compare_ascii_no_case;
32 using lyx::support::compare_no_case;
33 using lyx::support::contains;
43 void writeFileAscii(Buffer const & buf,
45 OutputParams const & runparams)
48 if (!::openFileWrite(ofs, fname))
50 writeFileAscii(buf, ofs, runparams);
54 void writeFileAscii(Buffer const & buf,
56 OutputParams const & runparams)
58 Buffer & tmp = const_cast<Buffer &>(buf);
59 ParagraphList par = const_cast<ParagraphList&>(tmp.paragraphs());
60 ParagraphList::iterator beg = par.begin();
61 ParagraphList::iterator end = par.end();
62 ParagraphList::iterator it = beg;
63 for (; it != end; ++it) {
64 asciiParagraph(buf, *it, os, runparams, it == beg);
72 pair<int, string> const addDepth(int depth, int ldepth)
76 d += (ldepth - depth) * 2;
77 return make_pair(d, string(d, ' '));
83 void asciiParagraph(Buffer const & buf,
84 Paragraph const & par,
86 OutputParams const & runparams,
90 Paragraph::depth_type ltype_depth = 0;
91 bool ref_printed = false;
92 Paragraph::depth_type depth = par.params().depth();
94 // First write the layout
95 string const & tmp = par.layout()->name();
96 if (compare_no_case(tmp, "itemize") == 0) {
98 ltype_depth = depth + 1;
99 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
101 ltype_depth = depth + 1;
102 } else if (contains(ascii_lowercase(tmp), "ection")) {
104 ltype_depth = depth + 1;
105 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
107 ltype_depth = depth + 1;
108 } else if (compare_ascii_no_case(tmp, "description") == 0) {
110 ltype_depth = depth + 1;
111 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
114 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
122 /* maybe some vertical spaces */
124 /* the labelwidthstring used in lists */
128 /* some pagebreaks? */
132 /* what about the alignment */
134 // runparams.linelen <= 0 is special and means we don't have paragraph breaks
136 string::size_type currlinelen = 0;
139 if (runparams.linelen > 0)
142 os << string(depth * 2, ' ');
143 currlinelen += depth * 2;
146 // we should probably change to the paragraph language in the
147 // gettext here (if possible) so that strings are output in
148 // the correct language! (20012712 Jug)
152 case 4: // (Sub)Paragraph
153 case 5: // Description
157 if (runparams.linelen > 0) {
158 os << _("Abstract") << "\n\n";
161 string const abst = _("Abstract: ");
163 currlinelen += abst.length();
167 case 7: // Bibliography
169 if (runparams.linelen > 0) {
170 os << _("References") << "\n\n";
173 string const refs = _("References: ");
175 currlinelen += refs.length();
182 string const label = par.params().labelString();
184 currlinelen += label.length() + 1;
192 pair<int, string> p = addDepth(depth, ltype_depth);
194 currlinelen += p.first;
197 // this is to change the linebreak to do it by word a bit more
198 // intelligent hopefully! (only in the case where we have a
199 // max runparams.linelength!) (Jug)
203 for (pos_type i = 0; i < par.size(); ++i) {
204 char c = par.getUChar(buf.params(), i);
206 case Paragraph::META_INSET: {
207 InsetBase const * inset = par.getInset(i);
208 if (runparams.linelen > 0) {
210 currlinelen += word.length();
213 if (inset->plaintext(buf, os, runparams)) {
214 // to be sure it breaks paragraph
215 currlinelen += runparams.linelen;
221 if (runparams.linelen > 0 &&
222 currlinelen + word.length() > runparams.linelen - 10) {
224 pair<int, string> p = addDepth(depth, ltype_depth);
226 currlinelen = p.first;
229 currlinelen += word.length() + 1;
234 lyxerr[Debug::INFO] <<
235 "writeAsciiFile: NULL char in structure." << endl;
240 if (runparams.linelen > 0 &&
241 currlinelen + word.length() > runparams.linelen)
244 pair<int, string> p = addDepth(depth, ltype_depth);
246 currlinelen = p.first;