summaryrefslogtreecommitdiff
path: root/src/xmlcomposer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmlcomposer.cpp')
-rw-r--r--src/xmlcomposer.cpp156
1 files changed, 118 insertions, 38 deletions
diff --git a/src/xmlcomposer.cpp b/src/xmlcomposer.cpp
index 9be1eeb..11ed2a0 100644
--- a/src/xmlcomposer.cpp
+++ b/src/xmlcomposer.cpp
@@ -50,6 +50,9 @@ RtfParser::RtfParser(const RtfParserOptions& options)
{
m_document = NULL;
memcpy(&m_options, &options, sizeof(options));
+
+ for(int i = 0; i < AUTOCOUNT_MAX; i++)
+ m_autocount[i] = 1;
}
RtfParser::~RtfParser()
@@ -165,6 +168,14 @@ void RtfParser::setAttribute(const string& name, const wstring& value, DOM::Elem
el.setAttribute(name, value);
}
+void RtfParser::setAttribute(const string& name, int value, DOM::Element el)
+{
+ ASSERT(name.length() > 0);
+ if(el == NULL)
+ el = getElement();
+ el.setAttribute(name, formatInt(value));
+}
+
void RtfParser::setDestination(DestinationPtr dest)
{
ASSERT(m_curLevel);
@@ -215,6 +226,17 @@ RtfFormatting& RtfParser::getTextFormatting()
return m_curLevel->getFormatting();
}
+int RtfParser::getAutoCount(int type)
+{
+ ASSERT(type < AUTOCOUNT_MAX);
+ return m_autocount[type];
+}
+
+void RtfParser::incrementAutoCount(int type)
+{
+ ASSERT(type < AUTOCOUNT_MAX);
+ m_autocount[type]++;
+}
// ---------------------------------------------------------------------------------
// Pass this stuff on through to the appropriate analysers etc...
@@ -256,8 +278,21 @@ void RtfParser::groupStart()
void RtfParser::groupEnd()
{
ASSERT(m_curLevel != NULL);
- AnalyserPtr analyser = m_curLevel->getAnalyser();
- if(analyser)
+ bool done = true;
+
+ // First see if this level has an ananlyser
+ AnalyserPtr analyser = m_curLevel->getAnalyser(false);
+ if(!analyser)
+ {
+ // If not then the analyser is going to live and we
+ // get one from a previous level
+ done = false;
+ analyser = m_curLevel->getAnalyser();
+ }
+
+ if(done)
+ analyser->done();
+ else
analyser->groupEnd();
LevelHandler::groupEnd();
@@ -416,7 +451,7 @@ bool RtfParser::ParseAnalyser::processTextContent(const string& cw, int flags, i
if(el != NULL)
{
// This ensures that our content destination is open and ready
- DestinationPtr dest = m_parser->getDestination();
+ DestinationPtr dest = m_parser->getDestination();
ASSERT(dest != NULL);
dest->charData(kValNull);
@@ -453,6 +488,10 @@ bool RtfParser::ParseAnalyser::processTextFormatting(const string& cw, int flags
format.textSetUnderline(on);
else if(cw == "cf" && HAS_PARAM)
format.textSetColor(param);
+ else if(cw == "super")
+ format.textSetSuScript(RtfFormatting::SUPERSCRIPT);
+ else if(cw == "sub")
+ format.textSetSuScript(RtfFormatting::SUBSCRIPT);
else
return false;
@@ -464,6 +503,26 @@ bool RtfParser::ParseAnalyser::processTextFormatting(const string& cw, int flags
return processTextFormatting(cw, flags, param, m_parser->getTextFormatting());
}
+bool RtfParser::ParseAnalyser::processTextAutoContent(const string& cw, int flags, int param)
+{
+ DestinationPtr dest = m_parser->getDestination();
+ ASSERT(dest != NULL);
+ dest->charData(kValNull);
+
+ // Auto generated content
+ if(cw == "chftn")
+ {
+ int ac = m_parser->getAutoCount(AUTOCOUNT_FOOTNOTE);
+
+ AN_ELEMENT(kElRef);
+ AN_ATTRIBUTE(kAtFootNote, ac);
+ dest->charData(formatInt(ac));
+ AN_POP_ELEMENT();
+ return true;
+ }
+
+ return false;
+}
ON_INITIALIZE(Skip)
{ AN_DESTINATION(Null); }
@@ -770,6 +829,8 @@ ON_CONTROLWORD(Root)
AN_ANALYSER(Skip);
else if(cw == "colortbl")
AN_ANALYSER(Skip);
+ else if(cw == "footnote")
+ AN_ANALYSER(FootNote);
else if(cw == "pict")
{
AN_ANALYSER(Skip);
@@ -779,6 +840,8 @@ ON_CONTROLWORD(Root)
AN_ANALYSER(Skip);
else if(processTextContent(cw, flags, param))
DUMMY;
+ else if(processTextAutoContent(cw, flags, param))
+ DUMMY;
else if(processTextFormatting(cw, flags, param))
DUMMY;
else
@@ -845,6 +908,16 @@ ON_CHARDATA(Content)
AN_ATTRIBUTE(kAtIndex, NUM_ATTR(format.textColor()));
elements++;
}
+ if(format.textSuScript() == RtfFormatting::SUPERSCRIPT)
+ {
+ AN_ELEMENT(kElSuper);
+ elements++;
+ }
+ if(format.textSuScript() == RtfFormatting::SUBSCRIPT)
+ {
+ AN_ELEMENT(kElSub);
+ elements++;
+ }
// Write the data to the element
m_parser->getElement().appendChild(
@@ -855,47 +928,54 @@ ON_CHARDATA(Content)
AN_POP_ELEMENT();
}
-#if 0
-ON_INITIALIZE(Table)
-{
- stack = 0;
- level = m_parser->getLevel();
- AN_ELEMENT(kElTable);
- AN_DESTINATION(Content);
-}
-ON_CONTROLWORD(Table)
+ON_INITIALIZE(FootNote)
{
- ASSERT(stack >= 0);
- ASSERT(level != NULL);
-
- if(cw == "trowd")
- {
- stack++;
- }
- else if(cw == "row")
- {
- stack--;
- if(stack <= 0)
- m_parser->rewindLevel(level);
- }
-
- else if(processTextContent(cw, flags, param))
- DUMMY;
- else if(processTextFormatting(cw, flags, param))
- DUMMY;
- else
- DEFAULT_CONTROLWORD;
-
- if(!m_parser->getTextFormatting().paraInTable())
- {
- m_parser->rewindLevel(level);
- }
+ int ac = m_parser->getAutoCount(AUTOCOUNT_FOOTNOTE);
+ AN_ELEMENT(kElFootNote);
+ AN_ATTRIBUTE(kAtId, ac);
+ AN_DESTINATION(Content);
+}
+ON_CONTROLWORD(FootNote)
+{
+ // Inside foot notes there's no link to the foot note
+ if(cw == "chftn")
+ {
+ DestinationPtr dest = m_parser->getDestination();
+ ASSERT(dest != NULL);
+ int ac = m_parser->getAutoCount(AUTOCOUNT_FOOTNOTE);
+ dest->charData(formatInt(ac));
+ return;
+ }
+
+ // Process text content in the foot note
+ else if(processTextContent(cw, flags, param))
+ DUMMY;
+ else if(processTextAutoContent(cw, flags, param))
+ DUMMY;
+ else if(processTextFormatting(cw, flags, param))
+ DUMMY;
+ else
+ DEFAULT_CONTROLWORD;
+}
+ON_DONE(FootNote)
+{
+ m_parser->incrementAutoCount(AUTOCOUNT_FOOTNOTE);
}
-#endif
+// TODO: Remove these (for debugging)
+ON_GROUPSTART(FootNote)
+{
+ int ac = m_parser->getAutoCount(AUTOCOUNT_FOOTNOTE);
+ fprintf(stderr, "%d start\n", ac);
+}
+ON_GROUPEND(FootNote)
+{
+ int ac = m_parser->getAutoCount(AUTOCOUNT_FOOTNOTE);
+ fprintf(stderr, "%d end\n", ac);
+}
ON_CHARDATA(Raw)