📄 gfxstate.cc
字号:
for (i = 0; i < 6; ++i) { matrix[i] = matrixA[i]; }}GfxShadingPattern::~GfxShadingPattern() { delete shading;}GfxPattern *GfxShadingPattern::copy() { return new GfxShadingPattern(shading->copy(), matrix);}//------------------------------------------------------------------------// GfxShading//------------------------------------------------------------------------GfxShading::GfxShading(int typeA) { type = typeA; colorSpace = NULL;}GfxShading::GfxShading(GfxShading *shading) { int i; type = shading->type; colorSpace = shading->colorSpace->copy(); for (i = 0; i < gfxColorMaxComps; ++i) { background.c[i] = shading->background.c[i]; } hasBackground = shading->hasBackground; xMin = shading->xMin; yMin = shading->yMin; xMax = shading->xMax; yMax = shading->yMax; hasBBox = shading->hasBBox;}GfxShading::~GfxShading() { if (colorSpace) { delete colorSpace; }}GfxShading *GfxShading::parse(Object *obj) { GfxShading *shading; Dict *dict; int typeA; Object obj1; if (obj->isDict()) { dict = obj->getDict(); } else if (obj->isStream()) { dict = obj->streamGetDict(); } else { return NULL; } if (!dict->lookup("ShadingType", &obj1)->isInt()) { error(-1, "Invalid ShadingType in shading dictionary"); obj1.free(); return NULL; } typeA = obj1.getInt(); obj1.free(); switch (typeA) { case 1: shading = GfxFunctionShading::parse(dict); break; case 2: shading = GfxAxialShading::parse(dict); break; case 3: shading = GfxRadialShading::parse(dict); break; case 4: if (obj->isStream()) { shading = GfxGouraudTriangleShading::parse(4, dict, obj->getStream()); } else { error(-1, "Invalid Type 4 shading object"); goto err1; } break; case 5: if (obj->isStream()) { shading = GfxGouraudTriangleShading::parse(5, dict, obj->getStream()); } else { error(-1, "Invalid Type 5 shading object"); goto err1; } break; case 6: if (obj->isStream()) { shading = GfxPatchMeshShading::parse(6, dict, obj->getStream()); } else { error(-1, "Invalid Type 6 shading object"); goto err1; } break; case 7: if (obj->isStream()) { shading = GfxPatchMeshShading::parse(7, dict, obj->getStream()); } else { error(-1, "Invalid Type 7 shading object"); goto err1; } break; default: error(-1, "Unimplemented shading type %d", typeA); goto err1; } return shading; err1: return NULL;}GBool GfxShading::init(Dict *dict) { Object obj1, obj2; int i; dict->lookup("ColorSpace", &obj1); if (!(colorSpace = GfxColorSpace::parse(&obj1))) { error(-1, "Bad color space in shading dictionary"); obj1.free(); return gFalse; } obj1.free(); for (i = 0; i < gfxColorMaxComps; ++i) { background.c[i] = 0; } hasBackground = gFalse; if (dict->lookup("Background", &obj1)->isArray()) { if (obj1.arrayGetLength() == colorSpace->getNComps()) { hasBackground = gTrue; for (i = 0; i < colorSpace->getNComps(); ++i) { background.c[i] = dblToCol(obj1.arrayGet(i, &obj2)->getNum()); obj2.free(); } } else { error(-1, "Bad Background in shading dictionary"); } } obj1.free(); xMin = yMin = xMax = yMax = 0; hasBBox = gFalse; if (dict->lookup("BBox", &obj1)->isArray()) { if (obj1.arrayGetLength() == 4) { hasBBox = gTrue; xMin = obj1.arrayGet(0, &obj2)->getNum(); obj2.free(); yMin = obj1.arrayGet(1, &obj2)->getNum(); obj2.free(); xMax = obj1.arrayGet(2, &obj2)->getNum(); obj2.free(); yMax = obj1.arrayGet(3, &obj2)->getNum(); obj2.free(); } else { error(-1, "Bad BBox in shading dictionary"); } } obj1.free(); return gTrue;}//------------------------------------------------------------------------// GfxFunctionShading//------------------------------------------------------------------------GfxFunctionShading::GfxFunctionShading(double x0A, double y0A, double x1A, double y1A, double *matrixA, Function **funcsA, int nFuncsA): GfxShading(1){ int i; x0 = x0A; y0 = y0A; x1 = x1A; y1 = y1A; for (i = 0; i < 6; ++i) { matrix[i] = matrixA[i]; } nFuncs = nFuncsA; for (i = 0; i < nFuncs; ++i) { funcs[i] = funcsA[i]; }}GfxFunctionShading::GfxFunctionShading(GfxFunctionShading *shading): GfxShading(shading){ int i; x0 = shading->x0; y0 = shading->y0; x1 = shading->x1; y1 = shading->y1; for (i = 0; i < 6; ++i) { matrix[i] = shading->matrix[i]; } nFuncs = shading->nFuncs; for (i = 0; i < nFuncs; ++i) { funcs[i] = shading->funcs[i]->copy(); }}GfxFunctionShading::~GfxFunctionShading() { int i; for (i = 0; i < nFuncs; ++i) { delete funcs[i]; }}GfxFunctionShading *GfxFunctionShading::parse(Dict *dict) { GfxFunctionShading *shading; double x0A, y0A, x1A, y1A; double matrixA[6]; Function *funcsA[gfxColorMaxComps]; int nFuncsA; Object obj1, obj2; int i; x0A = y0A = 0; x1A = y1A = 1; if (dict->lookup("Domain", &obj1)->isArray() && obj1.arrayGetLength() == 4) { x0A = obj1.arrayGet(0, &obj2)->getNum(); obj2.free(); y0A = obj1.arrayGet(1, &obj2)->getNum(); obj2.free(); x1A = obj1.arrayGet(2, &obj2)->getNum(); obj2.free(); y1A = obj1.arrayGet(3, &obj2)->getNum(); obj2.free(); } obj1.free(); matrixA[0] = 1; matrixA[1] = 0; matrixA[2] = 0; matrixA[3] = 1; matrixA[4] = 0; matrixA[5] = 0; if (dict->lookup("Matrix", &obj1)->isArray() && obj1.arrayGetLength() == 6) { matrixA[0] = obj1.arrayGet(0, &obj2)->getNum(); obj2.free(); matrixA[1] = obj1.arrayGet(1, &obj2)->getNum(); obj2.free(); matrixA[2] = obj1.arrayGet(2, &obj2)->getNum(); obj2.free(); matrixA[3] = obj1.arrayGet(3, &obj2)->getNum(); obj2.free(); matrixA[4] = obj1.arrayGet(4, &obj2)->getNum(); obj2.free(); matrixA[5] = obj1.arrayGet(5, &obj2)->getNum(); obj2.free(); } obj1.free(); dict->lookup("Function", &obj1); if (obj1.isArray()) { nFuncsA = obj1.arrayGetLength(); if (nFuncsA > gfxColorMaxComps) { error(-1, "Invalid Function array in shading dictionary"); goto err1; } for (i = 0; i < nFuncsA; ++i) { obj1.arrayGet(i, &obj2); if (!(funcsA[i] = Function::parse(&obj2))) { goto err2; } obj2.free(); } } else { nFuncsA = 1; if (!(funcsA[0] = Function::parse(&obj1))) { goto err1; } } obj1.free(); shading = new GfxFunctionShading(x0A, y0A, x1A, y1A, matrixA, funcsA, nFuncsA); if (!shading->init(dict)) { delete shading; return NULL; } return shading; err2: obj2.free(); err1: obj1.free(); return NULL;}GfxShading *GfxFunctionShading::copy() { return new GfxFunctionShading(this);}void GfxFunctionShading::getColor(double x, double y, GfxColor *color) { double in[2], out[gfxColorMaxComps]; int i; // NB: there can be one function with n outputs or n functions with // one output each (where n = number of color components) for (i = 0; i < gfxColorMaxComps; ++i) { out[i] = 0; } in[0] = x; in[1] = y; for (i = 0; i < nFuncs; ++i) { funcs[i]->transform(in, &out[i]); } for (i = 0; i < gfxColorMaxComps; ++i) { color->c[i] = dblToCol(out[i]); }}//------------------------------------------------------------------------// GfxAxialShading//------------------------------------------------------------------------GfxAxialShading::GfxAxialShading(double x0A, double y0A, double x1A, double y1A, double t0A, double t1A, Function **funcsA, int nFuncsA, GBool extend0A, GBool extend1A): GfxShading(2){ int i; x0 = x0A; y0 = y0A; x1 = x1A; y1 = y1A; t0 = t0A; t1 = t1A; nFuncs = nFuncsA; for (i = 0; i < nFuncs; ++i) { funcs[i] = funcsA[i]; } extend0 = extend0A; extend1 = extend1A;}GfxAxialShading::GfxAxialShading(GfxAxialShading *shading): GfxShading(shading){ int i; x0 = shading->x0; y0 = shading->y0; x1 = shading->x1; y1 = shading->y1; t0 = shading->t0; y1 = shading->t1; nFuncs = shading->nFuncs; for (i = 0; i < nFuncs; ++i) { funcs[i] = shading->funcs[i]->copy(); } extend0 = shading->extend0; extend1 = shading->extend1;}GfxAxialShading::~GfxAxialShading() { int i; for (i = 0; i < nFuncs; ++i) { delete funcs[i]; }}GfxAxialShading *GfxAxialShading::parse(Dict *dict) { GfxAxialShading *shading; double x0A, y0A, x1A, y1A; double t0A, t1A; Function *funcsA[gfxColorMaxComps]; int nFuncsA; GBool extend0A, extend1A; Object obj1, obj2; int i; x0A = y0A = x1A = y1A = 0; if (dict->lookup("Coords", &obj1)->isArray() && obj1.arrayGetLength() == 4) { x0A = obj1.arrayGet(0, &obj2)->getNum(); obj2.free(); y0A = obj1.arrayGet(1, &obj2)->getNum(); obj2.free(); x1A = obj1.arrayGet(2, &obj2)->getNum(); obj2.free(); y1A = obj1.arrayGet(3, &obj2)->getNum(); obj2.free(); } else { error(-1, "Missing or invalid Coords in shading dictionary"); goto err1; } obj1.free(); t0A = 0; t1A = 1; if (dict->lookup("Domain", &obj1)->isArray() && obj1.arrayGetLength() == 2) { t0A = obj1.arrayGet(0, &obj2)->getNum(); obj2.free(); t1A = obj1.arrayGet(1, &obj2)->getNum(); obj2.free(); } obj1.free(); dict->lookup("Function", &obj1); if (obj1.isArray()) { nFuncsA = obj1.arrayGetLength(); if (nFuncsA > gfxColorMaxComps) { error(-1, "Invalid Function array in shading dictionary"); goto err1; } for (i = 0; i < nFuncsA; ++i) { obj1.arrayGet(i, &obj2); if (!(funcsA[i] = Function::parse(&obj2))) { obj1.free(); obj2.free(); goto err1; } obj2.free(); } } else { nFuncsA = 1; if (!(funcsA[0] = Function::parse(&obj1))) { obj1.free(); goto err1; } } obj1.free(); extend0A = extend1A = gFalse; if (dict->lookup("Extend", &obj1)->isArray() && obj1.arrayGetLength() == 2) { extend0A = obj1.arrayGet(0, &obj2)->getBool(); obj2.free(); extend1A = obj1.arrayGet(1, &obj2)->getBool(); obj2.free(); } obj1.free(); shading = new GfxAxialShading(x0A, y0A, x1A, y1A, t0A, t1A, funcsA, nFuncsA, extend0A, extend1A); if (!shading->init(dict)) { delete shading; return NULL; } return shading; err1: return NULL;}GfxShading *GfxAxialShading::copy() { return new GfxAxialShading(this);}void GfxAxialShading::getColor(double t, GfxColor *color) { double out[gfxColorMaxComps]; int i; // NB: there can be one function with n outputs or n functions with // one output each (where n = number of color components) for (i = 0; i < gfxColorMaxComps; ++i) { out[i] = 0; } for (i = 0; i < nFuncs; ++i) { funcs[i]->transform(&t, &out[i]); } for (i = 0; i < gfxColorMaxComps; ++i) { color->c[i] = dblToCol(out[i]); }}//------------------------------------------------------------------------// GfxRadialShading//------------------------------------------------------------------------GfxRadialShading::GfxRadialShading(double x0A, double y0A, double r0A, double x1A, double y1A, double r1A, double t0A, double t1A, Function **funcsA, int nFuncsA, GBool extend0A, GBool extend1A): GfxShading(3){ int i; x0 = x0A; y0 = y0A; r0 = r0A; x1 = x1A; y1 = y1A; r1 = r1A; t0 = t0A; t1 = t1A; nFuncs = nFuncsA; for (i = 0; i < nFuncs; ++i) { funcs[i] = funcsA[i]; } extend0 = extend0A; extend1 = extend1A;}GfxRadialShading::GfxRadialShading(GfxRadialShading *shading): GfxShading(shading){ int i; x0 = shading->x0; y0 = shading->y0; r0 = shading->r0; x1 = shading->x1; y1 = shading->y1; r1 = shading->r1; t0 = shading->t0; y1 = shading->t1; nFuncs = shading->nFuncs; for (i = 0; i < nFuncs; ++i) { funcs[i] = shading->funcs[i]->copy(); } extend0 = shading->extend0; extend1 = shading->extend1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -