summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2018-10-26 18:08:40 (GMT)
committerGitHub <noreply@github.com>2018-10-26 18:08:40 (GMT)
commitefb615a0d4b477575e20751fa63a6f7a0f97e931 (patch)
tree0ca9a91f90a1f9724af816d7de4f7836198bb9c3
parent11d2be66bad300683f2a71ec5c1a716a501dde66 (diff)
parent6b41ee3cff858ded8d6af891e7725211ea0aba98 (diff)
downloadblt-efb615a0d4b477575e20751fa63a6f7a0f97e931.zip
blt-efb615a0d4b477575e20751fa63a6f7a0f97e931.tar.gz
blt-efb615a0d4b477575e20751fa63a6f7a0f97e931.tar.bz2
Merge pull request #24 from prs-de/fix-textstyle-memleakv3.2.13
Fix textstyle memleak
-rw-r--r--generic/tkbltGrAxis.C8
-rw-r--r--generic/tkbltGrText.C62
-rw-r--r--generic/tkbltGrText.h2
3 files changed, 28 insertions, 44 deletions
diff --git a/generic/tkbltGrAxis.C b/generic/tkbltGrAxis.C
index 738acc3..be3e995 100644
--- a/generic/tkbltGrAxis.C
+++ b/generic/tkbltGrAxis.C
@@ -685,7 +685,7 @@ void Axis::drawLimits(Drawable drawable)
ops->limitsTextStyle.anchor = TK_ANCHOR_SE;
int ww, hh;
- ts.drawText2(drawable, maxPtr, graphPtr_->right_, hMax, &ww, &hh);
+ ts.drawTextBBox(drawable, maxPtr, graphPtr_->right_, hMax, &ww, &hh);
hMax -= (hh + spacing);
}
else {
@@ -693,7 +693,7 @@ void Axis::drawLimits(Drawable drawable)
ops->limitsTextStyle.anchor = TK_ANCHOR_NW;
int ww, hh;
- ts.drawText2(drawable, maxPtr, vMax, graphPtr_->top_, &ww, &hh);
+ ts.drawTextBBox(drawable, maxPtr, vMax, graphPtr_->top_, &ww, &hh);
vMax += (ww + spacing);
}
}
@@ -704,14 +704,14 @@ void Axis::drawLimits(Drawable drawable)
ops->limitsTextStyle.angle = 90.0;
int ww, hh;
- ts.drawText2(drawable, minPtr, graphPtr_->left_, hMin, &ww, &hh);
+ ts.drawTextBBox(drawable, minPtr, graphPtr_->left_, hMin, &ww, &hh);
hMin -= (hh + spacing);
}
else {
ops->limitsTextStyle.angle = 0.0;
int ww, hh;
- ts.drawText2(drawable, minPtr, vMin, graphPtr_->bottom_, &ww, &hh);
+ ts.drawTextBBox(drawable, minPtr, vMin, graphPtr_->bottom_, &ww, &hh);
vMin += (ww + spacing);
}
}
diff --git a/generic/tkbltGrText.C b/generic/tkbltGrText.C
index 1bed069..0b4e3e3 100644
--- a/generic/tkbltGrText.C
+++ b/generic/tkbltGrText.C
@@ -78,36 +78,17 @@ TextStyle::~TextStyle()
free(ops_);
}
-void TextStyle::drawText(Drawable drawable, const char *text, int x, int y)
-{
- TextStyleOptions* ops = (TextStyleOptions*)ops_;
-
- if (!text || !(*text))
- return;
-
- if (!gc_)
- resetStyle();
-
- int w1, h1;
- Tk_TextLayout layout = Tk_ComputeTextLayout(ops->font, text, -1, -1,
- ops->justify, 0, &w1, &h1);
- Point2d rr = rotateText(x, y, w1, h1);
-#if (TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 6)
- TkDrawAngledTextLayout(graphPtr_->display_, drawable, gc_, layout,
- (int)rr.x, (int)rr.y,
- ops->angle, 0, -1);
-#else
- Tk_DrawTextLayout(graphPtr_->display_, drawable, gc_, layout,
- rr.x, rr.y, 0, -1);
-#endif
+void TextStyle::drawText(Drawable drawable, const char *text, double x, double y) {
+ drawText(drawable, text, (int)x, (int)y);
}
-void TextStyle::drawText(Drawable drawable, const char *text, double x, double y) {
- return drawText(drawable, text, (int)x, (int)y);
+void TextStyle::drawText(Drawable drawable, const char *text, int x, int y)
+{
+ drawTextBBox(drawable, text, x, y, NULL, NULL);
}
-void TextStyle::drawText2(Drawable drawable, const char *text,
- int x, int y, int* ww, int* hh)
+void TextStyle::drawTextBBox(Drawable drawable, const char *text,
+ int x, int y, int* ww, int* hh)
{
TextStyleOptions* ops = (TextStyleOptions*)ops_;
@@ -128,20 +109,23 @@ void TextStyle::drawText2(Drawable drawable, const char *text,
Tk_DrawTextLayout(graphPtr_->display_, drawable, gc_, layout,
(int)rr.x, (int)rr.y, 0, -1);
#endif
-
- double angle = fmod(ops->angle, 360.0);
- if (angle < 0.0)
- angle += 360.0;
-
- if (angle != 0.0) {
- double rotWidth, rotHeight;
- graphPtr_->getBoundingBox(w1, h1, angle, &rotWidth, &rotHeight, NULL);
- w1 = (int)rotWidth;
- h1 = (int)rotHeight;
+ Tk_FreeTextLayout(layout);
+
+ if (ww && hh) {
+ double angle = fmod(ops->angle, 360.0);
+ if (angle < 0.0)
+ angle += 360.0;
+
+ if (angle != 0.0) {
+ double rotWidth, rotHeight;
+ graphPtr_->getBoundingBox(w1, h1, angle, &rotWidth, &rotHeight, NULL);
+ w1 = (int)rotWidth;
+ h1 = (int)rotHeight;
+ }
+
+ *ww = w1;
+ *hh = h1;
}
-
- *ww = w1;
- *hh = h1;
}
void TextStyle::printText(PSOutput* psPtr, const char *text, int x, int y)
diff --git a/generic/tkbltGrText.h b/generic/tkbltGrText.h
index 4337e81..4593b33 100644
--- a/generic/tkbltGrText.h
+++ b/generic/tkbltGrText.h
@@ -69,7 +69,7 @@ namespace Blt {
void* ops() {return ops_;}
void drawText(Drawable, const char*, int, int);
void drawText(Drawable, const char*, double, double);
- void drawText2(Drawable, const char*, int, int, int*, int*);
+ void drawTextBBox(Drawable, const char*, int, int, int*, int*);
void printText(PSOutput*, const char*, int, int);
void printText(PSOutput*, const char*, double, double);
void getExtents(const char*, int*, int*);