procedure TJPFpdf.Image(vFile: string; vX: double; vY: double;
vWidth: double; vHeight: double);
var
i: integer;
img: TJPImageInfo;
flag: boolean;
begin
//Put an image on the page
flag := False;
if (Length(Self.pImages) > 0) then
for i := 0 to Length(Self.pImages) - 1 do
begin
if (Self.pImages[i].filePath = vFile) then
begin
flag := True;
img := Self.pImages[i];
break;
end;
end;
if not (flag) then
begin
//First use of image, get info
SetLength(Self.pImages, Length(Self.pImages) + 1);
Self.pImages[Length(Self.pImages) - 1].imgSource := TMemoryStream.Create;
Self.pImages[Length(Self.pImages) - 1] := GetInfoImage(vFile);
Self.pImages[Length(Self.pImages) - 1].n := Length(Self.pImages);
Self.pImages[Length(Self.pImages) - 1].filePath := vFile;
img := Self.pImages[Length(Self.pImages) - 1];
end
else
//Automatic width or height calculus
if (vWidth = 0) then
vWidth := StrToFloat(FloatToStrF((vHeight * img.w / img.h), ffNumber,
14, 2, TPDFFormatSetings), TPDFFormatSetings);
if (vHeight = 0) then
vHeight := StrToFloat(FloatToStrF((vWidth * img.h / img.w), ffNumber,
14, 2, TPDFFormatSetings), TPDFFormatSetings);
_out('q ' + FloatToStr(vWidth) + ' 0 0 ' + FloatToStr(vHeight) +
' ' + FloatToStr(vX) + ' -' + FloatToStr(vY + vHeight) + ' cm /I' +
IntToStr(Length(Self.pImages)) + ' Do Q');
end;
//modified procedure:
procedure TJPFpdf.Image(vFile: string; vX: double; vY: double;
vWidth: double; vHeight: double);
var
j,i: integer; //modified
img: TJPImageInfo;
flag: boolean;
begin
//Put an image on the page
flag := False;
if (Length(Self.pImages) > 0) then
begin
for i := 0 to Length(Self.pImages) - 1 do
begin
if (Self.pImages[i].filePath = vFile) then
begin
flag := True;
img := Self.pImages[i];
j:=i+1; // insert
break;
end;
end;
end;
if not (flag) then
begin
//First use of image, get info
SetLength(Self.pImages, Length(Self.pImages) + 1);
Self.pImages[Length(Self.pImages) - 1].imgSource := TMemoryStream.Create;
Self.pImages[Length(Self.pImages) - 1] := GetInfoImage(vFile);
Self.pImages[Length(Self.pImages) - 1].n := Length(Self.pImages);
Self.pImages[Length(Self.pImages) - 1].filePath := vFile;
img := Self.pImages[Length(Self.pImages) - 1];
j:=Length(Self.pImages); //insert
end;
//else
//Automatic width or height calculus
if (vWidth = 0) then
vWidth := StrToFloat(FloatToStrF((vHeight * img.w / img.h), ffNumber,
14, 2, TPDFFormatSetings), TPDFFormatSetings);
if (vHeight = 0) then
vHeight := StrToFloat(FloatToStrF((vWidth * img.h / img.w), ffNumber,
14, 2, TPDFFormatSetings), TPDFFormatSetings);
_out('q ' + FloatToStr(vWidth) + ' 0 0 ' + FloatToStr(vHeight) +
' ' + FloatToStr(vX) + ' -' + FloatToStr(vY + vHeight) + ' cm /I' +
IntToStr(j) + ' Do Q'); //modified
end;