void psOutput(int *hist, char *psFile) /* Output histogram in postscript format. */ { double labelSize = 72.0/2; double psInnerSize = psSize - labelSize; double tickSize = labelSize/4; double textSize = labelSize - tickSize; struct psGfx *ps = psOpen(psFile, psSize, psSize, psSize, psSize, margin); double val, maxVal = findMaxVal(hist); int x, y, both; double grayScale; double xPos, yPos, xMid; double xBinPts = psInnerSize/xBins; double yBinPts = psInnerSize/yBins; grayScale = 1.0 / maxVal * postScale; for (y=0; y<yBins; ++y) { int yg = yBins-1-y; yPos = yg*yBinPts; for (x=0; x<xBins; ++x) { xPos = x * xBinPts + labelSize; both = y*xBins + x; val = mightLog(hist[both]) * grayScale; if (val > 1.0) val = 1.0; if (val < 0.0) val = 0.0; psSetGray(ps, 1.0 - val); boxOut(ps, xPos, yPos, xBinPts, yBinPts); } } /* Draw ticks and labels. */ psSetGray(ps, 0); yPos = psInnerSize; for (x=labelStep; x<xBins; x += labelStep) { char buf[16]; sprintf(buf, "%d", x*xBinSize+xMin); xPos = x * xBinPts + labelSize; xMid = xPos; psDrawBox(ps, xPos, yPos, 1, tickSize); psTextDown(ps, xPos, yPos+tickSize+2, buf); } for (y=labelStep; y<yBins; y += labelStep) { char buf[16]; int yg = yBins-y; sprintf(buf, "%d", y*yBinSize+yMin); yPos = yg*yBinPts; psDrawBox(ps, textSize, yPos, tickSize, 1); psTextAt(ps, 0, yPos, buf); } psClose(&ps); }
void pscmBoxToPs(struct pscmGfx *pscm, int x, int y, int width, int height) /* adjust coordinates for PS */ { /* Do some clipping here to make the postScript * easier to edit in illustrator. */ double x2 = x + width; double y2 = y + height; if (x < pscm->clipMinX) x = pscm->clipMinX; if (y < pscm->clipMinY) y = pscm->clipMinY; if (x2 > pscm->clipMaxX) x2 = pscm->clipMaxX; if (y2 > pscm->clipMaxY) y2 = pscm->clipMaxY; /* adjust to pixel-centered coordinates */ x2 -= 1; y2 -= 1; double x1 = x; double y1 = y; /* pad a half-pixel all the way around the box */ x1 -= 0.5; y1 -= 0.5; x2 += 0.5; y2 += 0.5; psDrawBox(pscm->ps, x1, y1, x2-x1, y2-y1); }
static void pscmVerticalSmear(struct pscmGfx *pscm, int xOff, int yOff, int width, int height, Color *dots, boolean zeroClear) /* Put a series of one 'pixel' width vertical lines. */ { int x, i; struct psGfx *ps = pscm->ps; Color c; for (i=0; i<width; ++i) { x = xOff + i; c = dots[i]; if (c != MG_WHITE || !zeroClear) { pscmSetColor(pscm, c); psDrawBox(ps, x, yOff, 1, height); } } }
void boxOut(struct psGfx *ps, int x, int y, int width, int height) /* Draw a filled box in current color. */ { psDrawBox(ps, x, y, width+1, height+1); }