[Libreoffice-commits] core.git: 3 commits - writerfilter/source

Jan Holesovsky kendy at collabora.com
Thu Aug 7 06:22:08 PDT 2014


 writerfilter/source/dmapper/ThemeTable.cxx         |    4 +-
 writerfilter/source/ooxml/OOXMLFactory.cxx         |   35 ++++----------------
 writerfilter/source/ooxml/OOXMLFactory.hxx         |   14 +-------
 writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx |   16 ---------
 writerfilter/source/ooxml/factory_ns.py            |    2 -
 writerfilter/source/ooxml/factoryimpl_ns.py        |   36 +++++++++++++--------
 6 files changed, 38 insertions(+), 69 deletions(-)

New commits:
commit 617623fb783d6588a2999cae978ee9bb147e3847
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Aug 7 12:51:24 2014 +0200

    Revert "ugly hack for NS_ooxml::LN_CT_Style_type being the first attribute...
    
    I believe this is not necessary after the recent removal of unordered_map from
    handling the attributes.
    
    This reverts commit 76336334e669519cfa42413b851584fa321c004d.
    
    Change-Id: I631bc2613954953a30448dbe2a5bf564c529e2a0

diff --git a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
index 902d5a7..3a6b1be 100644
--- a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
@@ -23,7 +23,6 @@
 #include <resourcemodel/QNameToString.hxx>
 #include <com/sun/star/drawing/XShape.hpp>
 #include <oox/token/tokens.hxx>
-#include <ooxml/resourceids.hxx>
 
 namespace writerfilter {
 namespace ooxml
@@ -471,20 +470,7 @@ void OOXMLPropertySetImpl::add(OOXMLProperty::Pointer_t pProperty)
 {
     if (pProperty.get() != NULL && pProperty->getId() != 0x0)
     {
-        /*
-         HACK: Ugly hack. This retarded overdesigned writerfilter thing
-         processes attributes in random order (as given by boost::unordered_map
-         when iterating it), but StyleSheetTable::lcl_attribute() needs
-         to know whether NS_ooxml::LN_CT_Style_type is STYLE_TYPE_TABLE first.
-         And all this overdesigned machinery doesn't even give a reasonable
-         way to find out if an attribute is there before encountering it
-         in random order in lcl_attribute(), so just make sure here that
-         the attribute comes first.
-        */
-        if( pProperty->getId() == NS_ooxml::LN_CT_Style_type )
-            mProperties.insert( mProperties.begin(), pProperty );
-        else
-            mProperties.push_back(pProperty);
+        mProperties.push_back(pProperty);
     }
 }
 
commit 00db42fec1056999e8aaa5a5cd671ecb7f89c57a
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Aug 7 12:30:13 2014 +0200

    writerfilter: This depended on the order of attributes.
    
    This code actually worked by mistake, thanks to the wrong ordering of
    attributes that was caused by the usage of the boost::unordered_map.
    
    Change-Id: I72cc5b54496b03183987d4d004f985d368e63deb

diff --git a/writerfilter/source/dmapper/ThemeTable.cxx b/writerfilter/source/dmapper/ThemeTable.cxx
index 7817175..68efb48 100644
--- a/writerfilter/source/dmapper/ThemeTable.cxx
+++ b/writerfilter/source/dmapper/ThemeTable.cxx
@@ -112,8 +112,10 @@ void ThemeTable::lcl_sprm(Sprm& rSprm)
     dmapper_logger->chars(rSprm.toString());
 #endif
 
-    sal_uInt32 nSprmId = rSprm.getId();
+    m_pImpl->m_supplementalFontName = "";
+    m_pImpl->m_supplementalFontId = 0;
 
+    sal_uInt32 nSprmId = rSprm.getId();
     switch(nSprmId)
     {
     case NS_ooxml::LN_CT_BaseStyles_fontScheme:
commit 345a3a394e082595924bf219796627f6c00ae2dd
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Aug 7 08:27:45 2014 +0200

    writerfilter: Kill AttributeToResourceMap.
    
    IMPORTANT: From now on, the order of attributes becomes stable, based on the
    order in model.xml (not on implementation details of unordered_map), and the
    code that handles attributes may depend on a particular order.  If you want to
    change the order how the attributes are handled, change model.xml, and check
    you achieved what you wanted in the generated ::getAttributeInfoArray()'s.
    
    [Writerfilter loses another 250k (stripped dbgutil).  And the usage of
    unordered_map here was just completely bogus from the very beginning, as it
    was only iterated as a normal array anyway ;-)]
    
    Change-Id: Ic70c37793e313c4ccda1d6f374cc2d366307ba1b

diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx
index 75bee97..1318c9e 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.cxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.cxx
@@ -30,16 +30,6 @@ namespace ooxml {
 
 using namespace com::sun::star;
 
-AttributeInfo::AttributeInfo()
-:m_nResource(RT_NoResource), m_nRef(0)
-{
-}
-
-AttributeInfo::AttributeInfo(ResourceType_t nResource, Id nRef)
- :m_nResource(nResource), m_nRef(nRef)
-{
-}
-
 CreateElement::CreateElement()
 :m_nResource(RT_NoResource), m_nId(0)
 {
@@ -56,14 +46,6 @@ OOXMLFactory_ns::~OOXMLFactory_ns()
 {
 }
 
-AttributeToResourceMapPointer OOXMLFactory_ns::getAttributeToResourceMap(Id nId)
-{
-    if (m_AttributesMap.find(nId) == m_AttributesMap.end())
-        m_AttributesMap[nId] = createAttributeToResourceMap(nId);
-
-    return m_AttributesMap[nId];
-}
-
 CreateElementMapPointer OOXMLFactory_ns::getCreateElementMap(Id nId)
 {
     if (m_CreateElementsMap.find(nId) == m_CreateElementsMap.end())
@@ -105,23 +87,22 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
 
     if (pFactory.get() != NULL)
     {
-        AttributeToResourceMapPointer pMap = pFactory->getAttributeToResourceMap(nDefine);
-
-        AttributeToResourceMap::const_iterator aIt;
-        AttributeToResourceMap::const_iterator aEndIt = pMap->end();
-
         assert( dynamic_cast< sax_fastparser::FastAttributeList *>( Attribs.get() ) != NULL );
         sax_fastparser::FastAttributeList *pAttribs;
         pAttribs = static_cast< sax_fastparser::FastAttributeList *>( Attribs.get() );
 
-        for (aIt = pMap->begin(); aIt != aEndIt; ++aIt)
+        const AttributeInfo *pAttr = pFactory->getAttributeInfoArray(nDefine);
+        if (!pAttr)
+            return;
+
+        for (; pAttr->m_nToken != -1; ++pAttr)
         {
-            sal_Int32 nToken = aIt->first;
+            sal_Int32 nToken = pAttr->m_nToken;
             if (pAttribs->hasAttribute(nToken))
             {
                 Id nId = pFactory->getResourceId(nDefine, nToken);
 
-                switch (aIt->second.m_nResource)
+                switch (pAttr->m_nResource)
                 {
                 case RT_Boolean:
                     {
@@ -170,7 +151,7 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
                 case RT_List:
                     {
                         sal_uInt32 nValue;
-                        if (pFactory->getListValue(aIt->second.m_nRef, Attribs->getValue(nToken), nValue))
+                        if (pFactory->getListValue(pAttr->m_nRef, Attribs->getValue(nToken), nValue))
                         {
                             OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue);
                             pHandler->newProperty(nId, xValue);
diff --git a/writerfilter/source/ooxml/OOXMLFactory.hxx b/writerfilter/source/ooxml/OOXMLFactory.hxx
index f171b70..67a3e95 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.hxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.hxx
@@ -59,17 +59,11 @@ enum ResourceType_t {
 
 struct AttributeInfo
 {
+    Token_t m_nToken;
     ResourceType_t m_nResource;
     Id m_nRef;
-
-    AttributeInfo(ResourceType_t nResource, Id nRef);
-    AttributeInfo();
 };
 
-typedef boost::unordered_map<Token_t, AttributeInfo> AttributeToResourceMap;
-typedef boost::shared_ptr<AttributeToResourceMap> AttributeToResourceMapPointer;
-typedef boost::unordered_map<Id, AttributeToResourceMapPointer> AttributesMap;
-
 struct CreateElement
 {
     ResourceType_t m_nResource;
@@ -82,8 +76,6 @@ struct CreateElement
 typedef boost::unordered_map<Token_t, CreateElement> CreateElementMap;
 typedef boost::shared_ptr<CreateElementMap> CreateElementMapPointer;
 typedef boost::unordered_map<Id, CreateElementMapPointer> CreateElementsMap;
-typedef boost::unordered_map<Id, std::string> IdToStringMap;
-typedef boost::shared_ptr<IdToStringMap> IdToStringMapPointer;
 
 class OOXMLFactory_ns {
 public:
@@ -94,21 +86,19 @@ public:
     virtual void endAction(OOXMLFastContextHandler * pHandler);
     virtual void attributeAction(OOXMLFastContextHandler * pHandler, Token_t nToken, OOXMLValue::Pointer_t pValue);
 
-    AttributeToResourceMapPointer getAttributeToResourceMap(Id nId);
     CreateElementMapPointer getCreateElementMap(Id nId);
 
 protected:
     virtual ~OOXMLFactory_ns();
 
-    AttributesMap m_AttributesMap;
     CreateElementsMap m_CreateElementsMap;
 
-    virtual AttributeToResourceMapPointer createAttributeToResourceMap(Id nId) = 0;
     virtual CreateElementMapPointer createCreateElementMap(Id nId) = 0;
 
 public:
     virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue) = 0;
     virtual Id getResourceId(Id nDefine, sal_Int32 nToken) = 0;
+    virtual const AttributeInfo* getAttributeInfoArray(Id nId) = 0;
 };
 
 class OOXMLFactory
diff --git a/writerfilter/source/ooxml/factory_ns.py b/writerfilter/source/ooxml/factory_ns.py
index 2ab8889..f275ed4 100644
--- a/writerfilter/source/ooxml/factory_ns.py
+++ b/writerfilter/source/ooxml/factory_ns.py
@@ -35,7 +35,7 @@ public:
 
     static Pointer_t getInstance();
 
-    virtual AttributeToResourceMapPointer createAttributeToResourceMap(Id nId);
+    virtual const AttributeInfo* getAttributeInfoArray(Id nId);
     virtual CreateElementMapPointer createCreateElementMap(Id nId);
     virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue);
     virtual Id getResourceId(Id nDefine, sal_Int32 nToken);
diff --git a/writerfilter/source/ooxml/factoryimpl_ns.py b/writerfilter/source/ooxml/factoryimpl_ns.py
index 5263d9f..eee675e 100644
--- a/writerfilter/source/ooxml/factoryimpl_ns.py
+++ b/writerfilter/source/ooxml/factoryimpl_ns.py
@@ -9,6 +9,7 @@
 
 from __future__ import print_function
 from xml.dom import minidom
+from collections import OrderedDict
 import sys
 
 
@@ -125,8 +126,8 @@ def fastToken(attrNode):
     return "".join(ret)
 
 
-def factoryAttributeToResourceMapInner(nsNode, defineNode):
-    ret = []
+def collectAttributeToResource(nsNode, defineNode):
+    ret = OrderedDict()
     defineName = defineNode.getAttribute("name")
     for refNode in getChildrenByName(defineNode, "ref"):
         refName = refNode.getAttribute("name")
@@ -134,13 +135,11 @@ def factoryAttributeToResourceMapInner(nsNode, defineNode):
         if parent.localName in ("element", "attribute"):
             continue
         for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]:
-            ret.extend(factoryAttributeToResourceMapInner(nsNode, define))
+            ret.update(collectAttributeToResource(nsNode, define))
 
     attrNodes = defineNode.getElementsByTagName("attribute")
     for attrNode in attrNodes:
         attrToken = fastToken(attrNode)
-        if attrNode == attrNodes[0]:
-            ret.append("      // %s" % defineName)
         resourceName = resourceForAttribute(nsNode, attrNode)
         refDefine = "0"
         if len(resourceName):
@@ -148,32 +147,42 @@ def factoryAttributeToResourceMapInner(nsNode, defineNode):
                 refName = refNode.getAttribute("name")
                 for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]:
                     refDefine = idForDefine(nsNode, define)
-            ret.append("        (*pMap)[%s] = AttributeInfo(RT_%s, %s);" % (attrToken, resourceName, refDefine))
-        else:
-            ret.append("      // empty resource: %s" % fastToken(attrNode))
+            ret[attrToken] = "RT_%s, %s" % (resourceName, refDefine)
+
+    return ret
+
 
+def factoryAttributeToResourceMapInner(nsNode, defineNode):
+    ret = []
+    attributes = collectAttributeToResource(nsNode, defineNode)
+    for k in attributes.keys():
+        ret.append("                { %s, %s }," % (k, attributes[k]))
     return ret
 
 
 def factoryAttributeToResourceMap(nsNode):
-    print("""AttributeToResourceMapPointer OOXMLFactory_%s::createAttributeToResourceMap(Id nId)
+    print("""const AttributeInfo* OOXMLFactory_%s::getAttributeInfoArray(Id nId)
 {
-    AttributeToResourceMapPointer pMap(new AttributeToResourceMap());
-
     switch (nId)
     {""" % nsToLabel(nsNode))
     for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"):
         inner = "\n".join(factoryAttributeToResourceMapInner(nsNode, defineNode))
         if len(inner):
             print("    case %s:" % idForDefine(nsNode, defineNode))
+            print("        {")
+            print("            const static AttributeInfo info[] = {")
             print(inner)
+            print("                { -1, RT_NoResource, 0 }")
+            print("            };")
+            print("            return info;")
+            print("        }")
             print("        break;")
 
     print("""    default:
         break;
     }
 
-    return pMap;
+    return NULL;
 }""")
     print()
 
@@ -250,7 +259,8 @@ def factoryGetListValue(nsNode):
     }
 
     return false;
-}""")
+}
+""")
 
 
 # factoryCreateElementMap


More information about the Libreoffice-commits mailing list