GDI+私有字体集合引用新字体显示文字

GS_Neo 2009-02-05 05:55:24

/// <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);
}

文字无法显示,不知什么问题。。。。
...全文
194 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
fjwyshan 2009-02-06
  • 打赏
  • 举报
回复
友情up
noenoughmemory 2009-02-06
  • 打赏
  • 举报
回复
友情up
GS_Neo 2009-02-06
  • 打赏
  • 举报
回复
没有人吗?自己顶一下。。。。
GS_Neo 2009-02-06
  • 打赏
  • 举报
回复

/// <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);

}

换种方式解决,谢谢两位的友情up...

19,464

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧