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 "support/debug.h"
32 #include "support/docstream.h"
34 #include "frontends/FontMetrics.h"
35 #include "frontends/Painter.h"
37 #include "support/lassert.h"
38 #include <boost/next_prior.hpp>
47 MathData::MathData(Buffer * buf, const_iterator from, const_iterator to)
48 : base_type(from, to), buffer_(buf)
52 MathAtom & MathData::operator[](pos_type pos)
54 LASSERT(pos < size(), /**/);
55 return base_type::operator[](pos);
59 MathAtom const & MathData::operator[](pos_type pos) const
61 LASSERT(pos < size(), /**/);
62 return base_type::operator[](pos);
66 void MathData::insert(size_type pos, MathAtom const & t)
68 base_type::insert(begin() + pos, t);
72 void MathData::insert(size_type pos, MathData const & ar)
74 LASSERT(pos <= size(), /**/);
75 base_type::insert(begin() + pos, ar.begin(), ar.end());
79 void MathData::append(MathData const & ar)
85 void MathData::erase(size_type pos)
92 void MathData::erase(iterator pos1, iterator pos2)
94 base_type::erase(pos1, pos2);
98 void MathData::erase(iterator pos)
100 base_type::erase(pos);
104 void MathData::erase(size_type pos1, size_type pos2)
106 base_type::erase(begin() + pos1, begin() + pos2);
110 void MathData::dump2() const
114 for (const_iterator it = begin(); it != end(); ++it)
116 lyxerr << to_utf8(os.str());
120 void MathData::dump() const
124 for (const_iterator it = begin(); it != end(); ++it)
125 ns << '<' << *it << '>';
126 lyxerr << to_utf8(os.str());
130 void MathData::validate(LaTeXFeatures & features) const
132 for (const_iterator it = begin(); it != end(); ++it)
133 (*it)->validate(features);
137 bool MathData::match(MathData const & ar) const
139 return size() == ar.size() && matchpart(ar, 0);
143 bool MathData::matchpart(MathData const & ar, pos_type pos) const
145 if (size() < ar.size() + pos)
147 const_iterator it = begin() + pos;
148 for (const_iterator jt = ar.begin(); jt != ar.end(); ++jt, ++it)
149 if (asString(*it) != asString(*jt))
155 void MathData::replace(ReplaceData & rep)
157 for (size_type i = 0; i < size(); ++i) {
158 if (find1(rep.from, i)) {
160 lyxerr << "match found!" << endl;
161 erase(i, i + rep.from.size());
166 // FIXME: temporarily disabled
167 // for (const_iterator it = begin(); it != end(); ++it)
168 // it->nucleus()->replace(rep);
172 bool MathData::find1(MathData const & ar, size_type pos) const
174 lyxerr << "finding '" << ar << "' in '" << *this << "'" << endl;
175 for (size_type i = 0, n = ar.size(); i < n; ++i)
176 if (asString(operator[](pos + i)) != asString(ar[i]))
182 MathData::size_type MathData::find(MathData const & ar) const
184 for (int i = 0, last = size() - ar.size(); i < last; ++i)
191 MathData::size_type MathData::find_last(MathData const & ar) const
193 for (int i = size() - ar.size(); i >= 0; --i)
200 bool MathData::contains(MathData const & ar) const
202 if (find(ar) != size())
204 for (const_iterator it = begin(); it != end(); ++it)
205 if ((*it)->contains(ar))
211 void MathData::touch() const
218 bool isInside(DocIterator const & it, MathData const & ar,
219 pos_type p1, pos_type p2)
221 for (size_t i = 0; i != it.depth(); ++i) {
222 CursorSlice const & sl = it[i];
223 if (sl.inset().inMathed() && &sl.cell() == &ar)
224 return p1 <= sl.pos() && sl.pos() < p2;
233 void MathData::metrics(MetricsInfo & mi, Dimension & dim) const
235 frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
236 dim = fm.dimension('I');
237 int xascent = fm.dimension('x').ascent();
238 if (xascent >= dim.asc)
239 xascent = (2 * dim.asc) / 3;
241 mindes_ = (3 * xascent) / 4;
242 slevel_ = (4 * xascent) / 5;
243 sshift_ = xascent / 4;
247 // Cache the dimension.
248 mi.base.bv->coordCache().arrays().add(this, dim);
252 Cursor & cur = mi.base.bv->cursor();
253 const_cast<MathData*>(this)->updateMacros(&cur, mi.macrocontext, InternalUpdate);
255 DocIterator const & inlineCompletionPos = mi.base.bv->inlineCompletionPos();
256 MathData const * inlineCompletionData = 0;
257 if (inlineCompletionPos.inMathed())
258 inlineCompletionData = &inlineCompletionPos.cell();
263 CoordCacheBase<Inset> & coords = mi.base.bv->coordCache().insets();
264 for (pos_type i = 0, n = size(); i != n; ++i) {
265 MathAtom const & at = operator[](i);
267 coords.add(at.nucleus(), d);
270 kerning_ = at->kerning(mi.base.bv);
272 // HACK to draw completion suggestion inline
273 if (inlineCompletionData != this
274 || size_t(inlineCompletionPos.pos()) != i + 1)
277 docstring const & completion = mi.base.bv->inlineCompletion();
278 if (completion.length() == 0)
281 dim.wid += mathed_string_width(mi.base.font, completion);
283 // Cache the dimension.
284 mi.base.bv->coordCache().arrays().add(this, dim);
288 void MathData::draw(PainterInfo & pi, int x, int y) const
290 //lyxerr << "MathData::draw: x: " << x << " y: " << y << endl;
291 BufferView & bv = *pi.base.bv;
294 Dimension const & dim = bv.coordCache().getArrays().dim(this);
297 pi.pain.rectangle(x, y - dim.ascent(), dim.width(), dim.height(), Color_mathline);
301 // don't draw outside the workarea
302 if (y + dim.descent() <= 0
303 || y - dim.ascent() >= bv.workHeight()
304 || x + dim.width() <= 0
305 || x >= bv. workWidth())
308 DocIterator const & inlineCompletionPos = bv.inlineCompletionPos();
309 MathData const * inlineCompletionData = 0;
310 if (inlineCompletionPos.inMathed())
311 inlineCompletionData = &inlineCompletionPos.cell();
313 CoordCacheBase<Inset> & coords = pi.base.bv->coordCache().insets();
314 for (size_t i = 0, n = size(); i != n; ++i) {
315 MathAtom const & at = operator[](i);
316 coords.add(at.nucleus(), x, y);
317 at->drawSelection(pi, x, y);
319 x += coords.dim(at.nucleus()).wid;
321 // Is the inline completion here?
322 if (inlineCompletionData != this
323 || size_t(inlineCompletionPos.pos()) != i + 1)
325 docstring const & completion = bv.inlineCompletion();
326 if (completion.length() == 0)
328 FontInfo f = pi.base.font;
330 // draw the unique and the non-unique completion part
331 // Note: this is not time-critical as it is
332 // only done once per screen.
333 size_t uniqueTo = bv.inlineCompletionUniqueChars();
334 docstring s1 = completion.substr(0, uniqueTo);
335 docstring s2 = completion.substr(uniqueTo);
338 f.setColor(Color_inlinecompletion);
339 pi.pain.text(x, y, s1, f);
340 x += mathed_string_width(f, s1);
344 f.setColor(Color_nonunique_inlinecompletion);
345 pi.pain.text(x, y, s2, f);
346 x += mathed_string_width(f, s2);
352 void MathData::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
356 for (const_iterator it = begin(); it != end(); ++it) {
357 (*it)->metricsT(mi, d);
363 void MathData::drawT(TextPainter & pain, int x, int y) const
365 //lyxerr << "x: " << x << " y: " << y << ' ' << pain.workAreaHeight() << endl;
367 // FIXME: Abdel 16/10/2006
368 // This drawT() method is never used, this is dead code.
370 for (const_iterator it = begin(), et = end(); it != et; ++it) {
371 (*it)->drawT(pain, x, y);
372 //x += (*it)->width_;
378 void MathData::updateBuffer(ParIterator const & it, UpdateType utype)
381 for (size_t i = 0, n = size(); i != n; ++i) {
382 MathAtom & at = operator[](i);
383 at.nucleus()->updateBuffer(it, utype);
388 void MathData::updateMacros(Cursor * cur, MacroContext const & mc,
391 // If we are editing a macro, we cannot update it immediately,
392 // otherwise wrong undo steps will be recorded (bug 6208).
393 InsetMath const * inmath = cur ? cur->inset().asInsetMath() : 0;
394 MathMacro const * inmacro = inmath ? inmath->asMacro() : 0;
395 docstring const edited_name = inmacro ? inmacro->name() : docstring();
397 // go over the array and look for macros
398 for (size_t i = 0; i < size(); ++i) {
399 MathMacro * macroInset = operator[](i).nucleus()->asMacro();
400 if (!macroInset || macroInset->name_.empty()
401 || macroInset->name_[0] == '^'
402 || macroInset->name_[0] == '_'
403 || (macroInset->name() == edited_name
404 && macroInset->displayMode() ==
405 MathMacro::DISPLAY_UNFOLDED))
409 macroInset->updateMacro(mc);
410 size_t macroNumArgs = 0;
411 size_t macroOptionals = 0;
412 MacroData const * macro = macroInset->macro();
414 macroNumArgs = macro->numargs();
415 macroOptionals = macro->optionals();
418 // store old and compute new display mode
419 MathMacro::DisplayMode newDisplayMode;
420 MathMacro::DisplayMode oldDisplayMode = macroInset->displayMode();
421 newDisplayMode = macroInset->computeDisplayMode();
423 // arity changed or other reason to detach?
424 if (oldDisplayMode == MathMacro::DISPLAY_NORMAL
425 && (macroInset->arity() != macroNumArgs
426 || macroInset->optionals() != macroOptionals
427 || newDisplayMode == MathMacro::DISPLAY_UNFOLDED)) {
429 detachMacroParameters(cur, i);
430 // FIXME: proper anchor handling, this removes the selection
432 cur->clearSelection();
435 // the macro could have been copied while resizing this
436 macroInset = operator[](i).nucleus()->asMacro();
439 if (newDisplayMode != MathMacro::DISPLAY_UNFOLDED
440 && oldDisplayMode == MathMacro::DISPLAY_UNFOLDED) {
441 // put cursor in front of macro
443 int macroSlice = cur->find(macroInset);
444 if (macroSlice != -1)
445 cur->cutOff(macroSlice - 1);
449 // update the display mode
450 size_t appetite = macroInset->appetite();
451 macroInset->setDisplayMode(newDisplayMode);
454 if (newDisplayMode == MathMacro::DISPLAY_NORMAL
455 && (macroInset->arity() != macroNumArgs
456 || macroInset->optionals() != macroOptionals)) {
457 // is it a virgin macro which was never attached to parameters?
458 bool fromInitToNormalMode
459 = (oldDisplayMode == MathMacro::DISPLAY_INIT
460 || oldDisplayMode == MathMacro::DISPLAY_INTERACTIVE_INIT)
461 && newDisplayMode == MathMacro::DISPLAY_NORMAL;
463 // if the macro was entered interactively (i.e. not by paste or during
464 // loading), it should not be greedy, but the cursor should
465 // automatically jump into the macro when behind
466 bool interactive = (oldDisplayMode == MathMacro::DISPLAY_INTERACTIVE_INIT);
469 attachMacroParameters(cur, i, macroNumArgs, macroOptionals,
470 fromInitToNormalMode, interactive, appetite);
473 // FIXME: proper anchor handling, this removes the selection
474 cur->updateInsets(&cur->bottom().inset());
475 cur->clearSelection();
479 // Give macro the chance to adapt to new situation.
480 // The macroInset could be invalid now because it was put into a script
481 // inset and therefore "deep" copied. So get it again from the MathData.
482 InsetMath * inset = operator[](i).nucleus();
483 if (inset->asScriptInset())
484 inset = inset->asScriptInset()->nuc()[0].nucleus();
485 LASSERT(inset->asMacro(), /**/);
486 inset->asMacro()->updateRepresentation(cur, mc, utype);
491 void MathData::detachMacroParameters(DocIterator * cur, const size_type macroPos)
493 MathMacro * macroInset = operator[](macroPos).nucleus()->asMacro();
495 // detach all arguments
496 vector<MathData> detachedArgs;
497 if (macroPos + 1 == size())
498 // strip arguments if we are at the MathData end
499 macroInset->detachArguments(detachedArgs, true);
501 macroInset->detachArguments(detachedArgs, false);
504 int curMacroSlice = -1;
506 curMacroSlice = cur->find(macroInset);
507 idx_type curMacroIdx = -1;
508 pos_type curMacroPos = -1;
509 vector<CursorSlice> argSlices;
510 if (curMacroSlice != -1) {
511 curMacroPos = (*cur)[curMacroSlice].pos();
512 curMacroIdx = (*cur)[curMacroSlice].idx();
513 cur->cutOff(curMacroSlice, argSlices);
517 // only [] after the last non-empty argument can be dropped later
518 size_t lastNonEmptyOptional = 0;
519 for (size_t l = 0; l < detachedArgs.size() && l < macroInset->optionals(); ++l) {
520 if (!detachedArgs[l].empty())
521 lastNonEmptyOptional = l;
524 // optional arguments to be put back?
525 pos_type p = macroPos + 1;
527 for (; j < detachedArgs.size() && j < macroInset->optionals(); ++j) {
528 // another non-empty parameter follows?
529 bool canDropEmptyOptional = j >= lastNonEmptyOptional;
531 // then we can drop empty optional parameters
532 if (detachedArgs[j].empty() && canDropEmptyOptional) {
533 if (curMacroIdx == j)
534 (*cur)[curMacroSlice - 1].pos() = macroPos + 1;
538 // Otherwise we don't drop an empty optional, put it back normally
540 asArray(from_ascii("[]"), optarg);
541 MathData & arg = detachedArgs[j];
543 // look for "]", i.e. put a brace around?
544 InsetMathBrace * brace = 0;
545 for (size_t q = 0; q < arg.size(); ++q) {
546 if (arg[q]->getChar() == ']') {
548 brace = new InsetMathBrace(buffer_);
553 // put arg between []
555 brace->cell(0) = arg;
556 optarg.insert(1, MathAtom(brace));
558 optarg.insert(1, arg);
560 // insert it into the array
565 if (curMacroSlice == -1)
568 // cursor in optional argument of macro?
569 if (curMacroIdx == j) {
571 cur->append(0, curMacroPos);
572 (*cur)[curMacroSlice - 1].pos() = macroPos + 2;
574 (*cur)[curMacroSlice - 1].pos() = macroPos + 2 + curMacroPos;
575 cur->append(argSlices);
576 } else if ((*cur)[curMacroSlice - 1].pos() >= int(p))
577 // cursor right of macro
578 (*cur)[curMacroSlice - 1].pos() += optarg.size();
581 // put them back into the MathData
582 for (; j < detachedArgs.size(); ++j, ++p) {
583 MathData const & arg = detachedArgs[j];
585 && !arg[0]->asScriptInset()
586 && !(arg[0]->asMacro() && arg[0]->asMacro()->arity() > 0))
589 insert(p, MathAtom(new InsetMathBrace(arg)));
592 if (curMacroSlice == -1)
595 // cursor in j-th argument of macro?
596 if (curMacroIdx == j) {
597 if (operator[](p).nucleus()->asBraceInset()) {
598 (*cur)[curMacroSlice - 1].pos() = p;
599 cur->append(0, curMacroPos);
600 cur->append(argSlices);
602 (*cur)[curMacroSlice - 1].pos() = p; // + macroPos;
603 cur->append(argSlices);
605 } else if ((*cur)[curMacroSlice - 1].pos() >= int(p))
606 ++(*cur)[curMacroSlice - 1].pos();
610 cur->updateInsets(&cur->bottom().inset());
614 void MathData::attachMacroParameters(Cursor * cur,
615 const size_type macroPos, const size_type macroNumArgs,
616 const int macroOptionals, const bool fromInitToNormalMode,
617 const bool interactiveInit, const size_t appetite)
619 MathMacro * macroInset = operator[](macroPos).nucleus()->asMacro();
621 // start at atom behind the macro again, maybe with some new arguments
622 // from the detach phase above, to add them back into the macro inset
623 size_t p = macroPos + 1;
624 vector<MathData> detachedArgs;
625 MathAtom scriptToPutAround;
627 // find cursor slice again of this MathData
630 thisSlice = cur->find(*this);
633 thisPos = (*cur)[thisSlice].pos();
635 // find arguments behind the macro
636 if (!interactiveInit) {
637 collectOptionalParameters(cur, macroOptionals, detachedArgs, p,
638 scriptToPutAround, macroPos, thisPos, thisSlice);
640 collectParameters(cur, macroNumArgs, detachedArgs, p,
641 scriptToPutAround, macroPos, thisPos, thisSlice, appetite);
643 // attach arguments back to macro inset
644 macroInset->attachArguments(detachedArgs, macroNumArgs, macroOptionals);
646 // found tail script? E.g. \foo{a}b^x
647 if (scriptToPutAround.nucleus()) {
648 InsetMathScript * scriptInset =
649 scriptToPutAround.nucleus()->asScriptInset();
650 // In the math parser we remove empty braces in the base
651 // of a script inset, but we have to restore them here.
652 if (scriptInset->nuc().empty()) {
654 scriptInset->nuc().push_back(
655 MathAtom(new InsetMathBrace(ar)));
657 // put macro into a script inset
658 scriptInset->nuc()[0] = operator[](macroPos);
659 operator[](macroPos) = scriptToPutAround;
661 // go into the script inset nucleus
662 if (cur && thisPos == int(macroPos))
665 // get pointer to "deep" copied macro inset
666 scriptInset = operator[](macroPos).nucleus()->asScriptInset();
667 macroInset = scriptInset->nuc()[0].nucleus()->asMacro();
670 // remove them from the MathData
671 erase(begin() + macroPos + 1, begin() + p);
673 // cursor outside this MathData?
677 // fix cursor if right of p
678 if (thisPos >= int(p))
679 (*cur)[thisSlice].pos() -= p - (macroPos + 1);
681 // was the macro inset just inserted interactively and was now folded
682 // and the cursor is just behind?
683 if ((*cur)[thisSlice].pos() == int(macroPos + 1)
685 && fromInitToNormalMode
686 && macroInset->arity() > 0
687 && thisSlice + 1 == int(cur->depth())) {
688 // then enter it if the cursor was just behind
689 (*cur)[thisSlice].pos() = macroPos;
690 cur->push_back(CursorSlice(*macroInset));
691 macroInset->idxFirst(*cur);
696 void MathData::collectOptionalParameters(Cursor * cur,
697 const size_type numOptionalParams, vector<MathData> & params,
698 size_t & pos, MathAtom & scriptToPutAround,
699 const pos_type macroPos, const int thisPos, const int thisSlice)
701 Buffer * buf = cur ? cur->buffer() : 0;
702 // insert optional arguments?
703 while (params.size() < numOptionalParams
705 && !scriptToPutAround.nucleus()) {
706 // is a [] block following which could be an optional parameter?
707 if (operator[](pos)->getChar() != '[')
710 // found possible optional argument, look for "]"
711 size_t right = pos + 1;
712 for (; right < size(); ++right) {
713 MathAtom & cell = operator[](right);
715 if (cell->getChar() == ']')
719 // maybe "]" with a script around?
720 InsetMathScript * script = cell.nucleus()->asScriptInset();
723 if (script->nuc().size() != 1)
725 if (script->nuc()[0]->getChar() == ']') {
726 // script will be put around the macro later
727 scriptToPutAround = cell;
733 if (right >= size()) {
734 // no ] found, so it's not an optional argument
738 // add everything between [ and ] as optional argument
739 MathData optarg(buf, begin() + pos + 1, begin() + right);
743 if (optarg.size() == 1 && optarg[0]->asBraceInset()) {
745 params.push_back(optarg[0]->asBraceInset()->cell(0));
747 params.push_back(optarg);
749 // place cursor in optional argument of macro
751 && thisPos >= int(pos) && thisPos <= int(right)) {
752 int paramPos = max(0, thisPos - int(pos) - 1);
753 vector<CursorSlice> x;
754 cur->cutOff(thisSlice, x);
755 (*cur)[thisSlice].pos() = macroPos;
757 paramPos = x[0].pos();
760 cur->append(0, paramPos);
766 // fill up empty optional parameters
767 while (params.size() < numOptionalParams)
768 params.push_back(MathData());
772 void MathData::collectParameters(Cursor * cur,
773 const size_type numParams, vector<MathData> & params,
774 size_t & pos, MathAtom & scriptToPutAround,
775 const pos_type macroPos, const int thisPos, const int thisSlice,
776 const size_t appetite)
778 size_t startSize = params.size();
780 // insert normal arguments
781 while (params.size() < numParams
782 && params.size() - startSize < appetite
784 && !scriptToPutAround.nucleus()) {
785 MathAtom & cell = operator[](pos);
788 vector<CursorSlice> argSlices;
790 if (thisSlice != -1 && thisPos == int(pos))
791 cur->cutOff(thisSlice, argSlices);
793 // which kind of parameter is it? In {}? With index x^n?
794 InsetMathBrace const * brace = cell->asBraceInset();
796 // found brace, convert into argument
797 params.push_back(brace->cell(0));
799 // cursor inside of the brace or just in front of?
800 if (thisPos == int(pos) && !argSlices.empty()) {
801 argPos = argSlices[0].pos();
802 argSlices.erase(argSlices.begin());
804 } else if (cell->asScriptInset() && params.size() + 1 == numParams) {
805 // last inset with scripts without braces
806 // -> they belong to the macro, not the argument
807 InsetMathScript * script = cell.nucleus()->asScriptInset();
808 if (script->nuc().size() == 1 && script->nuc()[0]->asBraceInset())
809 // nucleus in brace? Unpack!
810 params.push_back(script->nuc()[0]->asBraceInset()->cell(0));
812 params.push_back(script->nuc());
814 // script will be put around below
815 scriptToPutAround = cell;
817 // this should only happen after loading, so make cursor handling simple
818 if (thisPos >= int(macroPos) && thisPos <= int(macroPos + numParams)) {
824 // the simplest case: plain inset
826 array.insert(0, cell);
827 params.push_back(array);
830 // put cursor in argument again
831 if (thisSlice != - 1 && thisPos == int(pos)) {
832 cur->append(params.size() - 1, argPos);
833 cur->append(argSlices);
834 (*cur)[thisSlice].pos() = macroPos;
842 int MathData::pos2x(BufferView const * bv, size_type pos) const
844 return pos2x(bv, pos, 0);
848 int MathData::pos2x(BufferView const * bv, size_type pos, int glue) const
851 size_type target = min(pos, size());
852 CoordCacheBase<Inset> const & coords = bv->coordCache().getInsets();
853 for (size_type i = 0; i < target; ++i) {
854 const_iterator it = begin() + i;
855 if ((*it)->getChar() == ' ')
857 //lyxerr << "char: " << (*it)->getChar()
858 // << "width: " << (*it)->width() << endl;
859 x += coords.dim((*it).nucleus()).wid;
865 MathData::size_type MathData::x2pos(BufferView const * bv, int targetx) const
867 return x2pos(bv, targetx, 0);
871 MathData::size_type MathData::x2pos(BufferView const * bv, int targetx, int glue) const
873 const_iterator it = begin();
876 CoordCacheBase<Inset> const & coords = bv->coordCache().getInsets();
877 // find first position after targetx
878 for (; currx < targetx && it < end(); ++it) {
880 if ((*it)->getChar() == ' ')
882 currx += coords.dim((*it).nucleus()).wid;
886 * If we are not at the beginning of the array, go to the left
887 * of the inset if one of the following two condition holds:
888 * - the current inset is editable (so that the cursor tip is
889 * deeper than us): in this case, we want all intermediate
890 * cursor slices to be before insets;
891 * - the mouse is closer to the left side of the inset than to
893 * See bug 1918 for details.
895 if (it != begin() && currx >= targetx
896 && ((*boost::prior(it))->asNestInset()
897 || abs(lastx - targetx) < abs(currx - targetx))) {
905 int MathData::dist(BufferView const & bv, int x, int y) const
907 return bv.coordCache().getArrays().squareDistance(this, x, y);
911 void MathData::setXY(BufferView & bv, int x, int y) const
913 //lyxerr << "setting position cache for MathData " << this << endl;
914 bv.coordCache().arrays().add(this, x, y);
918 Dimension const & MathData::dimension(BufferView const & bv) const
920 return bv.coordCache().getArrays().dim(this);
924 int MathData::xm(BufferView const & bv) const
926 Geometry const & g = bv.coordCache().getArrays().geometry(this);
928 return g.pos.x_ + g.dim.wid / 2;
932 int MathData::ym(BufferView const & bv) const
934 Geometry const & g = bv.coordCache().getArrays().geometry(this);
936 return g.pos.y_ + (g.dim.des - g.dim.asc) / 2;
940 int MathData::xo(BufferView const & bv) const
942 return bv.coordCache().getArrays().x(this);
946 int MathData::yo(BufferView const & bv) const
948 return bv.coordCache().getArrays().y(this);
952 ostream & operator<<(ostream & os, MathData const & ar)
954 odocstringstream oss;
955 NormalStream ns(oss);
957 return os << to_utf8(oss.str());
961 odocstream & operator<<(odocstream & os, MathData const & ar)