Esempio n. 1
0
        public CMap Parse(IInputBytes inputBytes)
        {
            var scanner = new CoreTokenScanner(inputBytes);

            var builder = new CharacterMapBuilder();

            IToken previousToken = null;

            while (scanner.MoveNext())
            {
                var token = scanner.CurrentToken;

                if (token is OperatorToken operatorToken)
                {
                    switch (operatorToken.Data)
                    {
                    case "usecmap":
                    {
                        if (previousToken is NameToken name && TryParseExternal(name.Data, out var external))
                        {
                            builder.UseCMap(external);
                        }
                        else
                        {
                            throw new InvalidOperationException("Unexpected token preceding external cmap call: " + previousToken);
                        }
                        break;
                    }
Esempio n. 2
0
        public CMap Parse(IInputBytes inputBytes, bool isLenientParsing)
        {
            var scanner = new CoreTokenScanner(inputBytes);

            var builder = new CharacterMapBuilder();

            IToken previousToken = null;

            while (scanner.MoveNext())
            {
                var token = scanner.CurrentToken;

                if (token is OperatorToken operatorToken)
                {
                    switch (operatorToken.Data)
                    {
                    case "usecmap":
                    {
                        if (previousToken is NameToken name)
                        {
                            var external = ParseExternal(name.Data);

                            builder.UseCMap(external);
                        }
                        else
                        {
                            throw new InvalidOperationException("Unexpected token preceding external cmap call: " + previousToken);
                        }
                        break;
                    }

                    case "begincodespacerange":
                    {
                        if (previousToken is NumericToken numeric)
                        {
                            CodespaceRangeParser.Parse(numeric, scanner, builder, isLenientParsing);
                        }
                        else
                        {
                            throw new InvalidOperationException("Unexpected token preceding start of codespace range: " + previousToken);
                        }
                    }
                    break;

                    case "beginbfchar":
                    {
                        if (previousToken is NumericToken numeric)
                        {
                            BaseFontCharacterParser.Parse(numeric, scanner, builder, isLenientParsing);
                        }
                        else
                        {
                            throw new InvalidOperationException("Unexpected token preceding start of base font characters: " + previousToken);
                        }
                    }
                    break;

                    case "beginbfrange":
                    {
                        if (previousToken is NumericToken numeric)
                        {
                            BaseFontRangeParser.Parse(numeric, scanner, builder, isLenientParsing);
                        }
                        else
                        {
                            throw new InvalidOperationException("Unexpected token preceding start of base font character ranges: " + previousToken);
                        }
                    }
                    break;

                    case "begincidchar":
                    {
                        if (previousToken is NumericToken numeric)
                        {
                            CidCharacterParser.Parse(numeric, scanner, builder, isLenientParsing);
                        }
                        else
                        {
                            throw new InvalidOperationException("Unexpected token preceding start of Cid character mapping: " + previousToken);
                        }
                        break;
                    }

                    case "begincidrange":
                    {
                        if (previousToken is NumericToken numeric)
                        {
                            CidRangeParser.Parse(numeric, scanner, builder, isLenientParsing);
                        }
                        else
                        {
                            throw new InvalidOperationException("Unexpected token preceding start of Cid ranges: " + previousToken);
                        }
                    }
                    break;
                    }
                }
                else if (token is NameToken name)
                {
                    CidFontNameParser.Parse(name, scanner, builder, isLenientParsing);
                }

                previousToken = token;
            }

            return(builder.Build());
        }