Пример #1
0
        public DocumentPage GetDocumentPage(int pageNumber, out Info1 info)
        {
            if (pageNumber == 0 && coverPage)
            {
                return(CoverPageExt.CreateCoverPage(_hdpi, _margins, _vdpi, PageSize, _control, out info));
            }

            var dv = new DrawingVisual();
            var dc = dv.RenderOpen();

            // DrawingGroup dg = new DrawingGroup();
            // var d = VisualTreeHelper.GetDpi((Visual)_control);
            // var dpiScale = new DpiScale(d.DpiScaleX * 2, d.DpiScaleY * 2);
            // VisualTreeHelper.SetRootDpi(dv, dpiScale);

            DrawPage(pageNumber, dc, out info);

            dc.Close();

            var bleedBox   = new Rect(0, 0, PageSize.Width, PageSize.Height);
            var contentBox = new Rect(0, 0, PageSize.Width, PageSize.Height);

            // var contentBox =  new Rect(_margins.Left, _margins.Top,
            // DocPageSize.Width, DocPageSize.Height);

            return(new DocumentPage(dv, PageSize, bleedBox, contentBox));
        }
Пример #2
0
        private void DrawPage(int pageNumber, DrawingContext dc, out Info1 info)
        {
            double pixelsPerDip = 1.0;

            if (coverPage)
            {
                pageNumber--;
            }

            var topOfPage = pageNumber * DocPageSize.Height;
            var width     = Math.Min(_bmp.Width, DocPageSize.Width);
            var viewBox   = new Rect(0, topOfPage, width, DocPageSize.Height);

            var b = new ImageBrush
            {
                ImageSource  = _bmp,
                AlignmentY   = AlignmentY.Top,
                AlignmentX   = AlignmentX.Left,
                Stretch      = Stretch.Uniform,
                Viewbox      = viewBox,
                ViewboxUnits = BrushMappingMode.Absolute
            };

            var rectangle = new Rect(_margins.Left, _margins.Top,
                                     DocPageSize.Width, DocPageSize.Height);

            Debug.WriteLine("box = " + viewBox);
            Debug.WriteLine(rectangle);
            var fTransform = true;

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (fTransform)
            {
                dc.PushTransform(new TranslateTransform(_margins.Left, _margins.Top));
            }

            var rect = rectangle;

            rect.Offset(-1 * _margins.Left, -1 * _margins.Top);
            rect.Width = width;
            dc.DrawRectangle(b, null, rect);

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (fTransform)
            {
                dc.Pop();
            }

            DrawDocumentTitle(dc, pixelsPerDip);
            DrawFooter(dc, rectangle, pixelsPerDip);
            DrawPageNumber(pageNumber);

            info = new Info1 {
                rectangle = rectangle, brush = b
            };
        }
Пример #3
0
        public static DocumentPage CreateCoverPage(int hdpi, Thickness thickness, int vdpi, Size pageSize, ICodeView codeView, out Info1 info)
        {
            var dv1 = new DrawingVisual();
            var dc0 = dv1.RenderOpen();

            var text = new FormattedText(codeView.DocumentTitle ?? "Untitled", CultureInfo.CurrentCulture,
                                         FlowDirection.LeftToRight,
                                         new Typeface(new FontFamily("Times new Roman"), FontStyles.Normal, FontWeights.Normal,
                                                      FontStretches.Normal), 32, Brushes.Black, null, TextFormattingMode.Ideal, 1);

            ;
            dc0.DrawText(text, new Point((pageSize.Width - text.Width) / 2, 4 * vdpi));

            var info1 =
                $"Margins:\t\tLeft: {thickness.Left / hdpi:N1};\t\tRight: {thickness.Right / hdpi:N1}; \r\n\t\tTop: {thickness.Top / vdpi:N1};\t\tBottom: {thickness.Bottom / vdpi:N1}\r\nPage Size:\t{pageSize.Width / hdpi:N1}\"x{pageSize.Height / vdpi:N1}\"\r\n";
            var text1 = new FormattedText(info1, CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                                          new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
                                          16, Brushes.Black, null, TextFormattingMode.Ideal, 1);

            ;
            dc0.DrawText(text1, new Point((pageSize.Width - text1.Width) / 2, 5 * vdpi));

            dc0.Close();
            info = null;


            return(new DocumentPage(dv1, pageSize,
                                    new Rect(0, -1 * vdpi, pageSize.Width, pageSize.Height + vdpi),
                                    new Rect(0, 0, pageSize.Width, pageSize.Height)));
        }