# HG changeset patch
# User Michael Stahl <mst@openoffice.org>
# Date 1303140562 0
# Node ID aea559b340040418c909b14aabda490858b4abf0
# Parent  4d286e27d1745f0d9643230acf946dbbe87001f5
rtftok01: writerfilter: support for a stack of RTF groups

diff --git a/writerfilter/source/rtftok/RTFDocumentImpl.cxx b/writerfilter/source/rtftok/RTFDocumentImpl.cxx
--- a/writerfilter/source/rtftok/RTFDocumentImpl.cxx
+++ b/writerfilter/source/rtftok/RTFDocumentImpl.cxx
@@ -293,6 +293,48 @@
 createRootDestination(RTFScannerHandlerImpl &);
 
 
+
+/** RTF Group context.
+ */
+class RTFGroup
+{
+public:
+    /** default ctor for inital Group, copy ctor for the rest */
+    explicit RTFGroup()
+        : m_TextEncoding(osl_getThreadTextEncoding())
+        , m_UnicodeCharacters(1)
+        , m_CharacterProperties()
+    { }
+
+    // general properties
+    rtl_TextEncoding m_TextEncoding;
+    unsigned int m_UnicodeCharacters;
+
+    // character properties
+    class CharacterProperties
+    {
+        public:
+            explicit CharacterProperties()
+                : m_bDefault(true)
+            { }
+            bool m_bDefault;
+    };
+    CharacterProperties m_CharacterProperties;
+
+    void ResetCharacterProperties() {
+        m_CharacterProperties = CharacterProperties();
+    };
+
+    // paragraph properties
+    // section properties
+    // table properties
+
+    void Reset() {
+        ResetCharacterProperties();
+    }
+};
+
+
 static char
 lcl_HexDigit(char const c)
 {
@@ -313,18 +355,18 @@
 public:
     explicit RTFScannerHandlerImpl(Stream & rStream)
         : m_rStream(rStream)
-        , m_TextEncoding(osl_getThreadTextEncoding())
         , m_NegativeCharacters(0)
-        , m_UnicodeCharacters(1)
     {
         m_Destinations.push( ::std::make_pair(0,
             RTFDestination::Pointer_t(createRootDestination(*this))) );
+        m_Groups.push( RTFGroup() ); // dummy group
     }
     virtual ~RTFScannerHandlerImpl() { }
     virtual void dest(char const*const token, char const*const value)
     {
         m_NegativeCharacters = 0;
         checkStrings();
+        m_Groups.push( RTFGroup(m_Groups.top()) ); // copy top of group stack
         RTFDestination::Pointer_t const pDestination(
             m_Destinations.top().second->dest(token, value) );
         OSL_ASSERT(pDestination);
@@ -359,6 +401,7 @@
     {
         m_NegativeCharacters = 0;
         checkStrings();
+        m_Groups.push( RTFGroup(m_Groups.top()) ); // copy top of group stack
         m_Destinations.top().second->lbrace();
         ++m_Destinations.top().first;
     }
@@ -374,6 +417,9 @@
                 m_Destinations.pop();
             }
         }
+        if (m_Groups.size() > 1) {
+            m_Groups.pop();
+        }
     }
     virtual void addSpaces(unsigned int const count)
     {
@@ -408,7 +454,7 @@
         checkString();
         m_UString.append(ch);
         /* don't check if it was 0, right? */
-        m_NegativeCharacters = m_UnicodeCharacters;
+        m_NegativeCharacters = GetCurrentGroup().m_UnicodeCharacters;
     }
     virtual void addHexChar(char const hexch[2])
     {
@@ -417,14 +463,18 @@
     }
     Stream & GetStream() { return m_rStream; }
 
-    rtl_TextEncoding GetEncoding() const { return m_TextEncoding; }
+    RTFGroup      & GetCurrentGroup()       { return m_Groups.top(); }
+    RTFGroup const& GetCurrentGroup() const { return m_Groups.top(); }
+    rtl_TextEncoding GetEncoding() const {
+        return GetCurrentGroup().m_TextEncoding;
+    }
     void SetEncoding(rtl_TextEncoding const e) {
 fprintf(stderr, "RTFScannerHandlerImpl::SetEncoding: %d\n", e);
-        m_TextEncoding = e;
+        GetCurrentGroup().m_TextEncoding = e;
     }
     void SetUnicodeCharacters(unsigned int const uc) {
 fprintf(stderr, "RTFScannerHandlerImpl::SetUnicodeCharacters: %d\n", uc);
-        m_UnicodeCharacters = uc;
+        GetCurrentGroup().m_UnicodeCharacters = uc;
     }
 
 private:
@@ -452,10 +502,9 @@
        to unicode individually (could be mult-byte enconding!) */
     ::rtl::OStringBuffer m_String;
     ::rtl::OUStringBuffer m_UString;
+    unsigned int m_NegativeCharacters;
     ::std::stack< ::std::pair<int, RTFDestination::Pointer_t> > m_Destinations;
-    rtl_TextEncoding m_TextEncoding;
-    unsigned int m_NegativeCharacters;
-    unsigned int m_UnicodeCharacters;
+    ::std::stack< RTFGroup > m_Groups;
 };
 
 
