3.4.3 Graph Object Get Set Font



Version Info

Minimum Origin Version Required: Origin 8 SR0

Example

  • Font only can via format tree to access, GraphObject class not support yet.
  • Before running, please keep there is text object named MyText on active graph.
  • Get and set bold, italic, underline properties can be used from Origin8.1.
void GraphObject_SetFont_ex(string strName = "MyText")
{
	GraphLayer gl = Project.ActiveLayer();
	if( !gl )
		return;
	
	GraphObject go = gl.GraphObjects(strName);
	if( !go )
		return;
	
	int nTypeFace, nFontSize;
	bool bBold, bItalic, bUnderline;
	if( GetFontInfo(go, nTypeFace, nFontSize, bBold, bItalic, bUnderline) )
	{	
		nFontSize = nFontSize * 1.5;
		bBold = !bBold;
		bItalic = !bItalic;
		bUnderline = !bUnderline;		
		SetFontInfo(go, &nTypeFace, &nFontSize, &bBold, &bItalic, &bUnderline);
	}
}

bool GetFontInfo(GraphObject &go, int &nTypeFace, int &nFontSize, bool &bBold, bool &bItalic, bool &bUnderline)
{
	if ( !go )
		return false;
	
	int nType;
	go.GetObjectType(&nType);		
	if(GROT_TEXT != nType)
		return false;
	
	Tree trFormat;
	trFormat = go.GetFormat(FPB_ALL, FPB_ALL, TRUE, TRUE);
	
	nTypeFace = trFormat.Root.Font.Face.nVal;
	nFontSize = trFormat.Root.Font.Size.nVal;
	
	// The following settings will be ready from Origin8.1
	/*
	bBold = trFormat.Root.Font.Bold.nVal;
	bItalic = trFormat.Root.Font.Italic.nVal;
	bUnderline = trFormat.Root.Font.Underline.nVal;	
	*/
	return true;
}

bool SetFontInfo(GraphObject &go,  int *pnTypeFace = NULL, int *pnFontSize = NULL, bool *pbBold = NULL, bool *pbItalic = NULL, bool *pbUnderline = NULL)
{
	if( !go )
		return false;
	
	int nType;
	go.GetObjectType(&nType);		
	if(GROT_TEXT != nType)
		return false;

	Tree trFormat;
	
	if(pnTypeFace)
		trFormat.Root.Font.Face.nVal = *pnTypeFace;
	
	if(pnFontSize)
		trFormat.Root.Font.Size.nVal = *pnFontSize;
	
	// The following settings will be ready from Origin8.1
	/*
	if(pbBold)
		trFormat.Root.Font.Bold.nVal = *pbBold;
	
	if(pbItalic)
		trFormat.Root.Font.Italic.nVal = *pbItalic;
	
	if(pbUnderline)
		trFormat.Root.Font.Underline.nVal = *pbUnderline;
	*/
	
	if( 0 == go.UpdateThemeIDs(trFormat.Root) )
		return go.ApplyFormat(trFormat, true, true);
	return false;
}