Difference between revisions of "fpvectorial"
Sekelsenmat (talk | contribs) |
Sekelsenmat (talk | contribs) (→SVG) |
||
Line 50: | Line 50: | ||
Following Inkscape and the Opera Browser, FPVectorial also hardcodes to 90 DPI. | Following Inkscape and the Opera Browser, FPVectorial also hardcodes to 90 DPI. | ||
+ | |||
+ | ===DXF=== | ||
+ | |||
+ | The Drawing eXchange Format from Autodesk AutoCAD. This format is documented, but the quality of the documentation is rather low, lacking adequate explanations. | ||
+ | |||
+ | The format itself is rather simple, composed by text. Each unit is composed of two lines, the first one being a number describing the type of data and then another line with the value itself, which might be text or a number. | ||
+ | |||
+ | Link to the documentation: | ||
+ | |||
+ | * http://www.autodesk.com/techpubs/autocad/acad2000/dxf/ | ||
==Usage examples== | ==Usage examples== |
Revision as of 23:08, 26 January 2011
Introduction
FPVectorial offers support to read, modify and write vectorial images.
It's counterpart library is fp-image, which works with raster images. FPVectorial comes with a unit which allows to draw a vectorial image to a TFPCustomCanvas, but no routines are provided to convert raster images to vectorial images.
Current file list
FPVectorial is located in Free Pascal 2.3.1+ in the directory fpc/packages/fpvectorial/src
The central unit is fpvectorial.
Readers and writers for various image formats
- pdfvectorialreader - Read support for PDF files, supports compression, only reads the first page
- avisocncgcodereader - Read support for the G-Code from the Aviso CNC machine
- avisocncgcodewriter - Write support for the G-Code from the Aviso CNC machine
- cdrvectorialreader - Initial work of a reader support for Corel Draw CDR files
- svgvectorialwriter - Write support for SVG. The most advanced at the moment. Supports lines, curves and text
- dxfvectorialreader - Read support for DXF, the Drawing eXchange Format utilized by the AutoCAD
Other units
- fpvtocanvas - Converts a vectorial document to a TFPCustomCanvas descendent (like TCanvas). Essentially converts the vectorial image to a raster image
- pdfvrlexico, pdfvrsemantico, pdfvrsintatico, avisozlib - Other units from the PDF reader, don't use directly
Formats
The PDF format is developed by Adobe (tm) and it is fully documented. Inside, PDF is simply text, so it is rather easy to parse, but parts of this text are usually can be compressed.
Link to the PDF Reference: http://www.adobe.com/devnet/pdf/pdf_reference.html
CorelDraw
Corel does not release public documentation for it's CorelDraw file format. Any information about this format depends on reverse engineering and guessing. The format is binary and consists of a tree of chunks.
SVG
Scalable Vectorial Graphics (SVG) is a standard from W3C for vectorial graphics. It is the native format of Inkscape and stores it's data as a single, uncompressed XML file with the extension ".svg".
Link to the specification: http://www.w3.org/TR/SVG/
A very serious shortcoming in SVG is that it does not allow real world units to be specified in the drawing routines, only pixel values accepted, which makes it impossible to have a document with real world units. This can be worked around by simply hardcoding to a fixed DPI resolution, which is 90 DPI for Inkscape. Read more here:
- http://stackoverflow.com/questions/1346922/svg-and-dpi-absolute-units-and-user-units-inkscape-vs-firefox-vs-imagemagick
- http://www.inkscapeforum.com/viewtopic.php?f=16&t=5904
- http://www.inkscapeforum.com/viewtopic.php?f=16&t=3700&p=17179&hilit=units+path#p17179
Following Inkscape and the Opera Browser, FPVectorial also hardcodes to 90 DPI.
DXF
The Drawing eXchange Format from Autodesk AutoCAD. This format is documented, but the quality of the documentation is rather low, lacking adequate explanations.
The format itself is rather simple, composed by text. Each unit is composed of two lines, the first one being a number describing the type of data and then another line with the value itself, which might be text or a number.
Link to the documentation:
Usage examples
Format conversion
This example loads a PDF, converts it to G-Code and writes the G-Code to a TStrings descendent
<delphi> uses
fpvectorial, pdfvectorialreader, avisocncgcodewriter;
var
Vec: TvVectorialDocument;
begin
if dialogoAbrir.Execute() then begin Vec := TvVectorialDocument.Create; try Vec.ReadFromFile(dialogoAbrir.FileName, vfPDF); Vec.WriteToStrings(synCodigo.Lines, vfGCodeAvisoCNCPrototipoV5); finally Vec.Free; end; end;
end; </delphi>
Drawing paths, bezier lines and text
This example shows how to render various elements.
<delphi> { Author: Felipe Monteiro de Carvalho
License: Public Domain } program fpvwritetest;
{$mode objfpc}{$H+}
uses
fpvectorial, svgvectorialwriter;
const
cFormat = vfSVG; cExtension = '.svg';
var
Vec: TvVectorialDocument;
begin
Vec := TvVectorialDocument.Create; try // All documents are 10cm x 10cm Vec.Width := 100; Vec.Height := 100;
// ...
// multi_test_1 Combines various elements Vec.Clear; Vec.StartPath(0, 20); Vec.AddLineToPath(30, 30); Vec.EndPath(); Vec.StartPath(0, 0); Vec.AddLineToPath(100, 0); Vec.AddLineToPath(100, 100); Vec.AddLineToPath(0, 100); Vec.AddLineToPath(0, 0); Vec.EndPath(); Vec.StartPath(0, 0); Vec.AddLineToPath(10, 10); Vec.AddBezierToPath(10, 20, 20, 20, 20, 10); Vec.AddLineToPath(30, 0); Vec.EndPath(); Vec.AddText(10, 10, 0, '10,10 Some text in english.'); Vec.AddText(20, 20, 0, '20, 20 Mówić, cześć, Włosku, Parabéns.'); Vec.AddText(30, 30, 0, '30, 30 森林,是一个高密'); Vec.WriteToFile('multi_test_1' + cExtension, cFormat); finally Vec.Free; end;
end. </delphi>
And here is the output of this example when rendered by the Opera Browser:
More examples
Please see in the FPC repository: http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/fpvectorial/examples/
Go to back Packages List