Am 11.03.2010 21:25, schrieb Vincent van Ravesteijn:
I want to fix the vertical alignment bugs in LyX 1.6 and also trunk.
To be able to do this, I need to calculate the height of the content
of the current cell (not the height of the row). How is this done?
tabular.cellInset(cell)->metrics(m, dim);
See InsetTabular::metrics(). Here the ascent and descent for each cell
in the row is determined and the maximum is set for the whole row.
Thanks for the hint. I'm nevertheless not able to access the metrics inside the draw() routine.
Attached is a patch that should fix the vertical alignment drawing for normal cells. The problem is
that it doesn't compile because of an unresolved external:
InsetTabular.obj : error LNK2019: unresolved external symbol "public: __thiscall
lyx::MetricsInfo::MetricsInfo(void)" (??0metricsi...@lyx@@q...@xz) referenced
in
function "public: virtual void __thiscall lyx::InsetTabular::draw(class lyx::Pa
interInfo &,int,int)const "
(?d...@insettabular@lyx@@ubexaavpainteri...@2@h...@z)
The problem is that the MetricsInfo is not available. I tried to extend the draw() routine so that
it also grabs the MetricsInfo and the Dimension and not only the PainterInfo but this fails too.
Is there a way to access the metrics?
thanks and regards
Uwe
p.s. I still don't understand how exactly dim.asc is calculated. Where in the
code is this done?
Index: InsetTabular.cpp
===================================================================
--- InsetTabular.cpp (revision 33720)
+++ InsetTabular.cpp (working copy)
@@ -3249,6 +3249,7 @@
dim.wid = tabular.width() + 2 * ADD_TO_TABULAR_WIDTH;
}
+
bool InsetTabular::isCellSelected(Cursor & cur, row_type row, col_type col)
const
{
@@ -3291,6 +3292,7 @@
bool const original_selection_state = pi.selected;
idx_type idx = 0;
+ int cy = 0;
first_visible_cell = Tabular::npos;
for (row_type r = 0; r < tabular.nrows(); ++r) {
int nx = x;
@@ -3309,8 +3311,30 @@
first_visible_cell = idx;
pi.selected |= isCellSelected(cur, r, c);
+
+ // set the position for the vertical alignment
+ cy = y;
+ Dimension dim;
+ MetricsInfo m;
+ // determine the cell dimensions
+ tabular.cellInset(idx)->metrics(m, dim);
+ // if the cell height is below the row height then
+ // substract space according to the row height
+ if ((dim.asc + dim.des) < tabular.rowHeight(idx)) {
+ cy += tabular.rowHeight(idx)/2;
+ switch (tabular.getVAlignment(idx)) {
+ case Tabular::LYX_VALIGN_TOP:
+ break;
+ case Tabular::LYX_VALIGN_MIDDLE:
+ cy -= (dim.asc + dim.des)/2;
+ break;
+ case Tabular::LYX_VALIGN_BOTTOM:
+ cy -= dim.asc + dim.des;
+ break;
+ }
+ }
+
int const cx = nx + tabular.textHOffset(idx);
- int const cy = y + tabular.textVOffset(idx);
// Cache the Inset position.
bv->coordCache().insets().add(cell(idx).get(), cx, y);
cell(idx)->draw(pi, cx, cy);