Exemple #1
0
 public static Object[] SplitDAelements(String da)
 {
     PRTokeniser tk = new PRTokeniser(PdfEncodings.ConvertToBytes(da, null));
     ArrayList stack = new ArrayList();
     Object[] ret = new Object[3];
     while (tk.NextToken()) {
         if (tk.TokenType == PRTokeniser.TK_COMMENT)
             continue;
         if (tk.TokenType == PRTokeniser.TK_OTHER) {
             String oper = tk.StringValue;
             if (oper.Equals("Tf")) {
                 if (stack.Count >= 2) {
                     ret[DA_FONT] = stack[stack.Count - 2];
                     ret[DA_SIZE] = float.Parse((String)stack[stack.Count - 1], NumberFormatInfo.InvariantInfo);
                 }
             }
             else if (oper.Equals("g")) {
                 if (stack.Count >= 1) {
                     float gray = float.Parse((String)stack[stack.Count - 1], NumberFormatInfo.InvariantInfo);
                     if (gray != 0)
                         ret[DA_COLOR] = new GrayColor(gray);
                 }
             }
             else if (oper.Equals("rg")) {
                 if (stack.Count >= 3) {
                     float red = float.Parse((String)stack[stack.Count - 3], NumberFormatInfo.InvariantInfo);
                     float green = float.Parse((String)stack[stack.Count - 2], NumberFormatInfo.InvariantInfo);
                     float blue = float.Parse((String)stack[stack.Count - 1], NumberFormatInfo.InvariantInfo);
                     ret[DA_COLOR] = new Color(red, green, blue);
                 }
             }
             else if (oper.Equals("k")) {
                 if (stack.Count >= 4) {
                     float cyan = float.Parse((String)stack[stack.Count - 4], NumberFormatInfo.InvariantInfo);
                     float magenta = float.Parse((String)stack[stack.Count - 3], NumberFormatInfo.InvariantInfo);
                     float yellow = float.Parse((String)stack[stack.Count - 2], NumberFormatInfo.InvariantInfo);
                     float black = float.Parse((String)stack[stack.Count - 1], NumberFormatInfo.InvariantInfo);
                     ret[DA_COLOR] = new CMYKColor(cyan, magenta, yellow, black);
                 }
             }
             stack.Clear();
         }
         else
             stack.Add(tk.StringValue);
     }
     return ret;
 }
Exemple #2
0
 /**
  * Creates a new instance of PdfContentParser
  * @param tokeniser the tokeniser with the content
  */
 public PdfContentParser(PRTokeniser tokeniser)
 {
     this.tokeniser = tokeniser;
 }
 /**
 * Creates a new instance of PdfContentParser
 * @param tokeniser the tokeniser with the content
 */
 public PdfContentParser(PRTokeniser tokeniser)
 {
     this.tokeniser = tokeniser;
 }
Exemple #4
0
 public static int[] CheckObjectStart(byte[] line)
 {
     try {
         PRTokeniser tk = new PRTokeniser(line);
         int num = 0;
         int gen = 0;
         if (!tk.NextToken() || tk.TokenType != TK_NUMBER)
             return null;
         num = tk.IntValue;
         if (!tk.NextToken() || tk.TokenType != TK_NUMBER)
             return null;
         gen = tk.IntValue;
         if (!tk.NextToken())
             return null;
         if (!tk.StringValue.Equals("obj"))
             return null;
         return new int[]{num, gen};
     }
     catch {
     }
     return null;
 }