[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - include/oox oox/source
Sarper Akdemir (via logerrit)
logerrit at kemper.freedesktop.org
Wed Jun 23 21:33:03 UTC 2021
include/oox/export/drawingml.hxx | 13 ++++++-
include/oox/export/shapes.hxx | 2 -
oox/source/export/drawingml.cxx | 67 ++++++++++++++++++++++++++++++++++-----
oox/source/export/shapes.cxx | 4 +-
4 files changed, 73 insertions(+), 13 deletions(-)
New commits:
commit b4e3b505f4b5c3dc62df1ad9ed683512a6765acc
Author: Sarper Akdemir <sarper.akdemir at collabora.com>
AuthorDate: Wed Jun 9 07:58:44 2021 +0300
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Jun 23 23:32:17 2021 +0200
tdf#59323: pptx export: add initial support for lstStyles in textboxes
Adds initial support for writing lstStyles that are specific to a shape.
Current implementation only writes first paragraph and first textruns properties
in it.
Made WriteParagraphProperties return a bool that determines whether or not it
wrote a pPr tag. Needed this since lvl1pPr tag should be started even if there
was no paragraph properties since run properties also written inside it.
Change-Id: Ie0cfc9b9f221093db3a1111ca29140a6dfb5e8ad
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117011
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117539
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index f8175b1e4ae8..fa309108c055 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -259,10 +259,19 @@ public:
void WriteTransformation(const tools::Rectangle& rRectangle,
sal_Int32 nXmlNamespace, bool bFlipH = false, bool bFlipV = false, sal_Int32 nRotation = 0, bool bIsGroupShape = false);
- void WriteText( const css::uno::Reference< css::uno::XInterface >& rXIface, const OUString& presetWarp, bool bBodyPr, bool bText = true, sal_Int32 nXmlNamespace = 0);
+ void WriteText( const css::uno::Reference< css::uno::XInterface >& rXIface, const OUString& presetWarp, bool bBodyPr, bool bText = true, sal_Int32 nXmlNamespace = 0, bool bWritePropertiesAsLstStyles = false);
+
+ /** Populates the lstStyle with the shape's text run and paragraph properties */
+ void WriteLstStyles(const css::uno::Reference<css::text::XTextContent>& rParagraph,
+ bool& rbOverridingCharHeight, sal_Int32& rnCharHeight,
+ const css::uno::Reference<css::beans::XPropertySet>& rXShapePropSet);
void WriteParagraph( const css::uno::Reference< css::text::XTextContent >& rParagraph,
bool& rbOverridingCharHeight, sal_Int32& rnCharHeight );
- void WriteParagraphProperties(const css::uno::Reference< css::text::XTextContent >& rParagraph, float fFirstCharHeight);
+ /** Writes paragraph properties
+
+ @returns true if any paragraph properties were written
+ */
+ bool WriteParagraphProperties(const css::uno::Reference< css::text::XTextContent >& rParagraph, float fFirstCharHeight, const sal_Int32 nElement = XML_pPr );
void WriteParagraphNumbering(const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, float fFirstCharHeight,
sal_Int16 nLevel );
void WriteParagraphTabStops(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet);
diff --git a/include/oox/export/shapes.hxx b/include/oox/export/shapes.hxx
index a8ea2d5c6005..aae207ff1464 100644
--- a/include/oox/export/shapes.hxx
+++ b/include/oox/export/shapes.hxx
@@ -179,7 +179,7 @@ public:
* @return <tt>*this</tt>
*/
ShapeExport& WriteShape( const css::uno::Reference< css::drawing::XShape >& xShape );
- ShapeExport& WriteTextBox( const css::uno::Reference< css::uno::XInterface >& xIface, sal_Int32 nXmlNamespace );
+ ShapeExport& WriteTextBox( const css::uno::Reference< css::uno::XInterface >& xIface, sal_Int32 nXmlNamespace, bool bWritePropertiesAsLstStyles = false );
virtual ShapeExport&
WriteTextShape( const css::uno::Reference< css::drawing::XShape >& xShape );
ShapeExport&
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index e5d0575acdd5..87898bb7d9d2 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -1781,7 +1781,7 @@ void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool
else if (GetProperty(rXPropSet, "CharHeight"))
{
nSize = static_cast<sal_Int32>(100*(*o3tl::doAccess<float>(mAny)));
- if ( nElement == XML_rPr )
+ if ( nElement == XML_rPr || nElement == XML_defRPr )
{
rbOverridingCharHeight = true;
rnCharHeight = nSize;
@@ -2673,14 +2673,14 @@ void DrawingML::WriteLinespacing( const LineSpacing& rSpacing )
}
}
-void DrawingML::WriteParagraphProperties( const Reference< XTextContent >& rParagraph, float fFirstCharHeight)
+bool DrawingML::WriteParagraphProperties( const Reference< XTextContent >& rParagraph, float fFirstCharHeight, sal_Int32 nElement)
{
Reference< XPropertySet > rXPropSet( rParagraph, UNO_QUERY );
Reference< XPropertyState > rXPropState( rParagraph, UNO_QUERY );
PropertyState eState;
if( !rXPropSet.is() || !rXPropState.is() )
- return;
+ return false;
sal_Int16 nLevel = -1;
if (GetProperty(rXPropSet, "NumberingLevel"))
@@ -2731,14 +2731,14 @@ void DrawingML::WriteParagraphProperties( const Reference< XTextContent >& rPara
|| bHasLinespacing )
{
if (nParaLeftMargin) // For Paragraph
- mpFS->startElementNS( XML_a, XML_pPr,
+ mpFS->startElementNS( XML_a, nElement,
XML_lvl, nLevel > 0 ? OString::number(nLevel).getStr() : nullptr,
XML_marL, nParaLeftMargin > 0 ? OString::number(oox::drawingml::convertHmmToEmu(nParaLeftMargin)).getStr() : nullptr,
XML_indent, nParaFirstLineIndent ? OString::number(oox::drawingml::convertHmmToEmu(nParaFirstLineIndent)).getStr() : nullptr,
XML_algn, GetAlignment( nAlignment ),
XML_rtl, bRtl ? ToPsz10(bRtl) : nullptr );
else
- mpFS->startElementNS( XML_a, XML_pPr,
+ mpFS->startElementNS( XML_a, nElement,
XML_lvl, nLevel > 0 ? OString::number(nLevel).getStr() : nullptr,
XML_marL, nLeftMargin > 0 ? OString::number(oox::drawingml::convertHmmToEmu(nLeftMargin)).getStr() : nullptr,
XML_indent, nLineIndentation ? OString::number(oox::drawingml::convertHmmToEmu(nLineIndentation)).getStr() : nullptr,
@@ -2776,7 +2776,51 @@ void DrawingML::WriteParagraphProperties( const Reference< XTextContent >& rPara
WriteParagraphNumbering( rXPropSet, fFirstCharHeight, nLevel );
WriteParagraphTabStops( rXPropSet );
- mpFS->endElementNS( XML_a, XML_pPr );
+ // do not end element for lstStyles since, defRPr should be stacked inside it
+ if( nElement != XML_lvl1pPr )
+ mpFS->endElementNS( XML_a, nElement );
+
+ return true;
+ }
+ return false;
+}
+
+void DrawingML::WriteLstStyles(const css::uno::Reference<css::text::XTextContent>& rParagraph,
+ bool& rbOverridingCharHeight, sal_Int32& rnCharHeight,
+ const css::uno::Reference<css::beans::XPropertySet>& /*rXShapePropSet*/)
+{
+ Reference<XEnumerationAccess> access(rParagraph, UNO_QUERY);
+ if (!access.is())
+ return;
+
+ Reference<XEnumeration> enumeration(access->createEnumeration());
+ if (!enumeration.is())
+ return;
+
+
+ Reference<XTextRange> rRun;
+
+ if (enumeration->hasMoreElements())
+ {
+ Any aAny(enumeration->nextElement());
+ if (aAny >>= rRun)
+ {
+ float fFirstCharHeight = rnCharHeight / 1000.;
+ Reference<XPropertySet> xFirstRunPropSet(rRun, UNO_QUERY);
+ Reference<XPropertySetInfo> xFirstRunPropSetInfo
+ = xFirstRunPropSet->getPropertySetInfo();
+
+ if (xFirstRunPropSetInfo->hasPropertyByName("CharHeight"))
+ fFirstCharHeight = xFirstRunPropSet->getPropertyValue("CharHeight").get<float>();
+
+ mpFS->startElementNS(XML_a, XML_lstStyle);
+ if( !WriteParagraphProperties(rParagraph, fFirstCharHeight, XML_lvl1pPr) )
+ mpFS->startElementNS(XML_a, XML_lvl1pPr);
+ WriteRunProperties(xFirstRunPropSet, false, XML_defRPr, true, rbOverridingCharHeight,
+ rnCharHeight, GetScriptType(rRun->getString()));
+ mpFS->endElementNS(XML_a, XML_lvl1pPr);
+ mpFS->endElementNS(XML_a, XML_lstStyle);
+ }
}
}
@@ -2820,7 +2864,7 @@ void DrawingML::WriteParagraph( const Reference< XTextContent >& rParagraph,
mpFS->endElementNS( XML_a, XML_p );
}
-void DrawingML::WriteText( const Reference< XInterface >& rXIface, const OUString& presetWarp, bool bBodyPr, bool bText, sal_Int32 nXmlNamespace )
+void DrawingML::WriteText( const Reference< XInterface >& rXIface, const OUString& presetWarp, bool bBodyPr, bool bText, sal_Int32 nXmlNamespace, bool bWritePropertiesAsLstStyles )
{
Reference< XText > xXText( rXIface, UNO_QUERY );
Reference< XPropertySet > rXPropSet( rXIface, UNO_QUERY );
@@ -3098,6 +3142,7 @@ void DrawingML::WriteText( const Reference< XInterface >& rXIface, const OUStrin
bool bOverridingCharHeight = false;
sal_Int32 nCharHeight = -1;
+ bool bFirstParagraph = true;
while( enumeration->hasMoreElements() )
{
@@ -3105,7 +3150,13 @@ void DrawingML::WriteText( const Reference< XInterface >& rXIface, const OUStrin
Any any ( enumeration->nextElement() );
if( any >>= paragraph)
- WriteParagraph( paragraph, bOverridingCharHeight, nCharHeight );
+ {
+ if (bFirstParagraph && bWritePropertiesAsLstStyles)
+ WriteLstStyles(paragraph, bOverridingCharHeight, nCharHeight, rXPropSet);
+
+ WriteParagraph(paragraph, bOverridingCharHeight, nCharHeight);
+ bFirstParagraph = false;
+ }
}
}
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 60b88181b5dc..1eb48b0efc5c 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -1591,7 +1591,7 @@ ShapeExport& ShapeExport::WriteShape( const Reference< XShape >& xShape )
return *this;
}
-ShapeExport& ShapeExport::WriteTextBox( const Reference< XInterface >& xIface, sal_Int32 nXmlNamespace )
+ShapeExport& ShapeExport::WriteTextBox( const Reference< XInterface >& xIface, sal_Int32 nXmlNamespace, bool bWritePropertiesAsLstStyles )
{
// In case this shape has an associated textbox, then export that, and we're done.
if (GetDocumentType() == DOCUMENT_DOCX && GetTextExport())
@@ -1616,7 +1616,7 @@ ShapeExport& ShapeExport::WriteTextBox( const Reference< XInterface >& xIface, s
pFS->startElementNS(nXmlNamespace,
(GetDocumentType() != DOCUMENT_DOCX ? XML_txBody : XML_txbx));
- WriteText( xIface, m_presetWarp, /*bBodyPr=*/(GetDocumentType() != DOCUMENT_DOCX) );
+ WriteText( xIface, m_presetWarp, /*bBodyPr=*/(GetDocumentType() != DOCUMENT_DOCX), true, 0, bWritePropertiesAsLstStyles );
pFS->endElementNS( nXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_txBody : XML_txbx) );
if (GetDocumentType() == DOCUMENT_DOCX)
WriteText( xIface, m_presetWarp, /*bBodyPr=*/true, /*bText=*/false, /*nXmlNamespace=*/nXmlNamespace );
More information about the Libreoffice-commits
mailing list