Skip to content

Commit 5fef483

Browse files
committed
oox: use a faster color hexification method with hex-in-uppercase.
This reduces the xml diff to MS' generation. Change-Id: I10a3f1db3347d1fb06c0d823e4b5e50104318c91 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191940 Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> Tested-by: Caolán McNamara <[email protected]> (cherry picked from commit 6219a5d) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191944 Tested-by: Jenkins Reviewed-by: Michael Meeks <[email protected]>
1 parent 96834fa commit 5fef483

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

include/oox/export/utils.hxx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,29 @@
2323
#include <sal/config.h>
2424

2525
#include <o3tl/unit_conversion.hxx>
26+
#include <rtl/strbuf.hxx>
2627
#include <rtl/string.hxx>
2728
#include <sal/types.h>
2829

2930
#include <cmath>
3031

32+
// Only used to output rgb colors as hex
3133
inline OString I32SHEX(sal_Int32 x)
3234
{
33-
OString aStr = OString::number(x, 16);
34-
while (aStr.getLength() < 6)
35-
aStr = "0" + aStr;
36-
return aStr;
35+
assert(x <= 0xffffff);
36+
rtl::OStringBuffer aRes(6);
37+
aRes.setLength(6);
38+
sal_Int32 n = 0;
39+
for (int nShift = 24-4; nShift >=0; nShift -= 4)
40+
{
41+
char nDigit = static_cast<char>((x >> nShift) & 0xf);
42+
if ( nDigit > 9 )
43+
aRes[n] = (nDigit-10) + 'A';
44+
else
45+
aRes[n] = (nDigit + '0');
46+
n++;
47+
}
48+
return aRes.makeStringAndClear();
3749
}
3850

3951
/**

sc/qa/unit/ThemeImportExportTest.cxx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,17 @@ CPPUNIT_TEST_FIXTURE(ThemeImportExportTest, testThemeExportOOXML)
121121
OString aClrScheme = "/a:theme/a:themeElements/a:clrScheme"_ostr;
122122
assertXPath(pXmlDoc, aClrScheme, "name", u"Office");
123123
assertXPath(pXmlDoc, aClrScheme + "/a:dk1/a:srgbClr", "val", u"000000");
124-
assertXPath(pXmlDoc, aClrScheme + "/a:lt1/a:srgbClr", "val", u"ffffff");
125-
assertXPath(pXmlDoc, aClrScheme + "/a:dk2/a:srgbClr", "val", u"44546a");
126-
assertXPath(pXmlDoc, aClrScheme + "/a:lt2/a:srgbClr", "val", u"e7e6e6");
127-
assertXPath(pXmlDoc, aClrScheme + "/a:accent1/a:srgbClr", "val", u"4472c4");
128-
assertXPath(pXmlDoc, aClrScheme + "/a:accent2/a:srgbClr", "val", u"ed7d31");
129-
assertXPath(pXmlDoc, aClrScheme + "/a:accent3/a:srgbClr", "val", u"a5a5a5");
130-
assertXPath(pXmlDoc, aClrScheme + "/a:accent4/a:srgbClr", "val", u"ffc000");
131-
assertXPath(pXmlDoc, aClrScheme + "/a:accent5/a:srgbClr", "val", u"5b9bd5");
132-
assertXPath(pXmlDoc, aClrScheme + "/a:accent6/a:srgbClr", "val", u"70ad47");
133-
assertXPath(pXmlDoc, aClrScheme + "/a:hlink/a:srgbClr", "val", u"0563c1");
134-
assertXPath(pXmlDoc, aClrScheme + "/a:folHlink/a:srgbClr", "val", u"954f72");
124+
assertXPath(pXmlDoc, aClrScheme + "/a:lt1/a:srgbClr", "val", u"FFFFFF");
125+
assertXPath(pXmlDoc, aClrScheme + "/a:dk2/a:srgbClr", "val", u"44546A");
126+
assertXPath(pXmlDoc, aClrScheme + "/a:lt2/a:srgbClr", "val", u"E7E6E6");
127+
assertXPath(pXmlDoc, aClrScheme + "/a:accent1/a:srgbClr", "val", u"4472C4");
128+
assertXPath(pXmlDoc, aClrScheme + "/a:accent2/a:srgbClr", "val", u"ED7D31");
129+
assertXPath(pXmlDoc, aClrScheme + "/a:accent3/a:srgbClr", "val", u"A5A5A5");
130+
assertXPath(pXmlDoc, aClrScheme + "/a:accent4/a:srgbClr", "val", u"FFC000");
131+
assertXPath(pXmlDoc, aClrScheme + "/a:accent5/a:srgbClr", "val", u"5B9BD5");
132+
assertXPath(pXmlDoc, aClrScheme + "/a:accent6/a:srgbClr", "val", u"70AD47");
133+
assertXPath(pXmlDoc, aClrScheme + "/a:hlink/a:srgbClr", "val", u"0563C1");
134+
assertXPath(pXmlDoc, aClrScheme + "/a:folHlink/a:srgbClr", "val", u"954F72");
135135
}
136136

137137
{

sd/qa/unit/export-tests-ooxml2.cxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest2, testTdf112333)
13811381
"p:par/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/"
13821382
"p:animClr/p:to/a:srgbClr",
13831383
"val");
1384-
CPPUNIT_ASSERT_EQUAL(u"0563c1"_ustr, sTo);
1384+
CPPUNIT_ASSERT_EQUAL(u"0563C1"_ustr, sTo);
13851385

13861386
sAttributeName = getXPathContent(
13871387
pXmlDocContent, "/p:sld/p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/"
@@ -1694,10 +1694,10 @@ CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest2, testAccentColor)
16941694
u"accent6");
16951695
xmlDocUniquePtr pXmlDocTheme1 = parseExport(u"ppt/theme/theme1.xml"_ustr);
16961696
assertXPath(pXmlDocTheme1, "/a:theme/a:themeElements/a:clrScheme/a:accent6/a:srgbClr", "val",
1697-
u"70ad47");
1697+
u"70AD47");
16981698
xmlDocUniquePtr pXmlDocTheme2 = parseExport(u"ppt/theme/theme2.xml"_ustr);
16991699
assertXPath(pXmlDocTheme2, "/a:theme/a:themeElements/a:clrScheme/a:accent6/a:srgbClr", "val",
1700-
u"deb340");
1700+
u"DEB340");
17011701

17021702
// Without the accompanying fix in place, this test would have failed with:
17031703
// - Expected: Motyw pakietu Office
@@ -1714,9 +1714,9 @@ CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest2, testThemeColors)
17141714

17151715
xmlDocUniquePtr pXmlDocTheme2 = parseExport(u"ppt/theme/theme1.xml"_ustr);
17161716
assertXPath(pXmlDocTheme2, "/a:theme/a:themeElements/a:clrScheme/a:dk2/a:srgbClr", "val",
1717-
u"44546a");
1717+
u"44546A");
17181718
assertXPath(pXmlDocTheme2, "/a:theme/a:themeElements/a:clrScheme/a:accent3/a:srgbClr", "val",
1719-
u"a5a5a5");
1719+
u"A5A5A5");
17201720
}
17211721

17221722
CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest2, testTdf111785)

sd/qa/unit/export-tests-ooxml3.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest3, testTdf114848)
134134

135135
xmlDocUniquePtr pXmlDocTheme1 = parseExport(u"ppt/theme/theme1.xml"_ustr);
136136
assertXPath(pXmlDocTheme1, "/a:theme/a:themeElements/a:clrScheme/a:dk2/a:srgbClr", "val",
137-
u"1f497d");
137+
u"1F497D");
138138
}
139139

140140
CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest3, testTdf147586)
@@ -755,15 +755,15 @@ CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest3, testTdf118835)
755755
xmlDocUniquePtr pXmlDocContent = parseExport(u"ppt/slides/slide1.xml"_ustr);
756756
assertXPath(pXmlDocContent, "(//p:animClr)[1]", "clrSpc", u"rgb");
757757
assertXPathContent(pXmlDocContent, "(//p:animClr)[1]//p:attrName", u"style.color");
758-
assertXPath(pXmlDocContent, "(//p:animClr)[1]//p:to/a:srgbClr", "val", u"ed1c24");
758+
assertXPath(pXmlDocContent, "(//p:animClr)[1]//p:to/a:srgbClr", "val", u"ED1C24");
759759

760760
assertXPath(pXmlDocContent, "(//p:animClr)[2]", "clrSpc", u"rgb");
761761
assertXPathContent(pXmlDocContent, "(//p:animClr)[2]//p:attrName", u"stroke.color");
762762
assertXPath(pXmlDocContent, "(//p:animClr)[2]//p:to/a:srgbClr", "val", u"333399");
763763

764764
assertXPath(pXmlDocContent, "(//p:animClr)[3]", "clrSpc", u"rgb");
765765
assertXPathContent(pXmlDocContent, "(//p:animClr)[3]//p:attrName", u"fillcolor");
766-
assertXPath(pXmlDocContent, "(//p:animClr)[3]//p:to/a:srgbClr", "val", u"fcd3c1");
766+
assertXPath(pXmlDocContent, "(//p:animClr)[3]//p:to/a:srgbClr", "val", u"FCD3C1");
767767

768768
assertXPath(pXmlDocContent, "(//p:animClr)[5]", "clrSpc", u"hsl");
769769
assertXPathContent(pXmlDocContent, "(//p:animClr)[5]//p:attrName", u"fillcolor");

0 commit comments

Comments
 (0)