~ubuntu-branches/ubuntu/trusty/openjade1.3/trusty

« back to all changes in this revision

Viewing changes to style/Style.h

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2002-04-09 00:01:50 UTC
  • Revision ID: james.westby@ubuntu.com-20020409000150-r9rkyalxlhvf9ba3
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 1996 James Clark
 
2
// See the file copying.txt for copying permission.
 
3
 
 
4
#ifndef Style_INCLUDED
 
5
#define Style_INCLUDED 1
 
6
 
 
7
#include "types.h"
 
8
#include "StringC.h"
 
9
#include "Named.h"
 
10
#include <stddef.h>
 
11
#include "ELObj.h"
 
12
#include "Vector.h"
 
13
#include "Ptr.h"
 
14
#include "Resource.h"
 
15
#include "Owner.h"
 
16
#include "Insn.h"
 
17
#include "FOTBuilder.h"
 
18
#include "Boolean.h"
 
19
#include "Node.h"
 
20
#include "Location.h"
 
21
#include "ProcessingMode.h"
 
22
 
 
23
#ifdef DSSSL_NAMESPACE
 
24
namespace DSSSL_NAMESPACE {
 
25
#endif
 
26
 
 
27
class StyleStack;
 
28
class Interpreter;
 
29
class VarStyleObj;
 
30
 
 
31
// InheritedC represents the specification of a value
 
32
// of an inherited characteristic.
 
33
// It is also used as a prototype for other specifications of
 
34
// values for that characteristic:
 
35
// the identifier for an inherited characteristic contains the
 
36
// InheritedC that specifies its initial value.
 
37
 
 
38
class InheritedC : public Resource {
 
39
public:
 
40
  InheritedC(const Identifier *ident, unsigned index);
 
41
  virtual ~InheritedC();
 
42
  virtual void set(VM &vm, const VarStyleObj *, FOTBuilder &,
 
43
                   ELObj *&, Vector<size_t> &dependencies) const = 0;
 
44
  virtual ELObj *value(VM &, const VarStyleObj *, Vector<size_t> &) const = 0;
 
45
  virtual ConstPtr<InheritedC> make(ELObj *, const Location &, Interpreter &) const = 0;
 
46
  unsigned index() const;
 
47
  const Identifier *identifier() const;
 
48
  void setIdentifier(const Identifier *);
 
49
protected:
 
50
  void invalidValue(const Location &, Interpreter &) const;
 
51
private:
 
52
  const Identifier *ident_;
 
53
  // The index of the inherited characteristic (not the specification).
 
54
  unsigned index_;
 
55
};
 
56
 
 
57
class VarInheritedC : public InheritedC {
 
58
public:
 
59
  VarInheritedC(const ConstPtr<InheritedC> &, const InsnPtr &code, const Location &);
 
60
  void set(VM &, const VarStyleObj *, FOTBuilder &, ELObj *&value,
 
61
           Vector<size_t> &dependencies) const;
 
62
  ELObj *value(VM &, const VarStyleObj *, Vector<size_t> &) const;
 
63
  virtual ConstPtr<InheritedC> make(ELObj *, const Location &, Interpreter &) const;
 
64
private:
 
65
  ConstPtr<InheritedC> inheritedC_;
 
66
  InsnPtr code_;
 
67
  Location loc_;
 
68
};
 
69
 
 
70
class StyleObjIter {
 
71
public:
 
72
  StyleObjIter();
 
73
  void append(const Vector<ConstPtr<InheritedC> > *, const VarStyleObj *);
 
74
  ConstPtr<InheritedC> next(const VarStyleObj *&);
 
75
private:
 
76
  size_t i_;
 
77
  size_t vi_;
 
78
  Vector<const VarStyleObj *> styleVec_;
 
79
  Vector<const Vector<ConstPtr<InheritedC> > *> vecs_;
 
80
};
 
81
 
 
82
class StyleObj : public ELObj {
 
83
public:
 
84
  StyleObj *asStyle();
 
85
  virtual void appendIter(StyleObjIter &) const = 0;
 
86
};
 
87
 
 
88
struct StyleSpec : public Resource {
 
89
  StyleSpec(Vector<ConstPtr<InheritedC> > &, Vector<ConstPtr<InheritedC> > &);
 
90
  Vector<ConstPtr<InheritedC> > forceSpecs;
 
91
  Vector<ConstPtr<InheritedC> > specs;
 
92
};
 
93
 
 
94
class BasicStyleObj : public StyleObj {
 
95
public:
 
96
  virtual void appendIterForce(StyleObjIter &) const = 0;
 
97
  virtual void appendIterNormal(StyleObjIter &) const = 0;
 
98
};
 
99
 
 
100
class VarStyleObj : public BasicStyleObj {
 
101
public:
 
102
  void *operator new(size_t, Collector &c) {
 
103
    return c.allocateObject(1);
 
104
  }
 
105
  VarStyleObj(const ConstPtr<StyleSpec> &, StyleObj *use, ELObj **display,
 
106
              const NodePtr &node);
 
107
  ~VarStyleObj();
 
108
  void appendIter(StyleObjIter &) const;
 
109
  void appendIterForce(StyleObjIter &) const;
 
110
  void appendIterNormal(StyleObjIter &) const;
 
111
  const NodePtr &node() const;
 
112
  ELObj **display() const;
 
113
  void traceSubObjects(Collector &) const;
 
114
private:
 
115
  ConstPtr<StyleSpec> styleSpec_;
 
116
  StyleObj *use_;
 
117
  ELObj **display_;
 
118
  NodePtr node_;
 
119
};
 
120
 
 
121
class OverriddenStyleObj : public StyleObj {
 
122
public:
 
123
  OverriddenStyleObj(BasicStyleObj *basic, StyleObj *override);
 
124
  void appendIter(StyleObjIter &) const;
 
125
  void traceSubObjects(Collector &) const;
 
126
private:
 
127
  BasicStyleObj *basic_;
 
128
  StyleObj *override_;
 
129
};
 
130
 
 
131
class MergeStyleObj : public StyleObj {
 
132
public:
 
133
  void *operator new(size_t, Collector &c) {
 
134
    return c.allocateObject(1);
 
135
  }
 
136
  MergeStyleObj();
 
137
  void append(StyleObj *);
 
138
  void appendIter(StyleObjIter &) const;
 
139
  void traceSubObjects(Collector &) const;
 
140
private:
 
141
  Vector<StyleObj *> styles_;
 
142
};
 
143
 
 
144
class ColorObj : public ELObj {
 
145
public:
 
146
  ColorObj *asColor();
 
147
  virtual void set(FOTBuilder &) const = 0;
 
148
  virtual void setBackground(FOTBuilder &) const = 0;
 
149
};
 
150
 
 
151
class DeviceRGBColorObj : public ColorObj {
 
152
public:
 
153
  DeviceRGBColorObj(unsigned char, unsigned char, unsigned char);
 
154
  void set(FOTBuilder &) const;
 
155
  void setBackground(FOTBuilder &) const;
 
156
private:
 
157
  FOTBuilder::DeviceRGBColor color_;
 
158
};
 
159
 
 
160
class ColorSpaceObj : public ELObj {
 
161
public:
 
162
  ColorSpaceObj *asColorSpace();
 
163
  virtual ELObj *makeColor(int argc, ELObj **argv, Interpreter &, const Location &) = 0;
 
164
};
 
165
 
 
166
class DeviceRGBColorSpaceObj : public ColorSpaceObj {
 
167
public:
 
168
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
 
169
};
 
170
 
 
171
class DeviceGrayColorSpaceObj : public ColorSpaceObj {
 
172
public:
 
173
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
 
174
};
 
175
 
 
176
class DeviceCMYKColorSpaceObj : public ColorSpaceObj {
 
177
public:
 
178
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
 
179
};
 
180
 
 
181
class DeviceKXColorSpaceObj : public ColorSpaceObj {
 
182
public:
 
183
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
 
184
};
 
185
 
 
186
class CIEXYZColorSpaceObj : public ColorSpaceObj {
 
187
public:
 
188
  CIEXYZColorSpaceObj(const double *, const double *);
 
189
  void *operator new(size_t, Collector &c) {
 
190
    return c.allocateObject(1);
 
191
  }
 
192
  ~CIEXYZColorSpaceObj();
 
193
  ELObj *makeColor(const double *, Interpreter &);
 
194
protected:
 
195
struct XYZData {
 
196
  double white_[3];
 
197
  double white_u;
 
198
  double white_v;
 
199
  double M_[9];
 
200
};
 
201
 XYZData *xyzData_; 
 
202
};
 
203
 
 
204
class CIELUVColorSpaceObj : public CIEXYZColorSpaceObj {
 
205
public:
 
206
  CIELUVColorSpaceObj(const double *, const double *, const double *);
 
207
  void *operator new(size_t, Collector &c) {
 
208
    return c.allocateObject(1);
 
209
  }
 
210
  ~CIELUVColorSpaceObj();
 
211
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
 
212
private:
 
213
struct LUVData {
 
214
  double range_[6]; 
 
215
};
 
216
  LUVData *luvData_;
 
217
};
 
218
 
 
219
class CIELABColorSpaceObj : public CIEXYZColorSpaceObj {
 
220
public:
 
221
  CIELABColorSpaceObj(const double *, const double *, const double *);
 
222
  void *operator new(size_t, Collector &c) {
 
223
    return c.allocateObject(1);
 
224
  }
 
225
  ~CIELABColorSpaceObj();
 
226
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
 
227
private:
 
228
struct LABData {
 
229
  double range_[6]; 
 
230
};
 
231
  LABData *labData_; 
 
232
};
 
233
 
 
234
class CIEABCColorSpaceObj : public CIEXYZColorSpaceObj {
 
235
public:
 
236
  CIEABCColorSpaceObj(const double *, const double *, const double *,
 
237
                      FunctionObj **, const double *, const double *,
 
238
                      FunctionObj **, const double *);
 
239
  void *operator new(size_t, Collector &c) {
 
240
    return c.allocateObject(1);
 
241
  }
 
242
  ~CIEABCColorSpaceObj();
 
243
  void traceSubObjects(Collector &) const;
 
244
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
 
245
private:
 
246
struct ABCData {
 
247
  double rangeAbc_[6]; 
 
248
  FunctionObj *decodeAbc_[3]; 
 
249
  double matrixAbc_[9]; 
 
250
  double rangeLmn_[6]; 
 
251
  FunctionObj *decodeLmn_[3]; 
 
252
  double matrixLmn_[9];
 
253
};
 
254
 ABCData *abcData_; 
 
255
};
 
256
 
 
257
class CIEAColorSpaceObj : public CIEXYZColorSpaceObj {
 
258
public:
 
259
  CIEAColorSpaceObj(const double *, const double *, const double *,
 
260
                    FunctionObj *, const double *, const double *,
 
261
                    FunctionObj **, const double *);
 
262
  void *operator new(size_t, Collector &c) {
 
263
    return c.allocateObject(1);
 
264
  }
 
265
  ~CIEAColorSpaceObj();
 
266
  void traceSubObjects(Collector &) const;
 
267
  ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
 
268
private:
 
269
struct AData {
 
270
  double rangeA_[2]; 
 
271
  FunctionObj *decodeA_; 
 
272
  double matrixA_[3]; 
 
273
  double rangeLmn_[6]; 
 
274
  FunctionObj *decodeLmn_[3]; 
 
275
  double matrixLmn_[9]; 
 
276
};
 
277
  AData *aData_;
 
278
};
 
279
 
 
280
struct InheritedCInfo : public Resource {
 
281
  InheritedCInfo(const ConstPtr<InheritedC> &, const VarStyleObj *,
 
282
                 unsigned valLevel, unsigned specLevel, const ProcessingMode::Rule *,
 
283
                 const Ptr<InheritedCInfo> &);
 
284
  ConstPtr<InheritedC> spec;
 
285
  Ptr<InheritedCInfo> prev;
 
286
  unsigned valLevel;
 
287
  unsigned specLevel;
 
288
  const ProcessingMode::Rule *rule;
 
289
  // If there are dependencies, then the cached value can only
 
290
  // be used only when the "value" flow object is at this level.
 
291
  ELObj *cachedValue;
 
292
  const VarStyleObj *style;
 
293
  // Includes both direct and indirect dependencies.
 
294
  Vector<size_t> dependencies;
 
295
};
 
296
 
 
297
struct PopList : public Resource {
 
298
  PopList(const Ptr<PopList> &);
 
299
  Vector<size_t> list;
 
300
  // List of the indices of those ICs that have dependencies
 
301
  // (ie that use actual-*) directly or indirectly.
 
302
  Vector<size_t> dependingList;
 
303
  Ptr<PopList> prev;
 
304
};
 
305
 
 
306
class StyleStack {
 
307
public:
 
308
  StyleStack();
 
309
  // These append on to dependencies.
 
310
  ELObj *actual(const ConstPtr<InheritedC> &, const Location &, Interpreter &,
 
311
                Vector<size_t> &dependencies);
 
312
  ELObj *actual(const ConstPtr<InheritedC> &, Interpreter &,
 
313
                Vector<size_t> &dependencies);
 
314
  ELObj *inherited(const ConstPtr<InheritedC> &, unsigned specLevel, Interpreter &,
 
315
                   Vector<size_t> &dependencies);
 
316
  void push(StyleObj *, VM &, FOTBuilder &);
 
317
  void pushStart();
 
318
  void pushContinue(StyleObj *, const ProcessingMode::Rule *, const NodePtr &,
 
319
                    Messenger *);
 
320
  void pushEnd(VM &, FOTBuilder &);
 
321
  void pop();
 
322
  void pushEmpty() { level_++; }
 
323
  void popEmpty() { level_--; }
 
324
  unsigned level() const { return level_; }
 
325
  void trace(Collector &) const;
 
326
private:
 
327
  Vector<Ptr<InheritedCInfo> > inheritedCInfo_;
 
328
  unsigned level_;
 
329
  Ptr<PopList> popList_;
 
330
};
 
331
 
 
332
inline
 
333
PopList::PopList(const Ptr<PopList> &p)
 
334
: prev(p)
 
335
{
 
336
}
 
337
 
 
338
inline
 
339
const Identifier *InheritedC::identifier() const
 
340
{
 
341
  return ident_;
 
342
}
 
343
 
 
344
inline
 
345
void InheritedC::setIdentifier(const Identifier *ident)
 
346
{
 
347
  ident_ = ident;
 
348
}
 
349
 
 
350
inline
 
351
unsigned InheritedC::index() const
 
352
{
 
353
  return index_;
 
354
}
 
355
 
 
356
inline
 
357
ELObj **VarStyleObj::display() const
 
358
{
 
359
  return display_;
 
360
}
 
361
 
 
362
inline
 
363
const NodePtr &VarStyleObj::node() const
 
364
{
 
365
  return node_;
 
366
}
 
367
 
 
368
inline
 
369
void StyleStack::pushStart()
 
370
{
 
371
  level_++;
 
372
  popList_ = new PopList(popList_);
 
373
}
 
374
 
 
375
inline
 
376
void StyleStack::push(StyleObj *style, VM &vm, FOTBuilder &fotb)
 
377
{
 
378
  pushStart();
 
379
  pushContinue(style, 0, NodePtr(), 0);
 
380
  pushEnd(vm, fotb);
 
381
}
 
382
 
 
383
inline
 
384
ELObj *StyleStack::actual(const ConstPtr<InheritedC> &ic,
 
385
                          Interpreter &interp,
 
386
                          Vector<size_t> &dep)
 
387
{
 
388
  return actual(ic, Location(), interp, dep);
 
389
}
 
390
 
 
391
#ifdef DSSSL_NAMESPACE
 
392
}
 
393
#endif
 
394
 
 
395
#endif /* not Style_INCLUDED */