]> git.lyx.org Git - lyx.git/blob - src/mathed/MathData.cpp
correct case
[lyx.git] / src / mathed / MathData.cpp
1 /**
2  * \file MathData.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  * \author Stefan Schimanski
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "MathData.h"
15 #include "InsetMathBrace.h"
16 #include "InsetMathFont.h"
17 #include "InsetMathScript.h"
18 #include "MacroTable.h"
19 #include "MathMacro.h"
20 #include "MathStream.h"
21 #include "MathSupport.h"
22 #include "ReplaceData.h"
23
24 #include "Buffer.h"
25 #include "BufferView.h"
26 #include "CoordCache.h"
27 #include "Cursor.h"
28 #include "debug.h"
29
30 #include "frontends/FontMetrics.h"
31 #include "frontends/Painter.h"
32
33 #include <boost/assert.hpp>
34 #include <boost/next_prior.hpp>
35
36
37 namespace lyx {
38
39 using std::abs;
40 using std::endl;
41 using std::min;
42 using std::ostringstream;
43 using std::string;
44 using std::vector;
45
46
47 MathData::MathData(const_iterator from, const_iterator to)
48         : base_type(from, to)
49 {}
50
51
52 MathAtom & MathData::operator[](pos_type pos)
53 {
54         BOOST_ASSERT(pos < size());
55         return base_type::operator[](pos);
56 }
57
58
59 MathAtom const & MathData::operator[](pos_type pos) const
60 {
61         BOOST_ASSERT(pos < size());
62         return base_type::operator[](pos);
63 }
64
65
66 void MathData::insert(size_type pos, MathAtom const & t)
67 {
68         base_type::insert(begin() + pos, t);
69 }
70
71
72 void MathData::insert(size_type pos, MathData const & ar)
73 {
74         BOOST_ASSERT(pos <= size());
75         base_type::insert(begin() + pos, ar.begin(), ar.end());
76 }
77
78
79 void MathData::append(MathData const & ar)
80 {
81         insert(size(), ar);
82 }
83
84
85 void MathData::erase(size_type pos)
86 {
87         if (pos < size())
88                 erase(pos, pos + 1);
89 }
90
91
92 void MathData::erase(iterator pos1, iterator pos2)
93 {
94         base_type::erase(pos1, pos2);
95 }
96
97
98 void MathData::erase(iterator pos)
99 {
100         base_type::erase(pos);
101 }
102
103
104 void MathData::erase(size_type pos1, size_type pos2)
105 {
106         base_type::erase(begin() + pos1, begin() + pos2);
107 }
108
109
110 void MathData::dump2() const
111 {
112         odocstringstream os;
113         NormalStream ns(os);
114         for (const_iterator it = begin(); it != end(); ++it)
115                 ns << *it << ' ';
116         lyxerr << to_utf8(os.str());
117 }
118
119
120 void MathData::dump() const
121 {
122         odocstringstream os;
123         NormalStream ns(os);
124         for (const_iterator it = begin(); it != end(); ++it)
125                 ns << '<' << *it << '>';
126         lyxerr << to_utf8(os.str());
127 }
128
129
130 void MathData::validate(LaTeXFeatures & features) const
131 {
132         for (const_iterator it = begin(); it != end(); ++it)
133                 (*it)->validate(features);
134 }
135
136
137 bool MathData::match(MathData const & ar) const
138 {
139         return size() == ar.size() && matchpart(ar, 0);
140 }
141
142
143 bool MathData::matchpart(MathData const & ar, pos_type pos) const
144 {
145         if (size() < ar.size() + pos)
146                 return false;
147         const_iterator it = begin() + pos;
148         for (const_iterator jt = ar.begin(); jt != ar.end(); ++jt, ++it)
149                 if (asString(*it) != asString(*jt))
150                         return false;
151         return true;
152 }
153
154
155 void MathData::replace(ReplaceData & rep)
156 {
157         for (size_type i = 0; i < size(); ++i) {
158                 if (find1(rep.from, i)) {
159                         // match found
160                         lyxerr << "match found!" << endl;
161                         erase(i, i + rep.from.size());
162                         insert(i, rep.to);
163                 }
164         }
165
166         // FIXME: temporarily disabled
167         // for (const_iterator it = begin(); it != end(); ++it)
168         //      it->nucleus()->replace(rep);
169 }
170
171
172 bool MathData::find1(MathData const & ar, size_type pos) const
173 {
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]))
177                         return false;
178         return true;
179 }
180
181
182 MathData::size_type MathData::find(MathData const & ar) const
183 {
184         for (int i = 0, last = size() - ar.size(); i < last; ++i)
185                 if (find1(ar, i))
186                         return i;
187         return size();
188 }
189
190
191 MathData::size_type MathData::find_last(MathData const & ar) const
192 {
193         for (int i = size() - ar.size(); i >= 0; --i)
194                 if (find1(ar, i))
195                         return i;
196         return size();
197 }
198
199
200 bool MathData::contains(MathData const & ar) const
201 {
202         if (find(ar) != size())
203                 return true;
204         for (const_iterator it = begin(); it != end(); ++it)
205                 if ((*it)->contains(ar))
206                         return true;
207         return false;
208 }
209
210
211 void MathData::touch() const
212 {
213 }
214
215
216 namespace {
217
218 bool isInside(DocIterator const & it, MathData const & ar,
219         pos_type p1, pos_type p2)
220 {
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;
225         }
226         return false;
227 }
228
229 }
230
231
232
233 void MathData::metrics(MetricsInfo & mi, Dimension & dim) const
234 {
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;
240         minasc_ = xascent;
241         mindes_ = (3 * xascent) / 4;
242         slevel_ = (4 * xascent) / 5;
243         sshift_ = xascent / 4;
244         kerning_ = 0;
245
246         if (empty()) {
247                 // Cache the dimension.
248                 mi.base.bv->coordCache().arrays().add(this, dim);
249                 return;
250         }
251
252         const_cast<MathData*>(this)->updateMacros(mi);
253
254         dim.asc = 0;
255         dim.wid = 0;
256         Dimension d;
257         atom_dims_.clear();
258         for (size_t i = 0, n = size(); i != n; ++i) {
259                 MathAtom const & at = operator[](i);
260                 at->metrics(mi, d);
261                 atom_dims_.push_back(d);
262                 dim += d;
263                 if (i == n - 1)
264                         kerning_ = at->kerning();
265         }
266         // Cache the dimension.
267         mi.base.bv->coordCache().arrays().add(this, dim);
268 }
269
270
271 void MathData::draw(PainterInfo & pi, int x, int y) const
272 {
273         //lyxerr << "MathData::draw: x: " << x << " y: " << y << endl;
274         BufferView & bv  = *pi.base.bv;
275         setXY(bv, x, y);
276
277         Dimension const & dim = bv.coordCache().getArrays().dim(this);
278
279         if (empty()) {
280                 pi.pain.rectangle(x, y - dim.ascent(), dim.width(), dim.height(), Color_mathline);
281                 return;
282         }
283
284         // don't draw outside the workarea
285         if (y + dim.descent() <= 0
286                 || y - dim.ascent() >= bv.workHeight()
287                 || x + dim.width() <= 0
288                 || x >= bv. workWidth())
289                 return;
290
291         for (size_t i = 0, n = size(); i != n; ++i) {
292                 MathAtom const & at = operator[](i);
293                 bv.coordCache().insets().add(at.nucleus(), x, y);
294                 at->drawSelection(pi, x, y);
295                 at->draw(pi, x, y);
296                 x += atom_dims_[i].wid;
297         }
298 }
299
300
301 void MathData::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
302 {
303         dim.clear();
304         Dimension d;
305         for (const_iterator it = begin(); it != end(); ++it) {
306                 (*it)->metricsT(mi, d);
307                 dim += d;
308         }
309 }
310
311
312 void MathData::drawT(TextPainter & pain, int x, int y) const
313 {
314         //lyxerr << "x: " << x << " y: " << y << ' ' << pain.workAreaHeight() << endl;
315
316         // FIXME: Abdel 16/10/2006
317         // This drawT() method is never used, this is dead code.
318
319         for (const_iterator it = begin(), et = end(); it != et; ++it) {
320                 (*it)->drawT(pain, x, y);
321                 //x += (*it)->width_;
322                 x += 2;
323         }
324 }
325
326
327 void MathData::updateMacros(MetricsInfo & mi) 
328 {
329         Cursor & cur = mi.base.bv->cursor();
330
331         // go over the array and look for macros
332         for (size_t i = 0; i < size(); ++i) {
333                 MathMacro * macroInset = operator[](i).nucleus()->asMacro();
334                 if (!macroInset)
335                         continue;
336                 
337                 // get macro
338                 macroInset->updateMacro(mi);
339                 size_t macroNumArgs = 0;
340                 int macroOptionals = 0;
341                 MacroData const * macro = macroInset->macro();
342                 if (macro) {
343                         macroNumArgs = macro->numargs();
344                         macroOptionals = macro->optionals();
345                 }
346
347                 // store old and compute new display mode
348                 MathMacro::DisplayMode newDisplayMode;
349                 MathMacro::DisplayMode oldDisplayMode = macroInset->displayMode();
350                 newDisplayMode = macroInset->computeDisplayMode(mi);
351
352                 // arity changed or other reason to detach?
353                 if (oldDisplayMode == MathMacro::DISPLAY_NORMAL
354                                 && (macroInset->arity() != macroNumArgs
355                                                 || macroInset->optionals() != macroOptionals
356                                                 || newDisplayMode == MathMacro::DISPLAY_UNFOLDED)) {
357                         detachMacroParameters(cur, i);
358                 }
359
360                 // the macro could have been copied while resizing this
361                 macroInset = operator[](i).nucleus()->asMacro();
362
363                 // Cursor in \label?
364                 if (newDisplayMode != MathMacro::DISPLAY_UNFOLDED 
365                                 && oldDisplayMode == MathMacro::DISPLAY_UNFOLDED) {
366                         // put cursor in front of macro
367                         int macroSlice = cur.find(macroInset);
368                         if (macroSlice != -1)
369                                 cur.cutOff(macroSlice - 1);
370                 }
371
372                 // update the display mode
373                 macroInset->setDisplayMode(newDisplayMode);
374
375                 // arity changed?
376                 if (newDisplayMode == MathMacro::DISPLAY_NORMAL 
377                                 && (macroInset->arity() != macroNumArgs
378                                                 || macroInset->optionals() != macroOptionals)) {
379                         // is it a virgin macro which was never attached to parameters?
380                         bool fromInitToNormalMode
381                         = oldDisplayMode == MathMacro::DISPLAY_INIT
382                                 && newDisplayMode == MathMacro::DISPLAY_NORMAL;
383                         
384                         // attach parameters
385                         attachMacroParameters(cur, i, macroNumArgs, macroOptionals,
386                                 fromInitToNormalMode);
387                 }
388
389                 // give macro the chance to adapt to new situation
390                 InsetMath * inset = operator[](i).nucleus();
391                 if (inset->asScriptInset())
392                         inset = inset->asScriptInset()->nuc()[0].nucleus();
393                 BOOST_ASSERT(inset->asMacro());
394                 inset->asMacro()->updateRepresentation(mi);
395         }
396 }
397
398
399 void MathData::detachMacroParameters(Cursor & cur, const size_type macroPos)
400 {
401         MathMacro * macroInset = operator[](macroPos).nucleus()->asMacro();
402         
403         // detach all arguments
404         std::vector<MathData> detachedArgs;
405         if (macroPos + 1 == size())
406                                 // strip arguments if we are at the MathData end
407                                 macroInset->detachArguments(detachedArgs, true);
408         else
409                                 macroInset->detachArguments(detachedArgs, false);
410         
411         // find cursor slice
412         int curMacroSlice = cur.find(macroInset);
413         int curMacroIdx = -1;
414         int curMacroPos = -1;
415         std::vector<CursorSlice> argSlices;
416         if (curMacroSlice != -1) {
417                                 curMacroPos = cur[curMacroSlice].pos();
418                                 curMacroIdx = cur[curMacroSlice].idx();
419                                 cur.cutOff(curMacroSlice, argSlices);
420                                 cur.pop_back();
421         }
422         
423         // only [] after the last non-empty argument can be dropped later 
424         size_t lastNonEmptyOptional = 0;
425         for (size_t l = 0; l < detachedArgs.size() && l < macroInset->optionals(); ++l) {
426                                 if (!detachedArgs[l].empty())
427                                         lastNonEmptyOptional = l;
428         }
429         
430         // optional arguments to be put back?
431         size_t p = macroPos + 1;
432         size_t j = 0;
433         for (; j < detachedArgs.size() && j < macroInset->optionals(); ++j) {
434                 // another non-empty parameter follows?
435                 bool canDropEmptyOptional = j >= lastNonEmptyOptional;
436                 
437                 // then we can drop empty optional parameters
438                 if (detachedArgs[j].empty() && canDropEmptyOptional) {
439                         if (curMacroIdx == j)
440                                 cur[curMacroSlice - 1].pos() = macroPos + 1;
441                         continue;
442                 }
443                 
444                 // Otherwise we don't drop an empty optional, put it back normally
445                 MathData optarg;
446                 asArray(from_ascii("[]"), optarg);
447                 MathData & arg = detachedArgs[j];
448                 
449                 // look for "]", i.e. put a brace around?
450                 InsetMathBrace * brace = 0;
451                 for (size_t q = 0; q < arg.size(); ++q) {
452                         if (arg[q]->getChar() == ']') {
453                                 // put brace
454                                 brace = new InsetMathBrace();
455                                 break;
456                         }
457                 }
458                 
459                 // put arg between []
460                 if (brace) {
461                         brace->cell(0) = arg;
462                         optarg.insert(1, MathAtom(brace));
463                 } else
464                         optarg.insert(1, arg);
465                 
466                 // insert it into the array
467                 insert(p, optarg);
468                 p += optarg.size();
469                 
470                 // cursor in optional argument of macro?
471                 if (curMacroIdx == j) {
472                         if (brace) {
473                                 cur.append(0, curMacroPos);
474                                 cur[curMacroSlice - 1].pos() = macroPos + 2;
475                         } else
476                                 cur[curMacroSlice - 1].pos() = macroPos + 2 + curMacroPos;
477                         cur.append(argSlices);
478                 } else if (cur[curMacroSlice - 1].pos() >= int(p))
479                         // cursor right of macro
480                         cur[curMacroSlice - 1].pos() += optarg.size();
481         }
482         
483         // put them back into the MathData
484         for (; j < detachedArgs.size(); ++j) {                          
485                 MathData const & arg = detachedArgs[j];
486                 if (arg.size() == 1 && !arg[0]->asScriptInset()) // && arg[0]->asCharInset())
487                         insert(p, arg[0]);
488                 else
489                         insert(p, MathAtom(new InsetMathBrace(arg)));
490                 
491                 // cursor in j-th argument of macro?
492                 if (curMacroIdx == int(j)) {
493                         if (operator[](p).nucleus()->asBraceInset()) {
494                                 cur[curMacroSlice - 1].pos() = p;
495                                 cur.append(0, curMacroPos);
496                                 cur.append(argSlices);
497                         } else {
498                                 cur[curMacroSlice - 1].pos() = p; // + macroPos;
499                                 cur.append(argSlices);
500                         }
501                 } else if (cur[curMacroSlice - 1].pos() >= int(p))
502                         ++cur[curMacroSlice - 1].pos();
503                 
504                 ++p;
505         }
506         
507         // FIXME: proper anchor handling, this removes the selection
508         cur.clearSelection();
509         cur.updateInsets(&cur.bottom().inset());
510 }
511
512
513 void MathData::attachMacroParameters(Cursor & cur, 
514         const size_type macroPos, const size_type macroNumArgs,
515         const int macroOptionals, const bool fromInitToNormalMode)
516 {
517         MathMacro * macroInset = operator[](macroPos).nucleus()->asMacro();
518
519         // start at atom behind the macro again, maybe with some new arguments from above
520         // to add them back into the macro inset
521         size_t p = macroPos + 1;
522         size_t j = 0;
523         std::vector<MathData>detachedArgs;
524         MathAtom scriptToPutAround;
525         
526         // find cursor slice again
527         int thisSlice = cur.find(*this);
528         int thisPos = -1;
529         if (thisSlice != -1)
530                 thisPos = cur[thisSlice].pos();
531         
532         // insert optional arguments?
533         for (; j < macroOptionals && p < size(); ++j) {
534                 // is a [] block following which could be an optional parameter?
535                 if (operator[](p)->getChar() != '[') {
536                         detachedArgs.push_back(MathData());
537                         continue;
538                 }
539                                 
540                 // found optional argument, look for "]"
541                 size_t right = p + 1;
542                 for (; right < size(); ++right) {
543                         if (operator[](right)->getChar() == ']')
544                                 // found right end
545                                 break;
546                 }
547                 
548                 // found?
549                 if (right < size()) {
550                         // add everything between [ and ] as optional argument
551                         MathData optarg(begin() + p + 1, begin() + right);
552                         // a brace?
553                         bool brace = false;
554                         if (optarg.size() == 1 && optarg[0]->asBraceInset()) {
555                                 brace = true;
556                                 detachedArgs.push_back(optarg[0]->asBraceInset()->cell(0));
557                         } else
558                                 detachedArgs.push_back(optarg);
559                         // place cursor in optional argument of macro
560                         if (thisPos >= int(p) && thisPos <= int(right)) {
561                                 int pos = std::max(0, thisPos - int(p) - 1);
562                                 std::vector<CursorSlice> x;
563                                 cur.cutOff(thisSlice, x);
564                                 cur[thisSlice].pos() = macroPos;
565                                 if (brace) {
566                                         pos = x[0].pos();
567                                         x.erase(x.begin());
568                                 }
569                                 cur.append(0, pos);
570                                 cur.append(x);
571                         }
572                         p = right + 1;
573                 } else {
574                         // no ] found, so it's not an optional argument
575                         // Note: This was "macroPos = p" before, which probably
576                         //       does not make sense. We want to stop with optional
577                         //       argument handling instead, so go back to the beginning.
578                         j = 0; 
579                         break;
580                 }
581         }
582         
583         // insert normal arguments
584         for (; j < macroNumArgs && p < size(); ++j) {
585                 MathAtom & cell = operator[](p);
586
587                 // fix cursor
588                 std::vector<CursorSlice> argSlices;
589                 int argPos = 0;
590                 if (thisPos == int(p)) {
591                         cur.cutOff(thisSlice, argSlices);
592                 }
593                 
594                 InsetMathBrace const * brace = cell->asBraceInset();
595                 if (brace) {
596                         // found brace, convert into argument
597                         detachedArgs.push_back(brace->cell(0));
598                         
599                         // cursor inside of the brace or just in front of?
600                         if (thisPos == int(p) && !argSlices.empty()) {
601                                 argPos = argSlices[0].pos();
602                                 argSlices.erase(argSlices.begin());
603                         }
604                 } else if (cell->asScriptInset() && j + 1 == macroNumArgs) {
605                         // last inset with scripts without braces
606                         // -> they belong to the macro, not the argument
607                         InsetMathScript * script = cell.nucleus()->asScriptInset();
608                         if (script->nuc().size() == 1 && script->nuc()[0]->asBraceInset())
609                                 // nucleus in brace? Unpack!
610                                 detachedArgs.push_back(script->nuc()[0]->asBraceInset()->cell(0));
611                         else
612                                 detachedArgs.push_back(script->nuc());
613                         
614                         // script will be put around below
615                         scriptToPutAround = cell;
616                         
617                         // this should only happen after loading, so make cursor handling simple
618                         if (thisPos >= int(macroPos) && thisPos <= int(macroPos + macroNumArgs)) {
619                                 argSlices.clear();
620                                 cur.append(0, 0);
621                         }
622                 } else {
623                         MathData array;
624                         array.insert(0, cell);
625                         detachedArgs.push_back(array);
626                 }
627                 
628                 // put cursor in argument again
629                 if (thisPos == int(p)) {
630                         cur.append(j, argPos);
631                         cur.append(argSlices);
632                         cur[thisSlice].pos() = macroPos;
633                 }
634                 
635                 ++p;
636         }
637         
638         // attach arguments back to macro inset
639         macroInset->attachArguments(detachedArgs, macroNumArgs, macroOptionals);
640         
641         // found tail script? E.g. \foo{a}b^x
642         if (scriptToPutAround.nucleus()) {
643                 // put macro into a script inset
644                 scriptToPutAround.nucleus()->asScriptInset()->nuc()[0] 
645                 = operator[](macroPos);
646                 operator[](macroPos) = scriptToPutAround;
647                 
648                 if (thisPos == int(macroPos))
649                         cur.append(0, 0);
650         }
651         
652         // remove them from the MathData
653         erase(begin() + macroPos + 1, begin() + p);
654         
655         // fix cursor if right of p
656         if (thisPos >= int(p))
657                 cur[thisSlice].pos() -= p - (macroPos + 1);
658         
659         // was the macro inset just inserted and was now folded?
660         if (cur[thisSlice].pos() == int(macroPos + 1)
661                         && fromInitToNormalMode
662                         && macroInset->arity() > 0
663                         && thisSlice + 1 == int(cur.depth())) {
664                 // then enter it if the cursor was just behind
665                 cur[thisSlice].pos() = macroPos;
666                 cur.push_back(CursorSlice(*macroInset));
667                 macroInset->idxFirst(cur);
668         }
669         
670         // FIXME: proper anchor handling, this removes the selection
671         cur.updateInsets(&cur.bottom().inset());
672         cur.clearSelection();   
673 }
674
675
676 int MathData::pos2x(size_type pos) const
677 {
678         return pos2x(pos, 0);
679 }
680
681
682 int MathData::pos2x(size_type pos, int glue) const
683 {
684         int x = 0;
685         size_type target = min(pos, size());
686         for (size_type i = 0; i < target; ++i) {
687                 const_iterator it = begin() + i;
688                 if ((*it)->getChar() == ' ')
689                         x += glue;
690                 //lyxerr << "char: " << (*it)->getChar()
691                 //      << "width: " << (*it)->width() << std::endl;
692                 x += atom_dims_[i].wid;
693         }
694         return x;
695 }
696
697
698 MathData::size_type MathData::x2pos(int targetx) const
699 {
700         return x2pos(targetx, 0);
701 }
702
703
704 MathData::size_type MathData::x2pos(int targetx, int glue) const
705 {
706         const_iterator it = begin();
707         int lastx = 0;
708         int currx = 0;
709         // find first position after targetx
710         for (; currx < targetx && it < end(); ++it) {
711                 lastx = currx;
712                 if ((*it)->getChar() == ' ')
713                         currx += glue;
714                 currx += atom_dims_[it - begin()].wid;
715         }
716
717         /**
718          * If we are not at the beginning of the array, go to the left
719          * of the inset if one of the following two condition holds:
720          * - the current inset is editable (so that the cursor tip is
721          *   deeper than us): in this case, we want all intermediate
722          *   cursor slices to be before insets;
723          * - the mouse is closer to the left side of the inset than to
724          *   the right one.
725          * See bug 1918 for details.
726          **/
727         if (it != begin() && currx >= targetx
728             && ((*boost::prior(it))->asNestInset()
729                 || abs(lastx - targetx) < abs(currx - targetx))) {
730                 --it;
731         }
732
733         return it - begin();
734 }
735
736
737 int MathData::dist(BufferView const & bv, int x, int y) const
738 {
739         return bv.coordCache().getArrays().squareDistance(this, x, y);
740 }
741
742
743 void MathData::setXY(BufferView & bv, int x, int y) const
744 {
745         //lyxerr << "setting position cache for MathData " << this << std::endl;
746         bv.coordCache().arrays().add(this, x, y);
747 }
748
749
750 Dimension const & MathData::dimension(BufferView const & bv) const
751 {
752         return bv.coordCache().getArrays().dim(this);
753 }
754
755
756 int MathData::xm(BufferView const & bv) const
757 {
758         Geometry const & g = bv.coordCache().getArrays().geometry(this);
759
760         return g.pos.x_ + g.dim.wid / 2;
761 }
762
763
764 int MathData::ym(BufferView const & bv) const
765 {
766         Geometry const & g = bv.coordCache().getArrays().geometry(this);
767
768         return g.pos.y_ + (g.dim.des - g.dim.asc) / 2;
769 }
770
771
772 int MathData::xo(BufferView const & bv) const
773 {
774         return bv.coordCache().getArrays().x(this);
775 }
776
777
778 int MathData::yo(BufferView const & bv) const
779 {
780         return bv.coordCache().getArrays().y(this);
781 }
782
783
784 std::ostream & operator<<(std::ostream & os, MathData const & ar)
785 {
786         odocstringstream oss;
787         NormalStream ns(oss);
788         ns << ar;
789         return os << to_utf8(oss.str());
790 }
791
792
793 odocstream & operator<<(odocstream & os, MathData const & ar)
794 {
795         NormalStream ns(os);
796         ns << ar;
797         return os;
798 }
799
800
801 } // namespace lyx