Pascal
function tsTextGetWidthA(pText: pAnsiChar): tsInt; function tsTextGetWidthW(pText: pWideChar): tsInt;
C/C++
tsInt tsTextGetWidthA(char * pText); tsInt tsTextGetWidthW(WideChar * pText);
This function calculates the width of an text and returns it. You also can use this function to query the actual width of the text inside an blockmode. For this you can call this functions inside the block mode with nil / NULL as pText and it will return the actual width.
|
Tip |
|---|---|
|
If you try to query the width of an text to align them like centering it's may be better to use the alignment of the library. This can be set with the Parameter TS_ALIGN and maybe some bit faster because the tsTextGetWidth functions needs to parse the text and calculate some things. All this also happens in the tsTextOut function. And if you only need to center an text this is some bit cheaper and some less work for you. |
|
It's an pointer to an null terminated string that contains the text of which you wants to know the width. If you call this function inside the block mode and you pass nil / NULL for pText the function will return the width of the actual drawn text.
Return value is the width of the given text or the width of the drawn text inside the block mode.
There is no active context. See also tsContextBind.
There was no renderer set. See the parameter TS_RENDERER.
There was no font bound to the actual context. See also tsFontBind.
This could happen only in the ansi version. And there was an error to convert the ansi to unicode text. But it's nearly not possible to get this error.
If you pass nil / NULL to this function. If you really wants to draw some text you should put it into this function. With nil / NULL this won't work.