{*************************************************************************}
{ TMS PDF Engine                                                          }
{ for Delphi & C++Builder                                                 }
{                                                                         }
{ written by TMS Software                                                 }
{           copyright © 2015                                              }
{           Email : info@tmssoftware.com                                  }
{           Web : http://www.tmssoftware.com                              }
{                                                                         }
{ The source code is given as is. The author is not responsible           }
{ for any possible damage done due to the use of this code.               }
{ The component can be freely used in any application. The complete       }
{ source code remains property of the author and may not be distributed,  }
{ published, given or sold in any form as such. No parts of the source    }
{ code can be included in any other component or application without      }
{ written authorization of the author.                                    }
{*************************************************************************}
unit IwAdvPDFIO;

interface

uses
  Classes, IwAdvPDFLIB;

type
  TIwAdvPDFIOComponent = class(TComponent)
  private
    FHeader: TPDFHeader;
    FFooter: TPDFHeader;
    FMetaData: TPDFMetaData;
    FPageLayout: TPDFPageLayout;
    function GetVersionStr: string;
    procedure SetFooter(const Value: TPDFHeader);
    procedure SetHeader(const Value: TPDFHeader);
    procedure SetMetaData(const Value: TPDFMetaData);
    procedure SetVersionStr(const Value: string);
    procedure SetPageLayout(const Value: TPDFPageLayout);
  protected
    function GetVersionNr: Integer; virtual;
  public
    constructor Create(AOwner: TComponent); override;
    procedure Assign(Source: TPersistent); override;
    destructor Destroy; override;
  published
    property Footer: TPDFHeader read FFooter write SetFooter;
    property Header: TPDFHeader read FHeader write SetHeader;
    property MetaData: TPDFMetaData read FMetaData write SetMetaData;
    property PageLayout: TPDFPageLayout read FPageLayout write SetPageLayout;
    property Version: string read GetVersionStr write SetVersionStr;
  end;

implementation

uses
  SysUtils, Windows;

{ TIwAdvPDFIOComponent }

procedure TIwAdvPDFIOComponent.Assign(Source: TPersistent);
begin
  if (Source is TIwAdvPDFIOComponent) then
  begin
    FHeader.Assign((Source as TIwAdvPDFIOComponent).Header);
    FFooter.Assign((Source as TIwAdvPDFIOComponent).Footer);
    FMetaData.Assign((Source as TIwAdvPDFIOComponent).MetaData);
    FPageLayout := ((Source as TIwAdvPDFIOComponent).PageLayout);
  end;
end;

constructor TIwAdvPDFIOComponent.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FHeader := TPDFHeader.Create;
  FFooter := TPDFHeader.Create;
  FMetaData := TPDFMetaData.Create;
  FPageLayout := plPortrait;
end;

destructor TIwAdvPDFIOComponent.Destroy;
begin
  FMetaData.Free;
  FHeader.Free;
  FFooter.Free;
  inherited;
end;

function TIwAdvPDFIOComponent.GetVersionNr: Integer;
begin
  Result := MakeLong(MakeWord(0,0),MakeWord(0,1));
end;

function TIwAdvPDFIOComponent.GetVersionStr: string;
var
  vn: Integer;
begin
  vn := GetVersionNr;
  Result := IntToStr(Hi(Hiword(vn)))+'.'+IntToStr(Lo(Hiword(vn)))+'.'+IntToStr(Hi(Loword(vn)))+'.'+IntToStr(Lo(Loword(vn)));
end;

procedure TIwAdvPDFIOComponent.SetFooter(const Value: TPDFHeader);
begin
  FFooter.Assign(Value);
end;

procedure TIwAdvPDFIOComponent.SetHeader(const Value: TPDFHeader);
begin
  FHeader.Assign(Value);
end;

procedure TIwAdvPDFIOComponent.SetMetaData(const Value: TPDFMetaData);
begin
  FMetaData.Assign(Value);
end;

procedure TIwAdvPDFIOComponent.SetPageLayout(const Value: TPDFPageLayout);
begin
  FPageLayout := Value;
end;

procedure TIwAdvPDFIOComponent.SetVersionStr(const Value: string);
begin
  //
end;

end.
