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;
69 InsetText::InsetText(InsetText const & ins, Buffer * buf)
71 par = new LyXParagraph(ins.par);
72 the_locking_inset = 0;
74 cursor_visible = false;
75 maxWidth = old_x = -1;
76 actpos = selection_start = selection_end = 0;
83 InsetText::~InsetText()
89 Inset * InsetText::Clone() const
91 InsetText * t = new InsetText(*this, buffer);
96 void InsetText::Write(ostream & os) const
99 WriteParagraphData(os);
102 void InsetText::WriteParagraphData(ostream & os) const
104 par->writeFile(os, buffer->params, 0, 0);
107 void InsetText::Read(LyXLex & lex)
109 string token, tmptok;
111 LyXParagraph *return_par = 0;
112 char depth = 0; // signed or unsigned?
113 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
114 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
115 LyXFont font(LyXFont::ALL_INHERIT);
118 par = new LyXParagraph;
122 token = lex.GetString();
125 if (token == "\\end_inset")
127 if (buffer->parseSingleLyXformat2Token(lex, par, return_par,
131 // the_end read this should NEVER happen
132 lex.printError("\\the_end read in inset! Error in document!");
136 if (token != "\\end_inset") {
137 lex.printError("Missing \\end_inset at this point. "
144 int InsetText::ascent(Painter & pain, LyXFont const & font) const
147 computeTextRows(pain);
152 return font.maxAscent();
156 int InsetText::descent(Painter & pain, LyXFont const & font) const
159 computeTextRows(pain);
164 return font.maxDescent();
168 int InsetText::width(Painter & pain, LyXFont const &) const
171 computeTextRows(pain);
178 int InsetText::getMaxWidth(UpdatableInset * inset) const
180 if (!the_locking_inset) {
181 lyxerr << "Text: No locking inset in this inset.\n";
185 if (the_locking_inset == inset)
188 return the_locking_inset->getMaxWidth(inset);
192 void InsetText::draw(Painter & pain, LyXFont const & f,
193 int baseline, float & x) const
196 computeTextRows(pain);
197 // init_inset = false;
199 UpdatableInset::draw(pain, f, baseline, x);
201 bool do_reset_pos = (x != top_x) || (baseline != top_baseline);
203 top_baseline = baseline;
204 computeBaselines(baseline);
205 for(unsigned int r = 0; r < rows.size() - 1; ++r) {
206 drawRowSelection(pain, rows[r].pos, rows[r + 1].pos, r,
207 rows[r].baseline, x);
208 drawRowText(pain, rows[r].pos, rows[r + 1].pos, rows[r].baseline, x);
211 if (!the_locking_inset && do_reset_pos) {
212 // HideInsetCursor(bv);
214 // ShowInsetCursor(bv);
219 void InsetText::drawRowSelection(Painter & pain, int startpos, int endpos,
220 int row, int baseline, float x) const
226 if (selection_start > selection_end) {
227 s_start = selection_end;
228 s_end = selection_start;
230 s_start = selection_start;
231 s_end = selection_end;
233 if ((s_start > endpos) || (s_end < startpos))
237 int ssel_x = esel_x = int(x);
240 for(; p < endpos; ++p) {
243 if ((p >= s_start) && (p <= s_end))
245 char ch = par->GetChar(p);
246 font = GetFont(par,p);
247 if (IsFloatChar(ch)) {
249 } else if (ch == LyXParagraph::META_INSET) {
250 Inset const * tmpinset = par->GetInset(p);
251 x += tmpinset->width(pain, font);
253 x += pain.width(ch,font);
258 if ((p >= s_start) && (p <= s_end))
260 if (ssel_x < esel_x) {
261 pain.fillRectangle(int(ssel_x), baseline-rows[row].asc,
262 int(esel_x - ssel_x),
263 rows[row].asc + rows[row].desc,
269 void InsetText::drawRowText(Painter & pain, int startpos, int endpos,
270 int baseline, float x) const
272 Assert(endpos <= par->Last());
274 for(int p = startpos; p < endpos; ++p) {
275 char ch = par->GetChar(p);
276 LyXFont font = GetFont(par,p);
277 if (IsFloatChar(ch)) {
279 } else if (ch == LyXParagraph::META_INSET) {
280 Inset * tmpinset = par->GetInset(p);
282 tmpinset->draw(pain, font, baseline, x);
284 pain.text(int(x), baseline, ch, font);
285 x += pain.width(ch,font);
291 char const * InsetText::EditMessage() const
293 return _("Opened Text Inset");
297 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
299 UpdatableInset::Edit(bv, x, y, button);
302 the_locking_inset = 0;
303 inset_pos = inset_x = inset_y = 0;
306 selection_start = selection_end = actpos;
307 current_font = real_current_font = GetFont(par, actpos);
311 void InsetText::InsetUnlock(BufferView * bv)
313 if (the_locking_inset)
314 the_locking_inset->InsetUnlock(bv);
316 if (hasSelection()) {
317 selection_start = selection_end = actpos;
318 bv->updateInset(this, false);
320 the_locking_inset = 0;
321 no_selection = false;
325 bool InsetText::UnlockInsetInInset(BufferView * bv, Inset * inset, bool lr)
327 if (!the_locking_inset)
329 if (the_locking_inset == inset) {
330 the_locking_inset->InsetUnlock(bv);
331 the_locking_inset = 0;
333 moveRight(bv, false);
336 return the_locking_inset->UnlockInsetInInset(bv, inset,lr);
340 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
342 if (!the_locking_inset)
344 if (the_locking_inset != inset)
345 return the_locking_inset->UpdateInsetInInset(bv, inset);
347 inset->draw(bv->getPainter(), real_current_font, inset_y, x);
348 bv->updateInset(this, true);
353 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
355 if (the_locking_inset) {
356 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
359 no_selection = false;
363 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
365 if (hasSelection()) {
366 selection_start = selection_end = actpos;
367 bv->updateInset(this, false);
369 no_selection = false;
370 if (the_locking_inset) {
371 setPos(bv, x, y, false);
374 if (par->GetChar(actpos) == LyXParagraph::META_INSET)
375 inset = static_cast<UpdatableInset*>(par->GetInset(actpos));
376 if (the_locking_inset == inset) {
377 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
380 // otherwise unlock the_locking_inset and lock the new inset
384 the_locking_inset->InsetUnlock(bv);
385 the_locking_inset = inset;
386 the_locking_inset->Edit(bv, x - inset_x, y - inset_y, button);
389 // otherwise only unlock the_locking_inset
390 the_locking_inset->InsetUnlock(bv);
393 the_locking_inset = 0;
395 selection_start = selection_end = actpos;
396 if (!the_locking_inset)
401 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int button)
403 if (the_locking_inset) {
404 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
409 int old = selection_end;
410 setPos(bv, x, y, false);
411 selection_end = actpos;
412 if (old != selection_end)
413 bv->updateInset(this, false);
415 no_selection = false;
419 void InsetText::InsetKeyPress(XKeyEvent * xke)
421 if (the_locking_inset) {
422 the_locking_inset->InsetKeyPress(xke);
428 UpdatableInset::RESULT InsetText::LocalDispatch(BufferView * bv,
429 int action, string const & arg)
431 no_selection = false;
432 if (UpdatableInset::LocalDispatch(bv, action, arg)) {
437 UpdatableInset::RESULT
440 if ((action < 0) && arg.empty())
443 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
444 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
446 if (the_locking_inset) {
447 result = the_locking_inset->LocalDispatch(bv, action, arg);
448 if (result == DISPATCHED) {
449 the_locking_inset->ToggleInsetCursor(bv);
450 bv->updateInset(this, false);
451 the_locking_inset->ToggleInsetCursor(bv);
453 } else if (result == FINISHED) {
454 if ((action == LFUN_RIGHT) || (action == -1)) {
455 actpos = inset_pos + 1;
458 the_locking_inset = 0;
466 par->InsertChar(actpos,arg[0]);
467 par->SetFont(actpos,real_current_font);
468 computeTextRows(bv->getPainter());
469 bv->updateInset(this, true);
471 selection_start = selection_end = actpos;
474 // --- Cursor Movements ---------------------------------------------
476 moveRight(bv, false);
477 selection_end = actpos;
478 bv->updateInset(this, false);
481 result= DISPATCH_RESULT(moveRight(bv));
482 if (hasSelection()) {
483 selection_start = selection_end = actpos;
484 bv->updateInset(this, false);
486 selection_start = selection_end = actpos;
491 selection_end = actpos;
492 bv->updateInset(this, false);
495 result= DISPATCH_RESULT(moveLeft(bv));
496 if (hasSelection()) {
497 selection_start = selection_end = actpos;
498 bv->updateInset(this, false);
500 selection_start = selection_end = actpos;
505 selection_end = actpos;
506 bv->updateInset(this, false);
509 result= DISPATCH_RESULT(moveDown(bv));
510 if (hasSelection()) {
511 selection_start = selection_end = actpos;
512 bv->updateInset(this, false);
514 selection_start = selection_end = actpos;
519 selection_end = actpos;
520 bv->updateInset(this, false);
523 result= DISPATCH_RESULT(moveUp(bv));
524 if (hasSelection()) {
525 selection_start = selection_end = actpos;
526 bv->updateInset(this, false);
528 selection_start = selection_end = actpos;
532 if (!actpos || par->IsNewline(actpos-1)) {
533 if (hasSelection()) {
534 selection_start = selection_end = actpos;
535 bv->updateInset(this, false);
541 if (Delete()) { // we need update
542 selection_start = selection_end = actpos;
543 computeTextRows(bv->getPainter());
544 bv->updateInset(this, true);
545 } else if (hasSelection()) {
546 selection_start = selection_end = actpos;
547 bv->updateInset(this, false);
551 for(; actpos > rows[actrow].pos; --actpos)
552 cx -= SingleWidth(bv->getPainter(), par, actpos);
553 cx -= SingleWidth(bv->getPainter(), par, actpos);
554 if (hasSelection()) {
555 selection_start = selection_end = actpos;
556 bv->updateInset(this, false);
558 selection_start = selection_end = actpos;
562 for(; actpos < rows[actrow + 1].pos; ++actpos)
563 cx += SingleWidth(bv->getPainter(), par, actpos);
564 if (hasSelection()) {
565 selection_start = selection_end = actpos;
566 bv->updateInset(this, false);
568 selection_start = selection_end = actpos;
571 case LFUN_MATH_MODE: // Open or create a math inset
572 InsertInset(bv, new InsetFormula);
573 if (hasSelection()) {
574 selection_start = selection_end = actpos;
575 bv->updateInset(this, false);
577 selection_start = selection_end = actpos;
581 result = UNDISPATCHED;
584 if (result != FINISHED) {
585 if (!the_locking_inset)
588 bv->unlockInset(this);
593 int InsetText::Latex(ostream & os, signed char fragile) const
597 int i = Latex(fstr, fragile);
603 int InsetText::Latex(string & file, signed char /* fragile */) const
607 return par->SimpleTeXOnePar(file, texrow);
611 void InsetText::Validate(LaTeXFeatures & features) const
613 par->validate(features);
617 // Returns the width of a character at a certain spot
618 int InsetText::SingleWidth(Painter & pain, LyXParagraph * par, int pos) const
620 LyXFont font = GetFont(par, pos);
621 char c = par->GetChar(pos);
623 if (IsPrintable(c)) {
624 return font.width(c);
625 } else if (c == LyXParagraph::META_INSET) {
626 Inset const * tmpinset = par->GetInset(pos);
628 return tmpinset->width(pain, font);
631 } else if (IsSeparatorChar(c))
633 else if (IsNewlineChar(c))
635 return font.width(c);
639 // Returns the width of a character at a certain spot
640 void InsetText::SingleHeight(Painter & pain, LyXParagraph * par,int pos,
641 int & asc, int & desc) const
643 LyXFont font = GetFont(par, pos);
644 char c = par->GetChar(pos);
647 if (c == LyXParagraph::META_INSET) {
648 Inset const * tmpinset=par->GetInset(pos);
650 asc = tmpinset->ascent(pain, font);
651 desc = tmpinset->descent(pain, font);
654 asc = font.maxAscent();
655 desc = font.maxDescent();
661 // Gets the fully instantiated font at a given position in a paragraph
662 // Basically the same routine as LyXParagraph::getFont() in paragraph.C.
663 // The difference is that this one is used for displaying, and thus we
664 // are allowed to make cosmetic improvements. For instance make footnotes
666 // If position is -1, we get the layout font of the paragraph.
667 // If position is -2, we get the font of the manual label of the paragraph.
668 LyXFont InsetText::GetFont(LyXParagraph * par, int pos) const
670 char par_depth = par->GetDepth();
672 LyXLayout const & layout =
673 textclasslist.Style(buffer->params.textclass, par->GetLayout());
675 // We specialize the 95% common case:
676 if (par->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
679 if (layout.labeltype == LABEL_MANUAL
680 && pos < BeginningOfMainBody(par)) {
682 return par->GetFontSettings(pos).realize(layout.reslabelfont);
684 return par->GetFontSettings(pos).realize(layout.resfont);
687 // process layoutfont for pos == -1 and labelfont for pos < -1
689 return layout.resfont;
691 return layout.reslabelfont;
694 // The uncommon case need not be optimized as much
696 LyXFont layoutfont, tmpfont;
700 if (pos < BeginningOfMainBody(par)) {
702 layoutfont = layout.labelfont;
705 layoutfont = layout.font;
707 tmpfont = par->GetFontSettings(pos);
708 tmpfont.realize(layoutfont);
711 // process layoutfont for pos == -1 and labelfont for pos < -1
713 tmpfont = layout.font;
715 tmpfont = layout.labelfont;
718 // Resolve against environment font information
719 //if (par->GetDepth()){ // already in while condition
720 while (par && par_depth && !tmpfont.resolved()) {
721 par = par->DepthHook(par_depth - 1);
723 tmpfont.realize(textclasslist.Style(buffer->params.textclass,
724 par->GetLayout()).font);
725 par_depth = par->GetDepth();
728 tmpfont.realize((textclasslist.TextClass(buffer->params.textclass).
734 int InsetText::BeginningOfMainBody(LyXParagraph * par) const
736 if (textclasslist.Style(buffer->params.textclass,
737 par->GetLayout()).labeltype != LABEL_MANUAL)
740 return par->BeginningOfMainBody();
744 void InsetText::GetCursorPos(int & x, int & y) const
751 int InsetText::InsetInInsetY()
753 if (!the_locking_inset)
757 return (y + the_locking_inset->InsetInInsetY());
761 void InsetText::ToggleInsetCursor(BufferView * bv)
763 if (the_locking_inset) {
764 the_locking_inset->ToggleInsetCursor(bv);
768 LyXFont font = GetFont(par, actpos);
770 int asc = font.maxAscent();
771 int desc = font.maxDescent();
774 bv->hideLockedInsetCursor();
776 bv->showLockedInsetCursor(cx, cy, asc, desc);
777 cursor_visible = !cursor_visible;
781 void InsetText::ShowInsetCursor(BufferView * bv)
783 if (!cursor_visible) {
784 LyXFont font = GetFont(par, actpos);
786 int asc = font.maxAscent();
787 int desc = font.maxDescent();
788 bv->fitLockedInsetCursor(cx, cy, asc, desc);
789 bv->showLockedInsetCursor(cx, cy, asc, desc);
790 cursor_visible = true;
795 void InsetText::HideInsetCursor(BufferView * bv)
798 ToggleInsetCursor(bv);
802 void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
807 // search right X-pos x==0 -> top_x
811 for(unsigned int i = 1;
812 ((cy + rows[i - 1].desc) < y) && (i < rows.size() - 1); ++i) {
813 cy = rows[i].baseline;
814 actpos = rows[i].pos;
822 int sw = swh = SingleWidth(bv->getPainter(), par,actpos);
823 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
825 while ((actpos < (rows[actrow + 1].pos - 1)) && ((cx + swh) < x)) {
828 sw = swh = SingleWidth(bv->getPainter(), par,actpos);
829 if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
832 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
834 static_cast<UpdatableInset*>(par->GetInset(actpos));
835 inset_x = cx - top_x;
838 the_locking_inset->Edit(bv, ox - inset_x, oy - inset_y, 0);
843 bool InsetText::moveRight(BufferView * bv, bool activate_inset)
845 if (actpos >= par->Last())
847 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
849 static_cast<UpdatableInset*>(par->GetInset(actpos));
850 inset_x = cx - top_x;
853 the_locking_inset->Edit(bv, 0, 0, 0);
862 bool InsetText::moveLeft(BufferView * bv, bool activate_inset)
867 if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
869 static_cast<UpdatableInset*>(par->GetInset(actpos));
871 inset_x = cx - top_x;
874 the_locking_inset->Edit(bv, the_locking_inset->
875 width(bv->getPainter(), GetFont(par,actpos)),
884 bool InsetText::moveUp(BufferView * bv, bool activate_inset)
888 cy = rows[actrow - 1].baseline - top_baseline;
889 setPos(bv, cx - top_x, cy, activate_inset);
894 bool InsetText::moveDown(BufferView * bv, bool activate_inset)
896 if (actrow >= int(rows.size() - 2))
898 cy = rows[actrow + 1].baseline - top_baseline;
899 setPos(bv, cx - top_x, cy, activate_inset);
904 void InsetText::resetPos(BufferView * bv)
906 int old_pos = actpos;
910 for(int i = 0; rows[i].pos <= actpos; ++i) {
911 cy = rows[i].baseline;
915 setPos(bv, 0, cy, false);
917 while(actpos < old_pos) {
918 cx += SingleWidth(bv->getPainter(), par,actpos);
924 bool InsetText::Delete()
926 /* some insets are undeletable here */
927 if (par->GetChar(actpos)==LyXParagraph::META_INSET) {
928 /* force complete redo when erasing display insets */
929 /* this is a cruel mathod but save..... Matthias */
930 if (par->GetInset(actpos)->Deletable() &&
931 par->GetInset(actpos)->display()) {
942 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
944 par->InsertChar(actpos, LyXParagraph::META_INSET);
945 par->InsertInset(actpos, inset);
946 computeTextRows(bv->getPainter());
947 bv->updateInset(this, true);
948 the_locking_inset = static_cast<UpdatableInset*>(inset);
949 inset_x = cx - top_x;
952 inset->Edit(bv, 0, 0, 0);
957 UpdatableInset * InsetText::GetLockingInset()
959 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
963 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
965 // if there is no selection just set the current_font
966 if (!hasSelection()) {
967 // Determine basis font
969 if (actpos < BeginningOfMainBody(par))
970 layoutfont = GetFont(par, -2);
972 layoutfont = GetFont(par, -1);
974 // Update current font
975 real_current_font.update(font, toggleall);
977 // Reduce to implicit settings
978 current_font = real_current_font;
979 current_font.reduce(layoutfont);
980 // And resolve it completely
981 real_current_font.realize(layoutfont);
986 if (selection_start > selection_end) {
987 s_start = selection_end;
988 s_end = selection_start;
990 s_start = selection_start;
991 s_end = selection_end;
994 while(s_start < s_end) {
995 newfont = GetFont(par,s_start);
996 newfont.update(font, toggleall);
997 SetCharFont(s_start, newfont);
1000 computeTextRows(bv->getPainter());
1001 bv->updateInset(this, true);
1005 void InsetText::SetCharFont(int pos, LyXFont const & f)
1007 /* let the insets convert their font */
1010 if (par->GetChar(pos) == LyXParagraph::META_INSET) {
1011 if (par->GetInset(pos))
1012 font = par->GetInset(pos)->ConvertFont(font);
1014 LyXLayout const & layout =
1015 textclasslist.Style(buffer->params.textclass,par->GetLayout());
1017 // Get concrete layout font to reduce against
1020 if (pos < BeginningOfMainBody(par))
1021 layoutfont = layout.labelfont;
1023 layoutfont = layout.font;
1026 layoutfont.realize((textclasslist.TextClass(buffer->params.textclass).
1029 // Now, reduce font against full layout font
1030 font.reduce(layoutfont);
1032 par->SetFont(pos, font);
1036 void InsetText::computeTextRows(Painter & pain) const
1050 rows.erase(rows.begin(),rows.end());
1051 int width = wordAscent = wordDescent = 0;
1052 insetWidth = maxAscent = maxDescent = 0;
1057 rows.push_back(row);
1059 for(p = 0; p < par->Last(); ++p) {
1060 insetWidth += SingleWidth(pain, par, p);
1061 SingleHeight(pain, par, p, asc, desc);
1062 if (asc > maxAscent)
1064 if (desc > maxDescent)
1067 rows[0].asc = maxAscent;
1068 rows[0].desc = maxDescent;
1069 // alocate a dummy row for the endpos
1070 row.pos = par->Last();
1071 rows.push_back(row);
1074 bool is_first_word_in_row = true;
1079 for(p = 0; p < par->Last(); ++p) {
1080 cw = SingleWidth(pain, par, p);
1082 lastWordWidth += cw;
1083 SingleHeight(pain, par, p, asc, desc);
1084 if (asc > wordAscent)
1086 if (desc > wordDescent)
1088 Inset const * inset = 0;
1089 if (((p + 1) < par->Last()) &&
1090 (par->GetChar(p + 1)==LyXParagraph::META_INSET))
1091 inset = par->GetInset(p + 1);
1092 if (inset && inset->display()) {
1093 if (!is_first_word_in_row && (width >= maxWidth)) {
1094 // we have to split also the row above
1095 rows[rows.size() - 1].asc = oasc;
1096 rows[rows.size() - 1].desc = odesc;
1098 rows.push_back(row);
1100 odesc = wordDescent;
1101 if (insetWidth < owidth)
1102 insetWidth = owidth;
1103 width = lastWordWidth;
1106 if (oasc < wordAscent)
1108 if (odesc < wordDescent)
1109 odesc = wordDescent;
1111 rows[rows.size() - 1].asc = oasc;
1112 rows[rows.size() - 1].desc = odesc;
1114 rows.push_back(row);
1115 SingleHeight(pain, par, p, asc, desc);
1116 rows[rows.size() - 1].asc = asc;
1117 rows[rows.size() - 1].desc = desc;
1118 row.pos = nwp = p + 1;
1119 rows.push_back(row);
1120 oasc = odesc = width = lastWordWidth = 0;
1121 is_first_word_in_row = true;
1122 wordAscent = wordDescent = 0;
1124 } else if (par->IsSeparator(p)) {
1125 if (width >= maxWidth) {
1126 if (is_first_word_in_row) {
1127 rows[rows.size() - 1].asc = wordAscent;
1128 rows[rows.size() - 1].desc = wordDescent;
1130 rows.push_back(row);
1131 oasc = odesc = width = 0;
1133 rows[rows.size() - 1].asc = oasc;
1134 rows[rows.size() - 1].desc = odesc;
1136 rows.push_back(row);
1138 odesc = wordDescent;
1139 if (insetWidth < owidth)
1140 insetWidth = owidth;
1141 width = lastWordWidth;
1143 wordAscent = wordDescent = lastWordWidth = 0;
1148 if (oasc < wordAscent)
1150 if (odesc < wordDescent)
1151 odesc = wordDescent;
1152 wordAscent = wordDescent = lastWordWidth = 0;
1154 is_first_word_in_row = false;
1157 // if we have some data in the paragraph we have ascent/descent
1159 if (width >= maxWidth) {
1161 rows[rows.size() - 1].asc = oasc;
1162 rows[rows.size() - 1].desc = odesc;
1163 // assign and allocate lower row
1165 rows.push_back(row);
1166 rows[rows.size() - 1].asc = wordAscent;
1167 rows[rows.size() - 1].desc = wordDescent;
1168 if (insetWidth < owidth)
1169 insetWidth = owidth;
1171 if (insetWidth < width)
1174 // assign last row data
1175 if (oasc < wordAscent)
1177 if (odesc < wordDescent)
1178 odesc = wordDescent;
1179 rows[rows.size() - 1].asc = oasc;
1180 rows[rows.size() - 1].desc = odesc;
1183 // alocate a dummy row for the endpos
1184 row.pos = par->Last();
1185 rows.push_back(row);
1186 // calculate maxAscent/Descent
1187 maxAscent = rows[0].asc;
1188 maxDescent = rows[0].desc;
1189 for (unsigned int i = 1; i < rows.size() - 1; ++i) {
1190 maxDescent += rows[i].asc + rows[i].desc + interline_space;
1193 if (the_locking_inset) {
1194 computeBaselines(top_baseline);
1197 inset_x = cx - top_x;
1204 void InsetText::computeBaselines(int baseline) const
1206 rows[0].baseline = baseline;
1207 for (unsigned int i = 1; i < rows.size() - 1; i++) {
1208 rows[i].baseline = rows[i - 1].baseline + rows[i - 1].desc +
1209 rows[i].asc + interline_space;