Exemple #1
0
        /**
         * This will parse the stream and create a cmap object.
         *
         * @param input The CMAP stream to parse.
         * @return The parsed stream as a java object.
         *
         * @throws IOException If there is an error parsing the stream.
         */
        public CMap Parse(Stream input)
        {
            PushbackStream cmapStream = new PushbackStream(input);
            CMap           result     = new CMap();
            Object         token      = null;

            while ((token = ParseNextToken(cmapStream)) != null)
            {
                if (token is Operator)
                {
                    Operator op = (Operator)token;
                    if (op.op.Equals(BEGIN_CODESPACE_RANGE))
                    {
                        while (true)
                        {
                            Object nx = ParseNextToken(cmapStream);
                            if (nx is Operator && ((Operator)nx).op.Equals("endcodespacerange"))
                            {
                                break;
                            }
                            byte[]         startRange = (byte[])nx;
                            byte[]         endRange   = (byte[])ParseNextToken(cmapStream);
                            CodespaceRange range      = new CodespaceRange();
                            range.SetStart(startRange);
                            range.SetEnd(endRange);
                            result.AddCodespaceRange(range);
                        }
                    }
                    else if (op.op.Equals(BEGIN_BASE_FONT_CHAR))
                    {
                        while (true)
                        {
                            Object nx = ParseNextToken(cmapStream);
                            if (nx is Operator && ((Operator)nx).op.Equals("endbfchar"))
                            {
                                break;
                            }
                            byte[] inputCode = (byte[])nx;
                            Object nextToken = ParseNextToken(cmapStream);
                            if (nextToken is byte[])
                            {
                                byte[] bytes = (byte[])nextToken;
                                String value = CreateStringFromBytes(bytes);
                                result.AddMapping(inputCode, value);
                            }
                            else if (nextToken is LiteralName)
                            {
                                result.AddMapping(inputCode, ((LiteralName)nextToken).name);
                            }
                            else
                            {
                                throw new IOException(MessageLocalization.GetComposedMessage("error.parsing.cmap.beginbfchar.expected.cosstring.or.cosname.and.not.1", nextToken));
                            }
                        }
                    }
                    else if (op.op.Equals(BEGIN_BASE_FONT_RANGE))
                    {
                        while (true)
                        {
                            Object nx = ParseNextToken(cmapStream);
                            if (nx is Operator && ((Operator)nx).op.Equals("endbfrange"))
                            {
                                break;
                            }
                            byte[]         startCode  = (byte[])nx;
                            byte[]         endCode    = (byte[])ParseNextToken(cmapStream);
                            Object         nextToken  = ParseNextToken(cmapStream);
                            IList <byte[]> array      = null;
                            byte[]         tokenBytes = null;
                            if (nextToken is IList <byte[]> )
                            {
                                array      = (IList <byte[]>)nextToken;
                                tokenBytes = array[0];
                            }
                            else
                            {
                                tokenBytes = (byte[])nextToken;
                            }

                            String value = null;

                            int  arrayIndex = 0;
                            bool done       = false;
                            while (!done)
                            {
                                if (Compare(startCode, endCode) >= 0)
                                {
                                    done = true;
                                }
                                value = CreateStringFromBytes(tokenBytes);
                                result.AddMapping(startCode, value);
                                Increment(startCode);

                                if (array == null)
                                {
                                    Increment(tokenBytes);
                                }
                                else
                                {
                                    arrayIndex++;
                                    if (arrayIndex < array.Count)
                                    {
                                        tokenBytes = array[arrayIndex];
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Exemple #2
0
 /**
  * This will add a codespace range.
  *
  * @param range A single codespace range.
  */
 public void AddCodespaceRange(CodespaceRange range)
 {
     codeSpaceRanges.Add(range);
 }