[Libreoffice-commits] core.git: 2 commits - writerfilter/source
Jan Holesovsky
kendy at collabora.com
Thu Aug 7 09:13:46 PDT 2014
writerfilter/source/ooxml/OOXMLFactory.cxx | 140 ++++++++++++++--------------
writerfilter/source/ooxml/factoryimpl_ns.py | 21 ++--
2 files changed, 84 insertions(+), 77 deletions(-)
New commits:
commit 525063f24d2a95bd0ae47780f7e7cb15333f0d33
Author: Jan Holesovsky <kendy at collabora.com>
Date: Thu Aug 7 18:12:12 2014 +0200
writerfilter: Old Python does not know OrderedDict, work that around.
Change-Id: I08fc7ba8e94d3d258f9e00ac45cd1a8a0b6b3ff3
diff --git a/writerfilter/source/ooxml/factoryimpl_ns.py b/writerfilter/source/ooxml/factoryimpl_ns.py
index eee675e..e619ffd 100644
--- a/writerfilter/source/ooxml/factoryimpl_ns.py
+++ b/writerfilter/source/ooxml/factoryimpl_ns.py
@@ -9,7 +9,6 @@
from __future__ import print_function
from xml.dom import minidom
-from collections import OrderedDict
import sys
@@ -127,7 +126,8 @@ def fastToken(attrNode):
def collectAttributeToResource(nsNode, defineNode):
- ret = OrderedDict()
+ ret_dict = {}
+ ret_order = []
defineName = defineNode.getAttribute("name")
for refNode in getChildrenByName(defineNode, "ref"):
refName = refNode.getAttribute("name")
@@ -135,7 +135,9 @@ def collectAttributeToResource(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.update(collectAttributeToResource(nsNode, define))
+ ret = collectAttributeToResource(nsNode, define)
+ ret_dict.update(ret[0])
+ ret_order.extend(ret[1])
attrNodes = defineNode.getElementsByTagName("attribute")
for attrNode in attrNodes:
@@ -147,16 +149,21 @@ def collectAttributeToResource(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[attrToken] = "RT_%s, %s" % (resourceName, refDefine)
+ ret_dict[attrToken] = "RT_%s, %s" % (resourceName, refDefine)
+ ret_order.append(attrToken)
- return ret
+ return [ret_dict, ret_order]
def factoryAttributeToResourceMapInner(nsNode, defineNode):
ret = []
attributes = collectAttributeToResource(nsNode, defineNode)
- for k in attributes.keys():
- ret.append(" { %s, %s }," % (k, attributes[k]))
+ already_used = set()
+ for k in attributes[1]:
+ if not (k in already_used):
+ ret.append(" { %s, %s }," % (k, attributes[0][k]))
+ already_used.add(k)
+
return ret
commit fea94f214e4a8dea58b1c1e3f09cbde339f0465f
Author: Jan Holesovsky <kendy at collabora.com>
Date: Thu Aug 7 15:41:10 2014 +0200
writerfilter: Kill unnecessary indentation (return or continue early).
Change-Id: Iad20b8f9b453d413ce0d249c65b5f44767f0264b
diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx
index 1318c9e..813982d 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.cxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.cxx
@@ -85,84 +85,84 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
Id nDefine = pHandler->getDefine();
OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
- if (pFactory.get() != NULL)
+ if (pFactory.get() == NULL)
+ return;
+
+ assert( dynamic_cast< sax_fastparser::FastAttributeList *>( Attribs.get() ) != NULL );
+ sax_fastparser::FastAttributeList *pAttribs;
+ pAttribs = static_cast< sax_fastparser::FastAttributeList *>( Attribs.get() );
+
+ const AttributeInfo *pAttr = pFactory->getAttributeInfoArray(nDefine);
+ if (!pAttr)
+ return;
+
+ for (; pAttr->m_nToken != -1; ++pAttr)
{
- assert( dynamic_cast< sax_fastparser::FastAttributeList *>( Attribs.get() ) != NULL );
- sax_fastparser::FastAttributeList *pAttribs;
- pAttribs = static_cast< sax_fastparser::FastAttributeList *>( Attribs.get() );
+ sal_Int32 nToken = pAttr->m_nToken;
+ if (!pAttribs->hasAttribute(nToken))
+ continue;
- const AttributeInfo *pAttr = pFactory->getAttributeInfoArray(nDefine);
- if (!pAttr)
- return;
+ Id nId = pFactory->getResourceId(nDefine, nToken);
- for (; pAttr->m_nToken != -1; ++pAttr)
+ switch (pAttr->m_nResource)
{
- sal_Int32 nToken = pAttr->m_nToken;
- if (pAttribs->hasAttribute(nToken))
+ case RT_Boolean:
{
- Id nId = pFactory->getResourceId(nDefine, nToken);
-
- switch (pAttr->m_nResource)
+ const char *pValue = "";
+ pAttribs->getAsChar(nToken, pValue);
+ OOXMLValue::Pointer_t xValue(OOXMLBooleanValue::Create(pValue));
+ pHandler->newProperty(nId, xValue);
+ pFactory->attributeAction(pHandler, nToken, xValue);
+ }
+ break;
+ case RT_String:
+ {
+ OUString aValue(pAttribs->getValue(nToken));
+ OOXMLValue::Pointer_t xValue(new OOXMLStringValue(aValue));
+ pHandler->newProperty(nId, xValue);
+ pFactory->attributeAction(pHandler, nToken, xValue);
+ }
+ break;
+ case RT_Integer:
+ {
+ sal_Int32 nValue;
+ pAttribs->getAsInteger(nToken,nValue);
+ OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue);
+ pHandler->newProperty(nId, xValue);
+ pFactory->attributeAction(pHandler, nToken, xValue);
+ }
+ break;
+ case RT_Hex:
+ {
+ const char *pValue = "";
+ pAttribs->getAsChar(nToken, pValue);
+ OOXMLValue::Pointer_t xValue(new OOXMLHexValue(pValue));
+ pHandler->newProperty(nId, xValue);
+ pFactory->attributeAction(pHandler, nToken, xValue);
+ }
+ break;
+ case RT_UniversalMeasure:
+ {
+ const char *pValue = "";
+ pAttribs->getAsChar(nToken, pValue);
+ OOXMLValue::Pointer_t xValue(new OOXMLUniversalMeasureValue(pValue));
+ pHandler->newProperty(nId, xValue);
+ pFactory->attributeAction(pHandler, nToken, xValue);
+ }
+ break;
+ case RT_List:
+ {
+ sal_uInt32 nValue;
+ if (pFactory->getListValue(pAttr->m_nRef, Attribs->getValue(nToken), nValue))
{
- case RT_Boolean:
- {
- const char *pValue = "";
- pAttribs->getAsChar(nToken, pValue);
- OOXMLValue::Pointer_t xValue(OOXMLBooleanValue::Create(pValue));
- pHandler->newProperty(nId, xValue);
- pFactory->attributeAction(pHandler, nToken, xValue);
- }
- break;
- case RT_String:
- {
- OUString aValue(pAttribs->getValue(nToken));
- OOXMLValue::Pointer_t xValue(new OOXMLStringValue(aValue));
- pHandler->newProperty(nId, xValue);
- pFactory->attributeAction(pHandler, nToken, xValue);
- }
- break;
- case RT_Integer:
- {
- sal_Int32 nValue;
- pAttribs->getAsInteger(nToken,nValue);
- OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue);
- pHandler->newProperty(nId, xValue);
- pFactory->attributeAction(pHandler, nToken, xValue);
- }
- break;
- case RT_Hex:
- {
- const char *pValue = "";
- pAttribs->getAsChar(nToken, pValue);
- OOXMLValue::Pointer_t xValue(new OOXMLHexValue(pValue));
- pHandler->newProperty(nId, xValue);
- pFactory->attributeAction(pHandler, nToken, xValue);
- }
- break;
- case RT_UniversalMeasure:
- {
- const char *pValue = "";
- pAttribs->getAsChar(nToken, pValue);
- OOXMLValue::Pointer_t xValue(new OOXMLUniversalMeasureValue(pValue));
- pHandler->newProperty(nId, xValue);
- pFactory->attributeAction(pHandler, nToken, xValue);
- }
- break;
- case RT_List:
- {
- sal_uInt32 nValue;
- if (pFactory->getListValue(pAttr->m_nRef, Attribs->getValue(nToken), nValue))
- {
- OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue);
- pHandler->newProperty(nId, xValue);
- pFactory->attributeAction(pHandler, nToken, xValue);
- }
- }
- break;
- default:
- break;
+ OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue);
+ pHandler->newProperty(nId, xValue);
+ pFactory->attributeAction(pHandler, nToken, xValue);
}
}
+ break;
+ default:
+ break;
}
}
}
More information about the Libreoffice-commits
mailing list