]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
Add support for todonotes package
[lyx.git] / src / TextMetrics.cpp
index a5f03648de854271f2261f8fb5d7e03a657f2ad3..eb71f74f1c00088fb1268eee64ce064c44022ff8 100644 (file)
@@ -506,11 +506,11 @@ bool TextMetrics::redoParagraph(pit_type const pit)
 }
 
 
-int TextMetrics::getAlign(Paragraph const & par, pos_type const pos) const
+LyXAlignment TextMetrics::getAlign(Paragraph const & par, pos_type const pos) const
 {
        Layout const & layout = par.layout();
 
-       int align;
+       LyXAlignment align;
        if (par.params().align() == LYX_ALIGN_LAYOUT)
                align = layout.align;
        else
@@ -627,9 +627,15 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
                        row.x += w;
                        break;
                case LYX_ALIGN_CENTER:
-                       row.dimension().wid = width - w / 2;
+                       row.dimension().wid = width - int(w / 2);
                        row.x += w / 2;
                        break;
+               case LYX_ALIGN_LEFT:
+               case LYX_ALIGN_NONE:
+               case LYX_ALIGN_LAYOUT:
+               case LYX_ALIGN_SPECIAL:
+               case LYX_ALIGN_DECIMAL:
+                       break;
                }
        }
 
@@ -660,7 +666,7 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
        for ( ; cit != cend; ++cit) {
                if (row.label_hfill && cit->endpos == body_pos
                    && cit->type == Row::SPACE)
-                       cit->dim.wid -= row.label_hfill * (nlh - 1);
+                       cit->dim.wid -= int(row.label_hfill * (nlh - 1));
                if (!cit->inset || !cit->inset->isHfill())
                        continue;
                if (pm.hfillExpansion(row, cit->pos))
@@ -680,7 +686,7 @@ int TextMetrics::labelFill(pit_type const pit, Row const & row) const
        Paragraph const & par = text_->getPar(pit);
        LBUFERR(par.beginOfBody() > 0 || par.isEnvSeparator(0));
 
-       int w = 0;
+       double w = 0;
        Row::const_iterator cit = row.begin();
        Row::const_iterator const end = row.end();
        // iterate over elements before main body (except the last one,
@@ -697,7 +703,7 @@ int TextMetrics::labelFill(pit_type const pit, Row const & row) const
        FontMetrics const & fm
                = theFontMetrics(text_->labelFont(par));
 
-       return max(0, fm.width(label) - w);
+       return max(0, fm.width(label) - int(w));
 }
 
 
@@ -1108,10 +1114,10 @@ pos_type TextMetrics::getPosNearX(Row const & row, int & x,
        pos_type pos = row.pos();
        boundary = false;
        if (row.empty())
-               x = row.x;
+               x = int(row.x);
        else if (x <= row.x) {
                pos = row.front().left_pos();
-               x = row.x;
+               x = int(row.x);
        } else if (x >= row.width() - row.right_margin) {
                pos = row.back().right_pos();
                x = row.width() - row.right_margin;
@@ -1123,7 +1129,7 @@ pos_type TextMetrics::getPosNearX(Row const & row, int & x,
                        if (w <= x &&  w + cit->width() > x) {
                                double x_offset = x - w;
                                pos = cit->x2pos(x_offset);
-                               x = x_offset + w;
+                               x = int(x_offset + w);
                                break;
                        }
                        w += cit->width();
@@ -1144,12 +1150,14 @@ pos_type TextMetrics::getPosNearX(Row const & row, int & x,
        }
 
        /** This tests for the case where the cursor is set at the end
-        * of a row which has been broken due to a display inset on
-        * next row. This is indicated by Row::right_boundary.
+        * of a row which has been broken due something else than a
+        * separator (a display inset or a forced breaking of the
+        * row). We know that there is a separator when the end of the
+        * row is larger than the end of its last element.
         */
        if (!row.empty() && pos == row.back().endpos
            && row.back().endpos == row.endpos())
-               boundary = row.right_boundary();
+               boundary = true;
 
        x += xo;
        return pos;