Using FPVectorial. lazarus / 39-Graphics ---------------------------------------------------------------------- cov · 2013-04-12 06:50 How do you use FPVectorial? I want to display a SVG file on a TImage. Is this possible? ---------------------------------------------------------------------- felipemdc · 2013-04-12 07:06 Yes, it is possible thought the SVG support is not very advanced at the moment. Luckly I am working on it at the moment, so I think that in 1 month or so the SVG reader should be getting much better in the following weeks and months. In general you should study the example project, it is in Lazarus-ccr subversion in the folder applications/fpvviewer To render a SVG image you should do something like this: var   Vec: TvVectorialDocument; begin   Vec := TvVectorialDocument.Create;   try     Vec.ReadFromFile(editFileName.FileName);     Vec.GetPage(0).DrawBackground(Drawer.Drawing.Canvas);     Vec.GetPage(0).Render(       Drawer.Drawing.Canvas,       0,       Drawer.Drawing.Height,       1,       -1);     Drawer.Invalidate;   finally     Vec.Free;   end; ---------------------------------------------------------------------- cov · 2013-04-12 08:07 Yes, I have been looking at the VPViewer project (downloaded from svn). I'm not clear of how to draw on the TImage canvas. I've cut-and-pasted your code above and get a SIGSEGV error on Vec.GetPage(0).DrawBackground(Drawer.Drawing.Canvas); ---------------------------------------------------------------------- felipemdc · 2013-04-12 09:03 You have to post all your code, I can guess with so little information. ---------------------------------------------------------------------- cov · 2013-04-12 11:49 Code: [Select]procedure TForm1.FormShow(Sender: TObject); var   Vec: TvVectorialDocument;   CanvasSize: TPoint; begin     with OpenDialog1 do       if Execute then       begin         Vec := TvVectorialDocument.Create;         try           Vec.ReadFromFile(FileName);           Vec.GetPage(0).DrawBackground(Drawer.Drawing.Canvas);//<-SIGSEGV here           Vec.GetPage(0).Render(               Drawer.Drawing.Canvas,               0,               Drawer.Drawing.Height,               1,               -1);           Drawer.Invalidate;         finally           Vec.Free;         end;       end; end;  That's it. Just copied-and-pasted your code, effectively. ---------------------------------------------------------------------- felipemdc · 2013-04-12 11:53 It should not compile at all, since you probably have no Drawer object in your code. You need to substitute "Drawer.Drawing.Canvas" with your destination Canvas. What is the name of your TImage control? Try something like MyImage.Picture.Bitmap.Canvas and MyImage.Picture.Bitmap.Height respectively for the Canvas and the Height Also, creating a dialog in OnShow does not look a good idea, I'd rather place a button to run this code. ---------------------------------------------------------------------- cov · 2013-04-12 12:19 Great! That's what I was asking, thank you! I'll give that a go... ---------------------------------------------------------------------- cov · 2013-04-12 12:58 Thanks, Felipe; that works. Code: [Select]  Image1.Canvas.Brush.Color:=clWhite;   Image1.Canvas.FillRect(0,0,Image1.Width,Image1.Height);   Vec.ReadFromFile(sFname);   Vec.GetPage(0).DrawBackground(Image1.Canvas);   Vec.GetPage(0).Render(               Image1.Canvas,               0,               Image1.Height,               1,               -1);   Image1.Invalidate; //<- Not sure what this does... The Image Canvas needs to be filled with white before the SVG is drawn otherwise it appears to be filled with black and (as the image appears to be drawn with a black pen only) no image appears. Also the SVG appears to be mostly drawn off screen, no matter what size the Image Canvas is (2 screenshots attached) 1. Is there a way to control the placement of the SVG image? 2. Is it possible to control the colour of the pen so that the image is rendered in it's original colours? ---------------------------------------------------------------------- felipemdc · 2013-04-12 13:03 Quote from: cov on April 12, 2013, 02:58:33 pm1. Is there a way to control the placement of the SVG image? Yes, that's what the 2nd and 3rd parameters are for. Try for example:   Vec.GetPage(0).Render(               Image1.Canvas,               0,               Image1.Height - 200, Quote2. Is it possible to control the colour of the pen so that the image is rendered in it's original colours? Use the latest subversion fpvectorial. I fixed a problem with SVG colors some days ago. If this doesn't solve the problem, please attach the SVG file. ---------------------------------------------------------------------- cov · 2013-04-12 14:12 Thanks Felipe. Code: [Select]  Vec.GetPage(0).Render(Image1.Canvas,0,0,1,-1);    Seems to work. How do you resize the image? It's awfully small. I've downloaded the SVN from today: the pen is still black although the image should be in colour. The SVG file is here (too large to be uploaded). ---------------------------------------------------------------------- felipemdc · 2013-04-12 14:15 Quote from: cov on April 12, 2013, 04:12:43 pmSeems to work. How do you resize the image? It's awfully small. That's what the 4th and 5th parameters do. To enlarge it by 2x for example do:   Vec.GetPage(0).Render(Image1.Canvas,0,Image1.Height,2,-2); ---------------------------------------------------------------------- felipemdc · 2013-04-12 14:17 If this file was originally made with AutoCad you could try opening a DXF version of it in fpvectorial for now. DXF and PostScript are the best supported formats at the moment. I am working on improving the SVG support. ---------------------------------------------------------------------- cov · 2013-04-12 14:36 Okay, If that will control the size, that would be great. Also should give the cabability of being able to zoom in and out. Is the colour enabled in the latest code? That would be quite important. Perhaps the svn update didn't take? Is it possible to change the colours? Maybe have the background as black and the black lines drawn in white? Using a DXF file wouldn't quite suit my purpose which is to have a thumbnail so that the user can check if he has the right drawing. WMF would be OK, though. ---------------------------------------------------------------------- felipemdc · 2013-04-12 14:50 Quote from: cov on April 12, 2013, 04:36:43 pmIs the colour enabled in the latest code? That would be quite important. Perhaps the svn update didn't take? It is, but it seams that your image uses something else. SVG is really huge ... there are 100s of ways of writing the same drawing in SVG. And this complicates it a lot. QuoteIs it possible to change the colours? Maybe have the background as black and the black lines drawn in white? Yes, check the "force background color" option in fpvviewer, thought I wrote this option for DXF, so I'm not sure how it will work in SVG. QuoteUsing a DXF file wouldn't quite suit my purpose which is to have a thumbnail so that the user can check if he has the right drawing. WMF would be OK, though. I don't see why it would not be suitable. DXF is fully vectorial. Try opening a DXF file with fpvviewer and use the mouse whell to zoom. You can zoom-in/out as much as you want in DXF. ---------------------------------------------------------------------- cov · 2013-04-12 15:00 Okay, I'll try that. The reason DXF isn't suitable is that an AutoCAD drawing can be (usually is) split into an area called Modelspace with one or more 'Paperspace' views that will incorporate information such as annotations, Drawing borders, titleblocks, revision information, etc that won't necessarily be on the modelspace area. The SVG file is a snapshot that takes the Paperspace view that was last looked at (or the Modelspace, if the Drawing was saved in that mode). ---------------------------------------------------------------------- cov · 2013-04-12 20:44 Hmmm. Getting a SIGSEGV exception. I've setup the Form.Image1 onShow:Code: [Select]    Vec := TvVectorialDocument.Create;     Image1.Canvas.Brush.Color:=clWhite;     Image1.Canvas.FillRect(0,0,Image1.Width,Image1.Height);     Vec.ReadFromFile(tmpPath+'thumb.svg'); Then Form1.FormResize:Code: [Select]  scale:=Image1.Width/250;   Vec.GetPage(0).DrawBackground(Image1.Canvas);   Vec.GetPage(0).Render(             Image1.Canvas,             0,             0,             scale,             -scale);   Image1.Invalidate; This gives a SIGSEGV in 'fpvectorial.pas' on line 4176 Code: [Select]Result := TvVectorialPage(FPages.Items[AIndex]);  How do you alter the size of the Image to match resizing of the Form? ---------------------------------------------------------------------- felipemdc · 2013-04-12 21:16 OnResize is probably being called after OnShow. Essential code should be on OnCreate, not OnShow. ---------------------------------------------------------------------- zamtmn · 2013-04-14 19:57 felipemdc QuoteThat's what the 4th and 5th parameters do. To enlarge it by 2x for example do:   Vec.GetPage(0).Render(Image1.Canvas,0,Image1.Height,2,-2); To correctly display the drawing you need to know its overall dimensions. It would be nice to have a calculation ADestX,ADestY,AMulX,AMulY within the FPV library for a particular ADest ---------------------------------------------------------------------- cov · 2013-04-25 12:14 Quote from: felipemdc on April 12, 2013, 09:06:05 amYes, it is possible thought the SVG support is not very advanced at the moment. Luckly I am working on it at the moment, so I think that in 1 month or so the SVG reader should be getting much better in the following weeks and months. In general you should study the example project, it is in Lazarus-ccr subversion in the folder applications/fpvviewer Hi Felipe, How are you getting on with your SVG implementation? Will it be able to read the SVG file that I showed you? I've put together a very basic parser which draws directly on the Image TCanvas, and while it sort of works, it's not very slick.