how can i work with font that dose not support any kind of FontStyle. by the way, I can not create a font Object from it. help??
The font code on Windows (as on any platform I guess) doesn't create new fonts from scratch; it will rather interpret what fonts are installed / available on your system and give you a way to work with those.
Each font is reached by making a FontFamily object; such a FontFamily then contains Font objects for each style that is available. If a certain style (such as 'bold' or 'italic') is not available on your system, you won't be able to create it.
You can test whether this is the case by using the FontFamily.IsStyleAvailable. Defined here as:
public bool IsStyleAvailable(
FontStyle style
)
If you want to create a font, you'll have to make sure it's available on the system first (which means you'll have to use a common font or package the font with your solution if you want an uncommon one).
Related
Ive seen https://docs.unity3d.com/ScriptReference/Font.GetOSInstalledFontNames.html however I want to know what would be the most efficient method of
Getting all available fonts in Resources folder into enum called FontFamily
Setting/accessing available font weight for each font into enum called FontWeight
Like an Adobe program would.
I can get individual font FILES from Resources with (Font)Resources.Load("Inter-Black-slnt=0"); however I want to display just Inter for all the Inter font files, just Arial for all Arial, etc in my enum FontFamily.
I then need to see which weights were provided for each font in FontFamily and update the FontWeight enum accordingly. I.e. if I have Arial-Bold, Arial-Regular, and Arial-Light, FontFamily would contain Bold, Regular, Light.
The only way I can think to do this is run a for loop splitting the names of all font files I find, but I want to know whether there's a more efficient/performant way to do this. How can I populate these font enums?
When displaying text in a Windows Form (like a TextBox for example) I can enter Chinese characters in it if I want, and they will get displayed correctly. However, the font used by the Form is not actually capable of rendering Chinese. As a result, if I try to use the Form's font in order to create a PDF file containing the text, it won't work:
myPdf.RenderText(myForm.Font, myForm.Text);
In this case in Windows 10, myForm.Font is just Microsoft Sans Serif (or Arial in older Windows versions,) which does not support Chinese (or CJK in general) and as a result the PDF won't render correctly when embedding the Arial font in it.
So, how do I find out which font is really used to render text in a Windows Form? It can't be what the Font property says it is. In this particular case, it's probably "SimSun" or some other system font that supports Chinese characters, but there doesn't seem to be any way whatsoever to find out.
How do I deal with this? If it's not possible to get the true font of a Form, then could I somehow detect what font (or combination of fonts) Windows would use to render a piece of text on a Form before actually displaying the text on that Form?
I'm working on a project in Windows Forms and I want to use custom fonts for buttons etc.
I have a static class that contains the styles of fonts that I want. For example:
ParagraphFont = new Font(Properties.Resources.Font, 14.25F);
TitleFont = new Font(Properties.Resources.Font, 48, FontStyle.Bold);
I want to be able to apply the font to the form/user control through the designer, but I can't figure out how to do this.
I've tried setting the fonts of all the controls to these variables after the InitialiseComponent() method, but this seems long-winded and tedious to do to the multiple forms and controls that my project has
Is there a quicker way of doing this?
Edit: My question is different to the suggested duplicate. I don't need to set the default font of the project, I want to set the font of each control individually to a style variable. For example:
label.Font = ParagraphFont;
In the designer. This way, I can change the font used in ParagraphFont at any time
How can I change the Font.Size in a RichTextBox .SelectionFont (which has two or three different FontFamily), without affecting the FontFamilyand the FontStyle
This one works fine, if I have only one Font.Family
richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont.FontFamily, 12);
But, if I have more, it throws nullexception.
Perhaps this answer from the question: "Reset RTF in RichTextBox?" may help you. I quote:
More you ask?
I use most of this via a small utility class that wraps this for all the styles and font changes. This way you can change font-size and not change font name, etc.
I've had the same problem. Check the answer by LarsTech here:
Changing font for richtextbox without losing formatting
You'll find properties such as SelectionFontName, SelectionFontSize, ...
How can I use an embedded font in Metro UI app?
Is it possible to use one for Tile Update?
To embed font in your Windows Store app, add the font to your project as "Content", and in your XAML simply write something like:
<TextBlock FontFamily="/Fonts/MyFont.otf#Cool Font"/>
Assuming your font name is "Cool Font", the file name is "MyFont.otf", and you placed in "Fonts" folder
Regarding how to use an embedded font, first take a look at About font embedding. Some of the classes that you might use are CreateFontFace or CreateFontFileReference.
No, there is not a way to change the font on your tile during a tile update (unless of course the font is part of your logo/image that you are sending to the tile). For reference, here is the tile schema for sending live updates to your tile, which doesn't have a way to change the font.