diff options
Diffstat (limited to 'oox/source/export/drawingml.cxx')
-rw-r--r-- | oox/source/export/drawingml.cxx | 209 |
1 files changed, 150 insertions, 59 deletions
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index fd4f67732607..5d3996430eff 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; @@ -2138,40 +2138,13 @@ OUString DrawingML::GetFieldValue( const css::uno::Reference< css::text::XTextRa { sal_Int32 nNumFmt = -1; rXPropSet->getPropertyValue(UNO_TC_PROP_NUMFORMAT) >>= nNumFmt; - switch(static_cast<SvxDateFormat>(nNumFmt)) - { - case SvxDateFormat::StdSmall: - case SvxDateFormat::A: aFieldValue = "datetime"; // 13/02/96 - break; - case SvxDateFormat::B: aFieldValue = "datetime1"; // 13/02/1996 - break; - case SvxDateFormat::StdBig: - case SvxDateFormat::D: aFieldValue = "datetime3"; // 13 February 1996 - break; - default: break; - } + aFieldValue = GetDatetimeTypeFromDate(static_cast<SvxDateFormat>(nNumFmt)); } else if(aFieldKind == "ExtTime") { sal_Int32 nNumFmt = -1; rXPropSet->getPropertyValue(UNO_TC_PROP_NUMFORMAT) >>= nNumFmt; - switch(static_cast<SvxTimeFormat>(nNumFmt)) - { - case SvxTimeFormat::Standard: - case SvxTimeFormat::HH24_MM_SS: - aFieldValue = "datetime11"; // 13:49:38 - break; - case SvxTimeFormat::HH24_MM: - aFieldValue = "datetime10"; // 13:49 - break; - case SvxTimeFormat::HH12_MM: - aFieldValue = "datetime12"; // 01:49 PM - break; - case SvxTimeFormat::HH12_MM_SS: - aFieldValue = "datetime13"; // 01:49:38 PM - break; - default: break; - } + aFieldValue = GetDatetimeTypeFromTime(static_cast<SvxTimeFormat>(nNumFmt)); } else if(aFieldKind == "ExtFile") { @@ -2198,6 +2171,85 @@ OUString DrawingML::GetFieldValue( const css::uno::Reference< css::text::XTextRa return aFieldValue; } +OUString DrawingML::GetDatetimeTypeFromDate(SvxDateFormat eDate) +{ + return GetDatetimeTypeFromDateTime(eDate, SvxTimeFormat::AppDefault); +} + +OUString DrawingML::GetDatetimeTypeFromTime(SvxTimeFormat eTime) +{ + return GetDatetimeTypeFromDateTime(SvxDateFormat::AppDefault, eTime); +} + +OUString DrawingML::GetDatetimeTypeFromDateTime(SvxDateFormat eDate, SvxTimeFormat eTime) +{ + OUString aDateField; + switch (eDate) + { + case SvxDateFormat::StdSmall: + case SvxDateFormat::A: + aDateField = "datetime"; + break; + case SvxDateFormat::B: + aDateField = "datetime1"; // 13/02/1996 + break; + case SvxDateFormat::C: + aDateField = "datetime5"; + break; + case SvxDateFormat::D: + aDateField = "datetime3"; // 13 February 1996 + break; + case SvxDateFormat::StdBig: + case SvxDateFormat::E: + case SvxDateFormat::F: + aDateField = "datetime2"; + break; + default: + break; + } + + OUString aTimeField; + switch (eTime) + { + case SvxTimeFormat::Standard: + case SvxTimeFormat::HH24_MM_SS: + case SvxTimeFormat::HH24_MM_SS_00: + aTimeField = "datetime11"; // 13:49:38 + break; + case SvxTimeFormat::HH24_MM: + aTimeField = "datetime10"; // 13:49 + break; + case SvxTimeFormat::HH12_MM: + case SvxTimeFormat::HH12_MM_AMPM: + aTimeField = "datetime12"; // 01:49 PM + break; + case SvxTimeFormat::HH12_MM_SS: + case SvxTimeFormat::HH12_MM_SS_AMPM: + case SvxTimeFormat::HH12_MM_SS_00: + case SvxTimeFormat::HH12_MM_SS_00_AMPM: + aTimeField = "datetime13"; // 01:49:38 PM + break; + default: + break; + } + + if (!aDateField.isEmpty() && aTimeField.isEmpty()) + return aDateField; + else if (!aTimeField.isEmpty() && aDateField.isEmpty()) + return aTimeField; + else if (!aDateField.isEmpty() && !aTimeField.isEmpty()) + { + if (aTimeField == "datetime11" || aTimeField == "datetime13") + // only datetime format that has Date and HH:MM:SS + return "datetime9"; // dd/mm/yyyy H:MM:SS + else + // only datetime format that has Date and HH:MM + return "datetime8"; // dd/mm/yyyy H:MM + } + else + return ""; +} + void DrawingML::WriteRun( const Reference< XTextRange >& rRun, bool& rbOverridingCharHeight, sal_Int32& rnCharHeight) { @@ -2623,14 +2675,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")) @@ -2681,14 +2733,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, @@ -2726,7 +2778,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); + } } } @@ -2757,7 +2853,11 @@ void DrawingML::WriteParagraph( const Reference< XTextContent >& rParagraph, Reference< XPropertySet > xFirstRunPropSet (run, UNO_QUERY); Reference< XPropertySetInfo > xFirstRunPropSetInfo = xFirstRunPropSet->getPropertySetInfo(); if( xFirstRunPropSetInfo->hasPropertyByName("CharHeight") ) + { fFirstCharHeight = xFirstRunPropSet->getPropertyValue("CharHeight").get<float>(); + rnCharHeight = 100 * fFirstCharHeight; + rbOverridingCharHeight = true; + } WriteParagraphProperties( rParagraph, fFirstCharHeight ); bPropertiesWritten = true; } @@ -2770,7 +2870,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 ); @@ -3002,7 +3102,7 @@ void DrawingML::WriteText( const Reference< XInterface >& rXIface, const OUStrin } } - WriteShape3DEffects( rXPropSet ); + Write3DEffects( rXPropSet, /*bIsText=*/true ); mpFS->endElementNS((nXmlNamespace ? nXmlNamespace : XML_a), XML_bodyPr); } @@ -3048,6 +3148,7 @@ void DrawingML::WriteText( const Reference< XInterface >& rXIface, const OUStrin bool bOverridingCharHeight = false; sal_Int32 nCharHeight = -1; + bool bFirstParagraph = true; while( enumeration->hasMoreElements() ) { @@ -3055,7 +3156,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; + } } } @@ -3933,7 +4040,7 @@ void DrawingML::WriteShapeEffects( const Reference< XPropertySet >& rXPropSet ) } } -void DrawingML::WriteShape3DEffects( const Reference< XPropertySet >& xPropSet ) +void DrawingML::Write3DEffects( const Reference< XPropertySet >& xPropSet, bool bIsText ) { // check existence of the grab bag if( !GetProperty( xPropSet, "InteropGrabBag" ) ) @@ -3942,8 +4049,10 @@ void DrawingML::WriteShape3DEffects( const Reference< XPropertySet >& xPropSet ) // extract the relevant properties from the grab bag Sequence< PropertyValue > aGrabBag, aEffectProps, aLightRigProps, aShape3DProps; mAny >>= aGrabBag; - auto pShapeProp = std::find_if(std::cbegin(aGrabBag), std::cend(aGrabBag), - [](const PropertyValue& rProp) { return rProp.Name == "3DEffectProperties"; }); + + auto pShapeProp = std::find_if( std::cbegin(aGrabBag), std::cend(aGrabBag), + [bIsText](const PropertyValue& rProp) + { return rProp.Name == (bIsText ? u"Text3DEffectProperties" : u"3DEffectProperties"); }); if (pShapeProp != std::cend(aGrabBag)) { Sequence< PropertyValue > a3DEffectProps; @@ -3959,24 +4068,6 @@ void DrawingML::WriteShape3DEffects( const Reference< XPropertySet >& xPropSet ) } } - auto pTextProp = std::find_if(std::cbegin(aGrabBag), std::cend(aGrabBag), - [](const PropertyValue& rProp) { return rProp.Name == "Text3DEffectProperties"; }); - - if (pTextProp != std::cend(aGrabBag)) - { - Sequence< PropertyValue > a3DEffectProps; - pTextProp->Value >>= a3DEffectProps; - for( const auto& r3DEffectProp : std::as_const(a3DEffectProps) ) - { - if( r3DEffectProp.Name == "Camera" ) - r3DEffectProp.Value >>= aEffectProps; - else if( r3DEffectProp.Name == "LightRig" ) - r3DEffectProp.Value >>= aLightRigProps; - else if( r3DEffectProp.Name == "Shape3D" ) - r3DEffectProp.Value >>= aShape3DProps; - } - } - if( !aEffectProps.hasElements() && !aLightRigProps.hasElements() && !aShape3DProps.hasElements() ) return; |