diff options
author | Stef Walter <stef@memberwebs.com> | 2005-04-19 17:24:24 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2005-04-19 17:24:24 +0000 |
commit | 6fab96c700f8a15b486c292e70c8fdb5d31121b2 (patch) | |
tree | 0262fbfd99f0954bed556599a6daaf983c566b6c /src | |
parent | c91a548602ca74b5989eb046bc9c906b81e0ae20 (diff) |
Added support for character styles.
Diffstat (limited to 'src')
-rw-r--r-- | src/rtfformatting.h | 12 | ||||
-rw-r--r-- | src/tags.h | 1 | ||||
-rw-r--r-- | src/xmlcomposer.cpp | 34 | ||||
-rw-r--r-- | src/xmlfixups.cpp | 15 |
4 files changed, 49 insertions, 13 deletions
diff --git a/src/rtfformatting.h b/src/rtfformatting.h index aa5ac58..3085198 100644 --- a/src/rtfformatting.h +++ b/src/rtfformatting.h @@ -70,7 +70,8 @@ public: m_color == format.m_color && m_suscript == format.m_suscript && m_font == format.m_font && - m_fsize == format.m_fsize; + m_fsize == format.m_fsize && + m_charstyle == format.m_charstyle; } bool paraEquals(RtfFormatting& format) const @@ -91,6 +92,7 @@ public: m_suscript = format.m_suscript; m_font = format.m_font; m_fsize = format.m_fsize; + m_charstyle = format.m_charstyle; m_style = format.m_style; m_list = format.m_list; @@ -105,6 +107,7 @@ public: m_suscript = 0; m_fsize = -1; m_font = -1; + m_charstyle = -1; } void resetPara() @@ -131,6 +134,8 @@ public: { return m_font; } int textFontSize() const { return m_fsize; } + int textStyle() + { return m_charstyle; } int paraStyle() const { return m_style; } int paraList() const @@ -156,6 +161,8 @@ public: { m_font = font; } void textSetFontSize(int fsize) { m_fsize = fsize == 24 ? -1 : fsize; } // default font size is always 24 + void textSetStyle(int style) + { m_charstyle = style; } void paraSetStyle(int style) { m_style = style; } void paraSetList(int list) @@ -179,12 +186,11 @@ protected: int m_color; int m_font; int m_fsize; + int m_charstyle; int m_style; int m_list; bool m_inTbl; - - // TODO: Character styles }; #endif // __RTFFORMATTING_H__ @@ -65,6 +65,7 @@ static const char* kElTab = "tab"; static const char* kElSect = "sect"; static const char* kElPage = "page"; static const char* kElStyle = "style"; +static const char* kElSpan = "span"; static const char* kElLine = "line"; static const char* kElList = "list"; static const char* kElStylesheet = "stylesheet"; diff --git a/src/xmlcomposer.cpp b/src/xmlcomposer.cpp index 93bd8f3..10b476f 100644 --- a/src/xmlcomposer.cpp +++ b/src/xmlcomposer.cpp @@ -525,6 +525,8 @@ bool XmlComposer::BaseAnalyser::processTextFormatting(const string& cw, int flag format.textSetFont(param); else if(cw == "fs" && HAS_PARAM) format.textSetFontSize(param); + else if(cw == "cs" && HAS_PARAM) + format.textSetStyle(param); else return false; @@ -640,8 +642,16 @@ ON_INITIALIZE(Style) ON_CONTROLWORD(Style) { - // Get the style id - if(flags & kAsterisk) + bool use = false; + + // The style id + if((cw == "s" && (flags & kHasParam)) || + (cw == "cs" && (flags & kAsterisk) && (flags & kHasParam))) + { + use = true; + } + + else if (flags & kAsterisk) { AN_ANALYSER(Skip); return; @@ -655,18 +665,19 @@ ON_CONTROLWORD(Style) haveStyle = true; } - // The style id - if(cw == "s" && flags & kHasParam) + if (use) { AN_ATTRIBUTE(kAtId, param); } // Otherwise get as much formatting out of the tag as possible - else if(processTextFormatting(cw, flags, param)) - DUMMY; - else - DEFAULT_CONTROLWORD; + { + if(processTextFormatting(cw, flags, param)) + DUMMY; + else + DEFAULT_CONTROLWORD; + } } ON_GROUPSTART(Style) @@ -1081,6 +1092,13 @@ ON_CHARDATA(Content) } } + if(format.textStyle() != -1) + { + AN_ELEMENT(kElSpan); + AN_ATTRIBUTE(kElStyle, format.textStyle()); + elements++; + } + // Now do text Properties if necessary if(format.textIsBold()) diff --git a/src/xmlfixups.cpp b/src/xmlfixups.cpp index eb6fcb7..458798a 100644 --- a/src/xmlfixups.cpp +++ b/src/xmlfixups.cpp @@ -42,10 +42,10 @@ #include "tags.h" static const char* kNoDuplicates[] = - { kElB, kElU, kElI, kElFont, kElHide, kElSuper, kElSub, NULL }; + { kElB, kElU, kElI, kElFont, kElHide, kElSuper, kElSub, kElSpan, NULL }; static const char* kRequireAttrs[] = - { kElFont, NULL }; + { kElFont, kElSpan, NULL }; static const char* kRemoveTags[] = { kElDest, kElListdef, kElListtable, kElFontTable, kElFontDef, NULL }; @@ -503,6 +503,17 @@ void XmlFixups::runPassTwo(const DOM::Document& doc) continue; // Current element no longer valid } + else if(name == kElSpan) + { + // Change style attribute on spans to name + if(haveStyles && el.hasAttribute(kElStyle)) + { + DOM::Element style = styles.get(el.getAttribute(kElStyle)); + if(style != NULL) + el.setAttribute(kElStyle, style.getAttribute(kAtName)); + } + } + // Change id attribute on fonts to name if(haveFonts && name == kElFont) { |