19,464
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 用简粗隶书新字体显示文字
/// </summary>
void CGDIPlusDemoView::OnPrivateFontCollection(Graphics* graphics)
{
//PointF pointF(0.0f, 10.0f);
SolidBrush solidBrush(Color::Red);
//创建私有字体集
PrivateFontCollection privateFontCollection;
privateFontCollection.AddFontFile(L"C:\\简粗隶书.TTF");
if(privateFontCollection.GetLastStatus() != Ok)
{
AfxMessageBox(_T("添加文件出错"));
return;
}
//从私有字体集合中构造简粗隶书,大小为像素
FontFamily pFontFamily(L"简粗隶书", &privateFontCollection);
Font tmpFont(&pFontFamily, 35);
WCHAR string[256];
wcscpy(string,L"沉舟侧畔千帆过");
RectF layout(100,100,200,100);
StringFormat format;
format.SetAlignment(StringAlignmentCenter);
format.SetLineAlignment(StringAlignmentCenter);
graphics->DrawString(string,wcslen(string),&tmpFont,layout,&format,&solidBrush);
}
/// <summary>
/// 用简粗隶书新字体显示文字
/// </summary>
void CGDIPlusDemoView::OnPrivateFontCollection(Graphics* graphics)
{
SolidBrush solidBrush(Color(255, 0, 0, 0));
INT found = 0;
INT count = 0;
WCHAR familyName[50];
FontFamily* pFontFamily;
PrivateFontCollection privateFontCollection;
// Add four font files to the private collection.
privateFontCollection.AddFontFile(L"C:\\WINDOWS\\Fonts\\Arial.ttf");
privateFontCollection.AddFontFile(L"C:\\WINDOWS\\Fonts\\Cour.ttf");
privateFontCollection.AddFontFile(L"C:\\WINDOWS\\Fonts\\Times.ttf");
privateFontCollection.AddFontFile(L"C:\\简粗隶书.TTF");
// How many font families are in the private collection?
count = privateFontCollection.GetFamilyCount();
// Allocate a buffer to hold the array of FontFamily objects returned by
// the GetFamilies method.
pFontFamily = (FontFamily*)malloc(count * sizeof(FontFamily));
// Get the array of FontFamily objects.
privateFontCollection.GetFamilies(count, pFontFamily, &found);
for(INT j = 0; j < found; ++j)
{
// Get the font family name.
pFontFamily[j].GetFamilyName(familyName);
// Pass the family name and the address of the private collection to a
// Font constructor.
Font font(familyName, 16);
// Use the font to draw a string.
graphics->DrawString(
L"Hello",
5, // string length
&font,
PointF(10.0f, (REAL)j*25),
&solidBrush);
}
free(pFontFamily);
}