summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorosnola <alonso.laurent@gmail.com>2017-04-19 14:48:46 +0200
committerDavid Tardon <dtardon@redhat.com>2017-04-19 14:48:46 +0200
commitb9044ff16623db8c3651ee3d3055bca206c5aa9e (patch)
treecd3362bf0d4e12ac44701d1b17aa3d07ca143126
parent6b96e0cb63d27352b89953a3bbe29693d845578a (diff)
simplify the code
Change-Id: Id4b7c753ace8e1ca612128b3d936bc3b347a48e1
-rw-r--r--src/lib/ABWContentCollector.cpp92
-rw-r--r--src/lib/ABWContentCollector.h5
-rw-r--r--src/lib/ABWParser.cpp14
3 files changed, 50 insertions, 61 deletions
diff --git a/src/lib/ABWContentCollector.cpp b/src/lib/ABWContentCollector.cpp
index 7eaf064..bc50660 100644
--- a/src/lib/ABWContentCollector.cpp
+++ b/src/lib/ABWContentCollector.cpp
@@ -585,8 +585,7 @@ void libabw::ABWContentCollector::_addBorderProperties(const std::map<std::strin
void libabw::ABWContentCollector::collectParagraphProperties(const char *level, const char *listid, const char * /*parentid*/, const char *style, const char *props)
{
- _closeParagraph();
- _closeListElement();
+ _closeBlock();
if (!level || !findInt(level, m_ps->m_currentListLevel) || m_ps->m_currentListLevel < 1)
m_ps->m_currentListLevel = 0;
if (!listid || !findInt(listid, m_ps->m_currentListId) || m_ps->m_currentListId < 0)
@@ -807,8 +806,7 @@ void libabw::ABWContentCollector::endDocument()
if (!m_ps->m_isPageSpanOpened)
_openPageSpan();
- _closeParagraph();
- _closeListElement();
+ _closeBlock();
m_ps->m_currentListLevel = 0;
_changeList(); // flush the list
@@ -874,8 +872,7 @@ void libabw::ABWContentCollector::closeParagraphOrListElement()
// we have an empty paragraph, insert it
if (!m_ps->m_isParagraphOpened && !m_ps->m_isListElementOpened)
_openSpan();
- _closeParagraph();
- _closeListElement();
+ _closeBlock();
m_ps->m_currentParagraphStyle.clear();
m_ps->m_inParagraphOrListElement = false;
}
@@ -884,14 +881,7 @@ void libabw::ABWContentCollector::openLink(const char *href)
{
if (m_ps->m_isSpanOpened)
_closeSpan();
- if (!m_ps->m_isParagraphOpened && !m_ps->m_isListElementOpened)
- {
- _changeList();
- if (m_ps->m_currentListLevel == 0)
- _openParagraph();
- else
- _openListElement();
- }
+ _openBlock();
librevenge::RVNGPropertyList propList;
if (href)
propList.insert("xlink:href", decodeUrl(href).c_str());
@@ -923,15 +913,13 @@ void libabw::ABWContentCollector::insertLineBreak()
void libabw::ABWContentCollector::insertColumnBreak()
{
- _closeParagraph();
- _closeListElement();
+ _closeBlock();
m_ps->m_deferredColumnBreak = true;
}
void libabw::ABWContentCollector::insertPageBreak()
{
- _closeParagraph();
- _closeListElement();
+ _closeBlock();
m_ps->m_deferredPageBreak = true;
}
@@ -1154,6 +1142,28 @@ void libabw::ABWContentCollector::_fillParagraphProperties(librevenge::RVNGPrope
m_ps->m_deferredColumnBreak = false;
}
+void libabw::ABWContentCollector::_openBlock()
+{
+ if (m_ps->m_isParagraphOpened || m_ps->m_isListElementOpened)
+ return;
+ if (m_ps->m_currentListLevel == 0)
+ _openParagraph();
+ else
+ _openListElement();
+}
+
+void libabw::ABWContentCollector::_closeBlock()
+{
+ if (!m_ps->m_isParagraphOpened && !m_ps->m_isListElementOpened)
+ return;
+ if (m_ps->m_isSpanOpened)
+ _closeSpan();
+ if (m_ps->m_isParagraphOpened)
+ _closeParagraph();
+ if (m_ps->m_isListElementOpened)
+ _closeListElement();
+}
+
void libabw::ABWContentCollector::_openParagraph()
{
if (!m_ps->m_isParagraphOpened)
@@ -1236,13 +1246,7 @@ void libabw::ABWContentCollector::_openSpan()
{
if (!m_ps->m_isSpanOpened)
{
- if (!m_ps->m_isParagraphOpened && !m_ps->m_isListElementOpened)
- {
- if (m_ps->m_currentListLevel == 0)
- _openParagraph();
- else
- _openListElement();
- }
+ _openBlock();
librevenge::RVNGPropertyList propList;
ABWUnit unit(ABW_NONE);
@@ -1340,8 +1344,7 @@ void libabw::ABWContentCollector::_closeSection()
while (!m_ps->m_tableStates.empty())
_closeTable();
- _closeParagraph();
- _closeListElement();
+ _closeBlock();
m_ps->m_currentListLevel = 0;
_changeList();
@@ -1358,8 +1361,7 @@ void libabw::ABWContentCollector::_closeHeader()
while (!m_ps->m_tableStates.empty())
_closeTable();
- _closeParagraph();
- _closeListElement();
+ _closeBlock();
m_ps->m_currentListLevel = 0;
_changeList();
@@ -1378,8 +1380,7 @@ void libabw::ABWContentCollector::_closeFooter()
while (!m_ps->m_tableStates.empty())
_closeTable();
- _closeParagraph();
- _closeListElement();
+ _closeBlock();
m_ps->m_currentListLevel = 0;
_changeList();
@@ -1551,8 +1552,7 @@ void libabw::ABWContentCollector::_closeTableCell()
{
if (m_ps->m_tableStates.top().m_isCellWithoutParagraph)
_openSpan();
- _closeParagraph();
- _closeListElement();
+ _closeBlock();
m_ps->m_currentListLevel = 0;
_changeList();
@@ -1580,8 +1580,7 @@ void libabw::ABWContentCollector::openFoot(const char *id)
void libabw::ABWContentCollector::closeFoot()
{
- _closeParagraph();
- _closeListElement();
+ _closeBlock();
m_ps->m_currentListLevel = 0;
_changeList();
@@ -1613,8 +1612,7 @@ void libabw::ABWContentCollector::openEndnote(const char *id)
void libabw::ABWContentCollector::closeEndnote()
{
- _closeParagraph();
- _closeListElement();
+ _closeBlock();
m_ps->m_currentListLevel = 0;
_changeList();
@@ -1951,8 +1949,7 @@ void libabw::ABWContentCollector::closeField()
void libabw::ABWContentCollector::openTable(const char *props)
{
- _closeParagraph();
- _closeListElement();
+ _closeBlock();
m_ps->m_currentListLevel = 0;
_changeList();
@@ -1986,8 +1983,7 @@ void libabw::ABWContentCollector::openTable(const char *props)
void libabw::ABWContentCollector::closeTable()
{
- _closeParagraph();
- _closeListElement();
+ _closeBlock();
m_ps->m_currentListLevel = 0;
_changeList();
_closeTable();
@@ -2102,15 +2098,8 @@ void libabw::ABWContentCollector::openFrame(const char *props, const char *image
iter = propMap.find(isParagraph ? "ypos" : "frame-page-ypos");
if (iter != propMap.end() && findDouble(iter->second, value, unit) && ABW_IN == unit)
propList.insert("svg:y", value);
- if (isParagraph && !m_ps->m_isParagraphOpened && !m_ps->m_isListElementOpened)
- {
- _changeList();
- if (m_ps->m_currentListLevel == 0)
- _openParagraph();
- else
- _openListElement();
- }
- else if (!isParagraph)
+ if (isParagraph) _openBlock();
+ else
{
iter = propMap.find("frame-pref-page");
int page=0;
@@ -2273,8 +2262,7 @@ void libabw::ABWContentCollector::_recurseListLevels(int oldLevel, int newLevel,
void libabw::ABWContentCollector::_changeList()
{
- _closeParagraph();
- _closeListElement();
+ _closeBlock();
_handleListChange();
}
diff --git a/src/lib/ABWContentCollector.h b/src/lib/ABWContentCollector.h
index 07226c0..9c31f34 100644
--- a/src/lib/ABWContentCollector.h
+++ b/src/lib/ABWContentCollector.h
@@ -175,6 +175,11 @@ private:
void _openSection();
void _closeSection();
+ //! open a paragraph or a list element (depend on m_currentListLevel)
+ void _openBlock();
+ //! close the current paragraph or list element
+ void _closeBlock();
+
void _openParagraph();
void _closeParagraph();
diff --git a/src/lib/ABWParser.cpp b/src/lib/ABWParser.cpp
index f03d7b6..13aad45 100644
--- a/src/lib/ABWParser.cpp
+++ b/src/lib/ABWParser.cpp
@@ -148,6 +148,7 @@ bool libabw::ABWParser::parse()
return false;
std::map<int, ABWListElement *> listElements;
+ bool ok=true;
try
{
std::map<int, int> tableSizes;
@@ -165,19 +166,14 @@ bool libabw::ABWParser::parse()
m_collector = &contentCollector;
m_input->seek(0, librevenge::RVNG_SEEK_SET);
if (!processXmlDocument(m_input))
- {
- clearListElements(listElements);
- return false;
- }
-
- clearListElements(listElements);
- return true;
+ ok=false;
}
catch (...)
{
- clearListElements(listElements);
- return false;
+ ok=false;
}
+ clearListElements(listElements);
+ return ok;
}
bool libabw::ABWParser::processXmlDocument(librevenge::RVNGInputStream *input)