summaryrefslogtreecommitdiff
path: root/sw/source/writerfilter/ooxml/OOXMLFactory.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2024-04-10 16:50:51 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-04-18 09:16:12 +0200
commit828c1999e08c5bfad0a1d0e6e5ab07ee8bbc427e (patch)
tree65dfe08b2f389fd5b6d8a639fda2815815931b2e /sw/source/writerfilter/ooxml/OOXMLFactory.cxx
parent8e86df886f84fe69f13cfc367a5dd843e6ea917c (diff)
move writerfilter inside sw
writerfilter wants to convert incoming RTF and OOXML files into writer's document model. But it currently has to do so by manipulating the limited subset that we expose through the UNO API. This is both slower and less accurate than having access to the full document model. So move it inside, and then we can strip out various hacks, and optimise imports. Change-Id: Ie1114d28130ef5f9a786531bc552cb8ee7768015 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165953 Tested-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw/source/writerfilter/ooxml/OOXMLFactory.cxx')
-rw-r--r--sw/source/writerfilter/ooxml/OOXMLFactory.cxx179
1 files changed, 179 insertions, 0 deletions
diff --git a/sw/source/writerfilter/ooxml/OOXMLFactory.cxx b/sw/source/writerfilter/ooxml/OOXMLFactory.cxx
new file mode 100644
index 000000000000..b11cf07c2900
--- /dev/null
+++ b/sw/source/writerfilter/ooxml/OOXMLFactory.cxx
@@ -0,0 +1,179 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sax/fastattribs.hxx>
+#include "OOXMLFactory.hxx"
+
+namespace writerfilter::ooxml {
+
+using namespace com::sun::star;
+
+
+OOXMLFactory_ns::~OOXMLFactory_ns()
+{
+}
+
+
+void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
+ const uno::Reference< xml::sax::XFastAttributeList > & xAttribs)
+{
+ Id nDefine = pHandler->getDefine();
+ OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
+
+ if (!pFactory)
+ return;
+
+ sax_fastparser::FastAttributeList& rAttribs =
+ sax_fastparser::castToFastAttributeList( xAttribs );
+
+ const AttributeInfo *pAttr = pFactory->getAttributeInfoArray(nDefine);
+ if (!pAttr)
+ return;
+
+ for (; pAttr->m_nToken != -1; ++pAttr)
+ {
+ sal_Int32 nToken = pAttr->m_nToken;
+ sal_Int32 nAttrIndex = rAttribs.getAttributeIndex(nToken);
+ if (nAttrIndex == -1)
+ continue;
+
+ Id nId = pFactory->getResourceId(nDefine, nToken);
+
+ OOXMLValue::Pointer_t xValue;
+ switch (pAttr->m_nResource)
+ {
+ case ResourceType::Boolean:
+ xValue = OOXMLBooleanValue::Create(rAttribs.getAsViewByIndex(nAttrIndex));
+ break;
+ case ResourceType::String:
+ xValue = new OOXMLStringValue(rAttribs.getValueByIndex(nAttrIndex));
+ break;
+ case ResourceType::Integer:
+ xValue = OOXMLIntegerValue::Create(rAttribs.getAsIntegerByIndex(nAttrIndex));
+ break;
+ case ResourceType::Hex:
+ xValue = new OOXMLHexValue(rAttribs.getAsViewByIndex(nAttrIndex));
+ break;
+ case ResourceType::HexColor:
+ xValue = new OOXMLHexColorValue(rAttribs.getAsViewByIndex(nAttrIndex));
+ break;
+ case ResourceType::TwipsMeasure_asSigned:
+ case ResourceType::TwipsMeasure_asZero:
+ xValue = new OOXMLTwipsMeasureValue(rAttribs.getAsViewByIndex(nAttrIndex));
+ if (xValue->getInt() < 0)
+ {
+ if (pAttr->m_nResource == ResourceType::TwipsMeasure_asZero)
+ xValue = OOXMLIntegerValue::Create(0);
+ }
+ break;
+ case ResourceType::HpsMeasure:
+ xValue = new OOXMLHpsMeasureValue(rAttribs.getAsViewByIndex(nAttrIndex));
+ break;
+ case ResourceType::MeasurementOrPercent:
+ xValue = new OOXMLMeasurementOrPercentValue(rAttribs.getAsViewByIndex(nAttrIndex));
+ break;
+ case ResourceType::List:
+ if (sal_uInt32 nValue;
+ pFactory->getListValue(pAttr->m_nRef, rAttribs.getAsViewByIndex(nAttrIndex), nValue))
+ {
+ xValue = OOXMLIntegerValue::Create(nValue);
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (xValue)
+ {
+ pHandler->newProperty(nId, xValue);
+ pFactory->attributeAction(pHandler, nToken, xValue);
+ }
+ }
+}
+
+uno::Reference< xml::sax::XFastContextHandler>
+OOXMLFactory::createFastChildContext(OOXMLFastContextHandler * pHandler,
+ Token_t Element)
+{
+ Id nDefine = pHandler->getDefine();
+
+ OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
+
+ uno::Reference< xml::sax::XFastContextHandler> ret;
+
+ //Avoid handling unknown tokens and recursing to death
+ if ((Element & 0xffff) < oox::XML_TOKEN_COUNT)
+ ret = createFastChildContextFromFactory(pHandler, pFactory, Element);
+
+ return ret;
+}
+
+void OOXMLFactory::characters(OOXMLFastContextHandler * pHandler,
+ const OUString & rString)
+{
+ Id nDefine = pHandler->getDefine();
+ OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
+
+ if (pFactory)
+ {
+ pFactory->charactersAction(pHandler, rString);
+ }
+}
+
+void OOXMLFactory::startAction(OOXMLFastContextHandler * pHandler)
+{
+ Id nDefine = pHandler->getDefine();
+ OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
+
+ if (pFactory)
+ {
+ pFactory->startAction(pHandler);
+ }
+}
+
+void OOXMLFactory::endAction(OOXMLFastContextHandler * pHandler)
+{
+ Id nDefine = pHandler->getDefine();
+ OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
+
+ if (pFactory)
+ {
+ pFactory->endAction(pHandler);
+ }
+}
+
+void OOXMLFactory_ns::startAction(OOXMLFastContextHandler *)
+{
+}
+
+void OOXMLFactory_ns::endAction(OOXMLFastContextHandler *)
+{
+}
+
+void OOXMLFactory_ns::charactersAction(OOXMLFastContextHandler *, const OUString &)
+{
+}
+
+void OOXMLFactory_ns::attributeAction(OOXMLFastContextHandler *, Token_t, const OOXMLValue::Pointer_t&)
+{
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */