1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
14 #pragma implementation "lyxparagraph.h"
21 #include "lyxparagraph.h"
22 #include "support/textutils.h"
26 #include "tex-strings.h"
28 #include "bufferparams.h"
29 #include "support/FileInfo.h"
30 #include "support/LAssert.h"
32 #include "LaTeXFeatures.h"
33 #include "insets/insetinclude.h"
34 #include "insets/insetbib.h"
35 #include "insets/insettext.h"
36 #include "support/filetools.h"
37 #include "lyx_gui_misc.h"
39 #include "support/lyxmanip.h"
40 #include "BufferView.h"
42 #include "ParameterStruct.h"
49 using std::lower_bound;
50 using std::upper_bound;
53 int tex_code_break_column = 72; // needs non-zero initialization. set later.
54 // this is a bad idea, but how can LyXParagraph find its buffer to get
55 // parameters? (JMarc)
57 extern string bibitemWidest(Buffer const *);
59 // this is a minibuffer
64 LyXFont minibuffer_font;
65 Inset * minibuffer_inset;
70 extern BufferView * current_view;
72 // Initialization of the counter for the paragraph id's,
73 // declared in lyxparagraph.h
74 unsigned int LyXParagraph::paragraph_id = 0;
76 // Initialize static member.
77 ShareContainer<LyXFont> LyXParagraph::FontTable::container;
80 LyXParagraph::LyXParagraph()
82 text.reserve(500); // is this number too big?
83 for (int i = 0; i < 10; ++i) setCounter(i , 0);
90 bibkey = 0; // ale970302
95 // This konstruktor inserts the new paragraph in a list.
96 LyXParagraph::LyXParagraph(LyXParagraph * par)
101 for (int i = 0; i < 10; ++i) setCounter(i, 0);
105 // double linked list begin
108 next_->previous_ = this;
110 previous_->next_ = this;
114 id_ = paragraph_id++;
116 bibkey = 0; // ale970302
122 LyXParagraph::LyXParagraph(LyXParagraph const & lp)
124 for (int i = 0; i < 10; ++i) setCounter(i , 0);
129 id_ = paragraph_id++;
134 // this is because of the dummy layout of the paragraphs that
138 inset_owner = lp.inset_owner;
142 bibkey = static_cast<InsetBibKey *>
143 (lp.bibkey->Clone(*current_view->buffer()));
147 // copy everything behind the break-position to the new paragraph
150 fontlist = lp.fontlist;
151 insetlist = lp.insetlist;
152 for (InsetList::iterator it = insetlist.begin();
153 it != insetlist.end(); ++it)
154 it->inset = it->inset->Clone(*current_view->buffer());
158 // the destructor removes the new paragraph from the list
159 LyXParagraph::~LyXParagraph()
162 previous_->next_ = next_;
164 next_->previous_ = previous_;
166 for (InsetList::iterator it = insetlist.begin();
167 it != insetlist.end(); ++it) {
174 //lyxerr << "LyXParagraph::paragraph_id = "
175 // << LyXParagraph::paragraph_id << endl;
179 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
180 BufferParams const & bparams,
183 // The beginning or end of a deeper (i.e. nested) area?
184 if (dth != params.depth()) {
185 if (params.depth() > dth) {
186 while (params.depth() > dth) {
187 os << "\n\\begin_deeper ";
191 while (params.depth() < dth) {
192 os << "\n\\end_deeper ";
198 // First write the layout
200 << textclasslist.NameOfLayout(bparams.textclass, layout)
203 // Maybe some vertical spaces.
204 if (params.spaceTop().kind() != VSpace::NONE)
205 os << "\\added_space_top "
206 << params.spaceTop().asLyXCommand() << " ";
207 if (params.spaceBottom().kind() != VSpace::NONE)
208 os << "\\added_space_bottom "
209 << params.spaceBottom().asLyXCommand() << " ";
211 // Maybe the paragraph has special spacing
212 params.spacing().writeFile(os, true);
214 // The labelwidth string used in lists.
215 if (!params.labelWidthString().empty())
216 os << "\\labelwidthstring "
217 << params.labelWidthString() << '\n';
219 // Lines above or below?
220 if (params.lineTop())
222 if (params.lineBottom())
223 os << "\\line_bottom ";
225 // Pagebreaks above or below?
226 if (params.pagebreakTop())
227 os << "\\pagebreak_top ";
228 if (params.pagebreakBottom())
229 os << "\\pagebreak_bottom ";
231 // Start of appendix?
232 if (params.startOfAppendix())
233 os << "\\start_of_appendix ";
236 if (params.noindent())
240 if (params.align() != LYX_ALIGN_LAYOUT) {
242 switch (params.align()) {
243 case LYX_ALIGN_LEFT: h = 1; break;
244 case LYX_ALIGN_RIGHT: h = 2; break;
245 case LYX_ALIGN_CENTER: h = 3; break;
246 default: h = 0; break;
248 os << "\\align " << string_align[h] << " ";
253 bibkey->Write(buf, os);
255 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
258 for (size_type i = 0; i < size(); ++i) {
264 // Write font changes
265 LyXFont font2 = GetFontSettings(bparams, i);
266 if (font2 != font1) {
267 font2.lyxWriteChanges(font1, os);
272 value_type const c = GetChar(i);
276 Inset const * inset = GetInset(i);
278 if (inset->DirectWrite()) {
279 // international char, let it write
280 // code directly so it's shorter in
282 inset->Write(buf, os);
284 os << "\n\\begin_inset ";
285 inset->Write(buf, os);
286 os << "\n\\end_inset \n\n";
292 os << "\n\\newline \n";
296 os << "\n\\hfill \n";
300 os << "\n\\backslash \n";
304 if (i + 1 < size() && GetChar(i + 1) == ' ') {
311 if ((column > 70 && c == ' ')
316 // this check is to amend a bug. LyX sometimes
317 // inserts '\0' this could cause problems.
321 lyxerr << "ERROR (LyXParagraph::writeFile):"
322 " NULL char in structure." << endl;
328 // now write the next paragraph
330 next_->writeFile(buf, os, bparams, dth);
334 void LyXParagraph::validate(LaTeXFeatures & features) const
336 BufferParams const & bparams = features.bufferParams();
339 if (params.lineTop() || params.lineBottom())
340 features.lyxline = true;
341 if (!params.spacing().isDefault())
342 features.setspace = true;
345 features.layout[GetLayout()] = true;
348 Language const * doc_language = bparams.language;
350 for (FontList::const_iterator cit = fontlist.begin();
351 cit != fontlist.end(); ++cit) {
352 if ((*cit).font().noun() == LyXFont::ON) {
353 lyxerr[Debug::LATEX] << "font.noun: "
354 << (*cit).font().noun()
356 features.noun = true;
357 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
358 << (*cit).font().stateText(0)
361 switch ((*cit).font().color()) {
363 case LColor::inherit:
367 features.color = true;
368 lyxerr[Debug::LATEX] << "Color enabled. Font: "
369 << (*cit).font().stateText(0)
373 Language const * language = (*cit).font().language();
374 if (language->babel() != doc_language->babel()) {
375 features.UsedLanguages.insert(language);
376 lyxerr[Debug::LATEX] << "Found language "
377 << language->babel() << endl;
382 for (InsetList::const_iterator cit = insetlist.begin();
383 cit != insetlist.end(); ++cit) {
385 (*cit).inset->Validate(features);
390 // First few functions needed for cut and paste and paragraph breaking.
391 void LyXParagraph::CopyIntoMinibuffer(Buffer const & buffer,
392 LyXParagraph::size_type pos) const
394 BufferParams bparams = buffer.params;
396 minibuffer_char = GetChar(pos);
397 minibuffer_font = GetFontSettings(bparams, pos);
398 minibuffer_inset = 0;
399 if (minibuffer_char == LyXParagraph::META_INSET) {
401 minibuffer_inset = GetInset(pos)->Clone(buffer);
403 minibuffer_inset = 0;
404 minibuffer_char = ' ';
405 // This reflects what GetInset() does (ARRae)
411 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
412 LyXParagraph::size_type pos)
414 minibuffer_char = GetChar(pos);
415 minibuffer_font = GetFontSettings(bparams, pos);
416 minibuffer_inset = 0;
417 if (minibuffer_char == LyXParagraph::META_INSET) {
419 minibuffer_inset = GetInset(pos);
420 // This is a little hack since I want exactly
421 // the inset, not just a clone. Otherwise
422 // the inset would be deleted when calling Erase(pos)
424 InsetTable search_elem(pos, 0);
425 InsetList::iterator it =
426 lower_bound(insetlist.begin(),
428 search_elem, matchIT());
429 if (it != insetlist.end() && (*it).pos == pos)
432 minibuffer_inset = 0;
433 minibuffer_char = ' ';
434 // This reflects what GetInset() does (ARRae)
439 // Erase(pos); now the caller is responsible for that.
443 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
445 if ((minibuffer_char == LyXParagraph::META_INSET) &&
446 !InsertInsetAllowed(minibuffer_inset))
448 if (minibuffer_char == LyXParagraph::META_INSET)
449 InsertInset(pos, minibuffer_inset, minibuffer_font);
451 InsertChar(pos, minibuffer_char, minibuffer_font);
459 void LyXParagraph::Clear()
468 void LyXParagraph::Erase(LyXParagraph::size_type pos)
470 lyx::Assert(pos < size());
471 // if it is an inset, delete the inset entry
472 if (text[pos] == LyXParagraph::META_INSET) {
474 InsetTable search_inset(pos, 0);
475 InsetList::iterator it =
476 lower_bound(insetlist.begin(),
478 search_inset, matchIT());
479 if (it != insetlist.end() && (*it).pos == pos) {
485 text.erase(text.begin() + pos);
487 // Erase entries in the tables.
488 FontTable search_font(pos, LyXFont());
490 FontList::iterator it =
491 lower_bound(fontlist.begin(),
493 search_font, matchFT());
494 if (it != fontlist.end() && (*it).pos() == pos &&
496 (it != fontlist.begin() && (*(it - 1)).pos() == pos - 1))) {
497 // If it is a multi-character font
498 // entry, we just make it smaller
499 // (see update below), otherwise we
501 unsigned int const i = it - fontlist.begin();
502 fontlist.erase(fontlist.begin() + i);
503 it = fontlist.begin() + i;
504 if (i > 0 && i < fontlist.size() &&
505 fontlist[i - 1].font() == fontlist[i].font()) {
506 fontlist.erase(fontlist.begin() + i - 1);
507 it = fontlist.begin() + i - 1;
511 // Update all other entries.
512 FontList::iterator fend = fontlist.end();
513 for (; it != fend; ++it)
514 (*it).pos((*it).pos() - 1);
516 // Update the inset table.
517 InsetTable search_inset(pos, 0);
518 InsetList::iterator lend = insetlist.end();
519 for (InsetList::iterator it =
520 upper_bound(insetlist.begin(),
522 search_inset, matchIT());
528 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
529 LyXParagraph::value_type c)
531 LyXFont const f(LyXFont::ALL_INHERIT);
532 InsertChar(pos, c, f);
536 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
537 LyXParagraph::value_type c,
538 LyXFont const & font)
540 lyx::Assert(pos <= size());
542 text.insert(text.begin() + pos, c);
544 // Update the font table.
545 FontTable search_font(pos, LyXFont());
546 for (FontList::iterator it = lower_bound(fontlist.begin(),
548 search_font, matchFT());
549 it != fontlist.end(); ++it)
550 (*it).pos((*it).pos() + 1);
552 // Update the inset table.
553 InsetTable search_inset(pos, 0);
554 for (InsetList::iterator it = lower_bound(insetlist.begin(),
556 search_inset, matchIT());
557 it != insetlist.end(); ++it)
564 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
567 LyXFont const f(LyXFont::ALL_INHERIT);
568 InsertInset(pos, inset, f);
572 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
573 Inset * inset, LyXFont const & font)
576 lyx::Assert(pos <= size());
578 InsertChar(pos, META_INSET, font);
579 lyx::Assert(text[pos] == META_INSET);
581 // Add a new entry in the inset table.
582 InsetTable search_inset(pos, 0);
583 InsetList::iterator it = lower_bound(insetlist.begin(),
585 search_inset, matchIT());
586 if (it != insetlist.end() && (*it).pos == pos)
587 lyxerr << "ERROR (LyXParagraph::InsertInset): "
588 "there is an inset in position: " << pos << endl;
590 insetlist.insert(it, InsetTable(pos, inset));
592 inset->setOwner(inset_owner);
596 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
598 //lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
601 return inset_owner->InsertInsetAllowed(inset);
606 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
608 lyx::Assert(pos < size());
611 InsetTable search_inset(pos, 0);
612 InsetList::iterator it = lower_bound(insetlist.begin(),
614 search_inset, matchIT());
615 if (it != insetlist.end() && (*it).pos == pos)
618 lyxerr << "ERROR (LyXParagraph::GetInset): "
619 "Inset does not exist: " << pos << endl;
622 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
623 // Did this commenting out introduce a bug? So far I have not
624 // see any, please enlighten me. (Lgb)
625 // My guess is that since the inset does not exist, we might
626 // as well replace it with a space to prevent craches. (Asger)
631 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
633 lyx::Assert(pos < size());
636 InsetTable search_inset(pos, 0);
637 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
639 search_inset, matchIT());
640 if (cit != insetlist.end() && (*cit).pos == pos)
643 lyxerr << "ERROR (LyXParagraph::GetInset): "
644 "Inset does not exist: " << pos << endl;
646 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
647 // Did this commenting out introduce a bug? So far I have not
648 // see any, please enlighten me. (Lgb)
649 // My guess is that since the inset does not exist, we might
650 // as well replace it with a space to prevent craches. (Asger)
655 // Gets uninstantiated font setting at position.
656 LyXFont const LyXParagraph::GetFontSettings(BufferParams const & bparams,
657 LyXParagraph::size_type pos) const
659 lyx::Assert(pos <= size());
661 FontTable search_font(pos, LyXFont());
662 FontList::const_iterator cit = lower_bound(fontlist.begin(),
664 search_font, matchFT());
665 if (cit != fontlist.end())
666 return (*cit).font();
668 if (pos == size() && size())
669 return GetFontSettings(bparams, pos - 1);
671 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
675 // Gets uninstantiated font setting at position 0
676 LyXFont const LyXParagraph::GetFirstFontSettings() const
679 if (!fontlist.empty())
680 return fontlist[0].font();
683 return LyXFont(LyXFont::ALL_INHERIT);
687 // Gets the fully instantiated font at a given position in a paragraph
688 // This is basically the same function as LyXText::GetFont() in text2.C.
689 // The difference is that this one is used for generating the LaTeX file,
690 // and thus cosmetic "improvements" are disallowed: This has to deliver
691 // the true picture of the buffer. (Asger)
692 // If position is -1, we get the layout font of the paragraph.
693 // If position is -2, we get the font of the manual label of the paragraph.
694 LyXFont const LyXParagraph::getFont(BufferParams const & bparams,
695 LyXParagraph::size_type pos) const
698 LyXLayout const & layout =
699 textclasslist.Style(bparams.textclass,
701 LyXParagraph::size_type main_body = 0;
702 if (layout.labeltype == LABEL_MANUAL)
703 main_body = BeginningOfMainBody();
708 layoutfont = layout.labelfont;
710 layoutfont = layout.font;
711 tmpfont = GetFontSettings(bparams, pos);
712 tmpfont.realize(layoutfont);
714 // process layoutfont for pos == -1 and labelfont for pos < -1
716 tmpfont = layout.font;
718 tmpfont = layout.labelfont;
719 tmpfont.setLanguage(getParLanguage(bparams));
722 // check for environment font information
723 char par_depth = GetDepth();
724 LyXParagraph const * par = this;
725 while (par && par_depth && !tmpfont.resolved()) {
726 par = par->DepthHook(par_depth - 1);
728 tmpfont.realize(textclasslist.
729 Style(bparams.textclass,
730 par->GetLayout()).font);
731 par_depth = par->GetDepth();
735 tmpfont.realize(textclasslist
736 .TextClass(bparams.textclass)
742 /// Returns the height of the highest font in range
744 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
745 LyXParagraph::size_type endpos) const
747 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
748 if (fontlist.empty())
751 FontTable end_search(endpos, LyXFont());
752 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
754 end_search, matchFT());
755 if (end_it != fontlist.end())
758 FontTable start_search(startpos, LyXFont());
759 for (FontList::const_iterator cit =
760 lower_bound(fontlist.begin(),
762 start_search, matchFT());
763 cit != end_it; ++cit) {
764 LyXFont::FONT_SIZE size = (*cit).font().size();
765 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
772 LyXParagraph::value_type
773 LyXParagraph::GetUChar(BufferParams const & bparams,
774 LyXParagraph::size_type pos) const
776 value_type c = GetChar(pos);
777 if (!lyxrc.rtl_support)
807 if (uc != c && GetFontSettings(bparams, pos).isRightToLeft())
814 // return an string of the current word, and the end of the word in lastpos.
815 string const LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
817 lyx::Assert(lastpos >= 0);
819 // the current word is defined as starting at the first character
820 // from the immediate left of lastpospos which meets the definition
821 // of IsLetter(), continuing to the last character to the right
822 // of this meeting IsLetter.
828 // move back until we have a letter
830 //there's no real reason to have firstpos & lastpos as
831 //separate variables as this is written, but maybe someon
832 // will want to return firstpos in the future.
834 //since someone might have typed a punctuation first
835 int firstpos = lastpos;
837 while ((firstpos >= 0) && !IsLetter(firstpos))
840 // now find the beginning by looking for a nonletter
842 while ((firstpos>= 0) && IsLetter(firstpos))
845 // the above is now pointing to the preceeding non-letter
849 // so copy characters into theword until we get a nonletter
850 // note that this can easily exceed lastpos, wich means
851 // that if used in the middle of a word, the whole word
854 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
860 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
861 LyXFont const & font)
863 lyx::Assert(pos <= size());
865 // First, reduce font against layout/label font
866 // Update: The SetCharFont() routine in text2.C already
867 // reduces font, so we don't need to do that here. (Asger)
868 // No need to simplify this because it will disappear
869 // in a new kernel. (Asger)
870 // Next search font table
872 FontTable search_font(pos, LyXFont());
873 FontList::iterator it = lower_bound(fontlist.begin(),
875 search_font, matchFT());
876 unsigned int i = it - fontlist.begin();
877 bool notfound = it == fontlist.end();
879 if (!notfound && fontlist[i].font() == font)
882 bool begin = pos == 0 || notfound ||
883 (i > 0 && fontlist[i-1].pos() == pos - 1);
884 // Is position pos is a beginning of a font block?
885 bool end = !notfound && fontlist[i].pos() == pos;
886 // Is position pos is the end of a font block?
887 if (begin && end) { // A single char block
888 if (i + 1 < fontlist.size() &&
889 fontlist[i + 1].font() == font) {
890 // Merge the singleton block with the next block
891 fontlist.erase(fontlist.begin() + i);
892 if (i > 0 && fontlist[i - 1].font() == font)
893 fontlist.erase(fontlist.begin() + i-1);
894 } else if (i > 0 && fontlist[i - 1].font() == font) {
895 // Merge the singleton block with the previous block
896 fontlist[i - 1].pos(pos);
897 fontlist.erase(fontlist.begin() + i);
899 fontlist[i].font(font);
901 if (i > 0 && fontlist[i - 1].font() == font)
902 fontlist[i - 1].pos(pos);
904 fontlist.insert(fontlist.begin() + i,
905 FontTable(pos, font));
907 fontlist[i].pos(pos - 1);
908 if (!(i + 1 < fontlist.size() &&
909 fontlist[i + 1].font() == font))
910 fontlist.insert(fontlist.begin() + i + 1,
911 FontTable(pos, font));
912 } else { // The general case. The block is splitted into 3 blocks
913 fontlist.insert(fontlist.begin() + i,
914 FontTable(pos - 1, fontlist[i].font()));
915 fontlist.insert(fontlist.begin() + i + 1,
916 FontTable(pos, font));
922 void LyXParagraph::next(LyXParagraph * p)
928 // This function is able to hide closed footnotes.
929 LyXParagraph * LyXParagraph::next()
935 LyXParagraph const * LyXParagraph::next() const
941 void LyXParagraph::previous(LyXParagraph * p)
947 // This function is able to hide closed footnotes.
948 LyXParagraph * LyXParagraph::previous()
954 // This function is able to hide closed footnotes.
955 LyXParagraph const * LyXParagraph::previous() const
961 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
962 LyXParagraph::size_type pos,
965 // create a new paragraph
966 LyXParagraph * tmp = new LyXParagraph(this);
968 // this is an idea for a more userfriendly layout handling, I will
969 // see what the users say
971 // layout stays the same with latex-environments
973 tmp->SetOnlyLayout(layout);
974 tmp->SetLabelWidthString(params.labelWidthString());
977 if (size() > pos || !size() || flag == 2) {
978 tmp->SetOnlyLayout(layout);
979 tmp->params.align(params.align());
980 tmp->SetLabelWidthString(params.labelWidthString());
982 tmp->params.lineBottom(params.lineBottom());
983 params.lineBottom(false);
984 tmp->params.pagebreakBottom(params.pagebreakBottom());
985 params.pagebreakBottom(false);
986 tmp->params.spaceBottom(params.spaceBottom());
987 params.spaceBottom(VSpace(VSpace::NONE));
989 tmp->params.depth(params.depth());
990 tmp->params.noindent(params.noindent());
992 // copy everything behind the break-position
993 // to the new paragraph
994 size_type pos_end = text.size() - 1;
997 for (; i <= pos_end; ++i) {
998 CutIntoMinibuffer(bparams, i);
999 if (tmp->InsertFromMinibuffer(j - pos))
1003 for (i = pos_end; i >= pos; --i)
1009 // just an idea of me
1011 tmp->params.lineTop(params.lineTop());
1012 tmp->params.pagebreakTop(params.pagebreakTop());
1013 tmp->params.spaceTop(params.spaceTop());
1014 tmp->bibkey = bibkey;
1016 // layout stays the same with latex-environments
1018 SetOnlyLayout(tmp->layout);
1019 SetLabelWidthString(tmp->params.labelWidthString());
1020 params.depth(tmp->params.depth());
1026 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1028 layout = par->layout;
1029 params.makeSame(par->params);
1031 // This can be changed after NEW_INSETS is in effect. (Lgb)
1032 SetLabelWidthString(par->params.labelWidthString());
1036 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1038 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1043 && (IsNewline(0) || IsLineSeparator(0))){
1052 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1055 par->layout == layout &&
1056 params.sameLayout(par->params);
1060 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1061 LyXParagraph::size_type pos)
1063 // create a new paragraph
1064 LyXParagraph * tmp = new LyXParagraph(this);
1065 tmp->MakeSameLayout(this);
1067 // When can pos > Last()?
1068 // I guess pos == Last() is possible.
1070 // copy everything behind the break-position to the new
1072 size_type pos_end = text.size() - 1;
1075 for (i = j = pos; i <= pos_end; ++i) {
1076 CutIntoMinibuffer(bparams, i);
1077 if (tmp->InsertFromMinibuffer(j - pos))
1083 for (size_type i = pos_end; i >= pos; --i)
1091 // Be carefull, this does not make any check at all.
1092 // This method has wrong name, it combined this par with the next par.
1093 // In that sense it is the reverse of break paragraph. (Lgb)
1094 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1096 // copy the next paragraph to this one
1097 LyXParagraph * the_next = next();
1099 // first the DTP-stuff
1100 params.lineBottom(the_next->params.lineBottom());
1101 params.spaceBottom(the_next->params.spaceBottom());
1102 params.pagebreakBottom(the_next->params.pagebreakBottom());
1104 size_type pos_end = the_next->text.size() - 1;
1105 size_type pos_insert = size();
1107 // ok, now copy the paragraph
1109 for (i = j = 0; i <= pos_end; ++i) {
1110 the_next->CutIntoMinibuffer(bparams, i);
1111 if (InsertFromMinibuffer(pos_insert + j))
1115 // delete the next paragraph
1116 LyXParagraph * ppar = the_next->previous_;
1117 LyXParagraph * npar = the_next->next_;
1123 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1125 LyXParagraph const * par = this;
1126 int par_depth = GetDepth();
1128 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1129 int const endlabeltype =
1130 textclasslist.Style(bparams.textclass,
1131 layout).endlabeltype;
1132 if (endlabeltype != END_LABEL_NO_LABEL) {
1134 return endlabeltype;
1136 int const next_depth = next_->GetDepth();
1137 if (par_depth > next_depth ||
1138 (par_depth == next_depth
1139 && layout != next_->GetLayout()))
1140 return endlabeltype;
1145 par = par->DepthHook(par_depth - 1);
1147 par_depth = par->GetDepth();
1149 return END_LABEL_NO_LABEL;
1153 char LyXParagraph::GetDepth() const
1155 return params.depth();
1159 char LyXParagraph::GetAlign() const
1161 return params.align();
1165 string const & LyXParagraph::GetLabelstring() const
1167 return params.labelString();
1171 int LyXParagraph::GetFirstCounter(int i) const
1177 // the next two functions are for the manual labels
1178 string const LyXParagraph::GetLabelWidthString() const
1180 if (!params.labelWidthString().empty())
1181 return params.labelWidthString();
1183 return _("Senseless with this layout!");
1187 void LyXParagraph::SetLabelWidthString(string const & s)
1189 params.labelWidthString(s);
1193 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1195 layout = new_layout;
1199 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
1201 layout = new_layout;
1202 params.labelWidthString(string());
1203 params.align(LYX_ALIGN_LAYOUT);
1204 params.spaceTop(VSpace(VSpace::NONE));
1205 params.spaceBottom(VSpace(VSpace::NONE));
1206 params.spacing(Spacing(Spacing::Default));
1210 // if the layout of a paragraph contains a manual label, the beginning of the
1211 // main body is the beginning of the second word. This is what the par-
1212 // function returns. If the layout does not contain a label, the main
1213 // body always starts with position 0. This differentiation is necessary,
1214 // because there cannot be a newline or a blank <= the beginning of the
1215 // main body in TeX.
1217 int LyXParagraph::BeginningOfMainBody() const
1219 // Unroll the first two cycles of the loop
1220 // and remember the previous character to
1221 // remove unnecessary GetChar() calls
1224 && GetChar(i) != LyXParagraph::META_NEWLINE) {
1226 char previous_char = 0;
1229 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1230 // Yes, this ^ is supposed to be "= " not "=="
1233 && previous_char != ' '
1234 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1236 previous_char = temp;
1245 LyXParagraph * LyXParagraph::DepthHook(int deth)
1247 LyXParagraph * newpar = this;
1252 newpar = newpar->previous();
1253 } while (newpar && newpar->GetDepth() > deth);
1256 if (previous() || GetDepth())
1257 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1266 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1268 LyXParagraph const * newpar = this;
1273 newpar = newpar->previous();
1274 } while (newpar && newpar->GetDepth() > deth);
1277 if (previous() || GetDepth())
1278 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1287 int LyXParagraph::AutoDeleteInsets()
1290 InsetList::size_type index = 0;
1291 while (index < insetlist.size()) {
1292 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1293 Erase(insetlist[index].pos);
1294 // Erase() calls to insetlist.erase(&insetlist[index])
1295 // so index shouldn't be increased.
1304 LyXParagraph::inset_iterator
1305 LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
1307 InsetTable search_inset(pos, 0);
1308 InsetList::iterator it = lower_bound(insetlist.begin(),
1310 search_inset, matchIT());
1311 return inset_iterator(it);
1315 // returns -1 if inset not found
1316 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1319 for (InsetList::const_iterator cit = insetlist.begin();
1320 cit != insetlist.end(); ++cit) {
1321 if ((*cit).inset == inset) {
1325 if (inset == bibkey)
1332 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
1333 BufferParams const & bparams,
1334 ostream & os, TexRow & texrow,
1337 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1338 LyXLayout const & style =
1339 textclasslist.Style(bparams.textclass,
1342 bool further_blank_line = false;
1344 if (params.startOfAppendix()) {
1345 os << "\\appendix\n";
1349 if (!params.spacing().isDefault()
1350 && (!previous() || !previous()->HasSameLayout(this))) {
1351 os << params.spacing().writeEnvirBegin() << "\n";
1355 if (tex_code_break_column && style.isCommand()){
1360 if (params.pagebreakTop()) {
1362 further_blank_line = true;
1364 if (params.spaceTop().kind() != VSpace::NONE) {
1365 os << params.spaceTop().asLatexCommand(bparams);
1366 further_blank_line = true;
1369 if (params.lineTop()) {
1370 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
1371 << "\\vspace{-1\\parskip}";
1372 further_blank_line = true;
1375 if (further_blank_line){
1380 Language const * language = getParLanguage(bparams);
1381 Language const * doc_language = bparams.language;
1382 Language const * previous_language = previous_
1383 ? previous_->getParLanguage(bparams) : doc_language;
1384 if (language->babel() != doc_language->babel() &&
1385 language->babel() != previous_language->babel()) {
1386 os << subst(lyxrc.language_command_begin, "$$lang",
1392 if (bparams.inputenc == "auto" &&
1393 language->encoding() != previous_language->encoding()) {
1394 os << "\\inputencoding{"
1395 << language->encoding()->LatexName()
1400 switch (style.latextype) {
1403 << style.latexname()
1404 << style.latexparam();
1406 case LATEX_ITEM_ENVIRONMENT:
1408 bibkey->Latex(buf, os, false, false);
1412 case LATEX_LIST_ENVIRONMENT:
1419 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
1421 // Make sure that \\par is done with the font of the last
1422 // character if this has another size as the default.
1423 // This is necessary because LaTeX (and LyX on the screen)
1424 // calculates the space between the baselines according
1425 // to this font. (Matthias)
1427 // Is this really needed ? (Dekel)
1428 // We do not need to use to change the font for the last paragraph
1429 // or for a command.
1430 LyXFont font = getFont(bparams, size() - 1);
1432 bool is_command = textclasslist.Style(bparams.textclass,
1433 GetLayout()).isCommand();
1434 if (style.resfont.size() != font.size() && next_ && !is_command) {
1437 os << "\\" << font.latexSize() << " \\par}";
1438 } else if (need_par) {
1440 } else if (is_command)
1443 if (language->babel() != doc_language->babel() &&
1445 || next_->getParLanguage(bparams)->babel() != language->babel())) {
1447 << subst(lyxrc.language_command_end, "$$lang",
1448 doc_language->babel());
1451 switch (style.latextype) {
1452 case LATEX_ITEM_ENVIRONMENT:
1453 case LATEX_LIST_ENVIRONMENT:
1454 if (next_ && (params.depth() < next_->params.depth())) {
1459 case LATEX_ENVIRONMENT:
1460 // if its the last paragraph of the current environment
1461 // skip it otherwise fall through
1463 && (next_->layout != layout
1464 || next_->params.depth() != params.depth()))
1467 // we don't need it for the last paragraph!!!
1468 // or for tables in floats
1469 // -- effectively creates a \par where there isn't one which
1470 // breaks a \subfigure or \subtable.
1477 further_blank_line = false;
1478 if (params.lineBottom()) {
1479 os << "\\lyxline{\\" << getFont(bparams,
1480 size() - 1).latexSize() << '}';
1481 further_blank_line = true;
1484 if (params.spaceBottom().kind() != VSpace::NONE) {
1485 os << params.spaceBottom().asLatexCommand(bparams);
1486 further_blank_line = true;
1489 if (params.pagebreakBottom()) {
1491 further_blank_line = true;
1494 if (further_blank_line){
1499 if (!params.spacing().isDefault()
1500 && (!next_ || !next_->HasSameLayout(this))) {
1501 os << params.spacing().writeEnvirEnd() << "\n";
1505 // we don't need it for the last paragraph!!!
1511 lyxerr[Debug::LATEX] << "TeXOnePar...done " << next_ << endl;
1516 // This one spits out the text of the paragraph
1517 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
1518 BufferParams const & bparams,
1519 ostream & os, TexRow & texrow,
1522 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
1524 bool return_value = false;
1526 LyXLayout const & style =
1527 textclasslist.Style(bparams.textclass,
1531 // Maybe we have to create a optional argument.
1532 size_type main_body;
1533 if (style.labeltype != LABEL_MANUAL)
1536 main_body = BeginningOfMainBody();
1538 if (main_body > 0) {
1540 basefont = getFont(bparams, -2); // Get label font
1542 basefont = getFont(bparams, -1); // Get layout font
1549 if (style.isCommand()) {
1552 } else if (params.align() != LYX_ALIGN_LAYOUT) {
1555 return_value = true;
1559 moving_arg |= style.needprotect;
1561 // Which font is currently active?
1562 LyXFont running_font(basefont);
1563 // Do we have an open font change?
1564 bool open_font = false;
1566 texrow.start(this, 0);
1568 for (size_type i = 0; i < size(); ++i) {
1570 // First char in paragraph or after label?
1571 if (i == main_body) {
1572 if (main_body > 0) {
1574 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1577 basefont = getFont(bparams, -1); // Now use the layout font
1578 running_font = basefont;
1582 if (style.isCommand()) {
1585 } else if (params.align() != LYX_ALIGN_LAYOUT && next_) {
1586 // We do not need \par here (Dekel)
1590 return_value = true;
1593 if (params.noindent()) {
1594 os << "\\noindent ";
1597 switch (params.align()) {
1598 case LYX_ALIGN_NONE:
1599 case LYX_ALIGN_BLOCK:
1600 case LYX_ALIGN_LAYOUT:
1601 case LYX_ALIGN_SPECIAL:
1603 case LYX_ALIGN_LEFT:
1606 if (getParLanguage(bparams)->babel() != "hebrew") {
1607 os << "\\raggedright ";
1610 os << "\\raggedleft ";
1614 case LYX_ALIGN_RIGHT:
1617 if (getParLanguage(bparams)->babel() != "hebrew") {
1618 os << "\\raggedleft ";
1621 os << "\\raggedright ";
1625 case LYX_ALIGN_CENTER:
1628 os << "\\centering ";
1634 value_type c = GetChar(i);
1636 // Fully instantiated font
1637 LyXFont font = getFont(bparams, i);
1639 LyXFont last_font = running_font;
1641 // Spaces at end of font change are simulated to be
1642 // outside font change, i.e. we write "\textXX{text} "
1643 // rather than "\textXX{text }". (Asger)
1644 if (open_font && c == ' ' && i <= size() - 2
1645 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
1646 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
1647 font = getFont(bparams, i + 1);
1649 // We end font definition before blanks
1650 if (!font.equalExceptLatex(running_font) && open_font) {
1651 column += running_font.latexWriteEndChanges(os,
1653 (i == main_body-1) ? basefont : font);
1654 running_font = basefont;
1658 // Blanks are printed before start of fontswitch
1660 // Do not print the separation of the optional argument
1661 if (i != main_body - 1) {
1662 SimpleTeXBlanks(os, texrow, i,
1663 column, font, style);
1667 // Do we need to change font?
1668 if (!font.equalExceptLatex(running_font)
1669 && i != main_body-1) {
1670 column += font.latexWriteStartChanges(os, basefont,
1672 running_font = font;
1676 if (c == LyXParagraph::META_NEWLINE) {
1677 // newlines are handled differently here than
1678 // the default in SimpleTeXSpecialChars().
1679 if (!style.newline_allowed
1680 || font.latex() == LyXFont::ON) {
1684 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1687 basefont = getFont(bparams, -1);
1688 running_font = basefont;
1689 if (font.family() ==
1690 LyXFont::TYPEWRITER_FAMILY) {
1698 texrow.start(this, i + 1);
1701 SimpleTeXSpecialChars(buf, bparams,
1702 os, texrow, moving_arg,
1703 font, running_font, basefont,
1704 open_font, style, i, column, c);
1708 // If we have an open font definition, we have to close it
1712 .latexWriteEndChanges(os, basefont,
1713 next_->getFont(bparams,
1716 running_font.latexWriteEndChanges(os, basefont,
1721 // Needed if there is an optional argument but no contents.
1722 if (main_body > 0 && main_body == size()) {
1724 return_value = false;
1727 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1728 return return_value;
1732 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
1734 bool retval = false;
1736 case LyXParagraph::META_HFILL:
1737 sgml_string.erase();
1739 case LyXParagraph::META_NEWLINE:
1743 sgml_string = "&";
1746 sgml_string = "<";
1749 sgml_string = ">";
1752 sgml_string = "$";
1755 sgml_string = "#";
1758 sgml_string = "%";
1761 sgml_string = "[";
1764 sgml_string = "]";
1767 sgml_string = "{";
1770 sgml_string = "}";
1773 sgml_string = "˜";
1776 sgml_string = """;
1779 sgml_string = "\";
1785 case '\0': // Ignore :-)
1786 sgml_string.erase();
1796 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
1797 LyXParagraph::size_type const i,
1798 int & column, LyXFont const & font,
1799 LyXLayout const & style)
1801 if (column > tex_code_break_column
1803 && GetChar(i - 1) != ' '
1805 // In LaTeX mode, we don't want to
1806 // break lines since some commands
1808 && ! (font.latex() == LyXFont::ON)
1809 // same in FreeSpacing mode
1810 && !style.free_spacing
1811 // In typewriter mode, we want to avoid
1812 // ! . ? : at the end of a line
1813 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
1814 && (GetChar(i-1) == '.'
1815 || GetChar(i-1) == '?'
1816 || GetChar(i-1) == ':'
1817 || GetChar(i-1) == '!'))) {
1818 if (tex_code_break_column == 0) {
1819 // in batchmode we need LaTeX to still
1820 // see it as a space not as an extra '\n'
1826 texrow.start(this, i + 1);
1828 } else if (font.latex() == LyXFont::OFF) {
1829 if (style.free_spacing) {
1838 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
1839 BufferParams const & bparams,
1840 ostream & os, TexRow & texrow,
1843 LyXFont & running_font,
1846 LyXLayout const & style,
1847 LyXParagraph::size_type & i,
1849 LyXParagraph::value_type const c)
1851 // Two major modes: LaTeX or plain
1852 // Handle here those cases common to both modes
1853 // and then split to handle the two modes separately.
1855 case LyXParagraph::META_INSET: {
1856 Inset * inset = GetInset(i);
1859 int const len = os.tellp();
1860 //ostream::pos_type const len = os.tellp();
1861 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
1862 || inset->LyxCode() == Inset::MATH_CODE
1863 || inset->LyxCode() == Inset::URL_CODE)
1864 && running_font.isRightToLeft()) {
1869 int tmp = inset->Latex(buf, os, moving_arg,
1870 style.free_spacing);
1878 column += int(os.tellp()) - len;
1887 case LyXParagraph::META_NEWLINE:
1889 column += running_font.latexWriteEndChanges(os,
1894 basefont = getFont(bparams, -1);
1895 running_font = basefont;
1898 case LyXParagraph::META_HFILL:
1904 // And now for the special cases within each mode
1905 // Are we in LaTeX mode?
1906 if (font.latex() == LyXFont::ON) {
1907 // at present we only have one option
1908 // but I'll leave it as a switch statement
1909 // so its simpler to extend. (ARRae)
1912 // make sure that we will not print
1913 // error generating chars to the tex
1914 // file. This test would not be needed
1915 // if it were done in the buffer
1923 // Plain mode (i.e. not LaTeX)
1926 os << "\\textbackslash{}";
1930 case '°': case '±': case '²': case '³':
1931 case '×': case '÷': case '¹': case 'ª':
1932 case 'º': case '¬': case 'µ':
1933 if (bparams.inputenc == "latin1" ||
1934 (bparams.inputenc == "auto" &&
1935 font.language()->encoding()->LatexName()
1937 os << "\\ensuremath{"
1946 case '|': case '<': case '>':
1947 // In T1 encoding, these characters exist
1948 if (lyxrc.fontenc == "T1") {
1950 //... but we should avoid ligatures
1951 if ((c == '>' || c == '<')
1953 && GetChar(i + 1) == c) {
1954 //os << "\\textcompwordmark{}";
1955 // Jean-Marc, have a look at
1956 // this. IÂ think this works
1964 // Typewriter font also has them
1965 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
1969 // Otherwise, we use what LaTeX
1973 os << "\\textless{}";
1977 os << "\\textgreater{}";
1981 os << "\\textbar{}";
1987 case '-': // "--" in Typewriter mode -> "-{}-"
1989 && GetChar(i + 1) == '-'
1990 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
1999 os << "\\char`\\\"{}";
2004 if (bparams.inputenc == "default") {
2013 case '%': case '#': case '{':
2020 os << "\\textasciitilde{}";
2025 os << "\\textasciicircum{}";
2029 case '*': case '[': case ']':
2030 // avoid being mistaken for optional arguments
2031 os << '{' << c << '}';
2036 // Blanks are printed before font switching.
2037 // Sure? I am not! (try nice-latex)
2038 // I am sure it's correct. LyX might be smarter
2039 // in the future, but for now, nothing wrong is
2044 /* idea for labels --- begin*/
2048 && font.family() != LyXFont::TYPEWRITER_FAMILY
2049 && GetChar(i + 1) == 'y'
2050 && GetChar(i + 2) == 'X') {
2058 && font.family() != LyXFont::TYPEWRITER_FAMILY
2059 && GetChar(i + 1) == 'e'
2060 && GetChar(i + 2) == 'X') {
2065 // Check for "LaTeX2e"
2068 && font.family() != LyXFont::TYPEWRITER_FAMILY
2069 && GetChar(i + 1) == 'a'
2070 && GetChar(i + 2) == 'T'
2071 && GetChar(i + 3) == 'e'
2072 && GetChar(i + 4) == 'X'
2073 && GetChar(i + 5) == '2'
2074 && GetChar(i + 6) == 'e') {
2079 // Check for "LaTeX"
2082 && font.family() != LyXFont::TYPEWRITER_FAMILY
2083 && GetChar(i + 1) == 'a'
2084 && GetChar(i + 2) == 'T'
2085 && GetChar(i + 3) == 'e'
2086 && GetChar(i + 4) == 'X') {
2090 /* idea for labels --- end*/
2091 } else if (c != '\0') {
2101 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
2102 BufferParams const & bparams,
2103 ostream & os, TexRow & texrow)
2105 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
2106 LyXParagraph * par = this;
2108 while (par && par->params.depth() == params.depth()) {
2109 if (textclasslist.Style(bparams.textclass,
2110 par->layout).isEnvironment()) {
2111 par = par->TeXEnvironment(buf, bparams,
2114 par = par->TeXOnePar(buf, bparams,
2118 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
2124 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
2125 BufferParams const & bparams,
2126 ostream & os, TexRow & texrow)
2128 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
2130 LyXLayout const & style =
2131 textclasslist.Style(bparams.textclass,
2134 if (style.isEnvironment()){
2135 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
2136 os << "\\begin{" << style.latexname() << "}{"
2137 << params.labelWidthString() << "}\n";
2138 } else if (style.labeltype == LABEL_BIBLIO) {
2140 os << "\\begin{" << style.latexname() << "}{"
2141 << bibitemWidest(buf)
2143 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
2144 os << "\\begin{" << style.latexname() << '}'
2145 << style.latexparam() << '\n';
2147 os << "\\begin{" << style.latexname() << '}'
2148 << style.latexparam() << '\n';
2151 LyXParagraph * par = this;
2153 par = par->TeXOnePar(buf, bparams,
2156 if (par && par->params.depth() > params.depth()) {
2157 if (textclasslist.Style(bparams.textclass,
2158 par->layout).isParagraph()
2160 // How to handle this? (Lgb)
2161 //&& !suffixIs(os, "\n\n")
2163 // There should be at least one '\n' already
2164 // but we need there to be two for Standard
2165 // paragraphs that are depth-increment'ed to be
2166 // output correctly. However, tables can
2167 // also be paragraphs so don't adjust them.
2170 // Will it ever harm to have one '\n' too
2171 // many? i.e. that we sometimes will have
2172 // three in a row. (Lgb)
2176 par = par->TeXDeeper(buf, bparams, os, texrow);
2179 && par->layout == layout
2180 && par->params.depth() == params.depth());
2182 if (style.isEnvironment()) {
2183 os << "\\end{" << style.latexname() << "}\n";
2186 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
2187 return par; // ale970302
2191 bool LyXParagraph::IsHfill(size_type pos) const
2193 return IsHfillChar(GetChar(pos));
2197 bool LyXParagraph::IsInset(size_type pos) const
2199 return IsInsetChar(GetChar(pos));
2203 bool LyXParagraph::IsNewline(size_type pos) const
2205 return pos >= 0 && IsNewlineChar(GetChar(pos));
2209 bool LyXParagraph::IsSeparator(size_type pos) const
2211 return IsSeparatorChar(GetChar(pos));
2215 bool LyXParagraph::IsLineSeparator(size_type pos) const
2217 return IsLineSeparatorChar(GetChar(pos));
2221 bool LyXParagraph::IsKomma(size_type pos) const
2223 return IsKommaChar(GetChar(pos));
2227 /// Used by the spellchecker
2228 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
2230 value_type const c = GetChar(pos);
2231 if (IsLetterChar(c))
2233 // '\0' is not a letter, allthough every string contains "" (below)
2236 // We want to pass the ' and escape chars to ispell
2237 string const extra = lyxrc.isp_esc_chars + '\'';
2238 char ch[2] = { c, 0 };
2239 return contains(extra, ch);
2243 bool LyXParagraph::IsWord(size_type pos ) const
2245 return IsWordChar(GetChar(pos)) ;
2250 LyXParagraph::getParLanguage(BufferParams const & bparams) const
2253 return GetFirstFontSettings().language();
2255 return previous_->getParLanguage(bparams);
2257 return bparams.language;
2261 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
2263 return lyxrc.rtl_support
2264 && getParLanguage(bparams)->RightToLeft();
2268 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
2269 Language const * from, Language const * to)
2271 for (size_type i = 0; i < size(); ++i) {
2272 LyXFont font = GetFontSettings(bparams, i);
2273 if (font.language() == from) {
2274 font.setLanguage(to);
2281 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
2283 Language const * doc_language = bparams.language;
2284 for (FontList::const_iterator cit = fontlist.begin();
2285 cit != fontlist.end(); ++cit)
2286 if ((*cit).font().language() != doc_language)
2292 // Convert the paragraph to a string.
2293 // Used for building the table of contents
2294 string const LyXParagraph::String(Buffer const * buffer, bool label)
2296 BufferParams const & bparams = buffer->params;
2298 if (label && !params.labelString().empty())
2299 s += params.labelString() + ' ';
2300 string::size_type const len = s.size();
2302 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
2303 value_type c = GetChar(i);
2306 else if (c == META_INSET &&
2307 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
2308 std::ostringstream ost;
2309 GetInset(i)->Ascii(buffer, ost);
2310 s += subst(ost.str().c_str(),'\n',' ');
2314 if (isRightToLeftPar(bparams))
2315 reverse(s.begin() + len,s.end());
2321 string const LyXParagraph::String(Buffer const * buffer,
2322 LyXParagraph::size_type beg,
2323 LyXParagraph::size_type end)
2325 std::ostringstream ost;
2327 if (beg == 0 && !params.labelString().empty())
2328 ost << params.labelString() << ' ';
2330 for (LyXParagraph::size_type i = beg; i < end; ++i) {
2331 value_type const c = GetUChar(buffer->params, i);
2334 else if (c == META_INSET) {
2335 GetInset(i)->Ascii(buffer, ost);
2339 return ost.str().c_str();
2343 void LyXParagraph::SetInsetOwner(Inset * i)
2346 for (InsetList::const_iterator cit = insetlist.begin();
2347 cit != insetlist.end(); ++cit) {
2349 (*cit).inset->setOwner(i);
2354 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
2357 for (InsetList::const_iterator cit = insetlist.begin();
2358 cit != insetlist.end(); ++cit) {
2360 if ((*cit).inset->IsTextInset()) {
2361 static_cast<UpdatableInset *>
2362 ((*cit).inset)->deleteLyXText(bv);
2369 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
2372 for (InsetList::const_iterator cit = insetlist.begin();
2373 cit != insetlist.end(); ++cit) {
2375 if ((*cit).inset->IsTextInset()) {
2376 static_cast<UpdatableInset *>
2377 ((*cit).inset)->resizeLyXText(bv);
2384 void LyXParagraph::fitToSize()
2386 TextContainer tmp(text.begin(), text.end());
2391 void LyXParagraph::setContentsFromPar(LyXParagraph * par)