#1 2021-05-03 12:52:58

Eric
Member
Registered: 2012-11-26
Posts: 129
Website

How to render rotated text ?

Hello,

I am trying to render rotated text, but SetTextMatrix does not seem to have any effect.

I have been trying with variations of the following code, with SetTextMatrix inside or outside BeginText, there was no effect... anything obvious I missed ?

      var a := rotation*(PI/180);
      var c := Cos(a);
      var s := Sin(a);
      pdf.Canvas.SetTextMatrix(c, s, -s, c, 0, 0);
      pdf.Canvas.BeginText;
      if centered then begin
         X := X + pdf.DefaultPageWidth div 2;
         Y := Y + pdf.DefaultPageHeight div 2;
      end;
      pdf.Canvas.TextRect(PdfRect(X, Y, X+1, Y+1), text, paCenter, False);
      //  pdf.Canvas.TextOut(X, Y, text);  // tried this as well, no better
      pdf.Canvas.EndText;

Offline

#2 2021-05-03 15:37:15

Eric
Member
Registered: 2012-11-26
Posts: 129
Website

Re: How to render rotated text ?

Found the issue: TPdfCanvas.TextRect always does a BeginText/EndText, so SetTextMatrix is completely ignored

Offline

#3 2023-06-28 23:04:41

surfzone
Member
Registered: 2023-06-25
Posts: 7

Re: How to render rotated text ?

With this changes, it works!

      var a := rotation*(PI/180);
      var c := Cos(a);
      var s := Sin(a);
      pdf.Canvas.BeginText;
      if centered then begin
         X := X + pdf.DefaultPageWidth div 2;
         Y := Y + pdf.DefaultPageHeight div 2;
      end;
      pdf.Canvas.SetTextMatrix(c, s, -s, c, X, Y);
      pdf.Canvas.ShowText(text); 
      pdf.Canvas.EndText;

BeginText BEFORE SetTextMatrix
and ShowText for write the Text

Offline

Board footer

Powered by FluxBB