Dear all,
in January 2011 there was an issue opened by "M. Niedermair" concerning
some problems using the OpenType font Linux Libertine
(http://itext-general.2136553.n4.nabble.com/FontFactory-registerDirectory-dir-tp3222941.html)
After we noticed similar problems – not only with Linux Libertine – my
colleague had a closer look into the code (Java version as well as C#).
1. Java:
Using a font like this:
BaseFont bf =
BaseFont.createFont("c:/windows/fonts/AdobeGothicStd-Bold.otf",BaseFont.IDENTITY_H,
true);
document.add(new Paragraph(content, new Font(bf)));
will throw an exception:
Exception in thread "main" java.lang.NullPointerException
at
com.itextpdf.text.pdf.CFFFontSubset.ReconstructPrivateSubrs(CFFFontSubset.java:1535)
at
com.itextpdf.text.pdf.CFFFontSubset.Reconstruct(CFFFontSubset.java:1406)
at
com.itextpdf.text.pdf.CFFFontSubset.BuildNewFile(CFFFontSubset.java:1147)
at
com.itextpdf.text.pdf.CFFFontSubset.Process(CFFFontSubset.java:378)
at
com.itextpdf.text.pdf.TtfUnicodeWriter.writeFont(TtfUnicodeWriter.java:32)
at
com.itextpdf.text.pdf.TrueTypeFontUnicode.writeFont(TrueTypeFontUnicode.java:337)
at com.itextpdf.text.pdf.FontDetails.writeFont(FontDetails.java:290)
at
com.itextpdf.text.pdf.PdfWriter.addSharedObjectsToBody(PdfWriter.java:1304)
at com.itextpdf.text.pdf.PdfWriter.close(PdfWriter.java:1212)
at com.itextpdf.text.pdf.PdfDocument.close(PdfDocument.java:777)
at com.itextpdf.text.Document.close(Document.java:398)
at info.FontTypesTest.createPdf(FontTypesTest.java:152)
at info.FontTypesTest.main(FontTypesTest.java:349)
The reason is line 1535 of CFFFontSubset.java:
OutputList.addLast(new RangeItem(new
RandomAccessFileOrArray(NewLSubrsIndex[i]),0,NewLSubrsIndex[i].length));
The Array NewLSubrsIndex[i] is null, therefore NewLSubrsIndex[i].length
throws an exceptions.
If I now add this:
if(NewLSubrsIndex[i]!=null)
OutputList.addLast(new RangeItem(new
RandomAccessFileOrArray(NewLSubrsIndex[i]),0,NewLSubrsIndex[i].length));
everything seems to be normal and a PDF is created. The array is only
used for CFF fonts.
2. C#
For the C# version the problem arises from "CFFontSubset.cs" at line
1534. I need to add :
if(NewLSubrsIndex[i]!=null)
OutputList.Add(new RangeItem(new
RandomAccessFileOrArray(NewLSubrsIndex[i]),0,NewLSubrsIndex[i].Length));
In addition I had to remove some code at line 1066 of CFFont.cs:
/* else if (key=="Encoding"){
fonts[j].encodingOffset = (int)args[0];
ReadEncoding(fonts[j].encodingOffset);
}*/
I my opinion this matches the fact, that using "WINANSI" instead of
"IDENTITY_H" works perfectly for Linux Libertine (but of course some
"special" glyphs are missing then).
The question remains: Do these changes above have any side-effects for
other fonts? Is this a bug at all or rather an error in the font
structure (as pointed out by "Mark Storer-2" in January 2011) which
misleads iText's routines?
Please find attached the patches.
Thank you very much
Best regards
Yu Gan and Martin Sievers
--
Diplom-Mathematiker Martin Sievers
Kompetenzzentrum für elektronische Erschließungs- und
Publikationsverfahren in den Geisteswissenschaften
(Trier Center for Digital Humanities)
Universität Trier
Fachbereich II / Germanistik
Universitätsring 15
54296 Trier
Postanschrift: Universität Trier, 54286 Trier
Projekte: XML-Print / Workspace for Collaborative Editing
Raum: DM333 (3.OG B)
Telefon: 0651 201-3017
Telefax: 0651 201-3589
Skype: martinsievers
E-Mail: [email protected]
Internet: http://www.kompetenzzentrum.uni-trier.de
Index: itext/src/main/java/com/itextpdf/text/pdf/CFFFontSubset.java
===================================================================
--- itext/src/main/java/com/itextpdf/text/pdf/CFFFontSubset.java
(revision 5617)
+++ itext/src/main/java/com/itextpdf/text/pdf/CFFFontSubset.java
(working copy)
@@ -1531,6 +1531,7 @@
if (fdSubrs[i]!= null && fonts[Font].PrivateSubrsOffset[i] >= 0)
{
OutputList.addLast(new
SubrMarkerItem(fdSubrs[i],fdPrivateBase[i]));
+ if(NewLSubrsIndex[i]!=null)
OutputList.addLast(new RangeItem(new
RandomAccessFileOrArray(NewLSubrsIndex[i]),0,NewLSubrsIndex[i].length));
}
}
From 3d0398093b05def56d00957bd738082da65399e0 Mon Sep 17 00:00:00 2001
From: yugan <[email protected]>
Date: Mon, 17 Dec 2012 14:39:39 +0100
Subject: [PATCH] CFFFont.cs
---
src/core/iTextSharp/text/pdf/CFFFont.cs | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/core/iTextSharp/text/pdf/CFFFont.cs
b/src/core/iTextSharp/text/pdf/CFFFont.cs
index 0e5d896..95b273b 100644
--- a/src/core/iTextSharp/text/pdf/CFFFont.cs
+++ b/src/core/iTextSharp/text/pdf/CFFFont.cs
@@ -1051,11 +1051,11 @@ namespace iTextSharp.text.pdf {
else if (key=="charset"){
fonts[j].charsetOffset = (int)args[0];
- }
+ }/*
else if (key=="Encoding"){
fonts[j].encodingOffset = (int)args[0];
ReadEncoding(fonts[j].encodingOffset);
- }
+ }*/
else if (key=="CharStrings") {
fonts[j].charstringsOffset = (int)args[0];
//System.err.Println("charstrings
"+fonts[j].charstringsOffset);
--
1.7.8.msysgit.0
From 8c46b86869099f70d7037bae21b8c9fcb284c3dd Mon Sep 17 00:00:00 2001
From: yugan <[email protected]>
Date: Mon, 17 Dec 2012 14:34:18 +0100
Subject: [PATCH] Exception in CFFFontSubset.java when using opentype font
---
src/core/iTextSharp/text/pdf/CFFFontSubset.cs | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/core/iTextSharp/text/pdf/CFFFontSubset.cs
b/src/core/iTextSharp/text/pdf/CFFFontSubset.cs
index 2e89eef..733e16d 100644
--- a/src/core/iTextSharp/text/pdf/CFFFontSubset.cs
+++ b/src/core/iTextSharp/text/pdf/CFFFontSubset.cs
@@ -1531,7 +1531,8 @@ namespace iTextSharp.text.pdf {
if (fdSubrs[i]!= null && fonts[Font].PrivateSubrsOffset[i] >=
0)
{
OutputList.Add(new
SubrMarkerItem(fdSubrs[i],fdPrivateBase[i]));
- OutputList.Add(new RangeItem(new
RandomAccessFileOrArray(NewLSubrsIndex[i]),0,NewLSubrsIndex[i].Length));
+ if(NewLSubrsIndex[i]!=null)
+ OutputList.Add(new RangeItem(new
RandomAccessFileOrArray(NewLSubrsIndex[i]),0,NewLSubrsIndex[i].Length));
}
}
}
--
1.7.8.msysgit.0
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php