Install the font when the application is running - c#

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.

Related

Why do only some button icons display

I am trying to set a toolbar button image. I have found various ways of defining button images, but none seem to work consistently.
Here are the ways I have found (either in documentation or on SO):
In code (doesn't work at all for me [for toolbar buttons])
public PXAction<DAC> action;
[PXButton(CommitChanges = true, ImageKey = PX.Web.UI.Sprite.Main.ArrowRight)]
[PXUIField(DisplayName = "Action")]
protected virtual void Action()
In ASPX, in Base Properties > Images > Normal of the screen editor
Normal | main#ArrowRight
In ASPX, in Ext Properties > ImageKey and ImageSet of the screen editor
ImageKey | main
ImageSet | ArrowRight
The ASPX options work for the main ArrowRight icon, but there are various other icons in the same sprite that I would like to use that do NOT work. For instance, intellisense in VS suggests that Relation and RelationF are also in the main sprite, but these display as blank images.
What am I doing wrong, and how can I access something other than arrows?
The web font is contained in the fonts folder of the Acumatica web site on the web server. Install a local Acumatica web site if necessary.
Font folder example: C:\AcumaticaSites\YourWebsite\fonts
Open one of the fonts file. The file acumatica-font-v1.svg can be opened in a text editor.
You will notice Relation / RelationF are missing and main-ArrowRight is declared in the file:
<glyph unicode="" glyph-name="main-ArrowRight, ac-arrow_forward" d="M448 134.4l262.4 262.4h-582.4v96h582.4l-262.4 275.2 64 64 384-384-384-384-64 70.4z" />
Check the mapping between the constant and the Unicode icon in Content\font-awesome.css CSS file:
.main-ArrowRight:before {
content: "\e90a";
}
You can also open the true type font ttf from the fonts folder and install it to view the icons in a font viewer.

Xamarin.Forms font awesone using Label

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

cannot open my RTF file with my custom fonts

I made my own custom .ttf fonts for my UWP program and put them in Assets folder (vs 2017/2019). They are working well when the Document is processed in RichEditBox. However, when I Save the RTF file and then Open it, my custom fonts are ignored. If I install my custom fonts beforehand into Windows\Fonts folder , then Open file load the document with my custom fonts. Looks like without installing my custom fonts the program does not link them to the document.
Again - I wrote a program with RichEditBox and my custom fonts in that program. When processed - fonts changed, styles changed, etc - everything goes as designed. When I save RTF file with that program, and open that RTF with that (the same) program - color table is OK but my fonts are not shown though the fonts were compiled with that program (BuildAction - Content; CopyToOutputDirectory - Copy always). To simplify - I made button with the information the file contains. Though fonts are compiled (located in Assets folder), the program does not link them to the document.
Actually with that button I tried to reproduce what is described here: RichEditBox (UWP) ignores font and foreground when setting Rtf text However in my case, the RichEditBox shows only fonts installed in Windows\Fonts directory. How to overcome that and either use links to local fonts compiled with my program or make installer install the fonts to Windows\Fonts directory?
How could I use my custom fonts (link them to the document) without installing them or what I need to do my UWP program installs my custom fonts to user's device while installing itself?
This is code for button I used to display text:
private void Page_Click(object sender, RoutedEventArgs e)
{
string myRtfString = #"{\rtf1\fbidis\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil MyFont;}{\f1\fnil MyFont1;}{\f2\fnil MyFont2;}} {\colortbl ;\red0\green0\blue0;\red255\green255\blue255;\red255\green100\blue0;} {\*\generator Riched20 10.0.18362}\viewkind4\uc1 \pard\sl480\slmult1\qj\cf1\highlight2\f0\fs36 tt\highlight3\f1 g\f0 acgt\f2 c\highlight2\f0 tt\highlight0\par}";
editor.Document.SetText(TextSetOptions.FormatRtf, myRtfString);
}
This is XAML for RichEditBox:
<RichEditBox
x:Name="editor"
Height="200"
FontFamily="Assets/Fonts/MyFont.ttf#MyFont"
FontSize="24" RelativePanel.Below="openFileButton"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True" />
Gosha, this way you can apply at least one of the fonts to that .rtf file - see below. For others, I think, you need to use either map information from that .rtf or make an additional map of your own. That will be some "trabajo", but what can you do?
private void applyMyFonts()
{
string TextOut;
MyRichEditBox.Document.GetText(TextGetOptions.None, out TextOut);
MyRichEditBox.Document.Selection.SetRange(0, TextOut.Length);
MyRichEditBox.Document.Selection.CharacterFormat.Name = "Assets/Fonts/MyFont.ttf#MyFont";
}
private async void OpenButton_Click(object sender, RoutedEventArgs e)
{
Windows.Storage.Pickers.FileOpenPicker open =
new Windows.Storage.Pickers.FileOpenPicker();
open.SuggestedStartLocation =
Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
open.FileTypeFilter.Add(".rtf");
Windows.Storage.StorageFile file = await open.PickSingleFileAsync();
if (file != null)
{
try
{
Windows.Storage.Streams.IRandomAccessStream randAccStream =
await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
// Load the file into the Document property of the RichEditBox.
MyRichEditBox.Document.LoadFromStream(Windows.UI.Text.TextSetOptions.FormatRtf, randAccStream);
}
catch (Exception)
{
ContentDialog errorDialog = new ContentDialog()
{
Title = "File open error",
Content = "Sorry, I couldn't open the file.",
PrimaryButtonText = "Ok"
};
await errorDialog.ShowAsync();
}
}
applyMyfonts();
}

Using custom fonts without install win8.1 WPF APP

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.

How to use custom font asp.net application

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?

Categories