diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tags.h | 2 | ||||
-rw-r--r-- | src/xmlcomposer.cpp | 69 | ||||
-rw-r--r-- | src/xmlcomposer.h | 14 |
3 files changed, 80 insertions, 5 deletions
@@ -88,6 +88,7 @@ static const char* kElFootNote = "footnote"; static const char* kElRef = "ref"; static const char* kElFont = "font"; static const char* kElOptions = "options"; +static const char* kElLink = "link"; // Attributes static const char* kAtName = "name"; @@ -103,6 +104,7 @@ static const char* kAtStart = "start"; static const char* kAtId = "id"; static const char* kAtTo = "to"; static const char* kAtSize = "size"; +static const char* kAtHref = "href"; // Values static const char* kValDisc = "disc"; diff --git a/src/xmlcomposer.cpp b/src/xmlcomposer.cpp index 0bcfbcc..aa7485f 100644 --- a/src/xmlcomposer.cpp +++ b/src/xmlcomposer.cpp @@ -322,10 +322,10 @@ void XmlComposer::addDocumentOption(DOM::Element& option) m_composer->popElement() #define AN_ATTRIBUTE(name, value) \ m_composer->setAttribute(name, value) -#define AN_DESTINATION_ATTR(name) \ - m_composer->setDestination(new Attribute(name)) #define AN_DESTINATION(cls) \ m_composer->setDestination(new cls) +#define AN_DESTINATION_ARG(cls, arg) \ + m_composer->setDestination(new cls(arg)) #define AN_ANALYSER(cls) \ m_composer->setAnalyser(AnalyserPtr(new cls)) #define AN_SET_ANALYSER(cls) \ @@ -663,7 +663,7 @@ ON_CONTROLWORD(Style) if(!haveStyle) { AN_ELEMENT(kElStyle); - AN_DESTINATION_ATTR(kAtName); + AN_DESTINATION_ARG(Attribute, kAtName); haveStyle = true; } @@ -742,7 +742,7 @@ ON_DONE(FontTable) ON_INITIALIZE(Font) { AN_ELEMENT(kElFontDef); - AN_DESTINATION_ATTR(kAtName); + AN_DESTINATION_ARG(Attribute, kAtName); } ON_CONTROLWORD(Font) @@ -796,7 +796,7 @@ ON_CONTROLWORD(List) { // The name if(cw == "listname") - AN_DESTINATION_ATTR(kAtName); + AN_DESTINATION_ARG(Attribute, kAtName); // The list id else if(cw == "listid" && HAS_PARAM) @@ -983,6 +983,57 @@ ON_CONTROLWORD(Info) DEFAULT_CONTROLWORD; } +// Field Analyser ------------------------------------------------------------------- + +static const string kFieldHyperlink = "HYPERLINK"; + +ON_CONTROLWORD(Field) +{ + // Pull out the field code and data nicely + if(cw == "fldinst" && flags & kAsterisk) + AN_DESTINATION_ARG(String, fieldCode); + + // And now we get to the precalculated field result... + else if(cw == "fldrslt") + { + // If we have a field code that we want to mess with ... + if(!fieldCode.empty()) + { + // Try to find a field code we recognize + wstring::size_type p = fieldCode.find_first_not_of(" \t"); + + if(fieldCode.compare(p, kFieldHyperlink.size(), kFieldHyperlink) == 0) + { + p += kFieldHyperlink.size(); + + // Find first quote + p = fieldCode.find('"', p); + p = (p == string::npos) ? 0 : p + 1; + + // And the end quote + wstring::size_type e = fieldCode.find('"', p); + e = (e == string::npos) ? string::npos : e - p; + + AN_ELEMENT(kElLink); + AN_ATTRIBUTE(kAtHref, fieldCode.substr(p, e)); + } + } + } + + // The internal link data + else if(flags & kAsterisk) + AN_DESTINATION(Null); + + // 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; +} // Root Analyser -------------------------------------------------------------------- @@ -1018,6 +1069,8 @@ ON_CONTROLWORD(Root) AN_ANALYSER(Skip); AN_DESTINATION(Null); } + else if(cw == "field") + AN_ANALYSER(Field); else if(flags & kAsterisk) AN_ANALYSER(Skip); else if(processTextContent(cw, flags, param)) @@ -1239,3 +1292,9 @@ ON_CHARDATA(Attribute) element.setAttribute(name, cur); } +// String Destination --------------------------------------------------------------- + +ON_CHARDATA(String) +{ + str.append(data); +} diff --git a/src/xmlcomposer.h b/src/xmlcomposer.h index 357cb58..26839d7 100644 --- a/src/xmlcomposer.h +++ b/src/xmlcomposer.h @@ -186,6 +186,13 @@ protected: DOM::Element element; END_DESTINATION + // Copies character data to a string + DESTINATION(String) + String(string& s) : str(s) {} + CHARDATA + DATA_PORTION + string& str; + END_DESTINATION // Base class for analysers with some helper functions class BaseAnalyser : @@ -294,6 +301,13 @@ protected: CONTROLWORD END_ANALYSER + // For parsing fields + ANALYSER(Field) + CONTROLWORD + DATA_PORTION + string fieldCode; + END_ANALYSER + // The main root analyser ANALYSER(Root) INITIALIZE |