Bug 129399 - Legends and labels do not print properly
Summary: Legends and labels do not print properly
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: unspecified Linux
: HI normal
Target Milestone: ---
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-19 03:48 UTC by Netterfield
Modified: 2007-01-05 23:37 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
kst file to demonstrate the problem: (18.58 KB, application/x-kst)
2006-06-19 03:49 UTC, Netterfield
Details
pdf from printing (23.92 KB, application/pdf)
2006-06-19 03:51 UTC, Netterfield
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Netterfield 2006-06-19 03:48:48 UTC
Version:           1.3.0_devel (using KDE 3.5.3, Kubuntu Package 4:3.5.3-0ubuntu0.1 dapper)
Compiler:          Target: i486-linux-gnu
OS:                Linux (i686) release 2.6.15-25-386

Create a window with multiple plots.
Create a legend (border =2, margin = 5) in one (or more) of the plots.  
Print the window.

The legend contents are shifted to the bottom right.
Comment 1 Netterfield 2006-06-19 03:49:50 UTC
Created attachment 16691 [details]
kst file to demonstrate the problem:
Comment 2 Netterfield 2006-06-19 03:51:28 UTC
Created attachment 16692 [details]
pdf from printing

Notice that the legend contents is shifted to the bottom right corner of the
legend box in the printout (but not when viewed in kst)
Comment 3 Andrew Walker 2006-06-20 19:50:28 UTC
It is not so much that the contents have been shifted to the bottom right, more that the font size relative to the legend box size is (slightly) larger when printing than when painting on the display.
Comment 4 Andrew Walker 2006-06-21 21:27:07 UTC
The same effect can also be seen with ordinary labels.
Comment 5 George Staikos 2006-09-18 05:54:05 UTC
At least one problem here is that we use _parent->geometry() instead of 
_parent->contentsRect() in the printing path.  We can't use contentsRect(), 
however, because it's invalid.  It could also be the case that the legend 
margin and/or the font size need to be adjusted.
Comment 6 Andrew Walker 2007-01-05 23:37:37 UTC
SVN commit 620401 by arwalker:

BUG:129399 Correctly handle the printing of legends and labels. This wasn't working properly as the lineWidthAdjustmentFactor() for the border wasn't taken into account when printing.

 M  +9 -0      kstborderedviewobject.cpp  
 M  +2 -1      kstborderedviewobject.h  
 M  +21 -14    kstviewlabel.cpp  
 M  +1 -0      kstviewlabel.h  
 M  +16 -6     kstviewlegend.cpp  
 M  +1 -0      kstviewlegend.h  


--- trunk/extragear/graphics/kst/src/libkstapp/kstborderedviewobject.cpp #620400:620401
@@ -186,6 +186,15 @@
 }
 
 
+void KstBorderedViewObject::setContentsRectForDevice(const KstPainter& painter, QRect& rect) {
+  const int mpb = (_margin + _padding + _borderWidth) * painter.lineWidthAdjustmentFactor();
+  _geom.setX(rect.left() - mpb);
+  _geom.setY(rect.top() - mpb);
+  _geom.setWidth(rect.width() + 2 * mpb);
+  _geom.setHeight(rect.height() + 2 * mpb);
+}
+
+
 void KstBorderedViewObject::setContentsRect(QRect& rect) {
   const int mpb = _margin + _padding + _borderWidth;
   _geom.setX(rect.left() - mpb);
--- trunk/extragear/graphics/kst/src/libkstapp/kstborderedviewobject.h #620400:620401
@@ -104,7 +104,8 @@
     virtual void paintSelf(KstPainter& p, const QRegion& bounds);
 
     QRect contentsRectForDevice(const KstPainter& painter) const;
-
+    virtual void setContentsRectForDevice(const KstPainter& painter, QRect& rect);
+  
   protected:
     virtual void readBinary(QDataStream& str);
     virtual void writeBinary(QDataStream& str);
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewlabel.cpp #620400:620401
@@ -382,16 +382,15 @@
   if (p.type() == KstPainter::P_PRINT || p.type() == KstPainter::P_EXPORT) {
     int absFontSizeOld = _absFontSize;
     
-    adjustSizeForText(_parent->geometry());
+    QRect cr(contentsRectForDevice(p));
+    cr.setSize(sizeForText(_parent->geometry()));
+    setContentsRectForDevice(p, cr);    
     KstBorderedViewObject::paintSelf(p, bounds);
-    const QRect geom(contentsRectForDevice(p));
-    p.setViewport(geom);
-    p.setWindow(0, 0, geom.width(), geom.height());
-
+    
+    p.translate(cr.left(), cr.top());
     if (!_transparent) {
-      p.fillRect(0, 0, geom.width(), geom.height(), backgroundColor());
+      p.fillRect(0, 0, cr.width(), cr.height(), backgroundColor());
     }
-
     drawToPainter(_parsed, p);
     
     _absFontSize = absFontSizeOld;
@@ -463,6 +462,13 @@
 
 
 void KstViewLabel::adjustSizeForText(QRect w) {
+  QRect cr(contentsRect());
+  cr.setSize(sizeForText(w));
+  setContentsRect(cr);
+}
+
+
+QSize KstViewLabel::sizeForText(QRect w) {
   double x_s, y_s;
   
   x_s = y_s = _fontSize + (double)KstSettings::globalSettings()->plotFontSize;
@@ -492,12 +498,13 @@
   }
  
   QSize sz(kMax(1, _textWidth), kMax(1, _textHeight));
+
   if (int(_rotation) != 0 && int(_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);
+    pts[2] = QPoint(_textWidth, _textHeight);
+    pts[3] = QPoint(_textWidth, 0);
     double theta = M_PI * (int(_rotation) % 360) / 180;
     double sina = sin(theta);
     double cosa = cos(theta);
@@ -507,26 +514,26 @@
 
     if (_parent) {
       QRect r(position(), pts.boundingRect().size());
+      r.setSize(r.size() + QSize(2 * _labelMargin * _ascent / 10, 2 * _labelMargin * _ascent / 10));
       sz = r.intersect(_parent->geometry()).size();
     } else {
       sz = pts.boundingRect().size();
+      sz += QSize(2 * _labelMargin * _ascent / 10, 2 * _labelMargin * _ascent / 10);
     }
   } else {
     if (_parent) {
       QRect r(position(), sz);
+      r.setSize(r.size() + QSize(2 * _labelMargin * _ascent / 10, 2 * _labelMargin * _ascent / 10));
       sz = r.intersect(_parent->geometry()).size();
     }
   }
-
-  QRect cr(contentsRect());
-  cr.setSize(sz + QSize(2 * _labelMargin * _ascent / 10, 2 * _labelMargin * _ascent / 10));
-  setContentsRect(cr);
+    
+  return sz;
 }
 
 
 bool KstViewLabel::layoutPopupMenu(KPopupMenu *menu, const QPoint& pos, KstViewObjectPtr topLevelParent) {
   KstViewObject::layoutPopupMenu(menu, pos, topLevelParent);
-  //menu->insertItem(i18n("&Adjust Size"), this, SLOT(adjustSizeForText()));
   return true;
 }
 
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewlabel.h #620400:620401
@@ -102,6 +102,7 @@
 
   public slots:
     void adjustSizeForText(QRect w);
+    QSize sizeForText(QRect w);
     void reparse();
 
   protected:
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewlegend.cpp #620400:620401
@@ -363,14 +363,17 @@
 void KstViewLegend::paintSelf(KstPainter& p, const QRegion& bounds) {
   if (p.type() == KstPainter::P_PRINT || p.type() == KstPainter::P_EXPORT) {
     p.save();
-    adjustSizeForText(_parent->geometry());
+    QRect cr(contentsRectForDevice(p));
+    cr.setSize(sizeForText(_parent->geometry()));
+    setContentsRectForDevice(p, cr);    
     KstBorderedViewObject::paintSelf(p, bounds);
-    const QRect cr(contentsRectForDevice(p));
+    
     p.translate(cr.left(), cr.top());
     if (!_transparent) {
       p.fillRect(0, 0, cr.width(), cr.height(), _backgroundColor);
     }
     drawToPainter(p);
+    
     p.restore();
   } else {
     const QRect cr(contentsRect());
@@ -440,6 +443,13 @@
 
 
 void KstViewLegend::adjustSizeForText(QRect w) {
+  QRect cr(contentsRect());
+  cr.setSize(sizeForText(w));
+  setContentsRect(cr);
+}
+
+
+QSize KstViewLegend::sizeForText(QRect w) {
   double x_s, y_s;
 
   x_s = y_s = _fontSize + (double)KstSettings::globalSettings()->plotFontSize;
@@ -480,15 +490,15 @@
   }
 
   QSize sz(width, height);
+  
+  sz += QSize(2 * _legendMargin * _ascent / 10, 2 * _legendMargin * _ascent / 10);
 
   if (_parent) {
     QRect r(position(), sz);
     sz = r.intersect(_parent->geometry()).size();
   }
-
-  QRect cr(contentsRect());
-  cr.setSize(sz + QSize(2 * _legendMargin * _ascent / 10, 2 * _legendMargin * _ascent / 10));
-  setContentsRect(cr);
+    
+  return sz;
 }
 
 void KstViewLegend::modifiedLegendEntry() {
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewlegend.h #620400:620401
@@ -101,6 +101,7 @@
 
   public slots:
     void adjustSizeForText(QRect w);
+    QSize sizeForText(QRect w);
     void modifiedLegendEntry(void);
 
   protected: