VpeGetCharacterHeight

<< Click to Display Table of Contents >>

Navigation:  Rendering >

VpeGetCharacterHeight

Previous pageReturn to chapter overviewNext page

[Professional Edition and above]

Returns for the currently selected font the height of the bounding box of the first character in the provided string.

VpeCoord VpeGetCharacterHeight(

VpeHandle hDoc,

LPCSTR s

)

VpeHandle hDoc

Document Handle

LPCSTR s

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;

 

VpeSetFont(hDoc, "Arial", 72);

VpeCoord ascent = VpeGetFontAscent(hDoc);

VpeCoord descent = VpeGetFontDescent(hDoc);

VpeCoord cap_height = VpeGetCharacterHeight(hDoc, "M");

 

// top

VpeLine(hDoc, left, top, right, top);

 

// cap height position

VpeCoord cap_pos = ascent - cap_height;

VpeSetPenColor(hDoc, COLOR_RED);

VpeLine(hDoc, left, top + cap_pos, right, top + cap_pos);

 

// baseline

VpeCoord baseline = top + ascent;

VpeSetPenColor(hDoc, COLOR_BLUE);

VpeLine(hDoc, left, baseline, right, baseline);

 

// bottom

VpeLine(hDoc, left, top + ascent + descent, right, top + ascent + descent);

 

// text

VpePrint(hDoc, left, top, "Üg My Text.");

VpeCoord x = nRight(hDoc);

 

// add-on text, positioned at cap height of main text

VpeSetFontSize(hDoc, 26);

VpeCoord SmallCapHeight = VpeGetCharacterHeight(hDoc, "M");

VpePrint(hDoc, x, baseline - cap_height - (VpeGetFontAscent(hDoc) - SmallCapHeight), "Test");