NNS_G2dTextCanvasGetStringWidth

構文


#include <nnsys/g2d/g2d_TextCanvas.h>

int NNS_G2dTextCanvasGetStringWidth(
	const NNSG2dTextCanvas* pTxn,
	const NNSG2dChar* str,
	const NNSG2dChar** pPos
);

引数

pTxn [IN] TextCanvas へのポインタ
str [IN] 文字列へのポインタ
pPos [OUT] 次の行へのポインタを受け取るバッファへのポインタ(NULL指定可)

返り値

1行分の文字列を描画した時の幅を返します。(ピクセル単位)

説明

1行分の文字列を描画した時の幅を計算します。
すなわち str から '\n' (0x0A) もしくは '\0' までを描画した場合の幅です。

pPos が NULL 以外である場合、 文字列 str に '\n' が含まれると最初の '\n' の次の文字へのポインタが、 そうでない場合は NULL が pPos の指すバッファに格納されます。

縦書きフォントでは文字列の高さを計算します。

サンプルコード

    // 各行の文字列長の合計を求める
    const char* str = "abcdefg\n" "ghijk\n" "lmn";
    int sum = 0;
    
    while( str != NULL )
    {
        sum += NNS_G2dTextCanvasGetStringWidth(&tc, str, &str);
    }

参照

NNS_G2dFontGetStringWidth, NNS_G2dTextCanvasGetTextWidth, NNS_G2dTextCanvasGetTextHeight, NNS_G2dTextCanvasGetTextRect

履歴

2007/03/14 縦書き/縦持ちフォントに対応。
2005/05/25 初版