[英]System::Drawing::Text::PrivateFontCollection not working when the font is not installed
I tried to add font from memory (embedded resource) and use it for my windows form (c++/cli) application... The code is working, but when the specified font is not installed on the computer the textbox is using the default font instead of my custom font. 我试图从内存(嵌入的资源)中添加字体,并将其用于Windows窗体(c ++ / cli)应用程序...代码正在工作,但是当计算机上未安装指定的字体时,文本框将使用默认字体而不是我的自定义字体。 CompatibleTextRenderingDefault is set to true.
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);
Both methods (AddFontFile, AddMemoryFont) available to load font into PrivateFontCollection do not fully support OpenType fonts. 两种可用于将字体加载到PrivateFontCollection中的方法(AddFontFile,AddMemoryFont)都不完全支持OpenType字体。 Use TrueType font instead.
请改用TrueType字体。
See also https://social.msdn.microsoft.com/Forums/en-US/40834a16-2378-4aeb-a499-25f835fe5738/opentype-font-as-embedded-resource?forum=winforms 另请参阅https://social.msdn.microsoft.com/Forums/zh-CN/40834a16-2378-4aeb-a499-25f835fe5738/opentype-font-as-embedded-resource?forum=winforms
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.