summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bltGrPSOutput.C31
-rw-r--r--src/bltGrPSOutput.h2
-rw-r--r--src/bltGrText.C28
-rw-r--r--src/bltGraph.C2
-rw-r--r--tests/linegraph.tcl2
-rw-r--r--tests/test.tcl2
6 files changed, 42 insertions, 25 deletions
diff --git a/src/bltGrPSOutput.C b/src/bltGrPSOutput.C
index a91c1bc..6e101d9 100644
--- a/src/bltGrPSOutput.C
+++ b/src/bltGrPSOutput.C
@@ -227,7 +227,7 @@ void PostScript::fillRectangles(XRectangle* rectangles, int nRectangles)
void PostScript::setBackground(XColor* colorPtr)
{
PageSetupOptions* pops = (PageSetupOptions*)graphPtr_->pageSetup_->ops_;
- XColorToPostScript(colorPtr);
+ printXColor(colorPtr);
append(" setrgbcolor\n");
if (pops->greyscale)
append(" currentgray setgray\n");
@@ -236,7 +236,7 @@ void PostScript::setBackground(XColor* colorPtr)
void PostScript::setForeground(XColor* colorPtr)
{
PageSetupOptions* pops = (PageSetupOptions*)graphPtr_->pageSetup_->ops_;
- XColorToPostScript(colorPtr);
+ printXColor(colorPtr);
append(" setrgbcolor\n");
if (pops->greyscale)
append(" currentgray setgray\n");
@@ -244,20 +244,11 @@ void PostScript::setForeground(XColor* colorPtr)
void PostScript::setFont(Tk_Font font)
{
-#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
+ Tcl_DString psdstr;
+ Tcl_DStringInit(&psdstr);
+ int psSize = Tk_PostscriptFontName(font, &psdstr);
+ format("%d /%s SetFont\n", psSize, Tcl_DStringValue(&psdstr));
+ Tcl_DStringFree(&psdstr);
}
void PostScript::setLineAttributes(XColor* colorPtr,int lineWidth,
@@ -468,12 +459,12 @@ void PostScript::setBitmap(Display *display, Pixmap bitmap, int w, int h)
XDestroyImage(imagePtr);
}
-void PostScript::XColorToPostScript(XColor* colorPtr)
+void PostScript::printXColor(XColor* colorPtr)
{
format("%g %g %g",
- ((double)(colorPtr->red >> 8) / 255.0),
- ((double)(colorPtr->green >> 8) / 255.0),
- ((double)(colorPtr->blue >> 8) / 255.0));
+ ((double)(colorPtr->red >> 8) / 255.0),
+ ((double)(colorPtr->green >> 8) / 255.0),
+ ((double)(colorPtr->blue >> 8) / 255.0));
}
int PostScript::preamble(const char* fileName)
diff --git a/src/bltGrPSOutput.h b/src/bltGrPSOutput.h
index d16da97..b963d5d 100644
--- a/src/bltGrPSOutput.h
+++ b/src/bltGrPSOutput.h
@@ -45,7 +45,7 @@ class PostScript {
protected:
void addComments(const char**);
- void XColorToPostScript(XColor*);
+ void printXColor(XColor*);
unsigned char reverseBits(unsigned char);
void byteToHex(unsigned char, char*);
void setJoinStyle(int);
diff --git a/src/bltGrText.C b/src/bltGrText.C
index bfbaed3..44b3aca 100644
--- a/src/bltGrText.C
+++ b/src/bltGrText.C
@@ -132,12 +132,36 @@ void TextStyle::drawText2(Drawable drawable, const char *text,
void TextStyle::printText(PostScript* psPtr, const char *text, int x, int y)
{
- // TextStyleOptions* ops = (TextStyleOptions*)ops_;
+ TextStyleOptions* ops = (TextStyleOptions*)ops_;
+ cerr << x << ',' << y << '=' << text << endl;
if (!text || !(*text))
return;
- psPtr->printText(text, x, y);
+ int w1, h1;
+ Tk_TextLayout layout = Tk_ComputeTextLayout(ops->font, text, -1, -1,
+ ops->justify, 0, &w1, &h1);
+
+ Tk_FontMetrics fm;
+ Tk_GetFontMetrics(ops->font, &fm);
+
+ // %Stack : w h theta centerX centerY
+ psPtr->format("%d %d %g %g %g BeginText\n", w1, h1, ops->angle, double(x), double(y));
+ psPtr->setFont(ops->font);
+ psPtr->setForeground(ops->color);
+
+ Tcl_ResetResult(graphPtr_->interp_);
+ Tk_TextLayoutToPostscript(graphPtr_->interp_, layout);
+ const char* ss = Blt::dupstr(Tcl_GetStringResult(graphPtr_->interp_));
+ Tcl_ResetResult(graphPtr_->interp_);
+ // %Stack : str strWidth x y
+ int width = Tk_TextWidth(ops->font, ss, strlen(ss));
+ psPtr->format("%s %d %g %g DrawAdjText\n", ss, width, 0., 0.);
+ delete [] ss;
+
+ psPtr->format("EndText\n");
+
+ // psPtr->printText(text, x, y);
}
void TextStyle::resetStyle()
diff --git a/src/bltGraph.C b/src/bltGraph.C
index 6857100..d7456d9 100644
--- a/src/bltGraph.C
+++ b/src/bltGraph.C
@@ -391,7 +391,7 @@ int Graph::print(const char* ident, PostScript* psPtr)
psPtr->fillRectangle(x, y, w, h);
psPtr->printRectangle(x, y, w, h);
- psPtr->append("gsave clip\n\n");
+ psPtr->append("gsave\n\n");
// Start
printMargins(psPtr);
diff --git a/tests/linegraph.tcl b/tests/linegraph.tcl
index 574282c..d591348 100644
--- a/tests/linegraph.tcl
+++ b/tests/linegraph.tcl
@@ -62,7 +62,7 @@ bltCmd $graph configure -background cyan
##bltCmd $graph legend
##bltCmd $graph marker
##bltCmd $graph pen
-##bltCmd $graph postscript
+#bltCmd $graph postscript output foo.ps
#bltCmd $graph transform
##bltCmd $graph x2axis
##bltCmd $graph xaxis
diff --git a/tests/test.tcl b/tests/test.tcl
index b51a5f2..120958b 100644
--- a/tests/test.tcl
+++ b/tests/test.tcl
@@ -4,6 +4,8 @@ set w .line
set graph [bltLineGraph $w]
#set graph [bltBarGraph $w]
+$graph postscript output foo.ps
+
#echo "done"
#bltPlotDestroy $w