How to apply custom font icon shapes in UWP - c#

I want to show some custom shapes through font icons in my UWP project. I have created my own .ttf file for custom shapes. But I don't know how to apply it programmatically.
TextBlock text = new TextBlock();
string font = "Assets/mycustomfont.webfont.ttf#MyCustomFont";
text.FontFamily= new Windows.UI.Xaml.Media.FontFamily(font);
this.grid1.Children.Add(text);
Anyone please help me on this.

The approach you are using is practically correct, but make sure to check the following:
The .ttf file must be included in the project and have Build Action set to Content in the Properties window
Start the path to the font with / to make sure it begins in root.
Ensure the # suffix actually matches the font metadata. A font viewer app like dp4 Font Viewer can help you with that. Use the Font Family name as the suffix.
I have written an article on my blog about using custom fonts in UWP so check it out to see if you haven't missed some of the steps there.

Related

How to get any suitable font in ImageSharp?

I am very tired of providing fonts for my application. It would be a lot easier to have some ready-to-use fonts collection that I can use.
See this
//I need to add text to image, no matter what font is
var fo = SystemFonts.Find("Mono");
var font = new Font(fo, 10f, FontStyle.Regular);
x.DrawText("123", font,color,point);
I need to be sure that computer running this piece of code have font Mono installed. But it is not always the case, so I had to keep font file in my project folder and so on...
This is just annoying.
What I want to do
//this must be a font that included into library itself.
var font = FontCollection.Any;
x.DrawText("123", font,color,point);
With this I can be sure that I will be able to print text on image no matter what system is.

How to get Internal Font Name programmatically in UWP mobile and desktop

I have downloaded custom font through code and want to apply it on my text view for that I want to know the exact name of font.
Note:
I want to know the font internal name not the font file name.let a font is abc.tff and when open the font the Name at top is "Arial", so i need the name Arial.
I have found method for pure windows 8/7 desktop applications not for UWP.
There is no way that I've found to extract the metadata from a font in order to find the name.
What you could do is create an observable collection that lists the data yourself... not ideal, but realistic.
Add(new Font("ABeeZee", "/Fonts/ABeeZee-regular.ttf#ABeeZee", "Sans Serif")
Then when you call the font, you can grab the data from your collection.

Defining a custom FontFamily with several font files in XAML/C#

I'm trying to define a custom font in a C# WinRT app. I can define a single-file font in XAML like so:
<Page.Resources>
<FontFamily x:Key="Cousine">/Fonts/Cousine-Regular.ttf#Cousine</FontFamily>
</Page.Resources>
But I have several other font files that I would like to be used where appropriate:
Cousine-Bold.ttf
Cousine-BoldItalic.ttf
Cousine-Italic.ttf
How do I define a font family that uses the different fonts for the different font weights/variants?
They should all be in the same ttf file and you reference them like:
/Fonts/Cousine-Regular.ttf#Cousine
/Fonts/Cousine-Regular.ttf#Cousine Bold
/Fonts/Cousine-Regular.ttf#Cousine Italic
/Fonts/Cousine-Regular.ttf#Cousine Bold Italic
I don't know if the last one is right. I came here looking for the answer to that question. It might be BoldItalic. Whatever it is, I believe you create that name when you create the ttf file so you would be able to figure it out.

rtf change font size

I am trying to perform edit functions in a RichTextBox on a C# (Windows Forms) application.
I would like to be able to select any number of text characters in the script then change targeted font characteristics.
The trouble I have is that each characters font properties may be set to different font. In this case the textbox ignores the event that I request.
How can I solve my problem?
Take a look at this:
Changing font for richtextbox without losing formatting
I think it's the same issue. LarsTech's solution is working perfectly for me.
I have a code to change the size:
RichTextBox1.Font.Size == new System.Drawing.Font(RichTextBox1.Font.Name, yoursize)
And if you want to change only the selected text size:
RichTextBox1.SelectionFont.Size == new System.Drawing.Font(RichTextBox1.SelectionFont.Name, yoursize)
Hope it will help.

How to use custom font in visual studio 2008 for C#.net window application?

I want to use Indian Font (Hindi) in Windows apps.When i used Mangal font for Hindi text ,then text visible but in block format.
so any one can help me for this.
Create New windows forms project and in Form.OnLoad handler, add the following lines:
PrivateFontCollection pfc = new PrivateFontCollection();
string fontFilePath = "C:\\Fonts\\PALETX3.ttf"
pfc.AddFontFile(fontFilePath);
label1.Font = new Font(pfc.Families[0], 16, FontStyle.Regular);
You can find more information from
http://msdn.microsoft.com/en-us/library/ms533820(VS.85).aspx
You can use this code:
YourMainForm.YourTextBox.Font = new Font("Your name of indian font",
YourMainForm.YourTextBox.Font.Size);
Make sure the font you are using supports the Unicode characters in controls. You can find this out using windows utility Character Map.
Some older fonts have characters for a certain code page but not for Unicode characters. For example windows font Marlett have only a few Unicode chars defined, the rest will appear as the boxes in your screen shot. If that is the case your best bet is to find a newer Unicode version of the font. Although in theory you can use font editing software to create a new version yourself (the glyphs are already in there) but it won't be easy. Best of luck :)

Categories