FPvectorial "Unsupported vector graphics" lazarus / 54-FPvectorial ---------------------------------------------------------------------- Edson · 2015-09-09 23:09 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. ---------------------------------------------------------------------- felipemdc · 2015-09-10 07:59 Use fpvectorial from Lazarus SVN, svg is supported: http://wiki.lazarus.freepascal.org/Getting_Lazarus#Getting_SVN ---------------------------------------------------------------------- Edson · 2015-09-10 15:57 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. ---------------------------------------------------------------------- wp · 2015-09-10 16:37 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 · 2015-09-10 16:47 This is my sample project. Maybe I'm doing something wrong. ---------------------------------------------------------------------- wp · 2015-09-10 17:18 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: 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. ---------------------------------------------------------------------- wp · 2015-09-10 17:46 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 · 2015-09-10 18:26 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. ---------------------------------------------------------------------- wp · 2015-09-10 18:33 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 · 2015-09-10 18:47 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. ---------------------------------------------------------------------- wp · 2015-09-10 19:46 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 · 2015-09-10 20:17 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. ---------------------------------------------------------------------- wp · 2015-09-10 20:42 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 · 2015-09-11 15:33 There are more differences if you see the other files. Look at this picture to compare. ---------------------------------------------------------------------- wp · 2016-01-01 23:50 Interim report: still far from perfect, but more and more svg files are rendered correctly with the current version of fpvectorial - see screenshot. ---------------------------------------------------------------------- felipemdc · 2016-06-22 20:15 I'm happy you like the progress that has been made SVG is a priority, but it is a really, really hard format to support .... too much flexibility, too many possible ways to describe the same thing. It is the most challenging format from our support list. ---------------------------------------------------------------------- Edson · 2016-06-23 05:11 Quote from: wp on January 02, 2016, 12:50:45 amInterim report: still far from perfect, but more and more svg files are rendered correctly with the current version of fpvectorial - see screenshot. Good. I haven't checked recently SVG on fpvectorial, but I see there are improvements. I will return to SVG later.