#1 2013-08-22 11:23:44

ddemars
Member
From: Le Puy en Velay, France
Registered: 2011-12-02
Posts: 7
Website

TPdfDocumentGDI : problem with vertical text alignment

I'm evaluating SynPdf for use with my gmPrintsuite Reports (canvas based report engine)
I noticed a slight shift in vertical text position when using TPdfDocumentGDI

I wrote a small sample application that shows up the problem

https://www.dropbox.com/s/p6euugbvg19iv … synpdf.zip

will try to find out today where's the problem (maybe in my code ?).
it may take some time as I'm new to SynPDf, but it will be the occasion for me to learn about text metrics.

Last edited by ddemars (2013-08-22 11:24:58)

Offline

#2 2013-08-22 12:50:51

ddemars
Member
From: Le Puy en Velay, France
Registered: 2011-12-02
Posts: 7
Website

Re: TPdfDocumentGDI : problem with vertical text alignment

a version of synpdf.pas with my modifications :

https://www.dropbox.com/s/pgt3046dfkv9mz7/SynPdf.zip

...seems it fixes the problem (at least in the sample app) but not sure if done properly.
Will try it with my reports now...

Offline

#3 2013-08-22 16:34:59

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,237
Website

Re: TPdfDocumentGDI : problem with vertical text alignment

Thanks for sharing.

We will take a look at it.

Offline

#4 2013-08-23 10:23:04

ddemars
Member
From: Le Puy en Velay, France
Registered: 2011-12-02
Posts: 7
Website

Re: TPdfDocumentGDI : problem with vertical text alignment

enhanced tests application. TextOut samples with different alignments.

https://www.dropbox.com/s/458cye411nwbu … synpdf.zip

show a problem also with TA_BOTTOM (previously the sample app only checked the default TA_TOP)

Offline

#5 2013-08-23 12:19:05

ddemars
Member
From: Le Puy en Velay, France
Registered: 2011-12-02
Posts: 7
Website

Re: TPdfDocumentGDI : problem with vertical text alignment

the TA_BOTTOM problem seems due to this rule not respected :

(from http://msdn.microsoft.com/en-us/library … 85%29.aspx )

The text-alignment flags are not necessarily single bit flags and may be equal to zero. The flags must be examined in groups of related flags, as shown in the following list.

    TA_LEFT, TA_RIGHT, and TA_CENTER
    TA_BOTTOM, TA_TOP, and TA_BASELINE
    TA_NOUPDATECP and TA_UPDATECP

To verify that a particular flag is set in the return value of this function:

    Apply the bitwise OR operator to the flag and its related flags.
    Apply the bitwise AND operator to the result and the return value.
    Test for the equality of this result and the flag.

Offline

#6 2013-08-27 10:46:27

ddemars
Member
From: Le Puy en Velay, France
Registered: 2011-12-02
Posts: 7
Website

Re: TPdfDocumentGDI : problem with vertical text alignment

here's synpdf.pas with my latest fix suggestions :

https://www.dropbox.com/s/kvdraf29yqk71 … SynPdf.zip

(also fixed an issue with text rotation, issue visible when adding a font orientation in the test application).

Offline

#7 2013-08-27 15:42:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,237
Website

Re: TPdfDocumentGDI : problem with vertical text alignment

Thanks!

Do you think it is stable enough to be included in the SynPDF trunk?

Offline

#8 2013-08-27 18:13:54

ddemars
Member
From: Le Puy en Velay, France
Registered: 2011-12-02
Posts: 7
Website

Re: TPdfDocumentGDI : problem with vertical text alignment

Yes in my opinion.
As I'm not expert in this field, I took time to visually check my changes with the test application I wrote.
If the concept of the test app is valid : draw to canvas, then draw to PDF's VCLCanvas, expecting the same visual result, then my changes are OK.

that said, my tests are basic and does not cover strange cases seen in SynPDF code... ( (Canvas.FWorldFactorY) < 0 ?? )
so perharps more checks with EMF sample files are welcome...

here's latest version of my test app :
https://www.dropbox.com/s/f880hoacz0zlq … synpdf.zip

if you run it (with my modifications) you will see some issues with DrawLine (underlined text).
Need to check but I don't think the problem comes from my changes, but was a previous issue.

Offline

#9 2013-08-28 08:10:09

ddemars
Member
From: Le Puy en Velay, France
Registered: 2011-12-02
Posts: 7
Website

Re: TPdfDocumentGDI : problem with vertical text alignment

here's fix for Drawline in TPdfEnum.TextOut (underlined and striked text) :

procedure DrawLine(var P: TPoint; aH: Single);
var tmp: TPdfEnumStatePen;
begin
  with DC[nDC] do begin
    tmp := Pen;
    pen.color := font.color;
    pen.width := aSize / 15 / Canvas.GetWorldFactorX / Canvas.FDevScale;
    pen.style := PS_SOLID;
    pen.null := False;
    NeedPen;
    if font.spec.angle=0 then begin
      // P = textout original coords
      // (-W,-H) = delta to text start pos (at baseline)
      // wW = text width
      // aH = delta H for drawed line (from baseline)
      Canvas.MoveToI(P.X  -W,(P.Y-(H-aH)));  //  deltax := -W     deltaY := (-H+aH)
      Canvas.LineToI(P.X -W+wW,(P.Y-(H-aH)));//  deltax := -W+wW  deltaY := (-H+aH)
    end else begin
      // rotation pattern :
      //       rdx = deltax * acos + deltay * asin
      //       rdy = deltay * acos - deltax * asin
      Canvas.MoveToI( P.X+( (-W)  *acos +(-H+aH)*asin ),
                      P.Y+((-H+aH)*acos -(-W)   *asin )  );

      Canvas.LineToI( P.X+((-W+wW) *acos +(-H+aH)*asin ),
                      P.Y+((-H+aH) *acos -(-W+wW)*asin )  );
    end;
    Canvas.Stroke;
    Pen := tmp;
    NeedPen;
  end;
end;

comments and redundant sign operators placed to ease the fix process. they can be removed.

Offline

#10 2013-08-28 13:06:38

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,237
Website

Re: TPdfDocumentGDI : problem with vertical text alignment

We have included your patch proposal.
See http://synopse.info/fossil/info/7373ead175

Sounds fine for our own regression files.

Merci beaucoup!
smile

Offline

Board footer

Powered by FluxBB