From b7ed6de51422ca7bc8333e80ae6e9a4d57e07239 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Mon, 6 Jul 2020 02:08:33 +0300 Subject: Use std::optional to allow optional inclusion of attributes ... instead of converting the O(U)String objects to char*. Eventually this could allow to drop variants of *Element that take XFastAttributeListRef. Change-Id: Ib2748fcd93e655c55a176c00410fdcc7f052930d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98179 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- include/sax/fshelper.hxx | 41 ++++++++++++++++------ oox/source/export/drawingml.cxx | 56 +++++++++++++++---------------- oox/source/export/shapes.cxx | 8 ++--- sc/source/filter/excel/xecontent.cxx | 15 ++++----- sc/source/filter/excel/xeescher.cxx | 8 ++--- sc/source/filter/excel/xeextlst.cxx | 4 +-- sc/source/filter/excel/xestyle.cxx | 4 +-- sd/source/filter/eppt/pptx-animations.cxx | 38 ++++++++++----------- sd/source/filter/eppt/pptx-epptooxml.cxx | 8 ++--- 9 files changed, 101 insertions(+), 81 deletions(-) diff --git a/include/sax/fshelper.hxx b/include/sax/fshelper.hxx index 235181bf9846..e4b5072345e2 100644 --- a/include/sax/fshelper.hxx +++ b/include/sax/fshelper.hxx @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -58,16 +59,21 @@ public: startElement(elementTokenId, std::forward(args)...); } template - void startElement(sal_Int32 elementTokenId, sal_Int32 attribute, const OString& value, Args &&... args) + void startElement(sal_Int32 elementTokenId, sal_Int32 attribute, + const std::optional& value, Args&&... args) { - pushAttributeValue(attribute, value); + if (value) + pushAttributeValue(attribute, *value); startElement(elementTokenId, std::forward(args)...); } template - void startElement(sal_Int32 elementTokenId, sal_Int32 attribute, const OUString& value, Args&&... args) + void startElement(sal_Int32 elementTokenId, sal_Int32 attribute, + const std::optional& value, Args&&... args) { - // The temporary created by toUtf8() must stay alive until startElement() ends using it - startElement(elementTokenId, attribute, value.toUtf8(), std::forward(args)...); + std::optional opt; + if (value) + opt = value->toUtf8(); + startElement(elementTokenId, attribute, opt, std::forward(args)...); } void startElement(sal_Int32 elementTokenId); @@ -87,16 +93,21 @@ public: singleElement(elementTokenId, std::forward(args)...); } template - void singleElement(sal_Int32 elementTokenId, sal_Int32 attribute, const OString& value, Args &&... args) + void singleElement(sal_Int32 elementTokenId, sal_Int32 attribute, + const std::optional& value, Args&&... args) { - pushAttributeValue(attribute, value); + if (value) + pushAttributeValue(attribute, *value); singleElement(elementTokenId, std::forward(args)...); } template - void singleElement(sal_Int32 elementTokenId, sal_Int32 attribute, const OUString& value, Args&&... args) + void singleElement(sal_Int32 elementTokenId, sal_Int32 attribute, + const std::optional& value, Args&&... args) { - // The temporary created by toUtf8() must stay alive until singleElement() ends using it - singleElement(elementTokenId, attribute, value.toUtf8(), std::forward(args)...); + std::optional opt; + if (value) + opt = value->toUtf8(); + singleElement(elementTokenId, attribute, opt, std::forward(args)...); } void singleElement(sal_Int32 elementTokenId); @@ -150,6 +161,16 @@ private: typedef std::shared_ptr< FastSerializerHelper > FSHelperPtr; +// Helpers to make intention to pass optional attributes to *Element finctions explicit, instead of +// using `(condition) ? value.toUtf8().getStr() : nullptr` syntax. +inline const char* UseIf(const char* s, bool bUse) { return bUse ? s : nullptr; } +// OString, OUString +template +std::optional UseIf(const TString& s, bool bUse) +{ + return bUse ? std::optional(s) : std::optional(); +} + } #endif // INCLUDED_SAX_FSHELPER_HXX diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 1d52bef4b25c..052ea8f93090 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -860,8 +860,8 @@ void DrawingML::WriteOutline( const Reference& rXPropSet, Referenc nEmuLineWidth = oox::drawingml::convertHmmToEmu(nLineWidth); mpFS->startElementNS( XML_a, XML_ln, XML_cap, cap, - XML_w, nLineWidth == 0 || (nLineWidth > 1 && nStyleLineWidth != nLineWidth) ? - OString::number(nEmuLineWidth).getStr() : nullptr ); + XML_w, sax_fastparser::UseIf(OString::number(nEmuLineWidth), + nLineWidth == 0 || (nLineWidth > 1 && nStyleLineWidth != nLineWidth)) ); if( bColorSet ) { @@ -1344,8 +1344,8 @@ void DrawingML::WriteImageBrightnessContrastTransparence(uno::ReferencesingleElementNS(XML_a, XML_lum, - XML_bright, nBright ? OString::number(nBright * 1000).getStr() : nullptr, - XML_contrast, nContrast ? OString::number(nContrast * 1000).getStr() : nullptr); + XML_bright, sax_fastparser::UseIf(OString::number(nBright * 1000), nBright != 0), + XML_contrast, sax_fastparser::UseIf(OString::number(nContrast * 1000), nContrast != 0)); } if (nTransparence) @@ -1611,9 +1611,9 @@ void DrawingML::WriteTransformation(const tools::Rectangle& rRect, { mpFS->startElementNS( nXmlNamespace, XML_xfrm, - XML_flipH, bFlipH ? "1" : nullptr, - XML_flipV, bFlipV ? "1" : nullptr, - XML_rot, (nRotation % 21600000) ? OString::number(nRotation).getStr() : nullptr ); + XML_flipH, sax_fastparser::UseIf("1", bFlipH), + XML_flipV, sax_fastparser::UseIf("1", bFlipV), + XML_rot, sax_fastparser::UseIf(OString::number(nRotation), nRotation % 21600000 != 0)); sal_Int32 nLeft = rRect.Left(); sal_Int32 nTop = rRect.Top(); @@ -1890,13 +1890,13 @@ void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool mpFS->startElementNS( XML_a, nElement, XML_b, bold, XML_i, italic, - XML_lang, usLanguage.isEmpty() ? nullptr : usLanguage.toUtf8().getStr(), + XML_lang, sax_fastparser::UseIf(usLanguage, !usLanguage.isEmpty()), XML_sz, OString::number(nSize), // For Condensed character spacing spc value is negative. - XML_spc, nCharKerning ? OString::number(nCharKerning).getStr() : nullptr, + XML_spc, sax_fastparser::UseIf(OString::number(nCharKerning), nCharKerning != 0), XML_strike, strikeout, XML_u, underline, - XML_baseline, nCharEscapement == 0 ? nullptr : OString::number(nCharEscapement*1000).getStr(), + XML_baseline, sax_fastparser::UseIf(OString::number(nCharEscapement*1000), nCharEscapement != 0), XML_cap, cap ); // mso doesn't like text color to be placed after typeface @@ -2409,7 +2409,7 @@ void DrawingML::WriteParagraphNumbering(const Reference< XPropertySet >& rXPropS aBulletChar = SubstituteBullet( aBulletChar, aFontDesc ); mpFS->singleElementNS( XML_a, XML_buFont, XML_typeface, aFontDesc.Name, - XML_charset, (aFontDesc.CharSet == awt::CharSet::SYMBOL) ? "2" : nullptr ); + XML_charset, sax_fastparser::UseIf("2", aFontDesc.CharSet == awt::CharSet::SYMBOL)); } OUString aAutoNumType = GetAutoNumType( nNumberingType, bSDot, bPBehind, bPBoth ); @@ -2418,7 +2418,7 @@ void DrawingML::WriteParagraphNumbering(const Reference< XPropertySet >& rXPropS { mpFS->singleElementNS(XML_a, XML_buAutoNum, XML_type, aAutoNumType, - XML_startAt, nStartWith > 1 ? OString::number(nStartWith).getStr() : nullptr); + XML_startAt, sax_fastparser::UseIf(OString::number(nStartWith), nStartWith > 1)); } else { @@ -2620,18 +2620,18 @@ void DrawingML::WriteParagraphProperties( const Reference< XTextContent >& rPara if (nParaLeftMargin) // For Paragraph mpFS->startElementNS( XML_a, XML_pPr, - 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_lvl, sax_fastparser::UseIf(OString::number(nLevel), nLevel > 0), + XML_marL, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nParaLeftMargin)), nParaLeftMargin > 0), + XML_indent, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nParaFirstLineIndent)), nParaFirstLineIndent != 0), XML_algn, GetAlignment( nAlignment ), - XML_rtl, bRtl ? ToPsz10(bRtl) : nullptr ); + XML_rtl, sax_fastparser::UseIf(ToPsz10(bRtl), bRtl)); else mpFS->startElementNS( XML_a, XML_pPr, - 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, + XML_lvl, sax_fastparser::UseIf(OString::number(nLevel), nLevel > 0), + XML_marL, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nLeftMargin)), nLeftMargin > 0), + XML_indent, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nLineIndentation)), nLineIndentation != 0), XML_algn, GetAlignment( nAlignment ), - XML_rtl, bRtl ? ToPsz10(bRtl) : nullptr ); + XML_rtl, sax_fastparser::UseIf(ToPsz10(bRtl), bRtl)); if( bHasLinespacing ) @@ -2836,15 +2836,15 @@ void DrawingML::WriteText( const Reference< XInterface >& rXIface, const OUStrin } mpFS->startElementNS( (nXmlNamespace ? nXmlNamespace : XML_a), XML_bodyPr, XML_wrap, pWrap, - XML_fromWordArt, bFromWordArt ? "1" : nullptr, - XML_lIns, (nLeft != DEFLRINS) ? OString::number(oox::drawingml::convertHmmToEmu(nLeft)).getStr() : nullptr, - XML_rIns, (nRight != DEFLRINS) ? OString::number(oox::drawingml::convertHmmToEmu(nRight)).getStr() : nullptr, - XML_tIns, (nTop != DEFTBINS) ? OString::number(oox::drawingml::convertHmmToEmu(nTop)).getStr() : nullptr, - XML_bIns, (nBottom != DEFTBINS) ? OString::number(oox::drawingml::convertHmmToEmu(nBottom)).getStr() : nullptr, + XML_fromWordArt, sax_fastparser::UseIf("1", bFromWordArt), + XML_lIns, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nLeft)), nLeft != DEFLRINS), + XML_rIns, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nRight)), nRight != DEFLRINS), + XML_tIns, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nTop)), nTop != DEFTBINS), + XML_bIns, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nBottom)), nBottom != DEFTBINS), XML_anchor, sVerticalAlignment, - XML_anchorCtr, bHorizontalCenter ? "1" : nullptr, + XML_anchorCtr, sax_fastparser::UseIf("1", bHorizontalCenter), XML_vert, sWritingMode, - XML_rot, ((nTextPreRotateAngle + nTextRotateAngle) != 0) ? oox::drawingml::calcRotationValue( (nTextPreRotateAngle + nTextRotateAngle) * 100 ).getStr() : nullptr ); + XML_rot, sax_fastparser::UseIf(oox::drawingml::calcRotationValue((nTextPreRotateAngle + nTextRotateAngle) * 100), (nTextPreRotateAngle + nTextRotateAngle) != 0)); if (bIsFontworkShape) { if (aAdjustmentSeq.hasElements()) @@ -2933,7 +2933,7 @@ void DrawingML::WriteText( const Reference< XInterface >& rXIface, const OUStrin } mpFS->singleElementNS(XML_a, XML_normAutofit, XML_fontScale, - ( nFontScale < MAX_SCALE_VAL && nFontScale > 0 ) ? OString::number(nFontScale).getStr() : nullptr); + sax_fastparser::UseIf(OString::number(nFontScale), nFontScale < MAX_SCALE_VAL && nFontScale > 0)); } else { diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx index 8cab446a3488..5729c9d27a66 100644 --- a/oox/source/export/shapes.cxx +++ b/oox/source/export/shapes.cxx @@ -802,7 +802,7 @@ ShapeExport& ShapeExport::WriteCustomShape( const Reference< XShape >& xShape ) pFS->startElementNS( mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), XML_name, GetShapeName(xShape), - XML_hidden, isVisible ? nullptr : "1" ); + XML_hidden, sax_fastparser::UseIf("1", !isVisible)); if( GETA( URL ) ) { @@ -1194,7 +1194,7 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape pFS->startElementNS( mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), XML_name, GetShapeName(xShape), - XML_descr, bHaveDesc ? sDescr.toUtf8().getStr() : nullptr ); + XML_descr, sax_fastparser::UseIf(sDescr, bHaveDesc)); // OOXTODO: //cNvPr children: XML_extLst, XML_hlinkHover if (bHasMediaURL) @@ -1780,8 +1780,8 @@ void ShapeExport::WriteTableCellProperties(const Reference< XPropertySet>& xCell aRightMargin >>= nRightMargin; mpFS->startElementNS(XML_a, XML_tcPr, - XML_marL, nLeftMargin > 0 ? OString::number(oox::drawingml::convertHmmToEmu(nLeftMargin)).getStr() : nullptr, - XML_marR, nRightMargin > 0 ? OString::number(oox::drawingml::convertHmmToEmu(nRightMargin)).getStr() : nullptr); + XML_marL, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nLeftMargin)), nLeftMargin > 0), + XML_marR, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nRightMargin)), nRightMargin > 0)); // Write background fill for table cell. // TODO diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx index 9e596fdcf35d..88e2018b16ab 100644 --- a/sc/source/filter/excel/xecontent.cxx +++ b/sc/source/filter/excel/xecontent.cxx @@ -525,14 +525,13 @@ void XclExpHyperlink::SaveXml( XclExpXmlStream& rStrm ) OUString sId = !msTarget.isEmpty() ? rStrm.addRelation( rStrm.GetCurrentStream()->getOutputStream(), oox::getRelationship(Relationship::HYPERLINK), msTarget, true ) : OUString(); + std::optional sTextMark; + if (mxTextMark) + sTextMark = XclXmlUtils::ToOString(*mxTextMark); rStrm.GetCurrentStream()->singleElement( XML_hyperlink, XML_ref, XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), maScPos), - FSNS( XML_r, XML_id ), !sId.isEmpty() - ? sId.toUtf8().getStr() - : nullptr, - XML_location, mxTextMark - ? XclXmlUtils::ToOString( *mxTextMark ).getStr() - : nullptr, + FSNS( XML_r, XML_id ), sax_fastparser::UseIf(sId, !sId.isEmpty()), + XML_location, sTextMark, // OOXTODO: XML_tooltip, from record HLinkTooltip 800h wzTooltip XML_display, m_Repr ); } @@ -1549,8 +1548,8 @@ void XclExpIconSet::SaveXml( XclExpXmlStream& rStrm ) const char* pIconSetName = ScIconSetFormat::getIconSetName(mrFormat.GetIconSetData()->eIconSetType); rWorksheet->startElement( XML_iconSet, XML_iconSet, pIconSetName, - XML_showValue, mrFormat.GetIconSetData()->mbShowValue ? nullptr : "0", - XML_reverse, mrFormat.GetIconSetData()->mbReverse ? "1" : nullptr ); + XML_showValue, sax_fastparser::UseIf("0", !mrFormat.GetIconSetData()->mbShowValue), + XML_reverse, sax_fastparser::UseIf("1", mrFormat.GetIconSetData()->mbReverse)); maCfvoList.SaveXml( rStrm ); diff --git a/sc/source/filter/excel/xeescher.cxx b/sc/source/filter/excel/xeescher.cxx index 8afbe2e3752b..0e78fbf251da 100644 --- a/sc/source/filter/excel/xeescher.cxx +++ b/sc/source/filter/excel/xeescher.cxx @@ -1192,10 +1192,10 @@ void XclExpTbxControlObj::SaveXml( XclExpXmlStream& rStrm ) // Insets are used just as internal margins for text boxes within shapes. // If this attribute is omitted, then a value of 45720 or 0.05 inches is implied. pDrawing->startElementNS(XML_a, XML_bodyPr, - XML_lIns, (nLeft != DEFLRINS) ? OString::number(oox::drawingml::convertHmmToEmu(nLeft)).getStr() : nullptr, - XML_rIns, (nRight != DEFLRINS) ? OString::number(oox::drawingml::convertHmmToEmu(nRight)).getStr() : nullptr, - XML_tIns, (nTop != DEFTBINS) ? OString::number(oox::drawingml::convertHmmToEmu(nTop)).getStr() : nullptr, - XML_bIns, (nBottom != DEFTBINS) ? OString::number(oox::drawingml::convertHmmToEmu(nBottom)).getStr() : nullptr, + XML_lIns, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nLeft)), nLeft != DEFLRINS), + XML_rIns, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nRight)), nRight != DEFLRINS), + XML_tIns, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nTop)), nTop != DEFTBINS), + XML_bIns, sax_fastparser::UseIf(OString::number(oox::drawingml::convertHmmToEmu(nBottom)), nBottom != DEFTBINS), XML_anchor, "ctr"); { diff --git a/sc/source/filter/excel/xeextlst.cxx b/sc/source/filter/excel/xeextlst.cxx index db770b0dc6cd..35d2fac152d7 100644 --- a/sc/source/filter/excel/xeextlst.cxx +++ b/sc/source/filter/excel/xeextlst.cxx @@ -340,7 +340,7 @@ void XclExpExtIconSet::SaveXml(XclExpXmlStream& rStrm) rWorksheet->startElementNS(XML_x14, XML_iconSet, XML_iconSet, mpIconSetName, - XML_custom, mbCustom ? ToPsz10(mbCustom) : nullptr, + XML_custom, sax_fastparser::UseIf(ToPsz10(mbCustom), mbCustom), XML_reverse, ToPsz10(mbReverse), XML_showValue, ToPsz10(mbShowValue)); @@ -398,7 +398,7 @@ void XclExpExtCfRule::SaveXml( XclExpXmlStream& rStrm ) sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream(); rWorksheet->startElementNS( XML_x14, XML_cfRule, XML_type, pType, - XML_priority, mnPriority == -1 ? nullptr : OString::number(mnPriority + 1).getStr(), + XML_priority, sax_fastparser::UseIf(OString::number(mnPriority + 1), mnPriority != -1), XML_operator, mOperator, XML_id, maId ); diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx index e91b64b5687c..76d9c2fb572f 100644 --- a/sc/source/filter/excel/xestyle.cxx +++ b/sc/source/filter/excel/xestyle.cxx @@ -1600,7 +1600,7 @@ void XclExpCellAlign::SaveXml( XclExpXmlStream& rStrm ) const // OOXTODO: XML_relativeIndent, mnIndent? // OOXTODO: XML_justifyLastLine, XML_shrinkToFit, ToPsz( mbShrink ), - XML_readingOrder, mnTextDir == EXC_XF_TEXTDIR_CONTEXT ? nullptr : OString::number(mnTextDir).getStr() ); + XML_readingOrder, sax_fastparser::UseIf(OString::number(mnTextDir), mnTextDir != EXC_XF_TEXTDIR_CONTEXT) ); } namespace { @@ -2200,7 +2200,7 @@ void XclExpXF::SaveXml( XclExpXmlStream& rStrm ) XML_fontId, OString::number(mnXclFont), XML_fillId, OString::number(mnFillId), XML_borderId, OString::number(mnBorderId), - XML_xfId, IsStyleXF() ? nullptr : OString::number( nXfId ).getStr(), + XML_xfId, sax_fastparser::UseIf(OString::number(nXfId), !IsStyleXF()), // OOXTODO: XML_quotePrefix, // OOXTODO: XML_pivotButton, // OOXTODO: XML_applyNumberFormat, ; diff --git a/sd/source/filter/eppt/pptx-animations.cxx b/sd/source/filter/eppt/pptx-animations.cxx index ec0f723c4974..90720501d07a 100644 --- a/sd/source/filter/eppt/pptx-animations.cxx +++ b/sd/source/filter/eppt/pptx-animations.cxx @@ -215,7 +215,7 @@ void WriteAnimateValues(const FSHelperPtr& pFS, const Reference& rXAni if (aValues[i].hasValue()) { pFS->startElementNS(XML_p, XML_tav, XML_fmla, - sFormula.isEmpty() ? nullptr : sFormula.toUtf8().getStr(), XML_tm, + sax_fastparser::UseIf(sFormula, !sFormula.isEmpty()), XML_tm, OString::number(static_cast(aKeyTimes[i] * 100000.0))); pFS->startElementNS(XML_p, XML_val); ValuePair aPair; @@ -901,10 +901,9 @@ void PPTXAnimationExport::WriteAnimationNodeAnimate(sal_Int32 nXmlNodeType) } mpFS->startElementNS(XML_p, nXmlNodeType, XML_calcmode, pCalcMode, XML_valueType, - pValueType, XML_from, - sFrom.isEmpty() ? nullptr : sFrom.toUtf8().getStr(), XML_to, - sTo.isEmpty() ? nullptr : sTo.toUtf8().getStr(), XML_by, - sBy.isEmpty() ? nullptr : sBy.toUtf8().getStr()); + pValueType, XML_from, sax_fastparser::UseIf(sFrom, !sFrom.isEmpty()), + XML_to, sax_fastparser::UseIf(sTo, !sTo.isEmpty()), XML_by, + sax_fastparser::UseIf(sBy, !sBy.isEmpty())); bTo = sTo.isEmpty() && sFrom.isEmpty() && sBy.isEmpty(); } @@ -982,7 +981,7 @@ void PPTXAnimationExport::WriteAnimationNodeAnimateInside(bool bSimple, bool bWr void PPTXAnimationExport::WriteAnimationNodeCommonPropsStart() { const Reference& rXNode = getCurrentNode(); - const char* pDuration = nullptr; + std::optional sDuration; const char* pRestart = nullptr; const char* pNodeType = nullptr; const char* pPresetClass = nullptr; @@ -999,7 +998,7 @@ void PPTXAnimationExport::WriteAnimationNodeCommonPropsStart() if (aAny >>= eTiming) { if (eTiming == Timing_INDEFINITE) - pDuration = "indefinite"; + sDuration = "indefinite"; } else aAny >>= fDuration; @@ -1013,17 +1012,20 @@ void PPTXAnimationExport::WriteAnimationNodeCommonPropsStart() pNodeType = convertEffectNodeType(nType); if (nType == EffectNodeType::TIMING_ROOT) { - if (!pDuration) - pDuration = "indefinite"; + if (!sDuration) + sDuration = "indefinite"; if (!pRestart) pRestart = "never"; } else if (nType == EffectNodeType::MAIN_SEQUENCE) { - pDuration = "indefinite"; + sDuration = "indefinite"; } } + if (fDuration != 0) + sDuration = OString::number(static_cast(fDuration * 1000.0)); + sal_uInt32 nPresetClass = mpContext->getEffectPresetClass(); if (nPresetClass != DFF_ANIM_PRESS_CLASS_USER_DEFINED) pPresetClass = convertEffectPresetClass(nPresetClass); @@ -1057,13 +1059,11 @@ void PPTXAnimationExport::WriteAnimationNodeCommonPropsStart() bool bAutoReverse = rXNode->getAutoReverse(); mpFS->startElementNS( - XML_p, XML_cTn, XML_id, OString::number(GetNextAnimationNodeId(rXNode)), XML_dur, - fDuration != 0 ? OString::number(static_cast(fDuration * 1000.0)).getStr() - : pDuration, - XML_autoRev, bAutoReverse ? "1" : nullptr, XML_restart, pRestart, XML_nodeType, pNodeType, - XML_fill, pFill, XML_presetClass, pPresetClass, XML_presetID, - bPresetId ? OString::number(nPresetId).getStr() : nullptr, XML_presetSubtype, - bPresetSubType ? OString::number(nPresetSubType).getStr() : nullptr); + XML_p, XML_cTn, XML_id, OString::number(GetNextAnimationNodeId(rXNode)), XML_dur, sDuration, + XML_autoRev, sax_fastparser::UseIf("1", bAutoReverse), XML_restart, pRestart, XML_nodeType, + pNodeType, XML_fill, pFill, XML_presetClass, pPresetClass, XML_presetID, + sax_fastparser::UseIf(OString::number(nPresetId), bPresetId), XML_presetSubtype, + sax_fastparser::UseIf(OString::number(nPresetSubType), bPresetSubType)); WriteAnimationCondList(mpContext->getCondition(true), XML_stCondLst); WriteAnimationCondList(mpContext->getCondition(false), XML_endCondLst); @@ -1192,8 +1192,8 @@ void PPTXAnimationExport::WriteAnimationNodeAudio() mpFS->startElementNS(XML_p, XML_tgtEl); mpFS->singleElementNS(XML_p, XML_sndTgt, FSNS(XML_r, XML_embed), - sRelId.isEmpty() ? nullptr : sRelId.toUtf8().getStr(), XML_name, - sUrl.isEmpty() ? nullptr : sName.toUtf8().getStr()); + sax_fastparser::UseIf(sRelId, !sRelId.isEmpty()), XML_name, + sax_fastparser::UseIf(sName, !sUrl.isEmpty())); mpFS->endElementNS(XML_p, XML_tgtEl); mpFS->endElementNS(XML_p, XML_cMediaNode); diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx index e1cb766858c5..9de1eb5b3f60 100644 --- a/sd/source/filter/eppt/pptx-epptooxml.cxx +++ b/sd/source/filter/eppt/pptx-epptooxml.cxx @@ -119,9 +119,9 @@ void WriteSndAc(const FSHelperPtr& pFS, const OUString& sSoundRelId, const OUStr { pFS->startElementNS(XML_p, XML_sndAc); pFS->startElementNS(XML_p, XML_stSnd); - pFS->singleElementNS(XML_p, XML_snd, - FSNS(XML_r, XML_embed), sSoundRelId.isEmpty() ? nullptr : sSoundRelId.toUtf8().getStr(), - XML_name, sSoundName.isEmpty() ? nullptr : sSoundName.toUtf8().getStr()); + pFS->singleElementNS(XML_p, XML_snd, FSNS(XML_r, XML_embed), + sax_fastparser::UseIf(sSoundRelId, !sSoundRelId.isEmpty()), XML_name, + sax_fastparser::UseIf(sSoundName, !sSoundName.isEmpty())); pFS->endElement(FSNS(XML_p, XML_stSnd)); pFS->endElement(FSNS(XML_p, XML_sndAc)); } @@ -900,7 +900,7 @@ void PowerPointExport::WriteTransition(const FSHelperPtr& pFS) pFS->startElementNS(XML_p, XML_transition, XML_spd, speed, - XML_advTm, isAdvanceTimingSet ? OString::number(advanceTiming * 1000).getStr() : nullptr); + XML_advTm, sax_fastparser::UseIf(OString::number(advanceTiming * 1000), isAdvanceTimingSet)); if (nTransition) { -- cgit