Author: leuven
Date: Mon May  9 14:33:32 2011
New Revision: 38655
URL: http://www.lyx.org/trac/changeset/38655

Log:
ensure that latex output for decimally aligned columns does NOT depend on 
cached metrics info (the member decimal_width)

Modified:
   lyx-devel/trunk/src/insets/InsetTabular.cpp

Modified: lyx-devel/trunk/src/insets/InsetTabular.cpp
==============================================================================
--- lyx-devel/trunk/src/insets/InsetTabular.cpp Mon May  9 08:34:17 2011        
(r38654)
+++ lyx-devel/trunk/src/insets/InsetTabular.cpp Mon May  9 14:33:32 2011        
(r38655)
@@ -516,19 +516,25 @@
 }
 
 
-InsetTableCell splitCell(InsetTableCell & head, docstring const align_d, bool 
& hassep)
+DocIterator separatorPos(InsetTableCell * cell, docstring const & align_d)
 {
-       InsetTableCell tail = InsetTableCell(head);
-
-       DocIterator dit = doc_iterator_begin(&head.buffer(), &head);
+       DocIterator dit = doc_iterator_begin(&(cell->buffer()), cell);
        for (; dit; dit.forwardChar())
                if (dit.inTexted() && dit.depth() == 1
                        && dit.paragraph().find(align_d, false, false, 
dit.pos()))
                        break;
 
-       pit_type const psize = head.paragraphs().front().size();
+       return dit;
+}
+
+
+InsetTableCell splitCell(InsetTableCell & head, docstring const align_d, bool 
& hassep)
+{
+       InsetTableCell tail = InsetTableCell(head);
+       DocIterator const dit = separatorPos(&head, align_d);
        hassep = dit;
        if (hassep) {
+               pit_type const psize = head.paragraphs().front().size();
                head.paragraphs().front().eraseChars(dit.pos(), psize, false);
                tail.paragraphs().front().eraseChars(0, 
                        dit.pos() < psize ? dit.pos() + 1 : psize, false);
@@ -2190,8 +2196,11 @@
                || (coldouble != celldouble);
 
        // we center in multicol when no decimal point
-       ismulticol |= ((column_info[c].alignment == LYX_ALIGN_DECIMAL)
-               && (cellInfo(cell).decimal_width == 0));
+       if (column_info[c].alignment == LYX_ALIGN_DECIMAL) {
+               docstring const align_d = column_info[c].decimal_point;
+               DocIterator const dit = separatorPos(cellInset(cell).get(), 
align_d);
+               ismulticol |= !dit;
+       }
 
        // up counter by 1 for each decimally aligned col since they use 2 
latex cols
        int latexcolspan = columnSpan(cell);
@@ -2480,8 +2489,7 @@
                                    ? OutputParams::PLAIN
                                    : OutputParams::ALIGNED;
 
-               if (getAlignment(cell) == LYX_ALIGN_DECIMAL
-                       && cellInfo(cell).decimal_width != 0) {
+               if (getAlignment(cell) == LYX_ALIGN_DECIMAL) {
                        // copy cell and split in 2
                        InsetTableCell head = 
InsetTableCell(*cellInset(cell).get());
                        head.setBuffer(buffer());
@@ -2491,13 +2499,15 @@
                        head.setMacrocontextPositionRecursive(dit);
                        bool hassep = false;
                        InsetTableCell tail = splitCell(head, 
column_info[c].decimal_point, hassep);
-                       tail.setBuffer(head.buffer());
-                       dit.pop_back();
-                       dit.push_back(CursorSlice(tail));
-                       tail.setMacrocontextPositionRecursive(dit);
                        head.latex(os, newrp);
-                       os << '&';
-                       tail.latex(os, newrp);
+                       if (hassep) {
+                               os << '&';
+                               tail.setBuffer(head.buffer());
+                               dit.pop_back();
+                               dit.push_back(CursorSlice(tail));
+                               tail.setMacrocontextPositionRecursive(dit);
+                               tail.latex(os, newrp);
+                       }
                } else if (!isPartOfMultiRow(row, c)) {
                        if (!runparams.nice)
                                os.texrow().start(par.id(), 0);
@@ -3482,11 +3492,7 @@
 
                                // remove text leading decimal point
                                docstring const align_d = 
tabular.column_info[c].decimal_point;
-                               dit = doc_iterator_begin(&tail.buffer(), &tail);
-                               for (; dit; dit.forwardChar())
-                                       if (dit.inTexted() && dit.depth()==1
-                                               && 
dit.paragraph().find(align_d, false, false, dit.pos()))
-                                               break;
+                               dit = separatorPos(&tail, align_d);
 
                                pit_type const psize = 
tail.paragraphs().front().size();
                                if (dit) {

Reply via email to