From a4954843d4e30e7c90e38edb8142f186e1bcb3c6 Mon Sep 17 00:00:00 2001 From: joye Date: Tue, 3 Jun 2014 18:41:33 +0000 Subject: *** empty log message *** --- bltGrMarkerBitmap.C | 18 +- bltGrMarkerBitmap.h | 3 +- src/bltConfig.C | 3 - src/bltConfig.h | 4 - src/bltGrAxis.C | 50 ++-- src/bltGrAxis.h | 6 +- src/bltGrElem.h | 6 +- src/bltGrElemBar.C | 69 +++-- src/bltGrElemBar.h | 10 +- src/bltGrElemLine.C | 149 +++++----- src/bltGrElemLine.h | 16 +- src/bltGrLegd.C | 33 +-- src/bltGrLegd.h | 2 +- src/bltGrMarker.h | 3 +- src/bltGrMarkerLine.C | 22 +- src/bltGrMarkerLine.h | 3 +- src/bltGrMarkerPolygon.C | 34 +-- src/bltGrMarkerPolygon.h | 3 +- src/bltGrMarkerText.C | 10 +- src/bltGrMarkerText.h | 3 +- src/bltGrPSOutput.C | 732 ++++++++++++++++++++++++----------------------- src/bltGrPSOutput.h | 144 ++++------ src/bltGrPostscriptOp.C | 118 +------- src/bltGrText.C | 2 +- src/bltGrText.h | 4 +- src/bltGraph.C | 98 +++---- src/bltGraph.h | 22 +- 27 files changed, 701 insertions(+), 866 deletions(-) diff --git a/bltGrMarkerBitmap.C b/bltGrMarkerBitmap.C index 2efc597..6615ca4 100644 --- a/bltGrMarkerBitmap.C +++ b/bltGrMarkerBitmap.C @@ -71,8 +71,6 @@ static Tk_OptionSpec optionSpecs[] = { {TK_OPTION_CUSTOM, "-mapy", "mapY", "MapY", "y", -1, Tk_Offset(BitmapMarkerOptions, yAxis), 0, &yAxisObjOption, 0}, {TK_OPTION_SYNONYM, "-outline", NULL, NULL, NULL, -1, 0, 0, "-foreground", 0}, - {TK_OPTION_STRING_TABLE, "-state", "state", "State", - "normal", -1, Tk_Offset(BitmapMarkerOptions, state), 0, &stateObjOption, 0}, {TK_OPTION_BOOLEAN, "-under", "under", "Under", "no", -1, Tk_Offset(BitmapMarkerOptions, drawUnder), 0, NULL, CACHE}, {TK_OPTION_PIXELS, "-xoffset", "xOffset", "XOffset", @@ -259,7 +257,7 @@ int BitmapMarker::regionIn(Region2d *extsPtr, int enclosed) ((anchorPt_.y + height_) <= extsPtr->top)); } -void BitmapMarker::print(Blt_Ps ps) +void BitmapMarker::print(PostScript* psPtr) { BitmapMarkerOptions* ops = (BitmapMarkerOptions*)ops_; @@ -267,15 +265,15 @@ void BitmapMarker::print(Blt_Ps ps) return; if (ops->fillColor) { - Blt_Ps_XSetBackground(ps, ops->fillColor); - Blt_Ps_XFillPolygon(ps, outline_, 4); + psPtr->setBackground(ops->fillColor); + psPtr->fillPolygon(outline_, 4); } - Blt_Ps_XSetForeground(ps, ops->outlineColor); + psPtr->setForeground(ops->outlineColor); - Blt_Ps_Format(ps, " gsave\n %g %g translate\n %d %d scale\n", + psPtr->format(" gsave\n %g %g translate\n %d %d scale\n", anchorPt_.x, anchorPt_.y + height_, width_, -height_); - Blt_Ps_Format(ps, " %d %d true [%d 0 0 %d 0 %d] {", + psPtr->format(" %d %d true [%d 0 0 %d 0 %d] {", width_, height_, width_, -height_, height_); - Blt_Ps_XSetBitmapData(ps, graphPtr_->display_, ops->bitmap, width_, height_); - Blt_Ps_VarAppend(ps, " } imagemask\n", "grestore\n", (char*)NULL); + psPtr->setBitmap(graphPtr_->display_, ops->bitmap, width_, height_); + psPtr->varAppend(" } imagemask\n", "grestore\n", NULL); } diff --git a/bltGrMarkerBitmap.h b/bltGrMarkerBitmap.h index a6d6853..d6eaac3 100644 --- a/bltGrMarkerBitmap.h +++ b/bltGrMarkerBitmap.h @@ -43,7 +43,6 @@ namespace Blt { Axis* xAxis; Axis* yAxis; int hide; - int state; int drawUnder; int xOffset; int yOffset; @@ -70,7 +69,7 @@ namespace Blt { void map(); int pointIn(Point2d*); int regionIn(Region2d*, int); - void print(Blt_Ps); + void print(PostScript*); public: BitmapMarker(Graph*, const char*, Tcl_HashEntry*); diff --git a/src/bltConfig.C b/src/bltConfig.C index 0e5d786..d76c4d1 100644 --- a/src/bltConfig.C +++ b/src/bltConfig.C @@ -53,9 +53,6 @@ void RestoreProc(ClientData clientData, Tk_Window tkwin, // Fill const char* fillObjOption[] = {"none", "x", "y", "both", NULL}; -// State -const char* stateObjOption[] = {"normal", "active", "disabled", NULL}; - // Dashes static Tk_CustomOptionSetProc DashesSetProc; static Tk_CustomOptionGetProc DashesGetProc; diff --git a/src/bltConfig.h b/src/bltConfig.h index 1a8b28d..d38f6cd 100644 --- a/src/bltConfig.h +++ b/src/bltConfig.h @@ -35,11 +35,7 @@ #include -#define BLT_STATE_NORMAL (0) -#define BLT_STATE_DISABLED (1<<1) - extern const char* fillObjOption[]; -extern const char* stateObjOption[]; extern Tk_ObjCustomOption dashesObjOption; extern Tk_ObjCustomOption listObjOption; diff --git a/src/bltGrAxis.C b/src/bltGrAxis.C index b5ade9e..a06f3f0 100644 --- a/src/bltGrAxis.C +++ b/src/bltGrAxis.C @@ -1660,17 +1660,17 @@ void Axis::makeGridLine(double value, Segment2d *sp) } } -void Axis::print(Blt_Ps ps) +void Axis::print(PostScript* psPtr) { AxisOptions* ops = (AxisOptions*)ops_; if (ops->hide || !use_) return; - Blt_Ps_Format(ps, "%% Axis \"%s\"\n", name_); + psPtr->format("%% Axis \"%s\"\n", name_); if (ops->normalBg) { int relief = active_ ? ops->activeRelief : ops->relief; - Blt_Ps_Fill3DRectangle(ps, ops->normalBg, left_, top_, + psPtr->fill3DRectangle(ops->normalBg, left_, top_, right_ - left_, bottom_ - top_, ops->borderWidth, relief); } @@ -1688,7 +1688,7 @@ void Axis::print(Blt_Ps ps) ts.xPad_ = 1; ts.yPad_ = 0; - ts.printText(ps, ops->title, titlePos_.x, titlePos_.y); + ts.printText(psPtr, ops->title, titlePos_.x, titlePos_.y); } if (ops->showTicks) { @@ -1706,40 +1706,40 @@ void Axis::print(Blt_Ps ps) for (Blt_ChainLink link=Blt_Chain_FirstLink(tickLabels_); link; link = Blt_Chain_NextLink(link)) { TickLabel *labelPtr = (TickLabel*)Blt_Chain_GetValue(link); - ts.printText(ps, labelPtr->string, labelPtr->anchorPos.x, + ts.printText(psPtr, labelPtr->string, labelPtr->anchorPos.x, labelPtr->anchorPos.y); } } if ((nSegments_ > 0) && (ops->lineWidth > 0)) { - Blt_Ps_XSetLineAttributes(ps, ops->tickColor, ops->lineWidth, - (Dashes*)NULL, CapButt, JoinMiter); - graphPtr_->printSegments(ps, segments_, nSegments_); + psPtr->setLineAttributes(ops->tickColor, ops->lineWidth, + (Dashes*)NULL, CapButt, JoinMiter); + psPtr->drawSegments(segments_, nSegments_); } } -void Axis::printGrids(Blt_Ps ps) +void Axis::printGrids(PostScript* psPtr) { AxisOptions* ops = (AxisOptions*)ops_; if (ops->hide || !ops->showGrid || !use_) return; - Blt_Ps_Format(ps, "%% Axis %s: grid line attributes\n", name_); - Blt_Ps_XSetLineAttributes(ps, ops->major.color, ops->major.lineWidth, + psPtr->format("%% Axis %s: grid line attributes\n", name_); + psPtr->setLineAttributes(ops->major.color, ops->major.lineWidth, &ops->major.dashes, CapButt, JoinMiter); - Blt_Ps_Format(ps, "%% Axis %s: major grid line segments\n", name_); - graphPtr_->printSegments(ps, ops->major.segments, ops->major.nUsed); + psPtr->format("%% Axis %s: major grid line segments\n", name_); + psPtr->drawSegments(ops->major.segments, ops->major.nUsed); if (ops->showGridMinor) { - Blt_Ps_XSetLineAttributes(ps, ops->minor.color, ops->minor.lineWidth, - &ops->minor.dashes, CapButt, JoinMiter); - Blt_Ps_Format(ps, "%% Axis %s: minor grid line segments\n", name_); - graphPtr_->printSegments(ps, ops->minor.segments, ops->minor.nUsed); + psPtr->setLineAttributes(ops->minor.color, ops->minor.lineWidth, + &ops->minor.dashes, CapButt, JoinMiter); + psPtr->format("%% Axis %s: minor grid line segments\n", name_); + psPtr->drawSegments(ops->minor.segments, ops->minor.nUsed); } } -void Axis::printLimits(Blt_Ps ps) +void Axis::printLimits(PostScript* psPtr) { AxisOptions* ops = (AxisOptions*)ops_; GraphOptions* gops = (GraphOptions*)graphPtr_->ops_; @@ -1775,40 +1775,42 @@ void Axis::printLimits(Blt_Ps ps) int textWidth, textHeight; TextStyle ts(graphPtr_, &ops->limitsTextStyle); if (maxPtr) { - graphPtr_->getTextExtents(ops->tickFont, maxPtr, -1, &textWidth, &textHeight); + graphPtr_->getTextExtents(ops->tickFont, maxPtr, -1, + &textWidth, &textHeight); if ((textWidth > 0) && (textHeight > 0)) { if (isHoriz) { ops->limitsTextStyle.angle = 90.0; ops->limitsTextStyle.anchor = TK_ANCHOR_SE; - ts.printText(ps, maxPtr, (double)graphPtr_->right_, hMax); + ts.printText(psPtr, maxPtr, (double)graphPtr_->right_, hMax); hMax -= (textWidth + spacing); } else { ops->limitsTextStyle.angle = 0.0; ops->limitsTextStyle.anchor = TK_ANCHOR_NW; - ts.printText(ps, maxPtr, vMax, (double)graphPtr_->top_); + ts.printText(psPtr, maxPtr, vMax, (double)graphPtr_->top_); vMax += (textWidth + spacing); } } } if (minPtr) { - graphPtr_->getTextExtents(ops->tickFont, minPtr, -1, &textWidth, &textHeight); + graphPtr_->getTextExtents(ops->tickFont, minPtr, -1, + &textWidth, &textHeight); if ((textWidth > 0) && (textHeight > 0)) { ops->limitsTextStyle.anchor = TK_ANCHOR_SW; if (isHoriz) { ops->limitsTextStyle.angle = 90.0; - ts.printText(ps, minPtr, (double)graphPtr_->left_, hMin); + ts.printText(psPtr, minPtr, (double)graphPtr_->left_, hMin); hMin -= (textWidth + spacing); } else { ops->limitsTextStyle.angle = 0.0; - ts.printText(ps, minPtr, vMin, (double)graphPtr_->bottom_); + ts.printText(psPtr, minPtr, vMin, (double)graphPtr_->bottom_); vMin += (textWidth + spacing); } } diff --git a/src/bltGrAxis.h b/src/bltGrAxis.h index b415935..644a60f 100644 --- a/src/bltGrAxis.h +++ b/src/bltGrAxis.h @@ -227,9 +227,9 @@ class Axis { void draw(Drawable); void drawGrids(Drawable); void drawLimits(Drawable); - void print(Blt_Ps); - void printGrids(Blt_Ps); - void printLimits(Blt_Ps); + void print(PostScript*); + void printGrids(PostScript*); + void printLimits(PostScript*); void mapStacked(int, int); void mapGridlines(); diff --git a/src/bltGrElem.h b/src/bltGrElem.h index 6e857e8..b8edfe9 100644 --- a/src/bltGrElem.h +++ b/src/bltGrElem.h @@ -152,9 +152,9 @@ class Element { virtual void drawActive(Drawable) =0; virtual void drawSymbol(Drawable, int, int, int) =0; virtual void closest() =0; - virtual void print(Blt_Ps) =0; - virtual void printActive(Blt_Ps) =0; - virtual void printSymbol(Blt_Ps, double, double, int) =0; + virtual void print(PostScript*) =0; + virtual void printActive(PostScript*) =0; + virtual void printSymbol(PostScript*, double, double, int) =0; virtual ClassId classId() =0; virtual const char* className() =0; diff --git a/src/bltGrElemBar.C b/src/bltGrElemBar.C index f4bfd17..09cd1fb 100644 --- a/src/bltGrElemBar.C +++ b/src/bltGrElemBar.C @@ -744,7 +744,7 @@ void BarElement::drawSymbol(Drawable drawable, int x, int y, int size) size, size); } -void BarElement::print(Blt_Ps ps) +void BarElement::print(PostScript* psPtr) { BarElementOptions* ops = (BarElementOptions*)ops_; @@ -752,7 +752,7 @@ void BarElement::print(Blt_Ps ps) return; // Comment the PostScript to indicate the start of the element - Blt_Ps_Format(ps, "\n%% Element \"%s\"\n\n", name_); + psPtr->format("\n%% Element \"%s\"\n\n", name_); int count = 0; for (Blt_ChainLink link = Blt_Chain_FirstLink(ops->stylePalette); link; @@ -762,35 +762,33 @@ void BarElement::print(Blt_Ps ps) BarPen* penPtr = (BarPen*)stylePtr->penPtr; BarPenOptions* pops = (BarPenOptions*)penPtr->ops(); if (stylePtr->nBars > 0) - printSegments(ps, penPtr, stylePtr->bars, stylePtr->nBars); + printSegments(psPtr, penPtr, stylePtr->bars, stylePtr->nBars); XColor* colorPtr = pops->errorBarColor; if (!colorPtr) colorPtr = pops->outlineColor; if ((stylePtr->xeb.length > 0) && (pops->errorBarShow & SHOW_X)) { - Blt_Ps_XSetLineAttributes(ps, colorPtr, pops->errorBarLineWidth, - NULL, CapButt, JoinMiter); - graphPtr_->printSegments(ps, stylePtr->xeb.segments, - stylePtr->xeb.length); + psPtr->setLineAttributes(colorPtr, pops->errorBarLineWidth, + NULL, CapButt, JoinMiter); + psPtr->drawSegments(stylePtr->xeb.segments, stylePtr->xeb.length); } if ((stylePtr->yeb.length > 0) && (pops->errorBarShow & SHOW_Y)) { - Blt_Ps_XSetLineAttributes(ps, colorPtr, pops->errorBarLineWidth, - NULL, CapButt, JoinMiter); - graphPtr_->printSegments(ps, stylePtr->yeb.segments, - stylePtr->yeb.length); + psPtr->setLineAttributes(colorPtr, pops->errorBarLineWidth, + NULL, CapButt, JoinMiter); + psPtr->drawSegments(stylePtr->yeb.segments, stylePtr->yeb.length); } if (pops->valueShow != SHOW_NONE) - printValues(ps, penPtr, stylePtr->bars, stylePtr->nBars, + printValues(psPtr, penPtr, stylePtr->bars, stylePtr->nBars, barToData_ + count); count += stylePtr->nBars; } } -void BarElement::printActive(Blt_Ps ps) +void BarElement::printActive(PostScript* psPtr) { BarElementOptions* ops = (BarElementOptions*)ops_; @@ -802,22 +800,22 @@ void BarElement::printActive(Blt_Ps ps) return; BarPenOptions* pops = (BarPenOptions*)penPtr->ops(); - Blt_Ps_Format(ps, "\n%% Active Element \"%s\"\n\n", name_); + psPtr->format("\n%% Active Element \"%s\"\n\n", name_); if (nActiveIndices_ > 0) { mapActive(); - printSegments(ps, penPtr, activeRects_, nActive_); + printSegments(psPtr, penPtr, activeRects_, nActive_); if (pops->valueShow != SHOW_NONE) - printValues(ps, penPtr, activeRects_, nActive_,activeToData_); + printValues(psPtr, penPtr, activeRects_, nActive_,activeToData_); } else if (nActiveIndices_ < 0) { - printSegments(ps, penPtr, bars_, nBars_); + printSegments(psPtr, penPtr, bars_, nBars_); if (pops->valueShow != SHOW_NONE) - printValues(ps, penPtr, bars_, nBars_, barToData_); + printValues(psPtr, penPtr, bars_, nBars_, barToData_); } } -void BarElement::printSymbol(Blt_Ps ps, double x, double y, int size) +void BarElement::printSymbol(PostScript* psPtr, double x, double y, int size) { BarElementOptions* ops = (BarElementOptions*)ops_; @@ -831,16 +829,16 @@ void BarElement::printSymbol(Blt_Ps ps, double x, double y, int size) * Build a PostScript procedure to draw the fill and outline of the symbol * after the path of the symbol shape has been formed */ - Blt_Ps_Append(ps, "\n" + psPtr->append("\n" "/DrawSymbolProc {\n" "gsave\n "); if (pops->outlineColor) { - Blt_Ps_XSetForeground(ps, pops->outlineColor); - Blt_Ps_Append(ps, " fill\n"); + psPtr->setForeground(pops->outlineColor); + psPtr->append(" fill\n"); } - Blt_Ps_Append(ps, " grestore\n"); - Blt_Ps_Append(ps, "} def\n\n"); - Blt_Ps_Format(ps, "%g %g %d Sq\n", x, y, size); + psPtr->append(" grestore\n"); + psPtr->append("} def\n\n"); + psPtr->format("%g %g %d Sq\n", x, y, size); } // Support @@ -1255,8 +1253,8 @@ void BarElement::drawValues(Drawable drawable, BarPen* penPtr, } } -void BarElement::printSegments(Blt_Ps ps, BarPen* penPtr, XRectangle *bars, - int nBars) +void BarElement::printSegments(PostScript* psPtr, BarPen* penPtr, + XRectangle *bars, int nBars) { BarPenOptions* pops = (BarPenOptions*)penPtr->ops(); XRectangle *rp, *rend; @@ -1269,21 +1267,20 @@ void BarElement::printSegments(Blt_Ps ps, BarPen* penPtr, XRectangle *bars, continue; } if (pops->outlineColor) { - Blt_Ps_XSetForeground(ps, pops->outlineColor); - Blt_Ps_XFillRectangle(ps, (double)rp->x, (double)rp->y, - (int)rp->width - 1, (int)rp->height - 1); + psPtr->setForeground(pops->outlineColor); + psPtr->fillRectangle((double)rp->x, (double)rp->y, + (int)rp->width - 1, (int)rp->height - 1); } if ((pops->fill) && (pops->borderWidth > 0) && - (pops->relief != TK_RELIEF_FLAT)) { - Blt_Ps_Draw3DRectangle(ps, pops->fill, (double)rp->x, (double)rp->y, + (pops->relief != TK_RELIEF_FLAT)) + psPtr->draw3DRectangle(pops->fill, (double)rp->x, (double)rp->y, (int)rp->width, (int)rp->height, pops->borderWidth, pops->relief); - } } } -void BarElement::printValues(Blt_Ps ps, BarPen* penPtr, XRectangle *bars, - int nBars, int *barToData) +void BarElement::printValues(PostScript* psPtr, BarPen* penPtr, + XRectangle *bars, int nBars, int *barToData) { BarPenOptions* pops = (BarPenOptions*)penPtr->ops(); BarElementOptions* ops = (BarElementOptions*)ops_; @@ -1326,7 +1323,7 @@ void BarElement::printValues(Blt_Ps ps, BarPen* penPtr, XRectangle *bars, anchorPos.y += rp->height; } - ts.printText(ps, string, anchorPos.x, anchorPos.y); + ts.printText(psPtr, string, anchorPos.x, anchorPos.y); } } diff --git a/src/bltGrElemBar.h b/src/bltGrElemBar.h index 92ff66b..21b8397 100644 --- a/src/bltGrElemBar.h +++ b/src/bltGrElemBar.h @@ -104,8 +104,8 @@ class BarElement : public Element { void mapErrorBars(BarStyle**); void drawSegments(Drawable, BarPen*, XRectangle*, int); void drawValues(Drawable, BarPen*, XRectangle*, int, int*); - void printSegments(Blt_Ps, BarPen*, XRectangle*, int); - void printValues(Blt_Ps, BarPen*, XRectangle*, int, int*); + void printSegments(PostScript*, BarPen*, XRectangle*, int); + void printValues(PostScript*, BarPen*, XRectangle*, int, int*); public: BarElement(Graph*, const char*, Tcl_HashEntry*); @@ -122,9 +122,9 @@ class BarElement : public Element { void draw(Drawable); void drawActive(Drawable); void drawSymbol(Drawable, int, int, int); - void print(Blt_Ps); - void printActive(Blt_Ps); - void printSymbol(Blt_Ps, double, double, int); + void print(PostScript*); + void printActive(PostScript*); + void printSymbol(PostScript*, double, double, int); }; #endif diff --git a/src/bltGrElemLine.C b/src/bltGrElemLine.C index 94fa14b..58c8980 100644 --- a/src/bltGrElemLine.C +++ b/src/bltGrElemLine.C @@ -653,7 +653,7 @@ void LineElement::drawSymbol(Drawable drawable, int x, int y, int size) } } -void LineElement::print(Blt_Ps ps) +void LineElement::print(PostScript* psPtr) { LineElementOptions* ops = (LineElementOptions*)ops_; LinePen* penPtr = NORMALPEN(ops); @@ -662,27 +662,27 @@ void LineElement::print(Blt_Ps ps) if (ops->hide) return; - Blt_Ps_Format(ps, "\n%% Element \"%s\"\n\n", name_); + psPtr->format("\n%% Element \"%s\"\n\n", name_); // Draw fill area if (fillPts_) { // Create a path to use for both the polygon and its outline - Blt_Ps_Append(ps, "% start fill area\n"); - graphPtr_->printPolyline(ps, fillPts_, nFillPts_); + psPtr->append("% start fill area\n"); + psPtr->drawPolyline(fillPts_, nFillPts_); // If the background fill color was specified, draw the polygon in a // solid fashion with that color if (ops->fillBg) - Blt_Ps_Append(ps, "gsave fill grestore\n"); + psPtr->append("gsave fill grestore\n"); else - Blt_Ps_Append(ps, "gsave fill grestore\n"); + psPtr->append("gsave fill grestore\n"); - Blt_Ps_Append(ps, "% end fill area\n"); + psPtr->append("% end fill area\n"); } // traces if ((Blt_Chain_GetLength(traces_) > 0) && (penOps->traceWidth > 0)) - printTraces(ps, penPtr); + printTraces(psPtr, penPtr); // Draw symbols, error bars, values unsigned int count =0; @@ -697,31 +697,29 @@ void LineElement::print(Blt_Ps ps) colorPtr = penOps->traceColor; if ((stylePtr->xeb.length > 0) && (penOps->errorBarShow & SHOW_X)) { - Blt_Ps_XSetLineAttributes(ps, colorPtr, penOps->errorBarLineWidth, + psPtr->setLineAttributes(colorPtr, penOps->errorBarLineWidth, NULL, CapButt, JoinMiter); - graphPtr_->printSegments(ps, stylePtr->xeb.segments, - stylePtr->xeb.length); + psPtr->drawSegments(stylePtr->xeb.segments, stylePtr->xeb.length); } if ((stylePtr->yeb.length > 0) && (penOps->errorBarShow & SHOW_Y)) { - Blt_Ps_XSetLineAttributes(ps, colorPtr, penOps->errorBarLineWidth, + psPtr->setLineAttributes(colorPtr, penOps->errorBarLineWidth, NULL, CapButt, JoinMiter); - graphPtr_->printSegments(ps, stylePtr->yeb.segments, - stylePtr->yeb.length); + psPtr->drawSegments(stylePtr->yeb.segments, stylePtr->yeb.length); } if ((stylePtr->symbolPts.length > 0) && (penOps->symbol.type != SYMBOL_NONE)) { - printSymbols(ps, penPtr, stylePtr->symbolSize, + printSymbols(psPtr, penPtr, stylePtr->symbolSize, stylePtr->symbolPts.length, stylePtr->symbolPts.points); } if (penOps->valueShow != SHOW_NONE) { - printValues(ps, penPtr, stylePtr->symbolPts.length, + printValues(psPtr, penPtr, stylePtr->symbolPts.length, stylePtr->symbolPts.points, symbolPts_.map + count); } count += stylePtr->symbolPts.length; } } -void LineElement::printActive(Blt_Ps ps) +void LineElement::printActive(PostScript* psPtr) { LineElementOptions* ops = (LineElementOptions*)ops_; LinePen* penPtr = (LinePen *)ops->activePenPtr; @@ -732,35 +730,35 @@ void LineElement::printActive(Blt_Ps ps) if (ops->hide || !active_) return; - Blt_Ps_Format(ps, "\n%% Active Element \"%s\"\n\n", name_); + psPtr->format("\n%% Active Element \"%s\"\n\n", name_); int symbolSize = scaleSymbol(penOps->symbol.size); if (nActiveIndices_ > 0) { mapActiveSymbols(); if (penOps->symbol.type != SYMBOL_NONE) - printSymbols(ps, penPtr, symbolSize, activePts_.length, + printSymbols(psPtr, penPtr, symbolSize, activePts_.length, activePts_.points); if (penOps->valueShow != SHOW_NONE) - printValues(ps, penPtr, activePts_.length, activePts_.points, + printValues(psPtr, penPtr, activePts_.length, activePts_.points, activePts_.map); } else if (nActiveIndices_ < 0) { if ((Blt_Chain_GetLength(traces_) > 0) && (penOps->traceWidth > 0)) - printTraces(ps, (LinePen*)penPtr); + printTraces(psPtr, (LinePen*)penPtr); if (penOps->symbol.type != SYMBOL_NONE) - printSymbols(ps, penPtr, symbolSize, symbolPts_.length, + printSymbols(psPtr, penPtr, symbolSize, symbolPts_.length, symbolPts_.points); if (penOps->valueShow != SHOW_NONE) { - printValues(ps, penPtr, symbolPts_.length, symbolPts_.points, + printValues(psPtr, penPtr, symbolPts_.length, symbolPts_.points, symbolPts_.map); } } } -void LineElement::printSymbol(Blt_Ps ps, double x, double y, int size) +void LineElement::printSymbol(PostScript* psPtr, double x, double y, int size) { LineElementOptions* ops = (LineElementOptions*)ops_; @@ -768,20 +766,18 @@ void LineElement::printSymbol(Blt_Ps ps, double x, double y, int size) LinePenOptions* penOps = (LinePenOptions*)penPtr->ops(); if (penOps->traceWidth > 0) { - /* - * Draw an extra line offset by one pixel from the previous to give a - * thicker appearance. This is only for the legend entry. This routine - * is never called for drawing the actual line segments. - */ - Blt_Ps_XSetLineAttributes(ps, penOps->traceColor, penOps->traceWidth, + // Draw an extra line offset by one pixel from the previous to give a + // thicker appearance. This is only for the legend entry. This routine + // is never called for drawing the actual line segments. + psPtr->setLineAttributes(penOps->traceColor, penOps->traceWidth, &penOps->traceDashes, CapButt, JoinMiter); - Blt_Ps_Format(ps, "%g %g %d Li\n", x, y, size + size); + psPtr->format("%g %g %d Li\n", x, y, size + size); } if (penOps->symbol.type != SYMBOL_NONE) { Point2d point; point.x = x; point.y = y; - printSymbols(ps, penPtr, size, 1, &point); + printSymbols(psPtr, penPtr, size, 1, &point); } } @@ -2626,7 +2622,7 @@ void LineElement::drawValues(Drawable drawable, LinePen* penPtr, } } -void LineElement::getSymbolPostScriptInfo(Blt_Ps ps, LinePen* penPtr, int size) +void LineElement::getSymbolPostScriptInfo(PostScript* psPtr, LinePen* penPtr, int size) { LinePenOptions* pops = (LinePenOptions*)penPtr->ops(); @@ -2640,11 +2636,11 @@ void LineElement::getSymbolPostScriptInfo(Blt_Ps ps, LinePen* penPtr, int size) outlineColor = pops->traceColor; if (pops->symbol.type == SYMBOL_NONE) - Blt_Ps_XSetLineAttributes(ps, pops->traceColor, pops->traceWidth + 2, - &pops->traceDashes, CapButt, JoinMiter); + psPtr->setLineAttributes(pops->traceColor, pops->traceWidth + 2, + &pops->traceDashes, CapButt, JoinMiter); else { - Blt_Ps_XSetLineWidth(ps, pops->symbol.outlineWidth); - Blt_Ps_XSetDashes(ps, (Dashes *)NULL); + psPtr->setLineWidth(pops->symbol.outlineWidth); + psPtr->setDashes(NULL); } /* @@ -2652,7 +2648,7 @@ void LineElement::getSymbolPostScriptInfo(Blt_Ps ps, LinePen* penPtr, int size) * both the bitmap and its mask. Otherwise fill and stroke the path formed * already. */ - Blt_Ps_Append(ps, "\n/DrawSymbolProc {\n"); + psPtr->append("\n/DrawSymbolProc {\n"); switch (pops->symbol.type) { case SYMBOL_NONE: break; /* Do nothing */ @@ -2671,37 +2667,35 @@ void LineElement::getSymbolPostScriptInfo(Blt_Ps ps, LinePen* penPtr, int size) scale = MIN(sx, sy); if (pops->symbol.mask != None) { - Blt_Ps_VarAppend(ps, "\n % Bitmap mask is \"", - Tk_NameOfBitmap(graphPtr_->display_, pops->symbol.mask), + psPtr->varAppend("\n % Bitmap mask is \"", + Tk_NameOfBitmap(graphPtr_->display_,pops->symbol.mask), "\"\n\n ", NULL); - Blt_Ps_XSetBackground(ps, fillColor); - Blt_Ps_DrawBitmap(ps, graphPtr_->display_, pops->symbol.mask, - scale, scale); + psPtr->setBackground(fillColor); + psPtr->drawBitmap(graphPtr_->display_, pops->symbol.mask, scale, scale); } - Blt_Ps_VarAppend(ps, "\n % Bitmap symbol is \"", - Tk_NameOfBitmap(graphPtr_->display_, pops->symbol.bitmap), + psPtr->varAppend("\n % Bitmap symbol is \"", + Tk_NameOfBitmap(graphPtr_->display_,pops->symbol.bitmap), "\"\n\n ", NULL); - Blt_Ps_XSetForeground(ps, outlineColor); - Blt_Ps_DrawBitmap(ps, graphPtr_->display_, pops->symbol.bitmap, - scale, scale); + psPtr->setForeground(outlineColor); + psPtr->drawBitmap(graphPtr_->display_, pops->symbol.bitmap, scale, scale); } break; default: - Blt_Ps_Append(ps, " "); - Blt_Ps_XSetBackground(ps, fillColor); - Blt_Ps_Append(ps, " gsave fill grestore\n"); + psPtr->append(" "); + psPtr->setBackground(fillColor); + psPtr->append(" gsave fill grestore\n"); if (pops->symbol.outlineWidth > 0) { - Blt_Ps_Append(ps, " "); - Blt_Ps_XSetForeground(ps, outlineColor); - Blt_Ps_Append(ps, " stroke\n"); + psPtr->append(" "); + psPtr->setForeground(outlineColor); + psPtr->append(" stroke\n"); } break; } - Blt_Ps_Append(ps, "} def\n\n"); + psPtr->append("} def\n\n"); } -void LineElement::printSymbols(Blt_Ps ps, LinePen* penPtr, int size, +void LineElement::printSymbols(PostScript* psPtr, LinePen* penPtr, int size, int nSymbolPts, Point2d *symbolPts) { LinePenOptions* pops = (LinePenOptions*)penPtr->ops(); @@ -2711,7 +2705,7 @@ void LineElement::printSymbols(Blt_Ps ps, LinePen* penPtr, int size, { "Li", "Sq", "Ci", "Di", "Pl", "Cr", "Sp", "Sc", "Tr", "Ar", "Bm", NULL }; - getSymbolPostScriptInfo(ps, penPtr, size); + getSymbolPostScriptInfo(psPtr, penPtr, size); symbolSize = (double)size; switch (pops->symbol.type) { @@ -2736,47 +2730,48 @@ void LineElement::printSymbols(Blt_Ps ps, LinePen* penPtr, int size, Point2d *pp, *endp; for (pp = symbolPts, endp = symbolPts + nSymbolPts; pp < endp; pp++) { - Blt_Ps_Format(ps, "%g %g %g %s\n", pp->x, pp->y, + psPtr->format("%g %g %g %s\n", pp->x, pp->y, symbolSize, symbolMacros[pops->symbol.type]); } } -void LineElement::setLineAttributes(Blt_Ps ps, LinePen* penPtr) +void LineElement::setLineAttributes(PostScript* psPtr, LinePen* penPtr) { LinePenOptions* pops = (LinePenOptions*)penPtr->ops(); - /* Set the attributes of the line (color, dashes, linewidth) */ - Blt_Ps_XSetLineAttributes(ps, pops->traceColor, pops->traceWidth, - &pops->traceDashes, CapButt, JoinMiter); + psPtr->setLineAttributes(pops->traceColor, pops->traceWidth, + &pops->traceDashes, CapButt, JoinMiter); + if ((LineIsDashed(pops->traceDashes)) && (pops->traceOffColor)) { - Blt_Ps_Append(ps, "/DashesProc {\n gsave\n "); - Blt_Ps_XSetBackground(ps, pops->traceOffColor); - Blt_Ps_Append(ps, " "); - Blt_Ps_XSetDashes(ps, (Dashes*)NULL); - Blt_Ps_Append(ps, "stroke\n grestore\n} def\n"); + psPtr->append("/DashesProc {\n gsave\n "); + psPtr->setBackground(pops->traceOffColor); + psPtr->append(" "); + psPtr->setDashes(NULL); + psPtr->append("stroke\n grestore\n} def\n"); } else { - Blt_Ps_Append(ps, "/DashesProc {} def\n"); + psPtr->append("/DashesProc {} def\n"); } } -void LineElement::printTraces(Blt_Ps ps, LinePen* penPtr) +void LineElement::printTraces(PostScript* psPtr, LinePen* penPtr) { - setLineAttributes(ps, penPtr); + setLineAttributes(psPtr, penPtr); for (Blt_ChainLink link = Blt_Chain_FirstLink(traces_); link; link = Blt_Chain_NextLink(link)) { bltTrace *tracePtr = (bltTrace*)Blt_Chain_GetValue(link); if (tracePtr->screenPts.length > 0) { - Blt_Ps_Append(ps, "% start trace\n"); - graphPtr_->printMaxPolyline(ps, tracePtr->screenPts.points, - tracePtr->screenPts.length); - Blt_Ps_Append(ps, "% end trace\n"); + psPtr->append("% start trace\n"); + psPtr->drawMaxPolyline(tracePtr->screenPts.points, + tracePtr->screenPts.length); + psPtr->append("% end trace\n"); } } } -void LineElement::printValues(Blt_Ps ps, LinePen* penPtr, int nSymbolPts, - Point2d *symbolPts, int *pointToData) +void LineElement::printValues(PostScript* psPtr, LinePen* penPtr, + int nSymbolPts, Point2d *symbolPts, + int *pointToData) { LineElementOptions* ops = (LineElementOptions*)ops_; LinePenOptions* pops = (LinePenOptions*)penPtr->ops(); @@ -2804,7 +2799,7 @@ void LineElement::printValues(Blt_Ps ps, LinePen* penPtr, int nSymbolPts, snprintf(string + strlen(string), TCL_DOUBLE_SPACE, fmt, y); } - ts.printText(ps, string, pp->x, pp->y); + ts.printText(psPtr, string, pp->x, pp->y); } } diff --git a/src/bltGrElemLine.h b/src/bltGrElemLine.h index 6611198..29dcdd4 100644 --- a/src/bltGrElemLine.h +++ b/src/bltGrElemLine.h @@ -137,14 +137,14 @@ class LineElement : public Element { void drawSymbols(Drawable, LinePen*, int, int, Point2d*); void drawTraces(Drawable, LinePen*); void drawValues(Drawable, LinePen*, int, Point2d*, int*); - void setLineAttributes(Blt_Ps, LinePen*); - void printTraces(Blt_Ps, LinePen*); - void printValues(Blt_Ps, LinePen*, int, Point2d*, int*); - void printSymbols(Blt_Ps, LinePen*, int, int, Point2d*); + void setLineAttributes(PostScript*, LinePen*); + void printTraces(PostScript*, LinePen*); + void printValues(PostScript*, LinePen*, int, Point2d*, int*); + void printSymbols(PostScript*, LinePen*, int, int, Point2d*); double distanceToLine(int, int, Point2d*, Point2d*, Point2d*); double distanceToX(int, int, Point2d*, Point2d*, Point2d*); double distanceToY(int, int, Point2d*, Point2d*, Point2d*); - void getSymbolPostScriptInfo(Blt_Ps, LinePen*, int); + void getSymbolPostScriptInfo(PostScript*, LinePen*, int); int simplify(Point2d*, int, int, double, int*); double findSplit(Point2d*, int, int, int*); @@ -163,9 +163,9 @@ class LineElement : public Element { void draw(Drawable); void drawActive(Drawable); void drawSymbol(Drawable, int, int, int); - void print(Blt_Ps); - void printActive(Blt_Ps); - void printSymbol(Blt_Ps, double, double, int); + void print(PostScript*); + void printActive(PostScript*); + void printSymbol(PostScript*, double, double, int); }; #endif diff --git a/src/bltGrLegd.C b/src/bltGrLegd.C index dcc59d1..e8ea6fe 100644 --- a/src/bltGrLegd.C +++ b/src/bltGrLegd.C @@ -494,15 +494,13 @@ void Legend::draw(Drawable drawable) if (isSelected) { XColor* color = (flags & FOCUS) ? ops->selInFocusFgColor : ops->selOutFocusFgColor; - XSetForeground(graphPtr_->display_, focusGC_, - color->pixel); + XSetForeground(graphPtr_->display_, focusGC_, color->pixel); } XDrawRectangle(graphPtr_->display_, pixmap, focusGC_, x + 1, y + 1, entryWidth_ - 3, entryHeight_ - 3); if (isSelected) - XSetForeground(graphPtr_->display_, focusGC_, - ops->focusColor->pixel); + XSetForeground(graphPtr_->display_, focusGC_, ops->focusColor->pixel); } // Check when to move to the next column @@ -545,7 +543,7 @@ void Legend::draw(Drawable drawable) Tk_FreePixmap(graphPtr_->display_, pixmap); } -void Legend::print(Blt_Ps ps) +void Legend::print(PostScript* psPtr) { LegendOptions* ops = (LegendOptions*)ops_; GraphOptions* gops = (GraphOptions*)graphPtr_->ops_; @@ -561,19 +559,19 @@ void Legend::print(Blt_Ps ps) int width = width_ - 2*ops->xPad; int height = height_ - 2*ops->yPad; - Blt_Ps_Append(ps, "% Legend\n"); + psPtr->append("% Legend\n"); if (pops->decorations) { if (ops->normalBg) - Blt_Ps_Fill3DRectangle(ps, ops->normalBg, x, y, width, height, + psPtr->fill3DRectangle(ops->normalBg, x, y, width, height, ops->borderWidth, ops->relief); else - Blt_Ps_Draw3DRectangle(ps, gops->normalBg, x, y, width, height, + psPtr->draw3DRectangle(gops->normalBg, x, y, width, height, ops->borderWidth, ops->relief); } else { - Blt_Ps_SetClearBackground(ps); - Blt_Ps_XFillRectangle(ps, x, y, width, height); + psPtr->setClearBackground(); + psPtr->fillRectangle(x, y, width, height); } Tk_FontMetrics fontMetrics; @@ -588,7 +586,7 @@ void Legend::print(Blt_Ps ps) x += ops->borderWidth; y += ops->borderWidth; TextStyle tts(graphPtr_, &ops->titleStyle); - tts.printText(ps, ops->title, x, y); + tts.printText(psPtr, ops->title, x, y); if (titleHeight_ > 0) y += titleHeight_ + ops->yPad; @@ -606,21 +604,20 @@ void Legend::print(Blt_Ps ps) if (elemPtr->labelActive_) { ops->style.color = ops->activeFgColor; - Blt_Ps_Fill3DRectangle(ps, ops->activeBg, x, y, entryWidth_, + psPtr->fill3DRectangle(ops->activeBg, x, y, entryWidth_, entryHeight_, ops->entryBW, ops->activeRelief); } else { ops->style.color = ops->fgColor; if (elemOps->legendRelief != TK_RELIEF_FLAT) { - Blt_Ps_Draw3DRectangle(ps, gops->normalBg, x, y, - entryWidth_, - entryHeight_, ops->entryBW, - elemOps->legendRelief); + psPtr->draw3DRectangle(gops->normalBg, x, y, entryWidth_, entryHeight_, + ops->entryBW, elemOps->legendRelief); } } - elemPtr->printSymbol(ps, x + xSymbol, y + ySymbol, symbolSize); - ts.printText(ps, elemOps->label, x + xLabel, y + ops->entryBW + ops->iyPad); + elemPtr->printSymbol(psPtr, x + xSymbol, y + ySymbol, symbolSize); + ts.printText(psPtr, elemOps->label, x + xLabel, + y + ops->entryBW + ops->iyPad); count++; if ((count % nRows_) > 0) diff --git a/src/bltGrLegd.h b/src/bltGrLegd.h index 9dbda2a..8eccdfb 100644 --- a/src/bltGrLegd.h +++ b/src/bltGrLegd.h @@ -151,7 +151,7 @@ class Legend : public Pick { int configure(); void map(int, int); void draw(Drawable drawable); - void print(Blt_Ps ps); + void print(PostScript* ps); void eventuallyInvokeSelectCmd(); void removeElement(Element*); diff --git a/src/bltGrMarker.h b/src/bltGrMarker.h index 827262e..844282a 100644 --- a/src/bltGrMarker.h +++ b/src/bltGrMarker.h @@ -57,7 +57,6 @@ namespace Blt { Axis* xAxis; Axis* yAxis; int hide; - int state; int drawUnder; int xOffset; int yOffset; @@ -93,7 +92,7 @@ namespace Blt { virtual void map() =0; virtual int pointIn(Point2d*) =0; virtual int regionIn(Region2d*, int) =0; - virtual void print(Blt_Ps) =0; + virtual void print(PostScript*) =0; virtual ClassId classId() =0; virtual const char* className() =0; diff --git a/src/bltGrMarkerLine.C b/src/bltGrMarkerLine.C index 50031ee..b973e97 100644 --- a/src/bltGrMarkerLine.C +++ b/src/bltGrMarkerLine.C @@ -78,8 +78,6 @@ static Tk_OptionSpec optionSpecs[] = { {TK_OPTION_COLOR, "-outline", "outline", "Outline", STD_NORMAL_FOREGROUND, -1, Tk_Offset(LineMarkerOptions, outlineColor), TK_OPTION_NULL_OK, NULL, 0}, - {TK_OPTION_STRING_TABLE, "-state", "state", "State", - "normal", -1, Tk_Offset(LineMarkerOptions, state), 0, &stateObjOption, 0}, {TK_OPTION_BOOLEAN, "-under", "under", "Under", "no", -1, Tk_Offset(LineMarkerOptions, drawUnder), 0, NULL, CACHE}, {TK_OPTION_PIXELS, "-xoffset", "xOffset", "XOffset", @@ -303,24 +301,24 @@ int LineMarker::regionIn(Region2d *extsPtr, int enclosed) } } -void LineMarker::print(Blt_Ps ps) +void LineMarker::print(PostScript* psPtr) { LineMarkerOptions* ops = (LineMarkerOptions*)ops_; if (nSegments_ > 0) { - Blt_Ps_XSetLineAttributes(ps, ops->outlineColor, ops->lineWidth, - &ops->dashes, ops->capStyle, ops->joinStyle); + psPtr->setLineAttributes(ops->outlineColor, ops->lineWidth, + &ops->dashes, ops->capStyle, ops->joinStyle); if ((LineIsDashed(ops->dashes)) && (ops->fillColor)) { - Blt_Ps_Append(ps, "/DashesProc {\n gsave\n "); - Blt_Ps_XSetBackground(ps, ops->fillColor); - Blt_Ps_Append(ps, " "); - Blt_Ps_XSetDashes(ps, (Dashes*)NULL); - Blt_Ps_VarAppend(ps, "stroke\n", " grestore\n", "} def\n", (char*)NULL); + psPtr->append("/DashesProc {\n gsave\n "); + psPtr->setBackground(ops->fillColor); + psPtr->append(" "); + psPtr->setDashes(NULL); + psPtr->varAppend("stroke\n", " grestore\n", "} def\n", NULL); } else - Blt_Ps_Append(ps, "/DashesProc {} def\n"); + psPtr->append("/DashesProc {} def\n"); - graphPtr_->printSegments(ps, segments_, nSegments_); + psPtr->drawSegments(segments_, nSegments_); } } diff --git a/src/bltGrMarkerLine.h b/src/bltGrMarkerLine.h index 61c5ec6..37d2197 100644 --- a/src/bltGrMarkerLine.h +++ b/src/bltGrMarkerLine.h @@ -41,7 +41,6 @@ namespace Blt { Axis* xAxis; Axis* yAxis; int hide; - int state; int drawUnder; int xOffset; int yOffset; @@ -67,7 +66,7 @@ namespace Blt { void map(); int pointIn(Point2d*); int regionIn(Region2d*, int); - void print(Blt_Ps); + void print(PostScript*); int pointInSegments(Point2d *samplePtr, Segment2d *segments, int nSegments, double halo); diff --git a/src/bltGrMarkerPolygon.C b/src/bltGrMarkerPolygon.C index 29dfd77..6618851 100644 --- a/src/bltGrMarkerPolygon.C +++ b/src/bltGrMarkerPolygon.C @@ -78,9 +78,6 @@ static Tk_OptionSpec optionSpecs[] = { {TK_OPTION_COLOR, "-outlinebg", "outlinebg", "OutlineBg", NULL, -1, Tk_Offset(PolygonMarkerOptions, outlineBg), TK_OPTION_NULL_OK, NULL, 0}, - {TK_OPTION_STRING_TABLE, "-state", "state", "State", - "normal", -1, Tk_Offset(PolygonMarkerOptions, state), - 0, &stateObjOption, 0}, {TK_OPTION_BOOLEAN, "-under", "under", "Under", "no", -1, Tk_Offset(PolygonMarkerOptions, drawUnder), 0, NULL, CACHE}, {TK_OPTION_PIXELS, "-xoffset", "xOffset", "XOffset", @@ -330,36 +327,35 @@ int PolygonMarker::regionIn(Region2d *extsPtr, int enclosed) return 0; } -void PolygonMarker::print(Blt_Ps ps) +void PolygonMarker::print(PostScript* psPtr) { PolygonMarkerOptions* ops = (PolygonMarkerOptions*)ops_; if (ops->fill) { - graphPtr_->printPolyline(ps, fillPts_, nFillPts_); + psPtr->drawPolyline(fillPts_, nFillPts_); if (ops->fillBg) { - Blt_Ps_XSetBackground(ps, ops->fillBg); - Blt_Ps_Append(ps, "gsave fill grestore\n"); + psPtr->setBackground(ops->fillBg); + psPtr->append("gsave fill grestore\n"); } - Blt_Ps_XSetForeground(ps, ops->fill); - Blt_Ps_Append(ps, "fill\n"); + psPtr->setForeground(ops->fill); + psPtr->append("fill\n"); } if ((ops->lineWidth > 0) && (ops->outline)) { - - Blt_Ps_XSetLineAttributes(ps, ops->outline, ops->lineWidth, &ops->dashes, - ops->capStyle, ops->joinStyle); + psPtr->setLineAttributes(ops->outline, ops->lineWidth, &ops->dashes, + ops->capStyle, ops->joinStyle); if ((ops->outlineBg) && (LineIsDashed(ops->dashes))) { - Blt_Ps_Append(ps, "/DashesProc {\ngsave\n "); - Blt_Ps_XSetBackground(ps, ops->outlineBg); - Blt_Ps_Append(ps, " "); - Blt_Ps_XSetDashes(ps, (Dashes*)NULL); - Blt_Ps_Append(ps, "stroke\n grestore\n} def\n"); + psPtr->append("/DashesProc {\ngsave\n "); + psPtr->setBackground(ops->outlineBg); + psPtr->append(" "); + psPtr->setDashes((Dashes*)NULL); + psPtr->append("stroke\n grestore\n} def\n"); } else - Blt_Ps_Append(ps, "/DashesProc {} def\n"); + psPtr->append("/DashesProc {} def\n"); - graphPtr_->printSegments(ps, outlinePts_, nOutlinePts_); + psPtr->drawSegments(outlinePts_, nOutlinePts_); } } diff --git a/src/bltGrMarkerPolygon.h b/src/bltGrMarkerPolygon.h index a38a79f..5060fe5 100644 --- a/src/bltGrMarkerPolygon.h +++ b/src/bltGrMarkerPolygon.h @@ -41,7 +41,6 @@ namespace Blt { Axis* xAxis; Axis* yAxis; int hide; - int state; int drawUnder; int xOffset; int yOffset; @@ -73,7 +72,7 @@ namespace Blt { void map(); int pointIn(Point2d*); int regionIn(Region2d*, int); - void print(Blt_Ps); + void print(PostScript*); public: PolygonMarker(Graph*, const char*, Tcl_HashEntry*); diff --git a/src/bltGrMarkerText.C b/src/bltGrMarkerText.C index fac7c5d..cc581d6 100644 --- a/src/bltGrMarkerText.C +++ b/src/bltGrMarkerText.C @@ -74,8 +74,6 @@ static Tk_OptionSpec optionSpecs[] = { {TK_OPTION_SYNONYM, "-outline", NULL, NULL, NULL, -1, 0, 0, "-foreground", 0}, {TK_OPTION_DOUBLE, "-rotate", "rotate", "Rotate", "0", -1, Tk_Offset(TextMarkerOptions, style.angle), 0, NULL, 0}, - {TK_OPTION_STRING_TABLE, "-state", "state", "State", - "normal", -1, Tk_Offset(TextMarkerOptions, state), 0, &stateObjOption, 0}, {TK_OPTION_STRING, "-text", "text", "Text", NULL, -1, Tk_Offset(TextMarkerOptions, string), TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_BOOLEAN, "-under", "under", "Under", @@ -255,7 +253,7 @@ int TextMarker::regionIn(Region2d *extsPtr, int enclosed) ((anchorPt_.y + height_) <= extsPtr->top)); } -void TextMarker::print(Blt_Ps ps) +void TextMarker::print(PostScript* psPtr) { TextMarkerOptions* ops = (TextMarkerOptions*)ops_; @@ -270,10 +268,10 @@ void TextMarker::print(Blt_Ps ps) points[ii].x = outline_[ii].x + anchorPt_.x; points[ii].y = outline_[ii].y + anchorPt_.y; } - Blt_Ps_XSetBackground(ps, ops->fillColor); - Blt_Ps_XFillPolygon(ps, points, 4); + psPtr->setBackground(ops->fillColor); + psPtr->fillPolygon(points, 4); } TextStyle ts(graphPtr_, &ops->style); - ts.printText(ps, ops->string, anchorPt_.x, anchorPt_.y); + ts.printText(psPtr, ops->string, anchorPt_.x, anchorPt_.y); } diff --git a/src/bltGrMarkerText.h b/src/bltGrMarkerText.h index a1409de..efe8b05 100644 --- a/src/bltGrMarkerText.h +++ b/src/bltGrMarkerText.h @@ -43,7 +43,6 @@ namespace Blt { Axis* xAxis; Axis* yAxis; int hide; - int state; int drawUnder; int xOffset; int yOffset; @@ -68,7 +67,7 @@ namespace Blt { void map(); int pointIn(Point2d*); int regionIn(Region2d*, int); - void print(Blt_Ps); + void print(PostScript*); public: TextMarker(Graph*, const char*, Tcl_HashEntry*); diff --git a/src/bltGrPSOutput.C b/src/bltGrPSOutput.C index f379ae9..7a8d0f1 100644 --- a/src/bltGrPSOutput.C +++ b/src/bltGrPSOutput.C @@ -29,6 +29,7 @@ */ #include +#include extern "C" { #include @@ -47,48 +48,57 @@ using namespace Blt; # define HAVE_UTF 0 #endif -void Graph::printPolyline(Blt_Ps ps, Point2d* screenPts, int nScreenPts) +PostScript::PostScript(Graph* graphPtr) { - Point2d *pp, *pend; + graphPtr_ = graphPtr; - pp = screenPts; - Blt_Ps_Append(ps, "newpath\n"); - Blt_Ps_Format(ps, " %g %g moveto\n", pp->x, pp->y); - for (pp++, pend = screenPts + nScreenPts; pp < pend; pp++) { - Blt_Ps_Format(ps, " %g %g lineto\n", pp->x, pp->y); - } + Tcl_DStringInit(&dString); +} + +PostScript::~PostScript() +{ + Tcl_DStringFree(&dString); } -void Graph::printMaxPolyline(Blt_Ps ps, Point2d* points, int nPoints) +void PostScript::drawPolyline(Point2d* screenPts, int nScreenPts) +{ + Point2d* pp = screenPts; + append("newpath\n"); + format(" %g %g moveto\n", pp->x, pp->y); + + Point2d* pend; + for (pp++, pend = screenPts + nScreenPts; pp < pend; pp++) + format(" %g %g lineto\n", pp->x, pp->y); +} + +void PostScript::drawMaxPolyline(Point2d* points, int nPoints) { if (nPoints <= 0) return; for (int nLeft = nPoints; nLeft > 0; nLeft -= 1500) { int length = MIN(1500, nLeft); - printPolyline(ps, points, length); - Blt_Ps_Append(ps, "DashesProc stroke\n"); + drawPolyline(points, length); + append("DashesProc stroke\n"); points += length; } } -void Graph::printSegments(Blt_Ps ps, Segment2d* segments, int nSegments) +void PostScript::drawSegments(Segment2d* segments, int nSegments) { + append("newpath\n"); + Segment2d* sp; Segment2d* send; - - Blt_Ps_Append(ps, "newpath\n"); for (sp = segments, send = sp + nSegments; sp < send; sp++) { - Blt_Ps_Format(ps, " %g %g moveto %g %g lineto\n", - sp->p.x, sp->p.y, sp->q.x, sp->q.y); - Blt_Ps_Append(ps, "DashesProc stroke\n"); + format(" %g %g moveto %g %g lineto\n", sp->p.x, sp->p.y, sp->q.x, sp->q.y); + append("DashesProc stroke\n"); } } -static Tcl_Interp *psInterp = NULL; - -int Blt_Ps_ComputeBoundingBox(PageSetup *setupPtr, int width, int height) +int PostScript::computeBBox(int width, int height) { + PageSetup* setupPtr = graphPtr_->pageSetup_; PageSetupOptions* pops = (PageSetupOptions*)setupPtr->ops_; int paperWidth, paperHeight; float hScale, vScale, scale; @@ -107,19 +117,16 @@ int Blt_Ps_ComputeBoundingBox(PageSetup *setupPtr, int width, int height) hSize = width; vSize = height; } - /* - * If the paper size wasn't specified, set it to the graph size plus the - * paper border. - */ + + // If the paper size wasn't specified, set it to the graph size plus the + // paper border. paperWidth = (pops->reqPaperWidth > 0) ? pops->reqPaperWidth : hSize + hBorder; paperHeight = (pops->reqPaperHeight > 0) ? pops->reqPaperHeight : vSize + vBorder; - /* - * Scale the plot size (the graph itself doesn't change size) if it's - * bigger than the paper or if -maxpect was set. - */ + // Scale the plot size (the graph itself doesn't change size) if it's + // bigger than the paper or if -maxpect was set. hScale = vScale = 1.0f; if ((setupPtr->flags & PS_MAXPECT) || ((hSize + hBorder) > paperWidth)) { hScale = (float)(paperWidth - hBorder) / (float)hSize; @@ -150,324 +157,202 @@ int Blt_Ps_ComputeBoundingBox(PageSetup *setupPtr, int width, int height) return paperHeight; } -PostScript *Blt_Ps_Create(Tcl_Interp* interp, PageSetup *setupPtr) -{ - PostScript* psPtr = (PostScript*)malloc(sizeof(PostScript)); - psPtr->setupPtr = setupPtr; - psPtr->interp = interp; - Tcl_DStringInit(&psPtr->dString); - return psPtr; -} - -void Blt_Ps_SetPrinting(PostScript *psPtr, int state) +const char* PostScript::getValue(int* lengthPtr) { - psInterp = ((state) && (psPtr != NULL)) ? psPtr->interp : NULL; + *lengthPtr = strlen(Tcl_DStringValue(&dString)); + return Tcl_DStringValue(&dString); } -void Blt_Ps_Free(PostScript *psPtr) +void PostScript::append(const char* string) { - Tcl_DStringFree(&psPtr->dString); - free(psPtr); + Tcl_DStringAppend(&dString, string, -1); } -const char *Blt_Ps_GetValue(PostScript *psPtr, int *lengthPtr) +void PostScript::format(const char* fmt, ...) { - *lengthPtr = strlen(Tcl_DStringValue(&psPtr->dString)); - return Tcl_DStringValue(&psPtr->dString); -} + va_list argList; -char *Blt_Ps_GetScratchBuffer(PostScript *psPtr) -{ - return psPtr->scratchArr; + va_start(argList, fmt); + vsnprintf(scratchArr, POSTSCRIPT_BUFSIZ, fmt, argList); + va_end(argList); + Tcl_DStringAppend(&dString, scratchArr, -1); } -void Blt_Ps_VarAppend TCL_VARARGS_DEF(PostScript *, arg1) +void PostScript::varAppend(const char* fmt, ...) { va_list argList; - PostScript *psPtr; - const char *string; - psPtr = TCL_VARARGS_START(PostScript, arg1, argList); + va_start(argList, fmt); for (;;) { - string = va_arg(argList, char *); - if (string == NULL) { + char* str = va_arg(argList, char *); + if (!str) break; - } - Tcl_DStringAppend(&psPtr->dString, string, -1); + Tcl_DStringAppend(&dString, str, -1); } -} - -void Blt_Ps_Append(PostScript *psPtr, const char *string) -{ - Tcl_DStringAppend(&psPtr->dString, string, -1); -} - -void Blt_Ps_Format TCL_VARARGS_DEF(PostScript *, arg1) -{ - va_list argList; - PostScript *psPtr; - char *fmt; - - psPtr = TCL_VARARGS_START(PostScript, arg1, argList); - fmt = va_arg(argList, char *); - vsnprintf(psPtr->scratchArr, POSTSCRIPT_BUFSIZ, fmt, argList); va_end(argList); - Tcl_DStringAppend(&psPtr->dString, psPtr->scratchArr, -1); } -int Blt_Ps_IncludeFile(Tcl_Interp* interp, Blt_Ps ps, const char *fileName) +void PostScript::setLineWidth(int lineWidth) { - Tcl_Channel channel; - Tcl_DString dString; - char *buf; - char *libDir; - int nBytes; - - buf = Blt_Ps_GetScratchBuffer(ps); - - /* - * Read in a standard prolog file from file and append it to the - * PostScript output stored in the Tcl_DString in psPtr. - */ - - libDir = (char *)Tcl_GetVar(interp, "tkblt_library", TCL_GLOBAL_ONLY); - if (libDir == NULL) { - Tcl_AppendResult(interp, "couldn't find TKBLT script library:", - "global variable \"tkblt_library\" doesn't exist", (char *)NULL); - return TCL_ERROR; - } - Tcl_DStringInit(&dString); - Tcl_DStringAppend(&dString, libDir, -1); - Tcl_DStringAppend(&dString, "/", -1); - Tcl_DStringAppend(&dString, fileName, -1); - fileName = Tcl_DStringValue(&dString); - Blt_Ps_VarAppend(ps, "\n% including file \"", fileName, "\"\n\n", - (char *)NULL); - channel = Tcl_OpenFileChannel(interp, fileName, "r", 0); - if (channel == NULL) { - Tcl_AppendResult(interp, "couldn't open prologue file \"", fileName, - "\": ", Tcl_PosixError(interp), (char *)NULL); - return TCL_ERROR; - } - for(;;) { - nBytes = Tcl_Read(channel, buf, POSTSCRIPT_BUFSIZ); - if (nBytes < 0) { - Tcl_AppendResult(interp, "error reading prologue file \"", - fileName, "\": ", Tcl_PosixError(interp), - (char *)NULL); - Tcl_Close(interp, channel); - Tcl_DStringFree(&dString); - return TCL_ERROR; - } - if (nBytes == 0) { - break; - } - buf[nBytes] = '\0'; - Blt_Ps_Append(ps, buf); - } - Tcl_DStringFree(&dString); - Tcl_Close(interp, channel); - return TCL_OK; + if (lineWidth < 1) + lineWidth = 1; + format("%d setlinewidth\n", lineWidth); } -static void XColorToPostScript(Blt_Ps ps, XColor* colorPtr) +void PostScript::drawRectangle(int x, int y, int width, int height) { - Blt_Ps_Format(ps, "%g %g %g", - ((double)(colorPtr->red >> 8) / 255.0), - ((double)(colorPtr->green >> 8) / 255.0), - ((double)(colorPtr->blue >> 8) / 255.0)); + append("newpath\n"); + format(" %d %d moveto\n", x, y); + format(" %d %d rlineto\n", width, 0); + format(" %d %d rlineto\n", 0, height); + format(" %d %d rlineto\n", -width, 0); + append("closepath\n"); } -void Blt_Ps_XSetBackground(PostScript *psPtr, XColor* colorPtr) +void PostScript::fillRectangle(double x, double y, int width, int height) { - PageSetupOptions* pops = (PageSetupOptions*)psPtr->setupPtr->ops_; - XColorToPostScript(psPtr, colorPtr); - Blt_Ps_Append(psPtr, " setrgbcolor\n"); - if (pops->greyscale) { - Blt_Ps_Append(psPtr, " currentgray setgray\n"); - } + drawRectangle((int)x, (int)y, width, height); + append("fill\n"); } -void Blt_Ps_XSetForeground(PostScript *psPtr, XColor* colorPtr) +void PostScript::fillRectangles(XRectangle* rectangles, int nRectangles) { - PageSetupOptions* pops = (PageSetupOptions*)psPtr->setupPtr->ops_; - XColorToPostScript(psPtr, colorPtr); - Blt_Ps_Append(psPtr, " setrgbcolor\n"); - if (pops->greyscale) { - Blt_Ps_Append(psPtr, " currentgray setgray\n"); - } + XRectangle *rp, *rend; + for (rp = rectangles, rend = rp + nRectangles; rp < rend; rp++) + fillRectangle((double)rp->x, (double)rp->y, (int)rp->width,(int)rp->height); } -static unsigned char ReverseBits(unsigned char byte) +void PostScript::setBackground(XColor* colorPtr) { - byte = ((byte >> 1) & 0x55) | ((byte << 1) & 0xaa); - byte = ((byte >> 2) & 0x33) | ((byte << 2) & 0xcc); - byte = ((byte >> 4) & 0x0f) | ((byte << 4) & 0xf0); - return byte; + PageSetupOptions* pops = (PageSetupOptions*)graphPtr_->pageSetup_->ops_; + XColorToPostScript(colorPtr); + append(" setrgbcolor\n"); + if (pops->greyscale) + append(" currentgray setgray\n"); } -static void ByteToHex(unsigned char byte, char *string) +void PostScript::setForeground(XColor* colorPtr) { - static char hexDigits[] = "0123456789ABCDEF"; - - string[0] = hexDigits[byte >> 4]; - string[1] = hexDigits[byte & 0x0F]; + PageSetupOptions* pops = (PageSetupOptions*)graphPtr_->pageSetup_->ops_; + XColorToPostScript(colorPtr); + append(" setrgbcolor\n"); + if (pops->greyscale) + append(" currentgray setgray\n"); } -void Blt_Ps_XSetBitmapData(Blt_Ps ps, Display *display, Pixmap bitmap, - int w, int h) +void PostScript::setFont(Tk_Font font) { - XImage* imagePtr = XGetImage(display, bitmap, 0, 0, w, h, 1, ZPixmap); - Blt_Ps_Append(ps, "\t<"); - int byteCount =0; - int bitPos =0; - for (int y=0; y= 30) { - string[2] = '\n'; - string[3] = '\t'; - string[4] = '\0'; - byteCount = 0; - } - Blt_Ps_Append(ps, string); - } - } /* x */ - if (bitPos != 7) { - byte = ReverseBits(byte); - ByteToHex(byte, string); - string[2] = '\0'; - Blt_Ps_Append(ps, string); - byteCount++; - } - } /* y */ - Blt_Ps_Append(ps, ">\n"); - XDestroyImage(imagePtr); +#if 0 + const char* family = FamilyToPsFamily(Blt_FamilyOfFont(font)); + if (family != NULL) { + double pointSize; + + Tcl_DString dString; + Tcl_DStringInit(&dString); + pointSize = (double)Blt_PostscriptFontName(font, &dString); + format("%g /%s SetFont\n", pointSize, Tcl_DStringValue(&dString)); + Tcl_DStringFree(&dString); + return; + } + append("12.0 /Helvetica-Bold SetFont\n"); +#endif } -void Blt_Ps_SetClearBackground(Blt_Ps ps) +void PostScript::setLineAttributes(XColor* colorPtr,int lineWidth, + Dashes* dashesPtr, int capStyle, + int joinStyle) { - Blt_Ps_Append(ps, "1 1 1 setrgbcolor\n"); + setJoinStyle(joinStyle); + setCapStyle(capStyle); + setForeground(colorPtr); + setLineWidth(lineWidth); + setDashes(dashesPtr); + append("/DashesProc {} def\n"); } -void Blt_Ps_XSetCapStyle(Blt_Ps ps, int capStyle) +void PostScript::fill3DRectangle(Tk_3DBorder border, double x, double y, + int width, int height, int borderWidth, + int relief) { - // X11:not last = 0, butt = 1, round = 2, projecting = 3 - // PS: butt = 0, round = 1, projecting = 2 - if (capStyle > 0) - capStyle--; - - Blt_Ps_Format(ps, "%d setlinecap\n", capStyle); -} + TkBorder* borderPtr = (TkBorder*)border; -void Blt_Ps_XSetJoinStyle(Blt_Ps ps, int joinStyle) -{ - /* - * miter = 0, round = 1, bevel = 2 - */ - Blt_Ps_Format(ps, "%d setlinejoin\n", joinStyle); + setBackground(borderPtr->bgColorPtr); + fillRectangle(x, y, width, height); + draw3DRectangle(border, x, y, width, height, borderWidth, relief); } -void Blt_Ps_XSetLineWidth(Blt_Ps ps, int lineWidth) +void PostScript::setClearBackground() { - if (lineWidth < 1) { - lineWidth = 1; - } - Blt_Ps_Format(ps, "%d setlinewidth\n", lineWidth); + append("1 1 1 setrgbcolor\n"); } -void Blt_Ps_XSetDashes(Blt_Ps ps, Dashes* dashesPtr) +void PostScript::setDashes(Dashes* dashesPtr) { - Blt_Ps_Append(ps, "[ "); - if (dashesPtr != NULL) { - unsigned char *vp; - - for (vp = dashesPtr->values; *vp != 0; vp++) { - Blt_Ps_Format(ps, " %d", *vp); - } + append("[ "); + if (dashesPtr) { + for (unsigned char* vp = dashesPtr->values; *vp != 0; vp++) + format(" %d", *vp); } - Blt_Ps_Append(ps, "] 0 setdash\n"); + append("] 0 setdash\n"); } -void Blt_Ps_XSetLineAttributes(Blt_Ps ps, XColor* colorPtr,int lineWidth, - Dashes* dashesPtr, int capStyle, int joinStyle) +void PostScript::fillPolygon(Point2d *screenPts, int nScreenPts) { - Blt_Ps_XSetJoinStyle(ps, joinStyle); - Blt_Ps_XSetCapStyle(ps, capStyle); - Blt_Ps_XSetForeground(ps, colorPtr); - Blt_Ps_XSetLineWidth(ps, lineWidth); - Blt_Ps_XSetDashes(ps, dashesPtr); - Blt_Ps_Append(ps, "/DashesProc {} def\n"); + drawPolygon(screenPts, nScreenPts); + append("fill\n"); } -void Blt_Ps_Rectangle(Blt_Ps ps, int x, int y, int width, int height) +void PostScript::drawBitmap(Display *display, Pixmap bitmap, + double xScale, double yScale) { - Blt_Ps_Append(ps, "newpath\n"); - Blt_Ps_Format(ps, " %d %d moveto\n", x, y); - Blt_Ps_Format(ps, " %d %d rlineto\n", width, 0); - Blt_Ps_Format(ps, " %d %d rlineto\n", 0, height); - Blt_Ps_Format(ps, " %d %d rlineto\n", -width, 0); - Blt_Ps_Append(ps, "closepath\n"); + int width, height; + Tk_SizeOfBitmap(display, bitmap, &width, &height); + + double sw = (double)width * xScale; + double sh = (double)height * yScale; + append(" gsave\n"); + format(" %g %g translate\n", sw * -0.5, sh * 0.5); + format(" %g %g scale\n", sw, -sh); + format(" %d %d true [%d 0 0 %d 0 %d] {", + width, height, width, -height, height); + setBitmap(display, bitmap, width, height); + append(" } imagemask\n grestore\n"); } -void Blt_Ps_XFillRectangle(Blt_Ps ps, double x, double y, int width, int height) +void PostScript::setJoinStyle(int joinStyle) { - Blt_Ps_Rectangle(ps, (int)x, (int)y, width, height); - Blt_Ps_Append(ps, "fill\n"); + // miter = 0, round = 1, bevel = 2 + format("%d setlinejoin\n", joinStyle); } -void Blt_Ps_PolylineFromXPoints(Blt_Ps ps, XPoint *points, int n) +void PostScript::setCapStyle(int capStyle) { - XPoint* pp = points; - Blt_Ps_Append(ps, "newpath\n"); - Blt_Ps_Format(ps, " %d %d moveto\n", pp->x, pp->y); - pp++; + // X11:not last = 0, butt = 1, round = 2, projecting = 3 + // PS: butt = 0, round = 1, projecting = 2 + if (capStyle > 0) + capStyle--; - for (XPoint* pend = points + n; pp < pend; pp++) - Blt_Ps_Format(ps, " %d %d lineto\n", pp->x, pp->y); + format("%d setlinecap\n", capStyle); } -void Blt_Ps_Polygon(Blt_Ps ps, Point2d *screenPts, int nScreenPts) +void PostScript::drawPolygon(Point2d *screenPts, int nScreenPts) { Point2d* pp = screenPts; - Blt_Ps_Append(ps, "newpath\n"); - Blt_Ps_Format(ps, " %g %g moveto\n", pp->x, pp->y); + append("newpath\n"); + format(" %g %g moveto\n", pp->x, pp->y); Point2d* pend; for (pp++, pend = screenPts + nScreenPts; pp < pend; pp++) - Blt_Ps_Format(ps, " %g %g lineto\n", pp->x, pp->y); - - Blt_Ps_Format(ps, " %g %g lineto\n", screenPts[0].x, screenPts[0].y); - Blt_Ps_Append(ps, "closepath\n"); -} + format(" %g %g lineto\n", pp->x, pp->y); -void Blt_Ps_XFillPolygon(Blt_Ps ps, Point2d *screenPts, int nScreenPts) -{ - Blt_Ps_Polygon(ps, screenPts, nScreenPts); - Blt_Ps_Append(ps, "fill\n"); + format(" %g %g lineto\n", screenPts[0].x, screenPts[0].y); + append("closepath\n"); } -void Blt_Ps_XFillRectangles(Blt_Ps ps, XRectangle *rectangles, int nRectangles) -{ - XRectangle *rp, *rend; - for (rp = rectangles, rend = rp + nRectangles; rp < rend; rp++) - Blt_Ps_XFillRectangle(ps, (double)rp->x, (double)rp->y, - (int)rp->width, (int)rp->height); -} - -void Blt_Ps_Draw3DRectangle(Blt_Ps ps, Tk_3DBorder border, double x, double y, - int width, int height, int borderWidth, int relief) +void PostScript::draw3DRectangle(Tk_3DBorder border, double x, double y, + int width, int height, int borderWidth, + int relief) { TkBorder* borderPtr = (TkBorder*)border; XColor* lightPtr, *darkPtr; @@ -500,17 +385,14 @@ void Blt_Ps_Draw3DRectangle(Blt_Ps ps, Tk_3DBorder border, double x, double y, if ((relief == TK_RELIEF_GROOVE) || (relief == TK_RELIEF_RIDGE)) { int halfWidth = borderWidth / 2; int insideOffset = borderWidth - halfWidth; - Blt_Ps_Draw3DRectangle(ps, border, (double)x, (double)y, - width, height, halfWidth, - (relief == TK_RELIEF_GROOVE) ? - TK_RELIEF_SUNKEN : TK_RELIEF_RAISED); - Blt_Ps_Draw3DRectangle(ps, border, - (double)(x + insideOffset), - (double)(y + insideOffset), - width - insideOffset * 2, - height - insideOffset * 2, halfWidth, - (relief == TK_RELIEF_GROOVE) ? - TK_RELIEF_RAISED : TK_RELIEF_SUNKEN); + draw3DRectangle(border, (double)x, (double)y, width, height, halfWidth, + (relief == TK_RELIEF_GROOVE) ? + TK_RELIEF_SUNKEN : TK_RELIEF_RAISED); + draw3DRectangle(border, (double)(x + insideOffset), + (double)(y + insideOffset), width - insideOffset * 2, + height - insideOffset * 2, halfWidth, + (relief == TK_RELIEF_GROOVE) ? + TK_RELIEF_RAISED : TK_RELIEF_SUNKEN); return; } @@ -525,9 +407,9 @@ void Blt_Ps_Draw3DRectangle(Blt_Ps ps, Tk_3DBorder border, double x, double y, else topPtr = bottomPtr = borderPtr->bgColorPtr; - Blt_Ps_XSetBackground(ps, bottomPtr); - Blt_Ps_XFillRectangle(ps, x, y + height - borderWidth, width, borderWidth); - Blt_Ps_XFillRectangle(ps, x + width - borderWidth, y, borderWidth, height); + setBackground(bottomPtr); + fillRectangle(x, y + height - borderWidth, width, borderWidth); + fillRectangle(x + width - borderWidth, y, borderWidth, height); Point2d points[7]; points[0].x = points[1].x = points[6].x = x; @@ -539,63 +421,215 @@ void Blt_Ps_Draw3DRectangle(Blt_Ps ps, Tk_3DBorder border, double x, double y, points[4].x = points[5].x = x + borderWidth; points[5].y = y + height - borderWidth; if (relief != TK_RELIEF_FLAT) - Blt_Ps_XSetBackground(ps, topPtr); + setBackground(topPtr); - Blt_Ps_XFillPolygon(ps, points, 7); + fillPolygon(points, 7); } -void Blt_Ps_Fill3DRectangle(Blt_Ps ps, Tk_3DBorder border, double x, double y, - int width, int height, int borderWidth, int relief) +void PostScript::setBitmap(Display *display, Pixmap bitmap, int w, int h) { - TkBorder* borderPtr = (TkBorder*)border; - - Blt_Ps_XSetBackground(ps, borderPtr->bgColorPtr); - Blt_Ps_XFillRectangle(ps, x, y, width, height); - Blt_Ps_Draw3DRectangle(ps, border, x, y, width, height, borderWidth, - relief); + XImage* imagePtr = XGetImage(display, bitmap, 0, 0, w, h, 1, ZPixmap); + append("\t<"); + int byteCount =0; + int bitPos =0; + for (int y=0; y= 30) { + string[2] = '\n'; + string[3] = '\t'; + string[4] = '\0'; + byteCount = 0; + } + append(string); + } + } /* x */ + if (bitPos != 7) { + byte = ReverseBits(byte); + ByteToHex(byte, string); + string[2] = '\0'; + append(string); + byteCount++; + } + } /* y */ + append(">\n"); + XDestroyImage(imagePtr); } -void Blt_Ps_XSetStipple(Blt_Ps ps, Display *display, Pixmap bitmap) +int PostScript::includeFile(const char *fileName) { - int width, height; + Tcl_Channel channel; + Tcl_DString dString; + int nBytes; - Tk_SizeOfBitmap(display, bitmap, &width, &height); - Blt_Ps_Format(ps, - "gsave\n" - " clip\n" - " %d %d\n", - width, height); - Blt_Ps_XSetBitmapData(ps, display, bitmap, width, height); - Blt_Ps_VarAppend(ps, - " StippleFill\n" - "grestore\n", (char *)NULL); + Tcl_Interp* interp = graphPtr_->interp_; + char* buf = scratchArr; + + // Read in a standard prolog file from file and append it to the + // PostScript output stored in the Tcl_DString in psPtr. + char* libDir = (char *)Tcl_GetVar(interp, "tkblt_library", TCL_GLOBAL_ONLY); + if (libDir == NULL) { + Tcl_AppendResult(interp, "couldn't find TKBLT script library:", + "global variable \"tkblt_library\" doesn't exist", + (char *)NULL); + return TCL_ERROR; + } + Tcl_DStringInit(&dString); + Tcl_DStringAppend(&dString, libDir, -1); + Tcl_DStringAppend(&dString, "/", -1); + Tcl_DStringAppend(&dString, fileName, -1); + fileName = Tcl_DStringValue(&dString); + varAppend("\n% including file \"", fileName, "\"\n\n", NULL); + channel = Tcl_OpenFileChannel(interp, fileName, "r", 0); + if (channel == NULL) { + Tcl_AppendResult(interp, "couldn't open prologue file \"", fileName, + "\": ", Tcl_PosixError(interp), (char *)NULL); + return TCL_ERROR; + } + for(;;) { + nBytes = Tcl_Read(channel, buf, POSTSCRIPT_BUFSIZ); + if (nBytes < 0) { + Tcl_AppendResult(interp, "error reading prologue file \"", + fileName, "\": ", Tcl_PosixError(interp), + (char *)NULL); + Tcl_Close(interp, channel); + Tcl_DStringFree(&dString); + return TCL_ERROR; + } + if (nBytes == 0) { + break; + } + buf[nBytes] = '\0'; + append(buf); + } + Tcl_DStringFree(&dString); + Tcl_Close(interp, channel); + return TCL_OK; } -void Blt_Ps_XSetFont(PostScript *psPtr, Tk_Font font) +void PostScript::XColorToPostScript(XColor* colorPtr) { -#if 0 - Tcl_Interp* interp = psPtr->interp; - const char *family; - - /* - * Check to see if it's a PostScript font. Tk_PostScriptFontName silently - * generates a bogus PostScript font name, so we have to check to see if - * this is really a PostScript font first before we call it. - */ - family = FamilyToPsFamily(Blt_FamilyOfFont(font)); - if (family != NULL) { - Tcl_DString dString; - double pointSize; + format("%g %g %g", + ((double)(colorPtr->red >> 8) / 255.0), + ((double)(colorPtr->green >> 8) / 255.0), + ((double)(colorPtr->blue >> 8) / 255.0)); +} + +int PostScript::preamble(const char* fileName) +{ + PageSetup* setupPtr = graphPtr_->pageSetup_; + PageSetupOptions* ops = (PageSetupOptions*)setupPtr->ops_; + time_t ticks; + char date[200]; /* Holds the date string from ctime() */ + char *newline; + + if (!fileName) + fileName = Tk_PathName(graphPtr_->tkwin_); + + append("%!PS-Adobe-3.0 EPSF-3.0\n"); + + // The "BoundingBox" comment is required for EPS files. The box + // coordinates are integers, so we need round away from the center of the + // box. + format("%%%%BoundingBox: %d %d %d %d\n", + setupPtr->left, setupPtr->paperHeight - setupPtr->top, + setupPtr->right, setupPtr->paperHeight - setupPtr->bottom); - Tcl_DStringInit(&dString); - pointSize = (double)Blt_PostscriptFontName(font, &dString); - Blt_Ps_Format(psPtr, "%g /%s SetFont\n", pointSize, - Tcl_DStringValue(&dString)); - Tcl_DStringFree(&dString); - return; + append("%%Pages: 0\n"); + + format("%%%%Creator: (%s %s %s)\n", PACKAGE_NAME, PACKAGE_VERSION, + Tk_Class(graphPtr_->tkwin_)); + + ticks = time((time_t *) NULL); + strcpy(date, ctime(&ticks)); + newline = date + strlen(date) - 1; + if (*newline == '\n') + *newline = '\0'; + + format("%%%%CreationDate: (%s)\n", date); + format("%%%%Title: (%s)\n", fileName); + append("%%DocumentData: Clean7Bit\n"); + if (ops->landscape) + append("%%Orientation: Landscape\n"); + else + append("%%Orientation: Portrait\n"); + + append("%%DocumentNeededResources: font Helvetica Courier\n"); + addComments(ops->comments); + append("%%EndComments\n\n"); + if (includeFile("bltGraph.pro") != TCL_OK) + return TCL_ERROR; + + if (ops->footer) { + const char* who = getenv("LOGNAME"); + if (!who) + who = "???"; + + varAppend("8 /Helvetica SetFont\n", + "10 30 moveto\n", + "(Date: ", date, ") show\n", + "10 20 moveto\n", + "(File: ", fileName, ") show\n", + "10 10 moveto\n", + "(Created by: ", who, "@", Tcl_GetHostName(), ") show\n", + "0 0 moveto\n", + (char *)NULL); } - Blt_Ps_Append(psPtr, "12.0 /Helvetica-Bold SetFont\n"); -#endif + + // Set the conversion from PostScript to X11 coordinates. Scale pica to + // pixels and flip the y-axis (the origin is the upperleft corner). + varAppend("% Transform coordinate system to use X11 coordinates\n\n", + "% 1. Flip y-axis over by reversing the scale,\n", + "% 2. Translate the origin to the other side of the page,\n", + "% making the origin the upper left corner\n", NULL); + format("1 -1 scale\n"); + + // Papersize is in pixels. Translate the new origin *after* changing the scale + format("0 %d translate\n\n", -setupPtr->paperHeight); + varAppend("% User defined page layout\n\n", "% Set color level\n", NULL); + format("%% Set origin\n%d %d translate\n\n", setupPtr->left,setupPtr->bottom); + if (ops->landscape) + format("%% Landscape orientation\n0 %g translate\n-90 rotate\n", + ((double)graphPtr_->width_ * setupPtr->scale)); + + append("\n%%EndSetup\n\n"); + + return TCL_OK; +} + +void PostScript::addComments(const char** comments) +{ + for (const char** p = comments; *p; p += 2) { + if (*(p+1) == NULL) + break; + format("%% %s: %s\n", *p, *(p+1)); + } +} + +unsigned char PostScript::ReverseBits(unsigned char byte) +{ + byte = ((byte >> 1) & 0x55) | ((byte << 1) & 0xaa); + byte = ((byte >> 2) & 0x33) | ((byte << 2) & 0xcc); + byte = ((byte >> 4) & 0x0f) | ((byte << 4) & 0xf0); + return byte; +} + +void PostScript::ByteToHex(unsigned char byte, char* string) +{ + static char hexDigits[] = "0123456789ABCDEF"; + + string[0] = hexDigits[byte >> 4]; + string[1] = hexDigits[byte & 0x0F]; } #if 0 @@ -619,17 +653,17 @@ static void TextLayoutToPostScript(Blt_Ps ps, int x, int y, TextLayout *textPtr) if (fragPtr->count < 1) { continue; } - Blt_Ps_Append(ps, "("); + append("("); count = 0; - dst = Blt_Ps_GetScratchBuffer(ps); + dst = scratchArr; src = fragPtr->text; end = fragPtr->text + fragPtr->count; while (src < end) { if (count > limit) { /* Don't let the scatch buffer overflow */ - dst = Blt_Ps_GetScratchBuffer(ps); + dst = scratchArr; dst[count] = '\0'; - Blt_Ps_Append(ps, dst); + append(dst); count = 0; } #if HAVE_UTF @@ -663,10 +697,10 @@ static void TextLayoutToPostScript(Blt_Ps ps, int x, int y, TextLayout *textPtr) count++; } } - bp = Blt_Ps_GetScratchBuffer(ps); + bp = scratchArr; bp[count] = '\0'; - Blt_Ps_Append(ps, bp); - Blt_Ps_Format(ps, ") %d %d %d DrawAdjText\n", + append(bp); + format(") %d %d %d DrawAdjText\n", fragPtr->width, x + fragPtr->x, y + fragPtr->y); } } @@ -696,33 +730,15 @@ void Blt_Ps_DrawText(Blt_Ps ps, const char *string, double x, double y) } /* Initialize text (sets translation and rotation) */ - Blt_Ps_Format(ps, "%d %d %g %g %g BeginText\n", textPtr->width, - textPtr->height, tsPtr->angle, t.x, t.y); + format("%d %d %g %g %g BeginText\n", textPtr->width, textPtr->height, + tsPtr->angle, t.x, t.y); - Blt_Ps_XSetFont(ps, tsPtr->font); + setFont(tsPtr->font); - Blt_Ps_XSetForeground(ps, tsPtr->color); + setForeground(tsPtr->color); TextLayoutToPostScript(ps, 0, 0, textPtr); free(textPtr); - Blt_Ps_Append(ps, "EndText\n"); + append("EndText\n"); } #endif -void Blt_Ps_DrawBitmap(Blt_Ps ps, Display *display, Pixmap bitmap, - double xScale, double yScale) -{ - int width, height; - Tk_SizeOfBitmap(display, bitmap, &width, &height); - - double sw = (double)width * xScale; - double sh = (double)height * yScale; - Blt_Ps_Append(ps, " gsave\n"); - Blt_Ps_Format(ps, " %g %g translate\n", sw * -0.5, sh * 0.5); - Blt_Ps_Format(ps, " %g %g scale\n", sw, -sh); - Blt_Ps_Format(ps, " %d %d true [%d 0 0 %d 0 %d] {", - width, height, width, -height, height); - Blt_Ps_XSetBitmapData(ps, display, bitmap, width, height); - Blt_Ps_Append(ps, " } imagemask\n grestore\n"); -} - - diff --git a/src/bltGrPSOutput.h b/src/bltGrPSOutput.h index 3f28039..8b43587 100644 --- a/src/bltGrPSOutput.h +++ b/src/bltGrPSOutput.h @@ -32,97 +32,59 @@ #include -#include "bltConfig.h" - -#define POSTSCRIPT_BUFSIZ ((BUFSIZ*2)-1) -struct _Blt_Ps { - Tcl_Interp* interp; - Tcl_DString dString; - PageSetup *setupPtr; - char scratchArr[POSTSCRIPT_BUFSIZ+1]; -}; - -typedef struct _Blt_Ps PostScript; - +#define POSTSCRIPT_BUFSIZ ((BUFSIZ*2)-1) #define PS_MAXPECT (1<<4) -typedef struct _Blt_Ps *Blt_Ps; - -extern Blt_Ps Blt_Ps_Create(Tcl_Interp* interp, PageSetup *setupPtr); - -extern void Blt_Ps_Free(Blt_Ps ps); - -extern const char *Blt_Ps_GetValue(Blt_Ps ps, int *lengthPtr); - -extern char *Blt_Ps_GetScratchBuffer(Blt_Ps ps); - -extern void Blt_Ps_Append(Blt_Ps ps, const char *string); - -extern void Blt_Ps_VarAppend TCL_VARARGS(Blt_Ps, ps); - -extern void Blt_Ps_Format TCL_VARARGS(Blt_Ps, ps); - -extern void Blt_Ps_SetClearBackground(Blt_Ps ps); - -extern int Blt_Ps_IncludeFile(Tcl_Interp* interp, Blt_Ps ps, - const char *fileName); - -extern int Blt_Ps_ComputeBoundingBox(PageSetup *setupPtr, int w, int h); - -extern void Blt_Ps_Rectangle(Blt_Ps ps, int x, int y, int w, int h); - - - -extern void Blt_Ps_XSetLineWidth(Blt_Ps ps, int lineWidth); - -extern void Blt_Ps_XSetBackground(Blt_Ps ps, XColor* colorPtr); - -extern void Blt_Ps_XSetBitmapData(Blt_Ps ps, Display *display, - Pixmap bitmap, int width, int height); - -extern void Blt_Ps_XSetForeground(Blt_Ps ps, XColor* colorPtr); - -extern void Blt_Ps_XSetFont(Blt_Ps ps, Tk_Font font); - -extern void Blt_Ps_XSetDashes(Blt_Ps ps, Dashes *dashesPtr); - -extern void Blt_Ps_XSetLineAttributes(Blt_Ps ps, XColor* colorPtr, - int lineWidth, Dashes *dashesPtr, - int capStyle, int joinStyle); - -extern void Blt_Ps_XSetStipple(Blt_Ps ps, Display *display, Pixmap bitmap); - -extern void Blt_Ps_Draw3DRectangle(Blt_Ps ps, Tk_3DBorder border, - double x, double y, int width, int height, int borderWidth, int relief); - -extern void Blt_Ps_Fill3DRectangle(Blt_Ps ps, Tk_3DBorder border, double x, - double y, int width, int height, int borderWidth, int relief); - -extern void Blt_Ps_XFillRectangle(Blt_Ps ps, double x, double y, - int width, int height); - -extern void Blt_Ps_XFillRectangles(Blt_Ps ps, XRectangle *rects, int n); - -extern void Blt_Ps_XFillPolygon(Blt_Ps ps, Point2d *screenPts, - int nScreenPts); - -extern void Blt_Ps_DrawPhoto(Blt_Ps ps, Tk_PhotoHandle photoToken, - double x, double y); - -extern void Blt_Ps_XDrawWindow(Blt_Ps ps, Tk_Window tkwin, - double x, double y); - -extern void Blt_Ps_DrawBitmap(Blt_Ps ps, Display *display, Pixmap bitmap, - double scaleX, double scaleY); - -extern void Blt_Ps_XSetCapStyle(Blt_Ps ps, int capStyle); - -extern void Blt_Ps_XSetJoinStyle(Blt_Ps ps, int joinStyle); - -extern void Blt_Ps_PolylineFromXPoints(Blt_Ps ps, XPoint *points, int n); - -extern void Blt_Ps_Polygon(Blt_Ps ps, Point2d *screenPts, int nScreenPts); - -extern void Blt_Ps_SetPrinting(Blt_Ps ps, int value); +class Graph; +class PageSetup; + +class PostScript { + public: + Graph* graphPtr_; + Tcl_DString dString; + char scratchArr[POSTSCRIPT_BUFSIZ+1]; + + protected: + void addComments(const char**); + void XColorToPostScript(XColor*); + unsigned char ReverseBits(unsigned char); + void ByteToHex(unsigned char, char*); + + public: + PostScript(Graph*); + virtual ~PostScript(); + + void drawPolyline(Point2d*, int); + void drawMaxPolyline(Point2d*, int); + void drawSegments(Segment2d*, int); + void drawBitmap(Display*, Pixmap, double, double); + void drawRectangle(int, int, int, int); + void drawPolygon(Point2d*, int); + void draw3DRectangle(Tk_3DBorder, double, double, int, int, int, int); + + void fillRectangle(double, double, int, int); + void fillRectangles(XRectangle*, int); + void fill3DRectangle(Tk_3DBorder, double, double, int, int, int, int); + void fillPolygon(Point2d*, int); + + void setFont(Tk_Font); + void setLineWidth(int); + void setBackground(XColor*); + void setForeground(XColor*); + void setLineAttributes(XColor*,int, Dashes*, int, int); + void setClearBackground(); + void setDashes(Dashes*); + void setJoinStyle(int); + void setCapStyle(int); + void setBitmap(Display*, Pixmap, int, int); + + int preamble(const char*); + int computeBBox(int, int); + const char* getValue(int*); + void append(const char*); + void format(const char*, ...); + void varAppend(const char*, ...); + int includeFile(const char*); +}; -#endif /* BLT_PS_H */ +#endif diff --git a/src/bltGrPostscriptOp.C b/src/bltGrPostscriptOp.C index eff6457..70c6474 100644 --- a/src/bltGrPostscriptOp.C +++ b/src/bltGrPostscriptOp.C @@ -138,24 +138,24 @@ static int OutputOp(ClientData clientData, Tcl_Interp* interp, } } - PostScript *psPtr = Blt_Ps_Create(graphPtr->interp_, graphPtr->pageSetup_); + PostScript* psPtr = new PostScript(graphPtr); if (PageSetupObjConfigure(graphPtr, interp, objc-3, objv+3) != TCL_OK) { if (channel) Tcl_Close(interp, channel); - Blt_Ps_Free(psPtr); + delete psPtr; return TCL_ERROR; } if (graphPtr->print(fileName, psPtr) != TCL_OK) { if (channel) Tcl_Close(interp, channel); - Blt_Ps_Free(psPtr); + delete psPtr; return TCL_ERROR; } int length; - const char *buffer = Blt_Ps_GetValue(psPtr, &length); + const char* buffer = psPtr->getValue(&length); if (channel) { int nBytes = Tcl_Write(channel, buffer, length); if (nBytes < 0) { @@ -163,7 +163,7 @@ static int OutputOp(ClientData clientData, Tcl_Interp* interp, Tcl_PosixError(interp), (char *)NULL); if (channel) Tcl_Close(interp, channel); - Blt_Ps_Free(psPtr); + delete psPtr; return TCL_ERROR; } Tcl_Close(interp, channel); @@ -171,7 +171,8 @@ static int OutputOp(ClientData clientData, Tcl_Interp* interp, else Tcl_SetStringObj(Tcl_GetObjResult(interp), buffer, length); - Blt_Ps_Free(psPtr); + delete psPtr; + return TCL_OK; } @@ -181,108 +182,3 @@ const Ensemble pageSetupEnsemble[] = { {"output", OutputOp, 0}, { 0,0,0 } }; - -// Support - -static void AddComments(Blt_Ps ps, const char **comments) -{ - const char **p; - for (p = comments; *p; p += 2) { - if (*(p+1) == NULL) { - break; - } - Blt_Ps_Format(ps, "%% %s: %s\n", *p, *(p+1)); - } -} - -int PostScriptPreamble(Graph* graphPtr, const char *fileName, Blt_Ps ps) -{ - PageSetup *setupPtr = graphPtr->pageSetup_; - PageSetupOptions* ops = (PageSetupOptions*)setupPtr->ops_; - time_t ticks; - char date[200]; /* Holds the date string from ctime() */ - char *newline; - - if (fileName == NULL) { - fileName = Tk_PathName(graphPtr->tkwin_); - } - Blt_Ps_Append(ps, "%!PS-Adobe-3.0 EPSF-3.0\n"); - - /* - * The "BoundingBox" comment is required for EPS files. The box - * coordinates are integers, so we need round away from the center of the - * box. - */ - Blt_Ps_Format(ps, "%%%%BoundingBox: %d %d %d %d\n", - setupPtr->left, setupPtr->paperHeight - setupPtr->top, - setupPtr->right, setupPtr->paperHeight - setupPtr->bottom); - - Blt_Ps_Append(ps, "%%Pages: 0\n"); - - Blt_Ps_Format(ps, "%%%%Creator: (%s %s %s)\n", - PACKAGE_NAME, PACKAGE_VERSION, Tk_Class(graphPtr->tkwin_)); - - ticks = time((time_t *) NULL); - strcpy(date, ctime(&ticks)); - newline = date + strlen(date) - 1; - if (*newline == '\n') { - *newline = '\0'; - } - Blt_Ps_Format(ps, "%%%%CreationDate: (%s)\n", date); - Blt_Ps_Format(ps, "%%%%Title: (%s)\n", fileName); - Blt_Ps_Append(ps, "%%DocumentData: Clean7Bit\n"); - if (ops->landscape) { - Blt_Ps_Append(ps, "%%Orientation: Landscape\n"); - } else { - Blt_Ps_Append(ps, "%%Orientation: Portrait\n"); - } - Blt_Ps_Append(ps, "%%DocumentNeededResources: font Helvetica Courier\n"); - AddComments(ps, ops->comments); - Blt_Ps_Append(ps, "%%EndComments\n\n"); - if (Blt_Ps_IncludeFile(graphPtr->interp_, ps, "bltGraph.pro") != TCL_OK) { - return TCL_ERROR; - } - if (ops->footer) { - const char *who; - - who = getenv("LOGNAME"); - if (who == NULL) { - who = "???"; - } - Blt_Ps_VarAppend(ps, - "8 /Helvetica SetFont\n", - "10 30 moveto\n", - "(Date: ", date, ") show\n", - "10 20 moveto\n", - "(File: ", fileName, ") show\n", - "10 10 moveto\n", - "(Created by: ", who, "@", Tcl_GetHostName(), ") show\n", - "0 0 moveto\n", - (char *)NULL); - } - /* - * Set the conversion from PostScript to X11 coordinates. Scale pica to - * pixels and flip the y-axis (the origin is the upperleft corner). - */ - Blt_Ps_VarAppend(ps, - "% Transform coordinate system to use X11 coordinates\n\n", - "% 1. Flip y-axis over by reversing the scale,\n", - "% 2. Translate the origin to the other side of the page,\n", - "% making the origin the upper left corner\n", (char *)NULL); - Blt_Ps_Format(ps, "1 -1 scale\n"); - /* Papersize is in pixels. Translate the new origin *after* changing the - * scale. */ - Blt_Ps_Format(ps, "0 %d translate\n\n", -setupPtr->paperHeight); - Blt_Ps_VarAppend(ps, "% User defined page layout\n\n", - "% Set color level\n", (char *)NULL); - Blt_Ps_Format(ps, "%% Set origin\n%d %d translate\n\n", - setupPtr->left, setupPtr->bottom); - if (ops->landscape) { - Blt_Ps_Format(ps, - "%% Landscape orientation\n0 %g translate\n-90 rotate\n", - ((double)graphPtr->width_ * setupPtr->scale)); - } - Blt_Ps_Append(ps, "\n%%EndSetup\n\n"); - return TCL_OK; -} - diff --git a/src/bltGrText.C b/src/bltGrText.C index 151e564..a13ba24 100644 --- a/src/bltGrText.C +++ b/src/bltGrText.C @@ -130,7 +130,7 @@ void TextStyle::drawText2(Drawable drawable, const char *text, *hh = h1; } -void TextStyle::printText(Blt_Ps ps, const char *text, int x, int y) +void TextStyle::printText(PostScript* psPtr, const char *text, int x, int y) { // TextStyleOptions* ops = (TextStyleOptions*)ops_; diff --git a/src/bltGrText.h b/src/bltGrText.h index 60d1009..d72ecab 100644 --- a/src/bltGrText.h +++ b/src/bltGrText.h @@ -35,7 +35,7 @@ #include "bltGrMisc.h" class Graph; -typedef struct _Blt_Ps *Blt_Ps; +class PostScript; typedef struct { Tk_Anchor anchor; @@ -68,7 +68,7 @@ class TextStyle { void* ops() {return ops_;} void drawText(Drawable, const char*, int, int); void drawText2(Drawable, const char*, int, int, int*, int*); - void printText(Blt_Ps, const char*, int, int); + void printText(PostScript*, const char*, int, int); void getExtents(const char*, int*, int*); }; diff --git a/src/bltGraph.C b/src/bltGraph.C index a8f1ec7..c5e5a88 100644 --- a/src/bltGraph.C +++ b/src/bltGraph.C @@ -54,8 +54,6 @@ using namespace Blt; #define MARKER_ABOVE 0 #define MARKER_UNDER 1 -extern int PostScriptPreamble(Graph* graphPtr, const char *fileName, Blt_Ps ps); - // OptionSpecs Graph::Graph(ClientData clientData, Tcl_Interp* interp, @@ -348,10 +346,9 @@ void Graph::draw() Tk_FreePixmap(display_, drawable); } -int Graph::print(const char *ident, Blt_Ps ps) +int Graph::print(const char* ident, PostScript* psPtr) { GraphOptions* ops = (GraphOptions*)ops_; - PageSetup *setupPtr = pageSetup_; PageSetupOptions* pops = (PageSetupOptions*)pageSetup_->ops_; // We need to know how big a graph to print. If the graph hasn't been drawn @@ -368,11 +365,10 @@ int Graph::print(const char *ident, Blt_Ps ps) else if (height_ < 2) height_ = Tk_ReqHeight(tkwin_); - Blt_Ps_ComputeBoundingBox(setupPtr, width_, height_); + psPtr->computeBBox(width_, height_); flags |= RESET; /* Turn on PostScript measurements when computing the graph's layout. */ - Blt_Ps_SetPrinting(ps, 1); reconfigure(); map(); @@ -383,72 +379,72 @@ int Graph::print(const char *ident, Blt_Ps ps) int w = (right_ - left_ + 1) + (2*ops->plotBW); int h = (bottom_ - top_ + 1) + (2*ops->plotBW); - int result = PostScriptPreamble(this, ident, ps); + int result = psPtr->preamble(ident); if (result != TCL_OK) goto error; - Blt_Ps_XSetFont(ps, ops->titleTextStyle.font); + psPtr->setFont(ops->titleTextStyle.font); if (pops->decorations) - Blt_Ps_XSetBackground(ps, Tk_3DBorderColor(ops->plotBg)); + psPtr->setBackground(Tk_3DBorderColor(ops->plotBg)); else - Blt_Ps_SetClearBackground(ps); + psPtr->setClearBackground(); - Blt_Ps_XFillRectangle(ps, x, y, w, h); - Blt_Ps_Rectangle(ps, x, y, w, h); - Blt_Ps_Append(ps, "gsave clip\n\n"); + psPtr->fillRectangle(x, y, w, h); + psPtr->drawRectangle(x, y, w, h); + psPtr->append("gsave clip\n\n"); // Start - printMargins(ps); + printMargins(psPtr); switch (legend_->position()) { case Legend::TOP: case Legend::BOTTOM: case Legend::RIGHT: case Legend::LEFT: - legend_->print(ps); + legend_->print(psPtr); break; default: break; } - printAxesGrids(ps); - printAxes(ps); - printAxesLimits(ps); + printAxesGrids(psPtr); + printAxes(psPtr); + printAxesLimits(psPtr); if (!legend_->isRaised()) { switch (legend_->position()) { case Legend::PLOT: case Legend::XY: - legend_->print(ps); + legend_->print(psPtr); break; default: break; } } - printMarkers(ps, MARKER_UNDER); - printElements(ps); - printActiveElements(ps); + printMarkers(psPtr, MARKER_UNDER); + printElements(psPtr); + printActiveElements(psPtr); if (legend_->isRaised()) { switch (legend_->position()) { case Legend::PLOT: case Legend::XY: - legend_->print(ps); + legend_->print(psPtr); break; default: break; } } - printMarkers(ps, MARKER_ABOVE); + printMarkers(psPtr, MARKER_ABOVE); - Blt_Ps_VarAppend(ps, "\n", "% Unset clipping\n", "grestore\n\n", NULL); - Blt_Ps_VarAppend(ps, "showpage\n", "%Trailer\n", "grestore\n", "end\n", "%EOF\n", NULL); + psPtr->varAppend("\n", "% Unset clipping\n", "grestore\n\n", NULL); + psPtr->varAppend("showpage\n", "%Trailer\n", "grestore\n", "end\n", "%EOF\n", + NULL); error: width_ = Tk_Width(tkwin_); height_ = Tk_Height(tkwin_); - Blt_Ps_SetPrinting(ps, 0); reconfigure(); // Redraw the graph in order to re-calculate the layout as soon as @@ -557,7 +553,7 @@ void Graph::drawMargins(Drawable drawable) } } -void Graph::printMargins(Blt_Ps ps) +void Graph::printMargins(PostScript* psPtr) { GraphOptions* ops = (GraphOptions*)ops_; PageSetupOptions* pops = (PageSetupOptions*)pageSetup_->ops_; @@ -576,27 +572,27 @@ void Graph::printMargins(Blt_Ps ps) // Clear the surrounding margins and clip the plotting surface if (pops->decorations) - Blt_Ps_XSetBackground(ps, Tk_3DBorderColor(ops->normalBg)); + psPtr->setBackground(Tk_3DBorderColor(ops->normalBg)); else - Blt_Ps_SetClearBackground(ps); + psPtr->setClearBackground(); - Blt_Ps_Append(ps, "% Margins\n"); - Blt_Ps_XFillRectangles(ps, margin, 4); + psPtr->append("% Margins\n"); + psPtr->fillRectangles(margin, 4); - Blt_Ps_Append(ps, "% Interior 3D border\n"); + psPtr->append("% Interior 3D border\n"); if (ops->plotBW > 0) { int x = left_ - ops->plotBW; int y = top_ - ops->plotBW; int w = (right_ - left_) + (2*ops->plotBW); int h = (bottom_ - top_) + (2*ops->plotBW); - Blt_Ps_Draw3DRectangle(ps, ops->normalBg, (double)x, (double)y, w, h, + psPtr->draw3DRectangle(ops->normalBg, (double)x, (double)y, w, h, ops->plotBW, ops->plotRelief); } if (ops->title) { - Blt_Ps_Append(ps, "% Graph title\n"); + psPtr->append("% Graph title\n"); TextStyle ts(this, &ops->titleTextStyle); - ts.printText(ps, ops->title, (double)titleX_, (double)titleY_); + ts.printText(psPtr, ops->title, (double)titleX_, (double)titleY_); } } @@ -698,21 +694,21 @@ void Graph::drawActiveElements(Drawable drawable) } } -void Graph::printElements(Blt_Ps ps) +void Graph::printElements(PostScript* psPtr) { for (Blt_ChainLink link=Blt_Chain_LastLink(elements_.displayList); link != NULL; link = Blt_Chain_PrevLink(link)) { Element* elemPtr = (Element*)Blt_Chain_GetValue(link); - elemPtr->print(ps); + elemPtr->print(psPtr); } } -void Graph::printActiveElements(Blt_Ps ps) +void Graph::printActiveElements(PostScript* psPtr) { for (Blt_ChainLink link=Blt_Chain_LastLink(elements_.displayList); link; link = Blt_Chain_PrevLink(link)) { Element* elemPtr = (Element*)Blt_Chain_GetValue(link); - elemPtr->printActive(ps); + elemPtr->printActive(psPtr); } } @@ -804,7 +800,7 @@ void Graph::drawMarkers(Drawable drawable, int under) } } -void Graph::printMarkers(Blt_Ps ps, int under) +void Graph::printMarkers(PostScript* psPtr, int under) { for (Blt_ChainLink link = Blt_Chain_LastLink(markers_.displayList); link; link = Blt_Chain_PrevLink(link)) { @@ -819,9 +815,9 @@ void Graph::printMarkers(Blt_Ps ps, int under) if (isElementHidden(markerPtr)) continue; - Blt_Ps_VarAppend(ps, "\n% Marker \"", markerPtr->name_, - "\" is a ", markerPtr->className(), ".\n", (char*)NULL); - markerPtr->print(ps); + psPtr->varAppend("\n% Marker \"", markerPtr->name_, + "\" is a ", markerPtr->className(), ".\n", NULL); + markerPtr->print(psPtr); } } @@ -848,7 +844,7 @@ Marker* Graph::nearestMarker(int x, int y, int under) if (isElementHidden(markerPtr)) continue; - if ((mops->drawUnder == under) && (mops->state == BLT_STATE_NORMAL)) + if (mops->drawUnder == under) if (markerPtr->pointIn(&point)) return markerPtr; } @@ -1037,7 +1033,7 @@ void Graph::drawAxesGrids(Drawable drawable) } } -void Graph::printAxes(Blt_Ps ps) +void Graph::printAxes(PostScript* psPtr) { GraphOptions* ops = (GraphOptions*)ops_; @@ -1046,12 +1042,12 @@ void Graph::printAxes(Blt_Ps ps) for (Blt_ChainLink link=Blt_Chain_FirstLink(mp->axes); link; link = Blt_Chain_NextLink(link)) { Axis *axisPtr = (Axis*)Blt_Chain_GetValue(link); - axisPtr->print(ps); + axisPtr->print(psPtr); } } } -void Graph::printAxesGrids(Blt_Ps ps) +void Graph::printAxesGrids(PostScript* psPtr) { GraphOptions* ops = (GraphOptions*)ops_; @@ -1059,18 +1055,18 @@ void Graph::printAxesGrids(Blt_Ps ps) for (Blt_ChainLink link=Blt_Chain_FirstLink(ops->margins[ii].axes); link; link = Blt_Chain_NextLink(link)) { Axis *axisPtr = (Axis*)Blt_Chain_GetValue(link); - axisPtr->printGrids(ps); + axisPtr->printGrids(psPtr); } } } -void Graph::printAxesLimits(Blt_Ps ps) +void Graph::printAxesLimits(PostScript* psPtr) { Tcl_HashSearch cursor; for (Tcl_HashEntry* hPtr=Tcl_FirstHashEntry(&axes_.table, &cursor); hPtr; hPtr = Tcl_NextHashEntry(&cursor)) { Axis *axisPtr = (Axis*)Tcl_GetHashValue(hPtr); - axisPtr->printLimits(ps); + axisPtr->printLimits(psPtr); } } diff --git a/src/bltGraph.h b/src/bltGraph.h index c47e294..8f58222 100644 --- a/src/bltGraph.h +++ b/src/bltGraph.h @@ -39,8 +39,6 @@ extern "C" { #include "bltGrMisc.h" #include "bltGrText.h" -typedef struct _Blt_Ps *Blt_Ps; - class Graph; class BindTable; class Crosshairs; @@ -49,6 +47,7 @@ class Element; class Legend; class Pen; class PageSetup; +class PostScript; class Pick { public: @@ -181,7 +180,7 @@ class Graph : public Pick { void layoutGraph(); void drawMargins(Drawable); - void printMargins(Blt_Ps); + void printMargins(PostScript*); int getMarginGeometry(Margin*); void destroyPens(); @@ -191,14 +190,14 @@ class Graph : public Pick { virtual void mapElements(); void drawElements(Drawable); void drawActiveElements(Drawable); - void printElements(Blt_Ps); - void printActiveElements(Blt_Ps); + void printElements(PostScript*); + void printActiveElements(PostScript*); void destroyMarkers(); void configureMarkers(); void mapMarkers(); void drawMarkers(Drawable, int); - void printMarkers(Blt_Ps, int); + void printMarkers(PostScript*, int); int createAxes(); void destroyAxes(); @@ -217,7 +216,7 @@ class Graph : public Pick { void map(); void draw(); void eventuallyRedraw(); - int print(const char*, Blt_Ps); + int print(const char*, PostScript*); void extents(Region2d*); int invoke(const Ensemble*, int, int, Tcl_Obj* const []); void reconfigure(); @@ -226,9 +225,9 @@ class Graph : public Pick { void disableCrosshairs(); int createAxis(int, Tcl_Obj* const []); - void printAxes(Blt_Ps); - void printAxesGrids(Blt_Ps); - void printAxesLimits(Blt_Ps); + void printAxes(PostScript*); + void printAxesGrids(PostScript*); + void printAxesLimits(PostScript*); int getAxis(Tcl_Obj*, Axis**); ClientData axisTag(const char*); Point2d map2D(double, double, Axis*, Axis*); @@ -255,9 +254,6 @@ class Graph : public Pick { ClientData pickEntry(int, int, ClassId*); void drawSegments(Drawable, GC, Segment2d*, int); - void printSegments(Blt_Ps, Segment2d*, int); - void printPolyline(Blt_Ps, Point2d*, int); - void printMaxPolyline(Blt_Ps, Point2d*, int); void setDashes(GC, Dashes*); GC getPrivateGC(unsigned long, XGCValues*); -- cgit v0.12