2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1998 The LyX Team.
9 * ======================================================
20 #pragma implementation
23 #include "insettext.h"
28 #include "commandtags.h"
31 #include "BufferView.h"
32 #include "support/textutils.h"
34 #include "insetlatexaccent.h"
35 #include "insetquotes.h"
36 #include "mathed/formulamacro.h"
38 #include "insetinfo.h"
39 #include "insetinclude.h"
41 #include "insetcommand.h"
42 #include "insetindex.h"
43 #include "insetlabel.h"
45 //#include "insettabular.h"
47 #include "insetspecialchar.h"
48 #include "LaTeXFeatures.h"
50 #include "lyx_gui_misc.h"
51 #include "support/LAssert.h"
53 extern unsigned char getCurrentTextClass(Buffer *);
55 InsetText::InsetText(Buffer * buf)
57 par = new LyXParagraph();
58 the_locking_inset = 0;
60 cursor_visible = false;
61 maxWidth = old_x = -1;
62 actpos = selection_start = selection_end = 0;
66 maxAscent = maxDescent = insetWidth = 0;
67 autoBreakRows = false;
71 InsetText::InsetText(InsetText const & ins, Buffer * buf)
73 par = new LyXParagraph(ins.par);
74 the_locking_inset = 0;
76 cursor_visible = false;
77 maxWidth = old_x = -1;
78 actpos = selection_start = selection_end = 0;
82 maxAscent = maxDescent = insetWidth = 0;
83 autoBreakRows = false;
87 InsetText::~InsetText()
93 Inset * InsetText::Clone() const
95 InsetText * t = new InsetText(*this, buffer);
100 void InsetText::Write(ostream & os) const
103 WriteParagraphData(os);
107 void InsetText::WriteParagraphData(ostream & os) const
109 par->writeFile(os, buffer->params, 0, 0);
113 void InsetText::Read(LyXLex & lex)
115 string token, tmptok;
117 LyXParagraph * return_par = 0;
118 char depth = 0; // signed or unsigned?
119 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
120 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
121 LyXFont font(LyXFont::ALL_INHERIT);
124 par = new LyXParagraph;
128 token = lex.GetString();
131 if (token == "\\end_inset")
133 if (buffer->parseSingleLyXformat2Token(lex, par, return_par,
137 // the_end read this should NEVER happen
138 lex.printError("\\the_end read in inset! Error in document!");
142 if (token != "\\end_inset") {
143 lex.printError("Missing \\end_inset at this point. "
150 int InsetText::ascent(Painter & pain, LyXFont const & font) const
153 computeTextRows(pain);
158 return font.maxAscent();
162 int InsetText::descent(Painter & pain, LyXFont const & font) const
165 computeTextRows(pain);
170 return font.maxDescent();
174 int InsetText::width(Painter & pain, LyXFont const &) const
177 computeTextRows(pain);
184 int InsetText::getMaxWidth(UpdatableInset * inset) const
186 if (!the_locking_inset) {
187 lyxerr << "Text: No locking inset in this inset.\n";
191 if (the_locking_inset == inset)
194 return the_locking_inset->getMaxWidth(inset);
198 void InsetText::draw(Painter & pain, LyXFont const & f,
199 int baseline, float & x) const
202 computeTextRows(pain);
203 // init_inset = false;
205 UpdatableInset::draw(pain, f, baseline, x);
207 bool do_reset_pos = (x != top_x) || (baseline != top_baseline);
209 top_baseline = baseline;
210 computeBaselines(baseline);
211 for(unsigned int r = 0; r < rows.size() - 1; ++r) {
212 drawRowSelection(pain, rows[r].pos, rows[r + 1].pos, r,
213 rows[r].baseline, x);
214 drawRowText(pain, rows[r].pos, rows[r + 1].pos, rows[r].baseline, x);
217 if (!the_locking_inset && do_reset_pos) {
218 // HideInsetCursor(bv);
220 // ShowInsetCursor(bv);
225 void InsetText::drawRowSelection(Painter & pain, int startpos, int endpos,
226 int row, int baseline, float x) const
232 if (selection_start > selection_end) {
233 s_start = selection_end;
234 s_end = selection_start;
236 s_start = selection_start;
237 s_end = selection_end;
239 if ((s_start > endpos) || (s_end < startpos))
243 int ssel_x = esel_x = int(x);
246 for(; p < endpos; ++p) {
249 if ((p >= s_start) && (p <= s_end))
251 char ch = par->GetChar(p);
252 font = GetFont(par,p);
253 if (IsFloatChar(ch)) {
255 } else if (ch == LyXParagraph::META_INSET) {
256 Inset const * tmpinset = par->GetInset(p);
257 x += tmpinset->width(pain, font);
259 x += pain.width(ch,font);
264 if ((p >= s_start) && (p <= s_end))
266 if (ssel_x < esel_x) {
267 pain.fillRectangle(int(ssel_x), baseline-rows[row].asc,
268 int(esel_x - ssel_x),
269 rows[row].asc + rows[row].desc,
275 void InsetText::drawRowText(Painter & pain, int startpos, int endpos,
276 int baseline, float x) const
278 Assert(endpos <= par->Last());
280 for(int p = startpos; p < endpos; ++p) {
281 char ch = par->GetChar(p);
282 LyXFont font = GetFont(par,p);
283 if (IsFloatChar(ch)) {
285 } else if (ch == LyXParagraph::META_INSET) {
286 Inset * tmpinset = par->GetInset(p);
288 tmpinset->draw(pain, font, baseline, x);
290 pain.text(int(x), baseline, ch, font);
291 x += pain.width(ch,font);
297 char const * InsetText::EditMessage() const
299 return _("Opened Text Inset");
303 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
305 UpdatableInset::Edit(bv, x, y, button);
308 the_locking_inset = 0;
309 inset_pos = inset_x = inset_y = 0;
312 selection_start = selection_end = actpos;
313 current_font = real_current_font = GetFont(par, actpos);
317 void InsetText::InsetUnlock(BufferView * bv)
319 if (the_locking_inset)
320 the_locking_inset->InsetUnlock(bv);
322 if (hasSelection()) {
323 selection_start = selection_end = actpos;
324 bv->updateInset(this, false);
326 the_locking_inset = 0;
327 no_selection = false;
331 bool InsetText::UnlockInsetInInset(BufferView * bv, Inset * inset, bool lr)
333 if (!the_locking_inset)
335 if (the_locking_inset == inset) {
336 the_locking_inset->InsetUnlock(bv);
337 the_locking_inset = 0;
339 moveRight(bv, false);
342 return the_locking_inset->UnlockInsetInInset(bv, inset,lr);
346 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
348 if (!the_locking_inset)
350 if (the_locking_inset != inset)
351 return the_locking_inset->UpdateInsetInInset(bv, inset);
353 inset->draw(bv->getPainter(), real_current_font, inset_y, x);
354 bv->updateInset(this, true);
359 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
361 if (the_locking_inset) {
362 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
365 no_selection = false;
369 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
371 if (hasSelection()) {
372 selection_start = selection_end = actpos;
373 bv->updateInset(this, false);
375 no_selection = false;
376 if (the_locking_inset) {
377 setPos(bv, x, y, false);
380 if (par->GetChar(actpos) == LyXParagraph::META_INSET)
381 inset = static_cast<UpdatableInset*>(par->GetInset(actpos));
382 if (the_locking_inset == inset) {
383 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
386 // otherwise unlock the_locking_inset and lock the new inset
390 the_locking_inset->InsetUnlock(bv);
391 the_locking_inset = inset;
392 the_locking_inset->Edit(bv, x - inset_x, y - inset_y, button);
395 // otherwise only unlock the_locking_inset
396 the_locking_inset->InsetUnlock(bv);
399 the_locking_inset = 0;
401 selection_start = selection_end = actpos;
402 if (!the_locking_inset)
407 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int button)
409 if (the_locking_inset) {
410 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
415 int old = selection_end;
416 setPos(bv, x, y, false);
417 selection_end = actpos;
418 if (old != selection_end)
419 bv->updateInset(this, false);
421 no_selection = false;
425 void InsetText::InsetKeyPress(XKeyEvent * xke)
427 if (the_locking_inset) {
428 the_locking_inset->InsetKeyPress(xke);
434 UpdatableInset::RESULT
435 InsetText::LocalDispatch(BufferView * bv,
436 int action, string const & arg)
438 no_selection = false;
439 if (UpdatableInset::LocalDispatch(bv, action, arg)) {
444 UpdatableInset::RESULT
447 if ((action < 0) && arg.empty())
450 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
451 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
453 if (the_locking_inset) {
454 result = the_locking_inset->LocalDispatch(bv, action, arg);
455 if (result == DISPATCHED) {
456 the_locking_inset->ToggleInsetCursor(bv);
457 bv->updateInset(this, false);
458 the_locking_inset->ToggleInsetCursor(bv);
460 } else if (result == FINISHED) {
461 if ((action == LFUN_RIGHT) || (action == -1)) {
462 actpos = inset_pos + 1;
465 the_locking_inset = 0;
473 par->InsertChar(actpos,arg[0]);
474 par->SetFont(actpos,real_current_font);
475 computeTextRows(bv->getPainter());
476 bv->updateInset(this, true);
478 selection_start = selection_end = actpos;
481 // --- Cursor Movements ---------------------------------------------
483 moveRight(bv, false);
484 selection_end = actpos;
485 bv->updateInset(this, false);
488 result= DISPATCH_RESULT(moveRight(bv));
489 if (hasSelection()) {
490 selection_start = selection_end = actpos;
491 bv->updateInset(this, false);
493 selection_start = selection_end = actpos;
498 selection_end = actpos;
499 bv->updateInset(this, false);
502 result= DISPATCH_RESULT(moveLeft(bv));
503 if (hasSelection()) {
504 selection_start = selection_end = actpos;
505 bv->updateInset(this, false);
507 selection_start = selection_end = actpos;
512 selection_end = actpos;
513 bv->updateInset(this, false);
516 result= DISPATCH_RESULT(moveDown(bv));
517 if (hasSelection()) {
518 selection_start = selection_end = actpos;
519 bv->updateInset(this, false);
521 selection_start = selection_end = actpos;
526 selection_end = actpos;
527 bv->updateInset(this, false);
530 result= DISPATCH_RESULT(moveUp(bv));
531 if (hasSelection()) {
532 selection_start = selection_end = actpos;
533 bv->updateInset(this, false);
535 selection_start = selection_end = actpos;
539 if (!actpos || par->IsNewline(actpos-1)) {
540 if (hasSelection()) {
541 selection_start = selection_end = actpos;
542 bv->updateInset(this, false);
548 if (Delete()) { // we need update
549 selection_start = selection_end = actpos;
550 computeTextRows(bv->getPainter());
551 bv->updateInset(this, true);
552 } else if (hasSelection()) {
553 selection_start = selection_end = actpos;
554 bv->updateInset(this, false);
558 for(; actpos > rows[actrow].pos; --actpos)
559 cx -= SingleWidth(bv->getPainter(), par, actpos);
560 cx -= SingleWidth(bv->getPainter(), par, actpos);
561 if (hasSelection()) {
562 selection_start = selection_end = actpos;
563 bv->updateInset(this, false);
565 selection_start = selection_end = actpos;
569 for(; actpos < rows[actrow + 1].pos; ++actpos)
570 cx += SingleWidth(bv->getPainter(), par, actpos);
571 if (hasSelection()) {
572 selection_start = selection_end = actpos;
573 bv->updateInset(this, false);
575 selection_start = selection_end = actpos;
578 case LFUN_MATH_MODE: // Open or create a math inset
579 InsertInset(bv, new InsetFormula);
580 if (hasSelection()) {
581 selection_start = selection_end = actpos;
582 bv->updateInset(this, false);
584 selection_start = selection_end = actpos;
588 result = UNDISPATCHED;
591 if (result != FINISHED) {
592 if (!the_locking_inset)
595 bv->unlockInset(this);
600 int InsetText::Latex(ostream & os, signed char /*fragile*/) const
602 #ifdef USE_OSTREAM_ONLY
605 int ret = par->SimpleTeXOnePar(fstr, texrow);
611 int i = Latex(fstr, fragile);
618 #ifndef USE_OSTREAM_ONLY
619 int InsetText::Latex(string & file, signed char /* fragile */) const
623 return par->SimpleTeXOnePar(file, texrow);
628 void InsetText::Validate(LaTeXFeatures & features) const
630 par->validate(features);
634 // Returns the width of a character at a certain spot
635 int InsetText::SingleWidth(Painter & pain, LyXParagraph * par, int pos) const
637 LyXFont font = GetFont(par, pos);
638 char c = par->GetChar(pos);
640 if (IsPrintable(c)) {
641 return font.width(c);
642 } else if (c == LyXParagraph::META_INSET) {
643 Inset const * tmpinset = par->GetInset(pos);
645 return tmpinset->width(pain, font);
648 } else if (IsSeparatorChar(c))
650 else if (IsNewlineChar(c))
652 return font.width(c);
656 // Returns the width of a character at a certain spot
657 void InsetText::SingleHeight(Painter & pain, LyXParagraph * par,int pos,
658 int & asc, int & desc) const
660 LyXFont font = GetFont(par, pos);
661 char c = par->GetChar(pos);
664 if (c == LyXParagraph::META_INSET) {
665 Inset const * tmpinset=par->GetInset(pos);
667 asc = tmpinset->ascent(pain, font);
668 desc = tmpinset->descent(pain, font);
671 asc = font.maxAscent();
672 desc = font.maxDescent();
678 // Gets the fully instantiated font at a given position in a paragraph
679 // Basically the same routine as LyXParagraph::getFont() in paragraph.C.
680 // The difference is that this one is used for displaying, and thus we
681 // are allowed to make cosmetic improvements. For instance make footnotes
683 // If position is -1, we get the layout font of the paragraph.
684 // If position is -2, we get the font of the manual label of the paragraph.
685 LyXFont InsetText::GetFont(LyXParagraph * par, int pos) const
687 char par_depth = par->GetDepth();
689 LyXLayout const & layout =
690 textclasslist.Style(buffer->params.textclass, par->GetLayout());
692 // We specialize the 95% common case:
693 if (par->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
696 if (layout.labeltype == LABEL_MANUAL
697 && pos < BeginningOfMainBody(par)) {
699 return par->GetFontSettings(pos).realize(layout.reslabelfont);
701 return par->GetFontSettings(pos).realize(layout.resfont);
704 // process layoutfont for pos == -1 and labelfont for pos < -1
706 return layout.resfont;
708 return layout.reslabelfont;
711 // The uncommon case need not be optimized as much
713 LyXFont layoutfont, tmpfont;
717 if (pos < BeginningOfMainBody(par)) {
719 layoutfont = layout.labelfont;
722 layoutfont = layout.font;
724 tmpfont = par->GetFontSettings(pos);
725 tmpfont.realize(layoutfont);
728 // process layoutfont for pos == -1 and labelfont for pos < -1
730 tmpfont = layout.font;
732 tmpfont = layout.labelfont;
735 // Resolve against environment font information
736 //if (par->GetDepth()){ // already in while condition
737 while (par && par_depth && !tmpfont.resolved()) {
738 par = par->DepthHook(par_depth - 1);
740 tmpfont.realize(textclasslist.Style(buffer->params.textclass,
741 par->GetLayout()).font);
742 par_depth = par->GetDepth();
745 tmpfont.realize((textclasslist.TextClass(buffer->params.textclass).
751 int InsetText::BeginningOfMainBody(LyXParagraph * par) const
753 if (textclasslist.Style(buffer->params.textclass,
754 par->GetLayout()).labeltype != LABEL_MANUAL)
757 return par->BeginningOfMainBody();
761 void InsetText::GetCursorPos(int & x, int & y) const
768 int InsetText::InsetInInsetY()
770 if (!the_locking_inset)
774 return (y + the_locking_inset->InsetInInsetY());
778 void InsetText::ToggleInsetCursor(BufferView * bv)
780 if (the_locking_inset) {
781 the_locking_inset->ToggleInsetCursor(bv);
785 LyXFont font = GetFont(par, actpos);
787 int asc = font.maxAscent();
788 int desc = font.maxDescent();
791 bv->hideLockedInsetCursor();
793 bv->showLockedInsetCursor(cx, cy, asc, desc);
794 cursor_visible = !cursor_visible;
798 void InsetText::ShowInsetCursor(BufferView * bv)
800 if (!cursor_visible) {
801 LyXFont font = GetFont(par, actpos);
803 int asc = font.maxAscent();
804 int desc = font.maxDescent();
805 bv->fitLockedInsetCursor(cx, cy, asc, desc);
806 bv->showLockedInsetCursor(cx, cy, asc, desc);
807 cursor_visible = true;
812 void InsetText::HideInsetCursor(BufferView * bv)
815 ToggleInsetCursor(bv);
819 void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
824 // search right X-pos x==0 -> top_x
828 for(unsigned int i = 1;
829 ((cy + rows[i - 1].desc) < y) && (i < rows.size() - 1); ++i) {
830 cy = rows[i].baseline;
831 actpos = rows[i].pos;
839 int sw = swh = SingleWidth(bv->getPainter(), par,actpos);
840 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
842 while ((actpos < (rows[actrow + 1].pos - 1)) && ((cx + swh) < x)) {
845 sw = swh = SingleWidth(bv->getPainter(), par,actpos);
846 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
849 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
851 static_cast<UpdatableInset*>(par->GetInset(actpos));
852 inset_x = cx - top_x;
855 the_locking_inset->Edit(bv, ox - inset_x, oy - inset_y, 0);
860 bool InsetText::moveRight(BufferView * bv, bool activate_inset)
862 if (actpos >= par->Last())
864 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
866 static_cast<UpdatableInset*>(par->GetInset(actpos));
867 inset_x = cx - top_x;
870 the_locking_inset->Edit(bv, 0, 0, 0);
879 bool InsetText::moveLeft(BufferView * bv, bool activate_inset)
884 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
886 static_cast<UpdatableInset*>(par->GetInset(actpos));
888 inset_x = cx - top_x;
891 the_locking_inset->Edit(bv, the_locking_inset->
892 width(bv->getPainter(), GetFont(par,actpos)),
901 bool InsetText::moveUp(BufferView * bv, bool activate_inset)
905 cy = rows[actrow - 1].baseline - top_baseline;
906 setPos(bv, cx - top_x, cy, activate_inset);
911 bool InsetText::moveDown(BufferView * bv, bool activate_inset)
913 if (actrow >= int(rows.size() - 2))
915 cy = rows[actrow + 1].baseline - top_baseline;
916 setPos(bv, cx - top_x, cy, activate_inset);
921 void InsetText::resetPos(BufferView * bv)
923 int old_pos = actpos;
927 for(int i = 0; rows[i].pos <= actpos; ++i) {
928 cy = rows[i].baseline;
932 setPos(bv, 0, cy, false);
934 while(actpos < old_pos) {
935 cx += SingleWidth(bv->getPainter(), par,actpos);
941 bool InsetText::Delete()
943 /* some insets are undeletable here */
944 if (par->GetChar(actpos)==LyXParagraph::META_INSET) {
945 /* force complete redo when erasing display insets */
946 /* this is a cruel mathod but save..... Matthias */
947 if (par->GetInset(actpos)->Deletable() &&
948 par->GetInset(actpos)->display()) {
959 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
961 par->InsertChar(actpos, LyXParagraph::META_INSET);
962 par->InsertInset(actpos, inset);
963 computeTextRows(bv->getPainter());
964 bv->updateInset(this, true);
965 the_locking_inset = static_cast<UpdatableInset*>(inset);
966 inset_x = cx - top_x;
969 inset->Edit(bv, 0, 0, 0);
974 UpdatableInset * InsetText::GetLockingInset()
976 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
980 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
982 // if there is no selection just set the current_font
983 if (!hasSelection()) {
984 // Determine basis font
986 if (actpos < BeginningOfMainBody(par))
987 layoutfont = GetFont(par, -2);
989 layoutfont = GetFont(par, -1);
991 // Update current font
992 real_current_font.update(font, toggleall);
994 // Reduce to implicit settings
995 current_font = real_current_font;
996 current_font.reduce(layoutfont);
997 // And resolve it completely
998 real_current_font.realize(layoutfont);
1003 if (selection_start > selection_end) {
1004 s_start = selection_end;
1005 s_end = selection_start;
1007 s_start = selection_start;
1008 s_end = selection_end;
1011 while(s_start < s_end) {
1012 newfont = GetFont(par,s_start);
1013 newfont.update(font, toggleall);
1014 SetCharFont(s_start, newfont);
1017 computeTextRows(bv->getPainter());
1018 bv->updateInset(this, true);
1022 void InsetText::SetCharFont(int pos, LyXFont const & f)
1024 /* let the insets convert their font */
1027 if (par->GetChar(pos) == LyXParagraph::META_INSET) {
1028 if (par->GetInset(pos))
1029 font = par->GetInset(pos)->ConvertFont(font);
1031 LyXLayout const & layout =
1032 textclasslist.Style(buffer->params.textclass,par->GetLayout());
1034 // Get concrete layout font to reduce against
1037 if (pos < BeginningOfMainBody(par))
1038 layoutfont = layout.labelfont;
1040 layoutfont = layout.font;
1043 layoutfont.realize((textclasslist.TextClass(buffer->params.textclass).
1046 // Now, reduce font against full layout font
1047 font.reduce(layoutfont);
1049 par->SetFont(pos, font);
1053 void InsetText::computeTextRows(Painter & pain) const
1067 rows.erase(rows.begin(),rows.end());
1068 int width = wordAscent = wordDescent = 0;
1069 insetWidth = maxAscent = maxDescent = 0;
1074 rows.push_back(row);
1075 if (!autoBreakRows) {
1076 for(p = 0; p < par->Last(); ++p) {
1077 insetWidth += SingleWidth(pain, par, p);
1078 SingleHeight(pain, par, p, asc, desc);
1079 if (asc > maxAscent)
1081 if (desc > maxDescent)
1084 rows[0].asc = maxAscent;
1085 rows[0].desc = maxDescent;
1086 // alocate a dummy row for the endpos
1087 row.pos = par->Last();
1088 rows.push_back(row);
1092 bool is_first_word_in_row = true;
1097 maxWidth = buffer->getUser()->paperWidth();
1098 for(p = 0; p < par->Last(); ++p) {
1099 cw = SingleWidth(pain, par, p);
1101 lastWordWidth += cw;
1102 SingleHeight(pain, par, p, asc, desc);
1103 if (asc > wordAscent)
1105 if (desc > wordDescent)
1107 Inset const * inset = 0;
1108 if (((p + 1) < par->Last()) &&
1109 (par->GetChar(p + 1)==LyXParagraph::META_INSET))
1110 inset = par->GetInset(p + 1);
1111 if (inset && inset->display()) {
1112 if (!is_first_word_in_row && (width >= maxWidth)) {
1113 // we have to split also the row above
1114 rows[rows.size() - 1].asc = oasc;
1115 rows[rows.size() - 1].desc = odesc;
1117 rows.push_back(row);
1119 odesc = wordDescent;
1120 if (insetWidth < owidth)
1121 insetWidth = owidth;
1122 width = lastWordWidth;
1125 if (oasc < wordAscent)
1127 if (odesc < wordDescent)
1128 odesc = wordDescent;
1130 rows[rows.size() - 1].asc = oasc;
1131 rows[rows.size() - 1].desc = odesc;
1133 rows.push_back(row);
1134 SingleHeight(pain, par, p, asc, desc);
1135 rows[rows.size() - 1].asc = asc;
1136 rows[rows.size() - 1].desc = desc;
1137 row.pos = nwp = p + 1;
1138 rows.push_back(row);
1139 oasc = odesc = width = lastWordWidth = 0;
1140 is_first_word_in_row = true;
1141 wordAscent = wordDescent = 0;
1143 } else if (par->IsSeparator(p)) {
1144 if (width >= maxWidth) {
1145 if (is_first_word_in_row) {
1146 rows[rows.size() - 1].asc = wordAscent;
1147 rows[rows.size() - 1].desc = wordDescent;
1149 rows.push_back(row);
1150 oasc = odesc = width = 0;
1152 rows[rows.size() - 1].asc = oasc;
1153 rows[rows.size() - 1].desc = odesc;
1155 rows.push_back(row);
1157 odesc = wordDescent;
1158 if (insetWidth < owidth)
1159 insetWidth = owidth;
1160 width = lastWordWidth;
1162 wordAscent = wordDescent = lastWordWidth = 0;
1167 if (oasc < wordAscent)
1169 if (odesc < wordDescent)
1170 odesc = wordDescent;
1171 wordAscent = wordDescent = lastWordWidth = 0;
1173 is_first_word_in_row = false;
1176 // if we have some data in the paragraph we have ascent/descent
1178 if (width >= maxWidth) {
1180 rows[rows.size() - 1].asc = oasc;
1181 rows[rows.size() - 1].desc = odesc;
1182 // assign and allocate lower row
1184 rows.push_back(row);
1185 rows[rows.size() - 1].asc = wordAscent;
1186 rows[rows.size() - 1].desc = wordDescent;
1187 if (insetWidth < owidth)
1188 insetWidth = owidth;
1190 if (insetWidth < width)
1193 // assign last row data
1194 if (oasc < wordAscent)
1196 if (odesc < wordDescent)
1197 odesc = wordDescent;
1198 rows[rows.size() - 1].asc = oasc;
1199 rows[rows.size() - 1].desc = odesc;
1202 // alocate a dummy row for the endpos
1203 row.pos = par->Last();
1204 rows.push_back(row);
1205 // calculate maxAscent/Descent
1206 maxAscent = rows[0].asc;
1207 maxDescent = rows[0].desc;
1208 for (unsigned int i = 1; i < rows.size() - 1; ++i) {
1209 maxDescent += rows[i].asc + rows[i].desc + interline_space;
1212 if (the_locking_inset) {
1213 computeBaselines(top_baseline);
1216 inset_x = cx - top_x;
1223 void InsetText::computeBaselines(int baseline) const
1225 rows[0].baseline = baseline;
1226 for (unsigned int i = 1; i < rows.size() - 1; i++) {
1227 rows[i].baseline = rows[i - 1].baseline + rows[i - 1].desc +
1228 rows[i].asc + interline_space;