From a7df15bacdaa3f4ae09613c349215be5294c6f67 Mon Sep 17 00:00:00 2001 From: psoares33 Date: Mon, 6 Jul 2009 21:19:56 +0000 Subject: [PATCH] Fix NPE when parsing Type 0 fonts without a ToUnicode map (I've seen some winding font entries stored as Type 0 instead of TT in some pdf files) git-svn-id: svn://svn.code.sf.net/p/itextsharp/code/trunk@48 820d3149-562b-4f88-9aa4-a8e61a3485cf --- src/core/iTextSharp/text/pdf/DocumentFont.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/iTextSharp/text/pdf/DocumentFont.cs b/src/core/iTextSharp/text/pdf/DocumentFont.cs index 1d898e9..fb63f93 100644 --- a/src/core/iTextSharp/text/pdf/DocumentFont.cs +++ b/src/core/iTextSharp/text/pdf/DocumentFont.cs @@ -136,7 +136,7 @@ namespace iTextSharp.text.pdf { } private void ProcessType0(PdfDictionary font) { - byte[] touni = PdfReader.GetStreamBytes((PRStream)PdfReader.GetPdfObjectRelease(font.Get(PdfName.TOUNICODE))); + PdfObject toUniObject = PdfReader.GetPdfObjectRelease(font.Get(PdfName.TOUNICODE)); PdfArray df = (PdfArray)PdfReader.GetPdfObjectRelease(font.Get(PdfName.DESCENDANTFONTS)); PdfDictionary cidft = (PdfDictionary)PdfReader.GetPdfObjectRelease(df[0]); PdfNumber dwo = (PdfNumber)PdfReader.GetPdfObjectRelease(cidft.Get(PdfName.DW)); @@ -146,7 +146,9 @@ namespace iTextSharp.text.pdf { IntHashtable widths = ReadWidths((PdfArray)PdfReader.GetPdfObjectRelease(cidft.Get(PdfName.W))); PdfDictionary fontDesc = (PdfDictionary)PdfReader.GetPdfObjectRelease(cidft.Get(PdfName.FONTDESCRIPTOR)); FillFontDesc(fontDesc); - FillMetrics(touni, widths, dw); + if (toUniObject != null){ + FillMetrics(PdfReader.GetStreamBytes((PRStream)toUniObject), widths, dw); + } } private IntHashtable ReadWidths(PdfArray ws) { @@ -638,5 +640,16 @@ namespace iTextSharp.text.pdf { protected override int[] GetRawCharBBox(int c, String name) { return null; } + + /** + * Exposes the unicode - > CID map that is constructed from the font's encoding + * @return the unicode to CID map + * @since 2.1.7 + */ + internal IntHashtable Uni2Byte { + get { + return uni2byte; + } + } } }