Renames the main fpvectorial example and adds a routine to detect the format from the extension.

git-svn-id: trunk@15826 -
This commit is contained in:
sekelsenmat 2010-08-16 08:18:21 +00:00
parent 8755a60e5c
commit b7d466e8ab
7 changed files with 66 additions and 42 deletions

10
.gitattributes vendored
View File

@ -2373,11 +2373,11 @@ packages/fpmkunit/fpmake.pp svneol=native#text/plain
packages/fpmkunit/src/fpmkunit.pp svneol=native#text/plain
packages/fpvectorial/Makefile svneol=native#text/plain
packages/fpvectorial/Makefile.fpc svneol=native#text/plain
packages/fpvectorial/examples/cdr2svg_mainform.lfm svneol=native#text/plain
packages/fpvectorial/examples/cdr2svg_mainform.pas svneol=native#text/plain
packages/fpvectorial/examples/cdr2svg_visual.ico -text
packages/fpvectorial/examples/cdr2svg_visual.lpi svneol=native#text/plain
packages/fpvectorial/examples/cdr2svg_visual.lpr svneol=native#text/plain
packages/fpvectorial/examples/fpvc_mainform.lfm svneol=native#text/plain
packages/fpvectorial/examples/fpvc_mainform.pas svneol=native#text/plain
packages/fpvectorial/examples/fpvectorialconverter.ico -text
packages/fpvectorial/examples/fpvectorialconverter.lpi svneol=native#text/plain
packages/fpvectorial/examples/fpvectorialconverter.lpr svneol=native#text/plain
packages/fpvectorial/fpmake.pp svneol=native#text/plain
packages/fpvectorial/src/avisocncgcodereader.pas svneol=native#text/plain
packages/fpvectorial/src/avisocncgcodewriter.pas svneol=native#text/plain

View File

@ -1,35 +1,35 @@
object formCDR2SVG: TformCDR2SVG
object formVectorialConverter: TformVectorialConverter
Left = 216
Height = 439
Top = 192
Width = 240
BorderStyle = bsSingle
Caption = 'cdr2svg'
Caption = 'FP Vectorial Converter'
ClientHeight = 439
ClientWidth = 240
LCLVersion = '0.9.29'
object Label1: TLabel
Left = 8
Height = 14
Top = 80
Width = 215
Caption = 'Location of the Input Corel Draw (*.cdr) file:'
Top = 104
Width = 123
Caption = 'Location of the Input file:'
ParentColor = False
end
object Label2: TLabel
Left = 8
Height = 59
Height = 96
Top = 8
Width = 224
AutoSize = False
Caption = 'This example project uses fpvectorial to convert a Corel Draw file (*.cdr) to an SVG (*.svg) vectorial graphics file.'
Caption = 'This converter application use the fpvectorial library to convert between various different vectorial graphics formats. The type is detected from the extension and the supported types are: PDF (*.pdf), SVG (*.svg) and Corel Draw file (*.cdr).'
ParentColor = False
WordWrap = True
end
object editInput: TFileNameEdit
Left = 8
Height = 21
Top = 104
Top = 120
Width = 192
DialogOptions = []
FilterIndex = 0
@ -42,9 +42,9 @@ object formCDR2SVG: TformCDR2SVG
object Label3: TLabel
Left = 8
Height = 14
Top = 138
Width = 154
Caption = 'Full path of the Output SVG file:'
Top = 144
Width = 132
Caption = 'Full path of the Output file:'
ParentColor = False
end
object editOutput: TFileNameEdit
@ -63,7 +63,7 @@ object formCDR2SVG: TformCDR2SVG
object buttonConvert: TButton
Left = 87
Height = 25
Top = 200
Top = 192
Width = 67
Caption = 'Convert'
OnClick = buttonConvertClick
@ -72,7 +72,7 @@ object formCDR2SVG: TformCDR2SVG
object buttonQuit: TButton
Left = 176
Height = 25
Top = 200
Top = 192
Width = 59
Caption = 'Quit'
OnClick = buttonQuitClick
@ -80,14 +80,14 @@ object formCDR2SVG: TformCDR2SVG
end
object imagePreview: TImage
Left = 8
Height = 202
Top = 232
Height = 210
Top = 224
Width = 224
end
object buttonVisualize: TButton
Left = 8
Height = 25
Top = 200
Top = 192
Width = 59
Caption = 'Visualize'
OnClick = buttonVisualizeClick

View File

@ -1,4 +1,4 @@
unit cdr2svg_mainform;
unit fpvc_mainform;
{$mode objfpc}{$H+}
@ -10,9 +10,9 @@ uses
type
{ TformCDR2SVG }
{ TformVectorialConverter }
TformCDR2SVG = class(TForm)
TformVectorialConverter = class(TForm)
buttonVisualize: TButton;
buttonConvert: TButton;
buttonQuit: TButton;
@ -33,7 +33,7 @@ type
end;
var
formCDR2SVG: TformCDR2SVG;
formVectorialConverter: TformVectorialConverter;
implementation
@ -43,14 +43,14 @@ uses
{$R *.lfm}
{ TformCDR2SVG }
{ TformVectorialConverter }
procedure TformCDR2SVG.buttonQuitClick(Sender: TObject);
procedure TformVectorialConverter.buttonQuitClick(Sender: TObject);
begin
Close;
end;
procedure TformCDR2SVG.buttonVisualizeClick(Sender: TObject);
procedure TformVectorialConverter.buttonVisualizeClick(Sender: TObject);
var
Vec: TvVectorialDocument;
begin
@ -68,14 +68,15 @@ begin
end;
end;
function TformCDR2SVG.CheckInput(): Boolean;
function TformVectorialConverter.CheckInput(): Boolean;
begin
// todo...
end;
procedure TformCDR2SVG.buttonConvertClick(Sender: TObject);
procedure TformVectorialConverter.buttonConvertClick(Sender: TObject);
var
Vec: TvVectorialDocument;
lFormat: TvVectorialFormat;
begin
// First check the in input
if not CheckInput() then Exit;
@ -83,8 +84,10 @@ begin
// Now convert
Vec := TvVectorialDocument.Create;
try
Vec.ReadFromFile(editInput.FileName, vfPDF);
Vec.WriteToFile(editOutPut.FileName, vfSVG);
lFormat := TvVectorialDocument.GetFormatFromExtension(editInput.FileName);
Vec.ReadFromFile(editInput.FileName, lFormat);
lFormat := TvVectorialDocument.GetFormatFromExtension(editOutPut.FileName);
Vec.WriteToFile(editOutPut.FileName, lFormat);
finally
Vec.Free;
end;

View File

Before

Width:  |  Height:  |  Size: 134 KiB

After

Width:  |  Height:  |  Size: 134 KiB

View File

@ -8,7 +8,7 @@
<AlwaysBuild Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="cdr2svg_visual"/>
<Title Value="fpvectorialconverter"/>
<UseXPManifest Value="True"/>
<Icon Value="0"/>
</General>
@ -35,16 +35,16 @@
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="cdr2svg_visual.lpr"/>
<Filename Value="fpvectorialconverter.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="cdr2svg_visual"/>
<UnitName Value="fpvectorialconverter"/>
</Unit0>
<Unit1>
<Filename Value="cdr2svg_mainform.pas"/>
<Filename Value="fpvc_mainform.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="formCDR2SVG"/>
<ComponentName Value="formVectorialConverter"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="cdr2svg_mainform"/>
<UnitName Value="fpvc_mainform"/>
</Unit1>
</Units>
</ProjectOptions>
@ -52,7 +52,7 @@
<Version Value="9"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="cdr2svg_visual"/>
<Filename Value="fpvectorialconverter"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)\"/>

View File

@ -1,4 +1,4 @@
program cdr2svg_visual;
program fpvectorialconverter;
{$mode objfpc}{$H+}
@ -7,14 +7,14 @@ uses
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, cdr2svg_mainform
Forms, fpvc_mainform
{ you can add units after this };
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TformCDR2SVG, formCDR2SVG);
Application.CreateForm(TformVectorialConverter, formVectorialConverter);
Application.Run;
end.

View File

@ -31,7 +31,12 @@ type
const
{ Default extensions }
{ Multi-purpose document formats }
STR_PDF_EXTENSION = '.pdf';
STR_POSTSCRIPT_EXTENSION = '.ps';
STR_SVG_EXTENSION = '.svg';
STR_CORELDRAW_EXTENSION = '.cdr';
STR_WINMETAFILE_EXTENSION = '.wmf';
type
TSegmentType = (
@ -84,6 +89,7 @@ type
procedure ReadFromFile(AFileName: string; AFormat: TvVectorialFormat);
procedure ReadFromStream(AStream: TStream; AFormat: TvVectorialFormat);
procedure ReadFromStrings(AStrings: TStrings; AFormat: TvVectorialFormat);
class function GetFormatFromExtension(AFileName: string): TvVectorialFormat;
{ Data reading methods }
function GetPath(ANum: Cardinal): TPath;
function GetPathCount: Integer;
@ -527,6 +533,21 @@ begin
end;
end;
class function TvVectorialDocument.GetFormatFromExtension(AFileName: string
): TvVectorialFormat;
var
lExt: string;
begin
lExt := ExtractFileExt(AFileName);
if AnsiCompareText(lExt, STR_PDF_EXTENSION) = 0 then Result := vfPDF
else if AnsiCompareText(lExt, STR_POSTSCRIPT_EXTENSION) = 0 then Result := vfPostScript
else if AnsiCompareText(lExt, STR_SVG_EXTENSION) = 0 then Result := vfSVG
else if AnsiCompareText(lExt, STR_CORELDRAW_EXTENSION) = 0 then Result := vfCorelDrawCDR
else if AnsiCompareText(lExt, STR_WINMETAFILE_EXTENSION) = 0 then Result := vfWindowsMetafileWMF
else
raise Exception.Create('TvVectorialDocument.GetFormatFromExtension: The extension (' + lExt + ') doesn''t match any supported formats.');
end;
function TvVectorialDocument.GetPath(ANum: Cardinal): TPath;
begin
if ANum >= FPaths.Count then raise Exception.Create('TvVectorialDocument.GetPath: Path number out of bounds');