This even feels good.

- Martin


On Wed, Dec 05, 2007 at 10:25:08PM +0000, [EMAIL PROTECTED] wrote:
> Author: younes
> Date: Wed Dec  5 23:25:07 2007
> New Revision: 21980
> 
> URL: http://www.lyx.org/trac/changeset/21980
> Log:
> Cleanup Hfill metrics and painting. InsetHFill is now treated almost like any 
> other inset.
> 
> Modified:
>     lyx-devel/trunk/src/TextMetrics.cpp
>     lyx-devel/trunk/src/insets/InsetHFill.cpp
>     lyx-devel/trunk/src/insets/InsetHFill.h
>     lyx-devel/trunk/src/rowpainter.cpp
>     lyx-devel/trunk/src/rowpainter.h
> 
> Modified: lyx-devel/trunk/src/TextMetrics.cpp
> URL: 
> http://www.lyx.org/trac/file/lyx-devel/trunk/src/TextMetrics.cpp?rev=21980
> ==============================================================================
> --- lyx-devel/trunk/src/TextMetrics.cpp (original)
> +++ lyx-devel/trunk/src/TextMetrics.cpp Wed Dec  5 23:25:07 2007
> @@ -512,7 +512,6 @@
>  void TextMetrics::computeRowMetrics(pit_type const pit,
>               Row & row, int width) const
>  {
> -
>       row.label_hfill = 0;
>       row.hfill = 0;
>       row.separator = 0;
> @@ -638,6 +637,28 @@
>                               row.x += row.label_hfill;
>               }
>       }
> +
> +     pos_type const endpos = row.endpos();
> +     pos_type body_pos = par.beginOfBody();
> +     if (body_pos > 0
> +             && (body_pos > endpos || !par.isLineSeparator(body_pos - 1)))
> +             body_pos = 0;
> +
> +     ParagraphMetrics & pm = par_metrics_[pit];
> +     InsetList::const_iterator ii = par.insetList().begin();
> +     InsetList::const_iterator iend = par.insetList().end();
> +     for ( ; ii != iend; ++ii) {
> +             if (ii->pos >= endpos || ii->pos < row.pos()
> +                     || ii->inset->lyxCode() != HFILL_CODE
> +                     || !pm.hfillExpansion(row, ii->pos))
> +                     continue;
> +
> +             Dimension dim = row.dimension();
> +             dim.wid = int(ii->pos >= body_pos ? row.hfill : 
> row.label_hfill);
> +             // Cache the inset dimension. 
> +             bv_->coordCache().insets().add(ii->inset, dim);
> +             pm.setInsetDimension(ii->inset, dim);
> +     }
>  }
>  
>  
> @@ -1045,7 +1066,6 @@
>       int const xo = origin_.x_;
>       x -= xo;
>       Paragraph const & par = text_->getPar(pit);
> -     ParagraphMetrics const & pm = par_metrics_[pit];
>       Bidi bidi;
>       bidi.computeTables(par, buffer, row);
>  
> @@ -1082,19 +1102,9 @@
>                               tmpx -= singleWidth(pit, body_pos - 1);
>               }
>  
> -             if (pm.hfillExpansion(row, c)) {
> -                     tmpx += singleWidth(pit, c);
> -                     if (c >= body_pos)
> -                             tmpx += row.hfill;
> -                     else
> -                             tmpx += row.label_hfill;
> -             } else if (par.isSeparator(c)) {
> -                     tmpx += singleWidth(pit, c);
> -                     if (c >= body_pos)
> +             tmpx += singleWidth(pit, c);
> +             if (par.isSeparator(c) && c >= body_pos)
>                               tmpx += row.separator;
> -             } else {
> -                     tmpx += singleWidth(pit, c);
> -             }
>               ++vc;
>       }
>  
> @@ -1512,9 +1522,7 @@
>  
>               x += pm.singleWidth(pos, font);
>  
> -             if (pm.hfillExpansion(row, pos))
> -                     x += (pos >= body_pos) ? row.hfill : row.label_hfill;
> -             else if (par.isSeparator(pos) && pos >= body_pos)
> +             if (par.isSeparator(pos) && pos >= body_pos)
>                       x += row.separator;
>       }
>  
> 
> Modified: lyx-devel/trunk/src/insets/InsetHFill.cpp
> URL: 
> http://www.lyx.org/trac/file/lyx-devel/trunk/src/insets/InsetHFill.cpp?rev=21980
> ==============================================================================
> --- lyx-devel/trunk/src/insets/InsetHFill.cpp (original)
> +++ lyx-devel/trunk/src/insets/InsetHFill.cpp Wed Dec  5 23:25:07 2007
> @@ -11,6 +11,11 @@
>  #include <config.h>
>  
>  #include "InsetHFill.h"
> +
> +#include "MetricsInfo.h"
> +
> +#include "frontends/Painter.h"
> +
>  #include "support/gettext.h"
>  
>  #include <ostream>
> @@ -40,9 +45,30 @@
>  
>  void InsetHFill::metrics(MetricsInfo &, Dimension & dim) const
>  {
> -     dim.wid = 3;
> -     dim.asc = 3;
> -     dim.des = 3;
> +     // The metrics for this inset are calculated externally in
> +     // \c TextMetrics::computeRowMetrics. Those are dummy value:
> +     dim = Dimension(10, 10, 10);
> +}
> +
> +
> +void InsetHFill::draw(PainterInfo & pi, int x, int y) const
> +{
> +     Dimension const dim = Inset::dimension(*pi.base.bv);
> +     x += 1;
> +
> +     int const y0 = y + dim.des;
> +     int const y1 = y - dim.asc;
> +
> +     pi.pain.line(x, y1, x, y0, Color_added_space);
> +     if (dim.wid == 0)
> +             // The HFill is not expanded.
> +             return;
> +
> +     int const x1 = x + dim.wid;
> +
> +     pi.pain.line(x, y, x1, y, Color_added_space,
> +             frontend::Painter::line_onoffdash);
> +     pi.pain.line(x1, y1, x1, y0, Color_added_space);
>  }
>  
>  
> 
> Modified: lyx-devel/trunk/src/insets/InsetHFill.h
> URL: 
> http://www.lyx.org/trac/file/lyx-devel/trunk/src/insets/InsetHFill.h?rev=21980
> ==============================================================================
> --- lyx-devel/trunk/src/insets/InsetHFill.h (original)
> +++ lyx-devel/trunk/src/insets/InsetHFill.h Wed Dec  5 23:25:07 2007
> @@ -24,6 +24,8 @@
>       InsetHFill();
>       ///
>       void metrics(MetricsInfo &, Dimension &) const;
> +     ///
> +     void draw(PainterInfo & pi, int x, int y) const;
>       ///
>       docstring const getScreenLabel(Buffer const &) const;
>       ///
> 
> Modified: lyx-devel/trunk/src/rowpainter.cpp
> URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/rowpainter.cpp?rev=21980
> ==============================================================================
> --- lyx-devel/trunk/src/rowpainter.cpp (original)
> +++ lyx-devel/trunk/src/rowpainter.cpp Wed Dec  5 23:25:07 2007
> @@ -88,36 +88,6 @@
>       return text_metrics_.leftMargin(text_metrics_.width(), pit_,
>               row_.pos());
>  }
> -
> -
> -void RowPainter::paintHfill(pos_type const pos, pos_type const body_pos)
> -{
> -     x_ += 1;
> -
> -     int const y0 = yo_;
> -     int const y1 = y0 - defaultRowHeight() / 2;
> -
> -     pi_.pain.line(int(x_), y1, int(x_), y0, Color_added_space);
> -
> -     if (pm_.hfillExpansion(row_, pos)) {
> -             int const y2 = (y0 + y1) / 2;
> -
> -             if (pos >= body_pos) {
> -                     pi_.pain.line(int(x_), y2, int(x_ + row_.hfill), y2,
> -                             Color_added_space,
> -                             Painter::line_onoffdash);
> -                     x_ += row_.hfill;
> -             } else {
> -                     pi_.pain.line(int(x_), y2, int(x_ + row_.label_hfill), 
> y2,
> -                             Color_added_space,
> -                             Painter::line_onoffdash);
> -                     x_ += row_.label_hfill;
> -             }
> -             pi_.pain.line(int(x_), y1, int(x_), y0, Color_added_space);
> -     }
> -     x_ += 2;
> -}
> -
>  
>  // If you want to debug inset metrics uncomment the following line:
>  //#define DEBUG_METRICS
> @@ -774,13 +744,7 @@
>                       x_ += row_.label_hfill + lwidth - width_pos;
>               }
>  
> -             if (par_.isHfill(pos)) {
> -                     Inset const * inset = par_.getInset(pos);
> -                     pi_.base.bv->coordCache().insets().add(inset, int(x_), 
> yo_);
> -                     paintHfill(pos, body_pos);
> -                     ++vpos;
> -
> -             } else if (par_.isSeparator(pos)) {
> +             if (par_.isSeparator(pos)) {
>                       Font const orig_font = 
> text_metrics_.getDisplayFont(pit_, pos);
>                       double const orig_x = x_;
>                       x_ += width_pos;
> 
> Modified: lyx-devel/trunk/src/rowpainter.h
> URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/rowpainter.h?rev=21980
> ==============================================================================
> --- lyx-devel/trunk/src/rowpainter.h (original)
> +++ lyx-devel/trunk/src/rowpainter.h Wed Dec  5 23:25:07 2007
> @@ -63,7 +63,6 @@
>       int paintAppendixStart(int y);
>       void paintFromPos(pos_type & vpos);
>       void paintInset(Inset const * inset, pos_type const pos);
> -     void paintHfill(pos_type const pos, pos_type const body_pos);
>  
>       /// return left margin
>       int leftMargin() const;
> 
> 
> _______________________________________________
> Cvslog mailing list
> [EMAIL PROTECTED]
> http://www.lyx.org/mailman/listinfo/cvslog
> 

Reply via email to