Author: clopes
Date: 2010-11-19 13:54:33 -0800 (Fri, 19 Nov 2010)
New Revision: 22943

Added:
   cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/cytoscape.png
Modified:
   
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/PDFExporter.as
   
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/SVGExporter.as
   cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/Images.as
   cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/LineStyles.as
   
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/NodeRenderer.as
Log:
SVG export: Fixed image alignment issue.
PDF Export: Added dashed/dotted line styles.

Added: cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/cytoscape.png
===================================================================
(Binary files differ)


Property changes on: 
cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/cytoscape.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/PDFExporter.as
===================================================================
--- 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/PDFExporter.as
        2010-11-19 21:34:56 UTC (rev 22942)
+++ 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/PDFExporter.as
        2010-11-19 21:54:33 UTC (rev 22943)
@@ -35,6 +35,7 @@
     import flare.vis.data.EdgeSprite;
     import flare.vis.data.NodeSprite;
     
+    import flash.display.CapsStyle;
     import flash.display.DisplayObject;
     import flash.filters.BitmapFilter;
     import flash.filters.GlowFilter;
@@ -47,6 +48,7 @@
     import org.alivepdf.display.Display;
     import org.alivepdf.drawing.Blend;
     import org.alivepdf.drawing.Caps;
+    import org.alivepdf.drawing.DashedLine;
     import org.alivepdf.drawing.Joint;
     import org.alivepdf.drawing.WindingRule;
     import org.alivepdf.fonts.CoreFont;
@@ -64,6 +66,7 @@
     import org.cytoscapeweb.util.Anchors;
     import org.cytoscapeweb.util.ArrowShapes;
     import org.cytoscapeweb.util.Fonts;
+    import org.cytoscapeweb.util.LineStyles;
     import org.cytoscapeweb.util.NodeShapes;
     import org.cytoscapeweb.util.Utils;
     import org.cytoscapeweb.util.VisualProperties;
@@ -202,7 +205,20 @@
                     
                     var w:Number = e.lineWidth * _scale;
                     var loop:Boolean = e.source === e.target;
+                    var lineStyle:String = e.props.lineStyle;
+                    var solid:Boolean = lineStyle === LineStyles.SOLID;
+                    var dashedLine:DashedLine;
+                    var cap:String = (LineStyles.getCaps(lineStyle) === 
CapsStyle.ROUND) ? Caps.ROUND : Caps.NONE;
+                    var dashArr:String = '';
                     
+                    if (!solid) {
+                        var onLength:Number = LineStyles.getOnLength(e, 
lineStyle, _scale);
+                        var offLength:Number = LineStyles.getOffLength(e, 
lineStyle, _scale);
+                        dashedLine = new DashedLine([onLength, offLength, 
onLength, offLength]);
+                    } else {
+                       dashedLine = null;
+                    }
+                    
                     // First let's draw any glow (e.g. for selected edges):
                     // -----------------------------------------------------
                     var filters:Array = e.filters;
@@ -215,11 +231,11 @@
                             
                             // The current version of AlivePDF does not 
support glows, gradients, etc.
                             // So we just draw a bigger shape behind the node:
-                            pdf.lineStyle(gc, gw, 0, ga);
+                            pdf.lineStyle(gc, gw, 0, ga, WindingRule.NON_ZERO, 
Blend.NORMAL, dashedLine, cap, Joint.MITER);
                             drawEdgeShaft(pdf, start, end, c1, c2, loop);
                             
                             // Arrow glow:
-                            pdf.lineStyle(gc, GLOW_WIDTH*_scale, 0, ga);
+                            pdf.lineStyle(gc, GLOW_WIDTH*_scale, 0, ga, 
WindingRule.NON_ZERO, Blend.NORMAL, null, Caps.NONE, Joint.MITER);
                             pdf.beginFill(gc);
                             drawEdgeArrowJoint(pdf, sJointPoints, 
saStyle.shape);
                             drawEdgeArrowJoint(pdf, tJointPoints, 
taStyle.shape);
@@ -232,31 +248,29 @@
                     // Draw the edge's line:
                     // -----------------------------------------------------
                     var edgeColor:RGBColor = new RGBColor(e.lineColor);
-                    pdf.lineStyle(edgeColor, w, 0, e.alpha, 
WindingRule.NON_ZERO, Blend.NORMAL, null, Caps.NONE, Joint.MITER);
+                    pdf.lineStyle(edgeColor, w, 0, e.alpha, 
WindingRule.NON_ZERO, Blend.NORMAL, dashedLine, cap, Joint.MITER);
                                   
                     drawEdgeShaft(pdf, start, end, c1, c2, loop);
                     
                     // Draw arrow joints:
                     // -----------------------------------------------------
-                    pdf.lineStyle(edgeColor, 0, 0, e.alpha);
+                    pdf.lineStyle(edgeColor, 0, 0, e.alpha, 
WindingRule.NON_ZERO, Blend.NORMAL, null, Caps.NONE, Joint.MITER);
                     
                     pdf.beginFill(edgeColor);
                     drawEdgeArrowJoint(pdf, sJointPoints, saStyle.shape);
-                    pdf.endFill();
-                    pdf.beginFill(edgeColor);
                     drawEdgeArrowJoint(pdf, tJointPoints, taStyle.shape);
                     pdf.endFill();
                     
                     // Draw arrows:
                     // -----------------------------------------------------
                     var saColor:RGBColor = new RGBColor(saStyle.color);
-                    pdf.lineStyle(saColor, 0, 0, e.alpha);
+                    pdf.lineStyle(saColor, 0, 0, e.alpha, 
WindingRule.NON_ZERO, Blend.NORMAL, null, Caps.NONE, Joint.MITER);
                     pdf.beginFill(saColor);
                     drawEdgeArrow(pdf, saStyle.shape, sArrowPoints, 
saStyle.height*_scale);
                     pdf.endFill();
                     
                     var taColor:RGBColor = new RGBColor(taStyle.color);
-                    pdf.lineStyle(taColor, 0, 0, e.alpha);
+                    pdf.lineStyle(taColor, 0, 0, e.alpha, 
WindingRule.NON_ZERO, Blend.NORMAL, null, Caps.NONE, Joint.MITER);
                     pdf.beginFill(taColor);
                     drawEdgeArrow(pdf, taStyle.shape, tArrowPoints, 
taStyle.height*_scale);
                     pdf.endFill();
@@ -430,6 +444,7 @@
                 if (shape === ArrowShapes.CIRCLE) {
                     var center:Point = points[0];
                     pdf.drawCircle(center.x, center.y, diameter/2);
+                    pdf.end(false);
                 } else if (shape === ArrowShapes.ARROW) {
                     var p1:Point = points[0];
                     var c1:Point = points[1];
@@ -443,6 +458,7 @@
                     pdf.lineTo(p3.x, p3.y);
                     Utils.quadraticToCubic(p3, c2, p1, ctrl1, ctrl2);
                     pdf.curveTo(ctrl1.x, ctrl1.y, ctrl2.x, ctrl2.y, p1.x, 
p1.y);
+                    pdf.moveTo(p1.x, p1.y);
                     pdf.end();
                 } else {
                     // Draw a polygon:
@@ -452,6 +468,8 @@
                         coordinates.push(p.y);
                     }
                     pdf.drawPolygone(coordinates);
+                    pdf.moveTo(points[0].x, points[0].y);
+                    pdf.end();
                 }
             }
         }
@@ -470,6 +488,7 @@
                             var ctrl2:Point = new Point();
                             Utils.quadraticToCubic(points[0], points[4], 
points[3], ctrl1, ctrl2);
                             pdf.curveTo(ctrl2.x, ctrl2.y, ctrl1.x, ctrl1.y, 
points[0].x, points[0].y);
+                            pdf.moveTo(points[0].x, points[0].y);
                             pdf.end();
                         }
                         break;
@@ -480,6 +499,8 @@
                             coordinates.push(p.y);
                         }
                         pdf.drawPolygone(coordinates);
+                        pdf.moveTo(points[0].x, points[0].y);
+                        pdf.end();
                         break;
                 }
             }

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/SVGExporter.as
===================================================================
--- 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/SVGExporter.as
        2010-11-19 21:34:56 UTC (rev 22942)
+++ 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/SVGExporter.as
        2010-11-19 21:54:33 UTC (rev 22943)
@@ -196,11 +196,11 @@
                     var dashArr:String = '';
                     
                     if (!solid) {
-                        var onLength:Number = LineStyles.getOnLength(e, 
lineStyle);
-                        var offLength:Number = LineStyles.getOffLength(e, 
lineStyle);
+                        var onLength:Number = LineStyles.getOnLength(e, 
lineStyle, _scale);
+                        var offLength:Number = LineStyles.getOffLength(e, 
lineStyle, _scale);
                         dashArr = 
'stroke-dasharray="'+onLength+','+offLength+'"';
                         cap = LineStyles.getCaps(lineStyle);
-                        cap = cap === CapsStyle.ROUND ? 'round' : 'butt';
+                        if (cap === CapsStyle.ROUND) cap = 'round';
                     }
                     
                     // First let's draw any glow (e.g. for selected edges):
@@ -319,9 +319,7 @@
                 
                 if (img != null) {
                     // Rescale image:
-                    var bmpSize:Number = Math.min(img.height, img.width);
-                    var scale:Number = w/bmpSize;
-                    img = Images.resizeBitmap(img, scale);
+                    img = Images.resizeToFill(img, new Rectangle(0, 0, w, h));
                     
                     // Encode as PNG and get bytes as Base64:
                     var encoder:PNGEncoder = new PNGEncoder();
@@ -329,14 +327,13 @@
                     var b64Enc:Base64Encoder = new Base64Encoder();
                     b64Enc.encodeBytes(ba);
                     var b64:String = b64Enc.toString();
-                    var mimeType:String = 'image/PNG';// TODO
                     
                     svg += '<clipPath id="clipNode_'+n.data.id+'">';
                     svg += nodeSvgShape;
                     svg += '</clipPath>';
                     svg += '<g clip-path="url(#clipNode_'+n.data.id+')">';
                     svg += '<g transform="matrix(1, 0, 0, 1, '+(np.x-w/2)+', 
'+(np.y-h/2)+')">';
-                    svg += '<image x="0" y="0" width="'+img.width+'" 
height="'+img.height+'" xlink:href="data:'+mimeType+';base64,'+b64+'"/>';
+                    svg += '<image x="0" y="0" width="'+img.width+'" 
height="'+img.height+'" xlink:href="data:image/PNG;base64,'+b64+'"/>';
                     svg += '</g>';
                     svg += '</g>';
                 }

Modified: cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/Images.as
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/Images.as 
2010-11-19 21:34:56 UTC (rev 22942)
+++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/Images.as 
2010-11-19 21:54:33 UTC (rev 22943)
@@ -32,6 +32,7 @@
     import flash.display.BitmapData;
     import flash.display.PixelSnapping;
     import flash.geom.Matrix;
+    import flash.geom.Rectangle;
     
     public class Images {
         
@@ -46,38 +47,32 @@
 
         // ========[ PUBLIC METHODS 
]===============================================================
 
-        public static function resizeBitmapToFit(bd:BitmapData, nw:Number, 
nh:Number):BitmapData {
-            if (bd.width > 0 && bd.height > 0) {
+        public static function resizeToFill(bd:BitmapData, 
rect:Rectangle):BitmapData {
+            if (bd.width > 0 && bd.height > 0 && rect.height > 0 && rect.width 
> 0) {
+               var rw:Number = rect.width;
+               var rh:Number = rect.height;
                 var w:Number = bd.width;
                 var h:Number = bd.height;
                 var originalRatio:Number = w/h;
-                var maxRatio:Number = nw/nh;
+                var maxRatio:Number = rw/rh;
                 var scale:Number;
                 
-                if (originalRatio > maxRatio) { // scale by width
-                    scale = nw/w;
+                if (originalRatio < maxRatio) { // scale by width
+                    scale = rw/w;
                 } else { // scale by height
-                    scale = nh/h;
+                    scale = rh/h;
                 }
                 
-                var m:Matrix = new Matrix();
-                m.scale(scale, scale);
-                m.translate(nw/2-(w*scale)/2, nh/2-(h*scale)/2);
-                
-                var bd2:BitmapData = new BitmapData(nw, nh, true, 0x000000);
-                bd2.draw(bd, m, null, null, null, true);
-    
-                var bmp:Bitmap = new Bitmap(bd2, PixelSnapping.NEVER, true);
-                
-                return bmp.bitmapData;
+                bd = resize(bd, scale, rw/2-(w*scale)/2, rh/2-(h*scale)/2);
             }
             
             return bd;
         }
     
-        public static function resizeBitmap(bd:BitmapData, 
scale:Number):BitmapData {   
+        public static function resize(bd:BitmapData, scale:Number, 
dx:Number=0, dy:Number=0):BitmapData {   
             var matrix:Matrix = new Matrix();
             matrix.scale(scale, scale);
+            matrix.translate(dx, dy);
             
             var bd2:BitmapData = new BitmapData(bd.width * scale, bd.height * 
scale, true, 0x000000);
             bd2.draw(bd, matrix, null, null, null, true);

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/LineStyles.as
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/LineStyles.as     
2010-11-19 21:34:56 UTC (rev 22942)
+++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/util/LineStyles.as     
2010-11-19 21:54:33 UTC (rev 22943)
@@ -55,20 +55,20 @@
         
         // ========[ PUBLIC METHODS 
]===============================================================
         
-        public static function getOnLength(e:EdgeSprite, 
lineStyle:String):Number {
+        public static function getOnLength(e:EdgeSprite, lineStyle:String, 
scale:Number=1):Number {
             var w:Number = e.lineWidth;
 
             switch (lineStyle) {
                 case DOT:       return 0.5;
-                case LONG_DASH: return 4*w;
+                case LONG_DASH: return 4 * w * scale;
                 case EQUAL_DASH:
-                default:        return 2*w;
+                default:        return 2 * w * scale;
             }
         }
         
-        public static function getOffLength(e:EdgeSprite, 
lineStyle:String):Number {
+        public static function getOffLength(e:EdgeSprite, lineStyle:String, 
scale:Number=1):Number {
             var w:Number = e.lineWidth;
-            return 2*w;
+            return 2 * w * scale;
         }
         
         public static function getCaps(lineStyle:String):String {

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/NodeRenderer.as
===================================================================
--- 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/NodeRenderer.as
    2010-11-19 21:34:56 UTC (rev 22942)
+++ 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/NodeRenderer.as
    2010-11-19 21:54:33 UTC (rev 22943)
@@ -161,19 +161,6 @@
                     var bd:BitmapData = _imgCache.getImage(url);
                     
                     if (bd != null) {
-                        // Reduce the image, if it is too large, to avoid some 
rendering issues:
-//                        const MAX_BMP_SCALE:uint = 30;
-//                        var maxZoom:Number = configProxy.maxZoom;
-//                        var zoom:Number = graphProxy.zoom;
-//                        var maxBmpSize:Number = size * zoom * MAX_BMP_SCALE;
-//                        
-//                        if (bmpSize > maxBmpSize) {
-//                            bd = resizeBitmap(bd, maxBmpSize/bmpSize);
-//                            bmpSize = Math.max(bd.height, bd.width);
-//                        }
-                        
-                        // TODO: only if "tofit_cropping" option:
-//                        bd = Images.resizeBitmapToFit(bd, size*maxZoom, 
size*maxZoom);
                         var bmpSize:Number = Math.min(bd.height, bd.width);
                         var scale:Number = size/bmpSize;
 

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to