I want to get all supported characters of a font, that font is stored in localhost:53625/fonts/WINGDNG2.TTF. I has try this thread in Stackoverflow
Get supported characters of a font - in C#
but have no luck.
When
Fonts.GetFontFamilies(#"C:\WINDOWS\Fonts\Arial.TTF");
return a list contain 1 family,
Fonts.GetFontFamilies(new
Uri(http://localhost:53625/fonts/WINGDNG2.TTF));
return a list contain 0 family.
Thank you for reading my question.
p/s: My project is a website using ASP.NET MVC5, so the function can be in C# (server side) or in Javascript (client site). If there are any codes can give me a list of supported characters of a font (with specific path like above), which side is no problem.
Instead of enumerating the Font Families, you can instantiate GlyphTypeface directly, if you know the font file location:
GlyphTypeface glyphTypeface = new GlyphTypeface(new Uri("file:///C:\\WINDOWS\\Fonts\\Kooten.ttf"));
Then access the GlyphCharacterMap to get all the supported characters:
IDictionary<int, ushort> characterMap = glyph.CharacterToGlyphMap;
https://msdn.microsoft.com/en-us/library/system.windows.media.glyphtypeface(v=vs.110).aspx
Related
I am fairly new to programming and I just wrote a simple application in C# .NET to retrieve information about system drive space. The program functions fine but I'm struggling with formatting the output.
See output:
I'm trying to use padding to get the text to line up in sort of a column format within a rich text box but the output doesn't line up because if there are multiple drives, the drive names are different lengths which throws off the padding. Even if the drive letter comes back one as M: and the other as I: the difference in the size of the letter is enough to throw off the alignment while padding.
I am wondering if there is a way to force each string value to a specific length so the padding is applied evenly or if maybe there's an even better way to format my output. Thank you in advance for your time and let me know if any further information would be helpful!
Note: One of the comments asked an important question, regarding whether the question refers to the System.Windows.Forms.RichTextBox (WinForms) or the System.Windows.Controls.RichTextBox (WPF) control. This answer applies only to the WinForms version of RichTextBox, so if you're using WPF, this doesn't apply.
The most important thing, and this was mentioned in the comments, is that you'll need to use a Monospaced font.
Since you stated you're using a RichTextBox, you'll need to know how to set it to use whatever monospaced font you've chosen.
To do that, you can use the RichTextBox.SelectionFont property.
For more general instructions, refer to this MSDN article: Setting Font Attributes for the Windows Forms RichTextBox Control
Once you set the RichTextBox.SelectionFont property, only text added to the control afterwards will use the specified font. To apply the font to existing text (i.e. you populate the RichTextBox and then change the font to an appropriate monospaced font), take a look at this answer, which tells you precisely what to do.
Once that's done, there remains the simple matter of adding the appropriate amount of whitespace to the end of each string, such that the next piece of data appears at the appropriate position. You'll probably be using String.PadRight, but for more general information about padding strings, check out this MSDN article: Padding Strings in the .NET Framework
Here is string formatting example:
string varOne = "Line One";
double varTwo = 15/100;
string output= String.Format("{0,-10} {1,5:P1}", varOne, varTwo);
//expected output is
//Line One 15 %
where formatting properties in curly brackets are:
{index[,alignment][ :formatString] }
I am trying to fill drop down box with font family names and I have a lot of fonts almost 600 and I want to reduce this number based on the user interface for example when the interface is LTR (western) English or french for example I would need to load just the fonts that support those scripts nothing more
right now I am doing this:
InstalledFontCollection c = new InstalledFontCollection();
FontFamily[] fontF = c.Families;
return fontF.Select(i => i.GetName(0)).ToArray();
when trying to change the language identifier in GetName method with other value I end up with the same amount of result
I have the values from Winnt.h header file which can be found here
I am using asp.net C# 4.5
what I am looking for is native C# solution without using P/Invoke or at least that would be my last fallback solution
Why the following code does not throw an exception?
FontFamily font = new FontFamily("bla bla bla");
I need to know if a specific font (as combination of FontFamily, FontStyle, FontWeight, ...) exists in my current OS. How have I to do?
This is by design. Programs frequently ask for fonts that are not present on the machine, especially in a country far flung from the programmer's domicile. The font mapper produces an alternative. Font substitution is in general very common. You are looking at Arial right now if you are on a Windows machine. But I can paste 你好世界 into this post and you'll see it render accurately, even though Arial doesn't have glyphs for Chinese characters.
So hint number one is to not actually worry about what fonts are available. The Windows api has EnumFontFamiliesEx() to enumerate available font families. But that's not exposed in WPF, some friction with OpenType there, a font standard that's rather poorly integrated with Windows. Another shadow cast when Adobe gets involved with anything Microsoft does, it seems.
Some confusion in the comments about Winforms' FontFamily class. Which is actually usable in this case, its GetFamilies() method returns an array of available families. But only TrueType, not OpenType fonts.
You can use the class System.Drawing.Text.InstalledFontCollection
http://msdn.microsoft.com/en-us/library/system.drawing.text.installedfontcollection.aspx
WPF have a framework specific method Fonts.SystemFontFamilies
http://msdn.microsoft.com/en-us/library/system.windows.media.fonts.systemfontfamilies.aspx
To answer the question of why it isn't throwing an exception, according to FontFamily Constructor on MSDN the exception wasn't added until framework version 3.5.
I suspect that you are targeting version 3.0 or below.
Cheers!
You can browse the available fonts on the System using the Fonts.SystemFontFamilies collection - use some Linq to match on whatever conditions you need;
// true
bool exists = (from f in Fonts.SystemFontFamilies where f.Source.Equals("Arial") select f).Any();
// false
exists = (from f in Fonts.SystemFontFamilies where f.Source.Equals("blahblah") select f).Any();
Currently I'm finishing my very first iPhone application with MonoTouch. Localization through the "*.lproj" folders works as expected.
Having an UIWebView that displays some user guidelines, I'm populating this one with the LoadHtmlString() method. (I.e. no internet connection is required).
Since the text is a bit longer, I do not want it to be placed inside the "Localizable.strings" file but being swapped out to a completely separate file (as I'm doing it for Windows .NET applications, too):
In the above screenshot, I would have one "help.html" file inside each language folder and call the LoadHtmlString method to read from the appropriate file in a way that would be similar to NSBundle.MainBundle.LocalizedString.
My question:
Is it possible to have per-language files and access them from within a MonoTouch application?
Follow-up to Dimitris' solution
Based on Dimitris' solution, I solved it by this code:
var localizedHtmlFile = NSBundle.MainBundle.PathForResource("help", "html");
var text = File.ReadAllText(localizedHtmlFile);
helpTextView.LoadHtmlString (text, null);
Yes, of course it is possible. You can get the path of the localized file like this:
string localizedHtmlFile = NSBundle.MainBundle.PathForResource("help", "html");
You can use the PathForResource method for various different types of resources (PDFs, images, etc.). The first parameter is the file name and the second one is its extension. Check the other overload of the PathForResource method for more options.
I'm working with ITextSharp for a project and am looking for a reasonable way to get a string list of different fonts it has available for use.
I thought maybe I could just use reflection and loop over a class of available fonts, but there does not seem to be an easy way to do this. What I really want to do is provide a drop down of available/supported fonts for my users to select from Does anyone have any thoughts on how I might accomplish this?
This webpage has a great reference for how to work with the 14 embedded fonts in iTextSharp, as well as how to embed and use any fonts of your choosing.
To get the list of fonts included in iTextSharp:
Dim myCol As ICollection
//Returns the list of all font families included in iTextSharp.
myCol = iTextSharp.text.FontFactory.RegisteredFamilies
//Returns the list of all fonts included in iTextSharp.
myCol = iTextSharp.text.FontFactory.RegisteredFonts
An example of a font family is Helvetica. An example of a font is Helvetica-Bold or Helvetica-Italic.
First call FontFactory.RegisterDirectories(); to get all fonts on the system registered.
Then call FontFactory.RegisteredFonts; to get all the fonts.