diff options
author | David Tardon <dtardon@redhat.com> | 2017-04-19 14:06:39 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2017-04-19 14:10:08 +0200 |
commit | 1b5518ab221a64f9c673ebd83c32ccb875ec6ee8 (patch) | |
tree | 75459719e97598f52a21c2ab2b43dce99e7c6846 | |
parent | 13b8cb1cba26b229e39666568d6760b7c91cf72d (diff) |
ofz#1020 look for some invalid table structures
Change-Id: Ia81b62f648d17e1592189cae64ed1eaec7eb0a2f
-rw-r--r-- | src/lib/ABWContentCollector.cpp | 43 | ||||
-rw-r--r-- | src/lib/ABWContentCollector.h | 2 |
2 files changed, 40 insertions, 5 deletions
diff --git a/src/lib/ABWContentCollector.cpp b/src/lib/ABWContentCollector.cpp index 69b29bf..79abad3 100644 --- a/src/lib/ABWContentCollector.cpp +++ b/src/lib/ABWContentCollector.cpp @@ -1997,9 +1997,8 @@ void libabw::ABWContentCollector::openCell(const char *props) { if (props) parsePropString(props, m_ps->m_tableStates.top().m_currentCellProperties); - int currentRow(0); - if (!findInt(_findCellProperty("top-attach"), currentRow)) - currentRow = m_ps->m_tableStates.top().m_currentTableRow + 1; + const int currentRow(getCellPos("top-attach", "bottom-attach", m_ps->m_tableStates.top().m_currentTableRow + 1)); + while (m_ps->m_tableStates.top().m_currentTableRow < currentRow) { if (m_ps->m_tableStates.top().m_currentTableRow >= 0) @@ -2007,11 +2006,45 @@ void libabw::ABWContentCollector::openCell(const char *props) _openTableRow(); } - if (!findInt(_findCellProperty("left-attach"), m_ps->m_tableStates.top().m_currentTableCol)) - m_ps->m_tableStates.top().m_currentTableCol++; + m_ps->m_tableStates.top().m_currentTableCol = + getCellPos("left-attach", "right-attach", m_ps->m_tableStates.top().m_currentTableCol + 1); } } +int libabw::ABWContentCollector::getCellPos(const char *startProp, const char *endProp, int defStart) +{ + int startAttach(0); + const bool haveStart(findInt(_findCellProperty(startProp), startAttach)); + int endAttach(0); + const bool haveEnd(findInt(_findCellProperty(endProp), endAttach)); + + int newStartAttach(startAttach); + + if (haveStart && haveEnd) + { + if (endAttach <= startAttach && endAttach > 0) + newStartAttach = endAttach - 1; + } + else if (haveStart && !haveEnd) + { + if (startAttach / 1000 > defStart) // likely a damaged input + newStartAttach = defStart; + } + else if (!haveStart && haveEnd) + { + if (endAttach <= 0 || endAttach / 1000 > defStart) // likely a damaged input + newStartAttach = defStart; + else + newStartAttach = endAttach - 1; + } + else + { + newStartAttach = defStart; + } + + return newStartAttach; +} + void libabw::ABWContentCollector::closeCell() { if (!m_ps->m_tableStates.empty()) diff --git a/src/lib/ABWContentCollector.h b/src/lib/ABWContentCollector.h index b80bce5..dcd6b3d 100644 --- a/src/lib/ABWContentCollector.h +++ b/src/lib/ABWContentCollector.h @@ -210,6 +210,8 @@ private: void _fillParagraphProperties(librevenge::RVNGPropertyList &propList, bool isListElement); bool _convertFieldDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propVect); + int getCellPos(const char *startProp, const char *endProp, int defStart); + std::shared_ptr<ABWContentParsingState> m_ps; librevenge::RVNGTextInterface *m_iface; std::stack<std::shared_ptr<ABWContentParsingState> > m_parsingStates; |