summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/xmlcomposer.cpp1
-rw-r--r--src/xmlfixups.cpp41
-rw-r--r--src/xmlfixups.h1
-rw-r--r--win32/rtfx.dsp22
4 files changed, 64 insertions, 1 deletions
diff --git a/src/xmlcomposer.cpp b/src/xmlcomposer.cpp
index 5c29e65..c2b0b10 100644
--- a/src/xmlcomposer.cpp
+++ b/src/xmlcomposer.cpp
@@ -104,6 +104,7 @@ void RtfParser::endDocument()
// Cleanup the tree
RtfFixups::removeDuplicates(m_document);
+ RtfFixups::consolidateStartTags(m_document);
RtfFixups::consolidateEndTags(m_document);
RtfFixups::breakTables(m_document);
RtfFixups::breakTags(m_document, kElTable, kElRow);
diff --git a/src/xmlfixups.cpp b/src/xmlfixups.cpp
index 64d360d..fe2232b 100644
--- a/src/xmlfixups.cpp
+++ b/src/xmlfixups.cpp
@@ -56,6 +56,9 @@ static const char* kHideList[] =
static const char* kConsolidateEnd[] =
{ kElFootNote, NULL };
+static const char* kConsolidateStart[] =
+ { kElInfo, kElStylesheet, NULL };
+
void RtfFixups::breakBreak(DOM::Document& doc, const string& contain,
const string& tag)
{
@@ -719,6 +722,44 @@ void RtfFixups::consolidateEndTags(DOM::Document& doc)
}
/**
+ * Consolidates a certain tag types at the start of the document
+ */
+void RtfFixups::consolidateStartTags(DOM::Document& doc)
+{
+ DOM::Element top = doc.getDocumentElement();
+ ASSERT(top != NULL);
+
+ DOM::Node first = top.getFirstChild();
+
+ for(const char** t = kConsolidateStart; *t != NULL; t++)
+ {
+ DOM::NodeList elements = doc.getElementsByTagName(*t);
+ if(elements != NULL)
+ {
+ int x = elements->getLength();
+ for(int j = 0; j < x; j++)
+ {
+ // Make sure it's a valid element
+ DOM::Element element = (const DOM::Element&)elements->item(j);
+ if(element == NULL || element == first)
+ continue;
+
+ DOM::Element parent = (const DOM::Element&)element.getParentNode();
+ if(parent == NULL)
+ continue;
+
+ // Remove it from it's child
+ parent.removeChild(element);
+
+ // And put at start of the document of the document
+ ASSERT(first != NULL);
+ top.insertBefore(element, first);
+ }
+ }
+ }
+}
+
+/**
* Removes adjacent duplicate nodes of certain names
*/
void RtfFixups::removeDuplicates(const DOM::Document& doc)
diff --git a/src/xmlfixups.h b/src/xmlfixups.h
index 2def770..a250c5a 100644
--- a/src/xmlfixups.h
+++ b/src/xmlfixups.h
@@ -57,6 +57,7 @@ public:
static void wrapTags(DOM::Document& document, const string& tagName, const string& wrapName);
static void removeTags(const DOM::Document& doc);
static void removeDuplicates(const DOM::Document& doc);
+ static void consolidateStartTags(DOM::Document& doc);
static void consolidateEndTags(DOM::Document& doc);
};
diff --git a/win32/rtfx.dsp b/win32/rtfx.dsp
index f19e662..c124300 100644
--- a/win32/rtfx.dsp
+++ b/win32/rtfx.dsp
@@ -68,7 +68,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "sablot/include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "sablot/include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
@@ -94,6 +94,10 @@ SOURCE=..\src\basehandler.cpp
# End Source File
# Begin Source File
+SOURCE=..\src\domhelpers.cpp
+# End Source File
+# Begin Source File
+
SOURCE=..\src\levelhandler.cpp
# End Source File
# Begin Source File
@@ -102,6 +106,10 @@ SOURCE=..\src\rtfanalyser.cpp
# End Source File
# Begin Source File
+SOURCE=..\src\rtffixups.cpp
+# End Source File
+# Begin Source File
+
SOURCE=..\src\rtfparsehelpers.cpp
# End Source File
# Begin Source File
@@ -127,6 +135,10 @@ SOURCE=..\src\basehandler.h
# End Source File
# Begin Source File
+SOURCE=..\src\domhelpers.h
+# End Source File
+# Begin Source File
+
SOURCE=..\src\levelhandler.h
# End Source File
# Begin Source File
@@ -139,6 +151,10 @@ SOURCE=..\src\rtfanalyser.h
# End Source File
# Begin Source File
+SOURCE=..\src\rtffixups.h
+# End Source File
+# Begin Source File
+
SOURCE=..\src\rtfformatting.h
# End Source File
# Begin Source File
@@ -155,6 +171,10 @@ SOURCE=..\src\sablo.h
# End Source File
# Begin Source File
+SOURCE=..\src\tags.h
+# End Source File
+# Begin Source File
+
SOURCE=..\src\usuals.h
# End Source File
# End Group