[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-edu-devel
Subject:    [kde-edu]: Re: Kig exporters: support linewidth in asymptote
From:       Raoul <raoulb () bluewin ! ch>
Date:       2011-04-25 13:01:21
Message-ID: 20110425150121.77f8a3d5 () pega ! pega
[Download RAW message or body]

Hi Maurizio,


> > Further I enabled the export of cubics and used the generic curve
> > sampling function for that. In principle it works but we get
> > strange artefacts at the points where there is a vertical tangent
> > for some branch of the curve. (I hope that I can fix that with a
> > new curve sampling algorithm, but this will take some time.)
> 
> The problem with cubics is more general, and it lies in the somewhat
> crude way a cubic is parametrized;  I am responsible for that :-)

Hmm, ok. I hoped the problem would be not that severe because the
cubics are drawn correctly on screen.

> There is a persone here in Brescia that perhaps could look into
> the problem, in search of a manner to parametrize a cubic in a more
> smooth way.
> As soon as I get the name an email of this person I will make you
> in contact...

Ok, thanks. Let's see what we can do about this issue.

> I commited your last patch.  Could you check if everything is
> allright?

Thanks for commiting. The only problem I found is related to
my own coding faults when dealing with default linewidts.
The current version gives to thick lines by default.

So I attach you a new small patch with more correct defaults.

Do you think we nee more tunig of the linewidth parameters?
The values seem to be reasonable except maybe the thickest ones.

Btw: we do not have different styles for dots. Should we support
that or just stick to the round dots?

> I noted a few stilistic modifications also.  It would be best to
> separate stilistic commits from real code modification.  I did not
> do that myself in this case, because most modifications were mixed
> together.

Ah, these were some small corrections done when I came along the
code anyway. I hope this does not introduce major problems.


-- Raoul
[Attachment #3 (text/x-patch)]

diff --git a/filters/asyexporterimpvisitor.cc b/filters/asyexporterimpvisitor.cc
index 06a8bbf..9d8f187 100644
--- a/filters/asyexporterimpvisitor.cc
+++ b/filters/asyexporterimpvisitor.cc
@@ -70,6 +70,9 @@ QString AsyExporterImpVisitor::emitPenStyle( const Qt::PenStyle& \
style )  
 QString AsyExporterImpVisitor::emitPenSize( const int width )
 {
+  // In this function we map the logical (integer) linewidth of Kig
+  // to real line widths that can be used in Asymptote.
+  // Default mapping is currently: asy_width = kig_width / 2.0
   QString pensize("");
   if ( width < 0 )
   {
@@ -79,7 +82,7 @@ QString AsyExporterImpVisitor::emitPenSize( const int width )
   else
   {
     // Asymptote definition of pen size
-    pensize = "linewidth(" + QString::number(width) + ")";
+    pensize = "linewidth(" + QString::number(width/2.0) + ")";
   }
   return  pensize;
 }
@@ -225,10 +228,8 @@ void AsyExporterImpVisitor::plotGenericCurve( const CurveImp* \
imp )  linelength = 0;
       }
     }
-    int width = mcurobj->drawer()->width();
-    if ( width == -1 ) width = 1;
     mstream << "draw(curve, "
-            << emitPen( mcurobj->drawer()->color(), width, \
mcurobj->drawer()->style() ) +            << emitPen( mcurobj->drawer()->color(), \
mcurobj->drawer()->width(), mcurobj->drawer()->style() )  << " );";
     newLine();
   }
@@ -240,9 +241,7 @@ void AsyExporterImpVisitor::visit( const LineImp* imp )
   Coordinate a = imp->data().a;
   Coordinate b = imp->data().b;
   calcBorderPoints( a, b, msr );
-  int width = mcurobj->drawer()->width();
-  if ( width == -1 ) width = 1;
-  emitLine( a, b, width, mcurobj->drawer()->style() );
+  emitLine( a, b, mcurobj->drawer()->width(), mcurobj->drawer()->style() );
 }
 
 
@@ -252,8 +251,10 @@ void AsyExporterImpVisitor::visit( const PointImp* imp )
           << emitCoord( imp->coordinate() )
           << ";";
   newLine();
+  // The factor of 6 is necessary to get the asymptote default dot size
+  // which is 6*asy_default_linewidth where asy_default_linewidth = 0.5
   int width = mcurobj->drawer()->width();
-  if ( width == -1 ) width = 3;
+  if ( width == -1 ) width = 6;
   mstream << "dot(point, "
           << emitPen( mcurobj->drawer()->color(), width, mcurobj->drawer()->style() \
)  << ");";
@@ -307,10 +308,8 @@ void AsyExporterImpVisitor::visit( const AngleImp* imp )
           << endangle
           << " );";
   newLine();
-  int width = mcurobj->drawer()->width();
-  if ( width == -1 ) width = 1;
   mstream << "draw(a, "
-          << emitPen( mcurobj->drawer()->color(), width, mcurobj->drawer()->style() \
) +          << emitPen( mcurobj->drawer()->color(), mcurobj->drawer()->width(), \
mcurobj->drawer()->style() )  << ", Arrow );";
   newLine();
 }
@@ -320,9 +319,7 @@ void AsyExporterImpVisitor::visit( const VectorImp* imp )
 {
   Coordinate a = imp->data().a;
   Coordinate b = imp->data().b;
-  int width = mcurobj->drawer()->width();
-  if ( width == -1 ) width = 1;
-  emitLine( a, b, width, mcurobj->drawer()->style(), true );
+  emitLine( a, b, mcurobj->drawer()->width(), mcurobj->drawer()->style(), true );
 }
 
 
@@ -343,10 +340,8 @@ void AsyExporterImpVisitor::visit( const CircleImp* imp )
   newLine();
   mstream << "path circle = Circle(center, radius);";
   newLine();
-  int width = mcurobj->drawer()->width();
-  if ( width == -1 ) width = 1;
   mstream << "draw(circle, "
-          << emitPen( mcurobj->drawer()->color(), width, mcurobj->drawer()->style() \
) +          << emitPen( mcurobj->drawer()->color(), mcurobj->drawer()->width(), \
mcurobj->drawer()->style() )  << " );";
   newLine();
 }
@@ -369,10 +364,7 @@ void AsyExporterImpVisitor::visit( const SegmentImp* imp )
 {
   Coordinate a = imp->data().a;
   Coordinate b = imp->data().b;
-
-  int width = mcurobj->drawer()->width();
-  if ( width == -1 ) width = 1;
-  emitLine( a, b, width, mcurobj->drawer()->style() );
+  emitLine( a, b, mcurobj->drawer()->width(), mcurobj->drawer()->style() );
 }
 
 
@@ -381,10 +373,7 @@ void AsyExporterImpVisitor::visit( const RayImp* imp )
   Coordinate a = imp->data().a;
   Coordinate b = imp->data().b;
   calcRayBorderPoints( a, b, msr );
-
-  int width = mcurobj->drawer()->width();
-  if ( width == -1 ) width = 1;
-  emitLine( a, b, width, mcurobj->drawer()->style() );
+  emitLine( a, b, mcurobj->drawer()->width(), mcurobj->drawer()->style() );
 }
 
 
@@ -408,10 +397,8 @@ void AsyExporterImpVisitor::visit( const ArcImp* imp )
           << endangle
           << " );";
   newLine();
-  int width = mcurobj->drawer()->width();
-  if ( width == -1 ) width = 1;
   mstream << "draw(arc, "
-          << emitPen( mcurobj->drawer()->color(), width, mcurobj->drawer()->style() \
) +          << emitPen( mcurobj->drawer()->color(), mcurobj->drawer()->width(), \
mcurobj->drawer()->style() )  << " );";
   newLine();
 }
@@ -444,10 +431,8 @@ void AsyExporterImpVisitor::visit( const FilledPolygonImp* imp )
           << emitPenColor( mcurobj->drawer()->color() )
           << "+opacity(0.5) );";
   newLine();
-  int width = mcurobj->drawer()->width();
-  if ( width == -1 ) width = 1;
   mstream << "draw(polygon, "
-          << emitPen( mcurobj->drawer()->color(), width, mcurobj->drawer()->style() \
) +          << emitPen( mcurobj->drawer()->color(), mcurobj->drawer()->width(), \
mcurobj->drawer()->style() )  << " );";
   newLine();
 }
@@ -476,10 +461,8 @@ void AsyExporterImpVisitor::visit(const ClosedPolygonalImp* imp)
   }
   mstream << "cycle;";
   newLine();
-  int width = mcurobj->drawer()->width();
-  if ( width == -1 ) width = 1;
   mstream << "draw(polygon, "
-          << emitPen( mcurobj->drawer()->color(), width, mcurobj->drawer()->style() \
) +          << emitPen( mcurobj->drawer()->color(), mcurobj->drawer()->width(), \
mcurobj->drawer()->style() )  << " );";
   newLine();
 }
@@ -516,10 +499,8 @@ void AsyExporterImpVisitor::visit(const OpenPolygonalImp* imp)
     }
   }
   newLine();
-  int width = mcurobj->drawer()->width();
-  if ( width == -1 ) width = 1;
   mstream << "draw(polygon, "
-          << emitPen( mcurobj->drawer()->color(), width, mcurobj->drawer()->style() \
) +          << emitPen( mcurobj->drawer()->color(), mcurobj->drawer()->width(), \
mcurobj->drawer()->style() )  << " );";
   newLine();
 }
@@ -527,8 +508,6 @@ void AsyExporterImpVisitor::visit(const OpenPolygonalImp* imp)
 
 void AsyExporterImpVisitor::visit ( const BezierImp* imp )
 {
-  int width = mcurobj->drawer()->width();
-  if ( width == -1 ) width = 1;
   std::vector<Coordinate> pts = imp->points();
   switch ( pts.size() )
   {
@@ -547,7 +526,7 @@ void AsyExporterImpVisitor::visit ( const BezierImp* imp )
     mstream << ";";
     newLine();
     mstream << "draw(bezier, "
-            << emitPen( mcurobj->drawer()->color(), width, \
mcurobj->drawer()->style() ) +            << emitPen( mcurobj->drawer()->color(), \
mcurobj->drawer()->width(), mcurobj->drawer()->style() )  << " );";
     newLine();
     break;
@@ -563,7 +542,7 @@ void AsyExporterImpVisitor::visit ( const BezierImp* imp )
     mstream << ";";
     newLine();
     mstream << "draw(bezier, "
-            << emitPen( mcurobj->drawer()->color(), width, \
mcurobj->drawer()->style() ) +            << emitPen( mcurobj->drawer()->color(), \
mcurobj->drawer()->width(), mcurobj->drawer()->style() )  << " );";
     newLine();
     break;


[Attachment #4 (application/x-gzip)]

_______________________________________________
kde-edu mailing list
kde-edu@mail.kde.org
https://mail.kde.org/mailman/listinfo/kde-edu


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic