示例#1
0
 private static void ExtractText(COperator obj, StringBuilder target)
 {
     if (obj.OpCode.OpCodeName == OpCodeName.Tj || obj.OpCode.OpCodeName == OpCodeName.TJ)
     {
         foreach (var element in obj.Operands)
         {
             ExtractText(element, target);
         }
         //target.Append(" ");
     }
 }
        /// <summary>
        /// Operators from name.
        /// </summary>
        /// <param name="name">The name.</param>
        public static COperator OperatorFromName(string name)
        {
            COperator op     = null;
            OpCode    opcode = StringToOpCode[name];

            if (opcode != null)
            {
                op = new COperator(opcode);
            }
            else
            {
                Debug.Assert(false, "Unknown operator in PDF content stream.");
            }
            return(op);
        }
示例#3
0
文件: CParser.cs 项目: Sl0vi/PDFsharp
        COperator CreateOperator(COperator op)
        {
            if (op.OpCode.OpCodeName == OpCodeName.BI)
            {
                _lexer.ScanInlineImage();
            }
#if DEBUG
            if (op.OpCode.Operands != -1 && op.OpCode.Operands != _operands.Count)
            {
                if (op.OpCode.OpCodeName != OpCodeName.ID)
                {
                    GetType();
                    Debug.Assert(false, "Invalid number of operands.");
                }
            }
#endif
            op.Operands.Add(_operands);
            _operands.Clear();
            return op;
        }
示例#4
0
 /// <summary>
 /// Operators from name.
 /// </summary>
 /// <param name="name">The name.</param>
 static public COperator OperatorFromName(string name)
 {
     COperator op = null;
     OpCode opcode = StringToOpCode[name];
     if (opcode != null)
     {
         op = new COperator(opcode);
     }
     else
     {
         Debug.Assert(false, "Unknown operator in PDF content stream.");
     }
     return op;
 }
示例#5
0
 private static void Write(COperator obj)
 {
     Console.Write("op:{0}(", obj.Name);
     foreach (var op in obj.Operands)
     {
         Write(op);
         Console.Write(", ");
     }
     Console.Write(")");
 }
示例#6
0
            private void ExtractText(COperator obj, StringBuilder target)
            {
                if (obj.OpCode.OpCodeName == OpCodeName.Tj || obj.OpCode.OpCodeName == OpCodeName.TJ)
                {
                    foreach (var element in obj.Operands)
                    {
                        ExtractText(element, target);
                    }
                    //target.Append(" ");
                }
                else if (obj.OpCode.OpCodeName == OpCodeName.Td || obj.OpCode.OpCodeName == OpCodeName.TD)
                {
                    target.Append("\n");
                }
                else if (obj.OpCode.OpCodeName == OpCodeName.Tm)
                {
                    double x=0;
                    if (obj.Operands[4] is CReal)
                    {
                        x = ((CReal)obj.Operands[4]).Value;
                    }
                    else if(obj.Operands[4] is CInteger)
                    {
                        x = (double)((CInteger)obj.Operands[4]).Value;
                    }
                    double y=0;
                    if (obj.Operands[5] is CReal)
                    {
                        y = ((CReal)obj.Operands[5]).Value;
                    }
                    else if (obj.Operands[5] is CInteger)
                    {
                        y = (double)((CInteger)obj.Operands[5]).Value;
                    }

                    diffX = x - lastX;

                    if (lastString != null)
                    {
                        target.Append(lastString);
                        if (lastString.Length == 1)
                        {
                            if ((lastString[0] >= 'A' && lastString[0] <= 'Z'))
                            {
                                if (lastString[0] == 'M')
                                {
                                    if (diffX > 11.3)
                                        target.Append(" ");
                                }
                                else
                                {
                                    if (diffX > 9.5)
                                        target.Append(" ");
                                }
                            }
                            else if ((lastString[0] >= 'a' && lastString[0] <= 'z'))
                            {
                                if (lastString[0] == 'm')
                                {
                                    if (diffX > 9.4)
                                    {
                                        target.Append(" ");
                                    }
                                }
                                else if (diffX > 7)
                                    target.Append(" ");
                            }
                            else if (diffX >8.1)
                                target.Append(" ");

                        }
                    }
                    diffY = lastY - y;
                    if (lastY != 0 && diffY > 13)
                    {
                        for (int i = 1; i < diffY / 13;i++ )
                            target.Append("\n");
                    }
                    lastX = x;
                    lastY = y;
                }
                else
                {

                }
            }