]> git.lyx.org Git - features.git/commitdiff
start fixing cursor size in math
authorAndré Pönitz <poenitz@gmx.net>
Mon, 10 Jan 2005 09:28:06 +0000 (09:28 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 10 Jan 2005 09:28:06 +0000 (09:28 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9460 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView_pimpl.C
src/cursor.C
src/cursor.h
src/frontends/ChangeLog
src/frontends/screen.C

index 95fdf3ee14cbba2aab06bc1d6a98fc6530ba25ef..9bf0dadfc6a1b19ca934b421a730e224da81d5d8 100644 (file)
@@ -56,6 +56,7 @@
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
 #include "frontends/FileDialog.h"
+#include "frontends/font_metrics.h"
 #include "frontends/LyXView.h"
 #include "frontends/LyXScreenFactory.h"
 #include "frontends/screen.h"
@@ -586,8 +587,9 @@ void BufferView::Pimpl::workAreaResize()
 bool BufferView::Pimpl::fitCursor()
 {
        if (bv_funcs::status(bv_, bv_->cursor()) == bv_funcs::CUR_INSIDE) {
-               int asc, des;
-               bv_->cursor().getDim(asc, des);
+               LyXFont const font = bv_->cursor().getFont();
+               int const asc = font_metrics::maxAscent(font);
+               int const des = font_metrics::maxDescent(font);
                Point p = bv_funcs::getPos(bv_->cursor());
                if (p.y_ - asc >= 0 && p.y_ + des < bv_->workHeight())
                        return false;
index 9b986ab506476195f1e1f7ac582e0c30c5fee0d1..276c4f2fc4d15f132f575cfb4b25481a8909cd62 100644 (file)
@@ -160,7 +160,6 @@ namespace {
                return false;
        }
 
-
 } // namespace anon
 
 
@@ -192,7 +191,8 @@ void LCursor::setCursor(DocIterator const & cur)
 
 void LCursor::dispatch(FuncRequest const & cmd0)
 {
-       lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: " << cmd0 << endl << *this << endl;
+       lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: "
+               << cmd0 << endl << *this << endl;
        if (empty())
                return;
 
@@ -200,7 +200,8 @@ void LCursor::dispatch(FuncRequest const & cmd0)
        LCursor safe = *this;
 
        for (; size(); pop()) {
-               lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: " << cmd0 << endl << *this << endl;
+               lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: "
+                       << cmd0 << endl << *this << endl;
                BOOST_ASSERT(pos() <= lastpos());
                BOOST_ASSERT(idx() <= lastidx());
                BOOST_ASSERT(pit() <= lastpit());
@@ -304,25 +305,6 @@ int LCursor::currentMode()
 }
 
 
-void LCursor::getDim(int & asc, int & des) const
-{
-       if (inMathed()) {
-               BOOST_ASSERT(inset().asMathInset());
-               //inset().asMathInset()->getCursorDim(asc, des);
-               asc = 10;
-               des = 2;
-       } else if (inTexted()) {
-               LyXFont const & realfont = text()->real_current_font;
-               asc = font_metrics::maxAscent(realfont);
-               des = font_metrics::maxDescent(realfont);
-       } else {
-               lyxerr << "should this happen?" << endl;
-               asc = 10;
-               des = 10;
-       }
-}
-
-
 void LCursor::getPos(int & x, int & y) const
 {
        Point p = bv_funcs::getPos(*this);
@@ -1132,3 +1114,24 @@ void LCursor::noUpdate()
 {
        disp_.update(false);
 }
+
+
+LyXFont LCursor::getFont() const
+{
+       // HACK. far from being perfect...
+       int s = 0;
+       // go up until first non-0 text is hit
+       // (innermost text is 0 in mathed)
+       for (s = size() - 1; s >= 0; --s)
+               if (operator[](s).text())
+                       break;
+       CursorSlice const & sl = operator[](s);
+       LyXText & text = *sl.text();
+       LyXFont font = text.getPar(sl.pit()).getFont(
+               bv().buffer()->params(),
+               sl.pos(),
+               outerFont(sl.pit(), text.paragraphs()));
+       for (; s < size(); ++s)
+               ;
+       return font;
+}
index 329e23a74b559edd3851d28ba78aefcc6ca99369..8deab33a050541b339807115d2e1853cb56d9d7c 100644 (file)
@@ -23,6 +23,7 @@ class BufferView;
 class FuncStatus;
 class FuncRequest;
 class Point;
+class LyXFont;
 
 // these should go
 class MathUnknownInset;
@@ -99,8 +100,6 @@ public:
        bool & macromode() { return macromode_; }
        /// returns x,y position
        void getPos(int & x, int & y) const;
-       /// returns cursor dimension
-       void getDim(int & asc, int & desc) const;
 
        //
        // common part
@@ -275,8 +274,9 @@ public:
        bool openable(MathAtom const &) const;
        ///
        Encoding const * getEncoding() const;
+       /// font at cursor position
+       LyXFont getFont() const;
 };
 
 
-
 #endif // LYXCURSOR_H
index 7ba705facd9d41f4e0850ca2ae35e2387a7516a5..9b44a18711d5ca2553855d376a1ca59ec98e6e29 100644 (file)
@@ -1,4 +1,8 @@
 
+2005-01-10  André Pönitz  <poenitz@gmx.net>
+
+       * screen.C (showCursor): use new function LCursor::getFont
+
 2004-12-06  Alfredo Braunstein  <abraunst@lyx.org>
 
        * screen.C (showCursor): draw half cursors
index 147d444d883e81c26d27e907ce67ceb50a00beea..2edabf1d02ebcc7a2f83512025b8b3212c168658 100644 (file)
@@ -174,13 +174,14 @@ void LyXScreen::showCursor(BufferView & bv)
        if (realfont.language() == latex_language)
                shape = BAR_SHAPE;
 
-       int ascent, descent;
-       bv.cursor().getDim(ascent, descent);
-       int h = ascent + descent;
+       LyXFont const font = bv.cursor().getFont();
+       int const asc = font_metrics::maxAscent(font);
+       int const des = font_metrics::maxDescent(font);
+       int h = asc + des;
        int x = 0;
        int y = 0;
        bv.cursor().getPos(x, y);
-       y -= ascent;
+       y -= asc;
        //lyxerr << "LyXScreen::showCursor x: " << x << " y: " << y << endl;
 
        // if it doesn't touch the screen, don't try to show it