#1 2023-06-26 14:10:14

Flashcqxg
Member
Registered: 2018-01-11
Posts: 18

MultilineTextRect does not work correctly

my code:
var
  PDF: TPdfDocument;
  R: TPdfRect;


      R.Left := 30;
      R.Top := 500;
      R.Right := 100;
      R.Bottom := 800;
      PDF.Canvas.SetFont('Times New Roman', 12, []);
      PDF.Canvas.MultilineTextRect(R, 'Welcome to mORMot Open Source', True);

Only the text 'Welcome to' is displayed, no other text is displayed.
Thanks.

Offline

#2 2023-06-28 08:14:40

rvk
Member
Registered: 2022-04-14
Posts: 93

Re: MultilineTextRect does not work correctly

It seems like you are misinterpreting some things.
First of all there are these lines in MultilineTextRect.

      MoveToNextLine;
      ARect.Top := ARect.Top - FPage.Leading;
      if ARect.Top < ARect.Bottom + FPage.FontSize then
        Break;

So the ARect.Top is decreasing with each line (by FPage.Leading which is default 0)
That means you have your Top and Bottom wrong.

Change them to Top := 800 and Bottom := 300; (the coordinates are from the bottom up)

Next... for the MoveToNextLine function to function you will need to set the Leading.

    /// Set the text leading, Tl, to the specified leading value
    // - leading which is a number expressed in unscaled text space units;
    // it specifies the vertical distance between the baselines of adjacent
    // lines of text
    // - Text leading is used only by the MoveToNextLine and ShowTextNextLine methods
    // - you can force the next line to be just below the current one by calling:
    // ! SetLeading(Attributes.FontSize);
    // - Default value is 0
    procedure SetLeading(leading: Single);                       {  TL  }

So if you change your code to this it should work:

      R.Left := 30;
      R.Top := 800; // this is almost at the top of the page
      R.Right := 100;
      R.Bottom := 300; // needs to be lower than the top
      PDF.Canvas.SetFont('Times New Roman', 12, []);
      PDF.Canvas.SetLeading(12); // font size, for newline
      PDF.Canvas.MultilineTextRect(R, 'Welcome to mORMot Open Source', True);

Offline

#3 2023-06-29 00:39:22

Flashcqxg
Member
Registered: 2018-01-11
Posts: 18

Re: MultilineTextRect does not work correctly

thank you,it works!

Offline

Board footer

Powered by FluxBB