EtheaDev / SVGIconImageList

Three engines to render SVG (Delphi Image32, Skia4Delphi, Direct2D wrapper) and four components to simplify use of SVG images (resize, fixedcolor, grayscale...)
Apache License 2.0
321 stars 93 forks source link

URL with single quotes #172

Closed pyscripter closed 3 years ago

pyscripter commented 3 years ago

I have seen svgs with the url enclosed in single quotes e.g.

  <circle cx="5" cy="5" r="4" fill="url('#myGradient')" />

from https://developer.mozilla.org/en-US/docs/Web/SVG/Element/radialGradient

Pascal SVG does not handle this.

To fix in SVGParse.pas change ParseURI to

function ParseURI(const URI: string; EmptyOnFail: Boolean): string;
var
  S: string;
begin
  if EmptyOnFail then
    Result := ''
  else
    Result := URI;
  if URI <> '' then
  begin
    S := Trim(URI);
    if (Copy(S, 1, 5) = 'url(#') and (S[Length(S)] = ')') then
      Result := Copy(S, 6, Length(S) - 6);
    // Remove single quotes
    if (Length(Result) > 0) and (Result[1] ='''') and (Result[Length(Result)]='''') then
       Result := Copy(Result, 2, Length(Result) - 2);
  end;
end;

Two lines aded.