Porting update.

git-svn-id: svn://svn.code.sf.net/p/itextsharp/code/trunk@25 820d3149-562b-4f88-9aa4-a8e61a3485cf
master
psoares33 2009-06-11 13:02:34 +00:00
parent 02a67fe785
commit 2f680df9bc
5 changed files with 181 additions and 72 deletions

View File

@ -143,7 +143,7 @@ namespace iTextSharp.text.pdf {
/** java.awt.Font property */
public const int AWT_MAXADVANCE = 12;
/**
* The undeline position. Usually a negative value.
* The underline position. Usually a negative value.
*/
public const int UNDERLINE_POSITION = 13;
/**
@ -265,7 +265,7 @@ namespace iTextSharp.text.pdf {
protected int compressionLevel = PdfStream.DEFAULT_COMPRESSION;
/**
* true if the font must use it's built in encoding. In that case the
* true if the font must use its built in encoding. In that case the
* <CODE>encoding</CODE> is only used to map a char to the position inside
* the font, not to the expected char name.
*/
@ -377,7 +377,8 @@ namespace iTextSharp.text.pdf {
public static BaseFont CreateFont() {
return CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
}
/**
/**
* Creates a new font. This font can be one of the 14 built in types,
* a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or collection) or a CJK font from the
* Adobe Asian Font Pack. TrueType fonts and CJK fonts can have an optional style modifier
@ -418,17 +419,71 @@ namespace iTextSharp.text.pdf {
* <PRE>
* createFont(name, encoding, embedded, true, null, null);
* </PRE>
* @param name the name of the font or it's location on file
* @param name the name of the font or its location on file
* @param encoding the encoding to be applied to this font
* @param embedded true if the font is to be embedded in the PDF
* @return returns a new font. This font may come from the cache
* @throws DocumentException the font is invalid
* @throws IOException the font file could not be read
*/
public static BaseFont CreateFont(string name, string encoding, bool embedded) {
return CreateFont(name, encoding, embedded, true, null, null);
public static BaseFont CreateFont(String name, String encoding, bool embedded) {
return CreateFont(name, encoding, embedded, true, null, null, false);
}
/**
* Creates a new font. This font can be one of the 14 built in types,
* a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or collection) or a CJK font from the
* Adobe Asian Font Pack. TrueType fonts and CJK fonts can have an optional style modifier
* appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
* example would be "STSong-Light,Bold". Note that this modifiers do not work if
* the font is embedded. Fonts in TrueType collections are addressed by index such as "msgothic.ttc,1".
* This would get the second font (indexes start at 0), in this case "MS PGothic".
* <P>
* The fonts are cached and if they already exist they are extracted from the cache,
* not parsed again.
* <P>
* Besides the common encodings described by name, custom encodings
* can also be made. These encodings will only work for the single byte fonts
* Type1 and TrueType. The encoding string starts with a '#'
* followed by "simple" or "full". If "simple" there is a decimal for the first character position and then a list
* of hex values representing the Unicode codes that compose that encoding.<br>
* The "simple" encoding is recommended for TrueType fonts
* as the "full" encoding risks not matching the character with the right glyph
* if not done with care.<br>
* The "full" encoding is specially aimed at Type1 fonts where the glyphs have to be
* described by non standard names like the Tex math fonts. Each group of three elements
* compose a code position: the one byte code order in decimal or as 'x' (x cannot be the space), the name and the Unicode character
* used to access the glyph. The space must be assigned to character position 32 otherwise
* text justification will not work.
* <P>
* Example for a "simple" encoding that includes the Unicode
* character space, A, B and ecyrillic:
* <PRE>
* "# simple 32 0020 0041 0042 0454"
* </PRE>
* <P>
* Example for a "full" encoding for a Type1 Tex font:
* <PRE>
* "# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020"
* </PRE>
* <P>
* This method calls:<br>
* <PRE>
* createFont(name, encoding, embedded, true, null, null);
* </PRE>
* @param name the name of the font or its location on file
* @param encoding the encoding to be applied to this font
* @param embedded true if the font is to be embedded in the PDF
* @param forceRead in some cases (TrueTypeFont, Type1Font), the full font file will be read and kept in memory if forceRead is true
* @return returns a new font. This font may come from the cache
* @throws DocumentException the font is invalid
* @throws IOException the font file could not be read
* @since 2.1.5
*/
public static BaseFont CreateFont(String name, String encoding, bool embedded, bool forceRead) {
return CreateFont(name, encoding, embedded, true, null, null, forceRead);
}
/** Creates a new font. This font can be one of the 14 built in types,
* a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or collection) or a CJK font from the
* Adobe Asian Font Pack. TrueType fonts and CJK fonts can have an optional style modifier
@ -466,7 +521,7 @@ namespace iTextSharp.text.pdf {
* <PRE>
* "# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020"
* </PRE>
* @param name the name of the font or it's location on file
* @param name the name of the font or its location on file
* @param encoding the encoding to be applied to this font
* @param embedded true if the font is to be embedded in the PDF
* @param cached true if the font comes from the cache or is added to
@ -477,11 +532,12 @@ namespace iTextSharp.text.pdf {
* is true, otherwise it will always be created new
* @throws DocumentException the font is invalid
* @throws IOException the font file could not be read
* @since iText 0.80
*/
public static BaseFont CreateFont(string name, string encoding, bool embedded, bool cached, byte[] ttfAfm, byte[] pfb) {
public static BaseFont CreateFont(String name, String encoding, bool embedded, bool cached, byte[] ttfAfm, byte[] pfb) {
return CreateFont(name, encoding, embedded, cached, ttfAfm, pfb, false);
}
/** Creates a new font. This font can be one of the 14 built in types,
* a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or collection) or a CJK font from the
* Adobe Asian Font Pack. TrueType fonts and CJK fonts can have an optional style modifier
@ -519,7 +575,7 @@ namespace iTextSharp.text.pdf {
* <PRE>
* "# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020"
* </PRE>
* @param name the name of the font or it's location on file
* @param name the name of the font or its location on file
* @param encoding the encoding to be applied to this font
* @param embedded true if the font is to be embedded in the PDF
* @param cached true if the font comes from the cache or is added to
@ -533,8 +589,67 @@ namespace iTextSharp.text.pdf {
* is true, otherwise it will always be created new
* @throws DocumentException the font is invalid
* @throws IOException the font file could not be read
* @since 2.0.3
*/
public static BaseFont CreateFont(string name, string encoding, bool embedded, bool cached, byte[] ttfAfm, byte[] pfb, bool noThrow) {
public static BaseFont CreateFont(String name, String encoding, bool embedded, bool cached, byte[] ttfAfm, byte[] pfb, bool noThrow) {
return CreateFont(name, encoding, embedded, cached, ttfAfm, pfb, false, false);
}
/** Creates a new font. This font can be one of the 14 built in types,
* a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or collection) or a CJK font from the
* Adobe Asian Font Pack. TrueType fonts and CJK fonts can have an optional style modifier
* appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
* example would be "STSong-Light,Bold". Note that this modifiers do not work if
* the font is embedded. Fonts in TrueType collections are addressed by index such as "msgothic.ttc,1".
* This would get the second font (indexes start at 0), in this case "MS PGothic".
* <P>
* The fonts may or may not be cached depending on the flag <CODE>cached</CODE>.
* If the <CODE>byte</CODE> arrays are present the font will be
* read from them instead of the name. A name is still required to identify
* the font type.
* <P>
* Besides the common encodings described by name, custom encodings
* can also be made. These encodings will only work for the single byte fonts
* Type1 and TrueType. The encoding string starts with a '#'
* followed by "simple" or "full". If "simple" there is a decimal for the first character position and then a list
* of hex values representing the Unicode codes that compose that encoding.<br>
* The "simple" encoding is recommended for TrueType fonts
* as the "full" encoding risks not matching the character with the right glyph
* if not done with care.<br>
* The "full" encoding is specially aimed at Type1 fonts where the glyphs have to be
* described by non standard names like the Tex math fonts. Each group of three elements
* compose a code position: the one byte code order in decimal or as 'x' (x cannot be the space), the name and the Unicode character
* used to access the glyph. The space must be assigned to character position 32 otherwise
* text justification will not work.
* <P>
* Example for a "simple" encoding that includes the Unicode
* character space, A, B and ecyrillic:
* <PRE>
* "# simple 32 0020 0041 0042 0454"
* </PRE>
* <P>
* Example for a "full" encoding for a Type1 Tex font:
* <PRE>
* "# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020"
* </PRE>
* @param name the name of the font or its location on file
* @param encoding the encoding to be applied to this font
* @param embedded true if the font is to be embedded in the PDF
* @param cached true if the font comes from the cache or is added to
* the cache if new, false if the font is always created new
* @param ttfAfm the true type font or the afm in a byte array
* @param pfb the pfb in a byte array
* @param noThrow if true will not throw an exception if the font is not recognized and will return null, if false will throw
* an exception if the font is not recognized. Note that even if true an exception may be thrown in some circumstances.
* This parameter is useful for FontFactory that may have to check many invalid font names before finding the right one
* @param forceRead in some cases (TrueTypeFont, Type1Font), the full font file will be read and kept in memory if forceRead is true
* @return returns a new font. This font may come from the cache but only if cached
* is true, otherwise it will always be created new
* @throws DocumentException the font is invalid
* @throws IOException the font file could not be read
* @since 2.1.5
*/
public static BaseFont CreateFont(String name, String encoding, bool embedded, bool cached, byte[] ttfAfm, byte[] pfb, bool noThrow, bool forceRead) {
string nameBase = GetBaseName(name);
encoding = NormalizeEncoding(encoding);
bool isBuiltinFonts14 = BuiltinFonts14.ContainsKey(name);
@ -554,14 +669,14 @@ namespace iTextSharp.text.pdf {
return fontFound;
}
if (isBuiltinFonts14 || name.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".afm") || name.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".pfm")) {
fontBuilt = new Type1Font(name, encoding, embedded, ttfAfm, pfb);
fontBuilt = new Type1Font(name, encoding, embedded, ttfAfm, pfb, forceRead);
fontBuilt.fastWinansi = encoding.Equals(CP1252);
}
else if (nameBase.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".ttf") || nameBase.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".otf") || nameBase.ToLower(System.Globalization.CultureInfo.InvariantCulture).IndexOf(".ttc,") > 0) {
if (encoding.Equals(IDENTITY_H) || encoding.Equals(IDENTITY_V))
fontBuilt = new TrueTypeFontUnicode(name, encoding, embedded, ttfAfm);
fontBuilt = new TrueTypeFontUnicode(name, encoding, embedded, ttfAfm, forceRead);
else {
fontBuilt = new TrueTypeFont(name, encoding, embedded, ttfAfm);
fontBuilt = new TrueTypeFont(name, encoding, embedded, ttfAfm, false, forceRead);
fontBuilt.fastWinansi = encoding.Equals(CP1252);
}
}
@ -1061,7 +1176,7 @@ namespace iTextSharp.text.pdf {
string nameBase = GetBaseName(name);
BaseFont fontBuilt = null;
if (nameBase.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".ttf") || nameBase.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".otf") || nameBase.ToLower(System.Globalization.CultureInfo.InvariantCulture).IndexOf(".ttc,") > 0)
fontBuilt = new TrueTypeFont(name, CP1252, false, ttfAfm, true);
fontBuilt = new TrueTypeFont(name, CP1252, false, ttfAfm, true, false);
else
fontBuilt = CreateFont(name, encoding, false, false, ttfAfm, null);
return fontBuilt.FullFontName;
@ -1079,7 +1194,7 @@ namespace iTextSharp.text.pdf {
String nameBase = GetBaseName(name);
BaseFont fontBuilt = null;
if (nameBase.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".ttf") || nameBase.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".otf") || nameBase.ToLower(System.Globalization.CultureInfo.InvariantCulture).IndexOf(".ttc,") > 0)
fontBuilt = new TrueTypeFont(name, CP1252, false, ttfAfm, true);
fontBuilt = new TrueTypeFont(name, CP1252, false, ttfAfm, true, false);
else
fontBuilt = CreateFont(name, encoding, false, false, ttfAfm, null);
return new Object[]{fontBuilt.PostscriptFontName, fontBuilt.FamilyFontName, fontBuilt.FullFontName};
@ -1097,7 +1212,7 @@ namespace iTextSharp.text.pdf {
String nameBase = GetBaseName(name);
BaseFont fontBuilt = null;
if (nameBase.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".ttf") || nameBase.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".otf") || nameBase.ToLower(System.Globalization.CultureInfo.InvariantCulture).IndexOf(".ttc,") > 0)
fontBuilt = new TrueTypeFont(name, CP1252, false, ttfAfm, true);
fontBuilt = new TrueTypeFont(name, CP1252, false, ttfAfm, true, false);
else
fontBuilt = CreateFont(name, encoding, false, false, ttfAfm, null);
return fontBuilt.AllNameEntries;
@ -1338,10 +1453,10 @@ namespace iTextSharp.text.pdf {
if (obj == null || !obj.IsDictionary())
return;
PdfDictionary font = (PdfDictionary)obj;
PdfName subtype = (PdfName)PdfReader.GetPdfObject(font.Get(PdfName.SUBTYPE));
PdfName subtype = font.GetAsName(PdfName.SUBTYPE);
if (!PdfName.TYPE1.Equals(subtype) && !PdfName.TRUETYPE.Equals(subtype))
return;
PdfName name = (PdfName)PdfReader.GetPdfObject(font.Get(PdfName.BASEFONT));
PdfName name = font.GetAsName(PdfName.BASEFONT);
fonts.Add(new Object[]{PdfName.DecodeName(name.ToString()), fontRef});
hits[fontRef.Number] = 1;
}
@ -1350,10 +1465,10 @@ namespace iTextSharp.text.pdf {
++level;
if (level > 50) // in case we have an endless loop
return;
PdfDictionary resources = (PdfDictionary)PdfReader.GetPdfObject(page.Get(PdfName.RESOURCES));
PdfDictionary resources = page.GetAsDict(PdfName.RESOURCES);
if (resources == null)
return;
PdfDictionary font = (PdfDictionary)PdfReader.GetPdfObject(resources.Get(PdfName.FONT));
PdfDictionary font = resources.GetAsDict(PdfName.FONT);
if (font != null) {
foreach (PdfName key in font.Keys) {
PdfObject ft = font.Get(key);
@ -1365,10 +1480,10 @@ namespace iTextSharp.text.pdf {
AddFont((PRIndirectReference)ft, hits, fonts);
}
}
PdfDictionary xobj = (PdfDictionary)PdfReader.GetPdfObject(resources.Get(PdfName.XOBJECT));
PdfDictionary xobj = resources.GetAsDict(PdfName.XOBJECT);
if (xobj != null) {
foreach (PdfName key in xobj.Keys) {
RecourseFonts((PdfDictionary)PdfReader.GetPdfObject(xobj.Get(key)), hits, fonts, level);
RecourseFonts(xobj.GetAsDict(key), hits, fonts, level);
}
}
}

View File

@ -107,8 +107,8 @@ namespace iTextSharp.text.pdf {
this.refFont = refFont;
fontType = FONT_TYPE_DOCUMENT;
font = (PdfDictionary)PdfReader.GetPdfObject(refFont);
fontName = PdfName.DecodeName(((PdfName)PdfReader.GetPdfObject(font.Get(PdfName.BASEFONT))).ToString());
PdfName subType = (PdfName)PdfReader.GetPdfObject(font.Get(PdfName.SUBTYPE));
fontName = PdfName.DecodeName(font.GetAsName(PdfName.BASEFONT).ToString());
PdfName subType = font.GetAsName(PdfName.SUBTYPE);
if (PdfName.TYPE1.Equals(subType) || PdfName.TRUETYPE.Equals(subType))
DoType1TT();
else {
@ -119,7 +119,7 @@ namespace iTextSharp.text.pdf {
return;
}
}
String enc = PdfName.DecodeName(((PdfName)PdfReader.GetPdfObject(font.Get(PdfName.ENCODING))).ToString());
String enc = PdfName.DecodeName(font.GetAsName(PdfName.ENCODING).ToString());
for (int k = 0; k < cjkEncs2.Length; ++k) {
if (enc.StartsWith(cjkEncs2[k])) {
if (k > 3)
@ -138,7 +138,7 @@ namespace iTextSharp.text.pdf {
private void ProcessType0(PdfDictionary font) {
byte[] touni = PdfReader.GetStreamBytes((PRStream)PdfReader.GetPdfObjectRelease(font.Get(PdfName.TOUNICODE)));
PdfArray df = (PdfArray)PdfReader.GetPdfObjectRelease(font.Get(PdfName.DESCENDANTFONTS));
PdfDictionary cidft = (PdfDictionary)PdfReader.GetPdfObjectRelease((PdfObject)df.ArrayList[0]);
PdfDictionary cidft = (PdfDictionary)PdfReader.GetPdfObjectRelease(df[0]);
PdfNumber dwo = (PdfNumber)PdfReader.GetPdfObjectRelease(cidft.Get(PdfName.DW));
int dw = 1000;
if (dwo != null)
@ -153,20 +153,19 @@ namespace iTextSharp.text.pdf {
IntHashtable hh = new IntHashtable();
if (ws == null)
return hh;
ArrayList ar = ws.ArrayList;
for (int k = 0; k < ar.Count; ++k) {
int c1 = ((PdfNumber)PdfReader.GetPdfObjectRelease((PdfObject)ar[k])).IntValue;
PdfObject obj = PdfReader.GetPdfObjectRelease((PdfObject)ar[++k]);
for (int k = 0; k < ws.Size; ++k) {
int c1 = ((PdfNumber)PdfReader.GetPdfObjectRelease(ws[k])).IntValue;
PdfObject obj = PdfReader.GetPdfObjectRelease(ws[++k]);
if (obj.IsArray()) {
ArrayList ar2 = ((PdfArray)obj).ArrayList;
for (int j = 0; j < ar2.Count; ++j) {
int c2 = ((PdfNumber)PdfReader.GetPdfObjectRelease((PdfObject)ar2[j])).IntValue;
PdfArray a2 = (PdfArray)obj;
for (int j = 0; j < a2.Size; ++j) {
int c2 = ((PdfNumber)PdfReader.GetPdfObjectRelease(a2[j])).IntValue;
hh[c1++] = c2;
}
}
else {
int c2 = ((PdfNumber)obj).IntValue;
int w = ((PdfNumber)PdfReader.GetPdfObjectRelease((PdfObject)ar[++k])).IntValue;
int w = ((PdfNumber)PdfReader.GetPdfObjectRelease(ws[++k])).IntValue;
for (; c1 <= c2; ++c1)
hh[c1] = w;
}
@ -223,9 +222,9 @@ namespace iTextSharp.text.pdf {
}
}
else {
ArrayList ar = ((PdfArray)ob2).ArrayList;
for (int j = 0; j < ar.Count; ++j, ++cid1c) {
String uni = DecodeString((PdfString)ar[j]);
PdfArray a = (PdfArray)ob2;
for (int j = 0; j < a.Size; ++j, ++cid1c) {
String uni = DecodeString(a.GetAsString(j));
if (uni.Length == 1) {
int unic = (int)uni[uni.Length - 1];
int w = dw;
@ -257,13 +256,12 @@ namespace iTextSharp.text.pdf {
FillEncoding(null);
else
FillEncoding((PdfName)enc);
PdfArray diffs = (PdfArray)PdfReader.GetPdfObject(encDic.Get(PdfName.DIFFERENCES));
PdfArray diffs = encDic.GetAsArray(PdfName.DIFFERENCES);
if (diffs != null) {
diffmap = new IntHashtable();
ArrayList dif = diffs.ArrayList;
int currentNumber = 0;
for (int k = 0; k < dif.Count; ++k) {
PdfObject obj = (PdfObject)dif[k];
for (int k = 0; k < diffs.Size; ++k) {
PdfObject obj = diffs[k];
if (obj.IsNumber())
currentNumber = ((PdfNumber)obj).IntValue;
else {
@ -278,9 +276,9 @@ namespace iTextSharp.text.pdf {
}
}
}
PdfArray newWidths = (PdfArray)PdfReader.GetPdfObject(font.Get(PdfName.WIDTHS));
PdfNumber first = (PdfNumber)PdfReader.GetPdfObject(font.Get(PdfName.FIRSTCHAR));
PdfNumber last = (PdfNumber)PdfReader.GetPdfObject(font.Get(PdfName.LASTCHAR));
PdfArray newWidths = font.GetAsArray(PdfName.WIDTHS);
PdfNumber first = font.GetAsNumber(PdfName.FIRSTCHAR);
PdfNumber last = font.GetAsNumber(PdfName.LASTCHAR);
if (BuiltinFonts14.ContainsKey(fontName)) {
BaseFont bf;
bf = BaseFont.CreateFont(fontName, WINANSI, false);
@ -308,36 +306,34 @@ namespace iTextSharp.text.pdf {
}
if (first != null && last != null && newWidths != null) {
int f = first.IntValue;
ArrayList ar = newWidths.ArrayList;
for (int k = 0; k < ar.Count; ++k) {
widths[f + k] = ((PdfNumber)ar[k]).IntValue;
for (int k = 0; k < newWidths.Size; ++k) {
widths[f + k] = newWidths.GetAsNumber(k).IntValue;
}
}
FillFontDesc((PdfDictionary)PdfReader.GetPdfObject(font.Get(PdfName.FONTDESCRIPTOR)));
FillFontDesc(font.GetAsDict(PdfName.FONTDESCRIPTOR));
}
private void FillFontDesc(PdfDictionary fontDesc) {
if (fontDesc == null)
return;
PdfNumber v = (PdfNumber)PdfReader.GetPdfObject(fontDesc.Get(PdfName.ASCENT));
PdfNumber v = fontDesc.GetAsNumber(PdfName.ASCENT);
if (v != null)
Ascender = v.FloatValue;
v = (PdfNumber)PdfReader.GetPdfObject(fontDesc.Get(PdfName.CAPHEIGHT));
v = fontDesc.GetAsNumber(PdfName.CAPHEIGHT);
if (v != null)
CapHeight = v.FloatValue;
v = (PdfNumber)PdfReader.GetPdfObject(fontDesc.Get(PdfName.DESCENT));
v = fontDesc.GetAsNumber(PdfName.DESCENT);
if (v != null)
Descender = v.FloatValue;
v = (PdfNumber)PdfReader.GetPdfObject(fontDesc.Get(PdfName.ITALICANGLE));
v = fontDesc.GetAsNumber(PdfName.ITALICANGLE);
if (v != null)
ItalicAngle = v.FloatValue;
PdfArray bbox = (PdfArray)PdfReader.GetPdfObject(fontDesc.Get(PdfName.FONTBBOX));
PdfArray bbox = fontDesc.GetAsArray(PdfName.FONTBBOX);
if (bbox != null) {
ArrayList ar = bbox.ArrayList;
llx = ((PdfNumber)ar[0]).FloatValue;
lly = ((PdfNumber)ar[1]).FloatValue;
urx = ((PdfNumber)ar[2]).FloatValue;
ury = ((PdfNumber)ar[3]).FloatValue;
llx = bbox.GetAsNumber(0).FloatValue;
lly = bbox.GetAsNumber(1).FloatValue;
urx = bbox.GetAsNumber(2).FloatValue;
ury = bbox.GetAsNumber(3).FloatValue;
if (llx > urx) {
float t = llx;
llx = urx;

View File

@ -350,8 +350,6 @@ namespace iTextSharp.text.pdf {
protected TrueTypeFont() {
}
internal TrueTypeFont(string ttFile, string enc, bool emb, byte[] ttfAfm) : this(ttFile, enc, emb, ttfAfm, false) {}
/** Creates a new TrueType font.
* @param ttFile the location of the font on file. The file must end in '.ttf' or
* '.ttc' but can have modifiers after the name
@ -361,7 +359,7 @@ namespace iTextSharp.text.pdf {
* @throws DocumentException the font is invalid
* @throws IOException the font file could not be read
*/
internal TrueTypeFont(string ttFile, string enc, bool emb, byte[] ttfAfm, bool justNames) {
internal TrueTypeFont(string ttFile, string enc, bool emb, byte[] ttfAfm, bool justNames, bool forceRead) {
this.justNames = justNames;
string nameBase = GetBaseName(ttFile);
string ttcName = GetTTCName(nameBase);
@ -376,7 +374,7 @@ namespace iTextSharp.text.pdf {
if (ttcName.Length < nameBase.Length)
ttcIndex = nameBase.Substring(ttcName.Length + 1);
if (fileName.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".ttf") || fileName.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".otf") || fileName.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".ttc")) {
Process(ttfAfm);
Process(ttfAfm, forceRead);
if (!justNames && embedded && os_2.fsType == 2)
throw new DocumentException(fileName + style + " cannot be embedded due to licensing restrictions.");
}
@ -630,12 +628,12 @@ namespace iTextSharp.text.pdf {
* @throws DocumentException the font is invalid
* @throws IOException the font file could not be read
*/
internal void Process(byte[] ttfAfm) {
internal void Process(byte[] ttfAfm, bool preload) {
tables = new Hashtable();
try {
if (ttfAfm == null)
rf = new RandomAccessFileOrArray(fileName);
rf = new RandomAccessFileOrArray(fileName, preload);
else
rf = new RandomAccessFileOrArray(ttfAfm);
if (ttcIndex.Length > 0) {

View File

@ -77,7 +77,7 @@ namespace iTextSharp.text.pdf {
* @throws DocumentException the font is invalid
* @throws IOException the font file could not be read
*/
internal TrueTypeFontUnicode(string ttFile, string enc, bool emb, byte[] ttfAfm) {
internal TrueTypeFontUnicode(string ttFile, string enc, bool emb, byte[] ttfAfm, bool forceRead) {
string nameBase = GetBaseName(ttFile);
string ttcName = GetTTCName(nameBase);
if (nameBase.Length < ttFile.Length) {
@ -91,7 +91,7 @@ namespace iTextSharp.text.pdf {
ttcIndex = nameBase.Substring(ttcName.Length + 1);
FontType = FONT_TYPE_TTUNI;
if ((fileName.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".ttf") || fileName.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".otf") || fileName.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".ttc")) && ((enc.Equals(IDENTITY_H) || enc.Equals(IDENTITY_V)) && emb)) {
Process(ttfAfm);
Process(ttfAfm, forceRead);
if (os_2.fsType == 2)
throw new DocumentException(fileName + style + " cannot be embedded due to licensing restrictions.");
// Sivan

View File

@ -161,7 +161,7 @@ namespace iTextSharp.text.pdf {
* @throws DocumentException the AFM file is invalid
* @throws IOException the AFM file could not be read
*/
internal Type1Font(string afmFile, string enc, bool emb, byte[] ttfAfm, byte[] pfb) {
internal Type1Font(string afmFile, string enc, bool emb, byte[] ttfAfm, byte[] pfb, bool forceRead) {
if (emb && ttfAfm != null && pfb == null)
throw new DocumentException("Two byte arrays are needed if the Type1 font is embedded.");
if (emb && ttfAfm != null)
@ -219,7 +219,7 @@ namespace iTextSharp.text.pdf {
else if (afmFile.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".afm")) {
try {
if (ttfAfm == null)
rf = new RandomAccessFileOrArray(afmFile);
rf = new RandomAccessFileOrArray(afmFile, forceRead);
else
rf = new RandomAccessFileOrArray(ttfAfm);
Process(rf);
@ -239,7 +239,7 @@ namespace iTextSharp.text.pdf {
try {
MemoryStream ba = new MemoryStream();
if (ttfAfm == null)
rf = new RandomAccessFileOrArray(afmFile);
rf = new RandomAccessFileOrArray(afmFile, forceRead);
else
rf = new RandomAccessFileOrArray(ttfAfm);
Pfm2afm.Convert(rf, ba);
@ -478,7 +478,7 @@ namespace iTextSharp.text.pdf {
try {
string filePfb = fileName.Substring(0, fileName.Length - 3) + "pfb";
if (pfb == null)
rf = new RandomAccessFileOrArray(filePfb);
rf = new RandomAccessFileOrArray(filePfb, true);
else
rf = new RandomAccessFileOrArray(pfb);
int fileLength = rf.Length;