public override int ReadCode(Bytes.IInputStream input, out byte[] bytes)
 {
     bytes = new byte[1] {
         (byte)input.ReadByte()
     };
     return(bytes[0]);
 }
Example #2
0
 /**
  * Constructor from a stream.
  * @param is The stream to read from. It will be closed by this method.
  * @ If an error occurs while reading from the stream.
  */
 public MemoryTTFDataStream(Bytes.IInputStream isource)
 {
     try
     {
         data = isource.GetBuffer();
     }
     finally
     {
         isource.Dispose();
     }
 }
Example #3
0
        public PdfType1Font(Document doc, Bytes.IInputStream pfbIn, Encoding encoding) : base(doc)
        {
            PdfType1FontEmbedder embedder = new PdfType1FontEmbedder(doc, Dictionary, pfbIn, encoding);

            this.encoding       = encoding;
            glyphList           = embedder.GlyphList;
            type1font           = embedder.Type1Font;
            genericFont         = embedder.Type1Font;
            isEmbedded          = true;
            isDamaged           = false;
            fontMatrixTransform = SKMatrix.Identity;
            codeToBytesMap      = new Dictionary <int, byte[]>();
        }
Example #4
0
        /**
         * This will load a PFB to be embedded into a document.
         *
         * @param doc The PDF document that will hold the embedded font.
         * @param dict The Font dictionary to write to.
         * @param pfbStream The pfb input.
         * @throws IOException If there is an error loading the data.
         */
        public PdfType1FontEmbedder(Document doc, PdfDictionary dict, Bytes.IInputStream pfbStream, Encoding encoding)
        {
            dict[PdfName.Subtype] = PdfName.Type1;

            // read the pfb
            byte[]    pfbBytes  = pfbStream.ToByteArray();
            PfbParser pfbParser = new PfbParser(pfbBytes);

            type1 = Type1Font.CreateWithPFB(pfbBytes);

            if (encoding == null)
            {
                fontEncoding = Type1Encoding.FromFontBox(type1.Encoding);
            }
            else
            {
                fontEncoding = encoding;
            }

            // build font descriptor
            FontDescriptor fd = BuildFontDescriptor(type1);

            PdfStream fontStream = new PdfStream(pfbParser.GetInputStream());

            fontStream.Header[PdfName.Length] = PdfInteger.Get(pfbParser.Size);
            for (int i = 0; i < pfbParser.Lengths.Length; i++)
            {
                fontStream.Header[new PdfName("Length" + (i + 1))] = PdfInteger.Get(pfbParser.Lengths[i]);
            }
            fd.FontFile = new FontFile(doc, fontStream);

            // set the values
            dict[PdfName.FontDescriptor] = fd.BaseObject;
            dict[PdfName.BaseFont]       = PdfName.Get(type1.Name);

            // widths
            List <int> widths = new List <int>(256);

            for (int code = 0; code <= 255; code++)
            {
                string name  = fontEncoding.GetName(code);
                int    width = (int)Math.Round(type1.GetWidth(name));
                widths.Add(width);
            }

            dict[PdfName.FirstChar] = PdfInteger.Get(0);
            dict[PdfName.LastChar]  = PdfInteger.Get(255);
            dict[PdfName.Widths]    = new PdfArray(widths.Select(p => PdfInteger.Get(p)));
            dict[PdfName.Encoding]  = encoding.GetPdfObject();
        }
Example #5
0
 /**
  * Parse an input stream and return a TrueType font.
  *
  * @param inputStream The TTF data stream to parse from. It will be closed before returning.
  * @return A TrueType font.
  * @ If there is an error parsing the TrueType font.
  */
 public TrueTypeFont Parse(Bytes.IInputStream inputStream, string fontName = null)
 {
     return(Parse(new MemoryTTFDataStream(inputStream), fontName));
 }
        /**
         * Loads a TTF to be embedded into a document as a simple font.
         *
         * <p><b>Note:</b> Simple fonts only support 256 characters. For Unicode support, use
         * {@link PDType0Font#load(Document, Bytes.IInputStream)} instead.</p>
         *
         * @param doc The PDF document that will hold the embedded font.
         * @param input A TTF file stream
         * @param encoding The PostScript encoding vector to be used for embedding.
         * @return a PdfTrueTypeFont instance.
         * @throws IOException If there is an error loading the data.
         */
        public static PdfTrueTypeFont Load(Document doc, Bytes.IInputStream input, Encoding encoding)

        {
            return(new PdfTrueTypeFont(doc, new TTFParser().Parse(input), encoding, true));
        }