gfxSetTextAlign() and gfxDrawText()

I am using gfxDrawText() function, which works properly as described.

When I had placed a gfxSetTextAlign() command before the gfxDrawText(), then the alignment was distorted.
The problem exists when the Argument for gfxSetTextAlign() was eith 6 or 2. When the argument was 0, no problem.

I realize the gfxSetTextAlign() is not necessary when using gfxDrawText(), however it seems that there should be no interaction.

Code below shows problem

//File Test-Text
pixelwidth	= Status("pxwidth");
pixelheight	= Status("pxheight");
GfxSetOverlayMode( 2 );
GfxFillSolidRect( 1, 1, pixelwidth, pixelheight, colorlightyellow ) ;
x1	= 300;
x2	= 350;
y1	= 100;
y2	= 150;
TA_Center    = 6;  //1 for gfxDrawText
TA_Left      = 0;
TA_Right	 = 2;

//GfxSetTextAlign( TA_Right );						// causes next line to lose alignment
GfxDrawtext( "XXXX",x1,y1,x2,y2,TA_Right);

gfxSetTextAlign() is supposed to be used in conjunction with GfxTextOut

There is no problem, but the reason you see alignment being distorted is because the calculation of the bounding-rectangle is changing.

In gfxDrawText() the co-ordinates are for the rectangle, not the Font, which is determined by the SetFont Function.
On the other hand, TextOut() will have the bounding rectangle very close to the text body like in PlotText().

I hope it clears your doubt, rather than taking more time and posting snaps.

I've not written the internal code, but this seems very logical. Therefore, you should use the right functions in their appropriate context.

Tomasz, I understand the workings of gfxDrawText().

The reason I wrote the post was to make you aware that there is interference from gfxSetTextAlign() if it is used prior to gfxDrawText().

DrawText - is a Microsoft function. If you have problem with how it works - call Microsoft. I don't have access to Windows source code and I can't change the way Windows works.

What you see is a Windows thing, not AmiBroker. See

Also if you actually read the docs I pointed out in previous reply

You would see this:

The text alignment mode for the device context must include the TA_LEFT, TA_TOP, and TA_NOUPDATECP flags.

So it operates 100% as described. There is nothing to be alerted when something works as described.

Besides your use of DrawText function is incorrect. TA_ are constants for SetTextAlign but DrawText has DIFFERENT constants. DrawText uses DT_ constants that are listed in MS web site I pointed out. Numerical values of those constants are in the winuser.h header file. TA_RIGHT just happens to be the same value as DT_RIGHT but other flags may not and technically your code is incorrect.

1 Like