UNPKG

6.49 kBtext/x-cView Raw
1/*
2 Source File : AbstractContentContextDriver.h
3
4
5 Copyright 2013 Gal Kahana HummusJS
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18
19 */
20#pragma once
21
22#include "nodes.h"
23
24#include "GlyphUnicodeMapping.h"
25#include "ObjectsBasicTypes.h"
26#include <string>
27
28class AbstractContentContext;
29class ResourcesDictionary;
30class PDFWriterDriver;
31class ConstructorsHolder;
32
33struct TextPlacingOptions
34{
35 TextPlacingOptions()
36 {
37 encoding = EEncodingText;
38 }
39
40 enum EEncoding
41 {
42 EEncodingText,
43 EEncodingCode,
44 EEncodingHex
45 };
46
47 EEncoding encoding;
48};
49
50class AbstractContentContextDriver : public node::ObjectWrap
51{
52public:
53
54
55 static void Init(v8::Local<v8::FunctionTemplate>& ioDriverTemplate);
56
57
58 void SetResourcesDictionary(ResourcesDictionary* inResourcesDictionary);
59
60 ConstructorsHolder* holder;
61protected:
62 AbstractContentContextDriver();
63
64private:
65
66 virtual AbstractContentContext* GetContext() = 0;
67
68 ResourcesDictionary* mResourcesDictionary;
69
70 // simple content placements
71 static METHOD_RETURN_TYPE DrawPath(const ARGS_TYPE& args);
72 static METHOD_RETURN_TYPE DrawCircle(const ARGS_TYPE& args);
73 static METHOD_RETURN_TYPE DrawSquare(const ARGS_TYPE& args);
74 static METHOD_RETURN_TYPE DrawRectangle(const ARGS_TYPE& args);
75 static METHOD_RETURN_TYPE WriteText(const ARGS_TYPE& args);
76 static METHOD_RETURN_TYPE DrawImage(const ARGS_TYPE& args);
77
78 // now for regular PDF operators implementation
79
80
81 // path stroke/fill
82 static METHOD_RETURN_TYPE b(const ARGS_TYPE& args);
83 static METHOD_RETURN_TYPE B(const ARGS_TYPE& args);
84 static METHOD_RETURN_TYPE bStar(const ARGS_TYPE& args);
85 static METHOD_RETURN_TYPE BStar(const ARGS_TYPE& args);
86 static METHOD_RETURN_TYPE s(const ARGS_TYPE& args);
87 static METHOD_RETURN_TYPE S(const ARGS_TYPE& args);
88 static METHOD_RETURN_TYPE f(const ARGS_TYPE& args);
89 static METHOD_RETURN_TYPE F(const ARGS_TYPE& args);
90 static METHOD_RETURN_TYPE fStar(const ARGS_TYPE& args);
91 static METHOD_RETURN_TYPE n(const ARGS_TYPE& args);
92
93 // path construction
94 static METHOD_RETURN_TYPE m(const ARGS_TYPE& args);
95 static METHOD_RETURN_TYPE l(const ARGS_TYPE& args);
96 static METHOD_RETURN_TYPE c(const ARGS_TYPE& args);
97 static METHOD_RETURN_TYPE v(const ARGS_TYPE& args);
98 static METHOD_RETURN_TYPE y(const ARGS_TYPE& args);
99 static METHOD_RETURN_TYPE h(const ARGS_TYPE& args);
100 static METHOD_RETURN_TYPE re(const ARGS_TYPE& args);
101
102 // graphic state
103 static METHOD_RETURN_TYPE q(const ARGS_TYPE& args);
104 static METHOD_RETURN_TYPE Q(const ARGS_TYPE& args);
105 static METHOD_RETURN_TYPE cm(const ARGS_TYPE& args);
106 static METHOD_RETURN_TYPE w(const ARGS_TYPE& args);
107 static METHOD_RETURN_TYPE J(const ARGS_TYPE& args);
108 static METHOD_RETURN_TYPE j(const ARGS_TYPE& args);
109 static METHOD_RETURN_TYPE M(const ARGS_TYPE& args);
110 static METHOD_RETURN_TYPE d(const ARGS_TYPE& args);
111 static METHOD_RETURN_TYPE ri(const ARGS_TYPE& args);
112 static METHOD_RETURN_TYPE i(const ARGS_TYPE& args);
113 static METHOD_RETURN_TYPE gs(const ARGS_TYPE& args);
114
115 // color operators
116 static METHOD_RETURN_TYPE CS(const ARGS_TYPE& args);
117 static METHOD_RETURN_TYPE cs(const ARGS_TYPE& args);
118 static METHOD_RETURN_TYPE SC(const ARGS_TYPE& args);
119 static METHOD_RETURN_TYPE SCN(const ARGS_TYPE& args);
120 static METHOD_RETURN_TYPE sc(const ARGS_TYPE& args);
121 static METHOD_RETURN_TYPE scn(const ARGS_TYPE& args);
122 static METHOD_RETURN_TYPE G(const ARGS_TYPE& args);
123 static METHOD_RETURN_TYPE g(const ARGS_TYPE& args);
124 static METHOD_RETURN_TYPE RG(const ARGS_TYPE& args);
125 static METHOD_RETURN_TYPE rg(const ARGS_TYPE& args);
126 static METHOD_RETURN_TYPE K(const ARGS_TYPE& args);
127 static METHOD_RETURN_TYPE k(const ARGS_TYPE& args);
128
129 // clip operators
130 static METHOD_RETURN_TYPE W(const ARGS_TYPE& args);
131 static METHOD_RETURN_TYPE WStar(const ARGS_TYPE& args);
132
133 // XObject usage
134 static METHOD_RETURN_TYPE doXObject(const ARGS_TYPE& args);
135
136 // Text state operators
137 static METHOD_RETURN_TYPE Tc(const ARGS_TYPE& args);
138 static METHOD_RETURN_TYPE Tw(const ARGS_TYPE& args);
139 static METHOD_RETURN_TYPE Tz(const ARGS_TYPE& args);
140 static METHOD_RETURN_TYPE TL(const ARGS_TYPE& args);
141 static METHOD_RETURN_TYPE Tr(const ARGS_TYPE& args);
142 static METHOD_RETURN_TYPE Ts(const ARGS_TYPE& args);
143
144 // Text object operators
145 static METHOD_RETURN_TYPE BT(const ARGS_TYPE& args);
146 static METHOD_RETURN_TYPE ET(const ARGS_TYPE& args);
147
148 // Text positioning operators
149 static METHOD_RETURN_TYPE Td(const ARGS_TYPE& args);
150 static METHOD_RETURN_TYPE TD(const ARGS_TYPE& args);
151 static METHOD_RETURN_TYPE Tm(const ARGS_TYPE& args);
152 static METHOD_RETURN_TYPE TStar(const ARGS_TYPE& args);
153
154 // Font setting
155 static METHOD_RETURN_TYPE Tf(const ARGS_TYPE& args);
156
157 // Text showing
158 static METHOD_RETURN_TYPE Tj(const ARGS_TYPE& args);
159 static METHOD_RETURN_TYPE Quote(const ARGS_TYPE& args);
160 static METHOD_RETURN_TYPE DoubleQuote(const ARGS_TYPE& args);
161 static METHOD_RETURN_TYPE TJ(const ARGS_TYPE& args);
162
163 // Others
164 static METHOD_RETURN_TYPE WriteFreeCode(const ARGS_TYPE& args);
165
166
167 static TextPlacingOptions ObjectToOptions(const v8::Local<v8::Object>& inObject);
168 static GlyphUnicodeMappingList ArrayToGlyphsList(const v8::Local<v8::Value>& inArray);
169
170 void SetupColorAndLineWidth(const v8::Local<v8::Value>& inMaybeOptions);
171 void SetColor(const v8::Local<v8::Value>& inMaybeOptions, bool inIsStroke);
172 void FinishPath(const v8::Local<v8::Value>& inMaybeOptions);
173 void SetFont(const v8::Local<v8::Value>& inMaybeOptions);
174 void SetRGBColor(unsigned long inColorValue,bool inIsStroke);
175
176};