summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-03-09 15:23:24 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-03-10 10:42:10 +0100
commit20c5a2abb61c4246c6001b7b6d5bd69cd5882cfd (patch)
tree2aa3dd2ff5cb12aa085107b41b043327fa0cb02d /xmloff
parentbfee21b6c87c420e0c5d3447b13e013592a30c22 (diff)
use FastParser in DrawAnnotationContext
Change-Id: I4228a5ccbd738d2e51473ded511cf4bfd2b6617d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90244 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/inc/XMLStringBufferImportContext.hxx13
-rw-r--r--xmloff/source/draw/ximppage.cxx145
-rw-r--r--xmloff/source/text/XMLStringBufferImportContext.cxx33
3 files changed, 134 insertions, 57 deletions
diff --git a/xmloff/inc/XMLStringBufferImportContext.hxx b/xmloff/inc/XMLStringBufferImportContext.hxx
index 6d843a1ca6af..9c607480084f 100644
--- a/xmloff/inc/XMLStringBufferImportContext.hxx
+++ b/xmloff/inc/XMLStringBufferImportContext.hxx
@@ -29,6 +29,8 @@
/**
* Import all text into a string buffer. Paragraph elements (<text:p>)
* are recognized and cause a return character (0x0a) to be added.
+ *
+ * Supports both old and fast-parser.
*/
class XMLStringBufferImportContext final : public SvXMLImportContext
{
@@ -36,13 +38,16 @@ class XMLStringBufferImportContext final : public SvXMLImportContext
public:
-
XMLStringBufferImportContext(
SvXMLImport& rImport,
sal_uInt16 nPrefix,
const OUString& sLocalName,
OUStringBuffer& rBuffer);
+ XMLStringBufferImportContext(
+ SvXMLImport& rImport,
+ OUStringBuffer& rBuffer);
+
virtual ~XMLStringBufferImportContext() override;
virtual SvXMLImportContextRef CreateChildContext(
@@ -54,6 +59,12 @@ public:
const OUString& rChars ) override;
virtual void EndElement() override;
+
+ virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+ sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
+ virtual void SAL_CALL startFastElement( sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
+ virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
+ virtual void SAL_CALL characters(const OUString& rChars) override;
};
#endif
diff --git a/xmloff/source/draw/ximppage.cxx b/xmloff/source/draw/ximppage.cxx
index 5bc4c9a8cc83..c265ef36e519 100644
--- a/xmloff/source/draw/ximppage.cxx
+++ b/xmloff/source/draw/ximppage.cxx
@@ -36,6 +36,7 @@
#include <xmloff/prstylei.hxx>
#include <PropertySetMerger.hxx>
#include <osl/diagnose.h>
+#include <sal/log.hxx>
#include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
#include <xmloff/xmluconv.hxx>
@@ -59,10 +60,13 @@ class DrawAnnotationContext : public SvXMLImportContext
{
public:
- DrawAnnotationContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,const Reference< xml::sax::XAttributeList>& xAttrList, const Reference< XAnnotationAccess >& xAnnotationAccess );
+ DrawAnnotationContext( SvXMLImport& rImport, const Reference< xml::sax::XFastAttributeList>& xAttrList, const Reference< XAnnotationAccess >& xAnnotationAccess );
+ virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+ sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList ) override;
- virtual void EndElement() override;
+ virtual void SAL_CALL startFastElement( sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
+ virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
private:
Reference< XAnnotation > mxAnnotation;
@@ -75,62 +79,85 @@ private:
}
-DrawAnnotationContext::DrawAnnotationContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,const Reference< xml::sax::XAttributeList>& xAttrList, const Reference< XAnnotationAccess >& xAnnotationAccess )
-: SvXMLImportContext( rImport, nPrfx, rLocalName )
+DrawAnnotationContext::DrawAnnotationContext( SvXMLImport& rImport, const Reference< xml::sax::XFastAttributeList>& xAttrList, const Reference< XAnnotationAccess >& xAnnotationAccess )
+: SvXMLImportContext( rImport )
, mxAnnotation( xAnnotationAccess->createAndInsertAnnotation() )
{
- if( mxAnnotation.is() )
- {
- sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
+ if( !mxAnnotation.is() )
+ return;
- RealPoint2D aPosition;
- RealSize2D aSize;
+ RealPoint2D aPosition;
+ RealSize2D aSize;
+
+ sax_fastparser::FastAttributeList *pAttribList =
+ sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
+ for (auto &aIter : *pAttribList)
+ {
+ OUString sValue = aIter.toString();
- for(sal_Int16 i=0; i < nAttrCount; i++)
+ switch( aIter.getToken() )
{
- OUString sValue( xAttrList->getValueByIndex( i ) );
- OUString sAttrName( xAttrList->getNameByIndex( i ) );
- OUString aLocalName;
- switch( GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ) )
+ case XML_ELEMENT(SVG, XML_X):
{
- case XML_NAMESPACE_SVG:
- if( IsXMLToken( aLocalName, XML_X ) )
- {
- sal_Int32 x;
- GetImport().GetMM100UnitConverter().convertMeasureToCore(
- x, sValue);
- aPosition.X = static_cast<double>(x) / 100.0;
- }
- else if( IsXMLToken( aLocalName, XML_Y ) )
- {
- sal_Int32 y;
- GetImport().GetMM100UnitConverter().convertMeasureToCore(
- y, sValue);
- aPosition.Y = static_cast<double>(y) / 100.0;
- }
- else if( IsXMLToken( aLocalName, XML_WIDTH ) )
- {
- sal_Int32 w;
- GetImport().GetMM100UnitConverter().convertMeasureToCore(
- w, sValue);
- aSize.Width = static_cast<double>(w) / 100.0;
- }
- else if( IsXMLToken( aLocalName, XML_HEIGHT ) )
- {
- sal_Int32 h;
- GetImport().GetMM100UnitConverter().convertMeasureToCore(
- h, sValue);
- aSize.Height = static_cast<double>(h) / 100.0;
- }
+ sal_Int32 x;
+ GetImport().GetMM100UnitConverter().convertMeasureToCore(
+ x, sValue);
+ aPosition.X = static_cast<double>(x) / 100.0;
break;
- default:
+ }
+ case XML_ELEMENT(SVG, XML_Y):
+ {
+ sal_Int32 y;
+ GetImport().GetMM100UnitConverter().convertMeasureToCore(
+ y, sValue);
+ aPosition.Y = static_cast<double>(y) / 100.0;
break;
}
- }
+ case XML_ELEMENT(SVG, XML_WIDTH):
+ {
+ sal_Int32 w;
+ GetImport().GetMM100UnitConverter().convertMeasureToCore(
+ w, sValue);
+ aSize.Width = static_cast<double>(w) / 100.0;
+ break;
+ }
+ case XML_ELEMENT(SVG, XML_HEIGHT):
+ {
+ sal_Int32 h;
+ GetImport().GetMM100UnitConverter().convertMeasureToCore(
+ h, sValue);
+ aSize.Height = static_cast<double>(h) / 100.0;
+ }
+ break;
+ default:
+ SAL_WARN("xmloff", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << sValue); }
+ }
+
+ mxAnnotation->setPosition( aPosition );
+ mxAnnotation->setSize( aSize );
+}
- mxAnnotation->setPosition( aPosition );
- mxAnnotation->setSize( aSize );
+css::uno::Reference< css::xml::sax::XFastContextHandler > DrawAnnotationContext::createFastChildContext(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
+{
+ if( mxAnnotation.is() )
+ {
+ if ((nElement & NMSP_MASK) == NAMESPACE_TOKEN(XML_NAMESPACE_DC))
+ {
+ if( (nElement & TOKEN_MASK) == XML_CREATOR )
+ return new XMLStringBufferImportContext(GetImport(), maAuthorBuffer);
+ else if( (nElement & TOKEN_MASK) == XML_DATE )
+ return new XMLStringBufferImportContext(GetImport(), maDateBuffer);
+ }
+ else if ( nElement == XML_ELEMENT(TEXT, XML_SENDER_INITIALS)
+ || nElement == XML_ELEMENT(LO_EXT, XML_SENDER_INITIALS)
+ || nElement == XML_ELEMENT(META, XML_CREATOR_INITIALS))
+ {
+ return new XMLStringBufferImportContext(GetImport(), maInitialsBuffer);
+ }
}
+ return nullptr;
}
SvXMLImportContextRef DrawAnnotationContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
@@ -141,17 +168,14 @@ SvXMLImportContextRef DrawAnnotationContext::CreateChildContext( sal_uInt16 nPre
{
if( XML_NAMESPACE_DC == nPrefix )
{
- if( IsXMLToken( rLocalName, XML_CREATOR ) )
- xContext = new XMLStringBufferImportContext(GetImport(), nPrefix, rLocalName, maAuthorBuffer);
- else if( IsXMLToken( rLocalName, XML_DATE ) )
- xContext = new XMLStringBufferImportContext(GetImport(), nPrefix, rLocalName, maDateBuffer);
+ // handled in createFastChildContext
}
else if (((XML_NAMESPACE_TEXT == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix)
&& IsXMLToken(rLocalName, XML_SENDER_INITIALS))
|| (XML_NAMESPACE_META == nPrefix
&& IsXMLToken(rLocalName, XML_CREATOR_INITIALS)))
{
- xContext = new XMLStringBufferImportContext(GetImport(), nPrefix, rLocalName, maInitialsBuffer);
+ // handled in createFastChildContext
}
else
{
@@ -179,7 +203,12 @@ SvXMLImportContextRef DrawAnnotationContext::CreateChildContext( sal_uInt16 nPre
return xContext;
}
-void DrawAnnotationContext::EndElement()
+void DrawAnnotationContext::startFastElement( sal_Int32 /*nElement*/,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
+{
+}
+
+void DrawAnnotationContext::endFastElement(sal_Int32)
{
if(mxCursor.is())
{
@@ -241,12 +270,17 @@ void SdXMLGenericPageContext::startFastElement( sal_Int32 /*nElement*/, const Re
css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLGenericPageContext::createFastChildContext(
sal_Int32 nElement,
- const Reference< xml::sax::XFastAttributeList>& /*xAttrList*/ )
+ const Reference< xml::sax::XFastAttributeList>& xAttrList )
{
if( nElement == XML_ELEMENT(PRESENTATION, XML_ANIMATIONS) )
{
return new XMLAnimationsContext( GetImport() );
}
+ else if( nElement == XML_ELEMENT(OFFICE, XML_ANNOTATION) || nElement == XML_ELEMENT(OFFICE_EXT, XML_ANNOTATION) )
+ {
+ if( mxAnnotationAccess.is() )
+ return new DrawAnnotationContext( GetImport(), xAttrList, mxAnnotationAccess );
+ }
return nullptr;
}
@@ -267,8 +301,7 @@ SvXMLImportContextRef SdXMLGenericPageContext::CreateChildContext( sal_uInt16 nP
}
else if( ((nPrefix == XML_NAMESPACE_OFFICE) || (nPrefix == XML_NAMESPACE_OFFICE_EXT)) && IsXMLToken( rLocalName, XML_ANNOTATION ) )
{
- if( mxAnnotationAccess.is() )
- xContext = new DrawAnnotationContext( GetImport(), nPrefix, rLocalName, xAttrList, mxAnnotationAccess );
+ // handled in createFastChildContext
}
else
{
diff --git a/xmloff/source/text/XMLStringBufferImportContext.cxx b/xmloff/source/text/XMLStringBufferImportContext.cxx
index bada65a69844..591504e2406b 100644
--- a/xmloff/source/text/XMLStringBufferImportContext.cxx
+++ b/xmloff/source/text/XMLStringBufferImportContext.cxx
@@ -38,10 +38,24 @@ XMLStringBufferImportContext::XMLStringBufferImportContext(
{
}
+XMLStringBufferImportContext::XMLStringBufferImportContext(
+ SvXMLImport& rImport,
+ OUStringBuffer& rBuffer) :
+ SvXMLImportContext(rImport),
+ rTextBuffer(rBuffer)
+{
+}
+
XMLStringBufferImportContext::~XMLStringBufferImportContext()
{
}
+css::uno::Reference< css::xml::sax::XFastContextHandler > XMLStringBufferImportContext::createFastChildContext(
+ sal_Int32 /*nElement*/, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
+{
+ return new XMLStringBufferImportContext(GetImport(), rTextBuffer);
+}
+
SvXMLImportContextRef XMLStringBufferImportContext::CreateChildContext(
sal_uInt16 nPrefix,
const OUString& rLocalName,
@@ -51,12 +65,31 @@ SvXMLImportContextRef XMLStringBufferImportContext::CreateChildContext(
rLocalName, rTextBuffer);
}
+void XMLStringBufferImportContext::characters(const OUString& rChars )
+{
+ rTextBuffer.append(rChars);
+}
+
void XMLStringBufferImportContext::Characters(
const OUString& rChars )
{
rTextBuffer.append(rChars);
}
+void XMLStringBufferImportContext::endFastElement(sal_Int32 nElement)
+{
+ // add return for paragraph elements
+ if ( nElement == XML_ELEMENT(TEXT, XML_P) || nElement == XML_ELEMENT(LO_EXT, XML_P))
+ {
+ rTextBuffer.append(u'\x000a');
+ }
+}
+
+void XMLStringBufferImportContext::startFastElement( sal_Int32 /*nElement*/,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
+{
+}
+
void XMLStringBufferImportContext::EndElement()
{
// add return for paragraph elements