[英]System::Drawing::Text::PrivateFontCollection not working when the font is not installed
我试图从内存(嵌入的资源)中添加字体,并将其用于Windows窗体(c ++ / cli)应用程序...代码正在工作,但是当计算机上未安装指定的字体时,文本框将使用默认字体而不是我的自定义字体。 CompatibleTextRenderingDefault设置为true。
System::Drawing::Text::PrivateFontCollection^ privateFont = gcnew System::Drawing::Text::PrivateFontCollection();
IO::Stream^ fontStream = Reflection::Assembly::GetExecutingAssembly()->GetManifestResourceStream("textfont.otf");
array<Byte>^ fontData = gcnew array<Byte>(fontStream->Length);
fontStream->Read(fontData, 0, (int)fontStream->Length);
fontStream->Close();
pin_ptr<byte> fontAddress = &fontData[0];
privateFont->AddMemoryFont((IntPtr)fontAddress, fontData->Length);
this->TextBox_Username->Font = gcnew System::Drawing::Font(safe_cast<System::Drawing::FontFamily^>(privateFont->Families[0]), 9.749999F, System::Drawing::FontStyle::Bold);
this->TextBox_Password->Font = gcnew System::Drawing::Font(safe_cast<System::Drawing::FontFamily^>(privateFont->Families[0]), 9.749999F, System::Drawing::FontStyle::Bold);
两种可用于将字体加载到PrivateFontCollection中的方法(AddFontFile,AddMemoryFont)都不完全支持OpenType字体。 请改用TrueType字体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.