This method uses GDI+ functionality to retrieve the height and width of text from text information.

[C++Builder]   [ bool = ]imagekitcontrolname->PrintDraw->MeasureString(HDC, int AreaWidth, int AreaHeight, float &AWidth, float &AHeight, int &charactersFitted, int &linesFilled, int FormatFlags, TVIkDeviceUnitMode UnitMode)
[Delphi]   [ Boolean = ]imagekitcontrolname.PrintDraw.MeasureString(DC: HDC; AreaWidth: Integer; AreaHeight: Integer; var AWidth: Single; var AHeight: Single; var charactersFitted: Integer; var linesFilled: Integer; FormatFlags: Integer; UnitMode: TVIkDeviceUnitMode)

[TVIkDeviceUnitMode Type]

Unit
     ImageKit

type
     TVIkDeviceUnitMode = (vikPrinterPixel, vikPrinterMM);

Parameters

Name Explanation
DC The device context
AreaWidth The maximum width (from 0)
AreaHeight The maximum height (from 0)
AWidth Retrieves the width of the text
AHeight Retrieves the height of the text
charactersFitted The number of characters in the retrieved text
linesFilled The number of lines in the retrieved text
FormatFlags The string format information (default is 0)
UnitMode Units of measurement (vikPrinterPixel: pixels, vikPrinterMM: 0.1mm)

Return Value

Returns True if successful. Returns False if unsuccessful.

Explanation

The MeasureString method uses GDI+ functionality to retrieve the height and width of text from text information. To retrieve the height and width of the text set in the Text property, the following properties should be set: FontName, FontSize, HCentering, VCentering, HotkeyPrefix, Text. If 0 is set in either the AreaWidth or AreaHeight parameters, the height and width of the whole text will be retrieved. However if the AreaWidth and AreaHeight parameters contain values other than 0, then only the height and width of the text contained within that area will be retrieved. The charactersFitted and linesFilled work in the same way. If 0 is set in either the AreaWidth or AreaHeight parameters, then the number of characters or the number of lines in the whole text will be retrieved and returned in the charactersFitted and linesFilled parameters. However if the AreaWidth and AreaHeight parameters contain values other than 0, then the values in the charactersFitted and linesFilled parameters will relate only to the text contained within the area defined by the AreaWidth and AreaHeight parameters.

If the UnitMode parameter is vikPrinterPixel then the AreaWidth, AreaHeight, Width, Height parameters are in pixel units.

If the UnitMode parameter is vikPrinterMM then AreaWidth, AreaHeight, Width, Height parameters are in 0.1mm units.


String Format info

Value Explanation
0x00000001 Text is displayed from right to left
0x00000002 Text is vertically aligned.
0x00000004 Parts of characters are allowed to overhang the string's layout rectangle. By default, characters are repositioned to avoid any overhang.
0x00000020 Control characters such as the left-to-right mark are shown in the output with a representative glyph.
0x00000400 Fallback to alternate fonts for characters not supported in the requested font is disabled. Any missing characters are displayed with the fonts missing glyph, usually an open square.
0x00000800 Includes the trailing space at the end of each line. Set this flag to include that space in measurement.
0x00001000 Text wrapping between lines when formatting within a rectangle is disabled. This flag is implied when a point is passed instead of a rectangle, or when the specified rectangle has a zero line length.
0x00002000 Only entire lines are laid out in the formatting rectangle. By default layout continues until the end of the text, or until no more lines are visible as a result of clipping, whichever comes first. Note that the default settings allow the last line to be partially obscured by a formatting rectangle that is not a whole multiple of the line height. To ensure that only whole lines are seen, specify this value and be careful to provide a formatting rectangle at least as tall as the height of one line.
0x00004000 Overhanging parts of glyphs, and unwrapped text reaching outside the formatting rectangle are allowed to show. By default all text and glyph parts reaching outside the formatting rectangle are clipped.

The values of the MeasureString method in Delphi should start with $ instead of 0x.

The following constants can be used: (vikDirectionRightToLeft = 0x00000001, vikDirectionVertical = 0x00000002, vikNoFitBlackBox = 0x00000004, vikDisplayFormatControl = 0x00000020, vikNoFontFallback = 0x00000400, vikMeasureTrailingSpaces = 0x00000800, vikNoWrap = 0x00001000, vikLineLimit = 0x00002000, vikNoClip = 0x00004000).

Sample code:

In C++Builder

float Str_Width, Str_Height;
int charactersFitted, linesFilled, ARight, ABottom;

VImageKit1->PrintDraw->ClearProperty();
VImageKit1->PrintDraw->FontSize = 20;
VImageKit1->PrintDraw->FontName = "Arial";
VImageKit1->PrintDraw->HotkeyPrefix = 0;
VImageKit1->PrintDraw->Text = "Text";
VImageKit1->PrintDraw->MeasureString(DC, 0, 0, Str_Width, Str_Height, charactersFitted, linesFilled, 0, vikPrinterPixel);

ARight = 10 + (int)Str_Width - 1;
ABottom = 10 + (int)Str_Height - 1;
VImageKit1->PrintDraw->CharAngle = 0;
VImageKit1->PrintDraw->TextColor1 = clRed;
VImageKit1->PrintDraw->Alpha1 = 255;
VImageKit1->PrintDraw->TextColor2 = clWhite;
VImageKit1->PrintDraw->Alpha2 = 255;
//Use Gradiation
VImageKit1->PrintDraw->DrawString(hDC, 10, 10, ARight, ABottom, 4, 0, 0, 0, 0, TVIkOutPutDeviceMode(vikPrinterPixel));

In Delphi

Str_Width, Str_Height: Single;
CharactersFitted, linesFilled, TxRight, TxBottom: Integer;

VImageKit1.PrintDraw.ClearProperty();
VImageKit1.PrintDraw.FontSize := 20;
VImageKit1.PrintDraw.FontName := 'Arial';
VImageKit1.PrintDraw.HotkeyPrefix := 0;
VImageKit1.PrintDraw.Text := 'Text';
VImageKit1.PrintDraw.MeasureString(DC, 0, 0, Str_Width, Str_Height, charactersFitted, linesFilled, 0, vikPrinterPixel);

TxRight := 10 + Trunc(Str_Width) - 1;
TxBottom := 10 + Trunc(Str_Height) - 1;
VImageKit1.PrintDraw.CharAngle := 0;
VImageKit1.PrintDraw.TextColor1 := clRed;
VImageKit1.PrintDraw.Alpha1 := 255;
VImageKit1.PrintDraw.TextColor2 := clWhite;
VImageKit1.PrintDraw.Alpha2 := 255;
//Use Gradiation
VImageKit1.PrintDraw.DrawString(DC, 10, 10, TxRight, TxBottom, 4, 0, 0, 0, 0, TVIkOutPutDeviceMode(vikPrinterPixel));

Differences between the ImageKit7/8/9/10

In VCL the constants contain a "v". In ActiveX, the constants are: ikPrinterPixel, ikPrinterMM, vikDirectionRightToLeft, vikDirectionVertical, vikNoFitBlackBox, vikDisplayFormatControl, vikNoFontFallback, vikMeasureTrailingSpaces, vikNoWrap, vikLineLimit, vikNoClip.

 

The ImageKit10 VCL is a product created by Newtone Corporation