Available in the LEADTOOLS Imaging toolkit. |
Font example for C++ 4.0 and later
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. The header file must have the following statement: #include "font.h".
void CDrawtestDlg::OnMouseUpLeadctrl1(short Button, short Shift, long x, long y)
{
float TextWidth;
float TextHeight;
// Specify the font, and styles.
COleFont myFont = m_Lead1.GetFont();
myFont.SetName("Times New Roman");
CY size = myFont.GetSize();
size.Hi = 0; // Hi will be 0 unless you use a really big font
size.Lo = 32L * 10000L; // 32 point
myFont.SetSize(size);
m_Lead1.SetDrawFontColor(RGB(0, 0, 255)); //Blue
m_Lead1.SetTextStyle(EFX_TEXTSTYLE_NORMAL);
m_Lead1.SetTextAlign(EFX_TEXTALIGN_HCENTER_VCENTER);
// Get the width and height of the text to be drawn.
TextWidth = m_Lead1.DrawTextWidth("This is my text.");
TextHeight = m_Lead1.DrawTextHeight("This is my text.");
// Set the location for the text
m_Lead1.SetTextTop(y);
m_Lead1.SetTextLeft(x);
m_Lead1.SetTextWidth(TextWidth);
m_Lead1.SetTextHeight(TextHeight);
// Set the properties for drawing a rectangle behind the text.
m_Lead1.SetDrawPenStyle(DRAWPENSTYLE_SOLID);
m_Lead1.SetDrawMode(DRAWMODE_COPY_PEN);
m_Lead1.SetDrawFillColor(RGB(0, 255, 0)); //Green
// Draw on the screen, not on the bitmap.
m_Lead1.SetDrawPersistence(FALSE);
// Draw the rectangle, then draw the text.
m_Lead1.DrawRectangle(x, y, TextWidth, TextHeight);
m_Lead1.DrawText("This is my text.", 0);
}