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
This commit is contained in:
Jürgen Vigna 2002-01-08 14:24:49 +00:00
parent 685c37df7f
commit 9a5f7d1fe4
15 changed files with 290 additions and 165 deletions

View File

@ -1,3 +1,13 @@
2002-01-08 Juergen Vigna <jug@sad.it>
* 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 <a.leeming@ic.ac.uk>
* lyx_gui.C (init): set the style of the menu popups to

View File

@ -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);
}

View File

@ -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,

View File

@ -1,3 +1,9 @@
2002-01-08 Juergen Vigna <jug@sad.it>
* 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 <jug@sad.it>
* insettext.C (getLyXText): Fixed this function. An insert into the

View File

@ -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()

View File

@ -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:
///

View File

@ -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{
///

View File

@ -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_;

View File

@ -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;

View File

@ -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?

View File

@ -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;
}

View File

@ -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
///

View File

@ -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;
if (params().startOfAppendix()) {
os << "\\appendix\n";
texrow.newline();
}
if (!params().spacing().isDefault()
&& (!previous() || !previous()->hasSameLayout(this))) {
os << params().spacing().writeEnvirBegin() << "\n";
texrow.newline();
}
LyXLayout style;
if (tex_code_break_column && style.isCommand()){
os << '\n';
texrow.newline();
}
// 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().pagebreakTop()) {
os << "\\newpage";
further_blank_line = true;
}
if (params().spaceTop().kind() != VSpace::NONE) {
os << params().spaceTop().asLatexCommand(bparams);
further_blank_line = true;
}
if (params().startOfAppendix()) {
os << "\\appendix\n";
texrow.newline();
}
if (params().lineTop()) {
os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
<< "\\vspace{-1\\parskip}";
further_blank_line = true;
}
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 (further_blank_line){
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().lineTop()) {
os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
<< "\\vspace{-1\\parskip}";
further_blank_line = true;
}
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;
if (!asdefault) {
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;
}
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;
}
}
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;
}
}
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;
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_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;
}
}
lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
return return_value;

View File

@ -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) {

View File

@ -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);
}