private void button3_Click(object sender, EventArgs e) { string filename = "Test/Sarabun-Regular.woff2"; using (FileStream fs = new FileStream(filename, FileMode.Open)) { OpenFontReader openFontReader = new OpenFontReader(); PreviewFontInfo previewFontInfo = openFontReader.ReadPreview(fs); } }
public bool AddFont(FontStreamSource src) { //preview data of font using (Stream stream = src.ReadFontStream()) { var reader = new OpenFontReader(); PreviewFontInfo previewFont = reader.ReadPreview(stream); if (previewFont == null || string.IsNullOrEmpty(previewFont.Name)) { //err! return(false); } //*** if (previewFont.IsFontCollection) { int mbCount = previewFont.MemberCount; bool passAll = true; for (int i = 0; i < mbCount; ++i) { PreviewFontInfo member = previewFont.GetMember(i); if (!RegisterFont(new InstalledFont( member.Name, member.SubFamilyName, member.TypographicFamilyName, member.TypographicSubFamilyName, src.PathName, member.Weight) { StreamOffset = member.ActualStreamOffset })) { passAll = false; } } return(passAll); } else { return(RegisterFont(new InstalledFont( previewFont.Name, previewFont.SubFamilyName, previewFont.TypographicFamilyName, previewFont.TypographicSubFamilyName, src.PathName, previewFont.Weight))); } } }
public bool AddFont(FontStreamSource src) { //preview data of font using (Stream stream = src.ReadFontStream()) { var reader = new OpenFontReader(); PreviewFontInfo previewFont = reader.ReadPreview(stream); if (string.IsNullOrEmpty(previewFont.fontName)) { //err! return(false); } return(RegisterFont(new InstalledFont(previewFont.fontName, previewFont.fontSubFamily, src.PathName))); } }
public bool AddFontStreamSource(IFontStreamSource src) { //preview data of font try { using (Stream stream = src.ReadFontStream()) { var reader = new OpenFontReader(); PreviewFontInfo previewFont = reader.ReadPreview(stream); if (previewFont == null || string.IsNullOrEmpty(previewFont.Name)) { //err! return(false); } if (previewFont.IsFontCollection) { int mbCount = previewFont.MemberCount; bool totalResult = true; for (int i = 0; i < mbCount; ++i) { //extract and each members if (!AddFontPreview(previewFont.GetMember(i), src.PathName)) { totalResult = false; } } return(totalResult); } else { return(AddFontPreview(previewFont, src.PathName)); } } } catch (IOException) { //TODO review here again return(false); } }
public bool AddFontStreamSource(IFontStreamSource src) { //preview data of font try { using (Stream stream = src.ReadFontStream()) { var reader = new OpenFontReader(); PreviewFontInfo previewFont = reader.ReadPreview(stream); if (string.IsNullOrEmpty(previewFont.fontName)) { //err! return(false); } //if (previewFont.fontName.StartsWith("Bungee")) //{ //} TypefaceStyle typefaceStyle = TypefaceStyle.Regular; switch (previewFont.OS2TranslatedStyle) { case OpenFont.Extensions.TranslatedOS2FontStyle.BOLD: typefaceStyle = TypefaceStyle.Bold; break; case OpenFont.Extensions.TranslatedOS2FontStyle.ITALIC: case OpenFont.Extensions.TranslatedOS2FontStyle.OBLIQUE: typefaceStyle = TypefaceStyle.Italic; break; case OpenFont.Extensions.TranslatedOS2FontStyle.REGULAR: typefaceStyle = TypefaceStyle.Regular; break; case (OpenFont.Extensions.TranslatedOS2FontStyle.BOLD | OpenFont.Extensions.TranslatedOS2FontStyle.ITALIC): typefaceStyle = TypefaceStyle.Bold | TypefaceStyle.Italic; break; } //--------------- //some font subfam="Bold Italic" but OS2TranslatedStyle is only Italic //so we should check the subfam name too! string[] fontSubFamUpperCaseName_split = previewFont.fontSubFamily.ToUpper().Split(' '); if (fontSubFamUpperCaseName_split.Length > 1) { if (typefaceStyle != (TypefaceStyle.Bold | TypefaceStyle.Italic)) { //translate more if ((fontSubFamUpperCaseName_split[0] == "BOLD" && fontSubFamUpperCaseName_split[1] == "ITALIC") || (fontSubFamUpperCaseName_split[0] == "ITALIC" && fontSubFamUpperCaseName_split[1] == "BOLD")) { typefaceStyle = TypefaceStyle.Bold | TypefaceStyle.Italic; } } } else { //=1 switch (fontSubFamUpperCaseName_split[0]) { case "BOLD": typefaceStyle = TypefaceStyle.Bold; break; case "ITALIC": typefaceStyle = TypefaceStyle.Italic; break; } } return(Register(new InstalledTypeface(previewFont.fontName, previewFont.fontSubFamily, src.PathName, typefaceStyle))); } } catch (IOException) { //TODO review here again return(false); } }