From 3034bc266dbdc8def5f1a851dd99e4e1d66ae1e7 Mon Sep 17 00:00:00 2001 From: Edwin Leuven Date: Mon, 9 May 2011 12:33:32 +0000 Subject: [PATCH] ensure that latex output for decimally aligned columns does NOT depend on cached metrics info (the member decimal_width) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38655 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/InsetTabular.cpp | 46 +++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 39a82f849d..ad97053bb1 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -516,19 +516,25 @@ string const featureAsString(Tabular::Feature action) } -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 @@ void Tabular::TeXCellPreamble(otexstream & os, idx_type cell, || (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 @@ void Tabular::TeXRow(otexstream & os, row_type row, ? 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 @@ void Tabular::TeXRow(otexstream & os, row_type row, 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 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const // 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) { -- 2.39.2