]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
Bug fix: correctly redraw a Row containing and inset which Dimension slightly changed...
[lyx.git] / src / TextMetrics.cpp
index 7b10179f2410b2925e38f6132788d17a34fab4ca..3a529020785624bf4a015800749383a08b843a05 100644 (file)
@@ -115,7 +115,7 @@ TextMetrics::TextMetrics(BufferView * bv, Text * text)
        dim_.asc = 10;
        dim_.des = 10;
 
-       //text_->updateLabels(*bv->buffer());
+       //text_->updateLabels(bv->buffer());
 }
 
 
@@ -172,26 +172,26 @@ bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim)
 
 int TextMetrics::rightMargin(ParagraphMetrics const & pm) const
 {
-       return main_text_? pm.rightMargin(*bv_->buffer()) : 0;
+       return main_text_? pm.rightMargin(bv_->buffer()) : 0;
 }
 
 
 int TextMetrics::rightMargin(pit_type const pit) const
 {
-       return main_text_? par_metrics_[pit].rightMargin(*bv_->buffer()) : 0;
+       return main_text_? par_metrics_[pit].rightMargin(bv_->buffer()) : 0;
 }
 
 
 bool TextMetrics::redoParagraph(pit_type const pit)
 {
+       Paragraph & par = text_->getPar(pit);
        // IMPORTANT NOTE: We pass 'false' explicitely in order to not call
        // redoParagraph() recursively inside parMetrics.
        Dimension old_dim = parMetrics(pit, false).dim();
        ParagraphMetrics & pm = par_metrics_[pit];
-       // reinitialize paragraph dimension.
-       pm.dim() = Dimension();
-       Paragraph & par = text_->getPar(pit);
-       Buffer & buffer = *bv_->buffer();
+       pm.reset(par);
+
+       Buffer & buffer = bv_->buffer();
        main_text_ = (text_ == &buffer.text());
        bool changed = false;
 
@@ -221,18 +221,17 @@ bool TextMetrics::redoParagraph(pit_type const pit)
        InsetList::const_iterator ii = par.insetlist.begin();
        InsetList::const_iterator iend = par.insetlist.end();
        for (; ii != iend; ++ii) {
+               Dimension old_dim = ii->inset->dimension();
                Dimension dim;
                int const w = max_width_ - text_->leftMargin(buffer, max_width_, pit, ii->pos)
                        - right_margin;
                Font const & font = ii->inset->noFontChange() ?
                        bufferfont : text_->getFont(buffer, par, ii->pos);
                MetricsInfo mi(bv_, font, w);
-               changed |= ii->inset->metrics(mi, dim);
+               ii->inset->metrics(mi, dim);
+               changed |= (old_dim != dim);
        }
 
-       // rebreak the paragraph
-       pm.rows().clear();
-
        par.setBeginOfBody();
        pos_type z = 0;
        // maximum pixel width of a row
@@ -275,7 +274,7 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
                Row const & row) const
 {
        RowMetrics result;
-       Buffer & buffer = *bv_->buffer();
+       Buffer & buffer = bv_->buffer();
        Paragraph const & par = text_->getPar(pit);
 
        double w = dim_.wid - row.width();
@@ -287,7 +286,7 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
                result.x = text_->leftMargin(buffer, max_width_, pit, row.pos());
 
        // is there a manual margin with a manual label
-       Layout_ptr const & layout = par.layout();
+       LayoutPtr const & layout = par.layout();
 
        if (layout->margintype == MARGIN_MANUAL
            && layout->labeltype == LABEL_MANUAL) {
@@ -397,7 +396,7 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
 
 int TextMetrics::labelFill(pit_type const pit, Row const & row) const
 {
-       Buffer & buffer = *bv_->buffer();
+       Buffer & buffer = bv_->buffer();
        Paragraph const & par = text_->getPar(pit);
 
        pos_type last = par.beginOfBody();
@@ -448,14 +447,14 @@ int TextMetrics::labelEnd(pit_type const pit) const
        if (text_->getPar(pit).layout()->margintype != MARGIN_MANUAL)
                return 0;
        // return the beginning of the body
-       return text_->leftMargin(*bv_->buffer(), max_width_, pit);
+       return text_->leftMargin(bv_->buffer(), max_width_, pit);
 }
 
 
 void TextMetrics::rowBreakPoint(int width, pit_type const pit,
                Row & row) const
 {
-       Buffer & buffer = *bv_->buffer();
+       Buffer & buffer = bv_->buffer();
        ParagraphMetrics const & pm = par_metrics_[pit];
        Paragraph const & par = text_->getPar(pit);
        pos_type const end = par.size();
@@ -470,7 +469,7 @@ void TextMetrics::rowBreakPoint(int width, pit_type const pit,
                return;
        }
 
-       Layout_ptr const & layout = par.layout();
+       LayoutPtr const & layout = par.layout();
 
        if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
                row.endpos(addressBreakPoint(pos, par));
@@ -571,7 +570,7 @@ void TextMetrics::rowBreakPoint(int width, pit_type const pit,
 void TextMetrics::setRowWidth(int right_margin,
                pit_type const pit, Row & row) const
 {
-       Buffer & buffer = *bv_->buffer();
+       Buffer & buffer = bv_->buffer();
        // get the pure distance
        pos_type const end = row.endpos();
        ParagraphMetrics const & pm = par_metrics_[pit];
@@ -622,13 +621,13 @@ void TextMetrics::setHeightOfRow(pit_type const pit,
        // ok, let us initialize the maxasc and maxdesc value.
        // Only the fontsize count. The other properties
        // are taken from the layoutfont. Nicer on the screen :)
-       Layout_ptr const & layout = par.layout();
+       LayoutPtr const & layout = par.layout();
 
        // as max get the first character of this row then it can
        // increase but not decrease the height. Just some point to
        // start with so we don't have to do the assignment below too
        // often.
-       Buffer const & buffer = *bv_->buffer();
+       Buffer const & buffer = bv_->buffer();
        Font font = text_->getFont(buffer, par, row.pos());
        Font::FONT_SIZE const tmpsize = font.size();
        font = text_->getLayoutFont(buffer, pit);
@@ -808,7 +807,7 @@ void TextMetrics::setHeightOfRow(pit_type const pit,
 pos_type TextMetrics::getColumnNearX(pit_type const pit,
                Row const & row, int & x, bool & boundary) const
 {
-       Buffer const & buffer = *bv_->buffer();
+       Buffer const & buffer = bv_->buffer();
 
        /// For the main Text, it is possible that this pit is not
        /// yet in the CoordCache when moving cursor up.
@@ -823,7 +822,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
        pos_type vc = row.pos();
        pos_type end = row.endpos();
        pos_type c = 0;
-       Layout_ptr const & layout = par.layout();
+       LayoutPtr const & layout = par.layout();
 
        bool left_side = false;
 
@@ -957,7 +956,7 @@ pos_type TextMetrics::x2pos(pit_type pit, int row, int x) const
 
 int TextMetrics::singleWidth(pit_type pit, pos_type pos) const
 {
-       Buffer const & buffer = *bv_->buffer();
+       Buffer const & buffer = bv_->buffer();
        ParagraphMetrics const & pm = par_metrics_[pit];
 
        return pm.singleWidth(pos, text_->getFont(buffer, text_->getPar(pit), pos));