As stated in the title i have a Font instance and i would get the FontFamily used to build that Font instance.
I need that specific FontFamily istance (or the ability to istantiate an equivalent instace).
Edited :
As asked i used Winform (on windows mobile, so i use NetCF 3.5)
You can use this to get the FontFamily of a Font:
FontFamily ff = oldFont.FontFamily;
Update - In .NET CF, all classes are optimized for minimal resource usage. The FontFamily property, thus does not exist in the Font class.
Related
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.
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.
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.
I'm facing a awkward problem. I can't set the FontStyle of a text. This is annoying me cause until now I'm not able to understand why the System. Drawing is missing, why I can't import her (At least I think I shouldn't).
The context is I'm in a silverlight application, setting the font color and style of a dynamic tree.
I'm using System.Windows.Media.SolidColorBrush to the Foreground, but I trying to set the FontStyle without success. And all google that I try answer the simple: 'use System.Drawing'
What I'm missing here?
You should not try to create a new FontStyle struct, but use the static properties of FontStyles: FontStyles.Italic or FontStyles.Normal.
The thing is, i need to use to function Graphics.measureString to know how long (in pixel) a string will be rendered on my page. The thing is, measureString needs to know what font family and font size (Verdana 11 for example) is used to be able to give me the width. For info, Graphics.measureStrings needs the string to measure, the font family and the font size, then it returns a SizeF object from which you can get the width attribute so you know what length it is on your webpage (it isn't always perfectly accurate though).
So, i was wondering if there was a way of getting that info from the page for the code behind, or am i doomed to hard code it somewhere in my control or some constants class.
Thanks for future (helping) answers
If your control has runat="server" then you can use the Style property to get the font-family and font-size:
string fontFamily = myControl.Style["font-family"];
string fontSize = myControl.Style["font-size"];
This will only work for inline styles though.
You can use this over Net Framework 4 with System.Web.dll; for example:
CssStyleCollection css = CssStyleTools.Create();
css.Value = "border-top:1px dotted #BBB;margin-top: 0px;font-size:12px";
Console.WriteLine(css["margin-top"]); //prints "0px"
and you can look at "Change Font Family and Font Size using HtmlAgilityPack".