File: Style.h

package info (click to toggle)
openjade 1.4devel1-13
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,020 kB
  • ctags: 11,087
  • sloc: cpp: 72,782; sh: 10,361; ansic: 2,365; lisp: 894; perl: 604; makefile: 436; sed: 93
file content (395 lines) | stat: -rw-r--r-- 10,519 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
// Copyright (c) 1996 James Clark
// See the file copying.txt for copying permission.

#ifndef Style_INCLUDED
#define Style_INCLUDED 1

#include <OpenSP/types.h>
#include <OpenSP/StringC.h>
#include <OpenSP/Named.h>
#include <stddef.h>
#include "ELObj.h"
#include <OpenSP/Vector.h>
#include <OpenSP/Ptr.h>
#include <OpenSP/Resource.h>
#include <OpenSP/Owner.h>
#include "Insn.h"
#include "FOTBuilder.h"
#include <OpenSP/Boolean.h>
#include "Node.h"
#include <OpenSP/Location.h>
#include "ProcessingMode.h"

#ifdef DSSSL_NAMESPACE
namespace DSSSL_NAMESPACE {
#endif

class StyleStack;
class Interpreter;
class VarStyleObj;

// InheritedC represents the specification of a value
// of an inherited characteristic.
// It is also used as a prototype for other specifications of
// values for that characteristic:
// the identifier for an inherited characteristic contains the
// InheritedC that specifies its initial value.

class InheritedC : public Resource {
public:
  InheritedC(const Identifier *ident, unsigned index);
  virtual ~InheritedC();
  virtual void set(VM &vm, const VarStyleObj *, FOTBuilder &,
                   ELObj *&, Vector<size_t> &dependencies) const = 0;
  virtual ELObj *value(VM &, const VarStyleObj *, Vector<size_t> &) const = 0;
  virtual ConstPtr<InheritedC> make(ELObj *, const Location &, Interpreter &) const = 0;
  unsigned index() const;
  const Identifier *identifier() const;
  void setIdentifier(const Identifier *);
protected:
  void invalidValue(const Location &, Interpreter &) const;
private:
  const Identifier *ident_;
  // The index of the inherited characteristic (not the specification).
  unsigned index_;
};

class VarInheritedC : public InheritedC {
public:
  VarInheritedC(const ConstPtr<InheritedC> &, const InsnPtr &code, const Location &);
  void set(VM &, const VarStyleObj *, FOTBuilder &, ELObj *&value,
           Vector<size_t> &dependencies) const;
  ELObj *value(VM &, const VarStyleObj *, Vector<size_t> &) const;
  virtual ConstPtr<InheritedC> make(ELObj *, const Location &, Interpreter &) const;
private:
  ConstPtr<InheritedC> inheritedC_;
  InsnPtr code_;
  Location loc_;
};

class StyleObjIter {
public:
  StyleObjIter();
  void append(const Vector<ConstPtr<InheritedC> > *, const VarStyleObj *);
  ConstPtr<InheritedC> next(const VarStyleObj *&);
private:
  size_t i_;
  size_t vi_;
  Vector<const VarStyleObj *> styleVec_;
  Vector<const Vector<ConstPtr<InheritedC> > *> vecs_;
};

class StyleObj : public ELObj {
public:
  StyleObj *asStyle();
  virtual void appendIter(StyleObjIter &) const = 0;
};

struct StyleSpec : public Resource {
  StyleSpec(Vector<ConstPtr<InheritedC> > &, Vector<ConstPtr<InheritedC> > &);
  Vector<ConstPtr<InheritedC> > forceSpecs;
  Vector<ConstPtr<InheritedC> > specs;
};

class BasicStyleObj : public StyleObj {
public:
  virtual void appendIterForce(StyleObjIter &) const = 0;
  virtual void appendIterNormal(StyleObjIter &) const = 0;
};

class VarStyleObj : public BasicStyleObj {
public:
  void *operator new(size_t, Collector &c) {
    return c.allocateObject(1);
  }
  VarStyleObj(const ConstPtr<StyleSpec> &, StyleObj *use, ELObj **display,
              const NodePtr &node);
  ~VarStyleObj();
  void appendIter(StyleObjIter &) const;
  void appendIterForce(StyleObjIter &) const;
  void appendIterNormal(StyleObjIter &) const;
  const NodePtr &node() const;
  ELObj **display() const;
  void traceSubObjects(Collector &) const;
private:
  ConstPtr<StyleSpec> styleSpec_;
  StyleObj *use_;
  ELObj **display_;
  NodePtr node_;
};

class OverriddenStyleObj : public StyleObj {
public:
  OverriddenStyleObj(BasicStyleObj *basic, StyleObj *override);
  void appendIter(StyleObjIter &) const;
  void traceSubObjects(Collector &) const;
private:
  BasicStyleObj *basic_;
  StyleObj *override_;
};

class MergeStyleObj : public StyleObj {
public:
  void *operator new(size_t, Collector &c) {
    return c.allocateObject(1);
  }
  MergeStyleObj();
  void append(StyleObj *);
  void appendIter(StyleObjIter &) const;
  void traceSubObjects(Collector &) const;
private:
  Vector<StyleObj *> styles_;
};

class ColorObj : public ELObj {
public:
  ColorObj *asColor();
  virtual void set(FOTBuilder &) const = 0;
  virtual void setBackground(FOTBuilder &) const = 0;
};

class DeviceRGBColorObj : public ColorObj {
public:
  DeviceRGBColorObj(unsigned char, unsigned char, unsigned char);
  void set(FOTBuilder &) const;
  void setBackground(FOTBuilder &) const;
private:
  FOTBuilder::DeviceRGBColor color_;
};

class ColorSpaceObj : public ELObj {
public:
  ColorSpaceObj *asColorSpace();
  virtual ELObj *makeColor(int argc, ELObj **argv, Interpreter &, const Location &) = 0;
};

class DeviceRGBColorSpaceObj : public ColorSpaceObj {
public:
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
};

class DeviceGrayColorSpaceObj : public ColorSpaceObj {
public:
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
};

class DeviceCMYKColorSpaceObj : public ColorSpaceObj {
public:
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
};

class DeviceKXColorSpaceObj : public ColorSpaceObj {
public:
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
};

class CIEXYZColorSpaceObj : public ColorSpaceObj {
public:
  CIEXYZColorSpaceObj(const double *, const double *);
  void *operator new(size_t, Collector &c) {
    return c.allocateObject(1);
  }
  ~CIEXYZColorSpaceObj();
  ELObj *makeColor(const double *, Interpreter &);
protected:
struct XYZData {
  double white_[3];
  double white_u;
  double white_v;
  double M_[9];
};
 XYZData *xyzData_; 
};

class CIELUVColorSpaceObj : public CIEXYZColorSpaceObj {
public:
  CIELUVColorSpaceObj(const double *, const double *, const double *);
  void *operator new(size_t, Collector &c) {
    return c.allocateObject(1);
  }
  ~CIELUVColorSpaceObj();
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
private:
struct LUVData {
  double range_[6]; 
};
  LUVData *luvData_;
};

class CIELABColorSpaceObj : public CIEXYZColorSpaceObj {
public:
  CIELABColorSpaceObj(const double *, const double *, const double *);
  void *operator new(size_t, Collector &c) {
    return c.allocateObject(1);
  }
  ~CIELABColorSpaceObj();
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
private:
struct LABData {
  double range_[6]; 
};
  LABData *labData_; 
};

class CIEABCColorSpaceObj : public CIEXYZColorSpaceObj {
public:
  CIEABCColorSpaceObj(const double *, const double *, const double *,
                      FunctionObj **, const double *, const double *,
                      FunctionObj **, const double *);
  void *operator new(size_t, Collector &c) {
    return c.allocateObject(1);
  }
  ~CIEABCColorSpaceObj();
  void traceSubObjects(Collector &) const;
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
private:
struct ABCData {
  double rangeAbc_[6]; 
  FunctionObj *decodeAbc_[3]; 
  double matrixAbc_[9]; 
  double rangeLmn_[6]; 
  FunctionObj *decodeLmn_[3]; 
  double matrixLmn_[9];
};
 ABCData *abcData_; 
};

class CIEAColorSpaceObj : public CIEXYZColorSpaceObj {
public:
  CIEAColorSpaceObj(const double *, const double *, const double *,
                    FunctionObj *, const double *, const double *,
                    FunctionObj **, const double *);
  void *operator new(size_t, Collector &c) {
    return c.allocateObject(1);
  }
  ~CIEAColorSpaceObj();
  void traceSubObjects(Collector &) const;
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
private:
struct AData {
  double rangeA_[2]; 
  FunctionObj *decodeA_; 
  double matrixA_[3]; 
  double rangeLmn_[6]; 
  FunctionObj *decodeLmn_[3]; 
  double matrixLmn_[9]; 
};
  AData *aData_;
};

struct InheritedCInfo : public Resource {
  InheritedCInfo(const ConstPtr<InheritedC> &, const VarStyleObj *,
		 unsigned valLevel, unsigned specLevel, const ProcessingMode::Rule *,
		 const Ptr<InheritedCInfo> &);
  ConstPtr<InheritedC> spec;
  Ptr<InheritedCInfo> prev;
  unsigned valLevel;
  unsigned specLevel;
  const ProcessingMode::Rule *rule;
  // If there are dependencies, then the cached value can only
  // be used only when the "value" flow object is at this level.
  ELObj *cachedValue;
  const VarStyleObj *style;
  // Includes both direct and indirect dependencies.
  Vector<size_t> dependencies;
};

struct PopList : public Resource {
  PopList(const Ptr<PopList> &);
  Vector<size_t> list;
  // List of the indices of those ICs that have dependencies
  // (ie that use actual-*) directly or indirectly.
  Vector<size_t> dependingList;
  Ptr<PopList> prev;
};

class StyleStack {
public:
  StyleStack();
  // These append on to dependencies.
  ELObj *actual(const ConstPtr<InheritedC> &, const Location &, Interpreter &,
		Vector<size_t> &dependencies);
  ELObj *actual(const ConstPtr<InheritedC> &, Interpreter &,
		Vector<size_t> &dependencies);
  ELObj *inherited(const ConstPtr<InheritedC> &, unsigned specLevel, Interpreter &,
		   Vector<size_t> &dependencies);
  void push(StyleObj *, VM &, FOTBuilder &);
  void pushStart();
  void pushContinue(StyleObj *, const ProcessingMode::Rule *, const NodePtr &,
		    Messenger *);
  void pushEnd(VM &, FOTBuilder &);
  void pop();
  void pushEmpty() { level_++; }
  void popEmpty() { level_--; }
  unsigned level() const { return level_; }
  void trace(Collector &) const;
private:
  Vector<Ptr<InheritedCInfo> > inheritedCInfo_;
  unsigned level_;
  Ptr<PopList> popList_;
};

inline
PopList::PopList(const Ptr<PopList> &p)
: prev(p)
{
}

inline
const Identifier *InheritedC::identifier() const
{
  return ident_;
}

inline
void InheritedC::setIdentifier(const Identifier *ident)
{
  ident_ = ident;
}

inline
unsigned InheritedC::index() const
{
  return index_;
}

inline
ELObj **VarStyleObj::display() const
{
  return display_;
}

inline
const NodePtr &VarStyleObj::node() const
{
  return node_;
}

inline
void StyleStack::pushStart()
{
  level_++;
  popList_ = new PopList(popList_);
}

inline
void StyleStack::push(StyleObj *style, VM &vm, FOTBuilder &fotb)
{
  pushStart();
  pushContinue(style, 0, NodePtr(), 0);
  pushEnd(vm, fotb);
}

inline
ELObj *StyleStack::actual(const ConstPtr<InheritedC> &ic,
			  Interpreter &interp,
			  Vector<size_t> &dep)
{
  return actual(ic, Location(), interp, dep);
}

#ifdef DSSSL_NAMESPACE
}
#endif

#endif /* not Style_INCLUDED */