Bug 128278

Summary: Symbol scaling is wrong when printing
Product: [Applications] kst Reporter: Nicolas Brisset <nicolas.brisset>
Component: generalAssignee: kst
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 1.x   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Proposed patch

Description Nicolas Brisset 2006-05-29 22:51:38 UTC
Version:           1.3.0_devel (using KDE 3.4.2, Mandrake Linux Cooker i586 - Cooker)
Compiler:          Target: i586-mandriva-linux-gnu
OS:                Linux (i686) release 2.6.12-12mdk

I'm trying to check printing, and here is the first problem I have found. To reproduce:
1) load column 1 vs INDEX from the tutorial data gyrodata.dat
2) set "Show points" on
3) make it show the legend in case it is not there by default
4) print to a postscript file (say test.ps)
5) open test.ps and look at the legend: the symbol can barely be seen

The expected result is a visible symbol, as in the kst window
Comment 1 Nicolas Brisset 2006-05-29 23:05:31 UTC
By the way, setting the curve width larger also affects symbol size, and they quickly become visible (weight = 3 looks quite OK).
Comment 2 Andrew Walker 2006-05-31 22:56:28 UTC
Created attachment 16386 [details]
Proposed patch

Correctly handles zero-width lines.
Better scales for printing.
Comment 3 Andrew Walker 2006-06-01 18:00:41 UTC
SVN commit 547292 by arwalker:

BUG:128278 Better scale symbols when printing.

 M  +8 -4      kstpainter.cpp  
 M  +21 -10    kstvcurve.cpp  


--- trunk/extragear/graphics/kst/src/libkstmath/kstpainter.cpp #547291:547292
@@ -57,10 +57,14 @@
 
 
 int KstPainter::lineWidthAdjustmentFactor() const {
-  const QRect& w(window());
-  /* For square windows, the line width is in units of 0.1% of window size */
-  /* For printing to Letter or A10, line width is ~in points */
-  const int factor = (w.width() + w.height()) / 2000;
+  int factor = 1;
+  
+  if (type() == P_PRINT || type() == P_EXPORT) {
+    const QRect& w(window());
+    
+    factor = (w.width() + w.height()) / 800;
+  }
+  
   return factor > 0 ? factor : 1;
 }
 
--- trunk/extragear/graphics/kst/src/libkstmath/kstvcurve.cpp #547291:547292
@@ -871,8 +871,14 @@
   if (sampleCount() > 0) {
     Qt::PenStyle style = KstLineStyle[lineStyle()];
     int i0, iN;
-    int width = lineWidth() * penWidth; //kMax(lineWidth(), penWidth);
-
+    int width;
+    
+    if (lineWidth() == 0) {
+      width = penWidth;
+    } else {
+      width = lineWidth() * penWidth;
+    }
+    
     if (xv->isRising()) {
       i0 = indexNearX(XMin, xv, NS);
       if (i0 > 0) {
@@ -1323,7 +1329,6 @@
         QRegion rgn((int)Lx, (int)Ly, (int)w, (int)h);
         const int size = int(kMax(w, h)) / int(pow(3.0, KSTPOINTDENSITY_MAXTYPE - pointDensity()));
         QPoint pt;
-        const int lineWidth = width; //this->lineWidth();
         for (i_pt = i0; i_pt <= iN; ++i_pt) {
           rX = xv->interpolate(i_pt, NS);
           rY = yv->interpolate(i_pt, NS);
@@ -1337,12 +1342,11 @@
           pt.setX(d2i(m_X * rX + b_X));
           pt.setY(d2i(m_Y * rY + b_Y));
           if (rgn.contains(pt)) {
-            KstCurvePointSymbol::draw(pointType, p, pt.x(), pt.y(), lineWidth);
+            KstCurvePointSymbol::draw(pointType, p, pt.x(), pt.y(), width);
             rgn -= QRegion(pt.x()-(size/2), pt.y()-(size/2), size, size, QRegion::Ellipse);
           }
         }
       } else {
-        const int lineWidth = width; //this->lineWidth();
         for (i_pt = i0; i_pt <= iN; ++i_pt) {
           rX = xv->interpolate(i_pt, NS);
           rY = yv->interpolate(i_pt, NS);
@@ -1356,7 +1360,7 @@
           X1 = m_X * rX + b_X;
           Y1 = m_Y * rY + b_Y;
           if (X1 >= Lx && X1 <= Hx && Y1 >= Ly && Y1 <= Hy) {
-            KstCurvePointSymbol::draw(pointType, p, d2i(X1), d2i(Y1), lineWidth);
+            KstCurvePointSymbol::draw(pointType, p, d2i(X1), d2i(Y1), width);
           }
         }
       }
@@ -1640,9 +1644,10 @@
   }
 
   if (hasLines() && xv->isRising()) {
-  // if hasLines then we should find the distance between the curve and the point, not the data and the point. if isRising because it is (probably) to slow to use this technique if the data is unordered.
-    
-    // borrowed from indexNearX. use binary search to find the indices immediately above and below our xpos.
+    // if hasLines then we should find the distance between the curve and the point, not the data and 
+    //  the point. if isRising because it is (probably) to slow to use this technique if the data is 
+    //  unordered. borrowed from indexNearX. use binary search to find the indices immediately above 
+    //  and below our xpos.
     int i_top = NS - 1;
     int i_bot = 0;
 
@@ -1676,8 +1681,14 @@
 
 
 void KstVCurve::paintLegendSymbol(KstPainter *p, const QRect& bound) {
-  int width = lineWidth() * p->lineWidthAdjustmentFactor();
+  int width;
   
+  if (lineWidth() == 0) {
+    width = p->lineWidthAdjustmentFactor();
+  } else {  
+    width = lineWidth() * p->lineWidthAdjustmentFactor();
+  }
+  
   p->save();
   if (hasLines()) {
     // draw a line from left to right centered vertically