fpvectorial-svg: Implements support for rgba colors

git-svn-id: trunk@45319 -
This commit is contained in:
sekelsenmat 2014-06-03 14:38:53 +00:00
parent 604bb5f428
commit 9ad149a4c9

View File

@ -434,6 +434,7 @@ var
lValue, lStr: string; lValue, lStr: string;
lStrings: TStringList; lStrings: TStringList;
i: Integer; i: Integer;
HasAlphaChannel: Boolean = False;
begin begin
Result := colBlack; Result := colBlack;
lValue := Trim(LowerCase(AValue)); lValue := Trim(LowerCase(AValue));
@ -443,15 +444,19 @@ begin
begin begin
lStrings := TStringList.Create; lStrings := TStringList.Create;
try try
lStr := Copy(lValue, 5, Length(lValue)-5); HasAlphaChannel := Copy(lValue, 0, 4) = 'rgba';
if HasAlphaChannel then lStr := Copy(lValue, 6, Length(lValue)-6)
else lStr := Copy(lValue, 5, Length(lValue)-5);
lStrings.Delimiter := ','; lStrings.Delimiter := ',';
lStrings.StrictDelimiter := True; lStrings.StrictDelimiter := True;
lStrings.DelimitedText := lStr; lStrings.DelimitedText := lStr;
if lStrings.Count = 3 then if lStrings.Count in [3, 4] then
begin begin
Result.Red := SVGColorValueStrToWord(lStrings.Strings[0]); Result.Red := SVGColorValueStrToWord(lStrings.Strings[0]);
Result.Green := SVGColorValueStrToWord(lStrings.Strings[1]); Result.Green := SVGColorValueStrToWord(lStrings.Strings[1]);
Result.Blue := SVGColorValueStrToWord(lStrings.Strings[2]); Result.Blue := SVGColorValueStrToWord(lStrings.Strings[2]);
if (lStrings.Count = 4) and HasAlphaChannel then
Result.alpha := StringFloatZeroToOneToWord(lStrings.Strings[3]);
end end
else else
raise Exception.Create(Format('[TvSVGVectorialReader.ReadSVGColor] An unexpected number of channels was found: %d', [lStrings.Count])); raise Exception.Create(Format('[TvSVGVectorialReader.ReadSVGColor] An unexpected number of channels was found: %d', [lStrings.Count]));