Przeglądaj źródła

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

git-svn-id: trunk@17428 -
sekelsenmat 14 lat temu
rodzic
commit
f7b6f77ff5

+ 2 - 2
packages/fpvectorial/examples/fpvc_mainform.lfm

@@ -12,7 +12,7 @@ object formVectorialConverter: TformVectorialConverter
     Left = 8
     Height = 18
     Top = 112
-    Width = 172
+    Width = 158
     Caption = 'Location of the Input file:'
     ParentColor = False
   end
@@ -45,7 +45,7 @@ object formVectorialConverter: TformVectorialConverter
     Left = 8
     Height = 18
     Top = 152
-    Width = 184
+    Width = 169
     Caption = 'Full path of the Output file:'
     ParentColor = False
   end

+ 3 - 6
packages/fpvectorial/examples/fpvc_mainform.pas

@@ -59,7 +59,7 @@ begin
 
   Vec := TvVectorialDocument.Create;
   try
-    Vec.ReadFromFile(editInput.FileName, vfPDF);
+    Vec.ReadFromFile(editInput.FileName);
     imagePreview.Canvas.Brush.Color := clWhite;
     imagePreview.Canvas.FillRect(0, 0, imagePreview.Width, imagePreview.Height);
     DrawFPVectorialToCanvas(Vec, imagePreview.Canvas);
@@ -76,7 +76,6 @@ end;
 procedure TformVectorialConverter.buttonConvertClick(Sender: TObject);
 var
   Vec: TvVectorialDocument;
-  lFormat: TvVectorialFormat;
 begin
   // First check the in input
   if not CheckInput() then Exit;
@@ -84,10 +83,8 @@ begin
   // Now convert
   Vec := TvVectorialDocument.Create;
   try
-    lFormat := TvVectorialDocument.GetFormatFromExtension(editInput.FileName);
-    Vec.ReadFromFile(editInput.FileName, lFormat);
-    lFormat := TvVectorialDocument.GetFormatFromExtension(editOutPut.FileName);
-    Vec.WriteToFile(editOutPut.FileName, lFormat);
+    Vec.ReadFromFile(editInput.FileName);
+    Vec.WriteToFile(editOutPut.FileName);
   finally
     Vec.Free;
   end;

+ 2 - 4
packages/fpvectorial/examples/fpvectorialconverter.lpi

@@ -4,9 +4,6 @@
     <Version Value="9"/>
     <PathDelim Value="\"/>
     <General>
-      <Flags>
-        <AlwaysBuild Value="False"/>
-      </Flags>
       <SessionStorage Value="InProjectDir"/>
       <MainUnit Value="0"/>
       <Title Value="fpvectorialconverter"/>
@@ -30,6 +27,7 @@
     <RunParams>
       <local>
         <FormatVersion Value="1"/>
+        <LaunchingApplication PathPlusParams="\usr\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
       </local>
     </RunParams>
     <RequiredPackages Count="1">
@@ -53,7 +51,7 @@
     </Units>
   </ProjectOptions>
   <CompilerOptions>
-    <Version Value="9"/>
+    <Version Value="10"/>
     <PathDelim Value="\"/>
     <Target>
       <Filename Value="fpvectorialconverter"/>

+ 14 - 9
packages/fpvectorial/src/fpvectorial.pas

@@ -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;