[Kst] extragear/graphics/kst/kst
George Staikos
staikos at kde.org
Fri Jun 17 01:46:11 CEST 2005
SVN commit 426315 by staikos:
Rotation 0->90 works including size adjustments.
M +6 -0 extensions/js/examples/testlabels.js
M +41 -9 kstviewlabel.cpp
--- trunk/extragear/graphics/kst/kst/extensions/js/examples/testlabels.js #426314:426315
@@ -38,5 +38,11 @@
lg.justification = 3 << 8;
lg.fontSize = 38;
+lh = new Label(w);
+lh.text = "\\Sigma^{(x+5)^2}_{5+1} + \\Pi^{\\Sigma^{i-j}_{i+j}}_{x = 0} + 5";
+lh.position = new Point(400, 394);
+lh.fontSize = 32;
+lh.rotation = 45;
+
--- trunk/extragear/graphics/kst/kst/kstviewlabel.cpp #426314:426315
@@ -333,7 +333,7 @@
pen.setColor(foregroundColor());
p.setPen(pen);
p.rotate(_rotation);
- //double rotationRadians = 3.1415926535897932333796 * _rotation / 180.0;
+ double rotationRadians = M_PI * (int(_rotation) % 360) / 180;
int hJust = KST_JUSTIFY_H(_justify);
if (QApplication::reverseLayout()) {
@@ -346,7 +346,13 @@
}
}
+ int descent = _textHeight - 1 - _ascent;
+
+ double up = _textHeight * sin(rotationRadians) * sin(rotationRadians);
+ double in = _textHeight * sin(2 * rotationRadians) / 2;
+
RenderContext rc(_fontName, _symbolFontName, _fontSize, &p);
+
switch (hJust) {
case KST_JUSTIFY_H_RIGHT:
rc.x = size().width() - _textWidth;
@@ -358,11 +364,10 @@
abort(); // should never be able to happen
case KST_JUSTIFY_H_LEFT:
default:
- rc.x = 0;
+ rc.x = in;
break;
}
- int descent = _textHeight - 1 - _ascent;
switch (KST_JUSTIFY_V(_justify)) {
case KST_JUSTIFY_V_BOTTOM:
rc.y = size().height() - descent;
@@ -373,7 +378,7 @@
case KST_JUSTIFY_V_NONE:
case KST_JUSTIFY_V_TOP:
default:
- rc.y = _textHeight - descent;
+ rc.y = _ascent - up;
break;
}
@@ -417,12 +422,39 @@
computeTextSize(_parsed); // FIXME this is inefficient
}
- QSize sz(_textWidth, _textHeight);
- if (_parent) {
- QRect r(position(), sz);
- resize(r.intersect(_parent->geometry()).size());
+ if (_rotation != 0 && _rotation != 180) {
+ QPointArray pts(4);
+ pts[0] = QPoint(0, 0);
+ pts[1] = QPoint(0, _textHeight);
+ pts[2] = QPoint(_textWidth, 0);
+ pts[3] = QPoint(_textWidth, _textHeight);
+ double theta = M_PI * (int(_rotation) % 360) / 180;
+ double sina = sin(theta);
+ double cosa = cos(theta);
+ QWMatrix m(cosa, sina, -sina, cosa, 0, 0);
+
+ QPoint to;
+ // FIXME: for different justify types
+ to.setX(_textWidth / 2);
+ to.setY(_textHeight / 2);
+ pts.translate(-to.x(), -to.y());
+ pts = m.map(pts);
+ pts.translate(to.x(), to.y());
+
+ if (_parent) {
+ QRect r(position(), pts.boundingRect().size());
+ resize(r.intersect(_parent->geometry()).size());
+ } else {
+ resize(pts.boundingRect().size());
+ }
} else {
- resize(sz);
+ QSize sz(_textWidth, _textHeight);
+ if (_parent) {
+ QRect r(position(), sz);
+ resize(r.intersect(_parent->geometry()).size());
+ } else {
+ resize(sz);
+ }
}
}
More information about the Kst
mailing list