• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FPDFAPI_PAGE_CPDF_PSENGINE_H_
8 #define CORE_FPDFAPI_PAGE_CPDF_PSENGINE_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fxcrt/fx_system.h"
14 
15 class CPDF_PSEngine;
16 class CPDF_PSOP;
17 class CPDF_SimpleParser;
18 
19 enum PDF_PSOP {
20   PSOP_ADD,
21   PSOP_SUB,
22   PSOP_MUL,
23   PSOP_DIV,
24   PSOP_IDIV,
25   PSOP_MOD,
26   PSOP_NEG,
27   PSOP_ABS,
28   PSOP_CEILING,
29   PSOP_FLOOR,
30   PSOP_ROUND,
31   PSOP_TRUNCATE,
32   PSOP_SQRT,
33   PSOP_SIN,
34   PSOP_COS,
35   PSOP_ATAN,
36   PSOP_EXP,
37   PSOP_LN,
38   PSOP_LOG,
39   PSOP_CVI,
40   PSOP_CVR,
41   PSOP_EQ,
42   PSOP_NE,
43   PSOP_GT,
44   PSOP_GE,
45   PSOP_LT,
46   PSOP_LE,
47   PSOP_AND,
48   PSOP_OR,
49   PSOP_XOR,
50   PSOP_NOT,
51   PSOP_BITSHIFT,
52   PSOP_TRUE,
53   PSOP_FALSE,
54   PSOP_IF,
55   PSOP_IFELSE,
56   PSOP_POP,
57   PSOP_EXCH,
58   PSOP_DUP,
59   PSOP_COPY,
60   PSOP_INDEX,
61   PSOP_ROLL,
62   PSOP_PROC,
63   PSOP_CONST
64 };
65 
66 constexpr uint32_t PSENGINE_STACKSIZE = 100;
67 
68 class CPDF_PSProc {
69  public:
70   CPDF_PSProc();
71   ~CPDF_PSProc();
72 
73   bool Parse(CPDF_SimpleParser* parser, int depth);
74   bool Execute(CPDF_PSEngine* pEngine);
75 
76  private:
77   static const int kMaxDepth = 128;
78   std::vector<std::unique_ptr<CPDF_PSOP>> m_Operators;
79 };
80 
81 class CPDF_PSEngine {
82  public:
83   CPDF_PSEngine();
84   ~CPDF_PSEngine();
85 
86   bool Parse(const FX_CHAR* str, int size);
87   bool Execute();
88   bool DoOperator(PDF_PSOP op);
Reset()89   void Reset() { m_StackCount = 0; }
90   void Push(FX_FLOAT value);
91   FX_FLOAT Pop();
GetStackSize()92   uint32_t GetStackSize() const { return m_StackCount; }
93 
94  private:
95   FX_FLOAT m_Stack[PSENGINE_STACKSIZE];
96   uint32_t m_StackCount;
97   CPDF_PSProc m_MainProc;
98 };
99 
100 #endif  // CORE_FPDFAPI_PAGE_CPDF_PSENGINE_H_
101