Recent

Author Topic: FPvectorial "Unsupported vector graphics"  (Read 20744 times)

Edson

  • Hero Member
  • *****
  • Posts: 1296
FPvectorial "Unsupported vector graphics"
« on: September 10, 2015, 01:09:58 am »
Hi.

Triying to show a simple SVG file, using:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  Vec: TvVectorialDocument;
begin
  Vec := TvVectorialDocument.Create;
  try
    Vec.ReadFromFile('d:\triac.svg');
    Vec.GetPage(0).DrawBackground(Image1.Canvas);
    Vec.GetPage(0).Render(
      Image1.Canvas,      0,      Image1.Height,      1,      -1);
    Image1.Invalidate;
  finally
    Vec.Free;
  end;
end;

And I get the error: "Unsupported vector graphics".

How do I know what formats are supported by FPvectorial?

Thanks.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: FPvectorial "Unsupported vector graphics"
« Reply #1 on: September 10, 2015, 09:59:42 am »
Use fpvectorial from Lazarus SVN, svg is supported: http://wiki.lazarus.freepascal.org/Getting_Lazarus#Getting_SVN

Edson

  • Hero Member
  • *****
  • Posts: 1296
Re: FPvectorial "Unsupported vector graphics"
« Reply #2 on: September 10, 2015, 05:57:55 pm »
Testing with the SVN version. The same error.

I have used 4 or 5 different SVG files (all of them can be correctly shown on the browser) with no success.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: FPvectorial "Unsupported vector graphics"
« Reply #3 on: September 10, 2015, 06:37:46 pm »
Please post these svg files here. FPVectorial does not claim to be able to read all files.

Do you have the svgvectorialreader in the uses clause?

Edson

  • Hero Member
  • *****
  • Posts: 1296
Re: FPvectorial "Unsupported vector graphics"
« Reply #4 on: September 10, 2015, 06:47:51 pm »
This is my sample project. Maybe I'm doing something wrong.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: FPvectorial "Unsupported vector graphics"
« Reply #5 on: September 10, 2015, 07:18:57 pm »
As I wrote above, add "svgvectorialreader" to the uses clause of the main form. This is because fpvectorial supports a variety of file formats but links only the needed ones into your program.

Add fpvectorialpkg as a requirement to the project (instead of adding it to the search path), i.e. open project inspector, "Add", "New requirement", type "fpvectorialpkg".

Then the error you report is gone. But the program still does not run, it does not like the parts marked in red:

<path fill="#999999" d="M1,16C1,7.72,7.71,1,16,1c8.279,0,15,6.72,15,15c0,8.29-6.721,15-15,15C7.71,31,1,24.29,1,16z"/>

Unfortunately, I do not know much about svg. What does the "-" token stand for? A mathematical operation (subtraction)? If yes, replace them by the difference values.
« Last Edit: September 10, 2015, 07:20:43 pm by wp »

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: FPvectorial "Unsupported vector graphics"
« Reply #6 on: September 10, 2015, 07:46:13 pm »
After some experimenting I see that the '-' seems to be an ordinary minus sign of a negative number. After inserting a comma before the '-' the file is read without error.

Certainly the parser of the svg reader should be clever enough to catch this case. Maybe I'll write a patch.

Edson

  • Hero Member
  • *****
  • Posts: 1296
Re: FPvectorial "Unsupported vector graphics"
« Reply #7 on: September 10, 2015, 08:26:31 pm »
Thanks @wp
You are right. It needs the unit "svgvectorialreader".  :)

And the negative number format, give error, but it's in some way manageable.
Sadly, All my SVG files seems to have this problem.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: FPvectorial "Unsupported vector graphics"
« Reply #8 on: September 10, 2015, 08:33:23 pm »
Which application did you use to create the files? Or are they downloaded from somewhere?

Since Firefox can open your files without issues I suspect that a missing separating space or comma before a minus character is within specification. Therefore, fpvectorial should be able to deal with this special case automatically.

Edson

  • Hero Member
  • *****
  • Posts: 1296
Re: FPvectorial "Unsupported vector graphics"
« Reply #9 on: September 10, 2015, 08:47:40 pm »
I'm triying to use the files from Fritzing: http://fritzing.org/home/

They represent electronic components.

Internet Explorer 11 can show the files correctly, too.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: FPvectorial "Unsupported vector graphics"
« Reply #10 on: September 10, 2015, 09:46:30 pm »
In the meanwhile I could fix the issue and uploaded a patch to bugtracker (http://bugs.freepascal.org/view.php?id=28659).

It may take some time until it is in the release version of Lazarus. If you want to test the patch please copy this procedure over the current one in unit svgvectorialreader.pas (starting at line 274) and recompile the package (of course, this is only a temporary fix, it will be lost whenever you reinstall Lazarus):

Code: [Select]
procedure TSVGPathTokenizer.TokenizePathString(AStr: string);
const
  Str_Space: Char = ' ';
  Str_Comma: Char = ',';
  Str_Plus: Char = '+';
  Str_Minus: Char = '-';
  ListOfCommandLetters: set of Char = ['a'..'d', 'f'..'z', 'A'..'D', 'F'..'Z'];
var
  i: Integer;
  lTmpStr: string = '';
  lState: Integer;
  lFirstTmpStrChar, lCurChar, lPrevChar: Char;
begin
  lState := 0;

  i := 1;
  while i <= Length(AStr) do
  begin
    case lState of
    0: // Adding to the tmp string
    begin
      if i > 0 then lPrevChar := AStr[i-1];
      lCurChar := AStr[i];
      if lCurChar = Str_Space then
      begin
        lState := 1;
        AddToken(lTmpStr);
        lTmpStr := '';
      end
      else if lCurChar = Str_Comma then
      begin
        AddToken(lTmpStr);
        lTmpStr := '';
      end
      else if (lCurChar in [Str_Plus, Str_Minus]) and (lPrevChar in ['0'..'9']) then
      begin
        AddToken(lTmpStr);
        lTmpStr := lCurChar;
      end
      else
      begin
        // Check for a break, from letter to number
        // But don't forget that we need to support 3.799e-4 !!
        // So e is not a valid letter for commands here
        if (Length(lTmpStr) >= 1) then
        begin
          lFirstTmpStrChar := lTmpStr[1];
          if ((lFirstTmpStrChar in ListOfCommandLetters) and not (lCurChar  in ListOfCommandLetters)) or
             (not (lFirstTmpStrChar in ListOfCommandLetters) and (lCurChar  in ListOfCommandLetters)) then
          begin
            AddToken(lTmpStr);
            lTmpStr := '';
            Continue;
          end;
        end;

        lTmpStr := lTmpStr + lCurChar;
      end;

      Inc(i);
    end;
    1: // Removing spaces
    begin
      if AStr[i] <> Str_Space then lState := 0
      else Inc(i);
    end;
    end;
  end;

  // If there is a token still to be added, add it now
  if (lState = 0) and (lTmpStr <> '') then AddToken(lTmpStr);
end;

Edson

  • Hero Member
  • *****
  • Posts: 1296
Re: FPvectorial "Unsupported vector graphics"
« Reply #11 on: September 10, 2015, 10:17:48 pm »
Good. It avoids the error messages.

Although it seems FPvectorial, doesn't draw correctly the SVG files. There is a big difference from what Firefox shows.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: FPvectorial "Unsupported vector graphics"
« Reply #12 on: September 10, 2015, 10:42:20 pm »
I see two differences:
  • the black background (I don't know enough of fpvectorial to get rid of it, but it is possible certainly),
  • the two 45° lines - they seem to be due to another bug.
Is it that what you mean?

Edson

  • Hero Member
  • *****
  • Posts: 1296
Re: FPvectorial "Unsupported vector graphics"
« Reply #13 on: September 11, 2015, 05:33:06 pm »
There are more differences if you see the other files. Look at this picture to compare.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: FPvectorial "Unsupported vector graphics"
« Reply #14 on: January 02, 2016, 12:50:45 am »
Interim report: still far from perfect, but more and more svg files are rendered correctly with the current version of fpvectorial - see screenshot.

 

TinyPortal © 2005-2018