private ICollection <String> ExtractFullFontNames(FontNames fontNames) { ICollection <String> uniqueFullNames = new HashSet <String>(); foreach (String[] fullName in fontNames.GetFullName()) { uniqueFullNames.Add(fullName[3].ToLowerInvariant()); } return(uniqueFullNames); }
internal CidFont(String fontName, ICollection <String> cmaps) { compatibleCmaps = cmaps; fontNames = new FontNames(); InitializeCidFontNameAndStyle(fontName); IDictionary <String, Object> fontDesc = CidFontProperties.GetAllFonts().Get(fontNames.GetFontName()); if (fontDesc == null) { throw new iText.IO.IOException("There is no such predefined font: {0}").SetMessageParams(fontName); } InitializeCidFontProperties(fontDesc); }
internal FontProgramDescriptor(FontNames fontNames, float italicAngle, bool isMonospace) { this.fontName = fontNames.GetFontName(); this.fontNameLowerCase = this.fontName.ToLowerInvariant(); this.fullNameLowerCase = fontNames.GetFullName()[0][3].ToLowerInvariant(); this.familyNameLowerCase = fontNames.GetFamilyName() != null && fontNames.GetFamilyName()[0][3] != null? fontNames.GetFamilyName()[0][3].ToLowerInvariant() : null; this.style = fontNames.GetStyle(); this.weight = fontNames.GetFontWeight(); this.macStyle = fontNames.GetMacStyle(); this.italicAngle = italicAngle; this.isMonospace = isMonospace; }
private String ExtractFamilyNameEnglishOpenType(FontNames fontNames) { if (fontNames.GetFamilyName() != null) { for (int k = 0; k < TT_FAMILY_ORDER.Length; k += 3) { foreach (String[] name in fontNames.GetFamilyName()) { if (TT_FAMILY_ORDER[k].Equals(name[0]) && TT_FAMILY_ORDER[k + 1].Equals(name[1]) && TT_FAMILY_ORDER[k + 2] .Equals(name[2])) { return(name[3].ToLowerInvariant()); } } } } return(null); }
public virtual FontNames GetFontNames() { FontNames fontNames = new FontNames(); fontNames.SetAllNames(GetAllNameEntries()); fontNames.SetFontName(GetPsFontName()); fontNames.SetFullName(fontNames.GetNames(4)); String[][] otfFamilyName = fontNames.GetNames(16); if (otfFamilyName != null) { fontNames.SetFamilyName(otfFamilyName); } else { fontNames.SetFamilyName(fontNames.GetNames(1)); } String[][] subfamily = fontNames.GetNames(2); if (subfamily != null) { fontNames.SetStyle(subfamily[0][3]); } String[][] otfSubFamily = fontNames.GetNames(17); if (otfFamilyName != null) { fontNames.SetSubfamily(otfSubFamily); } else { fontNames.SetSubfamily(subfamily); } String[][] cidName = fontNames.GetNames(20); if (cidName != null) { fontNames.SetCidFontName(cidName[0][3]); } fontNames.SetFontWeight(os_2.usWeightClass); fontNames.SetFontStretch(FontStretches.FromOpenTypeWidthClass(os_2.usWidthClass)); fontNames.SetMacStyle(head.macStyle); fontNames.SetAllowEmbedding(os_2.fsType != 2); return(fontNames); }
internal FontProgramDescriptor(FontNames fontNames, float italicAngle, bool isMonospace) { // Initially needed for open type fonts only. // The following sequence represents four triplets. // In each triplet items sequentially stand for platformID encodingID languageID (see open type naming table spec). // Each triplet is used further to determine whether the font name item is represented in English this.fontName = fontNames.GetFontName(); this.fontNameLowerCase = this.fontName.ToLowerInvariant(); this.fullNameLowerCase = fontNames.GetFullName()[0][3].ToLowerInvariant(); this.familyNameLowerCase = fontNames.GetFamilyName() != null && fontNames.GetFamilyName()[0][3] != null? fontNames.GetFamilyName()[0][3].ToLowerInvariant() : null; this.style = fontNames.GetStyle(); this.weight = fontNames.GetFontWeight(); this.macStyle = fontNames.GetMacStyle(); this.italicAngle = italicAngle; this.isMonospace = isMonospace; this.familyNameEnglishOpenType = ExtractFamilyNameEnglishOpenType(fontNames); this.fullNamesAllLangs = ExtractFullFontNames(fontNames); this.fullNamesEnglishOpenType = ExtractFullNamesEnglishOpenType(fontNames); }
private ICollection <String> ExtractFullNamesEnglishOpenType(FontNames fontNames) { if (familyNameEnglishOpenType != null) { ICollection <String> uniqueTtfSuitableFullNames = new HashSet <String>(); String[][] names = fontNames.GetFullName(); foreach (String[] name in names) { for (int k = 0; k < TT_FAMILY_ORDER.Length; k += 3) { if (TT_FAMILY_ORDER[k].Equals(name[0]) && TT_FAMILY_ORDER[k + 1].Equals(name[1]) && TT_FAMILY_ORDER[k + 2] .Equals(name[2])) { uniqueTtfSuitableFullNames.Add(name[3]); break; } } } return(uniqueTtfSuitableFullNames); } return(new HashSet <String>()); }
protected internal TrueTypeFont() { fontNames = new FontNames(); }
protected internal Type1Font() { fontNames = new FontNames(); }
internal FontProgramDescriptor(FontNames fontNames, FontMetrics fontMetrics) : this(fontNames, fontMetrics.GetItalicAngle(), fontMetrics.IsFixedPitch()) { }
/// <exception cref="System.IO.IOException"/> protected internal virtual void Process() { RandomAccessFileOrArray raf = fontParser.GetMetricsFile(); String line; bool startKernPairs = false; while (!startKernPairs && (line = raf.ReadLine()) != null) { StringTokenizer tok = new StringTokenizer(line, " ,\n\r\t\f"); if (!tok.HasMoreTokens()) { continue; } String ident = tok.NextToken(); switch (ident) { case "FontName": { fontNames.SetFontName(tok.NextToken("\u00ff").Substring(1)); break; } case "FullName": { String fullName = tok.NextToken("\u00ff").Substring(1); fontNames.SetFullName(new String[][] { new String[] { "", "", "", fullName } }); break; } case "FamilyName": { String familyName = tok.NextToken("\u00ff").Substring(1); fontNames.SetFamilyName(new String[][] { new String[] { "", "", "", familyName } }); break; } case "Weight": { fontNames.SetWeight(FontNames.ConvertFontWeight(tok.NextToken("\u00ff").Substring(1))); break; } case "ItalicAngle": { fontMetrics.SetItalicAngle(float.Parse(tok.NextToken(), System.Globalization.CultureInfo.InvariantCulture) ); break; } case "IsFixedPitch": { fontMetrics.SetIsFixedPitch(tok.NextToken().Equals("true")); break; } case "CharacterSet": { characterSet = tok.NextToken("\u00ff").Substring(1); break; } case "FontBBox": { int llx = (int)float.Parse(tok.NextToken(), System.Globalization.CultureInfo.InvariantCulture); int lly = (int)float.Parse(tok.NextToken(), System.Globalization.CultureInfo.InvariantCulture); int urx = (int)float.Parse(tok.NextToken(), System.Globalization.CultureInfo.InvariantCulture); int ury = (int)float.Parse(tok.NextToken(), System.Globalization.CultureInfo.InvariantCulture); fontMetrics.SetBbox(llx, lly, urx, ury); break; } case "UnderlinePosition": { fontMetrics.SetUnderlinePosition((int)float.Parse(tok.NextToken(), System.Globalization.CultureInfo.InvariantCulture )); break; } case "UnderlineThickness": { fontMetrics.SetUnderlineThickness((int)float.Parse(tok.NextToken(), System.Globalization.CultureInfo.InvariantCulture )); break; } case "EncodingScheme": { encodingScheme = tok.NextToken("\u00ff").Substring(1).Trim(); break; } case "CapHeight": { fontMetrics.SetCapHeight((int)float.Parse(tok.NextToken(), System.Globalization.CultureInfo.InvariantCulture )); break; } case "XHeight": { fontMetrics.SetXHeight((int)float.Parse(tok.NextToken(), System.Globalization.CultureInfo.InvariantCulture )); break; } case "Ascender": { fontMetrics.SetTypoAscender((int)float.Parse(tok.NextToken(), System.Globalization.CultureInfo.InvariantCulture )); break; } case "Descender": { fontMetrics.SetTypoDescender((int)float.Parse(tok.NextToken(), System.Globalization.CultureInfo.InvariantCulture )); break; } case "StdHW": { fontMetrics.SetStemH((int)float.Parse(tok.NextToken(), System.Globalization.CultureInfo.InvariantCulture)); break; } case "StdVW": { fontMetrics.SetStemV((int)float.Parse(tok.NextToken(), System.Globalization.CultureInfo.InvariantCulture)); break; } case "StartCharMetrics": { startKernPairs = true; break; } } } if (!startKernPairs) { String metricsPath = fontParser.GetAfmPath(); if (metricsPath != null) { throw new iText.IO.IOException("missing.startcharmetrics.in.1").SetMessageParams(metricsPath); } else { throw new iText.IO.IOException("missing.startcharmetrics.in.the.metrics.file"); } } avgWidth = 0; int widthCount = 0; while ((line = raf.ReadLine()) != null) { StringTokenizer tok = new StringTokenizer(line); if (!tok.HasMoreTokens()) { continue; } String ident = tok.NextToken(); if (ident.Equals("EndCharMetrics")) { startKernPairs = false; break; } int C = -1; int WX = 250; String N = ""; int[] B = null; tok = new StringTokenizer(line, ";"); while (tok.HasMoreTokens()) { StringTokenizer tokc = new StringTokenizer(tok.NextToken()); if (!tokc.HasMoreTokens()) { continue; } ident = tokc.NextToken(); switch (ident) { case "C": { C = System.Convert.ToInt32(tokc.NextToken()); break; } case "WX": { WX = (int)float.Parse(tokc.NextToken(), System.Globalization.CultureInfo.InvariantCulture); break; } case "N": { N = tokc.NextToken(); break; } case "B": { B = new int[] { System.Convert.ToInt32(tokc.NextToken()), System.Convert.ToInt32(tokc.NextToken()), System.Convert.ToInt32 (tokc.NextToken()), System.Convert.ToInt32(tokc.NextToken()) }; break; } } } int unicode = (int)AdobeGlyphList.NameToUnicode(N); Glyph glyph = new Glyph(C, WX, unicode, B); if (C >= 0) { codeToGlyph[C] = glyph; } if (unicode != -1) { unicodeToGlyph[unicode] = glyph; } avgWidth += WX; widthCount++; } if (widthCount != 0) { avgWidth /= widthCount; } if (startKernPairs) { String metricsPath = fontParser.GetAfmPath(); if (metricsPath != null) { throw new iText.IO.IOException("missing.endcharmetrics.in.1").SetMessageParams(metricsPath); } else { throw new iText.IO.IOException("missing.endcharmetrics.in.the.metrics.file"); } } // From AdobeGlyphList: // nonbreakingspace;00A0 // space;0020 if (!unicodeToGlyph.ContainsKey(0x00A0)) { Glyph space = null; if (unicodeToGlyph.ContainsKey(0x0020)) { space = unicodeToGlyph.Get(0x0020); } if (space != null) { unicodeToGlyph[0x00A0] = new Glyph(space.GetCode(), space.GetWidth(), 0x00A0, space.GetBbox()); } } bool endOfMetrics = false; while ((line = raf.ReadLine()) != null) { StringTokenizer tok = new StringTokenizer(line); if (!tok.HasMoreTokens()) { continue; } String ident = tok.NextToken(); if (ident.Equals("EndFontMetrics")) { endOfMetrics = true; break; } else { if (ident.Equals("StartKernPairs")) { startKernPairs = true; break; } } } if (startKernPairs) { while ((line = raf.ReadLine()) != null) { StringTokenizer tok = new StringTokenizer(line); if (!tok.HasMoreTokens()) { continue; } String ident = tok.NextToken(); if (ident.Equals("KPX")) { String first = tok.NextToken(); String second = tok.NextToken(); int? width = (int)float.Parse(tok.NextToken(), System.Globalization.CultureInfo.InvariantCulture); int firstUni = (int)AdobeGlyphList.NameToUnicode(first); int secondUni = (int)AdobeGlyphList.NameToUnicode(second); if (firstUni != -1 && secondUni != -1) { long record = ((long)firstUni << 32) + secondUni; kernPairs[record] = width; } } else { if (ident.Equals("EndKernPairs")) { startKernPairs = false; break; } } } } else { if (!endOfMetrics) { String metricsPath = fontParser.GetAfmPath(); if (metricsPath != null) { throw new iText.IO.IOException("missing.endfontmetrics.in.1").SetMessageParams(metricsPath); } else { throw new iText.IO.IOException("missing.endfontmetrics.in.the.metrics.file"); } } } if (startKernPairs) { String metricsPath = fontParser.GetAfmPath(); if (metricsPath != null) { throw new iText.IO.IOException("missing.endkernpairs.in.1").SetMessageParams(metricsPath); } else { throw new iText.IO.IOException("missing.endkernpairs.in.the.metrics.file"); } } raf.Close(); isFontSpecific = !(encodingScheme.Equals("AdobeStandardEncoding") || encodingScheme.Equals("StandardEncoding" )); }