Exemplo n.º 1
0
        public static Sm.DrawingVisual ToGeometryVisual(this Drawing input)
        {
            Sm.DrawingVisual drawings = new Sm.DrawingVisual();

            double scale = input.GetScale();

            Rg.Curve curve = input.Frame.ToNurbsCurve();

            double x0 = input.Frame.Center.X - input.Width / scale / 2;
            double x1 = input.Frame.Center.X + input.Width / scale / 2;

            double y0 = input.Frame.Center.Y - input.Height / scale / 2;
            double y1 = input.Frame.Center.Y + input.Height / scale / 2;

            Rg.Rectangle3d rect = new Rg.Rectangle3d(Rg.Plane.WorldXY, new Rg.Point3d(x0, y0, 0), new Rg.Point3d(x1, y1, 0));

            drawings.Children.Add(new Shape(rect.ToNurbsCurve(), new Wg.Graphic(Wg.Strokes.Transparent, new Wg.Fill(input.Background))).ToVisualDrawing());

            foreach (Shape shape in input.Shapes)
            {
                drawings.Children.Add(shape.ToVisualDrawing());
            }

            Sm.TransformGroup xform = new Sm.TransformGroup();

            double shiftW = (input.Width / scale / 2 - input.Frame.Center.X);
            double shiftH = -(input.Height / scale / 2 + input.Frame.Center.Y);

            xform.Children.Add(new Sm.TranslateTransform(shiftW, shiftH));
            xform.Children.Add(new Sm.ScaleTransform(scale, (-1) * scale));

            drawings.Transform = xform;

            return(drawings);
        }
Exemplo n.º 2
0
        public static Sm.DrawingGroup ToGeometryGroup(this Drawing input)
        {
            Sm.DrawingGroup drawings = new Sm.DrawingGroup();

            double scale = input.GetScale();

            Rg.Curve curve = input.Frame.ToNurbsCurve();

            double x0 = input.Frame.Center.X - input.Width / scale / 2;
            double x1 = input.Frame.Center.X + input.Width / scale / 2;

            double y0 = input.Frame.Center.Y - input.Height / scale / 2;
            double y1 = input.Frame.Center.Y + input.Height / scale / 2;

            Rg.Rectangle3d rect = new Rg.Rectangle3d(Rg.Plane.WorldXY, new Rg.Point3d(x0, y0, 0), new Rg.Point3d(x1, y1, 0));

            drawings.Children.Add(new Shape(rect.ToNurbsCurve(), new Wg.Graphic(Wg.Strokes.Transparent, new Wg.Fill(input.Background))).ToGeometryDrawing());

            foreach (Shape shape in input.Shapes)
            {
                drawings.Children.Add(shape.ToGeometryDrawing());
            }

            drawings.ClipGeometry = input.Frame.ToPolyline().ToGeometry();

            Sm.TransformGroup xform = new Sm.TransformGroup();

            xform.Children.Add(new Sm.TranslateTransform(input.Frame.Center.X - input.Width / 2, input.Frame.Center.Y - input.Height / 2));
            xform.Children.Add(new Sm.ScaleTransform(1, -1));

            drawings.Transform = xform;

            return(drawings);
        }
Exemplo n.º 3
0
        public static string ToSVG(this Hp.Drawing input)
        {
            double scale = input.GetScale();

            string drawing = "<svg width=\"" + input.Width + "\" height=\"" + input.Height + "\" shape-rendering=\"geometricPrecision\" xmlns=\"http://www.w3.org/2000/svg\" >" + Environment.NewLine;

            double shiftW = (input.Width / scale / 2 - input.Frame.Center.X);
            double shiftH = -(input.Height / scale / 2 + input.Frame.Center.Y);

            drawing += "<g class=\"Canvas\" id=\"Canvas\" transform=\"scale(" + scale + "," + (-1) * scale + ") translate(" + shiftW + "," + shiftH + ") \">" + Environment.NewLine;

            Dictionary <string, Wg.Effects> effects  = new Dictionary <string, Wg.Effects>();
            Dictionary <string, Wg.Graphic> graphics = new Dictionary <string, Wg.Graphic>();

            foreach (Shape shape in input.Shapes)
            {
                drawing += shape.ToPath();
                if (!graphics.ContainsKey(shape.Graphic.ID))
                {
                    graphics.Add(shape.Graphic.ID, shape.Graphic);
                }

                if (shape.Graphic.Effects.HasEffects)
                {
                    if (!effects.ContainsKey(shape.Graphic.Effects.ID))
                    {
                        effects.Add(shape.Graphic.Effects.ID, shape.Graphic.Effects);
                    }
                }
            }

            drawing += "</g >" + Environment.NewLine;

            drawing += "<defs>" + Environment.NewLine;
            drawing += "<clipPath id=\"Frame\"> <rect x=\"0\" y=\"0\" width=\"" + input.Width + "\" height=\"" + input.Height + "\" /> </clipPath>" + Environment.NewLine;

            foreach (Wg.Effects effect in effects.Values)
            {
                drawing += effect.ToSVG();
            }

            foreach (Wg.Graphic graphic in graphics.Values)
            {
                drawing += graphic.ToSVG();
            }

            drawing += "</defs>" + Environment.NewLine;
            drawing += "</svg >";

            return(drawing);
        }