]> git.lyx.org Git - features.git/commitdiff
fix the drawing for cells with a specified vertical alignment
authorEdwin Leuven <e.leuven@gmail.com>
Fri, 19 Mar 2010 09:41:31 +0000 (09:41 +0000)
committerEdwin Leuven <e.leuven@gmail.com>
Fri, 19 Mar 2010 09:41:31 +0000 (09:41 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33799 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetTabular.cpp
src/insets/InsetTabular.h

index fca719853f8b518071811216d5ba5fb78787bd43..a46c0a2c0c9b78d616ed8916436321aa710c4384 100644 (file)
@@ -518,6 +518,7 @@ Tabular::CellData::CellData(Buffer * buf)
          multirow(Tabular::CELL_NORMAL),
          alignment(LYX_ALIGN_CENTER),
          valignment(LYX_VALIGN_TOP),
+         voffset(0),
          top_line(false),
          bottom_line(false),
          left_line(false),
@@ -1221,20 +1222,7 @@ int Tabular::textHOffset(idx_type cell) const
 
 int Tabular::textVOffset(idx_type cell) const
 {
-       row_type const r = cellRow(cell);
-       int y = cellHeight(cell) - rowDescent(r) - rowAscent(r);
-       switch (getVAlignment(cell)) {
-          case LYX_VALIGN_TOP:
-                  y = 0;
-                  break;
-          case LYX_VALIGN_MIDDLE:
-                  y = y/2;
-                  break;
-          case LYX_VALIGN_BOTTOM:
-                  break;
-       }
-
-       return y;
+       return cellInfo(cell).voffset;
 }
 
 
@@ -3235,8 +3223,26 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
                        if (!p_width.zero())
                                dim.wid = m.base.textwidth;
                        tabular.setCellWidth(cell, dim.wid);
-                       maxAsc  = max(maxAsc, dim.asc);
-                       maxDesc = max(maxDesc, dim.des);
+
+                       // FIXME?: do we need a second metrics call
+                       // to get the descent of the text in last par?
+                       TextMetrics const & tm = 
+                               mi.base.bv->textMetrics(tabular.cellInset(cell)->getText(0));
+                       int const backdes = tm.last().second->descent();
+
+                       switch (tabular.getVAlignment(cell)) { 
+                               case Tabular::LYX_VALIGN_TOP:
+                                       tabular.cell_info[r][c].voffset = 0; 
+                                       break; 
+                               case Tabular::LYX_VALIGN_MIDDLE:
+                                       tabular.cell_info[r][c].voffset = -(dim.des - backdes - TEXT_TO_INSET_OFFSET)/2; 
+                                       break; 
+                               case Tabular::LYX_VALIGN_BOTTOM:
+                                       tabular.cell_info[r][c].voffset = -(dim.des - backdes - TEXT_TO_INSET_OFFSET);
+                                       break;
+                       }
+                       maxAsc  = max(maxAsc, dim.asc - tabular.cell_info[r][c].voffset);
+                       maxDesc = max(maxDesc, dim.des + tabular.cell_info[r][c].voffset);
                }
                int const top_space = tabular.row_info[r].top_space_default ?
                        default_line_space :
index b6cb46109b77b0e3513e7894305108acf48f8b77..9e3f532f390b70d7ff8e218ae27f041b28c90ed5 100644 (file)
@@ -491,6 +491,8 @@ public:
                ///
                VAlignment valignment;
                ///
+               int voffset;
+               ///
                bool top_line;
                ///
                bool bottom_line;