3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Stefan Schimanski
9 * Full author contact details are available in file CREDITS.
16 #include "InsetMathBrace.h"
17 #include "InsetMathFont.h"
18 #include "InsetMathScript.h"
19 #include "MacroTable.h"
20 #include "MathMacro.h"
21 #include "MathStream.h"
22 #include "MathSupport.h"
23 #include "MetricsInfo.h"
24 #include "ReplaceData.h"
27 #include "BufferView.h"
28 #include "CoordCache.h"
31 #include "mathed/InsetMathUnknown.h"
33 #include "support/debug.h"
34 #include "support/docstream.h"
36 #include "frontends/FontMetrics.h"
37 #include "frontends/Painter.h"
39 #include "support/gettext.h"
40 #include "support/lassert.h"
41 #include "support/lyxalgo.h"
50 MathData::MathData(Buffer * buf, const_iterator from, const_iterator to)
51 : base_type(from, to), minasc_(0), mindes_(0), slevel_(0),
52 sshift_(0), kerning_(0), buffer_(buf)
56 MathAtom & MathData::operator[](pos_type pos)
58 LBUFERR(pos < size());
59 return base_type::operator[](pos);
63 MathAtom const & MathData::operator[](pos_type pos) const
65 LBUFERR(pos < size());
66 return base_type::operator[](pos);
70 void MathData::insert(size_type pos, MathAtom const & t)
72 LBUFERR(pos <= size());
73 base_type::insert(begin() + pos, t);
77 void MathData::insert(size_type pos, MathData const & ar)
79 LBUFERR(pos <= size());
80 base_type::insert(begin() + pos, ar.begin(), ar.end());
84 void MathData::append(MathData const & ar)
90 void MathData::erase(size_type pos)
97 void MathData::erase(iterator pos1, iterator pos2)
99 base_type::erase(pos1, pos2);
103 void MathData::erase(iterator pos)
105 base_type::erase(pos);
109 void MathData::erase(size_type pos1, size_type pos2)
111 base_type::erase(begin() + pos1, begin() + pos2);
115 void MathData::dump2() const
119 for (const_iterator it = begin(); it != end(); ++it)
121 lyxerr << to_utf8(os.str());
125 void MathData::dump() const
129 for (const_iterator it = begin(); it != end(); ++it)
130 ns << '<' << *it << '>';
131 lyxerr << to_utf8(os.str());
135 void MathData::validate(LaTeXFeatures & features) const
137 for (const_iterator it = begin(); it != end(); ++it)
138 (*it)->validate(features);
142 bool MathData::match(MathData const & ar) const
144 return size() == ar.size() && matchpart(ar, 0);
148 bool MathData::matchpart(MathData const & ar, pos_type pos) const
150 if (size() < ar.size() + pos)
152 const_iterator it = begin() + pos;
153 for (const_iterator jt = ar.begin(); jt != ar.end(); ++jt, ++it)
154 if (asString(*it) != asString(*jt))
160 void MathData::replace(ReplaceData & rep)
162 for (size_type i = 0; i < size(); ++i) {
163 if (find1(rep.from, i)) {
165 lyxerr << "match found!" << endl;
166 erase(i, i + rep.from.size());
171 // FIXME: temporarily disabled
172 // for (const_iterator it = begin(); it != end(); ++it)
173 // it->nucleus()->replace(rep);
177 bool MathData::find1(MathData const & ar, size_type pos) const
179 lyxerr << "finding '" << ar << "' in '" << *this << "'" << endl;
180 for (size_type i = 0, n = ar.size(); i < n; ++i)
181 if (asString(operator[](pos + i)) != asString(ar[i]))
187 MathData::size_type MathData::find(MathData const & ar) const
189 for (int i = 0, last = size() - ar.size(); i < last; ++i)
196 MathData::size_type MathData::find_last(MathData const & ar) const
198 for (int i = size() - ar.size(); i >= 0; --i)
205 bool MathData::contains(MathData const & ar) const
207 if (find(ar) != size())
209 for (const_iterator it = begin(); it != end(); ++it)
210 if ((*it)->contains(ar))
216 void MathData::touch() const
224 bool isInside(DocIterator const & it, MathData const & ar,
225 pos_type p1, pos_type p2)
227 for (size_t i = 0; i != it.depth(); ++i) {
228 CursorSlice const & sl = it[i];
229 if (sl.inset().inMathed() && &sl.cell() == &ar)
230 return p1 <= sl.pos() && sl.pos() < p2;
239 void MathData::metrics(MetricsInfo & mi, Dimension & dim) const
241 frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
242 dim = fm.dimension('I');
243 int xascent = fm.dimension('x').ascent();
244 if (xascent >= dim.asc)
245 xascent = (2 * dim.asc) / 3;
247 mindes_ = (3 * xascent) / 4;
248 slevel_ = (4 * xascent) / 5;
249 sshift_ = xascent / 4;
253 // Cache the dimension.
254 mi.base.bv->coordCache().arrays().add(this, dim);
258 Cursor & cur = mi.base.bv->cursor();
259 const_cast<MathData*>(this)->updateMacros(&cur, mi.macrocontext, InternalUpdate);
261 DocIterator const & inlineCompletionPos = mi.base.bv->inlineCompletionPos();
262 MathData const * inlineCompletionData = 0;
263 if (inlineCompletionPos.inMathed())
264 inlineCompletionData = &inlineCompletionPos.cell();
269 CoordCache::Insets & coords = mi.base.bv->coordCache().insets();
270 for (pos_type i = 0, n = size(); i != n; ++i) {
271 MathAtom const & at = operator[](i);
273 coords.add(at.nucleus(), d);
276 kerning_ = at->kerning(mi.base.bv);
278 // HACK to draw completion suggestion inline
279 if (inlineCompletionData != this
280 || size_t(inlineCompletionPos.pos()) != i + 1)
283 docstring const & completion = mi.base.bv->inlineCompletion();
284 if (completion.length() == 0)
287 FontInfo font = mi.base.font;
288 augmentFont(font, from_ascii("mathnormal"));
289 dim.wid += mathed_string_width(font, completion);
291 // Cache the dimension.
292 mi.base.bv->coordCache().arrays().add(this, dim);
296 void MathData::draw(PainterInfo & pi, int x, int y) const
298 //lyxerr << "MathData::draw: x: " << x << " y: " << y << endl;
299 BufferView & bv = *pi.base.bv;
302 Dimension const & dim = bv.coordCache().getArrays().dim(this);
305 pi.pain.rectangle(x, y - dim.ascent(), dim.width(), dim.height(), Color_mathline);
309 // don't draw outside the workarea
310 if (y + dim.descent() <= 0
311 || y - dim.ascent() >= bv.workHeight()
312 || x + dim.width() <= 0
313 || x >= bv. workWidth())
316 DocIterator const & inlineCompletionPos = bv.inlineCompletionPos();
317 MathData const * inlineCompletionData = 0;
318 if (inlineCompletionPos.inMathed())
319 inlineCompletionData = &inlineCompletionPos.cell();
321 CoordCache::Insets & coords = pi.base.bv->coordCache().insets();
322 for (size_t i = 0, n = size(); i != n; ++i) {
323 MathAtom const & at = operator[](i);
324 coords.add(at.nucleus(), x, y);
325 at->drawSelection(pi, x, y);
327 x += coords.dim(at.nucleus()).wid;
329 // Is the inline completion here?
330 if (inlineCompletionData != this
331 || size_t(inlineCompletionPos.pos()) != i + 1)
333 docstring const & completion = bv.inlineCompletion();
334 if (completion.length() == 0)
336 FontInfo f = pi.base.font;
337 augmentFont(f, from_ascii("mathnormal"));
339 // draw the unique and the non-unique completion part
340 // Note: this is not time-critical as it is
341 // only done once per screen.
342 size_t uniqueTo = bv.inlineCompletionUniqueChars();
343 docstring s1 = completion.substr(0, uniqueTo);
344 docstring s2 = completion.substr(uniqueTo);
347 f.setColor(Color_inlinecompletion);
348 pi.pain.text(x, y, s1, f);
349 x += mathed_string_width(f, s1);
353 f.setColor(Color_nonunique_inlinecompletion);
354 pi.pain.text(x, y, s2, f);
355 x += mathed_string_width(f, s2);
361 void MathData::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
365 for (const_iterator it = begin(); it != end(); ++it) {
366 (*it)->metricsT(mi, d);
372 void MathData::drawT(TextPainter & pain, int x, int y) const
374 //lyxerr << "x: " << x << " y: " << y << ' ' << pain.workAreaHeight() << endl;
376 // FIXME: Abdel 16/10/2006
377 // This drawT() method is never used, this is dead code.
379 for (const_iterator it = begin(), et = end(); it != et; ++it) {
380 (*it)->drawT(pain, x, y);
381 //x += (*it)->width_;
387 void MathData::updateBuffer(ParIterator const & it, UpdateType utype)
390 for (size_t i = 0, n = size(); i != n; ++i) {
391 MathAtom & at = operator[](i);
392 at.nucleus()->updateBuffer(it, utype);
397 void MathData::updateMacros(Cursor * cur, MacroContext const & mc,
400 // If we are editing a macro, we cannot update it immediately,
401 // otherwise wrong undo steps will be recorded (bug 6208).
402 InsetMath const * inmath = cur ? cur->inset().asInsetMath() : 0;
403 MathMacro const * inmacro = inmath ? inmath->asMacro() : 0;
404 docstring const edited_name = inmacro ? inmacro->name() : docstring();
406 // go over the array and look for macros
407 for (size_t i = 0; i < size(); ++i) {
408 MathMacro * macroInset = operator[](i).nucleus()->asMacro();
409 if (!macroInset || macroInset->macroName().empty()
410 || macroInset->macroName()[0] == '^'
411 || macroInset->macroName()[0] == '_'
412 || (macroInset->name() == edited_name
413 && macroInset->displayMode() ==
414 MathMacro::DISPLAY_UNFOLDED))
418 macroInset->updateMacro(mc);
419 size_t macroNumArgs = 0;
420 size_t macroOptionals = 0;
421 MacroData const * macro = macroInset->macro();
423 macroNumArgs = macro->numargs();
424 macroOptionals = macro->optionals();
427 // store old and compute new display mode
428 MathMacro::DisplayMode newDisplayMode;
429 MathMacro::DisplayMode oldDisplayMode = macroInset->displayMode();
430 newDisplayMode = macroInset->computeDisplayMode();
432 // arity changed or other reason to detach?
433 if (oldDisplayMode == MathMacro::DISPLAY_NORMAL
434 && (macroInset->arity() != macroNumArgs
435 || macroInset->optionals() != macroOptionals
436 || newDisplayMode == MathMacro::DISPLAY_UNFOLDED))
437 detachMacroParameters(cur, i);
439 // the macro could have been copied while resizing this
440 macroInset = operator[](i).nucleus()->asMacro();
443 if (newDisplayMode != MathMacro::DISPLAY_UNFOLDED
444 && oldDisplayMode == MathMacro::DISPLAY_UNFOLDED) {
445 // put cursor in front of macro
447 int macroSlice = cur->find(macroInset);
448 if (macroSlice != -1)
449 cur->cutOff(macroSlice - 1);
453 // update the display mode
454 size_t appetite = macroInset->appetite();
455 macroInset->setDisplayMode(newDisplayMode);
458 if (newDisplayMode == MathMacro::DISPLAY_NORMAL
459 && (macroInset->arity() != macroNumArgs
460 || macroInset->optionals() != macroOptionals)) {
461 // is it a virgin macro which was never attached to parameters?
462 bool fromInitToNormalMode
463 = (oldDisplayMode == MathMacro::DISPLAY_INIT
464 || oldDisplayMode == MathMacro::DISPLAY_INTERACTIVE_INIT)
465 && newDisplayMode == MathMacro::DISPLAY_NORMAL;
467 // if the macro was entered interactively (i.e. not by paste or during
468 // loading), it should not be greedy, but the cursor should
469 // automatically jump into the macro when behind
470 bool interactive = (oldDisplayMode == MathMacro::DISPLAY_INTERACTIVE_INIT);
473 attachMacroParameters(cur, i, macroNumArgs, macroOptionals,
474 fromInitToNormalMode, interactive, appetite);
477 cur->updateInsets(&cur->bottom().inset());
480 // Give macro the chance to adapt to new situation.
481 // The macroInset could be invalid now because it was put into a script
482 // inset and therefore "deep" copied. So get it again from the MathData.
483 InsetMath * inset = operator[](i).nucleus();
484 if (inset->asScriptInset())
485 inset = inset->asScriptInset()->nuc()[0].nucleus();
486 LASSERT(inset->asMacro(), continue);
487 inset->asMacro()->updateRepresentation(cur, mc, utype);
492 void MathData::detachMacroParameters(DocIterator * cur, const size_type macroPos)
494 MathMacro * macroInset = operator[](macroPos).nucleus()->asMacro();
495 // We store this now, because the inset pointer will be invalidated in the scond loop below
496 size_t const optionals = macroInset->optionals();
498 // detach all arguments
499 vector<MathData> detachedArgs;
500 if (macroPos + 1 == size())
501 // strip arguments if we are at the MathData end
502 macroInset->detachArguments(detachedArgs, true);
504 macroInset->detachArguments(detachedArgs, false);
507 int curMacroSlice = -1;
509 curMacroSlice = cur->find(macroInset);
510 idx_type curMacroIdx = -1;
511 pos_type curMacroPos = -1;
512 vector<CursorSlice> argSlices;
513 if (curMacroSlice != -1) {
514 curMacroPos = (*cur)[curMacroSlice].pos();
515 curMacroIdx = (*cur)[curMacroSlice].idx();
516 cur->cutOff(curMacroSlice, argSlices);
520 // only [] after the last non-empty argument can be dropped later
521 size_t lastNonEmptyOptional = 0;
522 for (size_t l = 0; l < detachedArgs.size() && l < optionals; ++l) {
523 if (!detachedArgs[l].empty())
524 lastNonEmptyOptional = l;
527 // optional arguments to be put back?
528 pos_type p = macroPos + 1;
530 // WARNING: do not use macroInset below, the insert() call in the lopp will invalidate it!
531 for (; j < detachedArgs.size() && j < optionals; ++j) {
532 // another non-empty parameter follows?
533 bool canDropEmptyOptional = j >= lastNonEmptyOptional;
535 // then we can drop empty optional parameters
536 if (detachedArgs[j].empty() && canDropEmptyOptional) {
537 if (curMacroIdx == j)
538 (*cur)[curMacroSlice - 1].pos() = macroPos + 1;
542 // Otherwise we don't drop an empty optional, put it back normally
544 asArray(from_ascii("[]"), optarg);
545 MathData & arg = detachedArgs[j];
547 // look for "]", i.e. put a brace around?
548 InsetMathBrace * brace = 0;
549 for (size_t q = 0; q < arg.size(); ++q) {
550 if (arg[q]->getChar() == ']') {
552 brace = new InsetMathBrace(buffer_);
557 // put arg between []
559 brace->cell(0) = arg;
560 optarg.insert(1, MathAtom(brace));
562 optarg.insert(1, arg);
564 // insert it into the array
569 if (curMacroSlice == -1)
572 // cursor in optional argument of macro?
573 if (curMacroIdx == j) {
575 cur->append(0, curMacroPos);
576 (*cur)[curMacroSlice - 1].pos() = macroPos + 2;
578 (*cur)[curMacroSlice - 1].pos() = macroPos + 2 + curMacroPos;
579 cur->append(argSlices);
580 } else if ((*cur)[curMacroSlice - 1].pos() >= int(p))
581 // cursor right of macro
582 (*cur)[curMacroSlice - 1].pos() += optarg.size();
585 // put them back into the MathData
586 for (; j < detachedArgs.size(); ++j, ++p) {
587 MathData const & arg = detachedArgs[j];
589 && !arg[0]->asScriptInset()
590 && !(arg[0]->asMacro() && arg[0]->asMacro()->arity() > 0))
593 insert(p, MathAtom(new InsetMathBrace(arg)));
596 if (curMacroSlice == -1)
599 // cursor in j-th argument of macro?
600 if (curMacroIdx == j) {
601 if (operator[](p).nucleus()->asBraceInset()) {
602 (*cur)[curMacroSlice - 1].pos() = p;
603 cur->append(0, curMacroPos);
604 cur->append(argSlices);
606 (*cur)[curMacroSlice - 1].pos() = p; // + macroPos;
607 cur->append(argSlices);
609 } else if ((*cur)[curMacroSlice - 1].pos() >= int(p))
610 ++(*cur)[curMacroSlice - 1].pos();
614 cur->updateInsets(&cur->bottom().inset());
618 void MathData::attachMacroParameters(Cursor * cur,
619 const size_type macroPos, const size_type macroNumArgs,
620 const int macroOptionals, const bool fromInitToNormalMode,
621 const bool interactiveInit, const size_t appetite)
623 MathMacro * macroInset = operator[](macroPos).nucleus()->asMacro();
625 // start at atom behind the macro again, maybe with some new arguments
626 // from the detach phase above, to add them back into the macro inset
627 size_t p = macroPos + 1;
628 vector<MathData> detachedArgs;
629 MathAtom scriptToPutAround;
631 // find cursor slice again of this MathData
634 thisSlice = cur->find(*this);
637 thisPos = (*cur)[thisSlice].pos();
639 // find arguments behind the macro
640 if (!interactiveInit) {
641 collectOptionalParameters(cur, macroOptionals, detachedArgs, p,
642 scriptToPutAround, macroPos, thisPos, thisSlice);
644 collectParameters(cur, macroNumArgs, detachedArgs, p,
645 scriptToPutAround, macroPos, thisPos, thisSlice, appetite);
647 // attach arguments back to macro inset
648 macroInset->attachArguments(detachedArgs, macroNumArgs, macroOptionals);
650 // found tail script? E.g. \foo{a}b^x
651 if (scriptToPutAround.nucleus()) {
652 InsetMathScript * scriptInset =
653 scriptToPutAround.nucleus()->asScriptInset();
654 // In the math parser we remove empty braces in the base
655 // of a script inset, but we have to restore them here.
656 if (scriptInset->nuc().empty()) {
658 scriptInset->nuc().push_back(
659 MathAtom(new InsetMathBrace(ar)));
661 // put macro into a script inset
662 scriptInset->nuc()[0] = operator[](macroPos);
663 operator[](macroPos) = scriptToPutAround;
665 // go into the script inset nucleus
666 if (cur && thisPos == int(macroPos))
669 // get pointer to "deep" copied macro inset
670 scriptInset = operator[](macroPos).nucleus()->asScriptInset();
671 macroInset = scriptInset->nuc()[0].nucleus()->asMacro();
674 // remove them from the MathData
675 erase(macroPos + 1, p);
677 // cursor outside this MathData?
681 // fix cursor if right of p
682 if (thisPos >= int(p))
683 (*cur)[thisSlice].pos() -= p - (macroPos + 1);
685 // was the macro inset just inserted interactively and was now folded
686 // and the cursor is just behind?
687 if ((*cur)[thisSlice].pos() == int(macroPos + 1)
689 && fromInitToNormalMode
690 && macroInset->arity() > 0
691 && thisSlice + 1 == int(cur->depth())) {
692 // then enter it if the cursor was just behind
693 (*cur)[thisSlice].pos() = macroPos;
694 cur->push_back(CursorSlice(*macroInset));
695 macroInset->idxFirst(*cur);
700 void MathData::collectOptionalParameters(Cursor * cur,
701 const size_type numOptionalParams, vector<MathData> & params,
702 size_t & pos, MathAtom & scriptToPutAround,
703 const pos_type macroPos, const int thisPos, const int thisSlice)
705 Buffer * buf = cur ? cur->buffer() : 0;
706 // insert optional arguments?
707 while (params.size() < numOptionalParams
709 && !scriptToPutAround.nucleus()) {
710 // is a [] block following which could be an optional parameter?
711 if (operator[](pos)->getChar() != '[')
714 // found possible optional argument, look for "]"
715 size_t right = pos + 1;
716 for (; right < size(); ++right) {
717 MathAtom & cell = operator[](right);
719 if (cell->getChar() == ']')
723 // maybe "]" with a script around?
724 InsetMathScript * script = cell.nucleus()->asScriptInset();
727 if (script->nuc().size() != 1)
729 if (script->nuc()[0]->getChar() == ']') {
730 // script will be put around the macro later
731 scriptToPutAround = cell;
737 if (right >= size()) {
738 // no ] found, so it's not an optional argument
742 // add everything between [ and ] as optional argument
743 MathData optarg(buf, begin() + pos + 1, begin() + right);
747 if (optarg.size() == 1 && optarg[0]->asBraceInset()) {
749 params.push_back(optarg[0]->asBraceInset()->cell(0));
751 params.push_back(optarg);
753 // place cursor in optional argument of macro
755 && thisPos >= int(pos) && thisPos <= int(right)) {
756 int paramPos = max(0, thisPos - int(pos) - 1);
757 vector<CursorSlice> x;
758 cur->cutOff(thisSlice, x);
759 (*cur)[thisSlice].pos() = macroPos;
761 paramPos = x[0].pos();
764 cur->append(0, paramPos);
770 // fill up empty optional parameters
771 while (params.size() < numOptionalParams)
772 params.push_back(MathData());
776 void MathData::collectParameters(Cursor * cur,
777 const size_type numParams, vector<MathData> & params,
778 size_t & pos, MathAtom & scriptToPutAround,
779 const pos_type macroPos, const int thisPos, const int thisSlice,
780 const size_t appetite)
782 size_t startSize = params.size();
784 // insert normal arguments
785 while (params.size() < numParams
786 && params.size() - startSize < appetite
788 && !scriptToPutAround.nucleus()) {
789 MathAtom & cell = operator[](pos);
792 vector<CursorSlice> argSlices;
794 if (thisSlice != -1 && thisPos == int(pos))
795 cur->cutOff(thisSlice, argSlices);
797 // which kind of parameter is it? In {}? With index x^n?
798 InsetMathBrace const * brace = cell->asBraceInset();
800 // found brace, convert into argument
801 params.push_back(brace->cell(0));
803 // cursor inside of the brace or just in front of?
804 if (thisPos == int(pos) && !argSlices.empty()) {
805 argPos = argSlices[0].pos();
806 argSlices.erase(argSlices.begin());
808 } else if (cell->asScriptInset() && params.size() + 1 == numParams) {
809 // last inset with scripts without braces
810 // -> they belong to the macro, not the argument
811 InsetMathScript * script = cell.nucleus()->asScriptInset();
812 if (script->nuc().size() == 1 && script->nuc()[0]->asBraceInset())
813 // nucleus in brace? Unpack!
814 params.push_back(script->nuc()[0]->asBraceInset()->cell(0));
816 params.push_back(script->nuc());
818 // script will be put around below
819 scriptToPutAround = cell;
821 // this should only happen after loading, so make cursor handling simple
822 if (thisPos >= int(macroPos) && thisPos <= int(macroPos + numParams)) {
828 // the simplest case: plain inset
830 array.insert(0, cell);
831 params.push_back(array);
834 // put cursor in argument again
835 if (thisSlice != - 1 && thisPos == int(pos)) {
836 cur->append(params.size() - 1, argPos);
837 cur->append(argSlices);
838 (*cur)[thisSlice].pos() = macroPos;
846 int MathData::pos2x(BufferView const * bv, size_type pos) const
848 return pos2x(bv, pos, 0);
852 int MathData::pos2x(BufferView const * bv, size_type pos, int glue) const
855 size_type target = min(pos, size());
856 CoordCache::Insets const & coords = bv->coordCache().getInsets();
857 for (size_type i = 0; i < target; ++i) {
858 const_iterator it = begin() + i;
859 if ((*it)->getChar() == ' ')
861 //lyxerr << "char: " << (*it)->getChar()
862 // << "width: " << (*it)->width() << endl;
863 x += coords.dim((*it).nucleus()).wid;
869 MathData::size_type MathData::x2pos(BufferView const * bv, int targetx) const
871 return x2pos(bv, targetx, 0);
875 MathData::size_type MathData::x2pos(BufferView const * bv, int targetx, int glue) const
877 const_iterator it = begin();
880 CoordCache::Insets const & coords = bv->coordCache().getInsets();
881 // find first position after targetx
882 for (; currx < targetx && it != end(); ++it) {
884 if ((*it)->getChar() == ' ')
886 currx += coords.dim((*it).nucleus()).wid;
890 * If we are not at the beginning of the array, go to the left
891 * of the inset if one of the following two condition holds:
892 * - the current inset is editable (so that the cursor tip is
893 * deeper than us): in this case, we want all intermediate
894 * cursor slices to be before insets;
895 * - the mouse is closer to the left side of the inset than to
897 * See bug 1918 for details.
899 if (it != begin() && currx >= targetx
900 && ((*prev(it, 1))->asNestInset()
901 || abs(lastx - targetx) < abs(currx - targetx))) {
909 int MathData::dist(BufferView const & bv, int x, int y) const
911 return bv.coordCache().getArrays().squareDistance(this, x, y);
915 void MathData::setXY(BufferView & bv, int x, int y) const
917 //lyxerr << "setting position cache for MathData " << this << endl;
918 bv.coordCache().arrays().add(this, x, y);
922 Dimension const & MathData::dimension(BufferView const & bv) const
924 return bv.coordCache().getArrays().dim(this);
928 int MathData::xm(BufferView const & bv) const
930 Geometry const & g = bv.coordCache().getArrays().geometry(this);
932 return g.pos.x_ + g.dim.wid / 2;
936 int MathData::ym(BufferView const & bv) const
938 Geometry const & g = bv.coordCache().getArrays().geometry(this);
940 return g.pos.y_ + (g.dim.des - g.dim.asc) / 2;
944 int MathData::xo(BufferView const & bv) const
946 return bv.coordCache().getArrays().x(this);
950 int MathData::yo(BufferView const & bv) const
952 return bv.coordCache().getArrays().y(this);
956 ostream & operator<<(ostream & os, MathData const & ar)
958 odocstringstream oss;
959 NormalStream ns(oss);
961 return os << to_utf8(oss.str());
965 odocstream & operator<<(odocstream & os, MathData const & ar)