My WPF win APP is using following code and it works alright when font is already installed.
Button infoButton = new Button();
infoButton.Content = new FontIcon
{
FontFamily = new FontFamily("Segoe MDL2 Assets"),
Glyph = "",
Foreground = new SolidColorBrush(Colors.WhiteSmoke)
};
I want to use custom font without installing it on windows. I've included all relevant font files within my solution (build action set as content). How can I use that with above code? I know how to use it in XAML but I'm want to do it in C#.
I have used the below link to use new Font in the WPF application which is not installed in the system - It worked:
<http://www.bizicbojan.com/post/2011/01/19/Embedding-and-Referencing-Fonts-in-your-WPF-application.aspx>
I have used FontFamily in the control as below.
FontFamily="/HPID.KioskUIControls;component/Fonts/#Segoe MDL2 Assets".
The font file is available in Fonts folder for me.
May be this will help you too.
Thanks.
Related
I am developing a WPF C# program that shows some texts in a textblock with several fonts.
Font setting must be portable, so i save user selected font files next to program folder to load each time (in a static-name file).
var textFont = new FontFamily("file:///" + AppDomain.CurrentDomain.BaseDirectory + "/themes/tmp/text/#" + textFontName);
1- how to change font file and set fontfamily from it realtime? (i set fontfamily from file but when it replaced with another font, textblock shows empty characters)
Update: a sample of my code: https://github.com/qwerty13/Wpf-local-font-bug
2- how to install missing font and use it realtime? I am using fontreg.exe but it requires Adminstrator access and restarting program to apply.
I am using Xamarin.Forms and having difficulty using FontAwesome.
This font has its specific code to use.
public const string InfoCircle = "\uf05a";
I need to use them in a listview menu.
If I use them directly by typing it in Label, it works fine, but if I bring the font value from an API for example, instead of the FontAwesome-converted icon, the font-specific code appears. How to make the font appear correctly?
Thanks.
Print of iOS Simulator
I'm currently evaluating Xamarin Forms as an alternative to our webbased HTML applications targeting mobile platforms.
Our applications often use graphical symbols embedded in paragraphs of text.
The desired effect looks like this:
Of course the text also has to be able to freely wrap around, including all the symbols. In HTML this is simply achieved like this:
<p>Sample text with <img src="sample.jpg"> embedded</p>
How can I achieve the same effect using Xamarin Forms? I already looked at FormattedStrings which allow formatting of subparagraphs of Labels, however they do not seem to allow embedding of images.
Also please note that the solution is required to support iOS, Android and Windows Phone 8.1 at least.
Obviously being forced to use a WebView almost defeats the point of moving a HTML5 app to Xamarin!
In the Xamarin Forums a similar question has been asked: https://forums.xamarin.com/discussion/1649/text-with-image
To solve the problem Tomasz Cielecki cooked up some sample code here: https://gist.github.com/Cheesebaron/5034440
He then went onto blog about it here:
http://blog.ostebaronen.dk/2013/02/adding-images-to-textview-and-edittext.html
<snip>
I started out with a super simple sample trying to get an Image shown in a TextView. I googled up some solutions and sure, Spannables allow using ImageSpan inside of them! There were nice samples and such, and I came up with this.
ImageSpan in TextView
//Load up your drawable.
var imageSpan = new ImageSpan(this, Resource.Drawable.Icon);
//Set the text of SpannableString from TextView
var spannableString = new SpannableString(textView.Text);
//Add image at end of string
spannableString.SetSpan(imageSpan, textView.Text.Length-1, textView.Text.Length, 0);
Easy, huh? And you can add loads of other Spans to the Spannable, such as StyleSpan, which you can style your fonts with bold, italic and other styles.
Since that was so easy, I quickly tried to do that with an EditText. It also works just fine...
</snip>
Currently, the only way to have symbols and images within text blocks is to use WebView (https://developer.xamarin.com/guides/xamarin-forms/working-with/webview/)
var browser = new WebView();
var htmlSource = new HtmlWebViewSource ();
htmlSource.Html = #"<html><body>
<h1>Xamarin.Forms</h1>
<p>Welcome to WebView.</p>
</body></html>";
browser.Source = htmlSource;
I have been searching for a solution, but I couldn't succeed. The problem is as follows.
I have a WPF application where I am using FlowDocuments. I want to create a corresponding application on Android and share documents between those applications (WPF and Android) using a web service.
Android has SpannableString. But I couldn't figure out if we have a control in Android, like RichTextBox in WPF.
To sum up my question, Is there a format like Rich Text Format and an Android control to both display and manipulate this document on Android?
You can make use of the TextView together with the span fields to set different text styles (similar to Runs on XAML). There is also a SpannableStringBuilder which might ease this process.
SpannableString text = new SpannableString("Hello World!")
text.setSpan(new ForegroundColorSpan(Color.BLUE), 0, 5, 0);
text.setSpan(new StrikethroughSpan(), 7, 11, 0);
How to use custom font asp.net application.
I have a font file with me. I want to add that file as a resource and use it inside the project.
how to do it?
PrivateFontCollection pfc = new PrivateFontCollection();
Stream fontStream = this.GetType().Assembly.GetManifestResourceStream(Server.MapPath("~/Resources/EAN-13.ttf"));
byte[] fontdata = new byte[fontStream.Length];
fontStream.Read(fontdata, 0, (int)fontStream.Length);
fontStream.Close();
unsafe
{
fixed (byte* pFontData = fontdata)
{
pfc.AddMemoryFont((System.IntPtr)pFontData, fontdata.Length);
}
}
I tried this. But its not working.
You must distinguish between the code that run on server and the code that run on client browser.
The fonts that you have on your computer, on your server, can not be visible on user computer using the code behind just because you loading the fonts.
So you have two options here.
Load the fonts, and render a text in an image using this fonts, then show this image to the user.
Use client side techniques to show this fonts. Some of them are cross browser font embedding, and other can be javascript that can rendered them on client side.
You can google it with "embed custom fonts website".
Also you can check : http://typeface.neocracy.org/
and Is it possible to use custom fonts - using font-face?