internal override void WriteFont(PdfWriter writer, PdfIndirectReference piref, Object[] parms) { IntHashtable cjkTag = (IntHashtable)parms[0]; PdfIndirectReference ind_font = null; PdfObject pobj = null; PdfIndirectObject obj = null; pobj = GetFontDescriptor(); if (pobj != null) { obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } pobj = GetCIDFont(ind_font, cjkTag); if (pobj != null) { obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } pobj = GetFontBaseType(ind_font); writer.AddToBody(pobj, piref); }
/** Outputs to the writer the font dictionaries and streams. * @param writer the writer for this document * @param ref the font indirect reference * @param parms several parameters that depend on the font type * @throws IOException on error * @throws DocumentException error in generating the object */ internal override void WriteFont(PdfWriter writer, PdfIndirectReference piref, Object[] parms) { int firstChar = (int)parms[0]; int lastChar = (int)parms[1]; byte[] shortTag = (byte[])parms[2]; bool subsetp = (bool)parms[3] && subset; if (!subsetp) { firstChar = 0; lastChar = shortTag.Length - 1; for (int k = 0; k < shortTag.Length; ++k) { shortTag[k] = 1; } } PdfIndirectReference ind_font = null; PdfObject pobj = null; PdfIndirectObject obj = null; pobj = GetFullFontStream(); if (pobj != null) { obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } pobj = GetFontDescriptor(ind_font); if (pobj != null) { obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } pobj = GetFontBaseType(ind_font, firstChar, lastChar, shortTag); writer.AddToBody(pobj, piref); }
/** * Returns the CrossReferenceTable of the <CODE>Body</CODE>. * @param os * @param root * @param info * @param encryption * @param fileID * @param prevxref * @throws IOException */ internal void WriteCrossReferenceTable(Stream os, PdfIndirectReference root, PdfIndirectReference info, PdfIndirectReference encryption, PdfObject fileID, int prevxref) { int refNumber = 0; if (writer.FullCompression) { FlushObjStm(); refNumber = IndirectReferenceNumber; xrefs[new PdfCrossReference(refNumber, position)] = null; } int first = ((PdfCrossReference)xrefs.GetMinKey()).Refnum; int len = 0; ArrayList sections = new ArrayList(); foreach (PdfCrossReference entry in xrefs.Keys) { if (first + len == entry.Refnum) ++len; else { sections.Add(first); sections.Add(len); first = entry.Refnum; len = 1; } } sections.Add(first); sections.Add(len); if (writer.FullCompression) { int mid = 4; uint mask = 0xff000000; for (; mid > 1; --mid) { if ((mask & position) != 0) break; mask >>= 8; } ByteBuffer buf = new ByteBuffer(); foreach (PdfCrossReference entry in xrefs.Keys) { entry.ToPdf(mid, buf); } PdfStream xr = new PdfStream(buf.ToByteArray()); buf = null; xr.FlateCompress(writer.CompressionLevel); xr.Put(PdfName.SIZE, new PdfNumber(Size)); xr.Put(PdfName.ROOT, root); if (info != null) { xr.Put(PdfName.INFO, info); } if (encryption != null) xr.Put(PdfName.ENCRYPT, encryption); if (fileID != null) xr.Put(PdfName.ID, fileID); xr.Put(PdfName.W, new PdfArray(new int[]{1, mid, 2})); xr.Put(PdfName.TYPE, PdfName.XREF); PdfArray idx = new PdfArray(); for (int k = 0; k < sections.Count; ++k) idx.Add(new PdfNumber((int)sections[k])); xr.Put(PdfName.INDEX, idx); if (prevxref > 0) xr.Put(PdfName.PREV, new PdfNumber(prevxref)); PdfEncryption enc = writer.crypto; writer.crypto = null; PdfIndirectObject indirect = new PdfIndirectObject(refNumber, xr, writer); indirect.WriteTo(writer.Os); writer.crypto = enc; } else { byte[] tmp = GetISOBytes("xref\n"); os.Write(tmp, 0, tmp.Length); IEnumerator i = xrefs.Keys; i.MoveNext(); for (int k = 0; k < sections.Count; k += 2) { first = (int)sections[k]; len = (int)sections[k + 1]; tmp = GetISOBytes(first.ToString()); os.Write(tmp, 0, tmp.Length); os.WriteByte((byte)' '); tmp = GetISOBytes(len.ToString()); os.Write(tmp, 0, tmp.Length); os.WriteByte((byte)'\n'); while (len-- > 0) { ((PdfCrossReference)i.Current).ToPdf(os); i.MoveNext(); } } } }
internal PdfIndirectObject Add(PdfObject objecta, int refNumber, bool inObjStm) { if (inObjStm && objecta.CanBeInObjStm() && writer.FullCompression) { PdfCrossReference pxref = AddToObjStm(objecta, refNumber); PdfIndirectObject indirect = new PdfIndirectObject(refNumber, objecta, writer); xrefs.Remove(pxref); xrefs[pxref] = null; return indirect; } else { PdfIndirectObject indirect = new PdfIndirectObject(refNumber, objecta, writer); PdfCrossReference pxref = new PdfCrossReference(refNumber, position); xrefs.Remove(pxref); xrefs[pxref] = null; indirect.WriteTo(writer.Os); position = writer.Os.Counter; return indirect; } }
/** Outputs to the writer the font dictionaries and streams. * @param writer the writer for this document * @param ref the font indirect reference * @param parms several parameters that depend on the font type * @throws IOException on error * @throws DocumentException error in generating the object */ internal override void WriteFont(PdfWriter writer, PdfIndirectReference piref, Object[] parms) { Hashtable longTag = (Hashtable)parms[0]; AddRangeUni(longTag, true, subset); ArrayList tmp = new ArrayList(); foreach (object o in longTag.Values) { tmp.Add(o); } Object[] metrics = tmp.ToArray(); Array.Sort(metrics, this); PdfIndirectReference ind_font = null; PdfObject pobj = null; PdfIndirectObject obj = null; PdfIndirectReference cidset = null; if (writer.PDFXConformance == PdfWriter.PDFA1A || writer.PDFXConformance == PdfWriter.PDFA1B) { PdfStream stream; if (metrics.Length == 0) { stream = new PdfStream(new byte[] { (byte)0x80 }); } else { int top = ((int[])metrics[metrics.Length - 1])[0]; byte[] bt = new byte[top / 8 + 1]; for (int k = 0; k < metrics.Length; ++k) { int v = ((int[])metrics[k])[0]; bt[v / 8] |= rotbits[v % 8]; } stream = new PdfStream(bt); stream.FlateCompress(compressionLevel); } cidset = writer.AddToBody(stream).IndirectReference; } // sivan: cff if (cff) { byte[] b = ReadCffFont(); if (subset || subsetRanges != null) { CFFFontSubset cffs = new CFFFontSubset(new RandomAccessFileOrArray(b), longTag); b = cffs.Process((cffs.GetNames())[0]); } pobj = new StreamFont(b, "CIDFontType0C", compressionLevel); obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } else { byte[] b; if (subset || directoryOffset != 0) { TrueTypeFontSubSet sb = new TrueTypeFontSubSet(fileName, new RandomAccessFileOrArray(rf), longTag, directoryOffset, false, false); b = sb.Process(); } else { b = GetFullFont(); } int[] lengths = new int[] { b.Length }; pobj = new StreamFont(b, lengths, compressionLevel); obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } String subsetPrefix = ""; if (subset) { subsetPrefix = CreateSubsetPrefix(); } PdfDictionary dic = GetFontDescriptor(ind_font, subsetPrefix, cidset); obj = writer.AddToBody(dic); ind_font = obj.IndirectReference; pobj = GetCIDFontType2(ind_font, subsetPrefix, metrics); obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; pobj = GetToUnicode(metrics); PdfIndirectReference toUnicodeRef = null; if (pobj != null) { obj = writer.AddToBody(pobj); toUnicodeRef = obj.IndirectReference; } pobj = GetFontBaseType(ind_font, subsetPrefix, toUnicodeRef); writer.AddToBody(pobj, piref); }