2001-12-27 Juergen Vigna <jug@sad.it>
+ * buffer.C (asciiParagraph): more fixes.
+
+ * tabular.C (ascii): make ascii export support export of only the
+ data separated by a column-delimiter.
+ (ascii): better support for ascii export.
+
* buffer.C (asciiParagraph): rewrote to hopefully work as expected!
2001-12-26 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
string const Buffer::asciiParagraph(Paragraph const * par,
- unsigned int linelen) const
+ unsigned int linelen,
+ bool noparbreak) const
{
ostringstream buffer;
ostringstream word;
Paragraph::depth_type ltype_depth = 0;
string::size_type currlinelen = 0;
bool ref_printed = false;
-
- int noparbreak = 0;
// if (!par->previous()) {
#if 0
// begins or ends a deeper area ?
if (inset) {
if (linelen > 0)
buffer << word.str();
- if (inset->ascii(this, buffer)) {
+ if (inset->ascii(this, buffer, linelen)) {
// to be sure it breaks paragraph
currlinelen += linelen;
}
{
Paragraph * par = paragraph;
while (par) {
- ofs << asciiParagraph(par, linelen);
+ ofs << asciiParagraph(par, linelen, par->previous() == 0);
par = par->next();
}
ofs << "\n";
///
void writeFileAscii(std::ostream &, int);
///
- string const asciiParagraph(Paragraph const *,
- unsigned int linelen) const;
+ string const asciiParagraph(Paragraph const *, unsigned int linelen,
+ bool noparbreak = false) const;
///
void makeLaTeXFile(string const & filename,
string const & original_path,
+2001-12-27 Juergen Vigna <jug@sad.it>
+
+ * insettabular.C (ascii): export as tab-separated-values if the
+ function was not called from export (f.ex.: clipboard).
+
+ * insetcollapsable.h: added default support for ascii, linuxdoc and
+ docbook export (the insettext is exported by default!)
+
+ * insettabular.C (copySelection): suff the clipboard with the tabular
+ data in a tab separated format, seems more naturals then with all the
+ formating.
+
2001-12-24 Juergen Vigna <jug@sad.it>
* insettext.C (insetMotionNotify): added a mouse_x & mouse_y position
bool free_spc) const = 0;
///
virtual int ascii(Buffer const *,
- std::ostream &, int linelen = 0) const = 0;
+ std::ostream &, int linelen = 0) const = 0;
///
virtual int linuxdoc(Buffer const *, std::ostream &) const = 0;
///
return inset.latex(buf, os, fragile, free_spc);
}
+
+int InsetCollapsable::ascii(Buffer const *buf, std::ostream & os, int ll) const
+{
+ return inset.ascii(buf, os, ll);
+}
+
+
+int InsetCollapsable::linuxdoc(Buffer const *buf, std::ostream & os) const
+{
+ return inset.linuxdoc(buf, os);
+}
+
+
+int InsetCollapsable::docbook(Buffer const *buf, std::ostream & os) const
+{
+ return inset.docbook(buf, os);
+}
+
#if 0
int InsetCollapsable::getMaxWidth(BufferView * bv,
UpdatableInset const * in) const
int latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
///
- int ascii(Buffer const *, std::ostream &, int) const { return 0; }
+ int ascii(Buffer const *, std::ostream &, int) const;
///
- int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
+ int linuxdoc(Buffer const *, std::ostream &) const;
///
- int docbook(Buffer const *, std::ostream &) const { return 0; }
+ int docbook(Buffer const *, std::ostream &) const;
///
void validate(LaTeXFeatures & features) const;
///
#include "BufferView.h"
#include "undo_funcs.h"
#include "lyxlength.h"
+#include "ParagraphParameters.h"
#include "frontends/Dialogs.h"
#include "frontends/Alert.h"
int InsetTabular::latex(Buffer const * buf, ostream & os,
- bool fragile, bool fp) const
+ bool fragile, bool fp) const
{
- return tabular->Latex(buf, os, fragile, fp);
+ return tabular->latex(buf, os, fragile, fp);
}
-int InsetTabular::ascii(Buffer const * buf, ostream & os, int) const
+int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
{
- // This should be changed to a real ascii export
- return tabular->Ascii(buf, os);
+ if (ll > 0)
+ return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
+ false,0);
+ return tabular->ascii(buf, os, 0, false,0);
}
int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
{
- return tabular->Ascii(buf,os);
+ return tabular->ascii(buf,os, (int)parOwner()->params().depth(), false, 0);
}
os << "<informaltable>\n";
ret++;
}
- ret+= tabular->DocBook(buf,os);
+ ret+= tabular->docBook(buf,os);
if (!master) {
os << "</informaltable>\n";
ret++;
true, true);
ostringstream sstr;
- paste_tabular->Ascii(bv->buffer(), sstr);
+ paste_tabular->ascii(bv->buffer(), sstr,
+ (int)parOwner()->params().depth(), true, '\t');
bv->stuffClipboard(sstr.str().c_str());
return true;
}
unsigned int lines = 0;
while (p) {
- string const tmp = buf->asciiParagraph(p, linelen);
+ string const tmp = buf->asciiParagraph(p, linelen, p->previous()==0);
lines += countChar(tmp, '\n');
os << tmp;
p = p->next();
}
-int LyXTabular::Latex(Buffer const * buf,
+int LyXTabular::latex(Buffer const * buf,
ostream & os, bool fragile, bool fp) const
{
int ret = 0;
}
-int LyXTabular::DocBook(Buffer const * buf, ostream & os) const
+int LyXTabular::docBook(Buffer const * buf, ostream & os) const
{
int ret = 0;
return ret;
}
-
-namespace {
-
- inline
- void print_n_chars(ostream & os, unsigned char ch, int n)
- {
- os << string(n, ch);
- }
-
-} // namespace anon
-
-
-int LyXTabular::AsciiTopHLine(ostream & os, int row,
- vector<unsigned int> const & clen) const
+//--
+// ASCII export function and helpers
+//--
+int LyXTabular::asciiTopHLine(ostream & os, int row,
+ vector<unsigned int> const & clen) const
{
int const fcell = GetFirstCellInRow(row);
int const n = NumberOfCellsInRow(fcell) + fcell;
int len = clen[column];
while (IsPartOfMultiColumn(row, ++column))
len += clen[column] + 4;
- print_n_chars(os, ch, len);
+ os << string(len, ch);
if (TopLine(i)) {
if (RightLine(i))
os << "-+";
}
-int LyXTabular::AsciiBottomHLine(ostream & os, int row,
- vector<unsigned int> const & clen) const
+int LyXTabular::asciiBottomHLine(ostream & os, int row,
+ vector<unsigned int> const & clen) const
{
int const fcell = GetFirstCellInRow(row);
int const n = NumberOfCellsInRow(fcell) + fcell;
int len = clen[column];
while (IsPartOfMultiColumn(row, ++column))
len += clen[column] + 4;
- print_n_chars(os, ch, len);
+ os << string(len, ch);
if (BottomLine(i)) {
if (RightLine(i))
os << "-+";
}
-int LyXTabular::AsciiPrintCell(Buffer const * buf, ostream & os,
- int cell, int row, int column,
- vector<unsigned int> const & clen) const
+int LyXTabular::asciiPrintCell(Buffer const * buf, ostream & os,
+ int cell, int row, int column,
+ vector<unsigned int> const & clen,
+ bool onlydata) const
{
ostringstream sstr;
int ret = GetCellInset(cell)->ascii(buf, sstr, 0);
+ if (onlydata) {
+ os << sstr.str();
+ return ret;
+ }
+
if (LeftLine(cell))
os << "| ";
else
}
-int LyXTabular::Ascii(Buffer const * buf, ostream & os) const
+int LyXTabular::ascii(Buffer const * buf, ostream & os, int const depth,
+ bool onlydata, unsigned char delim) const
{
int ret = 0;
//+---------------------------------------------------------------------
vector<unsigned int> clen(columns_);
- // first all non (real) multicolumn cells!
- for (int j = 0; j < columns_; ++j) {
- clen[j] = 0;
- for (int i = 0; i < rows_; ++i) {
- int cell = GetCellNumber(i, j);
- if (IsMultiColumn(cell, true))
- continue;
- ostringstream sstr;
- GetCellInset(cell)->ascii(buf, sstr, 0);
- if (clen[j] < sstr.str().length())
- clen[j] = sstr.str().length();
+ if (!onlydata) {
+ // first all non (real) multicolumn cells!
+ for (int j = 0; j < columns_; ++j) {
+ clen[j] = 0;
+ for (int i = 0; i < rows_; ++i) {
+ int cell = GetCellNumber(i, j);
+ if (IsMultiColumn(cell, true))
+ continue;
+ ostringstream sstr;
+ GetCellInset(cell)->ascii(buf, sstr, 0);
+ if (clen[j] < sstr.str().length())
+ clen[j] = sstr.str().length();
+ }
}
- }
- // then all (real) multicolumn cells!
- for (int j = 0; j < columns_; ++j) {
- for (int i = 0; i < rows_; ++i) {
- int cell = GetCellNumber(i, j);
- if (!IsMultiColumn(cell, true) || IsPartOfMultiColumn(i, j))
- continue;
- ostringstream sstr;
- GetCellInset(cell)->ascii(buf, sstr, 0);
- int len = int(sstr.str().length());
- int const n = cells_in_multicolumn(cell);
- for (int k = j; (len > 0) && (k < (j + n - 1)); ++k)
- len -= clen[k];
- if (len > int(clen[j + n - 1]))
- clen[j + n - 1] = len;
+ // then all (real) multicolumn cells!
+ for (int j = 0; j < columns_; ++j) {
+ for (int i = 0; i < rows_; ++i) {
+ int cell = GetCellNumber(i, j);
+ if (!IsMultiColumn(cell, true) || IsPartOfMultiColumn(i, j))
+ continue;
+ ostringstream sstr;
+ GetCellInset(cell)->ascii(buf, sstr, 0);
+ int len = int(sstr.str().length());
+ int const n = cells_in_multicolumn(cell);
+ for (int k = j; (len > 0) && (k < (j + n - 1)); ++k)
+ len -= clen[k];
+ if (len > int(clen[j + n - 1]))
+ clen[j + n - 1] = len;
+ }
}
}
int cell = 0;
for (int i = 0; i < rows_; ++i) {
- AsciiTopHLine(os, i, clen);
+ if (!onlydata) {
+ if (asciiTopHLine(os, i, clen)) {
+ for (int j = 0; j < depth; ++j)
+ os << " ";
+ }
+ }
for (int j = 0; j < columns_; ++j) {
if (IsPartOfMultiColumn(i,j))
continue;
- ret += AsciiPrintCell(buf, os, cell, i, j, clen);
+ if (onlydata && j > 0)
+ os << delim;
+ ret += asciiPrintCell(buf, os, cell, i, j, clen, onlydata);
++cell;
}
os << endl;
- AsciiBottomHLine(os, i, clen);
+ if (!onlydata) {
+ for (int j = 0; j < depth; ++j)
+ os << " ";
+ if (asciiBottomHLine(os, i, clen)) {
+ for (int j = 0; j < depth; ++j)
+ os << " ";
+ }
+ }
}
return ret;
}
+//--
+// end ascii export
+//--
InsetText * LyXTabular::GetCellInset(int cell) const
void Read(Buffer const *, LyXLex &);
///
void OldFormatRead(LyXLex &, string const &);
- //
- // helper function for Latex returns number of newlines
- ///
- int TeXTopHLine(std::ostream &, int row) const;
- ///
- int TeXBottomHLine(std::ostream &, int row) const;
- ///
- int TeXCellPreamble(std::ostream &, int cell) const;
- ///
- int TeXCellPostamble(std::ostream &, int cell) const;
- ///
- int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
- bool fragile, bool fp) const;
- ///
- bool isValidRow(int const row) const;
- ///
- int TeXRow(std::ostream &, int const row, Buffer const * buf,
- bool fragile, bool fp) const;
- ///
- int Latex(Buffer const *, std::ostream &, bool, bool) const;
- /// auxiliary function for docbook rows
- int docbookRow(Buffer const * buf, std::ostream & os, int row) const;
- ///
- int DocBook(Buffer const * buf, std::ostream & os) const;
- ///
- // helper function for Latex returns number of newlines
- ///
- int AsciiTopHLine(std::ostream &, int row,
- std::vector<unsigned int> const &) const;
///
- int AsciiBottomHLine(std::ostream &, int row,
- std::vector<unsigned int> const &) const;
+ int latex(Buffer const *, std::ostream &, bool, bool) const;
///
- int AsciiPrintCell(Buffer const *, std::ostream &,
- int cell, int row, int column,
- std::vector<unsigned int> const &) const;
+ int docBook(Buffer const * buf, std::ostream & os) const;
///
- int Ascii(Buffer const *, std::ostream &) const;
+ int ascii(Buffer const *, std::ostream &, int const depth,
+ bool onlydata, unsigned char delim) const;
///
bool IsMultiColumn(int cell, bool real = false) const;
///
BoxType UseParbox(int cell) const;
///
void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
+ ///
+ // helper function for Latex returns number of newlines
+ ///
+ int TeXTopHLine(std::ostream &, int row) const;
+ ///
+ int TeXBottomHLine(std::ostream &, int row) const;
+ ///
+ int TeXCellPreamble(std::ostream &, int cell) const;
+ ///
+ int TeXCellPostamble(std::ostream &, int cell) const;
+ ///
+ int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
+ bool fragile, bool fp) const;
+ ///
+ bool isValidRow(int const row) const;
+ ///
+ int TeXRow(std::ostream &, int const row, Buffer const * buf,
+ bool fragile, bool fp) const;
+ ///
+ // helper function for ASCII returns number of newlines
+ ///
+ int asciiTopHLine(std::ostream &, int row,
+ std::vector<unsigned int> const &) const;
+ ///
+ int asciiBottomHLine(std::ostream &, int row,
+ std::vector<unsigned int> const &) const;
+ ///
+ int asciiPrintCell(Buffer const *, std::ostream &,
+ int cell, int row, int column,
+ std::vector<unsigned int> const &,
+ bool onlydata) const;
+ /// auxiliary function for docbook
+ int docbookRow(Buffer const * buf, std::ostream & os, int row) const;
};
#endif