Font example for Delphi
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.
var
TestText: String;
TextWidth: Single;
TextHeight: Single;
RasterFxd: LEADRasterFXD;
hDC: Longint;
nRet: Integer;
sRet: Smallint;
TempFont: TFont;
begin
RasterFxd:= CreateComObject ( CLASS_LEADRasterFxd) as LEADRasterFxd;
hDC := LEADRasterView1.GetClientDC(nRet);
//Specify the text, font, and styles
TestText := 'This is my text.';
TempFont:= TFont.Create ( ) ;
SetOleFont ( TempFont, RasterFxd.Font ) ;
TempFont.Name := 'Times New Roman';
TempFont.Size := 16;
RasterFxd.DrawFontColor := RGB(0, 0, 255); //Blue
RasterFxd.TextStyle := FXD_TEXTSTYLE_NORMAL;
RasterFxd.TextAlign := FXD_TEXTALIGN_HCENTER_VCENTER;
//Get the width and height of the text to be drawn.
TextWidth := RasterFxd.DrawTextWidth (hDC, TestText);
TextHeight := RasterFxd.DrawTextHeight (hDC, TestText);
//set the location for the text
RasterFxd.TextTop := y;
RasterFxd.TextLeft := x;
RasterFxd.TextWidth := TextWidth;
RasterFxd.TextHeight := TextHeight;
//Set the properties for drawing a rectangle behind the text.
RasterFxd.DrawPenStyle := DRAWPENSTYLE_SOLID;
RasterFxd.DrawMode := DRAWMODE_COPY_PEN;
RasterFxd.DrawFillColor := RGB(0, 255, 0); //Green
//Draw on the screen, not on the bitmap.
RasterFxd.DrawPersistence := False;
//Draw the rectangle, then draw the text.
RasterFxd.DrawRectangle (Nil, hDC, x, y, TextWidth, TextHeight);
RasterFxd.DrawText (Nil, hDC, TestText, 0);
TempFont.Free ( ) ;
LEADRasterView1.ReleaseClientDC(sRet);
end;