How to get any suitable font in ImageSharp? - c#

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.

Related

Syncfusion : Using a Google Font for the page number in html to pdf

I'm using Syncfusion's HTML to PDF which is working great!
Little hiccup though, all their documentation shows if you want to change the font of the page numbers at the bottom you have two choices:
standard font:
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f)
custom font:
PdfFont font = new PdfTrueTypeFont(Server.MapPath("/App_Data/ARIALUNI.ttf"), 24)
But I need to allow a font from google fonts. I have the font loaded in my html but the page numbers are painted after so I'm not sure how to 1. embed it & 2. set it.
Appreciate any help.
Many thanks
For anyone that comes across this rare ask, it's not supported. You need to load and store the TrueType font and then set it to the file location as above.

How to apply custom font icon shapes in UWP

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.

Get a font and font size from text?

I want to make an application for auto finding font.
Therefore, I try to get a font and font size from PDF text with Acrobat SDK.
I examined samples and documents, but I could not find it.
CAcroPDDoc pdDoc = new AcroPDDocClass();
pdDoc.Open(filename);
Object jsObj = pdDoc.GetJSObject();
Type T = jsObj.GetType();
// no idea for getting font and font size...
My tools : Visual Studio, C#, Acrobat DC, Acrobat DC SDK
For example PDF text, font and font size on Acrobat DC
Best regards
Acrobat JavaScript and, therefore, the JSO doesn't have access to the properties of text in the page content. The best you're going to be able to do is infer the size from the bounding box height but that won't be accurate since the bbox includes the leading. You can't get the font name at all.
You can get that information if you create a plugin but that would require C++ which you don't have listed as an option in your question.

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.

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