/// <summary>Register a font file and use an alias for the font contained in it.</summary> /// <param name="path">the path to a font file</param> /// <param name="alias">the alias you want to use for the font</param> internal virtual void RegisterFont(String path, String alias) { try { if (path.ToLowerInvariant().EndsWith(".ttf") || path.ToLowerInvariant().EndsWith(".otf") || path.ToLowerInvariant ().IndexOf(".ttc,", StringComparison.Ordinal) > 0) { FontProgramDescriptor descriptor = FontProgramDescriptorFactory.FetchDescriptor(path); fontNames.Put(descriptor.GetFontNameLowerCase(), path); if (alias != null) { String lcAlias = alias.ToLowerInvariant(); fontNames.Put(lcAlias, path); if (lcAlias.EndsWith("regular")) { //do this job to give higher priority to regular fonts in comparison with light, narrow, etc SaveCopyOfRegularFont(lcAlias, path); } } // register all the font names with all the locales foreach (String name in descriptor.GetFullNameAllLangs()) { fontNames.Put(name, path); if (name.EndsWith("regular")) { //do this job to give higher priority to regular fonts in comparison with light, narrow, etc SaveCopyOfRegularFont(name, path); } } if (descriptor.GetFamilyNameEnglishOpenType() != null) { foreach (String fullName in descriptor.GetFullNamesEnglishOpenType()) { RegisterFontFamily(descriptor.GetFamilyNameEnglishOpenType(), fullName, null); } } } else { if (path.ToLowerInvariant().EndsWith(".ttc")) { TrueTypeCollection ttc = new TrueTypeCollection(path); for (int i = 0; i < ttc.GetTTCSize(); i++) { String fullPath = path + "," + i; if (alias != null) { RegisterFont(fullPath, alias + "," + i); } else { RegisterFont(fullPath); } } } else { if (path.ToLowerInvariant().EndsWith(".afm") || path.ToLowerInvariant().EndsWith(".pfm")) { FontProgramDescriptor descriptor = FontProgramDescriptorFactory.FetchDescriptor(path); RegisterFontFamily(descriptor.GetFamilyNameLowerCase(), descriptor.GetFullNameLowerCase(), null); fontNames.Put(descriptor.GetFontNameLowerCase(), path); fontNames.Put(descriptor.GetFullNameLowerCase(), path); } } } LOGGER.Trace(MessageFormatUtil.Format("Registered {0}", path)); } catch (System.IO.IOException e) { throw new iText.IO.IOException(e); } }