]> git.lyx.org Git - features.git/commitdiff
* TextMetrics: getDisplayFont() and isRTLBoundary() takes pit instead of Paragraph.
authorAbdelrazak Younes <younes@lyx.org>
Sun, 2 Sep 2007 22:28:49 +0000 (22:28 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 2 Sep 2007 22:28:49 +0000 (22:28 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20015 a592a061-630c-0410-9148-cb99ea01b6c8

src/Cursor.cpp
src/FontIterator.cpp
src/FontIterator.h
src/Text.cpp
src/Text2.cpp
src/Text3.cpp
src/TextMetrics.cpp
src/TextMetrics.h
src/insets/InsetTabular.cpp
src/rowpainter.cpp

index 363114ef5a0afe5e1b9c1cc055da79e812307be0..f31e52fdabe56797dc04cdf14c4a290edc2b19cd 100644 (file)
@@ -1461,8 +1461,8 @@ Font Cursor::getFont() const
        if (pos > 0) {
                TextMetrics const & tm = bv().textMetrics(&text);
                if (pos == sl.lastpos()
-                               || (par.isSeparator(pos) &&
-                                               !tm.isRTLBoundary(par, pos)))
+                       || (par.isSeparator(pos) 
+                       && !tm.isRTLBoundary(sl.pit(), pos)))
                        --pos;
        }
        
@@ -1526,7 +1526,7 @@ void Cursor::setCurrentFont()
                        // abc| def -> font of c
                        // abc |[WERBEH], i.e. boundary==true -> font of c
                        // abc [WERBEH]| def, font of the space
-                       if (!tm.isRTLBoundary(par, cpos))
+                       if (!tm.isRTLBoundary(pit(), cpos))
                                --cpos;
                }
        }
@@ -1534,11 +1534,11 @@ void Cursor::setCurrentFont()
        // get font
        BufferParams const & bufparams = buffer().params();
        current_font = par.getFontSettings(bufparams, cpos);
-       real_current_font = tm.getDisplayFont(par, cpos);
+       real_current_font = tm.getDisplayFont(pit(), cpos);
 
        // special case for paragraph end
        if (pos() == lastpos()
-           && tm.isRTLBoundary(par, pos())
+           && tm.isRTLBoundary(pit(), pos())
            && !boundary()) {
                Language const * lang = par.getParLanguage(bufparams);
                current_font.setLanguage(lang);
index 116523f430e50e4e1da5c4648a0868a02d5d1bc5..c4f553162c7aa9f1e91f209bb708a1229dc7973b 100644 (file)
@@ -22,9 +22,9 @@ namespace lyx {
 
 
 FontIterator::FontIterator(TextMetrics const & tm,
-               Paragraph const & par, pos_type pos)
-       : tm_(tm), par_(par), pos_(pos),
-         font_(tm.getDisplayFont(par, pos)),
+               Paragraph const & par, pit_type pit, pos_type pos)
+       : tm_(tm), par_(par), pit_(pit), pos_(pos),
+         font_(tm.getDisplayFont(pit, pos)),
          endspan_(par.fontSpan(pos).last),
          bodypos_(par.beginOfBody())
 {}
@@ -46,7 +46,7 @@ FontIterator & FontIterator::operator++()
 {
        ++pos_;
        if (pos_ > endspan_ || pos_ == bodypos_) {
-               font_ = tm_.getDisplayFont(par_, pos_);
+               font_ = tm_.getDisplayFont(pit_, pos_);
                endspan_ = par_.fontSpan(pos_).last;
        }
        return *this;
index b5417877df4f5891fed94ae560bce4e9e6422086..44ecb3790813371662cc0c4de11a9cb2a7b628fb 100644 (file)
@@ -36,7 +36,7 @@ class FontIterator : std::iterator<std::forward_iterator_tag, Font>
 public:
        ///
        FontIterator(TextMetrics const & tm,
-               Paragraph const & par, pos_type pos);
+               Paragraph const & par, pit_type pit, pos_type pos);
        ///
        Font const & operator*() const;
        ///
@@ -50,6 +50,8 @@ private:
        ///
        Paragraph const & par_;
        ///
+       pit_type pit_;
+       ///
        pos_type pos_;
        ///
        Font font_;
index a5103a613b6c9ed0bf38e675003bff4cd7415f25..9fde15b3a2429dd00f17f65497d743693b14565f 100644 (file)
@@ -459,8 +459,8 @@ void Text::insertChar(Cursor & cur, char_type c)
                            !(contains(number_seperators, c) &&
                              cur.pos() != 0 &&
                              cur.pos() != cur.lastpos() &&
-                             tm.getDisplayFont(par, cur.pos()).number() == Font::ON &&
-                             tm.getDisplayFont(par, cur.pos() - 1).number() == Font::ON)
+                             tm.getDisplayFont(pit, cur.pos()).number() == Font::ON &&
+                             tm.getDisplayFont(pit, cur.pos() - 1).number() == Font::ON)
                           )
                                number(cur); // Set current_font.number to OFF
                } else if (isDigit(c) &&
@@ -478,7 +478,7 @@ void Text::insertChar(Cursor & cur, char_type c)
                                                tm.font_);
                                } else if (contains(number_seperators, c)
                                     && cur.pos() >= 2
-                                    && tm.getDisplayFont(par, cur.pos() - 2).number() == Font::ON) {
+                                    && tm.getDisplayFont(pit, cur.pos() - 2).number() == Font::ON) {
                                        setCharFont(buffer, pit, cur.pos() - 1, cur.current_font,
                                                tm.font_);
                                }
@@ -511,7 +511,7 @@ void Text::insertChar(Cursor & cur, char_type c)
        if ((cur.pos() >= 2) && (par.isLineSeparator(cur.pos() - 1))) {
                // get font in front and behind the space in question. But do NOT 
                // use getFont(cur.pos()) because the character c is not inserted yet
-               Font const & pre_space_font  = tm.getDisplayFont(par, cur.pos() - 2);
+               Font const & pre_space_font  = tm.getDisplayFont(cur.pit(), cur.pos() - 2);
                Font const & post_space_font = cur.real_current_font;
                bool pre_space_rtl  = pre_space_font.isVisibleRightToLeft();
                bool post_space_rtl = post_space_font.isVisibleRightToLeft();
@@ -524,7 +524,7 @@ void Text::insertChar(Cursor & cur, char_type c)
                                (pre_space_rtl == par.isRightToLeftPar(buffer.params())) ?
                                pre_space_font.language() : post_space_font.language();
 
-                       Font space_font = tm.getDisplayFont(par, cur.pos() - 1);
+                       Font space_font = tm.getDisplayFont(cur.pit(), cur.pos() - 1);
                        space_font.setLanguage(lang);
                        par.setFont(cur.pos() - 1, space_font);
                }
index 4cac71b48739663ea1729b90c5216d717fccf916..4c47d0811f6c66f8b956755fe9390d0a78f0ea33 100644 (file)
@@ -367,7 +367,7 @@ void Text::setFont(BufferView const & bv, CursorSlice const & begin,
                                // of noFontChange in Inset.h
                                setInsetFont(bv, pit, pos, font, toggleall);
                        TextMetrics const & tm = bv.textMetrics(this);
-                       Font f = tm.getDisplayFont(dit.paragraph(), pos);
+                       Font f = tm.getDisplayFont(pit, pos);
                        f.update(font, language, toggleall);
                        setCharFont(buffer, pit, pos, f, tm.font_);
                }
@@ -655,7 +655,7 @@ bool Text::cursorRight(Cursor & cur)
                TextMetrics const & tm = cur.bv().textMetrics(this);
                // if left of boundary -> just jump to right side
                // but for RTL boundaries don't, because: abc|DDEEFFghi -> abcDDEEF|Fghi
-               if (cur.boundary() && !tm.isRTLBoundary(cur.paragraph(), cur.pos()))
+               if (cur.boundary() && !tm.isRTLBoundary(cur.pit(), cur.pos()))
                        return setCursor(cur, cur.pit(), cur.pos(), true, false);
 
                // next position is left of boundary, 
@@ -684,7 +684,7 @@ bool Text::cursorRight(Cursor & cur)
                
                // in front of RTL boundary? Stay on this side of the boundary because:
                //   ab|cDDEEFFghi -> abc|DDEEFFghi
-               if (tm.isRTLBoundary(cur.paragraph(), cur.pos() + 1))
+               if (tm.isRTLBoundary(cur.pit(), cur.pos() + 1))
                        return setCursor(cur, cur.pit(), cur.pos() + 1, true, true);
                
                // move right
index e89f81e77a75ab8203bf618f9e61c0b3bd542e7c..1c0ceacfbbdf7c4f65c1916a79d231c6cd21ea39 100644 (file)
@@ -102,9 +102,8 @@ namespace {
 
                if (font.language() != ignore_language ||
                                font.number() != Font::IGNORE) {
-                       Paragraph & par = cur.paragraph();
                        TextMetrics const & tm = cur.bv().textMetrics(text);
-                       if (cur.boundary() != tm.isRTLBoundary(par,
+                       if (cur.boundary() != tm.isRTLBoundary(cur.pit(),
                                                cur.pos(), cur.real_current_font))
                                text->setCursor(cur, cur.pit(), cur.pos(),
                                                false, !cur.boundary());
index 2d820c4caeec34994711d032801ce7f4edecca34..c69ab1a345b2b9e645e400c692d9fd6d5f697a92 100644 (file)
@@ -208,11 +208,12 @@ void TextMetrics::applyOuterFont(Font & font) const
 }
 
 
-Font TextMetrics::getDisplayFont(Paragraph const & par,
-               pos_type const pos) const
+Font TextMetrics::getDisplayFont(pit_type pit, pos_type pos) const
 {
        BOOST_ASSERT(pos >= 0);
 
+       ParagraphList const & pars = text_->paragraphs();
+       Paragraph const & par = pars[pit];
        LayoutPtr const & layout = par.layout();
        Buffer const & buffer = bv_->buffer();
        // FIXME: broken?
@@ -252,18 +253,6 @@ Font TextMetrics::getDisplayFont(Paragraph const & par,
        if (!text_->isMainText(buffer))
                applyOuterFont(font);
 
-       // Find the pit value belonging to paragraph. This will not break
-       // even if pars_ would not be a vector anymore.
-       // Performance appears acceptable.
-
-       ParagraphList const & pars = text_->paragraphs();
-
-       pit_type pit = pars.size();
-       for (pit_type it = 0; it < pit; ++it)
-               if (&pars[it] == &par) {
-                       pit = it;
-                       break;
-               }
        // Realize against environment font information
        // NOTE: the cast to pit_type should be removed when pit_type
        // changes to a unsigned integer.
@@ -286,13 +275,11 @@ bool TextMetrics::isRTL(CursorSlice const & sl, bool boundary) const
        if (boundary && sl.pos() > 0)
                correction = -1;
                
-       Paragraph const & par = text_->getPar(sl.pit());
-       return getDisplayFont(par, sl.pos() + correction).isVisibleRightToLeft();
+       return getDisplayFont(sl.pit(), sl.pos() + correction).isVisibleRightToLeft();
 }
 
 
-bool TextMetrics::isRTLBoundary(Paragraph const & par,
-                         pos_type pos) const
+bool TextMetrics::isRTLBoundary(pit_type pit, pos_type pos) const
 {
        if (!lyxrc.rtl_support)
                return false;
@@ -301,28 +288,31 @@ bool TextMetrics::isRTLBoundary(Paragraph const & par,
        if (pos == 0)
                return false;
 
-       bool left = getDisplayFont(par, pos - 1).isVisibleRightToLeft();
+       Paragraph const & par = text_->getPar(pit);
+
+       bool left = getDisplayFont(pit, pos - 1).isVisibleRightToLeft();
        bool right;
        if (pos == par.size())
                right = par.isRightToLeftPar(bv_->buffer().params());
        else
-               right = getDisplayFont(par, pos).isVisibleRightToLeft();
+               right = getDisplayFont(pit, pos).isVisibleRightToLeft();
        return left != right;
 }
 
 
-bool TextMetrics::isRTLBoundary(Paragraph const & par,
-                         pos_type pos, Font const & font) const
+bool TextMetrics::isRTLBoundary(pit_type pit, pos_type pos,
+               Font const & font) const
 {
        if (!lyxrc.rtl_support)
                return false;
 
+       Paragraph const & par = text_->getPar(pit);
        bool left = font.isVisibleRightToLeft();
        bool right;
        if (pos == par.size())
                right = par.isRightToLeftPar(bv_->buffer().params());
        else
-               right = getDisplayFont(par, pos).isVisibleRightToLeft();
+               right = getDisplayFont(pit, pos).isVisibleRightToLeft();
        return left != right;
 }
 
@@ -372,7 +362,7 @@ bool TextMetrics::redoParagraph(pit_type const pit)
                int const w = max_width_ - leftMargin(max_width_, pit, ii->pos)
                        - right_margin;
                Font const & font = ii->inset->noFontChange() ?
-                       bufferfont : getDisplayFont(par, ii->pos);
+                       bufferfont : getDisplayFont(pit, ii->pos);
                MetricsInfo mi(bv_, font, w);
                changed |= ii->inset->metrics(mi, dim);
                changed |= (old_dim != dim);
@@ -660,7 +650,7 @@ pit_type TextMetrics::rowBreakPoint(int width, pit_type const pit,
        // pixel width since last breakpoint
        int chunkwidth = 0;
 
-       FontIterator fi = FontIterator(*this, par, pos);
+       FontIterator fi = FontIterator(*this, par, pit, pos);
        pos_type point = end;
        pos_type i = pos;
        for ( ; i < end; ++i, ++fi) {
@@ -751,7 +741,7 @@ int TextMetrics::rowWidth(int right_margin, pit_type const pit,
        pos_type i = first;
 
        if (i < end) {
-               FontIterator fi = FontIterator(*this, par, i);
+               FontIterator fi = FontIterator(*this, par, pit, i);
                for ( ; i < end; ++i, ++fi) {
                        if (body_pos > 0 && i == body_pos) {
                                FontMetrics const & fm = theFontMetrics(
@@ -797,7 +787,7 @@ boost::tuple<int, int> TextMetrics::rowHeight(pit_type const pit, pos_type const
        // start with so we don't have to do the assignment below too
        // often.
        Buffer const & buffer = bv_->buffer();
-       Font font = getDisplayFont(par, first);
+       Font font = getDisplayFont(pit, first);
        Font::FONT_SIZE const tmpsize = font.size();
        font = text_->getLayoutFont(buffer, pit);
        Font::FONT_SIZE const size = font.size();
@@ -1062,7 +1052,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
                bool const rtl = (bidi.level(c) % 2 == 1);
                if (left_side == rtl) {
                        ++c;
-                       boundary = isRTLBoundary(par, c);
+                       boundary = isRTLBoundary(pit, c);
                }
        }
 
@@ -1448,7 +1438,7 @@ int TextMetrics::cursorX(CursorSlice const & sl,
                // Use font span to speed things up, see above
                if (pos < font_span.first || pos > font_span.last) {
                        font_span = par.fontSpan(pos);
-                       font = getDisplayFont(par, pos);
+                       font = getDisplayFont(pit, pos);
                }
 
                x += pm.singleWidth(pos, font);
@@ -1779,7 +1769,7 @@ int TextMetrics::singleWidth(pit_type pit, pos_type pos) const
 {
        ParagraphMetrics const & pm = par_metrics_[pit];
 
-       return pm.singleWidth(pos, getDisplayFont(text_->getPar(pit), pos));
+       return pm.singleWidth(pos, getDisplayFont(pit, pos));
 }
 
 
@@ -2014,7 +2004,7 @@ void TextMetrics::drawRowSelection(PainterInfo & pi, int x, Row const & row,
                // but for RTL boundaries don't, because: abc|DDEEFFghi -> abcDDEEF|Fghi
                if (cur.boundary()) {
                        cur.boundary(false);
-               }       else if (isRTLBoundary(cur.paragraph(), cur.pos() + 1)) {
+               }       else if (isRTLBoundary(cur.pit(), cur.pos() + 1)) {
                        // in front of RTL boundary -> Stay on this side of the boundary because:
                        //   ab|cDDEEFFghi -> abc|DDEEFFghi
                        ++cur.pos();
index 556ca64b0292c7c0615f975274d3213e5e781ba2..d850074310fd8d152bda4908a87aba64b90a4c09 100644 (file)
@@ -54,7 +54,7 @@ public:
        /// The difference is that this one is used for displaying, and thus we
        /// are allowed to make cosmetic improvements. For instance make footnotes
        /// smaller. (Asger)
-       Font getDisplayFont(Paragraph const & par,
+       Font getDisplayFont(pit_type pit,
                pos_type pos) const;
 
        /// There are currently two font mechanisms in LyX:
@@ -69,10 +69,10 @@ public:
        /// is this position in the paragraph right-to-left?
        bool isRTL(CursorSlice const & sl, bool boundary) const;
        /// is between pos-1 and pos an RTL<->LTR boundary?
-       bool isRTLBoundary(Paragraph const & par,
+       bool isRTLBoundary(pit_type pit,
          pos_type pos) const;
        /// would be a RTL<->LTR boundary between pos and the given font?
-       bool isRTLBoundary(Paragraph const & par,
+       bool isRTLBoundary(pit_type pit,
          pos_type pos, Font const & font) const;
 
 
index 815d52826d766fa752435f722dca9d9e1e8192d2..b7f1b49955994ac5197142765db10319ebf1724e 100644 (file)
@@ -4746,9 +4746,8 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
                        // we can only set this if we are not too far right
                        if (cols < columns) {
                                shared_ptr<InsetText> inset = loctab->getCellInset(cell);
-                               Paragraph & par = inset->text_.getPar(0);
                                Font const font = bv.textMetrics(&inset->text_).
-                                       getDisplayFont(par, 0);
+                                       getDisplayFont(0, 0);
                                inset->setText(buf.substr(op, p - op), font,
                                               buffer.params().trackChanges);
                                ++cols;
@@ -4759,9 +4758,8 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
                        // we can only set this if we are not too far right
                        if (cols < columns) {
                                shared_ptr<InsetText> inset = tabular.getCellInset(cell);
-                               Paragraph & par = inset->text_.getPar(0);
                                Font const font = bv.textMetrics(&inset->text_).
-                                       getDisplayFont(par, 0);
+                                       getDisplayFont(0, 0);
                                inset->setText(buf.substr(op, p - op), font,
                                               buffer.params().trackChanges);
                        }
@@ -4777,8 +4775,7 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
        // check for the last cell if there is no trailing '\n'
        if (cell < cells && op < len) {
                shared_ptr<InsetText> inset = loctab->getCellInset(cell);
-               Paragraph & par = inset->text_.getPar(0);
-               Font const font = bv.textMetrics(&inset->text_).getDisplayFont(par, 0);
+               Font const font = bv.textMetrics(&inset->text_).getDisplayFont(0, 0);
                inset->setText(buf.substr(op, len - op), font,
                        buffer.params().trackChanges);
        }
index 1c47e6981c902acc4bb61649a89a5a8a92fb96eb..342026c71da1f2e964d53ff2fbb3c16d26d2938a 100644 (file)
@@ -123,7 +123,7 @@ void RowPainter::paintHfill(pos_type const pos, pos_type const body_pos)
 
 void RowPainter::paintInset(Inset const * inset, pos_type const pos)
 {
-       Font font = text_metrics_.getDisplayFont(par_, pos);
+       Font font = text_metrics_.getDisplayFont(pit_, pos);
 
        BOOST_ASSERT(inset);
        // FIXME: We should always use font, see documentation of
@@ -194,7 +194,7 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos, Font const & font)
                if (!Encodings::isComposeChar_hebrew(c)) {
                        if (isPrintableNonspace(c)) {
                                int const width2 = pm_.singleWidth(i,
-                                       text_metrics_.getDisplayFont(par_, i));
+                                       text_metrics_.getDisplayFont(pit_, i));
                                dx = (c == 0x05e8 || // resh
                                      c == 0x05d3)   // dalet
                                        ? width2 - width
@@ -228,7 +228,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos, Font const & font)
                if (!Encodings::isComposeChar_arabic(c)) {
                        if (isPrintableNonspace(c)) {
                                int const width2 = pm_.singleWidth(i,
-                                               text_metrics_.getDisplayFont(par_, i));
+                                               text_metrics_.getDisplayFont(pit_, i));
                                dx = (width2 - width) / 2;
                        }
                        break;
@@ -348,7 +348,7 @@ void RowPainter::paintForeignMark(double orig_x, Font const & font, int desc)
 void RowPainter::paintFromPos(pos_type & vpos)
 {
        pos_type const pos = bidi_.vis2log(vpos);
-       Font orig_font = text_metrics_.getDisplayFont(par_, pos);
+       Font orig_font = text_metrics_.getDisplayFont(pit_, pos);
        double const orig_x = x_;
 
        // usual characters, no insets
@@ -727,7 +727,7 @@ void RowPainter::paintText()
                // Use font span to speed things up, see above
                if (vpos < font_span.first || vpos > font_span.last) {
                        font_span = par_.fontSpan(vpos);
-                       font = text_metrics_.getDisplayFont(par_, vpos);
+                       font = text_metrics_.getDisplayFont(pit_, vpos);
                }
 
                const int width_pos = pm_.singleWidth(pos, font);
@@ -772,7 +772,7 @@ void RowPainter::paintText()
                        ++vpos;
 
                } else if (par_.isSeparator(pos)) {
-                       Font orig_font = text_metrics_.getDisplayFont(par_, pos);
+                       Font orig_font = text_metrics_.getDisplayFont(pit_, pos);
                        double const orig_x = x_;
                        x_ += width_pos;
                        if (pos >= body_pos)