7.5. tsTextGetWidth

Syntax

Pascal

function tsTextGetWidthA(pText: pAnsiChar): tsInt;

function tsTextGetWidthW(pText: pWideChar): tsInt;

C/C++

tsInt tsTextGetWidthA(char * pText);

tsInt tsTextGetWidthW(WideChar * pText);

Description

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] 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.

Parameters

pText

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

Return value is the width of the given text or the width of the drawn text inside the block mode.

Error Codes

TS_NO_ACTIVE_CONTEXT

There is no active context. See also tsContextBind.

TS_NO_ACTIVE_RENDERER

There was no renderer set. See the parameter TS_RENDERER.

TS_NO_ACTIVE_FONT

There was no font bound to the actual context. See also tsFontBind.

TS_INVALID_OPERATION

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.

TS_INVALID_VALUE

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.