// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Data; using System.Reflection; using System.Windows.Media; // Reference: PresentationCore namespace Spludlow.Drawing { /// /// GlyphTypeface methods /// /// Used by PDF Font reports to get more font information /// public class GlyphTypefaceInfo { public string Filename; public string Name; public string Style; public string FamilyName; public string FaceName; public string Win32FamilyName; public string Win32FaceName; public string VersionString; //public string Copyright; //public string Description; public string DesignerName; //public string LicenseDescription; public string ManufacturerName; //public string Trademark; public string EmbeddingRights; public double Baseline; public double Height; public double CapsHeight; public string Weight; public int GlyphCount; public bool Unicode; public override string ToString() { StringBuilder text = new StringBuilder(); foreach (FieldInfo fieldInfo in this.GetType().GetFields()) { object value = fieldInfo.GetValue(this); text.Append(fieldInfo.Name); text.Append(": "); if (value != null) text.Append(Convert.ToString(value)); text.AppendLine(); } return text.ToString(); } public GlyphTypefaceInfo(string filename) { GlyphTypeface glyphTypeface = new GlyphTypeface(new Uri(filename)); System.Globalization.CultureInfo culture = null; foreach (System.Globalization.CultureInfo itemCulture in glyphTypeface.FamilyNames.Keys) { if (itemCulture.TwoLetterISOLanguageName == "en") { if (culture == null) culture = itemCulture; else throw new ApplicationException("GlyphTypefaceInfo; Culture multiple matches for 'en':" + filename); } } if (culture == null) throw new ApplicationException("GlyphTypefaceInfo; Culture not found 'en':" + filename); this.Filename = filename; this.FamilyName = glyphTypeface.FamilyNames[culture]; this.FaceName = glyphTypeface.FaceNames[culture]; this.Name = this.FamilyName; if (this.FaceName != "Regular" && this.Name.Contains(" " + this.FaceName) == false) this.Name += " " + this.FaceName; // Some fonts allow Regular on end, other don't ! this.Style = glyphTypeface.Style.ToString(); this.Win32FamilyName = glyphTypeface.Win32FamilyNames[culture]; this.Win32FaceName = glyphTypeface.Win32FaceNames[culture]; this.VersionString = glyphTypeface.VersionStrings[culture]; //this.Copyright = glyphTypeface.Copyrights[culture]; //this.Description = glyphTypeface.Descriptions[culture]; this.DesignerName = glyphTypeface.DesignerNames[culture]; //this.LicenseDescription = glyphTypeface.LicenseDescriptions[culture]; this.ManufacturerName = glyphTypeface.ManufacturerNames[culture]; //this.Trademark = glyphTypeface.Trademarks[culture]; this.EmbeddingRights = glyphTypeface.EmbeddingRights.ToString(); this.Baseline = glyphTypeface.Baseline; this.Height = glyphTypeface.Height; this.CapsHeight = glyphTypeface.CapsHeight; this.Weight = glyphTypeface.Weight.ToString(); this.GlyphCount = glyphTypeface.GlyphCount; this.Unicode = glyphTypeface.Symbol; } public static DataTable Report() { return Report(@"C:\Windows\Fonts"); } public static DataTable Report(string directory) { List filenames = new List(); List subDirectories = new List(); foreach (string filename in Directory.GetFiles(directory, "*", SearchOption.AllDirectories)) { string extention = Path.GetExtension(filename).ToLower(); if (extention != ".ttf" && extention != ".otf") continue; filenames.Add(filename); string dir = Path.GetDirectoryName(filename); if (subDirectories.Contains(dir) == false) subDirectories.Add(dir); } foreach (string dir in subDirectories) Spludlow.Drawing.PDFFontChest.RegisterDirectory(dir); return GlyphTypefaceInfo.Report(filenames.ToArray()); } public static DataTable Report(string[] filenames) { DataTable table = null; using (System.Drawing.Text.PrivateFontCollection privateFontCollection = new System.Drawing.Text.PrivateFontCollection()) { foreach (string filename in filenames) { GlyphTypefaceInfo info = new GlyphTypefaceInfo(filename); if (table == null) { table = new DataTable(); table.Columns.Add("FontSystem", typeof(string)); table.Columns.Add("FontPDF", typeof(string)); foreach (FieldInfo fieldInfo in info.GetType().GetFields()) { table.Columns.Add(fieldInfo.Name, fieldInfo.FieldType); } } DataRow row = table.NewRow(); foreach (FieldInfo fieldInfo in info.GetType().GetFields()) { row[fieldInfo.Name] = fieldInfo.GetValue(info); } table.Rows.Add(row); privateFontCollection.AddFontFile(filename); } foreach (DataRow row in table.Rows) { string name = (string)row["Name"]; string fontPDF = ""; try { Spludlow.Drawing.PDFFontChest.GetFont(name + ", 24"); } catch (Exception ee) { fontPDF = ee.Message; } row["FontPDF"] = fontPDF; string fontSystem = ""; try { Spludlow.Drawing.ArtChest.Font(name + ", 24"); } catch (Exception ee) { fontSystem = ee.Message; } row["FontSystem"] = fontSystem; } } Spludlow.Log.Report("GlyphTypefaceInfo Report", table); return table; } } }