]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
* doxy
[lyx.git] / src / TextMetrics.cpp
index 2c74a8c8b6a3a991adb6362d0eeacb38f71a7018..19a71ffbb99154ad41ed597c0ab4431929aaf0b5 100644 (file)
@@ -135,7 +135,7 @@ TextMetrics::TextMetrics(BufferView * bv, Text * text)
        dim_.asc = 10;
        dim_.des = 10;
 
-       //text_->updateLabels(bv->buffer());
+       //text_->updateBuffer(bv->buffer());
 }
 
 
@@ -179,17 +179,6 @@ ParagraphMetrics & TextMetrics::parMetrics(pit_type pit, bool redo)
 }
 
 
-int TextMetrics::parPosition(pit_type pit) const
-{
-       if (pit < par_metrics_.begin()->first)
-               return -1000000;
-       if (pit > par_metrics_.rbegin()->first)
-               return +1000000;
-
-       return par_metrics_[pit].position();
-}
-
-
 bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim, int min_width)
 {
        LASSERT(mi.base.textwidth > 0, /**/);
@@ -244,11 +233,9 @@ int TextMetrics::rightMargin(pit_type const pit) const
 
 void TextMetrics::applyOuterFont(Font & font) const
 {
-       Font lf(font_);
-       lf.fontInfo().reduce(bv_->buffer().params().getFont().fontInfo());
-       lf.fontInfo().realize(font.fontInfo());
-       lf.setLanguage(font.language());
-       font = lf;
+       FontInfo lf(font_.fontInfo());
+       lf.reduce(bv_->buffer().params().getFont().fontInfo());
+       font.fontInfo().realize(lf); 
 }
 
 
@@ -335,13 +322,14 @@ bool TextMetrics::isRTLBoundary(pit_type pit, pos_type pos) const
 bool TextMetrics::isRTLBoundary(pit_type pit, pos_type pos,
                Font const & font) const
 {
-       if (!lyxrc.rtl_support)
+       if (!lyxrc.rtl_support
+           // no RTL boundary at paragraph start
+           || pos == 0
+           // if the metrics have not been calculated, then we are not
+           // on screen and can safely ignore issues about boundaries.
+           || !contains(pit))
                return false;
 
-       // no RTL boundary at paragraph start
-       if (pos == 0)
-               return false;
-       
        ParagraphMetrics & pm = par_metrics_[pit];
        // no RTL boundary in empty paragraph
        if (pm.rows().empty())
@@ -356,13 +344,6 @@ bool TextMetrics::isRTLBoundary(pit_type pit, pos_type pos,
                return false;
 
        Paragraph const & par = text_->getPar(pit);
-       bool left = font.isVisibleRightToLeft();
-       bool right;
-       if (pos == par.size())
-               right = par.isRTL(bv_->buffer().params());
-       else
-               right = displayFont(pit, pos).isVisibleRightToLeft();
-       
        // no RTL boundary at line break:
        // abc|\n    -> move right ->   abc\n       (and not:    abc\n|
        // FED                          FED|                     FED     )
@@ -372,6 +353,13 @@ bool TextMetrics::isRTLBoundary(pit_type pit, pos_type pos,
                        || par.isSeparator(pos - 1)))
                return false;
        
+       bool left = font.isVisibleRightToLeft();
+       bool right;
+       if (pos == par.size())
+               right = par.isRTL(bv_->buffer().params());
+       else
+               right = displayFont(pit, pos).isVisibleRightToLeft();
+       
        return left != right;
 }
 
@@ -379,7 +367,7 @@ bool TextMetrics::isRTLBoundary(pit_type pit, pos_type pos,
 bool TextMetrics::redoParagraph(pit_type const pit)
 {
        Paragraph & par = text_->getPar(pit);
-       // IMPORTANT NOTE: We pass 'false' explicitely in order to not call
+       // IMPORTANT NOTE: We pass 'false' explicitly in order to not call
        // redoParagraph() recursively inside parMetrics.
        Dimension old_dim = parMetrics(pit, false).dim();
        ParagraphMetrics & pm = par_metrics_[pit];
@@ -416,7 +404,7 @@ bool TextMetrics::redoParagraph(pit_type const pit)
                LYXERR(Debug::INFO, "MacroContext not initialised!"
                        << " Going through the buffer again and hope"
                        << " the context is better then.");
-               bv_->buffer().updateLabels();
+               bv_->buffer().updateBuffer();
                parPos = text_->macrocontextPosition();
                LASSERT(!parPos.empty(), /**/);
                parPos.pit() = pit;
@@ -1234,6 +1222,12 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
                return 0;
        }
 
+       // if the first character is a separator, we are in RTL
+       // text. This character will not be painted on screen
+       // and thus we should not count it and skip to the next.
+       if (par.isSeparator(bidi.vis2log(vc)))
+               ++vc;
+
        while (vc < end && tmpx <= x) {
                c = bidi.vis2log(vc);
                last_tmpx = tmpx;
@@ -1489,8 +1483,8 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y,
        
        int yy = y; // is modified by getPitAndRowNearY
        Row const & row = getPitAndRowNearY(yy, pit, assert_in_view, up);
-       bool bound = false;
 
+       bool bound = false; // is modified by getColumnNearX
        int xx = x; // is modified by getColumnNearX
        pos_type const pos = row.pos()
                + getColumnNearX(pit, row, xx, bound);
@@ -1512,17 +1506,16 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y,
        }
 
        ParagraphList const & pars = text_->paragraphs();
-       Inset const * insetBefore = pos ? pars[pit].getInset(pos - 1) : 0;
-       //Inset * insetBehind = pars[pit].getInset(pos);
+       Inset const * inset_before = pos ? pars[pit].getInset(pos - 1) : 0;
 
        // This should be just before or just behind the
        // cursor position set above.
-       LASSERT((pos != 0 && inset == insetBefore)
+       LASSERT(inset == inset_before 
                || inset == pars[pit].getInset(pos), /**/);
 
        // Make sure the cursor points to the position before
        // this inset.
-       if (inset == insetBefore) {
+       if (inset == inset_before) {
                --cur.pos();
                cur.boundary(false);
        }
@@ -2263,7 +2256,7 @@ void TextMetrics::drawRowSelection(PainterInfo & pi, int x, Row const & row,
 
        // go through row and draw from RTL boundary to RTL boundary
        while (cur < end) {
-               bool drawNow = false;
+               bool draw_now = false;
 
                // simplified cursorForward code below which does not
                // descend into insets and which does not go into the
@@ -2278,7 +2271,7 @@ void TextMetrics::drawRowSelection(PainterInfo & pi, int x, Row const & row,
                        // because:  ab|cDDEEFFghi -> abc|DDEEFFghi
                        ++cur.pos();
                        cur.boundary(true);
-                       drawNow = true;
+                       draw_now = true;
                } else {
                        // move right
                        ++cur.pos();
@@ -2293,7 +2286,7 @@ void TextMetrics::drawRowSelection(PainterInfo & pi, int x, Row const & row,
                        x1 = cursorX(cur.top(), cur.boundary());
                }
 
-               if (!(cur < end) || drawNow) {
+               if (!(cur < end) || draw_now) {
                        x2 = cursorX(cur.top(), cur.boundary());
                        pi.pain.fillRectangle(x + min(x1,x2), y1, abs(x2 - x1), y2 - y1,
                                Color_selection);