Extended loplugin:ostr: filter

Change-Id: I1c45cecb97789a3fc229084de1b7b4968d6069c6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159699
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann
2023-11-19 20:42:51 +01:00
parent f94351f54b
commit 1b19c6b7d0
4 changed files with 33 additions and 30 deletions

View File

@@ -65,7 +65,7 @@ CPPUNIT_TEST_FIXTURE(SvgFilterTest, testPreserveJpg)
// Make sure that the original JPG data is reused and we don't perform a PNG re-compress. // Make sure that the original JPG data is reused and we don't perform a PNG re-compress.
xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream);
OUString aAttributeValue = getXPath(pXmlDoc, "//svg:image", "href"); OUString aAttributeValue = getXPath(pXmlDoc, "//svg:image"_ostr, "href"_ostr);
// Without the accompanying fix in place, this test would have failed with: // Without the accompanying fix in place, this test would have failed with:
// - Expression: aAttributeValue.startsWith("data:image/jpeg") // - Expression: aAttributeValue.startsWith("data:image/jpeg")
@@ -93,7 +93,7 @@ CPPUNIT_TEST_FIXTURE(SvgFilterTest, testSemiTransparentLine)
// Get the style of the group around the actual <path> element. // Get the style of the group around the actual <path> element.
xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream);
OUString aStyle = getXPath( OUString aStyle = getXPath(
pXmlDoc, "//svg:g[@class='com.sun.star.drawing.LineShape']/svg:g/svg:g", "style"); pXmlDoc, "//svg:g[@class='com.sun.star.drawing.LineShape']/svg:g/svg:g"_ostr, "style"_ostr);
// Without the accompanying fix in place, this test would have failed, as the style was // Without the accompanying fix in place, this test would have failed, as the style was
// "mask:url(#mask1)", not "opacity: <value>". // "mask:url(#mask1)", not "opacity: <value>".
CPPUNIT_ASSERT(aStyle.startsWith("opacity: ", &aStyle)); CPPUNIT_ASSERT(aStyle.startsWith("opacity: ", &aStyle));
@@ -119,8 +119,9 @@ CPPUNIT_TEST_FIXTURE(SvgFilterTest, testSemiTransparentFillWithTransparentLine)
// Get the style of the group around the actual <path> element. // Get the style of the group around the actual <path> element.
xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream);
OUString aStyle = getXPath( OUString aStyle
pXmlDoc, "//svg:g[@class='com.sun.star.drawing.EllipseShape']/svg:g/svg:g", "style"); = getXPath(pXmlDoc, "//svg:g[@class='com.sun.star.drawing.EllipseShape']/svg:g/svg:g"_ostr,
"style"_ostr);
CPPUNIT_ASSERT(aStyle.startsWith("opacity: ", &aStyle)); CPPUNIT_ASSERT(aStyle.startsWith("opacity: ", &aStyle));
int nPercent = std::round(aStyle.toDouble() * 100); int nPercent = std::round(aStyle.toDouble() * 100);
// Make sure that the line is still 50% opaque // Make sure that the line is still 50% opaque
@@ -128,7 +129,8 @@ CPPUNIT_TEST_FIXTURE(SvgFilterTest, testSemiTransparentFillWithTransparentLine)
// Get the stroke of the fill of the EllipseShape (it must be "none") // Get the stroke of the fill of the EllipseShape (it must be "none")
OUString aStroke = getXPath( OUString aStroke = getXPath(
pXmlDoc, "//svg:g[@class='com.sun.star.drawing.EllipseShape']/svg:g/svg:path", "stroke"); pXmlDoc, "//svg:g[@class='com.sun.star.drawing.EllipseShape']/svg:g/svg:path"_ostr,
"stroke"_ostr);
// Without the accompanying fix in place, this test would have failed, as the stroke was // Without the accompanying fix in place, this test would have failed, as the stroke was
// "rgb(255,255,255)", not "none". // "rgb(255,255,255)", not "none".
CPPUNIT_ASSERT_EQUAL(OUString("none"), aStroke); CPPUNIT_ASSERT_EQUAL(OUString("none"), aStroke);
@@ -163,13 +165,13 @@ CPPUNIT_TEST_FIXTURE(SvgFilterTest, testSemiTransparentText)
// - Actual : 1 // - Actual : 1
// i.e. the 2nd shape lots its text. // i.e. the 2nd shape lots its text.
assertXPath(pXmlDoc, "//svg:g[@class='TextShape']//svg:text", 2); assertXPath(pXmlDoc, "//svg:g[@class='TextShape']//svg:text"_ostr, 2);
// First shape has semi-transparent text. // First shape has semi-transparent text.
assertXPath(pXmlDoc, "//svg:text[1]/svg:tspan/svg:tspan/svg:tspan[@fill-opacity='0.8']"); assertXPath(pXmlDoc, "//svg:text[1]/svg:tspan/svg:tspan/svg:tspan[@fill-opacity='0.8']"_ostr);
// Second shape has normal text. // Second shape has normal text.
assertXPath(pXmlDoc, "//svg:text[2]/svg:tspan/svg:tspan/svg:tspan[@fill-opacity]", 0); assertXPath(pXmlDoc, "//svg:text[2]/svg:tspan/svg:tspan/svg:tspan[@fill-opacity]"_ostr, 0);
} }
CPPUNIT_TEST_FIXTURE(SvgFilterTest, testSemiTransparentMultiParaText) CPPUNIT_TEST_FIXTURE(SvgFilterTest, testSemiTransparentMultiParaText)
@@ -207,20 +209,20 @@ CPPUNIT_TEST_FIXTURE(SvgFilterTest, testSemiTransparentMultiParaText)
// Then make sure that the two semi-transparent paragraphs have the same X position: // Then make sure that the two semi-transparent paragraphs have the same X position:
xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream);
assertXPath(pXmlDoc, "(//svg:g[@class='TextShape']//svg:tspan[@class='TextPosition'])[1]", "x", assertXPath(pXmlDoc, "(//svg:g[@class='TextShape']//svg:tspan[@class='TextPosition'])[1]"_ostr,
"250"); "x"_ostr, "250");
assertXPath(pXmlDoc, assertXPath(pXmlDoc,
"(//svg:g[@class='TextShape']//svg:tspan[@class='TextPosition'])[1]/svg:tspan", "(//svg:g[@class='TextShape']//svg:tspan[@class='TextPosition'])[1]/svg:tspan"_ostr,
"fill-opacity", "0.8"); "fill-opacity"_ostr, "0.8");
// Without the accompanying fix in place, this test would have failed with: // Without the accompanying fix in place, this test would have failed with:
// - Expected: 250 // - Expected: 250
// - Actual : 8819 // - Actual : 8819
// i.e. the X position of the second paragraph was wrong. // i.e. the X position of the second paragraph was wrong.
assertXPath(pXmlDoc, "(//svg:g[@class='TextShape']//svg:tspan[@class='TextPosition'])[2]", "x", assertXPath(pXmlDoc, "(//svg:g[@class='TextShape']//svg:tspan[@class='TextPosition'])[2]"_ostr,
"250"); "x"_ostr, "250");
assertXPath(pXmlDoc, assertXPath(pXmlDoc,
"(//svg:g[@class='TextShape']//svg:tspan[@class='TextPosition'])[2]/svg:tspan", "(//svg:g[@class='TextShape']//svg:tspan[@class='TextPosition'])[2]/svg:tspan"_ostr,
"fill-opacity", "0.8"); "fill-opacity"_ostr, "0.8");
} }
CPPUNIT_TEST_FIXTURE(SvgFilterTest, testShapeNographic) CPPUNIT_TEST_FIXTURE(SvgFilterTest, testShapeNographic)
@@ -266,7 +268,8 @@ CPPUNIT_TEST_FIXTURE(SvgFilterTest, testCustomBullet)
// i.e. the custom bullet used '<use transform="scale(285,285)" // i.e. the custom bullet used '<use transform="scale(285,285)"
// xlink:href="#bullet-char-template-45"/>', but nobody produced a bullet-char-template-45, // xlink:href="#bullet-char-template-45"/>', but nobody produced a bullet-char-template-45,
// instead we need the path of the glyph inline. // instead we need the path of the glyph inline.
CPPUNIT_ASSERT(!getXPath(pXmlDoc, "//svg:g[@class='BulletChars']//svg:path", "d").isEmpty()); CPPUNIT_ASSERT(
!getXPath(pXmlDoc, "//svg:g[@class='BulletChars']//svg:path"_ostr, "d"_ostr).isEmpty());
} }
CPPUNIT_TEST_FIXTURE(SvgFilterTest, attributeRedefinedTest) CPPUNIT_TEST_FIXTURE(SvgFilterTest, attributeRedefinedTest)
@@ -298,17 +301,17 @@ CPPUNIT_TEST_FIXTURE(SvgFilterTest, attributeRedefinedTest)
// <tspan id="id14" id="id15" id="id17" class="TextParagraph" font-family="Bahnschrift Light" font-size="1129px" font-weight="400"> // <tspan id="id14" id="id15" id="id17" class="TextParagraph" font-family="Bahnschrift Light" font-size="1129px" font-weight="400">
OString xPath = "//svg:g[@class='TextShape']//svg:text[@class='SVGTextShape']//" OString xPath = "//svg:g[@class='TextShape']//svg:text[@class='SVGTextShape']//"
"svg:tspan[@class='TextParagraph']"; "svg:tspan[@class='TextParagraph']"_ostr;
assertXPath(pXmlDoc, xPath, 4); assertXPath(pXmlDoc, xPath, 4);
//assert that each tspan element with TextParagraph class has id and the tspan element of //assert that each tspan element with TextParagraph class has id and the tspan element of
//each empty paragraph does not contain tspan element with class TextPosition //each empty paragraph does not contain tspan element with class TextPosition
assertXPath(pXmlDoc, xPath + "[1]", "id", "id4"); assertXPath(pXmlDoc, xPath + "[1]", "id"_ostr, "id4");
assertXPath(pXmlDoc, xPath + "[2]", "id", "id5"); assertXPath(pXmlDoc, xPath + "[2]", "id"_ostr, "id5");
assertXPath(pXmlDoc, xPath + "[2]//svg:tspan[@class='TextPosition']", 0); assertXPath(pXmlDoc, xPath + "[2]//svg:tspan[@class='TextPosition']", 0);
assertXPath(pXmlDoc, xPath + "[3]", "id", "id6"); assertXPath(pXmlDoc, xPath + "[3]", "id"_ostr, "id6");
assertXPath(pXmlDoc, xPath + "[3]//svg:tspan[@class='TextPosition']", 0); assertXPath(pXmlDoc, xPath + "[3]//svg:tspan[@class='TextPosition']", 0);
assertXPath(pXmlDoc, xPath + "[4]", "id", "id7"); assertXPath(pXmlDoc, xPath + "[4]", "id"_ostr, "id7");
} }
CPPUNIT_TEST_FIXTURE(SvgFilterTest, testTab) CPPUNIT_TEST_FIXTURE(SvgFilterTest, testTab)
@@ -343,7 +346,7 @@ CPPUNIT_TEST_FIXTURE(SvgFilterTest, testTab)
// - Expected: 2 // - Expected: 2
// - Actual : 1 // - Actual : 1
// i.e. the 2nd text portion was not positioned, which looked as if the tab is lost. // i.e. the 2nd text portion was not positioned, which looked as if the tab is lost.
assertXPath(pXmlDoc, "//svg:g[@class='TextShape']//svg:tspan[@class='TextPosition']", 2); assertXPath(pXmlDoc, "//svg:g[@class='TextShape']//svg:tspan[@class='TextPosition']"_ostr, 2);
} }
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();

View File

@@ -1019,7 +1019,7 @@ OString GetOOXMLPresetGeometry( std::u16string_view rShapeType )
{ u"ooxml-rect", "rect" }, { u"ooxml-rect", "rect" },
}; };
auto i(aCustomShapeTypeTranslationHashMap.find(rShapeType)); auto i(aCustomShapeTypeTranslationHashMap.find(rShapeType));
return i == aCustomShapeTypeTranslationHashMap.end() ? "rect" : i->second; return i == aCustomShapeTypeTranslationHashMap.end() ? "rect"_ostr : i->second;
} }
MSO_SPT GETVMLShapeType(std::u16string_view aType) MSO_SPT GETVMLShapeType(std::u16string_view aType)

View File

@@ -766,7 +766,7 @@ bool SVGFilter::implExportImpressOrDraw( const Reference< XOutputStream >& rxOSt
aCodec.BeginCompression( ZCODEC_DEFAULT_COMPRESSION, /*gzLib*/true ); aCodec.BeginCompression( ZCODEC_DEFAULT_COMPRESSION, /*gzLib*/true );
// the inner modify time/filename doesn't really matter in this context because // the inner modify time/filename doesn't really matter in this context because
// compressed graphic formats are meant to be opened as is - not to be extracted // compressed graphic formats are meant to be opened as is - not to be extracted
aCodec.SetCompressionMetadata( "inner", 0, nUncompressedCRC32 ); aCodec.SetCompressionMetadata( "inner"_ostr, 0, nUncompressedCRC32 );
aCodec.Compress( aTempStm, aCompressedStm ); aCodec.Compress( aTempStm, aCompressedStm );
sal_uInt32 nTotalIn = static_cast< sal_uInt32 >( aCodec.EndCompression() ); sal_uInt32 nTotalIn = static_cast< sal_uInt32 >( aCodec.EndCompression() );
if ( aCompressedStm.GetError() || nTotalIn != aDataSize ) if ( aCompressedStm.GetError() || nTotalIn != aDataSize )

View File

@@ -82,13 +82,13 @@ namespace XSLT
{ {
if (!m_storage || !m_storage->hasByName(streamName)) if (!m_storage || !m_storage->hasByName(streamName))
{ {
return "Not Found:";// + streamName; return "Not Found:"_ostr;// + streamName;
} }
Reference<XInputStream> subStream(m_storage->getByName(streamName), UNO_QUERY); Reference<XInputStream> subStream(m_storage->getByName(streamName), UNO_QUERY);
if (!subStream.is()) if (!subStream.is())
{ {
return "Not Found:";// + streamName; return "Not Found:"_ostr;// + streamName;
} }
//The first four byte are the length of the uncompressed data //The first four byte are the length of the uncompressed data
Sequence<sal_Int8> aLength(4); Sequence<sal_Int8> aLength(4);
@@ -98,7 +98,7 @@ namespace XSLT
int readbytes = subStream->readBytes(aLength, 4); int readbytes = subStream->readBytes(aLength, 4);
if (4 != readbytes) if (4 != readbytes)
{ {
return "Can not read the length."; return "Can not read the length."_ostr;
} }
sal_Int32 const oleLength = (static_cast<sal_uInt8>(aLength[0]) << 0U) sal_Int32 const oleLength = (static_cast<sal_uInt8>(aLength[0]) << 0U)
| (static_cast<sal_uInt8>(aLength[1]) << 8U) | (static_cast<sal_uInt8>(aLength[1]) << 8U)
@@ -106,14 +106,14 @@ namespace XSLT
| (static_cast<sal_uInt8>(aLength[3]) << 24U); | (static_cast<sal_uInt8>(aLength[3]) << 24U);
if (oleLength < 0) if (oleLength < 0)
{ {
return "invalid oleLength"; return "invalid oleLength"_ostr;
} }
Sequence<sal_Int8> content(oleLength); Sequence<sal_Int8> content(oleLength);
//Read all bytes. The compressed length should be less than the uncompressed length //Read all bytes. The compressed length should be less than the uncompressed length
readbytes = subStream->readBytes(content, oleLength); readbytes = subStream->readBytes(content, oleLength);
if (oleLength < readbytes) if (oleLength < readbytes)
{ {
return "oleLength";// +oleLength + readBytes; return "oleLength"_ostr;// +oleLength + readBytes;
} }
// Decompress the bytes // Decompress the bytes