<< Click to Display Table of Contents >> GetCharacterHeight |
[Professional Edition and above]
Returns for the currently selected font the height of the bounding box of the first character in the provided string.
method VpeCoord VPE.GetCharacterHeight(
string Text
)
string Text
The text to be rendered, only the first character of the string is used. Any additional characters are ignored.
Returns:
The method returns for the currently selected font the height of the bounding box of the first character in the provided string.
In case of an error, -1 is returned.
Remarks:
If you provide the capital letter "M" to this method, the returned value is the same like the text metric value "Cap Height" defined by font designers.
Using the Ascent, Descent and Character Height, the VPE API provides ways to align text at the Cap Height, the baseline or the descent of a selected font.
Example:
The following example draws lines at text metric positions of some text. Additionally the add-on text "Test" is drawn at the cap height position of the main text.
VpeCoord left = 2;
VpeCoord top = 2;
VpeCoord right = 18;
doc.SetFont("Arial", 72);
VpeCoord ascent = doc.FontAscent;
VpeCoord descent = doc.FontDescent;
VpeCoord cap_height = doc.CharacterHeight("M");
// top
doc.Line(left, top, right, top);
// cap height position
VpeCoord cap_pos = ascent - cap_height;
doc.PenColor = COLOR_RED;
doc.Line(left, top + cap_pos, right, top + cap_pos);
// baseline
VpeCoord baseline = top + ascent;
doc.PenColor = COLOR_BLUE;
doc.Line(left, baseline, right, baseline);
// bottom
doc.Line(left, top + ascent + descent, right, top + ascent + descent);
// text
doc.Print(left, top, "Üg My Text.");
VpeCoord x = doc.nRight;
// add-on text, positioned at cap height of main text
doc.FontSize = 26;
VpeCoord SmallCapHeight = doc.GetCharacterHeight("M");
doc.Print(x, baseline - cap_height - (doc.FontAscent - SmallCapHeight), "Test");