internal override bool Render(UIElement element, PdfRenderContext context)
        {
            Shape shape = element as Shape;

            if (shape == null)
            {
                return(false);
            }

            Type         type             = shape.GetType();
            PropertyInfo geometryProperty = type.GetProperty("DefiningGeometry", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            Geometry     geometry         = (Geometry)geometryProperty.GetValue(shape, null);
            var          pdfGeometry      = PdfGeometryHelper.ConvertGeometry(geometry);

            if (pdfGeometry == null)
            {
                return(false);
            }

            using (context.drawingSurface.SaveGraphicProperties())
            {
                SetFill(context, shape.Fill, shape.ActualWidth, shape.ActualHeight);
                SetStroke(context, shape.StrokeThickness, shape.Stroke, shape.ActualWidth, shape.ActualHeight);

                if (context.drawingSurface.GraphicProperties.IsFilled || context.drawingSurface.GraphicProperties.IsStroked)
                {
                    context.drawingSurface.DrawPath(pdfGeometry);
                }

                return(true);
            }
        }
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            Shape shape = element as Shape;
            if (shape == null)
            {
                return false;
            }

            Type type = shape.GetType();
            PropertyInfo geometryProperty = type.GetProperty("DefiningGeometry", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            Geometry geometry = (Geometry)geometryProperty.GetValue(shape, null);
            var pdfGeometry = PdfGeometryHelper.ConvertGeometry(geometry);
            if (pdfGeometry == null)
            {
                return false;
            }

            using (context.drawingSurface.SaveGraphicProperties())
            {
                SetFill(context, shape.Fill, shape.ActualWidth, shape.ActualHeight);
                SetStroke(context, shape.StrokeThickness, shape.Stroke, shape.ActualWidth, shape.ActualHeight, shape.StrokeDashArray);

                if (context.drawingSurface.GraphicProperties.IsFilled || context.drawingSurface.GraphicProperties.IsStroked)
                {
                    context.drawingSurface.DrawPath(pdfGeometry);
                }
                
                return true;
            }
        }
Exemple #3
0
        private void DrawBorderStroke(PdfRenderContext context, Thickness thickness, Brush stroke, double actualWidth, double actualHeight)
        {
            if (stroke == null)
            {
                return;
            }

            if (thickness.Left != 0)
            {
                LineRenderer.DrawLine(context, thickness.Left / 2, 0, thickness.Left / 2, actualHeight, thickness.Left, stroke, null);
            }
            if (thickness.Top != 0)
            {
                LineRenderer.DrawLine(context, 0, thickness.Top / 2, actualWidth, thickness.Top / 2, thickness.Top, stroke, null);
            }
            if (thickness.Right != 0)
            {
                double x = actualWidth - (thickness.Right / 2);
                LineRenderer.DrawLine(context, x, 0, x, actualHeight, thickness.Right, stroke, null);
            }
            if (thickness.Bottom != 0)
            {
                double y = actualHeight - (thickness.Bottom / 2);
                LineRenderer.DrawLine(context, 0, y, actualWidth, y, thickness.Bottom, stroke, null);
            }
        }
        internal static void SetFill(PdfRenderContext context, Brush brush, double width, double height)
        {
            var fill = PdfColorHelper.ConvertBrush(brush, context.opacity, context.drawingSurface.Position, width, height);

            context.drawingSurface.GraphicProperties.IsFilled = fill != null;
            context.drawingSurface.GraphicProperties.FillColor = fill;
        }
Exemple #5
0
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            Path path = element as Path;
            if (path == null)
            {
                return false;
            }

            var pdfGeometry = PdfGeometryHelper.ConvertGeometry(path.Data);
            if (pdfGeometry == null)
            {
                return false;
            }

            using (context.drawingSurface.SaveGraphicProperties())
            {
                SetFill(context, path.Fill, path.ActualWidth, path.ActualHeight);
                SetStroke(context, path.StrokeThickness, path.Stroke, path.ActualWidth, path.ActualHeight);

                if (context.drawingSurface.GraphicProperties.IsFilled || context.drawingSurface.GraphicProperties.IsStroked)
                {
                    context.drawingSurface.DrawPath(pdfGeometry);
                }

                return true;
            }
        }
        internal void Render(UIElement element, PdfRenderContext context)
        {
            if (element == null || element.Visibility != Visibility.Visible || element.Opacity == 0)
            {
                return;
            }

            var compositeSave = new CompositeDisposableObject();
            compositeSave.Add(UIElementRendererBase.SaveMatrixPosition(context.drawingSurface, element as FrameworkElement));
            compositeSave.Add(UIElementRendererBase.SaveClip(context.drawingSurface, element));
            compositeSave.Add(UIElementRendererBase.SaveOpacity(context, context.opacity * element.Opacity));

            using (compositeSave)
            {
                foreach (UIElementRendererBase renderer in this.renderers)
                {
                    bool success = renderer.Render(element, context);
                    if (success)
                    {
                        return;
                    }
                }
            }

            System.Diagnostics.Debug.WriteLine("" + element + " could not be exported correctly.");
        }
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            TextBlock textBlock = element as TextBlock;

            if (textBlock == null)
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(textBlock.Text))
            {
                using (context.drawingSurface.SaveProperties())
                {
                    SetFill(context, textBlock.Foreground, textBlock.ActualWidth, textBlock.ActualHeight);
                    SetFontFamily(context.drawingSurface, textBlock.FontFamily);
                    context.drawingSurface.TextProperties.FontSize = textBlock.FontSize;

                    Block block = new Block();
                    block.TextProperties.CopyFrom(context.drawingSurface.TextProperties);
                    block.GraphicProperties.CopyFrom(context.drawingSurface.GraphicProperties);
                    string[] textLines = textBlock.Text.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

                    foreach (string textLine in textLines)
                    {
                        block.InsertText(textLine);
                        block.InsertLineBreak();
                    }

                    context.drawingSurface.DrawBlock(block);
                }
            }

            return(true);
        }
Exemple #8
0
        internal static void DrawLine(PdfRenderContext context, double x1, double y1, double x2, double y2, double strokeThickness, Brush stroke, DoubleCollection dashArray)
        {
            using (context.drawingSurface.SaveGraphicProperties())
            {
                if (x1 == x2 && System.Math.Abs(y1 - y2) > 10)
                {
                    if (y2 < y1)
                    {
                        double max = y1;
                        y1 = y2;
                        y2 = max;
                    }

                    // offset the start position of the line to resolve a visual bug in Adobe Reader, where the axis line seems to continue after the last tick
                    y1 += 0.5;
                }

                SetStroke(context, strokeThickness, stroke, Math.Abs(x2 - x1), Math.Abs(y2 - y1));
                if (context.drawingSurface.GraphicProperties.IsStroked)
                {
                    context.drawingSurface.GraphicProperties.StrokeDashArray = dashArray;
                    context.drawingSurface.DrawLine(new Point(x1, y1), new Point(x2, y2));
                }
            }
        }
Exemple #9
0
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            Path path = element as Path;

            if (path == null)
            {
                return(false);
            }

            var pdfGeometry = PdfGeometryHelper.ConvertGeometry(path.Data);

            if (pdfGeometry == null)
            {
                return(false);
            }

            using (context.drawingSurface.SaveGraphicProperties())
            {
                SetFill(context, path.Fill, path.ActualWidth, path.ActualHeight);
                SetStroke(context, path.StrokeThickness, path.Stroke, path.ActualWidth, path.ActualHeight, path.StrokeDashArray);

                if (context.drawingSurface.GraphicProperties.IsFilled || context.drawingSurface.GraphicProperties.IsStroked)
                {
                    context.drawingSurface.DrawPath(pdfGeometry);
                }

                return(true);
            }
        }
        internal static void SetFill(PdfRenderContext context, Brush brush, double width, double height)
        {
            var fill = PdfColorHelper.ConvertBrush(brush, context.opacity, context.drawingSurface.Position, width, height);

            context.drawingSurface.GraphicProperties.IsFilled  = fill != null;
            context.drawingSurface.GraphicProperties.FillColor = fill;
        }
        private void DrawBorderStroke(PdfRenderContext context, Thickness thickness, Brush stroke, double actualWidth, double actualHeight)
        {
            if (stroke == null)
            {
                return;
            }

            if (thickness.Left != 0)
            {
                LineRenderer.DrawLine(context, thickness.Left / 2, 0, thickness.Left / 2, actualHeight, thickness.Left, stroke, null);
            }
            if (thickness.Top != 0)
            {
                LineRenderer.DrawLine(context, 0, thickness.Top / 2, actualWidth, thickness.Top / 2, thickness.Top, stroke, null);
            }
            if (thickness.Right != 0)
            {
                double x = actualWidth - (thickness.Right / 2);
                LineRenderer.DrawLine(context, x, 0, x, actualHeight, thickness.Right, stroke, null);
            }
            if (thickness.Bottom != 0)
            {
                double y = actualHeight - (thickness.Bottom / 2);
                LineRenderer.DrawLine(context, 0, y, actualWidth, y, thickness.Bottom, stroke, null);
            }
        }
Exemple #12
0
        public static void DrawTextBlock(string text, PdfRenderContext context, Brush foreground, double width, double height, FontFamily fontFamily, double fontSize)
        {
            if (!string.IsNullOrEmpty(text))
            {
                using (context.drawingSurface.SaveProperties())
                {
                    UIElementRendererBase.SetFill(context, foreground, width, height);
                    SetFontFamily(context.drawingSurface, fontFamily);
                    context.drawingSurface.TextProperties.FontSize = fontSize;

                    Block block = new Block();
                    block.TextProperties.CopyFrom(context.drawingSurface.TextProperties);
                    block.GraphicProperties.CopyFrom(context.drawingSurface.GraphicProperties);
                    string[] textLines = text.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

                    foreach (string textLine in textLines)
                    {
                        block.InsertText(textLine);
                        block.InsertLineBreak();
                    }

                    context.drawingSurface.DrawBlock(block);
                }
            }
        }
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            TextBlock textBlock = element as TextBlock;
            if (textBlock == null)
            {
                return false;
            }

            if (!string.IsNullOrEmpty(textBlock.Text))
            {
                using (context.drawingSurface.SaveProperties())
                {
                    SetFill(context, textBlock.Foreground, textBlock.ActualWidth, textBlock.ActualHeight);
                    SetFontFamily(context.drawingSurface, textBlock.FontFamily);
                    context.drawingSurface.TextProperties.FontSize = textBlock.FontSize;

                    Block block = new Block();
                    block.TextProperties.CopyFrom(context.drawingSurface.TextProperties);
                    block.GraphicProperties.CopyFrom(context.drawingSurface.GraphicProperties);
                    string[] textLines = textBlock.Text.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

                    foreach (string textLine in textLines)
                    {
                        block.InsertText(textLine);
                        block.InsertLineBreak();
                    }

                    context.drawingSurface.DrawBlock(block);
                }
            }

            return true;
        }
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            var border = element as System.Windows.Controls.Border;

            if (border == null)
            {
                return(false);
            }

            if (IsSimpleStrokeThickness(border.BorderThickness))
            {
                RectangleRenderer.DrawRectangle(context, border.Background, border.BorderBrush, border.BorderThickness.Left, border.ActualWidth, border.ActualHeight, null);
            }
            else
            {
                DrawBackground(context, border.Background, border.BorderThickness, border.ActualWidth, border.ActualHeight);
                DrawBorderStroke(context, border.BorderThickness, border.BorderBrush, border.ActualWidth, border.ActualHeight);
            }

            UIElement firstChild = border.Child;

            context.facade.Render(firstChild, context);

            return(true);
        }
Exemple #15
0
        internal void Render(UIElement element, PdfRenderContext context)
        {
            if (element == null || element.Visibility != Visibility.Visible || element.Opacity == 0)
            {
                return;
            }

            var compositeSave = new CompositeDisposableObject();

            compositeSave.Add(UIElementRendererBase.SaveMatrixPosition(context.drawingSurface, element as FrameworkElement));
            compositeSave.Add(UIElementRendererBase.SaveClip(context.drawingSurface, element));
            compositeSave.Add(UIElementRendererBase.SaveOpacity(context, context.opacity * element.Opacity));

            using (compositeSave)
            {
                foreach (UIElementRendererBase renderer in this.renderers)
                {
                    bool success = renderer.Render(element, context);
                    if (success)
                    {
                        return;
                    }
                }
            }

            System.Diagnostics.Debug.WriteLine("" + element + " could not be exported correctly.");
        }
 public void Dispose()
 {
     if (this.context != null)
     {
         this.context.opacity = this.opacity;
         this.context = null;
     }
 }
 public void Dispose()
 {
     if (this.context != null)
     {
         this.context.opacity = this.opacity;
         this.context         = null;
     }
 }
Exemple #18
0
 private void DrawBackground(PdfRenderContext context, Brush fill, Thickness thickness, double actualWidth, double actualHeight)
 {
     using (context.drawingSurface.SaveGraphicProperties())
     {
         context.drawingSurface.GraphicProperties.IsStroked = false;
         SetFill(context, fill, actualWidth, actualHeight);
         Rect innerRect = new Rect(thickness.Left, thickness.Top, actualWidth - thickness.Left - thickness.Right, actualHeight - thickness.Top - thickness.Bottom);
         context.drawingSurface.DrawRectangle(innerRect);
     }
 }
 private void DrawBackground(PdfRenderContext context, Brush fill, Thickness thickness, double actualWidth, double actualHeight)
 {
     using (context.drawingSurface.SaveGraphicProperties())
     {
         context.drawingSurface.GraphicProperties.IsStroked = false;
         SetFill(context, fill, actualWidth, actualHeight);
         Rect innerRect = new Rect(thickness.Left, thickness.Top, actualWidth - thickness.Left - thickness.Right, actualHeight - thickness.Top - thickness.Bottom);
         context.drawingSurface.DrawRectangle(innerRect);
     }
 }
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            Line line = element as Line;
            if (line == null)
            {
                return false;
            }

            DrawLine(context, line.X1, line.Y1, line.X2, line.Y2, line.StrokeThickness, line.Stroke, line.StrokeDashArray);

            return true;
        }
Exemple #21
0
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            Panel panel = element as Panel;
            if (panel == null)
            {
                return false;
            }

            RectangleRenderer.DrawRectangle(context, panel.Background, null, 0, panel.ActualWidth, panel.ActualHeight);

            return base.Render(panel, context);
        }
 internal static IDisposable SaveOpacity(PdfRenderContext context, double newOpacity)
 {
     if (context.opacity != newOpacity)
     {
         DisposableOpacity disposableOpacity = new DisposableOpacity(context);
         context.opacity = newOpacity;
         return disposableOpacity;
     }
     else
     {
         return null;
     }
 }
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            Panel panel = element as Panel;

            if (panel == null)
            {
                return(false);
            }

            RectangleRenderer.DrawRectangle(context, panel.Background, null, 0, panel.ActualWidth, panel.ActualHeight);

            return(base.Render(panel, context));
        }
 internal static IDisposable SaveOpacity(PdfRenderContext context, double newOpacity)
 {
     if (context.opacity != newOpacity)
     {
         DisposableOpacity disposableOpacity = new DisposableOpacity(context);
         context.opacity = newOpacity;
         return(disposableOpacity);
     }
     else
     {
         return(null);
     }
 }
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            Line line = element as Line;

            if (line == null)
            {
                return(false);
            }

            DrawLine(context, line.X1, line.Y1, line.X2, line.Y2, line.StrokeThickness, line.Stroke, line.StrokeDashArray);

            return(true);
        }
Exemple #26
0
        internal static void DrawRectangle(PdfRenderContext context, Brush fill, Brush stroke, double strokeThickness, double actualWidth, double actualHeight)
        {
            using (context.drawingSurface.SaveGraphicProperties())
            {
                SetFill(context, fill, actualWidth, actualHeight);
                SetStroke(context, strokeThickness, stroke, actualWidth, actualHeight);

                if (context.drawingSurface.GraphicProperties.IsFilled || context.drawingSurface.GraphicProperties.IsStroked)
                {
                    // account for the difference in the notion of stroke in wpf's Rectangle/Border and pdf's Rectangle
                    double thickness = context.drawingSurface.GraphicProperties.IsStroked ? strokeThickness : 0;

                    context.drawingSurface.DrawRectangle(new Rect(thickness / 2, thickness / 2, actualWidth - thickness, actualHeight - thickness));
                }
            }
        }
Exemple #27
0
        internal static void DrawRectangle(PdfRenderContext context, Brush fill, Brush stroke, double strokeThickness, double actualWidth, double actualHeight, DoubleCollection dashArray)
        {
            using (context.drawingSurface.SaveGraphicProperties())
            {
                SetFill(context, fill, actualWidth, actualHeight);
                SetStroke(context, strokeThickness, stroke, actualWidth, actualHeight, dashArray);

                if (context.drawingSurface.GraphicProperties.IsFilled || context.drawingSurface.GraphicProperties.IsStroked)
                {
                    // account for the difference in the notion of stroke in wpf's Rectangle/Border and pdf's Rectangle
                    double thickness = context.drawingSurface.GraphicProperties.IsStroked ? strokeThickness : 0;

                    context.drawingSurface.DrawRectangle(new Rect(thickness / 2, thickness / 2, actualWidth - thickness, actualHeight - thickness));
                }
            }
        }
        internal static void SetStroke(PdfRenderContext context, double thickness, Brush brush, double width, double height, DoubleCollection dashArray)
        {
            var stroke = PdfColorHelper.ConvertBrush(brush, context.opacity, context.drawingSurface.Position, width, height);
            context.drawingSurface.GraphicProperties.IsStroked = thickness != 0 && stroke != null;

            if (context.drawingSurface.GraphicProperties.IsStroked)
            {
                context.drawingSurface.GraphicProperties.StrokeThickness = thickness;
                context.drawingSurface.GraphicProperties.StrokeColor = stroke;

                if (dashArray != null)
                {
                    context.drawingSurface.GraphicProperties.StrokeDashArray = dashArray;
                }
            }
        }
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            var image = element as System.Windows.Controls.Image;
            if (image == null)
            {
                return false;
            }

            if (image.ActualWidth > 0 && image.ActualHeight > 0)
            {
                MemoryStream stream = new MemoryStream();
                Telerik.Windows.Media.Imaging.ExportExtensions.ExportToImage(image, stream, new PngBitmapEncoder());
                context.drawingSurface.DrawImage(stream);
            }

            return true;
        }
        internal static void SetStroke(PdfRenderContext context, double thickness, Brush brush, double width, double height, DoubleCollection dashArray)
        {
            var stroke = PdfColorHelper.ConvertBrush(brush, context.opacity, context.drawingSurface.Position, width, height);

            context.drawingSurface.GraphicProperties.IsStroked = thickness != 0 && stroke != null;

            if (context.drawingSurface.GraphicProperties.IsStroked)
            {
                context.drawingSurface.GraphicProperties.StrokeThickness = thickness;
                context.drawingSurface.GraphicProperties.StrokeColor     = stroke;

                if (dashArray != null)
                {
                    context.drawingSurface.GraphicProperties.StrokeDashArray = dashArray;
                }
            }
        }
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            var image = element as System.Windows.Controls.Image;

            if (image == null)
            {
                return(false);
            }

            if (image.ActualWidth > 0 && image.ActualHeight > 0)
            {
                MemoryStream stream = new MemoryStream();
                Telerik.Windows.Media.Imaging.ExportExtensions.ExportToImage(image, stream, new PngBitmapEncoder());
                context.drawingSurface.DrawImage(stream);
            }

            return(true);
        }
Exemple #32
0
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            FrameworkElement frameworkElement = element as FrameworkElement;

            if (frameworkElement == null)
            {
                return(false);
            }

            bool hasMatchingType = false;
            Type elementType     = frameworkElement.GetType();

            foreach (Type type in this.types)
            {
                if (elementType == type || elementType.IsSubclassOf(type))
                {
                    hasMatchingType = true;
                    break;
                }
            }

            if (!hasMatchingType)
            {
                return(false);
            }

            List <UIElement> uiElements = new List <UIElement>();

            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(frameworkElement); i++)
            {
                UIElement child = VisualTreeHelper.GetChild(frameworkElement, i) as UIElement;
                uiElements.Add(child);
            }

            uiElements = uiElements.OrderBy(el => Canvas.GetZIndex(el)).ToList();

            foreach (UIElement child in uiElements)
            {
                context.facade.Render(child, context);
            }

            return(true);
        }
Exemple #33
0
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            TextBlock textBlock = element as TextBlock;

            if (textBlock == null)
            {
                return(false);
            }

            string text       = textBlock.Text;
            Brush  foreground = textBlock.Foreground;
            double width      = textBlock.ActualWidth;
            double height     = textBlock.ActualHeight;
            var    fontFamily = textBlock.FontFamily;
            double fontSize   = textBlock.FontSize;

            TextRenderer.DrawTextBlock(text, context, foreground, width, height, fontFamily, fontSize);

            return(true);
        }
        internal static void SetStroke(PdfRenderContext context, double thickness, Brush brush, double width, double height)
        {
            context.drawingSurface.GraphicProperties.IsStroked = thickness != 0;
            if (!context.drawingSurface.GraphicProperties.IsStroked)
            {
                return;
            }

            context.drawingSurface.GraphicProperties.StrokeThickness = thickness;

            var stroke = PdfColorHelper.ConvertBrush(brush, context.opacity, context.drawingSurface.Position, width, height);
            if (stroke != null)
            {
                context.drawingSurface.GraphicProperties.StrokeColor = stroke;
            }
            else
            {
                context.drawingSurface.GraphicProperties.IsStroked = false;
            }
        }
Exemple #35
0
        internal static void SetStroke(PdfRenderContext context, double thickness, Brush brush, double width, double height)
        {
            context.drawingSurface.GraphicProperties.IsStroked = thickness != 0;
            if (!context.drawingSurface.GraphicProperties.IsStroked)
            {
                return;
            }

            context.drawingSurface.GraphicProperties.StrokeThickness = thickness;

            var stroke = PdfColorHelper.ConvertBrush(brush, context.opacity, context.drawingSurface.Position, width, height);

            if (stroke != null)
            {
                context.drawingSurface.GraphicProperties.StrokeColor = stroke;
            }
            else
            {
                context.drawingSurface.GraphicProperties.IsStroked = false;
            }
        }
Exemple #36
0
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            Ellipse ellipse = element as Ellipse;
            if (ellipse == null)
            {
                return false;
            }

            using (context.drawingSurface.SaveGraphicProperties())
            {
                SetStroke(context, ellipse.StrokeThickness, ellipse.Stroke, ellipse.ActualWidth, ellipse.ActualHeight);
                SetFill(context, ellipse.Fill, ellipse.ActualWidth, ellipse.ActualHeight);

                if (context.drawingSurface.GraphicProperties.IsFilled || context.drawingSurface.GraphicProperties.IsStroked)
                {
                    context.drawingSurface.DrawEllipse(new Point(ellipse.ActualWidth / 2, ellipse.ActualHeight / 2), ellipse.ActualWidth / 2, ellipse.ActualHeight / 2);
                }
            }

            return true;
        }
Exemple #37
0
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            TextBlock textBlock = element as TextBlock;
            if (textBlock == null)
            {
                return false;
            }

            if (!string.IsNullOrEmpty(textBlock.Text))
            {
                using (context.drawingSurface.SaveProperties())
                {
                    SetFill(context, textBlock.Foreground, textBlock.ActualWidth, textBlock.ActualHeight);
                    SetFontFamily(context.drawingSurface, textBlock.FontFamily);
                    context.drawingSurface.TextProperties.FontSize = textBlock.FontSize;
                    context.drawingSurface.DrawText(textBlock.Text);
                }
            }

            return true;
        }
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            FrameworkElement frameworkElement = element as FrameworkElement;
            if (frameworkElement == null)
            {
                return false;
            }

            bool hasMatchingType = false;
            Type elementType = frameworkElement.GetType();
            foreach (Type type in this.types)
            {
                if (elementType == type || elementType.IsSubclassOf(type))
                {
                    hasMatchingType = true;
                    break;
                }
            }

            if (!hasMatchingType)
            {
                return false;
            }

            List<UIElement> uiElements = new List<UIElement>();
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(frameworkElement); i++)
            {
                UIElement child = VisualTreeHelper.GetChild(frameworkElement, i) as UIElement;
                uiElements.Add(child);
            }

            uiElements = uiElements.OrderBy(el => Canvas.GetZIndex(el)).ToList();

            foreach (UIElement child in uiElements)
            {
                context.facade.Render(child, context);
            }

            return true;
        }
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            Ellipse ellipse = element as Ellipse;

            if (ellipse == null)
            {
                return(false);
            }

            using (context.drawingSurface.SaveGraphicProperties())
            {
                SetStroke(context, ellipse.StrokeThickness, ellipse.Stroke, ellipse.ActualWidth, ellipse.ActualHeight);
                SetFill(context, ellipse.Fill, ellipse.ActualWidth, ellipse.ActualHeight);

                if (context.drawingSurface.GraphicProperties.IsFilled || context.drawingSurface.GraphicProperties.IsStroked)
                {
                    context.drawingSurface.DrawEllipse(new Point(ellipse.ActualWidth / 2, ellipse.ActualHeight / 2), ellipse.ActualWidth / 2, ellipse.ActualHeight / 2);
                }
            }

            return(true);
        }
Exemple #40
0
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            TextBlock textBlock = element as TextBlock;

            if (textBlock == null)
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(textBlock.Text))
            {
                using (context.drawingSurface.SaveProperties())
                {
                    SetFill(context, textBlock.Foreground, textBlock.ActualWidth, textBlock.ActualHeight);
                    SetFontFamily(context.drawingSurface, textBlock.FontFamily);
                    context.drawingSurface.TextProperties.FontSize = textBlock.FontSize;
                    context.drawingSurface.DrawText(textBlock.Text);
                }
            }

            return(true);
        }
Exemple #41
0
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            Rectangle rectangle = element as Rectangle;

            if (rectangle == null)
            {
                return(false);
            }

            bool hasStroke = rectangle.Stroke != null && rectangle.StrokeThickness != 0;
            bool isLine    = rectangle.ActualWidth == 1 || rectangle.ActualHeight == 1;

            if (isLine && !hasStroke)
            {
                // export the thin Rectangle as a Line to work-around a visual bug in Adobe Reader

                // account for the different rendering in wpf's Rectangle and pdf's line
                Point startPoint;
                Point endPoint;
                if (rectangle.ActualWidth == 1)
                {
                    startPoint = new Point(0.5, 0);
                    endPoint   = new Point(0.5, rectangle.ActualHeight);
                }
                else
                {
                    startPoint = new Point(0.5, 0.5);
                    endPoint   = new Point(0.5 + rectangle.ActualWidth, 0.5);
                }

                LineRenderer.DrawLine(context, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, 1, rectangle.Fill, null);
            }
            else
            {
                DrawRectangle(context, rectangle.Fill, rectangle.Stroke, rectangle.StrokeThickness, rectangle.ActualWidth, rectangle.ActualHeight, rectangle.StrokeDashArray);
            }

            return(true);
        }
Exemple #42
0
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            Rectangle rectangle = element as Rectangle;
            if (rectangle == null)
            {
                return false;
            }

            bool hasStroke = rectangle.Stroke != null && rectangle.StrokeThickness != 0;
            bool isLine = rectangle.ActualWidth == 1 || rectangle.ActualHeight == 1;

            if (isLine && !hasStroke)
            {
                // export the thin Rectangle as a Line to work-around a visual bug in Adobe Reader

                // account for the different rendering in wpf's Rectangle and pdf's line
                Point startPoint;
                Point endPoint;
                if (rectangle.ActualWidth == 1)
                {
                    startPoint = new Point(0.5, 0);
                    endPoint = new Point(0.5, rectangle.ActualHeight);
                }
                else
                {
                    startPoint = new Point(0.5, 0.5);
                    endPoint = new Point(0.5 + rectangle.ActualWidth, 0.5);
                }

                LineRenderer.DrawLine(context, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, 1, rectangle.Fill, null);
            }
            else
            {
                DrawRectangle(context, rectangle.Fill, rectangle.Stroke, rectangle.StrokeThickness, rectangle.ActualWidth, rectangle.ActualHeight);
            }

            return true;
        }
Exemple #43
0
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            TextBox textBox = element as TextBox;

            if (textBox == null)
            {
                return(false);
            }

            string text       = textBox.Text;
            Brush  foreground = textBox.Foreground;
            double width      = textBox.ActualWidth;
            double height     = textBox.ActualHeight;
            var    fontFamily = textBox.FontFamily;
            double fontSize   = textBox.FontSize;

            using (SaveClip(context.drawingSurface, new Rect(0, 0, textBox.ActualWidth, textBox.ActualHeight)))
            {
                TextRenderer.DrawTextBlock(text, context, foreground, width, height, fontFamily, fontSize);
            }

            return(true);
        }
Exemple #44
0
        internal override bool Render(UIElement element, PdfRenderContext context)
        {
            var border = element as System.Windows.Controls.Border;
            if (border == null)
            {
                return false;
            }

            if (IsSimpleStrokeThickness(border.BorderThickness))
            {
                RectangleRenderer.DrawRectangle(context, border.Background, border.BorderBrush, border.BorderThickness.Left, border.ActualWidth, border.ActualHeight);
            }
            else
            {
                DrawBackground(context, border.Background, border.BorderThickness, border.ActualWidth, border.ActualHeight);
                DrawBorderStroke(context, border.BorderThickness, border.BorderBrush, border.ActualWidth, border.ActualHeight);
            }

            UIElement firstChild = border.Child;
            context.facade.Render(firstChild, context);

            return true;
        }
 internal DisposableOpacity(PdfRenderContext context)
 {
     this.context = context;
     this.opacity = context.opacity;
 }
 internal void Render(UIElement element, FixedContentEditor drawingSurface)
 {
     PdfRenderContext context = new PdfRenderContext(drawingSurface, this);
     this.Render(element, context);
 }
Exemple #47
0
        internal void Render(UIElement element, FixedContentEditor drawingSurface)
        {
            PdfRenderContext context = new PdfRenderContext(drawingSurface, this);

            this.Render(element, context);
        }
 internal DisposableOpacity(PdfRenderContext context)
 {
     this.context = context;
     this.opacity = context.opacity;
 }
 internal abstract bool Render(UIElement element, PdfRenderContext context);
 internal abstract bool Render(UIElement element, PdfRenderContext context);
Exemple #51
-18
        internal static void DrawLine(PdfRenderContext context, double x1, double y1, double x2, double y2, double strokeThickness, Brush stroke, DoubleCollection dashArray)
        {
            using (context.drawingSurface.SaveGraphicProperties())
            {
                if (x1 == x2 && System.Math.Abs(y1 - y2) > 10)
                {
                    if (y2 < y1)
                    {
                        double max = y1;
                        y1 = y2;
                        y2 = max;
                    }

                    // offset the start position of the line to resolve a visual bug in Adobe Reader, where the axis line seems to continue after the last tick
                    y1 += 0.5;
                }

                SetStroke(context, strokeThickness, stroke, Math.Abs(x2 - x1), Math.Abs(y2 - y1));
                if (context.drawingSurface.GraphicProperties.IsStroked)
                {
                    context.drawingSurface.GraphicProperties.StrokeDashArray = dashArray;
                    context.drawingSurface.DrawLine(new Point(x1, y1), new Point(x2, y2));
                }
            }
        }