- column = 0;
- } else {
- SimpleTeXSpecialChars(file, texrow,
- font, running_font, basefont,
- open_font, style, i, column, c);
- }
- }
-
- // If we have an open font definition, we have to close it
- if (open_font) {
- running_font.latexWriteEndChanges(file, basefont, basefont);
- }
-
- // Needed if there is an optional argument but no contents.
- if (main_body > 0 && main_body == size()) {
- file += "]~";
- return_value = false;
- }
-
- lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
- return return_value;
-}
-
-
-// This one spits out the text of a table paragraph
-bool LyXParagraph::SimpleTeXOneTablePar(string & file, TexRow & texrow)
-{
- lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
-
- bool return_value = false;
-
- LyXLayout const & style =
- textclasslist.Style(current_view->buffer()->params.textclass,
- GetLayout());
-
- int column = 0;
- if (!IsDummy()) { // it is dummy if it is in a float!!!
- if (style.isCommand()) {
- file += '{';
- ++column;
- } else if (align != LYX_ALIGN_LAYOUT) {
- file += '{';
- ++column;
- return_value = true;
- }
- if (noindent) {
- file += "\\noindent ";
- column += 10;
- }
- switch (align) {
- case LYX_ALIGN_NONE:
- case LYX_ALIGN_BLOCK:
- case LYX_ALIGN_LAYOUT:
- case LYX_ALIGN_SPECIAL: break;
- case LYX_ALIGN_LEFT:
- file += "\\raggedright ";
- column+= 13;
- break;
- case LYX_ALIGN_RIGHT:
- file += "\\raggedleft ";
- column+= 12;
- break;
- case LYX_ALIGN_CENTER:
- file += "\\centering ";
- column+= 11;
- break;
- }
- }
-
- LyXFont basefont = getFont(-1); // Get layout font
- // Which font is currently active?
- LyXFont running_font = basefont;
- LyXFont last_font;
- // Do we have an open font change?
- bool open_font = false;
- int current_cell_number = -1;
- int tmp = table->TexEndOfCell(file, current_cell_number);
- for (; tmp > 0 ; --tmp)
- texrow.newline();
-
- texrow.start(this, 0);
-
- for (size_type i = 0; i < size(); ++i) {
- char c = GetChar(i);
- if (table->IsContRow(current_cell_number + 1)) {
- if (c == LyXParagraph::META_NEWLINE)
- ++current_cell_number;
- continue;
- }
- ++column;
-
- // Fully instantiated font
- LyXFont font = getFont(i);
- last_font = running_font;
-
- // Spaces at end of font change are simulated to be
- // outside font change.
- // i.e. we write "\textXX{text} " rather than
- // "\textXX{text }". (Asger)
- if (open_font && c == ' ' && i <= size() - 2
- && getFont(i+1) != running_font && getFont(i+1) != font) {
- font = getFont(i+1);
- }
-
- // We end font definition before blanks
- if (font != running_font && open_font) {
- column += running_font.latexWriteEndChanges(file,
- basefont, font);
- running_font = basefont;
- open_font = false;
- }
- // Blanks are printed before start of fontswitch
- if (c == ' '){
- SimpleTeXBlanks(file, texrow, i, column, font, style);
- }
- // Do we need to change font?
- if (font != running_font) {
- column += font.latexWriteStartChanges(file, basefont, last_font);
- running_font = font;
- open_font = true;
- }
- // Do we need to turn on LaTeX mode?
- if (font.latex() != running_font.latex()) {
- if (font.latex() == LyXFont::ON
- && style.needprotect) {
- file += "\\protect ";
- column += 9;
- }
- }
- if (c == LyXParagraph::META_NEWLINE) {
- // special case for inside a table
- // different from default case in
- // SimpleTeXSpecialChars()
- if (open_font) {
- column += running_font
- .latexWriteEndChanges(file, basefont, basefont);
- open_font = false;
- }
- basefont = getFont(-1);
- running_font = basefont;
- ++current_cell_number;
- if (table->CellHasContRow(current_cell_number) >= 0) {
- TeXContTableRows(file, i + 1,
- current_cell_number,
- column, texrow);
- }
- // if this cell follow only ContRows till end don't
- // put the EndOfCell because it is put after the
- // for(...)
- if (table->ShouldBeVeryLastCell(current_cell_number)) {
- --current_cell_number;
- break;
- }
- int tmp = table->TexEndOfCell(file,
- current_cell_number);
- if (tmp > 0) {
- column = 0;
- } else if (tmp < 0) {
- tmp = -tmp;
- }
- for (; tmp--;) {
- texrow.newline();
- }
- texrow.start(this, i + 1);
- } else {
- SimpleTeXSpecialChars(file, texrow,
- font, running_font, basefont,
- open_font, style, i, column, c);
- }
- }
-
- // If we have an open font definition, we have to close it
- if (open_font) {
- running_font.latexWriteEndChanges(file, basefont, basefont);
- }
- ++current_cell_number;
- tmp = table->TexEndOfCell(file, current_cell_number);
- for (; tmp > 0; --tmp)
- texrow.newline();
- lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
- return return_value;
-}
-
-
-// This one spits out the text off ContRows in tables
-bool LyXParagraph::TeXContTableRows(string & file,
- LyXParagraph::size_type i,
- int current_cell_number,
- int & column, TexRow & texrow)
-{
- lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
- if (!table)
- return false;
-
- char c;
-
- bool return_value = false;
- LyXLayout const & style =
- textclasslist.Style(current_view->buffer()->params.textclass,
- GetLayout());
- LyXFont basefont = getFont(-1); // Get layout font
- LyXFont last_font;
- // Which font is currently active?
- LyXFont running_font = basefont;
- // Do we have an open font change?
- bool open_font = false;
-
- size_type lastpos = i;
- int cell = table->CellHasContRow(current_cell_number);
- ++current_cell_number;
- while(cell >= 0) {
- // first find the right position
- i = lastpos;
- for (; (i < size()) && (current_cell_number<cell); ++i) {
- c = GetChar(i);
- if (c == LyXParagraph::META_NEWLINE)
- ++current_cell_number;
- }
- lastpos = i;
- c = GetChar(i);
- if (table->Linebreaks(table->FirstVirtualCell(cell))) {
- file += " \\\\\n";
- texrow.newline();
- column = 0;
- } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
- file += ' ';
- }
-
- for (; i < size()
- && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
- ++i) {
- ++column;
-
- // Fully instantiated font
- LyXFont font = getFont(i);
- last_font = running_font;
-
- // Spaces at end of font change are simulated to
- // be outside font change. i.e. we write
- // "\textXX{text} " rather than "\textXX{text }".
- // (Asger)
- if (open_font && c == ' ' && i <= size() - 2
- && getFont(i + 1) != running_font
- && getFont(i + 1) != font) {
- font = getFont(i + 1);
- }
-
- // We end font definition before blanks
- if (font != running_font && open_font) {
- column += running_font.latexWriteEndChanges(file, basefont, font);
- running_font = basefont;
- open_font = false;
- }
- // Blanks are printed before start of fontswitch
- if (c == ' '){
- SimpleTeXBlanks(file, texrow, i,
- column, font, style);
- }
- // Do we need to change font?
- if (font != running_font) {
- column +=
- font.latexWriteStartChanges(file,
- basefont, last_font);
- running_font = font;
- open_font = true;
- }
- // Do we need to turn on LaTeX mode?
- if (font.latex() != running_font.latex()) {
- if (font.latex() == LyXFont::ON
- && style.needprotect)
- {
- file += "\\protect ";
- column += 9;
- }
- }
- SimpleTeXSpecialChars(file, texrow, font,
- running_font, basefont,
- open_font, style, i, column, c);
- }
- // If we have an open font definition, we have to close it
- if (open_font) {
- running_font.latexWriteEndChanges(file, basefont, basefont);
- open_font = false;
- }
- basefont = getFont(-1);
- running_font = basefont;
- cell = table->CellHasContRow(current_cell_number);
- }
- lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
- return return_value;
-}
-
-
-bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
-{
- bool retval = false;
- switch (c) {
- case LyXParagraph::META_HFILL:
- sgml_string.clear();
- break;
- case LyXParagraph::META_PROTECTED_SEPARATOR:
- sgml_string = ' ';
- break;
- case LyXParagraph::META_NEWLINE:
- sgml_string = '\n';
- break;
- case '&':
- sgml_string = "&";
- break;
- case '<':
- sgml_string = "<";
- break;
- case '>':
- sgml_string = ">";
- break;
- case '$':
- sgml_string = "$";
- break;
- case '#':
- sgml_string = "#";
- break;
- case '%':
- sgml_string = "%";
- break;
- case '[':
- sgml_string = "[";
- break;
- case ']':
- sgml_string = "]";
- break;
- case '{':
- sgml_string = "{";
- break;
- case '}':
- sgml_string = "}";
- break;
- case '~':
- sgml_string = "˜";
- break;
- case '"':
- sgml_string = """;
- break;
- case '\\':
- sgml_string = "\";
- break;
- case ' ':
- retval = true;
- sgml_string = ' ';
- break;
- case '\0': // Ignore :-)
- sgml_string.clear();
- break;
- default:
- sgml_string = c;
- break;
- }
- return retval;
-}
-
-
-void LyXParagraph::SimpleDocBookOneTablePar(string & file, string & extra,
- int & desc_on, int depth)
-{
- if (!table) return;
- lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
- int column = 0;
- LyXFont font1, font2;
- char c;
- Inset * inset;
- size_type main_body;
- string emph = "emphasis";
- bool emph_flag = false;
-
- LyXLayout const & style =
- textclasslist.Style(current_view->buffer()->params.textclass,
- GetLayout());
-
- if (style.labeltype != LABEL_MANUAL)
- main_body = 0;
- else
- main_body = BeginningOfMainBody();
-
- // Gets paragraph main font.
- if (main_body > 0)
- font1 = style.labelfont;
- else
- font1 = style.font;
-
- int char_line_count = depth;
- addNewlineAndDepth(file, depth);
- if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
- file += "<INFORMALTABLE>";
- addNewlineAndDepth(file, ++depth);
- }
- int current_cell_number = -1;
- int tmp = table->DocBookEndOfCell(file, current_cell_number, depth);
-
- // Parsing main loop.
- for (size_type i = 0; i < size(); ++i) {
- c = GetChar(i);
- if (table->IsContRow(current_cell_number+1)) {
- if (c == LyXParagraph::META_NEWLINE)
- ++current_cell_number;
- continue;
- }
- ++column;
-
- // Fully instantiated font
- font2 = getFont(i);
-
- // Handle <emphasis> tag.
- if (font1.emph() != font2.emph() && i) {
- if (font2.emph() == LyXFont::ON) {
- file += "<emphasis>";
- emph_flag= true;
- } else if (emph_flag) {
- file += "</emphasis>";
- emph_flag= false;
- }
- }
- if (c == LyXParagraph::META_NEWLINE) {
- // We have only to control for emphasis open here!
- if (emph_flag) {
- file += "</emphasis>";
- emph_flag= false;
- }
- font1 = font2 = getFont(-1);
- ++current_cell_number;
- if (table->CellHasContRow(current_cell_number) >= 0) {
- DocBookContTableRows(file, extra, desc_on, i+1,
- current_cell_number,
- column);
- }
- // if this cell follow only ContRows till end don't
- // put the EndOfCell because it is put after the
- // for(...)
- if (table->ShouldBeVeryLastCell(current_cell_number)) {
- --current_cell_number;
- break;
- }
- tmp = table->DocBookEndOfCell(file,
- current_cell_number,
- depth);
-
- if (tmp > 0)
- column = 0;
- } else if (c == LyXParagraph::META_INSET) {
- inset = GetInset(i);
- string tmp_out;
- inset->DocBook(tmp_out);
- //
- // This code needs some explanation:
- // Two insets are treated specially
- // label if it is the first element in a
- // command paragraph
- // desc_on == 3
- // graphics inside tables or figure floats
- // can't go on
- // title (the equivalente in latex for this
- // case is caption
- // and title should come first
- // desc_on == 4
- //
- if(desc_on != 3 || i != 0) {
- if(tmp_out[0] == '@') {
- if(desc_on == 4)
- extra += frontStrip(tmp_out,
- '@');
- else
- file += frontStrip(tmp_out,
- '@');
- } else
- file += tmp_out;
- }
- } else if (font2.latex() == LyXFont::ON) {
- // "TeX"-Mode on == > SGML-Mode on.
- if (c != '\0')
- file += c;
- ++char_line_count;
- } else {
- string sgml_string;
- if (linuxDocConvertChar(c, sgml_string)
- && !style.free_spacing) {
- // in freespacing mode, spaces are
- // non-breaking characters
- // char is ' '
- if (desc_on == 1) {
- ++char_line_count;
- file += '\n';
- file += "</term><listitem><para>";
- desc_on = 2;
- } else {
- file += c;
- }
- } else {
- file += sgml_string;
- }
- }
- font1 = font2;
- }
-
- // Needed if there is an optional argument but no contents.
- if (main_body > 0 && main_body == size()) {
- font1 = style.font;
- }
-
- if (emph_flag) {
- file += "</emphasis>";
- }
-
- ++current_cell_number;
- tmp = table->DocBookEndOfCell(file, current_cell_number, depth);
- // Resets description flag correctly.
- switch(desc_on){
- case 1:
- // <term> not closed...
- file += "</term>";
- break;
- }
- if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
- file += "</INFORMALTABLE>";
- file += '\n';
- lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
- << this << endl;
-}
-
-
-void LyXParagraph::DocBookContTableRows(string & file, string & extra,
- int & desc_on,
- LyXParagraph::size_type i,
- int current_cell_number, int &column)
-
-{
- if (!table) return;
-
- lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
-
- LyXFont font2;
- char c;
- Inset * inset;
- string emph= "emphasis";
- bool emph_flag= false;
- int char_line_count= 0;
-
- LyXLayout const & style =
- textclasslist.Style(current_view->buffer()->params.textclass,
- GetLayout());
-
- size_type main_body;
- if (style.labeltype != LABEL_MANUAL)
- main_body = 0;
- else
- main_body = BeginningOfMainBody();
-
- // Gets paragraph main font.
- LyXFont font1;
- if (main_body > 0)
- font1 = style.labelfont;
- else
- font1 = style.font;
-
- size_type lastpos = i;
- int cell = table->CellHasContRow(current_cell_number);
- ++current_cell_number;
- while(cell >= 0) {
- // first find the right position
- i = lastpos;
- for (; i < size() && current_cell_number < cell; ++i) {
- c = GetChar(i);
- if (c == LyXParagraph::META_NEWLINE)
- ++current_cell_number;
- }
- lastpos = i;
- c = GetChar(i);
- // I don't know how to handle this so I comment it
- // for the moment (Jug)
-// if (table->Linebreaks(table->FirstVirtualCell(cell))) {
-// file += " \\\\\n";
-// column = 0;
-// } else
- if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
- file += ' ';
- }
-
- for (; i < size()
- && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
- ++i) {
- ++column;
-
- // Fully instantiated font
- font2 = getFont(i);
-
- // Handle <emphasis> tag.
- if (font1.emph() != font2.emph() && i) {
- if (font2.emph() == LyXFont::ON) {
- file += "<emphasis>";
- emph_flag= true;
- } else if (emph_flag) {
- file += "</emphasis>";
- emph_flag= false;
- }
- }
- if (c == LyXParagraph::META_INSET) {
- inset = GetInset(i);
- string tmp_out;
- inset->DocBook(tmp_out);
- //
- // This code needs some explanation:
- // Two insets are treated specially
- // label if it is the first element in a
- // command paragraph
- // desc_on == 3
- // graphics inside tables or figure floats
- // can't go on title (the equivalente in
- // latex for this case is caption and title
- // should come first
- // desc_on == 4
- //
- if(desc_on != 3 || i != 0) {
- if(tmp_out[0] == '@') {
- if(desc_on == 4)
- extra += frontStrip(tmp_out, '@');
- else
- file += frontStrip(tmp_out, '@');
- } else
- file += tmp_out;
- }
- } else if (font2.latex() == LyXFont::ON) {
- // "TeX"-Mode on == > SGML-Mode on.
- if (c!= '\0')
- file += c;
- ++char_line_count;
- } else {
- string sgml_string;
- if (linuxDocConvertChar(c, sgml_string)
- && !style.free_spacing) {
- // in freespacing mode, spaces are
- // non-breaking characters
- // char is ' '
- if (desc_on == 1) {
- ++char_line_count;
- file += '\n';
- file += "</term><listitem><para>";
- desc_on = 2;
- } else {
- file += c;
- }
- } else {
- file += sgml_string;
- }
- }
- }
- // we have only to control for emphasis open here!
- if (emph_flag) {
- file += "</emphasis>";
- emph_flag= false;