[Kst] [Bug 123036] Legends do not show up when printing to ps file.

George Staikos staikos at kde.org
Sun Mar 19 22:31:12 CET 2006


------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
         
http://bugs.kde.org/show_bug.cgi?id=123036         
staikos kde org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From staikos kde org  2006-03-19 22:31 -------
SVN commit 520414 by staikos:

Make printing look closer to correct for any lines drawn by various objects.
It's not nearly WYSIWYG, and there are some issues to discuss, but this is close
enough for now.
BUG: 123036


 M  +4 -14     libkstapp/kst2dplot.cpp  
 M  +18 -6     libkstapp/kstborderedviewobject.cpp  
 M  +2 -0      libkstapp/kstborderedviewobject.h  
 M  +1 -1      libkstapp/kstviewarrow.cpp  
 M  +7 -6      libkstapp/kstviewbox.cpp  
 M  +4 -2      libkstapp/kstviewellipse.cpp  
 M  +1 -1      libkstapp/kstviewlabel.cpp  
 M  +1 -1      libkstapp/kstviewlegend.cpp  
 M  +3 -3      libkstapp/kstviewline.cpp  
 M  +1 -1      libkstapp/kstviewpicture.cpp  
 M  +7 -0      libkstmath/kstpainter.cpp  
 M  +2 -0      libkstmath/kstpainter.h  


--- trunk/extragear/graphics/kst/src/libkstapp/kst2dplot.cpp #520413:520414
 @ -2354,12 +2354,7  @
 
   p.fillRect(0, 0, winRect.width(), winRect.height(), _backgroundColor);
 
-  int basePenWidth = (x_px+y_px) / 1999;
-  if (basePenWidth == 0) {
-    basePenWidth = 1;
-  }
-
-  int penWidth = axisPenWidth()*basePenWidth;
+  int penWidth = axisPenWidth() * p.lineWidthAdjustmentFactor();
   p.setPen(QPen(_foregroundColor, penWidth));
 
   set2dPlotTickPix(xtick_len_px, ytick_len_px, x_px, y_px);
 @ -2460,7 +2455,7  @
     context.YMax = YMax;
     context._xLog = _xLog;
     context._yLog = _yLog;
-    context.penWidth = basePenWidth;
+    context.penWidth = p.lineWidthAdjustmentFactor();
     context._foregroundColor = _foregroundColor;
     context._backgroundColor = _backgroundColor;
 
 @ -5770,14 +5765,9  @
   double X2, Y2;
   int i, j;
 
-  int basePenWidth = (x_px+y_px) / 1999;
-  if (basePenWidth == 0) {
-    basePenWidth = 1;
-  }
+  int minor_width = p.lineWidthAdjustmentFactor() * minorPenWidth(); 
+  int major_width = p.lineWidthAdjustmentFactor() * majorPenWidth(); 
 
-  int minor_width = basePenWidth * minorPenWidth(); 
-  int major_width = basePenWidth * majorPenWidth(); 
-
   // draw X grid lines
   if (_xLog) {
     i = (int)floor( (double)_xMinorTicks * ( xleft_bdr_px - 1.0 - x_orig_px ) / xtick_px );
--- trunk/extragear/graphics/kst/src/libkstapp/kstborderedviewobject.cpp #520413:520414
 @ -95,13 +95,14  @
   }
   if (_borderWidth > 0) {
     QRect r;
-    QPen pen(_borderColor, _borderWidth);
+    const int bw(_borderWidth * p.lineWidthAdjustmentFactor());
+    QPen pen(_borderColor, bw);
     p.setBrush(Qt::NoBrush);
     p.setPen(pen);
-    r.setX(_geom.left() + _margin + _borderWidth / 2);
-    r.setY(_geom.top() + _margin + _borderWidth / 2);
-    r.setWidth(_geom.width() - 2 * _margin - _borderWidth + 1);
-    r.setHeight(_geom.height() - 2 * _margin - _borderWidth + 1);
+    r.setX(_geom.left() + _margin + bw / 2);
+    r.setY(_geom.top() + _margin + bw / 2);
+    r.setWidth(_geom.width() - 2 * _margin - bw + 1);
+    r.setHeight(_geom.height() - 2 * _margin - bw + 1);
     p.drawRect(r);
   }
   p.restore();
 @ -163,9 +164,20  @
 }
 
 
+QRect KstBorderedViewObject::contentsRectForDevice(const KstPainter& painter) const {
+  QRect rc;
+  const int mpb = (_margin + _padding + _borderWidth) * painter.lineWidthAdjustmentFactor();;
+  rc.setX(_geom.left() + mpb);
+  rc.setY(_geom.top() + mpb);
+  rc.setWidth(_geom.width() - 2 * mpb);
+  rc.setHeight(_geom.height() - 2 * mpb);
+  return rc;
+}
+
+
 QRect KstBorderedViewObject::contentsRect() const {
   QRect rc;
-  int mpb = _margin + _padding + _borderWidth;
+  const int mpb = _margin + _padding + _borderWidth;
   rc.setX(_geom.left() + mpb);
   rc.setY(_geom.top() + mpb);
   rc.setWidth(_geom.width() - 2 * mpb);
--- trunk/extragear/graphics/kst/src/libkstapp/kstborderedviewobject.h #520413:520414
 @ -102,6 +102,8  @
 
     virtual void paintSelf(KstPainter& p, const QRegion& bounds);
 
+    QRect contentsRectForDevice(const KstPainter& painter) const;
+
   protected:
     virtual void readBinary(QDataStream& str);
     virtual void writeBinary(QDataStream& str);
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewarrow.cpp #520413:520414
 @ -133,7 +133,7  @
   if (hasArrow()) {
     QPoint to = KstViewLine::to();
     QPoint from = KstViewLine::from();    
-    int w = width();
+    const int w = width() * p.lineWidthAdjustmentFactor();
     QPen pen(_foregroundColor, w);
     
     pen.setCapStyle(capStyle());
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewbox.cpp #520413:520414
 @ -80,9 +80,10  @
     }
   }
 
-  QPen pen(borderColor(), borderWidth());
+  const int bw(borderWidth() * p.lineWidthAdjustmentFactor());
+  QPen pen(borderColor(), bw);
   pen.setJoinStyle(_cornerStyle);
-  if (borderWidth() == 0) {
+  if (bw == 0) {
     pen.setStyle(Qt::NoPen);
   }
   p.setPen(pen);
 @ -92,10 +93,10  @
     p.setBrush(_foregroundColor);
   }
   QRect r;
-  r.setX(_geom.left() + borderWidth()/2);
-  r.setY(_geom.top() + borderWidth()/2);
-  r.setWidth(_geom.width() - borderWidth());
-  r.setHeight(_geom.height() - borderWidth());
+  r.setX(_geom.left() + bw / 2);
+  r.setY(_geom.top() + bw / 2);
+  r.setWidth(_geom.width() - bw);
+  r.setHeight(_geom.height() - bw);
 
   p.drawRoundRect(r, _xRound, _yRound);
   p.restore();
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewellipse.cpp #520413:520414
 @ -71,14 +71,16  @
     }
   }
 
-  QPen pen(_borderColor, _borderWidth);
+  const int bw(_borderWidth * p.lineWidthAdjustmentFactor());
+  QPen pen(_borderColor, bw);
   p.setPen(pen);
   if (_transparentFill) {
     p.setBrush(Qt::NoBrush);  
   } else {
     p.setBrush(_foregroundColor);
   }
-  p.drawEllipse(geometry().x() + _borderWidth/2, geometry().y() + _borderWidth/2, geometry().width() - _borderWidth, geometry().height() - _borderWidth);
+  const QRect g(geometry());
+  p.drawEllipse(g.x() + bw/2, g.y() + bw/2, g.width() - bw, g.height() - bw);
   p.restore();
 }
 
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewlabel.cpp #520413:520414
 @ -385,7 +385,7  @
       computeTextSize(_parsed);
     }
     KstBorderedViewObject::paintSelf(p, bounds);
-    const QRect geom(contentsRect());
+    const QRect geom(contentsRectForDevice(p));
     p.setViewport(geom);
     p.setWindow(0, 0, geom.width(), geom.height());
 
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewlegend.cpp #520413:520414
 @ -318,7 +318,7  @
     p.save();
     adjustSizeForText(_parent->geometry());
     KstBorderedViewObject::paintSelf(p, bounds);
-    const QRect cr(contentsRect());
+    const QRect cr(contentsRectForDevice(p));
     p.setViewport(cr);
     p.setWindow(0, 0, cr.width(), cr.height());
     if (!_transparent) {
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewline.cpp #520413:520414
 @ -98,7 +98,8  @
   }
 
   // figure out which direction to draw the line
-  QPen pen(_foregroundColor, _width);
+  const int w(_width * p.lineWidthAdjustmentFactor());
+  QPen pen(_foregroundColor, w);
   pen.setCapStyle(_capStyle);
   pen.setStyle(_penStyle);
   p.setPen(pen);
 @ -108,9 +109,8  @
   
   // Adjust for large widths.  We don't want the line clipped because it goes
   // out of the bounding box.
-  if (_width > 1 && geom.height() > 0) {
+  if (w > 1 && geom.height() > 0) {
     double theta = atan(geom.width()/geom.height());
-    int w = _width;
     if (theta >= 0 && theta <= M_PI/4) {
       u = int(fabs((w / 2.0) * (sin(theta) + cos(theta))));
       v = int(fabs((w / 2.0) * (1.5*sin(theta) + 0.5*cos(theta))));
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewpicture.cpp #520413:520414
 @ -113,7 +113,7  @
     KstBorderedViewObject::paintSelf(p, bounds);
   }
 
-  const QRect cr(contentsRect());
+  const QRect cr(contentsRectForDevice(p));
   if (_image.isNull()) {
     // fill with X
     p.setBrush(QBrush(Qt::gray, Qt::SolidPattern));
--- trunk/extragear/graphics/kst/src/libkstmath/kstpainter.cpp #520413:520414
 @ -56,4 +56,11  @
 }
 
 
+int KstPainter::lineWidthAdjustmentFactor() const {
+  const QRect& w(window());
+  // Magic number!  What does it mean?
+  const int factor = (w.width() + w.height()) / 1999;
+  return factor > 0 ? factor : 1;
+}
+
 // vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/src/libkstmath/kstpainter.h #520413:520414
 @ -48,6 +48,8  @
     bool makingMask() const;
     void setMakingMask(bool making);
 
+    int lineWidthAdjustmentFactor() const;
+
   private:
     PaintType _type;
     bool _drawInlineUI;


More information about the Kst mailing list