#1 2017-06-10 23:53:21

toshe
Member
Registered: 2017-06-10
Posts: 2

Wrong text placement, ARC DIRECTION etc.

Hello everyone,
I have two ugly metafiles coming from a statistical program that I need to export as PDF and I assume the ARC DIRECTION property is not handled correctly.
I have the following problems:
-    The vertical labels are rotated at 180 degree.
-    Some other labels (not the vertical ones) are placed either lower or upper (not consistent)
-    When using FastReport Exporter the vertical labels are also misplaces.
I spent days investigating what might be wrong as also none of the commercial exporter and also some metafile editors stuck there.
I think the ARC DIRECTION is the root of the problem. If I pass the arc direction as a parameter to CreateFont like

procedure TPdfEnum.CreateFont(aLogFont: PEMRExtCreateFontIndirect; counterClockwise: Boolean); 

     
and add the following line

if not counterClockwise then FontSpec.angle := FontSpec.angle * -1; 

then the vertical labels are shown correctly. But I could not figure out what might be wrong with the other labels and why the FastReport exporter still misplaces them.
But I doubt this will be enough. Because what if the ARC DIRECTION changes after the font is created? Do we need to create all the fonts with rotaiton again?

Here are the the problematic metafiles

Note: The program I get the files from have two option for export: EMF and WMF. Although the WMF is simpler and compacter it can’t be loaded in Delphi directly because of the buggy VCL. I needed to use low level APIs to convert it to EMF.

I would be happy if someone shows me the right place in the code where to dig further.

Thanks in advance

Offline

#2 2017-06-16 14:57:59

toshe
Member
Registered: 2017-06-10
Posts: 2

Re: Wrong text placement, ARC DIRECTION etc.

So the saga continues and I understood where the problem might be.
I found some scary errors in TPdfEnum.TextOut around the TA_BASELINE. The values for H were completly messed up.

I did the following very dirty fix that places my texts surprisingly accurate:

    wW := W;                                    // right x
    if (font.Align and TA_CENTER)=TA_CENTER then
      W := W/2                                  // center x
    else if (font.Align and TA_CENTER)=TA_RIGHT then
      W := W                                    // right x
    else
      W := 0;                                   // left x
    // V Align mask = TA_BASELINE or TA_BOTTOM or TA_TOP = TA_BASELINE
    if (font.Align and TA_BASELINE) = TA_BASELINE then
      H := -Abs(font.spec.cell)    else
    if (font.Align and TA_BASELINE )= TA_BOTTOM then
      H := 0     // bottom y
    else
      H := - 2 *abs(font.spec.cell) * sin(DegToRad(font.spec.angle));

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

But I am sure this is not the ultimate solution. I still can‘t understand what is going on in all the 11k+ lines. But if someone of the main contributors is willing to explain me some stuff we can together find a working solution.
Thanks in advance

Offline

#3 2017-12-13 12:56:12

MtwStark
Member
From: Italy
Registered: 2016-01-05
Posts: 27

Re: Wrong text placement, ARC DIRECTION etc.

Hi, toshe
I had a similar problem handling texts from RichEdit an I solved in his way:

            if (font.Align and TA_CENTER) = TA_CENTER then
                W := W / 2 // center x
            else if (font.Align and TA_CENTER) = TA_LEFT then
                W := 0; // left x
            // V Align mask = TA_BASELINE or TA_BOTTOM or TA_TOP = TA_BASELINE
            if (font.Align and TA_BASELINE) = TA_BASELINE then
                // always zero ?
                H := Abs(font.LogFont.lfHeight) - Abs(font.spec.cell) // center y
            else if (font.Align and TA_BASELINE) = TA_BOTTOM then
                H := Abs(font.spec.descent) // bottom y
            end else begin
                //H := -abs(font.spec.ascent); // top
                H := -abs(2 * font.spec.cell) + abs(font.spec.descent) + abs(font.spec.ascent) - 1; // top MTW
            end;

Mine does not handle rotated text but I noticed a certain similarity in our two formulas for H

Offline

Board footer

Powered by FluxBB