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

David Tardon dtardon at redhat.com
Sun Aug 3 00:55:23 PDT 2014


 writerfilter/CustomTarget_source.mk         |    5 ++
 writerfilter/source/ooxml/OOXMLFactory.cxx  |   16 ++++++-
 writerfilter/source/ooxml/OOXMLFactory.hxx  |   10 +++-
 writerfilter/source/ooxml/factory_ns.py     |    2 
 writerfilter/source/ooxml/factory_values.py |   59 ++++++++++++++++++++++++++++
 writerfilter/source/ooxml/factoryimpl_ns.py |   27 +++++++-----
 6 files changed, 101 insertions(+), 18 deletions(-)

New commits:
commit 6528607d34c9a2098ff5eec051fc9299ec37dfd7
Author: David Tardon <dtardon at redhat.com>
Date:   Sun Aug 3 09:51:49 2014 +0200

    Revert "writerfilter: Kill ListValueMap(s) & their construction."
    
    Apparently there can be much more than "just a few values" in some cases
    (186 in OOXMLFactory_dml_shapeGeometry::getListValue) and MSVC compiler
    cannot handle if statement that deeply nested.
    
    This reverts commit 7aa7047eb48e81bc0b32448ff0487c993fe9a4db.
    
    Change-Id: I2b4d166e73ce1e616fea81fcfcfc9915c5784d30

diff --git a/writerfilter/CustomTarget_source.mk b/writerfilter/CustomTarget_source.mk
index 10d74a7..6ff9c09 100644
--- a/writerfilter/CustomTarget_source.mk
+++ b/writerfilter/CustomTarget_source.mk
@@ -68,6 +68,7 @@ writerfilter_GEN_ooxml_NamespaceIds_hxx=$(writerfilter_WORK)/ooxml/OOXMLnamespac
 writerfilter_GEN_ooxml_QNameToStr_cxx=$(writerfilter_WORK)/ooxml/qnametostr.cxx
 writerfilter_GEN_ooxml_ResourceIds_hxx=$(writerfilter_WORK)/ooxml/resourceids.hxx
 writerfilter_GEN_ooxml_Token_xml=$(writerfilter_WORK)/ooxml/token.xml
+writerfilter_SRC_ooxml_FactoryValues_py=$(writerfilter_SRC)/ooxml/factory_values.py
 writerfilter_SRC_ooxml_FastTokens_py=$(writerfilter_SRC)/ooxml/fasttokens.py
 writerfilter_SRC_ooxml_GperfFastTokenHandler_py=$(writerfilter_SRC)/ooxml/gperffasttokenhandler.py
 writerfilter_SRC_ooxml_Model=$(writerfilter_SRC)/ooxml/model.xml
@@ -83,6 +84,10 @@ $(writerfilter_GEN_ooxml_Factory_hxx) : $(writerfilter_SRC)/ooxml/factoryinc.py
 	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1)
 	$(call gb_Helper_abbreviate_dirs, $(writerfilter_PYTHONCOMMAND) $< $(writerfilter_GEN_ooxml_Model_processed)) > $@
 
+$(writerfilter_GEN_ooxml_FactoryValues_hxx) : $(writerfilter_SRC_ooxml_FactoryValues_py) $(writerfilter_GEN_ooxml_Model_processed)
+	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1)
+	$(call gb_Helper_abbreviate_dirs, $(writerfilter_PYTHONCOMMAND) $(writerfilter_SRC_ooxml_FactoryValues_py) $(writerfilter_GEN_ooxml_Model_processed)) > $@
+
 $(writerfilter_GEN_ooxml_FastTokens_hxx) : $(writerfilter_SRC_ooxml_FastTokens_py) $(writerfilter_GEN_ooxml_Token_xml) | $(writerfilter_WORK)/ooxml/.dir
 	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1)
 	$(call gb_Helper_abbreviate_dirs, $(writerfilter_PYTHONCOMMAND) $(writerfilter_SRC_ooxml_FastTokens_py) $(writerfilter_GEN_ooxml_Token_xml)) > $@
diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx
index 5f8512f..afdadf1 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.cxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.cxx
@@ -62,6 +62,14 @@ AttributeToResourceMapPointer OOXMLFactory_ns::getAttributeToResourceMap(Id nId)
     return m_AttributesMap[nId];
 }
 
+ListValueMapPointer OOXMLFactory_ns::getListValueMap(Id nId)
+{
+    if (m_ListValuesMap.find(nId) == m_ListValuesMap.end())
+        m_ListValuesMap[nId] = createListValueMap(nId);
+
+    return m_ListValuesMap[nId];
+}
+
 CreateElementMapPointer OOXMLFactory_ns::getCreateElementMap(Id nId)
 {
     if (m_CreateElementsMap.find(nId) == m_CreateElementsMap.end())
@@ -183,9 +191,13 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
                     break;
                 case RT_List:
                     {
-                        sal_uInt32 nValue;
-                        if (pFactory->getListValue(aIt->second.m_nRef, Attribs->getValue(nToken), nValue))
+                        ListValueMapPointer pListValueMap =
+                            pFactory->getListValueMap(aIt->second.m_nRef);
+
+                        if (pListValueMap.get() != NULL)
                         {
+                            OUString aValue(Attribs->getValue(nToken));
+                            sal_uInt32 nValue = (*pListValueMap)[aValue];
                             OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue);
                             pHandler->newProperty(nId, xValue);
                             pFactory->attributeAction(pHandler, nToken, xValue);
diff --git a/writerfilter/source/ooxml/OOXMLFactory.hxx b/writerfilter/source/ooxml/OOXMLFactory.hxx
index 6167290..76676ac 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.hxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.hxx
@@ -70,6 +70,10 @@ typedef boost::unordered_map<Token_t, AttributeInfo> AttributeToResourceMap;
 typedef boost::shared_ptr<AttributeToResourceMap> AttributeToResourceMapPointer;
 typedef boost::unordered_map<Id, AttributeToResourceMapPointer> AttributesMap;
 
+typedef boost::unordered_map<OUString, sal_Int32, OUStringHash> ListValueMap;
+typedef boost::shared_ptr<ListValueMap> ListValueMapPointer;
+typedef boost::unordered_map<Id, ListValueMapPointer> ListValuesMap;
+
 struct CreateElement
 {
     ResourceType_t m_nResource;
@@ -102,6 +106,7 @@ public:
 #endif
 
     AttributeToResourceMapPointer getAttributeToResourceMap(Id nId);
+    ListValueMapPointer getListValueMap(Id nId);
     CreateElementMapPointer getCreateElementMap(Id nId);
     TokenToIdMapPointer getTokenToIdMap(Id nId);
 
@@ -109,15 +114,14 @@ protected:
     virtual ~OOXMLFactory_ns();
 
     AttributesMap m_AttributesMap;
+    ListValuesMap m_ListValuesMap;
     CreateElementsMap m_CreateElementsMap;
     TokenToIdsMap m_TokenToIdsMap;
 
     virtual AttributeToResourceMapPointer createAttributeToResourceMap(Id nId) = 0;
+    virtual ListValueMapPointer createListValueMap(Id nId) = 0;
     virtual CreateElementMapPointer createCreateElementMap(Id nId) = 0;
     virtual TokenToIdMapPointer createTokenToIdMap(Id nId) = 0;
-
-public:
-    virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue) = 0;
 };
 
 class OOXMLFactory
diff --git a/writerfilter/source/ooxml/factory_ns.py b/writerfilter/source/ooxml/factory_ns.py
index 4ccbf3c..991d23a 100644
--- a/writerfilter/source/ooxml/factory_ns.py
+++ b/writerfilter/source/ooxml/factory_ns.py
@@ -36,7 +36,7 @@ public:
     static Pointer_t getInstance();
 
     virtual AttributeToResourceMapPointer createAttributeToResourceMap(Id nId);
-    virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue);
+    virtual ListValueMapPointer createListValueMap(Id nId);
     virtual CreateElementMapPointer createCreateElementMap(Id nId);
     virtual TokenToIdMapPointer createTokenToIdMap(Id nId);
 #ifdef DEBUG_DOMAINMAPPER
diff --git a/writerfilter/source/ooxml/factory_values.py b/writerfilter/source/ooxml/factory_values.py
new file mode 100644
index 0000000..1279e9d
--- /dev/null
+++ b/writerfilter/source/ooxml/factory_values.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+from __future__ import print_function
+import xml.sax
+import string
+import sys
+
+
+class ContentHandler(xml.sax.handler.ContentHandler):
+    def __init__(self):
+        self.inValue = False
+        self.defines = []
+        self.chars = []
+
+    def __escape(self, name):
+        return name.replace('-', 'm').replace('+', 'p').replace(' ', '_').replace(',', '_')
+
+    def startDocument(self):
+        print('''
+#ifndef INCLUDED_FACTORY_VALUES
+#include <rtl/ustring.hxx>
+
+#define OOXMLValueString_ ""''')
+
+    def endDocument(self):
+        print("""
+#endif // INCLUDED_FACTORY_VALUES""")
+
+    def startElement(self, name, attrs):
+        if name == "value":
+            self.inValue = True
+
+    def endElement(self, name):
+        if name == "value":
+            self.inValue = False
+            characters = "".join(self.chars)
+            self.chars = []
+            if len(characters):
+                define = '#define OOXMLValueString_%s "%s"' % (self.__escape(characters), characters)
+                if not define in self.defines:
+                    self.defines.append(define)
+                    print(define)
+
+    def characters(self, chars):
+        if self.inValue:
+            self.chars.append(chars)
+
+parser = xml.sax.make_parser()
+parser.setContentHandler(ContentHandler())
+parser.parse(sys.argv[1])
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/writerfilter/source/ooxml/factoryimpl_ns.py b/writerfilter/source/ooxml/factoryimpl_ns.py
index 6fc9550..687814d 100644
--- a/writerfilter/source/ooxml/factoryimpl_ns.py
+++ b/writerfilter/source/ooxml/factoryimpl_ns.py
@@ -178,7 +178,7 @@ def factoryAttributeToResourceMap(nsNode):
     print()
 
 
-# factoryGetListValue
+# factoryListValueMap
 
 
 def idToLabel(idName):
@@ -193,33 +193,28 @@ def valueToLabel(value):
     return value.replace('-', 'm').replace('+', 'p').replace(' ', '_').replace(',', '_')
 
 
-def factoryGetListValue(nsNode):
-    print("""bool OOXMLFactory_%s::getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue)
+def factoryListValueMap(nsNode):
+    print("""ListValueMapPointer OOXMLFactory_%s::createListValueMap(Id nId)
 {
-    (void) rValue;
-    (void) rOutValue;
+    ListValueMapPointer pMap(new ListValueMap());
 
     switch (nId)
     {""" % nsToLabel(nsNode))
 
     for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("resource") == "List"]:
         print("    case %s:" % idForDefine(nsNode, resourceNode))
-        output_else = ""
         for valueNode in getChildrenByName(resourceNode, "value"):
             valueData = ""
             if len(valueNode.childNodes):
                 valueData = valueNode.childNodes[0].data
-            print("        %sif (rValue == \"%s\") { rOutValue = %s; }" % (output_else, valueData, idToLabel(valueNode.getAttribute("tokenid"))))
-            output_else = "else "
-        print("        %s{ return false; }" % (output_else))
-        print("        return true;")
+            print("        (*pMap)[OOXMLValueString_%s] = %s;" % (valueToLabel(valueData), idToLabel(valueNode.getAttribute("tokenid"))))
         print("        break;")
 
     print("""    default:
         break;
     }
 
-    return false;
+    return pMap;
 }""")
 
 
@@ -348,6 +343,13 @@ def charactersActionForValues(nsNode, refNode):
             if dataNode.getAttribute("type") == "int":
                 ret.append("    OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(sText));")
                 ret.append("    pValueHandler->setValue(pValue);")
+            elif dataNode.getAttribute("type") == "list":
+                ret.append("    ListValueMapPointer pListValueMap = getListValueMap(nDefine);")
+                ret.append("    if (pListValueMap.get() != NULL)")
+                ret.append("    {")
+                ret.append("        OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue((*pListValueMap)[sText]));")
+                ret.append("        pValueHandler->setValue(pValue);")
+                ret.append("    }")
         ret.append("    }")
 
     return ret
@@ -644,6 +646,7 @@ def getChildrenByName(parentNode, childName):
 def createImpl(modelNode, nsName):
     print("""
 #include "ooxml/resourceids.hxx"
+#include "OOXMLFactory_values.hxx"
 #include "OOXMLFactory_%s.hxx"
 #include "ooxml/OOXMLFastHelper.hxx"
 
@@ -670,7 +673,7 @@ namespace ooxml {
         factoryDestructor(nsLabel)
         factoryGetInstance(nsLabel)
         factoryAttributeToResourceMap(nsNode)
-        factoryGetListValue(nsNode)
+        factoryListValueMap(nsNode)
         factoryCreateElementMap(files, nsNode)
         factoryActions(nsNode)
         factoryGetDefineName(nsNode)


More information about the Libreoffice-commits mailing list