From 13a21fe51072c5a2757b7687690c96c140f88936 Mon Sep 17 00:00:00 2001 From: John Levon Date: Sat, 7 Jun 2003 17:45:43 +0000 Subject: [PATCH] minimal ERT spacing patch (first patch sent to list plus a couple of fixes) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7134 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 11 +++++++++++ src/buffer.C | 14 ++++++-------- src/insets/ChangeLog | 5 +++++ src/insets/insetert.C | 4 ++-- src/insets/insetgraphics.C | 8 +++++++- src/paragraph.C | 15 ++++++++++++++- src/paragraph.h | 5 ++++- src/paragraph_funcs.C | 5 ++--- src/paragraph_pimpl.C | 3 +-- src/text.C | 9 ++++----- src/text2.C | 2 +- 11 files changed, 57 insertions(+), 24 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 14da15ca4f..27ac7e4f7d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2003-06-07 John Levon + + * buffer.C: + * paragraph_funcs.C: + * paragraph_pimpl.C: + * text.C: + * text2.C: + * paragraph.h: + * paragraph.C: allow InsetERT to freely space lines, + and some consolidation of code + 2003-06-06 José Matos * buffer.C (makeDocBookFile): fix bug #821 diff --git a/src/buffer.C b/src/buffer.C index 0562d3e7a8..1fd247b510 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -414,7 +414,7 @@ void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos, for(string::const_iterator cit = str.begin(); cit != str.end(); ++cit) { if (*cit == '\n') { - if (autobreakrows && (!par->empty() || layout->keepempty)) { + if (autobreakrows && (!par->empty() || par->allowEmpty())) { breakParagraph(params, paragraphs, par, pos, layout->isEnvironment()); ++par; @@ -425,12 +425,10 @@ void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos, } // do not insert consecutive spaces if !free_spacing } else if ((*cit == ' ' || *cit == '\t') && - space_inserted && !layout->free_spacing && - !par->isFreeSpacing()) - { + space_inserted && !par->isFreeSpacing()) { continue; } else if (*cit == '\t') { - if (!layout->free_spacing && !par->isFreeSpacing()) { + if (!par->isFreeSpacing()) { // tabs are like spaces here par->insertChar(pos, ' ', font); ++pos; @@ -1522,7 +1520,7 @@ void Buffer::simpleLinuxDocOnePar(ostream & os, bool ws; string str; boost::tie(ws, str) = sgml::escapeChar(c); - if (ws && !style->free_spacing && !par->isFreeSpacing()) { + if (ws && !par->isFreeSpacing()) { // in freespacing mode, spaces are // non-breaking characters if (desc_on) {// if char is ' ' then... @@ -1907,9 +1905,9 @@ void Buffer::simpleDocBookOnePar(ostream & os, if (style->pass_thru) { os << c; - } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') { + } else if (par->isFreeSpacing() || c != ' ') { os << str; - } else if (desc_on ==1) { + } else if (desc_on == 1) { ++char_line_count; os << "\n"; desc_on = 2; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 4b03c88d47..35fbc6fb33 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2003-06-07 John Levon + + * insetert.C (latex): make a newline mean just that not + a new par + 2003-06-07 José Matos * insethfill.[Ch] (linuxdoc, docbook): implement output diff --git a/src/insets/insetert.C b/src/insets/insetert.C index f7c10d35b3..4a6888091f 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -346,8 +346,8 @@ int InsetERT::latex(Buffer const *, ostream & os, } ++par; if (par != end) { - os << "\n\n"; - lines += 2; + os << "\n"; + ++lines; } } diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index afe19346e2..ee09479850 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -330,8 +330,12 @@ string const InsetGraphics::prepareFile(Buffer const * buf, string orig_file = params().filename; string const rel_file = MakeRelPath(orig_file, buf->filePath()); - if (!IsFileReadable(rel_file)) + if (!IsFileReadable(orig_file)) { + lyxerr[Debug::GRAPHICS] + << "InsetGraphics::prepareFile\n" + << "No file '" << orig_file << "' can be found!" << endl; return rel_file; + } bool const zipped = zippedFile(orig_file); @@ -521,6 +525,8 @@ int InsetGraphics::latex(Buffer const * buf, ostream & os, (before + '{' + relative_file + " not found!}" + after); os << latex_str; + lyxerr[Debug::GRAPHICS] << "InsetGraphics::latex outputting:\n" + << latex_str << endl; // Return how many newlines we issued. return int(lyx::count(latex_str.begin(), latex_str.end(),'\n') + 1); } diff --git a/src/paragraph.C b/src/paragraph.C index 0da1d96d2c..5d711ee3c0 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -623,7 +623,7 @@ void Paragraph::makeSameLayout(Paragraph const & par) int Paragraph::stripLeadingSpaces() { - if (layout()->free_spacing || isFreeSpacing()) + if (isFreeSpacing()) return 0; int i = 0; @@ -1409,6 +1409,9 @@ ParagraphParameters const & Paragraph::params() const bool Paragraph::isFreeSpacing() const { + if (layout()->free_spacing) + return true; + // for now we just need this, later should we need this in some // other way we can always add a function to Inset::() too. if (pimpl_->inset_owner && pimpl_->inset_owner->owner()) @@ -1417,6 +1420,16 @@ bool Paragraph::isFreeSpacing() const } +bool Paragraph::allowEmpty() const +{ + if (layout()->keepempty) + return true; + if (pimpl_->inset_owner && pimpl_->inset_owner->owner()) + return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE); + return false; +} + + bool operator==(Paragraph const & lhs, Paragraph const & rhs) { #warning FIXME this implementatoin must be completely wrong... diff --git a/src/paragraph.h b/src/paragraph.h index c89c15b787..5c9ba843c3 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -283,9 +283,12 @@ public: /// int stripLeadingSpaces(); - /// + /// return true if we allow multiple spaces bool isFreeSpacing() const; + /// return true if we allow this par to stay empty + bool allowEmpty() const; + /// ParagraphParameters & params(); /// diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index 0842302dbb..7c42132308 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -71,7 +71,7 @@ void breakParagraph(BufferParams const & bparams, tmp->setLabelWidthString(par->params().labelWidthString()); } - bool const isempty = (par->layout()->keepempty && par->empty()); + bool const isempty = (par->allowEmpty() && par->empty()); if (!isempty && (par->size() > pos || par->empty() || flag == 2)) { tmp->layout(par->layout()); @@ -937,10 +937,9 @@ int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & tok lex.next(); font.setLyXColor(lex.getString()); } else if (token == "\\InsetSpace" || token == "\\SpecialChar") { - LyXLayout_ptr const & layout = par.layout(); // Insets don't make sense in a free-spacing context! ---Kayvan - if (layout->free_spacing || par.isFreeSpacing()) { + if (par.isFreeSpacing()) { if (token == "\\InsetSpace") par.insertChar(par.size(), ' ', font, change); else if (lex.isOK()) { diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index 912538e72d..75eb764983 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -429,8 +429,7 @@ void Paragraph::Pimpl::simpleTeXBlanks(ostream & os, TexRow & texrow, && getChar(i - 1) != ' ' && (i < size() - 1) // same in FreeSpacing mode - && !style.free_spacing - && !owner_->isFreeSpacing() + && !owner_->isFreeSpacing() // In typewriter mode, we want to avoid // ! . ? : at the end of a line && !(font.family() == LyXFont::TYPEWRITER_FAMILY diff --git a/src/text.C b/src/text.C index bc95c353bd..bcc7c640e0 100644 --- a/src/text.C +++ b/src/text.C @@ -1461,10 +1461,9 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout) LyXLayout_ptr const & layout = cursor.par()->layout(); // this is only allowed, if the current paragraph is not empty or caption - // and if it has not the keepempty flag aktive - if (cursor.par()->empty() - && layout->labeltype != LABEL_SENSITIVE - && !layout->keepempty) + // and if it has not the keepempty flag active + if (cursor.par()->empty() && !cursor.par()->allowEmpty() + && layout->labeltype != LABEL_SENSITIVE) return; setUndo(bv(), Undo::FINISH, cursor.par()); @@ -1487,7 +1486,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout) // breakParagraph call should return a bool if it inserts the // paragraph before or behind and we should react on that one // but we can fix this in 1.3.0 (Jug 20020509) - bool const isempty = (layout->keepempty && cursor.par()->empty()); + bool const isempty = (cursor.par()->allowEmpty() && cursor.par()->empty()); ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(), cursor.pos(), keep_layout); diff --git a/src/text2.C b/src/text2.C index afa44ca91d..1224d22cd5 100644 --- a/src/text2.C +++ b/src/text2.C @@ -2224,7 +2224,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor) return false; // Do not delete empty paragraphs with keepempty set. - if (old_cursor.par()->layout()->keepempty) + if (old_cursor.par()->allowEmpty()) return false; // only do our magic if we changed paragraph -- 2.39.2