]> git.lyx.org Git - features.git/commitdiff
* cursor_get_font.patch: the Cursor::getFont is responsible for the
authorStefan Schimanski <sts@lyx.org>
Thu, 7 Jun 2007 20:40:01 +0000 (20:40 +0000)
committerStefan Schimanski <sts@lyx.org>
Thu, 7 Jun 2007 20:40:01 +0000 (20:40 +0000)
cursor size. It should fit to the setCurrentFont function because the
cursor tells the user which font will be used when typing characters.
Especially on RTL/LTR boundaries it should fit because it is
essential for the user to see which writing direction is active. This
patch implements a simplified version of setCurrentFont's logic to
archive this.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18707 a592a061-630c-0410-9148-cb99ea01b6c8

src/Cursor.cpp

index d34f348d7307de57cb7324e85ef93025fc201109..bfb2338b0b71cfda5876714d3b18212f125f16bb 100644 (file)
@@ -1438,18 +1438,36 @@ void Cursor::noUpdate()
 
 Font Cursor::getFont() const
 {
+       // The logic here should more or less match to the Text::setCurrentFont
+       // logic, i.e. the cursor height should give a hint what will happen
+       // if a character is entered.
+       
        // HACK. far from being perfect...
-       int s = 0;
        // go up until first non-0 text is hit
        // (innermost text is 0 in mathed)
+       int s = 0;
        for (s = depth() - 1; s >= 0; --s)
                if (operator[](s).text())
                        break;
        CursorSlice const & sl = operator[](s);
        Text const & text = *sl.text();
-       Font font = text.getPar(sl.pit()).getFont(
-               bv().buffer()->params(),
-               sl.pos(),
+       Paragraph const & par = text.getPar(sl.pit());
+       
+       // on boundary, so we are really at the character before
+       pos_type pos = sl.pos();
+       if (pos > 0 && boundary())
+               --pos;
+       
+       // on space? Take the font before (only for RTL boundary stay)
+       if (pos > 0) {
+               if (pos == sl.lastpos()
+                               || (par.isSeparator(pos) && 
+                                               !text.isRTLBoundary(buffer(), par, pos)))
+                       --pos;
+       }
+       
+       // get font at the position
+       Font font = par.getFont(bv().buffer()->params(), pos,
                outerFont(sl.pit(), text.paragraphs()));
 
        return font;