summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndras Timar <andras.timar@collabora.com>2023-01-04 14:34:49 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2023-01-11 12:01:39 +0000
commit3c42bc6c2bc6d2005d4b00451660cd2d604da623 (patch)
tree75ebf226f1b5659d5618c1097ff3313b337fea71
parentRelated: tdf#152948 Align AddInMap English names to Add-In implementation (diff)
downloadcore-3c42bc6c2bc6d2005d4b00451660cd2d604da623.tar.gz
core-3c42bc6c2bc6d2005d4b00451660cd2d604da623.zip
import colors with transparency from html
The support is limited, but better than before. Before: the color was not imported. After: the color is imported as RGB, as if the background color was white. It is pretty much common in Writer that the background is white. On the other hand, transparency is not supported in many use cases, such as character background in this example green-highlight.html. Change-Id: Ia9449e2535ddfd8cd8c2672cb3bd32987083fdbb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145039 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com> (cherry picked from commit dd13717076e412d7b1079a12adaff01efebf0f80) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145218 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r--sw/qa/extras/htmlimport/data/green-highlight.html1
-rw-r--r--sw/qa/extras/htmlimport/htmlimport.cxx12
-rw-r--r--sw/source/filter/html/parcss1.cxx26
3 files changed, 36 insertions, 3 deletions
diff --git a/sw/qa/extras/htmlimport/data/green-highlight.html b/sw/qa/extras/htmlimport/data/green-highlight.html
new file mode 100644
index 000000000000..b8986e78ffd8
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/green-highlight.html
@@ -0,0 +1 @@
+<p><span style="background-color: #5fb23680">Highlight green (transparency: 0.5)</span></p>
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index b9d9595129f5..c97d4e4cbde4 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -562,6 +562,18 @@ CPPUNIT_TEST_FIXTURE(SwHtmlOptionsImportTest, testOleData2)
CPPUNIT_ASSERT(getProperty<OUString>(xShape, "HyperLinkURL").isEmpty());
}
+CPPUNIT_TEST_FIXTURE(HtmlImportTest, testRGBAColor)
+{
+ createSwWebDoc("green-highlight.html");
+ const uno::Reference<text::XTextRange> xPara = getParagraph(1);
+ const uno::Reference<beans::XPropertySet> xRun(getRun(xPara,1), uno::UNO_QUERY);
+ const Color nBackColor(0xaed89a);
+
+ // Without the accompanying fix in place, this test would have failed, the backround
+ // color was not imported at all, when it was in hex RGBA format in HTML.
+ CPPUNIT_ASSERT_EQUAL(nBackColor, getProperty<Color>(xRun, "CharBackColor"));
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/parcss1.cxx b/sw/source/filter/html/parcss1.cxx
index 50278e160483..0fa73d455fbc 100644
--- a/sw/source/filter/html/parcss1.cxx
+++ b/sw/source/filter/html/parcss1.cxx
@@ -530,11 +530,11 @@ CSS1Token CSS1Parser::GetNextToken()
bool bEOFSave = m_bEOF;
// first try to parse a hex digit
- OUStringBuffer sTmpBuffer(6);
+ OUStringBuffer sTmpBuffer(8);
do {
sTmpBuffer.append( m_cNextCh );
m_cNextCh = GetNextChar();
- } while( sTmpBuffer.getLength() < 7 &&
+ } while( sTmpBuffer.getLength() < 9 &&
( ('0'<=m_cNextCh && '9'>=m_cNextCh) ||
('A'<=m_cNextCh && 'F'>=m_cNextCh) ||
('a'<=m_cNextCh && 'f'>=m_cNextCh) ) &&
@@ -542,7 +542,7 @@ CSS1Token CSS1Parser::GetNextToken()
if( sTmpBuffer.getLength()==6 || sTmpBuffer.getLength()==3 )
{
- // we found a color in hex
+ // we found a color in hex (RGB)
m_aToken += sTmpBuffer;
nRet = CSS1_HEXCOLOR;
bNextCh = false;
@@ -550,6 +550,26 @@ CSS1Token CSS1Parser::GetNextToken()
break;
}
+ if( sTmpBuffer.getLength()==8 )
+ {
+ // we found a color in hex (RGBA)
+ // we convert it to RGB assuming white background
+ sal_uInt32 nColor = sTmpBuffer.makeStringAndClear().toUInt32(16);
+ sal_uInt32 nRed = (nColor & 0xff000000) >> 24;
+ sal_uInt32 nGreen = (nColor & 0xff0000) >> 16;
+ sal_uInt32 nBlue = (nColor & 0xff00) >> 8;
+ double nAlpha = (nColor & 0xff) / 255.0;
+ nRed = (1 - nAlpha) * 255 + nAlpha * nRed;
+ nGreen = (1 - nAlpha) * 255 + nAlpha * nGreen;
+ nBlue = (1 - nAlpha) * 255 + nAlpha * nBlue;
+ nColor = (nRed << 16) + (nGreen << 8) + nBlue;
+ m_aToken += OUString::number(nColor, 16);
+ nRet = CSS1_HEXCOLOR;
+ bNextCh = false;
+
+ break;
+ }
+
// otherwise we try a number
m_nInPos = nInPosSave;
m_cNextCh = cNextChSave;