配置した文字のフォントナンバーを取得する方法


配置した文字のフォントナンバーを取得する方法を紹介します。

まず、配置した文字でGetITextQuery()を使ってITextQueryCP textQueryを定義します。

次に、textQuery->GetTextPart()を使ってTextBlockPtr textBlockを定義します。

続きましてtextBlock->GetRunPropertiesForAdd()を使ってRunPropertiesCR runProps を定義します。

次にDgnFontManager::GetDgnFontMapP(ACTIVEMODEL)を使ってDgnFontNumMapP fontMapを定義します。

fontMap->GetFontNumber()でフォントナンバーが取得できます。

void getTextProperties()
{	
	ElementId id= 9199;
	EditElementHandle myText(id,ACTIVEMODEL);

	ITextQueryCP textQuery = myText.GetITextQuery();
	
	ITextPartIdPtr textPart;
	TextBlockPtr textBlock = textQuery->GetTextPart(myText, *textPart);

	RunPropertiesCR runProps = textBlock->GetRunPropertiesForAdd();
	DgnFontCR font = runProps.GetFont();
	
	UInt32 fontNo = 0;
	DgnFontNumMapP fontMap = DgnFontManager::GetDgnFontMapP(ACTIVEMODEL);
	fontMap->GetFontNumber(fontNo, font, false);
	myStr.Sprintf(L"font number is %d", fontNo);
	mdlDialog_dmsgsPrint(myStr);
}