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 }
constructor Create;
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 WriteToStrings(AStrings: TStrings; AFormat: TvVectorialFormat);
procedure ReadFromFile(AFileName: string; AFormat: TvVectorialFormat); overload;
@ -883,6 +884,14 @@ begin
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
}
@ -938,15 +947,10 @@ end;
}
procedure TvVectorialDocument.ReadFromFile(AFileName: string);
var
lExt: string;
lFormat: TvVectorialFormat;
begin
lExt := ExtractFileExt(AFileName);
if lExt = STR_PDF_EXTENSION then ReadFromFile(AFileName, vfPDF)
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);
lFormat := GetFormatFromExtension(ExtractFileExt(AFileName));
ReadFromFile(AFileName, lFormat);
end;
{@@
@ -995,6 +999,7 @@ begin
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 if AnsiCompareText(lExt, STR_AUTOCAD_EXCHANGE_EXTENSION) = 0 then Result := vfDXF
else
raise Exception.Create('TvVectorialDocument.GetFormatFromExtension: The extension (' + lExt + ') doesn''t match any supported formats.');
end;

View File

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

View File

@ -67,7 +67,7 @@ begin
Vec := TvVectorialDocument.Create;
try
Vec.ReadFromFile(editFileName.FileName, vfDXF);
Vec.ReadFromFile(editFileName.FileName);
// 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