summaryrefslogtreecommitdiff
path: root/packages/fpvectorial/src
diff options
context:
space:
mode:
authorsekelsenmat <sekelsenmat@3ad0048d-3df7-0310-abae-a5850022a9f2>2010-08-16 15:00:54 +0000
committersekelsenmat <sekelsenmat@3ad0048d-3df7-0310-abae-a5850022a9f2>2010-08-16 15:00:54 +0000
commit163519ff19fe1cb3ce6a09dfd5795eab9005d5a7 (patch)
tree49761078effed49963260efe1c862c2e97e3b639 /packages/fpvectorial/src
parent8ec6f9ab4121dd23a2413a02ad0cca1a24ece658 (diff)
downloadfpc-163519ff19fe1cb3ce6a09dfd5795eab9005d5a7.tar.gz
Adds a Corel Draw file format explorer and starts implementing the CDR reader in fpvectorial
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@15829 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/fpvectorial/src')
-rw-r--r--packages/fpvectorial/src/cdrvectorialreader.pas127
-rw-r--r--packages/fpvectorial/src/fpvectorial.pas6
2 files changed, 133 insertions, 0 deletions
diff --git a/packages/fpvectorial/src/cdrvectorialreader.pas b/packages/fpvectorial/src/cdrvectorialreader.pas
index ab8d0fb325..d438dc0bba 100644
--- a/packages/fpvectorial/src/cdrvectorialreader.pas
+++ b/packages/fpvectorial/src/cdrvectorialreader.pas
@@ -28,23 +28,150 @@ uses
type
+ TCDRChunk = class
+ Name: array[0..3] of Char;
+ Size: Cardinal;
+ ChildChunks: TFPList;
+ end;
+
+ TCDRChunkClass = class of TCDRChunk;
+
+ TvCDRInternalData = TCDRChunk;
+
+ TCDRChunkVRSN = class(TCDRChunk)
+ VersionStr: string;
+ VersionNum: Integer;
+ end;
+
{ TvCDRVectorialReader }
TvCDRVectorialReader = class(TvCustomVectorialReader)
+ private
+ procedure ReadVersionChunk(AStream: TStream; var AData: TCDRChunk);
+ function AddNewChunk(var AData: TCDRChunk; AClass: TCDRChunkClass): TCDRChunk;
public
{ General reading methods }
procedure ReadFromStream(AStream: TStream; AData: TvVectorialDocument); override;
+ { File format exploring methods }
+ procedure ExploreFromFile(AFilename: string; out AData: TvCDRInternalData);
+ procedure ExploreFromStream(AStream: TStream; out AData: TvCDRInternalData);
end;
implementation
{ TvPDFVectorialReader }
+procedure TvCDRVectorialReader.ReadVersionChunk(AStream: TStream;
+ var AData: TCDRChunk);
+var
+ lDWord: DWord;
+ lChunk: TCDRChunkVRSN absolute AData;
+ lVerBytes: array[0..1] of Byte;
+begin
+ // Read the Chunk name
+ lDWord := AStream.ReadDWord();
+
+ // Read the Chunk size
+ lDWord := AStream.ReadDWord();
+
+ // Read the version
+ AStream.Read(lVerBytes, 2);
+
+ if (lVerBytes[0] = $BC) and (lVerBytes[1] = $02) then
+ begin
+ lChunk.VersionNum := 7;
+ lChunk.VersionStr := 'CorelDraw 7';
+ end
+ else if (lVerBytes[0] = $20) and (lVerBytes[1] = $03) then
+ begin
+ lChunk.VersionNum := 8;
+ lChunk.VersionStr := 'CorelDraw 8';
+ end
+ else if (lVerBytes[0] = $21) and (lVerBytes[1] = $03) then
+ begin
+ lChunk.VersionNum := 8;
+ lChunk.VersionStr := 'CorelDraw 8bidi';
+ end
+ else if (lVerBytes[0] = $84) and (lVerBytes[1] = $03) then
+ begin
+ lChunk.VersionNum := 9;
+ lChunk.VersionStr := 'CorelDraw 9';
+ end
+ else if (lVerBytes[0] = $E8) and (lVerBytes[1] = $03) then
+ begin
+ lChunk.VersionNum := 10;
+ lChunk.VersionStr := 'CorelDraw 10';
+ end
+ else if (lVerBytes[0] = $4C) and (lVerBytes[1] = $04) then
+ begin
+ lChunk.VersionNum := 11;
+ lChunk.VersionStr := 'CorelDraw 11';
+ end
+ else if (lVerBytes[0] = $B0) and (lVerBytes[1] = $04) then
+ begin
+ lChunk.VersionNum := 12;
+ lChunk.VersionStr := 'CorelDraw 12';
+ end
+ else if (lVerBytes[0] = $14) and (lVerBytes[1] = $05) then
+ begin
+ lChunk.VersionNum := 13;
+ lChunk.VersionStr := 'CorelDraw X3';
+ end;
+end;
+
+function TvCDRVectorialReader.AddNewChunk(var AData: TCDRChunk; AClass: TCDRChunkClass): TCDRChunk;
+begin
+ if AData.ChildChunks = nil then AData.ChildChunks := TFPList.Create;
+
+ Result := AClass.Create;
+
+ AData.ChildChunks.Add(Result);
+end;
+
procedure TvCDRVectorialReader.ReadFromStream(AStream: TStream;
AData: TvVectorialDocument);
begin
end;
+procedure TvCDRVectorialReader.ExploreFromFile(AFilename: string;
+ out AData: TvCDRInternalData);
+var
+ FileStream: TFileStream;
+begin
+ FileStream := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyNone);
+ try
+ ExploreFromStream(FileStream, AData);
+ finally
+ FileStream.Free;
+ end;
+end;
+
+procedure TvCDRVectorialReader.ExploreFromStream(AStream: TStream;
+ out AData: TvCDRInternalData);
+var
+ lRIFF: array[0..3] of Char;
+ lDocSize, lDWord: Cardinal;
+ lChild: TCDRChunk;
+begin
+ // Create the data object
+ AData := TCDRChunk.Create;
+
+ // All CorelDraw files starts with "RIFF"
+ AStream.Read(lRIFF, 4);
+ if lRIFF <> 'RIFF' then
+ raise Exception.Create('[TvCDRVectorialReader.ExploreFromStream] The Corel Draw RIFF file marker wasn''t found.');
+
+ // And then 4 bytes for the document size
+ lDocSize := AStream.ReadDWord();
+
+ // And mroe 4 bytes of other stuff
+ lDWord := AStream.ReadDWord();
+
+ // Now comes the version
+ lChild := AddNewChunk(AData, TCDRChunkVRSN);
+ ReadVersionChunk(AStream, lChild);
+end;
+
initialization
RegisterVectorialReader(TvCDRVectorialReader, vfCorelDrawCDR);
diff --git a/packages/fpvectorial/src/fpvectorial.pas b/packages/fpvectorial/src/fpvectorial.pas
index a89843b6ff..39f3991e0d 100644
--- a/packages/fpvectorial/src/fpvectorial.pas
+++ b/packages/fpvectorial/src/fpvectorial.pas
@@ -90,6 +90,7 @@ type
procedure ReadFromStream(AStream: TStream; AFormat: TvVectorialFormat);
procedure ReadFromStrings(AStrings: TStrings; AFormat: TvVectorialFormat);
class function GetFormatFromExtension(AFileName: string): TvVectorialFormat;
+ function GetDetailedFileFormat(): string;
{ Data reading methods }
function GetPath(ANum: Cardinal): TPath;
function GetPathCount: Integer;
@@ -548,6 +549,11 @@ begin
raise Exception.Create('TvVectorialDocument.GetFormatFromExtension: The extension (' + lExt + ') doesn''t match any supported formats.');
end;
+function TvVectorialDocument.GetDetailedFileFormat(): string;
+begin
+
+end;
+
function TvVectorialDocument.GetPath(ANum: Cardinal): TPath;
begin
if ANum >= FPaths.Count then raise Exception.Create('TvVectorialDocument.GetPath: Path number out of bounds');