function GetTextBound(UseText: WideString; UseFont: WideString; UseSize: single;
var bW: integer;
var bH: integer; UseStrFormat: integer): GPSTATUS;
stdcall;
var
Graphics: cardinal;
Fam: GpFontFamily;
TempFont: GpFont;
DC: HDC;
begin
result := GenericError;
strFormat :=
nil;
Fam :=
nil;
// Create matching font
try
GdipCheck(GdipCreateFontFamilyFromName(UseFont,
nil, Fam));
if Assigned(Fam)
then
begin
GdipCheck(GdipCreateFont(Fam, UseSize, 0, 2, TempFont));
if Assigned(TempFont)
then
begin
DC := GetDC(GetDesktopWindow);
GdipCheck(GdipCreateStringFormat(0, 0, strFormat));
GdipCheck(GdipCreateFromHDC(
DC, Graphics));
GdipCheck(GdipMeasureString(Graphics, PWideChar(UseText), length(UseText), TempFont,
@layoutRect, strFormat, @boundingBox,
nil,
nil));
if Assigned(strFormat)
then
GdipCheck(GdipDeleteStringFormat(strFormat));
bW := round(boundingBox.Width - boundingBox.X);
bH := round(boundingBox.Height - boundingBox.Y);
if UseStrFormat <> 0
then
Swap(bW, bH);
ReleaseDc(GetDesktopWindow,
DC);
end;
end;
finally
if Graphics <> 0
then
GdipCheck(GdipDeleteGraphics(Graphics));
if Assigned(TempFont)
then
GdipCheck(GdipDeleteFont(TempFont));
// Lösche das Font Object
if Assigned(Fam)
then
GdipCheck(GdipDeleteFontFamily(Fam));
// Lösche das Font Family Object
end;
end;