Example #1
0
// *********************************************************************
// 					CreateFont()										
// *********************************************************************
CFont* GdiLabelDrawer::CreateFont(CLabelOptions* options, long fontSize, double scaleFactor)
{
	CFont* fnt = new CFont();

	CString s(options->fontName);
	fnt->CreatePointFont(fontSize * 10, s);

	LOGFONT lf;
	fnt->GetLogFont(&lf);

	if (scaleFactor != 1.0)
	{
		lf.lfWidth = long((double)lf.lfWidth * scaleFactor);
		lf.lfHeight = long((double)lf.lfHeight * scaleFactor);
	}
	if (abs(lf.lfHeight) < 4)	// changed 1 to 4; there is no way to read labels smaller than 4, but they slow down the performance
	{
		fnt->DeleteObject();
		delete fnt;
		return NULL;
	}

	lf.lfItalic = options->fontStyle & fstItalic;
	lf.lfUnderline = options->fontStyle & fstUnderline;
	lf.lfStrikeOut = options->fontStyle & fstStrikeout;
	lf.lfWeight = options->fontStyle & fstBold ? FW_BOLD : 0;

	fnt->DeleteObject();
	fnt->CreateFontIndirectA(&lf);

	return fnt;
}