You've already forked lazarus-ccr
PowerPDF: implements proportional property for images
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2100 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -47,7 +47,7 @@ procedure TPRJpegImage.Print(ACanvas: TPRCanvas; ARect: TRect);
|
|||||||
var
|
var
|
||||||
FDoc: TPdfDoc;
|
FDoc: TPdfDoc;
|
||||||
FXObjectName: string;
|
FXObjectName: string;
|
||||||
i: integer;
|
i,AWidth,AHeight: integer;
|
||||||
begin
|
begin
|
||||||
if not Printable then Exit;
|
if not Printable then Exit;
|
||||||
|
|
||||||
@ -73,8 +73,13 @@ begin
|
|||||||
FDoc.AddXObject(FXObjectName, CreatePdfImage(FPicture.Graphic, 'Pdf-Jpeg'));
|
FDoc.AddXObject(FXObjectName, CreatePdfImage(FPicture.Graphic, 'Pdf-Jpeg'));
|
||||||
end;
|
end;
|
||||||
with ARect, ACanvas.PdfCanvas do
|
with ARect, ACanvas.PdfCanvas do
|
||||||
if FStretch then
|
if FStretch then begin
|
||||||
DrawXObject(Left, Self.Page.Height - Bottom, Width, Height, FXObjectName)
|
AWidth := Width;
|
||||||
|
AHeight := Height;
|
||||||
|
if Proportional then
|
||||||
|
CalcProportionalBounds(AWidth, AHeight);
|
||||||
|
DrawXObject(Left, Self.Page.Height - Top - AHeight, AWidth, AHeight, FXObjectName)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
DrawXObjectEx(Left, Self.Page.Height - Top - FPicture.Height,
|
DrawXObjectEx(Left, Self.Page.Height - Top - FPicture.Height,
|
||||||
FPicture.Width, FPicture.Height,
|
FPicture.Width, FPicture.Height,
|
||||||
|
@ -475,13 +475,16 @@ type
|
|||||||
private
|
private
|
||||||
FSharedName: string;
|
FSharedName: string;
|
||||||
procedure SetStretch(Value: boolean);
|
procedure SetStretch(Value: boolean);
|
||||||
|
procedure SetProportional(AValue: boolean);
|
||||||
protected
|
protected
|
||||||
FPicture: TPicture;
|
FPicture: TPicture;
|
||||||
FSharedImage: boolean;
|
FSharedImage: boolean;
|
||||||
FStretch: boolean;
|
FStretch: boolean;
|
||||||
|
FProportional: boolean;
|
||||||
procedure SetPicture(Value: TPicture); virtual;
|
procedure SetPicture(Value: TPicture); virtual;
|
||||||
procedure Paint; override;
|
procedure Paint; override;
|
||||||
procedure Print(ACanvas: TPRCanvas; ARect: TRect); override;
|
procedure Print(ACanvas: TPRCanvas; ARect: TRect); override;
|
||||||
|
procedure CalcProportionalBounds(var AWidth, AHeight: Integer);
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -490,6 +493,7 @@ type
|
|||||||
property Picture: TPicture read FPicture write SetPicture;
|
property Picture: TPicture read FPicture write SetPicture;
|
||||||
property SharedImage: boolean read FSharedImage write FSharedImage;
|
property SharedImage: boolean read FSharedImage write FSharedImage;
|
||||||
property Stretch: boolean read FStretch write SetStretch default true;
|
property Stretch: boolean read FStretch write SetStretch default true;
|
||||||
|
property Proportional: boolean read FProportional write SetProportional;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TPRDestination }
|
{ TPRDestination }
|
||||||
@ -2286,6 +2290,10 @@ end;
|
|||||||
|
|
||||||
// Paint
|
// Paint
|
||||||
procedure TPRImage.Paint;
|
procedure TPRImage.Paint;
|
||||||
|
var
|
||||||
|
R: TRect;
|
||||||
|
AWidth,AHeight: Integer;
|
||||||
|
RatioH,RatioW: Double;
|
||||||
begin
|
begin
|
||||||
if (FPicture = nil) or (FPicture.Graphic = nil) or
|
if (FPicture = nil) or (FPicture.Graphic = nil) or
|
||||||
(FPicture.Graphic.Empty) then
|
(FPicture.Graphic.Empty) then
|
||||||
@ -2300,7 +2308,18 @@ begin
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
if FStretch then
|
if FStretch then
|
||||||
Canvas.StretchDraw(GetClientRect, FPicture.Graphic)
|
begin
|
||||||
|
R := GetClientRect;
|
||||||
|
|
||||||
|
AWidth := R.Right-R.Left;
|
||||||
|
AHeight := R.Bottom-R.Top;
|
||||||
|
if FProportional then
|
||||||
|
CalcProportionalBounds(AWidth, AHeight);
|
||||||
|
R.Right := R.Left + AWidth;
|
||||||
|
R.Bottom := R.Top + AHeight;
|
||||||
|
|
||||||
|
Canvas.StretchDraw(R, FPicture.Graphic)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
Canvas.Draw(0, 0, FPicture.Graphic);
|
Canvas.Draw(0, 0, FPicture.Graphic);
|
||||||
end;
|
end;
|
||||||
@ -2312,6 +2331,8 @@ var
|
|||||||
FXObjectName: string;
|
FXObjectName: string;
|
||||||
i: integer;
|
i: integer;
|
||||||
FIdx: integer;
|
FIdx: integer;
|
||||||
|
AWidth,AHeight: Integer;
|
||||||
|
RatioH,RatioW: Double;
|
||||||
begin
|
begin
|
||||||
if (FPicture = nil) or (FPicture.Graphic = nil) or
|
if (FPicture = nil) or (FPicture.Graphic = nil) or
|
||||||
(FPicture.Graphic.Empty) {or not (FPicture.Graphic is TFPImageBitmap)} then
|
(FPicture.Graphic.Empty) {or not (FPicture.Graphic is TFPImageBitmap)} then
|
||||||
@ -2341,14 +2362,33 @@ begin
|
|||||||
FDoc.AddXObject(FXObjectName, CreatePdfImage(FPicture.Graphic, 'Pdf-Bitmap', FDoc.ObjectMgr));
|
FDoc.AddXObject(FXObjectName, CreatePdfImage(FPicture.Graphic, 'Pdf-Bitmap', FDoc.ObjectMgr));
|
||||||
end;
|
end;
|
||||||
with ARect, ACanvas.PdfCanvas do
|
with ARect, ACanvas.PdfCanvas do
|
||||||
if FStretch then
|
if FStretch then begin
|
||||||
DrawXObject(Left, GetPage.Height - Bottom, Width, Height, FXObjectName)
|
AWidth := Width;
|
||||||
|
AHeight := Height;
|
||||||
|
if FProportional then
|
||||||
|
CalcProportionalBounds(AWidth, AHeight);
|
||||||
|
DrawXObject(Left, GetPage.Height - Top - AHeight, AWidth, AHeight, FXObjectName)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
DrawXObjectEx(Left, GetPage.Height - Top - FPicture.Height,
|
DrawXObjectEx(Left, GetPage.Height - Top - FPicture.Height,
|
||||||
FPicture.Width, FPicture.Height,
|
FPicture.Width, FPicture.Height,
|
||||||
Left, GetPage.Height - Top - Height, Width, Height, FXObjectName);
|
Left, GetPage.Height - Top - Height, Width, Height, FXObjectName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TPRImage.CalcProportionalBounds(var AWidth, AHeight: Integer);
|
||||||
|
var
|
||||||
|
RatioW,RatioH: Double;
|
||||||
|
begin
|
||||||
|
if (FPicture.Height<>0) and (FPicture.Width<>0) then begin
|
||||||
|
RatioW := AWidth/FPicture.Width;
|
||||||
|
RatioH := AHeight/FPicture.Height;
|
||||||
|
if RatioH<RatioW then
|
||||||
|
RatioW := RatioH;
|
||||||
|
AWidth := Round(RatioW * FPicture.Width);
|
||||||
|
AHeight := Round(RatioW * FPicture.Height);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
constructor TPRImage.Create(AOwner: TComponent);
|
constructor TPRImage.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
@ -2379,6 +2419,15 @@ begin
|
|||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TPRImage.SetProportional(AValue: boolean);
|
||||||
|
begin
|
||||||
|
if AValue <> FProportional then
|
||||||
|
begin
|
||||||
|
FProportional := AValue;
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
// Destroy
|
// Destroy
|
||||||
destructor TPRImage.Destroy;
|
destructor TPRImage.Destroy;
|
||||||
begin
|
begin
|
||||||
|
Reference in New Issue
Block a user