diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-03-27 10:07:31 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-04-04 15:24:49 +0200 |
commit | 4a4b1df72909fe96acdbcb95f90e30bd1a79c5eb (patch) | |
tree | 4da38d52d51c761cbf09f1a57b3f76b2dcd53d3a /oox | |
parent | 3154770b49f84981432ccc3756ceb1840ff8d8a0 (diff) |
Get rid of USS macro
The helper marco is used in export code to convert UTF-16 internal
string representation to UTF-8 used in XML encoding. I suppose that all
strings here should be already valid UTF-16 (an invalid input should
have been validated at import/input stage). An invalid string at this
stage means a programming error in another part of code that breaks this
precondition, and should not be handled at export stage.
(See also commit 0267a2326b5282023e8b08a147eca178c5db1980.)
This effectively changes flags used in conversion from UTF-16 to UTF-8,
so that now RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR is used instead of
RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT, so that the result would be
truncated on invalid bytes instead of inserting U+FFFD, and would fail
assertion in debug builds.
Other changed flags don't affect UTF-16-to-UTF-8 conversion.
Change-Id: I12b2cc5378208904c3266924187d6402700ed6f3
Reviewed-on: https://gerrit.libreoffice.org/69801
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/export/chartexport.cxx | 11 | ||||
-rw-r--r-- | oox/source/export/drawingml.cxx | 38 | ||||
-rw-r--r-- | oox/source/export/shapes.cxx | 17 |
3 files changed, 37 insertions, 29 deletions
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index 062636c91d62..5641d62119a1 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -457,7 +457,7 @@ void ChartExport::WriteChartObj( const Reference< XShape >& xShape, sal_Int32 nI pFS->singleElementNS( mnXmlNamespace, XML_cNvPr, XML_id, I32S( nID ), - XML_name, USS( sName ), + XML_name, sName.toUtf8(), FSEND ); pFS->singleElementNS( mnXmlNamespace, XML_cNvGraphicFramePr, @@ -526,9 +526,9 @@ void ChartExport::WriteChartObj( const Reference< XShape >& xShape, sal_Int32 nI XmlFilterBase* pFB = GetFB(); pFS->singleElement( FSNS( XML_c, XML_chart ), - FSNS( XML_xmlns, XML_c ), OUStringToOString(pFB->getNamespaceURL(OOX_NS(dmlChart)), RTL_TEXTENCODING_UTF8).getStr(), - FSNS( XML_xmlns, XML_r ), OUStringToOString(pFB->getNamespaceURL(OOX_NS(officeRel)), RTL_TEXTENCODING_UTF8).getStr(), - FSNS( XML_r, XML_id ), USS( sId ), + FSNS(XML_xmlns, XML_c), pFB->getNamespaceURL(OOX_NS(dmlChart)).toUtf8(), + FSNS(XML_xmlns, XML_r), pFB->getNamespaceURL(OOX_NS(officeRel)).toUtf8(), + FSNS(XML_r, XML_id), sId.toUtf8(), FSEND ); pFS->endElement( FSNS( XML_a, XML_graphicData ) ); @@ -3082,7 +3082,8 @@ void writeCustomLabel( const FSHelperPtr& pFS, ChartExport* pChartExport, else { // Field - pFS->startElement(FSNS(XML_a, XML_fld), XML_id, USS(rField->getGuid()), XML_type, USS(sFieldType), FSEND); + pFS->startElement(FSNS(XML_a, XML_fld), XML_id, rField->getGuid().toUtf8(), XML_type, + sFieldType.toUtf8(), FSEND); writeRunProperties(pChartExport, xPropertySet); pFS->startElement(FSNS(XML_a, XML_t), FSEND); diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 4c1077b265f8..b5047b80eb15 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -190,7 +190,7 @@ bool DrawingML::GetProperty( const Reference< XPropertySet >& rXPropertySet, con } catch( const Exception& ) { - /* printf ("exception when trying to get value of property: %s\n", USS(aName)); */ + /* printf ("exception when trying to get value of property: %s\n", aName.toUtf8()); */ } return false; } @@ -208,7 +208,7 @@ bool DrawingML::GetPropertyAndState( const Reference< XPropertySet >& rXProperty } catch( const Exception& ) { - /* printf ("exception when trying to get value of property: %s\n", USS(aName)); */ + /* printf ("exception when trying to get value of property: %s\n", aName.toUtf8()); */ } return false; } @@ -254,7 +254,7 @@ void DrawingML::WriteColor( const OUString& sColorSchemeName, const Sequence< Pr if( aTransformations.hasElements() ) { mpFS->startElementNS( XML_a, XML_schemeClr, - XML_val, USS( sColorSchemeName ), + XML_val, sColorSchemeName.toUtf8(), FSEND ); WriteColorTransformations( aTransformations ); mpFS->endElementNS( XML_a, XML_schemeClr ); @@ -262,7 +262,7 @@ void DrawingML::WriteColor( const OUString& sColorSchemeName, const Sequence< Pr else { mpFS->singleElementNS( XML_a, XML_schemeClr, - XML_val, USS( sColorSchemeName ), + XML_val, sColorSchemeName.toUtf8(), FSEND ); } } @@ -1176,7 +1176,7 @@ void DrawingML::WriteMediaNonVisualProperties(const css::uno::Reference<css::dra GetFS()->startElementNS(XML_p, XML_nvPr, FSEND); GetFS()->singleElementNS(XML_a, eMediaType == Relationship::VIDEO ? XML_videoFile : XML_audioFile, - FSNS(XML_r, XML_link), USS(aVideoFileRelId), + FSNS(XML_r, XML_link), aVideoFileRelId.toUtf8(), FSEND); GetFS()->startElementNS(XML_p, XML_extLst, FSEND); @@ -1185,7 +1185,7 @@ void DrawingML::WriteMediaNonVisualProperties(const css::uno::Reference<css::dra FSEND); GetFS()->singleElementNS(XML_p14, XML_media, - bEmbed? FSNS(XML_r, XML_embed): FSNS(XML_r, XML_link), USS(aMediaRelId), + bEmbed? FSNS(XML_r, XML_embed): FSNS(XML_r, XML_link), aMediaRelId.toUtf8(), FSEND); GetFS()->endElementNS(XML_p, XML_ext); @@ -1734,7 +1734,7 @@ void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool mpFS->startElementNS( XML_a, nElement, XML_b, bold, XML_i, italic, - XML_lang, usLanguage.isEmpty() ? nullptr : USS( usLanguage ), + XML_lang, usLanguage.isEmpty() ? nullptr : usLanguage.toUtf8().getStr(), XML_sz, IS( nSize ), // For Condensed character spacing spc value is negative. XML_spc, nCharKerning ? IS(nCharKerning) : nullptr, @@ -1790,9 +1790,11 @@ void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool mAny >>= usTypeface; OUString aSubstName( GetSubsFontName( usTypeface, SubsFontFlags::ONLYONE | SubsFontFlags::MS ) ); + if (!aSubstName.isEmpty()) + usTypeface = aSubstName; mpFS->singleElementNS( XML_a, XML_latin, - XML_typeface, USS(aSubstName.getLength() ? aSubstName : usTypeface), + XML_typeface, usTypeface.toUtf8(), XML_pitchFamily, pitch, XML_charset, charset, FSEND ); @@ -1811,9 +1813,11 @@ void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool mAny >>= usTypeface; OUString aSubstName( GetSubsFontName( usTypeface, SubsFontFlags::ONLYONE | SubsFontFlags::MS ) ); + if (!aSubstName.isEmpty()) + usTypeface = aSubstName; mpFS->singleElementNS( XML_a, bComplex ? XML_cs : XML_ea, - XML_typeface, USS(aSubstName.getLength() ? aSubstName : usTypeface), + XML_typeface, usTypeface.toUtf8(), XML_pitchFamily, pitch, XML_charset, charset, FSEND ); @@ -1840,7 +1844,7 @@ void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool sURL, true ); mpFS->singleElementNS( XML_a, XML_hlinkClick, - FSNS( XML_r,XML_id ), USS( sRelId ), + FSNS(XML_r, XML_id), sRelId.toUtf8(), FSEND ); } } @@ -2208,7 +2212,7 @@ void DrawingML::WriteParagraphNumbering(const Reference< XPropertySet >& rXPropS mpFS->singleElementNS( XML_a, XML_buSzPct, XML_val, IS( std::min(static_cast<sal_Int32>(std::lround(100000.f * fBulletSizeRel)), static_cast<sal_Int32>(400000))), FSEND); mpFS->startElementNS( XML_a, XML_buBlip, FSEND ); - mpFS->singleElementNS( XML_a, XML_blip, FSNS( XML_r, XML_embed ), USS( sRelationId ), FSEND ); + mpFS->singleElementNS(XML_a, XML_blip, FSNS(XML_r, XML_embed), sRelationId.toUtf8(), FSEND); mpFS->endElementNS( XML_a, XML_buBlip ); } else @@ -2248,7 +2252,7 @@ void DrawingML::WriteParagraphNumbering(const Reference< XPropertySet >& rXPropS } else { - mpFS->singleElementNS(XML_a, XML_buChar, XML_char, USS( OUString( aBulletChar ) ), FSEND); + mpFS->singleElementNS(XML_a, XML_buChar, XML_char, OUString(aBulletChar).toUtf8(), FSEND); } } } @@ -2791,13 +2795,13 @@ void DrawingML::WritePresetShape( const char* pShape, MSO_SPT eShapeType, bool b if( EscherPropertyContainer::GetAdjustmentValue( aAdjustmentSeq[ i ], i, nAdjustmentsWhichNeedsToBeConverted, nValue ) ) { // If the document model doesn't have an adjustment name (e.g. shape was created from VML), then take it from the predefined list. - OString aAdjName; - if (aAdjustmentSeq[i].Name.isEmpty()) - aAdjName = aAdjustments[i]; + OString aAdjName = aAdjustmentSeq[i].Name.isEmpty() + ? aAdjustments[i] + : aAdjustmentSeq[i].Name.toUtf8(); mpFS->singleElementNS( XML_a, XML_gd, - XML_name, aAdjustmentSeq[ i ].Name.getLength() > 0 ? USS(aAdjustmentSeq[ i ].Name) : aAdjName.getStr(), - XML_fmla, OString("val " + OString::number( nValue )).getStr(), + XML_name, aAdjName, + XML_fmla, OString("val " + OString::number(nValue)), FSEND ); } } diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx index d94183a207b2..d615d2ec32da 100644 --- a/oox/source/export/shapes.cxx +++ b/oox/source/export/shapes.cxx @@ -728,7 +728,7 @@ ShapeExport& ShapeExport::WriteCustomShape( const Reference< XShape >& xShape ) EscherPropertyContainer::IsDefaultObject( rSdrObjCustomShape, eShapeType)); - const char* sPresetShape = msfilter::util::GetOOXMLPresetGeometry( USS( sShapeType ) ); + const char* sPresetShape = msfilter::util::GetOOXMLPresetGeometry(sShapeType.toUtf8().getStr()); SAL_INFO("oox.shape", "custom shape type: " << sShapeType << " ==> " << sPresetShape); Sequence< PropertyValue > aGeometrySeq; sal_Int32 nAdjustmentValuesIndex = -1; @@ -806,7 +806,7 @@ ShapeExport& ShapeExport::WriteCustomShape( const Reference< XShape >& xShape ) mpURLTransformer->isExternalURL(sURL)); mpFS->singleElementNS( XML_a, XML_hlinkClick, - FSNS( XML_r,XML_id ), USS( sRelId ), + FSNS(XML_r,XML_id), sRelId.toUtf8(), FSEND ); } } @@ -1143,8 +1143,10 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape pFS->startElementNS( mnXmlNamespace, XML_cNvPr, XML_id, I32S( GetNewShapeID( xShape ) ), - XML_name, bHaveName ? USS( sName ) : OString( "Picture " + OString::number( mnPictureIdMax++ )).getStr(), - XML_descr, bHaveDesc ? USS( sDescr ) : nullptr, + XML_name, bHaveName + ? sName.toUtf8() + : OString("Picture " + OString::number(mnPictureIdMax++)), + XML_descr, bHaveDesc ? sDescr.toUtf8().getStr() : nullptr, FSEND ); // OOXTODO: //cNvPr children: XML_extLst, XML_hlinkClick, XML_hlinkHover @@ -1481,7 +1483,8 @@ ShapeExport& ShapeExport::WriteShape( const Reference< XShape >& xShape ) { OUString sShapeType = xShape->getShapeType(); SAL_INFO("oox.shape", "write shape: " << sShapeType); - NameToConvertMapType::const_iterator aConverter = lcl_GetConverters().find(USS(sShapeType)); + NameToConvertMapType::const_iterator aConverter + = lcl_GetConverters().find(sShapeType.toUtf8().getStr()); if (aConverter == lcl_GetConverters().end()) { SAL_INFO("oox.shape", "unknown shape"); @@ -2061,7 +2064,7 @@ ShapeExport& ShapeExport::WriteOLE2Shape( const Reference< XShape >& xShape ) { mpFS->startElementNS( mnXmlNamespace, XML_oleObj, XML_progId, pProgID, - FSNS(XML_r, XML_id), USS( sRelId ), + FSNS(XML_r, XML_id), sRelId.toUtf8(), XML_spid, "", FSEND ); } @@ -2069,7 +2072,7 @@ ShapeExport& ShapeExport::WriteOLE2Shape( const Reference< XShape >& xShape ) { mpFS->startElementNS( mnXmlNamespace, XML_oleObj, //? XML_name, "Document", - FSNS(XML_r, XML_id), USS( sRelId ), + FSNS(XML_r, XML_id), sRelId.toUtf8(), // The spec says that this is a required attribute, but PowerPoint can only handle an empty value. XML_spid, "", FSEND ); |