Bug 123036 - Legends do not show up when printing to ps file.
Summary: Legends do not show up when printing to ps file.
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: unspecified Linux
: VHI major
Target Milestone: ---
Assignee: George Staikos
URL:
Keywords:
: 123035 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-03-03 18:05 UTC by Carrie MacTavish
Modified: 2006-03-19 22:31 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
proposed fix against 1.3 (8.86 KB, patch)
2006-03-15 07:28 UTC, Netterfield
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Carrie MacTavish 2006-03-03 18:05:10 UTC
Version:           1.2.0 (using KDE 3.4.2 Level "b" , SUSE 10.0)
Compiler:          Target: i586-suse-linux
OS:                Linux (i686) release 2.6.13-15.8-default

legends do not appear when saving .ps file.  export to .eps file shows up in black and white, without legend.  can save as .png, labels appear, but legend box is messed up....could save without box as a work around, but fonts are a bit fuzzy and hard to read.
Comment 1 George Staikos 2006-03-03 20:42:56 UTC
*** Bug 123035 has been marked as a duplicate of this bug. ***
Comment 2 George Staikos 2006-03-03 20:43:43 UTC
1.2.1 will be prepared once this and all cases of 122927 are fixed.
Comment 3 Andrew Walker 2006-03-07 00:52:37 UTC
The problem here is with the combination of child view objects of 2dplot being tied to the PlotRegion and the resolution enhancement used when printing. In particular the following code in Kst2DPlot::draw(KstPainter& p, double resolutionEnhancement)

  } else {
    const QRect a(PlotRegion), b(WinRegion), c(PlotAndAxisRegion);
    setPixRect(RelPlotRegion, RelWinRegion, RelPlotAndAxisRegion);
    recursively(&KstViewObject::updateFromAspect); // alignment may have changed
    setPixRect(a, b, c);
  }

causes the child objects of Kst2DPlot to have their position set well outside of the plot, as the updateFromAspect(...) is called while the various 2dPlot regions are five times their real size, in order to achieve the resolution enhancement.

The solution would be to either get rid of the concept of resolution enhancement or call updateFromAspect(...) for all the children with the correct regions.
Comment 4 George Staikos 2006-03-07 03:12:41 UTC
  Yes this is one of several problems right now.  I have a number of them 
fixed but I don't want to commit until it's fully fixed because some of the 
changes might not be correct once the others are made.
Comment 5 George Staikos 2006-03-09 11:26:03 UTC
SVN commit 516941 by staikos:

This patch is really only partially done, but what's there works and I'm hitting
conflicts so it's time to commit.  this starts to fix the child object painting
(printing) problems.  There were a number of bugs, ranging from using the wrong
geometries, to the whole "resize, restore" sequence not fully completing.  This
cleans up some of them by using the proper parent geometry.  It also factors
resolution enhancement out to where it belongs: KstPainter.  Resolution
enhancement is not something that should be in Kst2DPlot.  it's something that
the caller should request in a painting sequence, and should be requested by the
caller.  -All- objects need to be aware of it, and the only sane way to do this
is make it a property of the painter.

Also some unnecessary draws and updates were removed.

With this, legend and label printing (along with other objects) can be properly
fixed.

CCBUG: 123036


 M  +2 -0      libkstapp/kst.cpp  
 M  +12 -19    libkstapp/kst2dplot.cpp  
 M  +3 -3      libkstapp/kst2dplot.h  
 M  +2 -2      libkstapp/kstviewlabel.cpp  
 M  +4 -7      libkstapp/kstviewlegend.cpp  
 M  +1 -1      libkstapp/kstviewobject.cpp  
 M  +2 -0      libkstapp/kstviewwindow.cpp  
 M  +11 -1     libkstmath/kstpainter.cpp  
 M  +4 -0      libkstmath/kstpainter.h  
Comment 6 Netterfield 2006-03-15 07:28:16 UTC
Created attachment 15130 [details]
proposed fix against 1.3
Comment 7 Netterfield 2006-03-15 07:31:38 UTC
I am attaching a patch which fixes this bug, but adds another (small, easy to fix) regression:

The fix:
  -completely get rid of "resolutionEnhancement"
  -Create the printers in HighResolution mode (they used to use screen resolution, which is why we had to introduce internal alignment).
  -internally specify the fonts in pixels rather than points.

The regression it introduces:
  -moving to high resolution mode means that line width N is much much narrower than it used to be on a printer.  I have fixed this for 1.3 for axis, grid lines and curves, but not for view objects (lines, boxes, etc).  The same sort of fix I added for the axis and curves needs to be applied to view objects.

The other bug it fixes:
  -line types now work on printers....

Unfortunately, this patch is only against svn.  Someone else needs to port it to 1.2 (I can't because I won't have any time for the next 2 weeks.)
Comment 8 Netterfield 2006-03-15 07:37:03 UTC
On Tuesday 14 March 2006 22:31, netterfield@astro.utoronto.ca wrote:
> ...
> resolution, which is why we had to introduce internal alignment).
> ....


Whoops: Should read 
"resolution, which is why we had to introduce resolution enhancement)."
Comment 9 George Staikos 2006-03-15 15:06:33 UTC
On Wednesday 15 March 2006 01:31, netterfield@astro.utoronto.ca wrote:

> The regression it introduces:
>   -moving to high resolution mode means that line width N is much much
> narrower than it used to be on a printer.  I have fixed this for 1.3 for
> axis, grid lines and curves, but not for view objects (lines, boxes, etc). 
> The same sort of fix I added for the axis and curves needs to be applied to
> view objects.
>
> Unfortunately, this patch is only against svn.  Someone else needs to port
> it to 1.2 (I can't because I won't have any time for the next 2 weeks.)


  I'll take care of all of that.
Comment 10 George Staikos 2006-03-15 20:13:40 UTC
On Wednesday 15 March 2006 13:48, Barth Netterfield wrote:
> OK to commit the patch?


  Reviewing (compiling) now after net went down and couldn't get at the 
patch...  I think it's ok based on reading it though.
Comment 11 George Staikos 2006-03-15 20:32:54 UTC
  Wow, this looks so much better in general.   I like it.
Comment 12 Netterfield 2006-03-16 01:53:55 UTC
SVN commit 519035 by netterfield:

fixes lable part of legend bug, but the borders are still too thin
CCBUG: 123036


 M  +2 -5      libkstapp/kst.cpp  
 M  +13 -20    libkstapp/kst2dplot.cpp  
 M  +1 -1      libkstapp/kstplotlabel.cpp  
 M  +2 -4      libkstapp/kstviewwindow.cpp  
 M  +19 -2     libkstapp/labelrenderer.h  
 M  +1 -10     libkstmath/kstpainter.cpp  
 M  +0 -4      libkstmath/kstpainter.h  
Comment 13 George Staikos 2006-03-19 22:31:09 UTC
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;