diff options
author | joye <joye> | 2014-06-10 18:37:20 (GMT) |
---|---|---|
committer | joye <joye> | 2014-06-10 18:37:20 (GMT) |
commit | 53fb30583d98af5691e8581fcf33fc3b8fadf923 (patch) | |
tree | bcfae60fbcbe4849f547b89b5a06098bd3b9a1ca | |
parent | bbdf932bc3724c5a11cb4c415995e5385cb251ec (diff) | |
download | blt-53fb30583d98af5691e8581fcf33fc3b8fadf923.zip blt-53fb30583d98af5691e8581fcf33fc3b8fadf923.tar.gz blt-53fb30583d98af5691e8581fcf33fc3b8fadf923.tar.bz2 |
*** empty log message ***
-rw-r--r-- | src/bltGrPSOutput.C | 53 | ||||
-rw-r--r-- | src/bltGrText.C | 32 |
2 files changed, 81 insertions, 4 deletions
diff --git a/src/bltGrPSOutput.C b/src/bltGrPSOutput.C index dbfed5e..9e8da53 100644 --- a/src/bltGrPSOutput.C +++ b/src/bltGrPSOutput.C @@ -814,9 +814,62 @@ void PostScript::prolog() " stroke\n" "} def\n" "\n" +"/baseline 0 def\n" +"/height 0 def\n" +"/justify 0 def\n" +"/lineLength 0 def\n" +"/spacing 0 def\n" +"/strings 0 def\n" +"/xoffset 0 def\n" +"/yoffset 0 def\n" +"/baselineSampler ( TXygqPZ) def\n" +"% Put an extra-tall character in; done this way to avoid encoding trouble\n" +"baselineSampler 0 196 put\n" +"\n" +"/cstringshow {\n" +" {\n" +" dup type /stringtype eq\n" +" { show } { glyphshow }\n" +" ifelse\n" +" } forall\n" +"} bind def\n" +"\n" +"/cstringwidth {\n" +" 0 exch 0 exch\n" +" {\n" +" dup type /stringtype eq\n" +" { stringwidth } {\n" +" currentfont /Encoding get exch 1 exch put (\001)\n" +" stringwidth\n" +" }\n" +" ifelse\n" +" exch 3 1 roll add 3 1 roll add exch\n" +" } forall\n" +"} bind def\n" +"\n" "/DrawText {\n" " gsave\n" +" /justify exch def\n" +" /yoffset exch def\n" +" /xoffset exch def\n" +" /spacing exch def\n" " /strings exch def\n" +" % First scan through all of the text to find the widest line.\n" +" /lineLength 0 def\n" +" strings {\n" +" cstringwidth pop\n" +" dup lineLength gt {/lineLength exch def} {pop} ifelse\n" +" newpath\n" +" } forall\n" +" % Compute the baseline offset and the actual font height.\n" +" 0 0 moveto baselineSampler false charpath\n" +" pathbbox dup /baseline exch def\n" +" exch pop exch sub /height exch def pop\n" +" newpath\n" +" % Translate and rotate coordinates first so that the origin is at\n" +" % the upper-left corner of the text's bounding box. Remember that\n" +" % angle for rotating, and x and y for positioning are still on the\n" +" % stack.\n" " translate\n" " neg rotate\n" " 0 0 moveto\n" diff --git a/src/bltGrText.C b/src/bltGrText.C index d2f0fd3..f806e72 100644 --- a/src/bltGrText.C +++ b/src/bltGrText.C @@ -142,14 +142,38 @@ void TextStyle::printText(PostScript* psPtr, const char *text, int x, int y) ops->justify, 0, &w1, &h1); // cerr << '(' << x << ',' << y << ')' << ' ' << text << endl; + + int xx =0; + int yy =0; + switch (ops->anchor) { + case TK_ANCHOR_NW: xx = 0; yy = 0; break; + case TK_ANCHOR_N: xx = 1; yy = 0; break; + case TK_ANCHOR_NE: xx = 2; yy = 0; break; + case TK_ANCHOR_E: xx = 2; yy = 1; break; + case TK_ANCHOR_SE: xx = 2; yy = 2; break; + case TK_ANCHOR_S: xx = 1; yy = 2; break; + case TK_ANCHOR_SW: xx = 0; yy = 2; break; + case TK_ANCHOR_W: xx = 0; yy = 1; break; + case TK_ANCHOR_CENTER: xx = 1; yy = 1; break; + } + + const char* justify =NULL; + switch (ops->justify) { + case TK_JUSTIFY_LEFT: justify = "0"; break; + case TK_JUSTIFY_CENTER: justify = "0.5"; break; + case TK_JUSTIFY_RIGHT: justify = "1"; break; + } + + Tk_FontMetrics fm; + Tk_GetFontMetrics(ops->font, &fm); + psPtr->format("%g %d %d [\n", ops->angle, x, y); Tcl_ResetResult(graphPtr_->interp_); Tk_TextLayoutToPostscript(graphPtr_->interp_, layout); - const char* ss = Tcl_GetStringResult(graphPtr_->interp_); - psPtr->append(ss); + psPtr->append(Tcl_GetStringResult(graphPtr_->interp_)); Tcl_ResetResult(graphPtr_->interp_); - psPtr->format("] DrawText\n"); - // psPtr->format("] %d %g %g %s %s DrawText\n", fm.linespace, xx/-2.0, yy/2.0, justify, "false"); + psPtr->format("] %d %g %g %s DrawText\n", + fm.linespace, xx/-2.0, yy/2.0, justify); #if 0 double w2, h2; |