📄 gfxstate.cc
字号:
color.c[i] = lookup[x[i] * nComps + i]; } colorSpace->getRGB(&color, rgb); }}void GfxImageColorMap::getCMYK(Guchar *x, GfxCMYK *cmyk) { GfxColor color; double *p; int i; if (colorSpace2) { p = &lookup[x[0] * nComps2]; for (i = 0; i < nComps2; ++i) { color.c[i] = *p++; } colorSpace2->getCMYK(&color, cmyk); } else { for (i = 0; i < nComps; ++i) { color.c[i] = lookup[x[i] * nComps + i]; } colorSpace->getCMYK(&color, cmyk); }}void GfxImageColorMap::getColor(Guchar *x, GfxColor *color) { int maxPixel, i; maxPixel = (1 << bits) - 1; for (i = 0; i < nComps; ++i) { color->c[i] = decodeLow[i] + (x[i] * decodeRange[i]) / maxPixel; }}//------------------------------------------------------------------------// GfxSubpath and GfxPath//------------------------------------------------------------------------GfxSubpath::GfxSubpath(double x1, double y1) { size = 16; x = (double *)gmalloc(size * sizeof(double)); y = (double *)gmalloc(size * sizeof(double)); curve = (GBool *)gmalloc(size * sizeof(GBool)); n = 1; x[0] = x1; y[0] = y1; curve[0] = gFalse; closed = gFalse;}GfxSubpath::~GfxSubpath() { gfree(x); gfree(y); gfree(curve);}// Used for copy().GfxSubpath::GfxSubpath(GfxSubpath *subpath) { size = subpath->size; n = subpath->n; x = (double *)gmalloc(size * sizeof(double)); y = (double *)gmalloc(size * sizeof(double)); curve = (GBool *)gmalloc(size * sizeof(GBool)); memcpy(x, subpath->x, n * sizeof(double)); memcpy(y, subpath->y, n * sizeof(double)); memcpy(curve, subpath->curve, n * sizeof(GBool)); closed = subpath->closed;}void GfxSubpath::lineTo(double x1, double y1) { if (n >= size) { size += 16; x = (double *)grealloc(x, size * sizeof(double)); y = (double *)grealloc(y, size * sizeof(double)); curve = (GBool *)grealloc(curve, size * sizeof(GBool)); } x[n] = x1; y[n] = y1; curve[n] = gFalse; ++n;}void GfxSubpath::curveTo(double x1, double y1, double x2, double y2, double x3, double y3) { if (n+3 > size) { size += 16; x = (double *)grealloc(x, size * sizeof(double)); y = (double *)grealloc(y, size * sizeof(double)); curve = (GBool *)grealloc(curve, size * sizeof(GBool)); } x[n] = x1; y[n] = y1; x[n+1] = x2; y[n+1] = y2; x[n+2] = x3; y[n+2] = y3; curve[n] = curve[n+1] = gTrue; curve[n+2] = gFalse; n += 3;}void GfxSubpath::close() { if (x[n-1] != x[0] || y[n-1] != y[0]) { lineTo(x[0], y[0]); } closed = gTrue;}GfxPath::GfxPath() { justMoved = gFalse; size = 16; n = 0; firstX = firstY = 0; subpaths = (GfxSubpath **)gmalloc(size * sizeof(GfxSubpath *));}GfxPath::~GfxPath() { int i; for (i = 0; i < n; ++i) delete subpaths[i]; gfree(subpaths);}// Used for copy().GfxPath::GfxPath(GBool justMoved1, double firstX1, double firstY1, GfxSubpath **subpaths1, int n1, int size1) { int i; justMoved = justMoved1; firstX = firstX1; firstY = firstY1; size = size1; n = n1; subpaths = (GfxSubpath **)gmalloc(size * sizeof(GfxSubpath *)); for (i = 0; i < n; ++i) subpaths[i] = subpaths1[i]->copy();}void GfxPath::moveTo(double x, double y) { justMoved = gTrue; firstX = x; firstY = y;}void GfxPath::lineTo(double x, double y) { if (justMoved) { if (n >= size) { size += 16; subpaths = (GfxSubpath **) grealloc(subpaths, size * sizeof(GfxSubpath *)); } subpaths[n] = new GfxSubpath(firstX, firstY); ++n; justMoved = gFalse; } subpaths[n-1]->lineTo(x, y);}void GfxPath::curveTo(double x1, double y1, double x2, double y2, double x3, double y3) { if (justMoved) { if (n >= size) { size += 16; subpaths = (GfxSubpath **) grealloc(subpaths, size * sizeof(GfxSubpath *)); } subpaths[n] = new GfxSubpath(firstX, firstY); ++n; justMoved = gFalse; } subpaths[n-1]->curveTo(x1, y1, x2, y2, x3, y3);}void GfxPath::close() { // this is necessary to handle the pathological case of // moveto/closepath/clip, which defines an empty clipping region if (justMoved) { if (n >= size) { size += 16; subpaths = (GfxSubpath **) grealloc(subpaths, size * sizeof(GfxSubpath *)); } subpaths[n] = new GfxSubpath(firstX, firstY); ++n; justMoved = gFalse; } subpaths[n-1]->close();}//------------------------------------------------------------------------// GfxState//------------------------------------------------------------------------GfxState::GfxState(double dpi, PDFRectangle *pageBox, int rotate, GBool upsideDown) { double k; px1 = pageBox->x1; py1 = pageBox->y1; px2 = pageBox->x2; py2 = pageBox->y2; k = dpi / 72.0; if (rotate == 90) { ctm[0] = 0; ctm[1] = upsideDown ? k : -k; ctm[2] = k; ctm[3] = 0; ctm[4] = -k * py1; ctm[5] = k * (upsideDown ? -px1 : px2); pageWidth = k * (py2 - py1); pageHeight = k * (px2 - px1); } else if (rotate == 180) { ctm[0] = -k; ctm[1] = 0; ctm[2] = 0; ctm[3] = upsideDown ? k : -k; ctm[4] = k * px2; ctm[5] = k * (upsideDown ? -py1 : py2); pageWidth = k * (px2 - px1); pageHeight = k * (py2 - py1); } else if (rotate == 270) { ctm[0] = 0; ctm[1] = upsideDown ? -k : k; ctm[2] = -k; ctm[3] = 0; ctm[4] = k * py2; ctm[5] = k * (upsideDown ? px2 : -px1); pageWidth = k * (py2 - py1); pageHeight = k * (px2 - px1); } else { ctm[0] = k; ctm[1] = 0; ctm[2] = 0; ctm[3] = upsideDown ? -k : k; ctm[4] = -k * px1; ctm[5] = k * (upsideDown ? py2 : -py1); pageWidth = k * (px2 - px1); pageHeight = k * (py2 - py1); } fillColorSpace = new GfxDeviceGrayColorSpace(); strokeColorSpace = new GfxDeviceGrayColorSpace(); fillColor.c[0] = 0; strokeColor.c[0] = 0; fillPattern = NULL; strokePattern = NULL; fillOpacity = 1; strokeOpacity = 1; lineWidth = 1; lineDash = NULL; lineDashLength = 0; lineDashStart = 0; flatness = 0; lineJoin = 0; lineCap = 0; miterLimit = 10; font = NULL; fontSize = 0; textMat[0] = 1; textMat[1] = 0; textMat[2] = 0; textMat[3] = 1; textMat[4] = 0; textMat[5] = 0; charSpace = 0; wordSpace = 0; horizScaling = 1; leading = 0; rise = 0; render = 0; path = new GfxPath(); curX = curY = 0; lineX = lineY = 0; clipXMin = 0; clipYMin = 0; clipXMax = pageWidth; clipYMax = pageHeight; saved = NULL;}GfxState::~GfxState() { if (fillColorSpace) { delete fillColorSpace; } if (strokeColorSpace) { delete strokeColorSpace; } if (fillPattern) { delete fillPattern; } if (strokePattern) { delete strokePattern; } gfree(lineDash); if (path) { // this gets set to NULL by restore() delete path; } if (saved) { delete saved; }}// Used for copy();GfxState::GfxState(GfxState *state) { memcpy(this, state, sizeof(GfxState)); if (fillColorSpace) { fillColorSpace = state->fillColorSpace->copy(); } if (strokeColorSpace) { strokeColorSpace = state->strokeColorSpace->copy(); } if (fillPattern) { fillPattern = state->fillPattern->copy(); } if (strokePattern) { strokePattern = state->strokePattern->copy(); } if (lineDashLength > 0) { lineDash = (double *)gmalloc(lineDashLength * sizeof(double)); memcpy(lineDash, state->lineDash, lineDashLength * sizeof(double)); } saved = NULL;}void GfxState::getUserClipBBox(double *xMin, double *yMin, double *xMax, double *yMax) { double ictm[6]; double xMin1, yMin1, xMax1, yMax1, det, tx, ty; // invert the CTM det = 1 / (ctm[0] * ctm[3] - ctm[1] * ctm[2]); ictm[0] = ctm[3] * det; ictm[1] = -ctm[1] * det; ictm[2] = -ctm[2] * det; ictm[3] = ctm[0] * det; ictm[4] = (ctm[2] * ctm[5] - ctm[3] * ctm[4]) * det; ictm[5] = (ctm[1] * ctm[4] - ctm[0] * ctm[5]) * det; // transform all four corners of the clip bbox; find the min and max // x and y values xMin1 = xMax1 = clipXMin * ictm[0] + clipYMin * ictm[2] + ictm[4]; yMin1 = yMax1 = clipXMin * ictm[1] + clipYMin * ictm[3] + ictm[5]; tx = clipXMin * ictm[0] + clipYMax * ictm[2] + ictm[4]; ty = clipXMin * ictm[1] + clipYMax * ictm[3] + ictm[5]; if (tx < xMin1) { xMin1 = tx; } else if (tx > xMax1) { xMax1 = tx; } if (ty < yMin1) { yMin1 = ty; } else if (ty > yMax1) { yMax1 = ty; } tx = clipXMax * ictm[0] + clipYMin * ictm[2] + ictm[4]; ty = clipXMax * ictm[1] + clipYMin * ictm[3] + ictm[5]; if (tx < xMin1) { xMin1 = tx; } else if (tx > xMax1) { xMax1 = tx; } if (ty < yMin1) { yMin1 = ty; } else if (ty > yMax1) { yMax1 = ty; } tx = clipXMax * ictm[0] + clipYMax * ictm[2] + ictm[4]; ty = clipXMax * ictm[1] + clipYMax * ictm[3] + ictm[5]; if (tx < xMin1) { xMin1 = tx; } else if (tx > xMax1) { xMax1 = tx; } if (ty < yMin1) { yMin1 = ty; } else if (ty > yMax1) { yMax1 = ty; } *xMin = xMin1; *yMin = yMin1; *xMax = xMax1; *yMax = yMax1;}double GfxState::transformWidth(double w) { double x, y; x = ctm[0] + ctm[2]; y = ctm[1] + ctm[3]; return w * sqrt(0.5 * (x * x + y * y));}double GfxState::getTransformedFontSize() { double x1, y1, x2, y2; x1 = textMat[2] * fontSize; y1 = textMat[3] * fontSize; x2 = ctm[0] * x1 + ctm[2] * y1; y2 = ctm[1] * x1 + ctm[3] * y1; return sqrt(x2 * x2 + y2 * y2);}void GfxState::getFontTransMat(double *m11, double *m12, double *m21, double *m22) { *m11 = (textMat[0] * ctm[0] + textMat[1] * ctm[2]) * fontSize; *m12 = (textMat[0] * ctm[1] + textMat[1] * ctm[3]) * fontSize; *m21 = (textMat[2] * ctm[0] + textMat[3] * ctm[2]) * fontSize; *m22 = (textMat[2] * ctm[1] + textMat[3] * ctm[3]) * fontSize;}void GfxState::setCTM(double a, double b, double c, double d, double e, double f) { int i; ctm[0] = a; ctm[1] = b; ctm[2] = c; ctm[3] = d; ctm[4] = e; ctm[5] = f; // avoid FP exceptions on badly messed up PDF files for (i = 0; i < 6; ++i) { if (ctm[i] > 1e10) { ctm[i] = 1e10; } else if (ctm[i] < -1e10) { ctm[i] = -1e10; } }}void GfxState::concatCTM(double a, double b, double c, double d, double e, double f) { double a1 = ctm[0]; double b1 = ctm[1]; double c1 = ctm[2]; double d1 = ctm[3]; int i; ctm[0] = a * a1 + b * c1; ctm[1] = a * b1 + b * d1; ctm[2] = c * a1 + d * c1; ctm[3] = c * b1 + d * d1; ctm[4] = e * a1 + f * c1 + ctm[4]; ctm[5] = e * b1 + f * d1 + ctm[5]; // avoid FP exceptions on badly messed up PDF files for (i = 0; i < 6; ++i) { if (ctm[i] > 1e10) { ctm[i] = 1e10; } else if (ctm[i] < -1e10) { ctm[i] = -1e10; } }}void GfxState::setFillColorSpace(GfxColorSpace *colorSpace) { if (fillColorSpace) { delete fillColorSpace; } fillColorSpace = colorSpace;}void GfxState::setStrokeColorSpace(GfxColorSpace *colorSpace) { if (strokeColorSpace) { delete strokeColorSpace; } strokeColorSpace = colorSpace;}void GfxState::setFillPattern(GfxPattern *pattern) { if (fillPattern) { delete fillPattern; } fillPattern = pattern;}void GfxState::setStrokePattern(GfxPattern *pattern) { if (strokePattern) { delete strokePattern; } strokePattern = pattern;}void GfxState::setLineDash(double *dash, int length, double start) { if (lineDash) gfree(lineDash); lineDash = dash; lineDashLength = length; lineDashStart = start;}void GfxState::clearPath() { delete path; path = new GfxPath();}void GfxState::clip() { double xMin, yMin, xMax, yMax, x, y; GfxSubpath *subpath; int i, j; xMin = xMax = yMin = yMax = 0; // make gcc happy for (i = 0; i < path->getNumSubpaths(); ++i) { subpath = path->getSubpath(i); for (j = 0; j < subpath->getNumPoints(); ++j) { transform(subpath->getX(j), subpath->getY(j), &x, &y); if (i == 0 && j == 0) { xMin = xMax = x; yMin = yMax = y; } else { if (x < xMin) { xMin = x; } else if (x > xMax) { xMax = x; } if (y < yMin) { yMin = y; } else if (y > yMax) { yMax = y; } } } } if (xMin > clipXMin) { clipXMin = xMin; } if (yMin > clipYMin) { clipYMin = yMin; } if (xMax < clipXMax) { clipXMax = xMax; } if (yMax < clipYMax) { clipYMax = yMax; }}void GfxState::textShift(double tx, double ty) { double dx, dy; textTransformDelta(tx, ty, &dx, &dy); curX += dx; curY += dy;}void GfxState::shift(double dx, double dy) { curX += dx; curY += dy;}GfxState *GfxState::save() { GfxState *newState; newState = copy(); newState->saved = this; return newState;}GfxState *GfxState::restore() { GfxState *oldState; if (saved) { oldState = saved; // these attributes aren't saved/restored by the q/Q operators oldState->path = path; oldState->curX = curX; oldState->curY = curY; oldState->lineX = lineX; oldState->lineY = lineY; path = NULL; saved = NULL; delete this; } else { oldState = this; } return oldState;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -