Font example for C++ Builder
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.
AnsiString TestText;
float TextWidth;
float TextHeight;
LEADRasterFXD* pRasterFxd;
long hDC;
TFont * TempFont = new TFont();
CoCreateInstance(CLSID_LEADRasterFXD, NULL, CLSCTX_ALL, IID_ILEADRasterFXD, (void**)&pRasterFxd);
hDC = LEADRasterView1->GetClientDC();
//Specify the text, font, and styles
TestText = "This is my text.";
SetOleFont ( TempFont, pRasterFxd->Font ) ;
TempFont->Name = "Times New Roman";
TempFont->Size = 16;
SetOleFont ( TempFont, pRasterFxd->Font ) ;
pRasterFxd->DrawFontColor = RGB(0, 0, 255); //Blue
pRasterFxd->TextStyle = FXD_TEXTSTYLE_NORMAL;
pRasterFxd->TextAlign = FXD_TEXTALIGN_HCENTER_VCENTER;
//Get the width and height of the text to be drawn->
TextWidth = pRasterFxd->DrawTextWidth (hDC, AnsiToOLESTR(TestText.c_str()));
TextHeight = pRasterFxd->DrawTextHeight(hDC, AnsiToOLESTR(TestText.c_str()));
//set the location for the text
pRasterFxd->TextTop = y;
pRasterFxd->TextLeft = x;
pRasterFxd->TextWidth = TextWidth;
pRasterFxd->TextHeight = TextHeight;
//Set the properties for drawing a rectangle behind the text->
pRasterFxd->DrawPenStyle = DRAWPENSTYLE_SOLID;
pRasterFxd->DrawMode = DRAWMODE_COPY_PEN;
pRasterFxd->DrawFillColor = RGB(0, 255, 0); //Green
//Draw on the screen, not on the bitmap->
pRasterFxd->DrawPersistence = False;
//Draw the rectangle, then draw the text->
pRasterFxd->DrawRectangle (NULL, hDC, x, y, TextWidth, TextHeight);
pRasterFxd->DrawText (NULL, hDC, AnsiToOLESTR(TestText.c_str()), 0);
LEADRasterView1->ReleaseClientDC( );
TempFont-> Free ( ) ;
pRasterFxd-> Release( );