internal PdfTrueTypeFont(PdfDictionary fontDictionary) : base(fontDictionary) { newFont = false; CMapToUnicode toUni = FontUtil.ProcessToUnicode(fontDictionary.Get(PdfName.ToUnicode)); fontEncoding = DocFontEncoding.CreateDocFontEncoding(fontDictionary.Get(PdfName.Encoding), toUni); fontProgram = DocTrueTypeFont.CreateFontProgram(fontDictionary, fontEncoding, toUni); embedded = ((IDocFontProgram)fontProgram).GetFontFile() != null; subset = false; }
/// <summary>Creates a Type 3 font based on an existing font dictionary, which must be an indirect object.</summary> /// <param name="fontDictionary">a dictionary of type <code>/Font</code>, must have an indirect reference.</param> internal PdfType3Font(PdfDictionary fontDictionary) : base(fontDictionary) { subset = true; embedded = true; fontProgram = new Type3Font(false); CMapToUnicode toUni = FontUtil.ProcessToUnicode(fontDictionary.Get(PdfName.ToUnicode)); fontEncoding = DocFontEncoding.CreateDocFontEncoding(fontDictionary.Get(PdfName.Encoding), toUni); PdfDictionary charProcsDic = GetPdfObject().GetAsDictionary(PdfName.CharProcs); PdfArray fontMatrixArray = GetPdfObject().GetAsArray(PdfName.FontMatrix); if (GetPdfObject().ContainsKey(PdfName.FontBBox)) { PdfArray fontBBox = GetPdfObject().GetAsArray(PdfName.FontBBox); fontProgram.GetFontMetrics().SetBbox(fontBBox.GetAsNumber(0).IntValue(), fontBBox.GetAsNumber(1).IntValue( ), fontBBox.GetAsNumber(2).IntValue(), fontBBox.GetAsNumber(3).IntValue()); } else { fontProgram.GetFontMetrics().SetBbox(0, 0, 0, 0); } int firstChar = NormalizeFirstLastChar(fontDictionary.GetAsNumber(PdfName.FirstChar), 0); int lastChar = NormalizeFirstLastChar(fontDictionary.GetAsNumber(PdfName.LastChar), 255); for (int i = firstChar; i <= lastChar; i++) { shortTag[i] = 1; } int[] widths = FontUtil.ConvertSimpleWidthsArray(fontDictionary.GetAsArray(PdfName.Widths), firstChar, 0); double[] fontMatrix = new double[6]; for (int i = 0; i < fontMatrixArray.Size(); i++) { fontMatrix[i] = ((PdfNumber)fontMatrixArray.Get(i)).GetValue(); } SetFontMatrix(fontMatrix); foreach (PdfName glyphName in charProcsDic.KeySet()) { int unicode = AdobeGlyphList.NameToUnicode(glyphName.GetValue()); if (unicode != -1 && fontEncoding.CanEncode(unicode)) { int code = fontEncoding.ConvertToByte(unicode); ((Type3Font)GetFontProgram()).AddGlyph(code, unicode, widths[code], null, new Type3Glyph(charProcsDic.GetAsStream (glyphName), GetDocument())); } } FillFontDescriptor(fontDictionary.GetAsDictionary(PdfName.FontDescriptor)); }
internal PdfType1Font(PdfDictionary fontDictionary) : base(fontDictionary) { newFont = false; CMapToUnicode toUni = FontUtil.ProcessToUnicode(fontDictionary.Get(PdfName.ToUnicode)); // if there is no FontDescriptor, it is most likely one of the Standard Font with StandardEncoding as base encoding. // unused variable. // boolean fillStandardEncoding = !fontDictionary.containsKey(PdfName.FontDescriptor); fontEncoding = DocFontEncoding.CreateDocFontEncoding(fontDictionary.Get(PdfName.Encoding), toUni); fontProgram = DocType1Font.CreateFontProgram(fontDictionary, fontEncoding, toUni); if (fontProgram is IDocFontProgram) { embedded = ((IDocFontProgram)fontProgram).GetFontFile() != null; } subset = false; }
internal PdfType0Font(PdfDictionary fontDictionary) : base(fontDictionary) { CheckFontDictionary(fontDictionary, PdfName.Type0); newFont = false; PdfDictionary cidFont = fontDictionary.GetAsArray(PdfName.DescendantFonts).GetAsDictionary(0); String cmap = fontDictionary.GetAsName(PdfName.Encoding).GetValue(); if (PdfEncodings.IDENTITY_H.Equals(cmap) || PdfEncodings.IDENTITY_V.Equals(cmap)) { PdfObject toUnicode = fontDictionary.Get(PdfName.ToUnicode); CMapToUnicode toUnicodeCMap = FontUtil.ProcessToUnicode(toUnicode); if (toUnicodeCMap == null) { String uniMap = GetUniMapFromOrdering(GetOrdering(cidFont)); toUnicodeCMap = FontUtil.GetToUnicodeFromUniMap(uniMap); if (toUnicodeCMap == null) { toUnicodeCMap = FontUtil.GetToUnicodeFromUniMap(PdfEncodings.IDENTITY_H); ILogger logger = LoggerFactory.GetLogger(typeof(iText.Kernel.Font.PdfType0Font)); logger.Error(String.Format(LogMessageConstant.UNKNOWN_CMAP, uniMap)); } } fontProgram = DocTrueTypeFont.CreateFontProgram(cidFont, toUnicodeCMap); cmapEncoding = new CMapEncoding(cmap); System.Diagnostics.Debug.Assert(fontProgram is IDocFontProgram); embedded = ((IDocFontProgram)fontProgram).GetFontFile() != null; cidFontType = CID_FONT_TYPE_2; } else { String cidFontName = cidFont.GetAsName(PdfName.BaseFont).GetValue(); String uniMap = GetUniMapFromOrdering(GetOrdering(cidFont)); if (uniMap != null && uniMap.StartsWith("Uni") && CidFontProperties.IsCidFont(cidFontName, uniMap)) { try { fontProgram = FontProgramFactory.CreateFont(cidFontName); cmapEncoding = new CMapEncoding(cmap, uniMap); embedded = false; } catch (System.IO.IOException) { fontProgram = null; cmapEncoding = null; } } else { CMapToUnicode toUnicodeCMap = FontUtil.GetToUnicodeFromUniMap(uniMap); if (toUnicodeCMap != null) { fontProgram = DocTrueTypeFont.CreateFontProgram(cidFont, toUnicodeCMap); cmapEncoding = new CMapEncoding(cmap, uniMap); } } if (fontProgram == null) { throw new PdfException(String.Format("Cannot recognise document font {0} with {1} encoding", cidFontName, cmap)); } cidFontType = CID_FONT_TYPE_0; } longTag = new LinkedDictionary <int, int[]>(); subset = false; }
protected internal PdfSimpleFont(PdfDictionary fontDictionary) : base(fontDictionary) { toUnicode = FontUtil.ProcessToUnicode(fontDictionary.Get(PdfName.ToUnicode)); }
internal PdfType0Font(PdfDictionary fontDictionary) : base(fontDictionary) { newFont = false; PdfDictionary cidFont = fontDictionary.GetAsArray(PdfName.DescendantFonts).GetAsDictionary(0); PdfObject cmap = fontDictionary.Get(PdfName.Encoding); PdfObject toUnicode = fontDictionary.Get(PdfName.ToUnicode); CMapToUnicode toUnicodeCMap = FontUtil.ProcessToUnicode(toUnicode); if (cmap.IsName() && (PdfEncodings.IDENTITY_H.Equals(((PdfName)cmap).GetValue()) || PdfEncodings.IDENTITY_V .Equals(((PdfName)cmap).GetValue()))) { if (toUnicodeCMap == null) { String uniMap = GetUniMapFromOrdering(GetOrdering(cidFont)); toUnicodeCMap = FontUtil.GetToUnicodeFromUniMap(uniMap); if (toUnicodeCMap == null) { toUnicodeCMap = FontUtil.GetToUnicodeFromUniMap(PdfEncodings.IDENTITY_H); ILog logger = LogManager.GetLogger(typeof(iText.Kernel.Font.PdfType0Font)); logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.UNKNOWN_CMAP, uniMap)); } } fontProgram = DocTrueTypeFont.CreateFontProgram(cidFont, toUnicodeCMap); cmapEncoding = CreateCMap(cmap, null); System.Diagnostics.Debug.Assert(fontProgram is IDocFontProgram); embedded = ((IDocFontProgram)fontProgram).GetFontFile() != null; } else { String cidFontName = cidFont.GetAsName(PdfName.BaseFont).GetValue(); String uniMap = GetUniMapFromOrdering(GetOrdering(cidFont)); if (uniMap != null && uniMap.StartsWith("Uni") && CidFontProperties.IsCidFont(cidFontName, uniMap)) { try { fontProgram = FontProgramFactory.CreateFont(cidFontName); cmapEncoding = CreateCMap(cmap, uniMap); embedded = false; } catch (System.IO.IOException) { fontProgram = null; cmapEncoding = null; } } else { if (toUnicodeCMap == null) { toUnicodeCMap = FontUtil.GetToUnicodeFromUniMap(uniMap); } if (toUnicodeCMap != null) { fontProgram = DocTrueTypeFont.CreateFontProgram(cidFont, toUnicodeCMap); cmapEncoding = CreateCMap(cmap, uniMap); } } if (fontProgram == null) { throw new PdfException(MessageFormatUtil.Format(PdfException.CannotRecogniseDocumentFontWithEncoding, cidFontName , cmap)); } } // DescendantFonts is a one-element array specifying the CIDFont dictionary that is the descendant of this Type 0 font. PdfDictionary cidFontDictionary = fontDictionary.GetAsArray(PdfName.DescendantFonts).GetAsDictionary(0); // Required according to the spec PdfName subtype = cidFontDictionary.GetAsName(PdfName.Subtype); if (PdfName.CIDFontType0.Equals(subtype)) { cidFontType = CID_FONT_TYPE_0; } else { if (PdfName.CIDFontType2.Equals(subtype)) { cidFontType = CID_FONT_TYPE_2; } else { LogManager.GetLogger(GetType()).Error(iText.IO.LogMessageConstant.FAILED_TO_DETERMINE_CID_FONT_SUBTYPE); } } longTag = new SortedSet <int>(); subset = false; }