예제 #1
0
        private void AddGeometryDrawing(ConvertibleDrawing.DrawingStackEntry entry)
        {
            GeometryDrawing geometryDrawing = entry.Drawing as GeometryDrawing;
            Path            path            = new Path();

            ConvertibleDrawing.SetPositionInCanvas((UIElement)path, entry.Offset);
            if (entry.Transform != Transform.Identity)
            {
                ConvertibleDrawing.SetValueIfNotDefault(UIElement.RenderTransformProperty, (DependencyObject)path, (object)entry.Transform);
            }
            entry.Canvas.Children.Add((UIElement)path);
            ConvertibleDrawing.SetValueIfNotDefault(Shape.FillProperty, (DependencyObject)path, (object)geometryDrawing.Brush);
            if (geometryDrawing.Pen != null)
            {
                Pen pen = geometryDrawing.Pen;
                ConvertibleDrawing.SetValueIfNotDefault(Shape.StrokeProperty, (DependencyObject)path, (object)pen.Brush);
                ConvertibleDrawing.SetValueIfNotDefault(Shape.StrokeDashArrayProperty, (DependencyObject)path, (object)pen.DashStyle.Dashes);
                ConvertibleDrawing.SetValueIfNotDefault(Shape.StrokeDashCapProperty, (DependencyObject)path, (object)pen.DashCap);
                ConvertibleDrawing.SetValueIfNotDefault(Shape.StrokeDashOffsetProperty, (DependencyObject)path, (object)pen.DashStyle.Offset);
                ConvertibleDrawing.SetValueIfNotDefault(Shape.StrokeEndLineCapProperty, (DependencyObject)path, (object)pen.EndLineCap);
                ConvertibleDrawing.SetValueIfNotDefault(Shape.StrokeLineJoinProperty, (DependencyObject)path, (object)pen.LineJoin);
                ConvertibleDrawing.SetValueIfNotDefault(Shape.StrokeMiterLimitProperty, (DependencyObject)path, (object)pen.MiterLimit);
                ConvertibleDrawing.SetValueIfNotDefault(Shape.StrokeStartLineCapProperty, (DependencyObject)path, (object)pen.StartLineCap);
                ConvertibleDrawing.SetValueIfNotDefault(Shape.StrokeThicknessProperty, (DependencyObject)path, (object)pen.Thickness);
            }
            path.Data = geometryDrawing.Geometry;
        }
예제 #2
0
        private Canvas AddCanvasLevel(ConvertibleDrawing.DrawingStackEntry entry)
        {
            Canvas       canvas       = new Canvas();
            DrawingGroup drawingGroup = entry.Drawing as DrawingGroup;

            if (entry.Transform != Transform.Identity)
            {
                CanonicalTransform canonicalTransform = new CanonicalTransform(entry.Transform);
                if (drawingGroup.Transform != null)
                {
                    canonicalTransform = new CanonicalTransform(entry.Transform.Value * drawingGroup.Transform.Value);
                }
                ConvertibleDrawing.SetValueIfNotDefault(UIElement.RenderTransformProperty, (DependencyObject)canvas, (object)canonicalTransform.TransformGroup);
            }
            ConvertibleDrawing.SetPositionInCanvas((UIElement)canvas, entry.Offset);
            ConvertibleDrawing.SetValueIfNotDefault(UIElement.BitmapEffectProperty, (DependencyObject)canvas, (object)drawingGroup.BitmapEffect);
            ConvertibleDrawing.SetValueIfNotDefault(UIElement.BitmapEffectInputProperty, (DependencyObject)canvas, (object)drawingGroup.BitmapEffectInput);
            ConvertibleDrawing.SetValueIfNotDefault(UIElement.OpacityProperty, (DependencyObject)canvas, (object)drawingGroup.Opacity);
            ConvertibleDrawing.SetValueIfNotDefault(UIElement.OpacityMaskProperty, (DependencyObject)canvas, (object)drawingGroup.OpacityMask);
            ConvertibleDrawing.SetValueIfNotDefault(UIElement.ClipProperty, (DependencyObject)canvas, (object)drawingGroup.ClipGeometry);
            if (!double.IsInfinity(drawingGroup.Bounds.Height))
            {
                ConvertibleDrawing.SetValueIfNotDefault(FrameworkElement.HeightProperty, (DependencyObject)canvas, (object)drawingGroup.Bounds.Height);
            }
            if (!double.IsInfinity(drawingGroup.Bounds.Width))
            {
                ConvertibleDrawing.SetValueIfNotDefault(FrameworkElement.WidthProperty, (DependencyObject)canvas, (object)drawingGroup.Bounds.Width);
            }
            entry.Canvas.Children.Add((UIElement)canvas);
            return(canvas);
        }
예제 #3
0
 protected void AddSimpleDrawingToCanvas(ConvertibleDrawing.DrawingStackEntry entry)
 {
     if (entry.Drawing is GeometryDrawing)
     {
         this.AddGeometryDrawing(entry);
     }
     else if (entry.Drawing is GlyphRunDrawing)
     {
         this.AddGlyphRunDrawing(entry);
     }
     else if (entry.Drawing is ImageDrawing)
     {
         this.AddImageDrawing(entry);
     }
     else if (entry.Drawing is VideoDrawing)
     {
         throw new NotSupportedException("VideoDrawing currently not supported.");
     }
 }
예제 #4
0
        private void AddImageDrawing(ConvertibleDrawing.DrawingStackEntry entry)
        {
            ImageDrawing imageDrawing = entry.Drawing as ImageDrawing;

            if (this.projectPath != null)
            {
                imageDrawing = (ImageDrawing)MakeDrawingBrushCommand.SimplifyImageDrawing(imageDrawing, this.projectPath);
            }
            Image image = new Image();

            ConvertibleDrawing.SetValueIfNotDefault(FrameworkElement.HeightProperty, (DependencyObject)image, (object)imageDrawing.Bounds.Height);
            ConvertibleDrawing.SetValueIfNotDefault(FrameworkElement.WidthProperty, (DependencyObject)image, (object)imageDrawing.Bounds.Width);
            ConvertibleDrawing.SetValueIfNotDefault(Image.SourceProperty, (DependencyObject)image, (object)imageDrawing.ImageSource);
            ConvertibleDrawing.SetPositionInCanvas((UIElement)image, entry.Offset);
            if (entry.Transform != Transform.Identity)
            {
                ConvertibleDrawing.SetValueIfNotDefault(UIElement.RenderTransformProperty, (DependencyObject)image, (object)entry.Transform);
            }
            entry.Canvas.Children.Add((UIElement)image);
        }
예제 #5
0
        private void AddGlyphRunDrawing(ConvertibleDrawing.DrawingStackEntry entry)
        {
            GlyphRunDrawing glyphRunDrawing = entry.Drawing as GlyphRunDrawing;

            System.Windows.Media.Geometry geometry = (System.Windows.Media.Geometry)null;
            if (glyphRunDrawing.GlyphRun != null)
            {
                geometry = glyphRunDrawing.GlyphRun.BuildGeometry();
            }
            Path path = new Path();

            ConvertibleDrawing.SetValueIfNotDefault(Shape.FillProperty, (DependencyObject)path, (object)glyphRunDrawing.ForegroundBrush);
            ConvertibleDrawing.SetValueIfNotDefault(Path.DataProperty, (DependencyObject)path, (object)geometry);
            ConvertibleDrawing.SetPositionInCanvas((UIElement)path, entry.Offset);
            if (entry.Transform != Transform.Identity)
            {
                ConvertibleDrawing.SetValueIfNotDefault(UIElement.RenderTransformProperty, (DependencyObject)path, (object)entry.Transform);
            }
            entry.Canvas.Children.Add((UIElement)path);
        }
예제 #6
0
        protected void PutDrawingOnCanvas(Canvas canvas)
        {
            Stack <ConvertibleDrawing.DrawingStackEntry> stack = new Stack <ConvertibleDrawing.DrawingStackEntry>();

            ConvertibleDrawing.DrawingStackEntry drawingStackEntry1 = new ConvertibleDrawing.DrawingStackEntry(canvas, this.Drawing, Matrix.Identity);
            stack.Push(drawingStackEntry1);
            while (stack.Count > 0)
            {
                ConvertibleDrawing.DrawingStackEntry entry = stack.Pop();
                DrawingGroup drawingGroup = entry.Drawing as DrawingGroup;
                if (drawingGroup != null)
                {
                    Matrix matrix = Matrix.Identity;
                    Canvas canvas1;
                    if (this.ShouldCreateCanvasFromDrawingGroup(drawingGroup))
                    {
                        canvas1 = this.AddCanvasLevel(entry);
                    }
                    else
                    {
                        Matrix identity = Matrix.Identity;
                        if (drawingGroup.Transform != null)
                        {
                            identity = drawingGroup.Transform.Value;
                        }
                        canvas1 = entry.Canvas;
                        matrix  = entry.Matrix * identity;
                    }
                    for (int index = drawingGroup.Children.Count - 1; index >= 0; --index)
                    {
                        ConvertibleDrawing.DrawingStackEntry drawingStackEntry2 = new ConvertibleDrawing.DrawingStackEntry(canvas1, drawingGroup.Children[index], matrix);
                        stack.Push(drawingStackEntry2);
                    }
                }
                else
                {
                    this.AddSimpleDrawingToCanvas(entry);
                }
            }
        }