From: Jürgen Vigna Date: Tue, 8 Jan 2002 14:24:49 +0000 (+0000) Subject: Fixed rowbreaking for "character"-insets and ignore all paragraph attributes X-Git-Tag: 1.6.10~20070 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=9a5f7d1fe43ddbc1308f69bc609825ac9d618922;p=features.git Fixed rowbreaking for "character"-insets and ignore all paragraph attributes when the cell is not fixed lenght in a tabular on LaTeX output! git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3315 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index 98ef9bd13d..2521921a5f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2002-01-08 Juergen Vigna + + * text.C (nextBreakPoint): use function Inset::isChar(). + + * paragraph.C (TeXOnePar): use function + Inset::forceDefaultParagraphs. + + * buffer.C (latexParagraphs): use function + Inset::forceDefaultParagraphs. + 2002-01-07 Angus Leeming * lyx_gui.C (init): set the style of the menu popups to diff --git a/src/buffer.C b/src/buffer.C index bd51584ec7..20bd850f45 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -2524,33 +2524,41 @@ void Buffer::makeLaTeXFile(string const & fname, // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end // void Buffer::latexParagraphs(ostream & ofs, Paragraph * par, - Paragraph * endpar, TexRow & texrow) const + Paragraph * endpar, TexRow & texrow) const { bool was_title = false; bool already_title = false; // if only_body while (par != endpar) { - LyXLayout const & layout = - textclasslist.Style(params.textclass, - par->layout); + Inset * in = par->inInset(); + // well we have to check if we are in an inset with unlimited + // lenght (all in one row) if that is true then we don't allow + // any special options in the paragraph and also we don't allow + // any environment other then "Standard" to be valid! + if ((in == 0) || !in->forceDefaultParagraphs(in)) { + LyXLayout const & layout = + textclasslist.Style(params.textclass, par->layout); if (layout.intitle) { - if (already_title) { - lyxerr <<"Error in latexParagraphs: You" - " should not mix title layouts" - " with normal ones." << endl; - } else - was_title = true; + if (already_title) { + lyxerr <<"Error in latexParagraphs: You" + " should not mix title layouts" + " with normal ones." << endl; + } else + was_title = true; } else if (was_title && !already_title) { - ofs << "\\maketitle\n"; - texrow.newline(); - already_title = true; - was_title = false; - } - - if (layout.isEnvironment()) { - par = par->TeXEnvironment(this, params, ofs, texrow); + ofs << "\\maketitle\n"; + texrow.newline(); + already_title = true; + was_title = false; + } + + if (layout.isEnvironment()) { + par = par->TeXEnvironment(this, params, ofs, texrow); + } else { + par = par->TeXOnePar(this, params, ofs, texrow, false); + } } else { par = par->TeXOnePar(this, params, ofs, texrow, false); } diff --git a/src/buffer.h b/src/buffer.h index cd8c55d7cf..4110e4e768 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -161,7 +161,7 @@ public: \param \a endpar if == 0 then to the end */ void latexParagraphs(std::ostream & os, Paragraph * par, - Paragraph * endpar, TexRow & texrow) const; + Paragraph * endpar, TexRow & texrow) const; /// void simpleDocBookOnePar(std::ostream &, Paragraph * par, int & desc_on, diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 1c0c8b36a1..db17dd44dd 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,9 @@ +2002-01-08 Juergen Vigna + + * inset.h: added isChar() function and implemented this for + insetspecialchar insetquotes and insetlatexaccent. + added forceDefaultParagraphs() and implemented it for insettabular. + 2002-01-07 Juergen Vigna * insettext.C (getLyXText): Fixed this function. An insert into the diff --git a/src/insets/inset.C b/src/insets/inset.C index bda005592d..9673978b3d 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -145,6 +145,15 @@ void Inset::id(int id_arg) void Inset::setFont(BufferView *, LyXFont const &, bool, bool ) {} + +bool Inset::forceDefaultParagraphs(Inset const * in) const +{ + if (owner()) + return owner()->forceDefaultParagraphs(in); + return false; +} + + // some stuff for inset locking UpdatableInset::UpdatableInset() diff --git a/src/insets/inset.h b/src/insets/inset.h index bc0ed0aae8..77f58f7b32 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -305,10 +305,15 @@ public: /// virtual bool allowSpellcheck() { return false; } + // should this inset be handled like a normal charater + virtual bool isChar() const { return false; } // is this equivalent to a letter? virtual bool isLetter() const { return false; } // is this equivalent to a space? virtual bool isSpace() const { return false; } + // if this inset has paragraphs should they be outputed all as default + // paragraps with "Standard" layout? + virtual bool forceDefaultParagraphs(Inset const *) const; protected: /// diff --git a/src/insets/insetlatexaccent.h b/src/insets/insetlatexaccent.h index b1fefd5570..4d4713b39a 100644 --- a/src/insets/insetlatexaccent.h +++ b/src/insets/insetlatexaccent.h @@ -72,6 +72,9 @@ public: Inset::Code lyxCode()const; /// inline bool canDisplay(); + // should this inset be handled like a normal charater + bool isChar() const { return true; } + /// all the accent types enum ACCENT_TYPES{ /// diff --git a/src/insets/insetquotes.h b/src/insets/insetquotes.h index d6f117f6bb..60592c8f86 100644 --- a/src/insets/insetquotes.h +++ b/src/insets/insetquotes.h @@ -103,6 +103,9 @@ public: virtual Inset * clone(Buffer const &, bool same_id = false) const; /// Inset::Code lyxCode() const; + // should this inset be handled like a normal charater + bool isChar() const { return true; } + private: /// quote_language language_; diff --git a/src/insets/insetspecialchar.C b/src/insets/insetspecialchar.C index 5de4d19e84..ae2704cb30 100644 --- a/src/insets/insetspecialchar.C +++ b/src/insets/insetspecialchar.C @@ -324,6 +324,12 @@ void InsetSpecialChar::validate(LaTeXFeatures & features) const } +bool InsetSpecialChar::isChar() const +{ + return true; +} + + bool InsetSpecialChar::isLetter() const { return kind_ == HYPHENATION || kind_ == LIGATURE_BREAK; diff --git a/src/insets/insetspecialchar.h b/src/insets/insetspecialchar.h index 5acb4e22ac..721dfaebf1 100644 --- a/src/insets/insetspecialchar.h +++ b/src/insets/insetspecialchar.h @@ -82,6 +82,9 @@ public: }; /// void validate(LaTeXFeatures &) const; + + // should this inset be handled like a normal charater + bool isChar() const; /// is this equivalent to a letter? bool isLetter() const; /// is this equivalent to a space? diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 37c8139131..2b8125df35 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -2778,3 +2778,37 @@ bool InsetTabular::insetAllowed(Inset::Code code) const return the_locking_inset->insetAllowed(code); return false; } + + +bool InsetTabular::forceDefaultParagraphs(Inset const * in) const +{ + int const n = tabular->GetNumberOfCells(); + static int last = 0; + + // maybe some speedup + if ((last < n) && tabular->GetCellInset(last) == in) { + if (tabular->GetPWidth(last+1).zero()) + return true; + return false; + } + if ((++last < n) && tabular->GetCellInset(last) == in) { + if (tabular->GetPWidth(last).zero()) + return true; + return false; + } + + for(int i=0; i < n; ++i) { + if (tabular->GetCellInset(i) == in) { + last = i; + if (tabular->GetPWidth(i).zero()) + return true; + return false; + } + } + last = 0; + // well we didn't obviously find it so maybe our owner knows more + if (owner()) + return owner()->forceDefaultParagraphs(in); + // if we're here there is really something strange going on!!! + return false; +} diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index e495a272d9..d054ae0d2c 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -222,6 +222,10 @@ public: bool searchBackward(BufferView *, string const &, bool const & = true, bool const & = false); + // this should return true if we have a "normal" cell, otherwise true. + // "normal" means without width set! + bool forceDefaultParagraphs(Inset const * in) const; + // // Public structures and variables /// diff --git a/src/paragraph.C b/src/paragraph.C index f3d909649e..2e3a09feb9 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1221,51 +1221,59 @@ int Paragraph::getPositionOfInset(Inset const * inset) const Paragraph * Paragraph::TeXOnePar(Buffer const * buf, - BufferParams const & bparams, - ostream & os, TexRow & texrow, - bool moving_arg) + BufferParams const & bparams, + ostream & os, TexRow & texrow, + bool moving_arg) { lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl; - LyXLayout const & style = - textclasslist.Style(bparams.textclass, - layout); - + Inset const * in = inInset(); bool further_blank_line = false; + LyXLayout style; + + // well we have to check if we are in an inset with unlimited + // lenght (all in one row) if that is true then we don't allow + // any special options in the paragraph and also we don't allow + // any environment other then "Standard" to be valid! + if ((in == 0) || !in->forceDefaultParagraphs(in)) { + style = textclasslist.Style(bparams.textclass, layout); + + if (params().startOfAppendix()) { + os << "\\appendix\n"; + texrow.newline(); + } - if (params().startOfAppendix()) { - os << "\\appendix\n"; - texrow.newline(); - } - - if (!params().spacing().isDefault() - && (!previous() || !previous()->hasSameLayout(this))) { - os << params().spacing().writeEnvirBegin() << "\n"; - texrow.newline(); - } + if (!params().spacing().isDefault() + && (!previous() || !previous()->hasSameLayout(this))) { + os << params().spacing().writeEnvirBegin() << "\n"; + texrow.newline(); + } - if (tex_code_break_column && style.isCommand()){ - os << '\n'; - texrow.newline(); - } + if (tex_code_break_column && style.isCommand()){ + os << '\n'; + texrow.newline(); + } - if (params().pagebreakTop()) { - os << "\\newpage"; - further_blank_line = true; - } - if (params().spaceTop().kind() != VSpace::NONE) { - os << params().spaceTop().asLatexCommand(bparams); - further_blank_line = true; - } + if (params().pagebreakTop()) { + os << "\\newpage"; + further_blank_line = true; + } + if (params().spaceTop().kind() != VSpace::NONE) { + os << params().spaceTop().asLatexCommand(bparams); + further_blank_line = true; + } - if (params().lineTop()) { - os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}' - << "\\vspace{-1\\parskip}"; - further_blank_line = true; - } + if (params().lineTop()) { + os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}' + << "\\vspace{-1\\parskip}"; + further_blank_line = true; + } - if (further_blank_line){ - os << '\n'; - texrow.newline(); + if (further_blank_line){ + os << '\n'; + texrow.newline(); + } + } else { + style = textclasslist.Style(bparams.textclass, 0); } Language const * language = getParLanguage(bparams); @@ -1275,22 +1283,24 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf, if (language->babel() != previous_language->babel() // check if we already put language command in TeXEnvironment() - && !(textclasslist.Style(bparams.textclass, layout).isEnvironment() - && (!previous() || previous()->layout != layout || - previous()->params().depth() != params().depth()))) { - + && !(style.isEnvironment() + && (!previous() || previous()->layout != layout || + previous()->params().depth() != params().depth()))) + { if (!lyxrc.language_command_end.empty() && - previous_language->babel() != doc_language->babel()) { + previous_language->babel() != doc_language->babel()) + { os << subst(lyxrc.language_command_end, "$$lang", - previous_language->babel()) + previous_language->babel()) << endl; texrow.newline(); } if (lyxrc.language_command_end.empty() || - language->babel() != doc_language->babel()) { + language->babel() != doc_language->babel()) + { os << subst(lyxrc.language_command_begin, "$$lang", - language->babel()) + language->babel()) << endl; texrow.newline(); } @@ -1336,11 +1346,10 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf, // or for a command. LyXFont const font = (size() == 0 - ? getLayoutFont(bparams) - : getFont(bparams, size() - 1)); + ? getLayoutFont(bparams) : getFont(bparams, size() - 1)); - bool is_command = textclasslist.Style(bparams.textclass, - getLayout()).isCommand(); + bool is_command = style.isCommand(); + if (style.resfont.size() != font.size() && next_ && !is_command) { if (!need_par) os << "{"; @@ -1374,31 +1383,33 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf, } } - further_blank_line = false; - if (params().lineBottom()) { - os << "\\lyxline{\\" << font.latexSize() << '}'; - further_blank_line = true; - } + if ((in == 0) || !in->forceDefaultParagraphs(in)) { + further_blank_line = false; + if (params().lineBottom()) { + os << "\\lyxline{\\" << font.latexSize() << '}'; + further_blank_line = true; + } - if (params().spaceBottom().kind() != VSpace::NONE) { - os << params().spaceBottom().asLatexCommand(bparams); - further_blank_line = true; - } + if (params().spaceBottom().kind() != VSpace::NONE) { + os << params().spaceBottom().asLatexCommand(bparams); + further_blank_line = true; + } - if (params().pagebreakBottom()) { - os << "\\newpage"; - further_blank_line = true; - } + if (params().pagebreakBottom()) { + os << "\\newpage"; + further_blank_line = true; + } - if (further_blank_line){ - os << '\n'; - texrow.newline(); - } + if (further_blank_line){ + os << '\n'; + texrow.newline(); + } - if (!params().spacing().isDefault() - && (!next_ || !next_->hasSameLayout(this))) { - os << params().spacing().writeEnvirEnd() << "\n"; - texrow.newline(); + if (!params().spacing().isDefault() + && (!next_ || !next_->hasSameLayout(this))) { + os << params().spacing().writeEnvirEnd() << "\n"; + texrow.newline(); + } } // we don't need it for the last paragraph!!! @@ -1432,17 +1443,29 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf, // This one spits out the text of the paragraph bool Paragraph::simpleTeXOnePar(Buffer const * buf, - BufferParams const & bparams, - ostream & os, TexRow & texrow, - bool moving_arg) + BufferParams const & bparams, + ostream & os, TexRow & texrow, + bool moving_arg) { lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl; bool return_value = false; - LyXLayout const & style = - textclasslist.Style(bparams.textclass, - getLayout()); + LyXLayout style; + + // well we have to check if we are in an inset with unlimited + // lenght (all in one row) if that is true then we don't allow + // any special options in the paragraph and also we don't allow + // any environment other then "Standard" to be valid! + bool asdefault = + (inInset() && inInset()->forceDefaultParagraphs(inInset())); + + if (asdefault) { + style = textclasslist.Style(bparams.textclass, 0); + } else { + style = textclasslist.Style(bparams.textclass, layout); + } + LyXFont basefont; // Maybe we have to create a optional argument. @@ -1497,39 +1520,42 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf, ++column; } - if (params().noindent()) { - os << "\\noindent "; - column += 10; - } - switch (params().align()) { - case LYX_ALIGN_NONE: - case LYX_ALIGN_BLOCK: - case LYX_ALIGN_LAYOUT: - case LYX_ALIGN_SPECIAL: - break; - case LYX_ALIGN_LEFT: - if (getParLanguage(bparams)->babel() != "hebrew") { - os << "\\begin{flushleft}"; - column += 17; - } else { - os << "\\begin{flushright}"; - column += 18; + if (!asdefault) { + if (params().noindent()) { + os << "\\noindent "; + column += 10; } - break; - case LYX_ALIGN_RIGHT: - if (getParLanguage(bparams)->babel() != "hebrew") { - os << "\\begin{flushright}"; - column += 18; - } else { - os << "\\begin{flushleft}"; - column += 17; + + switch (params().align()) { + case LYX_ALIGN_NONE: + case LYX_ALIGN_BLOCK: + case LYX_ALIGN_LAYOUT: + case LYX_ALIGN_SPECIAL: + break; + case LYX_ALIGN_LEFT: + if (getParLanguage(bparams)->babel() != "hebrew") { + os << "\\begin{flushleft}"; + column += 17; + } else { + os << "\\begin{flushright}"; + column += 18; + } + break; + case LYX_ALIGN_RIGHT: + if (getParLanguage(bparams)->babel() != "hebrew") { + os << "\\begin{flushright}"; + column += 18; + } else { + os << "\\begin{flushleft}"; + column += 17; + } + break; + case LYX_ALIGN_CENTER: + os << "\\begin{center}"; + column += 14; + break; } - break; - case LYX_ALIGN_CENTER: - os << "\\begin{center}"; - column += 14; - break; - } + } } value_type c = getChar(i); @@ -1636,35 +1662,37 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf, return_value = false; } - switch (params().align()) { - case LYX_ALIGN_NONE: - case LYX_ALIGN_BLOCK: - case LYX_ALIGN_LAYOUT: - case LYX_ALIGN_SPECIAL: - break; - case LYX_ALIGN_LEFT: - if (getParLanguage(bparams)->babel() != "hebrew") { - os << "\\end{flushleft}"; - column+= 15; - } else { - os << "\\end{flushright}"; - column+= 16; - } - break; - case LYX_ALIGN_RIGHT: - if (getParLanguage(bparams)->babel() != "hebrew") { - os << "\\end{flushright}"; - column+= 16; - } else { - os << "\\end{flushleft}"; - column+= 15; + if (!asdefault) { + switch (params().align()) { + case LYX_ALIGN_NONE: + case LYX_ALIGN_BLOCK: + case LYX_ALIGN_LAYOUT: + case LYX_ALIGN_SPECIAL: + break; + case LYX_ALIGN_LEFT: + if (getParLanguage(bparams)->babel() != "hebrew") { + os << "\\end{flushleft}"; + column+= 15; + } else { + os << "\\end{flushright}"; + column+= 16; + } + break; + case LYX_ALIGN_RIGHT: + if (getParLanguage(bparams)->babel() != "hebrew") { + os << "\\end{flushright}"; + column+= 16; + } else { + os << "\\end{flushleft}"; + column+= 15; + } + break; + case LYX_ALIGN_CENTER: + os << "\\end{center}"; + column+= 12; + break; } - break; - case LYX_ALIGN_CENTER: - os << "\\end{center}"; - column+= 12; - break; - } + } lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl; return return_value; diff --git a/src/support/textutils.h b/src/support/textutils.h index fa077d035a..5a48efcc38 100644 --- a/src/support/textutils.h +++ b/src/support/textutils.h @@ -47,6 +47,13 @@ bool IsLineSeparatorChar(char c) { } +/// +inline +bool IsLineSeparatorChar(char c, Inset * in) { + return ((c == ' ') || (in && in->isSpace())); +} + + /// inline bool IsKommaChar(char c) { diff --git a/src/text.C b/src/text.C index 543971669a..f86bdf8650 100644 --- a/src/text.C +++ b/src/text.C @@ -955,26 +955,25 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const while (doitonetime || ((x < width) && (i < last))) { doitonetime = false; char const c = par->getChar(i); + Inset * in = 0; + if (c == Paragraph::META_INSET) + in = par->getInset(i); if (IsNewlineChar(c)) { last_separator = i; x = width; // this means break - } else if (c == Paragraph::META_INSET && - par->getInset(i)) { - + } else if (in && !in->isChar()) { // check wether a Display() inset is // valid here. if not, change it to // non-display - if (par->getInset(i)->display() && + if (in->display() && (layout.isCommand() || (layout.labeltype == LABEL_MANUAL && i < beginningOfMainBody(bview->buffer(), par)))) { // display istn't allowd - par->getInset(i)->display(false); + in->display(false); x += singleWidth(bview, par, i, c); - } else if (par->getInset(i)->display() || - par->getInset(i)->needFullRow()) - { + } else if (in->display() || in->needFullRow()) { // So break the line here if (i == pos) { if (pos < last-1) { @@ -1000,7 +999,7 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const last_separator = i - 1; } } else { - if (IsLineSeparatorChar(c)) + if (IsLineSeparatorChar(c, in)) last_separator = i; x += singleWidth(bview, par, i, c); }