#1 PDF Engine » Text position with inverted y coordinates. » 2016-06-27 11:19:00

Magnus
Replies: 0

Hi,

On a page I am trying to print to pdf there is a metafile where the y-axis is inverted. It seems like the text is positioned with the starting point as lower left, instead of top left.

I am digging around in TPdfEnum.TextOut and looking at the H calculations. I dare not try to fix it myself since I do not know all the cases that the calculations are meant for, but

    if ASignY<0 then                            //inverted coordinates
      H := Abs(font.LogFont.lfHeight)+H;

is what finally destroys the H value.

Below is code for generating a metafile which shows the error. It is just a rectangle with text inside it.

When generating the pdf, the text is no longer inside the box.

var
  mf: TMetafile;
  mfc: TMetafileCanvas;
begin
  mf := TMetafile.Create;
  try
    mf.SetSize(100, 100);
    mfc := TMetafileCanvas.Create(mf, 0);
    try
      SetMapMode(mfc.Handle, MM_ANISOTROPIC);
      SetWindowExtEx(mfc.Handle, 100, 100, nil);
      SetViewportExtEx(mfc.Handle, 100, -100, nil);

      mfc.MoveTo(10, -10);
      mfc.LineTo(39, -10);
      mfc.LineTo(39, -26);
      mfc.LineTo(10, -26);
      mfc.LineTo(10, -10);
      mfc.TextOut(13, -12, 'Hello');
    finally
      mfc.Free;
    end;
  finally
    mf.free;
  end;
end;

Regards,

/Magnus

#2 PDF Engine » Pointer arithmetic overflow. » 2015-05-27 13:33:33

Magnus
Replies: 1

Hi, just wanted to alert you to an problem around some pointer arithmetic.

I got an access violation and traced it to the method:

TPdfWrite.Add(Text: PAnsiChar; Len: integer): TPdfWrite;

The ultimate reason was the statement:

if B+Len>=Bend then begin

In my case

B = $FFF73C82 
Len = $A2CBA
B + Len = $1693C
Bend = $FFF73DD3

and the if statement evaluated to false and the buffer was not reallocated, leading to an access violation.

I change the code to

if Len >= Bend - B then begin

and the problem was avoided.

Regards,

/Magnus

Board footer

Powered by FluxBB