1
// Copyright (c) 1996 James Clark
2
// See the file copying.txt for copying permission.
5
#define Style_INCLUDED 1
17
#include "FOTBuilder.h"
21
#include "ProcessingMode.h"
23
#ifdef DSSSL_NAMESPACE
24
namespace DSSSL_NAMESPACE {
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.
38
class InheritedC : public Resource {
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 *);
50
void invalidValue(const Location &, Interpreter &) const;
52
const Identifier *ident_;
53
// The index of the inherited characteristic (not the specification).
57
class VarInheritedC : public InheritedC {
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;
65
ConstPtr<InheritedC> inheritedC_;
73
void append(const Vector<ConstPtr<InheritedC> > *, const VarStyleObj *);
74
ConstPtr<InheritedC> next(const VarStyleObj *&);
78
Vector<const VarStyleObj *> styleVec_;
79
Vector<const Vector<ConstPtr<InheritedC> > *> vecs_;
82
class StyleObj : public ELObj {
85
virtual void appendIter(StyleObjIter &) const = 0;
88
struct StyleSpec : public Resource {
89
StyleSpec(Vector<ConstPtr<InheritedC> > &, Vector<ConstPtr<InheritedC> > &);
90
Vector<ConstPtr<InheritedC> > forceSpecs;
91
Vector<ConstPtr<InheritedC> > specs;
94
class BasicStyleObj : public StyleObj {
96
virtual void appendIterForce(StyleObjIter &) const = 0;
97
virtual void appendIterNormal(StyleObjIter &) const = 0;
100
class VarStyleObj : public BasicStyleObj {
102
void *operator new(size_t, Collector &c) {
103
return c.allocateObject(1);
105
VarStyleObj(const ConstPtr<StyleSpec> &, StyleObj *use, ELObj **display,
106
const NodePtr &node);
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;
115
ConstPtr<StyleSpec> styleSpec_;
121
class OverriddenStyleObj : public StyleObj {
123
OverriddenStyleObj(BasicStyleObj *basic, StyleObj *override);
124
void appendIter(StyleObjIter &) const;
125
void traceSubObjects(Collector &) const;
127
BasicStyleObj *basic_;
131
class MergeStyleObj : public StyleObj {
133
void *operator new(size_t, Collector &c) {
134
return c.allocateObject(1);
137
void append(StyleObj *);
138
void appendIter(StyleObjIter &) const;
139
void traceSubObjects(Collector &) const;
141
Vector<StyleObj *> styles_;
144
class ColorObj : public ELObj {
147
virtual void set(FOTBuilder &) const = 0;
148
virtual void setBackground(FOTBuilder &) const = 0;
151
class DeviceRGBColorObj : public ColorObj {
153
DeviceRGBColorObj(unsigned char, unsigned char, unsigned char);
154
void set(FOTBuilder &) const;
155
void setBackground(FOTBuilder &) const;
157
FOTBuilder::DeviceRGBColor color_;
160
class ColorSpaceObj : public ELObj {
162
ColorSpaceObj *asColorSpace();
163
virtual ELObj *makeColor(int argc, ELObj **argv, Interpreter &, const Location &) = 0;
166
class DeviceRGBColorSpaceObj : public ColorSpaceObj {
168
ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
171
class DeviceGrayColorSpaceObj : public ColorSpaceObj {
173
ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
176
class DeviceCMYKColorSpaceObj : public ColorSpaceObj {
178
ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
181
class DeviceKXColorSpaceObj : public ColorSpaceObj {
183
ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
186
class CIEXYZColorSpaceObj : public ColorSpaceObj {
188
CIEXYZColorSpaceObj(const double *, const double *);
189
void *operator new(size_t, Collector &c) {
190
return c.allocateObject(1);
192
~CIEXYZColorSpaceObj();
193
ELObj *makeColor(const double *, Interpreter &);
204
class CIELUVColorSpaceObj : public CIEXYZColorSpaceObj {
206
CIELUVColorSpaceObj(const double *, const double *, const double *);
207
void *operator new(size_t, Collector &c) {
208
return c.allocateObject(1);
210
~CIELUVColorSpaceObj();
211
ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
219
class CIELABColorSpaceObj : public CIEXYZColorSpaceObj {
221
CIELABColorSpaceObj(const double *, const double *, const double *);
222
void *operator new(size_t, Collector &c) {
223
return c.allocateObject(1);
225
~CIELABColorSpaceObj();
226
ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
234
class CIEABCColorSpaceObj : public CIEXYZColorSpaceObj {
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);
242
~CIEABCColorSpaceObj();
243
void traceSubObjects(Collector &) const;
244
ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
248
FunctionObj *decodeAbc_[3];
249
double matrixAbc_[9];
251
FunctionObj *decodeLmn_[3];
252
double matrixLmn_[9];
257
class CIEAColorSpaceObj : public CIEXYZColorSpaceObj {
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);
265
~CIEAColorSpaceObj();
266
void traceSubObjects(Collector &) const;
267
ELObj *makeColor(int argc, ELObj **argv, Interpreter &interp, const Location &);
271
FunctionObj *decodeA_;
274
FunctionObj *decodeLmn_[3];
275
double matrixLmn_[9];
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;
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.
292
const VarStyleObj *style;
293
// Includes both direct and indirect dependencies.
294
Vector<size_t> dependencies;
297
struct PopList : public Resource {
298
PopList(const Ptr<PopList> &);
300
// List of the indices of those ICs that have dependencies
301
// (ie that use actual-*) directly or indirectly.
302
Vector<size_t> dependingList;
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 &);
318
void pushContinue(StyleObj *, const ProcessingMode::Rule *, const NodePtr &,
320
void pushEnd(VM &, FOTBuilder &);
322
void pushEmpty() { level_++; }
323
void popEmpty() { level_--; }
324
unsigned level() const { return level_; }
325
void trace(Collector &) const;
327
Vector<Ptr<InheritedCInfo> > inheritedCInfo_;
329
Ptr<PopList> popList_;
333
PopList::PopList(const Ptr<PopList> &p)
339
const Identifier *InheritedC::identifier() const
345
void InheritedC::setIdentifier(const Identifier *ident)
351
unsigned InheritedC::index() const
357
ELObj **VarStyleObj::display() const
363
const NodePtr &VarStyleObj::node() const
369
void StyleStack::pushStart()
372
popList_ = new PopList(popList_);
376
void StyleStack::push(StyleObj *style, VM &vm, FOTBuilder &fotb)
379
pushContinue(style, 0, NodePtr(), 0);
384
ELObj *StyleStack::actual(const ConstPtr<InheritedC> &ic,
388
return actual(ic, Location(), interp, dep);
391
#ifdef DSSSL_NAMESPACE
395
#endif /* not Style_INCLUDED */