From 6fab96c700f8a15b486c292e70c8fdb5d31121b2 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Tue, 19 Apr 2005 17:24:24 +0000 Subject: Added support for character styles. --- src/rtfformatting.h | 12 +++++++++--- src/tags.h | 1 + src/xmlcomposer.cpp | 34 ++++++++++++++++++++++++++-------- src/xmlfixups.cpp | 15 +++++++++++++-- 4 files changed, 49 insertions(+), 13 deletions(-) (limited to 'src') 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__ diff --git a/src/tags.h b/src/tags.h index 19792a6..6435383 100644 --- a/src/tags.h +++ b/src/tags.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) { -- cgit v1.2.3