Ejemplo n.º 1
0
        public void CanReadBinaryEncryptedPortionOfFullPfb()
        {
            // TODO: support reading in these pfb files
            var bytes = GetFileBytes("Raleway-Black.pfb");

            Type1FontParser.Parse(new ByteArrayInputBytes(bytes), 0, 0);
        }
Ejemplo n.º 2
0
 public Type1FontHandler(IPdfTokenScanner pdfScanner, CMapCache cMapCache, IFilterProvider filterProvider,
                         FontDescriptorFactory fontDescriptorFactory,
                         IEncodingReader encodingReader,
                         Type1FontParser type1FontParser)
 {
     this.pdfScanner            = pdfScanner;
     this.cMapCache             = cMapCache;
     this.filterProvider        = filterProvider;
     this.fontDescriptorFactory = fontDescriptorFactory;
     this.encodingReader        = encodingReader;
     this.type1FontParser       = type1FontParser;
 }
Ejemplo n.º 3
0
        private Union <Type1Font, CompactFontFormatFontCollection> ParseFontProgram(FontDescriptor descriptor, bool isLenientParsing)
        {
            if (descriptor?.FontFile == null)
            {
                return(null);
            }

            if (descriptor.FontFile.ObjectKey.Data.ObjectNumber == 0)
            {
                return(null);
            }

            try
            {
                if (!(pdfScanner.Get(descriptor.FontFile.ObjectKey.Data).Data is StreamToken stream))
                {
                    return(null);
                }

                var bytes = stream.Decode(filterProvider);

                // We have a Compact Font Format font rather than an Adobe Type 1 Font.
                if (stream.StreamDictionary.TryGet(NameToken.Subtype, out NameToken subTypeName) &&
                    NameToken.Type1C.Equals(subTypeName))
                {
                    var cffFont = CompactFontFormatParser.Parse(new CompactFontFormatData(bytes));
                    return(Union <Type1Font, CompactFontFormatFontCollection> .Two(cffFont));
                }

                var length1 = stream.StreamDictionary.Get <NumericToken>(NameToken.Length1, pdfScanner);
                var length2 = stream.StreamDictionary.Get <NumericToken>(NameToken.Length2, pdfScanner);

                var font = Type1FontParser.Parse(new ByteArrayInputBytes(bytes), length1.Int, length2.Int);

                return(Union <Type1Font, CompactFontFormatFontCollection> .One(font));
            }
            catch
            {
                if (!isLenientParsing)
                {
                    throw;
                }
            }

            return(null);
        }
Ejemplo n.º 4
0
        public void OutputCmbx10Svgs()
        {
            var bytes = GetFileBytes("CMBX10");

            var result = Type1FontParser.Parse(new ByteArrayInputBytes(bytes), 0, 0);

            var builder = new StringBuilder("<!DOCTYPE html><html><head></head><body>");

            foreach (var charString in result.CharStrings.CharStrings)
            {
                Assert.True(result.CharStrings.TryGenerate(charString.Key, out var path));
                builder.AppendLine(path.ToFullSvg());
            }

            builder.Append("</body></html>");

            File.WriteAllText("cmbx10.html", builder.ToString());
        }
Ejemplo n.º 5
0
        public void CanReadFontWithCommentsInOtherSubrs()
        {
            var bytes = GetFileBytes("CMR10");

            Type1FontParser.Parse(new ByteArrayInputBytes(bytes), 0, 0);
        }
Ejemplo n.º 6
0
        public void CanReadAsciiPart()
        {
            var bytes = GetFileBytes("CMBX12");

            Type1FontParser.Parse(new ByteArrayInputBytes(bytes), 0, 0);
        }
Ejemplo n.º 7
0
        public void CanReadEncryptedPortion()
        {
            var bytes = GetFileBytes("CMCSC10");

            Type1FontParser.Parse(new ByteArrayInputBytes(bytes), 0, 0);
        }
Ejemplo n.º 8
0
        public void CanReadCharStrings()
        {
            var bytes = GetFileBytes("CMBX10.pfa");

            Type1FontParser.Parse(new ByteArrayInputBytes(bytes), 0, 0);
        }
Ejemplo n.º 9
0
        public void CanReadHexEncryptedPortion()
        {
            var bytes = GetFileBytes("AdobeUtopia.pfa");

            Type1FontParser.Parse(new ByteArrayInputBytes(bytes), 0, 0);
        }