Font example for C++ 5.0 and later
This example, in a MouseUp event, determines the size of a rectangle for a string in the specified font. It then draws the rectangle and draws the text on top of the rectangle.
//You must include FONT.H
//You must compile FONT.CPP
//Both are in \LEADTOOLS\INCLUDE
ILEADRasterFXD *pRasterFxd=NULL;
CoCreateInstance(CLSID_LEADRasterFXD, NULL, CLSCTX_ALL, IID_ILEADRasterFXD, (void**)&pRasterFxd);
float TextWidth;
float TextHeight;
COleFont myFont;
long hDC=NULL;
myFont.m_lpDispatch = pRasterFxd->GetFont();
CY size = myFont.GetSize();
size.Hi = 0; // Hi will be 0 unless you use a really big font
size.Lo = 32L * 10000L; // 32 point
myFont.SetSize(size);
pRasterFxd->PutDrawFontColor(RGB(0, 0, 255)); //Blue
pRasterFxd->PutTextStyle(FXD_TEXTSTYLE_NORMAL);
pRasterFxd->PutTextAlign(FXD_TEXTALIGN_HCENTER_VCENTER);
// Get the width and height of the text to be drawn.
hDC = m_LEADRasterView1.GetClientDC();
TextWidth = pRasterFxd->DrawTextWidth(hDC, "This is my text.");
TextHeight = pRasterFxd->DrawTextHeight(hDC, "This is my text.");
// Set the location for the text
pRasterFxd->PutTextTop (y);
pRasterFxd->PutTextLeft (x);
pRasterFxd->PutTextWidth (TextWidth);
pRasterFxd->PutTextHeight (TextHeight);
// Set the properties for drawing a rectangle behind the text.
pRasterFxd->PutDrawPenStyle(DRAWPENSTYLE_SOLID);
pRasterFxd->PutDrawMode(DRAWMODE_COPY_PEN);
pRasterFxd->PutDrawFillColor(RGB(0, 255, 0)); //Green
// Draw on the screen, not on the bitmap.
pRasterFxd->PutDrawPersistence(FALSE);
// Draw the rectangle, then draw the text.
pRasterFxd->DrawRectangle (NULL, hDC, x, y, TextWidth, TextHeight);
pRasterFxd->DrawText (NULL, hDC, "This is my text.", 0);
m_LEADRasterView1.ReleaseClientDC();
pRasterFxd->Release();