summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorShubham Goyal <22shubh22@gmail.com>2019-07-25 07:56:59 +0530
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2019-08-22 13:45:28 +0200
commit437fe778a81f3c39b8b259acd2d960c285d4f244 (patch)
tree2097fb4382d96889af6f1263e42703b938375822 /xmloff
parentbf1638f8fc629fa211a8c57f962b9a3c4c40152f (diff)
QR Code : ODF import/export
Change-Id: I6c1ae63a89d5ed34d2fa245279d4552949bb64a7 Reviewed-on: https://gerrit.libreoffice.org/74853 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/Library_xo.mk1
-rw-r--r--xmloff/source/core/xmltoken.cxx3
-rw-r--r--xmloff/source/draw/QRCodeContext.cxx95
-rw-r--r--xmloff/source/draw/QRCodeContext.hxx26
-rw-r--r--xmloff/source/draw/shapeexport.cxx43
-rw-r--r--xmloff/source/draw/ximpshap.cxx18
-rw-r--r--xmloff/source/text/XMLTextFrameContext.cxx9
-rw-r--r--xmloff/source/token/tokens.txt3
8 files changed, 197 insertions, 1 deletions
diff --git a/xmloff/Library_xo.mk b/xmloff/Library_xo.mk
index 031e7da6ab5d..0656f8ee2ab0 100644
--- a/xmloff/Library_xo.mk
+++ b/xmloff/Library_xo.mk
@@ -142,6 +142,7 @@ $(eval $(call gb_Library_add_exception_objects,xo,\
xmloff/source/draw/shapeexport \
xmloff/source/draw/shapeimport \
xmloff/source/draw/SignatureLineContext \
+ xmloff/source/draw/QRCodeContext \
xmloff/source/draw/xexptran \
xmloff/source/draw/ximp3dobject \
xmloff/source/draw/ximp3dscene \
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index a8fea52ebbfc..5ce4b8d8f1a5 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -1503,6 +1503,9 @@ namespace xmloff { namespace token {
TOKEN( "punctuation-wrap", XML_PUNCTUATION_WRAP ),
TOKEN( "purple", XML_PURPLE ),
TOKEN( "pyramid", XML_PYRAMID ),
+ TOKEN( "qrcode", XML_QRCODE ),
+ TOKEN( "qrcode-border", XML_QRCODE_BORDER ),
+ TOKEN( "qrcode-errorcorrection", XML_QRCODE_ERROR_CORRECTION ),
TOKEN( "quarter", XML_QUARTER ),
TOKEN( "query-name", XML_QUERY_NAME ),
TOKEN( "quo-vadis", XML_QUO_VADIS ),
diff --git a/xmloff/source/draw/QRCodeContext.cxx b/xmloff/source/draw/QRCodeContext.cxx
new file mode 100644
index 000000000000..bf0f4c0469d2
--- /dev/null
+++ b/xmloff/source/draw/QRCodeContext.cxx
@@ -0,0 +1,95 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#include "QRCodeContext.hxx"
+
+#include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/graphic/XGraphic.hpp>
+#include <com/sun/star/drawing/QRCode.hpp>
+#include <com/sun/star/drawing/QRCodeErrorCorrection.hpp>
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+
+#include <sal/log.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/storagehelper.hxx>
+#include <xmloff/xmltoken.hxx>
+#include <xmloff/xmlimp.hxx>
+#include <xmloff/xmlnmspe.hxx>
+#include <xmloff/xmluconv.hxx>
+#include <xmloff/nmspmap.hxx>
+#include <sax/tools/converter.hxx>
+
+#include <rtl/ustrbuf.hxx>
+#include <rtl/strbuf.hxx>
+#include <rtl/ustring.hxx>
+
+using namespace css;
+using namespace css::xml::sax;
+using namespace css::uno;
+using namespace css::drawing;
+using namespace css::embed;
+using namespace css::frame;
+using namespace css::io;
+using namespace css::graphic;
+using namespace xmloff::token;
+
+QRCodeContext::QRCodeContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,
+ const Reference<XAttributeList>& xAttrList,
+ const Reference<XShape>& rxShape)
+ : SvXMLImportContext(rImport, nPrfx, rLocalName)
+{
+ Reference<beans::XPropertySet> xPropSet(rxShape, UNO_QUERY_THROW);
+
+ css::drawing::QRCode aQRCode;
+ const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
+
+ for (sal_Int16 i = 0; i < nAttrCount; i++)
+ {
+ OUString sAttrName = xAttrList->getNameByIndex(i);
+ OUString aLocalName;
+ sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(sAttrName, &aLocalName);
+ OUString sValue = xAttrList->getValueByIndex(i);
+
+ switch (nPrefix)
+ {
+ case XML_NAMESPACE_LO_EXT:
+ if (IsXMLToken(aLocalName, XML_QRCODE_ERROR_CORRECTION))
+ {
+ OUString aErrorCorrValue = sValue;
+
+ if (aErrorCorrValue == "low")
+ aQRCode.ErrorCorrection = css::drawing::QRCodeErrorCorrection::LOW;
+ else if (aErrorCorrValue == "medium")
+ aQRCode.ErrorCorrection = css::drawing::QRCodeErrorCorrection::MEDIUM;
+ else if (aErrorCorrValue == "quartile")
+ aQRCode.ErrorCorrection = css::drawing::QRCodeErrorCorrection::QUARTILE;
+ else
+ aQRCode.ErrorCorrection = css::drawing::QRCodeErrorCorrection::HIGH;
+ }
+
+ if (IsXMLToken(aLocalName, XML_QRCODE_BORDER))
+ {
+ sax::Converter::convertNumber(aQRCode.Border, sValue, 0);
+ }
+ break;
+
+ case XML_NAMESPACE_OFFICE:
+ if (IsXMLToken(aLocalName, XML_STRING_VALUE))
+ {
+ aQRCode.Payload = sValue;
+ }
+ }
+ }
+ xPropSet->setPropertyValue("QRCodeProperties", Any(aQRCode));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/xmloff/source/draw/QRCodeContext.hxx b/xmloff/source/draw/QRCodeContext.hxx
new file mode 100644
index 000000000000..74709bab40f8
--- /dev/null
+++ b/xmloff/source/draw/QRCodeContext.hxx
@@ -0,0 +1,26 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#pragma once
+
+#include <com/sun/star/drawing/XShape.hpp>
+#include <xmloff/xmlictxt.hxx>
+
+// Used to import QR code properties from a QR code in ODF document
+// @see ximpshap
+
+class QRCodeContext : public SvXMLImportContext
+{
+public:
+ QRCodeContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,
+ const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList,
+ const css::uno::Reference<css::drawing::XShape>& rxShape);
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/xmloff/source/draw/shapeexport.cxx b/xmloff/source/draw/shapeexport.cxx
index 4de9defd61be..e6728b798ecc 100644
--- a/xmloff/source/draw/shapeexport.cxx
+++ b/xmloff/source/draw/shapeexport.cxx
@@ -64,6 +64,8 @@
#include <com/sun/star/drawing/XControlShape.hpp>
#include <com/sun/star/drawing/XCustomShapeEngine.hpp>
#include <com/sun/star/drawing/XGluePointsSupplier.hpp>
+#include <com/sun/star/drawing/QRCode.hpp>
+#include <com/sun/star/drawing/QRCodeErrorCorrection.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
@@ -91,6 +93,8 @@
#include <rtl/math.hxx>
#include <rtl/ustrbuf.hxx>
+#include <rtl/strbuf.hxx>
+#include <rtl/ustring.hxx>
#include <sal/log.hxx>
#include <sax/tools/converter.hxx>
@@ -1285,6 +1289,40 @@ void XMLShapeExport::ImpExportSignatureLine(const uno::Reference<drawing::XShape
true);
}
+void XMLShapeExport::ImpExportQRCode(const uno::Reference<drawing::XShape>& xShape)
+{
+ uno::Reference<beans::XPropertySet> xPropSet(xShape, uno::UNO_QUERY);
+
+ uno::Any aAny = xPropSet->getPropertyValue("QRCodeProperties");
+
+ css::drawing::QRCode aQRCode;
+ if(aAny >>= aQRCode)
+ {
+ mrExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_STRING_VALUE, aQRCode.Payload);
+ /* Export QR Code as per customised schema, @see OpenDocument-schema-v1.3+libreoffice */
+ OUString temp;
+ switch(aQRCode.ErrorCorrection){
+ case css::drawing::QRCodeErrorCorrection::LOW :
+ temp = "low";
+ break;
+ case css::drawing::QRCodeErrorCorrection::MEDIUM:
+ temp = "medium";
+ break;
+ case css::drawing::QRCodeErrorCorrection::QUARTILE:
+ temp = "quartile";
+ break;
+ case css::drawing::QRCodeErrorCorrection::HIGH:
+ temp = "high";
+ break;
+ }
+ mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_QRCODE_ERROR_CORRECTION, temp);
+ mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_QRCODE_BORDER, OUStringBuffer(20).append(aQRCode.Border).makeStringAndClear());
+
+ SvXMLElementExport aQRCodeElement(mrExport, XML_NAMESPACE_LO_EXT, XML_QRCODE, true,
+ true);
+ }
+}
+
void XMLShapeExport::ExportGraphicDefaults()
{
rtl::Reference<XMLStyleExport> aStEx(new XMLStyleExport(mrExport, mrExport.GetAutoStylePool().get()));
@@ -2443,9 +2481,12 @@ void XMLShapeExport::ImpExportGraphicObjectShape(
GetExport().GetImageMapExport().Export( xPropSet );
ImpExportDescription( xShape ); // #i68101#
- // Signature Line - needs to be after the images!
+ // Signature Line, QR Code - needs to be after the images!
if (GetExport().getDefaultVersion() > SvtSaveOptions::ODFVER_012)
+ {
ImpExportSignatureLine(xShape);
+ ImpExportQRCode(xShape);
+ }
}
void XMLShapeExport::ImpExportChartShape(
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
index 56efcdb64b2d..ec3c06ad1db2 100644
--- a/xmloff/source/draw/ximpshap.cxx
+++ b/xmloff/source/draw/ximpshap.cxx
@@ -73,6 +73,7 @@
#include "eventimp.hxx"
#include "descriptionimp.hxx"
#include "SignatureLineContext.hxx"
+#include "QRCodeContext.hxx"
#include "ximpcustomshape.hxx"
#include <XMLEmbeddedObjectImportContext.hxx>
#include <xmloff/xmlerror.hxx>
@@ -191,6 +192,10 @@ SvXMLImportContextRef SdXMLShapeContext::CreateChildContext( sal_uInt16 p_nPrefi
{
xContext = new SignatureLineContext( GetImport(), p_nPrefix, rLocalName, xAttrList, mxShape );
}
+ else if( p_nPrefix == XML_NAMESPACE_LO_EXT && IsXMLToken( rLocalName, XML_QRCODE ) )
+ {
+ xContext = new QRCodeContext( GetImport(), p_nPrefix, rLocalName, xAttrList, mxShape );
+ }
else if( p_nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
{
xContext = new SdXMLEventsContext( GetImport(), p_nPrefix, rLocalName, xAttrList, mxShape );
@@ -3522,6 +3527,19 @@ SvXMLImportContextRef SdXMLFrameShapeContext::CreateChildContext( sal_uInt16 nPr
}
}
}
+ else if ((XML_NAMESPACE_LO_EXT == nPrefix) && IsXMLToken(rLocalName, XML_QRCODE))
+ {
+ SdXMLShapeContext* pSContext = dynamic_cast<SdXMLShapeContext*>(mxImplContext.get());
+ if (pSContext)
+ {
+ uno::Reference<beans::XPropertySet> xPropSet(pSContext->getShape(), uno::UNO_QUERY);
+ if (xPropSet.is())
+ {
+ xContext = new QRCodeContext(GetImport(), nPrefix, rLocalName, xAttrList,
+ pSContext->getShape());
+ }
+ }
+ }
// call parent for content
if (!xContext)
xContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
diff --git a/xmloff/source/text/XMLTextFrameContext.cxx b/xmloff/source/text/XMLTextFrameContext.cxx
index 64704cd9fbc6..3755b3845c03 100644
--- a/xmloff/source/text/XMLTextFrameContext.cxx
+++ b/xmloff/source/text/XMLTextFrameContext.cxx
@@ -1670,6 +1670,15 @@ SvXMLImportContextRef XMLTextFrameContext::CreateChildContext(
}
xContext = m_xImplContext->CreateChildContext(p_nPrefix, rLocalName, xAttrList);
}
+ else if (p_nPrefix == XML_NAMESPACE_LO_EXT && (IsXMLToken(rLocalName, XML_QRCODE)))
+ {
+ if (getSupportsMultipleContents())
+ { // tdf#103567 ensure props are set on surviving shape
+ // note: no more draw:image can be added once we get here
+ m_xImplContext = solveMultipleImages();
+ }
+ xContext = m_xImplContext->CreateChildContext(p_nPrefix, rLocalName, xAttrList);
+ }
else
{
// the child is a drawing shape
diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt
index 82b64bc85642..dbd6f59945b9 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -1421,6 +1421,9 @@ publisher
punctuation-wrap
purple
pyramid
+qrcode
+qrcode-border
+qrcode-errorcorrection
quarter
query-name
quo-vadis