summaryrefslogtreecommitdiff
path: root/svgio/source/svgreader
diff options
context:
space:
mode:
authorXisco Fauli <anistenis@gmail.com>2016-02-12 01:36:58 +0100
committerNoel Grandin <noelgrandin@gmail.com>2016-02-13 13:38:39 +0000
commit3c8b880c5edc1dcbf0f481c558c6093513df6b45 (patch)
treebcdbe6cbcb48cc5ede632109e6db30428938fd21 /svgio/source/svgreader
parent52942f142ec40f762c1de0751d802fd42eaabed3 (diff)
SVGIO: tdf#97659: Add support for RGBA
Change-Id: Icbf3796cdc95f91d298a5ca52d44931b3985eac6 Reviewed-on: https://gerrit.libreoffice.org/22303 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'svgio/source/svgreader')
-rw-r--r--svgio/source/svgreader/svgstyleattributes.cxx28
-rw-r--r--svgio/source/svgreader/svgtools.cxx50
2 files changed, 65 insertions, 13 deletions
diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx
index 1f592e7d73d7..698f7e8ccd69 100644
--- a/svgio/source/svgreader/svgstyleattributes.cxx
+++ b/svgio/source/svgreader/svgstyleattributes.cxx
@@ -1258,10 +1258,15 @@ namespace svgio
{
SvgPaint aSvgPaint;
OUString aURL;
+ SvgNumber aOpacity;
- if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent))
+ if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent, aOpacity))
{
setFill(aSvgPaint);
+ if(aOpacity.isSet())
+ {
+ setOpacity(SvgNumber(basegfx::clamp(aOpacity.getNumber(), 0.0, 1.0)));
+ }
}
else if(!aURL.isEmpty())
{
@@ -1310,10 +1315,15 @@ namespace svgio
{
SvgPaint aSvgPaint;
OUString aURL;
+ SvgNumber aOpacity;
- if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent))
+ if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent, aOpacity))
{
setStroke(aSvgPaint);
+ if(aOpacity.isSet())
+ {
+ setOpacity(SvgNumber(basegfx::clamp(aOpacity.getNumber(), 0.0, 1.0)));
+ }
}
else if(!aURL.isEmpty())
{
@@ -1448,10 +1458,15 @@ namespace svgio
{
SvgPaint aSvgPaint;
OUString aURL;
+ SvgNumber aOpacity;
- if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent))
+ if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent, aOpacity))
{
setStopColor(aSvgPaint);
+ if(aOpacity.isSet())
+ {
+ setOpacity(SvgNumber(basegfx::clamp(aOpacity.getNumber(), 0.0, 1.0)));
+ }
}
break;
}
@@ -1767,10 +1782,15 @@ namespace svgio
{
SvgPaint aSvgPaint;
OUString aURL;
+ SvgNumber aOpacity;
- if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent))
+ if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent, aOpacity))
{
setColor(aSvgPaint);
+ if(aOpacity.isSet())
+ {
+ setOpacity(SvgNumber(basegfx::clamp(aOpacity.getNumber(), 0.0, 1.0)));
+ }
}
break;
}
diff --git a/svgio/source/svgreader/svgtools.cxx b/svgio/source/svgreader/svgtools.cxx
index ff74d63061aa..a4e4233a805d 100644
--- a/svgio/source/svgreader/svgtools.cxx
+++ b/svgio/source/svgreader/svgtools.cxx
@@ -814,7 +814,7 @@ namespace svgio
}
}
- bool read_color(const OUString& rCandidate, basegfx::BColor& rColor, bool bCaseIndependent)
+ bool read_color(const OUString& rCandidate, basegfx::BColor& rColor, bool bCaseIndependent, SvgNumber& rOpacity)
{
const sal_Int32 nLen(rCandidate.getLength());
@@ -866,8 +866,17 @@ namespace svgio
if(rCandidate.matchIgnoreAsciiCase(aStrRgb, 0))
{
- // rgb definition
+ // rgb/rgba definition
sal_Int32 nPos(strlen(aStrRgb));
+ bool bIsRGBA = false;
+
+ if('a' == rCandidate[nPos])
+ {
+ //Delete the 'a' from 'rbga'
+ skip_char(rCandidate, 'a', nPos, nPos + 1);
+ bIsRGBA = true;
+ }
+
skip_char(rCandidate, ' ', '(', nPos, nLen);
double fR(0.0);
@@ -901,17 +910,39 @@ namespace svgio
if(readNumber(rCandidate, nPos, fB, nLen))
{
- const double fFac(bIsPercent ? 0.01 : fFactor);
-
- rColor.setRed(fR * fFac);
- rColor.setGreen(fG * fFac);
- rColor.setBlue(fB * fFac);
+ double fA(1.0);
if(bIsPercent)
{
skip_char(rCandidate, '%', nPos, nLen);
}
+ skip_char(rCandidate, ' ', ',', nPos, nLen);
+
+ if(readNumber(rCandidate, nPos, fA, nLen))
+ {
+ if(bIsRGBA)
+ {
+ const double fFac(bIsPercent ? 0.01 : 1);
+ rOpacity = SvgNumber(fA * fFac);
+
+ if(bIsPercent)
+ {
+ skip_char(rCandidate, '%', nPos, nLen);
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ const double fFac(bIsPercent ? 0.01 : fFactor);
+
+ rColor.setRed(fR * fFac);
+ rColor.setGreen(fG * fFac);
+ rColor.setBlue(fB * fFac);
+
skip_char(rCandidate, ' ', ')', nPos, nLen);
return true;
}
@@ -1207,13 +1238,14 @@ namespace svgio
return false;
}
- bool readSvgPaint(const OUString& rCandidate, SvgPaint& rSvgPaint, OUString& rURL, bool bCaseIndependent)
+ bool readSvgPaint(const OUString& rCandidate, SvgPaint& rSvgPaint,
+ OUString& rURL, bool bCaseIndependent, SvgNumber& rOpacity)
{
if( !rCandidate.isEmpty() )
{
basegfx::BColor aColor;
- if(read_color(rCandidate, aColor, bCaseIndependent))
+ if(read_color(rCandidate, aColor, bCaseIndependent, rOpacity))
{
rSvgPaint = SvgPaint(aColor, true, true);
return true;