fpvectorial: adds new overloaded read/write methods which auto-detect the format

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1631 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat 2011-05-10 15:19:30 +00:00
parent c99184e64d
commit 60d7759c8a
3 changed files with 25 additions and 20 deletions

View File

@ -240,7 +240,8 @@ type
{ Base methods } { Base methods }
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
procedure WriteToFile(AFileName: string; AFormat: TvVectorialFormat); procedure WriteToFile(AFileName: string; AFormat: TvVectorialFormat); overload;
procedure WriteToFile(AFileName: string); overload;
procedure WriteToStream(AStream: TStream; AFormat: TvVectorialFormat); procedure WriteToStream(AStream: TStream; AFormat: TvVectorialFormat);
procedure WriteToStrings(AStrings: TStrings; AFormat: TvVectorialFormat); procedure WriteToStrings(AStrings: TStrings; AFormat: TvVectorialFormat);
procedure ReadFromFile(AFileName: string; AFormat: TvVectorialFormat); overload; procedure ReadFromFile(AFileName: string; AFormat: TvVectorialFormat); overload;
@ -883,6 +884,14 @@ begin
end; end;
end; end;
procedure TvVectorialDocument.WriteToFile(AFileName: string);
var
lFormat: TvVectorialFormat;
begin
lFormat := GetFormatFromExtension(ExtractFileExt(AFileName));
WriteToFile(AFileName, lFormat);
end;
{@@ {@@
Writes the document to a stream Writes the document to a stream
} }
@ -938,15 +947,10 @@ end;
} }
procedure TvVectorialDocument.ReadFromFile(AFileName: string); procedure TvVectorialDocument.ReadFromFile(AFileName: string);
var var
lExt: string; lFormat: TvVectorialFormat;
begin begin
lExt := ExtractFileExt(AFileName); lFormat := GetFormatFromExtension(ExtractFileExt(AFileName));
if lExt = STR_PDF_EXTENSION then ReadFromFile(AFileName, vfPDF) ReadFromFile(AFileName, lFormat);
else if lExt = STR_POSTSCRIPT_EXTENSION then ReadFromFile(AFileName, vfPostScript)
else if lExt = STR_SVG_EXTENSION then ReadFromFile(AFileName, vfSVG)
else if lExt = STR_CORELDRAW_EXTENSION then ReadFromFile(AFileName, vfCorelDrawCDR)
else if lExt = STR_WINMETAFILE_EXTENSION then ReadFromFile(AFileName, vfWindowsMetafileWMF)
else if lExt = STR_AUTOCAD_EXCHANGE_EXTENSION then ReadFromFile(AFileName, vfDXF);
end; end;
{@@ {@@
@ -995,6 +999,7 @@ begin
else if AnsiCompareText(lExt, STR_SVG_EXTENSION) = 0 then Result := vfSVG 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_CORELDRAW_EXTENSION) = 0 then Result := vfCorelDrawCDR
else if AnsiCompareText(lExt, STR_WINMETAFILE_EXTENSION) = 0 then Result := vfWindowsMetafileWMF else if AnsiCompareText(lExt, STR_WINMETAFILE_EXTENSION) = 0 then Result := vfWindowsMetafileWMF
else if AnsiCompareText(lExt, STR_AUTOCAD_EXCHANGE_EXTENSION) = 0 then Result := vfDXF
else else
raise Exception.Create('TvVectorialDocument.GetFormatFromExtension: The extension (' + lExt + ') doesn''t match any supported formats.'); raise Exception.Create('TvVectorialDocument.GetFormatFromExtension: The extension (' + lExt + ') doesn''t match any supported formats.');
end; end;

View File

@ -1,7 +1,7 @@
object frmFPVViewer: TfrmFPVViewer object frmFPVViewer: TfrmFPVViewer
Left = 186 Left = 318
Height = 473 Height = 473
Top = 137 Top = 299
Width = 375 Width = 375
Caption = 'Free Pascal Vectorial Viewer' Caption = 'Free Pascal Vectorial Viewer'
ClientHeight = 473 ClientHeight = 473
@ -11,7 +11,7 @@ object frmFPVViewer: TfrmFPVViewer
LCLVersion = '0.9.31' LCLVersion = '0.9.31'
object editFileName: TFileNameEdit object editFileName: TFileNameEdit
Left = 8 Left = 8
Height = 22 Height = 25
Top = 8 Top = 8
Width = 304 Width = 304
DialogOptions = [] DialogOptions = []
@ -33,7 +33,7 @@ object frmFPVViewer: TfrmFPVViewer
end end
object spinScale: TFloatSpinEdit object spinScale: TFloatSpinEdit
Left = 72 Left = 72
Height = 16 Height = 25
Top = 72 Top = 72
Width = 168 Width = 168
DecimalPlaces = 6 DecimalPlaces = 6
@ -45,9 +45,9 @@ object frmFPVViewer: TfrmFPVViewer
end end
object Label1: TLabel object Label1: TLabel
Left = 8 Left = 8
Height = 17 Height = 18
Top = 79 Top = 79
Width = 56 Width = 58
Caption = 'Scale by:' Caption = 'Scale by:'
ParentColor = False ParentColor = False
end end
@ -66,8 +66,8 @@ object frmFPVViewer: TfrmFPVViewer
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 0 Left = 0
Height = 345 Height = 369
Top = 128 Top = 104
Width = 375 Width = 375
PageIndex = 0 PageIndex = 0
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
@ -76,8 +76,8 @@ object frmFPVViewer: TfrmFPVViewer
object pageViewer: TPage object pageViewer: TPage
end end
object Page2: TPage object Page2: TPage
ClientWidth = 528 ClientWidth = 4224
ClientHeight = 624 ClientHeight = 4992
object DXFTreeView: TTreeView object DXFTreeView: TTreeView
Left = 8 Left = 8
Height = 313 Height = 313

View File

@ -67,7 +67,7 @@ begin
Vec := TvVectorialDocument.Create; Vec := TvVectorialDocument.Create;
try try
Vec.ReadFromFile(editFileName.FileName, vfDXF); Vec.ReadFromFile(editFileName.FileName);
// We need to be robust, because sometimes the document size won't be given // We need to be robust, because sometimes the document size won't be given
// also give up drawing everything if we need more then 4MB of RAM for the image // also give up drawing everything if we need more then 4MB of RAM for the image