summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjoye <joye>2014-05-06 18:43:52 (GMT)
committerjoye <joye>2014-05-06 18:43:52 (GMT)
commitb78feb1c2483283e3453fc95ce4b9a99ef3021cc (patch)
treefd254dc89fc02ed13218ffc59157cb30320ad4f8 /src
parent4eeb7705df89fdf5146da010b471e40dc2a7e708 (diff)
downloadblt-b78feb1c2483283e3453fc95ce4b9a99ef3021cc.zip
blt-b78feb1c2483283e3453fc95ce4b9a99ef3021cc.tar.gz
blt-b78feb1c2483283e3453fc95ce4b9a99ef3021cc.tar.bz2
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r--src/bltGrPSOutput.h2
-rw-r--r--src/bltGrText.C197
-rw-r--r--src/bltGraph.h5
3 files changed, 7 insertions, 197 deletions
diff --git a/src/bltGrPSOutput.h b/src/bltGrPSOutput.h
index 1f6593a..307b2d8 100644
--- a/src/bltGrPSOutput.h
+++ b/src/bltGrPSOutput.h
@@ -33,7 +33,7 @@
#include <tk.h>
#include "bltConfig.h"
-#include "bltText.h"
+//#include "bltGrText.h"
#define POSTSCRIPT_BUFSIZ ((BUFSIZ*2)-1)
struct _Blt_Ps {
diff --git a/src/bltGrText.C b/src/bltGrText.C
index 3da3d04..b540e04 100644
--- a/src/bltGrText.C
+++ b/src/bltGrText.C
@@ -39,11 +39,6 @@ extern "C" {
#include "bltGraph.h"
#include "bltPs.h"
-#define ROTATE_0 0
-#define ROTATE_90 1
-#define ROTATE_180 2
-#define ROTATE_270 3
-
TextStyle::TextStyle(Graph* graphPtr)
{
ops_ = (TextStyleOptions*)calloc(1, sizeof(TextStyleOptions));
@@ -126,7 +121,7 @@ void TextStyle::drawText2(Drawable drawable, const char *text,
if (angle != 0.0) {
double rotWidth, rotHeight;
- Blt_GetBoundingBox(w1, h1, angle, &rotWidth, &rotHeight, (Point2d*)NULL);
+ graphPtr_->getBoundingBox(w1, h1, angle, &rotWidth, &rotHeight, NULL);
w1 = rotWidth;
h1 = rotHeight;
}
@@ -177,7 +172,7 @@ Point2d TextStyle::rotateText(int x, int y, int w1, int h1)
double ccos = cos(M_PI*angle/180.);
double ssin = sin(M_PI*angle/180.);
double w2, h2;
- Blt_GetBoundingBox(w1, h1, angle, &w2, &h2, (Point2d *)NULL);
+ graphPtr_->getBoundingBox(w1, h1, angle, &w2, &h2, NULL);
double x1 = x+w1/2.;
double y1 = y+h1/2.;
@@ -187,7 +182,7 @@ Point2d TextStyle::rotateText(int x, int y, int w1, int h1)
double rx = x*ccos + y*ssin + (-x1*ccos -y1*ssin +x2);
double ry = -x*ssin + y*ccos + ( x1*ssin -y1*ccos +y2);
- return Blt_AnchorPoint(rx, ry, w2, h2, ops->anchor);
+ return graphPtr_->anchorPoint(rx, ry, w2, h2, ops->anchor);
}
void TextStyle::getExtents(const char *text, int* ww, int* hh)
@@ -199,189 +194,3 @@ void TextStyle::getExtents(const char *text, int* ww, int* hh)
*ww = w + 2*xPad_;
*hh = h + 2*yPad_;
}
-
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_GetBoundingBox
- *
- * Computes the dimensions of the bounding box surrounding a rectangle
- * rotated about its center. If pointArr isn't NULL, the coordinates of
- * the rotated rectangle are also returned.
- *
- * The dimensions are determined by rotating the rectangle, and doubling
- * the maximum x-coordinate and y-coordinate.
- *
- * w = 2 * maxX, h = 2 * maxY
- *
- * Since the rectangle is centered at 0,0, the coordinates of the
- * bounding box are (-w/2,-h/2 w/2,-h/2, w/2,h/2 -w/2,h/2).
- *
- * 0 ------- 1
- * | |
- * | x |
- * | |
- * 3 ------- 2
- *
- * Results:
- * The width and height of the bounding box containing the rotated
- * rectangle are returned.
- *
- *---------------------------------------------------------------------------
- */
-void Blt_GetBoundingBox(int width, int height, float angle,
- double *rotWidthPtr, double *rotHeightPtr,
- Point2d *bbox)
-{
- int i;
- double sinTheta, cosTheta;
- double radians;
- double xMax, yMax;
- double x, y;
- Point2d corner[4];
-
- angle = fmod(angle, 360.0);
- if (fmod(angle, (double)90.0) == 0.0) {
- int ll, ur, ul, lr;
- double rotWidth, rotHeight;
-
- /* Handle right-angle rotations specially. */
-
- int quadrant = (int)(angle / 90.0);
- switch (quadrant) {
- case ROTATE_270: /* 270 degrees */
- ul = 3, ur = 0, lr = 1, ll = 2;
- rotWidth = (double)height;
- rotHeight = (double)width;
- break;
- case ROTATE_90: /* 90 degrees */
- ul = 1, ur = 2, lr = 3, ll = 0;
- rotWidth = (double)height;
- rotHeight = (double)width;
- break;
- case ROTATE_180: /* 180 degrees */
- ul = 2, ur = 3, lr = 0, ll = 1;
- rotWidth = (double)width;
- rotHeight = (double)height;
- break;
- default:
- case ROTATE_0: /* 0 degrees */
- ul = 0, ur = 1, lr = 2, ll = 3;
- rotWidth = (double)width;
- rotHeight = (double)height;
- break;
- }
- if (bbox) {
- x = rotWidth * 0.5;
- y = rotHeight * 0.5;
- bbox[ll].x = bbox[ul].x = -x;
- bbox[ur].y = bbox[ul].y = -y;
- bbox[lr].x = bbox[ur].x = x;
- bbox[ll].y = bbox[lr].y = y;
- }
- *rotWidthPtr = rotWidth;
- *rotHeightPtr = rotHeight;
- return;
- }
- /* Set the four corners of the rectangle whose center is the origin. */
- corner[1].x = corner[2].x = (double)width * 0.5;
- corner[0].x = corner[3].x = -corner[1].x;
- corner[2].y = corner[3].y = (double)height * 0.5;
- corner[0].y = corner[1].y = -corner[2].y;
-
- radians = (-angle / 180.0) * M_PI;
- sinTheta = sin(radians), cosTheta = cos(radians);
- xMax = yMax = 0.0;
-
- /* Rotate the four corners and find the maximum X and Y coordinates */
-
- for (i = 0; i < 4; i++) {
- x = (corner[i].x * cosTheta) - (corner[i].y * sinTheta);
- y = (corner[i].x * sinTheta) + (corner[i].y * cosTheta);
- if (x > xMax)
- xMax = x;
-
- if (y > yMax)
- yMax = y;
-
- if (bbox) {
- bbox[i].x = x;
- bbox[i].y = y;
- }
- }
-
- /*
- * By symmetry, the width and height of the bounding box are twice the
- * maximum x and y coordinates.
- */
- *rotWidthPtr = xMax + xMax;
- *rotHeightPtr = yMax + yMax;
-}
-
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_AnchorPoint --
- *
- * Translates a position, using both the dimensions of the bounding box,
- * and the anchor direction, returning the coordinates of the upper-left
- * corner of the box. The anchor indicates where the given x-y position
- * is in relation to the bounding box.
- *
- * 7 nw --- 0 n --- 1 ne
- * | |
- * 6 w 8 center 2 e
- * | |
- * 5 sw --- 4 s --- 3 se
- *
- * The coordinates returned are translated to the origin of the bounding
- * box (suitable for giving to XCopyArea, XCopyPlane, etc.)
- *
- * Results:
- * The translated coordinates of the bounding box are returned.
- *
- *---------------------------------------------------------------------------
- */
-Point2d Blt_AnchorPoint(double x, double y, double w, double h,
- Tk_Anchor anchor)
-{
- Point2d t;
-
- switch (anchor) {
- case TK_ANCHOR_NW: /* 7 Upper left corner */
- break;
- case TK_ANCHOR_W: /* 6 Left center */
- y -= (h * 0.5);
- break;
- case TK_ANCHOR_SW: /* 5 Lower left corner */
- y -= h;
- break;
- case TK_ANCHOR_N: /* 0 Top center */
- x -= (w * 0.5);
- break;
- case TK_ANCHOR_CENTER: /* 8 Center */
- x -= (w * 0.5);
- y -= (h * 0.5);
- break;
- case TK_ANCHOR_S: /* 4 Bottom center */
- x -= (w * 0.5);
- y -= h;
- break;
- case TK_ANCHOR_NE: /* 1 Upper right corner */
- x -= w;
- break;
- case TK_ANCHOR_E: /* 2 Right center */
- x -= w;
- y -= (h * 0.5);
- break;
- case TK_ANCHOR_SE: /* 3 Lower right corner */
- x -= w;
- y -= h;
- break;
- }
-
- t.x = x;
- t.y = y;
- return t;
-}
-
diff --git a/src/bltGraph.h b/src/bltGraph.h
index 93d461f..ee62432 100644
--- a/src/bltGraph.h
+++ b/src/bltGraph.h
@@ -250,8 +250,9 @@ class Graph {
virtual int createPen(const char*, int, Tcl_Obj* const []) =0;
int getPen(Tcl_Obj*, Pen**);
- void getTextExtents(Tk_Font font, const char *text, int textLen,
- int* ww, int* hh);
+ void getTextExtents(Tk_Font, const char*, int, int*, int*);
+ void getBoundingBox(int, int, float, double*, double*, Point2d*);
+ Point2d anchorPoint(double, double, double, double, Tk_Anchor);
};
extern Blt_BindTagProc Blt_GraphTags;